@@ -21,18 +21,18 @@ struct debug_info {
21
21
long (* fn )(uint32_t );
22
22
uint32_t reg_id ;
23
23
const char * name ;
24
- parent_id_t parents [4 ];
24
+ ccu_parent_id_t parents [4 ];
25
25
uint32_t ncount , mcount ;
26
26
};
27
27
static struct debug_info * info_for_id (uint32_t id );
28
- static long debug_rate_pll (pll_id_t id );
29
- static long debug_rate_clk (module_clk_id_t id );
30
- static long debug_rate_bgr (bgr_id_t id );
31
- static long debug_rate_parent (parent_id_t id );
32
- static int get_parent_src_index (module_clk_id_t id , parent_id_t parent );
33
- static void validate_pll (pll_id_t id );
34
- static void validate_module_clk (module_clk_id_t id );
35
- static void validate_bgr (bgr_id_t id );
28
+ static long debug_rate_pll (ccu_pll_id_t id );
29
+ static long debug_rate_clk (ccu_module_id_t id );
30
+ static long debug_rate_bgr (ccu_bgr_id_t id );
31
+ static long debug_rate_parent (ccu_parent_id_t id );
32
+ static int get_parent_src_index (ccu_module_id_t id , ccu_parent_id_t parent );
33
+ static void validate_pll (ccu_pll_id_t id );
34
+ static void validate_module_clk (ccu_module_id_t id );
35
+ static void validate_bgr (ccu_bgr_id_t id );
36
36
37
37
typedef union {
38
38
struct {
@@ -88,7 +88,7 @@ static volatile uint32_t *reg_for_id(uint32_t raw_offset) {
88
88
// commonly used PLL rates and list in this table for easy access.
89
89
// if you need an additional rate config, simply add to this table
90
90
static const struct pll_config_t {
91
- pll_id_t pll_id ;
91
+ ccu_pll_id_t pll_id ;
92
92
uint32_t rate ;
93
93
struct { uint8_t P ; uint8_t N ; uint8_t M1 ; uint8_t M0 ; };
94
94
} pll_table [] = {
@@ -99,7 +99,7 @@ static const struct pll_config_t {
99
99
{0 }
100
100
};
101
101
102
- static const struct pll_config_t * get_pll_config_for_rate (pll_id_t id , long rate ) {
102
+ static const struct pll_config_t * get_pll_config_for_rate (ccu_pll_id_t id , long rate ) {
103
103
for (const struct pll_config_t * cfg = pll_table ; cfg -> rate != 0 ; cfg ++ ) {
104
104
if (cfg -> pll_id == id && cfg -> rate == rate ) return cfg ;
105
105
}
@@ -110,7 +110,7 @@ static const struct pll_config_t *get_pll_config_for_rate(pll_id_t id, long rate
110
110
#define BITS_N_M1 (n , m1 ) ((pll_reg_t){ .factor_n=n, .factor_m1=m1 }).bits
111
111
#define BITS_P_N_M1_M0 (p , n , m1 , m0 ) ((pll_reg_t){ .factor_p=p, .factor_n=n, .factor_m1=m1, .factor_m0=m0 }).bits;
112
112
113
- static void get_pll_bits (pll_id_t id , long rate , uint32_t * factor_mask , uint32_t * new_factors ) {
113
+ static void get_pll_bits (ccu_pll_id_t id , long rate , uint32_t * factor_mask , uint32_t * new_factors ) {
114
114
uint32_t out_mhz ;
115
115
const struct pll_config_t * cfg = get_pll_config_for_rate (id , rate );
116
116
if (!cfg ) error ("No matching pll config found in rate table." );
@@ -170,7 +170,7 @@ static void update_pll_bits(volatile uint32_t *reg, uint32_t factor_mask, uint32
170
170
* reg |= OUT_ENA ; // re-enable output
171
171
}
172
172
173
- long ccu_config_pll_rate (pll_id_t id , long rate ) {
173
+ long ccu_config_pll_rate (ccu_pll_id_t id , long rate ) {
174
174
validate_pll (id );
175
175
uint32_t factor_mask , new_factors ;
176
176
get_pll_bits (id , rate , & factor_mask , & new_factors );
@@ -180,7 +180,7 @@ long ccu_config_pll_rate(pll_id_t id, long rate) {
180
180
return set_rate ;
181
181
}
182
182
183
- static uint32_t get_module_clk_bits (module_clk_id_t id , parent_id_t parent , long rate ) {
183
+ static uint32_t get_module_clk_bits (ccu_module_id_t id , ccu_parent_id_t parent , long rate ) {
184
184
int src = get_parent_src_index (id , parent );
185
185
if (src == -1 ) error ("Parent id is not valid for module clock" )
186
186
long parent_rate = debug_rate_parent (parent );
@@ -220,7 +220,7 @@ static void update_clock_bits(volatile uint32_t *reg, uint32_t bits) {
220
220
* reg |= ENA ; // re-enable
221
221
}
222
222
223
- long ccu_config_module_clock_rate (module_clk_id_t id , parent_id_t parent , long rate ) {
223
+ long ccu_config_module_clock_rate (ccu_module_id_t id , ccu_parent_id_t parent , long rate ) {
224
224
validate_module_clk (id );
225
225
uint32_t new_bits = get_module_clk_bits (id , parent , rate );
226
226
update_clock_bits (reg_for_id (id ), new_bits );
@@ -235,7 +235,7 @@ long ccu_config_module_clock_rate(module_clk_id_t id, parent_id_t parent, long r
235
235
* and then the clock gating bit is enabled to avoid potential problems
236
236
* caused by the asynchronous release of the reset signal.
237
237
*/
238
- long ccu_ungate_bus_clock_bits (bgr_id_t id , uint32_t gating_bits , uint32_t reset_bits ) {
238
+ long ccu_ungate_bus_clock_bits (ccu_bgr_id_t id , uint32_t gating_bits , uint32_t reset_bits ) {
239
239
validate_bgr (id );
240
240
volatile uint32_t * reg = reg_for_id (id );
241
241
* reg |= reset_bits ; // de-assert reset
@@ -245,7 +245,7 @@ long ccu_ungate_bus_clock_bits(bgr_id_t id, uint32_t gating_bits, uint32_t reset
245
245
246
246
// most bus clocks use standard bits for reset/gate
247
247
// general function above allow other use cases
248
- long ccu_ungate_bus_clock (bgr_id_t id ) {
248
+ long ccu_ungate_bus_clock (ccu_bgr_id_t id ) {
249
249
const uint32_t standard_gating_bits = 1 << 0 ;
250
250
const uint32_t standard_reset_bits = 1 << 16 ;
251
251
return ccu_ungate_bus_clock_bits (id , standard_gating_bits , standard_reset_bits );
@@ -283,6 +283,7 @@ static struct debug_info info_table[] = {
283
283
{ INFO_CLK (CCU_SPI0_CLK_REG ), {PARENT_HOSC , PARENT_PERI , PARENT_PERI_2X }, .ncount = 2 ,.mcount = 4 },
284
284
{ INFO_CLK (CCU_SPI1_CLK_REG ), {PARENT_HOSC , PARENT_PERI , PARENT_PERI_2X }, .ncount = 2 ,.mcount = 4 },
285
285
{ INFO_CLK (CCU_I2S2_CLK_REG ), {PARENT_AUDIO0 , NOT_IN_MODEL , NOT_IN_MODEL , PARENT_AUDIO1_DIV5 }, .ncount = 0 ,.mcount = 5 },
286
+ { INFO_CLK (CCU_LEDC_CLK_REG ), {PARENT_HOSC , PARENT_PERI , NOT_IN_MODEL , NOT_IN_MODEL }, .ncount = 2 ,.mcount = 4 },
286
287
{ .name = "Bus Clock" },
287
288
{ INFO_BGR (CCU_DE_BGR_REG ), {PARENT_AHB0 } },
288
289
{ INFO_BGR (CCU_DPSS_TOP_BGR_REG ), {PARENT_AHB0 } },
@@ -295,10 +296,11 @@ static struct debug_info info_table[] = {
295
296
{ INFO_BGR (CCU_I2S_BGR_REG ), {PARENT_APB0 } },
296
297
{ INFO_BGR (CCU_TWI_BGR_REG ), {PARENT_APB1 } },
297
298
{ INFO_BGR (CCU_SPI_BGR_REG ), {PARENT_APB1 } },
299
+ { INFO_BGR (CCU_LEDC_BGR_REG ), {PARENT_APB1 } },
298
300
{0 },
299
301
};
300
302
301
- static int get_parent_src_index (module_clk_id_t id , parent_id_t parent ) {
303
+ static int get_parent_src_index (ccu_module_id_t id , ccu_parent_id_t parent ) {
302
304
for (struct debug_info * info = info_table ; info -> name ; info ++ ) {
303
305
if (info -> reg_id == id ) {
304
306
for (int i = 0 ; i < sizeof (info -> parents )/sizeof (* info -> parents ); i ++ ) {
@@ -330,7 +332,7 @@ void ccu_debug_show_clocks(const char *label) {
330
332
}
331
333
}
332
334
333
- static long debug_rate_parent (parent_id_t id ) {
335
+ static long debug_rate_parent (ccu_parent_id_t id ) {
334
336
int mult = 1 , div = 1 ;
335
337
switch (id ) {
336
338
case NOT_IN_MODEL : return -1 ;
@@ -354,7 +356,7 @@ static long debug_rate_parent(parent_id_t id) {
354
356
return -1 ;
355
357
}
356
358
357
- static long debug_rate_pll (pll_id_t id ) {
359
+ static long debug_rate_pll (ccu_pll_id_t id ) {
358
360
pll_reg_t pll ;
359
361
pll .bits = * reg_for_id (id );
360
362
if (!pll .ena || !pll .output_ena ) return 0 ;
@@ -373,34 +375,34 @@ static long debug_rate_pll(pll_id_t id) {
373
375
}
374
376
}
375
377
376
- static long debug_rate_clk (module_clk_id_t id ) {
378
+ static long debug_rate_clk (ccu_module_id_t id ) {
377
379
module_clk_reg_t clk ;
378
380
clk .bits = * reg_for_id (id );
379
381
if (id > CCU_APB1_CLK_REG && !clk .ena ) return 0 ; // cheezy (ena bits not applicable for psi/apb?)
380
382
int n = 1 << clk .factor_n ;
381
383
int m = clk .factor_m + 1 ;
382
384
struct debug_info * i = info_for_id (id );
383
- parent_id_t parent = i -> parents [clk .src ];
385
+ ccu_parent_id_t parent = i -> parents [clk .src ];
384
386
return debug_rate_parent (parent )/n /m ;
385
387
}
386
388
387
- static long debug_rate_bgr (bgr_id_t id ) {
389
+ static long debug_rate_bgr (ccu_bgr_id_t id ) {
388
390
uint32_t val = * reg_for_id (id );
389
391
struct debug_info * i = info_for_id (id );
390
392
return (val & 0xff ) ? debug_rate_parent (i -> parents [0 ]) : 0 ;
391
393
}
392
394
393
- static void validate_pll (pll_id_t id ) {
395
+ static void validate_pll (ccu_pll_id_t id ) {
394
396
struct debug_info * info = info_for_id (id );
395
397
if (!info || info -> fn != debug_rate_pll ) error ("PLL id is not valid" );
396
398
}
397
399
398
- static void validate_module_clk (module_clk_id_t id ) {
400
+ static void validate_module_clk (ccu_module_id_t id ) {
399
401
struct debug_info * info = info_for_id (id );
400
402
if (!info || info -> fn != debug_rate_clk ) error ("Module clock id is not valid" );
401
403
}
402
404
403
- static void validate_bgr (bgr_id_t id ) {
405
+ static void validate_bgr (ccu_bgr_id_t id ) {
404
406
struct debug_info * info = info_for_id (id );
405
407
if (!info || info -> fn != debug_rate_bgr ) error ("Bus clock id is not valid" );
406
408
}
0 commit comments