mirror of https://gitee.com/openkylin/linux.git
mfd: Add TPS6507x support
TPS6507x are multi function (PM, touchscreen) chipsets from TI. This commit also changes the corresponding regulator driver from being standalone to an MFD subdevice. Signed-off-by: Todd Fischer <todd.fischer@ridgerun.com> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
4ce5ba5ba2
commit
31dd6a2672
|
@ -116,6 +116,18 @@ config TPS65010
|
|||
This driver can also be built as a module. If so, the module
|
||||
will be called tps65010.
|
||||
|
||||
config TPS6507X
|
||||
tristate "TPS6507x Power Management / Touch Screen chips"
|
||||
select MFD_CORE
|
||||
depends on I2C
|
||||
help
|
||||
If you say yes here you get support for the TPS6507x series of
|
||||
Power Management / Touch Screen chips. These include voltage
|
||||
regulators, lithium ion/polymer battery charging, touch screen
|
||||
and other features that are often used in portable devices.
|
||||
This driver can also be built as a module. If so, the module
|
||||
will be called tps6507x.
|
||||
|
||||
config MENELAUS
|
||||
bool "Texas Instruments TWL92330/Menelaus PM chip"
|
||||
depends on I2C=y && ARCH_OMAP2
|
||||
|
|
|
@ -29,6 +29,7 @@ obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o
|
|||
obj-$(CONFIG_MFD_WM8994) += wm8994-core.o wm8994-irq.o
|
||||
|
||||
obj-$(CONFIG_TPS65010) += tps65010.o
|
||||
obj-$(CONFIG_TPS6507X) += tps6507x.o
|
||||
obj-$(CONFIG_MENELAUS) += menelaus.o
|
||||
|
||||
obj-$(CONFIG_TWL4030_CORE) += twl-core.o twl4030-irq.o twl6030-irq.o
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* tps6507x.c -- TPS6507x chip family multi-function driver
|
||||
*
|
||||
* Copyright (c) 2010 RidgeRun (todd.fischer@ridgerun.com)
|
||||
*
|
||||
* Author: Todd Fischer
|
||||
* todd.fischer@ridgerun.com
|
||||
*
|
||||
* Credits:
|
||||
*
|
||||
* Using code from wm831x-*.c, wm8400-core, Wolfson Microelectronics PLC.
|
||||
*
|
||||
* For licencing details see kernel-base/COPYING
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/mfd/core.h>
|
||||
#include <linux/mfd/tps6507x.h>
|
||||
|
||||
static struct mfd_cell tps6507x_devs[] = {
|
||||
{
|
||||
.name = "tps6507x-pmic",
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
static int tps6507x_i2c_read_device(struct tps6507x_dev *tps6507x, char reg,
|
||||
int bytes, void *dest)
|
||||
{
|
||||
struct i2c_client *i2c = tps6507x->i2c_client;
|
||||
struct i2c_msg xfer[2];
|
||||
int ret;
|
||||
|
||||
/* Write register */
|
||||
xfer[0].addr = i2c->addr;
|
||||
xfer[0].flags = 0;
|
||||
xfer[0].len = 1;
|
||||
xfer[0].buf = ®
|
||||
|
||||
/* Read data */
|
||||
xfer[1].addr = i2c->addr;
|
||||
xfer[1].flags = I2C_M_RD;
|
||||
xfer[1].len = bytes;
|
||||
xfer[1].buf = dest;
|
||||
|
||||
ret = i2c_transfer(i2c->adapter, xfer, 2);
|
||||
if (ret == 2)
|
||||
ret = 0;
|
||||
else if (ret >= 0)
|
||||
ret = -EIO;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int tps6507x_i2c_write_device(struct tps6507x_dev *tps6507x, char reg,
|
||||
int bytes, void *src)
|
||||
{
|
||||
struct i2c_client *i2c = tps6507x->i2c_client;
|
||||
/* we add 1 byte for device register */
|
||||
u8 msg[TPS6507X_MAX_REGISTER + 1];
|
||||
int ret;
|
||||
|
||||
if (bytes > (TPS6507X_MAX_REGISTER + 1))
|
||||
return -EINVAL;
|
||||
|
||||
msg[0] = reg;
|
||||
memcpy(&msg[1], src, bytes);
|
||||
|
||||
ret = i2c_master_send(i2c, msg, bytes + 1);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (ret != bytes + 1)
|
||||
return -EIO;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tps6507x_i2c_probe(struct i2c_client *i2c,
|
||||
const struct i2c_device_id *id)
|
||||
{
|
||||
struct tps6507x_dev *tps6507x;
|
||||
int ret = 0;
|
||||
|
||||
tps6507x = kzalloc(sizeof(struct tps6507x_dev), GFP_KERNEL);
|
||||
if (tps6507x == NULL) {
|
||||
kfree(i2c);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
i2c_set_clientdata(i2c, tps6507x);
|
||||
tps6507x->dev = &i2c->dev;
|
||||
tps6507x->i2c_client = i2c;
|
||||
tps6507x->read_dev = tps6507x_i2c_read_device;
|
||||
tps6507x->write_dev = tps6507x_i2c_write_device;
|
||||
|
||||
ret = mfd_add_devices(tps6507x->dev, -1,
|
||||
tps6507x_devs, ARRAY_SIZE(tps6507x_devs),
|
||||
NULL, 0);
|
||||
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
return ret;
|
||||
|
||||
err:
|
||||
mfd_remove_devices(tps6507x->dev);
|
||||
kfree(tps6507x);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int tps6507x_i2c_remove(struct i2c_client *i2c)
|
||||
{
|
||||
struct tps6507x_dev *tps6507x = i2c_get_clientdata(i2c);
|
||||
|
||||
mfd_remove_devices(tps6507x->dev);
|
||||
kfree(tps6507x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct i2c_device_id tps6507x_i2c_id[] = {
|
||||
{ "tps6507x", 0 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, tps6507x_i2c_id);
|
||||
|
||||
|
||||
static struct i2c_driver tps6507x_i2c_driver = {
|
||||
.driver = {
|
||||
.name = "tps6507x",
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
.probe = tps6507x_i2c_probe,
|
||||
.remove = tps6507x_i2c_remove,
|
||||
.id_table = tps6507x_i2c_id,
|
||||
};
|
||||
|
||||
static int __init tps6507x_i2c_init(void)
|
||||
{
|
||||
return i2c_add_driver(&tps6507x_i2c_driver);
|
||||
}
|
||||
/* init early so consumer devices can complete system boot */
|
||||
subsys_initcall(tps6507x_i2c_init);
|
||||
|
||||
static void __exit tps6507x_i2c_exit(void)
|
||||
{
|
||||
i2c_del_driver(&tps6507x_i2c_driver);
|
||||
}
|
||||
module_exit(tps6507x_i2c_exit);
|
||||
|
||||
MODULE_DESCRIPTION("TPS6507x chip family multi-function driver");
|
||||
MODULE_LICENSE("GPL");
|
|
@ -22,7 +22,6 @@
|
|||
#include <linux/platform_device.h>
|
||||
#include <linux/regulator/driver.h>
|
||||
#include <linux/regulator/machine.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/mfd/tps6507x.h>
|
||||
|
@ -104,22 +103,67 @@ struct tps_info {
|
|||
const u16 *table;
|
||||
};
|
||||
|
||||
static const struct tps_info tps6507x_pmic_regs[] = {
|
||||
{
|
||||
.name = "VDCDC1",
|
||||
.min_uV = 725000,
|
||||
.max_uV = 3300000,
|
||||
.table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
|
||||
.table = VDCDCx_VSEL_table,
|
||||
},
|
||||
{
|
||||
.name = "VDCDC2",
|
||||
.min_uV = 725000,
|
||||
.max_uV = 3300000,
|
||||
.table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
|
||||
.table = VDCDCx_VSEL_table,
|
||||
},
|
||||
{
|
||||
.name = "VDCDC3",
|
||||
.min_uV = 725000,
|
||||
.max_uV = 3300000,
|
||||
.table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
|
||||
.table = VDCDCx_VSEL_table,
|
||||
},
|
||||
{
|
||||
.name = "LDO1",
|
||||
.min_uV = 1000000,
|
||||
.max_uV = 3300000,
|
||||
.table_len = ARRAY_SIZE(LDO1_VSEL_table),
|
||||
.table = LDO1_VSEL_table,
|
||||
},
|
||||
{
|
||||
.name = "LDO2",
|
||||
.min_uV = 725000,
|
||||
.max_uV = 3300000,
|
||||
.table_len = ARRAY_SIZE(LDO2_VSEL_table),
|
||||
.table = LDO2_VSEL_table,
|
||||
},
|
||||
};
|
||||
|
||||
struct tps6507x_pmic {
|
||||
struct regulator_desc desc[TPS6507X_NUM_REGULATOR];
|
||||
struct i2c_client *client;
|
||||
struct tps6507x_dev *mfd;
|
||||
struct regulator_dev *rdev[TPS6507X_NUM_REGULATOR];
|
||||
const struct tps_info *info[TPS6507X_NUM_REGULATOR];
|
||||
struct mutex io_lock;
|
||||
};
|
||||
|
||||
static inline int tps6507x_pmic_read(struct tps6507x_pmic *tps, u8 reg)
|
||||
{
|
||||
return i2c_smbus_read_byte_data(tps->client, reg);
|
||||
u8 val;
|
||||
int err;
|
||||
|
||||
err = tps->mfd->read_dev(tps->mfd, reg, 1, &val);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline int tps6507x_pmic_write(struct tps6507x_pmic *tps, u8 reg, u8 val)
|
||||
{
|
||||
return i2c_smbus_write_byte_data(tps->client, reg, val);
|
||||
return tps->mfd->write_dev(tps->mfd, reg, 1, &val);
|
||||
}
|
||||
|
||||
static int tps6507x_pmic_set_bits(struct tps6507x_pmic *tps, u8 reg, u8 mask)
|
||||
|
@ -130,7 +174,7 @@ static int tps6507x_pmic_set_bits(struct tps6507x_pmic *tps, u8 reg, u8 mask)
|
|||
|
||||
data = tps6507x_pmic_read(tps, reg);
|
||||
if (data < 0) {
|
||||
dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg);
|
||||
dev_err(tps->mfd->dev, "Read from reg 0x%x failed\n", reg);
|
||||
err = data;
|
||||
goto out;
|
||||
}
|
||||
|
@ -138,7 +182,7 @@ static int tps6507x_pmic_set_bits(struct tps6507x_pmic *tps, u8 reg, u8 mask)
|
|||
data |= mask;
|
||||
err = tps6507x_pmic_write(tps, reg, data);
|
||||
if (err)
|
||||
dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg);
|
||||
dev_err(tps->mfd->dev, "Write for reg 0x%x failed\n", reg);
|
||||
|
||||
out:
|
||||
mutex_unlock(&tps->io_lock);
|
||||
|
@ -153,7 +197,7 @@ static int tps6507x_pmic_clear_bits(struct tps6507x_pmic *tps, u8 reg, u8 mask)
|
|||
|
||||
data = tps6507x_pmic_read(tps, reg);
|
||||
if (data < 0) {
|
||||
dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg);
|
||||
dev_err(tps->mfd->dev, "Read from reg 0x%x failed\n", reg);
|
||||
err = data;
|
||||
goto out;
|
||||
}
|
||||
|
@ -161,7 +205,7 @@ static int tps6507x_pmic_clear_bits(struct tps6507x_pmic *tps, u8 reg, u8 mask)
|
|||
data &= ~mask;
|
||||
err = tps6507x_pmic_write(tps, reg, data);
|
||||
if (err)
|
||||
dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg);
|
||||
dev_err(tps->mfd->dev, "Write for reg 0x%x failed\n", reg);
|
||||
|
||||
out:
|
||||
mutex_unlock(&tps->io_lock);
|
||||
|
@ -176,7 +220,7 @@ static int tps6507x_pmic_reg_read(struct tps6507x_pmic *tps, u8 reg)
|
|||
|
||||
data = tps6507x_pmic_read(tps, reg);
|
||||
if (data < 0)
|
||||
dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg);
|
||||
dev_err(tps->mfd->dev, "Read from reg 0x%x failed\n", reg);
|
||||
|
||||
mutex_unlock(&tps->io_lock);
|
||||
return data;
|
||||
|
@ -190,7 +234,7 @@ static int tps6507x_pmic_reg_write(struct tps6507x_pmic *tps, u8 reg, u8 val)
|
|||
|
||||
err = tps6507x_pmic_write(tps, reg, val);
|
||||
if (err < 0)
|
||||
dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg);
|
||||
dev_err(tps->mfd->dev, "Write for reg 0x%x failed\n", reg);
|
||||
|
||||
mutex_unlock(&tps->io_lock);
|
||||
return err;
|
||||
|
@ -483,11 +527,12 @@ static struct regulator_ops tps6507x_pmic_ldo_ops = {
|
|||
.list_voltage = tps6507x_pmic_ldo_list_voltage,
|
||||
};
|
||||
|
||||
static int __devinit tps6507x_pmic_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *id)
|
||||
static __devinit
|
||||
int tps6507x_pmic_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
|
||||
static int desc_id;
|
||||
const struct tps_info *info = (void *)id->driver_data;
|
||||
const struct tps_info *info = &tps6507x_pmic_regs[0];
|
||||
struct regulator_init_data *init_data;
|
||||
struct regulator_dev *rdev;
|
||||
struct tps6507x_pmic *tps;
|
||||
|
@ -495,16 +540,12 @@ static int __devinit tps6507x_pmic_probe(struct i2c_client *client,
|
|||
int i;
|
||||
int error;
|
||||
|
||||
if (!i2c_check_functionality(client->adapter,
|
||||
I2C_FUNC_SMBUS_BYTE_DATA))
|
||||
return -EIO;
|
||||
|
||||
/**
|
||||
* tps_board points to pmic related constants
|
||||
* coming from the board-evm file.
|
||||
*/
|
||||
|
||||
tps_board = dev_get_platdata(&client->dev);
|
||||
tps_board = dev_get_platdata(tps6507x_dev->dev);
|
||||
if (!tps_board)
|
||||
return -EINVAL;
|
||||
|
||||
|
@ -523,7 +564,7 @@ static int __devinit tps6507x_pmic_probe(struct i2c_client *client,
|
|||
mutex_init(&tps->io_lock);
|
||||
|
||||
/* common for all regulators */
|
||||
tps->client = client;
|
||||
tps->mfd = tps6507x_dev;
|
||||
|
||||
for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++, init_data++) {
|
||||
/* Register the regulators */
|
||||
|
@ -537,10 +578,11 @@ static int __devinit tps6507x_pmic_probe(struct i2c_client *client,
|
|||
tps->desc[i].owner = THIS_MODULE;
|
||||
|
||||
rdev = regulator_register(&tps->desc[i],
|
||||
&client->dev, init_data, tps);
|
||||
tps6507x_dev->dev, init_data, tps);
|
||||
if (IS_ERR(rdev)) {
|
||||
dev_err(&client->dev, "failed to register %s\n",
|
||||
id->name);
|
||||
dev_err(tps6507x_dev->dev,
|
||||
"failed to register %s regulator\n",
|
||||
pdev->name);
|
||||
error = PTR_ERR(rdev);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -549,7 +591,7 @@ static int __devinit tps6507x_pmic_probe(struct i2c_client *client,
|
|||
tps->rdev[i] = rdev;
|
||||
}
|
||||
|
||||
i2c_set_clientdata(client, tps);
|
||||
tps6507x_dev->pmic = tps;
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -567,14 +609,12 @@ static int __devinit tps6507x_pmic_probe(struct i2c_client *client,
|
|||
*
|
||||
* Unregister TPS driver as an i2c client device driver
|
||||
*/
|
||||
static int __devexit tps6507x_pmic_remove(struct i2c_client *client)
|
||||
static int __devexit tps6507x_pmic_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct tps6507x_pmic *tps = i2c_get_clientdata(client);
|
||||
struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev);
|
||||
struct tps6507x_pmic *tps = tps6507x_dev->pmic;
|
||||
int i;
|
||||
|
||||
/* clear the client data in i2c */
|
||||
i2c_set_clientdata(client, NULL);
|
||||
|
||||
for (i = 0; i < TPS6507X_NUM_REGULATOR; i++)
|
||||
regulator_unregister(tps->rdev[i]);
|
||||
|
||||
|
@ -583,59 +623,13 @@ static int __devexit tps6507x_pmic_remove(struct i2c_client *client)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const struct tps_info tps6507x_pmic_regs[] = {
|
||||
{
|
||||
.name = "VDCDC1",
|
||||
.min_uV = 725000,
|
||||
.max_uV = 3300000,
|
||||
.table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
|
||||
.table = VDCDCx_VSEL_table,
|
||||
},
|
||||
{
|
||||
.name = "VDCDC2",
|
||||
.min_uV = 725000,
|
||||
.max_uV = 3300000,
|
||||
.table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
|
||||
.table = VDCDCx_VSEL_table,
|
||||
},
|
||||
{
|
||||
.name = "VDCDC3",
|
||||
.min_uV = 725000,
|
||||
.max_uV = 3300000,
|
||||
.table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
|
||||
.table = VDCDCx_VSEL_table,
|
||||
},
|
||||
{
|
||||
.name = "LDO1",
|
||||
.min_uV = 1000000,
|
||||
.max_uV = 3300000,
|
||||
.table_len = ARRAY_SIZE(LDO1_VSEL_table),
|
||||
.table = LDO1_VSEL_table,
|
||||
},
|
||||
{
|
||||
.name = "LDO2",
|
||||
.min_uV = 725000,
|
||||
.max_uV = 3300000,
|
||||
.table_len = ARRAY_SIZE(LDO2_VSEL_table),
|
||||
.table = LDO2_VSEL_table,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct i2c_device_id tps6507x_pmic_id[] = {
|
||||
{.name = "tps6507x",
|
||||
.driver_data = (unsigned long) tps6507x_pmic_regs,},
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, tps6507x_pmic_id);
|
||||
|
||||
static struct i2c_driver tps6507x_i2c_driver = {
|
||||
static struct platform_driver tps6507x_pmic_driver = {
|
||||
.driver = {
|
||||
.name = "tps6507x",
|
||||
.name = "tps6507x-pmic",
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
.probe = tps6507x_pmic_probe,
|
||||
.remove = __devexit_p(tps6507x_pmic_remove),
|
||||
.id_table = tps6507x_pmic_id,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -645,7 +639,7 @@ static struct i2c_driver tps6507x_i2c_driver = {
|
|||
*/
|
||||
static int __init tps6507x_pmic_init(void)
|
||||
{
|
||||
return i2c_add_driver(&tps6507x_i2c_driver);
|
||||
return platform_driver_register(&tps6507x_pmic_driver);
|
||||
}
|
||||
subsys_initcall(tps6507x_pmic_init);
|
||||
|
||||
|
@ -656,10 +650,11 @@ subsys_initcall(tps6507x_pmic_init);
|
|||
*/
|
||||
static void __exit tps6507x_pmic_cleanup(void)
|
||||
{
|
||||
i2c_del_driver(&tps6507x_i2c_driver);
|
||||
platform_driver_unregister(&tps6507x_pmic_driver);
|
||||
}
|
||||
module_exit(tps6507x_pmic_cleanup);
|
||||
|
||||
MODULE_AUTHOR("Texas Instruments");
|
||||
MODULE_DESCRIPTION("TPS6507x voltage regulator driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_ALIAS("platform:tps6507x-pmic");
|
||||
|
|
|
@ -131,6 +131,8 @@
|
|||
/* VDCDC MASK */
|
||||
#define TPS6507X_DEFDCDCX_DCDC_MASK 0X3F
|
||||
|
||||
#define TPS6507X_MAX_REGISTER 0X19
|
||||
|
||||
/**
|
||||
* struct tps6507x_board - packages regulator and touchscreen init data
|
||||
* @tps6507x_regulator_data: regulator initialization values
|
||||
|
@ -142,4 +144,24 @@ struct tps6507x_board {
|
|||
struct regulator_init_data *tps6507x_pmic_init_data;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct tps6507x_dev - tps6507x sub-driver chip access routines
|
||||
* @read_dev() - I2C register read function
|
||||
* @write_dev() - I2C register write function
|
||||
*
|
||||
* Device data may be used to access the TPS6507x chip
|
||||
*/
|
||||
|
||||
struct tps6507x_dev {
|
||||
struct device *dev;
|
||||
struct i2c_client *i2c_client;
|
||||
int (*read_dev)(struct tps6507x_dev *tps6507x, char reg, int size,
|
||||
void *dest);
|
||||
int (*write_dev)(struct tps6507x_dev *tps6507x, char reg, int size,
|
||||
void *src);
|
||||
|
||||
/* Client devices */
|
||||
struct tps6507x_pmic *pmic;
|
||||
};
|
||||
|
||||
#endif /* __LINUX_MFD_TPS6507X_H */
|
||||
|
|
Loading…
Reference in New Issue