drm_connector.h 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. /*
  2. * Copyright (c) 2016 Intel Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that copyright
  7. * notice and this permission notice appear in supporting documentation, and
  8. * that the name of the copyright holders not be used in advertising or
  9. * publicity pertaining to distribution of the software without specific,
  10. * written prior permission. The copyright holders make no representations
  11. * about the suitability of this software for any purpose. It is provided "as
  12. * is" without express or implied warranty.
  13. *
  14. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THIS SOFTWARE.
  21. */
  22. #ifndef __DRM_CONNECTOR_H__
  23. #define __DRM_CONNECTOR_H__
  24. #include <linux/list.h>
  25. #include <linux/llist.h>
  26. #include <linux/ctype.h>
  27. #include <linux/hdmi.h>
  28. #include <drm/drm_mode_object.h>
  29. #include <uapi/drm/drm_mode.h>
  30. struct drm_connector_helper_funcs;
  31. struct drm_modeset_acquire_ctx;
  32. struct drm_device;
  33. struct drm_crtc;
  34. struct drm_encoder;
  35. struct drm_property;
  36. struct drm_property_blob;
  37. struct drm_printer;
  38. struct edid;
  39. enum drm_connector_force {
  40. DRM_FORCE_UNSPECIFIED,
  41. DRM_FORCE_OFF,
  42. DRM_FORCE_ON, /* force on analog part normally */
  43. DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
  44. };
  45. /**
  46. * enum drm_connector_status - status for a &drm_connector
  47. *
  48. * This enum is used to track the connector status. There are no separate
  49. * #defines for the uapi!
  50. */
  51. enum drm_connector_status {
  52. /**
  53. * @connector_status_connected: The connector is definitely connected to
  54. * a sink device, and can be enabled.
  55. */
  56. connector_status_connected = 1,
  57. /**
  58. * @connector_status_disconnected: The connector isn't connected to a
  59. * sink device which can be autodetect. For digital outputs like DP or
  60. * HDMI (which can be realiable probed) this means there's really
  61. * nothing there. It is driver-dependent whether a connector with this
  62. * status can be lit up or not.
  63. */
  64. connector_status_disconnected = 2,
  65. /**
  66. * @connector_status_unknown: The connector's status could not be
  67. * reliably detected. This happens when probing would either cause
  68. * flicker (like load-detection when the connector is in use), or when a
  69. * hardware resource isn't available (like when load-detection needs a
  70. * free CRTC). It should be possible to light up the connector with one
  71. * of the listed fallback modes. For default configuration userspace
  72. * should only try to light up connectors with unknown status when
  73. * there's not connector with @connector_status_connected.
  74. */
  75. connector_status_unknown = 3,
  76. };
  77. enum subpixel_order {
  78. SubPixelUnknown = 0,
  79. SubPixelHorizontalRGB,
  80. SubPixelHorizontalBGR,
  81. SubPixelVerticalRGB,
  82. SubPixelVerticalBGR,
  83. SubPixelNone,
  84. };
  85. /**
  86. * struct drm_scrambling: sink's scrambling support.
  87. */
  88. struct drm_scrambling {
  89. /**
  90. * @supported: scrambling supported for rates > 340 Mhz.
  91. */
  92. bool supported;
  93. /**
  94. * @low_rates: scrambling supported for rates <= 340 Mhz.
  95. */
  96. bool low_rates;
  97. };
  98. /*
  99. * struct drm_scdc - Information about scdc capabilities of a HDMI 2.0 sink
  100. *
  101. * Provides SCDC register support and capabilities related information on a
  102. * HDMI 2.0 sink. In case of a HDMI 1.4 sink, all parameter must be 0.
  103. */
  104. struct drm_scdc {
  105. /**
  106. * @supported: status control & data channel present.
  107. */
  108. bool supported;
  109. /**
  110. * @read_request: sink is capable of generating scdc read request.
  111. */
  112. bool read_request;
  113. /**
  114. * @scrambling: sink's scrambling capabilities
  115. */
  116. struct drm_scrambling scrambling;
  117. };
  118. /**
  119. * struct drm_hdmi_info - runtime information about the connected HDMI sink
  120. *
  121. * Describes if a given display supports advanced HDMI 2.0 features.
  122. * This information is available in CEA-861-F extension blocks (like HF-VSDB).
  123. */
  124. struct drm_hdmi_info {
  125. /** @scdc: sink's scdc support and capabilities */
  126. struct drm_scdc scdc;
  127. /**
  128. * @y420_vdb_modes: bitmap of modes which can support ycbcr420
  129. * output only (not normal RGB/YCBCR444/422 outputs). There are total
  130. * 107 VICs defined by CEA-861-F spec, so the size is 128 bits to map
  131. * upto 128 VICs;
  132. */
  133. unsigned long y420_vdb_modes[BITS_TO_LONGS(128)];
  134. /**
  135. * @y420_cmdb_modes: bitmap of modes which can support ycbcr420
  136. * output also, along with normal HDMI outputs. There are total 107
  137. * VICs defined by CEA-861-F spec, so the size is 128 bits to map upto
  138. * 128 VICs;
  139. */
  140. unsigned long y420_cmdb_modes[BITS_TO_LONGS(128)];
  141. /** @y420_cmdb_map: bitmap of SVD index, to extraxt vcb modes */
  142. u64 y420_cmdb_map;
  143. /** @y420_dc_modes: bitmap of deep color support index */
  144. u8 y420_dc_modes;
  145. };
  146. /**
  147. * enum drm_link_status - connector's link_status property value
  148. *
  149. * This enum is used as the connector's link status property value.
  150. * It is set to the values defined in uapi.
  151. *
  152. * @DRM_LINK_STATUS_GOOD: DP Link is Good as a result of successful
  153. * link training
  154. * @DRM_LINK_STATUS_BAD: DP Link is BAD as a result of link training
  155. * failure
  156. */
  157. enum drm_link_status {
  158. DRM_LINK_STATUS_GOOD = DRM_MODE_LINK_STATUS_GOOD,
  159. DRM_LINK_STATUS_BAD = DRM_MODE_LINK_STATUS_BAD,
  160. };
  161. /**
  162. * enum drm_panel_orientation - panel_orientation info for &drm_display_info
  163. *
  164. * This enum is used to track the (LCD) panel orientation. There are no
  165. * separate #defines for the uapi!
  166. *
  167. * @DRM_MODE_PANEL_ORIENTATION_UNKNOWN: The drm driver has not provided any
  168. * panel orientation information (normal
  169. * for non panels) in this case the "panel
  170. * orientation" connector prop will not be
  171. * attached.
  172. * @DRM_MODE_PANEL_ORIENTATION_NORMAL: The top side of the panel matches the
  173. * top side of the device's casing.
  174. * @DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP: The top side of the panel matches the
  175. * bottom side of the device's casing, iow
  176. * the panel is mounted upside-down.
  177. * @DRM_MODE_PANEL_ORIENTATION_LEFT_UP: The left side of the panel matches the
  178. * top side of the device's casing.
  179. * @DRM_MODE_PANEL_ORIENTATION_RIGHT_UP: The right side of the panel matches the
  180. * top side of the device's casing.
  181. */
  182. enum drm_panel_orientation {
  183. DRM_MODE_PANEL_ORIENTATION_UNKNOWN = -1,
  184. DRM_MODE_PANEL_ORIENTATION_NORMAL = 0,
  185. DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP,
  186. DRM_MODE_PANEL_ORIENTATION_LEFT_UP,
  187. DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
  188. };
  189. /**
  190. * struct drm_display_info - runtime data about the connected sink
  191. *
  192. * Describes a given display (e.g. CRT or flat panel) and its limitations. For
  193. * fixed display sinks like built-in panels there's not much difference between
  194. * this and &struct drm_connector. But for sinks with a real cable this
  195. * structure is meant to describe all the things at the other end of the cable.
  196. *
  197. * For sinks which provide an EDID this can be filled out by calling
  198. * drm_add_edid_modes().
  199. */
  200. struct drm_display_info {
  201. /**
  202. * @name: Name of the display.
  203. */
  204. char name[DRM_DISPLAY_INFO_LEN];
  205. /**
  206. * @width_mm: Physical width in mm.
  207. */
  208. unsigned int width_mm;
  209. /**
  210. * @height_mm: Physical height in mm.
  211. */
  212. unsigned int height_mm;
  213. /**
  214. * @pixel_clock: Maximum pixel clock supported by the sink, in units of
  215. * 100Hz. This mismatches the clock in &drm_display_mode (which is in
  216. * kHZ), because that's what the EDID uses as base unit.
  217. */
  218. unsigned int pixel_clock;
  219. /**
  220. * @bpc: Maximum bits per color channel. Used by HDMI and DP outputs.
  221. */
  222. unsigned int bpc;
  223. /**
  224. * @subpixel_order: Subpixel order of LCD panels.
  225. */
  226. enum subpixel_order subpixel_order;
  227. #define DRM_COLOR_FORMAT_RGB444 (1<<0)
  228. #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
  229. #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
  230. #define DRM_COLOR_FORMAT_YCRCB420 (1<<3)
  231. /**
  232. * @panel_orientation: Read only connector property for built-in panels,
  233. * indicating the orientation of the panel vs the device's casing.
  234. * drm_connector_init() sets this to DRM_MODE_PANEL_ORIENTATION_UNKNOWN.
  235. * When not UNKNOWN this gets used by the drm_fb_helpers to rotate the
  236. * fb to compensate and gets exported as prop to userspace.
  237. */
  238. int panel_orientation;
  239. /**
  240. * @color_formats: HDMI Color formats, selects between RGB and YCrCb
  241. * modes. Used DRM_COLOR_FORMAT\_ defines, which are _not_ the same ones
  242. * as used to describe the pixel format in framebuffers, and also don't
  243. * match the formats in @bus_formats which are shared with v4l.
  244. */
  245. u32 color_formats;
  246. /**
  247. * @bus_formats: Pixel data format on the wire, somewhat redundant with
  248. * @color_formats. Array of size @num_bus_formats encoded using
  249. * MEDIA_BUS_FMT\_ defines shared with v4l and media drivers.
  250. */
  251. const u32 *bus_formats;
  252. /**
  253. * @num_bus_formats: Size of @bus_formats array.
  254. */
  255. unsigned int num_bus_formats;
  256. #define DRM_BUS_FLAG_DE_LOW (1<<0)
  257. #define DRM_BUS_FLAG_DE_HIGH (1<<1)
  258. /* drive data on pos. edge */
  259. #define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
  260. /* drive data on neg. edge */
  261. #define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
  262. /* data is transmitted MSB to LSB on the bus */
  263. #define DRM_BUS_FLAG_DATA_MSB_TO_LSB (1<<4)
  264. /* data is transmitted LSB to MSB on the bus */
  265. #define DRM_BUS_FLAG_DATA_LSB_TO_MSB (1<<5)
  266. /**
  267. * @bus_flags: Additional information (like pixel signal polarity) for
  268. * the pixel data on the bus, using DRM_BUS_FLAGS\_ defines.
  269. */
  270. u32 bus_flags;
  271. /**
  272. * @max_tmds_clock: Maximum TMDS clock rate supported by the
  273. * sink in kHz. 0 means undefined.
  274. */
  275. int max_tmds_clock;
  276. /**
  277. * @dvi_dual: Dual-link DVI sink?
  278. */
  279. bool dvi_dual;
  280. /**
  281. * @has_hdmi_infoframe: Does the sink support the HDMI infoframe?
  282. */
  283. bool has_hdmi_infoframe;
  284. /**
  285. * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even
  286. * more stuff redundant with @bus_formats.
  287. */
  288. u8 edid_hdmi_dc_modes;
  289. /**
  290. * @cea_rev: CEA revision of the HDMI sink.
  291. */
  292. u8 cea_rev;
  293. /**
  294. * @hdmi: advance features of a HDMI sink.
  295. */
  296. struct drm_hdmi_info hdmi;
  297. /**
  298. * @non_desktop: Non desktop display (HMD).
  299. */
  300. bool non_desktop;
  301. };
  302. int drm_display_info_set_bus_formats(struct drm_display_info *info,
  303. const u32 *formats,
  304. unsigned int num_formats);
  305. /**
  306. * struct drm_tv_connector_state - TV connector related states
  307. * @subconnector: selected subconnector
  308. * @margins: margins
  309. * @margins.left: left margin
  310. * @margins.right: right margin
  311. * @margins.top: top margin
  312. * @margins.bottom: bottom margin
  313. * @mode: TV mode
  314. * @brightness: brightness in percent
  315. * @contrast: contrast in percent
  316. * @flicker_reduction: flicker reduction in percent
  317. * @overscan: overscan in percent
  318. * @saturation: saturation in percent
  319. * @hue: hue in percent
  320. */
  321. struct drm_tv_connector_state {
  322. enum drm_mode_subconnector subconnector;
  323. struct {
  324. unsigned int left;
  325. unsigned int right;
  326. unsigned int top;
  327. unsigned int bottom;
  328. } margins;
  329. unsigned int mode;
  330. unsigned int brightness;
  331. unsigned int contrast;
  332. unsigned int flicker_reduction;
  333. unsigned int overscan;
  334. unsigned int saturation;
  335. unsigned int hue;
  336. };
  337. /**
  338. * struct drm_connector_state - mutable connector state
  339. * @connector: backpointer to the connector
  340. * @best_encoder: can be used by helpers and drivers to select the encoder
  341. * @state: backpointer to global drm_atomic_state
  342. * @tv: TV connector state
  343. */
  344. struct drm_connector_state {
  345. struct drm_connector *connector;
  346. /**
  347. * @crtc: CRTC to connect connector to, NULL if disabled.
  348. *
  349. * Do not change this directly, use drm_atomic_set_crtc_for_connector()
  350. * instead.
  351. */
  352. struct drm_crtc *crtc;
  353. struct drm_encoder *best_encoder;
  354. /**
  355. * @link_status: Connector link_status to keep track of whether link is
  356. * GOOD or BAD to notify userspace if retraining is necessary.
  357. */
  358. enum drm_link_status link_status;
  359. struct drm_atomic_state *state;
  360. /**
  361. * @commit: Tracks the pending commit to prevent use-after-free conditions.
  362. *
  363. * Is only set when @crtc is NULL.
  364. */
  365. struct drm_crtc_commit *commit;
  366. struct drm_tv_connector_state tv;
  367. /**
  368. * @picture_aspect_ratio: Connector property to control the
  369. * HDMI infoframe aspect ratio setting.
  370. *
  371. * The %DRM_MODE_PICTURE_ASPECT_\* values much match the
  372. * values for &enum hdmi_picture_aspect
  373. */
  374. enum hdmi_picture_aspect picture_aspect_ratio;
  375. /**
  376. * @scaling_mode: Connector property to control the
  377. * upscaling, mostly used for built-in panels.
  378. */
  379. unsigned int scaling_mode;
  380. /**
  381. * @content_protection: Connector property to request content
  382. * protection. This is most commonly used for HDCP.
  383. */
  384. unsigned int content_protection;
  385. };
  386. /**
  387. * struct drm_connector_funcs - control connectors on a given device
  388. *
  389. * Each CRTC may have one or more connectors attached to it. The functions
  390. * below allow the core DRM code to control connectors, enumerate available modes,
  391. * etc.
  392. */
  393. struct drm_connector_funcs {
  394. /**
  395. * @dpms:
  396. *
  397. * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
  398. * is exposed as a standard property on the connector, but diverted to
  399. * this callback in the drm core. Note that atomic drivers don't
  400. * implement the 4 level DPMS support on the connector any more, but
  401. * instead only have an on/off "ACTIVE" property on the CRTC object.
  402. *
  403. * This hook is not used by atomic drivers, remapping of the legacy DPMS
  404. * property is entirely handled in the DRM core.
  405. *
  406. * RETURNS:
  407. *
  408. * 0 on success or a negative error code on failure.
  409. */
  410. int (*dpms)(struct drm_connector *connector, int mode);
  411. /**
  412. * @reset:
  413. *
  414. * Reset connector hardware and software state to off. This function isn't
  415. * called by the core directly, only through drm_mode_config_reset().
  416. * It's not a helper hook only for historical reasons.
  417. *
  418. * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
  419. * atomic state using this hook.
  420. */
  421. void (*reset)(struct drm_connector *connector);
  422. /**
  423. * @detect:
  424. *
  425. * Check to see if anything is attached to the connector. The parameter
  426. * force is set to false whilst polling, true when checking the
  427. * connector due to a user request. force can be used by the driver to
  428. * avoid expensive, destructive operations during automated probing.
  429. *
  430. * This callback is optional, if not implemented the connector will be
  431. * considered as always being attached.
  432. *
  433. * FIXME:
  434. *
  435. * Note that this hook is only called by the probe helper. It's not in
  436. * the helper library vtable purely for historical reasons. The only DRM
  437. * core entry point to probe connector state is @fill_modes.
  438. *
  439. * Note that the helper library will already hold
  440. * &drm_mode_config.connection_mutex. Drivers which need to grab additional
  441. * locks to avoid races with concurrent modeset changes need to use
  442. * &drm_connector_helper_funcs.detect_ctx instead.
  443. *
  444. * RETURNS:
  445. *
  446. * drm_connector_status indicating the connector's status.
  447. */
  448. enum drm_connector_status (*detect)(struct drm_connector *connector,
  449. bool force);
  450. /**
  451. * @force:
  452. *
  453. * This function is called to update internal encoder state when the
  454. * connector is forced to a certain state by userspace, either through
  455. * the sysfs interfaces or on the kernel cmdline. In that case the
  456. * @detect callback isn't called.
  457. *
  458. * FIXME:
  459. *
  460. * Note that this hook is only called by the probe helper. It's not in
  461. * the helper library vtable purely for historical reasons. The only DRM
  462. * core entry point to probe connector state is @fill_modes.
  463. */
  464. void (*force)(struct drm_connector *connector);
  465. /**
  466. * @fill_modes:
  467. *
  468. * Entry point for output detection and basic mode validation. The
  469. * driver should reprobe the output if needed (e.g. when hotplug
  470. * handling is unreliable), add all detected modes to &drm_connector.modes
  471. * and filter out any the device can't support in any configuration. It
  472. * also needs to filter out any modes wider or higher than the
  473. * parameters max_width and max_height indicate.
  474. *
  475. * The drivers must also prune any modes no longer valid from
  476. * &drm_connector.modes. Furthermore it must update
  477. * &drm_connector.status and &drm_connector.edid. If no EDID has been
  478. * received for this output connector->edid must be NULL.
  479. *
  480. * Drivers using the probe helpers should use
  481. * drm_helper_probe_single_connector_modes() or
  482. * drm_helper_probe_single_connector_modes_nomerge() to implement this
  483. * function.
  484. *
  485. * RETURNS:
  486. *
  487. * The number of modes detected and filled into &drm_connector.modes.
  488. */
  489. int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
  490. /**
  491. * @set_property:
  492. *
  493. * This is the legacy entry point to update a property attached to the
  494. * connector.
  495. *
  496. * This callback is optional if the driver does not support any legacy
  497. * driver-private properties. For atomic drivers it is not used because
  498. * property handling is done entirely in the DRM core.
  499. *
  500. * RETURNS:
  501. *
  502. * 0 on success or a negative error code on failure.
  503. */
  504. int (*set_property)(struct drm_connector *connector, struct drm_property *property,
  505. uint64_t val);
  506. /**
  507. * @late_register:
  508. *
  509. * This optional hook can be used to register additional userspace
  510. * interfaces attached to the connector, light backlight control, i2c,
  511. * DP aux or similar interfaces. It is called late in the driver load
  512. * sequence from drm_connector_register() when registering all the
  513. * core drm connector interfaces. Everything added from this callback
  514. * should be unregistered in the early_unregister callback.
  515. *
  516. * This is called while holding &drm_connector.mutex.
  517. *
  518. * Returns:
  519. *
  520. * 0 on success, or a negative error code on failure.
  521. */
  522. int (*late_register)(struct drm_connector *connector);
  523. /**
  524. * @early_unregister:
  525. *
  526. * This optional hook should be used to unregister the additional
  527. * userspace interfaces attached to the connector from
  528. * late_register(). It is called from drm_connector_unregister(),
  529. * early in the driver unload sequence to disable userspace access
  530. * before data structures are torndown.
  531. *
  532. * This is called while holding &drm_connector.mutex.
  533. */
  534. void (*early_unregister)(struct drm_connector *connector);
  535. /**
  536. * @destroy:
  537. *
  538. * Clean up connector resources. This is called at driver unload time
  539. * through drm_mode_config_cleanup(). It can also be called at runtime
  540. * when a connector is being hot-unplugged for drivers that support
  541. * connector hotplugging (e.g. DisplayPort MST).
  542. */
  543. void (*destroy)(struct drm_connector *connector);
  544. /**
  545. * @atomic_duplicate_state:
  546. *
  547. * Duplicate the current atomic state for this connector and return it.
  548. * The core and helpers guarantee that any atomic state duplicated with
  549. * this hook and still owned by the caller (i.e. not transferred to the
  550. * driver by calling &drm_mode_config_funcs.atomic_commit) will be
  551. * cleaned up by calling the @atomic_destroy_state hook in this
  552. * structure.
  553. *
  554. * Atomic drivers which don't subclass &struct drm_connector_state should use
  555. * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
  556. * state structure to extend it with driver-private state should use
  557. * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
  558. * duplicated in a consistent fashion across drivers.
  559. *
  560. * It is an error to call this hook before &drm_connector.state has been
  561. * initialized correctly.
  562. *
  563. * NOTE:
  564. *
  565. * If the duplicate state references refcounted resources this hook must
  566. * acquire a reference for each of them. The driver must release these
  567. * references again in @atomic_destroy_state.
  568. *
  569. * RETURNS:
  570. *
  571. * Duplicated atomic state or NULL when the allocation failed.
  572. */
  573. struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
  574. /**
  575. * @atomic_destroy_state:
  576. *
  577. * Destroy a state duplicated with @atomic_duplicate_state and release
  578. * or unreference all resources it references
  579. */
  580. void (*atomic_destroy_state)(struct drm_connector *connector,
  581. struct drm_connector_state *state);
  582. /**
  583. * @atomic_set_property:
  584. *
  585. * Decode a driver-private property value and store the decoded value
  586. * into the passed-in state structure. Since the atomic core decodes all
  587. * standardized properties (even for extensions beyond the core set of
  588. * properties which might not be implemented by all drivers) this
  589. * requires drivers to subclass the state structure.
  590. *
  591. * Such driver-private properties should really only be implemented for
  592. * truly hardware/vendor specific state. Instead it is preferred to
  593. * standardize atomic extension and decode the properties used to expose
  594. * such an extension in the core.
  595. *
  596. * Do not call this function directly, use
  597. * drm_atomic_connector_set_property() instead.
  598. *
  599. * This callback is optional if the driver does not support any
  600. * driver-private atomic properties.
  601. *
  602. * NOTE:
  603. *
  604. * This function is called in the state assembly phase of atomic
  605. * modesets, which can be aborted for any reason (including on
  606. * userspace's request to just check whether a configuration would be
  607. * possible). Drivers MUST NOT touch any persistent state (hardware or
  608. * software) or data structures except the passed in @state parameter.
  609. *
  610. * Also since userspace controls in which order properties are set this
  611. * function must not do any input validation (since the state update is
  612. * incomplete and hence likely inconsistent). Instead any such input
  613. * validation must be done in the various atomic_check callbacks.
  614. *
  615. * RETURNS:
  616. *
  617. * 0 if the property has been found, -EINVAL if the property isn't
  618. * implemented by the driver (which shouldn't ever happen, the core only
  619. * asks for properties attached to this connector). No other validation
  620. * is allowed by the driver. The core already checks that the property
  621. * value is within the range (integer, valid enum value, ...) the driver
  622. * set when registering the property.
  623. */
  624. int (*atomic_set_property)(struct drm_connector *connector,
  625. struct drm_connector_state *state,
  626. struct drm_property *property,
  627. uint64_t val);
  628. /**
  629. * @atomic_get_property:
  630. *
  631. * Reads out the decoded driver-private property. This is used to
  632. * implement the GETCONNECTOR IOCTL.
  633. *
  634. * Do not call this function directly, use
  635. * drm_atomic_connector_get_property() instead.
  636. *
  637. * This callback is optional if the driver does not support any
  638. * driver-private atomic properties.
  639. *
  640. * RETURNS:
  641. *
  642. * 0 on success, -EINVAL if the property isn't implemented by the
  643. * driver (which shouldn't ever happen, the core only asks for
  644. * properties attached to this connector).
  645. */
  646. int (*atomic_get_property)(struct drm_connector *connector,
  647. const struct drm_connector_state *state,
  648. struct drm_property *property,
  649. uint64_t *val);
  650. /**
  651. * @atomic_print_state:
  652. *
  653. * If driver subclasses &struct drm_connector_state, it should implement
  654. * this optional hook for printing additional driver specific state.
  655. *
  656. * Do not call this directly, use drm_atomic_connector_print_state()
  657. * instead.
  658. */
  659. void (*atomic_print_state)(struct drm_printer *p,
  660. const struct drm_connector_state *state);
  661. };
  662. /* mode specified on the command line */
  663. struct drm_cmdline_mode {
  664. bool specified;
  665. bool refresh_specified;
  666. bool bpp_specified;
  667. int xres, yres;
  668. int bpp;
  669. int refresh;
  670. bool rb;
  671. bool interlace;
  672. bool cvt;
  673. bool margins;
  674. enum drm_connector_force force;
  675. };
  676. /**
  677. * struct drm_connector - central DRM connector control structure
  678. * @dev: parent DRM device
  679. * @kdev: kernel device for sysfs attributes
  680. * @attr: sysfs attributes
  681. * @head: list management
  682. * @base: base KMS object
  683. * @name: human readable name, can be overwritten by the driver
  684. * @connector_type: one of the DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
  685. * @connector_type_id: index into connector type enum
  686. * @interlace_allowed: can this connector handle interlaced modes?
  687. * @doublescan_allowed: can this connector handle doublescan?
  688. * @stereo_allowed: can this connector handle stereo modes?
  689. * @funcs: connector control functions
  690. * @edid_blob_ptr: DRM property containing EDID if present
  691. * @properties: property tracking for this connector
  692. * @dpms: current dpms state
  693. * @helper_private: mid-layer private data
  694. * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
  695. * @force: a DRM_FORCE_<foo> state for forced mode sets
  696. * @override_edid: has the EDID been overwritten through debugfs for testing?
  697. * @encoder_ids: valid encoders for this connector
  698. * @eld: EDID-like data, if present
  699. * @latency_present: AV delay info from ELD, if found
  700. * @video_latency: video latency info from ELD, if found
  701. * @audio_latency: audio latency info from ELD, if found
  702. * @null_edid_counter: track sinks that give us all zeros for the EDID
  703. * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
  704. * @edid_corrupt: indicates whether the last read EDID was corrupt
  705. * @debugfs_entry: debugfs directory for this connector
  706. * @has_tile: is this connector connected to a tiled monitor
  707. * @tile_group: tile group for the connected monitor
  708. * @tile_is_single_monitor: whether the tile is one monitor housing
  709. * @num_h_tile: number of horizontal tiles in the tile group
  710. * @num_v_tile: number of vertical tiles in the tile group
  711. * @tile_h_loc: horizontal location of this tile
  712. * @tile_v_loc: vertical location of this tile
  713. * @tile_h_size: horizontal size of this tile.
  714. * @tile_v_size: vertical size of this tile.
  715. * @scaling_mode_property: Optional atomic property to control the upscaling.
  716. * @content_protection_property: Optional property to control content protection
  717. *
  718. * Each connector may be connected to one or more CRTCs, or may be clonable by
  719. * another connector if they can share a CRTC. Each connector also has a specific
  720. * position in the broader display (referred to as a 'screen' though it could
  721. * span multiple monitors).
  722. */
  723. struct drm_connector {
  724. struct drm_device *dev;
  725. struct device *kdev;
  726. struct device_attribute *attr;
  727. struct list_head head;
  728. struct drm_mode_object base;
  729. char *name;
  730. /**
  731. * @mutex: Lock for general connector state, but currently only protects
  732. * @registered. Most of the connector state is still protected by
  733. * &drm_mode_config.mutex.
  734. */
  735. struct mutex mutex;
  736. /**
  737. * @index: Compacted connector index, which matches the position inside
  738. * the mode_config.list for drivers not supporting hot-add/removing. Can
  739. * be used as an array index. It is invariant over the lifetime of the
  740. * connector.
  741. */
  742. unsigned index;
  743. int connector_type;
  744. int connector_type_id;
  745. bool interlace_allowed;
  746. bool doublescan_allowed;
  747. bool stereo_allowed;
  748. /**
  749. * @ycbcr_420_allowed : This bool indicates if this connector is
  750. * capable of handling YCBCR 420 output. While parsing the EDID
  751. * blocks, its very helpful to know, if the source is capable of
  752. * handling YCBCR 420 outputs.
  753. */
  754. bool ycbcr_420_allowed;
  755. /**
  756. * @registered: Is this connector exposed (registered) with userspace?
  757. * Protected by @mutex.
  758. */
  759. bool registered;
  760. /**
  761. * @modes:
  762. * Modes available on this connector (from fill_modes() + user).
  763. * Protected by &drm_mode_config.mutex.
  764. */
  765. struct list_head modes;
  766. /**
  767. * @status:
  768. * One of the drm_connector_status enums (connected, not, or unknown).
  769. * Protected by &drm_mode_config.mutex.
  770. */
  771. enum drm_connector_status status;
  772. /**
  773. * @probed_modes:
  774. * These are modes added by probing with DDC or the BIOS, before
  775. * filtering is applied. Used by the probe helpers. Protected by
  776. * &drm_mode_config.mutex.
  777. */
  778. struct list_head probed_modes;
  779. /**
  780. * @display_info: Display information is filled from EDID information
  781. * when a display is detected. For non hot-pluggable displays such as
  782. * flat panels in embedded systems, the driver should initialize the
  783. * &drm_display_info.width_mm and &drm_display_info.height_mm fields
  784. * with the physical size of the display.
  785. *
  786. * Protected by &drm_mode_config.mutex.
  787. */
  788. struct drm_display_info display_info;
  789. const struct drm_connector_funcs *funcs;
  790. struct drm_property_blob *edid_blob_ptr;
  791. struct drm_object_properties properties;
  792. struct drm_property *scaling_mode_property;
  793. /**
  794. * @content_protection_property: DRM ENUM property for content
  795. * protection
  796. */
  797. struct drm_property *content_protection_property;
  798. /**
  799. * @path_blob_ptr:
  800. *
  801. * DRM blob property data for the DP MST path property.
  802. */
  803. struct drm_property_blob *path_blob_ptr;
  804. /**
  805. * @tile_blob_ptr:
  806. *
  807. * DRM blob property data for the tile property (used mostly by DP MST).
  808. * This is meant for screens which are driven through separate display
  809. * pipelines represented by &drm_crtc, which might not be running with
  810. * genlocked clocks. For tiled panels which are genlocked, like
  811. * dual-link LVDS or dual-link DSI, the driver should try to not expose
  812. * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
  813. */
  814. struct drm_property_blob *tile_blob_ptr;
  815. /* should we poll this connector for connects and disconnects */
  816. /* hot plug detectable */
  817. #define DRM_CONNECTOR_POLL_HPD (1 << 0)
  818. /* poll for connections */
  819. #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
  820. /* can cleanly poll for disconnections without flickering the screen */
  821. /* DACs should rarely do this without a lot of testing */
  822. #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
  823. /**
  824. * @polled:
  825. *
  826. * Connector polling mode, a combination of
  827. *
  828. * DRM_CONNECTOR_POLL_HPD
  829. * The connector generates hotplug events and doesn't need to be
  830. * periodically polled. The CONNECT and DISCONNECT flags must not
  831. * be set together with the HPD flag.
  832. *
  833. * DRM_CONNECTOR_POLL_CONNECT
  834. * Periodically poll the connector for connection.
  835. *
  836. * DRM_CONNECTOR_POLL_DISCONNECT
  837. * Periodically poll the connector for disconnection.
  838. *
  839. * Set to 0 for connectors that don't support connection status
  840. * discovery.
  841. */
  842. uint8_t polled;
  843. /* requested DPMS state */
  844. int dpms;
  845. const struct drm_connector_helper_funcs *helper_private;
  846. /* forced on connector */
  847. struct drm_cmdline_mode cmdline_mode;
  848. enum drm_connector_force force;
  849. bool override_edid;
  850. #define DRM_CONNECTOR_MAX_ENCODER 3
  851. uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
  852. /**
  853. * @encoder: Currently bound encoder driving this connector, if any.
  854. * Only really meaningful for non-atomic drivers. Atomic drivers should
  855. * instead look at &drm_connector_state.best_encoder, and in case they
  856. * need the CRTC driving this output, &drm_connector_state.crtc.
  857. */
  858. struct drm_encoder *encoder;
  859. #define MAX_ELD_BYTES 128
  860. /* EDID bits */
  861. uint8_t eld[MAX_ELD_BYTES];
  862. bool latency_present[2];
  863. int video_latency[2]; /* [0]: progressive, [1]: interlaced */
  864. int audio_latency[2];
  865. int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
  866. unsigned bad_edid_counter;
  867. /* Flag for raw EDID header corruption - used in Displayport
  868. * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
  869. */
  870. bool edid_corrupt;
  871. struct dentry *debugfs_entry;
  872. /**
  873. * @state:
  874. *
  875. * Current atomic state for this connector.
  876. *
  877. * This is protected by @drm_mode_config.connection_mutex. Note that
  878. * nonblocking atomic commits access the current connector state without
  879. * taking locks. Either by going through the &struct drm_atomic_state
  880. * pointers, see for_each_oldnew_connector_in_state(),
  881. * for_each_old_connector_in_state() and
  882. * for_each_new_connector_in_state(). Or through careful ordering of
  883. * atomic commit operations as implemented in the atomic helpers, see
  884. * &struct drm_crtc_commit.
  885. */
  886. struct drm_connector_state *state;
  887. /* DisplayID bits */
  888. bool has_tile;
  889. struct drm_tile_group *tile_group;
  890. bool tile_is_single_monitor;
  891. uint8_t num_h_tile, num_v_tile;
  892. uint8_t tile_h_loc, tile_v_loc;
  893. uint16_t tile_h_size, tile_v_size;
  894. /**
  895. * @free_node:
  896. *
  897. * List used only by &drm_connector_iter to be able to clean up a
  898. * connector from any context, in conjunction with
  899. * &drm_mode_config.connector_free_work.
  900. */
  901. struct llist_node free_node;
  902. };
  903. #define obj_to_connector(x) container_of(x, struct drm_connector, base)
  904. int drm_connector_init(struct drm_device *dev,
  905. struct drm_connector *connector,
  906. const struct drm_connector_funcs *funcs,
  907. int connector_type);
  908. int drm_connector_register(struct drm_connector *connector);
  909. void drm_connector_unregister(struct drm_connector *connector);
  910. int drm_mode_connector_attach_encoder(struct drm_connector *connector,
  911. struct drm_encoder *encoder);
  912. void drm_connector_cleanup(struct drm_connector *connector);
  913. static inline unsigned drm_connector_index(struct drm_connector *connector)
  914. {
  915. return connector->index;
  916. }
  917. /**
  918. * drm_connector_lookup - lookup connector object
  919. * @dev: DRM device
  920. * @file_priv: drm file to check for lease against.
  921. * @id: connector object id
  922. *
  923. * This function looks up the connector object specified by id
  924. * add takes a reference to it.
  925. */
  926. static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
  927. struct drm_file *file_priv,
  928. uint32_t id)
  929. {
  930. struct drm_mode_object *mo;
  931. mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_CONNECTOR);
  932. return mo ? obj_to_connector(mo) : NULL;
  933. }
  934. /**
  935. * drm_connector_get - acquire a connector reference
  936. * @connector: DRM connector
  937. *
  938. * This function increments the connector's refcount.
  939. */
  940. static inline void drm_connector_get(struct drm_connector *connector)
  941. {
  942. drm_mode_object_get(&connector->base);
  943. }
  944. /**
  945. * drm_connector_put - release a connector reference
  946. * @connector: DRM connector
  947. *
  948. * This function decrements the connector's reference count and frees the
  949. * object if the reference count drops to zero.
  950. */
  951. static inline void drm_connector_put(struct drm_connector *connector)
  952. {
  953. drm_mode_object_put(&connector->base);
  954. }
  955. /**
  956. * drm_connector_reference - acquire a connector reference
  957. * @connector: DRM connector
  958. *
  959. * This is a compatibility alias for drm_connector_get() and should not be
  960. * used by new code.
  961. */
  962. static inline void drm_connector_reference(struct drm_connector *connector)
  963. {
  964. drm_connector_get(connector);
  965. }
  966. /**
  967. * drm_connector_unreference - release a connector reference
  968. * @connector: DRM connector
  969. *
  970. * This is a compatibility alias for drm_connector_put() and should not be
  971. * used by new code.
  972. */
  973. static inline void drm_connector_unreference(struct drm_connector *connector)
  974. {
  975. drm_connector_put(connector);
  976. }
  977. const char *drm_get_connector_status_name(enum drm_connector_status status);
  978. const char *drm_get_subpixel_order_name(enum subpixel_order order);
  979. const char *drm_get_dpms_name(int val);
  980. const char *drm_get_dvi_i_subconnector_name(int val);
  981. const char *drm_get_dvi_i_select_name(int val);
  982. const char *drm_get_tv_subconnector_name(int val);
  983. const char *drm_get_tv_select_name(int val);
  984. const char *drm_get_content_protection_name(int val);
  985. int drm_mode_create_dvi_i_properties(struct drm_device *dev);
  986. int drm_mode_create_tv_properties(struct drm_device *dev,
  987. unsigned int num_modes,
  988. const char * const modes[]);
  989. int drm_mode_create_scaling_mode_property(struct drm_device *dev);
  990. int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
  991. u32 scaling_mode_mask);
  992. int drm_connector_attach_content_protection_property(
  993. struct drm_connector *connector);
  994. int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
  995. int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
  996. int drm_mode_connector_set_path_property(struct drm_connector *connector,
  997. const char *path);
  998. int drm_mode_connector_set_tile_property(struct drm_connector *connector);
  999. int drm_mode_connector_update_edid_property(struct drm_connector *connector,
  1000. const struct edid *edid);
  1001. void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
  1002. uint64_t link_status);
  1003. int drm_connector_init_panel_orientation_property(
  1004. struct drm_connector *connector, int width, int height);
  1005. /**
  1006. * struct drm_tile_group - Tile group metadata
  1007. * @refcount: reference count
  1008. * @dev: DRM device
  1009. * @id: tile group id exposed to userspace
  1010. * @group_data: Sink-private data identifying this group
  1011. *
  1012. * @group_data corresponds to displayid vend/prod/serial for external screens
  1013. * with an EDID.
  1014. */
  1015. struct drm_tile_group {
  1016. struct kref refcount;
  1017. struct drm_device *dev;
  1018. int id;
  1019. u8 group_data[8];
  1020. };
  1021. struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
  1022. char topology[8]);
  1023. struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
  1024. char topology[8]);
  1025. void drm_mode_put_tile_group(struct drm_device *dev,
  1026. struct drm_tile_group *tg);
  1027. /**
  1028. * struct drm_connector_list_iter - connector_list iterator
  1029. *
  1030. * This iterator tracks state needed to be able to walk the connector_list
  1031. * within struct drm_mode_config. Only use together with
  1032. * drm_connector_list_iter_begin(), drm_connector_list_iter_end() and
  1033. * drm_connector_list_iter_next() respectively the convenience macro
  1034. * drm_for_each_connector_iter().
  1035. */
  1036. struct drm_connector_list_iter {
  1037. /* private: */
  1038. struct drm_device *dev;
  1039. struct drm_connector *conn;
  1040. };
  1041. void drm_connector_list_iter_begin(struct drm_device *dev,
  1042. struct drm_connector_list_iter *iter);
  1043. struct drm_connector *
  1044. drm_connector_list_iter_next(struct drm_connector_list_iter *iter);
  1045. void drm_connector_list_iter_end(struct drm_connector_list_iter *iter);
  1046. /**
  1047. * drm_for_each_connector_iter - connector_list iterator macro
  1048. * @connector: &struct drm_connector pointer used as cursor
  1049. * @iter: &struct drm_connector_list_iter
  1050. *
  1051. * Note that @connector is only valid within the list body, if you want to use
  1052. * @connector after calling drm_connector_list_iter_end() then you need to grab
  1053. * your own reference first using drm_connector_get().
  1054. */
  1055. #define drm_for_each_connector_iter(connector, iter) \
  1056. while ((connector = drm_connector_list_iter_next(iter)))
  1057. #endif