Add a real-time clock (RTC) to OpenWrt -- take MT7620 as an example

foreword

Real-time clock, the English name RTC (Real Time Clock), is very common in PC, but it is rarely mentioned in OpenWrt. There is a DS1307 TinyRTC real-time clock module on hand. After some tossing, it is integrated into the OpenWrt system. Then record the operation process.


background knowledge

DS1307 has been supported in the latest OpenWrt, but it has not been integrated into ramips. Therefore, a focus of this article is how to configure ds1307 for ramips system. In addition, writing a suitable dts node for ds1307 is also a focus of this article.


Implementation process

1. Configure ds1307 support for ramips

The system judges and processes the RTC_SUPPORT switch in ./scripts/medatata.pl. After analysis, it turns out that in target/linux/ramips/mt7620/target.mk, the

Original content:

FEATURES+=usb

change into:

FEATURES+=usb rtc

You can open mt7620's support for rtc.

At this point, make kernel_menuconfig enters the configuration menu. At the same time, it should be noted that since ds1307 is a module of the i2c interface, it is necessary to configure the support of i2c in the device. After selecting i2c, you can

See ds1307 in Device Drivers -> Real Time Clock

.config - Linux/mips 3.14.28 Kernel Configuration
 > Device Drivers > Real Time Clock ─────────────────────────────────────
  ┌──── Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSON RX-8025 ────┐
  │ CONFIG_RTC_DRV_DS1307:                                            │  
  │                                                                   │  
  │ If you say yes here you get support for various compatible RTC    │  
  │ chips (often with battery backup) connected with I2C. This driver │  
  │ should handle DS1307, DS1337, DS1338, DS1339, DS1340, ST M41T00,  │  
  │ EPSON RX-8025 and probably other chips. In some cases the RTC     │  
  │ must already have been initialized (by manufacturing or a         │  
  │ bootloader).                                                      │  
  │                                                                   │  
  │ The first seven registers on these chips hold an RTC, and other   │  
  │ registers may add features such as NVRAM, a trickle charger for   │  
  │ the RTC/NVRAM backup power, and alarms. NVRAM is visible in       │  
  │ sysfs, but other chip features may not be available.              │  
  │                                                                   │  
  │ This driver can also be built as a module. If so, the module      │  
  │ will be called rtc-ds1307.                                        │  
  │                                                                   │  
  │ Symbol: RTC_DRV_DS1307 [=y]                                       │  
  │ Type  : tristate                                                  │  
  │ Prompt: Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSON RX-8025 │  
  │   Location:                                                       │  
  │     -> Device Drivers                                             │  
  │       -> Real Time Clock (RTC_CLASS [=y])                         │  
  │   Defined at drivers/rtc/Kconfig:166                              │  
  │   Depends on: RTC_CLASS [=y] && I2C [=y]                          │  
  │                                                                   │  
  │                                                                   │  
  │                                                                   │  
  ├───────────────────────────────────────────────────────────(100%)──┤  
  │                             < Exit >                              │  
  └───────────────────────────────────────────────────────────────────┘  

2. Create a dts node for ds1307

After configuring the compile switch of ds1307, the next work is to add the device node of ds1307 in dts. Check the information of ds1307, the configured i2c address is 0x68, therefore, the following content can be added to dts:

	i2c@0 {
		compatible = "i2c-gpio";
		gpios = <&gpio2 0 0 /* sda = wan_led*/
				&gpio3 0 0 /* scl = wlan_led*/ >;
		i2c-gpio,delay-us = <10>;	/* ~20 kHz */
		#address-cells = <1>;
		#size-cells = <0>;
		
		rtc@68 {
			compatible = "dallas,ds1307";
			reg = <0x68>;
		};
		 
	};
After completing these two steps, you can make a firmware that supports ds1307.

When the system starts, you can see the following in the TTL:

[    0.130000] i2c-gpio i2c.4: using pins 40 (SDA) and 72 (SCL)
...
[    0.790000] rtc-ds1307 0-0068: rtc core: registered ds1307 as rtc0
[    0.810000] rtc-ds1307 0-0068: 56 bytes nvram
...
[    0.810000] rtc-ds1307 0-0068: setting system clock to 2015-01-26 22:31:15 UTC (1422311475)

It shows that the RTC has been successfully integrated into the mt7620 system.

ps: The hwclock command that comes with the system can easily operate the RTC accordingly.

postscript

The i2c-ralink driver in kernel 3.14.28 has been able to drive the 7620 hardware i2c normally, but when using i2cdetect, you need to add the -r parameter, so that you can correctly probe to the device.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325152023&siteId=291194637