int pnx4008_gpio_unregister_pin(unsigned short pin) { unsigned long bit = GPIO_BIT(pin); int ret = -EFAULT; /* Not registered */ gpio_lock(); if (GPIO_ISBID(pin)) { if (~access_map[GPIO_INDEX] & bit) goto out; access_map[GPIO_INDEX] &= ~bit; } else if (GPIO_ISRAM(pin)) { if (~access_map[GPIO_INDEX] & bit) goto out; access_map[GPIO_INDEX] &= ~bit; } else if (GPIO_ISMUX(pin)) { if (~access_map[MUX_INDEX] & bit) goto out; access_map[MUX_INDEX] &= ~bit; } else if (GPIO_ISOUT(pin)) { if (~access_map[OUTP_INDEX] & bit) goto out; access_map[OUTP_INDEX] &= ~bit; } else if (GPIO_ISIN(pin)) { if (~access_map[INP_INDEX] & bit) goto out; access_map[INP_INDEX] &= ~bit; } else goto out; ret = 0; out: gpio_unlock(); return ret; }
/* Read GPIO pin direction: 0= pin used as input, 1= pin used as output*/ int pnx4008_gpio_read_pin_direction(unsigned short pin) { int gpio = GPIO_BIT_MASK(pin); int ret = -EFAULT; gpio_lock(); if (GPIO_ISBID(pin) || GPIO_ISRAM(pin)) { ret = gpio_read_bit(PIO_DRV_STATE, gpio); } gpio_unlock(); return ret; }
/* Value = 0 : Set GPIO pin as input */ int pnx4008_gpio_set_pin_direction(unsigned short pin, int output) { int gpio = GPIO_BIT_MASK(pin); int ret = -EFAULT; gpio_lock(); if (GPIO_ISBID(pin) || GPIO_ISRAM(pin)) { ret = gpio_set_bit(output ? PIO_DRV_SET : PIO_DRV_CLR, gpio); } gpio_unlock(); return ret; }
/* Read pin mux function: 0= pin used as GPIO, 1= pin used for muxed function*/ int pnx4008_gpio_read_pin_mux(unsigned short pin) { int gpio = GPIO_BIT_MASK(pin); int ret = -EFAULT; gpio_lock(); if (GPIO_ISBID(pin)) { ret = gpio_read_bit(PIO_MUX_STATE, gpio_to_mux_map[gpio]); } else if (GPIO_ISOUT(pin)) { ret = gpio_read_bit(PIO_MUX_STATE, outp_to_mux_map[gpio]); } else if (GPIO_ISMUX(pin)) { ret = gpio_read_bit(PIO_MUX_STATE, gpio); } gpio_unlock(); return ret; }
/* Value = 0 : Set pin as GPIO */ int pnx4008_gpio_set_pin_mux(unsigned short pin, int output) { int gpio = GPIO_BIT_MASK(pin); int ret = -EFAULT; gpio_lock(); if (GPIO_ISBID(pin)) { ret = gpio_set_bit(output ? PIO_MUX_SET : PIO_MUX_CLR, gpio_to_mux_map[gpio]); } else if (GPIO_ISOUT(pin)) { ret = gpio_set_bit(output ? PIO_MUX_SET : PIO_MUX_CLR, outp_to_mux_map[gpio]); } else if (GPIO_ISMUX(pin)) { ret = gpio_set_bit(output ? PIO_MUX_SET : PIO_MUX_CLR, gpio); } gpio_unlock(); return ret; }
/* Write Value to output */ int pnx4008_gpio_write_pin(unsigned short pin, int output) { int gpio = GPIO_BIT_MASK(pin); int ret = -EFAULT; gpio_lock(); if (GPIO_ISOUT(pin)) { printk( "writing '%x' to '%x'\n", gpio, output ? PIO_OUTP_SET : PIO_OUTP_CLR ); ret = gpio_set_bit(output ? PIO_OUTP_SET : PIO_OUTP_CLR, gpio); } else if (GPIO_ISRAM(pin)) { if (gpio_read_bit(PIO_DRV_STATE, gpio) > 0) ret = gpio_set_bit(output ? PIO_SDOUTP_SET : PIO_SDOUTP_CLR, gpio); } else if (GPIO_ISBID(pin)) { if (gpio_read_bit(PIO_DRV_STATE, gpio) > 0) ret = gpio_set_bit(output ? PIO_OUTP_SET : PIO_OUTP_CLR, gpio); } gpio_unlock(); return ret; }
int pnx4008_gpio_register_pin(unsigned short pin) { unsigned long bit = GPIO_BIT(pin); int ret = -EBUSY; /* Already in use */ gpio_lock(); if (GPIO_ISBID(pin)) { if (access_map[GPIO_INDEX] & bit) goto out; access_map[GPIO_INDEX] |= bit; } else if (GPIO_ISRAM(pin)) { if (access_map[GPIO_INDEX] & bit) goto out; access_map[GPIO_INDEX] |= bit; } else if (GPIO_ISMUX(pin)) { if (access_map[MUX_INDEX] & bit) goto out; access_map[MUX_INDEX] |= bit; } else if (GPIO_ISOUT(pin)) { if (access_map[OUTP_INDEX] & bit) goto out; access_map[OUTP_INDEX] |= bit; } else if (GPIO_ISIN(pin)) { if (access_map[INP_INDEX] & bit) goto out; access_map[INP_INDEX] |= bit; } else goto out; ret = 0; out: gpio_unlock(); return ret; }
unsigned long pnx4008_gpio_read_pin(unsigned short pin) { unsigned long ret = -EFAULT; int gpio = GPIO_BIT_MASK(pin); gpio_lock(); if (GPIO_ISOUT(pin)) { ret = gpio_read_bit(PIO_OUTP_STATE, gpio); } else if (GPIO_ISRAM(pin)) { if (gpio_read_bit(PIO_DRV_STATE, gpio) == 0) { ret = gpio_read_bit(PIO_SDINP_STATE, gpio); } } else if (GPIO_ISBID(pin)) { ret = gpio_read_bit(PIO_DRV_STATE, gpio); if (ret > 0) ret = gpio_read_bit(PIO_OUTP_STATE, gpio); else if (ret == 0) ret = gpio_read_bit(PIO_INP_STATE, gpio_to_inp_map[gpio]); } else if (GPIO_ISIN(pin)) { ret = gpio_read_bit(PIO_INP_STATE, gpio); } gpio_unlock(); return ret; }
/**************************************************** * FUNCTION: Mutex lock * PARAMS: port - GPIO port # (0 ~ 31) * RETURN: N/A ***************************************************/ void GPIO_PortLock(int port) { UNUSED(port); gpio_lock(); }