Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

Getting data from a rtc device through I2C

Hi all,

I would like to retrieve information from a RTC device which is directly connected to a GPIO, using the i2c protocol. So, the first step was to load the i2c-gpio driver with this piece of code:

# define GPIO_RTC_SDA		100# define GPIO_RTC_SCL		99
MODULE_DESCRIPTION("i2c via gpio module");
MODULE_LICENSE("GPL");
static struct i2c_gpio_platform_data rtc_device_data = {
	.sda_pin = GPIO_RTC_SDA,
	.scl_pin = GPIO_RTC_SCL,
	.udelay  = 25
};
static struct platform_device i2c_gpio_bus_rtc = {
	.name 	= "i2c-gpio",
	.id		= 0,
	.dev	= {
		.platform_data = &rtc_device_data,
	}
};
static int __init i2c_gpio_bus_init(void)
{
	int ret;
	return platform_device_register(&i2c_gpio_bus_rtc);
}
static void __exit i2c_gpio_bus_exit(void)
{
	platform_device_unregister(&i2c_gpio_bus_rtc);
}
module_init(i2c_gpio_bus_init);
module_exit(i2c_gpio_bus_exit);

Once loaded, I get a new device in the /sys/bus/i2c/devices directory. For testing purpose I then use i2cdetect utility to scan the i2c bus to see if I could find my rtc device. But, I could not find it. So, I added manually a device at address 0x68 on the i2c bus with the following command:

echo m41t83 0x68 > /sys/devices/platform/i2c-gpio.0/i2c-0 (m41t83 is my rtc device) as it is explained in the Documentation/i2c/instantiating-devices file. However, it is still not working.

Does somebody understand what’s going on?

Info : I work with a nios II processor under linux (uClinux distrib). I use a device tree to setup board devices.

15 Replies