da9052-core.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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/mfd/core.h>
  18. #include <linux/slab.h>
  19. #include <linux/module.h>
  20. #include <linux/mfd/da9052/da9052.h>
  21. #include <linux/mfd/da9052/pdata.h>
  22. #include <linux/mfd/da9052/reg.h>
  23. static bool da9052_reg_readable(struct device *dev, unsigned int reg)
  24. {
  25. switch (reg) {
  26. case DA9052_PAGE0_CON_REG:
  27. case DA9052_STATUS_A_REG:
  28. case DA9052_STATUS_B_REG:
  29. case DA9052_STATUS_C_REG:
  30. case DA9052_STATUS_D_REG:
  31. case DA9052_EVENT_A_REG:
  32. case DA9052_EVENT_B_REG:
  33. case DA9052_EVENT_C_REG:
  34. case DA9052_EVENT_D_REG:
  35. case DA9052_FAULTLOG_REG:
  36. case DA9052_IRQ_MASK_A_REG:
  37. case DA9052_IRQ_MASK_B_REG:
  38. case DA9052_IRQ_MASK_C_REG:
  39. case DA9052_IRQ_MASK_D_REG:
  40. case DA9052_CONTROL_A_REG:
  41. case DA9052_CONTROL_B_REG:
  42. case DA9052_CONTROL_C_REG:
  43. case DA9052_CONTROL_D_REG:
  44. case DA9052_PDDIS_REG:
  45. case DA9052_INTERFACE_REG:
  46. case DA9052_RESET_REG:
  47. case DA9052_GPIO_0_1_REG:
  48. case DA9052_GPIO_2_3_REG:
  49. case DA9052_GPIO_4_5_REG:
  50. case DA9052_GPIO_6_7_REG:
  51. case DA9052_GPIO_8_9_REG:
  52. case DA9052_GPIO_10_11_REG:
  53. case DA9052_GPIO_12_13_REG:
  54. case DA9052_GPIO_14_15_REG:
  55. case DA9052_ID_0_1_REG:
  56. case DA9052_ID_2_3_REG:
  57. case DA9052_ID_4_5_REG:
  58. case DA9052_ID_6_7_REG:
  59. case DA9052_ID_8_9_REG:
  60. case DA9052_ID_10_11_REG:
  61. case DA9052_ID_12_13_REG:
  62. case DA9052_ID_14_15_REG:
  63. case DA9052_ID_16_17_REG:
  64. case DA9052_ID_18_19_REG:
  65. case DA9052_ID_20_21_REG:
  66. case DA9052_SEQ_STATUS_REG:
  67. case DA9052_SEQ_A_REG:
  68. case DA9052_SEQ_B_REG:
  69. case DA9052_SEQ_TIMER_REG:
  70. case DA9052_BUCKA_REG:
  71. case DA9052_BUCKB_REG:
  72. case DA9052_BUCKCORE_REG:
  73. case DA9052_BUCKPRO_REG:
  74. case DA9052_BUCKMEM_REG:
  75. case DA9052_BUCKPERI_REG:
  76. case DA9052_LDO1_REG:
  77. case DA9052_LDO2_REG:
  78. case DA9052_LDO3_REG:
  79. case DA9052_LDO4_REG:
  80. case DA9052_LDO5_REG:
  81. case DA9052_LDO6_REG:
  82. case DA9052_LDO7_REG:
  83. case DA9052_LDO8_REG:
  84. case DA9052_LDO9_REG:
  85. case DA9052_LDO10_REG:
  86. case DA9052_SUPPLY_REG:
  87. case DA9052_PULLDOWN_REG:
  88. case DA9052_CHGBUCK_REG:
  89. case DA9052_WAITCONT_REG:
  90. case DA9052_ISET_REG:
  91. case DA9052_BATCHG_REG:
  92. case DA9052_CHG_CONT_REG:
  93. case DA9052_INPUT_CONT_REG:
  94. case DA9052_CHG_TIME_REG:
  95. case DA9052_BBAT_CONT_REG:
  96. case DA9052_BOOST_REG:
  97. case DA9052_LED_CONT_REG:
  98. case DA9052_LEDMIN123_REG:
  99. case DA9052_LED1_CONF_REG:
  100. case DA9052_LED2_CONF_REG:
  101. case DA9052_LED3_CONF_REG:
  102. case DA9052_LED1CONT_REG:
  103. case DA9052_LED2CONT_REG:
  104. case DA9052_LED3CONT_REG:
  105. case DA9052_LED_CONT_4_REG:
  106. case DA9052_LED_CONT_5_REG:
  107. case DA9052_ADC_MAN_REG:
  108. case DA9052_ADC_CONT_REG:
  109. case DA9052_ADC_RES_L_REG:
  110. case DA9052_ADC_RES_H_REG:
  111. case DA9052_VDD_RES_REG:
  112. case DA9052_VDD_MON_REG:
  113. case DA9052_ICHG_AV_REG:
  114. case DA9052_ICHG_THD_REG:
  115. case DA9052_ICHG_END_REG:
  116. case DA9052_TBAT_RES_REG:
  117. case DA9052_TBAT_HIGHP_REG:
  118. case DA9052_TBAT_HIGHN_REG:
  119. case DA9052_TBAT_LOW_REG:
  120. case DA9052_T_OFFSET_REG:
  121. case DA9052_ADCIN4_RES_REG:
  122. case DA9052_AUTO4_HIGH_REG:
  123. case DA9052_AUTO4_LOW_REG:
  124. case DA9052_ADCIN5_RES_REG:
  125. case DA9052_AUTO5_HIGH_REG:
  126. case DA9052_AUTO5_LOW_REG:
  127. case DA9052_ADCIN6_RES_REG:
  128. case DA9052_AUTO6_HIGH_REG:
  129. case DA9052_AUTO6_LOW_REG:
  130. case DA9052_TJUNC_RES_REG:
  131. case DA9052_TSI_CONT_A_REG:
  132. case DA9052_TSI_CONT_B_REG:
  133. case DA9052_TSI_X_MSB_REG:
  134. case DA9052_TSI_Y_MSB_REG:
  135. case DA9052_TSI_LSB_REG:
  136. case DA9052_TSI_Z_MSB_REG:
  137. case DA9052_COUNT_S_REG:
  138. case DA9052_COUNT_MI_REG:
  139. case DA9052_COUNT_H_REG:
  140. case DA9052_COUNT_D_REG:
  141. case DA9052_COUNT_MO_REG:
  142. case DA9052_COUNT_Y_REG:
  143. case DA9052_ALARM_MI_REG:
  144. case DA9052_ALARM_H_REG:
  145. case DA9052_ALARM_D_REG:
  146. case DA9052_ALARM_MO_REG:
  147. case DA9052_ALARM_Y_REG:
  148. case DA9052_SECOND_A_REG:
  149. case DA9052_SECOND_B_REG:
  150. case DA9052_SECOND_C_REG:
  151. case DA9052_SECOND_D_REG:
  152. case DA9052_PAGE1_CON_REG:
  153. return true;
  154. default:
  155. return false;
  156. }
  157. }
  158. static bool da9052_reg_writeable(struct device *dev, unsigned int reg)
  159. {
  160. switch (reg) {
  161. case DA9052_PAGE0_CON_REG:
  162. case DA9052_EVENT_A_REG:
  163. case DA9052_EVENT_B_REG:
  164. case DA9052_EVENT_C_REG:
  165. case DA9052_EVENT_D_REG:
  166. case DA9052_FAULTLOG_REG:
  167. case DA9052_IRQ_MASK_A_REG:
  168. case DA9052_IRQ_MASK_B_REG:
  169. case DA9052_IRQ_MASK_C_REG:
  170. case DA9052_IRQ_MASK_D_REG:
  171. case DA9052_CONTROL_A_REG:
  172. case DA9052_CONTROL_B_REG:
  173. case DA9052_CONTROL_C_REG:
  174. case DA9052_CONTROL_D_REG:
  175. case DA9052_PDDIS_REG:
  176. case DA9052_RESET_REG:
  177. case DA9052_GPIO_0_1_REG:
  178. case DA9052_GPIO_2_3_REG:
  179. case DA9052_GPIO_4_5_REG:
  180. case DA9052_GPIO_6_7_REG:
  181. case DA9052_GPIO_8_9_REG:
  182. case DA9052_GPIO_10_11_REG:
  183. case DA9052_GPIO_12_13_REG:
  184. case DA9052_GPIO_14_15_REG:
  185. case DA9052_ID_0_1_REG:
  186. case DA9052_ID_2_3_REG:
  187. case DA9052_ID_4_5_REG:
  188. case DA9052_ID_6_7_REG:
  189. case DA9052_ID_8_9_REG:
  190. case DA9052_ID_10_11_REG:
  191. case DA9052_ID_12_13_REG:
  192. case DA9052_ID_14_15_REG:
  193. case DA9052_ID_16_17_REG:
  194. case DA9052_ID_18_19_REG:
  195. case DA9052_ID_20_21_REG:
  196. case DA9052_SEQ_STATUS_REG:
  197. case DA9052_SEQ_A_REG:
  198. case DA9052_SEQ_B_REG:
  199. case DA9052_SEQ_TIMER_REG:
  200. case DA9052_BUCKA_REG:
  201. case DA9052_BUCKB_REG:
  202. case DA9052_BUCKCORE_REG:
  203. case DA9052_BUCKPRO_REG:
  204. case DA9052_BUCKMEM_REG:
  205. case DA9052_BUCKPERI_REG:
  206. case DA9052_LDO1_REG:
  207. case DA9052_LDO2_REG:
  208. case DA9052_LDO3_REG:
  209. case DA9052_LDO4_REG:
  210. case DA9052_LDO5_REG:
  211. case DA9052_LDO6_REG:
  212. case DA9052_LDO7_REG:
  213. case DA9052_LDO8_REG:
  214. case DA9052_LDO9_REG:
  215. case DA9052_LDO10_REG:
  216. case DA9052_SUPPLY_REG:
  217. case DA9052_PULLDOWN_REG:
  218. case DA9052_CHGBUCK_REG:
  219. case DA9052_WAITCONT_REG:
  220. case DA9052_ISET_REG:
  221. case DA9052_BATCHG_REG:
  222. case DA9052_CHG_CONT_REG:
  223. case DA9052_INPUT_CONT_REG:
  224. case DA9052_BBAT_CONT_REG:
  225. case DA9052_BOOST_REG:
  226. case DA9052_LED_CONT_REG:
  227. case DA9052_LEDMIN123_REG:
  228. case DA9052_LED1_CONF_REG:
  229. case DA9052_LED2_CONF_REG:
  230. case DA9052_LED3_CONF_REG:
  231. case DA9052_LED1CONT_REG:
  232. case DA9052_LED2CONT_REG:
  233. case DA9052_LED3CONT_REG:
  234. case DA9052_LED_CONT_4_REG:
  235. case DA9052_LED_CONT_5_REG:
  236. case DA9052_ADC_MAN_REG:
  237. case DA9052_ADC_CONT_REG:
  238. case DA9052_ADC_RES_L_REG:
  239. case DA9052_ADC_RES_H_REG:
  240. case DA9052_VDD_RES_REG:
  241. case DA9052_VDD_MON_REG:
  242. case DA9052_ICHG_THD_REG:
  243. case DA9052_ICHG_END_REG:
  244. case DA9052_TBAT_HIGHP_REG:
  245. case DA9052_TBAT_HIGHN_REG:
  246. case DA9052_TBAT_LOW_REG:
  247. case DA9052_T_OFFSET_REG:
  248. case DA9052_AUTO4_HIGH_REG:
  249. case DA9052_AUTO4_LOW_REG:
  250. case DA9052_AUTO5_HIGH_REG:
  251. case DA9052_AUTO5_LOW_REG:
  252. case DA9052_AUTO6_HIGH_REG:
  253. case DA9052_AUTO6_LOW_REG:
  254. case DA9052_TSI_CONT_A_REG:
  255. case DA9052_TSI_CONT_B_REG:
  256. case DA9052_COUNT_S_REG:
  257. case DA9052_COUNT_MI_REG:
  258. case DA9052_COUNT_H_REG:
  259. case DA9052_COUNT_D_REG:
  260. case DA9052_COUNT_MO_REG:
  261. case DA9052_COUNT_Y_REG:
  262. case DA9052_ALARM_MI_REG:
  263. case DA9052_ALARM_H_REG:
  264. case DA9052_ALARM_D_REG:
  265. case DA9052_ALARM_MO_REG:
  266. case DA9052_ALARM_Y_REG:
  267. case DA9052_PAGE1_CON_REG:
  268. return true;
  269. default:
  270. return false;
  271. }
  272. }
  273. static bool da9052_reg_volatile(struct device *dev, unsigned int reg)
  274. {
  275. switch (reg) {
  276. case DA9052_STATUS_A_REG:
  277. case DA9052_STATUS_B_REG:
  278. case DA9052_STATUS_C_REG:
  279. case DA9052_STATUS_D_REG:
  280. case DA9052_EVENT_A_REG:
  281. case DA9052_EVENT_B_REG:
  282. case DA9052_EVENT_C_REG:
  283. case DA9052_EVENT_D_REG:
  284. case DA9052_CONTROL_B_REG:
  285. case DA9052_CONTROL_D_REG:
  286. case DA9052_SUPPLY_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. /*
  315. * TBAT look-up table is computed from the R90 reg (8 bit register)
  316. * reading as below. The battery temperature is in milliCentigrade
  317. * TBAT = (1/(t1+1/298) - 273) * 1000 mC
  318. * where t1 = (1/B)* ln(( ADCval * 2.5)/(R25*ITBAT*255))
  319. * Default values are R25 = 10e3, B = 3380, ITBAT = 50e-6
  320. * Example:
  321. * R25=10E3, B=3380, ITBAT=50e-6, ADCVAL=62d calculates
  322. * TBAT = 20015 mili degrees Centrigrade
  323. *
  324. */
  325. static const int32_t tbat_lookup[255] = {
  326. 183258, 144221, 124334, 111336, 101826, 94397, 88343, 83257,
  327. 78889, 75071, 71688, 68656, 65914, 63414, 61120, 59001,
  328. 570366, 55204, 53490, 51881, 50364, 48931, 47574, 46285,
  329. 45059, 43889, 42772, 41703, 40678, 39694, 38748, 37838,
  330. 36961, 36115, 35297, 34507, 33743, 33002, 32284, 31588,
  331. 30911, 30254, 29615, 28994, 28389, 27799, 27225, 26664,
  332. 26117, 25584, 25062, 24553, 24054, 23567, 23091, 22624,
  333. 22167, 21719, 21281, 20851, 20429, 20015, 19610, 19211,
  334. 18820, 18436, 18058, 17688, 17323, 16965, 16612, 16266,
  335. 15925, 15589, 15259, 14933, 14613, 14298, 13987, 13681,
  336. 13379, 13082, 12788, 12499, 12214, 11933, 11655, 11382,
  337. 11112, 10845, 10582, 10322, 10066, 9812, 9562, 9315,
  338. 9071, 8830, 8591, 8356, 8123, 7893, 7665, 7440,
  339. 7218, 6998, 6780, 6565, 6352, 6141, 5933, 5726,
  340. 5522, 5320, 5120, 4922, 4726, 4532, 4340, 4149,
  341. 3961, 3774, 3589, 3406, 3225, 3045, 2867, 2690,
  342. 2516, 2342, 2170, 2000, 1831, 1664, 1498, 1334,
  343. 1171, 1009, 849, 690, 532, 376, 221, 67,
  344. -84, -236, -386, -535, -683, -830, -975, -1119,
  345. -1263, -1405, -1546, -1686, -1825, -1964, -2101, -2237,
  346. -2372, -2506, -2639, -2771, -2902, -3033, -3162, -3291,
  347. -3418, -3545, -3671, -3796, -3920, -4044, -4166, -4288,
  348. -4409, -4529, -4649, -4767, -4885, -5002, -5119, -5235,
  349. -5349, -5464, -5577, -5690, -5802, -5913, -6024, -6134,
  350. -6244, -6352, -6461, -6568, -6675, -6781, -6887, -6992,
  351. -7096, -7200, -7303, -7406, -7508, -7609, -7710, -7810,
  352. -7910, -8009, -8108, -8206, -8304, -8401, -8497, -8593,
  353. -8689, -8784, -8878, -8972, -9066, -9159, -9251, -9343,
  354. -9435, -9526, -9617, -9707, -9796, -9886, -9975, -10063,
  355. -10151, -10238, -10325, -10412, -10839, -10923, -11007, -11090,
  356. -11173, -11256, -11338, -11420, -11501, -11583, -11663, -11744,
  357. -11823, -11903, -11982
  358. };
  359. static const u8 chan_mux[DA9052_ADC_VBBAT + 1] = {
  360. [DA9052_ADC_VDDOUT] = DA9052_ADC_MAN_MUXSEL_VDDOUT,
  361. [DA9052_ADC_ICH] = DA9052_ADC_MAN_MUXSEL_ICH,
  362. [DA9052_ADC_TBAT] = DA9052_ADC_MAN_MUXSEL_TBAT,
  363. [DA9052_ADC_VBAT] = DA9052_ADC_MAN_MUXSEL_VBAT,
  364. [DA9052_ADC_IN4] = DA9052_ADC_MAN_MUXSEL_AD4,
  365. [DA9052_ADC_IN5] = DA9052_ADC_MAN_MUXSEL_AD5,
  366. [DA9052_ADC_IN6] = DA9052_ADC_MAN_MUXSEL_AD6,
  367. [DA9052_ADC_VBBAT] = DA9052_ADC_MAN_MUXSEL_VBBAT
  368. };
  369. int da9052_adc_manual_read(struct da9052 *da9052, unsigned char channel)
  370. {
  371. int ret;
  372. unsigned short calc_data;
  373. unsigned short data;
  374. unsigned char mux_sel;
  375. if (channel > DA9052_ADC_VBBAT)
  376. return -EINVAL;
  377. mutex_lock(&da9052->auxadc_lock);
  378. /* Channel gets activated on enabling the Conversion bit */
  379. mux_sel = chan_mux[channel] | DA9052_ADC_MAN_MAN_CONV;
  380. ret = da9052_reg_write(da9052, DA9052_ADC_MAN_REG, mux_sel);
  381. if (ret < 0)
  382. goto err;
  383. /* Wait for an interrupt */
  384. if (!wait_for_completion_timeout(&da9052->done,
  385. msecs_to_jiffies(500))) {
  386. dev_err(da9052->dev,
  387. "timeout waiting for ADC conversion interrupt\n");
  388. ret = -ETIMEDOUT;
  389. goto err;
  390. }
  391. ret = da9052_reg_read(da9052, DA9052_ADC_RES_H_REG);
  392. if (ret < 0)
  393. goto err;
  394. calc_data = (unsigned short)ret;
  395. data = calc_data << 2;
  396. ret = da9052_reg_read(da9052, DA9052_ADC_RES_L_REG);
  397. if (ret < 0)
  398. goto err;
  399. calc_data = (unsigned short)(ret & DA9052_ADC_RES_LSB);
  400. data |= calc_data;
  401. ret = data;
  402. err:
  403. mutex_unlock(&da9052->auxadc_lock);
  404. return ret;
  405. }
  406. EXPORT_SYMBOL_GPL(da9052_adc_manual_read);
  407. int da9052_adc_read_temp(struct da9052 *da9052)
  408. {
  409. int tbat;
  410. tbat = da9052_reg_read(da9052, DA9052_TBAT_RES_REG);
  411. if (tbat <= 0)
  412. return tbat;
  413. /* ARRAY_SIZE check is not needed since TBAT is a 8-bit register */
  414. return tbat_lookup[tbat - 1];
  415. }
  416. EXPORT_SYMBOL_GPL(da9052_adc_read_temp);
  417. static const struct mfd_cell da9052_subdev_info[] = {
  418. {
  419. .name = "da9052-regulator",
  420. .id = 0,
  421. },
  422. {
  423. .name = "da9052-regulator",
  424. .id = 1,
  425. },
  426. {
  427. .name = "da9052-regulator",
  428. .id = 2,
  429. },
  430. {
  431. .name = "da9052-regulator",
  432. .id = 3,
  433. },
  434. {
  435. .name = "da9052-regulator",
  436. .id = 4,
  437. },
  438. {
  439. .name = "da9052-regulator",
  440. .id = 5,
  441. },
  442. {
  443. .name = "da9052-regulator",
  444. .id = 6,
  445. },
  446. {
  447. .name = "da9052-regulator",
  448. .id = 7,
  449. },
  450. {
  451. .name = "da9052-regulator",
  452. .id = 8,
  453. },
  454. {
  455. .name = "da9052-regulator",
  456. .id = 9,
  457. },
  458. {
  459. .name = "da9052-regulator",
  460. .id = 10,
  461. },
  462. {
  463. .name = "da9052-regulator",
  464. .id = 11,
  465. },
  466. {
  467. .name = "da9052-regulator",
  468. .id = 12,
  469. },
  470. {
  471. .name = "da9052-regulator",
  472. .id = 13,
  473. },
  474. {
  475. .name = "da9052-onkey",
  476. },
  477. {
  478. .name = "da9052-rtc",
  479. },
  480. {
  481. .name = "da9052-gpio",
  482. },
  483. {
  484. .name = "da9052-hwmon",
  485. },
  486. {
  487. .name = "da9052-leds",
  488. },
  489. {
  490. .name = "da9052-wled1",
  491. },
  492. {
  493. .name = "da9052-wled2",
  494. },
  495. {
  496. .name = "da9052-wled3",
  497. },
  498. {
  499. .name = "da9052-tsi",
  500. },
  501. {
  502. .name = "da9052-bat",
  503. },
  504. {
  505. .name = "da9052-watchdog",
  506. },
  507. };
  508. const struct regmap_config da9052_regmap_config = {
  509. .reg_bits = 8,
  510. .val_bits = 8,
  511. .cache_type = REGCACHE_RBTREE,
  512. .max_register = DA9052_PAGE1_CON_REG,
  513. .readable_reg = da9052_reg_readable,
  514. .writeable_reg = da9052_reg_writeable,
  515. .volatile_reg = da9052_reg_volatile,
  516. };
  517. EXPORT_SYMBOL_GPL(da9052_regmap_config);
  518. static int da9052_clear_fault_log(struct da9052 *da9052)
  519. {
  520. int ret = 0;
  521. int fault_log = 0;
  522. fault_log = da9052_reg_read(da9052, DA9052_FAULTLOG_REG);
  523. if (fault_log < 0) {
  524. dev_err(da9052->dev,
  525. "Cannot read FAULT_LOG %d\n", fault_log);
  526. return fault_log;
  527. }
  528. if (fault_log) {
  529. if (fault_log & DA9052_FAULTLOG_TWDERROR)
  530. dev_dbg(da9052->dev,
  531. "Fault log entry detected: TWD_ERROR\n");
  532. if (fault_log & DA9052_FAULTLOG_VDDFAULT)
  533. dev_dbg(da9052->dev,
  534. "Fault log entry detected: VDD_FAULT\n");
  535. if (fault_log & DA9052_FAULTLOG_VDDSTART)
  536. dev_dbg(da9052->dev,
  537. "Fault log entry detected: VDD_START\n");
  538. if (fault_log & DA9052_FAULTLOG_TEMPOVER)
  539. dev_dbg(da9052->dev,
  540. "Fault log entry detected: TEMP_OVER\n");
  541. if (fault_log & DA9052_FAULTLOG_KEYSHUT)
  542. dev_dbg(da9052->dev,
  543. "Fault log entry detected: KEY_SHUT\n");
  544. if (fault_log & DA9052_FAULTLOG_NSDSET)
  545. dev_dbg(da9052->dev,
  546. "Fault log entry detected: nSD_SHUT\n");
  547. if (fault_log & DA9052_FAULTLOG_WAITSET)
  548. dev_dbg(da9052->dev,
  549. "Fault log entry detected: WAIT_SHUT\n");
  550. ret = da9052_reg_write(da9052,
  551. DA9052_FAULTLOG_REG,
  552. 0xFF);
  553. if (ret < 0)
  554. dev_err(da9052->dev,
  555. "Cannot reset FAULT_LOG values %d\n", ret);
  556. }
  557. return ret;
  558. }
  559. int da9052_device_init(struct da9052 *da9052, u8 chip_id)
  560. {
  561. struct da9052_pdata *pdata = dev_get_platdata(da9052->dev);
  562. int ret;
  563. mutex_init(&da9052->auxadc_lock);
  564. init_completion(&da9052->done);
  565. ret = da9052_clear_fault_log(da9052);
  566. if (ret < 0)
  567. dev_warn(da9052->dev, "Cannot clear FAULT_LOG\n");
  568. if (pdata && pdata->init != NULL)
  569. pdata->init(da9052);
  570. da9052->chip_id = chip_id;
  571. ret = da9052_irq_init(da9052);
  572. if (ret != 0) {
  573. dev_err(da9052->dev, "da9052_irq_init failed: %d\n", ret);
  574. return ret;
  575. }
  576. ret = mfd_add_devices(da9052->dev, PLATFORM_DEVID_AUTO,
  577. da9052_subdev_info,
  578. ARRAY_SIZE(da9052_subdev_info), NULL, 0, NULL);
  579. if (ret) {
  580. dev_err(da9052->dev, "mfd_add_devices failed: %d\n", ret);
  581. goto err;
  582. }
  583. return 0;
  584. err:
  585. da9052_irq_exit(da9052);
  586. return ret;
  587. }
  588. void da9052_device_exit(struct da9052 *da9052)
  589. {
  590. mfd_remove_devices(da9052->dev);
  591. da9052_irq_exit(da9052);
  592. }
  593. MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
  594. MODULE_DESCRIPTION("DA9052 MFD Core");
  595. MODULE_LICENSE("GPL");