blob: 431e96f192883771e875e66b0f938299d9635894 [file] [log] [blame]
Andrzej Hajda068a0022013-12-04 16:35:12 +01001/*
2 * MIPI DSI Bus
3 *
4 * Copyright (C) 2012-2013, Samsung Electronics, Co., Ltd.
5 * Andrzej Hajda <a.hajda@samsung.com>
6 *
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:
14 *
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.
18 *
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.
26 */
27
28#include <drm/drm_mipi_dsi.h>
29
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>
35
36#include <video/mipi_display.h>
37
Thierry Reding009081e2014-08-05 10:41:13 +020038/**
39 * DOC: dsi helpers
40 *
41 * These functions contain some common logic and helpers to deal with MIPI DSI
42 * peripherals.
43 *
44 * Helpers are provided for a number of standard MIPI DSI command as well as a
45 * subset of the MIPI DCS command set.
46 */
47
Andrzej Hajda068a0022013-12-04 16:35:12 +010048static int mipi_dsi_device_match(struct device *dev, struct device_driver *drv)
49{
50 return of_driver_match_device(dev, drv);
51}
52
53static const struct dev_pm_ops mipi_dsi_device_pm_ops = {
54 .runtime_suspend = pm_generic_runtime_suspend,
55 .runtime_resume = pm_generic_runtime_resume,
56 .suspend = pm_generic_suspend,
57 .resume = pm_generic_resume,
58 .freeze = pm_generic_freeze,
59 .thaw = pm_generic_thaw,
60 .poweroff = pm_generic_poweroff,
61 .restore = pm_generic_restore,
62};
63
64static struct bus_type mipi_dsi_bus_type = {
65 .name = "mipi-dsi",
66 .match = mipi_dsi_device_match,
67 .pm = &mipi_dsi_device_pm_ops,
68};
69
70static void mipi_dsi_dev_release(struct device *dev)
71{
72 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
73
74 of_node_put(dev->of_node);
75 kfree(dsi);
76}
77
78static const struct device_type mipi_dsi_device_type = {
79 .release = mipi_dsi_dev_release,
80};
81
82static struct mipi_dsi_device *mipi_dsi_device_alloc(struct mipi_dsi_host *host)
83{
84 struct mipi_dsi_device *dsi;
85
86 dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
87 if (!dsi)
88 return ERR_PTR(-ENOMEM);
89
90 dsi->host = host;
91 dsi->dev.bus = &mipi_dsi_bus_type;
92 dsi->dev.parent = host->dev;
93 dsi->dev.type = &mipi_dsi_device_type;
94
95 device_initialize(&dsi->dev);
96
97 return dsi;
98}
99
100static int mipi_dsi_device_add(struct mipi_dsi_device *dsi)
101{
102 struct mipi_dsi_host *host = dsi->host;
103
104 dev_set_name(&dsi->dev, "%s.%d", dev_name(host->dev), dsi->channel);
105
106 return device_add(&dsi->dev);
107}
108
109static struct mipi_dsi_device *
110of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
111{
112 struct mipi_dsi_device *dsi;
113 struct device *dev = host->dev;
114 int ret;
115 u32 reg;
116
117 ret = of_property_read_u32(node, "reg", &reg);
118 if (ret) {
119 dev_err(dev, "device node %s has no valid reg property: %d\n",
120 node->full_name, ret);
121 return ERR_PTR(-EINVAL);
122 }
123
124 if (reg > 3) {
125 dev_err(dev, "device node %s has invalid reg property: %u\n",
126 node->full_name, reg);
127 return ERR_PTR(-EINVAL);
128 }
129
130 dsi = mipi_dsi_device_alloc(host);
131 if (IS_ERR(dsi)) {
132 dev_err(dev, "failed to allocate DSI device %s: %ld\n",
133 node->full_name, PTR_ERR(dsi));
134 return dsi;
135 }
136
137 dsi->dev.of_node = of_node_get(node);
138 dsi->channel = reg;
139
140 ret = mipi_dsi_device_add(dsi);
141 if (ret) {
142 dev_err(dev, "failed to add DSI device %s: %d\n",
143 node->full_name, ret);
144 kfree(dsi);
145 return ERR_PTR(ret);
146 }
147
148 return dsi;
149}
150
151int mipi_dsi_host_register(struct mipi_dsi_host *host)
152{
153 struct device_node *node;
154
Andrzej Hajdae49640d2014-03-28 12:52:37 +0100155 for_each_available_child_of_node(host->dev->of_node, node) {
156 /* skip nodes without reg property */
157 if (!of_find_property(node, "reg", NULL))
158 continue;
Andrzej Hajda068a0022013-12-04 16:35:12 +0100159 of_mipi_dsi_device_add(host, node);
Andrzej Hajdae49640d2014-03-28 12:52:37 +0100160 }
Andrzej Hajda068a0022013-12-04 16:35:12 +0100161
162 return 0;
163}
164EXPORT_SYMBOL(mipi_dsi_host_register);
165
166static int mipi_dsi_remove_device_fn(struct device *dev, void *priv)
167{
168 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
169
170 device_unregister(&dsi->dev);
171
172 return 0;
173}
174
175void mipi_dsi_host_unregister(struct mipi_dsi_host *host)
176{
177 device_for_each_child(host->dev, NULL, mipi_dsi_remove_device_fn);
178}
179EXPORT_SYMBOL(mipi_dsi_host_unregister);
180
181/**
182 * mipi_dsi_attach - attach a DSI device to its DSI host
183 * @dsi: DSI peripheral
184 */
185int mipi_dsi_attach(struct mipi_dsi_device *dsi)
186{
187 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
188
189 if (!ops || !ops->attach)
190 return -ENOSYS;
191
192 return ops->attach(dsi->host, dsi);
193}
194EXPORT_SYMBOL(mipi_dsi_attach);
195
196/**
197 * mipi_dsi_detach - detach a DSI device from its DSI host
198 * @dsi: DSI peripheral
199 */
200int mipi_dsi_detach(struct mipi_dsi_device *dsi)
201{
202 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
203
204 if (!ops || !ops->detach)
205 return -ENOSYS;
206
207 return ops->detach(dsi->host, dsi);
208}
209EXPORT_SYMBOL(mipi_dsi_detach);
210
Thierry Reding9eb491f2014-10-14 11:12:32 +0200211static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi,
212 struct mipi_dsi_msg *msg)
213{
214 const struct mipi_dsi_host_ops *ops = dsi->host->ops;
215
216 if (!ops || !ops->transfer)
217 return -ENOSYS;
218
219 if (dsi->mode_flags & MIPI_DSI_MODE_LPM)
220 msg->flags |= MIPI_DSI_MSG_USE_LPM;
221
222 return ops->transfer(dsi->host, msg);
223}
224
Andrzej Hajda068a0022013-12-04 16:35:12 +0100225/**
Thierry Reding02acb762014-11-04 14:59:14 +0100226 * mipi_dsi_packet_format_is_short - check if a packet is of the short format
227 * @type: MIPI DSI data type of the packet
228 *
229 * Return: true if the packet for the given data type is a short packet, false
230 * otherwise.
231 */
232bool mipi_dsi_packet_format_is_short(u8 type)
233{
234 switch (type) {
235 case MIPI_DSI_V_SYNC_START:
236 case MIPI_DSI_V_SYNC_END:
237 case MIPI_DSI_H_SYNC_START:
238 case MIPI_DSI_H_SYNC_END:
239 case MIPI_DSI_END_OF_TRANSMISSION:
240 case MIPI_DSI_COLOR_MODE_OFF:
241 case MIPI_DSI_COLOR_MODE_ON:
242 case MIPI_DSI_SHUTDOWN_PERIPHERAL:
243 case MIPI_DSI_TURN_ON_PERIPHERAL:
244 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
245 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
246 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
247 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
248 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
249 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
250 case MIPI_DSI_DCS_SHORT_WRITE:
251 case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
252 case MIPI_DSI_DCS_READ:
253 case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
254 return true;
255 }
256
257 return false;
258}
259EXPORT_SYMBOL(mipi_dsi_packet_format_is_short);
260
261/**
262 * mipi_dsi_packet_format_is_long - check if a packet is of the long format
263 * @type: MIPI DSI data type of the packet
264 *
265 * Return: true if the packet for the given data type is a long packet, false
266 * otherwise.
267 */
268bool mipi_dsi_packet_format_is_long(u8 type)
269{
270 switch (type) {
271 case MIPI_DSI_NULL_PACKET:
272 case MIPI_DSI_BLANKING_PACKET:
273 case MIPI_DSI_GENERIC_LONG_WRITE:
274 case MIPI_DSI_DCS_LONG_WRITE:
275 case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20:
276 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24:
277 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16:
278 case MIPI_DSI_PACKED_PIXEL_STREAM_30:
279 case MIPI_DSI_PACKED_PIXEL_STREAM_36:
280 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12:
281 case MIPI_DSI_PACKED_PIXEL_STREAM_16:
282 case MIPI_DSI_PACKED_PIXEL_STREAM_18:
283 case MIPI_DSI_PIXEL_STREAM_3BYTE_18:
284 case MIPI_DSI_PACKED_PIXEL_STREAM_24:
285 return true;
286 }
287
288 return false;
289}
290EXPORT_SYMBOL(mipi_dsi_packet_format_is_long);
291
292/**
Thierry Redinga52879e2014-10-16 13:44:02 +0200293 * mipi_dsi_create_packet - create a packet from a message according to the
294 * DSI protocol
295 * @packet: pointer to a DSI packet structure
296 * @msg: message to translate into a packet
297 *
298 * Return: 0 on success or a negative error code on failure.
299 */
300int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
301 const struct mipi_dsi_msg *msg)
302{
303 const u8 *tx = msg->tx_buf;
304
305 if (!packet || !msg)
306 return -EINVAL;
307
308 /* do some minimum sanity checking */
309 if (!mipi_dsi_packet_format_is_short(msg->type) &&
310 !mipi_dsi_packet_format_is_long(msg->type))
311 return -EINVAL;
312
313 if (msg->channel > 3)
314 return -EINVAL;
315
316 memset(packet, 0, sizeof(*packet));
317 packet->header[0] = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f);
318
319 /* TODO: compute ECC if hardware support is not available */
320
321 /*
322 * Long write packets contain the word count in header bytes 1 and 2.
323 * The payload follows the header and is word count bytes long.
324 *
325 * Short write packets encode up to two parameters in header bytes 1
326 * and 2.
327 */
328 if (mipi_dsi_packet_format_is_long(msg->type)) {
329 packet->header[1] = (msg->tx_len >> 0) & 0xff;
330 packet->header[2] = (msg->tx_len >> 8) & 0xff;
331
332 packet->payload_length = msg->tx_len;
333 packet->payload = tx;
334 } else {
335 packet->header[1] = (msg->tx_len > 0) ? tx[0] : 0;
336 packet->header[2] = (msg->tx_len > 1) ? tx[1] : 0;
337 }
338
339 packet->size = sizeof(packet->header) + packet->payload_length;
340
341 return 0;
342}
343EXPORT_SYMBOL(mipi_dsi_create_packet);
344
YoungJun Chodbf30b62014-08-05 09:27:15 +0200345/*
346 * mipi_dsi_set_maximum_return_packet_size() - specify the maximum size of the
347 * the payload in a long packet transmitted from the peripheral back to the
348 * host processor
349 * @dsi: DSI peripheral device
350 * @value: the maximum size of the payload
351 *
352 * Return: 0 on success or a negative error code on failure.
353 */
354int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
355 u16 value)
356{
357 u8 tx[2] = { value & 0xff, value >> 8 };
358 struct mipi_dsi_msg msg = {
359 .channel = dsi->channel,
360 .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
361 .tx_len = sizeof(tx),
362 .tx_buf = tx,
363 };
364
365 return mipi_dsi_device_transfer(dsi, &msg);
366}
367EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
368
Thierry Redinga52879e2014-10-16 13:44:02 +0200369/**
Thierry Reding550ab842014-08-05 10:36:21 +0200370 * mipi_dsi_generic_write() - transmit data using a generic write packet
371 * @dsi: DSI peripheral device
372 * @payload: buffer containing the payload
373 * @size: size of payload buffer
374 *
375 * This function will automatically choose the right data type depending on
376 * the payload length.
377 *
378 * Return: The number of bytes transmitted on success or a negative error code
379 * on failure.
380 */
381ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
382 size_t size)
383{
384 struct mipi_dsi_msg msg = {
385 .channel = dsi->channel,
386 .tx_buf = payload,
387 .tx_len = size
388 };
389
390 switch (size) {
391 case 0:
392 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
393 break;
394
395 case 1:
396 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
397 break;
398
399 case 2:
400 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
401 break;
402
403 default:
404 msg.type = MIPI_DSI_GENERIC_LONG_WRITE;
405 break;
406 }
407
408 return mipi_dsi_device_transfer(dsi, &msg);
409}
410EXPORT_SYMBOL(mipi_dsi_generic_write);
411
412/**
413 * mipi_dsi_generic_read() - receive data using a generic read packet
414 * @dsi: DSI peripheral device
415 * @params: buffer containing the request parameters
416 * @num_params: number of request parameters
417 * @data: buffer in which to return the received data
418 * @size: size of receive buffer
419 *
420 * This function will automatically choose the right data type depending on
421 * the number of parameters passed in.
422 *
423 * Return: The number of bytes successfully read or a negative error code on
424 * failure.
425 */
426ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
427 size_t num_params, void *data, size_t size)
428{
429 struct mipi_dsi_msg msg = {
430 .channel = dsi->channel,
431 .tx_len = num_params,
432 .tx_buf = params,
433 .rx_len = size,
434 .rx_buf = data
435 };
436
437 switch (num_params) {
438 case 0:
439 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
440 break;
441
442 case 1:
443 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
444 break;
445
446 case 2:
447 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
448 break;
449
450 default:
451 return -EINVAL;
452 }
453
454 return mipi_dsi_device_transfer(dsi, &msg);
455}
456EXPORT_SYMBOL(mipi_dsi_generic_read);
457
458/**
Thierry Reding960dd612014-07-21 15:47:10 +0200459 * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload
460 * @dsi: DSI peripheral device
461 * @data: buffer containing data to be transmitted
462 * @len: size of transmission buffer
463 *
464 * This function will automatically choose the right data type depending on
465 * the command payload length.
466 *
467 * Return: The number of bytes successfully transmitted or a negative error
468 * code on failure.
Andrzej Hajda068a0022013-12-04 16:35:12 +0100469 */
Thierry Reding960dd612014-07-21 15:47:10 +0200470ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
471 const void *data, size_t len)
Andrzej Hajda068a0022013-12-04 16:35:12 +0100472{
Andrzej Hajda068a0022013-12-04 16:35:12 +0100473 struct mipi_dsi_msg msg = {
Thierry Reding3c523d72014-07-21 12:28:25 +0200474 .channel = dsi->channel,
Andrzej Hajda068a0022013-12-04 16:35:12 +0100475 .tx_buf = data,
476 .tx_len = len
477 };
478
Andrzej Hajda068a0022013-12-04 16:35:12 +0100479 switch (len) {
480 case 0:
481 return -EINVAL;
Thierry Reding960dd612014-07-21 15:47:10 +0200482
Andrzej Hajda068a0022013-12-04 16:35:12 +0100483 case 1:
484 msg.type = MIPI_DSI_DCS_SHORT_WRITE;
485 break;
Thierry Reding960dd612014-07-21 15:47:10 +0200486
Andrzej Hajda068a0022013-12-04 16:35:12 +0100487 case 2:
488 msg.type = MIPI_DSI_DCS_SHORT_WRITE_PARAM;
489 break;
Thierry Reding960dd612014-07-21 15:47:10 +0200490
Andrzej Hajda068a0022013-12-04 16:35:12 +0100491 default:
492 msg.type = MIPI_DSI_DCS_LONG_WRITE;
493 break;
494 }
495
Thierry Reding9eb491f2014-10-14 11:12:32 +0200496 return mipi_dsi_device_transfer(dsi, &msg);
Andrzej Hajda068a0022013-12-04 16:35:12 +0100497}
Thierry Reding960dd612014-07-21 15:47:10 +0200498EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer);
499
500/**
501 * mipi_dsi_dcs_write() - send DCS write command
502 * @dsi: DSI peripheral device
503 * @cmd: DCS command
504 * @data: buffer containing the command payload
505 * @len: command payload length
506 *
507 * This function will automatically choose the right data type depending on
508 * the command payload length.
509 *
510 * Return: The number of bytes successfully transmitted or a negative error
511 * code on failure.
512 */
513ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
514 const void *data, size_t len)
515{
516 ssize_t err;
517 size_t size;
518 u8 *tx;
519
520 if (len > 0) {
521 size = 1 + len;
522
523 tx = kmalloc(size, GFP_KERNEL);
524 if (!tx)
525 return -ENOMEM;
526
527 /* concatenate the DCS command byte and the payload */
528 tx[0] = cmd;
529 memcpy(&tx[1], data, len);
530 } else {
531 tx = &cmd;
532 size = 1;
533 }
534
535 err = mipi_dsi_dcs_write_buffer(dsi, tx, size);
536
537 if (len > 0)
538 kfree(tx);
539
540 return err;
541}
Andrzej Hajda068a0022013-12-04 16:35:12 +0100542EXPORT_SYMBOL(mipi_dsi_dcs_write);
543
544/**
Thierry Reding960dd612014-07-21 15:47:10 +0200545 * mipi_dsi_dcs_read() - send DCS read request command
546 * @dsi: DSI peripheral device
547 * @cmd: DCS command
548 * @data: buffer in which to receive data
549 * @len: size of receive buffer
Andrzej Hajda068a0022013-12-04 16:35:12 +0100550 *
Thierry Reding960dd612014-07-21 15:47:10 +0200551 * Return: The number of bytes read or a negative error code on failure.
Andrzej Hajda068a0022013-12-04 16:35:12 +0100552 */
Thierry Reding3c523d72014-07-21 12:28:25 +0200553ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
554 size_t len)
Andrzej Hajda068a0022013-12-04 16:35:12 +0100555{
Andrzej Hajda068a0022013-12-04 16:35:12 +0100556 struct mipi_dsi_msg msg = {
Thierry Reding3c523d72014-07-21 12:28:25 +0200557 .channel = dsi->channel,
Andrzej Hajda068a0022013-12-04 16:35:12 +0100558 .type = MIPI_DSI_DCS_READ,
559 .tx_buf = &cmd,
560 .tx_len = 1,
561 .rx_buf = data,
562 .rx_len = len
563 };
564
Thierry Reding9eb491f2014-10-14 11:12:32 +0200565 return mipi_dsi_device_transfer(dsi, &msg);
Andrzej Hajda068a0022013-12-04 16:35:12 +0100566}
567EXPORT_SYMBOL(mipi_dsi_dcs_read);
568
YoungJun Cho42fe1e72014-08-05 10:38:31 +0200569/**
570 * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the
571 * display module except interface communication
572 * @dsi: DSI peripheral device
573 *
574 * Return: 0 on success or a negative error code on failure.
575 */
576int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi)
577{
578 ssize_t err;
579
580 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_ENTER_SLEEP_MODE, NULL, 0);
581 if (err < 0)
582 return err;
583
584 return 0;
585}
586EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode);
587
588/**
589 * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
590 * module
591 * @dsi: DSI peripheral device
592 *
593 * Return: 0 on success or a negative error code on failure.
594 */
595int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi)
596{
597 ssize_t err;
598
599 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_EXIT_SLEEP_MODE, NULL, 0);
600 if (err < 0)
601 return err;
602
603 return 0;
604}
605EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode);
606
607/**
608 * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
609 * display device
610 * @dsi: DSI peripheral device
611 *
612 * Return: 0 on success or a negative error code on failure.
613 */
614int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi)
615{
616 ssize_t err;
617
618 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0);
619 if (err < 0)
620 return err;
621
622 return 0;
623}
624EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off);
625
626/**
627 * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
628 * display device
629 * @dsi: DSI peripheral device
630 *
631 * Return: 0 on success or a negative error code on failure
632 */
633int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi)
634{
635 ssize_t err;
636
637 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_ON, NULL, 0);
638 if (err < 0)
639 return err;
640
641 return 0;
642}
643EXPORT_SYMBOL(mipi_dsi_dcs_set_display_on);
644
645/**
646 * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect
647 * output signal on the TE signal line
648 * @dsi: DSI peripheral device
649 *
650 * Return: 0 on success or a negative error code on failure
651 */
652int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi)
653{
654 ssize_t err;
655
656 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_OFF, NULL, 0);
657 if (err < 0)
658 return err;
659
660 return 0;
661}
662EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_off);
663
664/**
665 * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect
666 * output signal on the TE signal line.
667 * @dsi: DSI peripheral device
668 * @mode: the Tearing Effect Output Line mode
669 *
670 * Return: 0 on success or a negative error code on failure
671 */
672int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
673 enum mipi_dsi_dcs_tear_mode mode)
674{
675 u8 value = mode;
676 ssize_t err;
677
678 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_ON, &value,
679 sizeof(value));
680 if (err < 0)
681 return err;
682
683 return 0;
684}
685EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_on);
686
Andrzej Hajda068a0022013-12-04 16:35:12 +0100687static int mipi_dsi_drv_probe(struct device *dev)
688{
689 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
690 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
691
692 return drv->probe(dsi);
693}
694
695static int mipi_dsi_drv_remove(struct device *dev)
696{
697 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
698 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
699
700 return drv->remove(dsi);
701}
702
Thierry Redingd1621802014-04-29 17:19:57 +0200703static void mipi_dsi_drv_shutdown(struct device *dev)
704{
705 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
706 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
707
708 drv->shutdown(dsi);
709}
710
Andrzej Hajda068a0022013-12-04 16:35:12 +0100711/**
Thierry Reding009081e2014-08-05 10:41:13 +0200712 * mipi_dsi_driver_register() - register a driver for DSI devices
Andrzej Hajda068a0022013-12-04 16:35:12 +0100713 * @drv: DSI driver structure
Thierry Reding009081e2014-08-05 10:41:13 +0200714 *
715 * Return: 0 on success or a negative error code on failure.
Andrzej Hajda068a0022013-12-04 16:35:12 +0100716 */
717int mipi_dsi_driver_register(struct mipi_dsi_driver *drv)
718{
719 drv->driver.bus = &mipi_dsi_bus_type;
720 if (drv->probe)
721 drv->driver.probe = mipi_dsi_drv_probe;
722 if (drv->remove)
723 drv->driver.remove = mipi_dsi_drv_remove;
Thierry Redingd1621802014-04-29 17:19:57 +0200724 if (drv->shutdown)
725 drv->driver.shutdown = mipi_dsi_drv_shutdown;
Andrzej Hajda068a0022013-12-04 16:35:12 +0100726
727 return driver_register(&drv->driver);
728}
729EXPORT_SYMBOL(mipi_dsi_driver_register);
730
731/**
Thierry Reding009081e2014-08-05 10:41:13 +0200732 * mipi_dsi_driver_unregister() - unregister a driver for DSI devices
Andrzej Hajda068a0022013-12-04 16:35:12 +0100733 * @drv: DSI driver structure
Thierry Reding009081e2014-08-05 10:41:13 +0200734 *
735 * Return: 0 on success or a negative error code on failure.
Andrzej Hajda068a0022013-12-04 16:35:12 +0100736 */
737void mipi_dsi_driver_unregister(struct mipi_dsi_driver *drv)
738{
739 driver_unregister(&drv->driver);
740}
741EXPORT_SYMBOL(mipi_dsi_driver_unregister);
742
743static int __init mipi_dsi_bus_init(void)
744{
745 return bus_register(&mipi_dsi_bus_type);
746}
747postcore_initcall(mipi_dsi_bus_init);
748
749MODULE_AUTHOR("Andrzej Hajda <a.hajda@samsung.com>");
750MODULE_DESCRIPTION("MIPI DSI Bus");
751MODULE_LICENSE("GPL and additional rights");