gpio-core.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #ifndef __PLAT_SAMSUNG_GPIO_CORE_H
  14. #define __PLAT_SAMSUNG_GPIO_CORE_H
  15. /* Bring in machine-local definitions, especially S3C_GPIO_END */
  16. #include <mach/gpio-samsung.h>
  17. #define GPIOCON_OFF (0x00)
  18. #define GPIODAT_OFF (0x04)
  19. #define con_4bit_shift(__off) ((__off) * 4)
  20. /* Define the core gpiolib support functions that the s3c platforms may
  21. * need to extend or change depending on the hardware and the s3c chip
  22. * selected at build or found at run time.
  23. *
  24. * These definitions are not intended for driver inclusion, there is
  25. * nothing here that should not live outside the platform and core
  26. * specific code.
  27. */
  28. struct samsung_gpio_chip;
  29. /**
  30. * struct samsung_gpio_pm - power management (suspend/resume) information
  31. * @save: Routine to save the state of the GPIO block
  32. * @resume: Routine to resume the GPIO block.
  33. */
  34. struct samsung_gpio_pm {
  35. void (*save)(struct samsung_gpio_chip *chip);
  36. void (*resume)(struct samsung_gpio_chip *chip);
  37. };
  38. struct samsung_gpio_cfg;
  39. /**
  40. * struct samsung_gpio_chip - wrapper for specific implementation of gpio
  41. * @chip: The chip structure to be exported via gpiolib.
  42. * @base: The base pointer to the gpio configuration registers.
  43. * @group: The group register number for gpio interrupt support.
  44. * @irq_base: The base irq number.
  45. * @config: special function and pull-resistor control information.
  46. * @lock: Lock for exclusive access to this gpio bank.
  47. * @pm_save: Save information for suspend/resume support.
  48. * @bitmap_gpio_int: Bitmap for representing GPIO interrupt or not.
  49. *
  50. * This wrapper provides the necessary information for the Samsung
  51. * specific gpios being registered with gpiolib.
  52. *
  53. * The lock protects each gpio bank from multiple access of the shared
  54. * configuration registers, or from reading of data whilst another thread
  55. * is writing to the register set.
  56. *
  57. * Each chip has its own lock to avoid any contention between different
  58. * CPU cores trying to get one lock for different GPIO banks, where each
  59. * bank of GPIO has its own register space and configuration registers.
  60. */
  61. struct samsung_gpio_chip {
  62. struct gpio_chip chip;
  63. struct samsung_gpio_cfg *config;
  64. struct samsung_gpio_pm *pm;
  65. void __iomem *base;
  66. int irq_base;
  67. int group;
  68. spinlock_t lock;
  69. #ifdef CONFIG_PM
  70. u32 pm_save[4];
  71. #endif
  72. u32 bitmap_gpio_int;
  73. };
  74. static inline struct samsung_gpio_chip *to_samsung_gpio(struct gpio_chip *gpc)
  75. {
  76. return container_of(gpc, struct samsung_gpio_chip, chip);
  77. }
  78. /**
  79. * samsung_gpiolib_to_irq - convert gpio pin to irq number
  80. * @chip: The gpio chip that the pin belongs to.
  81. * @offset: The offset of the pin in the chip.
  82. *
  83. * This helper returns the irq number calculated from the chip->irq_base and
  84. * the provided offset.
  85. */
  86. extern int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset);
  87. /* exported for core SoC support to change */
  88. extern struct samsung_gpio_cfg s3c24xx_gpiocfg_default;
  89. #ifdef CONFIG_S3C_GPIO_TRACK
  90. extern struct samsung_gpio_chip *s3c_gpios[S3C_GPIO_END];
  91. static inline struct samsung_gpio_chip *samsung_gpiolib_getchip(unsigned int chip)
  92. {
  93. return (chip < S3C_GPIO_END) ? s3c_gpios[chip] : NULL;
  94. }
  95. #else
  96. /* machine specific code should provide samsung_gpiolib_getchip */
  97. extern struct samsung_gpio_chip s3c24xx_gpios[];
  98. static inline struct samsung_gpio_chip *samsung_gpiolib_getchip(unsigned int pin)
  99. {
  100. struct samsung_gpio_chip *chip;
  101. if (pin > S3C_GPIO_END)
  102. return NULL;
  103. chip = &s3c24xx_gpios[pin/32];
  104. return ((pin - chip->chip.base) < chip->chip.ngpio) ? chip : NULL;
  105. }
  106. static inline void s3c_gpiolib_track(struct samsung_gpio_chip *chip) { }
  107. #endif
  108. #ifdef CONFIG_PM
  109. extern struct samsung_gpio_pm samsung_gpio_pm_1bit;
  110. extern struct samsung_gpio_pm samsung_gpio_pm_2bit;
  111. extern struct samsung_gpio_pm samsung_gpio_pm_4bit;
  112. #define __gpio_pm(x) x
  113. #else
  114. #define samsung_gpio_pm_1bit NULL
  115. #define samsung_gpio_pm_2bit NULL
  116. #define samsung_gpio_pm_4bit NULL
  117. #define __gpio_pm(x) NULL
  118. #endif /* CONFIG_PM */
  119. /* locking wrappers to deal with multiple access to the same gpio bank */
  120. #define samsung_gpio_lock(_oc, _fl) spin_lock_irqsave(&(_oc)->lock, _fl)
  121. #define samsung_gpio_unlock(_oc, _fl) spin_unlock_irqrestore(&(_oc)->lock, _fl)
  122. #endif /* __PLAT_SAMSUNG_GPIO_CORE_H */