gpio-cfg.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. /* forward declaration if gpio-core.h hasn't been included */
  25. struct s3c_gpio_chip;
  26. /**
  27. * struct s3c_gpio_cfg GPIO configuration
  28. * @cfg_eint: Configuration setting when used for external interrupt source
  29. * @get_pull: Read the current pull configuration for the GPIO
  30. * @set_pull: Set the current pull configuraiton for the GPIO
  31. * @set_config: Set the current configuration for the GPIO
  32. * @get_config: Read the current configuration for the GPIO
  33. *
  34. * Each chip can have more than one type of GPIO bank available and some
  35. * have different capabilites even when they have the same control register
  36. * layouts. Provide an point to vector control routine and provide any
  37. * per-bank configuration information that other systems such as the
  38. * external interrupt code will need.
  39. */
  40. struct s3c_gpio_cfg {
  41. unsigned int cfg_eint;
  42. s3c_gpio_pull_t (*get_pull)(struct s3c_gpio_chip *chip, unsigned offs);
  43. int (*set_pull)(struct s3c_gpio_chip *chip, unsigned offs,
  44. s3c_gpio_pull_t pull);
  45. unsigned (*get_config)(struct s3c_gpio_chip *chip, unsigned offs);
  46. int (*set_config)(struct s3c_gpio_chip *chip, unsigned offs,
  47. unsigned config);
  48. };
  49. #define S3C_GPIO_SPECIAL_MARK (0xfffffff0)
  50. #define S3C_GPIO_SPECIAL(x) (S3C_GPIO_SPECIAL_MARK | (x))
  51. /* Defines for generic pin configurations */
  52. #define S3C_GPIO_INPUT (S3C_GPIO_SPECIAL(0))
  53. #define S3C_GPIO_OUTPUT (S3C_GPIO_SPECIAL(1))
  54. #define S3C_GPIO_SFN(x) (S3C_GPIO_SPECIAL(x))
  55. #define s3c_gpio_is_cfg_special(_cfg) \
  56. (((_cfg) & S3C_GPIO_SPECIAL_MARK) == S3C_GPIO_SPECIAL_MARK)
  57. /**
  58. * s3c_gpio_cfgpin() - Change the GPIO function of a pin.
  59. * @pin pin The pin number to configure.
  60. * @pin to The configuration for the pin's function.
  61. *
  62. * Configure which function is actually connected to the external
  63. * pin, such as an gpio input, output or some form of special function
  64. * connected to an internal peripheral block.
  65. */
  66. extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to);
  67. /* Define values for the pull-{up,down} available for each gpio pin.
  68. *
  69. * These values control the state of the weak pull-{up,down} resistors
  70. * available on most pins on the S3C series. Not all chips support both
  71. * up or down settings, and it may be dependant on the chip that is being
  72. * used to whether the particular mode is available.
  73. */
  74. #define S3C_GPIO_PULL_NONE ((__force s3c_gpio_pull_t)0x00)
  75. #define S3C_GPIO_PULL_DOWN ((__force s3c_gpio_pull_t)0x01)
  76. #define S3C_GPIO_PULL_UP ((__force s3c_gpio_pull_t)0x02)
  77. /**
  78. * s3c_gpio_setpull() - set the state of a gpio pin pull resistor
  79. * @pin: The pin number to configure the pull resistor.
  80. * @pull: The configuration for the pull resistor.
  81. *
  82. * This function sets the state of the pull-{up,down} resistor for the
  83. * specified pin. It will return 0 if successfull, or a negative error
  84. * code if the pin cannot support the requested pull setting.
  85. */
  86. extern int s3c_gpio_setpull(unsigned int pin, s3c_gpio_pull_t pull);
  87. /**
  88. * s3c_gpio_getpull() - get the pull resistor state of a gpio pin
  89. * @pin: The pin number to get the settings for
  90. *
  91. * Read the pull resistor value for the specified pin.
  92. */
  93. extern s3c_gpio_pull_t s3c_gpio_getpull(unsigned int pin);
  94. #endif /* __PLAT_GPIO_CFG_H */