用很笨的思路封装了6410 驱动中的io 操作
#include <mach/gpio-bank-e.h>
#include <mach/gpio-bank-m.h>
#include <mach/gpio-bank-a.h>
#include <mach/gpio-bank-b.h>
#include <mach/gpio-bank-c.h>
#include <mach/gpio-bank-d.h>
#include <mach/gpio-bank-e.h>
#include <mach/gpio-bank-f.h>
#include <mach/gpio-bank-g.h>
#include <mach/gpio-bank-h.h>
#include <mach/gpio-bank-i.h>
#include <mach/gpio-bank-j.h>
#include <mach/gpio-bank-k.h>
#include <mach/gpio-bank-m.h>
#include <mach/gpio-bank-n.h>
#include <mach/gpio-bank-o.h>
#include <mach/gpio-bank-p.h>
#include <mach/gpio-bank-q.h>
/*set the data of the 6410IO
IO_id: A-Q exceptedL
IO_number: 0-x
status: 0:low 1:high
return:ture:0 failed:-EINVAL
*/
int s3c6410_ioSetData(char IO_id ,unsigned char IO_number,unsigned char status )
{
unsigned tmp;
switch(IO_id)
{
case 'A':tmp=readl(S3C64XX_GPADAT);break;
case 'B':tmp=readl(S3C64XX_GPBDAT);break;
case 'C':tmp=readl(S3C64XX_GPCDAT);break;
case 'D':tmp=readl(S3C64XX_GPDDAT);break;
case 'E':tmp=readl(S3C64XX_GPEDAT);break;
case 'F':tmp=readl(S3C64XX_GPFDAT);break;
case 'G':tmp=readl(S3C64XX_GPGDAT);break;
case 'H':tmp=readl(S3C64XX_GPHDAT);break;
case 'I':tmp=readl(S3C64XX_GPIDAT);break;
case 'J':tmp=readl(S3C64XX_GPJDAT);break;
case 'K':tmp=readl(S3C64XX_GPKDAT);break;
case 'L':break;
case 'M':tmp=readl(S3C64XX_GPMDAT);break;
case 'N':tmp=readl(S3C64XX_GPNDAT);break;
case 'O':tmp=readl(S3C64XX_GPODAT);break;
case 'P':tmp=readl(S3C64XX_GPPDAT);break;
case 'Q':tmp=readl(S3C64XX_GPQDAT);break;
default :return -EINVAL;break;
}
switch(status)
{
case 0:tmp &= (~(1<<IO_number));break;
case 1:tmp |= (1<<IO_number);break;
default:return -EINVAL;break;
}
switch(IO_id)
{
case 'A':writel(tmp,S3C64XX_GPADAT);break;
case 'B':writel(tmp,S3C64XX_GPBDAT);break;
case 'C':writel(tmp,S3C64XX_GPCDAT);break;
case 'D':writel(tmp,S3C64XX_GPDDAT);break;
case 'E':writel(tmp,S3C64XX_GPEDAT);break;
case 'F':writel(tmp,S3C64XX_GPFDAT);break;
case 'G':writel(tmp,S3C64XX_GPGDAT);break;
case 'H':writel(tmp,S3C64XX_GPHDAT);break;
case 'I':writel(tmp,S3C64XX_GPIDAT);break;
case 'J':writel(tmp,S3C64XX_GPJDAT);break;
case 'K':writel(tmp,S3C64XX_GPKDAT);break;
case 'L':break;
case 'M':writel(tmp,S3C64XX_GPMDAT);break;
case 'N':writel(tmp,S3C64XX_GPNDAT);break;
case 'O':writel(tmp,S3C64XX_GPODAT);break;
case 'P':writel(tmp,S3C64XX_GPPDAT);break;
case 'Q':writel(tmp,S3C64XX_GPQDAT);break;
default :return -EINVAL;break;
}
return 0;
}
/*set the direction of the 6410IO
IO_id: 'A'-'Q' exceptedL
IO_number: 0-x
status: 0:input 1:output
return:ture:0 failed:-EINVAL
*/
int s3c6410_ioSetDir(char IO_id ,unsigned char IO_number,unsigned char status )
{
unsigned tmp=0;
unsigned char n=0;
switch(IO_id)
{
case 'A':n=1;tmp=readl(S3C64XX_GPACON);break;
case 'B':n=2;tmp=readl(S3C64XX_GPBCON);break;
case 'C':n=3;tmp=readl(S3C64XX_GPCCON);break;
case 'D':n=4;tmp=readl(S3C64XX_GPDCON);break;
case 'E':n=5;tmp=readl(S3C64XX_GPECON);break;
case 'F':n=6;tmp=readl(S3C64XX_GPFCON);break;
case 'G':n=7;tmp=readl(S3C64XX_GPGCON);break;
case 'H':n=8;if(IO_number<=7) tmp=readl(S3C64XX_GPHCON0) else tmp=readl(S3C64XX_GPHCON1);break;
case 'I':n=9;tmp=readl(S3C64XX_GPICON);break;
case 'J':n=10;tmp=readl(S3C64XX_GPJCON);break;
case 'K':n=11;tmp=readl(S3C64XX_GPKCON);break;
case 'L':n=12;break;
case 'M':n=13;tmp=readl(S3C64XX_GPMCON);break;
case 'N':n=14;tmp=readl(S3C64XX_GPNCON);break;
case 'O':n=15;tmp=readl(S3C64XX_GPOCON);break;
case 'P':n=16;tmp=readl(S3C64XX_GPPCON);break;
case 'Q':n=17;tmp=readl(S3C64XX_GPQCON);break;
default :return -EINVAL;break;
}
if((n==1)||(n==2)||(n==3)||(n==4)||(n==5)||(n==7)||(n==8)||(n==13))
{
switch(status)
{
case 0 :tmp&=(~(0x0f<<(4*IO_number)));break;
case 1 :tmp|=(1<<(4*IO_number));break;
default:return -EINVAL;break;
}
}
else if((n==6)||(n==9)||(n==10)||(n==11)||(n==14)||(n==15)||(n==16)||(n==17))
{
switch(status)
{
case 0 :tmp&=~(0x03<<(2*IO_number));break;
case 1 :tmp|=(1<<(2*IO_number));break;
default:return -EINVAL;break;
}
}
switch(IO_id)
{
case 'A':writel(tmp,S3C64XX_GPACON);break;
case 'B':writel(tmp,S3C64XX_GPBCON);break;
case 'C':writel(tmp,S3C64XX_GPCCON);break;
case 'D':writel(tmp,S3C64XX_GPDCON);break;
case 'E':writel(tmp,S3C64XX_GPECON);break;
case 'F':writel(tmp,S3C64XX_GPFCON);break;
case 'G':writel(tmp,S3C64XX_GPGCON);break;
case 'H':if(IO_number<=7) writel(tmp,S3C64XX_GPHCON0) else writel(tmp,S3C64XX_GPHCON1);break;
case 'I':writel(tmp,S3C64XX_GPICON);break;
case 'J':writel(tmp,S3C64XX_GPJCON);break;
case 'K':writel(tmp,S3C64XX_GPKCON);break;
case 'L':break;
case 'M':writel(tmp,S3C64XX_GPMCON);break;
case 'N':writel(tmp,S3C64XX_GPNCON);break;
case 'O':writel(tmp,S3C64XX_GPOCON);break;
case 'P':writel(tmp,S3C64XX_GPPCON);break;
case 'Q':writel(tmp,S3C64XX_GPQCON);break;
default :return -EINVAL;break;
}
return 0;
}
/*set the PullDown of the 6410IO
IO_id: A-Q exceptedL
IO_number: 0-x
status: 0:unenable 1:down enable 2:up enable3 reserved
return:ture:0 failed:-EINVAL
*/
int s3c6410_ioSetPullDown(char IO_id ,unsigned char IO_number,unsigned char status )
{
unsigned tmp;
switch(IO_id)
{
case 'A':tmp=readl(S3C64XX_GPAPUD);break;
case 'B':tmp=readl(S3C64XX_GPBPUD);break;
case 'C':tmp=readl(S3C64XX_GPCPUD);break;
case 'D':tmp=readl(S3C64XX_GPDPUD);break;
case 'E':tmp=readl(S3C64XX_GPEPUD);break;
case 'F':tmp=readl(S3C64XX_GPFPUD);break;
case 'G':tmp=readl(S3C64XX_GPGPUD);break;
case 'H':tmp=readl(S3C64XX_GPHPUD);break;
case 'I':tmp=readl(S3C64XX_GPIPUD);break;
case 'J':tmp=readl(S3C64XX_GPJPUD);break;
case 'K':tmp=readl(S3C64XX_GPKPUD);break;
case 'L':break;
case 'M':tmp=readl(S3C64XX_GPMPUD);break;
case 'N':tmp=readl(S3C64XX_GPNPUD);break;
case 'O':tmp=readl(S3C64XX_GPOPUD);break;
case 'P':tmp=readl(S3C64XX_GPPPUD);break;
case 'Q':tmp=readl(S3C64XX_GPQPUD);break;
default :return -EINVAL;break;
}
switch(status)
{
case 0:tmp&=~(0x03<<(2*IO_number));break;
case 1:tmp |= (1<<IO_number);break;
case 2:tmp |= (0x02<<IO_number);break;
case 3:tmp |= (0x03<<IO_number);break;
default:return -EINVAL;break;
}
switch(IO_id)
{
case 'A':writel(tmp,S3C64XX_GPAPUD);break;
case 'B':writel(tmp,S3C64XX_GPBPUD);break;
case 'C':writel(tmp,S3C64XX_GPCPUD);break;
case 'D':writel(tmp,S3C64XX_GPDPUD);break;
case 'E':writel(tmp,S3C64XX_GPEPUD);break;
case 'F':writel(tmp,S3C64XX_GPFPUD);break;
case 'G':writel(tmp,S3C64XX_GPGPUD);break;
case 'H':writel(tmp,S3C64XX_GPHPUD);break;
case 'I':writel(tmp,S3C64XX_GPIPUD);break;
case 'J':writel(tmp,S3C64XX_GPJPUD);break;
case 'K':writel(tmp,S3C64XX_GPKPUD);break;
case 'L':break;
case 'M':writel(tmp,S3C64XX_GPMPUD);break;
case 'N':writel(tmp,S3C64XX_GPNPUD);break;
case 'O':writel(tmp,S3C64XX_GPOPUD);break;
case 'P':writel(tmp,S3C64XX_GPPPUD);break;
case 'Q':writel(tmp,S3C64XX_GPQPUD);break;
default :return -EINVAL;break;
}
return 0;
}
页:
[1]