gpio-core.h 4.4 KB

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