Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
SRICHARAN R | beb407e | 2012-03-12 02:25:48 +0000 | [diff] [blame] | 2 | /* |
Nishanth Menon | 627612c | 2013-03-26 05:20:54 +0000 | [diff] [blame] | 3 | * (C) Copyright 2012-2013 |
SRICHARAN R | beb407e | 2012-03-12 02:25:48 +0000 | [diff] [blame] | 4 | * Texas Instruments, <www.ti.com> |
SRICHARAN R | beb407e | 2012-03-12 02:25:48 +0000 | [diff] [blame] | 5 | */ |
| 6 | #include <config.h> |
Nishanth Menon | 627612c | 2013-03-26 05:20:54 +0000 | [diff] [blame] | 7 | #include <palmas.h> |
SRICHARAN R | beb407e | 2012-03-12 02:25:48 +0000 | [diff] [blame] | 8 | |
Nishanth Menon | aa4f836 | 2013-03-26 05:20:55 +0000 | [diff] [blame] | 9 | void palmas_init_settings(void) |
SRICHARAN R | beb407e | 2012-03-12 02:25:48 +0000 | [diff] [blame] | 10 | { |
Lubomir Popov | ff397ab | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 11 | #ifdef CONFIG_PALMAS_SMPS7_FPWM |
| 12 | int err; |
| 13 | /* |
| 14 | * Set SMPS7 (1.8 V I/O supply on platforms with TWL6035/37) to |
| 15 | * forced PWM mode. This reduces noise (but affects efficiency). |
| 16 | */ |
| 17 | u8 val = SMPS_MODE_SLP_FPWM | SMPS_MODE_ACT_FPWM; |
| 18 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS7_CTRL, val); |
| 19 | if (err) |
| 20 | printf("palmas: could not force PWM for SMPS7: err = %d\n", |
| 21 | err); |
| 22 | #endif |
SRICHARAN R | beb407e | 2012-03-12 02:25:48 +0000 | [diff] [blame] | 23 | } |
Balaji T K | d9cf836 | 2012-03-12 02:25:49 +0000 | [diff] [blame] | 24 | |
Lokesh Vutla | d999d05 | 2016-11-23 13:25:28 +0530 | [diff] [blame] | 25 | #if defined(CONFIG_OMAP54XX) |
| 26 | int lp873x_mmc1_poweron_ldo(uint voltage) |
| 27 | { |
| 28 | if (palmas_i2c_write_u8(LP873X_LDO1_ADDR, LP873X_LDO1_VOLTAGE, |
| 29 | voltage)) { |
| 30 | printf("lp873x: could not set LDO1 voltage.\n"); |
| 31 | return 1; |
| 32 | } |
| 33 | /* TURN ON LDO1 */ |
| 34 | if (palmas_i2c_write_u8(LP873X_LDO1_ADDR, LP873X_LDO1_CTRL, |
| 35 | LP873X_LDO_CTRL_EN | LP873X_LDO_CTRL_RDIS_EN)) { |
| 36 | printf("lp873x: could not turn on LDO1.\n"); |
| 37 | return 1; |
| 38 | } |
| 39 | return 0; |
| 40 | |
| 41 | } |
| 42 | #endif |
| 43 | |
Lokesh Vutla | 22fa819 | 2017-08-21 12:50:50 +0530 | [diff] [blame] | 44 | 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] | 45 | { |
| 46 | u8 val = 0; |
| 47 | |
Nishanth Menon | 813fe9d | 2016-11-29 15:22:00 +0530 | [diff] [blame] | 48 | #if defined(CONFIG_DRA7XX) |
Jaehoon Chung | 10e80f3 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 49 | int ret; |
Lokesh Vutla | 22fa819 | 2017-08-21 12:50:50 +0530 | [diff] [blame] | 50 | |
| 51 | ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, ldo_volt, voltage); |
Jaehoon Chung | 10e80f3 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 52 | if (ret) { |
Lubomir Popov | ff397ab | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 53 | printf("tps65903x: could not set LDO1 voltage.\n"); |
Jaehoon Chung | 10e80f3 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 54 | return ret; |
Lubomir Popov | ff397ab | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 55 | } |
| 56 | /* TURN ON LDO1 */ |
| 57 | val = RSC_MODE_SLEEP | RSC_MODE_ACTIVE; |
Lokesh Vutla | 22fa819 | 2017-08-21 12:50:50 +0530 | [diff] [blame] | 58 | ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, ldo_ctrl, val); |
Jaehoon Chung | 10e80f3 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 59 | if (ret) { |
Lubomir Popov | ff397ab | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 60 | printf("tps65903x: could not turn on LDO1.\n"); |
Jaehoon Chung | 10e80f3 | 2016-12-15 20:49:50 +0900 | [diff] [blame] | 61 | return ret; |
Vincent Stehlé | 19b8bc4 | 2012-12-03 05:23:17 +0000 | [diff] [blame] | 62 | } |
Lubomir Popov | ff397ab | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 63 | return 0; |
| 64 | #else |
| 65 | /* |
| 66 | * We assume that this is a OMAP543X + TWL603X board: |
| 67 | * Set TWL6035/37 LDO9 to 3.0 V |
| 68 | */ |
| 69 | val = LDO_VOLT_3V0; |
| 70 | return twl603x_mmc1_set_ldo9(val); |
| 71 | #endif |
| 72 | } |
Balaji T K | d9cf836 | 2012-03-12 02:25:49 +0000 | [diff] [blame] | 73 | |
Lubomir Popov | ff397ab | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 74 | /* |
| 75 | * On some OMAP5 + TWL603X hardware the SD card socket and LDO9_IN are |
| 76 | * powered by an external 3.3 V regulator, while the output of LDO9 |
| 77 | * supplies VDDS_SDCARD for the OMAP5 interface only. This implies that |
| 78 | * LDO9 could be set to 'bypass' mode when required (e.g. for 3.3 V cards). |
| 79 | */ |
| 80 | int twl603x_mmc1_set_ldo9(u8 vsel) |
| 81 | { |
| 82 | u8 cval = 0, vval = 0; /* Off by default */ |
| 83 | int err; |
Vincent Stehlé | 19b8bc4 | 2012-12-03 05:23:17 +0000 | [diff] [blame] | 84 | |
Lubomir Popov | ff397ab | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 85 | if (vsel) { |
| 86 | /* Turn on */ |
| 87 | if (vsel > LDO_VOLT_3V3) { |
| 88 | /* Put LDO9 in bypass */ |
| 89 | cval = LDO9_BYP_EN | RSC_MODE_SLEEP | RSC_MODE_ACTIVE; |
| 90 | vval = LDO_VOLT_3V3; |
| 91 | } else { |
| 92 | cval = RSC_MODE_SLEEP | RSC_MODE_ACTIVE; |
| 93 | vval = vsel & 0x3f; |
| 94 | } |
Vincent Stehlé | 19b8bc4 | 2012-12-03 05:23:17 +0000 | [diff] [blame] | 95 | } |
Lubomir Popov | ff397ab | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 96 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_VOLTAGE, vval); |
| 97 | if (err) { |
| 98 | printf("twl603x: could not set LDO9 %s: err = %d\n", |
| 99 | vsel > LDO_VOLT_3V3 ? "bypass" : "voltage", err); |
| 100 | return err; |
| 101 | } |
| 102 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_CTRL, cval); |
| 103 | if (err) |
| 104 | printf("twl603x: could not turn %s LDO9: err = %d\n", |
| 105 | cval ? "on" : "off", err); |
| 106 | return err; |
| 107 | } |
Vincent Stehlé | 19b8bc4 | 2012-12-03 05:23:17 +0000 | [diff] [blame] | 108 | |
Lubomir Popov | ff397ab | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 109 | #ifdef CONFIG_PALMAS_AUDPWR |
| 110 | /* |
| 111 | * Turn audio codec power and 32 kHz clock on/off. Use for |
| 112 | * testing OMAP543X + TWL603X + TWL604X boards only. |
| 113 | */ |
| 114 | int twl603x_audio_power(u8 on) |
| 115 | { |
| 116 | u8 cval = 0, vval = 0, c32k = 0; |
| 117 | int err; |
| 118 | |
| 119 | if (on) { |
| 120 | vval = SMPS_VOLT_2V1; |
| 121 | cval = SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO; |
| 122 | c32k = RSC_MODE_SLEEP | RSC_MODE_ACTIVE; |
| 123 | } |
| 124 | /* Set SMPS9 to 2.1 V (for TWL604x), or to 0 (off) */ |
| 125 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_VOLTAGE, vval); |
| 126 | if (err) { |
| 127 | printf("twl603x: could not set SMPS9 voltage: err = %d\n", |
| 128 | err); |
| 129 | return err; |
| 130 | } |
| 131 | /* Turn on or off SMPS9 */ |
| 132 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_CTRL, cval); |
| 133 | if (err) { |
| 134 | printf("twl603x: could not turn SMPS9 %s: err = %d\n", |
| 135 | cval ? "on" : "off", err); |
| 136 | return err; |
| 137 | } |
| 138 | /* Output 32 kHz clock on or off */ |
| 139 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, CLK32KGAUDIO_CTRL, c32k); |
| 140 | if (err) |
| 141 | printf("twl603x: could not turn CLK32KGAUDIO %s: err = %d\n", |
| 142 | c32k ? "on" : "off", err); |
| 143 | return err; |
| 144 | } |
| 145 | #endif |
| 146 | |
Dan Murphy | e0926da | 2013-08-26 08:54:49 -0500 | [diff] [blame] | 147 | #ifdef CONFIG_PALMAS_USB_SS_PWR |
| 148 | /** |
| 149 | * @brief palmas_enable_ss_ldo - Configure EVM board specific configurations |
| 150 | * for the USB Super speed SMPS10 regulator. |
| 151 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 152 | * Return: 0 |
Dan Murphy | e0926da | 2013-08-26 08:54:49 -0500 | [diff] [blame] | 153 | */ |
| 154 | int palmas_enable_ss_ldo(void) |
| 155 | { |
| 156 | /* Enable smps10 regulator */ |
| 157 | return palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS10_CTRL, |
| 158 | SMPS10_MODE_ACTIVE_D); |
| 159 | } |
| 160 | #endif |
| 161 | |
Lubomir Popov | ff397ab | 2013-06-06 04:16:40 +0000 | [diff] [blame] | 162 | /* |
| 163 | * Enable/disable back-up battery (or super cap) charging on TWL6035/37. |
| 164 | * Please use defined BB_xxx values. |
| 165 | */ |
| 166 | int twl603x_enable_bb_charge(u8 bb_fields) |
| 167 | { |
| 168 | u8 val = bb_fields & 0x0f; |
| 169 | int err; |
| 170 | |
| 171 | val |= (VRTC_EN_SLP | VRTC_EN_OFF | VRTC_PWEN); |
| 172 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, BB_VRTC_CTRL, val); |
| 173 | if (err) |
| 174 | printf("twl603x: could not set BB_VRTC_CTRL to 0x%02x: err = %d\n", |
| 175 | val, err); |
| 176 | return err; |
Balaji T K | d9cf836 | 2012-03-12 02:25:49 +0000 | [diff] [blame] | 177 | } |
Jean-Jacques Hiblot | 77a1397 | 2018-12-07 14:50:46 +0100 | [diff] [blame] | 178 | |
Igor Opaniuk | f7c9176 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 179 | #if CONFIG_IS_ENABLED(DM_I2C) |
Jean-Jacques Hiblot | 77a1397 | 2018-12-07 14:50:46 +0100 | [diff] [blame] | 180 | int palmas_i2c_write_u8(u8 chip_no, u8 reg, u8 val) |
| 181 | { |
| 182 | struct udevice *dev; |
| 183 | int ret; |
| 184 | |
| 185 | ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev); |
| 186 | if (ret) { |
| 187 | pr_err("unable to get I2C bus. ret %d\n", ret); |
| 188 | return ret; |
| 189 | } |
| 190 | ret = dm_i2c_reg_write(dev, reg, val); |
| 191 | if (ret) { |
| 192 | pr_err("writing to palmas failed. ret %d\n", ret); |
| 193 | return ret; |
| 194 | } |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | int palmas_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp) |
| 199 | { |
| 200 | struct udevice *dev; |
| 201 | int ret; |
| 202 | |
| 203 | ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev); |
| 204 | if (ret) { |
| 205 | pr_err("unable to get I2C bus. ret %d\n", ret); |
| 206 | return ret; |
| 207 | } |
| 208 | ret = dm_i2c_reg_read(dev, reg); |
| 209 | if (ret < 0) { |
| 210 | pr_err("reading from palmas failed. ret %d\n", ret); |
| 211 | return ret; |
| 212 | } |
| 213 | *valp = (u8)ret; |
| 214 | return 0; |
| 215 | } |
| 216 | #endif |