mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
Merge tag 'pwm/for-5.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm
Pull pwm updates from Thierry Reding: "This is a fairly big release cycle from the PWM framework's point of view. There's a large patcheset here which converts drivers to use the new devm_platform_ioremap_resource() helper and a bunch of minor fixes to existing drivers. Some of the existing drivers also add support for more hardware, such as Atmel SAMA 5D2 and Mediatek MT8183. Finally there's a couple of new drivers for Intel Keem Bay and LGM SoCs as well as the DesignWare PWM controller" * tag 'pwm/for-5.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: (66 commits) pwm: sun4i: Remove erroneous else branch pwm: sl28cpld: Set driver data before registering the PWM chip pwm: Remove unused function pwmchip_add_inversed() pwm: imx27: Fix overflow for bigger periods pwm: bcm2835: Support apply function for atomic configuration pwm: keembay: Fix build failure with -Os pwm: core: Use octal permission pwm: lpss: Make compilable with COMPILE_TEST pwm: Fix dependencies on HAS_IOMEM pwm: Use -EINVAL for unsupported polarity pwm: sti: Remove unnecessary blank line pwm: sti: Avoid conditional gotos pwm: Add PWM fan controller driver for LGM SoC Add DT bindings YAML schema for PWM fan controller of LGM SoC pwm: Add DesignWare PWM Controller Driver dt-bindings: pwm: mtk-disp: add MT8167 SoC binding pwm: mediatek: Add MT8183 SoC support pwm: mediatek: Always use bus clock dt-bindings: pwm: pwm-mediatek: Add documentation for MT8183 SoC pwm: Add PWM driver for Intel Keem Bay ...
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
Atmel TCB PWM controller
|
||||
|
||||
Required properties:
|
||||
- compatible: should be "atmel,tcb-pwm"
|
||||
- #pwm-cells: should be 3. See pwm.yaml in this directory for a description of
|
||||
the cells format. The only third cell flag supported by this binding is
|
||||
PWM_POLARITY_INVERTED.
|
||||
- tc-block: The Timer Counter block to use as a PWM chip.
|
||||
|
||||
Example:
|
||||
|
||||
pwm {
|
||||
compatible = "atmel,tcb-pwm";
|
||||
#pwm-cells = <3>;
|
||||
tc-block = <1>;
|
||||
};
|
||||
47
Documentation/devicetree/bindings/pwm/intel,keembay-pwm.yaml
Normal file
47
Documentation/devicetree/bindings/pwm/intel,keembay-pwm.yaml
Normal file
@@ -0,0 +1,47 @@
|
||||
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
%YAML 1.2
|
||||
---
|
||||
$id: http://devicetree.org/schemas/pwm/intel,keembay-pwm.yaml#
|
||||
$schema: http://devicetree.org/meta-schemas/core.yaml#
|
||||
|
||||
title: Intel Keem Bay PWM Device Tree Bindings
|
||||
|
||||
maintainers:
|
||||
- Vijayakannan Ayyathurai <vijayakannan.ayyathurai@intel.com>
|
||||
|
||||
allOf:
|
||||
- $ref: pwm.yaml#
|
||||
|
||||
properties:
|
||||
compatible:
|
||||
enum:
|
||||
- intel,keembay-pwm
|
||||
|
||||
reg:
|
||||
maxItems: 1
|
||||
|
||||
clocks:
|
||||
maxItems: 1
|
||||
|
||||
"#pwm-cells":
|
||||
const: 2
|
||||
|
||||
required:
|
||||
- compatible
|
||||
- reg
|
||||
- clocks
|
||||
- '#pwm-cells'
|
||||
|
||||
additionalProperties: false
|
||||
|
||||
examples:
|
||||
- |
|
||||
#define KEEM_BAY_A53_GPIO
|
||||
|
||||
pwm@203200a0 {
|
||||
compatible = "intel,keembay-pwm";
|
||||
reg = <0x203200a0 0xe8>;
|
||||
clocks = <&scmi_clk KEEM_BAY_A53_GPIO>;
|
||||
#pwm-cells = <2>;
|
||||
};
|
||||
44
Documentation/devicetree/bindings/pwm/intel,lgm-pwm.yaml
Normal file
44
Documentation/devicetree/bindings/pwm/intel,lgm-pwm.yaml
Normal file
@@ -0,0 +1,44 @@
|
||||
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
|
||||
%YAML 1.2
|
||||
---
|
||||
$id: http://devicetree.org/schemas/pwm/intel,lgm-pwm.yaml#
|
||||
$schema: http://devicetree.org/meta-schemas/core.yaml#
|
||||
|
||||
title: LGM SoC PWM fan controller
|
||||
|
||||
maintainers:
|
||||
- Rahul Tanwar <rtanwar@maxlinear.com>
|
||||
|
||||
properties:
|
||||
compatible:
|
||||
const: intel,lgm-pwm
|
||||
|
||||
reg:
|
||||
maxItems: 1
|
||||
|
||||
"#pwm-cells":
|
||||
const: 2
|
||||
|
||||
clocks:
|
||||
maxItems: 1
|
||||
|
||||
resets:
|
||||
maxItems: 1
|
||||
|
||||
required:
|
||||
- compatible
|
||||
- reg
|
||||
- clocks
|
||||
- resets
|
||||
|
||||
additionalProperties: false
|
||||
|
||||
examples:
|
||||
- |
|
||||
pwm: pwm@e0d00000 {
|
||||
compatible = "intel,lgm-pwm";
|
||||
reg = <0xe0d00000 0x30>;
|
||||
#pwm-cells = <2>;
|
||||
clocks = <&cgu0 126>;
|
||||
resets = <&rcu0 0x30 21>;
|
||||
};
|
||||
@@ -7,6 +7,7 @@ Required properties:
|
||||
- "mediatek,mt7623-pwm": found on mt7623 SoC.
|
||||
- "mediatek,mt7628-pwm": found on mt7628 SoC.
|
||||
- "mediatek,mt7629-pwm": found on mt7629 SoC.
|
||||
- "mediatek,mt8183-pwm": found on mt8183 SoC.
|
||||
- "mediatek,mt8516-pwm": found on mt8516 SoC.
|
||||
- reg: physical base address and length of the controller's registers.
|
||||
- #pwm-cells: must be 2. See pwm.yaml in this directory for a description of
|
||||
|
||||
@@ -4,6 +4,7 @@ Required properties:
|
||||
- compatible: should be "mediatek,<name>-disp-pwm":
|
||||
- "mediatek,mt2701-disp-pwm": found on mt2701 SoC.
|
||||
- "mediatek,mt6595-disp-pwm": found on mt6595 SoC.
|
||||
- "mediatek,mt8167-disp-pwm", "mediatek,mt8173-disp-pwm": found on mt8167 SoC.
|
||||
- "mediatek,mt8173-disp-pwm": found on mt8173 SoC.
|
||||
- reg: physical base address and length of the controller's registers.
|
||||
- #pwm-cells: must be 2. See pwm.yaml in this directory for a description of
|
||||
|
||||
@@ -59,6 +59,7 @@ patternProperties:
|
||||
items:
|
||||
- enum:
|
||||
- atmel,tcb-timer
|
||||
- atmel,tcb-pwm
|
||||
- microchip,tcb-capture
|
||||
reg:
|
||||
description:
|
||||
@@ -68,10 +69,35 @@ patternProperties:
|
||||
|
||||
minItems: 1
|
||||
maxItems: 3
|
||||
required:
|
||||
- compatible
|
||||
- reg
|
||||
|
||||
"^pwm@[0-2]$":
|
||||
description: The timer block channels that are used as PWMs.
|
||||
$ref: ../../pwm/pwm.yaml#
|
||||
type: object
|
||||
properties:
|
||||
compatible:
|
||||
const: atmel,tcb-pwm
|
||||
reg:
|
||||
description:
|
||||
TCB channel to use for this PWM.
|
||||
enum: [ 0, 1, 2 ]
|
||||
|
||||
"#pwm-cells":
|
||||
description:
|
||||
The only third cell flag supported by this binding is
|
||||
PWM_POLARITY_INVERTED.
|
||||
const: 3
|
||||
|
||||
required:
|
||||
- compatible
|
||||
- reg
|
||||
- "#pwm-cells"
|
||||
|
||||
additionalProperties: false
|
||||
|
||||
|
||||
allOf:
|
||||
- if:
|
||||
@@ -158,7 +184,13 @@ examples:
|
||||
compatible = "atmel,tcb-timer";
|
||||
reg = <1>;
|
||||
};
|
||||
};
|
||||
|
||||
pwm@2 {
|
||||
compatible = "atmel,tcb-pwm";
|
||||
reg = <2>;
|
||||
#pwm-cells = <3>;
|
||||
};
|
||||
};
|
||||
/* TCB0 Capture with QDEC: */
|
||||
timer@f800c000 {
|
||||
compatible = "atmel,at91rm9200-tcb", "simple-mfd", "syscon";
|
||||
|
||||
@@ -53,8 +53,8 @@ config PWM_AB8500
|
||||
|
||||
config PWM_ATMEL
|
||||
tristate "Atmel PWM support"
|
||||
depends on OF
|
||||
depends on ARCH_AT91 || COMPILE_TEST
|
||||
depends on HAS_IOMEM && OF
|
||||
help
|
||||
Generic PWM framework driver for Atmel SoC.
|
||||
|
||||
@@ -75,7 +75,8 @@ config PWM_ATMEL_HLCDC_PWM
|
||||
|
||||
config PWM_ATMEL_TCB
|
||||
tristate "Atmel TC Block PWM support"
|
||||
depends on ATMEL_TCLIB && OF
|
||||
depends on OF
|
||||
select REGMAP_MMIO
|
||||
help
|
||||
Generic PWM framework driver for Atmel Timer Counter Block.
|
||||
|
||||
@@ -88,7 +89,7 @@ config PWM_ATMEL_TCB
|
||||
config PWM_BCM_IPROC
|
||||
tristate "iProc PWM support"
|
||||
depends on ARCH_BCM_IPROC || COMPILE_TEST
|
||||
depends on COMMON_CLK
|
||||
depends on COMMON_CLK && HAS_IOMEM
|
||||
default ARCH_BCM_IPROC
|
||||
help
|
||||
Generic PWM framework driver for Broadcom iProc PWM block. This
|
||||
@@ -111,6 +112,7 @@ config PWM_BCM_KONA
|
||||
config PWM_BCM2835
|
||||
tristate "BCM2835 PWM support"
|
||||
depends on ARCH_BCM2835 || ARCH_BRCMSTB || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
PWM framework driver for BCM2835 controller (Raspberry Pi)
|
||||
|
||||
@@ -120,6 +122,7 @@ config PWM_BCM2835
|
||||
config PWM_BERLIN
|
||||
tristate "Marvell Berlin PWM support"
|
||||
depends on ARCH_BERLIN || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
PWM framework driver for Marvell Berlin SoCs.
|
||||
|
||||
@@ -129,6 +132,7 @@ config PWM_BERLIN
|
||||
config PWM_BRCMSTB
|
||||
tristate "Broadcom STB PWM support"
|
||||
depends on ARCH_BRCMSTB || BMIPS_GENERIC || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for the Broadcom Set-top-Box
|
||||
SoCs (BCM7xxx).
|
||||
@@ -160,9 +164,19 @@ config PWM_CROS_EC
|
||||
PWM driver for exposing a PWM attached to the ChromeOS Embedded
|
||||
Controller.
|
||||
|
||||
config PWM_DWC
|
||||
tristate "DesignWare PWM Controller"
|
||||
depends on PCI
|
||||
help
|
||||
PWM driver for Synopsys DWC PWM Controller attached to a PCI bus.
|
||||
|
||||
To compile this driver as a module, choose M here: the module
|
||||
will be called pwm-dwc.
|
||||
|
||||
config PWM_EP93XX
|
||||
tristate "Cirrus Logic EP93xx PWM support"
|
||||
depends on ARCH_EP93XX || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for Cirrus Logic EP93xx.
|
||||
|
||||
@@ -184,6 +198,7 @@ config PWM_FSL_FTM
|
||||
config PWM_HIBVT
|
||||
tristate "HiSilicon BVT PWM support"
|
||||
depends on ARCH_HISI || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for HiSilicon BVT SoCs.
|
||||
|
||||
@@ -206,6 +221,7 @@ config PWM_IMG
|
||||
config PWM_IMX1
|
||||
tristate "i.MX1 PWM support"
|
||||
depends on ARCH_MXC || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for i.MX1 and i.MX21
|
||||
|
||||
@@ -215,6 +231,7 @@ config PWM_IMX1
|
||||
config PWM_IMX27
|
||||
tristate "i.MX27 PWM support"
|
||||
depends on ARCH_MXC || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for i.MX27 and later i.MX SoCs.
|
||||
|
||||
@@ -232,6 +249,17 @@ config PWM_IMX_TPM
|
||||
To compile this driver as a module, choose M here: the module
|
||||
will be called pwm-imx-tpm.
|
||||
|
||||
config PWM_INTEL_LGM
|
||||
tristate "Intel LGM PWM support"
|
||||
depends on HAS_IOMEM
|
||||
depends on (OF && X86) || COMPILE_TEST
|
||||
select REGMAP_MMIO
|
||||
help
|
||||
Generic PWM fan controller driver for LGM SoC.
|
||||
|
||||
To compile this driver as a module, choose M here: the module
|
||||
will be called pwm-intel-lgm.
|
||||
|
||||
config PWM_IQS620A
|
||||
tristate "Azoteq IQS620A PWM support"
|
||||
depends on MFD_IQS62X || COMPILE_TEST
|
||||
@@ -254,6 +282,15 @@ config PWM_JZ4740
|
||||
To compile this driver as a module, choose M here: the module
|
||||
will be called pwm-jz4740.
|
||||
|
||||
config PWM_KEEMBAY
|
||||
tristate "Intel Keem Bay PWM driver"
|
||||
depends on ARCH_KEEMBAY || (ARM64 && COMPILE_TEST)
|
||||
help
|
||||
The platform driver for Intel Keem Bay PWM controller.
|
||||
|
||||
To compile this driver as a module, choose M here: the module
|
||||
will be called pwm-keembay.
|
||||
|
||||
config PWM_LP3943
|
||||
tristate "TI/National Semiconductor LP3943 PWM support"
|
||||
depends on MFD_LP3943
|
||||
@@ -267,6 +304,7 @@ config PWM_LP3943
|
||||
config PWM_LPC18XX_SCT
|
||||
tristate "LPC18xx/43xx PWM/SCT support"
|
||||
depends on ARCH_LPC18XX || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for NXP LPC18xx PWM/SCT which
|
||||
supports 16 channels.
|
||||
@@ -279,6 +317,7 @@ config PWM_LPC18XX_SCT
|
||||
config PWM_LPC32XX
|
||||
tristate "LPC32XX PWM support"
|
||||
depends on ARCH_LPC32XX || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for LPC32XX. The LPC32XX SOC has two
|
||||
PWM controllers.
|
||||
@@ -287,11 +326,13 @@ config PWM_LPC32XX
|
||||
will be called pwm-lpc32xx.
|
||||
|
||||
config PWM_LPSS
|
||||
depends on HAS_IOMEM
|
||||
tristate
|
||||
|
||||
config PWM_LPSS_PCI
|
||||
tristate "Intel LPSS PWM PCI driver"
|
||||
depends on X86 && PCI
|
||||
depends on X86 || COMPILE_TEST
|
||||
depends on HAS_IOMEM && PCI
|
||||
select PWM_LPSS
|
||||
help
|
||||
The PCI driver for Intel Low Power Subsystem PWM controller.
|
||||
@@ -301,7 +342,8 @@ config PWM_LPSS_PCI
|
||||
|
||||
config PWM_LPSS_PLATFORM
|
||||
tristate "Intel LPSS PWM platform driver"
|
||||
depends on X86 && ACPI
|
||||
depends on (X86 && ACPI) || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
select PWM_LPSS
|
||||
help
|
||||
The platform driver for Intel Low Power Subsystem PWM controller.
|
||||
@@ -312,7 +354,7 @@ config PWM_LPSS_PLATFORM
|
||||
config PWM_MESON
|
||||
tristate "Amlogic Meson PWM driver"
|
||||
depends on ARCH_MESON || COMPILE_TEST
|
||||
depends on COMMON_CLK
|
||||
depends on COMMON_CLK && HAS_IOMEM
|
||||
help
|
||||
The platform driver for Amlogic Meson PWM controller.
|
||||
|
||||
@@ -333,6 +375,7 @@ config PWM_MTK_DISP
|
||||
config PWM_MEDIATEK
|
||||
tristate "MediaTek PWM support"
|
||||
depends on ARCH_MEDIATEK || RALINK || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for Mediatek ARM SoC.
|
||||
|
||||
@@ -341,8 +384,8 @@ config PWM_MEDIATEK
|
||||
|
||||
config PWM_MXS
|
||||
tristate "Freescale MXS PWM support"
|
||||
depends on OF
|
||||
depends on ARCH_MXS || COMPILE_TEST
|
||||
depends on HAS_IOMEM && OF
|
||||
select STMP_DEVICE
|
||||
help
|
||||
Generic PWM framework driver for Freescale MXS.
|
||||
@@ -373,6 +416,7 @@ config PWM_PCA9685
|
||||
config PWM_PXA
|
||||
tristate "PXA PWM support"
|
||||
depends on ARCH_PXA || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for PXA.
|
||||
|
||||
@@ -404,6 +448,7 @@ config PWM_RENESAS_TPU
|
||||
config PWM_ROCKCHIP
|
||||
tristate "Rockchip PWM support"
|
||||
depends on ARCH_ROCKCHIP || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for the PWM controller found on
|
||||
Rockchip SoCs.
|
||||
@@ -411,6 +456,7 @@ config PWM_ROCKCHIP
|
||||
config PWM_SAMSUNG
|
||||
tristate "Samsung PWM support"
|
||||
depends on PLAT_SAMSUNG || ARCH_S5PV210 || ARCH_EXYNOS || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for Samsung.
|
||||
|
||||
@@ -420,7 +466,7 @@ config PWM_SAMSUNG
|
||||
config PWM_SIFIVE
|
||||
tristate "SiFive PWM support"
|
||||
depends on OF
|
||||
depends on COMMON_CLK
|
||||
depends on COMMON_CLK && HAS_IOMEM
|
||||
depends on RISCV || COMPILE_TEST
|
||||
help
|
||||
Generic PWM framework driver for SiFive SoCs.
|
||||
@@ -441,7 +487,7 @@ config PWM_SL28CPLD
|
||||
config PWM_SPEAR
|
||||
tristate "STMicroelectronics SPEAr PWM support"
|
||||
depends on PLAT_SPEAR || COMPILE_TEST
|
||||
depends on OF
|
||||
depends on HAS_IOMEM && OF
|
||||
help
|
||||
Generic PWM framework driver for the PWM controller on ST
|
||||
SPEAr SoCs.
|
||||
@@ -463,7 +509,7 @@ config PWM_SPRD
|
||||
config PWM_STI
|
||||
tristate "STiH4xx PWM support"
|
||||
depends on ARCH_STI || COMPILE_TEST
|
||||
depends on OF
|
||||
depends on HAS_IOMEM && OF
|
||||
help
|
||||
Generic PWM framework driver for STiH4xx SoCs.
|
||||
|
||||
@@ -509,6 +555,7 @@ config PWM_SUN4I
|
||||
config PWM_TEGRA
|
||||
tristate "NVIDIA Tegra PWM support"
|
||||
depends on ARCH_TEGRA || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for the PWFM controller found on NVIDIA
|
||||
Tegra SoCs.
|
||||
@@ -519,6 +566,7 @@ config PWM_TEGRA
|
||||
config PWM_TIECAP
|
||||
tristate "ECAP PWM support"
|
||||
depends on ARCH_OMAP2PLUS || ARCH_DAVINCI_DA8XX || ARCH_KEYSTONE || ARCH_K3 || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
PWM driver support for the ECAP APWM controller found on TI SOCs
|
||||
|
||||
@@ -528,6 +576,7 @@ config PWM_TIECAP
|
||||
config PWM_TIEHRPWM
|
||||
tristate "EHRPWM PWM support"
|
||||
depends on ARCH_OMAP2PLUS || ARCH_DAVINCI_DA8XX || ARCH_K3 || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
PWM driver support for the EHRPWM controller found on TI SOCs
|
||||
|
||||
@@ -555,6 +604,7 @@ config PWM_TWL_LED
|
||||
config PWM_VT8500
|
||||
tristate "vt8500 PWM support"
|
||||
depends on ARCH_VT8500 || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for vt8500.
|
||||
|
||||
@@ -564,6 +614,7 @@ config PWM_VT8500
|
||||
config PWM_ZX
|
||||
tristate "ZTE ZX PWM support"
|
||||
depends on ARCH_ZX || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
help
|
||||
Generic PWM framework driver for ZTE ZX family SoCs.
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ obj-$(CONFIG_PWM_BRCMSTB) += pwm-brcmstb.o
|
||||
obj-$(CONFIG_PWM_CLPS711X) += pwm-clps711x.o
|
||||
obj-$(CONFIG_PWM_CRC) += pwm-crc.o
|
||||
obj-$(CONFIG_PWM_CROS_EC) += pwm-cros-ec.o
|
||||
obj-$(CONFIG_PWM_DWC) += pwm-dwc.o
|
||||
obj-$(CONFIG_PWM_EP93XX) += pwm-ep93xx.o
|
||||
obj-$(CONFIG_PWM_FSL_FTM) += pwm-fsl-ftm.o
|
||||
obj-$(CONFIG_PWM_HIBVT) += pwm-hibvt.o
|
||||
@@ -20,8 +21,10 @@ obj-$(CONFIG_PWM_IMG) += pwm-img.o
|
||||
obj-$(CONFIG_PWM_IMX1) += pwm-imx1.o
|
||||
obj-$(CONFIG_PWM_IMX27) += pwm-imx27.o
|
||||
obj-$(CONFIG_PWM_IMX_TPM) += pwm-imx-tpm.o
|
||||
obj-$(CONFIG_PWM_INTEL_LGM) += pwm-intel-lgm.o
|
||||
obj-$(CONFIG_PWM_IQS620A) += pwm-iqs620a.o
|
||||
obj-$(CONFIG_PWM_JZ4740) += pwm-jz4740.o
|
||||
obj-$(CONFIG_PWM_KEEMBAY) += pwm-keembay.o
|
||||
obj-$(CONFIG_PWM_LP3943) += pwm-lp3943.o
|
||||
obj-$(CONFIG_PWM_LPC18XX_SCT) += pwm-lpc18xx-sct.o
|
||||
obj-$(CONFIG_PWM_LPC32XX) += pwm-lpc32xx.o
|
||||
|
||||
@@ -1338,7 +1338,7 @@ DEFINE_SEQ_ATTRIBUTE(pwm_debugfs);
|
||||
|
||||
static int __init pwm_debugfs_init(void)
|
||||
{
|
||||
debugfs_create_file("pwm", S_IFREG | S_IRUGO, NULL, NULL,
|
||||
debugfs_create_file("pwm", S_IFREG | 0444, NULL, NULL,
|
||||
&pwm_debugfs_fops);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -101,12 +101,12 @@ static int ab8500_pwm_probe(struct platform_device *pdev)
|
||||
|
||||
ab8500->chip.dev = &pdev->dev;
|
||||
ab8500->chip.ops = &ab8500_pwm_ops;
|
||||
ab8500->chip.base = pdev->id;
|
||||
ab8500->chip.base = -1;
|
||||
ab8500->chip.npwm = 1;
|
||||
|
||||
err = pwmchip_add(&ab8500->chip);
|
||||
if (err < 0)
|
||||
return err;
|
||||
return dev_err_probe(&pdev->dev, err, "Failed to add pwm chip\n");
|
||||
|
||||
dev_dbg(&pdev->dev, "pwm probe successful\n");
|
||||
platform_set_drvdata(pdev, ab8500);
|
||||
|
||||
@@ -16,13 +16,16 @@
|
||||
#include <linux/err.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/mfd/syscon.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/pwm.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/slab.h>
|
||||
#include <soc/at91/atmel_tcb.h>
|
||||
|
||||
#define NPWM 6
|
||||
#define NPWM 2
|
||||
|
||||
#define ATMEL_TC_ACMR_MASK (ATMEL_TC_ACPA | ATMEL_TC_ACPC | \
|
||||
ATMEL_TC_AEEVT | ATMEL_TC_ASWTRG)
|
||||
@@ -48,11 +51,18 @@ struct atmel_tcb_channel {
|
||||
struct atmel_tcb_pwm_chip {
|
||||
struct pwm_chip chip;
|
||||
spinlock_t lock;
|
||||
struct atmel_tc *tc;
|
||||
u8 channel;
|
||||
u8 width;
|
||||
struct regmap *regmap;
|
||||
struct clk *clk;
|
||||
struct clk *gclk;
|
||||
struct clk *slow_clk;
|
||||
struct atmel_tcb_pwm_device *pwms[NPWM];
|
||||
struct atmel_tcb_channel bkup[NPWM / 2];
|
||||
struct atmel_tcb_channel bkup;
|
||||
};
|
||||
|
||||
const u8 atmel_tcb_divisors[] = { 2, 8, 32, 128, 0, };
|
||||
|
||||
static inline struct atmel_tcb_pwm_chip *to_tcb_chip(struct pwm_chip *chip)
|
||||
{
|
||||
return container_of(chip, struct atmel_tcb_pwm_chip, chip);
|
||||
@@ -74,10 +84,6 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip,
|
||||
{
|
||||
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
|
||||
struct atmel_tcb_pwm_device *tcbpwm;
|
||||
struct atmel_tc *tc = tcbpwmc->tc;
|
||||
void __iomem *regs = tc->regs;
|
||||
unsigned group = pwm->hwpwm / 2;
|
||||
unsigned index = pwm->hwpwm % 2;
|
||||
unsigned cmr;
|
||||
int ret;
|
||||
|
||||
@@ -85,7 +91,7 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip,
|
||||
if (!tcbpwm)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = clk_prepare_enable(tc->clk[group]);
|
||||
ret = clk_prepare_enable(tcbpwmc->clk);
|
||||
if (ret) {
|
||||
devm_kfree(chip->dev, tcbpwm);
|
||||
return ret;
|
||||
@@ -98,28 +104,31 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip,
|
||||
tcbpwm->div = 0;
|
||||
|
||||
spin_lock(&tcbpwmc->lock);
|
||||
cmr = __raw_readl(regs + ATMEL_TC_REG(group, CMR));
|
||||
regmap_read(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CMR), &cmr);
|
||||
/*
|
||||
* Get init config from Timer Counter registers if
|
||||
* Timer Counter is already configured as a PWM generator.
|
||||
*/
|
||||
if (cmr & ATMEL_TC_WAVE) {
|
||||
if (index == 0)
|
||||
tcbpwm->duty =
|
||||
__raw_readl(regs + ATMEL_TC_REG(group, RA));
|
||||
if (pwm->hwpwm == 0)
|
||||
regmap_read(tcbpwmc->regmap,
|
||||
ATMEL_TC_REG(tcbpwmc->channel, RA),
|
||||
&tcbpwm->duty);
|
||||
else
|
||||
tcbpwm->duty =
|
||||
__raw_readl(regs + ATMEL_TC_REG(group, RB));
|
||||
regmap_read(tcbpwmc->regmap,
|
||||
ATMEL_TC_REG(tcbpwmc->channel, RB),
|
||||
&tcbpwm->duty);
|
||||
|
||||
tcbpwm->div = cmr & ATMEL_TC_TCCLKS;
|
||||
tcbpwm->period = __raw_readl(regs + ATMEL_TC_REG(group, RC));
|
||||
regmap_read(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, RC),
|
||||
&tcbpwm->period);
|
||||
cmr &= (ATMEL_TC_TCCLKS | ATMEL_TC_ACMR_MASK |
|
||||
ATMEL_TC_BCMR_MASK);
|
||||
} else
|
||||
cmr = 0;
|
||||
|
||||
cmr |= ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO | ATMEL_TC_EEVT_XC0;
|
||||
__raw_writel(cmr, regs + ATMEL_TC_REG(group, CMR));
|
||||
regmap_write(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CMR), cmr);
|
||||
spin_unlock(&tcbpwmc->lock);
|
||||
|
||||
tcbpwmc->pwms[pwm->hwpwm] = tcbpwm;
|
||||
@@ -131,9 +140,8 @@ static void atmel_tcb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
{
|
||||
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
|
||||
struct atmel_tcb_pwm_device *tcbpwm = pwm_get_chip_data(pwm);
|
||||
struct atmel_tc *tc = tcbpwmc->tc;
|
||||
|
||||
clk_disable_unprepare(tc->clk[pwm->hwpwm / 2]);
|
||||
clk_disable_unprepare(tcbpwmc->clk);
|
||||
tcbpwmc->pwms[pwm->hwpwm] = NULL;
|
||||
devm_kfree(chip->dev, tcbpwm);
|
||||
}
|
||||
@@ -142,10 +150,6 @@ static void atmel_tcb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
{
|
||||
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
|
||||
struct atmel_tcb_pwm_device *tcbpwm = pwm_get_chip_data(pwm);
|
||||
struct atmel_tc *tc = tcbpwmc->tc;
|
||||
void __iomem *regs = tc->regs;
|
||||
unsigned group = pwm->hwpwm / 2;
|
||||
unsigned index = pwm->hwpwm % 2;
|
||||
unsigned cmr;
|
||||
enum pwm_polarity polarity = tcbpwm->polarity;
|
||||
|
||||
@@ -161,10 +165,10 @@ static void atmel_tcb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
polarity = !polarity;
|
||||
|
||||
spin_lock(&tcbpwmc->lock);
|
||||
cmr = __raw_readl(regs + ATMEL_TC_REG(group, CMR));
|
||||
regmap_read(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CMR), &cmr);
|
||||
|
||||
/* flush old setting and set the new one */
|
||||
if (index == 0) {
|
||||
if (pwm->hwpwm == 0) {
|
||||
cmr &= ~ATMEL_TC_ACMR_MASK;
|
||||
if (polarity == PWM_POLARITY_INVERSED)
|
||||
cmr |= ATMEL_TC_ASWTRG_CLEAR;
|
||||
@@ -178,20 +182,22 @@ static void atmel_tcb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
cmr |= ATMEL_TC_BSWTRG_SET;
|
||||
}
|
||||
|
||||
__raw_writel(cmr, regs + ATMEL_TC_REG(group, CMR));
|
||||
regmap_write(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CMR), cmr);
|
||||
|
||||
/*
|
||||
* Use software trigger to apply the new setting.
|
||||
* If both PWM devices in this group are disabled we stop the clock.
|
||||
*/
|
||||
if (!(cmr & (ATMEL_TC_ACPC | ATMEL_TC_BCPC))) {
|
||||
__raw_writel(ATMEL_TC_SWTRG | ATMEL_TC_CLKDIS,
|
||||
regs + ATMEL_TC_REG(group, CCR));
|
||||
tcbpwmc->bkup[group].enabled = 1;
|
||||
regmap_write(tcbpwmc->regmap,
|
||||
ATMEL_TC_REG(tcbpwmc->channel, CCR),
|
||||
ATMEL_TC_SWTRG | ATMEL_TC_CLKDIS);
|
||||
tcbpwmc->bkup.enabled = 1;
|
||||
} else {
|
||||
__raw_writel(ATMEL_TC_SWTRG, regs +
|
||||
ATMEL_TC_REG(group, CCR));
|
||||
tcbpwmc->bkup[group].enabled = 0;
|
||||
regmap_write(tcbpwmc->regmap,
|
||||
ATMEL_TC_REG(tcbpwmc->channel, CCR),
|
||||
ATMEL_TC_SWTRG);
|
||||
tcbpwmc->bkup.enabled = 0;
|
||||
}
|
||||
|
||||
spin_unlock(&tcbpwmc->lock);
|
||||
@@ -201,10 +207,6 @@ static int atmel_tcb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
{
|
||||
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
|
||||
struct atmel_tcb_pwm_device *tcbpwm = pwm_get_chip_data(pwm);
|
||||
struct atmel_tc *tc = tcbpwmc->tc;
|
||||
void __iomem *regs = tc->regs;
|
||||
unsigned group = pwm->hwpwm / 2;
|
||||
unsigned index = pwm->hwpwm % 2;
|
||||
u32 cmr;
|
||||
enum pwm_polarity polarity = tcbpwm->polarity;
|
||||
|
||||
@@ -220,12 +222,12 @@ static int atmel_tcb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
polarity = !polarity;
|
||||
|
||||
spin_lock(&tcbpwmc->lock);
|
||||
cmr = __raw_readl(regs + ATMEL_TC_REG(group, CMR));
|
||||
regmap_read(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CMR), &cmr);
|
||||
|
||||
/* flush old setting and set the new one */
|
||||
cmr &= ~ATMEL_TC_TCCLKS;
|
||||
|
||||
if (index == 0) {
|
||||
if (pwm->hwpwm == 0) {
|
||||
cmr &= ~ATMEL_TC_ACMR_MASK;
|
||||
|
||||
/* Set CMR flags according to given polarity */
|
||||
@@ -248,7 +250,7 @@ static int atmel_tcb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
* this config till next config call.
|
||||
*/
|
||||
if (tcbpwm->duty != tcbpwm->period && tcbpwm->duty > 0) {
|
||||
if (index == 0) {
|
||||
if (pwm->hwpwm == 0) {
|
||||
if (polarity == PWM_POLARITY_INVERSED)
|
||||
cmr |= ATMEL_TC_ACPA_SET | ATMEL_TC_ACPC_CLEAR;
|
||||
else
|
||||
@@ -263,19 +265,24 @@ static int atmel_tcb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
|
||||
cmr |= (tcbpwm->div & ATMEL_TC_TCCLKS);
|
||||
|
||||
__raw_writel(cmr, regs + ATMEL_TC_REG(group, CMR));
|
||||
regmap_write(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CMR), cmr);
|
||||
|
||||
if (index == 0)
|
||||
__raw_writel(tcbpwm->duty, regs + ATMEL_TC_REG(group, RA));
|
||||
if (pwm->hwpwm == 0)
|
||||
regmap_write(tcbpwmc->regmap,
|
||||
ATMEL_TC_REG(tcbpwmc->channel, RA),
|
||||
tcbpwm->duty);
|
||||
else
|
||||
__raw_writel(tcbpwm->duty, regs + ATMEL_TC_REG(group, RB));
|
||||
regmap_write(tcbpwmc->regmap,
|
||||
ATMEL_TC_REG(tcbpwmc->channel, RB),
|
||||
tcbpwm->duty);
|
||||
|
||||
__raw_writel(tcbpwm->period, regs + ATMEL_TC_REG(group, RC));
|
||||
regmap_write(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, RC),
|
||||
tcbpwm->period);
|
||||
|
||||
/* Use software trigger to apply the new setting */
|
||||
__raw_writel(ATMEL_TC_CLKEN | ATMEL_TC_SWTRG,
|
||||
regs + ATMEL_TC_REG(group, CCR));
|
||||
tcbpwmc->bkup[group].enabled = 1;
|
||||
regmap_write(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CCR),
|
||||
ATMEL_TC_SWTRG | ATMEL_TC_CLKEN);
|
||||
tcbpwmc->bkup.enabled = 1;
|
||||
spin_unlock(&tcbpwmc->lock);
|
||||
return 0;
|
||||
}
|
||||
@@ -285,29 +292,29 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
{
|
||||
struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
|
||||
struct atmel_tcb_pwm_device *tcbpwm = pwm_get_chip_data(pwm);
|
||||
unsigned group = pwm->hwpwm / 2;
|
||||
unsigned index = pwm->hwpwm % 2;
|
||||
struct atmel_tcb_pwm_device *atcbpwm = NULL;
|
||||
struct atmel_tc *tc = tcbpwmc->tc;
|
||||
int i;
|
||||
int i = 0;
|
||||
int slowclk = 0;
|
||||
unsigned period;
|
||||
unsigned duty;
|
||||
unsigned rate = clk_get_rate(tc->clk[group]);
|
||||
unsigned rate = clk_get_rate(tcbpwmc->clk);
|
||||
unsigned long long min;
|
||||
unsigned long long max;
|
||||
|
||||
/*
|
||||
* Find best clk divisor:
|
||||
* the smallest divisor which can fulfill the period_ns requirements.
|
||||
* If there is a gclk, the first divisor is actuallly the gclk selector
|
||||
*/
|
||||
for (i = 0; i < 5; ++i) {
|
||||
if (atmel_tc_divisors[i] == 0) {
|
||||
if (tcbpwmc->gclk)
|
||||
i = 1;
|
||||
for (; i < ARRAY_SIZE(atmel_tcb_divisors); ++i) {
|
||||
if (atmel_tcb_divisors[i] == 0) {
|
||||
slowclk = i;
|
||||
continue;
|
||||
}
|
||||
min = div_u64((u64)NSEC_PER_SEC * atmel_tc_divisors[i], rate);
|
||||
max = min << tc->tcb_config->counter_width;
|
||||
min = div_u64((u64)NSEC_PER_SEC * atmel_tcb_divisors[i], rate);
|
||||
max = min << tcbpwmc->width;
|
||||
if (max >= period_ns)
|
||||
break;
|
||||
}
|
||||
@@ -316,11 +323,11 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
* If none of the divisor are small enough to represent period_ns
|
||||
* take slow clock (32KHz).
|
||||
*/
|
||||
if (i == 5) {
|
||||
if (i == ARRAY_SIZE(atmel_tcb_divisors)) {
|
||||
i = slowclk;
|
||||
rate = clk_get_rate(tc->slow_clk);
|
||||
rate = clk_get_rate(tcbpwmc->slow_clk);
|
||||
min = div_u64(NSEC_PER_SEC, rate);
|
||||
max = min << tc->tcb_config->counter_width;
|
||||
max = min << tcbpwmc->width;
|
||||
|
||||
/* If period is too big return ERANGE error */
|
||||
if (max < period_ns)
|
||||
@@ -330,17 +337,13 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
duty = div_u64(duty_ns, min);
|
||||
period = div_u64(period_ns, min);
|
||||
|
||||
if (index == 0)
|
||||
atcbpwm = tcbpwmc->pwms[pwm->hwpwm + 1];
|
||||
if (pwm->hwpwm == 0)
|
||||
atcbpwm = tcbpwmc->pwms[1];
|
||||
else
|
||||
atcbpwm = tcbpwmc->pwms[pwm->hwpwm - 1];
|
||||
atcbpwm = tcbpwmc->pwms[0];
|
||||
|
||||
/*
|
||||
* PWM devices provided by TCB driver are grouped by 2:
|
||||
* - group 0: PWM 0 & 1
|
||||
* - group 1: PWM 2 & 3
|
||||
* - group 2: PWM 4 & 5
|
||||
*
|
||||
* PWM devices provided by the TCB driver are grouped by 2.
|
||||
* PWM devices in a given group must be configured with the
|
||||
* same period_ns.
|
||||
*
|
||||
@@ -376,32 +379,75 @@ static const struct pwm_ops atmel_tcb_pwm_ops = {
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static struct atmel_tcb_config tcb_rm9200_config = {
|
||||
.counter_width = 16,
|
||||
};
|
||||
|
||||
static struct atmel_tcb_config tcb_sam9x5_config = {
|
||||
.counter_width = 32,
|
||||
};
|
||||
|
||||
static struct atmel_tcb_config tcb_sama5d2_config = {
|
||||
.counter_width = 32,
|
||||
.has_gclk = 1,
|
||||
};
|
||||
|
||||
static const struct of_device_id atmel_tcb_of_match[] = {
|
||||
{ .compatible = "atmel,at91rm9200-tcb", .data = &tcb_rm9200_config, },
|
||||
{ .compatible = "atmel,at91sam9x5-tcb", .data = &tcb_sam9x5_config, },
|
||||
{ .compatible = "atmel,sama5d2-tcb", .data = &tcb_sama5d2_config, },
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
|
||||
static int atmel_tcb_pwm_probe(struct platform_device *pdev)
|
||||
{
|
||||
const struct of_device_id *match;
|
||||
struct atmel_tcb_pwm_chip *tcbpwm;
|
||||
const struct atmel_tcb_config *config;
|
||||
struct device_node *np = pdev->dev.of_node;
|
||||
struct atmel_tc *tc;
|
||||
struct regmap *regmap;
|
||||
struct clk *clk, *gclk = NULL;
|
||||
struct clk *slow_clk;
|
||||
char clk_name[] = "t0_clk";
|
||||
int err;
|
||||
int tcblock;
|
||||
int channel;
|
||||
|
||||
err = of_property_read_u32(np, "tc-block", &tcblock);
|
||||
err = of_property_read_u32(np, "reg", &channel);
|
||||
if (err < 0) {
|
||||
dev_err(&pdev->dev,
|
||||
"failed to get Timer Counter Block number from device tree (error: %d)\n",
|
||||
"failed to get Timer Counter Block channel from device tree (error: %d)\n",
|
||||
err);
|
||||
return err;
|
||||
}
|
||||
|
||||
tc = atmel_tc_alloc(tcblock);
|
||||
if (tc == NULL) {
|
||||
dev_err(&pdev->dev, "failed to allocate Timer Counter Block\n");
|
||||
return -ENOMEM;
|
||||
regmap = syscon_node_to_regmap(np->parent);
|
||||
if (IS_ERR(regmap))
|
||||
return PTR_ERR(regmap);
|
||||
|
||||
slow_clk = of_clk_get_by_name(np->parent, "slow_clk");
|
||||
if (IS_ERR(slow_clk))
|
||||
return PTR_ERR(slow_clk);
|
||||
|
||||
clk_name[1] += channel;
|
||||
clk = of_clk_get_by_name(np->parent, clk_name);
|
||||
if (IS_ERR(clk))
|
||||
clk = of_clk_get_by_name(np->parent, "t0_clk");
|
||||
if (IS_ERR(clk))
|
||||
return PTR_ERR(clk);
|
||||
|
||||
match = of_match_node(atmel_tcb_of_match, np->parent);
|
||||
config = match->data;
|
||||
|
||||
if (config->has_gclk) {
|
||||
gclk = of_clk_get_by_name(np->parent, "gclk");
|
||||
if (IS_ERR(gclk))
|
||||
return PTR_ERR(gclk);
|
||||
}
|
||||
|
||||
tcbpwm = devm_kzalloc(&pdev->dev, sizeof(*tcbpwm), GFP_KERNEL);
|
||||
if (tcbpwm == NULL) {
|
||||
err = -ENOMEM;
|
||||
goto err_free_tc;
|
||||
goto err_slow_clk;
|
||||
}
|
||||
|
||||
tcbpwm->chip.dev = &pdev->dev;
|
||||
@@ -410,11 +456,16 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
|
||||
tcbpwm->chip.of_pwm_n_cells = 3;
|
||||
tcbpwm->chip.base = -1;
|
||||
tcbpwm->chip.npwm = NPWM;
|
||||
tcbpwm->tc = tc;
|
||||
tcbpwm->channel = channel;
|
||||
tcbpwm->regmap = regmap;
|
||||
tcbpwm->clk = clk;
|
||||
tcbpwm->gclk = gclk;
|
||||
tcbpwm->slow_clk = slow_clk;
|
||||
tcbpwm->width = config->counter_width;
|
||||
|
||||
err = clk_prepare_enable(tc->slow_clk);
|
||||
err = clk_prepare_enable(slow_clk);
|
||||
if (err)
|
||||
goto err_free_tc;
|
||||
goto err_slow_clk;
|
||||
|
||||
spin_lock_init(&tcbpwm->lock);
|
||||
|
||||
@@ -427,10 +478,10 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
|
||||
return 0;
|
||||
|
||||
err_disable_clk:
|
||||
clk_disable_unprepare(tcbpwm->tc->slow_clk);
|
||||
clk_disable_unprepare(tcbpwm->slow_clk);
|
||||
|
||||
err_free_tc:
|
||||
atmel_tc_free(tc);
|
||||
err_slow_clk:
|
||||
clk_put(slow_clk);
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -440,14 +491,14 @@ static int atmel_tcb_pwm_remove(struct platform_device *pdev)
|
||||
struct atmel_tcb_pwm_chip *tcbpwm = platform_get_drvdata(pdev);
|
||||
int err;
|
||||
|
||||
clk_disable_unprepare(tcbpwm->tc->slow_clk);
|
||||
clk_disable_unprepare(tcbpwm->slow_clk);
|
||||
clk_put(tcbpwm->slow_clk);
|
||||
clk_put(tcbpwm->clk);
|
||||
|
||||
err = pwmchip_remove(&tcbpwm->chip);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
atmel_tc_free(tcbpwm->tc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -461,38 +512,33 @@ MODULE_DEVICE_TABLE(of, atmel_tcb_pwm_dt_ids);
|
||||
static int atmel_tcb_pwm_suspend(struct device *dev)
|
||||
{
|
||||
struct atmel_tcb_pwm_chip *tcbpwm = dev_get_drvdata(dev);
|
||||
void __iomem *base = tcbpwm->tc->regs;
|
||||
int i;
|
||||
struct atmel_tcb_channel *chan = &tcbpwm->bkup;
|
||||
unsigned int channel = tcbpwm->channel;
|
||||
|
||||
for (i = 0; i < (NPWM / 2); i++) {
|
||||
struct atmel_tcb_channel *chan = &tcbpwm->bkup[i];
|
||||
regmap_read(tcbpwm->regmap, ATMEL_TC_REG(channel, CMR), &chan->cmr);
|
||||
regmap_read(tcbpwm->regmap, ATMEL_TC_REG(channel, RA), &chan->ra);
|
||||
regmap_read(tcbpwm->regmap, ATMEL_TC_REG(channel, RB), &chan->rb);
|
||||
regmap_read(tcbpwm->regmap, ATMEL_TC_REG(channel, RC), &chan->rc);
|
||||
|
||||
chan->cmr = readl(base + ATMEL_TC_REG(i, CMR));
|
||||
chan->ra = readl(base + ATMEL_TC_REG(i, RA));
|
||||
chan->rb = readl(base + ATMEL_TC_REG(i, RB));
|
||||
chan->rc = readl(base + ATMEL_TC_REG(i, RC));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int atmel_tcb_pwm_resume(struct device *dev)
|
||||
{
|
||||
struct atmel_tcb_pwm_chip *tcbpwm = dev_get_drvdata(dev);
|
||||
void __iomem *base = tcbpwm->tc->regs;
|
||||
int i;
|
||||
struct atmel_tcb_channel *chan = &tcbpwm->bkup;
|
||||
unsigned int channel = tcbpwm->channel;
|
||||
|
||||
for (i = 0; i < (NPWM / 2); i++) {
|
||||
struct atmel_tcb_channel *chan = &tcbpwm->bkup[i];
|
||||
regmap_write(tcbpwm->regmap, ATMEL_TC_REG(channel, CMR), chan->cmr);
|
||||
regmap_write(tcbpwm->regmap, ATMEL_TC_REG(channel, RA), chan->ra);
|
||||
regmap_write(tcbpwm->regmap, ATMEL_TC_REG(channel, RB), chan->rb);
|
||||
regmap_write(tcbpwm->regmap, ATMEL_TC_REG(channel, RC), chan->rc);
|
||||
|
||||
if (chan->enabled)
|
||||
regmap_write(tcbpwm->regmap,
|
||||
ATMEL_TC_CLKEN | ATMEL_TC_SWTRG,
|
||||
ATMEL_TC_REG(channel, CCR));
|
||||
|
||||
writel(chan->cmr, base + ATMEL_TC_REG(i, CMR));
|
||||
writel(chan->ra, base + ATMEL_TC_REG(i, RA));
|
||||
writel(chan->rb, base + ATMEL_TC_REG(i, RB));
|
||||
writel(chan->rc, base + ATMEL_TC_REG(i, RC));
|
||||
if (chan->enabled) {
|
||||
writel(ATMEL_TC_CLKEN | ATMEL_TC_SWTRG,
|
||||
base + ATMEL_TC_REG(i, CCR));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -401,7 +401,6 @@ MODULE_DEVICE_TABLE(of, atmel_pwm_dt_ids);
|
||||
static int atmel_pwm_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct atmel_pwm_chip *atmel_pwm;
|
||||
struct resource *res;
|
||||
int ret;
|
||||
|
||||
atmel_pwm = devm_kzalloc(&pdev->dev, sizeof(*atmel_pwm), GFP_KERNEL);
|
||||
@@ -412,8 +411,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
|
||||
atmel_pwm->data = of_device_get_match_data(&pdev->dev);
|
||||
atmel_pwm->updated_pwms = 0;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
atmel_pwm->base = devm_ioremap_resource(&pdev->dev, res);
|
||||
atmel_pwm->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(atmel_pwm->base))
|
||||
return PTR_ERR(atmel_pwm->base);
|
||||
|
||||
|
||||
@@ -197,7 +197,6 @@ static const struct pwm_ops iproc_pwm_ops = {
|
||||
static int iproc_pwmc_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct iproc_pwmc *ip;
|
||||
struct resource *res;
|
||||
unsigned int i;
|
||||
u32 value;
|
||||
int ret;
|
||||
@@ -215,8 +214,7 @@ static int iproc_pwmc_probe(struct platform_device *pdev)
|
||||
ip->chip.of_xlate = of_pwm_xlate_with_flags;
|
||||
ip->chip.of_pwm_n_cells = 3;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
ip->base = devm_ioremap_resource(&pdev->dev, res);
|
||||
ip->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(ip->base))
|
||||
return PTR_ERR(ip->base);
|
||||
|
||||
|
||||
@@ -259,7 +259,6 @@ static const struct pwm_ops kona_pwm_ops = {
|
||||
static int kona_pwmc_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct kona_pwmc *kp;
|
||||
struct resource *res;
|
||||
unsigned int chan;
|
||||
unsigned int value = 0;
|
||||
int ret = 0;
|
||||
@@ -277,8 +276,7 @@ static int kona_pwmc_probe(struct platform_device *pdev)
|
||||
kp->chip.of_xlate = of_pwm_xlate_with_flags;
|
||||
kp->chip.of_pwm_n_cells = 3;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
kp->base = devm_ioremap_resource(&pdev->dev, res);
|
||||
kp->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(kp->base))
|
||||
return PTR_ERR(kp->base);
|
||||
|
||||
|
||||
@@ -58,13 +58,15 @@ static void bcm2835_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
writel(value, pc->base + PWM_CONTROL);
|
||||
}
|
||||
|
||||
static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
int duty_ns, int period_ns)
|
||||
static int bcm2835_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
const struct pwm_state *state)
|
||||
{
|
||||
|
||||
struct bcm2835_pwm *pc = to_bcm2835_pwm(chip);
|
||||
unsigned long rate = clk_get_rate(pc->clk);
|
||||
unsigned long long period;
|
||||
unsigned long scaler;
|
||||
u32 period;
|
||||
u32 val;
|
||||
|
||||
if (!rate) {
|
||||
dev_err(pc->dev, "failed to get clock rate\n");
|
||||
@@ -72,54 +74,34 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
}
|
||||
|
||||
scaler = DIV_ROUND_CLOSEST(NSEC_PER_SEC, rate);
|
||||
period = DIV_ROUND_CLOSEST(period_ns, scaler);
|
||||
/* set period */
|
||||
period = DIV_ROUND_CLOSEST_ULL(state->period, scaler);
|
||||
|
||||
if (period < PERIOD_MIN)
|
||||
/* dont accept a period that is too small or has been truncated */
|
||||
if ((period < PERIOD_MIN) || (period > U32_MAX))
|
||||
return -EINVAL;
|
||||
|
||||
writel(DIV_ROUND_CLOSEST(duty_ns, scaler),
|
||||
pc->base + DUTY(pwm->hwpwm));
|
||||
writel(period, pc->base + PERIOD(pwm->hwpwm));
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* set duty cycle */
|
||||
val = DIV_ROUND_CLOSEST_ULL(state->duty_cycle, scaler);
|
||||
writel(val, pc->base + DUTY(pwm->hwpwm));
|
||||
|
||||
static int bcm2835_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
{
|
||||
struct bcm2835_pwm *pc = to_bcm2835_pwm(chip);
|
||||
u32 value;
|
||||
/* set polarity */
|
||||
val = readl(pc->base + PWM_CONTROL);
|
||||
|
||||
value = readl(pc->base + PWM_CONTROL);
|
||||
value |= PWM_ENABLE << PWM_CONTROL_SHIFT(pwm->hwpwm);
|
||||
writel(value, pc->base + PWM_CONTROL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void bcm2835_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
|
||||
{
|
||||
struct bcm2835_pwm *pc = to_bcm2835_pwm(chip);
|
||||
u32 value;
|
||||
|
||||
value = readl(pc->base + PWM_CONTROL);
|
||||
value &= ~(PWM_ENABLE << PWM_CONTROL_SHIFT(pwm->hwpwm));
|
||||
writel(value, pc->base + PWM_CONTROL);
|
||||
}
|
||||
|
||||
static int bcm2835_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
enum pwm_polarity polarity)
|
||||
{
|
||||
struct bcm2835_pwm *pc = to_bcm2835_pwm(chip);
|
||||
u32 value;
|
||||
|
||||
value = readl(pc->base + PWM_CONTROL);
|
||||
|
||||
if (polarity == PWM_POLARITY_NORMAL)
|
||||
value &= ~(PWM_POLARITY << PWM_CONTROL_SHIFT(pwm->hwpwm));
|
||||
if (state->polarity == PWM_POLARITY_NORMAL)
|
||||
val &= ~(PWM_POLARITY << PWM_CONTROL_SHIFT(pwm->hwpwm));
|
||||
else
|
||||
value |= PWM_POLARITY << PWM_CONTROL_SHIFT(pwm->hwpwm);
|
||||
val |= PWM_POLARITY << PWM_CONTROL_SHIFT(pwm->hwpwm);
|
||||
|
||||
writel(value, pc->base + PWM_CONTROL);
|
||||
/* enable/disable */
|
||||
if (state->enabled)
|
||||
val |= PWM_ENABLE << PWM_CONTROL_SHIFT(pwm->hwpwm);
|
||||
else
|
||||
val &= ~(PWM_ENABLE << PWM_CONTROL_SHIFT(pwm->hwpwm));
|
||||
|
||||
writel(val, pc->base + PWM_CONTROL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -127,17 +109,13 @@ static int bcm2835_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
static const struct pwm_ops bcm2835_pwm_ops = {
|
||||
.request = bcm2835_pwm_request,
|
||||
.free = bcm2835_pwm_free,
|
||||
.config = bcm2835_pwm_config,
|
||||
.enable = bcm2835_pwm_enable,
|
||||
.disable = bcm2835_pwm_disable,
|
||||
.set_polarity = bcm2835_set_polarity,
|
||||
.apply = bcm2835_pwm_apply,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static int bcm2835_pwm_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct bcm2835_pwm *pc;
|
||||
struct resource *res;
|
||||
int ret;
|
||||
|
||||
pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
|
||||
@@ -146,8 +124,7 @@ static int bcm2835_pwm_probe(struct platform_device *pdev)
|
||||
|
||||
pc->dev = &pdev->dev;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
pc->base = devm_ioremap_resource(&pdev->dev, res);
|
||||
pc->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(pc->base))
|
||||
return PTR_ERR(pc->base);
|
||||
|
||||
|
||||
@@ -186,15 +186,13 @@ MODULE_DEVICE_TABLE(of, berlin_pwm_match);
|
||||
static int berlin_pwm_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct berlin_pwm_chip *pwm;
|
||||
struct resource *res;
|
||||
int ret;
|
||||
|
||||
pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
|
||||
if (!pwm)
|
||||
return -ENOMEM;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
pwm->base = devm_ioremap_resource(&pdev->dev, res);
|
||||
pwm->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(pwm->base))
|
||||
return PTR_ERR(pwm->base);
|
||||
|
||||
|
||||
@@ -234,7 +234,6 @@ MODULE_DEVICE_TABLE(of, brcmstb_pwm_of_match);
|
||||
static int brcmstb_pwm_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct brcmstb_pwm *p;
|
||||
struct resource *res;
|
||||
int ret;
|
||||
|
||||
p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
|
||||
@@ -262,8 +261,7 @@ static int brcmstb_pwm_probe(struct platform_device *pdev)
|
||||
p->chip.base = -1;
|
||||
p->chip.npwm = 2;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
p->base = devm_ioremap_resource(&pdev->dev, res);
|
||||
p->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(p->base)) {
|
||||
ret = PTR_ERR(p->base);
|
||||
goto out_clk;
|
||||
|
||||
@@ -113,14 +113,12 @@ static struct pwm_device *clps711x_pwm_xlate(struct pwm_chip *chip,
|
||||
static int clps711x_pwm_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct clps711x_chip *priv;
|
||||
struct resource *res;
|
||||
|
||||
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return -ENOMEM;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
priv->pmpcon = devm_ioremap_resource(&pdev->dev, res);
|
||||
priv->pmpcon = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(priv->pmpcon))
|
||||
return PTR_ERR(priv->pmpcon);
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ static int crc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
}
|
||||
|
||||
if (state->polarity != PWM_POLARITY_NORMAL)
|
||||
return -EOPNOTSUPP;
|
||||
return -EINVAL;
|
||||
|
||||
if (pwm_is_enabled(pwm) && !state->enabled) {
|
||||
err = regmap_write(crc_pwm->regmap, BACKLIGHT_EN, 0);
|
||||
|
||||
319
drivers/pwm/pwm-dwc.c
Normal file
319
drivers/pwm/pwm-dwc.c
Normal file
@@ -0,0 +1,319 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* DesignWare PWM Controller driver
|
||||
*
|
||||
* Copyright (C) 2018-2020 Intel Corporation
|
||||
*
|
||||
* Author: Felipe Balbi (Intel)
|
||||
* Author: Jarkko Nikula <jarkko.nikula@linux.intel.com>
|
||||
* Author: Raymond Tan <raymond.tan@intel.com>
|
||||
*
|
||||
* Limitations:
|
||||
* - The hardware cannot generate a 0 % or 100 % duty cycle. Both high and low
|
||||
* periods are one or more input clock periods long.
|
||||
*/
|
||||
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/export.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/pm_runtime.h>
|
||||
#include <linux/pwm.h>
|
||||
|
||||
#define DWC_TIM_LD_CNT(n) ((n) * 0x14)
|
||||
#define DWC_TIM_LD_CNT2(n) (((n) * 4) + 0xb0)
|
||||
#define DWC_TIM_CUR_VAL(n) (((n) * 0x14) + 0x04)
|
||||
#define DWC_TIM_CTRL(n) (((n) * 0x14) + 0x08)
|
||||
#define DWC_TIM_EOI(n) (((n) * 0x14) + 0x0c)
|
||||
#define DWC_TIM_INT_STS(n) (((n) * 0x14) + 0x10)
|
||||
|
||||
#define DWC_TIMERS_INT_STS 0xa0
|
||||
#define DWC_TIMERS_EOI 0xa4
|
||||
#define DWC_TIMERS_RAW_INT_STS 0xa8
|
||||
#define DWC_TIMERS_COMP_VERSION 0xac
|
||||
|
||||
#define DWC_TIMERS_TOTAL 8
|
||||
#define DWC_CLK_PERIOD_NS 10
|
||||
|
||||
/* Timer Control Register */
|
||||
#define DWC_TIM_CTRL_EN BIT(0)
|
||||
#define DWC_TIM_CTRL_MODE BIT(1)
|
||||
#define DWC_TIM_CTRL_MODE_FREE (0 << 1)
|
||||
#define DWC_TIM_CTRL_MODE_USER (1 << 1)
|
||||
#define DWC_TIM_CTRL_INT_MASK BIT(2)
|
||||
#define DWC_TIM_CTRL_PWM BIT(3)
|
||||
|
||||
struct dwc_pwm_ctx {
|
||||
u32 cnt;
|
||||
u32 cnt2;
|
||||
u32 ctrl;
|
||||
};
|
||||
|
||||
struct dwc_pwm {
|
||||
struct pwm_chip chip;
|
||||
void __iomem *base;
|
||||
struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL];
|
||||
};
|
||||
#define to_dwc_pwm(p) (container_of((p), struct dwc_pwm, chip))
|
||||
|
||||
static inline u32 dwc_pwm_readl(struct dwc_pwm *dwc, u32 offset)
|
||||
{
|
||||
return readl(dwc->base + offset);
|
||||
}
|
||||
|
||||
static inline void dwc_pwm_writel(struct dwc_pwm *dwc, u32 value, u32 offset)
|
||||
{
|
||||
writel(value, dwc->base + offset);
|
||||
}
|
||||
|
||||
static void __dwc_pwm_set_enable(struct dwc_pwm *dwc, int pwm, int enabled)
|
||||
{
|
||||
u32 reg;
|
||||
|
||||
reg = dwc_pwm_readl(dwc, DWC_TIM_CTRL(pwm));
|
||||
|
||||
if (enabled)
|
||||
reg |= DWC_TIM_CTRL_EN;
|
||||
else
|
||||
reg &= ~DWC_TIM_CTRL_EN;
|
||||
|
||||
dwc_pwm_writel(dwc, reg, DWC_TIM_CTRL(pwm));
|
||||
}
|
||||
|
||||
static int __dwc_pwm_configure_timer(struct dwc_pwm *dwc,
|
||||
struct pwm_device *pwm,
|
||||
const struct pwm_state *state)
|
||||
{
|
||||
u64 tmp;
|
||||
u32 ctrl;
|
||||
u32 high;
|
||||
u32 low;
|
||||
|
||||
/*
|
||||
* Calculate width of low and high period in terms of input clock
|
||||
* periods and check are the result within HW limits between 1 and
|
||||
* 2^32 periods.
|
||||
*/
|
||||
tmp = DIV_ROUND_CLOSEST_ULL(state->duty_cycle, DWC_CLK_PERIOD_NS);
|
||||
if (tmp < 1 || tmp > (1ULL << 32))
|
||||
return -ERANGE;
|
||||
low = tmp - 1;
|
||||
|
||||
tmp = DIV_ROUND_CLOSEST_ULL(state->period - state->duty_cycle,
|
||||
DWC_CLK_PERIOD_NS);
|
||||
if (tmp < 1 || tmp > (1ULL << 32))
|
||||
return -ERANGE;
|
||||
high = tmp - 1;
|
||||
|
||||
/*
|
||||
* Specification says timer usage flow is to disable timer, then
|
||||
* program it followed by enable. It also says Load Count is loaded
|
||||
* into timer after it is enabled - either after a disable or
|
||||
* a reset. Based on measurements it happens also without disable
|
||||
* whenever Load Count is updated. But follow the specification.
|
||||
*/
|
||||
__dwc_pwm_set_enable(dwc, pwm->hwpwm, false);
|
||||
|
||||
/*
|
||||
* Write Load Count and Load Count 2 registers. Former defines the
|
||||
* width of low period and latter the width of high period in terms
|
||||
* multiple of input clock periods:
|
||||
* Width = ((Count + 1) * input clock period).
|
||||
*/
|
||||
dwc_pwm_writel(dwc, low, DWC_TIM_LD_CNT(pwm->hwpwm));
|
||||
dwc_pwm_writel(dwc, high, DWC_TIM_LD_CNT2(pwm->hwpwm));
|
||||
|
||||
/*
|
||||
* Set user-defined mode, timer reloads from Load Count registers
|
||||
* when it counts down to 0.
|
||||
* Set PWM mode, it makes output to toggle and width of low and high
|
||||
* periods are set by Load Count registers.
|
||||
*/
|
||||
ctrl = DWC_TIM_CTRL_MODE_USER | DWC_TIM_CTRL_PWM;
|
||||
dwc_pwm_writel(dwc, ctrl, DWC_TIM_CTRL(pwm->hwpwm));
|
||||
|
||||
/*
|
||||
* Enable timer. Output starts from low period.
|
||||
*/
|
||||
__dwc_pwm_set_enable(dwc, pwm->hwpwm, state->enabled);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dwc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
const struct pwm_state *state)
|
||||
{
|
||||
struct dwc_pwm *dwc = to_dwc_pwm(chip);
|
||||
|
||||
if (state->polarity != PWM_POLARITY_INVERSED)
|
||||
return -EINVAL;
|
||||
|
||||
if (state->enabled) {
|
||||
if (!pwm->state.enabled)
|
||||
pm_runtime_get_sync(chip->dev);
|
||||
return __dwc_pwm_configure_timer(dwc, pwm, state);
|
||||
} else {
|
||||
if (pwm->state.enabled) {
|
||||
__dwc_pwm_set_enable(dwc, pwm->hwpwm, false);
|
||||
pm_runtime_put_sync(chip->dev);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||
struct pwm_state *state)
|
||||
{
|
||||
struct dwc_pwm *dwc = to_dwc_pwm(chip);
|
||||
u64 duty, period;
|
||||
|
||||
pm_runtime_get_sync(chip->dev);
|
||||
|
||||
state->enabled = !!(dwc_pwm_readl(dwc,
|
||||
DWC_TIM_CTRL(pwm->hwpwm)) & DWC_TIM_CTRL_EN);
|
||||
|
||||
duty = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT(pwm->hwpwm));
|
||||
duty += 1;
|
||||
duty *= DWC_CLK_PERIOD_NS;
|
||||
state->duty_cycle = duty;
|
||||
|
||||
period = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT2(pwm->hwpwm));
|
||||
period += 1;
|
||||
period *= DWC_CLK_PERIOD_NS;
|
||||
period += duty;
|
||||
state->period = period;
|
||||
|
||||
state->polarity = PWM_POLARITY_INVERSED;
|
||||
|
||||
pm_runtime_put_sync(chip->dev);
|
||||
}
|
||||
|
||||
static const struct pwm_ops dwc_pwm_ops = {
|
||||
.apply = dwc_pwm_apply,
|
||||
.get_state = dwc_pwm_get_state,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)
|
||||
{
|
||||
struct device *dev = &pci->dev;
|
||||
struct dwc_pwm *dwc;
|
||||
int ret;
|
||||
|
||||
dwc = devm_kzalloc(&pci->dev, sizeof(*dwc), GFP_KERNEL);
|
||||
if (!dwc)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = pcim_enable_device(pci);
|
||||
if (ret) {
|
||||
dev_err(&pci->dev,
|
||||
"Failed to enable device (%pe)\n", ERR_PTR(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
pci_set_master(pci);
|
||||
|
||||
ret = pcim_iomap_regions(pci, BIT(0), pci_name(pci));
|
||||
if (ret) {
|
||||
dev_err(&pci->dev,
|
||||
"Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
dwc->base = pcim_iomap_table(pci)[0];
|
||||
if (!dwc->base) {
|
||||
dev_err(&pci->dev, "Base address missing\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
pci_set_drvdata(pci, dwc);
|
||||
|
||||
dwc->chip.dev = dev;
|
||||
dwc->chip.ops = &dwc_pwm_ops;
|
||||
dwc->chip.npwm = DWC_TIMERS_TOTAL;
|
||||
dwc->chip.base = -1;
|
||||
|
||||
ret = pwmchip_add(&dwc->chip);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
pm_runtime_put(dev);
|
||||
pm_runtime_allow(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dwc_pwm_remove(struct pci_dev *pci)
|
||||
{
|
||||
struct dwc_pwm *dwc = pci_get_drvdata(pci);
|
||||
|
||||
pm_runtime_forbid(&pci->dev);
|
||||
pm_runtime_get_noresume(&pci->dev);
|
||||
|
||||
pwmchip_remove(&dwc->chip);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
static int dwc_pwm_suspend(struct device *dev)
|
||||
{
|
||||
struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
|
||||
struct dwc_pwm *dwc = pci_get_drvdata(pdev);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < DWC_TIMERS_TOTAL; i++) {
|
||||
if (dwc->chip.pwms[i].state.enabled) {
|
||||
dev_err(dev, "PWM %u in use by consumer (%s)\n",
|
||||
i, dwc->chip.pwms[i].label);
|
||||
return -EBUSY;
|
||||
}
|
||||
dwc->ctx[i].cnt = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT(i));
|
||||
dwc->ctx[i].cnt2 = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT2(i));
|
||||
dwc->ctx[i].ctrl = dwc_pwm_readl(dwc, DWC_TIM_CTRL(i));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dwc_pwm_resume(struct device *dev)
|
||||
{
|
||||
struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
|
||||
struct dwc_pwm *dwc = pci_get_drvdata(pdev);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < DWC_TIMERS_TOTAL; i++) {
|
||||
dwc_pwm_writel(dwc, dwc->ctx[i].cnt, DWC_TIM_LD_CNT(i));
|
||||
dwc_pwm_writel(dwc, dwc->ctx[i].cnt2, DWC_TIM_LD_CNT2(i));
|
||||
dwc_pwm_writel(dwc, dwc->ctx[i].ctrl, DWC_TIM_CTRL(i));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static SIMPLE_DEV_PM_OPS(dwc_pwm_pm_ops, dwc_pwm_suspend, dwc_pwm_resume);
|
||||
|
||||
static const struct pci_device_id dwc_pwm_id_table[] = {
|
||||
{ PCI_VDEVICE(INTEL, 0x4bb7) }, /* Elkhart Lake */
|
||||
{ } /* Terminating Entry */
|
||||
};
|
||||
MODULE_DEVICE_TABLE(pci, dwc_pwm_id_table);
|
||||
|
||||
static struct pci_driver dwc_pwm_driver = {
|
||||
.name = "pwm-dwc",
|
||||
.probe = dwc_pwm_probe,
|
||||
.remove = dwc_pwm_remove,
|
||||
.id_table = dwc_pwm_id_table,
|
||||
.driver = {
|
||||
.pm = &dwc_pwm_pm_ops,
|
||||
},
|
||||
};
|
||||
|
||||
module_pci_driver(dwc_pwm_driver);
|
||||
|
||||
MODULE_AUTHOR("Felipe Balbi (Intel)");
|
||||
MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@linux.intel.com>");
|
||||
MODULE_AUTHOR("Raymond Tan <raymond.tan@intel.com>");
|
||||
MODULE_DESCRIPTION("DesignWare PWM Controller");
|
||||
MODULE_LICENSE("GPL");
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user