Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
089c245
drivers: clock_control: Added clock driver for Raspberry Pi Pico
andrei-edward-popa Mar 18, 2023
f0aecbf
drivers: clock_control: rpi_pico: Configure GPOUT/GPIN pins
soburi Sep 9, 2023
7a339f0
drivers: watchdog: Changed how to get xtal frequency for Raspberry Pi…
andrei-edward-popa Dec 8, 2022
2817f35
drivers: serial: Removed all function calls from Raspberry Pi Pico SDK
andrei-edward-popa Mar 18, 2023
66b2041
drivers: spi: Changed how to get clock frequency for PL022
andrei-edward-popa Mar 18, 2023
0ff36cf
drivers: spi: pl022: Reset device on initializing
soburi Sep 8, 2023
d342c38
driver: pwm: rpi_pico: Change to use clock controller
soburi Aug 31, 2023
95c2c2b
drivers: pwm: rpi_pico: Reset device on init
soburi Sep 30, 2023
e7f7ec1
drivers: adc: rpi_pico: Turn on clock and reset device on init
soburi Sep 7, 2023
a24712a
drivers: misc: pio_rpi_pico: Turn on clock and reset device on init
soburi Sep 7, 2023
b8ffb90
drivers: usb: rpi_pico: Turn on clock on initializing
soburi Sep 7, 2023
de27520
drivers: counter: rpi_pico: Turn on clock and reset device on init
soburi Sep 13, 2023
2ae441a
driver: spi: spi_rpi_pico_pio: Change to use clock controller
soburi Sep 30, 2023
cbc2b31
boards: arm: rpi_pico: Added clock support in documentation
soburi Sep 30, 2023
6d65246
boards: arm: adafruit_kb2040: Added clock support in docs
soburi Aug 31, 2023
f280bb4
boards: arm: sparkfun_pro_micro_rp2040: Added clock support in docs
soburi Aug 31, 2023
a31739d
boards: arm: rpi_pico_w: Added counter support in docs
soburi Sep 30, 2023
2b081cb
boards: arm: adafruit_kb2040: Added counter support in docs
soburi Sep 30, 2023
6df5554
boards: arm: sparkfun_pro_micro_rp2040: Added counter support in docs
soburi Sep 30, 2023
d6f8d17
modules: hal_rpi_pico: Remove unused drivers
soburi Aug 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions boards/arm/adafruit_kb2040/adafruit_kb2040-pinctrl.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@
input-enable;
};
};

clocks_default: clocks_default {
};
};
11 changes: 5 additions & 6 deletions boards/arm/adafruit_kb2040/adafruit_kb2040.dts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
aliases {
watchdog0 = &wdt0;
};

xtal_clk: xtal-clk {
compatible = "fixed-clock";
clock-frequency = <12000000>;
#clock-cells = <0>;
};
};

&flash0 {
Expand Down Expand Up @@ -60,6 +54,11 @@
};
};

&clocks {
pinctrl-0 = <&clocks_default>;
pinctrl-names = "default";
};

&uart0 {
current-speed = <115200>;
status = "okay";
Expand Down
2 changes: 2 additions & 0 deletions boards/arm/adafruit_kb2040/adafruit_kb2040.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ supported:
- pwm
- flash
- dma
- counter
- clock
3 changes: 3 additions & 0 deletions boards/arm/adafruit_kb2040/adafruit_kb2040_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ CONFIG_UART_CONSOLE=y
# Enable reset by default
CONFIG_RESET=y

# Enable clock control by default
CONFIG_CLOCK_CONTROL=y

# Code partition needed to target the correct flash range
CONFIG_USE_DT_CODE_PARTITION=y

Expand Down
3 changes: 3 additions & 0 deletions boards/arm/adafruit_kb2040/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ hardware features:
* - Flash
- :kconfig:option:`CONFIG_FLASH`
- :dtcompatible:`raspberrypi,pico-flash`
* - Clock controller
- :kconfig:option:`CONFIG_CLOCK_CONTROL`
- :dtcompatible:`raspberrypi,pico-clock-controller`
* - UART (PIO)
- :kconfig:option:`CONFIG_SERIAL`
- :dtcompatible:`raspberrypi,pico-uart-pio`
Expand Down
3 changes: 3 additions & 0 deletions boards/arm/rpi_pico/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ hardware features:
* - Flash
- :kconfig:option:`CONFIG_FLASH`
- :dtcompatible:`raspberrypi,pico-flash`
* - Clock controller
- :kconfig:option:`CONFIG_CLOCK_CONTROL`
- :dtcompatible:`raspberrypi,pico-clock-controller`
* - UART (PIO)
- :kconfig:option:`CONFIG_SERIAL`
- :dtcompatible:`raspberrypi,pico-uart-pio`
Expand Down
11 changes: 5 additions & 6 deletions boards/arm/rpi_pico/rpi_pico-common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
zephyr,code-partition = &code_partition;
};

