Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * ST Microelectronics MFD: stmpe's i2c client specific driver
0004  *
0005  * Copyright (C) ST-Ericsson SA 2010
0006  * Copyright (C) ST Microelectronics SA 2011
0007  *
0008  * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
0009  * Author: Viresh Kumar <vireshk@kernel.org> for ST Microelectronics
0010  */
0011 
0012 #include <linux/i2c.h>
0013 #include <linux/interrupt.h>
0014 #include <linux/kernel.h>
0015 #include <linux/module.h>
0016 #include <linux/types.h>
0017 #include <linux/of_device.h>
0018 #include "stmpe.h"
0019 
0020 static int i2c_reg_read(struct stmpe *stmpe, u8 reg)
0021 {
0022     struct i2c_client *i2c = stmpe->client;
0023 
0024     return i2c_smbus_read_byte_data(i2c, reg);
0025 }
0026 
0027 static int i2c_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
0028 {
0029     struct i2c_client *i2c = stmpe->client;
0030 
0031     return i2c_smbus_write_byte_data(i2c, reg, val);
0032 }
0033 
0034 static int i2c_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values)
0035 {
0036     struct i2c_client *i2c = stmpe->client;
0037 
0038     return i2c_smbus_read_i2c_block_data(i2c, reg, length, values);
0039 }
0040 
0041 static int i2c_block_write(struct stmpe *stmpe, u8 reg, u8 length,
0042         const u8 *values)
0043 {
0044     struct i2c_client *i2c = stmpe->client;
0045 
0046     return i2c_smbus_write_i2c_block_data(i2c, reg, length, values);
0047 }
0048 
0049 static struct stmpe_client_info i2c_ci = {
0050     .read_byte = i2c_reg_read,
0051     .write_byte = i2c_reg_write,
0052     .read_block = i2c_block_read,
0053     .write_block = i2c_block_write,
0054 };
0055 
0056 static const struct of_device_id stmpe_of_match[] = {
0057     { .compatible = "st,stmpe610", .data = (void *)STMPE610, },
0058     { .compatible = "st,stmpe801", .data = (void *)STMPE801, },
0059     { .compatible = "st,stmpe811", .data = (void *)STMPE811, },
0060     { .compatible = "st,stmpe1600", .data = (void *)STMPE1600, },
0061     { .compatible = "st,stmpe1601", .data = (void *)STMPE1601, },
0062     { .compatible = "st,stmpe1801", .data = (void *)STMPE1801, },
0063     { .compatible = "st,stmpe2401", .data = (void *)STMPE2401, },
0064     { .compatible = "st,stmpe2403", .data = (void *)STMPE2403, },
0065     {},
0066 };
0067 MODULE_DEVICE_TABLE(of, stmpe_of_match);
0068 
0069 static int
0070 stmpe_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
0071 {
0072     enum stmpe_partnum partnum;
0073     const struct of_device_id *of_id;
0074 
0075     i2c_ci.data = (void *)id;
0076     i2c_ci.irq = i2c->irq;
0077     i2c_ci.client = i2c;
0078     i2c_ci.dev = &i2c->dev;
0079 
0080     of_id = of_match_device(stmpe_of_match, &i2c->dev);
0081     if (!of_id) {
0082         /*
0083          * This happens when the I2C ID matches the node name
0084          * but no real compatible string has been given.
0085          */
0086         dev_info(&i2c->dev, "matching on node name, compatible is preferred\n");
0087         partnum = id->driver_data;
0088     } else
0089         partnum = (enum stmpe_partnum)of_id->data;
0090 
0091     return stmpe_probe(&i2c_ci, partnum);
0092 }
0093 
0094 static int stmpe_i2c_remove(struct i2c_client *i2c)
0095 {
0096     struct stmpe *stmpe = dev_get_drvdata(&i2c->dev);
0097 
0098     stmpe_remove(stmpe);
0099 
0100     return 0;
0101 }
0102 
0103 static const struct i2c_device_id stmpe_i2c_id[] = {
0104     { "stmpe610", STMPE610 },
0105     { "stmpe801", STMPE801 },
0106     { "stmpe811", STMPE811 },
0107     { "stmpe1600", STMPE1600 },
0108     { "stmpe1601", STMPE1601 },
0109     { "stmpe1801", STMPE1801 },
0110     { "stmpe2401", STMPE2401 },
0111     { "stmpe2403", STMPE2403 },
0112     { }
0113 };
0114 MODULE_DEVICE_TABLE(i2c, stmpe_i2c_id);
0115 
0116 static struct i2c_driver stmpe_i2c_driver = {
0117     .driver = {
0118         .name = "stmpe-i2c",
0119 #ifdef CONFIG_PM
0120         .pm = &stmpe_dev_pm_ops,
0121 #endif
0122         .of_match_table = stmpe_of_match,
0123     },
0124     .probe      = stmpe_i2c_probe,
0125     .remove     = stmpe_i2c_remove,
0126     .id_table   = stmpe_i2c_id,
0127 };
0128 
0129 static int __init stmpe_init(void)
0130 {
0131     return i2c_add_driver(&stmpe_i2c_driver);
0132 }
0133 subsys_initcall(stmpe_init);
0134 
0135 static void __exit stmpe_exit(void)
0136 {
0137     i2c_del_driver(&stmpe_i2c_driver);
0138 }
0139 module_exit(stmpe_exit);
0140 
0141 MODULE_LICENSE("GPL v2");
0142 MODULE_DESCRIPTION("STMPE MFD I2C Interface Driver");
0143 MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");