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