xtal_clk: xtal-clk {
compatible = "fixed-clock";
clock-frequency = <12000000>;
#clock-cells = <0>;
};

aliases {
watchdog0 = &wdt0;
};
Expand Down Expand Up @@ -94,6 +88,11 @@
};
};

&clocks {
pinctrl-0 = <&clocks_default>;
pinctrl-names = "default";
};

&uart0 {
current-speed = <115200>;
status = "okay";
Expand Down
3 changes: 3 additions & 0 deletions boards/arm/rpi_pico/rpi_pico-pinctrl.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@
input-enable;
};
};

clocks_default: clocks_default {
};
};
1 change: 1 addition & 0 deletions boards/arm/rpi_pico/rpi_pico.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ supported:
- flash
- dma
- counter
- clock
1 change: 1 addition & 0 deletions boards/arm/rpi_pico/rpi_pico_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ CONFIG_BUILD_OUTPUT_UF2=y
CONFIG_BUILD_OUTPUT_HEX=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_RESET=y
CONFIG_CLOCK_CONTROL=y
2 changes: 2 additions & 0 deletions boards/arm/rpi_pico/rpi_pico_w.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ supported:
- flash
- dma
- pio
- counter
- clock
1 change: 1 addition & 0 deletions boards/arm/rpi_pico/rpi_pico_w_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ CONFIG_BUILD_OUTPUT_UF2=y
CONFIG_BUILD_OUTPUT_HEX=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_RESET=y
CONFIG_CLOCK_CONTROL=y
3 changes: 3 additions & 0 deletions boards/arm/sparkfun_pro_micro_rp2040/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ hardware features:
* - Flash
- :kconfig:option:`CONFIG_FLASH`
- :dtcompatible:`raspberrypi,pico-flash`
* - Clock controller
- :kconfig:option:`CONFIG_CLOCK_CONTROL`
- :dtcompatible:`raspberrypi,pico-clock-controller`
* - UART (PIO)
- :kconfig:option:`CONFIG_SERIAL`
- :dtcompatible:`raspberrypi,pico-uart-pio`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@
input-enable;
};
};

clocks_default: clocks_default {
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
aliases {
watchdog0 = &wdt0;
};

xtal_clk: xtal-clk {
compatible = "fixed-clock";
clock-frequency = <12000000>;
#clock-cells = <0>;
};
};

&flash0 {
Expand Down Expand Up @@ -62,6 +56,10 @@
};
};

&clocks {
pinctrl-0 = <&clocks_default>;
pinctrl-names = "default";
};

&uart0 {
current-speed = <115200>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ supported:
- pwm
- flash
- dma
- counter
- clock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

# Enable clock control by default
CONFIG_CLOCK_CONTROL=y

# Code partition needed to target the correct flash range
CONFIG_USE_DT_CODE_PARTITION=y

Expand Down
71 changes: 46 additions & 25 deletions drivers/adc/adc_rpi_pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#define DT_DRV_COMPAT raspberrypi_pico_adc

#include <zephyr/drivers/adc.h>
#include <zephyr/drivers/clock_control.h>
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/drivers/reset.h>
#include <zephyr/logging/log.h>

#include <hardware/adc.h>
Expand Down Expand Up @@ -36,6 +38,12 @@ struct adc_rpi_config {
const struct pinctrl_dev_config *pcfg;
/** function pointer to irq setup */
void (*irq_configure)(void);
/** Pointer to clock controller device */
const struct device *clk_dev;
/** Clock id of ADC clock */
clock_control_subsys_t clk_id;
/** Reset controller config */
const struct reset_dt_spec reset;
};

/**
Expand Down Expand Up @@ -299,6 +307,16 @@ static int adc_rpi_init(const struct device *dev)
return ret;
}

ret = clock_control_on(config->clk_dev, config->clk_id);
if (ret < 0) {
return ret;
}

ret = reset_line_toggle_dt(&config->reset);
if (ret < 0) {
return ret;
}

config->irq_configure();

/*
Expand Down Expand Up @@ -332,31 +350,34 @@ static int adc_rpi_init(const struct device *dev)

#define IRQ_CONFIGURE_DEFINE(idx) .irq_configure = adc_rpi_configure_func_##idx

#define ADC_RPI_INIT(idx) \
IRQ_CONFIGURE_FUNC(idx) \
PINCTRL_DT_INST_DEFINE(idx); \
static struct adc_driver_api adc_rpi_api_##idx = { \
.channel_setup = adc_rpi_channel_setup, \
.read = adc_rpi_read, \
.ref_internal = DT_INST_PROP(idx, vref_mv), \
IF_ENABLED(CONFIG_ADC_ASYNC, (.read_async = adc_rpi_read_async,)) \
}; \
static const struct adc_rpi_config adc_rpi_config_##idx = { \
.num_channels = ADC_RPI_CHANNEL_NUM, \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
IRQ_CONFIGURE_DEFINE(idx), \
}; \
static struct adc_rpi_data adc_rpi_data_##idx = { \
ADC_CONTEXT_INIT_TIMER(adc_rpi_data_##idx, ctx), \
ADC_CONTEXT_INIT_LOCK(adc_rpi_data_##idx, ctx), \
ADC_CONTEXT_INIT_SYNC(adc_rpi_data_##idx, ctx), \
.dev = DEVICE_DT_INST_GET(idx), \
}; \
\
DEVICE_DT_INST_DEFINE(idx, adc_rpi_init, NULL, \
&adc_rpi_data_##idx, \
&adc_rpi_config_##idx, POST_KERNEL, \
CONFIG_ADC_INIT_PRIORITY, \
#define ADC_RPI_INIT(idx) \
IRQ_CONFIGURE_FUNC(idx) \
PINCTRL_DT_INST_DEFINE(idx); \
static struct adc_driver_api adc_rpi_api_##idx = { \
.channel_setup = adc_rpi_channel_setup, \
.read = adc_rpi_read, \
.ref_internal = DT_INST_PROP(idx, vref_mv), \
IF_ENABLED(CONFIG_ADC_ASYNC, (.read_async = adc_rpi_read_async,)) \
}; \
static const struct adc_rpi_config adc_rpi_config_##idx = { \
.num_channels = ADC_RPI_CHANNEL_NUM, \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
.clk_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \
.clk_id = (clock_control_subsys_t)DT_INST_PHA_BY_IDX(idx, clocks, 0, clk_id), \
.reset = RESET_DT_SPEC_INST_GET(idx), \
IRQ_CONFIGURE_DEFINE(idx), \
}; \
static struct adc_rpi_data adc_rpi_data_##idx = { \
ADC_CONTEXT_INIT_TIMER(adc_rpi_data_##idx, ctx), \
ADC_CONTEXT_INIT_LOCK(adc_rpi_data_##idx, ctx), \
ADC_CONTEXT_INIT_SYNC(adc_rpi_data_##idx, ctx), \
.dev = DEVICE_DT_INST_GET(idx), \
}; \
\
DEVICE_DT_INST_DEFINE(idx, adc_rpi_init, NULL, \
&adc_rpi_data_##idx, \
&adc_rpi_config_##idx, POST_KERNEL, \
CONFIG_ADC_INIT_PRIORITY, \
&adc_rpi_api_##idx)

DT_INST_FOREACH_STATUS_OKAY(ADC_RPI_INIT);
1 change: 1 addition & 0 deletions drivers/clock_control/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_NXP_S32 clock_cont
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RA clock_control_ra.c)
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_AMBIQ clock_control_ambiq.c)
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_PWM clock_control_pwm.c)
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RPI_PICO clock_control_rpi_pico.c)


if(CONFIG_CLOCK_CONTROL_STM32_CUBE)
Expand Down
2 changes: 2 additions & 0 deletions drivers/clock_control/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ source "drivers/clock_control/Kconfig.ambiq"

source "drivers/clock_control/Kconfig.pwm"

source "drivers/clock_control/Kconfig.rpi_pico"

endif # CLOCK_CONTROL
19 changes: 19 additions & 0 deletions drivers/clock_control/Kconfig.rpi_pico
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Raspberry Pi Pico Clock Controller Driver configuration options

# Copyright (c) 2022 Andrei-Edward Popa
# SPDX-License-Identifier: Apache-2.0

config CLOCK_CONTROL_RPI_PICO
bool "Raspberry Pi Pico Clock Controller Driver"
default y
depends on DT_HAS_RASPBERRYPI_PICO_CLOCK_CONTROLLER_ENABLED

if CLOCK_CONTROL_RPI_PICO

config RPI_PICO_ROSC_USE_MEASURED_FREQ
bool "Use measured frequency for ring oscillator"
help
Instead of the dts value, use the value measured by
the frequency counter as the rosc frequency.

endif # CLOCK_CONTROL_RPI_PICO
Loading