summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/target/arm/imx233/i2c-imx233.c6
-rw-r--r--firmware/target/arm/imx233/pinctrl-imx233.h29
-rw-r--r--firmware/target/arm/imx233/pins/pins-imx233.h83
-rw-r--r--firmware/target/arm/imx233/pwm-imx233.c7
-rw-r--r--firmware/target/arm/imx233/sdmmc-imx233.c2
-rw-r--r--firmware/target/arm/imx233/ssp-imx233.c81
6 files changed, 156 insertions, 52 deletions
diff --git a/firmware/target/arm/imx233/i2c-imx233.c b/firmware/target/arm/imx233/i2c-imx233.c
index d087c94793..5641d6fc62 100644
--- a/firmware/target/arm/imx233/i2c-imx233.c
+++ b/firmware/target/arm/imx233/i2c-imx233.c
@@ -84,10 +84,8 @@ void imx233_i2c_init(void)
84{ 84{
85 BF_SET(I2C_CTRL0, SFTRST); 85 BF_SET(I2C_CTRL0, SFTRST);
86 /* setup pins (must be done when shutdown) */ 86 /* setup pins (must be done when shutdown) */
87 imx233_pinctrl_acquire(0, 30, "i2c"); 87 imx233_pinctrl_setup_vpin(VPIN_I2C_SCL, "i2c scl", PINCTRL_DRIVE_4mA, true);
88 imx233_pinctrl_acquire(0, 31, "i2c"); 88 imx233_pinctrl_setup_vpin(VPIN_I2C_SDA, "i2c sda", PINCTRL_DRIVE_4mA, true);
89 imx233_pinctrl_set_function(0, 30, PINCTRL_FUNCTION_MAIN);
90 imx233_pinctrl_set_function(0, 31, PINCTRL_FUNCTION_MAIN);
91 /* clear softreset */ 89 /* clear softreset */
92 imx233_reset_block(&HW_I2C_CTRL0); 90 imx233_reset_block(&HW_I2C_CTRL0);
93 /* Errata: 91 /* Errata:
diff --git a/firmware/target/arm/imx233/pinctrl-imx233.h b/firmware/target/arm/imx233/pinctrl-imx233.h
index 88d08430ad..05c2c15bea 100644
--- a/firmware/target/arm/imx233/pinctrl-imx233.h
+++ b/firmware/target/arm/imx233/pinctrl-imx233.h
@@ -131,4 +131,33 @@ static inline void imx233_pinctrl_enable_pullup_mask(unsigned bank, uint32_t pin
131void imx233_pinctrl_setup_irq(unsigned bank, unsigned pin, bool enable_int, 131void imx233_pinctrl_setup_irq(unsigned bank, unsigned pin, bool enable_int,
132 bool level, bool polarity, pin_irq_cb_t cb, intptr_t user); 132 bool level, bool polarity, pin_irq_cb_t cb, intptr_t user);
133 133
134/**
135 * Virtual pin interface
136 *
137 * This interface provides an easy way to configure standard pins for
138 * devices like SSP, LCD, etc
139 * The point here is that these pins can or cannot exist depending on the
140 * chip and the package and the drivers don't want to mess with that.
141 *
142 * A virtual pin is described by a bank, a pin and the function.
143 */
144typedef unsigned vpin_t;
145#define VPIN_PACK(bank, pin, mux) \
146 ((vpin_t)((bank) << 5 | (pin) | PINCTRL_FUNCTION_##mux << 7))
147#define VPIN_UNPACK_BANK(vpin) (((vpin) >> 5) & 3)
148#define VPIN_UNPACK_PIN(vpin) (((vpin) >> 0) & 0x1f)
149#define VPIN_UNPACK_MUX(vpin) (((vpin) >> 7) & 3)
150
151static inline void imx233_pinctrl_setup_vpin(vpin_t vpin, const char *name,
152 unsigned drive, bool pullup)
153{
154 unsigned bank = VPIN_UNPACK_BANK(vpin), pin = VPIN_UNPACK_PIN(vpin);
155 imx233_pinctrl_acquire(bank, pin, name);
156 imx233_pinctrl_set_function(bank, pin, VPIN_UNPACK_MUX(vpin));
157 imx233_pinctrl_set_drive(bank, pin, drive);
158 imx233_pinctrl_enable_pullup(bank, pin, pullup);
159}
160
161#include "pins/pins-imx233.h"
162
134#endif /* __PINCTRL_IMX233_H__ */ 163#endif /* __PINCTRL_IMX233_H__ */
diff --git a/firmware/target/arm/imx233/pins/pins-imx233.h b/firmware/target/arm/imx233/pins/pins-imx233.h
new file mode 100644
index 0000000000..12231a60d8
--- /dev/null
+++ b/firmware/target/arm/imx233/pins/pins-imx233.h
@@ -0,0 +1,83 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright © 2013 by Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef __PINS_IMX233__
22#define __PINS_IMX233__
23
24#define VPIN_PWM(channel) VPIN_PACK(1, 26 + (channel), MAIN)
25
26#define VPIN_I2C_SCL VPIN_PACK(0, 30, MAIN)
27#define VPIN_I2C_SDA VPIN_PACK(0, 31, MAIN)
28
29#define VPIN_SSP1_DET VPIN_PACK(2, 1, MAIN)
30#define VPIN_SSP1_CMD VPIN_PACK(2, 0, MAIN)
31#define VPIN_SSP1_SCK VPIN_PACK(2, 6, MAIN)
32#define VPIN_SSP1_D0 VPIN_PACK(2, 2, MAIN)
33#define VPIN_SSP1_D1 VPIN_PACK(2, 3, MAIN)
34#define VPIN_SSP1_D2 VPIN_PACK(2, 4, MAIN)
35#define VPIN_SSP1_D3 VPIN_PACK(2, 5, MAIN)
36#define VPIN_SSP1_D4 VPIN_PACK(0, 8, ALT2)
37#define VPIN_SSP1_D5 VPIN_PACK(0, 9, ALT2)
38#define VPIN_SSP1_D6 VPIN_PACK(0, 10, ALT2)
39#define VPIN_SSP1_D7 VPIN_PACK(0, 11, ALT2)
40#define VPIN_SSP1_D4_ALT VPIN_PACK(0, 26, ALT2)
41#define VPIN_SSP1_D5_ALT VPIN_PACK(0, 27, ALT2)
42#define VPIN_SSP1_D6_ALT VPIN_PACK(0, 28, ALT2)
43#define VPIN_SSP1_D7_ALT VPIN_PACK(0, 29, ALT2)
44
45#define VPIN_SSP2_DET VPIN_PACK(0, 19, ALT2)
46#define VPIN_SSP2_CMD VPIN_PACK(0, 20, ALT2)
47#define VPIN_SSP2_SCK VPIN_PACK(0, 24, ALT2)
48#define VPIN_SSP2_D0 VPIN_PACK(0, 0, ALT2)
49#define VPIN_SSP2_D1 VPIN_PACK(0, 1, ALT2)
50#define VPIN_SSP2_D2 VPIN_PACK(0, 2, ALT2)
51#define VPIN_SSP2_D3 VPIN_PACK(0, 3, ALT2)
52#define VPIN_SSP2_D4 VPIN_PACK(0, 4, ALT2)
53#define VPIN_SSP2_D5 VPIN_PACK(0, 5, ALT2)
54#define VPIN_SSP2_D6 VPIN_PACK(0, 6, ALT2)
55#define VPIN_SSP2_D7 VPIN_PACK(0, 7, ALT2)
56
57#define VPIN_UARTDBG_TX VPIN_PACK(1, 27, ALT2)
58#define VPIN_UARTDBG_RX VPIN_PACK(1, 26, ALT2)
59
60#define VPIN_LCD_D0 VPIN_PACK(1, 0, MAIN)
61#define VPIN_LCD_D1 VPIN_PACK(1, 1, MAIN)
62#define VPIN_LCD_D2 VPIN_PACK(1, 2, MAIN)
63#define VPIN_LCD_D3 VPIN_PACK(1, 3, MAIN)
64#define VPIN_LCD_D4 VPIN_PACK(1, 4, MAIN)
65#define VPIN_LCD_D5 VPIN_PACK(1, 5, MAIN)
66#define VPIN_LCD_D6 VPIN_PACK(1, 6, MAIN)
67#define VPIN_LCD_D7 VPIN_PACK(1, 7, MAIN)
68#define VPIN_LCD_D8 VPIN_PACK(1, 8, MAIN)
69#define VPIN_LCD_D9 VPIN_PACK(1, 9, MAIN)
70#define VPIN_LCD_D10 VPIN_PACK(1, 10, MAIN)
71#define VPIN_LCD_D11 VPIN_PACK(1, 11, MAIN)
72#define VPIN_LCD_D12 VPIN_PACK(1, 12, MAIN)
73#define VPIN_LCD_D13 VPIN_PACK(1, 13, MAIN)
74#define VPIN_LCD_D14 VPIN_PACK(1, 14, MAIN)
75#define VPIN_LCD_D15 VPIN_PACK(1, 15, MAIN)
76#define VPIN_LCD_D16 VPIN_PACK(1, 16, MAIN)
77#define VPIN_LCD_D17 VPIN_PACK(1, 17, MAIN)
78#define VPIN_LCD_RESET VPIN_PACK(1, 18, MAIN)
79#define VPIN_LCD_RS VPIN_PACK(1, 19, MAIN)
80#define VPIN_LCD_WR VPIN_PACK(1, 20, MAIN)
81#define VPIN_LCD_CS VPIN_PACK(1, 21, MAIN)
82
83#endif /* __PINS_IMX233__ */
diff --git a/firmware/target/arm/imx233/pwm-imx233.c b/firmware/target/arm/imx233/pwm-imx233.c
index 86460e0140..00aba9320e 100644
--- a/firmware/target/arm/imx233/pwm-imx233.c
+++ b/firmware/target/arm/imx233/pwm-imx233.c
@@ -49,12 +49,7 @@ void imx233_pwm_setup_channel(int channel, int period, int cdiv, int active,
49 if(enable) 49 if(enable)
50 imx233_pwm_enable_channel(channel, false); 50 imx233_pwm_enable_channel(channel, false);
51 /* setup pin */ 51 /* setup pin */
52 imx233_pinctrl_acquire(IMX233_PWM_PIN_BANK(channel), 52 imx233_pinctrl_setup_vpin(VPIN_PWM(channel), "pwm", PINCTRL_DRIVE_4mA, false);
53 IMX233_PWM_PIN(channel), "pwm");
54 imx233_pinctrl_set_function(IMX233_PWM_PIN_BANK(channel), IMX233_PWM_PIN(channel),
55 PINCTRL_FUNCTION_MAIN);
56 imx233_pinctrl_set_drive(IMX233_PWM_PIN_BANK(channel), IMX233_PWM_PIN(channel),
57 PINCTRL_DRIVE_4mA);
58 /* watch the order ! active THEN period */ 53 /* watch the order ! active THEN period */
59 HW_PWM_ACTIVEn(channel) = BF_OR2(PWM_ACTIVEn, ACTIVE(active), INACTIVE(inactive)); 54 HW_PWM_ACTIVEn(channel) = BF_OR2(PWM_ACTIVEn, ACTIVE(active), INACTIVE(inactive));
60 HW_PWM_PERIODn(channel) = BF_OR4(PWM_PERIODn, PERIOD(period - 1), 55 HW_PWM_PERIODn(channel) = BF_OR4(PWM_PERIODn, PERIOD(period - 1),
diff --git a/firmware/target/arm/imx233/sdmmc-imx233.c b/firmware/target/arm/imx233/sdmmc-imx233.c
index ed362a7bc0..8c18b284fd 100644
--- a/firmware/target/arm/imx233/sdmmc-imx233.c
+++ b/firmware/target/arm/imx233/sdmmc-imx233.c
@@ -200,7 +200,7 @@ static void sdmmc_power(int drive, bool on)
200 { 200 {
201 int bank = PIN2BANK(SDMMC_CONF(drive).power_pin); 201 int bank = PIN2BANK(SDMMC_CONF(drive).power_pin);
202 int pin = PIN2PIN(SDMMC_CONF(drive).power_pin); 202 int pin = PIN2PIN(SDMMC_CONF(drive).power_pin);
203 imx233_pinctrl_acquire(bank, pin, "sd/mmc power"); 203 imx233_pinctrl_acquire(bank, pin, "sdmmc_power");
204 imx233_pinctrl_set_function(bank, pin, PINCTRL_FUNCTION_GPIO); 204 imx233_pinctrl_set_function(bank, pin, PINCTRL_FUNCTION_GPIO);
205 imx233_pinctrl_enable_gpio(bank, pin, true); 205 imx233_pinctrl_enable_gpio(bank, pin, true);
206 if(SDMMC_FLAGS(drive) & POWER_INVERTED) 206 if(SDMMC_FLAGS(drive) & POWER_INVERTED)
diff --git a/firmware/target/arm/imx233/ssp-imx233.c b/firmware/target/arm/imx233/ssp-imx233.c
index d83cea7bc0..5f0880c2e9 100644
--- a/firmware/target/arm/imx233/ssp-imx233.c
+++ b/firmware/target/arm/imx233/ssp-imx233.c
@@ -167,39 +167,33 @@ void imx233_ssp_set_timings(int ssp, int divide, int rate, int timeout)
167void imx233_ssp_setup_ssp1_sd_mmc_pins(bool enable_pullups, unsigned bus_width, 167void imx233_ssp_setup_ssp1_sd_mmc_pins(bool enable_pullups, unsigned bus_width,
168 unsigned drive_strength, bool use_alt) 168 unsigned drive_strength, bool use_alt)
169{ 169{
170 (void) use_alt;
170 /* SSP_{CMD,SCK} */ 171 /* SSP_{CMD,SCK} */
171 imx233_pinctrl_set_drive(2, 0, drive_strength); 172 imx233_pinctrl_setup_vpin(VPIN_SSP1_CMD, "ssp1_cmd", drive_strength, enable_pullups);
172 imx233_pinctrl_set_drive(2, 6, drive_strength); 173 imx233_pinctrl_setup_vpin(VPIN_SSP1_SCK, "ssp1_sck", drive_strength, false);
173 imx233_pinctrl_acquire(2, 0, "ssp1 cmd");
174 imx233_pinctrl_acquire(2, 6, "ssp1 sck");
175 imx233_pinctrl_set_function(2, 0, PINCTRL_FUNCTION_MAIN);
176 imx233_pinctrl_set_function(2, 6, PINCTRL_FUNCTION_MAIN);
177 imx233_pinctrl_enable_pullup(2, 0, enable_pullups);
178 /* SSP_DATA{0-3} */ 174 /* SSP_DATA{0-3} */
179 for(unsigned i = 0; i < MIN(bus_width, 4); i++) 175 imx233_pinctrl_setup_vpin(VPIN_SSP1_D0, "ssp1_d0", drive_strength, enable_pullups);
176 if(bus_width >= 4)
180 { 177 {
181 imx233_pinctrl_acquire(2, 2 + i, "ssp1 data"); 178 imx233_pinctrl_setup_vpin(VPIN_SSP1_D1, "ssp1_d1", drive_strength, enable_pullups);
182 imx233_pinctrl_set_drive(2, 2 + i, drive_strength); 179 imx233_pinctrl_setup_vpin(VPIN_SSP1_D2, "ssp1_d2", drive_strength, enable_pullups);
183 imx233_pinctrl_set_function(2, 2 + i, PINCTRL_FUNCTION_MAIN); 180 imx233_pinctrl_setup_vpin(VPIN_SSP1_D3, "ssp1_d3", drive_strength, enable_pullups);
184 imx233_pinctrl_enable_pullup(2, 2 + i, enable_pullups);
185 } 181 }
186 182 if(bus_width >= 8)
187 /* SSP_DATA{4-7} */
188 for(unsigned i = 4; i < bus_width; i++)
189 { 183 {
190 if(use_alt) 184 if(use_alt)
191 { 185 {
192 imx233_pinctrl_acquire(0, 22 + i, "ssp1 data"); 186 imx233_pinctrl_setup_vpin(VPIN_SSP1_D4_ALT, "ssp1_d4", drive_strength, enable_pullups);
193 imx233_pinctrl_set_drive(0, 22 + i, drive_strength); 187 imx233_pinctrl_setup_vpin(VPIN_SSP1_D5_ALT, "ssp1_d5", drive_strength, enable_pullups);
194 imx233_pinctrl_set_function(0, 22 + i, PINCTRL_FUNCTION_ALT2); 188 imx233_pinctrl_setup_vpin(VPIN_SSP1_D6_ALT, "ssp1_d6", drive_strength, enable_pullups);
195 imx233_pinctrl_enable_pullup(0, 22 + i, enable_pullups); 189 imx233_pinctrl_setup_vpin(VPIN_SSP1_D7_ALT, "ssp1_d7", drive_strength, enable_pullups);
196 } 190 }
197 else 191 else
198 { 192 {
199 imx233_pinctrl_acquire(0, 4 + i, "ssp1 data"); 193 imx233_pinctrl_setup_vpin(VPIN_SSP1_D4, "ssp1_d4", drive_strength, enable_pullups);
200 imx233_pinctrl_set_drive(0, 4 + i, drive_strength); 194 imx233_pinctrl_setup_vpin(VPIN_SSP1_D5, "ssp1_d5", drive_strength, enable_pullups);
201 imx233_pinctrl_set_function(0, 4 + i, PINCTRL_FUNCTION_ALT2); 195 imx233_pinctrl_setup_vpin(VPIN_SSP1_D6, "ssp1_d6", drive_strength, enable_pullups);
202 imx233_pinctrl_enable_pullup(0, 4 + i, enable_pullups); 196 imx233_pinctrl_setup_vpin(VPIN_SSP1_D7, "ssp1_d7", drive_strength, enable_pullups);
203 } 197 }
204 } 198 }
205} 199}
@@ -207,23 +201,26 @@ void imx233_ssp_setup_ssp1_sd_mmc_pins(bool enable_pullups, unsigned bus_width,
207void imx233_ssp_setup_ssp2_sd_mmc_pins(bool enable_pullups, unsigned bus_width, 201void imx233_ssp_setup_ssp2_sd_mmc_pins(bool enable_pullups, unsigned bus_width,
208 unsigned drive_strength) 202 unsigned drive_strength)
209{ 203{
204 (void) enable_pullups;
205 (void) bus_width;
206 (void) drive_strength;
210 /* SSP_{CMD,SCK} */ 207 /* SSP_{CMD,SCK} */
211 imx233_pinctrl_acquire(0, 20, "ssp2 cmd"); 208 imx233_pinctrl_setup_vpin(VPIN_SSP2_CMD, "ssp2_cmd", drive_strength, enable_pullups);
212 imx233_pinctrl_acquire(0, 24, "ssp2 sck"); 209 imx233_pinctrl_setup_vpin(VPIN_SSP2_SCK, "ssp2_sck", drive_strength, false);
213 imx233_pinctrl_set_drive(0, 20, drive_strength); 210 /* SSP_DATA{0-3} */
214 imx233_pinctrl_set_drive(0, 24, drive_strength); 211 imx233_pinctrl_setup_vpin(VPIN_SSP2_D0, "ssp2_d0", drive_strength, enable_pullups);
215 imx233_pinctrl_set_function(0, 20, PINCTRL_FUNCTION_ALT2); 212 if(bus_width >= 4)
216 imx233_pinctrl_set_function(0, 24, PINCTRL_FUNCTION_ALT2); 213 {
217 imx233_pinctrl_enable_pullup(0, 20, enable_pullups); 214 imx233_pinctrl_setup_vpin(VPIN_SSP2_D1, "ssp2_d1", drive_strength, enable_pullups);
218 /* SSP_DATA{0-7}*/ 215 imx233_pinctrl_setup_vpin(VPIN_SSP2_D2, "ssp2_d2", drive_strength, enable_pullups);
219 for(unsigned i = 0; i < bus_width; i++) 216 imx233_pinctrl_setup_vpin(VPIN_SSP2_D3, "ssp2_d3", drive_strength, enable_pullups);
217 }
218 if(bus_width >= 8)
220 { 219 {
221 imx233_pinctrl_acquire(0, i, "ssp2 data"); 220 imx233_pinctrl_setup_vpin(VPIN_SSP2_D4, "ssp2_d4", drive_strength, enable_pullups);
222 imx233_pinctrl_set_drive(0, i, drive_strength); 221 imx233_pinctrl_setup_vpin(VPIN_SSP2_D5, "ssp2_d5", drive_strength, enable_pullups);
223 imx233_pinctrl_set_function(0, i, PINCTRL_FUNCTION_ALT2); 222 imx233_pinctrl_setup_vpin(VPIN_SSP2_D6, "ssp2_d6", drive_strength, enable_pullups);
224 imx233_pinctrl_enable_pullup(0, i, enable_pullups); 223 imx233_pinctrl_setup_vpin(VPIN_SSP2_D7, "ssp2_d7", drive_strength, enable_pullups);
225 imx233_pinctrl_enable_gpio(0, i, false);
226 imx233_pinctrl_set_gpio(0, i, false);
227 } 224 }
228} 225}
229 226
@@ -358,13 +355,15 @@ void imx233_ssp_sdmmc_setup_detect(int ssp, bool enable, ssp_detect_cb_t fn,
358 bool first_time, bool invert) 355 bool first_time, bool invert)
359{ 356{
360 ASSERT_SSP(ssp) 357 ASSERT_SSP(ssp)
361 int bank = ssp == 1 ? 2 : 0; 358 vpin_t vpin = VPIN_SSP1_DET;
362 int pin = ssp == 1 ? 1 : 19; 359 if(ssp == 2)
360 vpin = VPIN_SSP2_DET;
361 unsigned bank = VPIN_UNPACK_BANK(vpin), pin = VPIN_UNPACK_PIN(vpin);
363 ssp_detect_cb[ssp - 1] = fn; 362 ssp_detect_cb[ssp - 1] = fn;
364 ssp_detect_invert[ssp - 1] = invert; 363 ssp_detect_invert[ssp - 1] = invert;
365 if(enable) 364 if(enable)
366 { 365 {
367 imx233_pinctrl_acquire(bank, pin, ssp == 1 ? "ssp1 detect" : "ssp2 detect"); 366 imx233_pinctrl_acquire(bank, pin, ssp == 1 ? "ssp1_det" : "ssp2_det");
368 imx233_pinctrl_set_function(bank, pin, PINCTRL_FUNCTION_GPIO); 367 imx233_pinctrl_set_function(bank, pin, PINCTRL_FUNCTION_GPIO);
369 imx233_pinctrl_enable_gpio(bank, pin, false); 368 imx233_pinctrl_enable_gpio(bank, pin, false);
370 } 369 }