提交 2473d25a 编写于 作者: P Peter Ujfalusi 提交者: Samuel Ortiz

mfd: twl-core: Convert to use regmap for I/O

Remove the custom code to do I/O and replace it with standard regmap calls.
Reviewed-by: NMark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: NTero Kristo <t-kristo@ti.com>
Signed-off-by: NPeter Ujfalusi <peter.ujfalusi@ti.com>
Signed-off-by: NSamuel Ortiz <sameo@linux.intel.com>
上级 afc45898
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/device.h> #include <linux/device.h>
...@@ -171,13 +172,7 @@ EXPORT_SYMBOL(twl_rev); ...@@ -171,13 +172,7 @@ EXPORT_SYMBOL(twl_rev);
/* Structure for each TWL4030/TWL6030 Slave */ /* Structure for each TWL4030/TWL6030 Slave */
struct twl_client { struct twl_client {
struct i2c_client *client; struct i2c_client *client;
u8 address; struct regmap *regmap;
/* max numb of i2c_msg required is for read =2 */
struct i2c_msg xfer_msg[2];
/* To lock access to xfer_msg */
struct mutex xfer_lock;
}; };
static struct twl_client twl_modules[TWL_NUM_SLAVES]; static struct twl_client twl_modules[TWL_NUM_SLAVES];
...@@ -225,6 +220,33 @@ static struct twl_mapping twl4030_map[TWL4030_MODULE_LAST + 1] = { ...@@ -225,6 +220,33 @@ static struct twl_mapping twl4030_map[TWL4030_MODULE_LAST + 1] = {
{ 3, TWL4030_BASEADD_SECURED_REG }, { 3, TWL4030_BASEADD_SECURED_REG },
}; };
static struct regmap_config twl4030_regmap_config[4] = {
{
/* Address 0x48 */
.reg_bits = 8,
.val_bits = 8,
.max_register = 0xff,
},
{
/* Address 0x49 */
.reg_bits = 8,
.val_bits = 8,
.max_register = 0xff,
},
{
/* Address 0x4a */
.reg_bits = 8,
.val_bits = 8,
.max_register = 0xff,
},
{
/* Address 0x4b */
.reg_bits = 8,
.val_bits = 8,
.max_register = 0xff,
},
};
static struct twl_mapping twl6030_map[] = { static struct twl_mapping twl6030_map[] = {
/* /*
* NOTE: don't change this table without updating the * NOTE: don't change this table without updating the
...@@ -262,6 +284,27 @@ static struct twl_mapping twl6030_map[] = { ...@@ -262,6 +284,27 @@ static struct twl_mapping twl6030_map[] = {
{ SUB_CHIP_ID1, TWL6025_BASEADD_CHARGER }, { SUB_CHIP_ID1, TWL6025_BASEADD_CHARGER },
}; };
static struct regmap_config twl6030_regmap_config[3] = {
{
/* Address 0x48 */
.reg_bits = 8,
.val_bits = 8,
.max_register = 0xff,
},
{
/* Address 0x49 */
.reg_bits = 8,
.val_bits = 8,
.max_register = 0xff,
},
{
/* Address 0x4a */
.reg_bits = 8,
.val_bits = 8,
.max_register = 0xff,
},
};
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
/* Exported Functions */ /* Exported Functions */
...@@ -283,7 +326,6 @@ int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) ...@@ -283,7 +326,6 @@ int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
int ret; int ret;
int sid; int sid;
struct twl_client *twl; struct twl_client *twl;
struct i2c_msg *msg;
if (unlikely(mod_no > TWL_MODULE_LAST)) { if (unlikely(mod_no > TWL_MODULE_LAST)) {
pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
...@@ -301,32 +343,14 @@ int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) ...@@ -301,32 +343,14 @@ int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
} }
twl = &twl_modules[sid]; twl = &twl_modules[sid];
mutex_lock(&twl->xfer_lock); ret = regmap_bulk_write(twl->regmap, twl_map[mod_no].base + reg,
/* &value[1], num_bytes);
* [MSG1]: fill the register address data
* fill the data Tx buffer if (ret)
*/ pr_err("%s: Write failed (mod %d, reg 0x%02x count %d)\n",
msg = &twl->xfer_msg[0]; DRIVER_NAME, mod_no, reg, num_bytes);
msg->addr = twl->address;
msg->len = num_bytes + 1; return ret;
msg->flags = 0;
msg->buf = value;
/* over write the first byte of buffer with the register address */
*value = twl_map[mod_no].base + reg;
ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 1);
mutex_unlock(&twl->xfer_lock);
/* i2c_transfer returns number of messages transferred */
if (ret != 1) {
pr_err("%s: i2c_write failed to transfer all messages\n",
DRIVER_NAME);
if (ret < 0)
return ret;
else
return -EIO;
} else {
return 0;
}
} }
EXPORT_SYMBOL(twl_i2c_write); EXPORT_SYMBOL(twl_i2c_write);
...@@ -342,10 +366,8 @@ EXPORT_SYMBOL(twl_i2c_write); ...@@ -342,10 +366,8 @@ EXPORT_SYMBOL(twl_i2c_write);
int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
{ {
int ret; int ret;
u8 val;
int sid; int sid;
struct twl_client *twl; struct twl_client *twl;
struct i2c_msg *msg;
if (unlikely(mod_no > TWL_MODULE_LAST)) { if (unlikely(mod_no > TWL_MODULE_LAST)) {
pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
...@@ -363,34 +385,14 @@ int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) ...@@ -363,34 +385,14 @@ int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
} }
twl = &twl_modules[sid]; twl = &twl_modules[sid];
mutex_lock(&twl->xfer_lock); ret = regmap_bulk_read(twl->regmap, twl_map[mod_no].base + reg,
/* [MSG1] fill the register address data */ value, num_bytes);
msg = &twl->xfer_msg[0];
msg->addr = twl->address; if (ret)
msg->len = 1; pr_err("%s: Read failed (mod %d, reg 0x%02x count %d)\n",
msg->flags = 0; /* Read the register value */ DRIVER_NAME, mod_no, reg, num_bytes);
val = twl_map[mod_no].base + reg;
msg->buf = &val; return ret;
/* [MSG2] fill the data rx buffer */
msg = &twl->xfer_msg[1];
msg->addr = twl->address;
msg->flags = I2C_M_RD; /* Read the register value */
msg->len = num_bytes; /* only n bytes */
msg->buf = value;
ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 2);
mutex_unlock(&twl->xfer_lock);
/* i2c_transfer returns number of messages transferred */
if (ret != 2) {
pr_err("%s: i2c_read failed to transfer all messages\n",
DRIVER_NAME);
if (ret < 0)
return ret;
else
return -EIO;
} else {
return 0;
}
} }
EXPORT_SYMBOL(twl_i2c_read); EXPORT_SYMBOL(twl_i2c_read);
...@@ -1184,6 +1186,7 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -1184,6 +1186,7 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
struct twl4030_platform_data *pdata = client->dev.platform_data; struct twl4030_platform_data *pdata = client->dev.platform_data;
struct device_node *node = client->dev.of_node; struct device_node *node = client->dev.of_node;
struct platform_device *pdev; struct platform_device *pdev;
struct regmap_config *twl_regmap_config;
int irq_base = 0; int irq_base = 0;
int status; int status;
unsigned i, num_slaves; unsigned i, num_slaves;
...@@ -1237,22 +1240,23 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -1237,22 +1240,23 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
if ((id->driver_data) & TWL6030_CLASS) { if ((id->driver_data) & TWL6030_CLASS) {
twl_id = TWL6030_CLASS_ID; twl_id = TWL6030_CLASS_ID;
twl_map = &twl6030_map[0]; twl_map = &twl6030_map[0];
twl_regmap_config = twl6030_regmap_config;
num_slaves = TWL_NUM_SLAVES - 1; num_slaves = TWL_NUM_SLAVES - 1;
} else { } else {
twl_id = TWL4030_CLASS_ID; twl_id = TWL4030_CLASS_ID;
twl_map = &twl4030_map[0]; twl_map = &twl4030_map[0];
twl_regmap_config = twl4030_regmap_config;
num_slaves = TWL_NUM_SLAVES; num_slaves = TWL_NUM_SLAVES;
} }
for (i = 0; i < num_slaves; i++) { for (i = 0; i < num_slaves; i++) {
struct twl_client *twl = &twl_modules[i]; struct twl_client *twl = &twl_modules[i];
twl->address = client->addr + i;
if (i == 0) { if (i == 0) {
twl->client = client; twl->client = client;
} else { } else {
twl->client = i2c_new_dummy(client->adapter, twl->client = i2c_new_dummy(client->adapter,
twl->address); client->addr + i);
if (!twl->client) { if (!twl->client) {
dev_err(&client->dev, dev_err(&client->dev,
"can't attach client %d\n", i); "can't attach client %d\n", i);
...@@ -1260,7 +1264,16 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -1260,7 +1264,16 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
goto fail; goto fail;
} }
} }
mutex_init(&twl->xfer_lock);
twl->regmap = devm_regmap_init_i2c(twl->client,
&twl_regmap_config[i]);
if (IS_ERR(twl->regmap)) {
status = PTR_ERR(twl->regmap);
dev_err(&client->dev,
"Failed to allocate regmap %d, err: %d\n", i,
status);
goto fail;
}
} }
inuse = true; inuse = true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册