add the new bq27441 driver from lars straight into the kernel tree, to avoid having to build a module every time
parent
903e374985
commit
3594e1cdf1
|
@ -140,7 +140,7 @@ CONFIG_I2C_IMX=y
|
|||
CONFIG_SPI=y
|
||||
CONFIG_GPIO_SYSFS=y
|
||||
CONFIG_POWER_SUPPLY=y
|
||||
CONFIG_BATTERY_BQ27XXX=y
|
||||
CONFIG_BATTERY_BQ27441=y
|
||||
CONFIG_CHARGER_GPIO=y
|
||||
CONFIG_POWER_RESET=y
|
||||
CONFIG_POWER_RESET_SYSCON=y
|
||||
|
|
|
@ -157,6 +157,12 @@ config BATTERY_SBS
|
|||
Say Y to include support for SBS battery driver for SBS-compliant
|
||||
gas gauges.
|
||||
|
||||
config BATTERY_BQ27441
|
||||
tristate "BQ27441 quote unqote advanced battery driver"
|
||||
depends on I2C || I2C=n
|
||||
help
|
||||
Say Y here to use a special driver for the BQ27441.
|
||||
|
||||
config BATTERY_BQ27XXX
|
||||
tristate "BQ27xxx battery driver"
|
||||
depends on I2C || I2C=n
|
||||
|
|
|
@ -29,6 +29,7 @@ obj-$(CONFIG_BATTERY_COLLIE) += collie_battery.o
|
|||
obj-$(CONFIG_BATTERY_IPAQ_MICRO) += ipaq_micro_battery.o
|
||||
obj-$(CONFIG_BATTERY_WM97XX) += wm97xx_battery.o
|
||||
obj-$(CONFIG_BATTERY_SBS) += sbs-battery.o
|
||||
obj-$(CONFIG_BATTERY_BQ27441) += bq27441/bq27441_battery.o bq27441/bq27xxx_battery.o bq27441/bq27xxx_battery_i2c.o
|
||||
obj-$(CONFIG_BATTERY_BQ27XXX) += bq27xxx_battery.o
|
||||
obj-$(CONFIG_BATTERY_BQ27XXX_I2C) += bq27xxx_battery_i2c.o
|
||||
obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,7 @@
|
|||
#ifndef _BQ27441_BATTERY_H
|
||||
#define _BQ27441_BATTERY_H
|
||||
|
||||
int bq27441_init(struct bq27xxx_device_info *di);
|
||||
int bq27441_exit(struct bq27xxx_device_info *di);
|
||||
|
||||
#endif /* _BQ27441_BATTERY_H */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,73 @@
|
|||
#ifndef __LINUX_BQ27X00_BATTERY_H__
|
||||
#define __LINUX_BQ27X00_BATTERY_H__
|
||||
|
||||
enum bq27xxx_chip {
|
||||
BQ27000 = 1, /* bq27000, bq27200 */
|
||||
BQ27010, /* bq27010, bq27210 */
|
||||
BQ27500, /* bq27500, bq27510, bq27520 */
|
||||
BQ27530, /* bq27530, bq27531 */
|
||||
BQ27541, /* bq27541, bq27542, bq27546, bq27742 */
|
||||
BQ27545, /* bq27545 */
|
||||
BQ27421, /* bq27421, bq27425, bq27441, bq27621 */
|
||||
};
|
||||
|
||||
/**
|
||||
* struct bq27xxx_plaform_data - Platform data for bq27xxx devices
|
||||
* @name: Name of the battery.
|
||||
* @chip: Chip class number of this device.
|
||||
* @read: HDQ read callback.
|
||||
* This function should provide access to the HDQ bus the battery is
|
||||
* connected to.
|
||||
* The first parameter is a pointer to the battery device, the second the
|
||||
* register to be read. The return value should either be the content of
|
||||
* the passed register or an error value.
|
||||
*/
|
||||
struct bq27xxx_platform_data {
|
||||
const char *name;
|
||||
enum bq27xxx_chip chip;
|
||||
int (*read)(struct device *dev, unsigned int);
|
||||
};
|
||||
|
||||
struct bq27xxx_device_info;
|
||||
struct bq27xxx_access_methods {
|
||||
int (*read)(struct bq27xxx_device_info *di, u8 reg, bool single);
|
||||
int (*write)(struct bq27xxx_device_info *di, u8 reg, const u8 *data, size_t len);
|
||||
};
|
||||
|
||||
struct bq27xxx_reg_cache {
|
||||
int temperature;
|
||||
int time_to_empty;
|
||||
int time_to_empty_avg;
|
||||
int time_to_full;
|
||||
int charge_full;
|
||||
int cycle_count;
|
||||
int capacity;
|
||||
int energy;
|
||||
int flags;
|
||||
int power_avg;
|
||||
int health;
|
||||
};
|
||||
|
||||
struct dentry;
|
||||
|
||||
struct bq27xxx_device_info {
|
||||
struct device *dev;
|
||||
enum bq27xxx_chip chip;
|
||||
const char *name;
|
||||
struct bq27xxx_access_methods bus;
|
||||
struct bq27xxx_reg_cache cache;
|
||||
int charge_design_full;
|
||||
unsigned long last_update;
|
||||
struct delayed_work work;
|
||||
struct power_supply *bat;
|
||||
struct mutex lock;
|
||||
u8 *regs;
|
||||
struct dentry *dfs_dir;
|
||||
struct dentry *dfs_polarity_file;
|
||||
};
|
||||
|
||||
void bq27xxx_battery_update(struct bq27xxx_device_info *di);
|
||||
int bq27xxx_battery_setup(struct bq27xxx_device_info *di);
|
||||
void bq27xxx_battery_teardown(struct bq27xxx_device_info *di);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,202 @@
|
|||
/*
|
||||
* SCI Reset driver for Keystone based devices
|
||||
*
|
||||
* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Andrew F. Davis <afd@ti.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
|
||||
* kind, whether express or implied; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/module.h>
|
||||
#include <asm/unaligned.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include <linux/string.h>
|
||||
|
||||
#include "bq27xxx_battery.h"
|
||||
|
||||
static irqreturn_t bq27xxx_battery_irq_handler_thread(int irq, void *data)
|
||||
{
|
||||
struct bq27xxx_device_info *di = data;
|
||||
|
||||
bq27xxx_battery_update(di);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int bq27xxx_battery_i2c_read(struct bq27xxx_device_info *di, u8 reg,
|
||||
bool single)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(di->dev);
|
||||
struct i2c_msg msg[2];
|
||||
unsigned char data[2];
|
||||
int ret;
|
||||
|
||||
if (!client->adapter)
|
||||
return -ENODEV;
|
||||
|
||||
msg[0].addr = client->addr;
|
||||
msg[0].flags = 0;
|
||||
msg[0].buf = ®
|
||||
msg[0].len = sizeof(reg);
|
||||
msg[1].addr = client->addr;
|
||||
msg[1].flags = I2C_M_RD;
|
||||
msg[1].buf = data;
|
||||
if (single)
|
||||
msg[1].len = 1;
|
||||
else
|
||||
msg[1].len = 2;
|
||||
|
||||
ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (!single)
|
||||
ret = get_unaligned_le16(data);
|
||||
else
|
||||
ret = data[0];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int bq27xxx_battery_i2c_write(struct bq27xxx_device_info *di, u8 reg,
|
||||
const u8 *data, size_t len)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(di->dev);
|
||||
int ret;
|
||||
unsigned char *buf;
|
||||
|
||||
if (!client->adapter)
|
||||
return -ENODEV;
|
||||
|
||||
buf = kzalloc(len + sizeof(reg), GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
|
||||
buf[0] = reg;
|
||||
memcpy (&buf[1], data, len);
|
||||
|
||||
ret = i2c_master_send(client, buf, len + sizeof(reg));
|
||||
|
||||
kfree(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int bq27xxx_battery_i2c_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *id)
|
||||
{
|
||||
struct bq27xxx_device_info *di;
|
||||
int ret;
|
||||
|
||||
di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL);
|
||||
if (!di)
|
||||
return -ENOMEM;
|
||||
|
||||
di->dev = &client->dev;
|
||||
di->chip = id->driver_data;
|
||||
di->name = id->name;
|
||||
di->bus.read = bq27xxx_battery_i2c_read;
|
||||
di->bus.write = bq27xxx_battery_i2c_write;
|
||||
|
||||
ret = bq27xxx_battery_setup(di);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Schedule a polling after about 1 min */
|
||||
schedule_delayed_work(&di->work, 60 * HZ);
|
||||
|
||||
i2c_set_clientdata(client, di);
|
||||
|
||||
if (client->irq) {
|
||||
ret = devm_request_threaded_irq(&client->dev, client->irq,
|
||||
NULL, bq27xxx_battery_irq_handler_thread,
|
||||
IRQF_ONESHOT,
|
||||
di->name, di);
|
||||
if (ret) {
|
||||
dev_err(&client->dev,
|
||||
"Unable to register IRQ %d error %d\n",
|
||||
client->irq, ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bq27xxx_battery_i2c_remove(struct i2c_client *client)
|
||||
{
|
||||
struct bq27xxx_device_info *di = i2c_get_clientdata(client);
|
||||
|
||||
bq27xxx_battery_teardown(di);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct i2c_device_id bq27xxx_i2c_id_table[] = {
|
||||
{ "bq27200", BQ27000 },
|
||||
{ "bq27210", BQ27010 },
|
||||
{ "bq27500", BQ27500 },
|
||||
{ "bq27510", BQ27500 },
|
||||
{ "bq27520", BQ27500 },
|
||||
{ "bq27530", BQ27530 },
|
||||
{ "bq27531", BQ27530 },
|
||||
{ "bq27541", BQ27541 },
|
||||
{ "bq27542", BQ27541 },
|
||||
{ "bq27546", BQ27541 },
|
||||
{ "bq27742", BQ27541 },
|
||||
{ "bq27545", BQ27545 },
|
||||
{ "bq27421", BQ27421 },
|
||||
{ "bq27425", BQ27421 },
|
||||
{ "bq27441", BQ27421 },
|
||||
{ "bq27621", BQ27421 },
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, bq27xxx_i2c_id_table);
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
static const struct of_device_id bq27xxx_battery_i2c_of_match_table[] = {
|
||||
{ .compatible = "ti,bq27200" },
|
||||
{ .compatible = "ti,bq27210" },
|
||||
{ .compatible = "ti,bq27500" },
|
||||
{ .compatible = "ti,bq27510" },
|
||||
{ .compatible = "ti,bq27520" },
|
||||
{ .compatible = "ti,bq27530" },
|
||||
{ .compatible = "ti,bq27531" },
|
||||
{ .compatible = "ti,bq27541" },
|
||||
{ .compatible = "ti,bq27542" },
|
||||
{ .compatible = "ti,bq27546" },
|
||||
{ .compatible = "ti,bq27742" },
|
||||
{ .compatible = "ti,bq27545" },
|
||||
{ .compatible = "ti,bq27421" },
|
||||
{ .compatible = "ti,bq27425" },
|
||||
{ .compatible = "ti,bq27441" },
|
||||
{ .compatible = "ti,bq27621" },
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, bq27xxx_battery_i2c_of_match_table);
|
||||
#endif
|
||||
|
||||
static struct i2c_driver bq27xxx_battery_i2c_driver = {
|
||||
.driver = {
|
||||
.name = "bq27xxx-battery",
|
||||
.of_match_table = of_match_ptr(bq27xxx_battery_i2c_of_match_table),
|
||||
},
|
||||
.probe = bq27xxx_battery_i2c_probe,
|
||||
.remove = bq27xxx_battery_i2c_remove,
|
||||
.id_table = bq27xxx_i2c_id_table,
|
||||
};
|
||||
module_i2c_driver(bq27xxx_battery_i2c_driver);
|
||||
|
||||
MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
|
||||
MODULE_DESCRIPTION("BQ27xxx battery monitor i2c driver");
|
||||
MODULE_LICENSE("GPL");
|
Loading…
Reference in New Issue