hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/spi/spi-oc-tiny.c
....@@ -1,7 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * OpenCores tiny SPI master driver
34 *
4
- * http://opencores.org/project,tiny_spi
5
+ * https://opencores.org/project,tiny_spi
56 *
67 * Copyright (C) 2011 Thomas Chou <thomas@wytron.com.tw>
78 *
....@@ -9,10 +10,6 @@
910 * Copyright (c) 2006 Ben Dooks
1011 * Copyright (c) 2006 Simtec Electronics
1112 * Ben Dooks <ben@simtec.co.uk>
12
- *
13
- * This program is free software; you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License version 2 as
15
- * published by the Free Software Foundation.
1613 */
1714
1815 #include <linux/interrupt.h>
....@@ -23,7 +20,6 @@
2320 #include <linux/spi/spi_bitbang.h>
2421 #include <linux/spi/spi_oc_tiny.h>
2522 #include <linux/io.h>
26
-#include <linux/gpio.h>
2723 #include <linux/of.h>
2824
2925 #define DRV_NAME "spi_oc_tiny"
....@@ -53,8 +49,6 @@
5349 unsigned int txc, rxc;
5450 const u8 *txp;
5551 u8 *rxp;
56
- int gpio_cs_count;
57
- int *gpio_cs;
5852 };
5953
6054 static inline struct tiny_spi *tiny_spi_to_hw(struct spi_device *sdev)
....@@ -67,16 +61,6 @@
6761 struct tiny_spi *hw = tiny_spi_to_hw(spi);
6862
6963 return min(DIV_ROUND_UP(hw->freq, hz * 2), (1U << hw->baudwidth)) - 1;
70
-}
71
-
72
-static void tiny_spi_chipselect(struct spi_device *spi, int is_active)
73
-{
74
- struct tiny_spi *hw = tiny_spi_to_hw(spi);
75
-
76
- if (hw->gpio_cs_count > 0) {
77
- gpio_set_value(hw->gpio_cs[spi->chip_select],
78
- (spi->mode & SPI_CS_HIGH) ? is_active : !is_active);
79
- }
8064 }
8165
8266 static int tiny_spi_setup_transfer(struct spi_device *spi,
....@@ -206,24 +190,10 @@
206190 {
207191 struct tiny_spi *hw = platform_get_drvdata(pdev);
208192 struct device_node *np = pdev->dev.of_node;
209
- unsigned int i;
210193 u32 val;
211194
212195 if (!np)
213196 return 0;
214
- hw->gpio_cs_count = of_gpio_count(np);
215
- if (hw->gpio_cs_count > 0) {
216
- hw->gpio_cs = devm_kcalloc(&pdev->dev,
217
- hw->gpio_cs_count, sizeof(unsigned int),
218
- GFP_KERNEL);
219
- if (!hw->gpio_cs)
220
- return -ENOMEM;
221
- }
222
- for (i = 0; i < hw->gpio_cs_count; i++) {
223
- hw->gpio_cs[i] = of_get_gpio_flags(np, i, NULL);
224
- if (hw->gpio_cs[i] < 0)
225
- return -ENODEV;
226
- }
227197 hw->bitbang.master->dev.of_node = pdev->dev.of_node;
228198 if (!of_property_read_u32(np, "clock-frequency", &val))
229199 hw->freq = val;
....@@ -243,8 +213,6 @@
243213 struct tiny_spi_platform_data *platp = dev_get_platdata(&pdev->dev);
244214 struct tiny_spi *hw;
245215 struct spi_master *master;
246
- struct resource *res;
247
- unsigned int i;
248216 int err = -ENODEV;
249217
250218 master = spi_alloc_master(&pdev->dev, sizeof(struct tiny_spi));
....@@ -253,9 +221,9 @@
253221
254222 /* setup the master state. */
255223 master->bus_num = pdev->id;
256
- master->num_chipselect = 255;
257224 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
258225 master->setup = tiny_spi_setup;
226
+ master->use_gpio_descriptors = true;
259227
260228 hw = spi_master_get_devdata(master);
261229 platform_set_drvdata(pdev, hw);
....@@ -263,12 +231,10 @@
263231 /* setup the state for the bitbang driver */
264232 hw->bitbang.master = master;
265233 hw->bitbang.setup_transfer = tiny_spi_setup_transfer;
266
- hw->bitbang.chipselect = tiny_spi_chipselect;
267234 hw->bitbang.txrx_bufs = tiny_spi_txrx_bufs;
268235
269236 /* find and map our resources */
270
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
271
- hw->base = devm_ioremap_resource(&pdev->dev, res);
237
+ hw->base = devm_platform_ioremap_resource(pdev, 0);
272238 if (IS_ERR(hw->base)) {
273239 err = PTR_ERR(hw->base);
274240 goto exit;
....@@ -284,12 +250,6 @@
284250 }
285251 /* find platform data */
286252 if (platp) {
287
- hw->gpio_cs_count = platp->gpio_cs_count;
288
- hw->gpio_cs = platp->gpio_cs;
289
- if (platp->gpio_cs_count && !platp->gpio_cs) {
290
- err = -EBUSY;
291
- goto exit;
292
- }
293253 hw->freq = platp->freq;
294254 hw->baudwidth = platp->baudwidth;
295255 } else {
....@@ -297,13 +257,6 @@
297257 if (err)
298258 goto exit;
299259 }
300
- for (i = 0; i < hw->gpio_cs_count; i++) {
301
- err = gpio_request(hw->gpio_cs[i], dev_name(&pdev->dev));
302
- if (err)
303
- goto exit_gpio;
304
- gpio_direction_output(hw->gpio_cs[i], 1);
305
- }
306
- hw->bitbang.master->num_chipselect = max(1, hw->gpio_cs_count);
307260
308261 /* register our spi controller */
309262 err = spi_bitbang_start(&hw->bitbang);
....@@ -313,9 +266,6 @@
313266
314267 return 0;
315268
316
-exit_gpio:
317
- while (i-- > 0)
318
- gpio_free(hw->gpio_cs[i]);
319269 exit:
320270 spi_master_put(master);
321271 return err;
....@@ -325,11 +275,8 @@
325275 {
326276 struct tiny_spi *hw = platform_get_drvdata(pdev);
327277 struct spi_master *master = hw->bitbang.master;
328
- unsigned int i;
329278
330279 spi_bitbang_stop(&hw->bitbang);
331
- for (i = 0; i < hw->gpio_cs_count; i++)
332
- gpio_free(hw->gpio_cs[i]);
333280 spi_master_put(master);
334281 return 0;
335282 }