twl-common.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /*
  2. * twl-common.c
  3. *
  4. * Copyright (C) 2011 Texas Instruments, Inc..
  5. * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. *
  21. */
  22. #include <linux/i2c.h>
  23. #include <linux/i2c/twl.h>
  24. #include <linux/gpio.h>
  25. #include <linux/regulator/machine.h>
  26. #include <linux/regulator/fixed.h>
  27. #include <plat/i2c.h>
  28. #include <plat/usb.h>
  29. #include "twl-common.h"
  30. #include "pm.h"
  31. static struct i2c_board_info __initdata pmic_i2c_board_info = {
  32. .addr = 0x48,
  33. .flags = I2C_CLIENT_WAKE,
  34. };
  35. static struct i2c_board_info __initdata omap4_i2c1_board_info[] = {
  36. {
  37. .addr = 0x48,
  38. .flags = I2C_CLIENT_WAKE,
  39. },
  40. {
  41. I2C_BOARD_INFO("twl6040", 0x4b),
  42. },
  43. };
  44. void __init omap_pmic_init(int bus, u32 clkrate,
  45. const char *pmic_type, int pmic_irq,
  46. struct twl4030_platform_data *pmic_data)
  47. {
  48. strncpy(pmic_i2c_board_info.type, pmic_type,
  49. sizeof(pmic_i2c_board_info.type));
  50. pmic_i2c_board_info.irq = pmic_irq;
  51. pmic_i2c_board_info.platform_data = pmic_data;
  52. omap_register_i2c_bus(bus, clkrate, &pmic_i2c_board_info, 1);
  53. }
  54. void __init omap4_pmic_init(const char *pmic_type,
  55. struct twl4030_platform_data *pmic_data,
  56. struct twl6040_platform_data *twl6040_data, int twl6040_irq)
  57. {
  58. /* PMIC part*/
  59. strncpy(omap4_i2c1_board_info[0].type, pmic_type,
  60. sizeof(omap4_i2c1_board_info[0].type));
  61. omap4_i2c1_board_info[0].irq = OMAP44XX_IRQ_SYS_1N;
  62. omap4_i2c1_board_info[0].platform_data = pmic_data;
  63. /* TWL6040 audio IC part */
  64. omap4_i2c1_board_info[1].irq = twl6040_irq;
  65. omap4_i2c1_board_info[1].platform_data = twl6040_data;
  66. omap_register_i2c_bus(1, 400, omap4_i2c1_board_info, 2);
  67. }
  68. void __init omap_pmic_late_init(void)
  69. {
  70. /* Init the OMAP TWL parameters (if PMIC has been registerd) */
  71. if (pmic_i2c_board_info.irq)
  72. omap3_twl_init();
  73. if (omap4_i2c1_board_info[0].irq)
  74. omap4_twl_init();
  75. }
  76. #if defined(CONFIG_ARCH_OMAP3)
  77. static struct twl4030_usb_data omap3_usb_pdata = {
  78. .usb_mode = T2_USB_MODE_ULPI,
  79. };
  80. static int omap3_batt_table[] = {
  81. /* 0 C */
  82. 30800, 29500, 28300, 27100,
  83. 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
  84. 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
  85. 11600, 11200, 10800, 10400, 10000, 9630, 9280, 8950, 8620, 8310,
  86. 8020, 7730, 7460, 7200, 6950, 6710, 6470, 6250, 6040, 5830,
  87. 5640, 5450, 5260, 5090, 4920, 4760, 4600, 4450, 4310, 4170,
  88. 4040, 3910, 3790, 3670, 3550
  89. };
  90. static struct twl4030_bci_platform_data omap3_bci_pdata = {
  91. .battery_tmp_tbl = omap3_batt_table,
  92. .tblsize = ARRAY_SIZE(omap3_batt_table),
  93. };
  94. static struct twl4030_madc_platform_data omap3_madc_pdata = {
  95. .irq_line = 1,
  96. };
  97. static struct twl4030_codec_data omap3_codec;
  98. static struct twl4030_audio_data omap3_audio_pdata = {
  99. .audio_mclk = 26000000,
  100. .codec = &omap3_codec,
  101. };
  102. static struct regulator_consumer_supply omap3_vdda_dac_supplies[] = {
  103. REGULATOR_SUPPLY("vdda_dac", "omapdss_venc"),
  104. };
  105. static struct regulator_init_data omap3_vdac_idata = {
  106. .constraints = {
  107. .min_uV = 1800000,
  108. .max_uV = 1800000,
  109. .valid_modes_mask = REGULATOR_MODE_NORMAL
  110. | REGULATOR_MODE_STANDBY,
  111. .valid_ops_mask = REGULATOR_CHANGE_MODE
  112. | REGULATOR_CHANGE_STATUS,
  113. },
  114. .num_consumer_supplies = ARRAY_SIZE(omap3_vdda_dac_supplies),
  115. .consumer_supplies = omap3_vdda_dac_supplies,
  116. };
  117. static struct regulator_consumer_supply omap3_vpll2_supplies[] = {
  118. REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
  119. REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
  120. };
  121. static struct regulator_init_data omap3_vpll2_idata = {
  122. .constraints = {
  123. .min_uV = 1800000,
  124. .max_uV = 1800000,
  125. .valid_modes_mask = REGULATOR_MODE_NORMAL
  126. | REGULATOR_MODE_STANDBY,
  127. .valid_ops_mask = REGULATOR_CHANGE_MODE
  128. | REGULATOR_CHANGE_STATUS,
  129. },
  130. .num_consumer_supplies = ARRAY_SIZE(omap3_vpll2_supplies),
  131. .consumer_supplies = omap3_vpll2_supplies,
  132. };
  133. void __init omap3_pmic_get_config(struct twl4030_platform_data *pmic_data,
  134. u32 pdata_flags, u32 regulators_flags)
  135. {
  136. if (!pmic_data->irq_base)
  137. pmic_data->irq_base = TWL4030_IRQ_BASE;
  138. if (!pmic_data->irq_end)
  139. pmic_data->irq_end = TWL4030_IRQ_END;
  140. /* Common platform data configurations */
  141. if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
  142. pmic_data->usb = &omap3_usb_pdata;
  143. if (pdata_flags & TWL_COMMON_PDATA_BCI && !pmic_data->bci)
  144. pmic_data->bci = &omap3_bci_pdata;
  145. if (pdata_flags & TWL_COMMON_PDATA_MADC && !pmic_data->madc)
  146. pmic_data->madc = &omap3_madc_pdata;
  147. if (pdata_flags & TWL_COMMON_PDATA_AUDIO && !pmic_data->audio)
  148. pmic_data->audio = &omap3_audio_pdata;
  149. /* Common regulator configurations */
  150. if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
  151. pmic_data->vdac = &omap3_vdac_idata;
  152. if (regulators_flags & TWL_COMMON_REGULATOR_VPLL2 && !pmic_data->vpll2)
  153. pmic_data->vpll2 = &omap3_vpll2_idata;
  154. }
  155. #endif /* CONFIG_ARCH_OMAP3 */
  156. #if defined(CONFIG_ARCH_OMAP4)
  157. static struct twl4030_usb_data omap4_usb_pdata = {
  158. .phy_init = omap4430_phy_init,
  159. .phy_exit = omap4430_phy_exit,
  160. .phy_power = omap4430_phy_power,
  161. .phy_set_clock = omap4430_phy_set_clk,
  162. .phy_suspend = omap4430_phy_suspend,
  163. };
  164. static struct regulator_init_data omap4_vdac_idata = {
  165. .constraints = {
  166. .min_uV = 1800000,
  167. .max_uV = 1800000,
  168. .valid_modes_mask = REGULATOR_MODE_NORMAL
  169. | REGULATOR_MODE_STANDBY,
  170. .valid_ops_mask = REGULATOR_CHANGE_MODE
  171. | REGULATOR_CHANGE_STATUS,
  172. },
  173. };
  174. static struct regulator_init_data omap4_vaux2_idata = {
  175. .constraints = {
  176. .min_uV = 1200000,
  177. .max_uV = 2800000,
  178. .apply_uV = true,
  179. .valid_modes_mask = REGULATOR_MODE_NORMAL
  180. | REGULATOR_MODE_STANDBY,
  181. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  182. | REGULATOR_CHANGE_MODE
  183. | REGULATOR_CHANGE_STATUS,
  184. },
  185. };
  186. static struct regulator_init_data omap4_vaux3_idata = {
  187. .constraints = {
  188. .min_uV = 1000000,
  189. .max_uV = 3000000,
  190. .apply_uV = true,
  191. .valid_modes_mask = REGULATOR_MODE_NORMAL
  192. | REGULATOR_MODE_STANDBY,
  193. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  194. | REGULATOR_CHANGE_MODE
  195. | REGULATOR_CHANGE_STATUS,
  196. },
  197. };
  198. static struct regulator_consumer_supply omap4_vmmc_supply[] = {
  199. REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
  200. };
  201. /* VMMC1 for MMC1 card */
  202. static struct regulator_init_data omap4_vmmc_idata = {
  203. .constraints = {
  204. .min_uV = 1200000,
  205. .max_uV = 3000000,
  206. .apply_uV = true,
  207. .valid_modes_mask = REGULATOR_MODE_NORMAL
  208. | REGULATOR_MODE_STANDBY,
  209. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  210. | REGULATOR_CHANGE_MODE
  211. | REGULATOR_CHANGE_STATUS,
  212. },
  213. .num_consumer_supplies = ARRAY_SIZE(omap4_vmmc_supply),
  214. .consumer_supplies = omap4_vmmc_supply,
  215. };
  216. static struct regulator_init_data omap4_vpp_idata = {
  217. .constraints = {
  218. .min_uV = 1800000,
  219. .max_uV = 2500000,
  220. .apply_uV = true,
  221. .valid_modes_mask = REGULATOR_MODE_NORMAL
  222. | REGULATOR_MODE_STANDBY,
  223. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  224. | REGULATOR_CHANGE_MODE
  225. | REGULATOR_CHANGE_STATUS,
  226. },
  227. };
  228. static struct regulator_init_data omap4_vana_idata = {
  229. .constraints = {
  230. .min_uV = 2100000,
  231. .max_uV = 2100000,
  232. .valid_modes_mask = REGULATOR_MODE_NORMAL
  233. | REGULATOR_MODE_STANDBY,
  234. .valid_ops_mask = REGULATOR_CHANGE_MODE
  235. | REGULATOR_CHANGE_STATUS,
  236. },
  237. };
  238. static struct regulator_consumer_supply omap4_vcxio_supply[] = {
  239. REGULATOR_SUPPLY("vdds_dsi", "omapdss_dss"),
  240. REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
  241. REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.1"),
  242. };
  243. static struct regulator_init_data omap4_vcxio_idata = {
  244. .constraints = {
  245. .min_uV = 1800000,
  246. .max_uV = 1800000,
  247. .valid_modes_mask = REGULATOR_MODE_NORMAL
  248. | REGULATOR_MODE_STANDBY,
  249. .valid_ops_mask = REGULATOR_CHANGE_MODE
  250. | REGULATOR_CHANGE_STATUS,
  251. .always_on = true,
  252. },
  253. .num_consumer_supplies = ARRAY_SIZE(omap4_vcxio_supply),
  254. .consumer_supplies = omap4_vcxio_supply,
  255. };
  256. static struct regulator_init_data omap4_vusb_idata = {
  257. .constraints = {
  258. .min_uV = 3300000,
  259. .max_uV = 3300000,
  260. .valid_modes_mask = REGULATOR_MODE_NORMAL
  261. | REGULATOR_MODE_STANDBY,
  262. .valid_ops_mask = REGULATOR_CHANGE_MODE
  263. | REGULATOR_CHANGE_STATUS,
  264. },
  265. };
  266. static struct regulator_init_data omap4_clk32kg_idata = {
  267. .constraints = {
  268. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  269. },
  270. };
  271. void __init omap4_pmic_get_config(struct twl4030_platform_data *pmic_data,
  272. u32 pdata_flags, u32 regulators_flags)
  273. {
  274. if (!pmic_data->irq_base)
  275. pmic_data->irq_base = TWL6030_IRQ_BASE;
  276. if (!pmic_data->irq_end)
  277. pmic_data->irq_end = TWL6030_IRQ_END;
  278. /* Common platform data configurations */
  279. if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
  280. pmic_data->usb = &omap4_usb_pdata;
  281. /* Common regulator configurations */
  282. if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
  283. pmic_data->vdac = &omap4_vdac_idata;
  284. if (regulators_flags & TWL_COMMON_REGULATOR_VAUX2 && !pmic_data->vaux2)
  285. pmic_data->vaux2 = &omap4_vaux2_idata;
  286. if (regulators_flags & TWL_COMMON_REGULATOR_VAUX3 && !pmic_data->vaux3)
  287. pmic_data->vaux3 = &omap4_vaux3_idata;
  288. if (regulators_flags & TWL_COMMON_REGULATOR_VMMC && !pmic_data->vmmc)
  289. pmic_data->vmmc = &omap4_vmmc_idata;
  290. if (regulators_flags & TWL_COMMON_REGULATOR_VPP && !pmic_data->vpp)
  291. pmic_data->vpp = &omap4_vpp_idata;
  292. if (regulators_flags & TWL_COMMON_REGULATOR_VANA && !pmic_data->vana)
  293. pmic_data->vana = &omap4_vana_idata;
  294. if (regulators_flags & TWL_COMMON_REGULATOR_VCXIO && !pmic_data->vcxio)
  295. pmic_data->vcxio = &omap4_vcxio_idata;
  296. if (regulators_flags & TWL_COMMON_REGULATOR_VUSB && !pmic_data->vusb)
  297. pmic_data->vusb = &omap4_vusb_idata;
  298. if (regulators_flags & TWL_COMMON_REGULATOR_CLK32KG &&
  299. !pmic_data->clk32kg)
  300. pmic_data->clk32kg = &omap4_clk32kg_idata;
  301. }
  302. #endif /* CONFIG_ARCH_OMAP4 */