Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1148338
  • 博文数量: 241
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 2279
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-27 19:53
个人简介

JustForFun

文章分类

全部博文(241)

文章存档

2023年(8)

2022年(2)

2021年(3)

2020年(30)

2019年(11)

2018年(27)

2017年(54)

2016年(83)

2015年(23)

我的朋友

分类: LINUX

2017-09-27 17:40:15

plat-s3c/dev-i2c0.c>
mach-s3c6410/mach-smdk6410.c>
//////////////////////////////////////////////////////////////////////////////
mach-s3c6410/mach-smdk6410.c>
static void __init smdk6410_machine_init(void)
{
    unsigned int tmp;
    s3c_i2c0_set_platdata(NULL);
    //s3c_i2c1_set_platdata(NULL);
    i2c_register_board_info(0, i2c_devs0, ARRAY_SIZE(i2c_devs0));
    i2c_register_board_info(1, i2c_devs1, ARRAY_SIZE(i2c_devs1));
    spi_register_board_info(sam_spi_devs, ARRAY_SIZE(sam_spi_devs));
    platform_add_devices(smdk6410_devices, ARRAY_SIZE(smdk6410_devices));
   
}

//////////////////////////////////////////////////////////////////////////////

/**
 * i2c_register_board_info - statically declare I2C devices
 * @busnum: identifies the bus to which these devices belong
 * @info: vector of i2c device descriptors
 * @len: how many descriptors in the vector; may be zero to reserve
 *    the specified bus number.
 *
 * Systems using the Linux I2C driver stack can declare tables of board info
 * while they initialize.  This should be done in board-specific init code
 * near arch_initcall() time, or equivalent, before any I2C adapter driver is
 * registered.  For example, mainboard init code could define several devices,
 * as could the init code for each daughtercard in a board stack.
 *
 * The I2C devices will be created later, after the adapter for the relevant
 * bus has been registered.  After that moment, standard driver model tools
 * are used to bind "new style" I2C drivers to the devices.  The bus number
 * for any device declared using this routine is not available for dynamic
 * allocation.
 *
 * The board info passed can safely be __initdata, but be careful of embedded
 * pointers (for platform_data, functions, etc) since that won't be copied.
 */
int __init
i2c_register_board_info(int busnum,
    struct i2c_board_info const *info, unsigned len)
{
    int status;

    mutex_lock(&__i2c_board_lock);

    /* dynamic bus numbers will be assigned after the last static one */
    if (busnum >= __i2c_first_dynamic_bus_num)
        __i2c_first_dynamic_bus_num = busnum + 1;

    for (status = 0; len; len--, info++) {
        struct i2c_devinfo    *devinfo;

        devinfo = kzalloc(sizeof(*devinfo), GFP_KERNEL);
        if (!devinfo) {
            pr_debug("i2c-core: can't register boardinfo!\n");
            status = -ENOMEM;
            break;
        }

        devinfo->busnum = busnum;
        devinfo->board_info = *info;
//将 struct i2c_devinfo    *devinfo;通过list成员挂接到__i2c_board_list链表上
        list_add_tail(&devinfo->list, &__i2c_board_list);
    }

    mutex_unlock(&__i2c_board_lock);

    return status;
}

//////////////////////////////////////////////////////////////////////////////


static struct platform_device *smdk6410_devices[] __initdata = {
    &s3c_device_i2c0,
    //&s3c_device_i2c1,
    &s3c_device_spi0,
    &s3c_device_spi1,
    &s3c_device_keypad,
};


//////////////////////////////////////////////////////////////////////////////
plat-s3c/dev-i2c0.c>

static struct resource s3c_i2c_resource[] = {
    [0] = {
        .start = S3C_PA_IIC,
        .end   = S3C_PA_IIC + SZ_4K - 1,
        .flags = IORESOURCE_MEM,
    },
    [1] = {
        .start = IRQ_IIC,
        .end   = IRQ_IIC,
        .flags = IORESOURCE_IRQ,
    },
};

struct platform_device s3c_device_i2c0 = {
//匹配//static struct platform_driver s3c2410_i2c_driver
    .name          = "s3c2410-i2c",
#ifdef CONFIG_S3C_DEV_I2C1
    .id          = 0,
#else
    .id          = -1,
#endif
    .num_resources      = ARRAY_SIZE(s3c_i2c_resource),
    .resource      = s3c_i2c_resource,
};

//////////////////////////////////////////////////////////////////////////////


//
//struct i2c_client *i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
//   ------> strlcpy(client->name, info->type, sizeof(client->name));// i2c_board_info中的名字给了client
//static struct i2c_board_info i2c_devs0[]
////"24c08"这个名字就是用来创建i2c_client来和里static struct i2c_driver at24_driver进行匹配的。
static struct i2c_board_info i2c_devs0[] __initdata = {
    { I2C_BOARD_INFO("24c08", 0x50), },          //0x50为IIC芯片从设备地址 7bit
/*    { I2C_BOARD_INFO("WM8580", 0x1b), },    */
};

static struct i2c_board_info i2c_devs1[] __initdata = {
    { I2C_BOARD_INFO("24c128", 0x57), },    /* Samsung S524AD0XD1 */
    { I2C_BOARD_INFO("WM8580", 0x1b), },
};

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