28
28
#include <linux/of_address.h>
29
29
#include <linux/of_irq.h>
30
30
#include <linux/of_platform.h>
31
- #include <linux/of_gpio.h>
32
31
#include <linux/interrupt.h>
33
32
#include <linux/delay.h>
34
33
35
- #include <linux/gpio.h>
36
34
#include <linux/spi/spi.h>
37
35
#include <linux/spi/spi_bitbang.h>
38
36
@@ -127,8 +125,6 @@ struct ppc4xx_spi {
127
125
const unsigned char * tx ;
128
126
unsigned char * rx ;
129
127
130
- int * gpios ;
131
-
132
128
struct spi_ppc4xx_regs __iomem * regs ; /* pointer to the registers */
133
129
struct spi_master * master ;
134
130
struct device * dev ;
@@ -260,27 +256,6 @@ static int spi_ppc4xx_setup(struct spi_device *spi)
260
256
return 0 ;
261
257
}
262
258
263
- static void spi_ppc4xx_chipsel (struct spi_device * spi , int value )
264
- {
265
- struct ppc4xx_spi * hw = spi_master_get_devdata (spi -> master );
266
- unsigned int cs = spi -> chip_select ;
267
- unsigned int cspol ;
268
-
269
- /*
270
- * If there are no chip selects at all, or if this is the special
271
- * case of a non-existent (dummy) chip select, do nothing.
272
- */
273
-
274
- if (!hw -> master -> num_chipselect || hw -> gpios [cs ] == - EEXIST )
275
- return ;
276
-
277
- cspol = spi -> mode & SPI_CS_HIGH ? 1 : 0 ;
278
- if (value == BITBANG_CS_INACTIVE )
279
- cspol = !cspol ;
280
-
281
- gpio_set_value (hw -> gpios [cs ], cspol );
282
- }
283
-
284
259
static irqreturn_t spi_ppc4xx_int (int irq , void * dev_id )
285
260
{
286
261
struct ppc4xx_spi * hw ;
@@ -359,19 +334,6 @@ static void spi_ppc4xx_enable(struct ppc4xx_spi *hw)
359
334
dcri_clrset (SDR0 , SDR0_PFC1 , 0x80000000 >> 14 , 0 );
360
335
}
361
336
362
- static void free_gpios (struct ppc4xx_spi * hw )
363
- {
364
- if (hw -> master -> num_chipselect ) {
365
- int i ;
366
- for (i = 0 ; i < hw -> master -> num_chipselect ; i ++ )
367
- if (gpio_is_valid (hw -> gpios [i ]))
368
- gpio_free (hw -> gpios [i ]);
369
-
370
- kfree (hw -> gpios );
371
- hw -> gpios = NULL ;
372
- }
373
- }
374
-
375
337
/*
376
338
* platform_device layer stuff...
377
339
*/
@@ -385,7 +347,6 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
385
347
struct device * dev = & op -> dev ;
386
348
struct device_node * opbnp ;
387
349
int ret ;
388
- int num_gpios ;
389
350
const unsigned int * clk ;
390
351
391
352
master = spi_alloc_master (dev , sizeof * hw );
@@ -399,82 +360,40 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
399
360
400
361
init_completion (& hw -> done );
401
362
402
- /*
403
- * A count of zero implies a single SPI device without any chip-select.
404
- * Note that of_gpio_count counts all gpios assigned to this spi master.
405
- * This includes both "null" gpio's and real ones.
406
- */
407
- num_gpios = of_gpio_count (np );
408
- if (num_gpios > 0 ) {
409
- int i ;
410
-
411
- hw -> gpios = kcalloc (num_gpios , sizeof (* hw -> gpios ), GFP_KERNEL );
412
- if (!hw -> gpios ) {
413
- ret = - ENOMEM ;
414
- goto free_master ;
415
- }
416
-
417
- for (i = 0 ; i < num_gpios ; i ++ ) {
418
- int gpio ;
419
- enum of_gpio_flags flags ;
420
-
421
- gpio = of_get_gpio_flags (np , i , & flags );
422
- hw -> gpios [i ] = gpio ;
423
-
424
- if (gpio_is_valid (gpio )) {
425
- /* Real CS - set the initial state. */
426
- ret = gpio_request (gpio , np -> name );
427
- if (ret < 0 ) {
428
- dev_err (dev ,
429
- "can't request gpio #%d: %d\n" ,
430
- i , ret );
431
- goto free_gpios ;
432
- }
433
-
434
- gpio_direction_output (gpio ,
435
- !!(flags & OF_GPIO_ACTIVE_LOW ));
436
- } else if (gpio == - EEXIST ) {
437
- ; /* No CS, but that's OK. */
438
- } else {
439
- dev_err (dev , "invalid gpio #%d: %d\n" , i , gpio );
440
- ret = - EINVAL ;
441
- goto free_gpios ;
442
- }
443
- }
444
- }
445
-
446
363
/* Setup the state for the bitbang driver */
447
364
bbp = & hw -> bitbang ;
448
365
bbp -> master = hw -> master ;
449
366
bbp -> setup_transfer = spi_ppc4xx_setupxfer ;
450
- bbp -> chipselect = spi_ppc4xx_chipsel ;
451
367
bbp -> txrx_bufs = spi_ppc4xx_txrx ;
452
368
bbp -> use_dma = 0 ;
453
369
bbp -> master -> setup = spi_ppc4xx_setup ;
454
370
bbp -> master -> cleanup = spi_ppc4xx_cleanup ;
455
371
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 ;
456
378
457
379
/* the spi->mode bits understood by this driver: */
458
380
bbp -> master -> mode_bits =
459
381
SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_LSB_FIRST ;
460
382
461
- /* this many pins in all GPIO controllers */
462
- bbp -> master -> num_chipselect = num_gpios > 0 ? num_gpios : 0 ;
463
-
464
383
/* Get the clock for the OPB */
465
384
opbnp = of_find_compatible_node (NULL , NULL , "ibm,opb" );
466
385
if (opbnp == NULL ) {
467
386
dev_err (dev , "OPB: cannot find node\n" );
468
387
ret = - ENODEV ;
469
- goto free_gpios ;
388
+ goto free_master ;
470
389
}
471
390
/* Get the clock (Hz) for the OPB */
472
391
clk = of_get_property (opbnp , "clock-frequency" , NULL );
473
392
if (clk == NULL ) {
474
393
dev_err (dev , "OPB: no clock-frequency property set\n" );
475
394
of_node_put (opbnp );
476
395
ret = - ENODEV ;
477
- goto free_gpios ;
396
+ goto free_master ;
478
397
}
479
398
hw -> opb_freq = * clk ;
480
399
hw -> opb_freq >>= 2 ;
@@ -483,7 +402,7 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
483
402
ret = of_address_to_resource (np , 0 , & resource );
484
403
if (ret ) {
485
404
dev_err (dev , "error while parsing device node resource\n" );
486
- goto free_gpios ;
405
+ goto free_master ;
487
406
}
488
407
hw -> mapbase = resource .start ;
489
408
hw -> mapsize = resource_size (& resource );
@@ -492,7 +411,7 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
492
411
if (hw -> mapsize < sizeof (struct spi_ppc4xx_regs )) {
493
412
dev_err (dev , "too small to map registers\n" );
494
413
ret = - EINVAL ;
495
- goto free_gpios ;
414
+ goto free_master ;
496
415
}
497
416
498
417
/* Request IRQ */
@@ -501,7 +420,7 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
501
420
0 , "spi_ppc4xx_of" , (void * )hw );
502
421
if (ret ) {
503
422
dev_err (dev , "unable to allocate interrupt\n" );
504
- goto free_gpios ;
423
+ goto free_master ;
505
424
}
506
425
507
426
if (!request_mem_region (hw -> mapbase , hw -> mapsize , DRIVER_NAME )) {
@@ -538,8 +457,6 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)
538
457
release_mem_region (hw -> mapbase , hw -> mapsize );
539
458
request_mem_error :
540
459
free_irq (hw -> irqnum , hw );
541
- free_gpios :
542
- free_gpios (hw );
543
460
free_master :
544
461
spi_master_put (master );
545
462
@@ -556,7 +473,6 @@ static int spi_ppc4xx_of_remove(struct platform_device *op)
556
473
release_mem_region (hw -> mapbase , hw -> mapsize );
557
474
free_irq (hw -> irqnum , hw );
558
475
iounmap (hw -> regs );
559
- free_gpios (hw );
560
476
spi_master_put (master );
561
477
return 0 ;
562
478
}
0 commit comments