Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Driver for TPS61050/61052 boost converters, typically used for white LEDs
  4 * or audio amplifiers.
  5 *
  6 * Copyright (C) 2011 ST-Ericsson SA
  7 * Written on behalf of Linaro for ST-Ericsson
  8 *
  9 * Author: Linus Walleij <linus.walleij@linaro.org>
 
 
 10 */
 11
 12#include <linux/module.h>
 13#include <linux/kernel.h>
 14#include <linux/init.h>
 15#include <linux/err.h>
 16#include <linux/regmap.h>
 17#include <linux/platform_device.h>
 18#include <linux/regulator/driver.h>
 19#include <linux/mfd/core.h>
 20#include <linux/mfd/tps6105x.h>
 21
 22static const unsigned int tps6105x_voltages[] = {
 23	4500000,
 24	5000000,
 25	5250000,
 26	5000000, /* There is an additional 5V */
 27};
 28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 29static struct regulator_ops tps6105x_regulator_ops = {
 30	.enable		= regulator_enable_regmap,
 31	.disable	= regulator_disable_regmap,
 32	.is_enabled	= regulator_is_enabled_regmap,
 33	.get_voltage_sel = regulator_get_voltage_sel_regmap,
 34	.set_voltage_sel = regulator_set_voltage_sel_regmap,
 35	.list_voltage	= regulator_list_voltage_table,
 36};
 37
 38static const struct regulator_desc tps6105x_regulator_desc = {
 39	.name		= "tps6105x-boost",
 40	.of_match	= of_match_ptr("regulator"),
 41	.ops		= &tps6105x_regulator_ops,
 42	.type		= REGULATOR_VOLTAGE,
 43	.id		= 0,
 44	.owner		= THIS_MODULE,
 45	.n_voltages	= ARRAY_SIZE(tps6105x_voltages),
 46	.volt_table	= tps6105x_voltages,
 47	.vsel_reg	= TPS6105X_REG_0,
 48	.vsel_mask	= TPS6105X_REG0_VOLTAGE_MASK,
 49	.enable_reg	= TPS6105X_REG_0,
 50	.enable_mask	= TPS6105X_REG0_MODE_MASK,
 51	.enable_val	= TPS6105X_REG0_MODE_VOLTAGE <<
 52			  TPS6105X_REG0_MODE_SHIFT,
 53};
 54
 55/*
 56 * Registers the chip as a voltage regulator
 57 */
 58static int tps6105x_regulator_probe(struct platform_device *pdev)
 59{
 60	struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
 61	struct tps6105x_platform_data *pdata = tps6105x->pdata;
 62	struct regulator_config config = { };
 63	int ret;
 64
 65	/* This instance is not set for regulator mode so bail out */
 66	if (pdata->mode != TPS6105X_MODE_VOLTAGE) {
 67		dev_info(&pdev->dev,
 68			"chip not in voltage mode mode, exit probe\n");
 69		return 0;
 70	}
 71
 72	config.dev = &tps6105x->client->dev;
 73	config.init_data = pdata->regulator_data;
 74	config.driver_data = tps6105x;
 75	config.of_node = pdev->dev.parent->of_node;
 76	config.regmap = tps6105x->regmap;
 77
 78	/* Register regulator with framework */
 79	tps6105x->regulator = devm_regulator_register(&pdev->dev,
 80						      &tps6105x_regulator_desc,
 81						      &config);
 82	if (IS_ERR(tps6105x->regulator)) {
 83		ret = PTR_ERR(tps6105x->regulator);
 84		dev_err(&tps6105x->client->dev,
 85			"failed to register regulator\n");
 86		return ret;
 87	}
 88	platform_set_drvdata(pdev, tps6105x);
 89
 90	return 0;
 91}
 92
 
 
 
 
 
 
 
 93static struct platform_driver tps6105x_regulator_driver = {
 94	.driver = {
 95		.name  = "tps6105x-regulator",
 
 96	},
 97	.probe = tps6105x_regulator_probe,
 
 98};
 99
