BeagleBone - registering DS1307 RTC with kernel at boot up

Hello,

Beginner question; I have a working ds1307 that I can talk to with

echo ds3232 0x68 >/sys/bus/i2c/devices/i2c-3/new_device

from there I can do wonderful things such as

hwclock -f /dev/rtc1 -s

As a beginner I’m tempted to quit while I’m ahead and script these at start up. However, I’d like to try and register these with the kernel ‘properly’.

I believe I need to add the device to arch/arm/mach-omap2/board-omap3beagle.c - is this correct?

and, if so according to http://www.mjmwired.net/kernel/Documentation/i2c/instantiating-devices then I guess I need to write in something like this, that was already in there?
(presumably I can’t just add my ds1307 into this structure - because it’s probably on another bus??)

static struct i2c_board_info __initdata beagle_i2c_eeprom[] = { { I2C_BOARD_INFO("eeprom", 0x50), }, };

and I should add something in somewhere in static void __init omap3_beagle_init(void) ?

Although, in here I see omap3_beagle_i2c_init();

so should I add something in static int __init omap3_beagle_i2c_init(void) instead?

What I type is the next question… my first guess for adding some i2c_board_info would be;

`

static struct i2c_board_info __initdata rtc_i2c_device[] = {
{ /* DS1307 RTC on i2c2 */
I2C_BOARD_INFO(“ds1307”, 0x68),
.type = “ds1339”,
}

`

(i just copied https://github.com/bootc/linux/blob/rpi-3.2.21/arch/arm/mach-at91/board-cpu9krea.c#L276 there)

I’m not confident about the call to i2c_register_board_info…

do i just add

i2c_register_board_info(2, rtc_i2c_device, ARRAY_SIZE(rtc_i2c_device));

to omap3_beagle_i2c_init()

As you can probably tell, I’ve not done this before. I’ve tried to help myself as much as I can, but i’m getting diminishing returns from the worlds favorite search engine now. Am I very far off the mark?

Regards,

Michael

isn't there a specific board-file for the Bone? I see you use the
board-file for the Beagleboard while they have absolutely different
architecture.

Here is what I did for making a DS1307 like device – rtc-beada built into Pandaboard kernel:

  1. Board file board-omap4panda.c

/*

  • BeadaFrame RTC is connected as I2C slave device, and can be accessed at address 0x51
    */
    static struct i2c_board_info __initdata panda_i2c_beada_rtc[] = {
    {
    I2C_BOARD_INFO(“rtc-beada”, 0x51),
    },
    {
    I2C_BOARD_INFO(“tsc-beada”, 0x52),
    },
    {
    I2C_BOARD_INFO(“pwm-beada”, 0x53),
    },
    };

static int __init omap4_panda_i2c_init(void)
{
omap4_pmic_get_config(&omap4_panda_twldata, TWL_COMMON_PDATA_USB,
TWL_COMMON_REGULATOR_VDAC |
TWL_COMMON_REGULATOR_VAUX2 |
TWL_COMMON_REGULATOR_VAUX3 |
TWL_COMMON_REGULATOR_VMMC |
TWL_COMMON_REGULATOR_VPP |
TWL_COMMON_REGULATOR_VANA |
TWL_COMMON_REGULATOR_VCXIO |
TWL_COMMON_REGULATOR_VUSB |
TWL_COMMON_REGULATOR_CLK32KG);
omap4_pmic_init(“twl6030”, &omap4_panda_twldata);
omap_register_i2c_bus(2, 100, panda_i2c_beada_rtc, ARRAY_SIZE(panda_i2c_beada_rtc));
/*

  • Bus 3 is attached to the DVI port where devices like the pico DLP
  • projector don’t work reliably with 400kHz
    */
    omap_register_i2c_bus(3, 100, panda_i2c_eeprom,
    ARRAY_SIZE(panda_i2c_eeprom));
    omap_register_i2c_bus(4, 400, NULL, 0);
    return 0;
    }
  1. .config file
    CONFIG_RTC_LIB=y
    CONFIG_RTC_CLASS=y
    CONFIG_RTC_HCTOSYS=y
    CONFIG_RTC_HCTOSYS_DEVICE=“rtc0”

CONFIG_RTC_DEBUG is not set

EDIT: Of course, with a DS1307 just use “ds1307” instead. ← pre-coffee

Thanks everyone - that’s all really helpful. I’ll give myself a few marks for effort!

I thought I probably had the wrong board file, hence the question.

Thanks for the CONFIG hints too. I’m using ubuntu precise armhf 12.04… and looking at the config I had, it looked like most of it was there - but it looks like the rtc0/rtc1 business would have tripped me up.

I’ll let you now how I get on, post-coffee.