aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/max8998.c
diff options
context:
space:
mode:
authorJoonyoung Shim <jy0922.shim@samsung.com>2010-08-05 22:28:06 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2010-10-28 18:29:02 -0400
commit676e02d7a2ed9bb02994670a07df533a29a99de6 (patch)
treef429e20f654790895b44aca9193b6082da2a9669 /drivers/mfd/max8998.c
parent1203a1e6424d502e9c12d29512218487af5fdd1c (diff)
mfd: Use i2c_client as an argument on MAX8998 i2c routines
The MAX8998 chip have regulator and rtc features. The i2c slave address of regulator and rtc is different, so needs each i2c client on i2c operation functions. Also, this patch exports i2c operation functions instead of callback to make easy to read. Signed-off-by: Joonyoung Shim <jy0922.shim@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd/max8998.c')
-rw-r--r--drivers/mfd/max8998.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/drivers/mfd/max8998.c b/drivers/mfd/max8998.c
index f1c928915880..3b8a5076d351 100644
--- a/drivers/mfd/max8998.c
+++ b/drivers/mfd/max8998.c
@@ -36,13 +36,13 @@ static struct mfd_cell max8998_devs[] = {
36 } 36 }
37}; 37};
38 38
39static int max8998_i2c_device_read(struct max8998_dev *max8998, u8 reg, u8 *dest) 39int max8998_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest)
40{ 40{
41 struct i2c_client *client = max8998->i2c_client; 41 struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
42 int ret; 42 int ret;
43 43
44 mutex_lock(&max8998->iolock); 44 mutex_lock(&max8998->iolock);
45 ret = i2c_smbus_read_byte_data(client, reg); 45 ret = i2c_smbus_read_byte_data(i2c, reg);
46 mutex_unlock(&max8998->iolock); 46 mutex_unlock(&max8998->iolock);
47 if (ret < 0) 47 if (ret < 0)
48 return ret; 48 return ret;
@@ -51,36 +51,38 @@ static int max8998_i2c_device_read(struct max8998_dev *max8998, u8 reg, u8 *dest
51 *dest = ret; 51 *dest = ret;
52 return 0; 52 return 0;
53} 53}
54EXPORT_SYMBOL(max8998_read_reg);
54 55
55static int max8998_i2c_device_write(struct max8998_dev *max8998, u8 reg, u8 value) 56int max8998_write_reg(struct i2c_client *i2c, u8 reg, u8 value)
56{ 57{
57 struct i2c_client *client = max8998->i2c_client; 58 struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
58 int ret; 59 int ret;
59 60
60 mutex_lock(&max8998->iolock); 61 mutex_lock(&max8998->iolock);
61 ret = i2c_smbus_write_byte_data(client, reg, value); 62 ret = i2c_smbus_write_byte_data(i2c, reg, value);
62 mutex_unlock(&max8998->iolock); 63 mutex_unlock(&max8998->iolock);
63 return ret; 64 return ret;
64} 65}
66EXPORT_SYMBOL(max8998_write_reg);
65 67
66static int max8998_i2c_device_update(struct max8998_dev *max8998, u8 reg, 68int max8998_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask)
67 u8 val, u8 mask)
68{ 69{
69 struct i2c_client *client = max8998->i2c_client; 70 struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
70 int ret; 71 int ret;
71 72
72 mutex_lock(&max8998->iolock); 73 mutex_lock(&max8998->iolock);
73 ret = i2c_smbus_read_byte_data(client, reg); 74 ret = i2c_smbus_read_byte_data(i2c, reg);
74 if (ret >= 0) { 75 if (ret >= 0) {
75 u8 old_val = ret & 0xff; 76 u8 old_val = ret & 0xff;
76 u8 new_val = (val & mask) | (old_val & (~mask)); 77 u8 new_val = (val & mask) | (old_val & (~mask));
77 ret = i2c_smbus_write_byte_data(client, reg, new_val); 78 ret = i2c_smbus_write_byte_data(i2c, reg, new_val);
78 if (ret >= 0) 79 if (ret >= 0)
79 ret = 0; 80 ret = 0;
80 } 81 }
81 mutex_unlock(&max8998->iolock); 82 mutex_unlock(&max8998->iolock);
82 return ret; 83 return ret;
83} 84}
85EXPORT_SYMBOL(max8998_update_reg);
84 86
85static int max8998_i2c_probe(struct i2c_client *i2c, 87static int max8998_i2c_probe(struct i2c_client *i2c,
86 const struct i2c_device_id *id) 88 const struct i2c_device_id *id)
@@ -94,10 +96,7 @@ static int max8998_i2c_probe(struct i2c_client *i2c,
94 96
95 i2c_set_clientdata(i2c, max8998); 97 i2c_set_clientdata(i2c, max8998);
96 max8998->dev = &i2c->dev; 98 max8998->dev = &i2c->dev;
97 max8998->i2c_client = i2c; 99 max8998->i2c = i2c;
98 max8998->dev_read = max8998_i2c_device_read;
99 max8998->dev_write = max8998_i2c_device_write;
100 max8998->dev_update = max8998_i2c_device_update;
101 mutex_init(&max8998->iolock); 100 mutex_init(&max8998->iolock);
102 101
103 ret = mfd_add_devices(max8998->dev, -1, 102 ret = mfd_add_devices(max8998->dev, -1,