|
在S3C2440中IIC和SPI的控制器都是8位寄存器。但是我无论是使用iowrite8还是iowrite32写入,用ioread获得的都是0x0,但是把地址改成其他32的寄存器地址时读写成功。。郁闷。然后我不用iowrite而直接去操作映射获取的指针,也是失败的。。天啊,这是为什么。贴上代码
#define E2PROMADDR 0b1010000
#define TESTADDR 0b1111000
#define IICMEM_PABASE 0x54000000
#define IICMEN_LENGTH 0x10
#define IICMEM_NAME "iicmem"
#define IICCON_OFFSET 0x0
#define IICSTAT_OFFSET 0x4
#define IICADD_OFFSET 0x8
#define IICDS_OFFSET 0xc
int init_right;
void *iic_base;
static int __init e2prom_init(void)
{
unsigned int temp;
unsigned char temp2;
struct resource *iic_iomem;
volatile unsigned long *iiccon;
//volatile unsigned long *iicstat;
//volatile unsigned long *iicaddr;
//volatile unsigned long *iicds;
//先对IIC的内存区域进行映射
iic_iomem = request_mem_region(IICMEM_PABASE, IICMEN_LENGTH, IICMEM_NAME);
if(iic_iomem == NULL)
{
printk("request mem region fail\n");
goto init_fail_0;
}
iic_base = ioremap(IICMEM_PABASE, IICMEN_LENGTH);
//先禁止上啦,进行功能引脚的设置
temp = ioread32(S3C2410_GPECON);
temp |= 0xa0000000;
iowrite32(temp, S3C2410_GPECON);
temp = ioread32(S3C2410_GPEUP);
temp |= 0xc000;
iowrite32(temp, S3C2410_GPEUP);
//直接操作虚拟地址指针的方法
/* iiccon = (volatile unsigned long *)iic_base;
*iiccon = 0xff;
udelay(1);
printk("the iiccon is %d\n",*iiccon);*/
//这是8位的写入方法。无法写入
/* temp2 = ioread8(iic_base+IICCON_OFFSET);
mb();
temp2 = (1<<7)|(1<<5)|0xf;
iowrite8(temp2, iic_base+IICCON_OFFSET);
mb();
udelay(2);
temp2 = ioread8(iic_base+IICCON_OFFSET);
printk("after the IICCON is %d\n",temp2); */
//这是32位的写入方法
/* temp = ioread32(iic_base+IICCON_OFFSET);
mb();
temp = (1<<7)|(1<<5)|0xf;
iowrite32(temp, iic_base+IICCON_OFFSET);
mb();
udelay(2);
temp = ioread32(iic_base+IICCON_OFFSET);
printk("after the IICCON is %ld\n",temp);*/
init_right = 1;
printk("e2prom driver init success\n");
return 0;
init_fail_0:
init_right = 0;
printk("e2prom driver init fail\n");
return -1;
} |
|