Linux Audio

Check our new training course

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