aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/powerpc/fsl/mpc5121-psc.txt24
-rw-r--r--Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.txt2
-rw-r--r--Documentation/devicetree/bindings/spi/spi-img-spfi.txt1
-rw-r--r--arch/powerpc/include/asm/mpc52xx_psc.h5
-rw-r--r--drivers/spi/spi-dw-mmio.c3
-rw-r--r--drivers/spi/spi-dw.c4
-rw-r--r--drivers/spi/spi-dw.h35
-rw-r--r--drivers/spi/spi-fsl-espi.c89
-rw-r--r--drivers/spi/spi-fsl-lib.c19
-rw-r--r--drivers/spi/spi-fsl-lib.h3
-rw-r--r--drivers/spi/spi-fsl-spi.c43
-rw-r--r--drivers/spi/spi-img-spfi.c14
-rw-r--r--drivers/spi/spi-mpc512x-psc.c70
13 files changed, 198 insertions, 114 deletions
diff --git a/Documentation/devicetree/bindings/powerpc/fsl/mpc5121-psc.txt b/Documentation/devicetree/bindings/powerpc/fsl/mpc5121-psc.txt
index 8832e8798912..647817527c88 100644
--- a/Documentation/devicetree/bindings/powerpc/fsl/mpc5121-psc.txt
+++ b/Documentation/devicetree/bindings/powerpc/fsl/mpc5121-psc.txt
@@ -6,14 +6,14 @@ PSC in UART mode
6For PSC in UART mode the needed PSC serial devices 6For PSC in UART mode the needed PSC serial devices
7are specified by fsl,mpc5121-psc-uart nodes in the 7are specified by fsl,mpc5121-psc-uart nodes in the
8fsl,mpc5121-immr SoC node. Additionally the PSC FIFO 8fsl,mpc5121-immr SoC node. Additionally the PSC FIFO
9Controller node fsl,mpc5121-psc-fifo is requered there: 9Controller node fsl,mpc5121-psc-fifo is required there:
10 10
11fsl,mpc5121-psc-uart nodes 11fsl,mpc512x-psc-uart nodes
12-------------------------- 12--------------------------
13 13
14Required properties : 14Required properties :
15 - compatible : Should contain "fsl,mpc5121-psc-uart" and "fsl,mpc5121-psc" 15 - compatible : Should contain "fsl,<soc>-psc-uart" and "fsl,<soc>-psc"
16 - cell-index : Index of the PSC in hardware 16 Supported <soc>s: mpc5121, mpc5125
17 - reg : Offset and length of the register set for the PSC device 17 - reg : Offset and length of the register set for the PSC device
18 - interrupts : <a b> where a is the interrupt number of the 18 - interrupts : <a b> where a is the interrupt number of the
19 PSC FIFO Controller and b is a field that represents an 19 PSC FIFO Controller and b is a field that represents an
@@ -25,12 +25,21 @@ Recommended properties :
25 - fsl,rx-fifo-size : the size of the RX fifo slice (a multiple of 4) 25 - fsl,rx-fifo-size : the size of the RX fifo slice (a multiple of 4)
26 - fsl,tx-fifo-size : the size of the TX fifo slice (a multiple of 4) 26 - fsl,tx-fifo-size : the size of the TX fifo slice (a multiple of 4)
27 27
28PSC in SPI mode
29---------------
28 30
29fsl,mpc5121-psc-fifo node 31Similar to the UART mode a PSC can be operated in SPI mode. The compatible used
32for that is fsl,mpc5121-psc-spi. It requires a fsl,mpc5121-psc-fifo as well.
33The required and recommended properties are identical to the
34fsl,mpc5121-psc-uart nodes, just use spi instead of uart in the compatible
35string.
36
37fsl,mpc512x-psc-fifo node
30------------------------- 38-------------------------
31 39
32Required properties : 40Required properties :
33 - compatible : Should be "fsl,mpc5121-psc-fifo" 41 - compatible : Should be "fsl,<soc>-psc-fifo"
42 Supported <soc>s: mpc5121, mpc5125
34 - reg : Offset and length of the register set for the PSC 43 - reg : Offset and length of the register set for the PSC
35 FIFO Controller 44 FIFO Controller
36 - interrupts : <a b> where a is the interrupt number of the 45 - interrupts : <a b> where a is the interrupt number of the
@@ -39,6 +48,9 @@ Required properties :
39 - interrupt-parent : the phandle for the interrupt controller that 48 - interrupt-parent : the phandle for the interrupt controller that
40 services interrupts for this device. 49 services interrupts for this device.
41 50
51Recommended properties :
52 - clocks : specifies the clock needed to operate the fifo controller
53 - clock-names : name(s) for the clock(s) listed in clocks
42 54
43Example for a board using PSC0 and PSC1 devices in serial mode: 55Example for a board using PSC0 and PSC1 devices in serial mode:
44 56
diff --git a/Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.txt b/Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.txt
index bd99193e87b9..204b311e0400 100644
--- a/Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.txt
+++ b/Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.txt
@@ -10,6 +10,8 @@ Required properties:
10Optional properties: 10Optional properties:
11- cs-gpios : Specifies the gpio pis to be used for chipselects. 11- cs-gpios : Specifies the gpio pis to be used for chipselects.
12- num-cs : The number of chipselects. If omitted, this will default to 4. 12- num-cs : The number of chipselects. If omitted, this will default to 4.
13- reg-io-width : The I/O register width (in bytes) implemented by this
14 device. Supported values are 2 or 4 (the default).
13 15
14Child nodes as per the generic SPI binding. 16Child nodes as per the generic SPI binding.
15 17
diff --git a/Documentation/devicetree/bindings/spi/spi-img-spfi.txt b/Documentation/devicetree/bindings/spi/spi-img-spfi.txt
index e02fbf18c82c..494db6012d02 100644
--- a/Documentation/devicetree/bindings/spi/spi-img-spfi.txt
+++ b/Documentation/devicetree/bindings/spi/spi-img-spfi.txt
@@ -21,6 +21,7 @@ Required properties:
21Optional properties: 21Optional properties:
22- img,supports-quad-mode: Should be set if the interface supports quad mode 22- img,supports-quad-mode: Should be set if the interface supports quad mode
23 SPI transfers. 23 SPI transfers.
24- spfi-max-frequency: Maximum speed supported by the spfi block.
24 25
25Example: 26Example:
26 27
diff --git a/arch/powerpc/include/asm/mpc52xx_psc.h b/arch/powerpc/include/asm/mpc52xx_psc.h
index d0ece257d310..04c7e8fc24c2 100644
--- a/arch/powerpc/include/asm/mpc52xx_psc.h
+++ b/arch/powerpc/include/asm/mpc52xx_psc.h
@@ -150,7 +150,10 @@
150 150
151/* Structure of the hardware registers */ 151/* Structure of the hardware registers */
152struct mpc52xx_psc { 152struct mpc52xx_psc {
153 u8 mode; /* PSC + 0x00 */ 153 union {
154 u8 mode; /* PSC + 0x00 */
155 u8 mr2;
156 };
154 u8 reserved0[3]; 157 u8 reserved0[3];
155 union { /* PSC + 0x04 */ 158 union { /* PSC + 0x04 */
156 u16 status; 159 u16 status;
diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index eb03e1215195..7edede6e024b 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -74,6 +74,9 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
74 74
75 dws->max_freq = clk_get_rate(dwsmmio->clk); 75 dws->max_freq = clk_get_rate(dwsmmio->clk);
76 76
77 of_property_read_u32(pdev->dev.of_node, "reg-io-width",
78 &dws->reg_io_width);
79
77 num_cs = 4; 80 num_cs = 4;
78 81
79 if (pdev->dev.of_node) 82 if (pdev->dev.of_node)
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index 8d67d03c71eb..4fbfcdc5cb24 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -194,7 +194,7 @@ static void dw_writer(struct dw_spi *dws)
194 else 194 else
195 txw = *(u16 *)(dws->tx); 195 txw = *(u16 *)(dws->tx);
196 } 196 }
197 dw_writel(dws, DW_SPI_DR, txw); 197 dw_write_io_reg(dws, DW_SPI_DR, txw);
198 dws->tx += dws->n_bytes; 198 dws->tx += dws->n_bytes;
199 } 199 }
200} 200}
@@ -205,7 +205,7 @@ static void dw_reader(struct dw_spi *dws)
205 u16 rxw; 205 u16 rxw;
206 206
207 while (max--) { 207 while (max--) {
208 rxw = dw_readl(dws, DW_SPI_DR); 208 rxw = dw_read_io_reg(dws, DW_SPI_DR);
209 /* Care rx only if the transfer's original "rx" is not null */ 209 /* Care rx only if the transfer's original "rx" is not null */
210 if (dws->rx_end - dws->len) { 210 if (dws->rx_end - dws->len) {
211 if (dws->n_bytes == 1) 211 if (dws->n_bytes == 1)
diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h
index 6c91391c1a4f..b75ed327d5a2 100644
--- a/drivers/spi/spi-dw.h
+++ b/drivers/spi/spi-dw.h
@@ -109,6 +109,7 @@ struct dw_spi {
109 u32 fifo_len; /* depth of the FIFO buffer */ 109 u32 fifo_len; /* depth of the FIFO buffer */
110 u32 max_freq; /* max bus freq supported */ 110 u32 max_freq; /* max bus freq supported */
111 111
112 u32 reg_io_width; /* DR I/O width in bytes */
112 u16 bus_num; 113 u16 bus_num;
113 u16 num_cs; /* supported slave numbers */ 114 u16 num_cs; /* supported slave numbers */
114 115
@@ -145,11 +146,45 @@ static inline u32 dw_readl(struct dw_spi *dws, u32 offset)
145 return __raw_readl(dws->regs + offset); 146 return __raw_readl(dws->regs + offset);
146} 147}
147 148
149static inline u16 dw_readw(struct dw_spi *dws, u32 offset)
150{
151 return __raw_readw(dws->regs + offset);
152}
153
148static inline void dw_writel(struct dw_spi *dws, u32 offset, u32 val) 154static inline void dw_writel(struct dw_spi *dws, u32 offset, u32 val)
149{ 155{
150 __raw_writel(val, dws->regs + offset); 156 __raw_writel(val, dws->regs + offset);
151} 157}
152 158
159static inline void dw_writew(struct dw_spi *dws, u32 offset, u16 val)
160{
161 __raw_writew(val, dws->regs + offset);
162}
163
164static inline u32 dw_read_io_reg(struct dw_spi *dws, u32 offset)
165{
166 switch (dws->reg_io_width) {
167 case 2:
168 return dw_readw(dws, offset);
169 case 4:
170 default:
171 return dw_readl(dws, offset);
172 }
173}
174
175static inline void dw_write_io_reg(struct dw_spi *dws, u32 offset, u32 val)
176{
177 switch (dws->reg_io_width) {
178 case 2:
179 dw_writew(dws, offset, val);
180 break;
181 case 4:
182 default:
183 dw_writel(dws, offset, val);
184 break;
185 }
186}
187
153static inline void spi_enable_chip(struct dw_spi *dws, int enable) 188static inline void spi_enable_chip(struct dw_spi *dws, int enable)
154{ 189{
155 dw_writel(dws, DW_SPI_SSIENR, (enable ? 1 : 0)); 190 dw_writel(dws, DW_SPI_SSIENR, (enable ? 1 : 0));
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index d3f05a0525a4..c27124a5ec8e 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -21,6 +21,7 @@
21#include <linux/of_platform.h> 21#include <linux/of_platform.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/spi/spi.h> 23#include <linux/spi/spi.h>
24#include <linux/pm_runtime.h>
24#include <sysdev/fsl_soc.h> 25#include <sysdev/fsl_soc.h>
25 26
26#include "spi-fsl-lib.h" 27#include "spi-fsl-lib.h"
@@ -85,6 +86,8 @@ struct fsl_espi_transfer {
85#define SPCOM_TRANLEN(x) ((x) << 0) 86#define SPCOM_TRANLEN(x) ((x) << 0)
86#define SPCOM_TRANLEN_MAX 0xFFFF /* Max transaction length */ 87#define SPCOM_TRANLEN_MAX 0xFFFF /* Max transaction length */
87 88
89#define AUTOSUSPEND_TIMEOUT 2000
90
88static void fsl_espi_change_mode(struct spi_device *spi) 91static void fsl_espi_change_mode(struct spi_device *spi)
89{ 92{
90 struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master); 93 struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master);
@@ -485,6 +488,8 @@ static int fsl_espi_setup(struct spi_device *spi)
485 mpc8xxx_spi = spi_master_get_devdata(spi->master); 488 mpc8xxx_spi = spi_master_get_devdata(spi->master);
486 reg_base = mpc8xxx_spi->reg_base; 489 reg_base = mpc8xxx_spi->reg_base;
487 490
491 pm_runtime_get_sync(mpc8xxx_spi->dev);
492
488 hw_mode = cs->hw_mode; /* Save original settings */ 493 hw_mode = cs->hw_mode; /* Save original settings */
489 cs->hw_mode = mpc8xxx_spi_read_reg( 494 cs->hw_mode = mpc8xxx_spi_read_reg(
490 &reg_base->csmode[spi->chip_select]); 495 &reg_base->csmode[spi->chip_select]);
@@ -507,6 +512,10 @@ static int fsl_espi_setup(struct spi_device *spi)
507 mpc8xxx_spi_write_reg(&reg_base->mode, loop_mode); 512 mpc8xxx_spi_write_reg(&reg_base->mode, loop_mode);
508 513
509 retval = fsl_espi_setup_transfer(spi, NULL); 514 retval = fsl_espi_setup_transfer(spi, NULL);
515
516 pm_runtime_mark_last_busy(mpc8xxx_spi->dev);
517 pm_runtime_put_autosuspend(mpc8xxx_spi->dev);
518
510 if (retval < 0) { 519 if (retval < 0) {
511 cs->hw_mode = hw_mode; /* Restore settings */ 520 cs->hw_mode = hw_mode; /* Restore settings */
512 return retval; 521 return retval;
@@ -604,20 +613,14 @@ static irqreturn_t fsl_espi_irq(s32 irq, void *context_data)
604 return ret; 613 return ret;
605} 614}
606 615
607static void fsl_espi_remove(struct mpc8xxx_spi *mspi) 616#ifdef CONFIG_PM
617static int fsl_espi_runtime_suspend(struct device *dev)
608{ 618{
609 iounmap(mspi->reg_base); 619 struct spi_master *master = dev_get_drvdata(dev);
610} 620 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(master);
611 621 struct fsl_espi_reg *reg_base = mpc8xxx_spi->reg_base;
612static int fsl_espi_suspend(struct spi_master *master)
613{
614 struct mpc8xxx_spi *mpc8xxx_spi;
615 struct fsl_espi_reg *reg_base;
616 u32 regval; 622 u32 regval;
617 623
618 mpc8xxx_spi = spi_master_get_devdata(master);
619 reg_base = mpc8xxx_spi->reg_base;
620
621 regval = mpc8xxx_spi_read_reg(&reg_base->mode); 624 regval = mpc8xxx_spi_read_reg(&reg_base->mode);
622 regval &= ~SPMODE_ENABLE; 625 regval &= ~SPMODE_ENABLE;
623 mpc8xxx_spi_write_reg(&reg_base->mode, regval); 626 mpc8xxx_spi_write_reg(&reg_base->mode, regval);
@@ -625,21 +628,20 @@ static int fsl_espi_suspend(struct spi_master *master)
625 return 0; 628 return 0;
626} 629}
627 630
628static int fsl_espi_resume(struct spi_master *master) 631static int fsl_espi_runtime_resume(struct device *dev)
629{ 632{
630 struct mpc8xxx_spi *mpc8xxx_spi; 633 struct spi_master *master = dev_get_drvdata(dev);
631 struct fsl_espi_reg *reg_base; 634 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(master);
635 struct fsl_espi_reg *reg_base = mpc8xxx_spi->reg_base;
632 u32 regval; 636 u32 regval;
633 637
634 mpc8xxx_spi = spi_master_get_devdata(master);
635 reg_base = mpc8xxx_spi->reg_base;
636
637 regval = mpc8xxx_spi_read_reg(&reg_base->mode); 638 regval = mpc8xxx_spi_read_reg(&reg_base->mode);
638 regval |= SPMODE_ENABLE; 639 regval |= SPMODE_ENABLE;
639 mpc8xxx_spi_write_reg(&reg_base->mode, regval); 640 mpc8xxx_spi_write_reg(&reg_base->mode, regval);
640 641
641 return 0; 642 return 0;
642} 643}
644#endif
643 645
644static struct spi_master * fsl_espi_probe(struct device *dev, 646static struct spi_master * fsl_espi_probe(struct device *dev,
645 struct resource *mem, unsigned int irq) 647 struct resource *mem, unsigned int irq)
@@ -667,25 +669,23 @@ static struct spi_master * fsl_espi_probe(struct device *dev,
667 master->setup = fsl_espi_setup; 669 master->setup = fsl_espi_setup;
668 master->cleanup = fsl_espi_cleanup; 670 master->cleanup = fsl_espi_cleanup;
669 master->transfer_one_message = fsl_espi_do_one_msg; 671 master->transfer_one_message = fsl_espi_do_one_msg;
670 master->prepare_transfer_hardware = fsl_espi_resume; 672 master->auto_runtime_pm = true;
671 master->unprepare_transfer_hardware = fsl_espi_suspend;
672 673
673 mpc8xxx_spi = spi_master_get_devdata(master); 674 mpc8xxx_spi = spi_master_get_devdata(master);
674 mpc8xxx_spi->spi_remove = fsl_espi_remove;
675 675
676 mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem)); 676 mpc8xxx_spi->reg_base = devm_ioremap_resource(dev, mem);
677 if (!mpc8xxx_spi->reg_base) { 677 if (IS_ERR(mpc8xxx_spi->reg_base)) {
678 ret = -ENOMEM; 678 ret = PTR_ERR(mpc8xxx_spi->reg_base);
679 goto err_probe; 679 goto err_probe;
680 } 680 }
681 681
682 reg_base = mpc8xxx_spi->reg_base; 682 reg_base = mpc8xxx_spi->reg_base;
683 683
684 /* Register for SPI Interrupt */ 684 /* Register for SPI Interrupt */
685 ret = request_irq(mpc8xxx_spi->irq, fsl_espi_irq, 685 ret = devm_request_irq(dev, mpc8xxx_spi->irq, fsl_espi_irq,
686 0, "fsl_espi", mpc8xxx_spi); 686 0, "fsl_espi", mpc8xxx_spi);
687 if (ret) 687 if (ret)
688 goto free_irq; 688 goto err_probe;
689 689
690 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) { 690 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) {
691 mpc8xxx_spi->rx_shift = 16; 691 mpc8xxx_spi->rx_shift = 16;
@@ -731,18 +731,27 @@ static struct spi_master * fsl_espi_probe(struct device *dev,
731 731
732 mpc8xxx_spi_write_reg(&reg_base->mode, regval); 732 mpc8xxx_spi_write_reg(&reg_base->mode, regval);
733 733
734 ret = spi_register_master(master); 734 pm_runtime_set_autosuspend_delay(dev, AUTOSUSPEND_TIMEOUT);
735 pm_runtime_use_autosuspend(dev);
736 pm_runtime_set_active(dev);
737 pm_runtime_enable(dev);
738 pm_runtime_get_sync(dev);
739
740 ret = devm_spi_register_master(dev, master);
735 if (ret < 0) 741 if (ret < 0)
736 goto unreg_master; 742 goto err_pm;
737 743
738 dev_info(dev, "at 0x%p (irq = %d)\n", reg_base, mpc8xxx_spi->irq); 744 dev_info(dev, "at 0x%p (irq = %d)\n", reg_base, mpc8xxx_spi->irq);
739 745
746 pm_runtime_mark_last_busy(dev);
747 pm_runtime_put_autosuspend(dev);
748
740 return master; 749 return master;
741 750
742unreg_master: 751err_pm:
743 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi); 752 pm_runtime_put_noidle(dev);
744free_irq: 753 pm_runtime_disable(dev);
745 iounmap(mpc8xxx_spi->reg_base); 754 pm_runtime_set_suspended(dev);
746err_probe: 755err_probe:
747 spi_master_put(master); 756 spi_master_put(master);
748err: 757err:
@@ -809,7 +818,9 @@ err:
809 818
810static int of_fsl_espi_remove(struct platform_device *dev) 819static int of_fsl_espi_remove(struct platform_device *dev)
811{ 820{
812 return mpc8xxx_spi_remove(&dev->dev); 821 pm_runtime_disable(&dev->dev);
822
823 return 0;
813} 824}
814 825
815#ifdef CONFIG_PM_SLEEP 826#ifdef CONFIG_PM_SLEEP
@@ -824,7 +835,11 @@ static int of_fsl_espi_suspend(struct device *dev)
824 return ret; 835 return ret;
825 } 836 }
826 837
827 return fsl_espi_suspend(master); 838 ret = pm_runtime_force_suspend(dev);
839 if (ret < 0)
840 return ret;
841
842 return 0;
828} 843}
829 844
830static int of_fsl_espi_resume(struct device *dev) 845static int of_fsl_espi_resume(struct device *dev)
@@ -834,7 +849,7 @@ static int of_fsl_espi_resume(struct device *dev)
834 struct mpc8xxx_spi *mpc8xxx_spi; 849 struct mpc8xxx_spi *mpc8xxx_spi;
835 struct fsl_espi_reg *reg_base; 850 struct fsl_espi_reg *reg_base;
836 u32 regval; 851 u32 regval;
837 int i; 852 int i, ret;
838 853
839 mpc8xxx_spi = spi_master_get_devdata(master); 854 mpc8xxx_spi = spi_master_get_devdata(master);
840 reg_base = mpc8xxx_spi->reg_base; 855 reg_base = mpc8xxx_spi->reg_base;
@@ -854,11 +869,17 @@ static int of_fsl_espi_resume(struct device *dev)
854 869
855 mpc8xxx_spi_write_reg(&reg_base->mode, regval); 870 mpc8xxx_spi_write_reg(&reg_base->mode, regval);
856 871
872 ret = pm_runtime_force_resume(dev);
873 if (ret < 0)
874 return ret;
875
857 return spi_master_resume(master); 876 return spi_master_resume(master);
858} 877}
859#endif /* CONFIG_PM_SLEEP */ 878#endif /* CONFIG_PM_SLEEP */
860 879
861static const struct dev_pm_ops espi_pm = { 880static const struct dev_pm_ops espi_pm = {
881 SET_RUNTIME_PM_OPS(fsl_espi_runtime_suspend,
882 fsl_espi_runtime_resume, NULL)
862 SET_SYSTEM_SLEEP_PM_OPS(of_fsl_espi_suspend, of_fsl_espi_resume) 883 SET_SYSTEM_SLEEP_PM_OPS(of_fsl_espi_suspend, of_fsl_espi_resume)
863}; 884};
864 885
diff --git a/drivers/spi/spi-fsl-lib.c b/drivers/spi/spi-fsl-lib.c
index cb35d2f0d0e6..1e43412cd9f8 100644
--- a/drivers/spi/spi-fsl-lib.c
+++ b/drivers/spi/spi-fsl-lib.c
@@ -114,25 +114,6 @@ void mpc8xxx_spi_probe(struct device *dev, struct resource *mem,
114} 114}
115EXPORT_SYMBOL_GPL(mpc8xxx_spi_probe); 115EXPORT_SYMBOL_GPL(mpc8xxx_spi_probe);
116 116
117int mpc8xxx_spi_remove(struct device *dev)
118{
119 struct mpc8xxx_spi *mpc8xxx_spi;
120 struct spi_master *master;
121
122 master = dev_get_drvdata(dev);
123 mpc8xxx_spi = spi_master_get_devdata(master);
124
125 spi_unregister_master(master);
126
127 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
128
129 if (mpc8xxx_spi->spi_remove)
130 mpc8xxx_spi->spi_remove(mpc8xxx_spi);
131
132 return 0;
133}
134EXPORT_SYMBOL_GPL(mpc8xxx_spi_remove);
135
136int of_mpc8xxx_spi_probe(struct platform_device *ofdev) 117int of_mpc8xxx_spi_probe(struct platform_device *ofdev)
137{ 118{
138 struct device *dev = &ofdev->dev; 119 struct device *dev = &ofdev->dev;
diff --git a/drivers/spi/spi-fsl-lib.h b/drivers/spi/spi-fsl-lib.h
index 1326a392adca..84f5dcb7a897 100644
--- a/drivers/spi/spi-fsl-lib.h
+++ b/drivers/spi/spi-fsl-lib.h
@@ -54,9 +54,6 @@ struct mpc8xxx_spi {
54 void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *); 54 void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *);
55 u32(*get_tx) (struct mpc8xxx_spi *); 55 u32(*get_tx) (struct mpc8xxx_spi *);
56 56
57 /* hooks for different controller driver */
58 void (*spi_remove) (struct mpc8xxx_spi *mspi);
59
60 unsigned int count; 57 unsigned int count;
61 unsigned int irq; 58 unsigned int irq;
62 59
diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c
index 60c590790854..8b290d9d7935 100644
--- a/drivers/spi/spi-fsl-spi.c
+++ b/drivers/spi/spi-fsl-spi.c
@@ -559,12 +559,6 @@ static irqreturn_t fsl_spi_irq(s32 irq, void *context_data)
559 return ret; 559 return ret;
560} 560}
561 561
562static void fsl_spi_remove(struct mpc8xxx_spi *mspi)
563{
564 iounmap(mspi->reg_base);
565 fsl_spi_cpm_free(mspi);
566}
567
568static void fsl_spi_grlib_cs_control(struct spi_device *spi, bool on) 562static void fsl_spi_grlib_cs_control(struct spi_device *spi, bool on)
569{ 563{
570 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); 564 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
@@ -631,7 +625,6 @@ static struct spi_master * fsl_spi_probe(struct device *dev,
631 master->transfer_one_message = fsl_spi_do_one_msg; 625 master->transfer_one_message = fsl_spi_do_one_msg;
632 626
633 mpc8xxx_spi = spi_master_get_devdata(master); 627 mpc8xxx_spi = spi_master_get_devdata(master);
634 mpc8xxx_spi->spi_remove = fsl_spi_remove;
635 mpc8xxx_spi->max_bits_per_word = 32; 628 mpc8xxx_spi->max_bits_per_word = 32;
636 mpc8xxx_spi->type = fsl_spi_get_type(dev); 629 mpc8xxx_spi->type = fsl_spi_get_type(dev);
637 630
@@ -639,10 +632,10 @@ static struct spi_master * fsl_spi_probe(struct device *dev,
639 if (ret) 632 if (ret)
640 goto err_cpm_init; 633 goto err_cpm_init;
641 634
642 mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem)); 635 mpc8xxx_spi->reg_base = devm_ioremap_resource(dev, mem);
643 if (mpc8xxx_spi->reg_base == NULL) { 636 if (IS_ERR(mpc8xxx_spi->reg_base)) {
644 ret = -ENOMEM; 637 ret = PTR_ERR(mpc8xxx_spi->reg_base);
645 goto err_ioremap; 638 goto err_probe;
646 } 639 }
647 640
648 if (mpc8xxx_spi->type == TYPE_GRLIB) 641 if (mpc8xxx_spi->type == TYPE_GRLIB)
@@ -661,11 +654,11 @@ static struct spi_master * fsl_spi_probe(struct device *dev,
661 &mpc8xxx_spi->tx_shift, 8, 1); 654 &mpc8xxx_spi->tx_shift, 8, 1);
662 655
663 /* Register for SPI Interrupt */ 656 /* Register for SPI Interrupt */
664 ret = request_irq(mpc8xxx_spi->irq, fsl_spi_irq, 657 ret = devm_request_irq(dev, mpc8xxx_spi->irq, fsl_spi_irq,
665 0, "fsl_spi", mpc8xxx_spi); 658 0, "fsl_spi", mpc8xxx_spi);
666 659
667 if (ret != 0) 660 if (ret != 0)
668 goto free_irq; 661 goto err_probe;
669 662
670 reg_base = mpc8xxx_spi->reg_base; 663 reg_base = mpc8xxx_spi->reg_base;
671 664
@@ -686,20 +679,16 @@ static struct spi_master * fsl_spi_probe(struct device *dev,
686 679
687 mpc8xxx_spi_write_reg(&reg_base->mode, regval); 680 mpc8xxx_spi_write_reg(&reg_base->mode, regval);
688 681
689 ret = spi_register_master(master); 682 ret = devm_spi_register_master(dev, master);
690 if (ret < 0) 683 if (ret < 0)
691 goto unreg_master; 684 goto err_probe;
692 685
693 dev_info(dev, "at 0x%p (irq = %d), %s mode\n", reg_base, 686 dev_info(dev, "at 0x%p (irq = %d), %s mode\n", reg_base,
694 mpc8xxx_spi->irq, mpc8xxx_spi_strmode(mpc8xxx_spi->flags)); 687 mpc8xxx_spi->irq, mpc8xxx_spi_strmode(mpc8xxx_spi->flags));
695 688
696 return master; 689 return master;
697 690
698unreg_master: 691err_probe:
699 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
700free_irq:
701 iounmap(mpc8xxx_spi->reg_base);
702err_ioremap:
703 fsl_spi_cpm_free(mpc8xxx_spi); 692 fsl_spi_cpm_free(mpc8xxx_spi);
704err_cpm_init: 693err_cpm_init:
705 spi_master_put(master); 694 spi_master_put(master);
@@ -866,11 +855,8 @@ static int of_fsl_spi_remove(struct platform_device *ofdev)
866{ 855{
867 struct spi_master *master = platform_get_drvdata(ofdev); 856 struct spi_master *master = platform_get_drvdata(ofdev);
868 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(master); 857 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(master);
869 int ret;
870 858
871 ret = mpc8xxx_spi_remove(&ofdev->dev); 859 fsl_spi_cpm_free(mpc8xxx_spi);
872 if (ret)
873 return ret;
874 if (mpc8xxx_spi->type == TYPE_FSL) 860 if (mpc8xxx_spi->type == TYPE_FSL)
875 of_fsl_spi_free_chipselects(&ofdev->dev); 861 of_fsl_spi_free_chipselects(&ofdev->dev);
876 return 0; 862 return 0;
@@ -916,7 +902,12 @@ static int plat_mpc8xxx_spi_probe(struct platform_device *pdev)
916 902
917static int plat_mpc8xxx_spi_remove(struct platform_device *pdev) 903static int plat_mpc8xxx_spi_remove(struct platform_device *pdev)
918{ 904{
919 return mpc8xxx_spi_remove(&pdev->dev); 905 struct spi_master *master = platform_get_drvdata(pdev);
906 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(master);
907
908 fsl_spi_cpm_free(mpc8xxx_spi);
909
910 return 0;
920} 911}
921 912
922MODULE_ALIAS("platform:mpc8xxx_spi"); 913MODULE_ALIAS("platform:mpc8xxx_spi");
diff --git a/drivers/spi/spi-img-spfi.c b/drivers/spi/spi-img-spfi.c
index bb916c8d40db..823cbc92d1e7 100644
--- a/drivers/spi/spi-img-spfi.c
+++ b/drivers/spi/spi-img-spfi.c
@@ -581,6 +581,7 @@ static int img_spfi_probe(struct platform_device *pdev)
581 struct img_spfi *spfi; 581 struct img_spfi *spfi;
582 struct resource *res; 582 struct resource *res;
583 int ret; 583 int ret;
584 u32 max_speed_hz;
584 585
585 master = spi_alloc_master(&pdev->dev, sizeof(*spfi)); 586 master = spi_alloc_master(&pdev->dev, sizeof(*spfi));
586 if (!master) 587 if (!master)
@@ -645,6 +646,19 @@ static int img_spfi_probe(struct platform_device *pdev)
645 master->max_speed_hz = clk_get_rate(spfi->spfi_clk) / 4; 646 master->max_speed_hz = clk_get_rate(spfi->spfi_clk) / 4;
646 master->min_speed_hz = clk_get_rate(spfi->spfi_clk) / 512; 647 master->min_speed_hz = clk_get_rate(spfi->spfi_clk) / 512;
647 648
649 /*
650 * Maximum speed supported by spfi is limited to the lower value
651 * between 1/4 of the SPFI clock or to "spfi-max-frequency"
652 * defined in the device tree.
653 * If no value is defined in the device tree assume the maximum
654 * speed supported to be 1/4 of the SPFI clock.
655 */
656 if (!of_property_read_u32(spfi->dev->of_node, "spfi-max-frequency",
657 &max_speed_hz)) {
658 if (master->max_speed_hz > max_speed_hz)
659 master->max_speed_hz = max_speed_hz;
660 }
661
648 master->setup = img_spfi_setup; 662 master->setup = img_spfi_setup;
649 master->cleanup = img_spfi_cleanup; 663 master->cleanup = img_spfi_cleanup;
650 master->transfer_one = img_spfi_transfer_one; 664 master->transfer_one = img_spfi_transfer_one;
diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c
index 965d2bdcfdcc..1e75341689a6 100644
--- a/drivers/spi/spi-mpc512x-psc.c
+++ b/drivers/spi/spi-mpc512x-psc.c
@@ -30,11 +30,37 @@
30#include <linux/gpio.h> 30#include <linux/gpio.h>
31#include <asm/mpc52xx_psc.h> 31#include <asm/mpc52xx_psc.h>
32 32
33enum {
34 TYPE_MPC5121,
35 TYPE_MPC5125,
36};
37
38/*
39 * This macro abstracts the differences in the PSC register layout between
40 * MPC5121 (which uses a struct mpc52xx_psc) and MPC5125 (using mpc5125_psc).
41 */
42#define psc_addr(mps, regname) ({ \
43 void *__ret = NULL; \
44 switch (mps->type) { \
45 case TYPE_MPC5121: { \
46 struct mpc52xx_psc __iomem *psc = mps->psc; \
47 __ret = &psc->regname; \
48 }; \
49 break; \
50 case TYPE_MPC5125: { \
51 struct mpc5125_psc __iomem *psc = mps->psc; \
52 __ret = &psc->regname; \
53 }; \
54 break; \
55 } \
56 __ret; })
57
33struct mpc512x_psc_spi { 58struct mpc512x_psc_spi {
34 void (*cs_control)(struct spi_device *spi, bool on); 59 void (*cs_control)(struct spi_device *spi, bool on);
35 60
36 /* driver internal data */ 61 /* driver internal data */
37 struct mpc52xx_psc __iomem *psc; 62 int type;
63 void __iomem *psc;
38 struct mpc512x_psc_fifo __iomem *fifo; 64 struct mpc512x_psc_fifo __iomem *fifo;
39 unsigned int irq; 65 unsigned int irq;
40 u8 bits_per_word; 66 u8 bits_per_word;
@@ -71,13 +97,12 @@ static void mpc512x_psc_spi_activate_cs(struct spi_device *spi)
71{ 97{
72 struct mpc512x_psc_spi_cs *cs = spi->controller_state; 98 struct mpc512x_psc_spi_cs *cs = spi->controller_state;
73 struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); 99 struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master);
74 struct mpc52xx_psc __iomem *psc = mps->psc;
75 u32 sicr; 100 u32 sicr;
76 u32 ccr; 101 u32 ccr;
77 int speed; 102 int speed;
78 u16 bclkdiv; 103 u16 bclkdiv;
79 104
80 sicr = in_be32(&psc->sicr); 105 sicr = in_be32(psc_addr(mps, sicr));
81 106
82 /* Set clock phase and polarity */ 107 /* Set clock phase and polarity */
83 if (spi->mode & SPI_CPHA) 108 if (spi->mode & SPI_CPHA)
@@ -94,9 +119,9 @@ static void mpc512x_psc_spi_activate_cs(struct spi_device *spi)
94 sicr |= 0x10000000; 119 sicr |= 0x10000000;
95 else 120 else
96 sicr &= ~0x10000000; 121 sicr &= ~0x10000000;
97 out_be32(&psc->sicr, sicr); 122 out_be32(psc_addr(mps, sicr), sicr);
98 123
99 ccr = in_be32(&psc->ccr); 124 ccr = in_be32(psc_addr(mps, ccr));
100 ccr &= 0xFF000000; 125 ccr &= 0xFF000000;
101 speed = cs->speed_hz; 126 speed = cs->speed_hz;
102 if (!speed) 127 if (!speed)
@@ -104,7 +129,7 @@ static void mpc512x_psc_spi_activate_cs(struct spi_device *spi)
104 bclkdiv = (mps->mclk_rate / speed) - 1; 129 bclkdiv = (mps->mclk_rate / speed) - 1;
105 130
106 ccr |= (((bclkdiv & 0xff) << 16) | (((bclkdiv >> 8) & 0xff) << 8)); 131 ccr |= (((bclkdiv & 0xff) << 16) | (((bclkdiv >> 8) & 0xff) << 8));
107 out_be32(&psc->ccr, ccr); 132 out_be32(psc_addr(mps, ccr), ccr);
108 mps->bits_per_word = cs->bits_per_word; 133 mps->bits_per_word = cs->bits_per_word;
109 134
110 if (mps->cs_control && gpio_is_valid(spi->cs_gpio)) 135 if (mps->cs_control && gpio_is_valid(spi->cs_gpio))
@@ -315,16 +340,15 @@ static int mpc512x_psc_spi_msg_xfer(struct spi_master *master,
315static int mpc512x_psc_spi_prep_xfer_hw(struct spi_master *master) 340static int mpc512x_psc_spi_prep_xfer_hw(struct spi_master *master)
316{ 341{
317 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master); 342 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master);
318 struct mpc52xx_psc __iomem *psc = mps->psc;
319 343
320 dev_dbg(&master->dev, "%s()\n", __func__); 344 dev_dbg(&master->dev, "%s()\n", __func__);
321 345
322 /* Zero MR2 */ 346 /* Zero MR2 */
323 in_8(&psc->mode); 347 in_8(psc_addr(mps, mr2));
324 out_8(&psc->mode, 0x0); 348 out_8(psc_addr(mps, mr2), 0x0);
325 349
326 /* enable transmitter/receiver */ 350 /* enable transmitter/receiver */
327 out_8(&psc->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE); 351 out_8(psc_addr(mps, command), MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE);
328 352
329 return 0; 353 return 0;
330} 354}
@@ -332,13 +356,12 @@ static int mpc512x_psc_spi_prep_xfer_hw(struct spi_master *master)
332static int mpc512x_psc_spi_unprep_xfer_hw(struct spi_master *master) 356static int mpc512x_psc_spi_unprep_xfer_hw(struct spi_master *master)
333{ 357{
334 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master); 358 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master);
335 struct mpc52xx_psc __iomem *psc = mps->psc;
336 struct mpc512x_psc_fifo __iomem *fifo = mps->fifo; 359 struct mpc512x_psc_fifo __iomem *fifo = mps->fifo;
337 360
338 dev_dbg(&master->dev, "%s()\n", __func__); 361 dev_dbg(&master->dev, "%s()\n", __func__);
339 362
340 /* disable transmitter/receiver and fifo interrupt */ 363 /* disable transmitter/receiver and fifo interrupt */
341 out_8(&psc->command, MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE); 364 out_8(psc_addr(mps, command), MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE);
342 out_be32(&fifo->tximr, 0); 365 out_be32(&fifo->tximr, 0);
343 366
344 return 0; 367 return 0;
@@ -388,7 +411,6 @@ static void mpc512x_psc_spi_cleanup(struct spi_device *spi)
388static int mpc512x_psc_spi_port_config(struct spi_master *master, 411static int mpc512x_psc_spi_port_config(struct spi_master *master,
389 struct mpc512x_psc_spi *mps) 412 struct mpc512x_psc_spi *mps)
390{ 413{
391 struct mpc52xx_psc __iomem *psc = mps->psc;
392 struct mpc512x_psc_fifo __iomem *fifo = mps->fifo; 414 struct mpc512x_psc_fifo __iomem *fifo = mps->fifo;
393 u32 sicr; 415 u32 sicr;
394 u32 ccr; 416 u32 ccr;
@@ -396,12 +418,12 @@ static int mpc512x_psc_spi_port_config(struct spi_master *master,
396 u16 bclkdiv; 418 u16 bclkdiv;
397 419
398 /* Reset the PSC into a known state */ 420 /* Reset the PSC into a known state */
399 out_8(&psc->command, MPC52xx_PSC_RST_RX); 421 out_8(psc_addr(mps, command), MPC52xx_PSC_RST_RX);
400 out_8(&psc->command, MPC52xx_PSC_RST_TX); 422 out_8(psc_addr(mps, command), MPC52xx_PSC_RST_TX);
401 out_8(&psc->command, MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE); 423 out_8(psc_addr(mps, command), MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE);
402 424
403 /* Disable psc interrupts all useful interrupts are in fifo */ 425 /* Disable psc interrupts all useful interrupts are in fifo */
404 out_be16(&psc->isr_imr.imr, 0); 426 out_be16(psc_addr(mps, isr_imr.imr), 0);
405 427
406 /* Disable fifo interrupts, will be enabled later */ 428 /* Disable fifo interrupts, will be enabled later */
407 out_be32(&fifo->tximr, 0); 429 out_be32(&fifo->tximr, 0);
@@ -417,18 +439,18 @@ static int mpc512x_psc_spi_port_config(struct spi_master *master,
417 0x00004000 | /* MSTR = 1 -- SPI master */ 439 0x00004000 | /* MSTR = 1 -- SPI master */
418 0x00000800; /* UseEOF = 1 -- SS low until EOF */ 440 0x00000800; /* UseEOF = 1 -- SS low until EOF */
419 441
420 out_be32(&psc->sicr, sicr); 442 out_be32(psc_addr(mps, sicr), sicr);
421 443
422 ccr = in_be32(&psc->ccr); 444 ccr = in_be32(psc_addr(mps, ccr));
423 ccr &= 0xFF000000; 445 ccr &= 0xFF000000;
424 speed = 1000000; /* default 1MHz */ 446 speed = 1000000; /* default 1MHz */
425 bclkdiv = (mps->mclk_rate / speed) - 1; 447 bclkdiv = (mps->mclk_rate / speed) - 1;
426 ccr |= (((bclkdiv & 0xff) << 16) | (((bclkdiv >> 8) & 0xff) << 8)); 448 ccr |= (((bclkdiv & 0xff) << 16) | (((bclkdiv >> 8) & 0xff) << 8));
427 out_be32(&psc->ccr, ccr); 449 out_be32(psc_addr(mps, ccr), ccr);
428 450
429 /* Set 2ms DTL delay */ 451 /* Set 2ms DTL delay */
430 out_8(&psc->ctur, 0x00); 452 out_8(psc_addr(mps, ctur), 0x00);
431 out_8(&psc->ctlr, 0x82); 453 out_8(psc_addr(mps, ctlr), 0x82);
432 454
433 /* we don't use the alarms */ 455 /* we don't use the alarms */
434 out_be32(&fifo->rxalarm, 0xfff); 456 out_be32(&fifo->rxalarm, 0xfff);
@@ -482,6 +504,7 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr,
482 504
483 dev_set_drvdata(dev, master); 505 dev_set_drvdata(dev, master);
484 mps = spi_master_get_devdata(master); 506 mps = spi_master_get_devdata(master);
507 mps->type = (int)of_device_get_match_data(dev);
485 mps->irq = irq; 508 mps->irq = irq;
486 509
487 if (pdata == NULL) { 510 if (pdata == NULL) {
@@ -589,7 +612,8 @@ static int mpc512x_psc_spi_of_remove(struct platform_device *op)
589} 612}
590 613
591static const struct of_device_id mpc512x_psc_spi_of_match[] = { 614static const struct of_device_id mpc512x_psc_spi_of_match[] = {
592 { .compatible = "fsl,mpc5121-psc-spi", }, 615 { .compatible = "fsl,mpc5121-psc-spi", .data = (void *)TYPE_MPC5121 },
616 { .compatible = "fsl,mpc5125-psc-spi", .data = (void *)TYPE_MPC5125 },
593 {}, 617 {},
594}; 618};
595 619