pinctrl.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Interface the pinctrl subsystem
  3. *
  4. * Copyright (C) 2011 ST-Ericsson SA
  5. * Written on behalf of Linaro for ST-Ericsson
  6. * This interface is used in the core to keep track of pins.
  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_PINCTRL_H
  13. #define __LINUX_PINCTRL_PINCTRL_H
  14. #ifdef CONFIG_PINCTRL
  15. #include <linux/radix-tree.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/list.h>
  18. #include <linux/seq_file.h>
  19. struct pinctrl_dev;
  20. struct pinmux_ops;
  21. struct gpio_chip;
  22. /**
  23. * struct pinctrl_pin_desc - boards/machines provide information on their
  24. * pins, pads or other muxable units in this struct
  25. * @number: unique pin number from the global pin number space
  26. * @name: a name for this pin
  27. */
  28. struct pinctrl_pin_desc {
  29. unsigned number;
  30. const char *name;
  31. };
  32. /* Convenience macro to define a single named or anonymous pin descriptor */
  33. #define PINCTRL_PIN(a, b) { .number = a, .name = b }
  34. #define PINCTRL_PIN_ANON(a) { .number = a }
  35. /**
  36. * struct pinctrl_gpio_range - each pin controller can provide subranges of
  37. * the GPIO number space to be handled by the controller
  38. * @node: list node for internal use
  39. * @name: a name for the chip in this range
  40. * @id: an ID number for the chip in this range
  41. * @base: base offset of the GPIO range
  42. * @pin_base: base pin number of the GPIO range
  43. * @npins: number of pins in the GPIO range, including the base number
  44. * @gc: an optional pointer to a gpio_chip
  45. */
  46. struct pinctrl_gpio_range {
  47. struct list_head node;
  48. const char *name;
  49. unsigned int id;
  50. unsigned int base;
  51. unsigned int pin_base;
  52. unsigned int npins;
  53. struct gpio_chip *gc;
  54. };
  55. /**
  56. * struct pinctrl_ops - global pin control operations, to be implemented by
  57. * pin controller drivers.
  58. * @list_groups: list the number of selectable named groups available
  59. * in this pinmux driver, the core will begin on 0 and call this
  60. * repeatedly as long as it returns >= 0 to enumerate the groups
  61. * @get_group_name: return the group name of the pin group
  62. * @get_group_pins: return an array of pins corresponding to a certain
  63. * group selector @pins, and the size of the array in @num_pins
  64. * @pin_dbg_show: optional debugfs display hook that will provide per-device
  65. * info for a certain pin in debugfs
  66. */
  67. struct pinctrl_ops {
  68. int (*list_groups) (struct pinctrl_dev *pctldev, unsigned selector);
  69. const char *(*get_group_name) (struct pinctrl_dev *pctldev,
  70. unsigned selector);
  71. int (*get_group_pins) (struct pinctrl_dev *pctldev,
  72. unsigned selector,
  73. const unsigned **pins,
  74. unsigned *num_pins);
  75. void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s,
  76. unsigned offset);
  77. };
  78. /**
  79. * struct pinctrl_desc - pin controller descriptor, register this to pin
  80. * control subsystem
  81. * @name: name for the pin controller
  82. * @pins: an array of pin descriptors describing all the pins handled by
  83. * this pin controller
  84. * @npins: number of descriptors in the array, usually just ARRAY_SIZE()
  85. * of the pins field above
  86. * @maxpin: since pin spaces may be sparse, there can he "holes" in the
  87. * pin range, this attribute gives the maximum pin number in the
  88. * total range. This should not be lower than npins for example,
  89. * but may be equal to npins if you have no holes in the pin range.
  90. * @pctlops: pin control operation vtable, to support global concepts like
  91. * grouping of pins, this is optional.
  92. * @pmxops: pinmux operation vtable, if you support pinmuxing in your driver
  93. * @owner: module providing the pin controller, used for refcounting
  94. */
  95. struct pinctrl_desc {
  96. const char *name;
  97. struct pinctrl_pin_desc const *pins;
  98. unsigned int npins;
  99. unsigned int maxpin;
  100. struct pinctrl_ops *pctlops;
  101. struct pinmux_ops *pmxops;
  102. struct module *owner;
  103. };
  104. /* External interface to pin controller */
  105. extern struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
  106. struct device *dev, void *driver_data);
  107. extern void pinctrl_unregister(struct pinctrl_dev *pctldev);
  108. extern bool pin_is_valid(struct pinctrl_dev *pctldev, int pin);
  109. extern void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
  110. struct pinctrl_gpio_range *range);
  111. extern void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
  112. struct pinctrl_gpio_range *range);
  113. extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev);
  114. extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev);
  115. #else
  116. struct pinctrl_dev;
  117. /* Sufficiently stupid default function when pinctrl is not in use */
  118. static inline bool pin_is_valid(struct pinctrl_dev *pctldev, int pin)
  119. {
  120. return pin >= 0;
  121. }
  122. #endif /* !CONFIG_PINCTRL */
  123. #endif /* __LINUX_PINCTRL_PINCTRL_H */