Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 2 | /* NXP PCF50633 PMIC Driver |
| 3 | * |
| 4 | * (C) 2006-2008 by Openmoko, Inc. |
| 5 | * Author: Balaji Rao <balajirrao@openmoko.org> |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Broken down from monstrous PCF50633 driver mainly by |
| 9 | * Harald Welte and Andy Green and Werner Almesberger |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | |
| 19 | #include <linux/mfd/pcf50633/core.h> |
| 20 | #include <linux/mfd/pcf50633/pmic.h> |
| 21 | |
Axel Lin | 05cf34c | 2012-11-28 10:41:04 +0800 | [diff] [blame] | 22 | #define PCF50633_REGULATOR(_name, _id, _min_uV, _uV_step, _min_sel, _n) \ |
Axel Lin | 11bb88e | 2012-04-18 10:50:37 +0800 | [diff] [blame] | 23 | { \ |
| 24 | .name = _name, \ |
| 25 | .id = PCF50633_REGULATOR_##_id, \ |
| 26 | .ops = &pcf50633_regulator_ops, \ |
| 27 | .n_voltages = _n, \ |
Axel Lin | 05cf34c | 2012-11-28 10:41:04 +0800 | [diff] [blame] | 28 | .min_uV = _min_uV, \ |
| 29 | .uV_step = _uV_step, \ |
| 30 | .linear_min_sel = _min_sel, \ |
Axel Lin | 11bb88e | 2012-04-18 10:50:37 +0800 | [diff] [blame] | 31 | .type = REGULATOR_VOLTAGE, \ |
| 32 | .owner = THIS_MODULE, \ |
Axel Lin | 98667b4 | 2012-04-18 10:51:59 +0800 | [diff] [blame] | 33 | .vsel_reg = PCF50633_REG_##_id##OUT, \ |
| 34 | .vsel_mask = 0xff, \ |
Axel Lin | 11bb88e | 2012-04-18 10:50:37 +0800 | [diff] [blame] | 35 | .enable_reg = PCF50633_REG_##_id##OUT + 1, \ |
| 36 | .enable_mask = PCF50633_REGULATOR_ON, \ |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 37 | } |
| 38 | |
Bhumika Goyal | 0be7943 | 2017-01-28 20:30:16 +0530 | [diff] [blame] | 39 | static const struct regulator_ops pcf50633_regulator_ops = { |
Axel Lin | 368a788 | 2012-06-11 14:43:57 +0800 | [diff] [blame] | 40 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Axel Lin | 98667b4 | 2012-04-18 10:51:59 +0800 | [diff] [blame] | 41 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
Axel Lin | 05cf34c | 2012-11-28 10:41:04 +0800 | [diff] [blame] | 42 | .list_voltage = regulator_list_voltage_linear, |
| 43 | .map_voltage = regulator_map_voltage_linear, |
Axel Lin | 11bb88e | 2012-04-18 10:50:37 +0800 | [diff] [blame] | 44 | .enable = regulator_enable_regmap, |
| 45 | .disable = regulator_disable_regmap, |
| 46 | .is_enabled = regulator_is_enabled_regmap, |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
Axel Lin | 2ac2d7d | 2012-04-05 12:02:36 +0800 | [diff] [blame] | 49 | static const struct regulator_desc regulators[] = { |
Axel Lin | 05cf34c | 2012-11-28 10:41:04 +0800 | [diff] [blame] | 50 | [PCF50633_REGULATOR_AUTO] = |
| 51 | PCF50633_REGULATOR("auto", AUTO, 1800000, 25000, 0x2f, 128), |
| 52 | [PCF50633_REGULATOR_DOWN1] = |
| 53 | PCF50633_REGULATOR("down1", DOWN1, 625000, 25000, 0, 96), |
| 54 | [PCF50633_REGULATOR_DOWN2] = |
| 55 | PCF50633_REGULATOR("down2", DOWN2, 625000, 25000, 0, 96), |
| 56 | [PCF50633_REGULATOR_LDO1] = |
| 57 | PCF50633_REGULATOR("ldo1", LDO1, 900000, 100000, 0, 28), |
| 58 | [PCF50633_REGULATOR_LDO2] = |
| 59 | PCF50633_REGULATOR("ldo2", LDO2, 900000, 100000, 0, 28), |
| 60 | [PCF50633_REGULATOR_LDO3] = |
| 61 | PCF50633_REGULATOR("ldo3", LDO3, 900000, 100000, 0, 28), |
| 62 | [PCF50633_REGULATOR_LDO4] = |
| 63 | PCF50633_REGULATOR("ldo4", LDO4, 900000, 100000, 0, 28), |
| 64 | [PCF50633_REGULATOR_LDO5] = |
| 65 | PCF50633_REGULATOR("ldo5", LDO5, 900000, 100000, 0, 28), |
| 66 | [PCF50633_REGULATOR_LDO6] = |
| 67 | PCF50633_REGULATOR("ldo6", LDO6, 900000, 100000, 0, 28), |
| 68 | [PCF50633_REGULATOR_HCLDO] = |
| 69 | PCF50633_REGULATOR("hcldo", HCLDO, 900000, 100000, 0, 28), |
| 70 | [PCF50633_REGULATOR_MEMLDO] = |
| 71 | PCF50633_REGULATOR("memldo", MEMLDO, 900000, 100000, 0, 28), |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 74 | static int pcf50633_regulator_probe(struct platform_device *pdev) |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 75 | { |
| 76 | struct regulator_dev *rdev; |
| 77 | struct pcf50633 *pcf; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 78 | struct regulator_config config = { }; |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 79 | |
| 80 | /* Already set by core driver */ |
Lars-Peter Clausen | 98c2e49 | 2009-10-14 02:12:36 +0400 | [diff] [blame] | 81 | pcf = dev_to_pcf50633(pdev->dev.parent); |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 82 | |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 83 | config.dev = &pdev->dev; |
Jingoo Han | dff91d0 | 2013-07-30 17:20:47 +0900 | [diff] [blame] | 84 | config.init_data = dev_get_platdata(&pdev->dev); |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 85 | config.driver_data = pcf; |
Axel Lin | 11bb88e | 2012-04-18 10:50:37 +0800 | [diff] [blame] | 86 | config.regmap = pcf->regmap; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 87 | |
Jingoo Han | 5e0165e | 2013-09-30 09:57:23 +0900 | [diff] [blame] | 88 | rdev = devm_regulator_register(&pdev->dev, ®ulators[pdev->id], |
| 89 | &config); |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 90 | if (IS_ERR(rdev)) |
| 91 | return PTR_ERR(rdev); |
| 92 | |
Lars-Peter Clausen | 98c2e49 | 2009-10-14 02:12:36 +0400 | [diff] [blame] | 93 | platform_set_drvdata(pdev, rdev); |
| 94 | |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 95 | if (pcf->pdata->regulator_registered) |
| 96 | pcf->pdata->regulator_registered(pcf, pdev->id); |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 101 | static struct platform_driver pcf50633_regulator_driver = { |
| 102 | .driver = { |
Axel Lin | 561427f | 2013-11-30 12:21:03 +0800 | [diff] [blame] | 103 | .name = "pcf50633-regulator", |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 104 | }, |
| 105 | .probe = pcf50633_regulator_probe, |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | static int __init pcf50633_regulator_init(void) |
| 109 | { |
| 110 | return platform_driver_register(&pcf50633_regulator_driver); |
| 111 | } |
Mark Brown | 5a1b22b | 2009-04-27 18:21:18 +0100 | [diff] [blame] | 112 | subsys_initcall(pcf50633_regulator_init); |
Balaji Rao | 5ec271e | 2009-01-09 01:51:01 +0100 | [diff] [blame] | 113 | |
| 114 | static void __exit pcf50633_regulator_exit(void) |
| 115 | { |
| 116 | platform_driver_unregister(&pcf50633_regulator_driver); |
| 117 | } |
| 118 | module_exit(pcf50633_regulator_exit); |
| 119 | |
| 120 | MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>"); |
| 121 | MODULE_DESCRIPTION("PCF50633 regulator driver"); |
| 122 | MODULE_LICENSE("GPL"); |
| 123 | MODULE_ALIAS("platform:pcf50633-regulator"); |