18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (C) 2014 Broadcom Corporation 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or 58c2ecf20Sopenharmony_ci * modify it under the terms of the GNU General Public License as 68c2ecf20Sopenharmony_ci * published by the Free Software Foundation version 2. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * This program is distributed "as is" WITHOUT ANY WARRANTY of any 98c2ecf20Sopenharmony_ci * kind, whether express or implied; without even the implied warranty 108c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 118c2ecf20Sopenharmony_ci * GNU General Public License for more details. 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/clk.h> 158c2ecf20Sopenharmony_ci#include <linux/delay.h> 168c2ecf20Sopenharmony_ci#include <linux/err.h> 178c2ecf20Sopenharmony_ci#include <linux/io.h> 188c2ecf20Sopenharmony_ci#include <linux/ioport.h> 198c2ecf20Sopenharmony_ci#include <linux/math64.h> 208c2ecf20Sopenharmony_ci#include <linux/module.h> 218c2ecf20Sopenharmony_ci#include <linux/of.h> 228c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 238c2ecf20Sopenharmony_ci#include <linux/pwm.h> 248c2ecf20Sopenharmony_ci#include <linux/slab.h> 258c2ecf20Sopenharmony_ci#include <linux/types.h> 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* 288c2ecf20Sopenharmony_ci * The Kona PWM has some unusual characteristics. Here are the main points. 298c2ecf20Sopenharmony_ci * 308c2ecf20Sopenharmony_ci * 1) There is no disable bit and the hardware docs advise programming a zero 318c2ecf20Sopenharmony_ci * duty to achieve output equivalent to that of a normal disable operation. 328c2ecf20Sopenharmony_ci * 338c2ecf20Sopenharmony_ci * 2) Changes to prescale, duty, period, and polarity do not take effect until 348c2ecf20Sopenharmony_ci * a subsequent rising edge of the trigger bit. 358c2ecf20Sopenharmony_ci * 368c2ecf20Sopenharmony_ci * 3) If the smooth bit and trigger bit are both low, the output is a constant 378c2ecf20Sopenharmony_ci * high signal. Otherwise, the earlier waveform continues to be output. 388c2ecf20Sopenharmony_ci * 398c2ecf20Sopenharmony_ci * 4) If the smooth bit is set on the rising edge of the trigger bit, output 408c2ecf20Sopenharmony_ci * will transition to the new settings on a period boundary (which could be 418c2ecf20Sopenharmony_ci * seconds away). If the smooth bit is clear, new settings will be applied 428c2ecf20Sopenharmony_ci * as soon as possible (the hardware always has a 400ns delay). 438c2ecf20Sopenharmony_ci * 448c2ecf20Sopenharmony_ci * 5) When the external clock that feeds the PWM is disabled, output is pegged 458c2ecf20Sopenharmony_ci * high or low depending on its state at that exact instant. 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define PWM_CONTROL_OFFSET 0x00000000 498c2ecf20Sopenharmony_ci#define PWM_CONTROL_SMOOTH_SHIFT(chan) (24 + (chan)) 508c2ecf20Sopenharmony_ci#define PWM_CONTROL_TYPE_SHIFT(chan) (16 + (chan)) 518c2ecf20Sopenharmony_ci#define PWM_CONTROL_POLARITY_SHIFT(chan) (8 + (chan)) 528c2ecf20Sopenharmony_ci#define PWM_CONTROL_TRIGGER_SHIFT(chan) (chan) 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define PRESCALE_OFFSET 0x00000004 558c2ecf20Sopenharmony_ci#define PRESCALE_SHIFT(chan) ((chan) << 2) 568c2ecf20Sopenharmony_ci#define PRESCALE_MASK(chan) (0x7 << PRESCALE_SHIFT(chan)) 578c2ecf20Sopenharmony_ci#define PRESCALE_MIN 0x00000000 588c2ecf20Sopenharmony_ci#define PRESCALE_MAX 0x00000007 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#define PERIOD_COUNT_OFFSET(chan) (0x00000008 + ((chan) << 3)) 618c2ecf20Sopenharmony_ci#define PERIOD_COUNT_MIN 0x00000002 628c2ecf20Sopenharmony_ci#define PERIOD_COUNT_MAX 0x00ffffff 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#define DUTY_CYCLE_HIGH_OFFSET(chan) (0x0000000c + ((chan) << 3)) 658c2ecf20Sopenharmony_ci#define DUTY_CYCLE_HIGH_MIN 0x00000000 668c2ecf20Sopenharmony_ci#define DUTY_CYCLE_HIGH_MAX 0x00ffffff 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistruct kona_pwmc { 698c2ecf20Sopenharmony_ci struct pwm_chip chip; 708c2ecf20Sopenharmony_ci void __iomem *base; 718c2ecf20Sopenharmony_ci struct clk *clk; 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistatic inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *_chip) 758c2ecf20Sopenharmony_ci{ 768c2ecf20Sopenharmony_ci return container_of(_chip, struct kona_pwmc, chip); 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci/* 808c2ecf20Sopenharmony_ci * Clear trigger bit but set smooth bit to maintain old output. 818c2ecf20Sopenharmony_ci */ 828c2ecf20Sopenharmony_cistatic void kona_pwmc_prepare_for_settings(struct kona_pwmc *kp, 838c2ecf20Sopenharmony_ci unsigned int chan) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci unsigned int value = readl(kp->base + PWM_CONTROL_OFFSET); 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci value |= 1 << PWM_CONTROL_SMOOTH_SHIFT(chan); 888c2ecf20Sopenharmony_ci value &= ~(1 << PWM_CONTROL_TRIGGER_SHIFT(chan)); 898c2ecf20Sopenharmony_ci writel(value, kp->base + PWM_CONTROL_OFFSET); 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci /* 928c2ecf20Sopenharmony_ci * There must be a min 400ns delay between clearing trigger and setting 938c2ecf20Sopenharmony_ci * it. Failing to do this may result in no PWM signal. 948c2ecf20Sopenharmony_ci */ 958c2ecf20Sopenharmony_ci ndelay(400); 968c2ecf20Sopenharmony_ci} 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistatic void kona_pwmc_apply_settings(struct kona_pwmc *kp, unsigned int chan) 998c2ecf20Sopenharmony_ci{ 1008c2ecf20Sopenharmony_ci unsigned int value = readl(kp->base + PWM_CONTROL_OFFSET); 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci /* Set trigger bit and clear smooth bit to apply new settings */ 1038c2ecf20Sopenharmony_ci value &= ~(1 << PWM_CONTROL_SMOOTH_SHIFT(chan)); 1048c2ecf20Sopenharmony_ci value |= 1 << PWM_CONTROL_TRIGGER_SHIFT(chan); 1058c2ecf20Sopenharmony_ci writel(value, kp->base + PWM_CONTROL_OFFSET); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci /* Trigger bit must be held high for at least 400 ns. */ 1088c2ecf20Sopenharmony_ci ndelay(400); 1098c2ecf20Sopenharmony_ci} 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_cistatic int kona_pwmc_config(struct pwm_chip *chip, struct pwm_device *pwm, 1128c2ecf20Sopenharmony_ci int duty_ns, int period_ns) 1138c2ecf20Sopenharmony_ci{ 1148c2ecf20Sopenharmony_ci struct kona_pwmc *kp = to_kona_pwmc(chip); 1158c2ecf20Sopenharmony_ci u64 val, div, rate; 1168c2ecf20Sopenharmony_ci unsigned long prescale = PRESCALE_MIN, pc, dc; 1178c2ecf20Sopenharmony_ci unsigned int value, chan = pwm->hwpwm; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci /* 1208c2ecf20Sopenharmony_ci * Find period count, duty count and prescale to suit duty_ns and 1218c2ecf20Sopenharmony_ci * period_ns. This is done according to formulas described below: 1228c2ecf20Sopenharmony_ci * 1238c2ecf20Sopenharmony_ci * period_ns = 10^9 * (PRESCALE + 1) * PC / PWM_CLK_RATE 1248c2ecf20Sopenharmony_ci * duty_ns = 10^9 * (PRESCALE + 1) * DC / PWM_CLK_RATE 1258c2ecf20Sopenharmony_ci * 1268c2ecf20Sopenharmony_ci * PC = (PWM_CLK_RATE * period_ns) / (10^9 * (PRESCALE + 1)) 1278c2ecf20Sopenharmony_ci * DC = (PWM_CLK_RATE * duty_ns) / (10^9 * (PRESCALE + 1)) 1288c2ecf20Sopenharmony_ci */ 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci rate = clk_get_rate(kp->clk); 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci while (1) { 1338c2ecf20Sopenharmony_ci div = 1000000000; 1348c2ecf20Sopenharmony_ci div *= 1 + prescale; 1358c2ecf20Sopenharmony_ci val = rate * period_ns; 1368c2ecf20Sopenharmony_ci pc = div64_u64(val, div); 1378c2ecf20Sopenharmony_ci val = rate * duty_ns; 1388c2ecf20Sopenharmony_ci dc = div64_u64(val, div); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci /* If duty_ns or period_ns are not achievable then return */ 1418c2ecf20Sopenharmony_ci if (pc < PERIOD_COUNT_MIN) 1428c2ecf20Sopenharmony_ci return -EINVAL; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci /* If pc and dc are in bounds, the calculation is done */ 1458c2ecf20Sopenharmony_ci if (pc <= PERIOD_COUNT_MAX && dc <= DUTY_CYCLE_HIGH_MAX) 1468c2ecf20Sopenharmony_ci break; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci /* Otherwise, increase prescale and recalculate pc and dc */ 1498c2ecf20Sopenharmony_ci if (++prescale > PRESCALE_MAX) 1508c2ecf20Sopenharmony_ci return -EINVAL; 1518c2ecf20Sopenharmony_ci } 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci /* 1548c2ecf20Sopenharmony_ci * Don't apply settings if disabled. The period and duty cycle are 1558c2ecf20Sopenharmony_ci * always calculated above to ensure the new values are 1568c2ecf20Sopenharmony_ci * validated immediately instead of on enable. 1578c2ecf20Sopenharmony_ci */ 1588c2ecf20Sopenharmony_ci if (pwm_is_enabled(pwm)) { 1598c2ecf20Sopenharmony_ci kona_pwmc_prepare_for_settings(kp, chan); 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci value = readl(kp->base + PRESCALE_OFFSET); 1628c2ecf20Sopenharmony_ci value &= ~PRESCALE_MASK(chan); 1638c2ecf20Sopenharmony_ci value |= prescale << PRESCALE_SHIFT(chan); 1648c2ecf20Sopenharmony_ci writel(value, kp->base + PRESCALE_OFFSET); 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci writel(pc, kp->base + PERIOD_COUNT_OFFSET(chan)); 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci writel(dc, kp->base + DUTY_CYCLE_HIGH_OFFSET(chan)); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci kona_pwmc_apply_settings(kp, chan); 1718c2ecf20Sopenharmony_ci } 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci return 0; 1748c2ecf20Sopenharmony_ci} 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_cistatic int kona_pwmc_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, 1778c2ecf20Sopenharmony_ci enum pwm_polarity polarity) 1788c2ecf20Sopenharmony_ci{ 1798c2ecf20Sopenharmony_ci struct kona_pwmc *kp = to_kona_pwmc(chip); 1808c2ecf20Sopenharmony_ci unsigned int chan = pwm->hwpwm; 1818c2ecf20Sopenharmony_ci unsigned int value; 1828c2ecf20Sopenharmony_ci int ret; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci ret = clk_prepare_enable(kp->clk); 1858c2ecf20Sopenharmony_ci if (ret < 0) { 1868c2ecf20Sopenharmony_ci dev_err(chip->dev, "failed to enable clock: %d\n", ret); 1878c2ecf20Sopenharmony_ci return ret; 1888c2ecf20Sopenharmony_ci } 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci kona_pwmc_prepare_for_settings(kp, chan); 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci value = readl(kp->base + PWM_CONTROL_OFFSET); 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci if (polarity == PWM_POLARITY_NORMAL) 1958c2ecf20Sopenharmony_ci value |= 1 << PWM_CONTROL_POLARITY_SHIFT(chan); 1968c2ecf20Sopenharmony_ci else 1978c2ecf20Sopenharmony_ci value &= ~(1 << PWM_CONTROL_POLARITY_SHIFT(chan)); 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci writel(value, kp->base + PWM_CONTROL_OFFSET); 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci kona_pwmc_apply_settings(kp, chan); 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci clk_disable_unprepare(kp->clk); 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci return 0; 2068c2ecf20Sopenharmony_ci} 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_cistatic int kona_pwmc_enable(struct pwm_chip *chip, struct pwm_device *pwm) 2098c2ecf20Sopenharmony_ci{ 2108c2ecf20Sopenharmony_ci struct kona_pwmc *kp = to_kona_pwmc(chip); 2118c2ecf20Sopenharmony_ci int ret; 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci ret = clk_prepare_enable(kp->clk); 2148c2ecf20Sopenharmony_ci if (ret < 0) { 2158c2ecf20Sopenharmony_ci dev_err(chip->dev, "failed to enable clock: %d\n", ret); 2168c2ecf20Sopenharmony_ci return ret; 2178c2ecf20Sopenharmony_ci } 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci ret = kona_pwmc_config(chip, pwm, pwm_get_duty_cycle(pwm), 2208c2ecf20Sopenharmony_ci pwm_get_period(pwm)); 2218c2ecf20Sopenharmony_ci if (ret < 0) { 2228c2ecf20Sopenharmony_ci clk_disable_unprepare(kp->clk); 2238c2ecf20Sopenharmony_ci return ret; 2248c2ecf20Sopenharmony_ci } 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci return 0; 2278c2ecf20Sopenharmony_ci} 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_cistatic void kona_pwmc_disable(struct pwm_chip *chip, struct pwm_device *pwm) 2308c2ecf20Sopenharmony_ci{ 2318c2ecf20Sopenharmony_ci struct kona_pwmc *kp = to_kona_pwmc(chip); 2328c2ecf20Sopenharmony_ci unsigned int chan = pwm->hwpwm; 2338c2ecf20Sopenharmony_ci unsigned int value; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci kona_pwmc_prepare_for_settings(kp, chan); 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci /* Simulate a disable by configuring for zero duty */ 2388c2ecf20Sopenharmony_ci writel(0, kp->base + DUTY_CYCLE_HIGH_OFFSET(chan)); 2398c2ecf20Sopenharmony_ci writel(0, kp->base + PERIOD_COUNT_OFFSET(chan)); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci /* Set prescale to 0 for this channel */ 2428c2ecf20Sopenharmony_ci value = readl(kp->base + PRESCALE_OFFSET); 2438c2ecf20Sopenharmony_ci value &= ~PRESCALE_MASK(chan); 2448c2ecf20Sopenharmony_ci writel(value, kp->base + PRESCALE_OFFSET); 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci kona_pwmc_apply_settings(kp, chan); 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci clk_disable_unprepare(kp->clk); 2498c2ecf20Sopenharmony_ci} 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_cistatic const struct pwm_ops kona_pwm_ops = { 2528c2ecf20Sopenharmony_ci .config = kona_pwmc_config, 2538c2ecf20Sopenharmony_ci .set_polarity = kona_pwmc_set_polarity, 2548c2ecf20Sopenharmony_ci .enable = kona_pwmc_enable, 2558c2ecf20Sopenharmony_ci .disable = kona_pwmc_disable, 2568c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 2578c2ecf20Sopenharmony_ci}; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_cistatic int kona_pwmc_probe(struct platform_device *pdev) 2608c2ecf20Sopenharmony_ci{ 2618c2ecf20Sopenharmony_ci struct kona_pwmc *kp; 2628c2ecf20Sopenharmony_ci struct resource *res; 2638c2ecf20Sopenharmony_ci unsigned int chan; 2648c2ecf20Sopenharmony_ci unsigned int value = 0; 2658c2ecf20Sopenharmony_ci int ret = 0; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL); 2688c2ecf20Sopenharmony_ci if (kp == NULL) 2698c2ecf20Sopenharmony_ci return -ENOMEM; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, kp); 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci kp->chip.dev = &pdev->dev; 2748c2ecf20Sopenharmony_ci kp->chip.ops = &kona_pwm_ops; 2758c2ecf20Sopenharmony_ci kp->chip.base = -1; 2768c2ecf20Sopenharmony_ci kp->chip.npwm = 6; 2778c2ecf20Sopenharmony_ci kp->chip.of_xlate = of_pwm_xlate_with_flags; 2788c2ecf20Sopenharmony_ci kp->chip.of_pwm_n_cells = 3; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2818c2ecf20Sopenharmony_ci kp->base = devm_ioremap_resource(&pdev->dev, res); 2828c2ecf20Sopenharmony_ci if (IS_ERR(kp->base)) 2838c2ecf20Sopenharmony_ci return PTR_ERR(kp->base); 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci kp->clk = devm_clk_get(&pdev->dev, NULL); 2868c2ecf20Sopenharmony_ci if (IS_ERR(kp->clk)) { 2878c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "failed to get clock: %ld\n", 2888c2ecf20Sopenharmony_ci PTR_ERR(kp->clk)); 2898c2ecf20Sopenharmony_ci return PTR_ERR(kp->clk); 2908c2ecf20Sopenharmony_ci } 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci ret = clk_prepare_enable(kp->clk); 2938c2ecf20Sopenharmony_ci if (ret < 0) { 2948c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "failed to enable clock: %d\n", ret); 2958c2ecf20Sopenharmony_ci return ret; 2968c2ecf20Sopenharmony_ci } 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci /* Set push/pull for all channels */ 2998c2ecf20Sopenharmony_ci for (chan = 0; chan < kp->chip.npwm; chan++) 3008c2ecf20Sopenharmony_ci value |= (1 << PWM_CONTROL_TYPE_SHIFT(chan)); 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci writel(value, kp->base + PWM_CONTROL_OFFSET); 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci clk_disable_unprepare(kp->clk); 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci ret = pwmchip_add_with_polarity(&kp->chip, PWM_POLARITY_INVERSED); 3078c2ecf20Sopenharmony_ci if (ret < 0) 3088c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci return ret; 3118c2ecf20Sopenharmony_ci} 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_cistatic int kona_pwmc_remove(struct platform_device *pdev) 3148c2ecf20Sopenharmony_ci{ 3158c2ecf20Sopenharmony_ci struct kona_pwmc *kp = platform_get_drvdata(pdev); 3168c2ecf20Sopenharmony_ci unsigned int chan; 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci for (chan = 0; chan < kp->chip.npwm; chan++) 3198c2ecf20Sopenharmony_ci if (pwm_is_enabled(&kp->chip.pwms[chan])) 3208c2ecf20Sopenharmony_ci clk_disable_unprepare(kp->clk); 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci return pwmchip_remove(&kp->chip); 3238c2ecf20Sopenharmony_ci} 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_cistatic const struct of_device_id bcm_kona_pwmc_dt[] = { 3268c2ecf20Sopenharmony_ci { .compatible = "brcm,kona-pwm" }, 3278c2ecf20Sopenharmony_ci { }, 3288c2ecf20Sopenharmony_ci}; 3298c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, bcm_kona_pwmc_dt); 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_cistatic struct platform_driver kona_pwmc_driver = { 3328c2ecf20Sopenharmony_ci .driver = { 3338c2ecf20Sopenharmony_ci .name = "bcm-kona-pwm", 3348c2ecf20Sopenharmony_ci .of_match_table = bcm_kona_pwmc_dt, 3358c2ecf20Sopenharmony_ci }, 3368c2ecf20Sopenharmony_ci .probe = kona_pwmc_probe, 3378c2ecf20Sopenharmony_ci .remove = kona_pwmc_remove, 3388c2ecf20Sopenharmony_ci}; 3398c2ecf20Sopenharmony_cimodule_platform_driver(kona_pwmc_driver); 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ciMODULE_AUTHOR("Broadcom Corporation <bcm-kernel-feedback-list@broadcom.com>"); 3428c2ecf20Sopenharmony_ciMODULE_AUTHOR("Tim Kryger <tkryger@broadcom.com>"); 3438c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Broadcom Kona PWM driver"); 3448c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 345