* Board-specific RTC write * Time returned is in seconds from epoch (Jan 1 1970 at 00:00:00 UTC) */
| 148 | * Time returned is in seconds from epoch (Jan 1 1970 at 00:00:00 UTC) |
| 149 | */ |
| 150 | int cvmx_rtc_ds1337_write(uint32_t time) |
| 151 | { |
| 152 | struct clocktime ct; |
| 153 | struct timespec ts; |
| 154 | int i, rc, retry; |
| 155 | uint8_t reg[8]; |
| 156 | uint8_t sec; |
| 157 | |
| 158 | ts.tv_sec = time; |
| 159 | ts.tv_nsec = 0; |
| 160 | |
| 161 | clock_ts_to_ct(&ts, &ct); |
| 162 | |
| 163 | if (validate_ct_struct(&ct)) |
| 164 | { |
| 165 | cvmx_dprintf("Error: RTC was passed wrong calendar values, write failed\n"); |
| 166 | goto ct_invalid; |
| 167 | } |
| 168 | |
| 169 | reg[0] = bin2bcd(ct.sec); |
| 170 | reg[1] = bin2bcd(ct.min); |
| 171 | reg[2] = bin2bcd(ct.hour); /* Force 0..23 format even if using AM/PM */ |
| 172 | reg[3] = bin2bcd(ct.dow + 1); |
| 173 | reg[4] = bin2bcd(ct.day); |
| 174 | reg[5] = bin2bcd(ct.mon); |
| 175 | #if !defined(OCTEON_BOARD_CAPK_0100ND) |
| 176 | if (ct.year >= 2000) /* Set century bit*/ |
| 177 | { |
| 178 | reg[5] |= 0x80; |
| 179 | } |
| 180 | #endif |
| 181 | reg[6] = bin2bcd(ct.year % 100); |
| 182 | |
| 183 | /* Lockless write: detects the infrequent roll-over and retries */ |
| 184 | for(retry=0; retry<2; retry++) |
| 185 | { |
| 186 | rc = 0; |
| 187 | for(i=0; i<7; i++) |
| 188 | { |
| 189 | rc |= cvmx_twsi_write8(CVMX_RTC_DS1337_ADDR, i, reg[i]); |
| 190 | } |
| 191 | |
| 192 | sec = cvmx_twsi_read8(CVMX_RTC_DS1337_ADDR, 0x0); |
| 193 | if ((sec & 0xf) == (reg[0] & 0xf)) |
| 194 | break; /* Time did not roll-over, value is correct */ |
| 195 | } |
| 196 | |
| 197 | return (rc ? -1 : 0); |
| 198 | |
| 199 | ct_invalid: |
| 200 | return -1; |
| 201 | } |
| 202 | |
| 203 | #ifdef CVMX_RTC_DEBUG |
| 204 |
nothing calls this directly
no test coverage detected