drm_connector.h 33 KB

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