Linux 4.16.11
[linux/fpc-iii.git] / drivers / gpio / gpio-max7300.c
blob1ae9ba851c9ac08f6a737fc81d0c24f34b05214e
1 /*
2 * Copyright (C) 2009 Wolfram Sang, Pengutronix
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.
8 * Check max730x.c for further details.
9 */
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>
19 static int max7300_i2c_write(struct device *dev, unsigned int reg,
20 unsigned int val)
22 struct i2c_client *client = to_i2c_client(dev);
24 return i2c_smbus_write_byte_data(client, reg, val);
27 static int max7300_i2c_read(struct device *dev, unsigned int reg)
29 struct i2c_client *client = to_i2c_client(dev);
31 return i2c_smbus_read_byte_data(client, reg);
34 static int max7300_probe(struct i2c_client *client,
35 const struct i2c_device_id *id)
37 struct max7301 *ts;
39 if (!i2c_check_functionality(client->adapter,
40 I2C_FUNC_SMBUS_BYTE_DATA))
41 return -EIO;
43 ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL);
44 if (!ts)
45 return -ENOMEM;
47 ts->read = max7300_i2c_read;
48 ts->write = max7300_i2c_write;
49 ts->dev = &client->dev;
51 return __max730x_probe(ts);
54 static int max7300_remove(struct i2c_client *client)
56 return __max730x_remove(&client->dev);
59 static const struct i2c_device_id max7300_id[] = {
60 { "max7300", 0 },
61 { }
63 MODULE_DEVICE_TABLE(i2c, max7300_id);
65 static struct i2c_driver max7300_driver = {
66 .driver = {
67 .name = "max7300",
69 .probe = max7300_probe,
70 .remove = max7300_remove,
71 .id_table = max7300_id,
74 static int __init max7300_init(void)
76 return i2c_add_driver(&max7300_driver);
78 subsys_initcall(max7300_init);
80 static void __exit max7300_exit(void)
82 i2c_del_driver(&max7300_driver);
84 module_exit(max7300_exit);
86 MODULE_AUTHOR("Wolfram Sang");
87 MODULE_LICENSE("GPL v2");
88 MODULE_DESCRIPTION("MAX7300 GPIO-Expander");