diff options
62 files changed, 2302 insertions, 1252 deletions
diff --git a/Documentation/devicetree/bindings/mfd/rk808.txt b/Documentation/devicetree/bindings/mfd/rk808.txt index 9e6e2592e5c8..4ca6aab4273a 100644 --- a/Documentation/devicetree/bindings/mfd/rk808.txt +++ b/Documentation/devicetree/bindings/mfd/rk808.txt | |||
@@ -24,6 +24,10 @@ Optional properties: | |||
24 | - vcc10-supply: The input supply for LDO_REG6 | 24 | - vcc10-supply: The input supply for LDO_REG6 |
25 | - vcc11-supply: The input supply for LDO_REG8 | 25 | - vcc11-supply: The input supply for LDO_REG8 |
26 | - vcc12-supply: The input supply for SWITCH_REG2 | 26 | - vcc12-supply: The input supply for SWITCH_REG2 |
27 | - dvs-gpios: buck1/2 can be controlled by gpio dvs, this is GPIO specifiers | ||
28 | for 2 host gpio's used for dvs. The format of the gpio specifier depends in | ||
29 | the gpio controller. If DVS GPIOs aren't present, voltage changes will happen | ||
30 | very quickly with no slow ramp time. | ||
27 | 31 | ||
28 | Regulators: All the regulators of RK808 to be instantiated shall be | 32 | Regulators: All the regulators of RK808 to be instantiated shall be |
29 | listed in a child node named 'regulators'. Each regulator is represented | 33 | listed in a child node named 'regulators'. Each regulator is represented |
@@ -55,7 +59,9 @@ Example: | |||
55 | interrupt-parent = <&gpio0>; | 59 | interrupt-parent = <&gpio0>; |
56 | interrupts = <4 IRQ_TYPE_LEVEL_LOW>; | 60 | interrupts = <4 IRQ_TYPE_LEVEL_LOW>; |
57 | pinctrl-names = "default"; | 61 | pinctrl-names = "default"; |
58 | pinctrl-0 = <&pmic_int>; | 62 | pinctrl-0 = <&pmic_int &dvs_1 &dvs_2>; |
63 | dvs-gpios = <&gpio7 11 GPIO_ACTIVE_HIGH>, | ||
64 | <&gpio7 15 GPIO_ACTIVE_HIGH>; | ||
59 | reg = <0x1b>; | 65 | reg = <0x1b>; |
60 | rockchip,system-power-controller; | 66 | rockchip,system-power-controller; |
61 | wakeup-source; | 67 | wakeup-source; |
diff --git a/Documentation/devicetree/bindings/regulator/da9210.txt b/Documentation/devicetree/bindings/regulator/da9210.txt index 3297c53cb915..7aa9b1fa6b21 100644 --- a/Documentation/devicetree/bindings/regulator/da9210.txt +++ b/Documentation/devicetree/bindings/regulator/da9210.txt | |||
@@ -5,6 +5,10 @@ Required properties: | |||
5 | - compatible: must be "dlg,da9210" | 5 | - compatible: must be "dlg,da9210" |
6 | - reg: the i2c slave address of the regulator. It should be 0x68. | 6 | - reg: the i2c slave address of the regulator. It should be 0x68. |
7 | 7 | ||
8 | Optional properties: | ||
9 | |||
10 | - interrupts: a reference to the DA9210 interrupt, if available. | ||
11 | |||
8 | Any standard regulator properties can be used to configure the single da9210 | 12 | Any standard regulator properties can be used to configure the single da9210 |
9 | DCDC. | 13 | DCDC. |
10 | 14 | ||
diff --git a/Documentation/devicetree/bindings/regulator/da9211.txt b/Documentation/devicetree/bindings/regulator/da9211.txt index eb618907c7de..c620493e8dbe 100644 --- a/Documentation/devicetree/bindings/regulator/da9211.txt +++ b/Documentation/devicetree/bindings/regulator/da9211.txt | |||
@@ -1,7 +1,7 @@ | |||
1 | * Dialog Semiconductor DA9211/DA9213 Voltage Regulator | 1 | * Dialog Semiconductor DA9211/DA9213/DA9215 Voltage Regulator |
2 | 2 | ||
3 | Required properties: | 3 | Required properties: |
4 | - compatible: "dlg,da9211" or "dlg,da9213". | 4 | - compatible: "dlg,da9211" or "dlg,da9213" or "dlg,da9215" |
5 | - reg: I2C slave address, usually 0x68. | 5 | - reg: I2C slave address, usually 0x68. |
6 | - interrupts: the interrupt outputs of the controller | 6 | - interrupts: the interrupt outputs of the controller |
7 | - regulators: A node that houses a sub-node for each regulator within the | 7 | - regulators: A node that houses a sub-node for each regulator within the |
@@ -66,3 +66,31 @@ Example 2) DA9213 | |||
66 | }; | 66 | }; |
67 | }; | 67 | }; |
68 | }; | 68 | }; |
69 | |||
70 | |||
71 | Example 3) DA9215 | ||
72 | pmic: da9215@68 { | ||
73 | compatible = "dlg,da9215"; | ||
74 | reg = <0x68>; | ||
75 | interrupts = <3 27>; | ||
76 | |||
77 | regulators { | ||
78 | BUCKA { | ||
79 | regulator-name = "VBUCKA"; | ||
80 | regulator-min-microvolt = < 300000>; | ||
81 | regulator-max-microvolt = <1570000>; | ||
82 | regulator-min-microamp = <4000000>; | ||
83 | regulator-max-microamp = <7000000>; | ||
84 | enable-gpios = <&gpio 27 0>; | ||
85 | }; | ||
86 | BUCKB { | ||
87 | regulator-name = "VBUCKB"; | ||
88 | regulator-min-microvolt = < 300000>; | ||
89 | regulator-max-microvolt = <1570000>; | ||
90 | regulator-min-microamp = <4000000>; | ||
91 | regulator-max-microamp = <7000000>; | ||
92 | enable-gpios = <&gpio 17 0>; | ||
93 | }; | ||
94 | }; | ||
95 | }; | ||
96 | |||
diff --git a/Documentation/devicetree/bindings/regulator/max8973-regulator.txt b/Documentation/devicetree/bindings/regulator/max8973-regulator.txt index 55efb24e5683..f80ea2fe27e6 100644 --- a/Documentation/devicetree/bindings/regulator/max8973-regulator.txt +++ b/Documentation/devicetree/bindings/regulator/max8973-regulator.txt | |||
@@ -25,6 +25,12 @@ Optional properties: | |||
25 | -maxim,enable-frequency-shift: boolean, enable 9% frequency shift. | 25 | -maxim,enable-frequency-shift: boolean, enable 9% frequency shift. |
26 | -maxim,enable-bias-control: boolean, enable bias control. By enabling this | 26 | -maxim,enable-bias-control: boolean, enable bias control. By enabling this |
27 | startup delay can be reduce to 20us from 220us. | 27 | startup delay can be reduce to 20us from 220us. |
28 | -maxim,enable-etr: boolean, enable Enhanced Transient Response. | ||
29 | -maxim,enable-high-etr-sensitivity: boolean, Enhanced transient response | ||
30 | circuit is enabled and set for high sensitivity. If this | ||
31 | property is available then etr will be enable default. | ||
32 | |||
33 | Enhanced transient response (ETR) will affect the configuration of CKADV. | ||
28 | 34 | ||
29 | Example: | 35 | Example: |
30 | 36 | ||
diff --git a/Documentation/devicetree/bindings/regulator/mt6311-regulator.txt b/Documentation/devicetree/bindings/regulator/mt6311-regulator.txt new file mode 100644 index 000000000000..02649d8b3f5a --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/mt6311-regulator.txt | |||
@@ -0,0 +1,35 @@ | |||
1 | Mediatek MT6311 Regulator Driver | ||
2 | |||
3 | Required properties: | ||
4 | - compatible: "mediatek,mt6311-regulator" | ||
5 | - reg: I2C slave address, usually 0x6b. | ||
6 | - regulators: List of regulators provided by this controller. It is named | ||
7 | to VDVFS and VBIASN. | ||
8 | The definition for each of these nodes is defined using the standard binding | ||
9 | for regulators at Documentation/devicetree/bindings/regulator/regulator.txt. | ||
10 | |||
11 | The valid names for regulators are: | ||
12 | BUCK: | ||
13 | VDVFS | ||
14 | LDO: | ||
15 | VBIASN | ||
16 | |||
17 | Example: | ||
18 | mt6311: pmic@6b { | ||
19 | compatible = "mediatek,mt6311-regulator"; | ||
20 | reg = <0x6b>; | ||
21 | |||
22 | regulators { | ||
23 | mt6311_vcpu_reg: VDVFS { | ||
24 | regulator-name = "VDVFS"; | ||
25 | regulator-min-microvolt = < 600000>; | ||
26 | regulator-max-microvolt = <1400000>; | ||
27 | regulator-ramp-delay = <10000>; | ||
28 | }; | ||
29 | mt6311_ldo_reg: VBIASN { | ||
30 | regulator-name = "VBIASN"; | ||
31 | regulator-min-microvolt = <200000>; | ||
32 | regulator-max-microvolt = <800000>; | ||
33 | }; | ||
34 | }; | ||
35 | }; | ||
diff --git a/Documentation/devicetree/bindings/regulator/pwm-regulator.txt b/Documentation/devicetree/bindings/regulator/pwm-regulator.txt index ce91f61feb12..ed936f0f34f2 100644 --- a/Documentation/devicetree/bindings/regulator/pwm-regulator.txt +++ b/Documentation/devicetree/bindings/regulator/pwm-regulator.txt | |||
@@ -1,27 +1,68 @@ | |||
1 | pwm regulator bindings | 1 | Bindings for the Generic PWM Regulator |
2 | ====================================== | ||
3 | |||
4 | Currently supports 2 modes of operation: | ||
5 | |||
6 | Voltage Table: When in this mode, a voltage table (See below) of | ||
7 | predefined voltage <=> duty-cycle values must be | ||
8 | provided via DT. Limitations are that the regulator can | ||
9 | only operate at the voltages supplied in the table. | ||
10 | Intermediary duty-cycle values which would normally | ||
11 | allow finer grained voltage selection are ignored and | ||
12 | rendered useless. Although more control is given to | ||
13 | the user if the assumptions made in continuous-voltage | ||
14 | mode do not reign true. | ||
15 | |||
16 | Continuous Voltage: This mode uses the regulator's maximum and minimum | ||
17 | supplied voltages specified in the | ||
18 | regulator-{min,max}-microvolt properties to calculate | ||
19 | appropriate duty-cycle values. This allows for a much | ||
20 | more fine grained solution when compared with | ||
21 | voltage-table mode above. This solution does make an | ||
22 | assumption that a %50 duty-cycle value will cause the | ||
23 | regulator voltage to run at half way between the | ||
24 | supplied max_uV and min_uV values. | ||
2 | 25 | ||
3 | Required properties: | 26 | Required properties: |
4 | - compatible: Should be "pwm-regulator" | 27 | -------------------- |
5 | - pwms: OF device-tree PWM specification (see PWM binding pwm.txt) | 28 | - compatible: Should be "pwm-regulator" |
6 | - voltage-table: voltage and duty table, include 2 members in each set of | 29 | |
7 | brackets, first one is voltage(unit: uv), the next is duty(unit: percent) | 30 | - pwms: PWM specification (See: ../pwm/pwm.txt) |
31 | |||
32 | Only required for Voltage Table Mode: | ||
33 | - voltage-table: Voltage and Duty-Cycle table consisting of 2 cells | ||
34 | First cell is voltage in microvolts (uV) | ||
35 | Second cell is duty-cycle in percent (%) | ||
36 | |||
37 | NB: To be clear, if voltage-table is provided, then the device will be used | ||
38 | in Voltage Table Mode. If no voltage-table is provided, then the device will | ||
39 | be used in Continuous Voltage Mode. | ||
8 | 40 | ||
9 | Any property defined as part of the core regulator binding defined in | 41 | Any property defined as part of the core regulator binding can also be used. |
10 | regulator.txt can also be used. | 42 | (See: ../regulator/regulator.txt) |
11 | 43 | ||
12 | Example: | 44 | Continuous Voltage Example: |
13 | pwm_regulator { | 45 | pwm_regulator { |
14 | compatible = "pwm-regulator; | 46 | compatible = "pwm-regulator; |
15 | pwms = <&pwm1 0 8448 0>; | 47 | pwms = <&pwm1 0 8448 0>; |
48 | regulator-min-microvolt = <1016000>; | ||
49 | regulator-max-microvolt = <1114000>; | ||
50 | regulator-name = "vdd_logic"; | ||
51 | }; | ||
16 | 52 | ||
53 | Voltage Table Example: | ||
54 | pwm_regulator { | ||
55 | compatible = "pwm-regulator; | ||
56 | pwms = <&pwm1 0 8448 0>; | ||
57 | regulator-min-microvolt = <1016000>; | ||
58 | regulator-max-microvolt = <1114000>; | ||
59 | regulator-name = "vdd_logic"; | ||
60 | |||
61 | /* Voltage Duty-Cycle */ | ||
17 | voltage-table = <1114000 0>, | 62 | voltage-table = <1114000 0>, |
18 | <1095000 10>, | 63 | <1095000 10>, |
19 | <1076000 20>, | 64 | <1076000 20>, |
20 | <1056000 30>, | 65 | <1056000 30>, |
21 | <1036000 40>, | 66 | <1036000 40>, |
22 | <1016000 50>; | 67 | <1016000 50>; |
23 | |||
24 | regulator-min-microvolt = <1016000>; | ||
25 | regulator-max-microvolt = <1114000>; | ||
26 | regulator-name = "vdd_logic"; | ||
27 | }; | 68 | }; |
diff --git a/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt b/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt index 75b4604bad07..d00bfd8624a5 100644 --- a/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt +++ b/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt | |||
@@ -91,13 +91,65 @@ see regulator.txt - with additional custom properties described below: | |||
91 | - regulator-initial-mode: | 91 | - regulator-initial-mode: |
92 | Usage: optional | 92 | Usage: optional |
93 | Value type: <u32> | 93 | Value type: <u32> |
94 | Descrption: 1 = Set initial mode to high power mode (HPM), also referred | 94 | Description: 2 = Set initial mode to auto mode (automatically select |
95 | to as NPM. HPM consumes more ground current than LPM, but | 95 | between HPM and LPM); not available on boost type |
96 | regulators. | ||
97 | |||
98 | 1 = Set initial mode to high power mode (HPM), also referred | ||
99 | to as NPM. HPM consumes more ground current than LPM, but | ||
96 | it can source significantly higher load current. HPM is not | 100 | it can source significantly higher load current. HPM is not |
97 | available on boost type regulators. For voltage switch type | 101 | available on boost type regulators. For voltage switch type |
98 | regulators, HPM implies that over current protection and | 102 | regulators, HPM implies that over current protection and |
99 | soft start are active all the time. 0 = Set initial mode to | 103 | soft start are active all the time. |
100 | low power mode (LPM). | 104 | |
105 | 0 = Set initial mode to low power mode (LPM). | ||
106 | |||
107 | - qcom,ocp-max-retries: | ||
108 | Usage: optional | ||
109 | Value type: <u32> | ||
110 | Description: Maximum number of times to try toggling a voltage switch | ||
111 | off and back on as a result of consecutive over current | ||
112 | events. | ||
113 | |||
114 | - qcom,ocp-retry-delay: | ||
115 | Usage: optional | ||
116 | Value type: <u32> | ||
117 | Description: Time to delay in milliseconds between each voltage switch | ||
118 | toggle after an over current event takes place. | ||
119 | |||
120 | - qcom,pin-ctrl-enable: | ||
121 | Usage: optional | ||
122 | Value type: <u32> | ||
123 | Description: Bit mask specifying which hardware pins should be used to | ||
124 | enable the regulator, if any; supported bits are: | ||
125 | 0 = ignore all hardware enable signals | ||
126 | BIT(0) = follow HW0_EN signal | ||
127 | BIT(1) = follow HW1_EN signal | ||
128 | BIT(2) = follow HW2_EN signal | ||
129 | BIT(3) = follow HW3_EN signal | ||
130 | |||
131 | - qcom,pin-ctrl-hpm: | ||
132 | Usage: optional | ||
133 | Value type: <u32> | ||
134 | Description: Bit mask specifying which hardware pins should be used to | ||
135 | force the regulator into high power mode, if any; | ||
136 | supported bits are: | ||
137 | 0 = ignore all hardware enable signals | ||
138 | BIT(0) = follow HW0_EN signal | ||
139 | BIT(1) = follow HW1_EN signal | ||
140 | BIT(2) = follow HW2_EN signal | ||
141 | BIT(3) = follow HW3_EN signal | ||
142 | BIT(4) = follow PMIC awake state | ||
143 | |||
144 | - qcom,vs-soft-start-strength: | ||
145 | Usage: optional | ||
146 | Value type: <u32> | ||
147 | Description: This property sets the soft start strength for voltage | ||
148 | switch type regulators; supported values are: | ||
149 | 0 = 0.05 uA | ||
150 | 1 = 0.25 uA | ||
151 | 2 = 0.55 uA | ||
152 | 3 = 0.75 uA | ||
101 | 153 | ||
102 | Example: | 154 | Example: |
103 | 155 | ||
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt index db88feb28c03..24bd422cecd5 100644 --- a/Documentation/devicetree/bindings/regulator/regulator.txt +++ b/Documentation/devicetree/bindings/regulator/regulator.txt | |||
@@ -42,6 +42,7 @@ Optional properties: | |||
42 | - regulator-system-load: Load in uA present on regulator that is not captured by | 42 | - regulator-system-load: Load in uA present on regulator that is not captured by |
43 | any consumer request. | 43 | any consumer request. |
44 | - regulator-pull-down: Enable pull down resistor when the regulator is disabled. | 44 | - regulator-pull-down: Enable pull down resistor when the regulator is disabled. |
45 | - regulator-over-current-protection: Enable over current protection. | ||
45 | 46 | ||
46 | Deprecated properties: | 47 | Deprecated properties: |
47 | - regulator-compatible: If a regulator chip contains multiple | 48 | - regulator-compatible: If a regulator chip contains multiple |
diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index f4f3b3d53928..35b9e118b2fb 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/err.h> | 24 | #include <linux/err.h> |
25 | #include <linux/platform_device.h> | 25 | #include <linux/platform_device.h> |
26 | #include <linux/mfd/max77693.h> | 26 | #include <linux/mfd/max77693.h> |
27 | #include <linux/mfd/max77693-common.h> | ||
27 | #include <linux/mfd/max77693-private.h> | 28 | #include <linux/mfd/max77693-private.h> |
28 | #include <linux/extcon.h> | 29 | #include <linux/extcon.h> |
29 | #include <linux/regmap.h> | 30 | #include <linux/regmap.h> |
@@ -42,7 +43,7 @@ static struct max77693_reg_data default_init_data[] = { | |||
42 | { | 43 | { |
43 | /* STATUS2 - [3]ChgDetRun */ | 44 | /* STATUS2 - [3]ChgDetRun */ |
44 | .addr = MAX77693_MUIC_REG_STATUS2, | 45 | .addr = MAX77693_MUIC_REG_STATUS2, |
45 | .data = STATUS2_CHGDETRUN_MASK, | 46 | .data = MAX77693_STATUS2_CHGDETRUN_MASK, |
46 | }, { | 47 | }, { |
47 | /* INTMASK1 - Unmask [3]ADC1KM,[0]ADCM */ | 48 | /* INTMASK1 - Unmask [3]ADC1KM,[0]ADCM */ |
48 | .addr = MAX77693_MUIC_REG_INTMASK1, | 49 | .addr = MAX77693_MUIC_REG_INTMASK1, |
@@ -235,7 +236,7 @@ static int max77693_muic_set_debounce_time(struct max77693_muic_info *info, | |||
235 | */ | 236 | */ |
236 | ret = regmap_write(info->max77693->regmap_muic, | 237 | ret = regmap_write(info->max77693->regmap_muic, |
237 | MAX77693_MUIC_REG_CTRL3, | 238 | MAX77693_MUIC_REG_CTRL3, |
238 | time << CONTROL3_ADCDBSET_SHIFT); | 239 | time << MAX77693_CONTROL3_ADCDBSET_SHIFT); |
239 | if (ret) { | 240 | if (ret) { |
240 | dev_err(info->dev, "failed to set ADC debounce time\n"); | 241 | dev_err(info->dev, "failed to set ADC debounce time\n"); |
241 | return ret; | 242 | return ret; |
@@ -268,7 +269,7 @@ static int max77693_muic_set_path(struct max77693_muic_info *info, | |||
268 | if (attached) | 269 | if (attached) |
269 | ctrl1 = val; | 270 | ctrl1 = val; |
270 | else | 271 | else |
271 | ctrl1 = CONTROL1_SW_OPEN; | 272 | ctrl1 = MAX77693_CONTROL1_SW_OPEN; |
272 | 273 | ||
273 | ret = regmap_update_bits(info->max77693->regmap_muic, | 274 | ret = regmap_update_bits(info->max77693->regmap_muic, |
274 | MAX77693_MUIC_REG_CTRL1, COMP_SW_MASK, ctrl1); | 275 | MAX77693_MUIC_REG_CTRL1, COMP_SW_MASK, ctrl1); |
@@ -278,13 +279,14 @@ static int max77693_muic_set_path(struct max77693_muic_info *info, | |||
278 | } | 279 | } |
279 | 280 | ||
280 | if (attached) | 281 | if (attached) |
281 | ctrl2 |= CONTROL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */ | 282 | ctrl2 |= MAX77693_CONTROL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */ |
282 | else | 283 | else |
283 | ctrl2 |= CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */ | 284 | ctrl2 |= MAX77693_CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */ |
284 | 285 | ||
285 | ret = regmap_update_bits(info->max77693->regmap_muic, | 286 | ret = regmap_update_bits(info->max77693->regmap_muic, |
286 | MAX77693_MUIC_REG_CTRL2, | 287 | MAX77693_MUIC_REG_CTRL2, |
287 | CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK, ctrl2); | 288 | MAX77693_CONTROL2_LOWPWR_MASK | MAX77693_CONTROL2_CPEN_MASK, |
289 | ctrl2); | ||
288 | if (ret < 0) { | 290 | if (ret < 0) { |
289 | dev_err(info->dev, "failed to update MUIC register\n"); | 291 | dev_err(info->dev, "failed to update MUIC register\n"); |
290 | return ret; | 292 | return ret; |
@@ -326,8 +328,8 @@ static int max77693_muic_get_cable_type(struct max77693_muic_info *info, | |||
326 | * Read ADC value to check cable type and decide cable state | 328 | * Read ADC value to check cable type and decide cable state |
327 | * according to cable type | 329 | * according to cable type |
328 | */ | 330 | */ |
329 | adc = info->status[0] & STATUS1_ADC_MASK; | 331 | adc = info->status[0] & MAX77693_STATUS1_ADC_MASK; |
330 | adc >>= STATUS1_ADC_SHIFT; | 332 | adc >>= MAX77693_STATUS1_ADC_SHIFT; |
331 | 333 | ||
332 | /* | 334 | /* |
333 | * Check current cable state/cable type and store cable type | 335 | * Check current cable state/cable type and store cable type |
@@ -350,8 +352,8 @@ static int max77693_muic_get_cable_type(struct max77693_muic_info *info, | |||
350 | * Read ADC value to check cable type and decide cable state | 352 | * Read ADC value to check cable type and decide cable state |
351 | * according to cable type | 353 | * according to cable type |
352 | */ | 354 | */ |
353 | adc = info->status[0] & STATUS1_ADC_MASK; | 355 | adc = info->status[0] & MAX77693_STATUS1_ADC_MASK; |
354 | adc >>= STATUS1_ADC_SHIFT; | 356 | adc >>= MAX77693_STATUS1_ADC_SHIFT; |
355 | 357 | ||
356 | /* | 358 | /* |
357 | * Check current cable state/cable type and store cable type | 359 | * Check current cable state/cable type and store cable type |
@@ -366,13 +368,13 @@ static int max77693_muic_get_cable_type(struct max77693_muic_info *info, | |||
366 | } else { | 368 | } else { |
367 | *attached = true; | 369 | *attached = true; |
368 | 370 | ||
369 | adclow = info->status[0] & STATUS1_ADCLOW_MASK; | 371 | adclow = info->status[0] & MAX77693_STATUS1_ADCLOW_MASK; |
370 | adclow >>= STATUS1_ADCLOW_SHIFT; | 372 | adclow >>= MAX77693_STATUS1_ADCLOW_SHIFT; |
371 | adc1k = info->status[0] & STATUS1_ADC1K_MASK; | 373 | adc1k = info->status[0] & MAX77693_STATUS1_ADC1K_MASK; |
372 | adc1k >>= STATUS1_ADC1K_SHIFT; | 374 | adc1k >>= MAX77693_STATUS1_ADC1K_SHIFT; |
373 | 375 | ||
374 | vbvolt = info->status[1] & STATUS2_VBVOLT_MASK; | 376 | vbvolt = info->status[1] & MAX77693_STATUS2_VBVOLT_MASK; |
375 | vbvolt >>= STATUS2_VBVOLT_SHIFT; | 377 | vbvolt >>= MAX77693_STATUS2_VBVOLT_SHIFT; |
376 | 378 | ||
377 | /** | 379 | /** |
378 | * [0x1|VBVolt|ADCLow|ADC1K] | 380 | * [0x1|VBVolt|ADCLow|ADC1K] |
@@ -397,8 +399,8 @@ static int max77693_muic_get_cable_type(struct max77693_muic_info *info, | |||
397 | * Read charger type to check cable type and decide cable state | 399 | * Read charger type to check cable type and decide cable state |
398 | * according to type of charger cable. | 400 | * according to type of charger cable. |
399 | */ | 401 | */ |
400 | chg_type = info->status[1] & STATUS2_CHGTYP_MASK; | 402 | chg_type = info->status[1] & MAX77693_STATUS2_CHGTYP_MASK; |
401 | chg_type >>= STATUS2_CHGTYP_SHIFT; | 403 | chg_type >>= MAX77693_STATUS2_CHGTYP_SHIFT; |
402 | 404 | ||
403 | if (chg_type == MAX77693_CHARGER_TYPE_NONE) { | 405 | if (chg_type == MAX77693_CHARGER_TYPE_NONE) { |
404 | *attached = false; | 406 | *attached = false; |
@@ -422,10 +424,10 @@ static int max77693_muic_get_cable_type(struct max77693_muic_info *info, | |||
422 | * Read ADC value to check cable type and decide cable state | 424 | * Read ADC value to check cable type and decide cable state |
423 | * according to cable type | 425 | * according to cable type |
424 | */ | 426 | */ |
425 | adc = info->status[0] & STATUS1_ADC_MASK; | 427 | adc = info->status[0] & MAX77693_STATUS1_ADC_MASK; |
426 | adc >>= STATUS1_ADC_SHIFT; | 428 | adc >>= MAX77693_STATUS1_ADC_SHIFT; |
427 | chg_type = info->status[1] & STATUS2_CHGTYP_MASK; | 429 | chg_type = info->status[1] & MAX77693_STATUS2_CHGTYP_MASK; |
428 | chg_type >>= STATUS2_CHGTYP_SHIFT; | 430 | chg_type >>= MAX77693_STATUS2_CHGTYP_SHIFT; |
429 | 431 | ||
430 | if (adc == MAX77693_MUIC_ADC_OPEN | 432 | if (adc == MAX77693_MUIC_ADC_OPEN |
431 | && chg_type == MAX77693_CHARGER_TYPE_NONE) | 433 | && chg_type == MAX77693_CHARGER_TYPE_NONE) |
@@ -437,8 +439,8 @@ static int max77693_muic_get_cable_type(struct max77693_muic_info *info, | |||
437 | * Read vbvolt field, if vbvolt is 1, | 439 | * Read vbvolt field, if vbvolt is 1, |
438 | * this cable is used for charging. | 440 | * this cable is used for charging. |
439 | */ | 441 | */ |
440 | vbvolt = info->status[1] & STATUS2_VBVOLT_MASK; | 442 | vbvolt = info->status[1] & MAX77693_STATUS2_VBVOLT_MASK; |
441 | vbvolt >>= STATUS2_VBVOLT_SHIFT; | 443 | vbvolt >>= MAX77693_STATUS2_VBVOLT_SHIFT; |
442 | 444 | ||
443 | cable_type = vbvolt; | 445 | cable_type = vbvolt; |
444 | break; | 446 | break; |
@@ -520,7 +522,8 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info, | |||
520 | } | 522 | } |
521 | 523 | ||
522 | /* Dock-Car/Desk/Audio, PATH:AUDIO */ | 524 | /* Dock-Car/Desk/Audio, PATH:AUDIO */ |
523 | ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached); | 525 | ret = max77693_muic_set_path(info, MAX77693_CONTROL1_SW_AUDIO, |
526 | attached); | ||
524 | if (ret < 0) | 527 | if (ret < 0) |
525 | return ret; | 528 | return ret; |
526 | extcon_set_cable_state_(info->edev, dock_id, attached); | 529 | extcon_set_cable_state_(info->edev, dock_id, attached); |
@@ -585,14 +588,16 @@ static int max77693_muic_adc_ground_handler(struct max77693_muic_info *info) | |||
585 | case MAX77693_MUIC_GND_USB_HOST: | 588 | case MAX77693_MUIC_GND_USB_HOST: |
586 | case MAX77693_MUIC_GND_USB_HOST_VB: | 589 | case MAX77693_MUIC_GND_USB_HOST_VB: |
587 | /* USB_HOST, PATH: AP_USB */ | 590 | /* USB_HOST, PATH: AP_USB */ |
588 | ret = max77693_muic_set_path(info, CONTROL1_SW_USB, attached); | 591 | ret = max77693_muic_set_path(info, MAX77693_CONTROL1_SW_USB, |
592 | attached); | ||
589 | if (ret < 0) | 593 | if (ret < 0) |
590 | return ret; | 594 | return ret; |
591 | extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached); | 595 | extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached); |
592 | break; | 596 | break; |
593 | case MAX77693_MUIC_GND_AV_CABLE_LOAD: | 597 | case MAX77693_MUIC_GND_AV_CABLE_LOAD: |
594 | /* Audio Video Cable with load, PATH:AUDIO */ | 598 | /* Audio Video Cable with load, PATH:AUDIO */ |
595 | ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached); | 599 | ret = max77693_muic_set_path(info, MAX77693_CONTROL1_SW_AUDIO, |
600 | attached); | ||
596 | if (ret < 0) | 601 | if (ret < 0) |
597 | return ret; | 602 | return ret; |
598 | extcon_set_cable_state_(info->edev, EXTCON_USB, attached); | 603 | extcon_set_cable_state_(info->edev, EXTCON_USB, attached); |
@@ -615,7 +620,7 @@ static int max77693_muic_jig_handler(struct max77693_muic_info *info, | |||
615 | int cable_type, bool attached) | 620 | int cable_type, bool attached) |
616 | { | 621 | { |
617 | int ret = 0; | 622 | int ret = 0; |
618 | u8 path = CONTROL1_SW_OPEN; | 623 | u8 path = MAX77693_CONTROL1_SW_OPEN; |
619 | 624 | ||
620 | dev_info(info->dev, | 625 | dev_info(info->dev, |
621 | "external connector is %s (adc:0x%02x)\n", | 626 | "external connector is %s (adc:0x%02x)\n", |
@@ -625,12 +630,12 @@ static int max77693_muic_jig_handler(struct max77693_muic_info *info, | |||
625 | case MAX77693_MUIC_ADC_FACTORY_MODE_USB_OFF: /* ADC_JIG_USB_OFF */ | 630 | case MAX77693_MUIC_ADC_FACTORY_MODE_USB_OFF: /* ADC_JIG_USB_OFF */ |
626 | case MAX77693_MUIC_ADC_FACTORY_MODE_USB_ON: /* ADC_JIG_USB_ON */ | 631 | case MAX77693_MUIC_ADC_FACTORY_MODE_USB_ON: /* ADC_JIG_USB_ON */ |
627 | /* PATH:AP_USB */ | 632 | /* PATH:AP_USB */ |
628 | path = CONTROL1_SW_USB; | 633 | path = MAX77693_CONTROL1_SW_USB; |
629 | break; | 634 | break; |
630 | case MAX77693_MUIC_ADC_FACTORY_MODE_UART_OFF: /* ADC_JIG_UART_OFF */ | 635 | case MAX77693_MUIC_ADC_FACTORY_MODE_UART_OFF: /* ADC_JIG_UART_OFF */ |
631 | case MAX77693_MUIC_ADC_FACTORY_MODE_UART_ON: /* ADC_JIG_UART_ON */ | 636 | case MAX77693_MUIC_ADC_FACTORY_MODE_UART_ON: /* ADC_JIG_UART_ON */ |
632 | /* PATH:AP_UART */ | 637 | /* PATH:AP_UART */ |
633 | path = CONTROL1_SW_UART; | 638 | path = MAX77693_CONTROL1_SW_UART; |
634 | break; | 639 | break; |
635 | default: | 640 | default: |
636 | dev_err(info->dev, "failed to detect %s jig cable\n", | 641 | dev_err(info->dev, "failed to detect %s jig cable\n", |
@@ -1077,7 +1082,7 @@ static int max77693_muic_probe(struct platform_device *pdev) | |||
1077 | dev_dbg(&pdev->dev, "allocate register map\n"); | 1082 | dev_dbg(&pdev->dev, "allocate register map\n"); |
1078 | } else { | 1083 | } else { |
1079 | info->max77693->regmap_muic = devm_regmap_init_i2c( | 1084 | info->max77693->regmap_muic = devm_regmap_init_i2c( |
1080 | info->max77693->muic, | 1085 | info->max77693->i2c_muic, |
1081 | &max77693_muic_regmap_config); | 1086 | &max77693_muic_regmap_config); |
1082 | if (IS_ERR(info->max77693->regmap_muic)) { | 1087 | if (IS_ERR(info->max77693->regmap_muic)) { |
1083 | ret = PTR_ERR(info->max77693->regmap_muic); | 1088 | ret = PTR_ERR(info->max77693->regmap_muic); |
@@ -1164,28 +1169,9 @@ static int max77693_muic_probe(struct platform_device *pdev) | |||
1164 | } | 1169 | } |
1165 | 1170 | ||
1166 | for (i = 0; i < num_init_data; i++) { | 1171 | for (i = 0; i < num_init_data; i++) { |
1167 | enum max77693_irq_source irq_src | ||
1168 | = MAX77693_IRQ_GROUP_NR; | ||
1169 | |||
1170 | regmap_write(info->max77693->regmap_muic, | 1172 | regmap_write(info->max77693->regmap_muic, |
1171 | init_data[i].addr, | 1173 | init_data[i].addr, |
1172 | init_data[i].data); | 1174 | init_data[i].data); |
1173 | |||
1174 | switch (init_data[i].addr) { | ||
1175 | case MAX77693_MUIC_REG_INTMASK1: | ||
1176 | irq_src = MUIC_INT1; | ||
1177 | break; | ||
1178 | case MAX77693_MUIC_REG_INTMASK2: | ||
1179 | irq_src = MUIC_INT2; | ||
1180 | break; | ||
1181 | case MAX77693_MUIC_REG_INTMASK3: | ||
1182 | irq_src = MUIC_INT3; | ||
1183 | break; | ||
1184 | } | ||
1185 | |||
1186 | if (irq_src < MAX77693_IRQ_GROUP_NR) | ||
1187 | info->max77693->irq_masks_cur[irq_src] | ||
1188 | = init_data[i].data; | ||
1189 | } | 1175 | } |
1190 | 1176 | ||
1191 | if (pdata && pdata->muic_data) { | 1177 | if (pdata && pdata->muic_data) { |
@@ -1199,12 +1185,12 @@ static int max77693_muic_probe(struct platform_device *pdev) | |||
1199 | if (muic_pdata->path_uart) | 1185 | if (muic_pdata->path_uart) |
1200 | info->path_uart = muic_pdata->path_uart; | 1186 | info->path_uart = muic_pdata->path_uart; |
1201 | else | 1187 | else |
1202 | info->path_uart = CONTROL1_SW_UART; | 1188 | info->path_uart = MAX77693_CONTROL1_SW_UART; |
1203 | 1189 | ||
1204 | if (muic_pdata->path_usb) | 1190 | if (muic_pdata->path_usb) |
1205 | info->path_usb = muic_pdata->path_usb; | 1191 | info->path_usb = muic_pdata->path_usb; |
1206 | else | 1192 | else |
1207 | info->path_usb = CONTROL1_SW_USB; | 1193 | info->path_usb = MAX77693_CONTROL1_SW_USB; |
1208 | 1194 | ||
1209 | /* | 1195 | /* |
1210 | * Default delay time for detecting cable state | 1196 | * Default delay time for detecting cable state |
@@ -1216,8 +1202,8 @@ static int max77693_muic_probe(struct platform_device *pdev) | |||
1216 | else | 1202 | else |
1217 | delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT); | 1203 | delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT); |
1218 | } else { | 1204 | } else { |
1219 | info->path_usb = CONTROL1_SW_USB; | 1205 | info->path_usb = MAX77693_CONTROL1_SW_USB; |
1220 | info->path_uart = CONTROL1_SW_UART; | 1206 | info->path_uart = MAX77693_CONTROL1_SW_UART; |
1221 | delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT); | 1207 | delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT); |
1222 | } | 1208 | } |
1223 | 1209 | ||
diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c index cc5e7bca38c8..fdd928542c19 100644 --- a/drivers/extcon/extcon-max77843.c +++ b/drivers/extcon/extcon-max77843.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/i2c.h> | 15 | #include <linux/i2c.h> |
16 | #include <linux/interrupt.h> | 16 | #include <linux/interrupt.h> |
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/mfd/max77693-common.h> | ||
18 | #include <linux/mfd/max77843-private.h> | 19 | #include <linux/mfd/max77843-private.h> |
19 | #include <linux/module.h> | 20 | #include <linux/module.h> |
20 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
@@ -32,7 +33,7 @@ enum max77843_muic_status { | |||
32 | 33 | ||
33 | struct max77843_muic_info { | 34 | struct max77843_muic_info { |
34 | struct device *dev; | 35 | struct device *dev; |
35 | struct max77843 *max77843; | 36 | struct max77693_dev *max77843; |
36 | struct extcon_dev *edev; | 37 | struct extcon_dev *edev; |
37 | 38 | ||
38 | struct mutex mutex; | 39 | struct mutex mutex; |
@@ -198,18 +199,18 @@ static const struct regmap_irq_chip max77843_muic_irq_chip = { | |||
198 | static int max77843_muic_set_path(struct max77843_muic_info *info, | 199 | static int max77843_muic_set_path(struct max77843_muic_info *info, |
199 | u8 val, bool attached) | 200 | u8 val, bool attached) |
200 | { | 201 | { |
201 | struct max77843 *max77843 = info->max77843; | 202 | struct max77693_dev *max77843 = info->max77843; |
202 | int ret = 0; | 203 | int ret = 0; |
203 | unsigned int ctrl1, ctrl2; | 204 | unsigned int ctrl1, ctrl2; |
204 | 205 | ||
205 | if (attached) | 206 | if (attached) |
206 | ctrl1 = val; | 207 | ctrl1 = val; |
207 | else | 208 | else |
208 | ctrl1 = CONTROL1_SW_OPEN; | 209 | ctrl1 = MAX77843_MUIC_CONTROL1_SW_OPEN; |
209 | 210 | ||
210 | ret = regmap_update_bits(max77843->regmap_muic, | 211 | ret = regmap_update_bits(max77843->regmap_muic, |
211 | MAX77843_MUIC_REG_CONTROL1, | 212 | MAX77843_MUIC_REG_CONTROL1, |
212 | CONTROL1_COM_SW, ctrl1); | 213 | MAX77843_MUIC_CONTROL1_COM_SW, ctrl1); |
213 | if (ret < 0) { | 214 | if (ret < 0) { |
214 | dev_err(info->dev, "Cannot switch MUIC port\n"); | 215 | dev_err(info->dev, "Cannot switch MUIC port\n"); |
215 | return ret; | 216 | return ret; |
@@ -243,7 +244,7 @@ static int max77843_muic_get_cable_type(struct max77843_muic_info *info, | |||
243 | 244 | ||
244 | adc = info->status[MAX77843_MUIC_STATUS1] & | 245 | adc = info->status[MAX77843_MUIC_STATUS1] & |
245 | MAX77843_MUIC_STATUS1_ADC_MASK; | 246 | MAX77843_MUIC_STATUS1_ADC_MASK; |
246 | adc >>= STATUS1_ADC_SHIFT; | 247 | adc >>= MAX77843_MUIC_STATUS1_ADC_SHIFT; |
247 | 248 | ||
248 | switch (group) { | 249 | switch (group) { |
249 | case MAX77843_CABLE_GROUP_ADC: | 250 | case MAX77843_CABLE_GROUP_ADC: |
@@ -309,7 +310,7 @@ static int max77843_muic_get_cable_type(struct max77843_muic_info *info, | |||
309 | /* Get VBVolt register bit */ | 310 | /* Get VBVolt register bit */ |
310 | gnd_type |= (info->status[MAX77843_MUIC_STATUS2] & | 311 | gnd_type |= (info->status[MAX77843_MUIC_STATUS2] & |
311 | MAX77843_MUIC_STATUS2_VBVOLT_MASK); | 312 | MAX77843_MUIC_STATUS2_VBVOLT_MASK); |
312 | gnd_type >>= STATUS2_VBVOLT_SHIFT; | 313 | gnd_type >>= MAX77843_MUIC_STATUS2_VBVOLT_SHIFT; |
313 | 314 | ||
314 | /* Offset of GND cable */ | 315 | /* Offset of GND cable */ |
315 | gnd_type |= MAX77843_MUIC_GND_USB_HOST; | 316 | gnd_type |= MAX77843_MUIC_GND_USB_HOST; |
@@ -338,7 +339,9 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info) | |||
338 | switch (gnd_cable_type) { | 339 | switch (gnd_cable_type) { |
339 | case MAX77843_MUIC_GND_USB_HOST: | 340 | case MAX77843_MUIC_GND_USB_HOST: |
340 | case MAX77843_MUIC_GND_USB_HOST_VB: | 341 | case MAX77843_MUIC_GND_USB_HOST_VB: |
341 | ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); | 342 | ret = max77843_muic_set_path(info, |
343 | MAX77843_MUIC_CONTROL1_SW_USB, | ||
344 | attached); | ||
342 | if (ret < 0) | 345 | if (ret < 0) |
343 | return ret; | 346 | return ret; |
344 | 347 | ||
@@ -346,7 +349,9 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info) | |||
346 | break; | 349 | break; |
347 | case MAX77843_MUIC_GND_MHL_VB: | 350 | case MAX77843_MUIC_GND_MHL_VB: |
348 | case MAX77843_MUIC_GND_MHL: | 351 | case MAX77843_MUIC_GND_MHL: |
349 | ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); | 352 | ret = max77843_muic_set_path(info, |
353 | MAX77843_MUIC_CONTROL1_SW_OPEN, | ||
354 | attached); | ||
350 | if (ret < 0) | 355 | if (ret < 0) |
351 | return ret; | 356 | return ret; |
352 | 357 | ||
@@ -365,7 +370,7 @@ static int max77843_muic_jig_handler(struct max77843_muic_info *info, | |||
365 | int cable_type, bool attached) | 370 | int cable_type, bool attached) |
366 | { | 371 | { |
367 | int ret; | 372 | int ret; |
368 | u8 path = CONTROL1_SW_OPEN; | 373 | u8 path = MAX77843_MUIC_CONTROL1_SW_OPEN; |
369 | 374 | ||
370 | dev_dbg(info->dev, "external connector is %s (adc:0x%02x)\n", | 375 | dev_dbg(info->dev, "external connector is %s (adc:0x%02x)\n", |
371 | attached ? "attached" : "detached", cable_type); | 376 | attached ? "attached" : "detached", cable_type); |
@@ -373,10 +378,10 @@ static int max77843_muic_jig_handler(struct max77843_muic_info *info, | |||
373 | switch (cable_type) { | 378 | switch (cable_type) { |
374 | case MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF: | 379 | case MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF: |
375 | case MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON: | 380 | case MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON: |
376 | path = CONTROL1_SW_USB; | 381 | path = MAX77843_MUIC_CONTROL1_SW_USB; |
377 | break; | 382 | break; |
378 | case MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF: | 383 | case MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF: |
379 | path = CONTROL1_SW_UART; | 384 | path = MAX77843_MUIC_CONTROL1_SW_UART; |
380 | break; | 385 | break; |
381 | default: | 386 | default: |
382 | return -EINVAL; | 387 | return -EINVAL; |
@@ -474,14 +479,18 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info) | |||
474 | 479 | ||
475 | switch (chg_type) { | 480 | switch (chg_type) { |
476 | case MAX77843_MUIC_CHG_USB: | 481 | case MAX77843_MUIC_CHG_USB: |
477 | ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); | 482 | ret = max77843_muic_set_path(info, |
483 | MAX77843_MUIC_CONTROL1_SW_USB, | ||
484 | attached); | ||
478 | if (ret < 0) | 485 | if (ret < 0) |
479 | return ret; | 486 | return ret; |
480 | 487 | ||
481 | extcon_set_cable_state_(info->edev, EXTCON_USB, attached); | 488 | extcon_set_cable_state_(info->edev, EXTCON_USB, attached); |
482 | break; | 489 | break; |
483 | case MAX77843_MUIC_CHG_DOWNSTREAM: | 490 | case MAX77843_MUIC_CHG_DOWNSTREAM: |
484 | ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); | 491 | ret = max77843_muic_set_path(info, |
492 | MAX77843_MUIC_CONTROL1_SW_OPEN, | ||
493 | attached); | ||
485 | if (ret < 0) | 494 | if (ret < 0) |
486 | return ret; | 495 | return ret; |
487 | 496 | ||
@@ -489,14 +498,18 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info) | |||
489 | attached); | 498 | attached); |
490 | break; | 499 | break; |
491 | case MAX77843_MUIC_CHG_DEDICATED: | 500 | case MAX77843_MUIC_CHG_DEDICATED: |
492 | ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); | 501 | ret = max77843_muic_set_path(info, |
502 | MAX77843_MUIC_CONTROL1_SW_OPEN, | ||
503 | attached); | ||
493 | if (ret < 0) | 504 | if (ret < 0) |
494 | return ret; | 505 | return ret; |
495 | 506 | ||
496 | extcon_set_cable_state_(info->edev, EXTCON_TA, attached); | 507 | extcon_set_cable_state_(info->edev, EXTCON_TA, attached); |
497 | break; | 508 | break; |
498 | case MAX77843_MUIC_CHG_SPECIAL_500MA: | 509 | case MAX77843_MUIC_CHG_SPECIAL_500MA: |
499 | ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); | 510 | ret = max77843_muic_set_path(info, |
511 | MAX77843_MUIC_CONTROL1_SW_OPEN, | ||
512 | attached); | ||
500 | if (ret < 0) | 513 | if (ret < 0) |
501 | return ret; | 514 | return ret; |
502 | 515 | ||
@@ -504,7 +517,9 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info) | |||
504 | attached); | 517 | attached); |
505 | break; | 518 | break; |
506 | case MAX77843_MUIC_CHG_SPECIAL_1A: | 519 | case MAX77843_MUIC_CHG_SPECIAL_1A: |
507 | ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); | 520 | ret = max77843_muic_set_path(info, |
521 | MAX77843_MUIC_CONTROL1_SW_OPEN, | ||
522 | attached); | ||
508 | if (ret < 0) | 523 | if (ret < 0) |
509 | return ret; | 524 | return ret; |
510 | 525 | ||
@@ -528,7 +543,8 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info) | |||
528 | "failed to detect %s accessory (chg_type:0x%x)\n", | 543 | "failed to detect %s accessory (chg_type:0x%x)\n", |
529 | attached ? "attached" : "detached", chg_type); | 544 | attached ? "attached" : "detached", chg_type); |
530 | 545 | ||
531 | max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); | 546 | max77843_muic_set_path(info, MAX77843_MUIC_CONTROL1_SW_OPEN, |
547 | attached); | ||
532 | return -EINVAL; | 548 | return -EINVAL; |
533 | } | 549 | } |
534 | 550 | ||
@@ -539,7 +555,7 @@ static void max77843_muic_irq_work(struct work_struct *work) | |||
539 | { | 555 | { |
540 | struct max77843_muic_info *info = container_of(work, | 556 | struct max77843_muic_info *info = container_of(work, |
541 | struct max77843_muic_info, irq_work); | 557 | struct max77843_muic_info, irq_work); |
542 | struct max77843 *max77843 = info->max77843; | 558 | struct max77693_dev *max77843 = info->max77843; |
543 | int ret = 0; | 559 | int ret = 0; |
544 | 560 | ||
545 | mutex_lock(&info->mutex); | 561 | mutex_lock(&info->mutex); |
@@ -615,7 +631,7 @@ static void max77843_muic_detect_cable_wq(struct work_struct *work) | |||
615 | { | 631 | { |
616 | struct max77843_muic_info *info = container_of(to_delayed_work(work), | 632 | struct max77843_muic_info *info = container_of(to_delayed_work(work), |
617 | struct max77843_muic_info, wq_detcable); | 633 | struct max77843_muic_info, wq_detcable); |
618 | struct max77843 *max77843 = info->max77843; | 634 | struct max77693_dev *max77843 = info->max77843; |
619 | int chg_type, adc, ret; | 635 | int chg_type, adc, ret; |
620 | bool attached; | 636 | bool attached; |
621 | 637 | ||
@@ -656,7 +672,7 @@ err_cable_wq: | |||
656 | static int max77843_muic_set_debounce_time(struct max77843_muic_info *info, | 672 | static int max77843_muic_set_debounce_time(struct max77843_muic_info *info, |
657 | enum max77843_muic_adc_debounce_time time) | 673 | enum max77843_muic_adc_debounce_time time) |
658 | { | 674 | { |
659 | struct max77843 *max77843 = info->max77843; | 675 | struct max77693_dev *max77843 = info->max77843; |
660 | int ret; | 676 | int ret; |
661 | 677 | ||
662 | switch (time) { | 678 | switch (time) { |
@@ -667,7 +683,7 @@ static int max77843_muic_set_debounce_time(struct max77843_muic_info *info, | |||
667 | ret = regmap_update_bits(max77843->regmap_muic, | 683 | ret = regmap_update_bits(max77843->regmap_muic, |
668 | MAX77843_MUIC_REG_CONTROL4, | 684 | MAX77843_MUIC_REG_CONTROL4, |
669 | MAX77843_MUIC_CONTROL4_ADCDBSET_MASK, | 685 | MAX77843_MUIC_CONTROL4_ADCDBSET_MASK, |
670 | time << CONTROL4_ADCDBSET_SHIFT); | 686 | time << MAX77843_MUIC_CONTROL4_ADCDBSET_SHIFT); |
671 | if (ret < 0) { | 687 | if (ret < 0) { |
672 | dev_err(info->dev, "Cannot write MUIC regmap\n"); | 688 | dev_err(info->dev, "Cannot write MUIC regmap\n"); |
673 | return ret; | 689 | return ret; |
@@ -681,7 +697,7 @@ static int max77843_muic_set_debounce_time(struct max77843_muic_info *info, | |||
681 | return 0; | 697 | return 0; |
682 | } | 698 | } |
683 | 699 | ||
684 | static int max77843_init_muic_regmap(struct max77843 *max77843) | 700 | static int max77843_init_muic_regmap(struct max77693_dev *max77843) |
685 | { | 701 | { |
686 | int ret; | 702 | int ret; |
687 | 703 | ||
@@ -720,7 +736,7 @@ err_muic_i2c: | |||
720 | 736 | ||
721 | static int max77843_muic_probe(struct platform_device *pdev) | 737 | static int max77843_muic_probe(struct platform_device *pdev) |
722 | { | 738 | { |
723 | struct max77843 *max77843 = dev_get_drvdata(pdev->dev.parent); | 739 | struct max77693_dev *max77843 = dev_get_drvdata(pdev->dev.parent); |
724 | struct max77843_muic_info *info; | 740 | struct max77843_muic_info *info; |
725 | unsigned int id; | 741 | unsigned int id; |
726 | int i, ret; | 742 | int i, ret; |
@@ -768,7 +784,7 @@ static int max77843_muic_probe(struct platform_device *pdev) | |||
768 | max77843_muic_set_debounce_time(info, MAX77843_DEBOUNCE_TIME_25MS); | 784 | max77843_muic_set_debounce_time(info, MAX77843_DEBOUNCE_TIME_25MS); |
769 | 785 | ||
770 | /* Set initial path for UART */ | 786 | /* Set initial path for UART */ |
771 | max77843_muic_set_path(info, CONTROL1_SW_UART, true); | 787 | max77843_muic_set_path(info, MAX77843_MUIC_CONTROL1_SW_UART, true); |
772 | 788 | ||
773 | /* Check revision number of MUIC device */ | 789 | /* Check revision number of MUIC device */ |
774 | ret = regmap_read(max77843->regmap_muic, MAX77843_MUIC_REG_ID, &id); | 790 | ret = regmap_read(max77843->regmap_muic, MAX77843_MUIC_REG_ID, &id); |
@@ -830,7 +846,7 @@ err_muic_irq: | |||
830 | static int max77843_muic_remove(struct platform_device *pdev) | 846 | static int max77843_muic_remove(struct platform_device *pdev) |
831 | { | 847 | { |
832 | struct max77843_muic_info *info = platform_get_drvdata(pdev); | 848 | struct max77843_muic_info *info = platform_get_drvdata(pdev); |
833 | struct max77843 *max77843 = info->max77843; | 849 | struct max77693_dev *max77843 = info->max77843; |
834 | 850 | ||
835 | cancel_work_sync(&info->irq_work); | 851 | cancel_work_sync(&info->irq_work); |
836 | regmap_del_irq_chip(max77843->irq, max77843->irq_data_muic); | 852 | regmap_del_irq_chip(max77843->irq, max77843->irq_data_muic); |
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index d4f0a817e858..c41dec819cdf 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig | |||
@@ -167,28 +167,16 @@ config INPUT_M68K_BEEP | |||
167 | depends on M68K | 167 | depends on M68K |
168 | 168 | ||
169 | config INPUT_MAX77693_HAPTIC | 169 | config INPUT_MAX77693_HAPTIC |
170 | tristate "MAXIM MAX77693 haptic controller support" | 170 | tristate "MAXIM MAX77693/MAX77843 haptic controller support" |
171 | depends on MFD_MAX77693 && PWM | 171 | depends on (MFD_MAX77693 || MFD_MAX77843) && PWM |
172 | select INPUT_FF_MEMLESS | 172 | select INPUT_FF_MEMLESS |
173 | help | 173 | help |
174 | This option enables support for the haptic controller on | 174 | This option enables support for the haptic controller on |
175 | MAXIM MAX77693 chip. | 175 | MAXIM MAX77693 and MAX77843 chips. |
176 | 176 | ||
177 | To compile this driver as module, choose M here: the | 177 | To compile this driver as module, choose M here: the |
178 | module will be called max77693-haptic. | 178 | module will be called max77693-haptic. |
179 | 179 | ||
180 | config INPUT_MAX77843_HAPTIC | ||
181 | tristate "MAXIM MAX77843 haptic controller support" | ||
182 | depends on MFD_MAX77843 && REGULATOR | ||
183 | select INPUT_FF_MEMLESS | ||
184 | help | ||
185 | This option enables support for the haptic controller on | ||
186 | MAXIM MAX77843 chip. The driver supports ff-memless interface | ||
187 | from input framework. | ||
188 | |||
189 | To compile this driver as module, choose M here: the | ||
190 | module will be called max77843-haptic. | ||
191 | |||
192 | config INPUT_MAX8925_ONKEY | 180 | config INPUT_MAX8925_ONKEY |
193 | tristate "MAX8925 ONKEY support" | 181 | tristate "MAX8925 ONKEY support" |
194 | depends on MFD_MAX8925 | 182 | depends on MFD_MAX8925 |
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 53df07dcc23c..0357a088c6a9 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile | |||
@@ -41,7 +41,6 @@ obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o | |||
41 | obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o | 41 | obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o |
42 | obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o | 42 | obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o |
43 | obj-$(CONFIG_INPUT_MAX77693_HAPTIC) += max77693-haptic.o | 43 | obj-$(CONFIG_INPUT_MAX77693_HAPTIC) += max77693-haptic.o |
44 | obj-$(CONFIG_INPUT_MAX77843_HAPTIC) += max77843-haptic.o | ||
45 | obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o | 44 | obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o |
46 | obj-$(CONFIG_INPUT_MAX8997_HAPTIC) += max8997_haptic.o | 45 | obj-$(CONFIG_INPUT_MAX8997_HAPTIC) += max8997_haptic.o |
47 | obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) += mc13783-pwrbutton.o | 46 | obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) += mc13783-pwrbutton.o |
diff --git a/drivers/input/misc/max77693-haptic.c b/drivers/input/misc/max77693-haptic.c index 39e930c10ebb..6d96bff32a0e 100644 --- a/drivers/input/misc/max77693-haptic.c +++ b/drivers/input/misc/max77693-haptic.c | |||
@@ -1,8 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * MAXIM MAX77693 Haptic device driver | 2 | * MAXIM MAX77693/MAX77843 Haptic device driver |
3 | * | 3 | * |
4 | * Copyright (C) 2014 Samsung Electronics | 4 | * Copyright (C) 2014,2015 Samsung Electronics |
5 | * Jaewon Kim <jaewon02.kim@samsung.com> | 5 | * Jaewon Kim <jaewon02.kim@samsung.com> |
6 | * Krzysztof Kozlowski <k.kozlowski@samsung.com> | ||
6 | * | 7 | * |
7 | * This program is not provided / owned by Maxim Integrated Products. | 8 | * This program is not provided / owned by Maxim Integrated Products. |
8 | * | 9 | * |
@@ -24,7 +25,9 @@ | |||
24 | #include <linux/workqueue.h> | 25 | #include <linux/workqueue.h> |
25 | #include <linux/regulator/consumer.h> | 26 | #include <linux/regulator/consumer.h> |
26 | #include <linux/mfd/max77693.h> | 27 | #include <linux/mfd/max77693.h> |
28 | #include <linux/mfd/max77693-common.h> | ||
27 | #include <linux/mfd/max77693-private.h> | 29 | #include <linux/mfd/max77693-private.h> |
30 | #include <linux/mfd/max77843-private.h> | ||
28 | 31 | ||
29 | #define MAX_MAGNITUDE_SHIFT 16 | 32 | #define MAX_MAGNITUDE_SHIFT 16 |
30 | 33 | ||
@@ -46,6 +49,8 @@ enum max77693_haptic_pwm_divisor { | |||
46 | }; | 49 | }; |
47 | 50 | ||
48 | struct max77693_haptic { | 51 | struct max77693_haptic { |
52 | enum max77693_types dev_type; | ||
53 | |||
49 | struct regmap *regmap_pmic; | 54 | struct regmap *regmap_pmic; |
50 | struct regmap *regmap_haptic; | 55 | struct regmap *regmap_haptic; |
51 | struct device *dev; | 56 | struct device *dev; |
@@ -59,7 +64,6 @@ struct max77693_haptic { | |||
59 | unsigned int pwm_duty; | 64 | unsigned int pwm_duty; |
60 | enum max77693_haptic_motor_type type; | 65 | enum max77693_haptic_motor_type type; |
61 | enum max77693_haptic_pulse_mode mode; | 66 | enum max77693_haptic_pulse_mode mode; |
62 | enum max77693_haptic_pwm_divisor pwm_divisor; | ||
63 | 67 | ||
64 | struct work_struct work; | 68 | struct work_struct work; |
65 | }; | 69 | }; |
@@ -78,19 +82,52 @@ static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic) | |||
78 | return 0; | 82 | return 0; |
79 | } | 83 | } |
80 | 84 | ||
85 | static int max77843_haptic_bias(struct max77693_haptic *haptic, bool on) | ||
86 | { | ||
87 | int error; | ||
88 | |||
89 | if (haptic->dev_type != TYPE_MAX77843) | ||
90 | return 0; | ||
91 | |||
92 | error = regmap_update_bits(haptic->regmap_haptic, | ||
93 | MAX77843_SYS_REG_MAINCTRL1, | ||
94 | MAX77843_MAINCTRL1_BIASEN_MASK, | ||
95 | on << MAINCTRL1_BIASEN_SHIFT); | ||
96 | if (error) { | ||
97 | dev_err(haptic->dev, "failed to %s bias: %d\n", | ||
98 | on ? "enable" : "disable", error); | ||
99 | return error; | ||
100 | } | ||
101 | |||
102 | return 0; | ||
103 | } | ||
104 | |||
81 | static int max77693_haptic_configure(struct max77693_haptic *haptic, | 105 | static int max77693_haptic_configure(struct max77693_haptic *haptic, |
82 | bool enable) | 106 | bool enable) |
83 | { | 107 | { |
84 | unsigned int value; | 108 | unsigned int value, config_reg; |
85 | int error; | 109 | int error; |
86 | 110 | ||
87 | value = ((haptic->type << MAX77693_CONFIG2_MODE) | | 111 | switch (haptic->dev_type) { |
88 | (enable << MAX77693_CONFIG2_MEN) | | 112 | case TYPE_MAX77693: |
89 | (haptic->mode << MAX77693_CONFIG2_HTYP) | | 113 | value = ((haptic->type << MAX77693_CONFIG2_MODE) | |
90 | (haptic->pwm_divisor)); | 114 | (enable << MAX77693_CONFIG2_MEN) | |
115 | (haptic->mode << MAX77693_CONFIG2_HTYP) | | ||
116 | MAX77693_HAPTIC_PWM_DIVISOR_128); | ||
117 | config_reg = MAX77693_HAPTIC_REG_CONFIG2; | ||
118 | break; | ||
119 | case TYPE_MAX77843: | ||
120 | value = (haptic->type << MCONFIG_MODE_SHIFT) | | ||
121 | (enable << MCONFIG_MEN_SHIFT) | | ||
122 | MAX77693_HAPTIC_PWM_DIVISOR_128; | ||
123 | config_reg = MAX77843_HAP_REG_MCONFIG; | ||
124 | break; | ||
125 | default: | ||
126 | return -EINVAL; | ||
127 | } | ||
91 | 128 | ||
92 | error = regmap_write(haptic->regmap_haptic, | 129 | error = regmap_write(haptic->regmap_haptic, |
93 | MAX77693_HAPTIC_REG_CONFIG2, value); | 130 | config_reg, value); |
94 | if (error) { | 131 | if (error) { |
95 | dev_err(haptic->dev, | 132 | dev_err(haptic->dev, |
96 | "failed to update haptic config: %d\n", error); | 133 | "failed to update haptic config: %d\n", error); |
@@ -104,6 +141,9 @@ static int max77693_haptic_lowsys(struct max77693_haptic *haptic, bool enable) | |||
104 | { | 141 | { |
105 | int error; | 142 | int error; |
106 | 143 | ||
144 | if (haptic->dev_type != TYPE_MAX77693) | ||
145 | return 0; | ||
146 | |||
107 | error = regmap_update_bits(haptic->regmap_pmic, | 147 | error = regmap_update_bits(haptic->regmap_pmic, |
108 | MAX77693_PMIC_REG_LSCNFG, | 148 | MAX77693_PMIC_REG_LSCNFG, |
109 | MAX77693_PMIC_LOW_SYS_MASK, | 149 | MAX77693_PMIC_LOW_SYS_MASK, |
@@ -219,6 +259,10 @@ static int max77693_haptic_open(struct input_dev *dev) | |||
219 | struct max77693_haptic *haptic = input_get_drvdata(dev); | 259 | struct max77693_haptic *haptic = input_get_drvdata(dev); |
220 | int error; | 260 | int error; |
221 | 261 | ||
262 | error = max77843_haptic_bias(haptic, true); | ||
263 | if (error) | ||
264 | return error; | ||
265 | |||
222 | error = regulator_enable(haptic->motor_reg); | 266 | error = regulator_enable(haptic->motor_reg); |
223 | if (error) { | 267 | if (error) { |
224 | dev_err(haptic->dev, | 268 | dev_err(haptic->dev, |
@@ -241,6 +285,8 @@ static void max77693_haptic_close(struct input_dev *dev) | |||
241 | if (error) | 285 | if (error) |
242 | dev_err(haptic->dev, | 286 | dev_err(haptic->dev, |
243 | "failed to disable regulator: %d\n", error); | 287 | "failed to disable regulator: %d\n", error); |
288 | |||
289 | max77843_haptic_bias(haptic, false); | ||
244 | } | 290 | } |
245 | 291 | ||
246 | static int max77693_haptic_probe(struct platform_device *pdev) | 292 | static int max77693_haptic_probe(struct platform_device *pdev) |
@@ -254,13 +300,26 @@ static int max77693_haptic_probe(struct platform_device *pdev) | |||
254 | return -ENOMEM; | 300 | return -ENOMEM; |
255 | 301 | ||
256 | haptic->regmap_pmic = max77693->regmap; | 302 | haptic->regmap_pmic = max77693->regmap; |
257 | haptic->regmap_haptic = max77693->regmap_haptic; | ||
258 | haptic->dev = &pdev->dev; | 303 | haptic->dev = &pdev->dev; |
259 | haptic->type = MAX77693_HAPTIC_LRA; | 304 | haptic->type = MAX77693_HAPTIC_LRA; |
260 | haptic->mode = MAX77693_HAPTIC_EXTERNAL_MODE; | 305 | haptic->mode = MAX77693_HAPTIC_EXTERNAL_MODE; |
261 | haptic->pwm_divisor = MAX77693_HAPTIC_PWM_DIVISOR_128; | ||
262 | haptic->suspend_state = false; | 306 | haptic->suspend_state = false; |
263 | 307 | ||
308 | /* Variant-specific init */ | ||
309 | haptic->dev_type = platform_get_device_id(pdev)->driver_data; | ||
310 | switch (haptic->dev_type) { | ||
311 | case TYPE_MAX77693: | ||
312 | haptic->regmap_haptic = max77693->regmap_haptic; | ||
313 | break; | ||
314 | case TYPE_MAX77843: | ||
315 | haptic->regmap_haptic = max77693->regmap; | ||
316 | break; | ||
317 | default: | ||
318 | dev_err(&pdev->dev, "unsupported device type: %u\n", | ||
319 | haptic->dev_type); | ||
320 | return -EINVAL; | ||
321 | } | ||
322 | |||
264 | INIT_WORK(&haptic->work, max77693_haptic_play_work); | 323 | INIT_WORK(&haptic->work, max77693_haptic_play_work); |
265 | 324 | ||
266 | /* Get pwm and regulatot for haptic device */ | 325 | /* Get pwm and regulatot for haptic device */ |
@@ -338,16 +397,25 @@ static int __maybe_unused max77693_haptic_resume(struct device *dev) | |||
338 | static SIMPLE_DEV_PM_OPS(max77693_haptic_pm_ops, | 397 | static SIMPLE_DEV_PM_OPS(max77693_haptic_pm_ops, |
339 | max77693_haptic_suspend, max77693_haptic_resume); | 398 | max77693_haptic_suspend, max77693_haptic_resume); |
340 | 399 | ||
400 | static const struct platform_device_id max77693_haptic_id[] = { | ||
401 | { "max77693-haptic", TYPE_MAX77693 }, | ||
402 | { "max77843-haptic", TYPE_MAX77843 }, | ||
403 | {}, | ||
404 | }; | ||
405 | MODULE_DEVICE_TABLE(platform, max77693_haptic_id); | ||
406 | |||
341 | static struct platform_driver max77693_haptic_driver = { | 407 | static struct platform_driver max77693_haptic_driver = { |
342 | .driver = { | 408 | .driver = { |
343 | .name = "max77693-haptic", | 409 | .name = "max77693-haptic", |
344 | .pm = &max77693_haptic_pm_ops, | 410 | .pm = &max77693_haptic_pm_ops, |
345 | }, | 411 | }, |
346 | .probe = max77693_haptic_probe, | 412 | .probe = max77693_haptic_probe, |
413 | .id_table = max77693_haptic_id, | ||
347 | }; | 414 | }; |
348 | module_platform_driver(max77693_haptic_driver); | 415 | module_platform_driver(max77693_haptic_driver); |
349 | 416 | ||
350 | MODULE_AUTHOR("Jaewon Kim <jaewon02.kim@samsung.com>"); | 417 | MODULE_AUTHOR("Jaewon Kim <jaewon02.kim@samsung.com>"); |
351 | MODULE_DESCRIPTION("MAXIM MAX77693 Haptic driver"); | 418 | MODULE_AUTHOR("Krzysztof Kozlowski <k.kozlowski@samsung.com>"); |
419 | MODULE_DESCRIPTION("MAXIM 77693/77843 Haptic driver"); | ||
352 | MODULE_ALIAS("platform:max77693-haptic"); | 420 | MODULE_ALIAS("platform:max77693-haptic"); |
353 | MODULE_LICENSE("GPL"); | 421 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/input/misc/max77843-haptic.c b/drivers/input/misc/max77843-haptic.c deleted file mode 100644 index dccbb465a055..000000000000 --- a/drivers/input/misc/max77843-haptic.c +++ /dev/null | |||
@@ -1,358 +0,0 @@ | |||
1 | /* | ||
2 | * MAXIM MAX77693 Haptic device driver | ||
3 | * | ||
4 | * Copyright (C) 2015 Samsung Electronics | ||
5 | * Author: Jaewon Kim <jaewon02.kim@samsung.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | */ | ||
12 | |||
13 | #include <linux/err.h> | ||
14 | #include <linux/i2c.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/input.h> | ||
17 | #include <linux/mfd/max77843-private.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/pwm.h> | ||
21 | #include <linux/regmap.h> | ||
22 | #include <linux/regulator/consumer.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/workqueue.h> | ||
25 | |||
26 | #define MAX_MAGNITUDE_SHIFT 16 | ||
27 | |||
28 | enum max77843_haptic_motor_type { | ||
29 | MAX77843_HAPTIC_ERM = 0, | ||
30 | MAX77843_HAPTIC_LRA, | ||
31 | }; | ||
32 | |||
33 | enum max77843_haptic_pwm_divisor { | ||
34 | MAX77843_HAPTIC_PWM_DIVISOR_32 = 0, | ||
35 | MAX77843_HAPTIC_PWM_DIVISOR_64, | ||
36 | MAX77843_HAPTIC_PWM_DIVISOR_128, | ||
37 | MAX77843_HAPTIC_PWM_DIVISOR_256, | ||
38 | }; | ||
39 | |||
40 | struct max77843_haptic { | ||
41 | struct regmap *regmap_haptic; | ||
42 | struct device *dev; | ||
43 | struct input_dev *input_dev; | ||
44 | struct pwm_device *pwm_dev; | ||
45 | struct regulator *motor_reg; | ||
46 | struct work_struct work; | ||
47 | struct mutex mutex; | ||
48 | |||
49 | unsigned int magnitude; | ||
50 | unsigned int pwm_duty; | ||
51 | |||
52 | bool active; | ||
53 | bool suspended; | ||
54 | |||
55 | enum max77843_haptic_motor_type type; | ||
56 | enum max77843_haptic_pwm_divisor pwm_divisor; | ||
57 | }; | ||
58 | |||
59 | static int max77843_haptic_set_duty_cycle(struct max77843_haptic *haptic) | ||
60 | { | ||
61 | int delta = (haptic->pwm_dev->period + haptic->pwm_duty) / 2; | ||
62 | int error; | ||
63 | |||
64 | error = pwm_config(haptic->pwm_dev, delta, haptic->pwm_dev->period); | ||
65 | if (error) { | ||
66 | dev_err(haptic->dev, "failed to configure pwm: %d\n", error); | ||
67 | return error; | ||
68 | } | ||
69 | |||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static int max77843_haptic_bias(struct max77843_haptic *haptic, bool on) | ||
74 | { | ||
75 | int error; | ||
76 | |||
77 | error = regmap_update_bits(haptic->regmap_haptic, | ||
78 | MAX77843_SYS_REG_MAINCTRL1, | ||
79 | MAX77843_MAINCTRL1_BIASEN_MASK, | ||
80 | on << MAINCTRL1_BIASEN_SHIFT); | ||
81 | if (error) { | ||
82 | dev_err(haptic->dev, "failed to %s bias: %d\n", | ||
83 | on ? "enable" : "disable", error); | ||
84 | return error; | ||
85 | } | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | static int max77843_haptic_config(struct max77843_haptic *haptic, bool enable) | ||
91 | { | ||
92 | unsigned int value; | ||
93 | int error; | ||
94 | |||
95 | value = (haptic->type << MCONFIG_MODE_SHIFT) | | ||
96 | (enable << MCONFIG_MEN_SHIFT) | | ||
97 | (haptic->pwm_divisor << MCONFIG_PDIV_SHIFT); | ||
98 | |||
99 | error = regmap_write(haptic->regmap_haptic, | ||
100 | MAX77843_HAP_REG_MCONFIG, value); | ||
101 | if (error) { | ||
102 | dev_err(haptic->dev, | ||
103 | "failed to update haptic config: %d\n", error); | ||
104 | return error; | ||
105 | } | ||
106 | |||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | static int max77843_haptic_enable(struct max77843_haptic *haptic) | ||
111 | { | ||
112 | int error; | ||
113 | |||
114 | if (haptic->active) | ||
115 | return 0; | ||
116 | |||
117 | error = pwm_enable(haptic->pwm_dev); | ||
118 | if (error) { | ||
119 | dev_err(haptic->dev, | ||
120 | "failed to enable pwm device: %d\n", error); | ||
121 | return error; | ||
122 | } | ||
123 | |||
124 | error = max77843_haptic_config(haptic, true); | ||
125 | if (error) | ||
126 | goto err_config; | ||
127 | |||
128 | haptic->active = true; | ||
129 | |||
130 | return 0; | ||
131 | |||
132 | err_config: | ||
133 | pwm_disable(haptic->pwm_dev); | ||
134 | |||
135 | return error; | ||
136 | } | ||
137 | |||
138 | static int max77843_haptic_disable(struct max77843_haptic *haptic) | ||
139 | { | ||
140 | int error; | ||
141 | |||
142 | if (!haptic->active) | ||
143 | return 0; | ||
144 | |||
145 | error = max77843_haptic_config(haptic, false); | ||
146 | if (error) | ||
147 | return error; | ||
148 | |||
149 | pwm_disable(haptic->pwm_dev); | ||
150 | |||
151 | haptic->active = false; | ||
152 | |||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | static void max77843_haptic_play_work(struct work_struct *work) | ||
157 | { | ||
158 | struct max77843_haptic *haptic = | ||
159 | container_of(work, struct max77843_haptic, work); | ||
160 | int error; | ||
161 | |||
162 | mutex_lock(&haptic->mutex); | ||
163 | |||
164 | if (haptic->suspended) | ||
165 | goto out_unlock; | ||
166 | |||
167 | if (haptic->magnitude) { | ||
168 | error = max77843_haptic_set_duty_cycle(haptic); | ||
169 | if (error) { | ||
170 | dev_err(haptic->dev, | ||
171 | "failed to set duty cycle: %d\n", error); | ||
172 | goto out_unlock; | ||
173 | } | ||
174 | |||
175 | error = max77843_haptic_enable(haptic); | ||
176 | if (error) | ||
177 | dev_err(haptic->dev, | ||
178 | "cannot enable haptic: %d\n", error); | ||
179 | } else { | ||
180 | error = max77843_haptic_disable(haptic); | ||
181 | if (error) | ||
182 | dev_err(haptic->dev, | ||
183 | "cannot disable haptic: %d\n", error); | ||
184 | } | ||
185 | |||
186 | out_unlock: | ||
187 | mutex_unlock(&haptic->mutex); | ||
188 | } | ||
189 | |||
190 | static int max77843_haptic_play_effect(struct input_dev *dev, void *data, | ||
191 | struct ff_effect *effect) | ||
192 | { | ||
193 | struct max77843_haptic *haptic = input_get_drvdata(dev); | ||
194 | u64 period_mag_multi; | ||
195 | |||
196 | haptic->magnitude = effect->u.rumble.strong_magnitude; | ||
197 | if (!haptic->magnitude) | ||
198 | haptic->magnitude = effect->u.rumble.weak_magnitude; | ||
199 | |||
200 | period_mag_multi = (u64)haptic->pwm_dev->period * haptic->magnitude; | ||
201 | haptic->pwm_duty = (unsigned int)(period_mag_multi >> | ||
202 | MAX_MAGNITUDE_SHIFT); | ||
203 | |||
204 | schedule_work(&haptic->work); | ||
205 | |||
206 | return 0; | ||
207 | } | ||
208 | |||
209 | static int max77843_haptic_open(struct input_dev *dev) | ||
210 | { | ||
211 | struct max77843_haptic *haptic = input_get_drvdata(dev); | ||
212 | int error; | ||
213 | |||
214 | error = max77843_haptic_bias(haptic, true); | ||
215 | if (error) | ||
216 | return error; | ||
217 | |||
218 | error = regulator_enable(haptic->motor_reg); | ||
219 | if (error) { | ||
220 | dev_err(haptic->dev, | ||
221 | "failed to enable regulator: %d\n", error); | ||
222 | return error; | ||
223 | } | ||
224 | |||
225 | return 0; | ||
226 | } | ||
227 | |||
228 | static void max77843_haptic_close(struct input_dev *dev) | ||
229 | { | ||
230 | struct max77843_haptic *haptic = input_get_drvdata(dev); | ||
231 | int error; | ||
232 | |||
233 | cancel_work_sync(&haptic->work); | ||
234 | max77843_haptic_disable(haptic); | ||
235 | |||
236 | error = regulator_disable(haptic->motor_reg); | ||
237 | if (error) | ||
238 | dev_err(haptic->dev, | ||
239 | "failed to disable regulator: %d\n", error); | ||
240 | |||
241 | max77843_haptic_bias(haptic, false); | ||
242 | } | ||
243 | |||
244 | static int max77843_haptic_probe(struct platform_device *pdev) | ||
245 | { | ||
246 | struct max77843 *max77843 = dev_get_drvdata(pdev->dev.parent); | ||
247 | struct max77843_haptic *haptic; | ||
248 | int error; | ||
249 | |||
250 | haptic = devm_kzalloc(&pdev->dev, sizeof(*haptic), GFP_KERNEL); | ||
251 | if (!haptic) | ||
252 | return -ENOMEM; | ||
253 | |||
254 | haptic->regmap_haptic = max77843->regmap; | ||
255 | haptic->dev = &pdev->dev; | ||
256 | haptic->type = MAX77843_HAPTIC_LRA; | ||
257 | haptic->pwm_divisor = MAX77843_HAPTIC_PWM_DIVISOR_128; | ||
258 | |||
259 | INIT_WORK(&haptic->work, max77843_haptic_play_work); | ||
260 | mutex_init(&haptic->mutex); | ||
261 | |||
262 | haptic->pwm_dev = devm_pwm_get(&pdev->dev, NULL); | ||
263 | if (IS_ERR(haptic->pwm_dev)) { | ||
264 | dev_err(&pdev->dev, "failed to get pwm device\n"); | ||
265 | return PTR_ERR(haptic->pwm_dev); | ||
266 | } | ||
267 | |||
268 | haptic->motor_reg = devm_regulator_get_exclusive(&pdev->dev, "haptic"); | ||
269 | if (IS_ERR(haptic->motor_reg)) { | ||
270 | dev_err(&pdev->dev, "failed to get regulator\n"); | ||
271 | return PTR_ERR(haptic->motor_reg); | ||
272 | } | ||
273 | |||
274 | haptic->input_dev = devm_input_allocate_device(&pdev->dev); | ||
275 | if (!haptic->input_dev) { | ||
276 | dev_err(&pdev->dev, "failed to allocate input device\n"); | ||
277 | return -ENOMEM; | ||
278 | } | ||
279 | |||
280 | haptic->input_dev->name = "max77843-haptic"; | ||
281 | haptic->input_dev->id.version = 1; | ||
282 | haptic->input_dev->dev.parent = &pdev->dev; | ||
283 | haptic->input_dev->open = max77843_haptic_open; | ||
284 | haptic->input_dev->close = max77843_haptic_close; | ||
285 | input_set_drvdata(haptic->input_dev, haptic); | ||
286 | input_set_capability(haptic->input_dev, EV_FF, FF_RUMBLE); | ||
287 | |||
288 | error = input_ff_create_memless(haptic->input_dev, NULL, | ||
289 | max77843_haptic_play_effect); | ||
290 | if (error) { | ||
291 | dev_err(&pdev->dev, "failed to create force-feedback\n"); | ||
292 | return error; | ||
293 | } | ||
294 | |||
295 | error = input_register_device(haptic->input_dev); | ||
296 | if (error) { | ||
297 | dev_err(&pdev->dev, "failed to register input device\n"); | ||
298 | return error; | ||
299 | } | ||
300 | |||
301 | platform_set_drvdata(pdev, haptic); | ||
302 | |||
303 | return 0; | ||
304 | } | ||
305 | |||
306 | static int __maybe_unused max77843_haptic_suspend(struct device *dev) | ||
307 | { | ||
308 | struct platform_device *pdev = to_platform_device(dev); | ||
309 | struct max77843_haptic *haptic = platform_get_drvdata(pdev); | ||
310 | int error; | ||
311 | |||
312 | error = mutex_lock_interruptible(&haptic->mutex); | ||
313 | if (error) | ||
314 | return error; | ||
315 | |||
316 | max77843_haptic_disable(haptic); | ||
317 | |||
318 | haptic->suspended = true; | ||
319 | |||
320 | mutex_unlock(&haptic->mutex); | ||
321 | |||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | static int __maybe_unused max77843_haptic_resume(struct device *dev) | ||
326 | { | ||
327 | struct platform_device *pdev = to_platform_device(dev); | ||
328 | struct max77843_haptic *haptic = platform_get_drvdata(pdev); | ||
329 | unsigned int magnitude; | ||
330 | |||
331 | mutex_lock(&haptic->mutex); | ||
332 | |||
333 | haptic->suspended = false; | ||
334 | |||
335 | magnitude = ACCESS_ONCE(haptic->magnitude); | ||
336 | if (magnitude) | ||
337 | max77843_haptic_enable(haptic); | ||
338 | |||
339 | mutex_unlock(&haptic->mutex); | ||
340 | |||
341 | return 0; | ||
342 | } | ||
343 | |||
344 | static SIMPLE_DEV_PM_OPS(max77843_haptic_pm_ops, | ||
345 | max77843_haptic_suspend, max77843_haptic_resume); | ||
346 | |||
347 | static struct platform_driver max77843_haptic_driver = { | ||
348 | .driver = { | ||
349 | .name = "max77843-haptic", | ||
350 | .pm = &max77843_haptic_pm_ops, | ||
351 | }, | ||
352 | .probe = max77843_haptic_probe, | ||
353 | }; | ||
354 | module_platform_driver(max77843_haptic_driver); | ||
355 | |||
356 | MODULE_AUTHOR("Jaewon Kim <jaewon02.kim@samsung.com>"); | ||
357 | MODULE_DESCRIPTION("MAXIM MAX77843 Haptic driver"); | ||
358 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/leds/leds-max77693.c b/drivers/leds/leds-max77693.c index b8b0eec7b540..df348a06d8c7 100644 --- a/drivers/leds/leds-max77693.c +++ b/drivers/leds/leds-max77693.c | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | #include <linux/led-class-flash.h> | 14 | #include <linux/led-class-flash.h> |
15 | #include <linux/mfd/max77693.h> | 15 | #include <linux/mfd/max77693.h> |
16 | #include <linux/mfd/max77693-common.h> | ||
16 | #include <linux/mfd/max77693-private.h> | 17 | #include <linux/mfd/max77693-private.h> |
17 | #include <linux/module.h> | 18 | #include <linux/module.h> |
18 | #include <linux/mutex.h> | 19 | #include <linux/mutex.h> |
diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c index cb14afa97e6f..67bc53fdc389 100644 --- a/drivers/mfd/max77693.c +++ b/drivers/mfd/max77693.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/mutex.h> | 33 | #include <linux/mutex.h> |
34 | #include <linux/mfd/core.h> | 34 | #include <linux/mfd/core.h> |
35 | #include <linux/mfd/max77693.h> | 35 | #include <linux/mfd/max77693.h> |
36 | #include <linux/mfd/max77693-common.h> | ||
36 | #include <linux/mfd/max77693-private.h> | 37 | #include <linux/mfd/max77693-private.h> |
37 | #include <linux/regulator/machine.h> | 38 | #include <linux/regulator/machine.h> |
38 | #include <linux/regmap.h> | 39 | #include <linux/regmap.h> |
@@ -193,22 +194,22 @@ static int max77693_i2c_probe(struct i2c_client *i2c, | |||
193 | } else | 194 | } else |
194 | dev_info(max77693->dev, "device ID: 0x%x\n", reg_data); | 195 | dev_info(max77693->dev, "device ID: 0x%x\n", reg_data); |
195 | 196 | ||
196 | max77693->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); | 197 | max77693->i2c_muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); |
197 | if (!max77693->muic) { | 198 | if (!max77693->i2c_muic) { |
198 | dev_err(max77693->dev, "Failed to allocate I2C device for MUIC\n"); | 199 | dev_err(max77693->dev, "Failed to allocate I2C device for MUIC\n"); |
199 | return -ENODEV; | 200 | return -ENODEV; |
200 | } | 201 | } |
201 | i2c_set_clientdata(max77693->muic, max77693); | 202 | i2c_set_clientdata(max77693->i2c_muic, max77693); |
202 | 203 | ||
203 | max77693->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); | 204 | max77693->i2c_haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); |
204 | if (!max77693->haptic) { | 205 | if (!max77693->i2c_haptic) { |
205 | dev_err(max77693->dev, "Failed to allocate I2C device for Haptic\n"); | 206 | dev_err(max77693->dev, "Failed to allocate I2C device for Haptic\n"); |
206 | ret = -ENODEV; | 207 | ret = -ENODEV; |
207 | goto err_i2c_haptic; | 208 | goto err_i2c_haptic; |
208 | } | 209 | } |
209 | i2c_set_clientdata(max77693->haptic, max77693); | 210 | i2c_set_clientdata(max77693->i2c_haptic, max77693); |
210 | 211 | ||
211 | max77693->regmap_haptic = devm_regmap_init_i2c(max77693->haptic, | 212 | max77693->regmap_haptic = devm_regmap_init_i2c(max77693->i2c_haptic, |
212 | &max77693_regmap_haptic_config); | 213 | &max77693_regmap_haptic_config); |
213 | if (IS_ERR(max77693->regmap_haptic)) { | 214 | if (IS_ERR(max77693->regmap_haptic)) { |
214 | ret = PTR_ERR(max77693->regmap_haptic); | 215 | ret = PTR_ERR(max77693->regmap_haptic); |
@@ -222,7 +223,7 @@ static int max77693_i2c_probe(struct i2c_client *i2c, | |||
222 | * instance of MUIC device when irq of max77693 is initialized | 223 | * instance of MUIC device when irq of max77693 is initialized |
223 | * before call max77693-muic probe() function. | 224 | * before call max77693-muic probe() function. |
224 | */ | 225 | */ |
225 | max77693->regmap_muic = devm_regmap_init_i2c(max77693->muic, | 226 | max77693->regmap_muic = devm_regmap_init_i2c(max77693->i2c_muic, |
226 | &max77693_regmap_muic_config); | 227 | &max77693_regmap_muic_config); |
227 | if (IS_ERR(max77693->regmap_muic)) { | 228 | if (IS_ERR(max77693->regmap_muic)) { |
228 | ret = PTR_ERR(max77693->regmap_muic); | 229 | ret = PTR_ERR(max77693->regmap_muic); |
@@ -255,7 +256,7 @@ static int max77693_i2c_probe(struct i2c_client *i2c, | |||
255 | IRQF_ONESHOT | IRQF_SHARED | | 256 | IRQF_ONESHOT | IRQF_SHARED | |
256 | IRQF_TRIGGER_FALLING, 0, | 257 | IRQF_TRIGGER_FALLING, 0, |
257 | &max77693_charger_irq_chip, | 258 | &max77693_charger_irq_chip, |
258 | &max77693->irq_data_charger); | 259 | &max77693->irq_data_chg); |
259 | if (ret) { | 260 | if (ret) { |
260 | dev_err(max77693->dev, "failed to add irq chip: %d\n", ret); | 261 | dev_err(max77693->dev, "failed to add irq chip: %d\n", ret); |
261 | goto err_irq_charger; | 262 | goto err_irq_charger; |
@@ -296,15 +297,15 @@ err_mfd: | |||
296 | err_intsrc: | 297 | err_intsrc: |
297 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_muic); | 298 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_muic); |
298 | err_irq_muic: | 299 | err_irq_muic: |
299 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_charger); | 300 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_chg); |
300 | err_irq_charger: | 301 | err_irq_charger: |
301 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_topsys); | 302 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_topsys); |
302 | err_irq_topsys: | 303 | err_irq_topsys: |
303 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_led); | 304 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_led); |
304 | err_regmap: | 305 | err_regmap: |
305 | i2c_unregister_device(max77693->haptic); | 306 | i2c_unregister_device(max77693->i2c_haptic); |
306 | err_i2c_haptic: | 307 | err_i2c_haptic: |
307 | i2c_unregister_device(max77693->muic); | 308 | i2c_unregister_device(max77693->i2c_muic); |
308 | return ret; | 309 | return ret; |
309 | } | 310 | } |
310 | 311 | ||
@@ -315,12 +316,12 @@ static int max77693_i2c_remove(struct i2c_client *i2c) | |||
315 | mfd_remove_devices(max77693->dev); | 316 | mfd_remove_devices(max77693->dev); |
316 | 317 | ||
317 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_muic); | 318 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_muic); |
318 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_charger); | 319 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_chg); |
319 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_topsys); | 320 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_topsys); |
320 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_led); | 321 | regmap_del_irq_chip(max77693->irq, max77693->irq_data_led); |
321 | 322 | ||
322 | i2c_unregister_device(max77693->muic); | 323 | i2c_unregister_device(max77693->i2c_muic); |
323 | i2c_unregister_device(max77693->haptic); | 324 | i2c_unregister_device(max77693->i2c_haptic); |
324 | 325 | ||
325 | return 0; | 326 | return 0; |
326 | } | 327 | } |
diff --git a/drivers/mfd/max77843.c b/drivers/mfd/max77843.c index a354ac677ec7..c52162ea3d0a 100644 --- a/drivers/mfd/max77843.c +++ b/drivers/mfd/max77843.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/mfd/core.h> | 19 | #include <linux/mfd/core.h> |
20 | #include <linux/mfd/max77693-common.h> | ||
20 | #include <linux/mfd/max77843-private.h> | 21 | #include <linux/mfd/max77843-private.h> |
21 | #include <linux/of_device.h> | 22 | #include <linux/of_device.h> |
22 | #include <linux/platform_device.h> | 23 | #include <linux/platform_device.h> |
@@ -71,7 +72,7 @@ static const struct regmap_irq_chip max77843_irq_chip = { | |||
71 | }; | 72 | }; |
72 | 73 | ||
73 | /* Charger and Charger regulator use same regmap. */ | 74 | /* Charger and Charger regulator use same regmap. */ |
74 | static int max77843_chg_init(struct max77843 *max77843) | 75 | static int max77843_chg_init(struct max77693_dev *max77843) |
75 | { | 76 | { |
76 | int ret; | 77 | int ret; |
77 | 78 | ||
@@ -101,7 +102,7 @@ err_chg_i2c: | |||
101 | static int max77843_probe(struct i2c_client *i2c, | 102 | static int max77843_probe(struct i2c_client *i2c, |
102 | const struct i2c_device_id *id) | 103 | const struct i2c_device_id *id) |
103 | { | 104 | { |
104 | struct max77843 *max77843; | 105 | struct max77693_dev *max77843; |
105 | unsigned int reg_data; | 106 | unsigned int reg_data; |
106 | int ret; | 107 | int ret; |
107 | 108 | ||
@@ -113,6 +114,7 @@ static int max77843_probe(struct i2c_client *i2c, | |||
113 | max77843->dev = &i2c->dev; | 114 | max77843->dev = &i2c->dev; |
114 | max77843->i2c = i2c; | 115 | max77843->i2c = i2c; |
115 | max77843->irq = i2c->irq; | 116 | max77843->irq = i2c->irq; |
117 | max77843->type = id->driver_data; | ||
116 | 118 | ||
117 | max77843->regmap = devm_regmap_init_i2c(i2c, | 119 | max77843->regmap = devm_regmap_init_i2c(i2c, |
118 | &max77843_regmap_config); | 120 | &max77843_regmap_config); |
@@ -123,7 +125,7 @@ static int max77843_probe(struct i2c_client *i2c, | |||
123 | 125 | ||
124 | ret = regmap_add_irq_chip(max77843->regmap, max77843->irq, | 126 | ret = regmap_add_irq_chip(max77843->regmap, max77843->irq, |
125 | IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED, | 127 | IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED, |
126 | 0, &max77843_irq_chip, &max77843->irq_data); | 128 | 0, &max77843_irq_chip, &max77843->irq_data_topsys); |
127 | if (ret) { | 129 | if (ret) { |
128 | dev_err(&i2c->dev, "Failed to add TOPSYS IRQ chip\n"); | 130 | dev_err(&i2c->dev, "Failed to add TOPSYS IRQ chip\n"); |
129 | return ret; | 131 | return ret; |
@@ -164,18 +166,18 @@ static int max77843_probe(struct i2c_client *i2c, | |||
164 | return 0; | 166 | return 0; |
165 | 167 | ||
166 | err_pmic_id: | 168 | err_pmic_id: |
167 | regmap_del_irq_chip(max77843->irq, max77843->irq_data); | 169 | regmap_del_irq_chip(max77843->irq, max77843->irq_data_topsys); |
168 | 170 | ||
169 | return ret; | 171 | return ret; |
170 | } | 172 | } |
171 | 173 | ||
172 | static int max77843_remove(struct i2c_client *i2c) | 174 | static int max77843_remove(struct i2c_client *i2c) |
173 | { | 175 | { |
174 | struct max77843 *max77843 = i2c_get_clientdata(i2c); | 176 | struct max77693_dev *max77843 = i2c_get_clientdata(i2c); |
175 | 177 | ||
176 | mfd_remove_devices(max77843->dev); | 178 | mfd_remove_devices(max77843->dev); |
177 | 179 | ||
178 | regmap_del_irq_chip(max77843->irq, max77843->irq_data); | 180 | regmap_del_irq_chip(max77843->irq, max77843->irq_data_topsys); |
179 | 181 | ||
180 | i2c_unregister_device(max77843->i2c_chg); | 182 | i2c_unregister_device(max77843->i2c_chg); |
181 | 183 | ||
@@ -188,7 +190,7 @@ static const struct of_device_id max77843_dt_match[] = { | |||
188 | }; | 190 | }; |
189 | 191 | ||
190 | static const struct i2c_device_id max77843_id[] = { | 192 | static const struct i2c_device_id max77843_id[] = { |
191 | { "max77843", }, | 193 | { "max77843", TYPE_MAX77843, }, |
192 | { }, | 194 | { }, |
193 | }; | 195 | }; |
194 | MODULE_DEVICE_TABLE(i2c, max77843_id); | 196 | MODULE_DEVICE_TABLE(i2c, max77843_id); |
@@ -196,7 +198,7 @@ MODULE_DEVICE_TABLE(i2c, max77843_id); | |||
196 | static int __maybe_unused max77843_suspend(struct device *dev) | 198 | static int __maybe_unused max77843_suspend(struct device *dev) |
197 | { | 199 | { |
198 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); | 200 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); |
199 | struct max77843 *max77843 = i2c_get_clientdata(i2c); | 201 | struct max77693_dev *max77843 = i2c_get_clientdata(i2c); |
200 | 202 | ||
201 | disable_irq(max77843->irq); | 203 | disable_irq(max77843->irq); |
202 | if (device_may_wakeup(dev)) | 204 | if (device_may_wakeup(dev)) |
@@ -208,7 +210,7 @@ static int __maybe_unused max77843_suspend(struct device *dev) | |||
208 | static int __maybe_unused max77843_resume(struct device *dev) | 210 | static int __maybe_unused max77843_resume(struct device *dev) |
209 | { | 211 | { |
210 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); | 212 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); |
211 | struct max77843 *max77843 = i2c_get_clientdata(i2c); | 213 | struct max77693_dev *max77843 = i2c_get_clientdata(i2c); |
212 | 214 | ||
213 | if (device_may_wakeup(dev)) | 215 | if (device_may_wakeup(dev)) |
214 | disable_irq_wake(max77843->irq); | 216 | disable_irq_wake(max77843->irq); |
diff --git a/drivers/power/max77693_charger.c b/drivers/power/max77693_charger.c index 754879eb59f6..060cab5ae3aa 100644 --- a/drivers/power/max77693_charger.c +++ b/drivers/power/max77693_charger.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/power_supply.h> | 20 | #include <linux/power_supply.h> |
21 | #include <linux/regmap.h> | 21 | #include <linux/regmap.h> |
22 | #include <linux/mfd/max77693.h> | 22 | #include <linux/mfd/max77693.h> |
23 | #include <linux/mfd/max77693-common.h> | ||
23 | #include <linux/mfd/max77693-private.h> | 24 | #include <linux/mfd/max77693-private.h> |
24 | 25 | ||
25 | #define MAX77693_CHARGER_NAME "max77693-charger" | 26 | #define MAX77693_CHARGER_NAME "max77693-charger" |
diff --git a/drivers/regulator/88pm800.c b/drivers/regulator/88pm800.c index 7fd4f511d78f..a62a89674fb5 100644 --- a/drivers/regulator/88pm800.c +++ b/drivers/regulator/88pm800.c | |||
@@ -78,7 +78,6 @@ struct pm800_regulator_info { | |||
78 | }; | 78 | }; |
79 | 79 | ||
80 | struct pm800_regulators { | 80 | struct pm800_regulators { |
81 | struct regulator_dev *regulators[PM800_ID_RG_MAX]; | ||
82 | struct pm80x_chip *chip; | 81 | struct pm80x_chip *chip; |
83 | struct regmap *map; | 82 | struct regmap *map; |
84 | }; | 83 | }; |
@@ -92,14 +91,16 @@ struct pm800_regulators { | |||
92 | * not the constant voltage table. | 91 | * not the constant voltage table. |
93 | * n_volt - Number of available selectors | 92 | * n_volt - Number of available selectors |
94 | */ | 93 | */ |
95 | #define PM800_BUCK(vreg, ereg, ebit, amax, volt_ranges, n_volt) \ | 94 | #define PM800_BUCK(match, vreg, ereg, ebit, amax, volt_ranges, n_volt) \ |
96 | { \ | 95 | { \ |
97 | .desc = { \ | 96 | .desc = { \ |
98 | .name = #vreg, \ | 97 | .name = #vreg, \ |
99 | .ops = &pm800_volt_range_ops, \ | 98 | .of_match = of_match_ptr(#match), \ |
100 | .type = REGULATOR_VOLTAGE, \ | 99 | .regulators_node = of_match_ptr("regulators"), \ |
101 | .id = PM800_ID_##vreg, \ | 100 | .ops = &pm800_volt_range_ops, \ |
102 | .owner = THIS_MODULE, \ | 101 | .type = REGULATOR_VOLTAGE, \ |
102 | .id = PM800_ID_##vreg, \ | ||
103 | .owner = THIS_MODULE, \ | ||
103 | .n_voltages = n_volt, \ | 104 | .n_voltages = n_volt, \ |
104 | .linear_ranges = volt_ranges, \ | 105 | .linear_ranges = volt_ranges, \ |
105 | .n_linear_ranges = ARRAY_SIZE(volt_ranges), \ | 106 | .n_linear_ranges = ARRAY_SIZE(volt_ranges), \ |
@@ -108,7 +109,7 @@ struct pm800_regulators { | |||
108 | .enable_reg = PM800_##ereg, \ | 109 | .enable_reg = PM800_##ereg, \ |
109 | .enable_mask = 1 << (ebit), \ | 110 | .enable_mask = 1 << (ebit), \ |
110 | }, \ | 111 | }, \ |
111 | .max_ua = (amax), \ | 112 | .max_ua = (amax), \ |
112 | } | 113 | } |
113 | 114 | ||
114 | /* | 115 | /* |
@@ -120,22 +121,24 @@ struct pm800_regulators { | |||
120 | * For all the LDOes, there are too many ranges. Using volt_table will be | 121 | * For all the LDOes, there are too many ranges. Using volt_table will be |
121 | * simpler and faster. | 122 | * simpler and faster. |
122 | */ | 123 | */ |
123 | #define PM800_LDO(vreg, ereg, ebit, amax, ldo_volt_table) \ | 124 | #define PM800_LDO(match, vreg, ereg, ebit, amax, ldo_volt_table) \ |
124 | { \ | 125 | { \ |
125 | .desc = { \ | 126 | .desc = { \ |
126 | .name = #vreg, \ | 127 | .name = #vreg, \ |
127 | .ops = &pm800_volt_table_ops, \ | 128 | .of_match = of_match_ptr(#match), \ |
128 | .type = REGULATOR_VOLTAGE, \ | 129 | .regulators_node = of_match_ptr("regulators"), \ |
129 | .id = PM800_ID_##vreg, \ | 130 | .ops = &pm800_volt_table_ops, \ |
130 | .owner = THIS_MODULE, \ | 131 | .type = REGULATOR_VOLTAGE, \ |
131 | .n_voltages = ARRAY_SIZE(ldo_volt_table), \ | 132 | .id = PM800_ID_##vreg, \ |
132 | .vsel_reg = PM800_##vreg##_VOUT, \ | 133 | .owner = THIS_MODULE, \ |
133 | .vsel_mask = 0xf, \ | 134 | .n_voltages = ARRAY_SIZE(ldo_volt_table), \ |
134 | .enable_reg = PM800_##ereg, \ | 135 | .vsel_reg = PM800_##vreg##_VOUT, \ |
135 | .enable_mask = 1 << (ebit), \ | 136 | .vsel_mask = 0xf, \ |
136 | .volt_table = ldo_volt_table, \ | 137 | .enable_reg = PM800_##ereg, \ |
138 | .enable_mask = 1 << (ebit), \ | ||
139 | .volt_table = ldo_volt_table, \ | ||
137 | }, \ | 140 | }, \ |
138 | .max_ua = (amax), \ | 141 | .max_ua = (amax), \ |
139 | } | 142 | } |
140 | 143 | ||
141 | /* Ranges are sorted in ascending order. */ | 144 | /* Ranges are sorted in ascending order. */ |
@@ -178,122 +181,66 @@ static int pm800_get_current_limit(struct regulator_dev *rdev) | |||
178 | } | 181 | } |
179 | 182 | ||
180 | static struct regulator_ops pm800_volt_range_ops = { | 183 | static struct regulator_ops pm800_volt_range_ops = { |
181 | .list_voltage = regulator_list_voltage_linear_range, | 184 | .list_voltage = regulator_list_voltage_linear_range, |
182 | .map_voltage = regulator_map_voltage_linear_range, | 185 | .map_voltage = regulator_map_voltage_linear_range, |
183 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 186 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
184 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 187 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
185 | .enable = regulator_enable_regmap, | 188 | .enable = regulator_enable_regmap, |
186 | .disable = regulator_disable_regmap, | 189 | .disable = regulator_disable_regmap, |
187 | .is_enabled = regulator_is_enabled_regmap, | 190 | .is_enabled = regulator_is_enabled_regmap, |
188 | .get_current_limit = pm800_get_current_limit, | 191 | .get_current_limit = pm800_get_current_limit, |
189 | }; | 192 | }; |
190 | 193 | ||
191 | static struct regulator_ops pm800_volt_table_ops = { | 194 | static struct regulator_ops pm800_volt_table_ops = { |
192 | .list_voltage = regulator_list_voltage_table, | 195 | .list_voltage = regulator_list_voltage_table, |
193 | .map_voltage = regulator_map_voltage_iterate, | 196 | .map_voltage = regulator_map_voltage_iterate, |
194 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 197 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
195 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 198 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
196 | .enable = regulator_enable_regmap, | 199 | .enable = regulator_enable_regmap, |
197 | .disable = regulator_disable_regmap, | 200 | .disable = regulator_disable_regmap, |
198 | .is_enabled = regulator_is_enabled_regmap, | 201 | .is_enabled = regulator_is_enabled_regmap, |
199 | .get_current_limit = pm800_get_current_limit, | 202 | .get_current_limit = pm800_get_current_limit, |
200 | }; | 203 | }; |
201 | 204 | ||
202 | /* The array is indexed by id(PM800_ID_XXX) */ | 205 | /* The array is indexed by id(PM800_ID_XXX) */ |
203 | static struct pm800_regulator_info pm800_regulator_info[] = { | 206 | static struct pm800_regulator_info pm800_regulator_info[] = { |
204 | PM800_BUCK(BUCK1, BUCK_ENA, 0, 3000000, buck1_volt_range, 0x55), | 207 | PM800_BUCK(buck1, BUCK1, BUCK_ENA, 0, 3000000, buck1_volt_range, 0x55), |
205 | PM800_BUCK(BUCK2, BUCK_ENA, 1, 1200000, buck2_5_volt_range, 0x73), | 208 | PM800_BUCK(buck2, BUCK2, BUCK_ENA, 1, 1200000, buck2_5_volt_range, 0x73), |
206 | PM800_BUCK(BUCK3, BUCK_ENA, 2, 1200000, buck2_5_volt_range, 0x73), | 209 | PM800_BUCK(buck3, BUCK3, BUCK_ENA, 2, 1200000, buck2_5_volt_range, 0x73), |
207 | PM800_BUCK(BUCK4, BUCK_ENA, 3, 1200000, buck2_5_volt_range, 0x73), | 210 | PM800_BUCK(buck4, BUCK4, BUCK_ENA, 3, 1200000, buck2_5_volt_range, 0x73), |
208 | PM800_BUCK(BUCK5, BUCK_ENA, 4, 1200000, buck2_5_volt_range, 0x73), | 211 | PM800_BUCK(buck5, BUCK5, BUCK_ENA, 4, 1200000, buck2_5_volt_range, 0x73), |
209 | 212 | ||
210 | PM800_LDO(LDO1, LDO_ENA1_1, 0, 200000, ldo1_volt_table), | 213 | PM800_LDO(ldo1, LDO1, LDO_ENA1_1, 0, 200000, ldo1_volt_table), |
211 | PM800_LDO(LDO2, LDO_ENA1_1, 1, 10000, ldo2_volt_table), | 214 | PM800_LDO(ldo2, LDO2, LDO_ENA1_1, 1, 10000, ldo2_volt_table), |
212 | PM800_LDO(LDO3, LDO_ENA1_1, 2, 300000, ldo3_17_volt_table), | 215 | PM800_LDO(ldo3, LDO3, LDO_ENA1_1, 2, 300000, ldo3_17_volt_table), |
213 | PM800_LDO(LDO4, LDO_ENA1_1, 3, 300000, ldo3_17_volt_table), | 216 | PM800_LDO(ldo4, LDO4, LDO_ENA1_1, 3, 300000, ldo3_17_volt_table), |
214 | PM800_LDO(LDO5, LDO_ENA1_1, 4, 300000, ldo3_17_volt_table), | 217 | PM800_LDO(ldo5, LDO5, LDO_ENA1_1, 4, 300000, ldo3_17_volt_table), |
215 | PM800_LDO(LDO6, LDO_ENA1_1, 5, 300000, ldo3_17_volt_table), | 218 | PM800_LDO(ldo6, LDO6, LDO_ENA1_1, 5, 300000, ldo3_17_volt_table), |
216 | PM800_LDO(LDO7, LDO_ENA1_1, 6, 300000, ldo3_17_volt_table), | 219 | PM800_LDO(ldo7, LDO7, LDO_ENA1_1, 6, 300000, ldo3_17_volt_table), |
217 | PM800_LDO(LDO8, LDO_ENA1_1, 7, 300000, ldo3_17_volt_table), | 220 | PM800_LDO(ldo8, LDO8, LDO_ENA1_1, 7, 300000, ldo3_17_volt_table), |
218 | PM800_LDO(LDO9, LDO_ENA1_2, 0, 300000, ldo3_17_volt_table), | 221 | PM800_LDO(ldo9, LDO9, LDO_ENA1_2, 0, 300000, ldo3_17_volt_table), |
219 | PM800_LDO(LDO10, LDO_ENA1_2, 1, 300000, ldo3_17_volt_table), | 222 | PM800_LDO(ldo10, LDO10, LDO_ENA1_2, 1, 300000, ldo3_17_volt_table), |
220 | PM800_LDO(LDO11, LDO_ENA1_2, 2, 300000, ldo3_17_volt_table), | 223 | PM800_LDO(ldo11, LDO11, LDO_ENA1_2, 2, 300000, ldo3_17_volt_table), |
221 | PM800_LDO(LDO12, LDO_ENA1_2, 3, 300000, ldo3_17_volt_table), | 224 | PM800_LDO(ldo12, LDO12, LDO_ENA1_2, 3, 300000, ldo3_17_volt_table), |
222 | PM800_LDO(LDO13, LDO_ENA1_2, 4, 300000, ldo3_17_volt_table), | 225 | PM800_LDO(ldo13, LDO13, LDO_ENA1_2, 4, 300000, ldo3_17_volt_table), |
223 | PM800_LDO(LDO14, LDO_ENA1_2, 5, 300000, ldo3_17_volt_table), | 226 | PM800_LDO(ldo14, LDO14, LDO_ENA1_2, 5, 300000, ldo3_17_volt_table), |
224 | PM800_LDO(LDO15, LDO_ENA1_2, 6, 300000, ldo3_17_volt_table), | 227 | PM800_LDO(ldo15, LDO15, LDO_ENA1_2, 6, 300000, ldo3_17_volt_table), |
225 | PM800_LDO(LDO16, LDO_ENA1_2, 7, 300000, ldo3_17_volt_table), | 228 | PM800_LDO(ldo16, LDO16, LDO_ENA1_2, 7, 300000, ldo3_17_volt_table), |
226 | PM800_LDO(LDO17, LDO_ENA1_3, 0, 300000, ldo3_17_volt_table), | 229 | PM800_LDO(ldo17, LDO17, LDO_ENA1_3, 0, 300000, ldo3_17_volt_table), |
227 | PM800_LDO(LDO18, LDO_ENA1_3, 1, 200000, ldo18_19_volt_table), | 230 | PM800_LDO(ldo18, LDO18, LDO_ENA1_3, 1, 200000, ldo18_19_volt_table), |
228 | PM800_LDO(LDO19, LDO_ENA1_3, 2, 200000, ldo18_19_volt_table), | 231 | PM800_LDO(ldo19, LDO19, LDO_ENA1_3, 2, 200000, ldo18_19_volt_table), |
229 | }; | ||
230 | |||
231 | #define PM800_REGULATOR_OF_MATCH(_name, _id) \ | ||
232 | [PM800_ID_##_id] = { \ | ||
233 | .name = #_name, \ | ||
234 | .driver_data = &pm800_regulator_info[PM800_ID_##_id], \ | ||
235 | } | ||
236 | |||
237 | static struct of_regulator_match pm800_regulator_matches[] = { | ||
238 | PM800_REGULATOR_OF_MATCH(buck1, BUCK1), | ||
239 | PM800_REGULATOR_OF_MATCH(buck2, BUCK2), | ||
240 | PM800_REGULATOR_OF_MATCH(buck3, BUCK3), | ||
241 | PM800_REGULATOR_OF_MATCH(buck4, BUCK4), | ||
242 | PM800_REGULATOR_OF_MATCH(buck5, BUCK5), | ||
243 | PM800_REGULATOR_OF_MATCH(ldo1, LDO1), | ||
244 | PM800_REGULATOR_OF_MATCH(ldo2, LDO2), | ||
245 | PM800_REGULATOR_OF_MATCH(ldo3, LDO3), | ||
246 | PM800_REGULATOR_OF_MATCH(ldo4, LDO4), | ||
247 | PM800_REGULATOR_OF_MATCH(ldo5, LDO5), | ||
248 | PM800_REGULATOR_OF_MATCH(ldo6, LDO6), | ||
249 | PM800_REGULATOR_OF_MATCH(ldo7, LDO7), | ||
250 | PM800_REGULATOR_OF_MATCH(ldo8, LDO8), | ||
251 | PM800_REGULATOR_OF_MATCH(ldo9, LDO9), | ||
252 | PM800_REGULATOR_OF_MATCH(ldo10, LDO10), | ||
253 | PM800_REGULATOR_OF_MATCH(ldo11, LDO11), | ||
254 | PM800_REGULATOR_OF_MATCH(ldo12, LDO12), | ||
255 | PM800_REGULATOR_OF_MATCH(ldo13, LDO13), | ||
256 | PM800_REGULATOR_OF_MATCH(ldo14, LDO14), | ||
257 | PM800_REGULATOR_OF_MATCH(ldo15, LDO15), | ||
258 | PM800_REGULATOR_OF_MATCH(ldo16, LDO16), | ||
259 | PM800_REGULATOR_OF_MATCH(ldo17, LDO17), | ||
260 | PM800_REGULATOR_OF_MATCH(ldo18, LDO18), | ||
261 | PM800_REGULATOR_OF_MATCH(ldo19, LDO19), | ||
262 | }; | 232 | }; |
263 | 233 | ||
264 | static int pm800_regulator_dt_init(struct platform_device *pdev) | ||
265 | { | ||
266 | struct device_node *np = pdev->dev.of_node; | ||
267 | int ret; | ||
268 | |||
269 | ret = of_regulator_match(&pdev->dev, np, | ||
270 | pm800_regulator_matches, | ||
271 | ARRAY_SIZE(pm800_regulator_matches)); | ||
272 | if (ret < 0) | ||
273 | return ret; | ||
274 | |||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | static int pm800_regulator_probe(struct platform_device *pdev) | 234 | static int pm800_regulator_probe(struct platform_device *pdev) |
279 | { | 235 | { |
280 | struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent); | 236 | struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent); |
281 | struct pm80x_platform_data *pdata = dev_get_platdata(pdev->dev.parent); | 237 | struct pm80x_platform_data *pdata = dev_get_platdata(pdev->dev.parent); |
282 | struct pm800_regulators *pm800_data; | 238 | struct pm800_regulators *pm800_data; |
283 | struct pm800_regulator_info *info; | ||
284 | struct regulator_config config = { }; | 239 | struct regulator_config config = { }; |
285 | struct regulator_init_data *init_data; | 240 | struct regulator_init_data *init_data; |
286 | int i, ret; | 241 | int i, ret; |
287 | 242 | ||
288 | if (!pdata || pdata->num_regulators == 0) { | 243 | if (pdata && pdata->num_regulators) { |
289 | if (IS_ENABLED(CONFIG_OF)) { | ||
290 | ret = pm800_regulator_dt_init(pdev); | ||
291 | if (ret) | ||
292 | return ret; | ||
293 | } else { | ||
294 | return -ENODEV; | ||
295 | } | ||
296 | } else if (pdata->num_regulators) { | ||
297 | unsigned int count = 0; | 244 | unsigned int count = 0; |
298 | 245 | ||
299 | /* Check whether num_regulator is valid. */ | 246 | /* Check whether num_regulator is valid. */ |
@@ -303,8 +250,6 @@ static int pm800_regulator_probe(struct platform_device *pdev) | |||
303 | } | 250 | } |
304 | if (count != pdata->num_regulators) | 251 | if (count != pdata->num_regulators) |
305 | return -EINVAL; | 252 | return -EINVAL; |
306 | } else { | ||
307 | return -EINVAL; | ||
308 | } | 253 | } |
309 | 254 | ||
310 | pm800_data = devm_kzalloc(&pdev->dev, sizeof(*pm800_data), | 255 | pm800_data = devm_kzalloc(&pdev->dev, sizeof(*pm800_data), |
@@ -317,30 +262,27 @@ static int pm800_regulator_probe(struct platform_device *pdev) | |||
317 | 262 | ||
318 | platform_set_drvdata(pdev, pm800_data); | 263 | platform_set_drvdata(pdev, pm800_data); |
319 | 264 | ||
265 | config.dev = chip->dev; | ||
266 | config.regmap = pm800_data->map; | ||
320 | for (i = 0; i < PM800_ID_RG_MAX; i++) { | 267 | for (i = 0; i < PM800_ID_RG_MAX; i++) { |
321 | if (!pdata || pdata->num_regulators == 0) | 268 | struct regulator_dev *regulator; |
322 | init_data = pm800_regulator_matches[i].init_data; | 269 | |
323 | else | 270 | if (pdata && pdata->num_regulators) { |
324 | init_data = pdata->regulators[i]; | 271 | init_data = pdata->regulators[i]; |
325 | if (!init_data) | 272 | if (!init_data) |
326 | continue; | 273 | continue; |
327 | info = pm800_regulator_matches[i].driver_data; | ||
328 | config.dev = &pdev->dev; | ||
329 | config.init_data = init_data; | ||
330 | config.driver_data = info; | ||
331 | config.regmap = pm800_data->map; | ||
332 | config.of_node = pm800_regulator_matches[i].of_node; | ||
333 | |||
334 | pm800_data->regulators[i] = | ||
335 | regulator_register(&info->desc, &config); | ||
336 | if (IS_ERR(pm800_data->regulators[i])) { | ||
337 | ret = PTR_ERR(pm800_data->regulators[i]); | ||
338 | dev_err(&pdev->dev, "Failed to register %s\n", | ||
339 | info->desc.name); | ||
340 | 274 | ||
341 | while (--i >= 0) | 275 | config.init_data = init_data; |
342 | regulator_unregister(pm800_data->regulators[i]); | 276 | } |
277 | |||
278 | config.driver_data = &pm800_regulator_info[i]; | ||
343 | 279 | ||
280 | regulator = devm_regulator_register(&pdev->dev, | ||
281 | &pm800_regulator_info[i].desc, &config); | ||
282 | if (IS_ERR(regulator)) { | ||
283 | ret = PTR_ERR(regulator); | ||
284 | dev_err(&pdev->dev, "Failed to register %s\n", | ||
285 | pm800_regulator_info[i].desc.name); | ||
344 | return ret; | 286 | return ret; |
345 | } | 287 | } |
346 | } | 288 | } |
@@ -348,23 +290,11 @@ static int pm800_regulator_probe(struct platform_device *pdev) | |||
348 | return 0; | 290 | return 0; |
349 | } | 291 | } |
350 | 292 | ||
351 | static int pm800_regulator_remove(struct platform_device *pdev) | ||
352 | { | ||
353 | struct pm800_regulators *pm800_data = platform_get_drvdata(pdev); | ||
354 | int i; | ||
355 | |||
356 | for (i = 0; i < PM800_ID_RG_MAX; i++) | ||
357 | regulator_unregister(pm800_data->regulators[i]); | ||
358 | |||
359 | return 0; | ||
360 | } | ||
361 | |||
362 | static struct platform_driver pm800_regulator_driver = { | 293 | static struct platform_driver pm800_regulator_driver = { |
363 | .driver = { | 294 | .driver = { |
364 | .name = "88pm80x-regulator", | 295 | .name = "88pm80x-regulator", |
365 | }, | 296 | }, |
366 | .probe = pm800_regulator_probe, | 297 | .probe = pm800_regulator_probe, |
367 | .remove = pm800_regulator_remove, | ||
368 | }; | 298 | }; |
369 | 299 | ||
370 | module_platform_driver(pm800_regulator_driver); | 300 | module_platform_driver(pm800_regulator_driver); |
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index bef3bde6971b..64bccff557be 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig | |||
@@ -209,13 +209,13 @@ config REGULATOR_DA9210 | |||
209 | interface. | 209 | interface. |
210 | 210 | ||
211 | config REGULATOR_DA9211 | 211 | config REGULATOR_DA9211 |
212 | tristate "Dialog Semiconductor DA9211/DA9212/DA9213/DA9214 regulator" | 212 | tristate "Dialog Semiconductor DA9211/DA9212/DA9213/DA9214/DA9215 regulator" |
213 | depends on I2C | 213 | depends on I2C |
214 | select REGMAP_I2C | 214 | select REGMAP_I2C |
215 | help | 215 | help |
216 | Say y here to support for the Dialog Semiconductor DA9211/DA9212 | 216 | Say y here to support for the Dialog Semiconductor DA9211/DA9212 |
217 | /DA9213/DA9214. | 217 | /DA9213/DA9214/DA9215. |
218 | The DA9211/DA9212/DA9213/DA9214 is a multi-phase synchronous | 218 | The DA9211/DA9212/DA9213/DA9214/DA9215 is a multi-phase synchronous |
219 | step down converter 12A or 16A DC-DC Buck controlled through an I2C | 219 | step down converter 12A or 16A DC-DC Buck controlled through an I2C |
220 | interface. | 220 | interface. |
221 | 221 | ||
@@ -407,13 +407,13 @@ config REGULATOR_MAX77686 | |||
407 | Exynos-4 chips to control VARM and VINT voltages. | 407 | Exynos-4 chips to control VARM and VINT voltages. |
408 | 408 | ||
409 | config REGULATOR_MAX77693 | 409 | config REGULATOR_MAX77693 |
410 | tristate "Maxim MAX77693 regulator" | 410 | tristate "Maxim 77693/77843 regulator" |
411 | depends on MFD_MAX77693 | 411 | depends on (MFD_MAX77693 || MFD_MAX77843) |
412 | help | 412 | help |
413 | This driver controls a Maxim 77693 regulator via I2C bus. | 413 | This driver controls a Maxim 77693/77843 regulators via I2C bus. |
414 | The regulators include two LDOs, 'SAFEOUT1', 'SAFEOUT2' | 414 | The regulators include two LDOs, 'SAFEOUT1', 'SAFEOUT2' |
415 | and one current regulator 'CHARGER'. This is suitable for | 415 | and one current regulator 'CHARGER'. This is suitable for |
416 | Exynos-4x12 chips. | 416 | Exynos-4x12 (MAX77693) or Exynos5433 (MAX77843) SoC chips. |
417 | 417 | ||
418 | config REGULATOR_MAX77802 | 418 | config REGULATOR_MAX77802 |
419 | tristate "Maxim 77802 regulator" | 419 | tristate "Maxim 77802 regulator" |
@@ -424,14 +424,6 @@ config REGULATOR_MAX77802 | |||
424 | Exynos5420/Exynos5800 SoCs to control various voltages. | 424 | Exynos5420/Exynos5800 SoCs to control various voltages. |
425 | It includes support for control of voltage and ramp speed. | 425 | It includes support for control of voltage and ramp speed. |
426 | 426 | ||
427 | config REGULATOR_MAX77843 | ||
428 | tristate "Maxim 77843 regulator" | ||
429 | depends on MFD_MAX77843 | ||
430 | help | ||
431 | This driver controls a Maxim 77843 regulator. | ||
432 | The regulator include two 'SAFEOUT' for USB(Universal Serial Bus) | ||
433 | This is suitable for Exynos5433 SoC chips. | ||
434 | |||
435 | config REGULATOR_MC13XXX_CORE | 427 | config REGULATOR_MC13XXX_CORE |
436 | tristate | 428 | tristate |
437 | 429 | ||
@@ -451,6 +443,15 @@ config REGULATOR_MC13892 | |||
451 | Say y here to support the regulators found on the Freescale MC13892 | 443 | Say y here to support the regulators found on the Freescale MC13892 |
452 | PMIC. | 444 | PMIC. |
453 | 445 | ||
446 | config REGULATOR_MT6311 | ||
447 | tristate "MediaTek MT6311 PMIC" | ||
448 | depends on I2C | ||
449 | help | ||
450 | Say y here to select this option to enable the power regulator of | ||
451 | MediaTek MT6311 PMIC. | ||
452 | This driver supports the control of different power rails of device | ||
453 | through regulator interface. | ||
454 | |||
454 | config REGULATOR_MT6397 | 455 | config REGULATOR_MT6397 |
455 | tristate "MediaTek MT6397 PMIC" | 456 | tristate "MediaTek MT6397 PMIC" |
456 | depends on MFD_MT6397 | 457 | depends on MFD_MT6397 |
@@ -522,6 +523,18 @@ config REGULATOR_QCOM_RPM | |||
522 | Qualcomm RPM as a module. The module will be named | 523 | Qualcomm RPM as a module. The module will be named |
523 | "qcom_rpm-regulator". | 524 | "qcom_rpm-regulator". |
524 | 525 | ||
526 | config REGULATOR_QCOM_SMD_RPM | ||
527 | tristate "Qualcomm SMD based RPM regulator driver" | ||
528 | depends on QCOM_SMD_RPM | ||
529 | help | ||
530 | If you say yes to this option, support will be included for the | ||
531 | regulators exposed by the Resource Power Manager found in Qualcomm | ||
532 | 8974 based devices. | ||
533 | |||
534 | Say M here if you want to include support for the regulators on the | ||
535 | Qualcomm RPM as a module. The module will be named | ||
536 | "qcom_smd-regulator". | ||
537 | |||
525 | config REGULATOR_QCOM_SPMI | 538 | config REGULATOR_QCOM_SPMI |
526 | tristate "Qualcomm SPMI regulator driver" | 539 | tristate "Qualcomm SPMI regulator driver" |
527 | depends on SPMI || COMPILE_TEST | 540 | depends on SPMI || COMPILE_TEST |
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 91bf76267404..0f8174913c17 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
@@ -56,12 +56,13 @@ obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o | |||
56 | obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o | 56 | obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o |
57 | obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o | 57 | obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o |
58 | obj-$(CONFIG_REGULATOR_MAX77802) += max77802.o | 58 | obj-$(CONFIG_REGULATOR_MAX77802) += max77802.o |
59 | obj-$(CONFIG_REGULATOR_MAX77843) += max77843.o | ||
60 | obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o | 59 | obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o |
61 | obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o | 60 | obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o |
62 | obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o | 61 | obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o |
62 | obj-$(CONFIG_REGULATOR_MT6311) += mt6311-regulator.o | ||
63 | obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o | 63 | obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o |
64 | obj-$(CONFIG_REGULATOR_QCOM_RPM) += qcom_rpm-regulator.o | 64 | obj-$(CONFIG_REGULATOR_QCOM_RPM) += qcom_rpm-regulator.o |
65 | obj-$(CONFIG_REGULATOR_QCOM_SMD_RPM) += qcom_smd-regulator.o | ||
65 | obj-$(CONFIG_REGULATOR_QCOM_SPMI) += qcom_spmi-regulator.o | 66 | obj-$(CONFIG_REGULATOR_QCOM_SPMI) += qcom_spmi-regulator.o |
66 | obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o | 67 | obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o |
67 | obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o | 68 | obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o |
diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c index 2ff73d72ca34..896db168e4bd 100644 --- a/drivers/regulator/act8865-regulator.c +++ b/drivers/regulator/act8865-regulator.c | |||
@@ -530,7 +530,6 @@ MODULE_DEVICE_TABLE(i2c, act8865_ids); | |||
530 | static struct i2c_driver act8865_pmic_driver = { | 530 | static struct i2c_driver act8865_pmic_driver = { |
531 | .driver = { | 531 | .driver = { |
532 | .name = "act8865", | 532 | .name = "act8865", |
533 | .owner = THIS_MODULE, | ||
534 | }, | 533 | }, |
535 | .probe = act8865_pmic_probe, | 534 | .probe = act8865_pmic_probe, |
536 | .id_table = act8865_ids, | 535 | .id_table = act8865_ids, |
diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c index 48016a050d5f..ea50a886ba63 100644 --- a/drivers/regulator/ad5398.c +++ b/drivers/regulator/ad5398.c | |||
@@ -275,4 +275,3 @@ module_exit(ad5398_exit); | |||
275 | MODULE_DESCRIPTION("AD5398 and AD5821 current regulator driver"); | 275 | MODULE_DESCRIPTION("AD5398 and AD5821 current regulator driver"); |
276 | MODULE_AUTHOR("Sonic Zhang"); | 276 | MODULE_AUTHOR("Sonic Zhang"); |
277 | MODULE_LICENSE("GPL"); | 277 | MODULE_LICENSE("GPL"); |
278 | MODULE_ALIAS("i2c:ad5398-regulator"); | ||
diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c index 646829132b59..01bf3476a791 100644 --- a/drivers/regulator/axp20x-regulator.c +++ b/drivers/regulator/axp20x-regulator.c | |||
@@ -405,3 +405,4 @@ module_platform_driver(axp20x_regulator_driver); | |||
405 | MODULE_LICENSE("GPL v2"); | 405 | MODULE_LICENSE("GPL v2"); |
406 | MODULE_AUTHOR("Carlo Caione <carlo@caione.org>"); | 406 | MODULE_AUTHOR("Carlo Caione <carlo@caione.org>"); |
407 | MODULE_DESCRIPTION("Regulator Driver for AXP20X PMIC"); | 407 | MODULE_DESCRIPTION("Regulator Driver for AXP20X PMIC"); |
408 | MODULE_ALIAS("platform:axp20x-regulator"); | ||
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 78387a6cbae5..de9f272a0faf 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -111,6 +111,11 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, | |||
111 | const char *supply_name); | 111 | const char *supply_name); |
112 | static void _regulator_put(struct regulator *regulator); | 112 | static void _regulator_put(struct regulator *regulator); |
113 | 113 | ||
114 | static struct regulator_dev *dev_to_rdev(struct device *dev) | ||
115 | { | ||
116 | return container_of(dev, struct regulator_dev, dev); | ||
117 | } | ||
118 | |||
114 | static const char *rdev_get_name(struct regulator_dev *rdev) | 119 | static const char *rdev_get_name(struct regulator_dev *rdev) |
115 | { | 120 | { |
116 | if (rdev->constraints && rdev->constraints->name) | 121 | if (rdev->constraints && rdev->constraints->name) |
@@ -296,7 +301,7 @@ static int regulator_check_drms(struct regulator_dev *rdev) | |||
296 | return -ENODEV; | 301 | return -ENODEV; |
297 | } | 302 | } |
298 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { | 303 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { |
299 | rdev_err(rdev, "operation not allowed\n"); | 304 | rdev_dbg(rdev, "operation not allowed\n"); |
300 | return -EPERM; | 305 | return -EPERM; |
301 | } | 306 | } |
302 | return 0; | 307 | return 0; |
@@ -641,6 +646,8 @@ static int drms_uA_update(struct regulator_dev *rdev) | |||
641 | int current_uA = 0, output_uV, input_uV, err; | 646 | int current_uA = 0, output_uV, input_uV, err; |
642 | unsigned int mode; | 647 | unsigned int mode; |
643 | 648 | ||
649 | lockdep_assert_held_once(&rdev->mutex); | ||
650 | |||
644 | /* | 651 | /* |
645 | * first check to see if we can set modes at all, otherwise just | 652 | * first check to see if we can set modes at all, otherwise just |
646 | * tell the consumer everything is OK. | 653 | * tell the consumer everything is OK. |
@@ -761,6 +768,8 @@ static int suspend_set_state(struct regulator_dev *rdev, | |||
761 | /* locks held by caller */ | 768 | /* locks held by caller */ |
762 | static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state) | 769 | static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state) |
763 | { | 770 | { |
771 | lockdep_assert_held_once(&rdev->mutex); | ||
772 | |||
764 | if (!rdev->constraints) | 773 | if (!rdev->constraints) |
765 | return -EINVAL; | 774 | return -EINVAL; |
766 | 775 | ||
@@ -1082,6 +1091,15 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
1082 | } | 1091 | } |
1083 | } | 1092 | } |
1084 | 1093 | ||
1094 | if (rdev->constraints->over_current_protection | ||
1095 | && ops->set_over_current_protection) { | ||
1096 | ret = ops->set_over_current_protection(rdev); | ||
1097 | if (ret < 0) { | ||
1098 | rdev_err(rdev, "failed to set over current protection\n"); | ||
1099 | goto out; | ||
1100 | } | ||
1101 | } | ||
1102 | |||
1085 | print_constraints(rdev); | 1103 | print_constraints(rdev); |
1086 | return 0; | 1104 | return 0; |
1087 | out: | 1105 | out: |
@@ -1595,9 +1613,11 @@ static void _regulator_put(struct regulator *regulator) | |||
1595 | { | 1613 | { |
1596 | struct regulator_dev *rdev; | 1614 | struct regulator_dev *rdev; |
1597 | 1615 | ||
1598 | if (regulator == NULL || IS_ERR(regulator)) | 1616 | if (IS_ERR_OR_NULL(regulator)) |
1599 | return; | 1617 | return; |
1600 | 1618 | ||
1619 | lockdep_assert_held_once(®ulator_list_mutex); | ||
1620 | |||
1601 | rdev = regulator->rdev; | 1621 | rdev = regulator->rdev; |
1602 | 1622 | ||
1603 | debugfs_remove_recursive(regulator->debugfs); | 1623 | debugfs_remove_recursive(regulator->debugfs); |
@@ -1606,14 +1626,15 @@ static void _regulator_put(struct regulator *regulator) | |||
1606 | if (regulator->dev) | 1626 | if (regulator->dev) |
1607 | sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); | 1627 | sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); |
1608 | mutex_lock(&rdev->mutex); | 1628 | mutex_lock(&rdev->mutex); |
1609 | kfree(regulator->supply_name); | ||
1610 | list_del(®ulator->list); | 1629 | list_del(®ulator->list); |
1611 | kfree(regulator); | ||
1612 | 1630 | ||
1613 | rdev->open_count--; | 1631 | rdev->open_count--; |
1614 | rdev->exclusive = 0; | 1632 | rdev->exclusive = 0; |
1615 | mutex_unlock(&rdev->mutex); | 1633 | mutex_unlock(&rdev->mutex); |
1616 | 1634 | ||
1635 | kfree(regulator->supply_name); | ||
1636 | kfree(regulator); | ||
1637 | |||
1617 | module_put(rdev->owner); | 1638 | module_put(rdev->owner); |
1618 | } | 1639 | } |
1619 | 1640 | ||
@@ -1976,6 +1997,8 @@ static int _regulator_enable(struct regulator_dev *rdev) | |||
1976 | { | 1997 | { |
1977 | int ret; | 1998 | int ret; |
1978 | 1999 | ||
2000 | lockdep_assert_held_once(&rdev->mutex); | ||
2001 | |||
1979 | /* check voltage and requested load before enabling */ | 2002 | /* check voltage and requested load before enabling */ |
1980 | if (rdev->constraints && | 2003 | if (rdev->constraints && |
1981 | (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) | 2004 | (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) |
@@ -2076,6 +2099,8 @@ static int _regulator_disable(struct regulator_dev *rdev) | |||
2076 | { | 2099 | { |
2077 | int ret = 0; | 2100 | int ret = 0; |
2078 | 2101 | ||
2102 | lockdep_assert_held_once(&rdev->mutex); | ||
2103 | |||
2079 | if (WARN(rdev->use_count <= 0, | 2104 | if (WARN(rdev->use_count <= 0, |
2080 | "unbalanced disables for %s\n", rdev_get_name(rdev))) | 2105 | "unbalanced disables for %s\n", rdev_get_name(rdev))) |
2081 | return -EIO; | 2106 | return -EIO; |
@@ -2154,6 +2179,8 @@ static int _regulator_force_disable(struct regulator_dev *rdev) | |||
2154 | { | 2179 | { |
2155 | int ret = 0; | 2180 | int ret = 0; |
2156 | 2181 | ||
2182 | lockdep_assert_held_once(&rdev->mutex); | ||
2183 | |||
2157 | ret = _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | | 2184 | ret = _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | |
2158 | REGULATOR_EVENT_PRE_DISABLE, NULL); | 2185 | REGULATOR_EVENT_PRE_DISABLE, NULL); |
2159 | if (ret & NOTIFY_STOP_MASK) | 2186 | if (ret & NOTIFY_STOP_MASK) |
@@ -2722,7 +2749,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) | |||
2722 | goto out; | 2749 | goto out; |
2723 | 2750 | ||
2724 | /* If we're trying to set a range that overlaps the current voltage, | 2751 | /* If we're trying to set a range that overlaps the current voltage, |
2725 | * return succesfully even though the regulator does not support | 2752 | * return successfully even though the regulator does not support |
2726 | * changing the voltage. | 2753 | * changing the voltage. |
2727 | */ | 2754 | */ |
2728 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { | 2755 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { |
@@ -3450,6 +3477,8 @@ EXPORT_SYMBOL_GPL(regulator_bulk_free); | |||
3450 | int regulator_notifier_call_chain(struct regulator_dev *rdev, | 3477 | int regulator_notifier_call_chain(struct regulator_dev *rdev, |
3451 | unsigned long event, void *data) | 3478 | unsigned long event, void *data) |
3452 | { | 3479 | { |
3480 | lockdep_assert_held_once(&rdev->mutex); | ||
3481 | |||
3453 | _notifier_call_chain(rdev, event, data); | 3482 | _notifier_call_chain(rdev, event, data); |
3454 | return NOTIFY_DONE; | 3483 | return NOTIFY_DONE; |
3455 | 3484 | ||
@@ -3594,6 +3623,9 @@ static const struct attribute_group *regulator_dev_groups[] = { | |||
3594 | static void regulator_dev_release(struct device *dev) | 3623 | static void regulator_dev_release(struct device *dev) |
3595 | { | 3624 | { |
3596 | struct regulator_dev *rdev = dev_get_drvdata(dev); | 3625 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
3626 | |||
3627 | kfree(rdev->constraints); | ||
3628 | of_node_put(rdev->dev.of_node); | ||
3597 | kfree(rdev); | 3629 | kfree(rdev); |
3598 | } | 3630 | } |
3599 | 3631 | ||
@@ -3824,11 +3856,9 @@ void regulator_unregister(struct regulator_dev *rdev) | |||
3824 | WARN_ON(rdev->open_count); | 3856 | WARN_ON(rdev->open_count); |
3825 | unset_regulator_supplies(rdev); | 3857 | unset_regulator_supplies(rdev); |
3826 | list_del(&rdev->list); | 3858 | list_del(&rdev->list); |
3827 | kfree(rdev->constraints); | 3859 | mutex_unlock(®ulator_list_mutex); |
3828 | regulator_ena_gpio_free(rdev); | 3860 | regulator_ena_gpio_free(rdev); |
3829 | of_node_put(rdev->dev.of_node); | ||
3830 | device_unregister(&rdev->dev); | 3861 | device_unregister(&rdev->dev); |
3831 | mutex_unlock(®ulator_list_mutex); | ||
3832 | } | 3862 | } |
3833 | EXPORT_SYMBOL_GPL(regulator_unregister); | 3863 | EXPORT_SYMBOL_GPL(regulator_unregister); |
3834 | 3864 | ||
@@ -4147,13 +4177,57 @@ static int __init regulator_init(void) | |||
4147 | /* init early to allow our consumers to complete system booting */ | 4177 | /* init early to allow our consumers to complete system booting */ |
4148 | core_initcall(regulator_init); | 4178 | core_initcall(regulator_init); |
4149 | 4179 | ||
4150 | static int __init regulator_init_complete(void) | 4180 | static int __init regulator_late_cleanup(struct device *dev, void *data) |
4151 | { | 4181 | { |
4152 | struct regulator_dev *rdev; | 4182 | struct regulator_dev *rdev = dev_to_rdev(dev); |
4153 | const struct regulator_ops *ops; | 4183 | const struct regulator_ops *ops = rdev->desc->ops; |
4154 | struct regulation_constraints *c; | 4184 | struct regulation_constraints *c = rdev->constraints; |
4155 | int enabled, ret; | 4185 | int enabled, ret; |
4156 | 4186 | ||
4187 | if (c && c->always_on) | ||
4188 | return 0; | ||
4189 | |||
4190 | if (c && !(c->valid_ops_mask & REGULATOR_CHANGE_STATUS)) | ||
4191 | return 0; | ||
4192 | |||
4193 | mutex_lock(&rdev->mutex); | ||
4194 | |||
4195 | if (rdev->use_count) | ||
4196 | goto unlock; | ||
4197 | |||
4198 | /* If we can't read the status assume it's on. */ | ||
4199 | if (ops->is_enabled) | ||
4200 | enabled = ops->is_enabled(rdev); | ||
4201 | else | ||
4202 | enabled = 1; | ||
4203 | |||
4204 | if (!enabled) | ||
4205 | goto unlock; | ||
4206 | |||
4207 | if (have_full_constraints()) { | ||
4208 | /* We log since this may kill the system if it goes | ||
4209 | * wrong. */ | ||
4210 | rdev_info(rdev, "disabling\n"); | ||
4211 | ret = _regulator_do_disable(rdev); | ||
4212 | if (ret != 0) | ||
4213 | rdev_err(rdev, "couldn't disable: %d\n", ret); | ||
4214 | } else { | ||
4215 | /* The intention is that in future we will | ||
4216 | * assume that full constraints are provided | ||
4217 | * so warn even if we aren't going to do | ||
4218 | * anything here. | ||
4219 | */ | ||
4220 | rdev_warn(rdev, "incomplete constraints, leaving on\n"); | ||
4221 | } | ||
4222 | |||
4223 | unlock: | ||
4224 | mutex_unlock(&rdev->mutex); | ||
4225 | |||
4226 | return 0; | ||
4227 | } | ||
4228 | |||
4229 | static int __init regulator_init_complete(void) | ||
4230 | { | ||
4157 | /* | 4231 | /* |
4158 | * Since DT doesn't provide an idiomatic mechanism for | 4232 | * Since DT doesn't provide an idiomatic mechanism for |
4159 | * enabling full constraints and since it's much more natural | 4233 | * enabling full constraints and since it's much more natural |
@@ -4163,58 +4237,13 @@ static int __init regulator_init_complete(void) | |||
4163 | if (of_have_populated_dt()) | 4237 | if (of_have_populated_dt()) |
4164 | has_full_constraints = true; | 4238 | has_full_constraints = true; |
4165 | 4239 | ||
4166 | mutex_lock(®ulator_list_mutex); | ||
4167 | |||
4168 | /* If we have a full configuration then disable any regulators | 4240 | /* If we have a full configuration then disable any regulators |
4169 | * we have permission to change the status for and which are | 4241 | * we have permission to change the status for and which are |
4170 | * not in use or always_on. This is effectively the default | 4242 | * not in use or always_on. This is effectively the default |
4171 | * for DT and ACPI as they have full constraints. | 4243 | * for DT and ACPI as they have full constraints. |
4172 | */ | 4244 | */ |
4173 | list_for_each_entry(rdev, ®ulator_list, list) { | 4245 | class_for_each_device(®ulator_class, NULL, NULL, |
4174 | ops = rdev->desc->ops; | 4246 | regulator_late_cleanup); |
4175 | c = rdev->constraints; | ||
4176 | |||
4177 | if (c && c->always_on) | ||
4178 | continue; | ||
4179 | |||
4180 | if (c && !(c->valid_ops_mask & REGULATOR_CHANGE_STATUS)) | ||
4181 | continue; | ||
4182 | |||
4183 | mutex_lock(&rdev->mutex); | ||
4184 | |||
4185 | if (rdev->use_count) | ||
4186 | goto unlock; | ||
4187 | |||
4188 | /* If we can't read the status assume it's on. */ | ||
4189 | if (ops->is_enabled) | ||
4190 | enabled = ops->is_enabled(rdev); | ||
4191 | else | ||
4192 | enabled = 1; | ||
4193 | |||
4194 | if (!enabled) | ||
4195 | goto unlock; | ||
4196 | |||
4197 | if (have_full_constraints()) { | ||
4198 | /* We log since this may kill the system if it | ||
4199 | * goes wrong. */ | ||
4200 | rdev_info(rdev, "disabling\n"); | ||
4201 | ret = _regulator_do_disable(rdev); | ||
4202 | if (ret != 0) | ||
4203 | rdev_err(rdev, "couldn't disable: %d\n", ret); | ||
4204 | } else { | ||
4205 | /* The intention is that in future we will | ||
4206 | * assume that full constraints are provided | ||
4207 | * so warn even if we aren't going to do | ||
4208 | * anything here. | ||
4209 | */ | ||
4210 | rdev_warn(rdev, "incomplete constraints, leaving on\n"); | ||
4211 | } | ||
4212 | |||
4213 | unlock: | ||
4214 | mutex_unlock(&rdev->mutex); | ||
4215 | } | ||
4216 | |||
4217 | mutex_unlock(®ulator_list_mutex); | ||
4218 | 4247 | ||
4219 | return 0; | 4248 | return 0; |
4220 | } | 4249 | } |
diff --git a/drivers/regulator/da9062-regulator.c b/drivers/regulator/da9062-regulator.c index dd76da09b3c7..5638fe8d759d 100644 --- a/drivers/regulator/da9062-regulator.c +++ b/drivers/regulator/da9062-regulator.c | |||
@@ -818,7 +818,6 @@ static int da9062_regulator_probe(struct platform_device *pdev) | |||
818 | static struct platform_driver da9062_regulator_driver = { | 818 | static struct platform_driver da9062_regulator_driver = { |
819 | .driver = { | 819 | .driver = { |
820 | .name = "da9062-regulators", | 820 | .name = "da9062-regulators", |
821 | .owner = THIS_MODULE, | ||
822 | }, | 821 | }, |
823 | .probe = da9062_regulator_probe, | 822 | .probe = da9062_regulator_probe, |
824 | }; | 823 | }; |
diff --git a/drivers/regulator/da9210-regulator.c b/drivers/regulator/da9210-regulator.c index f0489cb9018b..b3517830edb6 100644 --- a/drivers/regulator/da9210-regulator.c +++ b/drivers/regulator/da9210-regulator.c | |||
@@ -22,6 +22,8 @@ | |||
22 | #include <linux/i2c.h> | 22 | #include <linux/i2c.h> |
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/init.h> | 24 | #include <linux/init.h> |
25 | #include <linux/interrupt.h> | ||
26 | #include <linux/irq.h> | ||
25 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
26 | #include <linux/regulator/driver.h> | 28 | #include <linux/regulator/driver.h> |
27 | #include <linux/regulator/machine.h> | 29 | #include <linux/regulator/machine.h> |
@@ -120,6 +122,55 @@ static int da9210_get_current_limit(struct regulator_dev *rdev) | |||
120 | return da9210_buck_limits[sel]; | 122 | return da9210_buck_limits[sel]; |
121 | } | 123 | } |
122 | 124 | ||
125 | static irqreturn_t da9210_irq_handler(int irq, void *data) | ||
126 | { | ||
127 | struct da9210 *chip = data; | ||
128 | unsigned int val, handled = 0; | ||
129 | int error, ret = IRQ_NONE; | ||
130 | |||
131 | error = regmap_read(chip->regmap, DA9210_REG_EVENT_B, &val); | ||
132 | if (error < 0) | ||
133 | goto error_i2c; | ||
134 | |||
135 | if (val & DA9210_E_OVCURR) { | ||
136 | regulator_notifier_call_chain(chip->rdev, | ||
137 | REGULATOR_EVENT_OVER_CURRENT, | ||
138 | NULL); | ||
139 | handled |= DA9210_E_OVCURR; | ||
140 | } | ||
141 | if (val & DA9210_E_NPWRGOOD) { | ||
142 | regulator_notifier_call_chain(chip->rdev, | ||
143 | REGULATOR_EVENT_UNDER_VOLTAGE, | ||
144 | NULL); | ||
145 | handled |= DA9210_E_NPWRGOOD; | ||
146 | } | ||
147 | if (val & (DA9210_E_TEMP_WARN | DA9210_E_TEMP_CRIT)) { | ||
148 | regulator_notifier_call_chain(chip->rdev, | ||
149 | REGULATOR_EVENT_OVER_TEMP, NULL); | ||
150 | handled |= val & (DA9210_E_TEMP_WARN | DA9210_E_TEMP_CRIT); | ||
151 | } | ||
152 | if (val & DA9210_E_VMAX) { | ||
153 | regulator_notifier_call_chain(chip->rdev, | ||
154 | REGULATOR_EVENT_REGULATION_OUT, | ||
155 | NULL); | ||
156 | handled |= DA9210_E_VMAX; | ||
157 | } | ||
158 | if (handled) { | ||
159 | /* Clear handled events */ | ||
160 | error = regmap_write(chip->regmap, DA9210_REG_EVENT_B, handled); | ||
161 | if (error < 0) | ||
162 | goto error_i2c; | ||
163 | |||
164 | ret = IRQ_HANDLED; | ||
165 | } | ||
166 | |||
167 | return ret; | ||
168 | |||
169 | error_i2c: | ||
170 | dev_err(regmap_get_device(chip->regmap), "I2C error : %d\n", error); | ||
171 | return ret; | ||
172 | } | ||
173 | |||
123 | /* | 174 | /* |
124 | * I2C driver interface functions | 175 | * I2C driver interface functions |
125 | */ | 176 | */ |
@@ -168,6 +219,30 @@ static int da9210_i2c_probe(struct i2c_client *i2c, | |||
168 | } | 219 | } |
169 | 220 | ||
170 | chip->rdev = rdev; | 221 | chip->rdev = rdev; |
222 | if (i2c->irq) { | ||
223 | error = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, | ||
224 | da9210_irq_handler, | ||
225 | IRQF_TRIGGER_LOW | | ||
226 | IRQF_ONESHOT | IRQF_SHARED, | ||
227 | "da9210", chip); | ||
228 | if (error) { | ||
229 | dev_err(&i2c->dev, "Failed to request IRQ%u: %d\n", | ||
230 | i2c->irq, error); | ||
231 | return error; | ||
232 | } | ||
233 | |||
234 | error = regmap_update_bits(chip->regmap, DA9210_REG_MASK_B, | ||
235 | DA9210_M_OVCURR | DA9210_M_NPWRGOOD | | ||
236 | DA9210_M_TEMP_WARN | | ||
237 | DA9210_M_TEMP_CRIT | DA9210_M_VMAX, 0); | ||
238 | if (error < 0) { | ||
239 | dev_err(&i2c->dev, "Failed to update mask reg: %d\n", | ||
240 | error); | ||
241 | return error; | ||
242 | } | ||
243 | } else { | ||
244 | dev_warn(&i2c->dev, "No IRQ configured\n"); | ||
245 | } | ||
171 | 246 | ||
172 | i2c_set_clientdata(i2c, chip); | 247 | i2c_set_clientdata(i2c, chip); |
173 | 248 | ||
@@ -184,7 +259,6 @@ MODULE_DEVICE_TABLE(i2c, da9210_i2c_id); | |||
184 | static struct i2c_driver da9210_regulator_driver = { | 259 | static struct i2c_driver da9210_regulator_driver = { |
185 | .driver = { | 260 | .driver = { |
186 | .name = "da9210", | 261 | .name = "da9210", |
187 | .owner = THIS_MODULE, | ||
188 | }, | 262 | }, |
189 | .probe = da9210_i2c_probe, | 263 | .probe = da9210_i2c_probe, |
190 | .id_table = da9210_i2c_id, | 264 | .id_table = da9210_i2c_id, |
diff --git a/drivers/regulator/da9211-regulator.c b/drivers/regulator/da9211-regulator.c index df79e4b1946e..04ef65b7eb3d 100644 --- a/drivers/regulator/da9211-regulator.c +++ b/drivers/regulator/da9211-regulator.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * da9211-regulator.c - Regulator device driver for DA9211/DA9213 | 2 | * da9211-regulator.c - Regulator device driver for DA9211/DA9213/DA9215 |
3 | * Copyright (C) 2014 Dialog Semiconductor Ltd. | 3 | * Copyright (C) 2015 Dialog Semiconductor Ltd. |
4 | * | 4 | * |
5 | * This library is free software; you can redistribute it and/or | 5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public | 6 | * modify it under the terms of the GNU Library General Public |
@@ -32,6 +32,7 @@ | |||
32 | /* DEVICE IDs */ | 32 | /* DEVICE IDs */ |
33 | #define DA9211_DEVICE_ID 0x22 | 33 | #define DA9211_DEVICE_ID 0x22 |
34 | #define DA9213_DEVICE_ID 0x23 | 34 | #define DA9213_DEVICE_ID 0x23 |
35 | #define DA9215_DEVICE_ID 0x24 | ||
35 | 36 | ||
36 | #define DA9211_BUCK_MODE_SLEEP 1 | 37 | #define DA9211_BUCK_MODE_SLEEP 1 |
37 | #define DA9211_BUCK_MODE_SYNC 2 | 38 | #define DA9211_BUCK_MODE_SYNC 2 |
@@ -90,6 +91,13 @@ static const int da9213_current_limits[] = { | |||
90 | 3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000, | 91 | 3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000, |
91 | 4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000 | 92 | 4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000 |
92 | }; | 93 | }; |
94 | /* Current limits for DA9215 buck (uA) indices | ||
95 | * corresponds with register values | ||
96 | */ | ||
97 | static const int da9215_current_limits[] = { | ||
98 | 4000000, 4200000, 4400000, 4600000, 4800000, 5000000, 5200000, 5400000, | ||
99 | 5600000, 5800000, 6000000, 6200000, 6400000, 6600000, 6800000, 7000000 | ||
100 | }; | ||
93 | 101 | ||
94 | static unsigned int da9211_buck_get_mode(struct regulator_dev *rdev) | 102 | static unsigned int da9211_buck_get_mode(struct regulator_dev *rdev) |
95 | { | 103 | { |
@@ -157,6 +165,10 @@ static int da9211_set_current_limit(struct regulator_dev *rdev, int min, | |||
157 | current_limits = da9213_current_limits; | 165 | current_limits = da9213_current_limits; |
158 | max_size = ARRAY_SIZE(da9213_current_limits)-1; | 166 | max_size = ARRAY_SIZE(da9213_current_limits)-1; |
159 | break; | 167 | break; |
168 | case DA9215: | ||
169 | current_limits = da9215_current_limits; | ||
170 | max_size = ARRAY_SIZE(da9215_current_limits)-1; | ||
171 | break; | ||
160 | default: | 172 | default: |
161 | return -EINVAL; | 173 | return -EINVAL; |
162 | } | 174 | } |
@@ -189,6 +201,9 @@ static int da9211_get_current_limit(struct regulator_dev *rdev) | |||
189 | case DA9213: | 201 | case DA9213: |
190 | current_limits = da9213_current_limits; | 202 | current_limits = da9213_current_limits; |
191 | break; | 203 | break; |
204 | case DA9215: | ||
205 | current_limits = da9215_current_limits; | ||
206 | break; | ||
192 | default: | 207 | default: |
193 | return -EINVAL; | 208 | return -EINVAL; |
194 | } | 209 | } |
@@ -350,13 +365,11 @@ static int da9211_regulator_init(struct da9211 *chip) | |||
350 | /* If configuration for 1/2 bucks is different between platform data | 365 | /* If configuration for 1/2 bucks is different between platform data |
351 | * and the register, driver should exit. | 366 | * and the register, driver should exit. |
352 | */ | 367 | */ |
353 | if ((chip->pdata->num_buck == 2 && data == 0x40) | 368 | if (chip->pdata->num_buck == 1 && data == 0x00) |
354 | || (chip->pdata->num_buck == 1 && data == 0x00)) { | 369 | chip->num_regulator = 1; |
355 | if (data == 0) | 370 | else if (chip->pdata->num_buck == 2 && data != 0x00) |
356 | chip->num_regulator = 1; | 371 | chip->num_regulator = 2; |
357 | else | 372 | else { |
358 | chip->num_regulator = 2; | ||
359 | } else { | ||
360 | dev_err(chip->dev, "Configuration is mismatched\n"); | 373 | dev_err(chip->dev, "Configuration is mismatched\n"); |
361 | return -EINVAL; | 374 | return -EINVAL; |
362 | } | 375 | } |
@@ -438,6 +451,9 @@ static int da9211_i2c_probe(struct i2c_client *i2c, | |||
438 | case DA9213_DEVICE_ID: | 451 | case DA9213_DEVICE_ID: |
439 | chip->chip_id = DA9213; | 452 | chip->chip_id = DA9213; |
440 | break; | 453 | break; |
454 | case DA9215_DEVICE_ID: | ||
455 | chip->chip_id = DA9215; | ||
456 | break; | ||
441 | default: | 457 | default: |
442 | dev_err(chip->dev, "Unsupported device id = 0x%x.\n", data); | 458 | dev_err(chip->dev, "Unsupported device id = 0x%x.\n", data); |
443 | return -ENODEV; | 459 | return -ENODEV; |
@@ -478,6 +494,7 @@ static int da9211_i2c_probe(struct i2c_client *i2c, | |||
478 | static const struct i2c_device_id da9211_i2c_id[] = { | 494 | static const struct i2c_device_id da9211_i2c_id[] = { |
479 | {"da9211", DA9211}, | 495 | {"da9211", DA9211}, |
480 | {"da9213", DA9213}, | 496 | {"da9213", DA9213}, |
497 | {"da9215", DA9215}, | ||
481 | {}, | 498 | {}, |
482 | }; | 499 | }; |
483 | MODULE_DEVICE_TABLE(i2c, da9211_i2c_id); | 500 | MODULE_DEVICE_TABLE(i2c, da9211_i2c_id); |
@@ -486,6 +503,7 @@ MODULE_DEVICE_TABLE(i2c, da9211_i2c_id); | |||
486 | static const struct of_device_id da9211_dt_ids[] = { | 503 | static const struct of_device_id da9211_dt_ids[] = { |
487 | { .compatible = "dlg,da9211", .data = &da9211_i2c_id[0] }, | 504 | { .compatible = "dlg,da9211", .data = &da9211_i2c_id[0] }, |
488 | { .compatible = "dlg,da9213", .data = &da9211_i2c_id[1] }, | 505 | { .compatible = "dlg,da9213", .data = &da9211_i2c_id[1] }, |
506 | { .compatible = "dlg,da9215", .data = &da9211_i2c_id[2] }, | ||
489 | {}, | 507 | {}, |
490 | }; | 508 | }; |
491 | MODULE_DEVICE_TABLE(of, da9211_dt_ids); | 509 | MODULE_DEVICE_TABLE(of, da9211_dt_ids); |
@@ -494,7 +512,6 @@ MODULE_DEVICE_TABLE(of, da9211_dt_ids); | |||
494 | static struct i2c_driver da9211_regulator_driver = { | 512 | static struct i2c_driver da9211_regulator_driver = { |
495 | .driver = { | 513 | .driver = { |
496 | .name = "da9211", | 514 | .name = "da9211", |
497 | .owner = THIS_MODULE, | ||
498 | .of_match_table = of_match_ptr(da9211_dt_ids), | 515 | .of_match_table = of_match_ptr(da9211_dt_ids), |
499 | }, | 516 | }, |
500 | .probe = da9211_i2c_probe, | 517 | .probe = da9211_i2c_probe, |
@@ -504,5 +521,5 @@ static struct i2c_driver da9211_regulator_driver = { | |||
504 | module_i2c_driver(da9211_regulator_driver); | 521 | module_i2c_driver(da9211_regulator_driver); |
505 | 522 | ||
506 | MODULE_AUTHOR("James Ban <James.Ban.opensource@diasemi.com>"); | 523 | MODULE_AUTHOR("James Ban <James.Ban.opensource@diasemi.com>"); |
507 | MODULE_DESCRIPTION("Regulator device driver for Dialog DA9211/DA9213"); | 524 | MODULE_DESCRIPTION("Regulator device driver for Dialog DA9211/DA9213/DA9215"); |
508 | MODULE_LICENSE("GPL v2"); | 525 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/regulator/da9211-regulator.h b/drivers/regulator/da9211-regulator.h index 93fa9df2721c..d6ad96fc64d3 100644 --- a/drivers/regulator/da9211-regulator.h +++ b/drivers/regulator/da9211-regulator.h | |||
@@ -1,16 +1,16 @@ | |||
1 | /* | 1 | /* |
2 | * da9211-regulator.h - Regulator definitions for DA9211/DA9213 | 2 | * da9211-regulator.h - Regulator definitions for DA9211/DA9213/DA9215 |
3 | * Copyright (C) 2014 Dialog Semiconductor Ltd. | 3 | * Copyright (C) 2015 Dialog Semiconductor Ltd. |
4 | * | 4 | * |
5 | * This library is free software; you can redistribute it and/or | 5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public | 6 | * modify it under the terms of the GNU General Public License |
7 | * License as published by the Free Software Foundation; either | 7 | * as published by the Free Software Foundation; either version 2 |
8 | * version 2 of the License, or (at your option) any later version. | 8 | * of the License, or (at your option) any later version. |
9 | * | 9 | * |
10 | * This library is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * Library General Public License for more details. | 13 | * GNU General Public License for more details. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #ifndef __DA9211_REGISTERS_H__ | 16 | #ifndef __DA9211_REGISTERS_H__ |
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c index 42865681c00b..4940e8287df6 100644 --- a/drivers/regulator/fan53555.c +++ b/drivers/regulator/fan53555.c | |||
@@ -439,6 +439,7 @@ static const struct i2c_device_id fan53555_id[] = { | |||
439 | }, | 439 | }, |
440 | { }, | 440 | { }, |
441 | }; | 441 | }; |
442 | MODULE_DEVICE_TABLE(i2c, fan53555_id); | ||
442 | 443 | ||
443 | static struct i2c_driver fan53555_regulator_driver = { | 444 | static struct i2c_driver fan53555_regulator_driver = { |
444 | .driver = { | 445 | .driver = { |
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c index 6e5da95fa025..4abd8e9c81e5 100644 --- a/drivers/regulator/isl6271a-regulator.c +++ b/drivers/regulator/isl6271a-regulator.c | |||
@@ -156,7 +156,6 @@ MODULE_DEVICE_TABLE(i2c, isl6271a_id); | |||
156 | static struct i2c_driver isl6271a_i2c_driver = { | 156 | static struct i2c_driver isl6271a_i2c_driver = { |
157 | .driver = { | 157 | .driver = { |
158 | .name = "isl6271a", | 158 | .name = "isl6271a", |
159 | .owner = THIS_MODULE, | ||
160 | }, | 159 | }, |
161 | .probe = isl6271a_probe, | 160 | .probe = isl6271a_probe, |
162 | .id_table = isl6271a_id, | 161 | .id_table = isl6271a_id, |
diff --git a/drivers/regulator/isl9305.c b/drivers/regulator/isl9305.c index 6e3a15fe00f1..257c1943e753 100644 --- a/drivers/regulator/isl9305.c +++ b/drivers/regulator/isl9305.c | |||
@@ -183,6 +183,7 @@ static const struct of_device_id isl9305_dt_ids[] = { | |||
183 | { .compatible = "isil,isl9305h" }, | 183 | { .compatible = "isil,isl9305h" }, |
184 | {}, | 184 | {}, |
185 | }; | 185 | }; |
186 | MODULE_DEVICE_TABLE(of, isl9305_dt_ids); | ||
186 | #endif | 187 | #endif |
187 | 188 | ||
188 | static const struct i2c_device_id isl9305_i2c_id[] = { | 189 | static const struct i2c_device_id isl9305_i2c_id[] = { |
@@ -195,7 +196,6 @@ MODULE_DEVICE_TABLE(i2c, isl9305_i2c_id); | |||
195 | static struct i2c_driver isl9305_regulator_driver = { | 196 | static struct i2c_driver isl9305_regulator_driver = { |
196 | .driver = { | 197 | .driver = { |
197 | .name = "isl9305", | 198 | .name = "isl9305", |
198 | .owner = THIS_MODULE, | ||
199 | .of_match_table = of_match_ptr(isl9305_dt_ids), | 199 | .of_match_table = of_match_ptr(isl9305_dt_ids), |
200 | }, | 200 | }, |
201 | .probe = isl9305_i2c_probe, | 201 | .probe = isl9305_i2c_probe, |
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c index 66fd2330dca0..15c25c622edf 100644 --- a/drivers/regulator/lp3971.c +++ b/drivers/regulator/lp3971.c | |||
@@ -452,7 +452,6 @@ MODULE_DEVICE_TABLE(i2c, lp3971_i2c_id); | |||
452 | static struct i2c_driver lp3971_i2c_driver = { | 452 | static struct i2c_driver lp3971_i2c_driver = { |
453 | .driver = { | 453 | .driver = { |
454 | .name = "LP3971", | 454 | .name = "LP3971", |
455 | .owner = THIS_MODULE, | ||
456 | }, | 455 | }, |
457 | .probe = lp3971_i2c_probe, | 456 | .probe = lp3971_i2c_probe, |
458 | .id_table = lp3971_i2c_id, | 457 | .id_table = lp3971_i2c_id, |
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c index aea485afcc1a..3a7e96e2c7b3 100644 --- a/drivers/regulator/lp3972.c +++ b/drivers/regulator/lp3972.c | |||
@@ -550,7 +550,6 @@ MODULE_DEVICE_TABLE(i2c, lp3972_i2c_id); | |||
550 | static struct i2c_driver lp3972_i2c_driver = { | 550 | static struct i2c_driver lp3972_i2c_driver = { |
551 | .driver = { | 551 | .driver = { |
552 | .name = "lp3972", | 552 | .name = "lp3972", |
553 | .owner = THIS_MODULE, | ||
554 | }, | 553 | }, |
555 | .probe = lp3972_i2c_probe, | 554 | .probe = lp3972_i2c_probe, |
556 | .id_table = lp3972_i2c_id, | 555 | .id_table = lp3972_i2c_id, |
diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c index 3de328ab41f3..e5af07208f9d 100644 --- a/drivers/regulator/lp872x.c +++ b/drivers/regulator/lp872x.c | |||
@@ -849,7 +849,7 @@ static struct lp872x_platform_data | |||
849 | 849 | ||
850 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | 850 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
851 | if (!pdata) | 851 | if (!pdata) |
852 | goto out; | 852 | return ERR_PTR(-ENOMEM); |
853 | 853 | ||
854 | of_property_read_u8(np, "ti,general-config", &pdata->general_config); | 854 | of_property_read_u8(np, "ti,general-config", &pdata->general_config); |
855 | if (of_find_property(np, "ti,update-config", NULL)) | 855 | if (of_find_property(np, "ti,update-config", NULL)) |
@@ -857,7 +857,7 @@ static struct lp872x_platform_data | |||
857 | 857 | ||
858 | pdata->dvs = devm_kzalloc(dev, sizeof(struct lp872x_dvs), GFP_KERNEL); | 858 | pdata->dvs = devm_kzalloc(dev, sizeof(struct lp872x_dvs), GFP_KERNEL); |
859 | if (!pdata->dvs) | 859 | if (!pdata->dvs) |
860 | goto out; | 860 | return ERR_PTR(-ENOMEM); |
861 | 861 | ||
862 | pdata->dvs->gpio = of_get_named_gpio(np, "ti,dvs-gpio", 0); | 862 | pdata->dvs->gpio = of_get_named_gpio(np, "ti,dvs-gpio", 0); |
863 | of_property_read_u8(np, "ti,dvs-vsel", (u8 *)&pdata->dvs->vsel); | 863 | of_property_read_u8(np, "ti,dvs-vsel", (u8 *)&pdata->dvs->vsel); |
@@ -903,15 +903,21 @@ static struct lp872x_platform_data | |||
903 | static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id) | 903 | static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id) |
904 | { | 904 | { |
905 | struct lp872x *lp; | 905 | struct lp872x *lp; |
906 | struct lp872x_platform_data *pdata; | ||
906 | int ret; | 907 | int ret; |
907 | const int lp872x_num_regulators[] = { | 908 | const int lp872x_num_regulators[] = { |
908 | [LP8720] = LP8720_NUM_REGULATORS, | 909 | [LP8720] = LP8720_NUM_REGULATORS, |
909 | [LP8725] = LP8725_NUM_REGULATORS, | 910 | [LP8725] = LP8725_NUM_REGULATORS, |
910 | }; | 911 | }; |
911 | 912 | ||
912 | if (cl->dev.of_node) | 913 | if (cl->dev.of_node) { |
913 | cl->dev.platform_data = lp872x_populate_pdata_from_dt(&cl->dev, | 914 | pdata = lp872x_populate_pdata_from_dt(&cl->dev, |
914 | (enum lp872x_id)id->driver_data); | 915 | (enum lp872x_id)id->driver_data); |
916 | if (IS_ERR(pdata)) | ||
917 | return PTR_ERR(pdata); | ||
918 | } else { | ||
919 | pdata = dev_get_platdata(&cl->dev); | ||
920 | } | ||
915 | 921 | ||
916 | lp = devm_kzalloc(&cl->dev, sizeof(struct lp872x), GFP_KERNEL); | 922 | lp = devm_kzalloc(&cl->dev, sizeof(struct lp872x), GFP_KERNEL); |
917 | if (!lp) | 923 | if (!lp) |
@@ -927,7 +933,7 @@ static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id) | |||
927 | } | 933 | } |
928 | 934 | ||
929 | lp->dev = &cl->dev; | 935 | lp->dev = &cl->dev; |
930 | lp->pdata = dev_get_platdata(&cl->dev); | 936 | lp->pdata = pdata; |
931 | lp->chipid = id->driver_data; | 937 | lp->chipid = id->driver_data; |
932 | i2c_set_clientdata(cl, lp); | 938 | i2c_set_clientdata(cl, lp); |
933 | 939 | ||
@@ -955,7 +961,6 @@ MODULE_DEVICE_TABLE(i2c, lp872x_ids); | |||
955 | static struct i2c_driver lp872x_driver = { | 961 | static struct i2c_driver lp872x_driver = { |
956 | .driver = { | 962 | .driver = { |
957 | .name = "lp872x", | 963 | .name = "lp872x", |
958 | .owner = THIS_MODULE, | ||
959 | .of_match_table = of_match_ptr(lp872x_dt_ids), | 964 | .of_match_table = of_match_ptr(lp872x_dt_ids), |
960 | }, | 965 | }, |
961 | .probe = lp872x_probe, | 966 | .probe = lp872x_probe, |
diff --git a/drivers/regulator/ltc3589.c b/drivers/regulator/ltc3589.c index 0ce8e4e0fa73..972c386b2690 100644 --- a/drivers/regulator/ltc3589.c +++ b/drivers/regulator/ltc3589.c | |||
@@ -378,7 +378,7 @@ static bool ltc3589_volatile_reg(struct device *dev, unsigned int reg) | |||
378 | return false; | 378 | return false; |
379 | } | 379 | } |
380 | 380 | ||
381 | static struct reg_default ltc3589_reg_defaults[] = { | 381 | static const struct reg_default ltc3589_reg_defaults[] = { |
382 | { LTC3589_SCR1, 0x00 }, | 382 | { LTC3589_SCR1, 0x00 }, |
383 | { LTC3589_OVEN, 0x00 }, | 383 | { LTC3589_OVEN, 0x00 }, |
384 | { LTC3589_SCR2, 0x00 }, | 384 | { LTC3589_SCR2, 0x00 }, |
@@ -542,7 +542,6 @@ MODULE_DEVICE_TABLE(i2c, ltc3589_i2c_id); | |||
542 | static struct i2c_driver ltc3589_driver = { | 542 | static struct i2c_driver ltc3589_driver = { |
543 | .driver = { | 543 | .driver = { |
544 | .name = DRIVER_NAME, | 544 | .name = DRIVER_NAME, |
545 | .owner = THIS_MODULE, | ||
546 | }, | 545 | }, |
547 | .probe = ltc3589_probe, | 546 | .probe = ltc3589_probe, |
548 | .id_table = ltc3589_i2c_id, | 547 | .id_table = ltc3589_i2c_id, |
@@ -552,4 +551,3 @@ module_i2c_driver(ltc3589_driver); | |||
552 | MODULE_AUTHOR("Philipp Zabel <p.zabel@pengutronix.de>"); | 551 | MODULE_AUTHOR("Philipp Zabel <p.zabel@pengutronix.de>"); |
553 | MODULE_DESCRIPTION("Regulator driver for Linear Technology LTC3589(-1,2)"); | 552 | MODULE_DESCRIPTION("Regulator driver for Linear Technology LTC3589(-1,2)"); |
554 | MODULE_LICENSE("GPL v2"); | 553 | MODULE_LICENSE("GPL v2"); |
555 | MODULE_ALIAS("i2c:ltc3589"); | ||
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c index d2a8c64cae42..2c1228d5796a 100644 --- a/drivers/regulator/max1586.c +++ b/drivers/regulator/max1586.c | |||
@@ -304,7 +304,6 @@ static struct i2c_driver max1586_pmic_driver = { | |||
304 | .probe = max1586_pmic_probe, | 304 | .probe = max1586_pmic_probe, |
305 | .driver = { | 305 | .driver = { |
306 | .name = "max1586", | 306 | .name = "max1586", |
307 | .owner = THIS_MODULE, | ||
308 | .of_match_table = of_match_ptr(max1586_of_match), | 307 | .of_match_table = of_match_ptr(max1586_of_match), |
309 | }, | 308 | }, |
310 | .id_table = max1586_id, | 309 | .id_table = max1586_id, |
diff --git a/drivers/regulator/max77693.c b/drivers/regulator/max77693.c index 38722c8311a5..de730fd3f8a5 100644 --- a/drivers/regulator/max77693.c +++ b/drivers/regulator/max77693.c | |||
@@ -1,8 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * max77693.c - Regulator driver for the Maxim 77693 | 2 | * max77693.c - Regulator driver for the Maxim 77693 and 77843 |
3 | * | 3 | * |
4 | * Copyright (C) 2013 Samsung Electronics | 4 | * Copyright (C) 2013-2015 Samsung Electronics |
5 | * Jonghwa Lee <jonghwa3.lee@samsung.com> | 5 | * Jonghwa Lee <jonghwa3.lee@samsung.com> |
6 | * Krzysztof Kozlowski <k.kozlowski.k@gmail.com> | ||
6 | * | 7 | * |
7 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
@@ -29,38 +30,64 @@ | |||
29 | #include <linux/regulator/driver.h> | 30 | #include <linux/regulator/driver.h> |
30 | #include <linux/regulator/machine.h> | 31 | #include <linux/regulator/machine.h> |
31 | #include <linux/mfd/max77693.h> | 32 | #include <linux/mfd/max77693.h> |
33 | #include <linux/mfd/max77693-common.h> | ||
32 | #include <linux/mfd/max77693-private.h> | 34 | #include <linux/mfd/max77693-private.h> |
35 | #include <linux/mfd/max77843-private.h> | ||
33 | #include <linux/regulator/of_regulator.h> | 36 | #include <linux/regulator/of_regulator.h> |
34 | #include <linux/regmap.h> | 37 | #include <linux/regmap.h> |
35 | 38 | ||
36 | #define CHGIN_ILIM_STEP_20mA 20000 | 39 | /* |
40 | * ID for MAX77843 regulators. | ||
41 | * There is no need for such for MAX77693. | ||
42 | */ | ||
43 | enum max77843_regulator_type { | ||
44 | MAX77843_SAFEOUT1 = 0, | ||
45 | MAX77843_SAFEOUT2, | ||
46 | MAX77843_CHARGER, | ||
47 | |||
48 | MAX77843_NUM, | ||
49 | }; | ||
50 | |||
51 | /* Register differences between chargers: MAX77693 and MAX77843 */ | ||
52 | struct chg_reg_data { | ||
53 | unsigned int linear_reg; | ||
54 | unsigned int linear_mask; | ||
55 | unsigned int uA_step; | ||
56 | unsigned int min_sel; | ||
57 | }; | ||
37 | 58 | ||
38 | /* | 59 | /* |
39 | * CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA | 60 | * MAX77693 CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA |
40 | * 0x00, 0x01, 0x2, 0x03 = 60 mA | 61 | * 0x00, 0x01, 0x2, 0x03 = 60 mA |
41 | * 0x04 ~ 0x7E = (60 + (X - 3) * 20) mA | 62 | * 0x04 ~ 0x7E = (60 + (X - 3) * 20) mA |
63 | * Actually for MAX77693 the driver manipulates the maximum input current, | ||
64 | * not the fast charge current (output). This should be fixed. | ||
65 | * | ||
66 | * On MAX77843 the calculation formula is the same (except values). | ||
67 | * Fortunately it properly manipulates the fast charge current. | ||
42 | */ | 68 | */ |
43 | static int max77693_chg_get_current_limit(struct regulator_dev *rdev) | 69 | static int max77693_chg_get_current_limit(struct regulator_dev *rdev) |
44 | { | 70 | { |
71 | const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev); | ||
45 | unsigned int chg_min_uA = rdev->constraints->min_uA; | 72 | unsigned int chg_min_uA = rdev->constraints->min_uA; |
46 | unsigned int chg_max_uA = rdev->constraints->max_uA; | 73 | unsigned int chg_max_uA = rdev->constraints->max_uA; |
47 | unsigned int reg, sel; | 74 | unsigned int reg, sel; |
48 | unsigned int val; | 75 | unsigned int val; |
49 | int ret; | 76 | int ret; |
50 | 77 | ||
51 | ret = regmap_read(rdev->regmap, MAX77693_CHG_REG_CHG_CNFG_09, ®); | 78 | ret = regmap_read(rdev->regmap, reg_data->linear_reg, ®); |
52 | if (ret < 0) | 79 | if (ret < 0) |
53 | return ret; | 80 | return ret; |
54 | 81 | ||
55 | sel = reg & CHG_CNFG_09_CHGIN_ILIM_MASK; | 82 | sel = reg & reg_data->linear_mask; |
56 | 83 | ||
57 | /* the first four codes for charger current are all 60mA */ | 84 | /* the first four codes for charger current are all 60mA */ |
58 | if (sel <= 3) | 85 | if (sel <= reg_data->min_sel) |
59 | sel = 0; | 86 | sel = 0; |
60 | else | 87 | else |
61 | sel -= 3; | 88 | sel -= reg_data->min_sel; |
62 | 89 | ||
63 | val = chg_min_uA + CHGIN_ILIM_STEP_20mA * sel; | 90 | val = chg_min_uA + reg_data->uA_step * sel; |
64 | if (val > chg_max_uA) | 91 | if (val > chg_max_uA) |
65 | return -EINVAL; | 92 | return -EINVAL; |
66 | 93 | ||
@@ -70,23 +97,43 @@ static int max77693_chg_get_current_limit(struct regulator_dev *rdev) | |||
70 | static int max77693_chg_set_current_limit(struct regulator_dev *rdev, | 97 | static int max77693_chg_set_current_limit(struct regulator_dev *rdev, |
71 | int min_uA, int max_uA) | 98 | int min_uA, int max_uA) |
72 | { | 99 | { |
100 | const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev); | ||
73 | unsigned int chg_min_uA = rdev->constraints->min_uA; | 101 | unsigned int chg_min_uA = rdev->constraints->min_uA; |
74 | int sel = 0; | 102 | int sel = 0; |
75 | 103 | ||
76 | while (chg_min_uA + CHGIN_ILIM_STEP_20mA * sel < min_uA) | 104 | while (chg_min_uA + reg_data->uA_step * sel < min_uA) |
77 | sel++; | 105 | sel++; |
78 | 106 | ||
79 | if (chg_min_uA + CHGIN_ILIM_STEP_20mA * sel > max_uA) | 107 | if (chg_min_uA + reg_data->uA_step * sel > max_uA) |
80 | return -EINVAL; | 108 | return -EINVAL; |
81 | 109 | ||
82 | /* the first four codes for charger current are all 60mA */ | 110 | /* the first four codes for charger current are all 60mA */ |
83 | sel += 3; | 111 | sel += reg_data->min_sel; |
84 | 112 | ||
85 | return regmap_write(rdev->regmap, | 113 | return regmap_write(rdev->regmap, reg_data->linear_reg, sel); |
86 | MAX77693_CHG_REG_CHG_CNFG_09, sel); | ||
87 | } | 114 | } |
88 | /* end of CHARGER regulator ops */ | 115 | /* end of CHARGER regulator ops */ |
89 | 116 | ||
117 | /* Returns regmap suitable for given regulator on chosen device */ | ||
118 | static struct regmap *max77693_get_regmap(enum max77693_types type, | ||
119 | struct max77693_dev *max77693, | ||
120 | int reg_id) | ||
121 | { | ||
122 | if (type == TYPE_MAX77693) | ||
123 | return max77693->regmap; | ||
124 | |||
125 | /* Else: TYPE_MAX77843 */ | ||
126 | switch (reg_id) { | ||
127 | case MAX77843_SAFEOUT1: | ||
128 | case MAX77843_SAFEOUT2: | ||
129 | return max77693->regmap; | ||
130 | case MAX77843_CHARGER: | ||
131 | return max77693->regmap_chg; | ||
132 | default: | ||
133 | return max77693->regmap; | ||
134 | } | ||
135 | } | ||
136 | |||
90 | static const unsigned int max77693_safeout_table[] = { | 137 | static const unsigned int max77693_safeout_table[] = { |
91 | 4850000, | 138 | 4850000, |
92 | 4900000, | 139 | 4900000, |
@@ -111,7 +158,7 @@ static struct regulator_ops max77693_charger_ops = { | |||
111 | .set_current_limit = max77693_chg_set_current_limit, | 158 | .set_current_limit = max77693_chg_set_current_limit, |
112 | }; | 159 | }; |
113 | 160 | ||
114 | #define regulator_desc_esafeout(_num) { \ | 161 | #define max77693_regulator_desc_esafeout(_num) { \ |
115 | .name = "ESAFEOUT"#_num, \ | 162 | .name = "ESAFEOUT"#_num, \ |
116 | .id = MAX77693_ESAFEOUT##_num, \ | 163 | .id = MAX77693_ESAFEOUT##_num, \ |
117 | .of_match = of_match_ptr("ESAFEOUT"#_num), \ | 164 | .of_match = of_match_ptr("ESAFEOUT"#_num), \ |
@@ -127,9 +174,9 @@ static struct regulator_ops max77693_charger_ops = { | |||
127 | .enable_mask = SAFEOUT_CTRL_ENSAFEOUT##_num##_MASK , \ | 174 | .enable_mask = SAFEOUT_CTRL_ENSAFEOUT##_num##_MASK , \ |
128 | } | 175 | } |
129 | 176 | ||
130 | static const struct regulator_desc regulators[] = { | 177 | static const struct regulator_desc max77693_supported_regulators[] = { |
131 | regulator_desc_esafeout(1), | 178 | max77693_regulator_desc_esafeout(1), |
132 | regulator_desc_esafeout(2), | 179 | max77693_regulator_desc_esafeout(2), |
133 | { | 180 | { |
134 | .name = "CHARGER", | 181 | .name = "CHARGER", |
135 | .id = MAX77693_CHARGER, | 182 | .id = MAX77693_CHARGER, |
@@ -145,18 +192,86 @@ static const struct regulator_desc regulators[] = { | |||
145 | }, | 192 | }, |
146 | }; | 193 | }; |
147 | 194 | ||
195 | static const struct chg_reg_data max77693_chg_reg_data = { | ||
196 | .linear_reg = MAX77693_CHG_REG_CHG_CNFG_09, | ||
197 | .linear_mask = CHG_CNFG_09_CHGIN_ILIM_MASK, | ||
198 | .uA_step = 20000, | ||
199 | .min_sel = 3, | ||
200 | }; | ||
201 | |||
202 | #define max77843_regulator_desc_esafeout(num) { \ | ||
203 | .name = "SAFEOUT" # num, \ | ||
204 | .id = MAX77843_SAFEOUT ## num, \ | ||
205 | .ops = &max77693_safeout_ops, \ | ||
206 | .of_match = of_match_ptr("SAFEOUT" # num), \ | ||
207 | .regulators_node = of_match_ptr("regulators"), \ | ||
208 | .type = REGULATOR_VOLTAGE, \ | ||
209 | .owner = THIS_MODULE, \ | ||
210 | .n_voltages = ARRAY_SIZE(max77693_safeout_table), \ | ||
211 | .volt_table = max77693_safeout_table, \ | ||
212 | .enable_reg = MAX77843_SYS_REG_SAFEOUTCTRL, \ | ||
213 | .enable_mask = MAX77843_REG_SAFEOUTCTRL_ENSAFEOUT ## num, \ | ||
214 | .vsel_reg = MAX77843_SYS_REG_SAFEOUTCTRL, \ | ||
215 | .vsel_mask = MAX77843_REG_SAFEOUTCTRL_SAFEOUT ## num ## _MASK, \ | ||
216 | } | ||
217 | |||
218 | static const struct regulator_desc max77843_supported_regulators[] = { | ||
219 | [MAX77843_SAFEOUT1] = max77843_regulator_desc_esafeout(1), | ||
220 | [MAX77843_SAFEOUT2] = max77843_regulator_desc_esafeout(2), | ||
221 | [MAX77843_CHARGER] = { | ||
222 | .name = "CHARGER", | ||
223 | .id = MAX77843_CHARGER, | ||
224 | .ops = &max77693_charger_ops, | ||
225 | .of_match = of_match_ptr("CHARGER"), | ||
226 | .regulators_node = of_match_ptr("regulators"), | ||
227 | .type = REGULATOR_CURRENT, | ||
228 | .owner = THIS_MODULE, | ||
229 | .enable_reg = MAX77843_CHG_REG_CHG_CNFG_00, | ||
230 | .enable_mask = MAX77843_CHG_MASK, | ||
231 | .enable_val = MAX77843_CHG_MASK, | ||
232 | }, | ||
233 | }; | ||
234 | |||
235 | static const struct chg_reg_data max77843_chg_reg_data = { | ||
236 | .linear_reg = MAX77843_CHG_REG_CHG_CNFG_02, | ||
237 | .linear_mask = MAX77843_CHG_FAST_CHG_CURRENT_MASK, | ||
238 | .uA_step = MAX77843_CHG_FAST_CHG_CURRENT_STEP, | ||
239 | .min_sel = 2, | ||
240 | }; | ||
241 | |||
148 | static int max77693_pmic_probe(struct platform_device *pdev) | 242 | static int max77693_pmic_probe(struct platform_device *pdev) |
149 | { | 243 | { |
244 | enum max77693_types type = platform_get_device_id(pdev)->driver_data; | ||
150 | struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent); | 245 | struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
246 | const struct regulator_desc *regulators; | ||
247 | unsigned int regulators_size; | ||
151 | int i; | 248 | int i; |
152 | struct regulator_config config = { }; | 249 | struct regulator_config config = { }; |
153 | 250 | ||
154 | config.dev = iodev->dev; | 251 | config.dev = iodev->dev; |
155 | config.regmap = iodev->regmap; | ||
156 | 252 | ||
157 | for (i = 0; i < ARRAY_SIZE(regulators); i++) { | 253 | switch (type) { |
254 | case TYPE_MAX77693: | ||
255 | regulators = max77693_supported_regulators; | ||
256 | regulators_size = ARRAY_SIZE(max77693_supported_regulators); | ||
257 | config.driver_data = (void *)&max77693_chg_reg_data; | ||
258 | break; | ||
259 | case TYPE_MAX77843: | ||
260 | regulators = max77843_supported_regulators; | ||
261 | regulators_size = ARRAY_SIZE(max77843_supported_regulators); | ||
262 | config.driver_data = (void *)&max77843_chg_reg_data; | ||
263 | break; | ||
264 | default: | ||
265 | dev_err(&pdev->dev, "Unsupported device type: %u\n", type); | ||
266 | return -ENODEV; | ||
267 | } | ||
268 | |||
269 | for (i = 0; i < regulators_size; i++) { | ||
158 | struct regulator_dev *rdev; | 270 | struct regulator_dev *rdev; |
159 | 271 | ||
272 | config.regmap = max77693_get_regmap(type, iodev, | ||
273 | regulators[i].id); | ||
274 | |||
160 | rdev = devm_regulator_register(&pdev->dev, | 275 | rdev = devm_regulator_register(&pdev->dev, |
161 | ®ulators[i], &config); | 276 | ®ulators[i], &config); |
162 | if (IS_ERR(rdev)) { | 277 | if (IS_ERR(rdev)) { |
@@ -170,7 +285,8 @@ static int max77693_pmic_probe(struct platform_device *pdev) | |||
170 | } | 285 | } |
171 | 286 | ||
172 | static const struct platform_device_id max77693_pmic_id[] = { | 287 | static const struct platform_device_id max77693_pmic_id[] = { |
173 | {"max77693-pmic", 0}, | 288 | { "max77693-pmic", TYPE_MAX77693 }, |
289 | { "max77843-regulator", TYPE_MAX77843 }, | ||
174 | {}, | 290 | {}, |
175 | }; | 291 | }; |
176 | 292 | ||
@@ -184,8 +300,19 @@ static struct platform_driver max77693_pmic_driver = { | |||
184 | .id_table = max77693_pmic_id, | 300 | .id_table = max77693_pmic_id, |
185 | }; | 301 | }; |
186 | 302 | ||
187 | module_platform_driver(max77693_pmic_driver); | 303 | static int __init max77693_pmic_init(void) |
304 | { | ||
305 | return platform_driver_register(&max77693_pmic_driver); | ||
306 | } | ||
307 | subsys_initcall(max77693_pmic_init); | ||
308 | |||
309 | static void __exit max77693_pmic_cleanup(void) | ||
310 | { | ||
311 | platform_driver_unregister(&max77693_pmic_driver); | ||
312 | } | ||
313 | module_exit(max77693_pmic_cleanup); | ||
188 | 314 | ||
189 | MODULE_DESCRIPTION("MAXIM MAX77693 regulator driver"); | 315 | MODULE_DESCRIPTION("MAXIM 77693/77843 regulator driver"); |
190 | MODULE_AUTHOR("Jonghwa Lee <jonghwa3.lee@samsung.com>"); | 316 | MODULE_AUTHOR("Jonghwa Lee <jonghwa3.lee@samsung.com>"); |
317 | MODULE_AUTHOR("Krzysztof Kozlowski <k.kozlowski.k@gmail.com>"); | ||
191 | MODULE_LICENSE("GPL"); | 318 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/regulator/max77843.c b/drivers/regulator/max77843.c deleted file mode 100644 index f4fd0d3cfa6e..000000000000 --- a/drivers/regulator/max77843.c +++ /dev/null | |||
@@ -1,201 +0,0 @@ | |||
1 | /* | ||
2 | * max77843.c - Regulator driver for the Maxim MAX77843 | ||
3 | * | ||
4 | * Copyright (C) 2015 Samsung Electronics | ||
5 | * Author: Jaewon Kim <jaewon02.kim@samsung.com> | ||
6 | * Author: Beomho Seo <beomho.seo@samsung.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | #include <linux/regulator/driver.h> | ||
17 | #include <linux/regulator/machine.h> | ||
18 | #include <linux/mfd/max77843-private.h> | ||
19 | #include <linux/regulator/of_regulator.h> | ||
20 | |||
21 | enum max77843_regulator_type { | ||
22 | MAX77843_SAFEOUT1 = 0, | ||
23 | MAX77843_SAFEOUT2, | ||
24 | MAX77843_CHARGER, | ||
25 | |||
26 | MAX77843_NUM, | ||
27 | }; | ||
28 | |||
29 | static const unsigned int max77843_safeout_voltage_table[] = { | ||
30 | 4850000, | ||
31 | 4900000, | ||
32 | 4950000, | ||
33 | 3300000, | ||
34 | }; | ||
35 | |||
36 | static int max77843_reg_get_current_limit(struct regulator_dev *rdev) | ||
37 | { | ||
38 | struct regmap *regmap = rdev->regmap; | ||
39 | unsigned int chg_min_uA = rdev->constraints->min_uA; | ||
40 | unsigned int chg_max_uA = rdev->constraints->max_uA; | ||
41 | unsigned int val; | ||
42 | int ret; | ||
43 | unsigned int reg, sel; | ||
44 | |||
45 | ret = regmap_read(regmap, MAX77843_CHG_REG_CHG_CNFG_02, ®); | ||
46 | if (ret) { | ||
47 | dev_err(&rdev->dev, "Failed to read charger register\n"); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | sel = reg & MAX77843_CHG_FAST_CHG_CURRENT_MASK; | ||
52 | |||
53 | if (sel < 0x03) | ||
54 | sel = 0; | ||
55 | else | ||
56 | sel -= 2; | ||
57 | |||
58 | val = chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel; | ||
59 | if (val > chg_max_uA) | ||
60 | return -EINVAL; | ||
61 | |||
62 | return val; | ||
63 | } | ||
64 | |||
65 | static int max77843_reg_set_current_limit(struct regulator_dev *rdev, | ||
66 | int min_uA, int max_uA) | ||
67 | { | ||
68 | struct regmap *regmap = rdev->regmap; | ||
69 | unsigned int chg_min_uA = rdev->constraints->min_uA; | ||
70 | int sel = 0; | ||
71 | |||
72 | while (chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel < min_uA) | ||
73 | sel++; | ||
74 | |||
75 | if (chg_min_uA + MAX77843_CHG_FAST_CHG_CURRENT_STEP * sel > max_uA) | ||
76 | return -EINVAL; | ||
77 | |||
78 | sel += 2; | ||
79 | |||
80 | return regmap_write(regmap, MAX77843_CHG_REG_CHG_CNFG_02, sel); | ||
81 | } | ||
82 | |||
83 | static struct regulator_ops max77843_charger_ops = { | ||
84 | .is_enabled = regulator_is_enabled_regmap, | ||
85 | .enable = regulator_enable_regmap, | ||
86 | .disable = regulator_disable_regmap, | ||
87 | .get_current_limit = max77843_reg_get_current_limit, | ||
88 | .set_current_limit = max77843_reg_set_current_limit, | ||
89 | }; | ||
90 | |||
91 | static struct regulator_ops max77843_regulator_ops = { | ||
92 | .is_enabled = regulator_is_enabled_regmap, | ||
93 | .enable = regulator_enable_regmap, | ||
94 | .disable = regulator_disable_regmap, | ||
95 | .list_voltage = regulator_list_voltage_table, | ||
96 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
97 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
98 | }; | ||
99 | |||
100 | #define MAX77843_SAFEOUT(num) { \ | ||
101 | .name = "SAFEOUT" # num, \ | ||
102 | .id = MAX77843_SAFEOUT ## num, \ | ||
103 | .ops = &max77843_regulator_ops, \ | ||
104 | .of_match = of_match_ptr("SAFEOUT" # num), \ | ||
105 | .regulators_node = of_match_ptr("regulators"), \ | ||
106 | .type = REGULATOR_VOLTAGE, \ | ||
107 | .owner = THIS_MODULE, \ | ||
108 | .n_voltages = ARRAY_SIZE(max77843_safeout_voltage_table), \ | ||
109 | .volt_table = max77843_safeout_voltage_table, \ | ||
110 | .enable_reg = MAX77843_SYS_REG_SAFEOUTCTRL, \ | ||
111 | .enable_mask = MAX77843_REG_SAFEOUTCTRL_ENSAFEOUT ## num, \ | ||
112 | .vsel_reg = MAX77843_SYS_REG_SAFEOUTCTRL, \ | ||
113 | .vsel_mask = MAX77843_REG_SAFEOUTCTRL_SAFEOUT ## num ## _MASK, \ | ||
114 | } | ||
115 | |||
116 | static const struct regulator_desc max77843_supported_regulators[] = { | ||
117 | [MAX77843_SAFEOUT1] = MAX77843_SAFEOUT(1), | ||
118 | [MAX77843_SAFEOUT2] = MAX77843_SAFEOUT(2), | ||
119 | [MAX77843_CHARGER] = { | ||
120 | .name = "CHARGER", | ||
121 | .id = MAX77843_CHARGER, | ||
122 | .ops = &max77843_charger_ops, | ||
123 | .of_match = of_match_ptr("CHARGER"), | ||
124 | .regulators_node = of_match_ptr("regulators"), | ||
125 | .type = REGULATOR_CURRENT, | ||
126 | .owner = THIS_MODULE, | ||
127 | .enable_reg = MAX77843_CHG_REG_CHG_CNFG_00, | ||
128 | .enable_mask = MAX77843_CHG_MASK | MAX77843_CHG_BUCK_MASK, | ||
129 | .enable_val = MAX77843_CHG_MASK | MAX77843_CHG_BUCK_MASK, | ||
130 | }, | ||
131 | }; | ||
132 | |||
133 | static struct regmap *max77843_get_regmap(struct max77843 *max77843, int reg_id) | ||
134 | { | ||
135 | switch (reg_id) { | ||
136 | case MAX77843_SAFEOUT1: | ||
137 | case MAX77843_SAFEOUT2: | ||
138 | return max77843->regmap; | ||
139 | case MAX77843_CHARGER: | ||
140 | return max77843->regmap_chg; | ||
141 | default: | ||
142 | return max77843->regmap; | ||
143 | } | ||
144 | } | ||
145 | |||
146 | static int max77843_regulator_probe(struct platform_device *pdev) | ||
147 | { | ||
148 | struct max77843 *max77843 = dev_get_drvdata(pdev->dev.parent); | ||
149 | struct regulator_config config = {}; | ||
150 | int i; | ||
151 | |||
152 | config.dev = max77843->dev; | ||
153 | config.driver_data = max77843; | ||
154 | |||
155 | for (i = 0; i < ARRAY_SIZE(max77843_supported_regulators); i++) { | ||
156 | struct regulator_dev *regulator; | ||
157 | |||
158 | config.regmap = max77843_get_regmap(max77843, | ||
159 | max77843_supported_regulators[i].id); | ||
160 | |||
161 | regulator = devm_regulator_register(&pdev->dev, | ||
162 | &max77843_supported_regulators[i], &config); | ||
163 | if (IS_ERR(regulator)) { | ||
164 | dev_err(&pdev->dev, | ||
165 | "Failed to regiser regulator-%d\n", i); | ||
166 | return PTR_ERR(regulator); | ||
167 | } | ||
168 | } | ||
169 | |||
170 | return 0; | ||
171 | } | ||
172 | |||
173 | static const struct platform_device_id max77843_regulator_id[] = { | ||
174 | { "max77843-regulator", }, | ||
175 | { /* sentinel */ }, | ||
176 | }; | ||
177 | |||
178 | static struct platform_driver max77843_regulator_driver = { | ||
179 | .driver = { | ||
180 | .name = "max77843-regulator", | ||
181 | }, | ||
182 | .probe = max77843_regulator_probe, | ||
183 | .id_table = max77843_regulator_id, | ||
184 | }; | ||
185 | |||
186 | static int __init max77843_regulator_init(void) | ||
187 | { | ||
188 | return platform_driver_register(&max77843_regulator_driver); | ||
189 | } | ||
190 | subsys_initcall(max77843_regulator_init); | ||
191 | |||
192 | static void __exit max77843_regulator_exit(void) | ||
193 | { | ||
194 | platform_driver_unregister(&max77843_regulator_driver); | ||
195 | } | ||
196 | module_exit(max77843_regulator_exit); | ||
197 | |||
198 | MODULE_AUTHOR("Jaewon Kim <jaewon02.kim@samsung.com>"); | ||
199 | MODULE_AUTHOR("Beomho Seo <beomho.seo@samsung.com>"); | ||
200 | MODULE_DESCRIPTION("Maxim MAX77843 regulator driver"); | ||
201 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c index 4071d74fa828..b87f62dd484e 100644 --- a/drivers/regulator/max8660.c +++ b/drivers/regulator/max8660.c | |||
@@ -518,7 +518,6 @@ static struct i2c_driver max8660_driver = { | |||
518 | .probe = max8660_probe, | 518 | .probe = max8660_probe, |
519 | .driver = { | 519 | .driver = { |
520 | .name = "max8660", | 520 | .name = "max8660", |
521 | .owner = THIS_MODULE, | ||
522 | }, | 521 | }, |
523 | .id_table = max8660_id, | 522 | .id_table = max8660_id, |
524 | }; | 523 | }; |
diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c index e94ddcf97722..5b75b7c2e3ea 100644 --- a/drivers/regulator/max8973-regulator.c +++ b/drivers/regulator/max8973-regulator.c | |||
@@ -75,6 +75,7 @@ | |||
75 | #define MAX8973_DISCH_ENBABLE BIT(5) | 75 | #define MAX8973_DISCH_ENBABLE BIT(5) |
76 | #define MAX8973_FT_ENABLE BIT(4) | 76 | #define MAX8973_FT_ENABLE BIT(4) |
77 | 77 | ||
78 | #define MAX8973_CKKADV_TRIP_MASK 0xC | ||
78 | #define MAX8973_CKKADV_TRIP_DISABLE 0xC | 79 | #define MAX8973_CKKADV_TRIP_DISABLE 0xC |
79 | #define MAX8973_CKKADV_TRIP_75mV_PER_US 0x0 | 80 | #define MAX8973_CKKADV_TRIP_75mV_PER_US 0x0 |
80 | #define MAX8973_CKKADV_TRIP_150mV_PER_US 0x4 | 81 | #define MAX8973_CKKADV_TRIP_150mV_PER_US 0x4 |
@@ -282,6 +283,55 @@ static int max8973_set_ramp_delay(struct regulator_dev *rdev, | |||
282 | return ret; | 283 | return ret; |
283 | } | 284 | } |
284 | 285 | ||
286 | static int max8973_set_current_limit(struct regulator_dev *rdev, | ||
287 | int min_ua, int max_ua) | ||
288 | { | ||
289 | struct max8973_chip *max = rdev_get_drvdata(rdev); | ||
290 | unsigned int val; | ||
291 | int ret; | ||
292 | |||
293 | if (max_ua <= 9000000) | ||
294 | val = MAX8973_CKKADV_TRIP_75mV_PER_US; | ||
295 | else if (max_ua <= 12000000) | ||
296 | val = MAX8973_CKKADV_TRIP_150mV_PER_US; | ||
297 | else | ||
298 | val = MAX8973_CKKADV_TRIP_DISABLE; | ||
299 | |||
300 | ret = regmap_update_bits(max->regmap, MAX8973_CONTROL2, | ||
301 | MAX8973_CKKADV_TRIP_MASK, val); | ||
302 | if (ret < 0) { | ||
303 | dev_err(max->dev, "register %d update failed: %d\n", | ||
304 | MAX8973_CONTROL2, ret); | ||
305 | return ret; | ||
306 | } | ||
307 | return 0; | ||
308 | } | ||
309 | |||
310 | static int max8973_get_current_limit(struct regulator_dev *rdev) | ||
311 | { | ||
312 | struct max8973_chip *max = rdev_get_drvdata(rdev); | ||
313 | unsigned int control2; | ||
314 | int ret; | ||
315 | |||
316 | ret = regmap_read(max->regmap, MAX8973_CONTROL2, &control2); | ||
317 | if (ret < 0) { | ||
318 | dev_err(max->dev, "register %d read failed: %d\n", | ||
319 | MAX8973_CONTROL2, ret); | ||
320 | return ret; | ||
321 | } | ||
322 | switch (control2 & MAX8973_CKKADV_TRIP_MASK) { | ||
323 | case MAX8973_CKKADV_TRIP_DISABLE: | ||
324 | return 15000000; | ||
325 | case MAX8973_CKKADV_TRIP_150mV_PER_US: | ||
326 | return 12000000; | ||
327 | case MAX8973_CKKADV_TRIP_75mV_PER_US: | ||
328 | return 9000000; | ||
329 | default: | ||
330 | break; | ||
331 | } | ||
332 | return 9000000; | ||
333 | } | ||
334 | |||
285 | static const struct regulator_ops max8973_dcdc_ops = { | 335 | static const struct regulator_ops max8973_dcdc_ops = { |
286 | .get_voltage_sel = max8973_dcdc_get_voltage_sel, | 336 | .get_voltage_sel = max8973_dcdc_get_voltage_sel, |
287 | .set_voltage_sel = max8973_dcdc_set_voltage_sel, | 337 | .set_voltage_sel = max8973_dcdc_set_voltage_sel, |
@@ -421,6 +471,8 @@ static struct max8973_regulator_platform_data *max8973_parse_dt( | |||
421 | struct device_node *np = dev->of_node; | 471 | struct device_node *np = dev->of_node; |
422 | int ret; | 472 | int ret; |
423 | u32 pval; | 473 | u32 pval; |
474 | bool etr_enable; | ||
475 | bool etr_sensitivity_high; | ||
424 | 476 | ||
425 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | 477 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
426 | if (!pdata) | 478 | if (!pdata) |
@@ -452,6 +504,23 @@ static struct max8973_regulator_platform_data *max8973_parse_dt( | |||
452 | if (of_property_read_bool(np, "maxim,enable-bias-control")) | 504 | if (of_property_read_bool(np, "maxim,enable-bias-control")) |
453 | pdata->control_flags |= MAX8973_CONTROL_BIAS_ENABLE; | 505 | pdata->control_flags |= MAX8973_CONTROL_BIAS_ENABLE; |
454 | 506 | ||
507 | etr_enable = of_property_read_bool(np, "maxim,enable-etr"); | ||
508 | etr_sensitivity_high = of_property_read_bool(np, | ||
509 | "maxim,enable-high-etr-sensitivity"); | ||
510 | if (etr_sensitivity_high) | ||
511 | etr_enable = true; | ||
512 | |||
513 | if (etr_enable) { | ||
514 | if (etr_sensitivity_high) | ||
515 | pdata->control_flags |= | ||
516 | MAX8973_CONTROL_CLKADV_TRIP_75mV_PER_US; | ||
517 | else | ||
518 | pdata->control_flags |= | ||
519 | MAX8973_CONTROL_CLKADV_TRIP_150mV_PER_US; | ||
520 | } else { | ||
521 | pdata->control_flags |= MAX8973_CONTROL_CLKADV_TRIP_DISABLED; | ||
522 | } | ||
523 | |||
455 | return pdata; | 524 | return pdata; |
456 | } | 525 | } |
457 | 526 | ||
@@ -568,6 +637,15 @@ static int max8973_probe(struct i2c_client *client, | |||
568 | max->lru_index[i] = i; | 637 | max->lru_index[i] = i; |
569 | max->lru_index[0] = max->curr_vout_reg; | 638 | max->lru_index[0] = max->curr_vout_reg; |
570 | max->lru_index[max->curr_vout_reg] = 0; | 639 | max->lru_index[max->curr_vout_reg] = 0; |
640 | } else { | ||
641 | /* | ||
642 | * If there is no DVS GPIO, the VOUT register | ||
643 | * address is fixed. | ||
644 | */ | ||
645 | max->ops.set_voltage_sel = regulator_set_voltage_sel_regmap; | ||
646 | max->ops.get_voltage_sel = regulator_get_voltage_sel_regmap; | ||
647 | max->desc.vsel_reg = max->curr_vout_reg; | ||
648 | max->desc.vsel_mask = MAX8973_VOUT_MASK; | ||
571 | } | 649 | } |
572 | 650 | ||
573 | if (pdata_from_dt) | 651 | if (pdata_from_dt) |
@@ -613,6 +691,8 @@ static int max8973_probe(struct i2c_client *client, | |||
613 | max->ops.enable = regulator_enable_regmap; | 691 | max->ops.enable = regulator_enable_regmap; |
614 | max->ops.disable = regulator_disable_regmap; | 692 | max->ops.disable = regulator_disable_regmap; |
615 | max->ops.is_enabled = regulator_is_enabled_regmap; | 693 | max->ops.is_enabled = regulator_is_enabled_regmap; |
694 | max->ops.set_current_limit = max8973_set_current_limit; | ||
695 | max->ops.get_current_limit = max8973_get_current_limit; | ||
616 | break; | 696 | break; |
617 | default: | 697 | default: |
618 | break; | 698 | break; |
@@ -652,7 +732,6 @@ static struct i2c_driver max8973_i2c_driver = { | |||
652 | .driver = { | 732 | .driver = { |
653 | .name = "max8973", | 733 | .name = "max8973", |
654 | .of_match_table = of_max8973_match_tbl, | 734 | .of_match_table = of_max8973_match_tbl, |
655 | .owner = THIS_MODULE, | ||
656 | }, | 735 | }, |
657 | .probe = max8973_probe, | 736 | .probe = max8973_probe, |
658 | .id_table = max8973_id, | 737 | .id_table = max8973_id, |
diff --git a/drivers/regulator/mt6311-regulator.c b/drivers/regulator/mt6311-regulator.c new file mode 100644 index 000000000000..02c4e5feca8e --- /dev/null +++ b/drivers/regulator/mt6311-regulator.c | |||
@@ -0,0 +1,179 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2015 MediaTek Inc. | ||
3 | * Author: Henry Chen <henryc.chen@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 | */ | ||
14 | |||
15 | #include <linux/err.h> | ||
16 | #include <linux/gpio.h> | ||
17 | #include <linux/i2c.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/regmap.h> | ||
22 | #include <linux/regulator/driver.h> | ||
23 | #include <linux/regulator/machine.h> | ||
24 | #include <linux/regulator/of_regulator.h> | ||
25 | #include <linux/regulator/mt6311.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include "mt6311-regulator.h" | ||
28 | |||
29 | static const struct regmap_config mt6311_regmap_config = { | ||
30 | .reg_bits = 8, | ||
31 | .val_bits = 8, | ||
32 | .max_register = MT6311_FQMTR_CON4, | ||
33 | }; | ||
34 | |||
35 | /* Default limits measured in millivolts and milliamps */ | ||
36 | #define MT6311_MIN_UV 600000 | ||
37 | #define MT6311_MAX_UV 1393750 | ||
38 | #define MT6311_STEP_UV 6250 | ||
39 | |||
40 | static const struct regulator_linear_range buck_volt_range[] = { | ||
41 | REGULATOR_LINEAR_RANGE(MT6311_MIN_UV, 0, 0x7f, MT6311_STEP_UV), | ||
42 | }; | ||
43 | |||
44 | static const struct regulator_ops mt6311_buck_ops = { | ||
45 | .list_voltage = regulator_list_voltage_linear_range, | ||
46 | .map_voltage = regulator_map_voltage_linear_range, | ||
47 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
48 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
49 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | ||
50 | .enable = regulator_enable_regmap, | ||
51 | .disable = regulator_disable_regmap, | ||
52 | .is_enabled = regulator_is_enabled_regmap, | ||
53 | }; | ||
54 | |||
55 | static const struct regulator_ops mt6311_ldo_ops = { | ||
56 | .enable = regulator_enable_regmap, | ||
57 | .disable = regulator_disable_regmap, | ||
58 | .is_enabled = regulator_is_enabled_regmap, | ||
59 | }; | ||
60 | |||
61 | #define MT6311_BUCK(_id) \ | ||
62 | {\ | ||
63 | .name = #_id,\ | ||
64 | .ops = &mt6311_buck_ops,\ | ||
65 | .of_match = of_match_ptr(#_id),\ | ||
66 | .regulators_node = of_match_ptr("regulators"),\ | ||
67 | .type = REGULATOR_VOLTAGE,\ | ||
68 | .id = MT6311_ID_##_id,\ | ||
69 | .n_voltages = (MT6311_MAX_UV - MT6311_MIN_UV) / MT6311_STEP_UV + 1,\ | ||
70 | .min_uV = MT6311_MIN_UV,\ | ||
71 | .uV_step = MT6311_STEP_UV,\ | ||
72 | .owner = THIS_MODULE,\ | ||
73 | .linear_ranges = buck_volt_range, \ | ||
74 | .n_linear_ranges = ARRAY_SIZE(buck_volt_range), \ | ||
75 | .enable_reg = MT6311_VDVFS11_CON9,\ | ||
76 | .enable_mask = MT6311_PMIC_VDVFS11_EN_MASK,\ | ||
77 | .vsel_reg = MT6311_VDVFS11_CON12,\ | ||
78 | .vsel_mask = MT6311_PMIC_VDVFS11_VOSEL_MASK,\ | ||
79 | } | ||
80 | |||
81 | #define MT6311_LDO(_id) \ | ||
82 | {\ | ||
83 | .name = #_id,\ | ||
84 | .ops = &mt6311_ldo_ops,\ | ||
85 | .of_match = of_match_ptr(#_id),\ | ||
86 | .regulators_node = of_match_ptr("regulators"),\ | ||
87 | .type = REGULATOR_VOLTAGE,\ | ||
88 | .id = MT6311_ID_##_id,\ | ||
89 | .owner = THIS_MODULE,\ | ||
90 | .enable_reg = MT6311_LDO_CON3,\ | ||
91 | .enable_mask = MT6311_PMIC_RG_VBIASN_EN_MASK,\ | ||
92 | } | ||
93 | |||
94 | static const struct regulator_desc mt6311_regulators[] = { | ||
95 | MT6311_BUCK(VDVFS), | ||
96 | MT6311_LDO(VBIASN), | ||
97 | }; | ||
98 | |||
99 | /* | ||
100 | * I2C driver interface functions | ||
101 | */ | ||
102 | static int mt6311_i2c_probe(struct i2c_client *i2c, | ||
103 | const struct i2c_device_id *id) | ||
104 | { | ||
105 | struct regulator_config config = { }; | ||
106 | struct regulator_dev *rdev; | ||
107 | struct regmap *regmap; | ||
108 | int i, ret; | ||
109 | unsigned int data; | ||
110 | |||
111 | regmap = devm_regmap_init_i2c(i2c, &mt6311_regmap_config); | ||
112 | if (IS_ERR(regmap)) { | ||
113 | ret = PTR_ERR(regmap); | ||
114 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", | ||
115 | ret); | ||
116 | return ret; | ||
117 | } | ||
118 | |||
119 | ret = regmap_read(regmap, MT6311_SWCID, &data); | ||
120 | if (ret < 0) { | ||
121 | dev_err(&i2c->dev, "Failed to read DEVICE_ID reg: %d\n", ret); | ||
122 | return ret; | ||
123 | } | ||
124 | |||
125 | switch (data) { | ||
126 | case MT6311_E1_CID_CODE: | ||
127 | case MT6311_E2_CID_CODE: | ||
128 | case MT6311_E3_CID_CODE: | ||
129 | break; | ||
130 | default: | ||
131 | dev_err(&i2c->dev, "Unsupported device id = 0x%x.\n", data); | ||
132 | return -ENODEV; | ||
133 | } | ||
134 | |||
135 | for (i = 0; i < MT6311_MAX_REGULATORS; i++) { | ||
136 | config.dev = &i2c->dev; | ||
137 | config.regmap = regmap; | ||
138 | |||
139 | rdev = devm_regulator_register(&i2c->dev, | ||
140 | &mt6311_regulators[i], &config); | ||
141 | if (IS_ERR(rdev)) { | ||
142 | dev_err(&i2c->dev, | ||
143 | "Failed to register MT6311 regulator\n"); | ||
144 | return PTR_ERR(rdev); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | static const struct i2c_device_id mt6311_i2c_id[] = { | ||
152 | {"mt6311", 0}, | ||
153 | {}, | ||
154 | }; | ||
155 | MODULE_DEVICE_TABLE(i2c, mt6311_i2c_id); | ||
156 | |||
157 | #ifdef CONFIG_OF | ||
158 | static const struct of_device_id mt6311_dt_ids[] = { | ||
159 | { .compatible = "mediatek,mt6311-regulator", | ||
160 | .data = &mt6311_i2c_id[0] }, | ||
161 | {}, | ||
162 | }; | ||
163 | MODULE_DEVICE_TABLE(of, mt6311_dt_ids); | ||
164 | #endif | ||
165 | |||
166 | static struct i2c_driver mt6311_regulator_driver = { | ||
167 | .driver = { | ||
168 | .name = "mt6311", | ||
169 | .of_match_table = of_match_ptr(mt6311_dt_ids), | ||
170 | }, | ||
171 | .probe = mt6311_i2c_probe, | ||
172 | .id_table = mt6311_i2c_id, | ||
173 | }; | ||
174 | |||
175 | module_i2c_driver(mt6311_regulator_driver); | ||
176 | |||
177 | MODULE_AUTHOR("Henry Chen <henryc.chen@mediatek.com>"); | ||
178 | MODULE_DESCRIPTION("Regulator device driver for Mediatek MT6311"); | ||
179 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/regulator/mt6311-regulator.h b/drivers/regulator/mt6311-regulator.h new file mode 100644 index 000000000000..5218db46a798 --- /dev/null +++ b/drivers/regulator/mt6311-regulator.h | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2015 MediaTek Inc. | ||
3 | * Author: Henry Chen <henryc.chen@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 | */ | ||
14 | |||
15 | #ifndef __MT6311_REGULATOR_H__ | ||
16 | #define __MT6311_REGULATOR_H__ | ||
17 | |||
18 | #define MT6311_SWCID 0x01 | ||
19 | |||
20 | #define MT6311_TOP_INT_CON 0x18 | ||
21 | #define MT6311_TOP_INT_MON 0x19 | ||
22 | |||
23 | #define MT6311_VDVFS11_CON0 0x87 | ||
24 | #define MT6311_VDVFS11_CON7 0x88 | ||
25 | #define MT6311_VDVFS11_CON8 0x89 | ||
26 | #define MT6311_VDVFS11_CON9 0x8A | ||
27 | #define MT6311_VDVFS11_CON10 0x8B | ||
28 | #define MT6311_VDVFS11_CON11 0x8C | ||
29 | #define MT6311_VDVFS11_CON12 0x8D | ||
30 | #define MT6311_VDVFS11_CON13 0x8E | ||
31 | #define MT6311_VDVFS11_CON14 0x8F | ||
32 | #define MT6311_VDVFS11_CON15 0x90 | ||
33 | #define MT6311_VDVFS11_CON16 0x91 | ||
34 | #define MT6311_VDVFS11_CON17 0x92 | ||
35 | #define MT6311_VDVFS11_CON18 0x93 | ||
36 | #define MT6311_VDVFS11_CON19 0x94 | ||
37 | |||
38 | #define MT6311_LDO_CON0 0xCC | ||
39 | #define MT6311_LDO_OCFB0 0xCD | ||
40 | #define MT6311_LDO_CON2 0xCE | ||
41 | #define MT6311_LDO_CON3 0xCF | ||
42 | #define MT6311_LDO_CON4 0xD0 | ||
43 | #define MT6311_FQMTR_CON0 0xD1 | ||
44 | #define MT6311_FQMTR_CON1 0xD2 | ||
45 | #define MT6311_FQMTR_CON2 0xD3 | ||
46 | #define MT6311_FQMTR_CON3 0xD4 | ||
47 | #define MT6311_FQMTR_CON4 0xD5 | ||
48 | |||
49 | #define MT6311_PMIC_RG_INT_POL_MASK 0x1 | ||
50 | #define MT6311_PMIC_RG_INT_EN_MASK 0x2 | ||
51 | #define MT6311_PMIC_RG_BUCK_OC_INT_STATUS_MASK 0x10 | ||
52 | |||
53 | #define MT6311_PMIC_VDVFS11_EN_CTRL_MASK 0x1 | ||
54 | #define MT6311_PMIC_VDVFS11_VOSEL_CTRL_MASK 0x2 | ||
55 | #define MT6311_PMIC_VDVFS11_EN_SEL_MASK 0x3 | ||
56 | #define MT6311_PMIC_VDVFS11_VOSEL_SEL_MASK 0xc | ||
57 | #define MT6311_PMIC_VDVFS11_EN_MASK 0x1 | ||
58 | #define MT6311_PMIC_VDVFS11_VOSEL_MASK 0x7F | ||
59 | #define MT6311_PMIC_VDVFS11_VOSEL_ON_MASK 0x7F | ||
60 | #define MT6311_PMIC_VDVFS11_VOSEL_SLEEP_MASK 0x7F | ||
61 | #define MT6311_PMIC_NI_VDVFS11_VOSEL_MASK 0x7F | ||
62 | |||
63 | #define MT6311_PMIC_RG_VBIASN_EN_MASK 0x1 | ||
64 | |||
65 | #endif | ||
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index b1c485b24ab2..250700c853bf 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c | |||
@@ -107,6 +107,9 @@ static void of_get_regulation_constraints(struct device_node *np, | |||
107 | if (!of_property_read_u32(np, "regulator-system-load", &pval)) | 107 | if (!of_property_read_u32(np, "regulator-system-load", &pval)) |
108 | constraints->system_load = pval; | 108 | constraints->system_load = pval; |
109 | 109 | ||
110 | constraints->over_current_protection = of_property_read_bool(np, | ||
111 | "regulator-over-current-protection"); | ||
112 | |||
110 | for (i = 0; i < ARRAY_SIZE(regulator_states); i++) { | 113 | for (i = 0; i < ARRAY_SIZE(regulator_states); i++) { |
111 | switch (i) { | 114 | switch (i) { |
112 | case PM_SUSPEND_MEM: | 115 | case PM_SUSPEND_MEM: |
diff --git a/drivers/regulator/pbias-regulator.c b/drivers/regulator/pbias-regulator.c index bd2b75c0d1d1..4fa7bcaf454e 100644 --- a/drivers/regulator/pbias-regulator.c +++ b/drivers/regulator/pbias-regulator.c | |||
@@ -30,6 +30,7 @@ | |||
30 | struct pbias_reg_info { | 30 | struct pbias_reg_info { |
31 | u32 enable; | 31 | u32 enable; |
32 | u32 enable_mask; | 32 | u32 enable_mask; |
33 | u32 disable_val; | ||
33 | u32 vmode; | 34 | u32 vmode; |
34 | unsigned int enable_time; | 35 | unsigned int enable_time; |
35 | char *name; | 36 | char *name; |
@@ -62,6 +63,7 @@ static const struct pbias_reg_info pbias_mmc_omap2430 = { | |||
62 | .enable = BIT(1), | 63 | .enable = BIT(1), |
63 | .enable_mask = BIT(1), | 64 | .enable_mask = BIT(1), |
64 | .vmode = BIT(0), | 65 | .vmode = BIT(0), |
66 | .disable_val = 0, | ||
65 | .enable_time = 100, | 67 | .enable_time = 100, |
66 | .name = "pbias_mmc_omap2430" | 68 | .name = "pbias_mmc_omap2430" |
67 | }; | 69 | }; |
@@ -77,6 +79,7 @@ static const struct pbias_reg_info pbias_sim_omap3 = { | |||
77 | static const struct pbias_reg_info pbias_mmc_omap4 = { | 79 | static const struct pbias_reg_info pbias_mmc_omap4 = { |
78 | .enable = BIT(26) | BIT(22), | 80 | .enable = BIT(26) | BIT(22), |
79 | .enable_mask = BIT(26) | BIT(25) | BIT(22), | 81 | .enable_mask = BIT(26) | BIT(25) | BIT(22), |
82 | .disable_val = BIT(25), | ||
80 | .vmode = BIT(21), | 83 | .vmode = BIT(21), |
81 | .enable_time = 100, | 84 | .enable_time = 100, |
82 | .name = "pbias_mmc_omap4" | 85 | .name = "pbias_mmc_omap4" |
@@ -85,6 +88,7 @@ static const struct pbias_reg_info pbias_mmc_omap4 = { | |||
85 | static const struct pbias_reg_info pbias_mmc_omap5 = { | 88 | static const struct pbias_reg_info pbias_mmc_omap5 = { |
86 | .enable = BIT(27) | BIT(26), | 89 | .enable = BIT(27) | BIT(26), |
87 | .enable_mask = BIT(27) | BIT(25) | BIT(26), | 90 | .enable_mask = BIT(27) | BIT(25) | BIT(26), |
91 | .disable_val = BIT(25), | ||
88 | .vmode = BIT(21), | 92 | .vmode = BIT(21), |
89 | .enable_time = 100, | 93 | .enable_time = 100, |
90 | .name = "pbias_mmc_omap5" | 94 | .name = "pbias_mmc_omap5" |
@@ -159,6 +163,7 @@ static int pbias_regulator_probe(struct platform_device *pdev) | |||
159 | drvdata[data_idx].desc.enable_reg = res->start; | 163 | drvdata[data_idx].desc.enable_reg = res->start; |
160 | drvdata[data_idx].desc.enable_mask = info->enable_mask; | 164 | drvdata[data_idx].desc.enable_mask = info->enable_mask; |
161 | drvdata[data_idx].desc.enable_val = info->enable; | 165 | drvdata[data_idx].desc.enable_val = info->enable; |
166 | drvdata[data_idx].desc.disable_val = info->disable_val; | ||
162 | 167 | ||
163 | cfg.init_data = pbias_matches[idx].init_data; | 168 | cfg.init_data = pbias_matches[idx].init_data; |
164 | cfg.driver_data = &drvdata[data_idx]; | 169 | cfg.driver_data = &drvdata[data_idx]; |
diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c index 8cc8d1877c44..2a44e5dd9c2a 100644 --- a/drivers/regulator/pfuze100-regulator.c +++ b/drivers/regulator/pfuze100-regulator.c | |||
@@ -643,7 +643,6 @@ static struct i2c_driver pfuze_driver = { | |||
643 | .id_table = pfuze_device_id, | 643 | .id_table = pfuze_device_id, |
644 | .driver = { | 644 | .driver = { |
645 | .name = "pfuze100-regulator", | 645 | .name = "pfuze100-regulator", |
646 | .owner = THIS_MODULE, | ||
647 | .of_match_table = pfuze_dt_ids, | 646 | .of_match_table = pfuze_dt_ids, |
648 | }, | 647 | }, |
649 | .probe = pfuze100_regulator_probe, | 648 | .probe = pfuze100_regulator_probe, |
@@ -653,4 +652,3 @@ module_i2c_driver(pfuze_driver); | |||
653 | MODULE_AUTHOR("Robin Gong <b38343@freescale.com>"); | 652 | MODULE_AUTHOR("Robin Gong <b38343@freescale.com>"); |
654 | MODULE_DESCRIPTION("Regulator Driver for Freescale PFUZE100/PFUZE200 PMIC"); | 653 | MODULE_DESCRIPTION("Regulator Driver for Freescale PFUZE100/PFUZE200 PMIC"); |
655 | MODULE_LICENSE("GPL v2"); | 654 | MODULE_LICENSE("GPL v2"); |
656 | MODULE_ALIAS("i2c:pfuze100-regulator"); | ||
diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c index ffa96124a5e7..fc3166dfcbfa 100644 --- a/drivers/regulator/pwm-regulator.c +++ b/drivers/regulator/pwm-regulator.c | |||
@@ -10,6 +10,7 @@ | |||
10 | * published by the Free Software Foundation. | 10 | * published by the Free Software Foundation. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/delay.h> | ||
13 | #include <linux/module.h> | 14 | #include <linux/module.h> |
14 | #include <linux/init.h> | 15 | #include <linux/init.h> |
15 | #include <linux/err.h> | 16 | #include <linux/err.h> |
@@ -21,9 +22,15 @@ | |||
21 | #include <linux/pwm.h> | 22 | #include <linux/pwm.h> |
22 | 23 | ||
23 | struct pwm_regulator_data { | 24 | struct pwm_regulator_data { |
24 | struct pwm_voltages *duty_cycle_table; | 25 | /* Shared */ |
25 | struct pwm_device *pwm; | 26 | struct pwm_device *pwm; |
27 | |||
28 | /* Voltage table */ | ||
29 | struct pwm_voltages *duty_cycle_table; | ||
26 | int state; | 30 | int state; |
31 | |||
32 | /* Continuous voltage */ | ||
33 | int volt_uV; | ||
27 | }; | 34 | }; |
28 | 35 | ||
29 | struct pwm_voltages { | 36 | struct pwm_voltages { |
@@ -31,6 +38,9 @@ struct pwm_voltages { | |||
31 | unsigned int dutycycle; | 38 | unsigned int dutycycle; |
32 | }; | 39 | }; |
33 | 40 | ||
41 | /** | ||
42 | * Voltage table call-backs | ||
43 | */ | ||
34 | static int pwm_regulator_get_voltage_sel(struct regulator_dev *rdev) | 44 | static int pwm_regulator_get_voltage_sel(struct regulator_dev *rdev) |
35 | { | 45 | { |
36 | struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev); | 46 | struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev); |
@@ -79,29 +89,129 @@ static int pwm_regulator_list_voltage(struct regulator_dev *rdev, | |||
79 | return drvdata->duty_cycle_table[selector].uV; | 89 | return drvdata->duty_cycle_table[selector].uV; |
80 | } | 90 | } |
81 | 91 | ||
82 | static struct regulator_ops pwm_regulator_voltage_ops = { | 92 | /** |
93 | * Continuous voltage call-backs | ||
94 | */ | ||
95 | static int pwm_voltage_to_duty_cycle_percentage(struct regulator_dev *rdev, int req_uV) | ||
96 | { | ||
97 | int min_uV = rdev->constraints->min_uV; | ||
98 | int max_uV = rdev->constraints->max_uV; | ||
99 | int diff = max_uV - min_uV; | ||
100 | |||
101 | return 100 - (((req_uV * 100) - (min_uV * 100)) / diff); | ||
102 | } | ||
103 | |||
104 | static int pwm_regulator_get_voltage(struct regulator_dev *rdev) | ||
105 | { | ||
106 | struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev); | ||
107 | |||
108 | return drvdata->volt_uV; | ||
109 | } | ||
110 | |||
111 | static int pwm_regulator_set_voltage(struct regulator_dev *rdev, | ||
112 | int min_uV, int max_uV, | ||
113 | unsigned *selector) | ||
114 | { | ||
115 | struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev); | ||
116 | unsigned int ramp_delay = rdev->constraints->ramp_delay; | ||
117 | unsigned int period = pwm_get_period(drvdata->pwm); | ||
118 | int duty_cycle; | ||
119 | int ret; | ||
120 | |||
121 | duty_cycle = pwm_voltage_to_duty_cycle_percentage(rdev, min_uV); | ||
122 | |||
123 | ret = pwm_config(drvdata->pwm, (period / 100) * duty_cycle, period); | ||
124 | if (ret) { | ||
125 | dev_err(&rdev->dev, "Failed to configure PWM\n"); | ||
126 | return ret; | ||
127 | } | ||
128 | |||
129 | ret = pwm_enable(drvdata->pwm); | ||
130 | if (ret) { | ||
131 | dev_err(&rdev->dev, "Failed to enable PWM\n"); | ||
132 | return ret; | ||
133 | } | ||
134 | drvdata->volt_uV = min_uV; | ||
135 | |||
136 | /* Delay required by PWM regulator to settle to the new voltage */ | ||
137 | usleep_range(ramp_delay, ramp_delay + 1000); | ||
138 | |||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | static struct regulator_ops pwm_regulator_voltage_table_ops = { | ||
83 | .set_voltage_sel = pwm_regulator_set_voltage_sel, | 143 | .set_voltage_sel = pwm_regulator_set_voltage_sel, |
84 | .get_voltage_sel = pwm_regulator_get_voltage_sel, | 144 | .get_voltage_sel = pwm_regulator_get_voltage_sel, |
85 | .list_voltage = pwm_regulator_list_voltage, | 145 | .list_voltage = pwm_regulator_list_voltage, |
86 | .map_voltage = regulator_map_voltage_iterate, | 146 | .map_voltage = regulator_map_voltage_iterate, |
87 | }; | 147 | }; |
88 | 148 | ||
149 | static struct regulator_ops pwm_regulator_voltage_continuous_ops = { | ||
150 | .get_voltage = pwm_regulator_get_voltage, | ||
151 | .set_voltage = pwm_regulator_set_voltage, | ||
152 | }; | ||
153 | |||
89 | static struct regulator_desc pwm_regulator_desc = { | 154 | static struct regulator_desc pwm_regulator_desc = { |
90 | .name = "pwm-regulator", | 155 | .name = "pwm-regulator", |
91 | .ops = &pwm_regulator_voltage_ops, | ||
92 | .type = REGULATOR_VOLTAGE, | 156 | .type = REGULATOR_VOLTAGE, |
93 | .owner = THIS_MODULE, | 157 | .owner = THIS_MODULE, |
94 | .supply_name = "pwm", | 158 | .supply_name = "pwm", |
95 | }; | 159 | }; |
96 | 160 | ||
161 | static int pwm_regulator_init_table(struct platform_device *pdev, | ||
162 | struct pwm_regulator_data *drvdata) | ||
163 | { | ||
164 | struct device_node *np = pdev->dev.of_node; | ||
165 | struct pwm_voltages *duty_cycle_table; | ||
166 | unsigned int length = 0; | ||
167 | int ret; | ||
168 | |||
169 | of_find_property(np, "voltage-table", &length); | ||
170 | |||
171 | if ((length < sizeof(*duty_cycle_table)) || | ||
172 | (length % sizeof(*duty_cycle_table))) { | ||
173 | dev_err(&pdev->dev, | ||
174 | "voltage-table length(%d) is invalid\n", | ||
175 | length); | ||
176 | return -EINVAL; | ||
177 | } | ||
178 | |||
179 | duty_cycle_table = devm_kzalloc(&pdev->dev, length, GFP_KERNEL); | ||
180 | if (!duty_cycle_table) | ||
181 | return -ENOMEM; | ||
182 | |||
183 | ret = of_property_read_u32_array(np, "voltage-table", | ||
184 | (u32 *)duty_cycle_table, | ||
185 | length / sizeof(u32)); | ||
186 | if (ret) { | ||
187 | dev_err(&pdev->dev, "Failed to read voltage-table\n"); | ||
188 | return ret; | ||
189 | } | ||
190 | |||
191 | drvdata->duty_cycle_table = duty_cycle_table; | ||
192 | pwm_regulator_desc.ops = &pwm_regulator_voltage_table_ops; | ||
193 | pwm_regulator_desc.n_voltages = length / sizeof(*duty_cycle_table); | ||
194 | |||
195 | return 0; | ||
196 | } | ||
197 | |||
198 | static int pwm_regulator_init_continuous(struct platform_device *pdev, | ||
199 | struct pwm_regulator_data *drvdata) | ||
200 | { | ||
201 | pwm_regulator_desc.ops = &pwm_regulator_voltage_continuous_ops; | ||
202 | pwm_regulator_desc.continuous_voltage_range = true; | ||
203 | |||
204 | return 0; | ||
205 | } | ||
206 | |||
97 | static int pwm_regulator_probe(struct platform_device *pdev) | 207 | static int pwm_regulator_probe(struct platform_device *pdev) |
98 | { | 208 | { |
209 | const struct regulator_init_data *init_data; | ||
99 | struct pwm_regulator_data *drvdata; | 210 | struct pwm_regulator_data *drvdata; |
100 | struct property *prop; | ||
101 | struct regulator_dev *regulator; | 211 | struct regulator_dev *regulator; |
102 | struct regulator_config config = { }; | 212 | struct regulator_config config = { }; |
103 | struct device_node *np = pdev->dev.of_node; | 213 | struct device_node *np = pdev->dev.of_node; |
104 | int length, ret; | 214 | int ret; |
105 | 215 | ||
106 | if (!np) { | 216 | if (!np) { |
107 | dev_err(&pdev->dev, "Device Tree node missing\n"); | 217 | dev_err(&pdev->dev, "Device Tree node missing\n"); |
@@ -112,44 +222,22 @@ static int pwm_regulator_probe(struct platform_device *pdev) | |||
112 | if (!drvdata) | 222 | if (!drvdata) |
113 | return -ENOMEM; | 223 | return -ENOMEM; |
114 | 224 | ||
115 | /* determine the number of voltage-table */ | 225 | if (of_find_property(np, "voltage-table", NULL)) |
116 | prop = of_find_property(np, "voltage-table", &length); | 226 | ret = pwm_regulator_init_table(pdev, drvdata); |
117 | if (!prop) { | 227 | else |
118 | dev_err(&pdev->dev, "No voltage-table\n"); | 228 | ret = pwm_regulator_init_continuous(pdev, drvdata); |
119 | return -EINVAL; | 229 | if (ret) |
120 | } | ||
121 | |||
122 | if ((length < sizeof(*drvdata->duty_cycle_table)) || | ||
123 | (length % sizeof(*drvdata->duty_cycle_table))) { | ||
124 | dev_err(&pdev->dev, "voltage-table length(%d) is invalid\n", | ||
125 | length); | ||
126 | return -EINVAL; | ||
127 | } | ||
128 | |||
129 | pwm_regulator_desc.n_voltages = length / sizeof(*drvdata->duty_cycle_table); | ||
130 | |||
131 | drvdata->duty_cycle_table = devm_kzalloc(&pdev->dev, | ||
132 | length, GFP_KERNEL); | ||
133 | if (!drvdata->duty_cycle_table) | ||
134 | return -ENOMEM; | ||
135 | |||
136 | /* read voltage table from DT property */ | ||
137 | ret = of_property_read_u32_array(np, "voltage-table", | ||
138 | (u32 *)drvdata->duty_cycle_table, | ||
139 | length / sizeof(u32)); | ||
140 | if (ret < 0) { | ||
141 | dev_err(&pdev->dev, "read voltage-table failed\n"); | ||
142 | return ret; | 230 | return ret; |
143 | } | ||
144 | 231 | ||
145 | config.init_data = of_get_regulator_init_data(&pdev->dev, np, | 232 | init_data = of_get_regulator_init_data(&pdev->dev, np, |
146 | &pwm_regulator_desc); | 233 | &pwm_regulator_desc); |
147 | if (!config.init_data) | 234 | if (!init_data) |
148 | return -ENOMEM; | 235 | return -ENOMEM; |
149 | 236 | ||
150 | config.of_node = np; | 237 | config.of_node = np; |
151 | config.dev = &pdev->dev; | 238 | config.dev = &pdev->dev; |
152 | config.driver_data = drvdata; | 239 | config.driver_data = drvdata; |
240 | config.init_data = init_data; | ||
153 | 241 | ||
154 | drvdata->pwm = devm_pwm_get(&pdev->dev, NULL); | 242 | drvdata->pwm = devm_pwm_get(&pdev->dev, NULL); |
155 | if (IS_ERR(drvdata->pwm)) { | 243 | if (IS_ERR(drvdata->pwm)) { |
diff --git a/drivers/regulator/qcom_smd-regulator.c b/drivers/regulator/qcom_smd-regulator.c new file mode 100644 index 000000000000..9c6167dd2c8b --- /dev/null +++ b/drivers/regulator/qcom_smd-regulator.c | |||
@@ -0,0 +1,350 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2015, Sony Mobile Communications AB. | ||
3 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. | ||
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 and | ||
7 | * only version 2 as 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 | */ | ||
14 | |||
15 | #include <linux/module.h> | ||
16 | #include <linux/of.h> | ||
17 | #include <linux/of_device.h> | ||
18 | #include <linux/platform_device.h> | ||
19 | #include <linux/regulator/driver.h> | ||
20 | #include <linux/regulator/machine.h> | ||
21 | #include <linux/regulator/of_regulator.h> | ||
22 | #include <linux/soc/qcom/smd-rpm.h> | ||
23 | |||
24 | struct qcom_rpm_reg { | ||
25 | struct device *dev; | ||
26 | |||
27 | struct qcom_smd_rpm *rpm; | ||
28 | |||
29 | u32 type; | ||
30 | u32 id; | ||
31 | |||
32 | struct regulator_desc desc; | ||
33 | |||
34 | int is_enabled; | ||
35 | int uV; | ||
36 | }; | ||
37 | |||
38 | struct rpm_regulator_req { | ||
39 | u32 key; | ||
40 | u32 nbytes; | ||
41 | u32 value; | ||
42 | }; | ||
43 | |||
44 | #define RPM_KEY_SWEN 0x6e657773 /* "swen" */ | ||
45 | #define RPM_KEY_UV 0x00007675 /* "uv" */ | ||
46 | #define RPM_KEY_MA 0x0000616d /* "ma" */ | ||
47 | |||
48 | static int rpm_reg_write_active(struct qcom_rpm_reg *vreg, | ||
49 | struct rpm_regulator_req *req, | ||
50 | size_t size) | ||
51 | { | ||
52 | return qcom_rpm_smd_write(vreg->rpm, | ||
53 | QCOM_SMD_RPM_ACTIVE_STATE, | ||
54 | vreg->type, | ||
55 | vreg->id, | ||
56 | req, size); | ||
57 | } | ||
58 | |||
59 | static int rpm_reg_enable(struct regulator_dev *rdev) | ||
60 | { | ||
61 | struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); | ||
62 | struct rpm_regulator_req req; | ||
63 | int ret; | ||
64 | |||
65 | req.key = RPM_KEY_SWEN; | ||
66 | req.nbytes = sizeof(u32); | ||
67 | req.value = 1; | ||
68 | |||
69 | ret = rpm_reg_write_active(vreg, &req, sizeof(req)); | ||
70 | if (!ret) | ||
71 | vreg->is_enabled = 1; | ||
72 | |||
73 | return ret; | ||
74 | } | ||
75 | |||
76 | static int rpm_reg_is_enabled(struct regulator_dev *rdev) | ||
77 | { | ||
78 | struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); | ||
79 | |||
80 | return vreg->is_enabled; | ||
81 | } | ||
82 | |||
83 | static int rpm_reg_disable(struct regulator_dev *rdev) | ||
84 | { | ||
85 | struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); | ||
86 | struct rpm_regulator_req req; | ||
87 | int ret; | ||
88 | |||
89 | req.key = RPM_KEY_SWEN; | ||
90 | req.nbytes = sizeof(u32); | ||
91 | req.value = 0; | ||
92 | |||
93 | ret = rpm_reg_write_active(vreg, &req, sizeof(req)); | ||
94 | if (!ret) | ||
95 | vreg->is_enabled = 0; | ||
96 | |||
97 | return ret; | ||
98 | } | ||
99 | |||
100 | static int rpm_reg_get_voltage(struct regulator_dev *rdev) | ||
101 | { | ||
102 | struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); | ||
103 | |||
104 | return vreg->uV; | ||
105 | } | ||
106 | |||
107 | static int rpm_reg_set_voltage(struct regulator_dev *rdev, | ||
108 | int min_uV, | ||
109 | int max_uV, | ||
110 | unsigned *selector) | ||
111 | { | ||
112 | struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); | ||
113 | struct rpm_regulator_req req; | ||
114 | int ret = 0; | ||
115 | |||
116 | req.key = RPM_KEY_UV; | ||
117 | req.nbytes = sizeof(u32); | ||
118 | req.value = min_uV; | ||
119 | |||
120 | ret = rpm_reg_write_active(vreg, &req, sizeof(req)); | ||
121 | if (!ret) | ||
122 | vreg->uV = min_uV; | ||
123 | |||
124 | return ret; | ||
125 | } | ||
126 | |||
127 | static int rpm_reg_set_load(struct regulator_dev *rdev, int load_uA) | ||
128 | { | ||
129 | struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); | ||
130 | struct rpm_regulator_req req; | ||
131 | |||
132 | req.key = RPM_KEY_MA; | ||
133 | req.nbytes = sizeof(u32); | ||
134 | req.value = load_uA; | ||
135 | |||
136 | return rpm_reg_write_active(vreg, &req, sizeof(req)); | ||
137 | } | ||
138 | |||
139 | static const struct regulator_ops rpm_smps_ldo_ops = { | ||
140 | .enable = rpm_reg_enable, | ||
141 | .disable = rpm_reg_disable, | ||
142 | .is_enabled = rpm_reg_is_enabled, | ||
143 | |||
144 | .get_voltage = rpm_reg_get_voltage, | ||
145 | .set_voltage = rpm_reg_set_voltage, | ||
146 | |||
147 | .set_load = rpm_reg_set_load, | ||
148 | }; | ||
149 | |||
150 | static const struct regulator_ops rpm_switch_ops = { | ||
151 | .enable = rpm_reg_enable, | ||
152 | .disable = rpm_reg_disable, | ||
153 | .is_enabled = rpm_reg_is_enabled, | ||
154 | }; | ||
155 | |||
156 | static const struct regulator_desc pm8x41_hfsmps = { | ||
157 | .linear_ranges = (struct regulator_linear_range[]) { | ||
158 | REGULATOR_LINEAR_RANGE( 375000, 0, 95, 12500), | ||
159 | REGULATOR_LINEAR_RANGE(1550000, 96, 158, 25000), | ||
160 | }, | ||
161 | .n_linear_ranges = 2, | ||
162 | .n_voltages = 159, | ||
163 | .ops = &rpm_smps_ldo_ops, | ||
164 | }; | ||
165 | |||
166 | static const struct regulator_desc pm8841_ftsmps = { | ||
167 | .linear_ranges = (struct regulator_linear_range[]) { | ||
168 | REGULATOR_LINEAR_RANGE(350000, 0, 184, 5000), | ||
169 | REGULATOR_LINEAR_RANGE(700000, 185, 339, 10000), | ||
170 | }, | ||
171 | .n_linear_ranges = 2, | ||
172 | .n_voltages = 340, | ||
173 | .ops = &rpm_smps_ldo_ops, | ||
174 | }; | ||
175 | |||
176 | static const struct regulator_desc pm8941_boost = { | ||
177 | .linear_ranges = (struct regulator_linear_range[]) { | ||
178 | REGULATOR_LINEAR_RANGE(4000000, 0, 15, 100000), | ||
179 | }, | ||
180 | .n_linear_ranges = 1, | ||
181 | .n_voltages = 16, | ||
182 | .ops = &rpm_smps_ldo_ops, | ||
183 | }; | ||
184 | |||
185 | static const struct regulator_desc pm8941_pldo = { | ||
186 | .linear_ranges = (struct regulator_linear_range[]) { | ||
187 | REGULATOR_LINEAR_RANGE( 750000, 0, 30, 25000), | ||
188 | REGULATOR_LINEAR_RANGE(1500000, 31, 99, 50000), | ||
189 | }, | ||
190 | .n_linear_ranges = 2, | ||
191 | .n_voltages = 100, | ||
192 | .ops = &rpm_smps_ldo_ops, | ||
193 | }; | ||
194 | |||
195 | static const struct regulator_desc pm8941_nldo = { | ||
196 | .linear_ranges = (struct regulator_linear_range[]) { | ||
197 | REGULATOR_LINEAR_RANGE(750000, 0, 63, 12500), | ||
198 | }, | ||
199 | .n_linear_ranges = 1, | ||
200 | .n_voltages = 64, | ||
201 | .ops = &rpm_smps_ldo_ops, | ||
202 | }; | ||
203 | |||
204 | static const struct regulator_desc pm8941_lnldo = { | ||
205 | .fixed_uV = 1740000, | ||
206 | .n_voltages = 1, | ||
207 | .ops = &rpm_smps_ldo_ops, | ||
208 | }; | ||
209 | |||
210 | static const struct regulator_desc pm8941_switch = { | ||
211 | .ops = &rpm_switch_ops, | ||
212 | }; | ||
213 | |||
214 | struct rpm_regulator_data { | ||
215 | const char *name; | ||
216 | u32 type; | ||
217 | u32 id; | ||
218 | const struct regulator_desc *desc; | ||
219 | const char *supply; | ||
220 | }; | ||
221 | |||
222 | static const struct rpm_regulator_data rpm_pm8841_regulators[] = { | ||
223 | { "s1", QCOM_SMD_RPM_SMPB, 1, &pm8x41_hfsmps, "vdd_s1" }, | ||
224 | { "s2", QCOM_SMD_RPM_SMPB, 2, &pm8841_ftsmps, "vdd_s2" }, | ||
225 | { "s3", QCOM_SMD_RPM_SMPB, 3, &pm8x41_hfsmps, "vdd_s3" }, | ||
226 | { "s4", QCOM_SMD_RPM_SMPB, 4, &pm8841_ftsmps, "vdd_s4" }, | ||
227 | { "s5", QCOM_SMD_RPM_SMPB, 5, &pm8841_ftsmps, "vdd_s5" }, | ||
228 | { "s6", QCOM_SMD_RPM_SMPB, 6, &pm8841_ftsmps, "vdd_s6" }, | ||
229 | { "s7", QCOM_SMD_RPM_SMPB, 7, &pm8841_ftsmps, "vdd_s7" }, | ||
230 | { "s8", QCOM_SMD_RPM_SMPB, 8, &pm8841_ftsmps, "vdd_s8" }, | ||
231 | {} | ||
232 | }; | ||
233 | |||
234 | static const struct rpm_regulator_data rpm_pm8941_regulators[] = { | ||
235 | { "s1", QCOM_SMD_RPM_SMPA, 1, &pm8x41_hfsmps, "vdd_s1" }, | ||
236 | { "s2", QCOM_SMD_RPM_SMPA, 2, &pm8x41_hfsmps, "vdd_s2" }, | ||
237 | { "s3", QCOM_SMD_RPM_SMPA, 3, &pm8x41_hfsmps, "vdd_s3" }, | ||
238 | { "s4", QCOM_SMD_RPM_BOOST, 1, &pm8941_boost }, | ||
239 | |||
240 | { "l1", QCOM_SMD_RPM_LDOA, 1, &pm8941_nldo, "vdd_l1_l3" }, | ||
241 | { "l2", QCOM_SMD_RPM_LDOA, 2, &pm8941_nldo, "vdd_l2_lvs1_2_3" }, | ||
242 | { "l3", QCOM_SMD_RPM_LDOA, 3, &pm8941_nldo, "vdd_l1_l3" }, | ||
243 | { "l4", QCOM_SMD_RPM_LDOA, 4, &pm8941_nldo, "vdd_l4_l11" }, | ||
244 | { "l5", QCOM_SMD_RPM_LDOA, 5, &pm8941_lnldo, "vdd_l5_l7" }, | ||
245 | { "l6", QCOM_SMD_RPM_LDOA, 6, &pm8941_pldo, "vdd_l6_l12_l14_l15" }, | ||
246 | { "l7", QCOM_SMD_RPM_LDOA, 7, &pm8941_lnldo, "vdd_l5_l7" }, | ||
247 | { "l8", QCOM_SMD_RPM_LDOA, 8, &pm8941_pldo, "vdd_l8_l16_l18_l19" }, | ||
248 | { "l9", QCOM_SMD_RPM_LDOA, 9, &pm8941_pldo, "vdd_l9_l10_l17_l22" }, | ||
249 | { "l10", QCOM_SMD_RPM_LDOA, 10, &pm8941_pldo, "vdd_l9_l10_l17_l22" }, | ||
250 | { "l11", QCOM_SMD_RPM_LDOA, 11, &pm8941_nldo, "vdd_l4_l11" }, | ||
251 | { "l12", QCOM_SMD_RPM_LDOA, 12, &pm8941_pldo, "vdd_l6_l12_l14_l15" }, | ||
252 | { "l13", QCOM_SMD_RPM_LDOA, 13, &pm8941_pldo, "vdd_l13_l20_l23_l24" }, | ||
253 | { "l14", QCOM_SMD_RPM_LDOA, 14, &pm8941_pldo, "vdd_l6_l12_l14_l15" }, | ||
254 | { "l15", QCOM_SMD_RPM_LDOA, 15, &pm8941_pldo, "vdd_l6_l12_l14_l15" }, | ||
255 | { "l16", QCOM_SMD_RPM_LDOA, 16, &pm8941_pldo, "vdd_l8_l16_l18_l19" }, | ||
256 | { "l17", QCOM_SMD_RPM_LDOA, 17, &pm8941_pldo, "vdd_l9_l10_l17_l22" }, | ||
257 | { "l18", QCOM_SMD_RPM_LDOA, 18, &pm8941_pldo, "vdd_l8_l16_l18_l19" }, | ||
258 | { "l19", QCOM_SMD_RPM_LDOA, 19, &pm8941_pldo, "vdd_l8_l16_l18_l19" }, | ||
259 | { "l20", QCOM_SMD_RPM_LDOA, 20, &pm8941_pldo, "vdd_l13_l20_l23_l24" }, | ||
260 | { "l21", QCOM_SMD_RPM_LDOA, 21, &pm8941_pldo, "vdd_l21" }, | ||
261 | { "l22", QCOM_SMD_RPM_LDOA, 22, &pm8941_pldo, "vdd_l9_l10_l17_l22" }, | ||
262 | { "l23", QCOM_SMD_RPM_LDOA, 23, &pm8941_pldo, "vdd_l13_l20_l23_l24" }, | ||
263 | { "l24", QCOM_SMD_RPM_LDOA, 24, &pm8941_pldo, "vdd_l13_l20_l23_l24" }, | ||
264 | |||
265 | { "lvs1", QCOM_SMD_RPM_VSA, 1, &pm8941_switch, "vdd_l2_lvs1_2_3" }, | ||
266 | { "lvs2", QCOM_SMD_RPM_VSA, 2, &pm8941_switch, "vdd_l2_lvs1_2_3" }, | ||
267 | { "lvs3", QCOM_SMD_RPM_VSA, 3, &pm8941_switch, "vdd_l2_lvs1_2_3" }, | ||
268 | |||
269 | { "5vs1", QCOM_SMD_RPM_VSA, 4, &pm8941_switch, "vin_5vs" }, | ||
270 | { "5vs2", QCOM_SMD_RPM_VSA, 5, &pm8941_switch, "vin_5vs" }, | ||
271 | |||
272 | {} | ||
273 | }; | ||
274 | |||
275 | static const struct of_device_id rpm_of_match[] = { | ||
276 | { .compatible = "qcom,rpm-pm8841-regulators", .data = &rpm_pm8841_regulators }, | ||
277 | { .compatible = "qcom,rpm-pm8941-regulators", .data = &rpm_pm8941_regulators }, | ||
278 | {} | ||
279 | }; | ||
280 | MODULE_DEVICE_TABLE(of, rpm_of_match); | ||
281 | |||
282 | static int rpm_reg_probe(struct platform_device *pdev) | ||
283 | { | ||
284 | const struct rpm_regulator_data *reg; | ||
285 | const struct of_device_id *match; | ||
286 | struct regulator_config config = { }; | ||
287 | struct regulator_dev *rdev; | ||
288 | struct qcom_rpm_reg *vreg; | ||
289 | struct qcom_smd_rpm *rpm; | ||
290 | |||
291 | rpm = dev_get_drvdata(pdev->dev.parent); | ||
292 | if (!rpm) { | ||
293 | dev_err(&pdev->dev, "unable to retrieve handle to rpm\n"); | ||
294 | return -ENODEV; | ||
295 | } | ||
296 | |||
297 | match = of_match_device(rpm_of_match, &pdev->dev); | ||
298 | for (reg = match->data; reg->name; reg++) { | ||
299 | vreg = devm_kzalloc(&pdev->dev, sizeof(*vreg), GFP_KERNEL); | ||
300 | if (!vreg) | ||
301 | return -ENOMEM; | ||
302 | |||
303 | vreg->dev = &pdev->dev; | ||
304 | vreg->type = reg->type; | ||
305 | vreg->id = reg->id; | ||
306 | vreg->rpm = rpm; | ||
307 | |||
308 | memcpy(&vreg->desc, reg->desc, sizeof(vreg->desc)); | ||
309 | |||
310 | vreg->desc.id = -1; | ||
311 | vreg->desc.owner = THIS_MODULE; | ||
312 | vreg->desc.type = REGULATOR_VOLTAGE; | ||
313 | vreg->desc.name = reg->name; | ||
314 | vreg->desc.supply_name = reg->supply; | ||
315 | vreg->desc.of_match = reg->name; | ||
316 | |||
317 | config.dev = &pdev->dev; | ||
318 | config.driver_data = vreg; | ||
319 | rdev = devm_regulator_register(&pdev->dev, &vreg->desc, &config); | ||
320 | if (IS_ERR(rdev)) { | ||
321 | dev_err(&pdev->dev, "failed to register %s\n", reg->name); | ||
322 | return PTR_ERR(rdev); | ||
323 | } | ||
324 | } | ||
325 | |||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | static struct platform_driver rpm_reg_driver = { | ||
330 | .probe = rpm_reg_probe, | ||
331 | .driver = { | ||
332 | .name = "qcom_rpm_smd_regulator", | ||
333 | .of_match_table = rpm_of_match, | ||
334 | }, | ||
335 | }; | ||
336 | |||
337 | static int __init rpm_reg_init(void) | ||
338 | { | ||
339 | return platform_driver_register(&rpm_reg_driver); | ||
340 | } | ||
341 | subsys_initcall(rpm_reg_init); | ||
342 | |||
343 | static void __exit rpm_reg_exit(void) | ||
344 | { | ||
345 | platform_driver_unregister(&rpm_reg_driver); | ||
346 | } | ||
347 | module_exit(rpm_reg_exit) | ||
348 | |||
349 | MODULE_DESCRIPTION("Qualcomm RPM regulator driver"); | ||
350 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c index 850a30a95b5b..88a5dc88badc 100644 --- a/drivers/regulator/qcom_spmi-regulator.c +++ b/drivers/regulator/qcom_spmi-regulator.c | |||
@@ -26,6 +26,70 @@ | |||
26 | #include <linux/regmap.h> | 26 | #include <linux/regmap.h> |
27 | #include <linux/list.h> | 27 | #include <linux/list.h> |
28 | 28 | ||
29 | /* Pin control enable input pins. */ | ||
30 | #define SPMI_REGULATOR_PIN_CTRL_ENABLE_NONE 0x00 | ||
31 | #define SPMI_REGULATOR_PIN_CTRL_ENABLE_EN0 0x01 | ||
32 | #define SPMI_REGULATOR_PIN_CTRL_ENABLE_EN1 0x02 | ||
33 | #define SPMI_REGULATOR_PIN_CTRL_ENABLE_EN2 0x04 | ||
34 | #define SPMI_REGULATOR_PIN_CTRL_ENABLE_EN3 0x08 | ||
35 | #define SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT 0x10 | ||
36 | |||
37 | /* Pin control high power mode input pins. */ | ||
38 | #define SPMI_REGULATOR_PIN_CTRL_HPM_NONE 0x00 | ||
39 | #define SPMI_REGULATOR_PIN_CTRL_HPM_EN0 0x01 | ||
40 | #define SPMI_REGULATOR_PIN_CTRL_HPM_EN1 0x02 | ||
41 | #define SPMI_REGULATOR_PIN_CTRL_HPM_EN2 0x04 | ||
42 | #define SPMI_REGULATOR_PIN_CTRL_HPM_EN3 0x08 | ||
43 | #define SPMI_REGULATOR_PIN_CTRL_HPM_SLEEP_B 0x10 | ||
44 | #define SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT 0x20 | ||
45 | |||
46 | /* | ||
47 | * Used with enable parameters to specify that hardware default register values | ||
48 | * should be left unaltered. | ||
49 | */ | ||
50 | #define SPMI_REGULATOR_USE_HW_DEFAULT 2 | ||
51 | |||
52 | /* Soft start strength of a voltage switch type regulator */ | ||
53 | enum spmi_vs_soft_start_str { | ||
54 | SPMI_VS_SOFT_START_STR_0P05_UA = 0, | ||
55 | SPMI_VS_SOFT_START_STR_0P25_UA, | ||
56 | SPMI_VS_SOFT_START_STR_0P55_UA, | ||
57 | SPMI_VS_SOFT_START_STR_0P75_UA, | ||
58 | SPMI_VS_SOFT_START_STR_HW_DEFAULT, | ||
59 | }; | ||
60 | |||
61 | /** | ||
62 | * struct spmi_regulator_init_data - spmi-regulator initialization data | ||
63 | * @pin_ctrl_enable: Bit mask specifying which hardware pins should be | ||
64 | * used to enable the regulator, if any | ||
65 | * Value should be an ORing of | ||
66 | * SPMI_REGULATOR_PIN_CTRL_ENABLE_* constants. If | ||
67 | * the bit specified by | ||
68 | * SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT is | ||
69 | * set, then pin control enable hardware registers | ||
70 | * will not be modified. | ||
71 | * @pin_ctrl_hpm: Bit mask specifying which hardware pins should be | ||
72 | * used to force the regulator into high power | ||
73 | * mode, if any | ||
74 | * Value should be an ORing of | ||
75 | * SPMI_REGULATOR_PIN_CTRL_HPM_* constants. If | ||
76 | * the bit specified by | ||
77 | * SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT is | ||
78 | * set, then pin control mode hardware registers | ||
79 | * will not be modified. | ||
80 | * @vs_soft_start_strength: This parameter sets the soft start strength for | ||
81 | * voltage switch type regulators. Its value | ||
82 | * should be one of SPMI_VS_SOFT_START_STR_*. If | ||
83 | * its value is SPMI_VS_SOFT_START_STR_HW_DEFAULT, | ||
84 | * then the soft start strength will be left at its | ||
85 | * default hardware value. | ||
86 | */ | ||
87 | struct spmi_regulator_init_data { | ||
88 | unsigned pin_ctrl_enable; | ||
89 | unsigned pin_ctrl_hpm; | ||
90 | enum spmi_vs_soft_start_str vs_soft_start_strength; | ||
91 | }; | ||
92 | |||
29 | /* These types correspond to unique register layouts. */ | 93 | /* These types correspond to unique register layouts. */ |
30 | enum spmi_regulator_logical_type { | 94 | enum spmi_regulator_logical_type { |
31 | SPMI_REGULATOR_LOGICAL_TYPE_SMPS, | 95 | SPMI_REGULATOR_LOGICAL_TYPE_SMPS, |
@@ -458,6 +522,14 @@ static int spmi_regulator_vs_enable(struct regulator_dev *rdev) | |||
458 | return spmi_regulator_common_enable(rdev); | 522 | return spmi_regulator_common_enable(rdev); |
459 | } | 523 | } |
460 | 524 | ||
525 | static int spmi_regulator_vs_ocp(struct regulator_dev *rdev) | ||
526 | { | ||
527 | struct spmi_regulator *vreg = rdev_get_drvdata(rdev); | ||
528 | u8 reg = SPMI_VS_OCP_OVERRIDE; | ||
529 | |||
530 | return spmi_vreg_write(vreg, SPMI_VS_REG_OCP, ®, 1); | ||
531 | } | ||
532 | |||
461 | static int spmi_regulator_common_disable(struct regulator_dev *rdev) | 533 | static int spmi_regulator_common_disable(struct regulator_dev *rdev) |
462 | { | 534 | { |
463 | struct spmi_regulator *vreg = rdev_get_drvdata(rdev); | 535 | struct spmi_regulator *vreg = rdev_get_drvdata(rdev); |
@@ -504,8 +576,7 @@ static int spmi_regulator_select_voltage(struct spmi_regulator *vreg, | |||
504 | * Force uV to be an allowed set point by applying a ceiling function to | 576 | * Force uV to be an allowed set point by applying a ceiling function to |
505 | * the uV value. | 577 | * the uV value. |
506 | */ | 578 | */ |
507 | *voltage_sel = (uV - range->min_uV + range->step_uV - 1) | 579 | *voltage_sel = DIV_ROUND_UP(uV - range->min_uV, range->step_uV); |
508 | / range->step_uV; | ||
509 | uV = *voltage_sel * range->step_uV + range->min_uV; | 580 | uV = *voltage_sel * range->step_uV + range->min_uV; |
510 | 581 | ||
511 | if (uV > max_uV) { | 582 | if (uV > max_uV) { |
@@ -792,6 +863,9 @@ static unsigned int spmi_regulator_common_get_mode(struct regulator_dev *rdev) | |||
792 | if (reg & SPMI_COMMON_MODE_HPM_MASK) | 863 | if (reg & SPMI_COMMON_MODE_HPM_MASK) |
793 | return REGULATOR_MODE_NORMAL; | 864 | return REGULATOR_MODE_NORMAL; |
794 | 865 | ||
866 | if (reg & SPMI_COMMON_MODE_AUTO_MASK) | ||
867 | return REGULATOR_MODE_FAST; | ||
868 | |||
795 | return REGULATOR_MODE_IDLE; | 869 | return REGULATOR_MODE_IDLE; |
796 | } | 870 | } |
797 | 871 | ||
@@ -799,11 +873,13 @@ static int | |||
799 | spmi_regulator_common_set_mode(struct regulator_dev *rdev, unsigned int mode) | 873 | spmi_regulator_common_set_mode(struct regulator_dev *rdev, unsigned int mode) |
800 | { | 874 | { |
801 | struct spmi_regulator *vreg = rdev_get_drvdata(rdev); | 875 | struct spmi_regulator *vreg = rdev_get_drvdata(rdev); |
802 | u8 mask = SPMI_COMMON_MODE_HPM_MASK; | 876 | u8 mask = SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK; |
803 | u8 val = 0; | 877 | u8 val = 0; |
804 | 878 | ||
805 | if (mode == REGULATOR_MODE_NORMAL) | 879 | if (mode == REGULATOR_MODE_NORMAL) |
806 | val = mask; | 880 | val = SPMI_COMMON_MODE_HPM_MASK; |
881 | else if (mode == REGULATOR_MODE_FAST) | ||
882 | val = SPMI_COMMON_MODE_AUTO_MASK; | ||
807 | 883 | ||
808 | return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); | 884 | return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); |
809 | } | 885 | } |
@@ -973,6 +1049,7 @@ static struct regulator_ops spmi_vs_ops = { | |||
973 | .is_enabled = spmi_regulator_common_is_enabled, | 1049 | .is_enabled = spmi_regulator_common_is_enabled, |
974 | .set_pull_down = spmi_regulator_common_set_pull_down, | 1050 | .set_pull_down = spmi_regulator_common_set_pull_down, |
975 | .set_soft_start = spmi_regulator_common_set_soft_start, | 1051 | .set_soft_start = spmi_regulator_common_set_soft_start, |
1052 | .set_over_current_protection = spmi_regulator_vs_ocp, | ||
976 | }; | 1053 | }; |
977 | 1054 | ||
978 | static struct regulator_ops spmi_boost_ops = { | 1055 | static struct regulator_ops spmi_boost_ops = { |
@@ -1203,10 +1280,111 @@ static int spmi_regulator_ftsmps_init_slew_rate(struct spmi_regulator *vreg) | |||
1203 | return ret; | 1280 | return ret; |
1204 | } | 1281 | } |
1205 | 1282 | ||
1283 | static int spmi_regulator_init_registers(struct spmi_regulator *vreg, | ||
1284 | const struct spmi_regulator_init_data *data) | ||
1285 | { | ||
1286 | int ret; | ||
1287 | enum spmi_regulator_logical_type type; | ||
1288 | u8 ctrl_reg[8], reg, mask; | ||
1289 | |||
1290 | type = vreg->logical_type; | ||
1291 | |||
1292 | ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, ctrl_reg, 8); | ||
1293 | if (ret) | ||
1294 | return ret; | ||
1295 | |||
1296 | /* Set up enable pin control. */ | ||
1297 | if ((type == SPMI_REGULATOR_LOGICAL_TYPE_SMPS | ||
1298 | || type == SPMI_REGULATOR_LOGICAL_TYPE_LDO | ||
1299 | || type == SPMI_REGULATOR_LOGICAL_TYPE_VS) | ||
1300 | && !(data->pin_ctrl_enable | ||
1301 | & SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT)) { | ||
1302 | ctrl_reg[SPMI_COMMON_IDX_ENABLE] &= | ||
1303 | ~SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK; | ||
1304 | ctrl_reg[SPMI_COMMON_IDX_ENABLE] |= | ||
1305 | data->pin_ctrl_enable & SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK; | ||
1306 | } | ||
1307 | |||
1308 | /* Set up mode pin control. */ | ||
1309 | if ((type == SPMI_REGULATOR_LOGICAL_TYPE_SMPS | ||
1310 | || type == SPMI_REGULATOR_LOGICAL_TYPE_LDO) | ||
1311 | && !(data->pin_ctrl_hpm | ||
1312 | & SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) { | ||
1313 | ctrl_reg[SPMI_COMMON_IDX_MODE] &= | ||
1314 | ~SPMI_COMMON_MODE_FOLLOW_ALL_MASK; | ||
1315 | ctrl_reg[SPMI_COMMON_IDX_MODE] |= | ||
1316 | data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_ALL_MASK; | ||
1317 | } | ||
1318 | |||
1319 | if (type == SPMI_REGULATOR_LOGICAL_TYPE_VS | ||
1320 | && !(data->pin_ctrl_hpm & SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) { | ||
1321 | ctrl_reg[SPMI_COMMON_IDX_MODE] &= | ||
1322 | ~SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK; | ||
1323 | ctrl_reg[SPMI_COMMON_IDX_MODE] |= | ||
1324 | data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK; | ||
1325 | } | ||
1326 | |||
1327 | if ((type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS | ||
1328 | || type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS | ||
1329 | || type == SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO) | ||
1330 | && !(data->pin_ctrl_hpm | ||
1331 | & SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) { | ||
1332 | ctrl_reg[SPMI_COMMON_IDX_MODE] &= | ||
1333 | ~SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK; | ||
1334 | ctrl_reg[SPMI_COMMON_IDX_MODE] |= | ||
1335 | data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK; | ||
1336 | } | ||
1337 | |||
1338 | /* Write back any control register values that were modified. */ | ||
1339 | ret = spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, ctrl_reg, 8); | ||
1340 | if (ret) | ||
1341 | return ret; | ||
1342 | |||
1343 | /* Set soft start strength and over current protection for VS. */ | ||
1344 | if (type == SPMI_REGULATOR_LOGICAL_TYPE_VS) { | ||
1345 | if (data->vs_soft_start_strength | ||
1346 | != SPMI_VS_SOFT_START_STR_HW_DEFAULT) { | ||
1347 | reg = data->vs_soft_start_strength | ||
1348 | & SPMI_VS_SOFT_START_SEL_MASK; | ||
1349 | mask = SPMI_VS_SOFT_START_SEL_MASK; | ||
1350 | return spmi_vreg_update_bits(vreg, | ||
1351 | SPMI_VS_REG_SOFT_START, | ||
1352 | reg, mask); | ||
1353 | } | ||
1354 | } | ||
1355 | |||
1356 | return 0; | ||
1357 | } | ||
1358 | |||
1359 | static void spmi_regulator_get_dt_config(struct spmi_regulator *vreg, | ||
1360 | struct device_node *node, struct spmi_regulator_init_data *data) | ||
1361 | { | ||
1362 | /* | ||
1363 | * Initialize configuration parameters to use hardware default in case | ||
1364 | * no value is specified via device tree. | ||
1365 | */ | ||
1366 | data->pin_ctrl_enable = SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT; | ||
1367 | data->pin_ctrl_hpm = SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT; | ||
1368 | data->vs_soft_start_strength = SPMI_VS_SOFT_START_STR_HW_DEFAULT; | ||
1369 | |||
1370 | /* These bindings are optional, so it is okay if they aren't found. */ | ||
1371 | of_property_read_u32(node, "qcom,ocp-max-retries", | ||
1372 | &vreg->ocp_max_retries); | ||
1373 | of_property_read_u32(node, "qcom,ocp-retry-delay", | ||
1374 | &vreg->ocp_retry_delay_ms); | ||
1375 | of_property_read_u32(node, "qcom,pin-ctrl-enable", | ||
1376 | &data->pin_ctrl_enable); | ||
1377 | of_property_read_u32(node, "qcom,pin-ctrl-hpm", &data->pin_ctrl_hpm); | ||
1378 | of_property_read_u32(node, "qcom,vs-soft-start-strength", | ||
1379 | &data->vs_soft_start_strength); | ||
1380 | } | ||
1381 | |||
1206 | static unsigned int spmi_regulator_of_map_mode(unsigned int mode) | 1382 | static unsigned int spmi_regulator_of_map_mode(unsigned int mode) |
1207 | { | 1383 | { |
1208 | if (mode) | 1384 | if (mode == 1) |
1209 | return REGULATOR_MODE_NORMAL; | 1385 | return REGULATOR_MODE_NORMAL; |
1386 | if (mode == 2) | ||
1387 | return REGULATOR_MODE_FAST; | ||
1210 | 1388 | ||
1211 | return REGULATOR_MODE_IDLE; | 1389 | return REGULATOR_MODE_IDLE; |
1212 | } | 1390 | } |
@@ -1215,12 +1393,23 @@ static int spmi_regulator_of_parse(struct device_node *node, | |||
1215 | const struct regulator_desc *desc, | 1393 | const struct regulator_desc *desc, |
1216 | struct regulator_config *config) | 1394 | struct regulator_config *config) |
1217 | { | 1395 | { |
1396 | struct spmi_regulator_init_data data = { }; | ||
1218 | struct spmi_regulator *vreg = config->driver_data; | 1397 | struct spmi_regulator *vreg = config->driver_data; |
1219 | struct device *dev = config->dev; | 1398 | struct device *dev = config->dev; |
1220 | int ret; | 1399 | int ret; |
1221 | 1400 | ||
1222 | vreg->ocp_max_retries = SPMI_VS_OCP_DEFAULT_MAX_RETRIES; | 1401 | spmi_regulator_get_dt_config(vreg, node, &data); |
1223 | vreg->ocp_retry_delay_ms = SPMI_VS_OCP_DEFAULT_RETRY_DELAY_MS; | 1402 | |
1403 | if (!vreg->ocp_max_retries) | ||
1404 | vreg->ocp_max_retries = SPMI_VS_OCP_DEFAULT_MAX_RETRIES; | ||
1405 | if (!vreg->ocp_retry_delay_ms) | ||
1406 | vreg->ocp_retry_delay_ms = SPMI_VS_OCP_DEFAULT_RETRY_DELAY_MS; | ||
1407 | |||
1408 | ret = spmi_regulator_init_registers(vreg, &data); | ||
1409 | if (ret) { | ||
1410 | dev_err(dev, "common initialization failed, ret=%d\n", ret); | ||
1411 | return ret; | ||
1412 | } | ||
1224 | 1413 | ||
1225 | if (vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS) { | 1414 | if (vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS) { |
1226 | ret = spmi_regulator_ftsmps_init_slew_rate(vreg); | 1415 | ret = spmi_regulator_ftsmps_init_slew_rate(vreg); |
diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c index 3fd44353cc80..d86a3dcd61e2 100644 --- a/drivers/regulator/rk808-regulator.c +++ b/drivers/regulator/rk808-regulator.c | |||
@@ -16,12 +16,16 @@ | |||
16 | * more details. | 16 | * more details. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <linux/module.h> | 19 | #include <linux/delay.h> |
20 | #include <linux/gpio.h> | ||
20 | #include <linux/i2c.h> | 21 | #include <linux/i2c.h> |
21 | #include <linux/mfd/rk808.h> | 22 | #include <linux/module.h> |
22 | #include <linux/of_device.h> | 23 | #include <linux/of_device.h> |
24 | #include <linux/of_gpio.h> | ||
25 | #include <linux/mfd/rk808.h> | ||
23 | #include <linux/regulator/driver.h> | 26 | #include <linux/regulator/driver.h> |
24 | #include <linux/regulator/of_regulator.h> | 27 | #include <linux/regulator/of_regulator.h> |
28 | #include <linux/gpio/consumer.h> | ||
25 | 29 | ||
26 | /* Field Definitions */ | 30 | /* Field Definitions */ |
27 | #define RK808_BUCK_VSEL_MASK 0x3f | 31 | #define RK808_BUCK_VSEL_MASK 0x3f |
@@ -36,12 +40,25 @@ | |||
36 | #define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET) | 40 | #define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET) |
37 | #define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET) | 41 | #define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET) |
38 | 42 | ||
43 | #define RK808_DVS2_POL BIT(2) | ||
44 | #define RK808_DVS1_POL BIT(1) | ||
45 | |||
39 | /* Offset from XXX_ON_VSEL to XXX_SLP_VSEL */ | 46 | /* Offset from XXX_ON_VSEL to XXX_SLP_VSEL */ |
40 | #define RK808_SLP_REG_OFFSET 1 | 47 | #define RK808_SLP_REG_OFFSET 1 |
41 | 48 | ||
49 | /* Offset from XXX_ON_VSEL to XXX_DVS_VSEL */ | ||
50 | #define RK808_DVS_REG_OFFSET 2 | ||
51 | |||
42 | /* Offset from XXX_EN_REG to SLEEP_SET_OFF_XXX */ | 52 | /* Offset from XXX_EN_REG to SLEEP_SET_OFF_XXX */ |
43 | #define RK808_SLP_SET_OFF_REG_OFFSET 2 | 53 | #define RK808_SLP_SET_OFF_REG_OFFSET 2 |
44 | 54 | ||
55 | /* max steps for increase voltage of Buck1/2, equal 100mv*/ | ||
56 | #define MAX_STEPS_ONE_TIME 8 | ||
57 | |||
58 | struct rk808_regulator_data { | ||
59 | struct gpio_desc *dvs_gpio[2]; | ||
60 | }; | ||
61 | |||
45 | static const int rk808_buck_config_regs[] = { | 62 | static const int rk808_buck_config_regs[] = { |
46 | RK808_BUCK1_CONFIG_REG, | 63 | RK808_BUCK1_CONFIG_REG, |
47 | RK808_BUCK2_CONFIG_REG, | 64 | RK808_BUCK2_CONFIG_REG, |
@@ -70,6 +87,131 @@ static const struct regulator_linear_range rk808_ldo6_voltage_ranges[] = { | |||
70 | REGULATOR_LINEAR_RANGE(800000, 0, 17, 100000), | 87 | REGULATOR_LINEAR_RANGE(800000, 0, 17, 100000), |
71 | }; | 88 | }; |
72 | 89 | ||
90 | static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev) | ||
91 | { | ||
92 | struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); | ||
93 | int id = rdev->desc->id - RK808_ID_DCDC1; | ||
94 | struct gpio_desc *gpio = pdata->dvs_gpio[id]; | ||
95 | unsigned int val; | ||
96 | int ret; | ||
97 | |||
98 | if (!gpio || gpiod_get_value(gpio) == 0) | ||
99 | return regulator_get_voltage_sel_regmap(rdev); | ||
100 | |||
101 | ret = regmap_read(rdev->regmap, | ||
102 | rdev->desc->vsel_reg + RK808_DVS_REG_OFFSET, | ||
103 | &val); | ||
104 | if (ret != 0) | ||
105 | return ret; | ||
106 | |||
107 | val &= rdev->desc->vsel_mask; | ||
108 | val >>= ffs(rdev->desc->vsel_mask) - 1; | ||
109 | |||
110 | return val; | ||
111 | } | ||
112 | |||
113 | static int rk808_buck1_2_i2c_set_voltage_sel(struct regulator_dev *rdev, | ||
114 | unsigned sel) | ||
115 | { | ||
116 | int ret, delta_sel; | ||
117 | unsigned int old_sel, tmp, val, mask = rdev->desc->vsel_mask; | ||
118 | |||
119 | ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val); | ||
120 | if (ret != 0) | ||
121 | return ret; | ||
122 | |||
123 | tmp = val & ~mask; | ||
124 | old_sel = val & mask; | ||
125 | old_sel >>= ffs(mask) - 1; | ||
126 | delta_sel = sel - old_sel; | ||
127 | |||
128 | /* | ||
129 | * If directly modify the register to change the voltage, we will face | ||
130 | * the risk of overshoot. Put it into a multi-step, can effectively | ||
131 | * avoid this problem, a step is 100mv here. | ||
132 | */ | ||
133 | while (delta_sel > MAX_STEPS_ONE_TIME) { | ||
134 | old_sel += MAX_STEPS_ONE_TIME; | ||
135 | val = old_sel << (ffs(mask) - 1); | ||
136 | val |= tmp; | ||
137 | |||
138 | /* | ||
139 | * i2c is 400kHz (2.5us per bit) and we must transmit _at least_ | ||
140 | * 3 bytes (24 bits) plus start and stop so 26 bits. So we've | ||
141 | * got more than 65 us between each voltage change and thus | ||
142 | * won't ramp faster than ~1500 uV / us. | ||
143 | */ | ||
144 | ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val); | ||
145 | delta_sel = sel - old_sel; | ||
146 | } | ||
147 | |||
148 | sel <<= ffs(mask) - 1; | ||
149 | val = tmp | sel; | ||
150 | ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val); | ||
151 | |||
152 | /* | ||
153 | * When we change the voltage register directly, the ramp rate is about | ||
154 | * 100000uv/us, wait 1us to make sure the target voltage to be stable, | ||
155 | * so we needn't wait extra time after that. | ||
156 | */ | ||
157 | udelay(1); | ||
158 | |||
159 | return ret; | ||
160 | } | ||
161 | |||
162 | static int rk808_buck1_2_set_voltage_sel(struct regulator_dev *rdev, | ||
163 | unsigned sel) | ||
164 | { | ||
165 | struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); | ||
166 | int id = rdev->desc->id - RK808_ID_DCDC1; | ||
167 | struct gpio_desc *gpio = pdata->dvs_gpio[id]; | ||
168 | unsigned int reg = rdev->desc->vsel_reg; | ||
169 | unsigned old_sel; | ||
170 | int ret, gpio_level; | ||
171 | |||
172 | if (!gpio) | ||
173 | return rk808_buck1_2_i2c_set_voltage_sel(rdev, sel); | ||
174 | |||
175 | gpio_level = gpiod_get_value(gpio); | ||
176 | if (gpio_level == 0) { | ||
177 | reg += RK808_DVS_REG_OFFSET; | ||
178 | ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &old_sel); | ||
179 | } else { | ||
180 | ret = regmap_read(rdev->regmap, | ||
181 | reg + RK808_DVS_REG_OFFSET, | ||
182 | &old_sel); | ||
183 | } | ||
184 | |||
185 | if (ret != 0) | ||
186 | return ret; | ||
187 | |||
188 | sel <<= ffs(rdev->desc->vsel_mask) - 1; | ||
189 | sel |= old_sel & ~rdev->desc->vsel_mask; | ||
190 | |||
191 | ret = regmap_write(rdev->regmap, reg, sel); | ||
192 | if (ret) | ||
193 | return ret; | ||
194 | |||
195 | gpiod_set_value(gpio, !gpio_level); | ||
196 | |||
197 | return ret; | ||
198 | } | ||
199 | |||
200 | static int rk808_buck1_2_set_voltage_time_sel(struct regulator_dev *rdev, | ||
201 | unsigned int old_selector, | ||
202 | unsigned int new_selector) | ||
203 | { | ||
204 | struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); | ||
205 | int id = rdev->desc->id - RK808_ID_DCDC1; | ||
206 | struct gpio_desc *gpio = pdata->dvs_gpio[id]; | ||
207 | |||
208 | /* if there is no dvs1/2 pin, we don't need wait extra time here. */ | ||
209 | if (!gpio) | ||
210 | return 0; | ||
211 | |||
212 | return regulator_set_voltage_time_sel(rdev, old_selector, new_selector); | ||
213 | } | ||
214 | |||
73 | static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) | 215 | static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) |
74 | { | 216 | { |
75 | unsigned int ramp_value = RK808_RAMP_RATE_10MV_PER_US; | 217 | unsigned int ramp_value = RK808_RAMP_RATE_10MV_PER_US; |
@@ -137,8 +279,9 @@ static int rk808_set_suspend_disable(struct regulator_dev *rdev) | |||
137 | static struct regulator_ops rk808_buck1_2_ops = { | 279 | static struct regulator_ops rk808_buck1_2_ops = { |
138 | .list_voltage = regulator_list_voltage_linear_range, | 280 | .list_voltage = regulator_list_voltage_linear_range, |
139 | .map_voltage = regulator_map_voltage_linear_range, | 281 | .map_voltage = regulator_map_voltage_linear_range, |
140 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 282 | .get_voltage_sel = rk808_buck1_2_get_voltage_sel_regmap, |
141 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 283 | .set_voltage_sel = rk808_buck1_2_set_voltage_sel, |
284 | .set_voltage_time_sel = rk808_buck1_2_set_voltage_time_sel, | ||
142 | .enable = regulator_enable_regmap, | 285 | .enable = regulator_enable_regmap, |
143 | .disable = regulator_disable_regmap, | 286 | .disable = regulator_disable_regmap, |
144 | .is_enabled = regulator_is_enabled_regmap, | 287 | .is_enabled = regulator_is_enabled_regmap, |
@@ -380,25 +523,69 @@ static struct of_regulator_match rk808_reg_matches[] = { | |||
380 | [RK808_ID_SWITCH2] = { .name = "SWITCH_REG2" }, | 523 | [RK808_ID_SWITCH2] = { .name = "SWITCH_REG2" }, |
381 | }; | 524 | }; |
382 | 525 | ||
526 | static int rk808_regulator_dt_parse_pdata(struct device *dev, | ||
527 | struct device *client_dev, | ||
528 | struct regmap *map, | ||
529 | struct rk808_regulator_data *pdata) | ||
530 | { | ||
531 | struct device_node *np; | ||
532 | int tmp, ret, i; | ||
533 | |||
534 | np = of_get_child_by_name(client_dev->of_node, "regulators"); | ||
535 | if (!np) | ||
536 | return -ENXIO; | ||
537 | |||
538 | ret = of_regulator_match(dev, np, rk808_reg_matches, | ||
539 | RK808_NUM_REGULATORS); | ||
540 | if (ret < 0) | ||
541 | goto dt_parse_end; | ||
542 | |||
543 | for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) { | ||
544 | pdata->dvs_gpio[i] = | ||
545 | devm_gpiod_get_index_optional(client_dev, "dvs", i, | ||
546 | GPIOD_OUT_LOW); | ||
547 | if (IS_ERR(pdata->dvs_gpio[i])) { | ||
548 | ret = PTR_ERR(pdata->dvs_gpio[i]); | ||
549 | dev_err(dev, "failed to get dvs%d gpio (%d)\n", i, ret); | ||
550 | goto dt_parse_end; | ||
551 | } | ||
552 | |||
553 | if (!pdata->dvs_gpio[i]) { | ||
554 | dev_warn(dev, "there is no dvs%d gpio\n", i); | ||
555 | continue; | ||
556 | } | ||
557 | |||
558 | tmp = i ? RK808_DVS2_POL : RK808_DVS1_POL; | ||
559 | ret = regmap_update_bits(map, RK808_IO_POL_REG, tmp, | ||
560 | gpiod_is_active_low(pdata->dvs_gpio[i]) ? | ||
561 | 0 : tmp); | ||
562 | } | ||
563 | |||
564 | dt_parse_end: | ||
565 | of_node_put(np); | ||
566 | return ret; | ||
567 | } | ||
568 | |||
383 | static int rk808_regulator_probe(struct platform_device *pdev) | 569 | static int rk808_regulator_probe(struct platform_device *pdev) |
384 | { | 570 | { |
385 | struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent); | 571 | struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent); |
386 | struct i2c_client *client = rk808->i2c; | 572 | struct i2c_client *client = rk808->i2c; |
387 | struct device_node *reg_np; | ||
388 | struct regulator_config config = {}; | 573 | struct regulator_config config = {}; |
389 | struct regulator_dev *rk808_rdev; | 574 | struct regulator_dev *rk808_rdev; |
575 | struct rk808_regulator_data *pdata; | ||
390 | int ret, i; | 576 | int ret, i; |
391 | 577 | ||
392 | reg_np = of_get_child_by_name(client->dev.of_node, "regulators"); | 578 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
393 | if (!reg_np) | 579 | if (!pdata) |
394 | return -ENXIO; | 580 | return -ENOMEM; |
395 | 581 | ||
396 | ret = of_regulator_match(&pdev->dev, reg_np, rk808_reg_matches, | 582 | ret = rk808_regulator_dt_parse_pdata(&pdev->dev, &client->dev, |
397 | RK808_NUM_REGULATORS); | 583 | rk808->regmap, pdata); |
398 | of_node_put(reg_np); | ||
399 | if (ret < 0) | 584 | if (ret < 0) |
400 | return ret; | 585 | return ret; |
401 | 586 | ||
587 | platform_set_drvdata(pdev, pdata); | ||
588 | |||
402 | /* Instantiate the regulators */ | 589 | /* Instantiate the regulators */ |
403 | for (i = 0; i < RK808_NUM_REGULATORS; i++) { | 590 | for (i = 0; i < RK808_NUM_REGULATORS; i++) { |
404 | if (!rk808_reg_matches[i].init_data || | 591 | if (!rk808_reg_matches[i].init_data || |
@@ -406,7 +593,7 @@ static int rk808_regulator_probe(struct platform_device *pdev) | |||
406 | continue; | 593 | continue; |
407 | 594 | ||
408 | config.dev = &client->dev; | 595 | config.dev = &client->dev; |
409 | config.driver_data = rk808; | 596 | config.driver_data = pdata; |
410 | config.regmap = rk808->regmap; | 597 | config.regmap = rk808->regmap; |
411 | config.of_node = rk808_reg_matches[i].of_node; | 598 | config.of_node = rk808_reg_matches[i].of_node; |
412 | config.init_data = rk808_reg_matches[i].init_data; | 599 | config.init_data = rk808_reg_matches[i].init_data; |
@@ -427,6 +614,7 @@ static struct platform_driver rk808_regulator_driver = { | |||
427 | .probe = rk808_regulator_probe, | 614 | .probe = rk808_regulator_probe, |
428 | .driver = { | 615 | .driver = { |
429 | .name = "rk808-regulator", | 616 | .name = "rk808-regulator", |
617 | .owner = THIS_MODULE, | ||
430 | }, | 618 | }, |
431 | }; | 619 | }; |
432 | 620 | ||
diff --git a/drivers/regulator/tps51632-regulator.c b/drivers/regulator/tps51632-regulator.c index c213e37eb69e..572816e30095 100644 --- a/drivers/regulator/tps51632-regulator.c +++ b/drivers/regulator/tps51632-regulator.c | |||
@@ -362,7 +362,6 @@ MODULE_DEVICE_TABLE(i2c, tps51632_id); | |||
362 | static struct i2c_driver tps51632_i2c_driver = { | 362 | static struct i2c_driver tps51632_i2c_driver = { |
363 | .driver = { | 363 | .driver = { |
364 | .name = "tps51632", | 364 | .name = "tps51632", |
365 | .owner = THIS_MODULE, | ||
366 | .of_match_table = of_match_ptr(tps51632_of_match), | 365 | .of_match_table = of_match_ptr(tps51632_of_match), |
367 | }, | 366 | }, |
368 | .probe = tps51632_probe, | 367 | .probe = tps51632_probe, |
diff --git a/drivers/regulator/tps62360-regulator.c b/drivers/regulator/tps62360-regulator.c index a1fd626c6c96..f6a6d36a6533 100644 --- a/drivers/regulator/tps62360-regulator.c +++ b/drivers/regulator/tps62360-regulator.c | |||
@@ -515,7 +515,6 @@ MODULE_DEVICE_TABLE(i2c, tps62360_id); | |||
515 | static struct i2c_driver tps62360_i2c_driver = { | 515 | static struct i2c_driver tps62360_i2c_driver = { |
516 | .driver = { | 516 | .driver = { |
517 | .name = "tps62360", | 517 | .name = "tps62360", |
518 | .owner = THIS_MODULE, | ||
519 | .of_match_table = of_match_ptr(tps62360_of_match), | 518 | .of_match_table = of_match_ptr(tps62360_of_match), |
520 | }, | 519 | }, |
521 | .probe = tps62360_probe, | 520 | .probe = tps62360_probe, |
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c index b941e564b3f3..5cc19b44974a 100644 --- a/drivers/regulator/tps65023-regulator.c +++ b/drivers/regulator/tps65023-regulator.c | |||
@@ -410,7 +410,6 @@ MODULE_DEVICE_TABLE(i2c, tps_65023_id); | |||
410 | static struct i2c_driver tps_65023_i2c_driver = { | 410 | static struct i2c_driver tps_65023_i2c_driver = { |
411 | .driver = { | 411 | .driver = { |
412 | .name = "tps65023", | 412 | .name = "tps65023", |
413 | .owner = THIS_MODULE, | ||
414 | }, | 413 | }, |
415 | .probe = tps_65023_probe, | 414 | .probe = tps_65023_probe, |
416 | .id_table = tps_65023_id, | 415 | .id_table = tps_65023_id, |
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c index 2852de05d64d..9e9d22038017 100644 --- a/drivers/regulator/tps6586x-regulator.c +++ b/drivers/regulator/tps6586x-regulator.c | |||
@@ -422,12 +422,12 @@ static struct tps6586x_platform_data *tps6586x_parse_regulator_dt( | |||
422 | return NULL; | 422 | return NULL; |
423 | 423 | ||
424 | for (i = 0; i < num; i++) { | 424 | for (i = 0; i < num; i++) { |
425 | int id; | 425 | uintptr_t id; |
426 | if (!tps6586x_matches[i].init_data) | 426 | if (!tps6586x_matches[i].init_data) |
427 | continue; | 427 | continue; |
428 | 428 | ||
429 | pdata->reg_init_data[i] = tps6586x_matches[i].init_data; | 429 | pdata->reg_init_data[i] = tps6586x_matches[i].init_data; |
430 | id = (int)tps6586x_matches[i].driver_data; | 430 | id = (uintptr_t)tps6586x_matches[i].driver_data; |
431 | if (id == TPS6586X_ID_SYS) | 431 | if (id == TPS6586X_ID_SYS) |
432 | sys_rail = pdata->reg_init_data[i]->constraints.name; | 432 | sys_rail = pdata->reg_init_data[i]->constraints.name; |
433 | 433 | ||
diff --git a/include/linux/mfd/max77693-common.h b/include/linux/mfd/max77693-common.h new file mode 100644 index 000000000000..095b121aa725 --- /dev/null +++ b/include/linux/mfd/max77693-common.h | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * Common data shared between Maxim 77693 and 77843 drivers | ||
3 | * | ||
4 | * Copyright (C) 2015 Samsung Electronics | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #ifndef __LINUX_MFD_MAX77693_COMMON_H | ||
13 | #define __LINUX_MFD_MAX77693_COMMON_H | ||
14 | |||
15 | enum max77693_types { | ||
16 | TYPE_MAX77693_UNKNOWN, | ||
17 | TYPE_MAX77693, | ||
18 | TYPE_MAX77843, | ||
19 | |||
20 | TYPE_MAX77693_NUM, | ||
21 | }; | ||
22 | |||
23 | /* | ||
24 | * Shared also with max77843. | ||
25 | */ | ||
26 | struct max77693_dev { | ||
27 | struct device *dev; | ||
28 | struct i2c_client *i2c; /* 0xCC , PMIC, Charger, Flash LED */ | ||
29 | struct i2c_client *i2c_muic; /* 0x4A , MUIC */ | ||
30 | struct i2c_client *i2c_haptic; /* MAX77693: 0x90 , Haptic */ | ||
31 | struct i2c_client *i2c_chg; /* MAX77843: 0xD2, Charger */ | ||
32 | |||
33 | enum max77693_types type; | ||
34 | |||
35 | struct regmap *regmap; | ||
36 | struct regmap *regmap_muic; | ||
37 | struct regmap *regmap_haptic; /* Only MAX77693 */ | ||
38 | struct regmap *regmap_chg; /* Only MAX77843 */ | ||
39 | |||
40 | struct regmap_irq_chip_data *irq_data_led; | ||
41 | struct regmap_irq_chip_data *irq_data_topsys; | ||
42 | struct regmap_irq_chip_data *irq_data_chg; /* Only MAX77693 */ | ||
43 | struct regmap_irq_chip_data *irq_data_muic; | ||
44 | |||
45 | int irq; | ||
46 | }; | ||
47 | |||
48 | |||
49 | #endif /* __LINUX_MFD_MAX77693_COMMON_H */ | ||
diff --git a/include/linux/mfd/max77693-private.h b/include/linux/mfd/max77693-private.h index 51633ea6f910..3c7a63b98ad6 100644 --- a/include/linux/mfd/max77693-private.h +++ b/include/linux/mfd/max77693-private.h | |||
@@ -310,30 +310,30 @@ enum max77693_muic_reg { | |||
310 | #define INTMASK2_CHGTYP_MASK (1 << INTMASK2_CHGTYP_SHIFT) | 310 | #define INTMASK2_CHGTYP_MASK (1 << INTMASK2_CHGTYP_SHIFT) |
311 | 311 | ||
312 | /* MAX77693 MUIC - STATUS1~3 Register */ | 312 | /* MAX77693 MUIC - STATUS1~3 Register */ |
313 | #define STATUS1_ADC_SHIFT (0) | 313 | #define MAX77693_STATUS1_ADC_SHIFT 0 |
314 | #define STATUS1_ADCLOW_SHIFT (5) | 314 | #define MAX77693_STATUS1_ADCLOW_SHIFT 5 |
315 | #define STATUS1_ADCERR_SHIFT (6) | 315 | #define MAX77693_STATUS1_ADCERR_SHIFT 6 |
316 | #define STATUS1_ADC1K_SHIFT (7) | 316 | #define MAX77693_STATUS1_ADC1K_SHIFT 7 |
317 | #define STATUS1_ADC_MASK (0x1f << STATUS1_ADC_SHIFT) | 317 | #define MAX77693_STATUS1_ADC_MASK (0x1f << MAX77693_STATUS1_ADC_SHIFT) |
318 | #define STATUS1_ADCLOW_MASK (0x1 << STATUS1_ADCLOW_SHIFT) | 318 | #define MAX77693_STATUS1_ADCLOW_MASK BIT(MAX77693_STATUS1_ADCLOW_SHIFT) |
319 | #define STATUS1_ADCERR_MASK (0x1 << STATUS1_ADCERR_SHIFT) | 319 | #define MAX77693_STATUS1_ADCERR_MASK BIT(MAX77693_STATUS1_ADCERR_SHIFT) |
320 | #define STATUS1_ADC1K_MASK (0x1 << STATUS1_ADC1K_SHIFT) | 320 | #define MAX77693_STATUS1_ADC1K_MASK BIT(MAX77693_STATUS1_ADC1K_SHIFT) |
321 | 321 | ||
322 | #define STATUS2_CHGTYP_SHIFT (0) | 322 | #define MAX77693_STATUS2_CHGTYP_SHIFT 0 |
323 | #define STATUS2_CHGDETRUN_SHIFT (3) | 323 | #define MAX77693_STATUS2_CHGDETRUN_SHIFT 3 |
324 | #define STATUS2_DCDTMR_SHIFT (4) | 324 | #define MAX77693_STATUS2_DCDTMR_SHIFT 4 |
325 | #define STATUS2_DXOVP_SHIFT (5) | 325 | #define MAX77693_STATUS2_DXOVP_SHIFT 5 |
326 | #define STATUS2_VBVOLT_SHIFT (6) | 326 | #define MAX77693_STATUS2_VBVOLT_SHIFT 6 |
327 | #define STATUS2_VIDRM_SHIFT (7) | 327 | #define MAX77693_STATUS2_VIDRM_SHIFT 7 |
328 | #define STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT) | 328 | #define MAX77693_STATUS2_CHGTYP_MASK (0x7 << MAX77693_STATUS2_CHGTYP_SHIFT) |
329 | #define STATUS2_CHGDETRUN_MASK (0x1 << STATUS2_CHGDETRUN_SHIFT) | 329 | #define MAX77693_STATUS2_CHGDETRUN_MASK BIT(MAX77693_STATUS2_CHGDETRUN_SHIFT) |
330 | #define STATUS2_DCDTMR_MASK (0x1 << STATUS2_DCDTMR_SHIFT) | 330 | #define MAX77693_STATUS2_DCDTMR_MASK BIT(MAX77693_STATUS2_DCDTMR_SHIFT) |
331 | #define STATUS2_DXOVP_MASK (0x1 << STATUS2_DXOVP_SHIFT) | 331 | #define MAX77693_STATUS2_DXOVP_MASK BIT(MAX77693_STATUS2_DXOVP_SHIFT) |
332 | #define STATUS2_VBVOLT_MASK (0x1 << STATUS2_VBVOLT_SHIFT) | 332 | #define MAX77693_STATUS2_VBVOLT_MASK BIT(MAX77693_STATUS2_VBVOLT_SHIFT) |
333 | #define STATUS2_VIDRM_MASK (0x1 << STATUS2_VIDRM_SHIFT) | 333 | #define MAX77693_STATUS2_VIDRM_MASK BIT(MAX77693_STATUS2_VIDRM_SHIFT) |
334 | 334 | ||
335 | #define STATUS3_OVP_SHIFT (2) | 335 | #define MAX77693_STATUS3_OVP_SHIFT 2 |
336 | #define STATUS3_OVP_MASK (0x1 << STATUS3_OVP_SHIFT) | 336 | #define MAX77693_STATUS3_OVP_MASK BIT(MAX77693_STATUS3_OVP_SHIFT) |
337 | 337 | ||
338 | /* MAX77693 CDETCTRL1~2 register */ | 338 | /* MAX77693 CDETCTRL1~2 register */ |
339 | #define CDETCTRL1_CHGDETEN_SHIFT (0) | 339 | #define CDETCTRL1_CHGDETEN_SHIFT (0) |
@@ -362,38 +362,38 @@ enum max77693_muic_reg { | |||
362 | #define COMN1SW_MASK (0x7 << COMN1SW_SHIFT) | 362 | #define COMN1SW_MASK (0x7 << COMN1SW_SHIFT) |
363 | #define COMP2SW_MASK (0x7 << COMP2SW_SHIFT) | 363 | #define COMP2SW_MASK (0x7 << COMP2SW_SHIFT) |
364 | #define COMP_SW_MASK (COMP2SW_MASK | COMN1SW_MASK) | 364 | #define COMP_SW_MASK (COMP2SW_MASK | COMN1SW_MASK) |
365 | #define CONTROL1_SW_USB ((1 << COMP2SW_SHIFT) \ | 365 | #define MAX77693_CONTROL1_SW_USB ((1 << COMP2SW_SHIFT) \ |
366 | | (1 << COMN1SW_SHIFT)) | 366 | | (1 << COMN1SW_SHIFT)) |
367 | #define CONTROL1_SW_AUDIO ((2 << COMP2SW_SHIFT) \ | 367 | #define MAX77693_CONTROL1_SW_AUDIO ((2 << COMP2SW_SHIFT) \ |
368 | | (2 << COMN1SW_SHIFT)) | 368 | | (2 << COMN1SW_SHIFT)) |
369 | #define CONTROL1_SW_UART ((3 << COMP2SW_SHIFT) \ | 369 | #define MAX77693_CONTROL1_SW_UART ((3 << COMP2SW_SHIFT) \ |
370 | | (3 << COMN1SW_SHIFT)) | 370 | | (3 << COMN1SW_SHIFT)) |
371 | #define CONTROL1_SW_OPEN ((0 << COMP2SW_SHIFT) \ | 371 | #define MAX77693_CONTROL1_SW_OPEN ((0 << COMP2SW_SHIFT) \ |
372 | | (0 << COMN1SW_SHIFT)) | 372 | | (0 << COMN1SW_SHIFT)) |
373 | 373 | ||
374 | #define CONTROL2_LOWPWR_SHIFT (0) | 374 | #define MAX77693_CONTROL2_LOWPWR_SHIFT 0 |
375 | #define CONTROL2_ADCEN_SHIFT (1) | 375 | #define MAX77693_CONTROL2_ADCEN_SHIFT 1 |
376 | #define CONTROL2_CPEN_SHIFT (2) | 376 | #define MAX77693_CONTROL2_CPEN_SHIFT 2 |
377 | #define CONTROL2_SFOUTASRT_SHIFT (3) | 377 | #define MAX77693_CONTROL2_SFOUTASRT_SHIFT 3 |
378 | #define CONTROL2_SFOUTORD_SHIFT (4) | 378 | #define MAX77693_CONTROL2_SFOUTORD_SHIFT 4 |
379 | #define CONTROL2_ACCDET_SHIFT (5) | 379 | #define MAX77693_CONTROL2_ACCDET_SHIFT 5 |
380 | #define CONTROL2_USBCPINT_SHIFT (6) | 380 | #define MAX77693_CONTROL2_USBCPINT_SHIFT 6 |
381 | #define CONTROL2_RCPS_SHIFT (7) | 381 | #define MAX77693_CONTROL2_RCPS_SHIFT 7 |
382 | #define CONTROL2_LOWPWR_MASK (0x1 << CONTROL2_LOWPWR_SHIFT) | 382 | #define MAX77693_CONTROL2_LOWPWR_MASK BIT(MAX77693_CONTROL2_LOWPWR_SHIFT) |
383 | #define CONTROL2_ADCEN_MASK (0x1 << CONTROL2_ADCEN_SHIFT) | 383 | #define MAX77693_CONTROL2_ADCEN_MASK BIT(MAX77693_CONTROL2_ADCEN_SHIFT) |
384 | #define CONTROL2_CPEN_MASK (0x1 << CONTROL2_CPEN_SHIFT) | 384 | #define MAX77693_CONTROL2_CPEN_MASK BIT(MAX77693_CONTROL2_CPEN_SHIFT) |
385 | #define CONTROL2_SFOUTASRT_MASK (0x1 << CONTROL2_SFOUTASRT_SHIFT) | 385 | #define MAX77693_CONTROL2_SFOUTASRT_MASK BIT(MAX77693_CONTROL2_SFOUTASRT_SHIFT) |
386 | #define CONTROL2_SFOUTORD_MASK (0x1 << CONTROL2_SFOUTORD_SHIFT) | 386 | #define MAX77693_CONTROL2_SFOUTORD_MASK BIT(MAX77693_CONTROL2_SFOUTORD_SHIFT) |
387 | #define CONTROL2_ACCDET_MASK (0x1 << CONTROL2_ACCDET_SHIFT) | 387 | #define MAX77693_CONTROL2_ACCDET_MASK BIT(MAX77693_CONTROL2_ACCDET_SHIFT) |
388 | #define CONTROL2_USBCPINT_MASK (0x1 << CONTROL2_USBCPINT_SHIFT) | 388 | #define MAX77693_CONTROL2_USBCPINT_MASK BIT(MAX77693_CONTROL2_USBCPINT_SHIFT) |
389 | #define CONTROL2_RCPS_MASK (0x1 << CONTROL2_RCPS_SHIFT) | 389 | #define MAX77693_CONTROL2_RCPS_MASK BIT(MAX77693_CONTROL2_RCPS_SHIFT) |
390 | 390 | ||
391 | #define CONTROL3_JIGSET_SHIFT (0) | 391 | #define MAX77693_CONTROL3_JIGSET_SHIFT 0 |
392 | #define CONTROL3_BTLDSET_SHIFT (2) | 392 | #define MAX77693_CONTROL3_BTLDSET_SHIFT 2 |
393 | #define CONTROL3_ADCDBSET_SHIFT (4) | 393 | #define MAX77693_CONTROL3_ADCDBSET_SHIFT 4 |
394 | #define CONTROL3_JIGSET_MASK (0x3 << CONTROL3_JIGSET_SHIFT) | 394 | #define MAX77693_CONTROL3_JIGSET_MASK (0x3 << MAX77693_CONTROL3_JIGSET_SHIFT) |
395 | #define CONTROL3_BTLDSET_MASK (0x3 << CONTROL3_BTLDSET_SHIFT) | 395 | #define MAX77693_CONTROL3_BTLDSET_MASK (0x3 << MAX77693_CONTROL3_BTLDSET_SHIFT) |
396 | #define CONTROL3_ADCDBSET_MASK (0x3 << CONTROL3_ADCDBSET_SHIFT) | 396 | #define MAX77693_CONTROL3_ADCDBSET_MASK (0x3 << MAX77693_CONTROL3_ADCDBSET_SHIFT) |
397 | 397 | ||
398 | /* Slave addr = 0x90: Haptic */ | 398 | /* Slave addr = 0x90: Haptic */ |
399 | enum max77693_haptic_reg { | 399 | enum max77693_haptic_reg { |
@@ -529,36 +529,4 @@ enum max77693_irq_muic { | |||
529 | MAX77693_MUIC_IRQ_NR, | 529 | MAX77693_MUIC_IRQ_NR, |
530 | }; | 530 | }; |
531 | 531 | ||
532 | struct max77693_dev { | ||
533 | struct device *dev; | ||
534 | struct i2c_client *i2c; /* 0xCC , PMIC, Charger, Flash LED */ | ||
535 | struct i2c_client *muic; /* 0x4A , MUIC */ | ||
536 | struct i2c_client *haptic; /* 0x90 , Haptic */ | ||
537 | |||
538 | int type; | ||
539 | |||
540 | struct regmap *regmap; | ||
541 | struct regmap *regmap_muic; | ||
542 | struct regmap *regmap_haptic; | ||
543 | |||
544 | struct regmap_irq_chip_data *irq_data_led; | ||
545 | struct regmap_irq_chip_data *irq_data_topsys; | ||
546 | struct regmap_irq_chip_data *irq_data_charger; | ||
547 | struct regmap_irq_chip_data *irq_data_muic; | ||
548 | |||
549 | int irq; | ||
550 | int irq_gpio; | ||
551 | struct mutex irqlock; | ||
552 | int irq_masks_cur[MAX77693_IRQ_GROUP_NR]; | ||
553 | int irq_masks_cache[MAX77693_IRQ_GROUP_NR]; | ||
554 | }; | ||
555 | |||
556 | enum max77693_types { | ||
557 | TYPE_MAX77693, | ||
558 | }; | ||
559 | |||
560 | extern int max77693_irq_init(struct max77693_dev *max77686); | ||
561 | extern void max77693_irq_exit(struct max77693_dev *max77686); | ||
562 | extern int max77693_irq_resume(struct max77693_dev *max77686); | ||
563 | |||
564 | #endif /* __LINUX_MFD_MAX77693_PRIV_H */ | 532 | #endif /* __LINUX_MFD_MAX77693_PRIV_H */ |
diff --git a/include/linux/mfd/max77843-private.h b/include/linux/mfd/max77843-private.h index 7178ace8379e..c19303b0ccfd 100644 --- a/include/linux/mfd/max77843-private.h +++ b/include/linux/mfd/max77843-private.h | |||
@@ -318,62 +318,62 @@ enum max77843_irq_muic { | |||
318 | MAX77843_INTSRCMASK_SYS_MASK | MAX77843_INTSRCMASK_CHGR_MASK) | 318 | MAX77843_INTSRCMASK_SYS_MASK | MAX77843_INTSRCMASK_CHGR_MASK) |
319 | 319 | ||
320 | /* MAX77843 STATUS register*/ | 320 | /* MAX77843 STATUS register*/ |
321 | #define STATUS1_ADC_SHIFT 0 | 321 | #define MAX77843_MUIC_STATUS1_ADC_SHIFT 0 |
322 | #define STATUS1_ADCERROR_SHIFT 6 | 322 | #define MAX77843_MUIC_STATUS1_ADCERROR_SHIFT 6 |
323 | #define STATUS1_ADC1K_SHIFT 7 | 323 | #define MAX77843_MUIC_STATUS1_ADC1K_SHIFT 7 |
324 | #define STATUS2_CHGTYP_SHIFT 0 | 324 | #define MAX77843_MUIC_STATUS2_CHGTYP_SHIFT 0 |
325 | #define STATUS2_CHGDETRUN_SHIFT 3 | 325 | #define MAX77843_MUIC_STATUS2_CHGDETRUN_SHIFT 3 |
326 | #define STATUS2_DCDTMR_SHIFT 4 | 326 | #define MAX77843_MUIC_STATUS2_DCDTMR_SHIFT 4 |
327 | #define STATUS2_DXOVP_SHIFT 5 | 327 | #define MAX77843_MUIC_STATUS2_DXOVP_SHIFT 5 |
328 | #define STATUS2_VBVOLT_SHIFT 6 | 328 | #define MAX77843_MUIC_STATUS2_VBVOLT_SHIFT 6 |
329 | #define STATUS3_VBADC_SHIFT 0 | 329 | #define MAX77843_MUIC_STATUS3_VBADC_SHIFT 0 |
330 | #define STATUS3_VDNMON_SHIFT 4 | 330 | #define MAX77843_MUIC_STATUS3_VDNMON_SHIFT 4 |
331 | #define STATUS3_DNRES_SHIFT 5 | 331 | #define MAX77843_MUIC_STATUS3_DNRES_SHIFT 5 |
332 | #define STATUS3_MPNACK_SHIFT 6 | 332 | #define MAX77843_MUIC_STATUS3_MPNACK_SHIFT 6 |
333 | 333 | ||
334 | #define MAX77843_MUIC_STATUS1_ADC_MASK (0x1f << STATUS1_ADC_SHIFT) | 334 | #define MAX77843_MUIC_STATUS1_ADC_MASK (0x1f << MAX77843_MUIC_STATUS1_ADC_SHIFT) |
335 | #define MAX77843_MUIC_STATUS1_ADCERROR_MASK BIT(STATUS1_ADCERROR_SHIFT) | 335 | #define MAX77843_MUIC_STATUS1_ADCERROR_MASK BIT(MAX77843_MUIC_STATUS1_ADCERROR_SHIFT) |
336 | #define MAX77843_MUIC_STATUS1_ADC1K_MASK BIT(STATUS1_ADC1K_SHIFT) | 336 | #define MAX77843_MUIC_STATUS1_ADC1K_MASK BIT(MAX77843_MUIC_STATUS1_ADC1K_SHIFT) |
337 | #define MAX77843_MUIC_STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT) | 337 | #define MAX77843_MUIC_STATUS2_CHGTYP_MASK (0x7 << MAX77843_MUIC_STATUS2_CHGTYP_SHIFT) |
338 | #define MAX77843_MUIC_STATUS2_CHGDETRUN_MASK BIT(STATUS2_CHGDETRUN_SHIFT) | 338 | #define MAX77843_MUIC_STATUS2_CHGDETRUN_MASK BIT(MAX77843_MUIC_STATUS2_CHGDETRUN_SHIFT) |
339 | #define MAX77843_MUIC_STATUS2_DCDTMR_MASK BIT(STATUS2_DCDTMR_SHIFT) | 339 | #define MAX77843_MUIC_STATUS2_DCDTMR_MASK BIT(MAX77843_MUIC_STATUS2_DCDTMR_SHIFT) |
340 | #define MAX77843_MUIC_STATUS2_DXOVP_MASK BIT(STATUS2_DXOVP_SHIFT) | 340 | #define MAX77843_MUIC_STATUS2_DXOVP_MASK BIT(MAX77843_MUIC_STATUS2_DXOVP_SHIFT) |
341 | #define MAX77843_MUIC_STATUS2_VBVOLT_MASK BIT(STATUS2_VBVOLT_SHIFT) | 341 | #define MAX77843_MUIC_STATUS2_VBVOLT_MASK BIT(MAX77843_MUIC_STATUS2_VBVOLT_SHIFT) |
342 | #define MAX77843_MUIC_STATUS3_VBADC_MASK (0xf << STATUS3_VBADC_SHIFT) | 342 | #define MAX77843_MUIC_STATUS3_VBADC_MASK (0xf << MAX77843_MUIC_STATUS3_VBADC_SHIFT) |
343 | #define MAX77843_MUIC_STATUS3_VDNMON_MASK BIT(STATUS3_VDNMON_SHIFT) | 343 | #define MAX77843_MUIC_STATUS3_VDNMON_MASK BIT(MAX77843_MUIC_STATUS3_VDNMON_SHIFT) |
344 | #define MAX77843_MUIC_STATUS3_DNRES_MASK BIT(STATUS3_DNRES_SHIFT) | 344 | #define MAX77843_MUIC_STATUS3_DNRES_MASK BIT(MAX77843_MUIC_STATUS3_DNRES_SHIFT) |
345 | #define MAX77843_MUIC_STATUS3_MPNACK_MASK BIT(STATUS3_MPNACK_SHIFT) | 345 | #define MAX77843_MUIC_STATUS3_MPNACK_MASK BIT(MAX77843_MUIC_STATUS3_MPNACK_SHIFT) |
346 | 346 | ||
347 | /* MAX77843 CONTROL register */ | 347 | /* MAX77843 CONTROL register */ |
348 | #define CONTROL1_COMP1SW_SHIFT 0 | 348 | #define MAX77843_MUIC_CONTROL1_COMP1SW_SHIFT 0 |
349 | #define CONTROL1_COMP2SW_SHIFT 3 | 349 | #define MAX77843_MUIC_CONTROL1_COMP2SW_SHIFT 3 |
350 | #define CONTROL1_IDBEN_SHIFT 7 | 350 | #define MAX77843_MUIC_CONTROL1_IDBEN_SHIFT 7 |
351 | #define CONTROL2_LOWPWR_SHIFT 0 | 351 | #define MAX77843_MUIC_CONTROL2_LOWPWR_SHIFT 0 |
352 | #define CONTROL2_ADCEN_SHIFT 1 | 352 | #define MAX77843_MUIC_CONTROL2_ADCEN_SHIFT 1 |
353 | #define CONTROL2_CPEN_SHIFT 2 | 353 | #define MAX77843_MUIC_CONTROL2_CPEN_SHIFT 2 |
354 | #define CONTROL2_ACC_DET_SHIFT 5 | 354 | #define MAX77843_MUIC_CONTROL2_ACC_DET_SHIFT 5 |
355 | #define CONTROL2_USBCPINT_SHIFT 6 | 355 | #define MAX77843_MUIC_CONTROL2_USBCPINT_SHIFT 6 |
356 | #define CONTROL2_RCPS_SHIFT 7 | 356 | #define MAX77843_MUIC_CONTROL2_RCPS_SHIFT 7 |
357 | #define CONTROL3_JIGSET_SHIFT 0 | 357 | #define MAX77843_MUIC_CONTROL3_JIGSET_SHIFT 0 |
358 | #define CONTROL4_ADCDBSET_SHIFT 0 | 358 | #define MAX77843_MUIC_CONTROL4_ADCDBSET_SHIFT 0 |
359 | #define CONTROL4_USBAUTO_SHIFT 4 | 359 | #define MAX77843_MUIC_CONTROL4_USBAUTO_SHIFT 4 |
360 | #define CONTROL4_FCTAUTO_SHIFT 5 | 360 | #define MAX77843_MUIC_CONTROL4_FCTAUTO_SHIFT 5 |
361 | #define CONTROL4_ADCMODE_SHIFT 6 | 361 | #define MAX77843_MUIC_CONTROL4_ADCMODE_SHIFT 6 |
362 | 362 | ||
363 | #define MAX77843_MUIC_CONTROL1_COMP1SW_MASK (0x7 << CONTROL1_COMP1SW_SHIFT) | 363 | #define MAX77843_MUIC_CONTROL1_COMP1SW_MASK (0x7 << MAX77843_MUIC_CONTROL1_COMP1SW_SHIFT) |
364 | #define MAX77843_MUIC_CONTROL1_COMP2SW_MASK (0x7 << CONTROL1_COMP2SW_SHIFT) | 364 | #define MAX77843_MUIC_CONTROL1_COMP2SW_MASK (0x7 << MAX77843_MUIC_CONTROL1_COMP2SW_SHIFT) |
365 | #define MAX77843_MUIC_CONTROL1_IDBEN_MASK BIT(CONTROL1_IDBEN_SHIFT) | 365 | #define MAX77843_MUIC_CONTROL1_IDBEN_MASK BIT(MAX77843_MUIC_CONTROL1_IDBEN_SHIFT) |
366 | #define MAX77843_MUIC_CONTROL2_LOWPWR_MASK BIT(CONTROL2_LOWPWR_SHIFT) | 366 | #define MAX77843_MUIC_CONTROL2_LOWPWR_MASK BIT(MAX77843_MUIC_CONTROL2_LOWPWR_SHIFT) |
367 | #define MAX77843_MUIC_CONTROL2_ADCEN_MASK BIT(CONTROL2_ADCEN_SHIFT) | 367 | #define MAX77843_MUIC_CONTROL2_ADCEN_MASK BIT(MAX77843_MUIC_CONTROL2_ADCEN_SHIFT) |
368 | #define MAX77843_MUIC_CONTROL2_CPEN_MASK BIT(CONTROL2_CPEN_SHIFT) | 368 | #define MAX77843_MUIC_CONTROL2_CPEN_MASK BIT(MAX77843_MUIC_CONTROL2_CPEN_SHIFT) |
369 | #define MAX77843_MUIC_CONTROL2_ACC_DET_MASK BIT(CONTROL2_ACC_DET_SHIFT) | 369 | #define MAX77843_MUIC_CONTROL2_ACC_DET_MASK BIT(MAX77843_MUIC_CONTROL2_ACC_DET_SHIFT) |
370 | #define MAX77843_MUIC_CONTROL2_USBCPINT_MASK BIT(CONTROL2_USBCPINT_SHIFT) | 370 | #define MAX77843_MUIC_CONTROL2_USBCPINT_MASK BIT(MAX77843_MUIC_CONTROL2_USBCPINT_SHIFT) |
371 | #define MAX77843_MUIC_CONTROL2_RCPS_MASK BIT(CONTROL2_RCPS_SHIFT) | 371 | #define MAX77843_MUIC_CONTROL2_RCPS_MASK BIT(MAX77843_MUIC_CONTROL2_RCPS_SHIFT) |
372 | #define MAX77843_MUIC_CONTROL3_JIGSET_MASK (0x3 << CONTROL3_JIGSET_SHIFT) | 372 | #define MAX77843_MUIC_CONTROL3_JIGSET_MASK (0x3 << MAX77843_MUIC_CONTROL3_JIGSET_SHIFT) |
373 | #define MAX77843_MUIC_CONTROL4_ADCDBSET_MASK (0x3 << CONTROL4_ADCDBSET_SHIFT) | 373 | #define MAX77843_MUIC_CONTROL4_ADCDBSET_MASK (0x3 << MAX77843_MUIC_CONTROL4_ADCDBSET_SHIFT) |
374 | #define MAX77843_MUIC_CONTROL4_USBAUTO_MASK BIT(CONTROL4_USBAUTO_SHIFT) | 374 | #define MAX77843_MUIC_CONTROL4_USBAUTO_MASK BIT(MAX77843_MUIC_CONTROL4_USBAUTO_SHIFT) |
375 | #define MAX77843_MUIC_CONTROL4_FCTAUTO_MASK BIT(CONTROL4_FCTAUTO_SHIFT) | 375 | #define MAX77843_MUIC_CONTROL4_FCTAUTO_MASK BIT(MAX77843_MUIC_CONTROL4_FCTAUTO_SHIFT) |
376 | #define MAX77843_MUIC_CONTROL4_ADCMODE_MASK (0x3 << CONTROL4_ADCMODE_SHIFT) | 376 | #define MAX77843_MUIC_CONTROL4_ADCMODE_MASK (0x3 << MAX77843_MUIC_CONTROL4_ADCMODE_SHIFT) |
377 | 377 | ||
378 | /* MAX77843 switch port */ | 378 | /* MAX77843 switch port */ |
379 | #define COM_OPEN 0 | 379 | #define COM_OPEN 0 |
@@ -383,38 +383,38 @@ enum max77843_irq_muic { | |||
383 | #define COM_AUX_USB 4 | 383 | #define COM_AUX_USB 4 |
384 | #define COM_AUX_UART 5 | 384 | #define COM_AUX_UART 5 |
385 | 385 | ||
386 | #define CONTROL1_COM_SW \ | 386 | #define MAX77843_MUIC_CONTROL1_COM_SW \ |
387 | ((MAX77843_MUIC_CONTROL1_COMP1SW_MASK | \ | 387 | ((MAX77843_MUIC_CONTROL1_COMP1SW_MASK | \ |
388 | MAX77843_MUIC_CONTROL1_COMP2SW_MASK)) | 388 | MAX77843_MUIC_CONTROL1_COMP2SW_MASK)) |
389 | 389 | ||
390 | #define CONTROL1_SW_OPEN \ | 390 | #define MAX77843_MUIC_CONTROL1_SW_OPEN \ |
391 | ((COM_OPEN << CONTROL1_COMP1SW_SHIFT | \ | 391 | ((COM_OPEN << MAX77843_MUIC_CONTROL1_COMP1SW_SHIFT | \ |
392 | COM_OPEN << CONTROL1_COMP2SW_SHIFT)) | 392 | COM_OPEN << MAX77843_MUIC_CONTROL1_COMP2SW_SHIFT)) |
393 | #define CONTROL1_SW_USB \ | 393 | #define MAX77843_MUIC_CONTROL1_SW_USB \ |
394 | ((COM_USB << CONTROL1_COMP1SW_SHIFT | \ | 394 | ((COM_USB << MAX77843_MUIC_CONTROL1_COMP1SW_SHIFT | \ |
395 | COM_USB << CONTROL1_COMP2SW_SHIFT)) | 395 | COM_USB << MAX77843_MUIC_CONTROL1_COMP2SW_SHIFT)) |
396 | #define CONTROL1_SW_AUDIO \ | 396 | #define MAX77843_MUIC_CONTROL1_SW_AUDIO \ |
397 | ((COM_AUDIO << CONTROL1_COMP1SW_SHIFT | \ | 397 | ((COM_AUDIO << MAX77843_MUIC_CONTROL1_COMP1SW_SHIFT | \ |
398 | COM_AUDIO << CONTROL1_COMP2SW_SHIFT)) | 398 | COM_AUDIO << MAX77843_MUIC_CONTROL1_COMP2SW_SHIFT)) |
399 | #define CONTROL1_SW_UART \ | 399 | #define MAX77843_MUIC_CONTROL1_SW_UART \ |
400 | ((COM_UART << CONTROL1_COMP1SW_SHIFT | \ | 400 | ((COM_UART << MAX77843_MUIC_CONTROL1_COMP1SW_SHIFT | \ |
401 | COM_UART << CONTROL1_COMP2SW_SHIFT)) | 401 | COM_UART << MAX77843_MUIC_CONTROL1_COMP2SW_SHIFT)) |
402 | #define CONTROL1_SW_AUX_USB \ | 402 | #define MAX77843_MUIC_CONTROL1_SW_AUX_USB \ |
403 | ((COM_AUX_USB << CONTROL1_COMP1SW_SHIFT | \ | 403 | ((COM_AUX_USB << MAX77843_MUIC_CONTROL1_COMP1SW_SHIFT | \ |
404 | COM_AUX_USB << CONTROL1_COMP2SW_SHIFT)) | 404 | COM_AUX_USB << MAX77843_MUIC_CONTROL1_COMP2SW_SHIFT)) |
405 | #define CONTROL1_SW_AUX_UART \ | 405 | #define MAX77843_MUIC_CONTROL1_SW_AUX_UART \ |
406 | ((COM_AUX_UART << CONTROL1_COMP1SW_SHIFT | \ | 406 | ((COM_AUX_UART << MAX77843_MUIC_CONTROL1_COMP1SW_SHIFT | \ |
407 | COM_AUX_UART << CONTROL1_COMP2SW_SHIFT)) | 407 | COM_AUX_UART << MAX77843_MUIC_CONTROL1_COMP2SW_SHIFT)) |
408 | 408 | ||
409 | #define MAX77843_DISABLE 0 | 409 | #define MAX77843_DISABLE 0 |
410 | #define MAX77843_ENABLE 1 | 410 | #define MAX77843_ENABLE 1 |
411 | 411 | ||
412 | #define CONTROL4_AUTO_DISABLE \ | 412 | #define CONTROL4_AUTO_DISABLE \ |
413 | ((MAX77843_DISABLE << CONTROL4_USBAUTO_SHIFT) | \ | 413 | ((MAX77843_DISABLE << MAX77843_MUIC_CONTROL4_USBAUTO_SHIFT) | \ |
414 | (MAX77843_DISABLE << CONTROL4_FCTAUTO_SHIFT)) | 414 | (MAX77843_DISABLE << MAX77843_MUIC_CONTROL4_FCTAUTO_SHIFT)) |
415 | #define CONTROL4_AUTO_ENABLE \ | 415 | #define CONTROL4_AUTO_ENABLE \ |
416 | ((MAX77843_ENABLE << CONTROL4_USBAUTO_SHIFT) | \ | 416 | ((MAX77843_ENABLE << MAX77843_MUIC_CONTROL4_USBAUTO_SHIFT) | \ |
417 | (MAX77843_ENABLE << CONTROL4_FCTAUTO_SHIFT)) | 417 | (MAX77843_ENABLE << MAX77843_MUIC_CONTROL4_FCTAUTO_SHIFT)) |
418 | 418 | ||
419 | /* MAX77843 SAFEOUT LDO Control register */ | 419 | /* MAX77843 SAFEOUT LDO Control register */ |
420 | #define SAFEOUTCTRL_SAFEOUT1_SHIFT 0 | 420 | #define SAFEOUTCTRL_SAFEOUT1_SHIFT 0 |
@@ -431,24 +431,4 @@ enum max77843_irq_muic { | |||
431 | #define MAX77843_REG_SAFEOUTCTRL_SAFEOUT2_MASK \ | 431 | #define MAX77843_REG_SAFEOUTCTRL_SAFEOUT2_MASK \ |
432 | (0x3 << SAFEOUTCTRL_SAFEOUT2_SHIFT) | 432 | (0x3 << SAFEOUTCTRL_SAFEOUT2_SHIFT) |
433 | 433 | ||
434 | struct max77843 { | ||
435 | struct device *dev; | ||
436 | |||
437 | struct i2c_client *i2c; | ||
438 | struct i2c_client *i2c_chg; | ||
439 | struct i2c_client *i2c_fuel; | ||
440 | struct i2c_client *i2c_muic; | ||
441 | |||
442 | struct regmap *regmap; | ||
443 | struct regmap *regmap_chg; | ||
444 | struct regmap *regmap_fuel; | ||
445 | struct regmap *regmap_muic; | ||
446 | |||
447 | struct regmap_irq_chip_data *irq_data; | ||
448 | struct regmap_irq_chip_data *irq_data_chg; | ||
449 | struct regmap_irq_chip_data *irq_data_fuel; | ||
450 | struct regmap_irq_chip_data *irq_data_muic; | ||
451 | |||
452 | int irq; | ||
453 | }; | ||
454 | #endif /* __MAX77843_H__ */ | 434 | #endif /* __MAX77843_H__ */ |
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index f8a689ed62a5..9e0e76992be0 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h | |||
@@ -550,8 +550,24 @@ static inline int regulator_count_voltages(struct regulator *regulator) | |||
550 | { | 550 | { |
551 | return 0; | 551 | return 0; |
552 | } | 552 | } |
553 | |||
554 | static inline int regulator_list_voltage(struct regulator *regulator, unsigned selector) | ||
555 | { | ||
556 | return -EINVAL; | ||
557 | } | ||
558 | |||
553 | #endif | 559 | #endif |
554 | 560 | ||
561 | static inline int regulator_set_voltage_triplet(struct regulator *regulator, | ||
562 | int min_uV, int target_uV, | ||
563 | int max_uV) | ||
564 | { | ||
565 | if (regulator_set_voltage(regulator, target_uV, max_uV) == 0) | ||
566 | return 0; | ||
567 | |||
568 | return regulator_set_voltage(regulator, min_uV, max_uV); | ||
569 | } | ||
570 | |||
555 | static inline int regulator_set_voltage_tol(struct regulator *regulator, | 571 | static inline int regulator_set_voltage_tol(struct regulator *regulator, |
556 | int new_uV, int tol_uV) | 572 | int new_uV, int tol_uV) |
557 | { | 573 | { |
diff --git a/include/linux/regulator/da9211.h b/include/linux/regulator/da9211.h index 5dd65acc2a69..a43a5ca1167b 100644 --- a/include/linux/regulator/da9211.h +++ b/include/linux/regulator/da9211.h | |||
@@ -1,16 +1,16 @@ | |||
1 | /* | 1 | /* |
2 | * da9211.h - Regulator device driver for DA9211/DA9213 | 2 | * da9211.h - Regulator device driver for DA9211/DA9213/DA9215 |
3 | * Copyright (C) 2014 Dialog Semiconductor Ltd. | 3 | * Copyright (C) 2015 Dialog Semiconductor Ltd. |
4 | * | 4 | * |
5 | * This library is free software; you can redistribute it and/or | 5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public | 6 | * modify it under the terms of the GNU General Public License |
7 | * License as published by the Free Software Foundation; either | 7 | * as published by the Free Software Foundation; either version 2 |
8 | * version 2 of the License, or (at your option) any later version. | 8 | * of the License, or (at your option) any later version. |
9 | * | 9 | * |
10 | * This library is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * Library General Public License for more details. | 13 | * GNU General Public License for more details. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #ifndef __LINUX_REGULATOR_DA9211_H | 16 | #ifndef __LINUX_REGULATOR_DA9211_H |
@@ -23,6 +23,7 @@ | |||
23 | enum da9211_chip_id { | 23 | enum da9211_chip_id { |
24 | DA9211, | 24 | DA9211, |
25 | DA9213, | 25 | DA9213, |
26 | DA9215, | ||
26 | }; | 27 | }; |
27 | 28 | ||
28 | struct da9211_pdata { | 29 | struct da9211_pdata { |
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 4db9fbe4889d..45932228cbf5 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h | |||
@@ -148,6 +148,7 @@ struct regulator_ops { | |||
148 | int (*get_current_limit) (struct regulator_dev *); | 148 | int (*get_current_limit) (struct regulator_dev *); |
149 | 149 | ||
150 | int (*set_input_current_limit) (struct regulator_dev *, int lim_uA); | 150 | int (*set_input_current_limit) (struct regulator_dev *, int lim_uA); |
151 | int (*set_over_current_protection) (struct regulator_dev *); | ||
151 | 152 | ||
152 | /* enable/disable regulator */ | 153 | /* enable/disable regulator */ |
153 | int (*enable) (struct regulator_dev *); | 154 | int (*enable) (struct regulator_dev *); |
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index b11be1260129..a1067d0b3991 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h | |||
@@ -147,6 +147,7 @@ struct regulation_constraints { | |||
147 | unsigned ramp_disable:1; /* disable ramp delay */ | 147 | unsigned ramp_disable:1; /* disable ramp delay */ |
148 | unsigned soft_start:1; /* ramp voltage slowly */ | 148 | unsigned soft_start:1; /* ramp voltage slowly */ |
149 | unsigned pull_down:1; /* pull down resistor when regulator off */ | 149 | unsigned pull_down:1; /* pull down resistor when regulator off */ |
150 | unsigned over_current_protection:1; /* auto disable on over current */ | ||
150 | }; | 151 | }; |
151 | 152 | ||
152 | /** | 153 | /** |
diff --git a/include/linux/regulator/mt6311.h b/include/linux/regulator/mt6311.h new file mode 100644 index 000000000000..8473259395b6 --- /dev/null +++ b/include/linux/regulator/mt6311.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2015 MediaTek Inc. | ||
3 | * Author: Henry Chen <henryc.chen@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 | */ | ||
14 | |||
15 | #ifndef __LINUX_REGULATOR_MT6311_H | ||
16 | #define __LINUX_REGULATOR_MT6311_H | ||
17 | |||
18 | #define MT6311_MAX_REGULATORS 2 | ||
19 | |||
20 | enum { | ||
21 | MT6311_ID_VDVFS = 0, | ||
22 | MT6311_ID_VBIASN, | ||
23 | }; | ||
24 | |||
25 | #define MT6311_E1_CID_CODE 0x10 | ||
26 | #define MT6311_E2_CID_CODE 0x20 | ||
27 | #define MT6311_E3_CID_CODE 0x30 | ||
28 | |||
29 | #endif /* __LINUX_REGULATOR_MT6311_H */ | ||