intel_dsi.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454
  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 intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
  246. const struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  247. struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  248. int ret;
  249. DRM_DEBUG_KMS("\n");
  250. pipe_config->has_dsi_encoder = true;
  251. if (fixed_mode) {
  252. intel_fixed_panel_mode(fixed_mode, adjusted_mode);
  253. if (HAS_GMCH_DISPLAY(dev_priv))
  254. intel_gmch_panel_fitting(crtc, pipe_config,
  255. intel_connector->panel.fitting_mode);
  256. else
  257. intel_pch_panel_fitting(crtc, pipe_config,
  258. intel_connector->panel.fitting_mode);
  259. }
  260. /* DSI uses short packets for sync events, so clear mode flags for DSI */
  261. adjusted_mode->flags = 0;
  262. if (IS_BROXTON(dev_priv)) {
  263. /* Dual link goes to DSI transcoder A. */
  264. if (intel_dsi->ports == BIT(PORT_C))
  265. pipe_config->cpu_transcoder = TRANSCODER_DSI_C;
  266. else
  267. pipe_config->cpu_transcoder = TRANSCODER_DSI_A;
  268. }
  269. ret = intel_compute_dsi_pll(encoder, pipe_config);
  270. if (ret)
  271. return false;
  272. pipe_config->clock_set = true;
  273. return true;
  274. }
  275. static void bxt_dsi_device_ready(struct intel_encoder *encoder)
  276. {
  277. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  278. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  279. enum port port;
  280. u32 val;
  281. DRM_DEBUG_KMS("\n");
  282. /* Exit Low power state in 4 steps*/
  283. for_each_dsi_port(port, intel_dsi->ports) {
  284. /* 1. Enable MIPI PHY transparent latch */
  285. val = I915_READ(BXT_MIPI_PORT_CTRL(port));
  286. I915_WRITE(BXT_MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD);
  287. usleep_range(2000, 2500);
  288. /* 2. Enter ULPS */
  289. val = I915_READ(MIPI_DEVICE_READY(port));
  290. val &= ~ULPS_STATE_MASK;
  291. val |= (ULPS_STATE_ENTER | DEVICE_READY);
  292. I915_WRITE(MIPI_DEVICE_READY(port), val);
  293. usleep_range(2, 3);
  294. /* 3. Exit ULPS */
  295. val = I915_READ(MIPI_DEVICE_READY(port));
  296. val &= ~ULPS_STATE_MASK;
  297. val |= (ULPS_STATE_EXIT | DEVICE_READY);
  298. I915_WRITE(MIPI_DEVICE_READY(port), val);
  299. usleep_range(1000, 1500);
  300. /* Clear ULPS and set device ready */
  301. val = I915_READ(MIPI_DEVICE_READY(port));
  302. val &= ~ULPS_STATE_MASK;
  303. val |= DEVICE_READY;
  304. I915_WRITE(MIPI_DEVICE_READY(port), val);
  305. }
  306. }
  307. static void vlv_dsi_device_ready(struct intel_encoder *encoder)
  308. {
  309. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  310. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  311. enum port port;
  312. u32 val;
  313. DRM_DEBUG_KMS("\n");
  314. mutex_lock(&dev_priv->sb_lock);
  315. /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
  316. * needed everytime after power gate */
  317. vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
  318. mutex_unlock(&dev_priv->sb_lock);
  319. /* bandgap reset is needed after everytime we do power gate */
  320. band_gap_reset(dev_priv);
  321. for_each_dsi_port(port, intel_dsi->ports) {
  322. I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
  323. usleep_range(2500, 3000);
  324. /* Enable MIPI PHY transparent latch
  325. * Common bit for both MIPI Port A & MIPI Port C
  326. * No similar bit in MIPI Port C reg
  327. */
  328. val = I915_READ(MIPI_PORT_CTRL(PORT_A));
  329. I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
  330. usleep_range(1000, 1500);
  331. I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
  332. usleep_range(2500, 3000);
  333. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
  334. usleep_range(2500, 3000);
  335. }
  336. }
  337. static void intel_dsi_device_ready(struct intel_encoder *encoder)
  338. {
  339. struct drm_device *dev = encoder->base.dev;
  340. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  341. vlv_dsi_device_ready(encoder);
  342. else if (IS_BROXTON(dev))
  343. bxt_dsi_device_ready(encoder);
  344. }
  345. static void intel_dsi_port_enable(struct intel_encoder *encoder)
  346. {
  347. struct drm_device *dev = encoder->base.dev;
  348. struct drm_i915_private *dev_priv = dev->dev_private;
  349. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  350. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  351. enum port port;
  352. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
  353. u32 temp;
  354. temp = I915_READ(VLV_CHICKEN_3);
  355. temp &= ~PIXEL_OVERLAP_CNT_MASK |
  356. intel_dsi->pixel_overlap <<
  357. PIXEL_OVERLAP_CNT_SHIFT;
  358. I915_WRITE(VLV_CHICKEN_3, temp);
  359. }
  360. for_each_dsi_port(port, intel_dsi->ports) {
  361. i915_reg_t port_ctrl = IS_BROXTON(dev) ?
  362. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  363. u32 temp;
  364. temp = I915_READ(port_ctrl);
  365. temp &= ~LANE_CONFIGURATION_MASK;
  366. temp &= ~DUAL_LINK_MODE_MASK;
  367. if (intel_dsi->ports == (BIT(PORT_A) | BIT(PORT_C))) {
  368. temp |= (intel_dsi->dual_link - 1)
  369. << DUAL_LINK_MODE_SHIFT;
  370. temp |= intel_crtc->pipe ?
  371. LANE_CONFIGURATION_DUAL_LINK_B :
  372. LANE_CONFIGURATION_DUAL_LINK_A;
  373. }
  374. /* assert ip_tg_enable signal */
  375. I915_WRITE(port_ctrl, temp | DPI_ENABLE);
  376. POSTING_READ(port_ctrl);
  377. }
  378. }
  379. static void intel_dsi_port_disable(struct intel_encoder *encoder)
  380. {
  381. struct drm_device *dev = encoder->base.dev;
  382. struct drm_i915_private *dev_priv = dev->dev_private;
  383. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  384. enum port port;
  385. for_each_dsi_port(port, intel_dsi->ports) {
  386. i915_reg_t port_ctrl = IS_BROXTON(dev) ?
  387. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  388. u32 temp;
  389. /* de-assert ip_tg_enable signal */
  390. temp = I915_READ(port_ctrl);
  391. I915_WRITE(port_ctrl, temp & ~DPI_ENABLE);
  392. POSTING_READ(port_ctrl);
  393. }
  394. }
  395. static void intel_dsi_enable(struct intel_encoder *encoder)
  396. {
  397. struct drm_device *dev = encoder->base.dev;
  398. struct drm_i915_private *dev_priv = dev->dev_private;
  399. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  400. enum port port;
  401. DRM_DEBUG_KMS("\n");
  402. if (is_cmd_mode(intel_dsi)) {
  403. for_each_dsi_port(port, intel_dsi->ports)
  404. I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
  405. } else {
  406. msleep(20); /* XXX */
  407. for_each_dsi_port(port, intel_dsi->ports)
  408. dpi_send_cmd(intel_dsi, TURN_ON, false, port);
  409. msleep(100);
  410. drm_panel_enable(intel_dsi->panel);
  411. for_each_dsi_port(port, intel_dsi->ports)
  412. wait_for_dsi_fifo_empty(intel_dsi, port);
  413. intel_dsi_port_enable(encoder);
  414. }
  415. intel_panel_enable_backlight(intel_dsi->attached_connector);
  416. }
  417. static void intel_dsi_prepare(struct intel_encoder *intel_encoder);
  418. static void intel_dsi_pre_enable(struct intel_encoder *encoder)
  419. {
  420. struct drm_device *dev = encoder->base.dev;
  421. struct drm_i915_private *dev_priv = dev->dev_private;
  422. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  423. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  424. enum port port;
  425. DRM_DEBUG_KMS("\n");
  426. /*
  427. * The BIOS may leave the PLL in a wonky state where it doesn't
  428. * lock. It needs to be fully powered down to fix it.
  429. */
  430. intel_disable_dsi_pll(encoder);
  431. intel_enable_dsi_pll(encoder, crtc->config);
  432. intel_dsi_prepare(encoder);
  433. /* Panel Enable over CRC PMIC */
  434. if (intel_dsi->gpio_panel)
  435. gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
  436. msleep(intel_dsi->panel_on_delay);
  437. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  438. u32 val;
  439. /* Disable DPOunit clock gating, can stall pipe */
  440. val = I915_READ(DSPCLK_GATE_D);
  441. val |= DPOUNIT_CLOCK_GATE_DISABLE;
  442. I915_WRITE(DSPCLK_GATE_D, val);
  443. }
  444. /* put device in ready state */
  445. intel_dsi_device_ready(encoder);
  446. drm_panel_prepare(intel_dsi->panel);
  447. for_each_dsi_port(port, intel_dsi->ports)
  448. wait_for_dsi_fifo_empty(intel_dsi, port);
  449. /* Enable port in pre-enable phase itself because as per hw team
  450. * recommendation, port should be enabled befor plane & pipe */
  451. intel_dsi_enable(encoder);
  452. }
  453. static void intel_dsi_enable_nop(struct intel_encoder *encoder)
  454. {
  455. DRM_DEBUG_KMS("\n");
  456. /* for DSI port enable has to be done before pipe
  457. * and plane enable, so port enable is done in
  458. * pre_enable phase itself unlike other encoders
  459. */
  460. }
  461. static void intel_dsi_pre_disable(struct intel_encoder *encoder)
  462. {
  463. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  464. enum port port;
  465. DRM_DEBUG_KMS("\n");
  466. intel_panel_disable_backlight(intel_dsi->attached_connector);
  467. if (is_vid_mode(intel_dsi)) {
  468. /* Send Shutdown command to the panel in LP mode */
  469. for_each_dsi_port(port, intel_dsi->ports)
  470. dpi_send_cmd(intel_dsi, SHUTDOWN, false, port);
  471. msleep(10);
  472. }
  473. }
  474. static void intel_dsi_disable(struct intel_encoder *encoder)
  475. {
  476. struct drm_device *dev = encoder->base.dev;
  477. struct drm_i915_private *dev_priv = dev->dev_private;
  478. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  479. enum port port;
  480. u32 temp;
  481. DRM_DEBUG_KMS("\n");
  482. if (is_vid_mode(intel_dsi)) {
  483. for_each_dsi_port(port, intel_dsi->ports)
  484. wait_for_dsi_fifo_empty(intel_dsi, port);
  485. intel_dsi_port_disable(encoder);
  486. msleep(2);
  487. }
  488. for_each_dsi_port(port, intel_dsi->ports) {
  489. /* Panel commands can be sent when clock is in LP11 */
  490. I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
  491. intel_dsi_reset_clocks(encoder, port);
  492. I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
  493. temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
  494. temp &= ~VID_MODE_FORMAT_MASK;
  495. I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
  496. I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
  497. }
  498. /* if disable packets are sent before sending shutdown packet then in
  499. * some next enable sequence send turn on packet error is observed */
  500. drm_panel_disable(intel_dsi->panel);
  501. for_each_dsi_port(port, intel_dsi->ports)
  502. wait_for_dsi_fifo_empty(intel_dsi, port);
  503. }
  504. static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
  505. {
  506. struct drm_device *dev = encoder->base.dev;
  507. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  508. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  509. enum port port;
  510. DRM_DEBUG_KMS("\n");
  511. for_each_dsi_port(port, intel_dsi->ports) {
  512. /* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */
  513. i915_reg_t port_ctrl = IS_BROXTON(dev) ?
  514. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(PORT_A);
  515. u32 val;
  516. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  517. ULPS_STATE_ENTER);
  518. usleep_range(2000, 2500);
  519. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  520. ULPS_STATE_EXIT);
  521. usleep_range(2000, 2500);
  522. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  523. ULPS_STATE_ENTER);
  524. usleep_range(2000, 2500);
  525. /* Wait till Clock lanes are in LP-00 state for MIPI Port A
  526. * only. MIPI Port C has no similar bit for checking
  527. */
  528. if (wait_for(((I915_READ(port_ctrl) & AFE_LATCHOUT)
  529. == 0x00000), 30))
  530. DRM_ERROR("DSI LP not going Low\n");
  531. /* Disable MIPI PHY transparent latch */
  532. val = I915_READ(port_ctrl);
  533. I915_WRITE(port_ctrl, val & ~LP_OUTPUT_HOLD);
  534. usleep_range(1000, 1500);
  535. I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
  536. usleep_range(2000, 2500);
  537. }
  538. intel_disable_dsi_pll(encoder);
  539. }
  540. static void intel_dsi_post_disable(struct intel_encoder *encoder)
  541. {
  542. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  543. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  544. DRM_DEBUG_KMS("\n");
  545. intel_dsi_disable(encoder);
  546. intel_dsi_clear_device_ready(encoder);
  547. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  548. u32 val;
  549. val = I915_READ(DSPCLK_GATE_D);
  550. val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
  551. I915_WRITE(DSPCLK_GATE_D, val);
  552. }
  553. drm_panel_unprepare(intel_dsi->panel);
  554. msleep(intel_dsi->panel_off_delay);
  555. /* Panel Disable over CRC PMIC */
  556. if (intel_dsi->gpio_panel)
  557. gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
  558. /*
  559. * FIXME As we do with eDP, just make a note of the time here
  560. * and perform the wait before the next panel power on.
  561. */
  562. msleep(intel_dsi->panel_pwr_cycle_delay);
  563. }
  564. static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
  565. enum pipe *pipe)
  566. {
  567. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  568. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  569. struct drm_device *dev = encoder->base.dev;
  570. enum intel_display_power_domain power_domain;
  571. enum port port;
  572. bool active = false;
  573. DRM_DEBUG_KMS("\n");
  574. power_domain = intel_display_port_power_domain(encoder);
  575. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  576. return false;
  577. /*
  578. * On Broxton the PLL needs to be enabled with a valid divider
  579. * configuration, otherwise accessing DSI registers will hang the
  580. * machine. See BSpec North Display Engine registers/MIPI[BXT].
  581. */
  582. if (IS_BROXTON(dev_priv) && !intel_dsi_pll_is_enabled(dev_priv))
  583. goto out_put_power;
  584. /* XXX: this only works for one DSI output */
  585. for_each_dsi_port(port, intel_dsi->ports) {
  586. i915_reg_t ctrl_reg = IS_BROXTON(dev) ?
  587. BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
  588. bool enabled = I915_READ(ctrl_reg) & DPI_ENABLE;
  589. /*
  590. * Due to some hardware limitations on VLV/CHV, the DPI enable
  591. * bit in port C control register does not get set. As a
  592. * workaround, check pipe B conf instead.
  593. */
  594. if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && port == PORT_C)
  595. enabled = I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
  596. /* Try command mode if video mode not enabled */
  597. if (!enabled) {
  598. u32 tmp = I915_READ(MIPI_DSI_FUNC_PRG(port));
  599. enabled = tmp & CMD_MODE_DATA_WIDTH_MASK;
  600. }
  601. if (!enabled)
  602. continue;
  603. if (!(I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY))
  604. continue;
  605. if (IS_BROXTON(dev_priv)) {
  606. u32 tmp = I915_READ(MIPI_CTRL(port));
  607. tmp &= BXT_PIPE_SELECT_MASK;
  608. tmp >>= BXT_PIPE_SELECT_SHIFT;
  609. if (WARN_ON(tmp > PIPE_C))
  610. continue;
  611. *pipe = tmp;
  612. } else {
  613. *pipe = port == PORT_A ? PIPE_A : PIPE_B;
  614. }
  615. active = true;
  616. break;
  617. }
  618. out_put_power:
  619. intel_display_power_put(dev_priv, power_domain);
  620. return active;
  621. }
  622. static void bxt_dsi_get_pipe_config(struct intel_encoder *encoder,
  623. struct intel_crtc_state *pipe_config)
  624. {
  625. struct drm_device *dev = encoder->base.dev;
  626. struct drm_i915_private *dev_priv = dev->dev_private;
  627. struct drm_display_mode *adjusted_mode =
  628. &pipe_config->base.adjusted_mode;
  629. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  630. unsigned int bpp, fmt;
  631. enum port port;
  632. u16 vfp, vsync, vbp;
  633. /*
  634. * Atleast one port is active as encoder->get_config called only if
  635. * encoder->get_hw_state() returns true.
  636. */
  637. for_each_dsi_port(port, intel_dsi->ports) {
  638. if (I915_READ(BXT_MIPI_PORT_CTRL(port)) & DPI_ENABLE)
  639. break;
  640. }
  641. fmt = I915_READ(MIPI_DSI_FUNC_PRG(port)) & VID_MODE_FORMAT_MASK;
  642. pipe_config->pipe_bpp =
  643. mipi_dsi_pixel_format_to_bpp(
  644. pixel_format_from_register_bits(fmt));
  645. bpp = pipe_config->pipe_bpp;
  646. /* In terms of pixels */
  647. adjusted_mode->crtc_hdisplay =
  648. I915_READ(BXT_MIPI_TRANS_HACTIVE(port));
  649. adjusted_mode->crtc_vdisplay =
  650. I915_READ(BXT_MIPI_TRANS_VACTIVE(port));
  651. adjusted_mode->crtc_vtotal =
  652. I915_READ(BXT_MIPI_TRANS_VTOTAL(port));
  653. /*
  654. * TODO: Retrieve hfp, hsync and hbp. Adjust them for dual link and
  655. * calculate hsync_start, hsync_end, htotal and hblank_end
  656. */
  657. /* vertical values are in terms of lines */
  658. vfp = I915_READ(MIPI_VFP_COUNT(port));
  659. vsync = I915_READ(MIPI_VSYNC_PADDING_COUNT(port));
  660. vbp = I915_READ(MIPI_VBP_COUNT(port));
  661. adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hdisplay;
  662. adjusted_mode->crtc_vsync_start =
  663. vfp + adjusted_mode->crtc_vdisplay;
  664. adjusted_mode->crtc_vsync_end =
  665. vsync + adjusted_mode->crtc_vsync_start;
  666. adjusted_mode->crtc_vblank_start = adjusted_mode->crtc_vdisplay;
  667. adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal;
  668. }
  669. static void intel_dsi_get_config(struct intel_encoder *encoder,
  670. struct intel_crtc_state *pipe_config)
  671. {
  672. struct drm_device *dev = encoder->base.dev;
  673. u32 pclk;
  674. DRM_DEBUG_KMS("\n");
  675. pipe_config->has_dsi_encoder = true;
  676. if (IS_BROXTON(dev))
  677. bxt_dsi_get_pipe_config(encoder, pipe_config);
  678. pclk = intel_dsi_get_pclk(encoder, pipe_config->pipe_bpp,
  679. pipe_config);
  680. if (!pclk)
  681. return;
  682. pipe_config->base.adjusted_mode.crtc_clock = pclk;
  683. pipe_config->port_clock = pclk;
  684. }
  685. static enum drm_mode_status
  686. intel_dsi_mode_valid(struct drm_connector *connector,
  687. struct drm_display_mode *mode)
  688. {
  689. struct intel_connector *intel_connector = to_intel_connector(connector);
  690. const struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  691. int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
  692. DRM_DEBUG_KMS("\n");
  693. if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
  694. DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
  695. return MODE_NO_DBLESCAN;
  696. }
  697. if (fixed_mode) {
  698. if (mode->hdisplay > fixed_mode->hdisplay)
  699. return MODE_PANEL;
  700. if (mode->vdisplay > fixed_mode->vdisplay)
  701. return MODE_PANEL;
  702. if (fixed_mode->clock > max_dotclk)
  703. return MODE_CLOCK_HIGH;
  704. }
  705. return MODE_OK;
  706. }
  707. /* return txclkesc cycles in terms of divider and duration in us */
  708. static u16 txclkesc(u32 divider, unsigned int us)
  709. {
  710. switch (divider) {
  711. case ESCAPE_CLOCK_DIVIDER_1:
  712. default:
  713. return 20 * us;
  714. case ESCAPE_CLOCK_DIVIDER_2:
  715. return 10 * us;
  716. case ESCAPE_CLOCK_DIVIDER_4:
  717. return 5 * us;
  718. }
  719. }
  720. /* return pixels in terms of txbyteclkhs */
  721. static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
  722. u16 burst_mode_ratio)
  723. {
  724. return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
  725. 8 * 100), lane_count);
  726. }
  727. static void set_dsi_timings(struct drm_encoder *encoder,
  728. const struct drm_display_mode *adjusted_mode)
  729. {
  730. struct drm_device *dev = encoder->dev;
  731. struct drm_i915_private *dev_priv = dev->dev_private;
  732. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  733. enum port port;
  734. unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
  735. unsigned int lane_count = intel_dsi->lane_count;
  736. u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
  737. hactive = adjusted_mode->crtc_hdisplay;
  738. hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay;
  739. hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
  740. hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end;
  741. if (intel_dsi->dual_link) {
  742. hactive /= 2;
  743. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  744. hactive += intel_dsi->pixel_overlap;
  745. hfp /= 2;
  746. hsync /= 2;
  747. hbp /= 2;
  748. }
  749. vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay;
  750. vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
  751. vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end;
  752. /* horizontal values are in terms of high speed byte clock */
  753. hactive = txbyteclkhs(hactive, bpp, lane_count,
  754. intel_dsi->burst_mode_ratio);
  755. hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  756. hsync = txbyteclkhs(hsync, bpp, lane_count,
  757. intel_dsi->burst_mode_ratio);
  758. hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  759. for_each_dsi_port(port, intel_dsi->ports) {
  760. if (IS_BROXTON(dev)) {
  761. /*
  762. * Program hdisplay and vdisplay on MIPI transcoder.
  763. * This is different from calculated hactive and
  764. * vactive, as they are calculated per channel basis,
  765. * whereas these values should be based on resolution.
  766. */
  767. I915_WRITE(BXT_MIPI_TRANS_HACTIVE(port),
  768. adjusted_mode->crtc_hdisplay);
  769. I915_WRITE(BXT_MIPI_TRANS_VACTIVE(port),
  770. adjusted_mode->crtc_vdisplay);
  771. I915_WRITE(BXT_MIPI_TRANS_VTOTAL(port),
  772. adjusted_mode->crtc_vtotal);
  773. }
  774. I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
  775. I915_WRITE(MIPI_HFP_COUNT(port), hfp);
  776. /* meaningful for video mode non-burst sync pulse mode only,
  777. * can be zero for non-burst sync events and burst modes */
  778. I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
  779. I915_WRITE(MIPI_HBP_COUNT(port), hbp);
  780. /* vertical values are in terms of lines */
  781. I915_WRITE(MIPI_VFP_COUNT(port), vfp);
  782. I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
  783. I915_WRITE(MIPI_VBP_COUNT(port), vbp);
  784. }
  785. }
  786. static u32 pixel_format_to_reg(enum mipi_dsi_pixel_format fmt)
  787. {
  788. switch (fmt) {
  789. case MIPI_DSI_FMT_RGB888:
  790. return VID_MODE_FORMAT_RGB888;
  791. case MIPI_DSI_FMT_RGB666:
  792. return VID_MODE_FORMAT_RGB666;
  793. case MIPI_DSI_FMT_RGB666_PACKED:
  794. return VID_MODE_FORMAT_RGB666_PACKED;
  795. case MIPI_DSI_FMT_RGB565:
  796. return VID_MODE_FORMAT_RGB565;
  797. default:
  798. MISSING_CASE(fmt);
  799. return VID_MODE_FORMAT_RGB666;
  800. }
  801. }
  802. static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
  803. {
  804. struct drm_encoder *encoder = &intel_encoder->base;
  805. struct drm_device *dev = encoder->dev;
  806. struct drm_i915_private *dev_priv = dev->dev_private;
  807. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  808. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  809. const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
  810. enum port port;
  811. unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
  812. u32 val, tmp;
  813. u16 mode_hdisplay;
  814. DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
  815. mode_hdisplay = adjusted_mode->crtc_hdisplay;
  816. if (intel_dsi->dual_link) {
  817. mode_hdisplay /= 2;
  818. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  819. mode_hdisplay += intel_dsi->pixel_overlap;
  820. }
  821. for_each_dsi_port(port, intel_dsi->ports) {
  822. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  823. /*
  824. * escape clock divider, 20MHz, shared for A and C.
  825. * device ready must be off when doing this! txclkesc?
  826. */
  827. tmp = I915_READ(MIPI_CTRL(PORT_A));
  828. tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  829. I915_WRITE(MIPI_CTRL(PORT_A), tmp |
  830. ESCAPE_CLOCK_DIVIDER_1);
  831. /* read request priority is per pipe */
  832. tmp = I915_READ(MIPI_CTRL(port));
  833. tmp &= ~READ_REQUEST_PRIORITY_MASK;
  834. I915_WRITE(MIPI_CTRL(port), tmp |
  835. READ_REQUEST_PRIORITY_HIGH);
  836. } else if (IS_BROXTON(dev)) {
  837. enum pipe pipe = intel_crtc->pipe;
  838. tmp = I915_READ(MIPI_CTRL(port));
  839. tmp &= ~BXT_PIPE_SELECT_MASK;
  840. tmp |= BXT_PIPE_SELECT(pipe);
  841. I915_WRITE(MIPI_CTRL(port), tmp);
  842. }
  843. /* XXX: why here, why like this? handling in irq handler?! */
  844. I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
  845. I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
  846. I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
  847. I915_WRITE(MIPI_DPI_RESOLUTION(port),
  848. adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT |
  849. mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
  850. }
  851. set_dsi_timings(encoder, adjusted_mode);
  852. val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
  853. if (is_cmd_mode(intel_dsi)) {
  854. val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
  855. val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
  856. } else {
  857. val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
  858. val |= pixel_format_to_reg(intel_dsi->pixel_format);
  859. }
  860. tmp = 0;
  861. if (intel_dsi->eotp_pkt == 0)
  862. tmp |= EOT_DISABLE;
  863. if (intel_dsi->clock_stop)
  864. tmp |= CLOCKSTOP;
  865. for_each_dsi_port(port, intel_dsi->ports) {
  866. I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
  867. /* timeouts for recovery. one frame IIUC. if counter expires,
  868. * EOT and stop state. */
  869. /*
  870. * In burst mode, value greater than one DPI line Time in byte
  871. * clock (txbyteclkhs) To timeout this timer 1+ of the above
  872. * said value is recommended.
  873. *
  874. * In non-burst mode, Value greater than one DPI frame time in
  875. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  876. * said value is recommended.
  877. *
  878. * In DBI only mode, value greater than one DBI frame time in
  879. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  880. * said value is recommended.
  881. */
  882. if (is_vid_mode(intel_dsi) &&
  883. intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
  884. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  885. txbyteclkhs(adjusted_mode->crtc_htotal, bpp,
  886. intel_dsi->lane_count,
  887. intel_dsi->burst_mode_ratio) + 1);
  888. } else {
  889. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  890. txbyteclkhs(adjusted_mode->crtc_vtotal *
  891. adjusted_mode->crtc_htotal,
  892. bpp, intel_dsi->lane_count,
  893. intel_dsi->burst_mode_ratio) + 1);
  894. }
  895. I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
  896. I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
  897. intel_dsi->turn_arnd_val);
  898. I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
  899. intel_dsi->rst_timer_val);
  900. /* dphy stuff */
  901. /* in terms of low power clock */
  902. I915_WRITE(MIPI_INIT_COUNT(port),
  903. txclkesc(intel_dsi->escape_clk_div, 100));
  904. if (IS_BROXTON(dev) && (!intel_dsi->dual_link)) {
  905. /*
  906. * BXT spec says write MIPI_INIT_COUNT for
  907. * both the ports, even if only one is
  908. * getting used. So write the other port
  909. * if not in dual link mode.
  910. */
  911. I915_WRITE(MIPI_INIT_COUNT(port ==
  912. PORT_A ? PORT_C : PORT_A),
  913. intel_dsi->init_count);
  914. }
  915. /* recovery disables */
  916. I915_WRITE(MIPI_EOT_DISABLE(port), tmp);
  917. /* in terms of low power clock */
  918. I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
  919. /* in terms of txbyteclkhs. actual high to low switch +
  920. * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
  921. *
  922. * XXX: write MIPI_STOP_STATE_STALL?
  923. */
  924. I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
  925. intel_dsi->hs_to_lp_count);
  926. /* XXX: low power clock equivalence in terms of byte clock.
  927. * the number of byte clocks occupied in one low power clock.
  928. * based on txbyteclkhs and txclkesc.
  929. * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
  930. * ) / 105.???
  931. */
  932. I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
  933. /* the bw essential for transmitting 16 long packets containing
  934. * 252 bytes meant for dcs write memory command is programmed in
  935. * this register in terms of byte clocks. based on dsi transfer
  936. * rate and the number of lanes configured the time taken to
  937. * transmit 16 long packets in a dsi stream varies. */
  938. I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
  939. I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
  940. intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
  941. intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
  942. if (is_vid_mode(intel_dsi))
  943. /* Some panels might have resolution which is not a
  944. * multiple of 64 like 1366 x 768. Enable RANDOM
  945. * resolution support for such panels by default */
  946. I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
  947. intel_dsi->video_frmt_cfg_bits |
  948. intel_dsi->video_mode_format |
  949. IP_TG_CONFIG |
  950. RANDOM_DPI_DISPLAY_RESOLUTION);
  951. }
  952. }
  953. static enum drm_connector_status
  954. intel_dsi_detect(struct drm_connector *connector, bool force)
  955. {
  956. return connector_status_connected;
  957. }
  958. static int intel_dsi_get_modes(struct drm_connector *connector)
  959. {
  960. struct intel_connector *intel_connector = to_intel_connector(connector);
  961. struct drm_display_mode *mode;
  962. DRM_DEBUG_KMS("\n");
  963. if (!intel_connector->panel.fixed_mode) {
  964. DRM_DEBUG_KMS("no fixed mode\n");
  965. return 0;
  966. }
  967. mode = drm_mode_duplicate(connector->dev,
  968. intel_connector->panel.fixed_mode);
  969. if (!mode) {
  970. DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
  971. return 0;
  972. }
  973. drm_mode_probed_add(connector, mode);
  974. return 1;
  975. }
  976. static int intel_dsi_set_property(struct drm_connector *connector,
  977. struct drm_property *property,
  978. uint64_t val)
  979. {
  980. struct drm_device *dev = connector->dev;
  981. struct intel_connector *intel_connector = to_intel_connector(connector);
  982. struct drm_crtc *crtc;
  983. int ret;
  984. ret = drm_object_property_set_value(&connector->base, property, val);
  985. if (ret)
  986. return ret;
  987. if (property == dev->mode_config.scaling_mode_property) {
  988. if (val == DRM_MODE_SCALE_NONE) {
  989. DRM_DEBUG_KMS("no scaling not supported\n");
  990. return -EINVAL;
  991. }
  992. if (HAS_GMCH_DISPLAY(dev) &&
  993. val == DRM_MODE_SCALE_CENTER) {
  994. DRM_DEBUG_KMS("centering not supported\n");
  995. return -EINVAL;
  996. }
  997. if (intel_connector->panel.fitting_mode == val)
  998. return 0;
  999. intel_connector->panel.fitting_mode = val;
  1000. }
  1001. crtc = intel_attached_encoder(connector)->base.crtc;
  1002. if (crtc && crtc->state->enable) {
  1003. /*
  1004. * If the CRTC is enabled, the display will be changed
  1005. * according to the new panel fitting mode.
  1006. */
  1007. intel_crtc_restore_mode(crtc);
  1008. }
  1009. return 0;
  1010. }
  1011. static void intel_dsi_connector_destroy(struct drm_connector *connector)
  1012. {
  1013. struct intel_connector *intel_connector = to_intel_connector(connector);
  1014. DRM_DEBUG_KMS("\n");
  1015. intel_panel_fini(&intel_connector->panel);
  1016. drm_connector_cleanup(connector);
  1017. kfree(connector);
  1018. }
  1019. static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
  1020. {
  1021. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  1022. if (intel_dsi->panel) {
  1023. drm_panel_detach(intel_dsi->panel);
  1024. /* XXX: Logically this call belongs in the panel driver. */
  1025. drm_panel_remove(intel_dsi->panel);
  1026. }
  1027. /* dispose of the gpios */
  1028. if (intel_dsi->gpio_panel)
  1029. gpiod_put(intel_dsi->gpio_panel);
  1030. intel_encoder_destroy(encoder);
  1031. }
  1032. static const struct drm_encoder_funcs intel_dsi_funcs = {
  1033. .destroy = intel_dsi_encoder_destroy,
  1034. };
  1035. static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
  1036. .get_modes = intel_dsi_get_modes,
  1037. .mode_valid = intel_dsi_mode_valid,
  1038. .best_encoder = intel_best_encoder,
  1039. };
  1040. static const struct drm_connector_funcs intel_dsi_connector_funcs = {
  1041. .dpms = drm_atomic_helper_connector_dpms,
  1042. .detect = intel_dsi_detect,
  1043. .destroy = intel_dsi_connector_destroy,
  1044. .fill_modes = drm_helper_probe_single_connector_modes,
  1045. .set_property = intel_dsi_set_property,
  1046. .atomic_get_property = intel_connector_atomic_get_property,
  1047. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  1048. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  1049. };
  1050. static void intel_dsi_add_properties(struct intel_connector *connector)
  1051. {
  1052. struct drm_device *dev = connector->base.dev;
  1053. if (connector->panel.fixed_mode) {
  1054. drm_mode_create_scaling_mode_property(dev);
  1055. drm_object_attach_property(&connector->base.base,
  1056. dev->mode_config.scaling_mode_property,
  1057. DRM_MODE_SCALE_ASPECT);
  1058. connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
  1059. }
  1060. }
  1061. void intel_dsi_init(struct drm_device *dev)
  1062. {
  1063. struct intel_dsi *intel_dsi;
  1064. struct intel_encoder *intel_encoder;
  1065. struct drm_encoder *encoder;
  1066. struct intel_connector *intel_connector;
  1067. struct drm_connector *connector;
  1068. struct drm_display_mode *scan, *fixed_mode = NULL;
  1069. struct drm_i915_private *dev_priv = dev->dev_private;
  1070. enum port port;
  1071. unsigned int i;
  1072. DRM_DEBUG_KMS("\n");
  1073. /* There is no detection method for MIPI so rely on VBT */
  1074. if (!intel_bios_is_dsi_present(dev_priv, &port))
  1075. return;
  1076. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  1077. dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
  1078. } else if (IS_BROXTON(dev)) {
  1079. dev_priv->mipi_mmio_base = BXT_MIPI_BASE;
  1080. } else {
  1081. DRM_ERROR("Unsupported Mipi device to reg base");
  1082. return;
  1083. }
  1084. intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
  1085. if (!intel_dsi)
  1086. return;
  1087. intel_connector = intel_connector_alloc();
  1088. if (!intel_connector) {
  1089. kfree(intel_dsi);
  1090. return;
  1091. }
  1092. intel_encoder = &intel_dsi->base;
  1093. encoder = &intel_encoder->base;
  1094. intel_dsi->attached_connector = intel_connector;
  1095. connector = &intel_connector->base;
  1096. drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI,
  1097. NULL);
  1098. intel_encoder->compute_config = intel_dsi_compute_config;
  1099. intel_encoder->pre_enable = intel_dsi_pre_enable;
  1100. intel_encoder->enable = intel_dsi_enable_nop;
  1101. intel_encoder->disable = intel_dsi_pre_disable;
  1102. intel_encoder->post_disable = intel_dsi_post_disable;
  1103. intel_encoder->get_hw_state = intel_dsi_get_hw_state;
  1104. intel_encoder->get_config = intel_dsi_get_config;
  1105. intel_connector->get_hw_state = intel_connector_get_hw_state;
  1106. intel_connector->unregister = intel_connector_unregister;
  1107. /*
  1108. * On BYT/CHV, pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI
  1109. * port C. BXT isn't limited like this.
  1110. */
  1111. if (IS_BROXTON(dev_priv))
  1112. intel_encoder->crtc_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C);
  1113. else if (port == PORT_A)
  1114. intel_encoder->crtc_mask = BIT(PIPE_A);
  1115. else
  1116. intel_encoder->crtc_mask = BIT(PIPE_B);
  1117. if (dev_priv->vbt.dsi.config->dual_link)
  1118. intel_dsi->ports = BIT(PORT_A) | BIT(PORT_C);
  1119. else
  1120. intel_dsi->ports = BIT(port);
  1121. /* Create a DSI host (and a device) for each port. */
  1122. for_each_dsi_port(port, intel_dsi->ports) {
  1123. struct intel_dsi_host *host;
  1124. host = intel_dsi_host_init(intel_dsi, port);
  1125. if (!host)
  1126. goto err;
  1127. intel_dsi->dsi_hosts[port] = host;
  1128. }
  1129. for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) {
  1130. intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi,
  1131. intel_dsi_drivers[i].panel_id);
  1132. if (intel_dsi->panel)
  1133. break;
  1134. }
  1135. if (!intel_dsi->panel) {
  1136. DRM_DEBUG_KMS("no device found\n");
  1137. goto err;
  1138. }
  1139. /*
  1140. * In case of BYT with CRC PMIC, we need to use GPIO for
  1141. * Panel control.
  1142. */
  1143. if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) {
  1144. intel_dsi->gpio_panel =
  1145. gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH);
  1146. if (IS_ERR(intel_dsi->gpio_panel)) {
  1147. DRM_ERROR("Failed to own gpio for panel control\n");
  1148. intel_dsi->gpio_panel = NULL;
  1149. }
  1150. }
  1151. intel_encoder->type = INTEL_OUTPUT_DSI;
  1152. intel_encoder->cloneable = 0;
  1153. drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
  1154. DRM_MODE_CONNECTOR_DSI);
  1155. drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
  1156. connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
  1157. connector->interlace_allowed = false;
  1158. connector->doublescan_allowed = false;
  1159. intel_connector_attach_encoder(intel_connector, intel_encoder);
  1160. drm_panel_attach(intel_dsi->panel, connector);
  1161. mutex_lock(&dev->mode_config.mutex);
  1162. drm_panel_get_modes(intel_dsi->panel);
  1163. list_for_each_entry(scan, &connector->probed_modes, head) {
  1164. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  1165. fixed_mode = drm_mode_duplicate(dev, scan);
  1166. break;
  1167. }
  1168. }
  1169. mutex_unlock(&dev->mode_config.mutex);
  1170. if (!fixed_mode) {
  1171. DRM_DEBUG_KMS("no fixed mode\n");
  1172. goto err;
  1173. }
  1174. intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
  1175. intel_dsi_add_properties(intel_connector);
  1176. drm_connector_register(connector);
  1177. intel_panel_setup_backlight(connector, INVALID_PIPE);
  1178. return;
  1179. err:
  1180. drm_encoder_cleanup(&intel_encoder->base);
  1181. kfree(intel_dsi);
  1182. kfree(intel_connector);
  1183. }