Commit 5a1c18b7 authored by Rafał Miłecki's avatar Rafał Miłecki Committed by Kalle Valo

bcma: keep a direct pointer to the struct device

Accessing struct device is pretty useful/common so having a direct
pointer:
1) Simplifies some code
2) Makes bcma_bus_get_host_dev() unneeded
3) Allows further improvements like using dev_* printing helpers
Signed-off-by: default avatarRafał Miłecki <rafal@milecki.pl>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent 7fdcb8e1
...@@ -33,7 +33,6 @@ int __init bcma_bus_early_register(struct bcma_bus *bus); ...@@ -33,7 +33,6 @@ int __init bcma_bus_early_register(struct bcma_bus *bus);
int bcma_bus_suspend(struct bcma_bus *bus); int bcma_bus_suspend(struct bcma_bus *bus);
int bcma_bus_resume(struct bcma_bus *bus); int bcma_bus_resume(struct bcma_bus *bus);
#endif #endif
struct device *bcma_bus_get_host_dev(struct bcma_bus *bus);
/* scan.c */ /* scan.c */
void bcma_detect_chip(struct bcma_bus *bus); void bcma_detect_chip(struct bcma_bus *bus);
......
...@@ -183,7 +183,7 @@ int bcma_gpio_init(struct bcma_drv_cc *cc) ...@@ -183,7 +183,7 @@ int bcma_gpio_init(struct bcma_drv_cc *cc)
chip->direction_input = bcma_gpio_direction_input; chip->direction_input = bcma_gpio_direction_input;
chip->direction_output = bcma_gpio_direction_output; chip->direction_output = bcma_gpio_direction_output;
chip->owner = THIS_MODULE; chip->owner = THIS_MODULE;
chip->parent = bcma_bus_get_host_dev(bus); chip->parent = bus->dev;
#if IS_BUILTIN(CONFIG_OF) #if IS_BUILTIN(CONFIG_OF)
chip->of_node = cc->core->dev.of_node; chip->of_node = cc->core->dev.of_node;
#endif #endif
......
...@@ -196,6 +196,8 @@ static int bcma_host_pci_probe(struct pci_dev *dev, ...@@ -196,6 +196,8 @@ static int bcma_host_pci_probe(struct pci_dev *dev,
goto err_pci_release_regions; goto err_pci_release_regions;
} }
bus->dev = &dev->dev;
/* Map MMIO */ /* Map MMIO */
err = -ENOMEM; err = -ENOMEM;
bus->mmio = pci_iomap(dev, 0, ~0UL); bus->mmio = pci_iomap(dev, 0, ~0UL);
......
...@@ -179,7 +179,6 @@ int __init bcma_host_soc_register(struct bcma_soc *soc) ...@@ -179,7 +179,6 @@ int __init bcma_host_soc_register(struct bcma_soc *soc)
/* Host specific */ /* Host specific */
bus->hosttype = BCMA_HOSTTYPE_SOC; bus->hosttype = BCMA_HOSTTYPE_SOC;
bus->ops = &bcma_host_soc_ops; bus->ops = &bcma_host_soc_ops;
bus->host_pdev = NULL;
/* Initialize struct, detect chip */ /* Initialize struct, detect chip */
bcma_init_bus(bus); bcma_init_bus(bus);
...@@ -213,6 +212,8 @@ static int bcma_host_soc_probe(struct platform_device *pdev) ...@@ -213,6 +212,8 @@ static int bcma_host_soc_probe(struct platform_device *pdev)
if (!bus) if (!bus)
return -ENOMEM; return -ENOMEM;
bus->dev = dev;
/* Map MMIO */ /* Map MMIO */
bus->mmio = of_iomap(np, 0); bus->mmio = of_iomap(np, 0);
if (!bus->mmio) if (!bus->mmio)
...@@ -221,7 +222,6 @@ static int bcma_host_soc_probe(struct platform_device *pdev) ...@@ -221,7 +222,6 @@ static int bcma_host_soc_probe(struct platform_device *pdev)
/* Host specific */ /* Host specific */
bus->hosttype = BCMA_HOSTTYPE_SOC; bus->hosttype = BCMA_HOSTTYPE_SOC;
bus->ops = &bcma_host_soc_ops; bus->ops = &bcma_host_soc_ops;
bus->host_pdev = pdev;
/* Initialize struct, detect chip */ /* Initialize struct, detect chip */
bcma_init_bus(bus); bcma_init_bus(bus);
......
...@@ -223,8 +223,8 @@ unsigned int bcma_core_irq(struct bcma_device *core, int num) ...@@ -223,8 +223,8 @@ unsigned int bcma_core_irq(struct bcma_device *core, int num)
mips_irq = bcma_core_mips_irq(core); mips_irq = bcma_core_mips_irq(core);
return mips_irq <= 4 ? mips_irq + 2 : 0; return mips_irq <= 4 ? mips_irq + 2 : 0;
} }
if (bus->host_pdev) if (bus->dev)
return bcma_of_get_irq(&bus->host_pdev->dev, core, num); return bcma_of_get_irq(bus->dev, core, num);
return 0; return 0;
case BCMA_HOSTTYPE_SDIO: case BCMA_HOSTTYPE_SDIO:
return 0; return 0;
...@@ -239,18 +239,18 @@ void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core) ...@@ -239,18 +239,18 @@ void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core)
core->dev.release = bcma_release_core_dev; core->dev.release = bcma_release_core_dev;
core->dev.bus = &bcma_bus_type; core->dev.bus = &bcma_bus_type;
dev_set_name(&core->dev, "bcma%d:%d", bus->num, core->core_index); dev_set_name(&core->dev, "bcma%d:%d", bus->num, core->core_index);
core->dev.parent = bcma_bus_get_host_dev(bus); core->dev.parent = bus->dev;
if (core->dev.parent) if (bus->dev)
bcma_of_fill_device(core->dev.parent, core); bcma_of_fill_device(bus->dev, core);
switch (bus->hosttype) { switch (bus->hosttype) {
case BCMA_HOSTTYPE_PCI: case BCMA_HOSTTYPE_PCI:
core->dma_dev = &bus->host_pci->dev; core->dma_dev = bus->dev;
core->irq = bus->host_pci->irq; core->irq = bus->host_pci->irq;
break; break;
case BCMA_HOSTTYPE_SOC: case BCMA_HOSTTYPE_SOC:
if (IS_ENABLED(CONFIG_OF) && bus->host_pdev) { if (IS_ENABLED(CONFIG_OF) && bus->dev) {
core->dma_dev = &bus->host_pdev->dev; core->dma_dev = bus->dev;
} else { } else {
core->dev.dma_mask = &core->dev.coherent_dma_mask; core->dev.dma_mask = &core->dev.coherent_dma_mask;
core->dma_dev = &core->dev; core->dma_dev = &core->dev;
...@@ -261,28 +261,6 @@ void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core) ...@@ -261,28 +261,6 @@ void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core)
} }
} }
struct device *bcma_bus_get_host_dev(struct bcma_bus *bus)
{
switch (bus->hosttype) {
case BCMA_HOSTTYPE_PCI:
if (bus->host_pci)
return &bus->host_pci->dev;
else
return NULL;
case BCMA_HOSTTYPE_SOC:
if (bus->host_pdev)
return &bus->host_pdev->dev;
else
return NULL;
case BCMA_HOSTTYPE_SDIO:
if (bus->host_sdio)
return &bus->host_sdio->dev;
else
return NULL;
}
return NULL;
}
void bcma_init_bus(struct bcma_bus *bus) void bcma_init_bus(struct bcma_bus *bus)
{ {
mutex_lock(&bcma_buses_mutex); mutex_lock(&bcma_buses_mutex);
...@@ -402,7 +380,6 @@ int bcma_bus_register(struct bcma_bus *bus) ...@@ -402,7 +380,6 @@ int bcma_bus_register(struct bcma_bus *bus)
{ {
int err; int err;
struct bcma_device *core; struct bcma_device *core;
struct device *dev;
/* Scan for devices (cores) */ /* Scan for devices (cores) */
err = bcma_bus_scan(bus); err = bcma_bus_scan(bus);
...@@ -425,10 +402,8 @@ int bcma_bus_register(struct bcma_bus *bus) ...@@ -425,10 +402,8 @@ int bcma_bus_register(struct bcma_bus *bus)
bcma_core_pci_early_init(&bus->drv_pci[0]); bcma_core_pci_early_init(&bus->drv_pci[0]);
} }
dev = bcma_bus_get_host_dev(bus); if (bus->dev)
if (dev) { of_platform_default_populate(bus->dev->of_node, NULL, bus->dev);
of_platform_default_populate(dev->of_node, NULL, dev);
}
/* Cores providing flash access go before SPROM init */ /* Cores providing flash access go before SPROM init */
list_for_each_entry(core, &bus->cores, list) { list_for_each_entry(core, &bus->cores, list) {
......
...@@ -332,6 +332,8 @@ extern int bcma_arch_register_fallback_sprom( ...@@ -332,6 +332,8 @@ extern int bcma_arch_register_fallback_sprom(
struct ssb_sprom *out)); struct ssb_sprom *out));
struct bcma_bus { struct bcma_bus {
struct device *dev;
/* The MMIO area. */ /* The MMIO area. */
void __iomem *mmio; void __iomem *mmio;
...@@ -339,14 +341,7 @@ struct bcma_bus { ...@@ -339,14 +341,7 @@ struct bcma_bus {
enum bcma_hosttype hosttype; enum bcma_hosttype hosttype;
bool host_is_pcie2; /* Used for BCMA_HOSTTYPE_PCI only */ bool host_is_pcie2; /* Used for BCMA_HOSTTYPE_PCI only */
union { struct pci_dev *host_pci; /* PCI bus pointer (BCMA_HOSTTYPE_PCI only) */
/* Pointer to the PCI bus (only for BCMA_HOSTTYPE_PCI) */
struct pci_dev *host_pci;
/* Pointer to the SDIO device (only for BCMA_HOSTTYPE_SDIO) */
struct sdio_func *host_sdio;
/* Pointer to platform device (only for BCMA_HOSTTYPE_SOC) */
struct platform_device *host_pdev;
};
struct bcma_chipinfo chipinfo; struct bcma_chipinfo chipinfo;
......
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