hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/spi/spi-ppc4xx.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * SPI_PPC4XX SPI controller driver.
34 *
....@@ -10,10 +11,6 @@
1011 * Copyright (c) 2006 Ben Dooks
1112 * Copyright (c) 2006 Simtec Electronics
1213 * Ben Dooks <ben@simtec.co.uk>
13
- *
14
- * This program is free software; you can redistribute it and/or modify it
15
- * under the terms of the GNU General Public License version 2 as published
16
- * by the Free Software Foundation.
1714 */
1815
1916 /*
....@@ -31,11 +28,9 @@
3128 #include <linux/of_address.h>
3229 #include <linux/of_irq.h>
3330 #include <linux/of_platform.h>
34
-#include <linux/of_gpio.h>
3531 #include <linux/interrupt.h>
3632 #include <linux/delay.h>
3733
38
-#include <linux/gpio.h>
3934 #include <linux/spi/spi.h>
4035 #include <linux/spi/spi_bitbang.h>
4136
....@@ -129,8 +124,6 @@
129124 /* data buffers */
130125 const unsigned char *tx;
131126 unsigned char *rx;
132
-
133
- int *gpios;
134127
135128 struct spi_ppc4xx_regs __iomem *regs; /* pointer to the registers */
136129 struct spi_master *master;
....@@ -263,27 +256,6 @@
263256 return 0;
264257 }
265258
266
-static void spi_ppc4xx_chipsel(struct spi_device *spi, int value)
267
-{
268
- struct ppc4xx_spi *hw = spi_master_get_devdata(spi->master);
269
- unsigned int cs = spi->chip_select;
270
- unsigned int cspol;
271
-
272
- /*
273
- * If there are no chip selects at all, or if this is the special
274
- * case of a non-existent (dummy) chip select, do nothing.
275
- */
276
-
277
- if (!hw->master->num_chipselect || hw->gpios[cs] == -EEXIST)
278
- return;
279
-
280
- cspol = spi->mode & SPI_CS_HIGH ? 1 : 0;
281
- if (value == BITBANG_CS_INACTIVE)
282
- cspol = !cspol;
283
-
284
- gpio_set_value(hw->gpios[cs], cspol);
285
-}
286
-
287259 static irqreturn_t spi_ppc4xx_int(int irq, void *dev_id)
288260 {
289261 struct ppc4xx_spi *hw;
....@@ -362,19 +334,6 @@
362334 dcri_clrset(SDR0, SDR0_PFC1, 0x80000000 >> 14, 0);
363335 }
364336
365
-static void free_gpios(struct ppc4xx_spi *hw)
366
-{
367
- if (hw->master->num_chipselect) {
368
- int i;
369
- for (i = 0; i < hw->master->num_chipselect; i++)
370
- if (gpio_is_valid(hw->gpios[i]))
371
- gpio_free(hw->gpios[i]);
372
-
373
- kfree(hw->gpios);
374
- hw->gpios = NULL;
375
- }
376
-}
377
-
378337 /*
379338 * platform_device layer stuff...
380339 */
....@@ -388,7 +347,6 @@
388347 struct device *dev = &op->dev;
389348 struct device_node *opbnp;
390349 int ret;
391
- int num_gpios;
392350 const unsigned int *clk;
393351
394352 master = spi_alloc_master(dev, sizeof *hw);
....@@ -402,74 +360,32 @@
402360
403361 init_completion(&hw->done);
404362
405
- /*
406
- * A count of zero implies a single SPI device without any chip-select.
407
- * Note that of_gpio_count counts all gpios assigned to this spi master.
408
- * This includes both "null" gpio's and real ones.
409
- */
410
- num_gpios = of_gpio_count(np);
411
- if (num_gpios > 0) {
412
- int i;
413
-
414
- hw->gpios = kcalloc(num_gpios, sizeof(*hw->gpios), GFP_KERNEL);
415
- if (!hw->gpios) {
416
- ret = -ENOMEM;
417
- goto free_master;
418
- }
419
-
420
- for (i = 0; i < num_gpios; i++) {
421
- int gpio;
422
- enum of_gpio_flags flags;
423
-
424
- gpio = of_get_gpio_flags(np, i, &flags);
425
- hw->gpios[i] = gpio;
426
-
427
- if (gpio_is_valid(gpio)) {
428
- /* Real CS - set the initial state. */
429
- ret = gpio_request(gpio, np->name);
430
- if (ret < 0) {
431
- dev_err(dev,
432
- "can't request gpio #%d: %d\n",
433
- i, ret);
434
- goto free_gpios;
435
- }
436
-
437
- gpio_direction_output(gpio,
438
- !!(flags & OF_GPIO_ACTIVE_LOW));
439
- } else if (gpio == -EEXIST) {
440
- ; /* No CS, but that's OK. */
441
- } else {
442
- dev_err(dev, "invalid gpio #%d: %d\n", i, gpio);
443
- ret = -EINVAL;
444
- goto free_gpios;
445
- }
446
- }
447
- }
448
-
449363 /* Setup the state for the bitbang driver */
450364 bbp = &hw->bitbang;
451365 bbp->master = hw->master;
452366 bbp->setup_transfer = spi_ppc4xx_setupxfer;
453
- bbp->chipselect = spi_ppc4xx_chipsel;
454367 bbp->txrx_bufs = spi_ppc4xx_txrx;
455368 bbp->use_dma = 0;
456369 bbp->master->setup = spi_ppc4xx_setup;
457370 bbp->master->cleanup = spi_ppc4xx_cleanup;
458371 bbp->master->bits_per_word_mask = SPI_BPW_MASK(8);
372
+ bbp->master->use_gpio_descriptors = true;
373
+ /*
374
+ * The SPI core will count the number of GPIO descriptors to figure
375
+ * out the number of chip selects available on the platform.
376
+ */
377
+ bbp->master->num_chipselect = 0;
459378
460379 /* the spi->mode bits understood by this driver: */
461380 bbp->master->mode_bits =
462381 SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_LSB_FIRST;
463
-
464
- /* this many pins in all GPIO controllers */
465
- bbp->master->num_chipselect = num_gpios > 0 ? num_gpios : 0;
466382
467383 /* Get the clock for the OPB */
468384 opbnp = of_find_compatible_node(NULL, NULL, "ibm,opb");
469385 if (opbnp == NULL) {
470386 dev_err(dev, "OPB: cannot find node\n");
471387 ret = -ENODEV;
472
- goto free_gpios;
388
+ goto free_master;
473389 }
474390 /* Get the clock (Hz) for the OPB */
475391 clk = of_get_property(opbnp, "clock-frequency", NULL);
....@@ -477,7 +393,7 @@
477393 dev_err(dev, "OPB: no clock-frequency property set\n");
478394 of_node_put(opbnp);
479395 ret = -ENODEV;
480
- goto free_gpios;
396
+ goto free_master;
481397 }
482398 hw->opb_freq = *clk;
483399 hw->opb_freq >>= 2;
....@@ -486,7 +402,7 @@
486402 ret = of_address_to_resource(np, 0, &resource);
487403 if (ret) {
488404 dev_err(dev, "error while parsing device node resource\n");
489
- goto free_gpios;
405
+ goto free_master;
490406 }
491407 hw->mapbase = resource.start;
492408 hw->mapsize = resource_size(&resource);
....@@ -495,7 +411,7 @@
495411 if (hw->mapsize < sizeof(struct spi_ppc4xx_regs)) {
496412 dev_err(dev, "too small to map registers\n");
497413 ret = -EINVAL;
498
- goto free_gpios;
414
+ goto free_master;
499415 }
500416
501417 /* Request IRQ */
....@@ -504,7 +420,7 @@
504420 0, "spi_ppc4xx_of", (void *)hw);
505421 if (ret) {
506422 dev_err(dev, "unable to allocate interrupt\n");
507
- goto free_gpios;
423
+ goto free_master;
508424 }
509425
510426 if (!request_mem_region(hw->mapbase, hw->mapsize, DRIVER_NAME)) {
....@@ -541,8 +457,6 @@
541457 release_mem_region(hw->mapbase, hw->mapsize);
542458 request_mem_error:
543459 free_irq(hw->irqnum, hw);
544
-free_gpios:
545
- free_gpios(hw);
546460 free_master:
547461 spi_master_put(master);
548462
....@@ -559,7 +473,6 @@
559473 release_mem_region(hw->mapbase, hw->mapsize);
560474 free_irq(hw->irqnum, hw);
561475 iounmap(hw->regs);
562
- free_gpios(hw);
563476 spi_master_put(master);
564477 return 0;
565478 }