blob: c7b0cbe8b598d8c750b62db10da91e04002bc901 [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
Nishanth Menon384bcae2013-03-26 05:20:56 +000026int palmas_mmc1_poweron_ldo(void)
Balaji T Kdd23e592012-03-12 02:25:49 +000027{
28 u8 val = 0;
29
Lubomir Popove9090fa2013-06-06 04:16:40 +000030#if defined(CONFIG_DRA7XX)
31 /*
32 * Currently valid for the dra7xx_evm board:
33 * Set TPS659038 LDO1 to 3.0 V
34 */
35 val = LDO_VOLT_3V0;
36 if (palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_VOLTAGE, val)) {
37 printf("tps65903x: could not set LDO1 voltage.\n");
Vincent Stehléce851c82012-12-03 05:23:17 +000038 return 1;
39 }
Lubomir Popove9090fa2013-06-06 04:16:40 +000040 /* TURN ON LDO1 */
41 val = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
42 if (palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_CTRL, val)) {
43 printf("tps65903x: could not turn on LDO1.\n");
Vincent Stehléce851c82012-12-03 05:23:17 +000044 return 1;
45 }
Vincent Stehléce851c82012-12-03 05:23:17 +000046 return 0;
Lubomir Popove9090fa2013-06-06 04:16:40 +000047#else
48 /*
49 * We assume that this is a OMAP543X + TWL603X board:
50 * Set TWL6035/37 LDO9 to 3.0 V
51 */
52 val = LDO_VOLT_3V0;
53 return twl603x_mmc1_set_ldo9(val);
54#endif
55}
56
57/*
58 * On some OMAP5 + TWL603X hardware the SD card socket and LDO9_IN are
59 * powered by an external 3.3 V regulator, while the output of LDO9
60 * supplies VDDS_SDCARD for the OMAP5 interface only. This implies that
61 * LDO9 could be set to 'bypass' mode when required (e.g. for 3.3 V cards).
62 */
63int twl603x_mmc1_set_ldo9(u8 vsel)
64{
65 u8 cval = 0, vval = 0; /* Off by default */
66 int err;
67
68 if (vsel) {
69 /* Turn on */
70 if (vsel > LDO_VOLT_3V3) {
71 /* Put LDO9 in bypass */
72 cval = LDO9_BYP_EN | RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
73 vval = LDO_VOLT_3V3;
74 } else {
75 cval = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
76 vval = vsel & 0x3f;
77 }
78 }
79 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_VOLTAGE, vval);
80 if (err) {
81 printf("twl603x: could not set LDO9 %s: err = %d\n",
82 vsel > LDO_VOLT_3V3 ? "bypass" : "voltage", err);
83 return err;
84 }
85 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_CTRL, cval);
86 if (err)
87 printf("twl603x: could not turn %s LDO9: err = %d\n",
88 cval ? "on" : "off", err);
89 return err;
90}
91
92#ifdef CONFIG_PALMAS_AUDPWR
93/*
94 * Turn audio codec power and 32 kHz clock on/off. Use for
95 * testing OMAP543X + TWL603X + TWL604X boards only.
96 */
97int twl603x_audio_power(u8 on)
98{
99 u8 cval = 0, vval = 0, c32k = 0;
100 int err;
101
102 if (on) {
103 vval = SMPS_VOLT_2V1;
104 cval = SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO;
105 c32k = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
106 }
107 /* Set SMPS9 to 2.1 V (for TWL604x), or to 0 (off) */
108 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_VOLTAGE, vval);
109 if (err) {
110 printf("twl603x: could not set SMPS9 voltage: err = %d\n",
111 err);
112 return err;
113 }
114 /* Turn on or off SMPS9 */
115 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_CTRL, cval);
116 if (err) {
117 printf("twl603x: could not turn SMPS9 %s: err = %d\n",
118 cval ? "on" : "off", err);
119 return err;
120 }
121 /* Output 32 kHz clock on or off */
122 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, CLK32KGAUDIO_CTRL, c32k);
123 if (err)
124 printf("twl603x: could not turn CLK32KGAUDIO %s: err = %d\n",
125 c32k ? "on" : "off", err);
126 return err;
127}
128#endif
129
130/*
131 * Enable/disable back-up battery (or super cap) charging on TWL6035/37.
132 * Please use defined BB_xxx values.
133 */
134int twl603x_enable_bb_charge(u8 bb_fields)
135{
136 u8 val = bb_fields & 0x0f;
137 int err;
138
139 val |= (VRTC_EN_SLP | VRTC_EN_OFF | VRTC_PWEN);
140 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, BB_VRTC_CTRL, val);
141 if (err)
142 printf("twl603x: could not set BB_VRTC_CTRL to 0x%02x: err = %d\n",
143 val, err);
144 return err;
Balaji T Kdd23e592012-03-12 02:25:49 +0000145}