Lines Matching +full:visconti +full:- +full:pwm

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Toshiba Visconti pulse-width-modulation controller driver
5 * Copyright (c) 2020 - 2021 TOSHIBA CORPORATION
6 * Copyright (c) 2020 - 2021 Toshiba Electronic Devices & Storage Corporation
11 * - The fixed input clock is running at 1 MHz and is divided by either 1,
13 * - When the settings of the PWM are modified, the new values are shadowed
17 * - Disabling the hardware completes the currently running period and keeps
26 #include <linux/pwm.h>
45 static int visconti_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in visconti_pwm_apply() argument
51 if (!state->enabled) { in visconti_pwm_apply()
52 writel(0, priv->base + PIPGM_PCSR(pwm->hwpwm)); in visconti_pwm_apply()
62 if (state->period > (0xffff << 3) * 1000) in visconti_pwm_apply()
65 period = state->period; in visconti_pwm_apply()
67 if (state->duty_cycle > period) in visconti_pwm_apply()
70 duty_cycle = state->duty_cycle; in visconti_pwm_apply()
81 return -ERANGE; in visconti_pwm_apply()
91 return -EINVAL; in visconti_pwm_apply()
96 if (state->polarity == PWM_POLARITY_INVERSED) in visconti_pwm_apply()
98 writel(pwmc0, priv->base + PIPGM_PWMC(pwm->hwpwm)); in visconti_pwm_apply()
99 writel(duty_cycle, priv->base + PIPGM_PDUT(pwm->hwpwm)); in visconti_pwm_apply()
100 writel(period, priv->base + PIPGM_PCSR(pwm->hwpwm)); in visconti_pwm_apply()
105 static int visconti_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, in visconti_pwm_get_state() argument
111 period = readl(priv->base + PIPGM_PCSR(pwm->hwpwm)); in visconti_pwm_get_state()
112 duty = readl(priv->base + PIPGM_PDUT(pwm->hwpwm)); in visconti_pwm_get_state()
113 pwmc0 = readl(priv->base + PIPGM_PWMC(pwm->hwpwm)); in visconti_pwm_get_state()
116 state->period = (period << pwmc0_clk) * NSEC_PER_USEC; in visconti_pwm_get_state()
117 state->duty_cycle = (duty << pwmc0_clk) * NSEC_PER_USEC; in visconti_pwm_get_state()
119 state->polarity = PWM_POLARITY_INVERSED; in visconti_pwm_get_state()
121 state->polarity = PWM_POLARITY_NORMAL; in visconti_pwm_get_state()
123 state->enabled = true; in visconti_pwm_get_state()
135 struct device *dev = &pdev->dev; in visconti_pwm_probe()
145 priv->base = devm_platform_ioremap_resource(pdev, 0); in visconti_pwm_probe()
146 if (IS_ERR(priv->base)) in visconti_pwm_probe()
147 return PTR_ERR(priv->base); in visconti_pwm_probe()
149 chip->ops = &visconti_pwm_ops; in visconti_pwm_probe()
151 ret = devm_pwmchip_add(&pdev->dev, chip); in visconti_pwm_probe()
153 return dev_err_probe(&pdev->dev, ret, "Cannot register visconti PWM\n"); in visconti_pwm_probe()
159 { .compatible = "toshiba,visconti-pwm", },
166 .name = "pwm-visconti",
173 MODULE_DESCRIPTION("Toshiba Visconti Pulse Width Modulator driver");
176 MODULE_ALIAS("platform:pwm-visconti");