Linux Audio

Check our new training course

Loading...
v4.6
 
 1/*
 2 * Copyright (C) 2009 Wolfram Sang, Pengutronix
 3 *
 4 * This program is free software; you can redistribute it and/or modify
 5 * it under the terms of the GNU General Public License version 2 as
 6 * published by the Free Software Foundation.
 7 *
 8 * Check max730x.c for further details.
 9 */
10
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/platform_device.h>
14#include <linux/mutex.h>
15#include <linux/i2c.h>
16#include <linux/spi/max7301.h>
17#include <linux/slab.h>
18
19static int max7300_i2c_write(struct device *dev, unsigned int reg,
20				unsigned int val)
21{
22	struct i2c_client *client = to_i2c_client(dev);
23
24	return i2c_smbus_write_byte_data(client, reg, val);
25}
26
27static int max7300_i2c_read(struct device *dev, unsigned int reg)
28{
29	struct i2c_client *client = to_i2c_client(dev);
30
31	return i2c_smbus_read_byte_data(client, reg);
32}
33
34static int max7300_probe(struct i2c_client *client,
35			 const struct i2c_device_id *id)
36{
37	struct max7301 *ts;
38
39	if (!i2c_check_functionality(client->adapter,
40			I2C_FUNC_SMBUS_BYTE_DATA))
41		return -EIO;
42
43	ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL);
44	if (!ts)
45		return -ENOMEM;
46
47	ts->read = max7300_i2c_read;
48	ts->write = max7300_i2c_write;
49	ts->dev = &client->dev;
50
51	return __max730x_probe(ts);
52}
53
54static int max7300_remove(struct i2c_client *client)
55{
56	return __max730x_remove(&client->dev);
57}
58
59static const struct i2c_device_id max7300_id[] = {
60	{ "max7300", 0 },
61	{ }
62};
63MODULE_DEVICE_TABLE(i2c, max7300_id);
64
65static struct i2c_driver max7300_driver = {
66	.driver = {
67		.name = "max7300",
68	},
69	.probe = max7300_probe,
70	.remove = max7300_remove,
71	.id_table = max7300_id,
72};
73
74static int __init max7300_init(void)
75{
76	return i2c_add_driver(&max7300_driver);
77}
78subsys_initcall(max7300_init);
79
80static void __exit max7300_exit(void)
81{
82	i2c_del_driver(&max7300_driver);
83}
84module_exit(max7300_exit);
85
86MODULE_AUTHOR("Wolfram Sang");
87MODULE_LICENSE("GPL v2");
88MODULE_DESCRIPTION("MAX7300 GPIO-Expander");
v5.9
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * Copyright (C) 2009 Wolfram Sang, Pengutronix
 
 
 
 
 4 *
 5 * Check max730x.c for further details.
 6 */
 7
 8#include <linux/module.h>
 9#include <linux/init.h>
10#include <linux/platform_device.h>
11#include <linux/mutex.h>
12#include <linux/i2c.h>
13#include <linux/spi/max7301.h>
14#include <linux/slab.h>
15
16static int max7300_i2c_write(struct device *dev, unsigned int reg,
17				unsigned int val)
18{
19	struct i2c_client *client = to_i2c_client(dev);
20
21	return i2c_smbus_write_byte_data(client, reg, val);
22}
23
24static int max7300_i2c_read(struct device *dev, unsigned int reg)
25{
26	struct i2c_client *client = to_i2c_client(dev);
27
28	return i2c_smbus_read_byte_data(client, reg);
29}
30
31static int max7300_probe(struct i2c_client *client,
32			 const struct i2c_device_id *id)
33{
34	struct max7301 *ts;
35
36	if (!i2c_check_functionality(client->adapter,
37			I2C_FUNC_SMBUS_BYTE_DATA))
38		return -EIO;
39
40	ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL);
41	if (!ts)
42		return -ENOMEM;
43
44	ts->read = max7300_i2c_read;
45	ts->write = max7300_i2c_write;
46	ts->dev = &client->dev;
47
48	return __max730x_probe(ts);
49}
50
51static int max7300_remove(struct i2c_client *client)
52{
53	return __max730x_remove(&client->dev);
54}
55
56static const struct i2c_device_id max7300_id[] = {
57	{ "max7300", 0 },
58	{ }
59};
60MODULE_DEVICE_TABLE(i2c, max7300_id);
61
62static struct i2c_driver max7300_driver = {
63	.driver = {
64		.name = "max7300",
65	},
66	.probe = max7300_probe,
67	.remove = max7300_remove,
68	.id_table = max7300_id,
69};
70
71static int __init max7300_init(void)
72{
73	return i2c_add_driver(&max7300_driver);
74}
75subsys_initcall(max7300_init);
76
77static void __exit max7300_exit(void)
78{
79	i2c_del_driver(&max7300_driver);
80}
81module_exit(max7300_exit);
82
83MODULE_AUTHOR("Wolfram Sang");
84MODULE_LICENSE("GPL v2");
85MODULE_DESCRIPTION("MAX7300 GPIO-Expander");