0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/interrupt.h>
0009 #include <linux/mfd/core.h>
0010 #include <linux/module.h>
0011 #include <linux/of_device.h>
0012 #include <linux/regmap.h>
0013
0014 #include <linux/mfd/lp873x.h>
0015
0016 static const struct regmap_config lp873x_regmap_config = {
0017 .reg_bits = 8,
0018 .val_bits = 8,
0019 .max_register = LP873X_REG_MAX,
0020 };
0021
0022 static const struct mfd_cell lp873x_cells[] = {
0023 { .name = "lp873x-regulator", },
0024 { .name = "lp873x-gpio", },
0025 };
0026
0027 static int lp873x_probe(struct i2c_client *client,
0028 const struct i2c_device_id *ids)
0029 {
0030 struct lp873x *lp873;
0031 int ret;
0032 unsigned int otpid;
0033
0034 lp873 = devm_kzalloc(&client->dev, sizeof(*lp873), GFP_KERNEL);
0035 if (!lp873)
0036 return -ENOMEM;
0037
0038 lp873->dev = &client->dev;
0039
0040 lp873->regmap = devm_regmap_init_i2c(client, &lp873x_regmap_config);
0041 if (IS_ERR(lp873->regmap)) {
0042 ret = PTR_ERR(lp873->regmap);
0043 dev_err(lp873->dev,
0044 "Failed to initialize register map: %d\n", ret);
0045 return ret;
0046 }
0047
0048 ret = regmap_read(lp873->regmap, LP873X_REG_OTP_REV, &otpid);
0049 if (ret) {
0050 dev_err(lp873->dev, "Failed to read OTP ID\n");
0051 return ret;
0052 }
0053
0054 lp873->rev = otpid & LP873X_OTP_REV_OTP_ID;
0055
0056 i2c_set_clientdata(client, lp873);
0057
0058 ret = mfd_add_devices(lp873->dev, PLATFORM_DEVID_AUTO, lp873x_cells,
0059 ARRAY_SIZE(lp873x_cells), NULL, 0, NULL);
0060
0061 return ret;
0062 }
0063
0064 static const struct of_device_id of_lp873x_match_table[] = {
0065 { .compatible = "ti,lp8733", },
0066 { .compatible = "ti,lp8732", },
0067 {}
0068 };
0069 MODULE_DEVICE_TABLE(of, of_lp873x_match_table);
0070
0071 static const struct i2c_device_id lp873x_id_table[] = {
0072 { "lp873x", 0 },
0073 { },
0074 };
0075 MODULE_DEVICE_TABLE(i2c, lp873x_id_table);
0076
0077 static struct i2c_driver lp873x_driver = {
0078 .driver = {
0079 .name = "lp873x",
0080 .of_match_table = of_lp873x_match_table,
0081 },
0082 .probe = lp873x_probe,
0083 .id_table = lp873x_id_table,
0084 };
0085 module_i2c_driver(lp873x_driver);
0086
0087 MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
0088 MODULE_DESCRIPTION("LP873X chip family Multi-Function Device driver");
0089 MODULE_LICENSE("GPL v2");