mini2440 spi驱动总结(3)

port_status=readl(SCRPND);
 port_status|=(1<<22);
 writel(port_status,SCRPND);
 
 port_status=readl(INTPND);
 port_status|=(1<<22);
 writel(port_status,INTPND);
 //SCRPND|=(1<<22);
 //INTPND|=(1<<22);

disable_irq(IRQ_SPI0);
// SPCON0|=(0<<6)|(0<<5)|(0<<4)|(0<<3)|(1<<2)|(0<<1)|(1<<0);
 
 
 
 while(endSpiRx==0)
 {
  while (!SPI_TXRX_READY);
  writeb(0xff,SPTDAT0);
  while(!SPI_TXRX_READY);
  spi_devp->dataRx[i]=SPRDAT0;
  i++;
  if(i>4)
  {
   endSpiRx=1;
  }
 }
 port_status=readl(SPCON0);
 port_status|=((0<<6)|(1<<5)|(0<<4)|(1<<3)|(1<<2)|(0<<1)|(0<<0));
 writel(port_status,SPCON0);
 
 enable_irq(IRQ_SPI0);
 printk("SPI irq end\n");
}
static void spi_setup_cdev(struct spi_dev *dev,int index)
{
 int err,devno=MKDEV(SPI_MAJOR,index);
 cdev_init(&dev->cdev,&spi_fops);
 //cdev_init(&spi_dev,&spi_fops);
 dev->cdev.owner=THIS_MODULE;
 dev->cdev.ops=&spi_fops;
 err=cdev_add(&dev->cdev,devno,1);
 if(err)
 printk("error\n");
 printk("-----------------------------------\n");
}
static int __init spi_init(void)
{
 int ret;
 dev_t devno=MKDEV(SPI_MAJOR,0);
 if(SPI_MAJOR)//申请设备号
  ret=register_chrdev_region(devno,1,SPI_NAME);
 else//动态申请设备号
 {
  ret=alloc_chrdev_region(&devno,0,1,SPI_NAME);
  SPI_MAJOR=MAJOR(devno);
 }
 if(ret<0)
  return ret;
 //动态申请设备结构体的内存
 spi_devp=kmalloc(sizeof(struct spi_dev),GFP_KERNEL);
 if(!spi_devp)//申请失败
 {
  ret=-ENOMEM;
  goto fail_malloc;
 }
 memset(spi_devp,0,sizeof(struct spi_dev));
 
 spi_setup_cdev(spi_devp,0);
 
 printk("init spi success\n");
 return 0;
fail_malloc:
 unregister_chrdev_region(devno,1);
 return ret;
}
static void __exit spi_exit(void)
{
 free_irq(IRQ_SPI0,NULL);
 unregister_chrdev(SPI_MAJOR,SPI_NAME);
}
//-----------------------------------------------------------------------------------------------------------------------
module_init(spi_init);
module_exit(spi_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Gflytu");
MODULE_DESCRIPTION("SPI DRIVER FOR MINI_S3C2440");

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwxjpy.html