69b4609a5fe893d7d213a2221108aca38ca06041
[openwrt/openwrt.git] / target / linux / ipq806x / patches / 0073-spi-qup-Get-rid-of-using-struct-spi_qup_device.patch
1 From 3027505ab8c8cb17291e53bca1d7bd770539d468 Mon Sep 17 00:00:00 2001
2 From: Axel Lin <axel.lin@ingics.com>
3 Date: Mon, 24 Feb 2014 23:07:36 +0800
4 Subject: [PATCH 073/182] spi: qup: Get rid of using struct spi_qup_device
5
6 Current code uses struct spi_qup_device to store spi->mode and spi->chip_select
7 settings. We can get these settings in spi_qup_transfer_one and spi_qup_set_cs
8 without using struct spi_qup_device. Refactor the code a bit to remove
9 spi_qup_setup(), spi_qup_cleanup(), and struct spi_qup_device.
10
11 Signed-off-by: Axel Lin <axel.lin@ingics.com>
12 Tested-by: Ivan T. Ivanov <iivanov@mm-sol.com>
13 Signed-off-by: Mark Brown <broonie@linaro.org>
14 ---
15 drivers/spi/spi-qup.c | 61 ++++++++-----------------------------------------
16 1 file changed, 9 insertions(+), 52 deletions(-)
17
18 diff --git a/drivers/spi/spi-qup.c b/drivers/spi/spi-qup.c
19 index 203f0d4..b032e88 100644
20 --- a/drivers/spi/spi-qup.c
21 +++ b/drivers/spi/spi-qup.c
22 @@ -123,11 +123,6 @@
23 #define SPI_DELAY_THRESHOLD 1
24 #define SPI_DELAY_RETRY 10
25
26 -struct spi_qup_device {
27 - int select;
28 - u16 mode;
29 -};
30 -
31 struct spi_qup {
32 void __iomem *base;
33 struct device *dev;
34 @@ -338,14 +333,13 @@ static irqreturn_t spi_qup_qup_irq(int irq, void *dev_id)
35
36
37 /* set clock freq ... bits per word */
38 -static int spi_qup_io_config(struct spi_qup *controller,
39 - struct spi_qup_device *chip,
40 - struct spi_transfer *xfer)
41 +static int spi_qup_io_config(struct spi_device *spi, struct spi_transfer *xfer)
42 {
43 + struct spi_qup *controller = spi_master_get_devdata(spi->master);
44 u32 config, iomode, mode;
45 int ret, n_words, w_size;
46
47 - if (chip->mode & SPI_LOOP && xfer->len > controller->in_fifo_sz) {
48 + if (spi->mode & SPI_LOOP && xfer->len > controller->in_fifo_sz) {
49 dev_err(controller->dev, "too big size for loopback %d > %d\n",
50 xfer->len, controller->in_fifo_sz);
51 return -EIO;
52 @@ -399,12 +393,12 @@ static int spi_qup_io_config(struct spi_qup *controller,
53
54 config = readl_relaxed(controller->base + SPI_CONFIG);
55
56 - if (chip->mode & SPI_LOOP)
57 + if (spi->mode & SPI_LOOP)
58 config |= SPI_CONFIG_LOOPBACK;
59 else
60 config &= ~SPI_CONFIG_LOOPBACK;
61
62 - if (chip->mode & SPI_CPHA)
63 + if (spi->mode & SPI_CPHA)
64 config &= ~SPI_CONFIG_INPUT_FIRST;
65 else
66 config |= SPI_CONFIG_INPUT_FIRST;
67 @@ -413,7 +407,7 @@ static int spi_qup_io_config(struct spi_qup *controller,
68 * HS_MODE improves signal stability for spi-clk high rates,
69 * but is invalid in loop back mode.
70 */
71 - if ((xfer->speed_hz >= SPI_HS_MIN_RATE) && !(chip->mode & SPI_LOOP))
72 + if ((xfer->speed_hz >= SPI_HS_MIN_RATE) && !(spi->mode & SPI_LOOP))
73 config |= SPI_CONFIG_HS_MODE;
74 else
75 config &= ~SPI_CONFIG_HS_MODE;
76 @@ -433,7 +427,6 @@ static int spi_qup_io_config(struct spi_qup *controller,
77 static void spi_qup_set_cs(struct spi_device *spi, bool enable)
78 {
79 struct spi_qup *controller = spi_master_get_devdata(spi->master);
80 - struct spi_qup_device *chip = spi_get_ctldata(spi);
81
82 u32 iocontol, mask;
83
84 @@ -444,9 +437,9 @@ static void spi_qup_set_cs(struct spi_device *spi, bool enable)
85 iocontol |= SPI_IO_C_FORCE_CS;
86
87 iocontol &= ~SPI_IO_C_CS_SELECT_MASK;
88 - iocontol |= SPI_IO_C_CS_SELECT(chip->select);
89 + iocontol |= SPI_IO_C_CS_SELECT(spi->chip_select);
90
91 - mask = SPI_IO_C_CS_N_POLARITY_0 << chip->select;
92 + mask = SPI_IO_C_CS_N_POLARITY_0 << spi->chip_select;
93
94 if (enable)
95 iocontol |= mask;
96 @@ -461,11 +454,10 @@ static int spi_qup_transfer_one(struct spi_master *master,
97 struct spi_transfer *xfer)
98 {
99 struct spi_qup *controller = spi_master_get_devdata(master);
100 - struct spi_qup_device *chip = spi_get_ctldata(spi);
101 unsigned long timeout, flags;
102 int ret = -EIO;
103
104 - ret = spi_qup_io_config(controller, chip, xfer);
105 + ret = spi_qup_io_config(spi, xfer);
106 if (ret)
107 return ret;
108
109 @@ -511,38 +503,6 @@ exit:
110 return ret;
111 }
112
113 -static int spi_qup_setup(struct spi_device *spi)
114 -{
115 - struct spi_qup *controller = spi_master_get_devdata(spi->master);
116 - struct spi_qup_device *chip = spi_get_ctldata(spi);
117 -
118 - if (!chip) {
119 - /* First setup */
120 - chip = kzalloc(sizeof(*chip), GFP_KERNEL);
121 - if (!chip) {
122 - dev_err(controller->dev, "no memory for chip data\n");
123 - return -ENOMEM;
124 - }
125 -
126 - chip->mode = spi->mode;
127 - chip->select = spi->chip_select;
128 - spi_set_ctldata(spi, chip);
129 - }
130 -
131 - return 0;
132 -}
133 -
134 -static void spi_qup_cleanup(struct spi_device *spi)
135 -{
136 - struct spi_qup_device *chip = spi_get_ctldata(spi);
137 -
138 - if (!chip)
139 - return;
140 -
141 - spi_set_ctldata(spi, NULL);
142 - kfree(chip);
143 -}
144 -
145 static int spi_qup_probe(struct platform_device *pdev)
146 {
147 struct spi_master *master;
148 @@ -561,7 +521,6 @@ static int spi_qup_probe(struct platform_device *pdev)
149 return PTR_ERR(base);
150
151 irq = platform_get_irq(pdev, 0);
152 -
153 if (irq < 0)
154 return irq;
155
156 @@ -617,8 +576,6 @@ static int spi_qup_probe(struct platform_device *pdev)
157 master->num_chipselect = SPI_NUM_CHIPSELECTS;
158 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
159 master->max_speed_hz = max_freq;
160 - master->setup = spi_qup_setup;
161 - master->cleanup = spi_qup_cleanup;
162 master->set_cs = spi_qup_set_cs;
163 master->transfer_one = spi_qup_transfer_one;
164 master->dev.of_node = pdev->dev.of_node;
165 --
166 1.7.10.4
167