2 #include <galileo/pci.h>
7 #include "zuma_pbb_mbox.h"
10 struct _zuma_mbox_dev zuma_mbox_dev;
13 static int zuma_mbox_write(struct _zuma_mbox_dev *dev, unsigned int data)
15 unsigned int status, count = 0, i;
17 status = (volatile int) le32_to_cpu(dev->sip->mbox_status);
19 while ((status & OUT_PENDING) && count < 1000) {
21 for (i = 0; i < 1000; i++)
23 status = (volatile int) le32_to_cpu(dev->sip->mbox_status);
26 /* if SET it means msg pending */
27 /* printf("mbox real write %08x\n",data); */
28 dev->sip->mbox_out = cpu_to_le32(data);
32 printf("mbox tx timeout\n");
36 static int zuma_mbox_read(struct _zuma_mbox_dev *dev, unsigned int *data)
38 unsigned int status, count = 0, i;
40 status = (volatile int) le32_to_cpu(dev->sip->mbox_status);
42 while (!(status & IN_VALID) && count < 1000) {
44 for (i = 0; i < 1000; i++)
46 status = (volatile int) le32_to_cpu(dev->sip->mbox_status);
49 /* if SET it means msg pending */
50 *data = le32_to_cpu(dev->sip->mbox_in);
51 /*printf("mbox real read %08x\n", *data); */
54 printf("mbox rx timeout\n");
58 static int zuma_mbox_do_one_mailbox(unsigned int out, unsigned int *in)
62 ret = zuma_mbox_write(&zuma_mbox_dev, out);
63 /*printf("write 0x%08x (%d bytes)\n", out, ret); */
66 ret = zuma_mbox_read(&zuma_mbox_dev, in);
67 /*printf("read 0x%08x (%d bytes)\n", *in, ret); */
74 #define RET_IF_FAILED(x) if ((x) == -1) return -1
76 static int zuma_mbox_do_all_mailbox(void)
79 unsigned short sdata_in;
81 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_START, &data_in));
83 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_MACL, &data_in));
84 memcpy(zuma_acc_mac + 2, &data_in, 4);
85 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_MACH, &data_in));
86 sdata_in = data_in & 0xffff;
87 memcpy(zuma_acc_mac, &sdata_in, 2);
89 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_IP, &data_in));
92 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_SLOT, &data_in));
93 zuma_slot_bac = data_in >> 3;
95 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_BAUD, &data_in));
96 zuma_console_baud = data_in & 0xffff;
97 zuma_debug_baud = data_in >> 16;
99 RET_IF_FAILED(zuma_mbox_do_one_mailbox
100 (ZUMA_MBOXMSG_ENG_PRV_MACL, &data_in));
101 memcpy(zuma_prv_mac + 2, &data_in, 4);
102 RET_IF_FAILED(zuma_mbox_do_one_mailbox
103 (ZUMA_MBOXMSG_ENG_PRV_MACH, &data_in));
104 sdata_in = data_in & 0xffff;
105 memcpy(zuma_prv_mac, &sdata_in, 2);
107 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_DONE, &data_in));
113 static void zuma_mbox_dump(void)
118 memcpy(&s, &zuma_acc_mac, sizeof(s));
119 memcpy(&i, &zuma_acc_mac[2], sizeof(i));
120 printf("ACC MAC=%04x%08x\n", s, i);
122 memcpy(&s, &zuma_prv_mac, sizeof(s));
123 memcpy(&s, &zuma_prv_mac[2], sizeof(i));
124 printf("PRV MAC=%04x%08x\n", s, i);
126 printf("slot:bac=%d:%d\n",
127 (zuma_slot_bac >> 2) & 0xf,
128 zuma_slot_bac & 0x3);
130 printf("BAUD1=%d BAUD2=%d\n",
136 static void zuma_mbox_setenv(void)
139 unsigned char save = 0;
141 data = getenv("baudrate");
143 if (!data || (zuma_console_baud != simple_strtoul(data, NULL, 10))) {
144 sprintf(buf, "%6d", zuma_console_baud);
145 setenv("baudrate", buf);
147 printf("baudrate doesn't match from mbox\n");
150 ip_to_string(zuma_ip, buf);
151 setenv("ipaddr", buf);
153 sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
157 zuma_prv_mac[3], zuma_prv_mac[4], zuma_prv_mac[5]);
158 setenv("ethaddr", buf);
160 sprintf(buf, "%02x", zuma_slot_bac);
161 setenv("bacslot", buf);
171 int zuma_mbox_init(void)
175 memset(&zuma_mbox_dev, 0, sizeof(struct _zuma_mbox_dev));
178 pci_find_device(VENDOR_ID_ZUMA, DEVICE_ID_ZUMA_PBB, 0);
180 if (zuma_mbox_dev.dev == -1) {
181 printf("no zuma pbb\n");
185 pci_read_config_dword(zuma_mbox_dev.dev, PCI_BASE_ADDRESS_0, &iobase);
187 iobase &= PCI_BASE_ADDRESS_MEM_MASK;
189 zuma_mbox_dev.sip = (PBB_DMA_REG_MAP *) iobase;
191 zuma_mbox_dev.sip->int_mask.word = 0;
193 printf("pbb @ %p v%d.%d, timestamp %08x\n", zuma_mbox_dev.sip,
194 zuma_mbox_dev.sip->version.pci_bits.rev_major,
195 zuma_mbox_dev.sip->version.pci_bits.rev_minor,
196 zuma_mbox_dev.sip->timestamp);
198 if (zuma_mbox_do_all_mailbox() == -1) {
199 printf("mailbox failed.. no ACC?\n");