All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 01/16] drm/dsi: Add message to packet translator
@ 2014-11-03  9:13 Thierry Reding
  2014-11-03  9:13 ` [PATCH v4 02/16] drm/dsi: Add DSI transfer helper Thierry Reding
                   ` (15 more replies)
  0 siblings, 16 replies; 28+ messages in thread
From: Thierry Reding @ 2014-11-03  9:13 UTC (permalink / raw)
  To: Thierry Reding; +Cc: Andrzej Hajda, dri-devel

From: Thierry Reding <treding@nvidia.com>

This commit introduces a new function, mipi_dsi_create_packet(), which
converts from a MIPI DSI message to a MIPI DSI packet. The MIPI DSI
packet is as close to the protocol described in the DSI specification as
possible and useful in drivers that need to write a DSI packet into a
FIFO to send a message off to the peripheral.

Suggested-by: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 drivers/gpu/drm/drm_mipi_dsi.c | 45 ++++++++++++++++++++++++++++++++++++++++++
 include/drm/drm_mipi_dsi.h     | 18 +++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index eb6dfe52cab2..76e81aba8220 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -199,6 +199,51 @@ int mipi_dsi_detach(struct mipi_dsi_device *dsi)
 EXPORT_SYMBOL(mipi_dsi_detach);
 
 /**
+ * mipi_dsi_create_packet - create a packet from a message according to the
+ *     DSI protocol
+ * @packet: pointer to a DSI packet structure
+ * @msg: message to translate into a packet
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
+			   const struct mipi_dsi_msg *msg)
+{
+	const u8 *tx = msg->tx_buf;
+
+	if (!packet || !msg)
+		return -EINVAL;
+
+	memset(packet, 0, sizeof(*packet));
+	packet->header[0] = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f);
+
+	/* TODO: compute ECC if hardware support is not available */
+
+	/*
+	 * Long write packets contain the word count in header bytes 1 and 2.
+	 * The payload follows the header and is word count bytes long.
+	 *
+	 * Short write packets encode up to two parameters in header bytes 1
+	 * and 2.
+	 */
+	if (msg->tx_len > 2) {
+		packet->header[1] = (msg->tx_len >> 0) & 0xff;
+		packet->header[2] = (msg->tx_len >> 8) & 0xff;
+
+		packet->payload_length = msg->tx_len;
+		packet->payload = tx;
+	} else {
+		packet->header[1] = (msg->tx_len > 0) ? tx[0] : 0;
+		packet->header[2] = (msg->tx_len > 1) ? tx[1] : 0;
+	}
+
+	packet->size = sizeof(packet->header) + packet->payload_length;
+
+	return 0;
+}
+EXPORT_SYMBOL(mipi_dsi_create_packet);
+
+/**
  * mipi_dsi_dcs_write - send DCS write command
  * @dsi: DSI device
  * @data: pointer to the command followed by parameters
diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h
index 8569dc5a1026..663aa68826f4 100644
--- a/include/drm/drm_mipi_dsi.h
+++ b/include/drm/drm_mipi_dsi.h
@@ -44,6 +44,24 @@ struct mipi_dsi_msg {
 };
 
 /**
+ * struct mipi_dsi_packet - represents a MIPI DSI packet in protocol format
+ * @size: size (in bytes) of the packet
+ * @header: the four bytes that make up the header (Data ID, Word Count or
+ *     Packet Data, and ECC)
+ * @payload_length: number of bytes in the payload
+ * @payload: a pointer to a buffer containing the payload, if any
+ */
+struct mipi_dsi_packet {
+	size_t size;
+	u8 header[4];
+	size_t payload_length;
+	const u8 *payload;
+};
+
+int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
+			   const struct mipi_dsi_msg *msg);
+
+/**
  * struct mipi_dsi_host_ops - DSI bus operations
  * @attach: attach DSI device to DSI host
  * @detach: detach DSI device from DSI host
-- 
2.1.2

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

^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2014-11-05 14:39 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-03  9:13 [PATCH v4 01/16] drm/dsi: Add message to packet translator Thierry Reding
2014-11-03  9:13 ` [PATCH v4 02/16] drm/dsi: Add DSI transfer helper Thierry Reding
2014-11-04 11:47   ` Andrzej Hajda
2014-11-03  9:13 ` [PATCH v4 03/16] drm/dsi: Make mipi_dsi_dcs_{read, write}() symmetrical Thierry Reding
2014-11-03  9:13 ` [PATCH v4 04/16] drm/dsi: Constify mipi_dsi_msg Thierry Reding
2014-11-03  9:13 ` [PATCH v4 05/16] drm/dsi: Add mipi_dsi_set_maximum_return_packet_size() helper Thierry Reding
2014-11-03  9:13 ` [PATCH v4 06/16] drm/panel: s6e8aa0: Use standard MIPI DSI function Thierry Reding
2014-11-03  9:13 ` [PATCH v4 07/16] drm/dsi: Implement generic read and write commands Thierry Reding
2014-11-03  9:13 ` [PATCH v4 08/16] drm/dsi: Implement some standard DCS commands Thierry Reding
2014-11-03  9:13 ` [PATCH v4 09/16] drm/dsi: Add to DocBook documentation Thierry Reding
2014-11-03  9:13 ` [PATCH v4 10/16] drm/dsi: Implement DCS nop command Thierry Reding
2014-11-03  9:13 ` [PATCH v4 11/16] drm/dsi: Implement DCS soft_reset command Thierry Reding
2014-11-03  9:13 ` [PATCH v4 12/16] drm/dsi: Implement DCS get_power_mode command Thierry Reding
2014-11-03  9:13 ` [PATCH v4 13/16] drm/dsi: Implement DCS {get, set}_pixel_format commands Thierry Reding
2014-11-03 17:10   ` Sean Paul
2014-11-04 13:34     ` [PATCH v4 13/16] drm/dsi: Implement DCS {get,set}_pixel_format commands Thierry Reding
2014-11-03  9:13 ` [PATCH v4 14/16] drm/dsi: Implement DCS set_{column, page}_address commands Thierry Reding
2014-11-03  9:13 ` [PATCH v4 15/16] drm/dsi: Resolve MIPI DSI device from phandle Thierry Reding
2014-11-03  9:13 ` [PATCH v4 16/16] drm/panel: Add Sharp LQ101R1SX01 support Thierry Reding
2014-11-03 17:28   ` Sean Paul
2014-11-04 10:41   ` Andrzej Hajda
2014-11-04 13:29     ` Thierry Reding
2014-11-05 14:39       ` Andrzej Hajda
2014-11-04 11:43 ` [PATCH v4 01/16] drm/dsi: Add message to packet translator Andrzej Hajda
2014-11-04 13:58   ` Thierry Reding
2014-11-04 14:21     ` Andrzej Hajda
2014-11-04 14:39       ` Thierry Reding
2014-11-05 13:35         ` Andrzej Hajda

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.