| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include <string.h> |
| 9 |
#include <assert.h> |
| 10 |
#include <device/i2c.h> |
| 11 |
#include <device/i2c_simple.h> |
| 12 |
#include <endian.h> |
| 13 |
#include <soc/timer.h> |
| 14 |
|
| 15 |
|
| 16 |
#include <libbdk-arch/bdk-numa.h> |
| 17 |
#include <libbdk-hal/bdk-config.h> |
| 18 |
#include <libbdk-hal/bdk-twsi.h> |
| 19 |
#include <libbdk-boot/bdk-watchdog.h> |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
int64_t bdk_twsix_read_ia(bdk_node_t node, int twsi_id, uint8_t dev_addr, |
| 36 |
uint16_t internal_addr, int num_bytes, |
| 37 |
int ia_width_bytes) |
| 38 |
{ |
| 39 |
struct i2c_msg seg[2]; |
| 40 |
u32 buf; |
| 41 |
|
| 42 |
assert(num_bytes < 5); |
| 43 |
assert(ia_width_bytes < 3); |
| 44 |
|
| 45 |
seg[0].flags = 0; |
| 46 |
seg[0].slave = dev_addr; |
| 47 |
seg[0].buf = (u8 *)&internal_addr; |
| 48 |
seg[0].len = ia_width_bytes; |
| 49 |
seg[1].flags = I2C_M_RD; |
| 50 |
seg[1].slave = dev_addr; |
| 51 |
seg[1].buf = (u8 *)&buf; |
| 52 |
seg[1].len = num_bytes; |
| 53 |
|
| 54 |
if (i2c_transfer(twsi_id, seg, ARRAY_SIZE(seg)) < 0) |
| 55 |
return -1; |
| 56 |
|
| 57 |
return cpu_to_be32(buf); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
int bdk_twsix_write_ia(bdk_node_t node, int twsi_id, uint8_t dev_addr, |
| 78 |
uint16_t internal_addr, int num_bytes, |
| 79 |
int ia_width_bytes, uint64_t data) |
| 80 |
{ |
| 81 |
struct i2c_msg seg; |
| 82 |
u8 buf[10]; |
| 83 |
|
| 84 |
assert(num_bytes <= 8); |
| 85 |
assert(ia_width_bytes < 3); |
| 86 |
|
| 87 |
memcpy(buf, &internal_addr, ia_width_bytes); |
| 88 |
memcpy(&buf[ia_width_bytes], &data, num_bytes); |
| 89 |
|
| 90 |
seg.flags = 0; |
| 91 |
seg.slave = dev_addr; |
| 92 |
seg.buf = buf; |
| 93 |
seg.len = num_bytes + ia_width_bytes; |
| 94 |
|
| 95 |
return platform_i2c_transfer(twsi_id, &seg, 1); |
| 96 |
} |
| 97 |
|
| 98 |
void bdk_watchdog_set(unsigned int timeout_ms) |
| 99 |
{ |
| 100 |
watchdog_set(0, timeout_ms); |
| 101 |
} |
| 102 |
|
| 103 |
void bdk_watchdog_poke(void) |
| 104 |
{ |
| 105 |
watchdog_poke(0); |
| 106 |
} |
| 107 |
|
| 108 |
void bdk_watchdog_disable(void) |
| 109 |
{ |
| 110 |
watchdog_disable(0); |
| 111 |
} |
| 112 |
|
| 113 |
int bdk_watchdog_is_running(void) |
| 114 |
{ |
| 115 |
return watchdog_is_running(0); |
| 116 |
} |