Commit aeb15291 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'pwm/for-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux

Pull pwm updates from Uwe Kleine-König:
 "This contains the usual amount of driver and device tree changes.
  Additionally there is a big rework of how pwm lowlevel drivers are
  registered to prepare adding character device support.

  Thanks to Dharma Balasubiramani, Dong Aisheng, Duje Mihanović, Jerome
  Brunet, Raag Jadav and Rafał Miłecki for their contributions. And
  sorry for those who still need some patience because I didn't manage
  to empty my review queue"

* tag 'pwm/for-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux: (185 commits)
  pwm: imx-tpm: fix probe crash due to access registers without clock
  pwm: meson: generalize 4 inputs clock on meson8 pwm type
  dt-bindings: pwm: amlogic: Add a new binding for meson8 pwm types
  dt-bindings: pwm: amlogic: fix s4 bindings
  pwm: dwc: simplify error handling
  pwm: dwc: Add 16 channel support for Intel Elkhart Lake
  pwm: dwc: drop redundant error check
  staging: greybus: pwm: Make use of devm_pwmchip_alloc() function
  staging: greybus: pwm: Rework how the number of PWM lines is determined
  staging: greybus: pwm: Drop unused gb_connection_set_data()
  staging: greybus: pwm: Rely on pwm framework to pass a valid hwpwm
  staging: greybus: pwm: Make use of pwmchip_parent() accessor
  staging: greybus: pwm: Change prototype of helpers to prepare further changes
  leds: qcom-lpg: Make use of devm_pwmchip_alloc() function
  drm/bridge: ti-sn65dsi86: Make use of devm_pwmchip_alloc() function
  drm/bridge: ti-sn65dsi86: Make use of pwmchip_parent() accessor
  gpio: mvebu: Make use of devm_pwmchip_alloc() function
  pwm: xilinx: Make use of devm_pwmchip_alloc() function
  pwm: xilinx: Prepare removing pwm_chip from driver data
  pwm: vt8500: Make use of devm_pwmchip_alloc() function
  ...
