1.1 --- a/include/jz4730.h Tue Jul 11 18:45:08 2017 +0200
1.2 +++ b/include/jz4730.h Wed Jul 12 15:46:53 2017 +0200
1.3 @@ -1343,83 +1343,11 @@
1.4 /*************************************************************************
1.5 * GPIO
1.6 *************************************************************************/
1.7 -#define GPIO_GPDR(n) (GPIO_BASE + (0x00 + (n)*0x30))
1.8 -#define GPIO_GPDIR(n) (GPIO_BASE + (0x04 + (n)*0x30))
1.9 -#define GPIO_GPODR(n) (GPIO_BASE + (0x08 + (n)*0x30))
1.10 -#define GPIO_GPPUR(n) (GPIO_BASE + (0x0c + (n)*0x30))
1.11 -#define GPIO_GPALR(n) (GPIO_BASE + (0x10 + (n)*0x30))
1.12 -#define GPIO_GPAUR(n) (GPIO_BASE + (0x14 + (n)*0x30))
1.13 -#define GPIO_GPIDLR(n) (GPIO_BASE + (0x18 + (n)*0x30))
1.14 -#define GPIO_GPIDUR(n) (GPIO_BASE + (0x1c + (n)*0x30))
1.15 -#define GPIO_GPIER(n) (GPIO_BASE + (0x20 + (n)*0x30))
1.16 -#define GPIO_GPIMR(n) (GPIO_BASE + (0x24 + (n)*0x30))
1.17 -#define GPIO_GPFR(n) (GPIO_BASE + (0x28 + (n)*0x30))
1.18 -
1.19 -#define REG_GPIO_GPDR(n) REG32(GPIO_GPDR((n)))
1.20 -#define REG_GPIO_GPDIR(n) REG32(GPIO_GPDIR((n)))
1.21 -#define REG_GPIO_GPODR(n) REG32(GPIO_GPODR((n)))
1.22 -#define REG_GPIO_GPPUR(n) REG32(GPIO_GPPUR((n)))
1.23 -#define REG_GPIO_GPALR(n) REG32(GPIO_GPALR((n)))
1.24 -#define REG_GPIO_GPAUR(n) REG32(GPIO_GPAUR((n)))
1.25 -#define REG_GPIO_GPIDLR(n) REG32(GPIO_GPIDLR((n)))
1.26 -#define REG_GPIO_GPIDUR(n) REG32(GPIO_GPIDUR((n)))
1.27 -#define REG_GPIO_GPIER(n) REG32(GPIO_GPIER((n)))
1.28 -#define REG_GPIO_GPIMR(n) REG32(GPIO_GPIMR((n)))
1.29 -#define REG_GPIO_GPFR(n) REG32(GPIO_GPFR((n)))
1.30 -
1.31 -#define GPIO_IRQ_LOLEVEL 0
1.32 -#define GPIO_IRQ_HILEVEL 1
1.33 -#define GPIO_IRQ_FALLEDG 2
1.34 -#define GPIO_IRQ_RAISEDG 3
1.35
1.36 #define IRQ_GPIO_0 48
1.37 #define NUM_GPIO 100
1.38
1.39 -#define GPIO_GPDR0 GPIO_GPDR(0)
1.40 -#define GPIO_GPDR1 GPIO_GPDR(1)
1.41 -#define GPIO_GPDR2 GPIO_GPDR(2)
1.42 -#define GPIO_GPDR3 GPIO_GPDR(3)
1.43 -#define GPIO_GPDIR0 GPIO_GPDIR(0)
1.44 -#define GPIO_GPDIR1 GPIO_GPDIR(1)
1.45 -#define GPIO_GPDIR2 GPIO_GPDIR(2)
1.46 -#define GPIO_GPDIR3 GPIO_GPDIR(3)
1.47 -#define GPIO_GPODR0 GPIO_GPODR(0)
1.48 -#define GPIO_GPODR1 GPIO_GPODR(1)
1.49 -#define GPIO_GPODR2 GPIO_GPODR(2)
1.50 -#define GPIO_GPODR3 GPIO_GPODR(3)
1.51 -#define GPIO_GPPUR0 GPIO_GPPUR(0)
1.52 -#define GPIO_GPPUR1 GPIO_GPPUR(1)
1.53 -#define GPIO_GPPUR2 GPIO_GPPUR(2)
1.54 -#define GPIO_GPPUR3 GPIO_GPPUR(3)
1.55 -#define GPIO_GPALR0 GPIO_GPALR(0)
1.56 -#define GPIO_GPALR1 GPIO_GPALR(1)
1.57 -#define GPIO_GPALR2 GPIO_GPALR(2)
1.58 -#define GPIO_GPALR3 GPIO_GPALR(3)
1.59 -#define GPIO_GPAUR0 GPIO_GPAUR(0)
1.60 -#define GPIO_GPAUR1 GPIO_GPAUR(1)
1.61 -#define GPIO_GPAUR2 GPIO_GPAUR(2)
1.62 -#define GPIO_GPAUR3 GPIO_GPAUR(3)
1.63 -#define GPIO_GPIDLR0 GPIO_GPIDLR(0)
1.64 -#define GPIO_GPIDLR1 GPIO_GPIDLR(1)
1.65 -#define GPIO_GPIDLR2 GPIO_GPIDLR(2)
1.66 -#define GPIO_GPIDLR3 GPIO_GPIDLR(3)
1.67 -#define GPIO_GPIDUR0 GPIO_GPIDUR(0)
1.68 -#define GPIO_GPIDUR1 GPIO_GPIDUR(1)
1.69 -#define GPIO_GPIDUR2 GPIO_GPIDUR(2)
1.70 -#define GPIO_GPIDUR3 GPIO_GPIDUR(3)
1.71 -#define GPIO_GPIER0 GPIO_GPIER(0)
1.72 -#define GPIO_GPIER1 GPIO_GPIER(1)
1.73 -#define GPIO_GPIER2 GPIO_GPIER(2)
1.74 -#define GPIO_GPIER3 GPIO_GPIER(3)
1.75 -#define GPIO_GPIMR0 GPIO_GPIMR(0)
1.76 -#define GPIO_GPIMR1 GPIO_GPIMR(1)
1.77 -#define GPIO_GPIMR2 GPIO_GPIMR(2)
1.78 -#define GPIO_GPIMR3 GPIO_GPIMR(3)
1.79 -#define GPIO_GPFR0 GPIO_GPFR(0)
1.80 -#define GPIO_GPFR1 GPIO_GPFR(1)
1.81 -#define GPIO_GPFR2 GPIO_GPFR(2)
1.82 -#define GPIO_GPFR3 GPIO_GPFR(3)
1.83 -
1.84 +/* Register definitions with absolute positioning have been removed. */
1.85
1.86 /*************************************************************************
1.87 * HARB
1.88 @@ -3160,356 +3088,7 @@
1.89 * GPIO
1.90 ***************************************************************************/
1.91
1.92 -/* p is the port number (0,1,2,3)
1.93 - * o is the pin offset (0-31) inside the port
1.94 - * n is the absolute number of a pin (0-124), regardless of the port
1.95 - * m is the interrupt manner (low/high/falling/rising)
1.96 - */
1.97 -
1.98 -#define __gpio_port_data(p) ( REG_GPIO_GPDR(p) )
1.99 -
1.100 -#define __gpio_port_as_output(p, o) \
1.101 -do { \
1.102 - unsigned int tmp; \
1.103 - REG_GPIO_GPIER(p) &= ~(1 << (o)); \
1.104 - REG_GPIO_GPDIR(p) |= (1 << (o)); \
1.105 - if (o < 16) { \
1.106 - tmp = REG_GPIO_GPALR(p); \
1.107 - tmp &= ~(3 << ((o) << 1)); \
1.108 - REG_GPIO_GPALR(p) = tmp; \
1.109 - } else { \
1.110 - tmp = REG_GPIO_GPAUR(p); \
1.111 - tmp &= ~(3 << (((o) - 16)<< 1)); \
1.112 - REG_GPIO_GPAUR(p) = tmp; \
1.113 - } \
1.114 -} while (0)
1.115 -
1.116 -#define __gpio_port_as_input(p, o) \
1.117 -do { \
1.118 - unsigned int tmp; \
1.119 - REG_GPIO_GPIER(p) &= ~(1 << (o)); \
1.120 - REG_GPIO_GPDIR(p) &= ~(1 << (o)); \
1.121 - if (o < 16) { \
1.122 - tmp = REG_GPIO_GPALR(p); \
1.123 - tmp &= ~(3 << ((o) << 1)); \
1.124 - REG_GPIO_GPALR(p) = tmp; \
1.125 - } else { \
1.126 - tmp = REG_GPIO_GPAUR(p); \
1.127 - tmp &= ~(3 << (((o) - 16)<< 1)); \
1.128 - REG_GPIO_GPAUR(p) = tmp; \
1.129 - } \
1.130 -} while (0)
1.131 -
1.132 -#define __gpio_as_output(n) \
1.133 -do { \
1.134 - unsigned int p, o; \
1.135 - p = (n) / 32; \
1.136 - o = (n) % 32; \
1.137 - __gpio_port_as_output(p, o); \
1.138 -} while (0)
1.139 -
1.140 -#define __gpio_as_input(n) \
1.141 -do { \
1.142 - unsigned int p, o; \
1.143 - p = (n) / 32; \
1.144 - o = (n) % 32; \
1.145 - __gpio_port_as_input(p, o); \
1.146 -} while (0)
1.147 -
1.148 -#define __gpio_set_pin(n) \
1.149 -do { \
1.150 - unsigned int p, o; \
1.151 - p = (n) / 32; \
1.152 - o = (n) % 32; \
1.153 - __gpio_port_data(p) |= (1 << o); \
1.154 -} while (0)
1.155 -
1.156 -#define __gpio_clear_pin(n) \
1.157 -do { \
1.158 - unsigned int p, o; \
1.159 - p = (n) / 32; \
1.160 - o = (n) % 32; \
1.161 - __gpio_port_data(p) &= ~(1 << o); \
1.162 -} while (0)
1.163 -
1.164 -static __inline__ unsigned int __gpio_get_pin(unsigned int n)
1.165 -{
1.166 - unsigned int p, o;
1.167 - p = (n) / 32;
1.168 - o = (n) % 32;
1.169 - if (__gpio_port_data(p) & (1 << o))
1.170 - return 1;
1.171 - else
1.172 - return 0;
1.173 -}
1.174 -
1.175 -
1.176 -#define __gpio_set_irq_detect_manner(p, o, m) \
1.177 -do { \
1.178 - unsigned int tmp; \
1.179 - if (o < 16) { \
1.180 - tmp = REG_GPIO_GPIDLR(p); \
1.181 - tmp &= ~(3 << ((o) << 1)); \
1.182 - tmp |= ((m) << ((o) << 1)); \
1.183 - REG_GPIO_GPIDLR(p) = tmp; \
1.184 - } else { \
1.185 - o -= 16; \
1.186 - tmp = REG_GPIO_GPIDUR(p); \
1.187 - tmp &= ~(3 << ((o) << 1)); \
1.188 - tmp |= ((m) << ((o) << 1)); \
1.189 - REG_GPIO_GPIDUR(p) = tmp; \
1.190 - } \
1.191 -} while (0)
1.192 -
1.193 -#define __gpio_port_as_irq(p, o, m) \
1.194 -do { \
1.195 - __gpio_set_irq_detect_manner(p, o, m); \
1.196 - __gpio_port_as_input(p, o); \
1.197 - REG_GPIO_GPIER(p) |= (1 << o); \
1.198 -} while (0)
1.199 -
1.200 -#define __gpio_as_irq(n, m) \
1.201 -do { \
1.202 - unsigned int p, o; \
1.203 - p = (n) / 32; \
1.204 - o = (n) % 32; \
1.205 - __gpio_port_as_irq(p, o, m); \
1.206 -} while (0)
1.207 -
1.208 -
1.209 -#define __gpio_as_irq_high_level(n) __gpio_as_irq(n, GPIO_IRQ_HILEVEL)
1.210 -#define __gpio_as_irq_low_level(n) __gpio_as_irq(n, GPIO_IRQ_LOLEVEL)
1.211 -#define __gpio_as_irq_fall_edge(n) __gpio_as_irq(n, GPIO_IRQ_FALLEDG)
1.212 -#define __gpio_as_irq_rise_edge(n) __gpio_as_irq(n, GPIO_IRQ_RAISEDG)
1.213 -
1.214 -
1.215 -#define __gpio_mask_irq(n) \
1.216 -do { \
1.217 - unsigned int p, o; \
1.218 - p = (n) / 32; \
1.219 - o = (n) % 32; \
1.220 - REG_GPIO_GPIER(p) &= ~(1 << o); \
1.221 -} while (0)
1.222 -
1.223 -#define __gpio_unmask_irq(n) \
1.224 -do { \
1.225 - unsigned int p, o; \
1.226 - p = (n) / 32; \
1.227 - o = (n) % 32; \
1.228 - REG_GPIO_GPIER(n) |= (1 << o); \
1.229 -} while (0)
1.230 -
1.231 -#define __gpio_ack_irq(n) \
1.232 -do { \
1.233 - unsigned int p, o; \
1.234 - p = (n) / 32; \
1.235 - o = (n) % 32; \
1.236 - REG_GPIO_GPFR(p) |= (1 << o); \
1.237 -} while (0)
1.238 -
1.239 -
1.240 -static __inline__ unsigned int __gpio_get_irq(void)
1.241 -{
1.242 - unsigned int tmp, i;
1.243 -
1.244 - tmp = REG_GPIO_GPFR(3);
1.245 - for (i=0; i<32; i++)
1.246 - if (tmp & (1 << i))
1.247 - return 0x60 + i;
1.248 - tmp = REG_GPIO_GPFR(2);
1.249 - for (i=0; i<32; i++)
1.250 - if (tmp & (1 << i))
1.251 - return 0x40 + i;
1.252 - tmp = REG_GPIO_GPFR(1);
1.253 - for (i=0; i<32; i++)
1.254 - if (tmp & (1 << i))
1.255 - return 0x20 + i;
1.256 - tmp = REG_GPIO_GPFR(0);
1.257 - for (i=0; i<32; i++)
1.258 - if (tmp & (1 << i))
1.259 - return i;
1.260 - return 0;
1.261 -}
1.262 -
1.263 -#define __gpio_group_irq(n) \
1.264 -({ \
1.265 - register int tmp, i; \
1.266 - tmp = REG_GPIO_GPFR((n)); \
1.267 - for (i=31;i>=0;i--) \
1.268 - if (tmp & (1 << i)) \
1.269 - break; \
1.270 - i; \
1.271 -})
1.272 -
1.273 -#define __gpio_enable_pull(n) \
1.274 -do { \
1.275 - unsigned int p, o; \
1.276 - p = (n) / 32; \
1.277 - o = (n) % 32; \
1.278 - REG_GPIO_GPPUR(p) |= (1 << o); \
1.279 -} while (0)
1.280 -
1.281 -#define __gpio_disable_pull(n) \
1.282 -do { \
1.283 - unsigned int p, o; \
1.284 - p = (n) / 32; \
1.285 - o = (n) % 32; \
1.286 - REG_GPIO_GPPUR(p) &= ~(1 << o); \
1.287 -} while (0)
1.288 -
1.289 -/* Init the alternate function pins */
1.290 -
1.291 -
1.292 -#define __gpio_as_ssi() \
1.293 -do { \
1.294 - REG_GPIO_GPALR(2) &= 0xFC00FFFF; \
1.295 - REG_GPIO_GPALR(2) |= 0x01550000; \
1.296 -} while (0)
1.297 -
1.298 -#define __gpio_as_uart3() \
1.299 -do { \
1.300 - REG_GPIO_GPAUR(0) &= 0xFFFF0000; \
1.301 - REG_GPIO_GPAUR(0) |= 0x00005555; \
1.302 -} while (0)
1.303 -
1.304 -#define __gpio_as_uart2() \
1.305 -do { \
1.306 - REG_GPIO_GPALR(3) &= 0x3FFFFFFF; \
1.307 - REG_GPIO_GPALR(3) |= 0x40000000; \
1.308 - REG_GPIO_GPAUR(3) &= 0xF3FFFFFF; \
1.309 - REG_GPIO_GPAUR(3) |= 0x04000000; \
1.310 -} while (0)
1.311 -
1.312 -#define __gpio_as_uart1() \
1.313 -do { \
1.314 - REG_GPIO_GPAUR(0) &= 0xFFF0FFFF; \
1.315 - REG_GPIO_GPAUR(0) |= 0x00050000; \
1.316 -} while (0)
1.317 -
1.318 -#define __gpio_as_uart0() \
1.319 -do { \
1.320 - REG_GPIO_GPAUR(3) &= 0x0FFFFFFF; \
1.321 - REG_GPIO_GPAUR(3) |= 0x50000000; \
1.322 -} while (0)
1.323 -
1.324 -
1.325 -#define __gpio_as_scc0() \
1.326 -do { \
1.327 - REG_GPIO_GPALR(2) &= 0xFFFFFFCC; \
1.328 - REG_GPIO_GPALR(2) |= 0x00000011; \
1.329 -} while (0)
1.330 -
1.331 -#define __gpio_as_scc1() \
1.332 -do { \
1.333 - REG_GPIO_GPALR(2) &= 0xFFFFFF33; \
1.334 - REG_GPIO_GPALR(2) |= 0x00000044; \
1.335 -} while (0)
1.336 -
1.337 -#define __gpio_as_scc() \
1.338 -do { \
1.339 - __gpio_as_scc0(); \
1.340 - __gpio_as_scc1(); \
1.341 -} while (0)
1.342 -
1.343 -#define __gpio_as_dma() \
1.344 -do { \
1.345 - REG_GPIO_GPALR(0) &= 0x00FFFFFF; \
1.346 - REG_GPIO_GPALR(0) |= 0x55000000; \
1.347 - REG_GPIO_GPAUR(0) &= 0xFF0FFFFF; \
1.348 - REG_GPIO_GPAUR(0) |= 0x00500000; \
1.349 -} while (0)
1.350 -
1.351 -#define __gpio_as_msc() \
1.352 -do { \
1.353 - REG_GPIO_GPALR(1) &= 0xFFFF000F; \
1.354 - REG_GPIO_GPALR(1) |= 0x00005550; \
1.355 -} while (0)
1.356 -
1.357 -#define __gpio_as_pcmcia() \
1.358 -do { \
1.359 - REG_GPIO_GPAUR(2) &= 0xF000FFFF; \
1.360 - REG_GPIO_GPAUR(2) |= 0x05550000; \
1.361 -} while (0)
1.362 -
1.363 -#define __gpio_as_emc() \
1.364 -do { \
1.365 - REG_GPIO_GPALR(2) &= 0x3FFFFFFF; \
1.366 - REG_GPIO_GPALR(2) |= 0x40000000; \
1.367 - REG_GPIO_GPAUR(2) &= 0xFFFF0000; \
1.368 - REG_GPIO_GPAUR(2) |= 0x00005555; \
1.369 -} while (0)
1.370 -
1.371 -#define __gpio_as_lcd_slave() \
1.372 -do { \
1.373 - REG_GPIO_GPALR(1) &= 0x0000FFFF; \
1.374 - REG_GPIO_GPALR(1) |= 0x55550000; \
1.375 - REG_GPIO_GPAUR(1) &= 0x00000000; \
1.376 - REG_GPIO_GPAUR(1) |= 0x55555555; \
1.377 -} while (0)
1.378 -
1.379 -#define __gpio_as_lcd_master() \
1.380 -do { \
1.381 - REG_GPIO_GPALR(1) &= 0x0000FFFF; \
1.382 - REG_GPIO_GPALR(1) |= 0x55550000; \
1.383 - REG_GPIO_GPAUR(1) &= 0x00000000; \
1.384 - REG_GPIO_GPAUR(1) |= 0x556A5555; \
1.385 -} while (0)
1.386 -
1.387 -#define __gpio_as_usb() \
1.388 -do { \
1.389 - REG_GPIO_GPAUR(0) &= 0x00FFFFFF; \
1.390 - REG_GPIO_GPAUR(0) |= 0x55000000; \
1.391 -} while (0)
1.392 -
1.393 -#define __gpio_as_ac97() \
1.394 -do { \
1.395 - REG_GPIO_GPALR(2) &= 0xC3FF03FF; \
1.396 - REG_GPIO_GPALR(2) |= 0x24005400; \
1.397 -} while (0)
1.398 -
1.399 -#define __gpio_as_i2s_slave() \
1.400 -do { \
1.401 - REG_GPIO_GPALR(2) &= 0xC3FF0CFF; \
1.402 - REG_GPIO_GPALR(2) |= 0x14005100; \
1.403 -} while (0)
1.404 -
1.405 -#define __gpio_as_i2s_master() \
1.406 -do { \
1.407 - REG_GPIO_GPALR(2) &= 0xC3FF0CFF; \
1.408 - REG_GPIO_GPALR(2) |= 0x28005100; \
1.409 -} while (0)
1.410 -
1.411 -#define __gpio_as_eth() \
1.412 -do { \
1.413 - REG_GPIO_GPAUR(3) &= 0xFC000000; \
1.414 - REG_GPIO_GPAUR(3) |= 0x01555555; \
1.415 -} while (0)
1.416 -
1.417 -#define __gpio_as_pwm() \
1.418 -do { \
1.419 - REG_GPIO_GPAUR(2) &= 0x0FFFFFFF; \
1.420 - REG_GPIO_GPAUR(2) |= 0x50000000; \
1.421 -} while (0)
1.422 -
1.423 -#define __gpio_as_ps2() \
1.424 -do { \
1.425 - REG_GPIO_GPALR(1) &= 0xFFFFFFF0; \
1.426 - REG_GPIO_GPALR(1) |= 0x00000005; \
1.427 -} while (0)
1.428 -
1.429 -#define __gpio_as_uprt() \
1.430 -do { \
1.431 - REG_GPIO_GPALR(1) &= 0x0000000F; \
1.432 - REG_GPIO_GPALR(1) |= 0x55555550; \
1.433 - REG_GPIO_GPALR(3) &= 0xC0000000; \
1.434 - REG_GPIO_GPALR(3) |= 0x15555555; \
1.435 -} while (0)
1.436 -
1.437 -#define __gpio_as_cim() \
1.438 -do { \
1.439 - REG_GPIO_GPALR(0) &= 0xFF000000; \
1.440 - REG_GPIO_GPALR(0) |= 0x00555555; \
1.441 -} while (0)
1.442 +/* Register operations using absolute positioning have been removed. */
1.443
1.444 /***************************************************************************
1.445 * HARB
2.1 --- a/include/jz4740.h Tue Jul 11 18:45:08 2017 +0200
2.2 +++ b/include/jz4740.h Wed Jul 12 15:46:53 2017 +0200
2.3 @@ -742,60 +742,11 @@
2.4 /*************************************************************************
2.5 * GPIO (General-Purpose I/O Ports)
2.6 *************************************************************************/
2.7 +
2.8 +/* Register definitions with absolute positioning have been removed. */
2.9 +
2.10 #define MAX_GPIO_NUM 128
2.11
2.12 -/* = 0,1,2,3 */
2.13 -#define GPIO_PXPIN(n) (GPIO_BASE + (0x00 + (n)*0x100)) /* PIN Level Register */
2.14 -#define GPIO_PXDAT(n) (GPIO_BASE + (0x10 + (n)*0x100)) /* Port Data Register */
2.15 -#define GPIO_PXDATS(n) (GPIO_BASE + (0x14 + (n)*0x100)) /* Port Data Set Register */
2.16 -#define GPIO_PXDATC(n) (GPIO_BASE + (0x18 + (n)*0x100)) /* Port Data Clear Register */
2.17 -#define GPIO_PXIM(n) (GPIO_BASE + (0x20 + (n)*0x100)) /* Interrupt Mask Register */
2.18 -#define GPIO_PXIMS(n) (GPIO_BASE + (0x24 + (n)*0x100)) /* Interrupt Mask Set Reg */
2.19 -#define GPIO_PXIMC(n) (GPIO_BASE + (0x28 + (n)*0x100)) /* Interrupt Mask Clear Reg */
2.20 -#define GPIO_PXPE(n) (GPIO_BASE + (0x30 + (n)*0x100)) /* Pull Enable Register */
2.21 -#define GPIO_PXPES(n) (GPIO_BASE + (0x34 + (n)*0x100)) /* Pull Enable Set Reg. */
2.22 -#define GPIO_PXPEC(n) (GPIO_BASE + (0x38 + (n)*0x100)) /* Pull Enable Clear Reg. */
2.23 -#define GPIO_PXFUN(n) (GPIO_BASE + (0x40 + (n)*0x100)) /* Function Register */
2.24 -#define GPIO_PXFUNS(n) (GPIO_BASE + (0x44 + (n)*0x100)) /* Function Set Register */
2.25 -#define GPIO_PXFUNC(n) (GPIO_BASE + (0x48 + (n)*0x100)) /* Function Clear Register */
2.26 -#define GPIO_PXSEL(n) (GPIO_BASE + (0x50 + (n)*0x100)) /* Select Register */
2.27 -#define GPIO_PXSELS(n) (GPIO_BASE + (0x54 + (n)*0x100)) /* Select Set Register */
2.28 -#define GPIO_PXSELC(n) (GPIO_BASE + (0x58 + (n)*0x100)) /* Select Clear Register */
2.29 -#define GPIO_PXDIR(n) (GPIO_BASE + (0x60 + (n)*0x100)) /* Direction Register */
2.30 -#define GPIO_PXDIRS(n) (GPIO_BASE + (0x64 + (n)*0x100)) /* Direction Set Register */
2.31 -#define GPIO_PXDIRC(n) (GPIO_BASE + (0x68 + (n)*0x100)) /* Direction Clear Register */
2.32 -#define GPIO_PXTRG(n) (GPIO_BASE + (0x70 + (n)*0x100)) /* Trigger Register */
2.33 -#define GPIO_PXTRGS(n) (GPIO_BASE + (0x74 + (n)*0x100)) /* Trigger Set Register */
2.34 -#define GPIO_PXTRGC(n) (GPIO_BASE + (0x78 + (n)*0x100)) /* Trigger Set Register */
2.35 -#define GPIO_PXFLG(n) (GPIO_BASE + (0x80 + (n)*0x100)) /* Port Flag Register */
2.36 -#define GPIO_PXFLGC(n) (GPIO_BASE + (0x84 + (n)*0x100)) /* Port Flag clear Register */
2.37 -
2.38 -#define REG_GPIO_PXPIN(n) REG32(GPIO_PXPIN((n))) /* PIN level */
2.39 -#define REG_GPIO_PXDAT(n) REG32(GPIO_PXDAT((n))) /* 1: interrupt pending */
2.40 -#define REG_GPIO_PXDATS(n) REG32(GPIO_PXDATS((n)))
2.41 -#define REG_GPIO_PXDATC(n) REG32(GPIO_PXDATC((n)))
2.42 -#define REG_GPIO_PXIM(n) REG32(GPIO_PXIM((n))) /* 1: mask pin interrupt */
2.43 -#define REG_GPIO_PXIMS(n) REG32(GPIO_PXIMS((n)))
2.44 -#define REG_GPIO_PXIMC(n) REG32(GPIO_PXIMC((n)))
2.45 -#define REG_GPIO_PXPE(n) REG32(GPIO_PXPE((n))) /* 1: disable pull up/down */
2.46 -#define REG_GPIO_PXPES(n) REG32(GPIO_PXPES((n)))
2.47 -#define REG_GPIO_PXPEC(n) REG32(GPIO_PXPEC((n)))
2.48 -#define REG_GPIO_PXFUN(n) REG32(GPIO_PXFUN((n))) /* 0:GPIO or intr, 1:FUNC */
2.49 -#define REG_GPIO_PXFUNS(n) REG32(GPIO_PXFUNS((n)))
2.50 -#define REG_GPIO_PXFUNC(n) REG32(GPIO_PXFUNC((n)))
2.51 -#define REG_GPIO_PXSEL(n) REG32(GPIO_PXSEL((n))) /* 0:GPIO/Fun0,1:intr/fun1*/
2.52 -#define REG_GPIO_PXSELS(n) REG32(GPIO_PXSELS((n)))
2.53 -#define REG_GPIO_PXSELC(n) REG32(GPIO_PXSELC((n)))
2.54 -#define REG_GPIO_PXDIR(n) REG32(GPIO_PXDIR((n))) /* 0:input/low-level-trig/falling-edge-trig, 1:output/high-level-trig/rising-edge-trig */
2.55 -#define REG_GPIO_PXDIRS(n) REG32(GPIO_PXDIRS((n)))
2.56 -#define REG_GPIO_PXDIRC(n) REG32(GPIO_PXDIRC((n)))
2.57 -#define REG_GPIO_PXTRG(n) REG32(GPIO_PXTRG((n))) /* 0:level-trigger, 1:edge-trigger */
2.58 -#define REG_GPIO_PXTRGS(n) REG32(GPIO_PXTRGS((n)))
2.59 -#define REG_GPIO_PXTRGC(n) REG32(GPIO_PXTRGC((n)))
2.60 -#define REG_GPIO_PXFLG(n) REG32(GPIO_PXFLG((n))) /* interrupt flag */
2.61 -#define REG_GPIO_PXFLGC(n) REG32(GPIO_PXFLGC((n))) /* interrupt flag */
2.62 -
2.63 -
2.64 /*************************************************************************
2.65 * UART
2.66 *************************************************************************/
2.67 @@ -2317,701 +2268,10 @@
2.68
2.69
2.70 /* Module Operation Definitions */
2.71 +
2.72 #ifndef __ASSEMBLY__
2.73
2.74 -
2.75 -/* GPIO Pins Description */
2.76 -/* PORT 0: */
2.77 -/* PIN/BIT N FUNC0 FUNC1 */
2.78 -/* 0 D0 - */
2.79 -/* 1 D1 - */
2.80 -/* 2 D2 - */
2.81 -/* 3 D3 - */
2.82 -/* 4 D4 - */
2.83 -/* 5 D5 - */
2.84 -/* 6 D6 - */
2.85 -/* 7 D7 - */
2.86 -/* 8 D8 - */
2.87 -/* 9 D9 - */
2.88 -/* 10 D10 - */
2.89 -/* 11 D11 - */
2.90 -/* 12 D12 - */
2.91 -/* 13 D13 - */
2.92 -/* 14 D14 - */
2.93 -/* 15 D15 - */
2.94 -/* 16 D16 - */
2.95 -/* 17 D17 - */
2.96 -/* 18 D18 - */
2.97 -/* 19 D19 - */
2.98 -/* 20 D20 - */
2.99 -/* 21 D21 - */
2.100 -/* 22 D22 - */
2.101 -/* 23 D23 - */
2.102 -/* 24 D24 - */
2.103 -/* 25 D25 - */
2.104 -/* 26 D26 - */
2.105 -/* 27 D27 - */
2.106 -/* 28 D28 - */
2.107 -/* 29 D29 - */
2.108 -/* 30 D30 - */
2.109 -/* 31 D31 - */
2.110 -/*------------------------------------------------------ */
2.111 -/* PORT 1: */
2.112 -/* */
2.113 -/* PIN/BIT N FUNC0 FUNC1 */
2.114 -/* 0 A0 - */
2.115 -/* 1 A1 - */
2.116 -/* 2 A2 - */
2.117 -/* 3 A3 - */
2.118 -/* 4 A4 - */
2.119 -/* 5 A5 - */
2.120 -/* 6 A6 - */
2.121 -/* 7 A7 - */
2.122 -/* 8 A8 - */
2.123 -/* 9 A9 - */
2.124 -/* 10 A10 - */
2.125 -/* 11 A11 - */
2.126 -/* 12 A12 - */
2.127 -/* 13 A13 - */
2.128 -/* 14 A14 - */
2.129 -/* 15 A15/CL - */
2.130 -/* 16 A16/AL - */
2.131 -/* 17 LCD_CLS A21 */
2.132 -/* 18 LCD_SPL A22 */
2.133 -/* 19 DCS# - */
2.134 -/* 20 RAS# - */
2.135 -/* 21 CAS# - */
2.136 -/* 22 RDWE#/BUFD# - */
2.137 -/* 23 CKE - */
2.138 -/* 24 CKO - */
2.139 -/* 25 CS1# - */
2.140 -/* 26 CS2# - */
2.141 -/* 27 CS3# - */
2.142 -/* 28 CS4# - */
2.143 -/* 29 RD# - */
2.144 -/* 30 WR# - */
2.145 -/* 31 WE0# - */
2.146 -/* Note: PIN15&16 are CL&AL when connecting to NAND flash. */
2.147 -/*------------------------------------------------------ */
2.148 -/* PORT 2: */
2.149 -/* */
2.150 -/* PIN/BIT N FUNC0 FUNC1 */
2.151 -/* 0 LCD_D0 - */
2.152 -/* 1 LCD_D1 - */
2.153 -/* 2 LCD_D2 - */
2.154 -/* 3 LCD_D3 - */
2.155 -/* 4 LCD_D4 - */
2.156 -/* 5 LCD_D5 - */
2.157 -/* 6 LCD_D6 - */
2.158 -/* 7 LCD_D7 - */
2.159 -/* 8 LCD_D8 - */
2.160 -/* 9 LCD_D9 - */
2.161 -/* 10 LCD_D10 - */
2.162 -/* 11 LCD_D11 - */
2.163 -/* 12 LCD_D12 - */
2.164 -/* 13 LCD_D13 - */
2.165 -/* 14 LCD_D14 - */
2.166 -/* 15 LCD_D15 - */
2.167 -/* 16 LCD_D16 - */
2.168 -/* 17 LCD_D17 - */
2.169 -/* 18 LCD_PCLK - */
2.170 -/* 19 LCD_HSYNC - */
2.171 -/* 20 LCD_VSYNC - */
2.172 -/* 21 LCD_DE - */
2.173 -/* 22 LCD_PS A19 */
2.174 -/* 23 LCD_REV A20 */
2.175 -/* 24 WE1# - */
2.176 -/* 25 WE2# - */
2.177 -/* 26 WE3# - */
2.178 -/* 27 WAIT# - */
2.179 -/* 28 FRE# - */
2.180 -/* 29 FWE# - */
2.181 -/* 30(NOTE:FRB#) - - */
2.182 -/* 31 - - */
2.183 -/* NOTE(1): PIN30 is used for FRB# when connecting to NAND flash. */
2.184 -/*------------------------------------------------------ */
2.185 -/* PORT 3: */
2.186 -/* */
2.187 -/* PIN/BIT N FUNC0 FUNC1 */
2.188 -/* 0 CIM_D0 - */
2.189 -/* 1 CIM_D1 - */
2.190 -/* 2 CIM_D2 - */
2.191 -/* 3 CIM_D3 - */
2.192 -/* 4 CIM_D4 - */
2.193 -/* 5 CIM_D5 - */
2.194 -/* 6 CIM_D6 - */
2.195 -/* 7 CIM_D7 - */
2.196 -/* 8 MSC_CMD - */
2.197 -/* 9 MSC_CLK - */
2.198 -/* 10 MSC_D0 - */
2.199 -/* 11 MSC_D1 - */
2.200 -/* 12 MSC_D2 - */
2.201 -/* 13 MSC_D3 - */
2.202 -/* 14 CIM_MCLK - */
2.203 -/* 15 CIM_PCLK - */
2.204 -/* 16 CIM_VSYNC - */
2.205 -/* 17 CIM_HSYNC - */
2.206 -/* 18 SSI_CLK SCLK_RSTN */
2.207 -/* 19 SSI_CE0# BIT_CLK(AIC) */
2.208 -/* 20 SSI_DT SDATA_OUT(AIC) */
2.209 -/* 21 SSI_DR SDATA_IN(AIC) */
2.210 -/* 22 SSI_CE1#&GPC SYNC(AIC) */
2.211 -/* 23 PWM0 I2C_SDA */
2.212 -/* 24 PWM1 I2C_SCK */
2.213 -/* 25 PWM2 UART0_TxD */
2.214 -/* 26 PWM3 UART0_RxD */
2.215 -/* 27 PWM4 A17 */
2.216 -/* 28 PWM5 A18 */
2.217 -/* 29 - - */
2.218 -/* 30 PWM6 UART0_CTS/UART1_RxD */
2.219 -/* 31 PWM7 UART0_RTS/UART1_TxD */
2.220 -/*
2.221 - * p is the port number (0,1,2,3)
2.222 - * o is the pin offset (0-31) inside the port
2.223 - * n is the absolute number of a pin (0-127), regardless of the port
2.224 - */
2.225 -
2.226 -/* Function Pins Mode */
2.227 -
2.228 -#define __gpio_as_func0(n) \
2.229 -do { \
2.230 - unsigned int p, o; \
2.231 - p = (n) / 32; \
2.232 - o = (n) % 32; \
2.233 - REG_GPIO_PXFUNS(p) = (1 << o); \
2.234 - REG_GPIO_PXSELC(p) = (1 << o); \
2.235 -} while (0)
2.236 -
2.237 -#define __gpio_as_func1(n) \
2.238 -do { \
2.239 - unsigned int p, o; \
2.240 - p = (n) / 32; \
2.241 - o = (n) % 32; \
2.242 - REG_GPIO_PXFUNS(p) = (1 << o); \
2.243 - REG_GPIO_PXSELS(p) = (1 << o); \
2.244 -} while (0)
2.245 -
2.246 -/*
2.247 - * D0 ~ D31, A0 ~ A16, DCS#, RAS#, CAS#, CKE#,
2.248 - * RDWE#, CKO#, WE0#, WE1#, WE2#, WE3#
2.249 - */
2.250 -#define __gpio_as_sdram_32bit() \
2.251 -do { \
2.252 - REG_GPIO_PXFUNS(0) = 0xffffffff; \
2.253 - REG_GPIO_PXSELC(0) = 0xffffffff; \
2.254 - REG_GPIO_PXPES(0) = 0xffffffff; \
2.255 - REG_GPIO_PXFUNS(1) = 0x81f9ffff; \
2.256 - REG_GPIO_PXSELC(1) = 0x81f9ffff; \
2.257 - REG_GPIO_PXPES(1) = 0x81f9ffff; \
2.258 - REG_GPIO_PXFUNS(2) = 0x07000000; \
2.259 - REG_GPIO_PXSELC(2) = 0x07000000; \
2.260 - REG_GPIO_PXPES(2) = 0x07000000; \
2.261 -} while (0)
2.262 -
2.263 -/*
2.264 - * D0 ~ D15, A0 ~ A16, DCS#, RAS#, CAS#, CKE#,
2.265 - * RDWE#, CKO#, WE0#, WE1#
2.266 - */
2.267 -#define __gpio_as_sdram_16bit_4720() \
2.268 -do { \
2.269 - REG_GPIO_PXFUNS(0) = 0x5442bfaa; \
2.270 - REG_GPIO_PXSELC(0) = 0x5442bfaa; \
2.271 - REG_GPIO_PXPES(0) = 0x5442bfaa; \
2.272 - REG_GPIO_PXFUNS(1) = 0x81f9ffff; \
2.273 - REG_GPIO_PXSELC(1) = 0x81f9ffff; \
2.274 - REG_GPIO_PXPES(1) = 0x81f9ffff; \
2.275 - REG_GPIO_PXFUNS(2) = 0x01000000; \
2.276 - REG_GPIO_PXSELC(2) = 0x01000000; \
2.277 - REG_GPIO_PXPES(2) = 0x01000000; \
2.278 -} while (0)
2.279 -
2.280 -/*
2.281 - * D0 ~ D15, A0 ~ A16, DCS#, RAS#, CAS#, CKE#,
2.282 - * RDWE#, CKO#, WE0#, WE1#
2.283 - */
2.284 -#define __gpio_as_sdram_16bit_4725() \
2.285 -do { \
2.286 - REG_GPIO_PXFUNS(0) = 0x0000ffff; \
2.287 - REG_GPIO_PXSELC(0) = 0x0000ffff; \
2.288 - REG_GPIO_PXPES(0) = 0x0000ffff; \
2.289 - REG_GPIO_PXFUNS(1) = 0x81f9ffff; \
2.290 - REG_GPIO_PXSELC(1) = 0x81f9ffff; \
2.291 - REG_GPIO_PXPES(1) = 0x81f9ffff; \
2.292 - REG_GPIO_PXFUNS(2) = 0x01000000; \
2.293 - REG_GPIO_PXSELC(2) = 0x01000000; \
2.294 - REG_GPIO_PXPES(2) = 0x01000000; \
2.295 -} while (0)
2.296 -
2.297 -
2.298 -/*
2.299 - * CS1#, CLE, ALE, FRE#, FWE#, FRB#, RDWE#/BUFD#
2.300 - */
2.301 -#define __gpio_as_nand() \
2.302 -do { \
2.303 - REG_GPIO_PXFUNS(1) = 0x02018000; \
2.304 - REG_GPIO_PXSELC(1) = 0x02018000; \
2.305 - REG_GPIO_PXPES(1) = 0x02018000; \
2.306 - REG_GPIO_PXFUNS(2) = 0x30000000; \
2.307 - REG_GPIO_PXSELC(2) = 0x30000000; \
2.308 - REG_GPIO_PXPES(2) = 0x30000000; \
2.309 - REG_GPIO_PXFUNC(2) = 0x40000000; \
2.310 - REG_GPIO_PXSELC(2) = 0x40000000; \
2.311 - REG_GPIO_PXDIRC(2) = 0x40000000; \
2.312 - REG_GPIO_PXPES(2) = 0x40000000; \
2.313 - REG_GPIO_PXFUNS(1) = 0x00400000; \
2.314 - REG_GPIO_PXSELC(1) = 0x00400000; \
2.315 -} while (0)
2.316 -
2.317 -/*
2.318 - * CS4#, RD#, WR#, WAIT#, A0 ~ A22, D0 ~ D7
2.319 - */
2.320 -#define __gpio_as_nor_8bit() \
2.321 -do { \
2.322 - REG_GPIO_PXFUNS(0) = 0x000000ff; \
2.323 - REG_GPIO_PXSELC(0) = 0x000000ff; \
2.324 - REG_GPIO_PXPES(0) = 0x000000ff; \
2.325 - REG_GPIO_PXFUNS(1) = 0x7041ffff; \
2.326 - REG_GPIO_PXSELC(1) = 0x7041ffff; \
2.327 - REG_GPIO_PXPES(1) = 0x7041ffff; \
2.328 - REG_GPIO_PXFUNS(1) = 0x00060000; \
2.329 - REG_GPIO_PXSELS(1) = 0x00060000; \
2.330 - REG_GPIO_PXPES(1) = 0x00060000; \
2.331 - REG_GPIO_PXFUNS(2) = 0x08000000; \
2.332 - REG_GPIO_PXSELC(2) = 0x08000000; \
2.333 - REG_GPIO_PXPES(2) = 0x08000000; \
2.334 - REG_GPIO_PXFUNS(2) = 0x00c00000; \
2.335 - REG_GPIO_PXSELS(2) = 0x00c00000; \
2.336 - REG_GPIO_PXPES(2) = 0x00c00000; \
2.337 - REG_GPIO_PXFUNS(3) = 0x18000000; \
2.338 - REG_GPIO_PXSELS(3) = 0x18000000; \
2.339 - REG_GPIO_PXPES(3) = 0x18000000; \
2.340 -} while (0)
2.341 -
2.342 -/*
2.343 - * CS4#, RD#, WR#, WAIT#, A0 ~ A22, D0 ~ D15
2.344 - */
2.345 -#define __gpio_as_nor_16bit() \
2.346 -do { \
2.347 - REG_GPIO_PXFUNS(0) = 0x0000ffff; \
2.348 - REG_GPIO_PXSELC(0) = 0x0000ffff; \
2.349 - REG_GPIO_PXPES(0) = 0x0000ffff; \
2.350 - REG_GPIO_PXFUNS(1) = 0x7041ffff; \
2.351 - REG_GPIO_PXSELC(1) = 0x7041ffff; \
2.352 - REG_GPIO_PXPES(1) = 0x7041ffff; \
2.353 - REG_GPIO_PXFUNS(1) = 0x00060000; \
2.354 - REG_GPIO_PXSELS(1) = 0x00060000; \
2.355 - REG_GPIO_PXPES(1) = 0x00060000; \
2.356 - REG_GPIO_PXFUNS(2) = 0x08000000; \
2.357 - REG_GPIO_PXSELC(2) = 0x08000000; \
2.358 - REG_GPIO_PXPES(2) = 0x08000000; \
2.359 - REG_GPIO_PXFUNS(2) = 0x00c00000; \
2.360 - REG_GPIO_PXSELS(2) = 0x00c00000; \
2.361 - REG_GPIO_PXPES(2) = 0x00c00000; \
2.362 - REG_GPIO_PXFUNS(3) = 0x18000000; \
2.363 - REG_GPIO_PXSELS(3) = 0x18000000; \
2.364 - REG_GPIO_PXPES(3) = 0x18000000; \
2.365 -} while (0)
2.366 -
2.367 -/*
2.368 - * UART0_TxD, UART_RxD0
2.369 - */
2.370 -#define __gpio_as_uart0() \
2.371 -do { \
2.372 - REG_GPIO_PXFUNS(3) = 0x06000000; \
2.373 - REG_GPIO_PXSELS(3) = 0x06000000; \
2.374 - REG_GPIO_PXPES(3) = 0x06000000; \
2.375 -} while (0)
2.376 -
2.377 -#define __gpio_jtag_to_uart0() \
2.378 -do { \
2.379 - REG_GPIO_PXSELS(2) = 0x80000000; \
2.380 -} while (0)
2.381 -
2.382 -/*
2.383 - * UART0_CTS, UART0_RTS
2.384 - */
2.385 -#define __gpio_as_ctsrts() \
2.386 -do { \
2.387 - REG_GPIO_PXFUNS(3) = 0xc0000000; \
2.388 - REG_GPIO_PXSELS(3) = 0xc0000000; \
2.389 - REG_GPIO_PXTRGC(3) = 0xc0000000; \
2.390 - REG_GPIO_PXPES(3) = 0xc0000000; \
2.391 -} while (0)
2.392 -
2.393 -/*
2.394 - * UART1_TxD, UART1_RxD1
2.395 - */
2.396 -#define __gpio_as_uart1() \
2.397 -do { \
2.398 - REG_GPIO_PXFUNS(3) = 0xc0000000; \
2.399 - REG_GPIO_PXSELC(3) = 0xc0000000; \
2.400 - REG_GPIO_PXTRGS(3) = 0xc0000000; \
2.401 - REG_GPIO_PXPES(3) = 0xc0000000; \
2.402 -} while (0)
2.403 -
2.404 -/*
2.405 - * LCD_D0~LCD_D15, LCD_PCLK, LCD_HSYNC, LCD_VSYNC, LCD_DE
2.406 - */
2.407 -#define __gpio_as_lcd_16bit() \
2.408 -do { \
2.409 - REG_GPIO_PXFUNS(2) = 0x003cffff; \
2.410 - REG_GPIO_PXSELC(2) = 0x003cffff; \
2.411 - REG_GPIO_PXPES(2) = 0x003cffff; \
2.412 -} while (0)
2.413 -
2.414 -/*
2.415 - * LCD_D0~LCD_D17, LCD_PCLK, LCD_HSYNC, LCD_VSYNC, LCD_DE
2.416 - */
2.417 -#define __gpio_as_lcd_18bit() \
2.418 -do { \
2.419 - REG_GPIO_PXFUNS(2) = 0x003fffff; \
2.420 - REG_GPIO_PXSELC(2) = 0x003fffff; \
2.421 - REG_GPIO_PXPES(2) = 0x003fffff; \
2.422 -} while (0)
2.423 -
2.424 -
2.425 -/* LCD_D0~LCD_D7, SLCD_CLK, SLCD_RS, SLCD_CS, LCD_DE */
2.426 -#define __gpio_as_slcd_8bit() \
2.427 -do { \
2.428 - REG_GPIO_PXFUNS(2) = 0x003c00ff; \
2.429 - REG_GPIO_PXSELC(2) = 0x003c00ff; \
2.430 -} while (0)
2.431 -
2.432 -/* LCD_D0~LCD_D7, SLCD_RS, SLCD_CS */
2.433 -#define __gpio_as_slcd_9bit() \
2.434 -do { \
2.435 - REG_GPIO_PXFUNS(2) = 0x001801ff; \
2.436 - REG_GPIO_PXSELC(2) = 0x001801ff; \
2.437 -} while (0)
2.438 -
2.439 -/* LCD_D0~LCD_D15, SLCD_RS, SLCD_CS */
2.440 -#define __gpio_as_slcd_16bit() \
2.441 -do { \
2.442 - REG_GPIO_PXFUNS(2) = 0x0018ffff; \
2.443 - REG_GPIO_PXSELC(2) = 0x0018ffff; \
2.444 -} while (0)
2.445 -
2.446 -/* LCD_D0~LCD_D17, SLCD_RS, SLCD_CS */
2.447 -#define __gpio_as_slcd_18bit() \
2.448 -do { \
2.449 - REG_GPIO_PXFUNS(2) = 0x001bffff; \
2.450 - REG_GPIO_PXSELC(2) = 0x001bffff; \
2.451 -} while (0)
2.452 -/*
2.453 - * CIM_D0~CIM_D7, CIM_MCLK, CIM_PCLK, CIM_VSYNC, CIM_HSYNC
2.454 - */
2.455 -#define __gpio_as_cim() \
2.456 -do { \
2.457 - REG_GPIO_PXFUNS(3) = 0x0003c0ff; \
2.458 - REG_GPIO_PXSELC(3) = 0x0003c0ff; \
2.459 - REG_GPIO_PXPES(3) = 0x0003c0ff; \
2.460 -} while (0)
2.461 -
2.462 -/*
2.463 - * SDATA_OUT, SDATA_IN, BIT_CLK, SYNC, SCLK_RESET
2.464 - */
2.465 -#define __gpio_as_aic() \
2.466 -do { \
2.467 - REG_GPIO_PXFUNS(3) = 0x007c0000; \
2.468 - REG_GPIO_PXSELS(3) = 0x007c0000; \
2.469 - REG_GPIO_PXPES(3) = 0x007c0000; \
2.470 -} while (0)
2.471 -
2.472 -/*
2.473 - * MSC_CMD, MSC_CLK, MSC_D0 ~ MSC_D3
2.474 - */
2.475 -#define __gpio_as_msc() \
2.476 -do { \
2.477 - REG_GPIO_PXFUNS(3) = 0x00003f00; \
2.478 - REG_GPIO_PXSELC(3) = 0x00003f00; \
2.479 - REG_GPIO_PXPES(3) = 0x00003f00; \
2.480 -} while (0)
2.481 -
2.482 -/*
2.483 - * SSI_CS0, SSI_CLK, SSI_DT, SSI_DR
2.484 - */
2.485 -#define __gpio_as_ssi() \
2.486 -do { \
2.487 - REG_GPIO_PXFUNS(3) = 0x003c0000; \
2.488 - REG_GPIO_PXSELC(3) = 0x003c0000; \
2.489 - REG_GPIO_PXPES(3) = 0x003c0000; \
2.490 -} while (0)
2.491 -
2.492 -/*
2.493 - * I2C_SCK, I2C_SDA
2.494 - */
2.495 -#define __gpio_as_i2c() \
2.496 -do { \
2.497 - REG_GPIO_PXFUNS(3) = 0x01800000; \
2.498 - REG_GPIO_PXSELS(3) = 0x01800000; \
2.499 - REG_GPIO_PXPES(3) = 0x01800000; \
2.500 -} while (0)
2.501 -
2.502 -/*
2.503 - * PWM0
2.504 - */
2.505 -#define __gpio_as_pwm0() \
2.506 -do { \
2.507 - REG_GPIO_PXFUNS(3) = 0x00800000; \
2.508 - REG_GPIO_PXSELC(3) = 0x00800000; \
2.509 - REG_GPIO_PXPES(3) = 0x00800000; \
2.510 -} while (0)
2.511 -
2.512 -/*
2.513 - * PWM1
2.514 - */
2.515 -#define __gpio_as_pwm1() \
2.516 -do { \
2.517 - REG_GPIO_PXFUNS(3) = 0x01000000; \
2.518 - REG_GPIO_PXSELC(3) = 0x01000000; \
2.519 - REG_GPIO_PXPES(3) = 0x01000000; \
2.520 -} while (0)
2.521 -
2.522 -/*
2.523 - * PWM2
2.524 - */
2.525 -#define __gpio_as_pwm2() \
2.526 -do { \
2.527 - REG_GPIO_PXFUNS(3) = 0x02000000; \
2.528 - REG_GPIO_PXSELC(3) = 0x02000000; \
2.529 - REG_GPIO_PXPES(3) = 0x02000000; \
2.530 -} while (0)
2.531 -
2.532 -/*
2.533 - * PWM3
2.534 - */
2.535 -#define __gpio_as_pwm3() \
2.536 -do { \
2.537 - REG_GPIO_PXFUNS(3) = 0x04000000; \
2.538 - REG_GPIO_PXSELC(3) = 0x04000000; \
2.539 - REG_GPIO_PXPES(3) = 0x04000000; \
2.540 -} while (0)
2.541 -
2.542 -/*
2.543 - * PWM4
2.544 - */
2.545 -#define __gpio_as_pwm4() \
2.546 -do { \
2.547 - REG_GPIO_PXFUNS(3) = 0x08000000; \
2.548 - REG_GPIO_PXSELC(3) = 0x08000000; \
2.549 - REG_GPIO_PXPES(3) = 0x08000000; \
2.550 -} while (0)
2.551 -
2.552 -/*
2.553 - * PWM5
2.554 - */
2.555 -#define __gpio_as_pwm5() \
2.556 -do { \
2.557 - REG_GPIO_PXFUNS(3) = 0x10000000; \
2.558 - REG_GPIO_PXSELC(3) = 0x10000000; \
2.559 - REG_GPIO_PXPES(3) = 0x10000000; \
2.560 -} while (0)
2.561 -
2.562 -/*
2.563 - * PWM6
2.564 - */
2.565 -#define __gpio_as_pwm6() \
2.566 -do { \
2.567 - REG_GPIO_PXFUNS(3) = 0x40000000; \
2.568 - REG_GPIO_PXSELC(3) = 0x40000000; \
2.569 - REG_GPIO_PXPES(3) = 0x40000000; \
2.570 -} while (0)
2.571 -
2.572 -/*
2.573 - * PWM7
2.574 - */
2.575 -#define __gpio_as_pwm7() \
2.576 -do { \
2.577 - REG_GPIO_PXFUNS(3) = 0x80000000; \
2.578 - REG_GPIO_PXSELC(3) = 0x80000000; \
2.579 - REG_GPIO_PXPES(3) = 0x80000000; \
2.580 -} while (0)
2.581 -
2.582 -/*
2.583 - * n = 0 ~ 7
2.584 - */
2.585 -#define __gpio_as_pwm(n) __gpio_as_pwm##n()
2.586 -
2.587 -/* GPIO or Interrupt Mode */
2.588 -
2.589 -#define __gpio_get_port(p) (REG_GPIO_PXPIN(p))
2.590 -
2.591 -#define __gpio_port_as_output(p, o) \
2.592 -do { \
2.593 - REG_GPIO_PXFUNC(p) = (1 << (o)); \
2.594 - REG_GPIO_PXSELC(p) = (1 << (o)); \
2.595 - REG_GPIO_PXDIRS(p) = (1 << (o)); \
2.596 -} while (0)
2.597 -
2.598 -#define __gpio_port_as_input(p, o) \
2.599 -do { \
2.600 - REG_GPIO_PXFUNC(p) = (1 << (o)); \
2.601 - REG_GPIO_PXSELC(p) = (1 << (o)); \
2.602 - REG_GPIO_PXDIRC(p) = (1 << (o)); \
2.603 -} while (0)
2.604 -
2.605 -#define __gpio_as_output(n) \
2.606 -do { \
2.607 - unsigned int p, o; \
2.608 - p = (n) / 32; \
2.609 - o = (n) % 32; \
2.610 - __gpio_port_as_output(p, o); \
2.611 -} while (0)
2.612 -
2.613 -#define __gpio_as_input(n) \
2.614 -do { \
2.615 - unsigned int p, o; \
2.616 - p = (n) / 32; \
2.617 - o = (n) % 32; \
2.618 - __gpio_port_as_input(p, o); \
2.619 -} while (0)
2.620 -
2.621 -#define __gpio_set_pin(n) \
2.622 -do { \
2.623 - unsigned int p, o; \
2.624 - p = (n) / 32; \
2.625 - o = (n) % 32; \
2.626 - REG_GPIO_PXDATS(p) = (1 << o); \
2.627 -} while (0)
2.628 -
2.629 -#define __gpio_clear_pin(n) \
2.630 -do { \
2.631 - unsigned int p, o; \
2.632 - p = (n) / 32; \
2.633 - o = (n) % 32; \
2.634 - REG_GPIO_PXDATC(p) = (1 << o); \
2.635 -} while (0)
2.636 -
2.637 -#define __gpio_get_pin(n) \
2.638 -({ \
2.639 - unsigned int p, o, v; \
2.640 - p = (n) / 32; \
2.641 - o = (n) % 32; \
2.642 - if (__gpio_get_port(p) & (1 << o)) \
2.643 - v = 1; \
2.644 - else \
2.645 - v = 0; \
2.646 - v; \
2.647 -})
2.648 -
2.649 -#define __gpio_as_irq_high_level(n) \
2.650 -do { \
2.651 - unsigned int p, o; \
2.652 - p = (n) / 32; \
2.653 - o = (n) % 32; \
2.654 - REG_GPIO_PXIMS(p) = (1 << o); \
2.655 - REG_GPIO_PXTRGC(p) = (1 << o); \
2.656 - REG_GPIO_PXFUNC(p) = (1 << o); \
2.657 - REG_GPIO_PXSELS(p) = (1 << o); \
2.658 - REG_GPIO_PXDIRS(p) = (1 << o); \
2.659 - REG_GPIO_PXFLGC(p) = (1 << o); \
2.660 - REG_GPIO_PXIMC(p) = (1 << o); \
2.661 -} while (0)
2.662 -
2.663 -#define __gpio_as_irq_low_level(n) \
2.664 -do { \
2.665 - unsigned int p, o; \
2.666 - p = (n) / 32; \
2.667 - o = (n) % 32; \
2.668 - REG_GPIO_PXIMS(p) = (1 << o); \
2.669 - REG_GPIO_PXTRGC(p) = (1 << o); \
2.670 - REG_GPIO_PXFUNC(p) = (1 << o); \
2.671 - REG_GPIO_PXSELS(p) = (1 << o); \
2.672 - REG_GPIO_PXDIRC(p) = (1 << o); \
2.673 - REG_GPIO_PXFLGC(p) = (1 << o); \
2.674 - REG_GPIO_PXIMC(p) = (1 << o); \
2.675 -} while (0)
2.676 -
2.677 -#define __gpio_as_irq_rise_edge(n) \
2.678 -do { \
2.679 - unsigned int p, o; \
2.680 - p = (n) / 32; \
2.681 - o = (n) % 32; \
2.682 - REG_GPIO_PXIMS(p) = (1 << o); \
2.683 - REG_GPIO_PXTRGS(p) = (1 << o); \
2.684 - REG_GPIO_PXFUNC(p) = (1 << o); \
2.685 - REG_GPIO_PXSELS(p) = (1 << o); \
2.686 - REG_GPIO_PXDIRS(p) = (1 << o); \
2.687 - REG_GPIO_PXFLGC(p) = (1 << o); \
2.688 - REG_GPIO_PXIMC(p) = (1 << o); \
2.689 -} while (0)
2.690 -
2.691 -#define __gpio_as_irq_fall_edge(n) \
2.692 -do { \
2.693 - unsigned int p, o; \
2.694 - p = (n) / 32; \
2.695 - o = (n) % 32; \
2.696 - REG_GPIO_PXIMS(p) = (1 << o); \
2.697 - REG_GPIO_PXTRGS(p) = (1 << o); \
2.698 - REG_GPIO_PXFUNC(p) = (1 << o); \
2.699 - REG_GPIO_PXSELS(p) = (1 << o); \
2.700 - REG_GPIO_PXDIRC(p) = (1 << o); \
2.701 - REG_GPIO_PXFLGC(p) = (1 << o); \
2.702 - REG_GPIO_PXIMC(p) = (1 << o); \
2.703 -} while (0)
2.704 -
2.705 -#define __gpio_mask_irq(n) \
2.706 -do { \
2.707 - unsigned int p, o; \
2.708 - p = (n) / 32; \
2.709 - o = (n) % 32; \
2.710 - REG_GPIO_PXIMS(p) = (1 << o); \
2.711 -} while (0)
2.712 -
2.713 -#define __gpio_unmask_irq(n) \
2.714 -do { \
2.715 - unsigned int p, o; \
2.716 - p = (n) / 32; \
2.717 - o = (n) % 32; \
2.718 - REG_GPIO_PXIMC(p) = (1 << o); \
2.719 -} while (0)
2.720 -
2.721 -#define __gpio_ack_irq(n) \
2.722 -do { \
2.723 - unsigned int p, o; \
2.724 - p = (n) / 32; \
2.725 - o = (n) % 32; \
2.726 - REG_GPIO_PXFLGC(p) = (1 << o); \
2.727 -} while (0)
2.728 -
2.729 -#define __gpio_get_irq() \
2.730 -({ \
2.731 - unsigned int p, i, tmp, v = 0; \
2.732 - for (p = 3; p >= 0; p--) { \
2.733 - tmp = REG_GPIO_PXFLG(p); \
2.734 - for (i = 0; i < 32; i++) \
2.735 - if (tmp & (1 << i)) \
2.736 - v = (32*p + i); \
2.737 - } \
2.738 - v; \
2.739 -})
2.740 -
2.741 -#define __gpio_group_irq(n) \
2.742 -({ \
2.743 - register int tmp, i; \
2.744 - tmp = REG_GPIO_PXFLG((n)); \
2.745 - for (i=31;i>=0;i--) \
2.746 - if (tmp & (1 << i)) \
2.747 - break; \
2.748 - i; \
2.749 -})
2.750 -
2.751 -#define __gpio_enable_pull(n) \
2.752 -do { \
2.753 - unsigned int p, o; \
2.754 - p = (n) / 32; \
2.755 - o = (n) % 32; \
2.756 - REG_GPIO_PXPEC(p) = (1 << o); \
2.757 -} while (0)
2.758 -
2.759 -#define __gpio_disable_pull(n) \
2.760 -do { \
2.761 - unsigned int p, o; \
2.762 - p = (n) / 32; \
2.763 - o = (n) % 32; \
2.764 - REG_GPIO_PXPES(p) = (1 << o); \
2.765 -} while (0)
2.766 -
2.767 +/* Register operations using absolute positioning have been removed. */
2.768
2.769 /***************************************************************************
2.770 * CPM
3.1 --- a/include/minipc.h Tue Jul 11 18:45:08 2017 +0200
3.2 +++ b/include/minipc.h Wed Jul 12 15:46:53 2017 +0200
3.3 @@ -22,13 +22,26 @@
3.4 #ifndef __MINIPC_H__
3.5 #define __MINIPC_H__
3.6
3.7 -/*
3.8 - * GPIO definition
3.9 - */
3.10 -#define GPIO_LED_EN 92
3.11 -#define GPIO_DISP_OFF_N 93
3.12 -#define GPIO_PWM0 94
3.13 -#define GPIO_POWER 97
3.14 +/* GPIO definitions. */
3.15 +
3.16 +#define GPIO_PORT_DMA 0
3.17 +
3.18 +#define GPIO_PORT_LCD 1
3.19 +#define GPIO_PORT_MSC 1
3.20 +
3.21 +#define GPIO_PORT_LED 2
3.22 +#define GPIO_PORT_PWM 2
3.23 +
3.24 +#define GPIO_LED_EN 28
3.25 +#define GPIO_DISP_OFF_N 29
3.26 +#define GPIO_PWM0 30
3.27 +
3.28 +#define GPIO_PORT_EMC 2
3.29 +
3.30 +#define GPIO_PORT_POWER 3
3.31 +#define GPIO_POWER 1
3.32 +
3.33 +/* Other details. */
3.34
3.35 #define GPIO_KEYIN_COUNT 8
3.36 #define GPIO_KEYOUT_COUNT 17
4.1 --- a/include/nanonote.h Tue Jul 11 18:45:08 2017 +0200
4.2 +++ b/include/nanonote.h Wed Jul 12 15:46:53 2017 +0200
4.3 @@ -26,33 +26,68 @@
4.4 * GPIO definition
4.5 * See: http://en.qi-hardware.com/wiki/Hardware_basics
4.6 */
4.7 -#define GPIO_LCD_CS (2 * 32 + 21)
4.8 -#define GPIO_AMP_EN (3 * 32 + 4)
4.9 +
4.10 +#define GPIO_PORT_AUDIO 1
4.11 +
4.12 +#define GPIO_AUDIO_EN 29 /* audio output enable */
4.13 +#define GPIO_COB_TEST 30 /* test point TP5 */
4.14 +
4.15 +/* LCD */
4.16 +
4.17 +#define GPIO_PORT_LCD 2
4.18
4.19 -#define GPIO_SDPW_EN (3 * 32 + 2)
4.20 -#define GPIO_SD_DETECT (3 * 32 + 0)
4.21 +#define GPIO_LCD_CS 21
4.22 +#define SPEN GPIO_LCD_CS /* serial command enable */
4.23 +#define SPDA 22 /* serial command data */
4.24 +#define SPCK 23 /* serial command clock */
4.25 +
4.26 +#define GPIO_SLCD8_MASK 0x003c00ff /* SLCD 8-bit pins */
4.27 +
4.28 +/* JTAG */
4.29 +
4.30 +#define GPIO_PORT_JTAG 2
4.31 +
4.32 +#define GPIO_JTAG_UART_EN 31 /* select UART on pad 147 */
4.33 +
4.34 +/* Sound/noise */
4.35 +
4.36 +#define GPIO_PORT_AMP 3
4.37 +#define GPIO_PORT_BUZZ 3
4.38
4.39 -#define GPIO_BUZZ_PWM (3 * 32 + 27)
4.40 -#define GPIO_USB_DETECT (3 * 32 + 28)
4.41 +#define GPIO_AMP_EN 4 /* speaker enable */
4.42 +#define GPIO_BUZZ_PWM 27 /* buzzer (PWM4) */
4.43 +
4.44 +/* USB */
4.45 +
4.46 +#define GPIO_PORT_USB 3
4.47 +
4.48 +#define GPIO_USB_DETECT 28
4.49 +
4.50 +/* Power */
4.51 +
4.52 +#define GPIO_PORT_POWER 3
4.53
4.54 -#define GPIO_AUDIO_POP (1 * 32 + 29)
4.55 -#define GPIO_COB_TEST (1 * 32 + 30)
4.56 +#define GPIO_POWER 29 /* power button */
4.57 +
4.58 +/* SD/MMC */
4.59 +
4.60 +#define GPIO_PORT_MSC 3
4.61 +#define GPIO_PORT_SD 3
4.62 +
4.63 +#define GPIO_SD_DETECT 0
4.64 +#define GPIO_SD_CD_N GPIO_SD_DETECT /* SD Card insert detect */
4.65 +#define GPIO_SDPW_EN 2
4.66 +#define GPIO_SD_VCC_EN_N GPIO_SDPW_EN /* SD Card Power Enable */
4.67 +#define GPIO_SD_CMD 8
4.68 +#define GPIO_MSC_MASK 0x00003f00
4.69 +
4.70 +/* Other details. */
4.71
4.72 #define GPIO_KEYIN_COUNT 8
4.73 #define GPIO_KEYOUT_COUNT 8
4.74
4.75 -#define GPIO_POWER (3 * 32 + 29)
4.76 -
4.77 -#define GPIO_SD_CD_N GPIO_SD_DETECT /* SD Card insert detect */
4.78 -#define GPIO_SD_VCC_EN_N GPIO_SDPW_EN /* SD Card Power Enable */
4.79 -
4.80 -#define GPIO_SD_CMD (3 * 32 + 8)
4.81 -
4.82 -#define SPEN GPIO_LCD_CS /* LCDCS :Serial command enable */
4.83 -#define SPDA (2 * 32 + 22) /* LCDSCL:Serial command clock input */
4.84 -#define SPCK (2 * 32 + 23) /* LCDSDA:Serial command data input */
4.85 -
4.86 -#define GPIO_IRQ IRQ_GPIO3
4.87 +#define GPIO_IRQ2 IRQ_GPIO2 /* IRQ for keyboard */
4.88 +#define GPIO_IRQ3 IRQ_GPIO3 /* IRQ for power button */
4.89
4.90 #define GPIO_REGION_SIZE 0x10000
4.91
5.1 --- a/stage1/Makefile Tue Jul 11 18:45:08 2017 +0200
5.2 +++ b/stage1/Makefile Wed Jul 12 15:46:53 2017 +0200
5.3 @@ -41,8 +41,8 @@
5.4
5.5 # Ordering of objects is important and cannot be left to replacement rules.
5.6
5.7 -SRC = head1.S stage1.c board.c cpm.c
5.8 -OBJ = head1.o stage1.o board.o cpm.o
5.9 +SRC = head1.S stage1.c board.c cpm.c gpio.c
5.10 +OBJ = head1.o stage1.o board.o cpm.o gpio.o
5.11
5.12 .PHONY: all clean distclean
5.13
6.1 --- a/stage1/board.c Tue Jul 11 18:45:08 2017 +0200
6.2 +++ b/stage1/board.c Wed Jul 12 15:46:53 2017 +0200
6.3 @@ -31,6 +31,7 @@
6.4 #include "memory.h"
6.5 #include "sdram.h"
6.6 #include "cpm.h"
6.7 +#include "gpio.h"
6.8 #include "usb_boot_defines.h"
6.9
6.10 /* These arguments are initialised by usbboot and are defined in...
6.11 @@ -66,21 +67,70 @@
6.12
6.13 void gpio_init()
6.14 {
6.15 + void *gpio_port_base;
6.16 +
6.17 #ifdef CONFIG_CPU_JZ4730
6.18 /*
6.19 * Initialize SDRAM pins
6.20 */
6.21 - __gpio_as_emc();
6.22 +
6.23 + /* gpio_as_emc */
6.24 +
6.25 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_EMC);
6.26 +
6.27 + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xC0000000, 0x40000000);
6.28 + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPAUR, 0x0000FFFF, 0x00005555);
6.29 #else
6.30 /*
6.31 - * Initialize NAND Flash Pins
6.32 - */
6.33 - __gpio_as_nand();
6.34 + Initialize NAND Flash Pins (gpio_as_nand)
6.35 + CS1#, CLE, ALE, FRE#, FWE#, FRB#, RDWE#/BUFD#
6.36 + */
6.37 +
6.38 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, 1);
6.39 +
6.40 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, 0x02018000);
6.41 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x02018000);
6.42 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, 0x02018000);
6.43 +
6.44 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, 2);
6.45 +
6.46 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, 0x30000000);
6.47 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x30000000);
6.48 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, 0x30000000);
6.49 +
6.50 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNC, 0x40000000);
6.51 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x40000000);
6.52 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXDIRC, 0x40000000);
6.53 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, 0x40000000);
6.54 +
6.55 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, 1);
6.56 +
6.57 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, 0x00400000);
6.58 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x00400000);
6.59
6.60 /*
6.61 - * Initialize SDRAM pins
6.62 - */
6.63 - __gpio_as_sdram_16bit_4720();
6.64 + Initialize SDRAM pins (gpio_as_sdram_16bit_4720)
6.65 + D0 ~ D15, A0 ~ A16, DCS#, RAS#, CAS#, CKE#,
6.66 + RDWE#, CKO#, WE0#, WE1#
6.67 + */
6.68 +
6.69 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, 0);
6.70 +
6.71 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, 0x5442bfaa);
6.72 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x5442bfaa);
6.73 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, 0x5442bfaa);
6.74 +
6.75 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, 1);
6.76 +
6.77 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, 0x81f9ffff);
6.78 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x81f9ffff);
6.79 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, 0x81f9ffff);
6.80 +
6.81 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, 2);
6.82 +
6.83 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, 0x01000000);
6.84 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x01000000);
6.85 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, 0x01000000);
6.86 #endif
6.87 }
6.88
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/stage1/gpio.c Wed Jul 12 15:46:53 2017 +0200
7.3 @@ -0,0 +1,1 @@
7.4 +../stage2/gpio.c
7.5 \ No newline at end of file
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/stage1/gpio.h Wed Jul 12 15:46:53 2017 +0200
8.3 @@ -0,0 +1,1 @@
8.4 +../stage2/gpio.h
8.5 \ No newline at end of file
9.1 --- a/stage2/Makefile Tue Jul 11 18:45:08 2017 +0200
9.2 +++ b/stage2/Makefile Wed Jul 12 15:46:53 2017 +0200
9.3 @@ -60,7 +60,7 @@
9.4
9.5 # Configure generic objects.
9.6
9.7 -CORE_SRC = stage2.c cpm.c cpu.c lcd.c jzlcd.c board.c irq.c paging.c tasks.c task_gpio.c
9.8 +CORE_SRC = stage2.c cpm.c cpu.c gpio.c lcd.c jzlcd.c board.c irq.c paging.c tasks.c task_gpio.c
9.9 CORE_OBJ = $(CORE_SRC:.c=.o)
9.10
9.11 # Add tasks.
10.1 --- a/stage2/board-minipc.c Tue Jul 11 18:45:08 2017 +0200
10.2 +++ b/stage2/board-minipc.c Wed Jul 12 15:46:53 2017 +0200
10.3 @@ -22,41 +22,52 @@
10.4
10.5 #include "board.h"
10.6 #include "minipc.h"
10.7 +#include "gpio.h"
10.8
10.9 /* Later initialisation functions. */
10.10
10.11 void gpio_init2()
10.12 {
10.13 + void *gpio_port_base;
10.14 +
10.15 /* LED enable. */
10.16
10.17 - __gpio_as_output(GPIO_LED_EN);
10.18 - __gpio_set_pin(GPIO_LED_EN);
10.19 + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_LED);
10.20 + jz4740_gpio_as_output(gpio_port_base, GPIO_LED_EN);
10.21 + jz4740_gpio_set_pin(gpio_port_base, GPIO_LED_EN);
10.22
10.23 __harb_usb0_uhc();
10.24 - __gpio_as_emc();
10.25 - __gpio_as_dma();
10.26 +
10.27 + /* gpio_as_emc */
10.28 +
10.29 + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_EMC);
10.30 +
10.31 + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xC0000000, 0x40000000);
10.32 + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPAUR, 0x0000FFFF, 0x00005555);
10.33 +
10.34 + /* gpio_as_dma */
10.35 +
10.36 + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_DMA);
10.37 +
10.38 + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xFF000000, 0x55000000);
10.39 + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPAUR, 0x00F00000, 0x00500000);
10.40
10.41 /* Initialise LCD pins. */
10.42
10.43 - __gpio_as_lcd_master();
10.44 + /* gpio_as_lcd_master */
10.45 +
10.46 + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_LCD);
10.47 +
10.48 + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xFFFF0000, 0x55550000);
10.49 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_GPAUR, 0x556A5555);
10.50
10.51 /* Initialise MSC pins. */
10.52
10.53 - __gpio_as_msc();
10.54 -
10.55 - /* Initialise other pins. */
10.56 -
10.57 - unsigned short i;
10.58 + /* gpio_as_msc */
10.59
10.60 - for (i = 0; i < GPIO_KEYIN_COUNT; i++) {
10.61 - __gpio_as_input(GPIO_KEYIN_BASE + i);
10.62 - __gpio_enable_pull(GPIO_KEYIN_BASE + i);
10.63 - }
10.64 + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_MSC);
10.65
10.66 - for (i = 0; i < GPIO_KEYOUT_COUNT; i++) {
10.67 - __gpio_as_output(GPIO_KEYOUT_BASE + i);
10.68 - __gpio_clear_pin(GPIO_KEYOUT_BASE + i);
10.69 - }
10.70 + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0x0000FFF0, 0x00005550);
10.71 }
10.72
10.73 void rtc_init()
10.74 @@ -107,13 +118,15 @@
10.75
10.76 void gpio_init_irq()
10.77 {
10.78 - __gpio_as_irq_low_level(GPIO_POWER);
10.79 + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_POWER);
10.80 + jz4740_gpio_as_irq(gpio_port_base, GPIO_POWER, gpio_irq_low_level);
10.81 __intc_unmask_irq(GPIO_IRQ);
10.82 }
10.83
10.84 int gpio_have_irq(uint8_t gpio)
10.85 {
10.86 - return (REG_GPIO_GPFR(gpio / 32) & (1 << (gpio % 32)));
10.87 + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, gpio / 32);
10.88 + return jz4740_gpio_have_irq(gpio_port_base, gpio % 32);
10.89 }
10.90
10.91 /* Board startup detection. */
11.1 --- a/stage2/board-nanonote.c Tue Jul 11 18:45:08 2017 +0200
11.2 +++ b/stage2/board-nanonote.c Wed Jul 12 15:46:53 2017 +0200
11.3 @@ -23,50 +23,82 @@
11.4 #include "board.h"
11.5 #include "nanonote.h"
11.6 #include "cpm.h"
11.7 +#include "gpio.h"
11.8
11.9 /* Later initialisation functions. */
11.10
11.11 void gpio_init2()
11.12 {
11.13 - /* Initialise LCD pins. */
11.14 + void *gpio_port_base;
11.15
11.16 - __gpio_as_slcd_8bit();
11.17 + /*
11.18 + Initialise LCD pins.
11.19 + gpio_as_slcd_8bit: LCD_D0~LCD_D7, SLCD_CLK, SLCD_RS, SLCD_CS, LCD_DE
11.20 + */
11.21
11.22 - /* Initialise MSC pins. */
11.23 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LCD);
11.24 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, GPIO_SLCD8_MASK);
11.25 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, GPIO_SLCD8_MASK);
11.26
11.27 - __gpio_as_msc();
11.28 + /*
11.29 + Initialise MSC pins.
11.30 + gpio_as_msc: MSC_CMD, MSC_CLK, MSC_D0 ~ MSC_D3
11.31 + */
11.32 +
11.33 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_MSC);
11.34 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, GPIO_MSC_MASK);
11.35 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, GPIO_MSC_MASK);
11.36 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, GPIO_MSC_MASK);
11.37
11.38 /* Initialise other pins. */
11.39
11.40 - /* Enable TP4, TP5 as UART0. */
11.41 + /* Enable TP4, TP5 as UART0 (gpio_jtag_to_uart0). */
11.42
11.43 - __gpio_jtag_to_uart0();
11.44 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_JTAG);
11.45 + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELS, 1 << GPIO_JTAG_UART_EN);
11.46 +
11.47 + /* Enable pull-up on the power switch. */
11.48
11.49 - __gpio_as_input(GPIO_POWER);
11.50 - __gpio_enable_pull(GPIO_POWER);
11.51 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_POWER);
11.52 + jz4740_gpio_as_input(gpio_port_base, GPIO_POWER);
11.53 + jz4740_gpio_enable_pull(gpio_port_base, GPIO_POWER);
11.54 +
11.55 + /* Enable audio output. */
11.56
11.57 - __gpio_as_output(GPIO_AUDIO_POP);
11.58 - __gpio_set_pin(GPIO_AUDIO_POP);
11.59 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_AUDIO);
11.60 + jz4740_gpio_as_output(gpio_port_base, GPIO_AUDIO_EN);
11.61 + jz4740_gpio_set_pin(gpio_port_base, GPIO_AUDIO_EN);
11.62
11.63 - __gpio_as_output(GPIO_LCD_CS);
11.64 - __gpio_clear_pin(GPIO_LCD_CS);
11.65 + /* Enable LCD signalling. */
11.66
11.67 - __gpio_as_output(GPIO_AMP_EN);
11.68 - __gpio_clear_pin(GPIO_AMP_EN);
11.69 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LCD);
11.70 + jz4740_gpio_as_output(gpio_port_base, GPIO_LCD_CS);
11.71 + jz4740_gpio_clear_pin(gpio_port_base, GPIO_LCD_CS);
11.72 +
11.73 + /* Enable speaker. */
11.74 +
11.75 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_AMP);
11.76 + jz4740_gpio_as_output(gpio_port_base, GPIO_AMP_EN);
11.77 + jz4740_gpio_clear_pin(gpio_port_base, GPIO_AMP_EN);
11.78 +
11.79 + /* Disable pull-up on SD pins. */
11.80
11.81 - __gpio_as_output(GPIO_SDPW_EN);
11.82 - __gpio_disable_pull(GPIO_SDPW_EN);
11.83 - __gpio_clear_pin(GPIO_SDPW_EN);
11.84 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_SD);
11.85 + jz4740_gpio_as_output(gpio_port_base, GPIO_SDPW_EN);
11.86 + jz4740_gpio_disable_pull(gpio_port_base, GPIO_SDPW_EN);
11.87 + jz4740_gpio_clear_pin(gpio_port_base, GPIO_SDPW_EN);
11.88 + jz4740_gpio_as_input(gpio_port_base, GPIO_SD_DETECT);
11.89 + jz4740_gpio_disable_pull(gpio_port_base, GPIO_SD_DETECT);
11.90
11.91 - __gpio_as_input(GPIO_SD_DETECT);
11.92 - __gpio_disable_pull(GPIO_SD_DETECT);
11.93 + /* Enable pull-up on USB detect pin. */
11.94
11.95 - __gpio_as_input(GPIO_USB_DETECT);
11.96 - __gpio_enable_pull(GPIO_USB_DETECT);
11.97 + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_USB);
11.98 + jz4740_gpio_as_input(gpio_port_base, GPIO_USB_DETECT);
11.99 + jz4740_gpio_enable_pull(gpio_port_base, GPIO_USB_DETECT);
11.100
11.101 /* Employ a PWM channel for the buzzer. */
11.102
11.103 - __gpio_as_pwm4();
11.104 + jz4740_gpio_as_pwm((void *) GPIO_BASE, 4);
11.105 }
11.106
11.107 void rtc_init()
11.108 @@ -132,13 +164,15 @@
11.109
11.110 void gpio_init_irq()
11.111 {
11.112 - __gpio_as_irq_low_level(GPIO_POWER);
11.113 - __intc_unmask_irq(GPIO_IRQ);
11.114 + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_POWER);
11.115 + jz4740_gpio_as_irq(gpio_port_base, GPIO_POWER, gpio_irq_level_low);
11.116 + __intc_unmask_irq(GPIO_IRQ3);
11.117 }
11.118
11.119 int gpio_have_irq(uint8_t gpio)
11.120 {
11.121 - return (REG_GPIO_PXFLG(gpio / 32) & (1 << (gpio % 32)));
11.122 + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, gpio / 32);
11.123 + return jz4740_gpio_have_irq(gpio_port_base, gpio % 32);
11.124 }
11.125
11.126 /* Board startup detection. */
12.1 --- a/stage2/board.c Tue Jul 11 18:45:08 2017 +0200
12.2 +++ b/stage2/board.c Wed Jul 12 15:46:53 2017 +0200
12.3 @@ -21,6 +21,7 @@
12.4
12.5 #include "sdram.h"
12.6 #include "board.h"
12.7 +#include "gpio.h"
12.8
12.9 unsigned long get_memory_size()
12.10 {
12.11 @@ -161,10 +162,13 @@
12.12
12.13 void gpio_clear(uint8_t gpio)
12.14 {
12.15 + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, gpio / 32);
12.16 +
12.17 /* Clear interrupt status. */
12.18
12.19 - __gpio_ack_irq(gpio);
12.20 - __intc_ack_irq(GPIO_IRQ);
12.21 + jz4740_gpio_ack_irq(gpio_port_base, gpio % 32);
12.22 + __intc_ack_irq(GPIO_IRQ2);
12.23 + __intc_ack_irq(GPIO_IRQ3);
12.24 }
12.25
12.26 /* Miscellaneous interrupt administration. */
13.1 --- a/stage2/lcd.c Tue Jul 11 18:45:08 2017 +0200
13.2 +++ b/stage2/lcd.c Wed Jul 12 15:46:53 2017 +0200
13.3 @@ -28,7 +28,7 @@
13.4 #include "board.h"
13.5
13.6 extern vidinfo_t panel_info;
13.7 -static uint32_t lcd_base;
13.8 +static uint32_t lcd_base; /* the screen memory, not the LCD registers */
13.9
13.10
13.11
13.12 @@ -273,16 +273,6 @@
13.13 udelay(1000);
13.14 }
13.15
13.16 -static void lcd_display_pin_init()
13.17 -{
13.18 - __lcd_display_pin_init();
13.19 -}
13.20 -
13.21 -static void lcd_display_on()
13.22 -{
13.23 - __lcd_display_on();
13.24 -}
13.25 -
13.26 static void lcd_set_bpp(uint8_t bpp)
13.27 {
13.28 jz4740_lcd_set_bpp(bpp, &panel_info);
14.1 --- a/stage2/minipc_claa070vc01.c Tue Jul 11 18:45:08 2017 +0200
14.2 +++ b/stage2/minipc_claa070vc01.c Wed Jul 12 15:46:53 2017 +0200
14.3 @@ -1,5 +1,5 @@
14.4 /*
14.5 - * MiniPC screen details
14.6 + * MiniPC screen details and panel-specific functions.
14.7 *
14.8 * Copyright (C) 2005-2007, Ingenic Semiconductor Inc.
14.9 * Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
14.10 @@ -20,9 +20,10 @@
14.11 * Boston, MA 02110-1301, USA
14.12 */
14.13
14.14 -#include "minipc_claa070vc01.h"
14.15 +#include "board.h"
14.16 #include "jzlcd.h"
14.17 #include "minipc.h"
14.18 +#include "gpio.h"
14.19
14.20 struct jzfb_info jzfb = {
14.21 MODE_TFT_GEN | PCLK_N | HSYNC_N | VSYNC_N,
14.22 @@ -33,3 +34,39 @@
14.23 .jz_fb=&jzfb, // this will need correcting for user mode usage
14.24 .lcd=0, // base address for registers
14.25 };
14.26 +
14.27 +void lcd_set_backlight_level(uint16_t n)
14.28 +{
14.29 + jz4740_gpio_as_pwm((void *) GPIO_BASE, 0);
14.30 + REG_PWM_DUT(0) = n;
14.31 + REG_PWM_PER(0) = 7;
14.32 + REG_PWM_CTR(0) = 0xc1;
14.33 +}
14.34 +
14.35 +void lcd_close_backlight()
14.36 +{
14.37 + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_PWM);
14.38 + jz4740_gpio_as_output(gpio_port_base, GPIO_PWM0);
14.39 + jz4740_gpio_clear_pin(gpio_port_base, GPIO_PWM0);
14.40 +}
14.41 +
14.42 +void lcd_display_pin_init()
14.43 +{
14.44 + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LED);
14.45 + jz4740_gpio_as_output(gpio_port_base, GPIO_DISP_OFF_N);
14.46 + lcd_set_backlight_level(8);
14.47 +}
14.48 +
14.49 +void lcd_display_on()
14.50 +{
14.51 + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LED);
14.52 + jz4740_gpio_set_pin(gpio_port_base, GPIO_DISP_OFF_N);
14.53 + lcd_set_backlight_level(8);
14.54 +}
14.55 +
14.56 +void lcd_display_off()
14.57 +{
14.58 + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LED);
14.59 + lcd_close_backlight();
14.60 + jz4740_gpio_clear_pin(gpio_port_base, GPIO_DISP_OFF_N);
14.61 +}
15.1 --- a/stage2/minipc_claa070vc01.h Tue Jul 11 18:45:08 2017 +0200
15.2 +++ b/stage2/minipc_claa070vc01.h Wed Jul 12 15:46:53 2017 +0200
15.3 @@ -2,7 +2,7 @@
15.4 * MiniPC panel-specific definitions
15.5 *
15.6 * Copyright (C) Xiangfu Liu <xiangfu@sharism.cc>
15.7 - * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
15.8 + * Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
15.9 *
15.10 * This program is free software; you can redistribute it and/or
15.11 * modify it under the terms of the GNU General Public License as
15.12 @@ -23,39 +23,12 @@
15.13 #ifndef __MINIPC_CLAA070VC01_H__
15.14 #define __MINIPC_CLAA070VC01_H__
15.15
15.16 -#include "board.h"
15.17 -#include "minipc.h"
15.18 -
15.19 -static inline void __lcd_set_backlight_level(u16 n)
15.20 -{
15.21 - __gpio_as_pwm();
15.22 - REG_PWM_DUT(0) = n;
15.23 - REG_PWM_PER(0) = 7;
15.24 - REG_PWM_CTR(0) = 0xc1;
15.25 -}
15.26 -
15.27 -static inline void __lcd_close_backlight()
15.28 -{
15.29 - __gpio_as_output(GPIO_PWM0);
15.30 - __gpio_clear_pin(GPIO_PWM0);
15.31 -}
15.32 +#include <stdint.h>
15.33
15.34 -static inline void __lcd_display_pin_init()
15.35 -{
15.36 - __gpio_as_output(GPIO_DISP_OFF_N);
15.37 - __lcd_set_backlight_level(8);
15.38 -}
15.39 -
15.40 -static inline void __lcd_display_on()
15.41 -{
15.42 - __gpio_set_pin(GPIO_DISP_OFF_N);
15.43 - __lcd_set_backlight_level(8);
15.44 -}
15.45 -
15.46 -static inline void __lcd_display_off()
15.47 -{
15.48 - __lcd_close_backlight();
15.49 - __gpio_clear_pin(GPIO_DISP_OFF_N);
15.50 -}
15.51 +void lcd_set_backlight_level(uint16_t n);
15.52 +void lcd_close_backlight();
15.53 +void lcd_display_pin_init();
15.54 +void lcd_display_on();
15.55 +void lcd_display_off();
15.56
15.57 #endif /* __MINIPC_CLAA070VC01_H__ */
16.1 --- a/stage2/nanonote_gpm940b0.c Tue Jul 11 18:45:08 2017 +0200
16.2 +++ b/stage2/nanonote_gpm940b0.c Wed Jul 12 15:46:53 2017 +0200
16.3 @@ -1,5 +1,5 @@
16.4 /*
16.5 - * Ben NanoNote screen details
16.6 + * Ben NanoNote screen details and panel-specific functions.
16.7 *
16.8 * Copyright (C) Xiangfu Liu <xiangfu@sharism.cc>
16.9 * Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
16.10 @@ -20,9 +20,10 @@
16.11 * Boston, MA 02110-1301, USA
16.12 */
16.13
16.14 -#include "nanonote_gpm940b0.h"
16.15 +#include "board.h"
16.16 #include "jzlcd.h"
16.17 #include "nanonote.h"
16.18 +#include "gpio.h"
16.19
16.20 struct jzfb_info jzfb = {
16.21 .cfg=MODE_8BIT_SERIAL_TFT | PCLK_N | HSYNC_N | VSYNC_N,
16.22 @@ -38,3 +39,52 @@
16.23 .jz_fb=&jzfb, // this will need correcting for user mode usage
16.24 .lcd=0, // base address for registers
16.25 };
16.26 +
16.27 +/* Display configuration functions. */
16.28 +
16.29 +static void spi_write_reg1(uint8_t reg, uint8_t val)
16.30 +{
16.31 + uint8_t no;
16.32 + uint16_t value;
16.33 + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LCD);
16.34 +
16.35 + jz4740_gpio_set_pin(gpio_port_base, SPEN);
16.36 + jz4740_gpio_set_pin(gpio_port_base, SPCK);
16.37 + jz4740_gpio_clear_pin(gpio_port_base, SPDA);
16.38 + jz4740_gpio_clear_pin(gpio_port_base, SPEN);
16.39 +
16.40 + value = ((reg << 8) | (val & 0xFF));
16.41 +
16.42 + for (no = 0; no < 16; no++)
16.43 + {
16.44 + jz4740_gpio_clear_pin(gpio_port_base, SPCK);
16.45 + jz4740_gpio_set_value(gpio_port_base, SPDA, value & 0x8000 ? 1 : 0);
16.46 + jz4740_gpio_set_pin(gpio_port_base, SPCK);
16.47 + value = (value << 1);
16.48 + }
16.49 +
16.50 + jz4740_gpio_set_pin(gpio_port_base, SPEN);
16.51 +}
16.52 +
16.53 +void lcd_display_pin_init()
16.54 +{
16.55 + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LCD);
16.56 +
16.57 + jz4740_gpio_as_output(gpio_port_base, SPEN);
16.58 + jz4740_gpio_as_output(gpio_port_base, SPCK);
16.59 + jz4740_gpio_as_output(gpio_port_base, SPDA);
16.60 +}
16.61 +
16.62 +void lcd_display_on()
16.63 +{
16.64 + spi_write_reg1(0x05, 0x1e);
16.65 + spi_write_reg1(0x05, 0x5e);
16.66 + spi_write_reg1(0x07, 0x8d);
16.67 + spi_write_reg1(0x13, 0x01);
16.68 + spi_write_reg1(0x05, 0x5f);
16.69 +}
16.70 +
16.71 +void lcd_display_off()
16.72 +{
16.73 + spi_write_reg1(0x05, 0x5e);
16.74 +}
17.1 --- a/stage2/nanonote_gpm940b0.h Tue Jul 11 18:45:08 2017 +0200
17.2 +++ b/stage2/nanonote_gpm940b0.h Wed Jul 12 15:46:53 2017 +0200
17.3 @@ -1,5 +1,5 @@
17.4 /*
17.5 - * Ben NanoNote panel-specific definitions
17.6 + * Ben NanoNote panel-specific definitions.
17.7 *
17.8 * Copyright (C) Xiangfu Liu <xiangfu@sharism.cc>
17.9 * Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
17.10 @@ -23,55 +23,8 @@
17.11 #ifndef __NANONOTE_GPM940B0_H__
17.12 #define __NANONOTE_GPM940B0_H__
17.13
17.14 -#include "board.h"
17.15 -#include "nanonote.h"
17.16 -
17.17 -static inline void __spi_write_reg1(uint8_t reg, uint8_t val)
17.18 -{
17.19 - uint8_t no, a=reg, b=val;
17.20 - uint16_t value;
17.21 -
17.22 - __gpio_set_pin(SPEN);
17.23 - __gpio_set_pin(SPCK);
17.24 - __gpio_clear_pin(SPDA);
17.25 - __gpio_clear_pin(SPEN);
17.26 -
17.27 - value = ((a << 8) | (b & 0xFF));
17.28 -
17.29 - for (no=0; no<16; no++)
17.30 - {
17.31 - __gpio_clear_pin(SPCK);
17.32 -
17.33 - if ((value & 0x8000) == 0x8000)
17.34 - __gpio_set_pin(SPDA);
17.35 - else
17.36 - __gpio_clear_pin(SPDA);
17.37 -
17.38 - __gpio_set_pin(SPCK);
17.39 - value = (value << 1);
17.40 - }
17.41 - __gpio_set_pin(SPEN);
17.42 -}
17.43 -
17.44 -static inline void __lcd_display_pin_init()
17.45 -{
17.46 - __gpio_as_output(SPEN);
17.47 - __gpio_as_output(SPCK);
17.48 - __gpio_as_output(SPDA);
17.49 -}
17.50 -
17.51 -static inline void __lcd_display_on()
17.52 -{
17.53 - __spi_write_reg1(0x05, 0x1e);
17.54 - __spi_write_reg1(0x05, 0x5e);
17.55 - __spi_write_reg1(0x07, 0x8d);
17.56 - __spi_write_reg1(0x13, 0x01);
17.57 - __spi_write_reg1(0x05, 0x5f);
17.58 -}
17.59 -
17.60 -static inline void __lcd_display_off()
17.61 -{
17.62 - __spi_write_reg1(0x05, 0x5e);
17.63 -}
17.64 +void lcd_display_pin_init();
17.65 +void lcd_display_on();
17.66 +void lcd_display_off();
17.67
17.68 #endif /* __NANONOTE_GPM940B0_H__ */
18.1 --- a/stage2/task_gpio.c Tue Jul 11 18:45:08 2017 +0200
18.2 +++ b/stage2/task_gpio.c Wed Jul 12 15:46:53 2017 +0200
18.3 @@ -23,6 +23,7 @@
18.4 #include "paging.h"
18.5 #include "memory.h"
18.6 #include "task_gpio.h"
18.7 +#include "gpio.h"
18.8
18.9 void task_gpio_init(uint8_t task)
18.10 {
18.11 @@ -41,49 +42,54 @@
18.12
18.13 void task_gpio_as_input(uint8_t pin)
18.14 {
18.15 - TASK_REG_GPIO_PXFUNC(pin / 32) = (1 << (pin % 32));
18.16 - TASK_REG_GPIO_PXSELC(pin / 32) = (1 << (pin % 32));
18.17 - TASK_REG_GPIO_PXDIRC(pin / 32) = (1 << (pin % 32));
18.18 + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32);
18.19 + jz4740_gpio_as_input(gpio_port_base, pin % 32);
18.20 }
18.21
18.22 void task_gpio_as_output(uint8_t pin)
18.23 {
18.24 - TASK_REG_GPIO_PXFUNC(pin / 32) = (1 << (pin % 32));
18.25 - TASK_REG_GPIO_PXSELC(pin / 32) = (1 << (pin % 32));
18.26 - TASK_REG_GPIO_PXDIRS(pin / 32) = (1 << (pin % 32));
18.27 + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32);
18.28 + jz4740_gpio_as_output(gpio_port_base, pin % 32);
18.29 }
18.30
18.31 void task_gpio_enable_pull(uint8_t pin)
18.32 {
18.33 - TASK_REG_GPIO_PXPEC(pin / 32) = (1 << (pin % 32));
18.34 + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32);
18.35 + jz4740_gpio_enable_pull(gpio_port_base, pin % 32);
18.36 }
18.37
18.38 void task_gpio_disable_pull(uint8_t pin)
18.39 {
18.40 - TASK_REG_GPIO_PXPES(pin / 32) = (1 << (pin % 32));
18.41 + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32);
18.42 + jz4740_gpio_disable_pull(gpio_port_base, pin % 32);
18.43 }
18.44
18.45 -inline int task_gpio_get_pin(uint8_t pin)
18.46 +int task_gpio_get_pin(uint8_t pin)
18.47 {
18.48 - return TASK_REG_GPIO_PXPIN(pin / 32) & (1 << (pin % 32));
18.49 + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32);
18.50 + return jz4740_gpio_get_pin(gpio_port_base, pin % 32);
18.51 }
18.52
18.53 -inline void task_gpio_set_pin(uint8_t pin)
18.54 +void task_gpio_set_pin(uint8_t pin)
18.55 {
18.56 - TASK_REG_GPIO_PXDATS(pin / 32) = (1 << (pin % 32));
18.57 + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32);
18.58 + jz4740_gpio_set_pin(gpio_port_base, pin % 32);
18.59 }
18.60
18.61 -inline void task_gpio_clear_pin(uint8_t pin)
18.62 +void task_gpio_clear_pin(uint8_t pin)
18.63 {
18.64 - TASK_REG_GPIO_PXDATC(pin / 32) = (1 << (pin % 32));
18.65 + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32);
18.66 + jz4740_gpio_clear_pin(gpio_port_base, pin % 32);
18.67 }
18.68
18.69 -inline void task_gpio_mask_irq(uint8_t pin)
18.70 +void task_gpio_mask_irq(uint8_t pin)
18.71 {
18.72 - TASK_REG_GPIO_PXIMS(pin / 32) = (1 << (pin % 32));
18.73 + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32);
18.74 + jz4740_gpio_mask_irq(gpio_port_base, pin % 32);
18.75 }
18.76
18.77 -inline void task_gpio_unmask_irq(uint8_t pin)
18.78 +void task_gpio_unmask_irq(uint8_t pin)
18.79 {
18.80 - TASK_REG_GPIO_PXIMC(pin / 32) = (1 << (pin % 32));
18.81 + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32);
18.82 + jz4740_gpio_unmask_irq(gpio_port_base, pin % 32);
18.83 }
19.1 --- a/stage2/task_gpio.h Tue Jul 11 18:45:08 2017 +0200
19.2 +++ b/stage2/task_gpio.h Wed Jul 12 15:46:53 2017 +0200
19.3 @@ -8,58 +8,6 @@
19.4
19.5 #define GPIO_BASE_PHYSICAL (GPIO_BASE - KSEG1_BASE)
19.6
19.7 -#define TASK_GPIO_PXPIN(n) (TASK_GPIO_BASE + (0x00 + (n)*0x100)) /* PIN Level Register */
19.8 -
19.9 -#define TASK_GPIO_PXDAT(n) (TASK_GPIO_BASE + (0x10 + (n)*0x100)) /* Port Data Register */
19.10 -#define TASK_GPIO_PXDATS(n) (TASK_GPIO_BASE + (0x14 + (n)*0x100)) /* Port Data Set Register */
19.11 -#define TASK_GPIO_PXDATC(n) (TASK_GPIO_BASE + (0x18 + (n)*0x100)) /* Port Data Clear Register */
19.12 -
19.13 -#define TASK_GPIO_PXIM(n) (TASK_GPIO_BASE + (0x20 + (n)*0x100)) /* Interrupt Mask Register */
19.14 -#define TASK_GPIO_PXIMS(n) (TASK_GPIO_BASE + (0x24 + (n)*0x100)) /* Interrupt Mask Set Reg */
19.15 -#define TASK_GPIO_PXIMC(n) (TASK_GPIO_BASE + (0x28 + (n)*0x100)) /* Interrupt Mask Clear Reg */
19.16 -
19.17 -#define TASK_GPIO_PXPE(n) (TASK_GPIO_BASE + (0x30 + (n)*0x100)) /* Pull Enable Register */
19.18 -#define TASK_GPIO_PXPES(n) (TASK_GPIO_BASE + (0x34 + (n)*0x100)) /* Pull Enable Set Reg. */
19.19 -#define TASK_GPIO_PXPEC(n) (TASK_GPIO_BASE + (0x38 + (n)*0x100)) /* Pull Enable Clear Reg. */
19.20 -
19.21 -#define TASK_GPIO_PXFUN(n) (TASK_GPIO_BASE + (0x40 + (n)*0x100)) /* Function Register */
19.22 -#define TASK_GPIO_PXFUNS(n) (TASK_GPIO_BASE + (0x44 + (n)*0x100)) /* Function Set Register */
19.23 -#define TASK_GPIO_PXFUNC(n) (TASK_GPIO_BASE + (0x48 + (n)*0x100)) /* Function Clear Register */
19.24 -
19.25 -#define TASK_GPIO_PXSEL(n) (TASK_GPIO_BASE + (0x50 + (n)*0x100)) /* Select Register */
19.26 -#define TASK_GPIO_PXSELS(n) (TASK_GPIO_BASE + (0x54 + (n)*0x100)) /* Select Set Register */
19.27 -#define TASK_GPIO_PXSELC(n) (TASK_GPIO_BASE + (0x58 + (n)*0x100)) /* Select Clear Register */
19.28 -
19.29 -#define TASK_GPIO_PXDIR(n) (TASK_GPIO_BASE + (0x60 + (n)*0x100)) /* Direction Register */
19.30 -#define TASK_GPIO_PXDIRS(n) (TASK_GPIO_BASE + (0x64 + (n)*0x100)) /* Direction Set Register */
19.31 -#define TASK_GPIO_PXDIRC(n) (TASK_GPIO_BASE + (0x68 + (n)*0x100)) /* Direction Clear Register */
19.32 -
19.33 -#define TASK_REG_GPIO_PXPIN(n) REG32(TASK_GPIO_PXPIN((n)))
19.34 -
19.35 -#define TASK_REG_GPIO_PXDAT(n) REG32(TASK_GPIO_PXDAT((n)))
19.36 -#define TASK_REG_GPIO_PXDATS(n) REG32(TASK_GPIO_PXDATS((n)))
19.37 -#define TASK_REG_GPIO_PXDATC(n) REG32(TASK_GPIO_PXDATC((n)))
19.38 -
19.39 -#define TASK_REG_GPIO_PXIM(n) REG32(TASK_GPIO_PXIM((n)))
19.40 -#define TASK_REG_GPIO_PXIMS(n) REG32(TASK_GPIO_PXIMS((n)))
19.41 -#define TASK_REG_GPIO_PXIMC(n) REG32(TASK_GPIO_PXIMC((n)))
19.42 -
19.43 -#define TASK_REG_GPIO_PXPE(n) REG32(TASK_GPIO_PXPE((n)))
19.44 -#define TASK_REG_GPIO_PXPES(n) REG32(TASK_GPIO_PXPES((n)))
19.45 -#define TASK_REG_GPIO_PXPEC(n) REG32(TASK_GPIO_PXPEC((n)))
19.46 -
19.47 -#define TASK_REG_GPIO_PXFUN(n) REG32(TASK_GPIO_PXFUN((n)))
19.48 -#define TASK_REG_GPIO_PXFUNS(n) REG32(TASK_GPIO_PXFUNS((n)))
19.49 -#define TASK_REG_GPIO_PXFUNC(n) REG32(TASK_GPIO_PXFUNC((n)))
19.50 -
19.51 -#define TASK_REG_GPIO_PXSEL(n) REG32(TASK_GPIO_PXSEL((n)))
19.52 -#define TASK_REG_GPIO_PXSELS(n) REG32(TASK_GPIO_PXSELS((n)))
19.53 -#define TASK_REG_GPIO_PXSELC(n) REG32(TASK_GPIO_PXSELC((n)))
19.54 -
19.55 -#define TASK_REG_GPIO_PXDIR(n) REG32(TASK_GPIO_PXDIR((n)))
19.56 -#define TASK_REG_GPIO_PXDIRS(n) REG32(TASK_GPIO_PXDIRS((n)))
19.57 -#define TASK_REG_GPIO_PXDIRC(n) REG32(TASK_GPIO_PXDIRC((n)))
19.58 -
19.59 void task_gpio_init(uint8_t task);
19.60 void task_gpio_as_input(uint8_t pin);
19.61 void task_gpio_as_output(uint8_t pin);