ab8500-core.c 28 KB

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