Commit e1d26a7642253a4b745a69c5faef494dd0b5c01a

Authored by Ian Ray
Committed by Tom Rini
1 parent 2d7818d04f

rtc: s35392a: encode command correctly

The 3-bit "command", or register, is encoded within the device address.
Configure the device accordingly, and pass command in DM I2C read/write
calls correctly.

Signed-off-by: Ian Ray <ian.ray@ge.com>
Signed-off-by: Robert Beckett <bob.beckett@collabora.com>

Showing 1 changed file with 18 additions and 11 deletions Side-by-side Diff

drivers/rtc/s35392a.c
... ... @@ -24,12 +24,14 @@
24 24 #include <linux/bitrev.h>
25 25 #include <rtc.h>
26 26  
27   -#define S35390A_CMD_STATUS1 0x30
28   -#define S35390A_CMD_STATUS2 0x31
29   -#define S35390A_CMD_TIME1 0x32
30   -#define S35390A_CMD_TIME2 0x33
31   -#define S35390A_CMD_INT2_REG1 0x35
  27 +#define S35390A_CHIP_ADDR 0x30
32 28  
  29 +#define S35390A_CMD_STATUS1 0x0
  30 +#define S35390A_CMD_STATUS2 0x1
  31 +#define S35390A_CMD_TIME1 0x2
  32 +#define S35390A_CMD_TIME2 0x3
  33 +#define S35390A_CMD_INT2_REG1 0x5
  34 +
33 35 #define S35390A_BYTE_YEAR 0
34 36 #define S35390A_BYTE_MONTH 1
35 37 #define S35390A_BYTE_DAY 2
36 38  
... ... @@ -85,11 +87,10 @@
85 87 int ret;
86 88  
87 89 #ifdef CONFIG_DM_RTC
88   - /* TODO: we need to tweak the chip address to reg */
89   - ret = dm_i2c_read(dev, 0, buf, len);
  90 + ret = dm_i2c_read(dev, reg, buf, len);
90 91 #else
91 92 (void)dev;
92   - ret = i2c_read(reg, 0, -1, buf, len);
  93 + ret = i2c_read(S35390A_CHIP_ADDR | reg, 0, -1, buf, len);
93 94 #endif
94 95  
95 96 return ret;
96 97  
... ... @@ -100,11 +101,10 @@
100 101 int ret;
101 102  
102 103 #ifdef CONFIG_DM_RTC
103   - /* TODO: we need to tweak the chip address to reg */
104   - ret = dm_i2c_write(dev, 0, buf, 1);
  104 + ret = dm_i2c_write(dev, reg, buf, len);
105 105 #else
106 106 (void)dev;
107   - ret = i2c_write(reg, 0, 0, buf, len);
  107 + ret = i2c_write(S35390A_CHIP_ADDR | reg, 0, 0, buf, len);
108 108 #endif
109 109  
110 110 return ret;
... ... @@ -336,6 +336,13 @@
336 336  
337 337 static int s35392a_probe(struct udevice *dev)
338 338 {
  339 +#if defined(CONFIG_DM_RTC)
  340 + /* 3-bit "command", or register, is encoded within the device address.
  341 + */
  342 + i2c_set_chip_offset_len(dev, 0);
  343 + i2c_set_chip_addr_offset_mask(dev, 0x7);
  344 +#endif
  345 +
339 346 s35392a_rtc_init(dev);
340 347 return 0;
341 348 }