rendered paste bodyint ata_init(void)
{
if (!initialized)
{
spinlock_init(&sd_mtx);
spinlock_lock(&sd_mtx);
ata_led(false);
initialized = true;
outl(inl(0x70000088) & ~(0x4), 0x70000088);
outl(inl(0x7000008c) & ~(0x4), 0x7000008c);
outl(inl(0x70000084) | 0x4, 0x70000084);
outl(0x1010, 0x70000034);
GPIOA_OUTPUT_EN &= ~(1 << 7);
GPIOA_ENABLE |= (1 << 7);
GPIOG_ENABLE |= (0x3 << 5);
GPIOG_OUTPUT_EN |= (0x3 << 5);
GPIOG_OUTPUT_VAL |= (0x3 << 5);
sleep(HZ/10);
sd_init_device(0);
queue_init(&sd_queue, true);
create_thread(sd_thread, sd_stack, sizeof(sd_stack),
sd_thread_name IF_PRIO(, PRIORITY_SYSTEM) IF_COP(, CPU, false));
/* enable interupt for the mSD card */
GPIOA_INT_EN &= ~(1 << 7);
CPU_INT_EN = HI_MASK;
CPU_HI_INT_EN = GPIO0_MASK;
current_status = GPIOA_INPUT_VAL & 0x80;
GPIOA_INT_LEV = (GPIOA_INT_LEV & ~0x80) | (current_status ^ 0x80);
GPIOA_INT_CLR = (1 << 7);
GPIOA_INT_EN |= (1 << 7);
spinlock_unlock(&sd_mtx);
}
return 0;
}