[OSD3358] How to set internal clock

Hi
I want to change the 32.768KHz OSC for RTC from external to internal.
I referenced the content of site below.
[Custom OSD3358 SiP] 4.19-RT-Kernel panic (shutdown)

I changed the file : 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch

+#if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
void rtc32k_enable(void)
{
+	struct davinci_rtc *rtc = (struct davinci_rtc *)RTC_BASE;
+
+	/*
+	 * Unlock the RTC's registers.  For more details please see the
+	 * RTC_SS section of the TRM.  In order to unlock we need to
+	 * write these specific values (keys) in this order.
+	 */
+	writel(RTC_KICK0R_WE, &rtc->kick0r);
+	writel(RTC_KICK1R_WE, &rtc->kick1r);
+
	if (board_is_pb() || board_is_blue()) {
		/* 6: EN_32KCLK */
		/* 3: SEL_32KCLK_SRC 0: internal, 1: external */
		writel((0 << 3) | (1 << 6), &rtc->osc);
	} else {
		/* Enable the RTC 32K OSC by setting bits 3 and 6. */
		writel((1 << 3) | (1 << 6), &rtc->osc);
	}
}
+#endif

Is it right?

and How can I configure the *.dts for the RTC change.
I am not good at kernel source.
Please, could you explain how to configure it for beaglebone black in detail

Regards.

Hi @taek8461,

Since you defined your board as “board_is_bblter” change this line:

   if (board_is_pb() || board_is_blue() || board_is_bblter()) {
   	/* 6: EN_32KCLK */
   	/* 3: SEL_32KCLK_SRC 0: internal, 1: external */
   	writel((0 << 3) | (1 << 6), &rtc->osc);
   } else {
   	/* Enable the RTC 32K OSC by setting bits 3 and 6. */
   	writel((1 << 3) | (1 << 6), &rtc->osc);
   }

For the kernel remove these 2 lines:

From:

&rtc {
	clocks = <&clk_32768_ck>, <&clk_24mhz_clkctrl AM3_CLK_24MHZ_CLKDIV32K_CLKCTRL 0>;
	clock-names = "ext-clk", "int-clk";
};

To:

&rtc {
};

That’ll get you the correct rtc clock set by u-boot

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/dts/am335x-bone-common.dtsi#n397

Regards,

Hi
Thank you for your help

I changed the file : 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch

+#if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
void rtc32k_enable(void)
{
+	struct davinci_rtc *rtc = (struct davinci_rtc *)RTC_BASE;
+
+	/*
+	 * Unlock the RTC's registers.  For more details please see the
+	 * RTC_SS section of the TRM.  In order to unlock we need to
+	 * write these specific values (keys) in this order.
+	 */
+	writel(RTC_KICK0R_WE, &rtc->kick0r);
+	writel(RTC_KICK1R_WE, &rtc->kick1r);
+
	if (board_is_pb() || board_is_blue() || board_is bblter()) {
		/* 6: EN_32KCLK */
		/* 3: SEL_32KCLK_SRC 0: internal, 1: external */
		writel((0 << 3) | (1 << 6), &rtc->osc);
	} else {
		/* Enable the RTC 32K OSC by setting bits 3 and 6. */
		writel((1 << 3) | (1 << 6), &rtc->osc);
	}
}
+#endif
...
...
static inline int board_is_bblter(void)
{
	return board_is_bone_lt() && !strncmp(board_ti_get_rev(), "LTER", 4);
}

and then, I run two command as below

patch -p1 < 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
patch -p1 < 0002-U-Boot-BeagleBone-Cape-Manager.patch

The following is the message after two command line run

I think the message show me some problems.

Could you let me know what I did wrong and how to fix it?

The following is install2_uboot.sh file.

image

please, help me.

Regards

Hi @taek8461, you just can’t randomly change lines in a *.patch file… Keep the original 2 patches the way they were, and create a 3rd patch with your actual changes.

The u-boot directory is a git repo, so it’s very easy to do a git diff and get your changes.

Regards,