diff mbox series

drm/bridge: ti-sn65dsi83: Add a sysfs entry for the pattern generator

Message ID 20220708140009.1665714-1-festevam@gmail.com (mailing list archive)
State New, archived
Headers show
Series drm/bridge: ti-sn65dsi83: Add a sysfs entry for the pattern generator | expand

Commit Message

Fabio Estevam July 8, 2022, 2 p.m. UTC
From: Fabio Estevam <festevam@denx.de>

The sn65dsi83 chip has a test pattern generator capability.

Add a sysfs entry to allow enabling and disabling it in runtime.

This is helpful during the MIPI DSI/LVDS bringup.

To enable the test pattern generator:

echo 1 >  /sys/bus/i2c/devices/0-002c/pattern_generator

To disable the test pattern generator:

echo 0 >  /sys/bus/i2c/devices/0-002c/pattern_generator

Signed-off-by: Fabio Estevam <festevam@denx.de>
---
 drivers/gpu/drm/bridge/ti-sn65dsi83.c | 42 +++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

Comments

Marek Vasut July 8, 2022, 2:03 p.m. UTC | #1
On 7/8/22 16:00, Fabio Estevam wrote:
> From: Fabio Estevam <festevam@denx.de>
> 
> The sn65dsi83 chip has a test pattern generator capability.
> 
> Add a sysfs entry to allow enabling and disabling it in runtime.
> 
> This is helpful during the MIPI DSI/LVDS bringup.
> 
> To enable the test pattern generator:
> 
> echo 1 >  /sys/bus/i2c/devices/0-002c/pattern_generator
> 
> To disable the test pattern generator:
> 
> echo 0 >  /sys/bus/i2c/devices/0-002c/pattern_generator

I have more of a design question here:
- Shouldn't we implement some sort of standardized helper to set test
   pattern on various other bridges ? There are other bridges which do
   support test pattern generation too.
- The API should be able to select different test patterns, since some
   bridges support more than one.

Thoughts ?
diff mbox series

Patch

diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi83.c b/drivers/gpu/drm/bridge/ti-sn65dsi83.c
index 14e7aa77e758..bb94b3fe9b17 100644
--- a/drivers/gpu/drm/bridge/ti-sn65dsi83.c
+++ b/drivers/gpu/drm/bridge/ti-sn65dsi83.c
@@ -731,6 +731,47 @@  static const struct of_device_id sn65dsi83_match_table[] = {
 };
 MODULE_DEVICE_TABLE(of, sn65dsi83_match_table);
 
+static ssize_t pattern_generator_store(struct device *dev,
+					struct device_attribute *attr,
+					const char *buf, size_t len)
+{
+	struct sn65dsi83 *ctx = dev_get_drvdata(dev);
+	bool arg;
+	int ret;
+
+	ret  = kstrtobool(buf, &arg);
+	if (ret < 0)
+		return ret;
+
+	ret = regmap_write(ctx->regmap, REG_VID_CHA_TEST_PATTERN, arg ? 0x10 : 0x00);
+	if (ret < 0)
+		return ret;
+
+	return len;
+}
+
+static ssize_t pattern_generator_show(struct device *dev,
+				       struct device_attribute *attr, char *buf)
+{
+	struct sn65dsi83 *ctx = dev_get_drvdata(dev);
+	int ret, test_pattern;
+
+	ret = regmap_read(ctx->regmap, REG_VID_CHA_TEST_PATTERN, &test_pattern);
+	if (ret < 0)
+		return ret;
+
+	return sprintf(buf, "%d\n", !!test_pattern);
+}
+
+static DEVICE_ATTR_RW(pattern_generator);
+
+static struct attribute *sn65dsi83_attrs[] = {
+	&dev_attr_pattern_generator.attr,
+	NULL,
+};
+
+ATTRIBUTE_GROUPS(sn65dsi83);
+
 static struct i2c_driver sn65dsi83_driver = {
 	.probe = sn65dsi83_probe,
 	.remove = sn65dsi83_remove,
@@ -738,6 +779,7 @@  static struct i2c_driver sn65dsi83_driver = {
 	.driver = {
 		.name = "sn65dsi83",
 		.of_match_table = sn65dsi83_match_table,
+		.dev_groups = sn65dsi83_groups,
 	},
 };
 module_i2c_driver(sn65dsi83_driver);