11
11
*/
12
12
13
13
#include <linux/module.h>
14
+ #include <linux/err.h>
14
15
#include <linux/errno.h>
15
16
#include <linux/of_platform.h>
16
17
#include <linux/interrupt.h>
17
18
#include <linux/delay.h>
18
19
#include <linux/gpio/consumer.h>
19
20
#include <linux/spi/spi.h>
20
21
#include <linux/io.h>
21
- #include <linux/of_gpio.h>
22
22
#include <linux/slab.h>
23
23
#include <linux/of_address.h>
24
24
#include <linux/of_irq.h>
@@ -90,7 +90,7 @@ struct mpc52xx_spi {
90
90
const u8 * tx_buf ;
91
91
int cs_change ;
92
92
int gpio_cs_count ;
93
- unsigned int * gpio_cs ;
93
+ struct gpio_desc * * gpio_cs ;
94
94
};
95
95
96
96
/*
@@ -102,9 +102,10 @@ static void mpc52xx_spi_chipsel(struct mpc52xx_spi *ms, int value)
102
102
103
103
if (ms -> gpio_cs_count > 0 ) {
104
104
cs = ms -> message -> spi -> chip_select ;
105
- gpio_set_value (ms -> gpio_cs [cs ], value ? 0 : 1 );
106
- } else
105
+ gpiod_set_value (ms -> gpio_cs [cs ], value );
106
+ } else {
107
107
out_8 (ms -> regs + SPI_PORTDATA , value ? 0 : 0x08 );
108
+ }
108
109
}
109
110
110
111
/*
@@ -386,10 +387,10 @@ static int mpc52xx_spi_probe(struct platform_device *op)
386
387
{
387
388
struct spi_master * master ;
388
389
struct mpc52xx_spi * ms ;
390
+ struct gpio_desc * gpio_cs ;
389
391
void __iomem * regs ;
390
392
u8 ctrl1 ;
391
393
int rc , i = 0 ;
392
- int gpio_cs ;
393
394
394
395
/* MMIO registers */
395
396
dev_dbg (& op -> dev , "probing mpc5200 SPI device\n" );
@@ -451,23 +452,16 @@ static int mpc52xx_spi_probe(struct platform_device *op)
451
452
}
452
453
453
454
for (i = 0 ; i < ms -> gpio_cs_count ; i ++ ) {
454
- gpio_cs = of_get_gpio (op -> dev .of_node , i );
455
- if (!gpio_is_valid (gpio_cs )) {
456
- dev_err (& op -> dev ,
457
- "could not parse the gpio field in oftree\n" );
458
- rc = - ENODEV ;
459
- goto err_gpio ;
460
- }
461
-
462
- rc = gpio_request (gpio_cs , dev_name (& op -> dev ));
455
+ gpio_cs = gpiod_get_index (& op -> dev ,
456
+ NULL , i , GPIOD_OUT_LOW );
457
+ rc = PTR_ERR_OR_ZERO (gpio_cs );
463
458
if (rc ) {
464
459
dev_err (& op -> dev ,
465
- "can't request spi cs gpio #%d on gpio line %d\n" ,
466
- i , gpio_cs );
460
+ "failed to get spi cs gpio #%d: %d\n" ,
461
+ i , rc );
467
462
goto err_gpio ;
468
463
}
469
464
470
- gpio_direction_output (gpio_cs , 1 );
471
465
ms -> gpio_cs [i ] = gpio_cs ;
472
466
}
473
467
}
@@ -508,7 +502,7 @@ static int mpc52xx_spi_probe(struct platform_device *op)
508
502
dev_err (& ms -> master -> dev , "initialization failed\n" );
509
503
err_gpio :
510
504
while (i -- > 0 )
511
- gpio_free (ms -> gpio_cs [i ]);
505
+ gpiod_put (ms -> gpio_cs [i ]);
512
506
513
507
kfree (ms -> gpio_cs );
514
508
err_alloc_gpio :
@@ -529,7 +523,7 @@ static int mpc52xx_spi_remove(struct platform_device *op)
529
523
free_irq (ms -> irq1 , ms );
530
524
531
525
for (i = 0 ; i < ms -> gpio_cs_count ; i ++ )
532
- gpio_free (ms -> gpio_cs [i ]);
526
+ gpiod_put (ms -> gpio_cs [i ]);
533
527
534
528
kfree (ms -> gpio_cs );
535
529
spi_unregister_master (master );
0 commit comments