Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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/platform_device.h> |
| 20 | #include <linux/gpio.h> |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 21 | #include <linux/regulator/machine.h> |
Laxman Dewangan | 3d55c29 | 2012-07-24 10:36:23 -0600 | [diff] [blame] | 22 | #include <linux/regulator/fixed.h> |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 23 | #include <linux/mfd/tps6586x.h> |
Stephen Warren | a12c0ef | 2012-05-02 15:47:12 -0600 | [diff] [blame] | 24 | #include <linux/of.h> |
| 25 | #include <linux/of_i2c.h> |
| 26 | |
| 27 | #include <asm/mach-types.h> |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 28 | |
| 29 | #include <mach/irqs.h> |
| 30 | |
Stephen Warren | f2a4d8a | 2011-05-31 15:14:07 -0600 | [diff] [blame] | 31 | #include "board-harmony.h" |
| 32 | |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 33 | static struct regulator_consumer_supply tps658621_ldo0_supply[] = { |
| 34 | REGULATOR_SUPPLY("pex_clk", NULL), |
| 35 | }; |
| 36 | |
| 37 | static struct regulator_init_data ldo0_data = { |
Laxman Dewangan | 3d55c29 | 2012-07-24 10:36:23 -0600 | [diff] [blame] | 38 | .supply_regulator = "vdd_sm2", |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 39 | .constraints = { |
Laxman Dewangan | 3d55c29 | 2012-07-24 10:36:23 -0600 | [diff] [blame] | 40 | .name = "vdd_ldo0", |
Thierry Reding | 1dbe1df | 2012-02-20 08:57:27 +0100 | [diff] [blame] | 41 | .min_uV = 3300 * 1000, |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 42 | .max_uV = 3300 * 1000, |
| 43 | .valid_modes_mask = (REGULATOR_MODE_NORMAL | |
| 44 | REGULATOR_MODE_STANDBY), |
| 45 | .valid_ops_mask = (REGULATOR_CHANGE_MODE | |
| 46 | REGULATOR_CHANGE_STATUS | |
| 47 | REGULATOR_CHANGE_VOLTAGE), |
Thierry Reding | 1dbe1df | 2012-02-20 08:57:27 +0100 | [diff] [blame] | 48 | .apply_uV = 1, |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 49 | }, |
| 50 | .num_consumer_supplies = ARRAY_SIZE(tps658621_ldo0_supply), |
| 51 | .consumer_supplies = tps658621_ldo0_supply, |
| 52 | }; |
| 53 | |
Laxman Dewangan | 3d55c29 | 2012-07-24 10:36:23 -0600 | [diff] [blame] | 54 | #define HARMONY_REGULATOR_INIT(_id, _name, _supply, _minmv, _maxmv) \ |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 55 | static struct regulator_init_data _id##_data = { \ |
Laxman Dewangan | 3d55c29 | 2012-07-24 10:36:23 -0600 | [diff] [blame] | 56 | .supply_regulator = _supply, \ |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 57 | .constraints = { \ |
Laxman Dewangan | 3d55c29 | 2012-07-24 10:36:23 -0600 | [diff] [blame] | 58 | .name = _name, \ |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 59 | .min_uV = (_minmv)*1000, \ |
| 60 | .max_uV = (_maxmv)*1000, \ |
| 61 | .valid_modes_mask = (REGULATOR_MODE_NORMAL | \ |
| 62 | REGULATOR_MODE_STANDBY), \ |
| 63 | .valid_ops_mask = (REGULATOR_CHANGE_MODE | \ |
| 64 | REGULATOR_CHANGE_STATUS | \ |
| 65 | REGULATOR_CHANGE_VOLTAGE), \ |
| 66 | }, \ |
| 67 | } |
| 68 | |
Laxman Dewangan | 3d55c29 | 2012-07-24 10:36:23 -0600 | [diff] [blame] | 69 | HARMONY_REGULATOR_INIT(sm0, "vdd_sm0", "vdd_sys", 725, 1500); |
| 70 | HARMONY_REGULATOR_INIT(sm1, "vdd_sm1", "vdd_sys", 725, 1500); |
| 71 | HARMONY_REGULATOR_INIT(sm2, "vdd_sm2", "vdd_sys", 3000, 4550); |
| 72 | HARMONY_REGULATOR_INIT(ldo1, "vdd_ldo1", "vdd_sm2", 725, 1500); |
| 73 | HARMONY_REGULATOR_INIT(ldo2, "vdd_ldo2", "vdd_sm2", 725, 1500); |
| 74 | HARMONY_REGULATOR_INIT(ldo3, "vdd_ldo3", "vdd_sm2", 1250, 3300); |
| 75 | HARMONY_REGULATOR_INIT(ldo4, "vdd_ldo4", "vdd_sm2", 1700, 2475); |
| 76 | HARMONY_REGULATOR_INIT(ldo5, "vdd_ldo5", NULL, 1250, 3300); |
| 77 | HARMONY_REGULATOR_INIT(ldo6, "vdd_ldo6", "vdd_sm2", 1250, 3300); |
| 78 | HARMONY_REGULATOR_INIT(ldo7, "vdd_ldo7", "vdd_sm2", 1250, 3300); |
| 79 | HARMONY_REGULATOR_INIT(ldo8, "vdd_ldo8", "vdd_sm2", 1250, 3300); |
| 80 | HARMONY_REGULATOR_INIT(ldo9, "vdd_ldo9", "vdd_sm2", 1250, 3300); |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 81 | |
| 82 | #define TPS_REG(_id, _data) \ |
| 83 | { \ |
| 84 | .id = TPS6586X_ID_##_id, \ |
| 85 | .name = "tps6586x-regulator", \ |
| 86 | .platform_data = _data, \ |
| 87 | } |
| 88 | |
| 89 | static struct tps6586x_subdev_info tps_devs[] = { |
| 90 | TPS_REG(SM_0, &sm0_data), |
| 91 | TPS_REG(SM_1, &sm1_data), |
| 92 | TPS_REG(SM_2, &sm2_data), |
| 93 | TPS_REG(LDO_0, &ldo0_data), |
| 94 | TPS_REG(LDO_1, &ldo1_data), |
| 95 | TPS_REG(LDO_2, &ldo2_data), |
| 96 | TPS_REG(LDO_3, &ldo3_data), |
| 97 | TPS_REG(LDO_4, &ldo4_data), |
| 98 | TPS_REG(LDO_5, &ldo5_data), |
| 99 | TPS_REG(LDO_6, &ldo6_data), |
| 100 | TPS_REG(LDO_7, &ldo7_data), |
| 101 | TPS_REG(LDO_8, &ldo8_data), |
| 102 | TPS_REG(LDO_9, &ldo9_data), |
| 103 | }; |
| 104 | |
| 105 | static struct tps6586x_platform_data tps_platform = { |
| 106 | .irq_base = TEGRA_NR_IRQS, |
| 107 | .num_subdevs = ARRAY_SIZE(tps_devs), |
| 108 | .subdevs = tps_devs, |
Stephen Warren | f2a4d8a | 2011-05-31 15:14:07 -0600 | [diff] [blame] | 109 | .gpio_base = HARMONY_GPIO_TPS6586X(0), |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | static struct i2c_board_info __initdata harmony_regulators[] = { |
| 113 | { |
| 114 | I2C_BOARD_INFO("tps6586x", 0x34), |
| 115 | .irq = INT_EXTERNAL_PMU, |
| 116 | .platform_data = &tps_platform, |
| 117 | }, |
| 118 | }; |
| 119 | |
| 120 | int __init harmony_regulator_init(void) |
| 121 | { |
Stephen Warren | a12c0ef | 2012-05-02 15:47:12 -0600 | [diff] [blame] | 122 | if (machine_is_harmony()) { |
Laxman Dewangan | 3d55c29 | 2012-07-24 10:36:23 -0600 | [diff] [blame] | 123 | regulator_register_always_on(0, "vdd_sys", |
| 124 | NULL, 0, 5000000); |
Stephen Warren | a12c0ef | 2012-05-02 15:47:12 -0600 | [diff] [blame] | 125 | i2c_register_board_info(3, harmony_regulators, 1); |
| 126 | } else { /* Harmony, booted using device tree */ |
| 127 | struct device_node *np; |
| 128 | struct i2c_adapter *adapter; |
| 129 | |
| 130 | np = of_find_node_by_path("/i2c@7000d000"); |
| 131 | if (np == NULL) { |
| 132 | pr_err("Could not find device_node for DVC I2C\n"); |
| 133 | return -ENODEV; |
| 134 | } |
| 135 | |
| 136 | adapter = of_find_i2c_adapter_by_node(np); |
| 137 | if (!adapter) { |
| 138 | pr_err("Could not find i2c_adapter for DVC I2C\n"); |
| 139 | return -ENODEV; |
| 140 | } |
| 141 | |
| 142 | i2c_new_device(adapter, harmony_regulators); |
| 143 | } |
Mike Rapoport | 6f168f2 | 2011-03-09 16:31:18 +0200 | [diff] [blame] | 144 | |
| 145 | return 0; |
| 146 | } |