1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2012-2013
4 * Texas Instruments, <www.ti.com>
9 void palmas_init_settings(void)
11 #ifdef CONFIG_PALMAS_SMPS7_FPWM
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).
17 u8 val = SMPS_MODE_SLP_FPWM | SMPS_MODE_ACT_FPWM;
18 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS7_CTRL, val);
20 printf("palmas: could not force PWM for SMPS7: err = %d\n",
25 #if defined(CONFIG_OMAP54XX)
26 int lp873x_mmc1_poweron_ldo(uint voltage)
28 if (palmas_i2c_write_u8(LP873X_LDO1_ADDR, LP873X_LDO1_VOLTAGE,
30 printf("lp873x: could not set LDO1 voltage.\n");
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");
44 int palmas_mmc1_poweron_ldo(uint ldo_volt, uint ldo_ctrl, uint voltage)
48 #if defined(CONFIG_DRA7XX)
51 ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, ldo_volt, voltage);
53 printf("tps65903x: could not set LDO1 voltage.\n");
57 val = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
58 ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, ldo_ctrl, val);
60 printf("tps65903x: could not turn on LDO1.\n");
66 * We assume that this is a OMAP543X + TWL603X board:
67 * Set TWL6035/37 LDO9 to 3.0 V
70 return twl603x_mmc1_set_ldo9(val);
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).
80 int twl603x_mmc1_set_ldo9(u8 vsel)
82 u8 cval = 0, vval = 0; /* Off by default */
87 if (vsel > LDO_VOLT_3V3) {
88 /* Put LDO9 in bypass */
89 cval = LDO9_BYP_EN | RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
92 cval = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
96 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_VOLTAGE, vval);
98 printf("twl603x: could not set LDO9 %s: err = %d\n",
99 vsel > LDO_VOLT_3V3 ? "bypass" : "voltage", err);
102 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_CTRL, cval);
104 printf("twl603x: could not turn %s LDO9: err = %d\n",
105 cval ? "on" : "off", err);
109 #ifdef CONFIG_PALMAS_AUDPWR
111 * Turn audio codec power and 32 kHz clock on/off. Use for
112 * testing OMAP543X + TWL603X + TWL604X boards only.
114 int twl603x_audio_power(u8 on)
116 u8 cval = 0, vval = 0, c32k = 0;
120 vval = SMPS_VOLT_2V1;
121 cval = SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO;
122 c32k = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
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);
127 printf("twl603x: could not set SMPS9 voltage: err = %d\n",
131 /* Turn on or off SMPS9 */
132 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_CTRL, cval);
134 printf("twl603x: could not turn SMPS9 %s: err = %d\n",
135 cval ? "on" : "off", err);
138 /* Output 32 kHz clock on or off */
139 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, CLK32KGAUDIO_CTRL, c32k);
141 printf("twl603x: could not turn CLK32KGAUDIO %s: err = %d\n",
142 c32k ? "on" : "off", err);
147 #ifdef CONFIG_PALMAS_USB_SS_PWR
149 * @brief palmas_enable_ss_ldo - Configure EVM board specific configurations
150 * for the USB Super speed SMPS10 regulator.
154 int palmas_enable_ss_ldo(void)
156 /* Enable smps10 regulator */
157 return palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS10_CTRL,
158 SMPS10_MODE_ACTIVE_D);
163 * Enable/disable back-up battery (or super cap) charging on TWL6035/37.
164 * Please use defined BB_xxx values.
166 int twl603x_enable_bb_charge(u8 bb_fields)
168 u8 val = bb_fields & 0x0f;
171 val |= (VRTC_EN_SLP | VRTC_EN_OFF | VRTC_PWEN);
172 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, BB_VRTC_CTRL, val);
174 printf("twl603x: could not set BB_VRTC_CTRL to 0x%02x: err = %d\n",
179 #if CONFIG_IS_ENABLED(DM_I2C)
180 int palmas_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
185 ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);
187 pr_err("unable to get I2C bus. ret %d\n", ret);
190 ret = dm_i2c_reg_write(dev, reg, val);
192 pr_err("writing to palmas failed. ret %d\n", ret);
198 int palmas_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
203 ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);
205 pr_err("unable to get I2C bus. ret %d\n", ret);
208 ret = dm_i2c_reg_read(dev, reg);
210 pr_err("reading from palmas failed. ret %d\n", ret);