/*-----------------------------------------------------------------------------------------------*\ \*-----------------------------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #include #include #include #include #define AR7GPIO_DEBUG #if defined(AR7GPIO_DEBUG) #define DBG(...) printk(KERN_INFO __VA_ARGS__) #else /*--- #if defined(AR7GPIO_DEBUG) ---*/ #define DBG(...) #endif /*--- #else ---*/ /*--- #if defined(AR7GPIO_DEBUG) ---*/ #if defined (CONFIG_MIPS_OHIO) extern union _hw_non_reset *OHIO_hw_non_reset; extern struct _hw_gpio *OHIO_hw_gpio; static spinlock_t ohio_gpio_spinlock; /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ void ohio_gpio_init(void) { printk("[ohio_gpio_init]\n"); OHIO_hw_non_reset->Bits.gpio_unreset = 1; spin_lock_init(&ohio_gpio_spinlock); ohio_take_device_out_of_reset(GPIO_RESET_BIT); } /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ int ohio_gpio_ctrl(unsigned int gpio_pin, enum _hw_gpio_function pin_mode, enum _hw_gpio_direction pin_dir) { unsigned int flags; if(gpio_pin >= 32) return(-1); spin_lock_irqsave(&ohio_gpio_spinlock, flags); if(pin_mode == GPIO_PIN) { OHIO_hw_gpio->Enable.Register |= (1 << gpio_pin); if (pin_dir == GPIO_INPUT_PIN) OHIO_hw_gpio->Direction.Register |= (1 << gpio_pin); else OHIO_hw_gpio->Direction.Register &= ~(1 << gpio_pin); } else { /* FUNCTIONAL PIN */ OHIO_hw_gpio->Enable.Register &= ~(1 << gpio_pin); } spin_unlock_irqrestore(&ohio_gpio_spinlock, flags); return (0); } /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ int ohio_gpio_out_bit(unsigned int gpio_pin, int value) { unsigned int flags; if(gpio_pin >= 32) return(-1); spin_lock_irqsave(&ohio_gpio_spinlock, flags); if(value == 1) OHIO_hw_gpio->OutputData.Register |= 1 << gpio_pin; else OHIO_hw_gpio->OutputData.Register &= ~(1 << gpio_pin); spin_unlock_irqrestore(&ohio_gpio_spinlock, flags); return(0); } /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ int ohio_gpio_in_bit(unsigned int gpio_pin) { if(gpio_pin >= 32) return(-1); return (OHIO_hw_gpio->InputData.Register & (1 << gpio_pin)); } /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ unsigned int ohio_gpio_in_value(void) { return OHIO_hw_gpio->InputData.Register; } /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ void ohio_gpio_set_bitmask(unsigned int mask, unsigned int value) { unsigned int flags; spin_lock_irqsave(&ohio_gpio_spinlock, flags); OHIO_hw_gpio->OutputData.Register &= ~mask; OHIO_hw_gpio->OutputData.Register |= value & mask; spin_unlock_irqrestore(&ohio_gpio_spinlock, flags); } EXPORT_SYMBOL(ohio_gpio_ctrl); EXPORT_SYMBOL(ohio_gpio_out_bit); EXPORT_SYMBOL(ohio_gpio_in_bit); EXPORT_SYMBOL(ohio_gpio_in_value); EXPORT_SYMBOL(ohio_gpio_set_bitmask); #endif /*--- #if defined (CONFIG_MIPS_OHIO) ---*/