Skip to content

Commit 9e264f3

Browse files
Amit Kumar Mahapatra via Alsa-develbroonie
authored andcommitted
spi: Replace all spi->chip_select and spi->cs_gpiod references with function call
Supporting multi-cs in spi drivers would require the chip_select & cs_gpiod members of struct spi_device to be an array. But changing the type of these members to array would break the spi driver functionality. To make the transition smoother introduced four new APIs to get/set the spi->chip_select & spi->cs_gpiod and replaced all spi->chip_select and spi->cs_gpiod references with get or set API calls. While adding multi-cs support in further patches the chip_select & cs_gpiod members of the spi_device structure would be converted to arrays & the "idx" parameter of the APIs would be used as array index i.e., spi->chip_select[idx] & spi->cs_gpiod[idx] respectively. Signed-off-by: Amit Kumar Mahapatra <[email protected]> Acked-by: Heiko Stuebner <[email protected]> # Rockchip drivers Reviewed-by: Michal Simek <[email protected]> Reviewed-by: Cédric Le Goater <[email protected]> # Aspeed driver Reviewed-by: Dhruva Gole <[email protected]> # SPI Cadence QSPI Reviewed-by: Patrice Chotard <[email protected]> # spi-stm32-qspi Acked-by: William Zhang <[email protected]> # bcm63xx-hsspi driver Reviewed-by: Serge Semin <[email protected]> # DW SSI part Link: https://lore.kernel.org/r/167847070432.26.15076794204368669839@mailman-core.alsa-project.org Signed-off-by: Mark Brown <[email protected]>
1 parent 21d19e6 commit 9e264f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+333
-328
lines changed

drivers/spi/spi-altera-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static void altera_spi_set_cs(struct spi_device *spi, bool is_high)
8080
altr_spi_writel(hw, ALTERA_SPI_TARGET_SEL, 0);
8181
} else {
8282
altr_spi_writel(hw, ALTERA_SPI_TARGET_SEL,
83-
BIT(spi->chip_select));
83+
BIT(spi_get_chipselect(spi, 0)));
8484
hw->imr |= ALTERA_SPI_CONTROL_SSO_MSK;
8585
altr_spi_writel(hw, ALTERA_SPI_CONTROL, hw->imr);
8686
}

