gpio.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 char 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. struct pinmux_gpio {
  32. pinmux_enum_t enum_id;
  33. pinmux_flag_t flags;
  34. };
  35. #define PINMUX_GPIO(gpio, data_or_mark) [gpio] = { data_or_mark }
  36. #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
  37. struct pinmux_cfg_reg {
  38. unsigned long reg, reg_width, field_width;
  39. unsigned long *cnt;
  40. pinmux_enum_t *enum_ids;
  41. };
  42. #define PINMUX_CFG_REG(name, r, r_width, f_width) \
  43. .reg = r, .reg_width = r_width, .field_width = f_width, \
  44. .cnt = (unsigned long [r_width / f_width]) {}, \
  45. .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)]) \
  46. struct pinmux_data_reg {
  47. unsigned long reg, reg_width;
  48. pinmux_enum_t *enum_ids;
  49. };
  50. #define PINMUX_DATA_REG(name, r, r_width) \
  51. .reg = r, .reg_width = r_width, \
  52. .enum_ids = (pinmux_enum_t [r_width]) \
  53. struct pinmux_range {
  54. pinmux_enum_t begin;
  55. pinmux_enum_t end;
  56. pinmux_enum_t force;
  57. };
  58. struct pinmux_info {
  59. char *name;
  60. pinmux_enum_t reserved_id;
  61. struct pinmux_range data;
  62. struct pinmux_range input;
  63. struct pinmux_range input_pd;
  64. struct pinmux_range input_pu;
  65. struct pinmux_range output;
  66. struct pinmux_range mark;
  67. struct pinmux_range function;
  68. unsigned first_gpio, last_gpio;
  69. struct pinmux_gpio *gpios;
  70. struct pinmux_cfg_reg *cfg_regs;
  71. struct pinmux_data_reg *data_regs;
  72. pinmux_enum_t *gpio_data;
  73. unsigned int gpio_data_size;
  74. unsigned long *gpio_in_use;
  75. };
  76. int register_pinmux(struct pinmux_info *pip);
  77. int __gpio_request(unsigned gpio);
  78. static inline int gpio_request(unsigned gpio, const char *label)
  79. {
  80. return __gpio_request(gpio);
  81. }
  82. void gpio_free(unsigned gpio);
  83. int gpio_direction_input(unsigned gpio);
  84. int gpio_direction_output(unsigned gpio, int value);
  85. int gpio_get_value(unsigned gpio);
  86. void gpio_set_value(unsigned gpio, int value);
  87. /* IRQ modes are unspported */
  88. static inline int gpio_to_irq(unsigned gpio)
  89. {
  90. WARN_ON(1);
  91. return -EINVAL;
  92. }
  93. static inline int irq_to_gpio(unsigned irq)
  94. {
  95. WARN_ON(1);
  96. return -EINVAL;
  97. }
  98. #include <asm-generic/gpio.h>
  99. #endif /* __ASM_SH_GPIO_H */