diff options
author | Michal Vokáč <michal.vokac@ysoft.com> | 2018-10-01 10:19:47 -0400 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2018-12-12 05:52:32 -0500 |
commit | 9f617ada9f823dff1944ebcf92ef4a05f5f322b7 (patch) | |
tree | fb45b09cc7e5df9d4cf7bd55b8d3a0210c2b5316 | |
parent | e3adc7efe678ba907f99791f5adfee81faea10e6 (diff) |
pwm: imx: Use bitops and bitfield macros to define register values
Use existing macros to define register fields instead of manually shifting
the bit masks. Also define some more register bits.
Signed-off-by: Michal Vokáč <michal.vokac@ysoft.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
-rw-r--r-- | drivers/pwm/pwm-imx.c | 78 |
1 files changed, 58 insertions, 20 deletions
diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c index bcbcac405718..7a4907b73d7c 100644 --- a/drivers/pwm/pwm-imx.c +++ b/drivers/pwm/pwm-imx.c | |||
@@ -5,6 +5,8 @@ | |||
5 | * Derived from pxa PWM driver by eric miao <eric.miao@marvell.com> | 5 | * Derived from pxa PWM driver by eric miao <eric.miao@marvell.com> |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <linux/bitfield.h> | ||
9 | #include <linux/bitops.h> | ||
8 | #include <linux/clk.h> | 10 | #include <linux/clk.h> |
9 | #include <linux/delay.h> | 11 | #include <linux/delay.h> |
10 | #include <linux/err.h> | 12 | #include <linux/err.h> |
@@ -23,7 +25,7 @@ | |||
23 | #define MX1_PWMS 0x04 /* PWM Sample Register */ | 25 | #define MX1_PWMS 0x04 /* PWM Sample Register */ |
24 | #define MX1_PWMP 0x08 /* PWM Period Register */ | 26 | #define MX1_PWMP 0x08 /* PWM Period Register */ |
25 | 27 | ||
26 | #define MX1_PWMC_EN (1 << 4) | 28 | #define MX1_PWMC_EN BIT(4) |
27 | 29 | ||
28 | /* i.MX27, i.MX31, i.MX35 share the same PWM function block: */ | 30 | /* i.MX27, i.MX31, i.MX35 share the same PWM function block: */ |
29 | 31 | ||
@@ -31,18 +33,53 @@ | |||
31 | #define MX3_PWMSR 0x04 /* PWM Status Register */ | 33 | #define MX3_PWMSR 0x04 /* PWM Status Register */ |
32 | #define MX3_PWMSAR 0x0C /* PWM Sample Register */ | 34 | #define MX3_PWMSAR 0x0C /* PWM Sample Register */ |
33 | #define MX3_PWMPR 0x10 /* PWM Period Register */ | 35 | #define MX3_PWMPR 0x10 /* PWM Period Register */ |
34 | #define MX3_PWMCR_PRESCALER(x) ((((x) - 1) & 0xFFF) << 4) | 36 | |
35 | #define MX3_PWMCR_STOPEN (1 << 25) | 37 | #define MX3_PWMCR_FWM GENMASK(27, 26) |
36 | #define MX3_PWMCR_DOZEEN (1 << 24) | 38 | #define MX3_PWMCR_STOPEN BIT(25) |
37 | #define MX3_PWMCR_WAITEN (1 << 23) | 39 | #define MX3_PWMCR_DOZEN BIT(24) |
38 | #define MX3_PWMCR_DBGEN (1 << 22) | 40 | #define MX3_PWMCR_WAITEN BIT(23) |
39 | #define MX3_PWMCR_POUTC (1 << 18) | 41 | #define MX3_PWMCR_DBGEN BIT(22) |
40 | #define MX3_PWMCR_CLKSRC_IPG_HIGH (2 << 16) | 42 | #define MX3_PWMCR_BCTR BIT(21) |
41 | #define MX3_PWMCR_CLKSRC_IPG (1 << 16) | 43 | #define MX3_PWMCR_HCTR BIT(20) |
42 | #define MX3_PWMCR_SWR (1 << 3) | 44 | |
43 | #define MX3_PWMCR_EN (1 << 0) | 45 | #define MX3_PWMCR_POUTC GENMASK(19, 18) |
44 | #define MX3_PWMSR_FIFOAV_4WORDS 0x4 | 46 | #define MX3_PWMCR_POUTC_NORMAL 0 |
45 | #define MX3_PWMSR_FIFOAV_MASK 0x7 | 47 | #define MX3_PWMCR_POUTC_INVERTED 1 |
48 | #define MX3_PWMCR_POUTC_OFF 2 | ||
49 | |||
50 | #define MX3_PWMCR_CLKSRC GENMASK(17, 16) | ||
51 | #define MX3_PWMCR_CLKSRC_OFF 0 | ||
52 | #define MX3_PWMCR_CLKSRC_IPG 1 | ||
53 | #define MX3_PWMCR_CLKSRC_IPG_HIGH 2 | ||
54 | #define MX3_PWMCR_CLKSRC_IPG_32K 3 | ||
55 | |||
56 | #define MX3_PWMCR_PRESCALER GENMASK(15, 4) | ||
57 | |||
58 | #define MX3_PWMCR_SWR BIT(3) | ||
59 | |||
60 | #define MX3_PWMCR_REPEAT GENMASK(2, 1) | ||
61 | #define MX3_PWMCR_REPEAT_1X 0 | ||
62 | #define MX3_PWMCR_REPEAT_2X 1 | ||
63 | #define MX3_PWMCR_REPEAT_4X 2 | ||
64 | #define MX3_PWMCR_REPEAT_8X 3 | ||
65 | |||
66 | #define MX3_PWMCR_EN BIT(0) | ||
67 | |||
68 | #define MX3_PWMSR_FWE BIT(6) | ||
69 | #define MX3_PWMSR_CMP BIT(5) | ||
70 | #define MX3_PWMSR_ROV BIT(4) | ||
71 | #define MX3_PWMSR_FE BIT(3) | ||
72 | |||
73 | #define MX3_PWMSR_FIFOAV GENMASK(2, 0) | ||
74 | #define MX3_PWMSR_FIFOAV_EMPTY 0 | ||
75 | #define MX3_PWMSR_FIFOAV_1WORD 1 | ||
76 | #define MX3_PWMSR_FIFOAV_2WORDS 2 | ||
77 | #define MX3_PWMSR_FIFOAV_3WORDS 3 | ||
78 | #define MX3_PWMSR_FIFOAV_4WORDS 4 | ||
79 | |||
80 | #define MX3_PWMCR_PRESCALER_SET(x) FIELD_PREP(MX3_PWMCR_PRESCALER, (x) - 1) | ||
81 | #define MX3_PWMCR_PRESCALER_GET(x) (FIELD_GET(MX3_PWMCR_PRESCALER, \ | ||
82 | (x)) + 1) | ||
46 | 83 | ||
47 | #define MX3_PWM_SWR_LOOP 5 | 84 | #define MX3_PWM_SWR_LOOP 5 |
48 | 85 | ||
@@ -142,14 +179,14 @@ static void imx_pwm_wait_fifo_slot(struct pwm_chip *chip, | |||
142 | u32 sr; | 179 | u32 sr; |
143 | 180 | ||
144 | sr = readl(imx->mmio_base + MX3_PWMSR); | 181 | sr = readl(imx->mmio_base + MX3_PWMSR); |
145 | fifoav = sr & MX3_PWMSR_FIFOAV_MASK; | 182 | fifoav = FIELD_GET(MX3_PWMSR_FIFOAV, sr); |
146 | if (fifoav == MX3_PWMSR_FIFOAV_4WORDS) { | 183 | if (fifoav == MX3_PWMSR_FIFOAV_4WORDS) { |
147 | period_ms = DIV_ROUND_UP(pwm_get_period(pwm), | 184 | period_ms = DIV_ROUND_UP(pwm_get_period(pwm), |
148 | NSEC_PER_MSEC); | 185 | NSEC_PER_MSEC); |
149 | msleep(period_ms); | 186 | msleep(period_ms); |
150 | 187 | ||
151 | sr = readl(imx->mmio_base + MX3_PWMSR); | 188 | sr = readl(imx->mmio_base + MX3_PWMSR); |
152 | if (fifoav == (sr & MX3_PWMSR_FIFOAV_MASK)) | 189 | if (fifoav == FIELD_GET(MX3_PWMSR_FIFOAV, sr)) |
153 | dev_warn(dev, "there is no free FIFO slot\n"); | 190 | dev_warn(dev, "there is no free FIFO slot\n"); |
154 | } | 191 | } |
155 | } | 192 | } |
@@ -207,13 +244,14 @@ static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm, | |||
207 | writel(duty_cycles, imx->mmio_base + MX3_PWMSAR); | 244 | writel(duty_cycles, imx->mmio_base + MX3_PWMSAR); |
208 | writel(period_cycles, imx->mmio_base + MX3_PWMPR); | 245 | writel(period_cycles, imx->mmio_base + MX3_PWMPR); |
209 | 246 | ||
210 | cr = MX3_PWMCR_PRESCALER(prescale) | | 247 | cr = MX3_PWMCR_PRESCALER_SET(prescale) | |
211 | MX3_PWMCR_STOPEN | MX3_PWMCR_DOZEEN | MX3_PWMCR_WAITEN | | 248 | MX3_PWMCR_STOPEN | MX3_PWMCR_DOZEN | MX3_PWMCR_WAITEN | |
212 | MX3_PWMCR_DBGEN | MX3_PWMCR_CLKSRC_IPG_HIGH | | 249 | FIELD_PREP(MX3_PWMCR_CLKSRC, MX3_PWMCR_CLKSRC_IPG_HIGH) | |
213 | MX3_PWMCR_EN; | 250 | MX3_PWMCR_DBGEN | MX3_PWMCR_EN; |
214 | 251 | ||
215 | if (state->polarity == PWM_POLARITY_INVERSED) | 252 | if (state->polarity == PWM_POLARITY_INVERSED) |
216 | cr |= MX3_PWMCR_POUTC; | 253 | cr |= FIELD_PREP(MX3_PWMCR_POUTC, |
254 | MX3_PWMCR_POUTC_INVERTED); | ||
217 | 255 | ||
218 | writel(cr, imx->mmio_base + MX3_PWMCR); | 256 | writel(cr, imx->mmio_base + MX3_PWMCR); |
219 | } else if (cstate.enabled) { | 257 | } else if (cstate.enabled) { |