SRICHARAN R | 2114429 | 2012-03-12 02:25:48 +0000 | [diff] [blame] | 1 | /* |
Nishanth Menon | cb19910 | 2013-03-26 05:20:54 +0000 | [diff] [blame] | 2 | * (C) Copyright 2012-2013 |
SRICHARAN R | 2114429 | 2012-03-12 02:25:48 +0000 | [diff] [blame] | 3 | * Texas Instruments, <www.ti.com> |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
SRICHARAN R | 2114429 | 2012-03-12 02:25:48 +0000 | [diff] [blame] | 6 | */ |
| 7 | #include <config.h> |
Nishanth Menon | cb19910 | 2013-03-26 05:20:54 +0000 | [diff] [blame] | 8 | #include <palmas.h> |
SRICHARAN R | 2114429 | 2012-03-12 02:25:48 +0000 | [diff] [blame] | 9 | |
Nishanth Menon | 1273388 | 2013-03-26 05:20:55 +0000 | [diff] [blame] | 10 | void palmas_init_settings(void) |
SRICHARAN R | 2114429 | 2012-03-12 02:25:48 +0000 | [diff] [blame] | 11 | { |
Lubomir Popov | e9090fa | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 12 | #ifdef CONFIG_PALMAS_SMPS7_FPWM |
| 13 | int err; |
| 14 | /* |
| 15 | * Set SMPS7 (1.8 V I/O supply on platforms with TWL6035/37) to |
| 16 | * forced PWM mode. This reduces noise (but affects efficiency). |
| 17 | */ |
| 18 | u8 val = SMPS_MODE_SLP_FPWM | SMPS_MODE_ACT_FPWM; |
| 19 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS7_CTRL, val); |
| 20 | if (err) |
| 21 | printf("palmas: could not force PWM for SMPS7: err = %d\n", |
| 22 | err); |
| 23 | #endif |
SRICHARAN R | 2114429 | 2012-03-12 02:25:48 +0000 | [diff] [blame] | 24 | } |
Balaji T K | dd23e59 | 2012-03-12 02:25:49 +0000 | [diff] [blame] | 25 | |
Lokesh Vutla | b4b0600 | 2016-11-23 13:25:28 +0530 | [diff] [blame] | 26 | #if defined(CONFIG_OMAP54XX) |
| 27 | int lp873x_mmc1_poweron_ldo(uint voltage) |
| 28 | { |
| 29 | if (palmas_i2c_write_u8(LP873X_LDO1_ADDR, LP873X_LDO1_VOLTAGE, |
| 30 | voltage)) { |
| 31 | printf("lp873x: could not set LDO1 voltage.\n"); |
| 32 | return 1; |
| 33 | } |
| 34 | /* TURN ON LDO1 */ |
| 35 | if (palmas_i2c_write_u8(LP873X_LDO1_ADDR, LP873X_LDO1_CTRL, |
| 36 | LP873X_LDO_CTRL_EN | LP873X_LDO_CTRL_RDIS_EN)) { |
| 37 | printf("lp873x: could not turn on LDO1.\n"); |
| 38 | return 1; |
| 39 | } |
| 40 | return 0; |
| 41 | |
| 42 | } |
| 43 | #endif |
| 44 | |
| 45 | int palmas_mmc1_poweron_ldo(uint voltage) |
Balaji T K | dd23e59 | 2012-03-12 02:25:49 +0000 | [diff] [blame] | 46 | { |
| 47 | u8 val = 0; |
| 48 | |
Nishanth Menon | 3891a54 | 2016-11-29 15:22:00 +0530 | [diff] [blame] | 49 | #if defined(CONFIG_DRA7XX) |
Jaehoon Chung | 505cf47 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 50 | int ret; |
Lubomir Popov | e9090fa | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 51 | /* |
| 52 | * Currently valid for the dra7xx_evm board: |
| 53 | * Set TPS659038 LDO1 to 3.0 V |
| 54 | */ |
| 55 | val = LDO_VOLT_3V0; |
Jaehoon Chung | 505cf47 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 56 | ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_VOLTAGE, val); |
| 57 | if (ret) { |
Lubomir Popov | e9090fa | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 58 | printf("tps65903x: could not set LDO1 voltage.\n"); |
Jaehoon Chung | 505cf47 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 59 | return ret; |
Vincent Stehlé | ce851c8 | 2012-12-03 05:23:17 +0000 | [diff] [blame] | 60 | } |
Lubomir Popov | e9090fa | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 61 | /* TURN ON LDO1 */ |
| 62 | val = RSC_MODE_SLEEP | RSC_MODE_ACTIVE; |
Jaehoon Chung | 505cf47 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 63 | ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_CTRL, val); |
| 64 | if (ret) { |
Lubomir Popov | e9090fa | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 65 | printf("tps65903x: could not turn on LDO1.\n"); |
Jaehoon Chung | 505cf47 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 66 | return ret; |
Vincent Stehlé | ce851c8 | 2012-12-03 05:23:17 +0000 | [diff] [blame] | 67 | } |
Vincent Stehlé | ce851c8 | 2012-12-03 05:23:17 +0000 | [diff] [blame] | 68 | return 0; |
Lubomir Popov | e9090fa | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 69 | #else |
| 70 | /* |
| 71 | * We assume that this is a OMAP543X + TWL603X board: |
| 72 | * Set TWL6035/37 LDO9 to 3.0 V |
| 73 | */ |
| 74 | val = LDO_VOLT_3V0; |
| 75 | return twl603x_mmc1_set_ldo9(val); |
| 76 | #endif |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * On some OMAP5 + TWL603X hardware the SD card socket and LDO9_IN are |
| 81 | * powered by an external 3.3 V regulator, while the output of LDO9 |
| 82 | * supplies VDDS_SDCARD for the OMAP5 interface only. This implies that |
| 83 | * LDO9 could be set to 'bypass' mode when required (e.g. for 3.3 V cards). |
| 84 | */ |
| 85 | int twl603x_mmc1_set_ldo9(u8 vsel) |
| 86 | { |
| 87 | u8 cval = 0, vval = 0; /* Off by default */ |
| 88 | int err; |
| 89 | |
| 90 | if (vsel) { |
| 91 | /* Turn on */ |
| 92 | if (vsel > LDO_VOLT_3V3) { |
| 93 | /* Put LDO9 in bypass */ |
| 94 | cval = LDO9_BYP_EN | RSC_MODE_SLEEP | RSC_MODE_ACTIVE; |
| 95 | vval = LDO_VOLT_3V3; |
| 96 | } else { |
| 97 | cval = RSC_MODE_SLEEP | RSC_MODE_ACTIVE; |
| 98 | vval = vsel & 0x3f; |
| 99 | } |
| 100 | } |
| 101 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_VOLTAGE, vval); |
| 102 | if (err) { |
| 103 | printf("twl603x: could not set LDO9 %s: err = %d\n", |
| 104 | vsel > LDO_VOLT_3V3 ? "bypass" : "voltage", err); |
| 105 | return err; |
| 106 | } |
| 107 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_CTRL, cval); |
| 108 | if (err) |
| 109 | printf("twl603x: could not turn %s LDO9: err = %d\n", |
| 110 | cval ? "on" : "off", err); |
| 111 | return err; |
| 112 | } |
| 113 | |
| 114 | #ifdef CONFIG_PALMAS_AUDPWR |
| 115 | /* |
| 116 | * Turn audio codec power and 32 kHz clock on/off. Use for |
| 117 | * testing OMAP543X + TWL603X + TWL604X boards only. |
| 118 | */ |
| 119 | int twl603x_audio_power(u8 on) |
| 120 | { |
| 121 | u8 cval = 0, vval = 0, c32k = 0; |
| 122 | int err; |
| 123 | |
| 124 | if (on) { |
| 125 | vval = SMPS_VOLT_2V1; |
| 126 | cval = SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO; |
| 127 | c32k = RSC_MODE_SLEEP | RSC_MODE_ACTIVE; |
| 128 | } |
| 129 | /* Set SMPS9 to 2.1 V (for TWL604x), or to 0 (off) */ |
| 130 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_VOLTAGE, vval); |
| 131 | if (err) { |
| 132 | printf("twl603x: could not set SMPS9 voltage: err = %d\n", |
| 133 | err); |
| 134 | return err; |
| 135 | } |
| 136 | /* Turn on or off SMPS9 */ |
| 137 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_CTRL, cval); |
| 138 | if (err) { |
| 139 | printf("twl603x: could not turn SMPS9 %s: err = %d\n", |
| 140 | cval ? "on" : "off", err); |
| 141 | return err; |
| 142 | } |
| 143 | /* Output 32 kHz clock on or off */ |
| 144 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, CLK32KGAUDIO_CTRL, c32k); |
| 145 | if (err) |
| 146 | printf("twl603x: could not turn CLK32KGAUDIO %s: err = %d\n", |
| 147 | c32k ? "on" : "off", err); |
| 148 | return err; |
| 149 | } |
| 150 | #endif |
| 151 | |
Dan Murphy | 1bd435b | 2013-08-26 08:54:49 -0500 | [diff] [blame] | 152 | #ifdef CONFIG_PALMAS_USB_SS_PWR |
| 153 | /** |
| 154 | * @brief palmas_enable_ss_ldo - Configure EVM board specific configurations |
| 155 | * for the USB Super speed SMPS10 regulator. |
| 156 | * |
| 157 | * @return 0 |
| 158 | */ |
| 159 | int palmas_enable_ss_ldo(void) |
| 160 | { |
| 161 | /* Enable smps10 regulator */ |
| 162 | return palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS10_CTRL, |
| 163 | SMPS10_MODE_ACTIVE_D); |
| 164 | } |
| 165 | #endif |
| 166 | |
Lubomir Popov | e9090fa | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 167 | /* |
| 168 | * Enable/disable back-up battery (or super cap) charging on TWL6035/37. |
| 169 | * Please use defined BB_xxx values. |
| 170 | */ |
| 171 | int twl603x_enable_bb_charge(u8 bb_fields) |
| 172 | { |
| 173 | u8 val = bb_fields & 0x0f; |
| 174 | int err; |
| 175 | |
| 176 | val |= (VRTC_EN_SLP | VRTC_EN_OFF | VRTC_PWEN); |
| 177 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, BB_VRTC_CTRL, val); |
| 178 | if (err) |
| 179 | printf("twl603x: could not set BB_VRTC_CTRL to 0x%02x: err = %d\n", |
| 180 | val, err); |
| 181 | return err; |
Balaji T K | dd23e59 | 2012-03-12 02:25:49 +0000 | [diff] [blame] | 182 | } |