da903x.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /*
  2. * Regulators driver for Dialog Semiconductor DA903x
  3. *
  4. * Copyright (C) 2006-2008 Marvell International Ltd.
  5. * Copyright (C) 2008 Compulab Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/err.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/regulator/driver.h>
  16. #include <linux/regulator/machine.h>
  17. #include <linux/mfd/da903x.h>
  18. /* DA9030 Registers */
  19. #define DA9030_INVAL (-1)
  20. #define DA9030_LDO1011 (0x10)
  21. #define DA9030_LDO15 (0x11)
  22. #define DA9030_LDO1416 (0x12)
  23. #define DA9030_LDO1819 (0x13)
  24. #define DA9030_LDO17 (0x14)
  25. #define DA9030_BUCK2DVM1 (0x15)
  26. #define DA9030_BUCK2DVM2 (0x16)
  27. #define DA9030_RCTL11 (0x17)
  28. #define DA9030_RCTL21 (0x18)
  29. #define DA9030_LDO1 (0x90)
  30. #define DA9030_LDO23 (0x91)
  31. #define DA9030_LDO45 (0x92)
  32. #define DA9030_LDO6 (0x93)
  33. #define DA9030_LDO78 (0x94)
  34. #define DA9030_LDO912 (0x95)
  35. #define DA9030_BUCK (0x96)
  36. #define DA9030_RCTL12 (0x97)
  37. #define DA9030_RCTL22 (0x98)
  38. #define DA9030_LDO_UNLOCK (0xa0)
  39. #define DA9030_LDO_UNLOCK_MASK (0xe0)
  40. #define DA9034_OVER1 (0x10)
  41. /* DA9034 Registers */
  42. #define DA9034_INVAL (-1)
  43. #define DA9034_OVER2 (0x11)
  44. #define DA9034_OVER3 (0x12)
  45. #define DA9034_LDO643 (0x13)
  46. #define DA9034_LDO987 (0x14)
  47. #define DA9034_LDO1110 (0x15)
  48. #define DA9034_LDO1312 (0x16)
  49. #define DA9034_LDO1514 (0x17)
  50. #define DA9034_VCC1 (0x20)
  51. #define DA9034_ADTV1 (0x23)
  52. #define DA9034_ADTV2 (0x24)
  53. #define DA9034_AVRC (0x25)
  54. #define DA9034_CDTV1 (0x26)
  55. #define DA9034_CDTV2 (0x27)
  56. #define DA9034_CVRC (0x28)
  57. #define DA9034_SDTV1 (0x29)
  58. #define DA9034_SDTV2 (0x2a)
  59. #define DA9034_SVRC (0x2b)
  60. #define DA9034_MDTV1 (0x32)
  61. #define DA9034_MDTV2 (0x33)
  62. #define DA9034_MVRC (0x34)
  63. /* DA9035 Registers. DA9034 Registers are comptabile to DA9035. */
  64. #define DA9035_OVER3 (0x12)
  65. #define DA9035_VCC2 (0x1f)
  66. #define DA9035_3DTV1 (0x2c)
  67. #define DA9035_3DTV2 (0x2d)
  68. #define DA9035_3VRC (0x2e)
  69. #define DA9035_AUTOSKIP (0x2f)
  70. struct da903x_regulator_info {
  71. struct regulator_desc desc;
  72. int min_uV;
  73. int max_uV;
  74. int step_uV;
  75. int vol_reg;
  76. int vol_shift;
  77. int vol_nbits;
  78. int update_reg;
  79. int update_bit;
  80. int enable_reg;
  81. int enable_bit;
  82. };
  83. static int da9034_ldo12_data[] = { 1700, 1750, 1800, 1850, 1900, 1950,
  84. 2000, 2050, 2700, 2750, 2800, 2850,
  85. 2900, 2950, 3000, 3050 };
  86. static inline struct device *to_da903x_dev(struct regulator_dev *rdev)
  87. {
  88. return rdev_get_dev(rdev)->parent->parent;
  89. }
  90. static inline int check_range(struct da903x_regulator_info *info,
  91. int min_uV, int max_uV)
  92. {
  93. if (min_uV < info->min_uV || min_uV > info->max_uV)
  94. return -EINVAL;
  95. return 0;
  96. }
  97. /* DA9030/DA9034 common operations */
  98. static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
  99. int min_uV, int max_uV)
  100. {
  101. struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
  102. struct device *da9034_dev = to_da903x_dev(rdev);
  103. uint8_t val, mask;
  104. if (check_range(info, min_uV, max_uV)) {
  105. pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
  106. return -EINVAL;
  107. }
  108. val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
  109. val <<= info->vol_shift;
  110. mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
  111. return da903x_update(da9034_dev, info->vol_reg, val, mask);
  112. }
  113. static int da903x_get_voltage(struct regulator_dev *rdev)
  114. {
  115. struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
  116. struct device *da9034_dev = to_da903x_dev(rdev);
  117. uint8_t val, mask;
  118. int ret;
  119. ret = da903x_read(da9034_dev, info->vol_reg, &val);
  120. if (ret)
  121. return ret;
  122. mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
  123. val = (val & mask) >> info->vol_shift;
  124. return info->min_uV + info->step_uV * val;
  125. }
  126. static int da903x_enable(struct regulator_dev *rdev)
  127. {
  128. struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
  129. struct device *da9034_dev = to_da903x_dev(rdev);
  130. return da903x_set_bits(da9034_dev, info->enable_reg,
  131. 1 << info->enable_bit);
  132. }
  133. static int da903x_disable(struct regulator_dev *rdev)
  134. {
  135. struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
  136. struct device *da9034_dev = to_da903x_dev(rdev);
  137. return da903x_clr_bits(da9034_dev, info->enable_reg,
  138. 1 << info->enable_bit);
  139. }
  140. static int da903x_is_enabled(struct regulator_dev *rdev)
  141. {
  142. struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
  143. struct device *da9034_dev = to_da903x_dev(rdev);
  144. uint8_t reg_val;
  145. int ret;
  146. ret = da903x_read(da9034_dev, info->enable_reg, &reg_val);
  147. if (ret)
  148. return ret;
  149. return !!(reg_val & (1 << info->enable_bit));
  150. }
  151. static int da903x_list_voltage(struct regulator_dev *rdev, unsigned selector)
  152. {
  153. struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
  154. int ret;
  155. ret = info->min_uV + info->step_uV * selector;
  156. if (ret > info->max_uV)
  157. return -EINVAL;
  158. return ret;
  159. }
  160. /* DA9030 specific operations */
  161. static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
  162. int min_uV, int max_uV)
  163. {
  164. struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
  165. struct device *da903x_dev = to_da903x_dev(rdev);
  166. uint8_t val, mask;
  167. int ret;
  168. if (check_range(info, min_uV, max_uV)) {
  169. pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
  170. return -EINVAL;
  171. }
  172. val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
  173. val <<= info->vol_shift;
  174. mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
  175. val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */
  176. mask |= DA9030_LDO_UNLOCK_MASK;
  177. /* write twice */
  178. ret = da903x_update(da903x_dev, info->vol_reg, val, mask);
  179. if (ret)
  180. return ret;
  181. return da903x_update(da903x_dev, info->vol_reg, val, mask);
  182. }
  183. static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
  184. int min_uV, int max_uV)
  185. {
  186. struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
  187. struct device *da903x_dev = to_da903x_dev(rdev);
  188. uint8_t val, mask;
  189. int thresh;
  190. if (check_range(info, min_uV, max_uV)) {
  191. pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
  192. return -EINVAL;
  193. }
  194. thresh = (info->max_uV + info->min_uV) / 2;
  195. if (min_uV < thresh) {
  196. val = (thresh - min_uV + info->step_uV - 1) / info->step_uV;
  197. val |= 0x4;
  198. } else {
  199. val = (min_uV - thresh + info->step_uV - 1) / info->step_uV;
  200. }
  201. val <<= info->vol_shift;
  202. mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
  203. return da903x_update(da903x_dev, info->vol_reg, val, mask);
  204. }
  205. static int da9030_get_ldo14_voltage(struct regulator_dev *rdev)
  206. {
  207. struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
  208. struct device *da903x_dev = to_da903x_dev(rdev);
  209. uint8_t val, mask;
  210. int ret;
  211. ret = da903x_read(da903x_dev, info->vol_reg, &val);
  212. if (ret)
  213. return ret;
  214. mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
  215. val = (val & mask) >> info->vol_shift;
  216. if (val & 0x4)
  217. return info->min_uV + info->step_uV * (3 - (val & ~0x4));
  218. else
  219. return (info->max_uV + info->min_uV) / 2 +
  220. info->step_uV * (val & ~0x4);
  221. }
  222. /* DA9034 specific operations */
  223. static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
  224. int min_uV, int max_uV)
  225. {
  226. struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
  227. struct device *da9034_dev = to_da903x_dev(rdev);
  228. uint8_t val, mask;
  229. int ret;
  230. if (check_range(info, min_uV, max_uV)) {
  231. pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
  232. return -EINVAL;
  233. }
  234. val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
  235. val <<= info->vol_shift;
  236. mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
  237. ret = da903x_update(da9034_dev, info->vol_reg, val, mask);
  238. if (ret)
  239. return ret;
  240. ret = da903x_set_bits(da9034_dev, info->update_reg,
  241. 1 << info->update_bit);
  242. return ret;
  243. }
  244. static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
  245. int min_uV, int max_uV)
  246. {
  247. struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
  248. struct device *da9034_dev = to_da903x_dev(rdev);
  249. uint8_t val, mask;
  250. if (check_range(info, min_uV, max_uV)) {
  251. pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
  252. return -EINVAL;
  253. }
  254. val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
  255. val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val);
  256. val <<= info->vol_shift;
  257. mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
  258. return da903x_update(da9034_dev, info->vol_reg, val, mask);
  259. }
  260. static int da9034_get_ldo12_voltage(struct regulator_dev *rdev)
  261. {
  262. struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
  263. struct device *da9034_dev = to_da903x_dev(rdev);
  264. uint8_t val, mask;
  265. int ret;
  266. ret = da903x_read(da9034_dev, info->vol_reg, &val);
  267. if (ret)
  268. return ret;
  269. mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
  270. val = (val & mask) >> info->vol_shift;
  271. if (val >= 8)
  272. return 2700000 + info->step_uV * (val - 8);
  273. return info->min_uV + info->step_uV * val;
  274. }
  275. static int da9034_list_ldo12_voltage(struct regulator_dev *rdev,
  276. unsigned selector)
  277. {
  278. if (selector >= ARRAY_SIZE(da9034_ldo12_data))
  279. return -EINVAL;
  280. return da9034_ldo12_data[selector] * 1000;
  281. }
  282. static struct regulator_ops da903x_regulator_ldo_ops = {
  283. .set_voltage = da903x_set_ldo_voltage,
  284. .get_voltage = da903x_get_voltage,
  285. .list_voltage = da903x_list_voltage,
  286. .enable = da903x_enable,
  287. .disable = da903x_disable,
  288. .is_enabled = da903x_is_enabled,
  289. };
  290. /* NOTE: this is dedicated for the insane DA9030 LDO14 */
  291. static struct regulator_ops da9030_regulator_ldo14_ops = {
  292. .set_voltage = da9030_set_ldo14_voltage,
  293. .get_voltage = da9030_get_ldo14_voltage,
  294. .list_voltage = da903x_list_voltage,
  295. .enable = da903x_enable,
  296. .disable = da903x_disable,
  297. .is_enabled = da903x_is_enabled,
  298. };
  299. /* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks */
  300. static struct regulator_ops da9030_regulator_ldo1_15_ops = {
  301. .set_voltage = da9030_set_ldo1_15_voltage,
  302. .get_voltage = da903x_get_voltage,
  303. .list_voltage = da903x_list_voltage,
  304. .enable = da903x_enable,
  305. .disable = da903x_disable,
  306. .is_enabled = da903x_is_enabled,
  307. };
  308. static struct regulator_ops da9034_regulator_dvc_ops = {
  309. .set_voltage = da9034_set_dvc_voltage,
  310. .get_voltage = da903x_get_voltage,
  311. .list_voltage = da903x_list_voltage,
  312. .enable = da903x_enable,
  313. .disable = da903x_disable,
  314. .is_enabled = da903x_is_enabled,
  315. };
  316. /* NOTE: this is dedicated for the insane LDO12 */
  317. static struct regulator_ops da9034_regulator_ldo12_ops = {
  318. .set_voltage = da9034_set_ldo12_voltage,
  319. .get_voltage = da9034_get_ldo12_voltage,
  320. .list_voltage = da9034_list_ldo12_voltage,
  321. .enable = da903x_enable,
  322. .disable = da903x_disable,
  323. .is_enabled = da903x_is_enabled,
  324. };
  325. #define DA903x_LDO(_pmic, _id, min, max, step, vreg, shift, nbits, ereg, ebit) \
  326. { \
  327. .desc = { \
  328. .name = "LDO" #_id, \
  329. .ops = &da903x_regulator_ldo_ops, \
  330. .type = REGULATOR_VOLTAGE, \
  331. .id = _pmic##_ID_LDO##_id, \
  332. .n_voltages = (step) ? ((max - min) / step + 1) : 1, \
  333. .owner = THIS_MODULE, \
  334. }, \
  335. .min_uV = (min) * 1000, \
  336. .max_uV = (max) * 1000, \
  337. .step_uV = (step) * 1000, \
  338. .vol_reg = _pmic##_##vreg, \
  339. .vol_shift = (shift), \
  340. .vol_nbits = (nbits), \
  341. .enable_reg = _pmic##_##ereg, \
  342. .enable_bit = (ebit), \
  343. }
  344. #define DA903x_DVC(_pmic, _id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \
  345. { \
  346. .desc = { \
  347. .name = #_id, \
  348. .ops = &da9034_regulator_dvc_ops, \
  349. .type = REGULATOR_VOLTAGE, \
  350. .id = _pmic##_ID_##_id, \
  351. .n_voltages = (step) ? ((max - min) / step + 1) : 1, \
  352. .owner = THIS_MODULE, \
  353. }, \
  354. .min_uV = (min) * 1000, \
  355. .max_uV = (max) * 1000, \
  356. .step_uV = (step) * 1000, \
  357. .vol_reg = _pmic##_##vreg, \
  358. .vol_shift = (0), \
  359. .vol_nbits = (nbits), \
  360. .update_reg = _pmic##_##ureg, \
  361. .update_bit = (ubit), \
  362. .enable_reg = _pmic##_##ereg, \
  363. .enable_bit = (ebit), \
  364. }
  365. #define DA9034_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \
  366. DA903x_LDO(DA9034, _id, min, max, step, vreg, shift, nbits, ereg, ebit)
  367. #define DA9030_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \
  368. DA903x_LDO(DA9030, _id, min, max, step, vreg, shift, nbits, ereg, ebit)
  369. #define DA9030_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \
  370. DA903x_DVC(DA9030, _id, min, max, step, vreg, nbits, ureg, ubit, \
  371. ereg, ebit)
  372. #define DA9034_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \
  373. DA903x_DVC(DA9034, _id, min, max, step, vreg, nbits, ureg, ubit, \
  374. ereg, ebit)
  375. #define DA9035_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \
  376. DA903x_DVC(DA9035, _id, min, max, step, vreg, nbits, ureg, ubit, \
  377. ereg, ebit)
  378. static struct da903x_regulator_info da903x_regulator_info[] = {
  379. /* DA9030 */
  380. DA9030_DVC(BUCK2, 850, 1625, 25, BUCK2DVM1, 5, BUCK2DVM1, 7, RCTL11, 0),
  381. DA9030_LDO( 1, 1200, 3200, 100, LDO1, 0, 5, RCTL12, 1),
  382. DA9030_LDO( 2, 1800, 3200, 100, LDO23, 0, 4, RCTL12, 2),
  383. DA9030_LDO( 3, 1800, 3200, 100, LDO23, 4, 4, RCTL12, 3),
  384. DA9030_LDO( 4, 1800, 3200, 100, LDO45, 0, 4, RCTL12, 4),
  385. DA9030_LDO( 5, 1800, 3200, 100, LDO45, 4, 4, RCTL12, 5),
  386. DA9030_LDO( 6, 1800, 3200, 100, LDO6, 0, 4, RCTL12, 6),
  387. DA9030_LDO( 7, 1800, 3200, 100, LDO78, 0, 4, RCTL12, 7),
  388. DA9030_LDO( 8, 1800, 3200, 100, LDO78, 4, 4, RCTL22, 0),
  389. DA9030_LDO( 9, 1800, 3200, 100, LDO912, 0, 4, RCTL22, 1),
  390. DA9030_LDO(10, 1800, 3200, 100, LDO1011, 0, 4, RCTL22, 2),
  391. DA9030_LDO(11, 1800, 3200, 100, LDO1011, 4, 4, RCTL22, 3),
  392. DA9030_LDO(12, 1800, 3200, 100, LDO912, 4, 4, RCTL22, 4),
  393. DA9030_LDO(14, 2760, 2940, 30, LDO1416, 0, 3, RCTL11, 4),
  394. DA9030_LDO(15, 1100, 2650, 50, LDO15, 0, 5, RCTL11, 5),
  395. DA9030_LDO(16, 1100, 2650, 50, LDO1416, 3, 5, RCTL11, 6),
  396. DA9030_LDO(17, 1800, 3200, 100, LDO17, 0, 4, RCTL11, 7),
  397. DA9030_LDO(18, 1800, 3200, 100, LDO1819, 0, 4, RCTL21, 2),
  398. DA9030_LDO(19, 1800, 3200, 100, LDO1819, 4, 4, RCTL21, 1),
  399. DA9030_LDO(13, 2100, 2100, 0, INVAL, 0, 0, RCTL11, 3), /* fixed @2.1V */
  400. /* DA9034 */
  401. DA9034_DVC(BUCK1, 725, 1500, 25, ADTV2, 5, VCC1, 0, OVER1, 0),
  402. DA9034_DVC(BUCK2, 725, 1500, 25, CDTV2, 5, VCC1, 2, OVER1, 1),
  403. DA9034_DVC(LDO2, 725, 1500, 25, SDTV2, 5, VCC1, 4, OVER1, 2),
  404. DA9034_DVC(LDO1, 1700, 2075, 25, MDTV1, 4, VCC1, 6, OVER3, 4),
  405. DA9034_LDO( 3, 1800, 3300, 100, LDO643, 0, 4, OVER3, 5),
  406. DA9034_LDO( 4, 1800, 2900,1100, LDO643, 4, 1, OVER3, 6),
  407. DA9034_LDO( 6, 2500, 2850, 50, LDO643, 5, 3, OVER2, 0),
  408. DA9034_LDO( 7, 2700, 3050, 50, LDO987, 0, 3, OVER2, 1),
  409. DA9034_LDO( 8, 2700, 2850, 50, LDO987, 3, 2, OVER2, 2),
  410. DA9034_LDO( 9, 2700, 3050, 50, LDO987, 5, 3, OVER2, 3),
  411. DA9034_LDO(10, 2700, 3050, 50, LDO1110, 0, 3, OVER2, 4),
  412. DA9034_LDO(11, 1800, 3300, 100, LDO1110, 4, 4, OVER2, 5),
  413. DA9034_LDO(12, 1700, 3050, 50, LDO1312, 0, 4, OVER3, 6),
  414. DA9034_LDO(13, 1800, 3300, 100, LDO1312, 4, 4, OVER2, 7),
  415. DA9034_LDO(14, 1800, 3300, 100, LDO1514, 0, 4, OVER3, 0),
  416. DA9034_LDO(15, 1800, 3300, 100, LDO1514, 4, 4, OVER3, 1),
  417. DA9034_LDO(5, 3100, 3100, 0, INVAL, 0, 0, OVER3, 7), /* fixed @3.1V */
  418. /* DA9035 */
  419. DA9035_DVC(BUCK3, 1800, 2200, 100, 3DTV1, 3, VCC2, 0, OVER3, 3),
  420. };
  421. static inline struct da903x_regulator_info *find_regulator_info(int id)
  422. {
  423. struct da903x_regulator_info *ri;
  424. int i;
  425. for (i = 0; i < ARRAY_SIZE(da903x_regulator_info); i++) {
  426. ri = &da903x_regulator_info[i];
  427. if (ri->desc.id == id)
  428. return ri;
  429. }
  430. return NULL;
  431. }
  432. static int __devinit da903x_regulator_probe(struct platform_device *pdev)
  433. {
  434. struct da903x_regulator_info *ri = NULL;
  435. struct regulator_dev *rdev;
  436. ri = find_regulator_info(pdev->id);
  437. if (ri == NULL) {
  438. dev_err(&pdev->dev, "invalid regulator ID specified\n");
  439. return -EINVAL;
  440. }
  441. /* Workaround for the weird LDO12 voltage setting */
  442. if (ri->desc.id == DA9034_ID_LDO12) {
  443. ri->desc.ops = &da9034_regulator_ldo12_ops;
  444. ri->desc.n_voltages = ARRAY_SIZE(da9034_ldo12_data);
  445. }
  446. if (ri->desc.id == DA9030_ID_LDO14)
  447. ri->desc.ops = &da9030_regulator_ldo14_ops;
  448. if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15)
  449. ri->desc.ops = &da9030_regulator_ldo1_15_ops;
  450. rdev = regulator_register(&ri->desc, &pdev->dev,
  451. pdev->dev.platform_data, ri);
  452. if (IS_ERR(rdev)) {
  453. dev_err(&pdev->dev, "failed to register regulator %s\n",
  454. ri->desc.name);
  455. return PTR_ERR(rdev);
  456. }
  457. platform_set_drvdata(pdev, rdev);
  458. return 0;
  459. }
  460. static int __devexit da903x_regulator_remove(struct platform_device *pdev)
  461. {
  462. struct regulator_dev *rdev = platform_get_drvdata(pdev);
  463. regulator_unregister(rdev);
  464. return 0;
  465. }
  466. static struct platform_driver da903x_regulator_driver = {
  467. .driver = {
  468. .name = "da903x-regulator",
  469. .owner = THIS_MODULE,
  470. },
  471. .probe = da903x_regulator_probe,
  472. .remove = __devexit_p(da903x_regulator_remove),
  473. };
  474. static int __init da903x_regulator_init(void)
  475. {
  476. return platform_driver_register(&da903x_regulator_driver);
  477. }
  478. subsys_initcall(da903x_regulator_init);
  479. static void __exit da903x_regulator_exit(void)
  480. {
  481. platform_driver_unregister(&da903x_regulator_driver);
  482. }
  483. module_exit(da903x_regulator_exit);
  484. MODULE_LICENSE("GPL");
  485. MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"
  486. "Mike Rapoport <mike@compulab.co.il>");
  487. MODULE_DESCRIPTION("Regulator Driver for Dialog Semiconductor DA903X PMIC");
  488. MODULE_ALIAS("platform:da903x-regulator");