max8925-core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * Base driver for Maxim MAX8925
  3. *
  4. * Copyright (C) 2009-2010 Marvell International Ltd.
  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. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/i2c.h>
  14. #include <linux/irq.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/mfd/core.h>
  18. #include <linux/mfd/max8925.h>
  19. static struct resource backlight_resources[] = {
  20. {
  21. .name = "max8925-backlight",
  22. .start = MAX8925_WLED_MODE_CNTL,
  23. .end = MAX8925_WLED_CNTL,
  24. .flags = IORESOURCE_IO,
  25. },
  26. };
  27. static struct mfd_cell backlight_devs[] = {
  28. {
  29. .name = "max8925-backlight",
  30. .num_resources = 1,
  31. .resources = &backlight_resources[0],
  32. .id = -1,
  33. },
  34. };
  35. static struct resource touch_resources[] = {
  36. {
  37. .name = "max8925-tsc",
  38. .start = MAX8925_TSC_IRQ,
  39. .end = MAX8925_ADC_RES_END,
  40. .flags = IORESOURCE_IO,
  41. },
  42. };
  43. static struct mfd_cell touch_devs[] = {
  44. {
  45. .name = "max8925-touch",
  46. .num_resources = 1,
  47. .resources = &touch_resources[0],
  48. .id = -1,
  49. },
  50. };
  51. static struct resource power_supply_resources[] = {
  52. {
  53. .name = "max8925-power",
  54. .start = MAX8925_CHG_IRQ1,
  55. .end = MAX8925_CHG_IRQ1_MASK,
  56. .flags = IORESOURCE_IO,
  57. },
  58. };
  59. static struct mfd_cell power_devs[] = {
  60. {
  61. .name = "max8925-power",
  62. .num_resources = 1,
  63. .resources = &power_supply_resources[0],
  64. .id = -1,
  65. },
  66. };
  67. static struct resource rtc_resources[] = {
  68. {
  69. .name = "max8925-rtc",
  70. .start = MAX8925_RTC_IRQ,
  71. .end = MAX8925_RTC_IRQ_MASK,
  72. .flags = IORESOURCE_IO,
  73. },
  74. };
  75. static struct mfd_cell rtc_devs[] = {
  76. {
  77. .name = "max8925-rtc",
  78. .num_resources = 1,
  79. .resources = &rtc_resources[0],
  80. .id = -1,
  81. },
  82. };
  83. static struct resource onkey_resources[] = {
  84. {
  85. .name = "max8925-onkey",
  86. .start = MAX8925_IRQ_GPM_SW_R,
  87. .end = MAX8925_IRQ_GPM_SW_R,
  88. .flags = IORESOURCE_IRQ,
  89. }, {
  90. .name = "max8925-onkey",
  91. .start = MAX8925_IRQ_GPM_SW_F,
  92. .end = MAX8925_IRQ_GPM_SW_F,
  93. .flags = IORESOURCE_IRQ,
  94. },
  95. };
  96. static struct mfd_cell onkey_devs[] = {
  97. {
  98. .name = "max8925-onkey",
  99. .num_resources = 2,
  100. .resources = &onkey_resources[0],
  101. .id = -1,
  102. },
  103. };
  104. #define MAX8925_REG_RESOURCE(_start, _end) \
  105. { \
  106. .start = MAX8925_##_start, \
  107. .end = MAX8925_##_end, \
  108. .flags = IORESOURCE_IO, \
  109. }
  110. static struct resource regulator_resources[] = {
  111. MAX8925_REG_RESOURCE(SDCTL1, SDCTL1),
  112. MAX8925_REG_RESOURCE(SDCTL2, SDCTL2),
  113. MAX8925_REG_RESOURCE(SDCTL3, SDCTL3),
  114. MAX8925_REG_RESOURCE(LDOCTL1, LDOCTL1),
  115. MAX8925_REG_RESOURCE(LDOCTL2, LDOCTL2),
  116. MAX8925_REG_RESOURCE(LDOCTL3, LDOCTL3),
  117. MAX8925_REG_RESOURCE(LDOCTL4, LDOCTL4),
  118. MAX8925_REG_RESOURCE(LDOCTL5, LDOCTL5),
  119. MAX8925_REG_RESOURCE(LDOCTL6, LDOCTL6),
  120. MAX8925_REG_RESOURCE(LDOCTL7, LDOCTL7),
  121. MAX8925_REG_RESOURCE(LDOCTL8, LDOCTL8),
  122. MAX8925_REG_RESOURCE(LDOCTL9, LDOCTL9),
  123. MAX8925_REG_RESOURCE(LDOCTL10, LDOCTL10),
  124. MAX8925_REG_RESOURCE(LDOCTL11, LDOCTL11),
  125. MAX8925_REG_RESOURCE(LDOCTL12, LDOCTL12),
  126. MAX8925_REG_RESOURCE(LDOCTL13, LDOCTL13),
  127. MAX8925_REG_RESOURCE(LDOCTL14, LDOCTL14),
  128. MAX8925_REG_RESOURCE(LDOCTL15, LDOCTL15),
  129. MAX8925_REG_RESOURCE(LDOCTL16, LDOCTL16),
  130. MAX8925_REG_RESOURCE(LDOCTL17, LDOCTL17),
  131. MAX8925_REG_RESOURCE(LDOCTL18, LDOCTL18),
  132. MAX8925_REG_RESOURCE(LDOCTL19, LDOCTL19),
  133. MAX8925_REG_RESOURCE(LDOCTL20, LDOCTL20),
  134. };
  135. #define MAX8925_REG_DEVS(_id) \
  136. { \
  137. .name = "max8925-regulator", \
  138. .num_resources = 1, \
  139. .resources = &regulator_resources[MAX8925_ID_##_id], \
  140. .id = MAX8925_ID_##_id, \
  141. }
  142. static struct mfd_cell regulator_devs[] = {
  143. MAX8925_REG_DEVS(SD1),
  144. MAX8925_REG_DEVS(SD2),
  145. MAX8925_REG_DEVS(SD3),
  146. MAX8925_REG_DEVS(LDO1),
  147. MAX8925_REG_DEVS(LDO2),
  148. MAX8925_REG_DEVS(LDO3),
  149. MAX8925_REG_DEVS(LDO4),
  150. MAX8925_REG_DEVS(LDO5),
  151. MAX8925_REG_DEVS(LDO6),
  152. MAX8925_REG_DEVS(LDO7),
  153. MAX8925_REG_DEVS(LDO8),
  154. MAX8925_REG_DEVS(LDO9),
  155. MAX8925_REG_DEVS(LDO10),
  156. MAX8925_REG_DEVS(LDO11),
  157. MAX8925_REG_DEVS(LDO12),
  158. MAX8925_REG_DEVS(LDO13),
  159. MAX8925_REG_DEVS(LDO14),
  160. MAX8925_REG_DEVS(LDO15),
  161. MAX8925_REG_DEVS(LDO16),
  162. MAX8925_REG_DEVS(LDO17),
  163. MAX8925_REG_DEVS(LDO18),
  164. MAX8925_REG_DEVS(LDO19),
  165. MAX8925_REG_DEVS(LDO20),
  166. };
  167. enum {
  168. FLAGS_ADC = 1, /* register in ADC component */
  169. FLAGS_RTC, /* register in RTC component */
  170. };
  171. struct max8925_irq_data {
  172. int reg;
  173. int mask_reg;
  174. int enable; /* enable or not */
  175. int offs; /* bit offset in mask register */
  176. int flags;
  177. int tsc_irq;
  178. };
  179. static struct max8925_irq_data max8925_irqs[] = {
  180. [MAX8925_IRQ_VCHG_DC_OVP] = {
  181. .reg = MAX8925_CHG_IRQ1,
  182. .mask_reg = MAX8925_CHG_IRQ1_MASK,
  183. .offs = 1 << 0,
  184. },
  185. [MAX8925_IRQ_VCHG_DC_F] = {
  186. .reg = MAX8925_CHG_IRQ1,
  187. .mask_reg = MAX8925_CHG_IRQ1_MASK,
  188. .offs = 1 << 1,
  189. },
  190. [MAX8925_IRQ_VCHG_DC_R] = {
  191. .reg = MAX8925_CHG_IRQ1,
  192. .mask_reg = MAX8925_CHG_IRQ1_MASK,
  193. .offs = 1 << 2,
  194. },
  195. [MAX8925_IRQ_VCHG_USB_OVP] = {
  196. .reg = MAX8925_CHG_IRQ1,
  197. .mask_reg = MAX8925_CHG_IRQ1_MASK,
  198. .offs = 1 << 3,
  199. },
  200. [MAX8925_IRQ_VCHG_USB_F] = {
  201. .reg = MAX8925_CHG_IRQ1,
  202. .mask_reg = MAX8925_CHG_IRQ1_MASK,
  203. .offs = 1 << 4,
  204. },
  205. [MAX8925_IRQ_VCHG_USB_R] = {
  206. .reg = MAX8925_CHG_IRQ1,
  207. .mask_reg = MAX8925_CHG_IRQ1_MASK,
  208. .offs = 1 << 5,
  209. },
  210. [MAX8925_IRQ_VCHG_THM_OK_R] = {
  211. .reg = MAX8925_CHG_IRQ2,
  212. .mask_reg = MAX8925_CHG_IRQ2_MASK,
  213. .offs = 1 << 0,
  214. },
  215. [MAX8925_IRQ_VCHG_THM_OK_F] = {
  216. .reg = MAX8925_CHG_IRQ2,
  217. .mask_reg = MAX8925_CHG_IRQ2_MASK,
  218. .offs = 1 << 1,
  219. },
  220. [MAX8925_IRQ_VCHG_SYSLOW_F] = {
  221. .reg = MAX8925_CHG_IRQ2,
  222. .mask_reg = MAX8925_CHG_IRQ2_MASK,
  223. .offs = 1 << 2,
  224. },
  225. [MAX8925_IRQ_VCHG_SYSLOW_R] = {
  226. .reg = MAX8925_CHG_IRQ2,
  227. .mask_reg = MAX8925_CHG_IRQ2_MASK,
  228. .offs = 1 << 3,
  229. },
  230. [MAX8925_IRQ_VCHG_RST] = {
  231. .reg = MAX8925_CHG_IRQ2,
  232. .mask_reg = MAX8925_CHG_IRQ2_MASK,
  233. .offs = 1 << 4,
  234. },
  235. [MAX8925_IRQ_VCHG_DONE] = {
  236. .reg = MAX8925_CHG_IRQ2,
  237. .mask_reg = MAX8925_CHG_IRQ2_MASK,
  238. .offs = 1 << 5,
  239. },
  240. [MAX8925_IRQ_VCHG_TOPOFF] = {
  241. .reg = MAX8925_CHG_IRQ2,
  242. .mask_reg = MAX8925_CHG_IRQ2_MASK,
  243. .offs = 1 << 6,
  244. },
  245. [MAX8925_IRQ_VCHG_TMR_FAULT] = {
  246. .reg = MAX8925_CHG_IRQ2,
  247. .mask_reg = MAX8925_CHG_IRQ2_MASK,
  248. .offs = 1 << 7,
  249. },
  250. [MAX8925_IRQ_GPM_RSTIN] = {
  251. .reg = MAX8925_ON_OFF_IRQ1,
  252. .mask_reg = MAX8925_ON_OFF_IRQ1_MASK,
  253. .offs = 1 << 0,
  254. },
  255. [MAX8925_IRQ_GPM_MPL] = {
  256. .reg = MAX8925_ON_OFF_IRQ1,
  257. .mask_reg = MAX8925_ON_OFF_IRQ1_MASK,
  258. .offs = 1 << 1,
  259. },
  260. [MAX8925_IRQ_GPM_SW_3SEC] = {
  261. .reg = MAX8925_ON_OFF_IRQ1,
  262. .mask_reg = MAX8925_ON_OFF_IRQ1_MASK,
  263. .offs = 1 << 2,
  264. },
  265. [MAX8925_IRQ_GPM_EXTON_F] = {
  266. .reg = MAX8925_ON_OFF_IRQ1,
  267. .mask_reg = MAX8925_ON_OFF_IRQ1_MASK,
  268. .offs = 1 << 3,
  269. },
  270. [MAX8925_IRQ_GPM_EXTON_R] = {
  271. .reg = MAX8925_ON_OFF_IRQ1,
  272. .mask_reg = MAX8925_ON_OFF_IRQ1_MASK,
  273. .offs = 1 << 4,
  274. },
  275. [MAX8925_IRQ_GPM_SW_1SEC] = {
  276. .reg = MAX8925_ON_OFF_IRQ1,
  277. .mask_reg = MAX8925_ON_OFF_IRQ1_MASK,
  278. .offs = 1 << 5,
  279. },
  280. [MAX8925_IRQ_GPM_SW_F] = {
  281. .reg = MAX8925_ON_OFF_IRQ1,
  282. .mask_reg = MAX8925_ON_OFF_IRQ1_MASK,
  283. .offs = 1 << 6,
  284. },
  285. [MAX8925_IRQ_GPM_SW_R] = {
  286. .reg = MAX8925_ON_OFF_IRQ1,
  287. .mask_reg = MAX8925_ON_OFF_IRQ1_MASK,
  288. .offs = 1 << 7,
  289. },
  290. [MAX8925_IRQ_GPM_SYSCKEN_F] = {
  291. .reg = MAX8925_ON_OFF_IRQ2,
  292. .mask_reg = MAX8925_ON_OFF_IRQ2_MASK,
  293. .offs = 1 << 0,
  294. },
  295. [MAX8925_IRQ_GPM_SYSCKEN_R] = {
  296. .reg = MAX8925_ON_OFF_IRQ2,
  297. .mask_reg = MAX8925_ON_OFF_IRQ2_MASK,
  298. .offs = 1 << 1,
  299. },
  300. [MAX8925_IRQ_RTC_ALARM1] = {
  301. .reg = MAX8925_RTC_IRQ,
  302. .mask_reg = MAX8925_RTC_IRQ_MASK,
  303. .offs = 1 << 2,
  304. .flags = FLAGS_RTC,
  305. },
  306. [MAX8925_IRQ_RTC_ALARM0] = {
  307. .reg = MAX8925_RTC_IRQ,
  308. .mask_reg = MAX8925_RTC_IRQ_MASK,
  309. .offs = 1 << 3,
  310. .flags = FLAGS_RTC,
  311. },
  312. [MAX8925_IRQ_TSC_STICK] = {
  313. .reg = MAX8925_TSC_IRQ,
  314. .mask_reg = MAX8925_TSC_IRQ_MASK,
  315. .offs = 1 << 0,
  316. .flags = FLAGS_ADC,
  317. .tsc_irq = 1,
  318. },
  319. [MAX8925_IRQ_TSC_NSTICK] = {
  320. .reg = MAX8925_TSC_IRQ,
  321. .mask_reg = MAX8925_TSC_IRQ_MASK,
  322. .offs = 1 << 1,
  323. .flags = FLAGS_ADC,
  324. .tsc_irq = 1,
  325. },
  326. };
  327. static inline struct max8925_irq_data *irq_to_max8925(struct max8925_chip *chip,
  328. int irq)
  329. {
  330. return &max8925_irqs[irq - chip->irq_base];
  331. }
  332. static irqreturn_t max8925_irq(int irq, void *data)
  333. {
  334. struct max8925_chip *chip = data;
  335. struct max8925_irq_data *irq_data;
  336. struct i2c_client *i2c;
  337. int read_reg = -1, value = 0;
  338. int i;
  339. for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) {
  340. irq_data = &max8925_irqs[i];
  341. /* TSC IRQ should be serviced in max8925_tsc_irq() */
  342. if (irq_data->tsc_irq)
  343. continue;
  344. if (irq_data->flags == FLAGS_RTC)
  345. i2c = chip->rtc;
  346. else if (irq_data->flags == FLAGS_ADC)
  347. i2c = chip->adc;
  348. else
  349. i2c = chip->i2c;
  350. if (read_reg != irq_data->reg) {
  351. read_reg = irq_data->reg;
  352. value = max8925_reg_read(i2c, irq_data->reg);
  353. }
  354. if (value & irq_data->enable)
  355. handle_nested_irq(chip->irq_base + i);
  356. }
  357. return IRQ_HANDLED;
  358. }
  359. static irqreturn_t max8925_tsc_irq(int irq, void *data)
  360. {
  361. struct max8925_chip *chip = data;
  362. struct max8925_irq_data *irq_data;
  363. struct i2c_client *i2c;
  364. int read_reg = -1, value = 0;
  365. int i;
  366. for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) {
  367. irq_data = &max8925_irqs[i];
  368. /* non TSC IRQ should be serviced in max8925_irq() */
  369. if (!irq_data->tsc_irq)
  370. continue;
  371. if (irq_data->flags == FLAGS_RTC)
  372. i2c = chip->rtc;
  373. else if (irq_data->flags == FLAGS_ADC)
  374. i2c = chip->adc;
  375. else
  376. i2c = chip->i2c;
  377. if (read_reg != irq_data->reg) {
  378. read_reg = irq_data->reg;
  379. value = max8925_reg_read(i2c, irq_data->reg);
  380. }
  381. if (value & irq_data->enable)
  382. handle_nested_irq(chip->irq_base + i);
  383. }
  384. return IRQ_HANDLED;
  385. }
  386. static void max8925_irq_lock(struct irq_data *data)
  387. {
  388. struct max8925_chip *chip = irq_data_get_irq_chip_data(data);
  389. mutex_lock(&chip->irq_lock);
  390. }
  391. static void max8925_irq_sync_unlock(struct irq_data *data)
  392. {
  393. struct max8925_chip *chip = irq_data_get_irq_chip_data(data);
  394. struct max8925_irq_data *irq_data;
  395. static unsigned char cache_chg[2] = {0xff, 0xff};
  396. static unsigned char cache_on[2] = {0xff, 0xff};
  397. static unsigned char cache_rtc = 0xff, cache_tsc = 0xff;
  398. unsigned char irq_chg[2], irq_on[2];
  399. unsigned char irq_rtc, irq_tsc;
  400. int i;
  401. /* Load cached value. In initial, all IRQs are masked */
  402. irq_chg[0] = cache_chg[0];
  403. irq_chg[1] = cache_chg[1];
  404. irq_on[0] = cache_on[0];
  405. irq_on[1] = cache_on[1];
  406. irq_rtc = cache_rtc;
  407. irq_tsc = cache_tsc;
  408. for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) {
  409. irq_data = &max8925_irqs[i];
  410. /* 1 -- disable, 0 -- enable */
  411. switch (irq_data->mask_reg) {
  412. case MAX8925_CHG_IRQ1_MASK:
  413. irq_chg[0] &= ~irq_data->enable;
  414. break;
  415. case MAX8925_CHG_IRQ2_MASK:
  416. irq_chg[1] &= ~irq_data->enable;
  417. break;
  418. case MAX8925_ON_OFF_IRQ1_MASK:
  419. irq_on[0] &= ~irq_data->enable;
  420. break;
  421. case MAX8925_ON_OFF_IRQ2_MASK:
  422. irq_on[1] &= ~irq_data->enable;
  423. break;
  424. case MAX8925_RTC_IRQ_MASK:
  425. irq_rtc &= ~irq_data->enable;
  426. break;
  427. case MAX8925_TSC_IRQ_MASK:
  428. irq_tsc &= ~irq_data->enable;
  429. break;
  430. default:
  431. dev_err(chip->dev, "wrong IRQ\n");
  432. break;
  433. }
  434. }
  435. /* update mask into registers */
  436. if (cache_chg[0] != irq_chg[0]) {
  437. cache_chg[0] = irq_chg[0];
  438. max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ1_MASK,
  439. irq_chg[0]);
  440. }
  441. if (cache_chg[1] != irq_chg[1]) {
  442. cache_chg[1] = irq_chg[1];
  443. max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ2_MASK,
  444. irq_chg[1]);
  445. }
  446. if (cache_on[0] != irq_on[0]) {
  447. cache_on[0] = irq_on[0];
  448. max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ1_MASK,
  449. irq_on[0]);
  450. }
  451. if (cache_on[1] != irq_on[1]) {
  452. cache_on[1] = irq_on[1];
  453. max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ2_MASK,
  454. irq_on[1]);
  455. }
  456. if (cache_rtc != irq_rtc) {
  457. cache_rtc = irq_rtc;
  458. max8925_reg_write(chip->rtc, MAX8925_RTC_IRQ_MASK, irq_rtc);
  459. }
  460. if (cache_tsc != irq_tsc) {
  461. cache_tsc = irq_tsc;
  462. max8925_reg_write(chip->adc, MAX8925_TSC_IRQ_MASK, irq_tsc);
  463. }
  464. mutex_unlock(&chip->irq_lock);
  465. }
  466. static void max8925_irq_enable(struct irq_data *data)
  467. {
  468. struct max8925_chip *chip = irq_data_get_irq_chip_data(data);
  469. max8925_irqs[data->irq - chip->irq_base].enable
  470. = max8925_irqs[data->irq - chip->irq_base].offs;
  471. }
  472. static void max8925_irq_disable(struct irq_data *data)
  473. {
  474. struct max8925_chip *chip = irq_data_get_irq_chip_data(data);
  475. max8925_irqs[data->irq - chip->irq_base].enable = 0;
  476. }
  477. static struct irq_chip max8925_irq_chip = {
  478. .name = "max8925",
  479. .irq_bus_lock = max8925_irq_lock,
  480. .irq_bus_sync_unlock = max8925_irq_sync_unlock,
  481. .irq_enable = max8925_irq_enable,
  482. .irq_disable = max8925_irq_disable,
  483. };
  484. static int max8925_irq_init(struct max8925_chip *chip, int irq,
  485. struct max8925_platform_data *pdata)
  486. {
  487. unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
  488. int i, ret;
  489. int __irq;
  490. if (!pdata || !pdata->irq_base) {
  491. dev_warn(chip->dev, "No interrupt support on IRQ base\n");
  492. return -EINVAL;
  493. }
  494. /* clear all interrupts */
  495. max8925_reg_read(chip->i2c, MAX8925_CHG_IRQ1);
  496. max8925_reg_read(chip->i2c, MAX8925_CHG_IRQ2);
  497. max8925_reg_read(chip->i2c, MAX8925_ON_OFF_IRQ1);
  498. max8925_reg_read(chip->i2c, MAX8925_ON_OFF_IRQ2);
  499. max8925_reg_read(chip->rtc, MAX8925_RTC_IRQ);
  500. max8925_reg_read(chip->adc, MAX8925_TSC_IRQ);
  501. /* mask all interrupts except for TSC */
  502. max8925_reg_write(chip->rtc, MAX8925_ALARM0_CNTL, 0);
  503. max8925_reg_write(chip->rtc, MAX8925_ALARM1_CNTL, 0);
  504. max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ1_MASK, 0xff);
  505. max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ2_MASK, 0xff);
  506. max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ1_MASK, 0xff);
  507. max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ2_MASK, 0xff);
  508. max8925_reg_write(chip->rtc, MAX8925_RTC_IRQ_MASK, 0xff);
  509. mutex_init(&chip->irq_lock);
  510. chip->core_irq = irq;
  511. chip->irq_base = pdata->irq_base;
  512. /* register with genirq */
  513. for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) {
  514. __irq = i + chip->irq_base;
  515. irq_set_chip_data(__irq, chip);
  516. irq_set_chip_and_handler(__irq, &max8925_irq_chip,
  517. handle_edge_irq);
  518. irq_set_nested_thread(__irq, 1);
  519. #ifdef CONFIG_ARM
  520. set_irq_flags(__irq, IRQF_VALID);
  521. #else
  522. irq_set_noprobe(__irq);
  523. #endif
  524. }
  525. if (!irq) {
  526. dev_warn(chip->dev, "No interrupt support on core IRQ\n");
  527. goto tsc_irq;
  528. }
  529. ret = request_threaded_irq(irq, NULL, max8925_irq, flags,
  530. "max8925", chip);
  531. if (ret) {
  532. dev_err(chip->dev, "Failed to request core IRQ: %d\n", ret);
  533. chip->core_irq = 0;
  534. }
  535. tsc_irq:
  536. /* mask TSC interrupt */
  537. max8925_reg_write(chip->adc, MAX8925_TSC_IRQ_MASK, 0x0f);
  538. if (!pdata->tsc_irq) {
  539. dev_warn(chip->dev, "No interrupt support on TSC IRQ\n");
  540. return 0;
  541. }
  542. chip->tsc_irq = pdata->tsc_irq;
  543. ret = request_threaded_irq(chip->tsc_irq, NULL, max8925_tsc_irq,
  544. flags, "max8925-tsc", chip);
  545. if (ret) {
  546. dev_err(chip->dev, "Failed to request TSC IRQ: %d\n", ret);
  547. chip->tsc_irq = 0;
  548. }
  549. return 0;
  550. }
  551. int __devinit max8925_device_init(struct max8925_chip *chip,
  552. struct max8925_platform_data *pdata)
  553. {
  554. int ret;
  555. max8925_irq_init(chip, chip->i2c->irq, pdata);
  556. if (pdata && (pdata->power || pdata->touch)) {
  557. /* enable ADC to control internal reference */
  558. max8925_set_bits(chip->i2c, MAX8925_RESET_CNFG, 1, 1);
  559. /* enable internal reference for ADC */
  560. max8925_set_bits(chip->adc, MAX8925_TSC_CNFG1, 3, 2);
  561. /* check for internal reference IRQ */
  562. do {
  563. ret = max8925_reg_read(chip->adc, MAX8925_TSC_IRQ);
  564. } while (ret & MAX8925_NREF_OK);
  565. /* enaable ADC scheduler, interval is 1 second */
  566. max8925_set_bits(chip->adc, MAX8925_ADC_SCHED, 3, 2);
  567. }
  568. /* enable Momentary Power Loss */
  569. max8925_set_bits(chip->rtc, MAX8925_MPL_CNTL, 1 << 4, 1 << 4);
  570. ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0],
  571. ARRAY_SIZE(rtc_devs),
  572. &rtc_resources[0], 0);
  573. if (ret < 0) {
  574. dev_err(chip->dev, "Failed to add rtc subdev\n");
  575. goto out;
  576. }
  577. ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
  578. ARRAY_SIZE(onkey_devs),
  579. &onkey_resources[0], 0);
  580. if (ret < 0) {
  581. dev_err(chip->dev, "Failed to add onkey subdev\n");
  582. goto out_dev;
  583. }
  584. if (pdata) {
  585. ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
  586. ARRAY_SIZE(regulator_devs),
  587. &regulator_resources[0], 0);
  588. if (ret < 0) {
  589. dev_err(chip->dev, "Failed to add regulator subdev\n");
  590. goto out_dev;
  591. }
  592. }
  593. if (pdata && pdata->backlight) {
  594. ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0],
  595. ARRAY_SIZE(backlight_devs),
  596. &backlight_resources[0], 0);
  597. if (ret < 0) {
  598. dev_err(chip->dev, "Failed to add backlight subdev\n");
  599. goto out_dev;
  600. }
  601. }
  602. if (pdata && pdata->power) {
  603. ret = mfd_add_devices(chip->dev, 0, &power_devs[0],
  604. ARRAY_SIZE(power_devs),
  605. &power_supply_resources[0], 0);
  606. if (ret < 0) {
  607. dev_err(chip->dev, "Failed to add power supply "
  608. "subdev\n");
  609. goto out_dev;
  610. }
  611. }
  612. if (pdata && pdata->touch) {
  613. ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
  614. ARRAY_SIZE(touch_devs),
  615. &touch_resources[0], 0);
  616. if (ret < 0) {
  617. dev_err(chip->dev, "Failed to add touch subdev\n");
  618. goto out_dev;
  619. }
  620. }
  621. return 0;
  622. out_dev:
  623. mfd_remove_devices(chip->dev);
  624. out:
  625. return ret;
  626. }
  627. void __devexit max8925_device_exit(struct max8925_chip *chip)
  628. {
  629. if (chip->core_irq)
  630. free_irq(chip->core_irq, chip);
  631. if (chip->tsc_irq)
  632. free_irq(chip->tsc_irq, chip);
  633. mfd_remove_devices(chip->dev);
  634. }
  635. MODULE_DESCRIPTION("PMIC Driver for Maxim MAX8925");
  636. MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com");
  637. MODULE_LICENSE("GPL");