diff options
Diffstat (limited to 'drivers/spi/pxa2xx_spi_pci.c')
-rw-r--r-- | drivers/spi/pxa2xx_spi_pci.c | 61 |
1 files changed, 21 insertions, 40 deletions
diff --git a/drivers/spi/pxa2xx_spi_pci.c b/drivers/spi/pxa2xx_spi_pci.c index b6589bb3a6c3..378e504f89eb 100644 --- a/drivers/spi/pxa2xx_spi_pci.c +++ b/drivers/spi/pxa2xx_spi_pci.c | |||
@@ -7,10 +7,9 @@ | |||
7 | #include <linux/of_device.h> | 7 | #include <linux/of_device.h> |
8 | #include <linux/spi/pxa2xx_spi.h> | 8 | #include <linux/spi/pxa2xx_spi.h> |
9 | 9 | ||
10 | struct awesome_struct { | 10 | struct ce4100_info { |
11 | struct ssp_device ssp; | 11 | struct ssp_device ssp; |
12 | struct platform_device spi_pdev; | 12 | struct platform_device *spi_pdev; |
13 | struct pxa2xx_spi_master spi_pdata; | ||
14 | }; | 13 | }; |
15 | 14 | ||
16 | static DEFINE_MUTEX(ssp_lock); | 15 | static DEFINE_MUTEX(ssp_lock); |
@@ -51,23 +50,15 @@ void pxa_ssp_free(struct ssp_device *ssp) | |||
51 | } | 50 | } |
52 | EXPORT_SYMBOL_GPL(pxa_ssp_free); | 51 | EXPORT_SYMBOL_GPL(pxa_ssp_free); |
53 | 52 | ||
54 | static void plat_dev_release(struct device *dev) | ||
55 | { | ||
56 | struct awesome_struct *as = container_of(dev, | ||
57 | struct awesome_struct, spi_pdev.dev); | ||
58 | |||
59 | of_device_node_put(&as->spi_pdev.dev); | ||
60 | } | ||
61 | |||
62 | static int __devinit ce4100_spi_probe(struct pci_dev *dev, | 53 | static int __devinit ce4100_spi_probe(struct pci_dev *dev, |
63 | const struct pci_device_id *ent) | 54 | const struct pci_device_id *ent) |
64 | { | 55 | { |
65 | int ret; | 56 | int ret; |
66 | resource_size_t phys_beg; | 57 | resource_size_t phys_beg; |
67 | resource_size_t phys_len; | 58 | resource_size_t phys_len; |
68 | struct awesome_struct *spi_info; | 59 | struct ce4100_info *spi_info; |
69 | struct platform_device *pdev; | 60 | struct platform_device *pdev; |
70 | struct pxa2xx_spi_master *spi_pdata; | 61 | struct pxa2xx_spi_master spi_pdata; |
71 | struct ssp_device *ssp; | 62 | struct ssp_device *ssp; |
72 | 63 | ||
73 | ret = pci_enable_device(dev); | 64 | ret = pci_enable_device(dev); |
@@ -84,31 +75,28 @@ static int __devinit ce4100_spi_probe(struct pci_dev *dev, | |||
84 | return ret; | 75 | return ret; |
85 | } | 76 | } |
86 | 77 | ||
78 | pdev = platform_device_alloc("pxa2xx-spi", dev->devfn); | ||
87 | spi_info = kzalloc(sizeof(*spi_info), GFP_KERNEL); | 79 | spi_info = kzalloc(sizeof(*spi_info), GFP_KERNEL); |
88 | if (!spi_info) { | 80 | if (!pdev || !spi_info ) { |
89 | ret = -ENOMEM; | 81 | ret = -ENOMEM; |
90 | goto err_kz; | 82 | goto err_nomem; |
91 | } | 83 | } |
92 | ssp = &spi_info->ssp; | 84 | memset(&spi_pdata, 0, sizeof(spi_pdata)); |
93 | pdev = &spi_info->spi_pdev; | 85 | spi_pdata.num_chipselect = dev->devfn; |
94 | spi_pdata = &spi_info->spi_pdata; | ||
95 | 86 | ||
96 | pdev->name = "pxa2xx-spi"; | 87 | ret = platform_device_add_data(pdev, &spi_pdata, sizeof(spi_pdata)); |
97 | pdev->id = dev->devfn; | 88 | if (ret) |
98 | pdev->dev.parent = &dev->dev; | 89 | goto err_nomem; |
99 | pdev->dev.platform_data = &spi_info->spi_pdata; | ||
100 | 90 | ||
91 | pdev->dev.parent = &dev->dev; | ||
101 | pdev->dev.of_node = dev->dev.of_node; | 92 | pdev->dev.of_node = dev->dev.of_node; |
102 | pdev->dev.release = plat_dev_release; | 93 | ssp = &spi_info->ssp; |
103 | |||
104 | spi_pdata->num_chipselect = dev->devfn; | ||
105 | |||
106 | ssp->phys_base = pci_resource_start(dev, 0); | 94 | ssp->phys_base = pci_resource_start(dev, 0); |
107 | ssp->mmio_base = ioremap(phys_beg, phys_len); | 95 | ssp->mmio_base = ioremap(phys_beg, phys_len); |
108 | if (!ssp->mmio_base) { | 96 | if (!ssp->mmio_base) { |
109 | dev_err(&pdev->dev, "failed to ioremap() registers\n"); | 97 | dev_err(&pdev->dev, "failed to ioremap() registers\n"); |
110 | ret = -EIO; | 98 | ret = -EIO; |
111 | goto err_remap; | 99 | goto err_nomem; |
112 | } | 100 | } |
113 | ssp->irq = dev->irq; | 101 | ssp->irq = dev->irq; |
114 | ssp->port_id = pdev->id; | 102 | ssp->port_id = pdev->id; |
@@ -120,7 +108,7 @@ static int __devinit ce4100_spi_probe(struct pci_dev *dev, | |||
120 | 108 | ||
121 | pci_set_drvdata(dev, spi_info); | 109 | pci_set_drvdata(dev, spi_info); |
122 | 110 | ||
123 | ret = platform_device_register(pdev); | 111 | ret = platform_device_add(pdev); |
124 | if (ret) | 112 | if (ret) |
125 | goto err_dev_add; | 113 | goto err_dev_add; |
126 | 114 | ||
@@ -133,27 +121,21 @@ err_dev_add: | |||
133 | mutex_unlock(&ssp_lock); | 121 | mutex_unlock(&ssp_lock); |
134 | iounmap(ssp->mmio_base); | 122 | iounmap(ssp->mmio_base); |
135 | 123 | ||
136 | err_remap: | 124 | err_nomem: |
137 | kfree(spi_info); | ||
138 | |||
139 | err_kz: | ||
140 | release_mem_region(phys_beg, phys_len); | 125 | release_mem_region(phys_beg, phys_len); |
141 | 126 | platform_device_put(pdev); | |
127 | kfree(spi_info); | ||
142 | return ret; | 128 | return ret; |
143 | } | 129 | } |
144 | 130 | ||
145 | static void __devexit ce4100_spi_remove(struct pci_dev *dev) | 131 | static void __devexit ce4100_spi_remove(struct pci_dev *dev) |
146 | { | 132 | { |
147 | struct awesome_struct *spi_info; | 133 | struct ce4100_info *spi_info; |
148 | struct platform_device *pdev; | ||
149 | struct ssp_device *ssp; | 134 | struct ssp_device *ssp; |
150 | 135 | ||
151 | spi_info = pci_get_drvdata(dev); | 136 | spi_info = pci_get_drvdata(dev); |
152 | |||
153 | ssp = &spi_info->ssp; | 137 | ssp = &spi_info->ssp; |
154 | pdev = &spi_info->spi_pdev; | 138 | platform_device_unregister(spi_info->spi_pdev); |
155 | |||
156 | platform_device_unregister(pdev); | ||
157 | 139 | ||
158 | iounmap(ssp->mmio_base); | 140 | iounmap(ssp->mmio_base); |
159 | release_mem_region(pci_resource_start(dev, 0), | 141 | release_mem_region(pci_resource_start(dev, 0), |
@@ -169,7 +151,6 @@ static void __devexit ce4100_spi_remove(struct pci_dev *dev) | |||
169 | } | 151 | } |
170 | 152 | ||
171 | static struct pci_device_id ce4100_spi_devices[] __devinitdata = { | 153 | static struct pci_device_id ce4100_spi_devices[] __devinitdata = { |
172 | |||
173 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e6a) }, | 154 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e6a) }, |
174 | { }, | 155 | { }, |
175 | }; | 156 | }; |