Revert "unicode: Don't special case ignorable code points"
[linux.git] / drivers / mfd / ti-lmu.c
blobcfc9f88b984202123783050c208819d4b5f97edb
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * TI LMU (Lighting Management Unit) Core Driver
5 * Copyright 2017 Texas Instruments
7 * Author: Milo Kim <milo.kim@ti.com>
8 */
10 #include <linux/delay.h>
11 #include <linux/err.h>
12 #include <linux/gpio/consumer.h>
13 #include <linux/i2c.h>
14 #include <linux/kernel.h>
15 #include <linux/mfd/core.h>
16 #include <linux/mfd/ti-lmu.h>
17 #include <linux/mfd/ti-lmu-register.h>
18 #include <linux/module.h>
19 #include <linux/of.h>
20 #include <linux/slab.h>
22 struct ti_lmu_data {
23 const struct mfd_cell *cells;
24 int num_cells;
25 unsigned int max_register;
28 static int ti_lmu_enable_hw(struct ti_lmu *lmu, enum ti_lmu_id id)
30 if (lmu->en_gpio)
31 gpiod_set_value(lmu->en_gpio, 1);
33 /* Delay about 1ms after HW enable pin control */
34 usleep_range(1000, 1500);
36 /* LM3631 has additional power up sequence - enable LCD_EN bit. */
37 if (id == LM3631) {
38 return regmap_update_bits(lmu->regmap, LM3631_REG_DEVCTRL,
39 LM3631_LCD_EN_MASK,
40 LM3631_LCD_EN_MASK);
43 return 0;
46 static void ti_lmu_disable_hw(void *data)
48 struct ti_lmu *lmu = data;
49 if (lmu->en_gpio)
50 gpiod_set_value(lmu->en_gpio, 0);
53 #define LM363X_REGULATOR(_id) \
54 { \
55 .name = "lm363x-regulator", \
56 .id = _id, \
57 .of_compatible = "ti,lm363x-regulator", \
58 } \
60 static const struct mfd_cell lm3631_devices[] = {
61 LM363X_REGULATOR(LM3631_BOOST),
62 LM363X_REGULATOR(LM3631_LDO_CONT),
63 LM363X_REGULATOR(LM3631_LDO_OREF),
64 LM363X_REGULATOR(LM3631_LDO_POS),
65 LM363X_REGULATOR(LM3631_LDO_NEG),
67 .name = "ti-lmu-backlight",
68 .id = LM3631,
69 .of_compatible = "ti,lm3631-backlight",
73 static const struct mfd_cell lm3632_devices[] = {
74 LM363X_REGULATOR(LM3632_BOOST),
75 LM363X_REGULATOR(LM3632_LDO_POS),
76 LM363X_REGULATOR(LM3632_LDO_NEG),
78 .name = "ti-lmu-backlight",
79 .id = LM3632,
80 .of_compatible = "ti,lm3632-backlight",
84 static const struct mfd_cell lm3633_devices[] = {
86 .name = "ti-lmu-backlight",
87 .id = LM3633,
88 .of_compatible = "ti,lm3633-backlight",
91 .name = "lm3633-leds",
92 .of_compatible = "ti,lm3633-leds",
94 /* Monitoring driver for open/short circuit detection */
96 .name = "ti-lmu-fault-monitor",
97 .id = LM3633,
98 .of_compatible = "ti,lm3633-fault-monitor",
102 static const struct mfd_cell lm3695_devices[] = {
104 .name = "ti-lmu-backlight",
105 .id = LM3695,
106 .of_compatible = "ti,lm3695-backlight",
110 static const struct mfd_cell lm36274_devices[] = {
111 LM363X_REGULATOR(LM36274_BOOST),
112 LM363X_REGULATOR(LM36274_LDO_POS),
113 LM363X_REGULATOR(LM36274_LDO_NEG),
115 .name = "lm36274-leds",
116 .id = LM36274,
117 .of_compatible = "ti,lm36274-backlight",
121 #define TI_LMU_DATA(chip, max_reg) \
122 static const struct ti_lmu_data chip##_data = \
124 .cells = chip##_devices, \
125 .num_cells = ARRAY_SIZE(chip##_devices),\
126 .max_register = max_reg, \
129 TI_LMU_DATA(lm3631, LM3631_MAX_REG);
130 TI_LMU_DATA(lm3632, LM3632_MAX_REG);
131 TI_LMU_DATA(lm3633, LM3633_MAX_REG);
132 TI_LMU_DATA(lm3695, LM3695_MAX_REG);
133 TI_LMU_DATA(lm36274, LM36274_MAX_REG);
135 static int ti_lmu_probe(struct i2c_client *cl)
137 const struct i2c_device_id *id = i2c_client_get_device_id(cl);
138 struct device *dev = &cl->dev;
139 const struct ti_lmu_data *data;
140 struct regmap_config regmap_cfg;
141 struct ti_lmu *lmu;
142 int ret;
145 * Get device specific data from of_match table.
146 * This data is defined by using TI_LMU_DATA() macro.
148 data = of_device_get_match_data(dev);
149 if (!data)
150 return -ENODEV;
152 lmu = devm_kzalloc(dev, sizeof(*lmu), GFP_KERNEL);
153 if (!lmu)
154 return -ENOMEM;
156 lmu->dev = &cl->dev;
158 /* Setup regmap */
159 memset(&regmap_cfg, 0, sizeof(struct regmap_config));
160 regmap_cfg.reg_bits = 8;
161 regmap_cfg.val_bits = 8;
162 regmap_cfg.name = id->name;
163 regmap_cfg.max_register = data->max_register;
165 lmu->regmap = devm_regmap_init_i2c(cl, &regmap_cfg);
166 if (IS_ERR(lmu->regmap))
167 return PTR_ERR(lmu->regmap);
169 /* HW enable pin control and additional power up sequence if required */
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;
177 ret = ti_lmu_enable_hw(lmu, id->driver_data);
178 if (ret)
179 return ret;
181 ret = devm_add_action_or_reset(dev, ti_lmu_disable_hw, lmu);
182 if (ret)
183 return ret;
186 * Fault circuit(open/short) can be detected by ti-lmu-fault-monitor.
187 * After fault detection is done, some devices should re-initialize
188 * configuration. The notifier enables such kind of handling.
190 BLOCKING_INIT_NOTIFIER_HEAD(&lmu->notifier);
192 i2c_set_clientdata(cl, lmu);
194 return devm_mfd_add_devices(lmu->dev, 0, data->cells,
195 data->num_cells, NULL, 0, NULL);
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 },
206 MODULE_DEVICE_TABLE(of, ti_lmu_of_match);
208 static const struct i2c_device_id ti_lmu_ids[] = {
209 { "lm3631", LM3631 },
210 { "lm3632", LM3632 },
211 { "lm3633", LM3633 },
212 { "lm3695", LM3695 },
213 { "lm36274", LM36274 },
216 MODULE_DEVICE_TABLE(i2c, ti_lmu_ids);
218 static struct i2c_driver ti_lmu_driver = {
219 .probe = ti_lmu_probe,
220 .driver = {
221 .name = "ti-lmu",
222 .of_match_table = ti_lmu_of_match,
224 .id_table = ti_lmu_ids,
227 module_i2c_driver(ti_lmu_driver);
229 MODULE_DESCRIPTION("TI LMU MFD Core Driver");
230 MODULE_AUTHOR("Milo Kim");
231 MODULE_LICENSE("GPL v2");