0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/gpio/consumer.h>
0009 #include <linux/interrupt.h>
0010 #include <linux/mfd/core.h>
0011 #include <linux/module.h>
0012 #include <linux/of_device.h>
0013 #include <linux/regmap.h>
0014
0015 #include <linux/mfd/lp87565.h>
0016
0017 static const struct regmap_config lp87565_regmap_config = {
0018 .reg_bits = 8,
0019 .val_bits = 8,
0020 .max_register = LP87565_REG_MAX,
0021 };
0022
0023 static const struct mfd_cell lp87565_cells[] = {
0024 { .name = "lp87565-q1-regulator", },
0025 { .name = "lp87565-q1-gpio", },
0026 };
0027
0028 static const struct of_device_id of_lp87565_match_table[] = {
0029 { .compatible = "ti,lp87565", },
0030 {
0031 .compatible = "ti,lp87524-q1",
0032 .data = (void *)LP87565_DEVICE_TYPE_LP87524_Q1,
0033 },
0034 {
0035 .compatible = "ti,lp87565-q1",
0036 .data = (void *)LP87565_DEVICE_TYPE_LP87565_Q1,
0037 },
0038 {
0039 .compatible = "ti,lp87561-q1",
0040 .data = (void *)LP87565_DEVICE_TYPE_LP87561_Q1,
0041 },
0042 {}
0043 };
0044 MODULE_DEVICE_TABLE(of, of_lp87565_match_table);
0045
0046 static int lp87565_probe(struct i2c_client *client,
0047 const struct i2c_device_id *ids)
0048 {
0049 struct lp87565 *lp87565;
0050 const struct of_device_id *of_id;
0051 int ret;
0052 unsigned int otpid;
0053
0054 lp87565 = devm_kzalloc(&client->dev, sizeof(*lp87565), GFP_KERNEL);
0055 if (!lp87565)
0056 return -ENOMEM;
0057
0058 lp87565->dev = &client->dev;
0059
0060 lp87565->regmap = devm_regmap_init_i2c(client, &lp87565_regmap_config);
0061 if (IS_ERR(lp87565->regmap)) {
0062 ret = PTR_ERR(lp87565->regmap);
0063 dev_err(lp87565->dev,
0064 "Failed to initialize register map: %d\n", ret);
0065 return ret;
0066 }
0067
0068 lp87565->reset_gpio = devm_gpiod_get_optional(lp87565->dev, "reset",
0069 GPIOD_OUT_LOW);
0070 if (IS_ERR(lp87565->reset_gpio)) {
0071 ret = PTR_ERR(lp87565->reset_gpio);
0072 if (ret == -EPROBE_DEFER)
0073 return ret;
0074 }
0075
0076 if (lp87565->reset_gpio) {
0077 gpiod_set_value_cansleep(lp87565->reset_gpio, 1);
0078
0079 usleep_range(2000, 4000);
0080
0081 gpiod_set_value_cansleep(lp87565->reset_gpio, 0);
0082
0083 usleep_range(1500, 3000);
0084 }
0085
0086 ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid);
0087 if (ret) {
0088 dev_err(lp87565->dev, "Failed to read OTP ID\n");
0089 return ret;
0090 }
0091
0092 lp87565->rev = otpid & LP87565_OTP_REV_OTP_ID;
0093
0094 of_id = of_match_device(of_lp87565_match_table, &client->dev);
0095 if (of_id)
0096 lp87565->dev_type = (enum lp87565_device_type)of_id->data;
0097
0098 i2c_set_clientdata(client, lp87565);
0099
0100 return devm_mfd_add_devices(lp87565->dev, PLATFORM_DEVID_AUTO,
0101 lp87565_cells, ARRAY_SIZE(lp87565_cells),
0102 NULL, 0, NULL);
0103 }
0104
0105 static void lp87565_shutdown(struct i2c_client *client)
0106 {
0107 struct lp87565 *lp87565 = i2c_get_clientdata(client);
0108
0109 gpiod_set_value_cansleep(lp87565->reset_gpio, 1);
0110 }
0111
0112 static const struct i2c_device_id lp87565_id_table[] = {
0113 { "lp87565-q1", 0 },
0114 { },
0115 };
0116 MODULE_DEVICE_TABLE(i2c, lp87565_id_table);
0117
0118 static struct i2c_driver lp87565_driver = {
0119 .driver = {
0120 .name = "lp87565",
0121 .of_match_table = of_lp87565_match_table,
0122 },
0123 .probe = lp87565_probe,
0124 .shutdown = lp87565_shutdown,
0125 .id_table = lp87565_id_table,
0126 };
0127 module_i2c_driver(lp87565_driver);
0128
0129 MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
0130 MODULE_DESCRIPTION("lp87565 chip family Multi-Function Device driver");
0131 MODULE_LICENSE("GPL v2");