1 From 5a1c18b761ddb299a06746948b9ec2814b04fa92 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Wed, 2 Jan 2019 00:00:01 +0100
4 Subject: [PATCH] bcma: keep a direct pointer to the struct device
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Accessing struct device is pretty useful/common so having a direct
11 1) Simplifies some code
12 2) Makes bcma_bus_get_host_dev() unneeded
13 3) Allows further improvements like using dev_* printing helpers
15 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
18 drivers/bcma/bcma_private.h | 1 -
19 drivers/bcma/driver_gpio.c | 2 +-
20 drivers/bcma/host_pci.c | 2 ++
21 drivers/bcma/host_soc.c | 4 ++--
22 drivers/bcma/main.c | 45 +++++++++----------------------------
23 include/linux/bcma/bcma.h | 11 +++------
24 6 files changed, 18 insertions(+), 47 deletions(-)
26 --- a/drivers/bcma/bcma_private.h
27 +++ b/drivers/bcma/bcma_private.h
28 @@ -33,7 +33,6 @@ int __init bcma_bus_early_register(struc
29 int bcma_bus_suspend(struct bcma_bus *bus);
30 int bcma_bus_resume(struct bcma_bus *bus);
32 -struct device *bcma_bus_get_host_dev(struct bcma_bus *bus);
35 void bcma_detect_chip(struct bcma_bus *bus);
36 --- a/drivers/bcma/driver_gpio.c
37 +++ b/drivers/bcma/driver_gpio.c
38 @@ -183,7 +183,7 @@ int bcma_gpio_init(struct bcma_drv_cc *c
39 chip->direction_input = bcma_gpio_direction_input;
40 chip->direction_output = bcma_gpio_direction_output;
41 chip->owner = THIS_MODULE;
42 - chip->parent = bcma_bus_get_host_dev(bus);
43 + chip->parent = bus->dev;
44 #if IS_BUILTIN(CONFIG_OF)
45 chip->of_node = cc->core->dev.of_node;
47 --- a/drivers/bcma/host_pci.c
48 +++ b/drivers/bcma/host_pci.c
49 @@ -196,6 +196,8 @@ static int bcma_host_pci_probe(struct pc
50 goto err_pci_release_regions;
53 + bus->dev = &dev->dev;
57 bus->mmio = pci_iomap(dev, 0, ~0UL);
58 --- a/drivers/bcma/host_soc.c
59 +++ b/drivers/bcma/host_soc.c
60 @@ -179,7 +179,6 @@ int __init bcma_host_soc_register(struct
62 bus->hosttype = BCMA_HOSTTYPE_SOC;
63 bus->ops = &bcma_host_soc_ops;
64 - bus->host_pdev = NULL;
66 /* Initialize struct, detect chip */
68 @@ -213,6 +212,8 @@ static int bcma_host_soc_probe(struct pl
75 bus->mmio = of_iomap(np, 0);
77 @@ -221,7 +222,6 @@ static int bcma_host_soc_probe(struct pl
79 bus->hosttype = BCMA_HOSTTYPE_SOC;
80 bus->ops = &bcma_host_soc_ops;
81 - bus->host_pdev = pdev;
83 /* Initialize struct, detect chip */
85 --- a/drivers/bcma/main.c
86 +++ b/drivers/bcma/main.c
87 @@ -223,8 +223,8 @@ unsigned int bcma_core_irq(struct bcma_d
88 mips_irq = bcma_core_mips_irq(core);
89 return mips_irq <= 4 ? mips_irq + 2 : 0;
92 - return bcma_of_get_irq(&bus->host_pdev->dev, core, num);
94 + return bcma_of_get_irq(bus->dev, core, num);
96 case BCMA_HOSTTYPE_SDIO:
98 @@ -239,18 +239,18 @@ void bcma_prepare_core(struct bcma_bus *
99 core->dev.release = bcma_release_core_dev;
100 core->dev.bus = &bcma_bus_type;
101 dev_set_name(&core->dev, "bcma%d:%d", bus->num, core->core_index);
102 - core->dev.parent = bcma_bus_get_host_dev(bus);
103 - if (core->dev.parent)
104 - bcma_of_fill_device(core->dev.parent, core);
105 + core->dev.parent = bus->dev;
107 + bcma_of_fill_device(bus->dev, core);
109 switch (bus->hosttype) {
110 case BCMA_HOSTTYPE_PCI:
111 - core->dma_dev = &bus->host_pci->dev;
112 + core->dma_dev = bus->dev;
113 core->irq = bus->host_pci->irq;
115 case BCMA_HOSTTYPE_SOC:
116 - if (IS_ENABLED(CONFIG_OF) && bus->host_pdev) {
117 - core->dma_dev = &bus->host_pdev->dev;
118 + if (IS_ENABLED(CONFIG_OF) && bus->dev) {
119 + core->dma_dev = bus->dev;
121 core->dev.dma_mask = &core->dev.coherent_dma_mask;
122 core->dma_dev = &core->dev;
123 @@ -261,28 +261,6 @@ void bcma_prepare_core(struct bcma_bus *
127 -struct device *bcma_bus_get_host_dev(struct bcma_bus *bus)
129 - switch (bus->hosttype) {
130 - case BCMA_HOSTTYPE_PCI:
132 - return &bus->host_pci->dev;
135 - case BCMA_HOSTTYPE_SOC:
136 - if (bus->host_pdev)
137 - return &bus->host_pdev->dev;
140 - case BCMA_HOSTTYPE_SDIO:
141 - if (bus->host_sdio)
142 - return &bus->host_sdio->dev;
149 void bcma_init_bus(struct bcma_bus *bus)
151 mutex_lock(&bcma_buses_mutex);
152 @@ -402,7 +380,6 @@ int bcma_bus_register(struct bcma_bus *b
155 struct bcma_device *core;
156 - struct device *dev;
158 /* Scan for devices (cores) */
159 err = bcma_bus_scan(bus);
160 @@ -425,10 +402,8 @@ int bcma_bus_register(struct bcma_bus *b
161 bcma_core_pci_early_init(&bus->drv_pci[0]);
164 - dev = bcma_bus_get_host_dev(bus);
166 - of_platform_default_populate(dev->of_node, NULL, dev);
169 + of_platform_default_populate(bus->dev->of_node, NULL, bus->dev);
171 /* Cores providing flash access go before SPROM init */
172 list_for_each_entry(core, &bus->cores, list) {
173 --- a/include/linux/bcma/bcma.h
174 +++ b/include/linux/bcma/bcma.h
175 @@ -332,6 +332,8 @@ extern int bcma_arch_register_fallback_s
176 struct ssb_sprom *out));
179 + struct device *dev;
184 @@ -339,14 +341,7 @@ struct bcma_bus {
186 enum bcma_hosttype hosttype;
187 bool host_is_pcie2; /* Used for BCMA_HOSTTYPE_PCI only */
189 - /* Pointer to the PCI bus (only for BCMA_HOSTTYPE_PCI) */
190 - struct pci_dev *host_pci;
191 - /* Pointer to the SDIO device (only for BCMA_HOSTTYPE_SDIO) */
192 - struct sdio_func *host_sdio;
193 - /* Pointer to platform device (only for BCMA_HOSTTYPE_SOC) */
194 - struct platform_device *host_pdev;
196 + struct pci_dev *host_pci; /* PCI bus pointer (BCMA_HOSTTYPE_PCI only) */
198 struct bcma_chipinfo chipinfo;