Re: [PATCH v2 5/5] drm/solomon: Add SSD130x OLED displays SPI support

From: Geert Uytterhoeven
Date: Tue Apr 12 2022 - 05:29:52 EST


Hi Javier,

On Mon, Apr 11, 2022 at 11:12 PM Javier Martinez Canillas
<javierm@xxxxxxxxxx> wrote:
> The ssd130x driver only provides the core support for these devices but it
> does not have any bus transport logic. Add a driver to interface over SPI.
>
> There is a difference in the communication protocol when using 4-wire SPI
> instead of I2C. For the latter, a control byte that contains a D/C# field
> has to be sent. This field tells the controller whether the data has to be
> written to the command register or to the graphics display data memory.
>
> But for 4-wire SPI that control byte is not used, instead a real D/C# line
> must be pulled HIGH for commands data and LOW for graphics display data.
>
> For this reason the standard SPI regmap can't be used and a custom .write
> bus handler is needed.
>
> Signed-off-by: Javier Martinez Canillas <javierm@xxxxxxxxxx>
> Acked-by: Mark Brown <broonie@xxxxxxxxxx>

Thanks for your patch!

> --- /dev/null
> +++ b/drivers/gpu/drm/solomon/ssd130x-spi.c

> +static struct gpio_desc *ssd130x_spi_get_dc(struct device *dev)
> +{
> + struct gpio_desc *dc = devm_gpiod_get(dev, "dc", GPIOD_OUT_LOW);
> +
> + if (IS_ERR(dc))
> + return ERR_PTR(dev_err_probe(dev, PTR_ERR(dc), "Failed to get dc gpio\n"));
> +
> + return dc;
> +}
> +
> +static int ssd130x_spi_probe(struct spi_device *spi)
> +{
> + struct ssd130x_spi_transport *t;
> + struct ssd130x_device *ssd130x;
> + struct regmap *regmap;
> + struct device *dev = &spi->dev;
> +
> + t = devm_kzalloc(dev, sizeof(*t), GFP_KERNEL);
> + if (!t)
> + return dev_err_probe(dev, -ENOMEM,
> + "Failed to allocate SPI transport data\n");
> +
> + t->spi = spi;
> +
> + t->dc = ssd130x_spi_get_dc(&spi->dev);
> + if (IS_ERR(t->dc))
> + return PTR_ERR(t->dc);

This can be simplified (no need for the PTR_ERR(ERR_PTR(...) dance)
by open-coding ssd130x_spi_get_dc() here.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds