⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpio.c.svn-base

📁 realtek的8186芯片ADSL路由AP源代码
💻 SVN-BASE
字号:
/** ----------------------------------------------------------------* Copyright c                  Realtek Semiconductor Corporation, 2003  * All rights reserved.* * Abstract: GPIO driver source code.** History: *  2007/10/22  SH  Merge for Kevin's patch for TR068* ---------------------------------------------------------------*/#if 0	//shlee#include <linux/config.h>#include <linux/string.h>#include <linux/mm.h>#include <linux/module.h>#include <linux/mman.h>#include <linux/ioctl.h>#include <linux/fd.h>#include <linux/init.h>#include <linux/slab.h>#include <asm/io.h>#include <asm/uaccess.h>#include <asm/byteorder.h>#endif	//#if 0#if defined(CONFIG_RTL8670)#include "lx4180.h"#else // 8671#include "lx5280.h"#endif#include "gpio.h"int led0enable=1; //for rtl8185 driverstatic int GPIOdataReg=0;/*Check BD800000 to identify which GPIO pins can be used*/unsigned int get_GPIOMask(void){  unsigned int SICR;#if defined(CONFIG_RTL8670)  unsigned int portMask=0;#else // 8671  unsigned int portMask=0xFFFFFFFF;#endif    SICR = REG32(RT8670_SICR_BASE);#if defined(CONFIG_RTL8671)    /*test if SPI is enabled*/    if (SICR&RT8670_SICR_SPI) { /*SPI is in use*/        portMask &= ~(GPIO_PA2|GPIO_PA1|GPIO_PA0|GPIO_PB7);  //disable A0~2 B7    };#endif    #if defined(CONFIG_RTL8670)    /*test if JTAG is enabled*/    if (SICR&RT8670_SICR_JTAG) { /*JTAG pin is used as GPIO A3-7*/        portMask |= (GPIO_PA7|GPIO_PA6|GPIO_PA5|GPIO_PA4|GPIO_PA3);  //enable portA 3-7    } else { /*JTAG is in use*/        portMask &= ~(GPIO_PA7|GPIO_PA6|GPIO_PA5|GPIO_PA4|GPIO_PA3);  //disable portA 3-7    };#else    /*test if JTAG is enabled*/        //printk("get_GPIOMask: 0x%x\n", SICR);        // Modified by Mason Yu for PPP LED    if (SICR&RT8670_SICR_JTAG) { /*JTAG is in use*/        portMask &= ~(GPIO_PB7|GPIO_PB6|GPIO_PB5|GPIO_PB4|GPIO_PB3);  //disable portB 3-7    };    #endif    /*test if UART is enabled*/    if (SICR&RT8670_SICR_UART) { /*UART is in use*/#if defined(CONFIG_RTL8670)        portMask |= (GPIO_PB6|GPIO_PB5|GPIO_PB4|GPIO_PB3|GPIO_PB2|GPIO_PB1|GPIO_PB0);  //enable PB0~6    } else { /*PCI is in use*/        portMask &= ~(GPIO_PB6|GPIO_PB5|GPIO_PB4|GPIO_PB3|GPIO_PB2|GPIO_PB1|GPIO_PB0);  //disable PB0~6    };#else // 8671        portMask &= ~(GPIO_PB1|GPIO_PB0);  //disable PB 0-1    };#endif        return portMask;}/*Config one GPIO pin. Release 1 only support output functionnumber and PIN location map:Pin	numPA7	15:	:PA0	8PB7	7:	:PB0	0*/void gpioConfig (int gpio_num, int gpio_func){  unsigned int useablePin;  unsigned int mask;      if ((gpio_num>15)||(gpio_num<0)) return;   //pin # error    //if (gpio_func&(GPIO_FUNC_INPUT|GPIO_FUNC_OUTPUT|    //		GPIO_FUNC_IRQ_FALL|GPIO_FUNC_IRQ_RISE|GPIO_FUNC_IRQ_LEVEL)==0) return;   //function error         	         useablePin = get_GPIOMask();    mask=1<<gpio_num;    if ((useablePin&mask)==0) {  //GPIO pins is shared by other modules	printf("RTL8670 GPIO config Error! PIN %d is used by a hardware module\n",gpio_num);        return;    };    if (gpio_num>7) { //PA    	gpio_num=gpio_num-8+16;    	mask=1<<gpio_num;    	        REG32(GPIO_PADIR) = REG32(GPIO_PADIR)|mask;    } else {  //PB    	if ((1<<gpio_num)==GPIO_PB2) {  //1/11/06' hrchen, GPB2 is shared with UART, disable UART first    		unsigned int SICR;            SICR = REG32(RT8670_SICR_BASE);            REG32(RT8670_SICR_BASE) = SICR&(~RT8670_SICR_UART);    	};    	gpio_num=gpio_num+16;    	mask=1<<gpio_num;        REG32(GPIO_PBDIR) = REG32(GPIO_PBDIR)|mask;    };}/*set GPIO pins on*/void gpioSet(int gpio_num){  unsigned int portMask=0;  //unsigned int dataReg;  unsigned int pins;        if ((gpio_num>15)||(gpio_num<0)) return;   //pin # error    //if (gpio_func&(GPIO_FUNC_INPUT|GPIO_FUNC_OUTPUT|    //		GPIO_FUNC_IRQ_FALL|GPIO_FUNC_IRQ_RISE|GPIO_FUNC_IRQ_LEVEL)==0) return;   //function error            pins = 1<<gpio_num;    portMask = get_GPIOMask();    pins &= portMask;  //mask out disable pins    if (pins==0) return;  //no pins to set            //dataReg = (REG32(GPIO_PADAT)>>8)|(REG32(GPIO_PBDAT)>>16);#ifdef CONFIG_TR068    GPIOdataReg |= 0x00200000; //shlee config GPA5 always high for TR068#endif    GPIOdataReg |= pins;  //set pins    //write out    REG32(GPIO_PADAT) = ((GPIOdataReg<< 8)&0x00FF0000);    REG32(GPIO_PBDAT) = ((GPIOdataReg<<16)&0x00FF0000);}/*set GPIO pins off*/void gpioClear(int gpio_num){  unsigned int portMask=0;  //unsigned int dataReg;  unsigned int pins;        if ((gpio_num>15)||(gpio_num<0)) return;   //pin # error    //if (gpio_func&(GPIO_FUNC_INPUT|GPIO_FUNC_OUTPUT|    //		GPIO_FUNC_IRQ_FALL|GPIO_FUNC_IRQ_RISE|GPIO_FUNC_IRQ_LEVEL)==0) return;   //function error                pins = 1<<gpio_num;    portMask = get_GPIOMask();    pins &= portMask;  //mask out disable pins    if (pins==0) return;  //no pins to reset                //dataReg = (REG32(GPIO_PADAT)>>8)|(REG32(GPIO_PBDAT)>>16);    GPIOdataReg &= ~pins;  //reset pins#ifdef CONFIG_TR068    GPIOdataReg |= 0x00002000;  //make GPA5 always high for TR068#endif    //write out    REG32(GPIO_PADAT) = (GPIOdataReg&0x0000FF00)<<8;    REG32(GPIO_PBDAT) = (GPIOdataReg&0x000000FF)<<16;}#ifdef CONFIG_TR068// addition by Kevin Chung 2007/09/19 for TR-068 power LED behaviorvoid gpioTR068(void){//	gpioConfig(POWER_LED_R, GPIO_FUNC_OUTPUT);		//	gpioConfig(POWER_LED_G, GPIO_FUNC_OUTPUT);	//	gpioClear(POWER_LED_R);//	gpioSet(POWER_LED_G);	GPIOdataReg=0x0040;}#endif#if 0 //Remove uncessary part - shlee// Added by Mason Yu for New map LEDvoid gpioHandshaking(int flag){	gpioConfig(ADSL_LED, GPIO_FUNC_OUTPUT);			// on	if ( flag == 1) {		gpioClear(ADSL_LED);		//gpioSet(ADSL_LED);		return;	}			// off	if ( flag == 0) {		gpioSet(ADSL_LED); 		//gpioClear(ADSL_LED);		return;	}}// Added by Mason Yu for New map LEDvoid gpioACT(int flag){		gpioConfig(ADSL_ACT_LED, GPIO_FUNC_OUTPUT);		// on	if ( flag == 1) {		gpioClear(ADSL_ACT_LED);		return;	}			// off	if ( flag == 0) {		gpioSet(ADSL_ACT_LED); 		return;	}}// Added by Mason Yu for New map LEDvoid gpioAlarm(int flag){	gpioConfig(ALARM_LED, GPIO_FUNC_OUTPUT);		// on	if ( flag == 1) {		gpioClear(ALARM_LED);		return;	}			// off	if ( flag == 0) {		gpioSet(ALARM_LED); 		return;	}}#endif //#if 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -