blob: 4f9a62cb34b2aaf08f72abea2a60e0168b4789d1 [file] [log] [blame]
SRICHARAN R21144292012-03-12 02:25:48 +00001/*
Nishanth Menoncb199102013-03-26 05:20:54 +00002 * (C) Copyright 2012-2013
SRICHARAN R21144292012-03-12 02:25:48 +00003 * Texas Instruments, <www.ti.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
SRICHARAN R21144292012-03-12 02:25:48 +00006 */
7#include <config.h>
Nishanth Menoncb199102013-03-26 05:20:54 +00008#include <palmas.h>
SRICHARAN R21144292012-03-12 02:25:48 +00009
Nishanth Menon12733882013-03-26 05:20:55 +000010void palmas_init_settings(void)
SRICHARAN R21144292012-03-12 02:25:48 +000011{
Lubomir Popove9090fa2013-06-06 04:16:40 +000012#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 R21144292012-03-12 02:25:48 +000024}
Balaji T Kdd23e592012-03-12 02:25:49 +000025
Lokesh Vutlab4b06002016-11-23 13:25:28 +053026#if defined(CONFIG_OMAP54XX)
27int 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
45int palmas_mmc1_poweron_ldo(uint voltage)
Balaji T Kdd23e592012-03-12 02:25:49 +000046{
47 u8 val = 0;
48
Nishanth Menon3891a542016-11-29 15:22:00 +053049#if defined(CONFIG_DRA7XX)
Lubomir Popove9090fa2013-06-06 04:16:40 +000050 /*
51 * Currently valid for the dra7xx_evm board:
52 * Set TPS659038 LDO1 to 3.0 V
53 */
54 val = LDO_VOLT_3V0;
55 if (palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_VOLTAGE, val)) {
56 printf("tps65903x: could not set LDO1 voltage.\n");
Vincent Stehléce851c82012-12-03 05:23:17 +000057 return 1;
58 }
Lubomir Popove9090fa2013-06-06 04:16:40 +000059 /* TURN ON LDO1 */
60 val = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
61 if (palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_CTRL, val)) {
62 printf("tps65903x: could not turn on LDO1.\n");
Vincent Stehléce851c82012-12-03 05:23:17 +000063 return 1;
64 }
Vincent Stehléce851c82012-12-03 05:23:17 +000065 return 0;
Lubomir Popove9090fa2013-06-06 04:16:40 +000066#else
67 /*
68 * We assume that this is a OMAP543X + TWL603X board:
69 * Set TWL6035/37 LDO9 to 3.0 V
70 */
71 val = LDO_VOLT_3V0;
72 return twl603x_mmc1_set_ldo9(val);
73#endif
74}
75
76/*
77 * On some OMAP5 + TWL603X hardware the SD card socket and LDO9_IN are
78 * powered by an external 3.3 V regulator, while the output of LDO9
79 * supplies VDDS_SDCARD for the OMAP5 interface only. This implies that
80 * LDO9 could be set to 'bypass' mode when required (e.g. for 3.3 V cards).
81 */
82int twl603x_mmc1_set_ldo9(u8 vsel)
83{
84 u8 cval = 0, vval = 0; /* Off by default */
85 int err;
86
87 if (vsel) {
88 /* Turn on */
89 if (vsel > LDO_VOLT_3V3) {
90 /* Put LDO9 in bypass */
91 cval = LDO9_BYP_EN | RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
92 vval = LDO_VOLT_3V3;
93 } else {
94 cval = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
95 vval = vsel & 0x3f;
96 }
97 }
98 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_VOLTAGE, vval);
99 if (err) {
100 printf("twl603x: could not set LDO9 %s: err = %d\n",
101 vsel > LDO_VOLT_3V3 ? "bypass" : "voltage", err);
102 return err;
103 }
104 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_CTRL, cval);
105 if (err)
106 printf("twl603x: could not turn %s LDO9: err = %d\n",
107 cval ? "on" : "off", err);
108 return err;
109}
110
111#ifdef CONFIG_PALMAS_AUDPWR
112/*
113 * Turn audio codec power and 32 kHz clock on/off. Use for
114 * testing OMAP543X + TWL603X + TWL604X boards only.
115 */
116int twl603x_audio_power(u8 on)
117{
118 u8 cval = 0, vval = 0, c32k = 0;
119 int err;
120
121 if (on) {
122 vval = SMPS_VOLT_2V1;
123 cval = SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO;
124 c32k = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
125 }
126 /* Set SMPS9 to 2.1 V (for TWL604x), or to 0 (off) */
127 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_VOLTAGE, vval);
128 if (err) {
129 printf("twl603x: could not set SMPS9 voltage: err = %d\n",
130 err);
131 return err;
132 }
133 /* Turn on or off SMPS9 */
134 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_CTRL, cval);
135 if (err) {
136 printf("twl603x: could not turn SMPS9 %s: err = %d\n",
137 cval ? "on" : "off", err);
138 return err;
139 }
140 /* Output 32 kHz clock on or off */
141 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, CLK32KGAUDIO_CTRL, c32k);
142 if (err)
143 printf("twl603x: could not turn CLK32KGAUDIO %s: err = %d\n",
144 c32k ? "on" : "off", err);
145 return err;
146}
147#endif
148
Dan Murphy1bd435b2013-08-26 08:54:49 -0500149#ifdef CONFIG_PALMAS_USB_SS_PWR
150/**
151 * @brief palmas_enable_ss_ldo - Configure EVM board specific configurations
152 * for the USB Super speed SMPS10 regulator.
153 *
154 * @return 0
155 */
156int palmas_enable_ss_ldo(void)
157{
158 /* Enable smps10 regulator */
159 return palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS10_CTRL,
160 SMPS10_MODE_ACTIVE_D);
161}
162#endif
163
Lubomir Popove9090fa2013-06-06 04:16:40 +0000164/*
165 * Enable/disable back-up battery (or super cap) charging on TWL6035/37.
166 * Please use defined BB_xxx values.
167 */
168int twl603x_enable_bb_charge(u8 bb_fields)
169{
170 u8 val = bb_fields & 0x0f;
171 int err;
172
173 val |= (VRTC_EN_SLP | VRTC_EN_OFF | VRTC_PWEN);
174 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, BB_VRTC_CTRL, val);
175 if (err)
176 printf("twl603x: could not set BB_VRTC_CTRL to 0x%02x: err = %d\n",
177 val, err);
178 return err;
Balaji T Kdd23e592012-03-12 02:25:49 +0000179}