@@ -745,6 +745,23 @@ int spi_add_device(struct spi_device *spi)
745
745
}
746
746
EXPORT_SYMBOL_GPL (spi_add_device );
747
747
748
+ static void spi_set_all_cs_unused (struct spi_device * spi )
749
+ {
750
+ u8 idx ;
751
+
752
+ /*
753
+ * Zero(0) is a valid physical CS value and can be located at any
754
+ * logical CS in the spi->chip_select[]. If all the physical CS
755
+ * are initialized to 0 then It would be difficult to differentiate
756
+ * between a valid physical CS 0 & an unused logical CS whose physical
757
+ * CS can be 0. As a solution to this issue initialize all the CS to 0xFF.
758
+ * Now all the unused logical CS will have 0xFF physical CS value & can be
759
+ * ignore while performing physical CS validity checks.
760
+ */
761
+ for (idx = 0 ; idx < SPI_CS_CNT_MAX ; idx ++ )
762
+ spi_set_chipselect (spi , idx , 0xFF );
763
+ }
764
+
748
765
/**
749
766
* spi_new_device - instantiate one new SPI device
750
767
* @ctlr: Controller to which device is connected
@@ -764,7 +781,6 @@ struct spi_device *spi_new_device(struct spi_controller *ctlr,
764
781
{
765
782
struct spi_device * proxy ;
766
783
int status ;
767
- u8 idx ;
768
784
769
785
/*
770
786
* NOTE: caller did any chip->bus_num checks necessary.
@@ -780,19 +796,10 @@ struct spi_device *spi_new_device(struct spi_controller *ctlr,
780
796
781
797
WARN_ON (strlen (chip -> modalias ) >= sizeof (proxy -> modalias ));
782
798
783
- /*
784
- * Zero(0) is a valid physical CS value and can be located at any
785
- * logical CS in the spi->chip_select[]. If all the physical CS
786
- * are initialized to 0 then It would be difficult to differentiate
787
- * between a valid physical CS 0 & an unused logical CS whose physical
788
- * CS can be 0. As a solution to this issue initialize all the CS to 0xFF.
789
- * Now all the unused logical CS will have 0xFF physical CS value & can be
790
- * ignore while performing physical CS validity checks.
791
- */
792
- for (idx = 0 ; idx < SPI_CS_CNT_MAX ; idx ++ )
793
- spi_set_chipselect (proxy , idx , 0xFF );
794
-
799
+ /* Use provided chip-select for proxy device */
800
+ spi_set_all_cs_unused (proxy );
795
801
spi_set_chipselect (proxy , 0 , chip -> chip_select );
802
+
796
803
proxy -> max_speed_hz = chip -> max_speed_hz ;
797
804
proxy -> mode = chip -> mode ;
798
805
proxy -> irq = chip -> irq ;
@@ -2418,17 +2425,7 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
2418
2425
return - EINVAL ;
2419
2426
}
2420
2427
2421
- /*
2422
- * Zero(0) is a valid physical CS value and can be located at any
2423
- * logical CS in the spi->chip_select[]. If all the physical CS
2424
- * are initialized to 0 then It would be difficult to differentiate
2425
- * between a valid physical CS 0 & an unused logical CS whose physical
2426
- * CS can be 0. As a solution to this issue initialize all the CS to 0xFF.
2427
- * Now all the unused logical CS will have 0xFF physical CS value & can be
2428
- * ignore while performing physical CS validity checks.
2429
- */
2430
- for (idx = 0 ; idx < SPI_CS_CNT_MAX ; idx ++ )
2431
- spi_set_chipselect (spi , idx , 0xFF );
2428
+ spi_set_all_cs_unused (spi );
2432
2429
2433
2430
/* Device address */
2434
2431
rc = of_property_read_variable_u32_array (nc , "reg" , & cs [0 ], 1 ,
@@ -2565,7 +2562,6 @@ struct spi_device *spi_new_ancillary_device(struct spi_device *spi,
2565
2562
struct spi_controller * ctlr = spi -> controller ;
2566
2563
struct spi_device * ancillary ;
2567
2564
int rc = 0 ;
2568
- u8 idx ;
2569
2565
2570
2566
/* Alloc an spi_device */
2571
2567
ancillary = spi_alloc_device (ctlr );
@@ -2576,19 +2572,8 @@ struct spi_device *spi_new_ancillary_device(struct spi_device *spi,
2576
2572
2577
2573
strscpy (ancillary -> modalias , "dummy" , sizeof (ancillary -> modalias ));
2578
2574
2579
- /*
2580
- * Zero(0) is a valid physical CS value and can be located at any
2581
- * logical CS in the spi->chip_select[]. If all the physical CS
2582
- * are initialized to 0 then It would be difficult to differentiate
2583
- * between a valid physical CS 0 & an unused logical CS whose physical
2584
- * CS can be 0. As a solution to this issue initialize all the CS to 0xFF.
2585
- * Now all the unused logical CS will have 0xFF physical CS value & can be
2586
- * ignore while performing physical CS validity checks.
2587
- */
2588
- for (idx = 0 ; idx < SPI_CS_CNT_MAX ; idx ++ )
2589
- spi_set_chipselect (ancillary , idx , 0xFF );
2590
-
2591
2575
/* Use provided chip-select for ancillary device */
2576
+ spi_set_all_cs_unused (ancillary );
2592
2577
spi_set_chipselect (ancillary , 0 , chip_select );
2593
2578
2594
2579
/* Take over SPI mode/speed from SPI main device */
@@ -2805,7 +2790,6 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
2805
2790
struct acpi_spi_lookup lookup = {};
2806
2791
struct spi_device * spi ;
2807
2792
int ret ;
2808
- u8 idx ;
2809
2793
2810
2794
if (!ctlr && index == -1 )
2811
2795
return ERR_PTR (- EINVAL );
@@ -2841,24 +2825,14 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
2841
2825
return ERR_PTR (- ENOMEM );
2842
2826
}
2843
2827
2844
- /*
2845
- * Zero(0) is a valid physical CS value and can be located at any
2846
- * logical CS in the spi->chip_select[]. If all the physical CS
2847
- * are initialized to 0 then It would be difficult to differentiate
2848
- * between a valid physical CS 0 & an unused logical CS whose physical
2849
- * CS can be 0. As a solution to this issue initialize all the CS to 0xFF.
2850
- * Now all the unused logical CS will have 0xFF physical CS value & can be
2851
- * ignore while performing physical CS validity checks.
2852
- */
2853
- for (idx = 0 ; idx < SPI_CS_CNT_MAX ; idx ++ )
2854
- spi_set_chipselect (spi , idx , 0xFF );
2828
+ spi_set_all_cs_unused (spi );
2829
+ spi_set_chipselect (spi , 0 , lookup .chip_select );
2855
2830
2856
2831
ACPI_COMPANION_SET (& spi -> dev , adev );
2857
2832
spi -> max_speed_hz = lookup .max_speed_hz ;
2858
2833
spi -> mode |= lookup .mode ;
2859
2834
spi -> irq = lookup .irq ;
2860
2835
spi -> bits_per_word = lookup .bits_per_word ;
2861
- spi_set_chipselect (spi , 0 , lookup .chip_select );
2862
2836
/*
2863
2837
* spi->chip_select[i] gives the corresponding physical CS for logical CS i
2864
2838
* logical CS number is represented by setting the ith bit in spi->cs_index_mask
0 commit comments