Subversion Repositories Kolibri OS

Rev

Rev 6937 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6084 serge 1
/*
2
 * MIPI DSI Bus
3
 *
4
 * Copyright (C) 2012-2013, Samsung Electronics, Co., Ltd.
5
 * Andrzej Hajda 
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 
29
 
30
#include 
31
#include 
32
//#include 
33
#include 
6088 serge 34
#include 
6084 serge 35
 
36
#include 
37
 
38
 
39
/**
40
 * mipi_dsi_attach - attach a DSI device to its DSI host
41
 * @dsi: DSI peripheral
42
 */
43
int mipi_dsi_attach(struct mipi_dsi_device *dsi)
44
{
45
	const struct mipi_dsi_host_ops *ops = dsi->host->ops;
46
 
47
	if (!ops || !ops->attach)
48
		return -ENOSYS;
49
 
50
	return ops->attach(dsi->host, dsi);
51
}
52
EXPORT_SYMBOL(mipi_dsi_attach);
53
 
54
static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi,
55
					struct mipi_dsi_msg *msg)
56
{
57
	const struct mipi_dsi_host_ops *ops = dsi->host->ops;
58
 
59
	if (!ops || !ops->transfer)
60
		return -ENOSYS;
61
 
62
	if (dsi->mode_flags & MIPI_DSI_MODE_LPM)
63
		msg->flags |= MIPI_DSI_MSG_USE_LPM;
64
 
65
	return ops->transfer(dsi->host, msg);
66
}
67
 
68
/**
69
 * mipi_dsi_packet_format_is_short - check if a packet is of the short format
70
 * @type: MIPI DSI data type of the packet
71
 *
72
 * Return: true if the packet for the given data type is a short packet, false
73
 * otherwise.
74
 */
75
bool mipi_dsi_packet_format_is_short(u8 type)
76
{
77
	switch (type) {
78
	case MIPI_DSI_V_SYNC_START:
79
	case MIPI_DSI_V_SYNC_END:
80
	case MIPI_DSI_H_SYNC_START:
81
	case MIPI_DSI_H_SYNC_END:
82
	case MIPI_DSI_END_OF_TRANSMISSION:
83
	case MIPI_DSI_COLOR_MODE_OFF:
84
	case MIPI_DSI_COLOR_MODE_ON:
85
	case MIPI_DSI_SHUTDOWN_PERIPHERAL:
86
	case MIPI_DSI_TURN_ON_PERIPHERAL:
87
	case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
88
	case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
89
	case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
90
	case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
91
	case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
92
	case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
93
	case MIPI_DSI_DCS_SHORT_WRITE:
94
	case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
95
	case MIPI_DSI_DCS_READ:
96
	case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
97
		return true;
98
	}
99
 
100
	return false;
101
}
102
EXPORT_SYMBOL(mipi_dsi_packet_format_is_short);
103
 
104
/**
105
 * mipi_dsi_packet_format_is_long - check if a packet is of the long format
106
 * @type: MIPI DSI data type of the packet
107
 *
108
 * Return: true if the packet for the given data type is a long packet, false
109
 * otherwise.
110
 */
111
bool mipi_dsi_packet_format_is_long(u8 type)
112
{
113
	switch (type) {
114
	case MIPI_DSI_NULL_PACKET:
115
	case MIPI_DSI_BLANKING_PACKET:
116
	case MIPI_DSI_GENERIC_LONG_WRITE:
117
	case MIPI_DSI_DCS_LONG_WRITE:
118
	case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20:
119
	case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24:
120
	case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16:
121
	case MIPI_DSI_PACKED_PIXEL_STREAM_30:
122
	case MIPI_DSI_PACKED_PIXEL_STREAM_36:
123
	case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12:
124
	case MIPI_DSI_PACKED_PIXEL_STREAM_16:
125
	case MIPI_DSI_PACKED_PIXEL_STREAM_18:
126
	case MIPI_DSI_PIXEL_STREAM_3BYTE_18:
127
	case MIPI_DSI_PACKED_PIXEL_STREAM_24:
128
		return true;
129
	}
130
 
131
	return false;
132
}
133
EXPORT_SYMBOL(mipi_dsi_packet_format_is_long);
134
 
