ab8500-core.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867
  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. /* put the u8 bank and u8 reg together into a an u16.
  215. * bank on higher 8 bits and reg in lower */
  216. u16 addr = ((u16)bank) << 8 | reg;
  217. mutex_lock(&ab8500->lock);
  218. ret = ab8500->read(ab8500, addr);
  219. if (ret < 0)
  220. dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
  221. addr, ret);
  222. else
  223. *value = ret;
  224. mutex_unlock(&ab8500->lock);
  225. dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
  226. return (ret < 0) ? ret : 0;
  227. }
  228. static int ab8500_get_register(struct device *dev, u8 bank,
  229. u8 reg, u8 *value)
  230. {
  231. int ret;
  232. struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
  233. atomic_inc(&ab8500->transfer_ongoing);
  234. ret = get_register_interruptible(ab8500, bank, reg, value);
  235. atomic_dec(&ab8500->transfer_ongoing);
  236. return ret;
  237. }
  238. static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank,
  239. u8 reg, u8 bitmask, u8 bitvalues)
  240. {
  241. int ret;
  242. /* put the u8 bank and u8 reg together into a an u16.
  243. * bank on higher 8 bits and reg in lower */
  244. u16 addr = ((u16)bank) << 8 | reg;
  245. mutex_lock(&ab8500->lock);
  246. if (ab8500->write_masked == NULL) {
  247. u8 data;
  248. ret = ab8500->read(ab8500, addr);
  249. if (ret < 0) {
  250. dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
  251. addr, ret);
  252. goto out;
  253. }
  254. data = (u8)ret;
  255. data = (~bitmask & data) | (bitmask & bitvalues);
  256. ret = ab8500->write(ab8500, addr, data);
  257. if (ret < 0)
  258. dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
  259. addr, ret);
  260. dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr,
  261. data);
  262. goto out;
  263. }
  264. ret = ab8500->write_masked(ab8500, addr, bitmask, bitvalues);
  265. if (ret < 0)
  266. dev_err(ab8500->dev, "failed to modify reg %#x: %d\n", addr,
  267. ret);
  268. out:
  269. mutex_unlock(&ab8500->lock);
  270. return ret;
  271. }
  272. static int ab8500_mask_and_set_register(struct device *dev,
  273. u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
  274. {
  275. int ret;
  276. struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
  277. atomic_inc(&ab8500->transfer_ongoing);
  278. ret = mask_and_set_register_interruptible(ab8500, bank, reg,
  279. bitmask, bitvalues);
  280. atomic_dec(&ab8500->transfer_ongoing);
  281. return ret;
  282. }
  283. static struct abx500_ops ab8500_ops = {
  284. .get_chip_id = ab8500_get_chip_id,
  285. .get_register = ab8500_get_register,
  286. .set_register = ab8500_set_register,
  287. .get_register_page = NULL,
  288. .set_register_page = NULL,
  289. .mask_and_set_register = ab8500_mask_and_set_register,
  290. .event_registers_startup_state_get = NULL,
  291. .startup_irq_enabled = NULL,
  292. .dump_all_banks = ab8500_dump_all_banks,
  293. };
  294. static void ab8500_irq_lock(struct irq_data *data)
  295. {
  296. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  297. mutex_lock(&ab8500->irq_lock);
  298. atomic_inc(&ab8500->transfer_ongoing);
  299. }
  300. static void ab8500_irq_sync_unlock(struct irq_data *data)
  301. {
  302. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  303. int i;
  304. for (i = 0; i < ab8500->mask_size; i++) {
  305. u8 old = ab8500->oldmask[i];
  306. u8 new = ab8500->mask[i];
  307. int reg;
  308. if (new == old)
  309. continue;
  310. /*
  311. * Interrupt register 12 doesn't exist prior to AB8500 version
  312. * 2.0
  313. */
  314. if (ab8500->irq_reg_offset[i] == 11 &&
  315. is_ab8500_1p1_or_earlier(ab8500))
  316. continue;
  317. if (ab8500->irq_reg_offset[i] < 0)
  318. continue;
  319. ab8500->oldmask[i] = new;
  320. reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i];
  321. set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new);
  322. }
  323. atomic_dec(&ab8500->transfer_ongoing);
  324. mutex_unlock(&ab8500->irq_lock);
  325. }
  326. static void ab8500_irq_mask(struct irq_data *data)
  327. {
  328. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  329. int offset = data->hwirq;
  330. int index = offset / 8;
  331. int mask = 1 << (offset % 8);
  332. ab8500->mask[index] |= mask;
  333. /* The AB8500 GPIOs have two interrupts each (rising & falling). */
  334. if (offset >= AB8500_INT_GPIO6R && offset <= AB8500_INT_GPIO41R)
  335. ab8500->mask[index + 2] |= mask;
  336. if (offset >= AB9540_INT_GPIO50R && offset <= AB9540_INT_GPIO54R)
  337. ab8500->mask[index + 1] |= mask;
  338. if (offset == AB8540_INT_GPIO43R || offset == AB8540_INT_GPIO44R)
  339. /* Here the falling IRQ is one bit lower */
  340. ab8500->mask[index] |= (mask << 1);
  341. }
  342. static void ab8500_irq_unmask(struct irq_data *data)
  343. {
  344. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  345. unsigned int type = irqd_get_trigger_type(data);
  346. int offset = data->hwirq;
  347. int index = offset / 8;
  348. int mask = 1 << (offset % 8);
  349. if (type & IRQ_TYPE_EDGE_RISING)
  350. ab8500->mask[index] &= ~mask;
  351. /* The AB8500 GPIOs have two interrupts each (rising & falling). */
  352. if (type & IRQ_TYPE_EDGE_FALLING) {
  353. if (offset >= AB8500_INT_GPIO6R && offset <= AB8500_INT_GPIO41R)
  354. ab8500->mask[index + 2] &= ~mask;
  355. else if (offset >= AB9540_INT_GPIO50R &&
  356. offset <= AB9540_INT_GPIO54R)
  357. ab8500->mask[index + 1] &= ~mask;
  358. else if (offset == AB8540_INT_GPIO43R ||
  359. offset == AB8540_INT_GPIO44R)
  360. /* Here the falling IRQ is one bit lower */
  361. ab8500->mask[index] &= ~(mask << 1);
  362. else
  363. ab8500->mask[index] &= ~mask;
  364. } else {
  365. /* Satisfies the case where type is not set. */
  366. ab8500->mask[index] &= ~mask;
  367. }
  368. }
  369. static int ab8500_irq_set_type(struct irq_data *data, unsigned int type)
  370. {
  371. return 0;
  372. }
  373. static struct irq_chip ab8500_irq_chip = {
  374. .name = "ab8500",
  375. .irq_bus_lock = ab8500_irq_lock,
  376. .irq_bus_sync_unlock = ab8500_irq_sync_unlock,
  377. .irq_mask = ab8500_irq_mask,
  378. .irq_disable = ab8500_irq_mask,
  379. .irq_unmask = ab8500_irq_unmask,
  380. .irq_set_type = ab8500_irq_set_type,
  381. };
  382. static void update_latch_offset(u8 *offset, int i)
  383. {
  384. /* Fix inconsistent ITFromLatch25 bit mapping... */
  385. if (unlikely(*offset == 17))
  386. *offset = 24;
  387. /* Fix inconsistent ab8540 bit mapping... */
  388. if (unlikely(*offset == 16))
  389. *offset = 25;
  390. if ((i == 3) && (*offset >= 24))
  391. *offset += 2;
  392. }
  393. static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500,
  394. int latch_offset, u8 latch_val)
  395. {
  396. int int_bit, line, i;
  397. for (i = 0; i < ab8500->mask_size; i++)
  398. if (ab8500->irq_reg_offset[i] == latch_offset)
  399. break;
  400. if (i >= ab8500->mask_size) {
  401. dev_err(ab8500->dev, "Register offset 0x%2x not declared\n",
  402. latch_offset);
  403. return -ENXIO;
  404. }
  405. /* ignore masked out interrupts */
  406. latch_val &= ~ab8500->mask[i];
  407. while (latch_val) {
  408. int_bit = __ffs(latch_val);
  409. line = (i << 3) + int_bit;
  410. latch_val &= ~(1 << int_bit);
  411. /*
  412. * This handles the falling edge hwirqs from the GPIO
  413. * lines. Route them back to the line registered for the
  414. * rising IRQ, as this is merely a flag for the same IRQ
  415. * in linux terms.
  416. */
  417. if (line >= AB8500_INT_GPIO6F && line <= AB8500_INT_GPIO41F)
  418. line -= 16;
  419. if (line >= AB9540_INT_GPIO50F && line <= AB9540_INT_GPIO54F)
  420. line -= 8;
  421. if (line == AB8540_INT_GPIO43F || line == AB8540_INT_GPIO44F)
  422. line += 1;
  423. handle_nested_irq(irq_create_mapping(ab8500->domain, line));
  424. }
  425. return 0;
  426. }
  427. static int ab8500_handle_hierarchical_latch(struct ab8500 *ab8500,
  428. int hier_offset, u8 hier_val)
  429. {
  430. int latch_bit, status;
  431. u8 latch_offset, latch_val;
  432. do {
  433. latch_bit = __ffs(hier_val);
  434. latch_offset = (hier_offset << 3) + latch_bit;
  435. update_latch_offset(&latch_offset, hier_offset);
  436. status = get_register_interruptible(ab8500,
  437. AB8500_INTERRUPT,
  438. AB8500_IT_LATCH1_REG + latch_offset,
  439. &latch_val);
  440. if (status < 0 || latch_val == 0)
  441. goto discard;
  442. status = ab8500_handle_hierarchical_line(ab8500,
  443. latch_offset, latch_val);
  444. if (status < 0)
  445. return status;
  446. discard:
  447. hier_val &= ~(1 << latch_bit);
  448. } while (hier_val);
  449. return 0;
  450. }
  451. static irqreturn_t ab8500_hierarchical_irq(int irq, void *dev)
  452. {
  453. struct ab8500 *ab8500 = dev;
  454. u8 i;
  455. dev_vdbg(ab8500->dev, "interrupt\n");
  456. /* Hierarchical interrupt version */
  457. for (i = 0; i < (ab8500->it_latchhier_num); i++) {
  458. int status;
  459. u8 hier_val;
  460. status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
  461. AB8500_IT_LATCHHIER1_REG + i, &hier_val);
  462. if (status < 0 || hier_val == 0)
  463. continue;
  464. status = ab8500_handle_hierarchical_latch(ab8500, i, hier_val);
  465. if (status < 0)
  466. break;
  467. }
  468. return IRQ_HANDLED;
  469. }
  470. static int ab8500_irq_map(struct irq_domain *d, unsigned int virq,
  471. irq_hw_number_t hwirq)
  472. {
  473. struct ab8500 *ab8500 = d->host_data;
  474. if (!ab8500)
  475. return -EINVAL;
  476. irq_set_chip_data(virq, ab8500);
  477. irq_set_chip_and_handler(virq, &ab8500_irq_chip,
  478. handle_simple_irq);
  479. irq_set_nested_thread(virq, 1);
  480. irq_set_noprobe(virq);
  481. return 0;
  482. }
  483. static const struct irq_domain_ops ab8500_irq_ops = {
  484. .map = ab8500_irq_map,
  485. .xlate = irq_domain_xlate_twocell,
  486. };
  487. static int ab8500_irq_init(struct ab8500 *ab8500, struct device_node *np)
  488. {
  489. int num_irqs;
  490. if (is_ab8540(ab8500))
  491. num_irqs = AB8540_NR_IRQS;
  492. else if (is_ab9540(ab8500))
  493. num_irqs = AB9540_NR_IRQS;
  494. else if (is_ab8505(ab8500))
  495. num_irqs = AB8505_NR_IRQS;
  496. else
  497. num_irqs = AB8500_NR_IRQS;
  498. /* If ->irq_base is zero this will give a linear mapping */
  499. ab8500->domain = irq_domain_add_simple(ab8500->dev->of_node,
  500. num_irqs, 0,
  501. &ab8500_irq_ops, ab8500);
  502. if (!ab8500->domain) {
  503. dev_err(ab8500->dev, "Failed to create irqdomain\n");
  504. return -ENOSYS;
  505. }
  506. return 0;
  507. }
  508. int ab8500_suspend(struct ab8500 *ab8500)
  509. {
  510. if (atomic_read(&ab8500->transfer_ongoing))
  511. return -EINVAL;
  512. return 0;
  513. }
  514. static struct resource ab8500_gpadc_resources[] = {
  515. {
  516. .name = "HW_CONV_END",
  517. .start = AB8500_INT_GP_HW_ADC_CONV_END,
  518. .end = AB8500_INT_GP_HW_ADC_CONV_END,
  519. .flags = IORESOURCE_IRQ,
  520. },
  521. {
  522. .name = "SW_CONV_END",
  523. .start = AB8500_INT_GP_SW_ADC_CONV_END,
  524. .end = AB8500_INT_GP_SW_ADC_CONV_END,
  525. .flags = IORESOURCE_IRQ,
  526. },
  527. };
  528. static struct resource ab8505_gpadc_resources[] = {
  529. {
  530. .name = "SW_CONV_END",
  531. .start = AB8500_INT_GP_SW_ADC_CONV_END,
  532. .end = AB8500_INT_GP_SW_ADC_CONV_END,
  533. .flags = IORESOURCE_IRQ,
  534. },
  535. };
  536. static struct resource ab8500_rtc_resources[] = {
  537. {
  538. .name = "60S",
  539. .start = AB8500_INT_RTC_60S,
  540. .end = AB8500_INT_RTC_60S,
  541. .flags = IORESOURCE_IRQ,
  542. },
  543. {
  544. .name = "ALARM",
  545. .start = AB8500_INT_RTC_ALARM,
  546. .end = AB8500_INT_RTC_ALARM,
  547. .flags = IORESOURCE_IRQ,
  548. },
  549. };
  550. static struct resource ab8540_rtc_resources[] = {
  551. {
  552. .name = "1S",
  553. .start = AB8540_INT_RTC_1S,
  554. .end = AB8540_INT_RTC_1S,
  555. .flags = IORESOURCE_IRQ,
  556. },
  557. {
  558. .name = "ALARM",
  559. .start = AB8500_INT_RTC_ALARM,
  560. .end = AB8500_INT_RTC_ALARM,
  561. .flags = IORESOURCE_IRQ,
  562. },
  563. };
  564. static struct resource ab8500_poweronkey_db_resources[] = {
  565. {
  566. .name = "ONKEY_DBF",
  567. .start = AB8500_INT_PON_KEY1DB_F,
  568. .end = AB8500_INT_PON_KEY1DB_F,
  569. .flags = IORESOURCE_IRQ,
  570. },
  571. {
  572. .name = "ONKEY_DBR",
  573. .start = AB8500_INT_PON_KEY1DB_R,
  574. .end = AB8500_INT_PON_KEY1DB_R,
  575. .flags = IORESOURCE_IRQ,
  576. },
  577. };
  578. static struct resource ab8500_av_acc_detect_resources[] = {
  579. {
  580. .name = "ACC_DETECT_1DB_F",
  581. .start = AB8500_INT_ACC_DETECT_1DB_F,
  582. .end = AB8500_INT_ACC_DETECT_1DB_F,
  583. .flags = IORESOURCE_IRQ,
  584. },
  585. {
  586. .name = "ACC_DETECT_1DB_R",
  587. .start = AB8500_INT_ACC_DETECT_1DB_R,
  588. .end = AB8500_INT_ACC_DETECT_1DB_R,
  589. .flags = IORESOURCE_IRQ,
  590. },
  591. {
  592. .name = "ACC_DETECT_21DB_F",
  593. .start = AB8500_INT_ACC_DETECT_21DB_F,
  594. .end = AB8500_INT_ACC_DETECT_21DB_F,
  595. .flags = IORESOURCE_IRQ,
  596. },
  597. {
  598. .name = "ACC_DETECT_21DB_R",
  599. .start = AB8500_INT_ACC_DETECT_21DB_R,
  600. .end = AB8500_INT_ACC_DETECT_21DB_R,
  601. .flags = IORESOURCE_IRQ,
  602. },
  603. {
  604. .name = "ACC_DETECT_22DB_F",
  605. .start = AB8500_INT_ACC_DETECT_22DB_F,
  606. .end = AB8500_INT_ACC_DETECT_22DB_F,
  607. .flags = IORESOURCE_IRQ,
  608. },
  609. {
  610. .name = "ACC_DETECT_22DB_R",
  611. .start = AB8500_INT_ACC_DETECT_22DB_R,
  612. .end = AB8500_INT_ACC_DETECT_22DB_R,
  613. .flags = IORESOURCE_IRQ,
  614. },
  615. };
  616. static struct resource ab8500_charger_resources[] = {
  617. {
  618. .name = "MAIN_CH_UNPLUG_DET",
  619. .start = AB8500_INT_MAIN_CH_UNPLUG_DET,
  620. .end = AB8500_INT_MAIN_CH_UNPLUG_DET,
  621. .flags = IORESOURCE_IRQ,
  622. },
  623. {
  624. .name = "MAIN_CHARGE_PLUG_DET",
  625. .start = AB8500_INT_MAIN_CH_PLUG_DET,
  626. .end = AB8500_INT_MAIN_CH_PLUG_DET,
  627. .flags = IORESOURCE_IRQ,
  628. },
  629. {
  630. .name = "VBUS_DET_R",
  631. .start = AB8500_INT_VBUS_DET_R,
  632. .end = AB8500_INT_VBUS_DET_R,
  633. .flags = IORESOURCE_IRQ,
  634. },
  635. {
  636. .name = "VBUS_DET_F",
  637. .start = AB8500_INT_VBUS_DET_F,
  638. .end = AB8500_INT_VBUS_DET_F,
  639. .flags = IORESOURCE_IRQ,
  640. },
  641. {
  642. .name = "USB_LINK_STATUS",
  643. .start = AB8500_INT_USB_LINK_STATUS,
  644. .end = AB8500_INT_USB_LINK_STATUS,
  645. .flags = IORESOURCE_IRQ,
  646. },
  647. {
  648. .name = "VBUS_OVV",
  649. .start = AB8500_INT_VBUS_OVV,
  650. .end = AB8500_INT_VBUS_OVV,
  651. .flags = IORESOURCE_IRQ,
  652. },
  653. {
  654. .name = "USB_CH_TH_PROT_R",
  655. .start = AB8500_INT_USB_CH_TH_PROT_R,
  656. .end = AB8500_INT_USB_CH_TH_PROT_R,
  657. .flags = IORESOURCE_IRQ,
  658. },
  659. {
  660. .name = "USB_CH_TH_PROT_F",
  661. .start = AB8500_INT_USB_CH_TH_PROT_F,
  662. .end = AB8500_INT_USB_CH_TH_PROT_F,
  663. .flags = IORESOURCE_IRQ,
  664. },
  665. {
  666. .name = "MAIN_EXT_CH_NOT_OK",
  667. .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
  668. .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
  669. .flags = IORESOURCE_IRQ,
  670. },
  671. {
  672. .name = "MAIN_CH_TH_PROT_R",
  673. .start = AB8500_INT_MAIN_CH_TH_PROT_R,
  674. .end = AB8500_INT_MAIN_CH_TH_PROT_R,
  675. .flags = IORESOURCE_IRQ,
  676. },
  677. {
  678. .name = "MAIN_CH_TH_PROT_F",
  679. .start = AB8500_INT_MAIN_CH_TH_PROT_F,
  680. .end = AB8500_INT_MAIN_CH_TH_PROT_F,
  681. .flags = IORESOURCE_IRQ,
  682. },
  683. {
  684. .name = "USB_CHARGER_NOT_OKR",
  685. .start = AB8500_INT_USB_CHARGER_NOT_OKR,
  686. .end = AB8500_INT_USB_CHARGER_NOT_OKR,
  687. .flags = IORESOURCE_IRQ,
  688. },
  689. {
  690. .name = "CH_WD_EXP",
  691. .start = AB8500_INT_CH_WD_EXP,
  692. .end = AB8500_INT_CH_WD_EXP,
  693. .flags = IORESOURCE_IRQ,
  694. },
  695. {
  696. .name = "VBUS_CH_DROP_END",
  697. .start = AB8500_INT_VBUS_CH_DROP_END,
  698. .end = AB8500_INT_VBUS_CH_DROP_END,
  699. .flags = IORESOURCE_IRQ,
  700. },
  701. };
  702. static struct resource ab8500_btemp_resources[] = {
  703. {
  704. .name = "BAT_CTRL_INDB",
  705. .start = AB8500_INT_BAT_CTRL_INDB,
  706. .end = AB8500_INT_BAT_CTRL_INDB,
  707. .flags = IORESOURCE_IRQ,
  708. },
  709. {
  710. .name = "BTEMP_LOW",
  711. .start = AB8500_INT_BTEMP_LOW,
  712. .end = AB8500_INT_BTEMP_LOW,
  713. .flags = IORESOURCE_IRQ,
  714. },
  715. {
  716. .name = "BTEMP_HIGH",
  717. .start = AB8500_INT_BTEMP_HIGH,
  718. .end = AB8500_INT_BTEMP_HIGH,
  719. .flags = IORESOURCE_IRQ,
  720. },
  721. {
  722. .name = "BTEMP_LOW_MEDIUM",
  723. .start = AB8500_INT_BTEMP_LOW_MEDIUM,
  724. .end = AB8500_INT_BTEMP_LOW_MEDIUM,
  725. .flags = IORESOURCE_IRQ,
  726. },
  727. {
  728. .name = "BTEMP_MEDIUM_HIGH",
  729. .start = AB8500_INT_BTEMP_MEDIUM_HIGH,
  730. .end = AB8500_INT_BTEMP_MEDIUM_HIGH,
  731. .flags = IORESOURCE_IRQ,
  732. },
  733. };
  734. static struct resource ab8500_fg_resources[] = {
  735. {
  736. .name = "NCONV_ACCU",
  737. .start = AB8500_INT_CCN_CONV_ACC,
  738. .end = AB8500_INT_CCN_CONV_ACC,
  739. .flags = IORESOURCE_IRQ,
  740. },
  741. {
  742. .name = "BATT_OVV",
  743. .start = AB8500_INT_BATT_OVV,
  744. .end = AB8500_INT_BATT_OVV,
  745. .flags = IORESOURCE_IRQ,
  746. },
  747. {
  748. .name = "LOW_BAT_F",
  749. .start = AB8500_INT_LOW_BAT_F,
  750. .end = AB8500_INT_LOW_BAT_F,
  751. .flags = IORESOURCE_IRQ,
  752. },
  753. {
  754. .name = "LOW_BAT_R",
  755. .start = AB8500_INT_LOW_BAT_R,
  756. .end = AB8500_INT_LOW_BAT_R,
  757. .flags = IORESOURCE_IRQ,
  758. },
  759. {
  760. .name = "CC_INT_CALIB",
  761. .start = AB8500_INT_CC_INT_CALIB,
  762. .end = AB8500_INT_CC_INT_CALIB,
  763. .flags = IORESOURCE_IRQ,
  764. },
  765. {
  766. .name = "CCEOC",
  767. .start = AB8500_INT_CCEOC,
  768. .end = AB8500_INT_CCEOC,
  769. .flags = IORESOURCE_IRQ,
  770. },
  771. };
  772. static struct resource ab8500_chargalg_resources[] = {};
  773. #ifdef CONFIG_DEBUG_FS
  774. static struct resource ab8500_debug_resources[] = {
  775. {
  776. .name = "IRQ_AB8500",
  777. /*
  778. * Number will be filled in. NOTE: this is deliberately
  779. * not flagged as an IRQ in ordet to avoid remapping using
  780. * the irqdomain in the MFD core, so that this IRQ passes
  781. * unremapped to the debug code.
  782. */
  783. },
  784. {
  785. .name = "IRQ_FIRST",
  786. .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
  787. .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
  788. .flags = IORESOURCE_IRQ,
  789. },
  790. {
  791. .name = "IRQ_LAST",
  792. .start = AB8500_INT_XTAL32K_KO,
  793. .end = AB8500_INT_XTAL32K_KO,
  794. .flags = IORESOURCE_IRQ,
  795. },
  796. };
  797. #endif
  798. static struct resource ab8500_usb_resources[] = {
  799. {
  800. .name = "ID_WAKEUP_R",
  801. .start = AB8500_INT_ID_WAKEUP_R,
  802. .end = AB8500_INT_ID_WAKEUP_R,
  803. .flags = IORESOURCE_IRQ,
  804. },
  805. {
  806. .name = "ID_WAKEUP_F",
  807. .start = AB8500_INT_ID_WAKEUP_F,
  808. .end = AB8500_INT_ID_WAKEUP_F,
  809. .flags = IORESOURCE_IRQ,
  810. },
  811. {
  812. .name = "VBUS_DET_F",
  813. .start = AB8500_INT_VBUS_DET_F,
  814. .end = AB8500_INT_VBUS_DET_F,
  815. .flags = IORESOURCE_IRQ,
  816. },
  817. {
  818. .name = "VBUS_DET_R",
  819. .start = AB8500_INT_VBUS_DET_R,
  820. .end = AB8500_INT_VBUS_DET_R,
  821. .flags = IORESOURCE_IRQ,
  822. },
  823. {
  824. .name = "USB_LINK_STATUS",
  825. .start = AB8500_INT_USB_LINK_STATUS,
  826. .end = AB8500_INT_USB_LINK_STATUS,
  827. .flags = IORESOURCE_IRQ,
  828. },
  829. {
  830. .name = "USB_ADP_PROBE_PLUG",
  831. .start = AB8500_INT_ADP_PROBE_PLUG,
  832. .end = AB8500_INT_ADP_PROBE_PLUG,
  833. .flags = IORESOURCE_IRQ,
  834. },
  835. {
  836. .name = "USB_ADP_PROBE_UNPLUG",
  837. .start = AB8500_INT_ADP_PROBE_UNPLUG,
  838. .end = AB8500_INT_ADP_PROBE_UNPLUG,
  839. .flags = IORESOURCE_IRQ,
  840. },
  841. };
  842. static struct resource ab8505_iddet_resources[] = {
  843. {
  844. .name = "KeyDeglitch",
  845. .start = AB8505_INT_KEYDEGLITCH,
  846. .end = AB8505_INT_KEYDEGLITCH,
  847. .flags = IORESOURCE_IRQ,
  848. },
  849. {
  850. .name = "KP",
  851. .start = AB8505_INT_KP,
  852. .end = AB8505_INT_KP,
  853. .flags = IORESOURCE_IRQ,
  854. },
  855. {
  856. .name = "IKP",
  857. .start = AB8505_INT_IKP,
  858. .end = AB8505_INT_IKP,
  859. .flags = IORESOURCE_IRQ,
  860. },
  861. {
  862. .name = "IKR",
  863. .start = AB8505_INT_IKR,
  864. .end = AB8505_INT_IKR,
  865. .flags = IORESOURCE_IRQ,
  866. },
  867. {
  868. .name = "KeyStuck",
  869. .start = AB8505_INT_KEYSTUCK,
  870. .end = AB8505_INT_KEYSTUCK,
  871. .flags = IORESOURCE_IRQ,
  872. },
  873. {
  874. .name = "VBUS_DET_R",
  875. .start = AB8500_INT_VBUS_DET_R,
  876. .end = AB8500_INT_VBUS_DET_R,
  877. .flags = IORESOURCE_IRQ,
  878. },
  879. {
  880. .name = "VBUS_DET_F",
  881. .start = AB8500_INT_VBUS_DET_F,
  882. .end = AB8500_INT_VBUS_DET_F,
  883. .flags = IORESOURCE_IRQ,
  884. },
  885. {
  886. .name = "ID_DET_PLUGR",
  887. .start = AB8500_INT_ID_DET_PLUGR,
  888. .end = AB8500_INT_ID_DET_PLUGR,
  889. .flags = IORESOURCE_IRQ,
  890. },
  891. {
  892. .name = "ID_DET_PLUGF",
  893. .start = AB8500_INT_ID_DET_PLUGF,
  894. .end = AB8500_INT_ID_DET_PLUGF,
  895. .flags = IORESOURCE_IRQ,
  896. },
  897. };
  898. static struct resource ab8500_temp_resources[] = {
  899. {
  900. .name = "ABX500_TEMP_WARM",
  901. .start = AB8500_INT_TEMP_WARM,
  902. .end = AB8500_INT_TEMP_WARM,
  903. .flags = IORESOURCE_IRQ,
  904. },
  905. };
  906. static const struct mfd_cell ab8500_bm_devs[] = {
  907. {
  908. .name = "ab8500-charger",
  909. .of_compatible = "stericsson,ab8500-charger",
  910. .num_resources = ARRAY_SIZE(ab8500_charger_resources),
  911. .resources = ab8500_charger_resources,
  912. .platform_data = &ab8500_bm_data,
  913. .pdata_size = sizeof(ab8500_bm_data),
  914. },
  915. {
  916. .name = "ab8500-btemp",
  917. .of_compatible = "stericsson,ab8500-btemp",
  918. .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
  919. .resources = ab8500_btemp_resources,
  920. .platform_data = &ab8500_bm_data,
  921. .pdata_size = sizeof(ab8500_bm_data),
  922. },
  923. {
  924. .name = "ab8500-fg",
  925. .of_compatible = "stericsson,ab8500-fg",
  926. .num_resources = ARRAY_SIZE(ab8500_fg_resources),
  927. .resources = ab8500_fg_resources,
  928. .platform_data = &ab8500_bm_data,
  929. .pdata_size = sizeof(ab8500_bm_data),
  930. },
  931. {
  932. .name = "ab8500-chargalg",
  933. .of_compatible = "stericsson,ab8500-chargalg",
  934. .num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
  935. .resources = ab8500_chargalg_resources,
  936. .platform_data = &ab8500_bm_data,
  937. .pdata_size = sizeof(ab8500_bm_data),
  938. },
  939. };
  940. static const struct mfd_cell ab8500_devs[] = {
  941. #ifdef CONFIG_DEBUG_FS
  942. {
  943. .name = "ab8500-debug",
  944. .of_compatible = "stericsson,ab8500-debug",
  945. .num_resources = ARRAY_SIZE(ab8500_debug_resources),
  946. .resources = ab8500_debug_resources,
  947. },
  948. #endif
  949. {
  950. .name = "ab8500-sysctrl",
  951. .of_compatible = "stericsson,ab8500-sysctrl",
  952. },
  953. {
  954. .name = "ab8500-ext-regulator",
  955. .of_compatible = "stericsson,ab8500-ext-regulator",
  956. },
  957. {
  958. .name = "ab8500-regulator",
  959. .of_compatible = "stericsson,ab8500-regulator",
  960. },
  961. {
  962. .name = "abx500-clk",
  963. .of_compatible = "stericsson,abx500-clk",
  964. },
  965. {
  966. .name = "ab8500-gpadc",
  967. .of_compatible = "stericsson,ab8500-gpadc",
  968. .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
  969. .resources = ab8500_gpadc_resources,
  970. },
  971. {
  972. .name = "ab8500-rtc",
  973. .of_compatible = "stericsson,ab8500-rtc",
  974. .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
  975. .resources = ab8500_rtc_resources,
  976. },
  977. {
  978. .name = "ab8500-acc-det",
  979. .of_compatible = "stericsson,ab8500-acc-det",
  980. .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
  981. .resources = ab8500_av_acc_detect_resources,
  982. },
  983. {
  984. .name = "ab8500-poweron-key",
  985. .of_compatible = "stericsson,ab8500-poweron-key",
  986. .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
  987. .resources = ab8500_poweronkey_db_resources,
  988. },
  989. {
  990. .name = "ab8500-pwm",
  991. .of_compatible = "stericsson,ab8500-pwm",
  992. .id = 1,
  993. },
  994. {
  995. .name = "ab8500-pwm",
  996. .of_compatible = "stericsson,ab8500-pwm",
  997. .id = 2,
  998. },
  999. {
  1000. .name = "ab8500-pwm",
  1001. .of_compatible = "stericsson,ab8500-pwm",
  1002. .id = 3,
  1003. },
  1004. {
  1005. .name = "ab8500-denc",
  1006. .of_compatible = "stericsson,ab8500-denc",
  1007. },
  1008. {
  1009. .name = "pinctrl-ab8500",
  1010. .of_compatible = "stericsson,ab8500-gpio",
  1011. },
  1012. {
  1013. .name = "abx500-temp",
  1014. .of_compatible = "stericsson,abx500-temp",
  1015. .num_resources = ARRAY_SIZE(ab8500_temp_resources),
  1016. .resources = ab8500_temp_resources,
  1017. },
  1018. {
  1019. .name = "ab8500-usb",
  1020. .of_compatible = "stericsson,ab8500-usb",
  1021. .num_resources = ARRAY_SIZE(ab8500_usb_resources),
  1022. .resources = ab8500_usb_resources,
  1023. },
  1024. {
  1025. .name = "ab8500-codec",
  1026. .of_compatible = "stericsson,ab8500-codec",
  1027. },
  1028. };
  1029. static const struct mfd_cell ab9540_devs[] = {
  1030. #ifdef CONFIG_DEBUG_FS
  1031. {
  1032. .name = "ab8500-debug",
  1033. .num_resources = ARRAY_SIZE(ab8500_debug_resources),
  1034. .resources = ab8500_debug_resources,
  1035. },
  1036. #endif
  1037. {
  1038. .name = "ab8500-sysctrl",
  1039. },
  1040. {
  1041. .name = "ab8500-ext-regulator",
  1042. },
  1043. {
  1044. .name = "ab8500-regulator",
  1045. },
  1046. {
  1047. .name = "abx500-clk",
  1048. .of_compatible = "stericsson,abx500-clk",
  1049. },
  1050. {
  1051. .name = "ab8500-gpadc",
  1052. .of_compatible = "stericsson,ab8500-gpadc",
  1053. .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
  1054. .resources = ab8500_gpadc_resources,
  1055. },
  1056. {
  1057. .name = "ab8500-rtc",
  1058. .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
  1059. .resources = ab8500_rtc_resources,
  1060. },
  1061. {
  1062. .name = "ab8500-acc-det",
  1063. .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
  1064. .resources = ab8500_av_acc_detect_resources,
  1065. },
  1066. {
  1067. .name = "ab8500-poweron-key",
  1068. .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
  1069. .resources = ab8500_poweronkey_db_resources,
  1070. },
  1071. {
  1072. .name = "ab8500-pwm",
  1073. .id = 1,
  1074. },
  1075. {
  1076. .name = "abx500-temp",
  1077. .num_resources = ARRAY_SIZE(ab8500_temp_resources),
  1078. .resources = ab8500_temp_resources,
  1079. },
  1080. {
  1081. .name = "pinctrl-ab9540",
  1082. .of_compatible = "stericsson,ab9540-gpio",
  1083. },
  1084. {
  1085. .name = "ab9540-usb",
  1086. .num_resources = ARRAY_SIZE(ab8500_usb_resources),
  1087. .resources = ab8500_usb_resources,
  1088. },
  1089. {
  1090. .name = "ab9540-codec",
  1091. },
  1092. {
  1093. .name = "ab-iddet",
  1094. .num_resources = ARRAY_SIZE(ab8505_iddet_resources),
  1095. .resources = ab8505_iddet_resources,
  1096. },
  1097. };
  1098. /* Device list for ab8505 */
  1099. static const struct mfd_cell ab8505_devs[] = {
  1100. #ifdef CONFIG_DEBUG_FS
  1101. {
  1102. .name = "ab8500-debug",
  1103. .num_resources = ARRAY_SIZE(ab8500_debug_resources),
  1104. .resources = ab8500_debug_resources,
  1105. },
  1106. #endif
  1107. {
  1108. .name = "ab8500-sysctrl",
  1109. },
  1110. {
  1111. .name = "ab8500-regulator",
  1112. },
  1113. {
  1114. .name = "abx500-clk",
  1115. .of_compatible = "stericsson,abx500-clk",
  1116. },
  1117. {
  1118. .name = "ab8500-gpadc",
  1119. .of_compatible = "stericsson,ab8500-gpadc",
  1120. .num_resources = ARRAY_SIZE(ab8505_gpadc_resources),
  1121. .resources = ab8505_gpadc_resources,
  1122. },
  1123. {
  1124. .name = "ab8500-rtc",
  1125. .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
  1126. .resources = ab8500_rtc_resources,
  1127. },
  1128. {
  1129. .name = "ab8500-acc-det",
  1130. .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
  1131. .resources = ab8500_av_acc_detect_resources,
  1132. },
  1133. {
  1134. .name = "ab8500-poweron-key",
  1135. .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
  1136. .resources = ab8500_poweronkey_db_resources,
  1137. },
  1138. {
  1139. .name = "ab8500-pwm",
  1140. .id = 1,
  1141. },
  1142. {
  1143. .name = "pinctrl-ab8505",
  1144. },
  1145. {
  1146. .name = "ab8500-usb",
  1147. .num_resources = ARRAY_SIZE(ab8500_usb_resources),
  1148. .resources = ab8500_usb_resources,
  1149. },
  1150. {
  1151. .name = "ab8500-codec",
  1152. },
  1153. {
  1154. .name = "ab-iddet",
  1155. .num_resources = ARRAY_SIZE(ab8505_iddet_resources),
  1156. .resources = ab8505_iddet_resources,
  1157. },
  1158. };
  1159. static const struct mfd_cell ab8540_devs[] = {
  1160. #ifdef CONFIG_DEBUG_FS
  1161. {
  1162. .name = "ab8500-debug",
  1163. .num_resources = ARRAY_SIZE(ab8500_debug_resources),
  1164. .resources = ab8500_debug_resources,
  1165. },
  1166. #endif
  1167. {
  1168. .name = "ab8500-sysctrl",
  1169. },
  1170. {
  1171. .name = "ab8500-ext-regulator",
  1172. },
  1173. {
  1174. .name = "ab8500-regulator",
  1175. },
  1176. {
  1177. .name = "abx500-clk",
  1178. .of_compatible = "stericsson,abx500-clk",
  1179. },
  1180. {
  1181. .name = "ab8500-gpadc",
  1182. .of_compatible = "stericsson,ab8500-gpadc",
  1183. .num_resources = ARRAY_SIZE(ab8505_gpadc_resources),
  1184. .resources = ab8505_gpadc_resources,
  1185. },
  1186. {
  1187. .name = "ab8500-acc-det",
  1188. .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
  1189. .resources = ab8500_av_acc_detect_resources,
  1190. },
  1191. {
  1192. .name = "ab8500-poweron-key",
  1193. .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
  1194. .resources = ab8500_poweronkey_db_resources,
  1195. },
  1196. {
  1197. .name = "ab8500-pwm",
  1198. .id = 1,
  1199. },
  1200. {
  1201. .name = "abx500-temp",
  1202. .num_resources = ARRAY_SIZE(ab8500_temp_resources),
  1203. .resources = ab8500_temp_resources,
  1204. },
  1205. {
  1206. .name = "pinctrl-ab8540",
  1207. },
  1208. {
  1209. .name = "ab8540-usb",
  1210. .num_resources = ARRAY_SIZE(ab8500_usb_resources),
  1211. .resources = ab8500_usb_resources,
  1212. },
  1213. {
  1214. .name = "ab8540-codec",
  1215. },
  1216. {
  1217. .name = "ab-iddet",
  1218. .num_resources = ARRAY_SIZE(ab8505_iddet_resources),
  1219. .resources = ab8505_iddet_resources,
  1220. },
  1221. };
  1222. static const struct mfd_cell ab8540_cut1_devs[] = {
  1223. {
  1224. .name = "ab8500-rtc",
  1225. .of_compatible = "stericsson,ab8500-rtc",
  1226. .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
  1227. .resources = ab8500_rtc_resources,
  1228. },
  1229. };
  1230. static const struct mfd_cell ab8540_cut2_devs[] = {
  1231. {
  1232. .name = "ab8540-rtc",
  1233. .of_compatible = "stericsson,ab8540-rtc",
  1234. .num_resources = ARRAY_SIZE(ab8540_rtc_resources),
  1235. .resources = ab8540_rtc_resources,
  1236. },
  1237. };
  1238. static ssize_t show_chip_id(struct device *dev,
  1239. struct device_attribute *attr, char *buf)
  1240. {
  1241. struct ab8500 *ab8500;
  1242. ab8500 = dev_get_drvdata(dev);
  1243. return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
  1244. }
  1245. /*
  1246. * ab8500 has switched off due to (SWITCH_OFF_STATUS):
  1247. * 0x01 Swoff bit programming
  1248. * 0x02 Thermal protection activation
  1249. * 0x04 Vbat lower then BattOk falling threshold
  1250. * 0x08 Watchdog expired
  1251. * 0x10 Non presence of 32kHz clock
  1252. * 0x20 Battery level lower than power on reset threshold
  1253. * 0x40 Power on key 1 pressed longer than 10 seconds
  1254. * 0x80 DB8500 thermal shutdown
  1255. */
  1256. static ssize_t show_switch_off_status(struct device *dev,
  1257. struct device_attribute *attr, char *buf)
  1258. {
  1259. int ret;
  1260. u8 value;
  1261. struct ab8500 *ab8500;
  1262. ab8500 = dev_get_drvdata(dev);
  1263. ret = get_register_interruptible(ab8500, AB8500_RTC,
  1264. AB8500_SWITCH_OFF_STATUS, &value);
  1265. if (ret < 0)
  1266. return ret;
  1267. return sprintf(buf, "%#x\n", value);
  1268. }
  1269. /* use mask and set to override the register turn_on_stat value */
  1270. void ab8500_override_turn_on_stat(u8 mask, u8 set)
  1271. {
  1272. spin_lock(&on_stat_lock);
  1273. turn_on_stat_mask = mask;
  1274. turn_on_stat_set = set;
  1275. spin_unlock(&on_stat_lock);
  1276. }
  1277. /*
  1278. * ab8500 has turned on due to (TURN_ON_STATUS):
  1279. * 0x01 PORnVbat
  1280. * 0x02 PonKey1dbF
  1281. * 0x04 PonKey2dbF
  1282. * 0x08 RTCAlarm
  1283. * 0x10 MainChDet
  1284. * 0x20 VbusDet
  1285. * 0x40 UsbIDDetect
  1286. * 0x80 Reserved
  1287. */
  1288. static ssize_t show_turn_on_status(struct device *dev,
  1289. struct device_attribute *attr, char *buf)
  1290. {
  1291. int ret;
  1292. u8 value;
  1293. struct ab8500 *ab8500;
  1294. ab8500 = dev_get_drvdata(dev);
  1295. ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
  1296. AB8500_TURN_ON_STATUS, &value);
  1297. if (ret < 0)
  1298. return ret;
  1299. /*
  1300. * In L9540, turn_on_status register is not updated correctly if
  1301. * the device is rebooted with AC/USB charger connected. Due to
  1302. * this, the device boots android instead of entering into charge
  1303. * only mode. Read the AC/USB status register to detect the charger
  1304. * presence and update the turn on status manually.
  1305. */
  1306. if (is_ab9540(ab8500)) {
  1307. spin_lock(&on_stat_lock);
  1308. value = (value & turn_on_stat_mask) | turn_on_stat_set;
  1309. spin_unlock(&on_stat_lock);
  1310. }
  1311. return sprintf(buf, "%#x\n", value);
  1312. }
  1313. static ssize_t show_turn_on_status_2(struct device *dev,
  1314. struct device_attribute *attr, char *buf)
  1315. {
  1316. int ret;
  1317. u8 value;
  1318. struct ab8500 *ab8500;
  1319. ab8500 = dev_get_drvdata(dev);
  1320. ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
  1321. AB8505_TURN_ON_STATUS_2, &value);
  1322. if (ret < 0)
  1323. return ret;
  1324. return sprintf(buf, "%#x\n", (value & 0x1));
  1325. }
  1326. static ssize_t show_ab9540_dbbrstn(struct device *dev,
  1327. struct device_attribute *attr, char *buf)
  1328. {
  1329. struct ab8500 *ab8500;
  1330. int ret;
  1331. u8 value;
  1332. ab8500 = dev_get_drvdata(dev);
  1333. ret = get_register_interruptible(ab8500, AB8500_REGU_CTRL2,
  1334. AB9540_MODEM_CTRL2_REG, &value);
  1335. if (ret < 0)
  1336. return ret;
  1337. return sprintf(buf, "%d\n",
  1338. (value & AB9540_MODEM_CTRL2_SWDBBRSTN_BIT) ? 1 : 0);
  1339. }
  1340. static ssize_t store_ab9540_dbbrstn(struct device *dev,
  1341. struct device_attribute *attr, const char *buf, size_t count)
  1342. {
  1343. struct ab8500 *ab8500;
  1344. int ret = count;
  1345. int err;
  1346. u8 bitvalues;
  1347. ab8500 = dev_get_drvdata(dev);
  1348. if (count > 0) {
  1349. switch (buf[0]) {
  1350. case '0':
  1351. bitvalues = 0;
  1352. break;
  1353. case '1':
  1354. bitvalues = AB9540_MODEM_CTRL2_SWDBBRSTN_BIT;
  1355. break;
  1356. default:
  1357. goto exit;
  1358. }
  1359. err = mask_and_set_register_interruptible(ab8500,
  1360. AB8500_REGU_CTRL2, AB9540_MODEM_CTRL2_REG,
  1361. AB9540_MODEM_CTRL2_SWDBBRSTN_BIT, bitvalues);
  1362. if (err)
  1363. dev_info(ab8500->dev,
  1364. "Failed to set DBBRSTN %c, err %#x\n",
  1365. buf[0], err);
  1366. }
  1367. exit:
  1368. return ret;
  1369. }
  1370. static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
  1371. static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
  1372. static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL);
  1373. static DEVICE_ATTR(turn_on_status_2, S_IRUGO, show_turn_on_status_2, NULL);
  1374. static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR,
  1375. show_ab9540_dbbrstn, store_ab9540_dbbrstn);
  1376. static struct attribute *ab8500_sysfs_entries[] = {
  1377. &dev_attr_chip_id.attr,
  1378. &dev_attr_switch_off_status.attr,
  1379. &dev_attr_turn_on_status.attr,
  1380. NULL,
  1381. };
  1382. static struct attribute *ab8505_sysfs_entries[] = {
  1383. &dev_attr_turn_on_status_2.attr,
  1384. NULL,
  1385. };
  1386. static struct attribute *ab9540_sysfs_entries[] = {
  1387. &dev_attr_chip_id.attr,
  1388. &dev_attr_switch_off_status.attr,
  1389. &dev_attr_turn_on_status.attr,
  1390. &dev_attr_dbbrstn.attr,
  1391. NULL,
  1392. };
  1393. static struct attribute_group ab8500_attr_group = {
  1394. .attrs = ab8500_sysfs_entries,
  1395. };
  1396. static struct attribute_group ab8505_attr_group = {
  1397. .attrs = ab8505_sysfs_entries,
  1398. };
  1399. static struct attribute_group ab9540_attr_group = {
  1400. .attrs = ab9540_sysfs_entries,
  1401. };
  1402. static int ab8500_probe(struct platform_device *pdev)
  1403. {
  1404. static const char *switch_off_status[] = {
  1405. "Swoff bit programming",
  1406. "Thermal protection activation",
  1407. "Vbat lower then BattOk falling threshold",
  1408. "Watchdog expired",
  1409. "Non presence of 32kHz clock",
  1410. "Battery level lower than power on reset threshold",
  1411. "Power on key 1 pressed longer than 10 seconds",
  1412. "DB8500 thermal shutdown"};
  1413. static const char *turn_on_status[] = {
  1414. "Battery rising (Vbat)",
  1415. "Power On Key 1 dbF",
  1416. "Power On Key 2 dbF",
  1417. "RTC Alarm",
  1418. "Main Charger Detect",
  1419. "Vbus Detect (USB)",
  1420. "USB ID Detect",
  1421. "UART Factory Mode Detect"};
  1422. struct ab8500_platform_data *plat = dev_get_platdata(&pdev->dev);
  1423. const struct platform_device_id *platid = platform_get_device_id(pdev);
  1424. enum ab8500_version version = AB8500_VERSION_UNDEFINED;
  1425. struct device_node *np = pdev->dev.of_node;
  1426. struct ab8500 *ab8500;
  1427. struct resource *resource;
  1428. int ret;
  1429. int i;
  1430. u8 value;
  1431. ab8500 = devm_kzalloc(&pdev->dev, sizeof(*ab8500), GFP_KERNEL);
  1432. if (!ab8500)
  1433. return -ENOMEM;
  1434. ab8500->dev = &pdev->dev;
  1435. resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1436. if (!resource) {
  1437. dev_err(&pdev->dev, "no IRQ resource\n");
  1438. return -ENODEV;
  1439. }
  1440. ab8500->irq = resource->start;
  1441. ab8500->read = ab8500_prcmu_read;
  1442. ab8500->write = ab8500_prcmu_write;
  1443. ab8500->write_masked = ab8500_prcmu_write_masked;
  1444. mutex_init(&ab8500->lock);
  1445. mutex_init(&ab8500->irq_lock);
  1446. atomic_set(&ab8500->transfer_ongoing, 0);
  1447. platform_set_drvdata(pdev, ab8500);
  1448. if (platid)
  1449. version = platid->driver_data;
  1450. if (version != AB8500_VERSION_UNDEFINED)
  1451. ab8500->version = version;
  1452. else {
  1453. ret = get_register_interruptible(ab8500, AB8500_MISC,
  1454. AB8500_IC_NAME_REG, &value);
  1455. if (ret < 0) {
  1456. dev_err(&pdev->dev, "could not probe HW\n");
  1457. return ret;
  1458. }
  1459. ab8500->version = value;
  1460. }
  1461. ret = get_register_interruptible(ab8500, AB8500_MISC,
  1462. AB8500_REV_REG, &value);
  1463. if (ret < 0)
  1464. return ret;
  1465. ab8500->chip_id = value;
  1466. dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n",
  1467. ab8500_version_str[ab8500->version],
  1468. ab8500->chip_id >> 4,
  1469. ab8500->chip_id & 0x0F);
  1470. /* Configure AB8540 */
  1471. if (is_ab8540(ab8500)) {
  1472. ab8500->mask_size = AB8540_NUM_IRQ_REGS;
  1473. ab8500->irq_reg_offset = ab8540_irq_regoffset;
  1474. ab8500->it_latchhier_num = AB8540_IT_LATCHHIER_NUM;
  1475. } /* Configure AB8500 or AB9540 IRQ */
  1476. else if (is_ab9540(ab8500) || is_ab8505(ab8500)) {
  1477. ab8500->mask_size = AB9540_NUM_IRQ_REGS;
  1478. ab8500->irq_reg_offset = ab9540_irq_regoffset;
  1479. ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM;
  1480. } else {
  1481. ab8500->mask_size = AB8500_NUM_IRQ_REGS;
  1482. ab8500->irq_reg_offset = ab8500_irq_regoffset;
  1483. ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM;
  1484. }
  1485. ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size,
  1486. GFP_KERNEL);
  1487. if (!ab8500->mask)
  1488. return -ENOMEM;
  1489. ab8500->oldmask = devm_kzalloc(&pdev->dev, ab8500->mask_size,
  1490. GFP_KERNEL);
  1491. if (!ab8500->oldmask)
  1492. return -ENOMEM;
  1493. /*
  1494. * ab8500 has switched off due to (SWITCH_OFF_STATUS):
  1495. * 0x01 Swoff bit programming
  1496. * 0x02 Thermal protection activation
  1497. * 0x04 Vbat lower then BattOk falling threshold
  1498. * 0x08 Watchdog expired
  1499. * 0x10 Non presence of 32kHz clock
  1500. * 0x20 Battery level lower than power on reset threshold
  1501. * 0x40 Power on key 1 pressed longer than 10 seconds
  1502. * 0x80 DB8500 thermal shutdown
  1503. */
  1504. ret = get_register_interruptible(ab8500, AB8500_RTC,
  1505. AB8500_SWITCH_OFF_STATUS, &value);
  1506. if (ret < 0)
  1507. return ret;
  1508. dev_info(ab8500->dev, "switch off cause(s) (%#x): ", value);
  1509. if (value) {
  1510. for (i = 0; i < ARRAY_SIZE(switch_off_status); i++) {
  1511. if (value & 1)
  1512. pr_cont(" \"%s\"", switch_off_status[i]);
  1513. value = value >> 1;
  1514. }
  1515. pr_cont("\n");
  1516. } else {
  1517. pr_cont(" None\n");
  1518. }
  1519. ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
  1520. AB8500_TURN_ON_STATUS, &value);
  1521. if (ret < 0)
  1522. return ret;
  1523. dev_info(ab8500->dev, "turn on reason(s) (%#x): ", value);
  1524. if (value) {
  1525. for (i = 0; i < ARRAY_SIZE(turn_on_status); i++) {
  1526. if (value & 1)
  1527. pr_cont("\"%s\" ", turn_on_status[i]);
  1528. value = value >> 1;
  1529. }
  1530. pr_cont("\n");
  1531. } else {
  1532. pr_cont("None\n");
  1533. }
  1534. if (plat && plat->init)
  1535. plat->init(ab8500);
  1536. if (is_ab9540(ab8500)) {
  1537. ret = get_register_interruptible(ab8500, AB8500_CHARGER,
  1538. AB8500_CH_USBCH_STAT1_REG, &value);
  1539. if (ret < 0)
  1540. return ret;
  1541. if ((value & VBUS_DET_DBNC1) && (value & VBUS_DET_DBNC100))
  1542. ab8500_override_turn_on_stat(~AB8500_POW_KEY_1_ON,
  1543. AB8500_VBUS_DET);
  1544. }
  1545. /* Clear and mask all interrupts */
  1546. for (i = 0; i < ab8500->mask_size; i++) {
  1547. /*
  1548. * Interrupt register 12 doesn't exist prior to AB8500 version
  1549. * 2.0
  1550. */
  1551. if (ab8500->irq_reg_offset[i] == 11 &&
  1552. is_ab8500_1p1_or_earlier(ab8500))
  1553. continue;
  1554. if (ab8500->irq_reg_offset[i] < 0)
  1555. continue;
  1556. get_register_interruptible(ab8500, AB8500_INTERRUPT,
  1557. AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i],
  1558. &value);
  1559. set_register_interruptible(ab8500, AB8500_INTERRUPT,
  1560. AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff);
  1561. }
  1562. ret = abx500_register_ops(ab8500->dev, &ab8500_ops);
  1563. if (ret)
  1564. return ret;
  1565. for (i = 0; i < ab8500->mask_size; i++)
  1566. ab8500->mask[i] = ab8500->oldmask[i] = 0xff;
  1567. ret = ab8500_irq_init(ab8500, np);
  1568. if (ret)
  1569. return ret;
  1570. ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL,
  1571. ab8500_hierarchical_irq,
  1572. IRQF_ONESHOT | IRQF_NO_SUSPEND,
  1573. "ab8500", ab8500);
  1574. if (ret)
  1575. return ret;
  1576. #ifdef CONFIG_DEBUG_FS
  1577. /* Pass to debugfs */
  1578. ab8500_debug_resources[0].start = ab8500->irq;
  1579. ab8500_debug_resources[0].end = ab8500->irq;
  1580. #endif
  1581. if (is_ab9540(ab8500))
  1582. ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs,
  1583. ARRAY_SIZE(ab9540_devs), NULL,
  1584. 0, ab8500->domain);
  1585. else if (is_ab8540(ab8500)) {
  1586. ret = mfd_add_devices(ab8500->dev, 0, ab8540_devs,
  1587. ARRAY_SIZE(ab8540_devs), NULL,
  1588. 0, ab8500->domain);
  1589. if (ret)
  1590. return ret;
  1591. if (is_ab8540_1p2_or_earlier(ab8500))
  1592. ret = mfd_add_devices(ab8500->dev, 0, ab8540_cut1_devs,
  1593. ARRAY_SIZE(ab8540_cut1_devs), NULL,
  1594. 0, ab8500->domain);
  1595. else /* ab8540 >= cut2 */
  1596. ret = mfd_add_devices(ab8500->dev, 0, ab8540_cut2_devs,
  1597. ARRAY_SIZE(ab8540_cut2_devs), NULL,
  1598. 0, ab8500->domain);
  1599. } else if (is_ab8505(ab8500))
  1600. ret = mfd_add_devices(ab8500->dev, 0, ab8505_devs,
  1601. ARRAY_SIZE(ab8505_devs), NULL,
  1602. 0, ab8500->domain);
  1603. else
  1604. ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
  1605. ARRAY_SIZE(ab8500_devs), NULL,
  1606. 0, ab8500->domain);
  1607. if (ret)
  1608. return ret;
  1609. if (!no_bm) {
  1610. /* Add battery management devices */
  1611. ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs,
  1612. ARRAY_SIZE(ab8500_bm_devs), NULL,
  1613. 0, ab8500->domain);
  1614. if (ret)
  1615. dev_err(ab8500->dev, "error adding bm devices\n");
  1616. }
  1617. if (((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
  1618. ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500))
  1619. ret = sysfs_create_group(&ab8500->dev->kobj,
  1620. &ab9540_attr_group);
  1621. else
  1622. ret = sysfs_create_group(&ab8500->dev->kobj,
  1623. &ab8500_attr_group);
  1624. if ((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
  1625. ab8500->chip_id >= AB8500_CUT2P0)
  1626. ret = sysfs_create_group(&ab8500->dev->kobj,
  1627. &ab8505_attr_group);
  1628. if (ret)
  1629. dev_err(ab8500->dev, "error creating sysfs entries\n");
  1630. return ret;
  1631. }
  1632. static int ab8500_remove(struct platform_device *pdev)
  1633. {
  1634. struct ab8500 *ab8500 = platform_get_drvdata(pdev);
  1635. if (((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
  1636. ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500))
  1637. sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group);
  1638. else
  1639. sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
  1640. if ((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
  1641. ab8500->chip_id >= AB8500_CUT2P0)
  1642. sysfs_remove_group(&ab8500->dev->kobj, &ab8505_attr_group);
  1643. mfd_remove_devices(ab8500->dev);
  1644. return 0;
  1645. }
  1646. static const struct platform_device_id ab8500_id[] = {
  1647. { "ab8500-core", AB8500_VERSION_AB8500 },
  1648. { "ab8505-i2c", AB8500_VERSION_AB8505 },
  1649. { "ab9540-i2c", AB8500_VERSION_AB9540 },
  1650. { "ab8540-i2c", AB8500_VERSION_AB8540 },
  1651. { }
  1652. };
  1653. static struct platform_driver ab8500_core_driver = {
  1654. .driver = {
  1655. .name = "ab8500-core",
  1656. },
  1657. .probe = ab8500_probe,
  1658. .remove = ab8500_remove,
  1659. .id_table = ab8500_id,
  1660. };
  1661. static int __init ab8500_core_init(void)
  1662. {
  1663. return platform_driver_register(&ab8500_core_driver);
  1664. }
  1665. static void __exit ab8500_core_exit(void)
  1666. {
  1667. platform_driver_unregister(&ab8500_core_driver);
  1668. }
  1669. core_initcall(ab8500_core_init);
  1670. module_exit(ab8500_core_exit);
  1671. MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent");
  1672. MODULE_DESCRIPTION("AB8500 MFD core");
  1673. MODULE_LICENSE("GPL v2");