imx: imx_clock: wdog: Add watchdog clock API
authorBryan O'Donoghue <[email protected]>
Fri, 13 Jul 2018 09:21:40 +0000 (10:21 +0100)
committerBryan O'Donoghue <[email protected]>
Tue, 4 Sep 2018 12:36:23 +0000 (13:36 +0100)
This patch adds a set of functions to enable the clock for each of the
watchdog IP blocks.

Unlike the MMC and UART blocks, the watchdog blocks operate off of the one
root clock, only the clock-gates are enable/disabled individually.

As a consequence the function clock_set_wdog_clk_root_bits() is used to set
the root-slice just once for all of the watchdog blocks.

Future implementations may need to change this model but for now on the one
supported processor and similar NXP SoCs this model should work fine.

Signed-off-by: Bryan O'Donoghue <[email protected]>
plat/imx/common/imx_clock.c
plat/imx/common/include/imx_clock.h

index 0a13d4db9f9d978e0c689a97260ff5d54917c5e5..09cd101b395c294c6dc8070c2a836fe237d8c3e0 100644 (file)
@@ -98,3 +98,37 @@ void imx_clock_enable_usdhc(unsigned int usdhc_id, uint32_t usdhc_clk_en_bits)
        /* Enable the clock gate */
        imx_clock_gate_enable(ccm_ccgr_id, true);
 }
+
+void imx_clock_enable_wdog(unsigned int wdog_id)
+{
+       unsigned int ccm_ccgr_id = CCM_CCGR_ID_WDOG1 + wdog_id;
+
+       /* Check for error */
+       if (wdog_id > MXC_MAX_WDOG_NUM)
+               return;
+
+       /* Enable the clock gate */
+       imx_clock_gate_enable(ccm_ccgr_id, true);
+}
+
+void imx_clock_disable_wdog(unsigned int wdog_id)
+{
+       unsigned int ccm_trgt_id = CCM_TRT_ID_WDOG_CLK_ROOT;
+       unsigned int ccm_ccgr_id = CCM_CCGR_ID_WDOG1 + wdog_id;
+
+       /* Check for error */
+       if (wdog_id > MXC_MAX_WDOG_NUM)
+               return;
+
+       /* Disable the clock gate */
+       imx_clock_gate_enable(ccm_ccgr_id, false);
+
+       /* Clear the target */
+       imx_clock_target_clr(ccm_trgt_id, 0xFFFFFFFF);
+}
+
+void imx_clock_set_wdog_clk_root_bits(uint32_t wdog_clk_root_en_bits)
+{
+       /* Enable the common clock root just once */
+       imx_clock_target_set(CCM_TRT_ID_WDOG_CLK_ROOT, wdog_clk_root_en_bits);
+}
index 51717c4b3b8c68be926ae00fbad4c73019e8acae..27858bbda14f77a612ec5c22033ccc25c5e96d34 100644 (file)
@@ -992,5 +992,8 @@ void imx_clock_init(void);
 void imx_clock_enable_uart(unsigned int uart_id, uint32_t uart_clk_en_bits);
 void imx_clock_disable_uart(unsigned int uart_id);
 void imx_clock_enable_usdhc(unsigned int usdhc_id, uint32_t usdhc_clk_en_bits);
+void imx_clock_set_wdog_clk_root_bits(uint32_t wdog_clk_root_en_bits);
+void imx_clock_enable_wdog(unsigned int wdog_id);
+void imx_clock_disable_wdog(unsigned int wdog_id);
 
 #endif /* __IMX_CLOCK_H__ */