I2C-GPIO-Bit bang
Hi Everybody,
I have a question, on using the available i2c-gpio driver in linux kernel.
If I do a lsmod I can see the loaded driver, but can't see any relevant devie nod in /dev directory.It has been registered as platform driver.
How can I access this driver from user space.?
If I need to create a /dev node, then how can I get the major no.?
I am attaching the driver for your review.
Any help will be appreciated.
Many thanks, betz
/*********************************/
struct i2c_s3c2410_bit {
struct i2c_adapter adap;
struct i2c_algo_bit_data algo;
};
static void i2c_s3c2410_bit_setsda(void *data, int state)
{
if (state)
s3c2410_gpio_cfgpin(S3C2410_GPD8, S3C2410_GPIO_INPUT);
else
{
s3c2410_gpio_setpin(S3C2410_GPD8, 0);
s3c2410_gpio_cfgpin(S3C2410_GPD8, S3C2410_GPIO_OUTPUT);
}
}
static void i2c_s3c2410_bit_setscl(void *data, int state)
{
if (state)
s3c2410_gpio_cfgpin(S3C2410_GPD9, S3C2410_GPIO_INPUT);
else
{
s3c2410_gpio_setpin(S3C2410_GPD9, 0);
s3c2410_gpio_cfgpin(S3C2410_GPD9, S3C2410_GPIO_OUTPUT);
}
}
static int i2c_s3c2410_bit_getsda(void *data)
{
return !!s3c2410_gpio_getpin(S3C2410_GPD8);
}
static int i2c_s3c2410_bit_getscl(void *data)
{
return !!s3c2410_gpio_getpin(S3C2410_GPD9);
}
static struct i2c_algo_bit_data i2c_s3c2410_bit_algo = {
.setsda = i2c_s3c2410_bit_setsda,
.setscl = i2c_s3c2410_bit_setscl,
.getsda = i2c_s3c2410_bit_getsda,
.getscl = i2c_s3c2410_bit_getscl,
.udelay = 100,
.timeout = HZ,
};
static int i2c_s3c2410_bit_probe(struct platform_device *dev)
{
// printk("%s\n", __FUNCTION__);
struct i2c_s3c2410_bit *i2c;
int ret;
printk("%s\n", __func__);
i2c = kzalloc(sizeof(struct i2c_s3c2410_bit), GFP_KERNEL);
if (!i2c) {
ret = -ENOMEM;
goto err_out;
}
s3c2410_gpio_cfgpin(S3C2410_GPD9, S3C2410_GPIO_INPUT);
s3c2410_gpio_cfgpin(S3C2410_GPD8, S3C2410_GPIO_INPUT);
i2c->adap.owner = THIS_MODULE;
strlcpy(i2c->adap.name, "S3C2410 bit-bang I2C adapter", sizeof(i2c->adap.name));
i2c->adap.algo_data = &i2c->algo;
i2c->adap.dev.parent = &dev->dev;
i2c->algo = i2c_s3c2410_bit_algo;
i2c->algo.data = i2c;
ret = i2c_bit_add_bus(&i2c->adap);
if (ret >= 0) {
platform_set_drvdata(dev, i2c);
return 0;
}
kfree(i2c);
err_out:
return ret;
}
static int i2c_s3c2410_bit_remove(struct platform_device *dev)
{
struct i2c_s3c2410_bit *i2c = platform_get_drvdata(dev);
platform_set_drvdata(dev, NULL);
i2c_del_adapter(&i2c->adap);
return 0;
}
static struct platform_driver i2c_s3c2410_bit_driver = {
.probe = i2c_s3c2410_bit_probe,
.remove = i2c_s3c2410_bit_remove,
.driver = {
.name = "s3c2410-i2c-bit",
.owner = THIS_MODULE,
},
};
static int __init i2c_s3c2410_bit_init(void)
{
return platform_driver_register(&i2c_s3c2410_bit_driver);
}
static void __exit i2c_s3c2410_bit_exit(void)
{
platform_driver_unregister(&i2c_s3c2410_bit_driver);
}
module_init(i2c_s3c2410_bit_init);
module_exit(i2c_s3c2410_bit_exit);
MODULE_DESCRIPTION("S3C2410 bit-bang I2C bus driver");
MODULE_LICENSE("GPL");
/*********************************/
|