135
/**
136
 * mipi_dsi_create_packet - create a packet from a message according to the
137
 *     DSI protocol
138
 * @packet: pointer to a DSI packet structure
139
 * @msg: message to translate into a packet
140
 *
141
 * Return: 0 on success or a negative error code on failure.
142
 */
143
int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
144
			   const struct mipi_dsi_msg *msg)
145
{
146
	if (!packet || !msg)
147
		return -EINVAL;
148
 
149
	/* do some minimum sanity checking */
150
	if (!mipi_dsi_packet_format_is_short(msg->type) &&
151
	    !mipi_dsi_packet_format_is_long(msg->type))
152
		return -EINVAL;
153
 
154
	if (msg->channel > 3)
155
		return -EINVAL;
156
 
157
	memset(packet, 0, sizeof(*packet));
158
	packet->header[0] = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f);
159
 
160
	/* TODO: compute ECC if hardware support is not available */
161
 
162
	/*
163
	 * Long write packets contain the word count in header bytes 1 and 2.
164
	 * The payload follows the header and is word count bytes long.
165
	 *
166
	 * Short write packets encode up to two parameters in header bytes 1
167
	 * and 2.
168
	 */
169
	if (mipi_dsi_packet_format_is_long(msg->type)) {
170
		packet->header[1] = (msg->tx_len >> 0) & 0xff;
171
		packet->header[2] = (msg->tx_len >> 8) & 0xff;
172
 
173
		packet->payload_length = msg->tx_len;
174
		packet->payload = msg->tx_buf;
175
	} else {
176
		const u8 *tx = msg->tx_buf;
177
 
178
		packet->header[1] = (msg->tx_len > 0) ? tx[0] : 0;
179
		packet->header[2] = (msg->tx_len > 1) ? tx[1] : 0;
180
	}
181
 
182
	packet->size = sizeof(packet->header) + packet->payload_length;
183
 
184
	return 0;
185
}
186
EXPORT_SYMBOL(mipi_dsi_create_packet);
187
 
7144 serge 188
/**
189
 * mipi_dsi_shutdown_peripheral() - sends a Shutdown Peripheral command
190
 * @dsi: DSI peripheral device
191
 *
192
 * Return: 0 on success or a negative error code on failure.
193
 */
194
int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
195
{
196
	struct mipi_dsi_msg msg = {
197
		.channel = dsi->channel,
198
		.type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
199
		.tx_buf = (u8 [2]) { 0, 0 },
200
		.tx_len = 2,
201
	};
202
 
203
	return mipi_dsi_device_transfer(dsi, &msg);
204
}
205
EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);
206
 
207
/**
208
 * mipi_dsi_turn_on_peripheral() - sends a Turn On Peripheral command
209
 * @dsi: DSI peripheral device
210
 *
211
 * Return: 0 on success or a negative error code on failure.
212
 */
213
int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi)
214
{
215
	struct mipi_dsi_msg msg = {
216
		.channel = dsi->channel,
217
		.type = MIPI_DSI_TURN_ON_PERIPHERAL,
218
		.tx_buf = (u8 [2]) { 0, 0 },
219
		.tx_len = 2,
220
	};
221
 
222
	return mipi_dsi_device_transfer(dsi, &msg);
223
}
224
EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);
225
 
6084 serge 226
/*
227
 * mipi_dsi_set_maximum_return_packet_size() - specify the maximum size of the
228
 *    the payload in a long packet transmitted from the peripheral back to the
229
 *    host processor
230
 * @dsi: DSI peripheral device
231
 * @value: the maximum size of the payload
232
 *
233
 * Return: 0 on success or a negative error code on failure.
234
 */
235
int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
236
					    u16 value)
237
{
238
	u8 tx[2] = { value & 0xff, value >> 8 };
239
	struct mipi_dsi_msg msg = {
240
		.channel = dsi->channel,
241
		.type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
242
		.tx_len = sizeof(tx),
243
		.tx_buf = tx,
244
	};
245
 
246
	return mipi_dsi_device_transfer(dsi, &msg);
247
}
248
EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
249
 
