aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Westerberg <mika.westerberg@linux.intel.com>2013-01-07 05:44:32 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2013-01-08 05:59:08 -0500
commit0202775bc3a28f2436ea6ee13ef3eb0e8f237857 (patch)
tree3431707a3563d7c4909b9f5f3cc1d6ca6894c31b
parente1b0f0df6a08329ce2f123240a5218c3e5c43b74 (diff)
spi/pxa2xx-pci: switch to use pcim_* interfaces
Instead of open-coding all the error management in the driver we can take advantage of the pcim_* interfaces that release the resources automatically. We also use platform_device_register_full() to register the platform device because it allows us to create and register the platform device at one go, simplifying the error management. This a preparatory step for getting rid of pxa_ssp_request()/free() which we will do in the next patch. Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--drivers/spi/spi-pxa2xx-pci.c86
1 files changed, 30 insertions, 56 deletions
diff --git a/drivers/spi/spi-pxa2xx-pci.c b/drivers/spi/spi-pxa2xx-pci.c
index cf95587eefde..ece979e9c642 100644
--- a/drivers/spi/spi-pxa2xx-pci.c
+++ b/drivers/spi/spi-pxa2xx-pci.c
@@ -54,101 +54,75 @@ EXPORT_SYMBOL_GPL(pxa_ssp_free);
54static int ce4100_spi_probe(struct pci_dev *dev, 54static int ce4100_spi_probe(struct pci_dev *dev,
55 const struct pci_device_id *ent) 55 const struct pci_device_id *ent)
56{ 56{
57 struct platform_device_info pi;
57 int ret; 58 int ret;
58 resource_size_t phys_beg;
59 resource_size_t phys_len;
60 struct ce4100_info *spi_info; 59 struct ce4100_info *spi_info;
61 struct platform_device *pdev; 60 struct platform_device *pdev;
62 struct pxa2xx_spi_master spi_pdata; 61 struct pxa2xx_spi_master spi_pdata;
63 struct ssp_device *ssp; 62 struct ssp_device *ssp;
64 63
65 ret = pci_enable_device(dev); 64 ret = pcim_enable_device(dev);
66 if (ret) 65 if (ret)
67 return ret; 66 return ret;
68 67
69 phys_beg = pci_resource_start(dev, 0); 68 ret = pcim_iomap_regions(dev, 1 << 0, "PXA2xx SPI");
70 phys_len = pci_resource_len(dev, 0); 69 if (!ret)
71
72 if (!request_mem_region(phys_beg, phys_len,
73 "CE4100 SPI")) {
74 dev_err(&dev->dev, "Can't request register space.\n");
75 ret = -EBUSY;
76 return ret; 70 return ret;
77 }
78 71
79 pdev = platform_device_alloc("pxa2xx-spi", dev->devfn); 72 spi_info = devm_kzalloc(&dev->dev, sizeof(*spi_info), GFP_KERNEL);
80 spi_info = kzalloc(sizeof(*spi_info), GFP_KERNEL); 73 if (!spi_info)
81 if (!pdev || !spi_info ) { 74 return -ENOMEM;
82 ret = -ENOMEM; 75
83 goto err_nomem;
84 }
85 memset(&spi_pdata, 0, sizeof(spi_pdata)); 76 memset(&spi_pdata, 0, sizeof(spi_pdata));
86 spi_pdata.num_chipselect = dev->devfn; 77 spi_pdata.num_chipselect = dev->devfn;
87 78
88 ret = platform_device_add_data(pdev, &spi_pdata, sizeof(spi_pdata));
89 if (ret)
90 goto err_nomem;
91
92 pdev->dev.parent = &dev->dev;
93 pdev->dev.of_node = dev->dev.of_node;
94 ssp = &spi_info->ssp; 79 ssp = &spi_info->ssp;
95 ssp->phys_base = pci_resource_start(dev, 0); 80 ssp->phys_base = pci_resource_start(dev, 0);
96 ssp->mmio_base = ioremap(phys_beg, phys_len); 81 ssp->mmio_base = pcim_iomap_table(dev)[0];
97 if (!ssp->mmio_base) { 82 if (!ssp->mmio_base) {
98 dev_err(&pdev->dev, "failed to ioremap() registers\n"); 83 dev_err(&dev->dev, "failed to ioremap() registers\n");
99 ret = -EIO; 84 return -EIO;
100 goto err_nomem;
101 } 85 }
102 ssp->irq = dev->irq; 86 ssp->irq = dev->irq;
103 ssp->port_id = pdev->id; 87 ssp->port_id = dev->devfn;
104 ssp->type = PXA25x_SSP; 88 ssp->type = PXA25x_SSP;
105 89
106 mutex_lock(&ssp_lock); 90 mutex_lock(&ssp_lock);
107 list_add(&ssp->node, &ssp_list); 91 list_add(&ssp->node, &ssp_list);
108 mutex_unlock(&ssp_lock); 92 mutex_unlock(&ssp_lock);
109 93
110 pci_set_drvdata(dev, spi_info); 94 memset(&pi, 0, sizeof(pi));
95 pi.parent = &dev->dev;
96 pi.name = "pxa2xx-spi";
97 pi.id = ssp->port_id;
98 pi.data = &spi_pdata;
99 pi.size_data = sizeof(spi_pdata);
111 100
112 ret = platform_device_add(pdev); 101 pdev = platform_device_register_full(&pi);
113 if (ret) 102 if (!pdev) {
114 goto err_dev_add; 103 mutex_lock(&ssp_lock);
104 list_del(&ssp->node);
105 mutex_unlock(&ssp_lock);
115 106
116 return ret; 107 return -ENOMEM;
108 }
117 109
118err_dev_add: 110 spi_info->spi_pdev = pdev;
119 pci_set_drvdata(dev, NULL); 111 pci_set_drvdata(dev, spi_info);
120 mutex_lock(&ssp_lock);
121 list_del(&ssp->node);
122 mutex_unlock(&ssp_lock);
123 iounmap(ssp->mmio_base);
124 112
125err_nomem: 113 return 0;
126 release_mem_region(phys_beg, phys_len);
127 platform_device_put(pdev);
128 kfree(spi_info);
129 return ret;
130} 114}
131 115
132static void ce4100_spi_remove(struct pci_dev *dev) 116static void ce4100_spi_remove(struct pci_dev *dev)
133{ 117{
134 struct ce4100_info *spi_info; 118 struct ce4100_info *spi_info = pci_get_drvdata(dev);
135 struct ssp_device *ssp; 119 struct ssp_device *ssp = &spi_info->ssp;
136 120
137 spi_info = pci_get_drvdata(dev);
138 ssp = &spi_info->ssp;
139 platform_device_unregister(spi_info->spi_pdev); 121 platform_device_unregister(spi_info->spi_pdev);
140 122
141 iounmap(ssp->mmio_base);
142 release_mem_region(pci_resource_start(dev, 0),
143 pci_resource_len(dev, 0));
144
145 mutex_lock(&ssp_lock); 123 mutex_lock(&ssp_lock);
146 list_del(&ssp->node); 124 list_del(&ssp->node);
147 mutex_unlock(&ssp_lock); 125 mutex_unlock(&ssp_lock);
148
149 pci_set_drvdata(dev, NULL);
150 pci_disable_device(dev);
151 kfree(spi_info);
152} 126}
153 127
154static DEFINE_PCI_DEVICE_TABLE(ce4100_spi_devices) = { 128static DEFINE_PCI_DEVICE_TABLE(ce4100_spi_devices) = {