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