1e85c5a15SMarek Vasut /*
2e85c5a15SMarek Vasut  * ROHM BD9571MWV-M regulator driver
3e85c5a15SMarek Vasut  *
4e85c5a15SMarek Vasut  * Copyright (C) 2017 Marek Vasut <marek.vasut+renesas@gmail.com>
5e85c5a15SMarek Vasut  *
6e85c5a15SMarek Vasut  * This program is free software; you can redistribute it and/or
7e85c5a15SMarek Vasut  * modify it under the terms of the GNU General Public License version 2 as
8e85c5a15SMarek Vasut  * published by the Free Software Foundation.
9e85c5a15SMarek Vasut  *
10e85c5a15SMarek Vasut  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11e85c5a15SMarek Vasut  * kind, whether expressed or implied; without even the implied warranty
12e85c5a15SMarek Vasut  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13e85c5a15SMarek Vasut  * GNU General Public License version 2 for more details.
14e85c5a15SMarek Vasut  *
15e85c5a15SMarek Vasut  * Based on the TPS65086 driver
16e85c5a15SMarek Vasut  *
17e85c5a15SMarek Vasut  * NOTE: VD09 is missing
18e85c5a15SMarek Vasut  */
19e85c5a15SMarek Vasut 
20e85c5a15SMarek Vasut #include <linux/module.h>
21e85c5a15SMarek Vasut #include <linux/of.h>
22e85c5a15SMarek Vasut #include <linux/platform_device.h>
23e85c5a15SMarek Vasut #include <linux/regulator/driver.h>
24e85c5a15SMarek Vasut 
25e85c5a15SMarek Vasut #include <linux/mfd/bd9571mwv.h>
26e85c5a15SMarek Vasut 
276eb0bfaeSGeert Uytterhoeven struct bd9571mwv_reg {
286eb0bfaeSGeert Uytterhoeven 	struct bd9571mwv *bd;
296eb0bfaeSGeert Uytterhoeven 
306eb0bfaeSGeert Uytterhoeven 	/* DDR Backup Power */
316eb0bfaeSGeert Uytterhoeven 	u8 bkup_mode_cnt_keepon;	/* from "rohm,ddr-backup-power" */
326eb0bfaeSGeert Uytterhoeven 	u8 bkup_mode_cnt_saved;
3302b3a073SGeert Uytterhoeven 	bool bkup_mode_enabled;
346eb0bfaeSGeert Uytterhoeven 
356eb0bfaeSGeert Uytterhoeven 	/* Power switch type */
366eb0bfaeSGeert Uytterhoeven 	bool rstbmode_level;
376eb0bfaeSGeert Uytterhoeven 	bool rstbmode_pulse;
386eb0bfaeSGeert Uytterhoeven };
396eb0bfaeSGeert Uytterhoeven 
40e85c5a15SMarek Vasut enum bd9571mwv_regulators { VD09, VD18, VD25, VD33, DVFS };
41e85c5a15SMarek Vasut 
42e85c5a15SMarek Vasut #define BD9571MWV_REG(_name, _of, _id, _ops, _vr, _vm, _nv, _min, _step, _lmin)\
43e85c5a15SMarek Vasut 	{							\
44e85c5a15SMarek Vasut 		.name			= _name,		\
45e85c5a15SMarek Vasut 		.of_match		= of_match_ptr(_of),	\
46e85c5a15SMarek Vasut 		.regulators_node	= "regulators",		\
47e85c5a15SMarek Vasut 		.id			= _id,			\
48e85c5a15SMarek Vasut 		.ops			= &_ops,		\
49e85c5a15SMarek Vasut 		.n_voltages		= _nv,			\
50e85c5a15SMarek Vasut 		.type			= REGULATOR_VOLTAGE,	\
51e85c5a15SMarek Vasut 		.owner			= THIS_MODULE,		\
52e85c5a15SMarek Vasut 		.vsel_reg		= _vr,			\
53e85c5a15SMarek Vasut 		.vsel_mask		= _vm,			\
54e85c5a15SMarek Vasut 		.min_uV			= _min,			\
55e85c5a15SMarek Vasut 		.uV_step		= _step,		\
56e85c5a15SMarek Vasut 		.linear_min_sel		= _lmin,		\
57e85c5a15SMarek Vasut 	}
58e85c5a15SMarek Vasut 
59cb42b648SAxel Lin static int bd9571mwv_avs_get_moni_state(struct regulator_dev *rdev)
60e85c5a15SMarek Vasut {
61e85c5a15SMarek Vasut 	unsigned int val;
62e85c5a15SMarek Vasut 	int ret;
63e85c5a15SMarek Vasut 
64e85c5a15SMarek Vasut 	ret = regmap_read(rdev->regmap, BD9571MWV_AVS_SET_MONI, &val);
65e85c5a15SMarek Vasut 	if (ret != 0)
66e85c5a15SMarek Vasut 		return ret;
67e85c5a15SMarek Vasut 
68e85c5a15SMarek Vasut 	return val & BD9571MWV_AVS_SET_MONI_MASK;
69e85c5a15SMarek Vasut }
70e85c5a15SMarek Vasut 
71cb42b648SAxel Lin static int bd9571mwv_avs_set_voltage_sel_regmap(struct regulator_dev *rdev,
72e85c5a15SMarek Vasut 						unsigned int sel)
73e85c5a15SMarek Vasut {
74e85c5a15SMarek Vasut 	int ret;
75e85c5a15SMarek Vasut 
76e85c5a15SMarek Vasut 	ret = bd9571mwv_avs_get_moni_state(rdev);
77e85c5a15SMarek Vasut 	if (ret < 0)
78e85c5a15SMarek Vasut 		return ret;
79e85c5a15SMarek Vasut 
80e85c5a15SMarek Vasut 	return regmap_write_bits(rdev->regmap, BD9571MWV_AVS_VD09_VID(ret),
81e85c5a15SMarek Vasut 				 rdev->desc->vsel_mask, sel);
82e85c5a15SMarek Vasut }
83e85c5a15SMarek Vasut 
84cb42b648SAxel Lin static int bd9571mwv_avs_get_voltage_sel_regmap(struct regulator_dev *rdev)
85e85c5a15SMarek Vasut {
86e85c5a15SMarek Vasut 	unsigned int val;
87e85c5a15SMarek Vasut 	int ret;
88e85c5a15SMarek Vasut 
89e85c5a15SMarek Vasut 	ret = bd9571mwv_avs_get_moni_state(rdev);
90e85c5a15SMarek Vasut 	if (ret < 0)
91e85c5a15SMarek Vasut 		return ret;
92e85c5a15SMarek Vasut 
93e85c5a15SMarek Vasut 	ret = regmap_read(rdev->regmap, BD9571MWV_AVS_VD09_VID(ret), &val);
94e85c5a15SMarek Vasut 	if (ret != 0)
95e85c5a15SMarek Vasut 		return ret;
96e85c5a15SMarek Vasut 
97e85c5a15SMarek Vasut 	val &= rdev->desc->vsel_mask;
98e85c5a15SMarek Vasut 	val >>= ffs(rdev->desc->vsel_mask) - 1;
99e85c5a15SMarek Vasut 
100e85c5a15SMarek Vasut 	return val;
101e85c5a15SMarek Vasut }
102e85c5a15SMarek Vasut 
103cb42b648SAxel Lin static int bd9571mwv_reg_set_voltage_sel_regmap(struct regulator_dev *rdev,
104e85c5a15SMarek Vasut 						unsigned int sel)
105e85c5a15SMarek Vasut {
106e85c5a15SMarek Vasut 	return regmap_write_bits(rdev->regmap, BD9571MWV_DVFS_SETVID,
107e85c5a15SMarek Vasut 				 rdev->desc->vsel_mask, sel);
108e85c5a15SMarek Vasut }
109e85c5a15SMarek Vasut 
110e85c5a15SMarek Vasut /* Operations permitted on AVS voltage regulator */
111e85c5a15SMarek Vasut static struct regulator_ops avs_ops = {
112e85c5a15SMarek Vasut 	.set_voltage_sel	= bd9571mwv_avs_set_voltage_sel_regmap,
113e85c5a15SMarek Vasut 	.map_voltage		= regulator_map_voltage_linear,
114e85c5a15SMarek Vasut 	.get_voltage_sel	= bd9571mwv_avs_get_voltage_sel_regmap,
115e85c5a15SMarek Vasut 	.list_voltage		= regulator_list_voltage_linear,
116e85c5a15SMarek Vasut };
117e85c5a15SMarek Vasut 
118e85c5a15SMarek Vasut /* Operations permitted on voltage regulators */
119e85c5a15SMarek Vasut static struct regulator_ops reg_ops = {
120e85c5a15SMarek Vasut 	.set_voltage_sel	= bd9571mwv_reg_set_voltage_sel_regmap,
121e85c5a15SMarek Vasut 	.map_voltage		= regulator_map_voltage_linear,
122e85c5a15SMarek Vasut 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
123e85c5a15SMarek Vasut 	.list_voltage		= regulator_list_voltage_linear,
124e85c5a15SMarek Vasut };
125e85c5a15SMarek Vasut 
126e85c5a15SMarek Vasut /* Operations permitted on voltage monitors */
127e85c5a15SMarek Vasut static struct regulator_ops vid_ops = {
128e85c5a15SMarek Vasut 	.map_voltage		= regulator_map_voltage_linear,
129e85c5a15SMarek Vasut 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
130e85c5a15SMarek Vasut 	.list_voltage		= regulator_list_voltage_linear,
131e85c5a15SMarek Vasut };
132e85c5a15SMarek Vasut 
133e85c5a15SMarek Vasut static struct regulator_desc regulators[] = {
134e85c5a15SMarek Vasut 	BD9571MWV_REG("VD09", "vd09", VD09, avs_ops, 0, 0x7f,
135e85c5a15SMarek Vasut 		      0x80, 600000, 10000, 0x3c),
136e85c5a15SMarek Vasut 	BD9571MWV_REG("VD18", "vd18", VD18, vid_ops, BD9571MWV_VD18_VID, 0xf,
137e85c5a15SMarek Vasut 		      16, 1625000, 25000, 0),
138e85c5a15SMarek Vasut 	BD9571MWV_REG("VD25", "vd25", VD25, vid_ops, BD9571MWV_VD25_VID, 0xf,
139e85c5a15SMarek Vasut 		      16, 2150000, 50000, 0),
140e85c5a15SMarek Vasut 	BD9571MWV_REG("VD33", "vd33", VD33, vid_ops, BD9571MWV_VD33_VID, 0xf,
141e85c5a15SMarek Vasut 		      11, 2800000, 100000, 0),
142e85c5a15SMarek Vasut 	BD9571MWV_REG("DVFS", "dvfs", DVFS, reg_ops,
143e85c5a15SMarek Vasut 		      BD9571MWV_DVFS_MONIVDAC, 0x7f,
144e85c5a15SMarek Vasut 		      0x80, 600000, 10000, 0x3c),
145e85c5a15SMarek Vasut };
146e85c5a15SMarek Vasut 
1476eb0bfaeSGeert Uytterhoeven #ifdef CONFIG_PM_SLEEP
1486eb0bfaeSGeert Uytterhoeven static int bd9571mwv_bkup_mode_read(struct bd9571mwv *bd, unsigned int *mode)
1496eb0bfaeSGeert Uytterhoeven {
1506eb0bfaeSGeert Uytterhoeven 	int ret;
1516eb0bfaeSGeert Uytterhoeven 
1526eb0bfaeSGeert Uytterhoeven 	ret = regmap_read(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
1536eb0bfaeSGeert Uytterhoeven 	if (ret) {
1546eb0bfaeSGeert Uytterhoeven 		dev_err(bd->dev, "failed to read backup mode (%d)\n", ret);
1556eb0bfaeSGeert Uytterhoeven 		return ret;
1566eb0bfaeSGeert Uytterhoeven 	}
1576eb0bfaeSGeert Uytterhoeven 
1586eb0bfaeSGeert Uytterhoeven 	return 0;
1596eb0bfaeSGeert Uytterhoeven }
1606eb0bfaeSGeert Uytterhoeven 
1616eb0bfaeSGeert Uytterhoeven static int bd9571mwv_bkup_mode_write(struct bd9571mwv *bd, unsigned int mode)
1626eb0bfaeSGeert Uytterhoeven {
1636eb0bfaeSGeert Uytterhoeven 	int ret;
1646eb0bfaeSGeert Uytterhoeven 
1656eb0bfaeSGeert Uytterhoeven 	ret = regmap_write(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
1666eb0bfaeSGeert Uytterhoeven 	if (ret) {
1676eb0bfaeSGeert Uytterhoeven 		dev_err(bd->dev, "failed to configure backup mode 0x%x (%d)\n",
1686eb0bfaeSGeert Uytterhoeven 			mode, ret);
1696eb0bfaeSGeert Uytterhoeven 		return ret;
1706eb0bfaeSGeert Uytterhoeven 	}
1716eb0bfaeSGeert Uytterhoeven 
1726eb0bfaeSGeert Uytterhoeven 	return 0;
1736eb0bfaeSGeert Uytterhoeven }
1746eb0bfaeSGeert Uytterhoeven 
17502b3a073SGeert Uytterhoeven static ssize_t backup_mode_show(struct device *dev,
17602b3a073SGeert Uytterhoeven 				struct device_attribute *attr, char *buf)
17702b3a073SGeert Uytterhoeven {
17802b3a073SGeert Uytterhoeven 	struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
17902b3a073SGeert Uytterhoeven 
18002b3a073SGeert Uytterhoeven 	return sprintf(buf, "%s\n", bdreg->bkup_mode_enabled ? "on" : "off");
18102b3a073SGeert Uytterhoeven }
18202b3a073SGeert Uytterhoeven 
18302b3a073SGeert Uytterhoeven static ssize_t backup_mode_store(struct device *dev,
18402b3a073SGeert Uytterhoeven 				 struct device_attribute *attr,
18502b3a073SGeert Uytterhoeven 				 const char *buf, size_t count)
18602b3a073SGeert Uytterhoeven {
18702b3a073SGeert Uytterhoeven 	struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
18802b3a073SGeert Uytterhoeven 	int ret;
18902b3a073SGeert Uytterhoeven 
19002b3a073SGeert Uytterhoeven 	if (!count)
19102b3a073SGeert Uytterhoeven 		return 0;
19202b3a073SGeert Uytterhoeven 
19302b3a073SGeert Uytterhoeven 	ret = kstrtobool(buf, &bdreg->bkup_mode_enabled);
19402b3a073SGeert Uytterhoeven 	if (ret)
19502b3a073SGeert Uytterhoeven 		return ret;
19602b3a073SGeert Uytterhoeven 
19702b3a073SGeert Uytterhoeven 	return count;
19802b3a073SGeert Uytterhoeven }
19902b3a073SGeert Uytterhoeven 
20002b3a073SGeert Uytterhoeven DEVICE_ATTR_RW(backup_mode);
20102b3a073SGeert Uytterhoeven 
2026eb0bfaeSGeert Uytterhoeven static int bd9571mwv_suspend(struct device *dev)
2036eb0bfaeSGeert Uytterhoeven {
2046eb0bfaeSGeert Uytterhoeven 	struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
2056eb0bfaeSGeert Uytterhoeven 	unsigned int mode;
2066eb0bfaeSGeert Uytterhoeven 	int ret;
2076eb0bfaeSGeert Uytterhoeven 
20802b3a073SGeert Uytterhoeven 	if (!bdreg->bkup_mode_enabled)
2096eb0bfaeSGeert Uytterhoeven 		return 0;
2106eb0bfaeSGeert Uytterhoeven 
2116eb0bfaeSGeert Uytterhoeven 	/* Save DDR Backup Mode */
2126eb0bfaeSGeert Uytterhoeven 	ret = bd9571mwv_bkup_mode_read(bdreg->bd, &mode);
2136eb0bfaeSGeert Uytterhoeven 	if (ret)
2146eb0bfaeSGeert Uytterhoeven 		return ret;
2156eb0bfaeSGeert Uytterhoeven 
2166eb0bfaeSGeert Uytterhoeven 	bdreg->bkup_mode_cnt_saved = mode;
2176eb0bfaeSGeert Uytterhoeven 
2186eb0bfaeSGeert Uytterhoeven 	if (!bdreg->rstbmode_pulse)
2196eb0bfaeSGeert Uytterhoeven 		return 0;
2206eb0bfaeSGeert Uytterhoeven 
2216eb0bfaeSGeert Uytterhoeven 	/* Enable DDR Backup Mode */
2226eb0bfaeSGeert Uytterhoeven 	mode &= ~BD9571MWV_BKUP_MODE_CNT_KEEPON_MASK;
2236eb0bfaeSGeert Uytterhoeven 	mode |= bdreg->bkup_mode_cnt_keepon;
2246eb0bfaeSGeert Uytterhoeven 
2256eb0bfaeSGeert Uytterhoeven 	if (mode != bdreg->bkup_mode_cnt_saved)
2266eb0bfaeSGeert Uytterhoeven 		return bd9571mwv_bkup_mode_write(bdreg->bd, mode);
2276eb0bfaeSGeert Uytterhoeven 
2286eb0bfaeSGeert Uytterhoeven 	return 0;
2296eb0bfaeSGeert Uytterhoeven }
2306eb0bfaeSGeert Uytterhoeven 
2316eb0bfaeSGeert Uytterhoeven static int bd9571mwv_resume(struct device *dev)
2326eb0bfaeSGeert Uytterhoeven {
2336eb0bfaeSGeert Uytterhoeven 	struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev);
2346eb0bfaeSGeert Uytterhoeven 
23502b3a073SGeert Uytterhoeven 	if (!bdreg->bkup_mode_enabled)
2366eb0bfaeSGeert Uytterhoeven 		return 0;
2376eb0bfaeSGeert Uytterhoeven 
2386eb0bfaeSGeert Uytterhoeven 	/* Restore DDR Backup Mode */
2396eb0bfaeSGeert Uytterhoeven 	return bd9571mwv_bkup_mode_write(bdreg->bd, bdreg->bkup_mode_cnt_saved);
2406eb0bfaeSGeert Uytterhoeven }
2416eb0bfaeSGeert Uytterhoeven 
2426eb0bfaeSGeert Uytterhoeven static const struct dev_pm_ops bd9571mwv_pm  = {
2436eb0bfaeSGeert Uytterhoeven 	SET_SYSTEM_SLEEP_PM_OPS(bd9571mwv_suspend, bd9571mwv_resume)
2446eb0bfaeSGeert Uytterhoeven };
2456eb0bfaeSGeert Uytterhoeven 
24602b3a073SGeert Uytterhoeven static int bd9571mwv_regulator_remove(struct platform_device *pdev)
24702b3a073SGeert Uytterhoeven {
24802b3a073SGeert Uytterhoeven 	device_remove_file(&pdev->dev, &dev_attr_backup_mode);
24902b3a073SGeert Uytterhoeven 	return 0;
25002b3a073SGeert Uytterhoeven }
2516eb0bfaeSGeert Uytterhoeven #define DEV_PM_OPS	&bd9571mwv_pm
2526eb0bfaeSGeert Uytterhoeven #else
2536eb0bfaeSGeert Uytterhoeven #define DEV_PM_OPS	NULL
25402b3a073SGeert Uytterhoeven #define bd9571mwv_regulator_remove	NULL
2556eb0bfaeSGeert Uytterhoeven #endif /* CONFIG_PM_SLEEP */
2566eb0bfaeSGeert Uytterhoeven 
257e85c5a15SMarek Vasut static int bd9571mwv_regulator_probe(struct platform_device *pdev)
258e85c5a15SMarek Vasut {
259e85c5a15SMarek Vasut 	struct bd9571mwv *bd = dev_get_drvdata(pdev->dev.parent);
260e85c5a15SMarek Vasut 	struct regulator_config config = { };
2616eb0bfaeSGeert Uytterhoeven 	struct bd9571mwv_reg *bdreg;
262e85c5a15SMarek Vasut 	struct regulator_dev *rdev;
2636eb0bfaeSGeert Uytterhoeven 	unsigned int val;
264e85c5a15SMarek Vasut 	int i;
265e85c5a15SMarek Vasut 
2666eb0bfaeSGeert Uytterhoeven 	bdreg = devm_kzalloc(&pdev->dev, sizeof(*bdreg), GFP_KERNEL);
2676eb0bfaeSGeert Uytterhoeven 	if (!bdreg)
2686eb0bfaeSGeert Uytterhoeven 		return -ENOMEM;
2696eb0bfaeSGeert Uytterhoeven 
2706eb0bfaeSGeert Uytterhoeven 	bdreg->bd = bd;
2716eb0bfaeSGeert Uytterhoeven 
2726eb0bfaeSGeert Uytterhoeven 	platform_set_drvdata(pdev, bdreg);
273e85c5a15SMarek Vasut 
274e85c5a15SMarek Vasut 	config.dev = &pdev->dev;
275e85c5a15SMarek Vasut 	config.dev->of_node = bd->dev->of_node;
276e85c5a15SMarek Vasut 	config.driver_data = bd;
277e85c5a15SMarek Vasut 	config.regmap = bd->regmap;
278e85c5a15SMarek Vasut 
279e85c5a15SMarek Vasut 	for (i = 0; i < ARRAY_SIZE(regulators); i++) {
280e85c5a15SMarek Vasut 		rdev = devm_regulator_register(&pdev->dev, &regulators[i],
281e85c5a15SMarek Vasut 					       &config);
282e85c5a15SMarek Vasut 		if (IS_ERR(rdev)) {
283e85c5a15SMarek Vasut 			dev_err(bd->dev, "failed to register %s regulator\n",
284e85c5a15SMarek Vasut 				pdev->name);
285e85c5a15SMarek Vasut 			return PTR_ERR(rdev);
286e85c5a15SMarek Vasut 		}
287e85c5a15SMarek Vasut 	}
288e85c5a15SMarek Vasut 
2896eb0bfaeSGeert Uytterhoeven 	val = 0;
2906eb0bfaeSGeert Uytterhoeven 	of_property_read_u32(bd->dev->of_node, "rohm,ddr-backup-power", &val);
2916eb0bfaeSGeert Uytterhoeven 	if (val & ~BD9571MWV_BKUP_MODE_CNT_KEEPON_MASK) {
2926eb0bfaeSGeert Uytterhoeven 		dev_err(bd->dev, "invalid %s mode %u\n",
2936eb0bfaeSGeert Uytterhoeven 			"rohm,ddr-backup-power", val);
2946eb0bfaeSGeert Uytterhoeven 		return -EINVAL;
2956eb0bfaeSGeert Uytterhoeven 	}
2966eb0bfaeSGeert Uytterhoeven 	bdreg->bkup_mode_cnt_keepon = val;
2976eb0bfaeSGeert Uytterhoeven 
2986eb0bfaeSGeert Uytterhoeven 	bdreg->rstbmode_level = of_property_read_bool(bd->dev->of_node,
2996eb0bfaeSGeert Uytterhoeven 						      "rohm,rstbmode-level");
3006eb0bfaeSGeert Uytterhoeven 	bdreg->rstbmode_pulse = of_property_read_bool(bd->dev->of_node,
3016eb0bfaeSGeert Uytterhoeven 						      "rohm,rstbmode-pulse");
3026eb0bfaeSGeert Uytterhoeven 	if (bdreg->rstbmode_level && bdreg->rstbmode_pulse) {
3036eb0bfaeSGeert Uytterhoeven 		dev_err(bd->dev, "only one rohm,rstbmode-* may be specified");
3046eb0bfaeSGeert Uytterhoeven 		return -EINVAL;
3056eb0bfaeSGeert Uytterhoeven 	}
3066eb0bfaeSGeert Uytterhoeven 
30702b3a073SGeert Uytterhoeven #ifdef CONFIG_PM_SLEEP
3086eb0bfaeSGeert Uytterhoeven 	if (bdreg->bkup_mode_cnt_keepon) {
30902b3a073SGeert Uytterhoeven 		int ret;
31002b3a073SGeert Uytterhoeven 
3116eb0bfaeSGeert Uytterhoeven 		/*
31202b3a073SGeert Uytterhoeven 		 * Backup mode is enabled by default in pulse mode, but needs
3136eb0bfaeSGeert Uytterhoeven 		 * explicit user setup in level mode.
3146eb0bfaeSGeert Uytterhoeven 		 */
31502b3a073SGeert Uytterhoeven 		bdreg->bkup_mode_enabled = bdreg->rstbmode_pulse;
31602b3a073SGeert Uytterhoeven 
31702b3a073SGeert Uytterhoeven 		ret = device_create_file(&pdev->dev, &dev_attr_backup_mode);
31802b3a073SGeert Uytterhoeven 		if (ret)
31902b3a073SGeert Uytterhoeven 			return ret;
3206eb0bfaeSGeert Uytterhoeven 	}
32102b3a073SGeert Uytterhoeven #endif /* CONFIG_PM_SLEEP */
3226eb0bfaeSGeert Uytterhoeven 
323e85c5a15SMarek Vasut 	return 0;
324e85c5a15SMarek Vasut }
325e85c5a15SMarek Vasut 
326e85c5a15SMarek Vasut static const struct platform_device_id bd9571mwv_regulator_id_table[] = {
327e85c5a15SMarek Vasut 	{ "bd9571mwv-regulator", },
328e85c5a15SMarek Vasut 	{ /* sentinel */ }
329e85c5a15SMarek Vasut };
330e85c5a15SMarek Vasut MODULE_DEVICE_TABLE(platform, bd9571mwv_regulator_id_table);
331e85c5a15SMarek Vasut 
332e85c5a15SMarek Vasut static struct platform_driver bd9571mwv_regulator_driver = {
333e85c5a15SMarek Vasut 	.driver = {
334e85c5a15SMarek Vasut 		.name = "bd9571mwv-regulator",
3356eb0bfaeSGeert Uytterhoeven 		.pm = DEV_PM_OPS,
336e85c5a15SMarek Vasut 	},
337e85c5a15SMarek Vasut 	.probe = bd9571mwv_regulator_probe,
33802b3a073SGeert Uytterhoeven 	.remove = bd9571mwv_regulator_remove,
339e85c5a15SMarek Vasut 	.id_table = bd9571mwv_regulator_id_table,
340e85c5a15SMarek Vasut };
341e85c5a15SMarek Vasut module_platform_driver(bd9571mwv_regulator_driver);
342e85c5a15SMarek Vasut 
343e85c5a15SMarek Vasut MODULE_AUTHOR("Marek Vasut <marek.vasut+renesas@gmail.com>");
344e85c5a15SMarek Vasut MODULE_DESCRIPTION("BD9571MWV Regulator driver");
345e85c5a15SMarek Vasut MODULE_LICENSE("GPL v2");
346