ab8500-core.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2010
  3. *
  4. * License Terms: GNU General Public License v2
  5. * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
  6. * Author: Rabin Vincent <rabin.vincent@stericsson.com>
  7. * Author: Mattias Wallin <mattias.wallin@stericsson.com>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/slab.h>
  11. #include <linux/init.h>
  12. #include <linux/irq.h>
  13. #include <linux/delay.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/module.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/mfd/core.h>
  18. #include <linux/mfd/abx500.h>
  19. #include <linux/mfd/ab8500.h>
  20. #include <linux/regulator/ab8500.h>
  21. /*
  22. * Interrupt register offsets
  23. * Bank : 0x0E
  24. */
  25. #define AB8500_IT_SOURCE1_REG 0x00
  26. #define AB8500_IT_SOURCE2_REG 0x01
  27. #define AB8500_IT_SOURCE3_REG 0x02
  28. #define AB8500_IT_SOURCE4_REG 0x03
  29. #define AB8500_IT_SOURCE5_REG 0x04
  30. #define AB8500_IT_SOURCE6_REG 0x05
  31. #define AB8500_IT_SOURCE7_REG 0x06
  32. #define AB8500_IT_SOURCE8_REG 0x07
  33. #define AB8500_IT_SOURCE19_REG 0x12
  34. #define AB8500_IT_SOURCE20_REG 0x13
  35. #define AB8500_IT_SOURCE21_REG 0x14
  36. #define AB8500_IT_SOURCE22_REG 0x15
  37. #define AB8500_IT_SOURCE23_REG 0x16
  38. #define AB8500_IT_SOURCE24_REG 0x17
  39. /*
  40. * latch registers
  41. */
  42. #define AB8500_IT_LATCH1_REG 0x20
  43. #define AB8500_IT_LATCH2_REG 0x21
  44. #define AB8500_IT_LATCH3_REG 0x22
  45. #define AB8500_IT_LATCH4_REG 0x23
  46. #define AB8500_IT_LATCH5_REG 0x24
  47. #define AB8500_IT_LATCH6_REG 0x25
  48. #define AB8500_IT_LATCH7_REG 0x26
  49. #define AB8500_IT_LATCH8_REG 0x27
  50. #define AB8500_IT_LATCH9_REG 0x28
  51. #define AB8500_IT_LATCH10_REG 0x29
  52. #define AB8500_IT_LATCH12_REG 0x2B
  53. #define AB8500_IT_LATCH19_REG 0x32
  54. #define AB8500_IT_LATCH20_REG 0x33
  55. #define AB8500_IT_LATCH21_REG 0x34
  56. #define AB8500_IT_LATCH22_REG 0x35
  57. #define AB8500_IT_LATCH23_REG 0x36
  58. #define AB8500_IT_LATCH24_REG 0x37
  59. /*
  60. * mask registers
  61. */
  62. #define AB8500_IT_MASK1_REG 0x40
  63. #define AB8500_IT_MASK2_REG 0x41
  64. #define AB8500_IT_MASK3_REG 0x42
  65. #define AB8500_IT_MASK4_REG 0x43
  66. #define AB8500_IT_MASK5_REG 0x44
  67. #define AB8500_IT_MASK6_REG 0x45
  68. #define AB8500_IT_MASK7_REG 0x46
  69. #define AB8500_IT_MASK8_REG 0x47
  70. #define AB8500_IT_MASK9_REG 0x48
  71. #define AB8500_IT_MASK10_REG 0x49
  72. #define AB8500_IT_MASK11_REG 0x4A
  73. #define AB8500_IT_MASK12_REG 0x4B
  74. #define AB8500_IT_MASK13_REG 0x4C
  75. #define AB8500_IT_MASK14_REG 0x4D
  76. #define AB8500_IT_MASK15_REG 0x4E
  77. #define AB8500_IT_MASK16_REG 0x4F
  78. #define AB8500_IT_MASK17_REG 0x50
  79. #define AB8500_IT_MASK18_REG 0x51
  80. #define AB8500_IT_MASK19_REG 0x52
  81. #define AB8500_IT_MASK20_REG 0x53
  82. #define AB8500_IT_MASK21_REG 0x54
  83. #define AB8500_IT_MASK22_REG 0x55
  84. #define AB8500_IT_MASK23_REG 0x56
  85. #define AB8500_IT_MASK24_REG 0x57
  86. #define AB8500_REV_REG 0x80
  87. #define AB8500_SWITCH_OFF_STATUS 0x00
  88. /*
  89. * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
  90. * numbers are indexed into this array with (num / 8).
  91. *
  92. * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at
  93. * offset 0.
  94. */
  95. static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
  96. 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
  97. };
  98. static int ab8500_get_chip_id(struct device *dev)
  99. {
  100. struct ab8500 *ab8500;
  101. if (!dev)
  102. return -EINVAL;
  103. ab8500 = dev_get_drvdata(dev->parent);
  104. return ab8500 ? (int)ab8500->chip_id : -EINVAL;
  105. }
  106. static int set_register_interruptible(struct ab8500 *ab8500, u8 bank,
  107. u8 reg, u8 data)
  108. {
  109. int ret;
  110. /*
  111. * Put the u8 bank and u8 register together into a an u16.
  112. * The bank on higher 8 bits and register in lower 8 bits.
  113. * */
  114. u16 addr = ((u16)bank) << 8 | reg;
  115. dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data);
  116. ret = mutex_lock_interruptible(&ab8500->lock);
  117. if (ret)
  118. return ret;
  119. ret = ab8500->write(ab8500, addr, data);
  120. if (ret < 0)
  121. dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
  122. addr, ret);
  123. mutex_unlock(&ab8500->lock);
  124. return ret;
  125. }
  126. static int ab8500_set_register(struct device *dev, u8 bank,
  127. u8 reg, u8 value)
  128. {
  129. struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
  130. return set_register_interruptible(ab8500, bank, reg, value);
  131. }
  132. static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
  133. u8 reg, u8 *value)
  134. {
  135. int ret;
  136. /* put the u8 bank and u8 reg together into a an u16.
  137. * bank on higher 8 bits and reg in lower */
  138. u16 addr = ((u16)bank) << 8 | reg;
  139. ret = mutex_lock_interruptible(&ab8500->lock);
  140. if (ret)
  141. return ret;
  142. ret = ab8500->read(ab8500, addr);
  143. if (ret < 0)
  144. dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
  145. addr, ret);
  146. else
  147. *value = ret;
  148. mutex_unlock(&ab8500->lock);
  149. dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
  150. return ret;
  151. }
  152. static int ab8500_get_register(struct device *dev, u8 bank,
  153. u8 reg, u8 *value)
  154. {
  155. struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
  156. return get_register_interruptible(ab8500, bank, reg, value);
  157. }
  158. static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank,
  159. u8 reg, u8 bitmask, u8 bitvalues)
  160. {
  161. int ret;
  162. u8 data;
  163. /* put the u8 bank and u8 reg together into a an u16.
  164. * bank on higher 8 bits and reg in lower */
  165. u16 addr = ((u16)bank) << 8 | reg;
  166. ret = mutex_lock_interruptible(&ab8500->lock);
  167. if (ret)
  168. return ret;
  169. ret = ab8500->read(ab8500, addr);
  170. if (ret < 0) {
  171. dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
  172. addr, ret);
  173. goto out;
  174. }
  175. data = (u8)ret;
  176. data = (~bitmask & data) | (bitmask & bitvalues);
  177. ret = ab8500->write(ab8500, addr, data);
  178. if (ret < 0)
  179. dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
  180. addr, ret);
  181. dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr, data);
  182. out:
  183. mutex_unlock(&ab8500->lock);
  184. return ret;
  185. }
  186. static int ab8500_mask_and_set_register(struct device *dev,
  187. u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
  188. {
  189. struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
  190. return mask_and_set_register_interruptible(ab8500, bank, reg,
  191. bitmask, bitvalues);
  192. }
  193. static struct abx500_ops ab8500_ops = {
  194. .get_chip_id = ab8500_get_chip_id,
  195. .get_register = ab8500_get_register,
  196. .set_register = ab8500_set_register,
  197. .get_register_page = NULL,
  198. .set_register_page = NULL,
  199. .mask_and_set_register = ab8500_mask_and_set_register,
  200. .event_registers_startup_state_get = NULL,
  201. .startup_irq_enabled = NULL,
  202. };
  203. static void ab8500_irq_lock(struct irq_data *data)
  204. {
  205. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  206. mutex_lock(&ab8500->irq_lock);
  207. }
  208. static void ab8500_irq_sync_unlock(struct irq_data *data)
  209. {
  210. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  211. int i;
  212. for (i = 0; i < AB8500_NUM_IRQ_REGS; i++) {
  213. u8 old = ab8500->oldmask[i];
  214. u8 new = ab8500->mask[i];
  215. int reg;
  216. if (new == old)
  217. continue;
  218. /* Interrupt register 12 doesn't exist prior to version 2.0 */
  219. if (ab8500_irq_regoffset[i] == 11 &&
  220. ab8500->chip_id < AB8500_CUT2P0)
  221. continue;
  222. ab8500->oldmask[i] = new;
  223. reg = AB8500_IT_MASK1_REG + ab8500_irq_regoffset[i];
  224. set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new);
  225. }
  226. mutex_unlock(&ab8500->irq_lock);
  227. }
  228. static void ab8500_irq_mask(struct irq_data *data)
  229. {
  230. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  231. int offset = data->irq - ab8500->irq_base;
  232. int index = offset / 8;
  233. int mask = 1 << (offset % 8);
  234. ab8500->mask[index] |= mask;
  235. }
  236. static void ab8500_irq_unmask(struct irq_data *data)
  237. {
  238. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  239. int offset = data->irq - ab8500->irq_base;
  240. int index = offset / 8;
  241. int mask = 1 << (offset % 8);
  242. ab8500->mask[index] &= ~mask;
  243. }
  244. static struct irq_chip ab8500_irq_chip = {
  245. .name = "ab8500",
  246. .irq_bus_lock = ab8500_irq_lock,
  247. .irq_bus_sync_unlock = ab8500_irq_sync_unlock,
  248. .irq_mask = ab8500_irq_mask,
  249. .irq_disable = ab8500_irq_mask,
  250. .irq_unmask = ab8500_irq_unmask,
  251. };
  252. static irqreturn_t ab8500_irq(int irq, void *dev)
  253. {
  254. struct ab8500 *ab8500 = dev;
  255. int i;
  256. dev_vdbg(ab8500->dev, "interrupt\n");
  257. for (i = 0; i < AB8500_NUM_IRQ_REGS; i++) {
  258. int regoffset = ab8500_irq_regoffset[i];
  259. int status;
  260. u8 value;
  261. /* Interrupt register 12 doesn't exist prior to version 2.0 */
  262. if (regoffset == 11 && ab8500->chip_id < AB8500_CUT2P0)
  263. continue;
  264. status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
  265. AB8500_IT_LATCH1_REG + regoffset, &value);
  266. if (status < 0 || value == 0)
  267. continue;
  268. do {
  269. int bit = __ffs(value);
  270. int line = i * 8 + bit;
  271. handle_nested_irq(ab8500->irq_base + line);
  272. value &= ~(1 << bit);
  273. } while (value);
  274. }
  275. return IRQ_HANDLED;
  276. }
  277. static int ab8500_irq_init(struct ab8500 *ab8500)
  278. {
  279. int base = ab8500->irq_base;
  280. int irq;
  281. for (irq = base; irq < base + AB8500_NR_IRQS; irq++) {
  282. irq_set_chip_data(irq, ab8500);
  283. irq_set_chip_and_handler(irq, &ab8500_irq_chip,
  284. handle_simple_irq);
  285. irq_set_nested_thread(irq, 1);
  286. #ifdef CONFIG_ARM
  287. set_irq_flags(irq, IRQF_VALID);
  288. #else
  289. irq_set_noprobe(irq);
  290. #endif
  291. }
  292. return 0;
  293. }
  294. static void ab8500_irq_remove(struct ab8500 *ab8500)
  295. {
  296. int base = ab8500->irq_base;
  297. int irq;
  298. for (irq = base; irq < base + AB8500_NR_IRQS; irq++) {
  299. #ifdef CONFIG_ARM
  300. set_irq_flags(irq, 0);
  301. #endif
  302. irq_set_chip_and_handler(irq, NULL, NULL);
  303. irq_set_chip_data(irq, NULL);
  304. }
  305. }
  306. static struct resource __devinitdata ab8500_gpio_resources[] = {
  307. {
  308. .name = "GPIO_INT6",
  309. .start = AB8500_INT_GPIO6R,
  310. .end = AB8500_INT_GPIO41F,
  311. .flags = IORESOURCE_IRQ,
  312. }
  313. };
  314. static struct resource __devinitdata ab8500_gpadc_resources[] = {
  315. {
  316. .name = "HW_CONV_END",
  317. .start = AB8500_INT_GP_HW_ADC_CONV_END,
  318. .end = AB8500_INT_GP_HW_ADC_CONV_END,
  319. .flags = IORESOURCE_IRQ,
  320. },
  321. {
  322. .name = "SW_CONV_END",
  323. .start = AB8500_INT_GP_SW_ADC_CONV_END,
  324. .end = AB8500_INT_GP_SW_ADC_CONV_END,
  325. .flags = IORESOURCE_IRQ,
  326. },
  327. };
  328. static struct resource __devinitdata ab8500_rtc_resources[] = {
  329. {
  330. .name = "60S",
  331. .start = AB8500_INT_RTC_60S,
  332. .end = AB8500_INT_RTC_60S,
  333. .flags = IORESOURCE_IRQ,
  334. },
  335. {
  336. .name = "ALARM",
  337. .start = AB8500_INT_RTC_ALARM,
  338. .end = AB8500_INT_RTC_ALARM,
  339. .flags = IORESOURCE_IRQ,
  340. },
  341. };
  342. static struct resource __devinitdata ab8500_poweronkey_db_resources[] = {
  343. {
  344. .name = "ONKEY_DBF",
  345. .start = AB8500_INT_PON_KEY1DB_F,
  346. .end = AB8500_INT_PON_KEY1DB_F,
  347. .flags = IORESOURCE_IRQ,
  348. },
  349. {
  350. .name = "ONKEY_DBR",
  351. .start = AB8500_INT_PON_KEY1DB_R,
  352. .end = AB8500_INT_PON_KEY1DB_R,
  353. .flags = IORESOURCE_IRQ,
  354. },
  355. };
  356. static struct resource __devinitdata ab8500_av_acc_detect_resources[] = {
  357. {
  358. .name = "ACC_DETECT_1DB_F",
  359. .start = AB8500_INT_ACC_DETECT_1DB_F,
  360. .end = AB8500_INT_ACC_DETECT_1DB_F,
  361. .flags = IORESOURCE_IRQ,
  362. },
  363. {
  364. .name = "ACC_DETECT_1DB_R",
  365. .start = AB8500_INT_ACC_DETECT_1DB_R,
  366. .end = AB8500_INT_ACC_DETECT_1DB_R,
  367. .flags = IORESOURCE_IRQ,
  368. },
  369. {
  370. .name = "ACC_DETECT_21DB_F",
  371. .start = AB8500_INT_ACC_DETECT_21DB_F,
  372. .end = AB8500_INT_ACC_DETECT_21DB_F,
  373. .flags = IORESOURCE_IRQ,
  374. },
  375. {
  376. .name = "ACC_DETECT_21DB_R",
  377. .start = AB8500_INT_ACC_DETECT_21DB_R,
  378. .end = AB8500_INT_ACC_DETECT_21DB_R,
  379. .flags = IORESOURCE_IRQ,
  380. },
  381. {
  382. .name = "ACC_DETECT_22DB_F",
  383. .start = AB8500_INT_ACC_DETECT_22DB_F,
  384. .end = AB8500_INT_ACC_DETECT_22DB_F,
  385. .flags = IORESOURCE_IRQ,
  386. },
  387. {
  388. .name = "ACC_DETECT_22DB_R",
  389. .start = AB8500_INT_ACC_DETECT_22DB_R,
  390. .end = AB8500_INT_ACC_DETECT_22DB_R,
  391. .flags = IORESOURCE_IRQ,
  392. },
  393. };
  394. static struct resource __devinitdata ab8500_charger_resources[] = {
  395. {
  396. .name = "MAIN_CH_UNPLUG_DET",
  397. .start = AB8500_INT_MAIN_CH_UNPLUG_DET,
  398. .end = AB8500_INT_MAIN_CH_UNPLUG_DET,
  399. .flags = IORESOURCE_IRQ,
  400. },
  401. {
  402. .name = "MAIN_CHARGE_PLUG_DET",
  403. .start = AB8500_INT_MAIN_CH_PLUG_DET,
  404. .end = AB8500_INT_MAIN_CH_PLUG_DET,
  405. .flags = IORESOURCE_IRQ,
  406. },
  407. {
  408. .name = "VBUS_DET_R",
  409. .start = AB8500_INT_VBUS_DET_R,
  410. .end = AB8500_INT_VBUS_DET_R,
  411. .flags = IORESOURCE_IRQ,
  412. },
  413. {
  414. .name = "VBUS_DET_F",
  415. .start = AB8500_INT_VBUS_DET_F,
  416. .end = AB8500_INT_VBUS_DET_F,
  417. .flags = IORESOURCE_IRQ,
  418. },
  419. {
  420. .name = "USB_LINK_STATUS",
  421. .start = AB8500_INT_USB_LINK_STATUS,
  422. .end = AB8500_INT_USB_LINK_STATUS,
  423. .flags = IORESOURCE_IRQ,
  424. },
  425. {
  426. .name = "USB_CHARGE_DET_DONE",
  427. .start = AB8500_INT_USB_CHG_DET_DONE,
  428. .end = AB8500_INT_USB_CHG_DET_DONE,
  429. .flags = IORESOURCE_IRQ,
  430. },
  431. {
  432. .name = "VBUS_OVV",
  433. .start = AB8500_INT_VBUS_OVV,
  434. .end = AB8500_INT_VBUS_OVV,
  435. .flags = IORESOURCE_IRQ,
  436. },
  437. {
  438. .name = "USB_CH_TH_PROT_R",
  439. .start = AB8500_INT_USB_CH_TH_PROT_R,
  440. .end = AB8500_INT_USB_CH_TH_PROT_R,
  441. .flags = IORESOURCE_IRQ,
  442. },
  443. {
  444. .name = "USB_CH_TH_PROT_F",
  445. .start = AB8500_INT_USB_CH_TH_PROT_F,
  446. .end = AB8500_INT_USB_CH_TH_PROT_F,
  447. .flags = IORESOURCE_IRQ,
  448. },
  449. {
  450. .name = "MAIN_EXT_CH_NOT_OK",
  451. .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
  452. .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
  453. .flags = IORESOURCE_IRQ,
  454. },
  455. {
  456. .name = "MAIN_CH_TH_PROT_R",
  457. .start = AB8500_INT_MAIN_CH_TH_PROT_R,
  458. .end = AB8500_INT_MAIN_CH_TH_PROT_R,
  459. .flags = IORESOURCE_IRQ,
  460. },
  461. {
  462. .name = "MAIN_CH_TH_PROT_F",
  463. .start = AB8500_INT_MAIN_CH_TH_PROT_F,
  464. .end = AB8500_INT_MAIN_CH_TH_PROT_F,
  465. .flags = IORESOURCE_IRQ,
  466. },
  467. {
  468. .name = "USB_CHARGER_NOT_OKR",
  469. .start = AB8500_INT_USB_CHARGER_NOT_OK,
  470. .end = AB8500_INT_USB_CHARGER_NOT_OK,
  471. .flags = IORESOURCE_IRQ,
  472. },
  473. {
  474. .name = "USB_CHARGER_NOT_OKF",
  475. .start = AB8500_INT_USB_CHARGER_NOT_OKF,
  476. .end = AB8500_INT_USB_CHARGER_NOT_OKF,
  477. .flags = IORESOURCE_IRQ,
  478. },
  479. {
  480. .name = "CH_WD_EXP",
  481. .start = AB8500_INT_CH_WD_EXP,
  482. .end = AB8500_INT_CH_WD_EXP,
  483. .flags = IORESOURCE_IRQ,
  484. },
  485. };
  486. static struct resource __devinitdata ab8500_btemp_resources[] = {
  487. {
  488. .name = "BAT_CTRL_INDB",
  489. .start = AB8500_INT_BAT_CTRL_INDB,
  490. .end = AB8500_INT_BAT_CTRL_INDB,
  491. .flags = IORESOURCE_IRQ,
  492. },
  493. {
  494. .name = "BTEMP_LOW",
  495. .start = AB8500_INT_BTEMP_LOW,
  496. .end = AB8500_INT_BTEMP_LOW,
  497. .flags = IORESOURCE_IRQ,
  498. },
  499. {
  500. .name = "BTEMP_HIGH",
  501. .start = AB8500_INT_BTEMP_HIGH,
  502. .end = AB8500_INT_BTEMP_HIGH,
  503. .flags = IORESOURCE_IRQ,
  504. },
  505. {
  506. .name = "BTEMP_LOW_MEDIUM",
  507. .start = AB8500_INT_BTEMP_LOW_MEDIUM,
  508. .end = AB8500_INT_BTEMP_LOW_MEDIUM,
  509. .flags = IORESOURCE_IRQ,
  510. },
  511. {
  512. .name = "BTEMP_MEDIUM_HIGH",
  513. .start = AB8500_INT_BTEMP_MEDIUM_HIGH,
  514. .end = AB8500_INT_BTEMP_MEDIUM_HIGH,
  515. .flags = IORESOURCE_IRQ,
  516. },
  517. };
  518. static struct resource __devinitdata ab8500_fg_resources[] = {
  519. {
  520. .name = "NCONV_ACCU",
  521. .start = AB8500_INT_CCN_CONV_ACC,
  522. .end = AB8500_INT_CCN_CONV_ACC,
  523. .flags = IORESOURCE_IRQ,
  524. },
  525. {
  526. .name = "BATT_OVV",
  527. .start = AB8500_INT_BATT_OVV,
  528. .end = AB8500_INT_BATT_OVV,
  529. .flags = IORESOURCE_IRQ,
  530. },
  531. {
  532. .name = "LOW_BAT_F",
  533. .start = AB8500_INT_LOW_BAT_F,
  534. .end = AB8500_INT_LOW_BAT_F,
  535. .flags = IORESOURCE_IRQ,
  536. },
  537. {
  538. .name = "LOW_BAT_R",
  539. .start = AB8500_INT_LOW_BAT_R,
  540. .end = AB8500_INT_LOW_BAT_R,
  541. .flags = IORESOURCE_IRQ,
  542. },
  543. {
  544. .name = "CC_INT_CALIB",
  545. .start = AB8500_INT_CC_INT_CALIB,
  546. .end = AB8500_INT_CC_INT_CALIB,
  547. .flags = IORESOURCE_IRQ,
  548. },
  549. };
  550. static struct resource __devinitdata ab8500_chargalg_resources[] = {};
  551. static struct resource __devinitdata ab8500_debug_resources[] = {
  552. {
  553. .name = "IRQ_FIRST",
  554. .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
  555. .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
  556. .flags = IORESOURCE_IRQ,
  557. },
  558. {
  559. .name = "IRQ_LAST",
  560. .start = AB8500_INT_USB_CHARGER_NOT_OKF,
  561. .end = AB8500_INT_USB_CHARGER_NOT_OKF,
  562. .flags = IORESOURCE_IRQ,
  563. },
  564. };
  565. static struct resource __devinitdata ab8500_usb_resources[] = {
  566. {
  567. .name = "ID_WAKEUP_R",
  568. .start = AB8500_INT_ID_WAKEUP_R,
  569. .end = AB8500_INT_ID_WAKEUP_R,
  570. .flags = IORESOURCE_IRQ,
  571. },
  572. {
  573. .name = "ID_WAKEUP_F",
  574. .start = AB8500_INT_ID_WAKEUP_F,
  575. .end = AB8500_INT_ID_WAKEUP_F,
  576. .flags = IORESOURCE_IRQ,
  577. },
  578. {
  579. .name = "VBUS_DET_F",
  580. .start = AB8500_INT_VBUS_DET_F,
  581. .end = AB8500_INT_VBUS_DET_F,
  582. .flags = IORESOURCE_IRQ,
  583. },
  584. {
  585. .name = "VBUS_DET_R",
  586. .start = AB8500_INT_VBUS_DET_R,
  587. .end = AB8500_INT_VBUS_DET_R,
  588. .flags = IORESOURCE_IRQ,
  589. },
  590. {
  591. .name = "USB_LINK_STATUS",
  592. .start = AB8500_INT_USB_LINK_STATUS,
  593. .end = AB8500_INT_USB_LINK_STATUS,
  594. .flags = IORESOURCE_IRQ,
  595. },
  596. {
  597. .name = "USB_ADP_PROBE_PLUG",
  598. .start = AB8500_INT_ADP_PROBE_PLUG,
  599. .end = AB8500_INT_ADP_PROBE_PLUG,
  600. .flags = IORESOURCE_IRQ,
  601. },
  602. {
  603. .name = "USB_ADP_PROBE_UNPLUG",
  604. .start = AB8500_INT_ADP_PROBE_UNPLUG,
  605. .end = AB8500_INT_ADP_PROBE_UNPLUG,
  606. .flags = IORESOURCE_IRQ,
  607. },
  608. };
  609. static struct resource __devinitdata ab8500_temp_resources[] = {
  610. {
  611. .name = "AB8500_TEMP_WARM",
  612. .start = AB8500_INT_TEMP_WARM,
  613. .end = AB8500_INT_TEMP_WARM,
  614. .flags = IORESOURCE_IRQ,
  615. },
  616. };
  617. static struct mfd_cell __devinitdata ab8500_devs[] = {
  618. #ifdef CONFIG_DEBUG_FS
  619. {
  620. .name = "ab8500-debug",
  621. .num_resources = ARRAY_SIZE(ab8500_debug_resources),
  622. .resources = ab8500_debug_resources,
  623. },
  624. #endif
  625. {
  626. .name = "ab8500-sysctrl",
  627. },
  628. {
  629. .name = "ab8500-regulator",
  630. },
  631. {
  632. .name = "ab8500-gpio",
  633. .num_resources = ARRAY_SIZE(ab8500_gpio_resources),
  634. .resources = ab8500_gpio_resources,
  635. },
  636. {
  637. .name = "ab8500-gpadc",
  638. .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
  639. .resources = ab8500_gpadc_resources,
  640. },
  641. {
  642. .name = "ab8500-rtc",
  643. .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
  644. .resources = ab8500_rtc_resources,
  645. },
  646. {
  647. .name = "ab8500-charger",
  648. .num_resources = ARRAY_SIZE(ab8500_charger_resources),
  649. .resources = ab8500_charger_resources,
  650. },
  651. {
  652. .name = "ab8500-btemp",
  653. .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
  654. .resources = ab8500_btemp_resources,
  655. },
  656. {
  657. .name = "ab8500-fg",
  658. .num_resources = ARRAY_SIZE(ab8500_fg_resources),
  659. .resources = ab8500_fg_resources,
  660. },
  661. {
  662. .name = "ab8500-chargalg",
  663. .num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
  664. .resources = ab8500_chargalg_resources,
  665. },
  666. {
  667. .name = "ab8500-acc-det",
  668. .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
  669. .resources = ab8500_av_acc_detect_resources,
  670. },
  671. {
  672. .name = "ab8500-codec",
  673. },
  674. {
  675. .name = "ab8500-usb",
  676. .num_resources = ARRAY_SIZE(ab8500_usb_resources),
  677. .resources = ab8500_usb_resources,
  678. },
  679. {
  680. .name = "ab8500-poweron-key",
  681. .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
  682. .resources = ab8500_poweronkey_db_resources,
  683. },
  684. {
  685. .name = "ab8500-pwm",
  686. .id = 1,
  687. },
  688. {
  689. .name = "ab8500-pwm",
  690. .id = 2,
  691. },
  692. {
  693. .name = "ab8500-pwm",
  694. .id = 3,
  695. },
  696. { .name = "ab8500-leds", },
  697. {
  698. .name = "ab8500-denc",
  699. },
  700. {
  701. .name = "ab8500-temp",
  702. .num_resources = ARRAY_SIZE(ab8500_temp_resources),
  703. .resources = ab8500_temp_resources,
  704. },
  705. };
  706. static ssize_t show_chip_id(struct device *dev,
  707. struct device_attribute *attr, char *buf)
  708. {
  709. struct ab8500 *ab8500;
  710. ab8500 = dev_get_drvdata(dev);
  711. return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
  712. }
  713. /*
  714. * ab8500 has switched off due to (SWITCH_OFF_STATUS):
  715. * 0x01 Swoff bit programming
  716. * 0x02 Thermal protection activation
  717. * 0x04 Vbat lower then BattOk falling threshold
  718. * 0x08 Watchdog expired
  719. * 0x10 Non presence of 32kHz clock
  720. * 0x20 Battery level lower than power on reset threshold
  721. * 0x40 Power on key 1 pressed longer than 10 seconds
  722. * 0x80 DB8500 thermal shutdown
  723. */
  724. static ssize_t show_switch_off_status(struct device *dev,
  725. struct device_attribute *attr, char *buf)
  726. {
  727. int ret;
  728. u8 value;
  729. struct ab8500 *ab8500;
  730. ab8500 = dev_get_drvdata(dev);
  731. ret = get_register_interruptible(ab8500, AB8500_RTC,
  732. AB8500_SWITCH_OFF_STATUS, &value);
  733. if (ret < 0)
  734. return ret;
  735. return sprintf(buf, "%#x\n", value);
  736. }
  737. static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
  738. static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
  739. static struct attribute *ab8500_sysfs_entries[] = {
  740. &dev_attr_chip_id.attr,
  741. &dev_attr_switch_off_status.attr,
  742. NULL,
  743. };
  744. static struct attribute_group ab8500_attr_group = {
  745. .attrs = ab8500_sysfs_entries,
  746. };
  747. int __devinit ab8500_init(struct ab8500 *ab8500)
  748. {
  749. struct ab8500_platform_data *plat = dev_get_platdata(ab8500->dev);
  750. int ret;
  751. int i;
  752. u8 value;
  753. if (plat)
  754. ab8500->irq_base = plat->irq_base;
  755. mutex_init(&ab8500->lock);
  756. mutex_init(&ab8500->irq_lock);
  757. ret = get_register_interruptible(ab8500, AB8500_MISC,
  758. AB8500_REV_REG, &value);
  759. if (ret < 0)
  760. return ret;
  761. switch (value) {
  762. case AB8500_CUT1P0:
  763. case AB8500_CUT1P1:
  764. case AB8500_CUT2P0:
  765. case AB8500_CUT3P0:
  766. case AB8500_CUT3P3:
  767. dev_info(ab8500->dev, "detected chip, revision: %#x\n", value);
  768. break;
  769. default:
  770. dev_err(ab8500->dev, "unknown chip, revision: %#x\n", value);
  771. return -EINVAL;
  772. }
  773. ab8500->chip_id = value;
  774. /*
  775. * ab8500 has switched off due to (SWITCH_OFF_STATUS):
  776. * 0x01 Swoff bit programming
  777. * 0x02 Thermal protection activation
  778. * 0x04 Vbat lower then BattOk falling threshold
  779. * 0x08 Watchdog expired
  780. * 0x10 Non presence of 32kHz clock
  781. * 0x20 Battery level lower than power on reset threshold
  782. * 0x40 Power on key 1 pressed longer than 10 seconds
  783. * 0x80 DB8500 thermal shutdown
  784. */
  785. ret = get_register_interruptible(ab8500, AB8500_RTC,
  786. AB8500_SWITCH_OFF_STATUS, &value);
  787. if (ret < 0)
  788. return ret;
  789. dev_info(ab8500->dev, "switch off status: %#x", value);
  790. if (plat && plat->init)
  791. plat->init(ab8500);
  792. /* Clear and mask all interrupts */
  793. for (i = 0; i < AB8500_NUM_IRQ_REGS; i++) {
  794. /* Interrupt register 12 doesn't exist prior to version 2.0 */
  795. if (ab8500_irq_regoffset[i] == 11 &&
  796. ab8500->chip_id < AB8500_CUT2P0)
  797. continue;
  798. get_register_interruptible(ab8500, AB8500_INTERRUPT,
  799. AB8500_IT_LATCH1_REG + ab8500_irq_regoffset[i],
  800. &value);
  801. set_register_interruptible(ab8500, AB8500_INTERRUPT,
  802. AB8500_IT_MASK1_REG + ab8500_irq_regoffset[i], 0xff);
  803. }
  804. ret = abx500_register_ops(ab8500->dev, &ab8500_ops);
  805. if (ret)
  806. return ret;
  807. for (i = 0; i < AB8500_NUM_IRQ_REGS; i++)
  808. ab8500->mask[i] = ab8500->oldmask[i] = 0xff;
  809. if (ab8500->irq_base) {
  810. ret = ab8500_irq_init(ab8500);
  811. if (ret)
  812. return ret;
  813. ret = request_threaded_irq(ab8500->irq, NULL, ab8500_irq,
  814. IRQF_ONESHOT | IRQF_NO_SUSPEND,
  815. "ab8500", ab8500);
  816. if (ret)
  817. goto out_removeirq;
  818. }
  819. ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
  820. ARRAY_SIZE(ab8500_devs), NULL,
  821. ab8500->irq_base);
  822. if (ret)
  823. goto out_freeirq;
  824. ret = sysfs_create_group(&ab8500->dev->kobj, &ab8500_attr_group);
  825. if (ret)
  826. dev_err(ab8500->dev, "error creating sysfs entries\n");
  827. return ret;
  828. out_freeirq:
  829. if (ab8500->irq_base) {
  830. free_irq(ab8500->irq, ab8500);
  831. out_removeirq:
  832. ab8500_irq_remove(ab8500);
  833. }
  834. return ret;
  835. }
  836. int __devexit ab8500_exit(struct ab8500 *ab8500)
  837. {
  838. sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
  839. mfd_remove_devices(ab8500->dev);
  840. if (ab8500->irq_base) {
  841. free_irq(ab8500->irq, ab8500);
  842. ab8500_irq_remove(ab8500);
  843. }
  844. return 0;
  845. }
  846. MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent");
  847. MODULE_DESCRIPTION("AB8500 MFD core");
  848. MODULE_LICENSE("GPL v2");