drm_connector.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  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/ctype.h>
  26. #include <linux/hdmi.h>
  27. #include <drm/drm_mode_object.h>
  28. #include <uapi/drm/drm_mode.h>
  29. struct drm_device;
  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. /**
  129. * enum drm_link_status - connector's link_status property value
  130. *
  131. * This enum is used as the connector's link status property value.
  132. * It is set to the values defined in uapi.
  133. *
  134. * @DRM_LINK_STATUS_GOOD: DP Link is Good as a result of successful
  135. * link training
  136. * @DRM_LINK_STATUS_BAD: DP Link is BAD as a result of link training
  137. * failure
  138. */
  139. enum drm_link_status {
  140. DRM_LINK_STATUS_GOOD = DRM_MODE_LINK_STATUS_GOOD,
  141. DRM_LINK_STATUS_BAD = DRM_MODE_LINK_STATUS_BAD,
  142. };
  143. /**
  144. * struct drm_display_info - runtime data about the connected sink
  145. *
  146. * Describes a given display (e.g. CRT or flat panel) and its limitations. For
  147. * fixed display sinks like built-in panels there's not much difference between
  148. * this and &struct drm_connector. But for sinks with a real cable this
  149. * structure is meant to describe all the things at the other end of the cable.
  150. *
  151. * For sinks which provide an EDID this can be filled out by calling
  152. * drm_add_edid_modes().
  153. */
  154. struct drm_display_info {
  155. /**
  156. * @name: Name of the display.
  157. */
  158. char name[DRM_DISPLAY_INFO_LEN];
  159. /**
  160. * @width_mm: Physical width in mm.
  161. */
  162. unsigned int width_mm;
  163. /**
  164. * @height_mm: Physical height in mm.
  165. */
  166. unsigned int height_mm;
  167. /**
  168. * @pixel_clock: Maximum pixel clock supported by the sink, in units of
  169. * 100Hz. This mismatches the clock in &drm_display_mode (which is in
  170. * kHZ), because that's what the EDID uses as base unit.
  171. */
  172. unsigned int pixel_clock;
  173. /**
  174. * @bpc: Maximum bits per color channel. Used by HDMI and DP outputs.
  175. */
  176. unsigned int bpc;
  177. /**
  178. * @subpixel_order: Subpixel order of LCD panels.
  179. */
  180. enum subpixel_order subpixel_order;
  181. #define DRM_COLOR_FORMAT_RGB444 (1<<0)
  182. #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
  183. #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
  184. /**
  185. * @color_formats: HDMI Color formats, selects between RGB and YCrCb
  186. * modes. Used DRM_COLOR_FORMAT\_ defines, which are _not_ the same ones
  187. * as used to describe the pixel format in framebuffers, and also don't
  188. * match the formats in @bus_formats which are shared with v4l.
  189. */
  190. u32 color_formats;
  191. /**
  192. * @bus_formats: Pixel data format on the wire, somewhat redundant with
  193. * @color_formats. Array of size @num_bus_formats encoded using
  194. * MEDIA_BUS_FMT\_ defines shared with v4l and media drivers.
  195. */
  196. const u32 *bus_formats;
  197. /**
  198. * @num_bus_formats: Size of @bus_formats array.
  199. */
  200. unsigned int num_bus_formats;
  201. #define DRM_BUS_FLAG_DE_LOW (1<<0)
  202. #define DRM_BUS_FLAG_DE_HIGH (1<<1)
  203. /* drive data on pos. edge */
  204. #define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
  205. /* drive data on neg. edge */
  206. #define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
  207. /* data is transmitted MSB to LSB on the bus */
  208. #define DRM_BUS_FLAG_DATA_MSB_TO_LSB (1<<4)
  209. /* data is transmitted LSB to MSB on the bus */
  210. #define DRM_BUS_FLAG_DATA_LSB_TO_MSB (1<<5)
  211. /**
  212. * @bus_flags: Additional information (like pixel signal polarity) for
  213. * the pixel data on the bus, using DRM_BUS_FLAGS\_ defines.
  214. */
  215. u32 bus_flags;
  216. /**
  217. * @max_tmds_clock: Maximum TMDS clock rate supported by the
  218. * sink in kHz. 0 means undefined.
  219. */
  220. int max_tmds_clock;
  221. /**
  222. * @dvi_dual: Dual-link DVI sink?
  223. */
  224. bool dvi_dual;
  225. /**
  226. * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even
  227. * more stuff redundant with @bus_formats.
  228. */
  229. u8 edid_hdmi_dc_modes;
  230. /**
  231. * @cea_rev: CEA revision of the HDMI sink.
  232. */
  233. u8 cea_rev;
  234. /**
  235. * @hdmi: advance features of a HDMI sink.
  236. */
  237. struct drm_hdmi_info hdmi;
  238. };
  239. int drm_display_info_set_bus_formats(struct drm_display_info *info,
  240. const u32 *formats,
  241. unsigned int num_formats);
  242. /**
  243. * struct drm_tv_connector_state - TV connector related states
  244. * @subconnector: selected subconnector
  245. * @margins: left/right/top/bottom margins
  246. * @mode: TV mode
  247. * @brightness: brightness in percent
  248. * @contrast: contrast in percent
  249. * @flicker_reduction: flicker reduction in percent
  250. * @overscan: overscan in percent
  251. * @saturation: saturation in percent
  252. * @hue: hue in percent
  253. */
  254. struct drm_tv_connector_state {
  255. enum drm_mode_subconnector subconnector;
  256. struct {
  257. unsigned int left;
  258. unsigned int right;
  259. unsigned int top;
  260. unsigned int bottom;
  261. } margins;
  262. unsigned int mode;
  263. unsigned int brightness;
  264. unsigned int contrast;
  265. unsigned int flicker_reduction;
  266. unsigned int overscan;
  267. unsigned int saturation;
  268. unsigned int hue;
  269. };
  270. /**
  271. * struct drm_connector_state - mutable connector state
  272. * @connector: backpointer to the connector
  273. * @best_encoder: can be used by helpers and drivers to select the encoder
  274. * @state: backpointer to global drm_atomic_state
  275. * @tv: TV connector state
  276. */
  277. struct drm_connector_state {
  278. struct drm_connector *connector;
  279. /**
  280. * @crtc: CRTC to connect connector to, NULL if disabled.
  281. *
  282. * Do not change this directly, use drm_atomic_set_crtc_for_connector()
  283. * instead.
  284. */
  285. struct drm_crtc *crtc;
  286. struct drm_encoder *best_encoder;
  287. /**
  288. * @link_status: Connector link_status to keep track of whether link is
  289. * GOOD or BAD to notify userspace if retraining is necessary.
  290. */
  291. enum drm_link_status link_status;
  292. struct drm_atomic_state *state;
  293. struct drm_tv_connector_state tv;
  294. /**
  295. * @picture_aspect_ratio: Connector property to control the
  296. * HDMI infoframe aspect ratio setting.
  297. *
  298. * The %DRM_MODE_PICTURE_ASPECT_\* values much match the
  299. * values for &enum hdmi_picture_aspect
  300. */
  301. enum hdmi_picture_aspect picture_aspect_ratio;
  302. /**
  303. * @scaling_mode: Connector property to control the
  304. * upscaling, mostly used for built-in panels.
  305. */
  306. unsigned int scaling_mode;
  307. };
  308. /**
  309. * struct drm_connector_funcs - control connectors on a given device
  310. *
  311. * Each CRTC may have one or more connectors attached to it. The functions
  312. * below allow the core DRM code to control connectors, enumerate available modes,
  313. * etc.
  314. */
  315. struct drm_connector_funcs {
  316. /**
  317. * @dpms:
  318. *
  319. * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
  320. * is exposed as a standard property on the connector, but diverted to
  321. * this callback in the drm core. Note that atomic drivers don't
  322. * implement the 4 level DPMS support on the connector any more, but
  323. * instead only have an on/off "ACTIVE" property on the CRTC object.
  324. *
  325. * Drivers implementing atomic modeset should use
  326. * drm_atomic_helper_connector_dpms() to implement this hook.
  327. *
  328. * RETURNS:
  329. *
  330. * 0 on success or a negative error code on failure.
  331. */
  332. int (*dpms)(struct drm_connector *connector, int mode);
  333. /**
  334. * @reset:
  335. *
  336. * Reset connector hardware and software state to off. This function isn't
  337. * called by the core directly, only through drm_mode_config_reset().
  338. * It's not a helper hook only for historical reasons.
  339. *
  340. * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
  341. * atomic state using this hook.
  342. */
  343. void (*reset)(struct drm_connector *connector);
  344. /**
  345. * @detect:
  346. *
  347. * Check to see if anything is attached to the connector. The parameter
  348. * force is set to false whilst polling, true when checking the
  349. * connector due to a user request. force can be used by the driver to
  350. * avoid expensive, destructive operations during automated probing.
  351. *
  352. * This callback is optional, if not implemented the connector will be
  353. * considered as always being attached.
  354. *
  355. * FIXME:
  356. *
  357. * Note that this hook is only called by the probe helper. It's not in
  358. * the helper library vtable purely for historical reasons. The only DRM
  359. * core entry point to probe connector state is @fill_modes.
  360. *
  361. * Note that the helper library will already hold
  362. * &drm_mode_config.connection_mutex. Drivers which need to grab additional
  363. * locks to avoid races with concurrent modeset changes need to use
  364. * &drm_connector_helper_funcs.detect_ctx instead.
  365. *
  366. * RETURNS:
  367. *
  368. * drm_connector_status indicating the connector's status.
  369. */
  370. enum drm_connector_status (*detect)(struct drm_connector *connector,
  371. bool force);
  372. /**
  373. * @force:
  374. *
  375. * This function is called to update internal encoder state when the
  376. * connector is forced to a certain state by userspace, either through
  377. * the sysfs interfaces or on the kernel cmdline. In that case the
  378. * @detect callback isn't called.
  379. *
  380. * FIXME:
  381. *
  382. * Note that this hook is only called by the probe helper. It's not in
  383. * the helper library vtable purely for historical reasons. The only DRM
  384. * core entry point to probe connector state is @fill_modes.
  385. */
  386. void (*force)(struct drm_connector *connector);
  387. /**
  388. * @fill_modes:
  389. *
  390. * Entry point for output detection and basic mode validation. The
  391. * driver should reprobe the output if needed (e.g. when hotplug
  392. * handling is unreliable), add all detected modes to &drm_connector.modes
  393. * and filter out any the device can't support in any configuration. It
  394. * also needs to filter out any modes wider or higher than the
  395. * parameters max_width and max_height indicate.
  396. *
  397. * The drivers must also prune any modes no longer valid from
  398. * &drm_connector.modes. Furthermore it must update
  399. * &drm_connector.status and &drm_connector.edid. If no EDID has been
  400. * received for this output connector->edid must be NULL.
  401. *
  402. * Drivers using the probe helpers should use
  403. * drm_helper_probe_single_connector_modes() or
  404. * drm_helper_probe_single_connector_modes_nomerge() to implement this
  405. * function.
  406. *
  407. * RETURNS:
  408. *
  409. * The number of modes detected and filled into &drm_connector.modes.
  410. */
  411. int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
  412. /**
  413. * @set_property:
  414. *
  415. * This is the legacy entry point to update a property attached to the
  416. * connector.
  417. *
  418. * Drivers implementing atomic modeset should use
  419. * drm_atomic_helper_connector_set_property() to implement this hook.
  420. *
  421. * This callback is optional if the driver does not support any legacy
  422. * driver-private properties.
  423. *
  424. * RETURNS:
  425. *
  426. * 0 on success or a negative error code on failure.
  427. */
  428. int (*set_property)(struct drm_connector *connector, struct drm_property *property,
  429. uint64_t val);
  430. /**
  431. * @late_register:
  432. *
  433. * This optional hook can be used to register additional userspace
  434. * interfaces attached to the connector, light backlight control, i2c,
  435. * DP aux or similar interfaces. It is called late in the driver load
  436. * sequence from drm_connector_register() when registering all the
  437. * core drm connector interfaces. Everything added from this callback
  438. * should be unregistered in the early_unregister callback.
  439. *
  440. * This is called while holding &drm_connector.mutex.
  441. *
  442. * Returns:
  443. *
  444. * 0 on success, or a negative error code on failure.
  445. */
  446. int (*late_register)(struct drm_connector *connector);
  447. /**
  448. * @early_unregister:
  449. *
  450. * This optional hook should be used to unregister the additional
  451. * userspace interfaces attached to the connector from
  452. * late_register(). It is called from drm_connector_unregister(),
  453. * early in the driver unload sequence to disable userspace access
  454. * before data structures are torndown.
  455. *
  456. * This is called while holding &drm_connector.mutex.
  457. */
  458. void (*early_unregister)(struct drm_connector *connector);
  459. /**
  460. * @destroy:
  461. *
  462. * Clean up connector resources. This is called at driver unload time
  463. * through drm_mode_config_cleanup(). It can also be called at runtime
  464. * when a connector is being hot-unplugged for drivers that support
  465. * connector hotplugging (e.g. DisplayPort MST).
  466. */
  467. void (*destroy)(struct drm_connector *connector);
  468. /**
  469. * @atomic_duplicate_state:
  470. *
  471. * Duplicate the current atomic state for this connector and return it.
  472. * The core and helpers guarantee that any atomic state duplicated with
  473. * this hook and still owned by the caller (i.e. not transferred to the
  474. * driver by calling &drm_mode_config_funcs.atomic_commit) will be
  475. * cleaned up by calling the @atomic_destroy_state hook in this
  476. * structure.
  477. *
  478. * Atomic drivers which don't subclass &struct drm_connector_state should use
  479. * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
  480. * state structure to extend it with driver-private state should use
  481. * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
  482. * duplicated in a consistent fashion across drivers.
  483. *
  484. * It is an error to call this hook before &drm_connector.state has been
  485. * initialized correctly.
  486. *
  487. * NOTE:
  488. *
  489. * If the duplicate state references refcounted resources this hook must
  490. * acquire a reference for each of them. The driver must release these
  491. * references again in @atomic_destroy_state.
  492. *
  493. * RETURNS:
  494. *
  495. * Duplicated atomic state or NULL when the allocation failed.
  496. */
  497. struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
  498. /**
  499. * @atomic_destroy_state:
  500. *
  501. * Destroy a state duplicated with @atomic_duplicate_state and release
  502. * or unreference all resources it references
  503. */
  504. void (*atomic_destroy_state)(struct drm_connector *connector,
  505. struct drm_connector_state *state);
  506. /**
  507. * @atomic_set_property:
  508. *
  509. * Decode a driver-private property value and store the decoded value
  510. * into the passed-in state structure. Since the atomic core decodes all
  511. * standardized properties (even for extensions beyond the core set of
  512. * properties which might not be implemented by all drivers) this
  513. * requires drivers to subclass the state structure.
  514. *
  515. * Such driver-private properties should really only be implemented for
  516. * truly hardware/vendor specific state. Instead it is preferred to
  517. * standardize atomic extension and decode the properties used to expose
  518. * such an extension in the core.
  519. *
  520. * Do not call this function directly, use
  521. * drm_atomic_connector_set_property() instead.
  522. *
  523. * This callback is optional if the driver does not support any
  524. * driver-private atomic properties.
  525. *
  526. * NOTE:
  527. *
  528. * This function is called in the state assembly phase of atomic
  529. * modesets, which can be aborted for any reason (including on
  530. * userspace's request to just check whether a configuration would be
  531. * possible). Drivers MUST NOT touch any persistent state (hardware or
  532. * software) or data structures except the passed in @state parameter.
  533. *
  534. * Also since userspace controls in which order properties are set this
  535. * function must not do any input validation (since the state update is
  536. * incomplete and hence likely inconsistent). Instead any such input
  537. * validation must be done in the various atomic_check callbacks.
  538. *
  539. * RETURNS:
  540. *
  541. * 0 if the property has been found, -EINVAL if the property isn't
  542. * implemented by the driver (which shouldn't ever happen, the core only
  543. * asks for properties attached to this connector). No other validation
  544. * is allowed by the driver. The core already checks that the property
  545. * value is within the range (integer, valid enum value, ...) the driver
  546. * set when registering the property.
  547. */
  548. int (*atomic_set_property)(struct drm_connector *connector,
  549. struct drm_connector_state *state,
  550. struct drm_property *property,
  551. uint64_t val);
  552. /**
  553. * @atomic_get_property:
  554. *
  555. * Reads out the decoded driver-private property. This is used to
  556. * implement the GETCONNECTOR IOCTL.
  557. *
  558. * Do not call this function directly, use
  559. * drm_atomic_connector_get_property() instead.
  560. *
  561. * This callback is optional if the driver does not support any
  562. * driver-private atomic properties.
  563. *
  564. * RETURNS:
  565. *
  566. * 0 on success, -EINVAL if the property isn't implemented by the
  567. * driver (which shouldn't ever happen, the core only asks for
  568. * properties attached to this connector).
  569. */
  570. int (*atomic_get_property)(struct drm_connector *connector,
  571. const struct drm_connector_state *state,
  572. struct drm_property *property,
  573. uint64_t *val);
  574. /**
  575. * @atomic_print_state:
  576. *
  577. * If driver subclasses &struct drm_connector_state, it should implement
  578. * this optional hook for printing additional driver specific state.
  579. *
  580. * Do not call this directly, use drm_atomic_connector_print_state()
  581. * instead.
  582. */
  583. void (*atomic_print_state)(struct drm_printer *p,
  584. const struct drm_connector_state *state);
  585. };
  586. /* mode specified on the command line */
  587. struct drm_cmdline_mode {
  588. bool specified;
  589. bool refresh_specified;
  590. bool bpp_specified;
  591. int xres, yres;
  592. int bpp;
  593. int refresh;
  594. bool rb;
  595. bool interlace;
  596. bool cvt;
  597. bool margins;
  598. enum drm_connector_force force;
  599. };
  600. /**
  601. * struct drm_connector - central DRM connector control structure
  602. * @dev: parent DRM device
  603. * @kdev: kernel device for sysfs attributes
  604. * @attr: sysfs attributes
  605. * @head: list management
  606. * @base: base KMS object
  607. * @name: human readable name, can be overwritten by the driver
  608. * @connector_type: one of the DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
  609. * @connector_type_id: index into connector type enum
  610. * @interlace_allowed: can this connector handle interlaced modes?
  611. * @doublescan_allowed: can this connector handle doublescan?
  612. * @stereo_allowed: can this connector handle stereo modes?
  613. * @funcs: connector control functions
  614. * @edid_blob_ptr: DRM property containing EDID if present
  615. * @properties: property tracking for this connector
  616. * @dpms: current dpms state
  617. * @helper_private: mid-layer private data
  618. * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
  619. * @force: a DRM_FORCE_<foo> state for forced mode sets
  620. * @override_edid: has the EDID been overwritten through debugfs for testing?
  621. * @encoder_ids: valid encoders for this connector
  622. * @encoder: encoder driving this connector, if any
  623. * @eld: EDID-like data, if present
  624. * @latency_present: AV delay info from ELD, if found
  625. * @video_latency: video latency info from ELD, if found
  626. * @audio_latency: audio latency info from ELD, if found
  627. * @null_edid_counter: track sinks that give us all zeros for the EDID
  628. * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
  629. * @edid_corrupt: indicates whether the last read EDID was corrupt
  630. * @debugfs_entry: debugfs directory for this connector
  631. * @has_tile: is this connector connected to a tiled monitor
  632. * @tile_group: tile group for the connected monitor
  633. * @tile_is_single_monitor: whether the tile is one monitor housing
  634. * @num_h_tile: number of horizontal tiles in the tile group
  635. * @num_v_tile: number of vertical tiles in the tile group
  636. * @tile_h_loc: horizontal location of this tile
  637. * @tile_v_loc: vertical location of this tile
  638. * @tile_h_size: horizontal size of this tile.
  639. * @tile_v_size: vertical size of this tile.
  640. * @scaling_mode_property: Optional atomic property to control the upscaling.
  641. *
  642. * Each connector may be connected to one or more CRTCs, or may be clonable by
  643. * another connector if they can share a CRTC. Each connector also has a specific
  644. * position in the broader display (referred to as a 'screen' though it could
  645. * span multiple monitors).
  646. */
  647. struct drm_connector {
  648. struct drm_device *dev;
  649. struct device *kdev;
  650. struct device_attribute *attr;
  651. struct list_head head;
  652. struct drm_mode_object base;
  653. char *name;
  654. /**
  655. * @mutex: Lock for general connector state, but currently only protects
  656. * @registered. Most of the connector state is still protected by
  657. * &drm_mode_config.mutex.
  658. */
  659. struct mutex mutex;
  660. /**
  661. * @index: Compacted connector index, which matches the position inside
  662. * the mode_config.list for drivers not supporting hot-add/removing. Can
  663. * be used as an array index. It is invariant over the lifetime of the
  664. * connector.
  665. */
  666. unsigned index;
  667. int connector_type;
  668. int connector_type_id;
  669. bool interlace_allowed;
  670. bool doublescan_allowed;
  671. bool stereo_allowed;
  672. /**
  673. * @registered: Is this connector exposed (registered) with userspace?
  674. * Protected by @mutex.
  675. */
  676. bool registered;
  677. /**
  678. * @modes:
  679. * Modes available on this connector (from fill_modes() + user).
  680. * Protected by &drm_mode_config.mutex.
  681. */
  682. struct list_head modes;
  683. /**
  684. * @status:
  685. * One of the drm_connector_status enums (connected, not, or unknown).
  686. * Protected by &drm_mode_config.mutex.
  687. */
  688. enum drm_connector_status status;
  689. /**
  690. * @probed_modes:
  691. * These are modes added by probing with DDC or the BIOS, before
  692. * filtering is applied. Used by the probe helpers. Protected by
  693. * &drm_mode_config.mutex.
  694. */
  695. struct list_head probed_modes;
  696. /**
  697. * @display_info: Display information is filled from EDID information
  698. * when a display is detected. For non hot-pluggable displays such as
  699. * flat panels in embedded systems, the driver should initialize the
  700. * &drm_display_info.width_mm and &drm_display_info.height_mm fields
  701. * with the physical size of the display.
  702. *
  703. * Protected by &drm_mode_config.mutex.
  704. */
  705. struct drm_display_info display_info;
  706. const struct drm_connector_funcs *funcs;
  707. struct drm_property_blob *edid_blob_ptr;
  708. struct drm_object_properties properties;
  709. struct drm_property *scaling_mode_property;
  710. /**
  711. * @path_blob_ptr:
  712. *
  713. * DRM blob property data for the DP MST path property.
  714. */
  715. struct drm_property_blob *path_blob_ptr;
  716. /**
  717. * @tile_blob_ptr:
  718. *
  719. * DRM blob property data for the tile property (used mostly by DP MST).
  720. * This is meant for screens which are driven through separate display
  721. * pipelines represented by &drm_crtc, which might not be running with
  722. * genlocked clocks. For tiled panels which are genlocked, like
  723. * dual-link LVDS or dual-link DSI, the driver should try to not expose
  724. * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
  725. */
  726. struct drm_property_blob *tile_blob_ptr;
  727. /* should we poll this connector for connects and disconnects */
  728. /* hot plug detectable */
  729. #define DRM_CONNECTOR_POLL_HPD (1 << 0)
  730. /* poll for connections */
  731. #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
  732. /* can cleanly poll for disconnections without flickering the screen */
  733. /* DACs should rarely do this without a lot of testing */
  734. #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
  735. /**
  736. * @polled:
  737. *
  738. * Connector polling mode, a combination of
  739. *
  740. * DRM_CONNECTOR_POLL_HPD
  741. * The connector generates hotplug events and doesn't need to be
  742. * periodically polled. The CONNECT and DISCONNECT flags must not
  743. * be set together with the HPD flag.
  744. *
  745. * DRM_CONNECTOR_POLL_CONNECT
  746. * Periodically poll the connector for connection.
  747. *
  748. * DRM_CONNECTOR_POLL_DISCONNECT
  749. * Periodically poll the connector for disconnection.
  750. *
  751. * Set to 0 for connectors that don't support connection status
  752. * discovery.
  753. */
  754. uint8_t polled;
  755. /* requested DPMS state */
  756. int dpms;
  757. const struct drm_connector_helper_funcs *helper_private;
  758. /* forced on connector */
  759. struct drm_cmdline_mode cmdline_mode;
  760. enum drm_connector_force force;
  761. bool override_edid;
  762. #define DRM_CONNECTOR_MAX_ENCODER 3
  763. uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
  764. struct drm_encoder *encoder; /* currently active encoder */
  765. #define MAX_ELD_BYTES 128
  766. /* EDID bits */
  767. uint8_t eld[MAX_ELD_BYTES];
  768. bool latency_present[2];
  769. int video_latency[2]; /* [0]: progressive, [1]: interlaced */
  770. int audio_latency[2];
  771. int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
  772. unsigned bad_edid_counter;
  773. /* Flag for raw EDID header corruption - used in Displayport
  774. * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
  775. */
  776. bool edid_corrupt;
  777. struct dentry *debugfs_entry;
  778. /**
  779. * @state:
  780. *
  781. * Current atomic state for this connector.
  782. *
  783. * This is protected by @drm_mode_config.connection_mutex. Note that
  784. * nonblocking atomic commits access the current connector state without
  785. * taking locks. Either by going through the &struct drm_atomic_state
  786. * pointers, see for_each_connector_in_state(),
  787. * for_each_oldnew_connector_in_state(),
  788. * for_each_old_connector_in_state() and
  789. * for_each_new_connector_in_state(). Or through careful ordering of
  790. * atomic commit operations as implemented in the atomic helpers, see
  791. * &struct drm_crtc_commit.
  792. */
  793. struct drm_connector_state *state;
  794. /* DisplayID bits */
  795. bool has_tile;
  796. struct drm_tile_group *tile_group;
  797. bool tile_is_single_monitor;
  798. uint8_t num_h_tile, num_v_tile;
  799. uint8_t tile_h_loc, tile_v_loc;
  800. uint16_t tile_h_size, tile_v_size;
  801. };
  802. #define obj_to_connector(x) container_of(x, struct drm_connector, base)
  803. int drm_connector_init(struct drm_device *dev,
  804. struct drm_connector *connector,
  805. const struct drm_connector_funcs *funcs,
  806. int connector_type);
  807. int drm_connector_register(struct drm_connector *connector);
  808. void drm_connector_unregister(struct drm_connector *connector);
  809. int drm_mode_connector_attach_encoder(struct drm_connector *connector,
  810. struct drm_encoder *encoder);
  811. void drm_connector_cleanup(struct drm_connector *connector);
  812. static inline unsigned drm_connector_index(struct drm_connector *connector)
  813. {
  814. return connector->index;
  815. }
  816. /**
  817. * drm_connector_lookup - lookup connector object
  818. * @dev: DRM device
  819. * @id: connector object id
  820. *
  821. * This function looks up the connector object specified by id
  822. * add takes a reference to it.
  823. */
  824. static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
  825. uint32_t id)
  826. {
  827. struct drm_mode_object *mo;
  828. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
  829. return mo ? obj_to_connector(mo) : NULL;
  830. }
  831. /**
  832. * drm_connector_get - acquire a connector reference
  833. * @connector: DRM connector
  834. *
  835. * This function increments the connector's refcount.
  836. */
  837. static inline void drm_connector_get(struct drm_connector *connector)
  838. {
  839. drm_mode_object_get(&connector->base);
  840. }
  841. /**
  842. * drm_connector_put - release a connector reference
  843. * @connector: DRM connector
  844. *
  845. * This function decrements the connector's reference count and frees the
  846. * object if the reference count drops to zero.
  847. */
  848. static inline void drm_connector_put(struct drm_connector *connector)
  849. {
  850. drm_mode_object_put(&connector->base);
  851. }
  852. /**
  853. * drm_connector_reference - acquire a connector reference
  854. * @connector: DRM connector
  855. *
  856. * This is a compatibility alias for drm_connector_get() and should not be
  857. * used by new code.
  858. */
  859. static inline void drm_connector_reference(struct drm_connector *connector)
  860. {
  861. drm_connector_get(connector);
  862. }
  863. /**
  864. * drm_connector_unreference - release a connector reference
  865. * @connector: DRM connector
  866. *
  867. * This is a compatibility alias for drm_connector_put() and should not be
  868. * used by new code.
  869. */
  870. static inline void drm_connector_unreference(struct drm_connector *connector)
  871. {
  872. drm_connector_put(connector);
  873. }
  874. const char *drm_get_connector_status_name(enum drm_connector_status status);
  875. const char *drm_get_subpixel_order_name(enum subpixel_order order);
  876. const char *drm_get_dpms_name(int val);
  877. const char *drm_get_dvi_i_subconnector_name(int val);
  878. const char *drm_get_dvi_i_select_name(int val);
  879. const char *drm_get_tv_subconnector_name(int val);
  880. const char *drm_get_tv_select_name(int val);
  881. int drm_mode_create_dvi_i_properties(struct drm_device *dev);
  882. int drm_mode_create_tv_properties(struct drm_device *dev,
  883. unsigned int num_modes,
  884. const char * const modes[]);
  885. int drm_mode_create_scaling_mode_property(struct drm_device *dev);
  886. int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
  887. u32 scaling_mode_mask);
  888. int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
  889. int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
  890. int drm_mode_connector_set_path_property(struct drm_connector *connector,
  891. const char *path);
  892. int drm_mode_connector_set_tile_property(struct drm_connector *connector);
  893. int drm_mode_connector_update_edid_property(struct drm_connector *connector,
  894. const struct edid *edid);
  895. void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
  896. uint64_t link_status);
  897. /**
  898. * struct drm_tile_group - Tile group metadata
  899. * @refcount: reference count
  900. * @dev: DRM device
  901. * @id: tile group id exposed to userspace
  902. * @group_data: Sink-private data identifying this group
  903. *
  904. * @group_data corresponds to displayid vend/prod/serial for external screens
  905. * with an EDID.
  906. */
  907. struct drm_tile_group {
  908. struct kref refcount;
  909. struct drm_device *dev;
  910. int id;
  911. u8 group_data[8];
  912. };
  913. struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
  914. char topology[8]);
  915. struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
  916. char topology[8]);
  917. void drm_mode_put_tile_group(struct drm_device *dev,
  918. struct drm_tile_group *tg);
  919. /**
  920. * drm_for_each_connector - iterate over all connectors
  921. * @connector: the loop cursor
  922. * @dev: the DRM device
  923. *
  924. * Iterate over all connectors of @dev.
  925. *
  926. * WARNING:
  927. *
  928. * This iterator is not safe against hotadd/removal of connectors and is
  929. * deprecated. Use drm_for_each_connector_iter() instead.
  930. */
  931. #define drm_for_each_connector(connector, dev) \
  932. list_for_each_entry(connector, &(dev)->mode_config.connector_list, head)
  933. /**
  934. * struct drm_connector_list_iter - connector_list iterator
  935. *
  936. * This iterator tracks state needed to be able to walk the connector_list
  937. * within struct drm_mode_config. Only use together with
  938. * drm_connector_list_iter_begin(), drm_connector_list_iter_end() and
  939. * drm_connector_list_iter_next() respectively the convenience macro
  940. * drm_for_each_connector_iter().
  941. */
  942. struct drm_connector_list_iter {
  943. /* private: */
  944. struct drm_device *dev;
  945. struct drm_connector *conn;
  946. };
  947. void drm_connector_list_iter_begin(struct drm_device *dev,
  948. struct drm_connector_list_iter *iter);
  949. struct drm_connector *
  950. drm_connector_list_iter_next(struct drm_connector_list_iter *iter);
  951. void drm_connector_list_iter_end(struct drm_connector_list_iter *iter);
  952. /**
  953. * drm_for_each_connector_iter - connector_list iterator macro
  954. * @connector: &struct drm_connector pointer used as cursor
  955. * @iter: &struct drm_connector_list_iter
  956. *
  957. * Note that @connector is only valid within the list body, if you want to use
  958. * @connector after calling drm_connector_list_iter_end() then you need to grab
  959. * your own reference first using drm_connector_begin().
  960. */
  961. #define drm_for_each_connector_iter(connector, iter) \
  962. while ((connector = drm_connector_list_iter_next(iter)))
  963. #endif