drm_connector.h 34 KB

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