250
/**
251
 * mipi_dsi_generic_write() - transmit data using a generic write packet
252
 * @dsi: DSI peripheral device
253
 * @payload: buffer containing the payload
254
 * @size: size of payload buffer
255
 *
256
 * This function will automatically choose the right data type depending on
257
 * the payload length.
258
 *
259
 * Return: The number of bytes transmitted on success or a negative error code
260
 * on failure.
261
 */
262
ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
263
			       size_t size)
264
{
265
	struct mipi_dsi_msg msg = {
266
		.channel = dsi->channel,
267
		.tx_buf = payload,
268
		.tx_len = size
269
	};
270
 
271
	switch (size) {
272
	case 0:
273
		msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
274
		break;
275
 
276
	case 1:
277
		msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
278
		break;
279
 
280
	case 2:
281
		msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
282
		break;
283
 
284
	default:
285
		msg.type = MIPI_DSI_GENERIC_LONG_WRITE;
286
		break;
287
	}
288
 
289
	return mipi_dsi_device_transfer(dsi, &msg);
290
}
291
EXPORT_SYMBOL(mipi_dsi_generic_write);
292
 
293
/**
294
 * mipi_dsi_generic_read() - receive data using a generic read packet
295
 * @dsi: DSI peripheral device
296
 * @params: buffer containing the request parameters
297
 * @num_params: number of request parameters
298
 * @data: buffer in which to return the received data
299
 * @size: size of receive buffer
300
 *
301
 * This function will automatically choose the right data type depending on
302
 * the number of parameters passed in.
303
 *
304
 * Return: The number of bytes successfully read or a negative error code on
305
 * failure.
306
 */
307
ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
308
			      size_t num_params, void *data, size_t size)
309
{
310
	struct mipi_dsi_msg msg = {
311
		.channel = dsi->channel,
312
		.tx_len = num_params,
313
		.tx_buf = params,
314
		.rx_len = size,
315
		.rx_buf = data
316
	};
317
 
318
	switch (num_params) {
319
	case 0:
320
		msg.type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
321
		break;
322
 
323
	case 1:
324
		msg.type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
325
		break;
326
 
327
	case 2:
328
		msg.type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
329
		break;
330
 
331
	default:
332
		return -EINVAL;
333
	}
334
 
335
	return mipi_dsi_device_transfer(dsi, &msg);
336
}
337
EXPORT_SYMBOL(mipi_dsi_generic_read);
338
 
339
/**
340
 * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload
341
 * @dsi: DSI peripheral device
342
 * @data: buffer containing data to be transmitted
343
 * @len: size of transmission buffer
344
 *
345
 * This function will automatically choose the right data type depending on
346
 * the command payload length.
347
 *
348
 * Return: The number of bytes successfully transmitted or a negative error
349
 * code on failure.
350
 */
351
ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
352
				  const void *data, size_t len)
353
{
354
	struct mipi_dsi_msg msg = {
355
		.channel = dsi->channel,
356
		.tx_buf = data,
357
		.tx_len = len
358
	};
359
 
360
	switch (len) {
361
	case 0:
362
		return -EINVAL;
363
 
364
	case 1:
365
		msg.type = MIPI_DSI_DCS_SHORT_WRITE;
366
		break;
367
 
368
	case 2:
369
		msg.type = MIPI_DSI_DCS_SHORT_WRITE_PARAM;
370
		break;
371
 
372
	default:
373
		msg.type = MIPI_DSI_DCS_LONG_WRITE;
374
		break;
375
	}
376
 
377
	return mipi_dsi_device_transfer(dsi, &msg);
378
}
379
EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer);
380
 
381
/**
382
 * mipi_dsi_dcs_write() - send DCS write command
383
 * @dsi: DSI peripheral device
384
 * @cmd: DCS command
385
 * @data: buffer containing the command payload
386
 * @len: command payload length
387
 *
388
 * This function will automatically choose the right data type depending on
389
 * the command payload length.
390
 *
391
 * Return: The number of bytes successfully transmitted or a negative error
392
 * code on failure.
393
 */
394
ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
395
			   const void *data, size_t len)
