080-v5.1-0001-bcma-keep-a-direct-pointer-to-the-struct-device.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. Accessing struct device is pretty useful/common so having a direct
  9. pointer:
  10. 1) Simplifies some code
  11. 2) Makes bcma_bus_get_host_dev() unneeded
  12. 3) Allows further improvements like using dev_* printing helpers
  13. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  14. Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
  15. ---
  16. drivers/bcma/bcma_private.h | 1 -
  17. drivers/bcma/driver_gpio.c | 2 +-
  18. drivers/bcma/host_pci.c | 2 ++
  19. drivers/bcma/host_soc.c | 4 ++--
  20. drivers/bcma/main.c | 45 +++++++++----------------------------
  21. include/linux/bcma/bcma.h | 11 +++------
  22. 6 files changed, 18 insertions(+), 47 deletions(-)
  23. --- a/drivers/bcma/bcma_private.h
  24. +++ b/drivers/bcma/bcma_private.h
  25. @@ -33,7 +33,6 @@ int __init bcma_bus_early_register(struc
  26. int bcma_bus_suspend(struct bcma_bus *bus);
  27. int bcma_bus_resume(struct bcma_bus *bus);
  28. #endif
  29. -struct device *bcma_bus_get_host_dev(struct bcma_bus *bus);
  30. /* scan.c */
  31. void bcma_detect_chip(struct bcma_bus *bus);
  32. --- a/drivers/bcma/driver_gpio.c
  33. +++ b/drivers/bcma/driver_gpio.c
  34. @@ -183,7 +183,7 @@ int bcma_gpio_init(struct bcma_drv_cc *c
  35. chip->direction_input = bcma_gpio_direction_input;
  36. chip->direction_output = bcma_gpio_direction_output;
  37. chip->owner = THIS_MODULE;
  38. - chip->parent = bcma_bus_get_host_dev(bus);
  39. + chip->parent = bus->dev;
  40. #if IS_BUILTIN(CONFIG_OF)
  41. chip->of_node = cc->core->dev.of_node;
  42. #endif
  43. --- a/drivers/bcma/host_pci.c
  44. +++ b/drivers/bcma/host_pci.c
  45. @@ -196,6 +196,8 @@ static int bcma_host_pci_probe(struct pc
  46. goto err_pci_release_regions;
  47. }
  48. + bus->dev = &dev->dev;
  49. +
  50. /* Map MMIO */
  51. err = -ENOMEM;
  52. bus->mmio = pci_iomap(dev, 0, ~0UL);
  53. --- a/drivers/bcma/host_soc.c
  54. +++ b/drivers/bcma/host_soc.c
  55. @@ -179,7 +179,6 @@ int __init bcma_host_soc_register(struct
  56. /* Host specific */
  57. bus->hosttype = BCMA_HOSTTYPE_SOC;
  58. bus->ops = &bcma_host_soc_ops;
  59. - bus->host_pdev = NULL;
  60. /* Initialize struct, detect chip */
  61. bcma_init_bus(bus);
  62. @@ -213,6 +212,8 @@ static int bcma_host_soc_probe(struct pl
  63. if (!bus)
  64. return -ENOMEM;
  65. + bus->dev = dev;
  66. +
  67. /* Map MMIO */
  68. bus->mmio = of_iomap(np, 0);
  69. if (!bus->mmio)
  70. @@ -221,7 +222,6 @@ static int bcma_host_soc_probe(struct pl
  71. /* Host specific */
  72. bus->hosttype = BCMA_HOSTTYPE_SOC;
  73. bus->ops = &bcma_host_soc_ops;
  74. - bus->host_pdev = pdev;
  75. /* Initialize struct, detect chip */
  76. bcma_init_bus(bus);
  77. --- a/drivers/bcma/main.c
  78. +++ b/drivers/bcma/main.c
  79. @@ -223,8 +223,8 @@ unsigned int bcma_core_irq(struct bcma_d
  80. mips_irq = bcma_core_mips_irq(core);
  81. return mips_irq <= 4 ? mips_irq + 2 : 0;
  82. }
  83. - if (bus->host_pdev)
  84. - return bcma_of_get_irq(&bus->host_pdev->dev, core, num);
  85. + if (bus->dev)
  86. + return bcma_of_get_irq(bus->dev, core, num);
  87. return 0;
  88. case BCMA_HOSTTYPE_SDIO:
  89. return 0;
  90. @@ -240,18 +240,18 @@ void bcma_prepare_core(struct bcma_bus *
  91. core->dev.release = bcma_release_core_dev;
  92. core->dev.bus = &bcma_bus_type;
  93. dev_set_name(&core->dev, "bcma%d:%d", bus->num, core->core_index);
  94. - core->dev.parent = bcma_bus_get_host_dev(bus);
  95. - if (core->dev.parent)
  96. - bcma_of_fill_device(core->dev.parent, core);
  97. + core->dev.parent = bus->dev;
  98. + if (bus->dev)
  99. + bcma_of_fill_device(bus->dev, core);
  100. switch (bus->hosttype) {
  101. case BCMA_HOSTTYPE_PCI:
  102. - core->dma_dev = &bus->host_pci->dev;
  103. + core->dma_dev = bus->dev;
  104. core->irq = bus->host_pci->irq;
  105. break;
  106. case BCMA_HOSTTYPE_SOC:
  107. - if (IS_ENABLED(CONFIG_OF) && bus->host_pdev) {
  108. - core->dma_dev = &bus->host_pdev->dev;
  109. + if (IS_ENABLED(CONFIG_OF) && bus->dev) {
  110. + core->dma_dev = bus->dev;
  111. } else {
  112. core->dev.dma_mask = &core->dev.coherent_dma_mask;
  113. core->dma_dev = &core->dev;
  114. @@ -262,28 +262,6 @@ void bcma_prepare_core(struct bcma_bus *
  115. }
  116. }
  117. -struct device *bcma_bus_get_host_dev(struct bcma_bus *bus)
  118. -{
  119. - switch (bus->hosttype) {
  120. - case BCMA_HOSTTYPE_PCI:
  121. - if (bus->host_pci)
  122. - return &bus->host_pci->dev;
  123. - else
  124. - return NULL;
  125. - case BCMA_HOSTTYPE_SOC:
  126. - if (bus->host_pdev)
  127. - return &bus->host_pdev->dev;
  128. - else
  129. - return NULL;
  130. - case BCMA_HOSTTYPE_SDIO:
  131. - if (bus->host_sdio)
  132. - return &bus->host_sdio->dev;
  133. - else
  134. - return NULL;
  135. - }
  136. - return NULL;
  137. -}
  138. -
  139. void bcma_init_bus(struct bcma_bus *bus)
  140. {
  141. mutex_lock(&bcma_buses_mutex);
  142. @@ -402,7 +380,6 @@ int bcma_bus_register(struct bcma_bus *b
  143. {
  144. int err;
  145. struct bcma_device *core;
  146. - struct device *dev;
  147. /* Scan for devices (cores) */
  148. err = bcma_bus_scan(bus);
  149. @@ -425,10 +402,8 @@ int bcma_bus_register(struct bcma_bus *b
  150. bcma_core_pci_early_init(&bus->drv_pci[0]);
  151. }
  152. - dev = bcma_bus_get_host_dev(bus);
  153. - if (dev) {
  154. - of_platform_default_populate(dev->of_node, NULL, dev);
  155. - }
  156. + if (bus->dev)
  157. + of_platform_default_populate(bus->dev->of_node, NULL, bus->dev);
  158. /* Cores providing flash access go before SPROM init */
  159. list_for_each_entry(core, &bus->cores, list) {
  160. --- a/include/linux/bcma/bcma.h
  161. +++ b/include/linux/bcma/bcma.h
  162. @@ -332,6 +332,8 @@ extern int bcma_arch_register_fallback_s
  163. struct ssb_sprom *out));
  164. struct bcma_bus {
  165. + struct device *dev;
  166. +
  167. /* The MMIO area. */
  168. void __iomem *mmio;
  169. @@ -339,14 +341,7 @@ struct bcma_bus {
  170. enum bcma_hosttype hosttype;
  171. bool host_is_pcie2; /* Used for BCMA_HOSTTYPE_PCI only */
  172. - union {
  173. - /* Pointer to the PCI bus (only for BCMA_HOSTTYPE_PCI) */
  174. - struct pci_dev *host_pci;
  175. - /* Pointer to the SDIO device (only for BCMA_HOSTTYPE_SDIO) */
  176. - struct sdio_func *host_sdio;
  177. - /* Pointer to platform device (only for BCMA_HOSTTYPE_SOC) */
  178. - struct platform_device *host_pdev;
  179. - };
  180. + struct pci_dev *host_pci; /* PCI bus pointer (BCMA_HOSTTYPE_PCI only) */
  181. struct bcma_chipinfo chipinfo;