Linux Audio

Check our new training course

Loading...
v3.5.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 __devinit max7300_probe(struct i2c_client *client,
35			 const struct i2c_device_id *id)
36{
37	struct max7301 *ts;
38	int ret;
39
40	if (!i2c_check_functionality(client->adapter,
41			I2C_FUNC_SMBUS_BYTE_DATA))
42		return -EIO;
43
44	ts = kzalloc(sizeof(struct max7301), GFP_KERNEL);
45	if (!ts)
46		return -ENOMEM;
47
48	ts->read = max7300_i2c_read;
49	ts->write = max7300_i2c_write;
50	ts->dev = &client->dev;
51
52	ret = __max730x_probe(ts);
53	if (ret)
54		kfree(ts);
55	return ret;
56}
57
58static int __devexit max7300_remove(struct i2c_client *client)
59{
60	return __max730x_remove(&client->dev);
61}
62
63static const struct i2c_device_id max7300_id[] = {
64	{ "max7300", 0 },
65	{ }
66};
67MODULE_DEVICE_TABLE(i2c, max7300_id);
68
69static struct i2c_driver max7300_driver = {
70	.driver = {
71		.name = "max7300",
72		.owner = THIS_MODULE,
73	},
74	.probe = max7300_probe,
75	.remove = __devexit_p(max7300_remove),
76	.id_table = max7300_id,
77};
78
79static int __init max7300_init(void)
80{
81	return i2c_add_driver(&max7300_driver);
82}
83subsys_initcall(max7300_init);
84
85static void __exit max7300_exit(void)
86{
87	i2c_del_driver(&max7300_driver);
88}
89module_exit(max7300_exit);
90
91MODULE_AUTHOR("Wolfram Sang");
92MODULE_LICENSE("GPL v2");
93MODULE_DESCRIPTION("MAX7300 GPIO-Expander");
v6.2
 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{
33	struct max7301 *ts;
 
34
35	if (!i2c_check_functionality(client->adapter,
36			I2C_FUNC_SMBUS_BYTE_DATA))
37		return -EIO;
38
39	ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL);
40	if (!ts)
41		return -ENOMEM;
42
43	ts->read = max7300_i2c_read;
44	ts->write = max7300_i2c_write;
45	ts->dev = &client->dev;
46
47	return __max730x_probe(ts);
 
 
 
48}
49
50static void max7300_remove(struct i2c_client *client)
51{
52	__max730x_remove(&client->dev);
53}
54
55static const struct i2c_device_id max7300_id[] = {
56	{ "max7300", 0 },
57	{ }
58};
59MODULE_DEVICE_TABLE(i2c, max7300_id);
60
61static struct i2c_driver max7300_driver = {
62	.driver = {
63		.name = "max7300",
 
64	},
65	.probe_new = max7300_probe,
66	.remove = max7300_remove,
67	.id_table = max7300_id,
68};
69
70static int __init max7300_init(void)
71{
72	return i2c_add_driver(&max7300_driver);
73}
74subsys_initcall(max7300_init);
75
76static void __exit max7300_exit(void)
77{
78	i2c_del_driver(&max7300_driver);
79}
80module_exit(max7300_exit);
81
82MODULE_AUTHOR("Wolfram Sang");
83MODULE_LICENSE("GPL v2");
84MODULE_DESCRIPTION("MAX7300 GPIO-Expander");