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