aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/spi/spi-dw-mmio.c70
-rw-r--r--drivers/spi/spi-dw-pci.c40
-rw-r--r--drivers/spi/spi-dw.c20
-rw-r--r--drivers/spi/spi-dw.h4
4 files changed, 37 insertions, 97 deletions
diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index 168c620947f4..569adf877b16 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -30,14 +30,13 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
30{ 30{
31 struct dw_spi_mmio *dwsmmio; 31 struct dw_spi_mmio *dwsmmio;
32 struct dw_spi *dws; 32 struct dw_spi *dws;
33 struct resource *mem, *ioarea; 33 struct resource *mem;
34 int ret; 34 int ret;
35 35
36 dwsmmio = kzalloc(sizeof(struct dw_spi_mmio), GFP_KERNEL); 36 dwsmmio = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_mmio),
37 if (!dwsmmio) { 37 GFP_KERNEL);
38 ret = -ENOMEM; 38 if (!dwsmmio)
39 goto err_end; 39 return -ENOMEM;
40 }
41 40
42 dws = &dwsmmio->dws; 41 dws = &dwsmmio->dws;
43 42
@@ -45,80 +44,51 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
45 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 44 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
46 if (!mem) { 45 if (!mem) {
47 dev_err(&pdev->dev, "no mem resource?\n"); 46 dev_err(&pdev->dev, "no mem resource?\n");
48 ret = -EINVAL; 47 return -EINVAL;
49 goto err_kfree;
50 } 48 }
51 49
52 ioarea = request_mem_region(mem->start, resource_size(mem), 50 dws->regs = devm_ioremap_resource(&pdev->dev, mem);
53 pdev->name); 51 if (IS_ERR(dws->regs)) {
54 if (!ioarea) { 52 dev_err(&pdev->dev, "SPI region map failed\n");
55 dev_err(&pdev->dev, "SPI region already claimed\n"); 53 return PTR_ERR(dws->regs);
56 ret = -EBUSY;
57 goto err_kfree;
58 }
59
60 dws->regs = ioremap_nocache(mem->start, resource_size(mem));
61 if (!dws->regs) {
62 dev_err(&pdev->dev, "SPI region already mapped\n");
63 ret = -ENOMEM;
64 goto err_release_reg;
65 } 54 }
66 55
67 dws->irq = platform_get_irq(pdev, 0); 56 dws->irq = platform_get_irq(pdev, 0);
68 if (dws->irq < 0) { 57 if (dws->irq < 0) {
69 dev_err(&pdev->dev, "no irq resource?\n"); 58 dev_err(&pdev->dev, "no irq resource?\n");
70 ret = dws->irq; /* -ENXIO */ 59 return dws->irq; /* -ENXIO */
71 goto err_unmap;
72 } 60 }
73 61
74 dwsmmio->clk = clk_get(&pdev->dev, NULL); 62 dwsmmio->clk = devm_clk_get(&pdev->dev, NULL);
75 if (IS_ERR(dwsmmio->clk)) { 63 if (IS_ERR(dwsmmio->clk))
76 ret = PTR_ERR(dwsmmio->clk); 64 return PTR_ERR(dwsmmio->clk);
77 goto err_unmap; 65 ret = clk_enable(dwsmmio->clk);
78 } 66 if (ret)
79 clk_enable(dwsmmio->clk); 67 return ret;
80 68
81 dws->parent_dev = &pdev->dev;
82 dws->bus_num = 0; 69 dws->bus_num = 0;
83 dws->num_cs = 4; 70 dws->num_cs = 4;
84 dws->max_freq = clk_get_rate(dwsmmio->clk); 71 dws->max_freq = clk_get_rate(dwsmmio->clk);
85 72
86 ret = dw_spi_add_host(dws); 73 ret = dw_spi_add_host(&pdev->dev, dws);
87 if (ret) 74 if (ret)
88 goto err_clk; 75 goto out;
89 76
90 platform_set_drvdata(pdev, dwsmmio); 77 platform_set_drvdata(pdev, dwsmmio);
91 return 0; 78 return 0;
92 79
93err_clk: 80out:
94 clk_disable(dwsmmio->clk); 81 clk_disable(dwsmmio->clk);
95 clk_put(dwsmmio->clk);
96 dwsmmio->clk = NULL;
97err_unmap:
98 iounmap(dws->regs);
99err_release_reg:
100 release_mem_region(mem->start, resource_size(mem));
101err_kfree:
102 kfree(dwsmmio);
103err_end:
104 return ret; 82 return ret;
105} 83}
106 84
107static int dw_spi_mmio_remove(struct platform_device *pdev) 85static int dw_spi_mmio_remove(struct platform_device *pdev)
108{ 86{
109 struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev); 87 struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev);
110 struct resource *mem;
111 88
112 clk_disable(dwsmmio->clk); 89 clk_disable(dwsmmio->clk);
113 clk_put(dwsmmio->clk);
114 dwsmmio->clk = NULL;
115
116 dw_spi_remove_host(&dwsmmio->dws); 90 dw_spi_remove_host(&dwsmmio->dws);
117 iounmap(dwsmmio->dws.regs);
118 kfree(dwsmmio);
119 91
120 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
121 release_mem_region(mem->start, resource_size(mem));
122 return 0; 92 return 0;
123} 93}
124 94
diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
index 66fa9955ea14..760dc0017a33 100644
--- a/drivers/spi/spi-dw-pci.c
+++ b/drivers/spi/spi-dw-pci.c
@@ -43,35 +43,24 @@ static int spi_pci_probe(struct pci_dev *pdev,
43 dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n", 43 dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n",
44 pdev->vendor, pdev->device); 44 pdev->vendor, pdev->device);
45 45
46 ret = pci_enable_device(pdev); 46 ret = pcim_enable_device(pdev);
47 if (ret) 47 if (ret)
48 return ret; 48 return ret;
49 49
50 dwpci = kzalloc(sizeof(struct dw_spi_pci), GFP_KERNEL); 50 dwpci = devm_kzalloc(&pdev-dev, sizeof(struct dw_spi_pci), GFP_KERNEL);
51 if (!dwpci) { 51 if (!dwpci)
52 ret = -ENOMEM; 52 return -ENOMEM;
53 goto err_disable;
54 }
55 53
56 dwpci->pdev = pdev; 54 dwpci->pdev = pdev;
57 dws = &dwpci->dws; 55 dws = &dwpci->dws;
58 56
59 /* Get basic io resource and map it */ 57 /* Get basic io resource and map it */
60 dws->paddr = pci_resource_start(pdev, pci_bar); 58 dws->paddr = pci_resource_start(pdev, pci_bar);
61 dws->iolen = pci_resource_len(pdev, pci_bar);
62 59
63 ret = pci_request_region(pdev, pci_bar, dev_name(&pdev->dev)); 60 ret = pcim_iomap_regions(pdev, 1, dev_name(&pdev->dev));
64 if (ret) 61 if (ret)
65 goto err_kfree; 62 return ret;
66
67 dws->regs = ioremap_nocache((unsigned long)dws->paddr,
68 pci_resource_len(pdev, pci_bar));
69 if (!dws->regs) {
70 ret = -ENOMEM;
71 goto err_release_reg;
72 }
73 63
74 dws->parent_dev = &pdev->dev;
75 dws->bus_num = 0; 64 dws->bus_num = 0;
76 dws->num_cs = 4; 65 dws->num_cs = 4;
77 dws->irq = pdev->irq; 66 dws->irq = pdev->irq;
@@ -83,26 +72,17 @@ static int spi_pci_probe(struct pci_dev *pdev,
83 if (pdev->device == 0x0800) { 72 if (pdev->device == 0x0800) {
84 ret = dw_spi_mid_init(dws); 73 ret = dw_spi_mid_init(dws);
85 if (ret) 74 if (ret)
86 goto err_unmap; 75 return ret;
87 } 76 }
88 77
89 ret = dw_spi_add_host(dws); 78 ret = dw_spi_add_host(&pdev->dev, dws);
90 if (ret) 79 if (ret)
91 goto err_unmap; 80 return ret;
92 81
93 /* PCI hook and SPI hook use the same drv data */ 82 /* PCI hook and SPI hook use the same drv data */
94 pci_set_drvdata(pdev, dwpci); 83 pci_set_drvdata(pdev, dwpci);
95 return 0;
96 84
97err_unmap: 85 return 0;
98 iounmap(dws->regs);
99err_release_reg:
100 pci_release_region(pdev, pci_bar);
101err_kfree:
102 kfree(dwpci);
103err_disable:
104 pci_disable_device(pdev);
105 return ret;
106} 86}
107 87
108static void spi_pci_remove(struct pci_dev *pdev) 88static void spi_pci_remove(struct pci_dev *pdev)
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index abf4fd5a2a25..48ec161d6eed 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -775,18 +775,16 @@ static void spi_hw_init(struct dw_spi *dws)
775 } 775 }
776} 776}
777 777
778int dw_spi_add_host(struct dw_spi *dws) 778int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
779{ 779{
780 struct spi_master *master; 780 struct spi_master *master;
781 int ret; 781 int ret;
782 782
783 BUG_ON(dws == NULL); 783 BUG_ON(dws == NULL);
784 784
785 master = spi_alloc_master(dws->parent_dev, 0); 785 master = spi_alloc_master(dev, 0);
786 if (!master) { 786 if (!master)
787 ret = -ENOMEM; 787 return -ENOMEM;
788 goto exit;
789 }
790 788
791 dws->master = master; 789 dws->master = master;
792 dws->type = SSI_MOTO_SPI; 790 dws->type = SSI_MOTO_SPI;
@@ -796,7 +794,7 @@ int dw_spi_add_host(struct dw_spi *dws)
796 snprintf(dws->name, sizeof(dws->name), "dw_spi%d", 794 snprintf(dws->name, sizeof(dws->name), "dw_spi%d",
797 dws->bus_num); 795 dws->bus_num);
798 796
799 ret = request_irq(dws->irq, dw_spi_irq, IRQF_SHARED, 797 ret = devm_request_irq(dev, dws->irq, dw_spi_irq, IRQF_SHARED,
800 dws->name, dws); 798 dws->name, dws);
801 if (ret < 0) { 799 if (ret < 0) {
802 dev_err(&master->dev, "can not get IRQ\n"); 800 dev_err(&master->dev, "can not get IRQ\n");
@@ -835,7 +833,7 @@ int dw_spi_add_host(struct dw_spi *dws)
835 } 833 }
836 834
837 spi_master_set_devdata(master, dws); 835 spi_master_set_devdata(master, dws);
838 ret = spi_register_master(master); 836 ret = devm_spi_register_master(dev, master);
839 if (ret) { 837 if (ret) {
840 dev_err(&master->dev, "problem registering spi master\n"); 838 dev_err(&master->dev, "problem registering spi master\n");
841 goto err_queue_alloc; 839 goto err_queue_alloc;
@@ -850,10 +848,8 @@ err_queue_alloc:
850 dws->dma_ops->dma_exit(dws); 848 dws->dma_ops->dma_exit(dws);
851err_diable_hw: 849err_diable_hw:
852 spi_enable_chip(dws, 0); 850 spi_enable_chip(dws, 0);
853 free_irq(dws->irq, dws);
854err_free_master: 851err_free_master:
855 spi_master_put(master); 852 spi_master_put(master);
856exit:
857 return ret; 853 return ret;
858} 854}
859EXPORT_SYMBOL_GPL(dw_spi_add_host); 855EXPORT_SYMBOL_GPL(dw_spi_add_host);
@@ -877,10 +873,6 @@ void dw_spi_remove_host(struct dw_spi *dws)
877 spi_enable_chip(dws, 0); 873 spi_enable_chip(dws, 0);
878 /* Disable clk */ 874 /* Disable clk */
879 spi_set_clk(dws, 0); 875 spi_set_clk(dws, 0);
880 free_irq(dws->irq, dws);
881
882 /* Disconnect from the SPI framework */
883 spi_unregister_master(dws->master);
884} 876}
885EXPORT_SYMBOL_GPL(dw_spi_remove_host); 877EXPORT_SYMBOL_GPL(dw_spi_remove_host);
886 878
diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h
index 5a5cd02ddb13..587643dae11e 100644
--- a/drivers/spi/spi-dw.h
+++ b/drivers/spi/spi-dw.h
@@ -92,13 +92,11 @@ struct dw_spi_dma_ops {
92struct dw_spi { 92struct dw_spi {
93 struct spi_master *master; 93 struct spi_master *master;
94 struct spi_device *cur_dev; 94 struct spi_device *cur_dev;
95 struct device *parent_dev;
96 enum dw_ssi_type type; 95 enum dw_ssi_type type;
97 char name[16]; 96 char name[16];
98 97
99 void __iomem *regs; 98 void __iomem *regs;
100 unsigned long paddr; 99 unsigned long paddr;
101 u32 iolen;
102 int irq; 100 int irq;
103 u32 fifo_len; /* depth of the FIFO buffer */ 101 u32 fifo_len; /* depth of the FIFO buffer */
104 u32 max_freq; /* max bus freq supported */ 102 u32 max_freq; /* max bus freq supported */
@@ -230,7 +228,7 @@ struct dw_spi_chip {
230 void (*cs_control)(u32 command); 228 void (*cs_control)(u32 command);
231}; 229};
232 230
233extern int dw_spi_add_host(struct dw_spi *dws); 231extern int dw_spi_add_host(struct device *dev, struct dw_spi *dws);
234extern void dw_spi_remove_host(struct dw_spi *dws); 232extern void dw_spi_remove_host(struct dw_spi *dws);
235extern int dw_spi_suspend_host(struct dw_spi *dws); 233extern int dw_spi_suspend_host(struct dw_spi *dws);
236extern int dw_spi_resume_host(struct dw_spi *dws); 234extern int dw_spi_resume_host(struct dw_spi *dws);