Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: Add a subdriver for TI TPS6105x regulator portions v2

This adds a subdriver for the regulator found inside the TPS61050
and TPS61052 chips.

Cc: Samuel Ortiz <samuel.ortiz@intel.com>
Cc: Ola Lilja <ola.o.lilja@stericsson.com>
Cc: Jonas Aberg <jonas.aberg@stericsson.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

authored by

Linus Walleij and committed by
Samuel Ortiz
2edd3b69 798a8eee

+214 -1
+2
drivers/mfd/Kconfig
··· 132 132 config TPS6105X 133 133 tristate "TPS61050/61052 Boost Converters" 134 134 depends on I2C 135 + select REGULATOR 136 + select REGULATOR_FIXED_VOLTAGE 135 137 help 136 138 This option enables a driver for the TP61050/TPS61052 137 139 high-power "white LED driver". This boost converter is
+9
drivers/regulator/Kconfig
··· 223 223 AB3100 analog baseband dealing with power regulators 224 224 for the system. 225 225 226 + config REGULATOR_TPS6105X 227 + tristate "TI TPS6105X Power regulators" 228 + depends on TPS6105X 229 + default y if TPS6105X 230 + help 231 + This driver supports TPS61050/TPS61052 voltage regulator chips. 232 + It is a single boost converter primarily for white LEDs and 233 + audio amplifiers. 234 + 226 235 config REGULATOR_TPS65023 227 236 tristate "TI TPS65023 Power regulators" 228 237 depends on I2C
+1 -1
drivers/regulator/Makefile
··· 34 34 obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o 35 35 obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o 36 36 obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o 37 - 37 + obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o 38 38 obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o 39 39 obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o 40 40 obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o
+196
drivers/regulator/tps6105x-regulator.c
··· 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 + 23 + static const int tps6105x_voltages[] = { 24 + 4500000, 25 + 5000000, 26 + 5250000, 27 + 5000000, /* There is an additional 5V */ 28 + }; 29 + 30 + static 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 + 45 + static 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 + 60 + static 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 + 78 + static 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 + 93 + static 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 + 108 + static 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 + 117 + static 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 + 126 + static 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 + */ 138 + static int __devinit tps6105x_regulator_probe(struct platform_device *pdev) 139 + { 140 + struct tps6105x *tps6105x = mfd_get_data(pdev); 141 + struct tps6105x_platform_data *pdata = tps6105x->pdata; 142 + int ret; 143 + 144 + /* This instance is not set for regulator mode so bail out */ 145 + if (pdata->mode != TPS6105X_MODE_VOLTAGE) { 146 + dev_info(&pdev->dev, 147 + "chip not in voltage mode mode, exit probe \n"); 148 + return 0; 149 + } 150 + 151 + /* Register regulator with framework */ 152 + tps6105x->regulator = regulator_register(&tps6105x_regulator_desc, 153 + &tps6105x->client->dev, 154 + pdata->regulator_data, tps6105x); 155 + if (IS_ERR(tps6105x->regulator)) { 156 + ret = PTR_ERR(tps6105x->regulator); 157 + dev_err(&tps6105x->client->dev, 158 + "failed to register regulator\n"); 159 + return ret; 160 + } 161 + 162 + return 0; 163 + } 164 + 165 + static int __devexit tps6105x_regulator_remove(struct platform_device *pdev) 166 + { 167 + struct tps6105x *tps6105x = platform_get_drvdata(pdev); 168 + regulator_unregister(tps6105x->regulator); 169 + return 0; 170 + } 171 + 172 + static struct platform_driver tps6105x_regulator_driver = { 173 + .driver = { 174 + .name = "tps6105x-regulator", 175 + .owner = THIS_MODULE, 176 + }, 177 + .probe = tps6105x_regulator_probe, 178 + .remove = __devexit_p(tps6105x_regulator_remove), 179 + }; 180 + 181 + static __init int tps6105x_regulator_init(void) 182 + { 183 + return platform_driver_register(&tps6105x_regulator_driver); 184 + } 185 + subsys_initcall(tps6105x_regulator_init); 186 + 187 + static __exit void tps6105x_regulator_exit(void) 188 + { 189 + platform_driver_unregister(&tps6105x_regulator_driver); 190 + } 191 + module_exit(tps6105x_regulator_exit); 192 + 193 + MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>"); 194 + MODULE_DESCRIPTION("TPS6105x regulator driver"); 195 + MODULE_LICENSE("GPL v2"); 196 + MODULE_ALIAS("platform:tps6105x-regulator");
+6
include/linux/mfd/tps6105x.h
··· 10 10 #define MFD_TPS6105X_H 11 11 12 12 #include <linux/i2c.h> 13 + #include <linux/regulator/machine.h> 13 14 14 15 /* 15 16 * Register definitions to all subdrivers ··· 72 71 * struct tps6105x_platform_data - TPS61905x platform data 73 72 * @mode: what mode this instance shall be operated in, 74 73 * this is not selectable at runtime 74 + * @regulator_data: initialization data for the voltage 75 + * regulator if used as a voltage source 75 76 */ 76 77 struct tps6105x_platform_data { 77 78 enum tps6105x_mode mode; 79 + struct regulator_init_data *regulator_data; 78 80 }; 79 81 80 82 /** 81 83 * struct tps6105x - state holder for the TPS6105x drivers 82 84 * @mutex: mutex to serialize I2C accesses 83 85 * @i2c_client: corresponding I2C client 86 + * @regulator: regulator device if used in voltage mode 84 87 */ 85 88 struct tps6105x { 86 89 struct tps6105x_platform_data *pdata; 87 90 struct mutex lock; 88 91 struct i2c_client *client; 92 + struct regulator_dev *regulator; 89 93 }; 90 94 91 95 extern int tps6105x_set(struct tps6105x *tps6105x, u8 reg, u8 value);