intel_dsi_panel_vbt.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. /*
  2. * Copyright © 2014 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Author: Shobhit Kumar <shobhit.kumar@intel.com>
  24. *
  25. */
  26. #include <drm/drmP.h>
  27. #include <drm/drm_crtc.h>
  28. #include <drm/drm_edid.h>
  29. #include <drm/i915_drm.h>
  30. #include <drm/drm_panel.h>
  31. #include <linux/gpio/consumer.h>
  32. #include <linux/slab.h>
  33. #include <video/mipi_display.h>
  34. #include <asm/intel-mid.h>
  35. #include <video/mipi_display.h>
  36. #include "i915_drv.h"
  37. #include "intel_drv.h"
  38. #include "intel_dsi.h"
  39. struct vbt_panel {
  40. struct drm_panel panel;
  41. struct intel_dsi *intel_dsi;
  42. };
  43. static inline struct vbt_panel *to_vbt_panel(struct drm_panel *panel)
  44. {
  45. return container_of(panel, struct vbt_panel, panel);
  46. }
  47. #define MIPI_TRANSFER_MODE_SHIFT 0
  48. #define MIPI_VIRTUAL_CHANNEL_SHIFT 1
  49. #define MIPI_PORT_SHIFT 3
  50. #define PREPARE_CNT_MAX 0x3F
  51. #define EXIT_ZERO_CNT_MAX 0x3F
  52. #define CLK_ZERO_CNT_MAX 0xFF
  53. #define TRAIL_CNT_MAX 0x1F
  54. #define NS_KHZ_RATIO 1000000
  55. /* base offsets for gpio pads */
  56. #define VLV_GPIO_NC_0_HV_DDI0_HPD 0x4130
  57. #define VLV_GPIO_NC_1_HV_DDI0_DDC_SDA 0x4120
  58. #define VLV_GPIO_NC_2_HV_DDI0_DDC_SCL 0x4110
  59. #define VLV_GPIO_NC_3_PANEL0_VDDEN 0x4140
  60. #define VLV_GPIO_NC_4_PANEL0_BKLTEN 0x4150
  61. #define VLV_GPIO_NC_5_PANEL0_BKLTCTL 0x4160
  62. #define VLV_GPIO_NC_6_HV_DDI1_HPD 0x4180
  63. #define VLV_GPIO_NC_7_HV_DDI1_DDC_SDA 0x4190
  64. #define VLV_GPIO_NC_8_HV_DDI1_DDC_SCL 0x4170
  65. #define VLV_GPIO_NC_9_PANEL1_VDDEN 0x4100
  66. #define VLV_GPIO_NC_10_PANEL1_BKLTEN 0x40E0
  67. #define VLV_GPIO_NC_11_PANEL1_BKLTCTL 0x40F0
  68. #define VLV_GPIO_PCONF0(base_offset) (base_offset)
  69. #define VLV_GPIO_PAD_VAL(base_offset) ((base_offset) + 8)
  70. struct gpio_map {
  71. u16 base_offset;
  72. bool init;
  73. };
  74. static struct gpio_map vlv_gpio_table[] = {
  75. { VLV_GPIO_NC_0_HV_DDI0_HPD },
  76. { VLV_GPIO_NC_1_HV_DDI0_DDC_SDA },
  77. { VLV_GPIO_NC_2_HV_DDI0_DDC_SCL },
  78. { VLV_GPIO_NC_3_PANEL0_VDDEN },
  79. { VLV_GPIO_NC_4_PANEL0_BKLTEN },
  80. { VLV_GPIO_NC_5_PANEL0_BKLTCTL },
  81. { VLV_GPIO_NC_6_HV_DDI1_HPD },
  82. { VLV_GPIO_NC_7_HV_DDI1_DDC_SDA },
  83. { VLV_GPIO_NC_8_HV_DDI1_DDC_SCL },
  84. { VLV_GPIO_NC_9_PANEL1_VDDEN },
  85. { VLV_GPIO_NC_10_PANEL1_BKLTEN },
  86. { VLV_GPIO_NC_11_PANEL1_BKLTCTL },
  87. };
  88. #define CHV_GPIO_IDX_START_N 0
  89. #define CHV_GPIO_IDX_START_E 73
  90. #define CHV_GPIO_IDX_START_SW 100
  91. #define CHV_GPIO_IDX_START_SE 198
  92. #define CHV_VBT_MAX_PINS_PER_FMLY 15
  93. #define CHV_GPIO_PAD_CFG0(f, i) (0x4400 + (f) * 0x400 + (i) * 8)
  94. #define CHV_GPIO_GPIOEN (1 << 15)
  95. #define CHV_GPIO_GPIOCFG_GPIO (0 << 8)
  96. #define CHV_GPIO_GPIOCFG_GPO (1 << 8)
  97. #define CHV_GPIO_GPIOCFG_GPI (2 << 8)
  98. #define CHV_GPIO_GPIOCFG_HIZ (3 << 8)
  99. #define CHV_GPIO_GPIOTXSTATE(state) ((!!(state)) << 1)
  100. #define CHV_GPIO_PAD_CFG1(f, i) (0x4400 + (f) * 0x400 + (i) * 8 + 4)
  101. #define CHV_GPIO_CFGLOCK (1 << 31)
  102. static inline enum port intel_dsi_seq_port_to_port(u8 port)
  103. {
  104. return port ? PORT_C : PORT_A;
  105. }
  106. static const u8 *mipi_exec_send_packet(struct intel_dsi *intel_dsi,
  107. const u8 *data)
  108. {
  109. struct mipi_dsi_device *dsi_device;
  110. u8 type, flags, seq_port;
  111. u16 len;
  112. enum port port;
  113. DRM_DEBUG_KMS("\n");
  114. flags = *data++;
  115. type = *data++;
  116. len = *((u16 *) data);
  117. data += 2;
  118. seq_port = (flags >> MIPI_PORT_SHIFT) & 3;
  119. /* For DSI single link on Port A & C, the seq_port value which is
  120. * parsed from Sequence Block#53 of VBT has been set to 0
  121. * Now, read/write of packets for the DSI single link on Port A and
  122. * Port C will based on the DVO port from VBT block 2.
  123. */
  124. if (intel_dsi->ports == (1 << PORT_C))
  125. port = PORT_C;
  126. else
  127. port = intel_dsi_seq_port_to_port(seq_port);
  128. dsi_device = intel_dsi->dsi_hosts[port]->device;
  129. if (!dsi_device) {
  130. DRM_DEBUG_KMS("no dsi device for port %c\n", port_name(port));
  131. goto out;
  132. }
  133. if ((flags >> MIPI_TRANSFER_MODE_SHIFT) & 1)
  134. dsi_device->mode_flags &= ~MIPI_DSI_MODE_LPM;
  135. else
  136. dsi_device->mode_flags |= MIPI_DSI_MODE_LPM;
  137. dsi_device->channel = (flags >> MIPI_VIRTUAL_CHANNEL_SHIFT) & 3;
  138. switch (type) {
  139. case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
  140. mipi_dsi_generic_write(dsi_device, NULL, 0);
  141. break;
  142. case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
  143. mipi_dsi_generic_write(dsi_device, data, 1);
  144. break;
  145. case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
  146. mipi_dsi_generic_write(dsi_device, data, 2);
  147. break;
  148. case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
  149. case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
  150. case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
  151. DRM_DEBUG_DRIVER("Generic Read not yet implemented or used\n");
  152. break;
  153. case MIPI_DSI_GENERIC_LONG_WRITE:
  154. mipi_dsi_generic_write(dsi_device, data, len);
  155. break;
  156. case MIPI_DSI_DCS_SHORT_WRITE:
  157. mipi_dsi_dcs_write_buffer(dsi_device, data, 1);
  158. break;
  159. case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
  160. mipi_dsi_dcs_write_buffer(dsi_device, data, 2);
  161. break;
  162. case MIPI_DSI_DCS_READ:
  163. DRM_DEBUG_DRIVER("DCS Read not yet implemented or used\n");
  164. break;
  165. case MIPI_DSI_DCS_LONG_WRITE:
  166. mipi_dsi_dcs_write_buffer(dsi_device, data, len);
  167. break;
  168. }
  169. out:
  170. data += len;
  171. return data;
  172. }
  173. static const u8 *mipi_exec_delay(struct intel_dsi *intel_dsi, const u8 *data)
  174. {
  175. u32 delay = *((const u32 *) data);
  176. DRM_DEBUG_KMS("\n");
  177. usleep_range(delay, delay + 10);
  178. data += 4;
  179. return data;
  180. }
  181. static void vlv_exec_gpio(struct drm_i915_private *dev_priv,
  182. u8 gpio_source, u8 gpio_index, bool value)
  183. {
  184. struct gpio_map *map;
  185. u16 pconf0, padval;
  186. u32 tmp;
  187. u8 port;
  188. if (gpio_index >= ARRAY_SIZE(vlv_gpio_table)) {
  189. DRM_DEBUG_KMS("unknown gpio index %u\n", gpio_index);
  190. return;
  191. }
  192. map = &vlv_gpio_table[gpio_index];
  193. if (dev_priv->vbt.dsi.seq_version >= 3) {
  194. /* XXX: this assumes vlv_gpio_table only has NC GPIOs. */
  195. port = IOSF_PORT_GPIO_NC;
  196. } else {
  197. if (gpio_source == 0) {
  198. port = IOSF_PORT_GPIO_NC;
  199. } else if (gpio_source == 1) {
  200. DRM_DEBUG_KMS("SC gpio not supported\n");
  201. return;
  202. } else {
  203. DRM_DEBUG_KMS("unknown gpio source %u\n", gpio_source);
  204. return;
  205. }
  206. }
  207. pconf0 = VLV_GPIO_PCONF0(map->base_offset);
  208. padval = VLV_GPIO_PAD_VAL(map->base_offset);
  209. mutex_lock(&dev_priv->sb_lock);
  210. if (!map->init) {
  211. /* FIXME: remove constant below */
  212. vlv_iosf_sb_write(dev_priv, port, pconf0, 0x2000CC00);
  213. map->init = true;
  214. }
  215. tmp = 0x4 | value;
  216. vlv_iosf_sb_write(dev_priv, port, padval, tmp);
  217. mutex_unlock(&dev_priv->sb_lock);
  218. }
  219. static void chv_exec_gpio(struct drm_i915_private *dev_priv,
  220. u8 gpio_source, u8 gpio_index, bool value)
  221. {
  222. u16 cfg0, cfg1;
  223. u16 family_num;
  224. u8 port;
  225. if (dev_priv->vbt.dsi.seq_version >= 3) {
  226. if (gpio_index >= CHV_GPIO_IDX_START_SE) {
  227. /* XXX: it's unclear whether 255->57 is part of SE. */
  228. gpio_index -= CHV_GPIO_IDX_START_SE;
  229. port = CHV_IOSF_PORT_GPIO_SE;
  230. } else if (gpio_index >= CHV_GPIO_IDX_START_SW) {
  231. gpio_index -= CHV_GPIO_IDX_START_SW;
  232. port = CHV_IOSF_PORT_GPIO_SW;
  233. } else if (gpio_index >= CHV_GPIO_IDX_START_E) {
  234. gpio_index -= CHV_GPIO_IDX_START_E;
  235. port = CHV_IOSF_PORT_GPIO_E;
  236. } else {
  237. port = CHV_IOSF_PORT_GPIO_N;
  238. }
  239. } else {
  240. /* XXX: The spec is unclear about CHV GPIO on seq v2 */
  241. if (gpio_source != 0) {
  242. DRM_DEBUG_KMS("unknown gpio source %u\n", gpio_source);
  243. return;
  244. }
  245. if (gpio_index >= CHV_GPIO_IDX_START_E) {
  246. DRM_DEBUG_KMS("invalid gpio index %u for GPIO N\n",
  247. gpio_index);
  248. return;
  249. }
  250. port = CHV_IOSF_PORT_GPIO_N;
  251. }
  252. family_num = gpio_index / CHV_VBT_MAX_PINS_PER_FMLY;
  253. gpio_index = gpio_index % CHV_VBT_MAX_PINS_PER_FMLY;
  254. cfg0 = CHV_GPIO_PAD_CFG0(family_num, gpio_index);
  255. cfg1 = CHV_GPIO_PAD_CFG1(family_num, gpio_index);
  256. mutex_lock(&dev_priv->sb_lock);
  257. vlv_iosf_sb_write(dev_priv, port, cfg1, 0);
  258. vlv_iosf_sb_write(dev_priv, port, cfg0,
  259. CHV_GPIO_GPIOEN | CHV_GPIO_GPIOCFG_GPO |
  260. CHV_GPIO_GPIOTXSTATE(value));
  261. mutex_unlock(&dev_priv->sb_lock);
  262. }
  263. static void bxt_exec_gpio(struct drm_i915_private *dev_priv,
  264. u8 gpio_source, u8 gpio_index, bool value)
  265. {
  266. /* XXX: this table is a quick ugly hack. */
  267. static struct gpio_desc *bxt_gpio_table[U8_MAX + 1];
  268. struct gpio_desc *gpio_desc = bxt_gpio_table[gpio_index];
  269. if (!gpio_desc) {
  270. gpio_desc = devm_gpiod_get_index(dev_priv->drm.dev,
  271. "panel", gpio_index,
  272. value ? GPIOD_OUT_LOW :
  273. GPIOD_OUT_HIGH);
  274. if (IS_ERR_OR_NULL(gpio_desc)) {
  275. DRM_ERROR("GPIO index %u request failed (%ld)\n",
  276. gpio_index, PTR_ERR(gpio_desc));
  277. return;
  278. }
  279. bxt_gpio_table[gpio_index] = gpio_desc;
  280. }
  281. gpiod_set_value(gpio_desc, value);
  282. }
  283. static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data)
  284. {
  285. struct drm_device *dev = intel_dsi->base.base.dev;
  286. struct drm_i915_private *dev_priv = to_i915(dev);
  287. u8 gpio_source, gpio_index = 0, gpio_number;
  288. bool value;
  289. DRM_DEBUG_KMS("\n");
  290. if (dev_priv->vbt.dsi.seq_version >= 3)
  291. gpio_index = *data++;
  292. gpio_number = *data++;
  293. /* gpio source in sequence v2 only */
  294. if (dev_priv->vbt.dsi.seq_version == 2)
  295. gpio_source = (*data >> 1) & 3;
  296. else
  297. gpio_source = 0;
  298. /* pull up/down */
  299. value = *data++ & 1;
  300. if (IS_VALLEYVIEW(dev_priv))
  301. vlv_exec_gpio(dev_priv, gpio_source, gpio_number, value);
  302. else if (IS_CHERRYVIEW(dev_priv))
  303. chv_exec_gpio(dev_priv, gpio_source, gpio_number, value);
  304. else
  305. bxt_exec_gpio(dev_priv, gpio_source, gpio_index, value);
  306. return data;
  307. }
  308. static const u8 *mipi_exec_i2c(struct intel_dsi *intel_dsi, const u8 *data)
  309. {
  310. DRM_DEBUG_KMS("Skipping I2C element execution\n");
  311. return data + *(data + 6) + 7;
  312. }
  313. static const u8 *mipi_exec_spi(struct intel_dsi *intel_dsi, const u8 *data)
  314. {
  315. DRM_DEBUG_KMS("Skipping SPI element execution\n");
  316. return data + *(data + 5) + 6;
  317. }
  318. static const u8 *mipi_exec_pmic(struct intel_dsi *intel_dsi, const u8 *data)
  319. {
  320. DRM_DEBUG_KMS("Skipping PMIC element execution\n");
  321. return data + 15;
  322. }
  323. typedef const u8 * (*fn_mipi_elem_exec)(struct intel_dsi *intel_dsi,
  324. const u8 *data);
  325. static const fn_mipi_elem_exec exec_elem[] = {
  326. [MIPI_SEQ_ELEM_SEND_PKT] = mipi_exec_send_packet,
  327. [MIPI_SEQ_ELEM_DELAY] = mipi_exec_delay,
  328. [MIPI_SEQ_ELEM_GPIO] = mipi_exec_gpio,
  329. [MIPI_SEQ_ELEM_I2C] = mipi_exec_i2c,
  330. [MIPI_SEQ_ELEM_SPI] = mipi_exec_spi,
  331. [MIPI_SEQ_ELEM_PMIC] = mipi_exec_pmic,
  332. };
  333. /*
  334. * MIPI Sequence from VBT #53 parsing logic
  335. * We have already separated each seqence during bios parsing
  336. * Following is generic execution function for any sequence
  337. */
  338. static const char * const seq_name[] = {
  339. [MIPI_SEQ_DEASSERT_RESET] = "MIPI_SEQ_DEASSERT_RESET",
  340. [MIPI_SEQ_INIT_OTP] = "MIPI_SEQ_INIT_OTP",
  341. [MIPI_SEQ_DISPLAY_ON] = "MIPI_SEQ_DISPLAY_ON",
  342. [MIPI_SEQ_DISPLAY_OFF] = "MIPI_SEQ_DISPLAY_OFF",
  343. [MIPI_SEQ_ASSERT_RESET] = "MIPI_SEQ_ASSERT_RESET",
  344. [MIPI_SEQ_BACKLIGHT_ON] = "MIPI_SEQ_BACKLIGHT_ON",
  345. [MIPI_SEQ_BACKLIGHT_OFF] = "MIPI_SEQ_BACKLIGHT_OFF",
  346. [MIPI_SEQ_TEAR_ON] = "MIPI_SEQ_TEAR_ON",
  347. [MIPI_SEQ_TEAR_OFF] = "MIPI_SEQ_TEAR_OFF",
  348. [MIPI_SEQ_POWER_ON] = "MIPI_SEQ_POWER_ON",
  349. [MIPI_SEQ_POWER_OFF] = "MIPI_SEQ_POWER_OFF",
  350. };
  351. static const char *sequence_name(enum mipi_seq seq_id)
  352. {
  353. if (seq_id < ARRAY_SIZE(seq_name) && seq_name[seq_id])
  354. return seq_name[seq_id];
  355. else
  356. return "(unknown)";
  357. }
  358. static void generic_exec_sequence(struct drm_panel *panel, enum mipi_seq seq_id)
  359. {
  360. struct vbt_panel *vbt_panel = to_vbt_panel(panel);
  361. struct intel_dsi *intel_dsi = vbt_panel->intel_dsi;
  362. struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
  363. const u8 *data;
  364. fn_mipi_elem_exec mipi_elem_exec;
  365. if (WARN_ON(seq_id >= ARRAY_SIZE(dev_priv->vbt.dsi.sequence)))
  366. return;
  367. data = dev_priv->vbt.dsi.sequence[seq_id];
  368. if (!data)
  369. return;
  370. WARN_ON(*data != seq_id);
  371. DRM_DEBUG_KMS("Starting MIPI sequence %d - %s\n",
  372. seq_id, sequence_name(seq_id));
  373. /* Skip Sequence Byte. */
  374. data++;
  375. /* Skip Size of Sequence. */
  376. if (dev_priv->vbt.dsi.seq_version >= 3)
  377. data += 4;
  378. while (1) {
  379. u8 operation_byte = *data++;
  380. u8 operation_size = 0;
  381. if (operation_byte == MIPI_SEQ_ELEM_END)
  382. break;
  383. if (operation_byte < ARRAY_SIZE(exec_elem))
  384. mipi_elem_exec = exec_elem[operation_byte];
  385. else
  386. mipi_elem_exec = NULL;
  387. /* Size of Operation. */
  388. if (dev_priv->vbt.dsi.seq_version >= 3)
  389. operation_size = *data++;
  390. if (mipi_elem_exec) {
  391. const u8 *next = data + operation_size;
  392. data = mipi_elem_exec(intel_dsi, data);
  393. /* Consistency check if we have size. */
  394. if (operation_size && data != next) {
  395. DRM_ERROR("Inconsistent operation size\n");
  396. return;
  397. }
  398. } else if (operation_size) {
  399. /* We have size, skip. */
  400. DRM_DEBUG_KMS("Unsupported MIPI operation byte %u\n",
  401. operation_byte);
  402. data += operation_size;
  403. } else {
  404. /* No size, can't skip without parsing. */
  405. DRM_ERROR("Unsupported MIPI operation byte %u\n",
  406. operation_byte);
  407. return;
  408. }
  409. }
  410. }
  411. static int vbt_panel_prepare(struct drm_panel *panel)
  412. {
  413. generic_exec_sequence(panel, MIPI_SEQ_ASSERT_RESET);
  414. generic_exec_sequence(panel, MIPI_SEQ_POWER_ON);
  415. generic_exec_sequence(panel, MIPI_SEQ_DEASSERT_RESET);
  416. generic_exec_sequence(panel, MIPI_SEQ_INIT_OTP);
  417. return 0;
  418. }
  419. static int vbt_panel_unprepare(struct drm_panel *panel)
  420. {
  421. generic_exec_sequence(panel, MIPI_SEQ_ASSERT_RESET);
  422. generic_exec_sequence(panel, MIPI_SEQ_POWER_OFF);
  423. return 0;
  424. }
  425. static int vbt_panel_enable(struct drm_panel *panel)
  426. {
  427. generic_exec_sequence(panel, MIPI_SEQ_DISPLAY_ON);
  428. generic_exec_sequence(panel, MIPI_SEQ_BACKLIGHT_ON);
  429. return 0;
  430. }
  431. static int vbt_panel_disable(struct drm_panel *panel)
  432. {
  433. generic_exec_sequence(panel, MIPI_SEQ_BACKLIGHT_OFF);
  434. generic_exec_sequence(panel, MIPI_SEQ_DISPLAY_OFF);
  435. return 0;
  436. }
  437. static int vbt_panel_get_modes(struct drm_panel *panel)
  438. {
  439. struct vbt_panel *vbt_panel = to_vbt_panel(panel);
  440. struct intel_dsi *intel_dsi = vbt_panel->intel_dsi;
  441. struct drm_device *dev = intel_dsi->base.base.dev;
  442. struct drm_i915_private *dev_priv = to_i915(dev);
  443. struct drm_display_mode *mode;
  444. if (!panel->connector)
  445. return 0;
  446. mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode);
  447. if (!mode)
  448. return 0;
  449. mode->type |= DRM_MODE_TYPE_PREFERRED;
  450. drm_mode_probed_add(panel->connector, mode);
  451. return 1;
  452. }
  453. static const struct drm_panel_funcs vbt_panel_funcs = {
  454. .disable = vbt_panel_disable,
  455. .unprepare = vbt_panel_unprepare,
  456. .prepare = vbt_panel_prepare,
  457. .enable = vbt_panel_enable,
  458. .get_modes = vbt_panel_get_modes,
  459. };
  460. struct drm_panel *vbt_panel_init(struct intel_dsi *intel_dsi, u16 panel_id)
  461. {
  462. struct drm_device *dev = intel_dsi->base.base.dev;
  463. struct drm_i915_private *dev_priv = to_i915(dev);
  464. struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
  465. struct mipi_pps_data *pps = dev_priv->vbt.dsi.pps;
  466. struct drm_display_mode *mode = dev_priv->vbt.lfp_lvds_vbt_mode;
  467. struct vbt_panel *vbt_panel;
  468. u32 bpp;
  469. u32 tlpx_ns, extra_byte_count, bitrate, tlpx_ui;
  470. u32 ui_num, ui_den;
  471. u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt;
  472. u32 ths_prepare_ns, tclk_trail_ns;
  473. u32 tclk_prepare_clkzero, ths_prepare_hszero;
  474. u32 lp_to_hs_switch, hs_to_lp_switch;
  475. u32 pclk, computed_ddr;
  476. u16 burst_mode_ratio;
  477. enum port port;
  478. DRM_DEBUG_KMS("\n");
  479. intel_dsi->eotp_pkt = mipi_config->eot_pkt_disabled ? 0 : 1;
  480. intel_dsi->clock_stop = mipi_config->enable_clk_stop ? 1 : 0;
  481. intel_dsi->lane_count = mipi_config->lane_cnt + 1;
  482. intel_dsi->pixel_format =
  483. pixel_format_from_register_bits(
  484. mipi_config->videomode_color_format << 7);
  485. bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
  486. intel_dsi->dual_link = mipi_config->dual_link;
  487. intel_dsi->pixel_overlap = mipi_config->pixel_overlap;
  488. intel_dsi->operation_mode = mipi_config->is_cmd_mode;
  489. intel_dsi->video_mode_format = mipi_config->video_transfer_mode;
  490. intel_dsi->escape_clk_div = mipi_config->byte_clk_sel;
  491. intel_dsi->lp_rx_timeout = mipi_config->lp_rx_timeout;
  492. intel_dsi->turn_arnd_val = mipi_config->turn_around_timeout;
  493. intel_dsi->rst_timer_val = mipi_config->device_reset_timer;
  494. intel_dsi->init_count = mipi_config->master_init_timer;
  495. intel_dsi->bw_timer = mipi_config->dbi_bw_timer;
  496. intel_dsi->video_frmt_cfg_bits =
  497. mipi_config->bta_enabled ? DISABLE_VIDEO_BTA : 0;
  498. pclk = mode->clock;
  499. /* In dual link mode each port needs half of pixel clock */
  500. if (intel_dsi->dual_link) {
  501. pclk = pclk / 2;
  502. /* we can enable pixel_overlap if needed by panel. In this
  503. * case we need to increase the pixelclock for extra pixels
  504. */
  505. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
  506. pclk += DIV_ROUND_UP(mode->vtotal *
  507. intel_dsi->pixel_overlap *
  508. 60, 1000);
  509. }
  510. }
  511. /* Burst Mode Ratio
  512. * Target ddr frequency from VBT / non burst ddr freq
  513. * multiply by 100 to preserve remainder
  514. */
  515. if (intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
  516. if (mipi_config->target_burst_mode_freq) {
  517. computed_ddr = (pclk * bpp) / intel_dsi->lane_count;
  518. if (mipi_config->target_burst_mode_freq <
  519. computed_ddr) {
  520. DRM_ERROR("Burst mode freq is less than computed\n");
  521. return NULL;
  522. }
  523. burst_mode_ratio = DIV_ROUND_UP(
  524. mipi_config->target_burst_mode_freq * 100,
  525. computed_ddr);
  526. pclk = DIV_ROUND_UP(pclk * burst_mode_ratio, 100);
  527. } else {
  528. DRM_ERROR("Burst mode target is not set\n");
  529. return NULL;
  530. }
  531. } else
  532. burst_mode_ratio = 100;
  533. intel_dsi->burst_mode_ratio = burst_mode_ratio;
  534. intel_dsi->pclk = pclk;
  535. bitrate = (pclk * bpp) / intel_dsi->lane_count;
  536. switch (intel_dsi->escape_clk_div) {
  537. case 0:
  538. tlpx_ns = 50;
  539. break;
  540. case 1:
  541. tlpx_ns = 100;
  542. break;
  543. case 2:
  544. tlpx_ns = 200;
  545. break;
  546. default:
  547. tlpx_ns = 50;
  548. break;
  549. }
  550. switch (intel_dsi->lane_count) {
  551. case 1:
  552. case 2:
  553. extra_byte_count = 2;
  554. break;
  555. case 3:
  556. extra_byte_count = 4;
  557. break;
  558. case 4:
  559. default:
  560. extra_byte_count = 3;
  561. break;
  562. }
  563. /*
  564. * ui(s) = 1/f [f in hz]
  565. * ui(ns) = 10^9 / (f*10^6) [f in Mhz] -> 10^3/f(Mhz)
  566. */
  567. /* in Kbps */
  568. ui_num = NS_KHZ_RATIO;
  569. ui_den = bitrate;
  570. tclk_prepare_clkzero = mipi_config->tclk_prepare_clkzero;
  571. ths_prepare_hszero = mipi_config->ths_prepare_hszero;
  572. /*
  573. * B060
  574. * LP byte clock = TLPX/ (8UI)
  575. */
  576. intel_dsi->lp_byte_clk = DIV_ROUND_UP(tlpx_ns * ui_den, 8 * ui_num);
  577. /* count values in UI = (ns value) * (bitrate / (2 * 10^6))
  578. *
  579. * Since txddrclkhs_i is 2xUI, all the count values programmed in
  580. * DPHY param register are divided by 2
  581. *
  582. * prepare count
  583. */
  584. ths_prepare_ns = max(mipi_config->ths_prepare,
  585. mipi_config->tclk_prepare);
  586. prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * ui_den, ui_num * 2);
  587. /* exit zero count */
  588. exit_zero_cnt = DIV_ROUND_UP(
  589. (ths_prepare_hszero - ths_prepare_ns) * ui_den,
  590. ui_num * 2
  591. );
  592. /*
  593. * Exit zero is unified val ths_zero and ths_exit
  594. * minimum value for ths_exit = 110ns
  595. * min (exit_zero_cnt * 2) = 110/UI
  596. * exit_zero_cnt = 55/UI
  597. */
  598. if (exit_zero_cnt < (55 * ui_den / ui_num) && (55 * ui_den) % ui_num)
  599. exit_zero_cnt += 1;
  600. /* clk zero count */
  601. clk_zero_cnt = DIV_ROUND_UP(
  602. (tclk_prepare_clkzero - ths_prepare_ns)
  603. * ui_den, 2 * ui_num);
  604. /* trail count */
  605. tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail);
  606. trail_cnt = DIV_ROUND_UP(tclk_trail_ns * ui_den, 2 * ui_num);
  607. if (prepare_cnt > PREPARE_CNT_MAX ||
  608. exit_zero_cnt > EXIT_ZERO_CNT_MAX ||
  609. clk_zero_cnt > CLK_ZERO_CNT_MAX ||
  610. trail_cnt > TRAIL_CNT_MAX)
  611. DRM_DEBUG_DRIVER("Values crossing maximum limits, restricting to max values\n");
  612. if (prepare_cnt > PREPARE_CNT_MAX)
  613. prepare_cnt = PREPARE_CNT_MAX;
  614. if (exit_zero_cnt > EXIT_ZERO_CNT_MAX)
  615. exit_zero_cnt = EXIT_ZERO_CNT_MAX;
  616. if (clk_zero_cnt > CLK_ZERO_CNT_MAX)
  617. clk_zero_cnt = CLK_ZERO_CNT_MAX;
  618. if (trail_cnt > TRAIL_CNT_MAX)
  619. trail_cnt = TRAIL_CNT_MAX;
  620. /* B080 */
  621. intel_dsi->dphy_reg = exit_zero_cnt << 24 | trail_cnt << 16 |
  622. clk_zero_cnt << 8 | prepare_cnt;
  623. /*
  624. * LP to HS switch count = 4TLPX + PREP_COUNT * 2 + EXIT_ZERO_COUNT * 2
  625. * + 10UI + Extra Byte Count
  626. *
  627. * HS to LP switch count = THS-TRAIL + 2TLPX + Extra Byte Count
  628. * Extra Byte Count is calculated according to number of lanes.
  629. * High Low Switch Count is the Max of LP to HS and
  630. * HS to LP switch count
  631. *
  632. */
  633. tlpx_ui = DIV_ROUND_UP(tlpx_ns * ui_den, ui_num);
  634. /* B044 */
  635. /* FIXME:
  636. * The comment above does not match with the code */
  637. lp_to_hs_switch = DIV_ROUND_UP(4 * tlpx_ui + prepare_cnt * 2 +
  638. exit_zero_cnt * 2 + 10, 8);
  639. hs_to_lp_switch = DIV_ROUND_UP(mipi_config->ths_trail + 2 * tlpx_ui, 8);
  640. intel_dsi->hs_to_lp_count = max(lp_to_hs_switch, hs_to_lp_switch);
  641. intel_dsi->hs_to_lp_count += extra_byte_count;
  642. /* B088 */
  643. /* LP -> HS for clock lanes
  644. * LP clk sync + LP11 + LP01 + tclk_prepare + tclk_zero +
  645. * extra byte count
  646. * 2TPLX + 1TLPX + 1 TPLX(in ns) + prepare_cnt * 2 + clk_zero_cnt *
  647. * 2(in UI) + extra byte count
  648. * In byteclks = (4TLPX + prepare_cnt * 2 + clk_zero_cnt *2 (in UI)) /
  649. * 8 + extra byte count
  650. */
  651. intel_dsi->clk_lp_to_hs_count =
  652. DIV_ROUND_UP(
  653. 4 * tlpx_ui + prepare_cnt * 2 +
  654. clk_zero_cnt * 2,
  655. 8);
  656. intel_dsi->clk_lp_to_hs_count += extra_byte_count;
  657. /* HS->LP for Clock Lanes
  658. * Low Power clock synchronisations + 1Tx byteclk + tclk_trail +
  659. * Extra byte count
  660. * 2TLPX + 8UI + (trail_count*2)(in UI) + Extra byte count
  661. * In byteclks = (2*TLpx(in UI) + trail_count*2 +8)(in UI)/8 +
  662. * Extra byte count
  663. */
  664. intel_dsi->clk_hs_to_lp_count =
  665. DIV_ROUND_UP(2 * tlpx_ui + trail_cnt * 2 + 8,
  666. 8);
  667. intel_dsi->clk_hs_to_lp_count += extra_byte_count;
  668. DRM_DEBUG_KMS("Eot %s\n", enableddisabled(intel_dsi->eotp_pkt));
  669. DRM_DEBUG_KMS("Clockstop %s\n", enableddisabled(!intel_dsi->clock_stop));
  670. DRM_DEBUG_KMS("Mode %s\n", intel_dsi->operation_mode ? "command" : "video");
  671. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  672. DRM_DEBUG_KMS("Dual link: DSI_DUAL_LINK_FRONT_BACK\n");
  673. else if (intel_dsi->dual_link == DSI_DUAL_LINK_PIXEL_ALT)
  674. DRM_DEBUG_KMS("Dual link: DSI_DUAL_LINK_PIXEL_ALT\n");
  675. else
  676. DRM_DEBUG_KMS("Dual link: NONE\n");
  677. DRM_DEBUG_KMS("Pixel Format %d\n", intel_dsi->pixel_format);
  678. DRM_DEBUG_KMS("TLPX %d\n", intel_dsi->escape_clk_div);
  679. DRM_DEBUG_KMS("LP RX Timeout 0x%x\n", intel_dsi->lp_rx_timeout);
  680. DRM_DEBUG_KMS("Turnaround Timeout 0x%x\n", intel_dsi->turn_arnd_val);
  681. DRM_DEBUG_KMS("Init Count 0x%x\n", intel_dsi->init_count);
  682. DRM_DEBUG_KMS("HS to LP Count 0x%x\n", intel_dsi->hs_to_lp_count);
  683. DRM_DEBUG_KMS("LP Byte Clock %d\n", intel_dsi->lp_byte_clk);
  684. DRM_DEBUG_KMS("DBI BW Timer 0x%x\n", intel_dsi->bw_timer);
  685. DRM_DEBUG_KMS("LP to HS Clock Count 0x%x\n", intel_dsi->clk_lp_to_hs_count);
  686. DRM_DEBUG_KMS("HS to LP Clock Count 0x%x\n", intel_dsi->clk_hs_to_lp_count);
  687. DRM_DEBUG_KMS("BTA %s\n",
  688. enableddisabled(!(intel_dsi->video_frmt_cfg_bits & DISABLE_VIDEO_BTA)));
  689. /* delays in VBT are in unit of 100us, so need to convert
  690. * here in ms
  691. * Delay (100us) * 100 /1000 = Delay / 10 (ms) */
  692. intel_dsi->backlight_off_delay = pps->bl_disable_delay / 10;
  693. intel_dsi->backlight_on_delay = pps->bl_enable_delay / 10;
  694. intel_dsi->panel_on_delay = pps->panel_on_delay / 10;
  695. intel_dsi->panel_off_delay = pps->panel_off_delay / 10;
  696. intel_dsi->panel_pwr_cycle_delay = pps->panel_power_cycle_delay / 10;
  697. /* This is cheating a bit with the cleanup. */
  698. vbt_panel = devm_kzalloc(dev->dev, sizeof(*vbt_panel), GFP_KERNEL);
  699. if (!vbt_panel)
  700. return NULL;
  701. vbt_panel->intel_dsi = intel_dsi;
  702. drm_panel_init(&vbt_panel->panel);
  703. vbt_panel->panel.funcs = &vbt_panel_funcs;
  704. drm_panel_add(&vbt_panel->panel);
  705. /* a regular driver would get the device in probe */
  706. for_each_dsi_port(port, intel_dsi->ports) {
  707. mipi_dsi_attach(intel_dsi->dsi_hosts[port]->device);
  708. }
  709. return &vbt_panel->panel;
  710. }