diff --git a/drivers/clk/clk-operations.c b/drivers/clk/clk-operations.c index 6fe7167ab..628c349af 100644 --- a/drivers/clk/clk-operations.c +++ b/drivers/clk/clk-operations.c @@ -122,8 +122,8 @@ const struct clk_ops clk_gate_ro_ops = { .is_enabled = clk_gate_is_enabled, }; -static inline unsigned long clk_div_recalc_rate(const struct clk *clk, - unsigned long prate) +static inline uint64_t clk_div_recalc_rate(const struct clk *clk, + uint64_t prate) { struct clk_div_data *data = (struct clk_div_data *)(clk->data); @@ -144,8 +144,8 @@ static inline unsigned long clk_div_recalc_rate(const struct clk *clk, return DIV_ROUND_UP_ULL((uint64_t)prate, div); } -static inline int clk_div_set_rate(const struct clk *clk, uint32_t rate, - uint32_t parent_rate) +static inline int clk_div_set_rate(const struct clk *clk, uint64_t rate, + uint64_t parent_rate) { struct clk_div_data *data = (struct clk_div_data *)(clk->data); uint32_t div = DIV_ROUND_UP(parent_rate, rate); @@ -212,7 +212,7 @@ static inline int clk_mux_set_parent(struct clk *clk, uint8_t index) struct clk_mux_data *data = (struct clk_mux_data *)(clk->data); if (data->table) { - unsigned int val = data->table[index]; + uint32_t val = data->table[index]; regmap_mux_update_bits(clk->base, data->offset, data->shift, data->mask, val); } @@ -231,16 +231,16 @@ const struct clk_ops clk_mux_ro_ops = { .get_parent = clk_mux_get_parent, }; -static inline unsigned long clk_factor_recalc_rate(const struct clk *clk, - unsigned long parent_rate) +static inline uint64_t clk_factor_recalc_rate(const struct clk *clk, + uint64_t parent_rate) { struct clk_fixed_factor_data *data = (struct clk_fixed_factor_data *)(clk->data); - unsigned long long int rate; + uint64_t rate; - rate = (unsigned long long int)parent_rate * data->mult; + rate = (uint64_t)parent_rate * data->mult; do_div(rate, data->div); - return (unsigned long)rate; + return (uint64_t)rate; } const struct clk_ops clk_fixed_factor_ops = { @@ -250,8 +250,8 @@ const struct clk_ops clk_fixed_factor_ops = { /* .recalc_accuracy = clk_factor_recalc_accuracy, */ }; -static inline int clk_source_set_rate(const struct clk *clk, uint32_t rate, - uint32_t parent_rate) +static inline int clk_source_set_rate(const struct clk *clk, uint64_t rate, + uint64_t parent_rate) { struct clk_source_data *data = (struct clk_source_data *)(clk->data); data->rate = rate; @@ -259,8 +259,8 @@ static inline int clk_source_set_rate(const struct clk *clk, uint32_t rate, return 0; } -static inline unsigned long clk_source_get_rate(const struct clk *clk, - unsigned long prate) +static inline uint64_t clk_source_get_rate(const struct clk *clk, + uint64_t prate) { struct clk_source_data *data = (struct clk_source_data *)(clk->data); diff --git a/drivers/clk/clk-operations.h b/drivers/clk/clk-operations.h index beccd73c8..44ca9032a 100644 --- a/drivers/clk/clk-operations.h +++ b/drivers/clk/clk-operations.h @@ -8,11 +8,11 @@ #include #include -#define CLK_INCORRECT_ARGS 1 -#define CLK_INVALID_OP 2 -#define CLK_INVALID_ID 3 -#define CLK_UNKNOWN_REQ 4 -#define CLK_UNKNOWN_TARGET 5 +#define CLK_INCORRECT_ARGS -1 +#define CLK_INVALID_OP -2 +#define CLK_INVALID_ID -3 +#define CLK_UNKNOWN_REQ -4 +#define CLK_UNKNOWN_TARGET -5 static inline int reg_write(uint64_t base, uint32_t offset, uint32_t val) { diff --git a/drivers/clk/clk.h b/drivers/clk/clk.h index 60bfd0485..f73d2b98e 100644 --- a/drivers/clk/clk.h +++ b/drivers/clk/clk.h @@ -70,8 +70,7 @@ struct clk_init_data; * clk_foo's clk_ops * * @init: pointer to struct clk_init_data that contains the init data shared - * with the common clock framework. This pointer will be set to NULL once - * a clk_register() variant is called on this clk_hw pointer. + * with the common clock framework. */ struct clk_hw { struct clk *clk; @@ -83,20 +82,6 @@ struct clk_hw { * be provided by the clock implementation, and will be called by drivers * through the clk_* api. * - * @prepare: Prepare the clock for enabling. This must not return until - * the clock is fully prepared, and it's safe to call clk_enable. - * This callback is intended to allow clock implementations to - * do any initialisation that may sleep. Called with - * prepare_lock held. - * - * @unprepare: Release the clock from its prepared state. This will typically - * undo any work done in the @prepare callback. Called with - * prepare_lock held. - * - * @is_prepared: Queries the hardware to determine if the clock is prepared. - * This function is allowed to sleep. Optional, if this op is not - * set then the prepare count will be used. - * * @enable: Enable the clock atomically. This must not return until the * clock is generating a valid clock signal, usable by consumer * devices. Called with enable_lock held. This function must not @@ -109,11 +94,6 @@ struct clk_hw { * This function must not sleep. Optional, if this op is not * set then the enable count will be used. * - * @disable_unused: Disable the clock atomically. Only called from - * clk_disable_unused for gate clocks with special needs. - * Called with enable_lock held. This function must not - * sleep. - * * @recalc_rate: Recalculate the rate of this clock, by querying hardware. The * parent rate is an input parameter. It is up to the caller to * ensure that the prepare_mutex is held across this call. If the @@ -165,9 +145,8 @@ struct clk_hw { struct clk_ops { uint8_t (*get_parent)(const struct clk *clk); int (*set_parent)(struct clk *clk, uint8_t index); - unsigned long (*recalc_rate)(const struct clk *clk, - unsigned long parent_rate); - int (*set_rate)(const struct clk *clk, uint32_t rate, uint32_t parent_rate); + uint64_t (*recalc_rate)(const struct clk *clk, uint64_t parent_rate); + int (*set_rate)(const struct clk *clk, uint64_t rate, uint64_t parent_rate); void (*init)(struct clk *clk); int (*enable)(struct clk *clk); int (*disable)(struct clk *clk); @@ -334,9 +313,6 @@ struct clk_fixed_factor_data { * .get_parent clk_op. * CLK_MUX_ROUND_CLOSEST - Use the parent rate that is closest to the desired * frequency. - * CLK_MUX_BIG_ENDIAN - By default little endian register accesses are used for - * the mux register. Setting this flag makes the register accesses big - * endian. */ struct clk_mux_data { uint32_t offset; @@ -368,21 +344,21 @@ const struct clk *get_parent(const struct clk *clk); * @clk: pointer to the current clk * */ -uint32_t clk_get_rate(const struct clk *clk, uint64_t *rate); +int clk_get_rate(const struct clk *clk, uint64_t *rate); /** * function clk_enable() - enable the target clock signal * * @clk: pointer to the current clk */ -uint32_t clk_enable(struct clk *clk); +int clk_enable(struct clk *clk); /** * function clk_disable() - disable the target clock signal * * @clk: pointer to the current clk */ -uint32_t clk_disable(struct clk *clk); +int clk_disable(struct clk *clk); /** * function clk_set_rate() - set the nearest rate to the requested rate for @@ -392,4 +368,4 @@ uint32_t clk_disable(struct clk *clk); * @req_rate: request rate * @rate: pointer to result variable */ -uint32_t clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate); +int clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate); diff --git a/drivers/clk/imx/clk-imx.c b/drivers/clk/imx/clk-imx.c index ab3ccb801..ef8b20c17 100644 --- a/drivers/clk/imx/clk-imx.c +++ b/drivers/clk/imx/clk-imx.c @@ -69,8 +69,7 @@ const struct clk_ops clk_gate2_ops = { .is_enabled = clk_gate2_is_enabled, }; -static unsigned long clk_pll_recalc_rate(const struct clk *clk, - unsigned long prate) +static uint64_t clk_pll_recalc_rate(const struct clk *clk, uint64_t prate) { /* TODO: This function is derived from Linux codebase, but seems wrong * according to the datasheet as PLL_REFCLK_DIV_VAL[5:10] is never used. */ @@ -112,8 +111,7 @@ const struct clk_ops clk_frac_pll_ops = { /* .set_rate = clk_pll_set_rate, */ }; -static unsigned long clk_sscg_pll_recalc_rate(const struct clk *clk, - unsigned long prate) +static uint64_t clk_sscg_pll_recalc_rate(const struct clk *clk, uint64_t prate) { struct clk_sscg_pll_data *data = (struct clk_sscg_pll_data *)(clk->data); uint64_t temp_rate = prate; @@ -173,8 +171,8 @@ const struct clk_ops clk_sscg_pll_ops = { /* .determine_rate = clk_sscg_pll_determine_rate, */ }; -static unsigned long imx8m_clk_core_slice_recalc_rate(const struct clk *clk, - unsigned long prate) +static uint64_t imx8m_clk_core_slice_recalc_rate(const struct clk *clk, + uint64_t prate) { struct clk_core_slice_data *data = (struct clk_core_slice_data *)(clk->data); @@ -226,8 +224,8 @@ const struct clk_ops clk_core_slice_ops = { .set_parent = imx8m_clk_core_slice_set_parent, }; -static unsigned long imx8m_clk_common_slice_recalc_rate(const struct clk *clk, - unsigned long prate) +static uint64_t imx8m_clk_common_slice_recalc_rate(const struct clk *clk, + uint64_t prate) { struct clk_common_slice_data *data = (struct clk_common_slice_data *)(clk->data); @@ -235,8 +233,7 @@ static unsigned long imx8m_clk_common_slice_recalc_rate(const struct clk *clk, uint32_t prediv_val = regmap_read_bits( clk->base, data->offset, data->prevdiv_shift, data->prevdiv_width); /* Divider value is n+1 */ - unsigned long prediv_rate = DIV_ROUND_UP_ULL((uint64_t)prate, - prediv_val + 1); + uint64_t prediv_rate = DIV_ROUND_UP_ULL((uint64_t)prate, prediv_val + 1); uint32_t postdiv_val = regmap_read_bits( clk->base, data->offset, data->postdiv_shift, data->postdiv_width); @@ -285,16 +282,15 @@ const struct clk_ops clk_common_slice_ops = { .set_parent = imx8m_clk_common_slice_set_parent, }; -static unsigned long imx8m_clk_bus_slice_recalc_rate(const struct clk *clk, - unsigned long prate) +static uint64_t imx8m_clk_bus_slice_recalc_rate(const struct clk *clk, + uint64_t prate) { struct clk_bus_slice_data *data = (struct clk_bus_slice_data *)(clk->data); uint32_t prediv_val = regmap_read_bits( clk->base, data->offset, data->prevdiv_shift, data->prevdiv_width); /* Divider value is n+1 */ - unsigned long prediv_rate = DIV_ROUND_UP_ULL((uint64_t)prate, - prediv_val + 1); + uint64_t prediv_rate = DIV_ROUND_UP_ULL((uint64_t)prate, prediv_val + 1); uint32_t postdiv_val = regmap_read_bits( clk->base, data->offset, data->postdiv_shift, data->postdiv_width); diff --git a/drivers/clk/imx/clk.c b/drivers/clk/imx/clk.c index d17b3cae9..1c3953a98 100644 --- a/drivers/clk/imx/clk.c +++ b/drivers/clk/imx/clk.c @@ -98,14 +98,14 @@ const struct clk *get_parent(const struct clk *clk) /* TODO: Should be just read from the structure, but need to update everytime when */ /* related clocks are modified */ -uint32_t clk_get_rate(const struct clk *clk, uint64_t *rate) +int clk_get_rate(const struct clk *clk, uint64_t *rate) { if (!clk) return CLK_UNKNOWN_TARGET; const struct clk_init_data *init = (struct clk_init_data *)clk->hw.init; uint64_t parent_rate = 0; - uint32_t err = 0; + int err = 0; const struct clk *parent_clk = get_parent(clk); @@ -124,7 +124,7 @@ uint32_t clk_get_rate(const struct clk *clk, uint64_t *rate) return 0; } -uint32_t clk_enable(struct clk *clk) +int clk_enable(struct clk *clk) { if (!clk) return CLK_UNKNOWN_TARGET; @@ -136,7 +136,7 @@ uint32_t clk_enable(struct clk *clk) return CLK_INVALID_OP; } -uint32_t clk_disable(struct clk *clk) +int clk_disable(struct clk *clk) { if (!clk) return CLK_UNKNOWN_TARGET; @@ -148,7 +148,7 @@ uint32_t clk_disable(struct clk *clk) return CLK_INVALID_OP; } -uint32_t clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate) +int clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate) { if (!clk) return CLK_UNKNOWN_TARGET; @@ -161,7 +161,7 @@ uint32_t clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate) const struct clk *pclk = get_parent(clk); uint64_t prate = 0; - uint32_t err = clk_get_rate(pclk, &prate); + int err = clk_get_rate(pclk, &prate); if (err) { LOG_DRIVER_ERR("Failed to get parent clock's rate\n"); return err; @@ -174,7 +174,7 @@ uint32_t clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate) if (pclk && pclk->hw.init->ops->set_rate) { const struct clk *ppclk = get_parent(pclk); uint64_t pprate = 0; - uint32_t err = clk_get_rate(ppclk, &pprate); + int err = clk_get_rate(ppclk, &pprate); if (!err) { pclk->hw.init->ops->set_rate(pclk, prate, pprate); return 0; @@ -190,7 +190,7 @@ int clk_msr_stat() #ifdef DEBUG_DRIVER int i; uint64_t rate = 0; - uint32_t err; + int err; LOG_DRIVER("-------Expected clock rates------\n"); for (i = 0; i < NUM_CLK_LIST; i++) { @@ -199,6 +199,7 @@ int clk_msr_stat() if (err) { LOG_DRIVER_ERR("Failed to get rate of %s: -%u\n", clk_list[i]->hw.init->name, err); + return err; } LOG_DRIVER("[%4d][%10luHz] %s\n", i, rate, clk_list[i]->hw.init->name); @@ -244,7 +245,7 @@ void init(void) microkit_msginfo protected(microkit_channel ch, microkit_msginfo msginfo) { - uint32_t err = 0; + int err = 0; uint32_t argc = microkit_msginfo_get_count(msginfo); /* TODO: Check if the channel is valid */ diff --git a/drivers/clk/imx/include/clk-imx.h b/drivers/clk/imx/include/clk-imx.h index db012ba42..3f853b133 100644 --- a/drivers/clk/imx/include/clk-imx.h +++ b/drivers/clk/imx/include/clk-imx.h @@ -244,8 +244,7 @@ struct clk _name = { \ }, \ } -#define IMX_CLK_GATE2_FLAGS(_name, _parent_clks, _base, _offset, _shift, \ - _flags) \ +#define IMX_CLK_GATE2_FLAGS(_name, _parent_clks, _base, _offset, _shift, _flags) \ struct clk _name = { \ .base = (_base), \ .data = &(struct clk_gate_data) { \ diff --git a/drivers/clk/meson/clk-meson.c b/drivers/clk/meson/clk-meson.c index 990cc2242..2c8af3869 100644 --- a/drivers/clk/meson/clk-meson.c +++ b/drivers/clk/meson/clk-meson.c @@ -220,8 +220,7 @@ const struct clk_ops meson_clk_pll_ro_ops = { #define N2_MIN 4 #define N2_MAX 511 -static unsigned long mpll_recalc_rate(const struct clk *clk, - unsigned long prate) +static uint64_t mpll_recalc_rate(const struct clk *clk, uint64_t prate) { struct meson_clk_mpll_data *data = (struct meson_clk_mpll_data *)(clk->data); @@ -239,8 +238,8 @@ static unsigned long mpll_recalc_rate(const struct clk *clk, return DIV_ROUND_UP_ULL((uint64_t)prate * SDM_DEN, divisor); } -static int mpll_set_rate(const struct clk *clk, uint32_t rate, - uint32_t parent_rate) +static int mpll_set_rate(const struct clk *clk, uint64_t rate, + uint64_t parent_rate) { struct meson_clk_mpll_data *data = (struct meson_clk_mpll_data *)(clk->data); @@ -291,7 +290,7 @@ static void mpll_init(struct clk *clk) data->sdm_en.width, 1); /* Set spread spectrum if possible */ - unsigned int ss = data->flags & CLK_MESON_MPLL_SPREAD_SPECTRUM ? 1 : 0; + uint32_t ss = data->flags & CLK_MESON_MPLL_SPREAD_SPECTRUM ? 1 : 0; regmap_update_bits(clk->base, data->ssen.reg_off, data->ssen.shift, data->ssen.width, ss); } @@ -457,8 +456,8 @@ static unsigned long meson_vclk_div_recalc_rate(const struct clk *clk, return DIV_ROUND_UP_ULL((uint64_t)prate, div); } -static int meson_vclk_div_set_rate(const struct clk *clk, uint32_t rate, - uint32_t parent_rate) +static int meson_vclk_div_set_rate(const struct clk *clk, uint64_t rate, + uint64_t parent_rate) { struct meson_vclk_div_data *data = (struct meson_vclk_div_data *)(clk->data); diff --git a/drivers/clk/meson/clk.c b/drivers/clk/meson/clk.c index 3f303882c..166af678b 100644 --- a/drivers/clk/meson/clk.c +++ b/drivers/clk/meson/clk.c @@ -90,14 +90,14 @@ const struct clk *get_parent(const struct clk *clk) /* TODO: Should be just read from the structure, but need to update everytime when */ /* related clocks are modified */ -uint32_t clk_get_rate(const struct clk *clk, unsigned long *rate) +int clk_get_rate(const struct clk *clk, uint64_t *rate) { if (!clk) return CLK_UNKNOWN_TARGET; const struct clk_init_data *init = (struct clk_init_data *)clk->hw.init; - unsigned long parent_rate = 0; - uint32_t err = 0; + uint64_t parent_rate = 0; + int err = 0; const struct clk *parent_clk = get_parent(clk); if (parent_clk) { @@ -115,7 +115,7 @@ uint32_t clk_get_rate(const struct clk *clk, unsigned long *rate) return 0; } -uint32_t clk_enable(struct clk *clk) +int clk_enable(struct clk *clk) { if (!clk) return CLK_UNKNOWN_TARGET; @@ -127,7 +127,7 @@ uint32_t clk_enable(struct clk *clk) return CLK_INVALID_OP; } -uint32_t clk_disable(struct clk *clk) +int clk_disable(struct clk *clk) { if (!clk) return CLK_UNKNOWN_TARGET; @@ -139,7 +139,7 @@ uint32_t clk_disable(struct clk *clk) return CLK_INVALID_OP; } -uint32_t clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate) +int clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate) { if (!clk) return CLK_UNKNOWN_TARGET; @@ -152,7 +152,7 @@ uint32_t clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate) const struct clk *pclk = get_parent(clk); uint64_t prate = 0; - uint32_t err = clk_get_rate(pclk, &prate); + int err = clk_get_rate(pclk, &prate); if (err) { LOG_DRIVER_ERR("Failed to get parent clock's rate\n"); return err; @@ -166,7 +166,7 @@ uint32_t clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate) if (pclk->hw.init->ops->set_rate) { const struct clk *ppclk = get_parent(pclk); uint64_t pprate = 0; - uint32_t err = clk_get_rate(ppclk, &pprate); + int err = clk_get_rate(ppclk, &pprate); if (!err) { pclk->hw.init->ops->set_rate(pclk, prate, pprate); *rate = req_rate; @@ -184,7 +184,7 @@ int clk_msr_stat() unsigned long clk_freq; int i = 0; uint64_t rate = 0; - uint32_t err; + int err; const char *const *clk_msr_list = get_msr_clk_list(); @@ -234,7 +234,7 @@ void init(void) /* Set rate for the target clock */ if (clk_configs[i].frequency > 0) { uint64_t rate = 0; - uint32_t err = clk_set_rate(clk, clk_configs[i].frequency, &rate); + int err = clk_set_rate(clk, clk_configs[i].frequency, &rate); if (err) { LOG_DRIVER_ERR("Failed to set rate [%d] for clk_id: %d\n", clk_configs[i].frequency, clk_configs[i].clk_id); @@ -245,7 +245,7 @@ void init(void) microkit_msginfo protected(microkit_channel ch, microkit_msginfo msginfo) { - uint32_t err = 0; + int err = 0; uint32_t ret_num = 0; uint32_t argc = microkit_msginfo_get_count(msginfo); diff --git a/examples/clk/client.c b/examples/clk/client.c index e9d66036f..ce84a1baa 100644 --- a/examples/clk/client.c +++ b/examples/clk/client.c @@ -19,27 +19,76 @@ void init(void) #ifdef TEST_BOARD_odroidc4 sddf_dprintf("Test board: odroidc4\n"); - uint32_t ret = sddf_clk_enable(CLK_DRIVER_CH, 10); - sddf_dprintf("ret_val: %x\n", ret); + /** + * CLKID_CLK81 = 10 + * CLKID_I2C = 24 + * CLKID_CPU_CLK = 187 + * + * see `sddf/drivers/clk/meson/include/g12a-bindings.h` for more clock indices. + * + **/ + uint32_t clk_id_to_enable = 10; + int ret = sddf_clk_enable(CLK_DRIVER_CH, clk_id_to_enable); + if (ret) { + sddf_dprintf("Failed to enable clock %u: err - %d\n", clk_id_to_enable, + ret); + } else { + sddf_dprintf("Successfully enabled clock %u\n", clk_id_to_enable); + } - ret = sddf_clk_disable(CLK_DRIVER_CH, 24); - sddf_dprintf("ret_val: %x\n", ret); + uint32_t clk_id_to_disable = 24; + ret = sddf_clk_disable(CLK_DRIVER_CH, clk_id_to_disable); + if (ret) { + sddf_dprintf("Failed to disable clock %u: err - %d\n", clk_id_to_enable, + ret); + } else { + sddf_dprintf("Successfully disabled clock %u\n", clk_id_to_enable); + } uint64_t rate = 0; - ret = sddf_clk_get_rate(CLK_DRIVER_CH, 10, &rate); - sddf_dprintf("err: %d rate: %lu\n", ret, rate); + uint32_t clk_id_to_set_rate = 10; + ret = sddf_clk_get_rate(CLK_DRIVER_CH, clk_id_to_set_rate, &rate); + if (ret) { + sddf_dprintf("Failed to get the rate of clock %u: err - %d\n", + clk_id_to_set_rate, ret); + } else { + sddf_dprintf("The rate of clock %u: %lu\n", clk_id_to_set_rate, rate); + } - ret = sddf_clk_set_rate(CLK_DRIVER_CH, 10, 150000000, &rate); - sddf_dprintf("err: %d, rate: %lu\n", ret, rate); + ret = sddf_clk_set_rate(CLK_DRIVER_CH, clk_id_to_set_rate, 150000000, + &rate); + if (ret) { + sddf_dprintf("Failed to set the rate of clock %u: err - %d\n", + clk_id_to_set_rate, ret); + } else { + sddf_dprintf("Set the rate of clock %u to %lu\n", ret, rate); + } - ret = sddf_clk_get_rate(CLK_DRIVER_CH, 187, &rate); - sddf_dprintf("err: %d, rate: %lu\n", ret, rate); + uint32_t clk_id_to_get_rate = 187; + ret = sddf_clk_get_rate(CLK_DRIVER_CH, clk_id_to_get_rate, &rate); + if (ret) { + sddf_dprintf("Failed to get the rate of clock %u: err - %d\n", + clk_id_to_get_rate, ret); + } else { + sddf_dprintf("The rate of clock %u: %lu\n", clk_id_to_get_rate, rate); + } #elif TEST_BOARD_maaxboard sddf_dprintf("Test board: maaxboard\n"); - uint32_t ret = sddf_clk_enable(CLK_DRIVER_CH, 196); - sddf_dprintf("ret_val: %x\n", ret); + /** + * IMX8MQ_CLK_SAI1_ROOT = 196 + * + * see `sddf/drivers/clk/imx/include/imx8mq-bindings.h` for more clock indices. + * */ + uint32_t clk_id_to_enable = 196; + int ret = sddf_clk_enable(CLK_DRIVER_CH, clk_id_to_enable); + if (ret) { + sddf_dprintf("Failed to enable clock %u: err - %d\n", clk_id_to_enable, + ret); + } else { + sddf_dprintf("Successfully enabled clock %u\n", clk_id_to_enable); + } #else sddf_dprintf("No tests for the target board\n", ret); diff --git a/include/sddf/clk/client.h b/include/sddf/clk/client.h index d5dc3e937..19cd5ad69 100644 --- a/include/sddf/clk/client.h +++ b/include/sddf/clk/client.h @@ -16,15 +16,14 @@ * @param channel of clock driver. * @param identifier of target clock. */ -static inline uint32_t sddf_clk_enable(microkit_channel channel, - uint32_t clk_id) +static inline int sddf_clk_enable(microkit_channel channel, uint32_t clk_id) { microkit_msginfo msginfo = microkit_msginfo_new(SDDF_CLK_ENABLE, 1); microkit_mr_set(SDDF_CLK_PARAM_ID, clk_id); msginfo = microkit_ppcall(channel, msginfo); - return (uint32_t)microkit_msginfo_get_label(msginfo); + return (int)microkit_msginfo_get_label(msginfo); } /** @@ -33,15 +32,14 @@ static inline uint32_t sddf_clk_enable(microkit_channel channel, * @param channel of clock driver. * @param identifier of target clock. */ -static inline uint32_t sddf_clk_disable(microkit_channel channel, - uint32_t clk_id) +static inline int sddf_clk_disable(microkit_channel channel, uint32_t clk_id) { microkit_msginfo msginfo = microkit_msginfo_new(SDDF_CLK_DISABLE, 1); microkit_mr_set(SDDF_CLK_PARAM_ID, clk_id); msginfo = microkit_ppcall(channel, msginfo); - return (uint32_t)microkit_msginfo_get_label(msginfo); + return (int)microkit_msginfo_get_label(msginfo); } /** @@ -51,8 +49,8 @@ static inline uint32_t sddf_clk_disable(microkit_channel channel, * @param identifier of target clock. * @param pointer to result variable. */ -static inline uint32_t sddf_clk_get_rate(microkit_channel channel, - uint32_t clk_id, uint64_t *rate) +static inline int sddf_clk_get_rate(microkit_channel channel, uint32_t clk_id, + uint64_t *rate) { microkit_msginfo msginfo = microkit_msginfo_new(SDDF_CLK_GET_RATE, 1); microkit_mr_set(SDDF_CLK_PARAM_ID, clk_id); @@ -60,7 +58,7 @@ static inline uint32_t sddf_clk_get_rate(microkit_channel channel, msginfo = microkit_ppcall(channel, msginfo); *rate = microkit_mr_get(0); - return (uint32_t)microkit_msginfo_get_label(msginfo); + return (int)microkit_msginfo_get_label(msginfo); } /** @@ -71,9 +69,8 @@ static inline uint32_t sddf_clk_get_rate(microkit_channel channel, * @param target clock frequency. * @param pointer to result variable. */ -static inline uint32_t sddf_clk_set_rate(microkit_channel channel, - uint32_t clk_id, uint64_t req_rate, - uint64_t *rate) +static inline int sddf_clk_set_rate(microkit_channel channel, uint32_t clk_id, + uint64_t req_rate, uint64_t *rate) { microkit_msginfo msginfo = microkit_msginfo_new(SDDF_CLK_SET_RATE, 2); microkit_mr_set(SDDF_CLK_PARAM_ID, clk_id); @@ -82,5 +79,5 @@ static inline uint32_t sddf_clk_set_rate(microkit_channel channel, msginfo = microkit_ppcall(channel, msginfo); *rate = microkit_mr_get(0); - return (uint32_t)microkit_msginfo_get_label(msginfo); + return (int)microkit_msginfo_get_label(msginfo); }