drm_connector.h 33 KB

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