Skip to content

Commit 2485c02

Browse files
michalsieroncarlescufi
authored andcommitted
pwm: pwm_litex: Use LiteX HAL
Removed register sizes from config struct, as they are known. This allowed to remove driver specific function reading from CSR and use `litex_write*` functions from LiteX HAL. Signed-off-by: Michal Sieron <[email protected]>
1 parent 0bfa223 commit 2485c02

File tree

1 file changed

+11
-40
lines changed

1 file changed

+11
-40
lines changed

drivers/pwm/pwm_litex.c

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,16 @@
1717
#define NUMBER_OF_CHANNELS 1
1818

1919
struct pwm_litex_cfg {
20-
uint32_t reg_en_size;
21-
uint32_t reg_width_size;
22-
uint32_t reg_period_size;
23-
volatile uint32_t *reg_en;
24-
volatile uint32_t *reg_width;
25-
volatile uint32_t *reg_period;
20+
uint32_t reg_en;
21+
uint32_t reg_width;
22+
uint32_t reg_period;
2623
};
2724

28-
static void litex_set_reg(volatile uint32_t *reg, uint32_t reg_size, uint32_t val)
29-
{
30-
uint32_t shifted_data;
31-
volatile uint32_t *reg_addr;
32-
33-
for (int i = 0; i < reg_size; ++i) {
34-
shifted_data = val >> ((reg_size - i - 1) * 8);
35-
reg_addr = ((volatile uint32_t *) reg) + i;
36-
*(reg_addr) = shifted_data;
37-
}
38-
}
39-
4025
int pwm_litex_init(const struct device *dev)
4126
{
4227
const struct pwm_litex_cfg *cfg = dev->config;
4328

44-
litex_set_reg(cfg->reg_en, cfg->reg_en_size, REG_EN_ENABLE);
29+
litex_write8(REG_EN_ENABLE, cfg->reg_en);
4530
return 0;
4631
}
4732

@@ -55,10 +40,10 @@ int pwm_litex_set_cycles(const struct device *dev, uint32_t channel,
5540
return -EINVAL;
5641
}
5742

58-
litex_set_reg(cfg->reg_en, cfg->reg_en_size, REG_EN_DISABLE);
59-
litex_set_reg(cfg->reg_width, cfg->reg_width_size, pulse_cycles);
60-
litex_set_reg(cfg->reg_period, cfg->reg_period_size, period_cycles);
61-
litex_set_reg(cfg->reg_en, cfg->reg_en_size, REG_EN_ENABLE);
43+
litex_write8(REG_EN_DISABLE, cfg->reg_en);
44+
litex_write32(pulse_cycles, cfg->reg_width);
45+
litex_write32(period_cycles, cfg->reg_period);
46+
litex_write8(REG_EN_ENABLE, cfg->reg_en);
6247

6348
return 0;
6449
}
@@ -81,25 +66,11 @@ static const struct pwm_driver_api pwm_litex_driver_api = {
8166

8267
/* Device Instantiation */
8368

84-
/* LiteX registers use only first byte from 4-bytes register, that's why they
85-
* occupy larger space in memory. We need to know the size that is
86-
* actually used, that is why the register size from dts is divided by 4.
87-
*/
88-
8969
#define PWM_LITEX_INIT(n) \
9070
static const struct pwm_litex_cfg pwm_litex_cfg_##n = { \
91-
.reg_en = \
92-
(volatile uint32_t *) \
93-
DT_INST_REG_ADDR_BY_NAME(n, enable), \
94-
.reg_en_size = DT_INST_REG_SIZE_BY_NAME(n, enable) / 4, \
95-
.reg_width = \
96-
(volatile uint32_t *) \
97-
DT_INST_REG_ADDR_BY_NAME(n, width), \
98-
.reg_width_size = DT_INST_REG_SIZE_BY_NAME(n, width) / 4, \
99-
.reg_period = \
100-
(volatile uint32_t *) \
101-
DT_INST_REG_ADDR_BY_NAME(n, period), \
102-
.reg_period_size = DT_INST_REG_SIZE_BY_NAME(n, period) / 4, \
71+
.reg_en = DT_INST_REG_ADDR_BY_NAME(n, enable), \
72+
.reg_width = DT_INST_REG_ADDR_BY_NAME(n, width), \
73+
.reg_period = DT_INST_REG_ADDR_BY_NAME(n, period), \
10374
}; \
10475
\
10576
DEVICE_DT_INST_DEFINE(n, \

0 commit comments

Comments
 (0)