0
votes

I need to get data from a RTC device (stm41t83) through I2C. The device is directly connected to two pins of a GPIO. I tried to use the i2c-gpio driver with the piece of code below,

#include <linux/module.h>
#include <linux/init.h>
#include <linux/i2c-gpio.h>
#include <linux/i2c.h>
#include <linux/platform_device.h>
#include <linux/kernel.h>

#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)
{
    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);

but when I use the i2cdetect utility from the i2c tools package, I can't see my RTC device located at 0x68. Do I need to add some other stuff to get it working?

Thanks for answers!

jrm

1
Are you sure the pin numbers are correct? This sounds stupid but when using an FPGA the GPIO pin numbers known by the Linux kernel may differ from the FPGA pin numbers. Maybe the Linux kernel does not see any of the FPGA pins! You might test this using "gpio_request(99, "scl");" in the kernel module. If 0 is returned you should call "gpio_free(99);". If non-zero is returned you know something is not working correctly. You sould also observe the value returned by platform_device_register.Martin Rosenau
Thank you for replying, Martin. Actually, my module calls the i2c-gpio driver which performs what you suggest me to test (gpio request/ free). When I load my kernel module, no error occurs on the gpio requests, so I guess everything is right? I printed the platform_device_register's return value which is equalled to 0.jrm
(continued), so the device is registered properly, isn't it? Do you know if I need a i2c chip driver to get data from it?jrm

1 Answers

0
votes

I finally solved my problem! I was not a software problem but rather a FPGA configuration issue. Follow this link, post #13 to know the answer.

Thanks to all ;-)