blob: c901fa50fea19f0085dab4147fdf713fdc77d56f [file] [log] [blame]
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +09001/*
Sangbeom Kim63063bf2012-07-11 21:06:55 +09002 * sec-irq.c
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +09003 *
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd
5 * http://www.samsung.com
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/device.h>
15#include <linux/interrupt.h>
16#include <linux/irq.h>
Sangbeom Kim6445b842012-07-11 21:08:11 +090017#include <linux/regmap.h>
18
Sangbeom Kim54227bc2012-07-11 21:07:16 +090019#include <linux/mfd/samsung/core.h>
20#include <linux/mfd/samsung/irq.h>
Sangbeom Kim6445b842012-07-11 21:08:11 +090021#include <linux/mfd/samsung/s2mps11.h>
Sangbeom Kim54227bc2012-07-11 21:07:16 +090022#include <linux/mfd/samsung/s5m8763.h>
23#include <linux/mfd/samsung/s5m8767.h>
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +090024
Sangbeom Kim6445b842012-07-11 21:08:11 +090025static struct regmap_irq s2mps11_irqs[] = {
26 [S2MPS11_IRQ_PWRONF] = {
27 .reg_offset = 1,
28 .mask = S2MPS11_IRQ_PWRONF_MASK,
29 },
30 [S2MPS11_IRQ_PWRONR] = {
31 .reg_offset = 1,
32 .mask = S2MPS11_IRQ_PWRONR_MASK,
33 },
34 [S2MPS11_IRQ_JIGONBF] = {
35 .reg_offset = 1,
36 .mask = S2MPS11_IRQ_JIGONBF_MASK,
37 },
38 [S2MPS11_IRQ_JIGONBR] = {
39 .reg_offset = 1,
40 .mask = S2MPS11_IRQ_JIGONBR_MASK,
41 },
42 [S2MPS11_IRQ_ACOKBF] = {
43 .reg_offset = 1,
44 .mask = S2MPS11_IRQ_ACOKBF_MASK,
45 },
46 [S2MPS11_IRQ_ACOKBR] = {
47 .reg_offset = 1,
48 .mask = S2MPS11_IRQ_ACOKBR_MASK,
49 },
50 [S2MPS11_IRQ_PWRON1S] = {
51 .reg_offset = 1,
52 .mask = S2MPS11_IRQ_PWRON1S_MASK,
53 },
54 [S2MPS11_IRQ_MRB] = {
55 .reg_offset = 1,
56 .mask = S2MPS11_IRQ_MRB_MASK,
57 },
58 [S2MPS11_IRQ_RTC60S] = {
59 .reg_offset = 2,
60 .mask = S2MPS11_IRQ_RTC60S_MASK,
61 },
62 [S2MPS11_IRQ_RTCA1] = {
63 .reg_offset = 2,
64 .mask = S2MPS11_IRQ_RTCA1_MASK,
65 },
66 [S2MPS11_IRQ_RTCA2] = {
67 .reg_offset = 2,
68 .mask = S2MPS11_IRQ_RTCA2_MASK,
69 },
70 [S2MPS11_IRQ_SMPL] = {
71 .reg_offset = 2,
72 .mask = S2MPS11_IRQ_SMPL_MASK,
73 },
74 [S2MPS11_IRQ_RTC1S] = {
75 .reg_offset = 2,
76 .mask = S2MPS11_IRQ_RTC1S_MASK,
77 },
78 [S2MPS11_IRQ_WTSR] = {
79 .reg_offset = 2,
80 .mask = S2MPS11_IRQ_WTSR_MASK,
81 },
82 [S2MPS11_IRQ_INT120C] = {
83 .reg_offset = 3,
84 .mask = S2MPS11_IRQ_INT120C_MASK,
85 },
86 [S2MPS11_IRQ_INT140C] = {
87 .reg_offset = 3,
88 .mask = S2MPS11_IRQ_INT140C_MASK,
89 },
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +090090};
91
Sangbeom Kim6445b842012-07-11 21:08:11 +090092
93static struct regmap_irq s5m8767_irqs[] = {
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +090094 [S5M8767_IRQ_PWRR] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +090095 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +090096 .mask = S5M8767_IRQ_PWRR_MASK,
97 },
98 [S5M8767_IRQ_PWRF] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +090099 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900100 .mask = S5M8767_IRQ_PWRF_MASK,
101 },
102 [S5M8767_IRQ_PWR1S] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900103 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900104 .mask = S5M8767_IRQ_PWR1S_MASK,
105 },
106 [S5M8767_IRQ_JIGR] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900107 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900108 .mask = S5M8767_IRQ_JIGR_MASK,
109 },
110 [S5M8767_IRQ_JIGF] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900111 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900112 .mask = S5M8767_IRQ_JIGF_MASK,
113 },
114 [S5M8767_IRQ_LOWBAT2] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900115 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900116 .mask = S5M8767_IRQ_LOWBAT2_MASK,
117 },
118 [S5M8767_IRQ_LOWBAT1] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900119 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900120 .mask = S5M8767_IRQ_LOWBAT1_MASK,
121 },
122 [S5M8767_IRQ_MRB] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900123 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900124 .mask = S5M8767_IRQ_MRB_MASK,
125 },
126 [S5M8767_IRQ_DVSOK2] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900127 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900128 .mask = S5M8767_IRQ_DVSOK2_MASK,
129 },
130 [S5M8767_IRQ_DVSOK3] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900131 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900132 .mask = S5M8767_IRQ_DVSOK3_MASK,
133 },
134 [S5M8767_IRQ_DVSOK4] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900135 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900136 .mask = S5M8767_IRQ_DVSOK4_MASK,
137 },
138 [S5M8767_IRQ_RTC60S] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900139 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900140 .mask = S5M8767_IRQ_RTC60S_MASK,
141 },
142 [S5M8767_IRQ_RTCA1] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900143 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900144 .mask = S5M8767_IRQ_RTCA1_MASK,
145 },
146 [S5M8767_IRQ_RTCA2] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900147 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900148 .mask = S5M8767_IRQ_RTCA2_MASK,
149 },
150 [S5M8767_IRQ_SMPL] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900151 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900152 .mask = S5M8767_IRQ_SMPL_MASK,
153 },
154 [S5M8767_IRQ_RTC1S] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900155 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900156 .mask = S5M8767_IRQ_RTC1S_MASK,
157 },
158 [S5M8767_IRQ_WTSR] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900159 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900160 .mask = S5M8767_IRQ_WTSR_MASK,
161 },
162};
163
Sangbeom Kim6445b842012-07-11 21:08:11 +0900164static struct regmap_irq s5m8763_irqs[] = {
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900165 [S5M8763_IRQ_DCINF] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900166 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900167 .mask = S5M8763_IRQ_DCINF_MASK,
168 },
169 [S5M8763_IRQ_DCINR] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900170 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900171 .mask = S5M8763_IRQ_DCINR_MASK,
172 },
173 [S5M8763_IRQ_JIGF] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900174 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900175 .mask = S5M8763_IRQ_JIGF_MASK,
176 },
177 [S5M8763_IRQ_JIGR] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900178 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900179 .mask = S5M8763_IRQ_JIGR_MASK,
180 },
181 [S5M8763_IRQ_PWRONF] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900182 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900183 .mask = S5M8763_IRQ_PWRONF_MASK,
184 },
185 [S5M8763_IRQ_PWRONR] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900186 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900187 .mask = S5M8763_IRQ_PWRONR_MASK,
188 },
189 [S5M8763_IRQ_WTSREVNT] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900190 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900191 .mask = S5M8763_IRQ_WTSREVNT_MASK,
192 },
193 [S5M8763_IRQ_SMPLEVNT] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900194 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900195 .mask = S5M8763_IRQ_SMPLEVNT_MASK,
196 },
197 [S5M8763_IRQ_ALARM1] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900198 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900199 .mask = S5M8763_IRQ_ALARM1_MASK,
200 },
201 [S5M8763_IRQ_ALARM0] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900202 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900203 .mask = S5M8763_IRQ_ALARM0_MASK,
204 },
205 [S5M8763_IRQ_ONKEY1S] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900206 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900207 .mask = S5M8763_IRQ_ONKEY1S_MASK,
208 },
209 [S5M8763_IRQ_TOPOFFR] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900210 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900211 .mask = S5M8763_IRQ_TOPOFFR_MASK,
212 },
213 [S5M8763_IRQ_DCINOVPR] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900214 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900215 .mask = S5M8763_IRQ_DCINOVPR_MASK,
216 },
217 [S5M8763_IRQ_CHGRSTF] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900218 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900219 .mask = S5M8763_IRQ_CHGRSTF_MASK,
220 },
221 [S5M8763_IRQ_DONER] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900222 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900223 .mask = S5M8763_IRQ_DONER_MASK,
224 },
225 [S5M8763_IRQ_CHGFAULT] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900226 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900227 .mask = S5M8763_IRQ_CHGFAULT_MASK,
228 },
229 [S5M8763_IRQ_LOBAT1] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900230 .reg_offset = 4,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900231 .mask = S5M8763_IRQ_LOBAT1_MASK,
232 },
233 [S5M8763_IRQ_LOBAT2] = {
Sangbeom Kim6445b842012-07-11 21:08:11 +0900234 .reg_offset = 4,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900235 .mask = S5M8763_IRQ_LOBAT2_MASK,
236 },
237};
238
Sangbeom Kim6445b842012-07-11 21:08:11 +0900239static struct regmap_irq_chip s2mps11_irq_chip = {
240 .name = "s2mps11",
241 .irqs = s2mps11_irqs,
242 .num_irqs = ARRAY_SIZE(s2mps11_irqs),
243 .num_regs = 3,
244 .status_base = S2MPS11_REG_INT1,
245 .mask_base = S2MPS11_REG_INT1M,
246 .ack_base = S2MPS11_REG_INT1,
247};
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900248
Sangbeom Kim6445b842012-07-11 21:08:11 +0900249static struct regmap_irq_chip s5m8767_irq_chip = {
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900250 .name = "s5m8767",
Sangbeom Kim6445b842012-07-11 21:08:11 +0900251 .irqs = s5m8767_irqs,
252 .num_irqs = ARRAY_SIZE(s5m8767_irqs),
253 .num_regs = 3,
254 .status_base = S5M8767_REG_INT1,
255 .mask_base = S5M8767_REG_INT1M,
256 .ack_base = S5M8767_REG_INT1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900257};
258
Sangbeom Kim6445b842012-07-11 21:08:11 +0900259static struct regmap_irq_chip s5m8763_irq_chip = {
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900260 .name = "s5m8763",
Sangbeom Kim6445b842012-07-11 21:08:11 +0900261 .irqs = s5m8763_irqs,
262 .num_irqs = ARRAY_SIZE(s5m8763_irqs),
263 .num_regs = 4,
264 .status_base = S5M8763_REG_IRQ1,
265 .mask_base = S5M8763_REG_IRQM1,
266 .ack_base = S5M8763_REG_IRQ1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900267};
268
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900269int sec_irq_init(struct sec_pmic_dev *sec_pmic)
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900270{
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900271 int ret = 0;
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900272 int type = sec_pmic->device_type;
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900273
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900274 if (!sec_pmic->irq) {
275 dev_warn(sec_pmic->dev,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900276 "No interrupt specified, no interrupts\n");
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900277 sec_pmic->irq_base = 0;
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900278 return 0;
279 }
280
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900281 switch (type) {
282 case S5M8763X:
Sangbeom Kim6445b842012-07-11 21:08:11 +0900283 ret = regmap_add_irq_chip(sec_pmic->regmap, sec_pmic->irq,
284 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
285 sec_pmic->irq_base, &s5m8763_irq_chip,
286 &sec_pmic->irq_data);
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900287 break;
288 case S5M8767X:
Sangbeom Kim6445b842012-07-11 21:08:11 +0900289 ret = regmap_add_irq_chip(sec_pmic->regmap, sec_pmic->irq,
290 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
291 sec_pmic->irq_base, &s5m8767_irq_chip,
292 &sec_pmic->irq_data);
293 break;
294 case S2MPS11X:
295 ret = regmap_add_irq_chip(sec_pmic->regmap, sec_pmic->irq,
296 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
297 sec_pmic->irq_base, &s2mps11_irq_chip,
298 &sec_pmic->irq_data);
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900299 break;
300 default:
Sangbeom Kim6445b842012-07-11 21:08:11 +0900301 dev_err(sec_pmic->dev, "Unknown device type %d\n",
302 sec_pmic->device_type);
Jonghwan Choic7a1fcf2012-02-20 16:22:56 +0100303 return -EINVAL;
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900304 }
305
Sangbeom Kim6445b842012-07-11 21:08:11 +0900306 if (ret != 0) {
307 dev_err(sec_pmic->dev, "Failed to register IRQ chip: %d\n", ret);
Jonghwan Choic7a1fcf2012-02-20 16:22:56 +0100308 return ret;
309 }
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900310
311 return 0;
312}
313
Sangbeom Kim63063bf2012-07-11 21:06:55 +0900314void sec_irq_exit(struct sec_pmic_dev *sec_pmic)
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900315{
Sangbeom Kim6445b842012-07-11 21:08:11 +0900316 regmap_del_irq_chip(sec_pmic->irq, sec_pmic->irq_data);
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900317}