| .. | .. |
|---|
| 1 | | -/* |
|---|
| 2 | | - * Copyright (c) 2014 MediaTek Inc. |
|---|
| 3 | | - * Author: Flora Fu <flora.fu@mediatek.com> |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 7 | | - * published by the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | | - * GNU General Public License for more details. |
|---|
| 13 | | - */ |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | +// |
|---|
| 3 | +// Copyright (c) 2014 MediaTek Inc. |
|---|
| 4 | +// Author: Flora Fu <flora.fu@mediatek.com> |
|---|
| 14 | 5 | |
|---|
| 15 | 6 | #include <linux/module.h> |
|---|
| 16 | 7 | #include <linux/of.h> |
|---|
| .. | .. |
|---|
| 22 | 13 | #include <linux/regulator/machine.h> |
|---|
| 23 | 14 | #include <linux/regulator/mt6397-regulator.h> |
|---|
| 24 | 15 | #include <linux/regulator/of_regulator.h> |
|---|
| 25 | | - |
|---|
| 26 | | -#define MT6397_BUCK_MODE_AUTO 0 |
|---|
| 27 | | -#define MT6397_BUCK_MODE_FORCE_PWM 1 |
|---|
| 16 | +#include <dt-bindings/regulator/mediatek,mt6397-regulator.h> |
|---|
| 28 | 17 | |
|---|
| 29 | 18 | /* |
|---|
| 30 | 19 | * MT6397 regulators' information |
|---|
| .. | .. |
|---|
| 64 | 53 | .vsel_mask = vosel_mask, \ |
|---|
| 65 | 54 | .enable_reg = enreg, \ |
|---|
| 66 | 55 | .enable_mask = BIT(0), \ |
|---|
| 56 | + .of_map_mode = mt6397_map_mode, \ |
|---|
| 67 | 57 | }, \ |
|---|
| 68 | 58 | .qi = BIT(13), \ |
|---|
| 69 | 59 | .vselon_reg = voselon, \ |
|---|
| .. | .. |
|---|
| 111 | 101 | .qi = BIT(15), \ |
|---|
| 112 | 102 | } |
|---|
| 113 | 103 | |
|---|
| 114 | | -static const struct regulator_linear_range buck_volt_range1[] = { |
|---|
| 104 | +static const struct linear_range buck_volt_range1[] = { |
|---|
| 115 | 105 | REGULATOR_LINEAR_RANGE(700000, 0, 0x7f, 6250), |
|---|
| 116 | 106 | }; |
|---|
| 117 | 107 | |
|---|
| 118 | | -static const struct regulator_linear_range buck_volt_range2[] = { |
|---|
| 108 | +static const struct linear_range buck_volt_range2[] = { |
|---|
| 119 | 109 | REGULATOR_LINEAR_RANGE(800000, 0, 0x7f, 6250), |
|---|
| 120 | 110 | }; |
|---|
| 121 | 111 | |
|---|
| 122 | | -static const struct regulator_linear_range buck_volt_range3[] = { |
|---|
| 112 | +static const struct linear_range buck_volt_range3[] = { |
|---|
| 123 | 113 | REGULATOR_LINEAR_RANGE(1500000, 0, 0x1f, 20000), |
|---|
| 124 | 114 | }; |
|---|
| 125 | 115 | |
|---|
| 126 | | -static const u32 ldo_volt_table1[] = { |
|---|
| 116 | +static const unsigned int ldo_volt_table1[] = { |
|---|
| 127 | 117 | 1500000, 1800000, 2500000, 2800000, |
|---|
| 128 | 118 | }; |
|---|
| 129 | 119 | |
|---|
| 130 | | -static const u32 ldo_volt_table2[] = { |
|---|
| 120 | +static const unsigned int ldo_volt_table2[] = { |
|---|
| 131 | 121 | 1800000, 3300000, |
|---|
| 132 | 122 | }; |
|---|
| 133 | 123 | |
|---|
| 134 | | -static const u32 ldo_volt_table3[] = { |
|---|
| 124 | +static const unsigned int ldo_volt_table3[] = { |
|---|
| 135 | 125 | 3000000, 3300000, |
|---|
| 136 | 126 | }; |
|---|
| 137 | 127 | |
|---|
| 138 | | -static const u32 ldo_volt_table4[] = { |
|---|
| 128 | +static const unsigned int ldo_volt_table4[] = { |
|---|
| 139 | 129 | 1220000, 1300000, 1500000, 1800000, 2500000, 2800000, 3000000, 3300000, |
|---|
| 140 | 130 | }; |
|---|
| 141 | 131 | |
|---|
| 142 | | -static const u32 ldo_volt_table5[] = { |
|---|
| 132 | +static const unsigned int ldo_volt_table5[] = { |
|---|
| 143 | 133 | 1200000, 1300000, 1500000, 1800000, 2500000, 2800000, 3000000, 3300000, |
|---|
| 144 | 134 | }; |
|---|
| 145 | 135 | |
|---|
| 146 | | -static const u32 ldo_volt_table5_v2[] = { |
|---|
| 136 | +static const unsigned int ldo_volt_table5_v2[] = { |
|---|
| 147 | 137 | 1200000, 1000000, 1500000, 1800000, 2500000, 2800000, 3000000, 3300000, |
|---|
| 148 | 138 | }; |
|---|
| 149 | 139 | |
|---|
| 150 | | -static const u32 ldo_volt_table6[] = { |
|---|
| 140 | +static const unsigned int ldo_volt_table6[] = { |
|---|
| 151 | 141 | 1200000, 1300000, 1500000, 1800000, 2500000, 2800000, 3000000, 2000000, |
|---|
| 152 | 142 | }; |
|---|
| 153 | 143 | |
|---|
| 154 | | -static const u32 ldo_volt_table7[] = { |
|---|
| 144 | +static const unsigned int ldo_volt_table7[] = { |
|---|
| 155 | 145 | 1300000, 1500000, 1800000, 2000000, 2500000, 2800000, 3000000, 3300000, |
|---|
| 156 | 146 | }; |
|---|
| 157 | 147 | |
|---|
| 148 | +static unsigned int mt6397_map_mode(unsigned int mode) |
|---|
| 149 | +{ |
|---|
| 150 | + switch (mode) { |
|---|
| 151 | + case MT6397_BUCK_MODE_AUTO: |
|---|
| 152 | + return REGULATOR_MODE_NORMAL; |
|---|
| 153 | + case MT6397_BUCK_MODE_FORCE_PWM: |
|---|
| 154 | + return REGULATOR_MODE_FAST; |
|---|
| 155 | + default: |
|---|
| 156 | + return REGULATOR_MODE_INVALID; |
|---|
| 157 | + } |
|---|
| 158 | +} |
|---|
| 159 | + |
|---|
| 158 | 160 | static int mt6397_regulator_set_mode(struct regulator_dev *rdev, |
|---|
| 159 | 161 | unsigned int mode) |
|---|
| 160 | 162 | { |
|---|