xref: /openbmc/linux/drivers/mfd/lp87565.c (revision 013e868b)
11e349600SKeerthy /*
21e349600SKeerthy  * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
31e349600SKeerthy  *
41e349600SKeerthy  * Author: Keerthy <j-keerthy@ti.com>
51e349600SKeerthy  *
61e349600SKeerthy  * This program is free software; you can redistribute it and/or
71e349600SKeerthy  * modify it under the terms of the GNU General Public License as
81e349600SKeerthy  * published by the Free Software Foundation version 2.
91e349600SKeerthy  */
101e349600SKeerthy 
111e349600SKeerthy #include <linux/interrupt.h>
121e349600SKeerthy #include <linux/mfd/core.h>
131e349600SKeerthy #include <linux/module.h>
141e349600SKeerthy #include <linux/of_device.h>
151e349600SKeerthy #include <linux/regmap.h>
161e349600SKeerthy 
171e349600SKeerthy #include <linux/mfd/lp87565.h>
181e349600SKeerthy 
191e349600SKeerthy static const struct regmap_config lp87565_regmap_config = {
201e349600SKeerthy 	.reg_bits = 8,
211e349600SKeerthy 	.val_bits = 8,
221e349600SKeerthy 	.max_register = LP87565_REG_MAX,
231e349600SKeerthy };
241e349600SKeerthy 
251e349600SKeerthy static const struct mfd_cell lp87565_cells[] = {
261e349600SKeerthy 	{ .name = "lp87565-q1-regulator", },
271e349600SKeerthy 	{ .name = "lp87565-q1-gpio", },
281e349600SKeerthy };
291e349600SKeerthy 
301e349600SKeerthy static const struct of_device_id of_lp87565_match_table[] = {
311e349600SKeerthy 	{ .compatible = "ti,lp87565", },
321e349600SKeerthy 	{
331e349600SKeerthy 		.compatible = "ti,lp87565-q1",
341e349600SKeerthy 		.data = (void *)LP87565_DEVICE_TYPE_LP87565_Q1,
351e349600SKeerthy 	},
36013e868bSKeerthy 	{
37013e868bSKeerthy 		.compatible = "ti,lp87561-q1",
38013e868bSKeerthy 		.data = (void *)LP87565_DEVICE_TYPE_LP87561_Q1,
39013e868bSKeerthy 	},
401e349600SKeerthy 	{}
411e349600SKeerthy };
421e349600SKeerthy MODULE_DEVICE_TABLE(of, of_lp87565_match_table);
431e349600SKeerthy 
441e349600SKeerthy static int lp87565_probe(struct i2c_client *client,
451e349600SKeerthy 			 const struct i2c_device_id *ids)
461e349600SKeerthy {
471e349600SKeerthy 	struct lp87565 *lp87565;
481e349600SKeerthy 	const struct of_device_id *of_id;
491e349600SKeerthy 	int ret;
501e349600SKeerthy 	unsigned int otpid;
511e349600SKeerthy 
521e349600SKeerthy 	lp87565 = devm_kzalloc(&client->dev, sizeof(*lp87565), GFP_KERNEL);
531e349600SKeerthy 	if (!lp87565)
541e349600SKeerthy 		return -ENOMEM;
551e349600SKeerthy 
561e349600SKeerthy 	lp87565->dev = &client->dev;
571e349600SKeerthy 
581e349600SKeerthy 	lp87565->regmap = devm_regmap_init_i2c(client, &lp87565_regmap_config);
591e349600SKeerthy 	if (IS_ERR(lp87565->regmap)) {
601e349600SKeerthy 		ret = PTR_ERR(lp87565->regmap);
611e349600SKeerthy 		dev_err(lp87565->dev,
621e349600SKeerthy 			"Failed to initialize register map: %d\n", ret);
631e349600SKeerthy 		return ret;
641e349600SKeerthy 	}
651e349600SKeerthy 
661e349600SKeerthy 	ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid);
671e349600SKeerthy 	if (ret) {
681e349600SKeerthy 		dev_err(lp87565->dev, "Failed to read OTP ID\n");
691e349600SKeerthy 		return ret;
701e349600SKeerthy 	}
711e349600SKeerthy 
721e349600SKeerthy 	lp87565->rev = otpid & LP87565_OTP_REV_OTP_ID;
731e349600SKeerthy 
741e349600SKeerthy 	of_id = of_match_device(of_lp87565_match_table, &client->dev);
751e349600SKeerthy 	if (of_id)
761e349600SKeerthy 		lp87565->dev_type = (enum lp87565_device_type)of_id->data;
771e349600SKeerthy 
781e349600SKeerthy 	i2c_set_clientdata(client, lp87565);
791e349600SKeerthy 
80ea3993a9SAxel Lin 	return devm_mfd_add_devices(lp87565->dev, PLATFORM_DEVID_AUTO,
81ea3993a9SAxel Lin 				    lp87565_cells, ARRAY_SIZE(lp87565_cells),
82ea3993a9SAxel Lin 				    NULL, 0, NULL);
831e349600SKeerthy }
841e349600SKeerthy 
851e349600SKeerthy static const struct i2c_device_id lp87565_id_table[] = {
861e349600SKeerthy 	{ "lp87565-q1", 0 },
871e349600SKeerthy 	{ },
881e349600SKeerthy };
891e349600SKeerthy MODULE_DEVICE_TABLE(i2c, lp87565_id_table);
901e349600SKeerthy 
911e349600SKeerthy static struct i2c_driver lp87565_driver = {
921e349600SKeerthy 	.driver	= {
931e349600SKeerthy 		.name	= "lp87565",
941e349600SKeerthy 		.of_match_table = of_lp87565_match_table,
951e349600SKeerthy 	},
961e349600SKeerthy 	.probe = lp87565_probe,
971e349600SKeerthy 	.id_table = lp87565_id_table,
981e349600SKeerthy };
991e349600SKeerthy module_i2c_driver(lp87565_driver);
1001e349600SKeerthy 
1011e349600SKeerthy MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
1021e349600SKeerthy MODULE_DESCRIPTION("lp87565 chip family Multi-Function Device driver");
1031e349600SKeerthy MODULE_LICENSE("GPL v2");
104