# HG changeset patch # User Paul Boddie # Date 1499867213 -7200 # Node ID 825b572484c67db8b7bdb86f285e818c9a8a4278 # Parent 1571da98c6b9e7eb453eed7ace4e39e15598303e Introduced a separate GPIO module with its operations each employing a base address to access the GPIO registers. diff -r 1571da98c6b9 -r 825b572484c6 include/jz4730.h --- a/include/jz4730.h Tue Jul 11 18:45:08 2017 +0200 +++ b/include/jz4730.h Wed Jul 12 15:46:53 2017 +0200 @@ -1343,83 +1343,11 @@ /************************************************************************* * GPIO *************************************************************************/ -#define GPIO_GPDR(n) (GPIO_BASE + (0x00 + (n)*0x30)) -#define GPIO_GPDIR(n) (GPIO_BASE + (0x04 + (n)*0x30)) -#define GPIO_GPODR(n) (GPIO_BASE + (0x08 + (n)*0x30)) -#define GPIO_GPPUR(n) (GPIO_BASE + (0x0c + (n)*0x30)) -#define GPIO_GPALR(n) (GPIO_BASE + (0x10 + (n)*0x30)) -#define GPIO_GPAUR(n) (GPIO_BASE + (0x14 + (n)*0x30)) -#define GPIO_GPIDLR(n) (GPIO_BASE + (0x18 + (n)*0x30)) -#define GPIO_GPIDUR(n) (GPIO_BASE + (0x1c + (n)*0x30)) -#define GPIO_GPIER(n) (GPIO_BASE + (0x20 + (n)*0x30)) -#define GPIO_GPIMR(n) (GPIO_BASE + (0x24 + (n)*0x30)) -#define GPIO_GPFR(n) (GPIO_BASE + (0x28 + (n)*0x30)) - -#define REG_GPIO_GPDR(n) REG32(GPIO_GPDR((n))) -#define REG_GPIO_GPDIR(n) REG32(GPIO_GPDIR((n))) -#define REG_GPIO_GPODR(n) REG32(GPIO_GPODR((n))) -#define REG_GPIO_GPPUR(n) REG32(GPIO_GPPUR((n))) -#define REG_GPIO_GPALR(n) REG32(GPIO_GPALR((n))) -#define REG_GPIO_GPAUR(n) REG32(GPIO_GPAUR((n))) -#define REG_GPIO_GPIDLR(n) REG32(GPIO_GPIDLR((n))) -#define REG_GPIO_GPIDUR(n) REG32(GPIO_GPIDUR((n))) -#define REG_GPIO_GPIER(n) REG32(GPIO_GPIER((n))) -#define REG_GPIO_GPIMR(n) REG32(GPIO_GPIMR((n))) -#define REG_GPIO_GPFR(n) REG32(GPIO_GPFR((n))) - -#define GPIO_IRQ_LOLEVEL 0 -#define GPIO_IRQ_HILEVEL 1 -#define GPIO_IRQ_FALLEDG 2 -#define GPIO_IRQ_RAISEDG 3 #define IRQ_GPIO_0 48 #define NUM_GPIO 100 -#define GPIO_GPDR0 GPIO_GPDR(0) -#define GPIO_GPDR1 GPIO_GPDR(1) -#define GPIO_GPDR2 GPIO_GPDR(2) -#define GPIO_GPDR3 GPIO_GPDR(3) -#define GPIO_GPDIR0 GPIO_GPDIR(0) -#define GPIO_GPDIR1 GPIO_GPDIR(1) -#define GPIO_GPDIR2 GPIO_GPDIR(2) -#define GPIO_GPDIR3 GPIO_GPDIR(3) -#define GPIO_GPODR0 GPIO_GPODR(0) -#define GPIO_GPODR1 GPIO_GPODR(1) -#define GPIO_GPODR2 GPIO_GPODR(2) -#define GPIO_GPODR3 GPIO_GPODR(3) -#define GPIO_GPPUR0 GPIO_GPPUR(0) -#define GPIO_GPPUR1 GPIO_GPPUR(1) -#define GPIO_GPPUR2 GPIO_GPPUR(2) -#define GPIO_GPPUR3 GPIO_GPPUR(3) -#define GPIO_GPALR0 GPIO_GPALR(0) -#define GPIO_GPALR1 GPIO_GPALR(1) -#define GPIO_GPALR2 GPIO_GPALR(2) -#define GPIO_GPALR3 GPIO_GPALR(3) -#define GPIO_GPAUR0 GPIO_GPAUR(0) -#define GPIO_GPAUR1 GPIO_GPAUR(1) -#define GPIO_GPAUR2 GPIO_GPAUR(2) -#define GPIO_GPAUR3 GPIO_GPAUR(3) -#define GPIO_GPIDLR0 GPIO_GPIDLR(0) -#define GPIO_GPIDLR1 GPIO_GPIDLR(1) -#define GPIO_GPIDLR2 GPIO_GPIDLR(2) -#define GPIO_GPIDLR3 GPIO_GPIDLR(3) -#define GPIO_GPIDUR0 GPIO_GPIDUR(0) -#define GPIO_GPIDUR1 GPIO_GPIDUR(1) -#define GPIO_GPIDUR2 GPIO_GPIDUR(2) -#define GPIO_GPIDUR3 GPIO_GPIDUR(3) -#define GPIO_GPIER0 GPIO_GPIER(0) -#define GPIO_GPIER1 GPIO_GPIER(1) -#define GPIO_GPIER2 GPIO_GPIER(2) -#define GPIO_GPIER3 GPIO_GPIER(3) -#define GPIO_GPIMR0 GPIO_GPIMR(0) -#define GPIO_GPIMR1 GPIO_GPIMR(1) -#define GPIO_GPIMR2 GPIO_GPIMR(2) -#define GPIO_GPIMR3 GPIO_GPIMR(3) -#define GPIO_GPFR0 GPIO_GPFR(0) -#define GPIO_GPFR1 GPIO_GPFR(1) -#define GPIO_GPFR2 GPIO_GPFR(2) -#define GPIO_GPFR3 GPIO_GPFR(3) - +/* Register definitions with absolute positioning have been removed. */ /************************************************************************* * HARB @@ -3160,356 +3088,7 @@ * GPIO ***************************************************************************/ -/* p is the port number (0,1,2,3) - * o is the pin offset (0-31) inside the port - * n is the absolute number of a pin (0-124), regardless of the port - * m is the interrupt manner (low/high/falling/rising) - */ - -#define __gpio_port_data(p) ( REG_GPIO_GPDR(p) ) - -#define __gpio_port_as_output(p, o) \ -do { \ - unsigned int tmp; \ - REG_GPIO_GPIER(p) &= ~(1 << (o)); \ - REG_GPIO_GPDIR(p) |= (1 << (o)); \ - if (o < 16) { \ - tmp = REG_GPIO_GPALR(p); \ - tmp &= ~(3 << ((o) << 1)); \ - REG_GPIO_GPALR(p) = tmp; \ - } else { \ - tmp = REG_GPIO_GPAUR(p); \ - tmp &= ~(3 << (((o) - 16)<< 1)); \ - REG_GPIO_GPAUR(p) = tmp; \ - } \ -} while (0) - -#define __gpio_port_as_input(p, o) \ -do { \ - unsigned int tmp; \ - REG_GPIO_GPIER(p) &= ~(1 << (o)); \ - REG_GPIO_GPDIR(p) &= ~(1 << (o)); \ - if (o < 16) { \ - tmp = REG_GPIO_GPALR(p); \ - tmp &= ~(3 << ((o) << 1)); \ - REG_GPIO_GPALR(p) = tmp; \ - } else { \ - tmp = REG_GPIO_GPAUR(p); \ - tmp &= ~(3 << (((o) - 16)<< 1)); \ - REG_GPIO_GPAUR(p) = tmp; \ - } \ -} while (0) - -#define __gpio_as_output(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - __gpio_port_as_output(p, o); \ -} while (0) - -#define __gpio_as_input(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - __gpio_port_as_input(p, o); \ -} while (0) - -#define __gpio_set_pin(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - __gpio_port_data(p) |= (1 << o); \ -} while (0) - -#define __gpio_clear_pin(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - __gpio_port_data(p) &= ~(1 << o); \ -} while (0) - -static __inline__ unsigned int __gpio_get_pin(unsigned int n) -{ - unsigned int p, o; - p = (n) / 32; - o = (n) % 32; - if (__gpio_port_data(p) & (1 << o)) - return 1; - else - return 0; -} - - -#define __gpio_set_irq_detect_manner(p, o, m) \ -do { \ - unsigned int tmp; \ - if (o < 16) { \ - tmp = REG_GPIO_GPIDLR(p); \ - tmp &= ~(3 << ((o) << 1)); \ - tmp |= ((m) << ((o) << 1)); \ - REG_GPIO_GPIDLR(p) = tmp; \ - } else { \ - o -= 16; \ - tmp = REG_GPIO_GPIDUR(p); \ - tmp &= ~(3 << ((o) << 1)); \ - tmp |= ((m) << ((o) << 1)); \ - REG_GPIO_GPIDUR(p) = tmp; \ - } \ -} while (0) - -#define __gpio_port_as_irq(p, o, m) \ -do { \ - __gpio_set_irq_detect_manner(p, o, m); \ - __gpio_port_as_input(p, o); \ - REG_GPIO_GPIER(p) |= (1 << o); \ -} while (0) - -#define __gpio_as_irq(n, m) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - __gpio_port_as_irq(p, o, m); \ -} while (0) - - -#define __gpio_as_irq_high_level(n) __gpio_as_irq(n, GPIO_IRQ_HILEVEL) -#define __gpio_as_irq_low_level(n) __gpio_as_irq(n, GPIO_IRQ_LOLEVEL) -#define __gpio_as_irq_fall_edge(n) __gpio_as_irq(n, GPIO_IRQ_FALLEDG) -#define __gpio_as_irq_rise_edge(n) __gpio_as_irq(n, GPIO_IRQ_RAISEDG) - - -#define __gpio_mask_irq(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_GPIER(p) &= ~(1 << o); \ -} while (0) - -#define __gpio_unmask_irq(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_GPIER(n) |= (1 << o); \ -} while (0) - -#define __gpio_ack_irq(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_GPFR(p) |= (1 << o); \ -} while (0) - - -static __inline__ unsigned int __gpio_get_irq(void) -{ - unsigned int tmp, i; - - tmp = REG_GPIO_GPFR(3); - for (i=0; i<32; i++) - if (tmp & (1 << i)) - return 0x60 + i; - tmp = REG_GPIO_GPFR(2); - for (i=0; i<32; i++) - if (tmp & (1 << i)) - return 0x40 + i; - tmp = REG_GPIO_GPFR(1); - for (i=0; i<32; i++) - if (tmp & (1 << i)) - return 0x20 + i; - tmp = REG_GPIO_GPFR(0); - for (i=0; i<32; i++) - if (tmp & (1 << i)) - return i; - return 0; -} - -#define __gpio_group_irq(n) \ -({ \ - register int tmp, i; \ - tmp = REG_GPIO_GPFR((n)); \ - for (i=31;i>=0;i--) \ - if (tmp & (1 << i)) \ - break; \ - i; \ -}) - -#define __gpio_enable_pull(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_GPPUR(p) |= (1 << o); \ -} while (0) - -#define __gpio_disable_pull(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_GPPUR(p) &= ~(1 << o); \ -} while (0) - -/* Init the alternate function pins */ - - -#define __gpio_as_ssi() \ -do { \ - REG_GPIO_GPALR(2) &= 0xFC00FFFF; \ - REG_GPIO_GPALR(2) |= 0x01550000; \ -} while (0) - -#define __gpio_as_uart3() \ -do { \ - REG_GPIO_GPAUR(0) &= 0xFFFF0000; \ - REG_GPIO_GPAUR(0) |= 0x00005555; \ -} while (0) - -#define __gpio_as_uart2() \ -do { \ - REG_GPIO_GPALR(3) &= 0x3FFFFFFF; \ - REG_GPIO_GPALR(3) |= 0x40000000; \ - REG_GPIO_GPAUR(3) &= 0xF3FFFFFF; \ - REG_GPIO_GPAUR(3) |= 0x04000000; \ -} while (0) - -#define __gpio_as_uart1() \ -do { \ - REG_GPIO_GPAUR(0) &= 0xFFF0FFFF; \ - REG_GPIO_GPAUR(0) |= 0x00050000; \ -} while (0) - -#define __gpio_as_uart0() \ -do { \ - REG_GPIO_GPAUR(3) &= 0x0FFFFFFF; \ - REG_GPIO_GPAUR(3) |= 0x50000000; \ -} while (0) - - -#define __gpio_as_scc0() \ -do { \ - REG_GPIO_GPALR(2) &= 0xFFFFFFCC; \ - REG_GPIO_GPALR(2) |= 0x00000011; \ -} while (0) - -#define __gpio_as_scc1() \ -do { \ - REG_GPIO_GPALR(2) &= 0xFFFFFF33; \ - REG_GPIO_GPALR(2) |= 0x00000044; \ -} while (0) - -#define __gpio_as_scc() \ -do { \ - __gpio_as_scc0(); \ - __gpio_as_scc1(); \ -} while (0) - -#define __gpio_as_dma() \ -do { \ - REG_GPIO_GPALR(0) &= 0x00FFFFFF; \ - REG_GPIO_GPALR(0) |= 0x55000000; \ - REG_GPIO_GPAUR(0) &= 0xFF0FFFFF; \ - REG_GPIO_GPAUR(0) |= 0x00500000; \ -} while (0) - -#define __gpio_as_msc() \ -do { \ - REG_GPIO_GPALR(1) &= 0xFFFF000F; \ - REG_GPIO_GPALR(1) |= 0x00005550; \ -} while (0) - -#define __gpio_as_pcmcia() \ -do { \ - REG_GPIO_GPAUR(2) &= 0xF000FFFF; \ - REG_GPIO_GPAUR(2) |= 0x05550000; \ -} while (0) - -#define __gpio_as_emc() \ -do { \ - REG_GPIO_GPALR(2) &= 0x3FFFFFFF; \ - REG_GPIO_GPALR(2) |= 0x40000000; \ - REG_GPIO_GPAUR(2) &= 0xFFFF0000; \ - REG_GPIO_GPAUR(2) |= 0x00005555; \ -} while (0) - -#define __gpio_as_lcd_slave() \ -do { \ - REG_GPIO_GPALR(1) &= 0x0000FFFF; \ - REG_GPIO_GPALR(1) |= 0x55550000; \ - REG_GPIO_GPAUR(1) &= 0x00000000; \ - REG_GPIO_GPAUR(1) |= 0x55555555; \ -} while (0) - -#define __gpio_as_lcd_master() \ -do { \ - REG_GPIO_GPALR(1) &= 0x0000FFFF; \ - REG_GPIO_GPALR(1) |= 0x55550000; \ - REG_GPIO_GPAUR(1) &= 0x00000000; \ - REG_GPIO_GPAUR(1) |= 0x556A5555; \ -} while (0) - -#define __gpio_as_usb() \ -do { \ - REG_GPIO_GPAUR(0) &= 0x00FFFFFF; \ - REG_GPIO_GPAUR(0) |= 0x55000000; \ -} while (0) - -#define __gpio_as_ac97() \ -do { \ - REG_GPIO_GPALR(2) &= 0xC3FF03FF; \ - REG_GPIO_GPALR(2) |= 0x24005400; \ -} while (0) - -#define __gpio_as_i2s_slave() \ -do { \ - REG_GPIO_GPALR(2) &= 0xC3FF0CFF; \ - REG_GPIO_GPALR(2) |= 0x14005100; \ -} while (0) - -#define __gpio_as_i2s_master() \ -do { \ - REG_GPIO_GPALR(2) &= 0xC3FF0CFF; \ - REG_GPIO_GPALR(2) |= 0x28005100; \ -} while (0) - -#define __gpio_as_eth() \ -do { \ - REG_GPIO_GPAUR(3) &= 0xFC000000; \ - REG_GPIO_GPAUR(3) |= 0x01555555; \ -} while (0) - -#define __gpio_as_pwm() \ -do { \ - REG_GPIO_GPAUR(2) &= 0x0FFFFFFF; \ - REG_GPIO_GPAUR(2) |= 0x50000000; \ -} while (0) - -#define __gpio_as_ps2() \ -do { \ - REG_GPIO_GPALR(1) &= 0xFFFFFFF0; \ - REG_GPIO_GPALR(1) |= 0x00000005; \ -} while (0) - -#define __gpio_as_uprt() \ -do { \ - REG_GPIO_GPALR(1) &= 0x0000000F; \ - REG_GPIO_GPALR(1) |= 0x55555550; \ - REG_GPIO_GPALR(3) &= 0xC0000000; \ - REG_GPIO_GPALR(3) |= 0x15555555; \ -} while (0) - -#define __gpio_as_cim() \ -do { \ - REG_GPIO_GPALR(0) &= 0xFF000000; \ - REG_GPIO_GPALR(0) |= 0x00555555; \ -} while (0) +/* Register operations using absolute positioning have been removed. */ /*************************************************************************** * HARB diff -r 1571da98c6b9 -r 825b572484c6 include/jz4740.h --- a/include/jz4740.h Tue Jul 11 18:45:08 2017 +0200 +++ b/include/jz4740.h Wed Jul 12 15:46:53 2017 +0200 @@ -742,60 +742,11 @@ /************************************************************************* * GPIO (General-Purpose I/O Ports) *************************************************************************/ + +/* Register definitions with absolute positioning have been removed. */ + #define MAX_GPIO_NUM 128 -/* = 0,1,2,3 */ -#define GPIO_PXPIN(n) (GPIO_BASE + (0x00 + (n)*0x100)) /* PIN Level Register */ -#define GPIO_PXDAT(n) (GPIO_BASE + (0x10 + (n)*0x100)) /* Port Data Register */ -#define GPIO_PXDATS(n) (GPIO_BASE + (0x14 + (n)*0x100)) /* Port Data Set Register */ -#define GPIO_PXDATC(n) (GPIO_BASE + (0x18 + (n)*0x100)) /* Port Data Clear Register */ -#define GPIO_PXIM(n) (GPIO_BASE + (0x20 + (n)*0x100)) /* Interrupt Mask Register */ -#define GPIO_PXIMS(n) (GPIO_BASE + (0x24 + (n)*0x100)) /* Interrupt Mask Set Reg */ -#define GPIO_PXIMC(n) (GPIO_BASE + (0x28 + (n)*0x100)) /* Interrupt Mask Clear Reg */ -#define GPIO_PXPE(n) (GPIO_BASE + (0x30 + (n)*0x100)) /* Pull Enable Register */ -#define GPIO_PXPES(n) (GPIO_BASE + (0x34 + (n)*0x100)) /* Pull Enable Set Reg. */ -#define GPIO_PXPEC(n) (GPIO_BASE + (0x38 + (n)*0x100)) /* Pull Enable Clear Reg. */ -#define GPIO_PXFUN(n) (GPIO_BASE + (0x40 + (n)*0x100)) /* Function Register */ -#define GPIO_PXFUNS(n) (GPIO_BASE + (0x44 + (n)*0x100)) /* Function Set Register */ -#define GPIO_PXFUNC(n) (GPIO_BASE + (0x48 + (n)*0x100)) /* Function Clear Register */ -#define GPIO_PXSEL(n) (GPIO_BASE + (0x50 + (n)*0x100)) /* Select Register */ -#define GPIO_PXSELS(n) (GPIO_BASE + (0x54 + (n)*0x100)) /* Select Set Register */ -#define GPIO_PXSELC(n) (GPIO_BASE + (0x58 + (n)*0x100)) /* Select Clear Register */ -#define GPIO_PXDIR(n) (GPIO_BASE + (0x60 + (n)*0x100)) /* Direction Register */ -#define GPIO_PXDIRS(n) (GPIO_BASE + (0x64 + (n)*0x100)) /* Direction Set Register */ -#define GPIO_PXDIRC(n) (GPIO_BASE + (0x68 + (n)*0x100)) /* Direction Clear Register */ -#define GPIO_PXTRG(n) (GPIO_BASE + (0x70 + (n)*0x100)) /* Trigger Register */ -#define GPIO_PXTRGS(n) (GPIO_BASE + (0x74 + (n)*0x100)) /* Trigger Set Register */ -#define GPIO_PXTRGC(n) (GPIO_BASE + (0x78 + (n)*0x100)) /* Trigger Set Register */ -#define GPIO_PXFLG(n) (GPIO_BASE + (0x80 + (n)*0x100)) /* Port Flag Register */ -#define GPIO_PXFLGC(n) (GPIO_BASE + (0x84 + (n)*0x100)) /* Port Flag clear Register */ - -#define REG_GPIO_PXPIN(n) REG32(GPIO_PXPIN((n))) /* PIN level */ -#define REG_GPIO_PXDAT(n) REG32(GPIO_PXDAT((n))) /* 1: interrupt pending */ -#define REG_GPIO_PXDATS(n) REG32(GPIO_PXDATS((n))) -#define REG_GPIO_PXDATC(n) REG32(GPIO_PXDATC((n))) -#define REG_GPIO_PXIM(n) REG32(GPIO_PXIM((n))) /* 1: mask pin interrupt */ -#define REG_GPIO_PXIMS(n) REG32(GPIO_PXIMS((n))) -#define REG_GPIO_PXIMC(n) REG32(GPIO_PXIMC((n))) -#define REG_GPIO_PXPE(n) REG32(GPIO_PXPE((n))) /* 1: disable pull up/down */ -#define REG_GPIO_PXPES(n) REG32(GPIO_PXPES((n))) -#define REG_GPIO_PXPEC(n) REG32(GPIO_PXPEC((n))) -#define REG_GPIO_PXFUN(n) REG32(GPIO_PXFUN((n))) /* 0:GPIO or intr, 1:FUNC */ -#define REG_GPIO_PXFUNS(n) REG32(GPIO_PXFUNS((n))) -#define REG_GPIO_PXFUNC(n) REG32(GPIO_PXFUNC((n))) -#define REG_GPIO_PXSEL(n) REG32(GPIO_PXSEL((n))) /* 0:GPIO/Fun0,1:intr/fun1*/ -#define REG_GPIO_PXSELS(n) REG32(GPIO_PXSELS((n))) -#define REG_GPIO_PXSELC(n) REG32(GPIO_PXSELC((n))) -#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 */ -#define REG_GPIO_PXDIRS(n) REG32(GPIO_PXDIRS((n))) -#define REG_GPIO_PXDIRC(n) REG32(GPIO_PXDIRC((n))) -#define REG_GPIO_PXTRG(n) REG32(GPIO_PXTRG((n))) /* 0:level-trigger, 1:edge-trigger */ -#define REG_GPIO_PXTRGS(n) REG32(GPIO_PXTRGS((n))) -#define REG_GPIO_PXTRGC(n) REG32(GPIO_PXTRGC((n))) -#define REG_GPIO_PXFLG(n) REG32(GPIO_PXFLG((n))) /* interrupt flag */ -#define REG_GPIO_PXFLGC(n) REG32(GPIO_PXFLGC((n))) /* interrupt flag */ - - /************************************************************************* * UART *************************************************************************/ @@ -2317,701 +2268,10 @@ /* Module Operation Definitions */ + #ifndef __ASSEMBLY__ - -/* GPIO Pins Description */ -/* PORT 0: */ -/* PIN/BIT N FUNC0 FUNC1 */ -/* 0 D0 - */ -/* 1 D1 - */ -/* 2 D2 - */ -/* 3 D3 - */ -/* 4 D4 - */ -/* 5 D5 - */ -/* 6 D6 - */ -/* 7 D7 - */ -/* 8 D8 - */ -/* 9 D9 - */ -/* 10 D10 - */ -/* 11 D11 - */ -/* 12 D12 - */ -/* 13 D13 - */ -/* 14 D14 - */ -/* 15 D15 - */ -/* 16 D16 - */ -/* 17 D17 - */ -/* 18 D18 - */ -/* 19 D19 - */ -/* 20 D20 - */ -/* 21 D21 - */ -/* 22 D22 - */ -/* 23 D23 - */ -/* 24 D24 - */ -/* 25 D25 - */ -/* 26 D26 - */ -/* 27 D27 - */ -/* 28 D28 - */ -/* 29 D29 - */ -/* 30 D30 - */ -/* 31 D31 - */ -/*------------------------------------------------------ */ -/* PORT 1: */ -/* */ -/* PIN/BIT N FUNC0 FUNC1 */ -/* 0 A0 - */ -/* 1 A1 - */ -/* 2 A2 - */ -/* 3 A3 - */ -/* 4 A4 - */ -/* 5 A5 - */ -/* 6 A6 - */ -/* 7 A7 - */ -/* 8 A8 - */ -/* 9 A9 - */ -/* 10 A10 - */ -/* 11 A11 - */ -/* 12 A12 - */ -/* 13 A13 - */ -/* 14 A14 - */ -/* 15 A15/CL - */ -/* 16 A16/AL - */ -/* 17 LCD_CLS A21 */ -/* 18 LCD_SPL A22 */ -/* 19 DCS# - */ -/* 20 RAS# - */ -/* 21 CAS# - */ -/* 22 RDWE#/BUFD# - */ -/* 23 CKE - */ -/* 24 CKO - */ -/* 25 CS1# - */ -/* 26 CS2# - */ -/* 27 CS3# - */ -/* 28 CS4# - */ -/* 29 RD# - */ -/* 30 WR# - */ -/* 31 WE0# - */ -/* Note: PIN15&16 are CL&AL when connecting to NAND flash. */ -/*------------------------------------------------------ */ -/* PORT 2: */ -/* */ -/* PIN/BIT N FUNC0 FUNC1 */ -/* 0 LCD_D0 - */ -/* 1 LCD_D1 - */ -/* 2 LCD_D2 - */ -/* 3 LCD_D3 - */ -/* 4 LCD_D4 - */ -/* 5 LCD_D5 - */ -/* 6 LCD_D6 - */ -/* 7 LCD_D7 - */ -/* 8 LCD_D8 - */ -/* 9 LCD_D9 - */ -/* 10 LCD_D10 - */ -/* 11 LCD_D11 - */ -/* 12 LCD_D12 - */ -/* 13 LCD_D13 - */ -/* 14 LCD_D14 - */ -/* 15 LCD_D15 - */ -/* 16 LCD_D16 - */ -/* 17 LCD_D17 - */ -/* 18 LCD_PCLK - */ -/* 19 LCD_HSYNC - */ -/* 20 LCD_VSYNC - */ -/* 21 LCD_DE - */ -/* 22 LCD_PS A19 */ -/* 23 LCD_REV A20 */ -/* 24 WE1# - */ -/* 25 WE2# - */ -/* 26 WE3# - */ -/* 27 WAIT# - */ -/* 28 FRE# - */ -/* 29 FWE# - */ -/* 30(NOTE:FRB#) - - */ -/* 31 - - */ -/* NOTE(1): PIN30 is used for FRB# when connecting to NAND flash. */ -/*------------------------------------------------------ */ -/* PORT 3: */ -/* */ -/* PIN/BIT N FUNC0 FUNC1 */ -/* 0 CIM_D0 - */ -/* 1 CIM_D1 - */ -/* 2 CIM_D2 - */ -/* 3 CIM_D3 - */ -/* 4 CIM_D4 - */ -/* 5 CIM_D5 - */ -/* 6 CIM_D6 - */ -/* 7 CIM_D7 - */ -/* 8 MSC_CMD - */ -/* 9 MSC_CLK - */ -/* 10 MSC_D0 - */ -/* 11 MSC_D1 - */ -/* 12 MSC_D2 - */ -/* 13 MSC_D3 - */ -/* 14 CIM_MCLK - */ -/* 15 CIM_PCLK - */ -/* 16 CIM_VSYNC - */ -/* 17 CIM_HSYNC - */ -/* 18 SSI_CLK SCLK_RSTN */ -/* 19 SSI_CE0# BIT_CLK(AIC) */ -/* 20 SSI_DT SDATA_OUT(AIC) */ -/* 21 SSI_DR SDATA_IN(AIC) */ -/* 22 SSI_CE1#&GPC SYNC(AIC) */ -/* 23 PWM0 I2C_SDA */ -/* 24 PWM1 I2C_SCK */ -/* 25 PWM2 UART0_TxD */ -/* 26 PWM3 UART0_RxD */ -/* 27 PWM4 A17 */ -/* 28 PWM5 A18 */ -/* 29 - - */ -/* 30 PWM6 UART0_CTS/UART1_RxD */ -/* 31 PWM7 UART0_RTS/UART1_TxD */ -/* - * p is the port number (0,1,2,3) - * o is the pin offset (0-31) inside the port - * n is the absolute number of a pin (0-127), regardless of the port - */ - -/* Function Pins Mode */ - -#define __gpio_as_func0(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXFUNS(p) = (1 << o); \ - REG_GPIO_PXSELC(p) = (1 << o); \ -} while (0) - -#define __gpio_as_func1(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXFUNS(p) = (1 << o); \ - REG_GPIO_PXSELS(p) = (1 << o); \ -} while (0) - -/* - * D0 ~ D31, A0 ~ A16, DCS#, RAS#, CAS#, CKE#, - * RDWE#, CKO#, WE0#, WE1#, WE2#, WE3# - */ -#define __gpio_as_sdram_32bit() \ -do { \ - REG_GPIO_PXFUNS(0) = 0xffffffff; \ - REG_GPIO_PXSELC(0) = 0xffffffff; \ - REG_GPIO_PXPES(0) = 0xffffffff; \ - REG_GPIO_PXFUNS(1) = 0x81f9ffff; \ - REG_GPIO_PXSELC(1) = 0x81f9ffff; \ - REG_GPIO_PXPES(1) = 0x81f9ffff; \ - REG_GPIO_PXFUNS(2) = 0x07000000; \ - REG_GPIO_PXSELC(2) = 0x07000000; \ - REG_GPIO_PXPES(2) = 0x07000000; \ -} while (0) - -/* - * D0 ~ D15, A0 ~ A16, DCS#, RAS#, CAS#, CKE#, - * RDWE#, CKO#, WE0#, WE1# - */ -#define __gpio_as_sdram_16bit_4720() \ -do { \ - REG_GPIO_PXFUNS(0) = 0x5442bfaa; \ - REG_GPIO_PXSELC(0) = 0x5442bfaa; \ - REG_GPIO_PXPES(0) = 0x5442bfaa; \ - REG_GPIO_PXFUNS(1) = 0x81f9ffff; \ - REG_GPIO_PXSELC(1) = 0x81f9ffff; \ - REG_GPIO_PXPES(1) = 0x81f9ffff; \ - REG_GPIO_PXFUNS(2) = 0x01000000; \ - REG_GPIO_PXSELC(2) = 0x01000000; \ - REG_GPIO_PXPES(2) = 0x01000000; \ -} while (0) - -/* - * D0 ~ D15, A0 ~ A16, DCS#, RAS#, CAS#, CKE#, - * RDWE#, CKO#, WE0#, WE1# - */ -#define __gpio_as_sdram_16bit_4725() \ -do { \ - REG_GPIO_PXFUNS(0) = 0x0000ffff; \ - REG_GPIO_PXSELC(0) = 0x0000ffff; \ - REG_GPIO_PXPES(0) = 0x0000ffff; \ - REG_GPIO_PXFUNS(1) = 0x81f9ffff; \ - REG_GPIO_PXSELC(1) = 0x81f9ffff; \ - REG_GPIO_PXPES(1) = 0x81f9ffff; \ - REG_GPIO_PXFUNS(2) = 0x01000000; \ - REG_GPIO_PXSELC(2) = 0x01000000; \ - REG_GPIO_PXPES(2) = 0x01000000; \ -} while (0) - - -/* - * CS1#, CLE, ALE, FRE#, FWE#, FRB#, RDWE#/BUFD# - */ -#define __gpio_as_nand() \ -do { \ - REG_GPIO_PXFUNS(1) = 0x02018000; \ - REG_GPIO_PXSELC(1) = 0x02018000; \ - REG_GPIO_PXPES(1) = 0x02018000; \ - REG_GPIO_PXFUNS(2) = 0x30000000; \ - REG_GPIO_PXSELC(2) = 0x30000000; \ - REG_GPIO_PXPES(2) = 0x30000000; \ - REG_GPIO_PXFUNC(2) = 0x40000000; \ - REG_GPIO_PXSELC(2) = 0x40000000; \ - REG_GPIO_PXDIRC(2) = 0x40000000; \ - REG_GPIO_PXPES(2) = 0x40000000; \ - REG_GPIO_PXFUNS(1) = 0x00400000; \ - REG_GPIO_PXSELC(1) = 0x00400000; \ -} while (0) - -/* - * CS4#, RD#, WR#, WAIT#, A0 ~ A22, D0 ~ D7 - */ -#define __gpio_as_nor_8bit() \ -do { \ - REG_GPIO_PXFUNS(0) = 0x000000ff; \ - REG_GPIO_PXSELC(0) = 0x000000ff; \ - REG_GPIO_PXPES(0) = 0x000000ff; \ - REG_GPIO_PXFUNS(1) = 0x7041ffff; \ - REG_GPIO_PXSELC(1) = 0x7041ffff; \ - REG_GPIO_PXPES(1) = 0x7041ffff; \ - REG_GPIO_PXFUNS(1) = 0x00060000; \ - REG_GPIO_PXSELS(1) = 0x00060000; \ - REG_GPIO_PXPES(1) = 0x00060000; \ - REG_GPIO_PXFUNS(2) = 0x08000000; \ - REG_GPIO_PXSELC(2) = 0x08000000; \ - REG_GPIO_PXPES(2) = 0x08000000; \ - REG_GPIO_PXFUNS(2) = 0x00c00000; \ - REG_GPIO_PXSELS(2) = 0x00c00000; \ - REG_GPIO_PXPES(2) = 0x00c00000; \ - REG_GPIO_PXFUNS(3) = 0x18000000; \ - REG_GPIO_PXSELS(3) = 0x18000000; \ - REG_GPIO_PXPES(3) = 0x18000000; \ -} while (0) - -/* - * CS4#, RD#, WR#, WAIT#, A0 ~ A22, D0 ~ D15 - */ -#define __gpio_as_nor_16bit() \ -do { \ - REG_GPIO_PXFUNS(0) = 0x0000ffff; \ - REG_GPIO_PXSELC(0) = 0x0000ffff; \ - REG_GPIO_PXPES(0) = 0x0000ffff; \ - REG_GPIO_PXFUNS(1) = 0x7041ffff; \ - REG_GPIO_PXSELC(1) = 0x7041ffff; \ - REG_GPIO_PXPES(1) = 0x7041ffff; \ - REG_GPIO_PXFUNS(1) = 0x00060000; \ - REG_GPIO_PXSELS(1) = 0x00060000; \ - REG_GPIO_PXPES(1) = 0x00060000; \ - REG_GPIO_PXFUNS(2) = 0x08000000; \ - REG_GPIO_PXSELC(2) = 0x08000000; \ - REG_GPIO_PXPES(2) = 0x08000000; \ - REG_GPIO_PXFUNS(2) = 0x00c00000; \ - REG_GPIO_PXSELS(2) = 0x00c00000; \ - REG_GPIO_PXPES(2) = 0x00c00000; \ - REG_GPIO_PXFUNS(3) = 0x18000000; \ - REG_GPIO_PXSELS(3) = 0x18000000; \ - REG_GPIO_PXPES(3) = 0x18000000; \ -} while (0) - -/* - * UART0_TxD, UART_RxD0 - */ -#define __gpio_as_uart0() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x06000000; \ - REG_GPIO_PXSELS(3) = 0x06000000; \ - REG_GPIO_PXPES(3) = 0x06000000; \ -} while (0) - -#define __gpio_jtag_to_uart0() \ -do { \ - REG_GPIO_PXSELS(2) = 0x80000000; \ -} while (0) - -/* - * UART0_CTS, UART0_RTS - */ -#define __gpio_as_ctsrts() \ -do { \ - REG_GPIO_PXFUNS(3) = 0xc0000000; \ - REG_GPIO_PXSELS(3) = 0xc0000000; \ - REG_GPIO_PXTRGC(3) = 0xc0000000; \ - REG_GPIO_PXPES(3) = 0xc0000000; \ -} while (0) - -/* - * UART1_TxD, UART1_RxD1 - */ -#define __gpio_as_uart1() \ -do { \ - REG_GPIO_PXFUNS(3) = 0xc0000000; \ - REG_GPIO_PXSELC(3) = 0xc0000000; \ - REG_GPIO_PXTRGS(3) = 0xc0000000; \ - REG_GPIO_PXPES(3) = 0xc0000000; \ -} while (0) - -/* - * LCD_D0~LCD_D15, LCD_PCLK, LCD_HSYNC, LCD_VSYNC, LCD_DE - */ -#define __gpio_as_lcd_16bit() \ -do { \ - REG_GPIO_PXFUNS(2) = 0x003cffff; \ - REG_GPIO_PXSELC(2) = 0x003cffff; \ - REG_GPIO_PXPES(2) = 0x003cffff; \ -} while (0) - -/* - * LCD_D0~LCD_D17, LCD_PCLK, LCD_HSYNC, LCD_VSYNC, LCD_DE - */ -#define __gpio_as_lcd_18bit() \ -do { \ - REG_GPIO_PXFUNS(2) = 0x003fffff; \ - REG_GPIO_PXSELC(2) = 0x003fffff; \ - REG_GPIO_PXPES(2) = 0x003fffff; \ -} while (0) - - -/* LCD_D0~LCD_D7, SLCD_CLK, SLCD_RS, SLCD_CS, LCD_DE */ -#define __gpio_as_slcd_8bit() \ -do { \ - REG_GPIO_PXFUNS(2) = 0x003c00ff; \ - REG_GPIO_PXSELC(2) = 0x003c00ff; \ -} while (0) - -/* LCD_D0~LCD_D7, SLCD_RS, SLCD_CS */ -#define __gpio_as_slcd_9bit() \ -do { \ - REG_GPIO_PXFUNS(2) = 0x001801ff; \ - REG_GPIO_PXSELC(2) = 0x001801ff; \ -} while (0) - -/* LCD_D0~LCD_D15, SLCD_RS, SLCD_CS */ -#define __gpio_as_slcd_16bit() \ -do { \ - REG_GPIO_PXFUNS(2) = 0x0018ffff; \ - REG_GPIO_PXSELC(2) = 0x0018ffff; \ -} while (0) - -/* LCD_D0~LCD_D17, SLCD_RS, SLCD_CS */ -#define __gpio_as_slcd_18bit() \ -do { \ - REG_GPIO_PXFUNS(2) = 0x001bffff; \ - REG_GPIO_PXSELC(2) = 0x001bffff; \ -} while (0) -/* - * CIM_D0~CIM_D7, CIM_MCLK, CIM_PCLK, CIM_VSYNC, CIM_HSYNC - */ -#define __gpio_as_cim() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x0003c0ff; \ - REG_GPIO_PXSELC(3) = 0x0003c0ff; \ - REG_GPIO_PXPES(3) = 0x0003c0ff; \ -} while (0) - -/* - * SDATA_OUT, SDATA_IN, BIT_CLK, SYNC, SCLK_RESET - */ -#define __gpio_as_aic() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x007c0000; \ - REG_GPIO_PXSELS(3) = 0x007c0000; \ - REG_GPIO_PXPES(3) = 0x007c0000; \ -} while (0) - -/* - * MSC_CMD, MSC_CLK, MSC_D0 ~ MSC_D3 - */ -#define __gpio_as_msc() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x00003f00; \ - REG_GPIO_PXSELC(3) = 0x00003f00; \ - REG_GPIO_PXPES(3) = 0x00003f00; \ -} while (0) - -/* - * SSI_CS0, SSI_CLK, SSI_DT, SSI_DR - */ -#define __gpio_as_ssi() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x003c0000; \ - REG_GPIO_PXSELC(3) = 0x003c0000; \ - REG_GPIO_PXPES(3) = 0x003c0000; \ -} while (0) - -/* - * I2C_SCK, I2C_SDA - */ -#define __gpio_as_i2c() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x01800000; \ - REG_GPIO_PXSELS(3) = 0x01800000; \ - REG_GPIO_PXPES(3) = 0x01800000; \ -} while (0) - -/* - * PWM0 - */ -#define __gpio_as_pwm0() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x00800000; \ - REG_GPIO_PXSELC(3) = 0x00800000; \ - REG_GPIO_PXPES(3) = 0x00800000; \ -} while (0) - -/* - * PWM1 - */ -#define __gpio_as_pwm1() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x01000000; \ - REG_GPIO_PXSELC(3) = 0x01000000; \ - REG_GPIO_PXPES(3) = 0x01000000; \ -} while (0) - -/* - * PWM2 - */ -#define __gpio_as_pwm2() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x02000000; \ - REG_GPIO_PXSELC(3) = 0x02000000; \ - REG_GPIO_PXPES(3) = 0x02000000; \ -} while (0) - -/* - * PWM3 - */ -#define __gpio_as_pwm3() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x04000000; \ - REG_GPIO_PXSELC(3) = 0x04000000; \ - REG_GPIO_PXPES(3) = 0x04000000; \ -} while (0) - -/* - * PWM4 - */ -#define __gpio_as_pwm4() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x08000000; \ - REG_GPIO_PXSELC(3) = 0x08000000; \ - REG_GPIO_PXPES(3) = 0x08000000; \ -} while (0) - -/* - * PWM5 - */ -#define __gpio_as_pwm5() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x10000000; \ - REG_GPIO_PXSELC(3) = 0x10000000; \ - REG_GPIO_PXPES(3) = 0x10000000; \ -} while (0) - -/* - * PWM6 - */ -#define __gpio_as_pwm6() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x40000000; \ - REG_GPIO_PXSELC(3) = 0x40000000; \ - REG_GPIO_PXPES(3) = 0x40000000; \ -} while (0) - -/* - * PWM7 - */ -#define __gpio_as_pwm7() \ -do { \ - REG_GPIO_PXFUNS(3) = 0x80000000; \ - REG_GPIO_PXSELC(3) = 0x80000000; \ - REG_GPIO_PXPES(3) = 0x80000000; \ -} while (0) - -/* - * n = 0 ~ 7 - */ -#define __gpio_as_pwm(n) __gpio_as_pwm##n() - -/* GPIO or Interrupt Mode */ - -#define __gpio_get_port(p) (REG_GPIO_PXPIN(p)) - -#define __gpio_port_as_output(p, o) \ -do { \ - REG_GPIO_PXFUNC(p) = (1 << (o)); \ - REG_GPIO_PXSELC(p) = (1 << (o)); \ - REG_GPIO_PXDIRS(p) = (1 << (o)); \ -} while (0) - -#define __gpio_port_as_input(p, o) \ -do { \ - REG_GPIO_PXFUNC(p) = (1 << (o)); \ - REG_GPIO_PXSELC(p) = (1 << (o)); \ - REG_GPIO_PXDIRC(p) = (1 << (o)); \ -} while (0) - -#define __gpio_as_output(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - __gpio_port_as_output(p, o); \ -} while (0) - -#define __gpio_as_input(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - __gpio_port_as_input(p, o); \ -} while (0) - -#define __gpio_set_pin(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXDATS(p) = (1 << o); \ -} while (0) - -#define __gpio_clear_pin(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXDATC(p) = (1 << o); \ -} while (0) - -#define __gpio_get_pin(n) \ -({ \ - unsigned int p, o, v; \ - p = (n) / 32; \ - o = (n) % 32; \ - if (__gpio_get_port(p) & (1 << o)) \ - v = 1; \ - else \ - v = 0; \ - v; \ -}) - -#define __gpio_as_irq_high_level(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXIMS(p) = (1 << o); \ - REG_GPIO_PXTRGC(p) = (1 << o); \ - REG_GPIO_PXFUNC(p) = (1 << o); \ - REG_GPIO_PXSELS(p) = (1 << o); \ - REG_GPIO_PXDIRS(p) = (1 << o); \ - REG_GPIO_PXFLGC(p) = (1 << o); \ - REG_GPIO_PXIMC(p) = (1 << o); \ -} while (0) - -#define __gpio_as_irq_low_level(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXIMS(p) = (1 << o); \ - REG_GPIO_PXTRGC(p) = (1 << o); \ - REG_GPIO_PXFUNC(p) = (1 << o); \ - REG_GPIO_PXSELS(p) = (1 << o); \ - REG_GPIO_PXDIRC(p) = (1 << o); \ - REG_GPIO_PXFLGC(p) = (1 << o); \ - REG_GPIO_PXIMC(p) = (1 << o); \ -} while (0) - -#define __gpio_as_irq_rise_edge(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXIMS(p) = (1 << o); \ - REG_GPIO_PXTRGS(p) = (1 << o); \ - REG_GPIO_PXFUNC(p) = (1 << o); \ - REG_GPIO_PXSELS(p) = (1 << o); \ - REG_GPIO_PXDIRS(p) = (1 << o); \ - REG_GPIO_PXFLGC(p) = (1 << o); \ - REG_GPIO_PXIMC(p) = (1 << o); \ -} while (0) - -#define __gpio_as_irq_fall_edge(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXIMS(p) = (1 << o); \ - REG_GPIO_PXTRGS(p) = (1 << o); \ - REG_GPIO_PXFUNC(p) = (1 << o); \ - REG_GPIO_PXSELS(p) = (1 << o); \ - REG_GPIO_PXDIRC(p) = (1 << o); \ - REG_GPIO_PXFLGC(p) = (1 << o); \ - REG_GPIO_PXIMC(p) = (1 << o); \ -} while (0) - -#define __gpio_mask_irq(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXIMS(p) = (1 << o); \ -} while (0) - -#define __gpio_unmask_irq(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXIMC(p) = (1 << o); \ -} while (0) - -#define __gpio_ack_irq(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXFLGC(p) = (1 << o); \ -} while (0) - -#define __gpio_get_irq() \ -({ \ - unsigned int p, i, tmp, v = 0; \ - for (p = 3; p >= 0; p--) { \ - tmp = REG_GPIO_PXFLG(p); \ - for (i = 0; i < 32; i++) \ - if (tmp & (1 << i)) \ - v = (32*p + i); \ - } \ - v; \ -}) - -#define __gpio_group_irq(n) \ -({ \ - register int tmp, i; \ - tmp = REG_GPIO_PXFLG((n)); \ - for (i=31;i>=0;i--) \ - if (tmp & (1 << i)) \ - break; \ - i; \ -}) - -#define __gpio_enable_pull(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXPEC(p) = (1 << o); \ -} while (0) - -#define __gpio_disable_pull(n) \ -do { \ - unsigned int p, o; \ - p = (n) / 32; \ - o = (n) % 32; \ - REG_GPIO_PXPES(p) = (1 << o); \ -} while (0) - +/* Register operations using absolute positioning have been removed. */ /*************************************************************************** * CPM diff -r 1571da98c6b9 -r 825b572484c6 include/minipc.h --- a/include/minipc.h Tue Jul 11 18:45:08 2017 +0200 +++ b/include/minipc.h Wed Jul 12 15:46:53 2017 +0200 @@ -22,13 +22,26 @@ #ifndef __MINIPC_H__ #define __MINIPC_H__ -/* - * GPIO definition - */ -#define GPIO_LED_EN 92 -#define GPIO_DISP_OFF_N 93 -#define GPIO_PWM0 94 -#define GPIO_POWER 97 +/* GPIO definitions. */ + +#define GPIO_PORT_DMA 0 + +#define GPIO_PORT_LCD 1 +#define GPIO_PORT_MSC 1 + +#define GPIO_PORT_LED 2 +#define GPIO_PORT_PWM 2 + +#define GPIO_LED_EN 28 +#define GPIO_DISP_OFF_N 29 +#define GPIO_PWM0 30 + +#define GPIO_PORT_EMC 2 + +#define GPIO_PORT_POWER 3 +#define GPIO_POWER 1 + +/* Other details. */ #define GPIO_KEYIN_COUNT 8 #define GPIO_KEYOUT_COUNT 17 diff -r 1571da98c6b9 -r 825b572484c6 include/nanonote.h --- a/include/nanonote.h Tue Jul 11 18:45:08 2017 +0200 +++ b/include/nanonote.h Wed Jul 12 15:46:53 2017 +0200 @@ -26,33 +26,68 @@ * GPIO definition * See: http://en.qi-hardware.com/wiki/Hardware_basics */ -#define GPIO_LCD_CS (2 * 32 + 21) -#define GPIO_AMP_EN (3 * 32 + 4) + +#define GPIO_PORT_AUDIO 1 + +#define GPIO_AUDIO_EN 29 /* audio output enable */ +#define GPIO_COB_TEST 30 /* test point TP5 */ + +/* LCD */ + +#define GPIO_PORT_LCD 2 -#define GPIO_SDPW_EN (3 * 32 + 2) -#define GPIO_SD_DETECT (3 * 32 + 0) +#define GPIO_LCD_CS 21 +#define SPEN GPIO_LCD_CS /* serial command enable */ +#define SPDA 22 /* serial command data */ +#define SPCK 23 /* serial command clock */ + +#define GPIO_SLCD8_MASK 0x003c00ff /* SLCD 8-bit pins */ + +/* JTAG */ + +#define GPIO_PORT_JTAG 2 + +#define GPIO_JTAG_UART_EN 31 /* select UART on pad 147 */ + +/* Sound/noise */ + +#define GPIO_PORT_AMP 3 +#define GPIO_PORT_BUZZ 3 -#define GPIO_BUZZ_PWM (3 * 32 + 27) -#define GPIO_USB_DETECT (3 * 32 + 28) +#define GPIO_AMP_EN 4 /* speaker enable */ +#define GPIO_BUZZ_PWM 27 /* buzzer (PWM4) */ + +/* USB */ + +#define GPIO_PORT_USB 3 + +#define GPIO_USB_DETECT 28 + +/* Power */ + +#define GPIO_PORT_POWER 3 -#define GPIO_AUDIO_POP (1 * 32 + 29) -#define GPIO_COB_TEST (1 * 32 + 30) +#define GPIO_POWER 29 /* power button */ + +/* SD/MMC */ + +#define GPIO_PORT_MSC 3 +#define GPIO_PORT_SD 3 + +#define GPIO_SD_DETECT 0 +#define GPIO_SD_CD_N GPIO_SD_DETECT /* SD Card insert detect */ +#define GPIO_SDPW_EN 2 +#define GPIO_SD_VCC_EN_N GPIO_SDPW_EN /* SD Card Power Enable */ +#define GPIO_SD_CMD 8 +#define GPIO_MSC_MASK 0x00003f00 + +/* Other details. */ #define GPIO_KEYIN_COUNT 8 #define GPIO_KEYOUT_COUNT 8 -#define GPIO_POWER (3 * 32 + 29) - -#define GPIO_SD_CD_N GPIO_SD_DETECT /* SD Card insert detect */ -#define GPIO_SD_VCC_EN_N GPIO_SDPW_EN /* SD Card Power Enable */ - -#define GPIO_SD_CMD (3 * 32 + 8) - -#define SPEN GPIO_LCD_CS /* LCDCS :Serial command enable */ -#define SPDA (2 * 32 + 22) /* LCDSCL:Serial command clock input */ -#define SPCK (2 * 32 + 23) /* LCDSDA:Serial command data input */ - -#define GPIO_IRQ IRQ_GPIO3 +#define GPIO_IRQ2 IRQ_GPIO2 /* IRQ for keyboard */ +#define GPIO_IRQ3 IRQ_GPIO3 /* IRQ for power button */ #define GPIO_REGION_SIZE 0x10000 diff -r 1571da98c6b9 -r 825b572484c6 stage1/Makefile --- a/stage1/Makefile Tue Jul 11 18:45:08 2017 +0200 +++ b/stage1/Makefile Wed Jul 12 15:46:53 2017 +0200 @@ -41,8 +41,8 @@ # Ordering of objects is important and cannot be left to replacement rules. -SRC = head1.S stage1.c board.c cpm.c -OBJ = head1.o stage1.o board.o cpm.o +SRC = head1.S stage1.c board.c cpm.c gpio.c +OBJ = head1.o stage1.o board.o cpm.o gpio.o .PHONY: all clean distclean diff -r 1571da98c6b9 -r 825b572484c6 stage1/board.c --- a/stage1/board.c Tue Jul 11 18:45:08 2017 +0200 +++ b/stage1/board.c Wed Jul 12 15:46:53 2017 +0200 @@ -31,6 +31,7 @@ #include "memory.h" #include "sdram.h" #include "cpm.h" +#include "gpio.h" #include "usb_boot_defines.h" /* These arguments are initialised by usbboot and are defined in... @@ -66,21 +67,70 @@ void gpio_init() { + void *gpio_port_base; + #ifdef CONFIG_CPU_JZ4730 /* * Initialize SDRAM pins */ - __gpio_as_emc(); + + /* gpio_as_emc */ + + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_EMC); + + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xC0000000, 0x40000000); + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPAUR, 0x0000FFFF, 0x00005555); #else /* - * Initialize NAND Flash Pins - */ - __gpio_as_nand(); + Initialize NAND Flash Pins (gpio_as_nand) + CS1#, CLE, ALE, FRE#, FWE#, FRB#, RDWE#/BUFD# + */ + + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, 1); + + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, 0x02018000); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x02018000); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, 0x02018000); + + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, 2); + + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, 0x30000000); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x30000000); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, 0x30000000); + + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNC, 0x40000000); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x40000000); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXDIRC, 0x40000000); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, 0x40000000); + + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, 1); + + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, 0x00400000); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x00400000); /* - * Initialize SDRAM pins - */ - __gpio_as_sdram_16bit_4720(); + Initialize SDRAM pins (gpio_as_sdram_16bit_4720) + D0 ~ D15, A0 ~ A16, DCS#, RAS#, CAS#, CKE#, + RDWE#, CKO#, WE0#, WE1# + */ + + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, 0); + + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, 0x5442bfaa); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x5442bfaa); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, 0x5442bfaa); + + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, 1); + + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, 0x81f9ffff); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x81f9ffff); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, 0x81f9ffff); + + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, 2); + + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, 0x01000000); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, 0x01000000); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, 0x01000000); #endif } diff -r 1571da98c6b9 -r 825b572484c6 stage1/gpio.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stage1/gpio.c Wed Jul 12 15:46:53 2017 +0200 @@ -0,0 +1,1 @@ +../stage2/gpio.c \ No newline at end of file diff -r 1571da98c6b9 -r 825b572484c6 stage1/gpio.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stage1/gpio.h Wed Jul 12 15:46:53 2017 +0200 @@ -0,0 +1,1 @@ +../stage2/gpio.h \ No newline at end of file diff -r 1571da98c6b9 -r 825b572484c6 stage2/Makefile --- a/stage2/Makefile Tue Jul 11 18:45:08 2017 +0200 +++ b/stage2/Makefile Wed Jul 12 15:46:53 2017 +0200 @@ -60,7 +60,7 @@ # Configure generic objects. -CORE_SRC = stage2.c cpm.c cpu.c lcd.c jzlcd.c board.c irq.c paging.c tasks.c task_gpio.c +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 CORE_OBJ = $(CORE_SRC:.c=.o) # Add tasks. diff -r 1571da98c6b9 -r 825b572484c6 stage2/board-minipc.c --- a/stage2/board-minipc.c Tue Jul 11 18:45:08 2017 +0200 +++ b/stage2/board-minipc.c Wed Jul 12 15:46:53 2017 +0200 @@ -22,41 +22,52 @@ #include "board.h" #include "minipc.h" +#include "gpio.h" /* Later initialisation functions. */ void gpio_init2() { + void *gpio_port_base; + /* LED enable. */ - __gpio_as_output(GPIO_LED_EN); - __gpio_set_pin(GPIO_LED_EN); + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_LED); + jz4740_gpio_as_output(gpio_port_base, GPIO_LED_EN); + jz4740_gpio_set_pin(gpio_port_base, GPIO_LED_EN); __harb_usb0_uhc(); - __gpio_as_emc(); - __gpio_as_dma(); + + /* gpio_as_emc */ + + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_EMC); + + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xC0000000, 0x40000000); + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPAUR, 0x0000FFFF, 0x00005555); + + /* gpio_as_dma */ + + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_DMA); + + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xFF000000, 0x55000000); + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPAUR, 0x00F00000, 0x00500000); /* Initialise LCD pins. */ - __gpio_as_lcd_master(); + /* gpio_as_lcd_master */ + + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_LCD); + + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0xFFFF0000, 0x55550000); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_GPAUR, 0x556A5555); /* Initialise MSC pins. */ - __gpio_as_msc(); - - /* Initialise other pins. */ - - unsigned short i; + /* gpio_as_msc */ - for (i = 0; i < GPIO_KEYIN_COUNT; i++) { - __gpio_as_input(GPIO_KEYIN_BASE + i); - __gpio_enable_pull(GPIO_KEYIN_BASE + i); - } + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_MSC); - for (i = 0; i < GPIO_KEYOUT_COUNT; i++) { - __gpio_as_output(GPIO_KEYOUT_BASE + i); - __gpio_clear_pin(GPIO_KEYOUT_BASE + i); - } + jz4740_gpio_ctrl_update(gpio_port_base, GPIO_GPALR, 0x0000FFF0, 0x00005550); } void rtc_init() @@ -107,13 +118,15 @@ void gpio_init_irq() { - __gpio_as_irq_low_level(GPIO_POWER); + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, GPIO_PORT_POWER); + jz4740_gpio_as_irq(gpio_port_base, GPIO_POWER, gpio_irq_low_level); __intc_unmask_irq(GPIO_IRQ); } int gpio_have_irq(uint8_t gpio) { - return (REG_GPIO_GPFR(gpio / 32) & (1 << (gpio % 32))); + gpio_port_base = jz4740_get_port((void *) GPIO_BASE, gpio / 32); + return jz4740_gpio_have_irq(gpio_port_base, gpio % 32); } /* Board startup detection. */ diff -r 1571da98c6b9 -r 825b572484c6 stage2/board-nanonote.c --- a/stage2/board-nanonote.c Tue Jul 11 18:45:08 2017 +0200 +++ b/stage2/board-nanonote.c Wed Jul 12 15:46:53 2017 +0200 @@ -23,50 +23,82 @@ #include "board.h" #include "nanonote.h" #include "cpm.h" +#include "gpio.h" /* Later initialisation functions. */ void gpio_init2() { - /* Initialise LCD pins. */ + void *gpio_port_base; - __gpio_as_slcd_8bit(); + /* + Initialise LCD pins. + gpio_as_slcd_8bit: LCD_D0~LCD_D7, SLCD_CLK, SLCD_RS, SLCD_CS, LCD_DE + */ - /* Initialise MSC pins. */ + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LCD); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, GPIO_SLCD8_MASK); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, GPIO_SLCD8_MASK); - __gpio_as_msc(); + /* + Initialise MSC pins. + gpio_as_msc: MSC_CMD, MSC_CLK, MSC_D0 ~ MSC_D3 + */ + + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_MSC); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXFUNS, GPIO_MSC_MASK); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELC, GPIO_MSC_MASK); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXPES, GPIO_MSC_MASK); /* Initialise other pins. */ - /* Enable TP4, TP5 as UART0. */ + /* Enable TP4, TP5 as UART0 (gpio_jtag_to_uart0). */ - __gpio_jtag_to_uart0(); + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_JTAG); + jz4740_gpio_ctrl_set(gpio_port_base, GPIO_PXSELS, 1 << GPIO_JTAG_UART_EN); + + /* Enable pull-up on the power switch. */ - __gpio_as_input(GPIO_POWER); - __gpio_enable_pull(GPIO_POWER); + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_POWER); + jz4740_gpio_as_input(gpio_port_base, GPIO_POWER); + jz4740_gpio_enable_pull(gpio_port_base, GPIO_POWER); + + /* Enable audio output. */ - __gpio_as_output(GPIO_AUDIO_POP); - __gpio_set_pin(GPIO_AUDIO_POP); + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_AUDIO); + jz4740_gpio_as_output(gpio_port_base, GPIO_AUDIO_EN); + jz4740_gpio_set_pin(gpio_port_base, GPIO_AUDIO_EN); - __gpio_as_output(GPIO_LCD_CS); - __gpio_clear_pin(GPIO_LCD_CS); + /* Enable LCD signalling. */ - __gpio_as_output(GPIO_AMP_EN); - __gpio_clear_pin(GPIO_AMP_EN); + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LCD); + jz4740_gpio_as_output(gpio_port_base, GPIO_LCD_CS); + jz4740_gpio_clear_pin(gpio_port_base, GPIO_LCD_CS); + + /* Enable speaker. */ + + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_AMP); + jz4740_gpio_as_output(gpio_port_base, GPIO_AMP_EN); + jz4740_gpio_clear_pin(gpio_port_base, GPIO_AMP_EN); + + /* Disable pull-up on SD pins. */ - __gpio_as_output(GPIO_SDPW_EN); - __gpio_disable_pull(GPIO_SDPW_EN); - __gpio_clear_pin(GPIO_SDPW_EN); + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_SD); + jz4740_gpio_as_output(gpio_port_base, GPIO_SDPW_EN); + jz4740_gpio_disable_pull(gpio_port_base, GPIO_SDPW_EN); + jz4740_gpio_clear_pin(gpio_port_base, GPIO_SDPW_EN); + jz4740_gpio_as_input(gpio_port_base, GPIO_SD_DETECT); + jz4740_gpio_disable_pull(gpio_port_base, GPIO_SD_DETECT); - __gpio_as_input(GPIO_SD_DETECT); - __gpio_disable_pull(GPIO_SD_DETECT); + /* Enable pull-up on USB detect pin. */ - __gpio_as_input(GPIO_USB_DETECT); - __gpio_enable_pull(GPIO_USB_DETECT); + gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_USB); + jz4740_gpio_as_input(gpio_port_base, GPIO_USB_DETECT); + jz4740_gpio_enable_pull(gpio_port_base, GPIO_USB_DETECT); /* Employ a PWM channel for the buzzer. */ - __gpio_as_pwm4(); + jz4740_gpio_as_pwm((void *) GPIO_BASE, 4); } void rtc_init() @@ -132,13 +164,15 @@ void gpio_init_irq() { - __gpio_as_irq_low_level(GPIO_POWER); - __intc_unmask_irq(GPIO_IRQ); + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_POWER); + jz4740_gpio_as_irq(gpio_port_base, GPIO_POWER, gpio_irq_level_low); + __intc_unmask_irq(GPIO_IRQ3); } int gpio_have_irq(uint8_t gpio) { - return (REG_GPIO_PXFLG(gpio / 32) & (1 << (gpio % 32))); + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, gpio / 32); + return jz4740_gpio_have_irq(gpio_port_base, gpio % 32); } /* Board startup detection. */ diff -r 1571da98c6b9 -r 825b572484c6 stage2/board.c --- a/stage2/board.c Tue Jul 11 18:45:08 2017 +0200 +++ b/stage2/board.c Wed Jul 12 15:46:53 2017 +0200 @@ -21,6 +21,7 @@ #include "sdram.h" #include "board.h" +#include "gpio.h" unsigned long get_memory_size() { @@ -161,10 +162,13 @@ void gpio_clear(uint8_t gpio) { + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, gpio / 32); + /* Clear interrupt status. */ - __gpio_ack_irq(gpio); - __intc_ack_irq(GPIO_IRQ); + jz4740_gpio_ack_irq(gpio_port_base, gpio % 32); + __intc_ack_irq(GPIO_IRQ2); + __intc_ack_irq(GPIO_IRQ3); } /* Miscellaneous interrupt administration. */ diff -r 1571da98c6b9 -r 825b572484c6 stage2/lcd.c --- a/stage2/lcd.c Tue Jul 11 18:45:08 2017 +0200 +++ b/stage2/lcd.c Wed Jul 12 15:46:53 2017 +0200 @@ -28,7 +28,7 @@ #include "board.h" extern vidinfo_t panel_info; -static uint32_t lcd_base; +static uint32_t lcd_base; /* the screen memory, not the LCD registers */ @@ -273,16 +273,6 @@ udelay(1000); } -static void lcd_display_pin_init() -{ - __lcd_display_pin_init(); -} - -static void lcd_display_on() -{ - __lcd_display_on(); -} - static void lcd_set_bpp(uint8_t bpp) { jz4740_lcd_set_bpp(bpp, &panel_info); diff -r 1571da98c6b9 -r 825b572484c6 stage2/minipc_claa070vc01.c --- a/stage2/minipc_claa070vc01.c Tue Jul 11 18:45:08 2017 +0200 +++ b/stage2/minipc_claa070vc01.c Wed Jul 12 15:46:53 2017 +0200 @@ -1,5 +1,5 @@ /* - * MiniPC screen details + * MiniPC screen details and panel-specific functions. * * Copyright (C) 2005-2007, Ingenic Semiconductor Inc. * Copyright (C) 2015, 2016, 2017 Paul Boddie @@ -20,9 +20,10 @@ * Boston, MA 02110-1301, USA */ -#include "minipc_claa070vc01.h" +#include "board.h" #include "jzlcd.h" #include "minipc.h" +#include "gpio.h" struct jzfb_info jzfb = { MODE_TFT_GEN | PCLK_N | HSYNC_N | VSYNC_N, @@ -33,3 +34,39 @@ .jz_fb=&jzfb, // this will need correcting for user mode usage .lcd=0, // base address for registers }; + +void lcd_set_backlight_level(uint16_t n) +{ + jz4740_gpio_as_pwm((void *) GPIO_BASE, 0); + REG_PWM_DUT(0) = n; + REG_PWM_PER(0) = 7; + REG_PWM_CTR(0) = 0xc1; +} + +void lcd_close_backlight() +{ + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_PWM); + jz4740_gpio_as_output(gpio_port_base, GPIO_PWM0); + jz4740_gpio_clear_pin(gpio_port_base, GPIO_PWM0); +} + +void lcd_display_pin_init() +{ + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LED); + jz4740_gpio_as_output(gpio_port_base, GPIO_DISP_OFF_N); + lcd_set_backlight_level(8); +} + +void lcd_display_on() +{ + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LED); + jz4740_gpio_set_pin(gpio_port_base, GPIO_DISP_OFF_N); + lcd_set_backlight_level(8); +} + +void lcd_display_off() +{ + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LED); + lcd_close_backlight(); + jz4740_gpio_clear_pin(gpio_port_base, GPIO_DISP_OFF_N); +} diff -r 1571da98c6b9 -r 825b572484c6 stage2/minipc_claa070vc01.h --- a/stage2/minipc_claa070vc01.h Tue Jul 11 18:45:08 2017 +0200 +++ b/stage2/minipc_claa070vc01.h Wed Jul 12 15:46:53 2017 +0200 @@ -2,7 +2,7 @@ * MiniPC panel-specific definitions * * Copyright (C) Xiangfu Liu - * Copyright (C) 2015, 2016 Paul Boddie + * Copyright (C) 2015, 2016, 2017 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -23,39 +23,12 @@ #ifndef __MINIPC_CLAA070VC01_H__ #define __MINIPC_CLAA070VC01_H__ -#include "board.h" -#include "minipc.h" - -static inline void __lcd_set_backlight_level(u16 n) -{ - __gpio_as_pwm(); - REG_PWM_DUT(0) = n; - REG_PWM_PER(0) = 7; - REG_PWM_CTR(0) = 0xc1; -} - -static inline void __lcd_close_backlight() -{ - __gpio_as_output(GPIO_PWM0); - __gpio_clear_pin(GPIO_PWM0); -} +#include -static inline void __lcd_display_pin_init() -{ - __gpio_as_output(GPIO_DISP_OFF_N); - __lcd_set_backlight_level(8); -} - -static inline void __lcd_display_on() -{ - __gpio_set_pin(GPIO_DISP_OFF_N); - __lcd_set_backlight_level(8); -} - -static inline void __lcd_display_off() -{ - __lcd_close_backlight(); - __gpio_clear_pin(GPIO_DISP_OFF_N); -} +void lcd_set_backlight_level(uint16_t n); +void lcd_close_backlight(); +void lcd_display_pin_init(); +void lcd_display_on(); +void lcd_display_off(); #endif /* __MINIPC_CLAA070VC01_H__ */ diff -r 1571da98c6b9 -r 825b572484c6 stage2/nanonote_gpm940b0.c --- a/stage2/nanonote_gpm940b0.c Tue Jul 11 18:45:08 2017 +0200 +++ b/stage2/nanonote_gpm940b0.c Wed Jul 12 15:46:53 2017 +0200 @@ -1,5 +1,5 @@ /* - * Ben NanoNote screen details + * Ben NanoNote screen details and panel-specific functions. * * Copyright (C) Xiangfu Liu * Copyright (C) 2015, 2016, 2017 Paul Boddie @@ -20,9 +20,10 @@ * Boston, MA 02110-1301, USA */ -#include "nanonote_gpm940b0.h" +#include "board.h" #include "jzlcd.h" #include "nanonote.h" +#include "gpio.h" struct jzfb_info jzfb = { .cfg=MODE_8BIT_SERIAL_TFT | PCLK_N | HSYNC_N | VSYNC_N, @@ -38,3 +39,52 @@ .jz_fb=&jzfb, // this will need correcting for user mode usage .lcd=0, // base address for registers }; + +/* Display configuration functions. */ + +static void spi_write_reg1(uint8_t reg, uint8_t val) +{ + uint8_t no; + uint16_t value; + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LCD); + + jz4740_gpio_set_pin(gpio_port_base, SPEN); + jz4740_gpio_set_pin(gpio_port_base, SPCK); + jz4740_gpio_clear_pin(gpio_port_base, SPDA); + jz4740_gpio_clear_pin(gpio_port_base, SPEN); + + value = ((reg << 8) | (val & 0xFF)); + + for (no = 0; no < 16; no++) + { + jz4740_gpio_clear_pin(gpio_port_base, SPCK); + jz4740_gpio_set_value(gpio_port_base, SPDA, value & 0x8000 ? 1 : 0); + jz4740_gpio_set_pin(gpio_port_base, SPCK); + value = (value << 1); + } + + jz4740_gpio_set_pin(gpio_port_base, SPEN); +} + +void lcd_display_pin_init() +{ + void *gpio_port_base = jz4740_gpio_get_port((void *) GPIO_BASE, GPIO_PORT_LCD); + + jz4740_gpio_as_output(gpio_port_base, SPEN); + jz4740_gpio_as_output(gpio_port_base, SPCK); + jz4740_gpio_as_output(gpio_port_base, SPDA); +} + +void lcd_display_on() +{ + spi_write_reg1(0x05, 0x1e); + spi_write_reg1(0x05, 0x5e); + spi_write_reg1(0x07, 0x8d); + spi_write_reg1(0x13, 0x01); + spi_write_reg1(0x05, 0x5f); +} + +void lcd_display_off() +{ + spi_write_reg1(0x05, 0x5e); +} diff -r 1571da98c6b9 -r 825b572484c6 stage2/nanonote_gpm940b0.h --- a/stage2/nanonote_gpm940b0.h Tue Jul 11 18:45:08 2017 +0200 +++ b/stage2/nanonote_gpm940b0.h Wed Jul 12 15:46:53 2017 +0200 @@ -1,5 +1,5 @@ /* - * Ben NanoNote panel-specific definitions + * Ben NanoNote panel-specific definitions. * * Copyright (C) Xiangfu Liu * Copyright (C) 2015, 2016, 2017 Paul Boddie @@ -23,55 +23,8 @@ #ifndef __NANONOTE_GPM940B0_H__ #define __NANONOTE_GPM940B0_H__ -#include "board.h" -#include "nanonote.h" - -static inline void __spi_write_reg1(uint8_t reg, uint8_t val) -{ - uint8_t no, a=reg, b=val; - uint16_t value; - - __gpio_set_pin(SPEN); - __gpio_set_pin(SPCK); - __gpio_clear_pin(SPDA); - __gpio_clear_pin(SPEN); - - value = ((a << 8) | (b & 0xFF)); - - for (no=0; no<16; no++) - { - __gpio_clear_pin(SPCK); - - if ((value & 0x8000) == 0x8000) - __gpio_set_pin(SPDA); - else - __gpio_clear_pin(SPDA); - - __gpio_set_pin(SPCK); - value = (value << 1); - } - __gpio_set_pin(SPEN); -} - -static inline void __lcd_display_pin_init() -{ - __gpio_as_output(SPEN); - __gpio_as_output(SPCK); - __gpio_as_output(SPDA); -} - -static inline void __lcd_display_on() -{ - __spi_write_reg1(0x05, 0x1e); - __spi_write_reg1(0x05, 0x5e); - __spi_write_reg1(0x07, 0x8d); - __spi_write_reg1(0x13, 0x01); - __spi_write_reg1(0x05, 0x5f); -} - -static inline void __lcd_display_off() -{ - __spi_write_reg1(0x05, 0x5e); -} +void lcd_display_pin_init(); +void lcd_display_on(); +void lcd_display_off(); #endif /* __NANONOTE_GPM940B0_H__ */ diff -r 1571da98c6b9 -r 825b572484c6 stage2/task_gpio.c --- a/stage2/task_gpio.c Tue Jul 11 18:45:08 2017 +0200 +++ b/stage2/task_gpio.c Wed Jul 12 15:46:53 2017 +0200 @@ -23,6 +23,7 @@ #include "paging.h" #include "memory.h" #include "task_gpio.h" +#include "gpio.h" void task_gpio_init(uint8_t task) { @@ -41,49 +42,54 @@ void task_gpio_as_input(uint8_t pin) { - TASK_REG_GPIO_PXFUNC(pin / 32) = (1 << (pin % 32)); - TASK_REG_GPIO_PXSELC(pin / 32) = (1 << (pin % 32)); - TASK_REG_GPIO_PXDIRC(pin / 32) = (1 << (pin % 32)); + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32); + jz4740_gpio_as_input(gpio_port_base, pin % 32); } void task_gpio_as_output(uint8_t pin) { - TASK_REG_GPIO_PXFUNC(pin / 32) = (1 << (pin % 32)); - TASK_REG_GPIO_PXSELC(pin / 32) = (1 << (pin % 32)); - TASK_REG_GPIO_PXDIRS(pin / 32) = (1 << (pin % 32)); + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32); + jz4740_gpio_as_output(gpio_port_base, pin % 32); } void task_gpio_enable_pull(uint8_t pin) { - TASK_REG_GPIO_PXPEC(pin / 32) = (1 << (pin % 32)); + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32); + jz4740_gpio_enable_pull(gpio_port_base, pin % 32); } void task_gpio_disable_pull(uint8_t pin) { - TASK_REG_GPIO_PXPES(pin / 32) = (1 << (pin % 32)); + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32); + jz4740_gpio_disable_pull(gpio_port_base, pin % 32); } -inline int task_gpio_get_pin(uint8_t pin) +int task_gpio_get_pin(uint8_t pin) { - return TASK_REG_GPIO_PXPIN(pin / 32) & (1 << (pin % 32)); + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32); + return jz4740_gpio_get_pin(gpio_port_base, pin % 32); } -inline void task_gpio_set_pin(uint8_t pin) +void task_gpio_set_pin(uint8_t pin) { - TASK_REG_GPIO_PXDATS(pin / 32) = (1 << (pin % 32)); + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32); + jz4740_gpio_set_pin(gpio_port_base, pin % 32); } -inline void task_gpio_clear_pin(uint8_t pin) +void task_gpio_clear_pin(uint8_t pin) { - TASK_REG_GPIO_PXDATC(pin / 32) = (1 << (pin % 32)); + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32); + jz4740_gpio_clear_pin(gpio_port_base, pin % 32); } -inline void task_gpio_mask_irq(uint8_t pin) +void task_gpio_mask_irq(uint8_t pin) { - TASK_REG_GPIO_PXIMS(pin / 32) = (1 << (pin % 32)); + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32); + jz4740_gpio_mask_irq(gpio_port_base, pin % 32); } -inline void task_gpio_unmask_irq(uint8_t pin) +void task_gpio_unmask_irq(uint8_t pin) { - TASK_REG_GPIO_PXIMC(pin / 32) = (1 << (pin % 32)); + void *gpio_port_base = jz4740_gpio_get_port((void *) TASK_GPIO_BASE, pin / 32); + jz4740_gpio_unmask_irq(gpio_port_base, pin % 32); } diff -r 1571da98c6b9 -r 825b572484c6 stage2/task_gpio.h --- a/stage2/task_gpio.h Tue Jul 11 18:45:08 2017 +0200 +++ b/stage2/task_gpio.h Wed Jul 12 15:46:53 2017 +0200 @@ -8,58 +8,6 @@ #define GPIO_BASE_PHYSICAL (GPIO_BASE - KSEG1_BASE) -#define TASK_GPIO_PXPIN(n) (TASK_GPIO_BASE + (0x00 + (n)*0x100)) /* PIN Level Register */ - -#define TASK_GPIO_PXDAT(n) (TASK_GPIO_BASE + (0x10 + (n)*0x100)) /* Port Data Register */ -#define TASK_GPIO_PXDATS(n) (TASK_GPIO_BASE + (0x14 + (n)*0x100)) /* Port Data Set Register */ -#define TASK_GPIO_PXDATC(n) (TASK_GPIO_BASE + (0x18 + (n)*0x100)) /* Port Data Clear Register */ - -#define TASK_GPIO_PXIM(n) (TASK_GPIO_BASE + (0x20 + (n)*0x100)) /* Interrupt Mask Register */ -#define TASK_GPIO_PXIMS(n) (TASK_GPIO_BASE + (0x24 + (n)*0x100)) /* Interrupt Mask Set Reg */ -#define TASK_GPIO_PXIMC(n) (TASK_GPIO_BASE + (0x28 + (n)*0x100)) /* Interrupt Mask Clear Reg */ - -#define TASK_GPIO_PXPE(n) (TASK_GPIO_BASE + (0x30 + (n)*0x100)) /* Pull Enable Register */ -#define TASK_GPIO_PXPES(n) (TASK_GPIO_BASE + (0x34 + (n)*0x100)) /* Pull Enable Set Reg. */ -#define TASK_GPIO_PXPEC(n) (TASK_GPIO_BASE + (0x38 + (n)*0x100)) /* Pull Enable Clear Reg. */ - -#define TASK_GPIO_PXFUN(n) (TASK_GPIO_BASE + (0x40 + (n)*0x100)) /* Function Register */ -#define TASK_GPIO_PXFUNS(n) (TASK_GPIO_BASE + (0x44 + (n)*0x100)) /* Function Set Register */ -#define TASK_GPIO_PXFUNC(n) (TASK_GPIO_BASE + (0x48 + (n)*0x100)) /* Function Clear Register */ - -#define TASK_GPIO_PXSEL(n) (TASK_GPIO_BASE + (0x50 + (n)*0x100)) /* Select Register */ -#define TASK_GPIO_PXSELS(n) (TASK_GPIO_BASE + (0x54 + (n)*0x100)) /* Select Set Register */ -#define TASK_GPIO_PXSELC(n) (TASK_GPIO_BASE + (0x58 + (n)*0x100)) /* Select Clear Register */ - -#define TASK_GPIO_PXDIR(n) (TASK_GPIO_BASE + (0x60 + (n)*0x100)) /* Direction Register */ -#define TASK_GPIO_PXDIRS(n) (TASK_GPIO_BASE + (0x64 + (n)*0x100)) /* Direction Set Register */ -#define TASK_GPIO_PXDIRC(n) (TASK_GPIO_BASE + (0x68 + (n)*0x100)) /* Direction Clear Register */ - -#define TASK_REG_GPIO_PXPIN(n) REG32(TASK_GPIO_PXPIN((n))) - -#define TASK_REG_GPIO_PXDAT(n) REG32(TASK_GPIO_PXDAT((n))) -#define TASK_REG_GPIO_PXDATS(n) REG32(TASK_GPIO_PXDATS((n))) -#define TASK_REG_GPIO_PXDATC(n) REG32(TASK_GPIO_PXDATC((n))) - -#define TASK_REG_GPIO_PXIM(n) REG32(TASK_GPIO_PXIM((n))) -#define TASK_REG_GPIO_PXIMS(n) REG32(TASK_GPIO_PXIMS((n))) -#define TASK_REG_GPIO_PXIMC(n) REG32(TASK_GPIO_PXIMC((n))) - -#define TASK_REG_GPIO_PXPE(n) REG32(TASK_GPIO_PXPE((n))) -#define TASK_REG_GPIO_PXPES(n) REG32(TASK_GPIO_PXPES((n))) -#define TASK_REG_GPIO_PXPEC(n) REG32(TASK_GPIO_PXPEC((n))) - -#define TASK_REG_GPIO_PXFUN(n) REG32(TASK_GPIO_PXFUN((n))) -#define TASK_REG_GPIO_PXFUNS(n) REG32(TASK_GPIO_PXFUNS((n))) -#define TASK_REG_GPIO_PXFUNC(n) REG32(TASK_GPIO_PXFUNC((n))) - -#define TASK_REG_GPIO_PXSEL(n) REG32(TASK_GPIO_PXSEL((n))) -#define TASK_REG_GPIO_PXSELS(n) REG32(TASK_GPIO_PXSELS((n))) -#define TASK_REG_GPIO_PXSELC(n) REG32(TASK_GPIO_PXSELC((n))) - -#define TASK_REG_GPIO_PXDIR(n) REG32(TASK_GPIO_PXDIR((n))) -#define TASK_REG_GPIO_PXDIRS(n) REG32(TASK_GPIO_PXDIRS((n))) -#define TASK_REG_GPIO_PXDIRC(n) REG32(TASK_GPIO_PXDIRC((n))) - void task_gpio_init(uint8_t task); void task_gpio_as_input(uint8_t pin); void task_gpio_as_output(uint8_t pin);