Skip to content

Commit c18d925

Browse files
jan-kiszkabroonie
authored andcommitted
spi: pxa2xx: Convert to GPIO descriptor API where possible
We still need to request/free GPIOs passed via the legacy path of pxa2xx_spi_chip::gpio_cs, but we can use the gpiod API otherwise. Consistently use the descriptor API instead of the legacy one. Signed-off-by: Jan Kiszka <[email protected]> Acked-by: Mika Westerberg <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent d35f2dc commit c18d925

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

drivers/spi/spi-pxa2xx.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ static void cs_assert(struct driver_data *drv_data)
402402
return;
403403
}
404404

405-
if (gpio_is_valid(chip->gpio_cs)) {
406-
gpio_set_value(chip->gpio_cs, chip->gpio_cs_inverted);
405+
if (chip->gpiod_cs) {
406+
gpiod_set_value(chip->gpiod_cs, chip->gpio_cs_inverted);
407407
return;
408408
}
409409

@@ -424,8 +424,8 @@ static void cs_deassert(struct driver_data *drv_data)
424424
return;
425425
}
426426

427-
if (gpio_is_valid(chip->gpio_cs)) {
428-
gpio_set_value(chip->gpio_cs, !chip->gpio_cs_inverted);
427+
if (chip->gpiod_cs) {
428+
gpiod_set_value(chip->gpiod_cs, !chip->gpio_cs_inverted);
429429
return;
430430
}
431431

@@ -1213,17 +1213,16 @@ static int setup_cs(struct spi_device *spi, struct chip_data *chip,
12131213
struct pxa2xx_spi_chip *chip_info)
12141214
{
12151215
struct driver_data *drv_data = spi_master_get_devdata(spi->master);
1216+
struct gpio_desc *gpiod;
12161217
int err = 0;
12171218

12181219
if (chip == NULL)
12191220
return 0;
12201221

12211222
if (drv_data->cs_gpiods) {
1222-
struct gpio_desc *gpiod;
1223-
12241223
gpiod = drv_data->cs_gpiods[spi->chip_select];
12251224
if (gpiod) {
1226-
chip->gpio_cs = desc_to_gpio(gpiod);
1225+
chip->gpiod_cs = gpiod;
12271226
chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
12281227
gpiod_set_value(gpiod, chip->gpio_cs_inverted);
12291228
}
@@ -1237,8 +1236,10 @@ static int setup_cs(struct spi_device *spi, struct chip_data *chip,
12371236
/* NOTE: setup() can be called multiple times, possibly with
12381237
* different chip_info, release previously requested GPIO
12391238
*/
1240-
if (gpio_is_valid(chip->gpio_cs))
1241-
gpio_free(chip->gpio_cs);
1239+
if (chip->gpiod_cs) {
1240+
gpio_free(desc_to_gpio(chip->gpiod_cs));
1241+
chip->gpiod_cs = NULL;
1242+
}
12421243

12431244
/* If (*cs_control) is provided, ignore GPIO chip select */
12441245
if (chip_info->cs_control) {
@@ -1254,11 +1255,11 @@ static int setup_cs(struct spi_device *spi, struct chip_data *chip,
12541255
return err;
12551256
}
12561257

1257-
chip->gpio_cs = chip_info->gpio_cs;
1258+
gpiod = gpio_to_desc(chip_info->gpio_cs);
1259+
chip->gpiod_cs = gpiod;
12581260
chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
12591261

1260-
err = gpio_direction_output(chip->gpio_cs,
1261-
!chip->gpio_cs_inverted);
1262+
err = gpiod_direction_output(gpiod, !chip->gpio_cs_inverted);
12621263
}
12631264

12641265
return err;
@@ -1317,8 +1318,7 @@ static int setup(struct spi_device *spi)
13171318
}
13181319

13191320
chip->frm = spi->chip_select;
1320-
} else
1321-
chip->gpio_cs = -1;
1321+
}
13221322
chip->enable_dma = drv_data->master_info->enable_dma;
13231323
chip->timeout = TIMOUT_DFLT;
13241324
}
@@ -1416,8 +1416,8 @@ static void cleanup(struct spi_device *spi)
14161416
return;
14171417

14181418
if (drv_data->ssp_type != CE4100_SSP && !drv_data->cs_gpiods &&
1419-
gpio_is_valid(chip->gpio_cs))
1420-
gpio_free(chip->gpio_cs);
1419+
chip->gpiod_cs)
1420+
gpio_free(desc_to_gpio(chip->gpiod_cs));
14211421

14221422
kfree(chip);
14231423
}

drivers/spi/spi-pxa2xx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct chip_data {
8383
u16 lpss_tx_threshold;
8484
u8 enable_dma;
8585
union {
86-
int gpio_cs;
86+
struct gpio_desc *gpiod_cs;
8787
unsigned int frm;
8888
};
8989
int gpio_cs_inverted;

0 commit comments

Comments
 (0)