Skip to content

Commit b50a1e1

Browse files
hkallweitbroonie
authored andcommitted
spi: intel: Improve resource mapping
Let's use the pci/platform-specialized functions for mapping a resource, and pass the mapped address to intel_spi_probe. Benefits are: - No separate call needed for getting the resource, and no access to struct pci_dev internals (pdev->resource[]). - More user-friendly output in /proc/iomem. In my case: before 80704000-80704fff : 0000:00:1f.5 80704000-80704fff : 0000:00:1f.5 0000:00:1f.5 after 80704000-80704fff : 0000:00:1f.5 80704000-80704fff : spi_intel_pci Signed-off-by: Heiner Kallweit <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 296e8d2 commit b50a1e1

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

drivers/spi/spi-intel-pci.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static int intel_spi_pci_probe(struct pci_dev *pdev,
4444
const struct pci_device_id *id)
4545
{
4646
struct intel_spi_boardinfo *info;
47+
void __iomem *base;
4748
int ret;
4849

4950
ret = pcim_enable_device(pdev);
@@ -56,7 +57,12 @@ static int intel_spi_pci_probe(struct pci_dev *pdev,
5657
return -ENOMEM;
5758

5859
info->data = pdev;
59-
return intel_spi_probe(&pdev->dev, &pdev->resource[0], info);
60+
61+
base = pcim_iomap_region(pdev, 0, KBUILD_MODNAME);
62+
if (IS_ERR(base))
63+
return PTR_ERR(base);
64+
65+
return intel_spi_probe(&pdev->dev, base, info);
6066
}
6167

6268
static const struct pci_device_id intel_spi_pci_ids[] = {

drivers/spi/spi-intel-platform.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414
static int intel_spi_platform_probe(struct platform_device *pdev)
1515
{
1616
struct intel_spi_boardinfo *info;
17-
struct resource *mem;
17+
void __iomem *base;
1818

1919
info = dev_get_platdata(&pdev->dev);
2020
if (!info)
2121
return -EINVAL;
2222

23-
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
24-
return intel_spi_probe(&pdev->dev, mem, info);
23+
base = devm_platform_ioremap_resource(pdev, 0);
24+
if (IS_ERR(base))
25+
return PTR_ERR(base);
26+
27+
return intel_spi_probe(&pdev->dev, base, info);
2528
}
2629

2730
static struct platform_driver intel_spi_platform_driver = {

drivers/spi/spi-intel.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,13 +1467,13 @@ EXPORT_SYMBOL_GPL(intel_spi_groups);
14671467
/**
14681468
* intel_spi_probe() - Probe the Intel SPI flash controller
14691469
* @dev: Pointer to the parent device
1470-
* @mem: MMIO resource
1470+
* @base: iomapped MMIO resource
14711471
* @info: Platform specific information
14721472
*
14731473
* Probes Intel SPI flash controller and creates the flash chip device.
14741474
* Returns %0 on success and negative errno in case of failure.
14751475
*/
1476-
int intel_spi_probe(struct device *dev, struct resource *mem,
1476+
int intel_spi_probe(struct device *dev, void __iomem *base,
14771477
const struct intel_spi_boardinfo *info)
14781478
{
14791479
struct spi_controller *host;
@@ -1488,10 +1488,7 @@ int intel_spi_probe(struct device *dev, struct resource *mem,
14881488

14891489
ispi = spi_controller_get_devdata(host);
14901490

1491-
ispi->base = devm_ioremap_resource(dev, mem);
1492-
if (IS_ERR(ispi->base))
1493-
return PTR_ERR(ispi->base);
1494-
1491+
ispi->base = base;
14951492
ispi->dev = dev;
14961493
ispi->host = host;
14971494
ispi->info = info;

drivers/spi/spi-intel.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111

1212
#include <linux/platform_data/x86/spi-intel.h>
1313

14-
struct resource;
15-
1614
extern const struct attribute_group *intel_spi_groups[];
1715

18-
int intel_spi_probe(struct device *dev, struct resource *mem,
16+
int intel_spi_probe(struct device *dev, void __iomem *base,
1917
const struct intel_spi_boardinfo *info);
2018

2119
#endif /* SPI_INTEL_H */

0 commit comments

Comments
 (0)