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 { 301e349600SKeerthy .compatible = "ti,lp87565-q1", 311e349600SKeerthy .data = (void *)LP87565_DEVICE_TYPE_LP87565_Q1, 321e349600SKeerthy }, 33013e868bSKeerthy { 34013e868bSKeerthy .compatible = "ti,lp87561-q1", 35013e868bSKeerthy .data = (void *)LP87565_DEVICE_TYPE_LP87561_Q1, 36013e868bSKeerthy }, 371e349600SKeerthy {} 381e349600SKeerthy }; 391e349600SKeerthy MODULE_DEVICE_TABLE(of, of_lp87565_match_table); 401e349600SKeerthy 411e349600SKeerthy static int lp87565_probe(struct i2c_client *client, 421e349600SKeerthy const struct i2c_device_id *ids) 431e349600SKeerthy { 441e349600SKeerthy struct lp87565 *lp87565; 451e349600SKeerthy const struct of_device_id *of_id; 461e349600SKeerthy int ret; 471e349600SKeerthy unsigned int otpid; 481e349600SKeerthy 491e349600SKeerthy lp87565 = devm_kzalloc(&client->dev, sizeof(*lp87565), GFP_KERNEL); 501e349600SKeerthy if (!lp87565) 511e349600SKeerthy return -ENOMEM; 521e349600SKeerthy 531e349600SKeerthy lp87565->dev = &client->dev; 541e349600SKeerthy 551e349600SKeerthy lp87565->regmap = devm_regmap_init_i2c(client, &lp87565_regmap_config); 561e349600SKeerthy if (IS_ERR(lp87565->regmap)) { 571e349600SKeerthy ret = PTR_ERR(lp87565->regmap); 581e349600SKeerthy dev_err(lp87565->dev, 591e349600SKeerthy "Failed to initialize register map: %d\n", ret); 601e349600SKeerthy return ret; 611e349600SKeerthy } 621e349600SKeerthy 631e349600SKeerthy ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid); 641e349600SKeerthy if (ret) { 651e349600SKeerthy dev_err(lp87565->dev, "Failed to read OTP ID\n"); 661e349600SKeerthy return ret; 671e349600SKeerthy } 681e349600SKeerthy 691e349600SKeerthy lp87565->rev = otpid & LP87565_OTP_REV_OTP_ID; 701e349600SKeerthy 711e349600SKeerthy of_id = of_match_device(of_lp87565_match_table, &client->dev); 721e349600SKeerthy if (of_id) 731e349600SKeerthy lp87565->dev_type = (enum lp87565_device_type)of_id->data; 741e349600SKeerthy 751e349600SKeerthy i2c_set_clientdata(client, lp87565); 761e349600SKeerthy 77ea3993a9SAxel Lin return devm_mfd_add_devices(lp87565->dev, PLATFORM_DEVID_AUTO, 78ea3993a9SAxel Lin lp87565_cells, ARRAY_SIZE(lp87565_cells), 79ea3993a9SAxel Lin NULL, 0, NULL); 801e349600SKeerthy } 811e349600SKeerthy 821e349600SKeerthy static const struct i2c_device_id lp87565_id_table[] = { 831e349600SKeerthy { "lp87565-q1", 0 }, 841e349600SKeerthy { }, 851e349600SKeerthy }; 861e349600SKeerthy MODULE_DEVICE_TABLE(i2c, lp87565_id_table); 871e349600SKeerthy 881e349600SKeerthy static struct i2c_driver lp87565_driver = { 891e349600SKeerthy .driver = { 901e349600SKeerthy .name = "lp87565", 911e349600SKeerthy .of_match_table = of_lp87565_match_table, 921e349600SKeerthy }, 931e349600SKeerthy .probe = lp87565_probe, 941e349600SKeerthy .id_table = lp87565_id_table, 951e349600SKeerthy }; 961e349600SKeerthy module_i2c_driver(lp87565_driver); 971e349600SKeerthy 981e349600SKeerthy MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>"); 991e349600SKeerthy MODULE_DESCRIPTION("lp87565 chip family Multi-Function Device driver"); 1001e349600SKeerthy MODULE_LICENSE("GPL v2"); 101