int __init find_via_cuda(void) { struct adb_request req; int err; if (macintosh_config->adb_type != MAC_ADB_CUDA) return 0; via = via1; cuda_state = idle; err = cuda_init_via(); if (err) { printk(KERN_ERR "cuda_init_via() failed\n"); via = NULL; return 0; } cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1); while (!req.complete) cuda_poll(); return 1; }
static int cuda_adb_req (void *host, const uint8_t *snd_buf, int len, uint8_t *rcv_buf) { uint8_t buffer[CUDA_BUF_SIZE], *pos; // CUDA_DPRINTF("len: %d %02x\n", len, snd_buf[0]); len = cuda_request(host, ADB_PACKET, snd_buf, len, buffer); if (len > 1 && buffer[0] == ADB_PACKET) { /* We handle 2 types of ADB packet here: Normal: <type> <status> <data> ... Error : <type> <status> <cmd> (<data> ...) Ideally we should use buffer[1] (status) to determine whether this is a normal or error packet but this requires a corresponding fix in QEMU <= 2.4. Hence we temporarily handle it this way to ease the transition. */ if (len > 2 && buffer[2] == snd_buf[0]) { /* Error */ pos = buffer + 3; len -= 3; } else { /* Normal */ pos = buffer + 2; len -= 2; } } else { pos = buffer + 1; len = -1; } memcpy(rcv_buf, pos, len); return len; }
static void rtc_set_time(int *idx) { uint8_t cmdbuf[5], obuf[3]; ucell second, minute, hour, day, month, year; const int *days; uint32_t now; unsigned int nb_days; int i; year = POP(); month = POP(); day = POP(); hour = POP(); minute = POP(); second = POP(); days = is_leap(year) ? days_month_leap : days_month; nb_days = (year - 1904) * 36525 / 100 + day; for (i = 0; i < month - 1; i++) nb_days += days[i]; now = (((nb_days * 24) + hour) * 60 + minute) * 60 + second; cmdbuf[0] = CUDA_SET_TIME; cmdbuf[1] = now >> 24; cmdbuf[2] = now >> 16; cmdbuf[3] = now >> 8; cmdbuf[4] = now; cuda_request(main_cuda, CUDA_PACKET, cmdbuf, sizeof(cmdbuf), obuf); }
__pmac unsigned long pmac_get_rtc_time(void) { struct adb_request req; /* Get the time from the RTC */ switch (adb_hardware) { case ADB_VIACUDA: if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0) return 0; while (!req.complete) cuda_poll(); if (req.reply_len != 7) printk(KERN_ERR "pmac_get_rtc_time: got %d byte reply\n", req.reply_len); return (req.reply[3] << 24) + (req.reply[4] << 16) + (req.reply[5] << 8) + req.reply[6] - RTC_OFFSET; case ADB_VIAPMU: if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0) return 0; while (!req.complete) pmu_poll(); if (req.reply_len != 5) printk(KERN_ERR "pmac_get_rtc_time: got %d byte reply\n", req.reply_len); return (req.reply[1] << 24) + (req.reply[2] << 16) + (req.reply[3] << 8) + req.reply[4] - RTC_OFFSET; default: return 0; } }
int __init find_via_cuda(void) { struct adb_request req; phys_addr_t taddr; const u32 *reg; int err; if (vias != 0) return 1; vias = of_find_node_by_name(NULL, "via-cuda"); if (vias == 0) return 0; reg = get_property(vias, "reg", NULL); if (reg == NULL) { printk(KERN_ERR "via-cuda: No \"reg\" property !\n"); goto fail; } taddr = of_translate_address(vias, reg); if (taddr == 0) { printk(KERN_ERR "via-cuda: Can't translate address !\n"); goto fail; } via = ioremap(taddr, 0x2000); if (via == NULL) { printk(KERN_ERR "via-cuda: Can't map address !\n"); goto fail; } cuda_state = idle; sys_ctrler = SYS_CTRLER_CUDA; err = cuda_init_via(); if (err) { printk(KERN_ERR "cuda_init_via() failed\n"); via = NULL; return 0; } /* Clear and enable interrupts, but only on PPC. On 68K it's done */ /* for us by the main VIA driver in arch/m68k/mac/via.c */ #ifndef CONFIG_MAC out_8(&via[IFR], 0x7f); /* clear interrupts by writing 1s */ out_8(&via[IER], IER_SET|SR_INT); /* enable interrupt from SR */ #endif /* enable autopoll */ cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1); while (!req.complete) cuda_poll(); return 1; fail: of_node_put(vias); vias = NULL; return 0; }
int __init find_via_cuda(void) { int err; struct adb_request req; if (vias != 0) return 1; vias = find_devices("via-cuda"); if (vias == 0) return 0; if (vias->next != 0) printk(KERN_WARNING "Warning: only using 1st via-cuda\n"); #if 0 { int i; printk("find_via_cuda: node = %p, addrs =", vias->node); for (i = 0; i < vias->n_addrs; ++i) printk(" %x(%x)", vias->addrs[i].address, vias->addrs[i].size); printk(", intrs ="); for (i = 0; i < vias->n_intrs; ++i) printk(" %x", vias->intrs[i].line); printk("\n"); } #endif if (vias->n_addrs != 1 || vias->n_intrs != 1) { printk(KERN_ERR "via-cuda: expecting 1 address (%d) and 1 interrupt (%d)\n", vias->n_addrs, vias->n_intrs); if (vias->n_addrs < 1 || vias->n_intrs < 1) return 0; } via = ioremap(vias->addrs->address, 0x2000); cuda_state = idle; sys_ctrler = SYS_CTRLER_CUDA; err = cuda_init_via(); if (err) { printk(KERN_ERR "cuda_init_via() failed\n"); via = NULL; return 0; } /* Clear and enable interrupts, but only on PPC. On 68K it's done */ /* for us by the main VIA driver in arch/m68k/mac/via.c */ #ifndef CONFIG_MAC out_8(&via[IFR], 0x7f); /* clear interrupts by writing 1s */ out_8(&via[IER], IER_SET|SR_INT); /* enable interrupt from SR */ #endif /* enable autopoll */ cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1); while (!req.complete) cuda_poll(); return 1; }
static void ppc32_poweroff(void) { uint8_t cmdbuf[2], obuf[64]; cmdbuf[0] = CUDA_POWERDOWN; cuda_request(main_cuda, CUDA_PACKET, cmdbuf, sizeof(cmdbuf), obuf); }
static void ppc32_reset_all(void) { uint8_t cmdbuf[2], obuf[64]; cmdbuf[0] = CUDA_RESET_SYSTEM; cuda_request(main_cuda, CUDA_PACKET, cmdbuf, sizeof(cmdbuf), obuf); }
int __init find_via_cuda(void) { struct adb_request req; phys_addr_t taddr; const u32 *reg; int err; if (vias != 0) return 1; vias = of_find_node_by_name(NULL, "via-cuda"); if (vias == 0) return 0; reg = of_get_property(vias, "reg", NULL); if (reg == NULL) { printk(KERN_ERR "via-cuda: No \"reg\" property !\n"); goto fail; } taddr = of_translate_address(vias, reg); if (taddr == 0) { printk(KERN_ERR "via-cuda: Can't translate address !\n"); goto fail; } via = ioremap(taddr, 0x2000); if (via == NULL) { printk(KERN_ERR "via-cuda: Can't map address !\n"); goto fail; } cuda_state = idle; sys_ctrler = SYS_CTRLER_CUDA; err = cuda_init_via(); if (err) { printk(KERN_ERR "cuda_init_via() failed\n"); via = NULL; return 0; } out_8(&via[IFR], 0x7f); out_8(&via[IER], IER_SET|SR_INT); cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1); while (!req.complete) cuda_poll(); return 1; fail: of_node_put(vias); vias = NULL; return 0; }
/* Reset adb bus - how do we do this?? */ static int cuda_reset_adb_bus(void) { struct adb_request req; if ((via == NULL) || !cuda_fully_inited) return -ENXIO; cuda_request(&req, NULL, 2, ADB_PACKET, 0); /* maybe? */ while (!req.complete) cuda_poll(); return 0; }
/* Enable/disable autopolling */ static int cuda_adb_autopoll(int devs) { struct adb_request req; if ((via == NULL) || !cuda_fully_inited) return -ENXIO; cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, (devs? 1: 0)); while (!req.complete) cuda_poll(); return 0; }
static void rtc_get_time(int *idx) { uint8_t cmdbuf[2], obuf[64]; ucell second, minute, hour, day, month, year; uint32_t now; int current; const int *days; cmdbuf[0] = CUDA_GET_TIME; cuda_request(main_cuda, CUDA_PACKET, cmdbuf, sizeof(cmdbuf), obuf); /* seconds since 01/01/1904 */ now = (obuf[3] << 24) + (obuf[4] << 16) + (obuf[5] << 8) + obuf[6]; second = now % 60; now /= 60; minute = now % 60; now /= 60; hour = now % 24; now /= 24; year = now * 100 / 36525; now -= year * 36525 / 100; year += 1904; days = is_leap(year) ? days_month_leap : days_month; current = 0; month = 0; while (month < 12) { if (now <= current + days[month]) { break; } current += days[month]; month++; } month++; day = now - current; PUSH(second); PUSH(minute); PUSH(hour); PUSH(day); PUSH(month); PUSH(year); }