drm/mediatek: Add MT8195 DisplayPort driver
Subsystems (6)
v12 cover drm/mediatek: Add MT8195 DisplayPort driver
This patch is separated from v10 which is including dp driver, phy driver and dpintf driver. This series is only contained the DisplayPort driver.
This series can be tested using 5.19-rc2 kernel and I test it in MT8195 Tomato Chromebook. Modetest these modes:
for eDP:
#0 2256x1504 60.00 2256 2304 2336 2536 1504 1507 1513 1549 235690 flags: phsync, nvsync; type: preferred, driver #1 2256x1504 48.00 2256 2304 2336 2536 1504 1507 1513 1549 188550 flags: phsync, nvsync; type: driver
for DP:
#0 1920x1080 60.00 1920 2008 2052 2200 1080 1084 1089 1125 148500 flags: phsync, pvsync; type: preferred, driver #1 1920x1080 59.94 1920 2008 2052 2200 1080 1084 1089 1125 148352 flags: phsync, pvsync; type: driver #2 1920x1080 50.00 1920 2448 2492 2640 1080 1084 1089 1125 148500 flags: phsync, pvsync; type: driver #3 1680x1050 59.95 1680 1784 1960 2240 1050 1053 1059 1089 146250 flags: nhsync, pvsync; type: driver #4 1600x900 60.00 1600 1624 1704 1800 900 901 904 1000 108000 flags: phsync, pvsync; type: driver #5 1280x1024 60.02 1280 1328 1440 1688 1024 1025 1028 1066 108000 flags: phsync, pvsync; type: driver #6 1280x800 59.81 1280 1352 1480 1680 800 803 809 831 83500 flags: nhsync, pvsync; type: driver #7 1280x720 60.00 1280 1390 1430 1650 720 725 730 750 74250 flags: phsync, pvsync; type: driver #8 1280x720 59.94 1280 1390 1430 1650 720 725 730 750 74176 flags: phsync, pvsync; type: driver #9 1280x720 50.00 1280 1720 1760 1980 720 725 730 750 74250 flags: phsync, pvsync; type: driver #10 1024x768 60.00 1024 1048 1184 1344 768 771 777 806 65000 flags: nhsync, nvsync; type: driver #11 800x600 60.32 800 840 968 1056 600 601 605 628 40000 flags: phsync, pvsync; type: driver #12 720x576 50.00 720 732 796 864 576 581 586 625 27000 flags: nhsync, nvsync; type: driver #13 720x480 60.00 720 736 798 858 480 489 495 525 27027 flags: nhsync, nvsync; type: driver #14 720x480 59.94 720 736 798 858 480 489 495 525 27000 flags: nhsync, nvsync; type: driver #15 640x480 60.00 640 656 752 800 480 490 492 525 25200 flags: nhsync, nvsync; type: driver #16 640x480 59.94 640 656 752 800 480 490 492 525 25175 flags: nhsync, nvsync; type: driver
Changes from v11 for dp driver:
dt-binding:
- Use data-lanes to determine the max supported lane numbers.
- Add mhz to max-linkrate to show the units.
embedded dp drivers:
- Modify Makefile.
- Drop some unused/redundant drivers.
- Move some features to patches of external dp and audio.
- Modify break condition of training loop to control cr/eq fail.
- Replace some function/definition with ones of common drm drivers.
- Remove dp_lock mutex because it's only locked in power_on/off.
- Add drm_dp_aux_(un)register in mtk_dp_bridge_(de)attach.
Changes from v10 for dp driver:
- Drop return value for write registers to make code more clear.
- Refine training state.
- Add property for dt-binding.
- Add new bug fix patches for audio and suspend.
- Rebase to v5.19-rc1.
Changes from v9:
- The DP-Phy is back to being a child device of the DP driver (as in v8)
- hot plug detection has been added back to Embedded Display Port... as after discussing with mediatek experts, this is needed eventhough the Embedded Display port is not un-pluggable
- rebased on linux-next
- simplified/split train_handler function, as suggested by Rex
- added comments on the sleep/delays present in the code
- removed previous patch introducing retries when receiving AUX_DEFER as this is already handled in the dp_aux framework
- added max-lane and max-linkrate device tree u8 properties instead of hardcoded #defines
Older revisions:
RFC - https://lore.kernel.org/linux-mediatek/[email protected]/
v1 - https://lore.kernel.org/linux-mediatek/[email protected]/ v2 - https://lore.kernel.org/linux-mediatek/[email protected]/ v3 - https://lore.kernel.org/linux-mediatek/[email protected]/ v4 - https://lore.kernel.org/linux-mediatek/[email protected]/ v5 - https://lore.kernel.org/all/[email protected]/ v6 - https://lore.kernel.org/linux-mediatek/[email protected]/ v7 - https://lore.kernel.org/linux-mediatek/[email protected]/ v8 - https://lore.kernel.org/linux-mediatek/[email protected]/ v9 - https://lore.kernel.org/all/[email protected]/
v10 - https://lore.kernel.org/all/[email protected]/
v11 - https://lore.kernel.org/r/[email protected]
Functional dependencies are:
- Add Mediatek Soc DRM (vdosys0) support for mt8195
https://lore.kernel.org/all/[email protected]/
- Add MediaTek SoC DRM (vdosys1) support for mt8195
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
Bo-Chen Chen (2):
drm/mediatek: set monitor to DP_SET_POWER_D3 to avoid garbage drm/mediatek: fix no audio when resolution change
Guillaume Ranquet (4):
drm/edid: Convert cea_sad helper struct to kernelDoc drm/edid: Add cea_sad helpers for freq/length drm/mediatek: Add MT8195 External DisplayPort support drm/mediatek: DP audio support for MT8195
Jitao Shi (1):
drm/mediatek: add hpd debounce
Markus Schneider-Pargmann (3):
dt-bindings: mediatek,dp: Add Display Port binding video/hdmi: Add audio_infoframe packing for DP drm/mediatek: Add MT8195 Embedded DisplayPort driver
.../display/mediatek/mediatek,dp.yaml | 108 + drivers/gpu/drm/drm_edid.c | 73 + drivers/gpu/drm/mediatek/Kconfig | 10 + drivers/gpu/drm/mediatek/Makefile | 1 + drivers/gpu/drm/mediatek/mtk_dp.c | 3042 +++++++++++++++++ drivers/gpu/drm/mediatek/mtk_dp_reg.h | 545 +++ drivers/gpu/drm/mediatek/mtk_drm_drv.c | 3 + drivers/gpu/drm/mediatek/mtk_drm_drv.h | 3 + drivers/video/hdmi.c | 82 +- include/drm/display/drm_dp.h | 2 + include/drm/drm_edid.h | 26 +- include/linux/hdmi.h | 7 +- 12 files changed, 3879 insertions(+), 23 deletions(-) create mode 100644 Documentation/devicetree/bindings/display/mediatek/mediatek,dp.yaml create mode 100644 drivers/gpu/drm/mediatek/mtk_dp.c create mode 100644 drivers/gpu/drm/mediatek/mtk_dp_reg.h
Signature · 1 line
2.18.0
PATCH v12 1/10 dt-bindings: mediatek,dp: Add Display Port binding
From: Markus Schneider-Pargmann <[email protected]>
This controller is present on several mediatek hardware. Currently mt8195 and mt8395 have this controller without a functional difference, so only one compatible field is added.
The controller can have two forms, as a normal display port and as an embedded display port.
--- .../display/mediatek/mediatek,dp.yaml | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/mediatek/mediatek,dp.yaml
Documentation/devicetree/bindings/display/mediatek/mediatek,dp.yaml new file +108 -0
@@ -0,0 +1,108 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/mediatek/mediatek,dp.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek Display Port Controller + +maintainers: + - Chun-Kuang Hu <[email protected]> + - Jitao shi <[email protected]> + +description: | + Device tree bindings for the MediaTek display port and + embedded display port controller present on some MediaTek SoCs. + +properties: + compatible: + enum: + - mediatek,mt8195-dp-tx + - mediatek,mt8195-edp-tx + + reg: + maxItems: 1 + + nvmem-cells: + maxItems: 1 + description: efuse data for display port calibration + + nvmem-cell-names: + const: dp_calibration_data + + power-domains: + maxItems: 1 + + interrupts: + maxItems: 1 + + ports: + $ref: /schemas/graph.yaml#/properties/ports + properties: + port@0: + $ref: /schemas/graph.yaml#/properties/port + description: Input endpoint of the controller, usually dp_intf + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: Output endpoint of the controller + + required: + - port@0 + - port@1 + + data-lanes: + $ref: /schemas/media/video-interfaces.yaml# + description: | + number of lanes supported by the hardware. + The possible values: + 0 - For 1 lane enabled in IP. + 0 1 - For 2 lanes enabled in IP. + 0 1 2 3 - For 4 lanes enabled in IP. + minItems: 1 + maxItems: 4 + + max-linkrate-mhz: + enum: [ 1620, 2700, 5400, 8100 ] + description: maximum link rate supported by the hardware. + +required: + - compatible + - reg + - interrupts + - ports + - data-lanes + - max-linkrate-mhz + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/power/mt8195-power.h> + dp_tx@1c600000 { + compatible = "mediatek,mt8195-dp-tx"; + reg = <0x1c600000 0x8000>; + power-domains = <&spm MT8195_POWER_DOMAIN_DP_TX>; + interrupts = <GIC_SPI 458 IRQ_TYPE_LEVEL_HIGH 0>; + data-lanes = <0 1 2 3>; + max-linkrate-mhz = <8100>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + edp_in: endpoint { + remote-endpoint = <&dp_intf0_out>; + }; + }; + port@1 { + reg = <1>; + edp_out: endpoint { + remote-endpoint = <&panel_in>; + }; + }; + }; + };
Signature · 1 line
2.18.0
Rob Herring
maintainerRe: [PATCH v12 01/10] dt-bindings: mediatek,dp: Add Display Port binding
Quoted 9 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This controller is present on several mediatek hardware. Currently mt8195 and mt8395 have this controller without a functional difference, so only one compatible field is added.
The controller can have two forms, as a normal display port and as an embedded display port.
Quoted 9 lines
Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Fix reviewers' comment]Signed-off-by Bo-Chen Chen <[email protected]>--- .../display/mediatek/mediatek,dp.yaml | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/mediatek/mediatek,dp.yaml
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/display/mediatek/mediatek,dp.example.dtb: dp_tx@1c600000: data-lanes: [[0, 1, 2, 3]] is not of type 'object'
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/display/mediatek/mediatek,dp.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/display/mediatek/mediatek,dp.example.dtb: dp_tx@1c600000: data-lanes: [[0, 1, 2, 3]] is not of type 'object'
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/display/mediatek/mediatek,dp.yaml
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/patch/
This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit.
PATCH v12 2/10 drm/edid: Convert cea_sad helper struct to kernelDoc
In reply to Bo-Chen ChenFrom: Guillaume Ranquet <[email protected]>
To illustrate the cea_sad helper struct more clear, we convert the driver comments to kernelDoc.
--- include/drm/drm_edid.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
include/drm/drm_edid.h +9 -3
@@ -359,12 +359,18 @@ struct edid {#define EDID_PRODUCT_ID (e) ((e)->prod_code[0] | ((e)->prod_code[1] << 8)) -/* Short Audio Descriptor */ +/** +* struct cea_sad - CEA Short Audio Descriptor. +* @format: See HDMI_AUDIO_CODING_TYPE_*. +* @channels: max number of channels - 1. +* @freq: See CEA_SAD_FREQ_*. +* @byte2: meaning depends on format. +*/ struct cea_sad {u8 format; -u8 channels;/* max number of channels - 1 */ +u8 channels;u8 freq; -u8 byte2;/* meaning depends on format */ +u8 byte2; };struct drm_encoder ;
Signature · 1 line
2.18.0
PATCH v12 3/10 drm/edid: Add cea_sad helpers for freq/length
In reply to Bo-Chen ChenFrom: Guillaume Ranquet <[email protected]>
This patch adds two helper functions that extract the frequency and word length from a struct cea_sad.
For these helper functions new defines are added that help translate the 'freq' and 'byte2' fields into real numbers.
--- drivers/gpu/drm/drm_edid.c | 73 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_edid.h | 14 ++++++++ 2 files changed, 87 insertions(+)
drivers/gpu/drm/drm_edid.c +73 -0
@@ -4916,6 +4916,79 @@ int drm_edid_to_speaker_allocation(const struct edid *edid, u8 **sadb) }EXPORT_SYMBOL (drm_edid_to_speaker_allocation); +/** +* drm_cea_sad_get_sample_rate - Extract the sample rate from cea_sad +* @sad: Pointer to the cea_sad struct +* +* Extracts the cea_sad frequency field and returns the sample rate in Hz. +* +* Return: Sample rate in Hz or a negative errno if parsing failed. +*/ +int drm_cea_sad_get_sample_rate (const struct cea_sad *sad) +{ +switch (sad->freq) { +case DRM_CEA_SAD_FREQ_32KHZ : +return 32000 ; +case DRM_CEA_SAD_FREQ_44KHZ : +return 44100 ; +case DRM_CEA_SAD_FREQ_48KHZ : +return 48000 ; +case DRM_CEA_SAD_FREQ_88KHZ : +return 88200 ; +case DRM_CEA_SAD_FREQ_96KHZ : +return 96000 ; +case DRM_CEA_SAD_FREQ_176KHZ : +return 176400 ; +case DRM_CEA_SAD_FREQ_192KHZ : +return 192000 ; +default : +return -EINVAL ; + } +} +EXPORT_SYMBOL (drm_cea_sad_get_sample_rate); + +static bool drm_cea_sad_is_pcm (const struct cea_sad *sad) +{ +switch (sad->format) { +case HDMI_AUDIO_CODING_TYPE_PCM : +return true; +default : +return false; + } +} + +/** +* drm_cea_sad_get_uncompressed_word_length - Extract word length +* @sad: Pointer to the cea_sad struct +* +* Extracts the cea_sad byte2 field and returns the word length for an +* uncompressed stream. +* +* Note: This function may only be called for uncompressed audio. +* +* Return: Word length in bits or a negative errno if parsing failed. +*/ +int drm_cea_sad_get_uncompressed_word_length (const struct cea_sad *sad) +{ +if (!drm_cea_sad_is_pcm (sad)) { +DRM_WARN ("Unable to get the uncompressed word length for format: %u\n" , + sad->format); +return -EINVAL ; + } + +switch (sad->byte2) { +case DRM_CEA_SAD_UNCOMPRESSED_WORD_16BIT : +return 16 ; +case DRM_CEA_SAD_UNCOMPRESSED_WORD_20BIT : +return 20 ; +case DRM_CEA_SAD_UNCOMPRESSED_WORD_24BIT : +return 24 ; +default : +return -EINVAL ; + } +} +EXPORT_SYMBOL (drm_cea_sad_get_uncompressed_word_length); +/** * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay * @connector: connector associated with the HDMI/DP sink
include/drm/drm_edid.h +14 -0
@@ -373,6 +373,18 @@ struct cea_sad {u8 byte2; }; +#define DRM_CEA_SAD_FREQ_32KHZ BIT(0) +#define DRM_CEA_SAD_FREQ_44KHZ BIT(1) +#define DRM_CEA_SAD_FREQ_48KHZ BIT(2) +#define DRM_CEA_SAD_FREQ_88KHZ BIT(3) +#define DRM_CEA_SAD_FREQ_96KHZ BIT(4) +#define DRM_CEA_SAD_FREQ_176KHZ BIT(5) +#define DRM_CEA_SAD_FREQ_192KHZ BIT(6) + +#define DRM_CEA_SAD_UNCOMPRESSED_WORD_16BIT BIT(0) +#define DRM_CEA_SAD_UNCOMPRESSED_WORD_20BIT BIT(1) +#define DRM_CEA_SAD_UNCOMPRESSED_WORD_24BIT BIT(2) +struct drm_encoder ;struct drm_connector ;struct drm_connector_state ;
@@ -380,6 +392,8 @@ struct drm_display_mode;int drm_edid_to_sad (const struct edid *edid,struct cea_sad **sads);int drm_edid_to_speaker_allocation (const struct edid *edid,u8 **sadb); +int drm_cea_sad_get_sample_rate (const struct cea_sad *sad); +int drm_cea_sad_get_uncompressed_word_length (const struct cea_sad *sad);int drm_av_sync_delay (struct drm_connector *connector,const struct drm_display_mode *mode);
Signature · 1 line
2.18.0
PATCH v12 4/10 video/hdmi: Add audio_infoframe packing for DP
In reply to Bo-Chen ChenFrom: Markus Schneider-Pargmann <[email protected]>
Similar to HDMI, DP uses audio infoframes as well which are structured very similar to the HDMI ones.
This patch adds a helper function to pack the HDMI audio infoframe for DP, called hdmi_audio_infoframe_pack_for_dp(). hdmi_audio_infoframe_pack_only() is split into two parts. One of them packs the payload only and can be used for HDMI and DP.
Also constify the frame parameter in hdmi_audio_infoframe_check() as it is passed to hdmi_audio_infoframe_check_only() which expects a const.
--- drivers/video/hdmi.c | 82 +++++++++++++++++++++++++++--------- include/drm/display/drm_dp.h | 2 + include/linux/hdmi.h | 7 ++- 3 files changed, 71 insertions(+), 20 deletions(-)
drivers/video/hdmi.c +63 -19
@@ -21,6 +21,7 @@* DEALINGS IN THE SOFTWARE. */ +#include <drm/display/drm_dp.h> #include <linux/bitops.h> #include <linux/bug.h> #include <linux/errno.h>
@@ -381,12 +382,34 @@ static int hdmi_audio_infoframe_check_only(const struct hdmi_audio_infoframe *fr* * Returns 0 on success or a negative error code on failure. */ -int hdmi_audio_infoframe_check (struct hdmi_audio_infoframe *frame) +int hdmi_audio_infoframe_check (const struct hdmi_audio_infoframe *frame) {return hdmi_audio_infoframe_check_only (frame); }EXPORT_SYMBOL (hdmi_audio_infoframe_check); +static void +hdmi_audio_infoframe_pack_payload (const struct hdmi_audio_infoframe *frame, +u8 *buffer) +{ +u8 channels; + +if (frame->channels >=2 ) + channels = frame->channels -1 ; +else + channels =0 ; + + buffer[0 ] = ((frame->coding_type &0xf ) <<4 ) | (channels &0x7 ); + buffer[1 ] = ((frame->sample_frequency &0x7 ) <<2 ) | + (frame->sample_size &0x3 ); + buffer[2 ] = frame->coding_type_ext &0x1f ; + buffer[3 ] = frame->channel_allocation; + buffer[4 ] = (frame->level_shift_value &0xf ) <<3 ; + +if (frame->downmix_inhibit) + buffer[4 ] |=BIT (7 ); +} +/** * hdmi_audio_infoframe_pack_only() - write HDMI audio infoframe to binary buffer * @frame: HDMI audio infoframe
@@ -404,7 +427,6 @@ EXPORT_SYMBOL(hdmi_audio_infoframe_check);ssize_t hdmi_audio_infoframe_pack_only (const struct hdmi_audio_infoframe *frame,void *buffer,size_t size) { -unsigned char channels;u8 *ptr = buffer;size_t length;int ret;
@@ -420,28 +442,13 @@ ssize_t hdmi_audio_infoframe_pack_only(const struct hdmi_audio_infoframe *frame,memset (buffer,0 , size); -if (frame->channels >=2 ) - channels = frame->channels -1 ; -else - channels =0 ; - ptr[0 ] = frame->type; ptr[1 ] = frame->version; ptr[2 ] = frame->length; ptr[3 ] =0 ;/* checksum */ -/* start infoframe payload */ - ptr +=HDMI_INFOFRAME_HEADER_SIZE ; - - ptr[0 ] = ((frame->coding_type &0xf ) <<4 ) | (channels &0x7 ); - ptr[1 ] = ((frame->sample_frequency &0x7 ) <<2 ) | - (frame->sample_size &0x3 ); - ptr[2 ] = frame->coding_type_ext &0x1f ; - ptr[3 ] = frame->channel_allocation; - ptr[4 ] = (frame->level_shift_value &0xf ) <<3 ; - -if (frame->downmix_inhibit) - ptr[4 ] |=BIT (7 ); +hdmi_audio_infoframe_pack_payload (frame, + ptr +HDMI_INFOFRAME_HEADER_SIZE );hdmi_infoframe_set_checksum (buffer, length);
@@ -479,6 +486,43 @@ ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, }EXPORT_SYMBOL (hdmi_audio_infoframe_pack); +/** +* hdmi_audio_infoframe_pack_for_dp - Pack a HDMI Audio infoframe for DisplayPort +* +* @frame: HDMI Audio infoframe +* @sdp: secondary data packet for display port. This is filled with the +* appropriate: data +* @dp_version: Display Port version to be encoded in the header +* +* Packs a HDMI Audio Infoframe to be sent over Display Port. This function +* fills the secondary data packet to be used for Display Port. +* +* Return: Number of total written bytes or a negative errno on failure. +*/ +ssize_t +hdmi_audio_infoframe_pack_for_dp (const struct hdmi_audio_infoframe *frame, +struct dp_sdp *sdp,u8 dp_version) +{ +int ret; + + ret =hdmi_audio_infoframe_check (frame); +if (ret) +return ret; + +memset (sdp->db,0 ,sizeof (sdp->db)); + +/* Secondary-data packet header */ + sdp->sdp_header.HB0 =0 ; + sdp->sdp_header.HB1 = frame->type; + sdp->sdp_header.HB2 =DP_SDP_AUDIO_INFOFRAME_HB2 ; + sdp->sdp_header.HB3 = (dp_version &0x3f ) <<2 ; + +hdmi_audio_infoframe_pack_payload (frame, sdp->db); + +return frame->length +4 ; +} +EXPORT_SYMBOL (hdmi_audio_infoframe_pack_for_dp); +/** * hdmi_vendor_infoframe_init() - initialize an HDMI vendor infoframe * @frame: HDMI vendor infoframe
include/drm/display/drm_dp.h +2 -0
@@ -1536,6 +1536,8 @@ enum drm_dp_phy {#define DP_SDP_VSC_EXT_CEA 0x21/* DP 1.4 */ /* 0x80+ CEA-861 infoframe types */ +#define DP_SDP_AUDIO_INFOFRAME_HB2 0x1b +/** * struct dp_sdp_header - DP secondary data packet header * @HB0: Secondary Data Packet ID
include/linux/hdmi.h +6 -1
@@ -336,7 +336,12 @@ ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, void *buffer, size_t size);ssize_t hdmi_audio_infoframe_pack_only (const struct hdmi_audio_infoframe *frame,void *buffer,size_t size); -int hdmi_audio_infoframe_check (struct hdmi_audio_infoframe *frame); +int hdmi_audio_infoframe_check (const struct hdmi_audio_infoframe *frame); + +struct dp_sdp ; +ssize_t +hdmi_audio_infoframe_pack_for_dp (const struct hdmi_audio_infoframe *frame, +struct dp_sdp *sdp,u8 dp_version);enum hdmi_3d_structure {HDMI_3D_STRUCTURE_INVALID =-1 ,
Signature · 1 line
2.18.0
PATCH v12 5/10 drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenFrom: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that both can work with the same register range. The phy driver sets device data that is read by the parent to get the phy device that can be used to control the phy properties.
This driver is based on an initial version by
Jitao shi <[email protected]>
--- drivers/gpu/drm/mediatek/Kconfig | 10 + drivers/gpu/drm/mediatek/Makefile | 1 + drivers/gpu/drm/mediatek/mtk_dp.c | 2198 ++++++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_dp_reg.h | 543 ++++++ drivers/gpu/drm/mediatek/mtk_drm_drv.c | 3 + drivers/gpu/drm/mediatek/mtk_drm_drv.h | 3 + 6 files changed, 2758 insertions(+) create mode 100644 drivers/gpu/drm/mediatek/mtk_dp.c create mode 100644 drivers/gpu/drm/mediatek/mtk_dp_reg.h
drivers/gpu/drm/mediatek/Kconfig +10 -0
@@ -15,12 +15,22 @@ config DRM_MEDIATEK select MTK_SMI select PHY_MTK_MIPI_DSI select VIDEOMODE_HELPERS + select DRM_MEDIATEK_DP help Choose this option if you have a Mediatek SoCs. The module will be called mediatek-drm This driver provides kernel mode setting and buffer management to userspace. +config DRM_MEDIATEK_DP + tristate "DRM DPTX Support for MediaTek SoCs" + depends on DRM_MEDIATEK + select PHY_MTK_DP + select DRM_DISPLAY_HELPER + select DRM_DISPLAY_DP_HELPER + help + DRM/KMS Display Port driver for MediaTek SoCs. + config DRM_MEDIATEK_HDMI tristate "DRM HDMI Support for Mediatek SoCs" depends on DRM_MEDIATEK
drivers/gpu/drm/mediatek/Makefile +1 -0
@@ -14,6 +14,7 @@ mediatek-drm-y := mtk_disp_aal.o \ mtk_drm_gem.o \ mtk_drm_plane.o \ mtk_dsi.o \ + mtk_dp.o \ mtk_dpi.o \ mtk_ethdr.o \ mtk_mdp_rdma.o
drivers/gpu/drm/mediatek/mtk_dp.c new file +2198 -0
2,198 lines not on this page · raw message
drivers/gpu/drm/mediatek/mtk_dp_reg.h new file +543 -0
543 lines not on this page · raw message
drivers/gpu/drm/mediatek/mtk_drm_drv.c +3 -0
@@ -1033,6 +1033,9 @@ static struct platform_driver * const mtk_drm_drivers[] = { &mtk_disp_ovl_driver, &mtk_disp_rdma_driver, &mtk_dpi_driver, +#if IS_REACHABLE(CONFIG_DRM_MEDIATEK_DP) + &mtk_dp_driver, +#endif &mtk_drm_platform_driver, &mtk_dsi_driver, &mtk_ethdr_driver,
drivers/gpu/drm/mediatek/mtk_drm_drv.h +3 -0
@@ -67,6 +67,9 @@ extern struct platform_driver mtk_disp_ovl_adaptor_driver;extern struct platform_driver mtk_disp_ovl_driver;extern struct platform_driver mtk_disp_rdma_driver;extern struct platform_driver mtk_dpi_driver; +#if IS_REACHABLE (CONFIG_DRM_MEDIATEK_DP ) +extern struct platform_driver mtk_dp_driver; +#endif extern struct platform_driver mtk_dsi_driver;extern struct platform_driver mtk_ethdr_driver;extern struct platform_driver mtk_mdp_rdma_driver;
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
Il 27/06/22 10:03, Bo-Chen Chen ha scritto:
Quoted 65 lines
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that both can work with the same register range. The phy driver sets device data that is read by the parent to get the phy device that can be used to control the phy properties.
This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>--- drivers/gpu/drm/mediatek/Kconfig | 10 + drivers/gpu/drm/mediatek/Makefile | 1 + drivers/gpu/drm/mediatek/mtk_dp.c | 2198 ++++++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_dp_reg.h | 543 ++++++ drivers/gpu/drm/mediatek/mtk_drm_drv.c | 3 + drivers/gpu/drm/mediatek/mtk_drm_drv.h | 3 + 6 files changed, 2758 insertions(+)create mode 100644
drivers/gpu/drm/mediatek/mtk_dp.ccreate mode 100644drivers/gpu/drm/mediatek/mtk_dp_reg.hdrivers/gpu/drm/mediatek/mtk_dp.c new file +25
-0@@ -0,0 +1,2198 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019-2022 MediaTek Inc. +* Copyright (c) 2022 BayLibre +*/ + +#include <drm/display/drm_dp.h> +#include <drm/display/drm_dp_helper.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_bridge.h> +#include <drm/drm_crtc.h> +#include <drm/drm_edid.h> +#include <drm/drm_of.h> +#include <drm/drm_panel.h> +#include <drm/drm_print.h> +#include <drm/drm_probe_helper.h> +#include <linux/arm-smccc.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/nvmem-consumer.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_platform.h>
drivers/gpu/drm/mediatek/mtk_dp.c line 35
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regmap.h> +#include <sound/hdmi-codec.h> +#include <video/videomode.h> + +#include "mtk_dp_reg.h" + +#define MTK_DP_SIP_CONTROL_AARCH32 0x82000523
Why have you forced this SIP call to AArch32 SMC convention? Is there any particular reason why this should always be AA32 and *never* AA64?
In any case, you've got MediaTek SIP macros in include/soc/mediatek/mtk_sip_svc.h so, please, include that header and either redefine this as
MTK_SIP_CMD(0x523) or add a new macro in there to force ARM_SMCCC_SMC_32 convention with a very explanatory comment saying why some calls need to be forced to use the AArch32 SMC convention.
drivers/gpu/drm/mediatek/mtk_dp.c line 46
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +11
-0+ +#define MTK_VDOSYS1_MAX_FRAMERATE 60 +#define MTK_DP_4P1T 4 +#define MTK_DP_HDE 2 +#define MTK_DP_PIX_PER_ADDR 2 +#define MTK_DP_AUX_WAIT_REPLY_COUNT 20 +#define MTK_DP_CHECK_SINK_CAP_TIMEOUT_COUNT 3 +#define MTK_DP_TBC_BUF_READ_START_ADDR 0x08 +#define MTK_DP_TRAIN_RETRY_LIMIT 8 +#define MTK_DP_TRAIN_MAX_ITERATIONS 5 +#define MTK_DP_DP_VERSION_11 0x11
MTK_DP_HW_VERSION_11 0x11 ?
...but anyway, this definition is unused, so please either use it or drop it.
Quoted 91 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +91
-0+ +enum mtk_dp_train_state { +MTK_DP_TRAIN_STATE_TRAINING , +MTK_DP_TRAIN_STATE_NORMAL , +}; + +struct mtk_dp_timings { +struct videomode vm; +u8 frame_rate; +}; + +struct mtk_dp_irq_sta { +bool hpd_disconnect; +bool hpd_inerrupt; +}; + +struct mtk_dp_train_info { +bool tps3; +bool tps4; +bool sink_ssc; +bool cable_plugged_in; +bool cable_state_change; +bool cr_done; +bool eq_done; +/* link_rate is in multiple of 0.27Gbps */ +int link_rate; +int lane_count; +struct mtk_dp_irq_sta irq_sta; +}; + +struct mtk_dp_info { +u32 depth; +enum dp_pixelformat format; +struct mtk_dp_timings timings; +}; + +struct dp_cal_data { +unsigned int glb_bias_trim; +unsigned int clktx_impse; + +unsigned int ln_tx_impsel_pmos[4 ]; +unsigned int ln_tx_impsel_nmos[4 ]; +}; + +struct mtk_dp { +struct device *dev; +struct platform_device *phy_dev; +struct phy *phy; +struct dp_cal_data cal_data; +u8 max_lanes; +u8 max_linkrate; + +struct drm_device *drm_dev; +struct drm_bridge bridge; +struct drm_bridge *next_bridge; +struct drm_dp_aux aux; + +u8 rx_cap[DP_RECEIVER_CAP_SIZE ]; + +struct mtk_dp_info info; + +struct mtk_dp_train_info train_info; +enum mtk_dp_train_state train_state; + +struct regmap *regs; + +bool enabled; + +struct drm_connector *conn; +}; + +static struct regmap_config mtk_dp_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =SEC_OFFSET +0x90 , + .name ="mtk-dp-registers" , +}; + +static struct mtk_dp *mtk_dp_from_bridge (struct drm_bridge *b) +{ + return container_of(b, struct mtk_dp, bridge); +} + +static u32 mtk_dp_read (struct mtk_dp *mtk_dp,u32 offset) +{ +u32 read_val; +int ret; + + ret =regmap_read (mtk_dp->regs, offset, &read_val); +if (ret) {
drivers/gpu/drm/mediatek/mtk_dp.c line 147
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+dev_err (mtk_dp->dev,"Failed to read register 0x%x: %d\n" , + offset, ret); +return 0 ; + } + +return read_val; +} + +static void mtk_dp_write (struct mtk_dp *mtk_dp,u32 offset,u32 val) +{
This should be int... you should propagate the error to the caller, and also eventually take action in case you get an error.
drivers/gpu/drm/mediatek/mtk_dp.c line 156
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +9
-0+if (regmap_write (mtk_dp->regs, offset, val)) +dev_err (mtk_dp->dev, +"Failed to write register 0x%x with value 0x%x\n" , + offset, val); +} + +static void mtk_dp_update_bits (struct mtk_dp *mtk_dp,u32 offset, +u32 val,u32 mask) +{
Same here.
drivers/gpu/drm/mediatek/mtk_dp.c line 168
Quoted 12 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +12
-0+if (regmap_update_bits (mtk_dp->regs, offset, mask, val)) +dev_err (mtk_dp->dev, +"Failed to update register 0x%x with value 0x%x, mask 0x%x\n" , + offset, val, mask); +} + +static void mtk_dp_bulk_16bit_write (struct mtk_dp *mtk_dp,u32 offset,u8 *buf, +size_t length) +{ +int i; +int num_regs = (length +1 ) /2 ; +
... and here.
drivers/gpu/drm/mediatek/mtk_dp.c line 174
Quoted 6 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +6
-0+/* 2 bytes per register */ +for (i =0 ; i < num_regs; i++) { +u32 val = buf[i *2 ] | + (i *2 +1 < length ? buf[i *2 +1 ] <<8 :0 ); + +mtk_dp_write (mtk_dp, offset + i *4 , val);
P.S.: Does it make sense to keep writing if you get an error?
I'd say that doing this may lead to unexpected hardware status.
Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+ } +} + +static unsigned long mtk_dp_sip_atf_call (struct mtk_dp *mtk_dp, +unsigned int cmd,unsigned int para)
drivers/gpu/drm/mediatek/mtk_dp.c line 189
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+{ +struct arm_smccc_res res; + +arm_smccc_smc (MTK_DP_SIP_CONTROL_AARCH32 , cmd, para,0 ,0 ,0 ,0 ,0 , + &res); + +dev_dbg (mtk_dp->dev,"sip cmd 0x%x, p1 0x%x, ret 0x%lx-0x%lx" , + cmd, para, res.a0, res.a1); + +return res.a1;
We have SIP_SVC_E_(xxxxx) error codes defined in mtk_sip_svc.h... this makes me think that res.a1 is not an unsigned long for real: please confirm.
Quoted 2 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+} +
..snip..
Quoted 21 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +21
-0+ +static void mtk_dp_set_color_format (struct mtk_dp *mtk_dp, +enum dp_pixelformat color_format) +{ +u32 val; + + mtk_dp->info.format = color_format; + +/* update MISC0 */ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3034 , + color_format <<DP_TEST_COLOR_FORMAT_SHIFT , +DP_TEST_COLOR_FORMAT_MASK ); + +switch (color_format) { +case DP_PIXELFORMAT_YUV422 : + val =PIXEL_ENCODE_FORMAT_DP_ENC0_P0_YCBCR422 ; +break ; +case DP_PIXELFORMAT_YUV420 : + val =PIXEL_ENCODE_FORMAT_DP_ENC0_P0_YCBCR420 ; +break ; +case DP_PIXELFORMAT_RGB :
drivers/gpu/drm/mediatek/mtk_dp.c line 308
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+case DP_PIXELFORMAT_YUV444 : + val =PIXEL_ENCODE_FORMAT_DP_ENC0_P0_RGB ; +break ; +case DP_PIXELFORMAT_Y_ONLY : +case DP_PIXELFORMAT_RAW : +case DP_PIXELFORMAT_RESERVED : +default : +drm_warn (mtk_dp->drm_dev,"Unsupported color format: %d\n" , + color_format); +return ;
return -EINVAL here?
drivers/gpu/drm/mediatek/mtk_dp.c line 312
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ } + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_303C , + val,PIXEL_ENCODE_FORMAT_DP_ENC0_P0_MASK );
... and return 0 here.
Quoted 20 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +20
-0+} + +static void mtk_dp_set_color_depth (struct mtk_dp *mtk_dp) +{ +u32 val; +/* Only support 8 bits currently */ +u32 color_depth =DP_MSA_MISC_8_BPC ; + + mtk_dp->info.depth = color_depth; + +/* Update MISC0 */ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3034 , + color_depth,DP_TEST_BIT_DEPTH_MASK ); + +switch (color_depth) { +case DP_MSA_MISC_6_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_6BIT ; +break ; +case DP_MSA_MISC_8_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_8BIT ;
drivers/gpu/drm/mediatek/mtk_dp.c line 342
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+break ; +case DP_MSA_MISC_10_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_10BIT ; +break ; +case DP_MSA_MISC_12_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_12BIT ; +break ; +case DP_MSA_MISC_16_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_16BIT ; +break ;
ditto
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+default : +drm_warn (mtk_dp->drm_dev,"Unsupported color depth %d\n" , + color_depth); +return ; + } + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_303C , val, +VIDEO_COLOR_DEPTH_DP_ENC0_P0_MASK ); +} +
..snip..
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+ +static int mtk_dp_phy_configure (struct mtk_dp *mtk_dp, +u32 link_rate,int lane_count) +{ +int ret; +union phy_configure_opts phy_opts = { + .dp = { + .link_rate =link_rate_to_mb_per_s (mtk_dp, link_rate), + .set_rate =1 , + .lanes = lane_count,
drivers/gpu/drm/mediatek/mtk_dp.c line 940
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+ .set_lanes = 1, + .ssc = mtk_dp->train_info.sink_ssc, + } + }; + +mtk_dp_update_bits (mtk_dp,MTK_DP_TOP_PWR_STATE ,DP_PWR_STATE_BANDGAP , +DP_PWR_STATE_MASK ); + + ret =phy_configure (mtk_dp->phy, &phy_opts); +
This new blank line is unnecessary, please remove.
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+if (ret) +return ret; + +mtk_dp_set_cal_data (mtk_dp); +mtk_dp_update_bits (mtk_dp,MTK_DP_TOP_PWR_STATE , +DP_PWR_STATE_BANDGAP_TPLL_LANE ,DP_PWR_STATE_MASK ); + +return 0 ; +} +
..snip..
drivers/gpu/drm/mediatek/mtk_dp.c line 1071
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ +static void mtk_dp_calculate_pixrate (struct mtk_dp *mtk_dp) +{ +u8 target_frame_rate =60 ;
Don't assign any value here: this will make sure to avoid double assignments later.
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+u32 target_pixel_clk; +struct drm_display_mode mode; +struct mtk_dp_timings *timings = &mtk_dp->info.timings; +
drivers/gpu/drm/mediatek/mtk_dp.c line 1085
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+drm_display_mode_from_videomode (&timings->vm, &mode); + +if (mtk_dp->info.timings.frame_rate >0 ) { + target_frame_rate = mtk_dp->info.timings.frame_rate; + target_pixel_clk = mode.htotal * mode.vtotal * + target_frame_rate; + }else { + target_pixel_clk = mode.htotal * mode.vtotal * + target_frame_rate; + }
This should be
if (mtk_dp->info.timings.frame_rate > 0) target_frame_rate = mtk_dp->info.timings.frame_rate; else target_frame_rate = 60; target_pixel_clk = mode.htotal * mode.vtotal * target_frame_rate;
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +11
-0+} + +static void mtk_dp_set_tx_out (struct mtk_dp *mtk_dp) +{ +mtk_dp_msa_bypass_disable (mtk_dp); +mtk_dp_calculate_pixrate (mtk_dp); +mtk_dp_pg_disable (mtk_dp); +mtk_dp_setup_tu (mtk_dp); +} + +static ssize_t mtk_dp_hpd_sink_event (struct mtk_dp *mtk_dp)
drivers/gpu/drm/mediatek/mtk_dp.c line 1106
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+{ +ssize_t ret; +u8 sink_count; +bool locked; +u8 link_status[DP_LINK_STATUS_SIZE ] = {}; +u32 sink_count_reg =DP_SINK_COUNT_ESI ; +u32 link_status_reg =DP_LANE0_1_STATUS ; + + ret =drm_dp_dpcd_readb (&mtk_dp->aux, sink_count_reg, &sink_count); +if (ret <0 ) {
This function can never return anything > 1, so this should probably be:
if (ret < 1) {
drm_err ....
return ret == 0 ? -EIO : ret;
}Quoted 29 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +29
-0+drm_err (mtk_dp->drm_dev,"Read sink count failed\n" ); +return ret; + } + + ret =drm_dp_dpcd_read (&mtk_dp->aux, link_status_reg, link_status, +sizeof (link_status)); +if (!ret) { +drm_err (mtk_dp->drm_dev,"Read link status failed\n" ); +return ret; + } + + locked =drm_dp_channel_eq_ok (link_status, + mtk_dp->train_info.lane_count); +if (!locked && mtk_dp->train_state >MTK_DP_TRAIN_STATE_TRAINING ) + mtk_dp->train_state =MTK_DP_TRAIN_STATE_TRAINING ; + +if (link_status[1 ] &DP_REMOTE_CONTROL_COMMAND_PENDING ) +drm_dp_dpcd_writeb (&mtk_dp->aux,DP_DEVICE_SERVICE_IRQ_VECTOR , +DP_REMOTE_CONTROL_COMMAND_PENDING ); + +if (DP_GET_SINK_COUNT (sink_count) && + (link_status[2 ] &DP_DOWNSTREAM_PORT_STATUS_CHANGED )) { + mtk_dp->train_state =MTK_DP_TRAIN_STATE_TRAINING ; +msleep (20 ); + } + +return 0 ; +} +
..snip..
Quoted 20 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +20
-0+ +static int mtk_dp_train_flow (struct mtk_dp *mtk_dp,u8 target_link_rate, +u8 target_lane_count) +{ +u8 lane_adjust[2 ] = {}; +bool pass_tps1 = false; +bool pass_tps2_3 = false; +int train_retries; +int status_control; +int iteration_count; +int ret; +u8 prev_lane_adjust; + +drm_dp_dpcd_writeb (&mtk_dp->aux,DP_LINK_BW_SET , target_link_rate); +drm_dp_dpcd_writeb (&mtk_dp->aux,DP_LANE_COUNT_SET , + target_lane_count |DP_LANE_COUNT_ENHANCED_FRAME_EN ); + +if (mtk_dp->train_info.sink_ssc) +drm_dp_dpcd_writeb (&mtk_dp->aux,DP_DOWNSPREAD_CTRL , +DP_SPREAD_AMP_0_5 );
drivers/gpu/drm/mediatek/mtk_dp.c line 1302
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+ + train_retries =0 ; + status_control =0 ; + iteration_count =1 ; + prev_lane_adjust =0xFF ; + +mtk_dp_set_lanes (mtk_dp, target_lane_count /2 ); + ret =mtk_dp_phy_configure (mtk_dp, target_link_rate, target_lane_count); +if (ret) +return -EINVAL ;
Why are you overriding the error value here?
drivers/gpu/drm/mediatek/mtk_dp.c line 1307
Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+ +dev_dbg (mtk_dp->dev, +"Link train target_link_rate = 0x%x, target_lane_count = 0x%x\n" , + target_link_rate, target_lane_count); +
Cheers,
Angelo
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
Quoted 92 lines · AngeloGioacchino Del Regno
Il 27/06/22 10:03, Bo-Chen Chen ha scritto:
Quoted 72 lines
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will
never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>--- drivers/gpu/drm/mediatek/Kconfig | 10 + drivers/gpu/drm/mediatek/Makefile | 1 + drivers/gpu/drm/mediatek/mtk_dp.c | 2198 ++++++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_dp_reg.h | 543 ++++++ drivers/gpu/drm/mediatek/mtk_drm_drv.c | 3 + drivers/gpu/drm/mediatek/mtk_drm_drv.h | 3 + 6 files changed, 2758 insertions(+)create mode 100644
drivers/gpu/drm/mediatek/mtk_dp.ccreate mode 100644drivers/gpu/drm/mediatek/mtk_dp_reg.hdrivers/gpu/drm/mediatek/mtk_dp.c new file +25
-0@@ -0,0 +1,2198 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019-2022 MediaTek Inc. +* Copyright (c) 2022 BayLibre +*/ + +#include <drm/display/drm_dp.h> +#include <drm/display/drm_dp_helper.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_bridge.h> +#include <drm/drm_crtc.h> +#include <drm/drm_edid.h> +#include <drm/drm_of.h> +#include <drm/drm_panel.h> +#include <drm/drm_print.h> +#include <drm/drm_probe_helper.h> +#include <linux/arm-smccc.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/nvmem-consumer.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_platform.h> drivers/gpu/drm/mediatek/mtk_dp.c line 35
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regmap.h> +#include <sound/hdmi-codec.h> +#include <video/videomode.h> + +#include "mtk_dp_reg.h" + +#define MTK_DP_SIP_CONTROL_AARCH32 0x82000523Why have you forced this SIP call to AArch32 SMC convention? Is there any particular reason why this should always be AA32 and *never* AA64?
In any case, you've got MediaTek SIP macros in
include/soc/mediatek/mtk_sip_svc.h
so, please, include that header and either redefine this as
Quoted 6 lines
MTK_SIP_CMD(0x523)or add a new macro in there to forceARM_SMCCC_SMC_32
convention with a very explanatory comment saying why some calls need to
be forced to use the AArch32 SMC convention.
Hello Angelo,
Thanks for your review.
ok, I will do this in next version.
Quoted 14 lines
drivers/gpu/drm/mediatek/mtk_dp.c line 46
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +11
-0+ +#define MTK_VDOSYS1_MAX_FRAMERATE 60 +#define MTK_DP_4P1T 4 +#define MTK_DP_HDE 2 +#define MTK_DP_PIX_PER_ADDR 2 +#define MTK_DP_AUX_WAIT_REPLY_COUNT 20 +#define MTK_DP_CHECK_SINK_CAP_TIMEOUT_COUNT 3 +#define MTK_DP_TBC_BUF_READ_START_ADDR 0x08 +#define MTK_DP_TRAIN_RETRY_LIMIT 8 +#define MTK_DP_TRAIN_MAX_ITERATIONS 5 +#define MTK_DP_DP_VERSION_11 0x11
MTK_DP_HW_VERSION_110x11?
Quoted 3 lines
...but anyway, this definition is unused, so please either use it or drop it.
it's fro audio patch, and I will move this there.
Quoted 108 lines
Quoted 101 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +92
-0+ +enum mtk_dp_train_state { +MTK_DP_TRAIN_STATE_TRAINING , +MTK_DP_TRAIN_STATE_NORMAL , +}; + +struct mtk_dp_timings { +struct videomode vm; +u8 frame_rate; +}; + +struct mtk_dp_irq_sta { +bool hpd_disconnect; +bool hpd_inerrupt; +}; + +struct mtk_dp_train_info { +bool tps3; +bool tps4; +bool sink_ssc; +bool cable_plugged_in; +bool cable_state_change; +bool cr_done; +bool eq_done; +/* link_rate is in multiple of 0.27Gbps */ +int link_rate; +int lane_count; +struct mtk_dp_irq_sta irq_sta; +}; + +struct mtk_dp_info { +u32 depth; +enum dp_pixelformat format; +struct mtk_dp_timings timings; +}; + +struct dp_cal_data { +unsigned int glb_bias_trim; +unsigned int clktx_impse; + +unsigned int ln_tx_impsel_pmos[4 ]; +unsigned int ln_tx_impsel_nmos[4 ]; +}; + +struct mtk_dp { +struct device *dev; +struct platform_device *phy_dev; +struct phy *phy; +struct dp_cal_data cal_data; +u8 max_lanes; +u8 max_linkrate; + +struct drm_device *drm_dev; +struct drm_bridge bridge; +struct drm_bridge *next_bridge; +struct drm_dp_aux aux; + +u8 rx_cap[DP_RECEIVER_CAP_SIZE ]; + +struct mtk_dp_info info; + +struct mtk_dp_train_info train_info; +enum mtk_dp_train_state train_state; + +struct regmap *regs; + +bool enabled; + +struct drm_connector *conn; +}; + +static struct regmap_config mtk_dp_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =SEC_OFFSET +0x90 , + .name ="mtk-dp-registers" , +}; + +static struct mtk_dp *mtk_dp_from_bridge (struct drm_bridge *b) +{ + return container_of(b, struct mtk_dp, bridge); +} + +static u32 mtk_dp_read (struct mtk_dp *mtk_dp,u32 offset) +{ +u32 read_val; +int ret; + + ret =regmap_read (mtk_dp->regs, offset, &read_val); +if (ret) { + dev_err(mtk_dp->dev, "Failed to read register 0x%x:%d\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +8
-0+ offset, ret); +return 0 ; + } + +return read_val; +} + +static void mtk_dp_write(struct mtk_dp *mtk_dp, u32 offset, u32Quoted 2 lines
val)
+{This should be int... you should propagate the error to the caller, and also
eventually take action in case you get an error.
Quoted 13 lines
drivers/gpu/drm/mediatek/mtk_dp.c line 156
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +3
-0+if (regmap_write (mtk_dp->regs, offset, val)) + dev_err(mtk_dp->dev, + "Failed to write register 0x%x with value0x%x\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +6
-0+ offset, val); +} + +static void mtk_dp_update_bits (struct mtk_dp *mtk_dp,u32 offset, +u32 val,u32 mask) +{Same here.
I don't think we need to control this.
From most drivers, I see there are many example which are not control the error of write register function.
If there is any error, the root cause is power domain is not enabled. In this case, we can not go to these register setting. Besides, we also can saves hundreds of driver lines to handle the write register error.
Quoted 17 lines
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +3
-0+if (regmap_update_bits (mtk_dp->regs, offset, mask, val)) + dev_err(mtk_dp->dev, + "Failed to update register 0x%x with value0x%x, mask 0x%x\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ offset, val, mask); +} + +static void mtk_dp_bulk_16bit_write(struct mtk_dp *mtk_dp, u32offset, u8 *buf,
drivers/gpu/drm/mediatek/mtk_dp.c line 168
Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+ size_t length) +{ +int i; +int num_regs = (length +1 ) /2 ; +... and here.
Quoted 12 lines
drivers/gpu/drm/mediatek/mtk_dp.c
Quoted 7 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+/* 2 bytes per register */ +for (i =0 ; i < num_regs; i++) { + u32 val = buf[i * 2] | + (i * 2 + 1 < length ? buf[i * 2 + 1] << 8 :0);
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ +mtk_dp_write (mtk_dp, offset + i *4 , val);
P.S.: Does it make sense to keep writing if you get an error?
I'd say that doing this may lead to unexpected hardware
status.
If one register failed to write, it should be for *all* registers and not only for *one* register.
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+ } +} + +static unsigned long mtk_dp_sip_atf_call (struct mtk_dp *mtk_dp, + unsigned int cmd, unsigned intpara)
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+{ +struct arm_smccc_res res; + + arm_smccc_smc(MTK_DP_SIP_CONTROL_AARCH32, cmd, para, 0, 0, 0,0, 0,
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ &res); +
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_dp.c line 189
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+dev_dbg (mtk_dp->dev,"sip cmd 0x%x, p1 0x%x, ret 0x%lx-0x%lx" , + cmd, para, res.a0, res.a1); + +return res.a1;We have
SIP_SVC_E_(xxxxx)error codes defined inmtk_sip_svc.h... this makes me
think that res.a1 is not an unsigned long for real: please confirm.
ok, I will confirm that.
Quoted 31 lines
Quoted 2 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+} +..snip..
Quoted 26 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +26
-0+ +static void mtk_dp_set_color_format (struct mtk_dp *mtk_dp, +enum dp_pixelformat color_format) +{ +u32 val; + + mtk_dp->info.format = color_format; + +/* update MISC0 */ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3034 , + color_format <<DP_TEST_COLOR_FORMAT_SHIFT , +DP_TEST_COLOR_FORMAT_MASK ); + +switch (color_format) { +case DP_PIXELFORMAT_YUV422 : + val =PIXEL_ENCODE_FORMAT_DP_ENC0_P0_YCBCR422 ; +break ; +case DP_PIXELFORMAT_YUV420 : + val =PIXEL_ENCODE_FORMAT_DP_ENC0_P0_YCBCR420 ; +break ; +case DP_PIXELFORMAT_RGB : +case DP_PIXELFORMAT_YUV444 : + val =PIXEL_ENCODE_FORMAT_DP_ENC0_P0_RGB ; +break ; +case DP_PIXELFORMAT_Y_ONLY : +case DP_PIXELFORMAT_RAW :
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_dp.c
Quoted 6 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +3
-0+case DP_PIXELFORMAT_RESERVED : +default : + drm_warn(mtk_dp->drm_dev, "Unsupported color format:%d\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ color_format); +return ;return
-EINVALhere?
ok, I will take care the error handle.
Quoted 118 lines
drivers/gpu/drm/mediatek/mtk_dp.c line 312
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ } + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_303C , + val,PIXEL_ENCODE_FORMAT_DP_ENC0_P0_MASK );... and return 0 here.
Quoted 20 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +20
-0+} + +static void mtk_dp_set_color_depth (struct mtk_dp *mtk_dp) +{ +u32 val; +/* Only support 8 bits currently */ +u32 color_depth =DP_MSA_MISC_8_BPC ; + + mtk_dp->info.depth = color_depth; + +/* Update MISC0 */ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3034 , + color_depth,DP_TEST_BIT_DEPTH_MASK ); + +switch (color_depth) { +case DP_MSA_MISC_6_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_6BIT ; +break ; +case DP_MSA_MISC_8_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_8BIT ;drivers/gpu/drm/mediatek/mtk_dp.c line 342
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+break ; +case DP_MSA_MISC_10_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_10BIT ; +break ; +case DP_MSA_MISC_12_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_12BIT ; +break ; +case DP_MSA_MISC_16_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_16BIT ; +break ;ditto
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+default : + drm_warn(mtk_dp->drm_dev, "Unsupported color depth%d\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +8
-0+ color_depth); +return ; + } + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_303C , val, +VIDEO_COLOR_DEPTH_DP_ENC0_P0_MASK ); +} +..snip..
Quoted 18 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +8
-0+ +static int mtk_dp_phy_configure(struct mtk_dp *mtk_dp, + u32 link_rate, int lane_count) +{ + int ret; + union phy_configure_opts phy_opts = { + .dp = { + .link_rate = link_rate_to_mb_per_s(mtk_dp,
link_rate),drivers/gpu/drm/mediatek/mtk_dp.c new file +8
-0+ .set_rate = 1, + .lanes = lane_count, + .set_lanes = 1, + .ssc = mtk_dp->train_info.sink_ssc, + } + }; + + mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE,
DP_PWR_STATE_BANDGAP,drivers/gpu/drm/mediatek/mtk_dp.c line 940
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ DP_PWR_STATE_MASK); + + ret =phy_configure (mtk_dp->phy, &phy_opts); +This new blank line is unnecessary, please remove.
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +6
-0+if (ret) +return ret; + +mtk_dp_set_cal_data (mtk_dp); + mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE, + DP_PWR_STATE_BANDGAP_TPLL_LANE,
DP_PWR_STATE_MASK);drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ +return 0 ; +} +..snip..
drivers/gpu/drm/mediatek/mtk_dp.c line 1071
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ +static void mtk_dp_calculate_pixrate (struct mtk_dp *mtk_dp) +{ +u8 target_frame_rate =60 ;Don't assign any value here: this will make sure to avoid double assignments later.
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+u32 target_pixel_clk; +struct drm_display_mode mode; +struct mtk_dp_timings *timings = &mtk_dp->info.timings; +drivers/gpu/drm/mediatek/mtk_dp.c line 1085
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+drm_display_mode_from_videomode (&timings->vm, &mode); + +if (mtk_dp->info.timings.frame_rate >0 ) { + target_frame_rate = mtk_dp->info.timings.frame_rate; + target_pixel_clk = mode.htotal * mode.vtotal * + target_frame_rate; + }else { + target_pixel_clk = mode.htotal * mode.vtotal * + target_frame_rate; + }This should be
Quoted 8 lines
if (mtk_dp->info.timings.frame_rate > 0) target_frame_rate = mtk_dp->info.timings.frame_rate; else target_frame_rate = 60; target_pixel_clk = mode.htotal * mode.vtotal *
target_frame_rate;
ok.
Quoted 26 lines
Quoted 21 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +20
-0+} + +static void mtk_dp_set_tx_out (struct mtk_dp *mtk_dp) +{ +mtk_dp_msa_bypass_disable (mtk_dp); +mtk_dp_calculate_pixrate (mtk_dp); +mtk_dp_pg_disable (mtk_dp); +mtk_dp_setup_tu (mtk_dp); +} + +static ssize_t mtk_dp_hpd_sink_event (struct mtk_dp *mtk_dp) +{ +ssize_t ret; +u8 sink_count; +bool locked; +u8 link_status[DP_LINK_STATUS_SIZE ] = {}; +u32 sink_count_reg =DP_SINK_COUNT_ESI ; +u32 link_status_reg =DP_LANE0_1_STATUS ; + + ret = drm_dp_dpcd_readb(&mtk_dp->aux, sink_count_reg,
&sink_count);drivers/gpu/drm/mediatek/mtk_dp.c line 1106
Quoted 1 line
drivers/gpu/drm/mediatek/mtk_dp.c new file +1
-0+if (ret <0 ) {This function can never return anything > 1, so this should probably be:
Quoted 5 lines
if (ret < 1) {
drm_err ....
return ret == 0 ? -EIO : ret;
}ok, I will check this.
BRs,
Bo-Chen
Quoted 81 lines
Quoted 32 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+drm_err (mtk_dp->drm_dev,"Read sink count failed\n" ); +return ret; + } + + ret = drm_dp_dpcd_read(&mtk_dp->aux, link_status_reg,
link_status,drivers/gpu/drm/mediatek/mtk_dp.c new file +9
-0+ sizeof(link_status)); +if (!ret) { +drm_err (mtk_dp->drm_dev,"Read link status failed\n" ); +return ret; + } + + locked =drm_dp_channel_eq_ok (link_status, + mtk_dp->train_info.lane_count); + if (!locked && mtk_dp->train_state >
MTK_DP_TRAIN_STATE_TRAINING)drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ mtk_dp->train_state =MTK_DP_TRAIN_STATE_TRAINING ; + +if (link_status[1 ] &DP_REMOTE_CONTROL_COMMAND_PENDING ) + drm_dp_dpcd_writeb(&mtk_dp->aux,
DP_DEVICE_SERVICE_IRQ_VECTOR,drivers/gpu/drm/mediatek/mtk_dp.c new file +11
-0+ DP_REMOTE_CONTROL_COMMAND_PENDING); + +if (DP_GET_SINK_COUNT (sink_count) && + (link_status[2 ] &DP_DOWNSTREAM_PORT_STATUS_CHANGED )) { + mtk_dp->train_state =MTK_DP_TRAIN_STATE_TRAINING ; +msleep (20 ); + } + +return 0 ; +} +..snip..
Quoted 32 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ +static int mtk_dp_train_flow(struct mtk_dp *mtk_dp, u8
target_link_rate,drivers/gpu/drm/mediatek/mtk_dp.c new file +12
-0+ u8 target_lane_count) +{ +u8 lane_adjust[2 ] = {}; +bool pass_tps1 = false; +bool pass_tps2_3 = false; +int train_retries; +int status_control; +int iteration_count; +int ret; +u8 prev_lane_adjust; + + drm_dp_dpcd_writeb(&mtk_dp->aux, DP_LINK_BW_SET,
target_link_rate);drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ drm_dp_dpcd_writeb(&mtk_dp->aux, DP_LANE_COUNT_SET, + target_lane_count |
DP_LANE_COUNT_ENHANCED_FRAME_EN);drivers/gpu/drm/mediatek/mtk_dp.c new file +12
-0+ +if (mtk_dp->train_info.sink_ssc) +drm_dp_dpcd_writeb (&mtk_dp->aux,DP_DOWNSPREAD_CTRL , +DP_SPREAD_AMP_0_5 ); + + train_retries =0 ; + status_control =0 ; + iteration_count =1 ; + prev_lane_adjust =0xFF ; + +mtk_dp_set_lanes (mtk_dp, target_lane_count /2 ); + ret = mtk_dp_phy_configure(mtk_dp, target_link_rate,
target_lane_count);drivers/gpu/drm/mediatek/mtk_dp.c line 1302
Quoted 2 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+if (ret) +return -EINVAL ;Why are you overriding the error value here?
drivers/gpu/drm/mediatek/mtk_dp.c line 1307
Quoted 6 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +3
-0+ + dev_dbg(mtk_dp->dev, + "Link train target_link_rate = 0x%x, target_lane_count= 0x%x\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ target_link_rate, target_lane_count); +Cheers,
Angelo
AngeloGioacchino Del Regno
maintainerRe: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
Il 27/06/22 12:30, Rex-BC Chen ha scritto:
Quoted 247 lines · AngeloGioacchino Del Regno
Quoted 92 lines
Il 27/06/22 10:03, Bo-Chen Chen ha scritto:
Quoted 72 lines
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will
never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>--- drivers/gpu/drm/mediatek/Kconfig | 10 + drivers/gpu/drm/mediatek/Makefile | 1 + drivers/gpu/drm/mediatek/mtk_dp.c | 2198 ++++++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_dp_reg.h | 543 ++++++ drivers/gpu/drm/mediatek/mtk_drm_drv.c | 3 + drivers/gpu/drm/mediatek/mtk_drm_drv.h | 3 + 6 files changed, 2758 insertions(+)create mode 100644
drivers/gpu/drm/mediatek/mtk_dp.ccreate mode 100644drivers/gpu/drm/mediatek/mtk_dp_reg.hdrivers/gpu/drm/mediatek/mtk_dp.c new file +25
-0@@ -0,0 +1,2198 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019-2022 MediaTek Inc. +* Copyright (c) 2022 BayLibre +*/ + +#include <drm/display/drm_dp.h> +#include <drm/display/drm_dp_helper.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_bridge.h> +#include <drm/drm_crtc.h> +#include <drm/drm_edid.h> +#include <drm/drm_of.h> +#include <drm/drm_panel.h> +#include <drm/drm_print.h> +#include <drm/drm_probe_helper.h> +#include <linux/arm-smccc.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/nvmem-consumer.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_platform.h> drivers/gpu/drm/mediatek/mtk_dp.c line 35
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regmap.h> +#include <sound/hdmi-codec.h> +#include <video/videomode.h> + +#include "mtk_dp_reg.h" + +#define MTK_DP_SIP_CONTROL_AARCH32 0x82000523Why have you forced this SIP call to AArch32 SMC convention? Is there any particular reason why this should always be AA32 and *never* AA64?
In any case, you've got MediaTek SIP macros in
include/soc/mediatek/mtk_sip_svc.h
so, please, include that header and either redefine this asQuoted 6 lines
MTK_SIP_CMD(0x523)or add a new macro in there to forceARM_SMCCC_SMC_32
convention with a very explanatory comment saying why some calls need to
be forced to use the AArch32 SMC convention.Hello Angelo,
Thanks for your review.
ok, I will do this in next version.Quoted 14 lines
drivers/gpu/drm/mediatek/mtk_dp.c line 46
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +11
-0+ +#define MTK_VDOSYS1_MAX_FRAMERATE 60 +#define MTK_DP_4P1T 4 +#define MTK_DP_HDE 2 +#define MTK_DP_PIX_PER_ADDR 2 +#define MTK_DP_AUX_WAIT_REPLY_COUNT 20 +#define MTK_DP_CHECK_SINK_CAP_TIMEOUT_COUNT 3 +#define MTK_DP_TBC_BUF_READ_START_ADDR 0x08 +#define MTK_DP_TRAIN_RETRY_LIMIT 8 +#define MTK_DP_TRAIN_MAX_ITERATIONS 5 +#define MTK_DP_DP_VERSION_11 0x11
MTK_DP_HW_VERSION_110x11?Quoted 3 lines
...but anyway, this definition is unused, so please either use it or drop it.
it's fro audio patch, and I will move this there.
Quoted 108 lines
Quoted 101 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +92
-0+ +enum mtk_dp_train_state { +MTK_DP_TRAIN_STATE_TRAINING , +MTK_DP_TRAIN_STATE_NORMAL , +}; + +struct mtk_dp_timings { +struct videomode vm; +u8 frame_rate; +}; + +struct mtk_dp_irq_sta { +bool hpd_disconnect; +bool hpd_inerrupt; +}; + +struct mtk_dp_train_info { +bool tps3; +bool tps4; +bool sink_ssc; +bool cable_plugged_in; +bool cable_state_change; +bool cr_done; +bool eq_done; +/* link_rate is in multiple of 0.27Gbps */ +int link_rate; +int lane_count; +struct mtk_dp_irq_sta irq_sta; +}; + +struct mtk_dp_info { +u32 depth; +enum dp_pixelformat format; +struct mtk_dp_timings timings; +}; + +struct dp_cal_data { +unsigned int glb_bias_trim; +unsigned int clktx_impse; + +unsigned int ln_tx_impsel_pmos[4 ]; +unsigned int ln_tx_impsel_nmos[4 ]; +}; + +struct mtk_dp { +struct device *dev; +struct platform_device *phy_dev; +struct phy *phy; +struct dp_cal_data cal_data; +u8 max_lanes; +u8 max_linkrate; + +struct drm_device *drm_dev; +struct drm_bridge bridge; +struct drm_bridge *next_bridge; +struct drm_dp_aux aux; + +u8 rx_cap[DP_RECEIVER_CAP_SIZE ]; + +struct mtk_dp_info info; + +struct mtk_dp_train_info train_info; +enum mtk_dp_train_state train_state; + +struct regmap *regs; + +bool enabled; + +struct drm_connector *conn; +}; + +static struct regmap_config mtk_dp_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =SEC_OFFSET +0x90 , + .name ="mtk-dp-registers" , +}; + +static struct mtk_dp *mtk_dp_from_bridge (struct drm_bridge *b) +{ + return container_of(b, struct mtk_dp, bridge); +} + +static u32 mtk_dp_read (struct mtk_dp *mtk_dp,u32 offset) +{ +u32 read_val; +int ret; + + ret =regmap_read (mtk_dp->regs, offset, &read_val); +if (ret) { + dev_err(mtk_dp->dev, "Failed to read register 0x%x:%d\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +8
-0+ offset, ret); +return 0 ; + } + +return read_val; +} + +static void mtk_dp_write(struct mtk_dp *mtk_dp, u32 offset, u32Quoted 2 lines
val)
+{This should be int... you should propagate the error to the caller, and also
eventually take action in case you get an error.Quoted 13 lines
drivers/gpu/drm/mediatek/mtk_dp.c line 156
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +3
-0+if (regmap_write (mtk_dp->regs, offset, val)) + dev_err(mtk_dp->dev, + "Failed to write register 0x%x with value0x%x\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +6
-0+ offset, val); +} + +static void mtk_dp_update_bits (struct mtk_dp *mtk_dp,u32 offset, +u32 val,u32 mask) +{Same here.
Quoted 8 lines
I don't think we need to control this.
From most drivers, I see there are many example which are not control
the error of write register function.If there is any error, the root cause is power domain is not enabled. In this case, we can not go to these register setting. Besides, we also can saves hundreds of driver lines to handle the write register error.
I agree with your vision - but you may have misunderstood the purpose of what I've proposed....
I'm not proposing to *always check* because, yes, sometimes (most of the times?) you can *safely* assume that the write gives no error and just works as we expect, but to only check that in some particular situations, one of which is in the mtk_dp_bulk_16bit_write() function (yeah, we have mtk_dp_write, not mtk_dp_update_bits, but the comment was put on the former as well).
Quoted 30 lines
Quoted 17 lines
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +3
-0+if (regmap_update_bits (mtk_dp->regs, offset, mask, val)) + dev_err(mtk_dp->dev, + "Failed to update register 0x%x with value0x%x, mask 0x%x\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ offset, val, mask); +} + +static void mtk_dp_bulk_16bit_write(struct mtk_dp *mtk_dp, u32offset, u8 *buf,
drivers/gpu/drm/mediatek/mtk_dp.c line 168
Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+ size_t length) +{ +int i; +int num_regs = (length +1 ) /2 ; +... and here.
Quoted 12 lines
drivers/gpu/drm/mediatek/mtk_dp.c
Quoted 7 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+/* 2 bytes per register */ +for (i =0 ; i < num_regs; i++) { + u32 val = buf[i * 2] | + (i * 2 + 1 < length ? buf[i * 2 + 1] << 8 :0);
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ +mtk_dp_write (mtk_dp, offset + i *4 , val);
P.S.: Does it make sense to keep writing if you get an error?
I'd say that doing this may lead to unexpected hardware
status.
Quoted 3 lines
If one register failed to write, it should be for *all* registers and not only for *one* register.
Yes, that's true - but your mtk_dp_write() function prints an error in the kmsg: for example, if num_regs is 4, we will get four prints.
Also, since logically one register write failing means all will fail (and usually it either fails at the first write, or never) if we check for the return value here, we can avoid iterating again with an expected, repeated, failure.
That's what I was meaning - hope it's clear now :-)
Quoted 316 lines
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+ } +} + +static unsigned long mtk_dp_sip_atf_call (struct mtk_dp *mtk_dp, + unsigned int cmd, unsigned intpara)
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+{ +struct arm_smccc_res res; + + arm_smccc_smc(MTK_DP_SIP_CONTROL_AARCH32, cmd, para, 0, 0, 0,0, 0,
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ &res); +Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_dp.c line 189
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+dev_dbg (mtk_dp->dev,"sip cmd 0x%x, p1 0x%x, ret 0x%lx-0x%lx" , + cmd, para, res.a0, res.a1); + +return res.a1;We have
SIP_SVC_E_(xxxxx)error codes defined inmtk_sip_svc.h... this makes me
think that res.a1 is not an unsigned long for real: please confirm.ok, I will confirm that.
Quoted 31 lines
Quoted 2 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+} +..snip..
Quoted 26 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +26
-0+ +static void mtk_dp_set_color_format (struct mtk_dp *mtk_dp, +enum dp_pixelformat color_format) +{ +u32 val; + + mtk_dp->info.format = color_format; + +/* update MISC0 */ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3034 , + color_format <<DP_TEST_COLOR_FORMAT_SHIFT , +DP_TEST_COLOR_FORMAT_MASK ); + +switch (color_format) { +case DP_PIXELFORMAT_YUV422 : + val =PIXEL_ENCODE_FORMAT_DP_ENC0_P0_YCBCR422 ; +break ; +case DP_PIXELFORMAT_YUV420 : + val =PIXEL_ENCODE_FORMAT_DP_ENC0_P0_YCBCR420 ; +break ; +case DP_PIXELFORMAT_RGB : +case DP_PIXELFORMAT_YUV444 : + val =PIXEL_ENCODE_FORMAT_DP_ENC0_P0_RGB ; +break ; +case DP_PIXELFORMAT_Y_ONLY : +case DP_PIXELFORMAT_RAW :Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_dp.c
Quoted 6 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +3
-0+case DP_PIXELFORMAT_RESERVED : +default : + drm_warn(mtk_dp->drm_dev, "Unsupported color format:%d\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ color_format); +return ;return
-EINVALhere?ok, I will take care the error handle.
Quoted 118 lines
drivers/gpu/drm/mediatek/mtk_dp.c line 312
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ } + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_303C , + val,PIXEL_ENCODE_FORMAT_DP_ENC0_P0_MASK );... and return 0 here.
Quoted 20 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +20
-0+} + +static void mtk_dp_set_color_depth (struct mtk_dp *mtk_dp) +{ +u32 val; +/* Only support 8 bits currently */ +u32 color_depth =DP_MSA_MISC_8_BPC ; + + mtk_dp->info.depth = color_depth; + +/* Update MISC0 */ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3034 , + color_depth,DP_TEST_BIT_DEPTH_MASK ); + +switch (color_depth) { +case DP_MSA_MISC_6_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_6BIT ; +break ; +case DP_MSA_MISC_8_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_8BIT ;drivers/gpu/drm/mediatek/mtk_dp.c line 342
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+break ; +case DP_MSA_MISC_10_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_10BIT ; +break ; +case DP_MSA_MISC_12_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_12BIT ; +break ; +case DP_MSA_MISC_16_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_16BIT ; +break ;ditto
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+default : + drm_warn(mtk_dp->drm_dev, "Unsupported color depth%d\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +8
-0+ color_depth); +return ; + } + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_303C , val, +VIDEO_COLOR_DEPTH_DP_ENC0_P0_MASK ); +} +..snip..
Quoted 18 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +8
-0+ +static int mtk_dp_phy_configure(struct mtk_dp *mtk_dp, + u32 link_rate, int lane_count) +{ + int ret; + union phy_configure_opts phy_opts = { + .dp = { + .link_rate = link_rate_to_mb_per_s(mtk_dp,
link_rate),drivers/gpu/drm/mediatek/mtk_dp.c new file +8
-0+ .set_rate = 1, + .lanes = lane_count, + .set_lanes = 1, + .ssc = mtk_dp->train_info.sink_ssc, + } + }; + + mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE,
DP_PWR_STATE_BANDGAP,drivers/gpu/drm/mediatek/mtk_dp.c line 940
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ DP_PWR_STATE_MASK); + + ret =phy_configure (mtk_dp->phy, &phy_opts); +This new blank line is unnecessary, please remove.
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +6
-0+if (ret) +return ret; + +mtk_dp_set_cal_data (mtk_dp); + mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE, + DP_PWR_STATE_BANDGAP_TPLL_LANE,
DP_PWR_STATE_MASK);drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ +return 0 ; +} +..snip..
drivers/gpu/drm/mediatek/mtk_dp.c line 1071
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ +static void mtk_dp_calculate_pixrate (struct mtk_dp *mtk_dp) +{ +u8 target_frame_rate =60 ;Don't assign any value here: this will make sure to avoid double assignments later.
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+u32 target_pixel_clk; +struct drm_display_mode mode; +struct mtk_dp_timings *timings = &mtk_dp->info.timings; +drivers/gpu/drm/mediatek/mtk_dp.c line 1085
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+drm_display_mode_from_videomode (&timings->vm, &mode); + +if (mtk_dp->info.timings.frame_rate >0 ) { + target_frame_rate = mtk_dp->info.timings.frame_rate; + target_pixel_clk = mode.htotal * mode.vtotal * + target_frame_rate; + }else { + target_pixel_clk = mode.htotal * mode.vtotal * + target_frame_rate; + }This should be
Quoted 8 lines
if (mtk_dp->info.timings.frame_rate > 0) target_frame_rate = mtk_dp->info.timings.frame_rate; else target_frame_rate = 60; target_pixel_clk = mode.htotal * mode.vtotal *
target_frame_rate;ok.
Quoted 26 lines
Quoted 21 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +20
-0+} + +static void mtk_dp_set_tx_out (struct mtk_dp *mtk_dp) +{ +mtk_dp_msa_bypass_disable (mtk_dp); +mtk_dp_calculate_pixrate (mtk_dp); +mtk_dp_pg_disable (mtk_dp); +mtk_dp_setup_tu (mtk_dp); +} + +static ssize_t mtk_dp_hpd_sink_event (struct mtk_dp *mtk_dp) +{ +ssize_t ret; +u8 sink_count; +bool locked; +u8 link_status[DP_LINK_STATUS_SIZE ] = {}; +u32 sink_count_reg =DP_SINK_COUNT_ESI ; +u32 link_status_reg =DP_LANE0_1_STATUS ; + + ret = drm_dp_dpcd_readb(&mtk_dp->aux, sink_count_reg,
&sink_count);drivers/gpu/drm/mediatek/mtk_dp.c line 1106
Quoted 1 line
drivers/gpu/drm/mediatek/mtk_dp.c new file +1
-0+if (ret <0 ) {This function can never return anything > 1, so this should probably be:
Quoted 5 lines
if (ret < 1) { drm_err .... return ret == 0 ? -EIO : ret; }ok, I will check this.
BRs,
Bo-ChenQuoted 81 lines
Quoted 32 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+drm_err (mtk_dp->drm_dev,"Read sink count failed\n" ); +return ret; + } + + ret = drm_dp_dpcd_read(&mtk_dp->aux, link_status_reg,
link_status,drivers/gpu/drm/mediatek/mtk_dp.c new file +9
-0+ sizeof(link_status)); +if (!ret) { +drm_err (mtk_dp->drm_dev,"Read link status failed\n" ); +return ret; + } + + locked =drm_dp_channel_eq_ok (link_status, + mtk_dp->train_info.lane_count); + if (!locked && mtk_dp->train_state >
MTK_DP_TRAIN_STATE_TRAINING)drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ mtk_dp->train_state =MTK_DP_TRAIN_STATE_TRAINING ; + +if (link_status[1 ] &DP_REMOTE_CONTROL_COMMAND_PENDING ) + drm_dp_dpcd_writeb(&mtk_dp->aux,
DP_DEVICE_SERVICE_IRQ_VECTOR,drivers/gpu/drm/mediatek/mtk_dp.c new file +11
-0+ DP_REMOTE_CONTROL_COMMAND_PENDING); + +if (DP_GET_SINK_COUNT (sink_count) && + (link_status[2 ] &DP_DOWNSTREAM_PORT_STATUS_CHANGED )) { + mtk_dp->train_state =MTK_DP_TRAIN_STATE_TRAINING ; +msleep (20 ); + } + +return 0 ; +} +..snip..
Quoted 32 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ +static int mtk_dp_train_flow(struct mtk_dp *mtk_dp, u8
target_link_rate,drivers/gpu/drm/mediatek/mtk_dp.c new file +12
-0+ u8 target_lane_count) +{ +u8 lane_adjust[2 ] = {}; +bool pass_tps1 = false; +bool pass_tps2_3 = false; +int train_retries; +int status_control; +int iteration_count; +int ret; +u8 prev_lane_adjust; + + drm_dp_dpcd_writeb(&mtk_dp->aux, DP_LINK_BW_SET,
target_link_rate);drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ drm_dp_dpcd_writeb(&mtk_dp->aux, DP_LANE_COUNT_SET, + target_lane_count |
DP_LANE_COUNT_ENHANCED_FRAME_EN);drivers/gpu/drm/mediatek/mtk_dp.c new file +12
-0+ +if (mtk_dp->train_info.sink_ssc) +drm_dp_dpcd_writeb (&mtk_dp->aux,DP_DOWNSPREAD_CTRL , +DP_SPREAD_AMP_0_5 ); + + train_retries =0 ; + status_control =0 ; + iteration_count =1 ; + prev_lane_adjust =0xFF ; + +mtk_dp_set_lanes (mtk_dp, target_lane_count /2 ); + ret = mtk_dp_phy_configure(mtk_dp, target_link_rate,
target_lane_count);drivers/gpu/drm/mediatek/mtk_dp.c line 1302
Quoted 2 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+if (ret) +return -EINVAL ;Why are you overriding the error value here?
drivers/gpu/drm/mediatek/mtk_dp.c line 1307
Quoted 6 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +3
-0+ + dev_dbg(mtk_dp->dev, + "Link train target_link_rate = 0x%x, target_lane_count= 0x%x\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ target_link_rate, target_lane_count); +Cheers,
Angelo
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenHi, Bo-Chen:
Quoted 43 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>--- drivers/gpu/drm/mediatek/Kconfig | 10 + drivers/gpu/drm/mediatek/Makefile | 1 + drivers/gpu/drm/mediatek/mtk_dp.c | 2198 ++++++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_dp_reg.h | 543 ++++++ drivers/gpu/drm/mediatek/mtk_drm_drv.c | 3 + drivers/gpu/drm/mediatek/mtk_drm_drv.h | 3 + 6 files changed, 2758 insertions(+) create mode 100644 drivers/gpu/drm/mediatek/mtk_dp.c create mode 100644 drivers/gpu/drm/mediatek/mtk_dp_reg.hdrivers/gpu/drm/mediatek/Kconfig +0
-0
drivers/gpu/drm/mediatek/Kconfig config DRM_MEDIATEK · line 18
Quoted 4 lines
drivers/gpu/drm/mediatek/Kconfig +1
-0@@ -15,12 +15,22 @@ config DRM_MEDIATEK select MTK_SMI select PHY_MTK_MIPI_DSI select VIDEOMODE_HELPERS + select DRM_MEDIATEK_DP
Remove this.
Quoted 16 lines
drivers/gpu/drm/mediatek/Kconfig +9
-0help Choose this option if you have a Mediatek SoCs. The module will be called mediatek-drm This driver provides kernel mode setting and buffer management to userspace. +config DRM_MEDIATEK_DP + tristate "DRM DPTX Support for MediaTek SoCs" + depends on DRM_MEDIATEK + select PHY_MTK_DP + select DRM_DISPLAY_HELPER + select DRM_DISPLAY_DP_HELPER + help + DRM/KMS Display Port driver for MediaTek SoCs. +
[snip]
drivers/gpu/drm/mediatek/mtk_drm_drv.c static struct platform_driver * const · line 1039
Quoted 13 lines
drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-0@@ -1033,6 +1033,9 @@ static struct platform_driver * const mtk_drm_drivers[] = { &mtk_disp_ovl_driver, &mtk_disp_rdma_driver, &mtk_dpi_driver, +#if IS_REACHABLE(CONFIG_DRM_MEDIATEK_DP) + &mtk_dp_driver, +#endif
Remove this, and treat dp driver like hdmi driver.
Regards,
CK
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_drm_drv.c +0
-0&mtk_drm_platform_driver, &mtk_dsi_driver,
&mtk_ethdr_driver,
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenHi, Bo-Chen:
Quoted 26 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
Quoted 27 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +13
-0+ +static int mtk_dp_training (struct mtk_dp *mtk_dp) +{ +bool training_done = false; +short max_retry =50 ; +int ret =0 ; + + do { + switch (mtk_dp->train_state) { + case MTK_DP_TRAIN_STATE_TRAINING: + ret = mtk_dp_train_start(mtk_dp); + if (!ret) + mtk_dp->train_state =
MTK_DP_TRAIN_STATE_NORMAL;drivers/gpu/drm/mediatek/mtk_dp.c new file +13
-0+break ; +case MTK_DP_TRAIN_STATE_NORMAL : +mtk_dp_video_config (mtk_dp); +mtk_dp_video_enable (mtk_dp, true); + training_done = true; +break ; +default : +break ; + } + +if (ret) { +if (ret == -EAGAIN ) +continue ;
drivers/gpu/drm/mediatek/mtk_dp.c line 1532
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+/* +* If we get any other error number, it doesn't +* make any sense to keep iterating. +*/ +break ; + } + }while (!training_done || --max_retry); + +return ret; +}
This function could re rewritten as:
static bool mtk_dp_training(struct mtk_dp *mtk_dp)
{
short max_retry = 50;
do {
ret = mtk_dp_train_start(mtk_dp);
if (!ret)
break;
else if (ret != -EAGAIN)
return false;
} while (--max_retry);
if (!max_retry)
return false;
mtk_dp_video_config(mtk_dp);
mtk_dp_video_enable(mtk_dp, true);
return true;
}Regards,
CK
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenHi, Bo-Chen:
Quoted 26 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +9
-0+ +static irqreturn_t mtk_dp_hpd_event_thread (int hpd,void *dev) +{ +struct mtk_dp *mtk_dp = dev; +u8 buf[DP_RECEIVER_CAP_SIZE ] = {}; + +if (mtk_dp->train_info.cable_state_change) { + mtk_dp->train_info.cable_state_change = false; +
drivers/gpu/drm/mediatek/mtk_dp.c line 1567
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+mtk_dp_update_bits (mtk_dp,MTK_DP_TOP_PWR_STATE , +DP_PWR_STATE_BANDGAP_TPLL_LANE , +DP_PWR_STATE_MASK ); +drm_dp_read_dpcd_caps (&mtk_dp->aux, buf); + mtk_dp->train_info.link_rate = +min_t (int, mtk_dp->max_linkrate, + buf[mtk_dp->max_linkrate]); + mtk_dp->train_info.lane_count = +min_t (int, mtk_dp->max_lanes, +drm_dp_max_lane_count (buf));
If the state_change is unplug, why do you modify link_rate and lane_count?
If the state_change is plug, there is a training flow to decide link_rate and lane_count. I think the training flow is correct and any modification here is redundant.
Regards,
CK
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +11
-0+ } + +if (mtk_dp->train_info.irq_sta.hpd_inerrupt) { +dev_dbg (mtk_dp->dev,"MTK_DP_HPD_INTERRUPT\n" ); + mtk_dp->train_info.irq_sta.hpd_inerrupt = false; +mtk_dp_hpd_sink_event (mtk_dp); + } + +return IRQ_HANDLED ; +} +
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenHi, Bo-Chen:
Quoted 26 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ +static void mtk_dp_calculate_pixrate (struct mtk_dp *mtk_dp) +{ +u8 target_frame_rate =60 ;
drivers/gpu/drm/mediatek/mtk_dp.c line 1081
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+u32 target_pixel_clk; +struct drm_display_mode mode; +struct mtk_dp_timings *timings = &mtk_dp->info.timings; + +drm_display_mode_from_videomode (&timings->vm, &mode); + +if (mtk_dp->info.timings.frame_rate >0 ) { + target_frame_rate = mtk_dp->info.timings.frame_rate; + target_pixel_clk = mode.htotal * mode.vtotal * + target_frame_rate;
target_pixel_clk is not used in other place, so remove it.
Regards,
CK
Quoted 6 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +6
-0+ }else { + target_pixel_clk = mode.htotal * mode.vtotal * + target_frame_rate; + } +} +
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenHi, Bo-Chen:
Quoted 26 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
drivers/gpu/drm/mediatek/mtk_dp.c line 1055
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ +static void mtk_dp_setup_tu (struct mtk_dp *mtk_dp) +{ +u32 sram_read_start =MTK_DP_TBC_BUF_READ_START_ADDR ;
This initial value is redundant. So remove this initial value.
drivers/gpu/drm/mediatek/mtk_dp.c line 1057
Quoted 2 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +2
-0+ +if (mtk_dp->train_info.lane_count >0 ) {
This checking would always be true.
This function would be called after training success, so mtk_dp-
Quoted 1 line
train_info.lane_count would be greater than 0.
So remove this checking.
Regards,
CK
Quoted 13 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +3
-0+ sram_read_start =min_t (u32, +MTK_DP_TBC_BUF_READ_START_ADDR , + mtk_dp->info.timings.vm.hactive/
(quoted diff) +2
-0+ mtk_dp->train_info.lane_count / + MTK_DP_4P1T / MTK_DP_HDE /
MTK_DP_PIX_PER_ADDR);drivers/gpu/drm/mediatek/mtk_dp.c new file +6
-0+mtk_dp_set_sram_read_start (mtk_dp, sram_read_start); + } + +mtk_dp_setup_encoder (mtk_dp); +} +
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenHi, Bo-Chen:
Quoted 26 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
Quoted 10 lines
(quoted diff) +2
-0+ +static int link_rate_to_mb_per_s(struct mtk_dp *mtk_dp, u32linkrate)
drivers/gpu/drm/mediatek/mtk_dp.c new file +7
-0+{ +switch (linkrate) { +case DP_LINK_BW_1_62 : +return 1620 ; +case DP_LINK_BW_2_7 : +return 2700 ; +case DP_LINK_BW_5_4 :
drivers/gpu/drm/mediatek/mtk_dp.c line 798
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+return 5400 ; +case DP_LINK_BW_8_1 : +return 8100 ; +default : +drm_err (mtk_dp->drm_dev, +"Implementation error, unknown linkrate %d\n" , + linkrate); +return -EINVAL ; + } +}
It looks like this function is equal to drm_dp_bw_code_to_link_rate(), so remove this function and use drm_dp_bw_code_to_link_rate().
Regards,
CK
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenHi, Bo-Chen:
Quoted 26 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
Quoted 8 lines
+++
b/drivers/gpu/drm/mediatek/mtk_dp_reg.hdrivers/gpu/drm/mediatek/mtk_dp_reg.h new file +6
-0@@ -0,0 +1,543 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019-2022 MediaTek Inc. +* Copyright (c) 2022 BayLibre +*/ +#ifndef _MTK_DP_REG_H_
drivers/gpu/drm/mediatek/mtk_dp_reg.h line 16
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_reg.h new file +10
-0+#define _MTK_DP_REG_H_ + +#define TOP_OFFSET 0x2000 +#define ENC0_OFFSET 0x3000 +#define ENC1_OFFSET 0x3200 +#define TRANS_OFFSET 0x3400 +#define AUX_OFFSET 0x3600 +#define SEC_OFFSET 0x4000 + +#define MTK_DP_SIP_ATF_VIDEO_UNMUTE BIT(5)
Useless, so remove it.
Regards,
CK
Quoted 2 lines
drivers/gpu/drm/mediatek/mtk_dp_reg.h new file +2
-0+#define MTK_DP_SIP_ATF_EDP_VIDEO_UNMUTE (BIT(0) | BIT(5)) +
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenHi, Bo-Chen:
Quoted 26 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
Quoted 19 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +13
-0+ +static void mtk_dp_power_enable (struct mtk_dp *mtk_dp) +{ +mtk_dp_update_bits (mtk_dp,MTK_DP_TOP_RESET_AND_PROBE , +0 ,SW_RST_B_PHYD ); + +/* Wait for power enable */ +usleep_range (10 ,200 ); + +mtk_dp_update_bits (mtk_dp,MTK_DP_TOP_RESET_AND_PROBE , +SW_RST_B_PHYD ,SW_RST_B_PHYD ); + mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE, + DP_PWR_STATE_BANDGAP_TPLL,
DP_PWR_STATE_MASK);drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+} + +static void mtk_dp_power_disable (struct mtk_dp *mtk_dp) +{ +mtk_dp_write (mtk_dp,MTK_DP_TOP_PWR_STATE ,0 );
drivers/gpu/drm/mediatek/mtk_dp.c line 1032
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+ +mtk_dp_write (mtk_dp,MTK_DP_0034 , +DA_CKM_CKTX0_EN_FORCE_EN | +DA_CKM_BIAS_LPF_EN_FORCE_VAL | +DA_CKM_BIAS_EN_FORCE_VAL | +DA_XTP_GLB_LDO_EN_FORCE_VAL | +DA_XTP_GLB_AVD10_ON_FORCE_VAL ); + +/* Disable RX */ +mtk_dp_write (mtk_dp,MTK_DP_1040 ,0 );
MTK_DP_1040 is set to 0 in mtk_dp_power_disable(), but it is not set to other value in mtk_dp_power_enable(). Does any thing would be wrong when mtk_dp_power_disable() and mtk_dp_power_enable()?
Regards,
CK
Quoted 5 lines
(quoted diff) +2
-0+ mtk_dp_write(mtk_dp, MTK_DP_TOP_MEM_PD, + 0x550 | BIT(FUSE_SEL_SHIFT) |
BIT(MEM_ISO_EN_SHIFT));(quoted diff) +2
-0+} +
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
Quoted 69 lines · CK Hu
Hi, Bo-Chen:
Quoted 28 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195
SoC.It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will
never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
Quoted 19 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +13
-0+ +static void mtk_dp_power_enable (struct mtk_dp *mtk_dp) +{ +mtk_dp_update_bits (mtk_dp,MTK_DP_TOP_RESET_AND_PROBE , +0 ,SW_RST_B_PHYD ); + +/* Wait for power enable */ +usleep_range (10 ,200 ); + +mtk_dp_update_bits (mtk_dp,MTK_DP_TOP_RESET_AND_PROBE , +SW_RST_B_PHYD ,SW_RST_B_PHYD ); + mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE, + DP_PWR_STATE_BANDGAP_TPLL,
DP_PWR_STATE_MASK);drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+} + +static void mtk_dp_power_disable (struct mtk_dp *mtk_dp) +{ +mtk_dp_write (mtk_dp,MTK_DP_TOP_PWR_STATE ,0 );drivers/gpu/drm/mediatek/mtk_dp.c line 1032
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+ +mtk_dp_write (mtk_dp,MTK_DP_0034 , +DA_CKM_CKTX0_EN_FORCE_EN | +DA_CKM_BIAS_LPF_EN_FORCE_VAL | +DA_CKM_BIAS_EN_FORCE_VAL | +DA_XTP_GLB_LDO_EN_FORCE_VAL | +DA_XTP_GLB_AVD10_ON_FORCE_VAL ); + +/* Disable RX */ +mtk_dp_write (mtk_dp,MTK_DP_1040 ,0 );
MTK_DP_1040is set to 0 inmtk_dp_power_disable(), but it is not set to
other value inmtk_dp_power_enable(). Does any thing would be wrong whenmtk_dp_power_disable()andmtk_dp_power_enable()?
Quoted 3 lines
Regards,
CK
Hello CK,
in mtk_dp_power_enable(),
after we reset the hw:
mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_RESET_AND_PROBE,
SW_RST_B_PHYD, SW_RST_B_PHYD); mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE, DP_PWR_STATE_BANDGAP_TPLL, DP_PWR_STATE_MASK);
the value will be set back to default value 0x7.
I will add "mtk_dp_write(mtk_dp, MTK_DP_1040, 7);" to prevent misunderstanding.
BRs,
Bo-Chen
Quoted 7 lines
Quoted 5 lines
(quoted diff) +2
-0+ mtk_dp_write(mtk_dp, MTK_DP_TOP_MEM_PD, + 0x550 | BIT(FUSE_SEL_SHIFT) |
BIT(MEM_ISO_EN_SHIFT));(quoted diff) +2
-0+} +
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenHi, Bo-Chen:
Quoted 26 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
drivers/gpu/drm/mediatek/mtk_dp.c line 1029
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +11
-0+ +static void mtk_dp_power_disable (struct mtk_dp *mtk_dp) +{ +mtk_dp_write (mtk_dp,MTK_DP_TOP_PWR_STATE ,0 ); + +mtk_dp_write (mtk_dp,MTK_DP_0034 , +DA_CKM_CKTX0_EN_FORCE_EN | +DA_CKM_BIAS_LPF_EN_FORCE_VAL | +DA_CKM_BIAS_EN_FORCE_VAL | +DA_XTP_GLB_LDO_EN_FORCE_VAL | +DA_XTP_GLB_AVD10_ON_FORCE_VAL );
Is this clock gating? If so, separate this to ccf driver.
Regards,
CK
Quoted 8 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+ +/* Disable RX */ +mtk_dp_write (mtk_dp,MTK_DP_1040 ,0 ); + mtk_dp_write(mtk_dp, MTK_DP_TOP_MEM_PD, + 0x550 | BIT(FUSE_SEL_SHIFT) |
BIT(MEM_ISO_EN_SHIFT));(quoted diff) +2
-0+} +
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
Quoted 48 lines · CK Hu
Hi, Bo-Chen:
Quoted 28 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195
SoC.It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will
never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
drivers/gpu/drm/mediatek/mtk_dp.c line 1029
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +11
-0+ +static void mtk_dp_power_disable (struct mtk_dp *mtk_dp) +{ +mtk_dp_write (mtk_dp,MTK_DP_TOP_PWR_STATE ,0 ); + +mtk_dp_write (mtk_dp,MTK_DP_0034 , +DA_CKM_CKTX0_EN_FORCE_EN | +DA_CKM_BIAS_LPF_EN_FORCE_VAL | +DA_CKM_BIAS_EN_FORCE_VAL | +DA_XTP_GLB_LDO_EN_FORCE_VAL | +DA_XTP_GLB_AVD10_ON_FORCE_VAL );Is this clock gating? If so, separate this to ccf driver.
Quoted 3 lines
Regards,
CK
Hello CK,
this register is inside dp hardware, so it should not move to ccf driver.
BRs,
Bo-Chen
Quoted 10 lines
Quoted 8 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+ +/* Disable RX */ +mtk_dp_write (mtk_dp,MTK_DP_1040 ,0 ); + mtk_dp_write(mtk_dp, MTK_DP_TOP_MEM_PD, + 0x550 | BIT(FUSE_SEL_SHIFT) |
BIT(MEM_ISO_EN_SHIFT));(quoted diff) +2
-0+} +
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenHi, Bo-Chen:
Quoted 26 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
Quoted 44 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +16
-0+ +static int mtk_dp_dt_parse (struct mtk_dp *mtk_dp, +struct platform_device *pdev) +{ +struct device_node *of_node = pdev->dev.of_node; +struct device *dev = &pdev->dev; +int ret =0 ; +void __iomem *base; +u32 linkrate; +int len; + + base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (base)) +return PTR_ERR (base); + + mtk_dp->regs = devm_regmap_init_mmio(dev, base,
&mtk_dp_regmap_config);drivers/gpu/drm/mediatek/mtk_dp.c new file +5
-0+if (IS_ERR (mtk_dp->regs)) +return PTR_ERR (mtk_dp->regs); + + len = of_property_count_elems_of_size(of_node, + "data-lanes",sizeof(u32));
drivers/gpu/drm/mediatek/mtk_dp.c new file +8
-0+if (len <0 || len >4 || len ==3 ) { +dev_err (dev,"invalid data lane size: %d\n" , len); +return -EINVAL ; + } + + mtk_dp->max_lanes = len; + + ret = device_property_read_u32(dev, "max-linkrate-mhz",&linkrate);
drivers/gpu/drm/mediatek/mtk_dp.c new file +12
-0+if (ret) { +dev_err (dev,"failed to read max linkrate: %d\n" , ret); +return ret; + } + +switch (linkrate) { +case 8100 :/* 8.1G */ + mtk_dp->max_linkrate =DP_LINK_BW_8_1 ; +break ; +case 5400 :/* 5.4G */ + mtk_dp->max_linkrate =DP_LINK_BW_5_4 ; +break ;
drivers/gpu/drm/mediatek/mtk_dp.c line 1690
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+case 2700 :/* 2.7G */ + mtk_dp->max_linkrate =DP_LINK_BW_2_7 ; +break ; +case 1620 :/* 1.62G */ + mtk_dp->max_linkrate =DP_LINK_BW_1_62 ; +break ; +default : +dev_err (dev,"invalid linkrate: %d\n" , linkrate); +return -EINVAL ; + }
Use drm_dp_link_rate_to_bw_code() instead of self-implementation.
Regards,
CK
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +4
-0+ +return 0 ; +} +
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenHi, Bo-Chen:
Quoted 26 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +9
-0+ +static void mtk_dp_set_color_depth (struct mtk_dp *mtk_dp) +{ +u32 val; +/* Only support 8 bits currently */ +u32 color_depth =DP_MSA_MISC_8_BPC ; + + mtk_dp->info.depth = color_depth; +
drivers/gpu/drm/mediatek/mtk_dp.c line 332
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+/* Update MISC0 */ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3034 , + color_depth,DP_TEST_BIT_DEPTH_MASK ); + +switch (color_depth) { +case DP_MSA_MISC_6_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_6BIT ; +break ; +case DP_MSA_MISC_8_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_8BIT ;
This driver just use DP_MSA_MISC_8_BPC, so keep this and drop others.
Regards,
CK
Quoted 21 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +12
-0+break ; +case DP_MSA_MISC_10_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_10BIT ; +break ; +case DP_MSA_MISC_12_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_12BIT ; +break ; +case DP_MSA_MISC_16_BPC : + val =VIDEO_COLOR_DEPTH_DP_ENC0_P0_16BIT ; +break ; +default : + drm_warn(mtk_dp->drm_dev, "Unsupported color depth%d\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +8
-0+ color_depth); +return ; + } + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_303C , val, +VIDEO_COLOR_DEPTH_DP_ENC0_P0_MASK ); +} +
Re: [PATCH v12 05/10] drm/mediatek: Add MT8195 Embedded DisplayPort driver
In reply to Bo-Chen ChenHi, Bo-Chen:
Quoted 26 lines · Bo-Chen Chen
From: Markus Schneider-Pargmann <[email protected]>
This patch adds a embedded displayport driver for the MediaTek mt8195 SoC.
It supports the MT8195, the embedded DisplayPort units. It offers DisplayPort 1.4 with up to 4 lanes.
The driver creates a child device for the phy. The child device will never exist without the parent being active. As they are sharing a register range, the parent passes a regmap pointer to the child so that
both can work with the same register range. The phy driver sets device
data that is read by the parent to get the phy device that can be used
to control the phy properties.This driver is based on an initial version by
Jitao shi <[email protected]>Signed-off-by Markus Schneider-Pargmann <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Cleanup the drivers and modify comments from reviewers]Signed-off-by Bo-Chen Chen <[email protected]>---
[snip]
drivers/gpu/drm/mediatek/mtk_dp.c line 284
Quoted 7 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +7
-0+ +static void mtk_dp_set_color_format (struct mtk_dp *mtk_dp, +enum dp_pixelformat color_format) +{ +u32 val; + + mtk_dp->info.format = color_format;
Drop this. mtk_dp->info.format is alwasy set out of this function.
drivers/gpu/drm/mediatek/mtk_dp.c line 294
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +10
-0+ +/* update MISC0 */ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3034 , + color_format <<DP_TEST_COLOR_FORMAT_SHIFT , +DP_TEST_COLOR_FORMAT_MASK ); + +switch (color_format) { +case DP_PIXELFORMAT_YUV422 : + val =PIXEL_ENCODE_FORMAT_DP_ENC0_P0_YCBCR422 ; +break ;
This driver use only DP_PIXELFORMAT_YUV422 and DP_PIXELFORMAT_RGB, so keep these two and drop others.
Regards,
CK
Quoted 21 lines
drivers/gpu/drm/mediatek/mtk_dp.c new file +12
-0+case DP_PIXELFORMAT_YUV420 : + val =PIXEL_ENCODE_FORMAT_DP_ENC0_P0_YCBCR420 ; +break ; +case DP_PIXELFORMAT_RGB : +case DP_PIXELFORMAT_YUV444 : + val =PIXEL_ENCODE_FORMAT_DP_ENC0_P0_RGB ; +break ; +case DP_PIXELFORMAT_Y_ONLY : +case DP_PIXELFORMAT_RAW : +case DP_PIXELFORMAT_RESERVED : +default : + drm_warn(mtk_dp->drm_dev, "Unsupported color format:%d\n",
drivers/gpu/drm/mediatek/mtk_dp.c new file +8
-0+ color_format); +return ; + } + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_303C , + val,PIXEL_ENCODE_FORMAT_DP_ENC0_P0_MASK ); +} +
PATCH v12 6/10 drm/mediatek: Add MT8195 External DisplayPort support
In reply to Bo-Chen ChenFrom: Guillaume Ranquet <[email protected]>
This patch adds External DisplayPort support to the mt8195 eDP driver.
--- drivers/gpu/drm/mediatek/mtk_dp.c | 217 ++++++++++++++++++++++++------ 1 file changed, 174 insertions(+), 43 deletions(-)
drivers/gpu/drm/mediatek/mtk_dp.c +174 -43
@@ -111,6 +111,7 @@ struct mtk_dp {struct regmap *regs;bool enabled; +bool has_fec;struct drm_connector *conn; };
@@ -123,6 +124,11 @@ static struct regmap_config mtk_dp_regmap_config = { .name = "mtk-dp-registers", }; +static bool mtk_dp_is_edp (struct mtk_dp *mtk_dp) +{ +return mtk_dp->next_bridge; +} +static struct mtk_dp *mtk_dp_from_bridge (struct drm_bridge *b) { return container_of(b, struct mtk_dp, bridge);
@@ -401,6 +407,20 @@ static bool mtk_dp_plug_state(struct mtk_dp *mtk_dp) HPD_DB_DP_TRANS_P0_MASK); } +static bool mtk_dp_plug_state_avoid_pulse (struct mtk_dp *mtk_dp) +{ +int wait; + +for (wait =7 ; !mtk_dp_plug_state (mtk_dp) && wait >0 ; --wait) +/* Avoid short pulses on the HPD isr */ +usleep_range (1000 ,5000 ); + +if (wait ==0 ) +return false; + +return true; +} +static void mtk_dp_aux_irq_clear (struct mtk_dp *mtk_dp) { mtk_dp_write(mtk_dp, MTK_DP_AUX_P0_3640,
@@ -625,6 +645,13 @@ static void mtk_dp_reset_swing_pre_emphasis(struct mtk_dp *mtk_dp) DP_TX3_PRE_EMPH_MASK); } +static void mtk_dp_fec_enable (struct mtk_dp *mtk_dp,bool enable) +{ +mtk_dp_update_bits (mtk_dp,MTK_DP_TRANS_P0_3540 , + enable ?BIT (FEC_EN_DP_TRANS_P0_SHIFT ) :0 , +FEC_EN_DP_TRANS_P0_MASK ); +} +static u32 mtk_dp_swirq_get_clear (struct mtk_dp *mtk_dp) { u32 irq_status = mtk_dp_read(mtk_dp, MTK_DP_TRANS_P0_35D0) &
@@ -851,35 +878,67 @@ static void mtk_dp_get_calibration_data(struct mtk_dp *mtk_dp)return ; } - cal_data->glb_bias_trim = -check_cal_data_valid (mtk_dp,1 ,0x1e , - (buf[3 ] >>27 ) &0x1f ,0xf ); - cal_data->clktx_impse = -check_cal_data_valid (mtk_dp,1 ,0xe , - (buf[0 ] >>9 ) &0xf ,0x8 ); - cal_data->ln_tx_impsel_pmos[0 ] = -check_cal_data_valid (mtk_dp,1 ,0xe , - (buf[2 ] >>28 ) &0xf ,0x8 ); - cal_data->ln_tx_impsel_nmos[0 ] = -check_cal_data_valid (mtk_dp,1 ,0xe , - (buf[2 ] >>24 ) &0xf ,0x8 ); - cal_data->ln_tx_impsel_pmos[1 ] = -check_cal_data_valid (mtk_dp,1 ,0xe , - (buf[2 ] >>20 ) &0xf ,0x8 ); - cal_data->ln_tx_impsel_nmos[1 ] = -check_cal_data_valid (mtk_dp,1 ,0xe , - (buf[2 ] >>16 ) &0xf ,0x8 ); - cal_data->ln_tx_impsel_pmos[2 ] = -check_cal_data_valid (mtk_dp,1 ,0xe , - (buf[2 ] >>12 ) &0xf ,0x8 ); - cal_data->ln_tx_impsel_nmos[2 ] = -check_cal_data_valid (mtk_dp,1 ,0xe , - (buf[2 ] >>8 ) &0xf ,0x8 ); - cal_data->ln_tx_impsel_pmos[3 ] = -check_cal_data_valid (mtk_dp,1 ,0xe , - (buf[2 ] >>4 ) &0xf ,0x8 ); - cal_data->ln_tx_impsel_nmos[3 ] = -check_cal_data_valid (mtk_dp,1 ,0xe , buf[2 ] &0xf ,0x8 ); +if (mtk_dp_is_edp (mtk_dp)) { + cal_data->glb_bias_trim = +check_cal_data_valid (mtk_dp,1 ,0x1e , + (buf[3 ] >>27 ) &0x1f ,0xf ); + cal_data->clktx_impse = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[0 ] >>9 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_pmos[0 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[2 ] >>28 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_nmos[0 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[2 ] >>24 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_pmos[1 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[2 ] >>20 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_nmos[1 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[2 ] >>16 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_pmos[2 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[2 ] >>12 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_nmos[2 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[2 ] >>8 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_pmos[3 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[2 ] >>4 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_nmos[3 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , buf[2 ] &0xf ,0x8 ); + }else { + cal_data->glb_bias_trim = +check_cal_data_valid (mtk_dp,1 ,0x1e , + (buf[0 ] >>27 ) &0x1f ,0xf ); + cal_data->clktx_impse = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[0 ] >>13 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_pmos[0 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[1 ] >>28 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_nmos[0 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[1 ] >>24 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_pmos[1 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[1 ] >>20 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_nmos[1 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[1 ] >>16 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_pmos[2 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[1 ] >>12 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_nmos[2 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[1 ] >>8 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_pmos[3 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , + (buf[1 ] >>4 ) &0xf ,0x8 ); + cal_data->ln_tx_impsel_nmos[3 ] = +check_cal_data_valid (mtk_dp,1 ,0xe , buf[1 ] &0xf ,0x8 ); + }kfree (buf); }
@@ -1000,7 +1059,10 @@ static void mtk_dp_video_mute(struct mtk_dp *mtk_dp, bool enable)VIDEO_MUTE_SEL_DP_ENC0_P0_MASK | VIDEO_MUTE_SW_DP_ENC0_P0_MASK); -mtk_dp_sip_atf_call (mtk_dp,MTK_DP_SIP_ATF_EDP_VIDEO_UNMUTE , enable); +mtk_dp_sip_atf_call (mtk_dp, +mtk_dp_is_edp (mtk_dp) ? +MTK_DP_SIP_ATF_EDP_VIDEO_UNMUTE : +MTK_DP_SIP_ATF_VIDEO_UNMUTE , enable); }static void mtk_dp_power_enable (struct mtk_dp *mtk_dp)
@@ -1048,6 +1110,8 @@ static void mtk_dp_initialize_priv_data(struct mtk_dp *mtk_dp) mtk_dp->info.depth =DP_MSA_MISC_8_BPC ;memset (&mtk_dp->info.timings,0 ,sizeof (struct mtk_dp_timings )); mtk_dp->info.timings.frame_rate =60 ; + + mtk_dp->has_fec = false; }static void mtk_dp_setup_tu (struct mtk_dp *mtk_dp)
@@ -1370,6 +1434,9 @@ static int mtk_dp_parse_capabilities(struct mtk_dp *mtk_dp)drm_dp_dpcd_writeb (&mtk_dp->aux,DP_SET_POWER ,DP_SET_POWER_D0 );usleep_range (2000 ,5000 ); +if (!mtk_dp_plug_state (mtk_dp)) +return -ENODEV ; +drm_dp_read_dpcd_caps (&mtk_dp->aux, mtk_dp->rx_cap); train_info->link_rate = min_t(int, mtk_dp->max_linkrate,
@@ -1410,6 +1477,9 @@ static int mtk_dp_train_start(struct mtk_dp *mtk_dp)u8 train_limit;u8 max_link_rate; +if (!mtk_dp_plug_state_avoid_pulse (mtk_dp)) +return -ENODEV ; + link_rate = mtk_dp->rx_cap[1 ]; lane_count = mtk_dp->rx_cap[2 ] &0x1F ;
@@ -1550,21 +1620,46 @@ static void mtk_dp_init_port(struct mtk_dp *mtk_dp)static irqreturn_t mtk_dp_hpd_event_thread (int hpd,void *dev) {struct mtk_dp *mtk_dp = dev; +int event;u8 buf[DP_RECEIVER_CAP_SIZE ] = {}; + event =mtk_dp_plug_state (mtk_dp) ? + connector_status_connected : connector_status_disconnected; + +if (event <0 ) +return IRQ_HANDLED ; + +dev_info (mtk_dp->dev,"drm_helper_hpd_irq_event\n" ); +drm_helper_hpd_irq_event (mtk_dp->bridge.dev); +if (mtk_dp->train_info.cable_state_change) { mtk_dp->train_info.cable_state_change = false; -mtk_dp_update_bits (mtk_dp,MTK_DP_TOP_PWR_STATE , -DP_PWR_STATE_BANDGAP_TPLL_LANE , -DP_PWR_STATE_MASK ); -drm_dp_read_dpcd_caps (&mtk_dp->aux, buf); - mtk_dp->train_info.link_rate = -min_t (int, mtk_dp->max_linkrate, - buf[mtk_dp->max_linkrate]); - mtk_dp->train_info.lane_count = -min_t (int, mtk_dp->max_lanes, -drm_dp_max_lane_count (buf)); + mtk_dp->train_state =MTK_DP_TRAIN_STATE_TRAINING ; + +if (!mtk_dp->train_info.cable_plugged_in) { +mtk_dp_video_mute (mtk_dp, true); + +mtk_dp_initialize_priv_data (mtk_dp); +mtk_dp_set_idle_pattern (mtk_dp, true); +if (mtk_dp->has_fec) +mtk_dp_fec_enable (mtk_dp, false); + +mtk_dp_update_bits (mtk_dp,MTK_DP_TOP_PWR_STATE , +DP_PWR_STATE_BANDGAP_TPLL , +DP_PWR_STATE_MASK ); + }else { +mtk_dp_update_bits (mtk_dp,MTK_DP_TOP_PWR_STATE , +DP_PWR_STATE_BANDGAP_TPLL_LANE , +DP_PWR_STATE_MASK ); +drm_dp_read_dpcd_caps (&mtk_dp->aux, buf); + mtk_dp->train_info.link_rate = +min_t (int, mtk_dp->max_linkrate, + buf[mtk_dp->max_linkrate]); + mtk_dp->train_info.lane_count = +min_t (int, mtk_dp->max_lanes, +drm_dp_max_lane_count (buf)); + } }if (mtk_dp->train_info.irq_sta.hpd_inerrupt) {
@@ -1692,6 +1787,24 @@ static int mtk_dp_dt_parse(struct mtk_dp *mtk_dp,return 0 ; } +static enum drm_connector_status mtk_dp_bdg_detect (struct drm_bridge *bridge) +{ +struct mtk_dp *mtk_dp =mtk_dp_from_bridge (bridge); +enum drm_connector_status ret = connector_status_disconnected; +u8 sink_count =0 ; + +if (mtk_dp_is_edp (mtk_dp)) +return connector_status_connected; + +if (mtk_dp_plug_state_avoid_pulse (mtk_dp)) { +drm_dp_dpcd_readb (&mtk_dp->aux,DP_SINK_COUNT , &sink_count); +if (DP_GET_SINK_COUNT (sink_count)) + ret = connector_status_connected; + } + +return ret; +} +static struct edid *mtk_dp_get_edid (struct drm_bridge *bridge,struct drm_connector *connector) {
@@ -1705,7 +1818,8 @@ static struct edid *mtk_dp_get_edid(struct drm_bridge *bridge,drm_dp_dpcd_writeb (&mtk_dp->aux,DP_SET_POWER ,DP_SET_POWER_D0 );usleep_range (2000 ,5000 ); - new_edid =drm_get_edid (connector, &mtk_dp->aux.ddc); +if (mtk_dp_plug_state (mtk_dp)) + new_edid =drm_get_edid (connector, &mtk_dp->aux.ddc);if (!enabled)drm_bridge_chain_post_disable (bridge);
@@ -2058,6 +2172,7 @@ static const struct drm_bridge_funcs mtk_dp_bridge_funcs = { .atomic_disable = mtk_dp_bridge_atomic_disable, .mode_valid = mtk_dp_bridge_mode_valid, .get_edid = mtk_dp_get_edid, + .detect = mtk_dp_bdg_detect, };static int mtk_dp_probe (struct platform_device *pdev)
@@ -2079,9 +2194,15 @@ static int mtk_dp_probe(struct platform_device *pdev) "failed to request dp irq resource\n"); mtk_dp->next_bridge =devm_drm_of_get_bridge (dev, dev->of_node,1 ,0 ); -if (IS_ERR (mtk_dp->next_bridge)) +if (IS_ERR (mtk_dp->next_bridge) && +PTR_ERR (mtk_dp->next_bridge) == -ENODEV ) { +dev_info (dev, +"No panel connected in devicetree, continue as external DP\n" ); + mtk_dp->next_bridge =NULL ; + }else if (IS_ERR (mtk_dp->next_bridge)) {return dev_err_probe (dev,PTR_ERR (mtk_dp->next_bridge),"Failed to get bridge\n" ); + } ret =mtk_dp_dt_parse (mtk_dp, pdev);if (ret)
@@ -2124,7 +2245,10 @@ static int mtk_dp_probe(struct platform_device *pdev) mtk_dp->bridge.ops =DRM_BRIDGE_OP_DETECT |DRM_BRIDGE_OP_EDID |DRM_BRIDGE_OP_HPD ; - mtk_dp->bridge.type = DRM_MODE_CONNECTOR_eDP; +if (mtk_dp_is_edp (mtk_dp)) + mtk_dp->bridge.type = DRM_MODE_CONNECTOR_eDP; +else + mtk_dp->bridge.type = DRM_MODE_CONNECTOR_DisplayPort;drm_bridge_add (&mtk_dp->bridge);
@@ -2151,6 +2275,12 @@ static int mtk_dp_suspend(struct device *dev) {struct mtk_dp *mtk_dp =dev_get_drvdata (dev); +if (mtk_dp_plug_state (mtk_dp)) { +drm_dp_dpcd_writeb (&mtk_dp->aux,DP_SET_POWER ,DP_SET_POWER_D3 ); +/* Ensure the sink is off before shutting down power */ +usleep_range (2000 ,3000 ); + } +mtk_dp_power_disable (mtk_dp);mtk_dp_hwirq_enable (mtk_dp, false);
@@ -2178,6 +2308,7 @@ static SIMPLE_DEV_PM_OPS(mtk_dp_pm_ops, mtk_dp_suspend, mtk_dp_resume);static const struct of_device_id mtk_dp_of_match[] = { { .compatible ="mediatek,mt8195-edp-tx" }, + { .compatible ="mediatek,mt8195-dp-tx" }, {}, };MODULE_DEVICE_TABLE (of, mtk_dp_of_match);
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [PATCH v12 06/10] drm/mediatek: Add MT8195 External DisplayPort support
Il 27/06/22 10:03, Bo-Chen Chen ha scritto:
Quoted 40 lines
From: Guillaume Ranquet <[email protected]>
This patch adds External DisplayPort support to the mt8195 eDP driver.
Signed-off-by Guillaume Ranquet <[email protected]>[Bo-Chen: Move some dp features here and modify for reviewers' comments.]Signed-off-by Bo-Chen Chen <[email protected]>--- drivers/gpu/drm/mediatek/mtk_dp.c | 217 ++++++++++++++++++++++++------ 1 file changed, 174 insertions(+), 43 deletions(-)drivers/gpu/drm/mediatek/mtk_dp.c +7
-0@@ -111,6 +111,7 @@ struct mtk_dp {struct regmap *regs;bool enabled; +bool has_fec;struct drm_connector *conn; };@@ -123,6 +124,11 @@ static struct regmap_config mtk_dp_regmap_config = { .name = "mtk-dp-registers", }; +static bool mtk_dp_is_edp (struct mtk_dp *mtk_dp) +{ +return mtk_dp->next_bridge; +} +static struct mtk_dp *mtk_dp_from_bridge (struct drm_bridge *b) { return container_of(b, struct mtk_dp, bridge);@@ -401,6 +407,20 @@ static bool mtk_dp_plug_state(struct mtk_dp *mtk_dp) HPD_DB_DP_TRANS_P0_MASK); } +static bool mtk_dp_plug_state_avoid_pulse (struct mtk_dp *mtk_dp)
drivers/gpu/drm/mediatek/mtk_dp.c static bool mtk_dp_plug_state(struct mtk_dp *mtk_dp) · line 420
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp.c +10
-0+{ +int wait; + +for (wait =7 ; !mtk_dp_plug_state (mtk_dp) && wait >0 ; --wait) +/* Avoid short pulses on the HPD isr */ +usleep_range (1000 ,5000 ); + +if (wait ==0 ) +return false; +
You can as well use existing APIs for that:
static bool mtk_dp_plug_state_avoid_pulse(struct mtk_dp *mtk_dp)
{
int ret;
return !!(readx_poll_timeout(mtk_dp_plug_state, mtk_dp, ret, ret,
4000, (7 * 4000)));
}P.S.: I've used 4000 instead of 5000 on purpose, check the definition of
readx_poll_timeout for more information.
All the rest of this commit looks good to me.
Cheers,
Angelo
PATCH v12 7/10 drm/mediatek: add hpd debounce
In reply to Bo-Chen ChenFrom: Jitao Shi <[email protected]>
From the DP spec 1.4a chapter 3.3, upstream devices should implement HPD signal de-bouncing on an external connection.
A period of 100ms should be used to detect an HPD connect event. To cover these cases, HPD de-bounce should be implemented only after HPD low has been detected for at least 100ms.
Therefore,
1. If HPD is low (which means plugging out) for longer than 100ms:
we need to do de-bouncing (which means we need to wait for 100ms).
2. If HPD low is for less than 100ms:
we don't need to care about the de-bouncing.
In this patch, we start a 100ms timer and use a need_debounce boolean to implement the feature.
Two cases when HPD is high:
1. If the timer is expired (>100ms):
- need_debounce is true.
- When HPD high (plugging event comes), need_debounce will be true and then we need to do de-bouncing (wait for 100ms).
2. If the timer is not expired (<100ms):
- need_debounce is false.
- When HPD high (plugging event comes), need_debounce will be false and no need to do de-bouncing.
HPD_______ __________________
| |<- 100ms ->
|____________|
<- 100ms ->Without HPD de-bouncing, USB-C to HDMI Adapaters will not be detected.
The change has been successfully tested with the following devices:
- Dell Adapter - USB-C to HDMI
- Acer 1in1 HDMI dongle
- Ugreen 1in1 HDMI dongle
- innowatt HDMI + USB3 hub
- Acer 2in1 HDMI dongle
- Apple 3in1 HDMI dongle (A2119)
- J5Create 3in1 HDMI dongle (JAC379)
--- drivers/gpu/drm/mediatek/mtk_dp.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/gpu/drm/mediatek/mtk_dp.c +22 -0
@@ -114,6 +114,8 @@ struct mtk_dp {bool has_fec;struct drm_connector *conn; +bool need_debounce; +struct timer_list debounce_timer; };static struct regmap_config mtk_dp_regmap_config = {
@@ -1629,6 +1631,9 @@ static irqreturn_t mtk_dp_hpd_event_thread(int hpd, void *dev)if (event <0 )return IRQ_HANDLED ; +if (mtk_dp->need_debounce && mtk_dp->train_info.cable_plugged_in) +msleep (100 ); +dev_info (mtk_dp->dev,"drm_helper_hpd_irq_event\n" );drm_helper_hpd_irq_event (mtk_dp->bridge.dev);
@@ -1714,6 +1719,12 @@ static irqreturn_t mtk_dp_hpd_isr_handler(struct mtk_dp *mtk_dp) } train_info->cable_state_change = true; +if (!train_info->cable_plugged_in) { +mod_timer (&mtk_dp->debounce_timer, + jiffies +msecs_to_jiffies (100 ) -1 ); + mtk_dp->need_debounce = false; + } +return IRQ_WAKE_THREAD ; }
@@ -2175,6 +2186,13 @@ static const struct drm_bridge_funcs mtk_dp_bridge_funcs = { .detect = mtk_dp_bdg_detect, }; +static void mtk_dp_debounce_timer (struct timer_list *t) +{ +struct mtk_dp *mtk_dp =from_timer (mtk_dp, t, debounce_timer); + + mtk_dp->need_debounce = true; +} +static int mtk_dp_probe (struct platform_device *pdev) {struct mtk_dp *mtk_dp;
@@ -2252,6 +2270,9 @@ static int mtk_dp_probe(struct platform_device *pdev)drm_bridge_add (&mtk_dp->bridge); + mtk_dp->need_debounce = true; +timer_setup (&mtk_dp->debounce_timer, mtk_dp_debounce_timer,0 ); +pm_runtime_enable (dev);pm_runtime_get_sync (dev);
@@ -2264,6 +2285,7 @@ static int mtk_dp_remove(struct platform_device *pdev)platform_device_unregister (mtk_dp->phy_dev);mtk_dp_video_mute (mtk_dp, true); +del_timer_sync (&mtk_dp->debounce_timer);pm_runtime_disable (&pdev->dev);
Signature · 1 line
2.18.0
Re: [PATCH v12 07/10] drm/mediatek: add hpd debounce
Il 27/06/22 10:03, Bo-Chen Chen ha scritto:
Quoted 43 lines
From: Jitao Shi <[email protected]>
From the DP spec 1.4a chapter 3.3, upstream devices should implement
HPD signal de-bouncing on an external connection.
A period of 100ms should be used to detect an HPD connect event. To cover these cases, HPD de-bounce should be implemented only after HPD low has been detected for at least 100ms.Therefore,
1. If HPD is low (which means plugging out) for longer than 100ms:
we need to do de-bouncing (which means we need to wait for 100ms).
2. If HPD low is for less than 100ms:
we don't need to care about the de-bouncing.In this patch, we start a 100ms timer and use a
need_debounceboolean to implement the feature.Two cases when HPD is high:
1. If the timer is expired (>100ms):
-need_debounceis true.
- When HPD high (plugging event comes),need_debouncewill be true and then we need to do de-bouncing (wait for 100ms).
2. If the timer is not expired (<100ms):
-need_debounceis false.
- When HPD high (plugging event comes),need_debouncewill be false and no need to do de-bouncing.
HPD_________________________| |<- 100ms -> |____________| <- 100ms ->Without HPD de-bouncing, USB-C to HDMI Adapaters will not be detected.
The change has been successfully tested with the following devices:
- Dell Adapter - USB-C to HDMI
- Acer 1in1 HDMI dongle
- Ugreen 1in1 HDMI dongle
- innowatt HDMI + USB3 hub
- Acer 2in1 HDMI dongle
- Apple 3in1 HDMI dongle (A2119)
- J5Create 3in1 HDMI dongle (JAC379)
Quoted 5 lines
Tested-by Rex-BC Chen <[email protected]>Reviewed-by Rex-BC Chen <[email protected]>Signed-off-by Jitao Shi <[email protected]>Signed-off-by Guillaume Ranquet <[email protected]>Signed-off-by Bo-Chen Chen <[email protected]>
PATCH v12 8/10 drm/mediatek: set monitor to DP_SET_POWER_D3 to avoid garbage
In reply to Bo-Chen ChenSet the monitor power state to DP_SET_POWER_D3 to avoid garbage.
--- drivers/gpu/drm/mediatek/mtk_dp.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/mediatek/mtk_dp.c +5 -0
@@ -2003,6 +2003,11 @@ static void mtk_dp_bridge_atomic_disable(struct drm_bridge *bridge, {struct mtk_dp *mtk_dp =mtk_dp_from_bridge (bridge); +if (mtk_dp_plug_state (mtk_dp)) { +drm_dp_dpcd_writeb (&mtk_dp->aux,DP_SET_POWER ,DP_SET_POWER_D3 ); +usleep_range (2000 ,3000 ); + } +mtk_dp_video_mute (mtk_dp, true); mtk_dp->train_state =MTK_DP_TRAIN_STATE_TRAINING ;
Signature · 1 line
2.18.0
Re: [PATCH v12 08/10] drm/mediatek: set monitor to DP_SET_POWER_D3 to avoid garbage
Il 27/06/22 10:03, Bo-Chen Chen ha scritto:
Quoted 4 lines
Set the monitor power state to
DP_SET_POWER_D3to avoid garbage.Signed-off-by Jitao Shi <[email protected]>Signed-off-by Bo-Chen Chen <[email protected]>
PATCH v12 9/10 drm/mediatek: DP audio support for MT8195
In reply to Bo-Chen ChenFrom: Guillaume Ranquet <[email protected]>
This patch adds audio support to the DP driver for MT8195 with up to 8 channels.
--- drivers/gpu/drm/mediatek/mtk_dp.c | 705 ++++++++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_dp_reg.h | 2 + 2 files changed, 707 insertions(+)
drivers/gpu/drm/mediatek/mtk_dp.c +705 -0
@@ -53,6 +53,7 @@ enum mtk_dp_train_state {struct mtk_dp_timings {struct videomode vm;u8 frame_rate; +u32 pix_rate_khz; };struct mtk_dp_irq_sta {
@@ -74,9 +75,41 @@ struct mtk_dp_train_info {struct mtk_dp_irq_sta irq_sta; }; +enum mtk_dp_sdp_type { +MTK_DP_SDP_NONE =0x00 , +MTK_DP_SDP_ACM =0x01 , +MTK_DP_SDP_ISRC =0x02 , +MTK_DP_SDP_AVI =0x03 , +MTK_DP_SDP_AUI =0x04 , +MTK_DP_SDP_SPD =0x05 , +MTK_DP_SDP_MPEG =0x06 , +MTK_DP_SDP_NTSC =0x07 , +MTK_DP_SDP_VSP =0x08 , +MTK_DP_SDP_VSC =0x09 , +MTK_DP_SDP_EXT =0x0A , +MTK_DP_SDP_PPS0 =0x0B , +MTK_DP_SDP_PPS1 =0x0C , +MTK_DP_SDP_PPS2 =0x0D , +MTK_DP_SDP_PPS3 =0x0E , +MTK_DP_SDP_DRM =0x10 , +MTK_DP_SDP_MAX_NUM +}; + +struct mtk_dp_sdp_packet { +enum mtk_dp_sdp_type type; +struct dp_sdp sdp; +}; + +struct mtk_dp_audio_cfg { +int sample_rate; +int word_length_bits; +int channels; +}; +struct mtk_dp_info {u32 depth;enum dp_pixelformat format; +struct mtk_dp_audio_cfg audio_caps;struct mtk_dp_timings timings; };
@@ -111,7 +144,20 @@ struct mtk_dp {struct regmap *regs;bool enabled; +bool audio_enable; +bool has_fec; +/* protect the plugged_cb as it's used in both bridge ops and audio */ +struct mutex update_plugged_status_lock; +/* protect the eld data as it's used in both bridge ops and audio */ +struct mutex eld_lock; +/* protect edid as it is used in both bridge ops and IRQ handler */ +struct mutex edid_lock; +struct edid *edid; + +hdmi_codec_plugged_cb plugged_cb; +struct device *codec_dev; +u8 connector_eld[MAX_ELD_BYTES ];struct drm_connector *conn;bool need_debounce;
@@ -403,6 +449,125 @@ static void mtk_dp_pg_disable(struct mtk_dp *mtk_dp) 4 << PGEN_PATTERN_SEL_SHIFT, PGEN_PATTERN_SEL_MASK); } +static void mtk_dp_audio_setup_channels (struct mtk_dp *mtk_dp, +struct mtk_dp_audio_cfg *cfg) +{ +u32 channel_enable_bits; + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_3324 , +AUDIO_SOURCE_MUX_DP_ENC1_P0_DPRX , +AUDIO_SOURCE_MUX_DP_ENC1_P0_MASK ); + +/* audio channel count change reset */ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_33F4 ,BIT (9 ),BIT (9 )); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_3304 , +AU_PRTY_REGEN_DP_ENC1_P0_MASK , +AU_PRTY_REGEN_DP_ENC1_P0_MASK ); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_3304 , +AU_CH_STS_REGEN_DP_ENC1_P0_MASK , +AU_CH_STS_REGEN_DP_ENC1_P0_MASK ); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_3304 , +AUDIO_SAMPLE_PRSENT_REGEN_DP_ENC1_P0_MASK , +AUDIO_SAMPLE_PRSENT_REGEN_DP_ENC1_P0_MASK ); + +switch (cfg->channels) { +case 2 : + channel_enable_bits =AUDIO_2CH_SEL_DP_ENC0_P0_MASK | +AUDIO_2CH_EN_DP_ENC0_P0_MASK ; +break ; +case 8 : +default : + channel_enable_bits =AUDIO_8CH_SEL_DP_ENC0_P0_MASK | +AUDIO_8CH_EN_DP_ENC0_P0_MASK ; +break ; + } +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3088 , + channel_enable_bits |AU_EN_DP_ENC0_P0_MASK , +AUDIO_2CH_SEL_DP_ENC0_P0_MASK | +AUDIO_2CH_EN_DP_ENC0_P0_MASK | +AUDIO_8CH_SEL_DP_ENC0_P0_MASK | +AUDIO_8CH_EN_DP_ENC0_P0_MASK | +AU_EN_DP_ENC0_P0_MASK ); + +/* audio channel count change reset */ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_33F4 ,0 ,BIT (9 )); + +/* enable audio reset */ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_33F4 ,BIT (0 ),BIT (0 )); +} + +static void mtk_dp_audio_channel_status_set (struct mtk_dp *mtk_dp, +struct mtk_dp_audio_cfg *cfg) +{ +struct snd_aes_iec958 iec = {0 }; + +switch (cfg->sample_rate) { +case 32000 : + iec.status[3 ] =IEC958_AES3_CON_FS_32000 ; +break ; +case 44100 : + iec.status[3 ] =IEC958_AES3_CON_FS_44100 ; +break ; +case 48000 : + iec.status[3 ] =IEC958_AES3_CON_FS_48000 ; +break ; +case 88200 : + iec.status[3 ] =IEC958_AES3_CON_FS_88200 ; +break ; +case 96000 : + iec.status[3 ] =IEC958_AES3_CON_FS_96000 ; +break ; +case 192000 : + iec.status[3 ] =IEC958_AES3_CON_FS_192000 ; +break ; +default : + iec.status[3 ] =IEC958_AES3_CON_FS_NOTID ; +break ; + } + +switch (cfg->word_length_bits) { +case 16 : + iec.status[4 ] =IEC958_AES4_CON_WORDLEN_20_16 ; +break ; +case 20 : + iec.status[4 ] =IEC958_AES4_CON_WORDLEN_20_16 | +IEC958_AES4_CON_MAX_WORDLEN_24 ; +break ; +case 24 : + iec.status[4 ] =IEC958_AES4_CON_WORDLEN_24_20 | +IEC958_AES4_CON_MAX_WORDLEN_24 ; +break ; +default : + iec.status[4 ] =IEC958_AES4_CON_WORDLEN_NOTID ; + } + +/* IEC 60958 consumer channel status bits */ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_308C , +0 ,CH_STATUS_0_DP_ENC0_P0_MASK ); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3090 , + iec.status[3 ] <<8 ,CH_STATUS_1_DP_ENC0_P0_MASK ); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3094 , + iec.status[4 ],CH_STATUS_2_DP_ENC0_P0_MASK ); +} + +static void mtk_dp_audio_sdp_asp_set_channels (struct mtk_dp *mtk_dp, +int channels) +{ +if (channels !=2 && channels !=8 ) + channels =8 ; + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_312C , + (channels -1 ) <<ASP_HB3_DP_ENC0_P0_SHIFT , +ASP_HB2_DP_ENC0_P0_MASK |ASP_HB3_DP_ENC0_P0_MASK ); +} + +static void mtk_dp_audio_set_divider (struct mtk_dp *mtk_dp) +{ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_30BC , +AUDIO_M_CODE_MULT_DIV_SEL_DP_ENC0_P0_DIV_2 , +AUDIO_M_CODE_MULT_DIV_SEL_DP_ENC0_P0_MASK ); +} +static bool mtk_dp_plug_state (struct mtk_dp *mtk_dp) { return !!(mtk_dp_read(mtk_dp, MTK_DP_TRANS_P0_3414) &
@@ -423,6 +588,169 @@ static bool mtk_dp_plug_state_avoid_pulse(struct mtk_dp *mtk_dp)return true; } +static void mtk_dp_sdp_trigger_packet (struct mtk_dp *mtk_dp, +enum mtk_dp_sdp_type type) +{ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_3280 , + type,SDP_PACKET_TYPE_DP_ENC1_P0_MASK ); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_3280 , +SDP_PACKET_W_DP_ENC1_P0 ,SDP_PACKET_W_DP_ENC1_P0 ); +} + +static void mtk_dp_sdp_set_data (struct mtk_dp *mtk_dp,u8 *data_bytes) +{ +mtk_dp_bulk_16bit_write (mtk_dp,MTK_DP_ENC1_P0_3200 , + data_bytes,0x10 ); +} + +static void mtk_dp_sdp_set_header (struct mtk_dp *mtk_dp, +enum mtk_dp_sdp_type type, +struct dp_sdp_header *header) +{ +u32 db_addr; + +switch (type) { +case MTK_DP_SDP_DRM : + db_addr =MTK_DP_ENC0_P0_3138 ; +break ; +case MTK_DP_SDP_PPS0 : +case MTK_DP_SDP_PPS1 : +case MTK_DP_SDP_PPS2 : +case MTK_DP_SDP_PPS3 : + db_addr =MTK_DP_ENC0_P0_3130 ; +break ; +default : + db_addr =MTK_DP_ENC0_P0_30D8 + (type -MTK_DP_SDP_ACM ) *8 ; +break ; + } + +mtk_dp_bulk_16bit_write (mtk_dp, db_addr, (u8 *)header,4 ); +} + +static const u32 sdp_type_to_reg[MTK_DP_SDP_MAX_NUM ] = { + [MTK_DP_SDP_NONE ] =0x0 , + [MTK_DP_SDP_ACM ] =MTK_DP_ENC0_P0_30B4 , + [MTK_DP_SDP_ISRC ] =MTK_DP_ENC0_P0_30B4 +1 , + [MTK_DP_SDP_AVI ] =MTK_DP_ENC0_P0_30A4 +1 , + [MTK_DP_SDP_AUI ] =MTK_DP_ENC0_P0_30A8 , + [MTK_DP_SDP_SPD ] =MTK_DP_ENC0_P0_30A8 +1 , + [MTK_DP_SDP_MPEG ] =MTK_DP_ENC0_P0_30AC , + [MTK_DP_SDP_NTSC ] =MTK_DP_ENC0_P0_30AC +1 , + [MTK_DP_SDP_VSP ] =MTK_DP_ENC0_P0_30B0 , + [MTK_DP_SDP_VSC ] =MTK_DP_ENC0_P0_30B8 , + [MTK_DP_SDP_EXT ] =MTK_DP_ENC0_P0_30B0 +1 , + [MTK_DP_SDP_PPS0 ] =MTK_DP_ENC0_P0_31E8 , + [MTK_DP_SDP_PPS1 ] =MTK_DP_ENC0_P0_31E8 , + [MTK_DP_SDP_PPS2 ] =MTK_DP_ENC0_P0_31E8 , + [MTK_DP_SDP_PPS3 ] =MTK_DP_ENC0_P0_31E8 , + [MTK_DP_SDP_DRM ] =MTK_DP_ENC0_P0_31DC , +}; + +static void mtk_dp_disable_sdp (struct mtk_dp *mtk_dp,enum mtk_dp_sdp_type type) +{ +if (type ==MTK_DP_SDP_NONE ) +return ; + +/* Disable periodic send */ +mtk_dp_update_bits (mtk_dp, sdp_type_to_reg[type] &0xfffc ,0 , +0xFF << ((sdp_type_to_reg[type] &3 ) *8 )); +} + +static void mtk_dp_setup_sdp (struct mtk_dp *mtk_dp, +struct mtk_dp_sdp_packet *packet) +{ +u32 reg, shift; + +mtk_dp_sdp_set_data (mtk_dp, packet->sdp.db); +mtk_dp_sdp_set_header (mtk_dp, packet->type, &packet->sdp.sdp_header); + +mtk_dp_disable_sdp (mtk_dp, packet->type); + +switch (packet->type) { +case MTK_DP_SDP_ISRC : +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_31EC , +0x1C <<ISRC1_HB3_DP_ENC0_P0_SHIFT , +ISRC1_HB3_DP_ENC0_P0_MASK ); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_3280 , +MTK_DP_SDP_ISRC , +SDP_PACKET_TYPE_DP_ENC1_P0_MASK ); + +if (packet->sdp.sdp_header.HB3 &BIT (2 )) +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_30BC , +BIT (ISRC_CONT_DP_ENC0_P0_SHIFT ), +ISRC_CONT_DP_ENC0_P0_MASK ); +else +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_30BC , +0 ,ISRC_CONT_DP_ENC0_P0_MASK ); + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_3280 , +SDP_PACKET_W_DP_ENC1_P0 , +SDP_PACKET_W_DP_ENC1_P0 ); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_30B4 , +5 <<ISRC_CFG_DP_ENC0_P0_SHIFT , +ISRC_CFG_DP_ENC0_P0_MASK ); +break ; +case MTK_DP_SDP_DRM : +mtk_dp_sdp_trigger_packet (mtk_dp, packet->type); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_31DC , +5 <<HDR0_CFG_DP_ENC0_P0_SHIFT , +HDR0_CFG_DP_ENC0_P0_MASK ); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_31EC , +0x1C <<ISRC1_HB3_DP_ENC0_P0_SHIFT , +ISRC1_HB3_DP_ENC0_P0_MASK ); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_3280 , +MTK_DP_SDP_ISRC , +SDP_PACKET_TYPE_DP_ENC1_P0_MASK ); + +if (packet->sdp.sdp_header.HB3 &BIT (2 )) +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_30BC , +BIT (ISRC_CONT_DP_ENC0_P0_SHIFT ), +ISRC_CONT_DP_ENC0_P0_MASK ); +else +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_30BC , +0 ,ISRC_CONT_DP_ENC0_P0_MASK ); + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_3280 , +SDP_PACKET_W_DP_ENC1_P0 , +SDP_PACKET_W_DP_ENC1_P0 ); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_30B4 , +5 <<ISRC_CFG_DP_ENC0_P0_SHIFT , +ISRC_CFG_DP_ENC0_P0_MASK ); +break ; +case MTK_DP_SDP_ACM : +case MTK_DP_SDP_AVI : +case MTK_DP_SDP_AUI : +case MTK_DP_SDP_SPD : +case MTK_DP_SDP_MPEG : +case MTK_DP_SDP_NTSC : +case MTK_DP_SDP_VSP : +case MTK_DP_SDP_VSC : +case MTK_DP_SDP_EXT : +case MTK_DP_SDP_PPS0 : +case MTK_DP_SDP_PPS1 : +case MTK_DP_SDP_PPS2 : +case MTK_DP_SDP_PPS3 : + reg = sdp_type_to_reg[packet->type]; + shift = (reg &3 ) *8 ; + +mtk_dp_sdp_trigger_packet (mtk_dp, packet->type); +/* Enable periodic sending */ +mtk_dp_update_bits (mtk_dp, reg &0xfffc , +0x05 << shift,0xff << shift); +break ; +case MTK_DP_SDP_NONE : +default : +break ; + } +} + +static void mtk_dp_sdp_vsc_ext_disable (struct mtk_dp *mtk_dp) +{ +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_30A0 , +0 ,BIT (7 ) |BIT (8 ) |BIT (12 )); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_328C ,0 ,BIT (7 )); +} +static void mtk_dp_aux_irq_clear (struct mtk_dp *mtk_dp) { mtk_dp_write(mtk_dp, MTK_DP_AUX_P0_3640,
@@ -1067,6 +1395,32 @@ static void mtk_dp_video_mute(struct mtk_dp *mtk_dp, bool enable) MTK_DP_SIP_ATF_VIDEO_UNMUTE, enable); } +static void mtk_dp_audio_mute (struct mtk_dp *mtk_dp,bool mute) +{ +u32 val[3 ]; + +if (mute) { + val[0 ] =BIT (VBID_AUDIO_MUTE_SW_DP_ENC0_P0_SHIFT ) | +BIT (VBID_AUDIO_MUTE_SEL_DP_ENC0_P0_SHIFT ); + val[1 ] =0 ; + val[2 ] =0 ; + }else { + val[0 ] =0 ; + val[1 ] =BIT (AU_EN_DP_ENC0_P0_SHIFT ); +/* Send one every two frames */ + val[2 ] =0x0F ; + } + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3030 , + val[0 ], +VBID_AUDIO_MUTE_FLAG_SW_DP_ENC0_P0_MASK | +VBID_AUDIO_MUTE_FLAG_SEL_DP_ENC0_P0_MASK ); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3088 , + val[1 ],AU_EN_DP_ENC0_P0_MASK ); +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_30A4 , + val[2 ],AU_TS_CFG_DP_ENC0_P0_MASK ); +} +static void mtk_dp_power_enable (struct mtk_dp *mtk_dp) { mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_RESET_AND_PROBE,
@@ -1114,6 +1468,78 @@ static void mtk_dp_initialize_priv_data(struct mtk_dp *mtk_dp) mtk_dp->info.timings.frame_rate =60 ; mtk_dp->has_fec = false; + mtk_dp->audio_enable = false; +} + +static void mtk_dp_sdp_set_down_cnt_init (struct mtk_dp *mtk_dp, +u32 sram_read_start) +{ +u32 sdp_down_cnt_init =0 ; +struct drm_display_mode mode; +struct mtk_dp_timings *timings = &mtk_dp->info.timings; + +drm_display_mode_from_videomode (&timings->vm, &mode); + +if (mtk_dp->info.timings.pix_rate_khz >0 ) + sdp_down_cnt_init = sram_read_start * + mtk_dp->train_info.link_rate *2700 *8 / + (timings->pix_rate_khz *4 ); + +switch (mtk_dp->train_info.lane_count) { +case 1 : + sdp_down_cnt_init =max_t (u32, sdp_down_cnt_init,0x1A ); +break ; +case 2 : +/* case for LowResolution && High Audio Sample Rate */ + sdp_down_cnt_init =max_t (u32, sdp_down_cnt_init,0x10 ); + sdp_down_cnt_init += mode.vtotal <=525 ?4 :0 ; +break ; +case 4 : +default : + sdp_down_cnt_init =max_t (u32, sdp_down_cnt_init,6 ); +break ; + } + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC0_P0_3040 , + sdp_down_cnt_init + <<SDP_DOWN_CNT_INIT_DP_ENC0_P0_SHIFT , +SDP_DOWN_CNT_INIT_DP_ENC0_P0_MASK ); +} + +static void mtk_dp_sdp_set_down_cnt_init_in_hblank (struct mtk_dp *mtk_dp) +{ +int pix_clk_mhz; +u32 dc_offset; +u32 spd_down_cnt_init =0 ; +struct drm_display_mode mode; +struct mtk_dp_timings *timings = &mtk_dp->info.timings; + +drm_display_mode_from_videomode (&timings->vm, &mode); + + pix_clk_mhz = mtk_dp->info.format ==DP_PIXELFORMAT_YUV420 ? + mtk_dp->info.timings.pix_rate_khz /2000 : + mtk_dp->info.timings.pix_rate_khz /1000 ; + +switch (mtk_dp->train_info.lane_count) { +case 1 : + spd_down_cnt_init =0x20 ; +break ; +case 2 : + dc_offset = (mode.vtotal <=525 ) ?0x14 :0x00 ; + spd_down_cnt_init =0x18 + dc_offset; +break ; +case 4 : +default : + dc_offset = (mode.vtotal <=525 ) ?0x08 :0x00 ; +if (pix_clk_mhz > mtk_dp->train_info.link_rate *27 ) + spd_down_cnt_init =0x8 ; +else + spd_down_cnt_init =0x10 + dc_offset; +break ; + } + +mtk_dp_update_bits (mtk_dp,MTK_DP_ENC1_P0_3364 , spd_down_cnt_init, +SDP_DOWN_CNT_INIT_IN_HBLANK_DP_ENC1_P0_MASK ); }static void mtk_dp_setup_tu (struct mtk_dp *mtk_dp)
@@ -1130,6 +1556,8 @@ static void mtk_dp_setup_tu(struct mtk_dp *mtk_dp) }mtk_dp_setup_encoder (mtk_dp); +mtk_dp_sdp_set_down_cnt_init_in_hblank (mtk_dp); +mtk_dp_sdp_set_down_cnt_init (mtk_dp, sram_read_start); }static void mtk_dp_calculate_pixrate (struct mtk_dp *mtk_dp)
@@ -1145,10 +1573,14 @@ static void mtk_dp_calculate_pixrate(struct mtk_dp *mtk_dp) target_frame_rate = mtk_dp->info.timings.frame_rate; target_pixel_clk = mode.htotal * mode.vtotal * target_frame_rate; + }else if (mtk_dp->info.timings.pix_rate_khz >0 ) { + target_pixel_clk = mtk_dp->info.timings.pix_rate_khz *1000 ; }else { target_pixel_clk = mode.htotal * mode.vtotal * target_frame_rate; } + + mtk_dp->info.timings.pix_rate_khz = target_pixel_clk /1000 ; }static void mtk_dp_set_tx_out (struct mtk_dp *mtk_dp)
@@ -1159,6 +1591,14 @@ static void mtk_dp_set_tx_out(struct mtk_dp *mtk_dp)mtk_dp_setup_tu (mtk_dp); } +static void mtk_dp_edid_free (struct mtk_dp *mtk_dp) +{ +mutex_lock (&mtk_dp->edid_lock); +kfree (mtk_dp->edid); + mtk_dp->edid =NULL ; +mutex_unlock (&mtk_dp->edid_lock); +} +static ssize_t mtk_dp_hpd_sink_event (struct mtk_dp *mtk_dp) {ssize_t ret;
@@ -1192,6 +1632,7 @@ static ssize_t mtk_dp_hpd_sink_event(struct mtk_dp *mtk_dp)if (DP_GET_SINK_COUNT (sink_count) && (link_status[2 ] &DP_DOWNSTREAM_PORT_STATUS_CHANGED )) { +mtk_dp_edid_free (mtk_dp); mtk_dp->train_state =MTK_DP_TRAIN_STATE_TRAINING ;msleep (20 ); }
@@ -1199,6 +1640,17 @@ static ssize_t mtk_dp_hpd_sink_event(struct mtk_dp *mtk_dp)return 0 ; } +static void mtk_dp_sdp_stop_sending (struct mtk_dp *mtk_dp) +{ +u8 packet_type; + +for (packet_type =MTK_DP_SDP_ACM ; packet_type <MTK_DP_SDP_MAX_NUM ; + packet_type++) +mtk_dp_disable_sdp (mtk_dp, packet_type); + +mtk_dp_sdp_vsc_ext_disable (mtk_dp); +} +static void mtk_dp_train_update_swing_pre (struct mtk_dp *mtk_dp,int lanes,u8 dpcd_adjust_req[2 ]) {
@@ -1465,6 +1917,55 @@ static int mtk_dp_parse_capabilities(struct mtk_dp *mtk_dp)return 0 ; } +static bool mtk_dp_edid_parse_audio_capabilities (struct mtk_dp *mtk_dp, +struct mtk_dp_audio_cfg *cfg) +{ +struct cea_sad *sads; +int sad_count; +int i; +bool ret = false; + +if (mtk_dp_is_edp (mtk_dp)) +return false; + +mutex_lock (&mtk_dp->edid_lock); +if (!mtk_dp->edid) { +mutex_unlock (&mtk_dp->edid_lock); +dev_err (mtk_dp->dev,"EDID not found!\n" ); +return false; + } + sad_count =drm_edid_to_sad (mtk_dp->edid, &sads); +mutex_unlock (&mtk_dp->edid_lock); + +if (sad_count <=0 ) { +drm_info (mtk_dp->drm_dev,"The SADs is NULL\n" ); +return false; + } + +for (i =0 ; i < sad_count; i++) { +int sample_rate, word_length; + +/* Only PCM supported at the moment */ +if (sads[i].format !=HDMI_AUDIO_CODING_TYPE_PCM ) +continue ; + + sample_rate =drm_cea_sad_get_sample_rate (&sads[i]); + word_length = +drm_cea_sad_get_uncompressed_word_length (&sads[i]); +if (sample_rate <=0 || word_length <=0 ) +continue ; + + cfg->channels = sads[i].channels; + cfg->word_length_bits = word_length; + cfg->sample_rate = sample_rate; + ret = true; +break ; + } +kfree (sads); + +return ret; +} +static void mtk_dp_train_change_mode (struct mtk_dp *mtk_dp) {phy_reset (mtk_dp->phy);
@@ -1557,6 +2058,48 @@ static void mtk_dp_video_enable(struct mtk_dp *mtk_dp, bool enable) } } +static void mtk_dp_audio_sdp_setup (struct mtk_dp *mtk_dp, +struct mtk_dp_audio_cfg *cfg) +{ +struct mtk_dp_sdp_packet packet; +struct hdmi_audio_infoframe frame; + +hdmi_audio_infoframe_init (&frame); + frame.coding_type =HDMI_AUDIO_CODING_TYPE_PCM ; + frame.channels = cfg->channels; + frame.sample_frequency = cfg->sample_rate; + +switch (cfg->word_length_bits) { +case 16 : + frame.sample_size =HDMI_AUDIO_SAMPLE_SIZE_16 ; +break ; +case 20 : + frame.sample_size =HDMI_AUDIO_SAMPLE_SIZE_20 ; +break ; +case 24 : +default : + frame.sample_size =HDMI_AUDIO_SAMPLE_SIZE_24 ; +break ; + } + + packet.type =MTK_DP_SDP_AUI ; +hdmi_audio_infoframe_pack_for_dp (&frame, &packet.sdp, +MTK_DP_DP_VERSION_11 ); + +mtk_dp_audio_sdp_asp_set_channels (mtk_dp, cfg->channels); +mtk_dp_setup_sdp (mtk_dp, &packet); +} + +static void mtk_dp_audio_setup (struct mtk_dp *mtk_dp, +struct mtk_dp_audio_cfg *cfg) +{ +mtk_dp_audio_sdp_setup (mtk_dp, cfg); +mtk_dp_audio_channel_status_set (mtk_dp, cfg); + +mtk_dp_audio_setup_channels (mtk_dp, cfg); +mtk_dp_audio_set_divider (mtk_dp); +} +static void mtk_dp_video_config (struct mtk_dp *mtk_dp) {mtk_dp_mn_overwrite_disable (mtk_dp);
@@ -1583,6 +2126,19 @@ static int mtk_dp_training(struct mtk_dp *mtk_dp)case MTK_DP_TRAIN_STATE_NORMAL :mtk_dp_video_config (mtk_dp);mtk_dp_video_enable (mtk_dp, true); + + mtk_dp->audio_enable = +mtk_dp_edid_parse_audio_capabilities (mtk_dp, + &mtk_dp->info.audio_caps); + +if (mtk_dp->audio_enable) { +mtk_dp_audio_setup (mtk_dp, &mtk_dp->info.audio_caps); +mtk_dp_audio_mute (mtk_dp, false); + }else { +memset (&mtk_dp->info.audio_caps,0 , +sizeof (mtk_dp->info.audio_caps)); + } + training_done = true;break ;default :
@@ -1644,12 +2200,15 @@ static irqreturn_t mtk_dp_hpd_event_thread(int hpd, void *dev)if (!mtk_dp->train_info.cable_plugged_in) {mtk_dp_video_mute (mtk_dp, true); +mtk_dp_audio_mute (mtk_dp, true);mtk_dp_initialize_priv_data (mtk_dp);mtk_dp_set_idle_pattern (mtk_dp, true);if (mtk_dp->has_fec)mtk_dp_fec_enable (mtk_dp, false); +mtk_dp_sdp_stop_sending (mtk_dp); +mtk_dp_edid_free (mtk_dp);mtk_dp_update_bits (mtk_dp,MTK_DP_TOP_PWR_STATE ,DP_PWR_STATE_BANDGAP_TPLL ,DP_PWR_STATE_MASK );
@@ -1798,6 +2357,18 @@ static int mtk_dp_dt_parse(struct mtk_dp *mtk_dp,return 0 ; } +static void mtk_dp_update_plugged_status (struct mtk_dp *mtk_dp) +{ +bool connected, has_audio; + +mutex_lock (&mtk_dp->update_plugged_status_lock); + connected =mtk_dp_plug_state_avoid_pulse (mtk_dp); + has_audio =drm_detect_monitor_audio (mtk_dp->edid); +if (mtk_dp->plugged_cb && mtk_dp->codec_dev) + mtk_dp->plugged_cb (mtk_dp->codec_dev, connected & has_audio); +mutex_unlock (&mtk_dp->update_plugged_status_lock); +} +static enum drm_connector_status mtk_dp_bdg_detect (struct drm_bridge *bridge) {struct mtk_dp *mtk_dp =mtk_dp_from_bridge (bridge);
@@ -1813,6 +2384,7 @@ static enum drm_connector_status mtk_dp_bdg_detect(struct drm_bridge *bridge) ret = connector_status_connected; } +mtk_dp_update_plugged_status (mtk_dp);return ret; }
@@ -1835,6 +2407,18 @@ static struct edid *mtk_dp_get_edid(struct drm_bridge *bridge,if (!enabled)drm_bridge_chain_post_disable (bridge); +mutex_lock (&mtk_dp->edid_lock); +kfree (mtk_dp->edid); + mtk_dp->edid =NULL ; + +if (!new_edid) { +mutex_unlock (&mtk_dp->edid_lock); +return NULL ; + } + + mtk_dp->edid =drm_edid_duplicate (new_edid); +mutex_unlock (&mtk_dp->edid_lock); +return new_edid; }
@@ -2009,6 +2593,7 @@ static void mtk_dp_bridge_atomic_disable(struct drm_bridge *bridge, }mtk_dp_video_mute (mtk_dp, true); +mtk_dp_audio_mute (mtk_dp, true); mtk_dp->train_state =MTK_DP_TRAIN_STATE_TRAINING ; mtk_dp->enabled = false;
@@ -2039,6 +2624,8 @@ static void mtk_dp_bridge_atomic_enable(struct drm_bridge *bridge, }mtk_dp_video_mute (mtk_dp, true); +mtk_dp_audio_mute (mtk_dp, true); +mtk_dp_sdp_stop_sending (mtk_dp);if (mtk_dp_parse_capabilities (mtk_dp)) {drm_err (mtk_dp->drm_dev,"Can't parse capabilities\n" );
@@ -2051,7 +2638,13 @@ static void mtk_dp_bridge_atomic_enable(struct drm_bridge *bridge,return ; } +mutex_lock (&mtk_dp->eld_lock); +memcpy (mtk_dp->connector_eld, mtk_dp->conn->eld,MAX_ELD_BYTES ); +mutex_unlock (&mtk_dp->eld_lock); + mtk_dp->enabled = true; + +mtk_dp_update_plugged_status (mtk_dp); } static enum drm_mode_status
@@ -2198,6 +2791,104 @@ static void mtk_dp_debounce_timer(struct timer_list *t) mtk_dp->need_debounce = true; } +/* +* HDMI audio codec callbacks +*/ +static int mtk_dp_audio_hw_params (struct device *dev,void *data, +struct hdmi_codec_daifmt *daifmt, +struct hdmi_codec_params *params) +{ +struct mtk_dp *mtk_dp =dev_get_drvdata (dev); +struct mtk_dp_audio_cfg cfg; + +if (!mtk_dp->enabled) { +pr_err ("%s, DP is not ready!\n" , __func__); +return -ENODEV ; + } + + cfg.channels = params->cea.channels; + cfg.sample_rate = params->sample_rate; + cfg.word_length_bits =24 ; + +mtk_dp_audio_setup (mtk_dp, &cfg); + +return 0 ; +} + +static int mtk_dp_audio_startup (struct device *dev,void *data) +{ +struct mtk_dp *mtk_dp =dev_get_drvdata (dev); + +mtk_dp_audio_mute (mtk_dp, false); + +return 0 ; +} + +static void mtk_dp_audio_shutdown (struct device *dev,void *data) +{ +struct mtk_dp *mtk_dp =dev_get_drvdata (dev); + +mtk_dp_audio_mute (mtk_dp, true); +} + +static int mtk_dp_audio_get_eld (struct device *dev,void *data,uint8_t *buf, +size_t len) +{ +struct mtk_dp *mtk_dp =dev_get_drvdata (dev); + +if (mtk_dp->enabled) +memcpy (buf, mtk_dp->connector_eld, len); +else +memset (buf,0 , len); + +return 0 ; +} + +static int mtk_dp_audio_hook_plugged_cb (struct device *dev,void *data, +hdmi_codec_plugged_cb fn, +struct device *codec_dev) +{ +struct mtk_dp *mtk_dp = data; + +mutex_lock (&mtk_dp->update_plugged_status_lock); + mtk_dp->plugged_cb = fn; + mtk_dp->codec_dev = codec_dev; +mutex_unlock (&mtk_dp->update_plugged_status_lock); + +mtk_dp_update_plugged_status (mtk_dp); + +return 0 ; +} + +static const struct hdmi_codec_ops mtk_dp_audio_codec_ops = { + .hw_params = mtk_dp_audio_hw_params, + .audio_startup = mtk_dp_audio_startup, + .audio_shutdown = mtk_dp_audio_shutdown, + .get_eld = mtk_dp_audio_get_eld, + .hook_plugged_cb = mtk_dp_audio_hook_plugged_cb, + .no_capture_mute =1 , +}; + +static int mtk_dp_register_audio_driver (struct device *dev) +{ +struct mtk_dp *mtk_dp =dev_get_drvdata (dev); +struct hdmi_codec_pdata codec_data = { + .ops = &mtk_dp_audio_codec_ops, + .max_i2s_channels =8 , + .i2s =1 , + .data = mtk_dp, + }; +struct platform_device *pdev; + + pdev =platform_device_register_data (dev,HDMI_CODEC_DRV_NAME , +PLATFORM_DEVID_AUTO , &codec_data, +sizeof (codec_data)); +if (IS_ERR (pdev)) +return PTR_ERR (pdev); + +return 0 ; +} +static int mtk_dp_probe (struct platform_device *pdev) {struct mtk_dp *mtk_dp;
@@ -2243,8 +2934,21 @@ static int mtk_dp_probe(struct platform_device *pdev)return dev_err_probe (dev, -EPROBE_DEFER ,"failed to request mediatek dptx irq\n" ); +mutex_init (&mtk_dp->edid_lock); +mutex_init (&mtk_dp->eld_lock); +mutex_init (&mtk_dp->update_plugged_status_lock); +platform_set_drvdata (pdev, mtk_dp); +if (!mtk_dp_is_edp (mtk_dp)) { + ret =mtk_dp_register_audio_driver (dev); +if (ret) { +dev_err (dev,"Failed to register audio driver: %d\n" , + ret); +return ret; + } + } + mtk_dp->phy_dev = platform_device_register_data(dev, "mediatek-dp-phy", PLATFORM_DEVID_AUTO, &mtk_dp->regs,
@@ -2290,6 +2994,7 @@ static int mtk_dp_remove(struct platform_device *pdev)platform_device_unregister (mtk_dp->phy_dev);mtk_dp_video_mute (mtk_dp, true); +mtk_dp_audio_mute (mtk_dp, true);del_timer_sync (&mtk_dp->debounce_timer);pm_runtime_disable (&pdev->dev);
drivers/gpu/drm/mediatek/mtk_dp_reg.h +2 -0
@@ -240,6 +240,8 @@#define ASP_HB3_DP_ENC0_P0_MASK GENMASK(15, 8)#define ASP_HB3_DP_ENC0_P0_SHIFT BIT(3) +#define MTK_DP_ENC0_P0_3130 (ENC0_OFFSET + 0x130) +#define MTK_DP_ENC0_P0_3138 (ENC0_OFFSET + 0x138)#define MTK_DP_ENC0_P0_3154 (ENC0_OFFSET + 0x154)#define PGEN_HTOTAL_DP_ENC0_P0_MASK GENMASK(13, 0)#define MTK_DP_ENC0_P0_3158 (ENC0_OFFSET + 0x158)
Signature · 1 line
2.18.0
PATCH v12 10/10 drm/mediatek: fix no audio when resolution change
In reply to Bo-Chen ChenWhen switching resolutions, config the audio setting with the previous audio parameters.
--- drivers/gpu/drm/mediatek/mtk_dp.c | 55 ++++++++++--------------------- 1 file changed, 18 insertions(+), 37 deletions(-)
drivers/gpu/drm/mediatek/mtk_dp.c +18 -37
@@ -109,7 +109,7 @@ struct mtk_dp_audio_cfg {struct mtk_dp_info {u32 depth;enum dp_pixelformat format; -struct mtk_dp_audio_cfg audio_caps; +struct mtk_dp_audio_cfg audio_cur_cfg;struct mtk_dp_timings timings; };
@@ -1921,9 +1921,7 @@ static bool mtk_dp_edid_parse_audio_capabilities(struct mtk_dp *mtk_dp, struct mtk_dp_audio_cfg *cfg) {struct cea_sad *sads; -int sad_count; -int i; -bool ret = false; +int ret;if (mtk_dp_is_edp (mtk_dp))return false;
@@ -1934,36 +1932,16 @@ static bool mtk_dp_edid_parse_audio_capabilities(struct mtk_dp *mtk_dp,dev_err (mtk_dp->dev,"EDID not found!\n" );return false; } - sad_count =drm_edid_to_sad (mtk_dp->edid, &sads); -mutex_unlock (&mtk_dp->edid_lock); -if (sad_count <=0 ) { + ret =drm_edid_to_sad (mtk_dp->edid, &sads); +mutex_unlock (&mtk_dp->edid_lock); +if (ret <=0 ) {drm_info (mtk_dp->drm_dev,"The SADs is NULL\n" );return false; } - -for (i =0 ; i < sad_count; i++) { -int sample_rate, word_length; - -/* Only PCM supported at the moment */ -if (sads[i].format !=HDMI_AUDIO_CODING_TYPE_PCM ) -continue ; - - sample_rate =drm_cea_sad_get_sample_rate (&sads[i]); - word_length = -drm_cea_sad_get_uncompressed_word_length (&sads[i]); -if (sample_rate <=0 || word_length <=0 ) -continue ; - - cfg->channels = sads[i].channels; - cfg->word_length_bits = word_length; - cfg->sample_rate = sample_rate; - ret = true; -break ; - }kfree (sads); -return ret; +return true; }static void mtk_dp_train_change_mode (struct mtk_dp *mtk_dp)
@@ -2129,14 +2107,15 @@ static int mtk_dp_training(struct mtk_dp *mtk_dp) mtk_dp->audio_enable =mtk_dp_edid_parse_audio_capabilities (mtk_dp, - &mtk_dp->info.audio_caps); + &mtk_dp->info.audio_cur_cfg);if (mtk_dp->audio_enable) { -mtk_dp_audio_setup (mtk_dp, &mtk_dp->info.audio_caps); +mtk_dp_audio_setup (mtk_dp, + &mtk_dp->info.audio_cur_cfg);mtk_dp_audio_mute (mtk_dp, false); }else { -memset (&mtk_dp->info.audio_caps,0 , -sizeof (mtk_dp->info.audio_caps)); +memset (&mtk_dp->info.audio_cur_cfg,0 , +sizeof (mtk_dp->info.audio_cur_cfg)); } training_done = true;
@@ -2590,6 +2569,9 @@ static void mtk_dp_bridge_atomic_disable(struct drm_bridge *bridge,if (mtk_dp_plug_state (mtk_dp)) {drm_dp_dpcd_writeb (&mtk_dp->aux,DP_SET_POWER ,DP_SET_POWER_D3 );usleep_range (2000 ,3000 ); + }else { +memset (&mtk_dp->info.audio_cur_cfg,0 , +sizeof (mtk_dp->info.audio_cur_cfg)); }mtk_dp_video_mute (mtk_dp, true);
@@ -2799,18 +2781,17 @@ static int mtk_dp_audio_hw_params(struct device *dev, void *data, struct hdmi_codec_params *params) {struct mtk_dp *mtk_dp =dev_get_drvdata (dev); -struct mtk_dp_audio_cfg cfg;if (!mtk_dp->enabled) {pr_err ("%s, DP is not ready!\n" , __func__);return -ENODEV ; } - cfg.channels = params->cea.channels; - cfg.sample_rate = params->sample_rate; - cfg.word_length_bits =24 ; + mtk_dp->info.audio_cur_cfg.channels = params->cea.channels; + mtk_dp->info.audio_cur_cfg.sample_rate = params->sample_rate; + mtk_dp->info.audio_cur_cfg.word_length_bits =24 ; -mtk_dp_audio_setup (mtk_dp, &cfg); +mtk_dp_audio_setup (mtk_dp, &mtk_dp->info.audio_cur_cfg);return 0 ; }
Signature · 1 line
2.18.0