1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2009 Wolfram Sang, Pengutronix
5 * Check max730x.c for further details.
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>
16 static int max7300_i2c_write(struct device *dev, unsigned int reg,
19 struct i2c_client *client = to_i2c_client(dev);
21 return i2c_smbus_write_byte_data(client, reg, val);
24 static int max7300_i2c_read(struct device *dev, unsigned int reg)
26 struct i2c_client *client = to_i2c_client(dev);
28 return i2c_smbus_read_byte_data(client, reg);
31 static int max7300_probe(struct i2c_client *client,
32 const struct i2c_device_id *id)
36 if (!i2c_check_functionality(client->adapter,
37 I2C_FUNC_SMBUS_BYTE_DATA))
40 ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL);
44 ts->read = max7300_i2c_read;
45 ts->write = max7300_i2c_write;
46 ts->dev = &client->dev;
48 return __max730x_probe(ts);
51 static int max7300_remove(struct i2c_client *client)
53 __max730x_remove(&client->dev);
58 static const struct i2c_device_id max7300_id[] = {
62 MODULE_DEVICE_TABLE(i2c, max7300_id);
64 static struct i2c_driver max7300_driver = {
68 .probe = max7300_probe,
69 .remove = max7300_remove,
70 .id_table = max7300_id,
73 static int __init max7300_init(void)
75 return i2c_add_driver(&max7300_driver);
77 subsys_initcall(max7300_init);
79 static void __exit max7300_exit(void)
81 i2c_del_driver(&max7300_driver);
83 module_exit(max7300_exit);
85 MODULE_AUTHOR("Wolfram Sang");
86 MODULE_LICENSE("GPL v2");
87 MODULE_DESCRIPTION("MAX7300 GPIO-Expander");