drivers/spi/spi-amd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static inline int amd_spi_fifo_xfer(struct amd_spi *amd_spi,
347347
case AMD_SPI_V1:
348348
break;
349349
case AMD_SPI_V2:
350-
amd_spi_clear_chip(amd_spi, message->spi->chip_select);
350+
amd_spi_clear_chip(amd_spi, spi_get_chipselect(message->spi, 0));
351351
break;
352352
default:
353353
return -ENODEV;
@@ -364,7 +364,7 @@ static int amd_spi_master_transfer(struct spi_master *master,
364364
struct amd_spi *amd_spi = spi_master_get_devdata(master);
365365
struct spi_device *spi = msg->spi;
366366

367-
amd_spi_select_chip(amd_spi, spi->chip_select);
367+
amd_spi_select_chip(amd_spi, spi_get_chipselect(spi, 0));
368368

369369
/*
370370
* Extract spi_transfers from the spi message and

drivers/spi/spi-ar934x.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static int ar934x_spi_transfer_one_message(struct spi_controller *ctlr,
125125
iowrite32(reg, sp->base + AR934X_SPI_DATAOUT);
126126
}
127127

128-
reg = AR934X_SPI_SHIFT_VAL(spi->chip_select, term,
128+
reg = AR934X_SPI_SHIFT_VAL(spi_get_chipselect(spi, 0), term,
129129
trx_cur * 8);
130130
iowrite32(reg, sp->base + AR934X_SPI_REG_SHIFT_CTRL);
131131
stat = readl_poll_timeout(

drivers/spi/spi-armada-3700.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ static void a3700_spi_set_cs(struct spi_device *spi, bool enable)
437437
struct a3700_spi *a3700_spi = spi_controller_get_devdata(spi->controller);
438438

439439
if (!enable)
440-
a3700_spi_activate_cs(a3700_spi, spi->chip_select);
440+
a3700_spi_activate_cs(a3700_spi, spi_get_chipselect(spi, 0));
441441
else
442-
a3700_spi_deactivate_cs(a3700_spi, spi->chip_select);
442+
a3700_spi_deactivate_cs(a3700_spi, spi_get_chipselect(spi, 0));
443443
}
444444

445445
static void a3700_spi_header_set(struct a3700_spi *a3700_spi)

drivers/spi/spi-aspeed-smc.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ static const struct aspeed_spi_data ast2400_spi_data;
296296
static int do_aspeed_spi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
297297
{
298298
struct aspeed_spi *aspi = spi_controller_get_devdata(mem->spi->master);
299-
struct aspeed_spi_chip *chip = &aspi->chips[mem->spi->chip_select];
299+
struct aspeed_spi_chip *chip = &aspi->chips[spi_get_chipselect(mem->spi, 0)];
300300
u32 addr_mode, addr_mode_backup;
301301
u32 ctl_val;
302302
int ret = 0;
@@ -377,7 +377,8 @@ static const char *aspeed_spi_get_name(struct spi_mem *mem)
377377
struct aspeed_spi *aspi = spi_controller_get_devdata(mem->spi->master);
378378
struct device *dev = aspi->dev;
379379

380-
return devm_kasprintf(dev, GFP_KERNEL, "%s.%d", dev_name(dev), mem->spi->chip_select);
380+
return devm_kasprintf(dev, GFP_KERNEL, "%s.%d", dev_name(dev),
381+
spi_get_chipselect(mem->spi, 0));
381382
}
382383

383384
struct aspeed_spi_window {
@@ -553,7 +554,7 @@ static int aspeed_spi_do_calibration(struct aspeed_spi_chip *chip);
553554
static int aspeed_spi_dirmap_create(struct spi_mem_dirmap_desc *desc)
554555
{
555556
struct aspeed_spi *aspi = spi_controller_get_devdata(desc->mem->spi->master);
556-
struct aspeed_spi_chip *chip = &aspi->chips[desc->mem->spi->chip_select];
557+
struct aspeed_spi_chip *chip = &aspi->chips[spi_get_chipselect(desc->mem->spi, 0)];
557558
struct spi_mem_op *op = &desc->info.op_tmpl;
558559
u32 ctl_val;
559560
int ret = 0;
@@ -620,7 +621,7 @@ static ssize_t aspeed_spi_dirmap_read(struct spi_mem_dirmap_desc *desc,
620621
u64 offset, size_t len, void *buf)
621622
{
622623
struct aspeed_spi *aspi = spi_controller_get_devdata(desc->mem->spi->master);
623-
struct aspeed_spi_chip *chip = &aspi->chips[desc->mem->spi->chip_select];
624+
struct aspeed_spi_chip *chip = &aspi->chips[spi_get_chipselect(desc->mem->spi, 0)];
624625

625626
/* Switch to USER command mode if mapping window is too small */
626627
if (chip->ahb_window_size < offset + len) {
@@ -670,7 +671,7 @@ static int aspeed_spi_setup(struct spi_device *spi)
670671
{
671672
struct aspeed_spi *aspi = spi_controller_get_devdata(spi->master);
672673
const struct aspeed_spi_data *data = aspi->data;
673-
unsigned int cs = spi->chip_select;
674+
unsigned int cs = spi_get_chipselect(spi, 0);
674675
struct aspeed_spi_chip *chip = &aspi->chips[cs];
675676

676677
chip->aspi = aspi;
@@ -697,7 +698,7 @@ static int aspeed_spi_setup(struct spi_device *spi)
697698
static void aspeed_spi_cleanup(struct spi_device *spi)
698699
{
699700
struct aspeed_spi *aspi = spi_controller_get_devdata(spi->master);
700-
unsigned int cs = spi->chip_select;
701+
unsigned int cs = spi_get_chipselect(spi, 0);
701702

702703
aspeed_spi_chip_enable(aspi, cs, false);
703704

drivers/spi/spi-at91-usart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ static int at91_usart_spi_setup(struct spi_device *spi)
390390

391391
dev_dbg(&spi->dev,
392392
"setup: bpw %u mode 0x%x -> mr %d %08x\n",
393-
spi->bits_per_word, spi->mode, spi->chip_select, mr);
393+
spi->bits_per_word, spi->mode, spi_get_chipselect(spi, 0), mr);
394394

395395
return 0;
396396
}

drivers/spi/spi-ath79.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static void ath79_spi_chipselect(struct spi_device *spi, int is_active)
7171
{
7272
struct ath79_spi *sp = ath79_spidev_to_sp(spi);
7373
int cs_high = (spi->mode & SPI_CS_HIGH) ? is_active : !is_active;
74-
u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select);
74+
u32 cs_bit = AR71XX_SPI_IOC_CS(spi_get_chipselect(spi, 0));
7575

7676
if (cs_high)
7777
sp->ioc_base |= cs_bit;
@@ -140,7 +140,7 @@ static int ath79_exec_mem_op(struct spi_mem *mem,
140140
struct ath79_spi *sp = ath79_spidev_to_sp(mem->spi);
141141

142142
/* Ensures that reading is performed on device connected to hardware cs0 */
143-
if (mem->spi->chip_select || mem->spi->cs_gpiod)
143+
if (spi_get_chipselect(mem->spi, 0) || spi_get_csgpiod(mem->spi, 0))
144144
return -ENOTSUPP;
145145

146146
/* Only use for fast-read op. */

drivers/spi/spi-atmel.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,10 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
327327
int chip_select;
328328
u32 mr;
329329

330-
if (spi->cs_gpiod)
330+
if (spi_get_csgpiod(spi, 0))
331331
chip_select = as->native_cs_for_gpio;
332332
else
333-
chip_select = spi->chip_select;
333+
chip_select = spi_get_chipselect(spi, 0);
334334

335335
if (atmel_spi_is_v2(as)) {
336336
spi_writel(as, CSR0 + 4 * chip_select, asd->csr);
@@ -378,10 +378,10 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
378378
int chip_select;
379379
u32 mr;
380380

381-
if (spi->cs_gpiod)
381+
if (spi_get_csgpiod(spi, 0))
382382
chip_select = as->native_cs_for_gpio;
383383
else
384-
chip_select = spi->chip_select;
384+
chip_select = spi_get_chipselect(spi, 0);
385385

386386
/* only deactivate *this* device; sometimes transfers to
387387
* another device may be active when this routine is called.
@@ -394,7 +394,7 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
394394

395395
dev_dbg(&spi->dev, "DEactivate NPCS, mr %08x\n", mr);
396396

397-
if (!spi->cs_gpiod)
397+
if (!spi_get_csgpiod(spi, 0))
398398
spi_writel(as, CR, SPI_BIT(LASTXFER));
399399
}
400400

@@ -800,10 +800,10 @@ static int atmel_spi_set_xfer_speed(struct atmel_spi *as,
800800
unsigned long bus_hz;
801801
int chip_select;
802802

803-
if (spi->cs_gpiod)
803+
if (spi_get_csgpiod(spi, 0))
804804
chip_select = as->native_cs_for_gpio;
805805
else
806-
chip_select = spi->chip_select;
806+
chip_select = spi_get_chipselect(spi, 0);
807807

808808
/* v1 chips start out at half the peripheral bus speed. */
809809
bus_hz = as->spi_clk;
@@ -1189,7 +1189,7 @@ static int atmel_spi_setup(struct spi_device *spi)
11891189
as = spi_controller_get_devdata(spi->controller);
11901190

11911191
/* see notes above re chipselect */
1192-
if (!spi->cs_gpiod && (spi->mode & SPI_CS_HIGH)) {
1192+
if (!spi_get_csgpiod(spi, 0) && (spi->mode & SPI_CS_HIGH)) {
11931193
dev_warn(&spi->dev, "setup: non GPIO CS can't be active-high\n");
11941194
return -EINVAL;
11951195
}
@@ -1201,24 +1201,24 @@ static int atmel_spi_setup(struct spi_device *spi)
12011201
*/
12021202
initialize_native_cs_for_gpio(as);
12031203

1204-
if (spi->cs_gpiod && as->native_cs_free) {
1204+
if (spi_get_csgpiod(spi, 0) && as->native_cs_free) {
12051205
dev_err(&spi->dev,
12061206
"No native CS available to support this GPIO CS\n");
12071207
return -EBUSY;
12081208
}
12091209

1210-
if (spi->cs_gpiod)
1210+
if (spi_get_csgpiod(spi, 0))
12111211
chip_select = as->native_cs_for_gpio;
12121212
else
1213-
chip_select = spi->chip_select;
1213+
chip_select = spi_get_chipselect(spi, 0);
12141214

12151215
csr = SPI_BF(BITS, bits - 8);
12161216
if (spi->mode & SPI_CPOL)
12171217
csr |= SPI_BIT(CPOL);
12181218
if (!(spi->mode & SPI_CPHA))
12191219
csr |= SPI_BIT(NCPHA);
12201220

1221-
if (!spi->cs_gpiod)
1221+
if (!spi_get_csgpiod(spi, 0))
12221222
csr |= SPI_BIT(CSAAT);
12231223
csr |= SPI_BF(DLYBS, 0);
12241224

@@ -1244,7 +1244,7 @@ static int atmel_spi_setup(struct spi_device *spi)
12441244

12451245
dev_dbg(&spi->dev,
12461246
"setup: bpw %u mode 0x%x -> csr%d %08x\n",
1247-
bits, spi->mode, spi->chip_select, csr);
1247+
bits, spi->mode, spi_get_chipselect(spi, 0), csr);
12481248

12491249
if (!atmel_spi_is_v2(as))
12501250
spi_writel(as, CSR0 + 4 * chip_select, csr);

drivers/spi/spi-au1550.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static void au1550_spi_chipsel(struct spi_device *spi, int value)
166166
switch (value) {
167167
case BITBANG_CS_INACTIVE:
168168
if (hw->pdata->deactivate_cs)
169-
hw->pdata->deactivate_cs(hw->pdata, spi->chip_select,
169+
hw->pdata->deactivate_cs(hw->pdata, spi_get_chipselect(spi, 0),
170170
cspol);
171171
break;
172172

@@ -211,7 +211,7 @@ static void au1550_spi_chipsel(struct spi_device *spi, int value)
211211
} while ((stat & PSC_SPISTAT_DR) == 0);
212212

213213
if (hw->pdata->activate_cs)
214-
hw->pdata->activate_cs(hw->pdata, spi->chip_select,
214+
hw->pdata->activate_cs(hw->pdata, spi_get_chipselect(spi, 0),
215215
cspol);
216216
break;
217217
}

drivers/spi/spi-axi-spi-engine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static void spi_engine_gen_cs(struct spi_engine_program *p, bool dry,
193193
unsigned int mask = 0xff;
194194

195195
if (assert)
196-
mask ^= BIT(spi->chip_select);
196+
mask ^= BIT(spi_get_chipselect(spi, 0));
197197

198198
spi_engine_program_add_cmd(p, dry, SPI_ENGINE_CMD_ASSERT(1, mask));
199199
}

drivers/spi/spi-bcm-qspi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ static int write_to_hw(struct bcm_qspi *qspi, struct spi_device *spi)
986986
if (has_bspi(qspi))
987987
mspi_cdram &= ~1;
988988
else
989-
mspi_cdram |= (~(1 << spi->chip_select) &
989+
mspi_cdram |= (~(1 << spi_get_chipselect(spi, 0)) &
990990
MSPI_CDRAM_PCS);
991991

992992
write_cdram_slot(qspi, slot, mspi_cdram);
@@ -1046,8 +1046,8 @@ static int bcm_qspi_bspi_exec_mem_op(struct spi_device *spi,
10461046
return -EIO;
10471047

10481048
from = op->addr.val;
1049-
if (!spi->cs_gpiod)
1050-
bcm_qspi_chip_select(qspi, spi->chip_select);
1049+
if (!spi_get_csgpiod(spi, 0))
1050+
bcm_qspi_chip_select(qspi, spi_get_chipselect(spi, 0));
10511051
bcm_qspi_write(qspi, MSPI, MSPI_WRITE_LOCK, 0);
10521052

10531053
/*
@@ -1126,8 +1126,8 @@ static int bcm_qspi_transfer_one(struct spi_master *master,
11261126
int slots;
11271127
unsigned long timeo = msecs_to_jiffies(100);
11281128

1129-
if (!spi->cs_gpiod)
1130-
bcm_qspi_chip_select(qspi, spi->chip_select);
1129+
if (!spi_get_csgpiod(spi, 0))
1130+
bcm_qspi_chip_select(qspi, spi_get_chipselect(spi, 0));
11311131
qspi->trans_pos.trans = trans;
11321132
qspi->trans_pos.byte = 0;
11331133

drivers/spi/spi-bcm2835.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,9 +1274,9 @@ static int bcm2835_spi_setup(struct spi_device *spi)
12741274
* The SPI core has successfully requested the CS GPIO line from the
12751275
* device tree, so we are done.
12761276
*/
1277-
if (spi->cs_gpiod)
1277+
if (spi_get_csgpiod(spi, 0))
12781278
return 0;
1279-
if (spi->chip_select > 1) {
1279+
if (spi_get_chipselect(spi, 0) > 1) {
12801280
/* error in the case of native CS requested with CS > 1
12811281
* officially there is a CS2, but it is not documented
12821282
* which GPIO is connected with that...
@@ -1301,18 +1301,19 @@ static int bcm2835_spi_setup(struct spi_device *spi)
13011301
if (!chip)
13021302
return 0;
13031303

1304-
spi->cs_gpiod = gpiochip_request_own_desc(chip, 8 - spi->chip_select,
1305-
DRV_NAME,
1306-
GPIO_LOOKUP_FLAGS_DEFAULT,
1307-
GPIOD_OUT_LOW);
1308-
if (IS_ERR(spi->cs_gpiod)) {
1309-
ret = PTR_ERR(spi->cs_gpiod);
1304+
spi_set_csgpiod(spi, 0, gpiochip_request_own_desc(chip,
1305+
8 - (spi_get_chipselect(spi, 0)),
1306+
DRV_NAME,
1307+
GPIO_LOOKUP_FLAGS_DEFAULT,
1308+
GPIOD_OUT_LOW));
1309+
if (IS_ERR(spi_get_csgpiod(spi, 0))) {
1310+
ret = PTR_ERR(spi_get_csgpiod(spi, 0));
13101311
goto err_cleanup;
13111312
}
13121313

13131314
/* and set up the "mode" and level */
13141315
dev_info(&spi->dev, "setting up native-CS%i to use GPIO\n",
1315-
spi->chip_select);
1316+
spi_get_chipselect(spi, 0));
13161317

13171318
return 0;
13181319

drivers/spi/spi-bcm2835aux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ static int bcm2835aux_spi_setup(struct spi_device *spi)
448448
if (spi->mode & SPI_NO_CS)
449449
return 0;
450450

451-
if (spi->cs_gpiod)
451+
if (spi_get_csgpiod(spi, 0))
452452
return 0;
453453

454454
/* for dt-backwards compatibility: only support native on CS0
@@ -465,7 +465,7 @@ static int bcm2835aux_spi_setup(struct spi_device *spi)
465465
dev_warn(&spi->dev,
466466
"Native CS is not supported - please configure cs-gpio in device-tree\n");
467467

468-
if (spi->chip_select == 0)
468+
if (spi_get_chipselect(spi, 0) == 0)
469469
return 0;
470470

471471
dev_warn(&spi->dev, "Native CS is not working for cs > 0\n");

0 commit comments

Comments
 (0)