parents aa7d6513 dd6c6d57
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/pwm/atmel,hlcdc-pwm.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Atmel's HLCDC's PWM controller
maintainers:
- Nicolas Ferre <nicolas.ferre@microchip.com>
- Alexandre Belloni <alexandre.belloni@bootlin.com>
- Claudiu Beznea <claudiu.beznea@tuxon.dev>
description:
The LCDC integrates a Pulse Width Modulation (PWM) Controller. This block
generates the LCD contrast control signal (LCD_PWM) that controls the
display's contrast by software. LCDC_PWM is an 8-bit PWM signal that can be
converted to an analog voltage with a simple passive filter. LCD display
panels have different backlight specifications in terms of minimum/maximum
values for PWM frequency. If the LCDC PWM frequency range does not match the
LCD display panel, it is possible to use the standalone PWM Controller to
drive the backlight.
properties:
compatible:
const: atmel,hlcdc-pwm
"#pwm-cells":
const: 3
required:
- compatible
- "#pwm-cells"
additionalProperties: false
Device-Tree bindings for Atmel's HLCDC (High-end LCD Controller) PWM driver
The Atmel HLCDC PWM is subdevice of the HLCDC MFD device.
See ../mfd/atmel-hlcdc.txt for more details.
Required properties:
- compatible: value should be one of the following:
"atmel,hlcdc-pwm"
- pinctr-names: the pin control state names. Should contain "default".
- pinctrl-0: should contain the pinctrl states described by pinctrl
default.
- #pwm-cells: should be set to 3. This PWM chip use the default 3 cells
bindings defined in pwm.yaml in this directory.
Example:
hlcdc: hlcdc@f0030000 {
compatible = "atmel,sama5d3-hlcdc";
reg = <0xf0030000 0x2000>;
clocks = <&lcdc_clk>, <&lcdck>, <&clk32k>;
clock-names = "periph_clk","sys_clk", "slow_clk";
hlcdc_pwm: hlcdc-pwm {
compatible = "atmel,hlcdc-pwm";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_lcd_pwm>;
#pwm-cells = <3>;
};
};
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/pwm/marvell,pxa-pwm.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Marvell PXA PWM
maintainers:
- Duje Mihanović <duje.mihanovic@skole.hr>
allOf:
- $ref: pwm.yaml#
properties:
compatible:
enum:
- marvell,pxa250-pwm
- marvell,pxa270-pwm
- marvell,pxa168-pwm
- marvell,pxa910-pwm
reg:
# Length should be 0x10
maxItems: 1
"#pwm-cells":
# Used for specifying the period length in nanoseconds
const: 1
clocks:
maxItems: 1
required:
- compatible
- reg
- "#pwm-cells"
- clocks
additionalProperties: false
examples:
- |
#include <dt-bindings/clock/pxa-clock.h>
pwm0: pwm@40b00000 {
compatible = "marvell,pxa250-pwm";
reg = <0x40b00000 0x10>;
#pwm-cells = <1>;
clocks = <&clks CLK_PWM0>;
};
...@@ -24,6 +24,7 @@ properties: ...@@ -24,6 +24,7 @@ properties:
- mediatek,mt7629-pwm - mediatek,mt7629-pwm
- mediatek,mt7981-pwm - mediatek,mt7981-pwm
- mediatek,mt7986-pwm - mediatek,mt7986-pwm
- mediatek,mt7988-pwm
- mediatek,mt8183-pwm - mediatek,mt8183-pwm
- mediatek,mt8365-pwm - mediatek,mt8365-pwm
- mediatek,mt8516-pwm - mediatek,mt8516-pwm
......
...@@ -9,9 +9,6 @@ title: Amlogic PWM ...@@ -9,9 +9,6 @@ title: Amlogic PWM
maintainers: maintainers:
- Heiner Kallweit <hkallweit1@gmail.com> - Heiner Kallweit <hkallweit1@gmail.com>
allOf:
- $ref: pwm.yaml#
properties: properties:
compatible: compatible:
oneOf: oneOf:
...@@ -24,24 +21,74 @@ properties: ...@@ -24,24 +21,74 @@ properties:
- amlogic,meson-g12a-ee-pwm - amlogic,meson-g12a-ee-pwm
- amlogic,meson-g12a-ao-pwm-ab - amlogic,meson-g12a-ao-pwm-ab
- amlogic,meson-g12a-ao-pwm-cd - amlogic,meson-g12a-ao-pwm-cd
- amlogic,meson-s4-pwm deprecated: true
- items: - items:
- const: amlogic,meson-gx-pwm - const: amlogic,meson-gx-pwm
- const: amlogic,meson-gxbb-pwm - const: amlogic,meson-gxbb-pwm
deprecated: true
- items: - items:
- const: amlogic,meson-gx-ao-pwm - const: amlogic,meson-gx-ao-pwm
- const: amlogic,meson-gxbb-ao-pwm - const: amlogic,meson-gxbb-ao-pwm
deprecated: true
- items: - items:
- const: amlogic,meson8-pwm - const: amlogic,meson8-pwm
- const: amlogic,meson8b-pwm - const: amlogic,meson8b-pwm
deprecated: true
- enum:
- amlogic,meson8-pwm-v2
- amlogic,meson-s4-pwm
- items:
- enum:
- amlogic,meson8b-pwm-v2
- amlogic,meson-gxbb-pwm-v2
- amlogic,meson-axg-pwm-v2
- amlogic,meson-g12-pwm-v2
- const: amlogic,meson8-pwm-v2
reg: reg:
maxItems: 1 maxItems: 1
clocks: clocks:
minItems: 1
maxItems: 4
clock-names:
minItems: 1 minItems: 1
maxItems: 2 maxItems: 2
"#pwm-cells":
const: 3
required:
- compatible
- reg
allOf:
- $ref: pwm.yaml#
- if:
properties:
compatible:
contains:
enum:
- amlogic,meson8-pwm
- amlogic,meson8b-pwm
- amlogic,meson-gxbb-pwm
- amlogic,meson-gxbb-ao-pwm
- amlogic,meson-axg-ee-pwm
- amlogic,meson-axg-ao-pwm
- amlogic,meson-g12a-ee-pwm
- amlogic,meson-g12a-ao-pwm-ab
- amlogic,meson-g12a-ao-pwm-cd
then:
# Obsolete historic bindings tied to the driver implementation
# The clocks provided here are meant to be matched with the input
# known (hard-coded) in the driver and used to select pwm clock
# source. Currently, the linux driver ignores this.
# This is kept to maintain ABI backward compatibility.
properties:
clocks:
maxItems: 2
clock-names: clock-names:
oneOf: oneOf:
- items: - items:
...@@ -50,12 +97,44 @@ properties: ...@@ -50,12 +97,44 @@ properties:
- const: clkin0 - const: clkin0
- const: clkin1 - const: clkin1
"#pwm-cells": # Newer binding where clock describe the actual clock inputs of the pwm
const: 3 # block. These are necessary but some inputs may be grounded.
- if:
properties:
compatible:
contains:
enum:
- amlogic,meson8-pwm-v2
then:
properties:
clocks:
minItems: 1
items:
- description: input clock 0 of the pwm block
- description: input clock 1 of the pwm block
- description: input clock 2 of the pwm block
- description: input clock 3 of the pwm block
clock-names: false
required:
- clocks
required: # Newer IP block take a single input per channel, instead of 4 inputs
- compatible # for both channels
- reg - if:
properties:
compatible:
contains:
enum:
- amlogic,meson-s4-pwm
then:
properties:
clocks:
items:
- description: input clock of PWM channel A
- description: input clock of PWM channel B
clock-names: false
required:
- clocks
additionalProperties: false additionalProperties: false
...@@ -68,3 +147,17 @@ examples: ...@@ -68,3 +147,17 @@ examples:
clock-names = "clkin0", "clkin1"; clock-names = "clkin0", "clkin1";
#pwm-cells = <3>; #pwm-cells = <3>;
}; };
- |
pwm@2000 {
compatible = "amlogic,meson8-pwm-v2";
reg = <0x1000 0x10>;
clocks = <&xtal>, <0>, <&fdiv4>, <&fdiv5>;
#pwm-cells = <3>;
};
- |
pwm@1000 {
compatible = "amlogic,meson-s4-pwm";
reg = <0x1000 0x10>;
clocks = <&pwm_src_a>, <&pwm_src_b>;
#pwm-cells = <3>;
};
Marvell PWM controller
Required properties:
- compatible: should be one or more of:
- "marvell,pxa250-pwm"
- "marvell,pxa270-pwm"
- "marvell,pxa168-pwm"
- "marvell,pxa910-pwm"
- reg: Physical base address and length of the registers used by the PWM channel
Note that one device instance must be created for each PWM that is used, so the
length covers only the register window for one PWM output, not that of the
entire PWM controller. Currently length is 0x10 for all supported devices.
- #pwm-cells: Should be 1. This cell is used to specify the period in
nanoseconds.
Example PWM device node:
pwm0: pwm@40b00000 {
compatible = "marvell,pxa250-pwm";
reg = <0x40b00000 0x10>;
#pwm-cells = <1>;
};
Example PWM client node:
backlight {
compatible = "pwm-backlight";
pwms = <&pwm0 5000000>;
...
}
...@@ -420,6 +420,7 @@ POWER ...@@ -420,6 +420,7 @@ POWER
devm_reboot_mode_unregister() devm_reboot_mode_unregister()
PWM PWM
devm_pwmchip_alloc()
devm_pwmchip_add() devm_pwmchip_add()
devm_pwm_get() devm_pwm_get()
devm_fwnode_pwm_get() devm_fwnode_pwm_get()
......
...@@ -143,11 +143,12 @@ to implement the pwm_*() functions itself. This means that it's impossible ...@@ -143,11 +143,12 @@ to implement the pwm_*() functions itself. This means that it's impossible
to have multiple PWM drivers in the system. For this reason it's mandatory to have multiple PWM drivers in the system. For this reason it's mandatory
for new drivers to use the generic PWM framework. for new drivers to use the generic PWM framework.
A new PWM controller/chip can be added using pwmchip_add() and removed A new PWM controller/chip can be allocated using pwmchip_alloc(), then
again with pwmchip_remove(). pwmchip_add() takes a filled in struct registered using pwmchip_add() and removed again with pwmchip_remove(). To undo
pwm_chip as argument which provides a description of the PWM chip, the pwmchip_alloc() use pwmchip_put(). pwmchip_add() takes a filled in struct
number of PWM devices provided by the chip and the chip-specific pwm_chip as argument which provides a description of the PWM chip, the number
implementation of the supported PWM operations to the framework. of PWM devices provided by the chip and the chip-specific implementation of the
supported PWM operations to the framework.
When implementing polarity support in a PWM driver, make sure to respect the When implementing polarity support in a PWM driver, make sure to respect the
signal conventions in the PWM framework. By definition, normal polarity signal conventions in the PWM framework. By definition, normal polarity
......
...@@ -99,7 +99,6 @@ struct mvebu_pwm { ...@@ -99,7 +99,6 @@ struct mvebu_pwm {
u32 offset; u32 offset;
unsigned long clk_rate; unsigned long clk_rate;
struct gpio_desc *gpiod; struct gpio_desc *gpiod;
struct pwm_chip chip;
spinlock_t lock; spinlock_t lock;
struct mvebu_gpio_chip *mvchip; struct mvebu_gpio_chip *mvchip;
...@@ -615,7 +614,7 @@ static const struct regmap_config mvebu_gpio_regmap_config = { ...@@ -615,7 +614,7 @@ static const struct regmap_config mvebu_gpio_regmap_config = {
*/ */
static struct mvebu_pwm *to_mvebu_pwm(struct pwm_chip *chip) static struct mvebu_pwm *to_mvebu_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct mvebu_pwm, chip); return pwmchip_get_drvdata(chip);
} }
static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
...@@ -789,6 +788,7 @@ static int mvebu_pwm_probe(struct platform_device *pdev, ...@@ -789,6 +788,7 @@ static int mvebu_pwm_probe(struct platform_device *pdev,
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct mvebu_pwm *mvpwm; struct mvebu_pwm *mvpwm;
struct pwm_chip *chip;
void __iomem *base; void __iomem *base;
u32 offset; u32 offset;
u32 set; u32 set;
...@@ -813,9 +813,11 @@ static int mvebu_pwm_probe(struct platform_device *pdev, ...@@ -813,9 +813,11 @@ static int mvebu_pwm_probe(struct platform_device *pdev,
if (IS_ERR(mvchip->clk)) if (IS_ERR(mvchip->clk))
return PTR_ERR(mvchip->clk); return PTR_ERR(mvchip->clk);
mvpwm = devm_kzalloc(dev, sizeof(struct mvebu_pwm), GFP_KERNEL); chip = devm_pwmchip_alloc(dev, mvchip->chip.ngpio, sizeof(*mvpwm));
if (!mvpwm) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
mvpwm = to_mvebu_pwm(chip);
mvchip->mvpwm = mvpwm; mvchip->mvpwm = mvpwm;
mvpwm->mvchip = mvchip; mvpwm->mvchip = mvchip;
mvpwm->offset = offset; mvpwm->offset = offset;
...@@ -868,13 +870,11 @@ static int mvebu_pwm_probe(struct platform_device *pdev, ...@@ -868,13 +870,11 @@ static int mvebu_pwm_probe(struct platform_device *pdev,
return -EINVAL; return -EINVAL;
} }
mvpwm->chip.dev = dev; chip->ops = &mvebu_pwm_ops;
mvpwm->chip.ops = &mvebu_pwm_ops;
mvpwm->chip.npwm = mvchip->chip.ngpio;
spin_lock_init(&mvpwm->lock); spin_lock_init(&mvpwm->lock);
return devm_pwmchip_add(dev, &mvpwm->chip); return devm_pwmchip_add(dev, chip);
} }
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
......
...@@ -197,7 +197,7 @@ struct ti_sn65dsi86 { ...@@ -197,7 +197,7 @@ struct ti_sn65dsi86 {
DECLARE_BITMAP(gchip_output, SN_NUM_GPIOS); DECLARE_BITMAP(gchip_output, SN_NUM_GPIOS);
#endif #endif
#if defined(CONFIG_PWM) #if defined(CONFIG_PWM)
struct pwm_chip pchip; struct pwm_chip *pchip;
bool pwm_enabled; bool pwm_enabled;
atomic_t pwm_pin_busy; atomic_t pwm_pin_busy;
#endif #endif
...@@ -1374,7 +1374,7 @@ static void ti_sn_pwm_pin_release(struct ti_sn65dsi86 *pdata) ...@@ -1374,7 +1374,7 @@ static void ti_sn_pwm_pin_release(struct ti_sn65dsi86 *pdata)
static struct ti_sn65dsi86 *pwm_chip_to_ti_sn_bridge(struct pwm_chip *chip) static struct ti_sn65dsi86 *pwm_chip_to_ti_sn_bridge(struct pwm_chip *chip)
{ {
return container_of(chip, struct ti_sn65dsi86, pchip); return pwmchip_get_drvdata(chip);
} }
static int ti_sn_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) static int ti_sn_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
...@@ -1415,7 +1415,7 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -1415,7 +1415,7 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
int ret; int ret;
if (!pdata->pwm_enabled) { if (!pdata->pwm_enabled) {
ret = pm_runtime_resume_and_get(chip->dev); ret = pm_runtime_resume_and_get(pwmchip_parent(chip));
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
...@@ -1431,7 +1431,7 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -1431,7 +1431,7 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
SN_GPIO_MUX_MASK << (2 * SN_PWM_GPIO_IDX), SN_GPIO_MUX_MASK << (2 * SN_PWM_GPIO_IDX),
SN_GPIO_MUX_SPECIAL << (2 * SN_PWM_GPIO_IDX)); SN_GPIO_MUX_SPECIAL << (2 * SN_PWM_GPIO_IDX));
if (ret) { if (ret) {
dev_err(chip->dev, "failed to mux in PWM function\n"); dev_err(pwmchip_parent(chip), "failed to mux in PWM function\n");
goto out; goto out;
} }
} }
...@@ -1507,7 +1507,7 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -1507,7 +1507,7 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
ret = regmap_write(pdata->regmap, SN_PWM_PRE_DIV_REG, pre_div); ret = regmap_write(pdata->regmap, SN_PWM_PRE_DIV_REG, pre_div);
if (ret) { if (ret) {
dev_err(chip->dev, "failed to update PWM_PRE_DIV\n"); dev_err(pwmchip_parent(chip), "failed to update PWM_PRE_DIV\n");
goto out; goto out;
} }
...@@ -1519,7 +1519,7 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -1519,7 +1519,7 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
FIELD_PREP(SN_PWM_INV_MASK, state->polarity == PWM_POLARITY_INVERSED); FIELD_PREP(SN_PWM_INV_MASK, state->polarity == PWM_POLARITY_INVERSED);
ret = regmap_write(pdata->regmap, SN_PWM_EN_INV_REG, pwm_en_inv); ret = regmap_write(pdata->regmap, SN_PWM_EN_INV_REG, pwm_en_inv);
if (ret) { if (ret) {
dev_err(chip->dev, "failed to update PWM_EN/PWM_INV\n"); dev_err(pwmchip_parent(chip), "failed to update PWM_EN/PWM_INV\n");
goto out; goto out;
} }
...@@ -1527,7 +1527,7 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -1527,7 +1527,7 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
out: out:
if (!pdata->pwm_enabled) if (!pdata->pwm_enabled)
pm_runtime_put_sync(chip->dev); pm_runtime_put_sync(pwmchip_parent(chip));
return ret; return ret;
} }
...@@ -1585,24 +1585,28 @@ static const struct pwm_ops ti_sn_pwm_ops = { ...@@ -1585,24 +1585,28 @@ static const struct pwm_ops ti_sn_pwm_ops = {
static int ti_sn_pwm_probe(struct auxiliary_device *adev, static int ti_sn_pwm_probe(struct auxiliary_device *adev,
const struct auxiliary_device_id *id) const struct auxiliary_device_id *id)
{ {
struct pwm_chip *chip;
struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent); struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent);
pdata->pchip.dev = &adev->dev; pdata->pchip = chip = devm_pwmchip_alloc(&adev->dev, 1, 0);
pdata->pchip.ops = &ti_sn_pwm_ops; if (IS_ERR(chip))
pdata->pchip.npwm = 1; return PTR_ERR(chip);
pdata->pchip.of_xlate = of_pwm_single_xlate;
pdata->pchip.of_pwm_n_cells = 1; pwmchip_set_drvdata(chip, pdata);
chip->ops = &ti_sn_pwm_ops;
chip->of_xlate = of_pwm_single_xlate;
devm_pm_runtime_enable(&adev->dev); devm_pm_runtime_enable(&adev->dev);
return pwmchip_add(&pdata->pchip); return pwmchip_add(chip);
} }
static void ti_sn_pwm_remove(struct auxiliary_device *adev) static void ti_sn_pwm_remove(struct auxiliary_device *adev)
{ {
struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent); struct ti_sn65dsi86 *pdata = dev_get_drvdata(adev->dev.parent);
pwmchip_remove(&pdata->pchip); pwmchip_remove(pdata->pchip);
if (pdata->pwm_enabled) if (pdata->pwm_enabled)
pm_runtime_put_sync(&adev->dev); pm_runtime_put_sync(&adev->dev);
......
...@@ -77,7 +77,7 @@ struct lpg { ...@@ -77,7 +77,7 @@ struct lpg {
struct mutex lock; struct mutex lock;
struct pwm_chip pwm; struct pwm_chip *pwm;
const struct lpg_data *data; const struct lpg_data *data;
...@@ -978,7 +978,7 @@ static int lpg_pattern_mc_clear(struct led_classdev *cdev) ...@@ -978,7 +978,7 @@ static int lpg_pattern_mc_clear(struct led_classdev *cdev)
static inline struct lpg *lpg_pwm_from_chip(struct pwm_chip *chip) static inline struct lpg *lpg_pwm_from_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct lpg, pwm); return pwmchip_get_drvdata(chip);
} }
static int lpg_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) static int lpg_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
...@@ -1093,13 +1093,17 @@ static const struct pwm_ops lpg_pwm_ops = { ...@@ -1093,13 +1093,17 @@ static const struct pwm_ops lpg_pwm_ops = {
static int lpg_add_pwm(struct lpg *lpg) static int lpg_add_pwm(struct lpg *lpg)
{ {
struct pwm_chip *chip;
int ret; int ret;
lpg->pwm.dev = lpg->dev; lpg->pwm = chip = devm_pwmchip_alloc(lpg->dev, lpg->num_channels, 0);
lpg->pwm.npwm = lpg->num_channels; if (IS_ERR(chip))
lpg->pwm.ops = &lpg_pwm_ops; return PTR_ERR(chip);
ret = devm_pwmchip_add(lpg->dev, &lpg->pwm); chip->ops = &lpg_pwm_ops;
pwmchip_set_drvdata(chip, lpg);
ret = devm_pwmchip_add(lpg->dev, chip);
if (ret) if (ret)
dev_err_probe(lpg->dev, ret, "failed to add PWM chip\n"); dev_err_probe(lpg->dev, ret, "failed to add PWM chip\n");
......
...@@ -1492,7 +1492,7 @@ static int intel_pinctrl_probe_pwm(struct intel_pinctrl *pctrl, ...@@ -1492,7 +1492,7 @@ static int intel_pinctrl_probe_pwm(struct intel_pinctrl *pctrl,
.base_unit_bits = 22, .base_unit_bits = 22,
.bypass = true, .bypass = true,
}; };
struct pwm_lpss_chip *pwm; struct pwm_chip *chip;
if (!(community->features & PINCTRL_FEATURE_PWM)) if (!(community->features & PINCTRL_FEATURE_PWM))
return 0; return 0;
...@@ -1500,8 +1500,8 @@ static int intel_pinctrl_probe_pwm(struct intel_pinctrl *pctrl, ...@@ -1500,8 +1500,8 @@ static int intel_pinctrl_probe_pwm(struct intel_pinctrl *pctrl,
if (!IS_REACHABLE(CONFIG_PWM_LPSS)) if (!IS_REACHABLE(CONFIG_PWM_LPSS))
return 0; return 0;
pwm = devm_pwm_lpss_probe(pctrl->dev, community->regs + PWMC, &info); chip = devm_pwm_lpss_probe(pctrl->dev, community->regs + PWMC, &info);
return PTR_ERR_OR_ZERO(pwm); return PTR_ERR_OR_ZERO(chip);
} }
int intel_pinctrl_probe(struct platform_device *pdev, int intel_pinctrl_probe(struct platform_device *pdev,
......
This diff is collapsed.
...@@ -24,13 +24,12 @@ ...@@ -24,13 +24,12 @@
#define AB8500_PWM_CLKRATE 9600000 #define AB8500_PWM_CLKRATE 9600000
struct ab8500_pwm_chip { struct ab8500_pwm_chip {
struct pwm_chip chip;
unsigned int hwid; unsigned int hwid;
}; };
static struct ab8500_pwm_chip *ab8500_pwm_from_chip(struct pwm_chip *chip) static struct ab8500_pwm_chip *ab8500_pwm_from_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct ab8500_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static int ab8500_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, static int ab8500_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
...@@ -92,12 +91,12 @@ static int ab8500_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -92,12 +91,12 @@ static int ab8500_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
* when disabled. * when disabled.
*/ */
if (!state->enabled || duty_steps == 0) { if (!state->enabled || duty_steps == 0) {
ret = abx500_mask_and_set_register_interruptible(chip->dev, ret = abx500_mask_and_set_register_interruptible(pwmchip_parent(chip),
AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG, AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG,
1 << ab8500->hwid, 0); 1 << ab8500->hwid, 0);
if (ret < 0) if (ret < 0)
dev_err(chip->dev, "%s: Failed to disable PWM, Error %d\n", dev_err(pwmchip_parent(chip), "%s: Failed to disable PWM, Error %d\n",
pwm->label, ret); pwm->label, ret);
return ret; return ret;
} }
...@@ -115,22 +114,22 @@ static int ab8500_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -115,22 +114,22 @@ static int ab8500_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
reg = AB8500_PWM_OUT_CTRL1_REG + (ab8500->hwid * 2); reg = AB8500_PWM_OUT_CTRL1_REG + (ab8500->hwid * 2);
ret = abx500_set_register_interruptible(chip->dev, AB8500_MISC, ret = abx500_set_register_interruptible(pwmchip_parent(chip), AB8500_MISC,
reg, lower_val); reg, lower_val);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = abx500_set_register_interruptible(chip->dev, AB8500_MISC, ret = abx500_set_register_interruptible(pwmchip_parent(chip), AB8500_MISC,
(reg + 1), higher_val); (reg + 1), higher_val);
if (ret < 0) if (ret < 0)
return ret; return ret;
/* enable */ /* enable */
ret = abx500_mask_and_set_register_interruptible(chip->dev, ret = abx500_mask_and_set_register_interruptible(pwmchip_parent(chip),
AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG, AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG,
1 << ab8500->hwid, 1 << ab8500->hwid); 1 << ab8500->hwid, 1 << ab8500->hwid);
if (ret < 0) if (ret < 0)
dev_err(chip->dev, "%s: Failed to enable PWM, Error %d\n", dev_err(pwmchip_parent(chip), "%s: Failed to enable PWM, Error %d\n",
pwm->label, ret); pwm->label, ret);
return ret; return ret;
...@@ -144,7 +143,7 @@ static int ab8500_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -144,7 +143,7 @@ static int ab8500_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
struct ab8500_pwm_chip *ab8500 = ab8500_pwm_from_chip(chip); struct ab8500_pwm_chip *ab8500 = ab8500_pwm_from_chip(chip);
unsigned int div, duty_steps; unsigned int div, duty_steps;
ret = abx500_get_register_interruptible(chip->dev, AB8500_MISC, ret = abx500_get_register_interruptible(pwmchip_parent(chip), AB8500_MISC,
AB8500_PWM_OUT_CTRL7_REG, AB8500_PWM_OUT_CTRL7_REG,
&ctrl7); &ctrl7);
if (ret) if (ret)
...@@ -157,13 +156,13 @@ static int ab8500_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -157,13 +156,13 @@ static int ab8500_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
return 0; return 0;
} }
ret = abx500_get_register_interruptible(chip->dev, AB8500_MISC, ret = abx500_get_register_interruptible(pwmchip_parent(chip), AB8500_MISC,
AB8500_PWM_OUT_CTRL1_REG + (ab8500->hwid * 2), AB8500_PWM_OUT_CTRL1_REG + (ab8500->hwid * 2),
&lower_val); &lower_val);
if (ret) if (ret)
return ret; return ret;
ret = abx500_get_register_interruptible(chip->dev, AB8500_MISC, ret = abx500_get_register_interruptible(pwmchip_parent(chip), AB8500_MISC,
AB8500_PWM_OUT_CTRL2_REG + (ab8500->hwid * 2), AB8500_PWM_OUT_CTRL2_REG + (ab8500->hwid * 2),
&higher_val); &higher_val);
if (ret) if (ret)
...@@ -185,6 +184,7 @@ static const struct pwm_ops ab8500_pwm_ops = { ...@@ -185,6 +184,7 @@ static const struct pwm_ops ab8500_pwm_ops = {
static int ab8500_pwm_probe(struct platform_device *pdev) static int ab8500_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct ab8500_pwm_chip *ab8500; struct ab8500_pwm_chip *ab8500;
int err; int err;
...@@ -195,16 +195,16 @@ static int ab8500_pwm_probe(struct platform_device *pdev) ...@@ -195,16 +195,16 @@ static int ab8500_pwm_probe(struct platform_device *pdev)
* Nothing to be done in probe, this is required to get the * Nothing to be done in probe, this is required to get the
* device which is required for ab8500 read and write * device which is required for ab8500 read and write
*/ */
ab8500 = devm_kzalloc(&pdev->dev, sizeof(*ab8500), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*ab8500));
if (ab8500 == NULL) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
ab8500->chip.dev = &pdev->dev; ab8500 = ab8500_pwm_from_chip(chip);
ab8500->chip.ops = &ab8500_pwm_ops;
ab8500->chip.npwm = 1; chip->ops = &ab8500_pwm_ops;
ab8500->hwid = pdev->id - 1; ab8500->hwid = pdev->id - 1;
err = devm_pwmchip_add(&pdev->dev, &ab8500->chip); err = devm_pwmchip_add(&pdev->dev, chip);
if (err < 0) if (err < 0)
return dev_err_probe(&pdev->dev, err, "Failed to add pwm chip\n"); return dev_err_probe(&pdev->dev, err, "Failed to add pwm chip\n");
......
...@@ -32,14 +32,13 @@ ...@@ -32,14 +32,13 @@
#define APPLE_PWM_CTRL_OUTPUT_ENABLE BIT(14) #define APPLE_PWM_CTRL_OUTPUT_ENABLE BIT(14)
struct apple_pwm { struct apple_pwm {
struct pwm_chip chip;
void __iomem *base; void __iomem *base;
u64 clkrate; u64 clkrate;
}; };
static inline struct apple_pwm *to_apple_pwm(struct pwm_chip *chip) static inline struct apple_pwm *to_apple_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct apple_pwm, chip); return pwmchip_get_drvdata(chip);
} }
static int apple_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, static int apple_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
...@@ -103,13 +102,16 @@ static const struct pwm_ops apple_pwm_ops = { ...@@ -103,13 +102,16 @@ static const struct pwm_ops apple_pwm_ops = {
static int apple_pwm_probe(struct platform_device *pdev) static int apple_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct apple_pwm *fpwm; struct apple_pwm *fpwm;
struct clk *clk; struct clk *clk;
int ret; int ret;
fpwm = devm_kzalloc(&pdev->dev, sizeof(*fpwm), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*fpwm));
if (!fpwm) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
fpwm = to_apple_pwm(chip);
fpwm->base = devm_platform_ioremap_resource(pdev, 0); fpwm->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(fpwm->base)) if (IS_ERR(fpwm->base))
...@@ -129,11 +131,9 @@ static int apple_pwm_probe(struct platform_device *pdev) ...@@ -129,11 +131,9 @@ static int apple_pwm_probe(struct platform_device *pdev)
if (fpwm->clkrate > NSEC_PER_SEC) if (fpwm->clkrate > NSEC_PER_SEC)
return dev_err_probe(&pdev->dev, -EINVAL, "pwm clock out of range"); return dev_err_probe(&pdev->dev, -EINVAL, "pwm clock out of range");
fpwm->chip.dev = &pdev->dev; chip->ops = &apple_pwm_ops;
fpwm->chip.npwm = 1;
fpwm->chip.ops = &apple_pwm_ops;
ret = devm_pwmchip_add(&pdev->dev, &fpwm->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) if (ret < 0)
return dev_err_probe(&pdev->dev, ret, "unable to add pwm chip"); return dev_err_probe(&pdev->dev, ret, "unable to add pwm chip");
......
...@@ -28,7 +28,6 @@ struct atmel_hlcdc_pwm_errata { ...@@ -28,7 +28,6 @@ struct atmel_hlcdc_pwm_errata {
}; };
struct atmel_hlcdc_pwm { struct atmel_hlcdc_pwm {
struct pwm_chip chip;
struct atmel_hlcdc *hlcdc; struct atmel_hlcdc *hlcdc;
struct clk *cur_clk; struct clk *cur_clk;
const struct atmel_hlcdc_pwm_errata *errata; const struct atmel_hlcdc_pwm_errata *errata;
...@@ -36,7 +35,7 @@ struct atmel_hlcdc_pwm { ...@@ -36,7 +35,7 @@ struct atmel_hlcdc_pwm {
static inline struct atmel_hlcdc_pwm *to_atmel_hlcdc_pwm(struct pwm_chip *chip) static inline struct atmel_hlcdc_pwm *to_atmel_hlcdc_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct atmel_hlcdc_pwm, chip); return pwmchip_get_drvdata(chip);
} }
static int atmel_hlcdc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, static int atmel_hlcdc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
...@@ -182,10 +181,12 @@ static const struct atmel_hlcdc_pwm_errata atmel_hlcdc_pwm_sama5d3_errata = { ...@@ -182,10 +181,12 @@ static const struct atmel_hlcdc_pwm_errata atmel_hlcdc_pwm_sama5d3_errata = {
static int atmel_hlcdc_pwm_suspend(struct device *dev) static int atmel_hlcdc_pwm_suspend(struct device *dev)
{ {
struct atmel_hlcdc_pwm *atmel = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct atmel_hlcdc_pwm *atmel = to_atmel_hlcdc_pwm(chip);
struct pwm_device *pwm = &chip->pwms[0];
/* Keep the periph clock enabled if the PWM is still running. */ /* Keep the periph clock enabled if the PWM is still running. */
if (pwm_is_enabled(&atmel->chip.pwms[0])) if (!pwm->state.enabled)
clk_disable_unprepare(atmel->hlcdc->periph_clk); clk_disable_unprepare(atmel->hlcdc->periph_clk);
return 0; return 0;
...@@ -193,21 +194,19 @@ static int atmel_hlcdc_pwm_suspend(struct device *dev) ...@@ -193,21 +194,19 @@ static int atmel_hlcdc_pwm_suspend(struct device *dev)
static int atmel_hlcdc_pwm_resume(struct device *dev) static int atmel_hlcdc_pwm_resume(struct device *dev)
{ {
struct atmel_hlcdc_pwm *atmel = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct pwm_state state; struct atmel_hlcdc_pwm *atmel = to_atmel_hlcdc_pwm(chip);
struct pwm_device *pwm = &chip->pwms[0];
int ret; int ret;
pwm_get_state(&atmel->chip.pwms[0], &state);
/* Re-enable the periph clock it was stopped during suspend. */ /* Re-enable the periph clock it was stopped during suspend. */
if (!state.enabled) { if (!pwm->state.enabled) {
ret = clk_prepare_enable(atmel->hlcdc->periph_clk); ret = clk_prepare_enable(atmel->hlcdc->periph_clk);
if (ret) if (ret)
return ret; return ret;
} }
return atmel_hlcdc_pwm_apply(&atmel->chip, &atmel->chip.pwms[0], return atmel_hlcdc_pwm_apply(chip, pwm, &pwm->state);
&state);
} }
static DEFINE_SIMPLE_DEV_PM_OPS(atmel_hlcdc_pwm_pm_ops, static DEFINE_SIMPLE_DEV_PM_OPS(atmel_hlcdc_pwm_pm_ops,
...@@ -243,15 +242,17 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev) ...@@ -243,15 +242,17 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev)
{ {
const struct of_device_id *match; const struct of_device_id *match;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct pwm_chip *chip;
struct atmel_hlcdc_pwm *atmel; struct atmel_hlcdc_pwm *atmel;
struct atmel_hlcdc *hlcdc; struct atmel_hlcdc *hlcdc;
int ret; int ret;
hlcdc = dev_get_drvdata(dev->parent); hlcdc = dev_get_drvdata(dev->parent);
atmel = devm_kzalloc(dev, sizeof(*atmel), GFP_KERNEL); chip = devm_pwmchip_alloc(dev, 1, sizeof(*atmel));
if (!atmel) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
atmel = to_atmel_hlcdc_pwm(chip);
ret = clk_prepare_enable(hlcdc->periph_clk); ret = clk_prepare_enable(hlcdc->periph_clk);
if (ret) if (ret)
...@@ -262,26 +263,25 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev) ...@@ -262,26 +263,25 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev)
atmel->errata = match->data; atmel->errata = match->data;
atmel->hlcdc = hlcdc; atmel->hlcdc = hlcdc;
atmel->chip.ops = &atmel_hlcdc_pwm_ops; chip->ops = &atmel_hlcdc_pwm_ops;
atmel->chip.dev = dev;
atmel->chip.npwm = 1;
ret = pwmchip_add(&atmel->chip); ret = pwmchip_add(chip);
if (ret) { if (ret) {
clk_disable_unprepare(hlcdc->periph_clk); clk_disable_unprepare(hlcdc->periph_clk);
return ret; return ret;
} }
platform_set_drvdata(pdev, atmel); platform_set_drvdata(pdev, chip);
return 0; return 0;
} }
static void atmel_hlcdc_pwm_remove(struct platform_device *pdev) static void atmel_hlcdc_pwm_remove(struct platform_device *pdev)
{ {
struct atmel_hlcdc_pwm *atmel = platform_get_drvdata(pdev); struct pwm_chip *chip = platform_get_drvdata(pdev);
struct atmel_hlcdc_pwm *atmel = to_atmel_hlcdc_pwm(chip);
pwmchip_remove(&atmel->chip); pwmchip_remove(chip);
clk_disable_unprepare(atmel->hlcdc->periph_clk); clk_disable_unprepare(atmel->hlcdc->periph_clk);
} }
......
...@@ -47,7 +47,6 @@ struct atmel_tcb_channel { ...@@ -47,7 +47,6 @@ struct atmel_tcb_channel {
}; };
struct atmel_tcb_pwm_chip { struct atmel_tcb_pwm_chip {
struct pwm_chip chip;
spinlock_t lock; spinlock_t lock;
u8 channel; u8 channel;
u8 width; u8 width;
...@@ -63,7 +62,7 @@ static const u8 atmel_tcb_divisors[] = { 2, 8, 32, 128, 0, }; ...@@ -63,7 +62,7 @@ static const u8 atmel_tcb_divisors[] = { 2, 8, 32, 128, 0, };
static inline struct atmel_tcb_pwm_chip *to_tcb_chip(struct pwm_chip *chip) static inline struct atmel_tcb_pwm_chip *to_tcb_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct atmel_tcb_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static int atmel_tcb_pwm_request(struct pwm_chip *chip, static int atmel_tcb_pwm_request(struct pwm_chip *chip,
...@@ -327,7 +326,7 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -327,7 +326,7 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
if ((atcbpwm && atcbpwm->duty > 0 && if ((atcbpwm && atcbpwm->duty > 0 &&
atcbpwm->duty != atcbpwm->period) && atcbpwm->duty != atcbpwm->period) &&
(atcbpwm->div != i || atcbpwm->period != period)) { (atcbpwm->div != i || atcbpwm->period != period)) {
dev_err(chip->dev, dev_err(pwmchip_parent(chip),
"failed to configure period_ns: PWM group already configured with a different value\n"); "failed to configure period_ns: PWM group already configured with a different value\n");
return -EINVAL; return -EINVAL;
} }
...@@ -388,6 +387,7 @@ static const struct of_device_id atmel_tcb_of_match[] = { ...@@ -388,6 +387,7 @@ static const struct of_device_id atmel_tcb_of_match[] = {
static int atmel_tcb_pwm_probe(struct platform_device *pdev) static int atmel_tcb_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
const struct of_device_id *match; const struct of_device_id *match;
struct atmel_tcb_pwm_chip *tcbpwm; struct atmel_tcb_pwm_chip *tcbpwm;
const struct atmel_tcb_config *config; const struct atmel_tcb_config *config;
...@@ -396,9 +396,10 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev) ...@@ -396,9 +396,10 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
int err; int err;
int channel; int channel;
tcbpwm = devm_kzalloc(&pdev->dev, sizeof(*tcbpwm), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, NPWM, sizeof(*tcbpwm));
if (tcbpwm == NULL) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
tcbpwm = to_tcb_chip(chip);
err = of_property_read_u32(np, "reg", &channel); err = of_property_read_u32(np, "reg", &channel);
if (err < 0) { if (err < 0) {
...@@ -436,9 +437,7 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev) ...@@ -436,9 +437,7 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
} }
} }
tcbpwm->chip.dev = &pdev->dev; chip->ops = &atmel_tcb_pwm_ops;
tcbpwm->chip.ops = &atmel_tcb_pwm_ops;
tcbpwm->chip.npwm = NPWM;
tcbpwm->channel = channel; tcbpwm->channel = channel;
tcbpwm->width = config->counter_width; tcbpwm->width = config->counter_width;
...@@ -448,11 +447,11 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev) ...@@ -448,11 +447,11 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
spin_lock_init(&tcbpwm->lock); spin_lock_init(&tcbpwm->lock);
err = pwmchip_add(&tcbpwm->chip); err = pwmchip_add(chip);
if (err < 0) if (err < 0)
goto err_disable_clk; goto err_disable_clk;
platform_set_drvdata(pdev, tcbpwm); platform_set_drvdata(pdev, chip);
return 0; return 0;
...@@ -473,9 +472,10 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev) ...@@ -473,9 +472,10 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
static void atmel_tcb_pwm_remove(struct platform_device *pdev) static void atmel_tcb_pwm_remove(struct platform_device *pdev)
{ {
struct atmel_tcb_pwm_chip *tcbpwm = platform_get_drvdata(pdev); struct pwm_chip *chip = platform_get_drvdata(pdev);
struct atmel_tcb_pwm_chip *tcbpwm = to_tcb_chip(chip);
pwmchip_remove(&tcbpwm->chip); pwmchip_remove(chip);
clk_disable_unprepare(tcbpwm->slow_clk); clk_disable_unprepare(tcbpwm->slow_clk);
clk_put(tcbpwm->gclk); clk_put(tcbpwm->gclk);
...@@ -491,7 +491,8 @@ MODULE_DEVICE_TABLE(of, atmel_tcb_pwm_dt_ids); ...@@ -491,7 +491,8 @@ MODULE_DEVICE_TABLE(of, atmel_tcb_pwm_dt_ids);
static int atmel_tcb_pwm_suspend(struct device *dev) static int atmel_tcb_pwm_suspend(struct device *dev)
{ {
struct atmel_tcb_pwm_chip *tcbpwm = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct atmel_tcb_pwm_chip *tcbpwm = to_tcb_chip(chip);
struct atmel_tcb_channel *chan = &tcbpwm->bkup; struct atmel_tcb_channel *chan = &tcbpwm->bkup;
unsigned int channel = tcbpwm->channel; unsigned int channel = tcbpwm->channel;
...@@ -505,7 +506,8 @@ static int atmel_tcb_pwm_suspend(struct device *dev) ...@@ -505,7 +506,8 @@ static int atmel_tcb_pwm_suspend(struct device *dev)
static int atmel_tcb_pwm_resume(struct device *dev) static int atmel_tcb_pwm_resume(struct device *dev)
{ {
struct atmel_tcb_pwm_chip *tcbpwm = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct atmel_tcb_pwm_chip *tcbpwm = to_tcb_chip(chip);
struct atmel_tcb_channel *chan = &tcbpwm->bkup; struct atmel_tcb_channel *chan = &tcbpwm->bkup;
unsigned int channel = tcbpwm->channel; unsigned int channel = tcbpwm->channel;
......
...@@ -77,7 +77,6 @@ struct atmel_pwm_data { ...@@ -77,7 +77,6 @@ struct atmel_pwm_data {
}; };
struct atmel_pwm_chip { struct atmel_pwm_chip {
struct pwm_chip chip;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
const struct atmel_pwm_data *data; const struct atmel_pwm_data *data;
...@@ -99,7 +98,7 @@ struct atmel_pwm_chip { ...@@ -99,7 +98,7 @@ struct atmel_pwm_chip {
static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip) static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct atmel_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static inline u32 atmel_pwm_readl(struct atmel_pwm_chip *chip, static inline u32 atmel_pwm_readl(struct atmel_pwm_chip *chip,
...@@ -210,7 +209,7 @@ static int atmel_pwm_calculate_cprd_and_pres(struct pwm_chip *chip, ...@@ -210,7 +209,7 @@ static int atmel_pwm_calculate_cprd_and_pres(struct pwm_chip *chip,
shift = fls(cycles) - atmel_pwm->data->cfg.period_bits; shift = fls(cycles) - atmel_pwm->data->cfg.period_bits;
if (shift > PWM_MAX_PRES) { if (shift > PWM_MAX_PRES) {
dev_err(chip->dev, "pres exceeds the maximum value\n"); dev_err(pwmchip_parent(chip), "pres exceeds the maximum value\n");
return -EINVAL; return -EINVAL;
} else if (shift > 0) { } else if (shift > 0) {
*pres = shift; *pres = shift;
...@@ -294,19 +293,16 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -294,19 +293,16 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state) const struct pwm_state *state)
{ {
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
struct pwm_state cstate;
unsigned long cprd, cdty; unsigned long cprd, cdty;
u32 pres, val; u32 pres, val;
int ret; int ret;
pwm_get_state(pwm, &cstate);
if (state->enabled) { if (state->enabled) {
unsigned long clkrate = clk_get_rate(atmel_pwm->clk); unsigned long clkrate = clk_get_rate(atmel_pwm->clk);
if (cstate.enabled && if (pwm->state.enabled &&
cstate.polarity == state->polarity && pwm->state.polarity == state->polarity &&
cstate.period == state->period) { pwm->state.period == state->period) {
u32 cmr = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, PWM_CMR); u32 cmr = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, PWM_CMR);
cprd = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, cprd = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm,
...@@ -321,19 +317,19 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -321,19 +317,19 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
ret = atmel_pwm_calculate_cprd_and_pres(chip, clkrate, state, &cprd, ret = atmel_pwm_calculate_cprd_and_pres(chip, clkrate, state, &cprd,
&pres); &pres);
if (ret) { if (ret) {
dev_err(chip->dev, dev_err(pwmchip_parent(chip),
"failed to calculate cprd and prescaler\n"); "failed to calculate cprd and prescaler\n");
return ret; return ret;
} }
atmel_pwm_calculate_cdty(state, clkrate, cprd, pres, &cdty); atmel_pwm_calculate_cdty(state, clkrate, cprd, pres, &cdty);
if (cstate.enabled) { if (pwm->state.enabled) {
atmel_pwm_disable(chip, pwm, false); atmel_pwm_disable(chip, pwm, false);
} else { } else {
ret = clk_enable(atmel_pwm->clk); ret = clk_enable(atmel_pwm->clk);
if (ret) { if (ret) {
dev_err(chip->dev, "failed to enable clock\n"); dev_err(pwmchip_parent(chip), "failed to enable clock\n");
return ret; return ret;
} }
} }
...@@ -348,7 +344,7 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -348,7 +344,7 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWM_CMR, val); atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWM_CMR, val);
atmel_pwm_set_cprd_cdty(chip, pwm, cprd, cdty); atmel_pwm_set_cprd_cdty(chip, pwm, cprd, cdty);
atmel_pwm_writel(atmel_pwm, PWM_ENA, 1 << pwm->hwpwm); atmel_pwm_writel(atmel_pwm, PWM_ENA, 1 << pwm->hwpwm);
} else if (cstate.enabled) { } else if (pwm->state.enabled) {
atmel_pwm_disable(chip, pwm, true); atmel_pwm_disable(chip, pwm, true);
} }
...@@ -462,8 +458,9 @@ static const struct of_device_id atmel_pwm_dt_ids[] = { ...@@ -462,8 +458,9 @@ static const struct of_device_id atmel_pwm_dt_ids[] = {
}; };
MODULE_DEVICE_TABLE(of, atmel_pwm_dt_ids); MODULE_DEVICE_TABLE(of, atmel_pwm_dt_ids);
static int atmel_pwm_enable_clk_if_on(struct atmel_pwm_chip *atmel_pwm, bool on) static int atmel_pwm_enable_clk_if_on(struct pwm_chip *chip, bool on)
{ {
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
unsigned int i, cnt = 0; unsigned int i, cnt = 0;
unsigned long sr; unsigned long sr;
int ret = 0; int ret = 0;
...@@ -472,7 +469,7 @@ static int atmel_pwm_enable_clk_if_on(struct atmel_pwm_chip *atmel_pwm, bool on) ...@@ -472,7 +469,7 @@ static int atmel_pwm_enable_clk_if_on(struct atmel_pwm_chip *atmel_pwm, bool on)
if (!sr) if (!sr)
return 0; return 0;
cnt = bitmap_weight(&sr, atmel_pwm->chip.npwm); cnt = bitmap_weight(&sr, chip->npwm);
if (!on) if (!on)
goto disable_clk; goto disable_clk;
...@@ -480,7 +477,7 @@ static int atmel_pwm_enable_clk_if_on(struct atmel_pwm_chip *atmel_pwm, bool on) ...@@ -480,7 +477,7 @@ static int atmel_pwm_enable_clk_if_on(struct atmel_pwm_chip *atmel_pwm, bool on)
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
ret = clk_enable(atmel_pwm->clk); ret = clk_enable(atmel_pwm->clk);
if (ret) { if (ret) {
dev_err(atmel_pwm->chip.dev, dev_err(pwmchip_parent(chip),
"failed to enable clock for pwm %pe\n", "failed to enable clock for pwm %pe\n",
ERR_PTR(ret)); ERR_PTR(ret));
...@@ -501,12 +498,14 @@ static int atmel_pwm_enable_clk_if_on(struct atmel_pwm_chip *atmel_pwm, bool on) ...@@ -501,12 +498,14 @@ static int atmel_pwm_enable_clk_if_on(struct atmel_pwm_chip *atmel_pwm, bool on)
static int atmel_pwm_probe(struct platform_device *pdev) static int atmel_pwm_probe(struct platform_device *pdev)
{ {
struct atmel_pwm_chip *atmel_pwm; struct atmel_pwm_chip *atmel_pwm;
struct pwm_chip *chip;
int ret; int ret;
atmel_pwm = devm_kzalloc(&pdev->dev, sizeof(*atmel_pwm), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 4, sizeof(*atmel_pwm));
if (!atmel_pwm) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
atmel_pwm = to_atmel_pwm_chip(chip);
atmel_pwm->data = of_device_get_match_data(&pdev->dev); atmel_pwm->data = of_device_get_match_data(&pdev->dev);
atmel_pwm->update_pending = 0; atmel_pwm->update_pending = 0;
...@@ -521,15 +520,13 @@ static int atmel_pwm_probe(struct platform_device *pdev) ...@@ -521,15 +520,13 @@ static int atmel_pwm_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(atmel_pwm->clk), return dev_err_probe(&pdev->dev, PTR_ERR(atmel_pwm->clk),
"failed to get prepared PWM clock\n"); "failed to get prepared PWM clock\n");
atmel_pwm->chip.dev = &pdev->dev; chip->ops = &atmel_pwm_ops;
atmel_pwm->chip.ops = &atmel_pwm_ops;
atmel_pwm->chip.npwm = 4;
ret = atmel_pwm_enable_clk_if_on(atmel_pwm, true); ret = atmel_pwm_enable_clk_if_on(chip, true);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = devm_pwmchip_add(&pdev->dev, &atmel_pwm->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) { if (ret < 0) {
dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
goto disable_clk; goto disable_clk;
...@@ -538,7 +535,7 @@ static int atmel_pwm_probe(struct platform_device *pdev) ...@@ -538,7 +535,7 @@ static int atmel_pwm_probe(struct platform_device *pdev)
return 0; return 0;
disable_clk: disable_clk:
atmel_pwm_enable_clk_if_on(atmel_pwm, false); atmel_pwm_enable_clk_if_on(chip, false);
return ret; return ret;
} }
......
...@@ -34,14 +34,13 @@ ...@@ -34,14 +34,13 @@
#define IPROC_PWM_PRESCALE_MAX 0x3f #define IPROC_PWM_PRESCALE_MAX 0x3f
struct iproc_pwmc { struct iproc_pwmc {
struct pwm_chip chip;
void __iomem *base; void __iomem *base;
struct clk *clk; struct clk *clk;
}; };
static inline struct iproc_pwmc *to_iproc_pwmc(struct pwm_chip *chip) static inline struct iproc_pwmc *to_iproc_pwmc(struct pwm_chip *chip)
{ {
return container_of(chip, struct iproc_pwmc, chip); return pwmchip_get_drvdata(chip);
} }
static void iproc_pwmc_enable(struct iproc_pwmc *ip, unsigned int channel) static void iproc_pwmc_enable(struct iproc_pwmc *ip, unsigned int channel)
...@@ -187,20 +186,20 @@ static const struct pwm_ops iproc_pwm_ops = { ...@@ -187,20 +186,20 @@ static const struct pwm_ops iproc_pwm_ops = {
static int iproc_pwmc_probe(struct platform_device *pdev) static int iproc_pwmc_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct iproc_pwmc *ip; struct iproc_pwmc *ip;
unsigned int i; unsigned int i;
u32 value; u32 value;
int ret; int ret;
ip = devm_kzalloc(&pdev->dev, sizeof(*ip), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 4, sizeof(*ip));
if (!ip) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
ip = to_iproc_pwmc(chip);
platform_set_drvdata(pdev, ip); platform_set_drvdata(pdev, ip);
ip->chip.dev = &pdev->dev; chip->ops = &iproc_pwm_ops;
ip->chip.ops = &iproc_pwm_ops;
ip->chip.npwm = 4;
ip->base = devm_platform_ioremap_resource(pdev, 0); ip->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(ip->base)) if (IS_ERR(ip->base))
...@@ -214,14 +213,14 @@ static int iproc_pwmc_probe(struct platform_device *pdev) ...@@ -214,14 +213,14 @@ static int iproc_pwmc_probe(struct platform_device *pdev)
/* Set full drive and normal polarity for all channels */ /* Set full drive and normal polarity for all channels */
value = readl(ip->base + IPROC_PWM_CTRL_OFFSET); value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);
for (i = 0; i < ip->chip.npwm; i++) { for (i = 0; i < chip->npwm; i++) {
value &= ~(1 << IPROC_PWM_CTRL_TYPE_SHIFT(i)); value &= ~(1 << IPROC_PWM_CTRL_TYPE_SHIFT(i));
value |= 1 << IPROC_PWM_CTRL_POLARITY_SHIFT(i); value |= 1 << IPROC_PWM_CTRL_POLARITY_SHIFT(i);
} }
writel(value, ip->base + IPROC_PWM_CTRL_OFFSET); writel(value, ip->base + IPROC_PWM_CTRL_OFFSET);
ret = devm_pwmchip_add(&pdev->dev, &ip->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) if (ret < 0)
return dev_err_probe(&pdev->dev, ret, return dev_err_probe(&pdev->dev, ret,
"failed to add PWM chip\n"); "failed to add PWM chip\n");
......
...@@ -56,14 +56,13 @@ ...@@ -56,14 +56,13 @@
#define DUTY_CYCLE_HIGH_MAX 0x00ffffff #define DUTY_CYCLE_HIGH_MAX 0x00ffffff
struct kona_pwmc { struct kona_pwmc {
struct pwm_chip chip;
void __iomem *base; void __iomem *base;
struct clk *clk; struct clk *clk;
}; };
static inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *chip) static inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *chip)
{ {
return container_of(chip, struct kona_pwmc, chip); return pwmchip_get_drvdata(chip);
} }
/* /*
...@@ -164,7 +163,7 @@ static int kona_pwmc_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -164,7 +163,7 @@ static int kona_pwmc_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
ret = clk_prepare_enable(kp->clk); ret = clk_prepare_enable(kp->clk);
if (ret < 0) { if (ret < 0) {
dev_err(chip->dev, "failed to enable clock: %d\n", ret); dev_err(pwmchip_parent(chip), "failed to enable clock: %d\n", ret);
return ret; return ret;
} }
...@@ -193,7 +192,7 @@ static int kona_pwmc_enable(struct pwm_chip *chip, struct pwm_device *pwm) ...@@ -193,7 +192,7 @@ static int kona_pwmc_enable(struct pwm_chip *chip, struct pwm_device *pwm)
ret = clk_prepare_enable(kp->clk); ret = clk_prepare_enable(kp->clk);
if (ret < 0) { if (ret < 0) {
dev_err(chip->dev, "failed to enable clock: %d\n", ret); dev_err(pwmchip_parent(chip), "failed to enable clock: %d\n", ret);
return ret; return ret;
} }
...@@ -273,18 +272,18 @@ static const struct pwm_ops kona_pwm_ops = { ...@@ -273,18 +272,18 @@ static const struct pwm_ops kona_pwm_ops = {
static int kona_pwmc_probe(struct platform_device *pdev) static int kona_pwmc_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct kona_pwmc *kp; struct kona_pwmc *kp;
unsigned int chan; unsigned int chan;
unsigned int value = 0; unsigned int value = 0;
int ret = 0; int ret = 0;
kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 6, sizeof(*kp));
if (kp == NULL) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
kp = to_kona_pwmc(chip);
kp->chip.dev = &pdev->dev; chip->ops = &kona_pwm_ops;
kp->chip.ops = &kona_pwm_ops;
kp->chip.npwm = 6;
kp->base = devm_platform_ioremap_resource(pdev, 0); kp->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(kp->base)) if (IS_ERR(kp->base))
...@@ -304,14 +303,14 @@ static int kona_pwmc_probe(struct platform_device *pdev) ...@@ -304,14 +303,14 @@ static int kona_pwmc_probe(struct platform_device *pdev)
} }
/* Set push/pull for all channels */ /* Set push/pull for all channels */
for (chan = 0; chan < kp->chip.npwm; chan++) for (chan = 0; chan < chip->npwm; chan++)
value |= (1 << PWM_CONTROL_TYPE_SHIFT(chan)); value |= (1 << PWM_CONTROL_TYPE_SHIFT(chan));
writel(value, kp->base + PWM_CONTROL_OFFSET); writel(value, kp->base + PWM_CONTROL_OFFSET);
clk_disable_unprepare(kp->clk); clk_disable_unprepare(kp->clk);
ret = devm_pwmchip_add(&pdev->dev, &kp->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) if (ret < 0)
dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);
......
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
#define PERIOD_MIN 0x2 #define PERIOD_MIN 0x2
struct bcm2835_pwm { struct bcm2835_pwm {
struct pwm_chip chip;
struct device *dev;
void __iomem *base; void __iomem *base;
struct clk *clk; struct clk *clk;
unsigned long rate; unsigned long rate;
...@@ -33,7 +31,7 @@ struct bcm2835_pwm { ...@@ -33,7 +31,7 @@ struct bcm2835_pwm {
static inline struct bcm2835_pwm *to_bcm2835_pwm(struct pwm_chip *chip) static inline struct bcm2835_pwm *to_bcm2835_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct bcm2835_pwm, chip); return pwmchip_get_drvdata(chip);
} }
static int bcm2835_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) static int bcm2835_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
...@@ -135,14 +133,14 @@ static void devm_clk_rate_exclusive_put(void *data) ...@@ -135,14 +133,14 @@ static void devm_clk_rate_exclusive_put(void *data)
static int bcm2835_pwm_probe(struct platform_device *pdev) static int bcm2835_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct bcm2835_pwm *pc; struct bcm2835_pwm *pc;
int ret; int ret;
pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 2, sizeof(*pc));
if (!pc) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
pc = to_bcm2835_pwm(chip);
pc->dev = &pdev->dev;
pc->base = devm_platform_ioremap_resource(pdev, 0); pc->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(pc->base)) if (IS_ERR(pc->base))
...@@ -168,14 +166,12 @@ static int bcm2835_pwm_probe(struct platform_device *pdev) ...@@ -168,14 +166,12 @@ static int bcm2835_pwm_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, -EINVAL, return dev_err_probe(&pdev->dev, -EINVAL,
"failed to get clock rate\n"); "failed to get clock rate\n");
pc->chip.dev = &pdev->dev; chip->ops = &bcm2835_pwm_ops;
pc->chip.ops = &bcm2835_pwm_ops; chip->atomic = true;
pc->chip.atomic = true;
pc->chip.npwm = 2;
platform_set_drvdata(pdev, pc); platform_set_drvdata(pdev, pc);
ret = devm_pwmchip_add(&pdev->dev, &pc->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) if (ret < 0)
return dev_err_probe(&pdev->dev, ret, return dev_err_probe(&pdev->dev, ret,
"failed to add pwmchip\n"); "failed to add pwmchip\n");
......
...@@ -49,7 +49,6 @@ struct berlin_pwm_channel { ...@@ -49,7 +49,6 @@ struct berlin_pwm_channel {
}; };
struct berlin_pwm_chip { struct berlin_pwm_chip {
struct pwm_chip chip;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
struct berlin_pwm_channel channel[BERLIN_PWM_NUMPWMS]; struct berlin_pwm_channel channel[BERLIN_PWM_NUMPWMS];
...@@ -57,7 +56,7 @@ struct berlin_pwm_chip { ...@@ -57,7 +56,7 @@ struct berlin_pwm_chip {
static inline struct berlin_pwm_chip *to_berlin_pwm_chip(struct pwm_chip *chip) static inline struct berlin_pwm_chip *to_berlin_pwm_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct berlin_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static inline u32 berlin_pwm_readl(struct berlin_pwm_chip *bpc, static inline u32 berlin_pwm_readl(struct berlin_pwm_chip *bpc,
...@@ -198,12 +197,14 @@ MODULE_DEVICE_TABLE(of, berlin_pwm_match); ...@@ -198,12 +197,14 @@ MODULE_DEVICE_TABLE(of, berlin_pwm_match);
static int berlin_pwm_probe(struct platform_device *pdev) static int berlin_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct berlin_pwm_chip *bpc; struct berlin_pwm_chip *bpc;
int ret; int ret;
bpc = devm_kzalloc(&pdev->dev, sizeof(*bpc), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, BERLIN_PWM_NUMPWMS, sizeof(*bpc));
if (!bpc) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
bpc = to_berlin_pwm_chip(chip);
bpc->base = devm_platform_ioremap_resource(pdev, 0); bpc->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(bpc->base)) if (IS_ERR(bpc->base))
...@@ -213,25 +214,24 @@ static int berlin_pwm_probe(struct platform_device *pdev) ...@@ -213,25 +214,24 @@ static int berlin_pwm_probe(struct platform_device *pdev)
if (IS_ERR(bpc->clk)) if (IS_ERR(bpc->clk))
return PTR_ERR(bpc->clk); return PTR_ERR(bpc->clk);
bpc->chip.dev = &pdev->dev; chip->ops = &berlin_pwm_ops;
bpc->chip.ops = &berlin_pwm_ops;
bpc->chip.npwm = BERLIN_PWM_NUMPWMS;
ret = devm_pwmchip_add(&pdev->dev, &bpc->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) if (ret < 0)
return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
platform_set_drvdata(pdev, bpc); platform_set_drvdata(pdev, chip);
return 0; return 0;
} }
static int berlin_pwm_suspend(struct device *dev) static int berlin_pwm_suspend(struct device *dev)
{ {
struct berlin_pwm_chip *bpc = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct berlin_pwm_chip *bpc = to_berlin_pwm_chip(chip);
unsigned int i; unsigned int i;
for (i = 0; i < bpc->chip.npwm; i++) { for (i = 0; i < chip->npwm; i++) {
struct berlin_pwm_channel *channel = &bpc->channel[i]; struct berlin_pwm_channel *channel = &bpc->channel[i];
channel->enable = berlin_pwm_readl(bpc, i, BERLIN_PWM_ENABLE); channel->enable = berlin_pwm_readl(bpc, i, BERLIN_PWM_ENABLE);
...@@ -247,7 +247,8 @@ static int berlin_pwm_suspend(struct device *dev) ...@@ -247,7 +247,8 @@ static int berlin_pwm_suspend(struct device *dev)
static int berlin_pwm_resume(struct device *dev) static int berlin_pwm_resume(struct device *dev)
{ {
struct berlin_pwm_chip *bpc = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct berlin_pwm_chip *bpc = to_berlin_pwm_chip(chip);
unsigned int i; unsigned int i;
int ret; int ret;
...@@ -255,7 +256,7 @@ static int berlin_pwm_resume(struct device *dev) ...@@ -255,7 +256,7 @@ static int berlin_pwm_resume(struct device *dev)
if (ret) if (ret)
return ret; return ret;
for (i = 0; i < bpc->chip.npwm; i++) { for (i = 0; i < chip->npwm; i++) {
struct berlin_pwm_channel *channel = &bpc->channel[i]; struct berlin_pwm_channel *channel = &bpc->channel[i];
berlin_pwm_writel(bpc, i, channel->ctrl, BERLIN_PWM_CONTROL); berlin_pwm_writel(bpc, i, channel->ctrl, BERLIN_PWM_CONTROL);
......
...@@ -54,7 +54,6 @@ ...@@ -54,7 +54,6 @@
struct brcmstb_pwm { struct brcmstb_pwm {
void __iomem *base; void __iomem *base;
struct clk *clk; struct clk *clk;
struct pwm_chip chip;
}; };
static inline u32 brcmstb_pwm_readl(struct brcmstb_pwm *p, static inline u32 brcmstb_pwm_readl(struct brcmstb_pwm *p,
...@@ -77,7 +76,7 @@ static inline void brcmstb_pwm_writel(struct brcmstb_pwm *p, u32 value, ...@@ -77,7 +76,7 @@ static inline void brcmstb_pwm_writel(struct brcmstb_pwm *p, u32 value,
static inline struct brcmstb_pwm *to_brcmstb_pwm(struct pwm_chip *chip) static inline struct brcmstb_pwm *to_brcmstb_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct brcmstb_pwm, chip); return pwmchip_get_drvdata(chip);
} }
/* /*
...@@ -230,12 +229,14 @@ MODULE_DEVICE_TABLE(of, brcmstb_pwm_of_match); ...@@ -230,12 +229,14 @@ MODULE_DEVICE_TABLE(of, brcmstb_pwm_of_match);
static int brcmstb_pwm_probe(struct platform_device *pdev) static int brcmstb_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct brcmstb_pwm *p; struct brcmstb_pwm *p;
int ret; int ret;
p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 2, sizeof(*p));
if (!p) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
p = to_brcmstb_pwm(chip);
p->clk = devm_clk_get_enabled(&pdev->dev, NULL); p->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(p->clk)) if (IS_ERR(p->clk))
...@@ -244,15 +245,13 @@ static int brcmstb_pwm_probe(struct platform_device *pdev) ...@@ -244,15 +245,13 @@ static int brcmstb_pwm_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, p); platform_set_drvdata(pdev, p);
p->chip.dev = &pdev->dev; chip->ops = &brcmstb_pwm_ops;
p->chip.ops = &brcmstb_pwm_ops;
p->chip.npwm = 2;
p->base = devm_platform_ioremap_resource(pdev, 0); p->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(p->base)) if (IS_ERR(p->base))
return PTR_ERR(p->base); return PTR_ERR(p->base);
ret = devm_pwmchip_add(&pdev->dev, &p->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret) if (ret)
return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
......
...@@ -28,12 +28,14 @@ ...@@ -28,12 +28,14 @@
#include <linux/pwm.h> #include <linux/pwm.h>
struct pwm_clk_chip { struct pwm_clk_chip {
struct pwm_chip chip;
struct clk *clk; struct clk *clk;
bool clk_enabled; bool clk_enabled;
}; };
#define to_pwm_clk_chip(_chip) container_of(_chip, struct pwm_clk_chip, chip) static inline struct pwm_clk_chip *to_pwm_clk_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int pwm_clk_apply(struct pwm_chip *chip, struct pwm_device *pwm, static int pwm_clk_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state) const struct pwm_state *state)
...@@ -81,35 +83,36 @@ static const struct pwm_ops pwm_clk_ops = { ...@@ -81,35 +83,36 @@ static const struct pwm_ops pwm_clk_ops = {
static int pwm_clk_probe(struct platform_device *pdev) static int pwm_clk_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct pwm_clk_chip *pcchip; struct pwm_clk_chip *pcchip;
int ret; int ret;
pcchip = devm_kzalloc(&pdev->dev, sizeof(*pcchip), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*pcchip));
if (!pcchip) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
pcchip = to_pwm_clk_chip(chip);
pcchip->clk = devm_clk_get_prepared(&pdev->dev, NULL); pcchip->clk = devm_clk_get_prepared(&pdev->dev, NULL);
if (IS_ERR(pcchip->clk)) if (IS_ERR(pcchip->clk))
return dev_err_probe(&pdev->dev, PTR_ERR(pcchip->clk), return dev_err_probe(&pdev->dev, PTR_ERR(pcchip->clk),
"Failed to get clock\n"); "Failed to get clock\n");
pcchip->chip.dev = &pdev->dev; chip->ops = &pwm_clk_ops;
pcchip->chip.ops = &pwm_clk_ops;
pcchip->chip.npwm = 1;
ret = pwmchip_add(&pcchip->chip); ret = pwmchip_add(chip);
if (ret < 0) if (ret < 0)
return dev_err_probe(&pdev->dev, ret, "Failed to add pwm chip\n"); return dev_err_probe(&pdev->dev, ret, "Failed to add pwm chip\n");
platform_set_drvdata(pdev, pcchip); platform_set_drvdata(pdev, chip);
return 0; return 0;
} }
static void pwm_clk_remove(struct platform_device *pdev) static void pwm_clk_remove(struct platform_device *pdev)
{ {
struct pwm_clk_chip *pcchip = platform_get_drvdata(pdev); struct pwm_chip *chip = platform_get_drvdata(pdev);
struct pwm_clk_chip *pcchip = to_pwm_clk_chip(chip);
pwmchip_remove(&pcchip->chip); pwmchip_remove(chip);
if (pcchip->clk_enabled) if (pcchip->clk_enabled)
clk_disable(pcchip->clk); clk_disable(pcchip->clk);
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <linux/pwm.h> #include <linux/pwm.h>
struct clps711x_chip { struct clps711x_chip {
struct pwm_chip chip;
void __iomem *pmpcon; void __iomem *pmpcon;
struct clk *clk; struct clk *clk;
spinlock_t lock; spinlock_t lock;
...@@ -20,7 +19,7 @@ struct clps711x_chip { ...@@ -20,7 +19,7 @@ struct clps711x_chip {
static inline struct clps711x_chip *to_clps711x_chip(struct pwm_chip *chip) static inline struct clps711x_chip *to_clps711x_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct clps711x_chip, chip); return pwmchip_get_drvdata(chip);
} }
static int clps711x_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) static int clps711x_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
...@@ -74,22 +73,15 @@ static const struct pwm_ops clps711x_pwm_ops = { ...@@ -74,22 +73,15 @@ static const struct pwm_ops clps711x_pwm_ops = {
.apply = clps711x_pwm_apply, .apply = clps711x_pwm_apply,
}; };
static struct pwm_device *clps711x_pwm_xlate(struct pwm_chip *chip,
const struct of_phandle_args *args)
{
if (args->args[0] >= chip->npwm)
return ERR_PTR(-EINVAL);
return pwm_request_from_chip(chip, args->args[0], NULL);
}
static int clps711x_pwm_probe(struct platform_device *pdev) static int clps711x_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct clps711x_chip *priv; struct clps711x_chip *priv;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 2, sizeof(*priv));
if (!priv) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
priv = to_clps711x_chip(chip);
priv->pmpcon = devm_platform_ioremap_resource(pdev, 0); priv->pmpcon = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(priv->pmpcon)) if (IS_ERR(priv->pmpcon))
...@@ -99,15 +91,11 @@ static int clps711x_pwm_probe(struct platform_device *pdev) ...@@ -99,15 +91,11 @@ static int clps711x_pwm_probe(struct platform_device *pdev)
if (IS_ERR(priv->clk)) if (IS_ERR(priv->clk))
return PTR_ERR(priv->clk); return PTR_ERR(priv->clk);
priv->chip.ops = &clps711x_pwm_ops; chip->ops = &clps711x_pwm_ops;
priv->chip.dev = &pdev->dev;
priv->chip.npwm = 2;
priv->chip.of_xlate = clps711x_pwm_xlate;
priv->chip.of_pwm_n_cells = 1;
spin_lock_init(&priv->lock); spin_lock_init(&priv->lock);
return devm_pwmchip_add(&pdev->dev, &priv->chip); return devm_pwmchip_add(&pdev->dev, chip);
} }
static const struct of_device_id __maybe_unused clps711x_pwm_dt_ids[] = { static const struct of_device_id __maybe_unused clps711x_pwm_dt_ids[] = {
......
...@@ -26,17 +26,15 @@ ...@@ -26,17 +26,15 @@
/** /**
* struct crystalcove_pwm - Crystal Cove PWM controller * struct crystalcove_pwm - Crystal Cove PWM controller
* @chip: the abstract pwm_chip structure.
* @regmap: the regmap from the parent device. * @regmap: the regmap from the parent device.
*/ */
struct crystalcove_pwm { struct crystalcove_pwm {
struct pwm_chip chip;
struct regmap *regmap; struct regmap *regmap;
}; };
static inline struct crystalcove_pwm *to_crc_pwm(struct pwm_chip *chip) static inline struct crystalcove_pwm *to_crc_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct crystalcove_pwm, chip); return pwmchip_get_drvdata(chip);
} }
static int crc_pwm_calc_clk_div(int period_ns) static int crc_pwm_calc_clk_div(int period_ns)
...@@ -55,7 +53,7 @@ static int crc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -55,7 +53,7 @@ static int crc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state) const struct pwm_state *state)
{ {
struct crystalcove_pwm *crc_pwm = to_crc_pwm(chip); struct crystalcove_pwm *crc_pwm = to_crc_pwm(chip);
struct device *dev = crc_pwm->chip.dev; struct device *dev = pwmchip_parent(chip);
int err; int err;
if (state->period > PWM_MAX_PERIOD_NS) { if (state->period > PWM_MAX_PERIOD_NS) {
...@@ -125,7 +123,7 @@ static int crc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -125,7 +123,7 @@ static int crc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
struct pwm_state *state) struct pwm_state *state)
{ {
struct crystalcove_pwm *crc_pwm = to_crc_pwm(chip); struct crystalcove_pwm *crc_pwm = to_crc_pwm(chip);
struct device *dev = crc_pwm->chip.dev; struct device *dev = pwmchip_parent(chip);
unsigned int clk_div, clk_div_reg, duty_cycle_reg; unsigned int clk_div, clk_div_reg, duty_cycle_reg;
int error; int error;
...@@ -160,22 +158,22 @@ static const struct pwm_ops crc_pwm_ops = { ...@@ -160,22 +158,22 @@ static const struct pwm_ops crc_pwm_ops = {
static int crystalcove_pwm_probe(struct platform_device *pdev) static int crystalcove_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct crystalcove_pwm *crc_pwm; struct crystalcove_pwm *crc_pwm;
struct device *dev = pdev->dev.parent; struct device *dev = pdev->dev.parent;
struct intel_soc_pmic *pmic = dev_get_drvdata(dev); struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
crc_pwm = devm_kzalloc(&pdev->dev, sizeof(*crc_pwm), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*crc_pwm));
if (!crc_pwm) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
crc_pwm = to_crc_pwm(chip);
crc_pwm->chip.dev = &pdev->dev; chip->ops = &crc_pwm_ops;
crc_pwm->chip.ops = &crc_pwm_ops;
crc_pwm->chip.npwm = 1;
/* get the PMIC regmap */ /* get the PMIC regmap */
crc_pwm->regmap = pmic->regmap; crc_pwm->regmap = pmic->regmap;
return devm_pwmchip_add(&pdev->dev, &crc_pwm->chip); return devm_pwmchip_add(&pdev->dev, chip);
} }
static struct platform_driver crystalcove_pwm_driver = { static struct platform_driver crystalcove_pwm_driver = {
......
...@@ -19,13 +19,11 @@ ...@@ -19,13 +19,11 @@
* struct cros_ec_pwm_device - Driver data for EC PWM * struct cros_ec_pwm_device - Driver data for EC PWM
* *
* @ec: Pointer to EC device * @ec: Pointer to EC device
* @chip: PWM controller chip
* @use_pwm_type: Use PWM types instead of generic channels * @use_pwm_type: Use PWM types instead of generic channels
* @channel: array with per-channel data * @channel: array with per-channel data
*/ */
struct cros_ec_pwm_device { struct cros_ec_pwm_device {
struct cros_ec_device *ec; struct cros_ec_device *ec;
struct pwm_chip chip;
bool use_pwm_type; bool use_pwm_type;
struct cros_ec_pwm *channel; struct cros_ec_pwm *channel;
}; };
...@@ -40,7 +38,7 @@ struct cros_ec_pwm { ...@@ -40,7 +38,7 @@ struct cros_ec_pwm {
static inline struct cros_ec_pwm_device *pwm_to_cros_ec_pwm(struct pwm_chip *chip) static inline struct cros_ec_pwm_device *pwm_to_cros_ec_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct cros_ec_pwm_device, chip); return pwmchip_get_drvdata(chip);
} }
static int cros_ec_dt_type_to_pwm_type(u8 dt_index, u8 *pwm_type) static int cros_ec_dt_type_to_pwm_type(u8 dt_index, u8 *pwm_type)
...@@ -93,9 +91,8 @@ static int cros_ec_pwm_set_duty(struct cros_ec_pwm_device *ec_pwm, u8 index, ...@@ -93,9 +91,8 @@ static int cros_ec_pwm_set_duty(struct cros_ec_pwm_device *ec_pwm, u8 index,
return cros_ec_cmd_xfer_status(ec, msg); return cros_ec_cmd_xfer_status(ec, msg);
} }
static int cros_ec_pwm_get_duty(struct cros_ec_pwm_device *ec_pwm, u8 index) static int cros_ec_pwm_get_duty(struct cros_ec_device *ec, bool use_pwm_type, u8 index)
{ {
struct cros_ec_device *ec = ec_pwm->ec;
struct { struct {
struct cros_ec_command msg; struct cros_ec_command msg;
union { union {
...@@ -115,7 +112,7 @@ static int cros_ec_pwm_get_duty(struct cros_ec_pwm_device *ec_pwm, u8 index) ...@@ -115,7 +112,7 @@ static int cros_ec_pwm_get_duty(struct cros_ec_pwm_device *ec_pwm, u8 index)
msg->insize = sizeof(*resp); msg->insize = sizeof(*resp);
msg->outsize = sizeof(*params); msg->outsize = sizeof(*params);
if (ec_pwm->use_pwm_type) { if (use_pwm_type) {
ret = cros_ec_dt_type_to_pwm_type(index, &params->pwm_type); ret = cros_ec_dt_type_to_pwm_type(index, &params->pwm_type);
if (ret) { if (ret) {
dev_err(ec->dev, "Invalid PWM type index: %d\n", index); dev_err(ec->dev, "Invalid PWM type index: %d\n", index);
...@@ -171,9 +168,9 @@ static int cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -171,9 +168,9 @@ static int cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
struct cros_ec_pwm *channel = &ec_pwm->channel[pwm->hwpwm]; struct cros_ec_pwm *channel = &ec_pwm->channel[pwm->hwpwm];
int ret; int ret;
ret = cros_ec_pwm_get_duty(ec_pwm, pwm->hwpwm); ret = cros_ec_pwm_get_duty(ec_pwm->ec, ec_pwm->use_pwm_type, pwm->hwpwm);
if (ret < 0) { if (ret < 0) {
dev_err(chip->dev, "error getting initial duty: %d\n", ret); dev_err(pwmchip_parent(chip), "error getting initial duty: %d\n", ret);
return ret; return ret;
} }
...@@ -226,13 +223,17 @@ static const struct pwm_ops cros_ec_pwm_ops = { ...@@ -226,13 +223,17 @@ static const struct pwm_ops cros_ec_pwm_ops = {
* of PWMs it supports directly, so we have to read the pwm duty cycle for * of PWMs it supports directly, so we have to read the pwm duty cycle for
* subsequent channels until we get an error. * subsequent channels until we get an error.
*/ */
static int cros_ec_num_pwms(struct cros_ec_pwm_device *ec_pwm) static int cros_ec_num_pwms(struct cros_ec_device *ec)
{ {
int i, ret; int i, ret;
/* The index field is only 8 bits */ /* The index field is only 8 bits */
for (i = 0; i <= U8_MAX; i++) { for (i = 0; i <= U8_MAX; i++) {
ret = cros_ec_pwm_get_duty(ec_pwm, i); /*
* Note that this function is only called when use_pwm_type is
* false. With use_pwm_type == true the number of PWMs is fixed.
*/
ret = cros_ec_pwm_get_duty(ec, false, i);
/* /*
* We look for SUCCESS, INVALID_COMMAND, or INVALID_PARAM * We look for SUCCESS, INVALID_COMMAND, or INVALID_PARAM
* responses; everything else is treated as an error. * responses; everything else is treated as an error.
...@@ -261,34 +262,34 @@ static int cros_ec_pwm_probe(struct platform_device *pdev) ...@@ -261,34 +262,34 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct cros_ec_pwm_device *ec_pwm; struct cros_ec_pwm_device *ec_pwm;
struct pwm_chip *chip; struct pwm_chip *chip;
bool use_pwm_type = false;
unsigned int npwm;
int ret; int ret;
if (!ec) if (!ec)
return dev_err_probe(dev, -EINVAL, "no parent EC device\n"); return dev_err_probe(dev, -EINVAL, "no parent EC device\n");
ec_pwm = devm_kzalloc(dev, sizeof(*ec_pwm), GFP_KERNEL); if (of_device_is_compatible(np, "google,cros-ec-pwm-type")) {
if (!ec_pwm) use_pwm_type = true;
return -ENOMEM; npwm = CROS_EC_PWM_DT_COUNT;
chip = &ec_pwm->chip; } else {
ec_pwm->ec = ec; ret = cros_ec_num_pwms(ec);
if (ret < 0)
return dev_err_probe(dev, ret, "Couldn't find PWMs\n");
npwm = ret;
}
chip = devm_pwmchip_alloc(dev, npwm, sizeof(*ec_pwm));
if (IS_ERR(chip))
return PTR_ERR(chip);
if (of_device_is_compatible(np, "google,cros-ec-pwm-type")) ec_pwm = pwm_to_cros_ec_pwm(chip);
ec_pwm->use_pwm_type = true; ec_pwm->use_pwm_type = use_pwm_type;
ec_pwm->ec = ec;
/* PWM chip */ /* PWM chip */
chip->dev = dev;
chip->ops = &cros_ec_pwm_ops; chip->ops = &cros_ec_pwm_ops;
chip->of_xlate = cros_ec_pwm_xlate; chip->of_xlate = cros_ec_pwm_xlate;
chip->of_pwm_n_cells = 1;
if (ec_pwm->use_pwm_type) {
chip->npwm = CROS_EC_PWM_DT_COUNT;
} else {
ret = cros_ec_num_pwms(ec_pwm);
if (ret < 0)
return dev_err_probe(dev, ret, "Couldn't find PWMs\n");
chip->npwm = ret;
}
ec_pwm->channel = devm_kcalloc(dev, chip->npwm, sizeof(*ec_pwm->channel), ec_pwm->channel = devm_kcalloc(dev, chip->npwm, sizeof(*ec_pwm->channel),
GFP_KERNEL); GFP_KERNEL);
......
...@@ -105,12 +105,12 @@ static int dwc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -105,12 +105,12 @@ static int dwc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
if (state->enabled) { if (state->enabled) {
if (!pwm->state.enabled) if (!pwm->state.enabled)
pm_runtime_get_sync(chip->dev); pm_runtime_get_sync(pwmchip_parent(chip));
return __dwc_pwm_configure_timer(dwc, pwm, state); return __dwc_pwm_configure_timer(dwc, pwm, state);
} else { } else {
if (pwm->state.enabled) { if (pwm->state.enabled) {
__dwc_pwm_set_enable(dwc, pwm->hwpwm, false); __dwc_pwm_set_enable(dwc, pwm->hwpwm, false);
pm_runtime_put_sync(chip->dev); pm_runtime_put_sync(pwmchip_parent(chip));
} }
} }
...@@ -124,7 +124,7 @@ static int dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -124,7 +124,7 @@ static int dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
u64 duty, period; u64 duty, period;
u32 ctrl, ld, ld2; u32 ctrl, ld, ld2;
pm_runtime_get_sync(chip->dev); pm_runtime_get_sync(pwmchip_parent(chip));
ctrl = dwc_pwm_readl(dwc, DWC_TIM_CTRL(pwm->hwpwm)); ctrl = dwc_pwm_readl(dwc, DWC_TIM_CTRL(pwm->hwpwm));
ld = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT(pwm->hwpwm)); ld = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT(pwm->hwpwm));
...@@ -149,7 +149,7 @@ static int dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -149,7 +149,7 @@ static int dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
state->period = period; state->period = period;
state->duty_cycle = duty; state->duty_cycle = duty;
pm_runtime_put_sync(chip->dev); pm_runtime_put_sync(pwmchip_parent(chip));
return 0; return 0;
} }
...@@ -159,21 +159,21 @@ static const struct pwm_ops dwc_pwm_ops = { ...@@ -159,21 +159,21 @@ static const struct pwm_ops dwc_pwm_ops = {
.get_state = dwc_pwm_get_state, .get_state = dwc_pwm_get_state,
}; };
struct dwc_pwm *dwc_pwm_alloc(struct device *dev) struct pwm_chip *dwc_pwm_alloc(struct device *dev)
{ {
struct pwm_chip *chip;
struct dwc_pwm *dwc; struct dwc_pwm *dwc;
dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); chip = devm_pwmchip_alloc(dev, DWC_TIMERS_TOTAL, sizeof(*dwc));
if (!dwc) if (IS_ERR(chip))
return NULL; return chip;
dwc = to_dwc_pwm(chip);
dwc->clk_ns = 10; dwc->clk_ns = 10;
dwc->chip.dev = dev; chip->ops = &dwc_pwm_ops;
dwc->chip.ops = &dwc_pwm_ops;
dwc->chip.npwm = DWC_TIMERS_TOTAL;
dev_set_drvdata(dev, dwc); dev_set_drvdata(dev, chip);
return dwc; return chip;
} }
EXPORT_SYMBOL_GPL(dwc_pwm_alloc); EXPORT_SYMBOL_GPL(dwc_pwm_alloc);
......
...@@ -25,39 +25,54 @@ ...@@ -25,39 +25,54 @@
#include "pwm-dwc.h" #include "pwm-dwc.h"
static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id) /* Elkhart Lake */
static const struct dwc_pwm_info ehl_pwm_info = {
.nr = 2,
.size = 0x1000,
};
static int dwc_pwm_init_one(struct device *dev, void __iomem *base, unsigned int offset)
{ {
struct device *dev = &pci->dev; struct pwm_chip *chip;
struct dwc_pwm *dwc; struct dwc_pwm *dwc;
int ret;
dwc = dwc_pwm_alloc(dev); chip = dwc_pwm_alloc(dev);
if (!dwc) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
dwc = to_dwc_pwm(chip);
dwc->base = base + offset;
return devm_pwmchip_add(dev, chip);
}
static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)
{
const struct dwc_pwm_info *info;
struct device *dev = &pci->dev;
int i, ret;
ret = pcim_enable_device(pci); ret = pcim_enable_device(pci);
if (ret) { if (ret)
dev_err(dev, "Failed to enable device (%pe)\n", ERR_PTR(ret)); return dev_err_probe(dev, ret, "Failed to enable device\n");
return ret;
}
pci_set_master(pci); pci_set_master(pci);
ret = pcim_iomap_regions(pci, BIT(0), pci_name(pci)); ret = pcim_iomap_regions(pci, BIT(0), pci_name(pci));
if (ret) { if (ret)
dev_err(dev, "Failed to iomap PCI BAR (%pe)\n", ERR_PTR(ret)); return dev_err_probe(dev, ret, "Failed to iomap PCI BAR\n");
return ret;
}
dwc->base = pcim_iomap_table(pci)[0]; info = (const struct dwc_pwm_info *)id->driver_data;
if (!dwc->base) {
dev_err(dev, "Base address missing\n");
return -ENOMEM;
}
ret = devm_pwmchip_add(dev, &dwc->chip); for (i = 0; i < info->nr; i++) {
/*
* No need to check for pcim_iomap_table() failure,
* pcim_iomap_regions() already does it for us.
*/
ret = dwc_pwm_init_one(dev, pcim_iomap_table(pci)[0], i * info->size);
if (ret) if (ret)
return ret; return ret;
}
pm_runtime_put(dev); pm_runtime_put(dev);
pm_runtime_allow(dev); pm_runtime_allow(dev);
...@@ -73,14 +88,14 @@ static void dwc_pwm_remove(struct pci_dev *pci) ...@@ -73,14 +88,14 @@ static void dwc_pwm_remove(struct pci_dev *pci)
static int dwc_pwm_suspend(struct device *dev) static int dwc_pwm_suspend(struct device *dev)
{ {
struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct dwc_pwm *dwc = pci_get_drvdata(pdev); struct dwc_pwm *dwc = to_dwc_pwm(chip);
int i; int i;
for (i = 0; i < DWC_TIMERS_TOTAL; i++) { for (i = 0; i < DWC_TIMERS_TOTAL; i++) {
if (dwc->chip.pwms[i].state.enabled) { if (chip->pwms[i].state.enabled) {
dev_err(dev, "PWM %u in use by consumer (%s)\n", dev_err(dev, "PWM %u in use by consumer (%s)\n",
i, dwc->chip.pwms[i].label); i, chip->pwms[i].label);
return -EBUSY; return -EBUSY;
} }
dwc->ctx[i].cnt = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT(i)); dwc->ctx[i].cnt = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT(i));
...@@ -93,8 +108,8 @@ static int dwc_pwm_suspend(struct device *dev) ...@@ -93,8 +108,8 @@ static int dwc_pwm_suspend(struct device *dev)
static int dwc_pwm_resume(struct device *dev) static int dwc_pwm_resume(struct device *dev)
{ {
struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct dwc_pwm *dwc = pci_get_drvdata(pdev); struct dwc_pwm *dwc = to_dwc_pwm(chip);
int i; int i;
for (i = 0; i < DWC_TIMERS_TOTAL; i++) { for (i = 0; i < DWC_TIMERS_TOTAL; i++) {
...@@ -109,7 +124,7 @@ static int dwc_pwm_resume(struct device *dev) ...@@ -109,7 +124,7 @@ static int dwc_pwm_resume(struct device *dev)
static DEFINE_SIMPLE_DEV_PM_OPS(dwc_pwm_pm_ops, dwc_pwm_suspend, dwc_pwm_resume); static DEFINE_SIMPLE_DEV_PM_OPS(dwc_pwm_pm_ops, dwc_pwm_suspend, dwc_pwm_resume);
static const struct pci_device_id dwc_pwm_id_table[] = { static const struct pci_device_id dwc_pwm_id_table[] = {
{ PCI_VDEVICE(INTEL, 0x4bb7) }, /* Elkhart Lake */ { PCI_VDEVICE(INTEL, 0x4bb7), (kernel_ulong_t)&ehl_pwm_info },
{ } /* Terminating Entry */ { } /* Terminating Entry */
}; };
MODULE_DEVICE_TABLE(pci, dwc_pwm_id_table); MODULE_DEVICE_TABLE(pci, dwc_pwm_id_table);
...@@ -120,7 +135,7 @@ static struct pci_driver dwc_pwm_driver = { ...@@ -120,7 +135,7 @@ static struct pci_driver dwc_pwm_driver = {
.remove = dwc_pwm_remove, .remove = dwc_pwm_remove,
.id_table = dwc_pwm_id_table, .id_table = dwc_pwm_id_table,
.driver = { .driver = {
.pm = pm_ptr(&dwc_pwm_pm_ops), .pm = pm_sleep_ptr(&dwc_pwm_pm_ops),
}, },
}; };
......
...@@ -33,6 +33,11 @@ MODULE_IMPORT_NS(dwc_pwm); ...@@ -33,6 +33,11 @@ MODULE_IMPORT_NS(dwc_pwm);
#define DWC_TIM_CTRL_INT_MASK BIT(2) #define DWC_TIM_CTRL_INT_MASK BIT(2)
#define DWC_TIM_CTRL_PWM BIT(3) #define DWC_TIM_CTRL_PWM BIT(3)
struct dwc_pwm_info {
unsigned int nr;
unsigned int size;
};
struct dwc_pwm_ctx { struct dwc_pwm_ctx {
u32 cnt; u32 cnt;
u32 cnt2; u32 cnt2;
...@@ -40,12 +45,15 @@ struct dwc_pwm_ctx { ...@@ -40,12 +45,15 @@ struct dwc_pwm_ctx {
}; };
struct dwc_pwm { struct dwc_pwm {
struct pwm_chip chip;
void __iomem *base; void __iomem *base;
unsigned int clk_ns; unsigned int clk_ns;
struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL]; struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL];
}; };
#define to_dwc_pwm(p) (container_of((p), struct dwc_pwm, chip))
static inline struct dwc_pwm *to_dwc_pwm(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static inline u32 dwc_pwm_readl(struct dwc_pwm *dwc, u32 offset) static inline u32 dwc_pwm_readl(struct dwc_pwm *dwc, u32 offset)
{ {
...@@ -57,4 +65,4 @@ static inline void dwc_pwm_writel(struct dwc_pwm *dwc, u32 value, u32 offset) ...@@ -57,4 +65,4 @@ static inline void dwc_pwm_writel(struct dwc_pwm *dwc, u32 value, u32 offset)
writel(value, dwc->base + offset); writel(value, dwc->base + offset);
} }
extern struct dwc_pwm *dwc_pwm_alloc(struct device *dev); extern struct pwm_chip *dwc_pwm_alloc(struct device *dev);
...@@ -36,24 +36,23 @@ ...@@ -36,24 +36,23 @@
struct ep93xx_pwm { struct ep93xx_pwm {
void __iomem *base; void __iomem *base;
struct clk *clk; struct clk *clk;
struct pwm_chip chip;
}; };
static inline struct ep93xx_pwm *to_ep93xx_pwm(struct pwm_chip *chip) static inline struct ep93xx_pwm *to_ep93xx_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct ep93xx_pwm, chip); return pwmchip_get_drvdata(chip);
} }
static int ep93xx_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) static int ep93xx_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
{ {
struct platform_device *pdev = to_platform_device(chip->dev); struct platform_device *pdev = to_platform_device(pwmchip_parent(chip));
return ep93xx_pwm_acquire_gpio(pdev); return ep93xx_pwm_acquire_gpio(pdev);
} }
static void ep93xx_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) static void ep93xx_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
{ {
struct platform_device *pdev = to_platform_device(chip->dev); struct platform_device *pdev = to_platform_device(pwmchip_parent(chip));
ep93xx_pwm_release_gpio(pdev); ep93xx_pwm_release_gpio(pdev);
} }
...@@ -163,12 +162,14 @@ static const struct pwm_ops ep93xx_pwm_ops = { ...@@ -163,12 +162,14 @@ static const struct pwm_ops ep93xx_pwm_ops = {
static int ep93xx_pwm_probe(struct platform_device *pdev) static int ep93xx_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct ep93xx_pwm *ep93xx_pwm; struct ep93xx_pwm *ep93xx_pwm;
int ret; int ret;
ep93xx_pwm = devm_kzalloc(&pdev->dev, sizeof(*ep93xx_pwm), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*ep93xx_pwm));
if (!ep93xx_pwm) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
ep93xx_pwm = to_ep93xx_pwm(chip);
ep93xx_pwm->base = devm_platform_ioremap_resource(pdev, 0); ep93xx_pwm->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(ep93xx_pwm->base)) if (IS_ERR(ep93xx_pwm->base))
...@@ -178,11 +179,9 @@ static int ep93xx_pwm_probe(struct platform_device *pdev) ...@@ -178,11 +179,9 @@ static int ep93xx_pwm_probe(struct platform_device *pdev)
if (IS_ERR(ep93xx_pwm->clk)) if (IS_ERR(ep93xx_pwm->clk))
return PTR_ERR(ep93xx_pwm->clk); return PTR_ERR(ep93xx_pwm->clk);
ep93xx_pwm->chip.dev = &pdev->dev; chip->ops = &ep93xx_pwm_ops;
ep93xx_pwm->chip.ops = &ep93xx_pwm_ops;
ep93xx_pwm->chip.npwm = 1;
ret = devm_pwmchip_add(&pdev->dev, &ep93xx_pwm->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -40,7 +40,6 @@ struct fsl_pwm_periodcfg { ...@@ -40,7 +40,6 @@ struct fsl_pwm_periodcfg {
}; };
struct fsl_pwm_chip { struct fsl_pwm_chip {
struct pwm_chip chip;
struct mutex lock; struct mutex lock;
struct regmap *regmap; struct regmap *regmap;
...@@ -55,7 +54,7 @@ struct fsl_pwm_chip { ...@@ -55,7 +54,7 @@ struct fsl_pwm_chip {
static inline struct fsl_pwm_chip *to_fsl_chip(struct pwm_chip *chip) static inline struct fsl_pwm_chip *to_fsl_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct fsl_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static void ftm_clear_write_protection(struct fsl_pwm_chip *fpc) static void ftm_clear_write_protection(struct fsl_pwm_chip *fpc)
...@@ -221,10 +220,11 @@ static bool fsl_pwm_is_other_pwm_enabled(struct fsl_pwm_chip *fpc, ...@@ -221,10 +220,11 @@ static bool fsl_pwm_is_other_pwm_enabled(struct fsl_pwm_chip *fpc,
return false; return false;
} }
static int fsl_pwm_apply_config(struct fsl_pwm_chip *fpc, static int fsl_pwm_apply_config(struct pwm_chip *chip,
struct pwm_device *pwm, struct pwm_device *pwm,
const struct pwm_state *newstate) const struct pwm_state *newstate)
{ {
struct fsl_pwm_chip *fpc = to_fsl_chip(chip);
unsigned int duty; unsigned int duty;
u32 reg_polarity; u32 reg_polarity;
...@@ -232,7 +232,7 @@ static int fsl_pwm_apply_config(struct fsl_pwm_chip *fpc, ...@@ -232,7 +232,7 @@ static int fsl_pwm_apply_config(struct fsl_pwm_chip *fpc,
bool do_write_period = false; bool do_write_period = false;
if (!fsl_pwm_calculate_period(fpc, newstate->period, &periodcfg)) { if (!fsl_pwm_calculate_period(fpc, newstate->period, &periodcfg)) {
dev_err(fpc->chip.dev, "failed to calculate new period\n"); dev_err(pwmchip_parent(chip), "failed to calculate new period\n");
return -EINVAL; return -EINVAL;
} }
...@@ -246,7 +246,7 @@ static int fsl_pwm_apply_config(struct fsl_pwm_chip *fpc, ...@@ -246,7 +246,7 @@ static int fsl_pwm_apply_config(struct fsl_pwm_chip *fpc,
*/ */
else if (!fsl_pwm_periodcfg_are_equal(&fpc->period, &periodcfg)) { else if (!fsl_pwm_periodcfg_are_equal(&fpc->period, &periodcfg)) {
if (fsl_pwm_is_other_pwm_enabled(fpc, pwm)) { if (fsl_pwm_is_other_pwm_enabled(fpc, pwm)) {
dev_err(fpc->chip.dev, dev_err(pwmchip_parent(chip),
"Cannot change period for PWM %u, disable other PWMs first\n", "Cannot change period for PWM %u, disable other PWMs first\n",
pwm->hwpwm); pwm->hwpwm);
return -EBUSY; return -EBUSY;
...@@ -322,7 +322,7 @@ static int fsl_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -322,7 +322,7 @@ static int fsl_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
goto end_mutex; goto end_mutex;
} }
ret = fsl_pwm_apply_config(fpc, pwm, newstate); ret = fsl_pwm_apply_config(chip, pwm, newstate);
if (ret) if (ret)
goto end_mutex; goto end_mutex;
...@@ -392,18 +392,19 @@ static const struct regmap_config fsl_pwm_regmap_config = { ...@@ -392,18 +392,19 @@ static const struct regmap_config fsl_pwm_regmap_config = {
static int fsl_pwm_probe(struct platform_device *pdev) static int fsl_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct fsl_pwm_chip *fpc; struct fsl_pwm_chip *fpc;
void __iomem *base; void __iomem *base;
int ret; int ret;
fpc = devm_kzalloc(&pdev->dev, sizeof(*fpc), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 8, sizeof(*fpc));
if (!fpc) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
fpc = to_fsl_chip(chip);
mutex_init(&fpc->lock); mutex_init(&fpc->lock);
fpc->soc = of_device_get_match_data(&pdev->dev); fpc->soc = of_device_get_match_data(&pdev->dev);
fpc->chip.dev = &pdev->dev;
base = devm_platform_ioremap_resource(pdev, 0); base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(base)) if (IS_ERR(base))
...@@ -422,16 +423,16 @@ static int fsl_pwm_probe(struct platform_device *pdev) ...@@ -422,16 +423,16 @@ static int fsl_pwm_probe(struct platform_device *pdev)
return PTR_ERR(fpc->clk[FSL_PWM_CLK_SYS]); return PTR_ERR(fpc->clk[FSL_PWM_CLK_SYS]);
} }
fpc->clk[FSL_PWM_CLK_FIX] = devm_clk_get(fpc->chip.dev, "ftm_fix"); fpc->clk[FSL_PWM_CLK_FIX] = devm_clk_get(&pdev->dev, "ftm_fix");
if (IS_ERR(fpc->clk[FSL_PWM_CLK_FIX])) if (IS_ERR(fpc->clk[FSL_PWM_CLK_FIX]))
return PTR_ERR(fpc->clk[FSL_PWM_CLK_FIX]); return PTR_ERR(fpc->clk[FSL_PWM_CLK_FIX]);
fpc->clk[FSL_PWM_CLK_EXT] = devm_clk_get(fpc->chip.dev, "ftm_ext"); fpc->clk[FSL_PWM_CLK_EXT] = devm_clk_get(&pdev->dev, "ftm_ext");
if (IS_ERR(fpc->clk[FSL_PWM_CLK_EXT])) if (IS_ERR(fpc->clk[FSL_PWM_CLK_EXT]))
return PTR_ERR(fpc->clk[FSL_PWM_CLK_EXT]); return PTR_ERR(fpc->clk[FSL_PWM_CLK_EXT]);
fpc->clk[FSL_PWM_CLK_CNTEN] = fpc->clk[FSL_PWM_CLK_CNTEN] =
devm_clk_get(fpc->chip.dev, "ftm_cnt_clk_en"); devm_clk_get(&pdev->dev, "ftm_cnt_clk_en");
if (IS_ERR(fpc->clk[FSL_PWM_CLK_CNTEN])) if (IS_ERR(fpc->clk[FSL_PWM_CLK_CNTEN]))
return PTR_ERR(fpc->clk[FSL_PWM_CLK_CNTEN]); return PTR_ERR(fpc->clk[FSL_PWM_CLK_CNTEN]);
...@@ -443,17 +444,15 @@ static int fsl_pwm_probe(struct platform_device *pdev) ...@@ -443,17 +444,15 @@ static int fsl_pwm_probe(struct platform_device *pdev)
if (IS_ERR(fpc->ipg_clk)) if (IS_ERR(fpc->ipg_clk))
fpc->ipg_clk = fpc->clk[FSL_PWM_CLK_SYS]; fpc->ipg_clk = fpc->clk[FSL_PWM_CLK_SYS];
chip->ops = &fsl_pwm_ops;
fpc->chip.ops = &fsl_pwm_ops; ret = devm_pwmchip_add(&pdev->dev, chip);
fpc->chip.npwm = 8;
ret = devm_pwmchip_add(&pdev->dev, &fpc->chip);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);
return ret; return ret;
} }
platform_set_drvdata(pdev, fpc); platform_set_drvdata(pdev, chip);
return fsl_pwm_init(fpc); return fsl_pwm_init(fpc);
} }
...@@ -461,14 +460,15 @@ static int fsl_pwm_probe(struct platform_device *pdev) ...@@ -461,14 +460,15 @@ static int fsl_pwm_probe(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int fsl_pwm_suspend(struct device *dev) static int fsl_pwm_suspend(struct device *dev)
{ {
struct fsl_pwm_chip *fpc = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct fsl_pwm_chip *fpc = to_fsl_chip(chip);
int i; int i;
regcache_cache_only(fpc->regmap, true); regcache_cache_only(fpc->regmap, true);
regcache_mark_dirty(fpc->regmap); regcache_mark_dirty(fpc->regmap);
for (i = 0; i < fpc->chip.npwm; i++) { for (i = 0; i < chip->npwm; i++) {
struct pwm_device *pwm = &fpc->chip.pwms[i]; struct pwm_device *pwm = &chip->pwms[i];
if (!test_bit(PWMF_REQUESTED, &pwm->flags)) if (!test_bit(PWMF_REQUESTED, &pwm->flags))
continue; continue;
...@@ -487,11 +487,12 @@ static int fsl_pwm_suspend(struct device *dev) ...@@ -487,11 +487,12 @@ static int fsl_pwm_suspend(struct device *dev)
static int fsl_pwm_resume(struct device *dev) static int fsl_pwm_resume(struct device *dev)
{ {
struct fsl_pwm_chip *fpc = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct fsl_pwm_chip *fpc = to_fsl_chip(chip);
int i; int i;
for (i = 0; i < fpc->chip.npwm; i++) { for (i = 0; i < chip->npwm; i++) {
struct pwm_device *pwm = &fpc->chip.pwms[i]; struct pwm_device *pwm = &chip->pwms[i];
if (!test_bit(PWMF_REQUESTED, &pwm->flags)) if (!test_bit(PWMF_REQUESTED, &pwm->flags))
continue; continue;
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#define PWM_DUTY_MASK GENMASK(31, 0) #define PWM_DUTY_MASK GENMASK(31, 0)
struct hibvt_pwm_chip { struct hibvt_pwm_chip {
struct pwm_chip chip;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
struct reset_control *rstc; struct reset_control *rstc;
...@@ -65,7 +64,7 @@ static const struct hibvt_pwm_soc hi3559v100_soc_info = { ...@@ -65,7 +64,7 @@ static const struct hibvt_pwm_soc hi3559v100_soc_info = {
static inline struct hibvt_pwm_chip *to_hibvt_pwm_chip(struct pwm_chip *chip) static inline struct hibvt_pwm_chip *to_hibvt_pwm_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct hibvt_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static void hibvt_pwm_set_bits(void __iomem *base, u32 offset, static void hibvt_pwm_set_bits(void __iomem *base, u32 offset,
...@@ -191,72 +190,71 @@ static int hibvt_pwm_probe(struct platform_device *pdev) ...@@ -191,72 +190,71 @@ static int hibvt_pwm_probe(struct platform_device *pdev)
{ {
const struct hibvt_pwm_soc *soc = const struct hibvt_pwm_soc *soc =
of_device_get_match_data(&pdev->dev); of_device_get_match_data(&pdev->dev);
struct hibvt_pwm_chip *pwm_chip; struct pwm_chip *chip;
struct hibvt_pwm_chip *hi_pwm_chip;
int ret, i; int ret, i;
pwm_chip = devm_kzalloc(&pdev->dev, sizeof(*pwm_chip), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, soc->num_pwms, sizeof(*hi_pwm_chip));
if (pwm_chip == NULL) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
hi_pwm_chip = to_hibvt_pwm_chip(chip);
pwm_chip->clk = devm_clk_get(&pdev->dev, NULL); hi_pwm_chip->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(pwm_chip->clk)) { if (IS_ERR(hi_pwm_chip->clk)) {
dev_err(&pdev->dev, "getting clock failed with %ld\n", dev_err(&pdev->dev, "getting clock failed with %ld\n",
PTR_ERR(pwm_chip->clk)); PTR_ERR(hi_pwm_chip->clk));
return PTR_ERR(pwm_chip->clk); return PTR_ERR(hi_pwm_chip->clk);
} }
pwm_chip->chip.ops = &hibvt_pwm_ops; chip->ops = &hibvt_pwm_ops;
pwm_chip->chip.dev = &pdev->dev; hi_pwm_chip->soc = soc;
pwm_chip->chip.npwm = soc->num_pwms;
pwm_chip->soc = soc;
pwm_chip->base = devm_platform_ioremap_resource(pdev, 0); hi_pwm_chip->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(pwm_chip->base)) if (IS_ERR(hi_pwm_chip->base))
return PTR_ERR(pwm_chip->base); return PTR_ERR(hi_pwm_chip->base);
ret = clk_prepare_enable(pwm_chip->clk); ret = clk_prepare_enable(hi_pwm_chip->clk);
if (ret < 0) if (ret < 0)
return ret; return ret;
pwm_chip->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); hi_pwm_chip->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
if (IS_ERR(pwm_chip->rstc)) { if (IS_ERR(hi_pwm_chip->rstc)) {
clk_disable_unprepare(pwm_chip->clk); clk_disable_unprepare(hi_pwm_chip->clk);
return PTR_ERR(pwm_chip->rstc); return PTR_ERR(hi_pwm_chip->rstc);
} }
reset_control_assert(pwm_chip->rstc); reset_control_assert(hi_pwm_chip->rstc);
msleep(30); msleep(30);
reset_control_deassert(pwm_chip->rstc); reset_control_deassert(hi_pwm_chip->rstc);
ret = pwmchip_add(&pwm_chip->chip); ret = pwmchip_add(chip);
if (ret < 0) { if (ret < 0) {
clk_disable_unprepare(pwm_chip->clk); clk_disable_unprepare(hi_pwm_chip->clk);
return ret; return ret;
} }
for (i = 0; i < pwm_chip->chip.npwm; i++) { for (i = 0; i < chip->npwm; i++) {
hibvt_pwm_set_bits(pwm_chip->base, PWM_CTRL_ADDR(i), hibvt_pwm_set_bits(hi_pwm_chip->base, PWM_CTRL_ADDR(i),
PWM_KEEP_MASK, (0x1 << PWM_KEEP_SHIFT)); PWM_KEEP_MASK, (0x1 << PWM_KEEP_SHIFT));
} }
platform_set_drvdata(pdev, pwm_chip); platform_set_drvdata(pdev, chip);
return 0; return 0;
} }
static void hibvt_pwm_remove(struct platform_device *pdev) static void hibvt_pwm_remove(struct platform_device *pdev)
{ {
struct hibvt_pwm_chip *pwm_chip; struct pwm_chip *chip = platform_get_drvdata(pdev);
struct hibvt_pwm_chip *hi_pwm_chip = to_hibvt_pwm_chip(chip);
pwm_chip = platform_get_drvdata(pdev);
pwmchip_remove(&pwm_chip->chip); pwmchip_remove(chip);
reset_control_assert(pwm_chip->rstc); reset_control_assert(hi_pwm_chip->rstc);
msleep(30); msleep(30);
reset_control_deassert(pwm_chip->rstc); reset_control_deassert(hi_pwm_chip->rstc);
clk_disable_unprepare(pwm_chip->clk); clk_disable_unprepare(hi_pwm_chip->clk);
} }
static const struct of_device_id hibvt_pwm_of_match[] = { static const struct of_device_id hibvt_pwm_of_match[] = {
......
...@@ -59,8 +59,6 @@ struct img_pwm_soc_data { ...@@ -59,8 +59,6 @@ struct img_pwm_soc_data {
}; };
struct img_pwm_chip { struct img_pwm_chip {
struct device *dev;
struct pwm_chip chip;
struct clk *pwm_clk; struct clk *pwm_clk;
struct clk *sys_clk; struct clk *sys_clk;
void __iomem *base; void __iomem *base;
...@@ -74,7 +72,7 @@ struct img_pwm_chip { ...@@ -74,7 +72,7 @@ struct img_pwm_chip {
static inline struct img_pwm_chip *to_img_pwm_chip(struct pwm_chip *chip) static inline struct img_pwm_chip *to_img_pwm_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct img_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static inline void img_pwm_writel(struct img_pwm_chip *imgchip, static inline void img_pwm_writel(struct img_pwm_chip *imgchip,
...@@ -99,7 +97,7 @@ static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -99,7 +97,7 @@ static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
if (period_ns < imgchip->min_period_ns || if (period_ns < imgchip->min_period_ns ||
period_ns > imgchip->max_period_ns) { period_ns > imgchip->max_period_ns) {
dev_err(chip->dev, "configured period not in range\n"); dev_err(pwmchip_parent(chip), "configured period not in range\n");
return -ERANGE; return -ERANGE;
} }
...@@ -120,14 +118,14 @@ static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -120,14 +118,14 @@ static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
div = PWM_CTRL_CFG_SUB_DIV0_DIV1; div = PWM_CTRL_CFG_SUB_DIV0_DIV1;
timebase = DIV_ROUND_UP(mul, 512); timebase = DIV_ROUND_UP(mul, 512);
} else { } else {
dev_err(chip->dev, dev_err(pwmchip_parent(chip),
"failed to configure timebase steps/divider value\n"); "failed to configure timebase steps/divider value\n");
return -EINVAL; return -EINVAL;
} }
duty = DIV_ROUND_UP(timebase * duty_ns, period_ns); duty = DIV_ROUND_UP(timebase * duty_ns, period_ns);
ret = pm_runtime_resume_and_get(chip->dev); ret = pm_runtime_resume_and_get(pwmchip_parent(chip));
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -141,8 +139,8 @@ static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -141,8 +139,8 @@ static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
(timebase << PWM_CH_CFG_TMBASE_SHIFT); (timebase << PWM_CH_CFG_TMBASE_SHIFT);
img_pwm_writel(imgchip, PWM_CH_CFG(pwm->hwpwm), val); img_pwm_writel(imgchip, PWM_CH_CFG(pwm->hwpwm), val);
pm_runtime_mark_last_busy(chip->dev); pm_runtime_mark_last_busy(pwmchip_parent(chip));
pm_runtime_put_autosuspend(chip->dev); pm_runtime_put_autosuspend(pwmchip_parent(chip));
return 0; return 0;
} }
...@@ -153,7 +151,7 @@ static int img_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) ...@@ -153,7 +151,7 @@ static int img_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
struct img_pwm_chip *imgchip = to_img_pwm_chip(chip); struct img_pwm_chip *imgchip = to_img_pwm_chip(chip);
int ret; int ret;
ret = pm_runtime_resume_and_get(chip->dev); ret = pm_runtime_resume_and_get(pwmchip_parent(chip));
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -177,8 +175,8 @@ static void img_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) ...@@ -177,8 +175,8 @@ static void img_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
val &= ~BIT(pwm->hwpwm); val &= ~BIT(pwm->hwpwm);
img_pwm_writel(imgchip, PWM_CTRL_CFG, val); img_pwm_writel(imgchip, PWM_CTRL_CFG, val);
pm_runtime_mark_last_busy(chip->dev); pm_runtime_mark_last_busy(pwmchip_parent(chip));
pm_runtime_put_autosuspend(chip->dev); pm_runtime_put_autosuspend(pwmchip_parent(chip));
} }
static int img_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, static int img_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
...@@ -225,7 +223,8 @@ MODULE_DEVICE_TABLE(of, img_pwm_of_match); ...@@ -225,7 +223,8 @@ MODULE_DEVICE_TABLE(of, img_pwm_of_match);
static int img_pwm_runtime_suspend(struct device *dev) static int img_pwm_runtime_suspend(struct device *dev)
{ {
struct img_pwm_chip *imgchip = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct img_pwm_chip *imgchip = to_img_pwm_chip(chip);
clk_disable_unprepare(imgchip->pwm_clk); clk_disable_unprepare(imgchip->pwm_clk);
clk_disable_unprepare(imgchip->sys_clk); clk_disable_unprepare(imgchip->sys_clk);
...@@ -235,7 +234,8 @@ static int img_pwm_runtime_suspend(struct device *dev) ...@@ -235,7 +234,8 @@ static int img_pwm_runtime_suspend(struct device *dev)
static int img_pwm_runtime_resume(struct device *dev) static int img_pwm_runtime_resume(struct device *dev)
{ {
struct img_pwm_chip *imgchip = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct img_pwm_chip *imgchip = to_img_pwm_chip(chip);
int ret; int ret;
ret = clk_prepare_enable(imgchip->sys_clk); ret = clk_prepare_enable(imgchip->sys_clk);
...@@ -259,13 +259,13 @@ static int img_pwm_probe(struct platform_device *pdev) ...@@ -259,13 +259,13 @@ static int img_pwm_probe(struct platform_device *pdev)
int ret; int ret;
u64 val; u64 val;
unsigned long clk_rate; unsigned long clk_rate;
struct pwm_chip *chip;
struct img_pwm_chip *imgchip; struct img_pwm_chip *imgchip;
imgchip = devm_kzalloc(&pdev->dev, sizeof(*imgchip), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, IMG_PWM_NPWM, sizeof(*imgchip));
if (!imgchip) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
imgchip = to_img_pwm_chip(chip);
imgchip->dev = &pdev->dev;
imgchip->base = devm_platform_ioremap_resource(pdev, 0); imgchip->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(imgchip->base)) if (IS_ERR(imgchip->base))
...@@ -290,7 +290,7 @@ static int img_pwm_probe(struct platform_device *pdev) ...@@ -290,7 +290,7 @@ static int img_pwm_probe(struct platform_device *pdev)
return PTR_ERR(imgchip->pwm_clk); return PTR_ERR(imgchip->pwm_clk);
} }
platform_set_drvdata(pdev, imgchip); platform_set_drvdata(pdev, chip);
pm_runtime_set_autosuspend_delay(&pdev->dev, IMG_PWM_PM_TIMEOUT); pm_runtime_set_autosuspend_delay(&pdev->dev, IMG_PWM_PM_TIMEOUT);
pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_use_autosuspend(&pdev->dev);
...@@ -317,11 +317,9 @@ static int img_pwm_probe(struct platform_device *pdev) ...@@ -317,11 +317,9 @@ static int img_pwm_probe(struct platform_device *pdev)
do_div(val, clk_rate); do_div(val, clk_rate);
imgchip->min_period_ns = val; imgchip->min_period_ns = val;
imgchip->chip.dev = &pdev->dev; chip->ops = &img_pwm_ops;
imgchip->chip.ops = &img_pwm_ops;
imgchip->chip.npwm = IMG_PWM_NPWM;
ret = pwmchip_add(&imgchip->chip); ret = pwmchip_add(chip);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "pwmchip_add failed: %d\n", ret); dev_err(&pdev->dev, "pwmchip_add failed: %d\n", ret);
goto err_suspend; goto err_suspend;
...@@ -340,19 +338,20 @@ static int img_pwm_probe(struct platform_device *pdev) ...@@ -340,19 +338,20 @@ static int img_pwm_probe(struct platform_device *pdev)
static void img_pwm_remove(struct platform_device *pdev) static void img_pwm_remove(struct platform_device *pdev)
{ {
struct img_pwm_chip *imgchip = platform_get_drvdata(pdev); struct pwm_chip *chip = platform_get_drvdata(pdev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
if (!pm_runtime_status_suspended(&pdev->dev)) if (!pm_runtime_status_suspended(&pdev->dev))
img_pwm_runtime_suspend(&pdev->dev); img_pwm_runtime_suspend(&pdev->dev);
pwmchip_remove(&imgchip->chip); pwmchip_remove(chip);
} }
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int img_pwm_suspend(struct device *dev) static int img_pwm_suspend(struct device *dev)
{ {
struct img_pwm_chip *imgchip = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct img_pwm_chip *imgchip = to_img_pwm_chip(chip);
int i, ret; int i, ret;
if (pm_runtime_status_suspended(dev)) { if (pm_runtime_status_suspended(dev)) {
...@@ -361,7 +360,7 @@ static int img_pwm_suspend(struct device *dev) ...@@ -361,7 +360,7 @@ static int img_pwm_suspend(struct device *dev)
return ret; return ret;
} }
for (i = 0; i < imgchip->chip.npwm; i++) for (i = 0; i < chip->npwm; i++)
imgchip->suspend_ch_cfg[i] = img_pwm_readl(imgchip, imgchip->suspend_ch_cfg[i] = img_pwm_readl(imgchip,
PWM_CH_CFG(i)); PWM_CH_CFG(i));
...@@ -374,7 +373,8 @@ static int img_pwm_suspend(struct device *dev) ...@@ -374,7 +373,8 @@ static int img_pwm_suspend(struct device *dev)
static int img_pwm_resume(struct device *dev) static int img_pwm_resume(struct device *dev)
{ {
struct img_pwm_chip *imgchip = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
struct img_pwm_chip *imgchip = to_img_pwm_chip(chip);
int ret; int ret;
int i; int i;
...@@ -382,13 +382,13 @@ static int img_pwm_resume(struct device *dev) ...@@ -382,13 +382,13 @@ static int img_pwm_resume(struct device *dev)
if (ret) if (ret)
return ret; return ret;
for (i = 0; i < imgchip->chip.npwm; i++) for (i = 0; i < chip->npwm; i++)
img_pwm_writel(imgchip, PWM_CH_CFG(i), img_pwm_writel(imgchip, PWM_CH_CFG(i),
imgchip->suspend_ch_cfg[i]); imgchip->suspend_ch_cfg[i]);
img_pwm_writel(imgchip, PWM_CTRL_CFG, imgchip->suspend_ctrl_cfg); img_pwm_writel(imgchip, PWM_CTRL_CFG, imgchip->suspend_ctrl_cfg);
for (i = 0; i < imgchip->chip.npwm; i++) for (i = 0; i < chip->npwm; i++)
if (imgchip->suspend_ctrl_cfg & BIT(i)) if (imgchip->suspend_ctrl_cfg & BIT(i))
regmap_clear_bits(imgchip->periph_regs, regmap_clear_bits(imgchip->periph_regs,
PERIP_PWM_PDM_CONTROL, PERIP_PWM_PDM_CONTROL,
......
...@@ -57,7 +57,6 @@ ...@@ -57,7 +57,6 @@
#define PWM_IMX_TPM_MOD_MOD GENMASK(PWM_IMX_TPM_MOD_WIDTH - 1, 0) #define PWM_IMX_TPM_MOD_MOD GENMASK(PWM_IMX_TPM_MOD_WIDTH - 1, 0)
struct imx_tpm_pwm_chip { struct imx_tpm_pwm_chip {
struct pwm_chip chip;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
struct mutex lock; struct mutex lock;
...@@ -75,7 +74,7 @@ struct imx_tpm_pwm_param { ...@@ -75,7 +74,7 @@ struct imx_tpm_pwm_param {
static inline struct imx_tpm_pwm_chip * static inline struct imx_tpm_pwm_chip *
to_imx_tpm_pwm_chip(struct pwm_chip *chip) to_imx_tpm_pwm_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct imx_tpm_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
/* /*
...@@ -336,35 +335,42 @@ static const struct pwm_ops imx_tpm_pwm_ops = { ...@@ -336,35 +335,42 @@ static const struct pwm_ops imx_tpm_pwm_ops = {
static int pwm_imx_tpm_probe(struct platform_device *pdev) static int pwm_imx_tpm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct imx_tpm_pwm_chip *tpm; struct imx_tpm_pwm_chip *tpm;
struct clk *clk;
void __iomem *base;
int ret; int ret;
unsigned int npwm;
u32 val; u32 val;
tpm = devm_kzalloc(&pdev->dev, sizeof(*tpm), GFP_KERNEL); base = devm_platform_ioremap_resource(pdev, 0);
if (!tpm) if (IS_ERR(base))
return -ENOMEM; return PTR_ERR(base);
platform_set_drvdata(pdev, tpm); clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(clk))
return dev_err_probe(&pdev->dev, PTR_ERR(clk),
"failed to get PWM clock\n");
tpm->base = devm_platform_ioremap_resource(pdev, 0); /* get number of channels */
if (IS_ERR(tpm->base)) val = readl(base + PWM_IMX_TPM_PARAM);
return PTR_ERR(tpm->base); npwm = FIELD_GET(PWM_IMX_TPM_PARAM_CHAN, val);
tpm->clk = devm_clk_get_enabled(&pdev->dev, NULL); chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*tpm));
if (IS_ERR(tpm->clk)) if (IS_ERR(chip))
return dev_err_probe(&pdev->dev, PTR_ERR(tpm->clk), return PTR_ERR(chip);
"failed to get PWM clock\n"); tpm = to_imx_tpm_pwm_chip(chip);
platform_set_drvdata(pdev, tpm);
tpm->chip.dev = &pdev->dev; tpm->base = base;
tpm->chip.ops = &imx_tpm_pwm_ops; tpm->clk = clk;
/* get number of channels */ chip->ops = &imx_tpm_pwm_ops;
val = readl(tpm->base + PWM_IMX_TPM_PARAM);
tpm->chip.npwm = FIELD_GET(PWM_IMX_TPM_PARAM_CHAN, val);
mutex_init(&tpm->lock); mutex_init(&tpm->lock);
ret = devm_pwmchip_add(&pdev->dev, &tpm->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret) if (ret)
return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
......
...@@ -28,10 +28,12 @@ struct pwm_imx1_chip { ...@@ -28,10 +28,12 @@ struct pwm_imx1_chip {
struct clk *clk_ipg; struct clk *clk_ipg;
struct clk *clk_per; struct clk *clk_per;
void __iomem *mmio_base; void __iomem *mmio_base;
struct pwm_chip chip;
}; };
#define to_pwm_imx1_chip(chip) container_of(chip, struct pwm_imx1_chip, chip) static inline struct pwm_imx1_chip *to_pwm_imx1_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int pwm_imx1_clk_prepare_enable(struct pwm_chip *chip) static int pwm_imx1_clk_prepare_enable(struct pwm_chip *chip)
{ {
...@@ -156,11 +158,13 @@ MODULE_DEVICE_TABLE(of, pwm_imx1_dt_ids); ...@@ -156,11 +158,13 @@ MODULE_DEVICE_TABLE(of, pwm_imx1_dt_ids);
static int pwm_imx1_probe(struct platform_device *pdev) static int pwm_imx1_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct pwm_imx1_chip *imx; struct pwm_imx1_chip *imx;
imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*imx));
if (!imx) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
imx = to_pwm_imx1_chip(chip);
imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
if (IS_ERR(imx->clk_ipg)) if (IS_ERR(imx->clk_ipg))
...@@ -172,15 +176,13 @@ static int pwm_imx1_probe(struct platform_device *pdev) ...@@ -172,15 +176,13 @@ static int pwm_imx1_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(imx->clk_per), return dev_err_probe(&pdev->dev, PTR_ERR(imx->clk_per),
"failed to get peripheral clock\n"); "failed to get peripheral clock\n");
imx->chip.ops = &pwm_imx1_ops; chip->ops = &pwm_imx1_ops;
imx->chip.dev = &pdev->dev;
imx->chip.npwm = 1;
imx->mmio_base = devm_platform_ioremap_resource(pdev, 0); imx->mmio_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(imx->mmio_base)) if (IS_ERR(imx->mmio_base))
return PTR_ERR(imx->mmio_base); return PTR_ERR(imx->mmio_base);
return devm_pwmchip_add(&pdev->dev, &imx->chip); return devm_pwmchip_add(&pdev->dev, chip);
} }
static struct platform_driver pwm_imx1_driver = { static struct platform_driver pwm_imx1_driver = {
......
...@@ -83,7 +83,6 @@ struct pwm_imx27_chip { ...@@ -83,7 +83,6 @@ struct pwm_imx27_chip {
struct clk *clk_ipg; struct clk *clk_ipg;
struct clk *clk_per; struct clk *clk_per;
void __iomem *mmio_base; void __iomem *mmio_base;
struct pwm_chip chip;
/* /*
* The driver cannot read the current duty cycle from the hardware if * The driver cannot read the current duty cycle from the hardware if
...@@ -93,7 +92,10 @@ struct pwm_imx27_chip { ...@@ -93,7 +92,10 @@ struct pwm_imx27_chip {
unsigned int duty_cycle; unsigned int duty_cycle;
}; };
#define to_pwm_imx27_chip(chip) container_of(chip, struct pwm_imx27_chip, chip) static inline struct pwm_imx27_chip *to_pwm_imx27_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int pwm_imx27_clk_prepare_enable(struct pwm_imx27_chip *imx) static int pwm_imx27_clk_prepare_enable(struct pwm_imx27_chip *imx)
{ {
...@@ -145,7 +147,7 @@ static int pwm_imx27_get_state(struct pwm_chip *chip, ...@@ -145,7 +147,7 @@ static int pwm_imx27_get_state(struct pwm_chip *chip,
state->polarity = PWM_POLARITY_INVERSED; state->polarity = PWM_POLARITY_INVERSED;
break; break;
default: default:
dev_warn(chip->dev, "can't set polarity, output disconnected"); dev_warn(pwmchip_parent(chip), "can't set polarity, output disconnected");
} }
prescaler = MX3_PWMCR_PRESCALER_GET(val); prescaler = MX3_PWMCR_PRESCALER_GET(val);
...@@ -177,7 +179,7 @@ static int pwm_imx27_get_state(struct pwm_chip *chip, ...@@ -177,7 +179,7 @@ static int pwm_imx27_get_state(struct pwm_chip *chip,
static void pwm_imx27_sw_reset(struct pwm_chip *chip) static void pwm_imx27_sw_reset(struct pwm_chip *chip)
{ {
struct pwm_imx27_chip *imx = to_pwm_imx27_chip(chip); struct pwm_imx27_chip *imx = to_pwm_imx27_chip(chip);
struct device *dev = chip->dev; struct device *dev = pwmchip_parent(chip);
int wait_count = 0; int wait_count = 0;
u32 cr; u32 cr;
...@@ -196,7 +198,7 @@ static void pwm_imx27_wait_fifo_slot(struct pwm_chip *chip, ...@@ -196,7 +198,7 @@ static void pwm_imx27_wait_fifo_slot(struct pwm_chip *chip,
struct pwm_device *pwm) struct pwm_device *pwm)
{ {
struct pwm_imx27_chip *imx = to_pwm_imx27_chip(chip); struct pwm_imx27_chip *imx = to_pwm_imx27_chip(chip);
struct device *dev = chip->dev; struct device *dev = pwmchip_parent(chip);
unsigned int period_ms; unsigned int period_ms;
int fifoav; int fifoav;
u32 sr; u32 sr;
...@@ -204,7 +206,7 @@ static void pwm_imx27_wait_fifo_slot(struct pwm_chip *chip, ...@@ -204,7 +206,7 @@ static void pwm_imx27_wait_fifo_slot(struct pwm_chip *chip,
sr = readl(imx->mmio_base + MX3_PWMSR); sr = readl(imx->mmio_base + MX3_PWMSR);
fifoav = FIELD_GET(MX3_PWMSR_FIFOAV, sr); fifoav = FIELD_GET(MX3_PWMSR_FIFOAV, sr);
if (fifoav == MX3_PWMSR_FIFOAV_4WORDS) { if (fifoav == MX3_PWMSR_FIFOAV_4WORDS) {
period_ms = DIV_ROUND_UP_ULL(pwm_get_period(pwm), period_ms = DIV_ROUND_UP_ULL(pwm->state.period,
NSEC_PER_MSEC); NSEC_PER_MSEC);
msleep(period_ms); msleep(period_ms);
...@@ -219,14 +221,11 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -219,14 +221,11 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm,
{ {
unsigned long period_cycles, duty_cycles, prescale; unsigned long period_cycles, duty_cycles, prescale;
struct pwm_imx27_chip *imx = to_pwm_imx27_chip(chip); struct pwm_imx27_chip *imx = to_pwm_imx27_chip(chip);
struct pwm_state cstate;
unsigned long long c; unsigned long long c;
unsigned long long clkrate; unsigned long long clkrate;
int ret; int ret;
u32 cr; u32 cr;
pwm_get_state(pwm, &cstate);
clkrate = clk_get_rate(imx->clk_per); clkrate = clk_get_rate(imx->clk_per);
c = clkrate * state->period; c = clkrate * state->period;
...@@ -254,7 +253,7 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -254,7 +253,7 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm,
* Wait for a free FIFO slot if the PWM is already enabled, and flush * Wait for a free FIFO slot if the PWM is already enabled, and flush
* the FIFO if the PWM was disabled and is about to be enabled. * the FIFO if the PWM was disabled and is about to be enabled.
*/ */
if (cstate.enabled) { if (pwm->state.enabled) {
pwm_imx27_wait_fifo_slot(chip, pwm); pwm_imx27_wait_fifo_slot(chip, pwm);
} else { } else {
ret = pwm_imx27_clk_prepare_enable(imx); ret = pwm_imx27_clk_prepare_enable(imx);
...@@ -306,13 +305,15 @@ MODULE_DEVICE_TABLE(of, pwm_imx27_dt_ids); ...@@ -306,13 +305,15 @@ MODULE_DEVICE_TABLE(of, pwm_imx27_dt_ids);
static int pwm_imx27_probe(struct platform_device *pdev) static int pwm_imx27_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct pwm_imx27_chip *imx; struct pwm_imx27_chip *imx;
int ret; int ret;
u32 pwmcr; u32 pwmcr;
imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*imx));
if (imx == NULL) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
imx = to_pwm_imx27_chip(chip);
imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
if (IS_ERR(imx->clk_ipg)) if (IS_ERR(imx->clk_ipg))
...@@ -324,9 +325,7 @@ static int pwm_imx27_probe(struct platform_device *pdev) ...@@ -324,9 +325,7 @@ static int pwm_imx27_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(imx->clk_per), return dev_err_probe(&pdev->dev, PTR_ERR(imx->clk_per),
"failed to get peripheral clock\n"); "failed to get peripheral clock\n");
imx->chip.ops = &pwm_imx27_ops; chip->ops = &pwm_imx27_ops;
imx->chip.dev = &pdev->dev;
imx->chip.npwm = 1;
imx->mmio_base = devm_platform_ioremap_resource(pdev, 0); imx->mmio_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(imx->mmio_base)) if (IS_ERR(imx->mmio_base))
...@@ -341,7 +340,7 @@ static int pwm_imx27_probe(struct platform_device *pdev) ...@@ -341,7 +340,7 @@ static int pwm_imx27_probe(struct platform_device *pdev)
if (!(pwmcr & MX3_PWMCR_EN)) if (!(pwmcr & MX3_PWMCR_EN))
pwm_imx27_clk_disable_unprepare(imx); pwm_imx27_clk_disable_unprepare(imx);
return devm_pwmchip_add(&pdev->dev, &imx->chip); return devm_pwmchip_add(&pdev->dev, chip);
} }
static struct platform_driver imx_pwm_driver = { static struct platform_driver imx_pwm_driver = {
......
...@@ -42,14 +42,13 @@ ...@@ -42,14 +42,13 @@
#define LGM_PWM_PERIOD_2WIRE_NS (40 * NSEC_PER_MSEC) #define LGM_PWM_PERIOD_2WIRE_NS (40 * NSEC_PER_MSEC)
struct lgm_pwm_chip { struct lgm_pwm_chip {
struct pwm_chip chip;
struct regmap *regmap; struct regmap *regmap;
u32 period; u32 period;
}; };
static inline struct lgm_pwm_chip *to_lgm_pwm_chip(struct pwm_chip *chip) static inline struct lgm_pwm_chip *to_lgm_pwm_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct lgm_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static int lgm_pwm_enable(struct pwm_chip *chip, bool enable) static int lgm_pwm_enable(struct pwm_chip *chip, bool enable)
...@@ -168,14 +167,16 @@ static int lgm_pwm_probe(struct platform_device *pdev) ...@@ -168,14 +167,16 @@ static int lgm_pwm_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct reset_control *rst; struct reset_control *rst;
struct pwm_chip *chip;
struct lgm_pwm_chip *pc; struct lgm_pwm_chip *pc;
void __iomem *io_base; void __iomem *io_base;
struct clk *clk; struct clk *clk;
int ret; int ret;
pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL); chip = devm_pwmchip_alloc(dev, 1, sizeof(*pc));
if (!pc) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
pc = to_lgm_pwm_chip(chip);
io_base = devm_platform_ioremap_resource(pdev, 0); io_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(io_base)) if (IS_ERR(io_base))
...@@ -203,13 +204,11 @@ static int lgm_pwm_probe(struct platform_device *pdev) ...@@ -203,13 +204,11 @@ static int lgm_pwm_probe(struct platform_device *pdev)
if (ret) if (ret)
return dev_err_probe(dev, ret, "cannot deassert reset control\n"); return dev_err_probe(dev, ret, "cannot deassert reset control\n");
pc->chip.dev = dev; chip->ops = &lgm_pwm_ops;
pc->chip.ops = &lgm_pwm_ops;
pc->chip.npwm = 1;
lgm_pwm_init(pc); lgm_pwm_init(pc);
ret = devm_pwmchip_add(dev, &pc->chip); ret = devm_pwmchip_add(dev, chip);
if (ret < 0) if (ret < 0)
return dev_err_probe(dev, ret, "failed to add PWM chip\n"); return dev_err_probe(dev, ret, "failed to add PWM chip\n");
......
...@@ -34,12 +34,17 @@ ...@@ -34,12 +34,17 @@
struct iqs620_pwm_private { struct iqs620_pwm_private {
struct iqs62x_core *iqs62x; struct iqs62x_core *iqs62x;
struct pwm_chip chip; struct device *dev;
struct notifier_block notifier; struct notifier_block notifier;
struct mutex lock; struct mutex lock;
unsigned int duty_scale; unsigned int duty_scale;
}; };
static inline struct iqs620_pwm_private *iqs620_pwm_from_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int iqs620_pwm_init(struct iqs620_pwm_private *iqs620_pwm, static int iqs620_pwm_init(struct iqs620_pwm_private *iqs620_pwm,
unsigned int duty_scale) unsigned int duty_scale)
{ {
...@@ -73,7 +78,7 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -73,7 +78,7 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
if (state->period < IQS620_PWM_PERIOD_NS) if (state->period < IQS620_PWM_PERIOD_NS)
return -EINVAL; return -EINVAL;
iqs620_pwm = container_of(chip, struct iqs620_pwm_private, chip); iqs620_pwm = iqs620_pwm_from_chip(chip);
/* /*
* The duty cycle generated by the device is calculated as follows: * The duty cycle generated by the device is calculated as follows:
...@@ -109,7 +114,7 @@ static int iqs620_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -109,7 +114,7 @@ static int iqs620_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
{ {
struct iqs620_pwm_private *iqs620_pwm; struct iqs620_pwm_private *iqs620_pwm;
iqs620_pwm = container_of(chip, struct iqs620_pwm_private, chip); iqs620_pwm = iqs620_pwm_from_chip(chip);
mutex_lock(&iqs620_pwm->lock); mutex_lock(&iqs620_pwm->lock);
...@@ -155,7 +160,7 @@ static int iqs620_pwm_notifier(struct notifier_block *notifier, ...@@ -155,7 +160,7 @@ static int iqs620_pwm_notifier(struct notifier_block *notifier,
mutex_unlock(&iqs620_pwm->lock); mutex_unlock(&iqs620_pwm->lock);
if (ret) { if (ret) {
dev_err(iqs620_pwm->chip.dev, dev_err(iqs620_pwm->dev,
"Failed to re-initialize device: %d\n", ret); "Failed to re-initialize device: %d\n", ret);
return NOTIFY_BAD; return NOTIFY_BAD;
} }
...@@ -176,21 +181,24 @@ static void iqs620_pwm_notifier_unregister(void *context) ...@@ -176,21 +181,24 @@ static void iqs620_pwm_notifier_unregister(void *context)
ret = blocking_notifier_chain_unregister(&iqs620_pwm->iqs62x->nh, ret = blocking_notifier_chain_unregister(&iqs620_pwm->iqs62x->nh,
&iqs620_pwm->notifier); &iqs620_pwm->notifier);
if (ret) if (ret)
dev_err(iqs620_pwm->chip.dev, dev_err(iqs620_pwm->dev,
"Failed to unregister notifier: %d\n", ret); "Failed to unregister notifier: %d\n", ret);
} }
static int iqs620_pwm_probe(struct platform_device *pdev) static int iqs620_pwm_probe(struct platform_device *pdev)
{ {
struct iqs62x_core *iqs62x = dev_get_drvdata(pdev->dev.parent); struct iqs62x_core *iqs62x = dev_get_drvdata(pdev->dev.parent);
struct pwm_chip *chip;
struct iqs620_pwm_private *iqs620_pwm; struct iqs620_pwm_private *iqs620_pwm;
unsigned int val; unsigned int val;
int ret; int ret;
iqs620_pwm = devm_kzalloc(&pdev->dev, sizeof(*iqs620_pwm), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*iqs620_pwm));
if (!iqs620_pwm) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
iqs620_pwm = iqs620_pwm_from_chip(chip);
iqs620_pwm->dev = &pdev->dev;
iqs620_pwm->iqs62x = iqs62x; iqs620_pwm->iqs62x = iqs62x;
ret = regmap_read(iqs62x->regmap, IQS620_PWR_SETTINGS, &val); ret = regmap_read(iqs62x->regmap, IQS620_PWR_SETTINGS, &val);
...@@ -205,9 +213,7 @@ static int iqs620_pwm_probe(struct platform_device *pdev) ...@@ -205,9 +213,7 @@ static int iqs620_pwm_probe(struct platform_device *pdev)
iqs620_pwm->duty_scale = val + 1; iqs620_pwm->duty_scale = val + 1;
} }
iqs620_pwm->chip.dev = &pdev->dev; chip->ops = &iqs620_pwm_ops;
iqs620_pwm->chip.ops = &iqs620_pwm_ops;
iqs620_pwm->chip.npwm = 1;
mutex_init(&iqs620_pwm->lock); mutex_init(&iqs620_pwm->lock);
...@@ -225,7 +231,7 @@ static int iqs620_pwm_probe(struct platform_device *pdev) ...@@ -225,7 +231,7 @@ static int iqs620_pwm_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
ret = devm_pwmchip_add(&pdev->dev, &iqs620_pwm->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret) if (ret)
dev_err(&pdev->dev, "Failed to add device: %d\n", ret); dev_err(&pdev->dev, "Failed to add device: %d\n", ret);
......
...@@ -25,23 +25,21 @@ struct soc_info { ...@@ -25,23 +25,21 @@ struct soc_info {
}; };
struct jz4740_pwm_chip { struct jz4740_pwm_chip {
struct pwm_chip chip;
struct regmap *map; struct regmap *map;
struct clk *clk[]; struct clk *clk[];
}; };
static inline struct jz4740_pwm_chip *to_jz4740(struct pwm_chip *chip) static inline struct jz4740_pwm_chip *to_jz4740(struct pwm_chip *chip)
{ {
return container_of(chip, struct jz4740_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static bool jz4740_pwm_can_use_chn(struct jz4740_pwm_chip *jz, static bool jz4740_pwm_can_use_chn(struct pwm_chip *chip, unsigned int channel)
unsigned int channel)
{ {
/* Enable all TCU channels for PWM use by default except channels 0/1 */ /* Enable all TCU channels for PWM use by default except channels 0/1 */
u32 pwm_channels_mask = GENMASK(jz->chip.npwm - 1, 2); u32 pwm_channels_mask = GENMASK(chip->npwm - 1, 2);
device_property_read_u32(jz->chip.dev->parent, device_property_read_u32(pwmchip_parent(chip)->parent,
"ingenic,pwm-channels-mask", "ingenic,pwm-channels-mask",
&pwm_channels_mask); &pwm_channels_mask);
...@@ -55,14 +53,15 @@ static int jz4740_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) ...@@ -55,14 +53,15 @@ static int jz4740_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
char name[16]; char name[16];
int err; int err;
if (!jz4740_pwm_can_use_chn(jz, pwm->hwpwm)) if (!jz4740_pwm_can_use_chn(chip, pwm->hwpwm))
return -EBUSY; return -EBUSY;
snprintf(name, sizeof(name), "timer%u", pwm->hwpwm); snprintf(name, sizeof(name), "timer%u", pwm->hwpwm);
clk = clk_get(chip->dev, name); clk = clk_get(pwmchip_parent(chip), name);
if (IS_ERR(clk)) { if (IS_ERR(clk)) {
dev_err(chip->dev, "error %pe: Failed to get clock\n", clk); dev_err(pwmchip_parent(chip),
"error %pe: Failed to get clock\n", clk);
return PTR_ERR(clk); return PTR_ERR(clk);
} }
...@@ -150,7 +149,7 @@ static int jz4740_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -150,7 +149,7 @@ static int jz4740_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
*/ */
rate = clk_round_rate(clk, tmp); rate = clk_round_rate(clk, tmp);
if (rate < 0) { if (rate < 0) {
dev_err(chip->dev, "Unable to round rate: %ld\n", rate); dev_err(pwmchip_parent(chip), "Unable to round rate: %ld\n", rate);
return rate; return rate;
} }
...@@ -171,7 +170,7 @@ static int jz4740_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -171,7 +170,7 @@ static int jz4740_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
err = clk_set_rate(clk, rate); err = clk_set_rate(clk, rate);
if (err) { if (err) {
dev_err(chip->dev, "Unable to set rate: %d\n", err); dev_err(pwmchip_parent(chip), "Unable to set rate: %d\n", err);
return err; return err;
} }
...@@ -224,6 +223,7 @@ static const struct pwm_ops jz4740_pwm_ops = { ...@@ -224,6 +223,7 @@ static const struct pwm_ops jz4740_pwm_ops = {
static int jz4740_pwm_probe(struct platform_device *pdev) static int jz4740_pwm_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct pwm_chip *chip;
struct jz4740_pwm_chip *jz; struct jz4740_pwm_chip *jz;
const struct soc_info *info; const struct soc_info *info;
...@@ -231,10 +231,10 @@ static int jz4740_pwm_probe(struct platform_device *pdev) ...@@ -231,10 +231,10 @@ static int jz4740_pwm_probe(struct platform_device *pdev)
if (!info) if (!info)
return -EINVAL; return -EINVAL;
jz = devm_kzalloc(dev, struct_size(jz, clk, info->num_pwms), chip = devm_pwmchip_alloc(dev, info->num_pwms, struct_size(jz, clk, info->num_pwms));
GFP_KERNEL); if (IS_ERR(chip))
if (!jz) return PTR_ERR(chip);
return -ENOMEM; jz = to_jz4740(chip);
jz->map = device_node_to_regmap(dev->parent->of_node); jz->map = device_node_to_regmap(dev->parent->of_node);
if (IS_ERR(jz->map)) { if (IS_ERR(jz->map)) {
...@@ -242,11 +242,9 @@ static int jz4740_pwm_probe(struct platform_device *pdev) ...@@ -242,11 +242,9 @@ static int jz4740_pwm_probe(struct platform_device *pdev)
return PTR_ERR(jz->map); return PTR_ERR(jz->map);
} }
jz->chip.dev = dev; chip->ops = &jz4740_pwm_ops;
jz->chip.ops = &jz4740_pwm_ops;
jz->chip.npwm = info->num_pwms;
return devm_pwmchip_add(dev, &jz->chip); return devm_pwmchip_add(dev, chip);
} }
static const struct soc_info jz4740_soc_info = { static const struct soc_info jz4740_soc_info = {
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#define KMB_PWM_HIGHLOW_OFFSET(ch) (0x20 + 4 * (ch)) #define KMB_PWM_HIGHLOW_OFFSET(ch) (0x20 + 4 * (ch))
struct keembay_pwm { struct keembay_pwm {
struct pwm_chip chip;
struct device *dev; struct device *dev;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
...@@ -44,7 +43,7 @@ struct keembay_pwm { ...@@ -44,7 +43,7 @@ struct keembay_pwm {
static inline struct keembay_pwm *to_keembay_pwm_dev(struct pwm_chip *chip) static inline struct keembay_pwm *to_keembay_pwm_dev(struct pwm_chip *chip)
{ {
return container_of(chip, struct keembay_pwm, chip); return pwmchip_get_drvdata(chip);
} }
static void keembay_clk_unprepare(void *data) static void keembay_clk_unprepare(void *data)
...@@ -185,12 +184,14 @@ static const struct pwm_ops keembay_pwm_ops = { ...@@ -185,12 +184,14 @@ static const struct pwm_ops keembay_pwm_ops = {
static int keembay_pwm_probe(struct platform_device *pdev) static int keembay_pwm_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct pwm_chip *chip;
struct keembay_pwm *priv; struct keembay_pwm *priv;
int ret; int ret;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); chip = devm_pwmchip_alloc(dev, KMB_TOTAL_PWM_CHANNELS, sizeof(*priv));
if (!priv) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
priv = to_keembay_pwm_dev(chip);
priv->clk = devm_clk_get(dev, NULL); priv->clk = devm_clk_get(dev, NULL);
if (IS_ERR(priv->clk)) if (IS_ERR(priv->clk))
...@@ -204,11 +205,9 @@ static int keembay_pwm_probe(struct platform_device *pdev) ...@@ -204,11 +205,9 @@ static int keembay_pwm_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
priv->chip.dev = dev; chip->ops = &keembay_pwm_ops;
priv->chip.ops = &keembay_pwm_ops;
priv->chip.npwm = KMB_TOTAL_PWM_CHANNELS;
ret = devm_pwmchip_add(dev, &priv->chip); ret = devm_pwmchip_add(dev, chip);
if (ret) if (ret)
return dev_err_probe(dev, ret, "Failed to add PWM chip\n"); return dev_err_probe(dev, ret, "Failed to add PWM chip\n");
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#define LP3943_MAX_PERIOD 1600000 #define LP3943_MAX_PERIOD 1600000
struct lp3943_pwm { struct lp3943_pwm {
struct pwm_chip chip;
struct lp3943 *lp3943; struct lp3943 *lp3943;
struct lp3943_platform_data *pdata; struct lp3943_platform_data *pdata;
struct lp3943_pwm_map pwm_map[LP3943_NUM_PWMS]; struct lp3943_pwm_map pwm_map[LP3943_NUM_PWMS];
...@@ -28,7 +27,7 @@ struct lp3943_pwm { ...@@ -28,7 +27,7 @@ struct lp3943_pwm {
static inline struct lp3943_pwm *to_lp3943_pwm(struct pwm_chip *chip) static inline struct lp3943_pwm *to_lp3943_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct lp3943_pwm, chip); return pwmchip_get_drvdata(chip);
} }
static struct lp3943_pwm_map * static struct lp3943_pwm_map *
...@@ -273,12 +272,14 @@ static int lp3943_pwm_parse_dt(struct device *dev, ...@@ -273,12 +272,14 @@ static int lp3943_pwm_parse_dt(struct device *dev,
static int lp3943_pwm_probe(struct platform_device *pdev) static int lp3943_pwm_probe(struct platform_device *pdev)
{ {
struct lp3943 *lp3943 = dev_get_drvdata(pdev->dev.parent); struct lp3943 *lp3943 = dev_get_drvdata(pdev->dev.parent);
struct pwm_chip *chip;
struct lp3943_pwm *lp3943_pwm; struct lp3943_pwm *lp3943_pwm;
int ret; int ret;
lp3943_pwm = devm_kzalloc(&pdev->dev, sizeof(*lp3943_pwm), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, LP3943_NUM_PWMS, sizeof(*lp3943_pwm));
if (!lp3943_pwm) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
lp3943_pwm = to_lp3943_pwm(chip);
lp3943_pwm->pdata = lp3943->pdata; lp3943_pwm->pdata = lp3943->pdata;
if (!lp3943_pwm->pdata) { if (!lp3943_pwm->pdata) {
...@@ -292,11 +293,9 @@ static int lp3943_pwm_probe(struct platform_device *pdev) ...@@ -292,11 +293,9 @@ static int lp3943_pwm_probe(struct platform_device *pdev)
} }
lp3943_pwm->lp3943 = lp3943; lp3943_pwm->lp3943 = lp3943;
lp3943_pwm->chip.dev = &pdev->dev; chip->ops = &lp3943_pwm_ops;
lp3943_pwm->chip.ops = &lp3943_pwm_ops;
lp3943_pwm->chip.npwm = LP3943_NUM_PWMS;
return devm_pwmchip_add(&pdev->dev, &lp3943_pwm->chip); return devm_pwmchip_add(&pdev->dev, chip);
} }
#ifdef CONFIG_OF #ifdef CONFIG_OF
......
...@@ -92,8 +92,6 @@ struct lpc18xx_pwm_data { ...@@ -92,8 +92,6 @@ struct lpc18xx_pwm_data {
}; };
struct lpc18xx_pwm_chip { struct lpc18xx_pwm_chip {
struct device *dev;
struct pwm_chip chip;
void __iomem *base; void __iomem *base;
struct clk *pwm_clk; struct clk *pwm_clk;
unsigned long clk_rate; unsigned long clk_rate;
...@@ -110,7 +108,7 @@ struct lpc18xx_pwm_chip { ...@@ -110,7 +108,7 @@ struct lpc18xx_pwm_chip {
static inline struct lpc18xx_pwm_chip * static inline struct lpc18xx_pwm_chip *
to_lpc18xx_pwm_chip(struct pwm_chip *chip) to_lpc18xx_pwm_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct lpc18xx_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static inline void lpc18xx_pwm_writel(struct lpc18xx_pwm_chip *lpc18xx_pwm, static inline void lpc18xx_pwm_writel(struct lpc18xx_pwm_chip *lpc18xx_pwm,
...@@ -198,7 +196,7 @@ static int lpc18xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -198,7 +196,7 @@ static int lpc18xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
if (period_ns < lpc18xx_pwm->min_period_ns || if (period_ns < lpc18xx_pwm->min_period_ns ||
period_ns > lpc18xx_pwm->max_period_ns) { period_ns > lpc18xx_pwm->max_period_ns) {
dev_err(chip->dev, "period %d not in range\n", period_ns); dev_err(pwmchip_parent(chip), "period %d not in range\n", period_ns);
return -ERANGE; return -ERANGE;
} }
...@@ -214,7 +212,7 @@ static int lpc18xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -214,7 +212,7 @@ static int lpc18xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
*/ */
if (requested_events > 2 && lpc18xx_pwm->period_ns != period_ns && if (requested_events > 2 && lpc18xx_pwm->period_ns != period_ns &&
lpc18xx_pwm->period_ns) { lpc18xx_pwm->period_ns) {
dev_err(chip->dev, "conflicting period requested for PWM %u\n", dev_err(pwmchip_parent(chip), "conflicting period requested for PWM %u\n",
pwm->hwpwm); pwm->hwpwm);
mutex_unlock(&lpc18xx_pwm->period_lock); mutex_unlock(&lpc18xx_pwm->period_lock);
return -EBUSY; return -EBUSY;
...@@ -289,7 +287,7 @@ static int lpc18xx_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) ...@@ -289,7 +287,7 @@ static int lpc18xx_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
LPC18XX_PWM_EVENT_MAX); LPC18XX_PWM_EVENT_MAX);
if (event >= LPC18XX_PWM_EVENT_MAX) { if (event >= LPC18XX_PWM_EVENT_MAX) {
dev_err(lpc18xx_pwm->dev, dev_err(pwmchip_parent(chip),
"maximum number of simultaneous channels reached\n"); "maximum number of simultaneous channels reached\n");
return -EBUSY; return -EBUSY;
} }
...@@ -349,16 +347,15 @@ MODULE_DEVICE_TABLE(of, lpc18xx_pwm_of_match); ...@@ -349,16 +347,15 @@ MODULE_DEVICE_TABLE(of, lpc18xx_pwm_of_match);
static int lpc18xx_pwm_probe(struct platform_device *pdev) static int lpc18xx_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct lpc18xx_pwm_chip *lpc18xx_pwm; struct lpc18xx_pwm_chip *lpc18xx_pwm;
int ret; int ret;
u64 val; u64 val;
lpc18xx_pwm = devm_kzalloc(&pdev->dev, sizeof(*lpc18xx_pwm), chip = devm_pwmchip_alloc(&pdev->dev, LPC18XX_NUM_PWMS, sizeof(*lpc18xx_pwm));
GFP_KERNEL); if (IS_ERR(chip))
if (!lpc18xx_pwm) return PTR_ERR(chip);
return -ENOMEM; lpc18xx_pwm = to_lpc18xx_pwm_chip(chip);
lpc18xx_pwm->dev = &pdev->dev;
lpc18xx_pwm->base = devm_platform_ioremap_resource(pdev, 0); lpc18xx_pwm->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(lpc18xx_pwm->base)) if (IS_ERR(lpc18xx_pwm->base))
...@@ -389,9 +386,7 @@ static int lpc18xx_pwm_probe(struct platform_device *pdev) ...@@ -389,9 +386,7 @@ static int lpc18xx_pwm_probe(struct platform_device *pdev)
lpc18xx_pwm->min_period_ns = DIV_ROUND_UP(NSEC_PER_SEC, lpc18xx_pwm->min_period_ns = DIV_ROUND_UP(NSEC_PER_SEC,
lpc18xx_pwm->clk_rate); lpc18xx_pwm->clk_rate);
lpc18xx_pwm->chip.dev = &pdev->dev; chip->ops = &lpc18xx_pwm_ops;
lpc18xx_pwm->chip.ops = &lpc18xx_pwm_ops;
lpc18xx_pwm->chip.npwm = LPC18XX_NUM_PWMS;
/* SCT counter must be in unify (32 bit) mode */ /* SCT counter must be in unify (32 bit) mode */
lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CONFIG, lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CONFIG,
...@@ -423,21 +418,22 @@ static int lpc18xx_pwm_probe(struct platform_device *pdev) ...@@ -423,21 +418,22 @@ static int lpc18xx_pwm_probe(struct platform_device *pdev)
val |= LPC18XX_PWM_PRE(0); val |= LPC18XX_PWM_PRE(0);
lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CTRL, val); lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CTRL, val);
ret = pwmchip_add(&lpc18xx_pwm->chip); ret = pwmchip_add(chip);
if (ret < 0) if (ret < 0)
return dev_err_probe(&pdev->dev, ret, "pwmchip_add failed\n"); return dev_err_probe(&pdev->dev, ret, "pwmchip_add failed\n");
platform_set_drvdata(pdev, lpc18xx_pwm); platform_set_drvdata(pdev, chip);
return 0; return 0;
} }
static void lpc18xx_pwm_remove(struct platform_device *pdev) static void lpc18xx_pwm_remove(struct platform_device *pdev)
{ {
struct lpc18xx_pwm_chip *lpc18xx_pwm = platform_get_drvdata(pdev); struct pwm_chip *chip = platform_get_drvdata(pdev);
struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip);
u32 val; u32 val;
pwmchip_remove(&lpc18xx_pwm->chip); pwmchip_remove(chip);
val = lpc18xx_pwm_readl(lpc18xx_pwm, LPC18XX_PWM_CTRL); val = lpc18xx_pwm_readl(lpc18xx_pwm, LPC18XX_PWM_CTRL);
lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CTRL, lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CTRL,
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include <linux/slab.h> #include <linux/slab.h>
struct lpc32xx_pwm_chip { struct lpc32xx_pwm_chip {
struct pwm_chip chip;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
}; };
...@@ -23,8 +22,10 @@ struct lpc32xx_pwm_chip { ...@@ -23,8 +22,10 @@ struct lpc32xx_pwm_chip {
#define PWM_ENABLE BIT(31) #define PWM_ENABLE BIT(31)
#define PWM_PIN_LEVEL BIT(30) #define PWM_PIN_LEVEL BIT(30)
#define to_lpc32xx_pwm_chip(_chip) \ static inline struct lpc32xx_pwm_chip *to_lpc32xx_pwm_chip(struct pwm_chip *chip)
container_of(_chip, struct lpc32xx_pwm_chip, chip) {
return pwmchip_get_drvdata(chip);
}
static int lpc32xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, static int lpc32xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
int duty_ns, int period_ns) int duty_ns, int period_ns)
...@@ -119,13 +120,15 @@ static const struct pwm_ops lpc32xx_pwm_ops = { ...@@ -119,13 +120,15 @@ static const struct pwm_ops lpc32xx_pwm_ops = {
static int lpc32xx_pwm_probe(struct platform_device *pdev) static int lpc32xx_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct lpc32xx_pwm_chip *lpc32xx; struct lpc32xx_pwm_chip *lpc32xx;
int ret; int ret;
u32 val; u32 val;
lpc32xx = devm_kzalloc(&pdev->dev, sizeof(*lpc32xx), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*lpc32xx));
if (!lpc32xx) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
lpc32xx = to_lpc32xx_pwm_chip(chip);
lpc32xx->base = devm_platform_ioremap_resource(pdev, 0); lpc32xx->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(lpc32xx->base)) if (IS_ERR(lpc32xx->base))
...@@ -135,16 +138,14 @@ static int lpc32xx_pwm_probe(struct platform_device *pdev) ...@@ -135,16 +138,14 @@ static int lpc32xx_pwm_probe(struct platform_device *pdev)
if (IS_ERR(lpc32xx->clk)) if (IS_ERR(lpc32xx->clk))
return PTR_ERR(lpc32xx->clk); return PTR_ERR(lpc32xx->clk);
lpc32xx->chip.dev = &pdev->dev; chip->ops = &lpc32xx_pwm_ops;
lpc32xx->chip.ops = &lpc32xx_pwm_ops;
lpc32xx->chip.npwm = 1;
/* If PWM is disabled, configure the output to the default value */ /* If PWM is disabled, configure the output to the default value */
val = readl(lpc32xx->base); val = readl(lpc32xx->base);
val &= ~PWM_PIN_LEVEL; val &= ~PWM_PIN_LEVEL;
writel(val, lpc32xx->base); writel(val, lpc32xx->base);
ret = devm_pwmchip_add(&pdev->dev, &lpc32xx->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "failed to add PWM chip, error %d\n", ret); dev_err(&pdev->dev, "failed to add PWM chip, error %d\n", ret);
return ret; return ret;
......
...@@ -18,7 +18,7 @@ static int pwm_lpss_probe_pci(struct pci_dev *pdev, ...@@ -18,7 +18,7 @@ static int pwm_lpss_probe_pci(struct pci_dev *pdev,
const struct pci_device_id *id) const struct pci_device_id *id)
{ {
const struct pwm_lpss_boardinfo *info; const struct pwm_lpss_boardinfo *info;
struct pwm_lpss_chip *lpwm; struct pwm_chip *chip;
int err; int err;
err = pcim_enable_device(pdev); err = pcim_enable_device(pdev);
...@@ -30,11 +30,9 @@ static int pwm_lpss_probe_pci(struct pci_dev *pdev, ...@@ -30,11 +30,9 @@ static int pwm_lpss_probe_pci(struct pci_dev *pdev,
return err; return err;
info = (struct pwm_lpss_boardinfo *)id->driver_data; info = (struct pwm_lpss_boardinfo *)id->driver_data;
lpwm = devm_pwm_lpss_probe(&pdev->dev, pcim_iomap_table(pdev)[0], info); chip = devm_pwm_lpss_probe(&pdev->dev, pcim_iomap_table(pdev)[0], info);
if (IS_ERR(lpwm)) if (IS_ERR(chip))
return PTR_ERR(lpwm); return PTR_ERR(chip);
pci_set_drvdata(pdev, lpwm);
pm_runtime_put(&pdev->dev); pm_runtime_put(&pdev->dev);
pm_runtime_allow(&pdev->dev); pm_runtime_allow(&pdev->dev);
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
static int pwm_lpss_probe_platform(struct platform_device *pdev) static int pwm_lpss_probe_platform(struct platform_device *pdev)
{ {
const struct pwm_lpss_boardinfo *info; const struct pwm_lpss_boardinfo *info;
struct pwm_lpss_chip *lpwm; struct pwm_chip *chip;
void __iomem *base; void __iomem *base;
info = device_get_match_data(&pdev->dev); info = device_get_match_data(&pdev->dev);
...@@ -31,11 +31,9 @@ static int pwm_lpss_probe_platform(struct platform_device *pdev) ...@@ -31,11 +31,9 @@ static int pwm_lpss_probe_platform(struct platform_device *pdev)
if (IS_ERR(base)) if (IS_ERR(base))
return PTR_ERR(base); return PTR_ERR(base);
lpwm = devm_pwm_lpss_probe(&pdev->dev, base, info); chip = devm_pwm_lpss_probe(&pdev->dev, base, info);
if (IS_ERR(lpwm)) if (IS_ERR(chip))
return PTR_ERR(lpwm); return PTR_ERR(chip);
platform_set_drvdata(pdev, lpwm);
/* /*
* On Cherry Trail devices the GFX0._PS0 AML checks if the controller * On Cherry Trail devices the GFX0._PS0 AML checks if the controller
......
...@@ -68,7 +68,7 @@ EXPORT_SYMBOL_GPL(pwm_lpss_tng_info); ...@@ -68,7 +68,7 @@ EXPORT_SYMBOL_GPL(pwm_lpss_tng_info);
static inline struct pwm_lpss_chip *to_lpwm(struct pwm_chip *chip) static inline struct pwm_lpss_chip *to_lpwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct pwm_lpss_chip, chip); return pwmchip_get_drvdata(chip);
} }
static inline u32 pwm_lpss_read(const struct pwm_device *pwm) static inline u32 pwm_lpss_read(const struct pwm_device *pwm)
...@@ -106,7 +106,7 @@ static int pwm_lpss_wait_for_update(struct pwm_device *pwm) ...@@ -106,7 +106,7 @@ static int pwm_lpss_wait_for_update(struct pwm_device *pwm)
*/ */
err = readl_poll_timeout(addr, val, !(val & PWM_SW_UPDATE), 40, ms); err = readl_poll_timeout(addr, val, !(val & PWM_SW_UPDATE), 40, ms);
if (err) if (err)
dev_err(pwm->chip->dev, "PWM_SW_UPDATE was not cleared\n"); dev_err(pwmchip_parent(pwm->chip), "PWM_SW_UPDATE was not cleared\n");
return err; return err;
} }
...@@ -114,7 +114,7 @@ static int pwm_lpss_wait_for_update(struct pwm_device *pwm) ...@@ -114,7 +114,7 @@ static int pwm_lpss_wait_for_update(struct pwm_device *pwm)
static inline int pwm_lpss_is_updating(struct pwm_device *pwm) static inline int pwm_lpss_is_updating(struct pwm_device *pwm)
{ {
if (pwm_lpss_read(pwm) & PWM_SW_UPDATE) { if (pwm_lpss_read(pwm) & PWM_SW_UPDATE) {
dev_err(pwm->chip->dev, "PWM_SW_UPDATE is still set, skipping update\n"); dev_err(pwmchip_parent(pwm->chip), "PWM_SW_UPDATE is still set, skipping update\n");
return -EBUSY; return -EBUSY;
} }
...@@ -190,16 +190,16 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -190,16 +190,16 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm,
if (state->enabled) { if (state->enabled) {
if (!pwm_is_enabled(pwm)) { if (!pwm_is_enabled(pwm)) {
pm_runtime_get_sync(chip->dev); pm_runtime_get_sync(pwmchip_parent(chip));
ret = pwm_lpss_prepare_enable(lpwm, pwm, state); ret = pwm_lpss_prepare_enable(lpwm, pwm, state);
if (ret) if (ret)
pm_runtime_put(chip->dev); pm_runtime_put(pwmchip_parent(chip));
} else { } else {
ret = pwm_lpss_prepare_enable(lpwm, pwm, state); ret = pwm_lpss_prepare_enable(lpwm, pwm, state);
} }
} else if (pwm_is_enabled(pwm)) { } else if (pwm_is_enabled(pwm)) {
pwm_lpss_write(pwm, pwm_lpss_read(pwm) & ~PWM_ENABLE); pwm_lpss_write(pwm, pwm_lpss_read(pwm) & ~PWM_ENABLE);
pm_runtime_put(chip->dev); pm_runtime_put(pwmchip_parent(chip));
} }
return ret; return ret;
...@@ -213,7 +213,7 @@ static int pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -213,7 +213,7 @@ static int pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
unsigned long long base_unit, freq, on_time_div; unsigned long long base_unit, freq, on_time_div;
u32 ctrl; u32 ctrl;
pm_runtime_get_sync(chip->dev); pm_runtime_get_sync(pwmchip_parent(chip));
base_unit_range = BIT(lpwm->info->base_unit_bits); base_unit_range = BIT(lpwm->info->base_unit_bits);
...@@ -235,7 +235,7 @@ static int pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -235,7 +235,7 @@ static int pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
state->polarity = PWM_POLARITY_NORMAL; state->polarity = PWM_POLARITY_NORMAL;
state->enabled = !!(ctrl & PWM_ENABLE); state->enabled = !!(ctrl & PWM_ENABLE);
pm_runtime_put(chip->dev); pm_runtime_put(pwmchip_parent(chip));
return 0; return 0;
} }
...@@ -245,10 +245,11 @@ static const struct pwm_ops pwm_lpss_ops = { ...@@ -245,10 +245,11 @@ static const struct pwm_ops pwm_lpss_ops = {
.get_state = pwm_lpss_get_state, .get_state = pwm_lpss_get_state,
}; };
struct pwm_lpss_chip *devm_pwm_lpss_probe(struct device *dev, void __iomem *base, struct pwm_chip *devm_pwm_lpss_probe(struct device *dev, void __iomem *base,
const struct pwm_lpss_boardinfo *info) const struct pwm_lpss_boardinfo *info)
{ {
struct pwm_lpss_chip *lpwm; struct pwm_lpss_chip *lpwm;
struct pwm_chip *chip;
unsigned long c; unsigned long c;
int i, ret; int i, ret;
u32 ctrl; u32 ctrl;
...@@ -256,9 +257,10 @@ struct pwm_lpss_chip *devm_pwm_lpss_probe(struct device *dev, void __iomem *base ...@@ -256,9 +257,10 @@ struct pwm_lpss_chip *devm_pwm_lpss_probe(struct device *dev, void __iomem *base
if (WARN_ON(info->npwm > LPSS_MAX_PWMS)) if (WARN_ON(info->npwm > LPSS_MAX_PWMS))
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
lpwm = devm_kzalloc(dev, sizeof(*lpwm), GFP_KERNEL); chip = devm_pwmchip_alloc(dev, info->npwm, sizeof(*lpwm));
if (!lpwm) if (IS_ERR(chip))
return ERR_PTR(-ENOMEM); return chip;
lpwm = to_lpwm(chip);
lpwm->regs = base; lpwm->regs = base;
lpwm->info = info; lpwm->info = info;
...@@ -267,23 +269,21 @@ struct pwm_lpss_chip *devm_pwm_lpss_probe(struct device *dev, void __iomem *base ...@@ -267,23 +269,21 @@ struct pwm_lpss_chip *devm_pwm_lpss_probe(struct device *dev, void __iomem *base
if (!c) if (!c)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
lpwm->chip.dev = dev; chip->ops = &pwm_lpss_ops;
lpwm->chip.ops = &pwm_lpss_ops;
lpwm->chip.npwm = info->npwm;
ret = devm_pwmchip_add(dev, &lpwm->chip); ret = devm_pwmchip_add(dev, chip);
if (ret) { if (ret) {
dev_err(dev, "failed to add PWM chip: %d\n", ret); dev_err(dev, "failed to add PWM chip: %d\n", ret);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
for (i = 0; i < lpwm->info->npwm; i++) { for (i = 0; i < lpwm->info->npwm; i++) {
ctrl = pwm_lpss_read(&lpwm->chip.pwms[i]); ctrl = pwm_lpss_read(&chip->pwms[i]);
if (ctrl & PWM_ENABLE) if (ctrl & PWM_ENABLE)
pm_runtime_get(dev); pm_runtime_get(dev);
} }
return lpwm; return chip;
} }
EXPORT_SYMBOL_GPL(devm_pwm_lpss_probe); EXPORT_SYMBOL_GPL(devm_pwm_lpss_probe);
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#define LPSS_MAX_PWMS 4 #define LPSS_MAX_PWMS 4
struct pwm_lpss_chip { struct pwm_lpss_chip {
struct pwm_chip chip;
void __iomem *regs; void __iomem *regs;
const struct pwm_lpss_boardinfo *info; const struct pwm_lpss_boardinfo *info;
}; };
......
...@@ -42,16 +42,13 @@ struct pwm_mediatek_of_data { ...@@ -42,16 +42,13 @@ struct pwm_mediatek_of_data {
/** /**
* struct pwm_mediatek_chip - struct representing PWM chip * struct pwm_mediatek_chip - struct representing PWM chip
* @chip: linux PWM chip representation
* @regs: base address of PWM chip * @regs: base address of PWM chip
* @clk_top: the top clock generator * @clk_top: the top clock generator
* @clk_main: the clock used by PWM core * @clk_main: the clock used by PWM core
* @clk_pwms: the clock used by each PWM channel * @clk_pwms: the clock used by each PWM channel
* @clk_freq: the fix clock frequency of legacy MIPS SoC
* @soc: pointer to chip's platform data * @soc: pointer to chip's platform data
*/ */
struct pwm_mediatek_chip { struct pwm_mediatek_chip {
struct pwm_chip chip;
void __iomem *regs; void __iomem *regs;
struct clk *clk_top; struct clk *clk_top;
struct clk *clk_main; struct clk *clk_main;
...@@ -70,7 +67,7 @@ static const unsigned int mtk_pwm_reg_offset_v2[] = { ...@@ -70,7 +67,7 @@ static const unsigned int mtk_pwm_reg_offset_v2[] = {
static inline struct pwm_mediatek_chip * static inline struct pwm_mediatek_chip *
to_pwm_mediatek_chip(struct pwm_chip *chip) to_pwm_mediatek_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct pwm_mediatek_chip, chip); return pwmchip_get_drvdata(chip);
} }
static int pwm_mediatek_clk_enable(struct pwm_chip *chip, static int pwm_mediatek_clk_enable(struct pwm_chip *chip,
...@@ -150,7 +147,7 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -150,7 +147,7 @@ static int pwm_mediatek_config(struct pwm_chip *chip, struct pwm_device *pwm,
if (clkdiv > PWM_CLK_DIV_MAX) { if (clkdiv > PWM_CLK_DIV_MAX) {
pwm_mediatek_clk_disable(chip, pwm); pwm_mediatek_clk_disable(chip, pwm);
dev_err(chip->dev, "period of %d ns not supported\n", period_ns); dev_err(pwmchip_parent(chip), "period of %d ns not supported\n", period_ns);
return -EINVAL; return -EINVAL;
} }
...@@ -233,21 +230,26 @@ static const struct pwm_ops pwm_mediatek_ops = { ...@@ -233,21 +230,26 @@ static const struct pwm_ops pwm_mediatek_ops = {
static int pwm_mediatek_probe(struct platform_device *pdev) static int pwm_mediatek_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct pwm_mediatek_chip *pc; struct pwm_mediatek_chip *pc;
const struct pwm_mediatek_of_data *soc;
unsigned int i; unsigned int i;
int ret; int ret;
pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); soc = of_device_get_match_data(&pdev->dev);
if (!pc)
return -ENOMEM; chip = devm_pwmchip_alloc(&pdev->dev, soc->num_pwms, sizeof(*pc));
if (IS_ERR(chip))
return PTR_ERR(chip);
pc = to_pwm_mediatek_chip(chip);
pc->soc = of_device_get_match_data(&pdev->dev); pc->soc = soc;
pc->regs = devm_platform_ioremap_resource(pdev, 0); pc->regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(pc->regs)) if (IS_ERR(pc->regs))
return PTR_ERR(pc->regs); return PTR_ERR(pc->regs);
pc->clk_pwms = devm_kmalloc_array(&pdev->dev, pc->soc->num_pwms, pc->clk_pwms = devm_kmalloc_array(&pdev->dev, soc->num_pwms,
sizeof(*pc->clk_pwms), GFP_KERNEL); sizeof(*pc->clk_pwms), GFP_KERNEL);
if (!pc->clk_pwms) if (!pc->clk_pwms)
return -ENOMEM; return -ENOMEM;
...@@ -262,7 +264,7 @@ static int pwm_mediatek_probe(struct platform_device *pdev) ...@@ -262,7 +264,7 @@ static int pwm_mediatek_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_main), return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_main),
"Failed to get main clock\n"); "Failed to get main clock\n");
for (i = 0; i < pc->soc->num_pwms; i++) { for (i = 0; i < soc->num_pwms; i++) {
char name[8]; char name[8];
snprintf(name, sizeof(name), "pwm%d", i + 1); snprintf(name, sizeof(name), "pwm%d", i + 1);
...@@ -273,11 +275,9 @@ static int pwm_mediatek_probe(struct platform_device *pdev) ...@@ -273,11 +275,9 @@ static int pwm_mediatek_probe(struct platform_device *pdev)
"Failed to get %s clock\n", name); "Failed to get %s clock\n", name);
} }
pc->chip.dev = &pdev->dev; chip->ops = &pwm_mediatek_ops;
pc->chip.ops = &pwm_mediatek_ops;
pc->chip.npwm = pc->soc->num_pwms;
ret = devm_pwmchip_add(&pdev->dev, &pc->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) if (ret < 0)
return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n"); return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n");
...@@ -340,6 +340,13 @@ static const struct pwm_mediatek_of_data mt7986_pwm_data = { ...@@ -340,6 +340,13 @@ static const struct pwm_mediatek_of_data mt7986_pwm_data = {
.reg_offset = mtk_pwm_reg_offset_v1, .reg_offset = mtk_pwm_reg_offset_v1,
}; };
static const struct pwm_mediatek_of_data mt7988_pwm_data = {
.num_pwms = 8,
.pwm45_fixup = false,
.has_ck_26m_sel = false,
.reg_offset = mtk_pwm_reg_offset_v2,
};
static const struct pwm_mediatek_of_data mt8183_pwm_data = { static const struct pwm_mediatek_of_data mt8183_pwm_data = {
.num_pwms = 4, .num_pwms = 4,
.pwm45_fixup = false, .pwm45_fixup = false,
...@@ -370,6 +377,7 @@ static const struct of_device_id pwm_mediatek_of_match[] = { ...@@ -370,6 +377,7 @@ static const struct of_device_id pwm_mediatek_of_match[] = {
{ .compatible = "mediatek,mt7629-pwm", .data = &mt7629_pwm_data }, { .compatible = "mediatek,mt7629-pwm", .data = &mt7629_pwm_data },
{ .compatible = "mediatek,mt7981-pwm", .data = &mt7981_pwm_data }, { .compatible = "mediatek,mt7981-pwm", .data = &mt7981_pwm_data },
{ .compatible = "mediatek,mt7986-pwm", .data = &mt7986_pwm_data }, { .compatible = "mediatek,mt7986-pwm", .data = &mt7986_pwm_data },
{ .compatible = "mediatek,mt7988-pwm", .data = &mt7988_pwm_data },
{ .compatible = "mediatek,mt8183-pwm", .data = &mt8183_pwm_data }, { .compatible = "mediatek,mt8183-pwm", .data = &mt8183_pwm_data },
{ .compatible = "mediatek,mt8365-pwm", .data = &mt8365_pwm_data }, { .compatible = "mediatek,mt8365-pwm", .data = &mt8365_pwm_data },
{ .compatible = "mediatek,mt8516-pwm", .data = &mt8516_pwm_data }, { .compatible = "mediatek,mt8516-pwm", .data = &mt8516_pwm_data },
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
#define MISC_A_EN BIT(0) #define MISC_A_EN BIT(0)
#define MESON_NUM_PWMS 2 #define MESON_NUM_PWMS 2
#define MESON_MAX_MUX_PARENTS 4 #define MESON_NUM_MUX_PARENTS 4
static struct meson_pwm_channel_data { static struct meson_pwm_channel_data {
u8 reg_offset; u8 reg_offset;
...@@ -97,12 +97,10 @@ struct meson_pwm_channel { ...@@ -97,12 +97,10 @@ struct meson_pwm_channel {
}; };
struct meson_pwm_data { struct meson_pwm_data {
const char * const *parent_names; const char *const parent_names[MESON_NUM_MUX_PARENTS];
unsigned int num_parents;
}; };
struct meson_pwm { struct meson_pwm {
struct pwm_chip chip;
const struct meson_pwm_data *data; const struct meson_pwm_data *data;
struct meson_pwm_channel channels[MESON_NUM_PWMS]; struct meson_pwm_channel channels[MESON_NUM_PWMS];
void __iomem *base; void __iomem *base;
...@@ -115,14 +113,14 @@ struct meson_pwm { ...@@ -115,14 +113,14 @@ struct meson_pwm {
static inline struct meson_pwm *to_meson_pwm(struct pwm_chip *chip) static inline struct meson_pwm *to_meson_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct meson_pwm, chip); return pwmchip_get_drvdata(chip);
} }
static int meson_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) static int meson_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
{ {
struct meson_pwm *meson = to_meson_pwm(chip); struct meson_pwm *meson = to_meson_pwm(chip);
struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm];
struct device *dev = chip->dev; struct device *dev = pwmchip_parent(chip);
int err; int err;
err = clk_prepare_enable(channel->clk); err = clk_prepare_enable(channel->clk);
...@@ -143,9 +141,10 @@ static void meson_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) ...@@ -143,9 +141,10 @@ static void meson_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
clk_disable_unprepare(channel->clk); clk_disable_unprepare(channel->clk);
} }
static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state) const struct pwm_state *state)
{ {
struct meson_pwm *meson = to_meson_pwm(chip);
struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm];
unsigned int cnt, duty_cnt; unsigned int cnt, duty_cnt;
unsigned long fin_freq; unsigned long fin_freq;
...@@ -169,19 +168,19 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, ...@@ -169,19 +168,19 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm,
fin_freq = clk_round_rate(channel->clk, freq); fin_freq = clk_round_rate(channel->clk, freq);
if (fin_freq == 0) { if (fin_freq == 0) {
dev_err(meson->chip.dev, "invalid source clock frequency\n"); dev_err(pwmchip_parent(chip), "invalid source clock frequency\n");
return -EINVAL; return -EINVAL;
} }
dev_dbg(meson->chip.dev, "fin_freq: %lu Hz\n", fin_freq); dev_dbg(pwmchip_parent(chip), "fin_freq: %lu Hz\n", fin_freq);
cnt = div_u64(fin_freq * period, NSEC_PER_SEC); cnt = div_u64(fin_freq * period, NSEC_PER_SEC);
if (cnt > 0xffff) { if (cnt > 0xffff) {
dev_err(meson->chip.dev, "unable to get period cnt\n"); dev_err(pwmchip_parent(chip), "unable to get period cnt\n");
return -EINVAL; return -EINVAL;
} }
dev_dbg(meson->chip.dev, "period=%llu cnt=%u\n", period, cnt); dev_dbg(pwmchip_parent(chip), "period=%llu cnt=%u\n", period, cnt);
if (duty == period) { if (duty == period) {
channel->hi = cnt; channel->hi = cnt;
...@@ -192,7 +191,7 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, ...@@ -192,7 +191,7 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm,
} else { } else {
duty_cnt = div_u64(fin_freq * duty, NSEC_PER_SEC); duty_cnt = div_u64(fin_freq * duty, NSEC_PER_SEC);
dev_dbg(meson->chip.dev, "duty=%llu duty_cnt=%u\n", duty, duty_cnt); dev_dbg(pwmchip_parent(chip), "duty=%llu duty_cnt=%u\n", duty, duty_cnt);
channel->hi = duty_cnt; channel->hi = duty_cnt;
channel->lo = cnt - duty_cnt; channel->lo = cnt - duty_cnt;
...@@ -203,8 +202,9 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, ...@@ -203,8 +202,9 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm,
return 0; return 0;
} }
static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) static void meson_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
{ {
struct meson_pwm *meson = to_meson_pwm(chip);
struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm];
struct meson_pwm_channel_data *channel_data; struct meson_pwm_channel_data *channel_data;
unsigned long flags; unsigned long flags;
...@@ -215,7 +215,7 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) ...@@ -215,7 +215,7 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm)
err = clk_set_rate(channel->clk, channel->rate); err = clk_set_rate(channel->clk, channel->rate);
if (err) if (err)
dev_err(meson->chip.dev, "setting clock rate failed\n"); dev_err(pwmchip_parent(chip), "setting clock rate failed\n");
spin_lock_irqsave(&meson->lock, flags); spin_lock_irqsave(&meson->lock, flags);
...@@ -230,8 +230,9 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) ...@@ -230,8 +230,9 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm)
spin_unlock_irqrestore(&meson->lock, flags); spin_unlock_irqrestore(&meson->lock, flags);
} }
static void meson_pwm_disable(struct meson_pwm *meson, struct pwm_device *pwm) static void meson_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
{ {
struct meson_pwm *meson = to_meson_pwm(chip);
unsigned long flags; unsigned long flags;
u32 value; u32 value;
...@@ -269,16 +270,16 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -269,16 +270,16 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
channel->hi = ~0; channel->hi = ~0;
channel->lo = 0; channel->lo = 0;
meson_pwm_enable(meson, pwm); meson_pwm_enable(chip, pwm);
} else { } else {
meson_pwm_disable(meson, pwm); meson_pwm_disable(chip, pwm);
} }
} else { } else {
err = meson_pwm_calc(meson, pwm, state); err = meson_pwm_calc(chip, pwm, state);
if (err < 0) if (err < 0)
return err; return err;
meson_pwm_enable(meson, pwm); meson_pwm_enable(chip, pwm);
} }
return 0; return 0;
...@@ -337,62 +338,32 @@ static const struct pwm_ops meson_pwm_ops = { ...@@ -337,62 +338,32 @@ static const struct pwm_ops meson_pwm_ops = {
.get_state = meson_pwm_get_state, .get_state = meson_pwm_get_state,
}; };
static const char * const pwm_meson8b_parent_names[] = {
"xtal", NULL, "fclk_div4", "fclk_div3"
};
static const struct meson_pwm_data pwm_meson8b_data = { static const struct meson_pwm_data pwm_meson8b_data = {
.parent_names = pwm_meson8b_parent_names, .parent_names = { "xtal", NULL, "fclk_div4", "fclk_div3" },
.num_parents = ARRAY_SIZE(pwm_meson8b_parent_names),
}; };
/* /*
* Only the 2 first inputs of the GXBB AO PWMs are valid * Only the 2 first inputs of the GXBB AO PWMs are valid
* The last 2 are grounded * The last 2 are grounded
*/ */
static const char * const pwm_gxbb_ao_parent_names[] = {
"xtal", "clk81"
};
static const struct meson_pwm_data pwm_gxbb_ao_data = { static const struct meson_pwm_data pwm_gxbb_ao_data = {
.parent_names = pwm_gxbb_ao_parent_names, .parent_names = { "xtal", "clk81", NULL, NULL },
.num_parents = ARRAY_SIZE(pwm_gxbb_ao_parent_names),
};
static const char * const pwm_axg_ee_parent_names[] = {
"xtal", "fclk_div5", "fclk_div4", "fclk_div3"
}; };
static const struct meson_pwm_data pwm_axg_ee_data = { static const struct meson_pwm_data pwm_axg_ee_data = {
.parent_names = pwm_axg_ee_parent_names, .parent_names = { "xtal", "fclk_div5", "fclk_div4", "fclk_div3" },
.num_parents = ARRAY_SIZE(pwm_axg_ee_parent_names),
};
static const char * const pwm_axg_ao_parent_names[] = {
"xtal", "axg_ao_clk81", "fclk_div4", "fclk_div5"
}; };
static const struct meson_pwm_data pwm_axg_ao_data = { static const struct meson_pwm_data pwm_axg_ao_data = {
.parent_names = pwm_axg_ao_parent_names, .parent_names = { "xtal", "axg_ao_clk81", "fclk_div4", "fclk_div5" },
.num_parents = ARRAY_SIZE(pwm_axg_ao_parent_names),
};
static const char * const pwm_g12a_ao_ab_parent_names[] = {
"xtal", "g12a_ao_clk81", "fclk_div4", "fclk_div5"
}; };
static const struct meson_pwm_data pwm_g12a_ao_ab_data = { static const struct meson_pwm_data pwm_g12a_ao_ab_data = {
.parent_names = pwm_g12a_ao_ab_parent_names, .parent_names = { "xtal", "g12a_ao_clk81", "fclk_div4", "fclk_div5" },
.num_parents = ARRAY_SIZE(pwm_g12a_ao_ab_parent_names),
};
static const char * const pwm_g12a_ao_cd_parent_names[] = {
"xtal", "g12a_ao_clk81",
}; };
static const struct meson_pwm_data pwm_g12a_ao_cd_data = { static const struct meson_pwm_data pwm_g12a_ao_cd_data = {
.parent_names = pwm_g12a_ao_cd_parent_names, .parent_names = { "xtal", "g12a_ao_clk81", NULL, NULL },
.num_parents = ARRAY_SIZE(pwm_g12a_ao_cd_parent_names),
}; };
static const struct of_device_id meson_pwm_matches[] = { static const struct of_device_id meson_pwm_matches[] = {
...@@ -432,20 +403,21 @@ static const struct of_device_id meson_pwm_matches[] = { ...@@ -432,20 +403,21 @@ static const struct of_device_id meson_pwm_matches[] = {
}; };
MODULE_DEVICE_TABLE(of, meson_pwm_matches); MODULE_DEVICE_TABLE(of, meson_pwm_matches);
static int meson_pwm_init_channels(struct meson_pwm *meson) static int meson_pwm_init_channels(struct pwm_chip *chip)
{ {
struct clk_parent_data mux_parent_data[MESON_MAX_MUX_PARENTS] = {}; struct meson_pwm *meson = to_meson_pwm(chip);
struct device *dev = meson->chip.dev; struct clk_parent_data mux_parent_data[MESON_NUM_MUX_PARENTS] = {};
struct device *dev = pwmchip_parent(chip);
unsigned int i; unsigned int i;
char name[255]; char name[255];
int err; int err;
for (i = 0; i < meson->data->num_parents; i++) { for (i = 0; i < MESON_NUM_MUX_PARENTS; i++) {
mux_parent_data[i].index = -1; mux_parent_data[i].index = -1;
mux_parent_data[i].name = meson->data->parent_names[i]; mux_parent_data[i].name = meson->data->parent_names[i];
} }
for (i = 0; i < meson->chip.npwm; i++) { for (i = 0; i < chip->npwm; i++) {
struct meson_pwm_channel *channel = &meson->channels[i]; struct meson_pwm_channel *channel = &meson->channels[i];
struct clk_parent_data div_parent = {}, gate_parent = {}; struct clk_parent_data div_parent = {}, gate_parent = {};
struct clk_init_data init = {}; struct clk_init_data init = {};
...@@ -456,7 +428,7 @@ static int meson_pwm_init_channels(struct meson_pwm *meson) ...@@ -456,7 +428,7 @@ static int meson_pwm_init_channels(struct meson_pwm *meson)
init.ops = &clk_mux_ops; init.ops = &clk_mux_ops;
init.flags = 0; init.flags = 0;
init.parent_data = mux_parent_data; init.parent_data = mux_parent_data;
init.num_parents = meson->data->num_parents; init.num_parents = MESON_NUM_MUX_PARENTS;
channel->mux.reg = meson->base + REG_MISC_AB; channel->mux.reg = meson->base + REG_MISC_AB;
channel->mux.shift = channel->mux.shift =
...@@ -525,29 +497,29 @@ static int meson_pwm_init_channels(struct meson_pwm *meson) ...@@ -525,29 +497,29 @@ static int meson_pwm_init_channels(struct meson_pwm *meson)
static int meson_pwm_probe(struct platform_device *pdev) static int meson_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct meson_pwm *meson; struct meson_pwm *meson;
int err; int err;
meson = devm_kzalloc(&pdev->dev, sizeof(*meson), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, MESON_NUM_PWMS, sizeof(*meson));
if (!meson) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
meson = to_meson_pwm(chip);
meson->base = devm_platform_ioremap_resource(pdev, 0); meson->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(meson->base)) if (IS_ERR(meson->base))
return PTR_ERR(meson->base); return PTR_ERR(meson->base);
spin_lock_init(&meson->lock); spin_lock_init(&meson->lock);
meson->chip.dev = &pdev->dev; chip->ops = &meson_pwm_ops;
meson->chip.ops = &meson_pwm_ops;
meson->chip.npwm = MESON_NUM_PWMS;
meson->data = of_device_get_match_data(&pdev->dev); meson->data = of_device_get_match_data(&pdev->dev);
err = meson_pwm_init_channels(meson); err = meson_pwm_init_channels(chip);
if (err < 0) if (err < 0)
return err; return err;
err = devm_pwmchip_add(&pdev->dev, &meson->chip); err = devm_pwmchip_add(&pdev->dev, chip);
if (err < 0) if (err < 0)
return dev_err_probe(&pdev->dev, err, return dev_err_probe(&pdev->dev, err,
"failed to register PWM chip\n"); "failed to register PWM chip\n");
......
...@@ -54,7 +54,6 @@ ...@@ -54,7 +54,6 @@
#define MCHPCOREPWM_TIMEOUT_MS 100u #define MCHPCOREPWM_TIMEOUT_MS 100u
struct mchp_core_pwm_chip { struct mchp_core_pwm_chip {
struct pwm_chip chip;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
struct mutex lock; /* protects the shared period */ struct mutex lock; /* protects the shared period */
...@@ -65,7 +64,7 @@ struct mchp_core_pwm_chip { ...@@ -65,7 +64,7 @@ struct mchp_core_pwm_chip {
static inline struct mchp_core_pwm_chip *to_mchp_core_pwm(struct pwm_chip *chip) static inline struct mchp_core_pwm_chip *to_mchp_core_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct mchp_core_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
static void mchp_core_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm, static void mchp_core_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm,
...@@ -447,13 +446,15 @@ MODULE_DEVICE_TABLE(of, mchp_core_of_match); ...@@ -447,13 +446,15 @@ MODULE_DEVICE_TABLE(of, mchp_core_of_match);
static int mchp_core_pwm_probe(struct platform_device *pdev) static int mchp_core_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct mchp_core_pwm_chip *mchp_core_pwm; struct mchp_core_pwm_chip *mchp_core_pwm;
struct resource *regs; struct resource *regs;
int ret; int ret;
mchp_core_pwm = devm_kzalloc(&pdev->dev, sizeof(*mchp_core_pwm), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 16, sizeof(*mchp_core_pwm));
if (!mchp_core_pwm) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
mchp_core_pwm = to_mchp_core_pwm(chip);
mchp_core_pwm->base = devm_platform_get_and_ioremap_resource(pdev, 0, &regs); mchp_core_pwm->base = devm_platform_get_and_ioremap_resource(pdev, 0, &regs);
if (IS_ERR(mchp_core_pwm->base)) if (IS_ERR(mchp_core_pwm->base))
...@@ -470,9 +471,7 @@ static int mchp_core_pwm_probe(struct platform_device *pdev) ...@@ -470,9 +471,7 @@ static int mchp_core_pwm_probe(struct platform_device *pdev)
mutex_init(&mchp_core_pwm->lock); mutex_init(&mchp_core_pwm->lock);
mchp_core_pwm->chip.dev = &pdev->dev; chip->ops = &mchp_core_pwm_ops;
mchp_core_pwm->chip.ops = &mchp_core_pwm_ops;
mchp_core_pwm->chip.npwm = 16;
mchp_core_pwm->channel_enabled = readb_relaxed(mchp_core_pwm->base + MCHPCOREPWM_EN(0)); mchp_core_pwm->channel_enabled = readb_relaxed(mchp_core_pwm->base + MCHPCOREPWM_EN(0));
mchp_core_pwm->channel_enabled |= mchp_core_pwm->channel_enabled |=
...@@ -485,7 +484,7 @@ static int mchp_core_pwm_probe(struct platform_device *pdev) ...@@ -485,7 +484,7 @@ static int mchp_core_pwm_probe(struct platform_device *pdev)
writel_relaxed(1U, mchp_core_pwm->base + MCHPCOREPWM_SYNC_UPD); writel_relaxed(1U, mchp_core_pwm->base + MCHPCOREPWM_SYNC_UPD);
mchp_core_pwm->update_timestamp = ktime_get(); mchp_core_pwm->update_timestamp = ktime_get();
ret = devm_pwmchip_add(&pdev->dev, &mchp_core_pwm->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret) if (ret)
return dev_err_probe(&pdev->dev, ret, "Failed to add pwmchip\n"); return dev_err_probe(&pdev->dev, ret, "Failed to add pwmchip\n");
......
...@@ -42,7 +42,6 @@ struct mtk_pwm_data { ...@@ -42,7 +42,6 @@ struct mtk_pwm_data {
}; };
struct mtk_disp_pwm { struct mtk_disp_pwm {
struct pwm_chip chip;
const struct mtk_pwm_data *data; const struct mtk_pwm_data *data;
struct clk *clk_main; struct clk *clk_main;
struct clk *clk_mm; struct clk *clk_mm;
...@@ -52,7 +51,7 @@ struct mtk_disp_pwm { ...@@ -52,7 +51,7 @@ struct mtk_disp_pwm {
static inline struct mtk_disp_pwm *to_mtk_disp_pwm(struct pwm_chip *chip) static inline struct mtk_disp_pwm *to_mtk_disp_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct mtk_disp_pwm, chip); return pwmchip_get_drvdata(chip);
} }
static void mtk_disp_pwm_update_bits(struct mtk_disp_pwm *mdp, u32 offset, static void mtk_disp_pwm_update_bits(struct mtk_disp_pwm *mdp, u32 offset,
...@@ -91,14 +90,14 @@ static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -91,14 +90,14 @@ static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
if (!mdp->enabled) { if (!mdp->enabled) {
err = clk_prepare_enable(mdp->clk_main); err = clk_prepare_enable(mdp->clk_main);
if (err < 0) { if (err < 0) {
dev_err(chip->dev, "Can't enable mdp->clk_main: %pe\n", dev_err(pwmchip_parent(chip), "Can't enable mdp->clk_main: %pe\n",
ERR_PTR(err)); ERR_PTR(err));
return err; return err;
} }
err = clk_prepare_enable(mdp->clk_mm); err = clk_prepare_enable(mdp->clk_mm);
if (err < 0) { if (err < 0) {
dev_err(chip->dev, "Can't enable mdp->clk_mm: %pe\n", dev_err(pwmchip_parent(chip), "Can't enable mdp->clk_mm: %pe\n",
ERR_PTR(err)); ERR_PTR(err));
clk_disable_unprepare(mdp->clk_main); clk_disable_unprepare(mdp->clk_main);
return err; return err;
...@@ -181,13 +180,13 @@ static int mtk_disp_pwm_get_state(struct pwm_chip *chip, ...@@ -181,13 +180,13 @@ static int mtk_disp_pwm_get_state(struct pwm_chip *chip,
err = clk_prepare_enable(mdp->clk_main); err = clk_prepare_enable(mdp->clk_main);
if (err < 0) { if (err < 0) {
dev_err(chip->dev, "Can't enable mdp->clk_main: %pe\n", ERR_PTR(err)); dev_err(pwmchip_parent(chip), "Can't enable mdp->clk_main: %pe\n", ERR_PTR(err));
return err; return err;
} }
err = clk_prepare_enable(mdp->clk_mm); err = clk_prepare_enable(mdp->clk_mm);
if (err < 0) { if (err < 0) {
dev_err(chip->dev, "Can't enable mdp->clk_mm: %pe\n", ERR_PTR(err)); dev_err(pwmchip_parent(chip), "Can't enable mdp->clk_mm: %pe\n", ERR_PTR(err));
clk_disable_unprepare(mdp->clk_main); clk_disable_unprepare(mdp->clk_main);
return err; return err;
} }
...@@ -231,12 +230,14 @@ static const struct pwm_ops mtk_disp_pwm_ops = { ...@@ -231,12 +230,14 @@ static const struct pwm_ops mtk_disp_pwm_ops = {
static int mtk_disp_pwm_probe(struct platform_device *pdev) static int mtk_disp_pwm_probe(struct platform_device *pdev)
{ {
struct pwm_chip *chip;
struct mtk_disp_pwm *mdp; struct mtk_disp_pwm *mdp;
int ret; int ret;
mdp = devm_kzalloc(&pdev->dev, sizeof(*mdp), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*mdp));
if (!mdp) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
mdp = to_mtk_disp_pwm(chip);
mdp->data = of_device_get_match_data(&pdev->dev); mdp->data = of_device_get_match_data(&pdev->dev);
...@@ -254,11 +255,9 @@ static int mtk_disp_pwm_probe(struct platform_device *pdev) ...@@ -254,11 +255,9 @@ static int mtk_disp_pwm_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(mdp->clk_mm), return dev_err_probe(&pdev->dev, PTR_ERR(mdp->clk_mm),
"Failed to get mm clock\n"); "Failed to get mm clock\n");
mdp->chip.dev = &pdev->dev; chip->ops = &mtk_disp_pwm_ops;
mdp->chip.ops = &mtk_disp_pwm_ops;
mdp->chip.npwm = 1;
ret = devm_pwmchip_add(&pdev->dev, &mdp->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) if (ret < 0)
return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n"); return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n");
......
...@@ -37,12 +37,14 @@ static const u8 cdiv_shift[PERIOD_CDIV_MAX] = { ...@@ -37,12 +37,14 @@ static const u8 cdiv_shift[PERIOD_CDIV_MAX] = {
}; };
struct mxs_pwm_chip { struct mxs_pwm_chip {
struct pwm_chip chip;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
}; };
#define to_mxs_pwm_chip(_chip) container_of(_chip, struct mxs_pwm_chip, chip) static inline struct mxs_pwm_chip *to_mxs_pwm_chip(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state) const struct pwm_state *state)
...@@ -120,12 +122,21 @@ static const struct pwm_ops mxs_pwm_ops = { ...@@ -120,12 +122,21 @@ static const struct pwm_ops mxs_pwm_ops = {
static int mxs_pwm_probe(struct platform_device *pdev) static int mxs_pwm_probe(struct platform_device *pdev)
{ {
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct pwm_chip *chip;
struct mxs_pwm_chip *mxs; struct mxs_pwm_chip *mxs;
u32 npwm;
int ret; int ret;
mxs = devm_kzalloc(&pdev->dev, sizeof(*mxs), GFP_KERNEL); ret = of_property_read_u32(np, "fsl,pwm-number", &npwm);
if (!mxs) if (ret < 0) {
return -ENOMEM; dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret);
return ret;
}
chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*mxs));
if (IS_ERR(chip))
return PTR_ERR(chip);
mxs = to_mxs_pwm_chip(chip);
mxs->base = devm_platform_ioremap_resource(pdev, 0); mxs->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(mxs->base)) if (IS_ERR(mxs->base))
...@@ -135,21 +146,14 @@ static int mxs_pwm_probe(struct platform_device *pdev) ...@@ -135,21 +146,14 @@ static int mxs_pwm_probe(struct platform_device *pdev)
if (IS_ERR(mxs->clk)) if (IS_ERR(mxs->clk))
return PTR_ERR(mxs->clk); return PTR_ERR(mxs->clk);
mxs->chip.dev = &pdev->dev; chip->ops = &mxs_pwm_ops;
mxs->chip.ops = &mxs_pwm_ops;
ret = of_property_read_u32(np, "fsl,pwm-number", &mxs->chip.npwm);
if (ret < 0) {
dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret);
return ret;
}
/* FIXME: Only do this if the PWM isn't already running */ /* FIXME: Only do this if the PWM isn't already running */
ret = stmp_reset_block(mxs->base); ret = stmp_reset_block(mxs->base);
if (ret) if (ret)
return dev_err_probe(&pdev->dev, ret, "failed to reset PWM\n"); return dev_err_probe(&pdev->dev, ret, "failed to reset PWM\n");
ret = devm_pwmchip_add(&pdev->dev, &mxs->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "failed to add pwm chip %d\n", ret); dev_err(&pdev->dev, "failed to add pwm chip %d\n", ret);
return ret; return ret;
......
...@@ -25,12 +25,11 @@ ...@@ -25,12 +25,11 @@
struct ntxec_pwm { struct ntxec_pwm {
struct ntxec *ec; struct ntxec *ec;
struct pwm_chip chip;
}; };
static struct ntxec_pwm *ntxec_pwm_from_chip(struct pwm_chip *chip) static struct ntxec_pwm *ntxec_pwm_from_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct ntxec_pwm, chip); return pwmchip_get_drvdata(chip);
} }
#define NTXEC_REG_AUTO_OFF_HI 0xa1 #define NTXEC_REG_AUTO_OFF_HI 0xa1
...@@ -141,16 +140,13 @@ static int ntxec_pwm_probe(struct platform_device *pdev) ...@@ -141,16 +140,13 @@ static int ntxec_pwm_probe(struct platform_device *pdev)
device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent); device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent);
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*priv));
if (!priv) if (IS_ERR(chip))
return -ENOMEM; return PTR_ERR(chip);
priv = ntxec_pwm_from_chip(chip);
priv->ec = ec; priv->ec = ec;
chip = &priv->chip;
chip->dev = &pdev->dev;
chip->ops = &ntxec_pwm_ops; chip->ops = &ntxec_pwm_ops;
chip->npwm = 1;
return devm_pwmchip_add(&pdev->dev, chip); return devm_pwmchip_add(&pdev->dev, chip);
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -49,7 +49,6 @@ MODULE_DEVICE_TABLE(platform, pwm_id_table); ...@@ -49,7 +49,6 @@ MODULE_DEVICE_TABLE(platform, pwm_id_table);
#define PWMDCR_FD (1 << 10) #define PWMDCR_FD (1 << 10)
struct pxa_pwm_chip { struct pxa_pwm_chip {
struct pwm_chip chip;
struct device *dev; struct device *dev;
struct clk *clk; struct clk *clk;
...@@ -58,7 +57,7 @@ struct pxa_pwm_chip { ...@@ -58,7 +57,7 @@ struct pxa_pwm_chip {
static inline struct pxa_pwm_chip *to_pxa_pwm_chip(struct pwm_chip *chip) static inline struct pxa_pwm_chip *to_pxa_pwm_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct pxa_pwm_chip, chip); return pwmchip_get_drvdata(chip);
} }
/* /*
...@@ -159,6 +158,7 @@ MODULE_DEVICE_TABLE(of, pwm_of_match); ...@@ -159,6 +158,7 @@ MODULE_DEVICE_TABLE(of, pwm_of_match);
static int pwm_probe(struct platform_device *pdev) static int pwm_probe(struct platform_device *pdev)
{ {
const struct platform_device_id *id = platform_get_device_id(pdev); const struct platform_device_id *id = platform_get_device_id(pdev);
struct pwm_chip *chip;
struct pxa_pwm_chip *pc; struct pxa_pwm_chip *pc;
int ret = 0; int ret = 0;
...@@ -168,28 +168,27 @@ static int pwm_probe(struct platform_device *pdev) ...@@ -168,28 +168,27 @@ static int pwm_probe(struct platform_device *pdev)
if (id == NULL) if (id == NULL)
return -EINVAL; return -EINVAL;
pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev,
if (pc == NULL) (id->driver_data & HAS_SECONDARY_PWM) ? 2 : 1,
return -ENOMEM; sizeof(*pc));
if (IS_ERR(chip))
return PTR_ERR(chip);
pc = to_pxa_pwm_chip(chip);
pc->clk = devm_clk_get(&pdev->dev, NULL); pc->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(pc->clk)) if (IS_ERR(pc->clk))
return PTR_ERR(pc->clk); return PTR_ERR(pc->clk);
pc->chip.dev = &pdev->dev; chip->ops = &pxa_pwm_ops;
pc->chip.ops = &pxa_pwm_ops;
pc->chip.npwm = (id->driver_data & HAS_SECONDARY_PWM) ? 2 : 1;
if (IS_ENABLED(CONFIG_OF)) { if (IS_ENABLED(CONFIG_OF))
pc->chip.of_xlate = of_pwm_single_xlate; chip->of_xlate = of_pwm_single_xlate;
pc->chip.of_pwm_n_cells = 1;
}
pc->mmio_base = devm_platform_ioremap_resource(pdev, 0); pc->mmio_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(pc->mmio_base)) if (IS_ERR(pc->mmio_base))
return PTR_ERR(pc->mmio_base); return PTR_ERR(pc->mmio_base);
ret = devm_pwmchip_add(&pdev->dev, &pc->chip); ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
return ret; return ret;
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
struct raspberrypi_pwm { struct raspberrypi_pwm {
struct rpi_firmware *firmware; struct rpi_firmware *firmware;
struct pwm_chip chip;
unsigned int duty_cycle; unsigned int duty_cycle;
}; };
...@@ -40,7 +39,7 @@ struct raspberrypi_pwm_prop { ...@@ -40,7 +39,7 @@ struct raspberrypi_pwm_prop {
static inline static inline
struct raspberrypi_pwm *raspberrypi_pwm_from_chip(struct pwm_chip *chip) struct raspberrypi_pwm *raspberrypi_pwm_from_chip(struct pwm_chip *chip)
{ {
return container_of(chip, struct raspberrypi_pwm, chip); return pwmchip_get_drvdata(chip);
} }
static int raspberrypi_pwm_set_property(struct rpi_firmware *firmware, static int raspberrypi_pwm_set_property(struct rpi_firmware *firmware,
...@@ -122,7 +121,7 @@ static int raspberrypi_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -122,7 +121,7 @@ static int raspberrypi_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
ret = raspberrypi_pwm_set_property(rpipwm->firmware, RPI_PWM_CUR_DUTY_REG, ret = raspberrypi_pwm_set_property(rpipwm->firmware, RPI_PWM_CUR_DUTY_REG,
duty_cycle); duty_cycle);
if (ret) { if (ret) {
dev_err(chip->dev, "Failed to set duty cycle: %pe\n", dev_err(pwmchip_parent(chip), "Failed to set duty cycle: %pe\n",
ERR_PTR(ret)); ERR_PTR(ret));
return ret; return ret;
} }
...@@ -142,6 +141,7 @@ static int raspberrypi_pwm_probe(struct platform_device *pdev) ...@@ -142,6 +141,7 @@ static int raspberrypi_pwm_probe(struct platform_device *pdev)
struct device_node *firmware_node; struct device_node *firmware_node;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct rpi_firmware *firmware; struct rpi_firmware *firmware;
struct pwm_chip *chip;
struct raspberrypi_pwm *rpipwm; struct raspberrypi_pwm *rpipwm;
int ret; int ret;
...@@ -157,14 +157,14 @@ static int raspberrypi_pwm_probe(struct platform_device *pdev) ...@@ -157,14 +157,14 @@ static int raspberrypi_pwm_probe(struct platform_device *pdev)
return dev_err_probe(dev, -EPROBE_DEFER, return dev_err_probe(dev, -EPROBE_DEFER,
"Failed to get firmware handle\n"); "Failed to get firmware handle\n");
rpipwm = devm_kzalloc(&pdev->dev, sizeof(*rpipwm), GFP_KERNEL); chip = devm_pwmchip_alloc(&pdev->dev, RASPBERRYPI_FIRMWARE_PWM_NUM,
if (!rpipwm) sizeof(*rpipwm));
return -ENOMEM; if (IS_ERR(chip))
return PTR_ERR(chip);
rpipwm = raspberrypi_pwm_from_chip(chip);
rpipwm->firmware = firmware; rpipwm->firmware = firmware;
rpipwm->chip.dev = dev; chip->ops = &raspberrypi_pwm_ops;
rpipwm->chip.ops = &raspberrypi_pwm_ops;
rpipwm->chip.npwm = RASPBERRYPI_FIRMWARE_PWM_NUM;
ret = raspberrypi_pwm_get_property(rpipwm->firmware, RPI_PWM_CUR_DUTY_REG, ret = raspberrypi_pwm_get_property(rpipwm->firmware, RPI_PWM_CUR_DUTY_REG,
&rpipwm->duty_cycle); &rpipwm->duty_cycle);
...@@ -173,7 +173,7 @@ static int raspberrypi_pwm_probe(struct platform_device *pdev) ...@@ -173,7 +173,7 @@ static int raspberrypi_pwm_probe(struct platform_device *pdev)
return ret; return ret;
} }
return devm_pwmchip_add(dev, &rpipwm->chip); return devm_pwmchip_add(dev, chip);
} }
static const struct of_device_id raspberrypi_pwm_of_match[] = { static const struct of_device_id raspberrypi_pwm_of_match[] = {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment