External Battery backed Real Time Clock (RTC) for A20 with Android

I decided that the built in A20 RTC was of no use because there was no way to add a battery backup to the board as Olimex had not brought out the RTC_VDD line from the processor.

As the DS1307, or in my case, the DS1338 was already supported by a kernel driver it should have been a simple process to remove the rtc-sun7i driver and rebuild the kernel with the rtc-ds1307 driver instead.

Well, the rtc-ds1307 driver inclusion was easy as I only had to locate it in the menuconfig for the kernel and enable it with <*>0 so that it would be built as part of the kernel. I didn’t want a module as it should be part of the OS and run on startup.

Well, after building the kernel, it would indeed run on startup and showed up on the dmesg output but rtc0 failed to be created in dev.

It took quite a bit of searching the internet and playing around but I finally figured it out and I was able to add the driver to the kernel and have it startup and create the rtc0 device.

Adding the i2c_board_info

As I2C devices are not auto detected in the system, you have to tell it what they are and where to find them. Locate the following file and edit the sun7i_init function at the bottom.


And insert the following after the sw_pdev_init() function.

 i2c_register_board_info(0, __rtc_i2c_board_info, ARRAY_SIZE(__rtc_i2c_board_info));

The first variable is the I2C bus your RTC is located on. For those who want to use the MOD_RTC on a UEXT, just change this line to match the I2C bus of that socket.

Now add the following at the top of the file, anywhere before the start of the other functions.

static struct i2c_board_info __rtc_i2c_board_info[] =  {
        I2C_BOARD_INFO("ds1307", 0x68),

Next add a #include <linux.i2c.h> to the top of the file so that we include the necessary drivers.

Now rebuild your kernel and then extract-bsp to the Android build and then make Android and pack and flash to your device. You should now have a working RTC but this time, it will be battery backed.

Any issues, pop them in the comments below.

By Dave McLaughlin

4 comments on “External Battery backed Real Time Clock (RTC) for A20 with Android

  1. Hi Dave,
    I am not using the same kernel as you (found a V3.0) and implemented your I2C changes… I haven’t got a chance to test it yet, but just FYI:

    The #include directive should be #include
    not #include as you mentionned.

    Thanks for all the hard work!

  2. Hello Dave,

    Did you manage to add and use the drivers for Invensense?
    Can you help me to add them in the core?

    Best regards,
    Ion Grozea (gvi70000 from olimex forum)

    • Sorry for the late reply.

      I have not needed to use the Invensense hardware so I have not tried to build for it.

      If you need this, you can edit the build and have it compile and then include this in your Android OS. Check if you need a driver from the Linux core too.

      I am busy on another project but I will try to get time to look at this later in the week for you and I’ll post back here how to build it into the core.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s