intel_dsi.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  1. /*
  2. * Copyright © 2013 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: Jani Nikula <jani.nikula@intel.com>
  24. */
  25. #include <drm/drmP.h>
  26. #include <drm/drm_atomic_helper.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 <drm/drm_mipi_dsi.h>
  32. #include <linux/slab.h>
  33. #include <linux/gpio/consumer.h>
  34. #include "i915_drv.h"
  35. #include "intel_drv.h"
  36. #include "intel_dsi.h"
  37. static const struct {
  38. u16 panel_id;
  39. struct drm_panel * (*init)(struct intel_dsi *intel_dsi, u16 panel_id);
  40. } intel_dsi_drivers[] = {
  41. {
  42. .panel_id = MIPI_DSI_GENERIC_PANEL_ID,
  43. .init = vbt_panel_init,
  44. },
  45. };
  46. enum mipi_dsi_pixel_format pixel_format_from_register_bits(u32 fmt)
  47. {
  48. /* It just so happens the VBT matches register contents. */
  49. switch (fmt) {
  50. case VID_MODE_FORMAT_RGB888:
  51. return MIPI_DSI_FMT_RGB888;
  52. case VID_MODE_FORMAT_RGB666:
  53. return MIPI_DSI_FMT_RGB666;
  54. case VID_MODE_FORMAT_RGB666_PACKED:
  55. return MIPI_DSI_FMT_RGB666_PACKED;
  56. case VID_MODE_FORMAT_RGB565:
  57. return MIPI_DSI_FMT_RGB565;
  58. default:
  59. MISSING_CASE(fmt);
  60. return MIPI_DSI_FMT_RGB666;
  61. }
  62. }
  63. static void wait_for_dsi_fifo_empty(struct intel_dsi *intel_dsi, enum port port)
  64. {
  65. struct drm_encoder *encoder = &intel_dsi->base.base;
  66. struct drm_device *dev = encoder->dev;
  67. struct drm_i915_private *dev_priv = dev->dev_private;
  68. u32 mask;
  69. mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY |
  70. LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY;
  71. if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & mask) == mask, 100))
  72. DRM_ERROR("DPI FIFOs are not empty\n");
  73. }
  74. static void write_data(struct drm_i915_private *dev_priv,
  75. i915_reg_t reg,
  76. const u8 *data, u32 len)
  77. {
  78. u32 i, j;
  79. for (i = 0; i < len; i += 4) {
  80. u32 val = 0;
  81. for (j = 0; j < min_t(u32, len - i, 4); j++)
  82. val |= *data++ << 8 * j;
  83. I915_WRITE(reg, val);
  84. }
  85. }
  86. static void read_data(struct drm_i915_private *dev_priv,
  87. i915_reg_t reg,
  88. u8 *data, u32 len)
  89. {
  90. u32 i, j;
  91. for (i = 0; i < len; i += 4) {
  92. u32 val = I915_READ(reg);
  93. for (j = 0; j < min_t(u32, len - i, 4); j++)
  94. *data++ = val >> 8 * j;
  95. }
  96. }
  97. static ssize_t intel_dsi_host_transfer(struct mipi_dsi_host *host,
  98. const struct mipi_dsi_msg *msg)
  99. {
  100. struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host);
  101. struct drm_device *dev = intel_dsi_host->intel_dsi->base.base.dev;
  102. struct drm_i915_private *dev_priv = dev->dev_private;
  103. enum port port = intel_dsi_host->port;
  104. struct mipi_dsi_packet packet;
  105. ssize_t ret;
  106. const u8 *header, *data;
  107. i915_reg_t data_reg, ctrl_reg;
  108. u32 data_mask, ctrl_mask;
  109. ret = mipi_dsi_create_packet(&packet, msg);
  110. if (ret < 0)
  111. return ret;
  112. header = packet.header;
  113. data = packet.payload;
  114. if (msg->flags & MIPI_DSI_MSG_USE_LPM) {
  115. data_reg = MIPI_LP_GEN_DATA(port);
  116. data_mask = LP_DATA_FIFO_FULL;
  117. ctrl_reg = MIPI_LP_GEN_CTRL(port);
  118. ctrl_mask = LP_CTRL_FIFO_FULL;
  119. } else {
  120. data_reg = MIPI_HS_GEN_DATA(port);
  121. data_mask = HS_DATA_FIFO_FULL;
  122. ctrl_reg = MIPI_HS_GEN_CTRL(port);
  123. ctrl_mask = HS_CTRL_FIFO_FULL;
  124. }
  125. /* note: this is never true for reads */
  126. if (packet.payload_length) {
  127. if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & data_mask) == 0, 50))
  128. DRM_ERROR("Timeout waiting for HS/LP DATA FIFO !full\n");
  129. write_data(dev_priv, data_reg, packet.payload,
  130. packet.payload_length);
  131. }
  132. if (msg->rx_len) {
  133. I915_WRITE(MIPI_INTR_STAT(port), GEN_READ_DATA_AVAIL);
  134. }
  135. if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & ctrl_mask) == 0, 50)) {
  136. DRM_ERROR("Timeout waiting for HS/LP CTRL FIFO !full\n");
  137. }
  138. I915_WRITE(ctrl_reg, header[2] << 16 | header[1] << 8 | header[0]);
  139. /* ->rx_len is set only for reads */
  140. if (msg->rx_len) {
  141. data_mask = GEN_READ_DATA_AVAIL;
  142. if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & data_mask) == data_mask, 50))
  143. DRM_ERROR("Timeout waiting for read data.\n");
  144. read_data(dev_priv, data_reg, msg->rx_buf, msg->rx_len);
  145. }
  146. /* XXX: fix for reads and writes */
  147. return 4 + packet.payload_length;
  148. }
  149. static int intel_dsi_host_attach(struct mipi_dsi_host *host,
  150. struct mipi_dsi_device *dsi)
  151. {
  152. return 0;
  153. }
  154. static int intel_dsi_host_detach(struct mipi_dsi_host *host,
  155. struct mipi_dsi_device *dsi)
  156. {
  157. return 0;
  158. }
  159. static const struct mipi_dsi_host_ops intel_dsi_host_ops = {
  160. .attach = intel_dsi_host_attach,
  161. .detach = intel_dsi_host_detach,
  162. .transfer = intel_dsi_host_transfer,
  163. };
  164. static struct intel_dsi_host *intel_dsi_host_init(struct intel_dsi *intel_dsi,
  165. enum port port)
  166. {
  167. struct intel_dsi_host *host;
  168. struct mipi_dsi_device *device;
  169. host = kzalloc(sizeof(*host), GFP_KERNEL);
  170. if (!host)
  171. return NULL;
  172. host->base.ops = &intel_dsi_host_ops;
  173. host->intel_dsi = intel_dsi;
  174. host->port = port;
  175. /*
  176. * We should call mipi_dsi_host_register(&host->base) here, but we don't
  177. * have a host->dev, and we don't have OF stuff either. So just use the
  178. * dsi framework as a library and hope for the best. Create the dsi
  179. * devices by ourselves here too. Need to be careful though, because we
  180. * don't initialize any of the driver model devices here.
  181. */
  182. device = kzalloc(sizeof(*device), GFP_KERNEL);
  183. if (!device) {
  184. kfree(host);
  185. return NULL;
  186. }
  187. device->host = &host->base;
  188. host->device = device;
  189. return host;
  190. }
  191. /*
  192. * send a video mode command
  193. *
  194. * XXX: commands with data in MIPI_DPI_DATA?
  195. */
  196. static int dpi_send_cmd(struct intel_dsi *intel_dsi, u32 cmd, bool hs,
  197. enum port port)
  198. {
  199. struct drm_encoder *encoder = &intel_dsi->base.base;
  200. struct drm_device *dev = encoder->dev;
  201. struct drm_i915_private *dev_priv = dev->dev_private;
  202. u32 mask;
  203. /* XXX: pipe, hs */
  204. if (hs)
  205. cmd &= ~DPI_LP_MODE;
  206. else
  207. cmd |= DPI_LP_MODE;
  208. /* clear bit */
  209. I915_WRITE(MIPI_INTR_STAT(port), SPL_PKT_SENT_INTERRUPT);
  210. /* XXX: old code skips write if control unchanged */
  211. if (cmd == I915_READ(MIPI_DPI_CONTROL(port)))
  212. DRM_ERROR("Same special packet %02x twice in a row.\n", cmd);
  213. I915_WRITE(MIPI_DPI_CONTROL(port), cmd);
  214. mask = SPL_PKT_SENT_INTERRUPT;
  215. if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & mask) == mask, 100))
  216. DRM_ERROR("Video mode command 0x%08x send failed.\n", cmd);
  217. return 0;
  218. }
  219. static void band_gap_reset(struct drm_i915_private *dev_priv)
  220. {
  221. mutex_lock(&dev_priv->sb_lock);
  222. vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
  223. vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
  224. vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
  225. udelay(150);
  226. vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
  227. vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
  228. mutex_unlock(&dev_priv->sb_lock);
  229. }
  230. static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
  231. {
  232. return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE;
  233. }
  234. static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
  235. {
  236. return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE;
  237. }
  238. static bool intel_dsi_compute_config(struct intel_encoder *encoder,
  239. struct intel_crtc_state *pipe_config)
  240. {
  241. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  242. struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
  243. base);
  244. struct intel_connector *intel_connector = intel_dsi->attached_connector;
  245. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  246. struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  247. DRM_DEBUG_KMS("\n");
  248. pipe_config->has_dsi_encoder = true;
  249. if (fixed_mode)
  250. intel_fixed_panel_mode(fixed_mode, adjusted_mode);
  251. /* DSI uses short packets for sync events, so clear mode flags for DSI */
  252. adjusted_mode->flags = 0;
  253. if (IS_BROXTON(dev_priv)) {
  254. /* Dual link goes to DSI transcoder A. */
  255. if (intel_dsi->ports == BIT(PORT_C))
  256. pipe_config->cpu_transcoder = TRANSCODER_DSI_C;
  257. else
  258. pipe_config->cpu_transcoder = TRANSCODER_DSI_A;
  259. }
  260. /*
  261. * FIXME move the DSI PLL calc from vlv_enable_dsi_pll()
  262. * to .compute_config().
  263. */
  264. pipe_config->clock_set = true;
  265. return true;
  266. }
  267. static void bxt_dsi_device_ready(struct intel_encoder *encoder)
  268. {
  269. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  270. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  271. enum port port;
  272. u32 val;
  273. DRM_DEBUG_KMS("\n");
  274. /* Exit Low power state in 4 steps*/
  275. for_each_dsi_port(port, intel_dsi->ports) {
  276. /* 1. Enable MIPI PHY transparent latch */
  277. val = I915_READ(BXT_MIPI_PORT_CTRL(port));
  278. I915_WRITE(BXT_MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD);
  279. usleep_range(2000, 2500);
  280. /* 2. Enter ULPS */
  281. val = I915_READ(MIPI_DEVICE_READY(port));
  282. val &= ~ULPS_STATE_MASK;
  283. val |= (ULPS_STATE_ENTER | DEVICE_READY);
  284. I915_WRITE(MIPI_DEVICE_READY(port), val);
  285. usleep_range(2, 3);
  286. /* 3. Exit ULPS */
  287. val = I915_READ(MIPI_DEVICE_READY(port));
  288. val &= ~ULPS_STATE_MASK;
  289. val |= (ULPS_STATE_EXIT | DEVICE_READY);
  290. I915_WRITE(MIPI_DEVICE_READY(port), val);
  291. usleep_range(1000, 1500);
  292. /* Clear ULPS and set device ready */
  293. val = I915_READ(MIPI_DEVICE_READY(port));
  294. val &= ~ULPS_STATE_MASK;
  295. val |= DEVICE_READY;
  296. I915_WRITE(MIPI_DEVICE_READY(port), val);
  297. }
  298. }
  299. static void vlv_dsi_device_ready(struct intel_encoder *encoder)
  300. {
  301. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  302. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  303. enum port port;
  304. u32 val;
  305. DRM_DEBUG_KMS("\n");
  306. mutex_lock(&dev_priv->sb_lock);
  307. /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
  308. * needed everytime after power gate */
  309. vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
  310. mutex_unlock(&dev_priv->sb_lock);
  311. /* bandgap reset is needed after everytime we do power gate */
  312. band_gap_reset(dev_priv);
  313. for_each_dsi_port(port, intel_dsi->ports) {
  314. I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
  315. usleep_range(2500, 3000);
  316. /* Enable MIPI PHY transparent latch
  317. * Common bit for both MIPI Port A & MIPI Port C
  318. * No similar bit in MIPI Port C reg
  319. */
  320. val = I915_READ(MIPI_PORT_CTRL(PORT_A));
  321. I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
  322. usleep_range(1000, 1500);
  323. I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
  324. usleep_range(2500, 3000);
  325. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
  326. usleep_range(2500, 3000);
  327. }
  328. }
  329. static void intel_dsi_device_ready(struct intel_encoder *encoder)
  330. {
  331. struct drm_device *dev = encoder->base.dev;
  332. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  333. vlv_dsi_device_ready(encoder);
  334. else if (IS_BROXTON(dev))
  335. bxt_dsi_device_ready(encoder);
  336. }
  337. static void intel_dsi_port_enable(struct intel_encoder *encoder)
  338. {
  339. struct drm_device *dev = encoder->base.dev;
  340. struct drm_i915_private *dev_priv = dev->dev_private;
  341. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  342. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  343. enum port port;
  344. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
  345. u32 temp;
  346. temp = I915_READ(VLV_CHICKEN_3);
  347. temp &= ~PIXEL_OVERLAP_CNT_MASK |
  348. intel_dsi->pixel_overlap <<
  349. PIXEL_OVERLAP_CNT_SHIFT;
  350. I915_WRITE(VLV_CHICKEN_3, temp);
  351. }
  352. for_each_dsi_port(port, intel_dsi->ports) {
  353. i915_reg_t port_ctrl = IS_BROXTON(dev) ?
  354. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  355. u32 temp;
  356. temp = I915_READ(port_ctrl);
  357. temp &= ~LANE_CONFIGURATION_MASK;
  358. temp &= ~DUAL_LINK_MODE_MASK;
  359. if (intel_dsi->ports == (BIT(PORT_A) | BIT(PORT_C))) {
  360. temp |= (intel_dsi->dual_link - 1)
  361. << DUAL_LINK_MODE_SHIFT;
  362. temp |= intel_crtc->pipe ?
  363. LANE_CONFIGURATION_DUAL_LINK_B :
  364. LANE_CONFIGURATION_DUAL_LINK_A;
  365. }
  366. /* assert ip_tg_enable signal */
  367. I915_WRITE(port_ctrl, temp | DPI_ENABLE);
  368. POSTING_READ(port_ctrl);
  369. }
  370. }
  371. static void intel_dsi_port_disable(struct intel_encoder *encoder)
  372. {
  373. struct drm_device *dev = encoder->base.dev;
  374. struct drm_i915_private *dev_priv = dev->dev_private;
  375. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  376. enum port port;
  377. for_each_dsi_port(port, intel_dsi->ports) {
  378. i915_reg_t port_ctrl = IS_BROXTON(dev) ?
  379. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  380. u32 temp;
  381. /* de-assert ip_tg_enable signal */
  382. temp = I915_READ(port_ctrl);
  383. I915_WRITE(port_ctrl, temp & ~DPI_ENABLE);
  384. POSTING_READ(port_ctrl);
  385. }
  386. }
  387. static void intel_dsi_enable(struct intel_encoder *encoder)
  388. {
  389. struct drm_device *dev = encoder->base.dev;
  390. struct drm_i915_private *dev_priv = dev->dev_private;
  391. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  392. enum port port;
  393. DRM_DEBUG_KMS("\n");
  394. if (is_cmd_mode(intel_dsi)) {
  395. for_each_dsi_port(port, intel_dsi->ports)
  396. I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
  397. } else {
  398. msleep(20); /* XXX */
  399. for_each_dsi_port(port, intel_dsi->ports)
  400. dpi_send_cmd(intel_dsi, TURN_ON, false, port);
  401. msleep(100);
  402. drm_panel_enable(intel_dsi->panel);
  403. for_each_dsi_port(port, intel_dsi->ports)
  404. wait_for_dsi_fifo_empty(intel_dsi, port);
  405. intel_dsi_port_enable(encoder);
  406. }
  407. intel_panel_enable_backlight(intel_dsi->attached_connector);
  408. }
  409. static void intel_dsi_prepare(struct intel_encoder *intel_encoder);
  410. static void intel_dsi_pre_enable(struct intel_encoder *encoder)
  411. {
  412. struct drm_device *dev = encoder->base.dev;
  413. struct drm_i915_private *dev_priv = dev->dev_private;
  414. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  415. enum port port;
  416. u32 tmp;
  417. DRM_DEBUG_KMS("\n");
  418. /*
  419. * The BIOS may leave the PLL in a wonky state where it doesn't
  420. * lock. It needs to be fully powered down to fix it.
  421. */
  422. intel_disable_dsi_pll(encoder);
  423. intel_enable_dsi_pll(encoder);
  424. intel_dsi_prepare(encoder);
  425. /* Panel Enable over CRC PMIC */
  426. if (intel_dsi->gpio_panel)
  427. gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
  428. msleep(intel_dsi->panel_on_delay);
  429. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  430. /* Disable DPOunit clock gating, can stall pipe */
  431. tmp = I915_READ(DSPCLK_GATE_D);
  432. tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
  433. I915_WRITE(DSPCLK_GATE_D, tmp);
  434. }
  435. /* put device in ready state */
  436. intel_dsi_device_ready(encoder);
  437. drm_panel_prepare(intel_dsi->panel);
  438. for_each_dsi_port(port, intel_dsi->ports)
  439. wait_for_dsi_fifo_empty(intel_dsi, port);
  440. /* Enable port in pre-enable phase itself because as per hw team
  441. * recommendation, port should be enabled befor plane & pipe */
  442. intel_dsi_enable(encoder);
  443. }
  444. static void intel_dsi_enable_nop(struct intel_encoder *encoder)
  445. {
  446. DRM_DEBUG_KMS("\n");
  447. /* for DSI port enable has to be done before pipe
  448. * and plane enable, so port enable is done in
  449. * pre_enable phase itself unlike other encoders
  450. */
  451. }
  452. static void intel_dsi_pre_disable(struct intel_encoder *encoder)
  453. {
  454. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  455. enum port port;
  456. DRM_DEBUG_KMS("\n");
  457. intel_panel_disable_backlight(intel_dsi->attached_connector);
  458. if (is_vid_mode(intel_dsi)) {
  459. /* Send Shutdown command to the panel in LP mode */
  460. for_each_dsi_port(port, intel_dsi->ports)
  461. dpi_send_cmd(intel_dsi, SHUTDOWN, false, port);
  462. msleep(10);
  463. }
  464. }
  465. static void intel_dsi_disable(struct intel_encoder *encoder)
  466. {
  467. struct drm_device *dev = encoder->base.dev;
  468. struct drm_i915_private *dev_priv = dev->dev_private;
  469. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  470. enum port port;
  471. u32 temp;
  472. DRM_DEBUG_KMS("\n");
  473. if (is_vid_mode(intel_dsi)) {
  474. for_each_dsi_port(port, intel_dsi->ports)
  475. wait_for_dsi_fifo_empty(intel_dsi, port);
  476. intel_dsi_port_disable(encoder);
  477. msleep(2);
  478. }
  479. for_each_dsi_port(port, intel_dsi->ports) {
  480. /* Panel commands can be sent when clock is in LP11 */
  481. I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
  482. intel_dsi_reset_clocks(encoder, port);
  483. I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
  484. temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
  485. temp &= ~VID_MODE_FORMAT_MASK;
  486. I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
  487. I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
  488. }
  489. /* if disable packets are sent before sending shutdown packet then in
  490. * some next enable sequence send turn on packet error is observed */
  491. drm_panel_disable(intel_dsi->panel);
  492. for_each_dsi_port(port, intel_dsi->ports)
  493. wait_for_dsi_fifo_empty(intel_dsi, port);
  494. }
  495. static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
  496. {
  497. struct drm_device *dev = encoder->base.dev;
  498. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  499. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  500. enum port port;
  501. DRM_DEBUG_KMS("\n");
  502. for_each_dsi_port(port, intel_dsi->ports) {
  503. /* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */
  504. i915_reg_t port_ctrl = IS_BROXTON(dev) ?
  505. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(PORT_A);
  506. u32 val;
  507. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  508. ULPS_STATE_ENTER);
  509. usleep_range(2000, 2500);
  510. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  511. ULPS_STATE_EXIT);
  512. usleep_range(2000, 2500);
  513. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  514. ULPS_STATE_ENTER);
  515. usleep_range(2000, 2500);
  516. /* Wait till Clock lanes are in LP-00 state for MIPI Port A
  517. * only. MIPI Port C has no similar bit for checking
  518. */
  519. if (wait_for(((I915_READ(port_ctrl) & AFE_LATCHOUT)
  520. == 0x00000), 30))
  521. DRM_ERROR("DSI LP not going Low\n");
  522. /* Disable MIPI PHY transparent latch */
  523. val = I915_READ(port_ctrl);
  524. I915_WRITE(port_ctrl, val & ~LP_OUTPUT_HOLD);
  525. usleep_range(1000, 1500);
  526. I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
  527. usleep_range(2000, 2500);
  528. }
  529. intel_disable_dsi_pll(encoder);
  530. }
  531. static void intel_dsi_post_disable(struct intel_encoder *encoder)
  532. {
  533. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  534. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  535. DRM_DEBUG_KMS("\n");
  536. intel_dsi_disable(encoder);
  537. intel_dsi_clear_device_ready(encoder);
  538. if (!IS_BROXTON(dev_priv)) {
  539. u32 val;
  540. val = I915_READ(DSPCLK_GATE_D);
  541. val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
  542. I915_WRITE(DSPCLK_GATE_D, val);
  543. }
  544. drm_panel_unprepare(intel_dsi->panel);
  545. msleep(intel_dsi->panel_off_delay);
  546. msleep(intel_dsi->panel_pwr_cycle_delay);
  547. /* Panel Disable over CRC PMIC */
  548. if (intel_dsi->gpio_panel)
  549. gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
  550. }
  551. static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
  552. enum pipe *pipe)
  553. {
  554. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  555. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  556. struct drm_device *dev = encoder->base.dev;
  557. enum intel_display_power_domain power_domain;
  558. enum port port;
  559. bool active = false;
  560. DRM_DEBUG_KMS("\n");
  561. power_domain = intel_display_port_power_domain(encoder);
  562. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  563. return false;
  564. /*
  565. * On Broxton the PLL needs to be enabled with a valid divider
  566. * configuration, otherwise accessing DSI registers will hang the
  567. * machine. See BSpec North Display Engine registers/MIPI[BXT].
  568. */
  569. if (IS_BROXTON(dev_priv) && !intel_dsi_pll_is_enabled(dev_priv))
  570. goto out_put_power;
  571. /* XXX: this only works for one DSI output */
  572. for_each_dsi_port(port, intel_dsi->ports) {
  573. i915_reg_t ctrl_reg = IS_BROXTON(dev) ?
  574. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  575. bool enabled = I915_READ(ctrl_reg) & DPI_ENABLE;
  576. /* Due to some hardware limitations on BYT, MIPI Port C DPI
  577. * Enable bit does not get set. To check whether DSI Port C
  578. * was enabled in BIOS, check the Pipe B enable bit
  579. */
  580. if (IS_VALLEYVIEW(dev) && port == PORT_C)
  581. enabled = I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
  582. /* Try command mode if video mode not enabled */
  583. if (!enabled) {
  584. u32 tmp = I915_READ(MIPI_DSI_FUNC_PRG(port));
  585. enabled = tmp & CMD_MODE_DATA_WIDTH_MASK;
  586. }
  587. if (!enabled)
  588. continue;
  589. if (!(I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY))
  590. continue;
  591. if (IS_BROXTON(dev_priv)) {
  592. u32 tmp = I915_READ(MIPI_CTRL(port));
  593. tmp &= BXT_PIPE_SELECT_MASK;
  594. tmp >>= BXT_PIPE_SELECT_SHIFT;
  595. if (WARN_ON(tmp > PIPE_C))
  596. continue;
  597. *pipe = tmp;
  598. } else {
  599. *pipe = port == PORT_A ? PIPE_A : PIPE_B;
  600. }
  601. active = true;
  602. break;
  603. }
  604. out_put_power:
  605. intel_display_power_put(dev_priv, power_domain);
  606. return active;
  607. }
  608. static void bxt_dsi_get_pipe_config(struct intel_encoder *encoder,
  609. struct intel_crtc_state *pipe_config)
  610. {
  611. struct drm_device *dev = encoder->base.dev;
  612. struct drm_i915_private *dev_priv = dev->dev_private;
  613. struct drm_display_mode *adjusted_mode =
  614. &pipe_config->base.adjusted_mode;
  615. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  616. unsigned int bpp, fmt;
  617. enum port port;
  618. u16 vfp, vsync, vbp;
  619. /*
  620. * Atleast one port is active as encoder->get_config called only if
  621. * encoder->get_hw_state() returns true.
  622. */
  623. for_each_dsi_port(port, intel_dsi->ports) {
  624. if (I915_READ(BXT_MIPI_PORT_CTRL(port)) & DPI_ENABLE)
  625. break;
  626. }
  627. fmt = I915_READ(MIPI_DSI_FUNC_PRG(port)) & VID_MODE_FORMAT_MASK;
  628. pipe_config->pipe_bpp =
  629. mipi_dsi_pixel_format_to_bpp(
  630. pixel_format_from_register_bits(fmt));
  631. bpp = pipe_config->pipe_bpp;
  632. /* In terms of pixels */
  633. adjusted_mode->crtc_hdisplay =
  634. I915_READ(BXT_MIPI_TRANS_HACTIVE(port));
  635. adjusted_mode->crtc_vdisplay =
  636. I915_READ(BXT_MIPI_TRANS_VACTIVE(port));
  637. adjusted_mode->crtc_vtotal =
  638. I915_READ(BXT_MIPI_TRANS_VTOTAL(port));
  639. /*
  640. * TODO: Retrieve hfp, hsync and hbp. Adjust them for dual link and
  641. * calculate hsync_start, hsync_end, htotal and hblank_end
  642. */
  643. /* vertical values are in terms of lines */
  644. vfp = I915_READ(MIPI_VFP_COUNT(port));
  645. vsync = I915_READ(MIPI_VSYNC_PADDING_COUNT(port));
  646. vbp = I915_READ(MIPI_VBP_COUNT(port));
  647. adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hdisplay;
  648. adjusted_mode->crtc_vsync_start =
  649. vfp + adjusted_mode->crtc_vdisplay;
  650. adjusted_mode->crtc_vsync_end =
  651. vsync + adjusted_mode->crtc_vsync_start;
  652. adjusted_mode->crtc_vblank_start = adjusted_mode->crtc_vdisplay;
  653. adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal;
  654. }
  655. static void intel_dsi_get_config(struct intel_encoder *encoder,
  656. struct intel_crtc_state *pipe_config)
  657. {
  658. struct drm_device *dev = encoder->base.dev;
  659. u32 pclk;
  660. DRM_DEBUG_KMS("\n");
  661. pipe_config->has_dsi_encoder = true;
  662. if (IS_BROXTON(dev))
  663. bxt_dsi_get_pipe_config(encoder, pipe_config);
  664. pclk = intel_dsi_get_pclk(encoder, pipe_config->pipe_bpp);
  665. if (!pclk)
  666. return;
  667. pipe_config->base.adjusted_mode.crtc_clock = pclk;
  668. pipe_config->port_clock = pclk;
  669. }
  670. static enum drm_mode_status
  671. intel_dsi_mode_valid(struct drm_connector *connector,
  672. struct drm_display_mode *mode)
  673. {
  674. struct intel_connector *intel_connector = to_intel_connector(connector);
  675. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  676. int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
  677. DRM_DEBUG_KMS("\n");
  678. if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
  679. DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
  680. return MODE_NO_DBLESCAN;
  681. }
  682. if (fixed_mode) {
  683. if (mode->hdisplay > fixed_mode->hdisplay)
  684. return MODE_PANEL;
  685. if (mode->vdisplay > fixed_mode->vdisplay)
  686. return MODE_PANEL;
  687. if (fixed_mode->clock > max_dotclk)
  688. return MODE_CLOCK_HIGH;
  689. }
  690. return MODE_OK;
  691. }
  692. /* return txclkesc cycles in terms of divider and duration in us */
  693. static u16 txclkesc(u32 divider, unsigned int us)
  694. {
  695. switch (divider) {
  696. case ESCAPE_CLOCK_DIVIDER_1:
  697. default:
  698. return 20 * us;
  699. case ESCAPE_CLOCK_DIVIDER_2:
  700. return 10 * us;
  701. case ESCAPE_CLOCK_DIVIDER_4:
  702. return 5 * us;
  703. }
  704. }
  705. /* return pixels in terms of txbyteclkhs */
  706. static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
  707. u16 burst_mode_ratio)
  708. {
  709. return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
  710. 8 * 100), lane_count);
  711. }
  712. static void set_dsi_timings(struct drm_encoder *encoder,
  713. const struct drm_display_mode *adjusted_mode)
  714. {
  715. struct drm_device *dev = encoder->dev;
  716. struct drm_i915_private *dev_priv = dev->dev_private;
  717. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  718. enum port port;
  719. unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
  720. unsigned int lane_count = intel_dsi->lane_count;
  721. u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
  722. hactive = adjusted_mode->crtc_hdisplay;
  723. hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay;
  724. hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
  725. hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end;
  726. if (intel_dsi->dual_link) {
  727. hactive /= 2;
  728. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  729. hactive += intel_dsi->pixel_overlap;
  730. hfp /= 2;
  731. hsync /= 2;
  732. hbp /= 2;
  733. }
  734. vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay;
  735. vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
  736. vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end;
  737. /* horizontal values are in terms of high speed byte clock */
  738. hactive = txbyteclkhs(hactive, bpp, lane_count,
  739. intel_dsi->burst_mode_ratio);
  740. hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  741. hsync = txbyteclkhs(hsync, bpp, lane_count,
  742. intel_dsi->burst_mode_ratio);
  743. hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  744. for_each_dsi_port(port, intel_dsi->ports) {
  745. if (IS_BROXTON(dev)) {
  746. /*
  747. * Program hdisplay and vdisplay on MIPI transcoder.
  748. * This is different from calculated hactive and
  749. * vactive, as they are calculated per channel basis,
  750. * whereas these values should be based on resolution.
  751. */
  752. I915_WRITE(BXT_MIPI_TRANS_HACTIVE(port),
  753. adjusted_mode->crtc_hdisplay);
  754. I915_WRITE(BXT_MIPI_TRANS_VACTIVE(port),
  755. adjusted_mode->crtc_vdisplay);
  756. I915_WRITE(BXT_MIPI_TRANS_VTOTAL(port),
  757. adjusted_mode->crtc_vtotal);
  758. }
  759. I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
  760. I915_WRITE(MIPI_HFP_COUNT(port), hfp);
  761. /* meaningful for video mode non-burst sync pulse mode only,
  762. * can be zero for non-burst sync events and burst modes */
  763. I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
  764. I915_WRITE(MIPI_HBP_COUNT(port), hbp);
  765. /* vertical values are in terms of lines */
  766. I915_WRITE(MIPI_VFP_COUNT(port), vfp);
  767. I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
  768. I915_WRITE(MIPI_VBP_COUNT(port), vbp);
  769. }
  770. }
  771. static u32 pixel_format_to_reg(enum mipi_dsi_pixel_format fmt)
  772. {
  773. switch (fmt) {
  774. case MIPI_DSI_FMT_RGB888:
  775. return VID_MODE_FORMAT_RGB888;
  776. case MIPI_DSI_FMT_RGB666:
  777. return VID_MODE_FORMAT_RGB666;
  778. case MIPI_DSI_FMT_RGB666_PACKED:
  779. return VID_MODE_FORMAT_RGB666_PACKED;
  780. case MIPI_DSI_FMT_RGB565:
  781. return VID_MODE_FORMAT_RGB565;
  782. default:
  783. MISSING_CASE(fmt);
  784. return VID_MODE_FORMAT_RGB666;
  785. }
  786. }
  787. static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
  788. {
  789. struct drm_encoder *encoder = &intel_encoder->base;
  790. struct drm_device *dev = encoder->dev;
  791. struct drm_i915_private *dev_priv = dev->dev_private;
  792. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  793. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  794. const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
  795. enum port port;
  796. unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
  797. u32 val, tmp;
  798. u16 mode_hdisplay;
  799. DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
  800. mode_hdisplay = adjusted_mode->crtc_hdisplay;
  801. if (intel_dsi->dual_link) {
  802. mode_hdisplay /= 2;
  803. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  804. mode_hdisplay += intel_dsi->pixel_overlap;
  805. }
  806. for_each_dsi_port(port, intel_dsi->ports) {
  807. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  808. /*
  809. * escape clock divider, 20MHz, shared for A and C.
  810. * device ready must be off when doing this! txclkesc?
  811. */
  812. tmp = I915_READ(MIPI_CTRL(PORT_A));
  813. tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  814. I915_WRITE(MIPI_CTRL(PORT_A), tmp |
  815. ESCAPE_CLOCK_DIVIDER_1);
  816. /* read request priority is per pipe */
  817. tmp = I915_READ(MIPI_CTRL(port));
  818. tmp &= ~READ_REQUEST_PRIORITY_MASK;
  819. I915_WRITE(MIPI_CTRL(port), tmp |
  820. READ_REQUEST_PRIORITY_HIGH);
  821. } else if (IS_BROXTON(dev)) {
  822. enum pipe pipe = intel_crtc->pipe;
  823. tmp = I915_READ(MIPI_CTRL(port));
  824. tmp &= ~BXT_PIPE_SELECT_MASK;
  825. tmp |= BXT_PIPE_SELECT(pipe);
  826. I915_WRITE(MIPI_CTRL(port), tmp);
  827. }
  828. /* XXX: why here, why like this? handling in irq handler?! */
  829. I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
  830. I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
  831. I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
  832. I915_WRITE(MIPI_DPI_RESOLUTION(port),
  833. adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT |
  834. mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
  835. }
  836. set_dsi_timings(encoder, adjusted_mode);
  837. val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
  838. if (is_cmd_mode(intel_dsi)) {
  839. val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
  840. val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
  841. } else {
  842. val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
  843. val |= pixel_format_to_reg(intel_dsi->pixel_format);
  844. }
  845. tmp = 0;
  846. if (intel_dsi->eotp_pkt == 0)
  847. tmp |= EOT_DISABLE;
  848. if (intel_dsi->clock_stop)
  849. tmp |= CLOCKSTOP;
  850. for_each_dsi_port(port, intel_dsi->ports) {
  851. I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
  852. /* timeouts for recovery. one frame IIUC. if counter expires,
  853. * EOT and stop state. */
  854. /*
  855. * In burst mode, value greater than one DPI line Time in byte
  856. * clock (txbyteclkhs) To timeout this timer 1+ of the above
  857. * said value is recommended.
  858. *
  859. * In non-burst mode, Value greater than one DPI frame time in
  860. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  861. * said value is recommended.
  862. *
  863. * In DBI only mode, value greater than one DBI frame time in
  864. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  865. * said value is recommended.
  866. */
  867. if (is_vid_mode(intel_dsi) &&
  868. intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
  869. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  870. txbyteclkhs(adjusted_mode->crtc_htotal, bpp,
  871. intel_dsi->lane_count,
  872. intel_dsi->burst_mode_ratio) + 1);
  873. } else {
  874. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  875. txbyteclkhs(adjusted_mode->crtc_vtotal *
  876. adjusted_mode->crtc_htotal,
  877. bpp, intel_dsi->lane_count,
  878. intel_dsi->burst_mode_ratio) + 1);
  879. }
  880. I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
  881. I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
  882. intel_dsi->turn_arnd_val);
  883. I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
  884. intel_dsi->rst_timer_val);
  885. /* dphy stuff */
  886. /* in terms of low power clock */
  887. I915_WRITE(MIPI_INIT_COUNT(port),
  888. txclkesc(intel_dsi->escape_clk_div, 100));
  889. if (IS_BROXTON(dev) && (!intel_dsi->dual_link)) {
  890. /*
  891. * BXT spec says write MIPI_INIT_COUNT for
  892. * both the ports, even if only one is
  893. * getting used. So write the other port
  894. * if not in dual link mode.
  895. */
  896. I915_WRITE(MIPI_INIT_COUNT(port ==
  897. PORT_A ? PORT_C : PORT_A),
  898. intel_dsi->init_count);
  899. }
  900. /* recovery disables */
  901. I915_WRITE(MIPI_EOT_DISABLE(port), tmp);
  902. /* in terms of low power clock */
  903. I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
  904. /* in terms of txbyteclkhs. actual high to low switch +
  905. * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
  906. *
  907. * XXX: write MIPI_STOP_STATE_STALL?
  908. */
  909. I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
  910. intel_dsi->hs_to_lp_count);
  911. /* XXX: low power clock equivalence in terms of byte clock.
  912. * the number of byte clocks occupied in one low power clock.
  913. * based on txbyteclkhs and txclkesc.
  914. * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
  915. * ) / 105.???
  916. */
  917. I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
  918. /* the bw essential for transmitting 16 long packets containing
  919. * 252 bytes meant for dcs write memory command is programmed in
  920. * this register in terms of byte clocks. based on dsi transfer
  921. * rate and the number of lanes configured the time taken to
  922. * transmit 16 long packets in a dsi stream varies. */
  923. I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
  924. I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
  925. intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
  926. intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
  927. if (is_vid_mode(intel_dsi))
  928. /* Some panels might have resolution which is not a
  929. * multiple of 64 like 1366 x 768. Enable RANDOM
  930. * resolution support for such panels by default */
  931. I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
  932. intel_dsi->video_frmt_cfg_bits |
  933. intel_dsi->video_mode_format |
  934. IP_TG_CONFIG |
  935. RANDOM_DPI_DISPLAY_RESOLUTION);
  936. }
  937. }
  938. static enum drm_connector_status
  939. intel_dsi_detect(struct drm_connector *connector, bool force)
  940. {
  941. return connector_status_connected;
  942. }
  943. static int intel_dsi_get_modes(struct drm_connector *connector)
  944. {
  945. struct intel_connector *intel_connector = to_intel_connector(connector);
  946. struct drm_display_mode *mode;
  947. DRM_DEBUG_KMS("\n");
  948. if (!intel_connector->panel.fixed_mode) {
  949. DRM_DEBUG_KMS("no fixed mode\n");
  950. return 0;
  951. }
  952. mode = drm_mode_duplicate(connector->dev,
  953. intel_connector->panel.fixed_mode);
  954. if (!mode) {
  955. DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
  956. return 0;
  957. }
  958. drm_mode_probed_add(connector, mode);
  959. return 1;
  960. }
  961. static void intel_dsi_connector_destroy(struct drm_connector *connector)
  962. {
  963. struct intel_connector *intel_connector = to_intel_connector(connector);
  964. DRM_DEBUG_KMS("\n");
  965. intel_panel_fini(&intel_connector->panel);
  966. drm_connector_cleanup(connector);
  967. kfree(connector);
  968. }
  969. static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
  970. {
  971. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  972. if (intel_dsi->panel) {
  973. drm_panel_detach(intel_dsi->panel);
  974. /* XXX: Logically this call belongs in the panel driver. */
  975. drm_panel_remove(intel_dsi->panel);
  976. }
  977. /* dispose of the gpios */
  978. if (intel_dsi->gpio_panel)
  979. gpiod_put(intel_dsi->gpio_panel);
  980. intel_encoder_destroy(encoder);
  981. }
  982. static const struct drm_encoder_funcs intel_dsi_funcs = {
  983. .destroy = intel_dsi_encoder_destroy,
  984. };
  985. static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
  986. .get_modes = intel_dsi_get_modes,
  987. .mode_valid = intel_dsi_mode_valid,
  988. .best_encoder = intel_best_encoder,
  989. };
  990. static const struct drm_connector_funcs intel_dsi_connector_funcs = {
  991. .dpms = drm_atomic_helper_connector_dpms,
  992. .detect = intel_dsi_detect,
  993. .destroy = intel_dsi_connector_destroy,
  994. .fill_modes = drm_helper_probe_single_connector_modes,
  995. .atomic_get_property = intel_connector_atomic_get_property,
  996. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  997. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  998. };
  999. void intel_dsi_init(struct drm_device *dev)
  1000. {
  1001. struct intel_dsi *intel_dsi;
  1002. struct intel_encoder *intel_encoder;
  1003. struct drm_encoder *encoder;
  1004. struct intel_connector *intel_connector;
  1005. struct drm_connector *connector;
  1006. struct drm_display_mode *scan, *fixed_mode = NULL;
  1007. struct drm_i915_private *dev_priv = dev->dev_private;
  1008. enum port port;
  1009. unsigned int i;
  1010. DRM_DEBUG_KMS("\n");
  1011. /* There is no detection method for MIPI so rely on VBT */
  1012. if (!intel_bios_is_dsi_present(dev_priv, &port))
  1013. return;
  1014. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  1015. dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
  1016. } else if (IS_BROXTON(dev)) {
  1017. dev_priv->mipi_mmio_base = BXT_MIPI_BASE;
  1018. } else {
  1019. DRM_ERROR("Unsupported Mipi device to reg base");
  1020. return;
  1021. }
  1022. intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
  1023. if (!intel_dsi)
  1024. return;
  1025. intel_connector = intel_connector_alloc();
  1026. if (!intel_connector) {
  1027. kfree(intel_dsi);
  1028. return;
  1029. }
  1030. intel_encoder = &intel_dsi->base;
  1031. encoder = &intel_encoder->base;
  1032. intel_dsi->attached_connector = intel_connector;
  1033. connector = &intel_connector->base;
  1034. drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI,
  1035. NULL);
  1036. intel_encoder->compute_config = intel_dsi_compute_config;
  1037. intel_encoder->pre_enable = intel_dsi_pre_enable;
  1038. intel_encoder->enable = intel_dsi_enable_nop;
  1039. intel_encoder->disable = intel_dsi_pre_disable;
  1040. intel_encoder->post_disable = intel_dsi_post_disable;
  1041. intel_encoder->get_hw_state = intel_dsi_get_hw_state;
  1042. intel_encoder->get_config = intel_dsi_get_config;
  1043. intel_connector->get_hw_state = intel_connector_get_hw_state;
  1044. intel_connector->unregister = intel_connector_unregister;
  1045. /*
  1046. * On BYT/CHV, pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI
  1047. * port C. BXT isn't limited like this.
  1048. */
  1049. if (IS_BROXTON(dev_priv))
  1050. intel_encoder->crtc_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C);
  1051. else if (port == PORT_A)
  1052. intel_encoder->crtc_mask = BIT(PIPE_A);
  1053. else
  1054. intel_encoder->crtc_mask = BIT(PIPE_B);
  1055. if (dev_priv->vbt.dsi.config->dual_link)
  1056. intel_dsi->ports = BIT(PORT_A) | BIT(PORT_C);
  1057. else
  1058. intel_dsi->ports = BIT(port);
  1059. /* Create a DSI host (and a device) for each port. */
  1060. for_each_dsi_port(port, intel_dsi->ports) {
  1061. struct intel_dsi_host *host;
  1062. host = intel_dsi_host_init(intel_dsi, port);
  1063. if (!host)
  1064. goto err;
  1065. intel_dsi->dsi_hosts[port] = host;
  1066. }
  1067. for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) {
  1068. intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi,
  1069. intel_dsi_drivers[i].panel_id);
  1070. if (intel_dsi->panel)
  1071. break;
  1072. }
  1073. if (!intel_dsi->panel) {
  1074. DRM_DEBUG_KMS("no device found\n");
  1075. goto err;
  1076. }
  1077. /*
  1078. * In case of BYT with CRC PMIC, we need to use GPIO for
  1079. * Panel control.
  1080. */
  1081. if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) {
  1082. intel_dsi->gpio_panel =
  1083. gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH);
  1084. if (IS_ERR(intel_dsi->gpio_panel)) {
  1085. DRM_ERROR("Failed to own gpio for panel control\n");
  1086. intel_dsi->gpio_panel = NULL;
  1087. }
  1088. }
  1089. intel_encoder->type = INTEL_OUTPUT_DSI;
  1090. intel_encoder->cloneable = 0;
  1091. drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
  1092. DRM_MODE_CONNECTOR_DSI);
  1093. drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
  1094. connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
  1095. connector->interlace_allowed = false;
  1096. connector->doublescan_allowed = false;
  1097. intel_connector_attach_encoder(intel_connector, intel_encoder);
  1098. drm_connector_register(connector);
  1099. drm_panel_attach(intel_dsi->panel, connector);
  1100. mutex_lock(&dev->mode_config.mutex);
  1101. drm_panel_get_modes(intel_dsi->panel);
  1102. list_for_each_entry(scan, &connector->probed_modes, head) {
  1103. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  1104. fixed_mode = drm_mode_duplicate(dev, scan);
  1105. break;
  1106. }
  1107. }
  1108. mutex_unlock(&dev->mode_config.mutex);
  1109. if (!fixed_mode) {
  1110. DRM_DEBUG_KMS("no fixed mode\n");
  1111. goto err;
  1112. }
  1113. intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
  1114. intel_panel_setup_backlight(connector, INVALID_PIPE);
  1115. return;
  1116. err:
  1117. drm_encoder_cleanup(&intel_encoder->base);
  1118. kfree(intel_dsi);
  1119. kfree(intel_connector);
  1120. }