gpio-cfg.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* linux/arch/arm/plat-s3c/include/plat/gpio-cfg.h
  2. *
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * http://armlinux.simtec.co.uk/
  6. * Ben Dooks <ben@simtec.co.uk>
  7. *
  8. * S3C Platform - GPIO pin configuration
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. /* This file contains the necessary definitions to get the basic gpio
  15. * pin configuration done such as setting a pin to input or output or
  16. * changing the pull-{up,down} configurations.
  17. */
  18. /* Note, this interface is being added to the s3c64xx arch first and will
  19. * be added to the s3c24xx systems later.
  20. */
  21. #ifndef __PLAT_GPIO_CFG_H
  22. #define __PLAT_GPIO_CFG_H __FILE__
  23. typedef unsigned int __bitwise__ s3c_gpio_pull_t;
  24. typedef unsigned int __bitwise__ s5p_gpio_drvstr_t;
  25. /* forward declaration if gpio-core.h hasn't been included */
  26. struct s3c_gpio_chip;
  27. /**
  28. * struct s3c_gpio_cfg GPIO configuration
  29. * @cfg_eint: Configuration setting when used for external interrupt source
  30. * @get_pull: Read the current pull configuration for the GPIO
  31. * @set_pull: Set the current pull configuraiton for the GPIO
  32. * @set_config: Set the current configuration for the GPIO
  33. * @get_config: Read the current configuration for the GPIO
  34. *
  35. * Each chip can have more than one type of GPIO bank available and some
  36. * have different capabilites even when they have the same control register
  37. * layouts. Provide an point to vector control routine and provide any
  38. * per-bank configuration information that other systems such as the
  39. * external interrupt code will need.
  40. */
  41. struct s3c_gpio_cfg {
  42. unsigned int cfg_eint;
  43. s3c_gpio_pull_t (*get_pull)(struct s3c_gpio_chip *chip, unsigned offs);
  44. int (*set_pull)(struct s3c_gpio_chip *chip, unsigned offs,
  45. s3c_gpio_pull_t pull);
  46. unsigned (*get_config)(struct s3c_gpio_chip *chip, unsigned offs);
  47. int (*set_config)(struct s3c_gpio_chip *chip, unsigned offs,
  48. unsigned config);
  49. };
  50. #define S3C_GPIO_SPECIAL_MARK (0xfffffff0)
  51. #define S3C_GPIO_SPECIAL(x) (S3C_GPIO_SPECIAL_MARK | (x))
  52. /* Defines for generic pin configurations */
  53. #define S3C_GPIO_INPUT (S3C_GPIO_SPECIAL(0))
  54. #define S3C_GPIO_OUTPUT (S3C_GPIO_SPECIAL(1))
  55. #define S3C_GPIO_SFN(x) (S3C_GPIO_SPECIAL(x))
  56. #define s3c_gpio_is_cfg_special(_cfg) \
  57. (((_cfg) & S3C_GPIO_SPECIAL_MARK) == S3C_GPIO_SPECIAL_MARK)
  58. /**
  59. * s3c_gpio_cfgpin() - Change the GPIO function of a pin.
  60. * @pin pin The pin number to configure.
  61. * @to to The configuration for the pin's function.
  62. *
  63. * Configure which function is actually connected to the external
  64. * pin, such as an gpio input, output or some form of special function
  65. * connected to an internal peripheral block.
  66. */
  67. extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to);
  68. /**
  69. * s3c_gpio_getcfg - Read the current function for a GPIO pin
  70. * @pin: The pin to read the configuration value for.
  71. *
  72. * Read the configuration state of the given @pin, returning a value that
  73. * could be passed back to s3c_gpio_cfgpin().
  74. *
  75. * @sa s3c_gpio_cfgpin
  76. */
  77. extern unsigned s3c_gpio_getcfg(unsigned int pin);
  78. /* Define values for the pull-{up,down} available for each gpio pin.
  79. *
  80. * These values control the state of the weak pull-{up,down} resistors
  81. * available on most pins on the S3C series. Not all chips support both
  82. * up or down settings, and it may be dependant on the chip that is being
  83. * used to whether the particular mode is available.
  84. */
  85. #define S3C_GPIO_PULL_NONE ((__force s3c_gpio_pull_t)0x00)
  86. #define S3C_GPIO_PULL_DOWN ((__force s3c_gpio_pull_t)0x01)
  87. #define S3C_GPIO_PULL_UP ((__force s3c_gpio_pull_t)0x02)
  88. /**
  89. * s3c_gpio_setpull() - set the state of a gpio pin pull resistor
  90. * @pin: The pin number to configure the pull resistor.
  91. * @pull: The configuration for the pull resistor.
  92. *
  93. * This function sets the state of the pull-{up,down} resistor for the
  94. * specified pin. It will return 0 if successfull, or a negative error
  95. * code if the pin cannot support the requested pull setting.
  96. */
  97. extern int s3c_gpio_setpull(unsigned int pin, s3c_gpio_pull_t pull);
  98. /**
  99. * s3c_gpio_getpull() - get the pull resistor state of a gpio pin
  100. * @pin: The pin number to get the settings for
  101. *
  102. * Read the pull resistor value for the specified pin.
  103. */
  104. extern s3c_gpio_pull_t s3c_gpio_getpull(unsigned int pin);
  105. /* Define values for the drvstr available for each gpio pin.
  106. *
  107. * These values control the value of the output signal driver strength,
  108. * configurable on most pins on the S5C series.
  109. */
  110. #define S5P_GPIO_DRVSTR_LV1 ((__force s5p_gpio_drvstr_t)0x00)
  111. #define S5P_GPIO_DRVSTR_LV2 ((__force s5p_gpio_drvstr_t)0x01)
  112. #define S5P_GPIO_DRVSTR_LV3 ((__force s5p_gpio_drvstr_t)0x10)
  113. #define S5P_GPIO_DRVSTR_LV4 ((__force s5p_gpio_drvstr_t)0x11)
  114. /**
  115. * s5c_gpio_get_drvstr() - get the driver streght value of a gpio pin
  116. * @pin: The pin number to get the settings for
  117. *
  118. * Read the driver streght value for the specified pin.
  119. */
  120. extern s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin);
  121. /**
  122. * s3c_gpio_set_drvstr() - set the driver streght value of a gpio pin
  123. * @pin: The pin number to configure the driver streght value
  124. * @drvstr: The new value of the driver strength
  125. *
  126. * This function sets the driver strength value for the specified pin.
  127. * It will return 0 if successfull, or a negative error code if the pin
  128. * cannot support the requested setting.
  129. */
  130. extern int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr);
  131. #endif /* __PLAT_GPIO_CFG_H */