Skip to content

Commit 2007cd7

Browse files
committed
clk: use data types with preknown length
This commit replaces all platform-dependent data types with fix-sized types, and unifies the return values of interfaces as signed integers. The return value 0 indicates the success on the request to clock driver, and negative values indicate the failure reasons. Signed-off-by: Terry Bai <terry.z.bai@gmail.com>
1 parent 1acc8de commit 2007cd7

File tree

10 files changed

+135
-118
lines changed

10 files changed

+135
-118
lines changed

drivers/clk/clk-operations.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ const struct clk_ops clk_gate_ro_ops = {
122122
.is_enabled = clk_gate_is_enabled,
123123
};
124124

125-
static inline unsigned long clk_div_recalc_rate(const struct clk *clk,
126-
unsigned long prate)
125+
static inline uint64_t clk_div_recalc_rate(const struct clk *clk,
126+
uint64_t prate)
127127
{
128128

129129
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,
144144
return DIV_ROUND_UP_ULL((uint64_t)prate, div);
145145
}
146146

147-
static inline int clk_div_set_rate(const struct clk *clk, uint32_t rate,
148-
uint32_t parent_rate)
147+
static inline int clk_div_set_rate(const struct clk *clk, uint64_t rate,
148+
uint64_t parent_rate)
149149
{
150150
struct clk_div_data *data = (struct clk_div_data *)(clk->data);
151151
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)
212212
struct clk_mux_data *data = (struct clk_mux_data *)(clk->data);
213213

214214
if (data->table) {
215-
unsigned int val = data->table[index];
215+
uint32_t val = data->table[index];
216216
regmap_mux_update_bits(clk->base, data->offset, data->shift, data->mask,
217217
val);
218218
}
@@ -231,16 +231,16 @@ const struct clk_ops clk_mux_ro_ops = {
231231
.get_parent = clk_mux_get_parent,
232232
};
233233

234-
static inline unsigned long clk_factor_recalc_rate(const struct clk *clk,
235-
unsigned long parent_rate)
234+
static inline uint64_t clk_factor_recalc_rate(const struct clk *clk,
235+
uint64_t parent_rate)
236236
{
237237
struct clk_fixed_factor_data *data =
238238
(struct clk_fixed_factor_data *)(clk->data);
239-
unsigned long long int rate;
239+
uint64_t rate;
240240

241-
rate = (unsigned long long int)parent_rate * data->mult;
241+
rate = (uint64_t)parent_rate * data->mult;
242242
do_div(rate, data->div);
243-
return (unsigned long)rate;
243+
return (uint64_t)rate;
244244
}
245245

