Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) 2009 Wolfram Sang, Pengutronix
0004  *
0005  * Check max730x.c for further details.
0006  */
0007 
0008 #include <linux/module.h>
0009 #include <linux/init.h>
0010 #include <linux/platform_device.h>
0011 #include <linux/mutex.h>
0012 #include <linux/i2c.h>
0013 #include <linux/spi/max7301.h>
0014 #include <linux/slab.h>
0015 
0016 static int max7300_i2c_write(struct device *dev, unsigned int reg,
0017                 unsigned int val)
0018 {
0019     struct i2c_client *client = to_i2c_client(dev);
0020 
0021     return i2c_smbus_write_byte_data(client, reg, val);
0022 }
0023 
0024 static int max7300_i2c_read(struct device *dev, unsigned int reg)
0025 {
0026     struct i2c_client *client = to_i2c_client(dev);
0027 
0028     return i2c_smbus_read_byte_data(client, reg);
0029 }
0030 
0031 static int max7300_probe(struct i2c_client *client,
0032              const struct i2c_device_id *id)
0033 {
0034     struct max7301 *ts;
0035 
0036     if (!i2c_check_functionality(client->adapter,
0037             I2C_FUNC_SMBUS_BYTE_DATA))
0038         return -EIO;
0039 
0040     ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL);
0041     if (!ts)
0042         return -ENOMEM;
0043 
0044     ts->read = max7300_i2c_read;
0045     ts->write = max7300_i2c_write;
0046     ts->dev = &client->dev;
0047 
0048     return __max730x_probe(ts);
0049 }
0050 
0051 static int max7300_remove(struct i2c_client *client)
0052 {
0053     __max730x_remove(&client->dev);
0054 
0055     return 0;
0056 }
0057 
0058 static const struct i2c_device_id max7300_id[] = {
0059     { "max7300", 0 },
0060     { }
0061 };
0062 MODULE_DEVICE_TABLE(i2c, max7300_id);
0063 
0064 static struct i2c_driver max7300_driver = {
0065     .driver = {
0066         .name = "max7300",
0067     },
0068     .probe = max7300_probe,
0069     .remove = max7300_remove,
0070     .id_table = max7300_id,
0071 };
0072 
0073 static int __init max7300_init(void)
0074 {
0075     return i2c_add_driver(&max7300_driver);
0076 }
0077 subsys_initcall(max7300_init);
0078 
0079 static void __exit max7300_exit(void)
0080 {
0081     i2c_del_driver(&max7300_driver);
0082 }
0083 module_exit(max7300_exit);
0084 
0085 MODULE_AUTHOR("Wolfram Sang");
0086 MODULE_LICENSE("GPL v2");
0087 MODULE_DESCRIPTION("MAX7300 GPIO-Expander");