Unverified Commit 6fc20a85 authored by Javier Martinez Canillas's avatar Javier Martinez Canillas
Browse files

drm/ssd130x: Use new regmap bulk write support to drop custom bus



Data writes for the ssd130x 4-wire SPI protocol need special handling, due
the Data/Command control (D/C) pin having to be toggled prior to the write.

The regmap API only allowed drivers to provide .reg_{read,write} callbacks
to do per register read/write, but didn't provide a way for drivers to do
the same for bulk read/writes.

For this reason, a custom regmap bus was used by the driver just to define
a bulk write callback that implements the D/C pin toggling. But the regmap
API has been extended to support defining bulk read/write handlers, so the
custom regmap bus is not needed anymore and could just be dropped.

Signed-off-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
Acked-by: default avatarSam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20220618174338.2253021-1-javierm@redhat.com
parent 53618649
Loading
Loading
Loading
Loading
+5 −16
Original line number Diff line number Diff line
@@ -18,11 +18,6 @@ struct ssd130x_spi_transport {
	struct gpio_desc *dc;
};

static const struct regmap_config ssd130x_spi_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
};

/*
 * The regmap bus .write handler, it is just a wrapper around spi_write()
 * but toggling the Data/Command control pin (D/C#). Since for 4-wire SPI
@@ -56,17 +51,12 @@ static int ssd130x_spi_read(void *context, const void *reg, size_t reg_size,
	return -EOPNOTSUPP;
}

/*
 * A custom bus is needed due the special write that toggles a D/C# pin,
 * another option could be to just have a .reg_write() callback but that
 * will prevent to do data writes in bulk.
 *
 * Once the regmap API is extended to support defining a bulk write handler
 * in the struct regmap_config, this can be simplified and the bus dropped.
 */
static struct regmap_bus regmap_ssd130x_spi_bus = {
static const struct regmap_config ssd130x_spi_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.write = ssd130x_spi_write,
	.read = ssd130x_spi_read,
	.can_multi_write = true,
};

static int ssd130x_spi_probe(struct spi_device *spi)
@@ -90,8 +80,7 @@ static int ssd130x_spi_probe(struct spi_device *spi)
	t->spi = spi;
	t->dc = dc;

	regmap = devm_regmap_init(dev, &regmap_ssd130x_spi_bus, t,
				  &ssd130x_spi_regmap_config);
	regmap = devm_regmap_init(dev, NULL, t, &ssd130x_spi_regmap_config);
	if (IS_ERR(regmap))
		return PTR_ERR(regmap);