3232#include <linux/scatterlist.h>
3333#include <linux/pm_runtime.h>
3434#include <linux/gpio.h>
35- #include <linux/of_gpio .h>
35+ #include <linux/of .h>
3636#include <linux/pinctrl/consumer.h>
3737
3838/*
@@ -362,8 +362,8 @@ struct vendor_data {
362362 * @sgt_tx: scattertable for the TX transfer
363363 * @dummypage: a dummy page used for driving data on the bus with DMA
364364 * @dma_running: indicates whether DMA is in operation
365- * @cur_cs: current chip select (gpio)
366- * @chipselects: list of chipselects (gpios)
365+ * @cur_cs: current chip select index
366+ * @cur_gpio: current chip select GPIO line
367367 */
368368struct pl022 {
369369 struct amba_device * adev ;
@@ -398,7 +398,7 @@ struct pl022 {
398398 bool dma_running ;
399399#endif
400400 int cur_cs ;
401- int * chipselects ;
401+ int cur_gpio ;
402402};
403403
404404/**
@@ -454,8 +454,8 @@ static void pl022_cs_control(struct pl022 *pl022, u32 command)
454454{
455455 if (pl022 -> vendor -> internal_cs_ctrl )
456456 internal_cs_control (pl022 , command );
457- else if (gpio_is_valid (pl022 -> cur_cs ))
458- gpio_set_value (pl022 -> cur_cs , command );
457+ else if (gpio_is_valid (pl022 -> cur_gpio ))
458+ gpio_set_value (pl022 -> cur_gpio , command );
459459}
460460
461461/**
@@ -1580,7 +1580,9 @@ static int pl022_transfer_one_message(struct spi_master *master,
15801580
15811581 /* Setup the SPI using the per chip configuration */
15821582 pl022 -> cur_chip = spi_get_ctldata (msg -> spi );
1583- pl022 -> cur_cs = pl022 -> chipselects [msg -> spi -> chip_select ];
1583+ pl022 -> cur_cs = msg -> spi -> chip_select ;
1584+ /* This is always available but may be set to -ENOENT */
1585+ pl022 -> cur_gpio = msg -> spi -> cs_gpio ;
15841586
15851587 restore_state (pl022 );
15861588 flush (pl022 );
@@ -1923,8 +1925,6 @@ static int pl022_setup(struct spi_device *spi)
19231925
19241926 /* Now set controller state based on controller data */
19251927 chip -> xfer_type = chip_info -> com_mode ;
1926- if (!gpio_is_valid (pl022 -> chipselects [spi -> chip_select ]))
1927- dev_warn (& spi -> dev , "invalid chip select\n" );
19281928
19291929 /* Check bits per word with vendor specific range */
19301930 if ((bits <= 3 ) || (bits > pl022 -> vendor -> max_bpw )) {
@@ -2072,7 +2072,6 @@ pl022_platform_data_dt_get(struct device *dev)
20722072{
20732073 struct device_node * np = dev -> of_node ;
20742074 struct pl022_ssp_controller * pd ;
2075- u32 tmp = 0 ;
20762075
20772076 if (!np ) {
20782077 dev_err (dev , "no dt node defined\n" );
@@ -2085,8 +2084,6 @@ pl022_platform_data_dt_get(struct device *dev)
20852084
20862085 pd -> bus_id = -1 ;
20872086 pd -> enable_dma = 1 ;
2088- of_property_read_u32 (np , "num-cs" , & tmp );
2089- pd -> num_chipselect = tmp ;
20902087 of_property_read_u32 (np , "pl022,autosuspend-delay" ,
20912088 & pd -> autosuspend_delay );
20922089 pd -> rt = of_property_read_bool (np , "pl022,rt" );
@@ -2101,8 +2098,7 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
21012098 dev_get_platdata (& adev -> dev );
21022099 struct spi_master * master ;
21032100 struct pl022 * pl022 = NULL ; /*Data for this driver */
2104- struct device_node * np = adev -> dev .of_node ;
2105- int status = 0 , i , num_cs ;
2101+ int status = 0 ;
21062102
21072103 dev_info (& adev -> dev ,
21082104 "ARM PL022 driver, device ID: 0x%08x\n" , adev -> periphid );
@@ -2114,13 +2110,6 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
21142110 return - ENODEV ;
21152111 }
21162112
2117- if (platform_info -> num_chipselect ) {
2118- num_cs = platform_info -> num_chipselect ;
2119- } else {
2120- dev_err (dev , "probe: no chip select defined\n" );
2121- return - ENODEV ;
2122- }
2123-
21242113 /* Allocate master with space for data */
21252114 master = spi_alloc_master (dev , sizeof (struct pl022 ));
21262115 if (master == NULL ) {
@@ -2133,19 +2122,12 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
21332122 pl022 -> master_info = platform_info ;
21342123 pl022 -> adev = adev ;
21352124 pl022 -> vendor = id -> data ;
2136- pl022 -> chipselects = devm_kcalloc (dev , num_cs , sizeof (int ),
2137- GFP_KERNEL );
2138- if (!pl022 -> chipselects ) {
2139- status = - ENOMEM ;
2140- goto err_no_mem ;
2141- }
21422125
21432126 /*
21442127 * Bus Number Which has been Assigned to this SSP controller
21452128 * on this board
21462129 */
21472130 master -> bus_num = platform_info -> bus_id ;
2148- master -> num_chipselect = num_cs ;
21492131 master -> cleanup = pl022_cleanup ;
21502132 master -> setup = pl022_setup ;
21512133 master -> auto_runtime_pm = true;
@@ -2154,36 +2136,6 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
21542136 master -> rt = platform_info -> rt ;
21552137 master -> dev .of_node = dev -> of_node ;
21562138
2157- if (platform_info -> num_chipselect && platform_info -> chipselects ) {
2158- for (i = 0 ; i < num_cs ; i ++ )
2159- pl022 -> chipselects [i ] = platform_info -> chipselects [i ];
2160- } else if (pl022 -> vendor -> internal_cs_ctrl ) {
2161- for (i = 0 ; i < num_cs ; i ++ )
2162- pl022 -> chipselects [i ] = i ;
2163- } else if (IS_ENABLED (CONFIG_OF )) {
2164- for (i = 0 ; i < num_cs ; i ++ ) {
2165- int cs_gpio = of_get_named_gpio (np , "cs-gpios" , i );
2166-
2167- if (cs_gpio == - EPROBE_DEFER ) {
2168- status = - EPROBE_DEFER ;
2169- goto err_no_gpio ;
2170- }
2171-
2172- pl022 -> chipselects [i ] = cs_gpio ;
2173-
2174- if (gpio_is_valid (cs_gpio )) {
2175- if (devm_gpio_request (dev , cs_gpio , "ssp-pl022" ))
2176- dev_err (& adev -> dev ,
2177- "could not request %d gpio\n" ,
2178- cs_gpio );
2179- else if (gpio_direction_output (cs_gpio , 1 ))
2180- dev_err (& adev -> dev ,
2181- "could not set gpio %d as output\n" ,
2182- cs_gpio );
2183- }
2184- }
2185- }
2186-
21872139 /*
21882140 * Supports mode 0-3, loopback, and active low CS. Transfers are
21892141 * always MS bit first on the original pl022.
@@ -2286,8 +2238,6 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
22862238 err_no_ioremap :
22872239 amba_release_regions (adev );
22882240 err_no_ioregion :
2289- err_no_gpio :
2290- err_no_mem :
22912241 spi_master_put (master );
22922242 return status ;
22932243}
0 commit comments