1 // SPDX-License-Identifier: GPL-2.0+
3 * caddy.c -- esd VME8349 support for "missing" access modes in TSI148.
4 * Copyright (c) 2009 esd gmbh.
14 #include <asm/mpc8349_pci.h>
21 static struct caddy_interface *caddy_interface;
23 void generate_answer(struct caddy_cmd *cmd, uint32_t status, uint32_t *result)
25 struct caddy_answer *answer;
28 answer = &caddy_interface->answer[caddy_interface->answer_in];
29 memset((void *)answer, 0, sizeof(struct caddy_answer));
30 answer->answer = cmd->cmd;
31 answer->issue = cmd->issue;
32 answer->status = status;
33 memcpy(answer->par, result, 5 * sizeof(result[0]));
34 ptr = caddy_interface->answer_in + 1;
35 ptr = ptr & (ANSWER_SIZE - 1);
36 if (ptr != caddy_interface->answer_out)
37 caddy_interface->answer_in = ptr;
40 int do_caddy(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
42 unsigned long base_addr;
44 struct caddy_cmd *caddy_cmd;
53 puts("Missing parameter\n");
57 base_addr = simple_strtoul(argv[1], NULL, 16);
58 caddy_interface = (struct caddy_interface *) base_addr;
60 memset((void *)caddy_interface, 0, sizeof(struct caddy_interface));
61 memcpy((void *)&caddy_interface->magic[0], &CADDY_MAGIC, 16);
63 while (ctrlc() == 0) {
64 if (caddy_interface->cmd_in != caddy_interface->cmd_out) {
65 memset(result, 0, 5 * sizeof(result[0]));
67 caddy_cmd = &caddy_interface->cmd[caddy_interface->cmd_out];
68 pci_ptr = (void *)CONFIG_SYS_PCI1_IO_PHYS +
69 (caddy_cmd->addr & 0x001fffff);
71 switch (caddy_cmd->cmd) {
72 case CADDY_CMD_IO_READ_8:
73 result[0] = in_8(pci_ptr);
76 case CADDY_CMD_IO_READ_16:
77 result[0] = in_be16(pci_ptr);
80 case CADDY_CMD_IO_READ_32:
81 result[0] = in_be32(pci_ptr);
84 case CADDY_CMD_IO_WRITE_8:
85 data8 = caddy_cmd->par[0] & 0x000000ff;
86 out_8(pci_ptr, data8);
89 case CADDY_CMD_IO_WRITE_16:
90 data16 = caddy_cmd->par[0] & 0x0000ffff;
91 out_be16(pci_ptr, data16);
94 case CADDY_CMD_IO_WRITE_32:
95 out_be32(pci_ptr, caddy_cmd->par[0]);
98 case CADDY_CMD_CONFIG_READ_8:
99 dev = PCI_BDF(caddy_cmd->par[0],
102 status = pci_read_config_byte(dev,
108 case CADDY_CMD_CONFIG_READ_16:
109 dev = PCI_BDF(caddy_cmd->par[0],
112 status = pci_read_config_word(dev,
118 case CADDY_CMD_CONFIG_READ_32:
119 dev = PCI_BDF(caddy_cmd->par[0],
122 status = pci_read_config_dword(dev,
127 case CADDY_CMD_CONFIG_WRITE_8:
128 dev = PCI_BDF(caddy_cmd->par[0],
131 data8 = caddy_cmd->par[3] & 0x000000ff;
132 status = pci_write_config_byte(dev,
137 case CADDY_CMD_CONFIG_WRITE_16:
138 dev = PCI_BDF(caddy_cmd->par[0],
141 data16 = caddy_cmd->par[3] & 0x0000ffff;
142 status = pci_write_config_word(dev,
147 case CADDY_CMD_CONFIG_WRITE_32:
148 dev = PCI_BDF(caddy_cmd->par[0],
151 status = pci_write_config_dword(dev,
161 generate_answer(caddy_cmd, status, &result[0]);
163 ptr = caddy_interface->cmd_out + 1;
164 ptr = ptr & (CMD_SIZE - 1);
165 caddy_interface->cmd_out = ptr;
168 caddy_interface->heartbeat++;
175 caddy, 2, 0, do_caddy,
176 "Start Caddy server.",
177 "Start Caddy server with Data structure a given addr\n"