Thomas Gleixner | 3c910ec | 2019-06-01 10:09:00 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Beniamino Galvani | 811b700 | 2014-08-30 14:50:24 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Regulator driver for Ricoh RN5T618 PMIC |
| 4 | * |
| 5 | * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com> |
Beniamino Galvani | 811b700 | 2014-08-30 14:50:24 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/mfd/rn5t618.h> |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/of.h> |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/regmap.h> |
| 13 | #include <linux/regulator/driver.h> |
| 14 | #include <linux/regulator/of_regulator.h> |
| 15 | |
Bhumika Goyal | 243842b | 2017-01-28 20:52:23 +0530 | [diff] [blame] | 16 | static const struct regulator_ops rn5t618_reg_ops = { |
Beniamino Galvani | 811b700 | 2014-08-30 14:50:24 +0200 | [diff] [blame] | 17 | .enable = regulator_enable_regmap, |
| 18 | .disable = regulator_disable_regmap, |
| 19 | .is_enabled = regulator_is_enabled_regmap, |
| 20 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 21 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 22 | .list_voltage = regulator_list_voltage_linear, |
| 23 | }; |
| 24 | |
| 25 | #define REG(rid, ereg, emask, vreg, vmask, min, max, step) \ |
Leonard Crestez | d824c7a | 2017-10-13 19:37:31 +0300 | [diff] [blame] | 26 | { \ |
Beniamino Galvani | 811b700 | 2014-08-30 14:50:24 +0200 | [diff] [blame] | 27 | .name = #rid, \ |
Beniamino Galvani | 9075cce | 2014-10-08 23:19:08 +0200 | [diff] [blame] | 28 | .of_match = of_match_ptr(#rid), \ |
| 29 | .regulators_node = of_match_ptr("regulators"), \ |
Beniamino Galvani | 811b700 | 2014-08-30 14:50:24 +0200 | [diff] [blame] | 30 | .id = RN5T618_##rid, \ |
| 31 | .type = REGULATOR_VOLTAGE, \ |
| 32 | .owner = THIS_MODULE, \ |
| 33 | .ops = &rn5t618_reg_ops, \ |
| 34 | .n_voltages = ((max) - (min)) / (step) + 1, \ |
| 35 | .min_uV = (min), \ |
| 36 | .uV_step = (step), \ |
| 37 | .enable_reg = RN5T618_##ereg, \ |
| 38 | .enable_mask = (emask), \ |
| 39 | .vsel_reg = RN5T618_##vreg, \ |
| 40 | .vsel_mask = (vmask), \ |
| 41 | } |
| 42 | |
Axel Lin | c229385 | 2019-03-20 20:10:57 +0800 | [diff] [blame] | 43 | static const struct regulator_desc rn5t567_regulators[] = { |
Stefan Agner | ed6d362 | 2016-06-28 22:53:20 -0700 | [diff] [blame] | 44 | /* DCDC */ |
| 45 | REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500), |
| 46 | REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500), |
| 47 | REG(DCDC3, DC3CTL, BIT(0), DC3DAC, 0xff, 600000, 3500000, 12500), |
| 48 | REG(DCDC4, DC4CTL, BIT(0), DC4DAC, 0xff, 600000, 3500000, 12500), |
| 49 | /* LDO */ |
| 50 | REG(LDO1, LDOEN1, BIT(0), LDO1DAC, 0x7f, 900000, 3500000, 25000), |
| 51 | REG(LDO2, LDOEN1, BIT(1), LDO2DAC, 0x7f, 900000, 3500000, 25000), |
| 52 | REG(LDO3, LDOEN1, BIT(2), LDO3DAC, 0x7f, 600000, 3500000, 25000), |
| 53 | REG(LDO4, LDOEN1, BIT(3), LDO4DAC, 0x7f, 900000, 3500000, 25000), |
| 54 | REG(LDO5, LDOEN1, BIT(4), LDO5DAC, 0x7f, 900000, 3500000, 25000), |
| 55 | /* LDO RTC */ |
| 56 | REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1200000, 3500000, 25000), |
| 57 | REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000), |
| 58 | }; |
| 59 | |
Axel Lin | c229385 | 2019-03-20 20:10:57 +0800 | [diff] [blame] | 60 | static const struct regulator_desc rn5t618_regulators[] = { |
Beniamino Galvani | 811b700 | 2014-08-30 14:50:24 +0200 | [diff] [blame] | 61 | /* DCDC */ |
| 62 | REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500), |
| 63 | REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500), |
| 64 | REG(DCDC3, DC3CTL, BIT(0), DC3DAC, 0xff, 600000, 3500000, 12500), |
| 65 | /* LDO */ |
| 66 | REG(LDO1, LDOEN1, BIT(0), LDO1DAC, 0x7f, 900000, 3500000, 25000), |
| 67 | REG(LDO2, LDOEN1, BIT(1), LDO2DAC, 0x7f, 900000, 3500000, 25000), |
| 68 | REG(LDO3, LDOEN1, BIT(2), LDO3DAC, 0x7f, 600000, 3500000, 25000), |
| 69 | REG(LDO4, LDOEN1, BIT(3), LDO4DAC, 0x7f, 900000, 3500000, 25000), |
| 70 | REG(LDO5, LDOEN1, BIT(4), LDO5DAC, 0x7f, 900000, 3500000, 25000), |
| 71 | /* LDO RTC */ |
| 72 | REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1700000, 3500000, 25000), |
| 73 | REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000), |
| 74 | }; |
| 75 | |
Axel Lin | c229385 | 2019-03-20 20:10:57 +0800 | [diff] [blame] | 76 | static const struct regulator_desc rc5t619_regulators[] = { |
Pierre-Hugues Husson | 83b2a3c | 2017-08-27 15:58:31 +0200 | [diff] [blame] | 77 | /* DCDC */ |
| 78 | REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500), |
| 79 | REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500), |
| 80 | REG(DCDC3, DC3CTL, BIT(0), DC3DAC, 0xff, 600000, 3500000, 12500), |
| 81 | REG(DCDC4, DC4CTL, BIT(0), DC4DAC, 0xff, 600000, 3500000, 12500), |
| 82 | REG(DCDC5, DC5CTL, BIT(0), DC5DAC, 0xff, 600000, 3500000, 12500), |
| 83 | /* LDO */ |
| 84 | REG(LDO1, LDOEN1, BIT(0), LDO1DAC, 0x7f, 900000, 3500000, 25000), |
| 85 | REG(LDO2, LDOEN1, BIT(1), LDO2DAC, 0x7f, 900000, 3500000, 25000), |
| 86 | REG(LDO3, LDOEN1, BIT(2), LDO3DAC, 0x7f, 900000, 3500000, 25000), |
| 87 | REG(LDO4, LDOEN1, BIT(3), LDO4DAC, 0x7f, 900000, 3500000, 25000), |
| 88 | REG(LDO5, LDOEN1, BIT(4), LDO5DAC, 0x7f, 600000, 3500000, 25000), |
| 89 | REG(LDO6, LDOEN1, BIT(5), LDO6DAC, 0x7f, 600000, 3500000, 25000), |
| 90 | REG(LDO7, LDOEN1, BIT(6), LDO7DAC, 0x7f, 900000, 3500000, 25000), |
| 91 | REG(LDO8, LDOEN1, BIT(7), LDO8DAC, 0x7f, 900000, 3500000, 25000), |
| 92 | REG(LDO9, LDOEN2, BIT(0), LDO9DAC, 0x7f, 900000, 3500000, 25000), |
| 93 | REG(LDO10, LDOEN2, BIT(0), LDO10DAC, 0x7f, 900000, 3500000, 25000), |
| 94 | /* LDO RTC */ |
| 95 | REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1700000, 3500000, 25000), |
| 96 | REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000), |
| 97 | }; |
| 98 | |
Beniamino Galvani | 811b700 | 2014-08-30 14:50:24 +0200 | [diff] [blame] | 99 | static int rn5t618_regulator_probe(struct platform_device *pdev) |
| 100 | { |
| 101 | struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent); |
| 102 | struct regulator_config config = { }; |
| 103 | struct regulator_dev *rdev; |
Axel Lin | c229385 | 2019-03-20 20:10:57 +0800 | [diff] [blame] | 104 | const struct regulator_desc *regulators; |
Beniamino Galvani | 9075cce | 2014-10-08 23:19:08 +0200 | [diff] [blame] | 105 | int i; |
Pierre-Hugues Husson | 83b2a3c | 2017-08-27 15:58:31 +0200 | [diff] [blame] | 106 | int num_regulators = 0; |
Beniamino Galvani | 811b700 | 2014-08-30 14:50:24 +0200 | [diff] [blame] | 107 | |
Stefan Agner | ed6d362 | 2016-06-28 22:53:20 -0700 | [diff] [blame] | 108 | switch (rn5t618->variant) { |
| 109 | case RN5T567: |
| 110 | regulators = rn5t567_regulators; |
Pierre-Hugues Husson | 83b2a3c | 2017-08-27 15:58:31 +0200 | [diff] [blame] | 111 | num_regulators = ARRAY_SIZE(rn5t567_regulators); |
Stefan Agner | ed6d362 | 2016-06-28 22:53:20 -0700 | [diff] [blame] | 112 | break; |
| 113 | case RN5T618: |
| 114 | regulators = rn5t618_regulators; |
Pierre-Hugues Husson | 83b2a3c | 2017-08-27 15:58:31 +0200 | [diff] [blame] | 115 | num_regulators = ARRAY_SIZE(rn5t618_regulators); |
| 116 | break; |
| 117 | case RC5T619: |
| 118 | regulators = rc5t619_regulators; |
| 119 | num_regulators = ARRAY_SIZE(rc5t619_regulators); |
Stefan Agner | ed6d362 | 2016-06-28 22:53:20 -0700 | [diff] [blame] | 120 | break; |
| 121 | default: |
| 122 | return -EINVAL; |
| 123 | } |
| 124 | |
| 125 | config.dev = pdev->dev.parent; |
| 126 | config.regmap = rn5t618->regmap; |
| 127 | |
Pierre-Hugues Husson | 83b2a3c | 2017-08-27 15:58:31 +0200 | [diff] [blame] | 128 | for (i = 0; i < num_regulators; i++) { |
Beniamino Galvani | 811b700 | 2014-08-30 14:50:24 +0200 | [diff] [blame] | 129 | rdev = devm_regulator_register(&pdev->dev, |
Stefan Agner | ed6d362 | 2016-06-28 22:53:20 -0700 | [diff] [blame] | 130 | ®ulators[i], |
Beniamino Galvani | 811b700 | 2014-08-30 14:50:24 +0200 | [diff] [blame] | 131 | &config); |
| 132 | if (IS_ERR(rdev)) { |
| 133 | dev_err(&pdev->dev, "failed to register %s regulator\n", |
Stefan Agner | ed6d362 | 2016-06-28 22:53:20 -0700 | [diff] [blame] | 134 | regulators[i].name); |
Beniamino Galvani | 811b700 | 2014-08-30 14:50:24 +0200 | [diff] [blame] | 135 | return PTR_ERR(rdev); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static struct platform_driver rn5t618_regulator_driver = { |
| 143 | .probe = rn5t618_regulator_probe, |
| 144 | .driver = { |
| 145 | .name = "rn5t618-regulator", |
| 146 | }, |
| 147 | }; |
| 148 | |
| 149 | module_platform_driver(rn5t618_regulator_driver); |
| 150 | |
| 151 | MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>"); |
| 152 | MODULE_DESCRIPTION("RN5T618 regulator driver"); |
| 153 | MODULE_LICENSE("GPL v2"); |