hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/mfd/ti-lmu.c
....@@ -1,18 +1,15 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * TI LMU (Lighting Management Unit) Core Driver
34 *
45 * Copyright 2017 Texas Instruments
56 *
67 * Author: Milo Kim <milo.kim@ti.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129
1310 #include <linux/delay.h>
1411 #include <linux/err.h>
15
-#include <linux/gpio.h>
12
+#include <linux/gpio/consumer.h>
1613 #include <linux/i2c.h>
1714 #include <linux/kernel.h>
1815 #include <linux/mfd/core.h>
....@@ -21,28 +18,18 @@
2118 #include <linux/module.h>
2219 #include <linux/of.h>
2320 #include <linux/of_device.h>
24
-#include <linux/of_gpio.h>
2521 #include <linux/slab.h>
2622
2723 struct ti_lmu_data {
28
- struct mfd_cell *cells;
24
+ const struct mfd_cell *cells;
2925 int num_cells;
3026 unsigned int max_register;
3127 };
3228
3329 static int ti_lmu_enable_hw(struct ti_lmu *lmu, enum ti_lmu_id id)
3430 {
35
- int ret;
36
-
37
- if (gpio_is_valid(lmu->en_gpio)) {
38
- ret = devm_gpio_request_one(lmu->dev, lmu->en_gpio,
39
- GPIOF_OUT_INIT_HIGH, "lmu_hwen");
40
- if (ret) {
41
- dev_err(lmu->dev, "Can not request enable GPIO: %d\n",
42
- ret);
43
- return ret;
44
- }
45
- }
31
+ if (lmu->en_gpio)
32
+ gpiod_set_value(lmu->en_gpio, 1);
4633
4734 /* Delay about 1ms after HW enable pin control */
4835 usleep_range(1000, 1500);
....@@ -57,19 +44,12 @@
5744 return 0;
5845 }
5946
60
-static void ti_lmu_disable_hw(struct ti_lmu *lmu)
47
+static void ti_lmu_disable_hw(void *data)
6148 {
62
- if (gpio_is_valid(lmu->en_gpio))
63
- gpio_set_value(lmu->en_gpio, 0);
49
+ struct ti_lmu *lmu = data;
50
+ if (lmu->en_gpio)
51
+ gpiod_set_value(lmu->en_gpio, 0);
6452 }
65
-
66
-static struct mfd_cell lm3532_devices[] = {
67
- {
68
- .name = "ti-lmu-backlight",
69
- .id = LM3532,
70
- .of_compatible = "ti,lm3532-backlight",
71
- },
72
-};
7353
7454 #define LM363X_REGULATOR(_id) \
7555 { \
....@@ -78,7 +58,7 @@
7858 .of_compatible = "ti,lm363x-regulator", \
7959 } \
8060
81
-static struct mfd_cell lm3631_devices[] = {
61
+static const struct mfd_cell lm3631_devices[] = {
8262 LM363X_REGULATOR(LM3631_BOOST),
8363 LM363X_REGULATOR(LM3631_LDO_CONT),
8464 LM363X_REGULATOR(LM3631_LDO_OREF),
....@@ -91,7 +71,7 @@
9171 },
9272 };
9373
94
-static struct mfd_cell lm3632_devices[] = {
74
+static const struct mfd_cell lm3632_devices[] = {
9575 LM363X_REGULATOR(LM3632_BOOST),
9676 LM363X_REGULATOR(LM3632_LDO_POS),
9777 LM363X_REGULATOR(LM3632_LDO_NEG),
....@@ -102,7 +82,7 @@
10282 },
10383 };
10484
105
-static struct mfd_cell lm3633_devices[] = {
85
+static const struct mfd_cell lm3633_devices[] = {
10686 {
10787 .name = "ti-lmu-backlight",
10888 .id = LM3633,
....@@ -120,7 +100,7 @@
120100 },
121101 };
122102
123
-static struct mfd_cell lm3695_devices[] = {
103
+static const struct mfd_cell lm3695_devices[] = {
124104 {
125105 .name = "ti-lmu-backlight",
126106 .id = LM3695,
....@@ -128,17 +108,14 @@
128108 },
129109 };
130110
131
-static struct mfd_cell lm3697_devices[] = {
111
+static const struct mfd_cell lm36274_devices[] = {
112
+ LM363X_REGULATOR(LM36274_BOOST),
113
+ LM363X_REGULATOR(LM36274_LDO_POS),
114
+ LM363X_REGULATOR(LM36274_LDO_NEG),
132115 {
133
- .name = "ti-lmu-backlight",
134
- .id = LM3697,
135
- .of_compatible = "ti,lm3697-backlight",
136
- },
137
- /* Monitoring driver for open/short circuit detection */
138
- {
139
- .name = "ti-lmu-fault-monitor",
140
- .id = LM3697,
141
- .of_compatible = "ti,lm3697-fault-monitor",
116
+ .name = "lm36274-leds",
117
+ .id = LM36274,
118
+ .of_compatible = "ti,lm36274-backlight",
142119 },
143120 };
144121
....@@ -150,41 +127,27 @@
150127 .max_register = max_reg, \
151128 } \
152129
153
-TI_LMU_DATA(lm3532, LM3532_MAX_REG);
154130 TI_LMU_DATA(lm3631, LM3631_MAX_REG);
155131 TI_LMU_DATA(lm3632, LM3632_MAX_REG);
156132 TI_LMU_DATA(lm3633, LM3633_MAX_REG);
157133 TI_LMU_DATA(lm3695, LM3695_MAX_REG);
158
-TI_LMU_DATA(lm3697, LM3697_MAX_REG);
159
-
160
-static const struct of_device_id ti_lmu_of_match[] = {
161
- { .compatible = "ti,lm3532", .data = &lm3532_data },
162
- { .compatible = "ti,lm3631", .data = &lm3631_data },
163
- { .compatible = "ti,lm3632", .data = &lm3632_data },
164
- { .compatible = "ti,lm3633", .data = &lm3633_data },
165
- { .compatible = "ti,lm3695", .data = &lm3695_data },
166
- { .compatible = "ti,lm3697", .data = &lm3697_data },
167
- { }
168
-};
169
-MODULE_DEVICE_TABLE(of, ti_lmu_of_match);
134
+TI_LMU_DATA(lm36274, LM36274_MAX_REG);
170135
171136 static int ti_lmu_probe(struct i2c_client *cl, const struct i2c_device_id *id)
172137 {
173138 struct device *dev = &cl->dev;
174
- const struct of_device_id *match;
175139 const struct ti_lmu_data *data;
176140 struct regmap_config regmap_cfg;
177141 struct ti_lmu *lmu;
178142 int ret;
179143
180
- match = of_match_device(ti_lmu_of_match, dev);
181
- if (!match)
182
- return -ENODEV;
183144 /*
184145 * Get device specific data from of_match table.
185146 * This data is defined by using TI_LMU_DATA() macro.
186147 */
187
- data = (struct ti_lmu_data *)match->data;
148
+ data = of_device_get_match_data(dev);
149
+ if (!data)
150
+ return -ENODEV;
188151
189152 lmu = devm_kzalloc(dev, sizeof(*lmu), GFP_KERNEL);
190153 if (!lmu)
....@@ -204,8 +167,18 @@
204167 return PTR_ERR(lmu->regmap);
205168
206169 /* HW enable pin control and additional power up sequence if required */
207
- lmu->en_gpio = of_get_named_gpio(dev->of_node, "enable-gpios", 0);
170
+ lmu->en_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH);
171
+ if (IS_ERR(lmu->en_gpio)) {
172
+ ret = PTR_ERR(lmu->en_gpio);
173
+ dev_err(dev, "Can not request enable GPIO: %d\n", ret);
174
+ return ret;
175
+ }
176
+
208177 ret = ti_lmu_enable_hw(lmu, id->driver_data);
178
+ if (ret)
179
+ return ret;
180
+
181
+ ret = devm_add_action_or_reset(dev, ti_lmu_disable_hw, lmu);
209182 if (ret)
210183 return ret;
211184
....@@ -218,33 +191,32 @@
218191
219192 i2c_set_clientdata(cl, lmu);
220193
221
- return mfd_add_devices(lmu->dev, 0, data->cells,
222
- data->num_cells, NULL, 0, NULL);
194
+ return devm_mfd_add_devices(lmu->dev, 0, data->cells,
195
+ data->num_cells, NULL, 0, NULL);
223196 }
224197
225
-static int ti_lmu_remove(struct i2c_client *cl)
226
-{
227
- struct ti_lmu *lmu = i2c_get_clientdata(cl);
228
-
229
- ti_lmu_disable_hw(lmu);
230
- mfd_remove_devices(lmu->dev);
231
- return 0;
232
-}
198
+static const struct of_device_id ti_lmu_of_match[] = {
199
+ { .compatible = "ti,lm3631", .data = &lm3631_data },
200
+ { .compatible = "ti,lm3632", .data = &lm3632_data },
201
+ { .compatible = "ti,lm3633", .data = &lm3633_data },
202
+ { .compatible = "ti,lm3695", .data = &lm3695_data },
203
+ { .compatible = "ti,lm36274", .data = &lm36274_data },
204
+ { }
205
+};
206
+MODULE_DEVICE_TABLE(of, ti_lmu_of_match);
233207
234208 static const struct i2c_device_id ti_lmu_ids[] = {
235
- { "lm3532", LM3532 },
236209 { "lm3631", LM3631 },
237210 { "lm3632", LM3632 },
238211 { "lm3633", LM3633 },
239212 { "lm3695", LM3695 },
240
- { "lm3697", LM3697 },
213
+ { "lm36274", LM36274 },
241214 { }
242215 };
243216 MODULE_DEVICE_TABLE(i2c, ti_lmu_ids);
244217
245218 static struct i2c_driver ti_lmu_driver = {
246219 .probe = ti_lmu_probe,
247
- .remove = ti_lmu_remove,
248220 .driver = {
249221 .name = "ti-lmu",
250222 .of_match_table = ti_lmu_of_match,