diff options
-rw-r--r-- | drivers/mfd/Kconfig | 1 | ||||
-rw-r--r-- | drivers/mfd/Makefile | 2 | ||||
-rw-r--r-- | drivers/mfd/max77686-irq.c | 319 | ||||
-rw-r--r-- | drivers/mfd/max77686.c | 97 | ||||
-rw-r--r-- | drivers/rtc/rtc-max77686.c | 27 | ||||
-rw-r--r-- | include/linux/mfd/max77686-private.h | 31 | ||||
-rw-r--r-- | include/linux/mfd/max77686.h | 2 |
7 files changed, 123 insertions, 356 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index b8d9ca0b68e2..30102042dcaf 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig | |||
@@ -384,6 +384,7 @@ config MFD_MAX77686 | |||
384 | depends on I2C=y | 384 | depends on I2C=y |
385 | select MFD_CORE | 385 | select MFD_CORE |
386 | select REGMAP_I2C | 386 | select REGMAP_I2C |
387 | select REGMAP_IRQ | ||
387 | select IRQ_DOMAIN | 388 | select IRQ_DOMAIN |
388 | help | 389 | help |
389 | Say yes here to add support for Maxim Semiconductor MAX77686. | 390 | Say yes here to add support for Maxim Semiconductor MAX77686. |
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 4e2bc255b8b0..f00148782d9b 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile | |||
@@ -115,7 +115,7 @@ da9063-objs := da9063-core.o da9063-irq.o da9063-i2c.o | |||
115 | obj-$(CONFIG_MFD_DA9063) += da9063.o | 115 | obj-$(CONFIG_MFD_DA9063) += da9063.o |
116 | 116 | ||
117 | obj-$(CONFIG_MFD_MAX14577) += max14577.o | 117 | obj-$(CONFIG_MFD_MAX14577) += max14577.o |
118 | obj-$(CONFIG_MFD_MAX77686) += max77686.o max77686-irq.o | 118 | obj-$(CONFIG_MFD_MAX77686) += max77686.o |
119 | obj-$(CONFIG_MFD_MAX77693) += max77693.o | 119 | obj-$(CONFIG_MFD_MAX77693) += max77693.o |
120 | obj-$(CONFIG_MFD_MAX8907) += max8907.o | 120 | obj-$(CONFIG_MFD_MAX8907) += max8907.o |
121 | max8925-objs := max8925-core.o max8925-i2c.o | 121 | max8925-objs := max8925-core.o max8925-i2c.o |
diff --git a/drivers/mfd/max77686-irq.c b/drivers/mfd/max77686-irq.c deleted file mode 100644 index cdc3280e2ec7..000000000000 --- a/drivers/mfd/max77686-irq.c +++ /dev/null | |||
@@ -1,319 +0,0 @@ | |||
1 | /* | ||
2 | * max77686-irq.c - Interrupt controller support for MAX77686 | ||
3 | * | ||
4 | * Copyright (C) 2012 Samsung Electronics Co.Ltd | ||
5 | * Chiwoong Byun <woong.byun@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 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | * This driver is based on max8997-irq.c | ||
22 | */ | ||
23 | |||
24 | #include <linux/err.h> | ||
25 | #include <linux/irq.h> | ||
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/gpio.h> | ||
28 | #include <linux/mfd/max77686.h> | ||
29 | #include <linux/mfd/max77686-private.h> | ||
30 | #include <linux/irqdomain.h> | ||
31 | #include <linux/regmap.h> | ||
32 | |||
33 | enum { | ||
34 | MAX77686_DEBUG_IRQ_INFO = 1 << 0, | ||
35 | MAX77686_DEBUG_IRQ_MASK = 1 << 1, | ||
36 | MAX77686_DEBUG_IRQ_INT = 1 << 2, | ||
37 | }; | ||
38 | |||
39 | static int debug_mask = 0; | ||
40 | module_param(debug_mask, int, 0); | ||
41 | MODULE_PARM_DESC(debug_mask, "Set debug_mask : 0x0=off 0x1=IRQ_INFO 0x2=IRQ_MASK 0x4=IRQ_INI)"); | ||
42 | |||
43 | static const u8 max77686_mask_reg[] = { | ||
44 | [PMIC_INT1] = MAX77686_REG_INT1MSK, | ||
45 | [PMIC_INT2] = MAX77686_REG_INT2MSK, | ||
46 | [RTC_INT] = MAX77686_RTC_INTM, | ||
47 | }; | ||
48 | |||
49 | static struct regmap *max77686_get_regmap(struct max77686_dev *max77686, | ||
50 | enum max77686_irq_source src) | ||
51 | { | ||
52 | switch (src) { | ||
53 | case PMIC_INT1 ... PMIC_INT2: | ||
54 | return max77686->regmap; | ||
55 | case RTC_INT: | ||
56 | return max77686->rtc_regmap; | ||
57 | default: | ||
58 | return ERR_PTR(-EINVAL); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | struct max77686_irq_data { | ||
63 | int mask; | ||
64 | enum max77686_irq_source group; | ||
65 | }; | ||
66 | |||
67 | #define DECLARE_IRQ(idx, _group, _mask) \ | ||
68 | [(idx)] = { .group = (_group), .mask = (_mask) } | ||
69 | static const struct max77686_irq_data max77686_irqs[] = { | ||
70 | DECLARE_IRQ(MAX77686_PMICIRQ_PWRONF, PMIC_INT1, 1 << 0), | ||
71 | DECLARE_IRQ(MAX77686_PMICIRQ_PWRONR, PMIC_INT1, 1 << 1), | ||
72 | DECLARE_IRQ(MAX77686_PMICIRQ_JIGONBF, PMIC_INT1, 1 << 2), | ||
73 | DECLARE_IRQ(MAX77686_PMICIRQ_JIGONBR, PMIC_INT1, 1 << 3), | ||
74 | DECLARE_IRQ(MAX77686_PMICIRQ_ACOKBF, PMIC_INT1, 1 << 4), | ||
75 | DECLARE_IRQ(MAX77686_PMICIRQ_ACOKBR, PMIC_INT1, 1 << 5), | ||
76 | DECLARE_IRQ(MAX77686_PMICIRQ_ONKEY1S, PMIC_INT1, 1 << 6), | ||
77 | DECLARE_IRQ(MAX77686_PMICIRQ_MRSTB, PMIC_INT1, 1 << 7), | ||
78 | DECLARE_IRQ(MAX77686_PMICIRQ_140C, PMIC_INT2, 1 << 0), | ||
79 | DECLARE_IRQ(MAX77686_PMICIRQ_120C, PMIC_INT2, 1 << 1), | ||
80 | DECLARE_IRQ(MAX77686_RTCIRQ_RTC60S, RTC_INT, 1 << 0), | ||
81 | DECLARE_IRQ(MAX77686_RTCIRQ_RTCA1, RTC_INT, 1 << 1), | ||
82 | DECLARE_IRQ(MAX77686_RTCIRQ_RTCA2, RTC_INT, 1 << 2), | ||
83 | DECLARE_IRQ(MAX77686_RTCIRQ_SMPL, RTC_INT, 1 << 3), | ||
84 | DECLARE_IRQ(MAX77686_RTCIRQ_RTC1S, RTC_INT, 1 << 4), | ||
85 | DECLARE_IRQ(MAX77686_RTCIRQ_WTSR, RTC_INT, 1 << 5), | ||
86 | }; | ||
87 | |||
88 | static void max77686_irq_lock(struct irq_data *data) | ||
89 | { | ||
90 | struct max77686_dev *max77686 = irq_get_chip_data(data->irq); | ||
91 | |||
92 | if (debug_mask & MAX77686_DEBUG_IRQ_MASK) | ||
93 | pr_info("%s\n", __func__); | ||
94 | |||
95 | mutex_lock(&max77686->irqlock); | ||
96 | } | ||
97 | |||
98 | static void max77686_irq_sync_unlock(struct irq_data *data) | ||
99 | { | ||
100 | struct max77686_dev *max77686 = irq_get_chip_data(data->irq); | ||
101 | int i; | ||
102 | |||
103 | for (i = 0; i < MAX77686_IRQ_GROUP_NR; i++) { | ||
104 | u8 mask_reg = max77686_mask_reg[i]; | ||
105 | struct regmap *map = max77686_get_regmap(max77686, i); | ||
106 | |||
107 | if (debug_mask & MAX77686_DEBUG_IRQ_MASK) | ||
108 | pr_debug("%s: mask_reg[%d]=0x%x, cur=0x%x\n", | ||
109 | __func__, i, mask_reg, max77686->irq_masks_cur[i]); | ||
110 | |||
111 | if (mask_reg == MAX77686_REG_INVALID || | ||
112 | IS_ERR_OR_NULL(map)) | ||
113 | continue; | ||
114 | |||
115 | max77686->irq_masks_cache[i] = max77686->irq_masks_cur[i]; | ||
116 | |||
117 | regmap_write(map, max77686_mask_reg[i], | ||
118 | max77686->irq_masks_cur[i]); | ||
119 | } | ||
120 | |||
121 | mutex_unlock(&max77686->irqlock); | ||
122 | } | ||
123 | |||
124 | static const inline struct max77686_irq_data *to_max77686_irq(int irq) | ||
125 | { | ||
126 | struct irq_data *data = irq_get_irq_data(irq); | ||
127 | return &max77686_irqs[data->hwirq]; | ||
128 | } | ||
129 | |||
130 | static void max77686_irq_mask(struct irq_data *data) | ||
131 | { | ||
132 | struct max77686_dev *max77686 = irq_get_chip_data(data->irq); | ||
133 | const struct max77686_irq_data *irq_data = to_max77686_irq(data->irq); | ||
134 | |||
135 | max77686->irq_masks_cur[irq_data->group] |= irq_data->mask; | ||
136 | |||
137 | if (debug_mask & MAX77686_DEBUG_IRQ_MASK) | ||
138 | pr_info("%s: group=%d, cur=0x%x\n", | ||
139 | __func__, irq_data->group, | ||
140 | max77686->irq_masks_cur[irq_data->group]); | ||
141 | } | ||
142 | |||
143 | static void max77686_irq_unmask(struct irq_data *data) | ||
144 | { | ||
145 | struct max77686_dev *max77686 = irq_get_chip_data(data->irq); | ||
146 | const struct max77686_irq_data *irq_data = to_max77686_irq(data->irq); | ||
147 | |||
148 | max77686->irq_masks_cur[irq_data->group] &= ~irq_data->mask; | ||
149 | |||
150 | if (debug_mask & MAX77686_DEBUG_IRQ_MASK) | ||
151 | pr_info("%s: group=%d, cur=0x%x\n", | ||
152 | __func__, irq_data->group, | ||
153 | max77686->irq_masks_cur[irq_data->group]); | ||
154 | } | ||
155 | |||
156 | static struct irq_chip max77686_irq_chip = { | ||
157 | .name = "max77686", | ||
158 | .irq_bus_lock = max77686_irq_lock, | ||
159 | .irq_bus_sync_unlock = max77686_irq_sync_unlock, | ||
160 | .irq_mask = max77686_irq_mask, | ||
161 | .irq_unmask = max77686_irq_unmask, | ||
162 | }; | ||
163 | |||
164 | static irqreturn_t max77686_irq_thread(int irq, void *data) | ||
165 | { | ||
166 | struct max77686_dev *max77686 = data; | ||
167 | unsigned int irq_reg[MAX77686_IRQ_GROUP_NR] = {}; | ||
168 | unsigned int irq_src; | ||
169 | int ret; | ||
170 | int i, cur_irq; | ||
171 | |||
172 | ret = regmap_read(max77686->regmap, MAX77686_REG_INTSRC, &irq_src); | ||
173 | if (ret < 0) { | ||
174 | dev_err(max77686->dev, "Failed to read interrupt source: %d\n", | ||
175 | ret); | ||
176 | return IRQ_NONE; | ||
177 | } | ||
178 | |||
179 | if (debug_mask & MAX77686_DEBUG_IRQ_INT) | ||
180 | pr_info("%s: irq_src=0x%x\n", __func__, irq_src); | ||
181 | |||
182 | if (irq_src == MAX77686_IRQSRC_PMIC) { | ||
183 | ret = regmap_bulk_read(max77686->regmap, | ||
184 | MAX77686_REG_INT1, irq_reg, 2); | ||
185 | if (ret < 0) { | ||
186 | dev_err(max77686->dev, "Failed to read interrupt source: %d\n", | ||
187 | ret); | ||
188 | return IRQ_NONE; | ||
189 | } | ||
190 | |||
191 | if (debug_mask & MAX77686_DEBUG_IRQ_INT) | ||
192 | pr_info("%s: int1=0x%x, int2=0x%x\n", __func__, | ||
193 | irq_reg[PMIC_INT1], irq_reg[PMIC_INT2]); | ||
194 | } | ||
195 | |||
196 | if (irq_src & MAX77686_IRQSRC_RTC) { | ||
197 | ret = regmap_read(max77686->rtc_regmap, | ||
198 | MAX77686_RTC_INT, &irq_reg[RTC_INT]); | ||
199 | if (ret < 0) { | ||
200 | dev_err(max77686->dev, "Failed to read interrupt source: %d\n", | ||
201 | ret); | ||
202 | return IRQ_NONE; | ||
203 | } | ||
204 | |||
205 | if (debug_mask & MAX77686_DEBUG_IRQ_INT) | ||
206 | pr_info("%s: rtc int=0x%x\n", __func__, | ||
207 | irq_reg[RTC_INT]); | ||
208 | |||
209 | } | ||
210 | |||
211 | for (i = 0; i < MAX77686_IRQ_GROUP_NR; i++) | ||
212 | irq_reg[i] &= ~max77686->irq_masks_cur[i]; | ||
213 | |||
214 | for (i = 0; i < MAX77686_IRQ_NR; i++) { | ||
215 | if (irq_reg[max77686_irqs[i].group] & max77686_irqs[i].mask) { | ||
216 | cur_irq = irq_find_mapping(max77686->irq_domain, i); | ||
217 | if (cur_irq) | ||
218 | handle_nested_irq(cur_irq); | ||
219 | } | ||
220 | } | ||
221 | |||
222 | return IRQ_HANDLED; | ||
223 | } | ||
224 | |||
225 | static int max77686_irq_domain_map(struct irq_domain *d, unsigned int irq, | ||
226 | irq_hw_number_t hw) | ||
227 | { | ||
228 | struct max77686_dev *max77686 = d->host_data; | ||
229 | |||
230 | irq_set_chip_data(irq, max77686); | ||
231 | irq_set_chip_and_handler(irq, &max77686_irq_chip, handle_edge_irq); | ||
232 | irq_set_nested_thread(irq, 1); | ||
233 | #ifdef CONFIG_ARM | ||
234 | set_irq_flags(irq, IRQF_VALID); | ||
235 | #else | ||
236 | irq_set_noprobe(irq); | ||
237 | #endif | ||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | static struct irq_domain_ops max77686_irq_domain_ops = { | ||
242 | .map = max77686_irq_domain_map, | ||
243 | }; | ||
244 | |||
245 | int max77686_irq_init(struct max77686_dev *max77686) | ||
246 | { | ||
247 | struct irq_domain *domain; | ||
248 | int i; | ||
249 | int ret; | ||
250 | int val; | ||
251 | struct regmap *map; | ||
252 | |||
253 | mutex_init(&max77686->irqlock); | ||
254 | |||
255 | if (max77686->irq_gpio && !max77686->irq) { | ||
256 | max77686->irq = gpio_to_irq(max77686->irq_gpio); | ||
257 | |||
258 | if (debug_mask & MAX77686_DEBUG_IRQ_INT) { | ||
259 | ret = gpio_request(max77686->irq_gpio, "pmic_irq"); | ||
260 | if (ret < 0) { | ||
261 | dev_err(max77686->dev, | ||
262 | "Failed to request gpio %d with ret:" | ||
263 | "%d\n", max77686->irq_gpio, ret); | ||
264 | return IRQ_NONE; | ||
265 | } | ||
266 | |||
267 | gpio_direction_input(max77686->irq_gpio); | ||
268 | val = gpio_get_value(max77686->irq_gpio); | ||
269 | gpio_free(max77686->irq_gpio); | ||
270 | pr_info("%s: gpio_irq=%x\n", __func__, val); | ||
271 | } | ||
272 | } | ||
273 | |||
274 | if (!max77686->irq) { | ||
275 | dev_err(max77686->dev, "irq is not specified\n"); | ||
276 | return -ENODEV; | ||
277 | } | ||
278 | |||
279 | /* Mask individual interrupt sources */ | ||
280 | for (i = 0; i < MAX77686_IRQ_GROUP_NR; i++) { | ||
281 | max77686->irq_masks_cur[i] = 0xff; | ||
282 | max77686->irq_masks_cache[i] = 0xff; | ||
283 | map = max77686_get_regmap(max77686, i); | ||
284 | |||
285 | if (IS_ERR_OR_NULL(map)) | ||
286 | continue; | ||
287 | if (max77686_mask_reg[i] == MAX77686_REG_INVALID) | ||
288 | continue; | ||
289 | |||
290 | regmap_write(map, max77686_mask_reg[i], 0xff); | ||
291 | } | ||
292 | domain = irq_domain_add_linear(NULL, MAX77686_IRQ_NR, | ||
293 | &max77686_irq_domain_ops, max77686); | ||
294 | if (!domain) { | ||
295 | dev_err(max77686->dev, "could not create irq domain\n"); | ||
296 | return -ENODEV; | ||
297 | } | ||
298 | max77686->irq_domain = domain; | ||
299 | |||
300 | ret = request_threaded_irq(max77686->irq, NULL, max77686_irq_thread, | ||
301 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, | ||
302 | "max77686-irq", max77686); | ||
303 | |||
304 | if (ret) | ||
305 | dev_err(max77686->dev, "Failed to request IRQ %d: %d\n", | ||
306 | max77686->irq, ret); | ||
307 | |||
308 | |||
309 | if (debug_mask & MAX77686_DEBUG_IRQ_INFO) | ||
310 | pr_info("%s-\n", __func__); | ||
311 | |||
312 | return 0; | ||
313 | } | ||
314 | |||
315 | void max77686_irq_exit(struct max77686_dev *max77686) | ||
316 | { | ||
317 | if (max77686->irq) | ||
318 | free_irq(max77686->irq, max77686); | ||
319 | } | ||
diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c index ce869acf27ae..3cb41d02cd3d 100644 --- a/drivers/mfd/max77686.c +++ b/drivers/mfd/max77686.c | |||
@@ -25,6 +25,8 @@ | |||
25 | #include <linux/export.h> | 25 | #include <linux/export.h> |
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | #include <linux/i2c.h> | 27 | #include <linux/i2c.h> |
28 | #include <linux/irq.h> | ||
29 | #include <linux/interrupt.h> | ||
28 | #include <linux/pm_runtime.h> | 30 | #include <linux/pm_runtime.h> |
29 | #include <linux/module.h> | 31 | #include <linux/module.h> |
30 | #include <linux/mfd/core.h> | 32 | #include <linux/mfd/core.h> |
@@ -46,6 +48,54 @@ static struct regmap_config max77686_regmap_config = { | |||
46 | .val_bits = 8, | 48 | .val_bits = 8, |
47 | }; | 49 | }; |
48 | 50 | ||
51 | static struct regmap_config max77686_rtc_regmap_config = { | ||
52 | .reg_bits = 8, | ||
53 | .val_bits = 8, | ||
54 | }; | ||
55 | |||
56 | static const struct regmap_irq max77686_irqs[] = { | ||
57 | /* INT1 interrupts */ | ||
58 | { .reg_offset = 0, .mask = MAX77686_INT1_PWRONF_MSK, }, | ||
59 | { .reg_offset = 0, .mask = MAX77686_INT1_PWRONR_MSK, }, | ||
60 | { .reg_offset = 0, .mask = MAX77686_INT1_JIGONBF_MSK, }, | ||
61 | { .reg_offset = 0, .mask = MAX77686_INT1_JIGONBR_MSK, }, | ||
62 | { .reg_offset = 0, .mask = MAX77686_INT1_ACOKBF_MSK, }, | ||
63 | { .reg_offset = 0, .mask = MAX77686_INT1_ACOKBR_MSK, }, | ||
64 | { .reg_offset = 0, .mask = MAX77686_INT1_ONKEY1S_MSK, }, | ||
65 | { .reg_offset = 0, .mask = MAX77686_INT1_MRSTB_MSK, }, | ||
66 | /* INT2 interrupts */ | ||
67 | { .reg_offset = 1, .mask = MAX77686_INT2_140C_MSK, }, | ||
68 | { .reg_offset = 1, .mask = MAX77686_INT2_120C_MSK, }, | ||
69 | }; | ||
70 | |||
71 | static const struct regmap_irq_chip max77686_irq_chip = { | ||
72 | .name = "max77686-pmic", | ||
73 | .status_base = MAX77686_REG_INT1, | ||
74 | .mask_base = MAX77686_REG_INT1MSK, | ||
75 | .num_regs = 2, | ||
76 | .irqs = max77686_irqs, | ||
77 | .num_irqs = ARRAY_SIZE(max77686_irqs), | ||
78 | }; | ||
79 | |||
80 | static const struct regmap_irq max77686_rtc_irqs[] = { | ||
81 | /* RTC interrupts */ | ||
82 | { .reg_offset = 0, .mask = MAX77686_RTCINT_RTC60S_MSK, }, | ||
83 | { .reg_offset = 0, .mask = MAX77686_RTCINT_RTCA1_MSK, }, | ||
84 | { .reg_offset = 0, .mask = MAX77686_RTCINT_RTCA2_MSK, }, | ||
85 | { .reg_offset = 0, .mask = MAX77686_RTCINT_SMPL_MSK, }, | ||
86 | { .reg_offset = 0, .mask = MAX77686_RTCINT_RTC1S_MSK, }, | ||
87 | { .reg_offset = 0, .mask = MAX77686_RTCINT_WTSR_MSK, }, | ||
88 | }; | ||
89 | |||
90 | static const struct regmap_irq_chip max77686_rtc_irq_chip = { | ||
91 | .name = "max77686-rtc", | ||
92 | .status_base = MAX77686_RTC_INT, | ||
93 | .mask_base = MAX77686_RTC_INTM, | ||
94 | .num_regs = 1, | ||
95 | .irqs = max77686_rtc_irqs, | ||
96 | .num_irqs = ARRAY_SIZE(max77686_rtc_irqs), | ||
97 | }; | ||
98 | |||
49 | #ifdef CONFIG_OF | 99 | #ifdef CONFIG_OF |
50 | static const struct of_device_id max77686_pmic_dt_match[] = { | 100 | static const struct of_device_id max77686_pmic_dt_match[] = { |
51 | {.compatible = "maxim,max77686", .data = NULL}, | 101 | {.compatible = "maxim,max77686", .data = NULL}, |
@@ -101,7 +151,6 @@ static int max77686_i2c_probe(struct i2c_client *i2c, | |||
101 | max77686->type = id->driver_data; | 151 | max77686->type = id->driver_data; |
102 | 152 | ||
103 | max77686->wakeup = pdata->wakeup; | 153 | max77686->wakeup = pdata->wakeup; |
104 | max77686->irq_gpio = pdata->irq_gpio; | ||
105 | max77686->irq = i2c->irq; | 154 | max77686->irq = i2c->irq; |
106 | 155 | ||
107 | max77686->regmap = devm_regmap_init_i2c(i2c, &max77686_regmap_config); | 156 | max77686->regmap = devm_regmap_init_i2c(i2c, &max77686_regmap_config); |
@@ -117,8 +166,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c, | |||
117 | dev_err(max77686->dev, | 166 | dev_err(max77686->dev, |
118 | "device not found on this channel (this is not an error)\n"); | 167 | "device not found on this channel (this is not an error)\n"); |
119 | return -ENODEV; | 168 | return -ENODEV; |
120 | } else | 169 | } |
121 | dev_info(max77686->dev, "device found\n"); | ||
122 | 170 | ||
123 | max77686->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC); | 171 | max77686->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC); |
124 | if (!max77686->rtc) { | 172 | if (!max77686->rtc) { |
@@ -127,15 +175,48 @@ static int max77686_i2c_probe(struct i2c_client *i2c, | |||
127 | } | 175 | } |
128 | i2c_set_clientdata(max77686->rtc, max77686); | 176 | i2c_set_clientdata(max77686->rtc, max77686); |
129 | 177 | ||
130 | max77686_irq_init(max77686); | 178 | max77686->rtc_regmap = devm_regmap_init_i2c(max77686->rtc, |
179 | &max77686_rtc_regmap_config); | ||
180 | if (IS_ERR(max77686->rtc_regmap)) { | ||
181 | ret = PTR_ERR(max77686->rtc_regmap); | ||
182 | dev_err(max77686->dev, "failed to allocate RTC regmap: %d\n", | ||
183 | ret); | ||
184 | goto err_unregister_i2c; | ||
185 | } | ||
186 | |||
187 | ret = regmap_add_irq_chip(max77686->regmap, max77686->irq, | ||
188 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT | | ||
189 | IRQF_SHARED, 0, &max77686_irq_chip, | ||
190 | &max77686->irq_data); | ||
191 | if (ret != 0) { | ||
192 | dev_err(&i2c->dev, "failed to add PMIC irq chip: %d\n", ret); | ||
193 | goto err_unregister_i2c; | ||
194 | } | ||
195 | ret = regmap_add_irq_chip(max77686->rtc_regmap, max77686->irq, | ||
196 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT | | ||
197 | IRQF_SHARED, 0, &max77686_rtc_irq_chip, | ||
198 | &max77686->rtc_irq_data); | ||
199 | if (ret != 0) { | ||
200 | dev_err(&i2c->dev, "failed to add RTC irq chip: %d\n", ret); | ||
201 | goto err_del_irqc; | ||
202 | } | ||
131 | 203 | ||
132 | ret = mfd_add_devices(max77686->dev, -1, max77686_devs, | 204 | ret = mfd_add_devices(max77686->dev, -1, max77686_devs, |
133 | ARRAY_SIZE(max77686_devs), NULL, 0, NULL); | 205 | ARRAY_SIZE(max77686_devs), NULL, 0, NULL); |
134 | if (ret < 0) { | 206 | if (ret < 0) { |
135 | mfd_remove_devices(max77686->dev); | 207 | dev_err(&i2c->dev, "failed to add MFD devices: %d\n", ret); |
136 | i2c_unregister_device(max77686->rtc); | 208 | goto err_del_rtc_irqc; |
137 | } | 209 | } |
138 | 210 | ||
211 | return 0; | ||
212 | |||
213 | err_del_rtc_irqc: | ||
214 | regmap_del_irq_chip(max77686->irq, max77686->rtc_irq_data); | ||
215 | err_del_irqc: | ||
216 | regmap_del_irq_chip(max77686->irq, max77686->irq_data); | ||
217 | err_unregister_i2c: | ||
218 | i2c_unregister_device(max77686->rtc); | ||
219 | |||
139 | return ret; | 220 | return ret; |
140 | } | 221 | } |
141 | 222 | ||
@@ -144,6 +225,10 @@ static int max77686_i2c_remove(struct i2c_client *i2c) | |||
144 | struct max77686_dev *max77686 = i2c_get_clientdata(i2c); | 225 | struct max77686_dev *max77686 = i2c_get_clientdata(i2c); |
145 | 226 | ||
146 | mfd_remove_devices(max77686->dev); | 227 | mfd_remove_devices(max77686->dev); |
228 | |||
229 | regmap_del_irq_chip(max77686->irq, max77686->rtc_irq_data); | ||
230 | regmap_del_irq_chip(max77686->irq, max77686->irq_data); | ||
231 | |||
147 | i2c_unregister_device(max77686->rtc); | 232 | i2c_unregister_device(max77686->rtc); |
148 | 233 | ||
149 | return 0; | 234 | return 0; |
diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c index 9efe118a28ba..d20a7f0786eb 100644 --- a/drivers/rtc/rtc-max77686.c +++ b/drivers/rtc/rtc-max77686.c | |||
@@ -492,16 +492,11 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info *info) | |||
492 | return ret; | 492 | return ret; |
493 | } | 493 | } |
494 | 494 | ||
495 | static struct regmap_config max77686_rtc_regmap_config = { | ||
496 | .reg_bits = 8, | ||
497 | .val_bits = 8, | ||
498 | }; | ||
499 | |||
500 | static int max77686_rtc_probe(struct platform_device *pdev) | 495 | static int max77686_rtc_probe(struct platform_device *pdev) |
501 | { | 496 | { |
502 | struct max77686_dev *max77686 = dev_get_drvdata(pdev->dev.parent); | 497 | struct max77686_dev *max77686 = dev_get_drvdata(pdev->dev.parent); |
503 | struct max77686_rtc_info *info; | 498 | struct max77686_rtc_info *info; |
504 | int ret, virq; | 499 | int ret; |
505 | 500 | ||
506 | dev_info(&pdev->dev, "%s\n", __func__); | 501 | dev_info(&pdev->dev, "%s\n", __func__); |
507 | 502 | ||
@@ -514,14 +509,7 @@ static int max77686_rtc_probe(struct platform_device *pdev) | |||
514 | info->dev = &pdev->dev; | 509 | info->dev = &pdev->dev; |
515 | info->max77686 = max77686; | 510 | info->max77686 = max77686; |
516 | info->rtc = max77686->rtc; | 511 | info->rtc = max77686->rtc; |
517 | info->max77686->rtc_regmap = devm_regmap_init_i2c(info->max77686->rtc, | 512 | |
518 | &max77686_rtc_regmap_config); | ||
519 | if (IS_ERR(info->max77686->rtc_regmap)) { | ||
520 | ret = PTR_ERR(info->max77686->rtc_regmap); | ||
521 | dev_err(info->max77686->dev, "Failed to allocate register map: %d\n", | ||
522 | ret); | ||
523 | return ret; | ||
524 | } | ||
525 | platform_set_drvdata(pdev, info); | 513 | platform_set_drvdata(pdev, info); |
526 | 514 | ||
527 | ret = max77686_rtc_init_reg(info); | 515 | ret = max77686_rtc_init_reg(info); |
@@ -550,15 +538,16 @@ static int max77686_rtc_probe(struct platform_device *pdev) | |||
550 | ret = -EINVAL; | 538 | ret = -EINVAL; |
551 | goto err_rtc; | 539 | goto err_rtc; |
552 | } | 540 | } |
553 | virq = irq_create_mapping(max77686->irq_domain, MAX77686_RTCIRQ_RTCA1); | 541 | |
554 | if (!virq) { | 542 | info->virq = regmap_irq_get_virq(max77686->rtc_irq_data, |
543 | MAX77686_RTCIRQ_RTCA1); | ||
544 | if (!info->virq) { | ||
555 | ret = -ENXIO; | 545 | ret = -ENXIO; |
556 | goto err_rtc; | 546 | goto err_rtc; |
557 | } | 547 | } |
558 | info->virq = virq; | ||
559 | 548 | ||
560 | ret = devm_request_threaded_irq(&pdev->dev, virq, NULL, | 549 | ret = devm_request_threaded_irq(&pdev->dev, info->virq, NULL, |
561 | max77686_rtc_alarm_irq, 0, "rtc-alarm0", info); | 550 | max77686_rtc_alarm_irq, 0, "rtc-alarm1", info); |
562 | if (ret < 0) | 551 | if (ret < 0) |
563 | dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", | 552 | dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", |
564 | info->virq, ret); | 553 | info->virq, ret); |
diff --git a/include/linux/mfd/max77686-private.h b/include/linux/mfd/max77686-private.h index 8c75a9c8dfab..8e177806cba1 100644 --- a/include/linux/mfd/max77686-private.h +++ b/include/linux/mfd/max77686-private.h | |||
@@ -181,9 +181,6 @@ enum max77686_rtc_reg { | |||
181 | MAX77686_ALARM2_DATE = 0x1B, | 181 | MAX77686_ALARM2_DATE = 0x1B, |
182 | }; | 182 | }; |
183 | 183 | ||
184 | #define MAX77686_IRQSRC_PMIC (0) | ||
185 | #define MAX77686_IRQSRC_RTC (1 << 0) | ||
186 | |||
187 | enum max77686_irq_source { | 184 | enum max77686_irq_source { |
188 | PMIC_INT1 = 0, | 185 | PMIC_INT1 = 0, |
189 | PMIC_INT2, | 186 | PMIC_INT2, |
@@ -205,16 +202,33 @@ enum max77686_irq { | |||
205 | MAX77686_PMICIRQ_140C, | 202 | MAX77686_PMICIRQ_140C, |
206 | MAX77686_PMICIRQ_120C, | 203 | MAX77686_PMICIRQ_120C, |
207 | 204 | ||
208 | MAX77686_RTCIRQ_RTC60S, | 205 | MAX77686_RTCIRQ_RTC60S = 0, |
209 | MAX77686_RTCIRQ_RTCA1, | 206 | MAX77686_RTCIRQ_RTCA1, |
210 | MAX77686_RTCIRQ_RTCA2, | 207 | MAX77686_RTCIRQ_RTCA2, |
211 | MAX77686_RTCIRQ_SMPL, | 208 | MAX77686_RTCIRQ_SMPL, |
212 | MAX77686_RTCIRQ_RTC1S, | 209 | MAX77686_RTCIRQ_RTC1S, |
213 | MAX77686_RTCIRQ_WTSR, | 210 | MAX77686_RTCIRQ_WTSR, |
214 | |||
215 | MAX77686_IRQ_NR, | ||
216 | }; | 211 | }; |
217 | 212 | ||
213 | #define MAX77686_INT1_PWRONF_MSK BIT(0) | ||
214 | #define MAX77686_INT1_PWRONR_MSK BIT(1) | ||
215 | #define MAX77686_INT1_JIGONBF_MSK BIT(2) | ||
216 | #define MAX77686_INT1_JIGONBR_MSK BIT(3) | ||
217 | #define MAX77686_INT1_ACOKBF_MSK BIT(4) | ||
218 | #define MAX77686_INT1_ACOKBR_MSK BIT(5) | ||
219 | #define MAX77686_INT1_ONKEY1S_MSK BIT(6) | ||
220 | #define MAX77686_INT1_MRSTB_MSK BIT(7) | ||
221 | |||
222 | #define MAX77686_INT2_140C_MSK BIT(0) | ||
223 | #define MAX77686_INT2_120C_MSK BIT(1) | ||
224 | |||
225 | #define MAX77686_RTCINT_RTC60S_MSK BIT(0) | ||
226 | #define MAX77686_RTCINT_RTCA1_MSK BIT(1) | ||
227 | #define MAX77686_RTCINT_RTCA2_MSK BIT(2) | ||
228 | #define MAX77686_RTCINT_SMPL_MSK BIT(3) | ||
229 | #define MAX77686_RTCINT_RTC1S_MSK BIT(4) | ||
230 | #define MAX77686_RTCINT_WTSR_MSK BIT(5) | ||
231 | |||
218 | struct max77686_dev { | 232 | struct max77686_dev { |
219 | struct device *dev; | 233 | struct device *dev; |
220 | struct i2c_client *i2c; /* 0xcc / PMIC, Battery Control, and FLASH */ | 234 | struct i2c_client *i2c; /* 0xcc / PMIC, Battery Control, and FLASH */ |
@@ -224,11 +238,10 @@ struct max77686_dev { | |||
224 | 238 | ||
225 | struct regmap *regmap; /* regmap for mfd */ | 239 | struct regmap *regmap; /* regmap for mfd */ |
226 | struct regmap *rtc_regmap; /* regmap for rtc */ | 240 | struct regmap *rtc_regmap; /* regmap for rtc */ |
227 | 241 | struct regmap_irq_chip_data *irq_data; | |
228 | struct irq_domain *irq_domain; | 242 | struct regmap_irq_chip_data *rtc_irq_data; |
229 | 243 | ||
230 | int irq; | 244 | int irq; |
231 | int irq_gpio; | ||
232 | bool wakeup; | 245 | bool wakeup; |
233 | struct mutex irqlock; | 246 | struct mutex irqlock; |
234 | int irq_masks_cur[MAX77686_IRQ_GROUP_NR]; | 247 | int irq_masks_cur[MAX77686_IRQ_GROUP_NR]; |
diff --git a/include/linux/mfd/max77686.h b/include/linux/mfd/max77686.h index 46c0f320ed76..4cbcc13e8a2a 100644 --- a/include/linux/mfd/max77686.h +++ b/include/linux/mfd/max77686.h | |||
@@ -89,8 +89,6 @@ struct max77686_opmode_data { | |||
89 | }; | 89 | }; |
90 | 90 | ||
91 | struct max77686_platform_data { | 91 | struct max77686_platform_data { |
92 | /* IRQ */ | ||
93 | int irq_gpio; | ||
94 | int ono; | 92 | int ono; |
95 | int wakeup; | 93 | int wakeup; |
96 | 94 | ||