gpio.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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/kernel.h>
  15. #include <linux/errno.h>
  16. #if defined(CONFIG_CPU_SH3)
  17. #include <cpu/gpio.h>
  18. #endif
  19. typedef unsigned short pinmux_enum_t;
  20. typedef unsigned short pinmux_flag_t;
  21. #define PINMUX_TYPE_NONE 0
  22. #define PINMUX_TYPE_FUNCTION 1
  23. #define PINMUX_TYPE_GPIO 2
  24. #define PINMUX_TYPE_OUTPUT 3
  25. #define PINMUX_TYPE_INPUT 4
  26. #define PINMUX_TYPE_INPUT_PULLUP 5
  27. #define PINMUX_TYPE_INPUT_PULLDOWN 6
  28. #define PINMUX_FLAG_TYPE (0x7)
  29. #define PINMUX_FLAG_WANT_PULLUP (1 << 3)
  30. #define PINMUX_FLAG_WANT_PULLDOWN (1 << 4)
  31. #define PINMUX_FLAG_DBIT_SHIFT 5
  32. #define PINMUX_FLAG_DBIT (0x1f << PINMUX_FLAG_DBIT_SHIFT)
  33. #define PINMUX_FLAG_DREG_SHIFT 10
  34. #define PINMUX_FLAG_DREG (0x3f << PINMUX_FLAG_DREG_SHIFT)
  35. struct pinmux_gpio {
  36. pinmux_enum_t enum_id;
  37. pinmux_flag_t flags;
  38. };
  39. #define PINMUX_GPIO(gpio, data_or_mark) [gpio] = { data_or_mark }
  40. #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
  41. struct pinmux_cfg_reg {
  42. unsigned long reg, reg_width, field_width;
  43. unsigned long *cnt;
  44. pinmux_enum_t *enum_ids;
  45. };
  46. #define PINMUX_CFG_REG(name, r, r_width, f_width) \
  47. .reg = r, .reg_width = r_width, .field_width = f_width, \
  48. .cnt = (unsigned long [r_width / f_width]) {}, \
  49. .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)]) \
  50. struct pinmux_data_reg {
  51. unsigned long reg, reg_width, reg_shadow;
  52. pinmux_enum_t *enum_ids;
  53. };
  54. #define PINMUX_DATA_REG(name, r, r_width) \
  55. .reg = r, .reg_width = r_width, \
  56. .enum_ids = (pinmux_enum_t [r_width]) \
  57. struct pinmux_range {
  58. pinmux_enum_t begin;
  59. pinmux_enum_t end;
  60. pinmux_enum_t force;
  61. };
  62. struct pinmux_info {
  63. char *name;
  64. pinmux_enum_t reserved_id;
  65. struct pinmux_range data;
  66. struct pinmux_range input;
  67. struct pinmux_range input_pd;
  68. struct pinmux_range input_pu;
  69. struct pinmux_range output;
  70. struct pinmux_range mark;
  71. struct pinmux_range function;
  72. unsigned first_gpio, last_gpio;
  73. struct pinmux_gpio *gpios;
  74. struct pinmux_cfg_reg *cfg_regs;
  75. struct pinmux_data_reg *data_regs;
  76. pinmux_enum_t *gpio_data;
  77. unsigned int gpio_data_size;
  78. unsigned long *gpio_in_use;
  79. };
  80. int register_pinmux(struct pinmux_info *pip);
  81. int __gpio_request(unsigned gpio);
  82. static inline int gpio_request(unsigned gpio, const char *label)
  83. {
  84. return __gpio_request(gpio);
  85. }
  86. void gpio_free(unsigned gpio);
  87. int gpio_direction_input(unsigned gpio);
  88. int gpio_direction_output(unsigned gpio, int value);
  89. int gpio_get_value(unsigned gpio);
  90. void gpio_set_value(unsigned gpio, int value);
  91. /* IRQ modes are unspported */
  92. static inline int gpio_to_irq(unsigned gpio)
  93. {
  94. WARN_ON(1);
  95. return -EINVAL;
  96. }
  97. static inline int irq_to_gpio(unsigned irq)
  98. {
  99. WARN_ON(1);
  100. return -EINVAL;
  101. }
  102. #include <asm-generic/gpio.h>
  103. #endif /* __ASM_SH_GPIO_H */