MOD-RTC with Linux - Anyone got it working

Started by dave-at-axon, March 31, 2014, 11:03:46 AM

Previous topic - Next topic

dave-at-axon

Has anyone gotten the MOD-RTC to work with Linux, be it the Android or Debian version?

I have a custom RTC on my carrier board base on a similar debice (I am using the DS1338) and I have built the kernel with the DS1307 enabled and disabled the rtc-sun7i driver.

I can see the driver being added to the i2c_core but the probe function, which sets up the driver and adds it to the rtc_driver_register, never gets called.

The sun7i kernel handles devices different to other kernels I've come across where the driver is added in the board.c file. As this file does not exist, I can't see any other way to add it.

Saying that, the module_i2c_driver() macro in the rtc-ds1307 driver should register it and it appears to do so as I see this in dmesg.

i2c-core: driver [rtc-ds1307] registered


I've added debug output to the start of the ds1307_probe() function but it never gets printed as the function never gets called.

Does anyone know how to get this driver to work? I want it part of the kernel, not separate, as it needs to be part of the Android system for time keeping.

I've also tried building as a module and insmod it in the init.rc but that still does not call ds1307_probe.

I need this as the built in rtc-sun7i driver does not support battery backup. My DS1338 has a lithium battery for backup.

rfk

#1
Hi Dave,


yes, it works!
I used the examples from githup: [size=78%]https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/A13/MOD-RTC[/size]
Just compiled the code from there on A20.
Works with battery for several weeks now.
For (Debian) startup, I slightly modified the script "/etc/init.d/hwclock.sh"
(Don't wonder about the strange path for MOD_RTC - its in the read-only part of a Fuse-unionfs)

in "start":

  case "$1" in
    start)
      echo ">> RFK: `date '+%F_%T (+%s)'` START: $0"
      # If the admin deleted the hwclock config, create a blank
      # template with the defaults.
      if [ -w /etc ] && [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then
          printf "0.0 0 0.0\n0\nUTC" > /etc/adjtime
      fi

      # ---------- RFK ------------
      echo ">> RFK: `date '+%F_%T (+%s)'` BEFORE set systemtime from MOD-RTC: $0"
      # /var/admin/MOD-RTC --verbose -s 2
      /sbin/MOD-RTC --verbose -s 2
      echo ">> RFK: `date '+%F_%T (+%s)'` AFTER set systemtime from MOD-RTC: $0"
      # ---------- RFK ------------





in "stop" - as first activity:




    stop|restart|reload|force-reload)
      #
      # Updates the Hardware Clock with the System Clock time.
      # This will *override* any changes made to the Hardware Clock.
      #
      # WARNING: If you disable this, any changes to the system
      #          clock will not be carried across reboots.
      #
      # ---------- RFK ------------
      echo ">> RFK: `date` STOP: $0"
      echo ">> RFK: `date '+%F_%T (+%s)'` BEFORE save to MOD-RTC: $0"
      # /var/admin/MOD-RTC --verbose -w 2
      /sbin/MOD-RTC --verbose -w 2
      # ---------- RFK ------------



hope it helps - no idea about Android,sorry
-- rfk

dave-at-axon

#2
I love kernel building and learning loads this last few weeks and I just got it working just before I saw your post... :)

I had to add the following code in the core.c file just after the sw_pdev_init(); line in the sun7i_init() function.


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


Note, I am using I2C-0 for my real time clock as my ADC on I2C-2 uses the same 0x68 address.

I also declared the following before this as:


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


The bit that got this working was the change of the name to ds1307 instead of rtc-ds1307 which was the name of the driver. Once I did this, the code to probe the driver was called and the device was initialised.

I now have a battery backed RTC that can withstand complete power downs of the system.