Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
  4 *
  5 * Author: Keerthy <j-keerthy@ti.com>
  6 */
  7
 
  8#include <linux/interrupt.h>
  9#include <linux/mfd/core.h>
 10#include <linux/module.h>
 11#include <linux/of_device.h>
 12#include <linux/regmap.h>
 13
 14#include <linux/mfd/lp87565.h>
 15
 16static const struct regmap_config lp87565_regmap_config = {
 17	.reg_bits = 8,
 18	.val_bits = 8,
 19	.max_register = LP87565_REG_MAX,
 20};
 21
 22static const struct mfd_cell lp87565_cells[] = {
 23	{ .name = "lp87565-q1-regulator", },
 24	{ .name = "lp87565-q1-gpio", },
 25};
 26
 27static const struct of_device_id of_lp87565_match_table[] = {
 28	{ .compatible = "ti,lp87565", },
 29	{
 
 
 
 
 30		.compatible = "ti,lp87565-q1",
 31		.data = (void *)LP87565_DEVICE_TYPE_LP87565_Q1,
 32	},
 33	{
 34		.compatible = "ti,lp87561-q1",
 35		.data = (void *)LP87565_DEVICE_TYPE_LP87561_Q1,
 36	},
 37	{}
 38};
 39MODULE_DEVICE_TABLE(of, of_lp87565_match_table);
 40
 41static int lp87565_probe(struct i2c_client *client,
 42			 const struct i2c_device_id *ids)
 43{
 44	struct lp87565 *lp87565;
 45	const struct of_device_id *of_id;
 46	int ret;
 47	unsigned int otpid;
 48
 49	lp87565 = devm_kzalloc(&client->dev, sizeof(*lp87565), GFP_KERNEL);
 50	if (!lp87565)
 51		return -ENOMEM;
 52
 53	lp87565->dev = &client->dev;
 54
 55	lp87565->regmap = devm_regmap_init_i2c(client, &lp87565_regmap_config);
 56	if (IS_ERR(lp87565->regmap)) {
 57		ret = PTR_ERR(lp87565->regmap);
 58		dev_err(lp87565->dev,
 59			"Failed to initialize register map: %d\n", ret);
 60		return ret;
 61	}
 62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 63	ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid);
 64	if (ret) {
 65		dev_err(lp87565->dev, "Failed to read OTP ID\n");
 66		return ret;
 67	}
 68
 69	lp87565->rev = otpid & LP87565_OTP_REV_OTP_ID;
 70
 71	of_id = of_match_device(of_lp87565_match_table, &client->dev);
 72	if (of_id)
 73		lp87565->dev_type = (enum lp87565_device_type)of_id->data;
 74
 75	i2c_set_clientdata(client, lp87565);
 76
 77	return devm_mfd_add_devices(lp87565->dev, PLATFORM_DEVID_AUTO,
 78				    lp87565_cells, ARRAY_SIZE(lp87565_cells),
 79				    NULL, 0, NULL);
 80}
 81
 
 
 
 
 
 
 
 82static const struct i2c_device_id lp87565_id_table[] = {
 83	{ "lp87565-q1", 0 },
 84	{ },
 85};
 86MODULE_DEVICE_TABLE(i2c, lp87565_id_table);
 87
 88static struct i2c_driver lp87565_driver = {
 89	.driver	= {
 90		.name	= "lp87565",
 91		.of_match_table = of_lp87565_match_table,
 92	},
 93	.probe = lp87565_probe,
 
 94	.id_table = lp87565_id_table,
 95};
 96module_i2c_driver(lp87565_driver);
 97
 98MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
 99MODULE_DESCRIPTION("lp87565 chip family Multi-Function Device driver");
