summaryrefslogtreecommitdiffstats
path: root/drivers/pwm/pwm-mxs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pwm/pwm-mxs.c')
-rw-r--r--drivers/pwm/pwm-mxs.c58
1 files changed, 22 insertions, 36 deletions
diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c
index e72f1dbcb0..6b89ac192a 100644
--- a/drivers/pwm/pwm-mxs.c
+++ b/drivers/pwm/pwm-mxs.c
@@ -1,13 +1,5 @@
-/*
- * Copyright 2012 Freescale Semiconductor, Inc.
- *
- * The code contained herein is licensed under the GNU General Public
- * License. You may obtain a copy of the GNU General Public License
- * Version 2 or later at the following locations:
- *
- * http://www.opensource.org/licenses/gpl-license.html
- * http://www.gnu.org/copyleft/gpl.html
- */
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: 2012 Freescale Semiconductor, Inc.
#include <common.h>
#include <init.h>
@@ -17,7 +9,7 @@
#include <stmp-device.h>
#include <linux/clk.h>
#include <linux/err.h>
-#include <asm-generic/div64.h>
+#include <linux/math64.h>
#define SET 0x4
#define CLR 0x8
@@ -52,18 +44,26 @@ struct mxs_pwm {
#define to_mxs_pwm_chip(_chip) container_of(_chip, struct mxs_pwm_chip, chip)
-static int mxs_pwm_config(struct pwm_chip *chip, int duty_ns, int period_ns)
+static int mxs_pwm_apply(struct pwm_chip *chip, const struct pwm_state *state)
{
struct mxs_pwm_chip *mxs = to_mxs_pwm_chip(chip);
int div = 0;
unsigned int period_cycles, duty_cycles;
unsigned long rate;
unsigned long long c;
+ bool enabled;
+
+ enabled = chip->state.p_enable;
+
+ if (enabled && !state->p_enable) {
+ writel(1 << mxs->chip.id, mxs->mxs->base + PWM_CTRL + CLR);
+ return 0;
+ }
rate = clk_get_rate(mxs->mxs->clk);
while (1) {
c = rate / cdiv[div];
- c = c * period_ns;
+ c = c * state->period_ns;
do_div(c, 1000000000);
if (c < PERIOD_PERIOD_MAX)
break;
@@ -73,8 +73,8 @@ static int mxs_pwm_config(struct pwm_chip *chip, int duty_ns, int period_ns)
}
period_cycles = c;
- c *= duty_ns;
- do_div(c, period_ns);
+ c *= state->duty_ns;
+ do_div(c, state->period_ns);
duty_cycles = c;
writel(duty_cycles << 16,
@@ -83,35 +83,20 @@ static int mxs_pwm_config(struct pwm_chip *chip, int duty_ns, int period_ns)
PERIOD_INACTIVE_LOW | PERIOD_CDIV(div),
mxs->mxs->base + PWM_PERIOD0 + mxs->chip.id * 0x20);
- return 0;
-}
-
-static int mxs_pwm_enable(struct pwm_chip *chip)
-{
- struct mxs_pwm_chip *mxs = to_mxs_pwm_chip(chip);
-
- writel(1 << mxs->chip.id, mxs->mxs->base + PWM_CTRL + SET);
+ if (!enabled && state->p_enable)
+ writel(1 << mxs->chip.id, mxs->mxs->base + PWM_CTRL + SET);
return 0;
}
-static void mxs_pwm_disable(struct pwm_chip *chip)
-{
- struct mxs_pwm_chip *mxs = to_mxs_pwm_chip(chip);
-
- writel(1 << mxs->chip.id, mxs->mxs->base + PWM_CTRL + CLR);
-}
-
static struct pwm_ops mxs_pwm_ops = {
- .config = mxs_pwm_config,
- .enable = mxs_pwm_enable,
- .disable = mxs_pwm_disable,
+ .apply = mxs_pwm_apply,
};
-static int mxs_pwm_probe(struct device_d *dev)
+static int mxs_pwm_probe(struct device *dev)
{
struct resource *iores;
- struct device_node *np = dev->device_node;
+ struct device_node *np = dev->of_node;
struct mxs_pwm *mxs;
int ret, i;
uint32_t npwm;
@@ -161,8 +146,9 @@ static const struct of_device_id mxs_pwm_dt_ids[] = {
{ .compatible = "fsl,imx23-pwm", },
{ /* sentinel */ }
};
+MODULE_DEVICE_TABLE(of, mxs_pwm_dt_ids);
-static struct driver_d mxs_pwm_driver = {
+static struct driver mxs_pwm_driver = {
.name = "mxs-pwm",
.of_compatible = mxs_pwm_dt_ids,
.probe = mxs_pwm_probe,