/*
* 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/config.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/workqueue.h>
#include <linux/suspend.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <asm/irq.h>
#include <asm/mach-types.h>
#include <asm/arch/gpio.h>
#include <asm/arch/mux.h>
#include <asm/arch/tps65010.h>
/*-------------------------------------------------------------------------*/
#define DRIVER_VERSION "2 May 2005"
#define DRIVER_NAME (tps65010_driver.name)
MODULE_DESCRIPTION("TPS6501x Power Management Driver");
MODULE_LICENSE("GPL");
static unsigned short normal_i2c[] = { 0x48, /* 0x49, */ I2C_CLIENT_END };
static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
I2C_CLIENT_INSMOD;
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 {
TPS_UNKNOWN = 0,
TPS65010,
TPS65011,
TPS65012,
TPS65013,
};
struct tps65010 {
struct i2c_client client;
struct semaphore lock;
int irq;
struct work_struct work;
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;
/* not currently tracking GPIO state */
};
#define POWER_POLL_DELAY msecs_to_jiffies(800)
/*-------------------------------------------------------------------------*/
#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" : "",
(regstatus & TPS_REG_PG_LD02) ? " ld02_bad" : "",
(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)
{
const char <