日期:2014-05-16  浏览次数:20759 次

关于pxa270 spi驱动程序的问题 先谢谢各位了
本人学写pxa270 spi驱动,对寄存器的赋值方法如下 请问下各位高手 这种赋值方法可行不 (sgpdr0,sgpsr0,sgpcr0,sgafr0这四个为GPIO口设置寄存器地址,剩下的为时钟与spi控制寄存器的地址,每个控制寄存器均为四字节)
我insmod 以后 程序只到了using 那就死机了。
#define DEVICE_NAME "/dev/spi"
#define sgpdr0 0x40e0000c
#define sgpsr0 0x40e00018
#define sgpcr0 0x40e00024
#define sgafr0 0x40e00058
#define sken0 0x41300004
#define ssscr0 0x41000000
#define ssscr1 0x41000004
#define sssdr0 0x41000010
#define sssr0 0x41000008
#define gpscr0 0x40e00024
static char spi_read=0x0;
static char spi_write=0x0;
unsigned long * spi_address;
unsigned long * spi_zt;
unsigned long * spi_kz;
static void Updateled(void)
{
  spi_address=ioremap(sgpdr0, 4);
  spi_read=(readl(spi_address));
  spi_write=spi_read | (0x07<<23);
  spi_write=spi_write & (~(0x01<<26));
  writel(spi_write,spi_address);
  iounmap(spi_address);
  spi_address=ioremap(sgpsr0,4);
  spi_read=(readl(spi_address));
  spi_write=spi_read | (0x01<<24);
  writel(spi_write,spi_address);
  iounmap(spi_address);
  spi_address=ioremap(sgafr0,4);
  spi_read=(readl(spi_address));
  spi_write=spi_read & (~(0x01<<14));
  spi_write=spi_write | (0x01<<15);
  spi_write=spi_write | (0x03<<19);
  spi_write=spi_write & (~(0x01<<18));
  spi_write=spi_write & (~(0x01<<21));
  writel(spi_write,spi_address);
  iounmap(spi_address);
  spi_address=ioremap(sken0,4);
  spi_read=(readl(spi_address));
  spi_write=spi_read | (0x01<<23);
  writel(spi_write,spi_address);
  iounmap(spi_address);
  spi_address=ioremap(ssscr1,4);
  spi_read=(readl(spi_address));
  spi_write=spi_read | (0x07<<10);
  spi_write=spi_write & (~(0xff));
  spi_write=spi_write & (~(0x01<<12));
  writel(spi_write,spi_address);
  iounmap(spi_address);
  spi_address=ioremap(ssscr0,4);
  spi_read=(readl(spi_address));
  spi_write=spi_read | (0x0b);
  spi_write=spi_write | (0x03<<9);
  spi_write=spi_write & (~(0x1f<<4));
  spi_write=spi_write & (~(0x1ff<<11));
  spi_write=spi_write & (~(0x01<<21));
  writel(spi_write,spi_address);
  iounmap(spi_address);
  spi_address=ioremap(gpscr0,4);
  spi_read=(readl(spi_address));
  spi_write=spi_read | (0x01<<24);
  writel(spi_write,spi_address);
  iounmap(spi_address);
  spi_address=ioremap(ssscr0,4);
  spi_read=(readl(spi_address));
  spi_write=spi_read | (0x01<<7);
  writel(spi_write,spi_address);
  iounmap(spi_address);
  spi_address=ioremap(sssdr0,4);
  writel(0x04,spi_address);
  iounmap(spi_address);


------解决方案--------------------
CPU应该没死机 你确定下在 内核里面有没有用到while语句 好像while语句不能用在内核里