drm_mipi_dsi.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053
  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. #include <linux/device.h>
  28. #include <linux/export.h>
  29. #include <linux/module.h>
  30. #include <linux/of.h>
  31. #include <linux/of_device.h>
  32. #include <linux/pm_runtime.h>
  33. #include <linux/slab.h>
  34. #include <drm/display/drm_dsc.h>
  35. #include <drm/drm_mipi_dsi.h>
  36. #include <drm/drm_print.h>
  37. #include <linux/media-bus-format.h>
  38. #include <video/mipi_display.h>
  39. /**
  40. * DOC: dsi helpers
  41. *
  42. * These functions contain some common logic and helpers to deal with MIPI DSI
  43. * peripherals.
  44. *
  45. * Helpers are provided for a number of standard MIPI DSI command as well as a
  46. * subset of the MIPI DCS command set.
  47. */
  48. static int mipi_dsi_device_match(struct device *dev, const struct device_driver *drv)
  49. {
  50. struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
  51. /* attempt OF style match */
  52. if (of_driver_match_device(dev, drv))
  53. return 1;
  54. /* compare DSI device and driver names */
  55. if (!strcmp(dsi->name, drv->name))
  56. return 1;
  57. return 0;
  58. }
  59. static int mipi_dsi_uevent(const struct device *dev, struct kobj_uevent_env *env)
  60. {
  61. const struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
  62. int err;
  63. err = of_device_uevent_modalias(dev, env);
  64. if (err != -ENODEV)
  65. return err;
  66. add_uevent_var(env, "MODALIAS=%s%s", MIPI_DSI_MODULE_PREFIX,
  67. dsi->name);
  68. return 0;
  69. }
  70. static const struct dev_pm_ops mipi_dsi_device_pm_ops = {
  71. .runtime_suspend = pm_generic_runtime_suspend,
  72. .runtime_resume = pm_generic_runtime_resume,
  73. .suspend = pm_generic_suspend,
  74. .resume = pm_generic_resume,
  75. .freeze = pm_generic_freeze,
  76. .thaw = pm_generic_thaw,
  77. .poweroff = pm_generic_poweroff,
  78. .restore = pm_generic_restore,
  79. };
  80. const struct bus_type mipi_dsi_bus_type = {
  81. .name = "mipi-dsi",
  82. .match = mipi_dsi_device_match,
  83. .uevent = mipi_dsi_uevent,
  84. .pm = &mipi_dsi_device_pm_ops,
  85. };
  86. EXPORT_SYMBOL_GPL(mipi_dsi_bus_type);
  87. /**
  88. * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
  89. * device tree node
  90. * @np: device tree node
  91. *
  92. * Return: A pointer to the MIPI DSI device corresponding to @np or NULL if no
  93. * such device exists (or has not been registered yet).
  94. */
  95. struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
  96. {
  97. struct device *dev;
  98. dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);
  99. return dev ? to_mipi_dsi_device(dev) : NULL;
  100. }
  101. EXPORT_SYMBOL(of_find_mipi_dsi_device_by_node);
  102. static void mipi_dsi_dev_release(struct device *dev)
  103. {
  104. struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
  105. of_node_put(dev->of_node);
  106. kfree(dsi);
  107. }
  108. static const struct device_type mipi_dsi_device_type = {
  109. .release = mipi_dsi_dev_release,
  110. };
  111. static struct mipi_dsi_device *mipi_dsi_device_alloc(struct mipi_dsi_host *host)
  112. {
  113. struct mipi_dsi_device *dsi;
  114. dsi = kzalloc_obj(*dsi);
  115. if (!dsi)
  116. return ERR_PTR(-ENOMEM);
  117. dsi->host = host;
  118. dsi->dev.bus = &mipi_dsi_bus_type;
  119. dsi->dev.parent = host->dev;
  120. dsi->dev.type = &mipi_dsi_device_type;
  121. device_initialize(&dsi->dev);
  122. return dsi;
  123. }
  124. static int mipi_dsi_device_add(struct mipi_dsi_device *dsi)
  125. {
  126. struct mipi_dsi_host *host = dsi->host;
  127. dev_set_name(&dsi->dev, "%s.%d", dev_name(host->dev), dsi->channel);
  128. return device_add(&dsi->dev);
  129. }
  130. #if IS_ENABLED(CONFIG_OF)
  131. static struct mipi_dsi_device *
  132. of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
  133. {
  134. struct mipi_dsi_device_info info = { };
  135. int ret;
  136. u32 reg;
  137. if (of_alias_from_compatible(node, info.type, sizeof(info.type)) < 0) {
  138. dev_err(host->dev, "modalias failure on %pOF\n", node);
  139. return ERR_PTR(-EINVAL);
  140. }
  141. ret = of_property_read_u32(node, "reg", &reg);
  142. if (ret) {
  143. dev_err(host->dev, "device node %pOF has no valid reg property: %d\n",
  144. node, ret);
  145. return ERR_PTR(-EINVAL);
  146. }
  147. info.channel = reg;
  148. info.node = of_node_get(node);
  149. return mipi_dsi_device_register_full(host, &info);
  150. }
  151. #else
  152. static struct mipi_dsi_device *
  153. of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
  154. {
  155. return ERR_PTR(-ENODEV);
  156. }
  157. #endif
  158. /**
  159. * mipi_dsi_device_register_full - create a MIPI DSI device
  160. * @host: DSI host to which this device is connected
  161. * @info: pointer to template containing DSI device information
  162. *
  163. * Create a MIPI DSI device by using the device information provided by
  164. * mipi_dsi_device_info template
  165. *
  166. * Returns:
  167. * A pointer to the newly created MIPI DSI device, or, a pointer encoded
  168. * with an error
  169. */
  170. struct mipi_dsi_device *
  171. mipi_dsi_device_register_full(struct mipi_dsi_host *host,
  172. const struct mipi_dsi_device_info *info)
  173. {
  174. struct mipi_dsi_device *dsi;
  175. int ret;
  176. if (!info) {
  177. dev_err(host->dev, "invalid mipi_dsi_device_info pointer\n");
  178. return ERR_PTR(-EINVAL);
  179. }
  180. if (info->channel > 3) {
  181. dev_err(host->dev, "invalid virtual channel: %u\n", info->channel);
  182. return ERR_PTR(-EINVAL);
  183. }
  184. dsi = mipi_dsi_device_alloc(host);
  185. if (IS_ERR(dsi)) {
  186. dev_err(host->dev, "failed to allocate DSI device %ld\n",
  187. PTR_ERR(dsi));
  188. return dsi;
  189. }
  190. device_set_node(&dsi->dev, of_fwnode_handle(info->node));
  191. dsi->channel = info->channel;
  192. strscpy(dsi->name, info->type, sizeof(dsi->name));
  193. ret = mipi_dsi_device_add(dsi);
  194. if (ret) {
  195. dev_err(host->dev, "failed to add DSI device %d\n", ret);
  196. kfree(dsi);
  197. return ERR_PTR(ret);
  198. }
  199. return dsi;
  200. }
  201. EXPORT_SYMBOL(mipi_dsi_device_register_full);
  202. /**
  203. * mipi_dsi_device_unregister - unregister MIPI DSI device
  204. * @dsi: DSI peripheral device
  205. */
  206. void mipi_dsi_device_unregister(struct mipi_dsi_device *dsi)
  207. {
  208. device_unregister(&dsi->dev);
  209. }
  210. EXPORT_SYMBOL(mipi_dsi_device_unregister);
  211. static void devm_mipi_dsi_device_unregister(void *arg)
  212. {
  213. struct mipi_dsi_device *dsi = arg;
  214. mipi_dsi_device_unregister(dsi);
  215. }
  216. /**
  217. * devm_mipi_dsi_device_register_full - create a managed MIPI DSI device
  218. * @dev: device to tie the MIPI-DSI device lifetime to
  219. * @host: DSI host to which this device is connected
  220. * @info: pointer to template containing DSI device information
  221. *
  222. * Create a MIPI DSI device by using the device information provided by
  223. * mipi_dsi_device_info template
  224. *
  225. * This is the managed version of mipi_dsi_device_register_full() which
  226. * automatically calls mipi_dsi_device_unregister() when @dev is
  227. * unbound.
  228. *
  229. * Returns:
  230. * A pointer to the newly created MIPI DSI device, or, a pointer encoded
  231. * with an error
  232. */
  233. struct mipi_dsi_device *
  234. devm_mipi_dsi_device_register_full(struct device *dev,
  235. struct mipi_dsi_host *host,
  236. const struct mipi_dsi_device_info *info)
  237. {
  238. struct mipi_dsi_device *dsi;
  239. int ret;
  240. dsi = mipi_dsi_device_register_full(host, info);
  241. if (IS_ERR(dsi))
  242. return dsi;
  243. ret = devm_add_action_or_reset(dev,
  244. devm_mipi_dsi_device_unregister,
  245. dsi);
  246. if (ret)
  247. return ERR_PTR(ret);
  248. return dsi;
  249. }
  250. EXPORT_SYMBOL_GPL(devm_mipi_dsi_device_register_full);
  251. static DEFINE_MUTEX(host_lock);
  252. static LIST_HEAD(host_list);
  253. /**
  254. * of_find_mipi_dsi_host_by_node() - find the MIPI DSI host matching a
  255. * device tree node
  256. * @node: device tree node
  257. *
  258. * Returns:
  259. * A pointer to the MIPI DSI host corresponding to @node or NULL if no
  260. * such device exists (or has not been registered yet).
  261. */
  262. struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node)
  263. {
  264. struct mipi_dsi_host *host;
  265. mutex_lock(&host_lock);
  266. list_for_each_entry(host, &host_list, list) {
  267. if (host->dev->of_node == node) {
  268. mutex_unlock(&host_lock);
  269. return host;
  270. }
  271. }
  272. mutex_unlock(&host_lock);
  273. return NULL;
  274. }
  275. EXPORT_SYMBOL(of_find_mipi_dsi_host_by_node);
  276. int mipi_dsi_host_register(struct mipi_dsi_host *host)
  277. {
  278. struct device_node *node;
  279. for_each_available_child_of_node(host->dev->of_node, node) {
  280. /* skip nodes without reg property */
  281. if (!of_property_present(node, "reg"))
  282. continue;
  283. of_mipi_dsi_device_add(host, node);
  284. }
  285. mutex_lock(&host_lock);
  286. list_add_tail(&host->list, &host_list);
  287. mutex_unlock(&host_lock);
  288. return 0;
  289. }
  290. EXPORT_SYMBOL(mipi_dsi_host_register);
  291. static int mipi_dsi_remove_device_fn(struct device *dev, void *priv)
  292. {
  293. struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
  294. if (dsi->attached)
  295. mipi_dsi_detach(dsi);
  296. mipi_dsi_device_unregister(dsi);
  297. return 0;
  298. }
  299. void mipi_dsi_host_unregister(struct mipi_dsi_host *host)
  300. {
  301. device_for_each_child(host->dev, NULL, mipi_dsi_remove_device_fn);
  302. mutex_lock(&host_lock);
  303. list_del_init(&host->list);
  304. mutex_unlock(&host_lock);
  305. }
  306. EXPORT_SYMBOL(mipi_dsi_host_unregister);
  307. /**
  308. * mipi_dsi_attach - attach a DSI device to its DSI host
  309. * @dsi: DSI peripheral
  310. */
  311. int mipi_dsi_attach(struct mipi_dsi_device *dsi)
  312. {
  313. const struct mipi_dsi_host_ops *ops = dsi->host->ops;
  314. int ret;
  315. if (!ops || !ops->attach)
  316. return -ENOSYS;
  317. ret = ops->attach(dsi->host, dsi);
  318. if (ret)
  319. return ret;
  320. dsi->attached = true;
  321. return 0;
  322. }
  323. EXPORT_SYMBOL(mipi_dsi_attach);
  324. /**
  325. * mipi_dsi_detach - detach a DSI device from its DSI host
  326. * @dsi: DSI peripheral
  327. */
  328. int mipi_dsi_detach(struct mipi_dsi_device *dsi)
  329. {
  330. const struct mipi_dsi_host_ops *ops = dsi->host->ops;
  331. if (WARN_ON(!dsi->attached))
  332. return -EINVAL;
  333. if (!ops || !ops->detach)
  334. return -ENOSYS;
  335. dsi->attached = false;
  336. return ops->detach(dsi->host, dsi);
  337. }
  338. EXPORT_SYMBOL(mipi_dsi_detach);
  339. static void devm_mipi_dsi_detach(void *arg)
  340. {
  341. struct mipi_dsi_device *dsi = arg;
  342. mipi_dsi_detach(dsi);
  343. }
  344. /**
  345. * devm_mipi_dsi_attach - Attach a MIPI-DSI device to its DSI Host
  346. * @dev: device to tie the MIPI-DSI device attachment lifetime to
  347. * @dsi: DSI peripheral
  348. *
  349. * This is the managed version of mipi_dsi_attach() which automatically
  350. * calls mipi_dsi_detach() when @dev is unbound.
  351. *
  352. * Returns:
  353. * 0 on success, a negative error code on failure.
  354. */
  355. int devm_mipi_dsi_attach(struct device *dev,
  356. struct mipi_dsi_device *dsi)
  357. {
  358. int ret;
  359. ret = mipi_dsi_attach(dsi);
  360. if (ret)
  361. return ret;
  362. ret = devm_add_action_or_reset(dev, devm_mipi_dsi_detach, dsi);
  363. if (ret)
  364. return ret;
  365. return 0;
  366. }
  367. EXPORT_SYMBOL_GPL(devm_mipi_dsi_attach);
  368. static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi,
  369. struct mipi_dsi_msg *msg)
  370. {
  371. const struct mipi_dsi_host_ops *ops = dsi->host->ops;
  372. if (!ops || !ops->transfer)
  373. return -ENOSYS;
  374. if (dsi->mode_flags & MIPI_DSI_MODE_LPM)
  375. msg->flags |= MIPI_DSI_MSG_USE_LPM;
  376. return ops->transfer(dsi->host, msg);
  377. }
  378. /**
  379. * mipi_dsi_packet_format_is_short - check if a packet is of the short format
  380. * @type: MIPI DSI data type of the packet
  381. *
  382. * Return: true if the packet for the given data type is a short packet, false
  383. * otherwise.
  384. */
  385. bool mipi_dsi_packet_format_is_short(u8 type)
  386. {
  387. switch (type) {
  388. case MIPI_DSI_V_SYNC_START:
  389. case MIPI_DSI_V_SYNC_END:
  390. case MIPI_DSI_H_SYNC_START:
  391. case MIPI_DSI_H_SYNC_END:
  392. case MIPI_DSI_COMPRESSION_MODE:
  393. case MIPI_DSI_END_OF_TRANSMISSION:
  394. case MIPI_DSI_COLOR_MODE_OFF:
  395. case MIPI_DSI_COLOR_MODE_ON:
  396. case MIPI_DSI_SHUTDOWN_PERIPHERAL:
  397. case MIPI_DSI_TURN_ON_PERIPHERAL:
  398. case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
  399. case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
  400. case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
  401. case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
  402. case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
  403. case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
  404. case MIPI_DSI_DCS_SHORT_WRITE:
  405. case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
  406. case MIPI_DSI_DCS_READ:
  407. case MIPI_DSI_EXECUTE_QUEUE:
  408. case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
  409. return true;
  410. }
  411. return false;
  412. }
  413. EXPORT_SYMBOL(mipi_dsi_packet_format_is_short);
  414. /**
  415. * mipi_dsi_packet_format_is_long - check if a packet is of the long format
  416. * @type: MIPI DSI data type of the packet
  417. *
  418. * Return: true if the packet for the given data type is a long packet, false
  419. * otherwise.
  420. */
  421. bool mipi_dsi_packet_format_is_long(u8 type)
  422. {
  423. switch (type) {
  424. case MIPI_DSI_NULL_PACKET:
  425. case MIPI_DSI_BLANKING_PACKET:
  426. case MIPI_DSI_GENERIC_LONG_WRITE:
  427. case MIPI_DSI_DCS_LONG_WRITE:
  428. case MIPI_DSI_PICTURE_PARAMETER_SET:
  429. case MIPI_DSI_COMPRESSED_PIXEL_STREAM:
  430. case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20:
  431. case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24:
  432. case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16:
  433. case MIPI_DSI_PACKED_PIXEL_STREAM_30:
  434. case MIPI_DSI_PACKED_PIXEL_STREAM_36:
  435. case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12:
  436. case MIPI_DSI_PACKED_PIXEL_STREAM_16:
  437. case MIPI_DSI_PACKED_PIXEL_STREAM_18:
  438. case MIPI_DSI_PIXEL_STREAM_3BYTE_18:
  439. case MIPI_DSI_PACKED_PIXEL_STREAM_24:
  440. return true;
  441. }
  442. return false;
  443. }
  444. EXPORT_SYMBOL(mipi_dsi_packet_format_is_long);
  445. /**
  446. * mipi_dsi_create_packet - create a packet from a message according to the
  447. * DSI protocol
  448. * @packet: pointer to a DSI packet structure
  449. * @msg: message to translate into a packet
  450. *
  451. * Return: 0 on success or a negative error code on failure.
  452. */
  453. int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
  454. const struct mipi_dsi_msg *msg)
  455. {
  456. if (!packet || !msg)
  457. return -EINVAL;
  458. /* do some minimum sanity checking */
  459. if (!mipi_dsi_packet_format_is_short(msg->type) &&
  460. !mipi_dsi_packet_format_is_long(msg->type))
  461. return -EINVAL;
  462. if (msg->channel > 3)
  463. return -EINVAL;
  464. memset(packet, 0, sizeof(*packet));
  465. packet->header[0] = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f);
  466. /* TODO: compute ECC if hardware support is not available */
  467. /*
  468. * Long write packets contain the word count in header bytes 1 and 2.
  469. * The payload follows the header and is word count bytes long.
  470. *
  471. * Short write packets encode up to two parameters in header bytes 1
  472. * and 2.
  473. */
  474. if (mipi_dsi_packet_format_is_long(msg->type)) {
  475. packet->header[1] = (msg->tx_len >> 0) & 0xff;
  476. packet->header[2] = (msg->tx_len >> 8) & 0xff;
  477. packet->payload_length = msg->tx_len;
  478. packet->payload = msg->tx_buf;
  479. } else {
  480. const u8 *tx = msg->tx_buf;
  481. packet->header[1] = (msg->tx_len > 0) ? tx[0] : 0;
  482. packet->header[2] = (msg->tx_len > 1) ? tx[1] : 0;
  483. }
  484. packet->size = sizeof(packet->header) + packet->payload_length;
  485. return 0;
  486. }
  487. EXPORT_SYMBOL(mipi_dsi_create_packet);
  488. /**
  489. * mipi_dsi_shutdown_peripheral() - sends a Shutdown Peripheral command
  490. * @dsi: DSI peripheral device
  491. *
  492. * Return: 0 on success or a negative error code on failure.
  493. */
  494. int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
  495. {
  496. struct mipi_dsi_msg msg = {
  497. .channel = dsi->channel,
  498. .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
  499. .tx_buf = (u8 [2]) { 0, 0 },
  500. .tx_len = 2,
  501. };
  502. int ret = mipi_dsi_device_transfer(dsi, &msg);
  503. return (ret < 0) ? ret : 0;
  504. }
  505. EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);
  506. /**
  507. * mipi_dsi_turn_on_peripheral() - sends a Turn On Peripheral command
  508. * @dsi: DSI peripheral device
  509. *
  510. * This function is deprecated. Use mipi_dsi_turn_on_peripheral_multi() instead.
  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. int ret = mipi_dsi_device_transfer(dsi, &msg);
  523. return (ret < 0) ? ret : 0;
  524. }
  525. EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);
  526. /*
  527. * mipi_dsi_set_maximum_return_packet_size() - specify the maximum size of
  528. * the payload in a long packet transmitted from the peripheral back to the
  529. * host processor
  530. * @dsi: DSI peripheral device
  531. * @value: the maximum size of the payload
  532. *
  533. * Return: 0 on success or a negative error code on failure.
  534. */
  535. int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
  536. u16 value)
  537. {
  538. u8 tx[2] = { value & 0xff, value >> 8 };
  539. struct mipi_dsi_msg msg = {
  540. .channel = dsi->channel,
  541. .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
  542. .tx_len = sizeof(tx),
  543. .tx_buf = tx,
  544. };
  545. int ret = mipi_dsi_device_transfer(dsi, &msg);
  546. return (ret < 0) ? ret : 0;
  547. }
  548. EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
  549. /**
  550. * mipi_dsi_compression_mode_ext() - enable/disable DSC on the peripheral
  551. * @dsi: DSI peripheral device
  552. * @enable: Whether to enable or disable the DSC
  553. * @algo: Selected compression algorithm
  554. * @pps_selector: Select PPS from the table of pre-stored or uploaded PPS entries
  555. *
  556. * Enable or disable Display Stream Compression on the peripheral.
  557. * This function is deprecated. Use mipi_dsi_compression_mode_ext_multi() instead.
  558. *
  559. * Return: 0 on success or a negative error code on failure.
  560. */
  561. int mipi_dsi_compression_mode_ext(struct mipi_dsi_device *dsi, bool enable,
  562. enum mipi_dsi_compression_algo algo,
  563. unsigned int pps_selector)
  564. {
  565. u8 tx[2] = { };
  566. struct mipi_dsi_msg msg = {
  567. .channel = dsi->channel,
  568. .type = MIPI_DSI_COMPRESSION_MODE,
  569. .tx_len = sizeof(tx),
  570. .tx_buf = tx,
  571. };
  572. int ret;
  573. if (algo > 3 || pps_selector > 3)
  574. return -EINVAL;
  575. tx[0] = (enable << 0) |
  576. (algo << 1) |
  577. (pps_selector << 4);
  578. ret = mipi_dsi_device_transfer(dsi, &msg);
  579. return (ret < 0) ? ret : 0;
  580. }
  581. EXPORT_SYMBOL(mipi_dsi_compression_mode_ext);
  582. /**
  583. * mipi_dsi_compression_mode() - enable/disable DSC on the peripheral
  584. * @dsi: DSI peripheral device
  585. * @enable: Whether to enable or disable the DSC
  586. *
  587. * Enable or disable Display Stream Compression on the peripheral using the
  588. * default Picture Parameter Set and VESA DSC 1.1 algorithm.
  589. *
  590. * Return: 0 on success or a negative error code on failure.
  591. */
  592. int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable)
  593. {
  594. return mipi_dsi_compression_mode_ext(dsi, enable, MIPI_DSI_COMPRESSION_DSC, 0);
  595. }
  596. EXPORT_SYMBOL(mipi_dsi_compression_mode);
  597. /**
  598. * mipi_dsi_picture_parameter_set() - transmit the DSC PPS to the peripheral
  599. * @dsi: DSI peripheral device
  600. * @pps: VESA DSC 1.1 Picture Parameter Set
  601. *
  602. * Transmit the VESA DSC 1.1 Picture Parameter Set to the peripheral.
  603. * This function is deprecated. Use mipi_dsi_picture_parameter_set_multi() instead.
  604. *
  605. * Return: 0 on success or a negative error code on failure.
  606. */
  607. int mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
  608. const struct drm_dsc_picture_parameter_set *pps)
  609. {
  610. struct mipi_dsi_msg msg = {
  611. .channel = dsi->channel,
  612. .type = MIPI_DSI_PICTURE_PARAMETER_SET,
  613. .tx_len = sizeof(*pps),
  614. .tx_buf = pps,
  615. };
  616. int ret = mipi_dsi_device_transfer(dsi, &msg);
  617. return (ret < 0) ? ret : 0;
  618. }
  619. EXPORT_SYMBOL(mipi_dsi_picture_parameter_set);
  620. /**
  621. * mipi_dsi_generic_write() - transmit data using a generic write packet
  622. * @dsi: DSI peripheral device
  623. * @payload: buffer containing the payload
  624. * @size: size of payload buffer
  625. *
  626. * This function will automatically choose the right data type depending on
  627. * the payload length.
  628. *
  629. * Return: The number of bytes transmitted on success or a negative error code
  630. * on failure.
  631. */
  632. ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
  633. size_t size)
  634. {
  635. struct mipi_dsi_msg msg = {
  636. .channel = dsi->channel,
  637. .tx_buf = payload,
  638. .tx_len = size
  639. };
  640. switch (size) {
  641. case 0:
  642. msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
  643. break;
  644. case 1:
  645. msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
  646. break;
  647. case 2:
  648. msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
  649. break;
  650. default:
  651. msg.type = MIPI_DSI_GENERIC_LONG_WRITE;
  652. break;
  653. }
  654. return mipi_dsi_device_transfer(dsi, &msg);
  655. }
  656. EXPORT_SYMBOL(mipi_dsi_generic_write);
  657. /**
  658. * mipi_dsi_generic_write_multi() - mipi_dsi_generic_write() w/ accum_err
  659. * @ctx: Context for multiple DSI transactions
  660. * @payload: buffer containing the payload
  661. * @size: size of payload buffer
  662. *
  663. * A wrapper around mipi_dsi_generic_write() that deals with errors in a way
  664. * that makes it convenient to make several calls in a row.
  665. */
  666. void mipi_dsi_generic_write_multi(struct mipi_dsi_multi_context *ctx,
  667. const void *payload, size_t size)
  668. {
  669. struct mipi_dsi_device *dsi = ctx->dsi;
  670. struct device *dev = &dsi->dev;
  671. ssize_t ret;
  672. if (ctx->accum_err)
  673. return;
  674. ret = mipi_dsi_generic_write(dsi, payload, size);
  675. if (ret < 0) {
  676. ctx->accum_err = ret;
  677. dev_err(dev, "sending generic data %*ph failed: %d\n",
  678. (int)size, payload, ctx->accum_err);
  679. }
  680. }
  681. EXPORT_SYMBOL(mipi_dsi_generic_write_multi);
  682. /**
  683. * mipi_dsi_dual_generic_write_multi() - mipi_dsi_generic_write_multi() for
  684. * two dsi channels, one after the other
  685. * @ctx: Context for multiple DSI transactions
  686. * @dsi1: First dsi channel to write buffer to
  687. * @dsi2: Second dsi channel to write buffer to
  688. * @payload: Buffer containing the payload
  689. * @size: Size of payload buffer
  690. *
  691. * A wrapper around mipi_dsi_generic_write_multi() that allows the user to
  692. * conveniently write to two dsi channels, one after the other.
  693. */
  694. void mipi_dsi_dual_generic_write_multi(struct mipi_dsi_multi_context *ctx,
  695. struct mipi_dsi_device *dsi1,
  696. struct mipi_dsi_device *dsi2,
  697. const void *payload, size_t size)
  698. {
  699. ctx->dsi = dsi1;
  700. mipi_dsi_generic_write_multi(ctx, payload, size);
  701. ctx->dsi = dsi2;
  702. mipi_dsi_generic_write_multi(ctx, payload, size);
  703. }
  704. EXPORT_SYMBOL(mipi_dsi_dual_generic_write_multi);
  705. /**
  706. * mipi_dsi_generic_read() - receive data using a generic read packet
  707. * @dsi: DSI peripheral device
  708. * @params: buffer containing the request parameters
  709. * @num_params: number of request parameters
  710. * @data: buffer in which to return the received data
  711. * @size: size of receive buffer
  712. *
  713. * This function will automatically choose the right data type depending on
  714. * the number of parameters passed in.
  715. *
  716. * Return: The number of bytes successfully read or a negative error code on
  717. * failure.
  718. */
  719. ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
  720. size_t num_params, void *data, size_t size)
  721. {
  722. struct mipi_dsi_msg msg = {
  723. .channel = dsi->channel,
  724. .tx_len = num_params,
  725. .tx_buf = params,
  726. .rx_len = size,
  727. .rx_buf = data
  728. };
  729. switch (num_params) {
  730. case 0:
  731. msg.type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
  732. break;
  733. case 1:
  734. msg.type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
  735. break;
  736. case 2:
  737. msg.type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
  738. break;
  739. default:
  740. return -EINVAL;
  741. }
  742. return mipi_dsi_device_transfer(dsi, &msg);
  743. }
  744. EXPORT_SYMBOL(mipi_dsi_generic_read);
  745. /**
  746. * drm_mipi_dsi_get_input_bus_fmt() - Get the required MEDIA_BUS_FMT_* based
  747. * input pixel format for a given DSI output
  748. * pixel format
  749. * @dsi_format: pixel format that a DSI host needs to output
  750. *
  751. * Various DSI hosts can use this function during their
  752. * &drm_bridge_funcs.atomic_get_input_bus_fmts operation to ascertain
  753. * the MEDIA_BUS_FMT_* pixel format required as input.
  754. *
  755. * RETURNS:
  756. * a 32-bit MEDIA_BUS_FMT_* value on success or 0 in case of failure.
  757. */
  758. u32 drm_mipi_dsi_get_input_bus_fmt(enum mipi_dsi_pixel_format dsi_format)
  759. {
  760. switch (dsi_format) {
  761. case MIPI_DSI_FMT_RGB888:
  762. return MEDIA_BUS_FMT_RGB888_1X24;
  763. case MIPI_DSI_FMT_RGB666:
  764. return MEDIA_BUS_FMT_RGB666_1X24_CPADHI;
  765. case MIPI_DSI_FMT_RGB666_PACKED:
  766. return MEDIA_BUS_FMT_RGB666_1X18;
  767. case MIPI_DSI_FMT_RGB565:
  768. return MEDIA_BUS_FMT_RGB565_1X16;
  769. default:
  770. /* Unsupported DSI Format */
  771. return 0;
  772. }
  773. }
  774. EXPORT_SYMBOL(drm_mipi_dsi_get_input_bus_fmt);
  775. /**
  776. * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload
  777. * @dsi: DSI peripheral device
  778. * @data: buffer containing data to be transmitted
  779. * @len: size of transmission buffer
  780. *
  781. * This function will automatically choose the right data type depending on
  782. * the command payload length.
  783. *
  784. * Return: The number of bytes successfully transmitted or a negative error
  785. * code on failure.
  786. */
  787. ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
  788. const void *data, size_t len)
  789. {
  790. struct mipi_dsi_msg msg = {
  791. .channel = dsi->channel,
  792. .tx_buf = data,
  793. .tx_len = len
  794. };
  795. switch (len) {
  796. case 0:
  797. return -EINVAL;
  798. case 1:
  799. msg.type = MIPI_DSI_DCS_SHORT_WRITE;
  800. break;
  801. case 2:
  802. msg.type = MIPI_DSI_DCS_SHORT_WRITE_PARAM;
  803. break;
  804. default:
  805. msg.type = MIPI_DSI_DCS_LONG_WRITE;
  806. break;
  807. }
  808. return mipi_dsi_device_transfer(dsi, &msg);
  809. }
  810. EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer);
  811. /**
  812. * mipi_dsi_dcs_write_buffer_chatty - mipi_dsi_dcs_write_buffer() w/ an error log
  813. * @dsi: DSI peripheral device
  814. * @data: buffer containing data to be transmitted
  815. * @len: size of transmission buffer
  816. *
  817. * Like mipi_dsi_dcs_write_buffer() but includes a dev_err()
  818. * call for you and returns 0 upon success, not the number of bytes sent.
  819. *
  820. * Return: 0 on success or a negative error code on failure.
  821. */
  822. int mipi_dsi_dcs_write_buffer_chatty(struct mipi_dsi_device *dsi,
  823. const void *data, size_t len)
  824. {
  825. struct device *dev = &dsi->dev;
  826. ssize_t ret;
  827. ret = mipi_dsi_dcs_write_buffer(dsi, data, len);
  828. if (ret < 0) {
  829. dev_err(dev, "sending dcs data %*ph failed: %zd\n",
  830. (int)len, data, ret);
  831. return ret;
  832. }
  833. return 0;
  834. }
  835. EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer_chatty);
  836. /**
  837. * mipi_dsi_dcs_write_buffer_multi - mipi_dsi_dcs_write_buffer_chatty() w/ accum_err
  838. * @ctx: Context for multiple DSI transactions
  839. * @data: buffer containing data to be transmitted
  840. * @len: size of transmission buffer
  841. *
  842. * Like mipi_dsi_dcs_write_buffer_chatty() but deals with errors in a way that
  843. * makes it convenient to make several calls in a row.
  844. */
  845. void mipi_dsi_dcs_write_buffer_multi(struct mipi_dsi_multi_context *ctx,
  846. const void *data, size_t len)
  847. {
  848. struct mipi_dsi_device *dsi = ctx->dsi;
  849. struct device *dev = &dsi->dev;
  850. ssize_t ret;
  851. if (ctx->accum_err)
  852. return;
  853. ret = mipi_dsi_dcs_write_buffer(dsi, data, len);
  854. if (ret < 0) {
  855. ctx->accum_err = ret;
  856. dev_err(dev, "sending dcs data %*ph failed: %d\n",
  857. (int)len, data, ctx->accum_err);
  858. }
  859. }
  860. EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer_multi);
  861. /**
  862. * mipi_dsi_dual_dcs_write_buffer_multi - mipi_dsi_dcs_write_buffer_multi() for
  863. * two dsi channels, one after the other
  864. * @ctx: Context for multiple DSI transactions
  865. * @dsi1: First dsi channel to write buffer to
  866. * @dsi2: Second dsi channel to write buffer to
  867. * @data: Buffer containing data to be transmitted
  868. * @len: Size of transmission buffer
  869. *
  870. * A wrapper around mipi_dsi_dcs_write_buffer_multi() that allows the user to
  871. * conveniently write to two dsi channels, one after the other.
  872. */
  873. void mipi_dsi_dual_dcs_write_buffer_multi(struct mipi_dsi_multi_context *ctx,
  874. struct mipi_dsi_device *dsi1,
  875. struct mipi_dsi_device *dsi2,
  876. const void *data, size_t len)
  877. {
  878. ctx->dsi = dsi1;
  879. mipi_dsi_dcs_write_buffer_multi(ctx, data, len);
  880. ctx->dsi = dsi2;
  881. mipi_dsi_dcs_write_buffer_multi(ctx, data, len);
  882. }
  883. EXPORT_SYMBOL(mipi_dsi_dual_dcs_write_buffer_multi);
  884. /**
  885. * mipi_dsi_dcs_write() - send DCS write command
  886. * @dsi: DSI peripheral device
  887. * @cmd: DCS command
  888. * @data: buffer containing the command payload
  889. * @len: command payload length
  890. *
  891. * This function will automatically choose the right data type depending on
  892. * the command payload length.
  893. *
  894. * Return: The number of bytes successfully transmitted or a negative error
  895. * code on failure.
  896. */
  897. ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
  898. const void *data, size_t len)
  899. {
  900. ssize_t err;
  901. size_t size;
  902. u8 stack_tx[8];
  903. u8 *tx;
  904. size = 1 + len;
  905. if (len > ARRAY_SIZE(stack_tx) - 1) {
  906. tx = kmalloc(size, GFP_KERNEL);
  907. if (!tx)
  908. return -ENOMEM;
  909. } else {
  910. tx = stack_tx;
  911. }
  912. /* concatenate the DCS command byte and the payload */
  913. tx[0] = cmd;
  914. if (data)
  915. memcpy(&tx[1], data, len);
  916. err = mipi_dsi_dcs_write_buffer(dsi, tx, size);
  917. if (tx != stack_tx)
  918. kfree(tx);
  919. return err;
  920. }
  921. EXPORT_SYMBOL(mipi_dsi_dcs_write);
  922. /**
  923. * mipi_dsi_dcs_read() - send DCS read request command
  924. * @dsi: DSI peripheral device
  925. * @cmd: DCS command
  926. * @data: buffer in which to receive data
  927. * @len: size of receive buffer
  928. *
  929. * Return: The number of bytes read or a negative error code on failure.
  930. */
  931. ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
  932. size_t len)
  933. {
  934. struct mipi_dsi_msg msg = {
  935. .channel = dsi->channel,
  936. .type = MIPI_DSI_DCS_READ,
  937. .tx_buf = &cmd,
  938. .tx_len = 1,
  939. .rx_buf = data,
  940. .rx_len = len
  941. };
  942. return mipi_dsi_device_transfer(dsi, &msg);
  943. }
  944. EXPORT_SYMBOL(mipi_dsi_dcs_read);
  945. /**
  946. * mipi_dsi_dcs_read_multi() - mipi_dsi_dcs_read() w/ accum_err
  947. * @ctx: Context for multiple DSI transactions
  948. * @cmd: DCS command
  949. * @data: buffer in which to receive data
  950. * @len: size of receive buffer
  951. *
  952. * Like mipi_dsi_dcs_read() but deals with errors in a way that makes it
  953. * convenient to make several calls in a row.
  954. */
  955. void mipi_dsi_dcs_read_multi(struct mipi_dsi_multi_context *ctx, u8 cmd,
  956. void *data, size_t len)
  957. {
  958. struct mipi_dsi_device *dsi = ctx->dsi;
  959. struct device *dev = &dsi->dev;
  960. struct mipi_dsi_msg msg = {
  961. .channel = dsi->channel,
  962. .type = MIPI_DSI_DCS_READ,
  963. .tx_buf = &cmd,
  964. .tx_len = 1,
  965. .rx_buf = data,
  966. .rx_len = len
  967. };
  968. ssize_t ret;
  969. if (ctx->accum_err)
  970. return;
  971. ret = mipi_dsi_device_transfer(dsi, &msg);
  972. if (ret < 0) {
  973. ctx->accum_err = ret;
  974. dev_err(dev, "dcs read with command %#x failed: %d\n", cmd,
  975. ctx->accum_err);
  976. }
  977. }
  978. EXPORT_SYMBOL(mipi_dsi_dcs_read_multi);
  979. /**
  980. * mipi_dsi_dcs_nop() - send DCS nop packet
  981. * @dsi: DSI peripheral device
  982. *
  983. * This function is deprecated. Use mipi_dsi_dcs_nop_multi() instead.
  984. *
  985. * Return: 0 on success or a negative error code on failure.
  986. */
  987. int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi)
  988. {
  989. ssize_t err;
  990. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_NOP, NULL, 0);
  991. if (err < 0)
  992. return err;
  993. return 0;
  994. }
  995. EXPORT_SYMBOL(mipi_dsi_dcs_nop);
  996. /**
  997. * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module
  998. * @dsi: DSI peripheral device
  999. *
  1000. * This function is deprecated. Use mipi_dsi_dcs_soft_reset_multi() instead.
  1001. *
  1002. * Return: 0 on success or a negative error code on failure.
  1003. */
  1004. int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi)
  1005. {
  1006. ssize_t err;
  1007. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SOFT_RESET, NULL, 0);
  1008. if (err < 0)
  1009. return err;
  1010. return 0;
  1011. }
  1012. EXPORT_SYMBOL(mipi_dsi_dcs_soft_reset);
  1013. /**
  1014. * mipi_dsi_dcs_get_power_mode() - query the display module's current power
  1015. * mode
  1016. * @dsi: DSI peripheral device
  1017. * @mode: return location for the current power mode
  1018. *
  1019. * Return: 0 on success or a negative error code on failure.
  1020. */
  1021. int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode)
  1022. {
  1023. ssize_t err;
  1024. err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_POWER_MODE, mode,
  1025. sizeof(*mode));
  1026. if (err <= 0) {
  1027. if (err == 0)
  1028. err = -ENODATA;
  1029. return err;
  1030. }
  1031. return 0;
  1032. }
  1033. EXPORT_SYMBOL(mipi_dsi_dcs_get_power_mode);
  1034. /**
  1035. * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image
  1036. * data used by the interface
  1037. * @dsi: DSI peripheral device
  1038. * @format: return location for the pixel format
  1039. *
  1040. * Return: 0 on success or a negative error code on failure.
  1041. */
  1042. int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format)
  1043. {
  1044. ssize_t err;
  1045. err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_PIXEL_FORMAT, format,
  1046. sizeof(*format));
  1047. if (err <= 0) {
  1048. if (err == 0)
  1049. err = -ENODATA;
  1050. return err;
  1051. }
  1052. return 0;
  1053. }
  1054. EXPORT_SYMBOL(mipi_dsi_dcs_get_pixel_format);
  1055. /**
  1056. * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the
  1057. * display module except interface communication
  1058. * @dsi: DSI peripheral device
  1059. *
  1060. * This function is deprecated. Use mipi_dsi_dcs_enter_sleep_mode_multi() instead.
  1061. *
  1062. * Return: 0 on success or a negative error code on failure.
  1063. */
  1064. int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi)
  1065. {
  1066. ssize_t err;
  1067. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_ENTER_SLEEP_MODE, NULL, 0);
  1068. if (err < 0)
  1069. return err;
  1070. return 0;
  1071. }
  1072. EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode);
  1073. /**
  1074. * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
  1075. * module
  1076. * @dsi: DSI peripheral device
  1077. *
  1078. * This function is deprecated. Use mipi_dsi_dcs_exit_sleep_mode_multi() instead.
  1079. *
  1080. * Return: 0 on success or a negative error code on failure.
  1081. */
  1082. int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi)
  1083. {
  1084. ssize_t err;
  1085. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_EXIT_SLEEP_MODE, NULL, 0);
  1086. if (err < 0)
  1087. return err;
  1088. return 0;
  1089. }
  1090. EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode);
  1091. /**
  1092. * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
  1093. * display device
  1094. * @dsi: DSI peripheral device
  1095. *
  1096. * This function is deprecated. Use mipi_dsi_dcs_set_display_off_multi() instead.
  1097. *
  1098. * Return: 0 on success or a negative error code on failure.
  1099. */
  1100. int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi)
  1101. {
  1102. ssize_t err;
  1103. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0);
  1104. if (err < 0)
  1105. return err;
  1106. return 0;
  1107. }
  1108. EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off);
  1109. /**
  1110. * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
  1111. * display device
  1112. * @dsi: DSI peripheral device
  1113. *
  1114. * This function is deprecated. Use mipi_dsi_dcs_set_display_on_multi() instead.
  1115. *
  1116. * Return: 0 on success or a negative error code on failure
  1117. */
  1118. int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi)
  1119. {
  1120. ssize_t err;
  1121. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_ON, NULL, 0);
  1122. if (err < 0)
  1123. return err;
  1124. return 0;
  1125. }
  1126. EXPORT_SYMBOL(mipi_dsi_dcs_set_display_on);
  1127. /**
  1128. * mipi_dsi_dcs_set_column_address() - define the column extent of the frame
  1129. * memory accessed by the host processor
  1130. * @dsi: DSI peripheral device
  1131. * @start: first column of frame memory
  1132. * @end: last column of frame memory
  1133. *
  1134. * This function is deprecated. Use mipi_dsi_dcs_set_column_address_multi()
  1135. * instead.
  1136. *
  1137. * Return: 0 on success or a negative error code on failure.
  1138. */
  1139. int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
  1140. u16 end)
  1141. {
  1142. u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
  1143. ssize_t err;
  1144. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, payload,
  1145. sizeof(payload));
  1146. if (err < 0)
  1147. return err;
  1148. return 0;
  1149. }
  1150. EXPORT_SYMBOL(mipi_dsi_dcs_set_column_address);
  1151. /**
  1152. * mipi_dsi_dcs_set_page_address() - define the page extent of the frame
  1153. * memory accessed by the host processor
  1154. * @dsi: DSI peripheral device
  1155. * @start: first page of frame memory
  1156. * @end: last page of frame memory
  1157. *
  1158. * This function is deprecated. Use mipi_dsi_dcs_set_page_address_multi()
  1159. * instead.
  1160. *
  1161. * Return: 0 on success or a negative error code on failure.
  1162. */
  1163. int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
  1164. u16 end)
  1165. {
  1166. u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff };
  1167. ssize_t err;
  1168. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PAGE_ADDRESS, payload,
  1169. sizeof(payload));
  1170. if (err < 0)
  1171. return err;
  1172. return 0;
  1173. }
  1174. EXPORT_SYMBOL(mipi_dsi_dcs_set_page_address);
  1175. /**
  1176. * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect
  1177. * output signal on the TE signal line.
  1178. * @dsi: DSI peripheral device
  1179. * @mode: the Tearing Effect Output Line mode
  1180. *
  1181. * This function is deprecated. Use mipi_dsi_dcs_set_tear_on_multi() instead.
  1182. *
  1183. * Return: 0 on success or a negative error code on failure
  1184. */
  1185. int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
  1186. enum mipi_dsi_dcs_tear_mode mode)
  1187. {
  1188. u8 value = mode;
  1189. ssize_t err;
  1190. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_ON, &value,
  1191. sizeof(value));
  1192. if (err < 0)
  1193. return err;
  1194. return 0;
  1195. }
  1196. EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_on);
  1197. /**
  1198. * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image
  1199. * data used by the interface
  1200. * @dsi: DSI peripheral device
  1201. * @format: pixel format
  1202. *
  1203. * This function is deprecated. Use mipi_dsi_dcs_set_pixel_format_multi()
  1204. * instead.
  1205. *
  1206. * Return: 0 on success or a negative error code on failure.
  1207. */
  1208. int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format)
  1209. {
  1210. ssize_t err;
  1211. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PIXEL_FORMAT, &format,
  1212. sizeof(format));
  1213. if (err < 0)
  1214. return err;
  1215. return 0;
  1216. }
  1217. EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format);
  1218. /**
  1219. * mipi_dsi_dcs_set_tear_scanline() - set the scanline to use as trigger for
  1220. * the Tearing Effect output signal of the display module
  1221. * @dsi: DSI peripheral device
  1222. * @scanline: scanline to use as trigger
  1223. *
  1224. * This function is deprecated. Use mipi_dsi_dcs_set_tear_scanline_multi()
  1225. * instead.
  1226. *
  1227. * Return: 0 on success or a negative error code on failure
  1228. */
  1229. int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline)
  1230. {
  1231. u8 payload[2] = { scanline >> 8, scanline & 0xff };
  1232. ssize_t err;
  1233. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_SCANLINE, payload,
  1234. sizeof(payload));
  1235. if (err < 0)
  1236. return err;
  1237. return 0;
  1238. }
  1239. EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_scanline);
  1240. /**
  1241. * mipi_dsi_dcs_set_display_brightness() - sets the brightness value of the
  1242. * display
  1243. * @dsi: DSI peripheral device
  1244. * @brightness: brightness value
  1245. *
  1246. * This function is deprecated. Use mipi_dsi_dcs_set_display_brightness_multi()
  1247. * instead.
  1248. *
  1249. * Return: 0 on success or a negative error code on failure.
  1250. */
  1251. int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi,
  1252. u16 brightness)
  1253. {
  1254. u8 payload[2] = { brightness & 0xff, brightness >> 8 };
  1255. ssize_t err;
  1256. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
  1257. payload, sizeof(payload));
  1258. if (err < 0)
  1259. return err;
  1260. return 0;
  1261. }
  1262. EXPORT_SYMBOL(mipi_dsi_dcs_set_display_brightness);
  1263. /**
  1264. * mipi_dsi_dcs_get_display_brightness() - gets the current brightness value
  1265. * of the display
  1266. * @dsi: DSI peripheral device
  1267. * @brightness: brightness value
  1268. *
  1269. * Return: 0 on success or a negative error code on failure.
  1270. */
  1271. int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
  1272. u16 *brightness)
  1273. {
  1274. ssize_t err;
  1275. err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_DISPLAY_BRIGHTNESS,
  1276. brightness, sizeof(*brightness));
  1277. if (err <= 0) {
  1278. if (err == 0)
  1279. err = -ENODATA;
  1280. return err;
  1281. }
  1282. return 0;
  1283. }
  1284. EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness);
  1285. /**
  1286. * mipi_dsi_dcs_set_display_brightness_large() - sets the 16-bit brightness value
  1287. * of the display
  1288. * @dsi: DSI peripheral device
  1289. * @brightness: brightness value
  1290. *
  1291. * Return: 0 on success or a negative error code on failure.
  1292. */
  1293. int mipi_dsi_dcs_set_display_brightness_large(struct mipi_dsi_device *dsi,
  1294. u16 brightness)
  1295. {
  1296. u8 payload[2] = { brightness >> 8, brightness & 0xff };
  1297. ssize_t err;
  1298. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
  1299. payload, sizeof(payload));
  1300. if (err < 0)
  1301. return err;
  1302. return 0;
  1303. }
  1304. EXPORT_SYMBOL(mipi_dsi_dcs_set_display_brightness_large);
  1305. /**
  1306. * mipi_dsi_dcs_get_display_brightness_large() - gets the current 16-bit
  1307. * brightness value of the display
  1308. * @dsi: DSI peripheral device
  1309. * @brightness: brightness value
  1310. *
  1311. * Return: 0 on success or a negative error code on failure.
  1312. */
  1313. int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi,
  1314. u16 *brightness)
  1315. {
  1316. u8 brightness_be[2];
  1317. ssize_t err;
  1318. err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_DISPLAY_BRIGHTNESS,
  1319. brightness_be, sizeof(brightness_be));
  1320. if (err <= 0) {
  1321. if (err == 0)
  1322. err = -ENODATA;
  1323. return err;
  1324. }
  1325. *brightness = (brightness_be[0] << 8) | brightness_be[1];
  1326. return 0;
  1327. }
  1328. EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness_large);
  1329. /**
  1330. * mipi_dsi_picture_parameter_set_multi() - transmit the DSC PPS to the peripheral
  1331. * @ctx: Context for multiple DSI transactions
  1332. * @pps: VESA DSC 1.1 Picture Parameter Set
  1333. *
  1334. * Like mipi_dsi_picture_parameter_set() but deals with errors in a way that
  1335. * makes it convenient to make several calls in a row.
  1336. */
  1337. void mipi_dsi_picture_parameter_set_multi(struct mipi_dsi_multi_context *ctx,
  1338. const struct drm_dsc_picture_parameter_set *pps)
  1339. {
  1340. struct mipi_dsi_device *dsi = ctx->dsi;
  1341. struct device *dev = &dsi->dev;
  1342. ssize_t ret;
  1343. if (ctx->accum_err)
  1344. return;
  1345. ret = mipi_dsi_picture_parameter_set(dsi, pps);
  1346. if (ret < 0) {
  1347. ctx->accum_err = ret;
  1348. dev_err(dev, "sending PPS failed: %d\n",
  1349. ctx->accum_err);
  1350. }
  1351. }
  1352. EXPORT_SYMBOL(mipi_dsi_picture_parameter_set_multi);
  1353. /**
  1354. * mipi_dsi_compression_mode_ext_multi() - enable/disable DSC on the peripheral
  1355. * @ctx: Context for multiple DSI transactions
  1356. * @enable: Whether to enable or disable the DSC
  1357. * @algo: Selected compression algorithm
  1358. * @pps_selector: Select PPS from the table of pre-stored or uploaded PPS entries
  1359. *
  1360. * Like mipi_dsi_compression_mode_ext() but deals with errors in a way that
  1361. * makes it convenient to make several calls in a row.
  1362. */
  1363. void mipi_dsi_compression_mode_ext_multi(struct mipi_dsi_multi_context *ctx,
  1364. bool enable,
  1365. enum mipi_dsi_compression_algo algo,
  1366. unsigned int pps_selector)
  1367. {
  1368. struct mipi_dsi_device *dsi = ctx->dsi;
  1369. struct device *dev = &dsi->dev;
  1370. ssize_t ret;
  1371. if (ctx->accum_err)
  1372. return;
  1373. ret = mipi_dsi_compression_mode_ext(dsi, enable, algo, pps_selector);
  1374. if (ret < 0) {
  1375. ctx->accum_err = ret;
  1376. dev_err(dev, "sending COMPRESSION_MODE failed: %d\n",
  1377. ctx->accum_err);
  1378. }
  1379. }
  1380. EXPORT_SYMBOL(mipi_dsi_compression_mode_ext_multi);
  1381. /**
  1382. * mipi_dsi_compression_mode_multi() - enable/disable DSC on the peripheral
  1383. * @ctx: Context for multiple DSI transactions
  1384. * @enable: Whether to enable or disable the DSC
  1385. *
  1386. * Enable or disable Display Stream Compression on the peripheral using the
  1387. * default Picture Parameter Set and VESA DSC 1.1 algorithm.
  1388. */
  1389. void mipi_dsi_compression_mode_multi(struct mipi_dsi_multi_context *ctx,
  1390. bool enable)
  1391. {
  1392. return mipi_dsi_compression_mode_ext_multi(ctx, enable,
  1393. MIPI_DSI_COMPRESSION_DSC, 0);
  1394. }
  1395. EXPORT_SYMBOL(mipi_dsi_compression_mode_multi);
  1396. /**
  1397. * mipi_dsi_dcs_nop_multi() - send DCS NOP packet
  1398. * @ctx: Context for multiple DSI transactions
  1399. *
  1400. * Like mipi_dsi_dcs_nop() but deals with errors in a way that
  1401. * makes it convenient to make several calls in a row.
  1402. */
  1403. void mipi_dsi_dcs_nop_multi(struct mipi_dsi_multi_context *ctx)
  1404. {
  1405. struct mipi_dsi_device *dsi = ctx->dsi;
  1406. struct device *dev = &dsi->dev;
  1407. ssize_t ret;
  1408. if (ctx->accum_err)
  1409. return;
  1410. ret = mipi_dsi_dcs_nop(dsi);
  1411. if (ret < 0) {
  1412. ctx->accum_err = ret;
  1413. dev_err(dev, "sending DCS NOP failed: %d\n",
  1414. ctx->accum_err);
  1415. }
  1416. }
  1417. EXPORT_SYMBOL(mipi_dsi_dcs_nop_multi);
  1418. /**
  1419. * mipi_dsi_dcs_enter_sleep_mode_multi() - send DCS ENTER_SLEEP_MODE packet
  1420. * @ctx: Context for multiple DSI transactions
  1421. *
  1422. * Like mipi_dsi_dcs_enter_sleep_mode() but deals with errors in a way that
  1423. * makes it convenient to make several calls in a row.
  1424. */
  1425. void mipi_dsi_dcs_enter_sleep_mode_multi(struct mipi_dsi_multi_context *ctx)
  1426. {
  1427. struct mipi_dsi_device *dsi = ctx->dsi;
  1428. struct device *dev = &dsi->dev;
  1429. ssize_t ret;
  1430. if (ctx->accum_err)
  1431. return;
  1432. ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
  1433. if (ret < 0) {
  1434. ctx->accum_err = ret;
  1435. dev_err(dev, "sending DCS ENTER_SLEEP_MODE failed: %d\n",
  1436. ctx->accum_err);
  1437. }
  1438. }
  1439. EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode_multi);
  1440. /**
  1441. * mipi_dsi_dcs_exit_sleep_mode_multi() - send DCS EXIT_SLEEP_MODE packet
  1442. * @ctx: Context for multiple DSI transactions
  1443. *
  1444. * Like mipi_dsi_dcs_exit_sleep_mode() but deals with errors in a way that
  1445. * makes it convenient to make several calls in a row.
  1446. */
  1447. void mipi_dsi_dcs_exit_sleep_mode_multi(struct mipi_dsi_multi_context *ctx)
  1448. {
  1449. struct mipi_dsi_device *dsi = ctx->dsi;
  1450. struct device *dev = &dsi->dev;
  1451. ssize_t ret;
  1452. if (ctx->accum_err)
  1453. return;
  1454. ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
  1455. if (ret < 0) {
  1456. ctx->accum_err = ret;
  1457. dev_err(dev, "sending DCS EXIT_SLEEP_MODE failed: %d\n",
  1458. ctx->accum_err);
  1459. }
  1460. }
  1461. EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode_multi);
  1462. /**
  1463. * mipi_dsi_dcs_set_display_off_multi() - send DCS SET_DISPLAY_OFF packet
  1464. * @ctx: Context for multiple DSI transactions
  1465. *
  1466. * Like mipi_dsi_dcs_set_display_off() but deals with errors in a way that
  1467. * makes it convenient to make several calls in a row.
  1468. */
  1469. void mipi_dsi_dcs_set_display_off_multi(struct mipi_dsi_multi_context *ctx)
  1470. {
  1471. struct mipi_dsi_device *dsi = ctx->dsi;
  1472. struct device *dev = &dsi->dev;
  1473. ssize_t ret;
  1474. if (ctx->accum_err)
  1475. return;
  1476. ret = mipi_dsi_dcs_set_display_off(dsi);
  1477. if (ret < 0) {
  1478. ctx->accum_err = ret;
  1479. dev_err(dev, "sending DCS SET_DISPLAY_OFF failed: %d\n",
  1480. ctx->accum_err);
  1481. }
  1482. }
  1483. EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off_multi);
  1484. /**
  1485. * mipi_dsi_dcs_set_display_on_multi() - send DCS SET_DISPLAY_ON packet
  1486. * @ctx: Context for multiple DSI transactions
  1487. *
  1488. * Like mipi_dsi_dcs_set_display_on() but deals with errors in a way that
  1489. * makes it convenient to make several calls in a row.
  1490. */
  1491. void mipi_dsi_dcs_set_display_on_multi(struct mipi_dsi_multi_context *ctx)
  1492. {
  1493. struct mipi_dsi_device *dsi = ctx->dsi;
  1494. struct device *dev = &dsi->dev;
  1495. ssize_t ret;
  1496. if (ctx->accum_err)
  1497. return;
  1498. ret = mipi_dsi_dcs_set_display_on(dsi);
  1499. if (ret < 0) {
  1500. ctx->accum_err = ret;
  1501. dev_err(dev, "sending DCS SET_DISPLAY_ON failed: %d\n",
  1502. ctx->accum_err);
  1503. }
  1504. }
  1505. EXPORT_SYMBOL(mipi_dsi_dcs_set_display_on_multi);
  1506. /**
  1507. * mipi_dsi_dcs_set_tear_on_multi() - send DCS SET_TEAR_ON packet
  1508. * @ctx: Context for multiple DSI transactions
  1509. * @mode: the Tearing Effect Output Line mode
  1510. *
  1511. * Like mipi_dsi_dcs_set_tear_on() but deals with errors in a way that
  1512. * makes it convenient to make several calls in a row.
  1513. */
  1514. void mipi_dsi_dcs_set_tear_on_multi(struct mipi_dsi_multi_context *ctx,
  1515. enum mipi_dsi_dcs_tear_mode mode)
  1516. {
  1517. struct mipi_dsi_device *dsi = ctx->dsi;
  1518. struct device *dev = &dsi->dev;
  1519. ssize_t ret;
  1520. if (ctx->accum_err)
  1521. return;
  1522. ret = mipi_dsi_dcs_set_tear_on(dsi, mode);
  1523. if (ret < 0) {
  1524. ctx->accum_err = ret;
  1525. dev_err(dev, "sending DCS SET_TEAR_ON failed: %d\n",
  1526. ctx->accum_err);
  1527. }
  1528. }
  1529. EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_on_multi);
  1530. /**
  1531. * mipi_dsi_turn_on_peripheral_multi() - sends a Turn On Peripheral command
  1532. * @ctx: Context for multiple DSI transactions
  1533. *
  1534. * Like mipi_dsi_turn_on_peripheral() but deals with errors in a way that
  1535. * makes it convenient to make several calls in a row.
  1536. */
  1537. void mipi_dsi_turn_on_peripheral_multi(struct mipi_dsi_multi_context *ctx)
  1538. {
  1539. struct mipi_dsi_device *dsi = ctx->dsi;
  1540. struct device *dev = &dsi->dev;
  1541. int ret;
  1542. if (ctx->accum_err)
  1543. return;
  1544. ret = mipi_dsi_turn_on_peripheral(dsi);
  1545. if (ret < 0) {
  1546. ctx->accum_err = ret;
  1547. dev_err(dev, "Failed to turn on peripheral: %d\n",
  1548. ctx->accum_err);
  1549. }
  1550. }
  1551. EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral_multi);
  1552. /**
  1553. * mipi_dsi_dcs_set_tear_off_multi() - turn off the display module's Tearing Effect
  1554. * output signal on the TE signal line
  1555. * @ctx: Context for multiple DSI transactions
  1556. */
  1557. void mipi_dsi_dcs_set_tear_off_multi(struct mipi_dsi_multi_context *ctx)
  1558. {
  1559. struct mipi_dsi_device *dsi = ctx->dsi;
  1560. struct device *dev = &dsi->dev;
  1561. ssize_t err;
  1562. if (ctx->accum_err)
  1563. return;
  1564. err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_OFF, NULL, 0);
  1565. if (err < 0) {
  1566. ctx->accum_err = err;
  1567. dev_err(dev, "Failed to set tear off: %d\n",
  1568. ctx->accum_err);
  1569. }
  1570. }
  1571. EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_off_multi);
  1572. /**
  1573. * mipi_dsi_dcs_soft_reset_multi() - perform a software reset of the display module
  1574. * @ctx: Context for multiple DSI transactions
  1575. *
  1576. * Like mipi_dsi_dcs_soft_reset() but deals with errors in a way that
  1577. * makes it convenient to make several calls in a row.
  1578. */
  1579. void mipi_dsi_dcs_soft_reset_multi(struct mipi_dsi_multi_context *ctx)
  1580. {
  1581. struct mipi_dsi_device *dsi = ctx->dsi;
  1582. struct device *dev = &dsi->dev;
  1583. int ret;
  1584. if (ctx->accum_err)
  1585. return;
  1586. ret = mipi_dsi_dcs_soft_reset(dsi);
  1587. if (ret < 0) {
  1588. ctx->accum_err = ret;
  1589. dev_err(dev, "Failed to mipi_dsi_dcs_soft_reset: %d\n",
  1590. ctx->accum_err);
  1591. }
  1592. }
  1593. EXPORT_SYMBOL(mipi_dsi_dcs_soft_reset_multi);
  1594. /**
  1595. * mipi_dsi_dcs_set_display_brightness_multi() - sets the brightness value of
  1596. * the display
  1597. * @ctx: Context for multiple DSI transactions
  1598. * @brightness: brightness value
  1599. *
  1600. * Like mipi_dsi_dcs_set_display_brightness() but deals with errors in a way that
  1601. * makes it convenient to make several calls in a row.
  1602. */
  1603. void mipi_dsi_dcs_set_display_brightness_multi(struct mipi_dsi_multi_context *ctx,
  1604. u16 brightness)
  1605. {
  1606. struct mipi_dsi_device *dsi = ctx->dsi;
  1607. struct device *dev = &dsi->dev;
  1608. int ret;
  1609. if (ctx->accum_err)
  1610. return;
  1611. ret = mipi_dsi_dcs_set_display_brightness(dsi, brightness);
  1612. if (ret < 0) {
  1613. ctx->accum_err = ret;
  1614. dev_err(dev, "Failed to write display brightness: %d\n",
  1615. ctx->accum_err);
  1616. }
  1617. }
  1618. EXPORT_SYMBOL(mipi_dsi_dcs_set_display_brightness_multi);
  1619. /**
  1620. * mipi_dsi_dcs_set_pixel_format_multi() - sets the pixel format for the RGB image
  1621. * data used by the interface
  1622. * @ctx: Context for multiple DSI transactions
  1623. * @format: pixel format
  1624. *
  1625. * Like mipi_dsi_dcs_set_pixel_format() but deals with errors in a way that
  1626. * makes it convenient to make several calls in a row.
  1627. */
  1628. void mipi_dsi_dcs_set_pixel_format_multi(struct mipi_dsi_multi_context *ctx,
  1629. u8 format)
  1630. {
  1631. struct mipi_dsi_device *dsi = ctx->dsi;
  1632. struct device *dev = &dsi->dev;
  1633. int ret;
  1634. if (ctx->accum_err)
  1635. return;
  1636. ret = mipi_dsi_dcs_set_pixel_format(dsi, format);
  1637. if (ret < 0) {
  1638. ctx->accum_err = ret;
  1639. dev_err(dev, "Failed to set pixel format: %d\n",
  1640. ctx->accum_err);
  1641. }
  1642. }
  1643. EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format_multi);
  1644. /**
  1645. * mipi_dsi_dcs_set_column_address_multi() - define the column extent of the
  1646. * frame memory accessed by the host processor
  1647. * @ctx: Context for multiple DSI transactions
  1648. * @start: first column of frame memory
  1649. * @end: last column of frame memory
  1650. *
  1651. * Like mipi_dsi_dcs_set_column_address() but deals with errors in a way that
  1652. * makes it convenient to make several calls in a row.
  1653. */
  1654. void mipi_dsi_dcs_set_column_address_multi(struct mipi_dsi_multi_context *ctx,
  1655. u16 start, u16 end)
  1656. {
  1657. struct mipi_dsi_device *dsi = ctx->dsi;
  1658. struct device *dev = &dsi->dev;
  1659. int ret;
  1660. if (ctx->accum_err)
  1661. return;
  1662. ret = mipi_dsi_dcs_set_column_address(dsi, start, end);
  1663. if (ret < 0) {
  1664. ctx->accum_err = ret;
  1665. dev_err(dev, "Failed to set column address: %d\n",
  1666. ctx->accum_err);
  1667. }
  1668. }
  1669. EXPORT_SYMBOL(mipi_dsi_dcs_set_column_address_multi);
  1670. /**
  1671. * mipi_dsi_dcs_set_page_address_multi() - define the page extent of the
  1672. * frame memory accessed by the host processor
  1673. * @ctx: Context for multiple DSI transactions
  1674. * @start: first page of frame memory
  1675. * @end: last page of frame memory
  1676. *
  1677. * Like mipi_dsi_dcs_set_page_address() but deals with errors in a way that
  1678. * makes it convenient to make several calls in a row.
  1679. */
  1680. void mipi_dsi_dcs_set_page_address_multi(struct mipi_dsi_multi_context *ctx,
  1681. u16 start, u16 end)
  1682. {
  1683. struct mipi_dsi_device *dsi = ctx->dsi;
  1684. struct device *dev = &dsi->dev;
  1685. int ret;
  1686. if (ctx->accum_err)
  1687. return;
  1688. ret = mipi_dsi_dcs_set_page_address(dsi, start, end);
  1689. if (ret < 0) {
  1690. ctx->accum_err = ret;
  1691. dev_err(dev, "Failed to set page address: %d\n",
  1692. ctx->accum_err);
  1693. }
  1694. }
  1695. EXPORT_SYMBOL(mipi_dsi_dcs_set_page_address_multi);
  1696. /**
  1697. * mipi_dsi_dcs_set_tear_scanline_multi() - set the scanline to use as trigger for
  1698. * the Tearing Effect output signal of the display module
  1699. * @ctx: Context for multiple DSI transactions
  1700. * @scanline: scanline to use as trigger
  1701. *
  1702. * Like mipi_dsi_dcs_set_tear_scanline() but deals with errors in a way that
  1703. * makes it convenient to make several calls in a row.
  1704. */
  1705. void mipi_dsi_dcs_set_tear_scanline_multi(struct mipi_dsi_multi_context *ctx,
  1706. u16 scanline)
  1707. {
  1708. struct mipi_dsi_device *dsi = ctx->dsi;
  1709. struct device *dev = &dsi->dev;
  1710. int ret;
  1711. if (ctx->accum_err)
  1712. return;
  1713. ret = mipi_dsi_dcs_set_tear_scanline(dsi, scanline);
  1714. if (ret < 0) {
  1715. ctx->accum_err = ret;
  1716. dev_err(dev, "Failed to set tear scanline: %d\n",
  1717. ctx->accum_err);
  1718. }
  1719. }
  1720. EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_scanline_multi);
  1721. static int mipi_dsi_drv_probe(struct device *dev)
  1722. {
  1723. struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
  1724. struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
  1725. return drv->probe(dsi);
  1726. }
  1727. static int mipi_dsi_drv_remove(struct device *dev)
  1728. {
  1729. struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
  1730. struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
  1731. drv->remove(dsi);
  1732. return 0;
  1733. }
  1734. static void mipi_dsi_drv_shutdown(struct device *dev)
  1735. {
  1736. struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
  1737. struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
  1738. drv->shutdown(dsi);
  1739. }
  1740. /**
  1741. * mipi_dsi_driver_register_full() - register a driver for DSI devices
  1742. * @drv: DSI driver structure
  1743. * @owner: owner module
  1744. *
  1745. * Return: 0 on success or a negative error code on failure.
  1746. */
  1747. int mipi_dsi_driver_register_full(struct mipi_dsi_driver *drv,
  1748. struct module *owner)
  1749. {
  1750. drv->driver.bus = &mipi_dsi_bus_type;
  1751. drv->driver.owner = owner;
  1752. if (drv->probe)
  1753. drv->driver.probe = mipi_dsi_drv_probe;
  1754. if (drv->remove)
  1755. drv->driver.remove = mipi_dsi_drv_remove;
  1756. if (drv->shutdown)
  1757. drv->driver.shutdown = mipi_dsi_drv_shutdown;
  1758. return driver_register(&drv->driver);
  1759. }
  1760. EXPORT_SYMBOL(mipi_dsi_driver_register_full);
  1761. /**
  1762. * mipi_dsi_driver_unregister() - unregister a driver for DSI devices
  1763. * @drv: DSI driver structure
  1764. *
  1765. * Return: 0 on success or a negative error code on failure.
  1766. */
  1767. void mipi_dsi_driver_unregister(struct mipi_dsi_driver *drv)
  1768. {
  1769. driver_unregister(&drv->driver);
  1770. }
  1771. EXPORT_SYMBOL(mipi_dsi_driver_unregister);
  1772. static int __init mipi_dsi_bus_init(void)
  1773. {
  1774. return bus_register(&mipi_dsi_bus_type);
  1775. }
  1776. postcore_initcall(mipi_dsi_bus_init);
  1777. MODULE_AUTHOR("Andrzej Hajda <a.hajda@samsung.com>");
  1778. MODULE_DESCRIPTION("MIPI DSI Bus");
  1779. MODULE_LICENSE("GPL and additional rights");