xref: /OK3568_Linux_fs/kernel/drivers/mfd/tps65010.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * tps65010 - driver for tps6501x power management chips
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2004 Texas Instruments
6*4882a593Smuzhiyun  * Copyright (C) 2004-2005 David Brownell
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/kernel.h>
10*4882a593Smuzhiyun #include <linux/module.h>
11*4882a593Smuzhiyun #include <linux/init.h>
12*4882a593Smuzhiyun #include <linux/slab.h>
13*4882a593Smuzhiyun #include <linux/interrupt.h>
14*4882a593Smuzhiyun #include <linux/i2c.h>
15*4882a593Smuzhiyun #include <linux/delay.h>
16*4882a593Smuzhiyun #include <linux/workqueue.h>
17*4882a593Smuzhiyun #include <linux/debugfs.h>
18*4882a593Smuzhiyun #include <linux/seq_file.h>
19*4882a593Smuzhiyun #include <linux/mutex.h>
20*4882a593Smuzhiyun #include <linux/platform_device.h>
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #include <linux/mfd/tps65010.h>
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #include <linux/gpio/driver.h>
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #define	DRIVER_VERSION	"2 May 2005"
30*4882a593Smuzhiyun #define	DRIVER_NAME	(tps65010_driver.driver.name)
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun MODULE_DESCRIPTION("TPS6501x Power Management Driver");
33*4882a593Smuzhiyun MODULE_LICENSE("GPL");
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun static struct i2c_driver tps65010_driver;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /* This driver handles a family of multipurpose chips, which incorporate
40*4882a593Smuzhiyun  * voltage regulators, lithium ion/polymer battery charging, GPIOs, LEDs,
41*4882a593Smuzhiyun  * and other features often needed in portable devices like cell phones
42*4882a593Smuzhiyun  * or digital cameras.
43*4882a593Smuzhiyun  *
44*4882a593Smuzhiyun  * The tps65011 and tps65013 have different voltage settings compared
45*4882a593Smuzhiyun  * to tps65010 and tps65012.  The tps65013 has a NO_CHG status/irq.
46*4882a593Smuzhiyun  * All except tps65010 have "wait" mode, possibly defaulted so that
47*4882a593Smuzhiyun  * battery-insert != device-on.
48*4882a593Smuzhiyun  *
49*4882a593Smuzhiyun  * We could distinguish between some models by checking VDCDC1.UVLO or
50*4882a593Smuzhiyun  * other registers, unless they've been changed already after powerup
51*4882a593Smuzhiyun  * as part of board setup by a bootloader.
52*4882a593Smuzhiyun  */
53*4882a593Smuzhiyun enum tps_model {
54*4882a593Smuzhiyun 	TPS65010,
55*4882a593Smuzhiyun 	TPS65011,
56*4882a593Smuzhiyun 	TPS65012,
57*4882a593Smuzhiyun 	TPS65013,
58*4882a593Smuzhiyun };
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun struct tps65010 {
61*4882a593Smuzhiyun 	struct i2c_client	*client;
62*4882a593Smuzhiyun 	struct mutex		lock;
63*4882a593Smuzhiyun 	struct delayed_work	work;
64*4882a593Smuzhiyun 	struct dentry		*file;
65*4882a593Smuzhiyun 	unsigned		charging:1;
66*4882a593Smuzhiyun 	unsigned		por:1;
67*4882a593Smuzhiyun 	unsigned		model:8;
68*4882a593Smuzhiyun 	u16			vbus;
69*4882a593Smuzhiyun 	unsigned long		flags;
70*4882a593Smuzhiyun #define	FLAG_VBUS_CHANGED	0
71*4882a593Smuzhiyun #define	FLAG_IRQ_ENABLE		1
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun 	/* copies of last register state */
74*4882a593Smuzhiyun 	u8			chgstatus, regstatus, chgconf;
75*4882a593Smuzhiyun 	u8			nmask1, nmask2;
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	u8			outmask;
78*4882a593Smuzhiyun 	struct gpio_chip	chip;
79*4882a593Smuzhiyun 	struct platform_device	*leds;
80*4882a593Smuzhiyun };
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun #define	POWER_POLL_DELAY	msecs_to_jiffies(5000)
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun #if	defined(DEBUG) || defined(CONFIG_DEBUG_FS)
87*4882a593Smuzhiyun 
dbg_chgstat(char * buf,size_t len,u8 chgstatus)88*4882a593Smuzhiyun static void dbg_chgstat(char *buf, size_t len, u8 chgstatus)
89*4882a593Smuzhiyun {
90*4882a593Smuzhiyun 	snprintf(buf, len, "%02x%s%s%s%s%s%s%s%s\n",
91*4882a593Smuzhiyun 		chgstatus,
92*4882a593Smuzhiyun 		(chgstatus & TPS_CHG_USB) ? " USB" : "",
93*4882a593Smuzhiyun 		(chgstatus & TPS_CHG_AC) ? " AC" : "",
94*4882a593Smuzhiyun 		(chgstatus & TPS_CHG_THERM) ? " therm" : "",
95*4882a593Smuzhiyun 		(chgstatus & TPS_CHG_TERM) ? " done" :
96*4882a593Smuzhiyun 			((chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
97*4882a593Smuzhiyun 				? " (charging)" : ""),
98*4882a593Smuzhiyun 		(chgstatus & TPS_CHG_TAPER_TMO) ? " taper_tmo" : "",
99*4882a593Smuzhiyun 		(chgstatus & TPS_CHG_CHG_TMO) ? " charge_tmo" : "",
100*4882a593Smuzhiyun 		(chgstatus & TPS_CHG_PRECHG_TMO) ? " prechg_tmo" : "",
101*4882a593Smuzhiyun 		(chgstatus & TPS_CHG_TEMP_ERR) ? " temp_err" : "");
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun 
dbg_regstat(char * buf,size_t len,u8 regstatus)104*4882a593Smuzhiyun static void dbg_regstat(char *buf, size_t len, u8 regstatus)
105*4882a593Smuzhiyun {
106*4882a593Smuzhiyun 	snprintf(buf, len, "%02x %s%s%s%s%s%s%s%s\n",
107*4882a593Smuzhiyun 		regstatus,
108*4882a593Smuzhiyun 		(regstatus & TPS_REG_ONOFF) ? "off" : "(on)",
109*4882a593Smuzhiyun 		(regstatus & TPS_REG_COVER) ? " uncover" : "",
110*4882a593Smuzhiyun 		(regstatus & TPS_REG_UVLO) ? " UVLO" : "",
111*4882a593Smuzhiyun 		(regstatus & TPS_REG_NO_CHG) ? " NO_CHG" : "",
112*4882a593Smuzhiyun 		(regstatus & TPS_REG_PG_LD02) ? " ld02_bad" : "",
113*4882a593Smuzhiyun 		(regstatus & TPS_REG_PG_LD01) ? " ld01_bad" : "",
114*4882a593Smuzhiyun 		(regstatus & TPS_REG_PG_MAIN) ? " main_bad" : "",
115*4882a593Smuzhiyun 		(regstatus & TPS_REG_PG_CORE) ? " core_bad" : "");
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun 
dbg_chgconf(int por,char * buf,size_t len,u8 chgconfig)118*4882a593Smuzhiyun static void dbg_chgconf(int por, char *buf, size_t len, u8 chgconfig)
119*4882a593Smuzhiyun {
120*4882a593Smuzhiyun 	const char *hibit;
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 	if (por)
123*4882a593Smuzhiyun 		hibit = (chgconfig & TPS_CHARGE_POR)
124*4882a593Smuzhiyun 				? "POR=69ms" : "POR=1sec";
125*4882a593Smuzhiyun 	else
126*4882a593Smuzhiyun 		hibit = (chgconfig & TPS65013_AUA) ? "AUA" : "";
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	snprintf(buf, len, "%02x %s%s%s AC=%d%% USB=%dmA %sCharge\n",
129*4882a593Smuzhiyun 		chgconfig, hibit,
130*4882a593Smuzhiyun 		(chgconfig & TPS_CHARGE_RESET) ? " reset" : "",
131*4882a593Smuzhiyun 		(chgconfig & TPS_CHARGE_FAST) ? " fast" : "",
132*4882a593Smuzhiyun 		({int p; switch ((chgconfig >> 3) & 3) {
133*4882a593Smuzhiyun 		case 3:		p = 100; break;
134*4882a593Smuzhiyun 		case 2:		p = 75; break;
135*4882a593Smuzhiyun 		case 1:		p = 50; break;
136*4882a593Smuzhiyun 		default:	p = 25; break;
137*4882a593Smuzhiyun 		}; p; }),
138*4882a593Smuzhiyun 		(chgconfig & TPS_VBUS_CHARGING)
139*4882a593Smuzhiyun 			? ((chgconfig & TPS_VBUS_500MA) ? 500 : 100)
140*4882a593Smuzhiyun 			: 0,
141*4882a593Smuzhiyun 		(chgconfig & TPS_CHARGE_ENABLE) ? "" : "No");
142*4882a593Smuzhiyun }
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun #endif
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun #ifdef	DEBUG
147*4882a593Smuzhiyun 
show_chgstatus(const char * label,u8 chgstatus)148*4882a593Smuzhiyun static void show_chgstatus(const char *label, u8 chgstatus)
149*4882a593Smuzhiyun {
150*4882a593Smuzhiyun 	char buf [100];
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	dbg_chgstat(buf, sizeof buf, chgstatus);
153*4882a593Smuzhiyun 	pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
154*4882a593Smuzhiyun }
155*4882a593Smuzhiyun 
show_regstatus(const char * label,u8 regstatus)156*4882a593Smuzhiyun static void show_regstatus(const char *label, u8 regstatus)
157*4882a593Smuzhiyun {
158*4882a593Smuzhiyun 	char buf [100];
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun 	dbg_regstat(buf, sizeof buf, regstatus);
161*4882a593Smuzhiyun 	pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun 
show_chgconfig(int por,const char * label,u8 chgconfig)164*4882a593Smuzhiyun static void show_chgconfig(int por, const char *label, u8 chgconfig)
165*4882a593Smuzhiyun {
166*4882a593Smuzhiyun 	char buf [100];
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun 	dbg_chgconf(por, buf, sizeof buf, chgconfig);
169*4882a593Smuzhiyun 	pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
170*4882a593Smuzhiyun }
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun #else
173*4882a593Smuzhiyun 
show_chgstatus(const char * label,u8 chgstatus)174*4882a593Smuzhiyun static inline void show_chgstatus(const char *label, u8 chgstatus) { }
show_regstatus(const char * label,u8 chgstatus)175*4882a593Smuzhiyun static inline void show_regstatus(const char *label, u8 chgstatus) { }
show_chgconfig(int por,const char * label,u8 chgconfig)176*4882a593Smuzhiyun static inline void show_chgconfig(int por, const char *label, u8 chgconfig) { }
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun #endif
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun #ifdef	CONFIG_DEBUG_FS
181*4882a593Smuzhiyun 
dbg_show(struct seq_file * s,void * _)182*4882a593Smuzhiyun static int dbg_show(struct seq_file *s, void *_)
183*4882a593Smuzhiyun {
184*4882a593Smuzhiyun 	struct tps65010	*tps = s->private;
185*4882a593Smuzhiyun 	u8		value, v2;
186*4882a593Smuzhiyun 	unsigned	i;
187*4882a593Smuzhiyun 	char		buf[100];
188*4882a593Smuzhiyun 	const char	*chip;
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun 	switch (tps->model) {
191*4882a593Smuzhiyun 	case TPS65010:	chip = "tps65010"; break;
192*4882a593Smuzhiyun 	case TPS65011:	chip = "tps65011"; break;
193*4882a593Smuzhiyun 	case TPS65012:	chip = "tps65012"; break;
194*4882a593Smuzhiyun 	case TPS65013:	chip = "tps65013"; break;
195*4882a593Smuzhiyun 	default:	chip = NULL; break;
196*4882a593Smuzhiyun 	}
197*4882a593Smuzhiyun 	seq_printf(s, "driver  %s\nversion %s\nchip    %s\n\n",
198*4882a593Smuzhiyun 			DRIVER_NAME, DRIVER_VERSION, chip);
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun 	mutex_lock(&tps->lock);
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun 	/* FIXME how can we tell whether a battery is present?
203*4882a593Smuzhiyun 	 * likely involves a charge gauging chip (like BQ26501).
204*4882a593Smuzhiyun 	 */
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun 	seq_printf(s, "%scharging\n\n", tps->charging ? "" : "(not) ");
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 	/* registers for monitoring battery charging and status; note
210*4882a593Smuzhiyun 	 * that reading chgstat and regstat may ack IRQs...
211*4882a593Smuzhiyun 	 */
212*4882a593Smuzhiyun 	value = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG);
213*4882a593Smuzhiyun 	dbg_chgconf(tps->por, buf, sizeof buf, value);
214*4882a593Smuzhiyun 	seq_printf(s, "chgconfig %s", buf);
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun 	value = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS);
217*4882a593Smuzhiyun 	dbg_chgstat(buf, sizeof buf, value);
218*4882a593Smuzhiyun 	seq_printf(s, "chgstat   %s", buf);
219*4882a593Smuzhiyun 	value = i2c_smbus_read_byte_data(tps->client, TPS_MASK1);
220*4882a593Smuzhiyun 	dbg_chgstat(buf, sizeof buf, value);
221*4882a593Smuzhiyun 	seq_printf(s, "mask1     %s", buf);
222*4882a593Smuzhiyun 	/* ignore ackint1 */
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun 	value = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS);
225*4882a593Smuzhiyun 	dbg_regstat(buf, sizeof buf, value);
226*4882a593Smuzhiyun 	seq_printf(s, "regstat   %s", buf);
227*4882a593Smuzhiyun 	value = i2c_smbus_read_byte_data(tps->client, TPS_MASK2);
228*4882a593Smuzhiyun 	dbg_regstat(buf, sizeof buf, value);
229*4882a593Smuzhiyun 	seq_printf(s, "mask2     %s\n", buf);
230*4882a593Smuzhiyun 	/* ignore ackint2 */
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 	queue_delayed_work(system_power_efficient_wq, &tps->work,
233*4882a593Smuzhiyun 			   POWER_POLL_DELAY);
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 	/* VMAIN voltage, enable lowpower, etc */
236*4882a593Smuzhiyun 	value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC1);
237*4882a593Smuzhiyun 	seq_printf(s, "vdcdc1    %02x\n", value);
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun 	/* VCORE voltage, vibrator on/off */
240*4882a593Smuzhiyun 	value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC2);
241*4882a593Smuzhiyun 	seq_printf(s, "vdcdc2    %02x\n", value);
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun 	/* both LD0s, and their lowpower behavior */
244*4882a593Smuzhiyun 	value = i2c_smbus_read_byte_data(tps->client, TPS_VREGS1);
245*4882a593Smuzhiyun 	seq_printf(s, "vregs1    %02x\n\n", value);
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun 	/* LEDs and GPIOs */
249*4882a593Smuzhiyun 	value = i2c_smbus_read_byte_data(tps->client, TPS_LED1_ON);
250*4882a593Smuzhiyun 	v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED1_PER);
251*4882a593Smuzhiyun 	seq_printf(s, "led1 %s, on=%02x, per=%02x, %d/%d msec\n",
252*4882a593Smuzhiyun 		(value & 0x80)
253*4882a593Smuzhiyun 			? ((v2 & 0x80) ? "on" : "off")
254*4882a593Smuzhiyun 			: ((v2 & 0x80) ? "blink" : "(nPG)"),
255*4882a593Smuzhiyun 		value, v2,
256*4882a593Smuzhiyun 		(value & 0x7f) * 10, (v2 & 0x7f) * 100);
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun 	value = i2c_smbus_read_byte_data(tps->client, TPS_LED2_ON);
259*4882a593Smuzhiyun 	v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED2_PER);
260*4882a593Smuzhiyun 	seq_printf(s, "led2 %s, on=%02x, per=%02x, %d/%d msec\n",
261*4882a593Smuzhiyun 		(value & 0x80)
262*4882a593Smuzhiyun 			? ((v2 & 0x80) ? "on" : "off")
263*4882a593Smuzhiyun 			: ((v2 & 0x80) ? "blink" : "off"),
264*4882a593Smuzhiyun 		value, v2,
265*4882a593Smuzhiyun 		(value & 0x7f) * 10, (v2 & 0x7f) * 100);
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun 	value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO);
268*4882a593Smuzhiyun 	v2 = i2c_smbus_read_byte_data(tps->client, TPS_MASK3);
269*4882a593Smuzhiyun 	seq_printf(s, "defgpio %02x mask3 %02x\n", value, v2);
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun 	for (i = 0; i < 4; i++) {
272*4882a593Smuzhiyun 		if (value & (1 << (4 + i)))
273*4882a593Smuzhiyun 			seq_printf(s, "  gpio%d-out %s\n", i + 1,
274*4882a593Smuzhiyun 				(value & (1 << i)) ? "low" : "hi ");
275*4882a593Smuzhiyun 		else
276*4882a593Smuzhiyun 			seq_printf(s, "  gpio%d-in  %s %s %s\n", i + 1,
277*4882a593Smuzhiyun 				(value & (1 << i)) ? "hi " : "low",
278*4882a593Smuzhiyun 				(v2 & (1 << i)) ? "no-irq" : "irq",
279*4882a593Smuzhiyun 				(v2 & (1 << (4 + i))) ? "rising" : "falling");
280*4882a593Smuzhiyun 	}
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun 	mutex_unlock(&tps->lock);
283*4882a593Smuzhiyun 	return 0;
284*4882a593Smuzhiyun }
285*4882a593Smuzhiyun 
dbg_tps_open(struct inode * inode,struct file * file)286*4882a593Smuzhiyun static int dbg_tps_open(struct inode *inode, struct file *file)
287*4882a593Smuzhiyun {
288*4882a593Smuzhiyun 	return single_open(file, dbg_show, inode->i_private);
289*4882a593Smuzhiyun }
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun static const struct file_operations debug_fops = {
292*4882a593Smuzhiyun 	.open		= dbg_tps_open,
293*4882a593Smuzhiyun 	.read		= seq_read,
294*4882a593Smuzhiyun 	.llseek		= seq_lseek,
295*4882a593Smuzhiyun 	.release	= single_release,
296*4882a593Smuzhiyun };
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun #define	DEBUG_FOPS	&debug_fops
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun #else
301*4882a593Smuzhiyun #define	DEBUG_FOPS	NULL
302*4882a593Smuzhiyun #endif
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun /* handle IRQS in a task context, so we can use I2C calls */
tps65010_interrupt(struct tps65010 * tps)307*4882a593Smuzhiyun static void tps65010_interrupt(struct tps65010 *tps)
308*4882a593Smuzhiyun {
309*4882a593Smuzhiyun 	u8 tmp = 0, mask, poll;
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun 	/* IRQs won't trigger for certain events, but we can get
312*4882a593Smuzhiyun 	 * others by polling (normally, with external power applied).
313*4882a593Smuzhiyun 	 */
314*4882a593Smuzhiyun 	poll = 0;
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun 	/* regstatus irqs */
317*4882a593Smuzhiyun 	if (tps->nmask2) {
318*4882a593Smuzhiyun 		tmp = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS);
319*4882a593Smuzhiyun 		mask = tmp ^ tps->regstatus;
320*4882a593Smuzhiyun 		tps->regstatus = tmp;
321*4882a593Smuzhiyun 		mask &= tps->nmask2;
322*4882a593Smuzhiyun 	} else
323*4882a593Smuzhiyun 		mask = 0;
324*4882a593Smuzhiyun 	if (mask) {
325*4882a593Smuzhiyun 		tps->regstatus =  tmp;
326*4882a593Smuzhiyun 		/* may need to shut something down ... */
327*4882a593Smuzhiyun 
328*4882a593Smuzhiyun 		/* "off" usually means deep sleep */
329*4882a593Smuzhiyun 		if (tmp & TPS_REG_ONOFF) {
330*4882a593Smuzhiyun 			pr_info("%s: power off button\n", DRIVER_NAME);
331*4882a593Smuzhiyun #if 0
332*4882a593Smuzhiyun 			/* REVISIT:  this might need its own workqueue
333*4882a593Smuzhiyun 			 * plus tweaks including deadlock avoidance ...
334*4882a593Smuzhiyun 			 * also needs to get error handling and probably
335*4882a593Smuzhiyun 			 * an #ifdef CONFIG_HIBERNATION
336*4882a593Smuzhiyun 			 */
337*4882a593Smuzhiyun 			hibernate();
338*4882a593Smuzhiyun #endif
339*4882a593Smuzhiyun 			poll = 1;
340*4882a593Smuzhiyun 		}
341*4882a593Smuzhiyun 	}
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun 	/* chgstatus irqs */
344*4882a593Smuzhiyun 	if (tps->nmask1) {
345*4882a593Smuzhiyun 		tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS);
346*4882a593Smuzhiyun 		mask = tmp ^ tps->chgstatus;
347*4882a593Smuzhiyun 		tps->chgstatus = tmp;
348*4882a593Smuzhiyun 		mask &= tps->nmask1;
349*4882a593Smuzhiyun 	} else
350*4882a593Smuzhiyun 		mask = 0;
351*4882a593Smuzhiyun 	if (mask) {
352*4882a593Smuzhiyun 		unsigned	charging = 0;
353*4882a593Smuzhiyun 
354*4882a593Smuzhiyun 		show_chgstatus("chg/irq", tmp);
355*4882a593Smuzhiyun 		if (tmp & (TPS_CHG_USB|TPS_CHG_AC))
356*4882a593Smuzhiyun 			show_chgconfig(tps->por, "conf", tps->chgconf);
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun 		/* Unless it was turned off or disabled, we charge any
359*4882a593Smuzhiyun 		 * battery whenever there's power available for it
360*4882a593Smuzhiyun 		 * and the charger hasn't been disabled.
361*4882a593Smuzhiyun 		 */
362*4882a593Smuzhiyun 		if (!(tps->chgstatus & ~(TPS_CHG_USB|TPS_CHG_AC))
363*4882a593Smuzhiyun 				&& (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
364*4882a593Smuzhiyun 				&& (tps->chgconf & TPS_CHARGE_ENABLE)
365*4882a593Smuzhiyun 				) {
366*4882a593Smuzhiyun 			if (tps->chgstatus & TPS_CHG_USB) {
367*4882a593Smuzhiyun 				/* VBUS options are readonly until reconnect */
368*4882a593Smuzhiyun 				if (mask & TPS_CHG_USB)
369*4882a593Smuzhiyun 					set_bit(FLAG_VBUS_CHANGED, &tps->flags);
370*4882a593Smuzhiyun 				charging = 1;
371*4882a593Smuzhiyun 			} else if (tps->chgstatus & TPS_CHG_AC)
372*4882a593Smuzhiyun 				charging = 1;
373*4882a593Smuzhiyun 		}
374*4882a593Smuzhiyun 		if (charging != tps->charging) {
375*4882a593Smuzhiyun 			tps->charging = charging;
376*4882a593Smuzhiyun 			pr_info("%s: battery %scharging\n",
377*4882a593Smuzhiyun 				DRIVER_NAME, charging ? "" :
378*4882a593Smuzhiyun 				((tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
379*4882a593Smuzhiyun 					? "NOT " : "dis"));
380*4882a593Smuzhiyun 		}
381*4882a593Smuzhiyun 	}
382*4882a593Smuzhiyun 
383*4882a593Smuzhiyun 	/* always poll to detect (a) power removal, without tps65013
384*4882a593Smuzhiyun 	 * NO_CHG IRQ; or (b) restart of charging after stop.
385*4882a593Smuzhiyun 	 */
386*4882a593Smuzhiyun 	if ((tps->model != TPS65013 || !tps->charging)
387*4882a593Smuzhiyun 			&& (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)))
388*4882a593Smuzhiyun 		poll = 1;
389*4882a593Smuzhiyun 	if (poll)
390*4882a593Smuzhiyun 		queue_delayed_work(system_power_efficient_wq, &tps->work,
391*4882a593Smuzhiyun 				   POWER_POLL_DELAY);
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun 	/* also potentially gpio-in rise or fall */
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun 
396*4882a593Smuzhiyun /* handle IRQs and polling using keventd for now */
tps65010_work(struct work_struct * work)397*4882a593Smuzhiyun static void tps65010_work(struct work_struct *work)
398*4882a593Smuzhiyun {
399*4882a593Smuzhiyun 	struct tps65010		*tps;
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun 	tps = container_of(to_delayed_work(work), struct tps65010, work);
402*4882a593Smuzhiyun 	mutex_lock(&tps->lock);
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun 	tps65010_interrupt(tps);
405*4882a593Smuzhiyun 
406*4882a593Smuzhiyun 	if (test_and_clear_bit(FLAG_VBUS_CHANGED, &tps->flags)) {
407*4882a593Smuzhiyun 		u8	chgconfig, tmp;
408*4882a593Smuzhiyun 
409*4882a593Smuzhiyun 		chgconfig = i2c_smbus_read_byte_data(tps->client,
410*4882a593Smuzhiyun 					TPS_CHGCONFIG);
411*4882a593Smuzhiyun 		chgconfig &= ~(TPS_VBUS_500MA | TPS_VBUS_CHARGING);
412*4882a593Smuzhiyun 		if (tps->vbus == 500)
413*4882a593Smuzhiyun 			chgconfig |= TPS_VBUS_500MA | TPS_VBUS_CHARGING;
414*4882a593Smuzhiyun 		else if (tps->vbus >= 100)
415*4882a593Smuzhiyun 			chgconfig |= TPS_VBUS_CHARGING;
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun 		i2c_smbus_write_byte_data(tps->client,
418*4882a593Smuzhiyun 					  TPS_CHGCONFIG, chgconfig);
419*4882a593Smuzhiyun 
420*4882a593Smuzhiyun 		/* vbus update fails unless VBUS is connected! */
421*4882a593Smuzhiyun 		tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG);
422*4882a593Smuzhiyun 		tps->chgconf = tmp;
423*4882a593Smuzhiyun 		show_chgconfig(tps->por, "update vbus", tmp);
424*4882a593Smuzhiyun 	}
425*4882a593Smuzhiyun 
426*4882a593Smuzhiyun 	if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags))
427*4882a593Smuzhiyun 		enable_irq(tps->client->irq);
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun 	mutex_unlock(&tps->lock);
430*4882a593Smuzhiyun }
431*4882a593Smuzhiyun 
tps65010_irq(int irq,void * _tps)432*4882a593Smuzhiyun static irqreturn_t tps65010_irq(int irq, void *_tps)
433*4882a593Smuzhiyun {
434*4882a593Smuzhiyun 	struct tps65010		*tps = _tps;
435*4882a593Smuzhiyun 
436*4882a593Smuzhiyun 	disable_irq_nosync(irq);
437*4882a593Smuzhiyun 	set_bit(FLAG_IRQ_ENABLE, &tps->flags);
438*4882a593Smuzhiyun 	queue_delayed_work(system_power_efficient_wq, &tps->work, 0);
439*4882a593Smuzhiyun 	return IRQ_HANDLED;
440*4882a593Smuzhiyun }
441*4882a593Smuzhiyun 
442*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
443*4882a593Smuzhiyun 
444*4882a593Smuzhiyun /* offsets 0..3 == GPIO1..GPIO4
445*4882a593Smuzhiyun  * offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes)
446*4882a593Smuzhiyun  * offset 6 == vibrator motor driver
447*4882a593Smuzhiyun  */
448*4882a593Smuzhiyun static void
tps65010_gpio_set(struct gpio_chip * chip,unsigned offset,int value)449*4882a593Smuzhiyun tps65010_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
450*4882a593Smuzhiyun {
451*4882a593Smuzhiyun 	if (offset < 4)
452*4882a593Smuzhiyun 		tps65010_set_gpio_out_value(offset + 1, value);
453*4882a593Smuzhiyun 	else if (offset < 6)
454*4882a593Smuzhiyun 		tps65010_set_led(offset - 3, value ? ON : OFF);
455*4882a593Smuzhiyun 	else
456*4882a593Smuzhiyun 		tps65010_set_vib(value);
457*4882a593Smuzhiyun }
458*4882a593Smuzhiyun 
459*4882a593Smuzhiyun static int
tps65010_output(struct gpio_chip * chip,unsigned offset,int value)460*4882a593Smuzhiyun tps65010_output(struct gpio_chip *chip, unsigned offset, int value)
461*4882a593Smuzhiyun {
462*4882a593Smuzhiyun 	/* GPIOs may be input-only */
463*4882a593Smuzhiyun 	if (offset < 4) {
464*4882a593Smuzhiyun 		struct tps65010		*tps;
465*4882a593Smuzhiyun 
466*4882a593Smuzhiyun 		tps = gpiochip_get_data(chip);
467*4882a593Smuzhiyun 		if (!(tps->outmask & (1 << offset)))
468*4882a593Smuzhiyun 			return -EINVAL;
469*4882a593Smuzhiyun 		tps65010_set_gpio_out_value(offset + 1, value);
470*4882a593Smuzhiyun 	} else if (offset < 6)
471*4882a593Smuzhiyun 		tps65010_set_led(offset - 3, value ? ON : OFF);
472*4882a593Smuzhiyun 	else
473*4882a593Smuzhiyun 		tps65010_set_vib(value);
474*4882a593Smuzhiyun 
475*4882a593Smuzhiyun 	return 0;
476*4882a593Smuzhiyun }
477*4882a593Smuzhiyun 
tps65010_gpio_get(struct gpio_chip * chip,unsigned offset)478*4882a593Smuzhiyun static int tps65010_gpio_get(struct gpio_chip *chip, unsigned offset)
479*4882a593Smuzhiyun {
480*4882a593Smuzhiyun 	int			value;
481*4882a593Smuzhiyun 	struct tps65010		*tps;
482*4882a593Smuzhiyun 
483*4882a593Smuzhiyun 	tps = gpiochip_get_data(chip);
484*4882a593Smuzhiyun 
485*4882a593Smuzhiyun 	if (offset < 4) {
486*4882a593Smuzhiyun 		value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO);
487*4882a593Smuzhiyun 		if (value < 0)
488*4882a593Smuzhiyun 			return value;
489*4882a593Smuzhiyun 		if (value & (1 << (offset + 4)))	/* output */
490*4882a593Smuzhiyun 			return !(value & (1 << offset));
491*4882a593Smuzhiyun 		else					/* input */
492*4882a593Smuzhiyun 			return !!(value & (1 << offset));
493*4882a593Smuzhiyun 	}
494*4882a593Smuzhiyun 
495*4882a593Smuzhiyun 	/* REVISIT we *could* report LED1/nPG and LED2 state ... */
496*4882a593Smuzhiyun 	return 0;
497*4882a593Smuzhiyun }
498*4882a593Smuzhiyun 
499*4882a593Smuzhiyun 
500*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
501*4882a593Smuzhiyun 
502*4882a593Smuzhiyun static struct tps65010 *the_tps;
503*4882a593Smuzhiyun 
tps65010_remove(struct i2c_client * client)504*4882a593Smuzhiyun static int tps65010_remove(struct i2c_client *client)
505*4882a593Smuzhiyun {
506*4882a593Smuzhiyun 	struct tps65010		*tps = i2c_get_clientdata(client);
507*4882a593Smuzhiyun 	struct tps65010_board	*board = dev_get_platdata(&client->dev);
508*4882a593Smuzhiyun 
509*4882a593Smuzhiyun 	if (board && board->teardown) {
510*4882a593Smuzhiyun 		int status = board->teardown(client, board->context);
511*4882a593Smuzhiyun 		if (status < 0)
512*4882a593Smuzhiyun 			dev_dbg(&client->dev, "board %s %s err %d\n",
513*4882a593Smuzhiyun 				"teardown", client->name, status);
514*4882a593Smuzhiyun 	}
515*4882a593Smuzhiyun 	if (client->irq > 0)
516*4882a593Smuzhiyun 		free_irq(client->irq, tps);
517*4882a593Smuzhiyun 	cancel_delayed_work_sync(&tps->work);
518*4882a593Smuzhiyun 	debugfs_remove(tps->file);
519*4882a593Smuzhiyun 	the_tps = NULL;
520*4882a593Smuzhiyun 	return 0;
521*4882a593Smuzhiyun }
522*4882a593Smuzhiyun 
tps65010_probe(struct i2c_client * client,const struct i2c_device_id * id)523*4882a593Smuzhiyun static int tps65010_probe(struct i2c_client *client,
524*4882a593Smuzhiyun 			  const struct i2c_device_id *id)
525*4882a593Smuzhiyun {
526*4882a593Smuzhiyun 	struct tps65010		*tps;
527*4882a593Smuzhiyun 	int			status;
528*4882a593Smuzhiyun 	struct tps65010_board	*board = dev_get_platdata(&client->dev);
529*4882a593Smuzhiyun 
530*4882a593Smuzhiyun 	if (the_tps) {
531*4882a593Smuzhiyun 		dev_dbg(&client->dev, "only one tps6501x chip allowed\n");
532*4882a593Smuzhiyun 		return -ENODEV;
533*4882a593Smuzhiyun 	}
534*4882a593Smuzhiyun 
535*4882a593Smuzhiyun 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
536*4882a593Smuzhiyun 		return -EINVAL;
537*4882a593Smuzhiyun 
538*4882a593Smuzhiyun 	tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
539*4882a593Smuzhiyun 	if (!tps)
540*4882a593Smuzhiyun 		return -ENOMEM;
541*4882a593Smuzhiyun 
542*4882a593Smuzhiyun 	mutex_init(&tps->lock);
543*4882a593Smuzhiyun 	INIT_DELAYED_WORK(&tps->work, tps65010_work);
544*4882a593Smuzhiyun 	tps->client = client;
545*4882a593Smuzhiyun 	tps->model = id->driver_data;
546*4882a593Smuzhiyun 
547*4882a593Smuzhiyun 	/* the IRQ is active low, but many gpio lines can't support that
548*4882a593Smuzhiyun 	 * so this driver uses falling-edge triggers instead.
549*4882a593Smuzhiyun 	 */
550*4882a593Smuzhiyun 	if (client->irq > 0) {
551*4882a593Smuzhiyun 		status = request_irq(client->irq, tps65010_irq,
552*4882a593Smuzhiyun 				     IRQF_TRIGGER_FALLING, DRIVER_NAME, tps);
553*4882a593Smuzhiyun 		if (status < 0) {
554*4882a593Smuzhiyun 			dev_dbg(&client->dev, "can't get IRQ %d, err %d\n",
555*4882a593Smuzhiyun 					client->irq, status);
556*4882a593Smuzhiyun 			return status;
557*4882a593Smuzhiyun 		}
558*4882a593Smuzhiyun 		/* annoying race here, ideally we'd have an option
559*4882a593Smuzhiyun 		 * to claim the irq now and enable it later.
560*4882a593Smuzhiyun 		 * FIXME genirq IRQF_NOAUTOEN now solves that ...
561*4882a593Smuzhiyun 		 */
562*4882a593Smuzhiyun 		disable_irq(client->irq);
563*4882a593Smuzhiyun 		set_bit(FLAG_IRQ_ENABLE, &tps->flags);
564*4882a593Smuzhiyun 	} else
565*4882a593Smuzhiyun 		dev_warn(&client->dev, "IRQ not configured!\n");
566*4882a593Smuzhiyun 
567*4882a593Smuzhiyun 
568*4882a593Smuzhiyun 	switch (tps->model) {
569*4882a593Smuzhiyun 	case TPS65010:
570*4882a593Smuzhiyun 	case TPS65012:
571*4882a593Smuzhiyun 		tps->por = 1;
572*4882a593Smuzhiyun 		break;
573*4882a593Smuzhiyun 	/* else CHGCONFIG.POR is replaced by AUA, enabling a WAIT mode */
574*4882a593Smuzhiyun 	}
575*4882a593Smuzhiyun 	tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG);
576*4882a593Smuzhiyun 	show_chgconfig(tps->por, "conf/init", tps->chgconf);
577*4882a593Smuzhiyun 
578*4882a593Smuzhiyun 	show_chgstatus("chg/init",
579*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(client, TPS_CHGSTATUS));
580*4882a593Smuzhiyun 	show_regstatus("reg/init",
581*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(client, TPS_REGSTATUS));
582*4882a593Smuzhiyun 
583*4882a593Smuzhiyun 	pr_debug("%s: vdcdc1 0x%02x, vdcdc2 %02x, vregs1 %02x\n", DRIVER_NAME,
584*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(client, TPS_VDCDC1),
585*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(client, TPS_VDCDC2),
586*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(client, TPS_VREGS1));
587*4882a593Smuzhiyun 	pr_debug("%s: defgpio 0x%02x, mask3 0x%02x\n", DRIVER_NAME,
588*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(client, TPS_DEFGPIO),
589*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(client, TPS_MASK3));
590*4882a593Smuzhiyun 
591*4882a593Smuzhiyun 	i2c_set_clientdata(client, tps);
592*4882a593Smuzhiyun 	the_tps = tps;
593*4882a593Smuzhiyun 
594*4882a593Smuzhiyun #if	defined(CONFIG_USB_GADGET) && !defined(CONFIG_USB_OTG)
595*4882a593Smuzhiyun 	/* USB hosts can't draw VBUS.  OTG devices could, later
596*4882a593Smuzhiyun 	 * when OTG infrastructure enables it.  USB peripherals
597*4882a593Smuzhiyun 	 * could be relying on VBUS while booting, though.
598*4882a593Smuzhiyun 	 */
599*4882a593Smuzhiyun 	tps->vbus = 100;
600*4882a593Smuzhiyun #endif
601*4882a593Smuzhiyun 
602*4882a593Smuzhiyun 	/* unmask the "interesting" irqs, then poll once to
603*4882a593Smuzhiyun 	 * kickstart monitoring, initialize shadowed status
604*4882a593Smuzhiyun 	 * registers, and maybe disable VBUS draw.
605*4882a593Smuzhiyun 	 */
606*4882a593Smuzhiyun 	tps->nmask1 = ~0;
607*4882a593Smuzhiyun 	(void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1);
608*4882a593Smuzhiyun 
609*4882a593Smuzhiyun 	tps->nmask2 = TPS_REG_ONOFF;
610*4882a593Smuzhiyun 	if (tps->model == TPS65013)
611*4882a593Smuzhiyun 		tps->nmask2 |= TPS_REG_NO_CHG;
612*4882a593Smuzhiyun 	(void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2);
613*4882a593Smuzhiyun 
614*4882a593Smuzhiyun 	(void) i2c_smbus_write_byte_data(client, TPS_MASK3, 0x0f
615*4882a593Smuzhiyun 		| i2c_smbus_read_byte_data(client, TPS_MASK3));
616*4882a593Smuzhiyun 
617*4882a593Smuzhiyun 	tps65010_work(&tps->work.work);
618*4882a593Smuzhiyun 
619*4882a593Smuzhiyun 	tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL,
620*4882a593Smuzhiyun 				tps, DEBUG_FOPS);
621*4882a593Smuzhiyun 
622*4882a593Smuzhiyun 	/* optionally register GPIOs */
623*4882a593Smuzhiyun 	if (board && board->base != 0) {
624*4882a593Smuzhiyun 		tps->outmask = board->outmask;
625*4882a593Smuzhiyun 
626*4882a593Smuzhiyun 		tps->chip.label = client->name;
627*4882a593Smuzhiyun 		tps->chip.parent = &client->dev;
628*4882a593Smuzhiyun 		tps->chip.owner = THIS_MODULE;
629*4882a593Smuzhiyun 
630*4882a593Smuzhiyun 		tps->chip.set = tps65010_gpio_set;
631*4882a593Smuzhiyun 		tps->chip.direction_output = tps65010_output;
632*4882a593Smuzhiyun 
633*4882a593Smuzhiyun 		/* NOTE:  only partial support for inputs; nyet IRQs */
634*4882a593Smuzhiyun 		tps->chip.get = tps65010_gpio_get;
635*4882a593Smuzhiyun 
636*4882a593Smuzhiyun 		tps->chip.base = board->base;
637*4882a593Smuzhiyun 		tps->chip.ngpio = 7;
638*4882a593Smuzhiyun 		tps->chip.can_sleep = 1;
639*4882a593Smuzhiyun 
640*4882a593Smuzhiyun 		status = gpiochip_add_data(&tps->chip, tps);
641*4882a593Smuzhiyun 		if (status < 0)
642*4882a593Smuzhiyun 			dev_err(&client->dev, "can't add gpiochip, err %d\n",
643*4882a593Smuzhiyun 					status);
644*4882a593Smuzhiyun 		else if (board->setup) {
645*4882a593Smuzhiyun 			status = board->setup(client, board->context);
646*4882a593Smuzhiyun 			if (status < 0) {
647*4882a593Smuzhiyun 				dev_dbg(&client->dev,
648*4882a593Smuzhiyun 					"board %s %s err %d\n",
649*4882a593Smuzhiyun 					"setup", client->name, status);
650*4882a593Smuzhiyun 				status = 0;
651*4882a593Smuzhiyun 			}
652*4882a593Smuzhiyun 		}
653*4882a593Smuzhiyun 	}
654*4882a593Smuzhiyun 
655*4882a593Smuzhiyun 	return 0;
656*4882a593Smuzhiyun }
657*4882a593Smuzhiyun 
658*4882a593Smuzhiyun static const struct i2c_device_id tps65010_id[] = {
659*4882a593Smuzhiyun 	{ "tps65010", TPS65010 },
660*4882a593Smuzhiyun 	{ "tps65011", TPS65011 },
661*4882a593Smuzhiyun 	{ "tps65012", TPS65012 },
662*4882a593Smuzhiyun 	{ "tps65013", TPS65013 },
663*4882a593Smuzhiyun 	{ "tps65014", TPS65011 },	/* tps65011 charging at 6.5V max */
664*4882a593Smuzhiyun 	{ }
665*4882a593Smuzhiyun };
666*4882a593Smuzhiyun MODULE_DEVICE_TABLE(i2c, tps65010_id);
667*4882a593Smuzhiyun 
668*4882a593Smuzhiyun static struct i2c_driver tps65010_driver = {
669*4882a593Smuzhiyun 	.driver = {
670*4882a593Smuzhiyun 		.name	= "tps65010",
671*4882a593Smuzhiyun 	},
672*4882a593Smuzhiyun 	.probe	= tps65010_probe,
673*4882a593Smuzhiyun 	.remove	= tps65010_remove,
674*4882a593Smuzhiyun 	.id_table = tps65010_id,
675*4882a593Smuzhiyun };
676*4882a593Smuzhiyun 
677*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
678*4882a593Smuzhiyun 
679*4882a593Smuzhiyun /* Draw from VBUS:
680*4882a593Smuzhiyun  *   0 mA -- DON'T DRAW (might supply power instead)
681*4882a593Smuzhiyun  * 100 mA -- usb unit load (slowest charge rate)
682*4882a593Smuzhiyun  * 500 mA -- usb high power (fast battery charge)
683*4882a593Smuzhiyun  */
tps65010_set_vbus_draw(unsigned mA)684*4882a593Smuzhiyun int tps65010_set_vbus_draw(unsigned mA)
685*4882a593Smuzhiyun {
686*4882a593Smuzhiyun 	unsigned long	flags;
687*4882a593Smuzhiyun 
688*4882a593Smuzhiyun 	if (!the_tps)
689*4882a593Smuzhiyun 		return -ENODEV;
690*4882a593Smuzhiyun 
691*4882a593Smuzhiyun 	/* assumes non-SMP */
692*4882a593Smuzhiyun 	local_irq_save(flags);
693*4882a593Smuzhiyun 	if (mA >= 500)
694*4882a593Smuzhiyun 		mA = 500;
695*4882a593Smuzhiyun 	else if (mA >= 100)
696*4882a593Smuzhiyun 		mA = 100;
697*4882a593Smuzhiyun 	else
698*4882a593Smuzhiyun 		mA = 0;
699*4882a593Smuzhiyun 	the_tps->vbus = mA;
700*4882a593Smuzhiyun 	if ((the_tps->chgstatus & TPS_CHG_USB)
701*4882a593Smuzhiyun 			&& test_and_set_bit(
702*4882a593Smuzhiyun 				FLAG_VBUS_CHANGED, &the_tps->flags)) {
703*4882a593Smuzhiyun 		/* gadget drivers call this in_irq() */
704*4882a593Smuzhiyun 		queue_delayed_work(system_power_efficient_wq, &the_tps->work,
705*4882a593Smuzhiyun 				   0);
706*4882a593Smuzhiyun 	}
707*4882a593Smuzhiyun 	local_irq_restore(flags);
708*4882a593Smuzhiyun 
709*4882a593Smuzhiyun 	return 0;
710*4882a593Smuzhiyun }
711*4882a593Smuzhiyun EXPORT_SYMBOL(tps65010_set_vbus_draw);
712*4882a593Smuzhiyun 
713*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
714*4882a593Smuzhiyun /* tps65010_set_gpio_out_value parameter:
715*4882a593Smuzhiyun  * gpio:  GPIO1, GPIO2, GPIO3 or GPIO4
716*4882a593Smuzhiyun  * value: LOW or HIGH
717*4882a593Smuzhiyun  */
tps65010_set_gpio_out_value(unsigned gpio,unsigned value)718*4882a593Smuzhiyun int tps65010_set_gpio_out_value(unsigned gpio, unsigned value)
719*4882a593Smuzhiyun {
720*4882a593Smuzhiyun 	int	 status;
721*4882a593Smuzhiyun 	unsigned defgpio;
722*4882a593Smuzhiyun 
723*4882a593Smuzhiyun 	if (!the_tps)
724*4882a593Smuzhiyun 		return -ENODEV;
725*4882a593Smuzhiyun 	if ((gpio < GPIO1) || (gpio > GPIO4))
726*4882a593Smuzhiyun 		return -EINVAL;
727*4882a593Smuzhiyun 
728*4882a593Smuzhiyun 	mutex_lock(&the_tps->lock);
729*4882a593Smuzhiyun 
730*4882a593Smuzhiyun 	defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO);
731*4882a593Smuzhiyun 
732*4882a593Smuzhiyun 	/* Configure GPIO for output */
733*4882a593Smuzhiyun 	defgpio |= 1 << (gpio + 3);
734*4882a593Smuzhiyun 
735*4882a593Smuzhiyun 	/* Writing 1 forces a logic 0 on that GPIO and vice versa */
736*4882a593Smuzhiyun 	switch (value) {
737*4882a593Smuzhiyun 	case LOW:
738*4882a593Smuzhiyun 		defgpio |= 1 << (gpio - 1);    /* set GPIO low by writing 1 */
739*4882a593Smuzhiyun 		break;
740*4882a593Smuzhiyun 	/* case HIGH: */
741*4882a593Smuzhiyun 	default:
742*4882a593Smuzhiyun 		defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */
743*4882a593Smuzhiyun 		break;
744*4882a593Smuzhiyun 	}
745*4882a593Smuzhiyun 
746*4882a593Smuzhiyun 	status = i2c_smbus_write_byte_data(the_tps->client,
747*4882a593Smuzhiyun 		TPS_DEFGPIO, defgpio);
748*4882a593Smuzhiyun 
749*4882a593Smuzhiyun 	pr_debug("%s: gpio%dout = %s, defgpio 0x%02x\n", DRIVER_NAME,
750*4882a593Smuzhiyun 		gpio, value ? "high" : "low",
751*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO));
752*4882a593Smuzhiyun 
753*4882a593Smuzhiyun 	mutex_unlock(&the_tps->lock);
754*4882a593Smuzhiyun 	return status;
755*4882a593Smuzhiyun }
756*4882a593Smuzhiyun EXPORT_SYMBOL(tps65010_set_gpio_out_value);
757*4882a593Smuzhiyun 
758*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
759*4882a593Smuzhiyun /* tps65010_set_led parameter:
760*4882a593Smuzhiyun  * led:  LED1 or LED2
761*4882a593Smuzhiyun  * mode: ON, OFF or BLINK
762*4882a593Smuzhiyun  */
tps65010_set_led(unsigned led,unsigned mode)763*4882a593Smuzhiyun int tps65010_set_led(unsigned led, unsigned mode)
764*4882a593Smuzhiyun {
765*4882a593Smuzhiyun 	int	 status;
766*4882a593Smuzhiyun 	unsigned led_on, led_per, offs;
767*4882a593Smuzhiyun 
768*4882a593Smuzhiyun 	if (!the_tps)
769*4882a593Smuzhiyun 		return -ENODEV;
770*4882a593Smuzhiyun 
771*4882a593Smuzhiyun 	if (led == LED1)
772*4882a593Smuzhiyun 		offs = 0;
773*4882a593Smuzhiyun 	else {
774*4882a593Smuzhiyun 		offs = 2;
775*4882a593Smuzhiyun 		led = LED2;
776*4882a593Smuzhiyun 	}
777*4882a593Smuzhiyun 
778*4882a593Smuzhiyun 	mutex_lock(&the_tps->lock);
779*4882a593Smuzhiyun 
780*4882a593Smuzhiyun 	pr_debug("%s: led%i_on   0x%02x\n", DRIVER_NAME, led,
781*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(the_tps->client,
782*4882a593Smuzhiyun 				TPS_LED1_ON + offs));
783*4882a593Smuzhiyun 
784*4882a593Smuzhiyun 	pr_debug("%s: led%i_per  0x%02x\n", DRIVER_NAME, led,
785*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(the_tps->client,
786*4882a593Smuzhiyun 				TPS_LED1_PER + offs));
787*4882a593Smuzhiyun 
788*4882a593Smuzhiyun 	switch (mode) {
789*4882a593Smuzhiyun 	case OFF:
790*4882a593Smuzhiyun 		led_on  = 1 << 7;
791*4882a593Smuzhiyun 		led_per = 0 << 7;
792*4882a593Smuzhiyun 		break;
793*4882a593Smuzhiyun 	case ON:
794*4882a593Smuzhiyun 		led_on  = 1 << 7;
795*4882a593Smuzhiyun 		led_per = 1 << 7;
796*4882a593Smuzhiyun 		break;
797*4882a593Smuzhiyun 	case BLINK:
798*4882a593Smuzhiyun 		led_on  = 0x30 | (0 << 7);
799*4882a593Smuzhiyun 		led_per = 0x08 | (1 << 7);
800*4882a593Smuzhiyun 		break;
801*4882a593Smuzhiyun 	default:
802*4882a593Smuzhiyun 		printk(KERN_ERR "%s: Wrong mode parameter for set_led()\n",
803*4882a593Smuzhiyun 		       DRIVER_NAME);
804*4882a593Smuzhiyun 		mutex_unlock(&the_tps->lock);
805*4882a593Smuzhiyun 		return -EINVAL;
806*4882a593Smuzhiyun 	}
807*4882a593Smuzhiyun 
808*4882a593Smuzhiyun 	status = i2c_smbus_write_byte_data(the_tps->client,
809*4882a593Smuzhiyun 			TPS_LED1_ON + offs, led_on);
810*4882a593Smuzhiyun 
811*4882a593Smuzhiyun 	if (status != 0) {
812*4882a593Smuzhiyun 		printk(KERN_ERR "%s: Failed to write led%i_on register\n",
813*4882a593Smuzhiyun 		       DRIVER_NAME, led);
814*4882a593Smuzhiyun 		mutex_unlock(&the_tps->lock);
815*4882a593Smuzhiyun 		return status;
816*4882a593Smuzhiyun 	}
817*4882a593Smuzhiyun 
818*4882a593Smuzhiyun 	pr_debug("%s: led%i_on   0x%02x\n", DRIVER_NAME, led,
819*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs));
820*4882a593Smuzhiyun 
821*4882a593Smuzhiyun 	status = i2c_smbus_write_byte_data(the_tps->client,
822*4882a593Smuzhiyun 			TPS_LED1_PER + offs, led_per);
823*4882a593Smuzhiyun 
824*4882a593Smuzhiyun 	if (status != 0) {
825*4882a593Smuzhiyun 		printk(KERN_ERR "%s: Failed to write led%i_per register\n",
826*4882a593Smuzhiyun 		       DRIVER_NAME, led);
827*4882a593Smuzhiyun 		mutex_unlock(&the_tps->lock);
828*4882a593Smuzhiyun 		return status;
829*4882a593Smuzhiyun 	}
830*4882a593Smuzhiyun 
831*4882a593Smuzhiyun 	pr_debug("%s: led%i_per  0x%02x\n", DRIVER_NAME, led,
832*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(the_tps->client,
833*4882a593Smuzhiyun 				TPS_LED1_PER + offs));
834*4882a593Smuzhiyun 
835*4882a593Smuzhiyun 	mutex_unlock(&the_tps->lock);
836*4882a593Smuzhiyun 
837*4882a593Smuzhiyun 	return status;
838*4882a593Smuzhiyun }
839*4882a593Smuzhiyun EXPORT_SYMBOL(tps65010_set_led);
840*4882a593Smuzhiyun 
841*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
842*4882a593Smuzhiyun /* tps65010_set_vib parameter:
843*4882a593Smuzhiyun  * value: ON or OFF
844*4882a593Smuzhiyun  */
tps65010_set_vib(unsigned value)845*4882a593Smuzhiyun int tps65010_set_vib(unsigned value)
846*4882a593Smuzhiyun {
847*4882a593Smuzhiyun 	int	 status;
848*4882a593Smuzhiyun 	unsigned vdcdc2;
849*4882a593Smuzhiyun 
850*4882a593Smuzhiyun 	if (!the_tps)
851*4882a593Smuzhiyun 		return -ENODEV;
852*4882a593Smuzhiyun 
853*4882a593Smuzhiyun 	mutex_lock(&the_tps->lock);
854*4882a593Smuzhiyun 
855*4882a593Smuzhiyun 	vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2);
856*4882a593Smuzhiyun 	vdcdc2 &= ~(1 << 1);
857*4882a593Smuzhiyun 	if (value)
858*4882a593Smuzhiyun 		vdcdc2 |= (1 << 1);
859*4882a593Smuzhiyun 	status = i2c_smbus_write_byte_data(the_tps->client,
860*4882a593Smuzhiyun 		TPS_VDCDC2, vdcdc2);
861*4882a593Smuzhiyun 
862*4882a593Smuzhiyun 	pr_debug("%s: vibrator %s\n", DRIVER_NAME, value ? "on" : "off");
863*4882a593Smuzhiyun 
864*4882a593Smuzhiyun 	mutex_unlock(&the_tps->lock);
865*4882a593Smuzhiyun 	return status;
866*4882a593Smuzhiyun }
867*4882a593Smuzhiyun EXPORT_SYMBOL(tps65010_set_vib);
868*4882a593Smuzhiyun 
869*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
870*4882a593Smuzhiyun /* tps65010_set_low_pwr parameter:
871*4882a593Smuzhiyun  * mode: ON or OFF
872*4882a593Smuzhiyun  */
tps65010_set_low_pwr(unsigned mode)873*4882a593Smuzhiyun int tps65010_set_low_pwr(unsigned mode)
874*4882a593Smuzhiyun {
875*4882a593Smuzhiyun 	int	 status;
876*4882a593Smuzhiyun 	unsigned vdcdc1;
877*4882a593Smuzhiyun 
878*4882a593Smuzhiyun 	if (!the_tps)
879*4882a593Smuzhiyun 		return -ENODEV;
880*4882a593Smuzhiyun 
881*4882a593Smuzhiyun 	mutex_lock(&the_tps->lock);
882*4882a593Smuzhiyun 
883*4882a593Smuzhiyun 	pr_debug("%s: %s low_pwr, vdcdc1 0x%02x\n", DRIVER_NAME,
884*4882a593Smuzhiyun 		mode ? "enable" : "disable",
885*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
886*4882a593Smuzhiyun 
887*4882a593Smuzhiyun 	vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
888*4882a593Smuzhiyun 
889*4882a593Smuzhiyun 	switch (mode) {
890*4882a593Smuzhiyun 	case OFF:
891*4882a593Smuzhiyun 		vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */
892*4882a593Smuzhiyun 		break;
893*4882a593Smuzhiyun 	/* case ON: */
894*4882a593Smuzhiyun 	default:
895*4882a593Smuzhiyun 		vdcdc1 |= TPS_ENABLE_LP;  /* enable ENABLE_LP bit */
896*4882a593Smuzhiyun 		break;
897*4882a593Smuzhiyun 	}
898*4882a593Smuzhiyun 
899*4882a593Smuzhiyun 	status = i2c_smbus_write_byte_data(the_tps->client,
900*4882a593Smuzhiyun 			TPS_VDCDC1, vdcdc1);
901*4882a593Smuzhiyun 
902*4882a593Smuzhiyun 	if (status != 0)
903*4882a593Smuzhiyun 		printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
904*4882a593Smuzhiyun 			DRIVER_NAME);
905*4882a593Smuzhiyun 	else
906*4882a593Smuzhiyun 		pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
907*4882a593Smuzhiyun 			i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
908*4882a593Smuzhiyun 
909*4882a593Smuzhiyun 	mutex_unlock(&the_tps->lock);
910*4882a593Smuzhiyun 
911*4882a593Smuzhiyun 	return status;
912*4882a593Smuzhiyun }
913*4882a593Smuzhiyun EXPORT_SYMBOL(tps65010_set_low_pwr);
914*4882a593Smuzhiyun 
915*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
916*4882a593Smuzhiyun /* tps65010_config_vregs1 parameter:
917*4882a593Smuzhiyun  * value to be written to VREGS1 register
918*4882a593Smuzhiyun  * Note: The complete register is written, set all bits you need
919*4882a593Smuzhiyun  */
tps65010_config_vregs1(unsigned value)920*4882a593Smuzhiyun int tps65010_config_vregs1(unsigned value)
921*4882a593Smuzhiyun {
922*4882a593Smuzhiyun 	int	 status;
923*4882a593Smuzhiyun 
924*4882a593Smuzhiyun 	if (!the_tps)
925*4882a593Smuzhiyun 		return -ENODEV;
926*4882a593Smuzhiyun 
927*4882a593Smuzhiyun 	mutex_lock(&the_tps->lock);
928*4882a593Smuzhiyun 
929*4882a593Smuzhiyun 	pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
930*4882a593Smuzhiyun 			i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
931*4882a593Smuzhiyun 
932*4882a593Smuzhiyun 	status = i2c_smbus_write_byte_data(the_tps->client,
933*4882a593Smuzhiyun 			TPS_VREGS1, value);
934*4882a593Smuzhiyun 
935*4882a593Smuzhiyun 	if (status != 0)
936*4882a593Smuzhiyun 		printk(KERN_ERR "%s: Failed to write vregs1 register\n",
937*4882a593Smuzhiyun 			DRIVER_NAME);
938*4882a593Smuzhiyun 	else
939*4882a593Smuzhiyun 		pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
940*4882a593Smuzhiyun 			i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
941*4882a593Smuzhiyun 
942*4882a593Smuzhiyun 	mutex_unlock(&the_tps->lock);
943*4882a593Smuzhiyun 
944*4882a593Smuzhiyun 	return status;
945*4882a593Smuzhiyun }
946*4882a593Smuzhiyun EXPORT_SYMBOL(tps65010_config_vregs1);
947*4882a593Smuzhiyun 
tps65010_config_vdcdc2(unsigned value)948*4882a593Smuzhiyun int tps65010_config_vdcdc2(unsigned value)
949*4882a593Smuzhiyun {
950*4882a593Smuzhiyun 	struct i2c_client *c;
951*4882a593Smuzhiyun 	int	 status;
952*4882a593Smuzhiyun 
953*4882a593Smuzhiyun 	if (!the_tps)
954*4882a593Smuzhiyun 		return -ENODEV;
955*4882a593Smuzhiyun 
956*4882a593Smuzhiyun 	c = the_tps->client;
957*4882a593Smuzhiyun 	mutex_lock(&the_tps->lock);
958*4882a593Smuzhiyun 
959*4882a593Smuzhiyun 	pr_debug("%s: vdcdc2 0x%02x\n", DRIVER_NAME,
960*4882a593Smuzhiyun 		 i2c_smbus_read_byte_data(c, TPS_VDCDC2));
961*4882a593Smuzhiyun 
962*4882a593Smuzhiyun 	status = i2c_smbus_write_byte_data(c, TPS_VDCDC2, value);
963*4882a593Smuzhiyun 
964*4882a593Smuzhiyun 	if (status != 0)
965*4882a593Smuzhiyun 		printk(KERN_ERR "%s: Failed to write vdcdc2 register\n",
966*4882a593Smuzhiyun 			DRIVER_NAME);
967*4882a593Smuzhiyun 	else
968*4882a593Smuzhiyun 		pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
969*4882a593Smuzhiyun 			 i2c_smbus_read_byte_data(c, TPS_VDCDC2));
970*4882a593Smuzhiyun 
971*4882a593Smuzhiyun 	mutex_unlock(&the_tps->lock);
972*4882a593Smuzhiyun 	return status;
973*4882a593Smuzhiyun }
974*4882a593Smuzhiyun EXPORT_SYMBOL(tps65010_config_vdcdc2);
975*4882a593Smuzhiyun 
976*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
977*4882a593Smuzhiyun /* tps65013_set_low_pwr parameter:
978*4882a593Smuzhiyun  * mode: ON or OFF
979*4882a593Smuzhiyun  */
980*4882a593Smuzhiyun 
981*4882a593Smuzhiyun /* FIXME: Assumes AC or USB power is present. Setting AUA bit is not
982*4882a593Smuzhiyun 	required if power supply is through a battery */
983*4882a593Smuzhiyun 
tps65013_set_low_pwr(unsigned mode)984*4882a593Smuzhiyun int tps65013_set_low_pwr(unsigned mode)
985*4882a593Smuzhiyun {
986*4882a593Smuzhiyun 	int	 status;
987*4882a593Smuzhiyun 	unsigned vdcdc1, chgconfig;
988*4882a593Smuzhiyun 
989*4882a593Smuzhiyun 	if (!the_tps || the_tps->por)
990*4882a593Smuzhiyun 		return -ENODEV;
991*4882a593Smuzhiyun 
992*4882a593Smuzhiyun 	mutex_lock(&the_tps->lock);
993*4882a593Smuzhiyun 
994*4882a593Smuzhiyun 	pr_debug("%s: %s low_pwr, chgconfig 0x%02x vdcdc1 0x%02x\n",
995*4882a593Smuzhiyun 		DRIVER_NAME,
996*4882a593Smuzhiyun 		mode ? "enable" : "disable",
997*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG),
998*4882a593Smuzhiyun 		i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
999*4882a593Smuzhiyun 
1000*4882a593Smuzhiyun 	chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
1001*4882a593Smuzhiyun 	vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
1002*4882a593Smuzhiyun 
1003*4882a593Smuzhiyun 	switch (mode) {
1004*4882a593Smuzhiyun 	case OFF:
1005*4882a593Smuzhiyun 		chgconfig &= ~TPS65013_AUA; /* disable AUA bit */
1006*4882a593Smuzhiyun 		vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */
1007*4882a593Smuzhiyun 		break;
1008*4882a593Smuzhiyun 	/* case ON: */
1009*4882a593Smuzhiyun 	default:
1010*4882a593Smuzhiyun 		chgconfig |= TPS65013_AUA;  /* enable AUA bit */
1011*4882a593Smuzhiyun 		vdcdc1 |= TPS_ENABLE_LP;  /* enable ENABLE_LP bit */
1012*4882a593Smuzhiyun 		break;
1013*4882a593Smuzhiyun 	}
1014*4882a593Smuzhiyun 
1015*4882a593Smuzhiyun 	status = i2c_smbus_write_byte_data(the_tps->client,
1016*4882a593Smuzhiyun 			TPS_CHGCONFIG, chgconfig);
1017*4882a593Smuzhiyun 	if (status != 0) {
1018*4882a593Smuzhiyun 		printk(KERN_ERR "%s: Failed to write chconfig register\n",
1019*4882a593Smuzhiyun 	 DRIVER_NAME);
1020*4882a593Smuzhiyun 		mutex_unlock(&the_tps->lock);
1021*4882a593Smuzhiyun 		return status;
1022*4882a593Smuzhiyun 	}
1023*4882a593Smuzhiyun 
1024*4882a593Smuzhiyun 	chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
1025*4882a593Smuzhiyun 	the_tps->chgconf = chgconfig;
1026*4882a593Smuzhiyun 	show_chgconfig(0, "chgconf", chgconfig);
1027*4882a593Smuzhiyun 
1028*4882a593Smuzhiyun 	status = i2c_smbus_write_byte_data(the_tps->client,
1029*4882a593Smuzhiyun 			TPS_VDCDC1, vdcdc1);
1030*4882a593Smuzhiyun 
1031*4882a593Smuzhiyun 	if (status != 0)
1032*4882a593Smuzhiyun 		printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
1033*4882a593Smuzhiyun 	 DRIVER_NAME);
1034*4882a593Smuzhiyun 	else
1035*4882a593Smuzhiyun 		pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
1036*4882a593Smuzhiyun 			i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
1037*4882a593Smuzhiyun 
1038*4882a593Smuzhiyun 	mutex_unlock(&the_tps->lock);
1039*4882a593Smuzhiyun 
1040*4882a593Smuzhiyun 	return status;
1041*4882a593Smuzhiyun }
1042*4882a593Smuzhiyun EXPORT_SYMBOL(tps65013_set_low_pwr);
1043*4882a593Smuzhiyun 
1044*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
1045*4882a593Smuzhiyun 
tps_init(void)1046*4882a593Smuzhiyun static int __init tps_init(void)
1047*4882a593Smuzhiyun {
1048*4882a593Smuzhiyun 	return i2c_add_driver(&tps65010_driver);
1049*4882a593Smuzhiyun }
1050*4882a593Smuzhiyun /* NOTE:  this MUST be initialized before the other parts of the system
1051*4882a593Smuzhiyun  * that rely on it ... but after the i2c bus on which this relies.
1052*4882a593Smuzhiyun  * That is, much earlier than on PC-type systems, which don't often use
1053*4882a593Smuzhiyun  * I2C as a core system bus.
1054*4882a593Smuzhiyun  */
1055*4882a593Smuzhiyun subsys_initcall(tps_init);
1056*4882a593Smuzhiyun 
tps_exit(void)1057*4882a593Smuzhiyun static void __exit tps_exit(void)
1058*4882a593Smuzhiyun {
1059*4882a593Smuzhiyun 	i2c_del_driver(&tps65010_driver);
1060*4882a593Smuzhiyun }
1061*4882a593Smuzhiyun module_exit(tps_exit);
1062*4882a593Smuzhiyun 
1063