396
{
397
	ssize_t err;
398
	size_t size;
399
	u8 *tx;
400
 
401
	if (len > 0) {
402
		size = 1 + len;
403
 
404
		tx = kmalloc(size, GFP_KERNEL);
405
		if (!tx)
406
			return -ENOMEM;
407
 
408
		/* concatenate the DCS command byte and the payload */
409
		tx[0] = cmd;
410
		memcpy(&tx[1], data, len);
411
	} else {
412
		tx = &cmd;
413
		size = 1;
414
	}
415
 
416
	err = mipi_dsi_dcs_write_buffer(dsi, tx, size);
417
 
418
	if (len > 0)
419
		kfree(tx);
420
 
421
	return err;
422
}
423
EXPORT_SYMBOL(mipi_dsi_dcs_write);
424
 
425
/**
426
 * mipi_dsi_dcs_read() - send DCS read request command
427
 * @dsi: DSI peripheral device
428
 * @cmd: DCS command
429
 * @data: buffer in which to receive data
430
 * @len: size of receive buffer
431
 *
432
 * Return: The number of bytes read or a negative error code on failure.
433
 */
434
ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
435
			  size_t len)
436
{
437
	struct mipi_dsi_msg msg = {
438
		.channel = dsi->channel,
439
		.type = MIPI_DSI_DCS_READ,
440
		.tx_buf = &cmd,
441
		.tx_len = 1,
442
		.rx_buf = data,
443
		.rx_len = len
444
	};
445
 
446
	return mipi_dsi_device_transfer(dsi, &msg);
447
}
448
EXPORT_SYMBOL(mipi_dsi_dcs_read);
449
 
450
/**
451
 * mipi_dsi_dcs_nop() - send DCS nop packet
452
 * @dsi: DSI peripheral device
453
 *
454
 * Return: 0 on success or a negative error code on failure.
455
 */
456
int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi)
457
{
458
	ssize_t err;
459
 
460
	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_NOP, NULL, 0);
461
	if (err < 0)
462
		return err;
463
 
464
	return 0;
465
}
466
EXPORT_SYMBOL(mipi_dsi_dcs_nop);
467
 
468
/**
469
 * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module
470
 * @dsi: DSI peripheral device
471
 *
472
 * Return: 0 on success or a negative error code on failure.
473
 */
474
int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi)
475
{
476
	ssize_t err;
477
 
478
	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SOFT_RESET, NULL, 0);
479
	if (err < 0)
480
		return err;
481
 
482
	return 0;
483
}
484
EXPORT_SYMBOL(mipi_dsi_dcs_soft_reset);
485
 
486
/**
487
 * mipi_dsi_dcs_get_power_mode() - query the display module's current power
488
 *    mode
489
 * @dsi: DSI peripheral device
490
 * @mode: return location for the current power mode
491
 *
492
 * Return: 0 on success or a negative error code on failure.
493
 */
494
int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode)
495
{
496
	ssize_t err;
497
 
498
	err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_POWER_MODE, mode,
499
				sizeof(*mode));
500
	if (err <= 0) {
501
		if (err == 0)
502
			err = -ENODATA;
503
 
504
		return err;
505
	}
506
 
507
	return 0;
508
}
509
EXPORT_SYMBOL(mipi_dsi_dcs_get_power_mode);
510
 
511
/**
512
 * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image
513
 *    data used by the interface
514
 * @dsi: DSI peripheral device
515
 * @format: return location for the pixel format
516
 *
517
 * Return: 0 on success or a negative error code on failure.
518
 */
519
int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format)
520
{
521
	ssize_t err;
522
 
523
	err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_PIXEL_FORMAT, format,
524
				sizeof(*format));
525
	if (err <= 0) {
526
		if (err == 0)
527
			err = -ENODATA;
528
 
529
		return err;
530
	}
531
 
532
	return 0;
533
}
534
EXPORT_SYMBOL(mipi_dsi_dcs_get_pixel_format);
535
 
536
/**
537
 * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the
538
 *    display module except interface communication
539
 * @dsi: DSI peripheral device
540
 *
541
 * Return: 0 on success or a negative error code on failure.
542
 */
543
int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi)
544
{
545
	ssize_t err;
546
 
547
	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_ENTER_SLEEP_MODE, NULL, 0);
548
	if (err < 0)
549
		return err;
550
 
551
	return 0;
552
}
553
EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode);
554
 
555
/**
556
 * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
557
 *    module
558
 * @dsi: DSI peripheral device
559
 *
560
 * Return: 0 on success or a negative error code on failure.
561
 */
