mipi_dsi.c 20 KB

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