da903x.c 17 KB

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