da9052-core.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * Device access for Dialog DA9052 PMICs.
  3. *
  4. * Copyright(c) 2011 Dialog Semiconductor Ltd.
  5. *
  6. * Author: David Dajun Chen <dchen@diasemi.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/device.h>
  14. #include <linux/delay.h>
  15. #include <linux/input.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/irq.h>
  18. #include <linux/mfd/core.h>
  19. #include <linux/slab.h>
  20. #include <linux/module.h>
  21. #include <linux/mfd/da9052/da9052.h>
  22. #include <linux/mfd/da9052/pdata.h>
  23. #include <linux/mfd/da9052/reg.h>
  24. #define DA9052_NUM_IRQ_REGS 4
  25. #define DA9052_IRQ_MASK_POS_1 0x01
  26. #define DA9052_IRQ_MASK_POS_2 0x02
  27. #define DA9052_IRQ_MASK_POS_3 0x04
  28. #define DA9052_IRQ_MASK_POS_4 0x08
  29. #define DA9052_IRQ_MASK_POS_5 0x10
  30. #define DA9052_IRQ_MASK_POS_6 0x20
  31. #define DA9052_IRQ_MASK_POS_7 0x40
  32. #define DA9052_IRQ_MASK_POS_8 0x80
  33. static bool da9052_reg_readable(struct device *dev, unsigned int reg)
  34. {
  35. switch (reg) {
  36. case DA9052_PAGE0_CON_REG:
  37. case DA9052_STATUS_A_REG:
  38. case DA9052_STATUS_B_REG:
  39. case DA9052_STATUS_C_REG:
  40. case DA9052_STATUS_D_REG:
  41. case DA9052_EVENT_A_REG:
  42. case DA9052_EVENT_B_REG:
  43. case DA9052_EVENT_C_REG:
  44. case DA9052_EVENT_D_REG:
  45. case DA9052_FAULTLOG_REG:
  46. case DA9052_IRQ_MASK_A_REG:
  47. case DA9052_IRQ_MASK_B_REG:
  48. case DA9052_IRQ_MASK_C_REG:
  49. case DA9052_IRQ_MASK_D_REG:
  50. case DA9052_CONTROL_A_REG:
  51. case DA9052_CONTROL_B_REG:
  52. case DA9052_CONTROL_C_REG:
  53. case DA9052_CONTROL_D_REG:
  54. case DA9052_PDDIS_REG:
  55. case DA9052_INTERFACE_REG:
  56. case DA9052_RESET_REG:
  57. case DA9052_GPIO_0_1_REG:
  58. case DA9052_GPIO_2_3_REG:
  59. case DA9052_GPIO_4_5_REG:
  60. case DA9052_GPIO_6_7_REG:
  61. case DA9052_GPIO_14_15_REG:
  62. case DA9052_ID_0_1_REG:
  63. case DA9052_ID_2_3_REG:
  64. case DA9052_ID_4_5_REG:
  65. case DA9052_ID_6_7_REG:
  66. case DA9052_ID_8_9_REG:
  67. case DA9052_ID_10_11_REG:
  68. case DA9052_ID_12_13_REG:
  69. case DA9052_ID_14_15_REG:
  70. case DA9052_ID_16_17_REG:
  71. case DA9052_ID_18_19_REG:
  72. case DA9052_ID_20_21_REG:
  73. case DA9052_SEQ_STATUS_REG:
  74. case DA9052_SEQ_A_REG:
  75. case DA9052_SEQ_B_REG:
  76. case DA9052_SEQ_TIMER_REG:
  77. case DA9052_BUCKA_REG:
  78. case DA9052_BUCKB_REG:
  79. case DA9052_BUCKCORE_REG:
  80. case DA9052_BUCKPRO_REG:
  81. case DA9052_BUCKMEM_REG:
  82. case DA9052_BUCKPERI_REG:
  83. case DA9052_LDO1_REG:
  84. case DA9052_LDO2_REG:
  85. case DA9052_LDO3_REG:
  86. case DA9052_LDO4_REG:
  87. case DA9052_LDO5_REG:
  88. case DA9052_LDO6_REG:
  89. case DA9052_LDO7_REG:
  90. case DA9052_LDO8_REG:
  91. case DA9052_LDO9_REG:
  92. case DA9052_LDO10_REG:
  93. case DA9052_SUPPLY_REG:
  94. case DA9052_PULLDOWN_REG:
  95. case DA9052_CHGBUCK_REG:
  96. case DA9052_WAITCONT_REG:
  97. case DA9052_ISET_REG:
  98. case DA9052_BATCHG_REG:
  99. case DA9052_CHG_CONT_REG:
  100. case DA9052_INPUT_CONT_REG:
  101. case DA9052_CHG_TIME_REG:
  102. case DA9052_BBAT_CONT_REG:
  103. case DA9052_BOOST_REG:
  104. case DA9052_LED_CONT_REG:
  105. case DA9052_LEDMIN123_REG:
  106. case DA9052_LED1_CONF_REG:
  107. case DA9052_LED2_CONF_REG:
  108. case DA9052_LED3_CONF_REG:
  109. case DA9052_LED1CONT_REG:
  110. case DA9052_LED2CONT_REG:
  111. case DA9052_LED3CONT_REG:
  112. case DA9052_LED_CONT_4_REG:
  113. case DA9052_LED_CONT_5_REG:
  114. case DA9052_ADC_MAN_REG:
  115. case DA9052_ADC_CONT_REG:
  116. case DA9052_ADC_RES_L_REG:
  117. case DA9052_ADC_RES_H_REG:
  118. case DA9052_VDD_RES_REG:
  119. case DA9052_VDD_MON_REG:
  120. case DA9052_ICHG_AV_REG:
  121. case DA9052_ICHG_THD_REG:
  122. case DA9052_ICHG_END_REG:
  123. case DA9052_TBAT_RES_REG:
  124. case DA9052_TBAT_HIGHP_REG:
  125. case DA9052_TBAT_HIGHN_REG:
  126. case DA9052_TBAT_LOW_REG:
  127. case DA9052_T_OFFSET_REG:
  128. case DA9052_ADCIN4_RES_REG:
  129. case DA9052_AUTO4_HIGH_REG:
  130. case DA9052_AUTO4_LOW_REG:
  131. case DA9052_ADCIN5_RES_REG:
  132. case DA9052_AUTO5_HIGH_REG:
  133. case DA9052_AUTO5_LOW_REG:
  134. case DA9052_ADCIN6_RES_REG:
  135. case DA9052_AUTO6_HIGH_REG:
  136. case DA9052_AUTO6_LOW_REG:
  137. case DA9052_TJUNC_RES_REG:
  138. case DA9052_TSI_CONT_A_REG:
  139. case DA9052_TSI_CONT_B_REG:
  140. case DA9052_TSI_X_MSB_REG:
  141. case DA9052_TSI_Y_MSB_REG:
  142. case DA9052_TSI_LSB_REG:
  143. case DA9052_TSI_Z_MSB_REG:
  144. case DA9052_COUNT_S_REG:
  145. case DA9052_COUNT_MI_REG:
  146. case DA9052_COUNT_H_REG:
  147. case DA9052_COUNT_D_REG:
  148. case DA9052_COUNT_MO_REG:
  149. case DA9052_COUNT_Y_REG:
  150. case DA9052_ALARM_MI_REG:
  151. case DA9052_ALARM_H_REG:
  152. case DA9052_ALARM_D_REG:
  153. case DA9052_ALARM_MO_REG:
  154. case DA9052_ALARM_Y_REG:
  155. case DA9052_SECOND_A_REG:
  156. case DA9052_SECOND_B_REG:
  157. case DA9052_SECOND_C_REG:
  158. case DA9052_SECOND_D_REG:
  159. case DA9052_PAGE1_CON_REG:
  160. return true;
  161. default:
  162. return false;
  163. }
  164. }
  165. static bool da9052_reg_writeable(struct device *dev, unsigned int reg)
  166. {
  167. switch (reg) {
  168. case DA9052_PAGE0_CON_REG:
  169. case DA9052_EVENT_A_REG:
  170. case DA9052_EVENT_B_REG:
  171. case DA9052_EVENT_C_REG:
  172. case DA9052_EVENT_D_REG:
  173. case DA9052_IRQ_MASK_A_REG:
  174. case DA9052_IRQ_MASK_B_REG:
  175. case DA9052_IRQ_MASK_C_REG:
  176. case DA9052_IRQ_MASK_D_REG:
  177. case DA9052_CONTROL_A_REG:
  178. case DA9052_CONTROL_B_REG:
  179. case DA9052_CONTROL_C_REG:
  180. case DA9052_CONTROL_D_REG:
  181. case DA9052_PDDIS_REG:
  182. case DA9052_RESET_REG:
  183. case DA9052_GPIO_0_1_REG:
  184. case DA9052_GPIO_2_3_REG:
  185. case DA9052_GPIO_4_5_REG:
  186. case DA9052_GPIO_6_7_REG:
  187. case DA9052_GPIO_14_15_REG:
  188. case DA9052_ID_0_1_REG:
  189. case DA9052_ID_2_3_REG:
  190. case DA9052_ID_4_5_REG:
  191. case DA9052_ID_6_7_REG:
  192. case DA9052_ID_8_9_REG:
  193. case DA9052_ID_10_11_REG:
  194. case DA9052_ID_12_13_REG:
  195. case DA9052_ID_14_15_REG:
  196. case DA9052_ID_16_17_REG:
  197. case DA9052_ID_18_19_REG:
  198. case DA9052_ID_20_21_REG:
  199. case DA9052_SEQ_STATUS_REG:
  200. case DA9052_SEQ_A_REG:
  201. case DA9052_SEQ_B_REG:
  202. case DA9052_SEQ_TIMER_REG:
  203. case DA9052_BUCKA_REG:
  204. case DA9052_BUCKB_REG:
  205. case DA9052_BUCKCORE_REG:
  206. case DA9052_BUCKPRO_REG:
  207. case DA9052_BUCKMEM_REG:
  208. case DA9052_BUCKPERI_REG:
  209. case DA9052_LDO1_REG:
  210. case DA9052_LDO2_REG:
  211. case DA9052_LDO3_REG:
  212. case DA9052_LDO4_REG:
  213. case DA9052_LDO5_REG:
  214. case DA9052_LDO6_REG:
  215. case DA9052_LDO7_REG:
  216. case DA9052_LDO8_REG:
  217. case DA9052_LDO9_REG:
  218. case DA9052_LDO10_REG:
  219. case DA9052_SUPPLY_REG:
  220. case DA9052_PULLDOWN_REG:
  221. case DA9052_CHGBUCK_REG:
  222. case DA9052_WAITCONT_REG:
  223. case DA9052_ISET_REG:
  224. case DA9052_BATCHG_REG:
  225. case DA9052_CHG_CONT_REG:
  226. case DA9052_INPUT_CONT_REG:
  227. case DA9052_BBAT_CONT_REG:
  228. case DA9052_BOOST_REG:
  229. case DA9052_LED_CONT_REG:
  230. case DA9052_LEDMIN123_REG:
  231. case DA9052_LED1_CONF_REG:
  232. case DA9052_LED2_CONF_REG:
  233. case DA9052_LED3_CONF_REG:
  234. case DA9052_LED1CONT_REG:
  235. case DA9052_LED2CONT_REG:
  236. case DA9052_LED3CONT_REG:
  237. case DA9052_LED_CONT_4_REG:
  238. case DA9052_LED_CONT_5_REG:
  239. case DA9052_ADC_MAN_REG:
  240. case DA9052_ADC_CONT_REG:
  241. case DA9052_ADC_RES_L_REG:
  242. case DA9052_ADC_RES_H_REG:
  243. case DA9052_VDD_RES_REG:
  244. case DA9052_VDD_MON_REG:
  245. case DA9052_ICHG_THD_REG:
  246. case DA9052_ICHG_END_REG:
  247. case DA9052_TBAT_HIGHP_REG:
  248. case DA9052_TBAT_HIGHN_REG:
  249. case DA9052_TBAT_LOW_REG:
  250. case DA9052_T_OFFSET_REG:
  251. case DA9052_AUTO4_HIGH_REG:
  252. case DA9052_AUTO4_LOW_REG:
  253. case DA9052_AUTO5_HIGH_REG:
  254. case DA9052_AUTO5_LOW_REG:
  255. case DA9052_AUTO6_HIGH_REG:
  256. case DA9052_AUTO6_LOW_REG:
  257. case DA9052_TSI_CONT_A_REG:
  258. case DA9052_TSI_CONT_B_REG:
  259. case DA9052_COUNT_S_REG:
  260. case DA9052_COUNT_MI_REG:
  261. case DA9052_COUNT_H_REG:
  262. case DA9052_COUNT_D_REG:
  263. case DA9052_COUNT_MO_REG:
  264. case DA9052_COUNT_Y_REG:
  265. case DA9052_ALARM_MI_REG:
  266. case DA9052_ALARM_H_REG:
  267. case DA9052_ALARM_D_REG:
  268. case DA9052_ALARM_MO_REG:
  269. case DA9052_ALARM_Y_REG:
  270. case DA9052_PAGE1_CON_REG:
  271. return true;
  272. default:
  273. return false;
  274. }
  275. }
  276. static bool da9052_reg_volatile(struct device *dev, unsigned int reg)
  277. {
  278. switch (reg) {
  279. case DA9052_STATUS_A_REG:
  280. case DA9052_STATUS_B_REG:
  281. case DA9052_STATUS_C_REG:
  282. case DA9052_STATUS_D_REG:
  283. case DA9052_EVENT_A_REG:
  284. case DA9052_EVENT_B_REG:
  285. case DA9052_EVENT_C_REG:
  286. case DA9052_EVENT_D_REG:
  287. case DA9052_FAULTLOG_REG:
  288. case DA9052_CHG_TIME_REG:
  289. case DA9052_ADC_RES_L_REG:
  290. case DA9052_ADC_RES_H_REG:
  291. case DA9052_VDD_RES_REG:
  292. case DA9052_ICHG_AV_REG:
  293. case DA9052_TBAT_RES_REG:
  294. case DA9052_ADCIN4_RES_REG:
  295. case DA9052_ADCIN5_RES_REG:
  296. case DA9052_ADCIN6_RES_REG:
  297. case DA9052_TJUNC_RES_REG:
  298. case DA9052_TSI_X_MSB_REG:
  299. case DA9052_TSI_Y_MSB_REG:
  300. case DA9052_TSI_LSB_REG:
  301. case DA9052_TSI_Z_MSB_REG:
  302. case DA9052_COUNT_S_REG:
  303. case DA9052_COUNT_MI_REG:
  304. case DA9052_COUNT_H_REG:
  305. case DA9052_COUNT_D_REG:
  306. case DA9052_COUNT_MO_REG:
  307. case DA9052_COUNT_Y_REG:
  308. case DA9052_ALARM_MI_REG:
  309. return true;
  310. default:
  311. return false;
  312. }
  313. }
  314. static struct resource da9052_rtc_resource = {
  315. .name = "ALM",
  316. .start = DA9052_IRQ_ALARM,
  317. .end = DA9052_IRQ_ALARM,
  318. .flags = IORESOURCE_IRQ,
  319. };
  320. static struct resource da9052_onkey_resource = {
  321. .name = "ONKEY",
  322. .start = DA9052_IRQ_NONKEY,
  323. .end = DA9052_IRQ_NONKEY,
  324. .flags = IORESOURCE_IRQ,
  325. };
  326. static struct resource da9052_bat_resources[] = {
  327. {
  328. .name = "BATT TEMP",
  329. .start = DA9052_IRQ_TBAT,
  330. .end = DA9052_IRQ_TBAT,
  331. .flags = IORESOURCE_IRQ,
  332. },
  333. {
  334. .name = "DCIN DET",
  335. .start = DA9052_IRQ_DCIN,
  336. .end = DA9052_IRQ_DCIN,
  337. .flags = IORESOURCE_IRQ,
  338. },
  339. {
  340. .name = "DCIN REM",
  341. .start = DA9052_IRQ_DCINREM,
  342. .end = DA9052_IRQ_DCINREM,
  343. .flags = IORESOURCE_IRQ,
  344. },
  345. {
  346. .name = "VBUS DET",
  347. .start = DA9052_IRQ_VBUS,
  348. .end = DA9052_IRQ_VBUS,
  349. .flags = IORESOURCE_IRQ,
  350. },
  351. {
  352. .name = "VBUS REM",
  353. .start = DA9052_IRQ_VBUSREM,
  354. .end = DA9052_IRQ_VBUSREM,
  355. .flags = IORESOURCE_IRQ,
  356. },
  357. {
  358. .name = "CHG END",
  359. .start = DA9052_IRQ_CHGEND,
  360. .end = DA9052_IRQ_CHGEND,
  361. .flags = IORESOURCE_IRQ,
  362. },
  363. };
  364. static struct resource da9052_tsi_resources[] = {
  365. {
  366. .name = "PENDWN",
  367. .start = DA9052_IRQ_PENDOWN,
  368. .end = DA9052_IRQ_PENDOWN,
  369. .flags = IORESOURCE_IRQ,
  370. },
  371. {
  372. .name = "TSIRDY",
  373. .start = DA9052_IRQ_TSIREADY,
  374. .end = DA9052_IRQ_TSIREADY,
  375. .flags = IORESOURCE_IRQ,
  376. },
  377. };
  378. static struct mfd_cell __devinitdata da9052_subdev_info[] = {
  379. {
  380. .name = "da9052-regulator",
  381. .id = 1,
  382. },
  383. {
  384. .name = "da9052-regulator",
  385. .id = 2,
  386. },
  387. {
  388. .name = "da9052-regulator",
  389. .id = 3,
  390. },
  391. {
  392. .name = "da9052-regulator",
  393. .id = 4,
  394. },
  395. {
  396. .name = "da9052-regulator",
  397. .id = 5,
  398. },
  399. {
  400. .name = "da9052-regulator",
  401. .id = 6,
  402. },
  403. {
  404. .name = "da9052-regulator",
  405. .id = 7,
  406. },
  407. {
  408. .name = "da9052-regulator",
  409. .id = 8,
  410. },
  411. {
  412. .name = "da9052-regulator",
  413. .id = 9,
  414. },
  415. {
  416. .name = "da9052-regulator",
  417. .id = 10,
  418. },
  419. {
  420. .name = "da9052-regulator",
  421. .id = 11,
  422. },
  423. {
  424. .name = "da9052-regulator",
  425. .id = 12,
  426. },
  427. {
  428. .name = "da9052-regulator",
  429. .id = 13,
  430. },
  431. {
  432. .name = "da9052-regulator",
  433. .id = 14,
  434. },
  435. {
  436. .name = "da9052-onkey",
  437. .resources = &da9052_onkey_resource,
  438. .num_resources = 1,
  439. },
  440. {
  441. .name = "da9052-rtc",
  442. .resources = &da9052_rtc_resource,
  443. .num_resources = 1,
  444. },
  445. {
  446. .name = "da9052-gpio",
  447. },
  448. {
  449. .name = "da9052-hwmon",
  450. },
  451. {
  452. .name = "da9052-leds",
  453. },
  454. {
  455. .name = "da9052-wled1",
  456. },
  457. {
  458. .name = "da9052-wled2",
  459. },
  460. {
  461. .name = "da9052-wled3",
  462. },
  463. {
  464. .name = "da9052-tsi",
  465. .resources = da9052_tsi_resources,
  466. .num_resources = ARRAY_SIZE(da9052_tsi_resources),
  467. },
  468. {
  469. .name = "da9052-bat",
  470. .resources = da9052_bat_resources,
  471. .num_resources = ARRAY_SIZE(da9052_bat_resources),
  472. },
  473. {
  474. .name = "da9052-watchdog",
  475. },
  476. };
  477. static struct regmap_irq da9052_irqs[] = {
  478. [DA9052_IRQ_DCIN] = {
  479. .reg_offset = 0,
  480. .mask = DA9052_IRQ_MASK_POS_1,
  481. },
  482. [DA9052_IRQ_VBUS] = {
  483. .reg_offset = 0,
  484. .mask = DA9052_IRQ_MASK_POS_2,
  485. },
  486. [DA9052_IRQ_DCINREM] = {
  487. .reg_offset = 0,
  488. .mask = DA9052_IRQ_MASK_POS_3,
  489. },
  490. [DA9052_IRQ_VBUSREM] = {
  491. .reg_offset = 0,
  492. .mask = DA9052_IRQ_MASK_POS_4,
  493. },
  494. [DA9052_IRQ_VDDLOW] = {
  495. .reg_offset = 0,
  496. .mask = DA9052_IRQ_MASK_POS_5,
  497. },
  498. [DA9052_IRQ_ALARM] = {
  499. .reg_offset = 0,
  500. .mask = DA9052_IRQ_MASK_POS_6,
  501. },
  502. [DA9052_IRQ_SEQRDY] = {
  503. .reg_offset = 0,
  504. .mask = DA9052_IRQ_MASK_POS_7,
  505. },
  506. [DA9052_IRQ_COMP1V2] = {
  507. .reg_offset = 0,
  508. .mask = DA9052_IRQ_MASK_POS_8,
  509. },
  510. [DA9052_IRQ_NONKEY] = {
  511. .reg_offset = 1,
  512. .mask = DA9052_IRQ_MASK_POS_1,
  513. },
  514. [DA9052_IRQ_IDFLOAT] = {
  515. .reg_offset = 1,
  516. .mask = DA9052_IRQ_MASK_POS_2,
  517. },
  518. [DA9052_IRQ_IDGND] = {
  519. .reg_offset = 1,
  520. .mask = DA9052_IRQ_MASK_POS_3,
  521. },
  522. [DA9052_IRQ_CHGEND] = {
  523. .reg_offset = 1,
  524. .mask = DA9052_IRQ_MASK_POS_4,
  525. },
  526. [DA9052_IRQ_TBAT] = {
  527. .reg_offset = 1,
  528. .mask = DA9052_IRQ_MASK_POS_5,
  529. },
  530. [DA9052_IRQ_ADC_EOM] = {
  531. .reg_offset = 1,
  532. .mask = DA9052_IRQ_MASK_POS_6,
  533. },
  534. [DA9052_IRQ_PENDOWN] = {
  535. .reg_offset = 1,
  536. .mask = DA9052_IRQ_MASK_POS_7,
  537. },
  538. [DA9052_IRQ_TSIREADY] = {
  539. .reg_offset = 1,
  540. .mask = DA9052_IRQ_MASK_POS_8,
  541. },
  542. [DA9052_IRQ_GPI0] = {
  543. .reg_offset = 2,
  544. .mask = DA9052_IRQ_MASK_POS_1,
  545. },
  546. [DA9052_IRQ_GPI1] = {
  547. .reg_offset = 2,
  548. .mask = DA9052_IRQ_MASK_POS_2,
  549. },
  550. [DA9052_IRQ_GPI2] = {
  551. .reg_offset = 2,
  552. .mask = DA9052_IRQ_MASK_POS_3,
  553. },
  554. [DA9052_IRQ_GPI3] = {
  555. .reg_offset = 2,
  556. .mask = DA9052_IRQ_MASK_POS_4,
  557. },
  558. [DA9052_IRQ_GPI4] = {
  559. .reg_offset = 2,
  560. .mask = DA9052_IRQ_MASK_POS_5,
  561. },
  562. [DA9052_IRQ_GPI5] = {
  563. .reg_offset = 2,
  564. .mask = DA9052_IRQ_MASK_POS_6,
  565. },
  566. [DA9052_IRQ_GPI6] = {
  567. .reg_offset = 2,
  568. .mask = DA9052_IRQ_MASK_POS_7,
  569. },
  570. [DA9052_IRQ_GPI7] = {
  571. .reg_offset = 2,
  572. .mask = DA9052_IRQ_MASK_POS_8,
  573. },
  574. [DA9052_IRQ_GPI8] = {
  575. .reg_offset = 3,
  576. .mask = DA9052_IRQ_MASK_POS_1,
  577. },
  578. [DA9052_IRQ_GPI9] = {
  579. .reg_offset = 3,
  580. .mask = DA9052_IRQ_MASK_POS_2,
  581. },
  582. [DA9052_IRQ_GPI10] = {
  583. .reg_offset = 3,
  584. .mask = DA9052_IRQ_MASK_POS_3,
  585. },
  586. [DA9052_IRQ_GPI11] = {
  587. .reg_offset = 3,
  588. .mask = DA9052_IRQ_MASK_POS_4,
  589. },
  590. [DA9052_IRQ_GPI12] = {
  591. .reg_offset = 3,
  592. .mask = DA9052_IRQ_MASK_POS_5,
  593. },
  594. [DA9052_IRQ_GPI13] = {
  595. .reg_offset = 3,
  596. .mask = DA9052_IRQ_MASK_POS_6,
  597. },
  598. [DA9052_IRQ_GPI14] = {
  599. .reg_offset = 3,
  600. .mask = DA9052_IRQ_MASK_POS_7,
  601. },
  602. [DA9052_IRQ_GPI15] = {
  603. .reg_offset = 3,
  604. .mask = DA9052_IRQ_MASK_POS_8,
  605. },
  606. };
  607. static struct regmap_irq_chip da9052_regmap_irq_chip = {
  608. .name = "da9052_irq",
  609. .status_base = DA9052_EVENT_A_REG,
  610. .mask_base = DA9052_IRQ_MASK_A_REG,
  611. .ack_base = DA9052_EVENT_A_REG,
  612. .num_regs = DA9052_NUM_IRQ_REGS,
  613. .irqs = da9052_irqs,
  614. .num_irqs = ARRAY_SIZE(da9052_irqs),
  615. };
  616. struct regmap_config da9052_regmap_config = {
  617. .reg_bits = 8,
  618. .val_bits = 8,
  619. .cache_type = REGCACHE_RBTREE,
  620. .max_register = DA9052_PAGE1_CON_REG,
  621. .readable_reg = da9052_reg_readable,
  622. .writeable_reg = da9052_reg_writeable,
  623. .volatile_reg = da9052_reg_volatile,
  624. };
  625. EXPORT_SYMBOL_GPL(da9052_regmap_config);
  626. int __devinit da9052_device_init(struct da9052 *da9052, u8 chip_id)
  627. {
  628. struct da9052_pdata *pdata = da9052->dev->platform_data;
  629. struct irq_desc *desc;
  630. int ret;
  631. if (pdata && pdata->init != NULL)
  632. pdata->init(da9052);
  633. da9052->chip_id = chip_id;
  634. if (!pdata || !pdata->irq_base)
  635. da9052->irq_base = -1;
  636. else
  637. da9052->irq_base = pdata->irq_base;
  638. ret = regmap_add_irq_chip(da9052->regmap, da9052->chip_irq,
  639. IRQF_TRIGGER_LOW | IRQF_ONESHOT,
  640. da9052->irq_base, &da9052_regmap_irq_chip,
  641. NULL);
  642. if (ret < 0)
  643. goto regmap_err;
  644. desc = irq_to_desc(da9052->chip_irq);
  645. da9052->irq_base = regmap_irq_chip_get_base(desc->action->dev_id);
  646. ret = mfd_add_devices(da9052->dev, -1, da9052_subdev_info,
  647. ARRAY_SIZE(da9052_subdev_info), NULL, 0);
  648. if (ret)
  649. goto err;
  650. return 0;
  651. err:
  652. mfd_remove_devices(da9052->dev);
  653. regmap_err:
  654. return ret;
  655. }
  656. void da9052_device_exit(struct da9052 *da9052)
  657. {
  658. regmap_del_irq_chip(da9052->chip_irq,
  659. irq_get_irq_data(da9052->irq_base)->chip_data);
  660. mfd_remove_devices(da9052->dev);
  661. }
  662. MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
  663. MODULE_DESCRIPTION("DA9052 MFD Core");
  664. MODULE_LICENSE("GPL");