ab8500-core.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378
  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/irqdomain.h>
  14. #include <linux/delay.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/module.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/mfd/core.h>
  19. #include <linux/mfd/abx500.h>
  20. #include <linux/mfd/abx500/ab8500.h>
  21. #include <linux/mfd/abx500/ab8500-bm.h>
  22. #include <linux/mfd/dbx500-prcmu.h>
  23. #include <linux/regulator/ab8500.h>
  24. #include <linux/of.h>
  25. #include <linux/of_device.h>
  26. /*
  27. * Interrupt register offsets
  28. * Bank : 0x0E
  29. */
  30. #define AB8500_IT_SOURCE1_REG 0x00
  31. #define AB8500_IT_SOURCE2_REG 0x01
  32. #define AB8500_IT_SOURCE3_REG 0x02
  33. #define AB8500_IT_SOURCE4_REG 0x03
  34. #define AB8500_IT_SOURCE5_REG 0x04
  35. #define AB8500_IT_SOURCE6_REG 0x05
  36. #define AB8500_IT_SOURCE7_REG 0x06
  37. #define AB8500_IT_SOURCE8_REG 0x07
  38. #define AB9540_IT_SOURCE13_REG 0x0C
  39. #define AB8500_IT_SOURCE19_REG 0x12
  40. #define AB8500_IT_SOURCE20_REG 0x13
  41. #define AB8500_IT_SOURCE21_REG 0x14
  42. #define AB8500_IT_SOURCE22_REG 0x15
  43. #define AB8500_IT_SOURCE23_REG 0x16
  44. #define AB8500_IT_SOURCE24_REG 0x17
  45. /*
  46. * latch registers
  47. */
  48. #define AB8500_IT_LATCH1_REG 0x20
  49. #define AB8500_IT_LATCH2_REG 0x21
  50. #define AB8500_IT_LATCH3_REG 0x22
  51. #define AB8500_IT_LATCH4_REG 0x23
  52. #define AB8500_IT_LATCH5_REG 0x24
  53. #define AB8500_IT_LATCH6_REG 0x25
  54. #define AB8500_IT_LATCH7_REG 0x26
  55. #define AB8500_IT_LATCH8_REG 0x27
  56. #define AB8500_IT_LATCH9_REG 0x28
  57. #define AB8500_IT_LATCH10_REG 0x29
  58. #define AB8500_IT_LATCH12_REG 0x2B
  59. #define AB9540_IT_LATCH13_REG 0x2C
  60. #define AB8500_IT_LATCH19_REG 0x32
  61. #define AB8500_IT_LATCH20_REG 0x33
  62. #define AB8500_IT_LATCH21_REG 0x34
  63. #define AB8500_IT_LATCH22_REG 0x35
  64. #define AB8500_IT_LATCH23_REG 0x36
  65. #define AB8500_IT_LATCH24_REG 0x37
  66. /*
  67. * mask registers
  68. */
  69. #define AB8500_IT_MASK1_REG 0x40
  70. #define AB8500_IT_MASK2_REG 0x41
  71. #define AB8500_IT_MASK3_REG 0x42
  72. #define AB8500_IT_MASK4_REG 0x43
  73. #define AB8500_IT_MASK5_REG 0x44
  74. #define AB8500_IT_MASK6_REG 0x45
  75. #define AB8500_IT_MASK7_REG 0x46
  76. #define AB8500_IT_MASK8_REG 0x47
  77. #define AB8500_IT_MASK9_REG 0x48
  78. #define AB8500_IT_MASK10_REG 0x49
  79. #define AB8500_IT_MASK11_REG 0x4A
  80. #define AB8500_IT_MASK12_REG 0x4B
  81. #define AB8500_IT_MASK13_REG 0x4C
  82. #define AB8500_IT_MASK14_REG 0x4D
  83. #define AB8500_IT_MASK15_REG 0x4E
  84. #define AB8500_IT_MASK16_REG 0x4F
  85. #define AB8500_IT_MASK17_REG 0x50
  86. #define AB8500_IT_MASK18_REG 0x51
  87. #define AB8500_IT_MASK19_REG 0x52
  88. #define AB8500_IT_MASK20_REG 0x53
  89. #define AB8500_IT_MASK21_REG 0x54
  90. #define AB8500_IT_MASK22_REG 0x55
  91. #define AB8500_IT_MASK23_REG 0x56
  92. #define AB8500_IT_MASK24_REG 0x57
  93. #define AB8500_IT_MASK25_REG 0x58
  94. /*
  95. * latch hierarchy registers
  96. */
  97. #define AB8500_IT_LATCHHIER1_REG 0x60
  98. #define AB8500_IT_LATCHHIER2_REG 0x61
  99. #define AB8500_IT_LATCHHIER3_REG 0x62
  100. #define AB8540_IT_LATCHHIER4_REG 0x63
  101. #define AB8500_IT_LATCHHIER_NUM 3
  102. #define AB8540_IT_LATCHHIER_NUM 4
  103. #define AB8500_REV_REG 0x80
  104. #define AB8500_IC_NAME_REG 0x82
  105. #define AB8500_SWITCH_OFF_STATUS 0x00
  106. #define AB8500_TURN_ON_STATUS 0x00
  107. #define AB8505_TURN_ON_STATUS_2 0x04
  108. #define AB8500_CH_USBCH_STAT1_REG 0x02
  109. #define VBUS_DET_DBNC100 0x02
  110. #define VBUS_DET_DBNC1 0x01
  111. static DEFINE_SPINLOCK(on_stat_lock);
  112. static u8 turn_on_stat_mask = 0xFF;
  113. static u8 turn_on_stat_set;
  114. static bool no_bm; /* No battery management */
  115. module_param(no_bm, bool, S_IRUGO);
  116. #define AB9540_MODEM_CTRL2_REG 0x23
  117. #define AB9540_MODEM_CTRL2_SWDBBRSTN_BIT BIT(2)
  118. /*
  119. * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
  120. * numbers are indexed into this array with (num / 8). The interupts are
  121. * defined in linux/mfd/ab8500.h
  122. *
  123. * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at
  124. * offset 0.
  125. */
  126. /* AB8500 support */
  127. static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
  128. 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
  129. };
  130. /* AB9540 / AB8505 support */
  131. static const int ab9540_irq_regoffset[AB9540_NUM_IRQ_REGS] = {
  132. 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 12, 13, 24, 5, 22, 23
  133. };
  134. /* AB8540 support */
  135. static const int ab8540_irq_regoffset[AB8540_NUM_IRQ_REGS] = {
  136. 0, 1, 2, 3, 4, -1, -1, -1, -1, 11, 18, 19, 20, 21, 12, 13, 24, 5, 22,
  137. 23, 25, 26, 27, 28, 29, 30, 31,
  138. };
  139. static const char ab8500_version_str[][7] = {
  140. [AB8500_VERSION_AB8500] = "AB8500",
  141. [AB8500_VERSION_AB8505] = "AB8505",
  142. [AB8500_VERSION_AB9540] = "AB9540",
  143. [AB8500_VERSION_AB8540] = "AB8540",
  144. };
  145. static int ab8500_prcmu_write(struct ab8500 *ab8500, u16 addr, u8 data)
  146. {
  147. int ret;
  148. ret = prcmu_abb_write((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1);
  149. if (ret < 0)
  150. dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
  151. return ret;
  152. }
  153. static int ab8500_prcmu_write_masked(struct ab8500 *ab8500, u16 addr, u8 mask,
  154. u8 data)
  155. {
  156. int ret;
  157. ret = prcmu_abb_write_masked((u8)(addr >> 8), (u8)(addr & 0xFF), &data,
  158. &mask, 1);
  159. if (ret < 0)
  160. dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
  161. return ret;
  162. }
  163. static int ab8500_prcmu_read(struct ab8500 *ab8500, u16 addr)
  164. {
  165. int ret;
  166. u8 data;
  167. ret = prcmu_abb_read((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1);
  168. if (ret < 0) {
  169. dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
  170. return ret;
  171. }
  172. return (int)data;
  173. }
  174. static int ab8500_get_chip_id(struct device *dev)
  175. {
  176. struct ab8500 *ab8500;
  177. if (!dev)
  178. return -EINVAL;
  179. ab8500 = dev_get_drvdata(dev->parent);
  180. return ab8500 ? (int)ab8500->chip_id : -EINVAL;
  181. }
  182. static int set_register_interruptible(struct ab8500 *ab8500, u8 bank,
  183. u8 reg, u8 data)
  184. {
  185. int ret;
  186. /*
  187. * Put the u8 bank and u8 register together into a an u16.
  188. * The bank on higher 8 bits and register in lower 8 bits.
  189. */
  190. u16 addr = ((u16)bank) << 8 | reg;
  191. dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data);
  192. mutex_lock(&ab8500->lock);
  193. ret = ab8500->write(ab8500, addr, data);
  194. if (ret < 0)
  195. dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
  196. addr, ret);
  197. mutex_unlock(&ab8500->lock);
  198. return ret;
  199. }
  200. static int ab8500_set_register(struct device *dev, u8 bank,
  201. u8 reg, u8 value)
  202. {
  203. int ret;
  204. struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
  205. atomic_inc(&ab8500->transfer_ongoing);
  206. ret = set_register_interruptible(ab8500, bank, reg, value);
  207. atomic_dec(&ab8500->transfer_ongoing);
  208. return ret;
  209. }
  210. static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
  211. u8 reg, u8 *value)
  212. {
  213. int ret;
  214. u16 addr = ((u16)bank) << 8 | reg;
  215. mutex_lock(&ab8500->lock);
  216. ret = ab8500->read(ab8500, addr);
  217. if (ret < 0)
  218. dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
  219. addr, ret);
  220. else
  221. *value = ret;
  222. mutex_unlock(&ab8500->lock);
  223. dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
  224. return ret;
  225. }
  226. static int ab8500_get_register(struct device *dev, u8 bank,
  227. u8 reg, u8 *value)
  228. {
  229. int ret;
  230. struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
  231. atomic_inc(&ab8500->transfer_ongoing);
  232. ret = get_register_interruptible(ab8500, bank, reg, value);
  233. atomic_dec(&ab8500->transfer_ongoing);
  234. return ret;
  235. }
  236. static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank,
  237. u8 reg, u8 bitmask, u8 bitvalues)
  238. {
  239. int ret;
  240. u16 addr = ((u16)bank) << 8 | reg;
  241. mutex_lock(&ab8500->lock);
  242. if (ab8500->write_masked == NULL) {
  243. u8 data;
  244. ret = ab8500->read(ab8500, addr);
  245. if (ret < 0) {
  246. dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
  247. addr, ret);
  248. goto out;
  249. }
  250. data = (u8)ret;
  251. data = (~bitmask & data) | (bitmask & bitvalues);
  252. ret = ab8500->write(ab8500, addr, data);
  253. if (ret < 0)
  254. dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
  255. addr, ret);
  256. dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr,
  257. data);
  258. goto out;
  259. }
  260. ret = ab8500->write_masked(ab8500, addr, bitmask, bitvalues);
  261. if (ret < 0)
  262. dev_err(ab8500->dev, "failed to modify reg %#x: %d\n", addr,
  263. ret);
  264. out:
  265. mutex_unlock(&ab8500->lock);
  266. return ret;
  267. }
  268. static int ab8500_mask_and_set_register(struct device *dev,
  269. u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
  270. {
  271. int ret;
  272. struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
  273. atomic_inc(&ab8500->transfer_ongoing);
  274. ret = mask_and_set_register_interruptible(ab8500, bank, reg,
  275. bitmask, bitvalues);
  276. atomic_dec(&ab8500->transfer_ongoing);
  277. return ret;
  278. }
  279. static struct abx500_ops ab8500_ops = {
  280. .get_chip_id = ab8500_get_chip_id,
  281. .get_register = ab8500_get_register,
  282. .set_register = ab8500_set_register,
  283. .get_register_page = NULL,
  284. .set_register_page = NULL,
  285. .mask_and_set_register = ab8500_mask_and_set_register,
  286. .event_registers_startup_state_get = NULL,
  287. .startup_irq_enabled = NULL,
  288. .dump_all_banks = ab8500_dump_all_banks,
  289. };
  290. static void ab8500_irq_lock(struct irq_data *data)
  291. {
  292. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  293. mutex_lock(&ab8500->irq_lock);
  294. atomic_inc(&ab8500->transfer_ongoing);
  295. }
  296. static void ab8500_irq_sync_unlock(struct irq_data *data)
  297. {
  298. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  299. int i;
  300. for (i = 0; i < ab8500->mask_size; i++) {
  301. u8 old = ab8500->oldmask[i];
  302. u8 new = ab8500->mask[i];
  303. int reg;
  304. if (new == old)
  305. continue;
  306. /*
  307. * Interrupt register 12 doesn't exist prior to AB8500 version
  308. * 2.0
  309. */
  310. if (ab8500->irq_reg_offset[i] == 11 &&
  311. is_ab8500_1p1_or_earlier(ab8500))
  312. continue;
  313. if (ab8500->irq_reg_offset[i] < 0)
  314. continue;
  315. ab8500->oldmask[i] = new;
  316. reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i];
  317. set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new);
  318. }
  319. atomic_dec(&ab8500->transfer_ongoing);
  320. mutex_unlock(&ab8500->irq_lock);
  321. }
  322. static void ab8500_irq_mask(struct irq_data *data)
  323. {
  324. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  325. int offset = data->hwirq;
  326. int index = offset / 8;
  327. int mask = 1 << (offset % 8);
  328. ab8500->mask[index] |= mask;
  329. /* The AB8500 GPIOs have two interrupts each (rising & falling). */
  330. if (offset >= AB8500_INT_GPIO6R && offset <= AB8500_INT_GPIO41R)
  331. ab8500->mask[index + 2] |= mask;
  332. if (offset >= AB9540_INT_GPIO50R && offset <= AB9540_INT_GPIO54R)
  333. ab8500->mask[index + 1] |= mask;
  334. if (offset == AB8540_INT_GPIO43R || offset == AB8540_INT_GPIO44R)
  335. /* Here the falling IRQ is one bit lower */
  336. ab8500->mask[index] |= (mask << 1);
  337. }
  338. static void ab8500_irq_unmask(struct irq_data *data)
  339. {
  340. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  341. unsigned int type = irqd_get_trigger_type(data);
  342. int offset = data->hwirq;
  343. int index = offset / 8;
  344. int mask = 1 << (offset % 8);
  345. if (type & IRQ_TYPE_EDGE_RISING)
  346. ab8500->mask[index] &= ~mask;
  347. /* The AB8500 GPIOs have two interrupts each (rising & falling). */
  348. if (type & IRQ_TYPE_EDGE_FALLING) {
  349. if (offset >= AB8500_INT_GPIO6R && offset <= AB8500_INT_GPIO41R)
  350. ab8500->mask[index + 2] &= ~mask;
  351. else if (offset >= AB9540_INT_GPIO50R &&
  352. offset <= AB9540_INT_GPIO54R)
  353. ab8500->mask[index + 1] &= ~mask;
  354. else if (offset == AB8540_INT_GPIO43R ||
  355. offset == AB8540_INT_GPIO44R)
  356. /* Here the falling IRQ is one bit lower */
  357. ab8500->mask[index] &= ~(mask << 1);
  358. else
  359. ab8500->mask[index] &= ~mask;
  360. } else {
  361. /* Satisfies the case where type is not set. */
  362. ab8500->mask[index] &= ~mask;
  363. }
  364. }
  365. static int ab8500_irq_set_type(struct irq_data *data, unsigned int type)
  366. {
  367. return 0;
  368. }
  369. static struct irq_chip ab8500_irq_chip = {
  370. .name = "ab8500",
  371. .irq_bus_lock = ab8500_irq_lock,
  372. .irq_bus_sync_unlock = ab8500_irq_sync_unlock,
  373. .irq_mask = ab8500_irq_mask,
  374. .irq_disable = ab8500_irq_mask,
  375. .irq_unmask = ab8500_irq_unmask,
  376. .irq_set_type = ab8500_irq_set_type,
  377. };
  378. static void update_latch_offset(u8 *offset, int i)
  379. {
  380. /* Fix inconsistent ITFromLatch25 bit mapping... */
  381. if (unlikely(*offset == 17))
  382. *offset = 24;
  383. /* Fix inconsistent ab8540 bit mapping... */
  384. if (unlikely(*offset == 16))
  385. *offset = 25;
  386. if ((i == 3) && (*offset >= 24))
  387. *offset += 2;
  388. }
  389. static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500,
  390. int latch_offset, u8 latch_val)
  391. {
  392. int int_bit, line, i;
  393. for (i = 0; i < ab8500->mask_size; i++)
  394. if (ab8500->irq_reg_offset[i] == latch_offset)
  395. break;
  396. if (i >= ab8500->mask_size) {
  397. dev_err(ab8500->dev, "Register offset 0x%2x not declared\n",
  398. latch_offset);
  399. return -ENXIO;
  400. }
  401. /* ignore masked out interrupts */
  402. latch_val &= ~ab8500->mask[i];
  403. while (latch_val) {
  404. int_bit = __ffs(latch_val);
  405. line = (i << 3) + int_bit;
  406. latch_val &= ~(1 << int_bit);
  407. /*
  408. * This handles the falling edge hwirqs from the GPIO
  409. * lines. Route them back to the line registered for the
  410. * rising IRQ, as this is merely a flag for the same IRQ
  411. * in linux terms.
  412. */
  413. if (line >= AB8500_INT_GPIO6F && line <= AB8500_INT_GPIO41F)
  414. line -= 16;
  415. if (line >= AB9540_INT_GPIO50F && line <= AB9540_INT_GPIO54F)
  416. line -= 8;
  417. if (line == AB8540_INT_GPIO43F || line == AB8540_INT_GPIO44F)
  418. line += 1;
  419. handle_nested_irq(irq_create_mapping(ab8500->domain, line));
  420. }
  421. return 0;
  422. }
  423. static int ab8500_handle_hierarchical_latch(struct ab8500 *ab8500,
  424. int hier_offset, u8 hier_val)
  425. {
  426. int latch_bit, status;
  427. u8 latch_offset, latch_val;
  428. do {
  429. latch_bit = __ffs(hier_val);
  430. latch_offset = (hier_offset << 3) + latch_bit;
  431. update_latch_offset(&latch_offset, hier_offset);
  432. status = get_register_interruptible(ab8500,
  433. AB8500_INTERRUPT,
  434. AB8500_IT_LATCH1_REG + latch_offset,
  435. &latch_val);
  436. if (status < 0 || latch_val == 0)
  437. goto discard;
  438. status = ab8500_handle_hierarchical_line(ab8500,
  439. latch_offset, latch_val);
  440. if (status < 0)
  441. return status;
  442. discard:
  443. hier_val &= ~(1 << latch_bit);
  444. } while (hier_val);
  445. return 0;
  446. }
  447. static irqreturn_t ab8500_hierarchical_irq(int irq, void *dev)
  448. {
  449. struct ab8500 *ab8500 = dev;
  450. u8 i;
  451. dev_vdbg(ab8500->dev, "interrupt\n");
  452. /* Hierarchical interrupt version */
  453. for (i = 0; i < (ab8500->it_latchhier_num); i++) {
  454. int status;
  455. u8 hier_val;
  456. status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
  457. AB8500_IT_LATCHHIER1_REG + i, &hier_val);
  458. if (status < 0 || hier_val == 0)
  459. continue;
  460. status = ab8500_handle_hierarchical_latch(ab8500, i, hier_val);
  461. if (status < 0)
  462. break;
  463. }
  464. return IRQ_HANDLED;
  465. }
  466. static int ab8500_irq_map(struct irq_domain *d, unsigned int virq,
  467. irq_hw_number_t hwirq)
  468. {
  469. struct ab8500 *ab8500 = d->host_data;
  470. if (!ab8500)
  471. return -EINVAL;
  472. irq_set_chip_data(virq, ab8500);
  473. irq_set_chip_and_handler(virq, &ab8500_irq_chip,
  474. handle_simple_irq);
  475. irq_set_nested_thread(virq, 1);
  476. irq_set_noprobe(virq);
  477. return 0;
  478. }
  479. static const struct irq_domain_ops ab8500_irq_ops = {
  480. .map = ab8500_irq_map,
  481. .xlate = irq_domain_xlate_twocell,
  482. };
  483. static int ab8500_irq_init(struct ab8500 *ab8500, struct device_node *np)
  484. {
  485. int num_irqs;
  486. if (is_ab8540(ab8500))
  487. num_irqs = AB8540_NR_IRQS;
  488. else if (is_ab9540(ab8500))
  489. num_irqs = AB9540_NR_IRQS;
  490. else if (is_ab8505(ab8500))
  491. num_irqs = AB8505_NR_IRQS;
  492. else
  493. num_irqs = AB8500_NR_IRQS;
  494. /* If ->irq_base is zero this will give a linear mapping */
  495. ab8500->domain = irq_domain_add_simple(ab8500->dev->of_node,
  496. num_irqs, 0,
  497. &ab8500_irq_ops, ab8500);
  498. if (!ab8500->domain) {
  499. dev_err(ab8500->dev, "Failed to create irqdomain\n");
  500. return -ENODEV;
  501. }
  502. return 0;
  503. }
  504. int ab8500_suspend(struct ab8500 *ab8500)
  505. {
  506. if (atomic_read(&ab8500->transfer_ongoing))
  507. return -EINVAL;
  508. return 0;
  509. }
  510. static const struct mfd_cell ab8500_bm_devs[] = {
  511. {
  512. .name = "ab8500-charger",
  513. .of_compatible = "stericsson,ab8500-charger",
  514. .platform_data = &ab8500_bm_data,
  515. .pdata_size = sizeof(ab8500_bm_data),
  516. },
  517. {
  518. .name = "ab8500-btemp",
  519. .of_compatible = "stericsson,ab8500-btemp",
  520. .platform_data = &ab8500_bm_data,
  521. .pdata_size = sizeof(ab8500_bm_data),
  522. },
  523. {
  524. .name = "ab8500-fg",
  525. .of_compatible = "stericsson,ab8500-fg",
  526. .platform_data = &ab8500_bm_data,
  527. .pdata_size = sizeof(ab8500_bm_data),
  528. },
  529. {
  530. .name = "ab8500-chargalg",
  531. .of_compatible = "stericsson,ab8500-chargalg",
  532. .platform_data = &ab8500_bm_data,
  533. .pdata_size = sizeof(ab8500_bm_data),
  534. },
  535. };
  536. static const struct mfd_cell ab8500_devs[] = {
  537. #ifdef CONFIG_DEBUG_FS
  538. {
  539. .name = "ab8500-debug",
  540. .of_compatible = "stericsson,ab8500-debug",
  541. },
  542. #endif
  543. {
  544. .name = "ab8500-sysctrl",
  545. .of_compatible = "stericsson,ab8500-sysctrl",
  546. },
  547. {
  548. .name = "ab8500-ext-regulator",
  549. .of_compatible = "stericsson,ab8500-ext-regulator",
  550. },
  551. {
  552. .name = "ab8500-regulator",
  553. .of_compatible = "stericsson,ab8500-regulator",
  554. },
  555. {
  556. .name = "abx500-clk",
  557. .of_compatible = "stericsson,abx500-clk",
  558. },
  559. {
  560. .name = "ab8500-gpadc",
  561. .of_compatible = "stericsson,ab8500-gpadc",
  562. },
  563. {
  564. .name = "ab8500-rtc",
  565. .of_compatible = "stericsson,ab8500-rtc",
  566. },
  567. {
  568. .name = "ab8500-acc-det",
  569. .of_compatible = "stericsson,ab8500-acc-det",
  570. },
  571. {
  572. .name = "ab8500-poweron-key",
  573. .of_compatible = "stericsson,ab8500-poweron-key",
  574. },
  575. {
  576. .name = "ab8500-pwm",
  577. .of_compatible = "stericsson,ab8500-pwm",
  578. .id = 1,
  579. },
  580. {
  581. .name = "ab8500-pwm",
  582. .of_compatible = "stericsson,ab8500-pwm",
  583. .id = 2,
  584. },
  585. {
  586. .name = "ab8500-pwm",
  587. .of_compatible = "stericsson,ab8500-pwm",
  588. .id = 3,
  589. },
  590. {
  591. .name = "ab8500-denc",
  592. .of_compatible = "stericsson,ab8500-denc",
  593. },
  594. {
  595. .name = "pinctrl-ab8500",
  596. .of_compatible = "stericsson,ab8500-gpio",
  597. },
  598. {
  599. .name = "abx500-temp",
  600. .of_compatible = "stericsson,abx500-temp",
  601. },
  602. {
  603. .name = "ab8500-usb",
  604. .of_compatible = "stericsson,ab8500-usb",
  605. },
  606. {
  607. .name = "ab8500-codec",
  608. .of_compatible = "stericsson,ab8500-codec",
  609. },
  610. };
  611. static const struct mfd_cell ab9540_devs[] = {
  612. #ifdef CONFIG_DEBUG_FS
  613. {
  614. .name = "ab8500-debug",
  615. },
  616. #endif
  617. {
  618. .name = "ab8500-sysctrl",
  619. },
  620. {
  621. .name = "ab8500-ext-regulator",
  622. },
  623. {
  624. .name = "ab8500-regulator",
  625. },
  626. {
  627. .name = "abx500-clk",
  628. .of_compatible = "stericsson,abx500-clk",
  629. },
  630. {
  631. .name = "ab8500-gpadc",
  632. .of_compatible = "stericsson,ab8500-gpadc",
  633. },
  634. {
  635. .name = "ab8500-rtc",
  636. },
  637. {
  638. .name = "ab8500-acc-det",
  639. },
  640. {
  641. .name = "ab8500-poweron-key",
  642. },
  643. {
  644. .name = "ab8500-pwm",
  645. .id = 1,
  646. },
  647. {
  648. .name = "abx500-temp",
  649. },
  650. {
  651. .name = "pinctrl-ab9540",
  652. .of_compatible = "stericsson,ab9540-gpio",
  653. },
  654. {
  655. .name = "ab9540-usb",
  656. },
  657. {
  658. .name = "ab9540-codec",
  659. },
  660. {
  661. .name = "ab-iddet",
  662. },
  663. };
  664. /* Device list for ab8505 */
  665. static const struct mfd_cell ab8505_devs[] = {
  666. #ifdef CONFIG_DEBUG_FS
  667. {
  668. .name = "ab8500-debug",
  669. },
  670. #endif
  671. {
  672. .name = "ab8500-sysctrl",
  673. },
  674. {
  675. .name = "ab8500-regulator",
  676. },
  677. {
  678. .name = "abx500-clk",
  679. .of_compatible = "stericsson,abx500-clk",
  680. },
  681. {
  682. .name = "ab8500-gpadc",
  683. .of_compatible = "stericsson,ab8500-gpadc",
  684. },
  685. {
  686. .name = "ab8500-rtc",
  687. },
  688. {
  689. .name = "ab8500-acc-det",
  690. },
  691. {
  692. .name = "ab8500-poweron-key",
  693. },
  694. {
  695. .name = "ab8500-pwm",
  696. .id = 1,
  697. },
  698. {
  699. .name = "pinctrl-ab8505",
  700. },
  701. {
  702. .name = "ab8500-usb",
  703. },
  704. {
  705. .name = "ab8500-codec",
  706. },
  707. {
  708. .name = "ab-iddet",
  709. },
  710. };
  711. static const struct mfd_cell ab8540_devs[] = {
  712. #ifdef CONFIG_DEBUG_FS
  713. {
  714. .name = "ab8500-debug",
  715. },
  716. #endif
  717. {
  718. .name = "ab8500-sysctrl",
  719. },
  720. {
  721. .name = "ab8500-ext-regulator",
  722. },
  723. {
  724. .name = "ab8500-regulator",
  725. },
  726. {
  727. .name = "abx500-clk",
  728. .of_compatible = "stericsson,abx500-clk",
  729. },
  730. {
  731. .name = "ab8500-gpadc",
  732. .of_compatible = "stericsson,ab8500-gpadc",
  733. },
  734. {
  735. .name = "ab8500-acc-det",
  736. },
  737. {
  738. .name = "ab8500-poweron-key",
  739. },
  740. {
  741. .name = "ab8500-pwm",
  742. .id = 1,
  743. },
  744. {
  745. .name = "abx500-temp",
  746. },
  747. {
  748. .name = "pinctrl-ab8540",
  749. },
  750. {
  751. .name = "ab8540-usb",
  752. },
  753. {
  754. .name = "ab8540-codec",
  755. },
  756. {
  757. .name = "ab-iddet",
  758. },
  759. };
  760. static const struct mfd_cell ab8540_cut1_devs[] = {
  761. {
  762. .name = "ab8500-rtc",
  763. .of_compatible = "stericsson,ab8500-rtc",
  764. },
  765. };
  766. static const struct mfd_cell ab8540_cut2_devs[] = {
  767. {
  768. .name = "ab8540-rtc",
  769. .of_compatible = "stericsson,ab8540-rtc",
  770. },
  771. };
  772. static ssize_t show_chip_id(struct device *dev,
  773. struct device_attribute *attr, char *buf)
  774. {
  775. struct ab8500 *ab8500;
  776. ab8500 = dev_get_drvdata(dev);
  777. return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
  778. }
  779. /*
  780. * ab8500 has switched off due to (SWITCH_OFF_STATUS):
  781. * 0x01 Swoff bit programming
  782. * 0x02 Thermal protection activation
  783. * 0x04 Vbat lower then BattOk falling threshold
  784. * 0x08 Watchdog expired
  785. * 0x10 Non presence of 32kHz clock
  786. * 0x20 Battery level lower than power on reset threshold
  787. * 0x40 Power on key 1 pressed longer than 10 seconds
  788. * 0x80 DB8500 thermal shutdown
  789. */
  790. static ssize_t show_switch_off_status(struct device *dev,
  791. struct device_attribute *attr, char *buf)
  792. {
  793. int ret;
  794. u8 value;
  795. struct ab8500 *ab8500;
  796. ab8500 = dev_get_drvdata(dev);
  797. ret = get_register_interruptible(ab8500, AB8500_RTC,
  798. AB8500_SWITCH_OFF_STATUS, &value);
  799. if (ret < 0)
  800. return ret;
  801. return sprintf(buf, "%#x\n", value);
  802. }
  803. /* use mask and set to override the register turn_on_stat value */
  804. void ab8500_override_turn_on_stat(u8 mask, u8 set)
  805. {
  806. spin_lock(&on_stat_lock);
  807. turn_on_stat_mask = mask;
  808. turn_on_stat_set = set;
  809. spin_unlock(&on_stat_lock);
  810. }
  811. /*
  812. * ab8500 has turned on due to (TURN_ON_STATUS):
  813. * 0x01 PORnVbat
  814. * 0x02 PonKey1dbF
  815. * 0x04 PonKey2dbF
  816. * 0x08 RTCAlarm
  817. * 0x10 MainChDet
  818. * 0x20 VbusDet
  819. * 0x40 UsbIDDetect
  820. * 0x80 Reserved
  821. */
  822. static ssize_t show_turn_on_status(struct device *dev,
  823. struct device_attribute *attr, char *buf)
  824. {
  825. int ret;
  826. u8 value;
  827. struct ab8500 *ab8500;
  828. ab8500 = dev_get_drvdata(dev);
  829. ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
  830. AB8500_TURN_ON_STATUS, &value);
  831. if (ret < 0)
  832. return ret;
  833. /*
  834. * In L9540, turn_on_status register is not updated correctly if
  835. * the device is rebooted with AC/USB charger connected. Due to
  836. * this, the device boots android instead of entering into charge
  837. * only mode. Read the AC/USB status register to detect the charger
  838. * presence and update the turn on status manually.
  839. */
  840. if (is_ab9540(ab8500)) {
  841. spin_lock(&on_stat_lock);
  842. value = (value & turn_on_stat_mask) | turn_on_stat_set;
  843. spin_unlock(&on_stat_lock);
  844. }
  845. return sprintf(buf, "%#x\n", value);
  846. }
  847. static ssize_t show_turn_on_status_2(struct device *dev,
  848. struct device_attribute *attr, char *buf)
  849. {
  850. int ret;
  851. u8 value;
  852. struct ab8500 *ab8500;
  853. ab8500 = dev_get_drvdata(dev);
  854. ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
  855. AB8505_TURN_ON_STATUS_2, &value);
  856. if (ret < 0)
  857. return ret;
  858. return sprintf(buf, "%#x\n", (value & 0x1));
  859. }
  860. static ssize_t show_ab9540_dbbrstn(struct device *dev,
  861. struct device_attribute *attr, char *buf)
  862. {
  863. struct ab8500 *ab8500;
  864. int ret;
  865. u8 value;
  866. ab8500 = dev_get_drvdata(dev);
  867. ret = get_register_interruptible(ab8500, AB8500_REGU_CTRL2,
  868. AB9540_MODEM_CTRL2_REG, &value);
  869. if (ret < 0)
  870. return ret;
  871. return sprintf(buf, "%d\n",
  872. (value & AB9540_MODEM_CTRL2_SWDBBRSTN_BIT) ? 1 : 0);
  873. }
  874. static ssize_t store_ab9540_dbbrstn(struct device *dev,
  875. struct device_attribute *attr, const char *buf, size_t count)
  876. {
  877. struct ab8500 *ab8500;
  878. int ret = count;
  879. int err;
  880. u8 bitvalues;
  881. ab8500 = dev_get_drvdata(dev);
  882. if (count > 0) {
  883. switch (buf[0]) {
  884. case '0':
  885. bitvalues = 0;
  886. break;
  887. case '1':
  888. bitvalues = AB9540_MODEM_CTRL2_SWDBBRSTN_BIT;
  889. break;
  890. default:
  891. goto exit;
  892. }
  893. err = mask_and_set_register_interruptible(ab8500,
  894. AB8500_REGU_CTRL2, AB9540_MODEM_CTRL2_REG,
  895. AB9540_MODEM_CTRL2_SWDBBRSTN_BIT, bitvalues);
  896. if (err)
  897. dev_info(ab8500->dev,
  898. "Failed to set DBBRSTN %c, err %#x\n",
  899. buf[0], err);
  900. }
  901. exit:
  902. return ret;
  903. }
  904. static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
  905. static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
  906. static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL);
  907. static DEVICE_ATTR(turn_on_status_2, S_IRUGO, show_turn_on_status_2, NULL);
  908. static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR,
  909. show_ab9540_dbbrstn, store_ab9540_dbbrstn);
  910. static struct attribute *ab8500_sysfs_entries[] = {
  911. &dev_attr_chip_id.attr,
  912. &dev_attr_switch_off_status.attr,
  913. &dev_attr_turn_on_status.attr,
  914. NULL,
  915. };
  916. static struct attribute *ab8505_sysfs_entries[] = {
  917. &dev_attr_turn_on_status_2.attr,
  918. NULL,
  919. };
  920. static struct attribute *ab9540_sysfs_entries[] = {
  921. &dev_attr_chip_id.attr,
  922. &dev_attr_switch_off_status.attr,
  923. &dev_attr_turn_on_status.attr,
  924. &dev_attr_dbbrstn.attr,
  925. NULL,
  926. };
  927. static struct attribute_group ab8500_attr_group = {
  928. .attrs = ab8500_sysfs_entries,
  929. };
  930. static struct attribute_group ab8505_attr_group = {
  931. .attrs = ab8505_sysfs_entries,
  932. };
  933. static struct attribute_group ab9540_attr_group = {
  934. .attrs = ab9540_sysfs_entries,
  935. };
  936. static int ab8500_probe(struct platform_device *pdev)
  937. {
  938. static const char * const switch_off_status[] = {
  939. "Swoff bit programming",
  940. "Thermal protection activation",
  941. "Vbat lower then BattOk falling threshold",
  942. "Watchdog expired",
  943. "Non presence of 32kHz clock",
  944. "Battery level lower than power on reset threshold",
  945. "Power on key 1 pressed longer than 10 seconds",
  946. "DB8500 thermal shutdown"};
  947. static const char * const turn_on_status[] = {
  948. "Battery rising (Vbat)",
  949. "Power On Key 1 dbF",
  950. "Power On Key 2 dbF",
  951. "RTC Alarm",
  952. "Main Charger Detect",
  953. "Vbus Detect (USB)",
  954. "USB ID Detect",
  955. "UART Factory Mode Detect"};
  956. const struct platform_device_id *platid = platform_get_device_id(pdev);
  957. enum ab8500_version version = AB8500_VERSION_UNDEFINED;
  958. struct device_node *np = pdev->dev.of_node;
  959. struct ab8500 *ab8500;
  960. struct resource *resource;
  961. int ret;
  962. int i;
  963. u8 value;
  964. ab8500 = devm_kzalloc(&pdev->dev, sizeof(*ab8500), GFP_KERNEL);
  965. if (!ab8500)
  966. return -ENOMEM;
  967. ab8500->dev = &pdev->dev;
  968. resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  969. if (!resource) {
  970. dev_err(&pdev->dev, "no IRQ resource\n");
  971. return -ENODEV;
  972. }
  973. ab8500->irq = resource->start;
  974. ab8500->read = ab8500_prcmu_read;
  975. ab8500->write = ab8500_prcmu_write;
  976. ab8500->write_masked = ab8500_prcmu_write_masked;
  977. mutex_init(&ab8500->lock);
  978. mutex_init(&ab8500->irq_lock);
  979. atomic_set(&ab8500->transfer_ongoing, 0);
  980. platform_set_drvdata(pdev, ab8500);
  981. if (platid)
  982. version = platid->driver_data;
  983. if (version != AB8500_VERSION_UNDEFINED)
  984. ab8500->version = version;
  985. else {
  986. ret = get_register_interruptible(ab8500, AB8500_MISC,
  987. AB8500_IC_NAME_REG, &value);
  988. if (ret < 0) {
  989. dev_err(&pdev->dev, "could not probe HW\n");
  990. return ret;
  991. }
  992. ab8500->version = value;
  993. }
  994. ret = get_register_interruptible(ab8500, AB8500_MISC,
  995. AB8500_REV_REG, &value);
  996. if (ret < 0)
  997. return ret;
  998. ab8500->chip_id = value;
  999. dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n",
  1000. ab8500_version_str[ab8500->version],
  1001. ab8500->chip_id >> 4,
  1002. ab8500->chip_id & 0x0F);
  1003. /* Configure AB8540 */
  1004. if (is_ab8540(ab8500)) {
  1005. ab8500->mask_size = AB8540_NUM_IRQ_REGS;
  1006. ab8500->irq_reg_offset = ab8540_irq_regoffset;
  1007. ab8500->it_latchhier_num = AB8540_IT_LATCHHIER_NUM;
  1008. } /* Configure AB8500 or AB9540 IRQ */
  1009. else if (is_ab9540(ab8500) || is_ab8505(ab8500)) {
  1010. ab8500->mask_size = AB9540_NUM_IRQ_REGS;
  1011. ab8500->irq_reg_offset = ab9540_irq_regoffset;
  1012. ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM;
  1013. } else {
  1014. ab8500->mask_size = AB8500_NUM_IRQ_REGS;
  1015. ab8500->irq_reg_offset = ab8500_irq_regoffset;
  1016. ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM;
  1017. }
  1018. ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size,
  1019. GFP_KERNEL);
  1020. if (!ab8500->mask)
  1021. return -ENOMEM;
  1022. ab8500->oldmask = devm_kzalloc(&pdev->dev, ab8500->mask_size,
  1023. GFP_KERNEL);
  1024. if (!ab8500->oldmask)
  1025. return -ENOMEM;
  1026. /*
  1027. * ab8500 has switched off due to (SWITCH_OFF_STATUS):
  1028. * 0x01 Swoff bit programming
  1029. * 0x02 Thermal protection activation
  1030. * 0x04 Vbat lower then BattOk falling threshold
  1031. * 0x08 Watchdog expired
  1032. * 0x10 Non presence of 32kHz clock
  1033. * 0x20 Battery level lower than power on reset threshold
  1034. * 0x40 Power on key 1 pressed longer than 10 seconds
  1035. * 0x80 DB8500 thermal shutdown
  1036. */
  1037. ret = get_register_interruptible(ab8500, AB8500_RTC,
  1038. AB8500_SWITCH_OFF_STATUS, &value);
  1039. if (ret < 0)
  1040. return ret;
  1041. dev_info(ab8500->dev, "switch off cause(s) (%#x): ", value);
  1042. if (value) {
  1043. for (i = 0; i < ARRAY_SIZE(switch_off_status); i++) {
  1044. if (value & 1)
  1045. pr_cont(" \"%s\"", switch_off_status[i]);
  1046. value = value >> 1;
  1047. }
  1048. pr_cont("\n");
  1049. } else {
  1050. pr_cont(" None\n");
  1051. }
  1052. ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
  1053. AB8500_TURN_ON_STATUS, &value);
  1054. if (ret < 0)
  1055. return ret;
  1056. dev_info(ab8500->dev, "turn on reason(s) (%#x): ", value);
  1057. if (value) {
  1058. for (i = 0; i < ARRAY_SIZE(turn_on_status); i++) {
  1059. if (value & 1)
  1060. pr_cont("\"%s\" ", turn_on_status[i]);
  1061. value = value >> 1;
  1062. }
  1063. pr_cont("\n");
  1064. } else {
  1065. pr_cont("None\n");
  1066. }
  1067. if (is_ab9540(ab8500)) {
  1068. ret = get_register_interruptible(ab8500, AB8500_CHARGER,
  1069. AB8500_CH_USBCH_STAT1_REG, &value);
  1070. if (ret < 0)
  1071. return ret;
  1072. if ((value & VBUS_DET_DBNC1) && (value & VBUS_DET_DBNC100))
  1073. ab8500_override_turn_on_stat(~AB8500_POW_KEY_1_ON,
  1074. AB8500_VBUS_DET);
  1075. }
  1076. /* Clear and mask all interrupts */
  1077. for (i = 0; i < ab8500->mask_size; i++) {
  1078. /*
  1079. * Interrupt register 12 doesn't exist prior to AB8500 version
  1080. * 2.0
  1081. */
  1082. if (ab8500->irq_reg_offset[i] == 11 &&
  1083. is_ab8500_1p1_or_earlier(ab8500))
  1084. continue;
  1085. if (ab8500->irq_reg_offset[i] < 0)
  1086. continue;
  1087. get_register_interruptible(ab8500, AB8500_INTERRUPT,
  1088. AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i],
  1089. &value);
  1090. set_register_interruptible(ab8500, AB8500_INTERRUPT,
  1091. AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff);
  1092. }
  1093. ret = abx500_register_ops(ab8500->dev, &ab8500_ops);
  1094. if (ret)
  1095. return ret;
  1096. for (i = 0; i < ab8500->mask_size; i++)
  1097. ab8500->mask[i] = ab8500->oldmask[i] = 0xff;
  1098. ret = ab8500_irq_init(ab8500, np);
  1099. if (ret)
  1100. return ret;
  1101. ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL,
  1102. ab8500_hierarchical_irq,
  1103. IRQF_ONESHOT | IRQF_NO_SUSPEND,
  1104. "ab8500", ab8500);
  1105. if (ret)
  1106. return ret;
  1107. if (is_ab9540(ab8500))
  1108. ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs,
  1109. ARRAY_SIZE(ab9540_devs), NULL,
  1110. 0, ab8500->domain);
  1111. else if (is_ab8540(ab8500)) {
  1112. ret = mfd_add_devices(ab8500->dev, 0, ab8540_devs,
  1113. ARRAY_SIZE(ab8540_devs), NULL,
  1114. 0, ab8500->domain);
  1115. if (ret)
  1116. return ret;
  1117. if (is_ab8540_1p2_or_earlier(ab8500))
  1118. ret = mfd_add_devices(ab8500->dev, 0, ab8540_cut1_devs,
  1119. ARRAY_SIZE(ab8540_cut1_devs), NULL,
  1120. 0, ab8500->domain);
  1121. else /* ab8540 >= cut2 */
  1122. ret = mfd_add_devices(ab8500->dev, 0, ab8540_cut2_devs,
  1123. ARRAY_SIZE(ab8540_cut2_devs), NULL,
  1124. 0, ab8500->domain);
  1125. } else if (is_ab8505(ab8500))
  1126. ret = mfd_add_devices(ab8500->dev, 0, ab8505_devs,
  1127. ARRAY_SIZE(ab8505_devs), NULL,
  1128. 0, ab8500->domain);
  1129. else
  1130. ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
  1131. ARRAY_SIZE(ab8500_devs), NULL,
  1132. 0, ab8500->domain);
  1133. if (ret)
  1134. return ret;
  1135. if (!no_bm) {
  1136. /* Add battery management devices */
  1137. ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs,
  1138. ARRAY_SIZE(ab8500_bm_devs), NULL,
  1139. 0, ab8500->domain);
  1140. if (ret)
  1141. dev_err(ab8500->dev, "error adding bm devices\n");
  1142. }
  1143. if (((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
  1144. ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500))
  1145. ret = sysfs_create_group(&ab8500->dev->kobj,
  1146. &ab9540_attr_group);
  1147. else
  1148. ret = sysfs_create_group(&ab8500->dev->kobj,
  1149. &ab8500_attr_group);
  1150. if ((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
  1151. ab8500->chip_id >= AB8500_CUT2P0)
  1152. ret = sysfs_create_group(&ab8500->dev->kobj,
  1153. &ab8505_attr_group);
  1154. if (ret)
  1155. dev_err(ab8500->dev, "error creating sysfs entries\n");
  1156. return ret;
  1157. }
  1158. static int ab8500_remove(struct platform_device *pdev)
  1159. {
  1160. struct ab8500 *ab8500 = platform_get_drvdata(pdev);
  1161. if (((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
  1162. ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500))
  1163. sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group);
  1164. else
  1165. sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
  1166. if ((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
  1167. ab8500->chip_id >= AB8500_CUT2P0)
  1168. sysfs_remove_group(&ab8500->dev->kobj, &ab8505_attr_group);
  1169. mfd_remove_devices(ab8500->dev);
  1170. return 0;
  1171. }
  1172. static const struct platform_device_id ab8500_id[] = {
  1173. { "ab8500-core", AB8500_VERSION_AB8500 },
  1174. { "ab8505-i2c", AB8500_VERSION_AB8505 },
  1175. { "ab9540-i2c", AB8500_VERSION_AB9540 },
  1176. { "ab8540-i2c", AB8500_VERSION_AB8540 },
  1177. { }
  1178. };
  1179. static struct platform_driver ab8500_core_driver = {
  1180. .driver = {
  1181. .name = "ab8500-core",
  1182. },
  1183. .probe = ab8500_probe,
  1184. .remove = ab8500_remove,
  1185. .id_table = ab8500_id,
  1186. };
  1187. static int __init ab8500_core_init(void)
  1188. {
  1189. return platform_driver_register(&ab8500_core_driver);
  1190. }
  1191. static void __exit ab8500_core_exit(void)
  1192. {
  1193. platform_driver_unregister(&ab8500_core_driver);
  1194. }
  1195. core_initcall(ab8500_core_init);
  1196. module_exit(ab8500_core_exit);
  1197. MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent");
  1198. MODULE_DESCRIPTION("AB8500 MFD core");
  1199. MODULE_LICENSE("GPL v2");