1*dc21c7adSKeerthy /* 2*dc21c7adSKeerthy * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/ 3*dc21c7adSKeerthy * 4*dc21c7adSKeerthy * Author: Keerthy <j-keerthy@ti.com> 5*dc21c7adSKeerthy * 6*dc21c7adSKeerthy * This program is free software; you can redistribute it and/or 7*dc21c7adSKeerthy * modify it under the terms of the GNU General Public License as 8*dc21c7adSKeerthy * published by the Free Software Foundation version 2. 9*dc21c7adSKeerthy * 10*dc21c7adSKeerthy * This program is distributed "as is" WITHOUT ANY WARRANTY of any 11*dc21c7adSKeerthy * kind, whether express or implied; without even the implied warranty 12*dc21c7adSKeerthy * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*dc21c7adSKeerthy * GNU General Public License for more details. 14*dc21c7adSKeerthy */ 15*dc21c7adSKeerthy 16*dc21c7adSKeerthy #include <linux/interrupt.h> 17*dc21c7adSKeerthy #include <linux/mfd/core.h> 18*dc21c7adSKeerthy #include <linux/module.h> 19*dc21c7adSKeerthy #include <linux/of_device.h> 20*dc21c7adSKeerthy #include <linux/regmap.h> 21*dc21c7adSKeerthy 22*dc21c7adSKeerthy #include <linux/mfd/lp873x.h> 23*dc21c7adSKeerthy 24*dc21c7adSKeerthy static const struct regmap_config lp873x_regmap_config = { 25*dc21c7adSKeerthy .reg_bits = 8, 26*dc21c7adSKeerthy .val_bits = 8, 27*dc21c7adSKeerthy .max_register = LP873X_REG_MAX, 28*dc21c7adSKeerthy }; 29*dc21c7adSKeerthy 30*dc21c7adSKeerthy static const struct mfd_cell lp873x_cells[] = { 31*dc21c7adSKeerthy { .name = "lp873x-regulator", }, 32*dc21c7adSKeerthy { .name = "lp873x-gpio", }, 33*dc21c7adSKeerthy }; 34*dc21c7adSKeerthy 35*dc21c7adSKeerthy static int lp873x_probe(struct i2c_client *client, 36*dc21c7adSKeerthy const struct i2c_device_id *ids) 37*dc21c7adSKeerthy { 38*dc21c7adSKeerthy struct lp873x *lp873; 39*dc21c7adSKeerthy int ret; 40*dc21c7adSKeerthy unsigned int otpid; 41*dc21c7adSKeerthy 42*dc21c7adSKeerthy lp873 = devm_kzalloc(&client->dev, sizeof(*lp873), GFP_KERNEL); 43*dc21c7adSKeerthy if (!lp873) 44*dc21c7adSKeerthy return -ENOMEM; 45*dc21c7adSKeerthy 46*dc21c7adSKeerthy lp873->dev = &client->dev; 47*dc21c7adSKeerthy 48*dc21c7adSKeerthy lp873->regmap = devm_regmap_init_i2c(client, &lp873x_regmap_config); 49*dc21c7adSKeerthy if (IS_ERR(lp873->regmap)) { 50*dc21c7adSKeerthy ret = PTR_ERR(lp873->regmap); 51*dc21c7adSKeerthy dev_err(lp873->dev, 52*dc21c7adSKeerthy "Failed to initialize register map: %d\n", ret); 53*dc21c7adSKeerthy return ret; 54*dc21c7adSKeerthy } 55*dc21c7adSKeerthy 56*dc21c7adSKeerthy mutex_init(&lp873->lock); 57*dc21c7adSKeerthy 58*dc21c7adSKeerthy ret = regmap_read(lp873->regmap, LP873X_REG_OTP_REV, &otpid); 59*dc21c7adSKeerthy if (ret) { 60*dc21c7adSKeerthy dev_err(lp873->dev, "Failed to read OTP ID\n"); 61*dc21c7adSKeerthy return ret; 62*dc21c7adSKeerthy } 63*dc21c7adSKeerthy 64*dc21c7adSKeerthy lp873->rev = otpid & LP873X_OTP_REV_OTP_ID; 65*dc21c7adSKeerthy 66*dc21c7adSKeerthy i2c_set_clientdata(client, lp873); 67*dc21c7adSKeerthy 68*dc21c7adSKeerthy ret = mfd_add_devices(lp873->dev, PLATFORM_DEVID_AUTO, lp873x_cells, 69*dc21c7adSKeerthy ARRAY_SIZE(lp873x_cells), NULL, 0, NULL); 70*dc21c7adSKeerthy 71*dc21c7adSKeerthy return ret; 72*dc21c7adSKeerthy } 73*dc21c7adSKeerthy 74*dc21c7adSKeerthy static const struct of_device_id of_lp873x_match_table[] = { 75*dc21c7adSKeerthy { .compatible = "ti,lp8733", }, 76*dc21c7adSKeerthy { .compatible = "ti,lp8732", }, 77*dc21c7adSKeerthy {} 78*dc21c7adSKeerthy }; 79*dc21c7adSKeerthy MODULE_DEVICE_TABLE(of, of_lp873x_match_table); 80*dc21c7adSKeerthy 81*dc21c7adSKeerthy static const struct i2c_device_id lp873x_id_table[] = { 82*dc21c7adSKeerthy { "lp873x", 0 }, 83*dc21c7adSKeerthy { }, 84*dc21c7adSKeerthy }; 85*dc21c7adSKeerthy MODULE_DEVICE_TABLE(i2c, lp873x_id_table); 86*dc21c7adSKeerthy 87*dc21c7adSKeerthy static struct i2c_driver lp873x_driver = { 88*dc21c7adSKeerthy .driver = { 89*dc21c7adSKeerthy .name = "lp873x", 90*dc21c7adSKeerthy .of_match_table = of_lp873x_match_table, 91*dc21c7adSKeerthy }, 92*dc21c7adSKeerthy .probe = lp873x_probe, 93*dc21c7adSKeerthy .id_table = lp873x_id_table, 94*dc21c7adSKeerthy }; 95*dc21c7adSKeerthy module_i2c_driver(lp873x_driver); 96*dc21c7adSKeerthy 97*dc21c7adSKeerthy MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>"); 98*dc21c7adSKeerthy MODULE_DESCRIPTION("LP873X chip family Multi-Function Device driver"); 99*dc21c7adSKeerthy MODULE_LICENSE("GPL v2"); 100