Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: spi-gpio: store chipselect information in private structure

The spi-gpio driver currently assumes the chipselect gpio number is
stored in ->controller_data of the device's static board information.

In devicetree environments, this information is unavailable and has to
be derived from the DT node.

This patch moves the gpio storage to the controller's private data so
the DT bindings can easily build upon the driver.

Signed-off-by: Daniel Mack <zonque@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

authored by

Daniel Mack and committed by
Mark Brown
161c2dd3 9a2a5245

+24 -10
+24 -10
drivers/spi/spi-gpio.c
··· 46 46 struct spi_bitbang bitbang; 47 47 struct spi_gpio_platform_data pdata; 48 48 struct platform_device *pdev; 49 + int cs_gpios[0]; 49 50 }; 50 51 51 52 /*----------------------------------------------------------------------*/ ··· 90 89 91 90 /*----------------------------------------------------------------------*/ 92 91 93 - static inline const struct spi_gpio_platform_data * __pure 94 - spi_to_pdata(const struct spi_device *spi) 92 + static inline struct spi_gpio * __pure 93 + spi_to_spi_gpio(const struct spi_device *spi) 95 94 { 96 95 const struct spi_bitbang *bang; 97 - const struct spi_gpio *spi_gpio; 96 + struct spi_gpio *spi_gpio; 98 97 99 98 bang = spi_master_get_devdata(spi->master); 100 99 spi_gpio = container_of(bang, struct spi_gpio, bitbang); 101 - return &spi_gpio->pdata; 100 + return spi_gpio; 101 + } 102 + 103 + static inline struct spi_gpio_platform_data * __pure 104 + spi_to_pdata(const struct spi_device *spi) 105 + { 106 + return &spi_to_spi_gpio(spi)->pdata; 102 107 } 103 108 104 109 /* this is #defined to avoid unused-variable warnings when inlining */ ··· 217 210 218 211 static void spi_gpio_chipselect(struct spi_device *spi, int is_active) 219 212 { 220 - unsigned long cs = (unsigned long) spi->controller_data; 213 + struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); 214 + unsigned int cs = spi_gpio->cs_gpios[spi->chip_select]; 221 215 222 216 /* set initial clock polarity */ 223 217 if (is_active) ··· 232 224 233 225 static int spi_gpio_setup(struct spi_device *spi) 234 226 { 235 - unsigned long cs = (unsigned long) spi->controller_data; 236 - int status = 0; 227 + unsigned int cs = (unsigned int) spi->controller_data; 228 + int status = 0; 229 + struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); 237 230 238 231 if (spi->bits_per_word > 32) 239 232 return -EINVAL; ··· 248 239 !(spi->mode & SPI_CS_HIGH)); 249 240 } 250 241 } 251 - if (!status) 242 + if (!status) { 252 243 status = spi_bitbang_setup(spi); 244 + spi_gpio->cs_gpios[spi->chip_select] = cs; 245 + } 246 + 253 247 if (status) { 254 248 if (!spi->controller_state && cs != SPI_GPIO_NO_CHIPSELECT) 255 249 gpio_free(cs); ··· 262 250 263 251 static void spi_gpio_cleanup(struct spi_device *spi) 264 252 { 265 - unsigned long cs = (unsigned long) spi->controller_data; 253 + struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); 254 + unsigned int cs = spi_gpio->cs_gpios[spi->chip_select]; 266 255 267 256 if (cs != SPI_GPIO_NO_CHIPSELECT) 268 257 gpio_free(cs); ··· 344 331 if (status < 0) 345 332 return status; 346 333 347 - master = spi_alloc_master(&pdev->dev, sizeof *spi_gpio); 334 + master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) + 335 + (sizeof(int) * SPI_N_CHIPSEL)); 348 336 if (!master) { 349 337 status = -ENOMEM; 350 338 goto gpio_free;