Skip to content

Commit 6204c09

Browse files
drivers: clock_control: add Infineon PSOC4 support
Add clock control driver support for Infineon PSoC4: - Fixed clock driver (clock_control_ifx_fixed_clock.c) - Fixed factor clock driver (clock_control_ifx_fixed_factor_clock.c) - Peripheral clock driver (clock_control_ifx_peri_clock.c) - CAT1 clock control header Provides clock initialization and management based on devicetree configuration. Signed-off-by: Dharun krithik k <[email protected]> Signed-off-by: Sayooj K Karun <[email protected]> Signed-off-by: Manojkumar Konisetty <[email protected]> Signed-off-by: Deepika aerlync <[email protected]>
1 parent fda8048 commit 6204c09

File tree

4 files changed

+49
-33
lines changed

4 files changed

+49
-33
lines changed

drivers/clock_control/clock_control_ifx_fixed_clock.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,41 @@ static int fixed_rate_clk_init(const struct device *dev)
8484
const struct fixed_rate_clock_config *const config = dev->config;
8585

8686
switch (config->system_clock) {
87-
87+
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_imo))
8888
case IFX_IMO:
89+
Cy_SysClk_ImoEnable();
90+
#if defined(CONFIG_SOC_FAMILY_INFINEON_PSOC4)
91+
int err = Cy_SysClk_ImoSetFrequency(config->rate);
92+
93+
if (err != CY_SYSCLK_SUCCESS) {
94+
printk("Failed to set IMO frequency with (error: %d)\n", err);
95+
return -EIO;
96+
}
97+
#endif
8998
break;
90-
99+
#endif
91100
case IFX_FLL:
92101
break;
93102

103+
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_iho))
94104
case IFX_IHO:
95105
Cy_SysClk_IhoEnable();
96106
break;
107+
#endif
97108

109+
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(clk_pilo))
98110
case IFX_PILO:
99111
Cy_SysClk_PiloEnable();
100112
break;
113+
#endif
101114

102115
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(dpll_hp))
103116
case IFX_DPLL500:
104117
ifx_clk_dpll_hp0_init();
105118
SystemCoreClockUpdate();
106119
break;
107120
#endif
121+
108122
default:
109123
break;
110124
}

drivers/clock_control/clock_control_ifx_fixed_factor_clock.c

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <zephyr/drivers/clock_control.h>
1313
#include <zephyr/kernel.h>
14-
#include <zephyr/logging/log.h>
1514
#include <stdlib.h>
1615

1716
#include <infineon_kconfig.h>
@@ -23,61 +22,53 @@
2322

2423
#define DT_DRV_COMPAT infineon_fixed_factor_clock
2524

