Skip to content

Commit b13c0df

Browse files
Haojian ZhuangSamuel Ortiz
authored andcommitted
mfd: Update i2c driver for max8925
Update I2C driver in order to fit all of three I2C components in max8925. Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 1ea933f commit b13c0df

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

drivers/mfd/max8925-i2c.c

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,23 @@
1414
#include <linux/i2c.h>
1515
#include <linux/mfd/max8925.h>
1616

17+
#define RTC_I2C_ADDR 0x68
18+
#define ADC_I2C_ADDR 0x47
19+
1720
static inline int max8925_read_device(struct i2c_client *i2c,
1821
int reg, int bytes, void *dest)
1922
{
20-
unsigned char data;
21-
unsigned char *buf;
2223
int ret;
2324

24-
buf = kzalloc(bytes + 1, GFP_KERNEL);
25-
if (!buf)
26-
return -ENOMEM;
27-
28-
data = (unsigned char)reg;
29-
ret = i2c_master_send(i2c, &data, 1);
30-
if (ret < 0)
31-
return ret;
32-
33-
ret = i2c_master_recv(i2c, buf, bytes + 1);
34-
if (ret < 0)
35-
return ret;
36-
memcpy(dest, buf, bytes);
37-
return 0;
25+
if (bytes > 1)
26+
ret = i2c_smbus_read_i2c_block_data(i2c, reg, bytes, dest);
27+
else {
28+
ret = i2c_smbus_read_byte_data(i2c, reg);
29+
if (ret < 0)
30+
return ret;
31+
*(unsigned char *)dest = (unsigned char)ret;
32+
}
33+
return ret;
3834
}
3935

4036
static inline int max8925_write_device(struct i2c_client *i2c,
@@ -55,7 +51,7 @@ static inline int max8925_write_device(struct i2c_client *i2c,
5551
int max8925_reg_read(struct i2c_client *i2c, int reg)
5652
{
5753
struct max8925_chip *chip = i2c_get_clientdata(i2c);
58-
unsigned char data;
54+
unsigned char data = 0;
5955
int ret;
6056

6157
mutex_lock(&chip->io_lock);
@@ -134,35 +130,36 @@ EXPORT_SYMBOL(max8925_set_bits);
134130

135131
static const struct i2c_device_id max8925_id_table[] = {
136132
{ "max8925", 0 },
137-
{}
133+
{ },
138134
};
139135
MODULE_DEVICE_TABLE(i2c, max8925_id_table);
140136

141137
static int __devinit max8925_probe(struct i2c_client *client,
142138
const struct i2c_device_id *id)
143139
{
144140
struct max8925_platform_data *pdata = client->dev.platform_data;
145-
struct max8925_chip *chip;
141+
static struct max8925_chip *chip;
146142

147143
if (!pdata) {
148144
pr_info("%s: platform data is missing\n", __func__);
149145
return -EINVAL;
150146
}
151-
if ((pdata->chip_id <= MAX8925_INVALID)
152-
|| (pdata->chip_id >= MAX8925_MAX)) {
153-
pr_info("#%s: wrong chip identification\n", __func__);
154-
return -EINVAL;
155-
}
156147

157148
chip = kzalloc(sizeof(struct max8925_chip), GFP_KERNEL);
158149
if (chip == NULL)
159150
return -ENOMEM;
160151
chip->i2c = client;
161-
chip->chip_id = pdata->chip_id;
162-
i2c_set_clientdata(client, chip);
163152
chip->dev = &client->dev;
164-
mutex_init(&chip->io_lock);
153+
i2c_set_clientdata(client, chip);
165154
dev_set_drvdata(chip->dev, chip);
155+
mutex_init(&chip->io_lock);
156+
157+
chip->rtc = i2c_new_dummy(chip->i2c->adapter, RTC_I2C_ADDR);
158+
i2c_set_clientdata(chip->rtc, chip);
159+
160+
chip->adc = i2c_new_dummy(chip->i2c->adapter, ADC_I2C_ADDR);
161+
i2c_set_clientdata(chip->adc, chip);
162+
166163
max8925_device_init(chip, pdata);
167164

168165
return 0;
@@ -173,7 +170,11 @@ static int __devexit max8925_remove(struct i2c_client *client)
173170
struct max8925_chip *chip = i2c_get_clientdata(client);
174171

175172
max8925_device_exit(chip);
176-
i2c_set_clientdata(client, NULL);
173+
i2c_unregister_device(chip->adc);
174+
i2c_unregister_device(chip->rtc);
175+
i2c_set_clientdata(chip->adc, NULL);
176+
i2c_set_clientdata(chip->rtc, NULL);
177+
i2c_set_clientdata(chip->i2c, NULL);
177178
kfree(chip);
178179
return 0;
179180
}

0 commit comments

Comments
 (0)