pm8921-core.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. /*
  2. * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #define pr_fmt(fmt) "%s: " fmt, __func__
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/slab.h>
  18. #include <linux/string.h>
  19. #include <linux/err.h>
  20. #include <linux/msm_ssbi.h>
  21. #include <linux/mfd/core.h>
  22. #include <linux/mfd/pm8xxx/pm8921.h>
  23. #include <linux/mfd/pm8xxx/core.h>
  24. #include <linux/mfd/pm8xxx/regulator.h>
  25. #include <linux/leds-pm8xxx.h>
  26. #define REG_HWREV 0x002 /* PMIC4 revision */
  27. #define REG_HWREV_2 0x0E8 /* PMIC4 revision 2 */
  28. #define REG_MPP_BASE 0x050
  29. #define REG_IRQ_BASE 0x1BB
  30. #define REG_TEMP_ALARM_CTRL 0x1B
  31. #define REG_TEMP_ALARM_PWM 0x9B
  32. #define REG_BATT_ALARM_THRESH 0x023
  33. #define REG_BATT_ALARM_CTRL1 0x024
  34. #define REG_BATT_ALARM_CTRL2 0x021
  35. #define REG_BATT_ALARM_PWM_CTRL 0x020
  36. #define PM8921_VERSION_MASK 0xFFF0
  37. #define PM8921_VERSION_VALUE 0x06F0
  38. #define PM8922_VERSION_VALUE 0x0AF0
  39. #define PM8917_VERSION_VALUE 0x0CF0
  40. #define PM8921_REVISION_MASK 0x000F
  41. #define REG_PM8921_PON_CNTRL_3 0x01D
  42. #define PM8921_RESTART_REASON_MASK 0x07
  43. #define SINGLE_IRQ_RESOURCE(_name, _irq) \
  44. { \
  45. .name = _name, \
  46. .start = _irq, \
  47. .end = _irq, \
  48. .flags = IORESOURCE_IRQ, \
  49. }
  50. struct pm8921 {
  51. struct device *dev;
  52. struct pm_irq_chip *irq_chip;
  53. struct mfd_cell *mfd_regulators;
  54. struct pm8xxx_regulator_core_platform_data *regulator_cdata;
  55. u32 rev_registers;
  56. u8 restart_reason;
  57. };
  58. static int pm8921_readb(const struct device *dev, u16 addr, u8 *val)
  59. {
  60. const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
  61. const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
  62. return msm_ssbi_read(pmic->dev->parent, addr, val, 1);
  63. }
  64. static int pm8921_writeb(const struct device *dev, u16 addr, u8 val)
  65. {
  66. const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
  67. const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
  68. return msm_ssbi_write(pmic->dev->parent, addr, &val, 1);
  69. }
  70. static int pm8921_read_buf(const struct device *dev, u16 addr, u8 *buf,
  71. int cnt)
  72. {
  73. const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
  74. const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
  75. return msm_ssbi_read(pmic->dev->parent, addr, buf, cnt);
  76. }
  77. static int pm8921_write_buf(const struct device *dev, u16 addr, u8 *buf,
  78. int cnt)
  79. {
  80. const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
  81. const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
  82. return msm_ssbi_write(pmic->dev->parent, addr, buf, cnt);
  83. }
  84. static int pm8921_read_irq_stat(const struct device *dev, int irq)
  85. {
  86. const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
  87. const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
  88. return pm8xxx_get_irq_stat(pmic->irq_chip, irq);
  89. }
  90. static enum pm8xxx_version pm8921_get_version(const struct device *dev)
  91. {
  92. const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
  93. const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
  94. enum pm8xxx_version version = -ENODEV;
  95. if ((pmic->rev_registers & PM8921_VERSION_MASK) == PM8921_VERSION_VALUE)
  96. version = PM8XXX_VERSION_8921;
  97. else if ((pmic->rev_registers & PM8921_VERSION_MASK)
  98. == PM8922_VERSION_VALUE)
  99. version = PM8XXX_VERSION_8922;
  100. else if ((pmic->rev_registers & PM8921_VERSION_MASK)
  101. == PM8917_VERSION_VALUE)
  102. version = PM8XXX_VERSION_8917;
  103. return version;
  104. }
  105. static int pm8921_get_revision(const struct device *dev)
  106. {
  107. const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
  108. const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
  109. return pmic->rev_registers & PM8921_REVISION_MASK;
  110. }
  111. static u8 pm8921_restart_reason(const struct device *dev)
  112. {
  113. const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
  114. const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
  115. return pmic->restart_reason;
  116. }
  117. static struct pm8xxx_drvdata pm8921_drvdata = {
  118. .pmic_readb = pm8921_readb,
  119. .pmic_writeb = pm8921_writeb,
  120. .pmic_read_buf = pm8921_read_buf,
  121. .pmic_write_buf = pm8921_write_buf,
  122. .pmic_read_irq_stat = pm8921_read_irq_stat,
  123. .pmic_get_version = pm8921_get_version,
  124. .pmic_get_revision = pm8921_get_revision,
  125. .pmic_restart_reason = pm8921_restart_reason,
  126. };
  127. static struct resource gpio_cell_resources[] = {
  128. [0] = {
  129. .start = PM8921_IRQ_BLOCK_BIT(PM8921_GPIO_BLOCK_START, 0),
  130. .end = PM8921_IRQ_BLOCK_BIT(PM8921_GPIO_BLOCK_START, 0)
  131. + PM8921_NR_GPIOS - 1,
  132. .flags = IORESOURCE_IRQ,
  133. },
  134. };
  135. static struct mfd_cell gpio_cell __devinitdata = {
  136. .name = PM8XXX_GPIO_DEV_NAME,
  137. .id = -1,
  138. .resources = gpio_cell_resources,
  139. .num_resources = ARRAY_SIZE(gpio_cell_resources),
  140. };
  141. static const struct resource adc_cell_resources[] __devinitconst = {
  142. SINGLE_IRQ_RESOURCE(NULL, PM8921_ADC_EOC_USR_IRQ),
  143. SINGLE_IRQ_RESOURCE(NULL, PM8921_ADC_BATT_TEMP_WARM_IRQ),
  144. SINGLE_IRQ_RESOURCE(NULL, PM8921_ADC_BATT_TEMP_COLD_IRQ),
  145. };
  146. static struct mfd_cell adc_cell __devinitdata = {
  147. .name = PM8XXX_ADC_DEV_NAME,
  148. .id = -1,
  149. .resources = adc_cell_resources,
  150. .num_resources = ARRAY_SIZE(adc_cell_resources),
  151. };
  152. static struct resource mpp_cell_resources[] = {
  153. {
  154. .start = PM8921_IRQ_BLOCK_BIT(PM8921_MPP_BLOCK_START, 0),
  155. .end = PM8921_IRQ_BLOCK_BIT(PM8921_MPP_BLOCK_START, 0)
  156. + PM8921_NR_MPPS - 1,
  157. .flags = IORESOURCE_IRQ,
  158. },
  159. };
  160. static struct mfd_cell mpp_cell __devinitdata = {
  161. .name = PM8XXX_MPP_DEV_NAME,
  162. .id = 0,
  163. .resources = mpp_cell_resources,
  164. .num_resources = ARRAY_SIZE(mpp_cell_resources),
  165. };
  166. static const struct resource rtc_cell_resources[] __devinitconst = {
  167. [0] = SINGLE_IRQ_RESOURCE(NULL, PM8921_RTC_ALARM_IRQ),
  168. [1] = {
  169. .name = "pmic_rtc_base",
  170. .start = PM8921_RTC_BASE,
  171. .end = PM8921_RTC_BASE,
  172. .flags = IORESOURCE_IO,
  173. },
  174. };
  175. static struct mfd_cell rtc_cell __devinitdata = {
  176. .name = PM8XXX_RTC_DEV_NAME,
  177. .id = -1,
  178. .resources = rtc_cell_resources,
  179. .num_resources = ARRAY_SIZE(rtc_cell_resources),
  180. };
  181. static const struct resource resources_pwrkey[] __devinitconst = {
  182. SINGLE_IRQ_RESOURCE(NULL, PM8921_PWRKEY_REL_IRQ),
  183. SINGLE_IRQ_RESOURCE(NULL, PM8921_PWRKEY_PRESS_IRQ),
  184. };
  185. static struct mfd_cell pwrkey_cell __devinitdata = {
  186. .name = PM8XXX_PWRKEY_DEV_NAME,
  187. .id = -1,
  188. .num_resources = ARRAY_SIZE(resources_pwrkey),
  189. .resources = resources_pwrkey,
  190. };
  191. static const struct resource resources_keypad[] = {
  192. SINGLE_IRQ_RESOURCE(NULL, PM8921_KEYPAD_IRQ),
  193. SINGLE_IRQ_RESOURCE(NULL, PM8921_KEYSTUCK_IRQ),
  194. };
  195. static struct mfd_cell keypad_cell __devinitdata = {
  196. .name = PM8XXX_KEYPAD_DEV_NAME,
  197. .id = -1,
  198. .num_resources = ARRAY_SIZE(resources_keypad),
  199. .resources = resources_keypad,
  200. };
  201. static struct mfd_cell debugfs_cell __devinitdata = {
  202. .name = "pm8xxx-debug",
  203. .id = 0,
  204. .platform_data = "pm8921-dbg",
  205. .pdata_size = sizeof("pm8921-dbg"),
  206. };
  207. static struct mfd_cell pwm_cell __devinitdata = {
  208. .name = PM8XXX_PWM_DEV_NAME,
  209. .id = -1,
  210. };
  211. static const struct resource charger_cell_resources[] __devinitconst = {
  212. SINGLE_IRQ_RESOURCE("USBIN_VALID_IRQ", PM8921_USBIN_VALID_IRQ),
  213. SINGLE_IRQ_RESOURCE("USBIN_OV_IRQ", PM8921_USBIN_OV_IRQ),
  214. SINGLE_IRQ_RESOURCE("BATT_INSERTED_IRQ", PM8921_BATT_INSERTED_IRQ),
  215. SINGLE_IRQ_RESOURCE("VBATDET_LOW_IRQ", PM8921_VBATDET_LOW_IRQ),
  216. SINGLE_IRQ_RESOURCE("USBIN_UV_IRQ", PM8921_USBIN_UV_IRQ),
  217. SINGLE_IRQ_RESOURCE("VBAT_OV_IRQ", PM8921_VBAT_OV_IRQ),
  218. SINGLE_IRQ_RESOURCE("CHGWDOG_IRQ", PM8921_CHGWDOG_IRQ),
  219. SINGLE_IRQ_RESOURCE("VCP_IRQ", PM8921_VCP_IRQ),
  220. SINGLE_IRQ_RESOURCE("ATCDONE_IRQ", PM8921_ATCDONE_IRQ),
  221. SINGLE_IRQ_RESOURCE("ATCFAIL_IRQ", PM8921_ATCFAIL_IRQ),
  222. SINGLE_IRQ_RESOURCE("CHGDONE_IRQ", PM8921_CHGDONE_IRQ),
  223. SINGLE_IRQ_RESOURCE("CHGFAIL_IRQ", PM8921_CHGFAIL_IRQ),
  224. SINGLE_IRQ_RESOURCE("CHGSTATE_IRQ", PM8921_CHGSTATE_IRQ),
  225. SINGLE_IRQ_RESOURCE("LOOP_CHANGE_IRQ", PM8921_LOOP_CHANGE_IRQ),
  226. SINGLE_IRQ_RESOURCE("FASTCHG_IRQ", PM8921_FASTCHG_IRQ),
  227. SINGLE_IRQ_RESOURCE("TRKLCHG_IRQ", PM8921_TRKLCHG_IRQ),
  228. SINGLE_IRQ_RESOURCE("BATT_REMOVED_IRQ", PM8921_BATT_REMOVED_IRQ),
  229. SINGLE_IRQ_RESOURCE("BATTTEMP_HOT_IRQ", PM8921_BATTTEMP_HOT_IRQ),
  230. SINGLE_IRQ_RESOURCE("CHGHOT_IRQ", PM8921_CHGHOT_IRQ),
  231. SINGLE_IRQ_RESOURCE("BATTTEMP_COLD_IRQ", PM8921_BATTTEMP_COLD_IRQ),
  232. SINGLE_IRQ_RESOURCE("CHG_GONE_IRQ", PM8921_CHG_GONE_IRQ),
  233. SINGLE_IRQ_RESOURCE("BAT_TEMP_OK_IRQ", PM8921_BAT_TEMP_OK_IRQ),
  234. SINGLE_IRQ_RESOURCE("COARSE_DET_LOW_IRQ", PM8921_COARSE_DET_LOW_IRQ),
  235. SINGLE_IRQ_RESOURCE("VDD_LOOP_IRQ", PM8921_VDD_LOOP_IRQ),
  236. SINGLE_IRQ_RESOURCE("VREG_OV_IRQ", PM8921_VREG_OV_IRQ),
  237. SINGLE_IRQ_RESOURCE("VBATDET_IRQ", PM8921_VBATDET_IRQ),
  238. SINGLE_IRQ_RESOURCE("BATFET_IRQ", PM8921_BATFET_IRQ),
  239. SINGLE_IRQ_RESOURCE("PSI_IRQ", PM8921_PSI_IRQ),
  240. SINGLE_IRQ_RESOURCE("DCIN_VALID_IRQ", PM8921_DCIN_VALID_IRQ),
  241. SINGLE_IRQ_RESOURCE("DCIN_OV_IRQ", PM8921_DCIN_OV_IRQ),
  242. SINGLE_IRQ_RESOURCE("DCIN_UV_IRQ", PM8921_DCIN_UV_IRQ),
  243. };
  244. static const struct resource bms_cell_resources[] __devinitconst = {
  245. SINGLE_IRQ_RESOURCE("PM8921_BMS_SBI_WRITE_OK", PM8921_BMS_SBI_WRITE_OK),
  246. SINGLE_IRQ_RESOURCE("PM8921_BMS_CC_THR", PM8921_BMS_CC_THR),
  247. SINGLE_IRQ_RESOURCE("PM8921_BMS_VSENSE_THR", PM8921_BMS_VSENSE_THR),
  248. SINGLE_IRQ_RESOURCE("PM8921_BMS_VSENSE_FOR_R", PM8921_BMS_VSENSE_FOR_R),
  249. SINGLE_IRQ_RESOURCE("PM8921_BMS_OCV_FOR_R", PM8921_BMS_OCV_FOR_R),
  250. SINGLE_IRQ_RESOURCE("PM8921_BMS_GOOD_OCV", PM8921_BMS_GOOD_OCV),
  251. SINGLE_IRQ_RESOURCE("PM8921_BMS_VSENSE_AVG", PM8921_BMS_VSENSE_AVG),
  252. };
  253. static struct mfd_cell charger_cell __devinitdata = {
  254. .name = PM8921_CHARGER_DEV_NAME,
  255. .id = -1,
  256. .resources = charger_cell_resources,
  257. .num_resources = ARRAY_SIZE(charger_cell_resources),
  258. };
  259. static struct mfd_cell bms_cell __devinitdata = {
  260. .name = PM8921_BMS_DEV_NAME,
  261. .id = -1,
  262. .resources = bms_cell_resources,
  263. .num_resources = ARRAY_SIZE(bms_cell_resources),
  264. };
  265. static struct mfd_cell misc_cell __devinitdata = {
  266. .name = PM8XXX_MISC_DEV_NAME,
  267. .id = -1,
  268. };
  269. static struct mfd_cell leds_cell __devinitdata = {
  270. .name = PM8XXX_LEDS_DEV_NAME,
  271. .id = -1,
  272. };
  273. static const struct resource thermal_alarm_cell_resources[] __devinitconst = {
  274. SINGLE_IRQ_RESOURCE("pm8921_tempstat_irq", PM8921_TEMPSTAT_IRQ),
  275. SINGLE_IRQ_RESOURCE("pm8921_overtemp_irq", PM8921_OVERTEMP_IRQ),
  276. };
  277. static struct pm8xxx_tm_core_data thermal_alarm_cdata = {
  278. .adc_channel = CHANNEL_DIE_TEMP,
  279. .adc_type = PM8XXX_TM_ADC_PM8XXX_ADC,
  280. .reg_addr_temp_alarm_ctrl = REG_TEMP_ALARM_CTRL,
  281. .reg_addr_temp_alarm_pwm = REG_TEMP_ALARM_PWM,
  282. .tm_name = "pm8921_tz",
  283. .irq_name_temp_stat = "pm8921_tempstat_irq",
  284. .irq_name_over_temp = "pm8921_overtemp_irq",
  285. };
  286. static struct mfd_cell thermal_alarm_cell __devinitdata = {
  287. .name = PM8XXX_TM_DEV_NAME,
  288. .id = -1,
  289. .resources = thermal_alarm_cell_resources,
  290. .num_resources = ARRAY_SIZE(thermal_alarm_cell_resources),
  291. .platform_data = &thermal_alarm_cdata,
  292. .pdata_size = sizeof(struct pm8xxx_tm_core_data),
  293. };
  294. static const struct resource batt_alarm_cell_resources[] __devinitconst = {
  295. SINGLE_IRQ_RESOURCE("pm8921_batt_alarm_irq", PM8921_BATT_ALARM_IRQ),
  296. };
  297. static struct pm8xxx_batt_alarm_core_data batt_alarm_cdata = {
  298. .irq_name = "pm8921_batt_alarm_irq",
  299. .reg_addr_threshold = REG_BATT_ALARM_THRESH,
  300. .reg_addr_ctrl1 = REG_BATT_ALARM_CTRL1,
  301. .reg_addr_ctrl2 = REG_BATT_ALARM_CTRL2,
  302. .reg_addr_pwm_ctrl = REG_BATT_ALARM_PWM_CTRL,
  303. };
  304. static struct mfd_cell batt_alarm_cell __devinitdata = {
  305. .name = PM8XXX_BATT_ALARM_DEV_NAME,
  306. .id = -1,
  307. .resources = batt_alarm_cell_resources,
  308. .num_resources = ARRAY_SIZE(batt_alarm_cell_resources),
  309. .platform_data = &batt_alarm_cdata,
  310. .pdata_size = sizeof(struct pm8xxx_batt_alarm_core_data),
  311. };
  312. static const struct resource ccadc_cell_resources[] __devinitconst = {
  313. SINGLE_IRQ_RESOURCE("PM8921_BMS_CCADC_EOC", PM8921_BMS_CCADC_EOC),
  314. };
  315. static struct mfd_cell ccadc_cell __devinitdata = {
  316. .name = PM8XXX_CCADC_DEV_NAME,
  317. .id = -1,
  318. .resources = ccadc_cell_resources,
  319. .num_resources = ARRAY_SIZE(ccadc_cell_resources),
  320. };
  321. static struct mfd_cell vibrator_cell __devinitdata = {
  322. .name = PM8XXX_VIBRATOR_DEV_NAME,
  323. .id = -1,
  324. };
  325. static struct pm8xxx_vreg regulator_data[] = {
  326. /* name pc_name ctrl test hpm_min */
  327. NLDO("8921_l1", "8921_l1_pc", 0x0AE, 0x0AF, LDO_150),
  328. NLDO("8921_l2", "8921_l2_pc", 0x0B0, 0x0B1, LDO_150),
  329. PLDO("8921_l3", "8921_l3_pc", 0x0B2, 0x0B3, LDO_150),
  330. PLDO("8921_l4", "8921_l4_pc", 0x0B4, 0x0B5, LDO_50),
  331. PLDO("8921_l5", "8921_l5_pc", 0x0B6, 0x0B7, LDO_300),
  332. PLDO("8921_l6", "8921_l6_pc", 0x0B8, 0x0B9, LDO_600),
  333. PLDO("8921_l7", "8921_l7_pc", 0x0BA, 0x0BB, LDO_150),
  334. PLDO("8921_l8", "8921_l8_pc", 0x0BC, 0x0BD, LDO_300),
  335. PLDO("8921_l9", "8921_l9_pc", 0x0BE, 0x0BF, LDO_300),
  336. PLDO("8921_l10", "8921_l10_pc", 0x0C0, 0x0C1, LDO_600),
  337. PLDO("8921_l11", "8921_l11_pc", 0x0C2, 0x0C3, LDO_150),
  338. NLDO("8921_l12", "8921_l12_pc", 0x0C4, 0x0C5, LDO_150),
  339. PLDO("8921_l14", "8921_l14_pc", 0x0C8, 0x0C9, LDO_50),
  340. PLDO("8921_l15", "8921_l15_pc", 0x0CA, 0x0CB, LDO_150),
  341. PLDO("8921_l16", "8921_l16_pc", 0x0CC, 0x0CD, LDO_300),
  342. PLDO("8921_l17", "8921_l17_pc", 0x0CE, 0x0CF, LDO_150),
  343. NLDO("8921_l18", "8921_l18_pc", 0x0D0, 0x0D1, LDO_150),
  344. PLDO("8921_l21", "8921_l21_pc", 0x0D6, 0x0D7, LDO_150),
  345. PLDO("8921_l22", "8921_l22_pc", 0x0D8, 0x0D9, LDO_150),
  346. PLDO("8921_l23", "8921_l23_pc", 0x0DA, 0x0DB, LDO_150),
  347. NLDO1200("8921_l24", 0x0DC, 0x0DD, LDO_1200),
  348. NLDO1200("8921_l25", 0x0DE, 0x0DF, LDO_1200),
  349. NLDO1200("8921_l26", 0x0E0, 0x0E1, LDO_1200),
  350. NLDO1200("8921_l27", 0x0E2, 0x0E3, LDO_1200),
  351. NLDO1200("8921_l28", 0x0E4, 0x0E5, LDO_1200),
  352. PLDO("8921_l29", "8921_l29_pc", 0x0E6, 0x0E7, LDO_150),
  353. /* name pc_name ctrl test2 clk sleep hpm_min */
  354. SMPS("8921_s1", "8921_s1_pc", 0x1D0, 0x1D5, 0x009, 0x1D2, SMPS_1500),
  355. SMPS("8921_s2", "8921_s2_pc", 0x1D8, 0x1DD, 0x00A, 0x1DA, SMPS_1500),
  356. SMPS("8921_s3", "8921_s3_pc", 0x1E0, 0x1E5, 0x00B, 0x1E2, SMPS_1500),
  357. SMPS("8921_s4", "8921_s4_pc", 0x1E8, 0x1ED, 0x011, 0x1EA, SMPS_1500),
  358. /* name ctrl fts_cnfg1 pfm pwr_cnfg hpm_min */
  359. FTSMPS("8921_s5", 0x025, 0x02E, 0x026, 0x032, SMPS_2000),
  360. FTSMPS("8921_s6", 0x036, 0x03F, 0x037, 0x043, SMPS_2000),
  361. /* name pc_name ctrl test2 clk sleep hpm_min */
  362. SMPS("8921_s7", "8921_s7_pc", 0x1F0, 0x1F5, 0x012, 0x1F2, SMPS_1500),
  363. SMPS("8921_s8", "8921_s8_pc", 0x1F8, 0x1FD, 0x013, 0x1FA, SMPS_1500),
  364. /* name pc_name ctrl test */
  365. VS("8921_lvs1", "8921_lvs1_pc", 0x060, 0x061),
  366. VS300("8921_lvs2", 0x062, 0x063),
  367. VS("8921_lvs3", "8921_lvs3_pc", 0x064, 0x065),
  368. VS("8921_lvs4", "8921_lvs4_pc", 0x066, 0x067),
  369. VS("8921_lvs5", "8921_lvs5_pc", 0x068, 0x069),
  370. VS("8921_lvs6", "8921_lvs6_pc", 0x06A, 0x06B),
  371. VS("8921_lvs7", "8921_lvs7_pc", 0x06C, 0x06D),
  372. VS300("8921_usb_otg", 0x06E, 0x06F),
  373. VS300("8921_hdmi_mvs", 0x070, 0x071),
  374. /* name ctrl */
  375. NCP("8921_ncp", 0x090),
  376. };
  377. /*
  378. * PM8917 adds 6 LDOs and a boost regulator beyond those available on PM8921.
  379. * It also replaces SMPS 3 with FTSMPS 3. PM8917 does not have an NCP.
  380. */
  381. static struct pm8xxx_vreg pm8917_regulator_data[] = {
  382. /* name pc_name ctrl test hpm_min */
  383. PLDO("8917_l30", "8917_l30_pc", 0x0A3, 0x0A4, LDO_150),
  384. PLDO("8917_l31", "8917_l31_pc", 0x0A5, 0x0A6, LDO_150),
  385. PLDO("8917_l32", "8917_l32_pc", 0x0A7, 0x0A8, LDO_150),
  386. PLDO("8917_l33", "8917_l33_pc", 0x0C6, 0x0C7, LDO_150),
  387. PLDO("8917_l34", "8917_l34_pc", 0x0D2, 0x0D3, LDO_150),
  388. PLDO("8917_l35", "8917_l35_pc", 0x0D4, 0x0D5, LDO_300),
  389. PLDO("8917_l36", "8917_l36_pc", 0x0A9, 0x0AA, LDO_50),
  390. /* name ctrl */
  391. BOOST("8917_boost", 0x04B),
  392. };
  393. #define MAX_NAME_COMPARISON_LEN 32
  394. static int __devinit match_regulator(enum pm8xxx_version version,
  395. struct pm8xxx_regulator_core_platform_data *core_data, const char *name)
  396. {
  397. int found = 0;
  398. int i;
  399. for (i = 0; i < ARRAY_SIZE(regulator_data); i++) {
  400. if (regulator_data[i].rdesc.name
  401. && strncmp(regulator_data[i].rdesc.name, name,
  402. MAX_NAME_COMPARISON_LEN) == 0) {
  403. core_data->is_pin_controlled = false;
  404. core_data->vreg = &regulator_data[i];
  405. found = 1;
  406. break;
  407. } else if (regulator_data[i].rdesc_pc.name
  408. && strncmp(regulator_data[i].rdesc_pc.name, name,
  409. MAX_NAME_COMPARISON_LEN) == 0) {
  410. core_data->is_pin_controlled = true;
  411. core_data->vreg = &regulator_data[i];
  412. found = 1;
  413. break;
  414. }
  415. }
  416. if (version == PM8XXX_VERSION_8917) {
  417. for (i = 0; i < ARRAY_SIZE(pm8917_regulator_data); i++) {
  418. if (pm8917_regulator_data[i].rdesc.name
  419. && strncmp(pm8917_regulator_data[i].rdesc.name,
  420. name, MAX_NAME_COMPARISON_LEN) == 0) {
  421. core_data->is_pin_controlled = false;
  422. core_data->vreg = &pm8917_regulator_data[i];
  423. found = 1;
  424. break;
  425. } else if (pm8917_regulator_data[i].rdesc_pc.name
  426. && strncmp(pm8917_regulator_data[i].rdesc_pc.name,
  427. name, MAX_NAME_COMPARISON_LEN) == 0) {
  428. core_data->is_pin_controlled = true;
  429. core_data->vreg = &pm8917_regulator_data[i];
  430. found = 1;
  431. break;
  432. }
  433. }
  434. }
  435. if (!found)
  436. pr_err("could not find a match for regulator: %s\n", name);
  437. return found;
  438. }
  439. static int __devinit
  440. pm8921_add_regulators(const struct pm8921_platform_data *pdata,
  441. struct pm8921 *pmic, int irq_base)
  442. {
  443. int ret = 0;
  444. struct mfd_cell *mfd_regulators;
  445. struct pm8xxx_regulator_core_platform_data *cdata;
  446. enum pm8xxx_version version;
  447. int i;
  448. version = pm8xxx_get_version(pmic->dev);
  449. /* Add one device for each regulator used by the board. */
  450. mfd_regulators = kzalloc(sizeof(struct mfd_cell)
  451. * (pdata->num_regulators), GFP_KERNEL);
  452. if (!mfd_regulators) {
  453. pr_err("Cannot allocate %d bytes for pm8921 regulator "
  454. "mfd cells\n", sizeof(struct mfd_cell)
  455. * (pdata->num_regulators));
  456. return -ENOMEM;
  457. }
  458. cdata = kzalloc(sizeof(struct pm8xxx_regulator_core_platform_data)
  459. * pdata->num_regulators, GFP_KERNEL);
  460. if (!cdata) {
  461. pr_err("Cannot allocate %d bytes for pm8921 regulator "
  462. "core data\n", pdata->num_regulators
  463. * sizeof(struct pm8xxx_regulator_core_platform_data));
  464. kfree(mfd_regulators);
  465. return -ENOMEM;
  466. }
  467. for (i = 0; i < ARRAY_SIZE(regulator_data); i++)
  468. mutex_init(&regulator_data[i].pc_lock);
  469. for (i = 0; i < ARRAY_SIZE(pm8917_regulator_data); i++)
  470. mutex_init(&pm8917_regulator_data[i].pc_lock);
  471. for (i = 0; i < pdata->num_regulators; i++) {
  472. if (!pdata->regulator_pdatas[i].init_data.constraints.name) {
  473. pr_err("name missing for regulator %d\n", i);
  474. ret = -EINVAL;
  475. goto bail;
  476. }
  477. if (!match_regulator(version, &cdata[i],
  478. pdata->regulator_pdatas[i].init_data.constraints.name)) {
  479. ret = -ENODEV;
  480. goto bail;
  481. }
  482. cdata[i].pdata = &(pdata->regulator_pdatas[i]);
  483. mfd_regulators[i].name = PM8XXX_REGULATOR_DEV_NAME;
  484. mfd_regulators[i].id = cdata[i].pdata->id;
  485. mfd_regulators[i].platform_data = &cdata[i];
  486. mfd_regulators[i].pdata_size =
  487. sizeof(struct pm8xxx_regulator_core_platform_data);
  488. }
  489. ret = mfd_add_devices(pmic->dev, 0, mfd_regulators,
  490. pdata->num_regulators, NULL, irq_base);
  491. if (ret)
  492. goto bail;
  493. pmic->mfd_regulators = mfd_regulators;
  494. pmic->regulator_cdata = cdata;
  495. return ret;
  496. bail:
  497. for (i = 0; i < ARRAY_SIZE(regulator_data); i++)
  498. mutex_destroy(&regulator_data[i].pc_lock);
  499. for (i = 0; i < ARRAY_SIZE(pm8917_regulator_data); i++)
  500. mutex_destroy(&pm8917_regulator_data[i].pc_lock);
  501. kfree(mfd_regulators);
  502. kfree(cdata);
  503. return ret;
  504. }
  505. static int __devinit
  506. pm8921_add_subdevices(const struct pm8921_platform_data *pdata,
  507. struct pm8921 *pmic)
  508. {
  509. int ret = 0, irq_base = 0;
  510. struct pm_irq_chip *irq_chip;
  511. enum pm8xxx_version version;
  512. version = pm8xxx_get_version(pmic->dev);
  513. if (pdata->irq_pdata) {
  514. pdata->irq_pdata->irq_cdata.nirqs = PM8921_NR_IRQS;
  515. pdata->irq_pdata->irq_cdata.base_addr = REG_IRQ_BASE;
  516. irq_base = pdata->irq_pdata->irq_base;
  517. irq_chip = pm8xxx_irq_init(pmic->dev, pdata->irq_pdata);
  518. if (IS_ERR(irq_chip)) {
  519. pr_err("Failed to init interrupts ret=%ld\n",
  520. PTR_ERR(irq_chip));
  521. return PTR_ERR(irq_chip);
  522. }
  523. pmic->irq_chip = irq_chip;
  524. }
  525. if (pdata->gpio_pdata) {
  526. if (version == PM8XXX_VERSION_8917) {
  527. gpio_cell_resources[0].end = gpio_cell_resources[0].end
  528. + PM8917_NR_GPIOS
  529. - PM8921_NR_GPIOS;
  530. pdata->gpio_pdata->gpio_cdata.ngpios = PM8917_NR_GPIOS;
  531. } else {
  532. pdata->gpio_pdata->gpio_cdata.ngpios = PM8921_NR_GPIOS;
  533. }
  534. gpio_cell.platform_data = pdata->gpio_pdata;
  535. gpio_cell.pdata_size = sizeof(struct pm8xxx_gpio_platform_data);
  536. ret = mfd_add_devices(pmic->dev, 0, &gpio_cell, 1,
  537. NULL, irq_base);
  538. if (ret) {
  539. pr_err("Failed to add gpio subdevice ret=%d\n", ret);
  540. goto bail;
  541. }
  542. }
  543. if (pdata->mpp_pdata) {
  544. if (version == PM8XXX_VERSION_8917) {
  545. mpp_cell_resources[0].end = mpp_cell_resources[0].end
  546. + PM8917_NR_MPPS
  547. - PM8921_NR_MPPS;
  548. pdata->mpp_pdata->core_data.nmpps = PM8917_NR_MPPS;
  549. } else {
  550. pdata->mpp_pdata->core_data.nmpps = PM8921_NR_MPPS;
  551. }
  552. pdata->mpp_pdata->core_data.base_addr = REG_MPP_BASE;
  553. mpp_cell.platform_data = pdata->mpp_pdata;
  554. mpp_cell.pdata_size = sizeof(struct pm8xxx_mpp_platform_data);
  555. ret = mfd_add_devices(pmic->dev, 0, &mpp_cell, 1, NULL,
  556. irq_base);
  557. if (ret) {
  558. pr_err("Failed to add mpp subdevice ret=%d\n", ret);
  559. goto bail;
  560. }
  561. }
  562. if (pdata->rtc_pdata) {
  563. rtc_cell.platform_data = pdata->rtc_pdata;
  564. rtc_cell.pdata_size = sizeof(struct pm8xxx_rtc_platform_data);
  565. ret = mfd_add_devices(pmic->dev, 0, &rtc_cell, 1, NULL,
  566. irq_base);
  567. if (ret) {
  568. pr_err("Failed to add rtc subdevice ret=%d\n", ret);
  569. goto bail;
  570. }
  571. }
  572. if (pdata->pwrkey_pdata) {
  573. pwrkey_cell.platform_data = pdata->pwrkey_pdata;
  574. pwrkey_cell.pdata_size =
  575. sizeof(struct pm8xxx_pwrkey_platform_data);
  576. ret = mfd_add_devices(pmic->dev, 0, &pwrkey_cell, 1, NULL,
  577. irq_base);
  578. if (ret) {
  579. pr_err("Failed to add pwrkey subdevice ret=%d\n", ret);
  580. goto bail;
  581. }
  582. }
  583. if (pdata->keypad_pdata) {
  584. keypad_cell.platform_data = pdata->keypad_pdata;
  585. keypad_cell.pdata_size =
  586. sizeof(struct pm8xxx_keypad_platform_data);
  587. ret = mfd_add_devices(pmic->dev, 0, &keypad_cell, 1, NULL,
  588. irq_base);
  589. if (ret) {
  590. pr_err("Failed to add keypad subdevice ret=%d\n", ret);
  591. goto bail;
  592. }
  593. }
  594. if (pdata->charger_pdata) {
  595. pdata->charger_pdata->charger_cdata.vbat_channel = CHANNEL_VBAT;
  596. pdata->charger_pdata->charger_cdata.batt_temp_channel
  597. = CHANNEL_BATT_THERM;
  598. pdata->charger_pdata->charger_cdata.batt_id_channel
  599. = CHANNEL_BATT_ID;
  600. charger_cell.platform_data = pdata->charger_pdata;
  601. charger_cell.pdata_size =
  602. sizeof(struct pm8921_charger_platform_data);
  603. ret = mfd_add_devices(pmic->dev, 0, &charger_cell, 1, NULL,
  604. irq_base);
  605. if (ret) {
  606. pr_err("Failed to add charger subdevice ret=%d\n", ret);
  607. goto bail;
  608. }
  609. }
  610. if (pdata->adc_pdata) {
  611. adc_cell.platform_data = pdata->adc_pdata;
  612. adc_cell.pdata_size =
  613. sizeof(struct pm8xxx_adc_platform_data);
  614. ret = mfd_add_devices(pmic->dev, 0, &adc_cell, 1, NULL,
  615. irq_base);
  616. if (ret) {
  617. pr_err("Failed to add regulator subdevices ret=%d\n",
  618. ret);
  619. }
  620. }
  621. if (pdata->bms_pdata) {
  622. pdata->bms_pdata->bms_cdata.batt_temp_channel
  623. = CHANNEL_BATT_THERM;
  624. pdata->bms_pdata->bms_cdata.vbat_channel = CHANNEL_VBAT;
  625. pdata->bms_pdata->bms_cdata.ref625mv_channel = CHANNEL_625MV;
  626. pdata->bms_pdata->bms_cdata.ref1p25v_channel = CHANNEL_125V;
  627. pdata->bms_pdata->bms_cdata.batt_id_channel = CHANNEL_BATT_ID;
  628. bms_cell.platform_data = pdata->bms_pdata;
  629. bms_cell.pdata_size = sizeof(struct pm8921_bms_platform_data);
  630. ret = mfd_add_devices(pmic->dev, 0, &bms_cell, 1, NULL,
  631. irq_base);
  632. if (ret) {
  633. pr_err("Failed to add bms subdevice ret=%d\n", ret);
  634. goto bail;
  635. }
  636. }
  637. if (pdata->num_regulators > 0 && pdata->regulator_pdatas) {
  638. ret = pm8921_add_regulators(pdata, pmic, irq_base);
  639. if (ret) {
  640. pr_err("Failed to add regulator subdevices ret=%d\n",
  641. ret);
  642. goto bail;
  643. }
  644. }
  645. ret = mfd_add_devices(pmic->dev, 0, &debugfs_cell, 1, NULL, irq_base);
  646. if (ret) {
  647. pr_err("Failed to add debugfs subdevice ret=%d\n", ret);
  648. goto bail;
  649. }
  650. if (pdata->misc_pdata) {
  651. misc_cell.platform_data = pdata->misc_pdata;
  652. misc_cell.pdata_size = sizeof(struct pm8xxx_misc_platform_data);
  653. ret = mfd_add_devices(pmic->dev, 0, &misc_cell, 1, NULL,
  654. irq_base);
  655. if (ret) {
  656. pr_err("Failed to add misc subdevice ret=%d\n", ret);
  657. goto bail;
  658. }
  659. }
  660. ret = mfd_add_devices(pmic->dev, 0, &thermal_alarm_cell, 1, NULL,
  661. irq_base);
  662. if (ret) {
  663. pr_err("Failed to add thermal alarm subdevice ret=%d\n",
  664. ret);
  665. goto bail;
  666. }
  667. ret = mfd_add_devices(pmic->dev, 0, &batt_alarm_cell, 1, NULL,
  668. irq_base);
  669. if (ret) {
  670. pr_err("Failed to add battery alarm subdevice ret=%d\n",
  671. ret);
  672. goto bail;
  673. }
  674. if (version != PM8XXX_VERSION_8917) {
  675. if (pdata->pwm_pdata) {
  676. pwm_cell.platform_data = pdata->pwm_pdata;
  677. pwm_cell.pdata_size =
  678. sizeof(struct pm8xxx_pwm_platform_data);
  679. }
  680. ret = mfd_add_devices(pmic->dev, 0, &pwm_cell, 1, NULL, 0);
  681. if (ret) {
  682. pr_err("Failed to add pwm subdevice ret=%d\n", ret);
  683. goto bail;
  684. }
  685. if (pdata->leds_pdata) {
  686. leds_cell.platform_data = pdata->leds_pdata;
  687. leds_cell.pdata_size =
  688. sizeof(struct pm8xxx_led_platform_data);
  689. ret = mfd_add_devices(pmic->dev, 0, &leds_cell,
  690. 1, NULL, 0);
  691. if (ret) {
  692. pr_err("Failed to add leds subdevice ret=%d\n",
  693. ret);
  694. goto bail;
  695. }
  696. }
  697. if (pdata->vibrator_pdata) {
  698. vibrator_cell.platform_data = pdata->vibrator_pdata;
  699. vibrator_cell.pdata_size =
  700. sizeof(struct pm8xxx_vibrator_platform_data);
  701. ret = mfd_add_devices(pmic->dev, 0, &vibrator_cell,
  702. 1, NULL, 0);
  703. if (ret) {
  704. pr_err("Failed to add vibrator ret=%d\n", ret);
  705. goto bail;
  706. }
  707. }
  708. }
  709. if (pdata->ccadc_pdata) {
  710. pdata->ccadc_pdata->ccadc_cdata.batt_temp_channel
  711. = CHANNEL_BATT_THERM;
  712. ccadc_cell.platform_data = pdata->ccadc_pdata;
  713. ccadc_cell.pdata_size =
  714. sizeof(struct pm8xxx_ccadc_platform_data);
  715. ret = mfd_add_devices(pmic->dev, 0, &ccadc_cell, 1, NULL,
  716. irq_base);
  717. if (ret) {
  718. pr_err("Failed to add ccadc subdevice ret=%d\n", ret);
  719. goto bail;
  720. }
  721. }
  722. return 0;
  723. bail:
  724. if (pmic->irq_chip) {
  725. pm8xxx_irq_exit(pmic->irq_chip);
  726. pmic->irq_chip = NULL;
  727. }
  728. return ret;
  729. }
  730. static const char * const pm8921_rev_names[] = {
  731. [PM8XXX_REVISION_8921_TEST] = "test",
  732. [PM8XXX_REVISION_8921_1p0] = "1.0",
  733. [PM8XXX_REVISION_8921_1p1] = "1.1",
  734. [PM8XXX_REVISION_8921_2p0] = "2.0",
  735. [PM8XXX_REVISION_8921_3p0] = "3.0",
  736. [PM8XXX_REVISION_8921_3p1] = "3.1",
  737. };
  738. static const char * const pm8922_rev_names[] = {
  739. [PM8XXX_REVISION_8922_TEST] = "test",
  740. [PM8XXX_REVISION_8922_1p0] = "1.0",
  741. [PM8XXX_REVISION_8922_1p1] = "1.1",
  742. [PM8XXX_REVISION_8922_2p0] = "2.0",
  743. };
  744. static const char * const pm8917_rev_names[] = {
  745. [PM8XXX_REVISION_8917_TEST] = "test",
  746. [PM8XXX_REVISION_8917_1p0] = "1.0",
  747. };
  748. static int __devinit pm8921_probe(struct platform_device *pdev)
  749. {
  750. const struct pm8921_platform_data *pdata = pdev->dev.platform_data;
  751. const char *revision_name = "unknown";
  752. struct pm8921 *pmic;
  753. enum pm8xxx_version version;
  754. int revision;
  755. int rc;
  756. u8 val;
  757. if (!pdata) {
  758. pr_err("missing platform data\n");
  759. return -EINVAL;
  760. }
  761. pmic = kzalloc(sizeof(struct pm8921), GFP_KERNEL);
  762. if (!pmic) {
  763. pr_err("Cannot alloc pm8921 struct\n");
  764. return -ENOMEM;
  765. }
  766. /* Read PMIC chip revision */
  767. rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV, &val, sizeof(val));
  768. if (rc) {
  769. pr_err("Failed to read hw rev reg %d:rc=%d\n", REG_HWREV, rc);
  770. goto err_read_rev;
  771. }
  772. pr_info("PMIC revision 1: %02X\n", val);
  773. pmic->rev_registers = val;
  774. /* Read PMIC chip revision 2 */
  775. rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV_2, &val, sizeof(val));
  776. if (rc) {
  777. pr_err("Failed to read hw rev 2 reg %d:rc=%d\n",
  778. REG_HWREV_2, rc);
  779. goto err_read_rev;
  780. }
  781. pr_info("PMIC revision 2: %02X\n", val);
  782. pmic->rev_registers |= val << BITS_PER_BYTE;
  783. pmic->dev = &pdev->dev;
  784. pm8921_drvdata.pm_chip_data = pmic;
  785. platform_set_drvdata(pdev, &pm8921_drvdata);
  786. /* Print out human readable version and revision names. */
  787. version = pm8xxx_get_version(pmic->dev);
  788. revision = pm8xxx_get_revision(pmic->dev);
  789. if (version == PM8XXX_VERSION_8921) {
  790. if (revision >= 0 && revision < ARRAY_SIZE(pm8921_rev_names))
  791. revision_name = pm8921_rev_names[revision];
  792. pr_info("PMIC version: PM8921 rev %s\n", revision_name);
  793. } else if (version == PM8XXX_VERSION_8922) {
  794. if (revision >= 0 && revision < ARRAY_SIZE(pm8922_rev_names))
  795. revision_name = pm8922_rev_names[revision];
  796. pr_info("PMIC version: PM8922 rev %s\n", revision_name);
  797. } else if (version == PM8XXX_VERSION_8917) {
  798. if (revision >= 0 && revision < ARRAY_SIZE(pm8917_rev_names))
  799. revision_name = pm8917_rev_names[revision];
  800. pr_info("PMIC version: PM8917 rev %s\n", revision_name);
  801. } else {
  802. WARN_ON(version != PM8XXX_VERSION_8921
  803. && version != PM8XXX_VERSION_8922
  804. && version != PM8XXX_VERSION_8917);
  805. }
  806. /* Log human readable restart reason */
  807. rc = msm_ssbi_read(pdev->dev.parent, REG_PM8921_PON_CNTRL_3, &val, 1);
  808. if (rc) {
  809. pr_err("Cannot read restart reason rc=%d\n", rc);
  810. goto err_read_rev;
  811. }
  812. val &= PM8XXX_RESTART_REASON_MASK;
  813. pr_info("PMIC Restart Reason: %s\n", pm8xxx_restart_reason_str[val]);
  814. pmic->restart_reason = val;
  815. rc = pm8921_add_subdevices(pdata, pmic);
  816. if (rc) {
  817. pr_err("Cannot add subdevices rc=%d\n", rc);
  818. goto err;
  819. }
  820. /* gpio might not work if no irq device is found */
  821. WARN_ON(pmic->irq_chip == NULL);
  822. return 0;
  823. err:
  824. mfd_remove_devices(pmic->dev);
  825. platform_set_drvdata(pdev, NULL);
  826. kfree(pmic->mfd_regulators);
  827. kfree(pmic->regulator_cdata);
  828. err_read_rev:
  829. kfree(pmic);
  830. return rc;
  831. }
  832. static int __devexit pm8921_remove(struct platform_device *pdev)
  833. {
  834. struct pm8xxx_drvdata *drvdata;
  835. struct pm8921 *pmic = NULL;
  836. int i;
  837. drvdata = platform_get_drvdata(pdev);
  838. if (drvdata)
  839. pmic = drvdata->pm_chip_data;
  840. if (pmic) {
  841. if (pmic->dev)
  842. mfd_remove_devices(pmic->dev);
  843. if (pmic->irq_chip)
  844. pm8xxx_irq_exit(pmic->irq_chip);
  845. if (pmic->mfd_regulators) {
  846. for (i = 0; i < ARRAY_SIZE(regulator_data); i++)
  847. mutex_destroy(&regulator_data[i].pc_lock);
  848. for (i = 0; i < ARRAY_SIZE(pm8917_regulator_data); i++)
  849. mutex_destroy(
  850. &pm8917_regulator_data[i].pc_lock);
  851. }
  852. kfree(pmic->mfd_regulators);
  853. kfree(pmic->regulator_cdata);
  854. kfree(pmic);
  855. }
  856. platform_set_drvdata(pdev, NULL);
  857. return 0;
  858. }
  859. static struct platform_driver pm8921_driver = {
  860. .probe = pm8921_probe,
  861. .remove = __devexit_p(pm8921_remove),
  862. .driver = {
  863. .name = "pm8921-core",
  864. .owner = THIS_MODULE,
  865. },
  866. };
  867. static int __init pm8921_init(void)
  868. {
  869. return platform_driver_register(&pm8921_driver);
  870. }
  871. postcore_initcall(pm8921_init);
  872. static void __exit pm8921_exit(void)
  873. {
  874. platform_driver_unregister(&pm8921_driver);
  875. }
  876. module_exit(pm8921_exit);
  877. MODULE_LICENSE("GPL v2");
  878. MODULE_DESCRIPTION("PMIC 8921 core driver");
  879. MODULE_VERSION("1.0");
  880. MODULE_ALIAS("platform:pm8921-core");