100MODULE_LICENSE("GPL v2");
v6.2
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
  4 *
  5 * Author: Keerthy <j-keerthy@ti.com>
  6 */
  7
  8#include <linux/gpio/consumer.h>
  9#include <linux/interrupt.h>
 10#include <linux/mfd/core.h>
 11#include <linux/module.h>
 12#include <linux/of_device.h>
 13#include <linux/regmap.h>
 14
 15#include <linux/mfd/lp87565.h>
 16
 17static const struct regmap_config lp87565_regmap_config = {
 18	.reg_bits = 8,
 19	.val_bits = 8,
 20	.max_register = LP87565_REG_MAX,
 21};
 22
 23static const struct mfd_cell lp87565_cells[] = {
 24	{ .name = "lp87565-q1-regulator", },
 25	{ .name = "lp87565-q1-gpio", },
 26};
 27
 28static const struct of_device_id of_lp87565_match_table[] = {
 29	{ .compatible = "ti,lp87565", },
 30	{
 31		.compatible = "ti,lp87524-q1",
 32		.data = (void *)LP87565_DEVICE_TYPE_LP87524_Q1,
 33	},
 34	{
 35		.compatible = "ti,lp87565-q1",
 36		.data = (void *)LP87565_DEVICE_TYPE_LP87565_Q1,
 37	},
 38	{
 39		.compatible = "ti,lp87561-q1",
 40		.data = (void *)LP87565_DEVICE_TYPE_LP87561_Q1,
 41	},
 42	{}
 43};
 44MODULE_DEVICE_TABLE(of, of_lp87565_match_table);
 45
 46static int lp87565_probe(struct i2c_client *client)
 
 47{
 48	struct lp87565 *lp87565;
 49	const struct of_device_id *of_id;
 50	int ret;
 51	unsigned int otpid;
 52
 53	lp87565 = devm_kzalloc(&client->dev, sizeof(*lp87565), GFP_KERNEL);
 54	if (!lp87565)
 55		return -ENOMEM;
 56
 57	lp87565->dev = &client->dev;
 58
 59	lp87565->regmap = devm_regmap_init_i2c(client, &lp87565_regmap_config);
 60	if (IS_ERR(lp87565->regmap)) {
 61		ret = PTR_ERR(lp87565->regmap);
 62		dev_err(lp87565->dev,
 63			"Failed to initialize register map: %d\n", ret);
 64		return ret;
 65	}
 66
 67	lp87565->reset_gpio = devm_gpiod_get_optional(lp87565->dev, "reset",
 68						      GPIOD_OUT_LOW);
 69	if (IS_ERR(lp87565->reset_gpio)) {
 70		ret = PTR_ERR(lp87565->reset_gpio);
 71		if (ret == -EPROBE_DEFER)
 72			return ret;
 73	}
 74
 75	if (lp87565->reset_gpio) {
 76		gpiod_set_value_cansleep(lp87565->reset_gpio, 1);
 77		/* The minimum assertion time is undocumented, just guess */
 78		usleep_range(2000, 4000);
 79
 80		gpiod_set_value_cansleep(lp87565->reset_gpio, 0);
 81		/* Min 1.2 ms before first I2C transaction */
 82		usleep_range(1500, 3000);
 83	}
 84
 85	ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid);
 86	if (ret) {
 87		dev_err(lp87565->dev, "Failed to read OTP ID\n");
 88		return ret;
 89	}
 90
 91	lp87565->rev = otpid & LP87565_OTP_REV_OTP_ID;
 92
 93	of_id = of_match_device(of_lp87565_match_table, &client->dev);
 94	if (of_id)
 95		lp87565->dev_type = (enum lp87565_device_type)of_id->data;
 96
 97	i2c_set_clientdata(client, lp87565);
 98
 99	return devm_mfd_add_devices(lp87565->dev, PLATFORM_DEVID_AUTO,
100				    lp87565_cells, ARRAY_SIZE(lp87565_cells),
101				    NULL, 0, NULL);
102}
103
104static void lp87565_shutdown(struct i2c_client *client)
105{
106	struct lp87565 *lp87565 = i2c_get_clientdata(client);
107
108	gpiod_set_value_cansleep(lp87565->reset_gpio, 1);
109}
110
111static const struct i2c_device_id lp87565_id_table[] = {
112	{ "lp87565-q1", 0 },
113	{ },
114};
115MODULE_DEVICE_TABLE(i2c, lp87565_id_table);
116
117static struct i2c_driver lp87565_driver = {
118	.driver	= {
119		.name	= "lp87565",
120		.of_match_table = of_lp87565_match_table,
121	},
122	.probe_new = lp87565_probe,
123	.shutdown = lp87565_shutdown,
124	.id_table = lp87565_id_table,
125};
126module_i2c_driver(lp87565_driver);
127
128MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
129MODULE_DESCRIPTION("lp87565 chip family Multi-Function Device driver");
130MODULE_LICENSE("GPL v2");