16a1beee2SAxel Lin // SPDX-License-Identifier: GPL-2.0
26a1beee2SAxel Lin //
36a1beee2SAxel Lin // FAN53555 Fairchild Digitally Programmable TinyBuck Regulator Driver.
46a1beee2SAxel Lin //
56a1beee2SAxel Lin // Supported Part Numbers:
66a1beee2SAxel Lin // FAN53555UC00X/01X/03X/04X/05X
76a1beee2SAxel Lin //
86a1beee2SAxel Lin // Copyright (c) 2012 Marvell Technology Ltd.
96a1beee2SAxel Lin // Yunfan Zhang <yfzhang@marvell.com>
106a1beee2SAxel Lin
116bb18339SCristian Ciocaltea #include <linux/bitops.h>
1249d8c599SYunfan Zhang #include <linux/err.h>
134fb9a506SCristian Ciocaltea #include <linux/i2c.h>
144fb9a506SCristian Ciocaltea #include <linux/module.h>
15045a44d4SRob Herring #include <linux/of.h>
164fb9a506SCristian Ciocaltea #include <linux/param.h>
1749d8c599SYunfan Zhang #include <linux/platform_device.h>
184fb9a506SCristian Ciocaltea #include <linux/regmap.h>
1949d8c599SYunfan Zhang #include <linux/regulator/driver.h>
204fb9a506SCristian Ciocaltea #include <linux/regulator/fan53555.h>
2149d8c599SYunfan Zhang #include <linux/regulator/machine.h>
2291f23d8fSHeiko Stuebner #include <linux/regulator/of_regulator.h>
2349d8c599SYunfan Zhang #include <linux/slab.h>
2449d8c599SYunfan Zhang
2549d8c599SYunfan Zhang /* Voltage setting */
2649d8c599SYunfan Zhang #define FAN53555_VSEL0 0x00
2749d8c599SYunfan Zhang #define FAN53555_VSEL1 0x01
28914df8faSJoseph Chen
29a27e71a6SCristian Ciocaltea #define RK8602_VSEL0 0x06
30a27e71a6SCristian Ciocaltea #define RK8602_VSEL1 0x07
31a27e71a6SCristian Ciocaltea
32914df8faSJoseph Chen #define TCS4525_VSEL0 0x11
33914df8faSJoseph Chen #define TCS4525_VSEL1 0x10
34914df8faSJoseph Chen #define TCS4525_TIME 0x13
35914df8faSJoseph Chen #define TCS4525_COMMAND 0x14
36914df8faSJoseph Chen
3749d8c599SYunfan Zhang /* Control register */
3849d8c599SYunfan Zhang #define FAN53555_CONTROL 0x02
3949d8c599SYunfan Zhang /* IC Type */
4049d8c599SYunfan Zhang #define FAN53555_ID1 0x03
4149d8c599SYunfan Zhang /* IC mask version */
4249d8c599SYunfan Zhang #define FAN53555_ID2 0x04
4349d8c599SYunfan Zhang /* Monitor register */
4449d8c599SYunfan Zhang #define FAN53555_MONITOR 0x05
4549d8c599SYunfan Zhang
4649d8c599SYunfan Zhang /* VSEL bit definitions */
47d2501661SCristian Ciocaltea #define VSEL_BUCK_EN BIT(7)
48d2501661SCristian Ciocaltea #define VSEL_MODE BIT(6)
49*886fee35SYu Jiaoliang /* Chip ID and Version */
5049d8c599SYunfan Zhang #define DIE_ID 0x0F /* ID1 */
5149d8c599SYunfan Zhang #define DIE_REV 0x0F /* ID2 */
5249d8c599SYunfan Zhang /* Control bit definitions */
53d2501661SCristian Ciocaltea #define CTL_OUTPUT_DISCHG BIT(7)
54d2501661SCristian Ciocaltea #define CTL_SLEW_MASK GENMASK(6, 4)
55d2501661SCristian Ciocaltea #define CTL_RESET BIT(2)
56f2a9eb97SBjorn Andersson #define CTL_MODE_VSEL0_MODE BIT(0)
57f2a9eb97SBjorn Andersson #define CTL_MODE_VSEL1_MODE BIT(1)
5849d8c599SYunfan Zhang
5949d8c599SYunfan Zhang #define FAN53555_NVOLTAGES 64 /* Numbers of voltages */
60f2a9eb97SBjorn Andersson #define FAN53526_NVOLTAGES 128
61a27e71a6SCristian Ciocaltea #define RK8602_NVOLTAGES 160
62914df8faSJoseph Chen
63d2501661SCristian Ciocaltea #define TCS_VSEL0_MODE BIT(7)
64d2501661SCristian Ciocaltea #define TCS_VSEL1_MODE BIT(6)
65914df8faSJoseph Chen
66c5d5b55bSCristian Ciocaltea #define TCS_SLEW_MASK GENMASK(4, 3)
6749d8c599SYunfan Zhang
68ee30928aSHeiko Stuebner enum fan53555_vendor {
69f2a9eb97SBjorn Andersson FAN53526_VENDOR_FAIRCHILD = 0,
70f2a9eb97SBjorn Andersson FAN53555_VENDOR_FAIRCHILD,
71a27e71a6SCristian Ciocaltea FAN53555_VENDOR_ROCKCHIP, /* RK8600, RK8601 */
72a27e71a6SCristian Ciocaltea RK8602_VENDOR_ROCKCHIP, /* RK8602, RK8603 */
73ee30928aSHeiko Stuebner FAN53555_VENDOR_SILERGY,
74b3cc8ec0SPeter Geis FAN53526_VENDOR_TCS,
75ee30928aSHeiko Stuebner };
76ee30928aSHeiko Stuebner
77f2a9eb97SBjorn Andersson enum {
78f2a9eb97SBjorn Andersson FAN53526_CHIP_ID_01 = 1,
79f2a9eb97SBjorn Andersson };
80f2a9eb97SBjorn Andersson
81f2a9eb97SBjorn Andersson enum {
82f2a9eb97SBjorn Andersson FAN53526_CHIP_REV_08 = 8,
83f2a9eb97SBjorn Andersson };
84f2a9eb97SBjorn Andersson
8549d8c599SYunfan Zhang /* IC Type */
8649d8c599SYunfan Zhang enum {
8749d8c599SYunfan Zhang FAN53555_CHIP_ID_00 = 0,
8849d8c599SYunfan Zhang FAN53555_CHIP_ID_01,
8949d8c599SYunfan Zhang FAN53555_CHIP_ID_02,
9049d8c599SYunfan Zhang FAN53555_CHIP_ID_03,
9149d8c599SYunfan Zhang FAN53555_CHIP_ID_04,
9249d8c599SYunfan Zhang FAN53555_CHIP_ID_05,
935e39cf49SWadim Egorov FAN53555_CHIP_ID_08 = 8,
9449d8c599SYunfan Zhang };
9549d8c599SYunfan Zhang
96f9028dcdSPeter Geis enum {
97a27e71a6SCristian Ciocaltea RK8600_CHIP_ID_08 = 8, /* RK8600, RK8601 */
98a27e71a6SCristian Ciocaltea };
99a27e71a6SCristian Ciocaltea
100a27e71a6SCristian Ciocaltea enum {
101a27e71a6SCristian Ciocaltea RK8602_CHIP_ID_10 = 10, /* RK8602, RK8603 */
102a27e71a6SCristian Ciocaltea };
103a27e71a6SCristian Ciocaltea
104a27e71a6SCristian Ciocaltea enum {
105f9028dcdSPeter Geis TCS4525_CHIP_ID_12 = 12,
106f9028dcdSPeter Geis };
107f9028dcdSPeter Geis
1085eee5eceSRudi Heitbaum enum {
1095eee5eceSRudi Heitbaum TCS4526_CHIP_ID_00 = 0,
1105eee5eceSRudi Heitbaum };
1115eee5eceSRudi Heitbaum
112e57cbb70SWadim Egorov /* IC mask revision */
113e57cbb70SWadim Egorov enum {
114e57cbb70SWadim Egorov FAN53555_CHIP_REV_00 = 0x3,
115e57cbb70SWadim Egorov FAN53555_CHIP_REV_13 = 0xf,
116e57cbb70SWadim Egorov };
117e57cbb70SWadim Egorov
118ee30928aSHeiko Stuebner enum {
119ee30928aSHeiko Stuebner SILERGY_SYR82X = 8,
1205365e3dfSVasily Khoruzhick SILERGY_SYR83X = 9,
121ee30928aSHeiko Stuebner };
122ee30928aSHeiko Stuebner
12349d8c599SYunfan Zhang struct fan53555_device_info {
124ee30928aSHeiko Stuebner enum fan53555_vendor vendor;
12549d8c599SYunfan Zhang struct device *dev;
12649d8c599SYunfan Zhang struct regulator_desc desc;
12749d8c599SYunfan Zhang struct regulator_init_data *regulator;
12849d8c599SYunfan Zhang /* IC Type and Rev */
12949d8c599SYunfan Zhang int chip_id;
13049d8c599SYunfan Zhang int chip_rev;
13149d8c599SYunfan Zhang /* Voltage setting register */
13249d8c599SYunfan Zhang unsigned int vol_reg;
13349d8c599SYunfan Zhang unsigned int sleep_reg;
134a27e71a6SCristian Ciocaltea unsigned int en_reg;
135a27e71a6SCristian Ciocaltea unsigned int sleep_en_reg;
13649d8c599SYunfan Zhang /* Voltage range and step(linear) */
13749d8c599SYunfan Zhang unsigned int vsel_min;
13849d8c599SYunfan Zhang unsigned int vsel_step;
139f2a9eb97SBjorn Andersson unsigned int vsel_count;
140f2a9eb97SBjorn Andersson /* Mode */
141f2a9eb97SBjorn Andersson unsigned int mode_reg;
142f2a9eb97SBjorn Andersson unsigned int mode_mask;
14349d8c599SYunfan Zhang /* Sleep voltage cache */
14449d8c599SYunfan Zhang unsigned int sleep_vol_cache;
145914df8faSJoseph Chen /* Slew rate */
146914df8faSJoseph Chen unsigned int slew_reg;
147914df8faSJoseph Chen unsigned int slew_mask;
148b61ac767SAxel Lin const unsigned int *ramp_delay_table;
149b61ac767SAxel Lin unsigned int n_ramp_values;
150914df8faSJoseph Chen unsigned int slew_rate;
15149d8c599SYunfan Zhang };
15249d8c599SYunfan Zhang
fan53555_set_suspend_voltage(struct regulator_dev * rdev,int uV)15349d8c599SYunfan Zhang static int fan53555_set_suspend_voltage(struct regulator_dev *rdev, int uV)
15449d8c599SYunfan Zhang {
15549d8c599SYunfan Zhang struct fan53555_device_info *di = rdev_get_drvdata(rdev);
15649d8c599SYunfan Zhang int ret;
15749d8c599SYunfan Zhang
15849d8c599SYunfan Zhang if (di->sleep_vol_cache == uV)
15949d8c599SYunfan Zhang return 0;
16049d8c599SYunfan Zhang ret = regulator_map_voltage_linear(rdev, uV, uV);
16149d8c599SYunfan Zhang if (ret < 0)
162145fe1e1SSachin Kamat return ret;
163a69929c7SAxel Lin ret = regmap_update_bits(rdev->regmap, di->sleep_reg,
164f2a9eb97SBjorn Andersson di->desc.vsel_mask, ret);
16549d8c599SYunfan Zhang if (ret < 0)
166145fe1e1SSachin Kamat return ret;
16749d8c599SYunfan Zhang /* Cache the sleep voltage setting.
16849d8c599SYunfan Zhang * Might not be the real voltage which is rounded */
16949d8c599SYunfan Zhang di->sleep_vol_cache = uV;
17049d8c599SYunfan Zhang
17149d8c599SYunfan Zhang return 0;
17249d8c599SYunfan Zhang }
17349d8c599SYunfan Zhang
fan53555_set_suspend_enable(struct regulator_dev * rdev)174ab7cad33Szhangqing static int fan53555_set_suspend_enable(struct regulator_dev *rdev)
175ab7cad33Szhangqing {
176ab7cad33Szhangqing struct fan53555_device_info *di = rdev_get_drvdata(rdev);
177ab7cad33Szhangqing
178a27e71a6SCristian Ciocaltea return regmap_update_bits(rdev->regmap, di->sleep_en_reg,
179ab7cad33Szhangqing VSEL_BUCK_EN, VSEL_BUCK_EN);
180ab7cad33Szhangqing }
181ab7cad33Szhangqing
fan53555_set_suspend_disable(struct regulator_dev * rdev)182ab7cad33Szhangqing static int fan53555_set_suspend_disable(struct regulator_dev *rdev)
183ab7cad33Szhangqing {
184ab7cad33Szhangqing struct fan53555_device_info *di = rdev_get_drvdata(rdev);
185ab7cad33Szhangqing
186a27e71a6SCristian Ciocaltea return regmap_update_bits(rdev->regmap, di->sleep_en_reg,
187ab7cad33Szhangqing VSEL_BUCK_EN, 0);
188ab7cad33Szhangqing }
189ab7cad33Szhangqing
fan53555_set_mode(struct regulator_dev * rdev,unsigned int mode)19049d8c599SYunfan Zhang static int fan53555_set_mode(struct regulator_dev *rdev, unsigned int mode)
19149d8c599SYunfan Zhang {
19249d8c599SYunfan Zhang struct fan53555_device_info *di = rdev_get_drvdata(rdev);
19349d8c599SYunfan Zhang
19449d8c599SYunfan Zhang switch (mode) {
19549d8c599SYunfan Zhang case REGULATOR_MODE_FAST:
196a69929c7SAxel Lin regmap_update_bits(rdev->regmap, di->mode_reg,
197f2a9eb97SBjorn Andersson di->mode_mask, di->mode_mask);
19849d8c599SYunfan Zhang break;
19949d8c599SYunfan Zhang case REGULATOR_MODE_NORMAL:
200a69929c7SAxel Lin regmap_update_bits(rdev->regmap, di->vol_reg, di->mode_mask, 0);
20149d8c599SYunfan Zhang break;
20249d8c599SYunfan Zhang default:
20349d8c599SYunfan Zhang return -EINVAL;
20449d8c599SYunfan Zhang }
20549d8c599SYunfan Zhang return 0;
20649d8c599SYunfan Zhang }
20749d8c599SYunfan Zhang
fan53555_get_mode(struct regulator_dev * rdev)20849d8c599SYunfan Zhang static unsigned int fan53555_get_mode(struct regulator_dev *rdev)
20949d8c599SYunfan Zhang {
21049d8c599SYunfan Zhang struct fan53555_device_info *di = rdev_get_drvdata(rdev);
21149d8c599SYunfan Zhang unsigned int val;
21249d8c599SYunfan Zhang int ret = 0;
21349d8c599SYunfan Zhang
214a69929c7SAxel Lin ret = regmap_read(rdev->regmap, di->mode_reg, &val);
21549d8c599SYunfan Zhang if (ret < 0)
21649d8c599SYunfan Zhang return ret;
217f2a9eb97SBjorn Andersson if (val & di->mode_mask)
21849d8c599SYunfan Zhang return REGULATOR_MODE_FAST;
21949d8c599SYunfan Zhang else
22049d8c599SYunfan Zhang return REGULATOR_MODE_NORMAL;
22149d8c599SYunfan Zhang }
22249d8c599SYunfan Zhang
223b61ac767SAxel Lin static const unsigned int slew_rates[] = {
224dd7e71fbSHeiko Stuebner 64000,
225dd7e71fbSHeiko Stuebner 32000,
226dd7e71fbSHeiko Stuebner 16000,
227dd7e71fbSHeiko Stuebner 8000,
228dd7e71fbSHeiko Stuebner 4000,
229dd7e71fbSHeiko Stuebner 2000,
230dd7e71fbSHeiko Stuebner 1000,
231dd7e71fbSHeiko Stuebner 500,
232dd7e71fbSHeiko Stuebner };
233dd7e71fbSHeiko Stuebner
234b61ac767SAxel Lin static const unsigned int tcs_slew_rates[] = {
235914df8faSJoseph Chen 18700,
236914df8faSJoseph Chen 9300,
237914df8faSJoseph Chen 4600,
238914df8faSJoseph Chen 2300,
239914df8faSJoseph Chen };
240914df8faSJoseph Chen
24171880ab2SBhumika Goyal static const struct regulator_ops fan53555_regulator_ops = {
24249d8c599SYunfan Zhang .set_voltage_sel = regulator_set_voltage_sel_regmap,
24349d8c599SYunfan Zhang .get_voltage_sel = regulator_get_voltage_sel_regmap,
244fda87a42SHeiko Stuebner .set_voltage_time_sel = regulator_set_voltage_time_sel,
24549d8c599SYunfan Zhang .map_voltage = regulator_map_voltage_linear,
24649d8c599SYunfan Zhang .list_voltage = regulator_list_voltage_linear,
24749d8c599SYunfan Zhang .set_suspend_voltage = fan53555_set_suspend_voltage,
24849d8c599SYunfan Zhang .enable = regulator_enable_regmap,
24949d8c599SYunfan Zhang .disable = regulator_disable_regmap,
25049d8c599SYunfan Zhang .is_enabled = regulator_is_enabled_regmap,
25149d8c599SYunfan Zhang .set_mode = fan53555_set_mode,
25249d8c599SYunfan Zhang .get_mode = fan53555_get_mode,
253b61ac767SAxel Lin .set_ramp_delay = regulator_set_ramp_delay_regmap,
254ab7cad33Szhangqing .set_suspend_enable = fan53555_set_suspend_enable,
255ab7cad33Szhangqing .set_suspend_disable = fan53555_set_suspend_disable,
25649d8c599SYunfan Zhang };
25749d8c599SYunfan Zhang
fan53526_voltages_setup_fairchild(struct fan53555_device_info * di)258f2a9eb97SBjorn Andersson static int fan53526_voltages_setup_fairchild(struct fan53555_device_info *di)
259f2a9eb97SBjorn Andersson {
260f2a9eb97SBjorn Andersson /* Init voltage range and step */
261f2a9eb97SBjorn Andersson switch (di->chip_id) {
262f2a9eb97SBjorn Andersson case FAN53526_CHIP_ID_01:
263f2a9eb97SBjorn Andersson switch (di->chip_rev) {
264f2a9eb97SBjorn Andersson case FAN53526_CHIP_REV_08:
265f2a9eb97SBjorn Andersson di->vsel_min = 600000;
266f2a9eb97SBjorn Andersson di->vsel_step = 6250;
267f2a9eb97SBjorn Andersson break;
268f2a9eb97SBjorn Andersson default:
269f2a9eb97SBjorn Andersson dev_err(di->dev,
270f2a9eb97SBjorn Andersson "Chip ID %d with rev %d not supported!\n",
271f2a9eb97SBjorn Andersson di->chip_id, di->chip_rev);
272f2a9eb97SBjorn Andersson return -EINVAL;
273f2a9eb97SBjorn Andersson }
274f2a9eb97SBjorn Andersson break;
275f2a9eb97SBjorn Andersson default:
276f2a9eb97SBjorn Andersson dev_err(di->dev,
277f2a9eb97SBjorn Andersson "Chip ID %d not supported!\n", di->chip_id);
278f2a9eb97SBjorn Andersson return -EINVAL;
279f2a9eb97SBjorn Andersson }
280f2a9eb97SBjorn Andersson
28130b38b80SAxel Lin di->slew_reg = FAN53555_CONTROL;
28230b38b80SAxel Lin di->slew_mask = CTL_SLEW_MASK;
283b61ac767SAxel Lin di->ramp_delay_table = slew_rates;
284b61ac767SAxel Lin di->n_ramp_values = ARRAY_SIZE(slew_rates);
285f2a9eb97SBjorn Andersson di->vsel_count = FAN53526_NVOLTAGES;
286f2a9eb97SBjorn Andersson
287f2a9eb97SBjorn Andersson return 0;
288f2a9eb97SBjorn Andersson }
289f2a9eb97SBjorn Andersson
fan53555_voltages_setup_fairchild(struct fan53555_device_info * di)290ee30928aSHeiko Stuebner static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di)
29149d8c599SYunfan Zhang {
29249d8c599SYunfan Zhang /* Init voltage range and step */
29349d8c599SYunfan Zhang switch (di->chip_id) {
29449d8c599SYunfan Zhang case FAN53555_CHIP_ID_00:
295e57cbb70SWadim Egorov switch (di->chip_rev) {
296e57cbb70SWadim Egorov case FAN53555_CHIP_REV_00:
297e57cbb70SWadim Egorov di->vsel_min = 600000;
298e57cbb70SWadim Egorov di->vsel_step = 10000;
299e57cbb70SWadim Egorov break;
300e57cbb70SWadim Egorov case FAN53555_CHIP_REV_13:
301e57cbb70SWadim Egorov di->vsel_min = 800000;
302e57cbb70SWadim Egorov di->vsel_step = 10000;
303e57cbb70SWadim Egorov break;
304e57cbb70SWadim Egorov default:
305e57cbb70SWadim Egorov dev_err(di->dev,
306e57cbb70SWadim Egorov "Chip ID %d with rev %d not supported!\n",
307e57cbb70SWadim Egorov di->chip_id, di->chip_rev);
308e57cbb70SWadim Egorov return -EINVAL;
309e57cbb70SWadim Egorov }
310e57cbb70SWadim Egorov break;
31149d8c599SYunfan Zhang case FAN53555_CHIP_ID_01:
31249d8c599SYunfan Zhang case FAN53555_CHIP_ID_03:
31349d8c599SYunfan Zhang case FAN53555_CHIP_ID_05:
3145e39cf49SWadim Egorov case FAN53555_CHIP_ID_08:
31549d8c599SYunfan Zhang di->vsel_min = 600000;
31649d8c599SYunfan Zhang di->vsel_step = 10000;
31749d8c599SYunfan Zhang break;
31849d8c599SYunfan Zhang case FAN53555_CHIP_ID_04:
31949d8c599SYunfan Zhang di->vsel_min = 603000;
32049d8c599SYunfan Zhang di->vsel_step = 12826;
32149d8c599SYunfan Zhang break;
32249d8c599SYunfan Zhang default:
32349d8c599SYunfan Zhang dev_err(di->dev,
324ee30928aSHeiko Stuebner "Chip ID %d not supported!\n", di->chip_id);
32549d8c599SYunfan Zhang return -EINVAL;
32649d8c599SYunfan Zhang }
327914df8faSJoseph Chen di->slew_reg = FAN53555_CONTROL;
328914df8faSJoseph Chen di->slew_mask = CTL_SLEW_MASK;
329b61ac767SAxel Lin di->ramp_delay_table = slew_rates;
330b61ac767SAxel Lin di->n_ramp_values = ARRAY_SIZE(slew_rates);
331f2a9eb97SBjorn Andersson di->vsel_count = FAN53555_NVOLTAGES;
332f2a9eb97SBjorn Andersson
333dd7e71fbSHeiko Stuebner return 0;
33449d8c599SYunfan Zhang }
33549d8c599SYunfan Zhang
fan53555_voltages_setup_rockchip(struct fan53555_device_info * di)336a27e71a6SCristian Ciocaltea static int fan53555_voltages_setup_rockchip(struct fan53555_device_info *di)
337a27e71a6SCristian Ciocaltea {
338a27e71a6SCristian Ciocaltea /* Init voltage range and step */
339a27e71a6SCristian Ciocaltea switch (di->chip_id) {
340a27e71a6SCristian Ciocaltea case RK8600_CHIP_ID_08:
341a27e71a6SCristian Ciocaltea di->vsel_min = 712500;
342a27e71a6SCristian Ciocaltea di->vsel_step = 12500;
343a27e71a6SCristian Ciocaltea break;
344a27e71a6SCristian Ciocaltea default:
345a27e71a6SCristian Ciocaltea dev_err(di->dev,
346a27e71a6SCristian Ciocaltea "Chip ID %d not supported!\n", di->chip_id);
347a27e71a6SCristian Ciocaltea return -EINVAL;
348a27e71a6SCristian Ciocaltea }
349a27e71a6SCristian Ciocaltea di->slew_reg = FAN53555_CONTROL;
350a27e71a6SCristian Ciocaltea di->slew_mask = CTL_SLEW_MASK;
351a27e71a6SCristian Ciocaltea di->ramp_delay_table = slew_rates;
352a27e71a6SCristian Ciocaltea di->n_ramp_values = ARRAY_SIZE(slew_rates);
353a27e71a6SCristian Ciocaltea di->vsel_count = FAN53555_NVOLTAGES;
354a27e71a6SCristian Ciocaltea
355a27e71a6SCristian Ciocaltea return 0;
356a27e71a6SCristian Ciocaltea }
357a27e71a6SCristian Ciocaltea
rk8602_voltages_setup_rockchip(struct fan53555_device_info * di)358a27e71a6SCristian Ciocaltea static int rk8602_voltages_setup_rockchip(struct fan53555_device_info *di)
359a27e71a6SCristian Ciocaltea {
360a27e71a6SCristian Ciocaltea /* Init voltage range and step */
361a27e71a6SCristian Ciocaltea switch (di->chip_id) {
362a27e71a6SCristian Ciocaltea case RK8602_CHIP_ID_10:
363a27e71a6SCristian Ciocaltea di->vsel_min = 500000;
364a27e71a6SCristian Ciocaltea di->vsel_step = 6250;
365a27e71a6SCristian Ciocaltea break;
366a27e71a6SCristian Ciocaltea default:
367a27e71a6SCristian Ciocaltea dev_err(di->dev,
368a27e71a6SCristian Ciocaltea "Chip ID %d not supported!\n", di->chip_id);
369a27e71a6SCristian Ciocaltea return -EINVAL;
370a27e71a6SCristian Ciocaltea }
371a27e71a6SCristian Ciocaltea di->slew_reg = FAN53555_CONTROL;
372a27e71a6SCristian Ciocaltea di->slew_mask = CTL_SLEW_MASK;
373a27e71a6SCristian Ciocaltea di->ramp_delay_table = slew_rates;
374a27e71a6SCristian Ciocaltea di->n_ramp_values = ARRAY_SIZE(slew_rates);
375a27e71a6SCristian Ciocaltea di->vsel_count = RK8602_NVOLTAGES;
376a27e71a6SCristian Ciocaltea
377a27e71a6SCristian Ciocaltea return 0;
378a27e71a6SCristian Ciocaltea }
379a27e71a6SCristian Ciocaltea
fan53555_voltages_setup_silergy(struct fan53555_device_info * di)380ee30928aSHeiko Stuebner static int fan53555_voltages_setup_silergy(struct fan53555_device_info *di)
381ee30928aSHeiko Stuebner {
382ee30928aSHeiko Stuebner /* Init voltage range and step */
383ee30928aSHeiko Stuebner switch (di->chip_id) {
384ee30928aSHeiko Stuebner case SILERGY_SYR82X:
3855365e3dfSVasily Khoruzhick case SILERGY_SYR83X:
386ee30928aSHeiko Stuebner di->vsel_min = 712500;
387ee30928aSHeiko Stuebner di->vsel_step = 12500;
388ee30928aSHeiko Stuebner break;
389ee30928aSHeiko Stuebner default:
390ee30928aSHeiko Stuebner dev_err(di->dev,
391ee30928aSHeiko Stuebner "Chip ID %d not supported!\n", di->chip_id);
392ee30928aSHeiko Stuebner return -EINVAL;
393ee30928aSHeiko Stuebner }
394914df8faSJoseph Chen di->slew_reg = FAN53555_CONTROL;
395914df8faSJoseph Chen di->slew_mask = CTL_SLEW_MASK;
396b61ac767SAxel Lin di->ramp_delay_table = slew_rates;
397b61ac767SAxel Lin di->n_ramp_values = ARRAY_SIZE(slew_rates);
398f2a9eb97SBjorn Andersson di->vsel_count = FAN53555_NVOLTAGES;
399f2a9eb97SBjorn Andersson
400ee30928aSHeiko Stuebner return 0;
401ee30928aSHeiko Stuebner }
402ee30928aSHeiko Stuebner
fan53526_voltages_setup_tcs(struct fan53555_device_info * di)403b3cc8ec0SPeter Geis static int fan53526_voltages_setup_tcs(struct fan53555_device_info *di)
404914df8faSJoseph Chen {
405f9028dcdSPeter Geis switch (di->chip_id) {
406f9028dcdSPeter Geis case TCS4525_CHIP_ID_12:
4075eee5eceSRudi Heitbaum case TCS4526_CHIP_ID_00:
408914df8faSJoseph Chen di->slew_reg = TCS4525_TIME;
409914df8faSJoseph Chen di->slew_mask = TCS_SLEW_MASK;
410b61ac767SAxel Lin di->ramp_delay_table = tcs_slew_rates;
411b61ac767SAxel Lin di->n_ramp_values = ARRAY_SIZE(tcs_slew_rates);
412914df8faSJoseph Chen
413914df8faSJoseph Chen /* Init voltage range and step */
414914df8faSJoseph Chen di->vsel_min = 600000;
415914df8faSJoseph Chen di->vsel_step = 6250;
416d4db69ebSPeter Geis di->vsel_count = FAN53526_NVOLTAGES;
417f9028dcdSPeter Geis break;
418f9028dcdSPeter Geis default:
419f9028dcdSPeter Geis dev_err(di->dev, "Chip ID %d not supported!\n", di->chip_id);
420f9028dcdSPeter Geis return -EINVAL;
421f9028dcdSPeter Geis }
422914df8faSJoseph Chen
423914df8faSJoseph Chen return 0;
424914df8faSJoseph Chen }
425914df8faSJoseph Chen
426ee30928aSHeiko Stuebner /* For 00,01,03,05 options:
427ee30928aSHeiko Stuebner * VOUT = 0.60V + NSELx * 10mV, from 0.60 to 1.23V.
428ee30928aSHeiko Stuebner * For 04 option:
429ee30928aSHeiko Stuebner * VOUT = 0.603V + NSELx * 12.826mV, from 0.603 to 1.411V.
430ee30928aSHeiko Stuebner * */
fan53555_device_setup(struct fan53555_device_info * di,struct fan53555_platform_data * pdata)431ee30928aSHeiko Stuebner static int fan53555_device_setup(struct fan53555_device_info *di,
432ee30928aSHeiko Stuebner struct fan53555_platform_data *pdata)
433ee30928aSHeiko Stuebner {
434ee30928aSHeiko Stuebner int ret = 0;
435ee30928aSHeiko Stuebner
436ee30928aSHeiko Stuebner /* Setup voltage control register */
437914df8faSJoseph Chen switch (di->vendor) {
438914df8faSJoseph Chen case FAN53526_VENDOR_FAIRCHILD:
439914df8faSJoseph Chen case FAN53555_VENDOR_FAIRCHILD:
440a27e71a6SCristian Ciocaltea case FAN53555_VENDOR_ROCKCHIP:
441914df8faSJoseph Chen case FAN53555_VENDOR_SILERGY:
442ee30928aSHeiko Stuebner switch (pdata->sleep_vsel_id) {
443ee30928aSHeiko Stuebner case FAN53555_VSEL_ID_0:
444ee30928aSHeiko Stuebner di->sleep_reg = FAN53555_VSEL0;
445ee30928aSHeiko Stuebner di->vol_reg = FAN53555_VSEL1;
446ee30928aSHeiko Stuebner break;
447ee30928aSHeiko Stuebner case FAN53555_VSEL_ID_1:
448ee30928aSHeiko Stuebner di->sleep_reg = FAN53555_VSEL1;
449ee30928aSHeiko Stuebner di->vol_reg = FAN53555_VSEL0;
450ee30928aSHeiko Stuebner break;
451ee30928aSHeiko Stuebner default:
452ee30928aSHeiko Stuebner dev_err(di->dev, "Invalid VSEL ID!\n");
453ee30928aSHeiko Stuebner return -EINVAL;
454ee30928aSHeiko Stuebner }
455a27e71a6SCristian Ciocaltea di->sleep_en_reg = di->sleep_reg;
456a27e71a6SCristian Ciocaltea di->en_reg = di->vol_reg;
457a27e71a6SCristian Ciocaltea break;
458a27e71a6SCristian Ciocaltea case RK8602_VENDOR_ROCKCHIP:
459a27e71a6SCristian Ciocaltea switch (pdata->sleep_vsel_id) {
460a27e71a6SCristian Ciocaltea case FAN53555_VSEL_ID_0:
461a27e71a6SCristian Ciocaltea di->sleep_reg = RK8602_VSEL0;
462a27e71a6SCristian Ciocaltea di->vol_reg = RK8602_VSEL1;
463a27e71a6SCristian Ciocaltea di->sleep_en_reg = FAN53555_VSEL0;
464a27e71a6SCristian Ciocaltea di->en_reg = FAN53555_VSEL1;
465a27e71a6SCristian Ciocaltea break;
466a27e71a6SCristian Ciocaltea case FAN53555_VSEL_ID_1:
467a27e71a6SCristian Ciocaltea di->sleep_reg = RK8602_VSEL1;
468a27e71a6SCristian Ciocaltea di->vol_reg = RK8602_VSEL0;
469a27e71a6SCristian Ciocaltea di->sleep_en_reg = FAN53555_VSEL1;
470a27e71a6SCristian Ciocaltea di->en_reg = FAN53555_VSEL0;
471a27e71a6SCristian Ciocaltea break;
472a27e71a6SCristian Ciocaltea default:
473a27e71a6SCristian Ciocaltea dev_err(di->dev, "Invalid VSEL ID!\n");
474a27e71a6SCristian Ciocaltea return -EINVAL;
475a27e71a6SCristian Ciocaltea }
476914df8faSJoseph Chen break;
477b3cc8ec0SPeter Geis case FAN53526_VENDOR_TCS:
478914df8faSJoseph Chen switch (pdata->sleep_vsel_id) {
479914df8faSJoseph Chen case FAN53555_VSEL_ID_0:
480914df8faSJoseph Chen di->sleep_reg = TCS4525_VSEL0;
481914df8faSJoseph Chen di->vol_reg = TCS4525_VSEL1;
482914df8faSJoseph Chen break;
483914df8faSJoseph Chen case FAN53555_VSEL_ID_1:
484914df8faSJoseph Chen di->sleep_reg = TCS4525_VSEL1;
485914df8faSJoseph Chen di->vol_reg = TCS4525_VSEL0;
486914df8faSJoseph Chen break;
487914df8faSJoseph Chen default:
488914df8faSJoseph Chen dev_err(di->dev, "Invalid VSEL ID!\n");
489914df8faSJoseph Chen return -EINVAL;
490914df8faSJoseph Chen }
491a27e71a6SCristian Ciocaltea di->sleep_en_reg = di->sleep_reg;
492a27e71a6SCristian Ciocaltea di->en_reg = di->vol_reg;
493914df8faSJoseph Chen break;
494914df8faSJoseph Chen default:
495914df8faSJoseph Chen dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
496914df8faSJoseph Chen return -EINVAL;
497914df8faSJoseph Chen }
498ee30928aSHeiko Stuebner
499f2a9eb97SBjorn Andersson /* Setup mode control register */
500ee30928aSHeiko Stuebner switch (di->vendor) {
501f2a9eb97SBjorn Andersson case FAN53526_VENDOR_FAIRCHILD:
502f2a9eb97SBjorn Andersson di->mode_reg = FAN53555_CONTROL;
503f2a9eb97SBjorn Andersson
504f2a9eb97SBjorn Andersson switch (pdata->sleep_vsel_id) {
505f2a9eb97SBjorn Andersson case FAN53555_VSEL_ID_0:
506f2a9eb97SBjorn Andersson di->mode_mask = CTL_MODE_VSEL1_MODE;
507f2a9eb97SBjorn Andersson break;
508f2a9eb97SBjorn Andersson case FAN53555_VSEL_ID_1:
509f2a9eb97SBjorn Andersson di->mode_mask = CTL_MODE_VSEL0_MODE;
510f2a9eb97SBjorn Andersson break;
511f2a9eb97SBjorn Andersson }
512f2a9eb97SBjorn Andersson break;
513f2a9eb97SBjorn Andersson case FAN53555_VENDOR_FAIRCHILD:
514a27e71a6SCristian Ciocaltea case FAN53555_VENDOR_ROCKCHIP:
515f2a9eb97SBjorn Andersson case FAN53555_VENDOR_SILERGY:
516f2a9eb97SBjorn Andersson di->mode_reg = di->vol_reg;
517f2a9eb97SBjorn Andersson di->mode_mask = VSEL_MODE;
518f2a9eb97SBjorn Andersson break;
519a27e71a6SCristian Ciocaltea case RK8602_VENDOR_ROCKCHIP:
520a27e71a6SCristian Ciocaltea di->mode_mask = VSEL_MODE;
521a27e71a6SCristian Ciocaltea
522a27e71a6SCristian Ciocaltea switch (pdata->sleep_vsel_id) {
523a27e71a6SCristian Ciocaltea case FAN53555_VSEL_ID_0:
524a27e71a6SCristian Ciocaltea di->mode_reg = FAN53555_VSEL1;
525a27e71a6SCristian Ciocaltea break;
526a27e71a6SCristian Ciocaltea case FAN53555_VSEL_ID_1:
527a27e71a6SCristian Ciocaltea di->mode_reg = FAN53555_VSEL0;
528a27e71a6SCristian Ciocaltea break;
529a27e71a6SCristian Ciocaltea }
530a27e71a6SCristian Ciocaltea break;
531b3cc8ec0SPeter Geis case FAN53526_VENDOR_TCS:
532914df8faSJoseph Chen di->mode_reg = TCS4525_COMMAND;
533914df8faSJoseph Chen
534914df8faSJoseph Chen switch (pdata->sleep_vsel_id) {
535914df8faSJoseph Chen case FAN53555_VSEL_ID_0:
536914df8faSJoseph Chen di->mode_mask = TCS_VSEL1_MODE;
537914df8faSJoseph Chen break;
538914df8faSJoseph Chen case FAN53555_VSEL_ID_1:
539914df8faSJoseph Chen di->mode_mask = TCS_VSEL0_MODE;
540914df8faSJoseph Chen break;
541914df8faSJoseph Chen }
542914df8faSJoseph Chen break;
543f2a9eb97SBjorn Andersson default:
544f2a9eb97SBjorn Andersson dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
545f2a9eb97SBjorn Andersson return -EINVAL;
546f2a9eb97SBjorn Andersson }
547f2a9eb97SBjorn Andersson
548f2a9eb97SBjorn Andersson /* Setup voltage range */
549f2a9eb97SBjorn Andersson switch (di->vendor) {
550f2a9eb97SBjorn Andersson case FAN53526_VENDOR_FAIRCHILD:
551f2a9eb97SBjorn Andersson ret = fan53526_voltages_setup_fairchild(di);
552f2a9eb97SBjorn Andersson break;
553ee30928aSHeiko Stuebner case FAN53555_VENDOR_FAIRCHILD:
554ee30928aSHeiko Stuebner ret = fan53555_voltages_setup_fairchild(di);
555ee30928aSHeiko Stuebner break;
556a27e71a6SCristian Ciocaltea case FAN53555_VENDOR_ROCKCHIP:
557a27e71a6SCristian Ciocaltea ret = fan53555_voltages_setup_rockchip(di);
558a27e71a6SCristian Ciocaltea break;
559a27e71a6SCristian Ciocaltea case RK8602_VENDOR_ROCKCHIP:
560a27e71a6SCristian Ciocaltea ret = rk8602_voltages_setup_rockchip(di);
561a27e71a6SCristian Ciocaltea break;
562ee30928aSHeiko Stuebner case FAN53555_VENDOR_SILERGY:
563ee30928aSHeiko Stuebner ret = fan53555_voltages_setup_silergy(di);
564ee30928aSHeiko Stuebner break;
565b3cc8ec0SPeter Geis case FAN53526_VENDOR_TCS:
566b3cc8ec0SPeter Geis ret = fan53526_voltages_setup_tcs(di);
567914df8faSJoseph Chen break;
568ee30928aSHeiko Stuebner default:
569fe230531SAxel Lin dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
570ee30928aSHeiko Stuebner return -EINVAL;
571ee30928aSHeiko Stuebner }
572ee30928aSHeiko Stuebner
573ee30928aSHeiko Stuebner return ret;
574ee30928aSHeiko Stuebner }
575ee30928aSHeiko Stuebner
fan53555_regulator_register(struct fan53555_device_info * di,struct regulator_config * config)57649d8c599SYunfan Zhang static int fan53555_regulator_register(struct fan53555_device_info *di,
57749d8c599SYunfan Zhang struct regulator_config *config)
57849d8c599SYunfan Zhang {
57949d8c599SYunfan Zhang struct regulator_desc *rdesc = &di->desc;
580a69929c7SAxel Lin struct regulator_dev *rdev;
58149d8c599SYunfan Zhang
58249d8c599SYunfan Zhang rdesc->name = "fan53555-reg";
5833415d601SHeiko Stuebner rdesc->supply_name = "vin";
58449d8c599SYunfan Zhang rdesc->ops = &fan53555_regulator_ops;
58549d8c599SYunfan Zhang rdesc->type = REGULATOR_VOLTAGE;
586f2a9eb97SBjorn Andersson rdesc->n_voltages = di->vsel_count;
587a27e71a6SCristian Ciocaltea rdesc->enable_reg = di->en_reg;
58849d8c599SYunfan Zhang rdesc->enable_mask = VSEL_BUCK_EN;
58949d8c599SYunfan Zhang rdesc->min_uV = di->vsel_min;
59049d8c599SYunfan Zhang rdesc->uV_step = di->vsel_step;
59149d8c599SYunfan Zhang rdesc->vsel_reg = di->vol_reg;
5926bb18339SCristian Ciocaltea rdesc->vsel_mask = BIT(fls(di->vsel_count - 1)) - 1;
593b61ac767SAxel Lin rdesc->ramp_reg = di->slew_reg;
594b61ac767SAxel Lin rdesc->ramp_mask = di->slew_mask;
595b61ac767SAxel Lin rdesc->ramp_delay_table = di->ramp_delay_table;
596b61ac767SAxel Lin rdesc->n_ramp_values = di->n_ramp_values;
59749d8c599SYunfan Zhang rdesc->owner = THIS_MODULE;
59849d8c599SYunfan Zhang
599a69929c7SAxel Lin rdev = devm_regulator_register(di->dev, &di->desc, config);
600a69929c7SAxel Lin return PTR_ERR_OR_ZERO(rdev);
60149d8c599SYunfan Zhang }
60249d8c599SYunfan Zhang
603121b567dSKrzysztof Kozlowski static const struct regmap_config fan53555_regmap_config = {
60449d8c599SYunfan Zhang .reg_bits = 8,
60549d8c599SYunfan Zhang .val_bits = 8,
60649d8c599SYunfan Zhang };
60749d8c599SYunfan Zhang
fan53555_parse_dt(struct device * dev,struct device_node * np,const struct regulator_desc * desc)60891f23d8fSHeiko Stuebner static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev,
609072e78b1SJavier Martinez Canillas struct device_node *np,
610072e78b1SJavier Martinez Canillas const struct regulator_desc *desc)
61191f23d8fSHeiko Stuebner {
61291f23d8fSHeiko Stuebner struct fan53555_platform_data *pdata;
61391f23d8fSHeiko Stuebner int ret;
61491f23d8fSHeiko Stuebner u32 tmp;
61591f23d8fSHeiko Stuebner
61691f23d8fSHeiko Stuebner pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
61791f23d8fSHeiko Stuebner if (!pdata)
61891f23d8fSHeiko Stuebner return NULL;
61991f23d8fSHeiko Stuebner
620072e78b1SJavier Martinez Canillas pdata->regulator = of_get_regulator_init_data(dev, np, desc);
62191f23d8fSHeiko Stuebner
62291f23d8fSHeiko Stuebner ret = of_property_read_u32(np, "fcs,suspend-voltage-selector",
62391f23d8fSHeiko Stuebner &tmp);
62491f23d8fSHeiko Stuebner if (!ret)
62591f23d8fSHeiko Stuebner pdata->sleep_vsel_id = tmp;
62691f23d8fSHeiko Stuebner
62791f23d8fSHeiko Stuebner return pdata;
62891f23d8fSHeiko Stuebner }
62991f23d8fSHeiko Stuebner
6305e97d7e8SJisheng Zhang static const struct of_device_id __maybe_unused fan53555_dt_ids[] = {
63191f23d8fSHeiko Stuebner {
632f2a9eb97SBjorn Andersson .compatible = "fcs,fan53526",
633f2a9eb97SBjorn Andersson .data = (void *)FAN53526_VENDOR_FAIRCHILD,
634f2a9eb97SBjorn Andersson }, {
63591f23d8fSHeiko Stuebner .compatible = "fcs,fan53555",
636ee30928aSHeiko Stuebner .data = (void *)FAN53555_VENDOR_FAIRCHILD
637ee30928aSHeiko Stuebner }, {
638a27e71a6SCristian Ciocaltea .compatible = "rockchip,rk8600",
639a27e71a6SCristian Ciocaltea .data = (void *)FAN53555_VENDOR_ROCKCHIP
640a27e71a6SCristian Ciocaltea }, {
641a27e71a6SCristian Ciocaltea .compatible = "rockchip,rk8602",
642a27e71a6SCristian Ciocaltea .data = (void *)RK8602_VENDOR_ROCKCHIP
643a27e71a6SCristian Ciocaltea }, {
644ee30928aSHeiko Stuebner .compatible = "silergy,syr827",
645ee30928aSHeiko Stuebner .data = (void *)FAN53555_VENDOR_SILERGY,
646ee30928aSHeiko Stuebner }, {
647ee30928aSHeiko Stuebner .compatible = "silergy,syr828",
648ee30928aSHeiko Stuebner .data = (void *)FAN53555_VENDOR_SILERGY,
649914df8faSJoseph Chen }, {
650914df8faSJoseph Chen .compatible = "tcs,tcs4525",
651b3cc8ec0SPeter Geis .data = (void *)FAN53526_VENDOR_TCS
6525eee5eceSRudi Heitbaum }, {
6535eee5eceSRudi Heitbaum .compatible = "tcs,tcs4526",
6545eee5eceSRudi Heitbaum .data = (void *)FAN53526_VENDOR_TCS
65591f23d8fSHeiko Stuebner },
65691f23d8fSHeiko Stuebner { }
65791f23d8fSHeiko Stuebner };
65891f23d8fSHeiko Stuebner MODULE_DEVICE_TABLE(of, fan53555_dt_ids);
65991f23d8fSHeiko Stuebner
fan53555_regulator_probe(struct i2c_client * client)66065542565SUwe Kleine-König static int fan53555_regulator_probe(struct i2c_client *client)
66149d8c599SYunfan Zhang {
66291f23d8fSHeiko Stuebner struct device_node *np = client->dev.of_node;
66349d8c599SYunfan Zhang struct fan53555_device_info *di;
66449d8c599SYunfan Zhang struct fan53555_platform_data *pdata;
66549d8c599SYunfan Zhang struct regulator_config config = { };
666a69929c7SAxel Lin struct regmap *regmap;
66749d8c599SYunfan Zhang unsigned int val;
66849d8c599SYunfan Zhang int ret;
66949d8c599SYunfan Zhang
670072e78b1SJavier Martinez Canillas di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info),
671072e78b1SJavier Martinez Canillas GFP_KERNEL);
672072e78b1SJavier Martinez Canillas if (!di)
673072e78b1SJavier Martinez Canillas return -ENOMEM;
674072e78b1SJavier Martinez Canillas
675dff91d0bSJingoo Han pdata = dev_get_platdata(&client->dev);
67691f23d8fSHeiko Stuebner if (!pdata)
677072e78b1SJavier Martinez Canillas pdata = fan53555_parse_dt(&client->dev, np, &di->desc);
67891f23d8fSHeiko Stuebner
6792c82f5b8SCristian Ciocaltea if (!pdata || !pdata->regulator)
6802c82f5b8SCristian Ciocaltea return dev_err_probe(&client->dev, -ENODEV,
6812c82f5b8SCristian Ciocaltea "Platform data not found!\n");
68249d8c599SYunfan Zhang
683e13426bfSAxel Lin di->regulator = pdata->regulator;
684364a399bSBiju Das di->vendor = (uintptr_t)i2c_get_match_data(client);
685364a399bSBiju Das if (!dev_fwnode(&client->dev)) {
686dd7e71fbSHeiko Stuebner /* if no ramp constraint set, get the pdata ramp_delay */
687dd7e71fbSHeiko Stuebner if (!di->regulator->constraints.ramp_delay) {
6882c82f5b8SCristian Ciocaltea if (pdata->slew_rate >= ARRAY_SIZE(slew_rates))
6892c82f5b8SCristian Ciocaltea return dev_err_probe(&client->dev, -EINVAL,
6902c82f5b8SCristian Ciocaltea "Invalid slew_rate\n");
691dd7e71fbSHeiko Stuebner
69291f23d8fSHeiko Stuebner di->regulator->constraints.ramp_delay
69387919e0cSAxel Lin = slew_rates[pdata->slew_rate];
69491f23d8fSHeiko Stuebner }
695dd7e71fbSHeiko Stuebner }
696dd7e71fbSHeiko Stuebner
697a69929c7SAxel Lin regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config);
6982c82f5b8SCristian Ciocaltea if (IS_ERR(regmap))
6992c82f5b8SCristian Ciocaltea return dev_err_probe(&client->dev, PTR_ERR(regmap),
7002c82f5b8SCristian Ciocaltea "Failed to allocate regmap!\n");
7012c82f5b8SCristian Ciocaltea
70249d8c599SYunfan Zhang di->dev = &client->dev;
70349d8c599SYunfan Zhang i2c_set_clientdata(client, di);
70449d8c599SYunfan Zhang /* Get chip ID */
705a69929c7SAxel Lin ret = regmap_read(regmap, FAN53555_ID1, &val);
7062c82f5b8SCristian Ciocaltea if (ret < 0)
7072c82f5b8SCristian Ciocaltea return dev_err_probe(&client->dev, ret, "Failed to get chip ID!\n");
7082c82f5b8SCristian Ciocaltea
70949d8c599SYunfan Zhang di->chip_id = val & DIE_ID;
71049d8c599SYunfan Zhang /* Get chip revision */
711a69929c7SAxel Lin ret = regmap_read(regmap, FAN53555_ID2, &val);
7122c82f5b8SCristian Ciocaltea if (ret < 0)
7132c82f5b8SCristian Ciocaltea return dev_err_probe(&client->dev, ret, "Failed to get chip Rev!\n");
7142c82f5b8SCristian Ciocaltea
71549d8c599SYunfan Zhang di->chip_rev = val & DIE_REV;
71649d8c599SYunfan Zhang dev_info(&client->dev, "FAN53555 Option[%d] Rev[%d] Detected!\n",
71749d8c599SYunfan Zhang di->chip_id, di->chip_rev);
71849d8c599SYunfan Zhang /* Device init */
71949d8c599SYunfan Zhang ret = fan53555_device_setup(di, pdata);
7202c82f5b8SCristian Ciocaltea if (ret < 0)
7212c82f5b8SCristian Ciocaltea return dev_err_probe(&client->dev, ret, "Failed to setup device!\n");
7222c82f5b8SCristian Ciocaltea
72349d8c599SYunfan Zhang /* Register regulator */
72449d8c599SYunfan Zhang config.dev = di->dev;
72549d8c599SYunfan Zhang config.init_data = di->regulator;
726a69929c7SAxel Lin config.regmap = regmap;
72749d8c599SYunfan Zhang config.driver_data = di;
72891f23d8fSHeiko Stuebner config.of_node = np;
72991f23d8fSHeiko Stuebner
73049d8c599SYunfan Zhang ret = fan53555_regulator_register(di, &config);
73149d8c599SYunfan Zhang if (ret < 0)
7322c82f5b8SCristian Ciocaltea dev_err_probe(&client->dev, ret, "Failed to register regulator!\n");
73349d8c599SYunfan Zhang
7342c82f5b8SCristian Ciocaltea return ret;
73549d8c599SYunfan Zhang }
73649d8c599SYunfan Zhang
73749d8c599SYunfan Zhang static const struct i2c_device_id fan53555_id[] = {
738ee30928aSHeiko Stuebner {
739f2a9eb97SBjorn Andersson .name = "fan53526",
740f2a9eb97SBjorn Andersson .driver_data = FAN53526_VENDOR_FAIRCHILD
741f2a9eb97SBjorn Andersson }, {
742ee30928aSHeiko Stuebner .name = "fan53555",
743ee30928aSHeiko Stuebner .driver_data = FAN53555_VENDOR_FAIRCHILD
744ee30928aSHeiko Stuebner }, {
745a27e71a6SCristian Ciocaltea .name = "rk8600",
746a27e71a6SCristian Ciocaltea .driver_data = FAN53555_VENDOR_ROCKCHIP
747a27e71a6SCristian Ciocaltea }, {
748a27e71a6SCristian Ciocaltea .name = "rk8602",
749a27e71a6SCristian Ciocaltea .driver_data = RK8602_VENDOR_ROCKCHIP
750a27e71a6SCristian Ciocaltea }, {
751fc1111b8SGuillaume Tucker .name = "syr827",
752fc1111b8SGuillaume Tucker .driver_data = FAN53555_VENDOR_SILERGY
753fc1111b8SGuillaume Tucker }, {
754fc1111b8SGuillaume Tucker .name = "syr828",
755ee30928aSHeiko Stuebner .driver_data = FAN53555_VENDOR_SILERGY
756914df8faSJoseph Chen }, {
757914df8faSJoseph Chen .name = "tcs4525",
758b3cc8ec0SPeter Geis .driver_data = FAN53526_VENDOR_TCS
7595eee5eceSRudi Heitbaum }, {
7605eee5eceSRudi Heitbaum .name = "tcs4526",
7615eee5eceSRudi Heitbaum .driver_data = FAN53526_VENDOR_TCS
762ee30928aSHeiko Stuebner },
76349d8c599SYunfan Zhang { },
76449d8c599SYunfan Zhang };
765e80c47bdSJavier Martinez Canillas MODULE_DEVICE_TABLE(i2c, fan53555_id);
76649d8c599SYunfan Zhang
76749d8c599SYunfan Zhang static struct i2c_driver fan53555_regulator_driver = {
76849d8c599SYunfan Zhang .driver = {
76949d8c599SYunfan Zhang .name = "fan53555-regulator",
770259b93b2SDouglas Anderson .probe_type = PROBE_PREFER_ASYNCHRONOUS,
77191f23d8fSHeiko Stuebner .of_match_table = of_match_ptr(fan53555_dt_ids),
77249d8c599SYunfan Zhang },
773964e1865SUwe Kleine-König .probe = fan53555_regulator_probe,
77449d8c599SYunfan Zhang .id_table = fan53555_id,
77549d8c599SYunfan Zhang };
77649d8c599SYunfan Zhang
77749d8c599SYunfan Zhang module_i2c_driver(fan53555_regulator_driver);
77849d8c599SYunfan Zhang
77949d8c599SYunfan Zhang MODULE_AUTHOR("Yunfan Zhang <yfzhang@marvell.com>");
78049d8c599SYunfan Zhang MODULE_DESCRIPTION("FAN53555 regulator driver");
78149d8c599SYunfan Zhang MODULE_LICENSE("GPL v2");
782