• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 <drm/drm_dsc.h>
37 #include <drm/drm_print.h>
38 #include <video/mipi_display.h>
39 
40 /**
41  * DOC: dsi helpers
42  *
43  * These functions contain some common logic and helpers to deal with MIPI DSI
44  * peripherals.
45  *
46  * Helpers are provided for a number of standard MIPI DSI command as well as a
47  * subset of the MIPI DCS command set.
48  */
49 
mipi_dsi_device_match(struct device * dev,struct device_driver * drv)50 static int mipi_dsi_device_match(struct device *dev, struct device_driver *drv)
51 {
52 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
53 
54 	/* attempt OF style match */
55 	if (of_driver_match_device(dev, drv))
56 		return 1;
57 
58 	/* compare DSI device and driver names */
59 	if (!strcmp(dsi->name, drv->name))
60 		return 1;
61 
62 	return 0;
63 }
64 
mipi_dsi_uevent(struct device * dev,struct kobj_uevent_env * env)65 static int mipi_dsi_uevent(struct device *dev, struct kobj_uevent_env *env)
66 {
67 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
68 	int err;
69 
70 	err = of_device_uevent_modalias(dev, env);
71 	if (err != -ENODEV)
72 		return err;
73 
74 	add_uevent_var(env, "MODALIAS=%s%s", MIPI_DSI_MODULE_PREFIX,
75 		       dsi->name);
76 
77 	return 0;
78 }
79 
80 static const struct dev_pm_ops mipi_dsi_device_pm_ops = {
81 	.runtime_suspend = pm_generic_runtime_suspend,
82 	.runtime_resume = pm_generic_runtime_resume,
83 	.suspend = pm_generic_suspend,
84 	.resume = pm_generic_resume,
85 	.freeze = pm_generic_freeze,
86 	.thaw = pm_generic_thaw,
87 	.poweroff = pm_generic_poweroff,
88 	.restore = pm_generic_restore,
89 };
90 
91 static struct bus_type mipi_dsi_bus_type = {
92 	.name = "mipi-dsi",
93 	.match = mipi_dsi_device_match,
94 	.uevent = mipi_dsi_uevent,
95 	.pm = &mipi_dsi_device_pm_ops,
96 };
97 
98 /**
99  * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
100  *    device tree node
101  * @np: device tree node
102  *
103  * Return: A pointer to the MIPI DSI device corresponding to @np or NULL if no
104  *    such device exists (or has not been registered yet).
105  */
of_find_mipi_dsi_device_by_node(struct device_node * np)106 struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
107 {
108 	struct device *dev;
109 
110 	dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);
111 
112 	return dev ? to_mipi_dsi_device(dev) : NULL;
113 }
114 EXPORT_SYMBOL(of_find_mipi_dsi_device_by_node);
115 
mipi_dsi_dev_release(struct device * dev)116 static void mipi_dsi_dev_release(struct device *dev)
117 {
118 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
119 
120 	of_node_put(dev->of_node);
121 	kfree(dsi);
122 }
123 
124 static const struct device_type mipi_dsi_device_type = {
125 	.release = mipi_dsi_dev_release,
126 };
127 
mipi_dsi_device_alloc(struct mipi_dsi_host * host)128 static struct mipi_dsi_device *mipi_dsi_device_alloc(struct mipi_dsi_host *host)
129 {
130 	struct mipi_dsi_device *dsi;
131 
132 	dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
133 	if (!dsi)
134 		return ERR_PTR(-ENOMEM);
135 
136 	dsi->host = host;
137 	dsi->dev.bus = &mipi_dsi_bus_type;
138 	dsi->dev.parent = host->dev;
139 	dsi->dev.type = &mipi_dsi_device_type;
140 
141 	device_initialize(&dsi->dev);
142 
143 	return dsi;
144 }
145 
mipi_dsi_device_add(struct mipi_dsi_device * dsi)146 static int mipi_dsi_device_add(struct mipi_dsi_device *dsi)
147 {
148 	struct mipi_dsi_host *host = dsi->host;
149 
150 	dev_set_name(&dsi->dev, "%s.%d", dev_name(host->dev),  dsi->channel);
151 
152 	return device_add(&dsi->dev);
153 }
154 
155 #if IS_ENABLED(CONFIG_OF)
156 static struct mipi_dsi_device *
of_mipi_dsi_device_add(struct mipi_dsi_host * host,struct device_node * node)157 of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
158 {
159 	struct mipi_dsi_device_info info = { };
160 	int ret;
161 	u32 reg;
162 
163 	if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) {
164 		drm_err(host, "modalias failure on %pOF\n", node);
165 		return ERR_PTR(-EINVAL);
166 	}
167 
168 	ret = of_property_read_u32(node, "reg", &reg);
169 	if (ret) {
170 		drm_err(host, "device node %pOF has no valid reg property: %d\n",
171 			node, ret);
172 		return ERR_PTR(-EINVAL);
173 	}
174 
175 	info.channel = reg;
176 	info.node = of_node_get(node);
177 
178 	return mipi_dsi_device_register_full(host, &info);
179 }
180 #else
181 static struct mipi_dsi_device *
of_mipi_dsi_device_add(struct mipi_dsi_host * host,struct device_node * node)182 of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
183 {
184 	return ERR_PTR(-ENODEV);
185 }
186 #endif
187 
188 /**
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
192  *
193  * Create a MIPI DSI device by using the device information provided by
194  * mipi_dsi_device_info template
195  *
196  * Returns:
197  * A pointer to the newly created MIPI DSI device, or, a pointer encoded
198  * with an error
199  */
200 struct mipi_dsi_device *
mipi_dsi_device_register_full(struct mipi_dsi_host * host,const struct mipi_dsi_device_info * info)201 mipi_dsi_device_register_full(struct mipi_dsi_host *host,
202 			      const struct mipi_dsi_device_info *info)
203 {
204 	struct mipi_dsi_device *dsi;
205 	int ret;
206 
207 	if (!info) {
208 		drm_err(host, "invalid mipi_dsi_device_info pointer\n");
209 		return ERR_PTR(-EINVAL);
210 	}
211 
212 	if (info->channel > 3) {
213 		drm_err(host, "invalid virtual channel: %u\n", info->channel);
214 		return ERR_PTR(-EINVAL);
215 	}
216 
217 	dsi = mipi_dsi_device_alloc(host);
218 	if (IS_ERR(dsi)) {
219 		drm_err(host, "failed to allocate DSI device %ld\n",
220 			PTR_ERR(dsi));
221 		return dsi;
222 	}
223 
224 	device_set_node(&dsi->dev, of_fwnode_handle(info->node));
225 	dsi->dev.fwnode = of_fwnode_handle(info->node);
226 	dsi->channel = info->channel;
227 	strlcpy(dsi->name, info->type, sizeof(dsi->name));
228 
229 	ret = mipi_dsi_device_add(dsi);
230 	if (ret) {
231 		drm_err(host, "failed to add DSI device %d\n", ret);
232 		kfree(dsi);
233 		return ERR_PTR(ret);
234 	}
235 
236 	return dsi;
237 }
238 EXPORT_SYMBOL(mipi_dsi_device_register_full);
239 
240 /**
241  * mipi_dsi_device_unregister - unregister MIPI DSI device
242  * @dsi: DSI peripheral device
243  */
mipi_dsi_device_unregister(struct mipi_dsi_device * dsi)244 void mipi_dsi_device_unregister(struct mipi_dsi_device *dsi)
245 {
246 	device_unregister(&dsi->dev);
247 }
248 EXPORT_SYMBOL(mipi_dsi_device_unregister);
249 
250 static DEFINE_MUTEX(host_lock);
251 static LIST_HEAD(host_list);
252 
253 /**
254  * of_find_mipi_dsi_host_by_node() - find the MIPI DSI host matching a
255  *				     device tree node
256  * @node: device tree node
257  *
258  * Returns:
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).
261  */
of_find_mipi_dsi_host_by_node(struct device_node * node)262 struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node)
263 {
264 	struct mipi_dsi_host *host;
265 
266 	mutex_lock(&host_lock);
267 
268 	list_for_each_entry(host, &host_list, list) {
269 		if (host->dev->of_node == node) {
270 			mutex_unlock(&host_lock);
271 			return host;
272 		}
273 	}
274 
275 	mutex_unlock(&host_lock);
276 
277 	return NULL;
278 }
279 EXPORT_SYMBOL(of_find_mipi_dsi_host_by_node);
280 
mipi_dsi_host_register(struct mipi_dsi_host * host)281 int mipi_dsi_host_register(struct mipi_dsi_host *host)
282 {
283 	struct device_node *node;
284 
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))
288 			continue;
289 		of_mipi_dsi_device_add(host, node);
290 	}
291 
292 	mutex_lock(&host_lock);
293 	list_add_tail(&host->list, &host_list);
294 	mutex_unlock(&host_lock);
295 
296 	return 0;
297 }
298 EXPORT_SYMBOL(mipi_dsi_host_register);
299 
mipi_dsi_remove_device_fn(struct device * dev,void * priv)300 static int mipi_dsi_remove_device_fn(struct device *dev, void *priv)
301 {
302 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
303 
304 	mipi_dsi_detach(dsi);
305 	mipi_dsi_device_unregister(dsi);
306 
307 	return 0;
308 }
309 
mipi_dsi_host_unregister(struct mipi_dsi_host * host)310 void mipi_dsi_host_unregister(struct mipi_dsi_host *host)
311 {
312 	device_for_each_child(host->dev, NULL, mipi_dsi_remove_device_fn);
313 
314 	mutex_lock(&host_lock);
315 	list_del_init(&host->list);
316 	mutex_unlock(&host_lock);
317 }
318 EXPORT_SYMBOL(mipi_dsi_host_unregister);
319 
320 /**
321  * mipi_dsi_attach - attach a DSI device to its DSI host
322  * @dsi: DSI peripheral
323  */
mipi_dsi_attach(struct mipi_dsi_device * dsi)324 int mipi_dsi_attach(struct mipi_dsi_device *dsi)
325 {
326 	const struct mipi_dsi_host_ops *ops = dsi->host->ops;
327 
328 	if (!ops || !ops->attach)
329 		return -ENOSYS;
330 
331 	return ops->attach(dsi->host, dsi);
332 }
333 EXPORT_SYMBOL(mipi_dsi_attach);
334 
335 /**
336  * mipi_dsi_detach - detach a DSI device from its DSI host
337  * @dsi: DSI peripheral
338  */
mipi_dsi_detach(struct mipi_dsi_device * dsi)339 int mipi_dsi_detach(struct mipi_dsi_device *dsi)
340 {
341 	const struct mipi_dsi_host_ops *ops = dsi->host->ops;
342 
343 	if (!ops || !ops->detach)
344 		return -ENOSYS;
345 
346 	return ops->detach(dsi->host, dsi);
347 }
348 EXPORT_SYMBOL(mipi_dsi_detach);
349 
mipi_dsi_device_transfer(struct mipi_dsi_device * dsi,struct mipi_dsi_msg * msg)350 static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi,
351 					struct mipi_dsi_msg *msg)
352 {
353 	const struct mipi_dsi_host_ops *ops = dsi->host->ops;
354 
355 	if (!ops || !ops->transfer)
356 		return -ENOSYS;
357 
358 	if (dsi->mode_flags & MIPI_DSI_MODE_LPM)
359 		msg->flags |= MIPI_DSI_MSG_USE_LPM;
360 	msg->flags |= MIPI_DSI_MSG_LASTCOMMAND;
361 
362 	return ops->transfer(dsi->host, msg);
363 }
364 
365 /**
366  * mipi_dsi_packet_format_is_short - check if a packet is of the short format
367  * @type: MIPI DSI data type of the packet
368  *
369  * Return: true if the packet for the given data type is a short packet, false
370  * otherwise.
371  */
mipi_dsi_packet_format_is_short(u8 type)372 bool mipi_dsi_packet_format_is_short(u8 type)
373 {
374 	switch (type) {
375 	case MIPI_DSI_V_SYNC_START:
376 	case MIPI_DSI_V_SYNC_END:
377 	case MIPI_DSI_H_SYNC_START:
378 	case MIPI_DSI_H_SYNC_END:
379 	case MIPI_DSI_COMPRESSION_MODE:
380 	case MIPI_DSI_END_OF_TRANSMISSION:
381 	case MIPI_DSI_COLOR_MODE_OFF:
382 	case MIPI_DSI_COLOR_MODE_ON:
383 	case MIPI_DSI_SHUTDOWN_PERIPHERAL:
384 	case MIPI_DSI_TURN_ON_PERIPHERAL:
385 	case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
386 	case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
387 	case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
388 	case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
389 	case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
390 	case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
391 	case MIPI_DSI_DCS_SHORT_WRITE:
392 	case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
393 	case MIPI_DSI_DCS_READ:
394 	case MIPI_DSI_EXECUTE_QUEUE:
395 	case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
396 		return true;
397 	}
398 
399 	return false;
400 }
401 EXPORT_SYMBOL(mipi_dsi_packet_format_is_short);
402 
403 /**
404  * mipi_dsi_packet_format_is_long - check if a packet is of the long format
405  * @type: MIPI DSI data type of the packet
406  *
407  * Return: true if the packet for the given data type is a long packet, false
408  * otherwise.
409  */
mipi_dsi_packet_format_is_long(u8 type)410 bool mipi_dsi_packet_format_is_long(u8 type)
411 {
412 	switch (type) {
413 	case MIPI_DSI_NULL_PACKET:
414 	case MIPI_DSI_BLANKING_PACKET:
415 	case MIPI_DSI_GENERIC_LONG_WRITE:
416 	case MIPI_DSI_DCS_LONG_WRITE:
417 	case MIPI_DSI_PICTURE_PARAMETER_SET:
418 	case MIPI_DSI_COMPRESSED_PIXEL_STREAM:
419 	case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20:
420 	case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24:
421 	case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16:
422 	case MIPI_DSI_PACKED_PIXEL_STREAM_30:
423 	case MIPI_DSI_PACKED_PIXEL_STREAM_36:
424 	case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12:
425 	case MIPI_DSI_PACKED_PIXEL_STREAM_16:
426 	case MIPI_DSI_PACKED_PIXEL_STREAM_18:
427 	case MIPI_DSI_PIXEL_STREAM_3BYTE_18:
428 	case MIPI_DSI_PACKED_PIXEL_STREAM_24:
429 		return true;
430 	}
431 
432 	return false;
433 }
434 EXPORT_SYMBOL(mipi_dsi_packet_format_is_long);
435 
436 /**
437  * mipi_dsi_create_packet - create a packet from a message according to the
438  *     DSI protocol
439  * @packet: pointer to a DSI packet structure
440  * @msg: message to translate into a packet
441  *
442  * Return: 0 on success or a negative error code on failure.
443  */
mipi_dsi_create_packet(struct mipi_dsi_packet * packet,const struct mipi_dsi_msg * msg)444 int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
445 			   const struct mipi_dsi_msg *msg)
446 {
447 	if (!packet || !msg)
448 		return -EINVAL;
449 
450 	/* do some minimum sanity checking */
451 	if (!mipi_dsi_packet_format_is_short(msg->type) &&
452 	    !mipi_dsi_packet_format_is_long(msg->type))
453 		return -EINVAL;
454 
455 	if (msg->channel > 3)
456 		return -EINVAL;
457 
458 	memset(packet, 0, sizeof(*packet));
459 	packet->header[0] = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f);
460 
461 	/* TODO: compute ECC if hardware support is not available */
462 
463 	/*
464 	 * Long write packets contain the word count in header bytes 1 and 2.
465 	 * The payload follows the header and is word count bytes long.
466 	 *
467 	 * Short write packets encode up to two parameters in header bytes 1
468 	 * and 2.
469 	 */
470 	if (mipi_dsi_packet_format_is_long(msg->type)) {
471 		packet->header[1] = (msg->tx_len >> 0) & 0xff;
472 		packet->header[2] = (msg->tx_len >> 8) & 0xff;
473 
474 		packet->payload_length = msg->tx_len;
475 		packet->payload = msg->tx_buf;
476 	} else {
477 		const u8 *tx = msg->tx_buf;
478 
479 		packet->header[1] = (msg->tx_len > 0) ? tx[0] : 0;
480 		packet->header[2] = (msg->tx_len > 1) ? tx[1] : 0;
481 	}
482 
483 	packet->size = sizeof(packet->header) + packet->payload_length;
484 
485 	return 0;
486 }
487 EXPORT_SYMBOL(mipi_dsi_create_packet);
488 
489 /**
490  * mipi_dsi_shutdown_peripheral() - sends a Shutdown Peripheral command
491  * @dsi: DSI peripheral device
492  *
493  * Return: 0 on success or a negative error code on failure.
494  */
mipi_dsi_shutdown_peripheral(struct mipi_dsi_device * dsi)495 int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
496 {
497 	struct mipi_dsi_msg msg = {
498 		.channel = dsi->channel,
499 		.type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
500 		.tx_buf = (u8 [2]) { 0, 0 },
501 		.tx_len = 2,
502 	};
503 	int ret = mipi_dsi_device_transfer(dsi, &msg);
504 
505 	return (ret < 0) ? ret : 0;
506 }
507 EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);
508 
509 /**
510  * mipi_dsi_turn_on_peripheral() - sends a Turn On Peripheral command
511  * @dsi: DSI peripheral device
512  *
513  * Return: 0 on success or a negative error code on failure.
514  */
mipi_dsi_turn_on_peripheral(struct mipi_dsi_device * dsi)515 int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi)
516 {
517 	struct mipi_dsi_msg msg = {
518 		.channel = dsi->channel,
519 		.type = MIPI_DSI_TURN_ON_PERIPHERAL,
520 		.tx_buf = (u8 [2]) { 0, 0 },
521 		.tx_len = 2,
522 	};
523 	int ret = mipi_dsi_device_transfer(dsi, &msg);
524 
525 	return (ret < 0) ? ret : 0;
526 }
527 EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);
528 
529 /*
530  * mipi_dsi_set_maximum_return_packet_size() - specify the maximum size of the
531  *    the payload in a long packet transmitted from the peripheral back to the
532  *    host processor
533  * @dsi: DSI peripheral device
534  * @value: the maximum size of the payload
535  *
536  * Return: 0 on success or a negative error code on failure.
537  */
mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device * dsi,u16 value)538 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
539 					    u16 value)
540 {
541 	u8 tx[2] = { value & 0xff, value >> 8 };
542 	struct mipi_dsi_msg msg = {
543 		.channel = dsi->channel,
544 		.type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
545 		.tx_len = sizeof(tx),
546 		.tx_buf = tx,
547 	};
548 	int ret = mipi_dsi_device_transfer(dsi, &msg);
549 
550 	return (ret < 0) ? ret : 0;
551 }
552 EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
553 
554 /**
555  * mipi_dsi_compression_mode() - enable/disable DSC on the peripheral
556  * @dsi: DSI peripheral device
557  * @enable: Whether to enable or disable the DSC
558  *
559  * Enable or disable Display Stream Compression on the peripheral using the
560  * default Picture Parameter Set and VESA DSC 1.1 algorithm.
561  *
562  * Return: 0 on success or a negative error code on failure.
563  */
mipi_dsi_compression_mode(struct mipi_dsi_device * dsi,bool enable)564 ssize_t mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable)
565 {
566 	/* Note: Needs updating for non-default PPS or algorithm */
567 	u8 tx[2] = { enable << 0, 0 };
568 	struct mipi_dsi_msg msg = {
569 		.channel = dsi->channel,
570 		.type = MIPI_DSI_COMPRESSION_MODE,
571 		.tx_len = sizeof(tx),
572 		.tx_buf = tx,
573 	};
574 	int ret = mipi_dsi_device_transfer(dsi, &msg);
575 
576 	return (ret < 0) ? ret : 0;
577 }
578 EXPORT_SYMBOL(mipi_dsi_compression_mode);
579 
580 /**
581  * mipi_dsi_picture_parameter_set() - transmit the DSC PPS to the peripheral
582  * @dsi: DSI peripheral device
583  * @pps: VESA DSC 1.1 Picture Parameter Set
584  *
585  * Transmit the VESA DSC 1.1 Picture Parameter Set to the peripheral.
586  *
587  * Return: 0 on success or a negative error code on failure.
588  */
mipi_dsi_picture_parameter_set(struct mipi_dsi_device * dsi,const struct drm_dsc_picture_parameter_set * pps)589 ssize_t mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
590 				       const struct drm_dsc_picture_parameter_set *pps)
591 {
592 	struct mipi_dsi_msg msg = {
593 		.channel = dsi->channel,
594 		.type = MIPI_DSI_PICTURE_PARAMETER_SET,
595 		.tx_len = sizeof(*pps),
596 		.tx_buf = pps,
597 	};
598 	int ret = mipi_dsi_device_transfer(dsi, &msg);
599 
600 	return (ret < 0) ? ret : 0;
601 }
602 EXPORT_SYMBOL(mipi_dsi_picture_parameter_set);
603 
604 /**
605  * mipi_dsi_generic_write() - transmit data using a generic write packet
606  * @dsi: DSI peripheral device
607  * @payload: buffer containing the payload
608  * @size: size of payload buffer
609  *
610  * This function will automatically choose the right data type depending on
611  * the payload length.
612  *
613  * Return: The number of bytes transmitted on success or a negative error code
614  * on failure.
615  */
mipi_dsi_generic_write(struct mipi_dsi_device * dsi,const void * payload,size_t size)616 ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
617 			       size_t size)
618 {
619 	struct mipi_dsi_msg msg = {
620 		.channel = dsi->channel,
621 		.tx_buf = payload,
622 		.tx_len = size
623 	};
624 
625 	switch (size) {
626 	case 0:
627 		msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
628 		break;
629 
630 	case 1:
631 		msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
632 		break;
633 
634 	case 2:
635 		msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
636 		break;
637 
638 	default:
639 		msg.type = MIPI_DSI_GENERIC_LONG_WRITE;
640 		break;
641 	}
642 
643 	return mipi_dsi_device_transfer(dsi, &msg);
644 }
645 EXPORT_SYMBOL(mipi_dsi_generic_write);
646 
647 /**
648  * mipi_dsi_generic_read() - receive data using a generic read packet
649  * @dsi: DSI peripheral device
650  * @params: buffer containing the request parameters
651  * @num_params: number of request parameters
652  * @data: buffer in which to return the received data
653  * @size: size of receive buffer
654  *
655  * This function will automatically choose the right data type depending on
656  * the number of parameters passed in.
657  *
658  * Return: The number of bytes successfully read or a negative error code on
659  * failure.
660  */
mipi_dsi_generic_read(struct mipi_dsi_device * dsi,const void * params,size_t num_params,void * data,size_t size)661 ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
662 			      size_t num_params, void *data, size_t size)
663 {
664 	struct mipi_dsi_msg msg = {
665 		.channel = dsi->channel,
666 		.tx_len = num_params,
667 		.tx_buf = params,
668 		.rx_len = size,
669 		.rx_buf = data
670 	};
671 
672 	switch (num_params) {
673 	case 0:
674 		msg.type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
675 		break;
676 
677 	case 1:
678 		msg.type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
679 		break;
680 
681 	case 2:
682 		msg.type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
683 		break;
684 
685 	default:
686 		return -EINVAL;
687 	}
688 
689 	return mipi_dsi_device_transfer(dsi, &msg);
690 }
691 EXPORT_SYMBOL(mipi_dsi_generic_read);
692 
693 /**
694  * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload
695  * @dsi: DSI peripheral device
696  * @data: buffer containing data to be transmitted
697  * @len: size of transmission buffer
698  *
699  * This function will automatically choose the right data type depending on
700  * the command payload length.
701  *
702  * Return: The number of bytes successfully transmitted or a negative error
703  * code on failure.
704  */
mipi_dsi_dcs_write_buffer(struct mipi_dsi_device * dsi,const void * data,size_t len)705 ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
706 				  const void *data, size_t len)
707 {
708 	struct mipi_dsi_msg msg = {
709 		.channel = dsi->channel,
710 		.tx_buf = data,
711 		.tx_len = len
712 	};
713 
714 	switch (len) {
715 	case 0:
716 		return -EINVAL;
717 
718 	case 1:
719 		msg.type = MIPI_DSI_DCS_SHORT_WRITE;
720 		break;
721 
722 	case 2:
723 		msg.type = MIPI_DSI_DCS_SHORT_WRITE_PARAM;
724 		break;
725 
726 	default:
727 		msg.type = MIPI_DSI_DCS_LONG_WRITE;
728 		break;
729 	}
730 
731 	return mipi_dsi_device_transfer(dsi, &msg);
732 }
733 EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer);
734 
735 /**
736  * mipi_dsi_dcs_write() - send DCS write command
737  * @dsi: DSI peripheral device
738  * @cmd: DCS command
739  * @data: buffer containing the command payload
740  * @len: command payload length
741  *
742  * This function will automatically choose the right data type depending on
743  * the command payload length.
744  *
745  * Return: The number of bytes successfully transmitted or a negative error
746  * code on failure.
747  */
mipi_dsi_dcs_write(struct mipi_dsi_device * dsi,u8 cmd,const void * data,size_t len)748 ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
749 			   const void *data, size_t len)
750 {
751 	ssize_t err;
752 	size_t size;
753 	u8 stack_tx[8];
754 	u8 *tx;
755 
756 	size = 1 + len;
757 	if (len > ARRAY_SIZE(stack_tx) - 1) {
758 		tx = kmalloc(size, GFP_KERNEL);
759 		if (!tx)
760 			return -ENOMEM;
761 	} else {
762 		tx = stack_tx;
763 	}
764 
765 	/* concatenate the DCS command byte and the payload */
766 	tx[0] = cmd;
767 	if (data)
768 		memcpy(&tx[1], data, len);
769 
770 	err = mipi_dsi_dcs_write_buffer(dsi, tx, size);
771 
772 	if (tx != stack_tx)
773 		kfree(tx);
774 
775 	return err;
776 }
777 EXPORT_SYMBOL(mipi_dsi_dcs_write);
778 
779 /**
780  * mipi_dsi_dcs_read() - send DCS read request command
781  * @dsi: DSI peripheral device
782  * @cmd: DCS command
783  * @data: buffer in which to receive data
784  * @len: size of receive buffer
785  *
786  * Return: The number of bytes read or a negative error code on failure.
787  */
mipi_dsi_dcs_read(struct mipi_dsi_device * dsi,u8 cmd,void * data,size_t len)788 ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
789 			  size_t len)
790 {
791 	struct mipi_dsi_msg msg = {
792 		.channel = dsi->channel,
793 		.type = MIPI_DSI_DCS_READ,
794 		.tx_buf = &cmd,
795 		.tx_len = 1,
796 		.rx_buf = data,
797 		.rx_len = len
798 	};
799 
800 	return mipi_dsi_device_transfer(dsi, &msg);
801 }
802 EXPORT_SYMBOL(mipi_dsi_dcs_read);
803 
804 /**
805  * mipi_dsi_dcs_nop() - send DCS nop packet
806  * @dsi: DSI peripheral device
807  *
808  * Return: 0 on success or a negative error code on failure.
809  */
mipi_dsi_dcs_nop(struct mipi_dsi_device * dsi)810 int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi)
811 {
812 	ssize_t err;
813 
814 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_NOP, NULL, 0);
815 	if (err < 0)
816 		return err;
817 
818 	return 0;
819 }
820 EXPORT_SYMBOL(mipi_dsi_dcs_nop);
821 
822 /**
823  * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module
824  * @dsi: DSI peripheral device
825  *
826  * Return: 0 on success or a negative error code on failure.
827  */
mipi_dsi_dcs_soft_reset(struct mipi_dsi_device * dsi)828 int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi)
829 {
830 	ssize_t err;
831 
832 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SOFT_RESET, NULL, 0);
833 	if (err < 0)
834 		return err;
835 
836 	return 0;
837 }
838 EXPORT_SYMBOL(mipi_dsi_dcs_soft_reset);
839 
840 /**
841  * mipi_dsi_dcs_get_power_mode() - query the display module's current power
842  *    mode
843  * @dsi: DSI peripheral device
844  * @mode: return location for the current power mode
845  *
846  * Return: 0 on success or a negative error code on failure.
847  */
mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device * dsi,u8 * mode)848 int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode)
849 {
850 	ssize_t err;
851 
852 	err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_POWER_MODE, mode,
853 				sizeof(*mode));
854 	if (err <= 0) {
855 		if (err == 0)
856 			err = -ENODATA;
857 
858 		return err;
859 	}
860 
861 	return 0;
862 }
863 EXPORT_SYMBOL(mipi_dsi_dcs_get_power_mode);
864 
865 /**
866  * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image
867  *    data used by the interface
868  * @dsi: DSI peripheral device
869  * @format: return location for the pixel format
870  *
871  * Return: 0 on success or a negative error code on failure.
872  */
mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device * dsi,u8 * format)873 int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format)
874 {
875 	ssize_t err;
876 
877 	err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_PIXEL_FORMAT, format,
878 				sizeof(*format));
879 	if (err <= 0) {
880 		if (err == 0)
881 			err = -ENODATA;
882 
883 		return err;
884 	}
885 
886 	return 0;
887 }
888 EXPORT_SYMBOL(mipi_dsi_dcs_get_pixel_format);
889 
890 /**
891  * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the
892  *    display module except interface communication
893  * @dsi: DSI peripheral device
894  *
895  * Return: 0 on success or a negative error code on failure.
896  */
mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device * dsi)897 int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi)
898 {
899 	ssize_t err;
900 
901 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_ENTER_SLEEP_MODE, NULL, 0);
902 	if (err < 0)
903 		return err;
904 
905 	return 0;
906 }
907 EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode);
908 
909 /**
910  * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
911  *    module
912  * @dsi: DSI peripheral device
913  *
914  * Return: 0 on success or a negative error code on failure.
915  */
mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device * dsi)916 int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi)
917 {
918 	ssize_t err;
919 
920 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_EXIT_SLEEP_MODE, NULL, 0);
921 	if (err < 0)
922 		return err;
923 
924 	return 0;
925 }
926 EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode);
927 
928 /**
929  * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
930  *    display device
931  * @dsi: DSI peripheral device
932  *
933  * Return: 0 on success or a negative error code on failure.
934  */
mipi_dsi_dcs_set_display_off(struct mipi_dsi_device * dsi)935 int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi)
936 {
937 	ssize_t err;
938 
939 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0);
940 	if (err < 0)
941 		return err;
942 
943 	return 0;
944 }
945 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off);
946 
947 /**
948  * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
949  *    display device
950  * @dsi: DSI peripheral device
951  *
952  * Return: 0 on success or a negative error code on failure
953  */
mipi_dsi_dcs_set_display_on(struct mipi_dsi_device * dsi)954 int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi)
955 {
956 	ssize_t err;
957 
958 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_ON, NULL, 0);
959 	if (err < 0)
960 		return err;
961 
962 	return 0;
963 }
964 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_on);
965 
966 /**
967  * mipi_dsi_dcs_set_column_address() - define the column extent of the frame
968  *    memory accessed by the host processor
969  * @dsi: DSI peripheral device
970  * @start: first column of frame memory
971  * @end: last column of frame memory
972  *
973  * Return: 0 on success or a negative error code on failure.
974  */
mipi_dsi_dcs_set_column_address(struct mipi_dsi_device * dsi,u16 start,u16 end)975 int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
976 				    u16 end)
977 {
978 	u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
979 	ssize_t err;
980 
981 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, payload,
982 				 sizeof(payload));
983 	if (err < 0)
984 		return err;
985 
986 	return 0;
987 }
988 EXPORT_SYMBOL(mipi_dsi_dcs_set_column_address);
989 
990 /**
991  * mipi_dsi_dcs_set_page_address() - define the page extent of the frame
992  *    memory accessed by the host processor
993  * @dsi: DSI peripheral device
994  * @start: first page of frame memory
995  * @end: last page of frame memory
996  *
997  * Return: 0 on success or a negative error code on failure.
998  */
mipi_dsi_dcs_set_page_address(struct mipi_dsi_device * dsi,u16 start,u16 end)999 int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
1000 				  u16 end)
1001 {
1002 	u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
1003 	ssize_t err;
1004 
1005 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PAGE_ADDRESS, payload,
1006 				 sizeof(payload));
1007 	if (err < 0)
1008 		return err;
1009 
1010 	return 0;
1011 }
1012 EXPORT_SYMBOL(mipi_dsi_dcs_set_page_address);
1013 
1014 /**
1015  * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect
1016  *    output signal on the TE signal line
1017  * @dsi: DSI peripheral device
1018  *
1019  * Return: 0 on success or a negative error code on failure
1020  */
mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device * dsi)1021 int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi)
1022 {
1023 	ssize_t err;
1024 
1025 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_OFF, NULL, 0);
1026 	if (err < 0)
1027 		return err;
1028 
1029 	return 0;
1030 }
1031 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_off);
1032 
1033 /**
1034  * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect
1035  *    output signal on the TE signal line.
1036  * @dsi: DSI peripheral device
1037  * @mode: the Tearing Effect Output Line mode
1038  *
1039  * Return: 0 on success or a negative error code on failure
1040  */
mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device * dsi,enum mipi_dsi_dcs_tear_mode mode)1041 int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
1042 			     enum mipi_dsi_dcs_tear_mode mode)
1043 {
1044 	u8 value = mode;
1045 	ssize_t err;
1046 
1047 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_ON, &value,
1048 				 sizeof(value));
1049 	if (err < 0)
1050 		return err;
1051 
1052 	return 0;
1053 }
1054 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_on);
1055 
1056 /**
1057  * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image
1058  *    data used by the interface
1059  * @dsi: DSI peripheral device
1060  * @format: pixel format
1061  *
1062  * Return: 0 on success or a negative error code on failure.
1063  */
mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device * dsi,u8 format)1064 int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format)
1065 {
1066 	ssize_t err;
1067 
1068 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PIXEL_FORMAT, &format,
1069 				 sizeof(format));
1070 	if (err < 0)
1071 		return err;
1072 
1073 	return 0;
1074 }
1075 EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format);
1076 
1077 /**
1078  * mipi_dsi_dcs_set_tear_scanline() - set the scanline to use as trigger for
1079  *    the Tearing Effect output signal of the display module
1080  * @dsi: DSI peripheral device
1081  * @scanline: scanline to use as trigger
1082  *
1083  * Return: 0 on success or a negative error code on failure
1084  */
mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device * dsi,u16 scanline)1085 int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline)
1086 {
1087 	u8 payload[2] = { scanline >> 8, scanline & 0xff };
1088 	ssize_t err;
1089 
1090 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_SCANLINE, payload,
1091 				 sizeof(payload));
1092 	if (err < 0)
1093 		return err;
1094 
1095 	return 0;
1096 }
1097 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_scanline);
1098 
1099 /**
1100  * mipi_dsi_dcs_set_display_brightness() - sets the brightness value of the
1101  *    display
1102  * @dsi: DSI peripheral device
1103  * @brightness: brightness value
1104  *
1105  * Return: 0 on success or a negative error code on failure.
1106  */
mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device * dsi,u16 brightness)1107 int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi,
1108 					u16 brightness)
1109 {
1110 	u8 payload[2] = { brightness & 0xff, brightness >> 8 };
1111 	ssize_t err;
1112 
1113 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
1114 				 payload, sizeof(payload));
1115 	if (err < 0)
1116 		return err;
1117 
1118 	return 0;
1119 }
1120 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_brightness);
1121 
1122 /**
1123  * mipi_dsi_dcs_get_display_brightness() - gets the current brightness value
1124  *    of the display
1125  * @dsi: DSI peripheral device
1126  * @brightness: brightness value
1127  *
1128  * Return: 0 on success or a negative error code on failure.
1129  */
mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device * dsi,u16 * brightness)1130 int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
1131 					u16 *brightness)
1132 {
1133 	ssize_t err;
1134 
1135 	err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_DISPLAY_BRIGHTNESS,
1136 				brightness, sizeof(*brightness));
1137 	if (err <= 0) {
1138 		if (err == 0)
1139 			err = -ENODATA;
1140 
1141 		return err;
1142 	}
1143 
1144 	return 0;
1145 }
1146 EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness);
1147 
1148 /**
1149  * mipi_dsi_dcs_set_display_brightness_large() - sets the 16-bit brightness value
1150  *    of the display
1151  * @dsi: DSI peripheral device
1152  * @brightness: brightness value
1153  *
1154  * Return: 0 on success or a negative error code on failure.
1155  */
mipi_dsi_dcs_set_display_brightness_large(struct mipi_dsi_device * dsi,u16 brightness)1156 int mipi_dsi_dcs_set_display_brightness_large(struct mipi_dsi_device *dsi,
1157 					     u16 brightness)
1158 {
1159 	u8 payload[2] = { brightness >> 8, brightness & 0xff };
1160 	ssize_t err;
1161 
1162 	err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
1163 				 payload, sizeof(payload));
1164 	if (err < 0)
1165 		return err;
1166 
1167 	return 0;
1168 }
1169 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_brightness_large);
1170 
1171 /**
1172  * mipi_dsi_dcs_get_display_brightness_large() - gets the current 16-bit
1173  *    brightness value of the display
1174  * @dsi: DSI peripheral device
1175  * @brightness: brightness value
1176  *
1177  * Return: 0 on success or a negative error code on failure.
1178  */
mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device * dsi,u16 * brightness)1179 int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi,
1180 					     u16 *brightness)
1181 {
1182 	u8 brightness_be[2];
1183 	ssize_t err;
1184 
1185 	err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_DISPLAY_BRIGHTNESS,
1186 				brightness_be, sizeof(brightness_be));
1187 	if (err <= 0) {
1188 		if (err == 0)
1189 			err = -ENODATA;
1190 
1191 		return err;
1192 	}
1193 
1194 	*brightness = (brightness_be[0] << 8) | brightness_be[1];
1195 
1196 	return 0;
1197 }
1198 EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness_large);
1199 
mipi_dsi_drv_probe(struct device * dev)1200 static int mipi_dsi_drv_probe(struct device *dev)
1201 {
1202 	struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
1203 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
1204 
1205 	return drv->probe(dsi);
1206 }
1207 
mipi_dsi_drv_remove(struct device * dev)1208 static int mipi_dsi_drv_remove(struct device *dev)
1209 {
1210 	struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
1211 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
1212 
1213 	return drv->remove(dsi);
1214 }
1215 
mipi_dsi_drv_shutdown(struct device * dev)1216 static void mipi_dsi_drv_shutdown(struct device *dev)
1217 {
1218 	struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
1219 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
1220 
1221 	drv->shutdown(dsi);
1222 }
1223 
1224 /**
1225  * mipi_dsi_driver_register_full() - register a driver for DSI devices
1226  * @drv: DSI driver structure
1227  * @owner: owner module
1228  *
1229  * Return: 0 on success or a negative error code on failure.
1230  */
mipi_dsi_driver_register_full(struct mipi_dsi_driver * drv,struct module * owner)1231 int mipi_dsi_driver_register_full(struct mipi_dsi_driver *drv,
1232 				  struct module *owner)
1233 {
1234 	drv->driver.bus = &mipi_dsi_bus_type;
1235 	drv->driver.owner = owner;
1236 
1237 	if (drv->probe)
1238 		drv->driver.probe = mipi_dsi_drv_probe;
1239 	if (drv->remove)
1240 		drv->driver.remove = mipi_dsi_drv_remove;
1241 	if (drv->shutdown)
1242 		drv->driver.shutdown = mipi_dsi_drv_shutdown;
1243 
1244 	return driver_register(&drv->driver);
1245 }
1246 EXPORT_SYMBOL(mipi_dsi_driver_register_full);
1247 
1248 /**
1249  * mipi_dsi_driver_unregister() - unregister a driver for DSI devices
1250  * @drv: DSI driver structure
1251  *
1252  * Return: 0 on success or a negative error code on failure.
1253  */
mipi_dsi_driver_unregister(struct mipi_dsi_driver * drv)1254 void mipi_dsi_driver_unregister(struct mipi_dsi_driver *drv)
1255 {
1256 	driver_unregister(&drv->driver);
1257 }
1258 EXPORT_SYMBOL(mipi_dsi_driver_unregister);
1259 
mipi_dsi_bus_init(void)1260 static int __init mipi_dsi_bus_init(void)
1261 {
1262 	return bus_register(&mipi_dsi_bus_type);
1263 }
1264 postcore_initcall(mipi_dsi_bus_init);
1265 
1266 MODULE_AUTHOR("Andrzej Hajda <a.hajda@samsung.com>");
1267 MODULE_DESCRIPTION("MIPI DSI Bus");
1268 MODULE_LICENSE("GPL and additional rights");
1269