docs: Add 24.12 release notes
[coreboot2.git] / src / soc / cavium / common / bdk-coreboot.c
blob448e329a104338db573333a4eeac43aaf92d0cc5
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 /*
4 * This file consists of data imported from bdk-config.c
5 */
7 // coreboot
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>
15 // BDK
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>
21 /**
22 * Do a twsi read from a 7 bit device address using an (optional)
23 * internal address. Up to 4 bytes can be read at a time.
25 * @param twsi_id which TWSI bus to use
26 * @param dev_addr Device address (7 bit)
27 * @param internal_addr
28 * Internal address. Can be 0, 1 or 2 bytes in width
29 * @param num_bytes Number of data bytes to read (1-4)
30 * @param ia_width_bytes
31 * Internal address size in bytes (0, 1, or 2)
33 * @return Read data, or -1 on failure
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)
39 struct i2c_msg seg[2];
40 u32 buf;
42 assert(num_bytes < 5);
43 assert(ia_width_bytes < 3);
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;
54 if (i2c_transfer(twsi_id, seg, ARRAY_SIZE(seg)) < 0)
55 return -1;
57 return cpu_to_be32(buf);
60 /**
61 * Write 1-8 bytes to a TWSI device using an internal address.
63 * @param twsi_id which TWSI interface to use
64 * @param dev_addr TWSI device address (7 bit only)
65 * @param internal_addr
66 * TWSI internal address (0, 8, or 16 bits)
67 * @param num_bytes Number of bytes to write (1-8)
68 * @param ia_width_bytes
69 * internal address width, in bytes (0, 1, 2)
70 * @param data Data to write. Data is written MSB first on the twsi bus,
71 * and only the lower num_bytes bytes of the argument are
72 * valid. If a 2 byte write is done, only the low 2 bytes of
73 * the argument is used.
75 * @return Zero on success, -1 on error
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)
81 struct i2c_msg seg;
82 u8 buf[10];
84 assert(num_bytes <= 8);
85 assert(ia_width_bytes < 3);
87 memcpy(buf, &internal_addr, ia_width_bytes);
88 memcpy(&buf[ia_width_bytes], &data, num_bytes);
90 seg.flags = 0;
91 seg.slave = dev_addr;
92 seg.buf = buf;
93 seg.len = num_bytes + ia_width_bytes;
95 return platform_i2c_transfer(twsi_id, &seg, 1);
98 void bdk_watchdog_set(unsigned int timeout_ms)
100 watchdog_set(0, timeout_ms);
103 void bdk_watchdog_poke(void)
105 watchdog_poke(0);
108 void bdk_watchdog_disable(void)
110 watchdog_disable(0);
113 int bdk_watchdog_is_running(void)
115 return watchdog_is_running(0);