From patchwork Wed Jul 25 05:38:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Qu, Jim" X-Patchwork-Id: 10543455 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B733517FD for ; Wed, 25 Jul 2018 05:38:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A550F29135 for ; Wed, 25 Jul 2018 05:38:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96C9A29430; Wed, 25 Jul 2018 05:38:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7252C29135 for ; Wed, 25 Jul 2018 05:38:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A373D6E222; Wed, 25 Jul 2018 05:38:41 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0073.outbound.protection.outlook.com [104.47.33.73]) by gabe.freedesktop.org (Postfix) with ESMTPS id 330B96E222; Wed, 25 Jul 2018 05:38:40 +0000 (UTC) Received: from DM3PR12MB0873.namprd12.prod.outlook.com (10.164.7.143) by DM3PR12MB0779.namprd12.prod.outlook.com (10.164.7.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.973.21; Wed, 25 Jul 2018 05:38:37 +0000 Received: from DM3PR12MB0873.namprd12.prod.outlook.com ([fe80::8ce9:6961:2e6d:6415]) by DM3PR12MB0873.namprd12.prod.outlook.com ([fe80::8ce9:6961:2e6d:6415%4]) with mapi id 15.20.0995.014; Wed, 25 Jul 2018 05:38:37 +0000 From: "Qu, Jim" To: Takashi Iwai , "alsa-devel@alsa-project.org" Subject: =?eucgb2312_cn?b?tPC4tDogW1BBVENIIDQvNF0gZHJtL2FtZGdwdTogQWRkIGF1ZGlvIGNv?= =?eucgb2312_cn?b?bXBvbmVudCBzdXBwb3J0?= Thread-Topic: [PATCH 4/4] drm/amdgpu: Add audio component support Thread-Index: AQHUIpSG238gl4y34UmKk6Dsu70eN6SfTUQ7 Date: Wed, 25 Jul 2018 05:38:37 +0000 Message-ID: References: <20180723145030.25133-1-tiwai@suse.de>, <20180723145030.25133-5-tiwai@suse.de> In-Reply-To: <20180723145030.25133-5-tiwai@suse.de> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [116.228.147.241] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM3PR12MB0779; 20:K9PnDiwIuWLmBm6Zk46CP6T1x4ozYZFPjwdFg4bBXCxhnfuZEM/PFXZ/mhF9WdPiiInPx/UnASrdtVJISLcYSlbI/CukC5gzdzu/J8Kuqi7KfCybPaNMRNZG/nKSQJuAlbaTrJapPMzlRGgGFiJzZjTKkHFRRiDCja2a9Ce2VYqa869yKmQNxvnxR8ngPtVu6+3TWMg5E/woxunob9GoSg8wk03u+5Yc8yEZjlThzsBhvh5xUN0IOBGAo4lGapiL x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 5a7bc5ed-1759-40d1-3c27-08d5f1f0de9e x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600073)(711020)(4618075)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:DM3PR12MB0779; x-ms-traffictypediagnostic: DM3PR12MB0779: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(217544274631240); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231311)(944501410)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:DM3PR12MB0779; BCL:0; PCL:0; RULEID:; SRVR:DM3PR12MB0779; x-forefront-prvs: 0744CFB5E8 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(396003)(366004)(346002)(39860400002)(376002)(189003)(199004)(7736002)(5660300001)(476003)(54906003)(110136005)(6306002)(305945005)(66066001)(55016002)(9686003)(186003)(486006)(53936002)(68736007)(6436002)(11346002)(102836004)(33656002)(2906002)(446003)(2900100001)(6506007)(316002)(14444005)(86362001)(97736004)(256004)(4326008)(106356001)(74316002)(76176011)(8936002)(72206003)(2501003)(14454004)(224303003)(3846002)(5250100002)(966005)(105586002)(81156014)(7696005)(26005)(81166006)(99286004)(478600001)(6116002)(25786009)(309714004); DIR:OUT; SFP:1101; SCL:1; SRVR:DM3PR12MB0779; H:DM3PR12MB0873.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: yanU5EM5EU0rBVIVdZo1HrTFRjg55Mff2Z++be03es4VLSc8eFx8LcVcBKFGBxGFuQMxCkMxaTcKJTcKhlzl+5I6QqwEKhtl8Nc5JdbPVjDxM7dDUKAxn8M+uklLT8sNP2s9qZFO3CKp3WX0etboLZr1o27vOy9klo94/S/jvBcu150sa9EYl/3uhP6OYSLuIozQ9UiKNwu1VJQJR3gemhF5QYQyN2dWQOcm54RILKWHR+j5+WLMZ1vTealA80Vz+C/zciB5C0k3hzIw6dplW0ljunv210kKI54gFC2M/JZqEMEXFjohJLCR6dPusJy0kCZ0+lRAZ0J5rxoZBWMl1aohtsV2ytdLTggJR0N3kGw= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a7bc5ed-1759-40d1-3c27-08d5f1f0de9e X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Jul 2018 05:38:37.0478 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB0779 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "dri-devel@lists.freedesktop.org" , "amd-gfx@lists.freedesktop.org" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP See comments in line. Thanks JimQu diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 2c7112ddfed4..fbe7216c5c56 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -193,6 +193,7 @@ config DRM_AMDGPU select BACKLIGHT_LCD_SUPPORT select INTERVAL_TREE select CHASH + select SND_HDA_COMPONENT if SND_HDA_CORE help Choose this option if you have a recent AMD Radeon graphics card. diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile b/drivers/gpu/drm/amd/amdgpu/Makefile index bfd332c95b61..9c26facddb17 100644 --- a/drivers/gpu/drm/amd/amdgpu/Makefile +++ b/drivers/gpu/drm/amd/amdgpu/Makefile @@ -52,7 +52,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \ amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \ amdgpu_gtt_mgr.o amdgpu_vram_mgr.o amdgpu_virt.o amdgpu_atomfirmware.o \ amdgpu_queue_mgr.o amdgpu_vf_error.o amdgpu_sched.o amdgpu_debugfs.o \ - amdgpu_ids.o + amdgpu_ids.o amdgpu_audio.o # add asic specific block amdgpu-$(CONFIG_DRM_AMDGPU_CIK)+= cik.o cik_ih.o kv_smc.o kv_dpm.o \ diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index a59c07590cee..203d2584c989 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -1957,5 +1957,9 @@ int amdgpu_dm_display_resume(struct amdgpu_device *adev ); static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; } #endif +int amdgpu_audio_component_init(struct amdgpu_device *adev); +void amdgpu_audio_component_fini(struct amdgpu_device *adev); +void amdgpu_audio_eld_notify(struct amdgpu_device *adev, int pin); + #include "amdgpu_object.h" #endif diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_audio.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_audio.c new file mode 100644 index 000000000000..39256e2f84b3 --- /dev/null +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_audio.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: MIT + +#include +#include "amdgpu.h" + +static int amdgpu_audio_component_get_eld(struct device *kdev, int port, + int pipe, bool *enabled, + unsigned char *buf, int max_bytes) +{ + struct drm_device *dev = dev_get_drvdata(kdev); + struct drm_encoder *encoder; + struct amdgpu_encoder *amdgpu_encoder; + struct amdgpu_encoder_atom_dig *dig; + struct drm_connector *connector; + int ret = 0; + + *enabled = 0; + list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { + amdgpu_encoder = to_amdgpu_encoder(encoder); + dig = amdgpu_encoder->enc_priv; + if (!dig || !dig->afmt || !dig->afmt->enabled) + continue; + if (!dig->afmt->pin || dig->afmt->pin->id != port) + continue; + connector = amdgpu_get_connector_for_encoder(encoder); + *enabled = !!connector; + if (connector) { + ret = drm_eld_size(connector->eld); + memcpy(buf, connector->eld, min(max_bytes, ret)); + break; + } + } + + return ret; +} + +static const struct drm_audio_component_ops amdgpu_audio_component_ops = { + .get_eld = amdgpu_audio_component_get_eld, +}; + +static int amdgpu_audio_component_bind(struct device *kdev, + struct device *hda_kdev, void *data) +{ + struct drm_device *dev = dev_get_drvdata(kdev); + struct amdgpu_device *adev = dev->dev_private; + struct drm_audio_component *acomp = data; + + acomp->ops = &amdgpu_audio_component_ops; + acomp->dev = kdev; + adev->mode_info.audio.component = acomp; + return 0; +} + +static void amdgpu_audio_component_unbind(struct device *kdev, + struct device *hda_kdev, void *data) +{ + struct drm_device *dev = dev_get_drvdata(kdev); + struct amdgpu_device *adev = dev->dev_private; + struct drm_audio_component *acomp = data; + + acomp->ops = NULL; + acomp->dev = NULL; + adev->mode_info.audio.component = NULL; +} + +static const struct component_ops amdgpu_audio_component_bind_ops = { + .bind = amdgpu_audio_component_bind, + .unbind = amdgpu_audio_component_unbind, +}; + +int amdgpu_audio_component_init(struct amdgpu_device *adev) +{ + int err; + + err = component_add(adev->dev, &amdgpu_audio_component_bind_ops); + if (err < 0) + return err; + adev->mode_info.audio.component_registered = true; + return 0; +} + +void amdgpu_audio_component_fini(struct amdgpu_device *adev) +{ + if (adev->mode_info.audio.component_registered) { + component_del(adev->dev, &amdgpu_audio_component_bind_ops); + adev->mode_info.audio.component_registered = false; + } +} + +void amdgpu_audio_eld_notify(struct amdgpu_device *adev, int pin) +{ + struct drm_audio_component *acomp = adev->mode_info.audio.component; + + if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify) + acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr, + pin, -1); +} diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h index b9e9e8b02fb7..7cb1aa97e522 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -260,6 +261,8 @@ struct amdgpu_audio { bool enabled; struct amdgpu_audio_pin pin[AMDGPU_MAX_AFMT_BLOCKS]; int num_pins; + bool component_registered; + struct drm_audio_component *component; }; struct amdgpu_display_funcs { diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c index ada241bfeee9..c8471a59930f 100644 --- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c +++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c @@ -1392,6 +1392,8 @@ static void dce_v10_0_audio_enable(struct amdgpu_device *adev, WREG32_AUDIO_ENDPT(pin->offset, ixAZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, enable ? AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL__AUDIO_ENABLED_MASK : 0); + + amdgpu_audio_eld_notify(adev, pin->id); } static const u32 pin_offsets[] = @@ -1430,6 +1432,8 @@ static int dce_v10_0_audio_init(struct amdgpu_device *adev) dce_v10_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false); } + amdgpu_audio_component_init(adev); + return 0; } @@ -1443,6 +1447,8 @@ static void dce_v10_0_audio_fini(struct amdgpu_device *adev) if (!adev->mode_info.audio.enabled) return; + amdgpu_audio_component_fini(adev); + for (i = 0; i < adev->mode_info.audio.num_pins; i++) dce_v10_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false); diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c index a5b96eac3033..49edb74725a7 100644 --- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c +++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c @@ -1418,6 +1418,8 @@ static void dce_v11_0_audio_enable(struct amdgpu_device *adev, WREG32_AUDIO_ENDPT(pin->offset, ixAZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, enable ? AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL__AUDIO_ENABLED_MASK : 0); + + amdgpu_audio_eld_notify(adev, pin->id); } static const u32 pin_offsets[] = @@ -1472,6 +1474,8 @@ static int dce_v11_0_audio_init(struct amdgpu_device *adev) dce_v11_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false); } + amdgpu_audio_component_init(adev); + return 0; } @@ -1485,6 +1489,8 @@ static void dce_v11_0_audio_fini(struct amdgpu_device *adev) if (!adev->mode_info.audio.enabled) return; + amdgpu_audio_component_fini(adev); + for (i = 0; i < adev->mode_info.audio.num_pins; i++) dce_v11_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false); diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c index 394cc1e8fe20..2b7468eaacca 100644 --- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c +++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c @@ -1297,6 +1297,8 @@ static void dce_v6_0_audio_enable(struct amdgpu_device *adev, WREG32_AUDIO_ENDPT(pin->offset, ixAZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, enable ? AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL__AUDIO_ENABLED_MASK : 0); + + amdgpu_audio_eld_notify(adev, pin->id); } static const u32 pin_offsets[7] = @@ -1343,6 +1345,8 @@ static int dce_v6_0_audio_init(struct amdgpu_device *adev) dce_v6_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false); } + amdgpu_audio_component_init(adev); + return 0; } @@ -1356,6 +1360,8 @@ static void dce_v6_0_audio_fini(struct amdgpu_device *adev) if (!adev->mode_info.audio.enabled) return; + amdgpu_audio_component_fini(adev); + for (i = 0; i < adev->mode_info.audio.num_pins; i++) dce_v6_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false); diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c index c9b9ab8f1b05..c2370ea1f64f 100644 --- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c +++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c @@ -1348,6 +1348,8 @@ static void dce_v8_0_audio_enable(struct amdgpu_device *adev, WREG32_AUDIO_ENDPT(pin->offset, ixAZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, enable ? AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL__AUDIO_ENABLED_MASK : 0); + + amdgpu_audio_eld_notify(adev, pin->id); } static const u32 pin_offsets[7] = @@ -1395,6 +1397,8 @@ static int dce_v8_0_audio_init(struct amdgpu_device *adev) dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false); } + amdgpu_audio_component_init(adev); + return 0; } @@ -1408,6 +1412,8 @@ static void dce_v8_0_audio_fini(struct amdgpu_device *adev) if (!adev->mode_info.audio.enabled) return; + amdgpu_audio_component_fini(adev); + for (i = 0; i < adev->mode_info.audio.num_pins; i++) dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);