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 <video/mipi_display.h>
41 * These functions contain some common logic and helpers to deal with MIPI DSI
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 const struct device_type mipi_dsi_device_type;
50 static int mipi_dsi_device_match(struct device *dev, struct device_driver *drv)
52 struct mipi_dsi_device *dsi;
54 dsi = dev->type == &mipi_dsi_device_type ?
55 to_mipi_dsi_device(dev) : NULL;
60 if (of_driver_match_device(dev, drv))
63 if (!strcmp(drv->name, "mipi_dsi_dummy") &&
64 !strcmp(dsi->name, "dummy"))
70 static const struct dev_pm_ops mipi_dsi_device_pm_ops = {
71 .runtime_suspend = pm_generic_runtime_suspend,
72 .runtime_resume = pm_generic_runtime_resume,
73 .suspend = pm_generic_suspend,
74 .resume = pm_generic_resume,
75 .freeze = pm_generic_freeze,
76 .thaw = pm_generic_thaw,
77 .poweroff = pm_generic_poweroff,
78 .restore = pm_generic_restore,
81 static struct bus_type mipi_dsi_bus_type = {
83 .match = mipi_dsi_device_match,
84 .pm = &mipi_dsi_device_pm_ops,
87 static int of_device_match(struct device *dev, void *data)
89 return dev->of_node == data;
93 * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
95 * @np: device tree node
97 * Return: A pointer to the MIPI DSI device corresponding to @np or NULL if no
98 * such device exists (or has not been registered yet).
100 struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
104 dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
106 return dev ? to_mipi_dsi_device(dev) : NULL;
108 EXPORT_SYMBOL(of_find_mipi_dsi_device_by_node);
110 static void mipi_dsi_dev_release(struct device *dev)
112 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
114 of_node_put(dev->of_node);
118 static const struct device_type mipi_dsi_device_type = {
119 .release = mipi_dsi_dev_release,
122 struct mipi_dsi_device_info {
123 char name[DSI_DEV_NAME_SIZE];
125 struct device_node *node;
128 static int __dsi_check_chan_busy(struct device *dev, void *data)
130 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
131 u32 reg = *(u32 *) data;
133 if (dsi && dsi->channel == reg)
139 static int mipi_dsi_check_chan_busy(struct mipi_dsi_host *host, u32 reg)
141 return device_for_each_child(host->dev, ®, __dsi_check_chan_busy);
144 static struct mipi_dsi_device *
145 mipi_dsi_device_new(struct mipi_dsi_host *host,
146 struct mipi_dsi_device_info *info)
148 struct device *dev = host->dev;
149 struct mipi_dsi_device *dsi;
153 dev_err(dev, "dsi device %s has invalid channel value: %u\n",
154 info->name, info->reg);
155 return ERR_PTR(-EINVAL);
158 dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
160 return ERR_PTR(-ENOMEM);
163 dsi->dev.bus = &mipi_dsi_bus_type;
164 dsi->dev.parent = host->dev;
165 dsi->dev.type = &mipi_dsi_device_type;
166 dsi->dev.of_node = info->node;
167 dsi->channel = info->reg;
168 strlcpy(dsi->name, info->name, sizeof(dsi->name));
170 dev_set_name(&dsi->dev, "%s.%d", dev_name(host->dev), info->reg);
172 r = mipi_dsi_check_chan_busy(host, info->reg);
176 r = device_register(&dsi->dev);
186 #if IS_ENABLED(CONFIG_OF)
187 static struct mipi_dsi_device *
188 of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
190 struct device *dev = host->dev;
191 struct mipi_dsi_device_info info = { };
194 if (of_modalias_node(node, info.name, sizeof(info.name)) < 0) {
195 dev_err(dev, "modalias failure on %s\n", node->full_name);
196 return ERR_PTR(-EINVAL);
199 ret = of_property_read_u32(node, "reg", &info.reg);
201 dev_err(dev, "device node %s has no valid reg property: %d\n",
202 node->full_name, ret);
203 return ERR_PTR(-EINVAL);
206 info.node = of_node_get(node);
208 return mipi_dsi_device_new(host, &info);
211 static struct mipi_dsi_device *
212 of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
218 static struct mipi_dsi_driver dummy_dsi_driver = {
219 .driver.name = "mipi_dsi_dummy",
222 struct mipi_dsi_device *mipi_dsi_new_dummy(struct mipi_dsi_host *host, u32 reg)
224 struct mipi_dsi_device_info info = { "dummy", reg, NULL, };
226 return mipi_dsi_device_new(host, &info);
228 EXPORT_SYMBOL(mipi_dsi_new_dummy);
230 void mipi_dsi_unregister_device(struct mipi_dsi_device *dsi)
233 device_unregister(&dsi->dev);
235 EXPORT_SYMBOL(mipi_dsi_unregister_device);
237 static DEFINE_MUTEX(host_lock);
238 static LIST_HEAD(host_list);
240 struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node)
242 struct mipi_dsi_host *host;
244 mutex_lock(&host_lock);
246 list_for_each_entry(host, &host_list, list) {
247 if (host->dev->of_node == node) {
248 mutex_unlock(&host_lock);
253 mutex_unlock(&host_lock);
257 EXPORT_SYMBOL(of_find_mipi_dsi_host_by_node);
259 int mipi_dsi_host_register(struct mipi_dsi_host *host)
261 struct device_node *node;
263 for_each_available_child_of_node(host->dev->of_node, node) {
264 /* skip nodes without reg property */
265 if (!of_find_property(node, "reg", NULL))
267 of_mipi_dsi_device_add(host, node);
270 mutex_lock(&host_lock);
271 list_add_tail(&host->list, &host_list);
272 mutex_unlock(&host_lock);
276 EXPORT_SYMBOL(mipi_dsi_host_register);
278 static int mipi_dsi_remove_device_fn(struct device *dev, void *priv)
280 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
282 device_unregister(&dsi->dev);
287 void mipi_dsi_host_unregister(struct mipi_dsi_host *host)
289 device_for_each_child(host->dev, NULL, mipi_dsi_remove_device_fn);
291 mutex_lock(&host_lock);
292 list_del_init(&host->list);
293 mutex_unlock(&host_lock);
295 EXPORT_SYMBOL(mipi_dsi_host_unregister);
298 * mipi_dsi_attach - attach a DSI device to its DSI host
299 * @dsi: DSI peripheral
301 int mipi_dsi_attach(struct mipi_dsi_device *dsi)
303 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
305 if (!ops || !ops->attach)
308 return ops->attach(dsi->host, dsi);
310 EXPORT_SYMBOL(mipi_dsi_attach);
313 * mipi_dsi_detach - detach a DSI device from its DSI host
314 * @dsi: DSI peripheral
316 int mipi_dsi_detach(struct mipi_dsi_device *dsi)
318 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
320 if (!ops || !ops->detach)
323 return ops->detach(dsi->host, dsi);
325 EXPORT_SYMBOL(mipi_dsi_detach);
327 static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi,
328 struct mipi_dsi_msg *msg)
330 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
332 if (!ops || !ops->transfer)
335 if (dsi->mode_flags & MIPI_DSI_MODE_LPM)
336 msg->flags |= MIPI_DSI_MSG_USE_LPM;
338 return ops->transfer(dsi->host, msg);
342 * mipi_dsi_packet_format_is_short - check if a packet is of the short format
343 * @type: MIPI DSI data type of the packet
345 * Return: true if the packet for the given data type is a short packet, false
348 bool mipi_dsi_packet_format_is_short(u8 type)
351 case MIPI_DSI_V_SYNC_START:
352 case MIPI_DSI_V_SYNC_END:
353 case MIPI_DSI_H_SYNC_START:
354 case MIPI_DSI_H_SYNC_END:
355 case MIPI_DSI_END_OF_TRANSMISSION:
356 case MIPI_DSI_COLOR_MODE_OFF:
357 case MIPI_DSI_COLOR_MODE_ON:
358 case MIPI_DSI_SHUTDOWN_PERIPHERAL:
359 case MIPI_DSI_TURN_ON_PERIPHERAL:
360 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
361 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
362 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
363 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
364 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
365 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
366 case MIPI_DSI_DCS_SHORT_WRITE:
367 case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
368 case MIPI_DSI_DCS_READ:
369 case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
375 EXPORT_SYMBOL(mipi_dsi_packet_format_is_short);
378 * mipi_dsi_packet_format_is_long - check if a packet is of the long format
379 * @type: MIPI DSI data type of the packet
381 * Return: true if the packet for the given data type is a long packet, false
384 bool mipi_dsi_packet_format_is_long(u8 type)
387 case MIPI_DSI_NULL_PACKET:
388 case MIPI_DSI_BLANKING_PACKET:
389 case MIPI_DSI_GENERIC_LONG_WRITE:
390 case MIPI_DSI_DCS_LONG_WRITE:
391 case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20:
392 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24:
393 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16:
394 case MIPI_DSI_PACKED_PIXEL_STREAM_30:
395 case MIPI_DSI_PACKED_PIXEL_STREAM_36:
396 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12:
397 case MIPI_DSI_PACKED_PIXEL_STREAM_16:
398 case MIPI_DSI_PACKED_PIXEL_STREAM_18:
399 case MIPI_DSI_PIXEL_STREAM_3BYTE_18:
400 case MIPI_DSI_PACKED_PIXEL_STREAM_24:
406 EXPORT_SYMBOL(mipi_dsi_packet_format_is_long);
409 * mipi_dsi_create_packet - create a packet from a message according to the
411 * @packet: pointer to a DSI packet structure
412 * @msg: message to translate into a packet
414 * Return: 0 on success or a negative error code on failure.
416 int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
417 const struct mipi_dsi_msg *msg)
422 /* do some minimum sanity checking */
423 if (!mipi_dsi_packet_format_is_short(msg->type) &&
424 !mipi_dsi_packet_format_is_long(msg->type))
427 if (msg->channel > 3)
430 memset(packet, 0, sizeof(*packet));
431 packet->header[0] = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f);
433 /* TODO: compute ECC if hardware support is not available */
436 * Long write packets contain the word count in header bytes 1 and 2.
437 * The payload follows the header and is word count bytes long.
439 * Short write packets encode up to two parameters in header bytes 1
442 if (mipi_dsi_packet_format_is_long(msg->type)) {
443 packet->header[1] = (msg->tx_len >> 0) & 0xff;
444 packet->header[2] = (msg->tx_len >> 8) & 0xff;
446 packet->payload_length = msg->tx_len;
447 packet->payload = msg->tx_buf;
449 const u8 *tx = msg->tx_buf;
451 packet->header[1] = (msg->tx_len > 0) ? tx[0] : 0;
452 packet->header[2] = (msg->tx_len > 1) ? tx[1] : 0;
455 packet->size = sizeof(packet->header) + packet->payload_length;
459 EXPORT_SYMBOL(mipi_dsi_create_packet);
462 * mipi_dsi_set_maximum_return_packet_size() - specify the maximum size of the
463 * the payload in a long packet transmitted from the peripheral back to the
465 * @dsi: DSI peripheral device
466 * @value: the maximum size of the payload
468 * Return: 0 on success or a negative error code on failure.
470 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
473 u8 tx[2] = { value & 0xff, value >> 8 };
474 struct mipi_dsi_msg msg = {
475 .channel = dsi->channel,
476 .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
477 .tx_len = sizeof(tx),
481 return mipi_dsi_device_transfer(dsi, &msg);
483 EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
486 * mipi_dsi_generic_write() - transmit data using a generic write packet
487 * @dsi: DSI peripheral device
488 * @payload: buffer containing the payload
489 * @size: size of payload buffer
491 * This function will automatically choose the right data type depending on
492 * the payload length.
494 * Return: The number of bytes transmitted on success or a negative error code
497 ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
500 struct mipi_dsi_msg msg = {
501 .channel = dsi->channel,
508 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
512 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
516 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
520 msg.type = MIPI_DSI_GENERIC_LONG_WRITE;
524 return mipi_dsi_device_transfer(dsi, &msg);
526 EXPORT_SYMBOL(mipi_dsi_generic_write);
529 * mipi_dsi_generic_read() - receive data using a generic read packet
530 * @dsi: DSI peripheral device
531 * @params: buffer containing the request parameters
532 * @num_params: number of request parameters
533 * @data: buffer in which to return the received data
534 * @size: size of receive buffer
536 * This function will automatically choose the right data type depending on
537 * the number of parameters passed in.
539 * Return: The number of bytes successfully read or a negative error code on
542 ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
543 size_t num_params, void *data, size_t size)
545 struct mipi_dsi_msg msg = {
546 .channel = dsi->channel,
547 .tx_len = num_params,
553 switch (num_params) {
555 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
559 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
563 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
570 return mipi_dsi_device_transfer(dsi, &msg);
572 EXPORT_SYMBOL(mipi_dsi_generic_read);
575 * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload
576 * @dsi: DSI peripheral device
577 * @data: buffer containing data to be transmitted
578 * @len: size of transmission buffer
580 * This function will automatically choose the right data type depending on
581 * the command payload length.
583 * Return: The number of bytes successfully transmitted or a negative error
586 ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
587 const void *data, size_t len)
589 struct mipi_dsi_msg msg = {
590 .channel = dsi->channel,
600 msg.type = MIPI_DSI_DCS_SHORT_WRITE;
604 msg.type = MIPI_DSI_DCS_SHORT_WRITE_PARAM;
608 msg.type = MIPI_DSI_DCS_LONG_WRITE;
612 return mipi_dsi_device_transfer(dsi, &msg);
614 EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer);
617 * mipi_dsi_dcs_write() - send DCS write command
618 * @dsi: DSI peripheral device
620 * @data: buffer containing the command payload
621 * @len: command payload length
623 * This function will automatically choose the right data type depending on
624 * the command payload length.
626 * Return: The number of bytes successfully transmitted or a negative error
629 ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
630 const void *data, size_t len)
639 tx = kmalloc(size, GFP_KERNEL);
643 /* concatenate the DCS command byte and the payload */
645 memcpy(&tx[1], data, len);
651 err = mipi_dsi_dcs_write_buffer(dsi, tx, size);
658 EXPORT_SYMBOL(mipi_dsi_dcs_write);
661 * mipi_dsi_dcs_read() - send DCS read request command
662 * @dsi: DSI peripheral device
664 * @data: buffer in which to receive data
665 * @len: size of receive buffer
667 * Return: The number of bytes read or a negative error code on failure.
669 ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
672 struct mipi_dsi_msg msg = {
673 .channel = dsi->channel,
674 .type = MIPI_DSI_DCS_READ,
681 return mipi_dsi_device_transfer(dsi, &msg);
683 EXPORT_SYMBOL(mipi_dsi_dcs_read);
686 * mipi_dsi_dcs_nop() - send DCS nop packet
687 * @dsi: DSI peripheral device
689 * Return: 0 on success or a negative error code on failure.
691 int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi)
695 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_NOP, NULL, 0);
701 EXPORT_SYMBOL(mipi_dsi_dcs_nop);
704 * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module
705 * @dsi: DSI peripheral device
707 * Return: 0 on success or a negative error code on failure.
709 int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi)
713 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SOFT_RESET, NULL, 0);
719 EXPORT_SYMBOL(mipi_dsi_dcs_soft_reset);
722 * mipi_dsi_dcs_get_power_mode() - query the display module's current power
724 * @dsi: DSI peripheral device
725 * @mode: return location for the current power mode
727 * Return: 0 on success or a negative error code on failure.
729 int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode)
733 err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_POWER_MODE, mode,
744 EXPORT_SYMBOL(mipi_dsi_dcs_get_power_mode);
747 * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image
748 * data used by the interface
749 * @dsi: DSI peripheral device
750 * @format: return location for the pixel format
752 * Return: 0 on success or a negative error code on failure.
754 int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format)
758 err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_PIXEL_FORMAT, format,
769 EXPORT_SYMBOL(mipi_dsi_dcs_get_pixel_format);
772 * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the
773 * display module except interface communication
774 * @dsi: DSI peripheral device
776 * Return: 0 on success or a negative error code on failure.
778 int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi)
782 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_ENTER_SLEEP_MODE, NULL, 0);
788 EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode);
791 * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
793 * @dsi: DSI peripheral device
795 * Return: 0 on success or a negative error code on failure.
797 int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi)
801 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_EXIT_SLEEP_MODE, NULL, 0);
807 EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode);
810 * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
812 * @dsi: DSI peripheral device
814 * Return: 0 on success or a negative error code on failure.
816 int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi)
820 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0);
826 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off);
829 * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
831 * @dsi: DSI peripheral device
833 * Return: 0 on success or a negative error code on failure
835 int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi)
839 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_ON, NULL, 0);
845 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_on);
848 * mipi_dsi_dcs_set_column_address() - define the column extent of the frame
849 * memory accessed by the host processor
850 * @dsi: DSI peripheral device
851 * @start: first column of frame memory
852 * @end: last column of frame memory
854 * Return: 0 on success or a negative error code on failure.
856 int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
859 u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
862 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, payload,
869 EXPORT_SYMBOL(mipi_dsi_dcs_set_column_address);
872 * mipi_dsi_dcs_set_page_address() - define the page extent of the frame
873 * memory accessed by the host processor
874 * @dsi: DSI peripheral device
875 * @start: first page of frame memory
876 * @end: last page of frame memory
878 * Return: 0 on success or a negative error code on failure.
880 int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
883 u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
886 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PAGE_ADDRESS, payload,
893 EXPORT_SYMBOL(mipi_dsi_dcs_set_page_address);
896 * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect
897 * output signal on the TE signal line
898 * @dsi: DSI peripheral device
900 * Return: 0 on success or a negative error code on failure
902 int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi)
906 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_OFF, NULL, 0);
912 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_off);
915 * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect
916 * output signal on the TE signal line.
917 * @dsi: DSI peripheral device
918 * @mode: the Tearing Effect Output Line mode
920 * Return: 0 on success or a negative error code on failure
922 int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
923 enum mipi_dsi_dcs_tear_mode mode)
928 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_ON, &value,
935 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_on);
938 * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image
939 * data used by the interface
940 * @dsi: DSI peripheral device
941 * @format: pixel format
943 * Return: 0 on success or a negative error code on failure.
945 int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format)
949 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PIXEL_FORMAT, &format,
956 EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format);
958 static int mipi_dsi_drv_probe(struct device *dev)
960 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
961 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
963 return drv->probe(dsi);
966 static int mipi_dsi_drv_remove(struct device *dev)
968 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
969 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
971 return drv->remove(dsi);
974 static void mipi_dsi_drv_shutdown(struct device *dev)
976 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
977 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
983 * mipi_dsi_driver_register_full() - register a driver for DSI devices
984 * @drv: DSI driver structure
985 * @owner: owner module
987 * Return: 0 on success or a negative error code on failure.
989 int mipi_dsi_driver_register_full(struct mipi_dsi_driver *drv,
990 struct module *owner)
992 drv->driver.bus = &mipi_dsi_bus_type;
993 drv->driver.owner = owner;
996 drv->driver.probe = mipi_dsi_drv_probe;
998 drv->driver.remove = mipi_dsi_drv_remove;
1000 drv->driver.shutdown = mipi_dsi_drv_shutdown;
1002 return driver_register(&drv->driver);
1004 EXPORT_SYMBOL(mipi_dsi_driver_register_full);
1007 * mipi_dsi_driver_unregister() - unregister a driver for DSI devices
1008 * @drv: DSI driver structure
1010 * Return: 0 on success or a negative error code on failure.
1012 void mipi_dsi_driver_unregister(struct mipi_dsi_driver *drv)
1014 driver_unregister(&drv->driver);
1016 EXPORT_SYMBOL(mipi_dsi_driver_unregister);
1018 static int __init mipi_dsi_bus_init(void)
1022 ret = bus_register(&mipi_dsi_bus_type);
1026 return mipi_dsi_driver_register(&dummy_dsi_driver);
1028 postcore_initcall(mipi_dsi_bus_init);
1030 MODULE_AUTHOR("Andrzej Hajda <a.hajda@samsung.com>");
1031 MODULE_DESCRIPTION("MIPI DSI Bus");
1032 MODULE_LICENSE("GPL and additional rights");