diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/rtc/rtc_mr100.c | 68 |
1 files changed, 53 insertions, 15 deletions
diff --git a/firmware/drivers/rtc/rtc_mr100.c b/firmware/drivers/rtc/rtc_mr100.c index 96d84156a7..5bb6afee0c 100644 --- a/firmware/drivers/rtc/rtc_mr100.c +++ b/firmware/drivers/rtc/rtc_mr100.c | |||
@@ -40,30 +40,30 @@ static void reverse_bits(unsigned char* v, int size) { | |||
40 | 40 | ||
41 | for(j=0; j<size; j++) { | 41 | for(j=0; j<size; j++) { |
42 | in = v[j]; | 42 | in = v[j]; |
43 | for(i=0; i<8; i++) { | 43 | out = in; |
44 | out |= (in & 1); | 44 | for(i=0; i<7; i++) { |
45 | in = in >>1; | 45 | in = in >>1; |
46 | out = out<<1; | 46 | out = out<<1; |
47 | out |= (in & 1); | ||
47 | } | 48 | } |
48 | v[j] = out>>1; | 49 | v[j] = out; |
49 | } | 50 | } |
50 | } | 51 | } |
51 | 52 | ||
52 | static int sw_i2c(int access, unsigned char chip, unsigned char cmd, | 53 | static int sw_i2c(int access, int cmd, unsigned char* buf, int count) { |
53 | unsigned char* buf, int count) { | 54 | int i, addr; |
54 | int i; | ||
55 | 55 | ||
56 | i2c_lock(); | 56 | i2c_lock(); |
57 | GPIOC_ENABLE |= 0x00000030; | 57 | GPIOC_ENABLE |= 0x00000030; |
58 | 58 | ||
59 | chip|=cmd<<1; | 59 | addr = RTC_ADDR | (cmd<<1); |
60 | 60 | ||
61 | if(access == SW_I2C_READ) { | 61 | if(access == SW_I2C_READ) { |
62 | i = sw_i2c_read(chip, 0, buf, count); | 62 | i = sw_i2c_read(addr, 0, buf, count); |
63 | reverse_bits(buf, count); | 63 | reverse_bits(buf, count); |
64 | } else { | 64 | } else { |
65 | reverse_bits(buf, count); | 65 | reverse_bits(buf, count); |
66 | i = sw_i2c_write(chip, 0, buf, count); | 66 | i = sw_i2c_write(addr, 0, buf, count); |
67 | } | 67 | } |
68 | 68 | ||
69 | GPIOC_ENABLE &= ~0x00000030; | 69 | GPIOC_ENABLE &= ~0x00000030; |
@@ -77,11 +77,49 @@ static int sw_i2c(int access, unsigned char chip, unsigned char cmd, | |||
77 | void rtc_init(void) | 77 | void rtc_init(void) |
78 | { | 78 | { |
79 | sw_i2c_init(); | 79 | sw_i2c_init(); |
80 | |||
81 | #if 0 | ||
82 | /* init sequence from OF for reference */ | ||
83 | /* currently we rely on the bootloader doing it for us */ | ||
84 | |||
85 | bool flag = true; | ||
86 | unsigned char data; | ||
87 | unsigned char v[7] = {0x00,0x47,0x17,0x06,0x03,0x02,0x08}; /* random time */ | ||
88 | |||
89 | if(flag) { | ||
90 | |||
91 | GPIOB_ENABLE |= 0x80; | ||
92 | GPIOB_OUTPUT_EN |= 0x80; | ||
93 | GPIOB_OUTPUT_VAL &= ~0x80; | ||
94 | |||
95 | DEV_EN |= 0x1000; | ||
96 | /* some more stuff that is not clear */ | ||
97 | |||
98 | sw_i2c(SW_I2C_READ, RTC_CMD_CTRL, &data, 1); | ||
99 | if((data<<0x18)>>0x1e) { /* bit 7 & 6 */ | ||
100 | |||
101 | data = 1; | ||
102 | sw_i2c(SW_I2C_WRITE, RTC_CMD_CTRL, &data, 1); | ||
103 | |||
104 | data = 1; | ||
105 | sw_i2c(SW_I2C_WRITE, RTC_CMD_CTRL, &data, 1); | ||
106 | |||
107 | data = 8; | ||
108 | sw_i2c(SW_I2C_WRITE, RTC_CMD_UNKN, &data, 1); | ||
109 | |||
110 | /* more stuff, perhaps set up time array? */ | ||
111 | |||
112 | rtc_write_datetime(v); | ||
113 | |||
114 | } | ||
115 | data = 2; | ||
116 | sw_i2c(SW_I2C_WRITE, RTC_CMD_CTRL, &data, 1); | ||
117 | |||
118 | } | ||
119 | data = 2; | ||
120 | sw_i2c(SW_I2C_WRITE, RTC_CMD_CTRL, &data, 1); | ||
121 | #endif | ||
80 | 122 | ||
81 | /* to set a time while buttons are stil not working | ||
82 | unsigned char v[7] = {0x00,0x47,0x17,0x06,0x03,0x02,0x08}; | ||
83 | rtc_write_datetime(v); | ||
84 | */ | ||
85 | } | 123 | } |
86 | 124 | ||
87 | int rtc_read_datetime(unsigned char* buf) | 125 | int rtc_read_datetime(unsigned char* buf) |
@@ -89,7 +127,7 @@ int rtc_read_datetime(unsigned char* buf) | |||
89 | int i; | 127 | int i; |
90 | unsigned char v[7]; | 128 | unsigned char v[7]; |
91 | 129 | ||
92 | i = sw_i2c(SW_I2C_READ, RTC_ADDR, RTC_CMD_DATA, v, 7); | 130 | i = sw_i2c(SW_I2C_READ, RTC_CMD_DATA, v, 7); |
93 | 131 | ||
94 | v[4] &= 0x3f; /* mask out p.m. flag */ | 132 | v[4] &= 0x3f; /* mask out p.m. flag */ |
95 | 133 | ||
@@ -107,7 +145,7 @@ int rtc_write_datetime(unsigned char* buf) | |||
107 | for(i=0; i<7; i++) | 145 | for(i=0; i<7; i++) |
108 | v[i]=buf[6-i]; | 146 | v[i]=buf[6-i]; |
109 | 147 | ||
110 | i = sw_i2c(SW_I2C_WRITE, RTC_ADDR, RTC_CMD_DATA, v, 7); | 148 | i = sw_i2c(SW_I2C_WRITE, RTC_CMD_DATA, v, 7); |
111 | 149 | ||
112 | return i; | 150 | return i; |
113 | } | 151 | } |