1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (C) 2016 Texas Instruments Incorporated - https://www.ti.com/ 4 * 5 * Author: Keerthy <j-keerthy@ti.com> 6 */ 7 8 #include <linux/interrupt.h> 9 #include <linux/mfd/core.h> 10 #include <linux/module.h> 11 #include <linux/regmap.h> 12 13 #include <linux/mfd/lp873x.h> 14 15 static const struct regmap_config lp873x_regmap_config = { 16 .reg_bits = 8, 17 .val_bits = 8, 18 .max_register = LP873X_REG_MAX, 19 }; 20 21 static const struct mfd_cell lp873x_cells[] = { 22 { .name = "lp873x-regulator", }, 23 { .name = "lp873x-gpio", }, 24 }; 25 26 static int lp873x_probe(struct i2c_client *client) 27 { 28 struct lp873x *lp873; 29 int ret; 30 unsigned int otpid; 31 32 lp873 = devm_kzalloc(&client->dev, sizeof(*lp873), GFP_KERNEL); 33 if (!lp873) 34 return -ENOMEM; 35 36 lp873->dev = &client->dev; 37 38 lp873->regmap = devm_regmap_init_i2c(client, &lp873x_regmap_config); 39 if (IS_ERR(lp873->regmap)) { 40 ret = PTR_ERR(lp873->regmap); 41 dev_err(lp873->dev, 42 "Failed to initialize register map: %d\n", ret); 43 return ret; 44 } 45 46 ret = regmap_read(lp873->regmap, LP873X_REG_OTP_REV, &otpid); 47 if (ret) { 48 dev_err(lp873->dev, "Failed to read OTP ID\n"); 49 return ret; 50 } 51 52 lp873->rev = otpid & LP873X_OTP_REV_OTP_ID; 53 54 i2c_set_clientdata(client, lp873); 55 56 ret = mfd_add_devices(lp873->dev, PLATFORM_DEVID_AUTO, lp873x_cells, 57 ARRAY_SIZE(lp873x_cells), NULL, 0, NULL); 58 59 return ret; 60 } 61 62 static const struct of_device_id of_lp873x_match_table[] = { 63 { .compatible = "ti,lp8733", }, 64 { .compatible = "ti,lp8732", }, 65 {} 66 }; 67 MODULE_DEVICE_TABLE(of, of_lp873x_match_table); 68 69 static const struct i2c_device_id lp873x_id_table[] = { 70 { "lp873x" }, 71 { } 72 }; 73 MODULE_DEVICE_TABLE(i2c, lp873x_id_table); 74 75 static struct i2c_driver lp873x_driver = { 76 .driver = { 77 .name = "lp873x", 78 .of_match_table = of_lp873x_match_table, 79 }, 80 .probe = lp873x_probe, 81 .id_table = lp873x_id_table, 82 }; 83 module_i2c_driver(lp873x_driver); 84 85 MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>"); 86 MODULE_DESCRIPTION("LP873X chip family Multi-Function Device driver"); 87 MODULE_LICENSE("GPL v2"); 88