Re: [PATCH v5 1/2] spi/pl022: Add chip select handling via GPIO

From: Linus Walleij
Date: Wed Aug 22 2012 - 07:09:29 EST


On Tue, Aug 21, 2012 at 6:00 PM, Roland Stigge <stigge@xxxxxxxxx> wrote:

> This patch adds the ability for the driver to control the chip select directly.
> This enables independence from cs_control callbacks. Configurable via
> platform_data, to be extended as DT in the following patch.
>
> Based on the initial patch by Alexandre Pereira da Silva <aletes.xgr@xxxxxxxxx>
>
> Signed-off-by: Roland Stigge <stigge@xxxxxxxxx>

(...)
> /*
> * This macro is used to define some register default values.
> @@ -356,6 +357,8 @@ struct vendor_data {
> * @sgt_rx: scattertable for the RX transfer
> * @sgt_tx: scattertable for the TX transfer
> * @dummypage: a dummy page used for driving data on the bus with DMA
> + * @cur_cs: current chip select (gpio)
> + * @chipselect: list of chipselects (gpios)
> */
> struct pl022 {
> struct amba_device *adev;
> @@ -389,6 +392,8 @@ struct pl022 {
> char *dummypage;
> bool dma_running;
> #endif
> + int cur_cs;
> + int *chipselect;

Since this is an array, it should be named "chipselects" (plural).

(...)
> @@ -1840,8 +1852,9 @@ static int pl022_setup(struct spi_device
> chip->xfer_type = chip_info->com_mode;
> if (!chip_info->cs_control) {
> chip->cs_control = null_cs_control;
> - dev_warn(&spi->dev,
> - "chip select function is NULL for this chip\n");
> + if (!gpio_is_valid(pl022->chipselect[spi->chip_select]))
> + dev_warn(&spi->dev,
> + "chip select function is NULL for this chip\n");

This dev_warn() is wrong. Alter to a proper warning message.

> @@ -2016,6 +2030,7 @@ pl022_probe(struct amba_device *adev, co
> pl022->master_info = platform_info;
> pl022->adev = adev;
> pl022->vendor = id->data;
> + pl022->chipselect = (int *)&master[1];

That last thing looks pretty awkward, atleast a comment
explaining what is going on is necessary. I would have done
it like this:

/* Point chipselects to allocated memory beyond the main struct */
pl022->chipselects = (int *) pl022 + sizeof(struct pl022);

Maybe it's simpler to just devm_kzalloc() this array.

Thanks,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/