Fabio Estevam | a99290c | 2018-07-06 19:47:17 -0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 2 | /* |
| 3 | * simple driver for PWM (Pulse Width Modulator) controller |
| 4 | * |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 5 | * Derived from pxa PWM driver by eric miao <eric.miao@marvell.com> |
| 6 | */ |
| 7 | |
Michal Vokáč | 9f617ad | 2018-10-01 16:19:47 +0200 | [diff] [blame^] | 8 | #include <linux/bitfield.h> |
| 9 | #include <linux/bitops.h> |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 10 | #include <linux/clk.h> |
Liu Ying | 137fd45 | 2014-05-28 18:50:13 +0800 | [diff] [blame] | 11 | #include <linux/delay.h> |
Michal Vokáč | e3adc7e | 2018-10-01 16:19:46 +0200 | [diff] [blame] | 12 | #include <linux/err.h> |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 13 | #include <linux/io.h> |
Michal Vokáč | e3adc7e | 2018-10-01 16:19:46 +0200 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/module.h> |
Sachin Kamat | 2a8876c | 2013-09-27 16:53:23 +0530 | [diff] [blame] | 16 | #include <linux/of.h> |
Philipp Zabel | 479e2e3 | 2012-06-25 16:16:25 +0200 | [diff] [blame] | 17 | #include <linux/of_device.h> |
Michal Vokáč | e3adc7e | 2018-10-01 16:19:46 +0200 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/pwm.h> |
| 20 | #include <linux/slab.h> |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 21 | |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 22 | /* i.MX1 and i.MX21 share the same PWM function block: */ |
| 23 | |
Liu Ying | 40f260c | 2014-05-28 18:50:12 +0800 | [diff] [blame] | 24 | #define MX1_PWMC 0x00 /* PWM Control Register */ |
| 25 | #define MX1_PWMS 0x04 /* PWM Sample Register */ |
| 26 | #define MX1_PWMP 0x08 /* PWM Period Register */ |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 27 | |
Michal Vokáč | 9f617ad | 2018-10-01 16:19:47 +0200 | [diff] [blame^] | 28 | #define MX1_PWMC_EN BIT(4) |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 29 | |
| 30 | /* i.MX27, i.MX31, i.MX35 share the same PWM function block: */ |
| 31 | |
Liu Ying | 40f260c | 2014-05-28 18:50:12 +0800 | [diff] [blame] | 32 | #define MX3_PWMCR 0x00 /* PWM Control Register */ |
Liu Ying | 137fd45 | 2014-05-28 18:50:13 +0800 | [diff] [blame] | 33 | #define MX3_PWMSR 0x04 /* PWM Status Register */ |
Liu Ying | 40f260c | 2014-05-28 18:50:12 +0800 | [diff] [blame] | 34 | #define MX3_PWMSAR 0x0C /* PWM Sample Register */ |
| 35 | #define MX3_PWMPR 0x10 /* PWM Period Register */ |
Michal Vokáč | 9f617ad | 2018-10-01 16:19:47 +0200 | [diff] [blame^] | 36 | |
| 37 | #define MX3_PWMCR_FWM GENMASK(27, 26) |
| 38 | #define MX3_PWMCR_STOPEN BIT(25) |
| 39 | #define MX3_PWMCR_DOZEN BIT(24) |
| 40 | #define MX3_PWMCR_WAITEN BIT(23) |
| 41 | #define MX3_PWMCR_DBGEN BIT(22) |
| 42 | #define MX3_PWMCR_BCTR BIT(21) |
| 43 | #define MX3_PWMCR_HCTR BIT(20) |
| 44 | |
| 45 | #define MX3_PWMCR_POUTC GENMASK(19, 18) |
| 46 | #define MX3_PWMCR_POUTC_NORMAL 0 |
| 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) |
Liu Ying | 137fd45 | 2014-05-28 18:50:13 +0800 | [diff] [blame] | 83 | |
| 84 | #define MX3_PWM_SWR_LOOP 5 |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 85 | |
| 86 | struct imx_chip { |
Philipp Zabel | 7b27c16 | 2012-06-25 16:15:20 +0200 | [diff] [blame] | 87 | struct clk *clk_per; |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 88 | |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 89 | void __iomem *mmio_base; |
| 90 | |
| 91 | struct pwm_chip chip; |
| 92 | }; |
| 93 | |
| 94 | #define to_imx_chip(chip) container_of(chip, struct imx_chip, chip) |
| 95 | |
Sascha Hauer | 19e7333 | 2012-07-03 17:28:14 +0200 | [diff] [blame] | 96 | static int imx_pwm_config_v1(struct pwm_chip *chip, |
| 97 | struct pwm_device *pwm, int duty_ns, int period_ns) |
| 98 | { |
| 99 | struct imx_chip *imx = to_imx_chip(chip); |
| 100 | |
| 101 | /* |
| 102 | * The PWM subsystem allows for exact frequencies. However, |
| 103 | * I cannot connect a scope on my device to the PWM line and |
| 104 | * thus cannot provide the program the PWM controller |
| 105 | * exactly. Instead, I'm relying on the fact that the |
| 106 | * Bootloader (u-boot or WinCE+haret) has programmed the PWM |
| 107 | * function group already. So I'll just modify the PWM sample |
| 108 | * register to follow the ratio of duty_ns vs. period_ns |
| 109 | * accordingly. |
| 110 | * |
| 111 | * This is good enough for programming the brightness of |
| 112 | * the LCD backlight. |
| 113 | * |
| 114 | * The real implementation would divide PERCLK[0] first by |
| 115 | * both the prescaler (/1 .. /128) and then by CLKSEL |
| 116 | * (/2 .. /16). |
| 117 | */ |
| 118 | u32 max = readl(imx->mmio_base + MX1_PWMP); |
| 119 | u32 p = max * duty_ns / period_ns; |
| 120 | writel(max - p, imx->mmio_base + MX1_PWMS); |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
Lukasz Majewski | b3c088f | 2017-01-29 22:54:08 +0100 | [diff] [blame] | 125 | static int imx_pwm_enable_v1(struct pwm_chip *chip, struct pwm_device *pwm) |
| 126 | { |
| 127 | struct imx_chip *imx = to_imx_chip(chip); |
| 128 | u32 val; |
| 129 | int ret; |
| 130 | |
| 131 | ret = clk_prepare_enable(imx->clk_per); |
| 132 | if (ret < 0) |
| 133 | return ret; |
| 134 | |
| 135 | val = readl(imx->mmio_base + MX1_PWMC); |
| 136 | val |= MX1_PWMC_EN; |
| 137 | writel(val, imx->mmio_base + MX1_PWMC); |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static void imx_pwm_disable_v1(struct pwm_chip *chip, struct pwm_device *pwm) |
Sascha Hauer | 66ad6a6 | 2012-08-28 11:39:25 +0200 | [diff] [blame] | 143 | { |
| 144 | struct imx_chip *imx = to_imx_chip(chip); |
| 145 | u32 val; |
| 146 | |
| 147 | val = readl(imx->mmio_base + MX1_PWMC); |
Lukasz Majewski | b3c088f | 2017-01-29 22:54:08 +0100 | [diff] [blame] | 148 | val &= ~MX1_PWMC_EN; |
Sascha Hauer | 66ad6a6 | 2012-08-28 11:39:25 +0200 | [diff] [blame] | 149 | writel(val, imx->mmio_base + MX1_PWMC); |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 150 | |
Philipp Zabel | 7b27c16 | 2012-06-25 16:15:20 +0200 | [diff] [blame] | 151 | clk_disable_unprepare(imx->clk_per); |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 152 | } |
| 153 | |
Lukasz Majewski | 970247a | 2017-01-29 22:54:09 +0100 | [diff] [blame] | 154 | static void imx_pwm_sw_reset(struct pwm_chip *chip) |
| 155 | { |
| 156 | struct imx_chip *imx = to_imx_chip(chip); |
| 157 | struct device *dev = chip->dev; |
| 158 | int wait_count = 0; |
| 159 | u32 cr; |
| 160 | |
| 161 | writel(MX3_PWMCR_SWR, imx->mmio_base + MX3_PWMCR); |
| 162 | do { |
| 163 | usleep_range(200, 1000); |
| 164 | cr = readl(imx->mmio_base + MX3_PWMCR); |
| 165 | } while ((cr & MX3_PWMCR_SWR) && |
| 166 | (wait_count++ < MX3_PWM_SWR_LOOP)); |
| 167 | |
| 168 | if (cr & MX3_PWMCR_SWR) |
| 169 | dev_warn(dev, "software reset timeout\n"); |
| 170 | } |
| 171 | |
Lukasz Majewski | 73b1ff1 | 2017-01-29 22:54:10 +0100 | [diff] [blame] | 172 | static void imx_pwm_wait_fifo_slot(struct pwm_chip *chip, |
| 173 | struct pwm_device *pwm) |
| 174 | { |
| 175 | struct imx_chip *imx = to_imx_chip(chip); |
| 176 | struct device *dev = chip->dev; |
| 177 | unsigned int period_ms; |
| 178 | int fifoav; |
| 179 | u32 sr; |
| 180 | |
| 181 | sr = readl(imx->mmio_base + MX3_PWMSR); |
Michal Vokáč | 9f617ad | 2018-10-01 16:19:47 +0200 | [diff] [blame^] | 182 | fifoav = FIELD_GET(MX3_PWMSR_FIFOAV, sr); |
Lukasz Majewski | 73b1ff1 | 2017-01-29 22:54:10 +0100 | [diff] [blame] | 183 | if (fifoav == MX3_PWMSR_FIFOAV_4WORDS) { |
| 184 | period_ms = DIV_ROUND_UP(pwm_get_period(pwm), |
| 185 | NSEC_PER_MSEC); |
| 186 | msleep(period_ms); |
| 187 | |
| 188 | sr = readl(imx->mmio_base + MX3_PWMSR); |
Michal Vokáč | 9f617ad | 2018-10-01 16:19:47 +0200 | [diff] [blame^] | 189 | if (fifoav == FIELD_GET(MX3_PWMSR_FIFOAV, sr)) |
Lukasz Majewski | 73b1ff1 | 2017-01-29 22:54:10 +0100 | [diff] [blame] | 190 | dev_warn(dev, "there is no free FIFO slot\n"); |
| 191 | } |
| 192 | } |
Lukasz Majewski | 970247a | 2017-01-29 22:54:09 +0100 | [diff] [blame] | 193 | |
Lukasz Majewski | 0ca1a11 | 2017-01-29 22:54:11 +0100 | [diff] [blame] | 194 | static int imx_pwm_apply_v2(struct pwm_chip *chip, struct pwm_device *pwm, |
| 195 | struct pwm_state *state) |
| 196 | { |
| 197 | unsigned long period_cycles, duty_cycles, prescale; |
| 198 | struct imx_chip *imx = to_imx_chip(chip); |
| 199 | struct pwm_state cstate; |
| 200 | unsigned long long c; |
| 201 | int ret; |
Lukasz Majewski | 326ed31 | 2017-01-29 22:54:15 +0100 | [diff] [blame] | 202 | u32 cr; |
Lukasz Majewski | 0ca1a11 | 2017-01-29 22:54:11 +0100 | [diff] [blame] | 203 | |
| 204 | pwm_get_state(pwm, &cstate); |
| 205 | |
| 206 | if (state->enabled) { |
| 207 | c = clk_get_rate(imx->clk_per); |
| 208 | c *= state->period; |
| 209 | |
| 210 | do_div(c, 1000000000); |
| 211 | period_cycles = c; |
| 212 | |
| 213 | prescale = period_cycles / 0x10000 + 1; |
| 214 | |
| 215 | period_cycles /= prescale; |
| 216 | c = (unsigned long long)period_cycles * state->duty_cycle; |
| 217 | do_div(c, state->period); |
| 218 | duty_cycles = c; |
| 219 | |
| 220 | /* |
| 221 | * according to imx pwm RM, the real period value should be |
| 222 | * PERIOD value in PWMPR plus 2. |
| 223 | */ |
| 224 | if (period_cycles > 2) |
| 225 | period_cycles -= 2; |
| 226 | else |
| 227 | period_cycles = 0; |
| 228 | |
| 229 | /* |
| 230 | * Wait for a free FIFO slot if the PWM is already enabled, and |
| 231 | * flush the FIFO if the PWM was disabled and is about to be |
| 232 | * enabled. |
| 233 | */ |
| 234 | if (cstate.enabled) { |
| 235 | imx_pwm_wait_fifo_slot(chip, pwm); |
| 236 | } else { |
| 237 | ret = clk_prepare_enable(imx->clk_per); |
| 238 | if (ret) |
| 239 | return ret; |
| 240 | |
| 241 | imx_pwm_sw_reset(chip); |
| 242 | } |
| 243 | |
| 244 | writel(duty_cycles, imx->mmio_base + MX3_PWMSAR); |
| 245 | writel(period_cycles, imx->mmio_base + MX3_PWMPR); |
| 246 | |
Michal Vokáč | 9f617ad | 2018-10-01 16:19:47 +0200 | [diff] [blame^] | 247 | cr = MX3_PWMCR_PRESCALER_SET(prescale) | |
| 248 | MX3_PWMCR_STOPEN | MX3_PWMCR_DOZEN | MX3_PWMCR_WAITEN | |
| 249 | FIELD_PREP(MX3_PWMCR_CLKSRC, MX3_PWMCR_CLKSRC_IPG_HIGH) | |
| 250 | MX3_PWMCR_DBGEN | MX3_PWMCR_EN; |
Lukasz Majewski | 326ed31 | 2017-01-29 22:54:15 +0100 | [diff] [blame] | 251 | |
| 252 | if (state->polarity == PWM_POLARITY_INVERSED) |
Michal Vokáč | 9f617ad | 2018-10-01 16:19:47 +0200 | [diff] [blame^] | 253 | cr |= FIELD_PREP(MX3_PWMCR_POUTC, |
| 254 | MX3_PWMCR_POUTC_INVERTED); |
Lukasz Majewski | 326ed31 | 2017-01-29 22:54:15 +0100 | [diff] [blame] | 255 | |
| 256 | writel(cr, imx->mmio_base + MX3_PWMCR); |
Lukasz Majewski | 0ca1a11 | 2017-01-29 22:54:11 +0100 | [diff] [blame] | 257 | } else if (cstate.enabled) { |
| 258 | writel(0, imx->mmio_base + MX3_PWMCR); |
| 259 | |
| 260 | clk_disable_unprepare(imx->clk_per); |
| 261 | } |
| 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | |
Lukasz Majewski | 0038922 | 2017-01-29 22:54:07 +0100 | [diff] [blame] | 266 | static const struct pwm_ops imx_pwm_ops_v1 = { |
Lukasz Majewski | b3c088f | 2017-01-29 22:54:08 +0100 | [diff] [blame] | 267 | .enable = imx_pwm_enable_v1, |
| 268 | .disable = imx_pwm_disable_v1, |
| 269 | .config = imx_pwm_config_v1, |
Lukasz Majewski | 0038922 | 2017-01-29 22:54:07 +0100 | [diff] [blame] | 270 | .owner = THIS_MODULE, |
| 271 | }; |
| 272 | |
| 273 | static const struct pwm_ops imx_pwm_ops_v2 = { |
Lukasz Majewski | 0ca1a11 | 2017-01-29 22:54:11 +0100 | [diff] [blame] | 274 | .apply = imx_pwm_apply_v2, |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 275 | .owner = THIS_MODULE, |
| 276 | }; |
| 277 | |
Philipp Zabel | 479e2e3 | 2012-06-25 16:16:25 +0200 | [diff] [blame] | 278 | struct imx_pwm_data { |
Lukasz Majewski | 326ed31 | 2017-01-29 22:54:15 +0100 | [diff] [blame] | 279 | bool polarity_supported; |
Lukasz Majewski | 0038922 | 2017-01-29 22:54:07 +0100 | [diff] [blame] | 280 | const struct pwm_ops *ops; |
Philipp Zabel | 479e2e3 | 2012-06-25 16:16:25 +0200 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | static struct imx_pwm_data imx_pwm_data_v1 = { |
Lukasz Majewski | 0038922 | 2017-01-29 22:54:07 +0100 | [diff] [blame] | 284 | .ops = &imx_pwm_ops_v1, |
Philipp Zabel | 479e2e3 | 2012-06-25 16:16:25 +0200 | [diff] [blame] | 285 | }; |
| 286 | |
| 287 | static struct imx_pwm_data imx_pwm_data_v2 = { |
Lukasz Majewski | 326ed31 | 2017-01-29 22:54:15 +0100 | [diff] [blame] | 288 | .polarity_supported = true, |
Lukasz Majewski | 0038922 | 2017-01-29 22:54:07 +0100 | [diff] [blame] | 289 | .ops = &imx_pwm_ops_v2, |
Philipp Zabel | 479e2e3 | 2012-06-25 16:16:25 +0200 | [diff] [blame] | 290 | }; |
| 291 | |
| 292 | static const struct of_device_id imx_pwm_dt_ids[] = { |
| 293 | { .compatible = "fsl,imx1-pwm", .data = &imx_pwm_data_v1, }, |
| 294 | { .compatible = "fsl,imx27-pwm", .data = &imx_pwm_data_v2, }, |
| 295 | { /* sentinel */ } |
| 296 | }; |
| 297 | MODULE_DEVICE_TABLE(of, imx_pwm_dt_ids); |
| 298 | |
Bill Pemberton | 3e9fe83 | 2012-11-19 13:23:14 -0500 | [diff] [blame] | 299 | static int imx_pwm_probe(struct platform_device *pdev) |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 300 | { |
Philipp Zabel | 479e2e3 | 2012-06-25 16:16:25 +0200 | [diff] [blame] | 301 | const struct of_device_id *of_id = |
| 302 | of_match_device(imx_pwm_dt_ids, &pdev->dev); |
Lothar Waßmann | 983290b | 2012-12-05 16:34:41 +0100 | [diff] [blame] | 303 | const struct imx_pwm_data *data; |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 304 | struct imx_chip *imx; |
| 305 | struct resource *r; |
| 306 | int ret = 0; |
| 307 | |
Philipp Zabel | 479e2e3 | 2012-06-25 16:16:25 +0200 | [diff] [blame] | 308 | if (!of_id) |
| 309 | return -ENODEV; |
| 310 | |
Lukasz Majewski | 0038922 | 2017-01-29 22:54:07 +0100 | [diff] [blame] | 311 | data = of_id->data; |
| 312 | |
Axel Lin | a9970e3 | 2012-07-01 08:27:23 +0800 | [diff] [blame] | 313 | imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); |
Jingoo Han | 1cbec74 | 2014-04-23 18:39:49 +0900 | [diff] [blame] | 314 | if (imx == NULL) |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 315 | return -ENOMEM; |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 316 | |
Philipp Zabel | 7b27c16 | 2012-06-25 16:15:20 +0200 | [diff] [blame] | 317 | imx->clk_per = devm_clk_get(&pdev->dev, "per"); |
| 318 | if (IS_ERR(imx->clk_per)) { |
| 319 | dev_err(&pdev->dev, "getting per clock failed with %ld\n", |
| 320 | PTR_ERR(imx->clk_per)); |
| 321 | return PTR_ERR(imx->clk_per); |
| 322 | } |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 323 | |
Lukasz Majewski | 0038922 | 2017-01-29 22:54:07 +0100 | [diff] [blame] | 324 | imx->chip.ops = data->ops; |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 325 | imx->chip.dev = &pdev->dev; |
| 326 | imx->chip.base = -1; |
| 327 | imx->chip.npwm = 1; |
| 328 | |
Lukasz Majewski | 326ed31 | 2017-01-29 22:54:15 +0100 | [diff] [blame] | 329 | if (data->polarity_supported) { |
| 330 | dev_dbg(&pdev->dev, "PWM supports output inversion\n"); |
| 331 | imx->chip.of_xlate = of_pwm_xlate_with_flags; |
| 332 | imx->chip.of_pwm_n_cells = 3; |
| 333 | } |
| 334 | |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 335 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | 6d4294d | 2013-01-21 11:09:16 +0100 | [diff] [blame] | 336 | imx->mmio_base = devm_ioremap_resource(&pdev->dev, r); |
| 337 | if (IS_ERR(imx->mmio_base)) |
| 338 | return PTR_ERR(imx->mmio_base); |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 339 | |
| 340 | ret = pwmchip_add(&imx->chip); |
| 341 | if (ret < 0) |
Axel Lin | a9970e3 | 2012-07-01 08:27:23 +0800 | [diff] [blame] | 342 | return ret; |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 343 | |
| 344 | platform_set_drvdata(pdev, imx); |
| 345 | return 0; |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 346 | } |
| 347 | |
Bill Pemberton | 77f3791 | 2012-11-19 13:26:09 -0500 | [diff] [blame] | 348 | static int imx_pwm_remove(struct platform_device *pdev) |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 349 | { |
| 350 | struct imx_chip *imx; |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 351 | |
| 352 | imx = platform_get_drvdata(pdev); |
| 353 | if (imx == NULL) |
| 354 | return -ENODEV; |
| 355 | |
Axel Lin | a9970e3 | 2012-07-01 08:27:23 +0800 | [diff] [blame] | 356 | return pwmchip_remove(&imx->chip); |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | static struct platform_driver imx_pwm_driver = { |
| 360 | .driver = { |
Philipp Zabel | 479e2e3 | 2012-06-25 16:16:25 +0200 | [diff] [blame] | 361 | .name = "imx-pwm", |
Sachin Kamat | becbca13 | 2013-09-30 08:56:41 +0530 | [diff] [blame] | 362 | .of_match_table = imx_pwm_dt_ids, |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 363 | }, |
| 364 | .probe = imx_pwm_probe, |
Bill Pemberton | fd10911 | 2012-11-19 13:21:28 -0500 | [diff] [blame] | 365 | .remove = imx_pwm_remove, |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 366 | }; |
| 367 | |
Sascha Hauer | 208d038 | 2012-08-28 08:27:40 +0200 | [diff] [blame] | 368 | module_platform_driver(imx_pwm_driver); |
Sascha Hauer | 2969324 | 2012-03-15 10:04:35 +0100 | [diff] [blame] | 369 | |
| 370 | MODULE_LICENSE("GPL v2"); |
| 371 | MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); |