1

net: ipa: introduce ipa_interrupt_init()

Create a new function ipa_interrupt_init() that is called at probe
time to allocate and initialize the IPA interrupt data structure.
Create ipa_interrupt_exit() as its inverse.

This follows the normal IPA driver pattern of *_init() functions
doing things that can be done before access to hardware is required.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Alex Elder 2024-03-01 11:02:37 -06:00 committed by David S. Miller
parent e87e4371ed
commit ad1be80d75
3 changed files with 68 additions and 19 deletions

View File

@ -19,6 +19,7 @@
* time only these three are supported. * time only these three are supported.
*/ */
#include <linux/platform_device.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
@ -238,26 +239,15 @@ void ipa_interrupt_simulate_suspend(struct ipa_interrupt *interrupt)
/* Configure the IPA interrupt framework */ /* Configure the IPA interrupt framework */
int ipa_interrupt_config(struct ipa *ipa) int ipa_interrupt_config(struct ipa *ipa)
{ {
struct ipa_interrupt *interrupt = ipa->interrupt;
struct device *dev = &ipa->pdev->dev; struct device *dev = &ipa->pdev->dev;
struct ipa_interrupt *interrupt; unsigned int irq = interrupt->irq;
const struct reg *reg; const struct reg *reg;
unsigned int irq;
int ret; int ret;
ret = platform_get_irq_byname(ipa->pdev, "ipa");
if (ret <= 0) {
dev_err(dev, "DT error %d getting \"ipa\" IRQ property\n", ret);
return ret ? : -EINVAL;
}
irq = ret;
interrupt = kzalloc(sizeof(*interrupt), GFP_KERNEL);
if (!interrupt)
return -ENOMEM;
interrupt->ipa = ipa; interrupt->ipa = ipa;
interrupt->irq = irq;
/* Start with all IPA interrupts disabled */ /* Disable all IPA interrupt types */
reg = ipa_reg(ipa, IPA_IRQ_EN); reg = ipa_reg(ipa, IPA_IRQ_EN);
iowrite32(0, ipa->reg_virt + reg_offset(reg)); iowrite32(0, ipa->reg_virt + reg_offset(reg));
@ -297,5 +287,32 @@ void ipa_interrupt_deconfig(struct ipa *ipa)
dev_pm_clear_wake_irq(dev); dev_pm_clear_wake_irq(dev);
free_irq(interrupt->irq, interrupt); free_irq(interrupt->irq, interrupt);
}
/* Initialize the IPA interrupt structure */
struct ipa_interrupt *ipa_interrupt_init(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct ipa_interrupt *interrupt;
int irq;
irq = platform_get_irq_byname(pdev, "ipa");
if (irq <= 0) {
dev_err(dev, "DT error %d getting \"ipa\" IRQ property\n", irq);
return ERR_PTR(irq ? : -EINVAL);
}
interrupt = kzalloc(sizeof(*interrupt), GFP_KERNEL);
if (!interrupt)
return ERR_PTR(-ENOMEM);
interrupt->irq = irq;
return interrupt;
}
/* Inverse of ipa_interrupt_init() */
void ipa_interrupt_exit(struct ipa_interrupt *interrupt)
{
kfree(interrupt); kfree(interrupt);
} }

View File

@ -89,4 +89,18 @@ int ipa_interrupt_config(struct ipa *ipa);
*/ */
void ipa_interrupt_deconfig(struct ipa *ipa); void ipa_interrupt_deconfig(struct ipa *ipa);
/**
* ipa_interrupt_init() - Initialize the IPA interrupt structure
* @pdev: IPA platform device pointer
*
* Return: Pointer to an IPA interrupt structure, or a pointer-coded error
*/
struct ipa_interrupt *ipa_interrupt_init(struct platform_device *pdev);
/**
* ipa_interrupt_exit() - Inverse of ipa_interrupt_init()
* @interrupt: IPA interrupt structure
*/
void ipa_interrupt_exit(struct ipa_interrupt *interrupt);
#endif /* _IPA_INTERRUPT_H_ */ #endif /* _IPA_INTERRUPT_H_ */

View File

@ -803,6 +803,7 @@ out_self:
static int ipa_probe(struct platform_device *pdev) static int ipa_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct ipa_interrupt *interrupt;
enum ipa_firmware_loader loader; enum ipa_firmware_loader loader;
const struct ipa_data *data; const struct ipa_data *data;
struct ipa_power *power; struct ipa_power *power;
@ -834,12 +835,21 @@ static int ipa_probe(struct platform_device *pdev)
if (loader == IPA_LOADER_DEFER) if (loader == IPA_LOADER_DEFER)
return -EPROBE_DEFER; return -EPROBE_DEFER;
/* The clock and interconnects might not be ready when we're /* The IPA interrupt might not be ready when we're probed, so this
* probed, so might return -EPROBE_DEFER. * might return -EPROBE_DEFER.
*/
interrupt = ipa_interrupt_init(pdev);
if (IS_ERR(interrupt))
return PTR_ERR(interrupt);
/* The clock and interconnects might not be ready when we're probed,
* so this might return -EPROBE_DEFER.
*/ */
power = ipa_power_init(dev, data->power_data); power = ipa_power_init(dev, data->power_data);
if (IS_ERR(power)) if (IS_ERR(power)) {
return PTR_ERR(power); ret = PTR_ERR(power);
goto err_interrupt_exit;
}
/* No more EPROBE_DEFER. Allocate and initialize the IPA structure */ /* No more EPROBE_DEFER. Allocate and initialize the IPA structure */
ipa = kzalloc(sizeof(*ipa), GFP_KERNEL); ipa = kzalloc(sizeof(*ipa), GFP_KERNEL);
@ -850,6 +860,7 @@ static int ipa_probe(struct platform_device *pdev)
ipa->pdev = pdev; ipa->pdev = pdev;
dev_set_drvdata(dev, ipa); dev_set_drvdata(dev, ipa);
ipa->interrupt = interrupt;
ipa->power = power; ipa->power = power;
ipa->version = data->version; ipa->version = data->version;
ipa->modem_route_count = data->modem_route_count; ipa->modem_route_count = data->modem_route_count;
@ -934,6 +945,8 @@ err_kfree_ipa:
kfree(ipa); kfree(ipa);
err_power_exit: err_power_exit:
ipa_power_exit(power); ipa_power_exit(power);
err_interrupt_exit:
ipa_interrupt_exit(interrupt);
return ret; return ret;
} }
@ -941,10 +954,14 @@ err_power_exit:
static void ipa_remove(struct platform_device *pdev) static void ipa_remove(struct platform_device *pdev)
{ {
struct ipa *ipa = dev_get_drvdata(&pdev->dev); struct ipa *ipa = dev_get_drvdata(&pdev->dev);
struct ipa_power *power = ipa->power;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct ipa_interrupt *interrupt;
struct ipa_power *power;
int ret; int ret;
power = ipa->power;
interrupt = ipa->interrupt;
/* Prevent the modem from triggering a call to ipa_setup(). This /* Prevent the modem from triggering a call to ipa_setup(). This
* also ensures a modem-initiated setup that's underway completes. * also ensures a modem-initiated setup that's underway completes.
*/ */
@ -986,6 +1003,7 @@ out_power_put:
ipa_reg_exit(ipa); ipa_reg_exit(ipa);
kfree(ipa); kfree(ipa);
ipa_power_exit(power); ipa_power_exit(power);
ipa_interrupt_exit(interrupt);
dev_info(dev, "IPA driver removed"); dev_info(dev, "IPA driver removed");
} }