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