SPI_s3c2410.c 寄存器定义

  1. #ifndef __KERNEL__   
  2. #define __KERNEL__   
  3. #endif   
  4. #ifndef MODULE   
  5. #define MODULE   
  6. #endif   
  7.   
  8.   
  9. #include <LINUX config.h>   
  10. #include <LINUX module.h>   
  11.   
  12.   
  13. MODULE_LICENSE("GPL");  
  14. MODULE_AUTHOR("HHT<LIKEHHT@SOHU.COM>");  
  15. MODULE_DESCRIPTION("SPI_driver for S3C2410");  
  16. #ifdef CONFIG_SMP   
  17. #define __SMP__   
  18. #endif   
  19.   
  20.   
  21. /***************************************************/  
  22.   
  23. #include <LINUX kernel.h>   /*printk()*/         
  24. #include <ASM uaccess.h>    /*copy_to_user(),copy_from_user()*/   
  25. #include <LINUX fs.h>       /*struct file_operations,register_chrdv()*/   
  26. #include <LINUX sched.h>    /*和任务有关系*/   
  27. #include <LINUX types.h>    /*u8,u16,u32...*/   
  28.   
  29.   
  30. #include <LINUX init.h>   
  31. #include <ASM hardware.h>   
  32. #include <ASM delay.h>   
  33.   
  34.   
  35. #include <LINUX version.h>   
  36. #include <LINUX iobuf.h>   
  37. #include <LINUX major.h>   
  38. #include <LINUX capability.h>   
  39. #include <LINUX smp_lock.h>   
  40. #include <LINUX fs.h>   
  41. #include <LINUX mm.h>   
  42. #include <ASM cpu_s3c2410.h arch>   
  43. #include <ASM io.h>   
  44. #include <LINUX sched.h>   
  45.   
  46.   
  47.   
  48.   
  49. unsigned long spi_gpgcon;//GPG Part define   
  50. unsigned long spi_gpgdat;  
  51. unsigned long spi_gpgup;  
  52. unsigned long spi_spcon1;//SPI Part define   
  53. unsigned long spi_spsta1;  
  54. unsigned long spi_sppin1;  
  55. unsigned long spi_sppre1;  
  56. unsigned long spi_sptdat1;  
  57. unsigned long spi_sprdat1;  
  58.   
  59.   
  60. /*****************************************************/  
  61.   
  62. static int spi_open(struct inode *,struct file *);  
  63. static int spi_release(struct inode *,struct file *);  
  64. static ssize_t spi_write(struct file *filp,const char *buf,size_t count,loff_t *f_ops);  
  65.   
  66.   
  67.   
  68.   
  69. /**********************************************************/  
  70. static struct file_operations spi_fops = {  
  71. owner:  THIS_MODULE,  
  72. open:   spi_open,  
  73. release:spi_release,  
  74. write:  spi_write,  
  75. };  
  76.   
  77.   
  78. static int spi_major = 0;  
  79. #define spi_name    "S3C2410_SPI"   
  80. #define spi_minor   1   
  81.   
  82. #ifdef CONFIG_DEVFS_FS   
  83. static devfs_handle_t devfs_spi_dir,devfs_spiraw;  
  84. #endif   
  85.   
  86. /********************************************************/  
  87.   
  88. static int spi_open(struct inode *inode,struct file *filp)  
  89. {  
  90. int value;  
  91. printk("<1>***************************");  
  92. printk("<1>spi open program begin../n");  
  93. printk("<1>now,GPG port init.../n");  
  94. spi_gpgcon &=0xffff033f;//GPGCON-3,5,6,7=11   
  95. spi_gpgcon |=0x0000fcc0;  
  96. value=(int)spi_gpgcon;  
  97. printk("spi_gpgcon=0x%x/n",value);  
  98. spi_gpgup &=(0xff00);//GPGUP-3,7=1 GPGUP-5,6=0   
  99. spi_gpgup |=0x0088;  
  100. value=(int)spi_gpgup;  
  101. printk("spi_gpgup=0x%x/n",value);  
  102. printk("<1>GPG port init end!/n");  
  103. printk("<1>****************************");  
  104.   
  105. return 0;  
  106. }  
  107.   
  108.   
  109. static int spi_release(struct inode *inode,struct file *filp)  
  110. {  
  111.     MOD_DEC_USE_COUNT;  
  112.     printk("<1>release/n");  
  113.     return 0;  
  114.   
  115. }  
  116.   
  117.   
  118. static ssize_t spi_write(struct file *filp,const char *buf,size_t count,loff_t *f_ops)  
  119. {  
  120. int i=0;  
  121. int config;  
  122. char string;  
  123. char str[20];  
  124. char *txStr,*rxStr;  
  125. volatile char *spiTxStr,*spiRxStr;  
  126. volatile int endSpiTx;  
  127.                                                                                                                  
  128. printk("<1>SPI polling TX/RX Test.../n");  
  129. printk("<1>Connet SPIMOSI1 into SPIMISO1/n");  
  130. endSpiTx=0;  
  131. spiTxStr="ABCD0123";  
  132. spiRxStr=str;  
  133. txStr=(char *)spiTxStr;  
  134. rxStr=(char *)spiRxStr;  
  135.                                                                                                                  
  136. spi_sppre1=0x0;//SPI Baud Rate Prescaler Register,Baud Rate=PCLK/2/(Prescaler value+1)   
  137. spi_spcon1=(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0<<1)|(0<<0);  
  138. config=(int)spi_spcon1;  
  139. printk("<1>spi_spcon1=0x%x/n",config);  
  140. //polling,en-sck,master,low,format A,nomal   
  141. spi_sppin1=(0<<2)|(1<<1)|(0<<0);  
  142. //Multi Master error detect disable,reserved,release   
  143. config=(int)spi_sppin1;  
  144. printk("spi_sppin1=0x%x/n",config);  
  145.   
  146.                                                                                                                  
  147. while(endSpiTx==0)  
  148. {  
  149. //if(spi_sta1&0x1)   
  150. if((spi_spsta1&0x01)==1) //data Tx/Rx ready   
  151. {  
  152. if(*spiTxStr !='/0')  
  153. {  
  154. spi_sptdat1=*spiTxStr++;  
  155. string=spi_sptdat1;  
  156. printk("transmit char=%c/n",string);  
  157. }  
  158. else  
  159. endSpiTx=1;  
  160.                                                                                                                  
  161. //while(!(spi_sta1&0x1)) ;   
  162. // while((spi_sta1&0x1)==0)   
  163. // ;//check Rx ready state   
  164.                                                                                                                  
  165. str[i]=spi_sprdat1;  
  166. printk("receive char=%c/n",str[i]);  
  167. i++;  
  168.                                                                                                                  
  169. }  
  170. }  
  171.   
  172.   
  173.   
  174. spi_spcon1=(0<<5)|(0<<4)|(1<<2)|(0<<1)|(0<<0);  
  175. //Polling,dis-sck,master,low,format A,nomal   
  176. *(spiRxStr-1)='/0';//remove last dummy data & attach End of String(Null)   
  177. printk("Tx string:%s/n",txStr);  
  178. printk("Rx string:%s/n",rxStr);  
  179. /* 
  180. if(strcmp(rxStr,txStr)==0) 
  181. printk("transmit and receive is ok!/n"); 
  182. else 
  183. printk("ERROR!/n"); 
  184. */  
  185. return 0;  
  186. }  
  187.   
  188.   
  189. static int __init spi_init(void)  
  190. {  
  191. int ret;  
  192. ret = register_chrdev(0,spi_name,&spi_fops);  
  193. if(ret < 0){  
  194.     printk("<1>cannot get major number/n");  
  195.     return ret;  
  196. }  
  197. spi_major = ret;  
  198.   
  199. #ifdef CONFIG_DEVFS_FS   
  200.     devfs_spi_dir = devfs_mk_dir(NULL,"spi",NULL);  
  201.     devfs_spiraw = devfs_register(devfs_spi_dir,"0",DEVFS_FL_DEFAULT,spi_major,spi_minor,S_IFCHR | S_IRUSR | S_IWUSR,&spi_fops,NULL);  
  202. #endif   
  203.   
  204. spi_gpgcon = *(volatile unsigned long *)ioremap (0x56000060,4);  
  205. spi_gpgdat = *(volatile unsigned long *)ioremap (0x56000064,4);  
  206. spi_gpgup = *(volatile unsigned long *)ioremap (0x56000068,4);  
  207.                                                                                                                  
  208. spi_spcon1 = *(volatile unsigned long *)ioremap(0x59000020,4);  
  209. spi_spsta1 = *(volatile unsigned long *)ioremap(0x59000024,4);  
  210. spi_sppin1 = *(volatile unsigned long *)ioremap(0x59000028,4);  
  211. spi_sppre1 = *(volatile unsigned long *)ioremap(0x5900002c,4);  
  212. spi_sptdat1 = *(volatile unsigned long *)ioremap(0x59000030,4);  
  213. spi_sprdat1 = *(volatile unsigned long *)ioremap(0x59000034,4);  
  214.                                                                                                                  
  215. printk("Init spi success!/n");  
  216. return 0;  
  217.   
  218.   
  219. printk("<1>initialized!/n");  
  220.   
  221. return 0;  
  222. }  
  223.   
  224.   
  225. static void __exit spi_exit(void)  
  226. {  
  227. #ifdef CONFIG_DEVFS_FS   
  228.     devfs_unregister(devfs_spiraw);  
  229.     devfs_unregister(devfs_spi_dir);  
  230. #endif   
  231.     unregister_chrdev(spi_major,spi_name);  
  232.   
  233.   
  234. }  
  235.   
  236. module_init(spi_init);  
  237. module_exit(spi_exit);  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值