intel_dsi.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  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 void intel_dsi_hot_plug(struct intel_encoder *encoder)
  219. {
  220. DRM_DEBUG_KMS("\n");
  221. }
  222. static bool intel_dsi_compute_config(struct intel_encoder *encoder,
  223. struct intel_crtc_state *config)
  224. {
  225. struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
  226. base);
  227. struct intel_connector *intel_connector = intel_dsi->attached_connector;
  228. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  229. struct drm_display_mode *adjusted_mode = &config->base.adjusted_mode;
  230. DRM_DEBUG_KMS("\n");
  231. if (fixed_mode)
  232. intel_fixed_panel_mode(fixed_mode, adjusted_mode);
  233. /* DSI uses short packets for sync events, so clear mode flags for DSI */
  234. adjusted_mode->flags = 0;
  235. return true;
  236. }
  237. static void intel_dsi_port_enable(struct intel_encoder *encoder)
  238. {
  239. struct drm_device *dev = encoder->base.dev;
  240. struct drm_i915_private *dev_priv = dev->dev_private;
  241. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  242. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  243. enum port port;
  244. u32 temp;
  245. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
  246. temp = I915_READ(VLV_CHICKEN_3);
  247. temp &= ~PIXEL_OVERLAP_CNT_MASK |
  248. intel_dsi->pixel_overlap <<
  249. PIXEL_OVERLAP_CNT_SHIFT;
  250. I915_WRITE(VLV_CHICKEN_3, temp);
  251. }
  252. for_each_dsi_port(port, intel_dsi->ports) {
  253. temp = I915_READ(MIPI_PORT_CTRL(port));
  254. temp &= ~LANE_CONFIGURATION_MASK;
  255. temp &= ~DUAL_LINK_MODE_MASK;
  256. if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) {
  257. temp |= (intel_dsi->dual_link - 1)
  258. << DUAL_LINK_MODE_SHIFT;
  259. temp |= intel_crtc->pipe ?
  260. LANE_CONFIGURATION_DUAL_LINK_B :
  261. LANE_CONFIGURATION_DUAL_LINK_A;
  262. }
  263. /* assert ip_tg_enable signal */
  264. I915_WRITE(MIPI_PORT_CTRL(port), temp | DPI_ENABLE);
  265. POSTING_READ(MIPI_PORT_CTRL(port));
  266. }
  267. }
  268. static void intel_dsi_port_disable(struct intel_encoder *encoder)
  269. {
  270. struct drm_device *dev = encoder->base.dev;
  271. struct drm_i915_private *dev_priv = dev->dev_private;
  272. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  273. enum port port;
  274. u32 temp;
  275. for_each_dsi_port(port, intel_dsi->ports) {
  276. /* de-assert ip_tg_enable signal */
  277. temp = I915_READ(MIPI_PORT_CTRL(port));
  278. I915_WRITE(MIPI_PORT_CTRL(port), temp & ~DPI_ENABLE);
  279. POSTING_READ(MIPI_PORT_CTRL(port));
  280. }
  281. }
  282. static void intel_dsi_device_ready(struct intel_encoder *encoder)
  283. {
  284. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  285. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  286. enum port port;
  287. u32 val;
  288. DRM_DEBUG_KMS("\n");
  289. mutex_lock(&dev_priv->sb_lock);
  290. /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
  291. * needed everytime after power gate */
  292. vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
  293. mutex_unlock(&dev_priv->sb_lock);
  294. /* bandgap reset is needed after everytime we do power gate */
  295. band_gap_reset(dev_priv);
  296. for_each_dsi_port(port, intel_dsi->ports) {
  297. I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
  298. usleep_range(2500, 3000);
  299. /* Enable MIPI PHY transparent latch
  300. * Common bit for both MIPI Port A & MIPI Port C
  301. * No similar bit in MIPI Port C reg
  302. */
  303. val = I915_READ(MIPI_PORT_CTRL(PORT_A));
  304. I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
  305. usleep_range(1000, 1500);
  306. I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
  307. usleep_range(2500, 3000);
  308. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
  309. usleep_range(2500, 3000);
  310. }
  311. }
  312. static void intel_dsi_enable(struct intel_encoder *encoder)
  313. {
  314. struct drm_device *dev = encoder->base.dev;
  315. struct drm_i915_private *dev_priv = dev->dev_private;
  316. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  317. enum port port;
  318. DRM_DEBUG_KMS("\n");
  319. if (is_cmd_mode(intel_dsi)) {
  320. for_each_dsi_port(port, intel_dsi->ports)
  321. I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
  322. } else {
  323. msleep(20); /* XXX */
  324. for_each_dsi_port(port, intel_dsi->ports)
  325. dpi_send_cmd(intel_dsi, TURN_ON, false, port);
  326. msleep(100);
  327. drm_panel_enable(intel_dsi->panel);
  328. for_each_dsi_port(port, intel_dsi->ports)
  329. wait_for_dsi_fifo_empty(intel_dsi, port);
  330. intel_dsi_port_enable(encoder);
  331. }
  332. }
  333. static void intel_dsi_pre_enable(struct intel_encoder *encoder)
  334. {
  335. struct drm_device *dev = encoder->base.dev;
  336. struct drm_i915_private *dev_priv = dev->dev_private;
  337. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  338. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  339. enum pipe pipe = intel_crtc->pipe;
  340. enum port port;
  341. u32 tmp;
  342. DRM_DEBUG_KMS("\n");
  343. /* Panel Enable over CRC PMIC */
  344. if (intel_dsi->gpio_panel)
  345. gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
  346. msleep(intel_dsi->panel_on_delay);
  347. /* Disable DPOunit clock gating, can stall pipe
  348. * and we need DPLL REFA always enabled */
  349. tmp = I915_READ(DPLL(pipe));
  350. tmp |= DPLL_REFA_CLK_ENABLE_VLV;
  351. I915_WRITE(DPLL(pipe), tmp);
  352. /* update the hw state for DPLL */
  353. intel_crtc->config->dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV |
  354. DPLL_REFA_CLK_ENABLE_VLV;
  355. tmp = I915_READ(DSPCLK_GATE_D);
  356. tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
  357. I915_WRITE(DSPCLK_GATE_D, tmp);
  358. /* put device in ready state */
  359. intel_dsi_device_ready(encoder);
  360. drm_panel_prepare(intel_dsi->panel);
  361. for_each_dsi_port(port, intel_dsi->ports)
  362. wait_for_dsi_fifo_empty(intel_dsi, port);
  363. /* Enable port in pre-enable phase itself because as per hw team
  364. * recommendation, port should be enabled befor plane & pipe */
  365. intel_dsi_enable(encoder);
  366. }
  367. static void intel_dsi_enable_nop(struct intel_encoder *encoder)
  368. {
  369. DRM_DEBUG_KMS("\n");
  370. /* for DSI port enable has to be done before pipe
  371. * and plane enable, so port enable is done in
  372. * pre_enable phase itself unlike other encoders
  373. */
  374. }
  375. static void intel_dsi_pre_disable(struct intel_encoder *encoder)
  376. {
  377. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  378. enum port port;
  379. DRM_DEBUG_KMS("\n");
  380. if (is_vid_mode(intel_dsi)) {
  381. /* Send Shutdown command to the panel in LP mode */
  382. for_each_dsi_port(port, intel_dsi->ports)
  383. dpi_send_cmd(intel_dsi, SHUTDOWN, false, port);
  384. msleep(10);
  385. }
  386. }
  387. static void intel_dsi_disable(struct intel_encoder *encoder)
  388. {
  389. struct drm_device *dev = encoder->base.dev;
  390. struct drm_i915_private *dev_priv = dev->dev_private;
  391. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  392. enum port port;
  393. u32 temp;
  394. DRM_DEBUG_KMS("\n");
  395. if (is_vid_mode(intel_dsi)) {
  396. for_each_dsi_port(port, intel_dsi->ports)
  397. wait_for_dsi_fifo_empty(intel_dsi, port);
  398. intel_dsi_port_disable(encoder);
  399. msleep(2);
  400. }
  401. for_each_dsi_port(port, intel_dsi->ports) {
  402. /* Panel commands can be sent when clock is in LP11 */
  403. I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
  404. temp = I915_READ(MIPI_CTRL(port));
  405. temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  406. I915_WRITE(MIPI_CTRL(port), temp |
  407. intel_dsi->escape_clk_div <<
  408. ESCAPE_CLOCK_DIVIDER_SHIFT);
  409. I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
  410. temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
  411. temp &= ~VID_MODE_FORMAT_MASK;
  412. I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
  413. I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
  414. }
  415. /* if disable packets are sent before sending shutdown packet then in
  416. * some next enable sequence send turn on packet error is observed */
  417. drm_panel_disable(intel_dsi->panel);
  418. for_each_dsi_port(port, intel_dsi->ports)
  419. wait_for_dsi_fifo_empty(intel_dsi, port);
  420. }
  421. static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
  422. {
  423. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  424. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  425. enum port port;
  426. u32 val;
  427. DRM_DEBUG_KMS("\n");
  428. for_each_dsi_port(port, intel_dsi->ports) {
  429. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  430. ULPS_STATE_ENTER);
  431. usleep_range(2000, 2500);
  432. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  433. ULPS_STATE_EXIT);
  434. usleep_range(2000, 2500);
  435. I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
  436. ULPS_STATE_ENTER);
  437. usleep_range(2000, 2500);
  438. /* Wait till Clock lanes are in LP-00 state for MIPI Port A
  439. * only. MIPI Port C has no similar bit for checking
  440. */
  441. if (wait_for(((I915_READ(MIPI_PORT_CTRL(PORT_A)) & AFE_LATCHOUT)
  442. == 0x00000), 30))
  443. DRM_ERROR("DSI LP not going Low\n");
  444. /* Disable MIPI PHY transparent latch
  445. * Common bit for both MIPI Port A & MIPI Port C
  446. */
  447. val = I915_READ(MIPI_PORT_CTRL(PORT_A));
  448. I915_WRITE(MIPI_PORT_CTRL(PORT_A), val & ~LP_OUTPUT_HOLD);
  449. usleep_range(1000, 1500);
  450. I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
  451. usleep_range(2000, 2500);
  452. }
  453. vlv_disable_dsi_pll(encoder);
  454. }
  455. static void intel_dsi_post_disable(struct intel_encoder *encoder)
  456. {
  457. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  458. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  459. u32 val;
  460. DRM_DEBUG_KMS("\n");
  461. intel_dsi_disable(encoder);
  462. intel_dsi_clear_device_ready(encoder);
  463. val = I915_READ(DSPCLK_GATE_D);
  464. val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
  465. I915_WRITE(DSPCLK_GATE_D, val);
  466. drm_panel_unprepare(intel_dsi->panel);
  467. msleep(intel_dsi->panel_off_delay);
  468. msleep(intel_dsi->panel_pwr_cycle_delay);
  469. /* Panel Disable over CRC PMIC */
  470. if (intel_dsi->gpio_panel)
  471. gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
  472. }
  473. static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
  474. enum pipe *pipe)
  475. {
  476. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  477. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  478. struct drm_device *dev = encoder->base.dev;
  479. enum intel_display_power_domain power_domain;
  480. u32 dpi_enabled, func;
  481. enum port port;
  482. DRM_DEBUG_KMS("\n");
  483. power_domain = intel_display_port_power_domain(encoder);
  484. if (!intel_display_power_is_enabled(dev_priv, power_domain))
  485. return false;
  486. /* XXX: this only works for one DSI output */
  487. for_each_dsi_port(port, intel_dsi->ports) {
  488. func = I915_READ(MIPI_DSI_FUNC_PRG(port));
  489. dpi_enabled = I915_READ(MIPI_PORT_CTRL(port)) &
  490. DPI_ENABLE;
  491. /* Due to some hardware limitations on BYT, MIPI Port C DPI
  492. * Enable bit does not get set. To check whether DSI Port C
  493. * was enabled in BIOS, check the Pipe B enable bit
  494. */
  495. if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) &&
  496. (port == PORT_C))
  497. dpi_enabled = I915_READ(PIPECONF(PIPE_B)) &
  498. PIPECONF_ENABLE;
  499. if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) {
  500. if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
  501. *pipe = port == PORT_A ? PIPE_A : PIPE_B;
  502. return true;
  503. }
  504. }
  505. }
  506. return false;
  507. }
  508. static void intel_dsi_get_config(struct intel_encoder *encoder,
  509. struct intel_crtc_state *pipe_config)
  510. {
  511. u32 pclk;
  512. DRM_DEBUG_KMS("\n");
  513. /*
  514. * DPLL_MD is not used in case of DSI, reading will get some default value
  515. * set dpll_md = 0
  516. */
  517. pipe_config->dpll_hw_state.dpll_md = 0;
  518. pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
  519. if (!pclk)
  520. return;
  521. pipe_config->base.adjusted_mode.crtc_clock = pclk;
  522. pipe_config->port_clock = pclk;
  523. }
  524. static enum drm_mode_status
  525. intel_dsi_mode_valid(struct drm_connector *connector,
  526. struct drm_display_mode *mode)
  527. {
  528. struct intel_connector *intel_connector = to_intel_connector(connector);
  529. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  530. DRM_DEBUG_KMS("\n");
  531. if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
  532. DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
  533. return MODE_NO_DBLESCAN;
  534. }
  535. if (fixed_mode) {
  536. if (mode->hdisplay > fixed_mode->hdisplay)
  537. return MODE_PANEL;
  538. if (mode->vdisplay > fixed_mode->vdisplay)
  539. return MODE_PANEL;
  540. }
  541. return MODE_OK;
  542. }
  543. /* return txclkesc cycles in terms of divider and duration in us */
  544. static u16 txclkesc(u32 divider, unsigned int us)
  545. {
  546. switch (divider) {
  547. case ESCAPE_CLOCK_DIVIDER_1:
  548. default:
  549. return 20 * us;
  550. case ESCAPE_CLOCK_DIVIDER_2:
  551. return 10 * us;
  552. case ESCAPE_CLOCK_DIVIDER_4:
  553. return 5 * us;
  554. }
  555. }
  556. /* return pixels in terms of txbyteclkhs */
  557. static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
  558. u16 burst_mode_ratio)
  559. {
  560. return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
  561. 8 * 100), lane_count);
  562. }
  563. static void set_dsi_timings(struct drm_encoder *encoder,
  564. const struct drm_display_mode *mode)
  565. {
  566. struct drm_device *dev = encoder->dev;
  567. struct drm_i915_private *dev_priv = dev->dev_private;
  568. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  569. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  570. enum port port;
  571. unsigned int bpp = intel_crtc->config->pipe_bpp;
  572. unsigned int lane_count = intel_dsi->lane_count;
  573. u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
  574. hactive = mode->hdisplay;
  575. hfp = mode->hsync_start - mode->hdisplay;
  576. hsync = mode->hsync_end - mode->hsync_start;
  577. hbp = mode->htotal - mode->hsync_end;
  578. if (intel_dsi->dual_link) {
  579. hactive /= 2;
  580. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  581. hactive += intel_dsi->pixel_overlap;
  582. hfp /= 2;
  583. hsync /= 2;
  584. hbp /= 2;
  585. }
  586. vfp = mode->vsync_start - mode->vdisplay;
  587. vsync = mode->vsync_end - mode->vsync_start;
  588. vbp = mode->vtotal - mode->vsync_end;
  589. /* horizontal values are in terms of high speed byte clock */
  590. hactive = txbyteclkhs(hactive, bpp, lane_count,
  591. intel_dsi->burst_mode_ratio);
  592. hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  593. hsync = txbyteclkhs(hsync, bpp, lane_count,
  594. intel_dsi->burst_mode_ratio);
  595. hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
  596. for_each_dsi_port(port, intel_dsi->ports) {
  597. I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
  598. I915_WRITE(MIPI_HFP_COUNT(port), hfp);
  599. /* meaningful for video mode non-burst sync pulse mode only,
  600. * can be zero for non-burst sync events and burst modes */
  601. I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
  602. I915_WRITE(MIPI_HBP_COUNT(port), hbp);
  603. /* vertical values are in terms of lines */
  604. I915_WRITE(MIPI_VFP_COUNT(port), vfp);
  605. I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
  606. I915_WRITE(MIPI_VBP_COUNT(port), vbp);
  607. }
  608. }
  609. static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
  610. {
  611. struct drm_encoder *encoder = &intel_encoder->base;
  612. struct drm_device *dev = encoder->dev;
  613. struct drm_i915_private *dev_priv = dev->dev_private;
  614. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  615. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  616. struct drm_display_mode *adjusted_mode =
  617. &intel_crtc->config->base.adjusted_mode;
  618. enum port port;
  619. unsigned int bpp = intel_crtc->config->pipe_bpp;
  620. u32 val, tmp;
  621. u16 mode_hdisplay;
  622. DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
  623. mode_hdisplay = adjusted_mode->hdisplay;
  624. if (intel_dsi->dual_link) {
  625. mode_hdisplay /= 2;
  626. if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
  627. mode_hdisplay += intel_dsi->pixel_overlap;
  628. }
  629. for_each_dsi_port(port, intel_dsi->ports) {
  630. /* escape clock divider, 20MHz, shared for A and C.
  631. * device ready must be off when doing this! txclkesc? */
  632. tmp = I915_READ(MIPI_CTRL(PORT_A));
  633. tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  634. I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
  635. /* read request priority is per pipe */
  636. tmp = I915_READ(MIPI_CTRL(port));
  637. tmp &= ~READ_REQUEST_PRIORITY_MASK;
  638. I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
  639. /* XXX: why here, why like this? handling in irq handler?! */
  640. I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
  641. I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
  642. I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
  643. I915_WRITE(MIPI_DPI_RESOLUTION(port),
  644. adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
  645. mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
  646. }
  647. set_dsi_timings(encoder, adjusted_mode);
  648. val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
  649. if (is_cmd_mode(intel_dsi)) {
  650. val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
  651. val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
  652. } else {
  653. val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
  654. /* XXX: cross-check bpp vs. pixel format? */
  655. val |= intel_dsi->pixel_format;
  656. }
  657. tmp = 0;
  658. if (intel_dsi->eotp_pkt == 0)
  659. tmp |= EOT_DISABLE;
  660. if (intel_dsi->clock_stop)
  661. tmp |= CLOCKSTOP;
  662. for_each_dsi_port(port, intel_dsi->ports) {
  663. I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
  664. /* timeouts for recovery. one frame IIUC. if counter expires,
  665. * EOT and stop state. */
  666. /*
  667. * In burst mode, value greater than one DPI line Time in byte
  668. * clock (txbyteclkhs) To timeout this timer 1+ of the above
  669. * said value is recommended.
  670. *
  671. * In non-burst mode, Value greater than one DPI frame time in
  672. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  673. * said value is recommended.
  674. *
  675. * In DBI only mode, value greater than one DBI frame time in
  676. * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
  677. * said value is recommended.
  678. */
  679. if (is_vid_mode(intel_dsi) &&
  680. intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
  681. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  682. txbyteclkhs(adjusted_mode->htotal, bpp,
  683. intel_dsi->lane_count,
  684. intel_dsi->burst_mode_ratio) + 1);
  685. } else {
  686. I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
  687. txbyteclkhs(adjusted_mode->vtotal *
  688. adjusted_mode->htotal,
  689. bpp, intel_dsi->lane_count,
  690. intel_dsi->burst_mode_ratio) + 1);
  691. }
  692. I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
  693. I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
  694. intel_dsi->turn_arnd_val);
  695. I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
  696. intel_dsi->rst_timer_val);
  697. /* dphy stuff */
  698. /* in terms of low power clock */
  699. I915_WRITE(MIPI_INIT_COUNT(port),
  700. txclkesc(intel_dsi->escape_clk_div, 100));
  701. /* recovery disables */
  702. I915_WRITE(MIPI_EOT_DISABLE(port), tmp);
  703. /* in terms of low power clock */
  704. I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
  705. /* in terms of txbyteclkhs. actual high to low switch +
  706. * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
  707. *
  708. * XXX: write MIPI_STOP_STATE_STALL?
  709. */
  710. I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
  711. intel_dsi->hs_to_lp_count);
  712. /* XXX: low power clock equivalence in terms of byte clock.
  713. * the number of byte clocks occupied in one low power clock.
  714. * based on txbyteclkhs and txclkesc.
  715. * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
  716. * ) / 105.???
  717. */
  718. I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
  719. /* the bw essential for transmitting 16 long packets containing
  720. * 252 bytes meant for dcs write memory command is programmed in
  721. * this register in terms of byte clocks. based on dsi transfer
  722. * rate and the number of lanes configured the time taken to
  723. * transmit 16 long packets in a dsi stream varies. */
  724. I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
  725. I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
  726. intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
  727. intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
  728. if (is_vid_mode(intel_dsi))
  729. /* Some panels might have resolution which is not a
  730. * multiple of 64 like 1366 x 768. Enable RANDOM
  731. * resolution support for such panels by default */
  732. I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
  733. intel_dsi->video_frmt_cfg_bits |
  734. intel_dsi->video_mode_format |
  735. IP_TG_CONFIG |
  736. RANDOM_DPI_DISPLAY_RESOLUTION);
  737. }
  738. }
  739. static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
  740. {
  741. DRM_DEBUG_KMS("\n");
  742. intel_dsi_prepare(encoder);
  743. vlv_enable_dsi_pll(encoder);
  744. }
  745. static enum drm_connector_status
  746. intel_dsi_detect(struct drm_connector *connector, bool force)
  747. {
  748. return connector_status_connected;
  749. }
  750. static int intel_dsi_get_modes(struct drm_connector *connector)
  751. {
  752. struct intel_connector *intel_connector = to_intel_connector(connector);
  753. struct drm_display_mode *mode;
  754. DRM_DEBUG_KMS("\n");
  755. if (!intel_connector->panel.fixed_mode) {
  756. DRM_DEBUG_KMS("no fixed mode\n");
  757. return 0;
  758. }
  759. mode = drm_mode_duplicate(connector->dev,
  760. intel_connector->panel.fixed_mode);
  761. if (!mode) {
  762. DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
  763. return 0;
  764. }
  765. drm_mode_probed_add(connector, mode);
  766. return 1;
  767. }
  768. static void intel_dsi_connector_destroy(struct drm_connector *connector)
  769. {
  770. struct intel_connector *intel_connector = to_intel_connector(connector);
  771. DRM_DEBUG_KMS("\n");
  772. intel_panel_fini(&intel_connector->panel);
  773. drm_connector_cleanup(connector);
  774. kfree(connector);
  775. }
  776. static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
  777. {
  778. struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
  779. if (intel_dsi->panel) {
  780. drm_panel_detach(intel_dsi->panel);
  781. /* XXX: Logically this call belongs in the panel driver. */
  782. drm_panel_remove(intel_dsi->panel);
  783. }
  784. /* dispose of the gpios */
  785. if (intel_dsi->gpio_panel)
  786. gpiod_put(intel_dsi->gpio_panel);
  787. intel_encoder_destroy(encoder);
  788. }
  789. static const struct drm_encoder_funcs intel_dsi_funcs = {
  790. .destroy = intel_dsi_encoder_destroy,
  791. };
  792. static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
  793. .get_modes = intel_dsi_get_modes,
  794. .mode_valid = intel_dsi_mode_valid,
  795. .best_encoder = intel_best_encoder,
  796. };
  797. static const struct drm_connector_funcs intel_dsi_connector_funcs = {
  798. .dpms = intel_connector_dpms,
  799. .detect = intel_dsi_detect,
  800. .destroy = intel_dsi_connector_destroy,
  801. .fill_modes = drm_helper_probe_single_connector_modes,
  802. .atomic_get_property = intel_connector_atomic_get_property,
  803. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  804. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  805. };
  806. void intel_dsi_init(struct drm_device *dev)
  807. {
  808. struct intel_dsi *intel_dsi;
  809. struct intel_encoder *intel_encoder;
  810. struct drm_encoder *encoder;
  811. struct intel_connector *intel_connector;
  812. struct drm_connector *connector;
  813. struct drm_display_mode *scan, *fixed_mode = NULL;
  814. struct drm_i915_private *dev_priv = dev->dev_private;
  815. enum port port;
  816. unsigned int i;
  817. DRM_DEBUG_KMS("\n");
  818. /* There is no detection method for MIPI so rely on VBT */
  819. if (!dev_priv->vbt.has_mipi)
  820. return;
  821. if (IS_VALLEYVIEW(dev)) {
  822. dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
  823. } else {
  824. DRM_ERROR("Unsupported Mipi device to reg base");
  825. return;
  826. }
  827. intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
  828. if (!intel_dsi)
  829. return;
  830. intel_connector = intel_connector_alloc();
  831. if (!intel_connector) {
  832. kfree(intel_dsi);
  833. return;
  834. }
  835. intel_encoder = &intel_dsi->base;
  836. encoder = &intel_encoder->base;
  837. intel_dsi->attached_connector = intel_connector;
  838. connector = &intel_connector->base;
  839. drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
  840. /* XXX: very likely not all of these are needed */
  841. intel_encoder->hot_plug = intel_dsi_hot_plug;
  842. intel_encoder->compute_config = intel_dsi_compute_config;
  843. intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
  844. intel_encoder->pre_enable = intel_dsi_pre_enable;
  845. intel_encoder->enable = intel_dsi_enable_nop;
  846. intel_encoder->disable = intel_dsi_pre_disable;
  847. intel_encoder->post_disable = intel_dsi_post_disable;
  848. intel_encoder->get_hw_state = intel_dsi_get_hw_state;
  849. intel_encoder->get_config = intel_dsi_get_config;
  850. intel_connector->get_hw_state = intel_connector_get_hw_state;
  851. intel_connector->unregister = intel_connector_unregister;
  852. /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
  853. if (dev_priv->vbt.dsi.config->dual_link) {
  854. /* XXX: does dual link work on either pipe? */
  855. intel_encoder->crtc_mask = (1 << PIPE_A);
  856. intel_dsi->ports = ((1 << PORT_A) | (1 << PORT_C));
  857. } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
  858. intel_encoder->crtc_mask = (1 << PIPE_A);
  859. intel_dsi->ports = (1 << PORT_A);
  860. } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
  861. intel_encoder->crtc_mask = (1 << PIPE_B);
  862. intel_dsi->ports = (1 << PORT_C);
  863. }
  864. /* Create a DSI host (and a device) for each port. */
  865. for_each_dsi_port(port, intel_dsi->ports) {
  866. struct intel_dsi_host *host;
  867. host = intel_dsi_host_init(intel_dsi, port);
  868. if (!host)
  869. goto err;
  870. intel_dsi->dsi_hosts[port] = host;
  871. }
  872. for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) {
  873. intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi,
  874. intel_dsi_drivers[i].panel_id);
  875. if (intel_dsi->panel)
  876. break;
  877. }
  878. if (!intel_dsi->panel) {
  879. DRM_DEBUG_KMS("no device found\n");
  880. goto err;
  881. }
  882. /*
  883. * In case of BYT with CRC PMIC, we need to use GPIO for
  884. * Panel control.
  885. */
  886. if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) {
  887. intel_dsi->gpio_panel =
  888. gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH);
  889. if (IS_ERR(intel_dsi->gpio_panel)) {
  890. DRM_ERROR("Failed to own gpio for panel control\n");
  891. intel_dsi->gpio_panel = NULL;
  892. }
  893. }
  894. intel_encoder->type = INTEL_OUTPUT_DSI;
  895. intel_encoder->cloneable = 0;
  896. drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
  897. DRM_MODE_CONNECTOR_DSI);
  898. drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
  899. connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
  900. connector->interlace_allowed = false;
  901. connector->doublescan_allowed = false;
  902. intel_connector_attach_encoder(intel_connector, intel_encoder);
  903. drm_connector_register(connector);
  904. drm_panel_attach(intel_dsi->panel, connector);
  905. mutex_lock(&dev->mode_config.mutex);
  906. drm_panel_get_modes(intel_dsi->panel);
  907. list_for_each_entry(scan, &connector->probed_modes, head) {
  908. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  909. fixed_mode = drm_mode_duplicate(dev, scan);
  910. break;
  911. }
  912. }
  913. mutex_unlock(&dev->mode_config.mutex);
  914. if (!fixed_mode) {
  915. DRM_DEBUG_KMS("no fixed mode\n");
  916. goto err;
  917. }
  918. intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
  919. return;
  920. err:
  921. drm_encoder_cleanup(&intel_encoder->base);
  922. kfree(intel_dsi);
  923. kfree(intel_connector);
  924. }