100static __init int tps6105x_regulator_init(void)
101{
102	return platform_driver_register(&tps6105x_regulator_driver);
103}
104subsys_initcall(tps6105x_regulator_init);
105
106static __exit void tps6105x_regulator_exit(void)
107{
108	platform_driver_unregister(&tps6105x_regulator_driver);
109}
110module_exit(tps6105x_regulator_exit);
111
112MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
113MODULE_DESCRIPTION("TPS6105x regulator driver");
114MODULE_LICENSE("GPL v2");
115MODULE_ALIAS("platform:tps6105x-regulator");
v3.5.6
 
  1/*
  2 * Driver for TPS61050/61052 boost converters, typically used for white LEDs
  3 * or audio amplifiers.
  4 *
  5 * Copyright (C) 2011 ST-Ericsson SA
  6 * Written on behalf of Linaro for ST-Ericsson
  7 *
  8 * Author: Linus Walleij <linus.walleij@linaro.org>
  9 *
 10 * License terms: GNU General Public License (GPL) version 2
 11 */
 12
 13#include <linux/module.h>
 14#include <linux/kernel.h>
 15#include <linux/init.h>
 16#include <linux/err.h>
 17#include <linux/i2c.h>
 18#include <linux/platform_device.h>
 19#include <linux/regulator/driver.h>
 20#include <linux/mfd/core.h>
 21#include <linux/mfd/tps6105x.h>
 22
 23static const int tps6105x_voltages[] = {
 24	4500000,
 25	5000000,
 26	5250000,
 27	5000000, /* There is an additional 5V */
 28};
 29
 30static int tps6105x_regulator_enable(struct regulator_dev *rdev)
 31{
 32	struct tps6105x *tps6105x = rdev_get_drvdata(rdev);
 33	int ret;
 34
 35	/* Activate voltage mode */
 36	ret = tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0,
 37		TPS6105X_REG0_MODE_MASK,
 38		TPS6105X_REG0_MODE_VOLTAGE << TPS6105X_REG0_MODE_SHIFT);
 39	if (ret)
 40		return ret;
 41
 42	return 0;
 43}
 44
 45static int tps6105x_regulator_disable(struct regulator_dev *rdev)
 46{
 47	struct tps6105x *tps6105x = rdev_get_drvdata(rdev);
 48	int ret;
 49
 50	/* Set into shutdown mode */
 51	ret = tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0,
 52		TPS6105X_REG0_MODE_MASK,
 53		TPS6105X_REG0_MODE_SHUTDOWN << TPS6105X_REG0_MODE_SHIFT);
 54	if (ret)
 55		return ret;
 56
 57	return 0;
 58}
 59
 60static int tps6105x_regulator_is_enabled(struct regulator_dev *rdev)
 61{
 62	struct tps6105x *tps6105x = rdev_get_drvdata(rdev);
 63	u8 regval;
 64	int ret;
 65
 66	ret = tps6105x_get(tps6105x, TPS6105X_REG_0, &regval);
 67	if (ret)
 68		return ret;
 69	regval &= TPS6105X_REG0_MODE_MASK;
 70	regval >>= TPS6105X_REG0_MODE_SHIFT;
 71
 72	if (regval == TPS6105X_REG0_MODE_VOLTAGE)
 73		return 1;
 74
 75	return 0;
 76}
 77
 78static int tps6105x_regulator_get_voltage_sel(struct regulator_dev *rdev)
 79{
 80	struct tps6105x *tps6105x = rdev_get_drvdata(rdev);
 81	u8 regval;
 82	int ret;
 83
 84	ret = tps6105x_get(tps6105x, TPS6105X_REG_0, &regval);
 85	if (ret)
 86		return ret;
 87
 88	regval &= TPS6105X_REG0_VOLTAGE_MASK;
 89	regval >>= TPS6105X_REG0_VOLTAGE_SHIFT;
 90	return (int) regval;
 91}
 92
 93static int tps6105x_regulator_set_voltage_sel(struct regulator_dev *rdev,
 94					      unsigned selector)
 95{
 96	struct tps6105x *tps6105x = rdev_get_drvdata(rdev);
 97	int ret;
 98
 99	ret = tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0,
100				    TPS6105X_REG0_VOLTAGE_MASK,
101				    selector << TPS6105X_REG0_VOLTAGE_SHIFT);
102	if (ret)
103		return ret;
104
105	return 0;
106}
107
108static int tps6105x_regulator_list_voltage(struct regulator_dev *rdev,
109					   unsigned selector)
110{
111	if (selector >= ARRAY_SIZE(tps6105x_voltages))
112		return -EINVAL;
113
114	return tps6105x_voltages[selector];
115}
116
117static struct regulator_ops tps6105x_regulator_ops = {
118	.enable		= tps6105x_regulator_enable,
119	.disable	= tps6105x_regulator_disable,
120	.is_enabled	= tps6105x_regulator_is_enabled,
121	.get_voltage_sel = tps6105x_regulator_get_voltage_sel,
122	.set_voltage_sel = tps6105x_regulator_set_voltage_sel,
123	.list_voltage	= tps6105x_regulator_list_voltage,
124};
125
126static const struct regulator_desc tps6105x_regulator_desc = {
127	.name		= "tps6105x-boost",
 
128	.ops		= &tps6105x_regulator_ops,
129	.type		= REGULATOR_VOLTAGE,
130	.id		= 0,
131	.owner		= THIS_MODULE,
132	.n_voltages	= ARRAY_SIZE(tps6105x_voltages),
 
 
 
 
 
 
 
133};
134
135/*
136 * Registers the chip as a voltage regulator
137 */
138static int __devinit tps6105x_regulator_probe(struct platform_device *pdev)
139{
140	struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
141	struct tps6105x_platform_data *pdata = tps6105x->pdata;
142	struct regulator_config config = { };
143	int ret;
144
145	/* This instance is not set for regulator mode so bail out */
146	if (pdata->mode != TPS6105X_MODE_VOLTAGE) {
147		dev_info(&pdev->dev,
148			 "chip not in voltage mode mode, exit probe \n");
149		return 0;
150	}
151
152	config.dev = &tps6105x->client->dev;
153	config.init_data = pdata->regulator_data;
154	config.driver_data = tps6105x;
 
 
155
156	/* Register regulator with framework */
157	tps6105x->regulator = regulator_register(&tps6105x_regulator_desc,
158						 &config);
 
159	if (IS_ERR(tps6105x->regulator)) {
160		ret = PTR_ERR(tps6105x->regulator);
161		dev_err(&tps6105x->client->dev,
162			"failed to register regulator\n");
163		return ret;
164	}
165	platform_set_drvdata(pdev, tps6105x);
166
167	return 0;
168}
169
170static int __devexit tps6105x_regulator_remove(struct platform_device *pdev)
171{
172	struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
173	regulator_unregister(tps6105x->regulator);
174	return 0;
175}
176
177static struct platform_driver tps6105x_regulator_driver = {
178	.driver = {
179		.name  = "tps6105x-regulator",
180		.owner = THIS_MODULE,
181	},
182	.probe = tps6105x_regulator_probe,
183	.remove = __devexit_p(tps6105x_regulator_remove),
184};
185
186static __init int tps6105x_regulator_init(void)
187{
188	return platform_driver_register(&tps6105x_regulator_driver);
189}
190subsys_initcall(tps6105x_regulator_init);
191
192static __exit void tps6105x_regulator_exit(void)
193{
194	platform_driver_unregister(&tps6105x_regulator_driver);
195}
196module_exit(tps6105x_regulator_exit);
197
198MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
199MODULE_DESCRIPTION("TPS6105x regulator driver");
200MODULE_LICENSE("GPL v2");
201MODULE_ALIAS("platform:tps6105x-regulator");