26-
LOG_MODULE_REGISTER(clock_control_ifx_fixed_factor_clock, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
27-
2825
struct fixed_factor_clock_config {
2926
uint32_t divider;
3027
uint32_t block; /* ifx_cat1_clock_block */
3128
uint32_t instance;
3229
uint32_t source_path;
30+
uint32_t source_block;
3331
};
3432

35-
static int check_legal_max_min(const struct device *dev)
33+
static int fixed_factor_clk_init(const struct device *dev)
3634
{
3735
const struct fixed_factor_clock_config *const config = dev->config;
36+
uint32_t source_instance;
3837

39-
#if defined(CONFIG_SOC_SERIES_PSE84)
40-
if (config->block == IFX_HF && config->instance == 0) {
41-
if (Cy_SysClk_ClkHfGetFrequency(0) > MHZ(200)) {
42-
LOG_ERR("clk_hf0 frequency is greater than legal max 200 MHz");
43-
return -EINVAL;
44-
}
45-
}
46-
#elif defined(CONFIG_SOC_SERIES_PSC3)
47-
if (config->block == IFX_HF && config->instance == 0) {
48-
if (Cy_SysClk_ClkHfGetFrequency(0) > MHZ(180)) {
49-
LOG_ERR("clk_hf0 frequency is greater than legal max 180 MHz");
50-
return -EINVAL;
51-
}
52-
}
53-
#endif
38+
switch (config->source_block) {
5439

55-
return 0;
56-
}
40+
case IFX_DPLL250_1:
41+
source_instance = 1;
42+
break;
5743

58-
static int fixed_factor_clk_init(const struct device *dev)
59-
{
60-
const struct fixed_factor_clock_config *const config = dev->config;
61-
uint32_t rslt;
44+
default:
45+
source_instance = 0;
46+
break;
47+
}
6248

6349
switch (config->block) {
6450

6551
case IFX_PATHMUX:
52+
#if !defined(CONFIG_SOC_FAMILY_INFINEON_PSOC4)
6653
Cy_SysClk_ClkPathSetSource(config->instance, config->source_path);
54+
#endif
6755
break;
6856

6957
case IFX_HF:
70-
Cy_SysClk_ClkHfSetSource(config->instance, config->source_path);
58+
#if defined(CONFIG_SOC_FAMILY_INFINEON_PSOC4)
59+
Cy_SysClk_ClkHfSetSource(source_instance);
60+
Cy_SysClk_ClkHfSetDivider(config->divider);
61+
#else
62+
Cy_SysClk_ClkHfSetSource(config->instance, source_instance);
7163
Cy_SysClk_ClkHfSetDivider(config->instance, config->divider);
7264
Cy_SysClk_ClkHfEnable(config->instance);
65+
#endif
7366
break;
7467

7568
default:
7669
return -EINVAL;
7770
}
7871

79-
rslt = check_legal_max_min(dev);
80-
8172
return 0;
8273
}
8374

@@ -87,6 +78,7 @@ static int fixed_factor_clk_init(const struct device *dev)
8778
.block = DT_INST_PROP(n, system_clock), \
8879
.instance = DT_INST_PROP(n, instance), \
8980
.source_path = DT_INST_PROP_OR(n, source_path, 1u), \
81+
.source_block = DT_INST_PROP_BY_PHANDLE(n, clocks, system_clock), \
9082
}; \
9183
DEVICE_DT_INST_DEFINE(n, fixed_factor_clk_init, NULL, NULL, \
9284
&fixed_factor_clock_config_##n, PRE_KERNEL_1, \

drivers/clock_control/clock_control_ifx_peri_clock.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <cy_sysclk.h>
2323
#include <cy_systick.h>
2424

25-
struct ifx_cat1_peri_clock_data {
25+
struct ifx_peri_clock_data {
2626
struct ifx_cat1_resource_inst hw_resource;
2727
struct ifx_cat1_clock clock;
2828
uint16_t divider;
@@ -67,12 +67,13 @@ en_clk_dst_t ifx_cat1_scb_get_clock_index(uint32_t block_num)
6767
#else
6868
clk = (en_clk_dst_t)((uint32_t)_IFX_CAT1_SCB0_PCLK_CLOCK + block_num);
6969
#endif
70+
7071
return clk;
7172
}
7273

7374
static int ifx_cat1_peri_clock_init(const struct device *dev)
7475
{
75-
struct ifx_cat1_peri_clock_data *const data = dev->data;
76+
struct ifx_peri_clock_data *const data = dev->data;
7677

7778
if (data->hw_resource.type == IFX_RSC_SCB) {
7879
en_clk_dst_t clk_idx = ifx_cat1_scb_get_clock_index(data->hw_resource.block_num);
@@ -105,7 +106,7 @@ static int ifx_cat1_peri_clock_init(const struct device *dev)
105106
#endif
106107

107108
#define INFINEON_CAT1_PERI_CLOCK_INIT(n) \
108-
static struct ifx_cat1_peri_clock_data ifx_cat1_peri_clock##n##_data = { \
109+
static struct ifx_peri_clock_data ifx_cat1_peri_clock##n##_data = { \
109110
PERI_CLOCK_INIT(n).divider = DT_INST_PROP(n, clock_div), \
110111
.hw_resource = {.type = DT_INST_PROP(n, resource_type), \
111112
.block_num = DT_INST_PROP(n, resource_instance)}, \

include/zephyr/drivers/clock_control/clock_control_ifx_cat1.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,15 @@ enum ifx_cat1_clock_block {
369369
IFX_CAT1_CLOCK_BLOCK_BAK, /*!< Backup Power Domain Clock */
370370
IFX_CAT1_CLOCK_BLOCK_PERI, /*!< Peripheral Clock Group */
371371

372+
#elif defined(CONFIG_SOC_FAMILY_INFINEON_PSOC4)
373+
IFX_CAT1_CLOCK_BLOCK_PERIPHERAL_16BIT =
374+
CY_SYSCLK_DIV_16_BIT, /* Equal to IFX_CAT1_CLOCK_BLOCK_PERIPHERAL0_16_BIT */
375+
376+
IFX_CAT1_CLOCK_BLOCK_PERIPHERAL_16_5BIT =
377+
CY_SYSCLK_DIV_16_5_BIT, /* Equal to IFX_CAT1_CLOCK_BLOCK_PERIPHERAL0_16_5_BIT */
378+
379+
IFX_CAT1_CLOCK_BLOCK_PERIPHERAL_24_5BIT =
380+
CY_SYSCLK_DIV_24_5_BIT, /* Equal to IFX_CAT1_CLOCK_BLOCK_PERIPHERAL0_24_5_BIT */
372381
#endif
373382
};
374383

0 commit comments

Comments
 (0)