Lines Matching +full:post +full:- +full:div2
2 * Copyright (c) 2022 Andrei-Edward Popa
5 * SPDX-License-Identifier: Apache-2.0
14 #include <zephyr/dt-bindings/clock/rpi_pico_rp2040_clock.h>
16 #include <zephyr/dt-bindings/clock/rpi_pico_rp2350_clock.h>
68 * Using the 'clock-names[0]' for expanding macro to frequency value.
69 * The 'clock-names[0]' is set same as label value that given to the node itself.
147 (-1)) \
151 rpi_pico_clkid_none = -1,
224 const struct clock_control_rpi_pico_config *config = dev->config; in rpi_pico_frequency_count()
226 fc_hw_t *fc0 = &config->clocks_regs->fc0; in rpi_pico_frequency_count()
272 return -1; in rpi_pico_frequency_count()
277 return ((fc0->result >> CLOCKS_FC0_RESULT_KHZ_LSB) * 1000) + in rpi_pico_frequency_count()
278 ((fc0->result & CLOCKS_FC0_RESULT_FRAC_BITS) * 1000 / CLOCKS_FC0_RESULT_FRAC_BITS); in rpi_pico_frequency_count()
283 hw_clear_bits(&rosc_hw->status, ROSC_STATUS_BADWRITE_BITS); in rpi_pico_rosc_write()
285 if (rosc_hw->status & ROSC_STATUS_BADWRITE_BITS) { in rpi_pico_rosc_write()
286 return -EINVAL; in rpi_pico_rosc_write()
291 if (rosc_hw->status & ROSC_STATUS_BADWRITE_BITS) { in rpi_pico_rosc_write()
292 return -EINVAL; in rpi_pico_rosc_write()
307 const struct clock_control_rpi_pico_config *config = dev->config; in rpi_pico_get_clock_src()
331 clock_hw_t *clock_hw = &config->clocks_regs->clk[id]; in rpi_pico_get_clock_src()
332 uint32_t aux = ((clock_hw->ctrl & CTRL_AUXSRC_BITS) >> CTRL_AUXSRC_LSB); in rpi_pico_get_clock_src()
344 clock_hw_t *clock_hw = &clocks_hw->clk[id]; in rpi_pico_get_clock_src()
345 uint32_t aux = ((clock_hw->ctrl & CTRL_AUXSRC_BITS) >> CTRL_AUXSRC_LSB); in rpi_pico_get_clock_src()
346 uint32_t src = ((clock_hw->ctrl >> CTRL_SRC_LSB) & CTRL_SRC_BITS); in rpi_pico_get_clock_src()
367 clock_hw_t *clock_hw = &clocks_hw->clk[id]; in rpi_pico_get_clock_src()
368 uint32_t aux = ((clock_hw->ctrl & CTRL_AUXSRC_BITS) >> CTRL_AUXSRC_LSB); in rpi_pico_get_clock_src()
369 uint32_t src = ((clock_hw->ctrl >> CTRL_SRC_LSB) & CTRL_SRC_BITS); in rpi_pico_get_clock_src()
389 clock_hw_t *clock_hw = &clocks_hw->clk[id]; in rpi_pico_get_clock_src()
390 uint32_t aux = ((clock_hw->ctrl & CTRL_AUXSRC_BITS) >> CTRL_AUXSRC_LSB); in rpi_pico_get_clock_src()
412 clock_hw_t *clock_hw = &clocks_hw->clk[id]; in rpi_pico_get_clock_src()
413 uint32_t aux = ((clock_hw->ctrl & CTRL_AUXSRC_BITS) >> CTRL_AUXSRC_LSB); in rpi_pico_get_clock_src()
440 const struct clock_control_rpi_pico_config *config = dev->config; in rpi_pico_is_clock_enabled()
454 clock_hw_t *clock_hw = &config->clocks_regs->clk[id]; in rpi_pico_is_clock_enabled()
456 if (clock_hw->ctrl & CTRL_ENABLE_BITS) { in rpi_pico_is_clock_enabled()
460 pll_hw_t *pll = (id == rpi_pico_clkid_pll_sys) ? config->pll_sys_regs in rpi_pico_is_clock_enabled()
461 : config->pll_usb_regs; in rpi_pico_is_clock_enabled()
463 if (!(pll->pwr & (PLL_PWR_VCOPD_BITS | PLL_PWR_POSTDIVPD_BITS | PLL_PWR_PD_BITS))) { in rpi_pico_is_clock_enabled()
467 if (config->xosc_regs->status & XOSC_STATUS_ENABLED_BITS) { in rpi_pico_is_clock_enabled()
486 const struct clock_control_rpi_pico_config *config = dev->config; in rpi_pico_calc_clock_freq()
487 struct clock_control_rpi_pico_data *data = dev->data; in rpi_pico_calc_clock_freq()
505 clock_hw_t *clock_hw = &config->clocks_regs->clk[id]; in rpi_pico_calc_clock_freq()
508 (((clock_hw->div & DIV_INT_BITS) >> DIV_INT_LSB) + in rpi_pico_calc_clock_freq()
509 ((clock_hw->div & DIV_FRAC_BITS) / (float)DIV_FRAC_BITS)); in rpi_pico_calc_clock_freq()
513 pll_hw_t *pll = (id == rpi_pico_clkid_pll_sys) ? config->pll_sys_regs in rpi_pico_calc_clock_freq()
514 : config->pll_usb_regs; in rpi_pico_calc_clock_freq()
516 (pll->fbdiv_int) / (pll->cs & PLL_CS_REFDIV_BITS) / in rpi_pico_calc_clock_freq()
517 ((pll->prim & PLL_PRIM_POSTDIV1_BITS) >> PLL_PRIM_POSTDIV1_LSB) / in rpi_pico_calc_clock_freq()
518 ((pll->prim & PLL_PRIM_POSTDIV2_BITS) >> PLL_PRIM_POSTDIV2_LSB); in rpi_pico_calc_clock_freq()
522 freq = data->rosc_freq; in rpi_pico_calc_clock_freq()
524 freq = data->rosc_ph_freq; in rpi_pico_calc_clock_freq()
533 return -EINVAL; in rpi_pico_is_valid_clock_index()
541 const struct clock_control_rpi_pico_config *config = dev->config; in clock_control_rpi_pico_on()
545 return -EINVAL; in clock_control_rpi_pico_on()
550 hw_clear_bits(&config->pll_sys_regs->pwr, PLL_PWR_BITS); in clock_control_rpi_pico_on()
553 hw_clear_bits(&config->pll_usb_regs->pwr, PLL_PWR_BITS); in clock_control_rpi_pico_on()
556 hw_set_bits(&config->clocks_regs->clk[clkid].ctrl, CTRL_ENABLE_BITS); in clock_control_rpi_pico_on()
564 const struct clock_control_rpi_pico_config *config = dev->config; in clock_control_rpi_pico_off()
568 return -EINVAL; in clock_control_rpi_pico_off()
573 hw_set_bits(&config->pll_sys_regs->pwr, PLL_PWR_BITS); in clock_control_rpi_pico_off()
576 hw_set_bits(&config->pll_usb_regs->pwr, PLL_PWR_BITS); in clock_control_rpi_pico_off()
579 hw_clear_bits(&config->clocks_regs->clk[clkid].ctrl, CTRL_ENABLE_BITS); in clock_control_rpi_pico_off()
591 return -EINVAL; in clock_control_rpi_pico_get_status()
604 struct clock_control_rpi_pico_data *data = dev->data; in clock_control_rpi_pico_get_rate()
608 return -EINVAL; in clock_control_rpi_pico_get_rate()
613 data->rosc_freq = rpi_pico_frequency_count(dev, sys); in clock_control_rpi_pico_get_rate()
615 data->rosc_ph_freq = rpi_pico_frequency_count(dev, sys); in clock_control_rpi_pico_get_rate()
635 uint32_t target = -1; in rpi_pico_clkid_tuple_reorder_by_dependencies()
651 const struct clock_control_rpi_pico_config *config = dev->config; in clock_control_rpi_pico_init()
652 struct clock_control_rpi_pico_data *data = dev->data; in clock_control_rpi_pico_init()
653 clocks_hw_t *clocks_regs = config->clocks_regs; in clock_control_rpi_pico_init()
654 rosc_hw_t *rosc_regs = config->rosc_regs; in clock_control_rpi_pico_init()
655 pll_hw_t *plls[] = {config->pll_sys_regs, config->pll_usb_regs}; in clock_control_rpi_pico_init()
685 clocks_regs->resus.ctrl = 0; in clock_control_rpi_pico_init()
691 clocks_hw->clk[RPI_PICO_CLKID_CLK_SYS].ctrl &= ~CTRL_SRC_BITS; in clock_control_rpi_pico_init()
692 while (clocks_hw->clk[RPI_PICO_CLKID_CLK_SYS].selected != 0x1) { in clock_control_rpi_pico_init()
695 clocks_hw->clk[RPI_PICO_CLKID_CLK_REF].ctrl &= ~CTRL_SRC_BITS; in clock_control_rpi_pico_init()
696 while (clocks_hw->clk[RPI_PICO_CLKID_CLK_REF].selected != 0x1) { in clock_control_rpi_pico_init()
702 pll_init(plls[i], config->plls_data[i].ref_div, in clock_control_rpi_pico_init()
703 CLOCK_FREQ_xosc * config->plls_data[i].fb_div, in clock_control_rpi_pico_init()
704 config->plls_data[i].post_div1, config->plls_data[i].post_div2); in clock_control_rpi_pico_init()
714 if (!(clock_configure(tuples[i].clk, config->clocks_data[tuples[i].clk].source, in clock_control_rpi_pico_init()
715 config->clocks_data[tuples[i].clk].aux_source, in clock_control_rpi_pico_init()
716 config->clocks_data[tuples[i].clk].source_rate, in clock_control_rpi_pico_init()
717 config->clocks_data[tuples[i].clk].rate))) { in clock_control_rpi_pico_init()
718 return -EINVAL; in clock_control_rpi_pico_init()
722 hw_clear_bits(&clocks_regs->clk[rpi_pico_clkid_clk_gpout0].ctrl, CTRL_ENABLE_BITS); in clock_control_rpi_pico_init()
723 hw_clear_bits(&clocks_regs->clk[rpi_pico_clkid_clk_gpout1].ctrl, CTRL_ENABLE_BITS); in clock_control_rpi_pico_init()
724 hw_clear_bits(&clocks_regs->clk[rpi_pico_clkid_clk_gpout2].ctrl, CTRL_ENABLE_BITS); in clock_control_rpi_pico_init()
725 hw_clear_bits(&clocks_regs->clk[rpi_pico_clkid_clk_gpout3].ctrl, CTRL_ENABLE_BITS); in clock_control_rpi_pico_init()
728 ret = rpi_pico_rosc_write(dev, &rosc_regs->phase, in clock_control_rpi_pico_init()
730 config->rosc_data.phase); in clock_control_rpi_pico_init()
735 ret = rpi_pico_rosc_write(dev, &rosc_regs->ctrl, in clock_control_rpi_pico_init()
737 config->rosc_data.range); in clock_control_rpi_pico_init()
742 if (config->rosc_data.div <= 0) { in clock_control_rpi_pico_init()
744 } else if (config->rosc_data.div > 31) { in clock_control_rpi_pico_init()
747 rosc_div = ROSC_DIV_VALUE_PASS + config->rosc_data.div; in clock_control_rpi_pico_init()
750 ret = rpi_pico_rosc_write(dev, &rosc_regs->div, rosc_div); in clock_control_rpi_pico_init()
755 ret = rpi_pico_rosc_write(dev, &rosc_regs->freqa, in clock_control_rpi_pico_init()
757 (config->rosc_data.code & UINT16_MAX)); in clock_control_rpi_pico_init()
762 ret = rpi_pico_rosc_write(dev, &rosc_regs->freqb, in clock_control_rpi_pico_init()
764 (config->rosc_data.code >> 16)); in clock_control_rpi_pico_init()
772 data->rosc_freq = in clock_control_rpi_pico_init()
774 data->rosc_ph_freq = rpi_pico_frequency_count( in clock_control_rpi_pico_init()
778 ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in clock_control_rpi_pico_init()
779 if (ret < 0 && ret != -ENOENT) { in clock_control_rpi_pico_init()
797 "pll_sys: fb-div is out of range");
799 "pll_sys: post-div1 is out of range");
801 "pll_sys: post-div2 is out of range");
807 "pll_usb: fb-div is out of range");
809 "pll_usb: post-div is out of range");
811 "pll_usb: post-div is out of range");