gpio.h 2.6 KB

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