Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7563435
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: 嵌入式

2012-01-04 16:41:53

/**

 * i2c_lzg7290 平台设备的注册

 * Lzy 2011-12-30

 */

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

static struct resource i2c_zlg7290_resources[] = {

[0] = {

.start = AT91SAM9G45_BASE_TWI0,

.end = AT91SAM9G45_BASE_TWI0 + SZ_16K - 1,

.flags = IORESOURCE_MEM,

},

[1] = {

.start = AT91SAM9G45_ID_TWI0,

.end = AT91SAM9G45_ID_TWI0,

.flags = IORESOURCE_IRQ,

},

};

/**

 * 平台设备结构体

 */

struct platform_device i2c_zlg7290_dev = {

.name = "at91_i2c", /* 指定平台设备名称 */

.id = -1, /* 设定一个设备 */

.resource = i2c_zlg7290_resources,

.num_resources = ARRAY_SIZE(i2c_zlg7290_resources),

};

/**

 * 配置用到的gpio

 */

void at91_i2c_cfg_gpio(void)

{

at91_set_A_periph(AT91_PIN_PA20, 0); /* TWD */

at91_set_multi_drive(AT91_PIN_PA20, 1);

at91_set_A_periph(AT91_PIN_PA21, 0); /* TWCK */

at91_set_multi_drive(AT91_PIN_PA21, 1);

}

/**

 * zlg7290平台设备注册

 */

static int __init i2c_init_zlg7290(void)

{

int ret;

at91_i2c_cfg_gpio(); /* 配置引脚 */

ret = platform_device_register(&i2c_zlg7290_dev); /* 注册 */

if(ret){

printk("device register failed!\n");

return ret;

}

return ret;

}

/**

 * zlg7290平台设备卸裁

 */

static void __exit i2c_exit_zlg7290(void)

{

platform_device_unregister(&i2c_zlg7290_dev);

}

module_init(i2c_init_zlg7290);

module_exit(i2c_exit_zlg7290);

 

MODULE_LICENSE("GPL");

MODULE_AUTHOR("Lzy");

 

 源码文件: IIC.rar   (使用控制器:获取不到时钟源,总是超时,求解决办法)

阅读(2299) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~