diff --git a/gpio/Makefile b/gpio/Makefile old mode 100644 new mode 100755 index 0a3713a..3b0405f --- a/gpio/Makefile +++ b/gpio/Makefile @@ -48,7 +48,8 @@ ifeq ($(PLATFORM),) #PLATFORM = OrangePi_H3 #PLATFORM = OrangePi_LITE2 #PLATFORM = OrangePi_H3_ZEROPLUS2 - PLATFORM = OrangePi_3 + #PLATFORM = OrangePi_3 + PLATFORM = OrangePi_RK3399 endif ifeq ($(PLATFORM), OrangePi_2G-IOT) @@ -91,6 +92,11 @@ EXTRA_CFLAGS = -DCONFIG_ORANGEPI_H3_ZEROPLUS2 EXTRA_CFLAGS += -DCONFIG_ORANGEPI endif +ifeq ($(PLATFORM), OrangePi_RK3399) +EXTRA_CFLAGS = -DCONFIG_ORANGEPI_RK3399 +EXTRA_CFLAGS += -DCONFIG_ORANGEPI +endif + # May not need to alter anything below this line ############################################################################### @@ -128,6 +134,10 @@ ifeq ($(PLATFORM), OrangePi_H3_ZEROPLUS2) SRC += OrangePi.c endif +ifeq ($(PLATFORM), OrangePi_RK3399) + SRC += OrangePi.c +endif + OBJ = $(SRC:.c=.o) all: gpio diff --git a/gpio/OrangePi.c b/gpio/OrangePi.c old mode 100644 new mode 100755 index a235013..3cdd8f2 --- a/gpio/OrangePi.c +++ b/gpio/OrangePi.c @@ -530,6 +530,95 @@ char *physNames [64] = }; #endif +#ifdef CONFIG_ORANGEPI_RK3399 +int pinToGpioOrangePi [64] = +{ + 43, 44, // 0, 1 + 64, 148, // 2, 3 + 147, 80, // 4 5 + 65, 81, // 6, 7 + 82, 66, // 8, 9 + 67, 39, //10,11 + 40, 83, //12,13 + 41, 42, //14,15 + 133, 154, //16,17 + 50, 68, //18,19 + 69, 76, //20,21 + 70, 71, //22,23 + 73, 72, //24,25 + 74, 75, //26,27 + + -1, -1, //28,29 + -1, -1, //30,31 + + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,// ... 63 +}; +int physToWpi[64] = +{ + -1, // 0 + -1, -1, // 1, 2 + 0, -1, //3, 4 + 1, -1, //5, 6 + 2, 3, //7, 8 + -1, 4, //9,10 + 5, 6, //11,12 + 7, -1, //13,14 + 8, 9, //15,16 + -1, 10, //17,18 + 11, -1, //19,20 + 12, 13, //21,22 + 14, 15, //23, 24 + -1, 16, // 25, 26 + + 17, 18, //27, 28 + 19, -1, //29, 30 + 20, 21, //31, 32 + 22, -1, //33, 34 + 23, 24, //35, 36 + 25, 26, //37, 38 + -1, 27, //39, 40 + // Padding: + + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 56 + -1, -1, -1, -1, -1, -1, -1, // ... 63 +}; + +char *physNames[64] = +{ + NULL, + " 3.3v", "5v ", + " SDA.0", "5V ", + " SCL.0", "0v ", + " GPIO4", "Tx ", + " 0v", "Rx ", + " GPIO17", "GPIO18 ", + " GPIO27", "0v ", + " GPIO22", "GPIO23 ", + " 3.3v", "GPIO24 ", + " MOSI", "0v ", + " MISO", "GPIO25 ", + " SCLK", "CS0 ", + " 0v", "CS1 ", + " DNP1", "DNP2 ", + " GPIO5", "0v ", + " GPIO6", "GPIO12 ", + " GPIO13", "0v ", + " GPIO19", "GPIO16 ", + " GPIO26", "GPIO20 ", + " 0v", "GPIO21 ", + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, +}; +#endif + + /* * ReadAll @@ -551,11 +640,13 @@ void OrangePiReadAll(void) printf (" +------+-----+----------+------+---+OrangePi Win/Win+ +---+---+------+---------+-----+--+\n"); #elif CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 printf (" +------+-----+----------+------+---+OrangePiH6+---+------+----------+-----+------+\n"); +#elif CONFIG_ORANGEPI_RK3399 + printf (" +------+-----+----------+------+---+OrangePi RK3399---+---+------+---------+-----+--+\n"); #endif printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n"); printf (" +------+-----+----------+------+---+----++----+---+------+----------+-----+------+\n"); -#ifdef CONFIG_ORANGEPI_H3 +#if defined CONFIG_ORANGEPI_H3 || defined CONFIG_ORANGEPI_RK3399 for (pin = 1 ; pin <= 42 ; pin += 2) #else CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_H3_ZEROPLUS2 || CONFIG_ORANGEPI_3 for (pin = 1 ; pin <= 26 ; pin += 2) @@ -576,6 +667,10 @@ void OrangePiReadAll(void) printf (" +------+-----+----------+------+---+OrangePi Win/Win+ +---+------+----------+-----+-----+\n"); #elif CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 printf (" +------+-----+----------+------+---+OrangePiH6+---+------+----------+-----+------+\n"); +#elif CONFIG_ORANGEPI_RK3399 + printf (" +------+-----+----------+------+---+OrangePi RK3399---+---+------+---------+-----+--+\n"); + + #endif wiringPiDebug = tmp; } diff --git a/gpio/gpio.c b/gpio/gpio.c old mode 100644 new mode 100755 index b4fb97e..01258f1 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -500,6 +500,10 @@ static void doExports (UNU int argc, UNU char *argv []) // Try to read the direction #ifdef CONFIG_ORANGEPI i = pinToGpioOrangePi[j]; +#ifdef CONFIG_ORANGEPI_RK3399 + i += 1000; +#endif + #endif sprintf (fName, "/sys/class/gpio/gpio%d/direction", i) ; @@ -589,6 +593,10 @@ void doExport (int argc, char *argv []) pin = atoi (argv [2]) ; #ifdef CONFIG_ORANGEPI pin = pinToGpioOrangePi[pin]; +#ifdef CONFIG_ORANGEPI_RK3399 + pin += 1000; +#endif + #endif mode = argv [3] ; @@ -706,6 +714,10 @@ void doEdge (int argc, char *argv []) pin = atoi (argv [2]) ; #ifdef CONFIG_ORANGEPI pin = pinToGpioOrangePi[pin]; +#ifdef CONFIG_ORANGEPI_RK3399 + pin += 1000; +#endif + #endif mode = argv [3] ; @@ -780,6 +792,10 @@ void doUnexport (int argc, char *argv []) pin = atoi (argv [2]) ; #ifdef CONFIG_ORANGEPI pin = pinToGpioOrangePi[pin]; +#ifdef CONFIG_ORANGEPI_RK3399 + pin += 1000; +#endif + #endif if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL) @@ -811,6 +827,10 @@ void doUnexportall (char *progName) { #ifdef CONFIG_ORANGEPI i = pinToGpioOrangePi[pin]; +#ifdef CONFIG_ORANGEPI_RK3399 + i += 1000; +#endif + #endif if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL) { diff --git a/wiringPi/Makefile b/wiringPi/Makefile old mode 100644 new mode 100755 index 41b53d1..edd7100 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -52,7 +52,8 @@ ifeq ($(PLATFORM),) #PLATFORM = OrangePi_LITE2 #PLATFORM = OrangePi_ZERO #PLATFORM = OrangePi_H3_ZEROPLUS2 - PLATFORM = OrangePi_3 + #PLATFORM = OrangePi_3 + PLATFORM = OrangePi_RK3399 endif ifeq ($(PLATFORM), OrangePi_2G-IOT) @@ -95,6 +96,11 @@ EXTRA_CFLAGS = -DCONFIG_ORANGEPI_H3_ZEROPLUS2 EXTRA_CFLAGS += -DCONFIG_ORANGEPI endif +ifeq ($(PLATFORM), OrangePi_RK3399) +EXTRA_CFLAGS = -DCONFIG_ORANGEPI_RK3399 +EXTRA_CFLAGS += -DCONFIG_ORANGEPI +endif + ############################################################################### SRC = wiringPi.c \ @@ -148,6 +154,10 @@ ifeq ($(PLATFORM), OrangePi_H3_ZEROPLUS2) SRC += OrangePi.c endif +ifeq ($(PLATFORM), OrangePi_RK3399) +SRC += OrangePi.c +endif + HEADERS = $(shell ls *.h) OBJ = $(SRC:.c=.o) diff --git a/wiringPi/OrangePi.c b/wiringPi/OrangePi.c old mode 100644 new mode 100755 index 20ac0a8..10abd09 --- a/wiringPi/OrangePi.c +++ b/wiringPi/OrangePi.c @@ -762,6 +762,108 @@ int ORANGEPI_PIN_MASK[12][32] = //[BANK] [INDEX] #endif +#ifdef CONFIG_ORANGEPI_RK3399 +int pinToGpioOrangePi[64] = +{ + 43, 44, // 0, 1 + 64, 148, // 2, 3 + 147, 80, // 4 5 + 65, 81, // 6, 7 + 82, 66, // 8, 9 + 67, 39, //10,11 + 40, 83, //12,13 + 41, 42, //14,15 + 133, 154, //16,17 + 50, 68, //18,19 + 69, 76, //20,21 + 70, 71, //22,23 + 73, 72, //24,25 + 74, 75, //26,27 + + -1, -1, //28,29 + -1, -1, //30,31 + + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,// ... 63 +}; + +int physToGpioOrangePi[64] =//head num map to OrangePi +{ + -1, // 0 + -1, -1, // 1, 2 + 43, -1, // 3, 4 + 44, -1, // 5, 6 + 64, 148, // 7, 8 + -1, 147, // 9, 10 + 80, 65, // 11, 12 + 81, -1, // 13, 14 + 82, 66, // 15, 16 + -1, 67, // 17, 18 + 39, -1, // 19, 20 + 40, 83, // 21, 22 + 41, 42, // 23, 24 + -1, 133, // 25, 26 + 154, 50, // 27, 28 + 68, -1, // 29, 30 + 69, 76, // 31, 32 + 70, -1, // 33, 34 + 71, 73, // 35, 36 + 72, 74, // 37, 38 + -1, 75, // 39, 40 +// Padding: + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 56 + -1, -1, -1, -1, -1, -1, -1, // ... 63 +}; + +int physToPinOrangePi[64] = //return wiringPI pin +{ + -1, // 0 + -1, -1, // 1, 2 + 0, -1, //3, 4 + 1, -1, //5, 6 + 2, 3, //7, 8 + -1, 4, //9,10 + 5, 6, //11,12 + 7, -1, //13,14 + 8, 9, //15,16 + -1, 10, //17,18 + 11, -1, //19,20 + 12, 13, //21,22 + 14, 15, //23, 24 + -1, 16, // 25, 26 + + 17, 18, //27, 28 + 19, -1, //29, 30 + 20, 21, //31, 32 + 22, -1, //33, 34 + 23, 24, //35, 36 + 25, 26, //37, 38 + -1, 27, //39, 40 +// Padding: + + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 56 + -1, -1, -1, -1, -1, -1, -1, // ... 63 +}; + int ORANGEPI_PIN_MASK[5][32] = //[BANK] [INDEX] + { + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//PA + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//PB + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//PC + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//PD + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},//PD + }; + +volatile uint32_t *gpio2_base; +volatile uint32_t *cru_base; +volatile uint32_t *grf_base; +volatile uint32_t *pmugrf_base; +volatile uint32_t *pmucru_base; +volatile uint32_t *gpio1_base; +volatile uint32_t *gpio4_base; +#endif /* CONFIG_ORANGEPI_RK3399 */ +// add 2019.1.8 + + /* * Data for use with the boardId functions. @@ -823,6 +925,27 @@ unsigned int readR(unsigned int addr) else /* Group A, B and D */ val = *((char *)OrangePi_gpio + mmap_seek); return val; +#elif CONFIG_ORANGEPI_RK3399 + unsigned int val = 0; + unsigned int mmap_base = (addr & ~MAP_MASK); + unsigned int mmap_seek = (addr - mmap_base); + if(mmap_base == CRU_BASE) + val = *((unsigned int *)((unsigned char *)cru_base + mmap_seek)); + else if(mmap_base == GRF_BASE) + val = *((unsigned int *)((unsigned char *)grf_base + mmap_seek)); + else if(mmap_base == GPIO2_BASE) + val = *((unsigned int *)((unsigned char *)gpio2_base + mmap_seek)); + else if(mmap_base == GPIO1_BASE) + val = *((unsigned int *)((unsigned char *)gpio1_base + mmap_seek)); + else if(mmap_base == PMUCRU_BASE) + val = *((unsigned int *)((unsigned char *)pmucru_base + mmap_seek)); + else if(mmap_base == PMUGRF_BASE) + val = *((unsigned int *)((unsigned char *)pmugrf_base + mmap_seek)); + else if(mmap_base == GPIO4_BASE) + val = *((unsigned int *)((unsigned char *)gpio4_base + mmap_seek)); + else ; + return val; + #else uint32_t val = 0; uint32_t mmap_base = (addr & ~MAP_MASK); @@ -849,6 +972,26 @@ void writeR(unsigned int val, unsigned int addr) *((char *)OrangePi_gpioC + mmap_seek) = val; else *((char *)OrangePi_gpio + mmap_seek) = val; + +#elif CONFIG_ORANGEPI_RK3399 + unsigned int mmap_base = (addr & ~MAP_MASK); + unsigned int mmap_seek = (addr - mmap_base); + if(mmap_base == CRU_BASE) + *((unsigned int *)((unsigned char *)cru_base + mmap_seek)) = val; + else if(mmap_base == GRF_BASE) + *((unsigned int *)((unsigned char *)grf_base + mmap_seek)) = val; + else if(mmap_base == GPIO2_BASE) + *((unsigned int *)((unsigned char *)gpio2_base + mmap_seek)) = val; + else if(mmap_base == GPIO1_BASE) + *((unsigned int *)((unsigned char *)gpio1_base + mmap_seek)) = val; + else if(mmap_base == PMUCRU_BASE) + *((unsigned int *)((unsigned char *)pmucru_base + mmap_seek)) = val; + else if(mmap_base == PMUGRF_BASE) + *((unsigned int *)((unsigned char *)pmugrf_base + mmap_seek)) = val; + else if(mmap_base == GPIO4_BASE) + *((unsigned int *)((unsigned char *)gpio4_base + mmap_seek)) = val; + else ; + #else unsigned int mmap_base = (addr & ~MAP_MASK); unsigned int mmap_seek = ((addr - mmap_base) >> 2); @@ -998,6 +1141,34 @@ int OrangePi_get_gpio_mode(int pin) unsigned int index = pin - (bank << 5); //算出 pin 属于组中的第多少个 unsigned int phyaddr = 0; unsigned char mode = -1; + +#ifdef CONFIG_ORANGEPI_RK3399 + unsigned int grf_phyaddr = 0, ddr_phyaddr = 0; + int offset = ((index - ((index >> 3) << 3))); + if(bank == 1){ + grf_phyaddr = PMUGRF_BASE + ((index >> 3) << 2) + 0x10; + ddr_phyaddr = GPIO1_BASE + GPIO_SWPORTA_DDR_OFFSET; + } + else if(bank == 2){ + grf_phyaddr = GRF_BASE + ((index >> 3) << 2); + ddr_phyaddr = GPIO2_BASE + GPIO_SWPORTA_DDR_OFFSET; + } + else if(bank == 4){ + grf_phyaddr = GRF_BASE + ((index >> 3) << 2) +0x20; + ddr_phyaddr = GPIO4_BASE + GPIO_SWPORTA_DDR_OFFSET; + } + else ; + if (ORANGEPI_PIN_MASK[bank-1][index] != -1) { + regval = readR(grf_phyaddr); + mode = (regval >> (offset << 1)) & 0x3; + if(mode == 0){ + regval = readR(ddr_phyaddr); + return (regval >> index) & 1; + } + return mode + 1; + } + +#else int offset = ((index - ((index >> 3) << 3)) << 2); @@ -1014,6 +1185,8 @@ int OrangePi_get_gpio_mode(int pin) } return mode; + +#endif } /* @@ -1027,6 +1200,9 @@ int OrangePi_set_gpio_mode(int pin, int mode) unsigned int phyaddr = 0; #ifdef CONFIG_ORANGEPI_2G_IOT unsigned int base_address = 0; +#elif CONFIG_ORANGEPI_RK3399 + int offset = ((index - ((index >> 3) << 3))); + unsigned int cru_phyaddr, grf_phyaddr, gpio_phyaddr; #else int offset = ((index - ((index >> 3) << 3)) << 2); @@ -1056,10 +1232,29 @@ int OrangePi_set_gpio_mode(int pin, int mode) phyaddr = base_address + OEN_SET_OUT_REGISTER; else printf("Invalid mode\n"); +#elif CONFIG_ORANGEPI_RK3399 + if(bank == 1){ + cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_OFFSET; + grf_phyaddr = PMUGRF_BASE + ((index >> 3) << 2) + 0x10; + gpio_phyaddr = GPIO1_BASE + GPIO_SWPORTA_DDR_OFFSET; + } + + else if(bank == 2){ + cru_phyaddr = CRU_BASE + CRU_CLKGATE_CON31_OFFSET; + grf_phyaddr = GRF_BASE + ((index >> 3) << 2); + gpio_phyaddr = GPIO2_BASE + GPIO_SWPORTA_DDR_OFFSET; + } + else if(bank == 4){ + cru_phyaddr = CRU_BASE + CRU_CLKGATE_CON31_OFFSET; + grf_phyaddr = GRF_BASE + ((index >> 3) << 2) +0x20; + gpio_phyaddr = GPIO4_BASE + GPIO_SWPORTA_DDR_OFFSET; + } + else; + #endif /* Ignore unused gpio */ if (ORANGEPI_PIN_MASK[bank][index] != -1) { -#ifndef CONFIG_ORANGEPI_2G_IOT +#if ! (defined CONFIG_ORANGEPI_2G_IOT || defined CONFIG_ORANGEPI_RK3399) regval = readR(phyaddr); if (wiringPiDebug) printf("Before read reg val: 0x%x offset:%d\n",regval,offset); @@ -1071,6 +1266,20 @@ int OrangePi_set_gpio_mode(int pin, int mode) if(INPUT == mode) { #ifdef CONFIG_ORANGEPI_2G_IOT writeR(GPIO_BIT(index), phyaddr); + +#elif CONFIG_ORANGEPI_RK3399 + writeR(0xffff0180, cru_phyaddr); + regval = readR(grf_phyaddr); + regval |= 0xffff << 16; + regval &= ~(0x3) << (offset << 1); + writeR(regval, grf_phyaddr); + regval = readR(gpio_phyaddr); + regval &= ~(1 << index); + writeR(regval, gpio_phyaddr); + if (wiringPiDebug){ + regval = readR(gpio_phyaddr); + printf("Input mode set over reg val: %#x\n",regval); + } #else regval &= ~(7 << offset); writeR(regval, phyaddr); @@ -1083,6 +1292,21 @@ int OrangePi_set_gpio_mode(int pin, int mode) writeR(GPIO_BIT(index), phyaddr); /* Set default value as 0 */ writeR(GPIO_BIT(index), base_address + CLR_REGISTER); +#elif CONFIG_ORANGEPI_RK3399 + writeR(0xffff0180, cru_phyaddr); + regval = readR(grf_phyaddr); + regval |= 0xffff << 16; + regval &= ~(0x3) << (offset << 1); + writeR(regval, grf_phyaddr); + regval = readR(gpio_phyaddr); + regval |= 1 << index; + writeR(regval, gpio_phyaddr); + if (wiringPiDebug){ + regval = readR(gpio_phyaddr); + printf("Out mode get value: 0x%x\n",regval); + } + + #else regval &= ~(7 << offset); regval |= (1 << offset); @@ -1133,6 +1357,11 @@ int OrangePi_digitalWrite(int pin, int value) unsigned int phyaddr = 0; #ifdef CONFIG_ORANGEPI_2G_IOT unsigned int base_address = 0; + +#elif CONFIG_ORANGEPI_RK3399 + unsigned int regval = 0; + unsigned int cru_phyaddr = 0; + #else unsigned int regval = 0; @@ -1164,7 +1393,9 @@ int OrangePi_digitalWrite(int pin, int value) close(fd); return 0; } + #endif + #ifdef CONFIG_ORANGEPI_2G_IOT /* Offset of register */ if (bank == 0) /* group A */ @@ -1184,13 +1415,32 @@ int OrangePi_digitalWrite(int pin, int value) phyaddr = base_address + SET_REGISTER; else printf("Invalid value\n"); + +#elif CONFIG_ORANGEPI_RK3399 + if(bank == 1){ + phyaddr = GPIO1_BASE + GPIO_SWPORTA_DR_OFFSET; + cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_OFFSET; + } + else if(bank == 2){ + phyaddr = GPIO2_BASE + GPIO_SWPORTA_DR_OFFSET; + cru_phyaddr = CRU_BASE + CRU_CLKGATE_CON31_OFFSET; + } + else if(bank == 4){ + phyaddr = GPIO4_BASE + GPIO_SWPORTA_DR_OFFSET; + cru_phyaddr = CRU_BASE + CRU_CLKGATE_CON31_OFFSET; + } + else; #endif /* Ignore unused gpio */ if (ORANGEPI_PIN_MASK[bank][index] != -1) { #ifdef CONFIG_ORANGEPI_2G_IOT writeR(GPIO_BIT(index), phyaddr); + #else + #ifdef CONFIG_ORANGEPI_RK3399 + writeR(0xffff0180, cru_phyaddr); + #endif regval = readR(phyaddr); if (wiringPiDebug) printf("befor write reg val: 0x%x,index:%d\n", regval, index); @@ -1221,7 +1471,8 @@ int OrangePi_digitalRead(int pin) int bank = pin >> 5; int index = pin - (bank << 5); int val; -#ifndef CONFIG_ORANGEPI_2G_IOT +#if ! (defined CONFIG_ORANGEPI_2G_IOT || defined CONFIG_ORANGEPI_RK3399) + unsigned int phyaddr; if (bank == 11) { @@ -1256,9 +1507,21 @@ int OrangePi_digitalRead(int pin) phys_OEN_R = base_address + OEN_VAL_REGISTER; phys_SET_R = base_address + SET_REGISTER; phys_VAL_R = base_address + VAL_REGISTER; + +#elif CONFIG_ORANGEPI_RK3399 + unsigned int phyaddr; + if(bank == 1) + phyaddr = GPIO1_BASE + GPIO_SWPORTA_DR_OFFSET; + else if(bank == 2) + phyaddr = GPIO2_BASE + GPIO_SWPORTA_DR_OFFSET; + else if(bank == 4) + phyaddr = GPIO4_BASE + GPIO_SWPORTA_DR_OFFSET; + else; + #endif if (ORANGEPI_PIN_MASK[bank][index] != -1) { #ifndef CONFIG_ORANGEPI_2G_IOT + val = readR(phyaddr); val = val >> index; val &= 1; @@ -1302,6 +1565,11 @@ int isOrangePi(void) #elif CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 /* Support: OrangePi zero */ char *OrangePi_string = "sun50iw6"; +#elif CONFIG_ORANGEPI_RK3399 + /* Support: OrangePi RK3399 */ + char *OrangePi_string = "rk3399"; + + #else /* Non-support */ char *OrangePi_string = "none"; @@ -1316,6 +1584,11 @@ int isOrangePi(void) } fclose(cpuFd); + +#ifdef CONFIG_ORANGEPI_RK3399 + strcpy(line, "Hardware : Rockchip rk3399 Family"); +#endif + if (strncmp(line, "Hardware", 8) != 0) piGpioLayoutOops("No \"Hardware\" line"); diff --git a/wiringPi/OrangePi.h b/wiringPi/OrangePi.h old mode 100644 new mode 100755 index eaedec2..0433947 --- a/wiringPi/OrangePi.h +++ b/wiringPi/OrangePi.h @@ -76,6 +76,56 @@ #define GPIO_PWM_OP (0x0300A000) #endif +/*********** OrangePi RK3399 *************/ +#ifdef CONFIG_ORANGEPI_RK3399 + +#define GPIO1_BASE 0xff730000 +#define GPIO2_BASE 0xff780000 +#define GPIO4_BASE 0xff790000 +#define GPIO_NUM (0x40) +#define GPIO_BIT(x) (1UL << (x)) +#define GPIO_SWPORTA_DR_OFFSET 0x00 +#define GPIO_SWPORTA_DDR_OFFSET 0x04 + +#define PMUGRF_BASE 0xff320000 +#define PMUGRF_GPIO1A_IOMUX 0x00010 +#define PMUGRF_GPIO1B_IOMUX 0x00014 +#define PMUGRF_GPIO1C_IOMUX 0x00018 +#define PMUGRF_GPIO1D_IOMUX 0x0001c + +#define GRF_BASE 0xff77e000 +#define GRF_GPIO2A_IOMUX_OFFSET 0x00 +#define GRF_GPIO2B_IOMUX_OFFSET 0x04 +#define GRF_GPIO2C_IOMUX_OFFSET 0x08 +#define GRF_GPIO2D_IOMUX_OFFSET 0x0c + +#define GRF_GPIO4A_IOMUX_OFFSET 0x20 +#define GRF_GPIO4B_IOMUX_OFFSET 0x24 +#define GRF_GPIO4C_IOMUX_OFFSET 0x28 +#define GRF_GPIO4D_IOMUX_OFFSET 0x2c + + +#define CRU_BASE 0xff760000 +#define PMUCRU_BASE 0xff750000 +#define CRU_CLKGATE_CON31_OFFSET 0x037c //bit 3 4 5 +#define PMUCRU_CLKGATE_CON1_OFFSET 0x0104 + +#define MEM_INFO (2048) +#define MAP_SIZE_L (4*1024) + +extern volatile unsigned int *gpio2_base; +extern volatile unsigned int *grf_base; +extern volatile unsigned int *cru_base; +extern volatile unsigned int *pmucru_base; +extern volatile unsigned int *pmugrf_base; +extern volatile unsigned int *gpio1_base; +extern volatile unsigned int *gpio4_base; + +#endif /* CONFIG_ORANGEPI_RK3399 */ +//csy 2019.1.8 + + + /****************** Global data *********************/ /* Current version */ #define PI_MAKER_ORANGEPI 4 @@ -158,5 +208,8 @@ extern int ORANGEPI_PIN_MASK[12][32]; extern int ORANGEPI_PIN_MASK[9][32]; #elif CONFIG_ORANGEPI_ZERO || CONFIG_ORANGEPI_H3_ZEROPLUS2 extern int ORANGEPI_PIN_MASK[12][32]; +#elif CONFIG_ORANGEPI_RK3399 +extern int ORANGEPI_PIN_MASK[5][32]; + #endif #endif diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c old mode 100644 new mode 100755 index 7704ba6..cfc1587 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -774,6 +774,11 @@ int piGpioLayout (void) if (strncmp (line, "Hardware", 8) == 0) break ; + +#ifdef CONFIG_ORANGEPI_RK3399 + strcpy(line, "Hardware : Rockchip rk3399 Family"); +#endif + if (strncmp (line, "Hardware", 8) != 0) piGpioLayoutOops ("No \"Hardware\" line") ; @@ -781,12 +786,17 @@ int piGpioLayout (void) printf ("piGpioLayout: Hardware: %s\n", line) ; rewind (cpuFd) ; - while (fgets (line, 120, cpuFd) != NULL) + + while (fgets (line, 120, cpuFd) != NULL) if (strncmp (line, "Revision", 8) == 0) break ; fclose (cpuFd) ; +#ifdef CONFIG_ORANGEPI_RK3399 + strcpy(line, "Revision : 0000"); +#endif + if (strncmp (line, "Revision", 8) != 0) piGpioLayoutOops ("No \"Revision\" line") ; @@ -949,6 +959,9 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) break ; fclose (cpuFd) ; +#ifdef CONFIG_ORANGEPI_RK3399 + strcpy(line, "Revision : 0000"); +#endif if (strncmp (line, "Revision", 8) != 0) piGpioLayoutOops ("No \"Revision\" line") ; @@ -2347,6 +2360,7 @@ int wiringPiSetup (void) return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno)); #else +#ifndef CONFIG_ORANGEPI_RK3399 /* GPIO */ #ifdef CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_BASE); @@ -2370,7 +2384,40 @@ int wiringPiSetup (void) if ((int32_t)(unsigned long)OrangePi_gpioC == -1) return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno)); +#else /* CONFIG_ORANGEPI_RK3399 */ + gpio2_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO2_BASE); + if ((int32_t)(unsigned long)gpio2_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (GPIO2_BASE) failed: %s\n", strerror(errno)); + cru_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CRU_BASE); + if ((int32_t)(unsigned long)cru_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (CRU_BASE) failed: %s\n", strerror(errno)); + pmucru_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, PMUCRU_BASE); + if ((int32_t)(unsigned long)pmucru_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (PMUCRU_BASE) failed: %s\n", strerror(errno)); + grf_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GRF_BASE); + if ((int32_t)(unsigned long)grf_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (GRF_BASE) failed: %s\n", strerror(errno)); + pmugrf_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, PMUGRF_BASE); + if ((int32_t)(unsigned long)pmugrf_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (PMUGRF_BASE) failed: %s\n", strerror(errno)); + gpio1_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO1_BASE); + if ((int32_t)(unsigned long)grf_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (GPIO1_BASE) failed: %s\n", strerror(errno)); + gpio4_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO4_BASE); + if ((int32_t)(unsigned long)gpio4_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (GPIO4_BASE) failed: %s\n", strerror(errno)); + + + #endif +#endif /* CONFIG_ORANGEPI_RK3399 */ #endif #else