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.
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 <drm/drm_dsc.h>
37 #include <video/mipi_display.h>
42 * These functions contain some common logic and helpers to deal with MIPI DSI
45 * Helpers are provided for a number of standard MIPI DSI command as well as a
46 * subset of the MIPI DCS command set.
49 static int mipi_dsi_device_match(struct device
*dev
, struct device_driver
*drv
)
51 struct mipi_dsi_device
*dsi
= to_mipi_dsi_device(dev
);
53 /* attempt OF style match */
54 if (of_driver_match_device(dev
, drv
))
57 /* compare DSI device and driver names */
58 if (!strcmp(dsi
->name
, drv
->name
))
64 static int mipi_dsi_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
66 struct mipi_dsi_device
*dsi
= to_mipi_dsi_device(dev
);
69 err
= of_device_uevent_modalias(dev
, env
);
73 add_uevent_var(env
, "MODALIAS=%s%s", MIPI_DSI_MODULE_PREFIX
,
79 static const struct dev_pm_ops mipi_dsi_device_pm_ops
= {
80 .runtime_suspend
= pm_generic_runtime_suspend
,
81 .runtime_resume
= pm_generic_runtime_resume
,
82 .suspend
= pm_generic_suspend
,
83 .resume
= pm_generic_resume
,
84 .freeze
= pm_generic_freeze
,
85 .thaw
= pm_generic_thaw
,
86 .poweroff
= pm_generic_poweroff
,
87 .restore
= pm_generic_restore
,
90 static struct bus_type mipi_dsi_bus_type
= {
92 .match
= mipi_dsi_device_match
,
93 .uevent
= mipi_dsi_uevent
,
94 .pm
= &mipi_dsi_device_pm_ops
,
98 * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
100 * @np: device tree node
102 * Return: A pointer to the MIPI DSI device corresponding to @np or NULL if no
103 * such device exists (or has not been registered yet).
105 struct mipi_dsi_device
*of_find_mipi_dsi_device_by_node(struct device_node
*np
)
109 dev
= bus_find_device_by_of_node(&mipi_dsi_bus_type
, np
);
111 return dev
? to_mipi_dsi_device(dev
) : NULL
;
113 EXPORT_SYMBOL(of_find_mipi_dsi_device_by_node
);
115 static void mipi_dsi_dev_release(struct device
*dev
)
117 struct mipi_dsi_device
*dsi
= to_mipi_dsi_device(dev
);
119 of_node_put(dev
->of_node
);
123 static const struct device_type mipi_dsi_device_type
= {
124 .release
= mipi_dsi_dev_release
,
127 static struct mipi_dsi_device
*mipi_dsi_device_alloc(struct mipi_dsi_host
*host
)
129 struct mipi_dsi_device
*dsi
;
131 dsi
= kzalloc(sizeof(*dsi
), GFP_KERNEL
);
133 return ERR_PTR(-ENOMEM
);
136 dsi
->dev
.bus
= &mipi_dsi_bus_type
;
137 dsi
->dev
.parent
= host
->dev
;
138 dsi
->dev
.type
= &mipi_dsi_device_type
;
140 device_initialize(&dsi
->dev
);
145 static int mipi_dsi_device_add(struct mipi_dsi_device
*dsi
)
147 struct mipi_dsi_host
*host
= dsi
->host
;
149 dev_set_name(&dsi
->dev
, "%s.%d", dev_name(host
->dev
), dsi
->channel
);
151 return device_add(&dsi
->dev
);
154 #if IS_ENABLED(CONFIG_OF)
155 static struct mipi_dsi_device
*
156 of_mipi_dsi_device_add(struct mipi_dsi_host
*host
, struct device_node
*node
)
158 struct device
*dev
= host
->dev
;
159 struct mipi_dsi_device_info info
= { };
163 if (of_modalias_node(node
, info
.type
, sizeof(info
.type
)) < 0) {
164 dev_err(dev
, "modalias failure on %pOF\n", node
);
165 return ERR_PTR(-EINVAL
);
168 ret
= of_property_read_u32(node
, "reg", ®
);
170 dev_err(dev
, "device node %pOF has no valid reg property: %d\n",
172 return ERR_PTR(-EINVAL
);
176 info
.node
= of_node_get(node
);
178 return mipi_dsi_device_register_full(host
, &info
);
181 static struct mipi_dsi_device
*
182 of_mipi_dsi_device_add(struct mipi_dsi_host
*host
, struct device_node
*node
)
184 return ERR_PTR(-ENODEV
);
189 * mipi_dsi_device_register_full - create a MIPI DSI device
190 * @host: DSI host to which this device is connected
191 * @info: pointer to template containing DSI device information
193 * Create a MIPI DSI device by using the device information provided by
194 * mipi_dsi_device_info template
197 * A pointer to the newly created MIPI DSI device, or, a pointer encoded
200 struct mipi_dsi_device
*
201 mipi_dsi_device_register_full(struct mipi_dsi_host
*host
,
202 const struct mipi_dsi_device_info
*info
)
204 struct mipi_dsi_device
*dsi
;
205 struct device
*dev
= host
->dev
;
209 dev_err(dev
, "invalid mipi_dsi_device_info pointer\n");
210 return ERR_PTR(-EINVAL
);
213 if (info
->channel
> 3) {
214 dev_err(dev
, "invalid virtual channel: %u\n", info
->channel
);
215 return ERR_PTR(-EINVAL
);
218 dsi
= mipi_dsi_device_alloc(host
);
220 dev_err(dev
, "failed to allocate DSI device %ld\n",
225 dsi
->dev
.of_node
= info
->node
;
226 dsi
->channel
= info
->channel
;
227 strlcpy(dsi
->name
, info
->type
, sizeof(dsi
->name
));
229 ret
= mipi_dsi_device_add(dsi
);
231 dev_err(dev
, "failed to add DSI device %d\n", ret
);
238 EXPORT_SYMBOL(mipi_dsi_device_register_full
);
241 * mipi_dsi_device_unregister - unregister MIPI DSI device
242 * @dsi: DSI peripheral device
244 void mipi_dsi_device_unregister(struct mipi_dsi_device
*dsi
)
246 device_unregister(&dsi
->dev
);
248 EXPORT_SYMBOL(mipi_dsi_device_unregister
);
250 static DEFINE_MUTEX(host_lock
);
251 static LIST_HEAD(host_list
);
254 * of_find_mipi_dsi_host_by_node() - find the MIPI DSI host matching a
256 * @node: device tree node
259 * A pointer to the MIPI DSI host corresponding to @node or NULL if no
260 * such device exists (or has not been registered yet).
262 struct mipi_dsi_host
*of_find_mipi_dsi_host_by_node(struct device_node
*node
)
264 struct mipi_dsi_host
*host
;
266 mutex_lock(&host_lock
);
268 list_for_each_entry(host
, &host_list
, list
) {
269 if (host
->dev
->of_node
== node
) {
270 mutex_unlock(&host_lock
);
275 mutex_unlock(&host_lock
);
279 EXPORT_SYMBOL(of_find_mipi_dsi_host_by_node
);
281 int mipi_dsi_host_register(struct mipi_dsi_host
*host
)
283 struct device_node
*node
;
285 for_each_available_child_of_node(host
->dev
->of_node
, node
) {
286 /* skip nodes without reg property */
287 if (!of_find_property(node
, "reg", NULL
))
289 of_mipi_dsi_device_add(host
, node
);
292 mutex_lock(&host_lock
);
293 list_add_tail(&host
->list
, &host_list
);
294 mutex_unlock(&host_lock
);
298 EXPORT_SYMBOL(mipi_dsi_host_register
);
300 static int mipi_dsi_remove_device_fn(struct device
*dev
, void *priv
)
302 struct mipi_dsi_device
*dsi
= to_mipi_dsi_device(dev
);
304 mipi_dsi_device_unregister(dsi
);
309 void mipi_dsi_host_unregister(struct mipi_dsi_host
*host
)
311 device_for_each_child(host
->dev
, NULL
, mipi_dsi_remove_device_fn
);
313 mutex_lock(&host_lock
);
314 list_del_init(&host
->list
);
315 mutex_unlock(&host_lock
);
317 EXPORT_SYMBOL(mipi_dsi_host_unregister
);
320 * mipi_dsi_attach - attach a DSI device to its DSI host
321 * @dsi: DSI peripheral
323 int mipi_dsi_attach(struct mipi_dsi_device
*dsi
)
325 const struct mipi_dsi_host_ops
*ops
= dsi
->host
->ops
;
327 if (!ops
|| !ops
->attach
)
330 return ops
->attach(dsi
->host
, dsi
);
332 EXPORT_SYMBOL(mipi_dsi_attach
);
335 * mipi_dsi_detach - detach a DSI device from its DSI host
336 * @dsi: DSI peripheral
338 int mipi_dsi_detach(struct mipi_dsi_device
*dsi
)
340 const struct mipi_dsi_host_ops
*ops
= dsi
->host
->ops
;
342 if (!ops
|| !ops
->detach
)
345 return ops
->detach(dsi
->host
, dsi
);
347 EXPORT_SYMBOL(mipi_dsi_detach
);
349 static ssize_t
mipi_dsi_device_transfer(struct mipi_dsi_device
*dsi
,
350 struct mipi_dsi_msg
*msg
)
352 const struct mipi_dsi_host_ops
*ops
= dsi
->host
->ops
;
354 if (!ops
|| !ops
->transfer
)
357 if (dsi
->mode_flags
& MIPI_DSI_MODE_LPM
)
358 msg
->flags
|= MIPI_DSI_MSG_USE_LPM
;
360 return ops
->transfer(dsi
->host
, msg
);
364 * mipi_dsi_packet_format_is_short - check if a packet is of the short format
365 * @type: MIPI DSI data type of the packet
367 * Return: true if the packet for the given data type is a short packet, false
370 bool mipi_dsi_packet_format_is_short(u8 type
)
373 case MIPI_DSI_V_SYNC_START
:
374 case MIPI_DSI_V_SYNC_END
:
375 case MIPI_DSI_H_SYNC_START
:
376 case MIPI_DSI_H_SYNC_END
:
377 case MIPI_DSI_COMPRESSION_MODE
:
378 case MIPI_DSI_END_OF_TRANSMISSION
:
379 case MIPI_DSI_COLOR_MODE_OFF
:
380 case MIPI_DSI_COLOR_MODE_ON
:
381 case MIPI_DSI_SHUTDOWN_PERIPHERAL
:
382 case MIPI_DSI_TURN_ON_PERIPHERAL
:
383 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM
:
384 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM
:
385 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM
:
386 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM
:
387 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM
:
388 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM
:
389 case MIPI_DSI_DCS_SHORT_WRITE
:
390 case MIPI_DSI_DCS_SHORT_WRITE_PARAM
:
391 case MIPI_DSI_DCS_READ
:
392 case MIPI_DSI_EXECUTE_QUEUE
:
393 case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE
:
399 EXPORT_SYMBOL(mipi_dsi_packet_format_is_short
);
402 * mipi_dsi_packet_format_is_long - check if a packet is of the long format
403 * @type: MIPI DSI data type of the packet
405 * Return: true if the packet for the given data type is a long packet, false
408 bool mipi_dsi_packet_format_is_long(u8 type
)
411 case MIPI_DSI_NULL_PACKET
:
412 case MIPI_DSI_BLANKING_PACKET
:
413 case MIPI_DSI_GENERIC_LONG_WRITE
:
414 case MIPI_DSI_DCS_LONG_WRITE
:
415 case MIPI_DSI_PICTURE_PARAMETER_SET
:
416 case MIPI_DSI_COMPRESSED_PIXEL_STREAM
:
417 case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20
:
418 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24
:
419 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16
:
420 case MIPI_DSI_PACKED_PIXEL_STREAM_30
:
421 case MIPI_DSI_PACKED_PIXEL_STREAM_36
:
422 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12
:
423 case MIPI_DSI_PACKED_PIXEL_STREAM_16
:
424 case MIPI_DSI_PACKED_PIXEL_STREAM_18
:
425 case MIPI_DSI_PIXEL_STREAM_3BYTE_18
:
426 case MIPI_DSI_PACKED_PIXEL_STREAM_24
:
432 EXPORT_SYMBOL(mipi_dsi_packet_format_is_long
);
435 * mipi_dsi_create_packet - create a packet from a message according to the
437 * @packet: pointer to a DSI packet structure
438 * @msg: message to translate into a packet
440 * Return: 0 on success or a negative error code on failure.
442 int mipi_dsi_create_packet(struct mipi_dsi_packet
*packet
,
443 const struct mipi_dsi_msg
*msg
)
448 /* do some minimum sanity checking */
449 if (!mipi_dsi_packet_format_is_short(msg
->type
) &&
450 !mipi_dsi_packet_format_is_long(msg
->type
))
453 if (msg
->channel
> 3)
456 memset(packet
, 0, sizeof(*packet
));
457 packet
->header
[0] = ((msg
->channel
& 0x3) << 6) | (msg
->type
& 0x3f);
459 /* TODO: compute ECC if hardware support is not available */
462 * Long write packets contain the word count in header bytes 1 and 2.
463 * The payload follows the header and is word count bytes long.
465 * Short write packets encode up to two parameters in header bytes 1
468 if (mipi_dsi_packet_format_is_long(msg
->type
)) {
469 packet
->header
[1] = (msg
->tx_len
>> 0) & 0xff;
470 packet
->header
[2] = (msg
->tx_len
>> 8) & 0xff;
472 packet
->payload_length
= msg
->tx_len
;
473 packet
->payload
= msg
->tx_buf
;
475 const u8
*tx
= msg
->tx_buf
;
477 packet
->header
[1] = (msg
->tx_len
> 0) ? tx
[0] : 0;
478 packet
->header
[2] = (msg
->tx_len
> 1) ? tx
[1] : 0;
481 packet
->size
= sizeof(packet
->header
) + packet
->payload_length
;
485 EXPORT_SYMBOL(mipi_dsi_create_packet
);
488 * mipi_dsi_shutdown_peripheral() - sends a Shutdown Peripheral command
489 * @dsi: DSI peripheral device
491 * Return: 0 on success or a negative error code on failure.
493 int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device
*dsi
)
495 struct mipi_dsi_msg msg
= {
496 .channel
= dsi
->channel
,
497 .type
= MIPI_DSI_SHUTDOWN_PERIPHERAL
,
498 .tx_buf
= (u8
[2]) { 0, 0 },
501 int ret
= mipi_dsi_device_transfer(dsi
, &msg
);
503 return (ret
< 0) ? ret
: 0;
505 EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral
);
508 * mipi_dsi_turn_on_peripheral() - sends a Turn On Peripheral command
509 * @dsi: DSI peripheral device
511 * Return: 0 on success or a negative error code on failure.
513 int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device
*dsi
)
515 struct mipi_dsi_msg msg
= {
516 .channel
= dsi
->channel
,
517 .type
= MIPI_DSI_TURN_ON_PERIPHERAL
,
518 .tx_buf
= (u8
[2]) { 0, 0 },
521 int ret
= mipi_dsi_device_transfer(dsi
, &msg
);
523 return (ret
< 0) ? ret
: 0;
525 EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral
);
528 * mipi_dsi_set_maximum_return_packet_size() - specify the maximum size of the
529 * the payload in a long packet transmitted from the peripheral back to the
531 * @dsi: DSI peripheral device
532 * @value: the maximum size of the payload
534 * Return: 0 on success or a negative error code on failure.
536 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device
*dsi
,
539 u8 tx
[2] = { value
& 0xff, value
>> 8 };
540 struct mipi_dsi_msg msg
= {
541 .channel
= dsi
->channel
,
542 .type
= MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE
,
543 .tx_len
= sizeof(tx
),
546 int ret
= mipi_dsi_device_transfer(dsi
, &msg
);
548 return (ret
< 0) ? ret
: 0;
550 EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size
);
553 * mipi_dsi_compression_mode() - enable/disable DSC on the peripheral
554 * @dsi: DSI peripheral device
555 * @enable: Whether to enable or disable the DSC
557 * Enable or disable Display Stream Compression on the peripheral using the
558 * default Picture Parameter Set and VESA DSC 1.1 algorithm.
560 * Return: 0 on success or a negative error code on failure.
562 ssize_t
mipi_dsi_compression_mode(struct mipi_dsi_device
*dsi
, bool enable
)
564 /* Note: Needs updating for non-default PPS or algorithm */
565 u8 tx
[2] = { enable
<< 0, 0 };
566 struct mipi_dsi_msg msg
= {
567 .channel
= dsi
->channel
,
568 .type
= MIPI_DSI_COMPRESSION_MODE
,
569 .tx_len
= sizeof(tx
),
572 int ret
= mipi_dsi_device_transfer(dsi
, &msg
);
574 return (ret
< 0) ? ret
: 0;
576 EXPORT_SYMBOL(mipi_dsi_compression_mode
);
579 * mipi_dsi_picture_parameter_set() - transmit the DSC PPS to the peripheral
580 * @dsi: DSI peripheral device
581 * @pps: VESA DSC 1.1 Picture Parameter Set
583 * Transmit the VESA DSC 1.1 Picture Parameter Set to the peripheral.
585 * Return: 0 on success or a negative error code on failure.
587 ssize_t
mipi_dsi_picture_parameter_set(struct mipi_dsi_device
*dsi
,
588 const struct drm_dsc_picture_parameter_set
*pps
)
590 struct mipi_dsi_msg msg
= {
591 .channel
= dsi
->channel
,
592 .type
= MIPI_DSI_PICTURE_PARAMETER_SET
,
593 .tx_len
= sizeof(*pps
),
596 int ret
= mipi_dsi_device_transfer(dsi
, &msg
);
598 return (ret
< 0) ? ret
: 0;
600 EXPORT_SYMBOL(mipi_dsi_picture_parameter_set
);
603 * mipi_dsi_generic_write() - transmit data using a generic write packet
604 * @dsi: DSI peripheral device
605 * @payload: buffer containing the payload
606 * @size: size of payload buffer
608 * This function will automatically choose the right data type depending on
609 * the payload length.
611 * Return: The number of bytes transmitted on success or a negative error code
614 ssize_t
mipi_dsi_generic_write(struct mipi_dsi_device
*dsi
, const void *payload
,
617 struct mipi_dsi_msg msg
= {
618 .channel
= dsi
->channel
,
625 msg
.type
= MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM
;
629 msg
.type
= MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM
;
633 msg
.type
= MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM
;
637 msg
.type
= MIPI_DSI_GENERIC_LONG_WRITE
;
641 return mipi_dsi_device_transfer(dsi
, &msg
);
643 EXPORT_SYMBOL(mipi_dsi_generic_write
);
646 * mipi_dsi_generic_read() - receive data using a generic read packet
647 * @dsi: DSI peripheral device
648 * @params: buffer containing the request parameters
649 * @num_params: number of request parameters
650 * @data: buffer in which to return the received data
651 * @size: size of receive buffer
653 * This function will automatically choose the right data type depending on
654 * the number of parameters passed in.
656 * Return: The number of bytes successfully read or a negative error code on
659 ssize_t
mipi_dsi_generic_read(struct mipi_dsi_device
*dsi
, const void *params
,
660 size_t num_params
, void *data
, size_t size
)
662 struct mipi_dsi_msg msg
= {
663 .channel
= dsi
->channel
,
664 .tx_len
= num_params
,
670 switch (num_params
) {
672 msg
.type
= MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM
;
676 msg
.type
= MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM
;
680 msg
.type
= MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM
;
687 return mipi_dsi_device_transfer(dsi
, &msg
);
689 EXPORT_SYMBOL(mipi_dsi_generic_read
);
692 * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload
693 * @dsi: DSI peripheral device
694 * @data: buffer containing data to be transmitted
695 * @len: size of transmission buffer
697 * This function will automatically choose the right data type depending on
698 * the command payload length.
700 * Return: The number of bytes successfully transmitted or a negative error
703 ssize_t
mipi_dsi_dcs_write_buffer(struct mipi_dsi_device
*dsi
,
704 const void *data
, size_t len
)
706 struct mipi_dsi_msg msg
= {
707 .channel
= dsi
->channel
,
717 msg
.type
= MIPI_DSI_DCS_SHORT_WRITE
;
721 msg
.type
= MIPI_DSI_DCS_SHORT_WRITE_PARAM
;
725 msg
.type
= MIPI_DSI_DCS_LONG_WRITE
;
729 return mipi_dsi_device_transfer(dsi
, &msg
);
731 EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer
);
734 * mipi_dsi_dcs_write() - send DCS write command
735 * @dsi: DSI peripheral device
737 * @data: buffer containing the command payload
738 * @len: command payload length
740 * This function will automatically choose the right data type depending on
741 * the command payload length.
743 * Return: The number of bytes successfully transmitted or a negative error
746 ssize_t
mipi_dsi_dcs_write(struct mipi_dsi_device
*dsi
, u8 cmd
,
747 const void *data
, size_t len
)
756 tx
= kmalloc(size
, GFP_KERNEL
);
760 /* concatenate the DCS command byte and the payload */
762 memcpy(&tx
[1], data
, len
);
768 err
= mipi_dsi_dcs_write_buffer(dsi
, tx
, size
);
775 EXPORT_SYMBOL(mipi_dsi_dcs_write
);
778 * mipi_dsi_dcs_read() - send DCS read request command
779 * @dsi: DSI peripheral device
781 * @data: buffer in which to receive data
782 * @len: size of receive buffer
784 * Return: The number of bytes read or a negative error code on failure.
786 ssize_t
mipi_dsi_dcs_read(struct mipi_dsi_device
*dsi
, u8 cmd
, void *data
,
789 struct mipi_dsi_msg msg
= {
790 .channel
= dsi
->channel
,
791 .type
= MIPI_DSI_DCS_READ
,
798 return mipi_dsi_device_transfer(dsi
, &msg
);
800 EXPORT_SYMBOL(mipi_dsi_dcs_read
);
803 * mipi_dsi_dcs_nop() - send DCS nop packet
804 * @dsi: DSI peripheral device
806 * Return: 0 on success or a negative error code on failure.
808 int mipi_dsi_dcs_nop(struct mipi_dsi_device
*dsi
)
812 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_NOP
, NULL
, 0);
818 EXPORT_SYMBOL(mipi_dsi_dcs_nop
);
821 * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module
822 * @dsi: DSI peripheral device
824 * Return: 0 on success or a negative error code on failure.
826 int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device
*dsi
)
830 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SOFT_RESET
, NULL
, 0);
836 EXPORT_SYMBOL(mipi_dsi_dcs_soft_reset
);
839 * mipi_dsi_dcs_get_power_mode() - query the display module's current power
841 * @dsi: DSI peripheral device
842 * @mode: return location for the current power mode
844 * Return: 0 on success or a negative error code on failure.
846 int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device
*dsi
, u8
*mode
)
850 err
= mipi_dsi_dcs_read(dsi
, MIPI_DCS_GET_POWER_MODE
, mode
,
861 EXPORT_SYMBOL(mipi_dsi_dcs_get_power_mode
);
864 * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image
865 * data used by the interface
866 * @dsi: DSI peripheral device
867 * @format: return location for the pixel format
869 * Return: 0 on success or a negative error code on failure.
871 int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device
*dsi
, u8
*format
)
875 err
= mipi_dsi_dcs_read(dsi
, MIPI_DCS_GET_PIXEL_FORMAT
, format
,
886 EXPORT_SYMBOL(mipi_dsi_dcs_get_pixel_format
);
889 * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the
890 * display module except interface communication
891 * @dsi: DSI peripheral device
893 * Return: 0 on success or a negative error code on failure.
895 int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device
*dsi
)
899 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_ENTER_SLEEP_MODE
, NULL
, 0);
905 EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode
);
908 * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
910 * @dsi: DSI peripheral device
912 * Return: 0 on success or a negative error code on failure.
914 int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device
*dsi
)
918 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_EXIT_SLEEP_MODE
, NULL
, 0);
924 EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode
);
927 * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
929 * @dsi: DSI peripheral device
931 * Return: 0 on success or a negative error code on failure.
933 int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device
*dsi
)
937 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_DISPLAY_OFF
, NULL
, 0);
943 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off
);
946 * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
948 * @dsi: DSI peripheral device
950 * Return: 0 on success or a negative error code on failure
952 int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device
*dsi
)
956 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_DISPLAY_ON
, NULL
, 0);
962 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_on
);
965 * mipi_dsi_dcs_set_column_address() - define the column extent of the frame
966 * memory accessed by the host processor
967 * @dsi: DSI peripheral device
968 * @start: first column of frame memory
969 * @end: last column of frame memory
971 * Return: 0 on success or a negative error code on failure.
973 int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device
*dsi
, u16 start
,
976 u8 payload
[4] = { start
>> 8, start
& 0xff, end
>> 8, end
& 0xff };
979 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_COLUMN_ADDRESS
, payload
,
986 EXPORT_SYMBOL(mipi_dsi_dcs_set_column_address
);
989 * mipi_dsi_dcs_set_page_address() - define the page extent of the frame
990 * memory accessed by the host processor
991 * @dsi: DSI peripheral device
992 * @start: first page of frame memory
993 * @end: last page of frame memory
995 * Return: 0 on success or a negative error code on failure.
997 int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device
*dsi
, u16 start
,
1000 u8 payload
[4] = { start
>> 8, start
& 0xff, end
>> 8, end
& 0xff };
1003 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_PAGE_ADDRESS
, payload
,
1010 EXPORT_SYMBOL(mipi_dsi_dcs_set_page_address
);
1013 * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect
1014 * output signal on the TE signal line
1015 * @dsi: DSI peripheral device
1017 * Return: 0 on success or a negative error code on failure
1019 int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device
*dsi
)
1023 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_TEAR_OFF
, NULL
, 0);
1029 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_off
);
1032 * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect
1033 * output signal on the TE signal line.
1034 * @dsi: DSI peripheral device
1035 * @mode: the Tearing Effect Output Line mode
1037 * Return: 0 on success or a negative error code on failure
1039 int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device
*dsi
,
1040 enum mipi_dsi_dcs_tear_mode mode
)
1045 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_TEAR_ON
, &value
,
1052 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_on
);
1055 * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image
1056 * data used by the interface
1057 * @dsi: DSI peripheral device
1058 * @format: pixel format
1060 * Return: 0 on success or a negative error code on failure.
1062 int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device
*dsi
, u8 format
)
1066 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_PIXEL_FORMAT
, &format
,
1073 EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format
);
1076 * mipi_dsi_dcs_set_tear_scanline() - set the scanline to use as trigger for
1077 * the Tearing Effect output signal of the display module
1078 * @dsi: DSI peripheral device
1079 * @scanline: scanline to use as trigger
1081 * Return: 0 on success or a negative error code on failure
1083 int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device
*dsi
, u16 scanline
)
1085 u8 payload
[3] = { MIPI_DCS_SET_TEAR_SCANLINE
, scanline
>> 8,
1089 err
= mipi_dsi_generic_write(dsi
, payload
, sizeof(payload
));
1095 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_scanline
);
1098 * mipi_dsi_dcs_set_display_brightness() - sets the brightness value of the
1100 * @dsi: DSI peripheral device
1101 * @brightness: brightness value
1103 * Return: 0 on success or a negative error code on failure.
1105 int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device
*dsi
,
1108 u8 payload
[2] = { brightness
& 0xff, brightness
>> 8 };
1111 err
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_DISPLAY_BRIGHTNESS
,
1112 payload
, sizeof(payload
));
1118 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_brightness
);
1121 * mipi_dsi_dcs_get_display_brightness() - gets the current brightness value
1123 * @dsi: DSI peripheral device
1124 * @brightness: brightness value
1126 * Return: 0 on success or a negative error code on failure.
1128 int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device
*dsi
,
1133 err
= mipi_dsi_dcs_read(dsi
, MIPI_DCS_GET_DISPLAY_BRIGHTNESS
,
1134 brightness
, sizeof(*brightness
));
1144 EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness
);
1146 static int mipi_dsi_drv_probe(struct device
*dev
)
1148 struct mipi_dsi_driver
*drv
= to_mipi_dsi_driver(dev
->driver
);
1149 struct mipi_dsi_device
*dsi
= to_mipi_dsi_device(dev
);
1151 return drv
->probe(dsi
);
1154 static int mipi_dsi_drv_remove(struct device
*dev
)
1156 struct mipi_dsi_driver
*drv
= to_mipi_dsi_driver(dev
->driver
);
1157 struct mipi_dsi_device
*dsi
= to_mipi_dsi_device(dev
);
1159 return drv
->remove(dsi
);
1162 static void mipi_dsi_drv_shutdown(struct device
*dev
)
1164 struct mipi_dsi_driver
*drv
= to_mipi_dsi_driver(dev
->driver
);
1165 struct mipi_dsi_device
*dsi
= to_mipi_dsi_device(dev
);
1171 * mipi_dsi_driver_register_full() - register a driver for DSI devices
1172 * @drv: DSI driver structure
1173 * @owner: owner module
1175 * Return: 0 on success or a negative error code on failure.
1177 int mipi_dsi_driver_register_full(struct mipi_dsi_driver
*drv
,
1178 struct module
*owner
)
1180 drv
->driver
.bus
= &mipi_dsi_bus_type
;
1181 drv
->driver
.owner
= owner
;
1184 drv
->driver
.probe
= mipi_dsi_drv_probe
;
1186 drv
->driver
.remove
= mipi_dsi_drv_remove
;
1188 drv
->driver
.shutdown
= mipi_dsi_drv_shutdown
;
1190 return driver_register(&drv
->driver
);
1192 EXPORT_SYMBOL(mipi_dsi_driver_register_full
);
1195 * mipi_dsi_driver_unregister() - unregister a driver for DSI devices
1196 * @drv: DSI driver structure
1198 * Return: 0 on success or a negative error code on failure.
1200 void mipi_dsi_driver_unregister(struct mipi_dsi_driver
*drv
)
1202 driver_unregister(&drv
->driver
);
1204 EXPORT_SYMBOL(mipi_dsi_driver_unregister
);
1206 static int __init
mipi_dsi_bus_init(void)
1208 return bus_register(&mipi_dsi_bus_type
);
1210 postcore_initcall(mipi_dsi_bus_init
);
1212 MODULE_AUTHOR("Andrzej Hajda <a.hajda@samsung.com>");
1213 MODULE_DESCRIPTION("MIPI DSI Bus");
1214 MODULE_LICENSE("GPL and additional rights");