gpio-core.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 the core gpiolib support functions that the s3c platforms may
  14. * need to extend or change depending on the hardware and the s3c chip
  15. * selected at build or found at run time.
  16. *
  17. * These definitions are not intended for driver inclusion, there is
  18. * nothing here that should not live outside the platform and core
  19. * specific code.
  20. */
  21. struct s3c_gpio_chip;
  22. /**
  23. * struct s3c_gpio_pm - power management (suspend/resume) information
  24. * @save: Routine to save the state of the GPIO block
  25. * @resume: Routine to resume the GPIO block.
  26. */
  27. struct s3c_gpio_pm {
  28. void (*save)(struct s3c_gpio_chip *chip);
  29. void (*resume)(struct s3c_gpio_chip *chip);
  30. };
  31. struct s3c_gpio_cfg;
  32. /**
  33. * struct s3c_gpio_chip - wrapper for specific implementation of gpio
  34. * @chip: The chip structure to be exported via gpiolib.
  35. * @base: The base pointer to the gpio configuration registers.
  36. * @config: special function and pull-resistor control information.
  37. * @pm_save: Save information for suspend/resume support.
  38. *
  39. * This wrapper provides the necessary information for the Samsung
  40. * specific gpios being registered with gpiolib.
  41. */
  42. struct s3c_gpio_chip {
  43. struct gpio_chip chip;
  44. struct s3c_gpio_cfg *config;
  45. struct s3c_gpio_pm *pm;
  46. void __iomem *base;
  47. #ifdef CONFIG_PM
  48. u32 pm_save[4];
  49. #endif
  50. };
  51. static inline struct s3c_gpio_chip *to_s3c_gpio(struct gpio_chip *gpc)
  52. {
  53. return container_of(gpc, struct s3c_gpio_chip, chip);
  54. }
  55. /** s3c_gpiolib_add() - add the s3c specific version of a gpio_chip.
  56. * @chip: The chip to register
  57. *
  58. * This is a wrapper to gpiochip_add() that takes our specific gpio chip
  59. * information and makes the necessary alterations for the platform and
  60. * notes the information for use with the configuration systems and any
  61. * other parts of the system.
  62. */
  63. extern void s3c_gpiolib_add(struct s3c_gpio_chip *chip);
  64. /* CONFIG_S3C_GPIO_TRACK enables the tracking of the s3c specific gpios
  65. * for use with the configuration calls, and other parts of the s3c gpiolib
  66. * support code.
  67. *
  68. * Not all s3c support code will need this, as some configurations of cpu
  69. * may only support one or two different configuration options and have an
  70. * easy gpio to s3c_gpio_chip mapping function. If this is the case, then
  71. * the machine support file should provide its own s3c_gpiolib_getchip()
  72. * and any other necessary functions.
  73. */
  74. #ifdef CONFIG_S3C_GPIO_TRACK
  75. extern struct s3c_gpio_chip *s3c_gpios[S3C_GPIO_END];
  76. static inline struct s3c_gpio_chip *s3c_gpiolib_getchip(unsigned int chip)
  77. {
  78. return (chip < S3C_GPIO_END) ? s3c_gpios[chip] : NULL;
  79. }
  80. #else
  81. /* machine specific code should provide s3c_gpiolib_getchip */
  82. static inline void s3c_gpiolib_track(struct s3c_gpio_chip *chip) { }
  83. #endif
  84. #ifdef CONFIG_PM
  85. extern struct s3c_gpio_pm s3c_gpio_pm_1bit;
  86. extern struct s3c_gpio_pm s3c_gpio_pm_2bit;
  87. extern struct s3c_gpio_pm s3c_gpio_pm_4bit;
  88. #define __gpio_pm(x) x
  89. #else
  90. #define s3c_gpio_pm_1bit NULL
  91. #define s3c_gpio_pm_2bit NULL
  92. #define s3c_gpio_pm_4bit NULL
  93. #define __gpio_pm(x) NULL
  94. #endif /* CONFIG_PM */