ab8500-core.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2010
  3. *
  4. * License Terms: GNU General Public License v2
  5. * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
  6. * Author: Rabin Vincent <rabin.vincent@stericsson.com>
  7. * Author: Mattias Wallin <mattias.wallin@stericsson.com>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/slab.h>
  11. #include <linux/init.h>
  12. #include <linux/irq.h>
  13. #include <linux/delay.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/module.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/mfd/core.h>
  18. #include <linux/mfd/abx500.h>
  19. #include <linux/mfd/abx500/ab8500.h>
  20. #include <linux/mfd/dbx500-prcmu.h>
  21. #include <linux/regulator/ab8500.h>
  22. #include <linux/of.h>
  23. #include <linux/of_device.h>
  24. /*
  25. * Interrupt register offsets
  26. * Bank : 0x0E
  27. */
  28. #define AB8500_IT_SOURCE1_REG 0x00
  29. #define AB8500_IT_SOURCE2_REG 0x01
  30. #define AB8500_IT_SOURCE3_REG 0x02
  31. #define AB8500_IT_SOURCE4_REG 0x03
  32. #define AB8500_IT_SOURCE5_REG 0x04
  33. #define AB8500_IT_SOURCE6_REG 0x05
  34. #define AB8500_IT_SOURCE7_REG 0x06
  35. #define AB8500_IT_SOURCE8_REG 0x07
  36. #define AB9540_IT_SOURCE13_REG 0x0C
  37. #define AB8500_IT_SOURCE19_REG 0x12
  38. #define AB8500_IT_SOURCE20_REG 0x13
  39. #define AB8500_IT_SOURCE21_REG 0x14
  40. #define AB8500_IT_SOURCE22_REG 0x15
  41. #define AB8500_IT_SOURCE23_REG 0x16
  42. #define AB8500_IT_SOURCE24_REG 0x17
  43. /*
  44. * latch registers
  45. */
  46. #define AB8500_IT_LATCH1_REG 0x20
  47. #define AB8500_IT_LATCH2_REG 0x21
  48. #define AB8500_IT_LATCH3_REG 0x22
  49. #define AB8500_IT_LATCH4_REG 0x23
  50. #define AB8500_IT_LATCH5_REG 0x24
  51. #define AB8500_IT_LATCH6_REG 0x25
  52. #define AB8500_IT_LATCH7_REG 0x26
  53. #define AB8500_IT_LATCH8_REG 0x27
  54. #define AB8500_IT_LATCH9_REG 0x28
  55. #define AB8500_IT_LATCH10_REG 0x29
  56. #define AB8500_IT_LATCH12_REG 0x2B
  57. #define AB9540_IT_LATCH13_REG 0x2C
  58. #define AB8500_IT_LATCH19_REG 0x32
  59. #define AB8500_IT_LATCH20_REG 0x33
  60. #define AB8500_IT_LATCH21_REG 0x34
  61. #define AB8500_IT_LATCH22_REG 0x35
  62. #define AB8500_IT_LATCH23_REG 0x36
  63. #define AB8500_IT_LATCH24_REG 0x37
  64. /*
  65. * mask registers
  66. */
  67. #define AB8500_IT_MASK1_REG 0x40
  68. #define AB8500_IT_MASK2_REG 0x41
  69. #define AB8500_IT_MASK3_REG 0x42
  70. #define AB8500_IT_MASK4_REG 0x43
  71. #define AB8500_IT_MASK5_REG 0x44
  72. #define AB8500_IT_MASK6_REG 0x45
  73. #define AB8500_IT_MASK7_REG 0x46
  74. #define AB8500_IT_MASK8_REG 0x47
  75. #define AB8500_IT_MASK9_REG 0x48
  76. #define AB8500_IT_MASK10_REG 0x49
  77. #define AB8500_IT_MASK11_REG 0x4A
  78. #define AB8500_IT_MASK12_REG 0x4B
  79. #define AB8500_IT_MASK13_REG 0x4C
  80. #define AB8500_IT_MASK14_REG 0x4D
  81. #define AB8500_IT_MASK15_REG 0x4E
  82. #define AB8500_IT_MASK16_REG 0x4F
  83. #define AB8500_IT_MASK17_REG 0x50
  84. #define AB8500_IT_MASK18_REG 0x51
  85. #define AB8500_IT_MASK19_REG 0x52
  86. #define AB8500_IT_MASK20_REG 0x53
  87. #define AB8500_IT_MASK21_REG 0x54
  88. #define AB8500_IT_MASK22_REG 0x55
  89. #define AB8500_IT_MASK23_REG 0x56
  90. #define AB8500_IT_MASK24_REG 0x57
  91. /*
  92. * latch hierarchy registers
  93. */
  94. #define AB8500_IT_LATCHHIER1_REG 0x60
  95. #define AB8500_IT_LATCHHIER2_REG 0x61
  96. #define AB8500_IT_LATCHHIER3_REG 0x62
  97. #define AB8500_IT_LATCHHIER_NUM 3
  98. #define AB8500_REV_REG 0x80
  99. #define AB8500_IC_NAME_REG 0x82
  100. #define AB8500_SWITCH_OFF_STATUS 0x00
  101. #define AB8500_TURN_ON_STATUS 0x00
  102. static bool no_bm; /* No battery management */
  103. module_param(no_bm, bool, S_IRUGO);
  104. #define AB9540_MODEM_CTRL2_REG 0x23
  105. #define AB9540_MODEM_CTRL2_SWDBBRSTN_BIT BIT(2)
  106. /*
  107. * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
  108. * numbers are indexed into this array with (num / 8). The interupts are
  109. * defined in linux/mfd/ab8500.h
  110. *
  111. * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at
  112. * offset 0.
  113. */
  114. /* AB8500 support */
  115. static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
  116. 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
  117. };
  118. /* AB9540 support */
  119. static const int ab9540_irq_regoffset[AB9540_NUM_IRQ_REGS] = {
  120. 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 12, 13, 24,
  121. };
  122. static const char ab8500_version_str[][7] = {
  123. [AB8500_VERSION_AB8500] = "AB8500",
  124. [AB8500_VERSION_AB8505] = "AB8505",
  125. [AB8500_VERSION_AB9540] = "AB9540",
  126. [AB8500_VERSION_AB8540] = "AB8540",
  127. };
  128. static int ab8500_i2c_write(struct ab8500 *ab8500, u16 addr, u8 data)
  129. {
  130. int ret;
  131. ret = prcmu_abb_write((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1);
  132. if (ret < 0)
  133. dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
  134. return ret;
  135. }
  136. static int ab8500_i2c_write_masked(struct ab8500 *ab8500, u16 addr, u8 mask,
  137. u8 data)
  138. {
  139. int ret;
  140. ret = prcmu_abb_write_masked((u8)(addr >> 8), (u8)(addr & 0xFF), &data,
  141. &mask, 1);
  142. if (ret < 0)
  143. dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
  144. return ret;
  145. }
  146. static int ab8500_i2c_read(struct ab8500 *ab8500, u16 addr)
  147. {
  148. int ret;
  149. u8 data;
  150. ret = prcmu_abb_read((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1);
  151. if (ret < 0) {
  152. dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
  153. return ret;
  154. }
  155. return (int)data;
  156. }
  157. static int ab8500_get_chip_id(struct device *dev)
  158. {
  159. struct ab8500 *ab8500;
  160. if (!dev)
  161. return -EINVAL;
  162. ab8500 = dev_get_drvdata(dev->parent);
  163. return ab8500 ? (int)ab8500->chip_id : -EINVAL;
  164. }
  165. static int set_register_interruptible(struct ab8500 *ab8500, u8 bank,
  166. u8 reg, u8 data)
  167. {
  168. int ret;
  169. /*
  170. * Put the u8 bank and u8 register together into a an u16.
  171. * The bank on higher 8 bits and register in lower 8 bits.
  172. * */
  173. u16 addr = ((u16)bank) << 8 | reg;
  174. dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data);
  175. mutex_lock(&ab8500->lock);
  176. ret = ab8500->write(ab8500, addr, data);
  177. if (ret < 0)
  178. dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
  179. addr, ret);
  180. mutex_unlock(&ab8500->lock);
  181. return ret;
  182. }
  183. static int ab8500_set_register(struct device *dev, u8 bank,
  184. u8 reg, u8 value)
  185. {
  186. int ret;
  187. struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
  188. atomic_inc(&ab8500->transfer_ongoing);
  189. ret = set_register_interruptible(ab8500, bank, reg, value);
  190. atomic_dec(&ab8500->transfer_ongoing);
  191. return ret;
  192. }
  193. static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
  194. u8 reg, u8 *value)
  195. {
  196. int ret;
  197. /* put the u8 bank and u8 reg together into a an u16.
  198. * bank on higher 8 bits and reg in lower */
  199. u16 addr = ((u16)bank) << 8 | reg;
  200. mutex_lock(&ab8500->lock);
  201. ret = ab8500->read(ab8500, addr);
  202. if (ret < 0)
  203. dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
  204. addr, ret);
  205. else
  206. *value = ret;
  207. mutex_unlock(&ab8500->lock);
  208. dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
  209. return ret;
  210. }
  211. static int ab8500_get_register(struct device *dev, u8 bank,
  212. u8 reg, u8 *value)
  213. {
  214. int ret;
  215. struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
  216. atomic_inc(&ab8500->transfer_ongoing);
  217. ret = get_register_interruptible(ab8500, bank, reg, value);
  218. atomic_dec(&ab8500->transfer_ongoing);
  219. return ret;
  220. }
  221. static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank,
  222. u8 reg, u8 bitmask, u8 bitvalues)
  223. {
  224. int ret;
  225. /* put the u8 bank and u8 reg together into a an u16.
  226. * bank on higher 8 bits and reg in lower */
  227. u16 addr = ((u16)bank) << 8 | reg;
  228. mutex_lock(&ab8500->lock);
  229. if (ab8500->write_masked == NULL) {
  230. u8 data;
  231. ret = ab8500->read(ab8500, addr);
  232. if (ret < 0) {
  233. dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
  234. addr, ret);
  235. goto out;
  236. }
  237. data = (u8)ret;
  238. data = (~bitmask & data) | (bitmask & bitvalues);
  239. ret = ab8500->write(ab8500, addr, data);
  240. if (ret < 0)
  241. dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
  242. addr, ret);
  243. dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr,
  244. data);
  245. goto out;
  246. }
  247. ret = ab8500->write_masked(ab8500, addr, bitmask, bitvalues);
  248. if (ret < 0)
  249. dev_err(ab8500->dev, "failed to modify reg %#x: %d\n", addr,
  250. ret);
  251. out:
  252. mutex_unlock(&ab8500->lock);
  253. return ret;
  254. }
  255. static int ab8500_mask_and_set_register(struct device *dev,
  256. u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
  257. {
  258. int ret;
  259. struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
  260. atomic_inc(&ab8500->transfer_ongoing);
  261. ret= mask_and_set_register_interruptible(ab8500, bank, reg,
  262. bitmask, bitvalues);
  263. atomic_dec(&ab8500->transfer_ongoing);
  264. return ret;
  265. }
  266. static struct abx500_ops ab8500_ops = {
  267. .get_chip_id = ab8500_get_chip_id,
  268. .get_register = ab8500_get_register,
  269. .set_register = ab8500_set_register,
  270. .get_register_page = NULL,
  271. .set_register_page = NULL,
  272. .mask_and_set_register = ab8500_mask_and_set_register,
  273. .event_registers_startup_state_get = NULL,
  274. .startup_irq_enabled = NULL,
  275. };
  276. static void ab8500_irq_lock(struct irq_data *data)
  277. {
  278. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  279. mutex_lock(&ab8500->irq_lock);
  280. atomic_inc(&ab8500->transfer_ongoing);
  281. }
  282. static void ab8500_irq_sync_unlock(struct irq_data *data)
  283. {
  284. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  285. int i;
  286. for (i = 0; i < ab8500->mask_size; i++) {
  287. u8 old = ab8500->oldmask[i];
  288. u8 new = ab8500->mask[i];
  289. int reg;
  290. if (new == old)
  291. continue;
  292. /*
  293. * Interrupt register 12 doesn't exist prior to AB8500 version
  294. * 2.0
  295. */
  296. if (ab8500->irq_reg_offset[i] == 11 &&
  297. is_ab8500_1p1_or_earlier(ab8500))
  298. continue;
  299. ab8500->oldmask[i] = new;
  300. reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i];
  301. set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new);
  302. }
  303. atomic_dec(&ab8500->transfer_ongoing);
  304. mutex_unlock(&ab8500->irq_lock);
  305. }
  306. static void ab8500_irq_mask(struct irq_data *data)
  307. {
  308. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  309. int offset = data->irq - ab8500->irq_base;
  310. int index = offset / 8;
  311. int mask = 1 << (offset % 8);
  312. ab8500->mask[index] |= mask;
  313. }
  314. static void ab8500_irq_unmask(struct irq_data *data)
  315. {
  316. struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
  317. int offset = data->irq - ab8500->irq_base;
  318. int index = offset / 8;
  319. int mask = 1 << (offset % 8);
  320. ab8500->mask[index] &= ~mask;
  321. }
  322. static struct irq_chip ab8500_irq_chip = {
  323. .name = "ab8500",
  324. .irq_bus_lock = ab8500_irq_lock,
  325. .irq_bus_sync_unlock = ab8500_irq_sync_unlock,
  326. .irq_mask = ab8500_irq_mask,
  327. .irq_disable = ab8500_irq_mask,
  328. .irq_unmask = ab8500_irq_unmask,
  329. };
  330. static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500,
  331. int latch_offset, u8 latch_val)
  332. {
  333. int int_bit = __ffs(latch_val);
  334. int line, i;
  335. do {
  336. int_bit = __ffs(latch_val);
  337. for (i = 0; i < ab8500->mask_size; i++)
  338. if (ab8500->irq_reg_offset[i] == latch_offset)
  339. break;
  340. if (i >= ab8500->mask_size) {
  341. dev_err(ab8500->dev, "Register offset 0x%2x not declared\n",
  342. latch_offset);
  343. return -ENXIO;
  344. }
  345. line = (i << 3) + int_bit;
  346. latch_val &= ~(1 << int_bit);
  347. handle_nested_irq(ab8500->irq_base + line);
  348. } while (latch_val);
  349. return 0;
  350. }
  351. static int ab8500_handle_hierarchical_latch(struct ab8500 *ab8500,
  352. int hier_offset, u8 hier_val)
  353. {
  354. int latch_bit, status;
  355. u8 latch_offset, latch_val;
  356. do {
  357. latch_bit = __ffs(hier_val);
  358. latch_offset = (hier_offset << 3) + latch_bit;
  359. /* Fix inconsistent ITFromLatch25 bit mapping... */
  360. if (unlikely(latch_offset == 17))
  361. latch_offset = 24;
  362. status = get_register_interruptible(ab8500,
  363. AB8500_INTERRUPT,
  364. AB8500_IT_LATCH1_REG + latch_offset,
  365. &latch_val);
  366. if (status < 0 || latch_val == 0)
  367. goto discard;
  368. status = ab8500_handle_hierarchical_line(ab8500,
  369. latch_offset, latch_val);
  370. if (status < 0)
  371. return status;
  372. discard:
  373. hier_val &= ~(1 << latch_bit);
  374. } while (hier_val);
  375. return 0;
  376. }
  377. static irqreturn_t ab8500_hierarchical_irq(int irq, void *dev)
  378. {
  379. struct ab8500 *ab8500 = dev;
  380. u8 i;
  381. dev_vdbg(ab8500->dev, "interrupt\n");
  382. /* Hierarchical interrupt version */
  383. for (i = 0; i < AB8500_IT_LATCHHIER_NUM; i++) {
  384. int status;
  385. u8 hier_val;
  386. status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
  387. AB8500_IT_LATCHHIER1_REG + i, &hier_val);
  388. if (status < 0 || hier_val == 0)
  389. continue;
  390. status = ab8500_handle_hierarchical_latch(ab8500, i, hier_val);
  391. if (status < 0)
  392. break;
  393. }
  394. return IRQ_HANDLED;
  395. }
  396. static irqreturn_t ab8500_irq(int irq, void *dev)
  397. {
  398. struct ab8500 *ab8500 = dev;
  399. int i;
  400. dev_vdbg(ab8500->dev, "interrupt\n");
  401. atomic_inc(&ab8500->transfer_ongoing);
  402. for (i = 0; i < ab8500->mask_size; i++) {
  403. int regoffset = ab8500->irq_reg_offset[i];
  404. int status;
  405. u8 value;
  406. /*
  407. * Interrupt register 12 doesn't exist prior to AB8500 version
  408. * 2.0
  409. */
  410. if (regoffset == 11 && is_ab8500_1p1_or_earlier(ab8500))
  411. continue;
  412. status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
  413. AB8500_IT_LATCH1_REG + regoffset, &value);
  414. if (status < 0 || value == 0)
  415. continue;
  416. do {
  417. int bit = __ffs(value);
  418. int line = i * 8 + bit;
  419. handle_nested_irq(ab8500->irq_base + line);
  420. value &= ~(1 << bit);
  421. } while (value);
  422. }
  423. atomic_dec(&ab8500->transfer_ongoing);
  424. return IRQ_HANDLED;
  425. }
  426. static int ab8500_irq_init(struct ab8500 *ab8500)
  427. {
  428. int base = ab8500->irq_base;
  429. int irq;
  430. int num_irqs;
  431. if (is_ab9540(ab8500))
  432. num_irqs = AB9540_NR_IRQS;
  433. else if (is_ab8505(ab8500))
  434. num_irqs = AB8505_NR_IRQS;
  435. else
  436. num_irqs = AB8500_NR_IRQS;
  437. for (irq = base; irq < base + num_irqs; irq++) {
  438. irq_set_chip_data(irq, ab8500);
  439. irq_set_chip_and_handler(irq, &ab8500_irq_chip,
  440. handle_simple_irq);
  441. irq_set_nested_thread(irq, 1);
  442. #ifdef CONFIG_ARM
  443. set_irq_flags(irq, IRQF_VALID);
  444. #else
  445. irq_set_noprobe(irq);
  446. #endif
  447. }
  448. return 0;
  449. }
  450. static void ab8500_irq_remove(struct ab8500 *ab8500)
  451. {
  452. int base = ab8500->irq_base;
  453. int irq;
  454. int num_irqs;
  455. if (is_ab9540(ab8500))
  456. num_irqs = AB9540_NR_IRQS;
  457. else if (is_ab8505(ab8500))
  458. num_irqs = AB8505_NR_IRQS;
  459. else
  460. num_irqs = AB8500_NR_IRQS;
  461. for (irq = base; irq < base + num_irqs; irq++) {
  462. #ifdef CONFIG_ARM
  463. set_irq_flags(irq, 0);
  464. #endif
  465. irq_set_chip_and_handler(irq, NULL, NULL);
  466. irq_set_chip_data(irq, NULL);
  467. }
  468. }
  469. int ab8500_suspend(struct ab8500 *ab8500)
  470. {
  471. if (atomic_read(&ab8500->transfer_ongoing))
  472. return -EINVAL;
  473. else
  474. return 0;
  475. }
  476. /* AB8500 GPIO Resources */
  477. static struct resource __devinitdata ab8500_gpio_resources[] = {
  478. {
  479. .name = "GPIO_INT6",
  480. .start = AB8500_INT_GPIO6R,
  481. .end = AB8500_INT_GPIO41F,
  482. .flags = IORESOURCE_IRQ,
  483. }
  484. };
  485. /* AB9540 GPIO Resources */
  486. static struct resource __devinitdata ab9540_gpio_resources[] = {
  487. {
  488. .name = "GPIO_INT6",
  489. .start = AB8500_INT_GPIO6R,
  490. .end = AB8500_INT_GPIO41F,
  491. .flags = IORESOURCE_IRQ,
  492. },
  493. {
  494. .name = "GPIO_INT14",
  495. .start = AB9540_INT_GPIO50R,
  496. .end = AB9540_INT_GPIO54R,
  497. .flags = IORESOURCE_IRQ,
  498. },
  499. {
  500. .name = "GPIO_INT15",
  501. .start = AB9540_INT_GPIO50F,
  502. .end = AB9540_INT_GPIO54F,
  503. .flags = IORESOURCE_IRQ,
  504. }
  505. };
  506. static struct resource __devinitdata ab8500_gpadc_resources[] = {
  507. {
  508. .name = "HW_CONV_END",
  509. .start = AB8500_INT_GP_HW_ADC_CONV_END,
  510. .end = AB8500_INT_GP_HW_ADC_CONV_END,
  511. .flags = IORESOURCE_IRQ,
  512. },
  513. {
  514. .name = "SW_CONV_END",
  515. .start = AB8500_INT_GP_SW_ADC_CONV_END,
  516. .end = AB8500_INT_GP_SW_ADC_CONV_END,
  517. .flags = IORESOURCE_IRQ,
  518. },
  519. };
  520. static struct resource __devinitdata ab8500_rtc_resources[] = {
  521. {
  522. .name = "60S",
  523. .start = AB8500_INT_RTC_60S,
  524. .end = AB8500_INT_RTC_60S,
  525. .flags = IORESOURCE_IRQ,
  526. },
  527. {
  528. .name = "ALARM",
  529. .start = AB8500_INT_RTC_ALARM,
  530. .end = AB8500_INT_RTC_ALARM,
  531. .flags = IORESOURCE_IRQ,
  532. },
  533. };
  534. static struct resource __devinitdata ab8500_poweronkey_db_resources[] = {
  535. {
  536. .name = "ONKEY_DBF",
  537. .start = AB8500_INT_PON_KEY1DB_F,
  538. .end = AB8500_INT_PON_KEY1DB_F,
  539. .flags = IORESOURCE_IRQ,
  540. },
  541. {
  542. .name = "ONKEY_DBR",
  543. .start = AB8500_INT_PON_KEY1DB_R,
  544. .end = AB8500_INT_PON_KEY1DB_R,
  545. .flags = IORESOURCE_IRQ,
  546. },
  547. };
  548. static struct resource __devinitdata ab8500_av_acc_detect_resources[] = {
  549. {
  550. .name = "ACC_DETECT_1DB_F",
  551. .start = AB8500_INT_ACC_DETECT_1DB_F,
  552. .end = AB8500_INT_ACC_DETECT_1DB_F,
  553. .flags = IORESOURCE_IRQ,
  554. },
  555. {
  556. .name = "ACC_DETECT_1DB_R",
  557. .start = AB8500_INT_ACC_DETECT_1DB_R,
  558. .end = AB8500_INT_ACC_DETECT_1DB_R,
  559. .flags = IORESOURCE_IRQ,
  560. },
  561. {
  562. .name = "ACC_DETECT_21DB_F",
  563. .start = AB8500_INT_ACC_DETECT_21DB_F,
  564. .end = AB8500_INT_ACC_DETECT_21DB_F,
  565. .flags = IORESOURCE_IRQ,
  566. },
  567. {
  568. .name = "ACC_DETECT_21DB_R",
  569. .start = AB8500_INT_ACC_DETECT_21DB_R,
  570. .end = AB8500_INT_ACC_DETECT_21DB_R,
  571. .flags = IORESOURCE_IRQ,
  572. },
  573. {
  574. .name = "ACC_DETECT_22DB_F",
  575. .start = AB8500_INT_ACC_DETECT_22DB_F,
  576. .end = AB8500_INT_ACC_DETECT_22DB_F,
  577. .flags = IORESOURCE_IRQ,
  578. },
  579. {
  580. .name = "ACC_DETECT_22DB_R",
  581. .start = AB8500_INT_ACC_DETECT_22DB_R,
  582. .end = AB8500_INT_ACC_DETECT_22DB_R,
  583. .flags = IORESOURCE_IRQ,
  584. },
  585. };
  586. static struct resource __devinitdata ab8500_charger_resources[] = {
  587. {
  588. .name = "MAIN_CH_UNPLUG_DET",
  589. .start = AB8500_INT_MAIN_CH_UNPLUG_DET,
  590. .end = AB8500_INT_MAIN_CH_UNPLUG_DET,
  591. .flags = IORESOURCE_IRQ,
  592. },
  593. {
  594. .name = "MAIN_CHARGE_PLUG_DET",
  595. .start = AB8500_INT_MAIN_CH_PLUG_DET,
  596. .end = AB8500_INT_MAIN_CH_PLUG_DET,
  597. .flags = IORESOURCE_IRQ,
  598. },
  599. {
  600. .name = "VBUS_DET_R",
  601. .start = AB8500_INT_VBUS_DET_R,
  602. .end = AB8500_INT_VBUS_DET_R,
  603. .flags = IORESOURCE_IRQ,
  604. },
  605. {
  606. .name = "VBUS_DET_F",
  607. .start = AB8500_INT_VBUS_DET_F,
  608. .end = AB8500_INT_VBUS_DET_F,
  609. .flags = IORESOURCE_IRQ,
  610. },
  611. {
  612. .name = "USB_LINK_STATUS",
  613. .start = AB8500_INT_USB_LINK_STATUS,
  614. .end = AB8500_INT_USB_LINK_STATUS,
  615. .flags = IORESOURCE_IRQ,
  616. },
  617. {
  618. .name = "VBUS_OVV",
  619. .start = AB8500_INT_VBUS_OVV,
  620. .end = AB8500_INT_VBUS_OVV,
  621. .flags = IORESOURCE_IRQ,
  622. },
  623. {
  624. .name = "USB_CH_TH_PROT_R",
  625. .start = AB8500_INT_USB_CH_TH_PROT_R,
  626. .end = AB8500_INT_USB_CH_TH_PROT_R,
  627. .flags = IORESOURCE_IRQ,
  628. },
  629. {
  630. .name = "USB_CH_TH_PROT_F",
  631. .start = AB8500_INT_USB_CH_TH_PROT_F,
  632. .end = AB8500_INT_USB_CH_TH_PROT_F,
  633. .flags = IORESOURCE_IRQ,
  634. },
  635. {
  636. .name = "MAIN_EXT_CH_NOT_OK",
  637. .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
  638. .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
  639. .flags = IORESOURCE_IRQ,
  640. },
  641. {
  642. .name = "MAIN_CH_TH_PROT_R",
  643. .start = AB8500_INT_MAIN_CH_TH_PROT_R,
  644. .end = AB8500_INT_MAIN_CH_TH_PROT_R,
  645. .flags = IORESOURCE_IRQ,
  646. },
  647. {
  648. .name = "MAIN_CH_TH_PROT_F",
  649. .start = AB8500_INT_MAIN_CH_TH_PROT_F,
  650. .end = AB8500_INT_MAIN_CH_TH_PROT_F,
  651. .flags = IORESOURCE_IRQ,
  652. },
  653. {
  654. .name = "USB_CHARGER_NOT_OKR",
  655. .start = AB8500_INT_USB_CHARGER_NOT_OKR,
  656. .end = AB8500_INT_USB_CHARGER_NOT_OKR,
  657. .flags = IORESOURCE_IRQ,
  658. },
  659. {
  660. .name = "CH_WD_EXP",
  661. .start = AB8500_INT_CH_WD_EXP,
  662. .end = AB8500_INT_CH_WD_EXP,
  663. .flags = IORESOURCE_IRQ,
  664. },
  665. };
  666. static struct resource __devinitdata ab8500_btemp_resources[] = {
  667. {
  668. .name = "BAT_CTRL_INDB",
  669. .start = AB8500_INT_BAT_CTRL_INDB,
  670. .end = AB8500_INT_BAT_CTRL_INDB,
  671. .flags = IORESOURCE_IRQ,
  672. },
  673. {
  674. .name = "BTEMP_LOW",
  675. .start = AB8500_INT_BTEMP_LOW,
  676. .end = AB8500_INT_BTEMP_LOW,
  677. .flags = IORESOURCE_IRQ,
  678. },
  679. {
  680. .name = "BTEMP_HIGH",
  681. .start = AB8500_INT_BTEMP_HIGH,
  682. .end = AB8500_INT_BTEMP_HIGH,
  683. .flags = IORESOURCE_IRQ,
  684. },
  685. {
  686. .name = "BTEMP_LOW_MEDIUM",
  687. .start = AB8500_INT_BTEMP_LOW_MEDIUM,
  688. .end = AB8500_INT_BTEMP_LOW_MEDIUM,
  689. .flags = IORESOURCE_IRQ,
  690. },
  691. {
  692. .name = "BTEMP_MEDIUM_HIGH",
  693. .start = AB8500_INT_BTEMP_MEDIUM_HIGH,
  694. .end = AB8500_INT_BTEMP_MEDIUM_HIGH,
  695. .flags = IORESOURCE_IRQ,
  696. },
  697. };
  698. static struct resource __devinitdata ab8500_fg_resources[] = {
  699. {
  700. .name = "NCONV_ACCU",
  701. .start = AB8500_INT_CCN_CONV_ACC,
  702. .end = AB8500_INT_CCN_CONV_ACC,
  703. .flags = IORESOURCE_IRQ,
  704. },
  705. {
  706. .name = "BATT_OVV",
  707. .start = AB8500_INT_BATT_OVV,
  708. .end = AB8500_INT_BATT_OVV,
  709. .flags = IORESOURCE_IRQ,
  710. },
  711. {
  712. .name = "LOW_BAT_F",
  713. .start = AB8500_INT_LOW_BAT_F,
  714. .end = AB8500_INT_LOW_BAT_F,
  715. .flags = IORESOURCE_IRQ,
  716. },
  717. {
  718. .name = "LOW_BAT_R",
  719. .start = AB8500_INT_LOW_BAT_R,
  720. .end = AB8500_INT_LOW_BAT_R,
  721. .flags = IORESOURCE_IRQ,
  722. },
  723. {
  724. .name = "CC_INT_CALIB",
  725. .start = AB8500_INT_CC_INT_CALIB,
  726. .end = AB8500_INT_CC_INT_CALIB,
  727. .flags = IORESOURCE_IRQ,
  728. },
  729. {
  730. .name = "CCEOC",
  731. .start = AB8500_INT_CCEOC,
  732. .end = AB8500_INT_CCEOC,
  733. .flags = IORESOURCE_IRQ,
  734. },
  735. };
  736. static struct resource __devinitdata ab8500_chargalg_resources[] = {};
  737. #ifdef CONFIG_DEBUG_FS
  738. static struct resource __devinitdata ab8500_debug_resources[] = {
  739. {
  740. .name = "IRQ_FIRST",
  741. .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
  742. .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
  743. .flags = IORESOURCE_IRQ,
  744. },
  745. {
  746. .name = "IRQ_LAST",
  747. .start = AB8500_INT_XTAL32K_KO,
  748. .end = AB8500_INT_XTAL32K_KO,
  749. .flags = IORESOURCE_IRQ,
  750. },
  751. };
  752. #endif
  753. static struct resource __devinitdata ab8500_usb_resources[] = {
  754. {
  755. .name = "ID_WAKEUP_R",
  756. .start = AB8500_INT_ID_WAKEUP_R,
  757. .end = AB8500_INT_ID_WAKEUP_R,
  758. .flags = IORESOURCE_IRQ,
  759. },
  760. {
  761. .name = "ID_WAKEUP_F",
  762. .start = AB8500_INT_ID_WAKEUP_F,
  763. .end = AB8500_INT_ID_WAKEUP_F,
  764. .flags = IORESOURCE_IRQ,
  765. },
  766. {
  767. .name = "VBUS_DET_F",
  768. .start = AB8500_INT_VBUS_DET_F,
  769. .end = AB8500_INT_VBUS_DET_F,
  770. .flags = IORESOURCE_IRQ,
  771. },
  772. {
  773. .name = "VBUS_DET_R",
  774. .start = AB8500_INT_VBUS_DET_R,
  775. .end = AB8500_INT_VBUS_DET_R,
  776. .flags = IORESOURCE_IRQ,
  777. },
  778. {
  779. .name = "USB_LINK_STATUS",
  780. .start = AB8500_INT_USB_LINK_STATUS,
  781. .end = AB8500_INT_USB_LINK_STATUS,
  782. .flags = IORESOURCE_IRQ,
  783. },
  784. {
  785. .name = "USB_ADP_PROBE_PLUG",
  786. .start = AB8500_INT_ADP_PROBE_PLUG,
  787. .end = AB8500_INT_ADP_PROBE_PLUG,
  788. .flags = IORESOURCE_IRQ,
  789. },
  790. {
  791. .name = "USB_ADP_PROBE_UNPLUG",
  792. .start = AB8500_INT_ADP_PROBE_UNPLUG,
  793. .end = AB8500_INT_ADP_PROBE_UNPLUG,
  794. .flags = IORESOURCE_IRQ,
  795. },
  796. };
  797. static struct resource __devinitdata ab8505_iddet_resources[] = {
  798. {
  799. .name = "KeyDeglitch",
  800. .start = AB8505_INT_KEYDEGLITCH,
  801. .end = AB8505_INT_KEYDEGLITCH,
  802. .flags = IORESOURCE_IRQ,
  803. },
  804. {
  805. .name = "KP",
  806. .start = AB8505_INT_KP,
  807. .end = AB8505_INT_KP,
  808. .flags = IORESOURCE_IRQ,
  809. },
  810. {
  811. .name = "IKP",
  812. .start = AB8505_INT_IKP,
  813. .end = AB8505_INT_IKP,
  814. .flags = IORESOURCE_IRQ,
  815. },
  816. {
  817. .name = "IKR",
  818. .start = AB8505_INT_IKR,
  819. .end = AB8505_INT_IKR,
  820. .flags = IORESOURCE_IRQ,
  821. },
  822. {
  823. .name = "KeyStuck",
  824. .start = AB8505_INT_KEYSTUCK,
  825. .end = AB8505_INT_KEYSTUCK,
  826. .flags = IORESOURCE_IRQ,
  827. },
  828. };
  829. static struct resource __devinitdata ab8500_temp_resources[] = {
  830. {
  831. .name = "AB8500_TEMP_WARM",
  832. .start = AB8500_INT_TEMP_WARM,
  833. .end = AB8500_INT_TEMP_WARM,
  834. .flags = IORESOURCE_IRQ,
  835. },
  836. };
  837. static struct mfd_cell __devinitdata abx500_common_devs[] = {
  838. #ifdef CONFIG_DEBUG_FS
  839. {
  840. .name = "ab8500-debug",
  841. .num_resources = ARRAY_SIZE(ab8500_debug_resources),
  842. .resources = ab8500_debug_resources,
  843. },
  844. #endif
  845. {
  846. .name = "ab8500-sysctrl",
  847. },
  848. {
  849. .name = "ab8500-regulator",
  850. },
  851. {
  852. .name = "ab8500-gpadc",
  853. .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
  854. .resources = ab8500_gpadc_resources,
  855. },
  856. {
  857. .name = "ab8500-rtc",
  858. .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
  859. .resources = ab8500_rtc_resources,
  860. },
  861. {
  862. .name = "ab8500-acc-det",
  863. .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
  864. .resources = ab8500_av_acc_detect_resources,
  865. },
  866. {
  867. .name = "ab8500-poweron-key",
  868. .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
  869. .resources = ab8500_poweronkey_db_resources,
  870. },
  871. {
  872. .name = "ab8500-pwm",
  873. .id = 1,
  874. },
  875. {
  876. .name = "ab8500-pwm",
  877. .id = 2,
  878. },
  879. {
  880. .name = "ab8500-pwm",
  881. .id = 3,
  882. },
  883. { .name = "ab8500-leds", },
  884. {
  885. .name = "ab8500-denc",
  886. },
  887. {
  888. .name = "ab8500-temp",
  889. .num_resources = ARRAY_SIZE(ab8500_temp_resources),
  890. .resources = ab8500_temp_resources,
  891. },
  892. };
  893. static struct mfd_cell __devinitdata ab8500_bm_devs[] = {
  894. {
  895. .name = "ab8500-charger",
  896. .num_resources = ARRAY_SIZE(ab8500_charger_resources),
  897. .resources = ab8500_charger_resources,
  898. },
  899. {
  900. .name = "ab8500-btemp",
  901. .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
  902. .resources = ab8500_btemp_resources,
  903. },
  904. {
  905. .name = "ab8500-fg",
  906. .num_resources = ARRAY_SIZE(ab8500_fg_resources),
  907. .resources = ab8500_fg_resources,
  908. },
  909. {
  910. .name = "ab8500-chargalg",
  911. .num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
  912. .resources = ab8500_chargalg_resources,
  913. },
  914. };
  915. static struct mfd_cell __devinitdata ab8500_devs[] = {
  916. {
  917. .name = "ab8500-gpio",
  918. .num_resources = ARRAY_SIZE(ab8500_gpio_resources),
  919. .resources = ab8500_gpio_resources,
  920. },
  921. {
  922. .name = "ab8500-usb",
  923. .num_resources = ARRAY_SIZE(ab8500_usb_resources),
  924. .resources = ab8500_usb_resources,
  925. },
  926. {
  927. .name = "ab8500-codec",
  928. },
  929. };
  930. static struct mfd_cell __devinitdata ab9540_devs[] = {
  931. {
  932. .name = "ab8500-gpio",
  933. .num_resources = ARRAY_SIZE(ab9540_gpio_resources),
  934. .resources = ab9540_gpio_resources,
  935. },
  936. {
  937. .name = "ab9540-usb",
  938. .num_resources = ARRAY_SIZE(ab8500_usb_resources),
  939. .resources = ab8500_usb_resources,
  940. },
  941. {
  942. .name = "ab9540-codec",
  943. },
  944. };
  945. /* Device list common to ab9540 and ab8505 */
  946. static struct mfd_cell __devinitdata ab9540_ab8505_devs[] = {
  947. {
  948. .name = "ab-iddet",
  949. .num_resources = ARRAY_SIZE(ab8505_iddet_resources),
  950. .resources = ab8505_iddet_resources,
  951. },
  952. };
  953. static ssize_t show_chip_id(struct device *dev,
  954. struct device_attribute *attr, char *buf)
  955. {
  956. struct ab8500 *ab8500;
  957. ab8500 = dev_get_drvdata(dev);
  958. return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
  959. }
  960. /*
  961. * ab8500 has switched off due to (SWITCH_OFF_STATUS):
  962. * 0x01 Swoff bit programming
  963. * 0x02 Thermal protection activation
  964. * 0x04 Vbat lower then BattOk falling threshold
  965. * 0x08 Watchdog expired
  966. * 0x10 Non presence of 32kHz clock
  967. * 0x20 Battery level lower than power on reset threshold
  968. * 0x40 Power on key 1 pressed longer than 10 seconds
  969. * 0x80 DB8500 thermal shutdown
  970. */
  971. static ssize_t show_switch_off_status(struct device *dev,
  972. struct device_attribute *attr, char *buf)
  973. {
  974. int ret;
  975. u8 value;
  976. struct ab8500 *ab8500;
  977. ab8500 = dev_get_drvdata(dev);
  978. ret = get_register_interruptible(ab8500, AB8500_RTC,
  979. AB8500_SWITCH_OFF_STATUS, &value);
  980. if (ret < 0)
  981. return ret;
  982. return sprintf(buf, "%#x\n", value);
  983. }
  984. /*
  985. * ab8500 has turned on due to (TURN_ON_STATUS):
  986. * 0x01 PORnVbat
  987. * 0x02 PonKey1dbF
  988. * 0x04 PonKey2dbF
  989. * 0x08 RTCAlarm
  990. * 0x10 MainChDet
  991. * 0x20 VbusDet
  992. * 0x40 UsbIDDetect
  993. * 0x80 Reserved
  994. */
  995. static ssize_t show_turn_on_status(struct device *dev,
  996. struct device_attribute *attr, char *buf)
  997. {
  998. int ret;
  999. u8 value;
  1000. struct ab8500 *ab8500;
  1001. ab8500 = dev_get_drvdata(dev);
  1002. ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
  1003. AB8500_TURN_ON_STATUS, &value);
  1004. if (ret < 0)
  1005. return ret;
  1006. return sprintf(buf, "%#x\n", value);
  1007. }
  1008. static ssize_t show_ab9540_dbbrstn(struct device *dev,
  1009. struct device_attribute *attr, char *buf)
  1010. {
  1011. struct ab8500 *ab8500;
  1012. int ret;
  1013. u8 value;
  1014. ab8500 = dev_get_drvdata(dev);
  1015. ret = get_register_interruptible(ab8500, AB8500_REGU_CTRL2,
  1016. AB9540_MODEM_CTRL2_REG, &value);
  1017. if (ret < 0)
  1018. return ret;
  1019. return sprintf(buf, "%d\n",
  1020. (value & AB9540_MODEM_CTRL2_SWDBBRSTN_BIT) ? 1 : 0);
  1021. }
  1022. static ssize_t store_ab9540_dbbrstn(struct device *dev,
  1023. struct device_attribute *attr, const char *buf, size_t count)
  1024. {
  1025. struct ab8500 *ab8500;
  1026. int ret = count;
  1027. int err;
  1028. u8 bitvalues;
  1029. ab8500 = dev_get_drvdata(dev);
  1030. if (count > 0) {
  1031. switch (buf[0]) {
  1032. case '0':
  1033. bitvalues = 0;
  1034. break;
  1035. case '1':
  1036. bitvalues = AB9540_MODEM_CTRL2_SWDBBRSTN_BIT;
  1037. break;
  1038. default:
  1039. goto exit;
  1040. }
  1041. err = mask_and_set_register_interruptible(ab8500,
  1042. AB8500_REGU_CTRL2, AB9540_MODEM_CTRL2_REG,
  1043. AB9540_MODEM_CTRL2_SWDBBRSTN_BIT, bitvalues);
  1044. if (err)
  1045. dev_info(ab8500->dev,
  1046. "Failed to set DBBRSTN %c, err %#x\n",
  1047. buf[0], err);
  1048. }
  1049. exit:
  1050. return ret;
  1051. }
  1052. static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
  1053. static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
  1054. static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL);
  1055. static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR,
  1056. show_ab9540_dbbrstn, store_ab9540_dbbrstn);
  1057. static struct attribute *ab8500_sysfs_entries[] = {
  1058. &dev_attr_chip_id.attr,
  1059. &dev_attr_switch_off_status.attr,
  1060. &dev_attr_turn_on_status.attr,
  1061. NULL,
  1062. };
  1063. static struct attribute *ab9540_sysfs_entries[] = {
  1064. &dev_attr_chip_id.attr,
  1065. &dev_attr_switch_off_status.attr,
  1066. &dev_attr_turn_on_status.attr,
  1067. &dev_attr_dbbrstn.attr,
  1068. NULL,
  1069. };
  1070. static struct attribute_group ab8500_attr_group = {
  1071. .attrs = ab8500_sysfs_entries,
  1072. };
  1073. static struct attribute_group ab9540_attr_group = {
  1074. .attrs = ab9540_sysfs_entries,
  1075. };
  1076. static const struct of_device_id ab8500_match[] = {
  1077. {
  1078. .compatible = "stericsson,ab8500",
  1079. .data = (void *)AB8500_VERSION_AB8500,
  1080. },
  1081. {},
  1082. };
  1083. static int __devinit ab8500_probe(struct platform_device *pdev)
  1084. {
  1085. struct ab8500_platform_data *plat = dev_get_platdata(&pdev->dev);
  1086. const struct platform_device_id *platid = platform_get_device_id(pdev);
  1087. enum ab8500_version version = AB8500_VERSION_UNDEFINED;
  1088. struct device_node *np = pdev->dev.of_node;
  1089. struct ab8500 *ab8500;
  1090. struct resource *resource;
  1091. int ret;
  1092. int i;
  1093. u8 value;
  1094. ab8500 = kzalloc(sizeof *ab8500, GFP_KERNEL);
  1095. if (!ab8500)
  1096. return -ENOMEM;
  1097. if (plat)
  1098. ab8500->irq_base = plat->irq_base;
  1099. else if (np)
  1100. ret = of_property_read_u32(np, "stericsson,irq-base", &ab8500->irq_base);
  1101. if (!ab8500->irq_base) {
  1102. dev_info(&pdev->dev, "couldn't find irq-base\n");
  1103. ret = -EINVAL;
  1104. goto out_free_ab8500;
  1105. }
  1106. ab8500->dev = &pdev->dev;
  1107. resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1108. if (!resource) {
  1109. ret = -ENODEV;
  1110. goto out_free_ab8500;
  1111. }
  1112. ab8500->irq = resource->start;
  1113. ab8500->read = ab8500_i2c_read;
  1114. ab8500->write = ab8500_i2c_write;
  1115. ab8500->write_masked = ab8500_i2c_write_masked;
  1116. mutex_init(&ab8500->lock);
  1117. mutex_init(&ab8500->irq_lock);
  1118. atomic_set(&ab8500->transfer_ongoing, 0);
  1119. platform_set_drvdata(pdev, ab8500);
  1120. if (platid)
  1121. version = platid->driver_data;
  1122. else if (np)
  1123. version = (unsigned int)
  1124. of_match_device(ab8500_match, &pdev->dev)->data;
  1125. if (version != AB8500_VERSION_UNDEFINED)
  1126. ab8500->version = version;
  1127. else {
  1128. ret = get_register_interruptible(ab8500, AB8500_MISC,
  1129. AB8500_IC_NAME_REG, &value);
  1130. if (ret < 0)
  1131. goto out_free_ab8500;
  1132. ab8500->version = value;
  1133. }
  1134. ret = get_register_interruptible(ab8500, AB8500_MISC,
  1135. AB8500_REV_REG, &value);
  1136. if (ret < 0)
  1137. goto out_free_ab8500;
  1138. ab8500->chip_id = value;
  1139. dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n",
  1140. ab8500_version_str[ab8500->version],
  1141. ab8500->chip_id >> 4,
  1142. ab8500->chip_id & 0x0F);
  1143. /* Configure AB8500 or AB9540 IRQ */
  1144. if (is_ab9540(ab8500) || is_ab8505(ab8500)) {
  1145. ab8500->mask_size = AB9540_NUM_IRQ_REGS;
  1146. ab8500->irq_reg_offset = ab9540_irq_regoffset;
  1147. } else {
  1148. ab8500->mask_size = AB8500_NUM_IRQ_REGS;
  1149. ab8500->irq_reg_offset = ab8500_irq_regoffset;
  1150. }
  1151. ab8500->mask = kzalloc(ab8500->mask_size, GFP_KERNEL);
  1152. if (!ab8500->mask)
  1153. return -ENOMEM;
  1154. ab8500->oldmask = kzalloc(ab8500->mask_size, GFP_KERNEL);
  1155. if (!ab8500->oldmask) {
  1156. ret = -ENOMEM;
  1157. goto out_freemask;
  1158. }
  1159. /*
  1160. * ab8500 has switched off due to (SWITCH_OFF_STATUS):
  1161. * 0x01 Swoff bit programming
  1162. * 0x02 Thermal protection activation
  1163. * 0x04 Vbat lower then BattOk falling threshold
  1164. * 0x08 Watchdog expired
  1165. * 0x10 Non presence of 32kHz clock
  1166. * 0x20 Battery level lower than power on reset threshold
  1167. * 0x40 Power on key 1 pressed longer than 10 seconds
  1168. * 0x80 DB8500 thermal shutdown
  1169. */
  1170. ret = get_register_interruptible(ab8500, AB8500_RTC,
  1171. AB8500_SWITCH_OFF_STATUS, &value);
  1172. if (ret < 0)
  1173. return ret;
  1174. dev_info(ab8500->dev, "switch off status: %#x", value);
  1175. if (plat && plat->init)
  1176. plat->init(ab8500);
  1177. /* Clear and mask all interrupts */
  1178. for (i = 0; i < ab8500->mask_size; i++) {
  1179. /*
  1180. * Interrupt register 12 doesn't exist prior to AB8500 version
  1181. * 2.0
  1182. */
  1183. if (ab8500->irq_reg_offset[i] == 11 &&
  1184. is_ab8500_1p1_or_earlier(ab8500))
  1185. continue;
  1186. get_register_interruptible(ab8500, AB8500_INTERRUPT,
  1187. AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i],
  1188. &value);
  1189. set_register_interruptible(ab8500, AB8500_INTERRUPT,
  1190. AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff);
  1191. }
  1192. ret = abx500_register_ops(ab8500->dev, &ab8500_ops);
  1193. if (ret)
  1194. goto out_freeoldmask;
  1195. for (i = 0; i < ab8500->mask_size; i++)
  1196. ab8500->mask[i] = ab8500->oldmask[i] = 0xff;
  1197. if (ab8500->irq_base) {
  1198. ret = ab8500_irq_init(ab8500);
  1199. if (ret)
  1200. goto out_freeoldmask;
  1201. /* Activate this feature only in ab9540 */
  1202. /* till tests are done on ab8500 1p2 or later*/
  1203. if (is_ab9540(ab8500))
  1204. ret = request_threaded_irq(ab8500->irq, NULL,
  1205. ab8500_hierarchical_irq,
  1206. IRQF_ONESHOT | IRQF_NO_SUSPEND,
  1207. "ab8500", ab8500);
  1208. else
  1209. ret = request_threaded_irq(ab8500->irq, NULL,
  1210. ab8500_irq,
  1211. IRQF_ONESHOT | IRQF_NO_SUSPEND,
  1212. "ab8500", ab8500);
  1213. if (ret)
  1214. goto out_removeirq;
  1215. }
  1216. if (!np) {
  1217. ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs,
  1218. ARRAY_SIZE(abx500_common_devs), NULL,
  1219. ab8500->irq_base);
  1220. if (ret)
  1221. goto out_freeirq;
  1222. if (is_ab9540(ab8500))
  1223. ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs,
  1224. ARRAY_SIZE(ab9540_devs), NULL,
  1225. ab8500->irq_base);
  1226. else
  1227. ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
  1228. ARRAY_SIZE(ab8500_devs), NULL,
  1229. ab8500->irq_base);
  1230. if (ret)
  1231. goto out_freeirq;
  1232. if (is_ab9540(ab8500) || is_ab8505(ab8500))
  1233. ret = mfd_add_devices(ab8500->dev, 0, ab9540_ab8505_devs,
  1234. ARRAY_SIZE(ab9540_ab8505_devs), NULL,
  1235. ab8500->irq_base);
  1236. if (ret)
  1237. goto out_freeirq;
  1238. }
  1239. if (!no_bm) {
  1240. /* Add battery management devices */
  1241. ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs,
  1242. ARRAY_SIZE(ab8500_bm_devs), NULL,
  1243. ab8500->irq_base);
  1244. if (ret)
  1245. dev_err(ab8500->dev, "error adding bm devices\n");
  1246. }
  1247. if (is_ab9540(ab8500))
  1248. ret = sysfs_create_group(&ab8500->dev->kobj,
  1249. &ab9540_attr_group);
  1250. else
  1251. ret = sysfs_create_group(&ab8500->dev->kobj,
  1252. &ab8500_attr_group);
  1253. if (ret)
  1254. dev_err(ab8500->dev, "error creating sysfs entries\n");
  1255. else
  1256. return ret;
  1257. out_freeirq:
  1258. if (ab8500->irq_base)
  1259. free_irq(ab8500->irq, ab8500);
  1260. out_removeirq:
  1261. if (ab8500->irq_base)
  1262. ab8500_irq_remove(ab8500);
  1263. out_freeoldmask:
  1264. kfree(ab8500->oldmask);
  1265. out_freemask:
  1266. kfree(ab8500->mask);
  1267. out_free_ab8500:
  1268. kfree(ab8500);
  1269. return ret;
  1270. }
  1271. static int __devexit ab8500_remove(struct platform_device *pdev)
  1272. {
  1273. struct ab8500 *ab8500 = platform_get_drvdata(pdev);
  1274. if (is_ab9540(ab8500))
  1275. sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group);
  1276. else
  1277. sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
  1278. mfd_remove_devices(ab8500->dev);
  1279. if (ab8500->irq_base) {
  1280. free_irq(ab8500->irq, ab8500);
  1281. ab8500_irq_remove(ab8500);
  1282. }
  1283. kfree(ab8500->oldmask);
  1284. kfree(ab8500->mask);
  1285. kfree(ab8500);
  1286. return 0;
  1287. }
  1288. static const struct platform_device_id ab8500_id[] = {
  1289. { "ab8500-core", AB8500_VERSION_AB8500 },
  1290. { "ab8505-i2c", AB8500_VERSION_AB8505 },
  1291. { "ab9540-i2c", AB8500_VERSION_AB9540 },
  1292. { "ab8540-i2c", AB8500_VERSION_AB8540 },
  1293. { }
  1294. };
  1295. static struct platform_driver ab8500_core_driver = {
  1296. .driver = {
  1297. .name = "ab8500-core",
  1298. .owner = THIS_MODULE,
  1299. .of_match_table = ab8500_match,
  1300. },
  1301. .probe = ab8500_probe,
  1302. .remove = __devexit_p(ab8500_remove),
  1303. .id_table = ab8500_id,
  1304. };
  1305. static int __init ab8500_core_init(void)
  1306. {
  1307. return platform_driver_register(&ab8500_core_driver);
  1308. }
  1309. static void __exit ab8500_core_exit(void)
  1310. {
  1311. platform_driver_unregister(&ab8500_core_driver);
  1312. }
  1313. arch_initcall(ab8500_core_init);
  1314. module_exit(ab8500_core_exit);
  1315. MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent");
  1316. MODULE_DESCRIPTION("AB8500 MFD core");
  1317. MODULE_LICENSE("GPL v2");