gpio.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * include/asm-sh/gpio.h
  3. *
  4. * Generic GPIO API and pinmux table support for SuperH.
  5. *
  6. * Copyright (c) 2008 Magnus Damm
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #ifndef __ASM_SH_GPIO_H
  13. #define __ASM_SH_GPIO_H
  14. #include <linux/errno.h>
  15. #if defined(CONFIG_CPU_SH3)
  16. #include <cpu/gpio.h>
  17. #endif
  18. typedef unsigned short pinmux_enum_t;
  19. typedef unsigned char pinmux_flag_t;
  20. #define PINMUX_TYPE_NONE 0
  21. #define PINMUX_TYPE_FUNCTION 1
  22. #define PINMUX_TYPE_GPIO 2
  23. #define PINMUX_TYPE_OUTPUT 3
  24. #define PINMUX_TYPE_INPUT 4
  25. #define PINMUX_TYPE_INPUT_PULLUP 5
  26. #define PINMUX_TYPE_INPUT_PULLDOWN 6
  27. #define PINMUX_FLAG_TYPE (0x7)
  28. #define PINMUX_FLAG_WANT_PULLUP (1 << 3)
  29. #define PINMUX_FLAG_WANT_PULLDOWN (1 << 4)
  30. struct pinmux_gpio {
  31. pinmux_enum_t enum_id;
  32. pinmux_flag_t flags;
  33. };
  34. #define PINMUX_GPIO(gpio, data_or_mark) [gpio] = { data_or_mark }
  35. #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
  36. struct pinmux_cfg_reg {
  37. unsigned long reg, reg_width, field_width;
  38. unsigned long *cnt;
  39. pinmux_enum_t *enum_ids;
  40. };
  41. #define PINMUX_CFG_REG(name, r, r_width, f_width) \
  42. .reg = r, .reg_width = r_width, .field_width = f_width, \
  43. .cnt = (unsigned long [r_width / f_width]) {}, \
  44. .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)]) \
  45. struct pinmux_data_reg {
  46. unsigned long reg, reg_width;
  47. pinmux_enum_t *enum_ids;
  48. };
  49. #define PINMUX_DATA_REG(name, r, r_width) \
  50. .reg = r, .reg_width = r_width, \
  51. .enum_ids = (pinmux_enum_t [r_width]) \
  52. struct pinmux_range {
  53. pinmux_enum_t begin;
  54. pinmux_enum_t end;
  55. };
  56. struct pinmux_info {
  57. char *name;
  58. pinmux_enum_t reserved_id;
  59. struct pinmux_range data;
  60. struct pinmux_range input;
  61. struct pinmux_range input_pd;
  62. struct pinmux_range input_pu;
  63. struct pinmux_range output;
  64. struct pinmux_range mark;
  65. struct pinmux_range function;
  66. unsigned first_gpio, last_gpio;
  67. struct pinmux_gpio *gpios;
  68. struct pinmux_cfg_reg *cfg_regs;
  69. struct pinmux_data_reg *data_regs;
  70. pinmux_enum_t *gpio_data;
  71. unsigned int gpio_data_size;
  72. unsigned long *gpio_in_use;
  73. };
  74. int register_pinmux(struct pinmux_info *pip);
  75. int __gpio_request(unsigned gpio);
  76. static inline int gpio_request(unsigned gpio, const char *label)
  77. {
  78. return __gpio_request(gpio);
  79. }
  80. void gpio_free(unsigned gpio);
  81. int gpio_direction_input(unsigned gpio);
  82. int gpio_direction_output(unsigned gpio, int value);
  83. int gpio_get_value(unsigned gpio);
  84. void gpio_set_value(unsigned gpio, int value);
  85. /* IRQ modes are unspported */
  86. static inline int gpio_to_irq(unsigned gpio)
  87. {
  88. WARN_ON(1);
  89. return -EINVAL;
  90. }
  91. static inline int irq_to_gpio(unsigned irq)
  92. {
  93. WARN_ON(1);
  94. return -EINVAL;
  95. }
  96. #include <asm-generic/gpio.h>
  97. #endif /* __ASM_SH_GPIO_H */