1
0
Fork 0

spi: clps711x: Use SPI-core "cs_gpios" property for storing GPIOs

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Mark Brown <broonie@linaro.org>
hifive-unleashed-5.1
Alexander Shiyan 2014-02-02 10:59:50 +04:00 committed by Mark Brown
parent 8dda9d9a48
commit 3e9ea4b4d5
1 changed files with 14 additions and 17 deletions

View File

@ -34,17 +34,12 @@ struct spi_clps711x_data {
u8 *rx_buf; u8 *rx_buf;
unsigned int bpw; unsigned int bpw;
int len; int len;
int chipselect[0];
}; };
static int spi_clps711x_setup(struct spi_device *spi) static int spi_clps711x_setup(struct spi_device *spi)
{ {
struct spi_clps711x_data *hw = spi_master_get_devdata(spi->master);
/* We are expect that SPI-device is not selected */ /* We are expect that SPI-device is not selected */
gpio_direction_output(hw->chipselect[spi->chip_select], gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
!(spi->mode & SPI_CS_HIGH));
return 0; return 0;
} }
@ -85,7 +80,6 @@ static int spi_clps711x_transfer_one_message(struct spi_master *master,
struct spi_clps711x_data *hw = spi_master_get_devdata(master); struct spi_clps711x_data *hw = spi_master_get_devdata(master);
struct spi_device *spi = msg->spi; struct spi_device *spi = msg->spi;
struct spi_transfer *xfer; struct spi_transfer *xfer;
int cs = hw->chipselect[spi->chip_select];
spi_clps711x_setup_mode(spi); spi_clps711x_setup_mode(spi);
@ -94,7 +88,7 @@ static int spi_clps711x_transfer_one_message(struct spi_master *master,
spi_clps711x_setup_xfer(spi, xfer); spi_clps711x_setup_xfer(spi, xfer);
gpio_set_value(cs, !!(spi->mode & SPI_CS_HIGH)); gpio_set_value(spi->cs_gpio, !!(spi->mode & SPI_CS_HIGH));
reinit_completion(&hw->done); reinit_completion(&hw->done);
@ -115,7 +109,7 @@ static int spi_clps711x_transfer_one_message(struct spi_master *master,
if (xfer->cs_change || if (xfer->cs_change ||
list_is_last(&xfer->transfer_list, &msg->transfers)) list_is_last(&xfer->transfer_list, &msg->transfers))
gpio_set_value(cs, !(spi->mode & SPI_CS_HIGH)); gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
msg->actual_length += xfer->len; msg->actual_length += xfer->len;
} }
@ -164,12 +158,15 @@ static int spi_clps711x_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
master = spi_alloc_master(&pdev->dev, master = spi_alloc_master(&pdev->dev, sizeof(*hw));
sizeof(struct spi_clps711x_data) + if (!master)
sizeof(int) * pdata->num_chipselect);
if (!master) {
dev_err(&pdev->dev, "SPI allocating memory error\n");
return -ENOMEM; return -ENOMEM;
master->cs_gpios = devm_kzalloc(&pdev->dev, sizeof(int) *
pdata->num_chipselect, GFP_KERNEL);
if (!master->cs_gpios) {
ret = -ENOMEM;
goto err_out;
} }
master->bus_num = pdev->id; master->bus_num = pdev->id;
@ -182,13 +179,13 @@ static int spi_clps711x_probe(struct platform_device *pdev)
hw = spi_master_get_devdata(master); hw = spi_master_get_devdata(master);
for (i = 0; i < master->num_chipselect; i++) { for (i = 0; i < master->num_chipselect; i++) {
hw->chipselect[i] = pdata->chipselect[i]; master->cs_gpios[i] = pdata->chipselect[i];
if (!gpio_is_valid(hw->chipselect[i])) { if (!gpio_is_valid(master->cs_gpios[i])) {
dev_err(&pdev->dev, "Invalid CS GPIO %i\n", i); dev_err(&pdev->dev, "Invalid CS GPIO %i\n", i);
ret = -EINVAL; ret = -EINVAL;
goto err_out; goto err_out;
} }
if (devm_gpio_request(&pdev->dev, hw->chipselect[i], NULL)) { if (devm_gpio_request(&pdev->dev, master->cs_gpios[i], NULL)) {
dev_err(&pdev->dev, "Can't get CS GPIO %i\n", i); dev_err(&pdev->dev, "Can't get CS GPIO %i\n", i);
ret = -EINVAL; ret = -EINVAL;
goto err_out; goto err_out;