< 첫번째 예제 >
먼저 module_init 이나 device register 단에서 해당 드라이버에 대한 정보를 등록하며 이때 파라미터로 전달한 데이터를 등록해 놓는다.
이때 다음 함수가 사용된다.
platform_set_drvdata
static struct ak4671_setup_data smdk6410_ak4671_setup = {
.i2c_bus = 3, // id = 3, GPIO_FM_SCL, GPIO_FM_SDA platform device.
.i2c_address = (0x24 >> 1),
};
static struct snd_soc_device smdk6410_snd_devdata = {
.machine = &smdk6410,
.platform = &s3c24xx_soc_platform,
.codec_dev = &soc_codec_dev_ak4671,
.codec_data = &smdk6410_ak4671_setup,
};
static struct platform_device *smdk6410_snd_device;
static int __init smdk6410_init(void)
{
...
smdk6410_snd_device = platform_device_alloc("soc-audio", 0);
if (!smdk6410_snd_device)
return -ENOMEM;
platform_set_drvdata(smdk6410_snd_device, &smdk6410_snd_devdata);
smdk6410_snd_devdata.dev = &smdk6410_snd_device->dev;
ret = platform_device_add(smdk6410_snd_device);
if (ret)
platform_device_put(smdk6410_snd_device);
...
}
module_init(smdk6410_init);
.i2c_bus = 3, // id = 3, GPIO_FM_SCL, GPIO_FM_SDA platform device.
.i2c_address = (0x24 >> 1),
};
static struct snd_soc_device smdk6410_snd_devdata = {
.machine = &smdk6410,
.platform = &s3c24xx_soc_platform,
.codec_dev = &soc_codec_dev_ak4671,
.codec_data = &smdk6410_ak4671_setup,
};
static struct platform_device *smdk6410_snd_device;
static int __init smdk6410_init(void)
{
...
smdk6410_snd_device = platform_device_alloc("soc-audio", 0);
if (!smdk6410_snd_device)
return -ENOMEM;
platform_set_drvdata(smdk6410_snd_device, &smdk6410_snd_devdata);
smdk6410_snd_devdata.dev = &smdk6410_snd_device->dev;
ret = platform_device_add(smdk6410_snd_device);
if (ret)
platform_device_put(smdk6410_snd_device);
...
}
module_init(smdk6410_init);
이후 해당 디바이스에 대한 register 가 되면 probe 함수가 호출되며 파라미터로 등록한 데이터를 얻을 수 있다.
static int ak4671_probe(struct platform_device *pdev)
{
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
struct ak4671_setup_data *setup = socdev->codec_data;
...
}
< 두번째 예제 >
device info 를 등록할때 구조체에 데이터를 등록시켜 놓는다.
static void msensor_reset(void)
{
/* MSENSE_nRST */
...
}
static struct abcd_platform_data abcd_platform_data = {
.reset = msensor_reset, // 전달하고 싶은 함수 주소 나 데이터
.poll_interval = 1000,
};
static struct i2c_board_info modelname_i2c1_devs[] __initdata = {
{
I2C_BOARD_INFO("abcd device", 0x1c),
.platform_data = &abcd_platform_data,
.irq = IRQ_EINT(29),
}, {
I2C_BOARD_INFO("another device", 0x90 >> 1),
.platform_data = &aquila_haptic_data,
},
};
static void __init universal_machine_init(void)
{
struct i2c_board_info *info;
info = model_name_i2c1_devs;
n = ARRAY_SIZE(model_name_i2c1_devs);
...
i2c_register_board_info(1, info, n);
platform_device_register(i2c);
}
{
/* MSENSE_nRST */
...
}
static struct abcd_platform_data abcd_platform_data = {
.reset = msensor_reset, // 전달하고 싶은 함수 주소 나 데이터
.poll_interval = 1000,
};
static struct i2c_board_info modelname_i2c1_devs[] __initdata = {
{
I2C_BOARD_INFO("abcd device", 0x1c),
.platform_data = &abcd_platform_data,
.irq = IRQ_EINT(29),
}, {
I2C_BOARD_INFO("another device", 0x90 >> 1),
.platform_data = &aquila_haptic_data,
},
};
static void __init universal_machine_init(void)
{
struct i2c_board_info *info;
info = model_name_i2c1_devs;
n = ARRAY_SIZE(model_name_i2c1_devs);
...
i2c_register_board_info(1, info, n);
platform_device_register(i2c);
}
probe 에서 꺼내다 쓴다.
static int abcd_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct abcd_chip *ac;
struct abcd_platform_data *pdata;
ac->reset = pdata->reset;
ac->poll_interval = pdata->poll_interval;
ac->client = client;
i2c_set_clientdata(client, ac);
...
}
'Programming > Linux_Kernel' 카테고리의 다른 글
linux 레지스터 맵핑주소 찾기 (0) | 2010.02.08 |
---|---|
정식 i2c port 에 등록하여 사용하기 (2) | 2010.02.06 |
linux 에서 GPIO로 I2C Emulation 사용하기 (0) | 2010.02.06 |
linux kernel update list 정리 (2.6.25 - 2.6.29) (0) | 2010.01.28 |
linux 초보자를 위한 잡다지식 퍼레이드 (2) | 2010.01.14 |