Commit aaa3cc29 authored by Uwe Kleine-König's avatar Uwe Kleine-König

pwm: dwc: Prepare removing pwm_chip from driver data

This prepares the driver for further changes that will drop struct
pwm_chip chip from struct dwc_pwm. Use the pwm_chip as driver
data and return value of dwc_pwm_alloc() instead of the dwc_pwm to get
access to the pwm_chip in dwc_pwm_probe() and dwc_pwm_suspend() without
using dwc->chip.

Thanks to Raag Jadav for providing a hunk of this patch that Uwe missed
during creation of this patch.

Link: https://lore.kernel.org/r/008ce5ab84b8e3baa3e81ab6d36dbb0e4be5c319.1707900770.git.u.kleine-koenig@pengutronix.de
Link: https://lore.kernel.org/r/20240219033835.11369-2-raag.jadav@intel.comSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent 452be942
...@@ -159,21 +159,23 @@ static const struct pwm_ops dwc_pwm_ops = { ...@@ -159,21 +159,23 @@ 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); dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
if (!dwc) if (!dwc)
return NULL; return ERR_PTR(-ENOMEM);
chip = &dwc->chip;
dwc->clk_ns = 10; dwc->clk_ns = 10;
dwc->chip.dev = dev; chip->dev = dev;
dwc->chip.ops = &dwc_pwm_ops; chip->ops = &dwc_pwm_ops;
dwc->chip.npwm = DWC_TIMERS_TOTAL; 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);
......
...@@ -28,12 +28,14 @@ ...@@ -28,12 +28,14 @@
static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id) static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)
{ {
struct device *dev = &pci->dev; struct device *dev = &pci->dev;
struct pwm_chip *chip;
struct dwc_pwm *dwc; struct dwc_pwm *dwc;
int ret; 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);
ret = pcim_enable_device(pci); ret = pcim_enable_device(pci);
if (ret) { if (ret) {
...@@ -55,7 +57,7 @@ static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id) ...@@ -55,7 +57,7 @@ static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id)
return -ENOMEM; return -ENOMEM;
} }
ret = devm_pwmchip_add(dev, &dwc->chip); ret = devm_pwmchip_add(dev, chip);
if (ret) if (ret)
return ret; return ret;
...@@ -73,13 +75,14 @@ static void dwc_pwm_remove(struct pci_dev *pci) ...@@ -73,13 +75,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 dwc_pwm *dwc = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
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));
...@@ -92,7 +95,8 @@ static int dwc_pwm_suspend(struct device *dev) ...@@ -92,7 +95,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 dwc_pwm *dwc = dev_get_drvdata(dev); struct pwm_chip *chip = dev_get_drvdata(dev);
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++) {
......
...@@ -57,4 +57,4 @@ static inline void dwc_pwm_writel(struct dwc_pwm *dwc, u32 value, u32 offset) ...@@ -57,4 +57,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);
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