Skip to content

Commit

Permalink
clock_control: nordic: move to new DT API
Browse files Browse the repository at this point in the history
Use the new devicetree API to access dts data.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
  • Loading branch information
mbolivar-nordic authored and galak committed Apr 14, 2020
1 parent 7c5c4da commit b9fff2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
17 changes: 12 additions & 5 deletions drivers/clock_control/nrf_clock_calibration.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ LOG_MODULE_DECLARE(clock_control, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
* is ongoing, it is requested by the calibration process and released when
* calibration is done.
*/
#ifndef DT_INST_0_NORDIC_NRF_TEMP_LABEL
#define DT_INST_0_NORDIC_NRF_TEMP_LABEL ""
#endif

static atomic_t cal_process_in_progress;
static s16_t prev_temperature; /* Previous temperature measurement. */
Expand Down Expand Up @@ -215,6 +212,17 @@ static void measure_temperature(struct k_work *work)
started ? "started" : "skipped", diff);
}

#define TEMP_NODE DT_INST(0, nordic_nrf_temp)

#if DT_HAS_NODE(TEMP_NODE)
static inline struct device *temp_device(void)
{
return device_get_binding(DT_LABEL(TEMP_NODE));
}
#else
#define temp_device() NULL
#endif

void z_nrf_clock_calibration_init(struct device *dev)
{
/* Anomaly 36: After watchdog timeout reset, CPU lockup reset, soft
Expand All @@ -224,8 +232,7 @@ void z_nrf_clock_calibration_init(struct device *dev)
nrf_clock_int_enable(NRF_CLOCK, NRF_CLOCK_INT_DONE_MASK);

if (CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP != 0) {
temp_sensor =
device_get_binding(DT_INST_0_NORDIC_NRF_TEMP_LABEL);
temp_sensor = temp_device();
}

clk_dev = dev;
Expand Down
12 changes: 6 additions & 6 deletions drivers/clock_control/nrf_power_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

LOG_MODULE_REGISTER(clock_control, CONFIG_CLOCK_CONTROL_LOG_LEVEL);

#define DT_DRV_COMPAT nordic_nrf_clock

/* Helper logging macros which prepends subsys name to the log. */
#ifdef CONFIG_LOG
#define CLOCK_LOG(lvl, dev, subsys, ...) \
Expand Down Expand Up @@ -300,11 +302,10 @@ void nrf_power_clock_isr(void *arg);

static int clk_init(struct device *dev)
{
IRQ_CONNECT(DT_INST_0_NORDIC_NRF_CLOCK_IRQ_0,
DT_INST_0_NORDIC_NRF_CLOCK_IRQ_0_PRIORITY,
IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority),
nrf_power_clock_isr, 0, 0);

irq_enable(DT_INST_0_NORDIC_NRF_CLOCK_IRQ_0);
irq_enable(DT_INST_IRQN(0));

nrf_clock_lf_src_set(NRF_CLOCK, CLOCK_CONTROL_NRF_K32SRC);

Expand Down Expand Up @@ -347,8 +348,7 @@ static const struct nrf_clock_control_config config = {
}
};

DEVICE_AND_API_INIT(clock_nrf,
DT_INST_0_NORDIC_NRF_CLOCK_LABEL,
DEVICE_AND_API_INIT(clock_nrf, DT_INST_LABEL(0),
clk_init, &data, &config, PRE_KERNEL_1,
CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&clock_control_api);
Expand Down Expand Up @@ -449,7 +449,7 @@ void nrf5_power_usb_power_int_enable(bool enable)

if (enable) {
nrf_power_int_enable(NRF_POWER, mask);
irq_enable(DT_INST_0_NORDIC_NRF_CLOCK_IRQ_0);
irq_enable(DT_INST_IRQN(0));
} else {
nrf_power_int_disable(NRF_POWER, mask);
}
Expand Down

0 comments on commit b9fff2c

Please sign in to comment.