Hardware Reference
In-Depth Information
kernel to search the I2C bus for an RTC, you need to have a special command-line option passed to the kernel at boot
time. It would look something like the following:
rtc.i2c=ds1307,0,0x68
This tells the Linux kernel to use the I2C bus to look for an RTC with the device type of DS1307 or an RTC that is
compatible on I2C bus 0 with the hex address of 0x68 . This command-line option depends on having the i2c-dev and
the rtc_ds1307 modules built in as part of the kernel. As you can see on the Raspberry Pi they are not built in; if the
module was built into the kernel you would not be able to use a tool like modinfo as it's no longer a kernel module but
part of the kernel itself. At this point you have two options.
First, you could compile your own kernel for the Raspberry Pi with the two above modules
built in. If you wanted to do this you could use the fast cross compile environment you
configured in Chapter 6.
If you don't want to recompile the kernel, you're going to need to compromise when your
RTC will come online. You've decided you don't want to have it come online early in the
boot process but you do not want it coming online too late into the system boot. If the RTC
comes on too late in the boot stages, you may find your boot messages are no longer in order
or the system logs appear to “jump” in time. It's not the end of the world but it's also not the
best outcome.
For this purpose I created an init.d script that will load and unload modules and create and remove the device
node. This script is written for Fedora and should work on any RHEL-type operating system. Take a look at Listing 8-1
to see the script. You need to create a file called /etc/init.d/pi-rtc and ensure that it has its execute bit set.
Listing 8-1. The init.d Script for the RTC
#!/bin/sh
#
# Author : Brendan Horan
# Description : To load and unload the ds1338 i2c rtc
# you should only need to change the address
#
# chkconfig: 12345 82 82
# description: I2C RTC
# Source function library.
if [ -e /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
fi
# set the hex address of the rtc chip
address=0x68
# Change nothing below this line
RETVAL=0
start() {
echo -n "Starting I2C RTC : "
modprobe i2c-dev
 
Search WWH ::




Custom Search