gpio-core.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. * @pm_save: Save information for suspend/resume support.
  41. *
  42. * This wrapper provides the necessary information for the Samsung
  43. * specific gpios being registered with gpiolib.
  44. */
  45. struct s3c_gpio_chip {
  46. struct gpio_chip chip;
  47. struct s3c_gpio_cfg *config;
  48. struct s3c_gpio_pm *pm;
  49. void __iomem *base;
  50. #ifdef CONFIG_PM
  51. u32 pm_save[4];
  52. #endif
  53. };
  54. static inline struct s3c_gpio_chip *to_s3c_gpio(struct gpio_chip *gpc)
  55. {
  56. return container_of(gpc, struct s3c_gpio_chip, chip);
  57. }
  58. /** s3c_gpiolib_add() - add the s3c specific version of a gpio_chip.
  59. * @chip: The chip to register
  60. *
  61. * This is a wrapper to gpiochip_add() that takes our specific gpio chip
  62. * information and makes the necessary alterations for the platform and
  63. * notes the information for use with the configuration systems and any
  64. * other parts of the system.
  65. */
  66. extern void s3c_gpiolib_add(struct s3c_gpio_chip *chip);
  67. /* CONFIG_S3C_GPIO_TRACK enables the tracking of the s3c specific gpios
  68. * for use with the configuration calls, and other parts of the s3c gpiolib
  69. * support code.
  70. *
  71. * Not all s3c support code will need this, as some configurations of cpu
  72. * may only support one or two different configuration options and have an
  73. * easy gpio to s3c_gpio_chip mapping function. If this is the case, then
  74. * the machine support file should provide its own s3c_gpiolib_getchip()
  75. * and any other necessary functions.
  76. */
  77. /**
  78. * samsung_gpiolib_add_4bit_chips - 4bit single register GPIO config.
  79. * @chip: The gpio chip that is being configured.
  80. * @nr_chips: The no of chips (gpio ports) for the GPIO being configured.
  81. *
  82. * This helper deal with the GPIO cases where the control register has 4 bits
  83. * of control per GPIO, generally in the form of:
  84. * 0000 = Input
  85. * 0001 = Output
  86. * others = Special functions (dependant on bank)
  87. *
  88. * Note, since the code to deal with the case where there are two control
  89. * registers instead of one, we do not have a seperate set of function
  90. * (samsung_gpiolib_add_4bit2_chips)for each case.
  91. */
  92. extern void samsung_gpiolib_add_4bit_chips(struct s3c_gpio_chip *chip,
  93. int nr_chips);
  94. extern void samsung_gpiolib_add_4bit2_chips(struct s3c_gpio_chip *chip,
  95. int nr_chips);
  96. extern void samsung_gpiolib_add_4bit(struct s3c_gpio_chip *chip);
  97. extern void samsung_gpiolib_add_4bit2(struct s3c_gpio_chip *chip);
  98. #ifdef CONFIG_S3C_GPIO_TRACK
  99. extern struct s3c_gpio_chip *s3c_gpios[S3C_GPIO_END];
  100. static inline struct s3c_gpio_chip *s3c_gpiolib_getchip(unsigned int chip)
  101. {
  102. return (chip < S3C_GPIO_END) ? s3c_gpios[chip] : NULL;
  103. }
  104. #else
  105. /* machine specific code should provide s3c_gpiolib_getchip */
  106. static inline void s3c_gpiolib_track(struct s3c_gpio_chip *chip) { }
  107. #endif
  108. #ifdef CONFIG_PM
  109. extern struct s3c_gpio_pm s3c_gpio_pm_1bit;
  110. extern struct s3c_gpio_pm s3c_gpio_pm_2bit;
  111. extern struct s3c_gpio_pm s3c_gpio_pm_4bit;
  112. #define __gpio_pm(x) x
  113. #else
  114. #define s3c_gpio_pm_1bit NULL
  115. #define s3c_gpio_pm_2bit NULL
  116. #define s3c_gpio_pm_4bit NULL
  117. #define __gpio_pm(x) NULL
  118. #endif /* CONFIG_PM */