246246
const struct clk_ops clk_fixed_factor_ops = {
@@ -250,17 +250,17 @@ const struct clk_ops clk_fixed_factor_ops = {
250250
/* .recalc_accuracy = clk_factor_recalc_accuracy, */
251251
};
252252

253-
static inline int clk_source_set_rate(const struct clk *clk, uint32_t rate,
254-
uint32_t parent_rate)
253+
static inline int clk_source_set_rate(const struct clk *clk, uint64_t rate,
254+
uint64_t parent_rate)
255255
{
256256
struct clk_source_data *data = (struct clk_source_data *)(clk->data);
257257
data->rate = rate;
258258

259259
return 0;
260260
}
261261

262-
static inline unsigned long clk_source_get_rate(const struct clk *clk,
263-
unsigned long prate)
262+
static inline uint64_t clk_source_get_rate(const struct clk *clk,
263+
uint64_t prate)
264264
{
265265
struct clk_source_data *data = (struct clk_source_data *)(clk->data);
266266

drivers/clk/clk-operations.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
#include <clk.h>
99
#include <utils.h>
1010

11-
#define CLK_INCORRECT_ARGS 1
12-
#define CLK_INVALID_OP 2
13-
#define CLK_INVALID_ID 3
14-
#define CLK_UNKNOWN_REQ 4
15-
#define CLK_UNKNOWN_TARGET 5
11+
#define CLK_INCORRECT_ARGS -1
12+
#define CLK_INVALID_OP -2
13+
#define CLK_INVALID_ID -3
14+
#define CLK_UNKNOWN_REQ -4
15+
#define CLK_UNKNOWN_TARGET -5
1616

1717
static inline int reg_write(uint64_t base, uint32_t offset, uint32_t val)
1818
{

drivers/clk/clk.h

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ struct clk_init_data;
7070
* clk_foo's clk_ops
7171
*
7272
* @init: pointer to struct clk_init_data that contains the init data shared
73-
* with the common clock framework. This pointer will be set to NULL once
74-
* a clk_register() variant is called on this clk_hw pointer.
73+
* with the common clock framework.
7574
*/
7675
struct clk_hw {
7776
struct clk *clk;
@@ -83,20 +82,6 @@ struct clk_hw {
8382
* be provided by the clock implementation, and will be called by drivers
8483
* through the clk_* api.
8584
*
86-
* @prepare: Prepare the clock for enabling. This must not return until
87-
* the clock is fully prepared, and it's safe to call clk_enable.
88-
* This callback is intended to allow clock implementations to
89-
* do any initialisation that may sleep. Called with
90-
* prepare_lock held.
91-
*
92-
* @unprepare: Release the clock from its prepared state. This will typically
93-
* undo any work done in the @prepare callback. Called with
94-
* prepare_lock held.
95-
*
96-
* @is_prepared: Queries the hardware to determine if the clock is prepared.
97-
* This function is allowed to sleep. Optional, if this op is not
98-
* set then the prepare count will be used.
99-
*
10085
* @enable: Enable the clock atomically. This must not return until the
10186
* clock is generating a valid clock signal, usable by consumer
10287
* devices. Called with enable_lock held. This function must not
@@ -109,11 +94,6 @@ struct clk_hw {
10994
* This function must not sleep. Optional, if this op is not
11095
* set then the enable count will be used.
11196
*
112-
* @disable_unused: Disable the clock atomically. Only called from
113-
* clk_disable_unused for gate clocks with special needs.
114-
* Called with enable_lock held. This function must not
115-
* sleep.
116-
*
11797
* @recalc_rate: Recalculate the rate of this clock, by querying hardware. The
11898
* parent rate is an input parameter. It is up to the caller to
11999
* ensure that the prepare_mutex is held across this call. If the
@@ -165,9 +145,8 @@ struct clk_hw {
165145
struct clk_ops {
166146
uint8_t (*get_parent)(const struct clk *clk);
167147
int (*set_parent)(struct clk *clk, uint8_t index);
168-
unsigned long (*recalc_rate)(const struct clk *clk,
169-
unsigned long parent_rate);
170-
int (*set_rate)(const struct clk *clk, uint32_t rate, uint32_t parent_rate);
148+
uint64_t (*recalc_rate)(const struct clk *clk, uint64_t parent_rate);
149+
int (*set_rate)(const struct clk *clk, uint64_t rate, uint64_t parent_rate);
171150
void (*init)(struct clk *clk);
172151
int (*enable)(struct clk *clk);
173152
int (*disable)(struct clk *clk);
@@ -334,9 +313,6 @@ struct clk_fixed_factor_data {
334313
* .get_parent clk_op.
335314
* CLK_MUX_ROUND_CLOSEST - Use the parent rate that is closest to the desired
336315
* frequency.
337-
* CLK_MUX_BIG_ENDIAN - By default little endian register accesses are used for
338-
* the mux register. Setting this flag makes the register accesses big
339-
* endian.
340316
*/
341317
struct clk_mux_data {
342318
uint32_t offset;
@@ -368,21 +344,21 @@ const struct clk *get_parent(const struct clk *clk);
368344
* @clk: pointer to the current clk
369345
*
370346
*/
371-
uint32_t clk_get_rate(const struct clk *clk, uint64_t *rate);
347+
int clk_get_rate(const struct clk *clk, uint64_t *rate);
372348

373349
/**
374350
* function clk_enable() - enable the target clock signal
375351
*
376352
* @clk: pointer to the current clk
377353
*/
378-
uint32_t clk_enable(struct clk *clk);
354+
int clk_enable(struct clk *clk);
379355

380356
/**
381357
* function clk_disable() - disable the target clock signal
382358
*
383359
* @clk: pointer to the current clk
384360
*/
385-
uint32_t clk_disable(struct clk *clk);
361+
int clk_disable(struct clk *clk);
386362

387363
/**
388364
* function clk_set_rate() - set the nearest rate to the requested rate for
@@ -392,4 +368,4 @@ uint32_t clk_disable(struct clk *clk);
392368
* @req_rate: request rate
393369
* @rate: pointer to result variable
394370
*/
395-
uint32_t clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate);
371+
int clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate);

drivers/clk/imx/clk-imx.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ const struct clk_ops clk_gate2_ops = {
6969
.is_enabled = clk_gate2_is_enabled,
7070
};
7171

72-
static unsigned long clk_pll_recalc_rate(const struct clk *clk,
73-
unsigned long prate)
72+
static uint64_t clk_pll_recalc_rate(const struct clk *clk, uint64_t prate)
7473
{
7574
/* TODO: This function is derived from Linux codebase, but seems wrong
7675
* 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 = {
112111
/* .set_rate = clk_pll_set_rate, */
113112
};
114113

115-
static unsigned long clk_sscg_pll_recalc_rate(const struct clk *clk,
116-
unsigned long prate)
114+
static uint64_t clk_sscg_pll_recalc_rate(const struct clk *clk, uint64_t prate)
117115
{
118116
struct clk_sscg_pll_data *data = (struct clk_sscg_pll_data *)(clk->data);
119117
uint64_t temp_rate = prate;
@@ -173,8 +171,8 @@ const struct clk_ops clk_sscg_pll_ops = {
173171
/* .determine_rate = clk_sscg_pll_determine_rate, */
174172
};
175173

176-
static unsigned long imx8m_clk_core_slice_recalc_rate(const struct clk *clk,
177-
unsigned long prate)
174+
static uint64_t imx8m_clk_core_slice_recalc_rate(const struct clk *clk,
175+
uint64_t prate)
178176
{
179177
struct clk_core_slice_data *data =
180178
(struct clk_core_slice_data *)(clk->data);
@@ -226,17 +224,16 @@ const struct clk_ops clk_core_slice_ops = {
226224
.set_parent = imx8m_clk_core_slice_set_parent,
227225
};
228226

229-
static unsigned long imx8m_clk_common_slice_recalc_rate(const struct clk *clk,
230-
unsigned long prate)
227+
static uint64_t imx8m_clk_common_slice_recalc_rate(const struct clk *clk,
228+
uint64_t prate)
231229
{
232230
struct clk_common_slice_data *data =
233231
(struct clk_common_slice_data *)(clk->data);
234232

235233
uint32_t prediv_val = regmap_read_bits(
236234
clk->base, data->offset, data->prevdiv_shift, data->prevdiv_width);
237235
/* Divider value is n+1 */
238-
unsigned long prediv_rate = DIV_ROUND_UP_ULL((uint64_t)prate,
239-
prediv_val + 1);
236+
uint64_t prediv_rate = DIV_ROUND_UP_ULL((uint64_t)prate, prediv_val + 1);
240237

241238
uint32_t postdiv_val = regmap_read_bits(
242239
clk->base, data->offset, data->postdiv_shift, data->postdiv_width);
@@ -285,16 +282,15 @@ const struct clk_ops clk_common_slice_ops = {
285282
.set_parent = imx8m_clk_common_slice_set_parent,
286283
};
287284

288-
static unsigned long imx8m_clk_bus_slice_recalc_rate(const struct clk *clk,
289-
unsigned long prate)
285+
static uint64_t imx8m_clk_bus_slice_recalc_rate(const struct clk *clk,
286+
uint64_t prate)
290287
{
291288
struct clk_bus_slice_data *data = (struct clk_bus_slice_data *)(clk->data);
292289

293290
uint32_t prediv_val = regmap_read_bits(
294291
clk->base, data->offset, data->prevdiv_shift, data->prevdiv_width);
295292
/* Divider value is n+1 */
296-
unsigned long prediv_rate = DIV_ROUND_UP_ULL((uint64_t)prate,
297-
prediv_val + 1);
293+
uint64_t prediv_rate = DIV_ROUND_UP_ULL((uint64_t)prate, prediv_val + 1);
298294

299295
uint32_t postdiv_val = regmap_read_bits(
300296
clk->base, data->offset, data->postdiv_shift, data->postdiv_width);

drivers/clk/imx/clk.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ const struct clk *get_parent(const struct clk *clk)
9898

9999
/* TODO: Should be just read from the structure, but need to update everytime when */
100100
/* related clocks are modified */
101-
uint32_t clk_get_rate(const struct clk *clk, uint64_t *rate)
101+
int clk_get_rate(const struct clk *clk, uint64_t *rate)
102102
{
103103
if (!clk)
104104
return CLK_UNKNOWN_TARGET;
105105

106106
const struct clk_init_data *init = (struct clk_init_data *)clk->hw.init;
107107
uint64_t parent_rate = 0;
108-
uint32_t err = 0;
108+
int err = 0;
109109

110110
const struct clk *parent_clk = get_parent(clk);
111111

@@ -124,7 +124,7 @@ uint32_t clk_get_rate(const struct clk *clk, uint64_t *rate)
124124
return 0;
125125
}
126126

127-
uint32_t clk_enable(struct clk *clk)
127+
int clk_enable(struct clk *clk)
128128
{
129129
if (!clk)
130130
return CLK_UNKNOWN_TARGET;
@@ -136,7 +136,7 @@ uint32_t clk_enable(struct clk *clk)
136136
return CLK_INVALID_OP;
137137
}
138138

139-
uint32_t clk_disable(struct clk *clk)
139+
int clk_disable(struct clk *clk)
140140
{
141141
if (!clk)
142142
return CLK_UNKNOWN_TARGET;
@@ -148,7 +148,7 @@ uint32_t clk_disable(struct clk *clk)
148148
return CLK_INVALID_OP;
149149
}
150150

151-
uint32_t clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate)
151+
int clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate)
152152
{
153153
if (!clk)
154154
return CLK_UNKNOWN_TARGET;
@@ -161,7 +161,7 @@ uint32_t clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate)
161161

162162
const struct clk *pclk = get_parent(clk);
163163
uint64_t prate = 0;
164-
uint32_t err = clk_get_rate(pclk, &prate);
164+
int err = clk_get_rate(pclk, &prate);
165165
if (err) {
166166
LOG_DRIVER_ERR("Failed to get parent clock's rate\n");
167167
return err;
@@ -174,7 +174,7 @@ uint32_t clk_set_rate(struct clk *clk, uint64_t req_rate, uint64_t *rate)
174174
if (pclk && pclk->hw.init->ops->set_rate) {
175175
const struct clk *ppclk = get_parent(pclk);
176176
uint64_t pprate = 0;
177-
uint32_t err = clk_get_rate(ppclk, &pprate);
177+
int err = clk_get_rate(ppclk, &pprate);
178178
if (!err) {
179179
pclk->hw.init->ops->set_rate(pclk, prate, pprate);
180180
return 0;
@@ -190,7 +190,7 @@ int clk_msr_stat()
190190
#ifdef DEBUG_DRIVER
191191
int i;
192192
uint64_t rate = 0;
193-
uint32_t err;
193+
int err;
194194

195195
LOG_DRIVER("-------Expected clock rates------\n");
196196
for (i = 0; i < NUM_CLK_LIST; i++) {
@@ -199,6 +199,7 @@ int clk_msr_stat()
199199
if (err) {
200200
LOG_DRIVER_ERR("Failed to get rate of %s: -%u\n",
201201
clk_list[i]->hw.init->name, err);
202+
return err;
202203
}
203204
LOG_DRIVER("[%4d][%10luHz] %s\n", i, rate,
204205
clk_list[i]->hw.init->name);
@@ -244,7 +245,7 @@ void init(void)
244245

245246
microkit_msginfo protected(microkit_channel ch, microkit_msginfo msginfo)
246247
{
247-
uint32_t err = 0;
248+
int err = 0;
248249
uint32_t argc = microkit_msginfo_get_count(msginfo);
249250

250251
/* TODO: Check if the channel is valid */

drivers/clk/imx/include/clk-imx.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ struct clk _name = { \
244244
}, \
245245
}
246246

247-
#define IMX_CLK_GATE2_FLAGS(_name, _parent_clks, _base, _offset, _shift, \
248-
_flags) \
247+
#define IMX_CLK_GATE2_FLAGS(_name, _parent_clks, _base, _offset, _shift, _flags) \
249248
struct clk _name = { \
250249
.base = (_base), \
251250
.data = &(struct clk_gate_data) { \

drivers/clk/meson/clk-meson.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ const struct clk_ops meson_clk_pll_ro_ops = {
220220
#define N2_MIN 4
221221
#define N2_MAX 511
222222

223-
static unsigned long mpll_recalc_rate(const struct clk *clk,
224-
unsigned long prate)
223+
static uint64_t mpll_recalc_rate(const struct clk *clk, uint64_t prate)
225224
{
226225
struct meson_clk_mpll_data *data =
227226
(struct meson_clk_mpll_data *)(clk->data);
@@ -239,8 +238,8 @@ static unsigned long mpll_recalc_rate(const struct clk *clk,
239238
return DIV_ROUND_UP_ULL((uint64_t)prate * SDM_DEN, divisor);
240239
}
241240

242-
static int mpll_set_rate(const struct clk *clk, uint32_t rate,
243-
uint32_t parent_rate)
241+
static int mpll_set_rate(const struct clk *clk, uint64_t rate,
242+
uint64_t parent_rate)
244243
{
245244
struct meson_clk_mpll_data *data =
246245
(struct meson_clk_mpll_data *)(clk->data);
@@ -291,7 +290,7 @@ static void mpll_init(struct clk *clk)
291290
data->sdm_en.width, 1);
292291

293292
/* Set spread spectrum if possible */
294-
unsigned int ss = data->flags & CLK_MESON_MPLL_SPREAD_SPECTRUM ? 1 : 0;
293+
uint32_t ss = data->flags & CLK_MESON_MPLL_SPREAD_SPECTRUM ? 1 : 0;
295294
regmap_update_bits(clk->base, data->ssen.reg_off, data->ssen.shift,
296295
data->ssen.width, ss);
297296
}
@@ -457,8 +456,8 @@ static unsigned long meson_vclk_div_recalc_rate(const struct clk *clk,
457456
return DIV_ROUND_UP_ULL((uint64_t)prate, div);
458457
}
459458

460-
static int meson_vclk_div_set_rate(const struct clk *clk, uint32_t rate,
461-
uint32_t parent_rate)
459+
static int meson_vclk_div_set_rate(const struct clk *clk, uint64_t rate,
460+
uint64_t parent_rate)
462461
{
463462
struct meson_vclk_div_data *data =
464463
(struct meson_vclk_div_data *)(clk->data);

0 commit comments

Comments
 (0)