Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 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> |
Grigoryev Denis | 7e50711 | 2015-10-02 16:14:41 +0000 | [diff] [blame] | 17 | #include <linux/regmap.h> |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 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 | |
Axel Lin | c55979b | 2012-05-20 10:37:33 +0800 | [diff] [blame] | 23 | static const unsigned int tps6105x_voltages[] = { |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 24 | 4500000, |
| 25 | 5000000, |
| 26 | 5250000, |
| 27 | 5000000, /* There is an additional 5V */ |
| 28 | }; |
| 29 | |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 30 | static struct regulator_ops tps6105x_regulator_ops = { |
Axel Lin | fad2ba6 | 2015-11-18 16:22:52 +0800 | [diff] [blame] | 31 | .enable = regulator_enable_regmap, |
| 32 | .disable = regulator_disable_regmap, |
| 33 | .is_enabled = regulator_is_enabled_regmap, |
| 34 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 35 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Axel Lin | c55979b | 2012-05-20 10:37:33 +0800 | [diff] [blame] | 36 | .list_voltage = regulator_list_voltage_table, |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
Axel Lin | d882d73 | 2012-04-06 08:30:42 +0800 | [diff] [blame] | 39 | static const struct regulator_desc tps6105x_regulator_desc = { |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 40 | .name = "tps6105x-boost", |
| 41 | .ops = &tps6105x_regulator_ops, |
| 42 | .type = REGULATOR_VOLTAGE, |
| 43 | .id = 0, |
| 44 | .owner = THIS_MODULE, |
| 45 | .n_voltages = ARRAY_SIZE(tps6105x_voltages), |
Axel Lin | c55979b | 2012-05-20 10:37:33 +0800 | [diff] [blame] | 46 | .volt_table = tps6105x_voltages, |
Axel Lin | fad2ba6 | 2015-11-18 16:22:52 +0800 | [diff] [blame] | 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, |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | /* |
| 56 | * Registers the chip as a voltage regulator |
| 57 | */ |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 58 | static int tps6105x_regulator_probe(struct platform_device *pdev) |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 59 | { |
Samuel Ortiz | a7c98ce | 2011-05-11 10:33:25 +0200 | [diff] [blame] | 60 | struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev); |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 61 | struct tps6105x_platform_data *pdata = tps6105x->pdata; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 62 | struct regulator_config config = { }; |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 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, |
Jingoo Han | 4932e89 | 2013-10-14 17:51:51 +0900 | [diff] [blame] | 68 | "chip not in voltage mode mode, exit probe\n"); |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 69 | return 0; |
| 70 | } |
| 71 | |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 72 | config.dev = &tps6105x->client->dev; |
| 73 | config.init_data = pdata->regulator_data; |
| 74 | config.driver_data = tps6105x; |
Axel Lin | fad2ba6 | 2015-11-18 16:22:52 +0800 | [diff] [blame] | 75 | config.regmap = tps6105x->regmap; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 76 | |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 77 | /* Register regulator with framework */ |
Jingoo Han | 6a2b5a9 | 2013-09-30 09:57:54 +0900 | [diff] [blame] | 78 | tps6105x->regulator = devm_regulator_register(&pdev->dev, |
| 79 | &tps6105x_regulator_desc, |
| 80 | &config); |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 81 | if (IS_ERR(tps6105x->regulator)) { |
| 82 | ret = PTR_ERR(tps6105x->regulator); |
| 83 | dev_err(&tps6105x->client->dev, |
| 84 | "failed to register regulator\n"); |
| 85 | return ret; |
| 86 | } |
Axel Lin | f0f060b | 2011-03-29 17:54:58 +0800 | [diff] [blame] | 87 | platform_set_drvdata(pdev, tps6105x); |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 92 | static struct platform_driver tps6105x_regulator_driver = { |
| 93 | .driver = { |
| 94 | .name = "tps6105x-regulator", |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 95 | }, |
| 96 | .probe = tps6105x_regulator_probe, |
Linus Walleij | 2edd3b6 | 2011-03-09 12:02:55 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | static __init int tps6105x_regulator_init(void) |
| 100 | { |
| 101 | return platform_driver_register(&tps6105x_regulator_driver); |
| 102 | } |
| 103 | subsys_initcall(tps6105x_regulator_init); |
| 104 | |
| 105 | static __exit void tps6105x_regulator_exit(void) |
| 106 | { |
| 107 | platform_driver_unregister(&tps6105x_regulator_driver); |
| 108 | } |
| 109 | module_exit(tps6105x_regulator_exit); |
| 110 | |
| 111 | MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>"); |
| 112 | MODULE_DESCRIPTION("TPS6105x regulator driver"); |
| 113 | MODULE_LICENSE("GPL v2"); |
| 114 | MODULE_ALIAS("platform:tps6105x-regulator"); |