Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 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> |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 20 | #include <linux/init.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/err.h> |
| 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/regulator/driver.h> |
| 25 | #include <linux/regulator/machine.h> |
| 26 | #include <linux/mfd/tps65090.h> |
| 27 | #include <linux/regulator/tps65090-regulator.h> |
| 28 | |
| 29 | struct tps65090_regulator { |
| 30 | int id; |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 31 | /* used by regulator core */ |
| 32 | struct regulator_desc desc; |
| 33 | |
| 34 | /* Device */ |
| 35 | struct device *dev; |
| 36 | }; |
| 37 | |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 38 | static struct regulator_ops tps65090_ops = { |
Axel Lin | 06c4998 | 2012-04-17 17:08:56 +0800 | [diff] [blame] | 39 | .enable = regulator_enable_regmap, |
| 40 | .disable = regulator_disable_regmap, |
| 41 | .is_enabled = regulator_is_enabled_regmap, |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 42 | }; |
| 43 | |
Axel Lin | 4b3bd55 | 2012-03-24 10:57:53 +0800 | [diff] [blame] | 44 | #define tps65090_REG(_id) \ |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 45 | { \ |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 46 | .id = TPS65090_ID_##_id, \ |
| 47 | .desc = { \ |
| 48 | .name = tps65090_rails(_id), \ |
| 49 | .id = TPS65090_ID_##_id, \ |
Axel Lin | 4b3bd55 | 2012-03-24 10:57:53 +0800 | [diff] [blame] | 50 | .ops = &tps65090_ops, \ |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 51 | .type = REGULATOR_VOLTAGE, \ |
| 52 | .owner = THIS_MODULE, \ |
Axel Lin | 06c4998 | 2012-04-17 17:08:56 +0800 | [diff] [blame] | 53 | .enable_reg = (TPS65090_ID_##_id) + 12, \ |
| 54 | .enable_mask = BIT(0), \ |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 55 | }, \ |
| 56 | } |
| 57 | |
| 58 | static struct tps65090_regulator TPS65090_regulator[] = { |
Axel Lin | 4b3bd55 | 2012-03-24 10:57:53 +0800 | [diff] [blame] | 59 | tps65090_REG(DCDC1), |
| 60 | tps65090_REG(DCDC2), |
| 61 | tps65090_REG(DCDC3), |
| 62 | tps65090_REG(FET1), |
| 63 | tps65090_REG(FET2), |
| 64 | tps65090_REG(FET3), |
| 65 | tps65090_REG(FET4), |
| 66 | tps65090_REG(FET5), |
| 67 | tps65090_REG(FET6), |
| 68 | tps65090_REG(FET7), |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | static inline struct tps65090_regulator *find_regulator_info(int id) |
| 72 | { |
| 73 | struct tps65090_regulator *ri; |
| 74 | int i; |
| 75 | |
| 76 | for (i = 0; i < ARRAY_SIZE(TPS65090_regulator); i++) { |
| 77 | ri = &TPS65090_regulator[i]; |
| 78 | if (ri->desc.id == id) |
| 79 | return ri; |
| 80 | } |
| 81 | return NULL; |
| 82 | } |
| 83 | |
| 84 | static int __devinit tps65090_regulator_probe(struct platform_device *pdev) |
| 85 | { |
Axel Lin | 06c4998 | 2012-04-17 17:08:56 +0800 | [diff] [blame] | 86 | struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent); |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 87 | struct tps65090_regulator *ri = NULL; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 88 | struct regulator_config config = { }; |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 89 | struct regulator_dev *rdev; |
| 90 | struct tps65090_regulator_platform_data *tps_pdata; |
| 91 | int id = pdev->id; |
| 92 | |
| 93 | dev_dbg(&pdev->dev, "Probing regulator %d\n", id); |
| 94 | |
| 95 | ri = find_regulator_info(id); |
| 96 | if (ri == NULL) { |
| 97 | dev_err(&pdev->dev, "invalid regulator ID specified\n"); |
| 98 | return -EINVAL; |
| 99 | } |
| 100 | tps_pdata = pdev->dev.platform_data; |
| 101 | ri->dev = &pdev->dev; |
| 102 | |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 103 | config.dev = &pdev->dev; |
| 104 | config.init_data = &tps_pdata->regulator; |
| 105 | config.driver_data = ri; |
Axel Lin | 06c4998 | 2012-04-17 17:08:56 +0800 | [diff] [blame] | 106 | config.regmap = tps65090_mfd->rmap; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 107 | |
| 108 | rdev = regulator_register(&ri->desc, &config); |
Axel Lin | 0ca2d6e | 2012-03-24 10:56:00 +0800 | [diff] [blame] | 109 | if (IS_ERR(rdev)) { |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 110 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
| 111 | ri->desc.name); |
| 112 | return PTR_ERR(rdev); |
| 113 | } |
| 114 | |
| 115 | platform_set_drvdata(pdev, rdev); |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static int __devexit tps65090_regulator_remove(struct platform_device *pdev) |
| 120 | { |
| 121 | struct regulator_dev *rdev = platform_get_drvdata(pdev); |
| 122 | |
| 123 | regulator_unregister(rdev); |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static struct platform_driver tps65090_regulator_driver = { |
| 128 | .driver = { |
| 129 | .name = "tps65090-regulator", |
| 130 | .owner = THIS_MODULE, |
| 131 | }, |
| 132 | .probe = tps65090_regulator_probe, |
| 133 | .remove = __devexit_p(tps65090_regulator_remove), |
| 134 | }; |
| 135 | |
| 136 | static int __init tps65090_regulator_init(void) |
| 137 | { |
| 138 | return platform_driver_register(&tps65090_regulator_driver); |
| 139 | } |
| 140 | subsys_initcall(tps65090_regulator_init); |
| 141 | |
| 142 | static void __exit tps65090_regulator_exit(void) |
| 143 | { |
| 144 | platform_driver_unregister(&tps65090_regulator_driver); |
| 145 | } |
| 146 | module_exit(tps65090_regulator_exit); |
| 147 | |
| 148 | MODULE_DESCRIPTION("tps65090 regulator driver"); |
| 149 | MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>"); |
| 150 | MODULE_LICENSE("GPL v2"); |