Commit 8f22c21d authored by Sam Ravnborg's avatar Sam Ravnborg
Browse files

drm/bridge: nxp-ptn3460: add drm_panel_bridge support



Prepare the bridge driver for use in a chained setup.

- Replacing direct use of drm_panel with drm_panel_bridge support.
- Make the connector creation optional

Note: the bridge panel will use the connector type from the panel.

v3:
  - Fix wrong logic in connector creation (Laurent)

v2:
  - Use panel_bridge for local variable name to align with other drivers
  - Fix that connector was created twice (Laurent)
  - Set bridge.type to DRM_MODE_CONNECTOR_LVDS.

Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Andrzej Hajda <a.hajda@samsung.com>
Cc: Neil Armstrong <narmstrong@baylibre.com>
Cc: Laurent Pinchart <Laurent.pinchart@ideasonboard.com>
Cc: Jonas Karlman <jonas@kwiboo.se>
Cc: Jernej Skrabec <jernej.skrabec@siol.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20200727170320.959777-6-sam@ravnborg.org
parent 4151c14c
Loading
Loading
Loading
Loading
+18 −40
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ struct ptn3460_bridge {
	struct drm_connector connector;
	struct i2c_client *client;
	struct drm_bridge bridge;
	struct drm_panel *panel;
	struct drm_bridge *panel_bridge;
	struct gpio_desc *gpio_pd_n;
	struct gpio_desc *gpio_rst_n;
	u32 edid_emulation;
@@ -126,11 +126,6 @@ static void ptn3460_pre_enable(struct drm_bridge *bridge)
	usleep_range(10, 20);
	gpiod_set_value(ptn_bridge->gpio_rst_n, 1);

	if (drm_panel_prepare(ptn_bridge->panel)) {
		DRM_ERROR("failed to prepare panel\n");
		return;
	}

	/*
	 * There's a bug in the PTN chip where it falsely asserts hotplug before
	 * it is fully functional. We're forced to wait for the maximum start up
@@ -145,16 +140,6 @@ static void ptn3460_pre_enable(struct drm_bridge *bridge)
	ptn_bridge->enabled = true;
}

static void ptn3460_enable(struct drm_bridge *bridge)
{
	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);

	if (drm_panel_enable(ptn_bridge->panel)) {
		DRM_ERROR("failed to enable panel\n");
		return;
	}
}

static void ptn3460_disable(struct drm_bridge *bridge)
{
	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
@@ -164,24 +149,10 @@ static void ptn3460_disable(struct drm_bridge *bridge)

	ptn_bridge->enabled = false;

	if (drm_panel_disable(ptn_bridge->panel)) {
		DRM_ERROR("failed to disable panel\n");
		return;
	}

	gpiod_set_value(ptn_bridge->gpio_rst_n, 1);
	gpiod_set_value(ptn_bridge->gpio_pd_n, 0);
}

static void ptn3460_post_disable(struct drm_bridge *bridge)
{
	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);

	if (drm_panel_unprepare(ptn_bridge->panel)) {
		DRM_ERROR("failed to unprepare panel\n");
		return;
	}
}

static struct edid *ptn3460_get_edid(struct drm_bridge *bridge,
				     struct drm_connector *connector)
@@ -247,10 +218,14 @@ static int ptn3460_bridge_attach(struct drm_bridge *bridge,
	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
	int ret;

	if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) {
		DRM_ERROR("Fix bridge driver to make connector optional!");
		return -EINVAL;
	}
	/* Let this driver create connector if requested */
	ret = drm_bridge_attach(bridge->encoder, ptn_bridge->panel_bridge,
				bridge, flags | DRM_BRIDGE_ATTACH_NO_CONNECTOR);
	if (ret < 0)
		return ret;

	if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)
		return 0;

	if (!bridge->encoder) {
		DRM_ERROR("Parent encoder object not found");
@@ -270,9 +245,6 @@ static int ptn3460_bridge_attach(struct drm_bridge *bridge,
	drm_connector_attach_encoder(&ptn_bridge->connector,
							bridge->encoder);

	if (ptn_bridge->panel)
		drm_panel_attach(ptn_bridge->panel, &ptn_bridge->connector);

	drm_helper_hpd_irq_event(ptn_bridge->connector.dev);

	return ret;
@@ -280,9 +252,7 @@ static int ptn3460_bridge_attach(struct drm_bridge *bridge,

static const struct drm_bridge_funcs ptn3460_bridge_funcs = {
	.pre_enable = ptn3460_pre_enable,
	.enable = ptn3460_enable,
	.disable = ptn3460_disable,
	.post_disable = ptn3460_post_disable,
	.attach = ptn3460_bridge_attach,
	.get_edid = ptn3460_get_edid,
};
@@ -292,6 +262,8 @@ static int ptn3460_probe(struct i2c_client *client,
{
	struct device *dev = &client->dev;
	struct ptn3460_bridge *ptn_bridge;
	struct drm_bridge *panel_bridge;
	struct drm_panel *panel;
	int ret;

	ptn_bridge = devm_kzalloc(dev, sizeof(*ptn_bridge), GFP_KERNEL);
@@ -299,10 +271,15 @@ static int ptn3460_probe(struct i2c_client *client,
		return -ENOMEM;
	}

	ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0, &ptn_bridge->panel, NULL);
	ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0, &panel, NULL);
	if (ret)
		return ret;

	panel_bridge = devm_drm_panel_bridge_add(dev, panel);
	if (IS_ERR(panel_bridge))
		return PTR_ERR(panel_bridge);

	ptn_bridge->panel_bridge = panel_bridge;
	ptn_bridge->client = client;

	ptn_bridge->gpio_pd_n = devm_gpiod_get(&client->dev, "powerdown",
@@ -334,6 +311,7 @@ static int ptn3460_probe(struct i2c_client *client,

	ptn_bridge->bridge.funcs = &ptn3460_bridge_funcs;
	ptn_bridge->bridge.ops = DRM_BRIDGE_OP_EDID;
	ptn_bridge->bridge.type = DRM_MODE_CONNECTOR_LVDS;
	ptn_bridge->bridge.of_node = dev->of_node;
	drm_bridge_add(&ptn_bridge->bridge);