pinmux.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Interface the pinmux subsystem
  3. *
  4. * Copyright (C) 2011 ST-Ericsson SA
  5. * Written on behalf of Linaro for ST-Ericsson
  6. * Based on bits of regulator core, gpio core and clk core
  7. *
  8. * Author: Linus Walleij <linus.walleij@linaro.org>
  9. *
  10. * License terms: GNU General Public License (GPL) version 2
  11. */
  12. #ifndef __LINUX_PINCTRL_PINMUX_H
  13. #define __LINUX_PINCTRL_PINMUX_H
  14. #include <linux/list.h>
  15. #include <linux/seq_file.h>
  16. #include "pinctrl.h"
  17. /* This struct is private to the core and should be regarded as a cookie */
  18. struct pinmux;
  19. #ifdef CONFIG_PINMUX
  20. struct pinctrl_dev;
  21. /**
  22. * struct pinmux_ops - pinmux operations, to be implemented by pin controller
  23. * drivers that support pinmuxing
  24. * @request: called by the core to see if a certain pin can be made available
  25. * available for muxing. This is called by the core to acquire the pins
  26. * before selecting any actual mux setting across a function. The driver
  27. * is allowed to answer "no" by returning a negative error code
  28. * @free: the reverse function of the request() callback, frees a pin after
  29. * being requested
  30. * @list_functions: list the number of selectable named functions available
  31. * in this pinmux driver, the core will begin on 0 and call this
  32. * repeatedly as long as it returns >= 0 to enumerate mux settings
  33. * @get_function_name: return the function name of the muxing selector,
  34. * called by the core to figure out which mux setting it shall map a
  35. * certain device to
  36. * @get_function_groups: return an array of groups names (in turn
  37. * referencing pins) connected to a certain function selector. The group
  38. * name can be used with the generic @pinctrl_ops to retrieve the
  39. * actual pins affected. The applicable groups will be returned in
  40. * @groups and the number of groups in @num_groups
  41. * @enable: enable a certain muxing function with a certain pin group. The
  42. * driver does not need to figure out whether enabling this function
  43. * conflicts some other use of the pins in that group, such collisions
  44. * are handled by the pinmux subsystem. The @func_selector selects a
  45. * certain function whereas @group_selector selects a certain set of pins
  46. * to be used. On simple controllers the latter argument may be ignored
  47. * @disable: disable a certain muxing selector with a certain pin group
  48. * @gpio_request_enable: requests and enables GPIO on a certain pin.
  49. * Implement this only if you can mux every pin individually as GPIO. The
  50. * affected GPIO range is passed along with an offset into that
  51. * specific GPIO range - function selectors and pin groups are orthogonal
  52. * to this, the core will however make sure the pins do not collide
  53. */
  54. struct pinmux_ops {
  55. int (*request) (struct pinctrl_dev *pctldev, unsigned offset);
  56. int (*free) (struct pinctrl_dev *pctldev, unsigned offset);
  57. int (*list_functions) (struct pinctrl_dev *pctldev, unsigned selector);
  58. const char *(*get_function_name) (struct pinctrl_dev *pctldev,
  59. unsigned selector);
  60. int (*get_function_groups) (struct pinctrl_dev *pctldev,
  61. unsigned selector,
  62. const char * const **groups,
  63. unsigned * const num_groups);
  64. int (*enable) (struct pinctrl_dev *pctldev, unsigned func_selector,
  65. unsigned group_selector);
  66. void (*disable) (struct pinctrl_dev *pctldev, unsigned func_selector,
  67. unsigned group_selector);
  68. int (*gpio_request_enable) (struct pinctrl_dev *pctldev,
  69. struct pinctrl_gpio_range *range,
  70. unsigned offset);
  71. };
  72. /* External interface to pinmux */
  73. extern int pinmux_request_gpio(unsigned gpio);
  74. extern void pinmux_free_gpio(unsigned gpio);
  75. extern struct pinmux * __must_check pinmux_get(struct device *dev, const char *name);
  76. extern void pinmux_put(struct pinmux *pmx);
  77. extern int pinmux_enable(struct pinmux *pmx);
  78. extern void pinmux_disable(struct pinmux *pmx);
  79. #else /* !CONFIG_PINMUX */
  80. static inline int pinmux_request_gpio(unsigned gpio)
  81. {
  82. return 0;
  83. }
  84. static inline void pinmux_free_gpio(unsigned gpio)
  85. {
  86. }
  87. static inline struct pinmux * __must_check pinmux_get(struct device *dev, const char *name)
  88. {
  89. return NULL;
  90. }
  91. static inline void pinmux_put(struct pinmux *pmx)
  92. {
  93. }
  94. static inline int pinmux_enable(struct pinmux *pmx)
  95. {
  96. return 0;
  97. }
  98. static inline void pinmux_disable(struct pinmux *pmx)
  99. {
  100. }
  101. #endif /* CONFIG_PINMUX */
  102. #endif /* __LINUX_PINCTRL_PINMUX_H */