ARM: pmu: add support for interrupt-affinity property
[linux/fpc-iii.git] / drivers / gpu / drm / drm_mipi_dsi.c
blob2d5ca8eec13a9611668a90756a756f6f40a0506b
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/drm_mipi_dsi.h>
30 #include <linux/device.h>
31 #include <linux/module.h>
32 #include <linux/of_device.h>
33 #include <linux/pm_runtime.h>
34 #include <linux/slab.h>
36 #include <video/mipi_display.h>
38 /**
39 * DOC: dsi helpers
41 * These functions contain some common logic and helpers to deal with MIPI DSI
42 * peripherals.
44 * Helpers are provided for a number of standard MIPI DSI command as well as a
45 * subset of the MIPI DCS command set.
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);
205 * mipi_dsi_attach - attach a DSI device to its DSI host
206 * @dsi: DSI peripheral
208 int mipi_dsi_attach(struct mipi_dsi_device *dsi)
210 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
212 if (!ops || !ops->attach)
213 return -ENOSYS;
215 return ops->attach(dsi->host, dsi);
217 EXPORT_SYMBOL(mipi_dsi_attach);
220 * mipi_dsi_detach - detach a DSI device from its DSI host
221 * @dsi: DSI peripheral
223 int mipi_dsi_detach(struct mipi_dsi_device *dsi)
225 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
227 if (!ops || !ops->detach)
228 return -ENOSYS;
230 return ops->detach(dsi->host, dsi);
232 EXPORT_SYMBOL(mipi_dsi_detach);
234 static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi,
235 struct mipi_dsi_msg *msg)
237 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
239 if (!ops || !ops->transfer)
240 return -ENOSYS;
242 if (dsi->mode_flags & MIPI_DSI_MODE_LPM)
243 msg->flags |= MIPI_DSI_MSG_USE_LPM;
245 return ops->transfer(dsi->host, msg);
249 * mipi_dsi_packet_format_is_short - check if a packet is of the short format
250 * @type: MIPI DSI data type of the packet
252 * Return: true if the packet for the given data type is a short packet, false
253 * otherwise.
255 bool mipi_dsi_packet_format_is_short(u8 type)
257 switch (type) {
258 case MIPI_DSI_V_SYNC_START:
259 case MIPI_DSI_V_SYNC_END:
260 case MIPI_DSI_H_SYNC_START:
261 case MIPI_DSI_H_SYNC_END:
262 case MIPI_DSI_END_OF_TRANSMISSION:
263 case MIPI_DSI_COLOR_MODE_OFF:
264 case MIPI_DSI_COLOR_MODE_ON:
265 case MIPI_DSI_SHUTDOWN_PERIPHERAL:
266 case MIPI_DSI_TURN_ON_PERIPHERAL:
267 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
268 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
269 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
270 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
271 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
272 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
273 case MIPI_DSI_DCS_SHORT_WRITE:
274 case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
275 case MIPI_DSI_DCS_READ:
276 case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
277 return true;
280 return false;
282 EXPORT_SYMBOL(mipi_dsi_packet_format_is_short);
285 * mipi_dsi_packet_format_is_long - check if a packet is of the long format
286 * @type: MIPI DSI data type of the packet
288 * Return: true if the packet for the given data type is a long packet, false
289 * otherwise.
291 bool mipi_dsi_packet_format_is_long(u8 type)
293 switch (type) {
294 case MIPI_DSI_NULL_PACKET:
295 case MIPI_DSI_BLANKING_PACKET:
296 case MIPI_DSI_GENERIC_LONG_WRITE:
297 case MIPI_DSI_DCS_LONG_WRITE:
298 case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20:
299 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24:
300 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16:
301 case MIPI_DSI_PACKED_PIXEL_STREAM_30:
302 case MIPI_DSI_PACKED_PIXEL_STREAM_36:
303 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12:
304 case MIPI_DSI_PACKED_PIXEL_STREAM_16:
305 case MIPI_DSI_PACKED_PIXEL_STREAM_18:
306 case MIPI_DSI_PIXEL_STREAM_3BYTE_18:
307 case MIPI_DSI_PACKED_PIXEL_STREAM_24:
308 return true;
311 return false;
313 EXPORT_SYMBOL(mipi_dsi_packet_format_is_long);
316 * mipi_dsi_create_packet - create a packet from a message according to the
317 * DSI protocol
318 * @packet: pointer to a DSI packet structure
319 * @msg: message to translate into a packet
321 * Return: 0 on success or a negative error code on failure.
323 int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
324 const struct mipi_dsi_msg *msg)
326 if (!packet || !msg)
327 return -EINVAL;
329 /* do some minimum sanity checking */
330 if (!mipi_dsi_packet_format_is_short(msg->type) &&
331 !mipi_dsi_packet_format_is_long(msg->type))
332 return -EINVAL;
334 if (msg->channel > 3)
335 return -EINVAL;
337 memset(packet, 0, sizeof(*packet));
338 packet->header[0] = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f);
340 /* TODO: compute ECC if hardware support is not available */
343 * Long write packets contain the word count in header bytes 1 and 2.
344 * The payload follows the header and is word count bytes long.
346 * Short write packets encode up to two parameters in header bytes 1
347 * and 2.
349 if (mipi_dsi_packet_format_is_long(msg->type)) {
350 packet->header[1] = (msg->tx_len >> 0) & 0xff;
351 packet->header[2] = (msg->tx_len >> 8) & 0xff;
353 packet->payload_length = msg->tx_len;
354 packet->payload = msg->tx_buf;
355 } else {
356 const u8 *tx = msg->tx_buf;
358 packet->header[1] = (msg->tx_len > 0) ? tx[0] : 0;
359 packet->header[2] = (msg->tx_len > 1) ? tx[1] : 0;
362 packet->size = sizeof(packet->header) + packet->payload_length;
364 return 0;
366 EXPORT_SYMBOL(mipi_dsi_create_packet);
369 * mipi_dsi_set_maximum_return_packet_size() - specify the maximum size of the
370 * the payload in a long packet transmitted from the peripheral back to the
371 * host processor
372 * @dsi: DSI peripheral device
373 * @value: the maximum size of the payload
375 * Return: 0 on success or a negative error code on failure.
377 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
378 u16 value)
380 u8 tx[2] = { value & 0xff, value >> 8 };
381 struct mipi_dsi_msg msg = {
382 .channel = dsi->channel,
383 .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
384 .tx_len = sizeof(tx),
385 .tx_buf = tx,
388 return mipi_dsi_device_transfer(dsi, &msg);
390 EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
393 * mipi_dsi_generic_write() - transmit data using a generic write packet
394 * @dsi: DSI peripheral device
395 * @payload: buffer containing the payload
396 * @size: size of payload buffer
398 * This function will automatically choose the right data type depending on
399 * the payload length.
401 * Return: The number of bytes transmitted on success or a negative error code
402 * on failure.
404 ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
405 size_t size)
407 struct mipi_dsi_msg msg = {
408 .channel = dsi->channel,
409 .tx_buf = payload,
410 .tx_len = size
413 switch (size) {
414 case 0:
415 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
416 break;
418 case 1:
419 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
420 break;
422 case 2:
423 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
424 break;
426 default:
427 msg.type = MIPI_DSI_GENERIC_LONG_WRITE;
428 break;
431 return mipi_dsi_device_transfer(dsi, &msg);
433 EXPORT_SYMBOL(mipi_dsi_generic_write);
436 * mipi_dsi_generic_read() - receive data using a generic read packet
437 * @dsi: DSI peripheral device
438 * @params: buffer containing the request parameters
439 * @num_params: number of request parameters
440 * @data: buffer in which to return the received data
441 * @size: size of receive buffer
443 * This function will automatically choose the right data type depending on
444 * the number of parameters passed in.
446 * Return: The number of bytes successfully read or a negative error code on
447 * failure.
449 ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
450 size_t num_params, void *data, size_t size)
452 struct mipi_dsi_msg msg = {
453 .channel = dsi->channel,
454 .tx_len = num_params,
455 .tx_buf = params,
456 .rx_len = size,
457 .rx_buf = data
460 switch (num_params) {
461 case 0:
462 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
463 break;
465 case 1:
466 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
467 break;
469 case 2:
470 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
471 break;
473 default:
474 return -EINVAL;
477 return mipi_dsi_device_transfer(dsi, &msg);
479 EXPORT_SYMBOL(mipi_dsi_generic_read);
482 * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload
483 * @dsi: DSI peripheral device
484 * @data: buffer containing data to be transmitted
485 * @len: size of transmission buffer
487 * This function will automatically choose the right data type depending on
488 * the command payload length.
490 * Return: The number of bytes successfully transmitted or a negative error
491 * code on failure.
493 ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
494 const void *data, size_t len)
496 struct mipi_dsi_msg msg = {
497 .channel = dsi->channel,
498 .tx_buf = data,
499 .tx_len = len
502 switch (len) {
503 case 0:
504 return -EINVAL;
506 case 1:
507 msg.type = MIPI_DSI_DCS_SHORT_WRITE;
508 break;
510 case 2:
511 msg.type = MIPI_DSI_DCS_SHORT_WRITE_PARAM;
512 break;
514 default:
515 msg.type = MIPI_DSI_DCS_LONG_WRITE;
516 break;
519 return mipi_dsi_device_transfer(dsi, &msg);
521 EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer);
524 * mipi_dsi_dcs_write() - send DCS write command
525 * @dsi: DSI peripheral device
526 * @cmd: DCS command
527 * @data: buffer containing the command payload
528 * @len: command payload length
530 * This function will automatically choose the right data type depending on
531 * the command payload length.
533 * Return: The number of bytes successfully transmitted or a negative error
534 * code on failure.
536 ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
537 const void *data, size_t len)
539 ssize_t err;
540 size_t size;
541 u8 *tx;
543 if (len > 0) {
544 size = 1 + len;
546 tx = kmalloc(size, GFP_KERNEL);
547 if (!tx)
548 return -ENOMEM;
550 /* concatenate the DCS command byte and the payload */
551 tx[0] = cmd;
552 memcpy(&tx[1], data, len);
553 } else {
554 tx = &cmd;
555 size = 1;
558 err = mipi_dsi_dcs_write_buffer(dsi, tx, size);
560 if (len > 0)
561 kfree(tx);
563 return err;
565 EXPORT_SYMBOL(mipi_dsi_dcs_write);
568 * mipi_dsi_dcs_read() - send DCS read request command
569 * @dsi: DSI peripheral device
570 * @cmd: DCS command
571 * @data: buffer in which to receive data
572 * @len: size of receive buffer
574 * Return: The number of bytes read or a negative error code on failure.
576 ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
577 size_t len)
579 struct mipi_dsi_msg msg = {
580 .channel = dsi->channel,
581 .type = MIPI_DSI_DCS_READ,
582 .tx_buf = &cmd,
583 .tx_len = 1,
584 .rx_buf = data,
585 .rx_len = len
588 return mipi_dsi_device_transfer(dsi, &msg);
590 EXPORT_SYMBOL(mipi_dsi_dcs_read);
593 * mipi_dsi_dcs_nop() - send DCS nop packet
594 * @dsi: DSI peripheral device
596 * Return: 0 on success or a negative error code on failure.
598 int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi)
600 ssize_t err;
602 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_NOP, NULL, 0);
603 if (err < 0)
604 return err;
606 return 0;
608 EXPORT_SYMBOL(mipi_dsi_dcs_nop);
611 * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module
612 * @dsi: DSI peripheral device
614 * Return: 0 on success or a negative error code on failure.
616 int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi)
618 ssize_t err;
620 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SOFT_RESET, NULL, 0);
621 if (err < 0)
622 return err;
624 return 0;
626 EXPORT_SYMBOL(mipi_dsi_dcs_soft_reset);
629 * mipi_dsi_dcs_get_power_mode() - query the display module's current power
630 * mode
631 * @dsi: DSI peripheral device
632 * @mode: return location for the current power mode
634 * Return: 0 on success or a negative error code on failure.
636 int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode)
638 ssize_t err;
640 err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_POWER_MODE, mode,
641 sizeof(*mode));
642 if (err <= 0) {
643 if (err == 0)
644 err = -ENODATA;
646 return err;
649 return 0;
651 EXPORT_SYMBOL(mipi_dsi_dcs_get_power_mode);
654 * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image
655 * data used by the interface
656 * @dsi: DSI peripheral device
657 * @format: return location for the pixel format
659 * Return: 0 on success or a negative error code on failure.
661 int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format)
663 ssize_t err;
665 err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_PIXEL_FORMAT, format,
666 sizeof(*format));
667 if (err <= 0) {
668 if (err == 0)
669 err = -ENODATA;
671 return err;
674 return 0;
676 EXPORT_SYMBOL(mipi_dsi_dcs_get_pixel_format);
679 * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the
680 * display module except interface communication
681 * @dsi: DSI peripheral device
683 * Return: 0 on success or a negative error code on failure.
685 int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi)
687 ssize_t err;
689 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_ENTER_SLEEP_MODE, NULL, 0);
690 if (err < 0)
691 return err;
693 return 0;
695 EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode);
698 * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
699 * module
700 * @dsi: DSI peripheral device
702 * Return: 0 on success or a negative error code on failure.
704 int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi)
706 ssize_t err;
708 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_EXIT_SLEEP_MODE, NULL, 0);
709 if (err < 0)
710 return err;
712 return 0;
714 EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode);
717 * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
718 * display device
719 * @dsi: DSI peripheral device
721 * Return: 0 on success or a negative error code on failure.
723 int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi)
725 ssize_t err;
727 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0);
728 if (err < 0)
729 return err;
731 return 0;
733 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off);
736 * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
737 * display device
738 * @dsi: DSI peripheral device
740 * Return: 0 on success or a negative error code on failure
742 int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi)
744 ssize_t err;
746 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_ON, NULL, 0);
747 if (err < 0)
748 return err;
750 return 0;
752 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_on);
755 * mipi_dsi_dcs_set_column_address() - define the column extent of the frame
756 * memory accessed by the host processor
757 * @dsi: DSI peripheral device
758 * @start: first column of frame memory
759 * @end: last column of frame memory
761 * Return: 0 on success or a negative error code on failure.
763 int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
764 u16 end)
766 u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
767 ssize_t err;
769 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, payload,
770 sizeof(payload));
771 if (err < 0)
772 return err;
774 return 0;
776 EXPORT_SYMBOL(mipi_dsi_dcs_set_column_address);
779 * mipi_dsi_dcs_set_page_address() - define the page extent of the frame
780 * memory accessed by the host processor
781 * @dsi: DSI peripheral device
782 * @start: first page of frame memory
783 * @end: last page of frame memory
785 * Return: 0 on success or a negative error code on failure.
787 int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
788 u16 end)
790 u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
791 ssize_t err;
793 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PAGE_ADDRESS, payload,
794 sizeof(payload));
795 if (err < 0)
796 return err;
798 return 0;
800 EXPORT_SYMBOL(mipi_dsi_dcs_set_page_address);
803 * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect
804 * output signal on the TE signal line
805 * @dsi: DSI peripheral device
807 * Return: 0 on success or a negative error code on failure
809 int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi)
811 ssize_t err;
813 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_OFF, NULL, 0);
814 if (err < 0)
815 return err;
817 return 0;
819 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_off);
822 * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect
823 * output signal on the TE signal line.
824 * @dsi: DSI peripheral device
825 * @mode: the Tearing Effect Output Line mode
827 * Return: 0 on success or a negative error code on failure
829 int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
830 enum mipi_dsi_dcs_tear_mode mode)
832 u8 value = mode;
833 ssize_t err;
835 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_ON, &value,
836 sizeof(value));
837 if (err < 0)
838 return err;
840 return 0;
842 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_on);
845 * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image
846 * data used by the interface
847 * @dsi: DSI peripheral device
848 * @format: pixel format
850 * Return: 0 on success or a negative error code on failure.
852 int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format)
854 ssize_t err;
856 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PIXEL_FORMAT, &format,
857 sizeof(format));
858 if (err < 0)
859 return err;
861 return 0;
863 EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format);
865 static int mipi_dsi_drv_probe(struct device *dev)
867 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
868 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
870 return drv->probe(dsi);
873 static int mipi_dsi_drv_remove(struct device *dev)
875 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
876 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
878 return drv->remove(dsi);
881 static void mipi_dsi_drv_shutdown(struct device *dev)
883 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
884 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
886 drv->shutdown(dsi);
890 * mipi_dsi_driver_register_full() - register a driver for DSI devices
891 * @drv: DSI driver structure
892 * @owner: owner module
894 * Return: 0 on success or a negative error code on failure.
896 int mipi_dsi_driver_register_full(struct mipi_dsi_driver *drv,
897 struct module *owner)
899 drv->driver.bus = &mipi_dsi_bus_type;
900 drv->driver.owner = owner;
902 if (drv->probe)
903 drv->driver.probe = mipi_dsi_drv_probe;
904 if (drv->remove)
905 drv->driver.remove = mipi_dsi_drv_remove;
906 if (drv->shutdown)
907 drv->driver.shutdown = mipi_dsi_drv_shutdown;
909 return driver_register(&drv->driver);
911 EXPORT_SYMBOL(mipi_dsi_driver_register_full);
914 * mipi_dsi_driver_unregister() - unregister a driver for DSI devices
915 * @drv: DSI driver structure
917 * Return: 0 on success or a negative error code on failure.
919 void mipi_dsi_driver_unregister(struct mipi_dsi_driver *drv)
921 driver_unregister(&drv->driver);
923 EXPORT_SYMBOL(mipi_dsi_driver_unregister);
925 static int __init mipi_dsi_bus_init(void)
927 return bus_register(&mipi_dsi_bus_type);
929 postcore_initcall(mipi_dsi_bus_init);
931 MODULE_AUTHOR("Andrzej Hajda <a.hajda@samsung.com>");
932 MODULE_DESCRIPTION("MIPI DSI Bus");
933 MODULE_LICENSE("GPL and additional rights");