xref: /OK3568_Linux_fs/kernel/drivers/regulator/tps6105x-regulator.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Driver for TPS61050/61052 boost converters, typically used for white LEDs
4*4882a593Smuzhiyun  * or audio amplifiers.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 2011 ST-Ericsson SA
7*4882a593Smuzhiyun  * Written on behalf of Linaro for ST-Ericsson
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * Author: Linus Walleij <linus.walleij@linaro.org>
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/module.h>
13*4882a593Smuzhiyun #include <linux/kernel.h>
14*4882a593Smuzhiyun #include <linux/init.h>
15*4882a593Smuzhiyun #include <linux/err.h>
16*4882a593Smuzhiyun #include <linux/regmap.h>
17*4882a593Smuzhiyun #include <linux/platform_device.h>
18*4882a593Smuzhiyun #include <linux/regulator/driver.h>
19*4882a593Smuzhiyun #include <linux/mfd/core.h>
20*4882a593Smuzhiyun #include <linux/mfd/tps6105x.h>
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun static const unsigned int tps6105x_voltages[] = {
23*4882a593Smuzhiyun 	4500000,
24*4882a593Smuzhiyun 	5000000,
25*4882a593Smuzhiyun 	5250000,
26*4882a593Smuzhiyun 	5000000, /* There is an additional 5V */
27*4882a593Smuzhiyun };
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun static const struct regulator_ops tps6105x_regulator_ops = {
30*4882a593Smuzhiyun 	.enable		= regulator_enable_regmap,
31*4882a593Smuzhiyun 	.disable	= regulator_disable_regmap,
32*4882a593Smuzhiyun 	.is_enabled	= regulator_is_enabled_regmap,
33*4882a593Smuzhiyun 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
34*4882a593Smuzhiyun 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
35*4882a593Smuzhiyun 	.list_voltage	= regulator_list_voltage_table,
36*4882a593Smuzhiyun };
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun static const struct regulator_desc tps6105x_regulator_desc = {
39*4882a593Smuzhiyun 	.name		= "tps6105x-boost",
40*4882a593Smuzhiyun 	.of_match	= of_match_ptr("regulator"),
41*4882a593Smuzhiyun 	.ops		= &tps6105x_regulator_ops,
42*4882a593Smuzhiyun 	.type		= REGULATOR_VOLTAGE,
43*4882a593Smuzhiyun 	.id		= 0,
44*4882a593Smuzhiyun 	.owner		= THIS_MODULE,
45*4882a593Smuzhiyun 	.n_voltages	= ARRAY_SIZE(tps6105x_voltages),
46*4882a593Smuzhiyun 	.volt_table	= tps6105x_voltages,
47*4882a593Smuzhiyun 	.vsel_reg	= TPS6105X_REG_0,
48*4882a593Smuzhiyun 	.vsel_mask	= TPS6105X_REG0_VOLTAGE_MASK,
49*4882a593Smuzhiyun 	.enable_reg	= TPS6105X_REG_0,
50*4882a593Smuzhiyun 	.enable_mask	= TPS6105X_REG0_MODE_MASK,
51*4882a593Smuzhiyun 	.enable_val	= TPS6105X_REG0_MODE_VOLTAGE <<
52*4882a593Smuzhiyun 			  TPS6105X_REG0_MODE_SHIFT,
53*4882a593Smuzhiyun };
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun /*
56*4882a593Smuzhiyun  * Registers the chip as a voltage regulator
57*4882a593Smuzhiyun  */
tps6105x_regulator_probe(struct platform_device * pdev)58*4882a593Smuzhiyun static int tps6105x_regulator_probe(struct platform_device *pdev)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun 	struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
61*4882a593Smuzhiyun 	struct tps6105x_platform_data *pdata = tps6105x->pdata;
62*4882a593Smuzhiyun 	struct regulator_config config = { };
63*4882a593Smuzhiyun 	int ret;
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	/* This instance is not set for regulator mode so bail out */
66*4882a593Smuzhiyun 	if (pdata->mode != TPS6105X_MODE_VOLTAGE) {
67*4882a593Smuzhiyun 		dev_info(&pdev->dev,
68*4882a593Smuzhiyun 			"chip not in voltage mode mode, exit probe\n");
69*4882a593Smuzhiyun 		return 0;
70*4882a593Smuzhiyun 	}
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	config.dev = &tps6105x->client->dev;
73*4882a593Smuzhiyun 	config.init_data = pdata->regulator_data;
74*4882a593Smuzhiyun 	config.driver_data = tps6105x;
75*4882a593Smuzhiyun 	config.of_node = pdev->dev.parent->of_node;
76*4882a593Smuzhiyun 	config.regmap = tps6105x->regmap;
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 	/* Register regulator with framework */
79*4882a593Smuzhiyun 	tps6105x->regulator = devm_regulator_register(&pdev->dev,
80*4882a593Smuzhiyun 						      &tps6105x_regulator_desc,
81*4882a593Smuzhiyun 						      &config);
82*4882a593Smuzhiyun 	if (IS_ERR(tps6105x->regulator)) {
83*4882a593Smuzhiyun 		ret = PTR_ERR(tps6105x->regulator);
84*4882a593Smuzhiyun 		dev_err(&tps6105x->client->dev,
85*4882a593Smuzhiyun 			"failed to register regulator\n");
86*4882a593Smuzhiyun 		return ret;
87*4882a593Smuzhiyun 	}
88*4882a593Smuzhiyun 	platform_set_drvdata(pdev, tps6105x);
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 	return 0;
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun static struct platform_driver tps6105x_regulator_driver = {
94*4882a593Smuzhiyun 	.driver = {
95*4882a593Smuzhiyun 		.name  = "tps6105x-regulator",
96*4882a593Smuzhiyun 	},
97*4882a593Smuzhiyun 	.probe = tps6105x_regulator_probe,
98*4882a593Smuzhiyun };
99*4882a593Smuzhiyun 
tps6105x_regulator_init(void)100*4882a593Smuzhiyun static __init int tps6105x_regulator_init(void)
101*4882a593Smuzhiyun {
102*4882a593Smuzhiyun 	return platform_driver_register(&tps6105x_regulator_driver);
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun subsys_initcall(tps6105x_regulator_init);
105*4882a593Smuzhiyun 
tps6105x_regulator_exit(void)106*4882a593Smuzhiyun static __exit void tps6105x_regulator_exit(void)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun 	platform_driver_unregister(&tps6105x_regulator_driver);
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun module_exit(tps6105x_regulator_exit);
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
113*4882a593Smuzhiyun MODULE_DESCRIPTION("TPS6105x regulator driver");
114*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
115*4882a593Smuzhiyun MODULE_ALIAS("platform:tps6105x-regulator");
116