drm/linux: Add sign_extend64()
[dragonfly.git] / sys / dev / drm / drm_mipi_dsi.c
blobeccce98ec721cd6fcd574e2439a1bfd2d700a128
1 /*
2 * MIPI DSI Bus
4 * Copyright (C) 2012-2013, Samsung Electronics, Co., Ltd.
5 * Andrzej Hajda <a.hajda@samsung.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 * USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include <drm/drmP.h>
29 #include <drm/drm_mipi_dsi.h>
31 #include <linux/device.h>
32 #include <linux/module.h>
33 #include <linux/slab.h>
35 #include <video/mipi_display.h>
37 /**
38 * DOC: dsi helpers
40 * These functions contain some common logic and helpers to deal with MIPI DSI
41 * peripherals.
43 * Helpers are provided for a number of standard MIPI DSI command as well as a
44 * subset of the MIPI DCS command set.
47 #if 0
48 static int mipi_dsi_device_match(struct device *dev, struct device_driver *drv)
50 return of_driver_match_device(dev, drv);
53 static const struct dev_pm_ops mipi_dsi_device_pm_ops = {
54 .runtime_suspend = pm_generic_runtime_suspend,
55 .runtime_resume = pm_generic_runtime_resume,
56 .suspend = pm_generic_suspend,
57 .resume = pm_generic_resume,
58 .freeze = pm_generic_freeze,
59 .thaw = pm_generic_thaw,
60 .poweroff = pm_generic_poweroff,
61 .restore = pm_generic_restore,
64 static struct bus_type mipi_dsi_bus_type = {
65 .name = "mipi-dsi",
66 .match = mipi_dsi_device_match,
67 .pm = &mipi_dsi_device_pm_ops,
70 static int of_device_match(struct device *dev, void *data)
72 return dev->of_node == data;
75 /**
76 * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
77 * device tree node
78 * @np: device tree node
80 * Return: A pointer to the MIPI DSI device corresponding to @np or NULL if no
81 * such device exists (or has not been registered yet).
83 struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
85 struct device *dev;
87 dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
89 return dev ? to_mipi_dsi_device(dev) : NULL;
91 EXPORT_SYMBOL(of_find_mipi_dsi_device_by_node);
93 static void mipi_dsi_dev_release(struct device *dev)
95 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
97 of_node_put(dev->of_node);
98 kfree(dsi);
101 static const struct device_type mipi_dsi_device_type = {
102 .release = mipi_dsi_dev_release,
105 static struct mipi_dsi_device *mipi_dsi_device_alloc(struct mipi_dsi_host *host)
107 struct mipi_dsi_device *dsi;
109 dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
110 if (!dsi)
111 return ERR_PTR(-ENOMEM);
113 dsi->host = host;
114 dsi->dev.bus = &mipi_dsi_bus_type;
115 dsi->dev.parent = host->dev;
116 dsi->dev.type = &mipi_dsi_device_type;
118 device_initialize(&dsi->dev);
120 return dsi;
123 static int mipi_dsi_device_add(struct mipi_dsi_device *dsi)
125 struct mipi_dsi_host *host = dsi->host;
127 dev_set_name(&dsi->dev, "%s.%d", dev_name(host->dev), dsi->channel);
129 return device_add(&dsi->dev);
132 static struct mipi_dsi_device *
133 of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
135 struct mipi_dsi_device *dsi;
136 struct device *dev = host->dev;
137 int ret;
138 u32 reg;
140 ret = of_property_read_u32(node, "reg", &reg);
141 if (ret) {
142 dev_err(dev, "device node %s has no valid reg property: %d\n",
143 node->full_name, ret);
144 return ERR_PTR(-EINVAL);
147 if (reg > 3) {
148 dev_err(dev, "device node %s has invalid reg property: %u\n",
149 node->full_name, reg);
150 return ERR_PTR(-EINVAL);
153 dsi = mipi_dsi_device_alloc(host);
154 if (IS_ERR(dsi)) {
155 dev_err(dev, "failed to allocate DSI device %s: %ld\n",
156 node->full_name, PTR_ERR(dsi));
157 return dsi;
160 dsi->dev.of_node = of_node_get(node);
161 dsi->channel = reg;
163 ret = mipi_dsi_device_add(dsi);
164 if (ret) {
165 dev_err(dev, "failed to add DSI device %s: %d\n",
166 node->full_name, ret);
167 kfree(dsi);
168 return ERR_PTR(ret);
171 return dsi;
174 int mipi_dsi_host_register(struct mipi_dsi_host *host)
176 struct device_node *node;
178 for_each_available_child_of_node(host->dev->of_node, node) {
179 /* skip nodes without reg property */
180 if (!of_find_property(node, "reg", NULL))
181 continue;
182 of_mipi_dsi_device_add(host, node);
185 return 0;
187 EXPORT_SYMBOL(mipi_dsi_host_register);
189 static int mipi_dsi_remove_device_fn(struct device *dev, void *priv)
191 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
193 device_unregister(&dsi->dev);
195 return 0;
198 void mipi_dsi_host_unregister(struct mipi_dsi_host *host)
200 device_for_each_child(host->dev, NULL, mipi_dsi_remove_device_fn);
202 EXPORT_SYMBOL(mipi_dsi_host_unregister);
203 #endif
206 * mipi_dsi_attach - attach a DSI device to its DSI host
207 * @dsi: DSI peripheral
209 int mipi_dsi_attach(struct mipi_dsi_device *dsi)
211 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
213 if (!ops || !ops->attach)
214 return -ENOSYS;
216 return ops->attach(dsi->host, dsi);
218 EXPORT_SYMBOL(mipi_dsi_attach);
221 * mipi_dsi_detach - detach a DSI device from its DSI host
222 * @dsi: DSI peripheral
224 int mipi_dsi_detach(struct mipi_dsi_device *dsi)
226 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
228 if (!ops || !ops->detach)
229 return -ENOSYS;
231 return ops->detach(dsi->host, dsi);
233 EXPORT_SYMBOL(mipi_dsi_detach);
235 static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi,
236 struct mipi_dsi_msg *msg)
238 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
240 if (!ops || !ops->transfer)
241 return -ENOSYS;
243 if (dsi->mode_flags & MIPI_DSI_MODE_LPM)
244 msg->flags |= MIPI_DSI_MSG_USE_LPM;
246 return ops->transfer(dsi->host, msg);
250 * mipi_dsi_packet_format_is_short - check if a packet is of the short format
251 * @type: MIPI DSI data type of the packet
253 * Return: true if the packet for the given data type is a short packet, false
254 * otherwise.
256 bool mipi_dsi_packet_format_is_short(u8 type)
258 switch (type) {
259 case MIPI_DSI_V_SYNC_START:
260 case MIPI_DSI_V_SYNC_END:
261 case MIPI_DSI_H_SYNC_START:
262 case MIPI_DSI_H_SYNC_END:
263 case MIPI_DSI_END_OF_TRANSMISSION:
264 case MIPI_DSI_COLOR_MODE_OFF:
265 case MIPI_DSI_COLOR_MODE_ON:
266 case MIPI_DSI_SHUTDOWN_PERIPHERAL:
267 case MIPI_DSI_TURN_ON_PERIPHERAL:
268 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
269 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
270 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
271 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
272 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
273 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
274 case MIPI_DSI_DCS_SHORT_WRITE:
275 case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
276 case MIPI_DSI_DCS_READ:
277 case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
278 return true;
281 return false;
283 EXPORT_SYMBOL(mipi_dsi_packet_format_is_short);
286 * mipi_dsi_packet_format_is_long - check if a packet is of the long format
287 * @type: MIPI DSI data type of the packet
289 * Return: true if the packet for the given data type is a long packet, false
290 * otherwise.
292 bool mipi_dsi_packet_format_is_long(u8 type)
294 switch (type) {
295 case MIPI_DSI_NULL_PACKET:
296 case MIPI_DSI_BLANKING_PACKET:
297 case MIPI_DSI_GENERIC_LONG_WRITE:
298 case MIPI_DSI_DCS_LONG_WRITE:
299 case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20:
300 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24:
301 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16:
302 case MIPI_DSI_PACKED_PIXEL_STREAM_30:
303 case MIPI_DSI_PACKED_PIXEL_STREAM_36:
304 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12:
305 case MIPI_DSI_PACKED_PIXEL_STREAM_16:
306 case MIPI_DSI_PACKED_PIXEL_STREAM_18:
307 case MIPI_DSI_PIXEL_STREAM_3BYTE_18:
308 case MIPI_DSI_PACKED_PIXEL_STREAM_24:
309 return true;
312 return false;
314 EXPORT_SYMBOL(mipi_dsi_packet_format_is_long);
317 * mipi_dsi_create_packet - create a packet from a message according to the
318 * DSI protocol
319 * @packet: pointer to a DSI packet structure
320 * @msg: message to translate into a packet
322 * Return: 0 on success or a negative error code on failure.
324 int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
325 const struct mipi_dsi_msg *msg)
327 if (!packet || !msg)
328 return -EINVAL;
330 /* do some minimum sanity checking */
331 if (!mipi_dsi_packet_format_is_short(msg->type) &&
332 !mipi_dsi_packet_format_is_long(msg->type))
333 return -EINVAL;
335 if (msg->channel > 3)
336 return -EINVAL;
338 memset(packet, 0, sizeof(*packet));
339 packet->header[0] = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f);
341 /* TODO: compute ECC if hardware support is not available */
344 * Long write packets contain the word count in header bytes 1 and 2.
345 * The payload follows the header and is word count bytes long.
347 * Short write packets encode up to two parameters in header bytes 1
348 * and 2.
350 if (mipi_dsi_packet_format_is_long(msg->type)) {
351 packet->header[1] = (msg->tx_len >> 0) & 0xff;
352 packet->header[2] = (msg->tx_len >> 8) & 0xff;
354 packet->payload_length = msg->tx_len;
355 packet->payload = msg->tx_buf;
356 } else {
357 const u8 *tx = msg->tx_buf;
359 packet->header[1] = (msg->tx_len > 0) ? tx[0] : 0;
360 packet->header[2] = (msg->tx_len > 1) ? tx[1] : 0;
363 packet->size = sizeof(packet->header) + packet->payload_length;
365 return 0;
367 EXPORT_SYMBOL(mipi_dsi_create_packet);
369 #if 0
371 * mipi_dsi_set_maximum_return_packet_size() - specify the maximum size of the
372 * the payload in a long packet transmitted from the peripheral back to the
373 * host processor
374 * @dsi: DSI peripheral device
375 * @value: the maximum size of the payload
377 * Return: 0 on success or a negative error code on failure.
379 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
380 u16 value)
382 u8 tx[2] = { value & 0xff, value >> 8 };
383 struct mipi_dsi_msg msg = {
384 .channel = dsi->channel,
385 .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
386 .tx_len = sizeof(tx),
387 .tx_buf = tx,
390 return mipi_dsi_device_transfer(dsi, &msg);
392 EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
393 #endif
396 * mipi_dsi_generic_write() - transmit data using a generic write packet
397 * @dsi: DSI peripheral device
398 * @payload: buffer containing the payload
399 * @size: size of payload buffer
401 * This function will automatically choose the right data type depending on
402 * the payload length.
404 * Return: The number of bytes transmitted on success or a negative error code
405 * on failure.
407 ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
408 size_t size)
410 struct mipi_dsi_msg msg = {
411 .channel = dsi->channel,
412 .tx_buf = payload,
413 .tx_len = size
416 switch (size) {
417 case 0:
418 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
419 break;
421 case 1:
422 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
423 break;
425 case 2:
426 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
427 break;
429 default:
430 msg.type = MIPI_DSI_GENERIC_LONG_WRITE;
431 break;
434 return mipi_dsi_device_transfer(dsi, &msg);
436 EXPORT_SYMBOL(mipi_dsi_generic_write);
439 * mipi_dsi_generic_read() - receive data using a generic read packet
440 * @dsi: DSI peripheral device
441 * @params: buffer containing the request parameters
442 * @num_params: number of request parameters
443 * @data: buffer in which to return the received data
444 * @size: size of receive buffer
446 * This function will automatically choose the right data type depending on
447 * the number of parameters passed in.
449 * Return: The number of bytes successfully read or a negative error code on
450 * failure.
452 ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
453 size_t num_params, void *data, size_t size)
455 struct mipi_dsi_msg msg = {
456 .channel = dsi->channel,
457 .tx_len = num_params,
458 .tx_buf = params,
459 .rx_len = size,
460 .rx_buf = data
463 switch (num_params) {
464 case 0:
465 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
466 break;
468 case 1:
469 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
470 break;
472 case 2:
473 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
474 break;
476 default:
477 return -EINVAL;
480 return mipi_dsi_device_transfer(dsi, &msg);
482 EXPORT_SYMBOL(mipi_dsi_generic_read);
485 * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload
486 * @dsi: DSI peripheral device
487 * @data: buffer containing data to be transmitted
488 * @len: size of transmission buffer
490 * This function will automatically choose the right data type depending on
491 * the command payload length.
493 * Return: The number of bytes successfully transmitted or a negative error
494 * code on failure.
496 ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
497 const void *data, size_t len)
499 struct mipi_dsi_msg msg = {
500 .channel = dsi->channel,
501 .tx_buf = data,
502 .tx_len = len
505 switch (len) {
506 case 0:
507 return -EINVAL;
509 case 1:
510 msg.type = MIPI_DSI_DCS_SHORT_WRITE;
511 break;
513 case 2:
514 msg.type = MIPI_DSI_DCS_SHORT_WRITE_PARAM;
515 break;
517 default:
518 msg.type = MIPI_DSI_DCS_LONG_WRITE;
519 break;
522 return mipi_dsi_device_transfer(dsi, &msg);
524 EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer);
526 #if 0
528 * mipi_dsi_dcs_write() - send DCS write command
529 * @dsi: DSI peripheral device
530 * @cmd: DCS command
531 * @data: buffer containing the command payload
532 * @len: command payload length
534 * This function will automatically choose the right data type depending on
535 * the command payload length.
537 * Return: The number of bytes successfully transmitted or a negative error
538 * code on failure.
540 ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
541 const void *data, size_t len)
543 ssize_t err;
544 size_t size;
545 u8 *tx;
547 if (len > 0) {
548 size = 1 + len;
550 tx = kmalloc(size, GFP_KERNEL);
551 if (!tx)
552 return -ENOMEM;
554 /* concatenate the DCS command byte and the payload */
555 tx[0] = cmd;
556 memcpy(&tx[1], data, len);
557 } else {
558 tx = &cmd;
559 size = 1;
562 err = mipi_dsi_dcs_write_buffer(dsi, tx, size);
564 if (len > 0)
565 kfree(tx);
567 return err;
569 EXPORT_SYMBOL(mipi_dsi_dcs_write);
570 #endif
573 * mipi_dsi_dcs_read() - send DCS read request command
574 * @dsi: DSI peripheral device
575 * @cmd: DCS command
576 * @data: buffer in which to receive data
577 * @len: size of receive buffer
579 * Return: The number of bytes read or a negative error code on failure.
581 ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
582 size_t len)
584 struct mipi_dsi_msg msg = {
585 .channel = dsi->channel,
586 .type = MIPI_DSI_DCS_READ,
587 .tx_buf = &cmd,
588 .tx_len = 1,
589 .rx_buf = data,
590 .rx_len = len
593 return mipi_dsi_device_transfer(dsi, &msg);
595 EXPORT_SYMBOL(mipi_dsi_dcs_read);
597 #if 0
599 * mipi_dsi_dcs_nop() - send DCS nop packet
600 * @dsi: DSI peripheral device
602 * Return: 0 on success or a negative error code on failure.
604 int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi)
606 ssize_t err;
608 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_NOP, NULL, 0);
609 if (err < 0)
610 return err;
612 return 0;
614 EXPORT_SYMBOL(mipi_dsi_dcs_nop);
617 * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module
618 * @dsi: DSI peripheral device
620 * Return: 0 on success or a negative error code on failure.
622 int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi)
624 ssize_t err;
626 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SOFT_RESET, NULL, 0);
627 if (err < 0)
628 return err;
630 return 0;
632 EXPORT_SYMBOL(mipi_dsi_dcs_soft_reset);
635 * mipi_dsi_dcs_get_power_mode() - query the display module's current power
636 * mode
637 * @dsi: DSI peripheral device
638 * @mode: return location for the current power mode
640 * Return: 0 on success or a negative error code on failure.
642 int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode)
644 ssize_t err;
646 err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_POWER_MODE, mode,
647 sizeof(*mode));
648 if (err <= 0) {
649 if (err == 0)
650 err = -ENODATA;
652 return err;
655 return 0;
657 EXPORT_SYMBOL(mipi_dsi_dcs_get_power_mode);
660 * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image
661 * data used by the interface
662 * @dsi: DSI peripheral device
663 * @format: return location for the pixel format
665 * Return: 0 on success or a negative error code on failure.
667 int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format)
669 ssize_t err;
671 err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_PIXEL_FORMAT, format,
672 sizeof(*format));
673 if (err <= 0) {
674 if (err == 0)
675 err = -ENODATA;
677 return err;
680 return 0;
682 EXPORT_SYMBOL(mipi_dsi_dcs_get_pixel_format);
685 * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the
686 * display module except interface communication
687 * @dsi: DSI peripheral device
689 * Return: 0 on success or a negative error code on failure.
691 int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi)
693 ssize_t err;
695 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_ENTER_SLEEP_MODE, NULL, 0);
696 if (err < 0)
697 return err;
699 return 0;
701 EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode);
704 * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
705 * module
706 * @dsi: DSI peripheral device
708 * Return: 0 on success or a negative error code on failure.
710 int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi)
712 ssize_t err;
714 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_EXIT_SLEEP_MODE, NULL, 0);
715 if (err < 0)
716 return err;
718 return 0;
720 EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode);
723 * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
724 * display device
725 * @dsi: DSI peripheral device
727 * Return: 0 on success or a negative error code on failure.
729 int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi)
731 ssize_t err;
733 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0);
734 if (err < 0)
735 return err;
737 return 0;
739 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off);
742 * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
743 * display device
744 * @dsi: DSI peripheral device
746 * Return: 0 on success or a negative error code on failure
748 int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi)
750 ssize_t err;
752 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_ON, NULL, 0);
753 if (err < 0)
754 return err;
756 return 0;
758 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_on);
761 * mipi_dsi_dcs_set_column_address() - define the column extent of the frame
762 * memory accessed by the host processor
763 * @dsi: DSI peripheral device
764 * @start: first column of frame memory
765 * @end: last column of frame memory
767 * Return: 0 on success or a negative error code on failure.
769 int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
770 u16 end)
772 u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
773 ssize_t err;
775 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, payload,
776 sizeof(payload));
777 if (err < 0)
778 return err;
780 return 0;
782 EXPORT_SYMBOL(mipi_dsi_dcs_set_column_address);
785 * mipi_dsi_dcs_set_page_address() - define the page extent of the frame
786 * memory accessed by the host processor
787 * @dsi: DSI peripheral device
788 * @start: first page of frame memory
789 * @end: last page of frame memory
791 * Return: 0 on success or a negative error code on failure.
793 int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
794 u16 end)
796 u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
797 ssize_t err;
799 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PAGE_ADDRESS, payload,
800 sizeof(payload));
801 if (err < 0)
802 return err;
804 return 0;
806 EXPORT_SYMBOL(mipi_dsi_dcs_set_page_address);
809 * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect
810 * output signal on the TE signal line
811 * @dsi: DSI peripheral device
813 * Return: 0 on success or a negative error code on failure
815 int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi)
817 ssize_t err;
819 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_OFF, NULL, 0);
820 if (err < 0)
821 return err;
823 return 0;
825 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_off);
828 * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect
829 * output signal on the TE signal line.
830 * @dsi: DSI peripheral device
831 * @mode: the Tearing Effect Output Line mode
833 * Return: 0 on success or a negative error code on failure
835 int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
836 enum mipi_dsi_dcs_tear_mode mode)
838 u8 value = mode;
839 ssize_t err;
841 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_ON, &value,
842 sizeof(value));
843 if (err < 0)
844 return err;
846 return 0;
848 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_on);
851 * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image
852 * data used by the interface
853 * @dsi: DSI peripheral device
854 * @format: pixel format
856 * Return: 0 on success or a negative error code on failure.
858 int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format)
860 ssize_t err;
862 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PIXEL_FORMAT, &format,
863 sizeof(format));
864 if (err < 0)
865 return err;
867 return 0;
869 EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format);
871 static int mipi_dsi_drv_probe(struct device *dev)
873 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
874 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
876 return drv->probe(dsi);
879 static int mipi_dsi_drv_remove(struct device *dev)
881 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
882 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
884 return drv->remove(dsi);
887 static void mipi_dsi_drv_shutdown(struct device *dev)
889 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
890 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
892 drv->shutdown(dsi);
896 * mipi_dsi_driver_register_full() - register a driver for DSI devices
897 * @drv: DSI driver structure
898 * @owner: owner module
900 * Return: 0 on success or a negative error code on failure.
902 int mipi_dsi_driver_register_full(struct mipi_dsi_driver *drv,
903 struct module *owner)
905 drv->driver.bus = &mipi_dsi_bus_type;
906 drv->driver.owner = owner;
908 if (drv->probe)
909 drv->driver.probe = mipi_dsi_drv_probe;
910 if (drv->remove)
911 drv->driver.remove = mipi_dsi_drv_remove;
912 if (drv->shutdown)
913 drv->driver.shutdown = mipi_dsi_drv_shutdown;
915 return driver_register(&drv->driver);
917 EXPORT_SYMBOL(mipi_dsi_driver_register_full);
920 * mipi_dsi_driver_unregister() - unregister a driver for DSI devices
921 * @drv: DSI driver structure
923 * Return: 0 on success or a negative error code on failure.
925 void mipi_dsi_driver_unregister(struct mipi_dsi_driver *drv)
927 driver_unregister(&drv->driver);
929 EXPORT_SYMBOL(mipi_dsi_driver_unregister);
931 static int __init mipi_dsi_bus_init(void)
933 return bus_register(&mipi_dsi_bus_type);
935 postcore_initcall(mipi_dsi_bus_init);
936 #endif
938 MODULE_AUTHOR("Andrzej Hajda <a.hajda@samsung.com>");
939 MODULE_DESCRIPTION("MIPI DSI Bus");