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
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.
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>
15 drivers/spi/spi-qup.c | 61 ++++++++-----------------------------------------
16 1 file changed, 9 insertions(+), 52 deletions(-)
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
23 #define SPI_DELAY_THRESHOLD 1
24 #define SPI_DELAY_RETRY 10
26 -struct spi_qup_device {
34 @@ -338,14 +333,13 @@ static irqreturn_t spi_qup_qup_irq(int irq, void *dev_id)
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)
43 + struct spi_qup *controller = spi_master_get_devdata(spi->master);
44 u32 config, iomode, mode;
45 int ret, n_words, w_size;
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);
52 @@ -399,12 +393,12 @@ static int spi_qup_io_config(struct spi_qup *controller,
54 config = readl_relaxed(controller->base + SPI_CONFIG);
56 - if (chip->mode & SPI_LOOP)
57 + if (spi->mode & SPI_LOOP)
58 config |= SPI_CONFIG_LOOPBACK;
60 config &= ~SPI_CONFIG_LOOPBACK;
62 - if (chip->mode & SPI_CPHA)
63 + if (spi->mode & SPI_CPHA)
64 config &= ~SPI_CONFIG_INPUT_FIRST;
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.
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;
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)
79 struct spi_qup *controller = spi_master_get_devdata(spi->master);
80 - struct spi_qup_device *chip = spi_get_ctldata(spi);
84 @@ -444,9 +437,9 @@ static void spi_qup_set_cs(struct spi_device *spi, bool enable)
85 iocontol |= SPI_IO_C_FORCE_CS;
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);
91 - mask = SPI_IO_C_CS_N_POLARITY_0 << chip->select;
92 + mask = SPI_IO_C_CS_N_POLARITY_0 << spi->chip_select;
96 @@ -461,11 +454,10 @@ static int spi_qup_transfer_one(struct spi_master *master,
97 struct spi_transfer *xfer)
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;
104 - ret = spi_qup_io_config(controller, chip, xfer);
105 + ret = spi_qup_io_config(spi, xfer);
109 @@ -511,38 +503,6 @@ exit:
113 -static int spi_qup_setup(struct spi_device *spi)
115 - struct spi_qup *controller = spi_master_get_devdata(spi->master);
116 - struct spi_qup_device *chip = spi_get_ctldata(spi);
120 - chip = kzalloc(sizeof(*chip), GFP_KERNEL);
122 - dev_err(controller->dev, "no memory for chip data\n");
126 - chip->mode = spi->mode;
127 - chip->select = spi->chip_select;
128 - spi_set_ctldata(spi, chip);
134 -static void spi_qup_cleanup(struct spi_device *spi)
136 - struct spi_qup_device *chip = spi_get_ctldata(spi);
141 - spi_set_ctldata(spi, NULL);
145 static int spi_qup_probe(struct platform_device *pdev)
147 struct spi_master *master;
148 @@ -561,7 +521,6 @@ static int spi_qup_probe(struct platform_device *pdev)
149 return PTR_ERR(base);
151 irq = platform_get_irq(pdev, 0);
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;