Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Base driver for Maxim MAX8925 |
| 3 | * |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 4 | * Copyright (C) 2009-2010 Marvell International Ltd. |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 5 | * Haojian Zhuang <haojian.zhuang@marvell.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 version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/i2c.h> |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 15 | #include <linux/irq.h> |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 16 | #include <linux/interrupt.h> |
Qing Xu | 4e405ae | 2013-02-04 23:40:42 +0800 | [diff] [blame] | 17 | #include <linux/irqdomain.h> |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 19 | #include <linux/regulator/machine.h> |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 20 | #include <linux/mfd/core.h> |
| 21 | #include <linux/mfd/max8925.h> |
Qing Xu | 4e405ae | 2013-02-04 23:40:42 +0800 | [diff] [blame] | 22 | #include <linux/of.h> |
| 23 | #include <linux/of_platform.h> |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 24 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 25 | static struct resource bk_resources[] = { |
Haojian Zhuang | 63b501e | 2012-09-17 12:19:04 +0800 | [diff] [blame] | 26 | { 0x84, 0x84, "mode control", IORESOURCE_REG, }, |
| 27 | { 0x85, 0x85, "control", IORESOURCE_REG, }, |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 28 | }; |
| 29 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 30 | static struct mfd_cell bk_devs[] = { |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 31 | { |
| 32 | .name = "max8925-backlight", |
Haojian Zhuang | 63b501e | 2012-09-17 12:19:04 +0800 | [diff] [blame] | 33 | .num_resources = ARRAY_SIZE(bk_resources), |
| 34 | .resources = &bk_resources[0], |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 35 | .id = -1, |
| 36 | }, |
| 37 | }; |
| 38 | |
| 39 | static struct resource touch_resources[] = { |
| 40 | { |
| 41 | .name = "max8925-tsc", |
| 42 | .start = MAX8925_TSC_IRQ, |
| 43 | .end = MAX8925_ADC_RES_END, |
Mark Brown | 015625a | 2012-08-07 19:42:49 +0100 | [diff] [blame] | 44 | .flags = IORESOURCE_REG, |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 45 | }, |
| 46 | }; |
| 47 | |
Geert Uytterhoeven | 7c0517b | 2013-11-18 14:33:00 +0100 | [diff] [blame] | 48 | static const struct mfd_cell touch_devs[] = { |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 49 | { |
| 50 | .name = "max8925-touch", |
| 51 | .num_resources = 1, |
| 52 | .resources = &touch_resources[0], |
| 53 | .id = -1, |
| 54 | }, |
| 55 | }; |
| 56 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 57 | static struct resource power_supply_resources[] = { |
| 58 | { |
| 59 | .name = "max8925-power", |
| 60 | .start = MAX8925_CHG_IRQ1, |
| 61 | .end = MAX8925_CHG_IRQ1_MASK, |
Mark Brown | 015625a | 2012-08-07 19:42:49 +0100 | [diff] [blame] | 62 | .flags = IORESOURCE_REG, |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 63 | }, |
| 64 | }; |
| 65 | |
Geert Uytterhoeven | 7c0517b | 2013-11-18 14:33:00 +0100 | [diff] [blame] | 66 | static const struct mfd_cell power_devs[] = { |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 67 | { |
| 68 | .name = "max8925-power", |
| 69 | .num_resources = 1, |
| 70 | .resources = &power_supply_resources[0], |
| 71 | .id = -1, |
| 72 | }, |
| 73 | }; |
| 74 | |
| 75 | static struct resource rtc_resources[] = { |
| 76 | { |
| 77 | .name = "max8925-rtc", |
Haojian Zhuang | c1a2f31 | 2012-06-05 18:08:50 +0800 | [diff] [blame] | 78 | .start = MAX8925_IRQ_RTC_ALARM0, |
| 79 | .end = MAX8925_IRQ_RTC_ALARM0, |
| 80 | .flags = IORESOURCE_IRQ, |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 81 | }, |
| 82 | }; |
| 83 | |
Geert Uytterhoeven | 7c0517b | 2013-11-18 14:33:00 +0100 | [diff] [blame] | 84 | static const struct mfd_cell rtc_devs[] = { |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 85 | { |
| 86 | .name = "max8925-rtc", |
| 87 | .num_resources = 1, |
| 88 | .resources = &rtc_resources[0], |
| 89 | .id = -1, |
| 90 | }, |
| 91 | }; |
| 92 | |
Haojian Zhuang | d0f7a6d | 2010-06-18 19:59:53 +0200 | [diff] [blame] | 93 | static struct resource onkey_resources[] = { |
| 94 | { |
| 95 | .name = "max8925-onkey", |
Haojian Zhuang | 2d95ae3 | 2010-09-08 09:44:35 -0400 | [diff] [blame] | 96 | .start = MAX8925_IRQ_GPM_SW_R, |
| 97 | .end = MAX8925_IRQ_GPM_SW_R, |
| 98 | .flags = IORESOURCE_IRQ, |
| 99 | }, { |
| 100 | .name = "max8925-onkey", |
| 101 | .start = MAX8925_IRQ_GPM_SW_F, |
| 102 | .end = MAX8925_IRQ_GPM_SW_F, |
Haojian Zhuang | d0f7a6d | 2010-06-18 19:59:53 +0200 | [diff] [blame] | 103 | .flags = IORESOURCE_IRQ, |
| 104 | }, |
| 105 | }; |
| 106 | |
Geert Uytterhoeven | 7c0517b | 2013-11-18 14:33:00 +0100 | [diff] [blame] | 107 | static const struct mfd_cell onkey_devs[] = { |
Haojian Zhuang | d0f7a6d | 2010-06-18 19:59:53 +0200 | [diff] [blame] | 108 | { |
| 109 | .name = "max8925-onkey", |
Haojian Zhuang | 2d95ae3 | 2010-09-08 09:44:35 -0400 | [diff] [blame] | 110 | .num_resources = 2, |
Haojian Zhuang | d0f7a6d | 2010-06-18 19:59:53 +0200 | [diff] [blame] | 111 | .resources = &onkey_resources[0], |
| 112 | .id = -1, |
| 113 | }, |
| 114 | }; |
| 115 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 116 | static struct resource sd1_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 117 | {0x06, 0x06, "sdv", IORESOURCE_REG, }, |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 118 | }; |
| 119 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 120 | static struct resource sd2_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 121 | {0x09, 0x09, "sdv", IORESOURCE_REG, }, |
| 122 | }; |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 123 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 124 | static struct resource sd3_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 125 | {0x0c, 0x0c, "sdv", IORESOURCE_REG, }, |
| 126 | }; |
| 127 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 128 | static struct resource ldo1_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 129 | {0x1a, 0x1a, "ldov", IORESOURCE_REG, }, |
| 130 | }; |
| 131 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 132 | static struct resource ldo2_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 133 | {0x1e, 0x1e, "ldov", IORESOURCE_REG, }, |
| 134 | }; |
| 135 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 136 | static struct resource ldo3_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 137 | {0x22, 0x22, "ldov", IORESOURCE_REG, }, |
| 138 | }; |
| 139 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 140 | static struct resource ldo4_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 141 | {0x26, 0x26, "ldov", IORESOURCE_REG, }, |
| 142 | }; |
| 143 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 144 | static struct resource ldo5_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 145 | {0x2a, 0x2a, "ldov", IORESOURCE_REG, }, |
| 146 | }; |
| 147 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 148 | static struct resource ldo6_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 149 | {0x2e, 0x2e, "ldov", IORESOURCE_REG, }, |
| 150 | }; |
| 151 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 152 | static struct resource ldo7_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 153 | {0x32, 0x32, "ldov", IORESOURCE_REG, }, |
| 154 | }; |
| 155 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 156 | static struct resource ldo8_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 157 | {0x36, 0x36, "ldov", IORESOURCE_REG, }, |
| 158 | }; |
| 159 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 160 | static struct resource ldo9_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 161 | {0x3a, 0x3a, "ldov", IORESOURCE_REG, }, |
| 162 | }; |
| 163 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 164 | static struct resource ldo10_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 165 | {0x3e, 0x3e, "ldov", IORESOURCE_REG, }, |
| 166 | }; |
| 167 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 168 | static struct resource ldo11_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 169 | {0x42, 0x42, "ldov", IORESOURCE_REG, }, |
| 170 | }; |
| 171 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 172 | static struct resource ldo12_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 173 | {0x46, 0x46, "ldov", IORESOURCE_REG, }, |
| 174 | }; |
| 175 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 176 | static struct resource ldo13_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 177 | {0x4a, 0x4a, "ldov", IORESOURCE_REG, }, |
| 178 | }; |
| 179 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 180 | static struct resource ldo14_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 181 | {0x4e, 0x4e, "ldov", IORESOURCE_REG, }, |
| 182 | }; |
| 183 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 184 | static struct resource ldo15_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 185 | {0x52, 0x52, "ldov", IORESOURCE_REG, }, |
| 186 | }; |
| 187 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 188 | static struct resource ldo16_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 189 | {0x12, 0x12, "ldov", IORESOURCE_REG, }, |
| 190 | }; |
| 191 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 192 | static struct resource ldo17_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 193 | {0x16, 0x16, "ldov", IORESOURCE_REG, }, |
| 194 | }; |
| 195 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 196 | static struct resource ldo18_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 197 | {0x74, 0x74, "ldov", IORESOURCE_REG, }, |
| 198 | }; |
| 199 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 200 | static struct resource ldo19_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 201 | {0x5e, 0x5e, "ldov", IORESOURCE_REG, }, |
| 202 | }; |
| 203 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 204 | static struct resource ldo20_resources[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 205 | {0x9e, 0x9e, "ldov", IORESOURCE_REG, }, |
| 206 | }; |
| 207 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 208 | static struct mfd_cell reg_devs[] = { |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 209 | { |
| 210 | .name = "max8925-regulator", |
| 211 | .id = 0, |
| 212 | .num_resources = ARRAY_SIZE(sd1_resources), |
| 213 | .resources = sd1_resources, |
| 214 | }, { |
| 215 | .name = "max8925-regulator", |
| 216 | .id = 1, |
| 217 | .num_resources = ARRAY_SIZE(sd2_resources), |
| 218 | .resources = sd2_resources, |
| 219 | }, { |
| 220 | .name = "max8925-regulator", |
| 221 | .id = 2, |
| 222 | .num_resources = ARRAY_SIZE(sd3_resources), |
| 223 | .resources = sd3_resources, |
| 224 | }, { |
| 225 | .name = "max8925-regulator", |
| 226 | .id = 3, |
| 227 | .num_resources = ARRAY_SIZE(ldo1_resources), |
| 228 | .resources = ldo1_resources, |
| 229 | }, { |
| 230 | .name = "max8925-regulator", |
| 231 | .id = 4, |
| 232 | .num_resources = ARRAY_SIZE(ldo2_resources), |
| 233 | .resources = ldo2_resources, |
| 234 | }, { |
| 235 | .name = "max8925-regulator", |
| 236 | .id = 5, |
| 237 | .num_resources = ARRAY_SIZE(ldo3_resources), |
| 238 | .resources = ldo3_resources, |
| 239 | }, { |
| 240 | .name = "max8925-regulator", |
| 241 | .id = 6, |
| 242 | .num_resources = ARRAY_SIZE(ldo4_resources), |
| 243 | .resources = ldo4_resources, |
| 244 | }, { |
| 245 | .name = "max8925-regulator", |
| 246 | .id = 7, |
| 247 | .num_resources = ARRAY_SIZE(ldo5_resources), |
| 248 | .resources = ldo5_resources, |
| 249 | }, { |
| 250 | .name = "max8925-regulator", |
| 251 | .id = 8, |
| 252 | .num_resources = ARRAY_SIZE(ldo6_resources), |
| 253 | .resources = ldo6_resources, |
| 254 | }, { |
| 255 | .name = "max8925-regulator", |
| 256 | .id = 9, |
| 257 | .num_resources = ARRAY_SIZE(ldo7_resources), |
| 258 | .resources = ldo7_resources, |
| 259 | }, { |
| 260 | .name = "max8925-regulator", |
| 261 | .id = 10, |
| 262 | .num_resources = ARRAY_SIZE(ldo8_resources), |
| 263 | .resources = ldo8_resources, |
| 264 | }, { |
| 265 | .name = "max8925-regulator", |
| 266 | .id = 11, |
| 267 | .num_resources = ARRAY_SIZE(ldo9_resources), |
| 268 | .resources = ldo9_resources, |
| 269 | }, { |
| 270 | .name = "max8925-regulator", |
| 271 | .id = 12, |
| 272 | .num_resources = ARRAY_SIZE(ldo10_resources), |
| 273 | .resources = ldo10_resources, |
| 274 | }, { |
| 275 | .name = "max8925-regulator", |
| 276 | .id = 13, |
| 277 | .num_resources = ARRAY_SIZE(ldo11_resources), |
| 278 | .resources = ldo11_resources, |
| 279 | }, { |
| 280 | .name = "max8925-regulator", |
| 281 | .id = 14, |
| 282 | .num_resources = ARRAY_SIZE(ldo12_resources), |
| 283 | .resources = ldo12_resources, |
| 284 | }, { |
| 285 | .name = "max8925-regulator", |
| 286 | .id = 15, |
| 287 | .num_resources = ARRAY_SIZE(ldo13_resources), |
| 288 | .resources = ldo13_resources, |
| 289 | }, { |
| 290 | .name = "max8925-regulator", |
| 291 | .id = 16, |
| 292 | .num_resources = ARRAY_SIZE(ldo14_resources), |
| 293 | .resources = ldo14_resources, |
| 294 | }, { |
| 295 | .name = "max8925-regulator", |
| 296 | .id = 17, |
| 297 | .num_resources = ARRAY_SIZE(ldo15_resources), |
| 298 | .resources = ldo15_resources, |
| 299 | }, { |
| 300 | .name = "max8925-regulator", |
| 301 | .id = 18, |
| 302 | .num_resources = ARRAY_SIZE(ldo16_resources), |
| 303 | .resources = ldo16_resources, |
| 304 | }, { |
| 305 | .name = "max8925-regulator", |
| 306 | .id = 19, |
| 307 | .num_resources = ARRAY_SIZE(ldo17_resources), |
| 308 | .resources = ldo17_resources, |
| 309 | }, { |
| 310 | .name = "max8925-regulator", |
| 311 | .id = 20, |
| 312 | .num_resources = ARRAY_SIZE(ldo18_resources), |
| 313 | .resources = ldo18_resources, |
| 314 | }, { |
| 315 | .name = "max8925-regulator", |
| 316 | .id = 21, |
| 317 | .num_resources = ARRAY_SIZE(ldo19_resources), |
| 318 | .resources = ldo19_resources, |
| 319 | }, { |
| 320 | .name = "max8925-regulator", |
| 321 | .id = 22, |
| 322 | .num_resources = ARRAY_SIZE(ldo20_resources), |
| 323 | .resources = ldo20_resources, |
| 324 | }, |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 325 | }; |
| 326 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 327 | enum { |
| 328 | FLAGS_ADC = 1, /* register in ADC component */ |
| 329 | FLAGS_RTC, /* register in RTC component */ |
| 330 | }; |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 331 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 332 | struct max8925_irq_data { |
| 333 | int reg; |
| 334 | int mask_reg; |
| 335 | int enable; /* enable or not */ |
| 336 | int offs; /* bit offset in mask register */ |
| 337 | int flags; |
| 338 | int tsc_irq; |
| 339 | }; |
| 340 | |
| 341 | static struct max8925_irq_data max8925_irqs[] = { |
| 342 | [MAX8925_IRQ_VCHG_DC_OVP] = { |
| 343 | .reg = MAX8925_CHG_IRQ1, |
| 344 | .mask_reg = MAX8925_CHG_IRQ1_MASK, |
| 345 | .offs = 1 << 0, |
| 346 | }, |
| 347 | [MAX8925_IRQ_VCHG_DC_F] = { |
| 348 | .reg = MAX8925_CHG_IRQ1, |
| 349 | .mask_reg = MAX8925_CHG_IRQ1_MASK, |
| 350 | .offs = 1 << 1, |
| 351 | }, |
| 352 | [MAX8925_IRQ_VCHG_DC_R] = { |
| 353 | .reg = MAX8925_CHG_IRQ1, |
| 354 | .mask_reg = MAX8925_CHG_IRQ1_MASK, |
| 355 | .offs = 1 << 2, |
| 356 | }, |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 357 | [MAX8925_IRQ_VCHG_THM_OK_R] = { |
| 358 | .reg = MAX8925_CHG_IRQ2, |
| 359 | .mask_reg = MAX8925_CHG_IRQ2_MASK, |
| 360 | .offs = 1 << 0, |
| 361 | }, |
| 362 | [MAX8925_IRQ_VCHG_THM_OK_F] = { |
| 363 | .reg = MAX8925_CHG_IRQ2, |
| 364 | .mask_reg = MAX8925_CHG_IRQ2_MASK, |
| 365 | .offs = 1 << 1, |
| 366 | }, |
| 367 | [MAX8925_IRQ_VCHG_SYSLOW_F] = { |
| 368 | .reg = MAX8925_CHG_IRQ2, |
| 369 | .mask_reg = MAX8925_CHG_IRQ2_MASK, |
| 370 | .offs = 1 << 2, |
| 371 | }, |
| 372 | [MAX8925_IRQ_VCHG_SYSLOW_R] = { |
| 373 | .reg = MAX8925_CHG_IRQ2, |
| 374 | .mask_reg = MAX8925_CHG_IRQ2_MASK, |
| 375 | .offs = 1 << 3, |
| 376 | }, |
| 377 | [MAX8925_IRQ_VCHG_RST] = { |
| 378 | .reg = MAX8925_CHG_IRQ2, |
| 379 | .mask_reg = MAX8925_CHG_IRQ2_MASK, |
| 380 | .offs = 1 << 4, |
| 381 | }, |
| 382 | [MAX8925_IRQ_VCHG_DONE] = { |
| 383 | .reg = MAX8925_CHG_IRQ2, |
| 384 | .mask_reg = MAX8925_CHG_IRQ2_MASK, |
| 385 | .offs = 1 << 5, |
| 386 | }, |
| 387 | [MAX8925_IRQ_VCHG_TOPOFF] = { |
| 388 | .reg = MAX8925_CHG_IRQ2, |
| 389 | .mask_reg = MAX8925_CHG_IRQ2_MASK, |
| 390 | .offs = 1 << 6, |
| 391 | }, |
| 392 | [MAX8925_IRQ_VCHG_TMR_FAULT] = { |
| 393 | .reg = MAX8925_CHG_IRQ2, |
| 394 | .mask_reg = MAX8925_CHG_IRQ2_MASK, |
| 395 | .offs = 1 << 7, |
| 396 | }, |
| 397 | [MAX8925_IRQ_GPM_RSTIN] = { |
| 398 | .reg = MAX8925_ON_OFF_IRQ1, |
| 399 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, |
| 400 | .offs = 1 << 0, |
| 401 | }, |
| 402 | [MAX8925_IRQ_GPM_MPL] = { |
| 403 | .reg = MAX8925_ON_OFF_IRQ1, |
| 404 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, |
| 405 | .offs = 1 << 1, |
| 406 | }, |
| 407 | [MAX8925_IRQ_GPM_SW_3SEC] = { |
| 408 | .reg = MAX8925_ON_OFF_IRQ1, |
| 409 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, |
| 410 | .offs = 1 << 2, |
| 411 | }, |
| 412 | [MAX8925_IRQ_GPM_EXTON_F] = { |
| 413 | .reg = MAX8925_ON_OFF_IRQ1, |
| 414 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, |
| 415 | .offs = 1 << 3, |
| 416 | }, |
| 417 | [MAX8925_IRQ_GPM_EXTON_R] = { |
| 418 | .reg = MAX8925_ON_OFF_IRQ1, |
| 419 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, |
| 420 | .offs = 1 << 4, |
| 421 | }, |
| 422 | [MAX8925_IRQ_GPM_SW_1SEC] = { |
| 423 | .reg = MAX8925_ON_OFF_IRQ1, |
| 424 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, |
| 425 | .offs = 1 << 5, |
| 426 | }, |
| 427 | [MAX8925_IRQ_GPM_SW_F] = { |
| 428 | .reg = MAX8925_ON_OFF_IRQ1, |
| 429 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, |
| 430 | .offs = 1 << 6, |
| 431 | }, |
| 432 | [MAX8925_IRQ_GPM_SW_R] = { |
| 433 | .reg = MAX8925_ON_OFF_IRQ1, |
| 434 | .mask_reg = MAX8925_ON_OFF_IRQ1_MASK, |
| 435 | .offs = 1 << 7, |
| 436 | }, |
| 437 | [MAX8925_IRQ_GPM_SYSCKEN_F] = { |
| 438 | .reg = MAX8925_ON_OFF_IRQ2, |
| 439 | .mask_reg = MAX8925_ON_OFF_IRQ2_MASK, |
| 440 | .offs = 1 << 0, |
| 441 | }, |
| 442 | [MAX8925_IRQ_GPM_SYSCKEN_R] = { |
| 443 | .reg = MAX8925_ON_OFF_IRQ2, |
| 444 | .mask_reg = MAX8925_ON_OFF_IRQ2_MASK, |
| 445 | .offs = 1 << 1, |
| 446 | }, |
| 447 | [MAX8925_IRQ_RTC_ALARM1] = { |
| 448 | .reg = MAX8925_RTC_IRQ, |
| 449 | .mask_reg = MAX8925_RTC_IRQ_MASK, |
| 450 | .offs = 1 << 2, |
| 451 | .flags = FLAGS_RTC, |
| 452 | }, |
| 453 | [MAX8925_IRQ_RTC_ALARM0] = { |
| 454 | .reg = MAX8925_RTC_IRQ, |
| 455 | .mask_reg = MAX8925_RTC_IRQ_MASK, |
| 456 | .offs = 1 << 3, |
| 457 | .flags = FLAGS_RTC, |
| 458 | }, |
| 459 | [MAX8925_IRQ_TSC_STICK] = { |
| 460 | .reg = MAX8925_TSC_IRQ, |
| 461 | .mask_reg = MAX8925_TSC_IRQ_MASK, |
| 462 | .offs = 1 << 0, |
| 463 | .flags = FLAGS_ADC, |
| 464 | .tsc_irq = 1, |
| 465 | }, |
| 466 | [MAX8925_IRQ_TSC_NSTICK] = { |
| 467 | .reg = MAX8925_TSC_IRQ, |
| 468 | .mask_reg = MAX8925_TSC_IRQ_MASK, |
| 469 | .offs = 1 << 1, |
| 470 | .flags = FLAGS_ADC, |
| 471 | .tsc_irq = 1, |
| 472 | }, |
| 473 | }; |
| 474 | |
| 475 | static inline struct max8925_irq_data *irq_to_max8925(struct max8925_chip *chip, |
| 476 | int irq) |
| 477 | { |
| 478 | return &max8925_irqs[irq - chip->irq_base]; |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 479 | } |
| 480 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 481 | static irqreturn_t max8925_irq(int irq, void *data) |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 482 | { |
| 483 | struct max8925_chip *chip = data; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 484 | struct max8925_irq_data *irq_data; |
| 485 | struct i2c_client *i2c; |
| 486 | int read_reg = -1, value = 0; |
| 487 | int i; |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 488 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 489 | for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) { |
| 490 | irq_data = &max8925_irqs[i]; |
| 491 | /* TSC IRQ should be serviced in max8925_tsc_irq() */ |
| 492 | if (irq_data->tsc_irq) |
| 493 | continue; |
| 494 | if (irq_data->flags == FLAGS_RTC) |
| 495 | i2c = chip->rtc; |
| 496 | else if (irq_data->flags == FLAGS_ADC) |
| 497 | i2c = chip->adc; |
| 498 | else |
| 499 | i2c = chip->i2c; |
| 500 | if (read_reg != irq_data->reg) { |
| 501 | read_reg = irq_data->reg; |
| 502 | value = max8925_reg_read(i2c, irq_data->reg); |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 503 | } |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 504 | if (value & irq_data->enable) |
| 505 | handle_nested_irq(chip->irq_base + i); |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 506 | } |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 507 | return IRQ_HANDLED; |
| 508 | } |
| 509 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 510 | static irqreturn_t max8925_tsc_irq(int irq, void *data) |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 511 | { |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 512 | struct max8925_chip *chip = data; |
| 513 | struct max8925_irq_data *irq_data; |
| 514 | struct i2c_client *i2c; |
| 515 | int read_reg = -1, value = 0; |
| 516 | int i; |
| 517 | |
| 518 | for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) { |
| 519 | irq_data = &max8925_irqs[i]; |
| 520 | /* non TSC IRQ should be serviced in max8925_irq() */ |
| 521 | if (!irq_data->tsc_irq) |
| 522 | continue; |
| 523 | if (irq_data->flags == FLAGS_RTC) |
| 524 | i2c = chip->rtc; |
| 525 | else if (irq_data->flags == FLAGS_ADC) |
| 526 | i2c = chip->adc; |
| 527 | else |
| 528 | i2c = chip->i2c; |
| 529 | if (read_reg != irq_data->reg) { |
| 530 | read_reg = irq_data->reg; |
| 531 | value = max8925_reg_read(i2c, irq_data->reg); |
| 532 | } |
| 533 | if (value & irq_data->enable) |
| 534 | handle_nested_irq(chip->irq_base + i); |
| 535 | } |
| 536 | return IRQ_HANDLED; |
| 537 | } |
| 538 | |
Mark Brown | 98d9bc1 | 2010-12-11 18:20:55 +0000 | [diff] [blame] | 539 | static void max8925_irq_lock(struct irq_data *data) |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 540 | { |
Mark Brown | 98d9bc1 | 2010-12-11 18:20:55 +0000 | [diff] [blame] | 541 | struct max8925_chip *chip = irq_data_get_irq_chip_data(data); |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 542 | |
| 543 | mutex_lock(&chip->irq_lock); |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 544 | } |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 545 | |
Mark Brown | 98d9bc1 | 2010-12-11 18:20:55 +0000 | [diff] [blame] | 546 | static void max8925_irq_sync_unlock(struct irq_data *data) |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 547 | { |
Mark Brown | 98d9bc1 | 2010-12-11 18:20:55 +0000 | [diff] [blame] | 548 | struct max8925_chip *chip = irq_data_get_irq_chip_data(data); |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 549 | struct max8925_irq_data *irq_data; |
| 550 | static unsigned char cache_chg[2] = {0xff, 0xff}; |
| 551 | static unsigned char cache_on[2] = {0xff, 0xff}; |
| 552 | static unsigned char cache_rtc = 0xff, cache_tsc = 0xff; |
| 553 | unsigned char irq_chg[2], irq_on[2]; |
| 554 | unsigned char irq_rtc, irq_tsc; |
| 555 | int i; |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 556 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 557 | /* Load cached value. In initial, all IRQs are masked */ |
| 558 | irq_chg[0] = cache_chg[0]; |
| 559 | irq_chg[1] = cache_chg[1]; |
| 560 | irq_on[0] = cache_on[0]; |
| 561 | irq_on[1] = cache_on[1]; |
| 562 | irq_rtc = cache_rtc; |
| 563 | irq_tsc = cache_tsc; |
| 564 | for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) { |
| 565 | irq_data = &max8925_irqs[i]; |
Kevin Liu | 9018231 | 2010-09-08 09:44:36 -0400 | [diff] [blame] | 566 | /* 1 -- disable, 0 -- enable */ |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 567 | switch (irq_data->mask_reg) { |
| 568 | case MAX8925_CHG_IRQ1_MASK: |
Kevin Liu | 9018231 | 2010-09-08 09:44:36 -0400 | [diff] [blame] | 569 | irq_chg[0] &= ~irq_data->enable; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 570 | break; |
| 571 | case MAX8925_CHG_IRQ2_MASK: |
Kevin Liu | 9018231 | 2010-09-08 09:44:36 -0400 | [diff] [blame] | 572 | irq_chg[1] &= ~irq_data->enable; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 573 | break; |
| 574 | case MAX8925_ON_OFF_IRQ1_MASK: |
Kevin Liu | 9018231 | 2010-09-08 09:44:36 -0400 | [diff] [blame] | 575 | irq_on[0] &= ~irq_data->enable; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 576 | break; |
| 577 | case MAX8925_ON_OFF_IRQ2_MASK: |
Kevin Liu | 9018231 | 2010-09-08 09:44:36 -0400 | [diff] [blame] | 578 | irq_on[1] &= ~irq_data->enable; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 579 | break; |
| 580 | case MAX8925_RTC_IRQ_MASK: |
Kevin Liu | 9018231 | 2010-09-08 09:44:36 -0400 | [diff] [blame] | 581 | irq_rtc &= ~irq_data->enable; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 582 | break; |
| 583 | case MAX8925_TSC_IRQ_MASK: |
Kevin Liu | 9018231 | 2010-09-08 09:44:36 -0400 | [diff] [blame] | 584 | irq_tsc &= ~irq_data->enable; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 585 | break; |
| 586 | default: |
| 587 | dev_err(chip->dev, "wrong IRQ\n"); |
| 588 | break; |
| 589 | } |
| 590 | } |
| 591 | /* update mask into registers */ |
| 592 | if (cache_chg[0] != irq_chg[0]) { |
| 593 | cache_chg[0] = irq_chg[0]; |
| 594 | max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ1_MASK, |
| 595 | irq_chg[0]); |
| 596 | } |
| 597 | if (cache_chg[1] != irq_chg[1]) { |
| 598 | cache_chg[1] = irq_chg[1]; |
| 599 | max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ2_MASK, |
| 600 | irq_chg[1]); |
| 601 | } |
| 602 | if (cache_on[0] != irq_on[0]) { |
| 603 | cache_on[0] = irq_on[0]; |
| 604 | max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ1_MASK, |
| 605 | irq_on[0]); |
| 606 | } |
| 607 | if (cache_on[1] != irq_on[1]) { |
| 608 | cache_on[1] = irq_on[1]; |
| 609 | max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ2_MASK, |
| 610 | irq_on[1]); |
| 611 | } |
| 612 | if (cache_rtc != irq_rtc) { |
| 613 | cache_rtc = irq_rtc; |
| 614 | max8925_reg_write(chip->rtc, MAX8925_RTC_IRQ_MASK, irq_rtc); |
| 615 | } |
| 616 | if (cache_tsc != irq_tsc) { |
| 617 | cache_tsc = irq_tsc; |
| 618 | max8925_reg_write(chip->adc, MAX8925_TSC_IRQ_MASK, irq_tsc); |
| 619 | } |
| 620 | |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 621 | mutex_unlock(&chip->irq_lock); |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 622 | } |
| 623 | |
Mark Brown | 98d9bc1 | 2010-12-11 18:20:55 +0000 | [diff] [blame] | 624 | static void max8925_irq_enable(struct irq_data *data) |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 625 | { |
Mark Brown | 98d9bc1 | 2010-12-11 18:20:55 +0000 | [diff] [blame] | 626 | struct max8925_chip *chip = irq_data_get_irq_chip_data(data); |
Lee Jones | a5c5acc | 2014-07-21 14:16:23 +0100 | [diff] [blame] | 627 | |
Mark Brown | 98d9bc1 | 2010-12-11 18:20:55 +0000 | [diff] [blame] | 628 | max8925_irqs[data->irq - chip->irq_base].enable |
| 629 | = max8925_irqs[data->irq - chip->irq_base].offs; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 630 | } |
| 631 | |
Mark Brown | 98d9bc1 | 2010-12-11 18:20:55 +0000 | [diff] [blame] | 632 | static void max8925_irq_disable(struct irq_data *data) |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 633 | { |
Mark Brown | 98d9bc1 | 2010-12-11 18:20:55 +0000 | [diff] [blame] | 634 | struct max8925_chip *chip = irq_data_get_irq_chip_data(data); |
Lee Jones | a5c5acc | 2014-07-21 14:16:23 +0100 | [diff] [blame] | 635 | |
Mark Brown | 98d9bc1 | 2010-12-11 18:20:55 +0000 | [diff] [blame] | 636 | max8925_irqs[data->irq - chip->irq_base].enable = 0; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | static struct irq_chip max8925_irq_chip = { |
| 640 | .name = "max8925", |
Mark Brown | 98d9bc1 | 2010-12-11 18:20:55 +0000 | [diff] [blame] | 641 | .irq_bus_lock = max8925_irq_lock, |
| 642 | .irq_bus_sync_unlock = max8925_irq_sync_unlock, |
| 643 | .irq_enable = max8925_irq_enable, |
| 644 | .irq_disable = max8925_irq_disable, |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 645 | }; |
| 646 | |
Qing Xu | 4e405ae | 2013-02-04 23:40:42 +0800 | [diff] [blame] | 647 | static int max8925_irq_domain_map(struct irq_domain *d, unsigned int virq, |
| 648 | irq_hw_number_t hw) |
| 649 | { |
| 650 | irq_set_chip_data(virq, d->host_data); |
| 651 | irq_set_chip_and_handler(virq, &max8925_irq_chip, handle_edge_irq); |
| 652 | irq_set_nested_thread(virq, 1); |
| 653 | #ifdef CONFIG_ARM |
| 654 | set_irq_flags(virq, IRQF_VALID); |
| 655 | #else |
| 656 | irq_set_noprobe(virq); |
| 657 | #endif |
| 658 | return 0; |
| 659 | } |
| 660 | |
Krzysztof Kozlowski | 7ce7b26 | 2015-04-27 21:54:13 +0900 | [diff] [blame] | 661 | static const struct irq_domain_ops max8925_irq_domain_ops = { |
Qing Xu | 4e405ae | 2013-02-04 23:40:42 +0800 | [diff] [blame] | 662 | .map = max8925_irq_domain_map, |
| 663 | .xlate = irq_domain_xlate_onetwocell, |
| 664 | }; |
| 665 | |
| 666 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 667 | static int max8925_irq_init(struct max8925_chip *chip, int irq, |
| 668 | struct max8925_platform_data *pdata) |
| 669 | { |
| 670 | unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; |
Qing Xu | 4e405ae | 2013-02-04 23:40:42 +0800 | [diff] [blame] | 671 | int ret; |
| 672 | struct device_node *node = chip->dev->of_node; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 673 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 674 | /* clear all interrupts */ |
| 675 | max8925_reg_read(chip->i2c, MAX8925_CHG_IRQ1); |
| 676 | max8925_reg_read(chip->i2c, MAX8925_CHG_IRQ2); |
| 677 | max8925_reg_read(chip->i2c, MAX8925_ON_OFF_IRQ1); |
| 678 | max8925_reg_read(chip->i2c, MAX8925_ON_OFF_IRQ2); |
| 679 | max8925_reg_read(chip->rtc, MAX8925_RTC_IRQ); |
| 680 | max8925_reg_read(chip->adc, MAX8925_TSC_IRQ); |
Haojian Zhuang | 68e488d | 2010-04-27 14:55:28 -0400 | [diff] [blame] | 681 | /* mask all interrupts except for TSC */ |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 682 | max8925_reg_write(chip->rtc, MAX8925_ALARM0_CNTL, 0); |
| 683 | max8925_reg_write(chip->rtc, MAX8925_ALARM1_CNTL, 0); |
| 684 | max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ1_MASK, 0xff); |
| 685 | max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ2_MASK, 0xff); |
| 686 | max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ1_MASK, 0xff); |
| 687 | max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ2_MASK, 0xff); |
| 688 | max8925_reg_write(chip->rtc, MAX8925_RTC_IRQ_MASK, 0xff); |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 689 | |
| 690 | mutex_init(&chip->irq_lock); |
Qing Xu | 4e405ae | 2013-02-04 23:40:42 +0800 | [diff] [blame] | 691 | chip->irq_base = irq_alloc_descs(-1, 0, MAX8925_NR_IRQS, 0); |
| 692 | if (chip->irq_base < 0) { |
| 693 | dev_err(chip->dev, "Failed to allocate interrupts, ret:%d\n", |
| 694 | chip->irq_base); |
| 695 | return -EBUSY; |
| 696 | } |
| 697 | |
| 698 | irq_domain_add_legacy(node, MAX8925_NR_IRQS, chip->irq_base, 0, |
| 699 | &max8925_irq_domain_ops, chip); |
| 700 | |
| 701 | /* request irq handler for pmic main irq*/ |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 702 | chip->core_irq = irq; |
Qing Xu | 4e405ae | 2013-02-04 23:40:42 +0800 | [diff] [blame] | 703 | if (!chip->core_irq) |
| 704 | return -EBUSY; |
Fengguang Wu | 619a1e3 | 2012-09-19 09:41:13 +0800 | [diff] [blame] | 705 | ret = request_threaded_irq(irq, NULL, max8925_irq, flags | IRQF_ONESHOT, |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 706 | "max8925", chip); |
| 707 | if (ret) { |
| 708 | dev_err(chip->dev, "Failed to request core IRQ: %d\n", ret); |
| 709 | chip->core_irq = 0; |
Qing Xu | 4e405ae | 2013-02-04 23:40:42 +0800 | [diff] [blame] | 710 | return -EBUSY; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 711 | } |
Haojian Zhuang | 68e488d | 2010-04-27 14:55:28 -0400 | [diff] [blame] | 712 | |
Qing Xu | 4e405ae | 2013-02-04 23:40:42 +0800 | [diff] [blame] | 713 | /* request irq handler for pmic tsc irq*/ |
| 714 | |
Haojian Zhuang | 68e488d | 2010-04-27 14:55:28 -0400 | [diff] [blame] | 715 | /* mask TSC interrupt */ |
| 716 | max8925_reg_write(chip->adc, MAX8925_TSC_IRQ_MASK, 0x0f); |
| 717 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 718 | if (!pdata->tsc_irq) { |
| 719 | dev_warn(chip->dev, "No interrupt support on TSC IRQ\n"); |
| 720 | return 0; |
| 721 | } |
| 722 | chip->tsc_irq = pdata->tsc_irq; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 723 | ret = request_threaded_irq(chip->tsc_irq, NULL, max8925_tsc_irq, |
Fengguang Wu | 619a1e3 | 2012-09-19 09:41:13 +0800 | [diff] [blame] | 724 | flags | IRQF_ONESHOT, "max8925-tsc", chip); |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 725 | if (ret) { |
| 726 | dev_err(chip->dev, "Failed to request TSC IRQ: %d\n", ret); |
| 727 | chip->tsc_irq = 0; |
| 728 | } |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 729 | return 0; |
| 730 | } |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 731 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 732 | static void init_regulator(struct max8925_chip *chip, |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 733 | struct max8925_platform_data *pdata) |
| 734 | { |
| 735 | int ret; |
| 736 | |
| 737 | if (!pdata) |
| 738 | return; |
| 739 | if (pdata->sd1) { |
| 740 | reg_devs[0].platform_data = pdata->sd1; |
| 741 | reg_devs[0].pdata_size = sizeof(struct regulator_init_data); |
| 742 | } |
| 743 | if (pdata->sd2) { |
| 744 | reg_devs[1].platform_data = pdata->sd2; |
| 745 | reg_devs[1].pdata_size = sizeof(struct regulator_init_data); |
| 746 | } |
| 747 | if (pdata->sd3) { |
| 748 | reg_devs[2].platform_data = pdata->sd3; |
| 749 | reg_devs[2].pdata_size = sizeof(struct regulator_init_data); |
| 750 | } |
| 751 | if (pdata->ldo1) { |
| 752 | reg_devs[3].platform_data = pdata->ldo1; |
| 753 | reg_devs[3].pdata_size = sizeof(struct regulator_init_data); |
| 754 | } |
| 755 | if (pdata->ldo2) { |
| 756 | reg_devs[4].platform_data = pdata->ldo2; |
| 757 | reg_devs[4].pdata_size = sizeof(struct regulator_init_data); |
| 758 | } |
| 759 | if (pdata->ldo3) { |
| 760 | reg_devs[5].platform_data = pdata->ldo3; |
| 761 | reg_devs[5].pdata_size = sizeof(struct regulator_init_data); |
| 762 | } |
| 763 | if (pdata->ldo4) { |
| 764 | reg_devs[6].platform_data = pdata->ldo4; |
| 765 | reg_devs[6].pdata_size = sizeof(struct regulator_init_data); |
| 766 | } |
| 767 | if (pdata->ldo5) { |
| 768 | reg_devs[7].platform_data = pdata->ldo5; |
| 769 | reg_devs[7].pdata_size = sizeof(struct regulator_init_data); |
| 770 | } |
| 771 | if (pdata->ldo6) { |
| 772 | reg_devs[8].platform_data = pdata->ldo6; |
| 773 | reg_devs[8].pdata_size = sizeof(struct regulator_init_data); |
| 774 | } |
| 775 | if (pdata->ldo7) { |
| 776 | reg_devs[9].platform_data = pdata->ldo7; |
| 777 | reg_devs[9].pdata_size = sizeof(struct regulator_init_data); |
| 778 | } |
| 779 | if (pdata->ldo8) { |
| 780 | reg_devs[10].platform_data = pdata->ldo8; |
| 781 | reg_devs[10].pdata_size = sizeof(struct regulator_init_data); |
| 782 | } |
| 783 | if (pdata->ldo9) { |
| 784 | reg_devs[11].platform_data = pdata->ldo9; |
| 785 | reg_devs[11].pdata_size = sizeof(struct regulator_init_data); |
| 786 | } |
| 787 | if (pdata->ldo10) { |
| 788 | reg_devs[12].platform_data = pdata->ldo10; |
| 789 | reg_devs[12].pdata_size = sizeof(struct regulator_init_data); |
| 790 | } |
| 791 | if (pdata->ldo11) { |
| 792 | reg_devs[13].platform_data = pdata->ldo11; |
| 793 | reg_devs[13].pdata_size = sizeof(struct regulator_init_data); |
| 794 | } |
| 795 | if (pdata->ldo12) { |
| 796 | reg_devs[14].platform_data = pdata->ldo12; |
| 797 | reg_devs[14].pdata_size = sizeof(struct regulator_init_data); |
| 798 | } |
| 799 | if (pdata->ldo13) { |
| 800 | reg_devs[15].platform_data = pdata->ldo13; |
| 801 | reg_devs[15].pdata_size = sizeof(struct regulator_init_data); |
| 802 | } |
| 803 | if (pdata->ldo14) { |
| 804 | reg_devs[16].platform_data = pdata->ldo14; |
| 805 | reg_devs[16].pdata_size = sizeof(struct regulator_init_data); |
| 806 | } |
| 807 | if (pdata->ldo15) { |
| 808 | reg_devs[17].platform_data = pdata->ldo15; |
| 809 | reg_devs[17].pdata_size = sizeof(struct regulator_init_data); |
| 810 | } |
| 811 | if (pdata->ldo16) { |
| 812 | reg_devs[18].platform_data = pdata->ldo16; |
| 813 | reg_devs[18].pdata_size = sizeof(struct regulator_init_data); |
| 814 | } |
| 815 | if (pdata->ldo17) { |
| 816 | reg_devs[19].platform_data = pdata->ldo17; |
| 817 | reg_devs[19].pdata_size = sizeof(struct regulator_init_data); |
| 818 | } |
| 819 | if (pdata->ldo18) { |
| 820 | reg_devs[20].platform_data = pdata->ldo18; |
| 821 | reg_devs[20].pdata_size = sizeof(struct regulator_init_data); |
| 822 | } |
| 823 | if (pdata->ldo19) { |
| 824 | reg_devs[21].platform_data = pdata->ldo19; |
| 825 | reg_devs[21].pdata_size = sizeof(struct regulator_init_data); |
| 826 | } |
| 827 | if (pdata->ldo20) { |
| 828 | reg_devs[22].platform_data = pdata->ldo20; |
| 829 | reg_devs[22].pdata_size = sizeof(struct regulator_init_data); |
| 830 | } |
| 831 | ret = mfd_add_devices(chip->dev, 0, reg_devs, ARRAY_SIZE(reg_devs), |
| 832 | NULL, 0, NULL); |
| 833 | if (ret < 0) { |
| 834 | dev_err(chip->dev, "Failed to add regulator subdev\n"); |
| 835 | return; |
| 836 | } |
| 837 | } |
| 838 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 839 | int max8925_device_init(struct max8925_chip *chip, |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 840 | struct max8925_platform_data *pdata) |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 841 | { |
| 842 | int ret; |
| 843 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 844 | max8925_irq_init(chip, chip->i2c->irq, pdata); |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 845 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 846 | if (pdata && (pdata->power || pdata->touch)) { |
| 847 | /* enable ADC to control internal reference */ |
| 848 | max8925_set_bits(chip->i2c, MAX8925_RESET_CNFG, 1, 1); |
| 849 | /* enable internal reference for ADC */ |
| 850 | max8925_set_bits(chip->adc, MAX8925_TSC_CNFG1, 3, 2); |
| 851 | /* check for internal reference IRQ */ |
| 852 | do { |
| 853 | ret = max8925_reg_read(chip->adc, MAX8925_TSC_IRQ); |
| 854 | } while (ret & MAX8925_NREF_OK); |
| 855 | /* enaable ADC scheduler, interval is 1 second */ |
| 856 | max8925_set_bits(chip->adc, MAX8925_ADC_SCHED, 3, 2); |
| 857 | } |
| 858 | |
| 859 | /* enable Momentary Power Loss */ |
| 860 | max8925_set_bits(chip->rtc, MAX8925_MPL_CNTL, 1 << 4, 1 << 4); |
| 861 | |
| 862 | ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0], |
| 863 | ARRAY_SIZE(rtc_devs), |
Qing Xu | f9ed143 | 2013-02-04 23:40:43 +0800 | [diff] [blame] | 864 | NULL, chip->irq_base, NULL); |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 865 | if (ret < 0) { |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 866 | dev_err(chip->dev, "Failed to add rtc subdev\n"); |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 867 | goto out; |
| 868 | } |
Haojian Zhuang | d0f7a6d | 2010-06-18 19:59:53 +0200 | [diff] [blame] | 869 | |
| 870 | ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0], |
| 871 | ARRAY_SIZE(onkey_devs), |
Qing Xu | 678e8cb | 2013-02-04 23:40:44 +0800 | [diff] [blame] | 872 | NULL, chip->irq_base, NULL); |
Haojian Zhuang | d0f7a6d | 2010-06-18 19:59:53 +0200 | [diff] [blame] | 873 | if (ret < 0) { |
| 874 | dev_err(chip->dev, "Failed to add onkey subdev\n"); |
| 875 | goto out_dev; |
| 876 | } |
| 877 | |
Haojian Zhuang | 51acdb6 | 2012-09-17 12:19:05 +0800 | [diff] [blame] | 878 | init_regulator(chip, pdata); |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 879 | |
| 880 | if (pdata && pdata->backlight) { |
Haojian Zhuang | 63b501e | 2012-09-17 12:19:04 +0800 | [diff] [blame] | 881 | bk_devs[0].platform_data = &pdata->backlight; |
| 882 | bk_devs[0].pdata_size = sizeof(struct max8925_backlight_pdata); |
| 883 | } |
| 884 | ret = mfd_add_devices(chip->dev, 0, bk_devs, ARRAY_SIZE(bk_devs), |
| 885 | NULL, 0, NULL); |
| 886 | if (ret < 0) { |
| 887 | dev_err(chip->dev, "Failed to add backlight subdev\n"); |
| 888 | goto out_dev; |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 889 | } |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 890 | |
Qing Xu | f9ed143 | 2013-02-04 23:40:43 +0800 | [diff] [blame] | 891 | ret = mfd_add_devices(chip->dev, 0, &power_devs[0], |
| 892 | ARRAY_SIZE(power_devs), |
| 893 | NULL, 0, NULL); |
| 894 | if (ret < 0) { |
| 895 | dev_err(chip->dev, |
| 896 | "Failed to add power supply subdev, err = %d\n", ret); |
| 897 | goto out_dev; |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 898 | } |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 899 | |
| 900 | if (pdata && pdata->touch) { |
| 901 | ret = mfd_add_devices(chip->dev, 0, &touch_devs[0], |
| 902 | ARRAY_SIZE(touch_devs), |
Qing Xu | f9ed143 | 2013-02-04 23:40:43 +0800 | [diff] [blame] | 903 | NULL, chip->tsc_irq, NULL); |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 904 | if (ret < 0) { |
| 905 | dev_err(chip->dev, "Failed to add touch subdev\n"); |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 906 | goto out_dev; |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 907 | } |
| 908 | } |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 909 | |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 910 | return 0; |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 911 | out_dev: |
| 912 | mfd_remove_devices(chip->dev); |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 913 | out: |
| 914 | return ret; |
| 915 | } |
| 916 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 917 | void max8925_device_exit(struct max8925_chip *chip) |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 918 | { |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 919 | if (chip->core_irq) |
| 920 | free_irq(chip->core_irq, chip); |
| 921 | if (chip->tsc_irq) |
| 922 | free_irq(chip->tsc_irq, chip); |
Haojian Zhuang | 1ad9989 | 2010-01-08 12:43:29 -0500 | [diff] [blame] | 923 | mfd_remove_devices(chip->dev); |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 924 | } |
| 925 | |
Haojian Zhuang | 1f1cf8f | 2010-02-05 16:07:54 +0100 | [diff] [blame] | 926 | |
Haojian Zhuang | d50f8f3 | 2010-01-08 12:29:23 +0100 | [diff] [blame] | 927 | MODULE_DESCRIPTION("PMIC Driver for Maxim MAX8925"); |
| 928 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com"); |
| 929 | MODULE_LICENSE("GPL"); |