Advertisement
Guest User

Untitled

a guest
Dec 21st, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.64 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2010-2011 NVIDIA, Inc.
  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 as
  6. * 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. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. * 02111-1307, USA
  17. */
  18. #include <linux/i2c.h>
  19. #include <linux/pda_power.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/resource.h>
  22. #include <linux/regulator/machine.h>
  23. #include <linux/mfd/tps6586x.h>
  24. #include <linux/gpio.h>
  25. #include <linux/io.h>
  26. #include <linux/power/gpio-charger.h>
  27.  
  28. #include <mach/iomap.h>
  29. #include <mach/irqs.h>
  30.  
  31. #include <generated/mach-types.h>
  32.  
  33. #include "gpio-names.h"
  34. #include "fuse.h"
  35. #include "pm.h"
  36. #include "wakeups-t2.h"
  37. #include "board.h"
  38. #include "board-ventana.h"
  39.  
  40. #define PMC_CTRL 0x0
  41. #define PMC_CTRL_INTR_LOW (1 << 17)
  42.  
  43. #define CHARGING_DISABLE TEGRA_GPIO_PR6
  44.  
  45. int __init ventana_charge_init(void)
  46. {
  47. gpio_request(CHARGING_DISABLE, "chg_disable");
  48. gpio_direction_output(CHARGING_DISABLE, 0);
  49. tegra_gpio_enable(CHARGING_DISABLE);
  50. return 0;
  51. }
  52.  
  53. static struct regulator_consumer_supply tps658621_sm0_supply[] = {
  54. REGULATOR_SUPPLY("vdd_core", NULL),
  55. };
  56. static struct regulator_consumer_supply tps658621_sm1_supply[] = {
  57. REGULATOR_SUPPLY("vdd_cpu", NULL),
  58. };
  59. static struct regulator_consumer_supply tps658621_sm2_supply[] = {
  60. REGULATOR_SUPPLY("vdd_sm2", NULL),
  61. };
  62. static struct regulator_consumer_supply tps658621_ldo0_supply[] = {
  63. REGULATOR_SUPPLY("vdd_ldo0", NULL),
  64. REGULATOR_SUPPLY("p_cam_avdd", NULL),
  65. };
  66. static struct regulator_consumer_supply tps658621_ldo1_supply[] = {
  67. REGULATOR_SUPPLY("vdd_ldo1", NULL),
  68. REGULATOR_SUPPLY("avdd_pll", NULL),
  69. };
  70. static struct regulator_consumer_supply tps658621_ldo2_supply[] = {
  71. REGULATOR_SUPPLY("vdd_ldo2", NULL),
  72. REGULATOR_SUPPLY("vdd_rtc", NULL),
  73. REGULATOR_SUPPLY("vdd_aon", NULL),
  74. };
  75. static struct regulator_consumer_supply tps658621_ldo3_supply[] = {
  76. REGULATOR_SUPPLY("vdd_ldo3", NULL),
  77. REGULATOR_SUPPLY("avdd_usb", NULL),
  78. REGULATOR_SUPPLY("avdd_usb_pll", NULL),
  79. };
  80. static struct regulator_consumer_supply tps658621_ldo4_supply[] = {
  81. REGULATOR_SUPPLY("vdd_ldo4", NULL),
  82. REGULATOR_SUPPLY("avdd_osc", NULL),
  83. REGULATOR_SUPPLY("vddio_sys", "panjit_touch"),
  84. };
  85. static struct regulator_consumer_supply tps658621_ldo5_supply[] = {
  86. REGULATOR_SUPPLY("vdd_ldo5", NULL),
  87. REGULATOR_SUPPLY("vmmc", "sdhci-tegra.3"),
  88. };
  89. static struct regulator_consumer_supply tps658621_ldo6_supply[] = {
  90. REGULATOR_SUPPLY("vdd_ldo6", NULL),
  91. REGULATOR_SUPPLY("vcsi", "tegra_camera"),
  92. REGULATOR_SUPPLY("vdd_dmic", "tegra-snd-wm8903"),
  93. };
  94. static struct regulator_consumer_supply tps658621_ldo7_supply[] = {
  95. REGULATOR_SUPPLY("vdd_ldo7", NULL),
  96. REGULATOR_SUPPLY("avdd_hdmi", NULL),
  97. REGULATOR_SUPPLY("vdd_fuse", NULL),
  98. };
  99. static struct regulator_consumer_supply tps658621_ldo8_supply[] = {
  100. REGULATOR_SUPPLY("vdd_ldo8", NULL),
  101. REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
  102. };
  103. static struct regulator_consumer_supply tps658621_ldo9_supply[] = {
  104. REGULATOR_SUPPLY("vdd_ldo9", NULL),
  105. REGULATOR_SUPPLY("avdd_2v85", NULL),
  106. REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
  107. REGULATOR_SUPPLY("vdd_spk_amp", "tegra-snd-wm8903"),
  108. };
  109.  
  110. static struct tps6586x_settings sm0_config = {
  111. .sm_pwm_mode = PWM_DEFAULT_VALUE,
  112. .slew_rate = SLEW_RATE_3520UV_PER_SEC,
  113. };
  114.  
  115. static struct tps6586x_settings sm1_config = {
  116. /*
  117. * Current TPS6586x is known for having a voltage glitch if current load
  118. * changes from low to high in auto PWM/PFM mode for CPU's Vdd line.
  119. */
  120. .sm_pwm_mode = PWM_ONLY,
  121. .slew_rate = SLEW_RATE_3520UV_PER_SEC,
  122. };
  123.  
  124. #define REGULATOR_INIT(_id, _minmv, _maxmv, on, config) \
  125. { \
  126. .constraints = { \
  127. .min_uV = (_minmv)*1000, \
  128. .max_uV = (_maxmv)*1000, \
  129. .valid_modes_mask = (REGULATOR_MODE_NORMAL | \
  130. REGULATOR_MODE_STANDBY), \
  131. .valid_ops_mask = (REGULATOR_CHANGE_MODE | \
  132. REGULATOR_CHANGE_STATUS | \
  133. REGULATOR_CHANGE_VOLTAGE), \
  134. .always_on = on, \
  135. .apply_uV = 1, \
  136. }, \
  137. .num_consumer_supplies = ARRAY_SIZE(tps658621_##_id##_supply),\
  138. .consumer_supplies = tps658621_##_id##_supply, \
  139. .driver_data = config, \
  140. }
  141.  
  142. #define ON 1
  143. #define OFF 0
  144.  
  145. static struct regulator_init_data sm0_data = REGULATOR_INIT(sm0, 725, 1500, ON, &sm0_config);
  146. static struct regulator_init_data sm1_data = REGULATOR_INIT(sm1, 725, 1500, ON, &sm1_config);
  147. static struct regulator_init_data sm2_data = REGULATOR_INIT(sm2, 3000, 4550, ON, NULL);
  148. static struct regulator_init_data ldo0_data = REGULATOR_INIT(ldo0, 1250, 3300, OFF, NULL);
  149. static struct regulator_init_data ldo1_data = REGULATOR_INIT(ldo1, 725, 1500, ON, NULL);
  150. static struct regulator_init_data ldo2_data = REGULATOR_INIT(ldo2, 725, 1500, OFF, NULL);
  151. static struct regulator_init_data ldo3_data = REGULATOR_INIT(ldo3, 1250, 3300, OFF, NULL);
  152. static struct regulator_init_data ldo4_data = REGULATOR_INIT(ldo4, 1700, 2475, ON, NULL);
  153. static struct regulator_init_data ldo5_data = REGULATOR_INIT(ldo5, 1250, 3300, ON, NULL);
  154. static struct regulator_init_data ldo6_data = REGULATOR_INIT(ldo6, 1800, 1800, OFF, NULL);
  155. static struct regulator_init_data ldo7_data = REGULATOR_INIT(ldo7, 1250, 3300, OFF, NULL);
  156. static struct regulator_init_data ldo8_data = REGULATOR_INIT(ldo8, 1250, 3300, OFF, NULL);
  157. static struct regulator_init_data ldo9_data = REGULATOR_INIT(ldo9, 1250, 3300, OFF, NULL);
  158.  
  159. static struct tps6586x_rtc_platform_data rtc_data = {
  160. .irq = TEGRA_NR_IRQS + TPS6586X_INT_RTC_ALM1,
  161. .start = {
  162. .year = 2009,
  163. .month = 1,
  164. .day = 1,
  165. },
  166. .cl_sel = TPS6586X_RTC_CL_SEL_1_5PF /* use lowest (external 20pF cap) */
  167. };
  168.  
  169. #define TPS_REG(_id, _data) \
  170. { \
  171. .id = TPS6586X_ID_##_id, \
  172. .name = "tps6586x-regulator", \
  173. .platform_data = _data, \
  174. }
  175.  
  176. static struct tps6586x_subdev_info tps_devs[] = {
  177. TPS_REG(SM_0, &sm0_data),
  178. TPS_REG(SM_1, &sm1_data),
  179. TPS_REG(SM_2, &sm2_data),
  180. TPS_REG(LDO_0, &ldo0_data),
  181. TPS_REG(LDO_1, &ldo1_data),
  182. TPS_REG(LDO_2, &ldo2_data),
  183. TPS_REG(LDO_3, &ldo3_data),
  184. TPS_REG(LDO_4, &ldo4_data),
  185. TPS_REG(LDO_5, &ldo5_data),
  186. TPS_REG(LDO_6, &ldo6_data),
  187. TPS_REG(LDO_7, &ldo7_data),
  188. TPS_REG(LDO_8, &ldo8_data),
  189. TPS_REG(LDO_9, &ldo9_data),
  190. {
  191. .id = 0,
  192. .name = "tps6586x-rtc",
  193. .platform_data = &rtc_data,
  194. },
  195. };
  196.  
  197. static struct tps6586x_platform_data tps_platform = {
  198. .irq_base = TPS6586X_INT_BASE,
  199. .num_subdevs = ARRAY_SIZE(tps_devs),
  200. .subdevs = tps_devs,
  201. .gpio_base = TPS6586X_GPIO_BASE,
  202. };
  203.  
  204. static struct i2c_board_info __initdata ventana_regulators[] = {
  205. {
  206. I2C_BOARD_INFO("tps6586x", 0x34),
  207. .irq = INT_EXTERNAL_PMU,
  208. .platform_data = &tps_platform,
  209. },
  210. };
  211.  
  212. static void ventana_board_suspend(int lp_state, enum suspend_stage stg)
  213. {
  214. if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_SUSPEND_BEFORE_CPU))
  215. tegra_console_uart_suspend();
  216. }
  217.  
  218. static void ventana_board_resume(int lp_state, enum resume_stage stg)
  219. {
  220. if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_RESUME_AFTER_CPU))
  221. tegra_console_uart_resume();
  222. }
  223.  
  224. static struct tegra_suspend_platform_data ventana_suspend_data = {
  225. /*
  226. * Check power on time and crystal oscillator start time
  227. * for appropriate settings.
  228. */
  229. .cpu_timer = 2000,
  230. .cpu_off_timer = 100,
  231. .suspend_mode = TEGRA_SUSPEND_LP1,
  232. .core_timer = 0x7e7e,
  233. .core_off_timer = 0xf,
  234. .corereq_high = false,
  235. .sysclkreq_high = true,
  236. .board_suspend = ventana_board_suspend,
  237. .board_resume = ventana_board_resume,
  238. };
  239.  
  240. int __init ventana_regulator_init(void)
  241. {
  242. void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
  243. void __iomem *chip_id = IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804;
  244. u32 pmc_ctrl;
  245. u32 minor;
  246.  
  247. minor = (readl(chip_id) >> 16) & 0xf;
  248. /* A03 (but not A03p) chips do not support LP0 */
  249. if (minor == 3 && !(tegra_spare_fuse(18) || tegra_spare_fuse(19)))
  250. ventana_suspend_data.suspend_mode = TEGRA_SUSPEND_LP1;
  251.  
  252. /* configure the power management controller to trigger PMU
  253. * interrupts when low */
  254. pmc_ctrl = readl(pmc + PMC_CTRL);
  255. writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
  256.  
  257. i2c_register_board_info(4, ventana_regulators, 1);
  258.  
  259. // regulator_has_full_constraints();
  260.  
  261. tegra_init_suspend(&ventana_suspend_data);
  262.  
  263. return 0;
  264. }
  265.  
  266. static char *ventana_battery[] = {
  267. "battery",
  268. };
  269.  
  270. static struct gpio_charger_platform_data ventana_charger_pdata = {
  271. .name = "ac",
  272. .type = POWER_SUPPLY_TYPE_MAINS,
  273. .gpio = AC_PRESENT_GPIO,
  274. .gpio_active_low = 1,
  275. .supplied_to = ventana_battery,
  276. .num_supplicants = ARRAY_SIZE(ventana_battery),
  277. };
  278.  
  279. static struct platform_device ventana_charger_device = {
  280. .name = "gpio-charger",
  281. .dev = {
  282. .platform_data = &ventana_charger_pdata,
  283. },
  284. };
  285.  
  286. int __init ventana_charger_init(void)
  287. {
  288. tegra_gpio_enable(AC_PRESENT_GPIO);
  289. platform_device_register(&ventana_charger_device);
  290. return 0;
  291. }
  292.  
  293. static int __init ventana_pcie_init(void)
  294. {
  295. int ret;
  296.  
  297. if (!machine_is_ventana())
  298. return 0;
  299.  
  300. ret = gpio_request(TPS6586X_GPIO_BASE, "pcie_vdd");
  301. if (ret < 0)
  302. goto fail;
  303.  
  304. ret = gpio_direction_output(TPS6586X_GPIO_BASE, 1);
  305. if (ret < 0)
  306. goto fail;
  307.  
  308. gpio_export(TPS6586X_GPIO_BASE, false);
  309. return 0;
  310.  
  311. fail:
  312. pr_err("%s: gpio_request failed #%d\n", __func__, TPS6586X_GPIO_BASE);
  313. gpio_free(TPS6586X_GPIO_BASE);
  314. return ret;
  315. }
  316.  
  317. late_initcall(ventana_pcie_init);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement