home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / src / linux-headers-2.6.28-15 / arch / arm / plat-mxc / include / mach / gpio.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-09  |  5.4 KB  |  168 lines

  1. /*
  2.  * Copyright 2004-2008 Freescale Semiconductor, Inc. All Rights Reserved.
  3.  */
  4.  
  5. /*
  6.  * The code contained herein is licensed under the GNU General Public
  7.  * License. You may obtain a copy of the GNU General Public License
  8.  * Version 2 or later at the following locations:
  9.  *
  10.  * http://www.opensource.org/licenses/gpl-license.html
  11.  * http://www.gnu.org/copyleft/gpl.html
  12.  */
  13. #ifndef __ASM_ARCH_MXC_GPIO_H__
  14. #define __ASM_ARCH_MXC_GPIO_H__
  15.  
  16. /*!
  17.  * @defgroup GPIO General Purpose Input Output (GPIO)
  18.  */
  19.  
  20. /*!
  21.  * @file arch-mxc/gpio.h
  22.  * @brief This file contains the GPIO API functions.
  23.  *
  24.  * @ingroup GPIO
  25.  */
  26.  
  27. #include <linux/interrupt.h>
  28. #include <asm/sizes.h>
  29.  
  30. typedef unsigned int iomux_pin_name_t;
  31.  
  32. /* gpio related defines */
  33.  
  34. /*!
  35.  * There are two queues for registered GPIO ISRs. One is for high priority and
  36.  * the other is for low priority. The ISRs in the high priority queue will be
  37.  * called first before the low priority queue if more than one GPIO interrupt
  38.  * occurs at the same time.
  39.  */
  40. enum gpio_prio {
  41.     GPIO_HIGH_PRIO = 0,    /*!< high priority queue */
  42.     GPIO_LOW_PRIO        /*!< low priority queue */
  43. };
  44.  
  45. /*!
  46.  * This enumeration data type defines various different ways for interrupting
  47.  * the ARM core from GPIO signals. The way to interrupt the core is dictated
  48.  * by the external hardware.
  49.  */
  50. typedef enum gpio_int_cfg {
  51. #if defined(CONFIG_ARCH_MX21) || defined(CONFIG_ARCH_MX27)
  52.     GPIO_INT_LOW_LEV = 0x3,    /*!< low level sensitive */
  53.     GPIO_INT_HIGH_LEV = 0x2,    /*!< high level sensitive */
  54.     GPIO_INT_RISE_EDGE = 0x0,    /*!< rising edge sensitive */
  55.     GPIO_INT_FALL_EDGE = 0x1,    /*!< falling edge sensitive */
  56.     GPIO_INT_NONE = 0x4    /*!< No interrupt */
  57. #else
  58.     GPIO_INT_LOW_LEV = 0x0,    /*!< low level sensitive */
  59.     GPIO_INT_HIGH_LEV = 0x1,    /*!< high level sensitive */
  60.     GPIO_INT_RISE_EDGE = 0x2,    /*!< rising edge sensitive */
  61.     GPIO_INT_FALL_EDGE = 0x3,    /*!< falling edge sensitive */
  62.     GPIO_INT_NONE = 0x4    /*!< No interrupt */
  63. #endif
  64. } gpio_edge_t;
  65.  
  66. typedef irqreturn_t(*gpio_irq_handler) (int, void *);
  67.  
  68. /*!
  69.  * This function configures the GPIO signal to be either input or output. For
  70.  * input signals used for generating interrupts for the ARM core, how the
  71.  * interrupts being triggered is also passed in via \a icr. For output signals,
  72.  * the \a icr value doesn't matter.
  73.  *
  74.  * @param  port         specified port with 0-GPIO port 1; 1-GPIO port 2
  75.  * @param  sig_no       specified GPIO signal (0 based)
  76.  * @param  out          #true for output, #false for input
  77.  * @param  icr          value defined in \b #gpio_int_cfg
  78.  */
  79. void gpio_config(__u32 port, __u32 sig_no, bool out, enum gpio_int_cfg icr);
  80.  
  81. /*!
  82.  * This function sets a GPIO signal value.
  83.  *
  84.  * @param  port         specified port with 0-GPIO port 1; 1-GPIO port 2
  85.  * @param  sig_no       specified GPIO signal (0 based)
  86.  * @param  data         value to be set (only 0 or 1 is valid)
  87.  */
  88. void gpio_set_data(__u32 port, __u32 sig_no, __u32 data);
  89.  
  90. /*!
  91.  * This function returns the value of the GPIO signal.
  92.  *
  93.  * @param  port         specified port with 0-GPIO port 1; 1-GPIO port 2
  94.  * @param  sig_no       specified GPIO signal (0 based)
  95.  *
  96.  * @return Value of the GPIO signal
  97.  */
  98. __u32 gpio_get_data(__u32 port, __u32 sig_no);
  99.  
  100. /*!
  101.  * This function is responsible for registering a GPIO signal's ISR.
  102.  *
  103.  * @param  port         specified port with 0-GPIO port 1; 1-GPIO port 2
  104.  * @param  sig_no       specified GPIO signal (0 based)
  105.  * @param  prio         priority as defined in \b enum \b #gpio_prio
  106.  * @param  handler      GPIO ISR function pointer for the GPIO signal
  107.  * @param  irq_flags    irq flags (not used)
  108.  * @param  devname      device name associated with the interrupt
  109.  * @param  dev_id       some unique information for the ISR
  110.  *
  111.  * @return 0 if successful; non-zero otherwise.
  112.  */
  113. int gpio_request_irq(__u32 port, __u32 sig_no, enum gpio_prio prio,
  114.              gpio_irq_handler handler, __u32 irq_flags,
  115.              const char *devname, void *dev_id);
  116.  
  117. /*!
  118.  * This function un-registers an ISR with the GPIO interrupt module.
  119.  *
  120.  * @param  port         specified port with 0-GPIO port 1; 1-GPIO port 2
  121.  * @param  sig_no       specified GPIO signal (0 based)
  122.  * @param  prio         priority as defined in \b enum \b #gpio_prio
  123.  */
  124. void gpio_free_irq(__u32 port, __u32 sig_no, enum gpio_prio prio);
  125.  
  126. /*!
  127.  * Request ownership for a GPIO pin. The caller has to check the return value
  128.  * of this function to make sure it returns 0 before make use of that pin.
  129.  * @param pin        a name defined by \b iomux_pin_name_t
  130.  * @return        0 if successful; Non-zero otherwise
  131.  */
  132. int mxc_request_gpio(iomux_pin_name_t pin);
  133.  
  134. /*!
  135.  * Exported function to set a GPIO pin's direction
  136.  * @param pin        a name defined by \b iomux_pin_name_t
  137.  * @param is_input    1 (or non-zero) for input; 0 for output
  138.  */
  139. void mxc_set_gpio_direction(iomux_pin_name_t pin, int is_input);
  140.  
  141. /*!
  142.  * Exported function to set a GPIO pin's data output
  143.  * @param pin        a name defined by \b iomux_pin_name_t
  144.  * @param data        value to be set (only 0 or 1 is valid)
  145.  */
  146. void mxc_set_gpio_dataout(iomux_pin_name_t pin, u32 data);
  147.  
  148. /*!
  149.  * Return the data value of a GPIO signal.
  150.  * @param pin    a name defined by \b iomux_pin_name_t
  151.  *
  152.  * @return     value (0 or 1) of the GPIO signal; -1 if pass in invalid pin
  153.  */
  154. int mxc_get_gpio_datain(iomux_pin_name_t pin);
  155.  
  156. /*!
  157.  * Release ownership for a GPIO pin
  158.  * @param pin        a name defined by \b iomux_pin_name_t
  159.  */
  160. void mxc_free_gpio(iomux_pin_name_t pin);
  161.  
  162. /*!
  163.  * GPIO driver initialization
  164.  * @return    always 0
  165.  */
  166. int mxc_gpio_init(void);
  167. #endif                /* __ASM_ARCH_MXC_GPIO_H__ */
  168.