panel-khadas-ts050.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2020 BayLibre, SAS
  4. * Author: Neil Armstrong <narmstrong@baylibre.com>
  5. */
  6. #include <linux/delay.h>
  7. #include <linux/gpio/consumer.h>
  8. #include <linux/module.h>
  9. #include <linux/of.h>
  10. #include <linux/regulator/consumer.h>
  11. #include <video/mipi_display.h>
  12. #include <drm/drm_crtc.h>
  13. #include <drm/drm_device.h>
  14. #include <drm/drm_mipi_dsi.h>
  15. #include <drm/drm_modes.h>
  16. #include <drm/drm_panel.h>
  17. struct khadas_ts050_panel {
  18. struct drm_panel base;
  19. struct mipi_dsi_device *link;
  20. struct regulator *supply;
  21. struct gpio_desc *reset_gpio;
  22. struct gpio_desc *enable_gpio;
  23. struct khadas_ts050_panel_data *panel_data;
  24. };
  25. struct khadas_ts050_panel_cmd {
  26. u8 cmd;
  27. u8 data[55];
  28. u8 size;
  29. };
  30. struct khadas_ts050_panel_data {
  31. struct khadas_ts050_panel_cmd *init_code;
  32. int len;
  33. };
  34. static const struct khadas_ts050_panel_cmd ts050v2_init_code[] = {
  35. {0xB9, {0xFF, 0x83, 0x99}, 0x03},
  36. {0xBA, {0x63, 0x23, 0x68, 0xCF}, 0x04},
  37. {0xD2, {0x55}, 0x01},
  38. {0xB1, {0x02, 0x04, 0x70, 0x90, 0x01, 0x32, 0x33,
  39. 0x11, 0x11, 0x4D, 0x57, 0x56, 0x73, 0x02, 0x02}, 0x0f},
  40. {0xB2, {0x00, 0x80, 0x80, 0xAE, 0x0A, 0x0E, 0x75, 0x11, 0x00, 0x00, 0x00}, 0x0b},
  41. {0xB4, {0x00, 0xFF, 0x04, 0xA4, 0x02, 0xA0, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02,
  42. 0x00, 0x24, 0x02, 0x04, 0x0A, 0x21, 0x03, 0x00, 0x00, 0x08, 0xA6, 0x88,
  43. 0x04, 0xA4, 0x02, 0xA0, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 0x24,
  44. 0x02, 0x04, 0x0A, 0x00, 0x00, 0x08, 0xA6, 0x00, 0x08, 0x11}, 0x2e},
  45. {0xD3, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
  46. 0x18, 0x32, 0x10, 0x09, 0x00, 0x09, 0x32,
  47. 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  48. 0x00, 0x00, 0x11, 0x00, 0x02, 0x02, 0x03, 0x00, 0x00, 0x00, 0x0A,
  49. 0x40}, 0x21},
  50. {0xD5, {0x18, 0x18, 0x18, 0x18, 0x21, 0x20, 0x18, 0x18, 0x19, 0x19, 0x19,
  51. 0x19, 0x18, 0x18, 0x18, 0x18, 0x03, 0x02, 0x01, 0x00, 0x2F, 0x2F,
  52. 0x30, 0x30, 0x31, 0x31, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18}, 0x20},
  53. {0xD6, {0x18, 0x18, 0x18, 0x18, 0x20, 0x21, 0x19, 0x19, 0x18, 0x18, 0x19,
  54. 0x19, 0x18, 0x18, 0x18, 0x18, 0x00, 0x01, 0x02, 0x03, 0x2F, 0x2F,
  55. 0x30, 0x30, 0x31, 0x31, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18}, 0x20},
  56. {0xD8, {0x0A, 0xBE, 0xFA, 0xA0, 0x0A, 0xBE, 0xFA, 0xA0}, 0x08},
  57. {0xBD, {0x01}, 0x01},
  58. {0xD8, {0x0F, 0xFF, 0xFF, 0xE0, 0x0F, 0xFF, 0xFF, 0xE0}, 0x08},
  59. {0xBD, {0x02}, 0x01},
  60. {0xD8, {0x0F, 0xFF, 0xFF, 0xE0, 0x0F, 0xFF, 0xFF, 0xE0}, 0x08},
  61. {0xBD, {0x00}, 0x01},
  62. {0xE0, {0x01, 0x35, 0x41, 0x3B, 0x79, 0x81, 0x8C, 0x85, 0x8E,
  63. 0x95, 0x9B, 0xA0, 0xA4, 0xAB, 0xB1, 0xB3, 0xB7, 0xC5, 0xBD, 0xC5,
  64. 0xB6, 0xC2, 0xC2, 0x62, 0x5D, 0x66, 0x73, 0x01, 0x35, 0x41, 0x3B,
  65. 0x79, 0x81, 0x8C, 0x85, 0x8E, 0x95, 0x9B, 0xA0, 0xA4, 0xAB, 0xB1,
  66. 0xB3, 0xB7, 0xB5, 0xBD, 0xC5, 0xB6, 0xC2, 0xC2, 0x62, 0x5D, 0x66,
  67. 0x73}, 0x36},
  68. {0xB6, {0x97, 0x97}, 0x02},
  69. {0xCC, {0xC8}, 0x02},
  70. {0xBF, {0x40, 0x41, 0x50, 0x19}, 0x04},
  71. {0xC6, {0xFF, 0xF9}, 0x02},
  72. {0xC0, {0x25, 0x5A}, 0x02},
  73. };
  74. /* Only the CMD1 User Command set is documented */
  75. static const struct khadas_ts050_panel_cmd ts050_init_code[] = {
  76. /* Select Unknown CMD Page (Undocumented) */
  77. {0xff, {0xee}, 0x01},
  78. /* Reload CMD1: Don't reload default value to register */
  79. {0xfb, {0x01}, 0x01},
  80. {0x1f, {0x45}, 0x01},
  81. {0x24, {0x4f}, 0x01},
  82. {0x38, {0xc8}, 0x01},
  83. {0x39, {0x27}, 0x01},
  84. {0x1e, {0x77}, 0x01},
  85. {0x1d, {0x0f}, 0x01},
  86. {0x7e, {0x71}, 0x01},
  87. {0x7c, {0x03}, 0x01},
  88. {0xff, {0x00}, 0x01},
  89. {0xfb, {0x01}, 0x01},
  90. {0x35, {0x01}, 0x01},
  91. /* Select CMD2 Page0 (Undocumented) */
  92. {0xff, {0x01}, 0x01},
  93. /* Reload CMD1: Don't reload default value to register */
  94. {0xfb, {0x01}, 0x01},
  95. {0x00, {0x01}, 0x01},
  96. {0x01, {0x55}, 0x01},
  97. {0x02, {0x40}, 0x01},
  98. {0x05, {0x40}, 0x01},
  99. {0x06, {0x4a}, 0x01},
  100. {0x07, {0x24}, 0x01},
  101. {0x08, {0x0c}, 0x01},
  102. {0x0b, {0x7d}, 0x01},
  103. {0x0c, {0x7d}, 0x01},
  104. {0x0e, {0xb0}, 0x01},
  105. {0x0f, {0xae}, 0x01},
  106. {0x11, {0x10}, 0x01},
  107. {0x12, {0x10}, 0x01},
  108. {0x13, {0x03}, 0x01},
  109. {0x14, {0x4a}, 0x01},
  110. {0x15, {0x12}, 0x01},
  111. {0x16, {0x12}, 0x01},
  112. {0x18, {0x00}, 0x01},
  113. {0x19, {0x77}, 0x01},
  114. {0x1a, {0x55}, 0x01},
  115. {0x1b, {0x13}, 0x01},
  116. {0x1c, {0x00}, 0x01},
  117. {0x1d, {0x00}, 0x01},
  118. {0x1e, {0x13}, 0x01},
  119. {0x1f, {0x00}, 0x01},
  120. {0x23, {0x00}, 0x01},
  121. {0x24, {0x00}, 0x01},
  122. {0x25, {0x00}, 0x01},
  123. {0x26, {0x00}, 0x01},
  124. {0x27, {0x00}, 0x01},
  125. {0x28, {0x00}, 0x01},
  126. {0x35, {0x00}, 0x01},
  127. {0x66, {0x00}, 0x01},
  128. {0x58, {0x82}, 0x01},
  129. {0x59, {0x02}, 0x01},
  130. {0x5a, {0x02}, 0x01},
  131. {0x5b, {0x02}, 0x01},
  132. {0x5c, {0x82}, 0x01},
  133. {0x5d, {0x82}, 0x01},
  134. {0x5e, {0x02}, 0x01},
  135. {0x5f, {0x02}, 0x01},
  136. {0x72, {0x31}, 0x01},
  137. /* Select CMD2 Page4 (Undocumented) */
  138. {0xff, {0x05}, 0x01},
  139. /* Reload CMD1: Don't reload default value to register */
  140. {0xfb, {0x01}, 0x01},
  141. {0x00, {0x01}, 0x01},
  142. {0x01, {0x0b}, 0x01},
  143. {0x02, {0x0c}, 0x01},
  144. {0x03, {0x09}, 0x01},
  145. {0x04, {0x0a}, 0x01},
  146. {0x05, {0x00}, 0x01},
  147. {0x06, {0x0f}, 0x01},
  148. {0x07, {0x10}, 0x01},
  149. {0x08, {0x00}, 0x01},
  150. {0x09, {0x00}, 0x01},
  151. {0x0a, {0x00}, 0x01},
  152. {0x0b, {0x00}, 0x01},
  153. {0x0c, {0x00}, 0x01},
  154. {0x0d, {0x13}, 0x01},
  155. {0x0e, {0x15}, 0x01},
  156. {0x0f, {0x17}, 0x01},
  157. {0x10, {0x01}, 0x01},
  158. {0x11, {0x0b}, 0x01},
  159. {0x12, {0x0c}, 0x01},
  160. {0x13, {0x09}, 0x01},
  161. {0x14, {0x0a}, 0x01},
  162. {0x15, {0x00}, 0x01},
  163. {0x16, {0x0f}, 0x01},
  164. {0x17, {0x10}, 0x01},
  165. {0x18, {0x00}, 0x01},
  166. {0x19, {0x00}, 0x01},
  167. {0x1a, {0x00}, 0x01},
  168. {0x1b, {0x00}, 0x01},
  169. {0x1c, {0x00}, 0x01},
  170. {0x1d, {0x13}, 0x01},
  171. {0x1e, {0x15}, 0x01},
  172. {0x1f, {0x17}, 0x01},
  173. {0x20, {0x00}, 0x01},
  174. {0x21, {0x03}, 0x01},
  175. {0x22, {0x01}, 0x01},
  176. {0x23, {0x40}, 0x01},
  177. {0x24, {0x40}, 0x01},
  178. {0x25, {0xed}, 0x01},
  179. {0x29, {0x58}, 0x01},
  180. {0x2a, {0x12}, 0x01},
  181. {0x2b, {0x01}, 0x01},
  182. {0x4b, {0x06}, 0x01},
  183. {0x4c, {0x11}, 0x01},
  184. {0x4d, {0x20}, 0x01},
  185. {0x4e, {0x02}, 0x01},
  186. {0x4f, {0x02}, 0x01},
  187. {0x50, {0x20}, 0x01},
  188. {0x51, {0x61}, 0x01},
  189. {0x52, {0x01}, 0x01},
  190. {0x53, {0x63}, 0x01},
  191. {0x54, {0x77}, 0x01},
  192. {0x55, {0xed}, 0x01},
  193. {0x5b, {0x00}, 0x01},
  194. {0x5c, {0x00}, 0x01},
  195. {0x5d, {0x00}, 0x01},
  196. {0x5e, {0x00}, 0x01},
  197. {0x5f, {0x15}, 0x01},
  198. {0x60, {0x75}, 0x01},
  199. {0x61, {0x00}, 0x01},
  200. {0x62, {0x00}, 0x01},
  201. {0x63, {0x00}, 0x01},
  202. {0x64, {0x00}, 0x01},
  203. {0x65, {0x00}, 0x01},
  204. {0x66, {0x00}, 0x01},
  205. {0x67, {0x00}, 0x01},
  206. {0x68, {0x04}, 0x01},
  207. {0x69, {0x00}, 0x01},
  208. {0x6a, {0x00}, 0x01},
  209. {0x6c, {0x40}, 0x01},
  210. {0x75, {0x01}, 0x01},
  211. {0x76, {0x01}, 0x01},
  212. {0x7a, {0x80}, 0x01},
  213. {0x7b, {0xa3}, 0x01},
  214. {0x7c, {0xd8}, 0x01},
  215. {0x7d, {0x60}, 0x01},
  216. {0x7f, {0x15}, 0x01},
  217. {0x80, {0x81}, 0x01},
  218. {0x83, {0x05}, 0x01},
  219. {0x93, {0x08}, 0x01},
  220. {0x94, {0x10}, 0x01},
  221. {0x8a, {0x00}, 0x01},
  222. {0x9b, {0x0f}, 0x01},
  223. {0xea, {0xff}, 0x01},
  224. {0xec, {0x00}, 0x01},
  225. /* Select CMD2 Page0 (Undocumented) */
  226. {0xff, {0x01}, 0x01},
  227. /* Reload CMD1: Don't reload default value to register */
  228. {0xfb, {0x01}, 0x01},
  229. {0x75, {0x00}, 0x01},
  230. {0x76, {0xdf}, 0x01},
  231. {0x77, {0x00}, 0x01},
  232. {0x78, {0xe4}, 0x01},
  233. {0x79, {0x00}, 0x01},
  234. {0x7a, {0xed}, 0x01},
  235. {0x7b, {0x00}, 0x01},
  236. {0x7c, {0xf6}, 0x01},
  237. {0x7d, {0x00}, 0x01},
  238. {0x7e, {0xff}, 0x01},
  239. {0x7f, {0x01}, 0x01},
  240. {0x80, {0x07}, 0x01},
  241. {0x81, {0x01}, 0x01},
  242. {0x82, {0x10}, 0x01},
  243. {0x83, {0x01}, 0x01},
  244. {0x84, {0x18}, 0x01},
  245. {0x85, {0x01}, 0x01},
  246. {0x86, {0x20}, 0x01},
  247. {0x87, {0x01}, 0x01},
  248. {0x88, {0x3d}, 0x01},
  249. {0x89, {0x01}, 0x01},
  250. {0x8a, {0x56}, 0x01},
  251. {0x8b, {0x01}, 0x01},
  252. {0x8c, {0x84}, 0x01},
  253. {0x8d, {0x01}, 0x01},
  254. {0x8e, {0xab}, 0x01},
  255. {0x8f, {0x01}, 0x01},
  256. {0x90, {0xec}, 0x01},
  257. {0x91, {0x02}, 0x01},
  258. {0x92, {0x22}, 0x01},
  259. {0x93, {0x02}, 0x01},
  260. {0x94, {0x23}, 0x01},
  261. {0x95, {0x02}, 0x01},
  262. {0x96, {0x55}, 0x01},
  263. {0x97, {0x02}, 0x01},
  264. {0x98, {0x8b}, 0x01},
  265. {0x99, {0x02}, 0x01},
  266. {0x9a, {0xaf}, 0x01},
  267. {0x9b, {0x02}, 0x01},
  268. {0x9c, {0xdf}, 0x01},
  269. {0x9d, {0x03}, 0x01},
  270. {0x9e, {0x01}, 0x01},
  271. {0x9f, {0x03}, 0x01},
  272. {0xa0, {0x2c}, 0x01},
  273. {0xa2, {0x03}, 0x01},
  274. {0xa3, {0x39}, 0x01},
  275. {0xa4, {0x03}, 0x01},
  276. {0xa5, {0x47}, 0x01},
  277. {0xa6, {0x03}, 0x01},
  278. {0xa7, {0x56}, 0x01},
  279. {0xa9, {0x03}, 0x01},
  280. {0xaa, {0x66}, 0x01},
  281. {0xab, {0x03}, 0x01},
  282. {0xac, {0x76}, 0x01},
  283. {0xad, {0x03}, 0x01},
  284. {0xae, {0x85}, 0x01},
  285. {0xaf, {0x03}, 0x01},
  286. {0xb0, {0x90}, 0x01},
  287. {0xb1, {0x03}, 0x01},
  288. {0xb2, {0xcb}, 0x01},
  289. {0xb3, {0x00}, 0x01},
  290. {0xb4, {0xdf}, 0x01},
  291. {0xb5, {0x00}, 0x01},
  292. {0xb6, {0xe4}, 0x01},
  293. {0xb7, {0x00}, 0x01},
  294. {0xb8, {0xed}, 0x01},
  295. {0xb9, {0x00}, 0x01},
  296. {0xba, {0xf6}, 0x01},
  297. {0xbb, {0x00}, 0x01},
  298. {0xbc, {0xff}, 0x01},
  299. {0xbd, {0x01}, 0x01},
  300. {0xbe, {0x07}, 0x01},
  301. {0xbf, {0x01}, 0x01},
  302. {0xc0, {0x10}, 0x01},
  303. {0xc1, {0x01}, 0x01},
  304. {0xc2, {0x18}, 0x01},
  305. {0xc3, {0x01}, 0x01},
  306. {0xc4, {0x20}, 0x01},
  307. {0xc5, {0x01}, 0x01},
  308. {0xc6, {0x3d}, 0x01},
  309. {0xc7, {0x01}, 0x01},
  310. {0xc8, {0x56}, 0x01},
  311. {0xc9, {0x01}, 0x01},
  312. {0xca, {0x84}, 0x01},
  313. {0xcb, {0x01}, 0x01},
  314. {0xcc, {0xab}, 0x01},
  315. {0xcd, {0x01}, 0x01},
  316. {0xce, {0xec}, 0x01},
  317. {0xcf, {0x02}, 0x01},
  318. {0xd0, {0x22}, 0x01},
  319. {0xd1, {0x02}, 0x01},
  320. {0xd2, {0x23}, 0x01},
  321. {0xd3, {0x02}, 0x01},
  322. {0xd4, {0x55}, 0x01},
  323. {0xd5, {0x02}, 0x01},
  324. {0xd6, {0x8b}, 0x01},
  325. {0xd7, {0x02}, 0x01},
  326. {0xd8, {0xaf}, 0x01},
  327. {0xd9, {0x02}, 0x01},
  328. {0xda, {0xdf}, 0x01},
  329. {0xdb, {0x03}, 0x01},
  330. {0xdc, {0x01}, 0x01},
  331. {0xdd, {0x03}, 0x01},
  332. {0xde, {0x2c}, 0x01},
  333. {0xdf, {0x03}, 0x01},
  334. {0xe0, {0x39}, 0x01},
  335. {0xe1, {0x03}, 0x01},
  336. {0xe2, {0x47}, 0x01},
  337. {0xe3, {0x03}, 0x01},
  338. {0xe4, {0x56}, 0x01},
  339. {0xe5, {0x03}, 0x01},
  340. {0xe6, {0x66}, 0x01},
  341. {0xe7, {0x03}, 0x01},
  342. {0xe8, {0x76}, 0x01},
  343. {0xe9, {0x03}, 0x01},
  344. {0xea, {0x85}, 0x01},
  345. {0xeb, {0x03}, 0x01},
  346. {0xec, {0x90}, 0x01},
  347. {0xed, {0x03}, 0x01},
  348. {0xee, {0xcb}, 0x01},
  349. {0xef, {0x00}, 0x01},
  350. {0xf0, {0xbb}, 0x01},
  351. {0xf1, {0x00}, 0x01},
  352. {0xf2, {0xc0}, 0x01},
  353. {0xf3, {0x00}, 0x01},
  354. {0xf4, {0xcc}, 0x01},
  355. {0xf5, {0x00}, 0x01},
  356. {0xf6, {0xd6}, 0x01},
  357. {0xf7, {0x00}, 0x01},
  358. {0xf8, {0xe1}, 0x01},
  359. {0xf9, {0x00}, 0x01},
  360. {0xfa, {0xea}, 0x01},
  361. /* Select CMD2 Page2 (Undocumented) */
  362. {0xff, {0x02}, 0x01},
  363. /* Reload CMD1: Don't reload default value to register */
  364. {0xfb, {0x01}, 0x01},
  365. {0x00, {0x00}, 0x01},
  366. {0x01, {0xf4}, 0x01},
  367. {0x02, {0x00}, 0x01},
  368. {0x03, {0xef}, 0x01},
  369. {0x04, {0x01}, 0x01},
  370. {0x05, {0x07}, 0x01},
  371. {0x06, {0x01}, 0x01},
  372. {0x07, {0x28}, 0x01},
  373. {0x08, {0x01}, 0x01},
  374. {0x09, {0x44}, 0x01},
  375. {0x0a, {0x01}, 0x01},
  376. {0x0b, {0x76}, 0x01},
  377. {0x0c, {0x01}, 0x01},
  378. {0x0d, {0xa0}, 0x01},
  379. {0x0e, {0x01}, 0x01},
  380. {0x0f, {0xe7}, 0x01},
  381. {0x10, {0x02}, 0x01},
  382. {0x11, {0x1f}, 0x01},
  383. {0x12, {0x02}, 0x01},
  384. {0x13, {0x22}, 0x01},
  385. {0x14, {0x02}, 0x01},
  386. {0x15, {0x54}, 0x01},
  387. {0x16, {0x02}, 0x01},
  388. {0x17, {0x8b}, 0x01},
  389. {0x18, {0x02}, 0x01},
  390. {0x19, {0xaf}, 0x01},
  391. {0x1a, {0x02}, 0x01},
  392. {0x1b, {0xe0}, 0x01},
  393. {0x1c, {0x03}, 0x01},
  394. {0x1d, {0x01}, 0x01},
  395. {0x1e, {0x03}, 0x01},
  396. {0x1f, {0x2d}, 0x01},
  397. {0x20, {0x03}, 0x01},
  398. {0x21, {0x39}, 0x01},
  399. {0x22, {0x03}, 0x01},
  400. {0x23, {0x47}, 0x01},
  401. {0x24, {0x03}, 0x01},
  402. {0x25, {0x57}, 0x01},
  403. {0x26, {0x03}, 0x01},
  404. {0x27, {0x65}, 0x01},
  405. {0x28, {0x03}, 0x01},
  406. {0x29, {0x77}, 0x01},
  407. {0x2a, {0x03}, 0x01},
  408. {0x2b, {0x85}, 0x01},
  409. {0x2d, {0x03}, 0x01},
  410. {0x2f, {0x8f}, 0x01},
  411. {0x30, {0x03}, 0x01},
  412. {0x31, {0xcb}, 0x01},
  413. {0x32, {0x00}, 0x01},
  414. {0x33, {0xbb}, 0x01},
  415. {0x34, {0x00}, 0x01},
  416. {0x35, {0xc0}, 0x01},
  417. {0x36, {0x00}, 0x01},
  418. {0x37, {0xcc}, 0x01},
  419. {0x38, {0x00}, 0x01},
  420. {0x39, {0xd6}, 0x01},
  421. {0x3a, {0x00}, 0x01},
  422. {0x3b, {0xe1}, 0x01},
  423. {0x3d, {0x00}, 0x01},
  424. {0x3f, {0xea}, 0x01},
  425. {0x40, {0x00}, 0x01},
  426. {0x41, {0xf4}, 0x01},
  427. {0x42, {0x00}, 0x01},
  428. {0x43, {0xfe}, 0x01},
  429. {0x44, {0x01}, 0x01},
  430. {0x45, {0x07}, 0x01},
  431. {0x46, {0x01}, 0x01},
  432. {0x47, {0x28}, 0x01},
  433. {0x48, {0x01}, 0x01},
  434. {0x49, {0x44}, 0x01},
  435. {0x4a, {0x01}, 0x01},
  436. {0x4b, {0x76}, 0x01},
  437. {0x4c, {0x01}, 0x01},
  438. {0x4d, {0xa0}, 0x01},
  439. {0x4e, {0x01}, 0x01},
  440. {0x4f, {0xe7}, 0x01},
  441. {0x50, {0x02}, 0x01},
  442. {0x51, {0x1f}, 0x01},
  443. {0x52, {0x02}, 0x01},
  444. {0x53, {0x22}, 0x01},
  445. {0x54, {0x02}, 0x01},
  446. {0x55, {0x54}, 0x01},
  447. {0x56, {0x02}, 0x01},
  448. {0x58, {0x8b}, 0x01},
  449. {0x59, {0x02}, 0x01},
  450. {0x5a, {0xaf}, 0x01},
  451. {0x5b, {0x02}, 0x01},
  452. {0x5c, {0xe0}, 0x01},
  453. {0x5d, {0x03}, 0x01},
  454. {0x5e, {0x01}, 0x01},
  455. {0x5f, {0x03}, 0x01},
  456. {0x60, {0x2d}, 0x01},
  457. {0x61, {0x03}, 0x01},
  458. {0x62, {0x39}, 0x01},
  459. {0x63, {0x03}, 0x01},
  460. {0x64, {0x47}, 0x01},
  461. {0x65, {0x03}, 0x01},
  462. {0x66, {0x57}, 0x01},
  463. {0x67, {0x03}, 0x01},
  464. {0x68, {0x65}, 0x01},
  465. {0x69, {0x03}, 0x01},
  466. {0x6a, {0x77}, 0x01},
  467. {0x6b, {0x03}, 0x01},
  468. {0x6c, {0x85}, 0x01},
  469. {0x6d, {0x03}, 0x01},
  470. {0x6e, {0x8f}, 0x01},
  471. {0x6f, {0x03}, 0x01},
  472. {0x70, {0xcb}, 0x01},
  473. {0x71, {0x00}, 0x01},
  474. {0x72, {0x00}, 0x01},
  475. {0x73, {0x00}, 0x01},
  476. {0x74, {0x21}, 0x01},
  477. {0x75, {0x00}, 0x01},
  478. {0x76, {0x4c}, 0x01},
  479. {0x77, {0x00}, 0x01},
  480. {0x78, {0x6b}, 0x01},
  481. {0x79, {0x00}, 0x01},
  482. {0x7a, {0x85}, 0x01},
  483. {0x7b, {0x00}, 0x01},
  484. {0x7c, {0x9a}, 0x01},
  485. {0x7d, {0x00}, 0x01},
  486. {0x7e, {0xad}, 0x01},
  487. {0x7f, {0x00}, 0x01},
  488. {0x80, {0xbe}, 0x01},
  489. {0x81, {0x00}, 0x01},
  490. {0x82, {0xcd}, 0x01},
  491. {0x83, {0x01}, 0x01},
  492. {0x84, {0x01}, 0x01},
  493. {0x85, {0x01}, 0x01},
  494. {0x86, {0x29}, 0x01},
  495. {0x87, {0x01}, 0x01},
  496. {0x88, {0x68}, 0x01},
  497. {0x89, {0x01}, 0x01},
  498. {0x8a, {0x98}, 0x01},
  499. {0x8b, {0x01}, 0x01},
  500. {0x8c, {0xe5}, 0x01},
  501. {0x8d, {0x02}, 0x01},
  502. {0x8e, {0x1e}, 0x01},
  503. {0x8f, {0x02}, 0x01},
  504. {0x90, {0x30}, 0x01},
  505. {0x91, {0x02}, 0x01},
  506. {0x92, {0x52}, 0x01},
  507. {0x93, {0x02}, 0x01},
  508. {0x94, {0x88}, 0x01},
  509. {0x95, {0x02}, 0x01},
  510. {0x96, {0xaa}, 0x01},
  511. {0x97, {0x02}, 0x01},
  512. {0x98, {0xd7}, 0x01},
  513. {0x99, {0x02}, 0x01},
  514. {0x9a, {0xf7}, 0x01},
  515. {0x9b, {0x03}, 0x01},
  516. {0x9c, {0x21}, 0x01},
  517. {0x9d, {0x03}, 0x01},
  518. {0x9e, {0x2e}, 0x01},
  519. {0x9f, {0x03}, 0x01},
  520. {0xa0, {0x3d}, 0x01},
  521. {0xa2, {0x03}, 0x01},
  522. {0xa3, {0x4c}, 0x01},
  523. {0xa4, {0x03}, 0x01},
  524. {0xa5, {0x5e}, 0x01},
  525. {0xa6, {0x03}, 0x01},
  526. {0xa7, {0x71}, 0x01},
  527. {0xa9, {0x03}, 0x01},
  528. {0xaa, {0x86}, 0x01},
  529. {0xab, {0x03}, 0x01},
  530. {0xac, {0x94}, 0x01},
  531. {0xad, {0x03}, 0x01},
  532. {0xae, {0xfa}, 0x01},
  533. {0xaf, {0x00}, 0x01},
  534. {0xb0, {0x00}, 0x01},
  535. {0xb1, {0x00}, 0x01},
  536. {0xb2, {0x21}, 0x01},
  537. {0xb3, {0x00}, 0x01},
  538. {0xb4, {0x4c}, 0x01},
  539. {0xb5, {0x00}, 0x01},
  540. {0xb6, {0x6b}, 0x01},
  541. {0xb7, {0x00}, 0x01},
  542. {0xb8, {0x85}, 0x01},
  543. {0xb9, {0x00}, 0x01},
  544. {0xba, {0x9a}, 0x01},
  545. {0xbb, {0x00}, 0x01},
  546. {0xbc, {0xad}, 0x01},
  547. {0xbd, {0x00}, 0x01},
  548. {0xbe, {0xbe}, 0x01},
  549. {0xbf, {0x00}, 0x01},
  550. {0xc0, {0xcd}, 0x01},
  551. {0xc1, {0x01}, 0x01},
  552. {0xc2, {0x01}, 0x01},
  553. {0xc3, {0x01}, 0x01},
  554. {0xc4, {0x29}, 0x01},
  555. {0xc5, {0x01}, 0x01},
  556. {0xc6, {0x68}, 0x01},
  557. {0xc7, {0x01}, 0x01},
  558. {0xc8, {0x98}, 0x01},
  559. {0xc9, {0x01}, 0x01},
  560. {0xca, {0xe5}, 0x01},
  561. {0xcb, {0x02}, 0x01},
  562. {0xcc, {0x1e}, 0x01},
  563. {0xcd, {0x02}, 0x01},
  564. {0xce, {0x20}, 0x01},
  565. {0xcf, {0x02}, 0x01},
  566. {0xd0, {0x52}, 0x01},
  567. {0xd1, {0x02}, 0x01},
  568. {0xd2, {0x88}, 0x01},
  569. {0xd3, {0x02}, 0x01},
  570. {0xd4, {0xaa}, 0x01},
  571. {0xd5, {0x02}, 0x01},
  572. {0xd6, {0xd7}, 0x01},
  573. {0xd7, {0x02}, 0x01},
  574. {0xd8, {0xf7}, 0x01},
  575. {0xd9, {0x03}, 0x01},
  576. {0xda, {0x21}, 0x01},
  577. {0xdb, {0x03}, 0x01},
  578. {0xdc, {0x2e}, 0x01},
  579. {0xdd, {0x03}, 0x01},
  580. {0xde, {0x3d}, 0x01},
  581. {0xdf, {0x03}, 0x01},
  582. {0xe0, {0x4c}, 0x01},
  583. {0xe1, {0x03}, 0x01},
  584. {0xe2, {0x5e}, 0x01},
  585. {0xe3, {0x03}, 0x01},
  586. {0xe4, {0x71}, 0x01},
  587. {0xe5, {0x03}, 0x01},
  588. {0xe6, {0x86}, 0x01},
  589. {0xe7, {0x03}, 0x01},
  590. {0xe8, {0x94}, 0x01},
  591. {0xe9, {0x03}, 0x01},
  592. {0xea, {0xfa}, 0x01},
  593. /* Select CMD2 Page0 (Undocumented) */
  594. {0xff, {0x01}, 0x01},
  595. /* Reload CMD1: Don't reload default value to register */
  596. {0xfb, {0x01}, 0x01},
  597. /* Select CMD2 Page1 (Undocumented) */
  598. {0xff, {0x02}, 0x01},
  599. /* Reload CMD1: Don't reload default value to register */
  600. {0xfb, {0x01}, 0x01},
  601. /* Select CMD2 Page3 (Undocumented) */
  602. {0xff, {0x04}, 0x01},
  603. /* Reload CMD1: Don't reload default value to register */
  604. {0xfb, {0x01}, 0x01},
  605. /* Select CMD1 */
  606. {0xff, {0x00}, 0x01},
  607. {0xd3, {0x22}, 0x01}, /* RGBMIPICTRL: VSYNC back porch = 34 */
  608. {0xd4, {0x04}, 0x01}, /* RGBMIPICTRL: VSYNC front porch = 4 */
  609. };
  610. struct khadas_ts050_panel_data ts050_panel_data = {
  611. .init_code = (struct khadas_ts050_panel_cmd *)ts050_init_code,
  612. .len = ARRAY_SIZE(ts050_init_code)
  613. };
  614. struct khadas_ts050_panel_data ts050v2_panel_data = {
  615. .init_code = (struct khadas_ts050_panel_cmd *)ts050v2_init_code,
  616. .len = ARRAY_SIZE(ts050v2_init_code)
  617. };
  618. static inline
  619. struct khadas_ts050_panel *to_khadas_ts050_panel(struct drm_panel *panel)
  620. {
  621. return container_of(panel, struct khadas_ts050_panel, base);
  622. }
  623. static int khadas_ts050_panel_prepare(struct drm_panel *panel)
  624. {
  625. struct khadas_ts050_panel *khadas_ts050 = to_khadas_ts050_panel(panel);
  626. unsigned int i;
  627. int err;
  628. gpiod_set_value_cansleep(khadas_ts050->enable_gpio, 0);
  629. err = regulator_enable(khadas_ts050->supply);
  630. if (err < 0)
  631. return err;
  632. gpiod_set_value_cansleep(khadas_ts050->enable_gpio, 1);
  633. msleep(60);
  634. gpiod_set_value_cansleep(khadas_ts050->reset_gpio, 1);
  635. usleep_range(10000, 11000);
  636. gpiod_set_value_cansleep(khadas_ts050->reset_gpio, 0);
  637. /* Select CMD2 page 4 (Undocumented) */
  638. mipi_dsi_dcs_write(khadas_ts050->link, 0xff, (u8[]){ 0x05 }, 1);
  639. /* Reload CMD1: Don't reload default value to register */
  640. mipi_dsi_dcs_write(khadas_ts050->link, 0xfb, (u8[]){ 0x01 }, 1);
  641. mipi_dsi_dcs_write(khadas_ts050->link, 0xc5, (u8[]){ 0x01 }, 1);
  642. msleep(100);
  643. for (i = 0; i < khadas_ts050->panel_data->len; i++) {
  644. err = mipi_dsi_dcs_write(khadas_ts050->link,
  645. khadas_ts050->panel_data->init_code[i].cmd,
  646. &khadas_ts050->panel_data->init_code[i].data,
  647. khadas_ts050->panel_data->init_code[i].size);
  648. if (err < 0) {
  649. dev_err(panel->dev, "failed write cmds: %d\n", err);
  650. goto poweroff;
  651. }
  652. }
  653. err = mipi_dsi_dcs_exit_sleep_mode(khadas_ts050->link);
  654. if (err < 0) {
  655. dev_err(panel->dev, "failed to exit sleep mode: %d\n", err);
  656. goto poweroff;
  657. }
  658. msleep(120);
  659. /* Select CMD1 */
  660. mipi_dsi_dcs_write(khadas_ts050->link, 0xff, (u8[]){ 0x00 }, 1);
  661. err = mipi_dsi_dcs_set_tear_on(khadas_ts050->link,
  662. MIPI_DSI_DCS_TEAR_MODE_VBLANK);
  663. if (err < 0) {
  664. dev_err(panel->dev, "failed to set tear on: %d\n", err);
  665. goto poweroff;
  666. }
  667. err = mipi_dsi_dcs_set_display_on(khadas_ts050->link);
  668. if (err < 0) {
  669. dev_err(panel->dev, "failed to set display on: %d\n", err);
  670. goto poweroff;
  671. }
  672. usleep_range(10000, 11000);
  673. return 0;
  674. poweroff:
  675. gpiod_set_value_cansleep(khadas_ts050->enable_gpio, 0);
  676. gpiod_set_value_cansleep(khadas_ts050->reset_gpio, 1);
  677. regulator_disable(khadas_ts050->supply);
  678. return err;
  679. }
  680. static int khadas_ts050_panel_unprepare(struct drm_panel *panel)
  681. {
  682. struct khadas_ts050_panel *khadas_ts050 = to_khadas_ts050_panel(panel);
  683. int err;
  684. err = mipi_dsi_dcs_enter_sleep_mode(khadas_ts050->link);
  685. if (err < 0)
  686. dev_err(panel->dev, "failed to enter sleep mode: %d\n", err);
  687. msleep(150);
  688. gpiod_set_value_cansleep(khadas_ts050->enable_gpio, 0);
  689. gpiod_set_value_cansleep(khadas_ts050->reset_gpio, 1);
  690. err = regulator_disable(khadas_ts050->supply);
  691. if (err < 0)
  692. return err;
  693. return 0;
  694. }
  695. static int khadas_ts050_panel_disable(struct drm_panel *panel)
  696. {
  697. struct khadas_ts050_panel *khadas_ts050 = to_khadas_ts050_panel(panel);
  698. int err;
  699. err = mipi_dsi_dcs_set_display_off(khadas_ts050->link);
  700. if (err < 0)
  701. dev_err(panel->dev, "failed to set display off: %d\n", err);
  702. usleep_range(10000, 11000);
  703. return 0;
  704. }
  705. static const struct drm_display_mode default_mode = {
  706. .clock = 160000,
  707. .hdisplay = 1080,
  708. .hsync_start = 1080 + 117,
  709. .hsync_end = 1080 + 117 + 5,
  710. .htotal = 1080 + 117 + 5 + 160,
  711. .vdisplay = 1920,
  712. .vsync_start = 1920 + 4,
  713. .vsync_end = 1920 + 4 + 3,
  714. .vtotal = 1920 + 4 + 3 + 31,
  715. .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
  716. };
  717. static int khadas_ts050_panel_get_modes(struct drm_panel *panel,
  718. struct drm_connector *connector)
  719. {
  720. struct drm_display_mode *mode;
  721. mode = drm_mode_duplicate(connector->dev, &default_mode);
  722. if (!mode) {
  723. dev_err(panel->dev, "failed to add mode %ux%u@%u\n",
  724. default_mode.hdisplay, default_mode.vdisplay,
  725. drm_mode_vrefresh(&default_mode));
  726. return -ENOMEM;
  727. }
  728. drm_mode_set_name(mode);
  729. drm_mode_probed_add(connector, mode);
  730. connector->display_info.width_mm = 64;
  731. connector->display_info.height_mm = 118;
  732. connector->display_info.bpc = 8;
  733. return 1;
  734. }
  735. static const struct drm_panel_funcs khadas_ts050_panel_funcs = {
  736. .prepare = khadas_ts050_panel_prepare,
  737. .unprepare = khadas_ts050_panel_unprepare,
  738. .disable = khadas_ts050_panel_disable,
  739. .get_modes = khadas_ts050_panel_get_modes,
  740. };
  741. static const struct of_device_id khadas_ts050_of_match[] = {
  742. { .compatible = "khadas,ts050", .data = &ts050_panel_data, },
  743. { .compatible = "khadas,ts050v2", .data = &ts050v2_panel_data, },
  744. { /* sentinel */ }
  745. };
  746. MODULE_DEVICE_TABLE(of, khadas_ts050_of_match);
  747. static int khadas_ts050_panel_add(struct khadas_ts050_panel *khadas_ts050)
  748. {
  749. struct device *dev = &khadas_ts050->link->dev;
  750. int err;
  751. khadas_ts050->supply = devm_regulator_get(dev, "power");
  752. if (IS_ERR(khadas_ts050->supply))
  753. return dev_err_probe(dev, PTR_ERR(khadas_ts050->supply),
  754. "failed to get power supply");
  755. khadas_ts050->reset_gpio = devm_gpiod_get(dev, "reset",
  756. GPIOD_OUT_LOW);
  757. if (IS_ERR(khadas_ts050->reset_gpio))
  758. return dev_err_probe(dev, PTR_ERR(khadas_ts050->reset_gpio),
  759. "failed to get reset gpio");
  760. khadas_ts050->enable_gpio = devm_gpiod_get(dev, "enable",
  761. GPIOD_OUT_HIGH);
  762. if (IS_ERR(khadas_ts050->enable_gpio))
  763. return dev_err_probe(dev, PTR_ERR(khadas_ts050->enable_gpio),
  764. "failed to get enable gpio");
  765. drm_panel_init(&khadas_ts050->base, &khadas_ts050->link->dev,
  766. &khadas_ts050_panel_funcs, DRM_MODE_CONNECTOR_DSI);
  767. err = drm_panel_of_backlight(&khadas_ts050->base);
  768. if (err)
  769. return err;
  770. drm_panel_add(&khadas_ts050->base);
  771. return 0;
  772. }
  773. static int khadas_ts050_panel_probe(struct mipi_dsi_device *dsi)
  774. {
  775. struct khadas_ts050_panel *khadas_ts050;
  776. int err;
  777. const void *data = of_device_get_match_data(&dsi->dev);
  778. if (!data) {
  779. dev_err(&dsi->dev, "No matching data\n");
  780. return -ENODEV;
  781. }
  782. dsi->lanes = 4;
  783. dsi->format = MIPI_DSI_FMT_RGB888;
  784. dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
  785. MIPI_DSI_MODE_LPM | MIPI_DSI_MODE_NO_EOT_PACKET;
  786. khadas_ts050 = devm_kzalloc(&dsi->dev, sizeof(*khadas_ts050),
  787. GFP_KERNEL);
  788. if (!khadas_ts050)
  789. return -ENOMEM;
  790. khadas_ts050->panel_data = (struct khadas_ts050_panel_data *)data;
  791. mipi_dsi_set_drvdata(dsi, khadas_ts050);
  792. khadas_ts050->link = dsi;
  793. err = khadas_ts050_panel_add(khadas_ts050);
  794. if (err < 0)
  795. return err;
  796. err = mipi_dsi_attach(dsi);
  797. if (err)
  798. drm_panel_remove(&khadas_ts050->base);
  799. return err;
  800. }
  801. static void khadas_ts050_panel_remove(struct mipi_dsi_device *dsi)
  802. {
  803. struct khadas_ts050_panel *khadas_ts050 = mipi_dsi_get_drvdata(dsi);
  804. int err;
  805. err = mipi_dsi_detach(dsi);
  806. if (err < 0)
  807. dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
  808. drm_panel_remove(&khadas_ts050->base);
  809. }
  810. static struct mipi_dsi_driver khadas_ts050_panel_driver = {
  811. .driver = {
  812. .name = "panel-khadas-ts050",
  813. .of_match_table = khadas_ts050_of_match,
  814. },
  815. .probe = khadas_ts050_panel_probe,
  816. .remove = khadas_ts050_panel_remove,
  817. };
  818. module_mipi_dsi_driver(khadas_ts050_panel_driver);
  819. MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
  820. MODULE_DESCRIPTION("Khadas TS050 panel driver");
  821. MODULE_LICENSE("GPL v2");