主题 : 菜鸟求救:MINI2440 ADC控制寄存器改不了 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 24982
精华: 0
发帖: 11
金钱: 60 两
威望: 12 点
综合积分: 22 分
注册时间: 2010-07-17
最后登录: 2010-10-21
楼主  发表于: 2010-07-17 14:40

 菜鸟求救:MINI2440 ADC控制寄存器改不了

读取ADCCON 的值一直是默认值0x3fc4,怎么设置不了。
    
  程序:#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/input.h>
#include <linux/init.h>
#include <linux/clk.h>
#include <linux/sched.h>
#include <linux/miscdevice.h>
#include <linux/wait.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <plat/regs-adc.h>
#include <mach/regs-gpio.h>
#include <mach/map.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <linux/slab.h>
#include <linux/errno.h>
//#include <asm-generic/errno-base.h>

#define ADC_NAME "adc"

static void __iomem *base_addr;
static int adc_data;
static struct clk *adc_clock;

//#define ADCCON (*(volatile unsigned long *)(base_addr+S3C2410_ADCCON))
//#define ADCTSC (*(volatile unsigned long *)(base_addr+S3C2410_ADCTSC))
//#define ADCDAT0 (*(volatile unsigned long *)(base_addr+S3C2410_ADCDAT0))
//#define ADCDAT1 (*(volatile unsigned long *)(base_addr+S3C2410_ADCDAT1))

static void START_ADC(void)
{  
  unsigned long tmp;
  tmp=(1<<14) | (255<<6) |(0<<3);
  iowrite32(tmp,base_addr);
  tmp=ioread32(base_addr);
  tmp=tmp | (1<<0);
  iowrite32(tmp,base_addr);
}
    

static ssize_t adc_read(struct file *filp,char*buf,size_t len,loff_t *off)
{  
  unsigned long adccon1;
  char str[20]={0};
  size_t size;  
    
  START_ADC();
  printk("base_addr=0x%x\n",base_addr);
  adccon1=ioread32(base_addr); /*adccon一直为默认值0x3fc4,改不了,为什么????
  printk("adccon2=0x%x\n",adccon1);
  while(!(adccon1&0x8000));
  adc_data=ioread32(base_addr+S3C2410_ADCDAT0);
  adc_data &=0x3ff;
    
    
  size=sprintf(str,"%d\n",adc_data);
  if(len>=size){
  int r =copy_to_user(buf,str,size);
  return r ? r:size;  
  }else {
  return -1;  
  }

}  

static int adc_open(struct inode *inode,struct file *filp)
{
  printk("adc opened\n");
  return 0;
}

static int adc_release(struct inode *inode,struct file *filp)
{
  printk("adc closed\n");
  return 0;
}

static struct file_operations dev_fops={
  owner: THIS_MODULE,
open: adc_open,
read : adc_read,
  release : adc_release,  

};



static int __init adc_init(void)
{ int ret;
  base_addr=ioremap(0x58000000,0x20);
  if(base_addr==NULL){
  printk(KERN_ERR"failed to remap register block\n");
  return -ENOMEM;
  }  
  printk("base_addr=0x%x\n",base_addr);
  adc_clock=clk_get(NULL,"abc");
  if(!adc_clock){
  printk(KERN_ERR"failed to get adc clock soure\n");
  return -ENOENT;
  }
  clk_enable(adc_clock);
  // ADCTSC=0;/*Normal ADC*/
    
    
  ret=register_chrdev(255,ADC_NAME,&dev_fops);
  
  printk("ADC_device init");
  return ret;
}

static void __exit adc_exit(void)
{ printk("moudule exit!\n");
  iounmap(base_addr);
  printk("iounmap.....!\n");
  if(adc_clock)
  /* { clk_disable(adc_clock);
  clk_put(adc_clock);
  adc_clock=NULL;
  } */ 没注释掉,模块卸载不了,为什么??  
  printk("adc_clock.....!\n");
  unregister_chrdev(255,ADC_NAME);
  printk("module exit all\n");
}

module_init(adc_init);
module_exit(adc_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("MY_ADC");


是哪出了问题,是我的IO控制方法有问题?还是。。。。。。郁闷我好久了。ADCCON为什么改不了。  
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2010-07-17 15:33
复制代码
  1. adccon1=ioread32(base_addr); /*adccon一直为默认值0x3fc4,改不了,为什么????
  2.   printk("adccon2=0x%x\n",adccon1);
  3.   while(!(adccon1&0x8000));

自始至终,变量adccon1只赋值了一次, 你凭什么期待它的值会改变?
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 19870
精华: 0
发帖: 27
金钱: 135 两
威望: 27 点
综合积分: 54 分
注册时间: 2010-04-24
最后登录: 2014-05-26
2楼  发表于: 2011-05-04 21:33
因为你没有正确的获取adc时钟 所以不能修改