1 // SPDX-License-Identifier: GPL-2.0+
4 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
7 #ifdef CONFIG_GDSYS_LEGACY_DRIVERS
13 #include <gdsys_fpga.h>
16 MCINT_SLAVE_LINK_CHANGED_EV = 1 << 7,
17 MCINT_TX_ERROR_EV = 1 << 9,
18 MCINT_TX_BUFFER_FREE = 1 << 10,
19 MCINT_TX_PACKET_TRANSMITTED_EV = 1 << 11,
20 MCINT_RX_ERROR_EV = 1 << 13,
21 MCINT_RX_CONTENT_AVAILABLE = 1 << 14,
22 MCINT_RX_PACKET_RECEIVED_EV = 1 << 15,
25 int mclink_probe(void)
30 for (k = 0; k < CONFIG_SYS_MCLINK_MAX; ++k) {
35 FPGA_GET_REG(k, mc_status, &mc_status);
37 if (!(mc_status & (1 << 15)))
40 FPGA_SET_REG(k, mc_control, 0x8000);
42 FPGA_GET_REG(k, mc_status, &mc_status);
43 while (!(mc_status & (1 << 14))) {
49 FPGA_GET_REG(k, mc_status, &mc_status);
54 printf("waited %d us for mclink %d to come up\n", ctr * 100, k);
62 int mclink_send(u8 slave, u16 addr, u16 data)
69 /* reset interrupt status */
70 FPGA_GET_REG(0, mc_int, &int_status);
71 FPGA_SET_REG(0, mc_int, int_status);
74 FPGA_SET_REG(0, mc_tx_address, addr);
75 FPGA_SET_REG(0, mc_tx_data, data);
76 FPGA_SET_REG(0, mc_tx_cmd, (slave & 0x03) << 14);
77 FPGA_SET_REG(0, mc_control, 0x8001);
80 FPGA_GET_REG(0, mc_int, &int_status);
81 while (!(int_status & MCINT_RX_PACKET_RECEIVED_EV)) {
85 FPGA_GET_REG(0, mc_int, &int_status);
88 FPGA_GET_REG(0, mc_rx_cmd_status, &rx_cmd_status);
89 rx_cmd = (rx_cmd_status >> 12) & 0x03;
91 printf("mclink_send: received cmd %d, expected %d\n", rx_cmd,
97 int mclink_receive(u8 slave, u16 addr, u16 *data)
102 unsigned int ctr = 0;
104 /* send read request */
105 FPGA_SET_REG(0, mc_tx_address, addr);
106 FPGA_SET_REG(0, mc_tx_cmd,
107 ((slave & 0x03) << 14) | (1 << 12) | (1 << 0));
108 FPGA_SET_REG(0, mc_control, 0x8001);
112 FPGA_GET_REG(0, mc_int, &int_status);
113 while (!(int_status & MCINT_RX_CONTENT_AVAILABLE)) {
117 FPGA_GET_REG(0, mc_int, &int_status);
121 FPGA_GET_REG(0, mc_rx_cmd_status, &rx_cmd_status);
122 if ((rx_cmd_status >> 14) != slave) {
123 printf("mclink_receive: reply from slave %d, expected %d\n",
124 rx_cmd_status >> 14, slave);
128 rx_cmd = (rx_cmd_status >> 12) & 0x03;
130 printf("mclink_send: received cmd %d, expected %d\n",
135 FPGA_GET_REG(0, mc_rx_data, data);
140 #endif /* CONFIG_GDSYS_LEGACY_DRIVERS */