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

regulator: Add TPS65090 regulator driver

Add TPS65090 regulator driver

TPS65090 PMIC from TI consists of 3 step down converters,
2 always on LDOs and 7 current limited load switches. The
output voltages are ON/OFF controllable and are meant to
supply power to the components on target board.

Signed-off-by: Venu Byravarasu <vbyravarasu@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

authored by

Venu Byravarasu and committed by
Mark Brown
452534e5 4dbd8f63

+255
+7
drivers/regulator/Kconfig
··· 294 294 three step-down converters and two general-purpose LDO voltage regulators. 295 295 It supports TI's software based Class-2 SmartReflex implementation. 296 296 297 + config REGULATOR_TPS65090 298 + tristate "TI TPS65090 Power regulator" 299 + depends on MFD_TPS65090 300 + help 301 + This driver provides support for the voltage regulators on the 302 + TI TPS65090 PMIC. 303 + 297 304 config REGULATOR_TPS65217 298 305 tristate "TI TPS65217 Power regulators" 299 306 depends on MFD_TPS65217
+1
drivers/regulator/Makefile
··· 40 40 obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o 41 41 obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o 42 42 obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o 43 + obj-$(CONFIG_REGULATOR_TPS65090) += tps65090-regulator.o 43 44 obj-$(CONFIG_REGULATOR_TPS65217) += tps65217-regulator.o 44 45 obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o 45 46 obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o
+197
drivers/regulator/tps65090-regulator.c
··· 1 + /* 2 + * Regulator driver for tps65090 power management chip. 3 + * 4 + * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. 5 + 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms and conditions of the GNU General Public License, 8 + * version 2, as published by the Free Software Foundation. 9 + 10 + * This program is distributed in the hope it will be useful, but WITHOUT 11 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 + * more details. 14 + 15 + * You should have received a copy of the GNU General Public License 16 + * along with this program. If not, see <http://www.gnu.org/licenses/> 17 + */ 18 + 19 + #include <linux/module.h> 20 + #include <linux/delay.h> 21 + #include <linux/init.h> 22 + #include <linux/slab.h> 23 + #include <linux/err.h> 24 + #include <linux/platform_device.h> 25 + #include <linux/regulator/driver.h> 26 + #include <linux/regulator/machine.h> 27 + #include <linux/mfd/tps65090.h> 28 + #include <linux/regulator/tps65090-regulator.h> 29 + 30 + struct tps65090_regulator { 31 + int id; 32 + /* Regulator register address.*/ 33 + u8 reg_en_reg; 34 + u8 en_bit; 35 + 36 + /* used by regulator core */ 37 + struct regulator_desc desc; 38 + 39 + /* Device */ 40 + struct device *dev; 41 + }; 42 + 43 + static inline struct device *to_tps65090_dev(struct regulator_dev *rdev) 44 + { 45 + return rdev_get_dev(rdev)->parent->parent; 46 + } 47 + 48 + static int tps65090_reg_is_enabled(struct regulator_dev *rdev) 49 + { 50 + struct tps65090_regulator *ri = rdev_get_drvdata(rdev); 51 + struct device *parent = to_tps65090_dev(rdev); 52 + uint8_t control; 53 + int ret; 54 + 55 + ret = tps65090_read(parent, ri->reg_en_reg, &control); 56 + if (ret < 0) { 57 + dev_err(&rdev->dev, "Error in reading reg 0x%x\n", 58 + ri->reg_en_reg); 59 + return ret; 60 + } 61 + return (((control >> ri->en_bit) & 1) == 1); 62 + } 63 + 64 + static int tps65090_reg_enable(struct regulator_dev *rdev) 65 + { 66 + struct tps65090_regulator *ri = rdev_get_drvdata(rdev); 67 + struct device *parent = to_tps65090_dev(rdev); 68 + int ret; 69 + 70 + ret = tps65090_set_bits(parent, ri->reg_en_reg, ri->en_bit); 71 + if (ret < 0) 72 + dev_err(&rdev->dev, "Error in updating reg 0x%x\n", 73 + ri->reg_en_reg); 74 + return ret; 75 + } 76 + 77 + static int tps65090_reg_disable(struct regulator_dev *rdev) 78 + { 79 + struct tps65090_regulator *ri = rdev_get_drvdata(rdev); 80 + struct device *parent = to_tps65090_dev(rdev); 81 + int ret; 82 + 83 + ret = tps65090_clr_bits(parent, ri->reg_en_reg, ri->en_bit); 84 + if (ret < 0) 85 + dev_err(&rdev->dev, "Error in updating reg 0x%x\n", 86 + ri->reg_en_reg); 87 + 88 + return ret; 89 + } 90 + 91 + static struct regulator_ops tps65090_ops = { 92 + .enable = tps65090_reg_enable, 93 + .disable = tps65090_reg_disable, 94 + .is_enabled = tps65090_reg_is_enabled, 95 + }; 96 + 97 + #define tps65090_REG(_id, _en_reg, _en_bit, _ops) \ 98 + { \ 99 + .reg_en_reg = _en_reg, \ 100 + .en_bit = _en_bit, \ 101 + .id = TPS65090_ID_##_id, \ 102 + .desc = { \ 103 + .name = tps65090_rails(_id), \ 104 + .id = TPS65090_ID_##_id, \ 105 + .ops = &_ops, \ 106 + .type = REGULATOR_VOLTAGE, \ 107 + .owner = THIS_MODULE, \ 108 + }, \ 109 + } 110 + 111 + static struct tps65090_regulator TPS65090_regulator[] = { 112 + tps65090_REG(DCDC1, 12, 0, tps65090_ops), 113 + tps65090_REG(DCDC2, 13, 0, tps65090_ops), 114 + tps65090_REG(DCDC3, 14, 0, tps65090_ops), 115 + tps65090_REG(FET1, 15, 0, tps65090_ops), 116 + tps65090_REG(FET2, 16, 0, tps65090_ops), 117 + tps65090_REG(FET3, 17, 0, tps65090_ops), 118 + tps65090_REG(FET4, 18, 0, tps65090_ops), 119 + tps65090_REG(FET5, 19, 0, tps65090_ops), 120 + tps65090_REG(FET6, 20, 0, tps65090_ops), 121 + tps65090_REG(FET7, 21, 0, tps65090_ops), 122 + }; 123 + 124 + static inline struct tps65090_regulator *find_regulator_info(int id) 125 + { 126 + struct tps65090_regulator *ri; 127 + int i; 128 + 129 + for (i = 0; i < ARRAY_SIZE(TPS65090_regulator); i++) { 130 + ri = &TPS65090_regulator[i]; 131 + if (ri->desc.id == id) 132 + return ri; 133 + } 134 + return NULL; 135 + } 136 + 137 + static int __devinit tps65090_regulator_probe(struct platform_device *pdev) 138 + { 139 + struct tps65090_regulator *ri = NULL; 140 + struct regulator_dev *rdev; 141 + struct tps65090_regulator_platform_data *tps_pdata; 142 + int id = pdev->id; 143 + 144 + dev_dbg(&pdev->dev, "Probing regulator %d\n", id); 145 + 146 + ri = find_regulator_info(id); 147 + if (ri == NULL) { 148 + dev_err(&pdev->dev, "invalid regulator ID specified\n"); 149 + return -EINVAL; 150 + } 151 + tps_pdata = pdev->dev.platform_data; 152 + ri->dev = &pdev->dev; 153 + 154 + rdev = regulator_register(&ri->desc, &pdev->dev, 155 + &tps_pdata->regulator, ri, NULL); 156 + if (IS_ERR_OR_NULL(rdev)) { 157 + dev_err(&pdev->dev, "failed to register regulator %s\n", 158 + ri->desc.name); 159 + return PTR_ERR(rdev); 160 + } 161 + 162 + platform_set_drvdata(pdev, rdev); 163 + return 0; 164 + } 165 + 166 + static int __devexit tps65090_regulator_remove(struct platform_device *pdev) 167 + { 168 + struct regulator_dev *rdev = platform_get_drvdata(pdev); 169 + 170 + regulator_unregister(rdev); 171 + return 0; 172 + } 173 + 174 + static struct platform_driver tps65090_regulator_driver = { 175 + .driver = { 176 + .name = "tps65090-regulator", 177 + .owner = THIS_MODULE, 178 + }, 179 + .probe = tps65090_regulator_probe, 180 + .remove = __devexit_p(tps65090_regulator_remove), 181 + }; 182 + 183 + static int __init tps65090_regulator_init(void) 184 + { 185 + return platform_driver_register(&tps65090_regulator_driver); 186 + } 187 + subsys_initcall(tps65090_regulator_init); 188 + 189 + static void __exit tps65090_regulator_exit(void) 190 + { 191 + platform_driver_unregister(&tps65090_regulator_driver); 192 + } 193 + module_exit(tps65090_regulator_exit); 194 + 195 + MODULE_DESCRIPTION("tps65090 regulator driver"); 196 + MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>"); 197 + MODULE_LICENSE("GPL v2");
+50
include/linux/regulator/tps65090-regulator.h
··· 1 + /* 2 + * Regulator driver interface for TI TPS65090 PMIC family 3 + * 4 + * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. 5 + 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms and conditions of the GNU General Public License, 8 + * version 2, as published by the Free Software Foundation. 9 + 10 + * This program is distributed in the hope it will be useful, but WITHOUT 11 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 + * more details. 14 + 15 + * You should have received a copy of the GNU General Public License 16 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 + */ 18 + 19 + #ifndef __REGULATOR_TPS65090_H 20 + #define __REGULATOR_TPS65090_H 21 + 22 + #include <linux/regulator/machine.h> 23 + 24 + #define tps65090_rails(_name) "tps65090_"#_name 25 + 26 + enum { 27 + TPS65090_ID_DCDC1, 28 + TPS65090_ID_DCDC2, 29 + TPS65090_ID_DCDC3, 30 + TPS65090_ID_FET1, 31 + TPS65090_ID_FET2, 32 + TPS65090_ID_FET3, 33 + TPS65090_ID_FET4, 34 + TPS65090_ID_FET5, 35 + TPS65090_ID_FET6, 36 + TPS65090_ID_FET7, 37 + }; 38 + 39 + /* 40 + * struct tps65090_regulator_platform_data 41 + * 42 + * @regulator: The regulator init data. 43 + * @slew_rate_uV_per_us: Slew rate microvolt per microsec. 44 + */ 45 + 46 + struct tps65090_regulator_platform_data { 47 + struct regulator_init_data regulator; 48 + }; 49 + 50 + #endif /* __REGULATOR_TPS65090_H */