149f53951SKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
2e85c5a15SMarek Vasut /*
3e85c5a15SMarek Vasut  * ROHM BD9571MWV-M regulator driver
4e85c5a15SMarek Vasut  *
5e85c5a15SMarek Vasut  * Copyright (C) 2017 Marek Vasut <marek.vasut+renesas@gmail.com>
6e85c5a15SMarek Vasut  *
7e85c5a15SMarek Vasut  * Based on the TPS65086 driver
8e85c5a15SMarek Vasut  *
9e85c5a15SMarek Vasut  * NOTE: VD09 is missing
10e85c5a15SMarek Vasut  */
11e85c5a15SMarek Vasut 
12e85c5a15SMarek Vasut #include <linux/module.h>
13e85c5a15SMarek Vasut #include <linux/of.h>
14e85c5a15SMarek Vasut #include <linux/platform_device.h>
15e85c5a15SMarek Vasut #include <linux/regulator/driver.h>
16e85c5a15SMarek Vasut 
17e85c5a15SMarek Vasut #include <linux/mfd/bd9571mwv.h>
18e85c5a15SMarek Vasut 
196eb0bfaeSGeert Uytterhoeven struct bd9571mwv_reg {
206eb0bfaeSGeert Uytterhoeven 	struct bd9571mwv *bd;
216eb0bfaeSGeert Uytterhoeven 
226eb0bfaeSGeert Uytterhoeven 	/* DDR Backup Power */
236eb0bfaeSGeert Uytterhoeven 	u8 bkup_mode_cnt_keepon;	/* from "rohm,ddr-backup-power" */
246eb0bfaeSGeert Uytterhoeven 	u8 bkup_mode_cnt_saved;
2502b3a073SGeert Uytterhoeven 	bool bkup_mode_enabled;
266eb0bfaeSGeert Uytterhoeven 
276eb0bfaeSGeert Uytterhoeven 	/* Power switch type */
286eb0bfaeSGeert Uytterhoeven 	bool rstbmode_level;
296eb0bfaeSGeert Uytterhoeven 	bool rstbmode_pulse;
306eb0bfaeSGeert Uytterhoeven };
316eb0bfaeSGeert Uytterhoeven 
32e85c5a15SMarek Vasut enum bd9571mwv_regulators { VD09, VD18, VD25, VD33, DVFS };
33e85c5a15SMarek Vasut 
34e85c5a15SMarek Vasut #define BD9571MWV_REG(_name, _of, _id, _ops, _vr, _vm, _nv, _min, _step, _lmin)\
35e85c5a15SMarek Vasut 	{							\
36e85c5a15SMarek Vasut 		.name			= _name,		\
37e85c5a15SMarek Vasut 		.of_match		= of_match_ptr(_of),	\
38e85c5a15SMarek Vasut 		.regulators_node	= "regulators",		\
39e85c5a15SMarek Vasut 		.id			= _id,			\
40e85c5a15SMarek Vasut 		.ops			= &_ops,		\
41e85c5a15SMarek Vasut 		.n_voltages		= _nv,			\
42e85c5a15SMarek Vasut 		.type			= REGULATOR_VOLTAGE,	\
43e85c5a15SMarek Vasut 		.owner			= THIS_MODULE,		\
44e85c5a15SMarek Vasut 		.vsel_reg		= _vr,			\
45e85c5a15SMarek Vasut 		.vsel_mask		= _vm,			\
46e85c5a15SMarek Vasut 		.min_uV			= _min,			\
47e85c5a15SMarek Vasut 		.uV_step		= _step,		\
48e85c5a15SMarek Vasut 		.linear_min_sel		= _lmin,		\
49e85c5a15SMarek Vasut 	}
50e85c5a15SMarek Vasut 
51cb42b648SAxel Lin static int bd9571mwv_avs_get_moni_state(struct regulator_dev *rdev)
52e85c5a15SMarek Vasut {
53e85c5a15SMarek Vasut 	unsigned int val;
54e85c5a15SMarek Vasut 	int ret;
55e85c5a15SMarek Vasut 
56e85c5a15SMarek Vasut 	ret = regmap_read(rdev->regmap, BD9571MWV_AVS_SET_MONI, &val);
57e85c5a15SMarek Vasut 	if (ret != 0)
58e85c5a15SMarek Vasut 		return ret;
59e85c5a15SMarek Vasut 
60e85c5a15SMarek Vasut 	return val & BD9571MWV_AVS_SET_MONI_MASK;
61e85c5a15SMarek Vasut }
62e85c5a15SMarek Vasut 
63cb42b648SAxel Lin static int bd9571mwv_avs_set_voltage_sel_regmap(struct regulator_dev *rdev,
64e85c5a15SMarek Vasut 						unsigned int sel)
65e85c5a15SMarek Vasut {
66e85c5a15SMarek Vasut 	int ret;
67e85c5a15SMarek Vasut 
68e85c5a15SMarek Vasut 	ret = bd9571mwv_avs_get_moni_state(rdev);
69e85c5a15SMarek Vasut 	if (ret < 0)
70e85c5a15SMarek Vasut 		return ret;
71e85c5a15SMarek Vasut 
72e85c5a15SMarek Vasut 	return regmap_write_bits(rdev->regmap, BD9571MWV_AVS_VD09_VID(ret),
73e85c5a15SMarek Vasut 				 rdev->desc->vsel_mask, sel);
74e85c5a15SMarek Vasut }
75e85c5a15SMarek Vasut 
76cb42b648SAxel Lin static int bd9571mwv_avs_get_voltage_sel_regmap(struct regulator_dev *rdev)
77e85c5a15SMarek Vasut {
78e85c5a15SMarek Vasut 	unsigned int val;
79e85c5a15SMarek Vasut 	int ret;
80e85c5a15SMarek Vasut 
81e85c5a15SMarek Vasut 	ret = bd9571mwv_avs_get_moni_state(rdev);
82e85c5a15SMarek Vasut 	if (ret < 0)
83e85c5a15SMarek Vasut 		return ret;
84e85c5a15SMarek Vasut 
85e85c5a15SMarek Vasut 	ret = regmap_read(rdev->regmap, BD9571MWV_AVS_VD09_VID(ret), &val);
86e85c5a15SMarek Vasut 	if (ret != 0)
87e85c5a15SMarek Vasut 		return ret;
88e85c5a15SMarek Vasut 
89e85c5a15SMarek Vasut 	val &= rdev->desc->vsel_mask;
90e85c5a15SMarek Vasut 	val >>= ffs(rdev->desc->vsel_mask) - 1;
91e85c5a15SMarek Vasut 
92e85c5a15SMarek Vasut 	return val;
93e85c5a15SMarek Vasut }
94e85c5a15SMarek Vasut 
95cb42b648SAxel Lin static int bd9571mwv_reg_set_voltage_sel_regmap(struct regulator_dev *rdev,
96e85c5a15SMarek Vasut 						unsigned int sel)
97e85c5a15SMarek Vasut {
98e85c5a15SMarek Vasut 	return regmap_write_bits(rdev->regmap, BD9571MWV_DVFS_SETVID,
99e85c5a15SMarek Vasut 				 rdev->desc->vsel_mask, sel);
100e85c5a15SMarek Vasut }
101e85c5a15SMarek Vasut 
102e85c5a15SMarek Vasut /* Operations permitted on AVS voltage regulator */
103e109e711SAxel Lin static const struct regulator_ops avs_ops = {
104e85c5a15SMarek Vasut 	.set_voltage_sel	= bd9571mwv_avs_set_voltage_sel_regmap,
105e85c5a15SMarek Vasut 	.map_voltage		= regulator_map_voltage_linear,
106e85c5a15SMarek Vasut 	.get_voltage_sel	= bd9571mwv_avs_get_voltage_sel_regmap,
107e85c5a15SMarek Vasut 	.list_voltage		= regulator_list_voltage_linear,
108e85c5a15SMarek Vasut };
109e85c5a15SMarek Vasut 
110e85c5a15SMarek Vasut /* Operations permitted on voltage regulators */
111e109e711SAxel Lin static const struct regulator_ops reg_ops = {
112e85c5a15SMarek Vasut 	.set_voltage_sel	= bd9571mwv_reg_set_voltage_sel_regmap,
113e85c5a15SMarek Vasut 	.map_voltage		= regulator_map_voltage_linear,
114e85c5a15SMarek Vasut 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
115e85c5a15SMarek Vasut 	.list_voltage		= regulator_list_voltage_linear,
116e85c5a15SMarek Vasut };
117e85c5a15SMarek Vasut 
118e85c5a15SMarek Vasut /* Operations permitted on voltage monitors */
119e109e711SAxel Lin static const struct regulator_ops vid_ops = {
120e85c5a15SMarek Vasut 	.map_voltage		= regulator_map_voltage_linear,
121e85c5a15SMarek Vasut 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
122e85c5a15SMarek Vasut 	.list_voltage		= regulator_list_voltage_linear,
123e85c5a15SMarek Vasut };
124e85c5a15SMarek Vasut 
125e109e711SAxel Lin static const struct regulator_desc regulators[] = {
126e85c5a15SMarek Vasut 	BD9571MWV_REG("VD09", "vd09", VD09, avs_ops, 0, 0x7f,
127e85c5a15SMarek Vasut 		      0x80, 600000, 10000, 0x3c),
128e85c5a15SMarek Vasut 	BD9571MWV_REG("VD18", "vd18", VD18, vid_ops, BD9571MWV_VD18_VID, 0xf,
129e85c5a15SMarek Vasut 		      16, 1625000, 25000, 0),
130e85c5a15SMarek Vasut 	BD9571MWV_REG("VD25", "vd25", VD25, vid_ops, BD9571MWV_VD25_VID, 0xf,
131e85c5a15SMarek Vasut 		      16, 2150000, 50000, 0),
132e85c5a15SMarek Vasut 	BD9571MWV_REG("VD33", "vd33", VD33, vid_ops, BD9571MWV_VD33_VID, 0xf,
133e85c5a15SMarek Vasut 		      11, 2800000, 100000, 0),
134e85c5a15SMarek Vasut 	BD9571MWV_REG("DVFS", "dvfs", DVFS, reg_ops,
135e85c5a15SMarek Vasut 		      BD9571MWV_DVFS_MONIVDAC, 0x7f,
136e85c5a15SMarek Vasut 		      0x80, 600000, 10000, 0x3c),
137e85c5a15SMarek Vasut };
138e85c5a15SMarek Vasut 
1396eb0bfaeSGeert Uytterhoeven #ifdef CONFIG_PM_SLEEP
1406eb0bfaeSGeert Uytterhoeven static int bd9571mwv_bkup_mode_read(struct bd9571mwv *bd, unsigned int *mode)
1416eb0bfaeSGeert Uytterhoeven {
1426eb0bfaeSGeert Uytterhoeven 	int ret;
1436eb0bfaeSGeert Uytterhoeven 
1446eb0bfaeSGeert Uytterhoeven 	ret = regmap_read(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
1456eb0bfaeSGeert Uytterhoeven 	if (ret) {
1466eb0bfaeSGeert Uytterhoeven 		dev_err(bd->dev, "failed to read backup mode (%d)\n", ret);
1476eb0bfaeSGeert Uytterhoeven 		return ret;
1486eb0bfaeSGeert Uytterhoeven 	}
1496eb0bfaeSGeert Uytterhoeven 
1506eb0bfaeSGeert Uytterhoeven 	return 0;
1516eb0bfaeSGeert Uytterhoeven }
1526eb0bfaeSGeert Uytterhoeven 
1536eb0bfaeSGeert Uytterhoeven static int bd9571mwv_bkup_mode_write(struct bd9571mwv *bd, unsigned int mode)
1546eb0bfaeSGeert Uytterhoeven {
1556eb0bfaeSGeert Uytterhoeven 	int ret;
1566eb0bfaeSGeert Uytterhoeven 
1576eb0bfaeSGeert Uytterhoeven 	ret = regmap_write(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
1586eb0bfaeSGeert Uytterhoeven 	if (ret) {
1596eb0bfaeSGeert Uytterhoeven 		dev_err(bd->dev, "failed to configure backup mode 0x%x (%d)\n",
1606eb0bfaeSGeert Uytterhoeven 			mode, ret);
1616eb0bfaeSGeert Uytterhoeven 		return ret;
1626eb0bfaeSGeert Uytterhoeven 	}
1636eb0bfaeSGeert Uytterhoeven 
1646eb0bfaeSGeert Uytterhoeven 	return 0;
1656eb0bfaeSGeert Uytterhoeven }
1666eb0bfaeSGeert Uytterhoeven 
16702b3a073SGeert Uytterhoeven static ssize_t backup_mode_show(struct device *dev,
16802b3a073SGeert Uytterhoeven 				struct device_attribute *attr, char *buf)
16902b3a073SGeert Uytterhoeven {
17002b3a073SGeert Uytterhoeven 	struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
17102b3a073SGeert Uytterhoeven 
17202b3a073SGeert Uytterhoeven 	return sprintf(buf, "%s\n", bdreg->bkup_mode_enabled ? "on" : "off");
17302b3a073SGeert Uytterhoeven }
17402b3a073SGeert Uytterhoeven 
17502b3a073SGeert Uytterhoeven static ssize_t backup_mode_store(struct device *dev,
17602b3a073SGeert Uytterhoeven 				 struct device_attribute *attr,
17702b3a073SGeert Uytterhoeven 				 const char *buf, size_t count)
17802b3a073SGeert Uytterhoeven {
17902b3a073SGeert Uytterhoeven 	struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
180e436875fSGeert Uytterhoeven 	unsigned int mode;
18102b3a073SGeert Uytterhoeven 	int ret;
18202b3a073SGeert Uytterhoeven 
18302b3a073SGeert Uytterhoeven 	if (!count)
18402b3a073SGeert Uytterhoeven 		return 0;
18502b3a073SGeert Uytterhoeven 
18602b3a073SGeert Uytterhoeven 	ret = kstrtobool(buf, &bdreg->bkup_mode_enabled);
18702b3a073SGeert Uytterhoeven 	if (ret)
18802b3a073SGeert Uytterhoeven 		return ret;
18902b3a073SGeert Uytterhoeven 
190e436875fSGeert Uytterhoeven 	if (!bdreg->rstbmode_level)
191e436875fSGeert Uytterhoeven 		return count;
192e436875fSGeert Uytterhoeven 
193e436875fSGeert Uytterhoeven 	/*
194e436875fSGeert Uytterhoeven 	 * Configure DDR Backup Mode, to change the role of the accessory power
195e436875fSGeert Uytterhoeven 	 * switch from a power switch to a wake-up switch, or vice versa
196e436875fSGeert Uytterhoeven 	 */
197e436875fSGeert Uytterhoeven 	ret = bd9571mwv_bkup_mode_read(bdreg->bd, &mode);
198e436875fSGeert Uytterhoeven 	if (ret)
199e436875fSGeert Uytterhoeven 		return ret;
200e436875fSGeert Uytterhoeven 
201e436875fSGeert Uytterhoeven 	mode &= ~BD9571MWV_BKUP_MODE_CNT_KEEPON_MASK;
202e436875fSGeert Uytterhoeven 	if (bdreg->bkup_mode_enabled)
203e436875fSGeert Uytterhoeven 		mode |= bdreg->bkup_mode_cnt_keepon;
204e436875fSGeert Uytterhoeven 
205e436875fSGeert Uytterhoeven 	ret = bd9571mwv_bkup_mode_write(bdreg->bd, mode);
206e436875fSGeert Uytterhoeven 	if (ret)
207e436875fSGeert Uytterhoeven 		return ret;
208e436875fSGeert Uytterhoeven 
20902b3a073SGeert Uytterhoeven 	return count;
21002b3a073SGeert Uytterhoeven }
21102b3a073SGeert Uytterhoeven 
212a70a4694SWei Yongjun static DEVICE_ATTR_RW(backup_mode);
21302b3a073SGeert Uytterhoeven 
2146eb0bfaeSGeert Uytterhoeven static int bd9571mwv_suspend(struct device *dev)
2156eb0bfaeSGeert Uytterhoeven {
2166eb0bfaeSGeert Uytterhoeven 	struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
2176eb0bfaeSGeert Uytterhoeven 	unsigned int mode;
2186eb0bfaeSGeert Uytterhoeven 	int ret;
2196eb0bfaeSGeert Uytterhoeven 
22002b3a073SGeert Uytterhoeven 	if (!bdreg->bkup_mode_enabled)
2216eb0bfaeSGeert Uytterhoeven 		return 0;
2226eb0bfaeSGeert Uytterhoeven 
2236eb0bfaeSGeert Uytterhoeven 	/* Save DDR Backup Mode */
2246eb0bfaeSGeert Uytterhoeven 	ret = bd9571mwv_bkup_mode_read(bdreg->bd, &mode);
2256eb0bfaeSGeert Uytterhoeven 	if (ret)
2266eb0bfaeSGeert Uytterhoeven 		return ret;
2276eb0bfaeSGeert Uytterhoeven 
2286eb0bfaeSGeert Uytterhoeven 	bdreg->bkup_mode_cnt_saved = mode;
2296eb0bfaeSGeert Uytterhoeven 
2306eb0bfaeSGeert Uytterhoeven 	if (!bdreg->rstbmode_pulse)
2316eb0bfaeSGeert Uytterhoeven 		return 0;
2326eb0bfaeSGeert Uytterhoeven 
2336eb0bfaeSGeert Uytterhoeven 	/* Enable DDR Backup Mode */
2346eb0bfaeSGeert Uytterhoeven 	mode &= ~BD9571MWV_BKUP_MODE_CNT_KEEPON_MASK;
2356eb0bfaeSGeert Uytterhoeven 	mode |= bdreg->bkup_mode_cnt_keepon;
2366eb0bfaeSGeert Uytterhoeven 
2376eb0bfaeSGeert Uytterhoeven 	if (mode != bdreg->bkup_mode_cnt_saved)
2386eb0bfaeSGeert Uytterhoeven 		return bd9571mwv_bkup_mode_write(bdreg->bd, mode);
2396eb0bfaeSGeert Uytterhoeven 
2406eb0bfaeSGeert Uytterhoeven 	return 0;
2416eb0bfaeSGeert Uytterhoeven }
2426eb0bfaeSGeert Uytterhoeven 
2436eb0bfaeSGeert Uytterhoeven static int bd9571mwv_resume(struct device *dev)
2446eb0bfaeSGeert Uytterhoeven {
2456eb0bfaeSGeert Uytterhoeven 	struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
2466eb0bfaeSGeert Uytterhoeven 
24702b3a073SGeert Uytterhoeven 	if (!bdreg->bkup_mode_enabled)
2486eb0bfaeSGeert Uytterhoeven 		return 0;
2496eb0bfaeSGeert Uytterhoeven 
2506eb0bfaeSGeert Uytterhoeven 	/* Restore DDR Backup Mode */
2516eb0bfaeSGeert Uytterhoeven 	return bd9571mwv_bkup_mode_write(bdreg->bd, bdreg->bkup_mode_cnt_saved);
2526eb0bfaeSGeert Uytterhoeven }
2536eb0bfaeSGeert Uytterhoeven 
2546eb0bfaeSGeert Uytterhoeven static const struct dev_pm_ops bd9571mwv_pm  = {
2556eb0bfaeSGeert Uytterhoeven 	SET_SYSTEM_SLEEP_PM_OPS(bd9571mwv_suspend, bd9571mwv_resume)
2566eb0bfaeSGeert Uytterhoeven };
2576eb0bfaeSGeert Uytterhoeven 
25802b3a073SGeert Uytterhoeven static int bd9571mwv_regulator_remove(struct platform_device *pdev)
25902b3a073SGeert Uytterhoeven {
26002b3a073SGeert Uytterhoeven 	device_remove_file(&pdev->dev, &dev_attr_backup_mode);
26102b3a073SGeert Uytterhoeven 	return 0;
26202b3a073SGeert Uytterhoeven }
2636eb0bfaeSGeert Uytterhoeven #define DEV_PM_OPS	&bd9571mwv_pm
2646eb0bfaeSGeert Uytterhoeven #else
2656eb0bfaeSGeert Uytterhoeven #define DEV_PM_OPS	NULL
26602b3a073SGeert Uytterhoeven #define bd9571mwv_regulator_remove	NULL
2676eb0bfaeSGeert Uytterhoeven #endif /* CONFIG_PM_SLEEP */
2686eb0bfaeSGeert Uytterhoeven 
269e85c5a15SMarek Vasut static int bd9571mwv_regulator_probe(struct platform_device *pdev)
270e85c5a15SMarek Vasut {
271e85c5a15SMarek Vasut 	struct bd9571mwv *bd = dev_get_drvdata(pdev->dev.parent);
272e85c5a15SMarek Vasut 	struct regulator_config config = { };
2736eb0bfaeSGeert Uytterhoeven 	struct bd9571mwv_reg *bdreg;
274e85c5a15SMarek Vasut 	struct regulator_dev *rdev;
2756eb0bfaeSGeert Uytterhoeven 	unsigned int val;
276e85c5a15SMarek Vasut 	int i;
277e85c5a15SMarek Vasut 
2786eb0bfaeSGeert Uytterhoeven 	bdreg = devm_kzalloc(&pdev->dev, sizeof(*bdreg), GFP_KERNEL);
2796eb0bfaeSGeert Uytterhoeven 	if (!bdreg)
2806eb0bfaeSGeert Uytterhoeven 		return -ENOMEM;
2816eb0bfaeSGeert Uytterhoeven 
2826eb0bfaeSGeert Uytterhoeven 	bdreg->bd = bd;
2836eb0bfaeSGeert Uytterhoeven 
2846eb0bfaeSGeert Uytterhoeven 	platform_set_drvdata(pdev, bdreg);
285e85c5a15SMarek Vasut 
286e85c5a15SMarek Vasut 	config.dev = &pdev->dev;
287e85c5a15SMarek Vasut 	config.dev->of_node = bd->dev->of_node;
288e85c5a15SMarek Vasut 	config.driver_data = bd;
289e85c5a15SMarek Vasut 	config.regmap = bd->regmap;
290e85c5a15SMarek Vasut 
291e85c5a15SMarek Vasut 	for (i = 0; i < ARRAY_SIZE(regulators); i++) {
292e85c5a15SMarek Vasut 		rdev = devm_regulator_register(&pdev->dev, &regulators[i],
293e85c5a15SMarek Vasut 					       &config);
294e85c5a15SMarek Vasut 		if (IS_ERR(rdev)) {
295e85c5a15SMarek Vasut 			dev_err(bd->dev, "failed to register %s regulator\n",
296e85c5a15SMarek Vasut 				pdev->name);
297e85c5a15SMarek Vasut 			return PTR_ERR(rdev);
298e85c5a15SMarek Vasut 		}
299e85c5a15SMarek Vasut 	}
300e85c5a15SMarek Vasut 
3016eb0bfaeSGeert Uytterhoeven 	val = 0;
3026eb0bfaeSGeert Uytterhoeven 	of_property_read_u32(bd->dev->of_node, "rohm,ddr-backup-power", &val);
3036eb0bfaeSGeert Uytterhoeven 	if (val & ~BD9571MWV_BKUP_MODE_CNT_KEEPON_MASK) {
3046eb0bfaeSGeert Uytterhoeven 		dev_err(bd->dev, "invalid %s mode %u\n",
3056eb0bfaeSGeert Uytterhoeven 			"rohm,ddr-backup-power", val);
3066eb0bfaeSGeert Uytterhoeven 		return -EINVAL;
3076eb0bfaeSGeert Uytterhoeven 	}
3086eb0bfaeSGeert Uytterhoeven 	bdreg->bkup_mode_cnt_keepon = val;
3096eb0bfaeSGeert Uytterhoeven 
3106eb0bfaeSGeert Uytterhoeven 	bdreg->rstbmode_level = of_property_read_bool(bd->dev->of_node,
3116eb0bfaeSGeert Uytterhoeven 						      "rohm,rstbmode-level");
3126eb0bfaeSGeert Uytterhoeven 	bdreg->rstbmode_pulse = of_property_read_bool(bd->dev->of_node,
3136eb0bfaeSGeert Uytterhoeven 						      "rohm,rstbmode-pulse");
3146eb0bfaeSGeert Uytterhoeven 	if (bdreg->rstbmode_level && bdreg->rstbmode_pulse) {
3156eb0bfaeSGeert Uytterhoeven 		dev_err(bd->dev, "only one rohm,rstbmode-* may be specified");
3166eb0bfaeSGeert Uytterhoeven 		return -EINVAL;
3176eb0bfaeSGeert Uytterhoeven 	}
3186eb0bfaeSGeert Uytterhoeven 
31902b3a073SGeert Uytterhoeven #ifdef CONFIG_PM_SLEEP
3206eb0bfaeSGeert Uytterhoeven 	if (bdreg->bkup_mode_cnt_keepon) {
32102b3a073SGeert Uytterhoeven 		int ret;
32202b3a073SGeert Uytterhoeven 
3236eb0bfaeSGeert Uytterhoeven 		/*
32402b3a073SGeert Uytterhoeven 		 * Backup mode is enabled by default in pulse mode, but needs
3256eb0bfaeSGeert Uytterhoeven 		 * explicit user setup in level mode.
3266eb0bfaeSGeert Uytterhoeven 		 */
32702b3a073SGeert Uytterhoeven 		bdreg->bkup_mode_enabled = bdreg->rstbmode_pulse;
32802b3a073SGeert Uytterhoeven 
32902b3a073SGeert Uytterhoeven 		ret = device_create_file(&pdev->dev, &dev_attr_backup_mode);
33002b3a073SGeert Uytterhoeven 		if (ret)
33102b3a073SGeert Uytterhoeven 			return ret;
3326eb0bfaeSGeert Uytterhoeven 	}
33302b3a073SGeert Uytterhoeven #endif /* CONFIG_PM_SLEEP */
3346eb0bfaeSGeert Uytterhoeven 
335e85c5a15SMarek Vasut 	return 0;
336e85c5a15SMarek Vasut }
337e85c5a15SMarek Vasut 
338e85c5a15SMarek Vasut static const struct platform_device_id bd9571mwv_regulator_id_table[] = {
339e85c5a15SMarek Vasut 	{ "bd9571mwv-regulator", },
340e85c5a15SMarek Vasut 	{ /* sentinel */ }
341e85c5a15SMarek Vasut };
342e85c5a15SMarek Vasut MODULE_DEVICE_TABLE(platform, bd9571mwv_regulator_id_table);
343e85c5a15SMarek Vasut 
344e85c5a15SMarek Vasut static struct platform_driver bd9571mwv_regulator_driver = {
345e85c5a15SMarek Vasut 	.driver = {
346e85c5a15SMarek Vasut 		.name = "bd9571mwv-regulator",
3476eb0bfaeSGeert Uytterhoeven 		.pm = DEV_PM_OPS,
348e85c5a15SMarek Vasut 	},
349e85c5a15SMarek Vasut 	.probe = bd9571mwv_regulator_probe,
35002b3a073SGeert Uytterhoeven 	.remove = bd9571mwv_regulator_remove,
351e85c5a15SMarek Vasut 	.id_table = bd9571mwv_regulator_id_table,
352e85c5a15SMarek Vasut };
353e85c5a15SMarek Vasut module_platform_driver(bd9571mwv_regulator_driver);
354e85c5a15SMarek Vasut 
355e85c5a15SMarek Vasut MODULE_AUTHOR("Marek Vasut <marek.vasut+renesas@gmail.com>");
356e85c5a15SMarek Vasut MODULE_DESCRIPTION("BD9571MWV Regulator driver");
357e85c5a15SMarek Vasut MODULE_LICENSE("GPL v2");
358