Skip to contentSkip to conversation

drm/panel: add s6e3ha2 AMOLED panel driver

PATCH Superseded Hyungwon Hwang 3 participants 3 messages Jan 27, 2015 – Feb 5, 2015

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 drm/panel: add s6e3ha2 AMOLED panel driver

From: Donghwa Lee <[email protected]>

This patch adds MIPI-DSI based S6E3HA2 panel driver. This panel has 1440x2560 resolution in 5.7-inch physical panel.

---
Changes for v2:
- Fix errata in documentation and source code comments Changes for v3:
- Remove the term LCD to clarify the sort of this panel
- Rename lcd-en-gpios to panel-en-gpios to clarify the sort of this panel
- Fix errata in documentation and source code comments

 .../devicetree/bindings/panel/samsung,s6e3ha2.txt  |  49 ++
 drivers/gpu/drm/panel/Kconfig                      |   6 +
 drivers/gpu/drm/panel/Makefile                     |   1 +
 drivers/gpu/drm/panel/panel-s6e3ha2.c              | 513 +++++++++++++++++++++
 4 files changed, 569 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/panel/samsung,s6e3ha2.txt
 create mode 100644 drivers/gpu/drm/panel/panel-s6e3ha2.c
Documentation/devicetree/bindings/panel/samsung,s6e3ha2.txt new file +49 -0
new file mode 100644
index 0000000..5210926
@@ -0,0 +1,49 @@
+Samsung S6E3HA2 5.7" 1440x2560 AMOLED panel
+
+Required properties:
+  - compatible: "samsung,s6e3ha2"
+  - reg: the virtual channel number of a DSI peripheral
+  - vdd3-supply: core voltage supply
+  - vci-supply: voltage supply for analog circuits
+  - reset-gpios: a GPIO spec for the reset pin
+  - panel-en-gpios: a GPIO spec for the panel enable pin
+  - te-gpios: a GPIO spec for the tearing effect synchronization signal gpio pin
+
+Optional properties:
+  - display-timings: timings for the connected panel as described by [1]
+  - panel-width-mm: physical panel width [mm]
+  - panel-height-mm: physical panel height [mm]
+
+The device node can contain one 'port' child node with one child
+'endpoint' node, according to the bindings defined in [2]. This
+node should describe panel's video bus.
+
+[1]: Documentation/devicetree/bindings/video/display-timing.txt
+[2]: Documentation/devicetree/bindings/media/video-interfaces.txt
+
+Example:
+
+panel@0 {
+	compatible = "samsung,s6e3ha2";
+	reg = <0>;
+	vdd3-supply = <&ldo27_reg>;
+	vci-supply = <&ldo28_reg>;
+	reset-gpios = <&gpg0 0 0>;
+	panel-en-gpios = <&gpf1 5 0>;
+	te-gpios = <&gpf1 3 1>;
+	panel-width-mm = <71>;
+	panel-height-mm = <125>;
+
+	display-timings {
+		timing-0 {
+			clock-frequency = <0>;
+			hactive = <1440>;
+			vactive = <2560>;
+			hfront-porch = <1>;
+			hback-porch = <1>;
+			hsync-len = <1>;
+			vfront-porch = <1>;
+			vback-porch = <15>;
+			vsync-len = <1>;
+		};
+	};
drivers/gpu/drm/panel/Kconfig +6 -0
index dec60b2..451b5f3 100644
@@ -46,4 +46,10 @@ config DRM_PANEL_S6E63J0X03
 	select DRM_MIPI_DSI
 	select VIDEOMODE_HELPERS
 
+config DRM_PANEL_S6E3HA2
+	tristate "S6E3HA2 DSI video mode panel"
+	depends on OF
+	select DRM_MIPI_DSI
+	select VIDEOMODE_HELPERS
+
 endmenu
drivers/gpu/drm/panel/Makefile +1 -0
index 6467be7..7bd7b84 100644
@@ -3,3 +3,4 @@ obj-$(CONFIG_DRM_PANEL_LD9040) += panel-ld9040.o
 obj-$(CONFIG_DRM_PANEL_S6E8AA0) += panel-s6e8aa0.o
 obj-$(CONFIG_DRM_PANEL_S6E63J0X03) += panel-s6e63j0x03.o
 obj-$(CONFIG_DRM_PANEL_SHARP_LQ101R1SX01) += panel-sharp-lq101r1sx01.o
+obj-$(CONFIG_DRM_PANEL_S6E3HA2) += panel-s6e3ha2.o
drivers/gpu/drm/panel/panel-s6e3ha2.c new file +513 -0

513 lines not on this page · raw message

--
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#1 lore raw
Quoted 30 lines · Hyungwon Hwang

From: Donghwa Lee <[email protected]>

This patch adds MIPI-DSI based S6E3HA2 panel driver. This panel has 1440x2560 resolution in 5.7-inch physical panel.

---
Changes for v2:
- Fix errata in documentation and source code comments Changes for v3:
- Remove the term LCD to clarify the sort of this panel
- Rename lcd-en-gpios to panel-en-gpios to clarify the sort of this panel
- Fix errata in documentation and source code comments

 .../devicetree/bindings/panel/samsung,s6e3ha2.txt  |  49 ++
 drivers/gpu/drm/panel/Kconfig                      |   6 +
 drivers/gpu/drm/panel/Makefile                     |   1 +
 drivers/gpu/drm/panel/panel-s6e3ha2.c              | 513 +++++++++++++++++++++
 4 files changed, 569 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/panel/samsung,s6e3ha2.txt
 create mode 100644 drivers/gpu/drm/panel/panel-s6e3ha2.c
Documentation/devicetree/bindings/panel/samsung,s6e3ha2.txt new file +0 -0
new file mode 100644
index 0000000..5210926

Documentation/devicetree/bindings/panel/samsung,s6e3ha2.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/panel/samsung,s6e3ha2.txt new file +9 -0
@@ -0,0 +1,49 @@
+Samsung S6E3HA2 5.7" 1440x2560 AMOLED panel
+
+Required properties:
+  - compatible: "samsung,s6e3ha2"
+  - reg: the virtual channel number of a DSI peripheral
+  - vdd3-supply: core voltage supply
+  - vci-supply: voltage supply for analog circuits
+  - reset-gpios: a GPIO spec for the reset pin
+  - panel-en-gpios: a GPIO spec for the panel enable pin

Why not "enable-gpios"? That would be much more in line with the reset-gpios property.

Documentation/devicetree/bindings/panel/samsung,s6e3ha2.txt line 10

Quoted 1 line
Documentation/devicetree/bindings/panel/samsung,s6e3ha2.txt new file +1 -0
+  - te-gpios: a GPIO spec for the tearing effect synchronization signal gpio pin

s/gpio/GPIO/

Documentation/devicetree/bindings/panel/samsung,s6e3ha2.txt line 15

Quoted 5 lines
Documentation/devicetree/bindings/panel/samsung,s6e3ha2.txt new file +5 -0
+
+Optional properties:
+  - display-timings: timings for the connected panel as described by [1]
+  - panel-width-mm: physical panel width [mm]
+  - panel-height-mm: physical panel height [mm]

If these are optional, what happens if they aren't there? The panel is not likely to work in that case.

Also I think these should be hard-coded in the driver, because they are implied by the "compatible" string.

Documentation/devicetree/bindings/panel/samsung,s6e3ha2.txt line 19

Quoted 3 lines
Documentation/devicetree/bindings/panel/samsung,s6e3ha2.txt new file +3 -0
+The device node can contain one 'port' child node with one child
+'endpoint' node, according to the bindings defined in [2]. This
+node should describe panel's video bus.

The example doesn't show how to use that, why is it necessary?

Quoted 1 line
drivers/gpu/drm/panel/panel-s6e3ha2.c +0 -0

[...]

Quoted 8 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +8 -0
+struct s6e3ha2 {
+	struct device *dev;
+	struct drm_panel panel;
+
+	struct regulator_bulk_data supplies[2];
+	struct gpio_desc *reset_gpio;
+	struct gpio_desc *panel_en_gpio;
+	struct videomode vm;

drivers/gpu/drm/panel/panel-s6e3ha2.c line 44

Quoted 10 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +10 -0
+	u32 width_mm;
+	u32 height_mm;
+
+	/* This field is tested by functions directly accessing DSI bus before
+	 * transfer, transfer is skipped if it is set. In case of transfer
+	 * failure or unexpected response the field is set to error value.
+	 * Such construct allows to eliminate many checks in higher level
+	 * functions.
+	 */
+	int error;

I hate myself for not NAK'ing the first patch that introduced this idiom stronger. I think it's a really bad concept and you're not doing yourself any favours by using it.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 227

Quoted 6 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +6 -0
+static void s6e3ha2_te_start_setting(struct s6e3ha2 *ctx)
+{
+	s6e3ha2_dcs_write_seq_static(ctx, 0xb9, 0x10, 0x09, 0xff, 0x00, 0x09);
+}
+
+

Gratuituous blank line.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 244

Quoted 3 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +3 -0
+static void s6e3ha2_panel_init(struct s6e3ha2 *ctx)
+{
+	s6e3ha2_dcs_write_seq_static(ctx, MIPI_DCS_EXIT_SLEEP_MODE);

We have a standard function for this, please use it.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 268

Quoted 2 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +2 -0
+	/* common setting */
+	s6e3ha2_dcs_write_seq_static(ctx, MIPI_DCS_SET_TEAR_ON);

Same here.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 294

Quoted 2 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +2 -0
+	s6e3ha2_test_key_off_f0(ctx);
+	s6e3ha2_dcs_write_seq_static(ctx, MIPI_DCS_SET_DISPLAY_ON);

And here.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 312

Quoted 6 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +6 -0
+static int s6e3ha2_unprepare(struct drm_panel *panel)
+{
+	struct s6e3ha2 *ctx = panel_to_s6e3ha2(panel);
+
+	s6e3ha2_dcs_write_seq_static(ctx, MIPI_DCS_ENTER_SLEEP_MODE);
+	s6e3ha2_dcs_write_seq_static(ctx, MIPI_DCS_SET_DISPLAY_OFF);

More standard functions.

Quoted 16 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +16 -0
+	msleep(40);
+
+	s6e3ha2_clear_error(ctx);
+
+	return s6e3ha2_power_off(ctx);
+}
+
+static int s6e3ha2_power_on(struct s6e3ha2 *ctx)
+{
+	int ret;
+
+	ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+	if (ret < 0)
+		return ret;
+
+	msleep(25);

drivers/gpu/drm/panel/panel-s6e3ha2.c line 338

Quoted 10 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +10 -0
+
+	gpiod_set_value(ctx->panel_en_gpio, 0);
+	usleep_range(5000, 6000);
+	gpiod_set_value(ctx->panel_en_gpio, 1);
+
+	gpiod_set_value(ctx->reset_gpio, 1);
+	usleep_range(5000, 6000);
+	gpiod_set_value(ctx->reset_gpio, 0);
+	usleep_range(5000, 6000);
+	gpiod_set_value(ctx->reset_gpio, 1);

I would expect the value after power on to be 0 for reset. Perhaps you need GPIO_ACTIVE_LOW in your device tree? Also why do you toggle thrice? I would assume that putting the peripheral into reset and taking it out again would be enough.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 353

Quoted 11 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +11 -0
+static int s6e3ha2_prepare(struct drm_panel *panel)
+{
+	struct s6e3ha2 *ctx = panel_to_s6e3ha2(panel);
+	int ret;
+
+	ret = s6e3ha2_power_on(ctx);
+	if (ret < 0)
+		return ret;
+
+	s6e3ha2_panel_init(ctx);
+	if (ctx->error < 0)

This is one of the reasons why ctx->error is a bad idea. It's completely unintuitive to check ctx->error here because nobody's actually setting it in this context.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 354

Quoted 1 line
drivers/gpu/drm/panel/panel-s6e3ha2.c +1 -0
+		s6e3ha2_unprepare(panel);

This is somewhat asymmetric. I would expect the s6e3ha2_panel_init() to undo what it did on failure, so that you would only have to call s6e3ha2_power_off() here and undo what you did in *this* function.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 362

Quoted 4 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +4 -0
+static int s6e3ha2_enable(struct drm_panel *panel)
+{
+	return 0;
+}

This is really where you're supposed to turn on the backlight or similar. Where does that happen?

Quoted 13 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +13 -0
+static int s6e3ha2_get_modes(struct drm_panel *panel)
+{
+	struct drm_connector *connector = panel->connector;
+	struct s6e3ha2 *ctx = panel_to_s6e3ha2(panel);
+	struct drm_display_mode *mode;
+
+	mode = drm_mode_create(connector->dev);
+	if (!mode) {
+		DRM_ERROR("failed to create a new display mode\n");
+		return 0;
+	}
+
+	drm_display_mode_from_videomode(&ctx->vm, mode);

drivers/gpu/drm/panel/panel-s6e3ha2.c line 386

Quoted 10 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +10 -0
+	mode->width_mm = ctx->width_mm;
+	mode->height_mm = ctx->height_mm;
+	connector->display_info.width_mm = mode->width_mm;
+	connector->display_info.height_mm = mode->height_mm;
+
+	mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+	drm_mode_probed_add(connector, mode);
+
+	return 1;
+}

Like I said before, the mode is implied by the compatible value, so no need to parse it from device tree.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 418

Quoted 7 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +7 -0
+static int s6e3ha2_probe(struct mipi_dsi_device *dsi)
+{
+	struct device *dev = &dsi->dev;
+	struct s6e3ha2 *ctx;
+	int ret;
+
+	ctx = devm_kzalloc(dev, sizeof(struct s6e3ha2), GFP_KERNEL);

sizeof(*ctx) is much shorter.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 450

Quoted 7 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +7 -0
+	ctx->reset_gpio = devm_gpiod_get(dev, "reset");
+	if (IS_ERR(ctx->reset_gpio)) {
+		dev_err(dev, "cannot get reset-gpios %ld\n",
+			PTR_ERR(ctx->reset_gpio));
+		return PTR_ERR(ctx->reset_gpio);
+	}
+	ret = gpiod_direction_output(ctx->reset_gpio, 1);

For consistency the above two lines should be separated by a blank line.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 462

Quoted 12 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +12 -0
+	if (ret < 0) {
+		dev_err(dev, "cannot configure reset-gpios %d\n", ret);
+		return ret;
+	}
+
+	ctx->panel_en_gpio = devm_gpiod_get(dev, "panel-en");
+	if (IS_ERR(ctx->panel_en_gpio)) {
+		dev_err(dev, "cannot get panel-en-gpios %ld\n",
+			PTR_ERR(ctx->panel_en_gpio));
+		return PTR_ERR(ctx->panel_en_gpio);
+	}
+	ret = gpiod_direction_output(ctx->panel_en_gpio, 1);

Same here.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 466

Quoted 4 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +4 -0
+	if (ret < 0) {
+		dev_err(dev, "cannot configure panel-en-gpios %d\n", ret);
+		return ret;
+	}

You seem to be turning on the panel here. That's wrong because you're supposed to wait for the display driver to tell you to turn it on via ->prepare() and ->enable().

drivers/gpu/drm/panel/panel-s6e3ha2.c line 470

Quoted 4 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +4 -0
+
+	drm_panel_init(&ctx->panel);
+	ctx->panel.dev = dev;
+	ctx->panel.funcs = &s6e3ha2_drm_funcs;

I don't see a use for the _drm in here.

Quoted 1 line

+static struct of_device_id s6e3ha2_of_match[] = {

static const, please.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 503

Quoted 10 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c +10 -0
+	{ .compatible = "samsung,s6e3ha2" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, s6e3ha2_of_match);
+
+static struct mipi_dsi_driver s6e3ha2_driver = {
+	.probe = s6e3ha2_probe,
+	.remove = s6e3ha2_remove,
+	.driver = {
+		.name = "panel_s6e3ha2",

Please use a - instead of an _ here, for consistency with other drivers.

drivers/gpu/drm/panel/panel-s6e3ha2.c line 504

Quoted 1 line
drivers/gpu/drm/panel/panel-s6e3ha2.c +1 -0
+		.owner = THIS_MODULE,

No need for this anymore.

Thierry

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

Hi Thierry,

Quoted 1 line · Thierry Reding

On Tue, Jan 27, 2015 at 10:48:32AM +0900, Hyungwon Hwang wrote:

(...)

Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c new file +4 -0
+
+	/* This field is tested by functions directly accessing DSI bus before
+	 * transfer, transfer is skipped if it is set. In case of transfer
+	 * failure or unexpected response the field is set to error value.
Quoted 8 lines

drivers/gpu/drm/panel/panel-s6e3ha2.c line 44

Quoted 4 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c new file +4 -0
+	 * Such construct allows to eliminate many checks in higher level
+	 * functions.
+	 */
+	int error;

I hate myself for not NAK'ing the first patch that introduced this idiom stronger. I think it's a really bad concept and you're not doing yourself any favours by using it.

The main favor of using it is much shorter code. The idiom eliminates redundant error checking in case of nested function calls - and this is quite common for panel drivers.

Moreover the same idiom is used also in other places. I have not dig too much but as I remember it is present at least in:
- V4L2 core: struct v4l2_ctrl_handler.error,
- fs/seq_file: struct seq_file overflow handling

(...)

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c new file +7 -0
+static int s6e3ha2_prepare(struct drm_panel *panel)
+{
+	struct s6e3ha2 *ctx = panel_to_s6e3ha2(panel);
+	int ret;
+
+	ret = s6e3ha2_power_on(ctx);
+	if (ret < 0)
Quoted 9 lines

drivers/gpu/drm/panel/panel-s6e3ha2.c line 353

Quoted 4 lines
drivers/gpu/drm/panel/panel-s6e3ha2.c new file +4 -0
+		return ret;
+
+	s6e3ha2_panel_init(ctx);
+	if (ctx->error < 0)

This is one of the reasons why ctx->error is a bad idea. It's completely unintuitive to check ctx->error here because nobody's actually setting it in this context.

But this is classical example of passing variable by reference. You pass ctx to s6e3ha2_panel_init to allow ctx modification. So the natural thing is to check after the call what was changed, for example by reading ctx->error.

The advantage of the idiom is that you are not obliged to do it now, it can be done later. In case of propagating error by return value you should check the error after every call and it results in much more bloated code.

Regards
Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel