2005-05-25 00:34:51 +00:00
|
|
|
/*
|
|
|
|
* tps65010 - driver for tps6501x power management chips
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Texas Instruments
|
|
|
|
* Copyright (C) 2004-2005 David Brownell
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#include <linux/seq_file.h>
|
2006-01-18 22:16:04 +00:00
|
|
|
#include <linux/mutex.h>
|
2008-02-29 06:07:28 +00:00
|
|
|
#include <linux/platform_device.h>
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2008-01-27 17:14:49 +00:00
|
|
|
#include <linux/i2c/tps65010.h>
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2008-02-29 06:07:28 +00:00
|
|
|
#include <asm/gpio.h>
|
|
|
|
|
|
|
|
|
2005-05-25 00:34:51 +00:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#define DRIVER_VERSION "2 May 2005"
|
2006-08-11 20:53:08 +00:00
|
|
|
#define DRIVER_NAME (tps65010_driver.driver.name)
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("TPS6501x Power Management Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
static struct i2c_driver tps65010_driver;
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* This driver handles a family of multipurpose chips, which incorporate
|
|
|
|
* voltage regulators, lithium ion/polymer battery charging, GPIOs, LEDs,
|
|
|
|
* and other features often needed in portable devices like cell phones
|
|
|
|
* or digital cameras.
|
|
|
|
*
|
|
|
|
* The tps65011 and tps65013 have different voltage settings compared
|
|
|
|
* to tps65010 and tps65012. The tps65013 has a NO_CHG status/irq.
|
|
|
|
* All except tps65010 have "wait" mode, possibly defaulted so that
|
|
|
|
* battery-insert != device-on.
|
|
|
|
*
|
|
|
|
* We could distinguish between some models by checking VDCDC1.UVLO or
|
|
|
|
* other registers, unless they've been changed already after powerup
|
|
|
|
* as part of board setup by a bootloader.
|
|
|
|
*/
|
|
|
|
enum tps_model {
|
|
|
|
TPS65010,
|
|
|
|
TPS65011,
|
|
|
|
TPS65012,
|
|
|
|
TPS65013,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tps65010 {
|
2007-10-13 21:56:30 +00:00
|
|
|
struct i2c_client *client;
|
2006-01-18 22:16:04 +00:00
|
|
|
struct mutex lock;
|
2006-12-13 08:33:46 +00:00
|
|
|
struct delayed_work work;
|
2005-05-25 00:34:51 +00:00
|
|
|
struct dentry *file;
|
|
|
|
unsigned charging:1;
|
|
|
|
unsigned por:1;
|
|
|
|
unsigned model:8;
|
|
|
|
u16 vbus;
|
|
|
|
unsigned long flags;
|
|
|
|
#define FLAG_VBUS_CHANGED 0
|
|
|
|
#define FLAG_IRQ_ENABLE 1
|
|
|
|
|
|
|
|
/* copies of last register state */
|
|
|
|
u8 chgstatus, regstatus, chgconf;
|
|
|
|
u8 nmask1, nmask2;
|
|
|
|
|
2008-02-29 06:07:28 +00:00
|
|
|
u8 outmask;
|
|
|
|
struct gpio_chip chip;
|
|
|
|
struct platform_device *leds;
|
2005-05-25 00:34:51 +00:00
|
|
|
};
|
|
|
|
|
2006-08-11 20:53:08 +00:00
|
|
|
#define POWER_POLL_DELAY msecs_to_jiffies(5000)
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#if defined(DEBUG) || defined(CONFIG_DEBUG_FS)
|
|
|
|
|
|
|
|
static void dbg_chgstat(char *buf, size_t len, u8 chgstatus)
|
|
|
|
{
|
|
|
|
snprintf(buf, len, "%02x%s%s%s%s%s%s%s%s\n",
|
|
|
|
chgstatus,
|
|
|
|
(chgstatus & TPS_CHG_USB) ? " USB" : "",
|
|
|
|
(chgstatus & TPS_CHG_AC) ? " AC" : "",
|
|
|
|
(chgstatus & TPS_CHG_THERM) ? " therm" : "",
|
|
|
|
(chgstatus & TPS_CHG_TERM) ? " done" :
|
|
|
|
((chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
|
|
|
|
? " (charging)" : ""),
|
|
|
|
(chgstatus & TPS_CHG_TAPER_TMO) ? " taper_tmo" : "",
|
|
|
|
(chgstatus & TPS_CHG_CHG_TMO) ? " charge_tmo" : "",
|
|
|
|
(chgstatus & TPS_CHG_PRECHG_TMO) ? " prechg_tmo" : "",
|
|
|
|
(chgstatus & TPS_CHG_TEMP_ERR) ? " temp_err" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dbg_regstat(char *buf, size_t len, u8 regstatus)
|
|
|
|
{
|
|
|
|
snprintf(buf, len, "%02x %s%s%s%s%s%s%s%s\n",
|
|
|
|
regstatus,
|
|
|
|
(regstatus & TPS_REG_ONOFF) ? "off" : "(on)",
|
|
|
|
(regstatus & TPS_REG_COVER) ? " uncover" : "",
|
|
|
|
(regstatus & TPS_REG_UVLO) ? " UVLO" : "",
|
|
|
|
(regstatus & TPS_REG_NO_CHG) ? " NO_CHG" : "",
|
2005-06-29 14:13:00 +00:00
|
|
|
(regstatus & TPS_REG_PG_LD02) ? " ld02_bad" : "",
|
2005-05-25 00:34:51 +00:00
|
|
|
(regstatus & TPS_REG_PG_LD01) ? " ld01_bad" : "",
|
|
|
|
(regstatus & TPS_REG_PG_MAIN) ? " main_bad" : "",
|
|
|
|
(regstatus & TPS_REG_PG_CORE) ? " core_bad" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dbg_chgconf(int por, char *buf, size_t len, u8 chgconfig)
|
|
|
|
{
|
2005-06-29 14:13:00 +00:00
|
|
|
const char *hibit;
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
if (por)
|
|
|
|
hibit = (chgconfig & TPS_CHARGE_POR)
|
|
|
|
? "POR=69ms" : "POR=1sec";
|
|
|
|
else
|
|
|
|
hibit = (chgconfig & TPS65013_AUA) ? "AUA" : "";
|
|
|
|
|
|
|
|
snprintf(buf, len, "%02x %s%s%s AC=%d%% USB=%dmA %sCharge\n",
|
|
|
|
chgconfig, hibit,
|
|
|
|
(chgconfig & TPS_CHARGE_RESET) ? " reset" : "",
|
|
|
|
(chgconfig & TPS_CHARGE_FAST) ? " fast" : "",
|
|
|
|
({int p; switch ((chgconfig >> 3) & 3) {
|
|
|
|
case 3: p = 100; break;
|
|
|
|
case 2: p = 75; break;
|
|
|
|
case 1: p = 50; break;
|
|
|
|
default: p = 25; break;
|
|
|
|
}; p; }),
|
|
|
|
(chgconfig & TPS_VBUS_CHARGING)
|
|
|
|
? ((chgconfig & TPS_VBUS_500MA) ? 500 : 100)
|
|
|
|
: 0,
|
|
|
|
(chgconfig & TPS_CHARGE_ENABLE) ? "" : "No");
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
static void show_chgstatus(const char *label, u8 chgstatus)
|
|
|
|
{
|
|
|
|
char buf [100];
|
|
|
|
|
|
|
|
dbg_chgstat(buf, sizeof buf, chgstatus);
|
|
|
|
pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_regstatus(const char *label, u8 regstatus)
|
|
|
|
{
|
|
|
|
char buf [100];
|
|
|
|
|
|
|
|
dbg_regstat(buf, sizeof buf, regstatus);
|
|
|
|
pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_chgconfig(int por, const char *label, u8 chgconfig)
|
|
|
|
{
|
|
|
|
char buf [100];
|
|
|
|
|
|
|
|
dbg_chgconf(por, buf, sizeof buf, chgconfig);
|
|
|
|
pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static inline void show_chgstatus(const char *label, u8 chgstatus) { }
|
|
|
|
static inline void show_regstatus(const char *label, u8 chgstatus) { }
|
|
|
|
static inline void show_chgconfig(int por, const char *label, u8 chgconfig) { }
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
|
|
|
|
static int dbg_show(struct seq_file *s, void *_)
|
|
|
|
{
|
|
|
|
struct tps65010 *tps = s->private;
|
|
|
|
u8 value, v2;
|
|
|
|
unsigned i;
|
|
|
|
char buf[100];
|
|
|
|
const char *chip;
|
|
|
|
|
|
|
|
switch (tps->model) {
|
|
|
|
case TPS65010: chip = "tps65010"; break;
|
|
|
|
case TPS65011: chip = "tps65011"; break;
|
|
|
|
case TPS65012: chip = "tps65012"; break;
|
|
|
|
case TPS65013: chip = "tps65013"; break;
|
|
|
|
default: chip = NULL; break;
|
|
|
|
}
|
|
|
|
seq_printf(s, "driver %s\nversion %s\nchip %s\n\n",
|
|
|
|
DRIVER_NAME, DRIVER_VERSION, chip);
|
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_lock(&tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
/* FIXME how can we tell whether a battery is present?
|
|
|
|
* likely involves a charge gauging chip (like BQ26501).
|
|
|
|
*/
|
|
|
|
|
|
|
|
seq_printf(s, "%scharging\n\n", tps->charging ? "" : "(not) ");
|
|
|
|
|
|
|
|
|
|
|
|
/* registers for monitoring battery charging and status; note
|
|
|
|
* that reading chgstat and regstat may ack IRQs...
|
|
|
|
*/
|
2007-10-13 21:56:30 +00:00
|
|
|
value = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG);
|
2005-05-25 00:34:51 +00:00
|
|
|
dbg_chgconf(tps->por, buf, sizeof buf, value);
|
|
|
|
seq_printf(s, "chgconfig %s", buf);
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
value = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS);
|
2005-05-25 00:34:51 +00:00
|
|
|
dbg_chgstat(buf, sizeof buf, value);
|
|
|
|
seq_printf(s, "chgstat %s", buf);
|
2007-10-13 21:56:30 +00:00
|
|
|
value = i2c_smbus_read_byte_data(tps->client, TPS_MASK1);
|
2005-05-25 00:34:51 +00:00
|
|
|
dbg_chgstat(buf, sizeof buf, value);
|
|
|
|
seq_printf(s, "mask1 %s", buf);
|
|
|
|
/* ignore ackint1 */
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
value = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS);
|
2005-05-25 00:34:51 +00:00
|
|
|
dbg_regstat(buf, sizeof buf, value);
|
|
|
|
seq_printf(s, "regstat %s", buf);
|
2007-10-13 21:56:30 +00:00
|
|
|
value = i2c_smbus_read_byte_data(tps->client, TPS_MASK2);
|
2005-05-25 00:34:51 +00:00
|
|
|
dbg_regstat(buf, sizeof buf, value);
|
|
|
|
seq_printf(s, "mask2 %s\n", buf);
|
|
|
|
/* ignore ackint2 */
|
|
|
|
|
|
|
|
(void) schedule_delayed_work(&tps->work, POWER_POLL_DELAY);
|
|
|
|
|
|
|
|
|
|
|
|
/* VMAIN voltage, enable lowpower, etc */
|
2007-10-13 21:56:30 +00:00
|
|
|
value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC1);
|
2005-05-25 00:34:51 +00:00
|
|
|
seq_printf(s, "vdcdc1 %02x\n", value);
|
|
|
|
|
|
|
|
/* VCORE voltage, vibrator on/off */
|
2007-10-13 21:56:30 +00:00
|
|
|
value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC2);
|
2005-05-25 00:34:51 +00:00
|
|
|
seq_printf(s, "vdcdc2 %02x\n", value);
|
|
|
|
|
|
|
|
/* both LD0s, and their lowpower behavior */
|
2007-10-13 21:56:30 +00:00
|
|
|
value = i2c_smbus_read_byte_data(tps->client, TPS_VREGS1);
|
2005-05-25 00:34:51 +00:00
|
|
|
seq_printf(s, "vregs1 %02x\n\n", value);
|
|
|
|
|
|
|
|
|
|
|
|
/* LEDs and GPIOs */
|
2007-10-13 21:56:30 +00:00
|
|
|
value = i2c_smbus_read_byte_data(tps->client, TPS_LED1_ON);
|
|
|
|
v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED1_PER);
|
2005-05-25 00:34:51 +00:00
|
|
|
seq_printf(s, "led1 %s, on=%02x, per=%02x, %d/%d msec\n",
|
|
|
|
(value & 0x80)
|
|
|
|
? ((v2 & 0x80) ? "on" : "off")
|
|
|
|
: ((v2 & 0x80) ? "blink" : "(nPG)"),
|
|
|
|
value, v2,
|
|
|
|
(value & 0x7f) * 10, (v2 & 0x7f) * 100);
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
value = i2c_smbus_read_byte_data(tps->client, TPS_LED2_ON);
|
|
|
|
v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED2_PER);
|
2005-05-25 00:34:51 +00:00
|
|
|
seq_printf(s, "led2 %s, on=%02x, per=%02x, %d/%d msec\n",
|
|
|
|
(value & 0x80)
|
|
|
|
? ((v2 & 0x80) ? "on" : "off")
|
|
|
|
: ((v2 & 0x80) ? "blink" : "off"),
|
|
|
|
value, v2,
|
|
|
|
(value & 0x7f) * 10, (v2 & 0x7f) * 100);
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO);
|
|
|
|
v2 = i2c_smbus_read_byte_data(tps->client, TPS_MASK3);
|
2005-05-25 00:34:51 +00:00
|
|
|
seq_printf(s, "defgpio %02x mask3 %02x\n", value, v2);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
2005-06-29 14:13:00 +00:00
|
|
|
if (value & (1 << (4 + i)))
|
2005-05-25 00:34:51 +00:00
|
|
|
seq_printf(s, " gpio%d-out %s\n", i + 1,
|
|
|
|
(value & (1 << i)) ? "low" : "hi ");
|
|
|
|
else
|
|
|
|
seq_printf(s, " gpio%d-in %s %s %s\n", i + 1,
|
|
|
|
(value & (1 << i)) ? "hi " : "low",
|
|
|
|
(v2 & (1 << i)) ? "no-irq" : "irq",
|
|
|
|
(v2 & (1 << (4 + i))) ? "rising" : "falling");
|
|
|
|
}
|
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_unlock(&tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dbg_tps_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2006-09-27 08:50:46 +00:00
|
|
|
return single_open(file, dbg_show, inode->i_private);
|
2005-05-25 00:34:51 +00:00
|
|
|
}
|
|
|
|
|
2007-02-12 08:55:32 +00:00
|
|
|
static const struct file_operations debug_fops = {
|
2005-05-25 00:34:51 +00:00
|
|
|
.open = dbg_tps_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEBUG_FOPS &debug_fops
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define DEBUG_FOPS NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* handle IRQS in a task context, so we can use I2C calls */
|
|
|
|
static void tps65010_interrupt(struct tps65010 *tps)
|
|
|
|
{
|
|
|
|
u8 tmp = 0, mask, poll;
|
|
|
|
|
2006-12-13 08:33:46 +00:00
|
|
|
/* IRQs won't trigger for certain events, but we can get
|
2005-05-25 00:34:51 +00:00
|
|
|
* others by polling (normally, with external power applied).
|
|
|
|
*/
|
|
|
|
poll = 0;
|
|
|
|
|
|
|
|
/* regstatus irqs */
|
|
|
|
if (tps->nmask2) {
|
2007-10-13 21:56:30 +00:00
|
|
|
tmp = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS);
|
2005-05-25 00:34:51 +00:00
|
|
|
mask = tmp ^ tps->regstatus;
|
|
|
|
tps->regstatus = tmp;
|
|
|
|
mask &= tps->nmask2;
|
|
|
|
} else
|
|
|
|
mask = 0;
|
|
|
|
if (mask) {
|
|
|
|
tps->regstatus = tmp;
|
|
|
|
/* may need to shut something down ... */
|
|
|
|
|
|
|
|
/* "off" usually means deep sleep */
|
|
|
|
if (tmp & TPS_REG_ONOFF) {
|
|
|
|
pr_info("%s: power off button\n", DRIVER_NAME);
|
|
|
|
#if 0
|
|
|
|
/* REVISIT: this might need its own workqueue
|
|
|
|
* plus tweaks including deadlock avoidance ...
|
2007-05-06 21:50:49 +00:00
|
|
|
* also needs to get error handling and probably
|
2007-07-29 21:24:36 +00:00
|
|
|
* an #ifdef CONFIG_HIBERNATION
|
2005-05-25 00:34:51 +00:00
|
|
|
*/
|
2007-05-09 09:33:18 +00:00
|
|
|
hibernate();
|
2005-05-25 00:34:51 +00:00
|
|
|
#endif
|
|
|
|
poll = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* chgstatus irqs */
|
|
|
|
if (tps->nmask1) {
|
2007-10-13 21:56:30 +00:00
|
|
|
tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS);
|
2005-05-25 00:34:51 +00:00
|
|
|
mask = tmp ^ tps->chgstatus;
|
|
|
|
tps->chgstatus = tmp;
|
|
|
|
mask &= tps->nmask1;
|
|
|
|
} else
|
|
|
|
mask = 0;
|
|
|
|
if (mask) {
|
|
|
|
unsigned charging = 0;
|
|
|
|
|
|
|
|
show_chgstatus("chg/irq", tmp);
|
|
|
|
if (tmp & (TPS_CHG_USB|TPS_CHG_AC))
|
|
|
|
show_chgconfig(tps->por, "conf", tps->chgconf);
|
|
|
|
|
|
|
|
/* Unless it was turned off or disabled, we charge any
|
|
|
|
* battery whenever there's power available for it
|
|
|
|
* and the charger hasn't been disabled.
|
|
|
|
*/
|
|
|
|
if (!(tps->chgstatus & ~(TPS_CHG_USB|TPS_CHG_AC))
|
|
|
|
&& (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
|
|
|
|
&& (tps->chgconf & TPS_CHARGE_ENABLE)
|
|
|
|
) {
|
|
|
|
if (tps->chgstatus & TPS_CHG_USB) {
|
|
|
|
/* VBUS options are readonly until reconnect */
|
|
|
|
if (mask & TPS_CHG_USB)
|
|
|
|
set_bit(FLAG_VBUS_CHANGED, &tps->flags);
|
|
|
|
charging = 1;
|
|
|
|
} else if (tps->chgstatus & TPS_CHG_AC)
|
|
|
|
charging = 1;
|
|
|
|
}
|
|
|
|
if (charging != tps->charging) {
|
|
|
|
tps->charging = charging;
|
|
|
|
pr_info("%s: battery %scharging\n",
|
|
|
|
DRIVER_NAME, charging ? "" :
|
|
|
|
((tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
|
|
|
|
? "NOT " : "dis"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* always poll to detect (a) power removal, without tps65013
|
|
|
|
* NO_CHG IRQ; or (b) restart of charging after stop.
|
|
|
|
*/
|
|
|
|
if ((tps->model != TPS65013 || !tps->charging)
|
|
|
|
&& (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)))
|
|
|
|
poll = 1;
|
|
|
|
if (poll)
|
|
|
|
(void) schedule_delayed_work(&tps->work, POWER_POLL_DELAY);
|
|
|
|
|
|
|
|
/* also potentially gpio-in rise or fall */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle IRQs and polling using keventd for now */
|
2006-12-13 08:33:46 +00:00
|
|
|
static void tps65010_work(struct work_struct *work)
|
2005-05-25 00:34:51 +00:00
|
|
|
{
|
2006-12-13 08:33:46 +00:00
|
|
|
struct tps65010 *tps;
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2006-12-13 08:33:46 +00:00
|
|
|
tps = container_of(work, struct tps65010, work.work);
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_lock(&tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
tps65010_interrupt(tps);
|
|
|
|
|
|
|
|
if (test_and_clear_bit(FLAG_VBUS_CHANGED, &tps->flags)) {
|
|
|
|
int status;
|
|
|
|
u8 chgconfig, tmp;
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
chgconfig = i2c_smbus_read_byte_data(tps->client,
|
2005-05-25 00:34:51 +00:00
|
|
|
TPS_CHGCONFIG);
|
|
|
|
chgconfig &= ~(TPS_VBUS_500MA | TPS_VBUS_CHARGING);
|
|
|
|
if (tps->vbus == 500)
|
|
|
|
chgconfig |= TPS_VBUS_500MA | TPS_VBUS_CHARGING;
|
|
|
|
else if (tps->vbus >= 100)
|
|
|
|
chgconfig |= TPS_VBUS_CHARGING;
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
status = i2c_smbus_write_byte_data(tps->client,
|
2005-05-25 00:34:51 +00:00
|
|
|
TPS_CHGCONFIG, chgconfig);
|
|
|
|
|
|
|
|
/* vbus update fails unless VBUS is connected! */
|
2007-10-13 21:56:30 +00:00
|
|
|
tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG);
|
2005-05-25 00:34:51 +00:00
|
|
|
tps->chgconf = tmp;
|
|
|
|
show_chgconfig(tps->por, "update vbus", tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags))
|
2007-10-13 21:56:30 +00:00
|
|
|
enable_irq(tps->client->irq);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_unlock(&tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t tps65010_irq(int irq, void *_tps)
|
2005-05-25 00:34:51 +00:00
|
|
|
{
|
|
|
|
struct tps65010 *tps = _tps;
|
|
|
|
|
|
|
|
disable_irq_nosync(irq);
|
|
|
|
set_bit(FLAG_IRQ_ENABLE, &tps->flags);
|
2006-12-13 08:33:46 +00:00
|
|
|
(void) schedule_work(&tps->work.work);
|
2005-05-25 00:34:51 +00:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-02-29 06:07:28 +00:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* offsets 0..3 == GPIO1..GPIO4
|
|
|
|
* offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes)
|
2008-10-14 15:30:04 +00:00
|
|
|
* offset 6 == vibrator motor driver
|
2008-02-29 06:07:28 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
tps65010_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
|
|
|
|
{
|
|
|
|
if (offset < 4)
|
|
|
|
tps65010_set_gpio_out_value(offset + 1, value);
|
2008-10-14 15:30:04 +00:00
|
|
|
else if (offset < 6)
|
2008-02-29 06:07:28 +00:00
|
|
|
tps65010_set_led(offset - 3, value ? ON : OFF);
|
2008-10-14 15:30:04 +00:00
|
|
|
else
|
|
|
|
tps65010_set_vib(value);
|
2008-02-29 06:07:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tps65010_output(struct gpio_chip *chip, unsigned offset, int value)
|
|
|
|
{
|
|
|
|
/* GPIOs may be input-only */
|
|
|
|
if (offset < 4) {
|
|
|
|
struct tps65010 *tps;
|
|
|
|
|
|
|
|
tps = container_of(chip, struct tps65010, chip);
|
|
|
|
if (!(tps->outmask & (1 << offset)))
|
|
|
|
return -EINVAL;
|
|
|
|
tps65010_set_gpio_out_value(offset + 1, value);
|
2008-10-14 15:30:04 +00:00
|
|
|
} else if (offset < 6)
|
2008-02-29 06:07:28 +00:00
|
|
|
tps65010_set_led(offset - 3, value ? ON : OFF);
|
2008-10-14 15:30:04 +00:00
|
|
|
else
|
|
|
|
tps65010_set_vib(value);
|
2008-02-29 06:07:28 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tps65010_gpio_get(struct gpio_chip *chip, unsigned offset)
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
struct tps65010 *tps;
|
|
|
|
|
|
|
|
tps = container_of(chip, struct tps65010, chip);
|
|
|
|
|
|
|
|
if (offset < 4) {
|
|
|
|
value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO);
|
|
|
|
if (value < 0)
|
|
|
|
return 0;
|
|
|
|
if (value & (1 << (offset + 4))) /* output */
|
|
|
|
return !(value & (1 << offset));
|
|
|
|
else /* input */
|
|
|
|
return (value & (1 << offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* REVISIT we *could* report LED1/nPG and LED2 state ... */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-25 00:34:51 +00:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static struct tps65010 *the_tps;
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
static int __exit tps65010_remove(struct i2c_client *client)
|
2005-05-25 00:34:51 +00:00
|
|
|
{
|
2007-10-13 21:56:30 +00:00
|
|
|
struct tps65010 *tps = i2c_get_clientdata(client);
|
2008-02-29 06:07:28 +00:00
|
|
|
struct tps65010_board *board = client->dev.platform_data;
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2008-02-29 06:07:28 +00:00
|
|
|
if (board && board->teardown) {
|
|
|
|
int status = board->teardown(client, board->context);
|
|
|
|
if (status < 0)
|
|
|
|
dev_dbg(&client->dev, "board %s %s err %d\n",
|
|
|
|
"teardown", client->name, status);
|
|
|
|
}
|
2007-10-13 21:56:30 +00:00
|
|
|
if (client->irq > 0)
|
|
|
|
free_irq(client->irq, tps);
|
2006-12-13 08:33:46 +00:00
|
|
|
cancel_delayed_work(&tps->work);
|
|
|
|
flush_scheduled_work();
|
2005-05-25 00:34:51 +00:00
|
|
|
debugfs_remove(tps->file);
|
2010-03-20 14:12:54 +00:00
|
|
|
kfree(tps);
|
2005-06-29 14:13:00 +00:00
|
|
|
the_tps = NULL;
|
2005-05-25 00:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-29 21:11:39 +00:00
|
|
|
static int tps65010_probe(struct i2c_client *client,
|
|
|
|
const struct i2c_device_id *id)
|
2005-05-25 00:34:51 +00:00
|
|
|
{
|
|
|
|
struct tps65010 *tps;
|
|
|
|
int status;
|
2008-02-29 06:07:28 +00:00
|
|
|
struct tps65010_board *board = client->dev.platform_data;
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
if (the_tps) {
|
2007-10-13 21:56:30 +00:00
|
|
|
dev_dbg(&client->dev, "only one tps6501x chip allowed\n");
|
|
|
|
return -ENODEV;
|
2005-05-25 00:34:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2005-10-17 21:09:43 +00:00
|
|
|
tps = kzalloc(sizeof *tps, GFP_KERNEL);
|
2005-05-25 00:34:51 +00:00
|
|
|
if (!tps)
|
2007-10-13 21:56:30 +00:00
|
|
|
return -ENOMEM;
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_init(&tps->lock);
|
2006-12-13 08:33:46 +00:00
|
|
|
INIT_DELAYED_WORK(&tps->work, tps65010_work);
|
2007-10-13 21:56:30 +00:00
|
|
|
tps->client = client;
|
2008-04-29 21:11:40 +00:00
|
|
|
tps->model = id->driver_data;
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
/* the IRQ is active low, but many gpio lines can't support that
|
|
|
|
* so this driver uses falling-edge triggers instead.
|
|
|
|
*/
|
|
|
|
if (client->irq > 0) {
|
|
|
|
status = request_irq(client->irq, tps65010_irq,
|
|
|
|
IRQF_SAMPLE_RANDOM | IRQF_TRIGGER_FALLING,
|
|
|
|
DRIVER_NAME, tps);
|
2005-05-25 00:34:51 +00:00
|
|
|
if (status < 0) {
|
2007-10-13 21:56:30 +00:00
|
|
|
dev_dbg(&client->dev, "can't get IRQ %d, err %d\n",
|
2007-10-13 21:56:30 +00:00
|
|
|
client->irq, status);
|
2005-05-25 00:34:51 +00:00
|
|
|
goto fail1;
|
|
|
|
}
|
|
|
|
/* annoying race here, ideally we'd have an option
|
|
|
|
* to claim the irq now and enable it later.
|
2007-10-13 21:56:30 +00:00
|
|
|
* FIXME genirq IRQF_NOAUTOEN now solves that ...
|
2005-05-25 00:34:51 +00:00
|
|
|
*/
|
2007-10-13 21:56:30 +00:00
|
|
|
disable_irq(client->irq);
|
2005-05-25 00:34:51 +00:00
|
|
|
set_bit(FLAG_IRQ_ENABLE, &tps->flags);
|
|
|
|
} else
|
2007-10-13 21:56:30 +00:00
|
|
|
dev_warn(&client->dev, "IRQ not configured!\n");
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
switch (tps->model) {
|
|
|
|
case TPS65010:
|
|
|
|
case TPS65012:
|
|
|
|
tps->por = 1;
|
|
|
|
break;
|
|
|
|
/* else CHGCONFIG.POR is replaced by AUA, enabling a WAIT mode */
|
|
|
|
}
|
2007-10-13 21:56:30 +00:00
|
|
|
tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG);
|
2005-05-25 00:34:51 +00:00
|
|
|
show_chgconfig(tps->por, "conf/init", tps->chgconf);
|
|
|
|
|
|
|
|
show_chgstatus("chg/init",
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(client, TPS_CHGSTATUS));
|
2005-05-25 00:34:51 +00:00
|
|
|
show_regstatus("reg/init",
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(client, TPS_REGSTATUS));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
pr_debug("%s: vdcdc1 0x%02x, vdcdc2 %02x, vregs1 %02x\n", DRIVER_NAME,
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(client, TPS_VDCDC1),
|
|
|
|
i2c_smbus_read_byte_data(client, TPS_VDCDC2),
|
|
|
|
i2c_smbus_read_byte_data(client, TPS_VREGS1));
|
2005-05-25 00:34:51 +00:00
|
|
|
pr_debug("%s: defgpio 0x%02x, mask3 0x%02x\n", DRIVER_NAME,
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(client, TPS_DEFGPIO),
|
|
|
|
i2c_smbus_read_byte_data(client, TPS_MASK3));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2008-04-29 21:11:38 +00:00
|
|
|
i2c_set_clientdata(client, tps);
|
2005-05-25 00:34:51 +00:00
|
|
|
the_tps = tps;
|
|
|
|
|
|
|
|
#if defined(CONFIG_USB_GADGET) && !defined(CONFIG_USB_OTG)
|
|
|
|
/* USB hosts can't draw VBUS. OTG devices could, later
|
|
|
|
* when OTG infrastructure enables it. USB peripherals
|
|
|
|
* could be relying on VBUS while booting, though.
|
|
|
|
*/
|
|
|
|
tps->vbus = 100;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* unmask the "interesting" irqs, then poll once to
|
|
|
|
* kickstart monitoring, initialize shadowed status
|
|
|
|
* registers, and maybe disable VBUS draw.
|
|
|
|
*/
|
|
|
|
tps->nmask1 = ~0;
|
2007-10-13 21:56:30 +00:00
|
|
|
(void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
tps->nmask2 = TPS_REG_ONOFF;
|
|
|
|
if (tps->model == TPS65013)
|
|
|
|
tps->nmask2 |= TPS_REG_NO_CHG;
|
2007-10-13 21:56:30 +00:00
|
|
|
(void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
(void) i2c_smbus_write_byte_data(client, TPS_MASK3, 0x0f
|
|
|
|
| i2c_smbus_read_byte_data(client, TPS_MASK3));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2006-12-13 08:33:46 +00:00
|
|
|
tps65010_work(&tps->work.work);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL,
|
|
|
|
tps, DEBUG_FOPS);
|
2008-02-29 06:07:28 +00:00
|
|
|
|
|
|
|
/* optionally register GPIOs */
|
2009-11-02 16:52:20 +00:00
|
|
|
if (board && board->base != 0) {
|
2008-02-29 06:07:28 +00:00
|
|
|
tps->outmask = board->outmask;
|
|
|
|
|
|
|
|
tps->chip.label = client->name;
|
gpio: sysfs interface
This adds a simple sysfs interface for GPIOs.
/sys/class/gpio
/export ... asks the kernel to export a GPIO to userspace
/unexport ... to return a GPIO to the kernel
/gpioN ... for each exported GPIO #N
/value ... always readable, writes fail for input GPIOs
/direction ... r/w as: in, out (default low); write high, low
/gpiochipN ... for each gpiochip; #N is its first GPIO
/base ... (r/o) same as N
/label ... (r/o) descriptive, not necessarily unique
/ngpio ... (r/o) number of GPIOs; numbered N .. N+(ngpio - 1)
GPIOs claimed by kernel code may be exported by its owner using a new
gpio_export() call, which should be most useful for driver debugging.
Such exports may optionally be done without a "direction" attribute.
Userspace may ask to take over a GPIO by writing to a sysfs control file,
helping to cope with incomplete board support or other "one-off"
requirements that don't merit full kernel support:
echo 23 > /sys/class/gpio/export
... will gpio_request(23, "sysfs") and gpio_export(23);
use /sys/class/gpio/gpio-23/direction to (re)configure it,
when that GPIO can be used as both input and output.
echo 23 > /sys/class/gpio/unexport
... will gpio_free(23), when it was exported as above
The extra D-space footprint is a few hundred bytes, except for the sysfs
resources associated with each exported GPIO. The additional I-space
footprint is about two thirds of the current size of gpiolib (!). Since
no /dev node creation is involved, no "udev" support is needed.
Related changes:
* This adds a device pointer to "struct gpio_chip". When GPIO
providers initialize that, sysfs gpio class devices become children of
that device instead of being "virtual" devices.
* The (few) gpio_chip providers which have such a device node have
been updated.
* Some gpio_chip drivers also needed to update their module "owner"
field ... for which missing kerneldoc was added.
* Some gpio_chips don't support input GPIOs. Those GPIOs are now
flagged appropriately when the chip is registered.
Based on previous patches, and discussion both on and off LKML.
A Documentation/ABI/testing/sysfs-gpio update is ready to submit once this
merges to mainline.
[akpm@linux-foundation.org: a few maintenance build fixes]
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
Cc: Greg KH <greg@kroah.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-07-25 08:46:07 +00:00
|
|
|
tps->chip.dev = &client->dev;
|
|
|
|
tps->chip.owner = THIS_MODULE;
|
2008-02-29 06:07:28 +00:00
|
|
|
|
|
|
|
tps->chip.set = tps65010_gpio_set;
|
|
|
|
tps->chip.direction_output = tps65010_output;
|
|
|
|
|
|
|
|
/* NOTE: only partial support for inputs; nyet IRQs */
|
|
|
|
tps->chip.get = tps65010_gpio_get;
|
|
|
|
|
|
|
|
tps->chip.base = board->base;
|
2008-10-14 15:30:04 +00:00
|
|
|
tps->chip.ngpio = 7;
|
2008-02-29 06:07:28 +00:00
|
|
|
tps->chip.can_sleep = 1;
|
|
|
|
|
|
|
|
status = gpiochip_add(&tps->chip);
|
|
|
|
if (status < 0)
|
|
|
|
dev_err(&client->dev, "can't add gpiochip, err %d\n",
|
|
|
|
status);
|
|
|
|
else if (board->setup) {
|
|
|
|
status = board->setup(client, board->context);
|
|
|
|
if (status < 0) {
|
|
|
|
dev_dbg(&client->dev,
|
|
|
|
"board %s %s err %d\n",
|
|
|
|
"setup", client->name, status);
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-25 00:34:51 +00:00
|
|
|
return 0;
|
2005-06-29 14:13:00 +00:00
|
|
|
fail1:
|
|
|
|
kfree(tps);
|
2007-10-13 21:56:30 +00:00
|
|
|
return status;
|
2005-05-25 00:34:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 21:11:40 +00:00
|
|
|
static const struct i2c_device_id tps65010_id[] = {
|
|
|
|
{ "tps65010", TPS65010 },
|
|
|
|
{ "tps65011", TPS65011 },
|
|
|
|
{ "tps65012", TPS65012 },
|
|
|
|
{ "tps65013", TPS65013 },
|
2008-10-14 15:30:04 +00:00
|
|
|
{ "tps65014", TPS65011 }, /* tps65011 charging at 6.5V max */
|
2008-04-29 21:11:40 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, tps65010_id);
|
|
|
|
|
2005-05-25 00:34:51 +00:00
|
|
|
static struct i2c_driver tps65010_driver = {
|
2005-11-26 19:36:00 +00:00
|
|
|
.driver = {
|
|
|
|
.name = "tps65010",
|
|
|
|
},
|
2007-10-13 21:56:30 +00:00
|
|
|
.probe = tps65010_probe,
|
|
|
|
.remove = __exit_p(tps65010_remove),
|
2008-04-29 21:11:40 +00:00
|
|
|
.id_table = tps65010_id,
|
2005-05-25 00:34:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* Draw from VBUS:
|
|
|
|
* 0 mA -- DON'T DRAW (might supply power instead)
|
|
|
|
* 100 mA -- usb unit load (slowest charge rate)
|
|
|
|
* 500 mA -- usb high power (fast battery charge)
|
|
|
|
*/
|
|
|
|
int tps65010_set_vbus_draw(unsigned mA)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (!the_tps)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* assumes non-SMP */
|
|
|
|
local_irq_save(flags);
|
|
|
|
if (mA >= 500)
|
|
|
|
mA = 500;
|
|
|
|
else if (mA >= 100)
|
|
|
|
mA = 100;
|
|
|
|
else
|
|
|
|
mA = 0;
|
|
|
|
the_tps->vbus = mA;
|
|
|
|
if ((the_tps->chgstatus & TPS_CHG_USB)
|
|
|
|
&& test_and_set_bit(
|
|
|
|
FLAG_VBUS_CHANGED, &the_tps->flags)) {
|
|
|
|
/* gadget drivers call this in_irq() */
|
2006-12-13 08:33:46 +00:00
|
|
|
(void) schedule_work(&the_tps->work.work);
|
2005-05-25 00:34:51 +00:00
|
|
|
}
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(tps65010_set_vbus_draw);
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* tps65010_set_gpio_out_value parameter:
|
|
|
|
* gpio: GPIO1, GPIO2, GPIO3 or GPIO4
|
|
|
|
* value: LOW or HIGH
|
|
|
|
*/
|
|
|
|
int tps65010_set_gpio_out_value(unsigned gpio, unsigned value)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
unsigned defgpio;
|
|
|
|
|
|
|
|
if (!the_tps)
|
|
|
|
return -ENODEV;
|
|
|
|
if ((gpio < GPIO1) || (gpio > GPIO4))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_lock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
/* Configure GPIO for output */
|
|
|
|
defgpio |= 1 << (gpio + 3);
|
|
|
|
|
|
|
|
/* Writing 1 forces a logic 0 on that GPIO and vice versa */
|
|
|
|
switch (value) {
|
|
|
|
case LOW:
|
|
|
|
defgpio |= 1 << (gpio - 1); /* set GPIO low by writing 1 */
|
|
|
|
break;
|
|
|
|
/* case HIGH: */
|
|
|
|
default:
|
|
|
|
defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
status = i2c_smbus_write_byte_data(the_tps->client,
|
2005-05-25 00:34:51 +00:00
|
|
|
TPS_DEFGPIO, defgpio);
|
|
|
|
|
|
|
|
pr_debug("%s: gpio%dout = %s, defgpio 0x%02x\n", DRIVER_NAME,
|
|
|
|
gpio, value ? "high" : "low",
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_unlock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(tps65010_set_gpio_out_value);
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* tps65010_set_led parameter:
|
|
|
|
* led: LED1 or LED2
|
|
|
|
* mode: ON, OFF or BLINK
|
|
|
|
*/
|
|
|
|
int tps65010_set_led(unsigned led, unsigned mode)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
unsigned led_on, led_per, offs;
|
|
|
|
|
|
|
|
if (!the_tps)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2005-06-29 14:13:00 +00:00
|
|
|
if (led == LED1)
|
2005-05-25 00:34:51 +00:00
|
|
|
offs = 0;
|
|
|
|
else {
|
|
|
|
offs = 2;
|
|
|
|
led = LED2;
|
|
|
|
}
|
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_lock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2005-06-29 14:13:00 +00:00
|
|
|
pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(the_tps->client,
|
2005-06-29 14:13:00 +00:00
|
|
|
TPS_LED1_ON + offs));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2005-06-29 14:13:00 +00:00
|
|
|
pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(the_tps->client,
|
2005-06-29 14:13:00 +00:00
|
|
|
TPS_LED1_PER + offs));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case OFF:
|
|
|
|
led_on = 1 << 7;
|
|
|
|
led_per = 0 << 7;
|
|
|
|
break;
|
|
|
|
case ON:
|
|
|
|
led_on = 1 << 7;
|
|
|
|
led_per = 1 << 7;
|
|
|
|
break;
|
|
|
|
case BLINK:
|
|
|
|
led_on = 0x30 | (0 << 7);
|
|
|
|
led_per = 0x08 | (1 << 7);
|
|
|
|
break;
|
|
|
|
default:
|
2005-06-29 14:13:00 +00:00
|
|
|
printk(KERN_ERR "%s: Wrong mode parameter for set_led()\n",
|
2005-05-25 00:34:51 +00:00
|
|
|
DRIVER_NAME);
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_unlock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
status = i2c_smbus_write_byte_data(the_tps->client,
|
2005-05-25 00:34:51 +00:00
|
|
|
TPS_LED1_ON + offs, led_on);
|
|
|
|
|
|
|
|
if (status != 0) {
|
|
|
|
printk(KERN_ERR "%s: Failed to write led%i_on register\n",
|
|
|
|
DRIVER_NAME, led);
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_unlock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2005-06-29 14:13:00 +00:00
|
|
|
pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
status = i2c_smbus_write_byte_data(the_tps->client,
|
2005-05-25 00:34:51 +00:00
|
|
|
TPS_LED1_PER + offs, led_per);
|
|
|
|
|
|
|
|
if (status != 0) {
|
|
|
|
printk(KERN_ERR "%s: Failed to write led%i_per register\n",
|
|
|
|
DRIVER_NAME, led);
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_unlock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2005-06-29 14:13:00 +00:00
|
|
|
pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(the_tps->client,
|
2005-06-29 14:13:00 +00:00
|
|
|
TPS_LED1_PER + offs));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_unlock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(tps65010_set_led);
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* tps65010_set_vib parameter:
|
|
|
|
* value: ON or OFF
|
|
|
|
*/
|
|
|
|
int tps65010_set_vib(unsigned value)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
unsigned vdcdc2;
|
|
|
|
|
|
|
|
if (!the_tps)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_lock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2);
|
2005-05-25 00:34:51 +00:00
|
|
|
vdcdc2 &= ~(1 << 1);
|
|
|
|
if (value)
|
|
|
|
vdcdc2 |= (1 << 1);
|
2007-10-13 21:56:30 +00:00
|
|
|
status = i2c_smbus_write_byte_data(the_tps->client,
|
2005-05-25 00:34:51 +00:00
|
|
|
TPS_VDCDC2, vdcdc2);
|
|
|
|
|
|
|
|
pr_debug("%s: vibrator %s\n", DRIVER_NAME, value ? "on" : "off");
|
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_unlock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(tps65010_set_vib);
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* tps65010_set_low_pwr parameter:
|
|
|
|
* mode: ON or OFF
|
|
|
|
*/
|
|
|
|
int tps65010_set_low_pwr(unsigned mode)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
unsigned vdcdc1;
|
|
|
|
|
|
|
|
if (!the_tps)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_lock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
pr_debug("%s: %s low_pwr, vdcdc1 0x%02x\n", DRIVER_NAME,
|
|
|
|
mode ? "enable" : "disable",
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case OFF:
|
|
|
|
vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */
|
|
|
|
break;
|
|
|
|
/* case ON: */
|
|
|
|
default:
|
|
|
|
vdcdc1 |= TPS_ENABLE_LP; /* enable ENABLE_LP bit */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
status = i2c_smbus_write_byte_data(the_tps->client,
|
2005-05-25 00:34:51 +00:00
|
|
|
TPS_VDCDC1, vdcdc1);
|
|
|
|
|
|
|
|
if (status != 0)
|
|
|
|
printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
|
2005-06-29 14:13:00 +00:00
|
|
|
DRIVER_NAME);
|
2005-05-25 00:34:51 +00:00
|
|
|
else
|
|
|
|
pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_unlock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(tps65010_set_low_pwr);
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* tps65010_config_vregs1 parameter:
|
|
|
|
* value to be written to VREGS1 register
|
|
|
|
* Note: The complete register is written, set all bits you need
|
|
|
|
*/
|
|
|
|
int tps65010_config_vregs1(unsigned value)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (!the_tps)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_lock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
status = i2c_smbus_write_byte_data(the_tps->client,
|
2005-05-25 00:34:51 +00:00
|
|
|
TPS_VREGS1, value);
|
|
|
|
|
|
|
|
if (status != 0)
|
|
|
|
printk(KERN_ERR "%s: Failed to write vregs1 register\n",
|
2005-06-29 14:13:00 +00:00
|
|
|
DRIVER_NAME);
|
2005-05-25 00:34:51 +00:00
|
|
|
else
|
|
|
|
pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_unlock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(tps65010_config_vregs1);
|
|
|
|
|
2009-11-02 16:52:30 +00:00
|
|
|
int tps65010_config_vdcdc2(unsigned value)
|
|
|
|
{
|
|
|
|
struct i2c_client *c;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (!the_tps)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
c = the_tps->client;
|
|
|
|
mutex_lock(&the_tps->lock);
|
|
|
|
|
|
|
|
pr_debug("%s: vdcdc2 0x%02x\n", DRIVER_NAME,
|
|
|
|
i2c_smbus_read_byte_data(c, TPS_VDCDC2));
|
|
|
|
|
|
|
|
status = i2c_smbus_write_byte_data(c, TPS_VDCDC2, value);
|
|
|
|
|
|
|
|
if (status != 0)
|
|
|
|
printk(KERN_ERR "%s: Failed to write vdcdc2 register\n",
|
|
|
|
DRIVER_NAME);
|
|
|
|
else
|
|
|
|
pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
|
|
|
|
i2c_smbus_read_byte_data(c, TPS_VDCDC2));
|
|
|
|
|
|
|
|
mutex_unlock(&the_tps->lock);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(tps65010_config_vdcdc2);
|
|
|
|
|
2005-05-25 00:34:51 +00:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* tps65013_set_low_pwr parameter:
|
|
|
|
* mode: ON or OFF
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* FIXME: Assumes AC or USB power is present. Setting AUA bit is not
|
|
|
|
required if power supply is through a battery */
|
|
|
|
|
|
|
|
int tps65013_set_low_pwr(unsigned mode)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
unsigned vdcdc1, chgconfig;
|
|
|
|
|
|
|
|
if (!the_tps || the_tps->por)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_lock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
pr_debug("%s: %s low_pwr, chgconfig 0x%02x vdcdc1 0x%02x\n",
|
|
|
|
DRIVER_NAME,
|
|
|
|
mode ? "enable" : "disable",
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG),
|
|
|
|
i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
|
|
|
|
vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case OFF:
|
|
|
|
chgconfig &= ~TPS65013_AUA; /* disable AUA bit */
|
|
|
|
vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */
|
|
|
|
break;
|
|
|
|
/* case ON: */
|
|
|
|
default:
|
|
|
|
chgconfig |= TPS65013_AUA; /* enable AUA bit */
|
|
|
|
vdcdc1 |= TPS_ENABLE_LP; /* enable ENABLE_LP bit */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
status = i2c_smbus_write_byte_data(the_tps->client,
|
2005-05-25 00:34:51 +00:00
|
|
|
TPS_CHGCONFIG, chgconfig);
|
|
|
|
if (status != 0) {
|
|
|
|
printk(KERN_ERR "%s: Failed to write chconfig register\n",
|
|
|
|
DRIVER_NAME);
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_unlock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
|
2005-05-25 00:34:51 +00:00
|
|
|
the_tps->chgconf = chgconfig;
|
|
|
|
show_chgconfig(0, "chgconf", chgconfig);
|
|
|
|
|
2007-10-13 21:56:30 +00:00
|
|
|
status = i2c_smbus_write_byte_data(the_tps->client,
|
2005-05-25 00:34:51 +00:00
|
|
|
TPS_VDCDC1, vdcdc1);
|
|
|
|
|
|
|
|
if (status != 0)
|
|
|
|
printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
|
|
|
|
DRIVER_NAME);
|
|
|
|
else
|
|
|
|
pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
|
2007-10-13 21:56:30 +00:00
|
|
|
i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
|
2005-05-25 00:34:51 +00:00
|
|
|
|
2006-01-18 22:16:04 +00:00
|
|
|
mutex_unlock(&the_tps->lock);
|
2005-05-25 00:34:51 +00:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(tps65013_set_low_pwr);
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int __init tps_init(void)
|
|
|
|
{
|
|
|
|
u32 tries = 3;
|
|
|
|
int status = -ENODEV;
|
|
|
|
|
|
|
|
printk(KERN_INFO "%s: version %s\n", DRIVER_NAME, DRIVER_VERSION);
|
|
|
|
|
|
|
|
/* some boards have startup glitches */
|
|
|
|
while (tries--) {
|
|
|
|
status = i2c_add_driver(&tps65010_driver);
|
|
|
|
if (the_tps)
|
|
|
|
break;
|
|
|
|
i2c_del_driver(&tps65010_driver);
|
|
|
|
if (!tries) {
|
|
|
|
printk(KERN_ERR "%s: no chip?\n", DRIVER_NAME);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
pr_debug("%s: re-probe ...\n", DRIVER_NAME);
|
|
|
|
msleep(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
/* NOTE: this MUST be initialized before the other parts of the system
|
|
|
|
* that rely on it ... but after the i2c bus on which this relies.
|
|
|
|
* That is, much earlier than on PC-type systems, which don't often use
|
|
|
|
* I2C as a core system bus.
|
|
|
|
*/
|
|
|
|
subsys_initcall(tps_init);
|
|
|
|
|
|
|
|
static void __exit tps_exit(void)
|
|
|
|
{
|
|
|
|
i2c_del_driver(&tps65010_driver);
|
|
|
|
}
|
|
|
|
module_exit(tps_exit);
|
|
|
|
|