[RFC 6/7] drm: atmel-hlcdc: move to DPI

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Replace atmel output implementation with the DPI host implementation, which
will prevent adding support for new kind of slave devices (encoders,
 panels, ...).

Call mipi_dpi_host_apply_format in CRTC commit to apply the newly selected
video bus format to use on the DPI bus.

Signed-off-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxxxxxxx>
---
 drivers/gpu/drm/atmel-hlcdc/Makefile             |   1 -
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c   |  11 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c     |  12 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.h     |   6 +-
 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c | 443 -----------------------
 5 files changed, 17 insertions(+), 456 deletions(-)
 delete mode 100644 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c

diff --git a/drivers/gpu/drm/atmel-hlcdc/Makefile b/drivers/gpu/drm/atmel-hlcdc/Makefile
index 979e431..83bdc37 100644
--- a/drivers/gpu/drm/atmel-hlcdc/Makefile
+++ b/drivers/gpu/drm/atmel-hlcdc/Makefile
@@ -2,7 +2,6 @@ atmel-hlcdc-dc-y := atmel_hlcdc_crtc.o \
 		atmel_hlcdc_dc.o \
 		atmel_hlcdc_dpi.o \
 		atmel_hlcdc_layer.o \
-		atmel_hlcdc_output.o \
 		atmel_hlcdc_plane.o
 
 obj-$(CONFIG_DRM_ATMEL_HLCDC)	+= atmel-hlcdc-dc.o
diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c
index 9f2a056..dda4e7e 100644
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c
+++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c
@@ -218,14 +218,17 @@ int atmel_hlcdc_crtc_mode_set_base(struct drm_crtc *c, int x, int y,
 					  mode->vdisplay << 16);
 }
 
-static void atmel_hlcdc_crtc_prepare(struct drm_crtc *crtc)
+static void atmel_hlcdc_crtc_prepare(struct drm_crtc *c)
 {
-	atmel_hlcdc_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
+	atmel_hlcdc_crtc_dpms(c, DRM_MODE_DPMS_OFF);
 }
 
