1a10e763bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 21e349600SKeerthy /* 34f4ed454SAlexander A. Klimov * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/ 41e349600SKeerthy * 51e349600SKeerthy * Author: Keerthy <j-keerthy@ti.com> 61e349600SKeerthy */ 71e349600SKeerthy 81e349600SKeerthy #include <linux/interrupt.h> 91e349600SKeerthy #include <linux/mfd/core.h> 101e349600SKeerthy #include <linux/module.h> 111e349600SKeerthy #include <linux/of_device.h> 121e349600SKeerthy #include <linux/regmap.h> 131e349600SKeerthy 141e349600SKeerthy #include <linux/mfd/lp87565.h> 151e349600SKeerthy 161e349600SKeerthy static const struct regmap_config lp87565_regmap_config = { 171e349600SKeerthy .reg_bits = 8, 181e349600SKeerthy .val_bits = 8, 191e349600SKeerthy .max_register = LP87565_REG_MAX, 201e349600SKeerthy }; 211e349600SKeerthy 221e349600SKeerthy static const struct mfd_cell lp87565_cells[] = { 231e349600SKeerthy { .name = "lp87565-q1-regulator", }, 241e349600SKeerthy { .name = "lp87565-q1-gpio", }, 251e349600SKeerthy }; 261e349600SKeerthy 271e349600SKeerthy static const struct of_device_id of_lp87565_match_table[] = { 281e349600SKeerthy { .compatible = "ti,lp87565", }, 291e349600SKeerthy { 30*4b6ec08fSLuca Ceresoli .compatible = "ti,lp87524-q1", 31*4b6ec08fSLuca Ceresoli .data = (void *)LP87565_DEVICE_TYPE_LP87524_Q1, 32*4b6ec08fSLuca Ceresoli }, 33*4b6ec08fSLuca Ceresoli { 341e349600SKeerthy .compatible = "ti,lp87565-q1", 351e349600SKeerthy .data = (void *)LP87565_DEVICE_TYPE_LP87565_Q1, 361e349600SKeerthy }, 37013e868bSKeerthy { 38013e868bSKeerthy .compatible = "ti,lp87561-q1", 39013e868bSKeerthy .data = (void *)LP87565_DEVICE_TYPE_LP87561_Q1, 40013e868bSKeerthy }, 411e349600SKeerthy {} 421e349600SKeerthy }; 431e349600SKeerthy MODULE_DEVICE_TABLE(of, of_lp87565_match_table); 441e349600SKeerthy 451e349600SKeerthy static int lp87565_probe(struct i2c_client *client, 461e349600SKeerthy const struct i2c_device_id *ids) 471e349600SKeerthy { 481e349600SKeerthy struct lp87565 *lp87565; 491e349600SKeerthy const struct of_device_id *of_id; 501e349600SKeerthy int ret; 511e349600SKeerthy unsigned int otpid; 521e349600SKeerthy 531e349600SKeerthy lp87565 = devm_kzalloc(&client->dev, sizeof(*lp87565), GFP_KERNEL); 541e349600SKeerthy if (!lp87565) 551e349600SKeerthy return -ENOMEM; 561e349600SKeerthy 571e349600SKeerthy lp87565->dev = &client->dev; 581e349600SKeerthy 591e349600SKeerthy lp87565->regmap = devm_regmap_init_i2c(client, &lp87565_regmap_config); 601e349600SKeerthy if (IS_ERR(lp87565->regmap)) { 611e349600SKeerthy ret = PTR_ERR(lp87565->regmap); 621e349600SKeerthy dev_err(lp87565->dev, 631e349600SKeerthy "Failed to initialize register map: %d\n", ret); 641e349600SKeerthy return ret; 651e349600SKeerthy } 661e349600SKeerthy 671e349600SKeerthy ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid); 681e349600SKeerthy if (ret) { 691e349600SKeerthy dev_err(lp87565->dev, "Failed to read OTP ID\n"); 701e349600SKeerthy return ret; 711e349600SKeerthy } 721e349600SKeerthy 731e349600SKeerthy lp87565->rev = otpid & LP87565_OTP_REV_OTP_ID; 741e349600SKeerthy 751e349600SKeerthy of_id = of_match_device(of_lp87565_match_table, &client->dev); 761e349600SKeerthy if (of_id) 771e349600SKeerthy lp87565->dev_type = (enum lp87565_device_type)of_id->data; 781e349600SKeerthy 791e349600SKeerthy i2c_set_clientdata(client, lp87565); 801e349600SKeerthy 81ea3993a9SAxel Lin return devm_mfd_add_devices(lp87565->dev, PLATFORM_DEVID_AUTO, 82ea3993a9SAxel Lin lp87565_cells, ARRAY_SIZE(lp87565_cells), 83ea3993a9SAxel Lin NULL, 0, NULL); 841e349600SKeerthy } 851e349600SKeerthy 861e349600SKeerthy static const struct i2c_device_id lp87565_id_table[] = { 871e349600SKeerthy { "lp87565-q1", 0 }, 881e349600SKeerthy { }, 891e349600SKeerthy }; 901e349600SKeerthy MODULE_DEVICE_TABLE(i2c, lp87565_id_table); 911e349600SKeerthy 921e349600SKeerthy static struct i2c_driver lp87565_driver = { 931e349600SKeerthy .driver = { 941e349600SKeerthy .name = "lp87565", 951e349600SKeerthy .of_match_table = of_lp87565_match_table, 961e349600SKeerthy }, 971e349600SKeerthy .probe = lp87565_probe, 981e349600SKeerthy .id_table = lp87565_id_table, 991e349600SKeerthy }; 1001e349600SKeerthy module_i2c_driver(lp87565_driver); 1011e349600SKeerthy 1021e349600SKeerthy MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>"); 1031e349600SKeerthy MODULE_DESCRIPTION("lp87565 chip family Multi-Function Device driver"); 1041e349600SKeerthy MODULE_LICENSE("GPL v2"); 105