|
@@ -198,59 +198,238 @@ int mipi_dsi_detach(struct mipi_dsi_device *dsi)
|
|
|
}
|
|
|
EXPORT_SYMBOL(mipi_dsi_detach);
|
|
|
|
|
|
+static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi,
|
|
|
+ struct mipi_dsi_msg *msg)
|
|
|
+{
|
|
|
+ const struct mipi_dsi_host_ops *ops = dsi->host->ops;
|
|
|
+
|
|
|
+ if (!ops || !ops->transfer)
|
|
|
+ return -ENOSYS;
|
|
|
+
|
|
|
+ if (dsi->mode_flags & MIPI_DSI_MODE_LPM)
|
|
|
+ msg->flags |= MIPI_DSI_MSG_USE_LPM;
|
|
|
+
|
|
|
+ return ops->transfer(dsi->host, msg);
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
- * mipi_dsi_dcs_write - send DCS write command
|
|
|
- * @dsi: DSI device
|
|
|
- * @data: pointer to the command followed by parameters
|
|
|
- * @len: length of @data
|
|
|
+ * mipi_dsi_packet_format_is_short - check if a packet is of the short format
|
|
|
+ * @type: MIPI DSI data type of the packet
|
|
|
+ *
|
|
|
+ * Return: true if the packet for the given data type is a short packet, false
|
|
|
+ * otherwise.
|
|
|
*/
|
|
|
-ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, const void *data,
|
|
|
- size_t len)
|
|
|
+bool mipi_dsi_packet_format_is_short(u8 type)
|
|
|
+{
|
|
|
+ switch (type) {
|
|
|
+ case MIPI_DSI_V_SYNC_START:
|
|
|
+ case MIPI_DSI_V_SYNC_END:
|
|
|
+ case MIPI_DSI_H_SYNC_START:
|
|
|
+ case MIPI_DSI_H_SYNC_END:
|
|
|
+ case MIPI_DSI_END_OF_TRANSMISSION:
|
|
|
+ case MIPI_DSI_COLOR_MODE_OFF:
|
|
|
+ case MIPI_DSI_COLOR_MODE_ON:
|
|
|
+ case MIPI_DSI_SHUTDOWN_PERIPHERAL:
|
|
|
+ case MIPI_DSI_TURN_ON_PERIPHERAL:
|
|
|
+ case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
|
|
|
+ case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
|
|
|
+ case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
|
|
|
+ case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
|
|
|
+ case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
|
|
|
+ case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
|
|
|
+ case MIPI_DSI_DCS_SHORT_WRITE:
|
|
|
+ case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
|
|
|
+ case MIPI_DSI_DCS_READ:
|
|
|
+ case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(mipi_dsi_packet_format_is_short);
|
|
|
+
|
|
|
+/**
|
|
|
+ * mipi_dsi_packet_format_is_long - check if a packet is of the long format
|
|
|
+ * @type: MIPI DSI data type of the packet
|
|
|
+ *
|
|
|
+ * Return: true if the packet for the given data type is a long packet, false
|
|
|
+ * otherwise.
|
|
|
+ */
|
|
|
+bool mipi_dsi_packet_format_is_long(u8 type)
|
|
|
+{
|
|
|
+ switch (type) {
|
|
|
+ case MIPI_DSI_NULL_PACKET:
|
|
|
+ case MIPI_DSI_BLANKING_PACKET:
|
|
|
+ case MIPI_DSI_GENERIC_LONG_WRITE:
|
|
|
+ case MIPI_DSI_DCS_LONG_WRITE:
|
|
|
+ case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20:
|
|
|
+ case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24:
|
|
|
+ case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16:
|
|
|
+ case MIPI_DSI_PACKED_PIXEL_STREAM_30:
|
|
|
+ case MIPI_DSI_PACKED_PIXEL_STREAM_36:
|
|
|
+ case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12:
|
|
|
+ case MIPI_DSI_PACKED_PIXEL_STREAM_16:
|
|
|
+ case MIPI_DSI_PACKED_PIXEL_STREAM_18:
|
|
|
+ case MIPI_DSI_PIXEL_STREAM_3BYTE_18:
|
|
|
+ case MIPI_DSI_PACKED_PIXEL_STREAM_24:
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(mipi_dsi_packet_format_is_long);
|
|
|
+
|
|
|
+/**
|
|
|
+ * 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;
|
|
|
+
|
|
|
+ /* do some minimum sanity checking */
|
|
|
+ if (!mipi_dsi_packet_format_is_short(msg->type) &&
|
|
|
+ !mipi_dsi_packet_format_is_long(msg->type))
|
|
|
+ return -EINVAL;
|
|
|
+
|
|
|
+ if (msg->channel > 3)
|
|
|
+ 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 (mipi_dsi_packet_format_is_long(msg->type)) {
|
|
|
+ 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_buffer() - transmit a DCS command with payload
|
|
|
+ * @dsi: DSI peripheral device
|
|
|
+ * @data: buffer containing data to be transmitted
|
|
|
+ * @len: size of transmission buffer
|
|
|
+ *
|
|
|
+ * This function will automatically choose the right data type depending on
|
|
|
+ * the command payload length.
|
|
|
+ *
|
|
|
+ * Return: The number of bytes successfully transmitted or a negative error
|
|
|
+ * code on failure.
|
|
|
+ */
|
|
|
+ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
|
|
|
+ const void *data, size_t len)
|
|
|
{
|
|
|
- const struct mipi_dsi_host_ops *ops = dsi->host->ops;
|
|
|
struct mipi_dsi_msg msg = {
|
|
|
.channel = dsi->channel,
|
|
|
.tx_buf = data,
|
|
|
.tx_len = len
|
|
|
};
|
|
|
|
|
|
- if (!ops || !ops->transfer)
|
|
|
- return -ENOSYS;
|
|
|
-
|
|
|
switch (len) {
|
|
|
case 0:
|
|
|
return -EINVAL;
|
|
|
+
|
|
|
case 1:
|
|
|
msg.type = MIPI_DSI_DCS_SHORT_WRITE;
|
|
|
break;
|
|
|
+
|
|
|
case 2:
|
|
|
msg.type = MIPI_DSI_DCS_SHORT_WRITE_PARAM;
|
|
|
break;
|
|
|
+
|
|
|
default:
|
|
|
msg.type = MIPI_DSI_DCS_LONG_WRITE;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- if (dsi->mode_flags & MIPI_DSI_MODE_LPM)
|
|
|
- msg.flags = MIPI_DSI_MSG_USE_LPM;
|
|
|
+ return mipi_dsi_device_transfer(dsi, &msg);
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer);
|
|
|
+
|
|
|
+/**
|
|
|
+ * mipi_dsi_dcs_write() - send DCS write command
|
|
|
+ * @dsi: DSI peripheral device
|
|
|
+ * @cmd: DCS command
|
|
|
+ * @data: buffer containing the command payload
|
|
|
+ * @len: command payload length
|
|
|
+ *
|
|
|
+ * This function will automatically choose the right data type depending on
|
|
|
+ * the command payload length.
|
|
|
+ *
|
|
|
+ * Return: The number of bytes successfully transmitted or a negative error
|
|
|
+ * code on failure.
|
|
|
+ */
|
|
|
+ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
|
|
|
+ const void *data, size_t len)
|
|
|
+{
|
|
|
+ ssize_t err;
|
|
|
+ size_t size;
|
|
|
+ u8 *tx;
|
|
|
+
|
|
|
+ if (len > 0) {
|
|
|
+ size = 1 + len;
|
|
|
+
|
|
|
+ tx = kmalloc(size, GFP_KERNEL);
|
|
|
+ if (!tx)
|
|
|
+ return -ENOMEM;
|
|
|
+
|
|
|
+ /* concatenate the DCS command byte and the payload */
|
|
|
+ tx[0] = cmd;
|
|
|
+ memcpy(&tx[1], data, len);
|
|
|
+ } else {
|
|
|
+ tx = &cmd;
|
|
|
+ size = 1;
|
|
|
+ }
|
|
|
|
|
|
- return ops->transfer(dsi->host, &msg);
|
|
|
+ err = mipi_dsi_dcs_write_buffer(dsi, tx, size);
|
|
|
+
|
|
|
+ if (len > 0)
|
|
|
+ kfree(tx);
|
|
|
+
|
|
|
+ return err;
|
|
|
}
|
|
|
EXPORT_SYMBOL(mipi_dsi_dcs_write);
|
|
|
|
|
|
/**
|
|
|
- * mipi_dsi_dcs_read - send DCS read request command
|
|
|
- * @dsi: DSI device
|
|
|
- * @cmd: DCS read command
|
|
|
- * @data: pointer to read buffer
|
|
|
- * @len: length of @data
|
|
|
+ * mipi_dsi_dcs_read() - send DCS read request command
|
|
|
+ * @dsi: DSI peripheral device
|
|
|
+ * @cmd: DCS command
|
|
|
+ * @data: buffer in which to receive data
|
|
|
+ * @len: size of receive buffer
|
|
|
*
|
|
|
- * Function returns number of read bytes or error code.
|
|
|
+ * Return: The number of bytes read or a negative error code on failure.
|
|
|
*/
|
|
|
ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
|
|
|
size_t len)
|
|
|
{
|
|
|
- const struct mipi_dsi_host_ops *ops = dsi->host->ops;
|
|
|
struct mipi_dsi_msg msg = {
|
|
|
.channel = dsi->channel,
|
|
|
.type = MIPI_DSI_DCS_READ,
|
|
@@ -260,13 +439,7 @@ ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
|
|
|
.rx_len = len
|
|
|
};
|
|
|
|
|
|
- if (!ops || !ops->transfer)
|
|
|
- return -ENOSYS;
|
|
|
-
|
|
|
- if (dsi->mode_flags & MIPI_DSI_MODE_LPM)
|
|
|
- msg.flags = MIPI_DSI_MSG_USE_LPM;
|
|
|
-
|
|
|
- return ops->transfer(dsi->host, &msg);
|
|
|
+ return mipi_dsi_device_transfer(dsi, &msg);
|
|
|
}
|
|
|
EXPORT_SYMBOL(mipi_dsi_dcs_read);
|
|
|
|