Skip to content

Commit 81432e2

Browse files
bjdooks-ctthierryreding
authored andcommitted
pwm: dwc: make timer clock configurable
Add a configurable clock base rate for the pwm as when being built for non-PCI the block may be sourced from an internal clock. Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.kernel.org/r/20230907161242.67190-3-ben.dooks@codethink.co.uk Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
1 parent 721ee18 commit 81432e2

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

drivers/pwm/pwm-dwc-core.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ static int __dwc_pwm_configure_timer(struct dwc_pwm *dwc,
4949
* periods and check are the result within HW limits between 1 and
5050
* 2^32 periods.
5151
*/
52-
tmp = DIV_ROUND_CLOSEST_ULL(state->duty_cycle, DWC_CLK_PERIOD_NS);
52+
tmp = DIV_ROUND_CLOSEST_ULL(state->duty_cycle, dwc->clk_ns);
5353
if (tmp < 1 || tmp > (1ULL << 32))
5454
return -ERANGE;
5555
low = tmp - 1;
5656

5757
tmp = DIV_ROUND_CLOSEST_ULL(state->period - state->duty_cycle,
58-
DWC_CLK_PERIOD_NS);
58+
dwc->clk_ns);
5959
if (tmp < 1 || tmp > (1ULL << 32))
6060
return -ERANGE;
6161
high = tmp - 1;
@@ -130,12 +130,12 @@ static int dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
130130

131131
duty = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT(pwm->hwpwm));
132132
duty += 1;
133-
duty *= DWC_CLK_PERIOD_NS;
133+
duty *= dwc->clk_ns;
134134
state->duty_cycle = duty;
135135

136136
period = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT2(pwm->hwpwm));
137137
period += 1;
138-
period *= DWC_CLK_PERIOD_NS;
138+
period *= dwc->clk_ns;
139139
period += duty;
140140
state->period = period;
141141

@@ -159,6 +159,7 @@ struct dwc_pwm *dwc_pwm_alloc(struct device *dev)
159159
if (!dwc)
160160
return NULL;
161161

162+
dwc->clk_ns = 10;
162163
dwc->chip.dev = dev;
163164
dwc->chip.ops = &dwc_pwm_ops;
164165
dwc->chip.npwm = DWC_TIMERS_TOTAL;

drivers/pwm/pwm-dwc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ MODULE_IMPORT_NS(dwc_pwm);
2424
#define DWC_TIMERS_COMP_VERSION 0xac
2525

2626
#define DWC_TIMERS_TOTAL 8
27-
#define DWC_CLK_PERIOD_NS 10
2827

2928
/* Timer Control Register */
3029
#define DWC_TIM_CTRL_EN BIT(0)
@@ -43,6 +42,7 @@ struct dwc_pwm_ctx {
4342
struct dwc_pwm {
4443
struct pwm_chip chip;
4544
void __iomem *base;
45+
unsigned int clk_ns;
4646
struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL];
4747
};
4848
#define to_dwc_pwm(p) (container_of((p), struct dwc_pwm, chip))

0 commit comments

Comments
 (0)