aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/drm_mipi_dsi.c
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2014-10-16 07:44:02 -0400
committerThierry Reding <treding@nvidia.com>2014-11-13 07:55:26 -0500
commita52879e8d7cbeed69be5e54c69701e5edea8cc00 (patch)
treedaba30972f3fc580fb3b6c818d31500bd3be2597 /drivers/gpu/drm/drm_mipi_dsi.c
parent02acb76d72b3672330b6a20d2773048658b2d176 (diff)
drm/dsi: Add message to packet translator
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> Reviewed-by: Sean Paul <seanpaul@chromium.org> Signed-off-by: Thierry Reding <treding@nvidia.com>
Diffstat (limited to 'drivers/gpu/drm/drm_mipi_dsi.c')
-rw-r--r--drivers/gpu/drm/drm_mipi_dsi.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index adf056677498..44ff665f216f 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -266,6 +266,59 @@ bool mipi_dsi_packet_format_is_long(u8 type)
266EXPORT_SYMBOL(mipi_dsi_packet_format_is_long); 266EXPORT_SYMBOL(mipi_dsi_packet_format_is_long);
267 267
268/** 268/**
269 * mipi_dsi_create_packet - create a packet from a message according to the
270 * DSI protocol
271 * @packet: pointer to a DSI packet structure
272 * @msg: message to translate into a packet
273 *
274 * Return: 0 on success or a negative error code on failure.
275 */
276int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
277 const struct mipi_dsi_msg *msg)
278{
279 const u8 *tx = msg->tx_buf;
280
281 if (!packet || !msg)
282 return -EINVAL;
283
284 /* do some minimum sanity checking */
285 if (!mipi_dsi_packet_format_is_short(msg->type) &&
286 !mipi_dsi_packet_format_is_long(msg->type))
287 return -EINVAL;
288
289 if (msg->channel > 3)
290 return -EINVAL;
291
292 memset(packet, 0, sizeof(*packet));
293 packet->header[0] = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f);
294
295 /* TODO: compute ECC if hardware support is not available */
296
297 /*
298 * Long write packets contain the word count in header bytes 1 and 2.
299 * The payload follows the header and is word count bytes long.
300 *
301 * Short write packets encode up to two parameters in header bytes 1
302 * and 2.
303 */
304 if (mipi_dsi_packet_format_is_long(msg->type)) {
305 packet->header[1] = (msg->tx_len >> 0) & 0xff;
306 packet->header[2] = (msg->tx_len >> 8) & 0xff;
307
308 packet->payload_length = msg->tx_len;
309 packet->payload = tx;
310 } else {
311 packet->header[1] = (msg->tx_len > 0) ? tx[0] : 0;
312 packet->header[2] = (msg->tx_len > 1) ? tx[1] : 0;
313 }
314
315 packet->size = sizeof(packet->header) + packet->payload_length;
316
317 return 0;
318}
319EXPORT_SYMBOL(mipi_dsi_create_packet);
320
321/**
269 * mipi_dsi_dcs_write - send DCS write command 322 * mipi_dsi_dcs_write - send DCS write command
270 * @dsi: DSI device 323 * @dsi: DSI device
271 * @data: pointer to the command followed by parameters 324 * @data: pointer to the command followed by parameters