主题 : SPI的时钟使能信号 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 32530
精华: 0
发帖: 17
金钱: 85 两
威望: 17 点
综合积分: 34 分
注册时间: 2010-11-17
最后登录: 2011-01-05
楼主  发表于: 2010-11-21 09:28

 SPI的时钟使能信号

大家好!我在驱动程序中用以下两种方法来设置SPI的时钟使能信号,

为什么SPICLK0引脚始终为高电平,而没有时钟信号呢?希望有过类似

经验的人能够指导一下,不胜感激!
(1)
#define pCLKCON (*(unsigned long *)ioremap(0x4c00000c,4);
pCLKCON |= (1<<18);

(2)
__raw_writel(__raw_readl(S3C2410_CLKCON) | S3C2410_CLKCON_SPI,

S3C2410_CLKCON);
wsk
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2010-11-21 13:19
你确定把SPICLK0对应的GPIO配置成SPICLK0了?
"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: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
2楼  发表于: 2010-11-21 13:26
(1)
#define pCLKCON (*(unsigned long *)ioremap(0x4c00000c,4);

另外,少用这种让人看不懂的定义

起码可以用
#define pCLKCON *((unsigned long *)(base + 0xc))

unsigned long base = ioremap(0x4c000000, 64);
"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: 32530
精华: 0
发帖: 17
金钱: 85 两
威望: 17 点
综合积分: 34 分
注册时间: 2010-11-17
最后登录: 2011-01-05
3楼  发表于: 2010-11-21 18:24
谢谢!  我是这样配置IO口的:  s3c2410_gpio_cfgpin(S3C2410_GPE(13),S3C2410_GPE13_SPICLK0);
wsk
级别: 新手上路
UID: 32530
精华: 0
发帖: 17
金钱: 85 两
威望: 17 点
综合积分: 34 分
注册时间: 2010-11-17
最后登录: 2011-01-05
4楼  发表于: 2010-11-21 19:54
驱动程序如下,希望加载后SPICLK0口能产生时钟信号.

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/gpio.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <mach/regs-gpio.h>
#include <mach/regs-clock.h>
#include <mach/hardware.h>
#include <mach/regs-irq.h>
#include <linux/clk.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/miscdevice.h>

#define DEVICE_NAME "test"

static void __iomem *base_addr;

#define myCLKCON (*(volatile unsigned long *)(base_addr+0x0c))

static int test_open(struct inode *inode,struct file *filp)
{
    printk("in open function\n");
    return 0;
}

static ssize_t test_write(struct file *filp,const char __user *buf,size_t count,loff_t *f_ops)
{
    printk("in write function\n");
    return 0;
}

static int test_close(struct inode *inode,struct file *filp)
{
    printk("in close function\n");
    return 0;
}

static struct file_operations test_fops = {
    .owner = THIS_MODULE,
    .open =test_open,
    .write =test_write,
    .release=test_close,
};
static struct miscdevice misc = {
    .minor = MISC_DYNAMIC_MINOR,
    .name = DEVICE_NAME,
    .fops = &test_fops,
};
static int __init dev_init(void)
{
    int ret;

    s3c2410_gpio_cfgpin(S3C2410_GPE(13),S3C2410_GPE13_SPICLK0);
    
    base_addr=ioremap(0x4c000000,64);
    if(base_addr==NULL)
    {
        printk("Failed to remap register block\n");
        return -ENOMEM;
    }
    else
         printk("ioremap succeded\n");

    //__raw_writel(__raw_readl(S3C2410_CLKCON)|S3C2410_CLKCON_SPI,S3C2410_CLKCON);
    myCLKCON |= (1<<18);

    ret = misc_register(&misc);
    printk(DEVICE_NAME"\tinitialized\n");
    return ret;
}
static void __exit dev_exit(void)
{
    iounmap(base_addr);
    misc_deregister(&misc);
}

module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("FriendlyARM Inc.");
wsk
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
5楼  发表于: 2010-11-21 21:14
我印象里根据SPI的spec,时钟信号是数据传输时才会有的。另外,内核里已经包含了S3C2440A的SPI Controller驱动,你最好先参考一下,搞清楚硬件的操作规则
http://lxr.linux.no/linux+v2.6.32.2/drivers/spi/spi_s3c24xx.c
"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: 32530
精华: 0
发帖: 17
金钱: 85 两
威望: 17 点
综合积分: 34 分
注册时间: 2010-11-17
最后登录: 2011-01-05
6楼  发表于: 2010-11-21 22:30
是这样啊! 那我再看看,谢谢啊!
wsk