intel_dsi.c 36 KB

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