Skip to content

Commit 486486c

Browse files
TonyHan11kartben
authored andcommitted
soc: microchip: sam-clk: optimize get_rate() for MCKx clocks
Obtain the divisor value for generate the corresponding MCKx from the register instead of from the variable to avoid wrong result caused by un-synced division ratios. Signed-off-by: Tony Han <tony.han@microchip.com>
1 parent 5a4d714 commit 486486c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

soc/microchip/sam/common/clk-master.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ static int clk_mck_get_rate(const struct device *dev, clock_control_subsys_t sys
157157

158158
struct clk_master *master = to_clk_master(dev);
159159
int retval = 0;
160+
uint32_t mcr;
160161

161162
const struct device *parent;
163+
k_spinlock_key_t key;
162164
uint8_t i;
163165

164166
for (i = 0; ; i++) {
@@ -172,6 +174,12 @@ static int clk_mck_get_rate(const struct device *dev, clock_control_subsys_t sys
172174
}
173175
}
174176

177+
key = k_spin_lock(master->lock);
178+
master->pmc->PMC_MCR = master->id;
179+
mcr = master->pmc->PMC_MCR;
180+
master->div = FIELD_GET(PMC_MCR_DIV_Msk, mcr);
181+
k_spin_unlock(master->lock, key);
182+
175183
retval = clock_control_get_rate(parent, NULL, rate);
176184
if (retval) {
177185
LOG_ERR("get parent clock rate failed.");

0 commit comments

Comments
 (0)