pinmux.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Freescale STMP37XX/STMP378X Pin Multiplexing
  3. *
  4. * Author: Vladislav Buzov <vbuzov@embeddedalley.com>
  5. *
  6. * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
  7. * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
  8. */
  9. /*
  10. * The code contained herein is licensed under the GNU General Public
  11. * License. You may obtain a copy of the GNU General Public License
  12. * Version 2 or later at the following locations:
  13. *
  14. * http://www.opensource.org/licenses/gpl-license.html
  15. * http://www.gnu.org/copyleft/gpl.html
  16. */
  17. #ifndef __PINMUX_H
  18. #define __PINMUX_H
  19. #include <linux/spinlock.h>
  20. #include <linux/types.h>
  21. #include <linux/gpio.h>
  22. #include <asm-generic/gpio.h>
  23. /* Pin definitions */
  24. #include "pins.h"
  25. #include <mach/pins.h>
  26. /*
  27. * Each pin may be routed up to four different HW interfaces
  28. * including GPIO
  29. */
  30. enum pin_fun {
  31. PIN_FUN1 = 0,
  32. PIN_FUN2,
  33. PIN_FUN3,
  34. PIN_GPIO,
  35. };
  36. /*
  37. * Each pin may have different output drive strength in range from
  38. * 4mA to 20mA. The most common case is 4, 8 and 12 mA strengths.
  39. */
  40. enum pin_strength {
  41. PIN_4MA = 0,
  42. PIN_8MA,
  43. PIN_12MA,
  44. PIN_16MA,
  45. PIN_20MA,
  46. };
  47. /*
  48. * Each pin can be programmed for 1.8V or 3.3V
  49. */
  50. enum pin_voltage {
  51. PIN_1_8V = 0,
  52. PIN_3_3V,
  53. };
  54. /*
  55. * Structure to define a group of pins and their parameters
  56. */
  57. struct pin_desc {
  58. unsigned id;
  59. enum pin_fun fun;
  60. enum pin_strength strength;
  61. enum pin_voltage voltage;
  62. unsigned pullup:1;
  63. };
  64. struct pin_group {
  65. struct pin_desc *pins;
  66. int nr_pins;
  67. };
  68. /* Set pin drive strength */
  69. void stmp3xxx_pin_strength(unsigned id, enum pin_strength strength,
  70. const char *label);
  71. /* Set pin voltage */
  72. void stmp3xxx_pin_voltage(unsigned id, enum pin_voltage voltage,
  73. const char *label);
  74. /* Enable pull-up resistor for a pin */
  75. void stmp3xxx_pin_pullup(unsigned id, int enable, const char *label);
  76. /*
  77. * Request a pin ownership, only one module (identified by @label)
  78. * may own a pin.
  79. */
  80. int stmp3xxx_request_pin(unsigned id, enum pin_fun fun, const char *label);
  81. /* Release pin */
  82. void stmp3xxx_release_pin(unsigned id, const char *label);
  83. void stmp3xxx_set_pin_type(unsigned id, enum pin_fun fun);
  84. /*
  85. * Each bank is associated with a number of registers to control
  86. * pin function, drive strength, voltage and pull-up reigster. The
  87. * number of registers of a given type depends on the number of bits
  88. * describin particular pin.
  89. */
  90. #define HW_MUXSEL_NUM 2 /* registers per bank */
  91. #define HW_MUXSEL_PIN_LEN 2 /* bits per pin */
  92. #define HW_MUXSEL_PIN_NUM 16 /* pins per register */
  93. #define HW_MUXSEL_PINFUN_MASK 0x3 /* pin function mask */
  94. #define HW_MUXSEL_PINFUN_NUM 4 /* four options for a pin */
  95. #define HW_DRIVE_NUM 4 /* registers per bank */
  96. #define HW_DRIVE_PIN_LEN 4 /* bits per pin */
  97. #define HW_DRIVE_PIN_NUM 8 /* pins per register */
  98. #define HW_DRIVE_PINDRV_MASK 0x3 /* pin strength mask - 2 bits */
  99. #define HW_DRIVE_PINDRV_NUM 5 /* five possible strength values */
  100. #define HW_DRIVE_PINV_MASK 0x4 /* pin voltage mask - 1 bit */
  101. struct stmp3xxx_pinmux_bank {
  102. struct gpio_chip chip;
  103. /* Pins allocation map */
  104. unsigned long pin_map;
  105. /* Pin owner names */
  106. const char *pin_labels[32];
  107. /* Bank registers */
  108. void __iomem *hw_muxsel[HW_MUXSEL_NUM];
  109. void __iomem *hw_drive[HW_DRIVE_NUM];
  110. void __iomem *hw_pull;
  111. void __iomem *pin2irq,
  112. *irqlevel,
  113. *irqpolarity,
  114. *irqen,
  115. *irqstat;
  116. /* HW MUXSEL register function bit values */
  117. u8 functions[HW_MUXSEL_PINFUN_NUM];
  118. /*
  119. * HW DRIVE register strength bit values:
  120. * 0xff - requested strength is not supported for this bank
  121. */
  122. u8 strengths[HW_DRIVE_PINDRV_NUM];
  123. /* GPIO things */
  124. void __iomem *hw_gpio_in,
  125. *hw_gpio_out,
  126. *hw_gpio_doe;
  127. int irq, virq;
  128. };
  129. int __init stmp3xxx_pinmux_init(int virtual_irq_start);
  130. #endif /* __PINMUX_H */