Skip to content

Commit 1209c55

Browse files
andy-shevbroonie
authored andcommitted
spi: Consistently use BIT for cs_index_mask
Some of the parts related to the chip select are using BIT() macro the rest are using plain numbers. Unify all of them to use BIT(). While at it, make the (repetitive) comment clearer when assigning cs_index_mask during SPI target device enumeration. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://msgid.link/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 9086d0f commit 1209c55

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

drivers/spi/spi.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ static inline bool spi_is_last_cs(struct spi_device *spi)
10211021
bool last = false;
10221022

10231023
for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
1024-
if ((spi->cs_index_mask >> idx) & 0x01) {
1024+
if (spi->cs_index_mask & BIT(idx)) {
10251025
if (spi->controller->last_cs[idx] == spi_get_chipselect(spi, idx))
10261026
last = true;
10271027
}
@@ -1072,8 +1072,7 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force)
10721072
* into account.
10731073
*/
10741074
for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
1075-
if (((spi->cs_index_mask >> idx) & 0x01) &&
1076-
spi_get_csgpiod(spi, idx)) {
1075+
if ((spi->cs_index_mask & BIT(idx)) && spi_get_csgpiod(spi, idx)) {
10771076
if (has_acpi_companion(&spi->dev))
10781077
gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx),
10791078
!enable);
@@ -2456,14 +2455,10 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
24562455
spi_set_chipselect(spi, idx, cs[idx]);
24572456

24582457
/*
2459-
* spi->chip_select[i] gives the corresponding physical CS for logical CS i
2460-
* logical CS number is represented by setting the ith bit in spi->cs_index_mask
2461-
* So, for example, if spi->cs_index_mask = 0x01 then logical CS number is 0 and
2462-
* spi->chip_select[0] will give the physical CS.
2463-
* By default spi->chip_select[0] will hold the physical CS number so, set
2464-
* spi->cs_index_mask as 0x01.
2458+
* By default spi->chip_select[0] will hold the physical CS number,
2459+
* so set bit 0 in spi->cs_index_mask.
24652460
*/
2466-
spi->cs_index_mask = 0x01;
2461+
spi->cs_index_mask = BIT(0);
24672462

24682463
/* Device speed */
24692464
if (!of_property_read_u32(nc, "spi-max-frequency", &value))
@@ -2587,14 +2582,10 @@ struct spi_device *spi_new_ancillary_device(struct spi_device *spi,
25872582
ancillary->max_speed_hz = spi->max_speed_hz;
25882583
ancillary->mode = spi->mode;
25892584
/*
2590-
* spi->chip_select[i] gives the corresponding physical CS for logical CS i
2591-
* logical CS number is represented by setting the ith bit in spi->cs_index_mask
2592-
* So, for example, if spi->cs_index_mask = 0x01 then logical CS number is 0 and
2593-
* spi->chip_select[0] will give the physical CS.
2594-
* By default spi->chip_select[0] will hold the physical CS number so, set
2595-
* spi->cs_index_mask as 0x01.
2585+
* By default spi->chip_select[0] will hold the physical CS number,
2586+
* so set bit 0 in spi->cs_index_mask.
25962587
*/
2597-
ancillary->cs_index_mask = 0x01;
2588+
ancillary->cs_index_mask = BIT(0);
25982589

25992590
WARN_ON(!mutex_is_locked(&ctlr->add_lock));
26002591

@@ -2841,14 +2832,10 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
28412832
spi->irq = lookup.irq;
28422833
spi->bits_per_word = lookup.bits_per_word;
28432834
/*
2844-
* spi->chip_select[i] gives the corresponding physical CS for logical CS i
2845-
* logical CS number is represented by setting the ith bit in spi->cs_index_mask
2846-
* So, for example, if spi->cs_index_mask = 0x01 then logical CS number is 0 and
2847-
* spi->chip_select[0] will give the physical CS.
2848-
* By default spi->chip_select[0] will hold the physical CS number so, set
2849-
* spi->cs_index_mask as 0x01.
2835+
* By default spi->chip_select[0] will hold the physical CS number,
2836+
* so set bit 0 in spi->cs_index_mask.
28502837
*/
2851-
spi->cs_index_mask = 0x01;
2838+
spi->cs_index_mask = BIT(0);
28522839

28532840
return spi;
28542841
}

0 commit comments

Comments
 (0)