rtc: rx8025: cleanup accessors

Remove useless error messages, at that point, the user already knows
something went wrong but will not be able to do anything about it anyway.
It is also highly unlikely that some registers are readable/writable
but not some other ones.

Also, transform rx8025_read_reg to be more resemblant to
i2c_smbus_read_byte_data()

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
This commit is contained in:
Alexandre Belloni 2015-08-04 00:40:25 +02:00
parent 6f0a8cfebb
commit fd9061fb49

View file

@ -75,65 +75,43 @@ struct rx8025_data {
u8 ctrl1; u8 ctrl1;
}; };
static int rx8025_read_reg(struct i2c_client *client, int number, u8 *value) static s32 rx8025_read_reg(const struct i2c_client *client, u8 number)
{ {
int ret = i2c_smbus_read_byte_data(client, number << 4); return i2c_smbus_read_byte_data(client, number << 4);
if (ret < 0) {
dev_err(&client->dev, "Unable to read register #%d\n", number);
return ret;
}
*value = ret;
return 0;
} }
static int rx8025_read_regs(struct i2c_client *client, static int rx8025_read_regs(const struct i2c_client *client,
int number, u8 length, u8 *values) u8 number, u8 length, u8 *values)
{ {
int ret = i2c_smbus_read_i2c_block_data(client, number << 4, int ret = i2c_smbus_read_i2c_block_data(client, number << 4, length,
length, values); values);
if (ret != length)
if (ret != length) {
dev_err(&client->dev, "Unable to read registers #%d..#%d\n",
number, number + length - 1);
return ret < 0 ? ret : -EIO; return ret < 0 ? ret : -EIO;
}
return 0; return 0;
} }
static int rx8025_write_reg(struct i2c_client *client, int number, u8 value) static s32 rx8025_write_reg(const struct i2c_client *client, u8 number,
u8 value)
{ {
int ret = i2c_smbus_write_byte_data(client, number << 4, value); return i2c_smbus_write_byte_data(client, number << 4, value);
if (ret)
dev_err(&client->dev, "Unable to write register #%d\n",
number);
return ret;
} }
static int rx8025_write_regs(struct i2c_client *client, static s32 rx8025_write_regs(const struct i2c_client *client,
int number, u8 length, u8 *values) u8 number, u8 length, const u8 *values)
{ {
int ret = i2c_smbus_write_i2c_block_data(client, number << 4, return i2c_smbus_write_i2c_block_data(client, number << 4,
length, values); length, values);
if (ret)
dev_err(&client->dev, "Unable to write registers #%d..#%d\n",
number, number + length - 1);
return ret;
} }
static irqreturn_t rx8025_handle_irq(int irq, void *dev_id) static irqreturn_t rx8025_handle_irq(int irq, void *dev_id)
{ {
struct i2c_client *client = dev_id; struct i2c_client *client = dev_id;
struct rx8025_data *rx8025 = i2c_get_clientdata(client); struct rx8025_data *rx8025 = i2c_get_clientdata(client);
u8 status; int status;
if (rx8025_read_reg(client, RX8025_REG_CTRL2, &status)) status = rx8025_read_reg(client, RX8025_REG_CTRL2);
if (status < 0)
goto out; goto out;
if (!(status & RX8025_BIT_CTRL2_XST)) if (!(status & RX8025_BIT_CTRL2_XST))
@ -166,12 +144,12 @@ out:
static int rx8025_get_time(struct device *dev, struct rtc_time *dt) static int rx8025_get_time(struct device *dev, struct rtc_time *dt)
{ {
struct rx8025_data *rx8025 = dev_get_drvdata(dev); struct rx8025_data *rx8025 = dev_get_drvdata(dev);
u8 date[7], ctrl; u8 date[7];
int err; int ctrl, err;
err = rx8025_read_reg(rx8025->client, RX8025_REG_CTRL2, &ctrl); ctrl = rx8025_read_reg(rx8025->client, RX8025_REG_CTRL2);
if (err) if (ctrl < 0)
return err; return ctrl;
if (ctrl & RX8025_BIT_CTRL2_PON) { if (ctrl & RX8025_BIT_CTRL2_PON) {
dev_warn(dev, "power-on reset detected, date is invalid\n"); dev_warn(dev, "power-on reset detected, date is invalid\n");
@ -302,8 +280,8 @@ static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)
{ {
struct rx8025_data *rx8025 = dev_get_drvdata(dev); struct rx8025_data *rx8025 = dev_get_drvdata(dev);
struct i2c_client *client = rx8025->client; struct i2c_client *client = rx8025->client;
u8 ctrl2, ald[2]; u8 ald[2];
int err; int ctrl2, err;
if (client->irq <= 0) if (client->irq <= 0)
return -EINVAL; return -EINVAL;
@ -312,9 +290,9 @@ static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)
if (err) if (err)
return err; return err;
err = rx8025_read_reg(client, RX8025_REG_CTRL2, &ctrl2); ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2);
if (err) if (ctrl2 < 0)
return err; return ctrl2;
dev_dbg(dev, "%s: read alarm 0x%02x 0x%02x ctrl2 %02x\n", dev_dbg(dev, "%s: read alarm 0x%02x 0x%02x ctrl2 %02x\n",
__func__, ald[0], ald[1], ctrl2); __func__, ald[0], ald[1], ctrl2);
@ -435,12 +413,11 @@ static struct rtc_class_ops rx8025_rtc_ops = {
static int rx8025_get_clock_adjust(struct device *dev, int *adj) static int rx8025_get_clock_adjust(struct device *dev, int *adj)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
u8 digoff; int digoff;
int err;
err = rx8025_read_reg(client, RX8025_REG_DIGOFF, &digoff); digoff = rx8025_read_reg(client, RX8025_REG_DIGOFF);
if (err) if (digoff < 0)
return err; return digoff;
*adj = digoff >= 64 ? digoff - 128 : digoff; *adj = digoff >= 64 ? digoff - 128 : digoff;
if (*adj > 0) if (*adj > 0)