ab5500-core.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  1. /*
  2. * Copyright (C) 2007-2011 ST-Ericsson
  3. * License terms: GNU General Public License (GPL) version 2
  4. * Low-level core for exclusive access to the AB5500 IC on the I2C bus
  5. * and some basic chip-configuration.
  6. * Author: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
  7. * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
  8. * Author: Mattias Wallin <mattias.wallin@stericsson.com>
  9. * Author: Rickard Andersson <rickard.andersson@stericsson.com>
  10. * Author: Karl Komierowski <karl.komierowski@stericsson.com>
  11. * Author: Bibek Basu <bibek.basu@stericsson.com>
  12. *
  13. * TODO: Event handling with irq_chip. Waiting for PRCMU fw support.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/mutex.h>
  17. #include <linux/err.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/slab.h>
  20. #include <linux/device.h>
  21. #include <linux/irq.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/random.h>
  24. #include <linux/mfd/abx500.h>
  25. #include <linux/mfd/abx500/ab5500.h>
  26. #include <linux/list.h>
  27. #include <linux/bitops.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/mfd/core.h>
  30. #include <linux/mfd/db5500-prcmu.h>
  31. #include "ab5500-core.h"
  32. #include "ab5500-debugfs.h"
  33. #define AB5500_NUM_EVENT_REG 23
  34. #define AB5500_IT_LATCH0_REG 0x40
  35. #define AB5500_IT_MASK0_REG 0x60
  36. /*
  37. * Permissible register ranges for reading and writing per device and bank.
  38. *
  39. * The ranges must be listed in increasing address order, and no overlaps are
  40. * allowed. It is assumed that write permission implies read permission
  41. * (i.e. only RO and RW permissions should be used). Ranges with write
  42. * permission must not be split up.
  43. */
  44. #define NO_RANGE {.count = 0, .range = NULL,}
  45. static struct ab5500_i2c_banks ab5500_bank_ranges[AB5500_NUM_DEVICES] = {
  46. [AB5500_DEVID_USB] = {
  47. .nbanks = 1,
  48. .bank = (struct ab5500_i2c_ranges []) {
  49. {
  50. .bankid = AB5500_BANK_USB,
  51. .nranges = 12,
  52. .range = (struct ab5500_reg_range[]) {
  53. {
  54. .first = 0x01,
  55. .last = 0x01,
  56. .perm = AB5500_PERM_RW,
  57. },
  58. {
  59. .first = 0x80,
  60. .last = 0x83,
  61. .perm = AB5500_PERM_RW,
  62. },
  63. {
  64. .first = 0x87,
  65. .last = 0x8A,
  66. .perm = AB5500_PERM_RW,
  67. },
  68. {
  69. .first = 0x8B,
  70. .last = 0x8B,
  71. .perm = AB5500_PERM_RO,
  72. },
  73. {
  74. .first = 0x91,
  75. .last = 0x92,
  76. .perm = AB5500_PERM_RO,
  77. },
  78. {
  79. .first = 0x93,
  80. .last = 0x93,
  81. .perm = AB5500_PERM_RW,
  82. },
  83. {
  84. .first = 0x94,
  85. .last = 0x94,
  86. .perm = AB5500_PERM_RO,
  87. },
  88. {
  89. .first = 0xA8,
  90. .last = 0xB0,
  91. .perm = AB5500_PERM_RO,
  92. },
  93. {
  94. .first = 0xB2,
  95. .last = 0xB2,
  96. .perm = AB5500_PERM_RO,
  97. },
  98. {
  99. .first = 0xB4,
  100. .last = 0xBC,
  101. .perm = AB5500_PERM_RO,
  102. },
  103. {
  104. .first = 0xBF,
  105. .last = 0xBF,
  106. .perm = AB5500_PERM_RO,
  107. },
  108. {
  109. .first = 0xC1,
  110. .last = 0xC5,
  111. .perm = AB5500_PERM_RO,
  112. },
  113. },
  114. },
  115. },
  116. },
  117. [AB5500_DEVID_ADC] = {
  118. .nbanks = 1,
  119. .bank = (struct ab5500_i2c_ranges []) {
  120. {
  121. .bankid = AB5500_BANK_ADC,
  122. .nranges = 6,
  123. .range = (struct ab5500_reg_range[]) {
  124. {
  125. .first = 0x1F,
  126. .last = 0x22,
  127. .perm = AB5500_PERM_RO,
  128. },
  129. {
  130. .first = 0x23,
  131. .last = 0x24,
  132. .perm = AB5500_PERM_RW,
  133. },
  134. {
  135. .first = 0x26,
  136. .last = 0x2D,
  137. .perm = AB5500_PERM_RO,
  138. },
  139. {
  140. .first = 0x2F,
  141. .last = 0x34,
  142. .perm = AB5500_PERM_RW,
  143. },
  144. {
  145. .first = 0x37,
  146. .last = 0x57,
  147. .perm = AB5500_PERM_RW,
  148. },
  149. {
  150. .first = 0x58,
  151. .last = 0x58,
  152. .perm = AB5500_PERM_RO,
  153. },
  154. },
  155. },
  156. },
  157. },
  158. [AB5500_DEVID_LEDS] = {
  159. .nbanks = 1,
  160. .bank = (struct ab5500_i2c_ranges []) {
  161. {
  162. .bankid = AB5500_BANK_LED,
  163. .nranges = 1,
  164. .range = (struct ab5500_reg_range[]) {
  165. {
  166. .first = 0x00,
  167. .last = 0x0C,
  168. .perm = AB5500_PERM_RW,
  169. },
  170. },
  171. },
  172. },
  173. },
  174. [AB5500_DEVID_VIDEO] = {
  175. .nbanks = 1,
  176. .bank = (struct ab5500_i2c_ranges []) {
  177. {
  178. .bankid = AB5500_BANK_VDENC,
  179. .nranges = 12,
  180. .range = (struct ab5500_reg_range[]) {
  181. {
  182. .first = 0x00,
  183. .last = 0x08,
  184. .perm = AB5500_PERM_RW,
  185. },
  186. {
  187. .first = 0x09,
  188. .last = 0x09,
  189. .perm = AB5500_PERM_RO,
  190. },
  191. {
  192. .first = 0x0A,
  193. .last = 0x12,
  194. .perm = AB5500_PERM_RW,
  195. },
  196. {
  197. .first = 0x15,
  198. .last = 0x19,
  199. .perm = AB5500_PERM_RW,
  200. },
  201. {
  202. .first = 0x1B,
  203. .last = 0x21,
  204. .perm = AB5500_PERM_RW,
  205. },
  206. {
  207. .first = 0x27,
  208. .last = 0x2C,
  209. .perm = AB5500_PERM_RW,
  210. },
  211. {
  212. .first = 0x41,
  213. .last = 0x41,
  214. .perm = AB5500_PERM_RW,
  215. },
  216. {
  217. .first = 0x45,
  218. .last = 0x5B,
  219. .perm = AB5500_PERM_RW,
  220. },
  221. {
  222. .first = 0x5D,
  223. .last = 0x5D,
  224. .perm = AB5500_PERM_RW,
  225. },
  226. {
  227. .first = 0x69,
  228. .last = 0x69,
  229. .perm = AB5500_PERM_RW,
  230. },
  231. {
  232. .first = 0x6C,
  233. .last = 0x6D,
  234. .perm = AB5500_PERM_RW,
  235. },
  236. {
  237. .first = 0x80,
  238. .last = 0x81,
  239. .perm = AB5500_PERM_RW,
  240. },
  241. },
  242. },
  243. },
  244. },
  245. [AB5500_DEVID_REGULATORS] = {
  246. .nbanks = 2,
  247. .bank = (struct ab5500_i2c_ranges []) {
  248. {
  249. .bankid = AB5500_BANK_STARTUP,
  250. .nranges = 12,
  251. .range = (struct ab5500_reg_range[]) {
  252. {
  253. .first = 0x00,
  254. .last = 0x01,
  255. .perm = AB5500_PERM_RW,
  256. },
  257. {
  258. .first = 0x1F,
  259. .last = 0x1F,
  260. .perm = AB5500_PERM_RW,
  261. },
  262. {
  263. .first = 0x2E,
  264. .last = 0x2E,
  265. .perm = AB5500_PERM_RO,
  266. },
  267. {
  268. .first = 0x2F,
  269. .last = 0x30,
  270. .perm = AB5500_PERM_RW,
  271. },
  272. {
  273. .first = 0x50,
  274. .last = 0x51,
  275. .perm = AB5500_PERM_RW,
  276. },
  277. {
  278. .first = 0x60,
  279. .last = 0x61,
  280. .perm = AB5500_PERM_RW,
  281. },
  282. {
  283. .first = 0x66,
  284. .last = 0x8A,
  285. .perm = AB5500_PERM_RW,
  286. },
  287. {
  288. .first = 0x8C,
  289. .last = 0x96,
  290. .perm = AB5500_PERM_RW,
  291. },
  292. {
  293. .first = 0xAA,
  294. .last = 0xB4,
  295. .perm = AB5500_PERM_RW,
  296. },
  297. {
  298. .first = 0xB7,
  299. .last = 0xBF,
  300. .perm = AB5500_PERM_RW,
  301. },
  302. {
  303. .first = 0xC1,
  304. .last = 0xCA,
  305. .perm = AB5500_PERM_RW,
  306. },
  307. {
  308. .first = 0xD3,
  309. .last = 0xE0,
  310. .perm = AB5500_PERM_RW,
  311. },
  312. },
  313. },
  314. {
  315. .bankid = AB5500_BANK_SIM_USBSIM,
  316. .nranges = 1,
  317. .range = (struct ab5500_reg_range[]) {
  318. {
  319. .first = 0x13,
  320. .last = 0x19,
  321. .perm = AB5500_PERM_RW,
  322. },
  323. },
  324. },
  325. },
  326. },
  327. [AB5500_DEVID_SIM] = {
  328. .nbanks = 1,
  329. .bank = (struct ab5500_i2c_ranges []) {
  330. {
  331. .bankid = AB5500_BANK_SIM_USBSIM,
  332. .nranges = 1,
  333. .range = (struct ab5500_reg_range[]) {
  334. {
  335. .first = 0x13,
  336. .last = 0x19,
  337. .perm = AB5500_PERM_RW,
  338. },
  339. },
  340. },
  341. },
  342. },
  343. [AB5500_DEVID_RTC] = {
  344. .nbanks = 1,
  345. .bank = (struct ab5500_i2c_ranges []) {
  346. {
  347. .bankid = AB5500_BANK_RTC,
  348. .nranges = 2,
  349. .range = (struct ab5500_reg_range[]) {
  350. {
  351. .first = 0x00,
  352. .last = 0x04,
  353. .perm = AB5500_PERM_RW,
  354. },
  355. {
  356. .first = 0x06,
  357. .last = 0x0C,
  358. .perm = AB5500_PERM_RW,
  359. },
  360. },
  361. },
  362. },
  363. },
  364. [AB5500_DEVID_CHARGER] = {
  365. .nbanks = 1,
  366. .bank = (struct ab5500_i2c_ranges []) {
  367. {
  368. .bankid = AB5500_BANK_CHG,
  369. .nranges = 2,
  370. .range = (struct ab5500_reg_range[]) {
  371. {
  372. .first = 0x11,
  373. .last = 0x11,
  374. .perm = AB5500_PERM_RO,
  375. },
  376. {
  377. .first = 0x12,
  378. .last = 0x1B,
  379. .perm = AB5500_PERM_RW,
  380. },
  381. },
  382. },
  383. },
  384. },
  385. [AB5500_DEVID_FUELGAUGE] = {
  386. .nbanks = 1,
  387. .bank = (struct ab5500_i2c_ranges []) {
  388. {
  389. .bankid = AB5500_BANK_FG_BATTCOM_ACC,
  390. .nranges = 2,
  391. .range = (struct ab5500_reg_range[]) {
  392. {
  393. .first = 0x00,
  394. .last = 0x0B,
  395. .perm = AB5500_PERM_RO,
  396. },
  397. {
  398. .first = 0x0C,
  399. .last = 0x10,
  400. .perm = AB5500_PERM_RW,
  401. },
  402. },
  403. },
  404. },
  405. },
  406. [AB5500_DEVID_VIBRATOR] = {
  407. .nbanks = 1,
  408. .bank = (struct ab5500_i2c_ranges []) {
  409. {
  410. .bankid = AB5500_BANK_VIBRA,
  411. .nranges = 2,
  412. .range = (struct ab5500_reg_range[]) {
  413. {
  414. .first = 0x10,
  415. .last = 0x13,
  416. .perm = AB5500_PERM_RW,
  417. },
  418. {
  419. .first = 0xFE,
  420. .last = 0xFE,
  421. .perm = AB5500_PERM_RW,
  422. },
  423. },
  424. },
  425. },
  426. },
  427. [AB5500_DEVID_CODEC] = {
  428. .nbanks = 1,
  429. .bank = (struct ab5500_i2c_ranges []) {
  430. {
  431. .bankid = AB5500_BANK_AUDIO_HEADSETUSB,
  432. .nranges = 2,
  433. .range = (struct ab5500_reg_range[]) {
  434. {
  435. .first = 0x00,
  436. .last = 0x48,
  437. .perm = AB5500_PERM_RW,
  438. },
  439. {
  440. .first = 0xEB,
  441. .last = 0xFB,
  442. .perm = AB5500_PERM_RW,
  443. },
  444. },
  445. },
  446. },
  447. },
  448. [AB5500_DEVID_POWER] = {
  449. .nbanks = 2,
  450. .bank = (struct ab5500_i2c_ranges []) {
  451. {
  452. .bankid = AB5500_BANK_STARTUP,
  453. .nranges = 1,
  454. .range = (struct ab5500_reg_range[]) {
  455. {
  456. .first = 0x30,
  457. .last = 0x30,
  458. .perm = AB5500_PERM_RW,
  459. },
  460. },
  461. },
  462. {
  463. .bankid = AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP,
  464. .nranges = 1,
  465. .range = (struct ab5500_reg_range[]) {
  466. {
  467. .first = 0x01,
  468. .last = 0x01,
  469. .perm = AB5500_PERM_RW,
  470. },
  471. },
  472. },
  473. },
  474. },
  475. };
  476. #define AB5500_IRQ(bank, bit) ((bank) * 8 + (bit))
  477. /* I appologize for the resource names beeing a mix of upper case
  478. * and lower case but I want them to be exact as the documentation */
  479. static struct mfd_cell ab5500_devs[AB5500_NUM_DEVICES] = {
  480. [AB5500_DEVID_LEDS] = {
  481. .name = "ab5500-leds",
  482. .id = AB5500_DEVID_LEDS,
  483. },
  484. [AB5500_DEVID_POWER] = {
  485. .name = "ab5500-power",
  486. .id = AB5500_DEVID_POWER,
  487. },
  488. [AB5500_DEVID_REGULATORS] = {
  489. .name = "ab5500-regulator",
  490. .id = AB5500_DEVID_REGULATORS,
  491. },
  492. [AB5500_DEVID_SIM] = {
  493. .name = "ab5500-sim",
  494. .id = AB5500_DEVID_SIM,
  495. .num_resources = 1,
  496. .resources = (struct resource[]) {
  497. {
  498. .name = "SIMOFF",
  499. .flags = IORESOURCE_IRQ,
  500. .start = AB5500_IRQ(2, 0), /*rising*/
  501. .end = AB5500_IRQ(2, 1), /*falling*/
  502. },
  503. },
  504. },
  505. [AB5500_DEVID_RTC] = {
  506. .name = "ab5500-rtc",
  507. .id = AB5500_DEVID_RTC,
  508. .num_resources = 1,
  509. .resources = (struct resource[]) {
  510. {
  511. .name = "RTC_Alarm",
  512. .flags = IORESOURCE_IRQ,
  513. .start = AB5500_IRQ(1, 7),
  514. .end = AB5500_IRQ(1, 7),
  515. }
  516. },
  517. },
  518. [AB5500_DEVID_CHARGER] = {
  519. .name = "ab5500-charger",
  520. .id = AB5500_DEVID_CHARGER,
  521. },
  522. [AB5500_DEVID_ADC] = {
  523. .name = "ab5500-adc",
  524. .id = AB5500_DEVID_ADC,
  525. .num_resources = 10,
  526. .resources = (struct resource[]) {
  527. {
  528. .name = "TRIGGER-0",
  529. .flags = IORESOURCE_IRQ,
  530. .start = AB5500_IRQ(0, 0),
  531. .end = AB5500_IRQ(0, 0),
  532. },
  533. {
  534. .name = "TRIGGER-1",
  535. .flags = IORESOURCE_IRQ,
  536. .start = AB5500_IRQ(0, 1),
  537. .end = AB5500_IRQ(0, 1),
  538. },
  539. {
  540. .name = "TRIGGER-2",
  541. .flags = IORESOURCE_IRQ,
  542. .start = AB5500_IRQ(0, 2),
  543. .end = AB5500_IRQ(0, 2),
  544. },
  545. {
  546. .name = "TRIGGER-3",
  547. .flags = IORESOURCE_IRQ,
  548. .start = AB5500_IRQ(0, 3),
  549. .end = AB5500_IRQ(0, 3),
  550. },
  551. {
  552. .name = "TRIGGER-4",
  553. .flags = IORESOURCE_IRQ,
  554. .start = AB5500_IRQ(0, 4),
  555. .end = AB5500_IRQ(0, 4),
  556. },
  557. {
  558. .name = "TRIGGER-5",
  559. .flags = IORESOURCE_IRQ,
  560. .start = AB5500_IRQ(0, 5),
  561. .end = AB5500_IRQ(0, 5),
  562. },
  563. {
  564. .name = "TRIGGER-6",
  565. .flags = IORESOURCE_IRQ,
  566. .start = AB5500_IRQ(0, 6),
  567. .end = AB5500_IRQ(0, 6),
  568. },
  569. {
  570. .name = "TRIGGER-7",
  571. .flags = IORESOURCE_IRQ,
  572. .start = AB5500_IRQ(0, 7),
  573. .end = AB5500_IRQ(0, 7),
  574. },
  575. {
  576. .name = "TRIGGER-VBAT",
  577. .flags = IORESOURCE_IRQ,
  578. .start = AB5500_IRQ(0, 8),
  579. .end = AB5500_IRQ(0, 8),
  580. },
  581. {
  582. .name = "TRIGGER-VBAT-TXON",
  583. .flags = IORESOURCE_IRQ,
  584. .start = AB5500_IRQ(0, 9),
  585. .end = AB5500_IRQ(0, 9),
  586. },
  587. },
  588. },
  589. [AB5500_DEVID_FUELGAUGE] = {
  590. .name = "ab5500-fuelgauge",
  591. .id = AB5500_DEVID_FUELGAUGE,
  592. .num_resources = 6,
  593. .resources = (struct resource[]) {
  594. {
  595. .name = "Batt_attach",
  596. .flags = IORESOURCE_IRQ,
  597. .start = AB5500_IRQ(7, 5),
  598. .end = AB5500_IRQ(7, 5),
  599. },
  600. {
  601. .name = "Batt_removal",
  602. .flags = IORESOURCE_IRQ,
  603. .start = AB5500_IRQ(7, 6),
  604. .end = AB5500_IRQ(7, 6),
  605. },
  606. {
  607. .name = "UART_framing",
  608. .flags = IORESOURCE_IRQ,
  609. .start = AB5500_IRQ(7, 7),
  610. .end = AB5500_IRQ(7, 7),
  611. },
  612. {
  613. .name = "UART_overrun",
  614. .flags = IORESOURCE_IRQ,
  615. .start = AB5500_IRQ(8, 0),
  616. .end = AB5500_IRQ(8, 0),
  617. },
  618. {
  619. .name = "UART_Rdy_RX",
  620. .flags = IORESOURCE_IRQ,
  621. .start = AB5500_IRQ(8, 1),
  622. .end = AB5500_IRQ(8, 1),
  623. },
  624. {
  625. .name = "UART_Rdy_TX",
  626. .flags = IORESOURCE_IRQ,
  627. .start = AB5500_IRQ(8, 2),
  628. .end = AB5500_IRQ(8, 2),
  629. },
  630. },
  631. },
  632. [AB5500_DEVID_VIBRATOR] = {
  633. .name = "ab5500-vibrator",
  634. .id = AB5500_DEVID_VIBRATOR,
  635. },
  636. [AB5500_DEVID_CODEC] = {
  637. .name = "ab5500-codec",
  638. .id = AB5500_DEVID_CODEC,
  639. .num_resources = 3,
  640. .resources = (struct resource[]) {
  641. {
  642. .name = "audio_spkr1_ovc",
  643. .flags = IORESOURCE_IRQ,
  644. .start = AB5500_IRQ(9, 5),
  645. .end = AB5500_IRQ(9, 5),
  646. },
  647. {
  648. .name = "audio_plllocked",
  649. .flags = IORESOURCE_IRQ,
  650. .start = AB5500_IRQ(9, 6),
  651. .end = AB5500_IRQ(9, 6),
  652. },
  653. {
  654. .name = "audio_spkr2_ovc",
  655. .flags = IORESOURCE_IRQ,
  656. .start = AB5500_IRQ(17, 4),
  657. .end = AB5500_IRQ(17, 4),
  658. },
  659. },
  660. },
  661. [AB5500_DEVID_USB] = {
  662. .name = "ab5500-usb",
  663. .id = AB5500_DEVID_USB,
  664. .num_resources = 36,
  665. .resources = (struct resource[]) {
  666. {
  667. .name = "Link_Update",
  668. .flags = IORESOURCE_IRQ,
  669. .start = AB5500_IRQ(22, 1),
  670. .end = AB5500_IRQ(22, 1),
  671. },
  672. {
  673. .name = "DCIO",
  674. .flags = IORESOURCE_IRQ,
  675. .start = AB5500_IRQ(8, 3),
  676. .end = AB5500_IRQ(8, 4),
  677. },
  678. {
  679. .name = "VBUS_R",
  680. .flags = IORESOURCE_IRQ,
  681. .start = AB5500_IRQ(8, 5),
  682. .end = AB5500_IRQ(8, 5),
  683. },
  684. {
  685. .name = "VBUS_F",
  686. .flags = IORESOURCE_IRQ,
  687. .start = AB5500_IRQ(8, 6),
  688. .end = AB5500_IRQ(8, 6),
  689. },
  690. {
  691. .name = "CHGstate_10_PCVBUSchg",
  692. .flags = IORESOURCE_IRQ,
  693. .start = AB5500_IRQ(8, 7),
  694. .end = AB5500_IRQ(8, 7),
  695. },
  696. {
  697. .name = "DCIOreverse_ovc",
  698. .flags = IORESOURCE_IRQ,
  699. .start = AB5500_IRQ(9, 0),
  700. .end = AB5500_IRQ(9, 0),
  701. },
  702. {
  703. .name = "USBCharDetDone",
  704. .flags = IORESOURCE_IRQ,
  705. .start = AB5500_IRQ(9, 1),
  706. .end = AB5500_IRQ(9, 1),
  707. },
  708. {
  709. .name = "DCIO_no_limit",
  710. .flags = IORESOURCE_IRQ,
  711. .start = AB5500_IRQ(9, 2),
  712. .end = AB5500_IRQ(9, 2),
  713. },
  714. {
  715. .name = "USB_suspend",
  716. .flags = IORESOURCE_IRQ,
  717. .start = AB5500_IRQ(9, 3),
  718. .end = AB5500_IRQ(9, 3),
  719. },
  720. {
  721. .name = "DCIOreverse_fwdcurrent",
  722. .flags = IORESOURCE_IRQ,
  723. .start = AB5500_IRQ(9, 4),
  724. .end = AB5500_IRQ(9, 4),
  725. },
  726. {
  727. .name = "Vbus_Imeasmax_change",
  728. .flags = IORESOURCE_IRQ,
  729. .start = AB5500_IRQ(9, 5),
  730. .end = AB5500_IRQ(9, 6),
  731. },
  732. {
  733. .name = "OVV",
  734. .flags = IORESOURCE_IRQ,
  735. .start = AB5500_IRQ(14, 5),
  736. .end = AB5500_IRQ(14, 5),
  737. },
  738. {
  739. .name = "USBcharging_NOTok",
  740. .flags = IORESOURCE_IRQ,
  741. .start = AB5500_IRQ(15, 3),
  742. .end = AB5500_IRQ(15, 3),
  743. },
  744. {
  745. .name = "usb_adp_sensoroff",
  746. .flags = IORESOURCE_IRQ,
  747. .start = AB5500_IRQ(15, 6),
  748. .end = AB5500_IRQ(15, 6),
  749. },
  750. {
  751. .name = "usb_adp_probeplug",
  752. .flags = IORESOURCE_IRQ,
  753. .start = AB5500_IRQ(15, 7),
  754. .end = AB5500_IRQ(15, 7),
  755. },
  756. {
  757. .name = "usb_adp_sinkerror",
  758. .flags = IORESOURCE_IRQ,
  759. .start = AB5500_IRQ(16, 0),
  760. .end = AB5500_IRQ(16, 6),
  761. },
  762. {
  763. .name = "usb_adp_sourceerror",
  764. .flags = IORESOURCE_IRQ,
  765. .start = AB5500_IRQ(16, 1),
  766. .end = AB5500_IRQ(16, 1),
  767. },
  768. {
  769. .name = "usb_idgnd_r",
  770. .flags = IORESOURCE_IRQ,
  771. .start = AB5500_IRQ(16, 2),
  772. .end = AB5500_IRQ(16, 2),
  773. },
  774. {
  775. .name = "usb_idgnd_f",
  776. .flags = IORESOURCE_IRQ,
  777. .start = AB5500_IRQ(16, 3),
  778. .end = AB5500_IRQ(16, 3),
  779. },
  780. {
  781. .name = "usb_iddetR1",
  782. .flags = IORESOURCE_IRQ,
  783. .start = AB5500_IRQ(16, 4),
  784. .end = AB5500_IRQ(16, 5),
  785. },
  786. {
  787. .name = "usb_iddetR2",
  788. .flags = IORESOURCE_IRQ,
  789. .start = AB5500_IRQ(16, 6),
  790. .end = AB5500_IRQ(16, 7),
  791. },
  792. {
  793. .name = "usb_iddetR3",
  794. .flags = IORESOURCE_IRQ,
  795. .start = AB5500_IRQ(17, 0),
  796. .end = AB5500_IRQ(17, 1),
  797. },
  798. {
  799. .name = "usb_iddetR4",
  800. .flags = IORESOURCE_IRQ,
  801. .start = AB5500_IRQ(17, 2),
  802. .end = AB5500_IRQ(17, 3),
  803. },
  804. {
  805. .name = "CharTempWindowOk",
  806. .flags = IORESOURCE_IRQ,
  807. .start = AB5500_IRQ(17, 7),
  808. .end = AB5500_IRQ(18, 0),
  809. },
  810. {
  811. .name = "USB_SprDetect",
  812. .flags = IORESOURCE_IRQ,
  813. .start = AB5500_IRQ(18, 1),
  814. .end = AB5500_IRQ(18, 1),
  815. },
  816. {
  817. .name = "usb_adp_probe_unplug",
  818. .flags = IORESOURCE_IRQ,
  819. .start = AB5500_IRQ(18, 2),
  820. .end = AB5500_IRQ(18, 2),
  821. },
  822. {
  823. .name = "VBUSChDrop",
  824. .flags = IORESOURCE_IRQ,
  825. .start = AB5500_IRQ(18, 3),
  826. .end = AB5500_IRQ(18, 4),
  827. },
  828. {
  829. .name = "dcio_char_rec_done",
  830. .flags = IORESOURCE_IRQ,
  831. .start = AB5500_IRQ(18, 5),
  832. .end = AB5500_IRQ(18, 5),
  833. },
  834. {
  835. .name = "Charging_stopped_by_temp",
  836. .flags = IORESOURCE_IRQ,
  837. .start = AB5500_IRQ(18, 6),
  838. .end = AB5500_IRQ(18, 6),
  839. },
  840. {
  841. .name = "CHGstate_11_SafeModeVBUS",
  842. .flags = IORESOURCE_IRQ,
  843. .start = AB5500_IRQ(21, 1),
  844. .end = AB5500_IRQ(21, 2),
  845. },
  846. {
  847. .name = "CHGstate_12_comletedVBUS",
  848. .flags = IORESOURCE_IRQ,
  849. .start = AB5500_IRQ(21, 2),
  850. .end = AB5500_IRQ(21, 2),
  851. },
  852. {
  853. .name = "CHGstate_13_completedVBUS",
  854. .flags = IORESOURCE_IRQ,
  855. .start = AB5500_IRQ(21, 3),
  856. .end = AB5500_IRQ(21, 3),
  857. },
  858. {
  859. .name = "CHGstate_14_FullChgDCIO",
  860. .flags = IORESOURCE_IRQ,
  861. .start = AB5500_IRQ(21, 4),
  862. .end = AB5500_IRQ(21, 4),
  863. },
  864. {
  865. .name = "CHGstate_15_SafeModeDCIO",
  866. .flags = IORESOURCE_IRQ,
  867. .start = AB5500_IRQ(21, 5),
  868. .end = AB5500_IRQ(21, 5),
  869. },
  870. {
  871. .name = "CHGstate_16_OFFsuspendDCIO",
  872. .flags = IORESOURCE_IRQ,
  873. .start = AB5500_IRQ(21, 6),
  874. .end = AB5500_IRQ(21, 6),
  875. },
  876. {
  877. .name = "CHGstate_17_completedDCIO",
  878. .flags = IORESOURCE_IRQ,
  879. .start = AB5500_IRQ(21, 7),
  880. .end = AB5500_IRQ(21, 7),
  881. },
  882. },
  883. },
  884. [AB5500_DEVID_OTP] = {
  885. .name = "ab5500-otp",
  886. .id = AB5500_DEVID_OTP,
  887. },
  888. [AB5500_DEVID_VIDEO] = {
  889. .name = "ab5500-video",
  890. .id = AB5500_DEVID_VIDEO,
  891. .num_resources = 1,
  892. .resources = (struct resource[]) {
  893. {
  894. .name = "plugTVdet",
  895. .flags = IORESOURCE_IRQ,
  896. .start = AB5500_IRQ(22, 2),
  897. .end = AB5500_IRQ(22, 2),
  898. },
  899. },
  900. },
  901. [AB5500_DEVID_DBIECI] = {
  902. .name = "ab5500-dbieci",
  903. .id = AB5500_DEVID_DBIECI,
  904. .num_resources = 10,
  905. .resources = (struct resource[]) {
  906. {
  907. .name = "COLL",
  908. .flags = IORESOURCE_IRQ,
  909. .start = AB5500_IRQ(14, 0),
  910. .end = AB5500_IRQ(14, 0),
  911. },
  912. {
  913. .name = "RESERR",
  914. .flags = IORESOURCE_IRQ,
  915. .start = AB5500_IRQ(14, 1),
  916. .end = AB5500_IRQ(14, 1),
  917. },
  918. {
  919. .name = "FRAERR",
  920. .flags = IORESOURCE_IRQ,
  921. .start = AB5500_IRQ(14, 2),
  922. .end = AB5500_IRQ(14, 2),
  923. },
  924. {
  925. .name = "COMERR",
  926. .flags = IORESOURCE_IRQ,
  927. .start = AB5500_IRQ(14, 3),
  928. .end = AB5500_IRQ(14, 3),
  929. },
  930. {
  931. .name = "BSI_indicator",
  932. .flags = IORESOURCE_IRQ,
  933. .start = AB5500_IRQ(14, 4),
  934. .end = AB5500_IRQ(14, 4),
  935. },
  936. {
  937. .name = "SPDSET",
  938. .flags = IORESOURCE_IRQ,
  939. .start = AB5500_IRQ(14, 6),
  940. .end = AB5500_IRQ(14, 6),
  941. },
  942. {
  943. .name = "DSENT",
  944. .flags = IORESOURCE_IRQ,
  945. .start = AB5500_IRQ(14, 7),
  946. .end = AB5500_IRQ(14, 7),
  947. },
  948. {
  949. .name = "DREC",
  950. .flags = IORESOURCE_IRQ,
  951. .start = AB5500_IRQ(15, 0),
  952. .end = AB5500_IRQ(15, 0),
  953. },
  954. {
  955. .name = "ACCINT",
  956. .flags = IORESOURCE_IRQ,
  957. .start = AB5500_IRQ(15, 1),
  958. .end = AB5500_IRQ(15, 1),
  959. },
  960. {
  961. .name = "NOPINT",
  962. .flags = IORESOURCE_IRQ,
  963. .start = AB5500_IRQ(15, 2),
  964. .end = AB5500_IRQ(15, 2),
  965. },
  966. },
  967. },
  968. [AB5500_DEVID_ONSWA] = {
  969. .name = "ab5500-onswa",
  970. .id = AB5500_DEVID_ONSWA,
  971. .num_resources = 2,
  972. .resources = (struct resource[]) {
  973. {
  974. .name = "ONSWAn_rising",
  975. .flags = IORESOURCE_IRQ,
  976. .start = AB5500_IRQ(1, 3),
  977. .end = AB5500_IRQ(1, 3),
  978. },
  979. {
  980. .name = "ONSWAn_falling",
  981. .flags = IORESOURCE_IRQ,
  982. .start = AB5500_IRQ(1, 4),
  983. .end = AB5500_IRQ(1, 4),
  984. },
  985. },
  986. },
  987. };
  988. /*
  989. * Functionality for getting/setting register values.
  990. */
  991. int ab5500_get_register_interruptible_raw(struct ab5500 *ab,
  992. u8 bank, u8 reg,
  993. u8 *value)
  994. {
  995. int err;
  996. if (bank >= AB5500_NUM_BANKS)
  997. return -EINVAL;
  998. err = mutex_lock_interruptible(&ab->access_mutex);
  999. if (err)
  1000. return err;
  1001. err = db5500_prcmu_abb_read(bankinfo[bank].slave_addr, reg, value, 1);
  1002. mutex_unlock(&ab->access_mutex);
  1003. return err;
  1004. }
  1005. static int get_register_page_interruptible(struct ab5500 *ab, u8 bank,
  1006. u8 first_reg, u8 *regvals, u8 numregs)
  1007. {
  1008. int err;
  1009. if (bank >= AB5500_NUM_BANKS)
  1010. return -EINVAL;
  1011. err = mutex_lock_interruptible(&ab->access_mutex);
  1012. if (err)
  1013. return err;
  1014. while (numregs) {
  1015. /* The hardware limit for get page is 4 */
  1016. u8 curnum = min_t(u8, numregs, 4u);
  1017. err = db5500_prcmu_abb_read(bankinfo[bank].slave_addr,
  1018. first_reg, regvals, curnum);
  1019. if (err)
  1020. goto out;
  1021. numregs -= curnum;
  1022. first_reg += curnum;
  1023. regvals += curnum;
  1024. }
  1025. out:
  1026. mutex_unlock(&ab->access_mutex);
  1027. return err;
  1028. }
  1029. int ab5500_mask_and_set_register_interruptible_raw(struct ab5500 *ab, u8 bank,
  1030. u8 reg, u8 bitmask, u8 bitvalues)
  1031. {
  1032. int err = 0;
  1033. if (bank >= AB5500_NUM_BANKS)
  1034. return -EINVAL;
  1035. if (bitmask) {
  1036. u8 buf;
  1037. err = mutex_lock_interruptible(&ab->access_mutex);
  1038. if (err)
  1039. return err;
  1040. if (bitmask == 0xFF) /* No need to read in this case. */
  1041. buf = bitvalues;
  1042. else { /* Read and modify the register value. */
  1043. err = db5500_prcmu_abb_read(bankinfo[bank].slave_addr,
  1044. reg, &buf, 1);
  1045. if (err)
  1046. return err;
  1047. buf = ((~bitmask & buf) | (bitmask & bitvalues));
  1048. }
  1049. /* Write the new value. */
  1050. err = db5500_prcmu_abb_write(bankinfo[bank].slave_addr, reg,
  1051. &buf, 1);
  1052. mutex_unlock(&ab->access_mutex);
  1053. }
  1054. return err;
  1055. }
  1056. static int
  1057. set_register_interruptible(struct ab5500 *ab, u8 bank, u8 reg, u8 value)
  1058. {
  1059. return ab5500_mask_and_set_register_interruptible_raw(ab, bank, reg,
  1060. 0xff, value);
  1061. }
  1062. /*
  1063. * Read/write permission checking functions.
  1064. */
  1065. static const struct ab5500_i2c_ranges *get_bankref(u8 devid, u8 bank)
  1066. {
  1067. u8 i;
  1068. if (devid < AB5500_NUM_DEVICES) {
  1069. for (i = 0; i < ab5500_bank_ranges[devid].nbanks; i++) {
  1070. if (ab5500_bank_ranges[devid].bank[i].bankid == bank)
  1071. return &ab5500_bank_ranges[devid].bank[i];
  1072. }
  1073. }
  1074. return NULL;
  1075. }
  1076. static bool page_write_allowed(u8 devid, u8 bank, u8 first_reg, u8 last_reg)
  1077. {
  1078. u8 i; /* range loop index */
  1079. const struct ab5500_i2c_ranges *bankref;
  1080. bankref = get_bankref(devid, bank);
  1081. if (bankref == NULL || last_reg < first_reg)
  1082. return false;
  1083. for (i = 0; i < bankref->nranges; i++) {
  1084. if (first_reg < bankref->range[i].first)
  1085. break;
  1086. if ((last_reg <= bankref->range[i].last) &&
  1087. (bankref->range[i].perm & AB5500_PERM_WR))
  1088. return true;
  1089. }
  1090. return false;
  1091. }
  1092. static bool reg_write_allowed(u8 devid, u8 bank, u8 reg)
  1093. {
  1094. return page_write_allowed(devid, bank, reg, reg);
  1095. }
  1096. static bool page_read_allowed(u8 devid, u8 bank, u8 first_reg, u8 last_reg)
  1097. {
  1098. u8 i;
  1099. const struct ab5500_i2c_ranges *bankref;
  1100. bankref = get_bankref(devid, bank);
  1101. if (bankref == NULL || last_reg < first_reg)
  1102. return false;
  1103. /* Find the range (if it exists in the list) that includes first_reg. */
  1104. for (i = 0; i < bankref->nranges; i++) {
  1105. if (first_reg < bankref->range[i].first)
  1106. return false;
  1107. if (first_reg <= bankref->range[i].last)
  1108. break;
  1109. }
  1110. /* Make sure that the entire range up to and including last_reg is
  1111. * readable. This may span several of the ranges in the list.
  1112. */
  1113. while ((i < bankref->nranges) &&
  1114. (bankref->range[i].perm & AB5500_PERM_RD)) {
  1115. if (last_reg <= bankref->range[i].last)
  1116. return true;
  1117. if ((++i >= bankref->nranges) ||
  1118. (bankref->range[i].first !=
  1119. (bankref->range[i - 1].last + 1))) {
  1120. break;
  1121. }
  1122. }
  1123. return false;
  1124. }
  1125. static bool reg_read_allowed(u8 devid, u8 bank, u8 reg)
  1126. {
  1127. return page_read_allowed(devid, bank, reg, reg);
  1128. }
  1129. /*
  1130. * The exported register access functionality.
  1131. */
  1132. static int ab5500_get_chip_id(struct device *dev)
  1133. {
  1134. struct ab5500 *ab = dev_get_drvdata(dev->parent);
  1135. return (int)ab->chip_id;
  1136. }
  1137. static int ab5500_mask_and_set_register_interruptible(struct device *dev,
  1138. u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
  1139. {
  1140. struct ab5500 *ab;
  1141. struct platform_device *pdev = to_platform_device(dev);
  1142. if ((AB5500_NUM_BANKS <= bank) ||
  1143. !reg_write_allowed(pdev->id, bank, reg))
  1144. return -EINVAL;
  1145. ab = dev_get_drvdata(dev->parent);
  1146. return ab5500_mask_and_set_register_interruptible_raw(ab, bank, reg,
  1147. bitmask, bitvalues);
  1148. }
  1149. static int ab5500_set_register_interruptible(struct device *dev, u8 bank,
  1150. u8 reg, u8 value)
  1151. {
  1152. return ab5500_mask_and_set_register_interruptible(dev, bank, reg, 0xFF,
  1153. value);
  1154. }
  1155. static int ab5500_get_register_interruptible(struct device *dev, u8 bank,
  1156. u8 reg, u8 *value)
  1157. {
  1158. struct ab5500 *ab;
  1159. struct platform_device *pdev = to_platform_device(dev);
  1160. if ((AB5500_NUM_BANKS <= bank) ||
  1161. !reg_read_allowed(pdev->id, bank, reg))
  1162. return -EINVAL;
  1163. ab = dev_get_drvdata(dev->parent);
  1164. return ab5500_get_register_interruptible_raw(ab, bank, reg, value);
  1165. }
  1166. static int ab5500_get_register_page_interruptible(struct device *dev, u8 bank,
  1167. u8 first_reg, u8 *regvals, u8 numregs)
  1168. {
  1169. struct ab5500 *ab;
  1170. struct platform_device *pdev = to_platform_device(dev);
  1171. if ((AB5500_NUM_BANKS <= bank) ||
  1172. !page_read_allowed(pdev->id, bank,
  1173. first_reg, (first_reg + numregs - 1)))
  1174. return -EINVAL;
  1175. ab = dev_get_drvdata(dev->parent);
  1176. return get_register_page_interruptible(ab, bank, first_reg, regvals,
  1177. numregs);
  1178. }
  1179. static int
  1180. ab5500_event_registers_startup_state_get(struct device *dev, u8 *event)
  1181. {
  1182. struct ab5500 *ab;
  1183. ab = dev_get_drvdata(dev->parent);
  1184. if (!ab->startup_events_read)
  1185. return -EAGAIN; /* Try again later */
  1186. memcpy(event, ab->startup_events, AB5500_NUM_EVENT_REG);
  1187. return 0;
  1188. }
  1189. static struct abx500_ops ab5500_ops = {
  1190. .get_chip_id = ab5500_get_chip_id,
  1191. .get_register = ab5500_get_register_interruptible,
  1192. .set_register = ab5500_set_register_interruptible,
  1193. .get_register_page = ab5500_get_register_page_interruptible,
  1194. .set_register_page = NULL,
  1195. .mask_and_set_register = ab5500_mask_and_set_register_interruptible,
  1196. .event_registers_startup_state_get =
  1197. ab5500_event_registers_startup_state_get,
  1198. .startup_irq_enabled = NULL,
  1199. };
  1200. /*
  1201. * ab5500_setup : Basic set-up, datastructure creation/destruction
  1202. * and I2C interface.This sets up a default config
  1203. * in the AB5500 chip so that it will work as expected.
  1204. * @ab : Pointer to ab5500 structure
  1205. * @settings : Pointer to struct abx500_init_settings
  1206. * @size : Size of init data
  1207. */
  1208. static int __init ab5500_setup(struct ab5500 *ab,
  1209. struct abx500_init_settings *settings, unsigned int size)
  1210. {
  1211. int err = 0;
  1212. int i;
  1213. for (i = 0; i < size; i++) {
  1214. err = ab5500_mask_and_set_register_interruptible_raw(ab,
  1215. settings[i].bank,
  1216. settings[i].reg,
  1217. 0xFF, settings[i].setting);
  1218. if (err)
  1219. goto exit_no_setup;
  1220. /* If event mask register update the event mask in ab5500 */
  1221. if ((settings[i].bank == AB5500_BANK_IT) &&
  1222. (AB5500_MASK_BASE <= settings[i].reg) &&
  1223. (settings[i].reg <= AB5500_MASK_END)) {
  1224. ab->mask[settings[i].reg - AB5500_MASK_BASE] =
  1225. settings[i].setting;
  1226. }
  1227. }
  1228. exit_no_setup:
  1229. return err;
  1230. }
  1231. struct ab_family_id {
  1232. u8 id;
  1233. char *name;
  1234. };
  1235. static const struct ab_family_id ids[] __initdata = {
  1236. /* AB5500 */
  1237. {
  1238. .id = AB5500_1_0,
  1239. .name = "1.0"
  1240. },
  1241. {
  1242. .id = AB5500_1_1,
  1243. .name = "1.1"
  1244. },
  1245. /* Terminator */
  1246. {
  1247. .id = 0x00,
  1248. }
  1249. };
  1250. static int __init ab5500_probe(struct platform_device *pdev)
  1251. {
  1252. struct ab5500 *ab;
  1253. struct ab5500_platform_data *ab5500_plf_data =
  1254. pdev->dev.platform_data;
  1255. int err;
  1256. int i;
  1257. ab = kzalloc(sizeof(struct ab5500), GFP_KERNEL);
  1258. if (!ab) {
  1259. dev_err(&pdev->dev,
  1260. "could not allocate ab5500 device\n");
  1261. return -ENOMEM;
  1262. }
  1263. /* Initialize data structure */
  1264. mutex_init(&ab->access_mutex);
  1265. mutex_init(&ab->irq_lock);
  1266. ab->dev = &pdev->dev;
  1267. platform_set_drvdata(pdev, ab);
  1268. /* Read chip ID register */
  1269. err = ab5500_get_register_interruptible_raw(ab,
  1270. AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP,
  1271. AB5500_CHIP_ID, &ab->chip_id);
  1272. if (err) {
  1273. dev_err(&pdev->dev, "could not communicate with the analog "
  1274. "baseband chip\n");
  1275. goto exit_no_detect;
  1276. }
  1277. for (i = 0; ids[i].id != 0x0; i++) {
  1278. if (ids[i].id == ab->chip_id) {
  1279. snprintf(&ab->chip_name[0], sizeof(ab->chip_name) - 1,
  1280. "AB5500 %s", ids[i].name);
  1281. break;
  1282. }
  1283. }
  1284. if (ids[i].id == 0x0) {
  1285. dev_err(&pdev->dev, "unknown analog baseband chip id: 0x%x\n",
  1286. ab->chip_id);
  1287. dev_err(&pdev->dev, "driver not started!\n");
  1288. goto exit_no_detect;
  1289. }
  1290. /* Clear and mask all interrupts */
  1291. for (i = 0; i < AB5500_NUM_IRQ_REGS; i++) {
  1292. u8 latchreg = AB5500_IT_LATCH0_REG + i;
  1293. u8 maskreg = AB5500_IT_MASK0_REG + i;
  1294. u8 val;
  1295. ab5500_get_register_interruptible_raw(ab, AB5500_BANK_IT,
  1296. latchreg, &val);
  1297. set_register_interruptible(ab, AB5500_BANK_IT, maskreg, 0xff);
  1298. ab->mask[i] = ab->oldmask[i] = 0xff;
  1299. }
  1300. err = abx500_register_ops(&pdev->dev, &ab5500_ops);
  1301. if (err) {
  1302. dev_err(&pdev->dev, "ab5500_register ops error\n");
  1303. goto exit_no_detect;
  1304. }
  1305. /* Set up and register the platform devices. */
  1306. for (i = 0; i < AB5500_NUM_DEVICES; i++) {
  1307. ab5500_devs[i].platform_data = ab5500_plf_data->dev_data[i];
  1308. ab5500_devs[i].pdata_size =
  1309. sizeof(ab5500_plf_data->dev_data[i]);
  1310. }
  1311. err = mfd_add_devices(&pdev->dev, 0, ab5500_devs,
  1312. ARRAY_SIZE(ab5500_devs), NULL,
  1313. ab5500_plf_data->irq.base);
  1314. if (err) {
  1315. dev_err(&pdev->dev, "ab5500_mfd_add_device error\n");
  1316. goto exit_no_detect;
  1317. }
  1318. err = ab5500_setup(ab, ab5500_plf_data->init_settings,
  1319. ab5500_plf_data->init_settings_sz);
  1320. if (err) {
  1321. dev_err(&pdev->dev, "ab5500_setup error\n");
  1322. goto exit_no_detect;
  1323. }
  1324. ab5500_setup_debugfs(ab);
  1325. dev_info(&pdev->dev, "detected AB chip: %s\n", &ab->chip_name[0]);
  1326. return 0;
  1327. exit_no_detect:
  1328. kfree(ab);
  1329. return err;
  1330. }
  1331. static int __exit ab5500_remove(struct platform_device *pdev)
  1332. {
  1333. struct ab5500 *ab = platform_get_drvdata(pdev);
  1334. ab5500_remove_debugfs();
  1335. mfd_remove_devices(&pdev->dev);
  1336. kfree(ab);
  1337. return 0;
  1338. }
  1339. static struct platform_driver ab5500_driver = {
  1340. .driver = {
  1341. .name = "ab5500-core",
  1342. .owner = THIS_MODULE,
  1343. },
  1344. .remove = __exit_p(ab5500_remove),
  1345. };
  1346. static int __init ab5500_core_init(void)
  1347. {
  1348. return platform_driver_probe(&ab5500_driver, ab5500_probe);
  1349. }
  1350. static void __exit ab5500_core_exit(void)
  1351. {
  1352. platform_driver_unregister(&ab5500_driver);
  1353. }
  1354. subsys_initcall(ab5500_core_init);
  1355. module_exit(ab5500_core_exit);
  1356. MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
  1357. MODULE_DESCRIPTION("AB5500 core driver");
  1358. MODULE_LICENSE("GPL");