gpio-core.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* linux/arch/arm/plat-s3c/include/plat/gpio-core.h
  2. *
  3. * Copyright 2008 Simtec Electronics
  4. * http://armlinux.simtec.co.uk/
  5. * Ben Dooks <ben@simtec.co.uk>
  6. *
  7. * S3C Platform - GPIO core
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #define GPIOCON_OFF (0x00)
  14. #define GPIODAT_OFF (0x04)
  15. #define con_4bit_shift(__off) ((__off) * 4)
  16. /* Define the core gpiolib support functions that the s3c platforms may
  17. * need to extend or change depending on the hardware and the s3c chip
  18. * selected at build or found at run time.
  19. *
  20. * These definitions are not intended for driver inclusion, there is
  21. * nothing here that should not live outside the platform and core
  22. * specific code.
  23. */
  24. struct s3c_gpio_chip;
  25. /**
  26. * struct s3c_gpio_pm - power management (suspend/resume) information
  27. * @save: Routine to save the state of the GPIO block
  28. * @resume: Routine to resume the GPIO block.
  29. */
  30. struct s3c_gpio_pm {
  31. void (*save)(struct s3c_gpio_chip *chip);
  32. void (*resume)(struct s3c_gpio_chip *chip);
  33. };
  34. struct s3c_gpio_cfg;
  35. /**
  36. * struct s3c_gpio_chip - wrapper for specific implementation of gpio
  37. * @chip: The chip structure to be exported via gpiolib.
  38. * @base: The base pointer to the gpio configuration registers.
  39. * @config: special function and pull-resistor control information.
  40. * @lock: Lock for exclusive access to this gpio bank.
  41. * @pm_save: Save information for suspend/resume support.
  42. *
  43. * This wrapper provides the necessary information for the Samsung
  44. * specific gpios being registered with gpiolib.
  45. *
  46. * The lock protects each gpio bank from multiple access of the shared
  47. * configuration registers, or from reading of data whilst another thread
  48. * is writing to the register set.
  49. *
  50. * Each chip has its own lock to avoid any contention between different
  51. * CPU cores trying to get one lock for different GPIO banks, where each
  52. * bank of GPIO has its own register space and configuration registers.
  53. */
  54. struct s3c_gpio_chip {
  55. struct gpio_chip chip;
  56. struct s3c_gpio_cfg *config;
  57. struct s3c_gpio_pm *pm;
  58. void __iomem *base;
  59. spinlock_t lock;
  60. #ifdef CONFIG_PM
  61. u32 pm_save[4];
  62. #endif
  63. };
  64. static inline struct s3c_gpio_chip *to_s3c_gpio(struct gpio_chip *gpc)
  65. {
  66. return container_of(gpc, struct s3c_gpio_chip, chip);
  67. }
  68. /** s3c_gpiolib_add() - add the s3c specific version of a gpio_chip.
  69. * @chip: The chip to register
  70. *
  71. * This is a wrapper to gpiochip_add() that takes our specific gpio chip
  72. * information and makes the necessary alterations for the platform and
  73. * notes the information for use with the configuration systems and any
  74. * other parts of the system.
  75. */
  76. extern void s3c_gpiolib_add(struct s3c_gpio_chip *chip);
  77. /* CONFIG_S3C_GPIO_TRACK enables the tracking of the s3c specific gpios
  78. * for use with the configuration calls, and other parts of the s3c gpiolib
  79. * support code.
  80. *
  81. * Not all s3c support code will need this, as some configurations of cpu
  82. * may only support one or two different configuration options and have an
  83. * easy gpio to s3c_gpio_chip mapping function. If this is the case, then
  84. * the machine support file should provide its own s3c_gpiolib_getchip()
  85. * and any other necessary functions.
  86. */
  87. /**
  88. * samsung_gpiolib_add_4bit_chips - 4bit single register GPIO config.
  89. * @chip: The gpio chip that is being configured.
  90. * @nr_chips: The no of chips (gpio ports) for the GPIO being configured.
  91. *
  92. * This helper deal with the GPIO cases where the control register has 4 bits
  93. * of control per GPIO, generally in the form of:
  94. * 0000 = Input
  95. * 0001 = Output
  96. * others = Special functions (dependant on bank)
  97. *
  98. * Note, since the code to deal with the case where there are two control
  99. * registers instead of one, we do not have a separate set of function
  100. * (samsung_gpiolib_add_4bit2_chips)for each case.
  101. */
  102. extern void samsung_gpiolib_add_4bit_chips(struct s3c_gpio_chip *chip,
  103. int nr_chips);
  104. extern void samsung_gpiolib_add_4bit2_chips(struct s3c_gpio_chip *chip,
  105. int nr_chips);
  106. extern void samsung_gpiolib_add_4bit(struct s3c_gpio_chip *chip);
  107. extern void samsung_gpiolib_add_4bit2(struct s3c_gpio_chip *chip);
  108. /* exported for core SoC support to change */
  109. extern struct s3c_gpio_cfg s3c24xx_gpiocfg_default;
  110. #ifdef CONFIG_S3C_GPIO_TRACK
  111. extern struct s3c_gpio_chip *s3c_gpios[S3C_GPIO_END];
  112. static inline struct s3c_gpio_chip *s3c_gpiolib_getchip(unsigned int chip)
  113. {
  114. return (chip < S3C_GPIO_END) ? s3c_gpios[chip] : NULL;
  115. }
  116. #else
  117. /* machine specific code should provide s3c_gpiolib_getchip */
  118. #include <mach/gpio-track.h>
  119. static inline void s3c_gpiolib_track(struct s3c_gpio_chip *chip) { }
  120. #endif
  121. #ifdef CONFIG_PM
  122. extern struct s3c_gpio_pm s3c_gpio_pm_1bit;
  123. extern struct s3c_gpio_pm s3c_gpio_pm_2bit;
  124. extern struct s3c_gpio_pm s3c_gpio_pm_4bit;
  125. #define __gpio_pm(x) x
  126. #else
  127. #define s3c_gpio_pm_1bit NULL
  128. #define s3c_gpio_pm_2bit NULL
  129. #define s3c_gpio_pm_4bit NULL
  130. #define __gpio_pm(x) NULL
  131. #endif /* CONFIG_PM */
  132. /* locking wrappers to deal with multiple access to the same gpio bank */
  133. #define s3c_gpio_lock(_oc, _fl) spin_lock_irqsave(&(_oc)->lock, _fl)
  134. #define s3c_gpio_unlock(_oc, _fl) spin_unlock_irqrestore(&(_oc)->lock, _fl)