blob: 0dd84e99081e9d30539ab96cccc255591a18be82 [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] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053027 .reg_offset = 0,
Sangbeom Kim6445b842012-07-11 21:08:11 +090028 .mask = S2MPS11_IRQ_PWRONF_MASK,
29 },
30 [S2MPS11_IRQ_PWRONR] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053031 .reg_offset = 0,
Sangbeom Kim6445b842012-07-11 21:08:11 +090032 .mask = S2MPS11_IRQ_PWRONR_MASK,
33 },
34 [S2MPS11_IRQ_JIGONBF] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053035 .reg_offset = 0,
Sangbeom Kim6445b842012-07-11 21:08:11 +090036 .mask = S2MPS11_IRQ_JIGONBF_MASK,
37 },
38 [S2MPS11_IRQ_JIGONBR] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053039 .reg_offset = 0,
Sangbeom Kim6445b842012-07-11 21:08:11 +090040 .mask = S2MPS11_IRQ_JIGONBR_MASK,
41 },
42 [S2MPS11_IRQ_ACOKBF] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053043 .reg_offset = 0,
Sangbeom Kim6445b842012-07-11 21:08:11 +090044 .mask = S2MPS11_IRQ_ACOKBF_MASK,
45 },
46 [S2MPS11_IRQ_ACOKBR] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053047 .reg_offset = 0,
Sangbeom Kim6445b842012-07-11 21:08:11 +090048 .mask = S2MPS11_IRQ_ACOKBR_MASK,
49 },
50 [S2MPS11_IRQ_PWRON1S] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053051 .reg_offset = 0,
Sangbeom Kim6445b842012-07-11 21:08:11 +090052 .mask = S2MPS11_IRQ_PWRON1S_MASK,
53 },
54 [S2MPS11_IRQ_MRB] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053055 .reg_offset = 0,
Sangbeom Kim6445b842012-07-11 21:08:11 +090056 .mask = S2MPS11_IRQ_MRB_MASK,
57 },
58 [S2MPS11_IRQ_RTC60S] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053059 .reg_offset = 1,
Sangbeom Kim6445b842012-07-11 21:08:11 +090060 .mask = S2MPS11_IRQ_RTC60S_MASK,
61 },
62 [S2MPS11_IRQ_RTCA1] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053063 .reg_offset = 1,
Sangbeom Kim6445b842012-07-11 21:08:11 +090064 .mask = S2MPS11_IRQ_RTCA1_MASK,
65 },
66 [S2MPS11_IRQ_RTCA2] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053067 .reg_offset = 1,
Sangbeom Kim6445b842012-07-11 21:08:11 +090068 .mask = S2MPS11_IRQ_RTCA2_MASK,
69 },
70 [S2MPS11_IRQ_SMPL] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053071 .reg_offset = 1,
Sangbeom Kim6445b842012-07-11 21:08:11 +090072 .mask = S2MPS11_IRQ_SMPL_MASK,
73 },
74 [S2MPS11_IRQ_RTC1S] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053075 .reg_offset = 1,
Sangbeom Kim6445b842012-07-11 21:08:11 +090076 .mask = S2MPS11_IRQ_RTC1S_MASK,
77 },
78 [S2MPS11_IRQ_WTSR] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053079 .reg_offset = 1,
Sangbeom Kim6445b842012-07-11 21:08:11 +090080 .mask = S2MPS11_IRQ_WTSR_MASK,
81 },
82 [S2MPS11_IRQ_INT120C] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053083 .reg_offset = 2,
Sangbeom Kim6445b842012-07-11 21:08:11 +090084 .mask = S2MPS11_IRQ_INT120C_MASK,
85 },
86 [S2MPS11_IRQ_INT140C] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053087 .reg_offset = 2,
Sangbeom Kim6445b842012-07-11 21:08:11 +090088 .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] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053095 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +090096 .mask = S5M8767_IRQ_PWRR_MASK,
97 },
98 [S5M8767_IRQ_PWRF] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +053099 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900100 .mask = S5M8767_IRQ_PWRF_MASK,
101 },
102 [S5M8767_IRQ_PWR1S] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530103 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900104 .mask = S5M8767_IRQ_PWR1S_MASK,
105 },
106 [S5M8767_IRQ_JIGR] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530107 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900108 .mask = S5M8767_IRQ_JIGR_MASK,
109 },
110 [S5M8767_IRQ_JIGF] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530111 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900112 .mask = S5M8767_IRQ_JIGF_MASK,
113 },
114 [S5M8767_IRQ_LOWBAT2] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530115 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900116 .mask = S5M8767_IRQ_LOWBAT2_MASK,
117 },
118 [S5M8767_IRQ_LOWBAT1] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530119 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900120 .mask = S5M8767_IRQ_LOWBAT1_MASK,
121 },
122 [S5M8767_IRQ_MRB] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530123 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900124 .mask = S5M8767_IRQ_MRB_MASK,
125 },
126 [S5M8767_IRQ_DVSOK2] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530127 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900128 .mask = S5M8767_IRQ_DVSOK2_MASK,
129 },
130 [S5M8767_IRQ_DVSOK3] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530131 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900132 .mask = S5M8767_IRQ_DVSOK3_MASK,
133 },
134 [S5M8767_IRQ_DVSOK4] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530135 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900136 .mask = S5M8767_IRQ_DVSOK4_MASK,
137 },
138 [S5M8767_IRQ_RTC60S] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530139 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900140 .mask = S5M8767_IRQ_RTC60S_MASK,
141 },
142 [S5M8767_IRQ_RTCA1] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530143 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900144 .mask = S5M8767_IRQ_RTCA1_MASK,
145 },
146 [S5M8767_IRQ_RTCA2] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530147 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900148 .mask = S5M8767_IRQ_RTCA2_MASK,
149 },
150 [S5M8767_IRQ_SMPL] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530151 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900152 .mask = S5M8767_IRQ_SMPL_MASK,
153 },
154 [S5M8767_IRQ_RTC1S] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530155 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900156 .mask = S5M8767_IRQ_RTC1S_MASK,
157 },
158 [S5M8767_IRQ_WTSR] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530159 .reg_offset = 2,
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] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530166 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900167 .mask = S5M8763_IRQ_DCINF_MASK,
168 },
169 [S5M8763_IRQ_DCINR] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530170 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900171 .mask = S5M8763_IRQ_DCINR_MASK,
172 },
173 [S5M8763_IRQ_JIGF] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530174 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900175 .mask = S5M8763_IRQ_JIGF_MASK,
176 },
177 [S5M8763_IRQ_JIGR] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530178 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900179 .mask = S5M8763_IRQ_JIGR_MASK,
180 },
181 [S5M8763_IRQ_PWRONF] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530182 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900183 .mask = S5M8763_IRQ_PWRONF_MASK,
184 },
185 [S5M8763_IRQ_PWRONR] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530186 .reg_offset = 0,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900187 .mask = S5M8763_IRQ_PWRONR_MASK,
188 },
189 [S5M8763_IRQ_WTSREVNT] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530190 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900191 .mask = S5M8763_IRQ_WTSREVNT_MASK,
192 },
193 [S5M8763_IRQ_SMPLEVNT] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530194 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900195 .mask = S5M8763_IRQ_SMPLEVNT_MASK,
196 },
197 [S5M8763_IRQ_ALARM1] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530198 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900199 .mask = S5M8763_IRQ_ALARM1_MASK,
200 },
201 [S5M8763_IRQ_ALARM0] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530202 .reg_offset = 1,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900203 .mask = S5M8763_IRQ_ALARM0_MASK,
204 },
205 [S5M8763_IRQ_ONKEY1S] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530206 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900207 .mask = S5M8763_IRQ_ONKEY1S_MASK,
208 },
209 [S5M8763_IRQ_TOPOFFR] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530210 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900211 .mask = S5M8763_IRQ_TOPOFFR_MASK,
212 },
213 [S5M8763_IRQ_DCINOVPR] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530214 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900215 .mask = S5M8763_IRQ_DCINOVPR_MASK,
216 },
217 [S5M8763_IRQ_CHGRSTF] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530218 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900219 .mask = S5M8763_IRQ_CHGRSTF_MASK,
220 },
221 [S5M8763_IRQ_DONER] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530222 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900223 .mask = S5M8763_IRQ_DONER_MASK,
224 },
225 [S5M8763_IRQ_CHGFAULT] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530226 .reg_offset = 2,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900227 .mask = S5M8763_IRQ_CHGFAULT_MASK,
228 },
229 [S5M8763_IRQ_LOBAT1] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530230 .reg_offset = 3,
Sangbeom Kim5ac2ffa72011-12-23 17:28:09 +0900231 .mask = S5M8763_IRQ_LOBAT1_MASK,
232 },
233 [S5M8763_IRQ_LOBAT2] = {
Inderpal Singh5e393a22012-10-17 11:48:55 +0530234 .reg_offset = 3,
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}