.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * TI LMU (Lighting Management Unit) Core Driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright 2017 Texas Instruments |
---|
5 | 6 | * |
---|
6 | 7 | * 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. |
---|
11 | 8 | */ |
---|
12 | 9 | |
---|
13 | 10 | #include <linux/delay.h> |
---|
14 | 11 | #include <linux/err.h> |
---|
15 | | -#include <linux/gpio.h> |
---|
| 12 | +#include <linux/gpio/consumer.h> |
---|
16 | 13 | #include <linux/i2c.h> |
---|
17 | 14 | #include <linux/kernel.h> |
---|
18 | 15 | #include <linux/mfd/core.h> |
---|
.. | .. |
---|
21 | 18 | #include <linux/module.h> |
---|
22 | 19 | #include <linux/of.h> |
---|
23 | 20 | #include <linux/of_device.h> |
---|
24 | | -#include <linux/of_gpio.h> |
---|
25 | 21 | #include <linux/slab.h> |
---|
26 | 22 | |
---|
27 | 23 | struct ti_lmu_data { |
---|
28 | | - struct mfd_cell *cells; |
---|
| 24 | + const struct mfd_cell *cells; |
---|
29 | 25 | int num_cells; |
---|
30 | 26 | unsigned int max_register; |
---|
31 | 27 | }; |
---|
32 | 28 | |
---|
33 | 29 | static int ti_lmu_enable_hw(struct ti_lmu *lmu, enum ti_lmu_id id) |
---|
34 | 30 | { |
---|
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); |
---|
46 | 33 | |
---|
47 | 34 | /* Delay about 1ms after HW enable pin control */ |
---|
48 | 35 | usleep_range(1000, 1500); |
---|
.. | .. |
---|
57 | 44 | return 0; |
---|
58 | 45 | } |
---|
59 | 46 | |
---|
60 | | -static void ti_lmu_disable_hw(struct ti_lmu *lmu) |
---|
| 47 | +static void ti_lmu_disable_hw(void *data) |
---|
61 | 48 | { |
---|
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); |
---|
64 | 52 | } |
---|
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 | | -}; |
---|
73 | 53 | |
---|
74 | 54 | #define LM363X_REGULATOR(_id) \ |
---|
75 | 55 | { \ |
---|
.. | .. |
---|
78 | 58 | .of_compatible = "ti,lm363x-regulator", \ |
---|
79 | 59 | } \ |
---|
80 | 60 | |
---|
81 | | -static struct mfd_cell lm3631_devices[] = { |
---|
| 61 | +static const struct mfd_cell lm3631_devices[] = { |
---|
82 | 62 | LM363X_REGULATOR(LM3631_BOOST), |
---|
83 | 63 | LM363X_REGULATOR(LM3631_LDO_CONT), |
---|
84 | 64 | LM363X_REGULATOR(LM3631_LDO_OREF), |
---|
.. | .. |
---|
91 | 71 | }, |
---|
92 | 72 | }; |
---|
93 | 73 | |
---|
94 | | -static struct mfd_cell lm3632_devices[] = { |
---|
| 74 | +static const struct mfd_cell lm3632_devices[] = { |
---|
95 | 75 | LM363X_REGULATOR(LM3632_BOOST), |
---|
96 | 76 | LM363X_REGULATOR(LM3632_LDO_POS), |
---|
97 | 77 | LM363X_REGULATOR(LM3632_LDO_NEG), |
---|
.. | .. |
---|
102 | 82 | }, |
---|
103 | 83 | }; |
---|
104 | 84 | |
---|
105 | | -static struct mfd_cell lm3633_devices[] = { |
---|
| 85 | +static const struct mfd_cell lm3633_devices[] = { |
---|
106 | 86 | { |
---|
107 | 87 | .name = "ti-lmu-backlight", |
---|
108 | 88 | .id = LM3633, |
---|
.. | .. |
---|
120 | 100 | }, |
---|
121 | 101 | }; |
---|
122 | 102 | |
---|
123 | | -static struct mfd_cell lm3695_devices[] = { |
---|
| 103 | +static const struct mfd_cell lm3695_devices[] = { |
---|
124 | 104 | { |
---|
125 | 105 | .name = "ti-lmu-backlight", |
---|
126 | 106 | .id = LM3695, |
---|
.. | .. |
---|
128 | 108 | }, |
---|
129 | 109 | }; |
---|
130 | 110 | |
---|
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), |
---|
132 | 115 | { |
---|
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", |
---|
142 | 119 | }, |
---|
143 | 120 | }; |
---|
144 | 121 | |
---|
.. | .. |
---|
150 | 127 | .max_register = max_reg, \ |
---|
151 | 128 | } \ |
---|
152 | 129 | |
---|
153 | | -TI_LMU_DATA(lm3532, LM3532_MAX_REG); |
---|
154 | 130 | TI_LMU_DATA(lm3631, LM3631_MAX_REG); |
---|
155 | 131 | TI_LMU_DATA(lm3632, LM3632_MAX_REG); |
---|
156 | 132 | TI_LMU_DATA(lm3633, LM3633_MAX_REG); |
---|
157 | 133 | 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); |
---|
170 | 135 | |
---|
171 | 136 | static int ti_lmu_probe(struct i2c_client *cl, const struct i2c_device_id *id) |
---|
172 | 137 | { |
---|
173 | 138 | struct device *dev = &cl->dev; |
---|
174 | | - const struct of_device_id *match; |
---|
175 | 139 | const struct ti_lmu_data *data; |
---|
176 | 140 | struct regmap_config regmap_cfg; |
---|
177 | 141 | struct ti_lmu *lmu; |
---|
178 | 142 | int ret; |
---|
179 | 143 | |
---|
180 | | - match = of_match_device(ti_lmu_of_match, dev); |
---|
181 | | - if (!match) |
---|
182 | | - return -ENODEV; |
---|
183 | 144 | /* |
---|
184 | 145 | * Get device specific data from of_match table. |
---|
185 | 146 | * This data is defined by using TI_LMU_DATA() macro. |
---|
186 | 147 | */ |
---|
187 | | - data = (struct ti_lmu_data *)match->data; |
---|
| 148 | + data = of_device_get_match_data(dev); |
---|
| 149 | + if (!data) |
---|
| 150 | + return -ENODEV; |
---|
188 | 151 | |
---|
189 | 152 | lmu = devm_kzalloc(dev, sizeof(*lmu), GFP_KERNEL); |
---|
190 | 153 | if (!lmu) |
---|
.. | .. |
---|
204 | 167 | return PTR_ERR(lmu->regmap); |
---|
205 | 168 | |
---|
206 | 169 | /* 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 | + |
---|
208 | 177 | 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); |
---|
209 | 182 | if (ret) |
---|
210 | 183 | return ret; |
---|
211 | 184 | |
---|
.. | .. |
---|
218 | 191 | |
---|
219 | 192 | i2c_set_clientdata(cl, lmu); |
---|
220 | 193 | |
---|
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); |
---|
223 | 196 | } |
---|
224 | 197 | |
---|
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); |
---|
233 | 207 | |
---|
234 | 208 | static const struct i2c_device_id ti_lmu_ids[] = { |
---|
235 | | - { "lm3532", LM3532 }, |
---|
236 | 209 | { "lm3631", LM3631 }, |
---|
237 | 210 | { "lm3632", LM3632 }, |
---|
238 | 211 | { "lm3633", LM3633 }, |
---|
239 | 212 | { "lm3695", LM3695 }, |
---|
240 | | - { "lm3697", LM3697 }, |
---|
| 213 | + { "lm36274", LM36274 }, |
---|
241 | 214 | { } |
---|
242 | 215 | }; |
---|
243 | 216 | MODULE_DEVICE_TABLE(i2c, ti_lmu_ids); |
---|
244 | 217 | |
---|
245 | 218 | static struct i2c_driver ti_lmu_driver = { |
---|
246 | 219 | .probe = ti_lmu_probe, |
---|
247 | | - .remove = ti_lmu_remove, |
---|
248 | 220 | .driver = { |
---|
249 | 221 | .name = "ti-lmu", |
---|
250 | 222 | .of_match_table = ti_lmu_of_match, |
---|