diff options
Diffstat (limited to 'firmware/target/arm/imx233/pinctrl-imx233.h')
-rw-r--r-- | firmware/target/arm/imx233/pinctrl-imx233.h | 74 |
1 files changed, 45 insertions, 29 deletions
diff --git a/firmware/target/arm/imx233/pinctrl-imx233.h b/firmware/target/arm/imx233/pinctrl-imx233.h index 05c2c15bea..3fcf042071 100644 --- a/firmware/target/arm/imx233/pinctrl-imx233.h +++ b/firmware/target/arm/imx233/pinctrl-imx233.h | |||
@@ -35,23 +35,24 @@ | |||
35 | #define PINCTRL_FUNCTION_ALT2 2 | 35 | #define PINCTRL_FUNCTION_ALT2 2 |
36 | #define PINCTRL_FUNCTION_GPIO 3 | 36 | #define PINCTRL_FUNCTION_GPIO 3 |
37 | 37 | ||
38 | #if IMX233_SUBTARGET >= 3700 | ||
38 | #define PINCTRL_DRIVE_4mA 0 | 39 | #define PINCTRL_DRIVE_4mA 0 |
39 | #define PINCTRL_DRIVE_8mA 1 | 40 | #define PINCTRL_DRIVE_8mA 1 |
40 | #define PINCTRL_DRIVE_12mA 2 | 41 | #define PINCTRL_DRIVE_12mA 2 |
41 | #define PINCTRL_DRIVE_16mA 3 /* not available on all pins */ | 42 | #define PINCTRL_DRIVE_16mA 3 /* not available on all pins */ |
43 | #else | ||
44 | #define PINCTRL_DRIVE_4mA 0 | ||
45 | #define PINCTRL_DRIVE_8mA 1 | ||
46 | #endif | ||
42 | 47 | ||
43 | #ifdef IMX233_PINCTRL_DEBUG | 48 | #ifdef IMX233_PINCTRL_DEBUG |
44 | void imx233_pinctrl_acquire(unsigned bank, unsigned pin, const char *name); | 49 | void imx233_pinctrl_acquire(unsigned bank, unsigned pin, const char *name); |
45 | void imx233_pinctrl_acquire_mask(unsigned bank, uint32_t mask, const char *name); | ||
46 | void imx233_pinctrl_release(unsigned bank, unsigned pin, const char *name); | 50 | void imx233_pinctrl_release(unsigned bank, unsigned pin, const char *name); |
47 | void imx233_pinctrl_release_mask(unsigned bank, uint32_t mask, const char *name); | ||
48 | const char *imx233_pinctrl_blame(unsigned bank, unsigned pin); | 51 | const char *imx233_pinctrl_blame(unsigned bank, unsigned pin); |
49 | #else | 52 | #else |
50 | #define imx233_pinctrl_acquire(...) | 53 | #define imx233_pinctrl_acquire(...) |
51 | #define imx233_pinctrl_acquire_mask(...) | ||
52 | #define imx233_pinctrl_release(...) | 54 | #define imx233_pinctrl_release(...) |
53 | #define imx233_pinctrl_release_mask(...) | 55 | #define imx233_pinctrl_get_pin_use(...) NULL |
54 | #define imx233_pinctrl_blame(...) NULL | ||
55 | #endif | 56 | #endif |
56 | 57 | ||
57 | typedef void (*pin_irq_cb_t)(int bank, int pin, intptr_t user); | 58 | typedef void (*pin_irq_cb_t)(int bank, int pin, intptr_t user); |
@@ -61,11 +62,19 @@ static inline void imx233_pinctrl_init(void) | |||
61 | HW_PINCTRL_CTRL_CLR = BM_OR2(PINCTRL_CTRL, CLKGATE, SFTRST); | 62 | HW_PINCTRL_CTRL_CLR = BM_OR2(PINCTRL_CTRL, CLKGATE, SFTRST); |
62 | } | 63 | } |
63 | 64 | ||
65 | #if IMX233_SUBTARGET >= 3700 | ||
64 | static inline void imx233_pinctrl_set_drive(unsigned bank, unsigned pin, unsigned strength) | 66 | static inline void imx233_pinctrl_set_drive(unsigned bank, unsigned pin, unsigned strength) |
65 | { | 67 | { |
66 | HW_PINCTRL_DRIVEn_CLR(4 * bank + pin / 8) = 3 << (4 * (pin % 8)); | 68 | HW_PINCTRL_DRIVEn_CLR(4 * bank + pin / 8) = 3 << (4 * (pin % 8)); |
67 | HW_PINCTRL_DRIVEn_SET(4 * bank + pin / 8) = strength << (4 * (pin % 8)); | 69 | HW_PINCTRL_DRIVEn_SET(4 * bank + pin / 8) = strength << (4 * (pin % 8)); |
68 | } | 70 | } |
71 | #else | ||
72 | static inline void imx233_pinctrl_set_drive(unsigned bank, unsigned pin, unsigned strength) | ||
73 | { | ||
74 | HW_PINCTRL_DRIVEn_CLR(bank) = 1 << pin; | ||
75 | HW_PINCTRL_DRIVEn_SET(bank) = strength << pin; | ||
76 | } | ||
77 | #endif | ||
69 | 78 | ||
70 | static inline void imx233_pinctrl_enable_gpio(unsigned bank, unsigned pin, bool enable) | 79 | static inline void imx233_pinctrl_enable_gpio(unsigned bank, unsigned pin, bool enable) |
71 | { | 80 | { |
@@ -75,14 +84,6 @@ static inline void imx233_pinctrl_enable_gpio(unsigned bank, unsigned pin, bool | |||
75 | HW_PINCTRL_DOEn_CLR(bank) = 1 << pin; | 84 | HW_PINCTRL_DOEn_CLR(bank) = 1 << pin; |
76 | } | 85 | } |
77 | 86 | ||
78 | static inline void imx233_pinctrl_enable_gpio_mask(unsigned bank, uint32_t pin_mask, bool enable) | ||
79 | { | ||
80 | if(enable) | ||
81 | HW_PINCTRL_DOEn_SET(bank) = pin_mask; | ||
82 | else | ||
83 | HW_PINCTRL_DOEn_CLR(bank) = pin_mask; | ||
84 | } | ||
85 | |||
86 | static inline void imx233_pinctrl_set_gpio(unsigned bank, unsigned pin, bool value) | 87 | static inline void imx233_pinctrl_set_gpio(unsigned bank, unsigned pin, bool value) |
87 | { | 88 | { |
88 | if(value) | 89 | if(value) |
@@ -91,25 +92,32 @@ static inline void imx233_pinctrl_set_gpio(unsigned bank, unsigned pin, bool val | |||
91 | HW_PINCTRL_DOUTn_CLR(bank) = 1 << pin; | 92 | HW_PINCTRL_DOUTn_CLR(bank) = 1 << pin; |
92 | } | 93 | } |
93 | 94 | ||
94 | static inline void imx233_pinctrl_set_gpio_mask(unsigned bank, uint32_t pin_mask, bool value) | 95 | static inline bool imx233_pinctrl_get_gpio(unsigned bank, unsigned pin) |
95 | { | ||
96 | if(value) | ||
97 | HW_PINCTRL_DOUTn_SET(bank) = pin_mask; | ||
98 | else | ||
99 | HW_PINCTRL_DOUTn_CLR(bank) = pin_mask; | ||
100 | } | ||
101 | |||
102 | static inline uint32_t imx233_pinctrl_get_gpio_mask(unsigned bank, uint32_t pin_mask) | ||
103 | { | 96 | { |
104 | return HW_PINCTRL_DINn(bank) & pin_mask; | 97 | return (HW_PINCTRL_DINn(bank) >> pin) & 1; |
105 | } | 98 | } |
106 | 99 | ||
107 | static inline void imx233_pinctrl_set_function(unsigned bank, unsigned pin, unsigned function) | 100 | static inline void imx233_pinctrl_set_function(unsigned bank, unsigned pin, unsigned function) |
108 | { | 101 | { |
102 | #if IMX233_SUBTARGET >= 3700 | ||
109 | HW_PINCTRL_MUXSELn_CLR(2 * bank + pin / 16) = 3 << (2 * (pin % 16)); | 103 | HW_PINCTRL_MUXSELn_CLR(2 * bank + pin / 16) = 3 << (2 * (pin % 16)); |
110 | HW_PINCTRL_MUXSELn_SET(2 * bank + pin / 16) = function << (2 * (pin % 16)); | 104 | HW_PINCTRL_MUXSELn_SET(2 * bank + pin / 16) = function << (2 * (pin % 16)); |
105 | #else | ||
106 | if(pin < 16) | ||
107 | { | ||
108 | HW_PINCTRL_MUXSELLn_CLR(bank) = 3 << (2 * pin); | ||
109 | HW_PINCTRL_MUXSELLn_SET(bank) = function << (2 * pin); | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | pin -= 16; | ||
114 | HW_PINCTRL_MUXSELHn_CLR(bank) = 3 << (2 * pin); | ||
115 | HW_PINCTRL_MUXSELHn_SET(bank) = function << (2 * pin); | ||
116 | } | ||
117 | #endif | ||
111 | } | 118 | } |
112 | 119 | ||
120 | #if IMX233_SUBTARGET >= 3700 | ||
113 | static inline void imx233_pinctrl_enable_pullup(unsigned bank, unsigned pin, bool enable) | 121 | static inline void imx233_pinctrl_enable_pullup(unsigned bank, unsigned pin, bool enable) |
114 | { | 122 | { |
115 | if(enable) | 123 | if(enable) |
@@ -117,14 +125,14 @@ static inline void imx233_pinctrl_enable_pullup(unsigned bank, unsigned pin, boo | |||
117 | else | 125 | else |
118 | HW_PINCTRL_PULLn_CLR(bank) = 1 << pin; | 126 | HW_PINCTRL_PULLn_CLR(bank) = 1 << pin; |
119 | } | 127 | } |
120 | 128 | #else | |
121 | static inline void imx233_pinctrl_enable_pullup_mask(unsigned bank, uint32_t pin_msk, bool enable) | 129 | static inline void imx233_pinctrl_enable_pullup(unsigned bank, unsigned pin, bool enable) |
122 | { | 130 | { |
123 | if(enable) | 131 | (void) bank; |
124 | HW_PINCTRL_PULLn_SET(bank) = pin_msk; | 132 | (void) pin; |
125 | else | 133 | (void) enable; |
126 | HW_PINCTRL_PULLn_CLR(bank) = pin_msk; | ||
127 | } | 134 | } |
135 | #endif | ||
128 | 136 | ||
129 | /** On irq, the pin irq interrupt is disable and then cb is called; | 137 | /** On irq, the pin irq interrupt is disable and then cb is called; |
130 | * the setup_pin_irq function needs to be called again to enable it again */ | 138 | * the setup_pin_irq function needs to be called again to enable it again */ |
@@ -158,6 +166,14 @@ static inline void imx233_pinctrl_setup_vpin(vpin_t vpin, const char *name, | |||
158 | imx233_pinctrl_enable_pullup(bank, pin, pullup); | 166 | imx233_pinctrl_enable_pullup(bank, pin, pullup); |
159 | } | 167 | } |
160 | 168 | ||
169 | #if IMX233_SUBTARGET < 3700 | ||
170 | #include "pins/pins-stmp3600.h" | ||
171 | #elif IMX233_SUBTARGET < 3770 | ||
172 | #include "pins/pins-stmp3700.h" | ||
173 | #elif IMX233_SUBTARGET < 3780 | ||
174 | #error implement this | ||
175 | #else | ||
161 | #include "pins/pins-imx233.h" | 176 | #include "pins/pins-imx233.h" |
177 | #endif | ||
162 | 178 | ||
163 | #endif /* __PINCTRL_IMX233_H__ */ | 179 | #endif /* __PINCTRL_IMX233_H__ */ |