cancel
Showing results for 
Search instead for 
Did you mean: 

RTC TimeStamp enable from RTC Linux Driver

jutoroa
Associate III

Hello!

I'm currently working with a stm32mp157f-dk2 development kit and designing a custom PCB with a STM32MP153A. I have working with the Developer/Distribution package of openST. I want to enable the TimeStamp function of the RTC, and be able to read the TimeStamp Time Register (RTC_TSTR) and Date Register (RTC_TSDR). I have been looking information for some time and I didn't found any support in the RTC linux driver bindings (<linux/rtc.h>), or in the stm32-rtc linux driver (<linux/drivers/rtc/rtc-stm32.c>). Also in the wiki I have not been able to find information about it's integration with the device tree. I have already check this post about reading from the M4:  https://community.st.com/t5/stm32-mpus-products/how-can-the-cortex-m4-access-to-rtc-timestamp/td-p/276948 . But for reading the timestamp I have to enable it from the linux core.

Does anyone have any suggestions on how this situation can be addressed?

I have been modifying the linux driver, but I'm not sure if there is a more simplier way to do it.

Thank you!

1 REPLY 1
jutoroa
Associate III

 

 

/* Function to enable the timestamp edge detection in the control register */
static int stm32_rtc_set_timestamp(struct platform_device *pdev, struct stm32_rtc *rtc)
{
	const struct stm32_rtc_registers *regs = &rtc->data->regs;
	unsigned int cr;

	/* Start the configuration for the timestamp */
	stm32_rtc_wpr_unlock(rtc);

	cr = readl_relaxed(rtc->base + regs->cr);
	dev_dbg(&pdev->dev, "CR: %u\n", cr);

	cr &= ~STM32_RTC_CR_TSE;   // Turn off the TSE
	writel_relaxed(0b0, rtc->base + regs->cr);
	
	cr |= STM32_RTC_CR_TSEDGE;	// Set the TSE Edge
	writel_relaxed(cr, rtc->base + regs->cr);

	cr |= STM32_RTC_CR_TSE;		// Turn on the TSE
	writel_relaxed(cr, rtc->base + regs->cr);
	
       /* Read to CR to check the data*/
	cr = readl_relaxed(rtc->base + regs->cr);
	dev_dbg(&pdev->dev, "CR modified: %u \n", cr);

	stm32_rtc_wpr_lock(rtc);

	return 0;
}

 

 

Currently we have modified the rtc-stm32.c file from the Developer Package linux source code (linux/drivers/rtc/rtc-stm32.c), following the steps in the reference manual to enable write access to the RTC protected registers, without success.

I have made the function 
stm32_rtc_set_timestamp() to modify the control register (CR), and be call in the 

stm32_rtc_probe() function after the line:
----> ret = stm32_rtc_init(pdev, rtc); 
Without success.
Anyone have some clue about what it's missing to be able to write in the CR of the RTC? It's necessary to Disable backup domain write protection in the PWR to acces the RTC protected registers (PWR_CR1_DBP)? How can I do it from the linux driver?

Thank you in advance!