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