Skip to content

Commit a8cf696

Browse files
TonyHan11kartben
authored andcommitted
drivers: clock_control: microchip: sckc: optimize get_rate, get_status
Optimize sckc_get_rate() to be called without configurations in parameter, the selection of slow clock of the timing domain directly comes from the register. Optimize sckc_get_status() with return value "CLOCK_CONTROL_STATUS_ON", slow clock is always on either driven by the RC oscillator or by the 32.768 kHz crystal oscillator. Signed-off-by: Tony Han <tony.han@microchip.com>
1 parent eb1b2e0 commit a8cf696

File tree

1 file changed

+7
-32
lines changed

1 file changed

+7
-32
lines changed

drivers/clock_control/clock_control_sama7g5_sckc.c

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,15 @@ static int sckc_get_rate(const struct device *dev,
5151
uint32_t *rate)
5252
{
5353
ARG_UNUSED(dev);
54+
ARG_UNUSED(sys);
5455

56+
bool sel_xtal = (sckc_reg->SCKC_CR & SCKC_CR_TD_OSCSEL_Msk) ==
57+
SCKC_CR_TD_OSCSEL(SCKC_CR_TD_OSCSEL_XTAL_Val);
5558
int ret = 0;
5659

57-
const struct sam_sckc_config *cfg = sys;
58-
59-
if (cfg == NULL) {
60-
LOG_ERR("The SCKC config can not be NULL.");
61-
return -ENXIO;
62-
}
60+
LOG_DBG("%s Oscillator", sel_xtal ? "Crystal" : "RC");
6361

64-
LOG_DBG("%s Oscillator", cfg->crystal_osc ? "Crystal" : "RC");
65-
66-
if (cfg->crystal_osc) {
62+
if (sel_xtal) {
6763
ret = clock_control_get_rate(SAM_DT_SLOW_XTAL, NULL, rate);
6864
} else {
6965
*rate = KHZ(64);
@@ -77,30 +73,9 @@ static enum clock_control_status sckc_get_status(const struct device *dev,
7773
clock_control_subsys_t sys)
7874
{
7975
ARG_UNUSED(dev);
76+
ARG_UNUSED(sys);
8077

81-
const struct sam_sckc_config *cfg = sys;
82-
enum clock_control_status status = CLOCK_CONTROL_STATUS_OFF;
83-
84-
if (cfg == NULL) {
85-
LOG_ERR("The SCKC config can not be NULL.");
86-
return -ENXIO;
87-
}
88-
89-
LOG_DBG("%s Oscillator", cfg->crystal_osc ? "Crystal" : "RC");
90-
91-
if (cfg->crystal_osc) {
92-
if ((sckc_reg->SCKC_CR & SCKC_CR_Msk) ==
93-
SCKC_CR_TD_OSCSEL(SCKC_CR_TD_OSCSEL_XTAL_Val)) {
94-
status = CLOCK_CONTROL_STATUS_ON;
95-
}
96-
} else {
97-
if ((sckc_reg->SCKC_CR & SCKC_CR_Msk) ==
98-
SCKC_CR_TD_OSCSEL(SCKC_CR_TD_OSCSEL_RC_Val)) {
99-
status = CLOCK_CONTROL_STATUS_ON;
100-
}
101-
}
102-
103-
return status;
78+
return CLOCK_CONTROL_STATUS_ON;
10479
}
10580

10681
static DEVICE_API(clock_control, sckc_api) = {

0 commit comments

Comments
 (0)