|
楼主 |
发表于 2007-7-13 09:15:48
|
显示全部楼层
SPSTA0和SPRDAT0这两个只读的寄存器是可以访问,能读出数据
其他的W/R的SPI寄存器都不能写和读。
Ioremap地方是我比较疑惑的
驱动:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/config.h>
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/cdev.h>
#include <linux/devfs_fs_kernel.h>
#include <asm/arch/regs-gpio.h>
#include <asm/arch/regs-irq.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <linux/slab.h>
#include <linux/delay.h>
#define DEVICE_NAME "spi"
struct cdev spi_dev;
unsigned int spi_major_number=0;
unsigned long SPI_GPBCON;//GPB Part define
unsigned long SPI_GPBDAT;
unsigned long SPI_GPBUP;
unsigned long SPI_GPECON;//GPE Part define
unsigned long SPI_GPEDAT;
unsigned long SPI_GPEUP;
unsigned long SPI_GPGCON;//GPG Part define
unsigned long SPI_GPGDAT;
unsigned long SPI_GPGUP;
unsigned long SPI_SPCON0;//SPI Part define
unsigned long SPI_SPSTA0;
unsigned long SPI_SPPIN0;
unsigned long SPI_SPPRE0;
unsigned long SPI_SPTDAT0;
unsigned long SPI_SPRDAT0;
unsigned long SPI_GPFCON;
unsigned long SPI_GPFDAT;
unsigned long SPI_GPFUP;
#define spi_gpbcon (*(volatile unsigned long *)SPI_GPBCON)
#define spi_gpbdat (*(volatile unsigned long *)SPI_GPBDAT)
#define spi_gpbup (*(volatile unsigned long *)SPI_GPBUP)
#define spi_gpecon (*(volatile unsigned long *)SPI_GPECON)
#define spi_gpedat (*(volatile unsigned long *)SPI_GPEDAT)
#define spi_gpeup (*(volatile unsigned long *)SPI_GPEUP)
#define spi_gpgcon (*(volatile unsigned long *)SPI_GPGCON)
#define spi_gpgdat (*(volatile unsigned long *)SPI_GPGDAT)
#define spi_gpgup (*(volatile unsigned long *)SPI_GPGUP)
#define spi_con0 (*(volatile unsigned long *)SPI_SPCON0)
#define spi_sta0 (*(volatile unsigned long *)SPI_SPSTA0)
#define spi_pin0 (*(volatile unsigned long *)SPI_SPPIN0)
#define spi_pre0 (*(volatile unsigned long *)SPI_SPPRE0)
#define spi_tdat0 (*(volatile unsigned long *)SPI_SPTDAT0)
#define spi_rdat0 (*(volatile unsigned long *)SPI_SPRDAT0)
#define spi_gpfcon (*(volatile unsigned long *)SPI_GPFCON)
#define spi_gpfdat (*(volatile unsigned long *)SPI_GPFDAT)
#define spi_gpfup (*(volatile unsigned long *)SPI_GPFUP)
static struct file_operations spi_fops = {
.owner = THIS_MODULE,
};
static int __init spi_init(void)
{
int ret,devno;
dev_t dev;
ret = alloc_chrdev_region(&dev,0,1,DEVICE_NAME);
spi_major_number = MAJOR(dev);
printk(KERN_INFO "Initial CC2420 SPI driver!\n");
if (ret<0) {
printk(KERN_WARNING "CC2420:can't get major number %d\n",spi_major_number);
return ret;
}
devno = MKDEV(spi_major_number,0);
cdev_init(&spi_dev,&spi_fops);
spi_dev.owner = THIS_MODULE;
spi_dev.ops = &spi_fops;
ret = cdev_add(&spi_dev,devno,1);
if (ret) {
unregister_chrdev_region(dev,1);
printk(KERN_NOTICE "Error %d adding spi device\n",ret);
return ret;
}
devfs_mk_cdev(MKDEV(spi_major_number,0), S_IFCHR | S_IRUSR | S_IWUSR,DEVICE_NAME);
printk(KERN_INFO"/dev/%s has been added to your system.\n",DEVICE_NAME);
/****************************************************************
* 2410 SPI configuration *
* GPG2=nSS0,GPB0=nSS1 GPE11=SPIMISO0, GPE12=SPIMOSI0, GPE13=SPICLK0*
* SPI0 is tested by this code*
****************************************************************/
SPI_GPBCON = ioremap(0x56000010,4);
SPI_GPBDAT = ioremap(0x56000014,4);
SPI_GPBUP = ioremap(0x56000018,4);
SPI_GPECON = ioremap(0x56000040,4);
SPI_GPEDAT = ioremap(0x56000044,4);
SPI_GPEUP = ioremap(0x56000048,4);
SPI_GPFCON = ioremap(0x56000050,4);
SPI_GPFDAT = ioremap(0x56000054,4);
SPI_GPFUP = ioremap(0x56000058,4);
SPI_GPGCON = ioremap(0x56000060,4);
SPI_GPGDAT = ioremap(0x56000064,4);
SPI_GPGUP = ioremap(0x56000068,4);
spi_gpgup=0xa;
printk("gpgup=0x%x\n",spi_gpgup); //此处能正确读回来
SPI_SPCON0 = ioremap(0x59000000,4);
spi_con0=0xa;
printk("spi_con0=0x%x\n",spi_con0); //此处值为0,但是只要把映射地址改为其他IO地址或着I2C之类的寄存器,都能正确读出
//所以这个地方很迷茫,不知道是不是CHIP的问题,我在2.4上都是能正常读写。
//0x59000000 该寄存器可读可写。
SPI_SPSTA0 = ioremap(0x59000004,4);
SPI_SPPIN0 = ioremap(0x59000008,4);
SPI_SPPRE0 = ioremap(0x5900000c,4);
SPI_SPTDAT0 = ioremap(0x59000010,4);
SPI_SPRDAT0 = ioremap(0x59000014,4);
printk("Init spi success!\n");
return 0;
}
static void __exit spi_exit(void)
{
dev_t dev=MKDEV(spi_major_number,0);
cdev_del(&spi_dev);
unregister_chrdev_region(dev,1);
devfs_remove(DEVICE_NAME);
printk(KERN_INFO "unregistered the %s\n",DEVICE_NAME);
}
module_init(spi_init);
module_exit(spi_exit);
MODULE_LICENSE("GPL");
/*****************************************************************/
Makefile:
ifneq ($(KERNELRELEASE),)
obj-m := ioremap.o
else
KDIR :=/utuLinuxfor2410V1.2/utu-linux_for_s3c2410_V1.3
#KDIR ?= /usr/src/linux
PWD:= $(shell pwd)
#INCLUDEDIR = $(KDIR)/include
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
rm -f *.o *.ko *.mod.*
endif
/**********************************************/ |
|