提交 13f2483c 编写于 作者: A Axel Lin 提交者: Anton Vorontsov

ds2781_battery: Use DS2781_PARAM_EEPROM_SIZE and DS2781_USER_EEPROM_SIZE

Since we have defined DS2781_PARAM_EEPROM_SIZE and
DS2781_USER_EEPROM_SIZE, use them to simplify the code.
Signed-off-by: NAxel Lin <axel.lin@gmail.com>
Acked-by: NEvgeniy Polyakov <zbr@ioremap.net>
Signed-off-by: NAnton Vorontsov <anton.vorontsov@linaro.org>
上级 840b91bd
...@@ -643,9 +643,7 @@ static ssize_t ds2781_read_param_eeprom_bin(struct file *filp, ...@@ -643,9 +643,7 @@ static ssize_t ds2781_read_param_eeprom_bin(struct file *filp,
struct power_supply *psy = to_power_supply(dev); struct power_supply *psy = to_power_supply(dev);
struct ds2781_device_info *dev_info = to_ds2781_device_info(psy); struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
count = min_t(loff_t, count, count = min_t(loff_t, count, DS2781_PARAM_EEPROM_SIZE - off);
DS2781_EEPROM_BLOCK1_END -
DS2781_EEPROM_BLOCK1_START + 1 - off);
return ds2781_read_block(dev_info, buf, return ds2781_read_block(dev_info, buf,
DS2781_EEPROM_BLOCK1_START + off, count); DS2781_EEPROM_BLOCK1_START + off, count);
...@@ -661,9 +659,7 @@ static ssize_t ds2781_write_param_eeprom_bin(struct file *filp, ...@@ -661,9 +659,7 @@ static ssize_t ds2781_write_param_eeprom_bin(struct file *filp,
struct ds2781_device_info *dev_info = to_ds2781_device_info(psy); struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
int ret; int ret;
count = min_t(loff_t, count, count = min_t(loff_t, count, DS2781_PARAM_EEPROM_SIZE - off);
DS2781_EEPROM_BLOCK1_END -
DS2781_EEPROM_BLOCK1_START + 1 - off);
ret = ds2781_write(dev_info, buf, ret = ds2781_write(dev_info, buf,
DS2781_EEPROM_BLOCK1_START + off, count); DS2781_EEPROM_BLOCK1_START + off, count);
...@@ -682,7 +678,7 @@ static struct bin_attribute ds2781_param_eeprom_bin_attr = { ...@@ -682,7 +678,7 @@ static struct bin_attribute ds2781_param_eeprom_bin_attr = {
.name = "param_eeprom", .name = "param_eeprom",
.mode = S_IRUGO | S_IWUSR, .mode = S_IRUGO | S_IWUSR,
}, },
.size = DS2781_EEPROM_BLOCK1_END - DS2781_EEPROM_BLOCK1_START + 1, .size = DS2781_PARAM_EEPROM_SIZE,
.read = ds2781_read_param_eeprom_bin, .read = ds2781_read_param_eeprom_bin,
.write = ds2781_write_param_eeprom_bin, .write = ds2781_write_param_eeprom_bin,
}; };
...@@ -696,9 +692,7 @@ static ssize_t ds2781_read_user_eeprom_bin(struct file *filp, ...@@ -696,9 +692,7 @@ static ssize_t ds2781_read_user_eeprom_bin(struct file *filp,
struct power_supply *psy = to_power_supply(dev); struct power_supply *psy = to_power_supply(dev);
struct ds2781_device_info *dev_info = to_ds2781_device_info(psy); struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
count = min_t(loff_t, count, count = min_t(loff_t, count, DS2781_USER_EEPROM_SIZE - off);
DS2781_EEPROM_BLOCK0_END -
DS2781_EEPROM_BLOCK0_START + 1 - off);
return ds2781_read_block(dev_info, buf, return ds2781_read_block(dev_info, buf,
DS2781_EEPROM_BLOCK0_START + off, count); DS2781_EEPROM_BLOCK0_START + off, count);
...@@ -715,9 +709,7 @@ static ssize_t ds2781_write_user_eeprom_bin(struct file *filp, ...@@ -715,9 +709,7 @@ static ssize_t ds2781_write_user_eeprom_bin(struct file *filp,
struct ds2781_device_info *dev_info = to_ds2781_device_info(psy); struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
int ret; int ret;
count = min_t(loff_t, count, count = min_t(loff_t, count, DS2781_USER_EEPROM_SIZE - off);
DS2781_EEPROM_BLOCK0_END -
DS2781_EEPROM_BLOCK0_START + 1 - off);
ret = ds2781_write(dev_info, buf, ret = ds2781_write(dev_info, buf,
DS2781_EEPROM_BLOCK0_START + off, count); DS2781_EEPROM_BLOCK0_START + off, count);
...@@ -736,7 +728,7 @@ static struct bin_attribute ds2781_user_eeprom_bin_attr = { ...@@ -736,7 +728,7 @@ static struct bin_attribute ds2781_user_eeprom_bin_attr = {
.name = "user_eeprom", .name = "user_eeprom",
.mode = S_IRUGO | S_IWUSR, .mode = S_IRUGO | S_IWUSR,
}, },
.size = DS2781_EEPROM_BLOCK0_END - DS2781_EEPROM_BLOCK0_START + 1, .size = DS2781_USER_EEPROM_SIZE,
.read = ds2781_read_user_eeprom_bin, .read = ds2781_read_user_eeprom_bin,
.write = ds2781_write_user_eeprom_bin, .write = ds2781_write_user_eeprom_bin,
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册