562
int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi)
563
{
564
	ssize_t err;
565
 
566
	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_EXIT_SLEEP_MODE, NULL, 0);
567
	if (err < 0)
568
		return err;
569
 
570
	return 0;
571
}
572
EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode);
573
 
574
/**
575
 * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
576
 *    display device
577
 * @dsi: DSI peripheral device
578
 *
579
 * Return: 0 on success or a negative error code on failure.
580
 */
581
int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi)
582
{
583
	ssize_t err;
584
 
585
	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0);
586
	if (err < 0)
587
		return err;
588
 
589
	return 0;
590
}
591
EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off);
592
 
593
/**
594
 * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
595
 *    display device
596
 * @dsi: DSI peripheral device
597
 *
598
 * Return: 0 on success or a negative error code on failure
599
 */
600
int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi)
601
{
602
	ssize_t err;
603
 
604
	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_ON, NULL, 0);
605
	if (err < 0)
606
		return err;
607
 
608
	return 0;
609
}
610
EXPORT_SYMBOL(mipi_dsi_dcs_set_display_on);
611
 
612
/**
613
 * mipi_dsi_dcs_set_column_address() - define the column extent of the frame
614
 *    memory accessed by the host processor
615
 * @dsi: DSI peripheral device
616
 * @start: first column of frame memory
617
 * @end: last column of frame memory
618
 *
619
 * Return: 0 on success or a negative error code on failure.
620
 */
621
int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
622
				    u16 end)
623
{
624
	u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
625
	ssize_t err;
626
 
627
	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, payload,
628
				 sizeof(payload));
629
	if (err < 0)
630
		return err;
631
 
632
	return 0;
633
}
634
EXPORT_SYMBOL(mipi_dsi_dcs_set_column_address);
635
 
636
/**
637
 * mipi_dsi_dcs_set_page_address() - define the page extent of the frame
638
 *    memory accessed by the host processor
639
 * @dsi: DSI peripheral device
640
 * @start: first page of frame memory
641
 * @end: last page of frame memory
642
 *
643
 * Return: 0 on success or a negative error code on failure.
644
 */
645
int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
646
				  u16 end)
647
{
648
	u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
649
	ssize_t err;
650
 
651
	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PAGE_ADDRESS, payload,
652
				 sizeof(payload));
653
	if (err < 0)
654
		return err;
655
 
656
	return 0;
657
}
658
EXPORT_SYMBOL(mipi_dsi_dcs_set_page_address);
659
 
660
/**
661
 * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect
662
 *    output signal on the TE signal line
663
 * @dsi: DSI peripheral device
664
 *
665
 * Return: 0 on success or a negative error code on failure
666
 */
667
int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi)
668
{
669
	ssize_t err;
670
 
671
	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_OFF, NULL, 0);
672
	if (err < 0)
673
		return err;
674
 
675
	return 0;
676
}
677
EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_off);
678
 
679
/**
680
 * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect
681
 *    output signal on the TE signal line.
682
 * @dsi: DSI peripheral device
683
 * @mode: the Tearing Effect Output Line mode
684
 *
685
 * Return: 0 on success or a negative error code on failure
686
 */
687
int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
688
			     enum mipi_dsi_dcs_tear_mode mode)
689
{
690
	u8 value = mode;
691
	ssize_t err;
692
 
693
	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_ON, &value,
694
				 sizeof(value));
695
	if (err < 0)
696
		return err;
697
 
698
	return 0;
699
}
700
EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_on);
701
 
702
/**
703
 * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image
704
 *    data used by the interface
705
 * @dsi: DSI peripheral device
706
 * @format: pixel format
707
 *
708
 * Return: 0 on success or a negative error code on failure.
709
 */
710
int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format)
711
{
712
	ssize_t err;
713
 
714
	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PIXEL_FORMAT, &format,
715
				 sizeof(format));
716
	if (err < 0)
717
		return err;
718
 
719
	return 0;
720
}
721
EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format);
722
 
723
MODULE_AUTHOR("Andrzej Hajda ");
724
MODULE_DESCRIPTION("MIPI DSI Bus");
725
MODULE_LICENSE("GPL and additional rights");