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
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.
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>
40 * These functions contain some common logic and helpers to deal with MIPI DSI
43 * Helpers are provided for a number of standard MIPI DSI command as well as a
44 * subset of the MIPI DCS command set.
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
))
56 /* compare DSI device and driver names */
57 if (!strcmp(dsi
->name
, drv
->name
))
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
= {
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
;
86 * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
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
)
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
);
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
);
121 return ERR_PTR(-ENOMEM
);
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
);
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
= { };
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", ®
);
158 dev_err(dev
, "device node %s has no valid reg property: %d\n",
159 node
->full_name
, ret
);
160 return ERR_PTR(-EINVAL
);
164 info
.node
= of_node_get(node
);
166 return mipi_dsi_device_register_full(host
, &info
);
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
);
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
185 * A pointer to the newly created MIPI DSI device, or, a pointer encoded
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
;
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
);
208 dev_err(dev
, "failed to allocate DSI device %ld\n",
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
);
219 dev_err(dev
, "failed to add DSI device %d\n", ret
);
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
244 * @node: device tree node
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
);
263 mutex_unlock(&host_lock
);
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
))
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
);
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
);
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
);
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
)
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
)
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
)
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
359 bool mipi_dsi_packet_format_is_short(u8 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
:
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
395 bool mipi_dsi_packet_format_is_long(u8 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
:
417 EXPORT_SYMBOL(mipi_dsi_packet_format_is_long
);
420 * mipi_dsi_create_packet - create a packet from a message according to the
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
)
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
))
438 if (msg
->channel
> 3)
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
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
;
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
;
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 },
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 },
506 return mipi_dsi_device_transfer(dsi
, &msg
);
508 EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral
);
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
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
,
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
),
531 return mipi_dsi_device_transfer(dsi
, &msg
);
533 EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size
);
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
548 ssize_t
mipi_dsi_generic_write(struct mipi_dsi_device
*dsi
, const void *payload
,
551 struct mipi_dsi_msg msg
= {
552 .channel
= dsi
->channel
,
559 msg
.type
= MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM
;
563 msg
.type
= MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM
;
567 msg
.type
= MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM
;
571 msg
.type
= MIPI_DSI_GENERIC_LONG_WRITE
;
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
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
,
604 switch (num_params
) {
606 msg
.type
= MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM
;
610 msg
.type
= MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM
;
614 msg
.type
= MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM
;
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
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
,
651 msg
.type
= MIPI_DSI_DCS_SHORT_WRITE
;
655 msg
.type
= MIPI_DSI_DCS_SHORT_WRITE_PARAM
;
659 msg
.type
= MIPI_DSI_DCS_LONG_WRITE
;
663 return mipi_dsi_device_transfer(dsi
, &msg
);
665 EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer
);
669 * mipi_dsi_dcs_write() - send DCS write command
670 * @dsi: DSI peripheral device
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
681 ssize_t
mipi_dsi_dcs_write(struct mipi_dsi_device
*dsi
, u8 cmd
,
682 const void *data
, size_t len
)
691 tx
= kmalloc(size
, GFP_KERNEL
);
695 /* concatenate the DCS command byte and the payload */
697 memcpy(&tx
[1], data
, len
);
703 err
= mipi_dsi_dcs_write_buffer(dsi
, tx
, size
);
710 EXPORT_SYMBOL(mipi_dsi_dcs_write
);
714 * mipi_dsi_dcs_read() - send DCS read request command
715 * @dsi: DSI peripheral device
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
,
725 struct mipi_dsi_msg msg
= {
726 .channel
= dsi
->channel
,
727 .type
= MIPI_DSI_DCS_READ
,
734 return mipi_dsi_device_transfer(dsi
, &msg
);
736 EXPORT_SYMBOL(mipi_dsi_dcs_read
);
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
)
749 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_NOP
, NULL
, 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
)
767 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SOFT_RESET
, NULL
, 0);
773 EXPORT_SYMBOL(mipi_dsi_dcs_soft_reset
);
776 * mipi_dsi_dcs_get_power_mode() - query the display module's current power
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
)
787 err
= mipi_dsi_dcs_read(dsi
, MIPI_DCS_GET_POWER_MODE
, mode
,
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
)
812 err
= mipi_dsi_dcs_read(dsi
, MIPI_DCS_GET_PIXEL_FORMAT
, format
,
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
)
836 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_ENTER_SLEEP_MODE
, NULL
, 0);
842 EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode
);
845 * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
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
)
855 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_EXIT_SLEEP_MODE
, NULL
, 0);
861 EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode
);
864 * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
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
)
874 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_DISPLAY_OFF
, NULL
, 0);
880 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off
);
883 * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
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
)
893 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_DISPLAY_ON
, NULL
, 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
,
913 u8 payload
[4] = { start
>> 8, start
& 0xff, end
>> 8, end
& 0xff };
916 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_COLUMN_ADDRESS
, payload
,
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
,
937 u8 payload
[4] = { start
>> 8, start
& 0xff, end
>> 8, end
& 0xff };
940 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_PAGE_ADDRESS
, payload
,
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
)
960 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_TEAR_OFF
, NULL
, 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
)
982 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_TEAR_ON
, &value
,
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
)
1003 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_PIXEL_FORMAT
, &format
,
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
);
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
;
1050 drv
->driver
.probe
= mipi_dsi_drv_probe
;
1052 drv
->driver
.remove
= mipi_dsi_drv_remove
;
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
);
1079 MODULE_AUTHOR("Andrzej Hajda <a.hajda@samsung.com>");
1080 MODULE_DESCRIPTION("MIPI DSI Bus");