2 * Copyright (C) 2012 Samsung Electronics
3 * Alim Akhtar <alim.akhtar@samsung.com>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 /* Chip register numbers (not exported from this module) */
33 BBAT_BBCHOSTEN_MASK
= 1 << 0,
35 BBAT_BBCVS_MASK
= 3 << BBAT_BBCVS_SHIFT
,
39 * Max77686 parameters values
40 * see max77686.h for parameters details
42 struct max77686_para max77686_param
[] = {/*{regnum, vol_addr, vol_bitpos,
43 vol_bitmask, reg_enaddr, reg_enbitpos, reg_enbitmask, reg_enbiton,
44 reg_enbitoff, vol_min, vol_div}*/
45 {PMIC_BUCK1
, 0x11, 0x0, 0x3F, 0x10, 0x0, 0x3, 0x3, 0x0, 750, 50000},
46 {PMIC_BUCK2
, 0x14, 0x0, 0xFF, 0x12, 0x4, 0x3, 0x1, 0x0, 600, 12500},
47 {PMIC_BUCK3
, 0x1E, 0x0, 0xFF, 0x1C, 0x4, 0x3, 0x1, 0x0, 600, 12500},
48 {PMIC_BUCK4
, 0x28, 0x0, 0xFF, 0x26, 0x4, 0x3, 0x1, 0x0, 600, 12500},
49 {PMIC_BUCK5
, 0x31, 0x0, 0x3F, 0x30, 0x0, 0x3, 0x3, 0x0, 750, 50000},
50 {PMIC_BUCK6
, 0x33, 0x0, 0x3F, 0x32, 0x0, 0x3, 0x3, 0x0, 750, 50000},
51 {PMIC_BUCK7
, 0x35, 0x0, 0x3F, 0x34, 0x0, 0x3, 0x3, 0x0, 750, 50000},
52 {PMIC_BUCK8
, 0x37, 0x0, 0x3F, 0x36, 0x0, 0x3, 0x3, 0x0, 750, 50000},
53 {PMIC_BUCK9
, 0x39, 0x0, 0x3F, 0x38, 0x0, 0x3, 0x3, 0x0, 750, 50000},
54 {PMIC_LDO1
, 0x40, 0x0, 0x3F, 0x40, 0x6, 0x3, 0x3, 0x0, 800, 25000},
55 {PMIC_LDO2
, 0x41, 0x0, 0x3F, 0x41, 0x6, 0x3, 0x1, 0x0, 800, 25000},
56 {PMIC_LDO3
, 0x42, 0x0, 0x3F, 0x42, 0x6, 0x3, 0x3, 0x0, 800, 50000},
57 {PMIC_LDO4
, 0x43, 0x0, 0x3F, 0x43, 0x6, 0x3, 0x3, 0x0, 800, 50000},
58 {PMIC_LDO5
, 0x44, 0x0, 0x3F, 0x44, 0x6, 0x3, 0x3, 0x0, 800, 50000},
59 {PMIC_LDO6
, 0x45, 0x0, 0x3F, 0x45, 0x6, 0x3, 0x1, 0x0, 800, 25000},
60 {PMIC_LDO7
, 0x46, 0x0, 0x3F, 0x46, 0x6, 0x3, 0x1, 0x0, 800, 25000},
61 {PMIC_LDO8
, 0x47, 0x0, 0x3F, 0x47, 0x6, 0x3, 0x1, 0x0, 800, 25000},
62 {PMIC_LDO9
, 0x48, 0x0, 0x3F, 0x48, 0x6, 0x3, 0x3, 0x0, 800, 50000},
63 {PMIC_LDO10
, 0x49, 0x0, 0x3F, 0x49, 0x6, 0x3, 0x1, 0x0, 800, 50000},
64 {PMIC_LDO11
, 0x4A, 0x0, 0x3F, 0x4A, 0x6, 0x3, 0x1, 0x0, 800, 50000},
65 {PMIC_LDO12
, 0x4B, 0x0, 0x3F, 0x4B, 0x6, 0x3, 0x1, 0x0, 800, 50000},
66 {PMIC_LDO13
, 0x4C, 0x0, 0x3F, 0x4C, 0x6, 0x3, 0x3, 0x0, 800, 50000},
67 {PMIC_LDO14
, 0x4D, 0x0, 0x3F, 0x4D, 0x6, 0x3, 0x1, 0x0, 800, 50000},
68 {PMIC_LDO15
, 0x4E, 0x0, 0x3F, 0x4E, 0x6, 0x3, 0x1, 0x0, 800, 25000},
69 {PMIC_LDO16
, 0x4F, 0x0, 0x3F, 0x4F, 0x6, 0x3, 0x1, 0x0, 800, 50000},
70 {PMIC_LDO17
, 0x50, 0x0, 0x3F, 0x50, 0x6, 0x3, 0x3, 0x0, 800, 50000},
71 {PMIC_LDO18
, 0x51, 0x0, 0x3F, 0x51, 0x6, 0x3, 0x3, 0x0, 800, 50000},
72 {PMIC_LDO19
, 0x52, 0x0, 0x3F, 0x52, 0x6, 0x3, 0x3, 0x0, 800, 50000},
73 {PMIC_LDO20
, 0x53, 0x0, 0x3F, 0x53, 0x6, 0x3, 0x3, 0x0, 800, 50000},
74 {PMIC_LDO21
, 0x54, 0x0, 0x3F, 0x54, 0x6, 0x3, 0x3, 0x0, 800, 50000},
75 {PMIC_LDO22
, 0x55, 0x0, 0x3F, 0x55, 0x6, 0x3, 0x3, 0x0, 800, 50000},
76 {PMIC_LDO23
, 0x56, 0x0, 0x3F, 0x56, 0x6, 0x3, 0x3, 0x0, 800, 50000},
77 {PMIC_LDO24
, 0x57, 0x0, 0x3F, 0x57, 0x6, 0x3, 0x3, 0x0, 800, 50000},
78 {PMIC_LDO25
, 0x58, 0x0, 0x3F, 0x58, 0x6, 0x3, 0x3, 0x0, 800, 50000},
79 {PMIC_LDO26
, 0x59, 0x0, 0x3F, 0x59, 0x6, 0x3, 0x3, 0x0, 800, 50000},
80 {PMIC_EN32KHZ_CP
, 0x0, 0x0, 0x0, 0x7F, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0},
84 * Write a value to a register
86 * @param chip_addr i2c addr for max77686
87 * @param reg reg number to write
88 * @param val value to be written
91 static inline int max77686_i2c_write(unsigned char chip_addr
,
92 unsigned int reg
, unsigned char val
)
94 return i2c_write(chip_addr
, reg
, 1, &val
, 1);
98 * Read a value from a register
100 * @param chip_addr i2c addr for max77686
101 * @param reg reg number to write
102 * @param val value to be written
105 static inline int max77686_i2c_read(unsigned char chip_addr
,
106 unsigned int reg
, unsigned char *val
)
108 return i2c_read(chip_addr
, reg
, 1, val
, 1);
112 * Enable the max77686 register
114 * @param reg register number of buck/ldo to be enabled
115 * @param enable enable or disable bit
118 needed to set the buck/ldo enable bit OFF
119 * @return Return 0 if ok, else -1
121 static int max77686_enablereg(enum max77686_regnum reg
, int enable
)
123 struct max77686_para
*pmic
;
124 unsigned char read_data
;
127 pmic
= &max77686_param
[reg
];
129 ret
= max77686_i2c_read(MAX77686_I2C_ADDR
, pmic
->reg_enaddr
,
132 debug("max77686 i2c read failed.\n");
136 if (enable
== REG_DISABLE
) {
137 clrbits_8(&read_data
,
138 pmic
->reg_enbitmask
<< pmic
->reg_enbitpos
);
140 clrsetbits_8(&read_data
,
141 pmic
->reg_enbitmask
<< pmic
->reg_enbitpos
,
142 pmic
->reg_enbiton
<< pmic
->reg_enbitpos
);
145 ret
= max77686_i2c_write(MAX77686_I2C_ADDR
,
146 pmic
->reg_enaddr
, read_data
);
148 debug("max77686 i2c write failed.\n");
155 static int max77686_do_volsetting(enum max77686_regnum reg
, unsigned int volt
,
156 int enable
, int volt_units
)
158 struct max77686_para
*pmic
;
159 unsigned char read_data
;
163 pmic
= &max77686_param
[reg
];
165 if (pmic
->vol_addr
== 0) {
166 debug("not a voltage register.\n");
170 ret
= max77686_i2c_read(MAX77686_I2C_ADDR
, pmic
->vol_addr
, &read_data
);
172 debug("max77686 i2c read failed.\n");
176 if (volt_units
== MAX77686_UV
)
177 vol_level
= volt
- pmic
->vol_min
* 1000;
179 vol_level
= (volt
- pmic
->vol_min
) * 1000;
182 debug("Not a valid voltage level to set\n");
185 vol_level
/= pmic
->vol_div
;
187 clrsetbits_8(&read_data
, pmic
->vol_bitmask
<< pmic
->vol_bitpos
,
188 vol_level
<< pmic
->vol_bitpos
);
190 ret
= max77686_i2c_write(MAX77686_I2C_ADDR
, pmic
->vol_addr
, read_data
);
192 debug("max77686 i2c write failed.\n");
196 ret
= max77686_enablereg(reg
, enable
);
198 debug("Failed to enable buck/ldo.\n");
205 int max77686_volsetting(enum max77686_regnum reg
, unsigned int volt
,
206 int enable
, int volt_units
)
208 int old_bus
= i2c_get_bus_num();
212 ret
= max77686_do_volsetting(reg
, volt
, enable
, volt_units
);
213 i2c_set_bus_num(old_bus
);
217 int max77686_enable_32khz_cp(void)
220 return max77686_enablereg(PMIC_EN32KHZ_CP
, REG_ENABLE
);
223 int max77686_disable_backup_batt(void)
229 ret
= max77686_i2c_read(MAX77686_I2C_ADDR
, REG_BBAT
, &val
);
231 debug("max77686 i2c read failed\n");
235 /* If we already have the correct values, exit */
236 if ((val
& (BBAT_BBCVS_MASK
| BBAT_BBCHOSTEN_MASK
)) ==
240 /* First disable charging */
241 val
&= ~BBAT_BBCHOSTEN_MASK
;
242 ret
= max77686_i2c_write(MAX77686_I2C_ADDR
, REG_BBAT
, val
);
244 debug("max77686 i2c write failed\n");
248 /* Finally select 3.5V to minimize power consumption */
249 val
|= BBAT_BBCVS_MASK
;
250 ret
= max77686_i2c_write(MAX77686_I2C_ADDR
, REG_BBAT
, val
);
252 debug("max77686 i2c write failed\n");