-static void atmel_hlcdc_crtc_commit(struct drm_crtc *crtc)
+static void atmel_hlcdc_crtc_commit(struct drm_crtc *c)
 {
-	atmel_hlcdc_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
+	struct atmel_hlcdc_crtc *crtc = drm_crtc_to_atmel_hlcdc_crtc(c);
+
+	mipi_dpi_host_apply_format(crtc->dc->dpi);
+	atmel_hlcdc_crtc_dpms(c, DRM_MODE_DPMS_ON);
 }
 
 static bool atmel_hlcdc_crtc_mode_fixup(struct drm_crtc *crtc,
diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c
index 70c8808..1e799b8 100644
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c
+++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c
@@ -233,12 +233,6 @@ static int atmel_hlcdc_dc_modeset_init(struct drm_device *dev)
 
 	drm_mode_config_init(dev);
 
-	ret = atmel_hlcdc_create_outputs(dev);
-	if (ret) {
-		dev_err(dev->dev, "failed to create panel: %d\n", ret);
-		return ret;
-	}
-
 	planes = atmel_hlcdc_create_planes(dev);
 	if (IS_ERR(planes)) {
 		dev_err(dev->dev, "failed to create planes\n");
@@ -258,6 +252,12 @@ static int atmel_hlcdc_dc_modeset_init(struct drm_device *dev)
 		dc->layers[planes->overlays[i]->layer.desc->id] =
 						&planes->overlays[i]->layer;
 
+	ret = atmel_hlcdc_dpi_create(dev);
+	if (ret) {
+		dev_err(dev->dev, "failed to create DPI host\n");
+		return ret;
+	}
+
 	ret = atmel_hlcdc_crtc_create(dev);
 	if (ret) {
 		dev_err(dev->dev, "failed to create crtc\n");
diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.h b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.h
index 8194152..24a4ee7 100644
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.h
+++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.h
@@ -30,6 +30,7 @@
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_gem_cma_helper.h>
+#include <drm/drm_mipi_dpi.h>
 #include <drm/drm_panel.h>
 #include <drm/drmP.h>
 
@@ -176,6 +177,7 @@ struct atmel_hlcdc_dc {
 	struct atmel_hlcdc *hlcdc;
 	struct drm_fbdev_cma *fbdev;
 	struct drm_crtc *crtc;
+	struct mipi_dpi_host *dpi;
 	struct atmel_hlcdc_planes *planes;
 	struct atmel_hlcdc_layer *layers[ATMEL_HLCDC_MAX_LAYERS];
 	struct workqueue_struct *wq;
@@ -196,6 +198,8 @@ int atmel_hlcdc_plane_prepare_update_req(struct drm_plane *p,
 int atmel_hlcdc_plane_apply_update_req(struct drm_plane *p,
 				struct atmel_hlcdc_plane_update_req *req);
 
+int atmel_hlcdc_dpi_create(struct drm_device *dev);
+
 void atmel_hlcdc_crtc_irq(struct drm_crtc *c);
 
 void atmel_hlcdc_crtc_cancel_page_flip(struct drm_crtc *crtc,
@@ -203,8 +207,6 @@ void atmel_hlcdc_crtc_cancel_page_flip(struct drm_crtc *crtc,
 
 int atmel_hlcdc_crtc_create(struct drm_device *dev);
 
-int atmel_hlcdc_create_outputs(struct drm_device *dev);
-
 struct atmel_hlcdc_pwm_chip *atmel_hlcdc_pwm_create(struct drm_device *dev,
 						    struct clk *slow_clk,
 						    struct clk *sys_clk,
diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c
deleted file mode 100644
index 8d3a5cb..0000000
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c
+++ /dev/null
@@ -1,443 +0,0 @@
-/*
- * Copyright (C) 2014 Traphandler
- * Copyright (C) 2014 Free Electrons
- * Copyright (C) 2014 Atmel
- *
- * Author: Jean-Jacques Hiblot <jjhiblot@xxxxxxxxxxxxxxx>
- * Author: Boris BREZILLON <boris.brezillon@xxxxxxxxxxxxxxxxxx>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <linux/of_graph.h>
-
-#include <drm/drmP.h>
-#include <drm/drm_panel.h>
-
-#include "atmel_hlcdc_dc.h"
-
-/**
- * Atmel HLCDC RGB output mode
- */
-enum atmel_hlcdc_connector_rgb_mode {
-	ATMEL_HLCDC_CONNECTOR_RGB444,
-	ATMEL_HLCDC_CONNECTOR_RGB565,
-	ATMEL_HLCDC_CONNECTOR_RGB666,
-	ATMEL_HLCDC_CONNECTOR_RGB888,
-};
-
-struct atmel_hlcdc_slave;
-
-/**
- * Atmel HLCDC Slave device operations structure
- *
- * This structure defines an abstraction to be implemented by each slave
- * device type (panel, convertors, ...).
- *
- * @enable: Enable the slave device
- * @disable: Disable the slave device
- * @get_modes: retrieve modes supported by the slave device
- * @destroy: detroy the slave device and all associated data
- */
-struct atmel_hlcdc_slave_ops {
-	int (*enable)(struct atmel_hlcdc_slave *slave);
-	int (*disable)(struct atmel_hlcdc_slave *slave);
-	int (*get_modes)(struct atmel_hlcdc_slave *slave);
-	int (*mode_valid)(struct atmel_hlcdc_slave *slave,
-			  struct drm_display_mode *mode);
-	void (*destroy)(struct atmel_hlcdc_slave *slave);
-};
-
-/**
- * Atmel HLCDC Slave device structure
- *
- * This structure is the base slave device structure to be overloaded by
- * each slave device implementation.
- *
- * @ops: slave device operations
- */
-struct atmel_hlcdc_slave {
-	const struct atmel_hlcdc_slave_ops *ops;
-};
-
-/**
- * Atmel HLCDC Panel device structure
- *
- * This structure is specialization of the slave device structure to
- * interface with drm panels.
- *
- * @slave: base slave device fields
- * @panel: drm panel attached to this slave device
- */
-struct atmel_hlcdc_panel {
-	struct atmel_hlcdc_slave slave;
-	struct drm_panel *panel;
-};
-
-static inline struct atmel_hlcdc_panel *
-atmel_hlcdc_slave_to_panel(struct atmel_hlcdc_slave *slave)
-{
-	return container_of(slave, struct atmel_hlcdc_panel, slave);
-}
-
-/**
- * Atmel HLCDC RGB connector structure
- *
- * This structure stores informations about an DRM panel connected through
- * the RGB connector.
- *
- * @connector: DRM connector
- * @encoder: DRM encoder
- * @hlcdc: pointer to the atmel_hlcdc structure provided by the MFD device
- * @slave: slave device connected to this output
- * @endpoint: DT endpoint representing this output
- * @dpms: current DPMS mode
- */
-struct atmel_hlcdc_rgb_output {
-	struct drm_connector connector;
-	struct drm_encoder encoder;
-	struct atmel_hlcdc_dc *dc;
-	struct atmel_hlcdc_slave *slave;
-	struct of_endpoint endpoint;
-	int dpms;
-};
-
-static inline struct atmel_hlcdc_rgb_output *
-drm_connector_to_atmel_hlcdc_rgb_output(struct drm_connector *connector)
-{
-	return container_of(connector, struct atmel_hlcdc_rgb_output,
-			    connector);
-}
-
-static inline struct atmel_hlcdc_rgb_output *
-drm_encoder_to_atmel_hlcdc_rgb_output(struct drm_encoder *encoder)
-{
-	return container_of(encoder, struct atmel_hlcdc_rgb_output, encoder);
-}
-
-static int atmel_hlcdc_panel_enable(struct atmel_hlcdc_slave *slave)
-{
-	struct atmel_hlcdc_panel *panel = atmel_hlcdc_slave_to_panel(slave);
-
-	return drm_panel_enable(panel->panel);
-}
-
-static int atmel_hlcdc_panel_disable(struct atmel_hlcdc_slave *slave)
-{
-	struct atmel_hlcdc_panel *panel = atmel_hlcdc_slave_to_panel(slave);
-
-	return drm_panel_disable(panel->panel);
-}
-
-static int atmel_hlcdc_panel_get_modes(struct atmel_hlcdc_slave *slave)
-{
-	struct atmel_hlcdc_panel *panel = atmel_hlcdc_slave_to_panel(slave);
-
-	return panel->panel->funcs->get_modes(panel->panel);
-}
-
-static int atmel_hlcdc_panel_mode_valid(struct atmel_hlcdc_slave *slave,
-					struct drm_display_mode *mode)
-{
-	return MODE_OK;
-}
-
-static void atmel_hlcdc_panel_destroy(struct atmel_hlcdc_slave *slave)
-{
-	struct atmel_hlcdc_panel *panel = atmel_hlcdc_slave_to_panel(slave);
-
-	drm_panel_detach(panel->panel);
-	kfree(panel);
-}
-
-static const struct atmel_hlcdc_slave_ops atmel_hlcdc_panel_ops = {
-	.enable = atmel_hlcdc_panel_enable,
-	.disable = atmel_hlcdc_panel_disable,
-	.get_modes = atmel_hlcdc_panel_get_modes,
-	.mode_valid = atmel_hlcdc_panel_mode_valid,
-	.destroy = atmel_hlcdc_panel_destroy,
-};
-
-static struct atmel_hlcdc_slave *
-atmel_hlcdc_panel_detect(struct atmel_hlcdc_rgb_output *rgb)
-{
-	struct device_node *np;
-	struct drm_panel *p = NULL;
-	struct atmel_hlcdc_panel *panel;
-
-	np = of_graph_get_remote_port_parent(rgb->endpoint.local_node);
-	if (!np)
-		return NULL;
-
-	p = of_drm_find_panel(np);
-	of_node_put(np);
-
-	if (p) {
-		panel = kzalloc(sizeof(*panel), GFP_KERNEL);
-		if (!panel)
-			return NULL;
-
-		drm_panel_attach(p, &rgb->connector);
-		panel->panel = p;
-		panel->slave.ops = &atmel_hlcdc_panel_ops;
-		return &panel->slave;
-	}
-
-	return NULL;
-}
-
-static void atmel_hlcdc_rgb_encoder_dpms(struct drm_encoder *encoder,
-					 int mode)
-{
-	struct atmel_hlcdc_rgb_output *rgb =
-			drm_encoder_to_atmel_hlcdc_rgb_output(encoder);
-
-	if (mode != DRM_MODE_DPMS_ON)
-		mode = DRM_MODE_DPMS_OFF;
-
-	if (mode == rgb->dpms)
-		return;
-
-	if (mode != DRM_MODE_DPMS_ON)
-		rgb->slave->ops->disable(rgb->slave);
-	else
-		rgb->slave->ops->enable(rgb->slave);
-
-	rgb->dpms = mode;
-}
-
-static bool
-atmel_hlcdc_rgb_encoder_mode_fixup(struct drm_encoder *encoder,
-				   const struct drm_display_mode *mode,
-				   struct drm_display_mode *adjusted)
-{
-	return true;
-}
-
-static void atmel_hlcdc_rgb_encoder_prepare(struct drm_encoder *encoder)
-{
-	atmel_hlcdc_rgb_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
-}
-
-static void atmel_hlcdc_rgb_encoder_commit(struct drm_encoder *encoder)
-{
-	atmel_hlcdc_rgb_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
-}
-
-static void
-atmel_hlcdc_rgb_encoder_mode_set(struct drm_encoder *encoder,
-				 struct drm_display_mode *mode,
-				 struct drm_display_mode *adjusted)
-{
-	struct atmel_hlcdc_rgb_output *rgb =
-			drm_encoder_to_atmel_hlcdc_rgb_output(encoder);
-	struct drm_display_info *info = &rgb->connector.display_info;
-	unsigned int cfg;
-
-	cfg = 0;
-
-	if (info->num_bus_formats) {
-		switch (info->bus_formats[0]) {
-		case VIDEO_BUS_FMT_RGB565_1X16:
-			cfg |= ATMEL_HLCDC_CONNECTOR_RGB565 << 8;
-			break;
-		case VIDEO_BUS_FMT_RGB666_1X18:
-			cfg |= ATMEL_HLCDC_CONNECTOR_RGB666 << 8;
-			break;
-		case VIDEO_BUS_FMT_RGB888_1X24:
-			cfg |= ATMEL_HLCDC_CONNECTOR_RGB888 << 8;
-			break;
-		case VIDEO_BUS_FMT_RGB444_1X12:
-		default:
-			break;
-		}
-	}
-
-	regmap_update_bits(rgb->dc->hlcdc->regmap, ATMEL_HLCDC_CFG(5),
-			   ATMEL_HLCDC_MODE_MASK,
-			   cfg);
-}
-
-static struct drm_encoder_helper_funcs atmel_hlcdc_rgb_encoder_helper_funcs = {
-	.dpms = atmel_hlcdc_rgb_encoder_dpms,
-	.mode_fixup = atmel_hlcdc_rgb_encoder_mode_fixup,
-	.prepare = atmel_hlcdc_rgb_encoder_prepare,
-	.commit = atmel_hlcdc_rgb_encoder_commit,
-	.mode_set = atmel_hlcdc_rgb_encoder_mode_set,
-};
-
-static void atmel_hlcdc_rgb_encoder_destroy(struct drm_encoder *encoder)
-{
-	drm_encoder_cleanup(encoder);
-	memset(encoder, 0, sizeof(*encoder));
-}
-
-static const struct drm_encoder_funcs atmel_hlcdc_rgb_encoder_funcs = {
-	.destroy = atmel_hlcdc_rgb_encoder_destroy,
-};
-
-static int atmel_hlcdc_rgb_get_modes(struct drm_connector *connector)
-{
-	struct atmel_hlcdc_rgb_output *rgb =
-			drm_connector_to_atmel_hlcdc_rgb_output(connector);
-
-	return rgb->slave->ops->get_modes(rgb->slave);
-}
-
-static int atmel_hlcdc_rgb_mode_valid(struct drm_connector *connector,
-				      struct drm_display_mode *mode)
-{
-	struct atmel_hlcdc_rgb_output *rgb =
-			drm_connector_to_atmel_hlcdc_rgb_output(connector);
-	int ret;
-
-	ret = atmel_hlcdc_dc_mode_valid(rgb->dc, mode);
-	if (ret != MODE_OK)
-		return ret;
-
-	return rgb->slave->ops->mode_valid(rgb->slave, mode);
-}
-
-static struct drm_encoder *
-atmel_hlcdc_rgb_best_encoder(struct drm_connector *connector)
-{
-	struct atmel_hlcdc_rgb_output *rgb =
-			drm_connector_to_atmel_hlcdc_rgb_output(connector);
-
-	return &rgb->encoder;
-}
-
-static struct drm_connector_helper_funcs atmel_hlcdc_rgb_connector_helper_funcs = {
-	.get_modes = atmel_hlcdc_rgb_get_modes,
-	.mode_valid = atmel_hlcdc_rgb_mode_valid,
-	.best_encoder = atmel_hlcdc_rgb_best_encoder,
-};
-
-static enum drm_connector_status
-atmel_hlcdc_rgb_connector_detect(struct drm_connector *connector, bool force)
-{
-	struct atmel_hlcdc_rgb_output *rgb =
-			drm_connector_to_atmel_hlcdc_rgb_output(connector);
-
-	if (!rgb->slave) {
-		/* At the moment we only support panel devices */
-		rgb->slave = atmel_hlcdc_panel_detect(rgb);
-	}
-
-	if (rgb->slave)
-		return connector_status_connected;
-
-	return connector_status_unknown;
-}
-
-static void
-atmel_hlcdc_rgb_connector_destroy(struct drm_connector *connector)
-{
-	struct atmel_hlcdc_rgb_output *rgb =
-			drm_connector_to_atmel_hlcdc_rgb_output(connector);
-
-	if (rgb->slave && rgb->slave->ops->destroy)
-		rgb->slave->ops->destroy(rgb->slave);
-
-	drm_connector_unregister(&rgb->connector);
-	drm_connector_cleanup(connector);
-}
-
-static const struct drm_connector_funcs atmel_hlcdc_rgb_connector_funcs = {
-	.dpms = drm_helper_connector_dpms,
-	.detect = atmel_hlcdc_rgb_connector_detect,
-	.fill_modes = drm_helper_probe_single_connector_modes,
-	.destroy = atmel_hlcdc_rgb_connector_destroy,
-};
-
-static int atmel_hlcdc_create_output(struct drm_device *dev,
-				     struct of_endpoint *ep)
-{
-	struct atmel_hlcdc_dc *dc = dev->dev_private;
-	struct atmel_hlcdc_rgb_output *rgb;
-	int ret;
-
-	rgb = devm_kzalloc(dev->dev, sizeof(*rgb), GFP_KERNEL);
-	if (!rgb)
-		return -ENOMEM;
-
-	rgb->endpoint = *ep;
-
-	rgb->dpms = DRM_MODE_DPMS_OFF;
-
-	rgb->dc = dc;
-
-	drm_encoder_helper_add(&rgb->encoder,
-			       &atmel_hlcdc_rgb_encoder_helper_funcs);
-	ret = drm_encoder_init(dev, &rgb->encoder,
-			       &atmel_hlcdc_rgb_encoder_funcs,
-			       DRM_MODE_ENCODER_LVDS);
-	if (ret)
-		return ret;
-
-	rgb->connector.dpms = DRM_MODE_DPMS_OFF;
-	rgb->connector.polled = DRM_CONNECTOR_POLL_CONNECT;
-	drm_connector_helper_add(&rgb->connector,
-				 &atmel_hlcdc_rgb_connector_helper_funcs);
-	ret = drm_connector_init(dev, &rgb->connector,
-				 &atmel_hlcdc_rgb_connector_funcs,
-				 DRM_MODE_CONNECTOR_LVDS);
-	if (ret)
-		goto err_encoder_cleanup;
-
-	drm_mode_connector_attach_encoder(&rgb->connector, &rgb->encoder);
-
-	ret = drm_connector_register(&rgb->connector);
-	if (ret)
-		goto err_connector_cleanup;
-
-	rgb->encoder.possible_crtcs = 0x1;
-
-	return 0;
-
-err_connector_cleanup:
-	drm_connector_cleanup(&rgb->connector);
-err_encoder_cleanup:
-	drm_encoder_cleanup(&rgb->encoder);
-
-	return ret;
-}
-
-int atmel_hlcdc_create_outputs(struct drm_device *dev)
-{
-	struct device_node *port_np, *np;
-	struct of_endpoint ep;
-	int ret;
-
-	port_np = of_get_child_by_name(dev->dev->of_node, "port");
-	if (!port_np)
-		return -EINVAL;
-
-	np = of_get_child_by_name(port_np, "endpoint");
-	of_node_put(port_np);
-
-	if (!np)
-		return -EINVAL;
-
-	ret = of_graph_parse_endpoint(np, &ep);
-	of_node_put(port_np);
-
-	if (ret)
-		return ret;
-
-	ret = atmel_hlcdc_create_output(dev, &ep);
-	if (ret)
-		return ret;
-
-	return 0;
-}
-- 
1.9.1

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux