Thomas Gleixner | 74ba920 | 2019-05-20 09:19:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 2 | /* |
| 3 | * EHRPWM PWM driver |
| 4 | * |
Alexander A. Klimov | 216a094 | 2020-07-08 19:59:24 +0200 | [diff] [blame] | 5 | * Copyright (C) 2012 Texas Instruments, Inc. - https://www.ti.com/ |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/platform_device.h> |
| 10 | #include <linux/pwm.h> |
| 11 | #include <linux/io.h> |
| 12 | #include <linux/err.h> |
| 13 | #include <linux/clk.h> |
| 14 | #include <linux/pm_runtime.h> |
Philip, Avinash | 53ad9e8d | 2012-11-27 14:18:13 +0530 | [diff] [blame] | 15 | #include <linux/of_device.h> |
| 16 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 17 | /* EHRPWM registers and bits definitions */ |
| 18 | |
| 19 | /* Time base module registers */ |
| 20 | #define TBCTL 0x00 |
| 21 | #define TBPRD 0x0A |
| 22 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 23 | #define TBCTL_PRDLD_MASK BIT(3) |
| 24 | #define TBCTL_PRDLD_SHDW 0 |
| 25 | #define TBCTL_PRDLD_IMDT BIT(3) |
| 26 | #define TBCTL_CLKDIV_MASK (BIT(12) | BIT(11) | BIT(10) | BIT(9) | \ |
| 27 | BIT(8) | BIT(7)) |
| 28 | #define TBCTL_CTRMODE_MASK (BIT(1) | BIT(0)) |
| 29 | #define TBCTL_CTRMODE_UP 0 |
| 30 | #define TBCTL_CTRMODE_DOWN BIT(0) |
| 31 | #define TBCTL_CTRMODE_UPDOWN BIT(1) |
| 32 | #define TBCTL_CTRMODE_FREEZE (BIT(1) | BIT(0)) |
| 33 | |
| 34 | #define TBCTL_HSPCLKDIV_SHIFT 7 |
| 35 | #define TBCTL_CLKDIV_SHIFT 10 |
| 36 | |
| 37 | #define CLKDIV_MAX 7 |
| 38 | #define HSPCLKDIV_MAX 7 |
| 39 | #define PERIOD_MAX 0xFFFF |
| 40 | |
| 41 | /* compare module registers */ |
| 42 | #define CMPA 0x12 |
| 43 | #define CMPB 0x14 |
| 44 | |
| 45 | /* Action qualifier module registers */ |
| 46 | #define AQCTLA 0x16 |
| 47 | #define AQCTLB 0x18 |
| 48 | #define AQSFRC 0x1A |
| 49 | #define AQCSFRC 0x1C |
| 50 | |
| 51 | #define AQCTL_CBU_MASK (BIT(9) | BIT(8)) |
| 52 | #define AQCTL_CBU_FRCLOW BIT(8) |
| 53 | #define AQCTL_CBU_FRCHIGH BIT(9) |
| 54 | #define AQCTL_CBU_FRCTOGGLE (BIT(9) | BIT(8)) |
| 55 | #define AQCTL_CAU_MASK (BIT(5) | BIT(4)) |
| 56 | #define AQCTL_CAU_FRCLOW BIT(4) |
| 57 | #define AQCTL_CAU_FRCHIGH BIT(5) |
| 58 | #define AQCTL_CAU_FRCTOGGLE (BIT(5) | BIT(4)) |
| 59 | #define AQCTL_PRD_MASK (BIT(3) | BIT(2)) |
| 60 | #define AQCTL_PRD_FRCLOW BIT(2) |
| 61 | #define AQCTL_PRD_FRCHIGH BIT(3) |
| 62 | #define AQCTL_PRD_FRCTOGGLE (BIT(3) | BIT(2)) |
| 63 | #define AQCTL_ZRO_MASK (BIT(1) | BIT(0)) |
| 64 | #define AQCTL_ZRO_FRCLOW BIT(0) |
| 65 | #define AQCTL_ZRO_FRCHIGH BIT(1) |
| 66 | #define AQCTL_ZRO_FRCTOGGLE (BIT(1) | BIT(0)) |
| 67 | |
Philip, Avinash | daa5629 | 2012-09-06 10:40:03 +0530 | [diff] [blame] | 68 | #define AQCTL_CHANA_POLNORMAL (AQCTL_CAU_FRCLOW | AQCTL_PRD_FRCHIGH | \ |
| 69 | AQCTL_ZRO_FRCHIGH) |
| 70 | #define AQCTL_CHANA_POLINVERSED (AQCTL_CAU_FRCHIGH | AQCTL_PRD_FRCLOW | \ |
| 71 | AQCTL_ZRO_FRCLOW) |
| 72 | #define AQCTL_CHANB_POLNORMAL (AQCTL_CBU_FRCLOW | AQCTL_PRD_FRCHIGH | \ |
| 73 | AQCTL_ZRO_FRCHIGH) |
| 74 | #define AQCTL_CHANB_POLINVERSED (AQCTL_CBU_FRCHIGH | AQCTL_PRD_FRCLOW | \ |
| 75 | AQCTL_ZRO_FRCLOW) |
| 76 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 77 | #define AQSFRC_RLDCSF_MASK (BIT(7) | BIT(6)) |
| 78 | #define AQSFRC_RLDCSF_ZRO 0 |
| 79 | #define AQSFRC_RLDCSF_PRD BIT(6) |
| 80 | #define AQSFRC_RLDCSF_ZROPRD BIT(7) |
| 81 | #define AQSFRC_RLDCSF_IMDT (BIT(7) | BIT(6)) |
| 82 | |
| 83 | #define AQCSFRC_CSFB_MASK (BIT(3) | BIT(2)) |
| 84 | #define AQCSFRC_CSFB_FRCDIS 0 |
| 85 | #define AQCSFRC_CSFB_FRCLOW BIT(2) |
| 86 | #define AQCSFRC_CSFB_FRCHIGH BIT(3) |
| 87 | #define AQCSFRC_CSFB_DISSWFRC (BIT(3) | BIT(2)) |
| 88 | #define AQCSFRC_CSFA_MASK (BIT(1) | BIT(0)) |
| 89 | #define AQCSFRC_CSFA_FRCDIS 0 |
| 90 | #define AQCSFRC_CSFA_FRCLOW BIT(0) |
| 91 | #define AQCSFRC_CSFA_FRCHIGH BIT(1) |
| 92 | #define AQCSFRC_CSFA_DISSWFRC (BIT(1) | BIT(0)) |
| 93 | |
| 94 | #define NUM_PWM_CHANNEL 2 /* EHRPWM channels */ |
| 95 | |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 96 | struct ehrpwm_context { |
| 97 | u16 tbctl; |
| 98 | u16 tbprd; |
| 99 | u16 cmpa; |
| 100 | u16 cmpb; |
| 101 | u16 aqctla; |
| 102 | u16 aqctlb; |
| 103 | u16 aqsfrc; |
| 104 | u16 aqcsfrc; |
| 105 | }; |
| 106 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 107 | struct ehrpwm_pwm_chip { |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 108 | struct pwm_chip chip; |
| 109 | unsigned long clk_rate; |
| 110 | void __iomem *mmio_base; |
Philip, Avinash | 01b2d45 | 2012-09-06 10:44:25 +0530 | [diff] [blame] | 111 | unsigned long period_cycles[NUM_PWM_CHANNEL]; |
Philip, Avinash | daa5629 | 2012-09-06 10:40:03 +0530 | [diff] [blame] | 112 | enum pwm_polarity polarity[NUM_PWM_CHANNEL]; |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 113 | struct clk *tbclk; |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 114 | struct ehrpwm_context ctx; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | static inline struct ehrpwm_pwm_chip *to_ehrpwm_pwm_chip(struct pwm_chip *chip) |
| 118 | { |
| 119 | return container_of(chip, struct ehrpwm_pwm_chip, chip); |
| 120 | } |
| 121 | |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 122 | static inline u16 ehrpwm_read(void __iomem *base, unsigned int offset) |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 123 | { |
| 124 | return readw(base + offset); |
| 125 | } |
| 126 | |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 127 | static inline void ehrpwm_write(void __iomem *base, unsigned int offset, |
| 128 | u16 value) |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 129 | { |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 130 | writew(value, base + offset); |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 131 | } |
| 132 | |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 133 | static void ehrpwm_modify(void __iomem *base, unsigned int offset, u16 mask, |
| 134 | u16 value) |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 135 | { |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 136 | unsigned short val; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 137 | |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 138 | val = readw(base + offset); |
| 139 | val &= ~mask; |
| 140 | val |= value & mask; |
| 141 | writew(val, base + offset); |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /** |
| 145 | * set_prescale_div - Set up the prescaler divider function |
| 146 | * @rqst_prescaler: prescaler value min |
| 147 | * @prescale_div: prescaler value set |
| 148 | * @tb_clk_div: Time Base Control prescaler bits |
| 149 | */ |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 150 | static int set_prescale_div(unsigned long rqst_prescaler, u16 *prescale_div, |
| 151 | u16 *tb_clk_div) |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 152 | { |
| 153 | unsigned int clkdiv, hspclkdiv; |
| 154 | |
| 155 | for (clkdiv = 0; clkdiv <= CLKDIV_MAX; clkdiv++) { |
| 156 | for (hspclkdiv = 0; hspclkdiv <= HSPCLKDIV_MAX; hspclkdiv++) { |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 157 | /* |
| 158 | * calculations for prescaler value : |
| 159 | * prescale_div = HSPCLKDIVIDER * CLKDIVIDER. |
| 160 | * HSPCLKDIVIDER = 2 ** hspclkdiv |
| 161 | * CLKDIVIDER = (1), if clkdiv == 0 *OR* |
| 162 | * (2 * clkdiv), if clkdiv != 0 |
| 163 | * |
| 164 | * Configure prescale_div value such that period |
| 165 | * register value is less than 65535. |
| 166 | */ |
| 167 | |
| 168 | *prescale_div = (1 << clkdiv) * |
| 169 | (hspclkdiv ? (hspclkdiv * 2) : 1); |
| 170 | if (*prescale_div > rqst_prescaler) { |
| 171 | *tb_clk_div = (clkdiv << TBCTL_CLKDIV_SHIFT) | |
| 172 | (hspclkdiv << TBCTL_HSPCLKDIV_SHIFT); |
| 173 | return 0; |
| 174 | } |
| 175 | } |
| 176 | } |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 177 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 178 | return 1; |
| 179 | } |
| 180 | |
Philip, Avinash | daa5629 | 2012-09-06 10:40:03 +0530 | [diff] [blame] | 181 | static void configure_polarity(struct ehrpwm_pwm_chip *pc, int chan) |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 182 | { |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 183 | u16 aqctl_val, aqctl_mask; |
| 184 | unsigned int aqctl_reg; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 185 | |
| 186 | /* |
Philip, Avinash | daa5629 | 2012-09-06 10:40:03 +0530 | [diff] [blame] | 187 | * Configure PWM output to HIGH/LOW level on counter |
| 188 | * reaches compare register value and LOW/HIGH level |
| 189 | * on counter value reaches period register value and |
| 190 | * zero value on counter |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 191 | */ |
| 192 | if (chan == 1) { |
| 193 | aqctl_reg = AQCTLB; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 194 | aqctl_mask = AQCTL_CBU_MASK; |
Philip, Avinash | daa5629 | 2012-09-06 10:40:03 +0530 | [diff] [blame] | 195 | |
| 196 | if (pc->polarity[chan] == PWM_POLARITY_INVERSED) |
| 197 | aqctl_val = AQCTL_CHANB_POLINVERSED; |
| 198 | else |
| 199 | aqctl_val = AQCTL_CHANB_POLNORMAL; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 200 | } else { |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 201 | aqctl_reg = AQCTLA; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 202 | aqctl_mask = AQCTL_CAU_MASK; |
Philip, Avinash | daa5629 | 2012-09-06 10:40:03 +0530 | [diff] [blame] | 203 | |
| 204 | if (pc->polarity[chan] == PWM_POLARITY_INVERSED) |
| 205 | aqctl_val = AQCTL_CHANA_POLINVERSED; |
| 206 | else |
| 207 | aqctl_val = AQCTL_CHANA_POLNORMAL; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 208 | } |
| 209 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 210 | aqctl_mask |= AQCTL_PRD_MASK | AQCTL_ZRO_MASK; |
Philip, Avinash | daa5629 | 2012-09-06 10:40:03 +0530 | [diff] [blame] | 211 | ehrpwm_modify(pc->mmio_base, aqctl_reg, aqctl_mask, aqctl_val); |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /* |
| 215 | * period_ns = 10^9 * (ps_divval * period_cycles) / PWM_CLK_RATE |
| 216 | * duty_ns = 10^9 * (ps_divval * duty_cycles) / PWM_CLK_RATE |
| 217 | */ |
| 218 | static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 219 | int duty_ns, int period_ns) |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 220 | { |
| 221 | struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip); |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 222 | u32 period_cycles, duty_cycles; |
| 223 | u16 ps_divval, tb_divval; |
| 224 | unsigned int i, cmp_reg; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 225 | unsigned long long c; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 226 | |
Thierry Reding | c2d476a | 2012-09-02 22:13:40 +0200 | [diff] [blame] | 227 | if (period_ns > NSEC_PER_SEC) |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 228 | return -ERANGE; |
| 229 | |
| 230 | c = pc->clk_rate; |
| 231 | c = c * period_ns; |
| 232 | do_div(c, NSEC_PER_SEC); |
| 233 | period_cycles = (unsigned long)c; |
| 234 | |
| 235 | if (period_cycles < 1) { |
| 236 | period_cycles = 1; |
| 237 | duty_cycles = 1; |
| 238 | } else { |
| 239 | c = pc->clk_rate; |
| 240 | c = c * duty_ns; |
| 241 | do_div(c, NSEC_PER_SEC); |
| 242 | duty_cycles = (unsigned long)c; |
| 243 | } |
| 244 | |
Philip, Avinash | 01b2d45 | 2012-09-06 10:44:25 +0530 | [diff] [blame] | 245 | /* |
| 246 | * Period values should be same for multiple PWM channels as IP uses |
| 247 | * same period register for multiple channels. |
| 248 | */ |
| 249 | for (i = 0; i < NUM_PWM_CHANNEL; i++) { |
| 250 | if (pc->period_cycles[i] && |
| 251 | (pc->period_cycles[i] != period_cycles)) { |
| 252 | /* |
| 253 | * Allow channel to reconfigure period if no other |
| 254 | * channels being configured. |
| 255 | */ |
| 256 | if (i == pwm->hwpwm) |
| 257 | continue; |
| 258 | |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 259 | dev_err(chip->dev, |
| 260 | "period value conflicts with channel %u\n", |
| 261 | i); |
Philip, Avinash | 01b2d45 | 2012-09-06 10:44:25 +0530 | [diff] [blame] | 262 | return -EINVAL; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | pc->period_cycles[pwm->hwpwm] = period_cycles; |
| 267 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 268 | /* Configure clock prescaler to support Low frequency PWM wave */ |
| 269 | if (set_prescale_div(period_cycles/PERIOD_MAX, &ps_divval, |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 270 | &tb_divval)) { |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 271 | dev_err(chip->dev, "Unsupported values\n"); |
| 272 | return -EINVAL; |
| 273 | } |
| 274 | |
| 275 | pm_runtime_get_sync(chip->dev); |
| 276 | |
| 277 | /* Update clock prescaler values */ |
| 278 | ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_CLKDIV_MASK, tb_divval); |
| 279 | |
| 280 | /* Update period & duty cycle with presacler division */ |
| 281 | period_cycles = period_cycles / ps_divval; |
| 282 | duty_cycles = duty_cycles / ps_divval; |
| 283 | |
| 284 | /* Configure shadow loading on Period register */ |
| 285 | ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_PRDLD_MASK, TBCTL_PRDLD_SHDW); |
| 286 | |
| 287 | ehrpwm_write(pc->mmio_base, TBPRD, period_cycles); |
| 288 | |
| 289 | /* Configure ehrpwm counter for up-count mode */ |
| 290 | ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_CTRMODE_MASK, |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 291 | TBCTL_CTRMODE_UP); |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 292 | |
Philip, Avinash | daa5629 | 2012-09-06 10:40:03 +0530 | [diff] [blame] | 293 | if (pwm->hwpwm == 1) |
| 294 | /* Channel 1 configured with compare B register */ |
| 295 | cmp_reg = CMPB; |
| 296 | else |
| 297 | /* Channel 0 configured with compare A register */ |
| 298 | cmp_reg = CMPA; |
| 299 | |
| 300 | ehrpwm_write(pc->mmio_base, cmp_reg, duty_cycles); |
| 301 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 302 | pm_runtime_put_sync(chip->dev); |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 303 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 304 | return 0; |
| 305 | } |
| 306 | |
Philip, Avinash | daa5629 | 2012-09-06 10:40:03 +0530 | [diff] [blame] | 307 | static int ehrpwm_pwm_set_polarity(struct pwm_chip *chip, |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 308 | struct pwm_device *pwm, |
| 309 | enum pwm_polarity polarity) |
Philip, Avinash | daa5629 | 2012-09-06 10:40:03 +0530 | [diff] [blame] | 310 | { |
| 311 | struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip); |
| 312 | |
| 313 | /* Configuration of polarity in hardware delayed, do at enable */ |
| 314 | pc->polarity[pwm->hwpwm] = polarity; |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 315 | |
Philip, Avinash | daa5629 | 2012-09-06 10:40:03 +0530 | [diff] [blame] | 316 | return 0; |
| 317 | } |
| 318 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 319 | static int ehrpwm_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) |
| 320 | { |
| 321 | struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip); |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 322 | u16 aqcsfrc_val, aqcsfrc_mask; |
Philip, Avinash | 0074b49 | 2013-01-10 18:35:26 +0530 | [diff] [blame] | 323 | int ret; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 324 | |
| 325 | /* Leave clock enabled on enabling PWM */ |
| 326 | pm_runtime_get_sync(chip->dev); |
| 327 | |
| 328 | /* Disabling Action Qualifier on PWM output */ |
| 329 | if (pwm->hwpwm) { |
| 330 | aqcsfrc_val = AQCSFRC_CSFB_FRCDIS; |
| 331 | aqcsfrc_mask = AQCSFRC_CSFB_MASK; |
| 332 | } else { |
| 333 | aqcsfrc_val = AQCSFRC_CSFA_FRCDIS; |
| 334 | aqcsfrc_mask = AQCSFRC_CSFA_MASK; |
| 335 | } |
| 336 | |
| 337 | /* Changes to shadow mode */ |
| 338 | ehrpwm_modify(pc->mmio_base, AQSFRC, AQSFRC_RLDCSF_MASK, |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 339 | AQSFRC_RLDCSF_ZRO); |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 340 | |
| 341 | ehrpwm_modify(pc->mmio_base, AQCSFRC, aqcsfrc_mask, aqcsfrc_val); |
| 342 | |
Philip, Avinash | daa5629 | 2012-09-06 10:40:03 +0530 | [diff] [blame] | 343 | /* Channels polarity can be configured from action qualifier module */ |
| 344 | configure_polarity(pc, pwm->hwpwm); |
| 345 | |
Vignesh R | aa49d62 | 2018-06-11 11:39:55 +0530 | [diff] [blame] | 346 | /* Enable TBCLK */ |
Marek Belisko | b388f15 | 2013-06-26 14:38:04 +0200 | [diff] [blame] | 347 | ret = clk_enable(pc->tbclk); |
Philip, Avinash | 0074b49 | 2013-01-10 18:35:26 +0530 | [diff] [blame] | 348 | if (ret) { |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 349 | dev_err(chip->dev, "Failed to enable TBCLK for %s: %d\n", |
| 350 | dev_name(pc->chip.dev), ret); |
Philip, Avinash | 0074b49 | 2013-01-10 18:35:26 +0530 | [diff] [blame] | 351 | return ret; |
| 352 | } |
Philip, Avinash | d91861d | 2012-11-27 14:18:12 +0530 | [diff] [blame] | 353 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | static void ehrpwm_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) |
| 358 | { |
| 359 | struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip); |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 360 | u16 aqcsfrc_val, aqcsfrc_mask; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 361 | |
| 362 | /* Action Qualifier puts PWM output low forcefully */ |
| 363 | if (pwm->hwpwm) { |
| 364 | aqcsfrc_val = AQCSFRC_CSFB_FRCLOW; |
| 365 | aqcsfrc_mask = AQCSFRC_CSFB_MASK; |
| 366 | } else { |
| 367 | aqcsfrc_val = AQCSFRC_CSFA_FRCLOW; |
| 368 | aqcsfrc_mask = AQCSFRC_CSFA_MASK; |
| 369 | } |
| 370 | |
Vignesh R | 38dabd9 | 2018-06-11 11:39:56 +0530 | [diff] [blame] | 371 | /* Update shadow register first before modifying active register */ |
Christoph Vogtländer | b00ef53 | 2019-03-12 14:38:46 +0530 | [diff] [blame] | 372 | ehrpwm_modify(pc->mmio_base, AQSFRC, AQSFRC_RLDCSF_MASK, |
| 373 | AQSFRC_RLDCSF_ZRO); |
Vignesh R | 38dabd9 | 2018-06-11 11:39:56 +0530 | [diff] [blame] | 374 | ehrpwm_modify(pc->mmio_base, AQCSFRC, aqcsfrc_mask, aqcsfrc_val); |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 375 | /* |
| 376 | * Changes to immediate action on Action Qualifier. This puts |
| 377 | * Action Qualifier control on PWM output from next TBCLK |
| 378 | */ |
| 379 | ehrpwm_modify(pc->mmio_base, AQSFRC, AQSFRC_RLDCSF_MASK, |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 380 | AQSFRC_RLDCSF_IMDT); |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 381 | |
| 382 | ehrpwm_modify(pc->mmio_base, AQCSFRC, aqcsfrc_mask, aqcsfrc_val); |
| 383 | |
Philip, Avinash | d91861d | 2012-11-27 14:18:12 +0530 | [diff] [blame] | 384 | /* Disabling TBCLK on PWM disable */ |
Marek Belisko | b388f15 | 2013-06-26 14:38:04 +0200 | [diff] [blame] | 385 | clk_disable(pc->tbclk); |
Philip, Avinash | d91861d | 2012-11-27 14:18:12 +0530 | [diff] [blame] | 386 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 387 | /* Disable clock on PWM disable */ |
| 388 | pm_runtime_put_sync(chip->dev); |
| 389 | } |
| 390 | |
| 391 | static void ehrpwm_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) |
| 392 | { |
Philip, Avinash | 01b2d45 | 2012-09-06 10:44:25 +0530 | [diff] [blame] | 393 | struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip); |
| 394 | |
Boris Brezillon | 5c31252 | 2015-07-01 10:21:47 +0200 | [diff] [blame] | 395 | if (pwm_is_enabled(pwm)) { |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 396 | dev_warn(chip->dev, "Removing PWM device without disabling\n"); |
| 397 | pm_runtime_put_sync(chip->dev); |
| 398 | } |
Philip, Avinash | 01b2d45 | 2012-09-06 10:44:25 +0530 | [diff] [blame] | 399 | |
| 400 | /* set period value to zero on free */ |
| 401 | pc->period_cycles[pwm->hwpwm] = 0; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static const struct pwm_ops ehrpwm_pwm_ops = { |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 405 | .free = ehrpwm_pwm_free, |
| 406 | .config = ehrpwm_pwm_config, |
| 407 | .set_polarity = ehrpwm_pwm_set_polarity, |
| 408 | .enable = ehrpwm_pwm_enable, |
| 409 | .disable = ehrpwm_pwm_disable, |
| 410 | .owner = THIS_MODULE, |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 411 | }; |
| 412 | |
Philip, Avinash | 53ad9e8d | 2012-11-27 14:18:13 +0530 | [diff] [blame] | 413 | static const struct of_device_id ehrpwm_of_match[] = { |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 414 | { .compatible = "ti,am3352-ehrpwm" }, |
| 415 | { .compatible = "ti,am33xx-ehrpwm" }, |
Philip, Avinash | 53ad9e8d | 2012-11-27 14:18:13 +0530 | [diff] [blame] | 416 | {}, |
| 417 | }; |
| 418 | MODULE_DEVICE_TABLE(of, ehrpwm_of_match); |
| 419 | |
Bill Pemberton | 3e9fe83 | 2012-11-19 13:23:14 -0500 | [diff] [blame] | 420 | static int ehrpwm_pwm_probe(struct platform_device *pdev) |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 421 | { |
Cooper Jr., Franklin | ae5200d | 2016-05-03 10:56:52 -0500 | [diff] [blame] | 422 | struct device_node *np = pdev->dev.of_node; |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 423 | struct ehrpwm_pwm_chip *pc; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 424 | struct clk *clk; |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 425 | int ret; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 426 | |
| 427 | pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); |
Jingoo Han | 5e34895 | 2014-04-23 18:41:48 +0900 | [diff] [blame] | 428 | if (!pc) |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 429 | return -ENOMEM; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 430 | |
| 431 | clk = devm_clk_get(&pdev->dev, "fck"); |
| 432 | if (IS_ERR(clk)) { |
Cooper Jr., Franklin | ae5200d | 2016-05-03 10:56:52 -0500 | [diff] [blame] | 433 | if (of_device_is_compatible(np, "ti,am33xx-ecap")) { |
| 434 | dev_warn(&pdev->dev, "Binding is obsolete.\n"); |
| 435 | clk = devm_clk_get(pdev->dev.parent, "fck"); |
| 436 | } |
| 437 | } |
| 438 | |
Grygorii Strashko | 44db536 | 2020-10-30 22:12:54 +0200 | [diff] [blame] | 439 | if (IS_ERR(clk)) |
| 440 | return dev_err_probe(&pdev->dev, PTR_ERR(clk), "Failed to get fck\n"); |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 441 | |
| 442 | pc->clk_rate = clk_get_rate(clk); |
| 443 | if (!pc->clk_rate) { |
| 444 | dev_err(&pdev->dev, "failed to get clock rate\n"); |
| 445 | return -EINVAL; |
| 446 | } |
| 447 | |
| 448 | pc->chip.dev = &pdev->dev; |
| 449 | pc->chip.ops = &ehrpwm_pwm_ops; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 450 | pc->chip.npwm = NUM_PWM_CHANNEL; |
| 451 | |
Yangtao Li | dc13c0f | 2019-12-29 08:05:56 +0000 | [diff] [blame] | 452 | pc->mmio_base = devm_platform_ioremap_resource(pdev, 0); |
Thierry Reding | 6d4294d | 2013-01-21 11:09:16 +0100 | [diff] [blame] | 453 | if (IS_ERR(pc->mmio_base)) |
| 454 | return PTR_ERR(pc->mmio_base); |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 455 | |
Philip, Avinash | d91861d | 2012-11-27 14:18:12 +0530 | [diff] [blame] | 456 | /* Acquire tbclk for Time Base EHRPWM submodule */ |
| 457 | pc->tbclk = devm_clk_get(&pdev->dev, "tbclk"); |
Grygorii Strashko | 44db536 | 2020-10-30 22:12:54 +0200 | [diff] [blame] | 458 | if (IS_ERR(pc->tbclk)) |
| 459 | return dev_err_probe(&pdev->dev, PTR_ERR(pc->tbclk), "Failed to get tbclk\n"); |
Philip, Avinash | d91861d | 2012-11-27 14:18:12 +0530 | [diff] [blame] | 460 | |
Marek Belisko | b388f15 | 2013-06-26 14:38:04 +0200 | [diff] [blame] | 461 | ret = clk_prepare(pc->tbclk); |
| 462 | if (ret < 0) { |
| 463 | dev_err(&pdev->dev, "clk_prepare() failed: %d\n", ret); |
| 464 | return ret; |
| 465 | } |
| 466 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 467 | ret = pwmchip_add(&pc->chip); |
| 468 | if (ret < 0) { |
| 469 | dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); |
Johan Hovold | e2b5602 | 2017-07-20 12:48:17 +0200 | [diff] [blame] | 470 | goto err_clk_unprepare; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 471 | } |
| 472 | |
Thierry Reding | d870c80 | 2017-08-21 08:42:56 +0200 | [diff] [blame] | 473 | platform_set_drvdata(pdev, pc); |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 474 | pm_runtime_enable(&pdev->dev); |
Philip, Avinash | 53ad9e8d | 2012-11-27 14:18:13 +0530 | [diff] [blame] | 475 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 476 | return 0; |
Johan Hovold | e2b5602 | 2017-07-20 12:48:17 +0200 | [diff] [blame] | 477 | |
| 478 | err_clk_unprepare: |
| 479 | clk_unprepare(pc->tbclk); |
| 480 | |
| 481 | return ret; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 482 | } |
| 483 | |
Bill Pemberton | 77f3791 | 2012-11-19 13:26:09 -0500 | [diff] [blame] | 484 | static int ehrpwm_pwm_remove(struct platform_device *pdev) |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 485 | { |
| 486 | struct ehrpwm_pwm_chip *pc = platform_get_drvdata(pdev); |
| 487 | |
Marek Belisko | b388f15 | 2013-06-26 14:38:04 +0200 | [diff] [blame] | 488 | clk_unprepare(pc->tbclk); |
| 489 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 490 | pm_runtime_disable(&pdev->dev); |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 491 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 492 | return pwmchip_remove(&pc->chip); |
| 493 | } |
| 494 | |
Wolfram Sang | af5935e | 2014-04-02 13:56:21 +0200 | [diff] [blame] | 495 | #ifdef CONFIG_PM_SLEEP |
Axel Lin | b343a18 | 2013-03-26 22:55:57 +0800 | [diff] [blame] | 496 | static void ehrpwm_pwm_save_context(struct ehrpwm_pwm_chip *pc) |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 497 | { |
| 498 | pm_runtime_get_sync(pc->chip.dev); |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 499 | |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 500 | pc->ctx.tbctl = ehrpwm_read(pc->mmio_base, TBCTL); |
| 501 | pc->ctx.tbprd = ehrpwm_read(pc->mmio_base, TBPRD); |
| 502 | pc->ctx.cmpa = ehrpwm_read(pc->mmio_base, CMPA); |
| 503 | pc->ctx.cmpb = ehrpwm_read(pc->mmio_base, CMPB); |
| 504 | pc->ctx.aqctla = ehrpwm_read(pc->mmio_base, AQCTLA); |
| 505 | pc->ctx.aqctlb = ehrpwm_read(pc->mmio_base, AQCTLB); |
| 506 | pc->ctx.aqsfrc = ehrpwm_read(pc->mmio_base, AQSFRC); |
| 507 | pc->ctx.aqcsfrc = ehrpwm_read(pc->mmio_base, AQCSFRC); |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 508 | |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 509 | pm_runtime_put_sync(pc->chip.dev); |
| 510 | } |
| 511 | |
Axel Lin | b343a18 | 2013-03-26 22:55:57 +0800 | [diff] [blame] | 512 | static void ehrpwm_pwm_restore_context(struct ehrpwm_pwm_chip *pc) |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 513 | { |
| 514 | ehrpwm_write(pc->mmio_base, TBPRD, pc->ctx.tbprd); |
| 515 | ehrpwm_write(pc->mmio_base, CMPA, pc->ctx.cmpa); |
| 516 | ehrpwm_write(pc->mmio_base, CMPB, pc->ctx.cmpb); |
| 517 | ehrpwm_write(pc->mmio_base, AQCTLA, pc->ctx.aqctla); |
| 518 | ehrpwm_write(pc->mmio_base, AQCTLB, pc->ctx.aqctlb); |
| 519 | ehrpwm_write(pc->mmio_base, AQSFRC, pc->ctx.aqsfrc); |
| 520 | ehrpwm_write(pc->mmio_base, AQCSFRC, pc->ctx.aqcsfrc); |
| 521 | ehrpwm_write(pc->mmio_base, TBCTL, pc->ctx.tbctl); |
| 522 | } |
| 523 | |
| 524 | static int ehrpwm_pwm_suspend(struct device *dev) |
| 525 | { |
| 526 | struct ehrpwm_pwm_chip *pc = dev_get_drvdata(dev); |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 527 | unsigned int i; |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 528 | |
| 529 | ehrpwm_pwm_save_context(pc); |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 530 | |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 531 | for (i = 0; i < pc->chip.npwm; i++) { |
| 532 | struct pwm_device *pwm = &pc->chip.pwms[i]; |
| 533 | |
Boris Brezillon | 5c31252 | 2015-07-01 10:21:47 +0200 | [diff] [blame] | 534 | if (!pwm_is_enabled(pwm)) |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 535 | continue; |
| 536 | |
| 537 | /* Disable explicitly if PWM is running */ |
| 538 | pm_runtime_put_sync(dev); |
| 539 | } |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 540 | |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | static int ehrpwm_pwm_resume(struct device *dev) |
| 545 | { |
| 546 | struct ehrpwm_pwm_chip *pc = dev_get_drvdata(dev); |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 547 | unsigned int i; |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 548 | |
| 549 | for (i = 0; i < pc->chip.npwm; i++) { |
| 550 | struct pwm_device *pwm = &pc->chip.pwms[i]; |
| 551 | |
Boris Brezillon | 5c31252 | 2015-07-01 10:21:47 +0200 | [diff] [blame] | 552 | if (!pwm_is_enabled(pwm)) |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 553 | continue; |
| 554 | |
| 555 | /* Enable explicitly if PWM was running */ |
| 556 | pm_runtime_get_sync(dev); |
| 557 | } |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 558 | |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 559 | ehrpwm_pwm_restore_context(pc); |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 560 | |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 561 | return 0; |
| 562 | } |
Jingoo Han | 29258b2 | 2013-03-11 11:14:41 +0900 | [diff] [blame] | 563 | #endif |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 564 | |
| 565 | static SIMPLE_DEV_PM_OPS(ehrpwm_pwm_pm_ops, ehrpwm_pwm_suspend, |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 566 | ehrpwm_pwm_resume); |
Philip Avinash | 0e2feb1 | 2013-01-17 14:50:02 +0530 | [diff] [blame] | 567 | |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 568 | static struct platform_driver ehrpwm_pwm_driver = { |
| 569 | .driver = { |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 570 | .name = "ehrpwm", |
Philip, Avinash | 53ad9e8d | 2012-11-27 14:18:13 +0530 | [diff] [blame] | 571 | .of_match_table = ehrpwm_of_match, |
Thierry Reding | d2c95e4 | 2017-08-21 08:42:25 +0200 | [diff] [blame] | 572 | .pm = &ehrpwm_pwm_pm_ops, |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 573 | }, |
| 574 | .probe = ehrpwm_pwm_probe, |
Bill Pemberton | fd10911 | 2012-11-19 13:21:28 -0500 | [diff] [blame] | 575 | .remove = ehrpwm_pwm_remove, |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 576 | }; |
Philip, Avinash | 19891b2 | 2012-07-25 16:58:19 +0530 | [diff] [blame] | 577 | module_platform_driver(ehrpwm_pwm_driver); |
| 578 | |
| 579 | MODULE_DESCRIPTION("EHRPWM PWM driver"); |
| 580 | MODULE_AUTHOR("Texas Instruments"); |
| 581 | MODULE_LICENSE("GPL"); |