cc32aee17b689e4097e1c7e85bdac9f1e2602e28
[openwrt/staging/neocturne.git] /
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
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Accessing struct device is pretty useful/common so having a direct
10 pointer:
11 1) Simplifies some code
12 2) Makes bcma_bus_get_host_dev() unneeded
13 3) Allows further improvements like using dev_* printing helpers
14
15 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
17 ---
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(-)
25
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);
31 #endif
32 -struct device *bcma_bus_get_host_dev(struct bcma_bus *bus);
33
34 /* scan.c */
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;
46 #endif
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;
51 }
52
53 + bus->dev = &dev->dev;
54 +
55 /* Map MMIO */
56 err = -ENOMEM;
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
61 /* Host specific */
62 bus->hosttype = BCMA_HOSTTYPE_SOC;
63 bus->ops = &bcma_host_soc_ops;
64 - bus->host_pdev = NULL;
65
66 /* Initialize struct, detect chip */
67 bcma_init_bus(bus);
68 @@ -213,6 +212,8 @@ static int bcma_host_soc_probe(struct pl
69 if (!bus)
70 return -ENOMEM;
71
72 + bus->dev = dev;
73 +
74 /* Map MMIO */
75 bus->mmio = of_iomap(np, 0);
76 if (!bus->mmio)
77 @@ -221,7 +222,6 @@ static int bcma_host_soc_probe(struct pl
78 /* Host specific */
79 bus->hosttype = BCMA_HOSTTYPE_SOC;
80 bus->ops = &bcma_host_soc_ops;
81 - bus->host_pdev = pdev;
82
83 /* Initialize struct, detect chip */
84 bcma_init_bus(bus);
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;
90 }
91 - if (bus->host_pdev)
92 - return bcma_of_get_irq(&bus->host_pdev->dev, core, num);
93 + if (bus->dev)
94 + return bcma_of_get_irq(bus->dev, core, num);
95 return 0;
96 case BCMA_HOSTTYPE_SDIO:
97 return 0;
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;
106 + if (bus->dev)
107 + bcma_of_fill_device(bus->dev, core);
108
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;
114 break;
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;
120 } else {
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 *
124 }
125 }
126
127 -struct device *bcma_bus_get_host_dev(struct bcma_bus *bus)
128 -{
129 - switch (bus->hosttype) {
130 - case BCMA_HOSTTYPE_PCI:
131 - if (bus->host_pci)
132 - return &bus->host_pci->dev;
133 - else
134 - return NULL;
135 - case BCMA_HOSTTYPE_SOC:
136 - if (bus->host_pdev)
137 - return &bus->host_pdev->dev;
138 - else
139 - return NULL;
140 - case BCMA_HOSTTYPE_SDIO:
141 - if (bus->host_sdio)
142 - return &bus->host_sdio->dev;
143 - else
144 - return NULL;
145 - }
146 - return NULL;
147 -}
148 -
149 void bcma_init_bus(struct bcma_bus *bus)
150 {
151 mutex_lock(&bcma_buses_mutex);
152 @@ -402,7 +380,6 @@ int bcma_bus_register(struct bcma_bus *b
153 {
154 int err;
155 struct bcma_device *core;
156 - struct device *dev;
157
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]);
162 }
163
164 - dev = bcma_bus_get_host_dev(bus);
165 - if (dev) {
166 - of_platform_default_populate(dev->of_node, NULL, dev);
167 - }
168 + if (bus->dev)
169 + of_platform_default_populate(bus->dev->of_node, NULL, bus->dev);
170
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));
177
178 struct bcma_bus {
179 + struct device *dev;
180 +
181 /* The MMIO area. */
182 void __iomem *mmio;
183
184 @@ -339,14 +341,7 @@ struct bcma_bus {
185
186 enum bcma_hosttype hosttype;
187 bool host_is_pcie2; /* Used for BCMA_HOSTTYPE_PCI only */
188 - union {
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;
195 - };
196 + struct pci_dev *host_pci; /* PCI bus pointer (BCMA_HOSTTYPE_PCI only) */
197
198 struct bcma_chipinfo chipinfo;
199