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) {
22 status = (volatile int)le32_to_cpu(dev->sip->mbox_status);
25 /* if SET it means msg pending */
26 /* printf("mbox real write %08x\n",data); */
27 dev->sip->mbox_out = cpu_to_le32(data);
31 printf("mbox tx timeout\n");
35 static int zuma_mbox_read(struct _zuma_mbox_dev *dev, unsigned int *data)
37 unsigned int status, count = 0, i;
39 status = (volatile int)le32_to_cpu(dev->sip->mbox_status);
41 while(!(status & IN_VALID) && count < 1000) {
44 status = (volatile int)le32_to_cpu(dev->sip->mbox_status);
47 /* if SET it means msg pending */
48 *data=le32_to_cpu(dev->sip->mbox_in);
49 /*printf("mbox real read %08x\n", *data); */
52 printf("mbox rx timeout\n");
56 static int zuma_mbox_do_one_mailbox(unsigned int out, unsigned int *in)
59 ret=zuma_mbox_write(&zuma_mbox_dev,out);
60 /*printf("write 0x%08x (%d bytes)\n", out, ret); */
62 ret=zuma_mbox_read(&zuma_mbox_dev,in);
63 /*printf("read 0x%08x (%d bytes)\n", *in, ret); */
69 #define RET_IF_FAILED(x) if ((x) == -1) return -1
71 static int zuma_mbox_do_all_mailbox(void)
74 unsigned short sdata_in;
76 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_START, &data_in));
78 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_MACL, &data_in));
79 memcpy(zuma_acc_mac+2,&data_in,4);
80 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_MACH, &data_in));
81 sdata_in=data_in&0xffff;
82 memcpy(zuma_acc_mac,&sdata_in,2);
84 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_IP, &data_in));
87 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_SLOT, &data_in));
88 zuma_slot_bac=data_in>>3;
90 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_BAUD, &data_in));
91 zuma_console_baud = data_in & 0xffff;
92 zuma_debug_baud = data_in >> 16;
94 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_ENG_PRV_MACL, &data_in));
95 memcpy(zuma_prv_mac+2,&data_in,4);
96 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_ENG_PRV_MACH, &data_in));
97 sdata_in=data_in&0xffff;
98 memcpy(zuma_prv_mac,&sdata_in,2);
100 RET_IF_FAILED(zuma_mbox_do_one_mailbox(ZUMA_MBOXMSG_DONE, &data_in));
109 printf("ACC MAC=%04x%08x\n",*(unsigned short *)(&zuma_acc_mac),*(unsigned int *)((char *)&zuma_acc_mac+2));
110 printf("PRV MAC=%04x%08x\n",*(unsigned short *)(&zuma_prv_mac),*(unsigned int *)((char *)&zuma_prv_mac+2));
111 printf("slot:bac=%d:%d\n",(zuma_slot_bac>>2)&0xf, zuma_slot_bac & 0x3);
112 printf("BAUD1=%d BAUD2=%d\n",zuma_console_baud,zuma_debug_baud);
117 zuma_mbox_setenv(void)
119 unsigned char *data, buf[32];
120 unsigned char save = 0;
122 data = getenv("baudrate");
124 if(!data || (zuma_console_baud != simple_strtoul(data, NULL, 10))) {
125 sprintf(buf, "%6d", zuma_console_baud);
126 setenv("baudrate", buf);
128 printf("baudrate doesn't match from mbox\n");
131 ip_to_string(zuma_ip, buf);
132 setenv("ipaddr", buf);
134 sprintf(buf,"%02x:%02x:%02x:%02x:%02x:%02x",
141 setenv("ethaddr", buf);
143 sprintf(buf,"%02x",zuma_slot_bac);
144 setenv("bacslot", buf);
154 int zuma_mbox_init(void)
157 memset(&zuma_mbox_dev, 0, sizeof(struct _zuma_mbox_dev));
159 zuma_mbox_dev.dev = pci_find_device(VENDOR_ID_ZUMA, DEVICE_ID_ZUMA_PBB, 0);
161 if(zuma_mbox_dev.dev == -1) {
162 printf("no zuma pbb\n");
166 pci_read_config_dword(zuma_mbox_dev.dev, PCI_BASE_ADDRESS_0, &iobase);
168 zuma_mbox_dev.sip = (PBB_DMA_REG_MAP *) (iobase & PCI_BASE_ADDRESS_MEM_MASK);
170 zuma_mbox_dev.sip->int_mask.word=0;
172 printf("pbb @ %p v%d.%d, timestamp %08x\n", zuma_mbox_dev.sip,
173 zuma_mbox_dev.sip->version.pci_bits.rev_major,
174 zuma_mbox_dev.sip->version.pci_bits.rev_minor,
175 zuma_mbox_dev.sip->timestamp);
177 if (zuma_mbox_do_all_mailbox() == -1) {
178 printf("mailbox failed.. no ACC?\n");