kernel: update 4.1 to 4.1.5
[openwrt/svn-archive/archive.git] / target / linux / sunxi / patches-4.1 / 105-mfd-axp20x-add-axp152-support.patch
1 From a50e5abe10c95108ece5d3a91027570e66b5f238 Mon Sep 17 00:00:00 2001
2 From: Michal Suchanek <hramrach@gmail.com>
3 Date: Sat, 11 Jul 2015 14:59:56 +0200
4 Subject: [PATCH] mfd: axp20x: Add axp152 support
5
6 The axp152 is a stripped down version of the axp202 pmic with the battery
7 charging function removed as it is intended for top-set boxes.
8
9 Signed-off-by: Michal Suchanek <hramrach@gmail.com>
10 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
11 Signed-off-by: Lee Jones <lee.jones@linaro.org>
12 ---
13 drivers/mfd/axp20x.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++
14 include/linux/mfd/axp20x.h | 61 +++++++++++++++++++++++++++++++++-
15 2 files changed, 143 insertions(+), 1 deletion(-)
16
17 --- a/drivers/mfd/axp20x.c
18 +++ b/drivers/mfd/axp20x.c
19 @@ -30,12 +30,34 @@
20 #define AXP20X_OFF 0x80
21
22 static const char * const axp20x_model_names[] = {
23 + "AXP152",
24 "AXP202",
25 "AXP209",
26 "AXP221",
27 "AXP288",
28 };
29
30 +static const struct regmap_range axp152_writeable_ranges[] = {
31 + regmap_reg_range(AXP152_LDO3456_DC1234_CTRL, AXP152_IRQ3_STATE),
32 + regmap_reg_range(AXP152_DCDC_MODE, AXP152_PWM1_DUTY_CYCLE),
33 +};
34 +
35 +static const struct regmap_range axp152_volatile_ranges[] = {
36 + regmap_reg_range(AXP152_PWR_OP_MODE, AXP152_PWR_OP_MODE),
37 + regmap_reg_range(AXP152_IRQ1_EN, AXP152_IRQ3_STATE),
38 + regmap_reg_range(AXP152_GPIO_INPUT, AXP152_GPIO_INPUT),
39 +};
40 +
41 +static const struct regmap_access_table axp152_writeable_table = {
42 + .yes_ranges = axp152_writeable_ranges,
43 + .n_yes_ranges = ARRAY_SIZE(axp152_writeable_ranges),
44 +};
45 +
46 +static const struct regmap_access_table axp152_volatile_table = {
47 + .yes_ranges = axp152_volatile_ranges,
48 + .n_yes_ranges = ARRAY_SIZE(axp152_volatile_ranges),
49 +};
50 +
51 static const struct regmap_range axp20x_writeable_ranges[] = {
52 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ5_STATE),
53 regmap_reg_range(AXP20X_DCDC_MODE, AXP20X_FG_RES),
54 @@ -99,6 +121,11 @@ static const struct regmap_access_table
55 .n_yes_ranges = ARRAY_SIZE(axp288_volatile_ranges),
56 };
57
58 +static struct resource axp152_pek_resources[] = {
59 + DEFINE_RES_IRQ_NAMED(AXP152_IRQ_PEK_RIS_EDGE, "PEK_DBR"),
60 + DEFINE_RES_IRQ_NAMED(AXP152_IRQ_PEK_FAL_EDGE, "PEK_DBF"),
61 +};
62 +
63 static struct resource axp20x_pek_resources[] = {
64 {
65 .name = "PEK_DBR",
66 @@ -160,6 +187,15 @@ static struct resource axp288_fuel_gauge
67 },
68 };
69
70 +static const struct regmap_config axp152_regmap_config = {
71 + .reg_bits = 8,
72 + .val_bits = 8,
73 + .wr_table = &axp152_writeable_table,
74 + .volatile_table = &axp152_volatile_table,
75 + .max_register = AXP152_PWM1_DUTY_CYCLE,
76 + .cache_type = REGCACHE_RBTREE,
77 +};
78 +
79 static const struct regmap_config axp20x_regmap_config = {
80 .reg_bits = 8,
81 .val_bits = 8,
82 @@ -190,6 +226,26 @@ static const struct regmap_config axp288
83 #define INIT_REGMAP_IRQ(_variant, _irq, _off, _mask) \
84 [_variant##_IRQ_##_irq] = { .reg_offset = (_off), .mask = BIT(_mask) }
85
86 +static const struct regmap_irq axp152_regmap_irqs[] = {
87 + INIT_REGMAP_IRQ(AXP152, LDO0IN_CONNECT, 0, 6),
88 + INIT_REGMAP_IRQ(AXP152, LDO0IN_REMOVAL, 0, 5),
89 + INIT_REGMAP_IRQ(AXP152, ALDO0IN_CONNECT, 0, 3),
90 + INIT_REGMAP_IRQ(AXP152, ALDO0IN_REMOVAL, 0, 2),
91 + INIT_REGMAP_IRQ(AXP152, DCDC1_V_LOW, 1, 5),
92 + INIT_REGMAP_IRQ(AXP152, DCDC2_V_LOW, 1, 4),
93 + INIT_REGMAP_IRQ(AXP152, DCDC3_V_LOW, 1, 3),
94 + INIT_REGMAP_IRQ(AXP152, DCDC4_V_LOW, 1, 2),
95 + INIT_REGMAP_IRQ(AXP152, PEK_SHORT, 1, 1),
96 + INIT_REGMAP_IRQ(AXP152, PEK_LONG, 1, 0),
97 + INIT_REGMAP_IRQ(AXP152, TIMER, 2, 7),
98 + INIT_REGMAP_IRQ(AXP152, PEK_RIS_EDGE, 2, 6),
99 + INIT_REGMAP_IRQ(AXP152, PEK_FAL_EDGE, 2, 5),
100 + INIT_REGMAP_IRQ(AXP152, GPIO3_INPUT, 2, 3),
101 + INIT_REGMAP_IRQ(AXP152, GPIO2_INPUT, 2, 2),
102 + INIT_REGMAP_IRQ(AXP152, GPIO1_INPUT, 2, 1),
103 + INIT_REGMAP_IRQ(AXP152, GPIO0_INPUT, 2, 0),
104 +};
105 +
106 static const struct regmap_irq axp20x_regmap_irqs[] = {
107 INIT_REGMAP_IRQ(AXP20X, ACIN_OVER_V, 0, 7),
108 INIT_REGMAP_IRQ(AXP20X, ACIN_PLUGIN, 0, 6),
109 @@ -299,6 +355,7 @@ static const struct regmap_irq axp288_re
110 };
111
112 static const struct of_device_id axp20x_of_match[] = {
113 + { .compatible = "x-powers,axp152", .data = (void *) AXP152_ID },
114 { .compatible = "x-powers,axp202", .data = (void *) AXP202_ID },
115 { .compatible = "x-powers,axp209", .data = (void *) AXP209_ID },
116 { .compatible = "x-powers,axp221", .data = (void *) AXP221_ID },
117 @@ -323,6 +380,18 @@ static const struct acpi_device_id axp20
118 };
119 MODULE_DEVICE_TABLE(acpi, axp20x_acpi_match);
120
121 +static const struct regmap_irq_chip axp152_regmap_irq_chip = {
122 + .name = "axp152_irq_chip",
123 + .status_base = AXP152_IRQ1_STATE,
124 + .ack_base = AXP152_IRQ1_STATE,
125 + .mask_base = AXP152_IRQ1_EN,
126 + .mask_invert = true,
127 + .init_ack_masked = true,
128 + .irqs = axp152_regmap_irqs,
129 + .num_irqs = ARRAY_SIZE(axp152_regmap_irqs),
130 + .num_regs = 3,
131 +};
132 +
133 static const struct regmap_irq_chip axp20x_regmap_irq_chip = {
134 .name = "axp20x_irq_chip",
135 .status_base = AXP20X_IRQ1_STATE,
136 @@ -381,6 +450,14 @@ static struct mfd_cell axp22x_cells[] =
137 },
138 };
139
140 +static struct mfd_cell axp152_cells[] = {
141 + {
142 + .name = "axp20x-pek",
143 + .num_resources = ARRAY_SIZE(axp152_pek_resources),
144 + .resources = axp152_pek_resources,
145 + },
146 +};
147 +
148 static struct resource axp288_adc_resources[] = {
149 {
150 .name = "GPADC",
151 @@ -519,6 +596,12 @@ static int axp20x_match_device(struct ax
152 }
153
154 switch (axp20x->variant) {
155 + case AXP152_ID:
156 + axp20x->nr_cells = ARRAY_SIZE(axp152_cells);
157 + axp20x->cells = axp152_cells;
158 + axp20x->regmap_cfg = &axp152_regmap_config;
159 + axp20x->regmap_irq_chip = &axp152_regmap_irq_chip;
160 + break;
161 case AXP202_ID:
162 case AXP209_ID:
163 axp20x->nr_cells = ARRAY_SIZE(axp20x_cells);
164 --- a/include/linux/mfd/axp20x.h
165 +++ b/include/linux/mfd/axp20x.h
166 @@ -12,7 +12,8 @@
167 #define __LINUX_MFD_AXP20X_H
168
169 enum {
170 - AXP202_ID = 0,
171 + AXP152_ID = 0,
172 + AXP202_ID,
173 AXP209_ID,
174 AXP221_ID,
175 AXP288_ID,
176 @@ -22,6 +23,24 @@ enum {
177 #define AXP20X_DATACACHE(m) (0x04 + (m))
178
179 /* Power supply */
180 +#define AXP152_PWR_OP_MODE 0x01
181 +#define AXP152_LDO3456_DC1234_CTRL 0x12
182 +#define AXP152_ALDO_OP_MODE 0x13
183 +#define AXP152_LDO0_CTRL 0x15
184 +#define AXP152_DCDC2_V_OUT 0x23
185 +#define AXP152_DCDC2_V_SCAL 0x25
186 +#define AXP152_DCDC1_V_OUT 0x26
187 +#define AXP152_DCDC3_V_OUT 0x27
188 +#define AXP152_ALDO12_V_OUT 0x28
189 +#define AXP152_DLDO1_V_OUT 0x29
190 +#define AXP152_DLDO2_V_OUT 0x2a
191 +#define AXP152_DCDC4_V_OUT 0x2b
192 +#define AXP152_V_OFF 0x31
193 +#define AXP152_OFF_CTRL 0x32
194 +#define AXP152_PEK_KEY 0x36
195 +#define AXP152_DCDC_FREQ 0x37
196 +#define AXP152_DCDC_MODE 0x80
197 +
198 #define AXP20X_PWR_INPUT_STATUS 0x00
199 #define AXP20X_PWR_OP_MODE 0x01
200 #define AXP20X_USB_OTG_STATUS 0x02
201 @@ -69,6 +88,13 @@ enum {
202 #define AXP22X_CHRG_CTRL3 0x35
203
204 /* Interrupt */
205 +#define AXP152_IRQ1_EN 0x40
206 +#define AXP152_IRQ2_EN 0x41
207 +#define AXP152_IRQ3_EN 0x42
208 +#define AXP152_IRQ1_STATE 0x48
209 +#define AXP152_IRQ2_STATE 0x49
210 +#define AXP152_IRQ3_STATE 0x4a
211 +
212 #define AXP20X_IRQ1_EN 0x40
213 #define AXP20X_IRQ2_EN 0x41
214 #define AXP20X_IRQ3_EN 0x42
215 @@ -127,6 +153,19 @@ enum {
216 #define AXP22X_PWREN_CTRL2 0x8d
217
218 /* GPIO */
219 +#define AXP152_GPIO0_CTRL 0x90
220 +#define AXP152_GPIO1_CTRL 0x91
221 +#define AXP152_GPIO2_CTRL 0x92
222 +#define AXP152_GPIO3_CTRL 0x93
223 +#define AXP152_LDOGPIO2_V_OUT 0x96
224 +#define AXP152_GPIO_INPUT 0x97
225 +#define AXP152_PWM0_FREQ_X 0x98
226 +#define AXP152_PWM0_FREQ_Y 0x99
227 +#define AXP152_PWM0_DUTY_CYCLE 0x9a
228 +#define AXP152_PWM1_FREQ_X 0x9b
229 +#define AXP152_PWM1_FREQ_Y 0x9c
230 +#define AXP152_PWM1_DUTY_CYCLE 0x9d
231 +
232 #define AXP20X_GPIO0_CTRL 0x90
233 #define AXP20X_LDO5_V_OUT 0x91
234 #define AXP20X_GPIO1_CTRL 0x92
235 @@ -224,6 +263,26 @@ enum {
236
237 /* IRQs */
238 enum {
239 + AXP152_IRQ_LDO0IN_CONNECT = 1,
240 + AXP152_IRQ_LDO0IN_REMOVAL,
241 + AXP152_IRQ_ALDO0IN_CONNECT,
242 + AXP152_IRQ_ALDO0IN_REMOVAL,
243 + AXP152_IRQ_DCDC1_V_LOW,
244 + AXP152_IRQ_DCDC2_V_LOW,
245 + AXP152_IRQ_DCDC3_V_LOW,
246 + AXP152_IRQ_DCDC4_V_LOW,
247 + AXP152_IRQ_PEK_SHORT,
248 + AXP152_IRQ_PEK_LONG,
249 + AXP152_IRQ_TIMER,
250 + AXP152_IRQ_PEK_RIS_EDGE,
251 + AXP152_IRQ_PEK_FAL_EDGE,
252 + AXP152_IRQ_GPIO3_INPUT,
253 + AXP152_IRQ_GPIO2_INPUT,
254 + AXP152_IRQ_GPIO1_INPUT,
255 + AXP152_IRQ_GPIO0_INPUT,
256 +};
257 +
258 +enum {
259 AXP20X_IRQ_ACIN_OVER_V = 1,
260 AXP20X_IRQ_ACIN_PLUGIN,
261 AXP20X_IRQ_ACIN_REMOVAL,