LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-24-2010, 05:41 AM   #1
betran
LQ Newbie
 
Registered: Feb 2010
Posts: 2

Rep: Reputation: 0
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");

/*********************************/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Could not set I2C Bus Busy bit to zero mist_4u Linux - Newbie 2 10-15-2009 12:00 AM
Using GPIO (from kernel GPIO support) in MY application DannyGilbert Linux - Kernel 2 03-16-2009 07:52 AM
Simple Bit Bang Serial Driver Question Gnu2Linux2 Linux - Embedded & Single-board computer 1 08-06-2008 02:39 PM
Opensuse Servers Gone Bang? sniff SUSE / openSUSE 1 01-16-2008 11:10 AM
Help me. Crash! Bang! Boom! rkane Slackware 1 05-24-2003 03:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration