drm_connector.h 35 KB

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