drm/linux: Remove a redundant definition of NSEC_PER_SEC
[dragonfly.git] / sys / dev / drm / drm_mipi_dsi.c
blob5cbd4ab86a7e15f1024bf3bd1d6c6ffef9b3a898
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 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
52 /* attempt OF style match */
53 if (of_driver_match_device(dev, drv))
54 return 1;
56 /* compare DSI device and driver names */
57 if (!strcmp(dsi->name, drv->name))
58 return 1;
60 return 0;
63 static const struct dev_pm_ops mipi_dsi_device_pm_ops = {
64 .runtime_suspend = pm_generic_runtime_suspend,
65 .runtime_resume = pm_generic_runtime_resume,
66 .suspend = pm_generic_suspend,
67 .resume = pm_generic_resume,
68 .freeze = pm_generic_freeze,
69 .thaw = pm_generic_thaw,
70 .poweroff = pm_generic_poweroff,
71 .restore = pm_generic_restore,
74 static struct bus_type mipi_dsi_bus_type = {
75 .name = "mipi-dsi",
76 .match = mipi_dsi_device_match,
77 .pm = &mipi_dsi_device_pm_ops,
80 static int of_device_match(struct device *dev, void *data)
82 return dev->of_node == data;
85 /**
86 * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
87 * device tree node
88 * @np: device tree node
90 * Return: A pointer to the MIPI DSI device corresponding to @np or NULL if no
91 * such device exists (or has not been registered yet).
93 struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
95 struct device *dev;
97 dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
99 return dev ? to_mipi_dsi_device(dev) : NULL;
101 EXPORT_SYMBOL(of_find_mipi_dsi_device_by_node);
103 static void mipi_dsi_dev_release(struct device *dev)
105 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
107 of_node_put(dev->of_node);
108 kfree(dsi);
111 static const struct device_type mipi_dsi_device_type = {
112 .release = mipi_dsi_dev_release,
115 static struct mipi_dsi_device *mipi_dsi_device_alloc(struct mipi_dsi_host *host)
117 struct mipi_dsi_device *dsi;
119 dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
120 if (!dsi)
121 return ERR_PTR(-ENOMEM);
123 dsi->host = host;
124 dsi->dev.bus = &mipi_dsi_bus_type;
125 dsi->dev.parent = host->dev;
126 dsi->dev.type = &mipi_dsi_device_type;
128 device_initialize(&dsi->dev);
130 return dsi;
133 static int mipi_dsi_device_add(struct mipi_dsi_device *dsi)
135 struct mipi_dsi_host *host = dsi->host;
137 dev_set_name(&dsi->dev, "%s.%d", dev_name(host->dev), dsi->channel);
139 return device_add(&dsi->dev);
142 #if IS_ENABLED(CONFIG_OF)
143 static struct mipi_dsi_device *
144 of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
146 struct device *dev = host->dev;
147 struct mipi_dsi_device_info info = { };
148 int ret;
149 u32 reg;
151 if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) {
152 dev_err(dev, "modalias failure on %s\n", node->full_name);
153 return ERR_PTR(-EINVAL);
156 ret = of_property_read_u32(node, "reg", &reg);
157 if (ret) {
158 dev_err(dev, "device node %s has no valid reg property: %d\n",
159 node->full_name, ret);
160 return ERR_PTR(-EINVAL);
163 info.channel = reg;
164 info.node = of_node_get(node);
166 return mipi_dsi_device_register_full(host, &info);
168 #else
169 static struct mipi_dsi_device *
170 of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
172 return ERR_PTR(-ENODEV);
174 #endif
177 * mipi_dsi_device_register_full - create a MIPI DSI device
178 * @host: DSI host to which this device is connected
179 * @info: pointer to template containing DSI device information
181 * Create a MIPI DSI device by using the device information provided by
182 * mipi_dsi_device_info template
184 * Returns:
185 * A pointer to the newly created MIPI DSI device, or, a pointer encoded
186 * with an error
188 struct mipi_dsi_device *
189 mipi_dsi_device_register_full(struct mipi_dsi_host *host,
190 const struct mipi_dsi_device_info *info)
192 struct mipi_dsi_device *dsi;
193 struct device *dev = host->dev;
194 int ret;
196 if (!info) {
197 dev_err(dev, "invalid mipi_dsi_device_info pointer\n");
198 return ERR_PTR(-EINVAL);
201 if (info->channel > 3) {
202 dev_err(dev, "invalid virtual channel: %u\n", info->channel);
203 return ERR_PTR(-EINVAL);
206 dsi = mipi_dsi_device_alloc(host);
207 if (IS_ERR(dsi)) {
208 dev_err(dev, "failed to allocate DSI device %ld\n",
209 PTR_ERR(dsi));
210 return dsi;
213 dsi->dev.of_node = info->node;
214 dsi->channel = info->channel;
215 strlcpy(dsi->name, info->type, sizeof(dsi->name));
217 ret = mipi_dsi_device_add(dsi);
218 if (ret) {
219 dev_err(dev, "failed to add DSI device %d\n", ret);
220 kfree(dsi);
221 return ERR_PTR(ret);
224 return dsi;
226 EXPORT_SYMBOL(mipi_dsi_device_register_full);
229 * mipi_dsi_device_unregister - unregister MIPI DSI device
230 * @dsi: DSI peripheral device
232 void mipi_dsi_device_unregister(struct mipi_dsi_device *dsi)
234 device_unregister(&dsi->dev);
236 EXPORT_SYMBOL(mipi_dsi_device_unregister);
238 static DEFINE_MUTEX(host_lock);
239 static LIST_HEAD(host_list);
242 * of_find_mipi_dsi_host_by_node() - find the MIPI DSI host matching a
243 * device tree node
244 * @node: device tree node
246 * Returns:
247 * A pointer to the MIPI DSI host corresponding to @node or NULL if no
248 * such device exists (or has not been registered yet).
250 struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node)
252 struct mipi_dsi_host *host;
254 mutex_lock(&host_lock);
256 list_for_each_entry(host, &host_list, list) {
257 if (host->dev->of_node == node) {
258 mutex_unlock(&host_lock);
259 return host;
263 mutex_unlock(&host_lock);
265 return NULL;
267 EXPORT_SYMBOL(of_find_mipi_dsi_host_by_node);
269 int mipi_dsi_host_register(struct mipi_dsi_host *host)
271 struct device_node *node;
273 for_each_available_child_of_node(host->dev->of_node, node) {
274 /* skip nodes without reg property */
275 if (!of_find_property(node, "reg", NULL))
276 continue;
277 of_mipi_dsi_device_add(host, node);
280 mutex_lock(&host_lock);
281 list_add_tail(&host->list, &host_list);
282 mutex_unlock(&host_lock);
284 return 0;
286 EXPORT_SYMBOL(mipi_dsi_host_register);
288 static int mipi_dsi_remove_device_fn(struct device *dev, void *priv)
290 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
292 mipi_dsi_device_unregister(dsi);
294 return 0;
297 void mipi_dsi_host_unregister(struct mipi_dsi_host *host)
299 device_for_each_child(host->dev, NULL, mipi_dsi_remove_device_fn);
301 mutex_lock(&host_lock);
302 list_del_init(&host->list);
303 mutex_unlock(&host_lock);
305 EXPORT_SYMBOL(mipi_dsi_host_unregister);
306 #endif
309 * mipi_dsi_attach - attach a DSI device to its DSI host
310 * @dsi: DSI peripheral
312 int mipi_dsi_attach(struct mipi_dsi_device *dsi)
314 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
316 if (!ops || !ops->attach)
317 return -ENOSYS;
319 return ops->attach(dsi->host, dsi);
321 EXPORT_SYMBOL(mipi_dsi_attach);
324 * mipi_dsi_detach - detach a DSI device from its DSI host
325 * @dsi: DSI peripheral
327 int mipi_dsi_detach(struct mipi_dsi_device *dsi)
329 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
331 if (!ops || !ops->detach)
332 return -ENOSYS;
334 return ops->detach(dsi->host, dsi);
336 EXPORT_SYMBOL(mipi_dsi_detach);
338 static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi,
339 struct mipi_dsi_msg *msg)
341 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
343 if (!ops || !ops->transfer)
344 return -ENOSYS;
346 if (dsi->mode_flags & MIPI_DSI_MODE_LPM)
347 msg->flags |= MIPI_DSI_MSG_USE_LPM;
349 return ops->transfer(dsi->host, msg);
353 * mipi_dsi_packet_format_is_short - check if a packet is of the short format
354 * @type: MIPI DSI data type of the packet
356 * Return: true if the packet for the given data type is a short packet, false
357 * otherwise.
359 bool mipi_dsi_packet_format_is_short(u8 type)
361 switch (type) {
362 case MIPI_DSI_V_SYNC_START:
363 case MIPI_DSI_V_SYNC_END:
364 case MIPI_DSI_H_SYNC_START:
365 case MIPI_DSI_H_SYNC_END:
366 case MIPI_DSI_END_OF_TRANSMISSION:
367 case MIPI_DSI_COLOR_MODE_OFF:
368 case MIPI_DSI_COLOR_MODE_ON:
369 case MIPI_DSI_SHUTDOWN_PERIPHERAL:
370 case MIPI_DSI_TURN_ON_PERIPHERAL:
371 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
372 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
373 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
374 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
375 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
376 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
377 case MIPI_DSI_DCS_SHORT_WRITE:
378 case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
379 case MIPI_DSI_DCS_READ:
380 case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
381 return true;
384 return false;
386 EXPORT_SYMBOL(mipi_dsi_packet_format_is_short);
389 * mipi_dsi_packet_format_is_long - check if a packet is of the long format
390 * @type: MIPI DSI data type of the packet
392 * Return: true if the packet for the given data type is a long packet, false
393 * otherwise.
395 bool mipi_dsi_packet_format_is_long(u8 type)
397 switch (type) {
398 case MIPI_DSI_NULL_PACKET:
399 case MIPI_DSI_BLANKING_PACKET:
400 case MIPI_DSI_GENERIC_LONG_WRITE:
401 case MIPI_DSI_DCS_LONG_WRITE:
402 case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20:
403 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24:
404 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16:
405 case MIPI_DSI_PACKED_PIXEL_STREAM_30:
406 case MIPI_DSI_PACKED_PIXEL_STREAM_36:
407 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12:
408 case MIPI_DSI_PACKED_PIXEL_STREAM_16:
409 case MIPI_DSI_PACKED_PIXEL_STREAM_18:
410 case MIPI_DSI_PIXEL_STREAM_3BYTE_18:
411 case MIPI_DSI_PACKED_PIXEL_STREAM_24:
412 return true;
415 return false;
417 EXPORT_SYMBOL(mipi_dsi_packet_format_is_long);
420 * mipi_dsi_create_packet - create a packet from a message according to the
421 * DSI protocol
422 * @packet: pointer to a DSI packet structure
423 * @msg: message to translate into a packet
425 * Return: 0 on success or a negative error code on failure.
427 int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
428 const struct mipi_dsi_msg *msg)
430 if (!packet || !msg)
431 return -EINVAL;
433 /* do some minimum sanity checking */
434 if (!mipi_dsi_packet_format_is_short(msg->type) &&
435 !mipi_dsi_packet_format_is_long(msg->type))
436 return -EINVAL;
438 if (msg->channel > 3)
439 return -EINVAL;
441 memset(packet, 0, sizeof(*packet));
442 packet->header[0] = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f);
444 /* TODO: compute ECC if hardware support is not available */
447 * Long write packets contain the word count in header bytes 1 and 2.
448 * The payload follows the header and is word count bytes long.
450 * Short write packets encode up to two parameters in header bytes 1
451 * and 2.
453 if (mipi_dsi_packet_format_is_long(msg->type)) {
454 packet->header[1] = (msg->tx_len >> 0) & 0xff;
455 packet->header[2] = (msg->tx_len >> 8) & 0xff;
457 packet->payload_length = msg->tx_len;
458 packet->payload = msg->tx_buf;
459 } else {
460 const u8 *tx = msg->tx_buf;
462 packet->header[1] = (msg->tx_len > 0) ? tx[0] : 0;
463 packet->header[2] = (msg->tx_len > 1) ? tx[1] : 0;
466 packet->size = sizeof(packet->header) + packet->payload_length;
468 return 0;
470 EXPORT_SYMBOL(mipi_dsi_create_packet);
473 * mipi_dsi_shutdown_peripheral() - sends a Shutdown Peripheral command
474 * @dsi: DSI peripheral device
476 * Return: 0 on success or a negative error code on failure.
478 int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
480 struct mipi_dsi_msg msg = {
481 .channel = dsi->channel,
482 .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
483 .tx_buf = (u8 [2]) { 0, 0 },
484 .tx_len = 2,
487 return mipi_dsi_device_transfer(dsi, &msg);
489 EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);
492 * mipi_dsi_turn_on_peripheral() - sends a Turn On Peripheral command
493 * @dsi: DSI peripheral device
495 * Return: 0 on success or a negative error code on failure.
497 int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi)
499 struct mipi_dsi_msg msg = {
500 .channel = dsi->channel,
501 .type = MIPI_DSI_TURN_ON_PERIPHERAL,
502 .tx_buf = (u8 [2]) { 0, 0 },
503 .tx_len = 2,
506 return mipi_dsi_device_transfer(dsi, &msg);
508 EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);
510 #if 0
512 * mipi_dsi_set_maximum_return_packet_size() - specify the maximum size of the
513 * the payload in a long packet transmitted from the peripheral back to the
514 * host processor
515 * @dsi: DSI peripheral device
516 * @value: the maximum size of the payload
518 * Return: 0 on success or a negative error code on failure.
520 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
521 u16 value)
523 u8 tx[2] = { value & 0xff, value >> 8 };
524 struct mipi_dsi_msg msg = {
525 .channel = dsi->channel,
526 .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
527 .tx_len = sizeof(tx),
528 .tx_buf = tx,
531 return mipi_dsi_device_transfer(dsi, &msg);
533 EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
534 #endif
537 * mipi_dsi_generic_write() - transmit data using a generic write packet
538 * @dsi: DSI peripheral device
539 * @payload: buffer containing the payload
540 * @size: size of payload buffer
542 * This function will automatically choose the right data type depending on
543 * the payload length.
545 * Return: The number of bytes transmitted on success or a negative error code
546 * on failure.
548 ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
549 size_t size)
551 struct mipi_dsi_msg msg = {
552 .channel = dsi->channel,
553 .tx_buf = payload,
554 .tx_len = size
557 switch (size) {
558 case 0:
559 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
560 break;
562 case 1:
563 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
564 break;
566 case 2:
567 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
568 break;
570 default:
571 msg.type = MIPI_DSI_GENERIC_LONG_WRITE;
572 break;
575 return mipi_dsi_device_transfer(dsi, &msg);
577 EXPORT_SYMBOL(mipi_dsi_generic_write);
580 * mipi_dsi_generic_read() - receive data using a generic read packet
581 * @dsi: DSI peripheral device
582 * @params: buffer containing the request parameters
583 * @num_params: number of request parameters
584 * @data: buffer in which to return the received data
585 * @size: size of receive buffer
587 * This function will automatically choose the right data type depending on
588 * the number of parameters passed in.
590 * Return: The number of bytes successfully read or a negative error code on
591 * failure.
593 ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
594 size_t num_params, void *data, size_t size)
596 struct mipi_dsi_msg msg = {
597 .channel = dsi->channel,
598 .tx_len = num_params,
599 .tx_buf = params,
600 .rx_len = size,
601 .rx_buf = data
604 switch (num_params) {
605 case 0:
606 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
607 break;
609 case 1:
610 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
611 break;
613 case 2:
614 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
615 break;
617 default:
618 return -EINVAL;
621 return mipi_dsi_device_transfer(dsi, &msg);
623 EXPORT_SYMBOL(mipi_dsi_generic_read);
626 * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload
627 * @dsi: DSI peripheral device
628 * @data: buffer containing data to be transmitted
629 * @len: size of transmission buffer
631 * This function will automatically choose the right data type depending on
632 * the command payload length.
634 * Return: The number of bytes successfully transmitted or a negative error
635 * code on failure.
637 ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
638 const void *data, size_t len)
640 struct mipi_dsi_msg msg = {
641 .channel = dsi->channel,
642 .tx_buf = data,
643 .tx_len = len
646 switch (len) {
647 case 0:
648 return -EINVAL;
650 case 1:
651 msg.type = MIPI_DSI_DCS_SHORT_WRITE;
652 break;
654 case 2:
655 msg.type = MIPI_DSI_DCS_SHORT_WRITE_PARAM;
656 break;
658 default:
659 msg.type = MIPI_DSI_DCS_LONG_WRITE;
660 break;
663 return mipi_dsi_device_transfer(dsi, &msg);
665 EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer);
667 #if 0
669 * mipi_dsi_dcs_write() - send DCS write command
670 * @dsi: DSI peripheral device
671 * @cmd: DCS command
672 * @data: buffer containing the command payload
673 * @len: command payload length
675 * This function will automatically choose the right data type depending on
676 * the command payload length.
678 * Return: The number of bytes successfully transmitted or a negative error
679 * code on failure.
681 ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
682 const void *data, size_t len)
684 ssize_t err;
685 size_t size;
686 u8 *tx;
688 if (len > 0) {
689 size = 1 + len;
691 tx = kmalloc(size, GFP_KERNEL);
692 if (!tx)
693 return -ENOMEM;
695 /* concatenate the DCS command byte and the payload */
696 tx[0] = cmd;
697 memcpy(&tx[1], data, len);
698 } else {
699 tx = &cmd;
700 size = 1;
703 err = mipi_dsi_dcs_write_buffer(dsi, tx, size);
705 if (len > 0)
706 kfree(tx);
708 return err;
710 EXPORT_SYMBOL(mipi_dsi_dcs_write);
711 #endif
714 * mipi_dsi_dcs_read() - send DCS read request command
715 * @dsi: DSI peripheral device
716 * @cmd: DCS command
717 * @data: buffer in which to receive data
718 * @len: size of receive buffer
720 * Return: The number of bytes read or a negative error code on failure.
722 ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
723 size_t len)
725 struct mipi_dsi_msg msg = {
726 .channel = dsi->channel,
727 .type = MIPI_DSI_DCS_READ,
728 .tx_buf = &cmd,
729 .tx_len = 1,
730 .rx_buf = data,
731 .rx_len = len
734 return mipi_dsi_device_transfer(dsi, &msg);
736 EXPORT_SYMBOL(mipi_dsi_dcs_read);
738 #if 0
740 * mipi_dsi_dcs_nop() - send DCS nop packet
741 * @dsi: DSI peripheral device
743 * Return: 0 on success or a negative error code on failure.
745 int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi)
747 ssize_t err;
749 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_NOP, NULL, 0);
750 if (err < 0)
751 return err;
753 return 0;
755 EXPORT_SYMBOL(mipi_dsi_dcs_nop);
758 * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module
759 * @dsi: DSI peripheral device
761 * Return: 0 on success or a negative error code on failure.
763 int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi)
765 ssize_t err;
767 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SOFT_RESET, NULL, 0);
768 if (err < 0)
769 return err;
771 return 0;
773 EXPORT_SYMBOL(mipi_dsi_dcs_soft_reset);
776 * mipi_dsi_dcs_get_power_mode() - query the display module's current power
777 * mode
778 * @dsi: DSI peripheral device
779 * @mode: return location for the current power mode
781 * Return: 0 on success or a negative error code on failure.
783 int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode)
785 ssize_t err;
787 err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_POWER_MODE, mode,
788 sizeof(*mode));
789 if (err <= 0) {
790 if (err == 0)
791 err = -ENODATA;
793 return err;
796 return 0;
798 EXPORT_SYMBOL(mipi_dsi_dcs_get_power_mode);
801 * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image
802 * data used by the interface
803 * @dsi: DSI peripheral device
804 * @format: return location for the pixel format
806 * Return: 0 on success or a negative error code on failure.
808 int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format)
810 ssize_t err;
812 err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_PIXEL_FORMAT, format,
813 sizeof(*format));
814 if (err <= 0) {
815 if (err == 0)
816 err = -ENODATA;
818 return err;
821 return 0;
823 EXPORT_SYMBOL(mipi_dsi_dcs_get_pixel_format);
826 * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the
827 * display module except interface communication
828 * @dsi: DSI peripheral device
830 * Return: 0 on success or a negative error code on failure.
832 int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi)
834 ssize_t err;
836 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_ENTER_SLEEP_MODE, NULL, 0);
837 if (err < 0)
838 return err;
840 return 0;
842 EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode);
845 * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
846 * module
847 * @dsi: DSI peripheral device
849 * Return: 0 on success or a negative error code on failure.
851 int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi)
853 ssize_t err;
855 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_EXIT_SLEEP_MODE, NULL, 0);
856 if (err < 0)
857 return err;
859 return 0;
861 EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode);
864 * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
865 * display device
866 * @dsi: DSI peripheral device
868 * Return: 0 on success or a negative error code on failure.
870 int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi)
872 ssize_t err;
874 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0);
875 if (err < 0)
876 return err;
878 return 0;
880 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off);
883 * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
884 * display device
885 * @dsi: DSI peripheral device
887 * Return: 0 on success or a negative error code on failure
889 int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi)
891 ssize_t err;
893 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_ON, NULL, 0);
894 if (err < 0)
895 return err;
897 return 0;
899 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_on);
902 * mipi_dsi_dcs_set_column_address() - define the column extent of the frame
903 * memory accessed by the host processor
904 * @dsi: DSI peripheral device
905 * @start: first column of frame memory
906 * @end: last column of frame memory
908 * Return: 0 on success or a negative error code on failure.
910 int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
911 u16 end)
913 u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
914 ssize_t err;
916 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, payload,
917 sizeof(payload));
918 if (err < 0)
919 return err;
921 return 0;
923 EXPORT_SYMBOL(mipi_dsi_dcs_set_column_address);
926 * mipi_dsi_dcs_set_page_address() - define the page extent of the frame
927 * memory accessed by the host processor
928 * @dsi: DSI peripheral device
929 * @start: first page of frame memory
930 * @end: last page of frame memory
932 * Return: 0 on success or a negative error code on failure.
934 int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
935 u16 end)
937 u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
938 ssize_t err;
940 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PAGE_ADDRESS, payload,
941 sizeof(payload));
942 if (err < 0)
943 return err;
945 return 0;
947 EXPORT_SYMBOL(mipi_dsi_dcs_set_page_address);
950 * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect
951 * output signal on the TE signal line
952 * @dsi: DSI peripheral device
954 * Return: 0 on success or a negative error code on failure
956 int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi)
958 ssize_t err;
960 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_OFF, NULL, 0);
961 if (err < 0)
962 return err;
964 return 0;
966 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_off);
969 * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect
970 * output signal on the TE signal line.
971 * @dsi: DSI peripheral device
972 * @mode: the Tearing Effect Output Line mode
974 * Return: 0 on success or a negative error code on failure
976 int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
977 enum mipi_dsi_dcs_tear_mode mode)
979 u8 value = mode;
980 ssize_t err;
982 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_ON, &value,
983 sizeof(value));
984 if (err < 0)
985 return err;
987 return 0;
989 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_on);
992 * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image
993 * data used by the interface
994 * @dsi: DSI peripheral device
995 * @format: pixel format
997 * Return: 0 on success or a negative error code on failure.
999 int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format)
1001 ssize_t err;
1003 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PIXEL_FORMAT, &format,
1004 sizeof(format));
1005 if (err < 0)
1006 return err;
1008 return 0;
1010 EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format);
1012 static int mipi_dsi_drv_probe(struct device *dev)
1014 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
1015 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
1017 return drv->probe(dsi);
1020 static int mipi_dsi_drv_remove(struct device *dev)
1022 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
1023 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
1025 return drv->remove(dsi);
1028 static void mipi_dsi_drv_shutdown(struct device *dev)
1030 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
1031 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
1033 drv->shutdown(dsi);
1037 * mipi_dsi_driver_register_full() - register a driver for DSI devices
1038 * @drv: DSI driver structure
1039 * @owner: owner module
1041 * Return: 0 on success or a negative error code on failure.
1043 int mipi_dsi_driver_register_full(struct mipi_dsi_driver *drv,
1044 struct module *owner)
1046 drv->driver.bus = &mipi_dsi_bus_type;
1047 drv->driver.owner = owner;
1049 if (drv->probe)
1050 drv->driver.probe = mipi_dsi_drv_probe;
1051 if (drv->remove)
1052 drv->driver.remove = mipi_dsi_drv_remove;
1053 if (drv->shutdown)
1054 drv->driver.shutdown = mipi_dsi_drv_shutdown;
1056 return driver_register(&drv->driver);
1058 EXPORT_SYMBOL(mipi_dsi_driver_register_full);
1061 * mipi_dsi_driver_unregister() - unregister a driver for DSI devices
1062 * @drv: DSI driver structure
1064 * Return: 0 on success or a negative error code on failure.
1066 void mipi_dsi_driver_unregister(struct mipi_dsi_driver *drv)
1068 driver_unregister(&drv->driver);
1070 EXPORT_SYMBOL(mipi_dsi_driver_unregister);
1072 static int __init mipi_dsi_bus_init(void)
1074 return bus_register(&mipi_dsi_bus_type);
1076 postcore_initcall(mipi_dsi_bus_init);
1077 #endif
1079 MODULE_AUTHOR("Andrzej Hajda <a.hajda@samsung.com>");
1080 MODULE_DESCRIPTION("MIPI DSI Bus");