From patchwork Fri Feb 10 04:48:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orlando Chamberlain X-Patchwork-Id: 55215 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp755645wrn; Thu, 9 Feb 2023 20:52:00 -0800 (PST) X-Google-Smtp-Source: AK7set+V0ncz35biLl3V4Q88tjGNg5/4/xCoXwH+7bXZpuybl4+yr3ZQX1QKBlLaDNDnRVUbTJyP X-Received: by 2002:a50:a41b:0:b0:4ab:1689:64f1 with SMTP id u27-20020a50a41b000000b004ab168964f1mr7210759edb.8.1676004720193; Thu, 09 Feb 2023 20:52:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676004720; cv=none; d=google.com; s=arc-20160816; b=MHh0brR+TYexEzucU4hDTElzVKVMnQCMOhGLSKMORRGeS56xgvar9403U9uNhM7n2I z6O+cl3BIz8nsDtwIh+9DBxr5jK+ZPxpoE2AQsiTSoIpg/SmT2CNTVKDB6YerIvDMhlP Cap5T6SyDokGe2Fnk/7SoAxo7P0wCFCm0KLFtihQ/fGCA0YlBfR5N5XzDnkNNPFP304h vp1nxowkyf0PapyM63Cox/BwPF+Si0kYhNrHjCpGklqbTkxVRypxOCShdZIjJ8rSSN7L VHhTBStCVBdwZwY8ZwAxIrsClpI8mJ1ZgpFapxPAOSb3N0mnVzgm6kVryn2lkZDTEz/3 0reA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5mAzAHTdZsC5IqNul3xJsl6wPXmAHfKwZ27VCzKXGF4=; b=Y7rVo9k9TQPuuiTL3mWwQ+2p5DhXDH4igdG5dQMpvk5XcXRGs/JITAVEjbWVX9RqJb dE0uUt2UeLPL5tj2DlCT+Copz0f2F3yrPm7B1hxhJW8inRtYpYYDklctvoiYlaAgZCd2 ouoOGsrJ8yzLjdZTISo8Q1n2D5nqdyyANEpjTbpgQG2Y3kYSy9liol6gGU2Il30OcyaQ TvChzgjwDgba2AmnLFjHt+smTJgj5kmMThCi0ns7S+k20hWp/+hX4igWU/qrsxmTbgsb 4JwEGwG2lq83GGyKyKmw3j/e5DFoRVvWDsBHkg7RTKBFk8jzMusOOH/mq7/Zu9r7d6pH Qukw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JVtiloj7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z16-20020aa7d410000000b004aad854e24csi4261102edq.24.2023.02.09.20.51.37; Thu, 09 Feb 2023 20:52:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JVtiloj7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229762AbjBJEuX (ORCPT + 99 others); Thu, 9 Feb 2023 23:50:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230477AbjBJEuK (ORCPT ); Thu, 9 Feb 2023 23:50:10 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1F775B74E; Thu, 9 Feb 2023 20:50:09 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id q9so2973528pgq.5; Thu, 09 Feb 2023 20:50:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5mAzAHTdZsC5IqNul3xJsl6wPXmAHfKwZ27VCzKXGF4=; b=JVtiloj7yRa4BQFYW86RmJebSQYTmr6ulQWbaNdE813YnQNwxXxigdeqKGwJ547OA9 iKneGqYybribFvactjWAxLOC1FFyHyE+vrJN9XEm4Abm2yHTeo6rcn+1OgEhy5wP98gZ +ThcUd3YSIgv/n1tSUkAQD0bQGEO9epBP65UtYfzB4TDt5HkYEHAUsO9ybZHG+TDzu0u hqJKP33cLtrVl0eYH6Qi6HmbIoL1D0nmoU8eLgaP0zLDynkeKmwUzTLzZaRDN3rU0PL/ En5vvM6GmtpTk46YMQcS55SP+xFg1xh1ZcTgKWrbYfmIOMTZVYpC6OIy+kKwcbJ4fUCF NfGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5mAzAHTdZsC5IqNul3xJsl6wPXmAHfKwZ27VCzKXGF4=; b=QsU4lTjw8OkLlk8yMyhfB/0Au9kN822s3nOScVY9NuQMCAav7klgBpMFNkNpzMPyd1 +YXXu1kBm8LeznkG6+hakTDxVLL/fnbwGpaSJjGWtKJRlbDU581LiXn4iuwBePBIN93E 7cvYgGVjoqST/LejMIqUuRJ+QYm0slKEAhRuxaJeTOm914hD06o0IMhFiHBmtAlPQLgF 2/43wFFSiM6d4nn6YLBpEOjXy3rVG5LP5P3JrXDmFTk6AnxcKjO5UDxA/JJZek0ePA9h fujqrIGGRUj7h+EpnXY+BPeAfw9HgtQje4nf88/cWnnCWIgRI6NQZRXMh6sPx0Ypr0gQ hnSg== X-Gm-Message-State: AO0yUKX9pwwzJJd6Iu8gWfGpb4CdmvIGl5owLMpAfSE7P+lb+uSB5b7E 619dkjR5HU1G7Ljk6LZUpPLKrRHBA14tBw== X-Received: by 2002:a62:1c13:0:b0:593:2289:f01c with SMTP id c19-20020a621c13000000b005932289f01cmr11514678pfc.25.1676004609052; Thu, 09 Feb 2023 20:50:09 -0800 (PST) Received: from localhost.localdomain ([202.53.32.211]) by smtp.gmail.com with ESMTPSA id t13-20020a62ea0d000000b0057fec210d33sm2269218pfh.152.2023.02.09.20.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 20:50:08 -0800 (PST) From: Orlando Chamberlain To: platform-driver-x86@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org Cc: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Hans de Goede , Mark Gross , Jaroslav Kysela , Takashi Iwai , Hawking Zhang , Andrey Grodzovsky , Lijo Lazar , YiPeng Chai , Somalapuram Amaranath , Mario Limonciello , Bokun Zhang , Jack Xiao , Kai Vehmanen , Pierre-Louis Bossart , Rander Wang , Ranjani Sridharan , =?utf-8?q?Amadeusz_S?= =?utf-8?q?=C5=82awi=C5=84ski?= , Yong Zhi , Evan Quan , Kerem Karabay , Aditya Garg , Aun-Ali Zaidi , Orlando Chamberlain Subject: [RFC PATCH 1/9] apple-gmux: use cpu_to_be32 instead of manual reorder Date: Fri, 10 Feb 2023 15:48:18 +1100 Message-Id: <20230210044826.9834-2-orlandoch.dev@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210044826.9834-1-orlandoch.dev@gmail.com> References: <20230210044826.9834-1-orlandoch.dev@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757418325797210599?= X-GMAIL-MSGID: =?utf-8?q?1757418325797210599?= Currently it manually flips the byte order, but we can instead use cpu_to_be32(val) for this. Signed-off-by: Orlando Chamberlain --- drivers/platform/x86/apple-gmux.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c index 9333f82cfa8a..e8cb084cb81f 100644 --- a/drivers/platform/x86/apple-gmux.c +++ b/drivers/platform/x86/apple-gmux.c @@ -94,13 +94,7 @@ static u32 gmux_pio_read32(struct apple_gmux_data *gmux_data, int port) static void gmux_pio_write32(struct apple_gmux_data *gmux_data, int port, u32 val) { - int i; - u8 tmpval; - - for (i = 0; i < 4; i++) { - tmpval = (val >> (i * 8)) & 0xff; - outb(tmpval, gmux_data->iostart + port + i); - } + outl(cpu_to_be32(val), gmux_data->iostart + port); } static int gmux_index_wait_ready(struct apple_gmux_data *gmux_data) @@ -177,16 +171,8 @@ static u32 gmux_index_read32(struct apple_gmux_data *gmux_data, int port) static void gmux_index_write32(struct apple_gmux_data *gmux_data, int port, u32 val) { - int i; - u8 tmpval; - mutex_lock(&gmux_data->index_lock); - - for (i = 0; i < 4; i++) { - tmpval = (val >> (i * 8)) & 0xff; - outb(tmpval, gmux_data->iostart + GMUX_PORT_VALUE + i); - } - + outl(cpu_to_be32(val), gmux_data->iostart + GMUX_PORT_VALUE); gmux_index_wait_ready(gmux_data); outb(port & 0xff, gmux_data->iostart + GMUX_PORT_WRITE); gmux_index_wait_complete(gmux_data); From patchwork Fri Feb 10 04:48:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orlando Chamberlain X-Patchwork-Id: 55218 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp755806wrn; Thu, 9 Feb 2023 20:52:32 -0800 (PST) X-Google-Smtp-Source: AK7set/6/N7oZumKwrJjY0MDoe1k8rd96kY22fWdNBm48NKCEwHokKtKUhhjxEnX26qGnyw9o2ww X-Received: by 2002:a05:6a21:6d9b:b0:bc:bae7:642f with SMTP id wl27-20020a056a216d9b00b000bcbae7642fmr18161477pzb.58.1676004751932; Thu, 09 Feb 2023 20:52:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676004751; cv=none; d=google.com; s=arc-20160816; b=ukazm/v651sJ8X5CTux2OCMiqAYZjgIaRY8IVTItv8PKUfDZ09E9QCrtlZMaj1eSDc h1IbFKME2AVQgPVoHsopk1LakOnWodE5AdbfMZAIZCwlG2BoMlhkXh/j1HjzvFIBcKZn 32kIZg4QNz1lI9v1TQUBMn6qsPkceqO9kzE8oSdkq46adOyR72bCKeQPcGXx9tw1PhAi 3GhCotQ9kcX/hExzGY+xk5a3yAlM9dGYVLlPfDKiZj7IKaBC9R+OKtlmxxm3DdgHhasB 4EER/xWbHxDwLneHb7IpSz8VbmS3JkdfQS7GQGeaM4EtLIN7UmrQmxoSug8sCTu4QVU2 Ugcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Y8Z+rw3Lo4ZI53HBYFrES/rZyYmIcMPWeV9Tjc6GjJE=; b=vRrVVH8+l+fIcKATegYHm0idcI1/wY7tDS+XHjPTX2RN1x4OeBjnthxrB5Uw+SjBqS vDCZ1ai0tG4cT4JwZTWU81klMA1YSR2RDByWFIWa24wqRXpc8F9Y4o7xi4wCv8ILvvI2 cIU2K88x2yVX+aZ1pZNZuc0d+HNQQBJcAakvbdOnLRB+Nb2av8f1fj2dHn2Lg/+oXTF1 wai5EF59Fz+FA5VZPLJ0LupnM3fURTmIYe7bBpBda3oyGuIA5QLHmlj9HwRimz0Rml3e V3UgVIS7fwrSHAtK0BILzyIbUA+tfyD85f8mQBrOsygfKEkXTYfvl3h5W45+O6Gz48yK Vl7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dfjrwZCU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a63700c000000b004df3ece2141si3524299pgc.788.2023.02.09.20.52.19; Thu, 09 Feb 2023 20:52:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dfjrwZCU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231249AbjBJEud (ORCPT + 99 others); Thu, 9 Feb 2023 23:50:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231255AbjBJEuV (ORCPT ); Thu, 9 Feb 2023 23:50:21 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A544E70976; Thu, 9 Feb 2023 20:50:19 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id v18-20020a17090ae99200b00230f079dcd9so7292512pjy.1; Thu, 09 Feb 2023 20:50:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y8Z+rw3Lo4ZI53HBYFrES/rZyYmIcMPWeV9Tjc6GjJE=; b=dfjrwZCUTXg0++zE/wVkz4Z96Dke9cdiJGPWOJx+bSbwOuQzxzamUP7h08RKQKxmci TJuBqsc+PY+NgKeBk1dK5ehjoB56e05oCGCVdL0fCqIdQhc0VEGhFat0cmuxanHzAMg0 PkBLd+8yttsFpd3mZCaA1SzojWL4FcQ3HiMdQp77gFhOpZsKqeYz/jeR1LyHxN4YyLTb 3ZMp1vTJystxqoDQUey6c9p8i3s2QjUBsSsvBZ5rfq9WUIORdJzIDSR0QALHgrjXZ77j ScTwjw3ohujsiuZkCI2r2hTPzZp/mGapCXYydIZhMspEsgiXfPGfK8D+y5YVUcqfbqEh 3VYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y8Z+rw3Lo4ZI53HBYFrES/rZyYmIcMPWeV9Tjc6GjJE=; b=jzyqCXMdfqqldbbMaDXjAbBclEuq+Q2GFfGHnlNRWZmxZOvUV9UVGmHNrJ9rw4A0lO P0pzklApw8nOnwZNF3X1qQ95SFBTHj9nfG2zs75JYFVUYJ+uIM0GL0Qht7xkzBAdlqKR zvs0t/5g7ee/SIfs1csKFHCE4Uw0tIN1wnGCEE7TcS2vGOomh5z5TjzR511G1Ed/+agf qyu8exxrr0Hxt9A2tHXLqj3f/xrMHtd0z7OM6r+D9LdHha3cLop+4GMY26Ht9m36L2fh R5bZagYpdzrk3grulg2derfmEutmlfNfPawZCe/5KzyUrtSpspqpS64csSn6EQJzLLGl 147w== X-Gm-Message-State: AO0yUKX9xiCS9323PD74vqS4BA+ISIAdsl/XNU4jH3Hyqw9GtcgA8RqV JItGEcFJijPy+IOAOtLB9mkMwYASs6kVsw== X-Received: by 2002:a05:6a21:339a:b0:bf:22ca:ef55 with SMTP id yy26-20020a056a21339a00b000bf22caef55mr17822193pzb.37.1676004618944; Thu, 09 Feb 2023 20:50:18 -0800 (PST) Received: from localhost.localdomain ([202.53.32.211]) by smtp.gmail.com with ESMTPSA id t13-20020a62ea0d000000b0057fec210d33sm2269218pfh.152.2023.02.09.20.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 20:50:18 -0800 (PST) From: Orlando Chamberlain To: platform-driver-x86@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org Cc: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Hans de Goede , Mark Gross , Jaroslav Kysela , Takashi Iwai , Hawking Zhang , Andrey Grodzovsky , Lijo Lazar , YiPeng Chai , Somalapuram Amaranath , Mario Limonciello , Bokun Zhang , Jack Xiao , Kai Vehmanen , Pierre-Louis Bossart , Rander Wang , Ranjani Sridharan , =?utf-8?q?Amadeusz_S?= =?utf-8?q?=C5=82awi=C5=84ski?= , Yong Zhi , Evan Quan , Kerem Karabay , Aditya Garg , Aun-Ali Zaidi , Orlando Chamberlain Subject: [RFC PATCH 2/9] apple-gmux: consolidate version reading Date: Fri, 10 Feb 2023 15:48:19 +1100 Message-Id: <20230210044826.9834-3-orlandoch.dev@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210044826.9834-1-orlandoch.dev@gmail.com> References: <20230210044826.9834-1-orlandoch.dev@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757418358772893656?= X-GMAIL-MSGID: =?utf-8?q?1757418358772893656?= Read gmux version in one go as 32 bits on both indexed and classic gmux's. Classic gmux's used to read the version as major = inb(base + 0x4); minor = inb(base + 0x5); release = inb(base + 0x6); but this can instead be done the same way as indexed gmux's with gmux_read32(), so the same version reading code is used for classic and indexed gmux's (as well as mmio gmux's that will be added to this driver). Signed-off-by: Orlando Chamberlain --- drivers/platform/x86/apple-gmux.c | 14 ++++++-------- include/linux/apple-gmux.h | 6 +----- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c index e8cb084cb81f..67628104f31a 100644 --- a/drivers/platform/x86/apple-gmux.c +++ b/drivers/platform/x86/apple-gmux.c @@ -580,15 +580,13 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) if (indexed) { mutex_init(&gmux_data->index_lock); gmux_data->indexed = true; - version = gmux_read32(gmux_data, GMUX_PORT_VERSION_MAJOR); - ver_major = (version >> 24) & 0xff; - ver_minor = (version >> 16) & 0xff; - ver_release = (version >> 8) & 0xff; - } else { - ver_major = gmux_read8(gmux_data, GMUX_PORT_VERSION_MAJOR); - ver_minor = gmux_read8(gmux_data, GMUX_PORT_VERSION_MINOR); - ver_release = gmux_read8(gmux_data, GMUX_PORT_VERSION_RELEASE); } + + version = gmux_read32(gmux_data, GMUX_PORT_VERSION_MAJOR); + ver_major = (version >> 24) & 0xff; + ver_minor = (version >> 16) & 0xff; + ver_release = (version >> 8) & 0xff; + pr_info("Found gmux version %d.%d.%d [%s]\n", ver_major, ver_minor, ver_release, (gmux_data->indexed ? "indexed" : "classic")); diff --git a/include/linux/apple-gmux.h b/include/linux/apple-gmux.h index 1f68b49bcd68..eb2caee04abd 100644 --- a/include/linux/apple-gmux.h +++ b/include/linux/apple-gmux.h @@ -67,7 +67,6 @@ static inline bool apple_gmux_is_indexed(unsigned long iostart) */ static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, bool *indexed_ret) { - u8 ver_major, ver_minor, ver_release; struct device *dev = NULL; struct acpi_device *adev; struct resource *res; @@ -95,10 +94,7 @@ static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, bool *indexed_ret) * Invalid version information may indicate either that the gmux * device isn't present or that it's a new one that uses indexed io. */ - ver_major = inb(res->start + GMUX_PORT_VERSION_MAJOR); - ver_minor = inb(res->start + GMUX_PORT_VERSION_MINOR); - ver_release = inb(res->start + GMUX_PORT_VERSION_RELEASE); - if (ver_major == 0xff && ver_minor == 0xff && ver_release == 0xff) { + if (!(~inl(res->start + GMUX_PORT_VERSION_MAJOR))) { indexed = apple_gmux_is_indexed(res->start); if (!indexed) goto out; From patchwork Fri Feb 10 04:48:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orlando Chamberlain X-Patchwork-Id: 55216 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp755759wrn; Thu, 9 Feb 2023 20:52:22 -0800 (PST) X-Google-Smtp-Source: AK7set/Qpziwcwja+mPpdGc6T9IY8Osz4Mf7Dqaqk/LidVytSUOYx52auMkKAUhYZorW+JGZOcei X-Received: by 2002:a17:906:ecb0:b0:84d:4325:7f7a with SMTP id qh16-20020a170906ecb000b0084d43257f7amr14190224ejb.65.1676004742625; Thu, 09 Feb 2023 20:52:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676004742; cv=none; d=google.com; s=arc-20160816; b=tZVhINR5qOXK1kwqxIcs7+5cF0rVKaoLxkXPHogUEekLLs2FI7uUTvumSoMoK53k4y ugiXnHxPLAA3Ytn8imJF/aegeRDOZ9Dolp+XeBnJGdibSHQxU1x7+PCjbSNoBNkBFhTY 2ryLO42wp7xkX5I0SPPI4heFt4YzgqSgeVnA0MXEeQMASXVAjCm3yJzV4WyaiRm//LCo OHetQkbPyDH1kGEk3pnEGvDPHAERVFcP/4KcEkRnYPrd2DbVjYjDlusHVy1bP9JelUeH LHT8jY/jCQw+rUh0u0DWTnojvQDDvFtIdGszSZ4BPUtJ2Eg9QK/k1fI2VSvRZ9pHvBrH kh7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zqShi3EgLDtgztLIgW/MuPsWv2vSLPgVWXrp/LobXww=; b=msxkFUW3M6cCvUhJ9l4rq++cXZd3goTTSEi2hyr8IUgymfNtWd/EMEP9Wkmv8SsMEx 0nWwdEOCCMcoHCDTDxVxxGLW1lP1Ozvi+esIqUZ2p7TDNZecWgSIT0PdQbQn/CNGFe2y OG7L9LmiXklBb/gW9nnq3JEZzlRmUxV8FmICvr9VgZijf4arOY7fAMKtkamjp4D3cYrP lgUoiNuqu/ELmH9mkixbuet8Ek5iC32JoN/qyLbpenNmoJ5OPzW6oSmtKXqyFSEBLxeQ wkVDLbUCgOfWybAyNpRjBl5WyZX8kGjp1fmEfniDoXXqR4JQ4gZKxdiVOSEUpNPeJYeq 3Gag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="Om+u/6Vn"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id uk7-20020a170907ca0700b008897b74cf85si4170293ejc.839.2023.02.09.20.51.59; Thu, 09 Feb 2023 20:52:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="Om+u/6Vn"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231219AbjBJEut (ORCPT + 99 others); Thu, 9 Feb 2023 23:50:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231255AbjBJEuf (ORCPT ); Thu, 9 Feb 2023 23:50:35 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E4D56E984; Thu, 9 Feb 2023 20:50:29 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id ay1so2754295pfb.7; Thu, 09 Feb 2023 20:50:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zqShi3EgLDtgztLIgW/MuPsWv2vSLPgVWXrp/LobXww=; b=Om+u/6VnAJG9TE8AtmP7qvhlFAe++DibsHxfnKB/uw1rT0M0wwXXptoFr0Xv+20ydo eakNNTYlCCk2g+ALxRE6kmjCfzNbNOYJFbMBHqWvHvIm2k/uZfv6KIo0xugx3nQig2py J1no3BHk6c8ezYo6oWs4KfkhLQOu7YRb0G1aFzEpM6YreNPESvbQ4vwbkdQg1ll66Mfa qmCJAD9lIdQ09n5BrE3kzDSLu8s0jx5ZJ2hqM233WpFqKrLUDc8SXFgEQ8iWwYwFo7zR SkcsIvSD7qiSPHhO2o5OR47wO55x0ECXZiVlRFfBnNKUyj1V+gZQOOhi2rAshPHtOKDE yP0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zqShi3EgLDtgztLIgW/MuPsWv2vSLPgVWXrp/LobXww=; b=fEeGayo9oSAzFo55k3ySjp9dRHOLyVpkVHUAQLhs6NMfgpobzEcneEwX0GCGoAPL1k inzOgFbsc4FqjNOaeus3HcJXvryd6FpqmpQ1eRFaz2pKz7jt7wHqHeL7Ok4+LTJGlasA Gze1LK+dbPwy2xWFBv2dbPg0WbBz7cofpp6MxvGPwwCwnB33c8JKhBMUumMT7m0i5hhd GqqdQNvwZEGDklH6CwrRXYOUshe2YoPRFOLcvZFgj4KYYE7vlB4W7O+vbtpWG1pnUxVG uNh9kLANRm58vmpHNKMZmvZiXvvJE9JUAU+r/swii0C4TQEzxVWDMkruecn21TQQJDGQ Fg4w== X-Gm-Message-State: AO0yUKUUFvCDhQ+cyw7Ve4kNvneNkPZs4ct4OKuGtN9xX+VE+kTgqzNW 31sRkEG3DRJhUJFwTrLcNb9lpSzQMvJCMQ== X-Received: by 2002:a62:6458:0:b0:5a8:6bb7:5fc5 with SMTP id y85-20020a626458000000b005a86bb75fc5mr1170747pfb.19.1676004628485; Thu, 09 Feb 2023 20:50:28 -0800 (PST) Received: from localhost.localdomain ([202.53.32.211]) by smtp.gmail.com with ESMTPSA id t13-20020a62ea0d000000b0057fec210d33sm2269218pfh.152.2023.02.09.20.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 20:50:28 -0800 (PST) From: Orlando Chamberlain To: platform-driver-x86@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org Cc: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Hans de Goede , Mark Gross , Jaroslav Kysela , Takashi Iwai , Hawking Zhang , Andrey Grodzovsky , Lijo Lazar , YiPeng Chai , Somalapuram Amaranath , Mario Limonciello , Bokun Zhang , Jack Xiao , Kai Vehmanen , Pierre-Louis Bossart , Rander Wang , Ranjani Sridharan , =?utf-8?q?Amadeusz_S?= =?utf-8?q?=C5=82awi=C5=84ski?= , Yong Zhi , Evan Quan , Kerem Karabay , Aditya Garg , Aun-Ali Zaidi , Orlando Chamberlain Subject: [RFC PATCH 3/9] apple-gmux: use first bit to check switch state Date: Fri, 10 Feb 2023 15:48:20 +1100 Message-Id: <20230210044826.9834-4-orlandoch.dev@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210044826.9834-1-orlandoch.dev@gmail.com> References: <20230210044826.9834-1-orlandoch.dev@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757418348759472245?= X-GMAIL-MSGID: =?utf-8?q?1757418348759472245?= On T2 Macs with MMIO gmux, when GMUX_PORT_SWITCH_DISPLAY is read, it can have values of 2, 3, 4, and 5. Odd values correspond to the discrete gpu, and even values correspond to the integrated gpu. The current logic is that only 2 corresponds to IGD, but this doesn't work for T2 Macs. Instead, check the first bit to determine the connected gpu. As T2 Macs with gmux only can switch the internal display, it is untested if this change (or a similar change) would be applicable to GMUX_PORT_SWITCH_DDC and GMUX_PORT_SWITCH_EXTERNAL. Signed-off-by: Orlando Chamberlain --- drivers/platform/x86/apple-gmux.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c index 67628104f31a..6109f4c2867c 100644 --- a/drivers/platform/x86/apple-gmux.c +++ b/drivers/platform/x86/apple-gmux.c @@ -332,10 +332,10 @@ static void gmux_read_switch_state(struct apple_gmux_data *gmux_data) else gmux_data->switch_state_ddc = VGA_SWITCHEROO_DIS; - if (gmux_read8(gmux_data, GMUX_PORT_SWITCH_DISPLAY) == 2) - gmux_data->switch_state_display = VGA_SWITCHEROO_IGD; - else + if (gmux_read8(gmux_data, GMUX_PORT_SWITCH_DISPLAY) & 1) gmux_data->switch_state_display = VGA_SWITCHEROO_DIS; + else + gmux_data->switch_state_display = VGA_SWITCHEROO_IGD; if (gmux_read8(gmux_data, GMUX_PORT_SWITCH_EXTERNAL) == 2) gmux_data->switch_state_external = VGA_SWITCHEROO_IGD; From patchwork Fri Feb 10 04:48:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orlando Chamberlain X-Patchwork-Id: 55221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp755900wrn; Thu, 9 Feb 2023 20:52:50 -0800 (PST) X-Google-Smtp-Source: AK7set/J+ROvhIp2CF1b3f3J7qn6u+Y9HwkxByyGFa6G33C0/PU0S9CpIyOziR69OQdM3UQ0gBiO X-Received: by 2002:a17:902:d10c:b0:19a:599f:f81a with SMTP id w12-20020a170902d10c00b0019a599ff81amr3865411plw.4.1676004770408; Thu, 09 Feb 2023 20:52:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676004770; cv=none; d=google.com; s=arc-20160816; b=r4XpV7rco+Psg8arjTlZGwfMTBLZazTAFTBem5h5JJQmNwtYcbDoGzfCBeJWhp3rgJ lnCBhoSk1Z7CKAIZOqv8bEopPpPDfh5gxs0hpHQ4rPeqT8G1M9bs6IUU+/iy+4NHT1SR uE6D94ctqAONO4LoD3OBxaGEaL9tcyHHbufCQss95zAdK0cis2m6ACIbC1plCPWjaiQb ozmrwnBqEuJawCdmGYimIj+z4gPtfrxNB0Kg8574hqRoY5/MEZzER5Bv6fPnCBm5lsYq D16HzsHPbeO0U1Jb64Rj3TfErlsKlO8IFxu6BAGCJG8j4HAjZCTD0Lh2kcVCG90Mp47/ 5QTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=llCbPbOzgkB9LqnEKDg0eJRQRzqzHegvsI/7ZgnBi0I=; b=gddMXmkGzwbxtKRA41kYbG2zX7mRMXkF8gR9kHu1eU8Fi9xUfkcxPzYy7v78SnELDn eRv5+hE203x7ZS0LrgLbANbPWEx39GXaCPl8gu8Mq8pWnVzzO5ntX77d6I0PSrXgXRlJ 8vpioT93kIPMFoDj98L18h4azu8q5GywchlCMIL4f+tqe0YvYy1ma/qy0Mh2GJp0XjVW 5oem56H0QG6ylye8QbM/wbqz0svCO0XYk0GN0Ey50TRXWclZGuATk0EeaIIxy0MPXfzp gxauipx/8wnNb+9cKriep2q5wj1YP37C3iZVdRGdYT5J+DWCH8/Dscxhp69c5GSbVCJ8 DtdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DakxaCeF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e187-20020a6369c4000000b004dfbe579e26si3709334pgc.351.2023.02.09.20.52.38; Thu, 09 Feb 2023 20:52:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DakxaCeF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231229AbjBJEvD (ORCPT + 99 others); Thu, 9 Feb 2023 23:51:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231192AbjBJEur (ORCPT ); Thu, 9 Feb 2023 23:50:47 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8C147717D; Thu, 9 Feb 2023 20:50:38 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id s8so2950412pgg.11; Thu, 09 Feb 2023 20:50:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=llCbPbOzgkB9LqnEKDg0eJRQRzqzHegvsI/7ZgnBi0I=; b=DakxaCeFrVUDK+fBPzwW0q50lGy8dfpodfy+gMycCeoLm0uDmeXFnQXXDZyLi7del7 JaaUcKkYa2ZMk6NKk7ql73vYJwD80tNBKd8BX9MS8jQSeiI2oGavDPYPWA6joip4Hx6U TLbJ+Kk1/3UIiTtq+g00TLDRCrzTYNbB+gaBeh3Mt5sKSY007swlm4nV852KMa/uGthP xLqZRWkgrgHg9wl5MbP3LDrV9cVcfLruRDM0bWbAYXXU4XhiGEZQ/DtWVnKsLeYZpIO4 rvMDC+rIIjsQt/LUdFi99/aFasESB8qmzDqCEijNL41XCe/zLP+GtXIzbmudLQkyprqV o/cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=llCbPbOzgkB9LqnEKDg0eJRQRzqzHegvsI/7ZgnBi0I=; b=5xZCAEA7yDfHXUV3JpZduAkAfYXwmsEALg0IsXY+T3dzjx8E3/VTfcZzNJH3mocero aoQOGTGIEcIpNIsUDHO+If2DGwoC0i4X2vfn0QgWt/COS/0ewKP0Aq3hRBUC5DhnwMp5 zsRhdc4XONtW+bn7v1WLyZF4KiPhAM1dljwRWdFsG93W5NXUtJ7z5SJ0lgt92qtltPxN GqfuSp+4oJuyxDgVALix4aVFAkTClPt4fQIBgW4nOzgPg1NT7WP/Pk1vDTk7NvmiKNQ3 LGoUfk2s+um4I82IVQMbpUp10mVsOHj6iGtmeqT9E5FgB0EwzKdSAyasGT1ll68OUa6x Mzdw== X-Gm-Message-State: AO0yUKXCV0QuDodAG5YgJaVB/OI5lddmEBlXUKQghJDYHbH9DDX0cJ6P O4J3XgnNPYaG7GiQ/8GzlQQqH6zgr/DzIQ== X-Received: by 2002:aa7:991a:0:b0:5a8:4de2:e95e with SMTP id z26-20020aa7991a000000b005a84de2e95emr5148288pff.18.1676004637995; Thu, 09 Feb 2023 20:50:37 -0800 (PST) Received: from localhost.localdomain ([202.53.32.211]) by smtp.gmail.com with ESMTPSA id t13-20020a62ea0d000000b0057fec210d33sm2269218pfh.152.2023.02.09.20.50.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 20:50:37 -0800 (PST) From: Orlando Chamberlain To: platform-driver-x86@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org Cc: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Hans de Goede , Mark Gross , Jaroslav Kysela , Takashi Iwai , Hawking Zhang , Andrey Grodzovsky , Lijo Lazar , YiPeng Chai , Somalapuram Amaranath , Mario Limonciello , Bokun Zhang , Jack Xiao , Kai Vehmanen , Pierre-Louis Bossart , Rander Wang , Ranjani Sridharan , =?utf-8?q?Amadeusz_S?= =?utf-8?q?=C5=82awi=C5=84ski?= , Yong Zhi , Evan Quan , Kerem Karabay , Aditya Garg , Aun-Ali Zaidi , Orlando Chamberlain Subject: [RFC PATCH 4/9] apple-gmux: refactor gmux types Date: Fri, 10 Feb 2023 15:48:21 +1100 Message-Id: <20230210044826.9834-5-orlandoch.dev@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210044826.9834-1-orlandoch.dev@gmail.com> References: <20230210044826.9834-1-orlandoch.dev@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757418378377903759?= X-GMAIL-MSGID: =?utf-8?q?1757418378377903759?= Add apple_gmux_config struct containing operations and data specific to each mux type. This is in preparation for adding a third, MMIO based, gmux type. Signed-off-by: Orlando Chamberlain --- drivers/platform/x86/apple-gmux.c | 91 ++++++++++++++++++++----------- include/linux/apple-gmux.h | 18 ++++-- 2 files changed, 70 insertions(+), 39 deletions(-) diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c index 6109f4c2867c..760434a527c1 100644 --- a/drivers/platform/x86/apple-gmux.c +++ b/drivers/platform/x86/apple-gmux.c @@ -5,6 +5,7 @@ * Copyright (C) Canonical Ltd. * Copyright (C) 2010-2012 Andreas Heider * Copyright (C) 2015 Lukas Wunner + * Copyright (C) 2023 Orlando Chamberlain */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt @@ -43,10 +44,12 @@ * http://www.renesas.com/products/mpumcu/h8s/h8s2100/h8s2113/index.jsp */ +struct apple_gmux_config; + struct apple_gmux_data { unsigned long iostart; unsigned long iolen; - bool indexed; + const struct apple_gmux_config *config; struct mutex index_lock; struct backlight_device *bdev; @@ -64,6 +67,17 @@ struct apple_gmux_data { static struct apple_gmux_data *apple_gmux_data; +struct apple_gmux_config { + u8 (*read8)(struct apple_gmux_data *gmux_data, int port); + void (*write8)(struct apple_gmux_data *gmux_data, int port, u8 val); + u32 (*read32)(struct apple_gmux_data *gmux_data, int port); + void (*write32)(struct apple_gmux_data *gmux_data, int port, u32 val); + const struct vga_switcheroo_handler *gmux_handler; + enum vga_switcheroo_handler_flags_t handler_flags; + unsigned long resource_type; + char *name; +}; + #define GMUX_INTERRUPT_ENABLE 0xff #define GMUX_INTERRUPT_DISABLE 0x00 @@ -181,35 +195,23 @@ static void gmux_index_write32(struct apple_gmux_data *gmux_data, int port, static u8 gmux_read8(struct apple_gmux_data *gmux_data, int port) { - if (gmux_data->indexed) - return gmux_index_read8(gmux_data, port); - else - return gmux_pio_read8(gmux_data, port); + return gmux_data->config->read8(gmux_data, port); } static void gmux_write8(struct apple_gmux_data *gmux_data, int port, u8 val) { - if (gmux_data->indexed) - gmux_index_write8(gmux_data, port, val); - else - gmux_pio_write8(gmux_data, port, val); + return gmux_data->config->write8(gmux_data, port, val); } static u32 gmux_read32(struct apple_gmux_data *gmux_data, int port) { - if (gmux_data->indexed) - return gmux_index_read32(gmux_data, port); - else - return gmux_pio_read32(gmux_data, port); + return gmux_data->config->read32(gmux_data, port); } static void gmux_write32(struct apple_gmux_data *gmux_data, int port, u32 val) { - if (gmux_data->indexed) - gmux_index_write32(gmux_data, port, val); - else - gmux_pio_write32(gmux_data, port, val); + return gmux_data->config->write32(gmux_data, port, val); } /** @@ -449,19 +451,41 @@ static enum vga_switcheroo_client_id gmux_get_client_id(struct pci_dev *pdev) return VGA_SWITCHEROO_DIS; } -static const struct vga_switcheroo_handler gmux_handler_indexed = { +static const struct vga_switcheroo_handler gmux_handler_no_ddc = { .switchto = gmux_switchto, .power_state = gmux_set_power_state, .get_client_id = gmux_get_client_id, }; -static const struct vga_switcheroo_handler gmux_handler_classic = { +static const struct vga_switcheroo_handler gmux_handler_ddc = { .switchto = gmux_switchto, .switch_ddc = gmux_switch_ddc, .power_state = gmux_set_power_state, .get_client_id = gmux_get_client_id, }; +static const struct apple_gmux_config apple_gmux_pio = { + .read8 = &gmux_pio_read8, + .write8 = &gmux_pio_write8, + .read32 = &gmux_pio_read32, + .write32 = &gmux_pio_write32, + .gmux_handler = &gmux_handler_ddc, + .handler_flags = VGA_SWITCHEROO_CAN_SWITCH_DDC, + .resource_type = IORESOURCE_IO, + .name = "classic" +}; + +static const struct apple_gmux_config apple_gmux_index = { + .read8 = &gmux_index_read8, + .write8 = &gmux_index_write8, + .read32 = &gmux_index_read32, + .write32 = &gmux_index_write32, + .gmux_handler = &gmux_handler_no_ddc, + .handler_flags = VGA_SWITCHEROO_NEEDS_EDP_CONFIG, + .resource_type = IORESOURCE_IO, + .name = "indexed" +}; + /** * DOC: Interrupt * @@ -551,13 +575,13 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) int ret = -ENXIO; acpi_status status; unsigned long long gpe; - bool indexed = false; + enum apple_gmux_type type; u32 version; if (apple_gmux_data) return -EBUSY; - if (!apple_gmux_detect(pnp, &indexed)) { + if (!apple_gmux_detect(pnp, &type)) { pr_info("gmux device not present\n"); return -ENODEV; } @@ -567,6 +591,16 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) return -ENOMEM; pnp_set_drvdata(pnp, gmux_data); + switch (type) { + case APPLE_GMUX_TYPE_INDEXED: + gmux_data->config = &apple_gmux_index; + mutex_init(&gmux_data->index_lock); + break; + case APPLE_GMUX_TYPE_PIO: + gmux_data->config = &apple_gmux_pio; + break; + } + res = pnp_get_resource(pnp, IORESOURCE_IO, 0); gmux_data->iostart = res->start; gmux_data->iolen = resource_size(res); @@ -577,18 +611,13 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) goto err_free; } - if (indexed) { - mutex_init(&gmux_data->index_lock); - gmux_data->indexed = true; - } - version = gmux_read32(gmux_data, GMUX_PORT_VERSION_MAJOR); ver_major = (version >> 24) & 0xff; ver_minor = (version >> 16) & 0xff; ver_release = (version >> 8) & 0xff; pr_info("Found gmux version %d.%d.%d [%s]\n", ver_major, ver_minor, - ver_release, (gmux_data->indexed ? "indexed" : "classic")); + ver_release, gmux_data->config->name); memset(&props, 0, sizeof(props)); props.type = BACKLIGHT_PLATFORM; @@ -678,12 +707,8 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) * * Pre-retina MacBook Pros can switch the panel's DDC separately. */ - if (gmux_data->indexed) - ret = vga_switcheroo_register_handler(&gmux_handler_indexed, - VGA_SWITCHEROO_NEEDS_EDP_CONFIG); - else - ret = vga_switcheroo_register_handler(&gmux_handler_classic, - VGA_SWITCHEROO_CAN_SWITCH_DDC); + ret = vga_switcheroo_register_handler(gmux_data->config->gmux_handler, + gmux_data->config->handler_flags); if (ret) { pr_err("Failed to register vga_switcheroo handler\n"); goto err_register_handler; diff --git a/include/linux/apple-gmux.h b/include/linux/apple-gmux.h index eb2caee04abd..25c1de4a716e 100644 --- a/include/linux/apple-gmux.h +++ b/include/linux/apple-gmux.h @@ -36,6 +36,11 @@ #define GMUX_MIN_IO_LEN (GMUX_PORT_BRIGHTNESS + 4) +enum apple_gmux_type { + APPLE_GMUX_TYPE_PIO, + APPLE_GMUX_TYPE_INDEXED +}; + #if IS_ENABLED(CONFIG_APPLE_GMUX) static inline bool apple_gmux_is_indexed(unsigned long iostart) { @@ -65,12 +70,12 @@ static inline bool apple_gmux_is_indexed(unsigned long iostart) * Return: %true if a supported gmux ACPI device is detected and the kernel * was configured with CONFIG_APPLE_GMUX, %false otherwise. */ -static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, bool *indexed_ret) +static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, enum apple_gmux_type *type_ret) { struct device *dev = NULL; struct acpi_device *adev; struct resource *res; - bool indexed = false; + enum apple_gmux_type type = APPLE_GMUX_TYPE_PIO; bool ret = false; if (!pnp_dev) { @@ -95,13 +100,14 @@ static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, bool *indexed_ret) * device isn't present or that it's a new one that uses indexed io. */ if (!(~inl(res->start + GMUX_PORT_VERSION_MAJOR))) { - indexed = apple_gmux_is_indexed(res->start); - if (!indexed) + if (apple_gmux_is_indexed(res->start)) + type = APPLE_GMUX_TYPE_INDEXED; + else goto out; } - if (indexed_ret) - *indexed_ret = indexed; + if (type_ret) + *type_ret = type; ret = true; out: From patchwork Fri Feb 10 04:48:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orlando Chamberlain X-Patchwork-Id: 55220 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp755879wrn; Thu, 9 Feb 2023 20:52:47 -0800 (PST) X-Google-Smtp-Source: AK7set9Nd0/t/t2MMqfb6LWk7LgGo5jz/GcE5p25ZtIKKY8Ua/pGwMj+bvOF8Om3ymECreBCLMqW X-Received: by 2002:a17:906:2603:b0:862:11f6:a082 with SMTP id h3-20020a170906260300b0086211f6a082mr13950905ejc.17.1676004767396; Thu, 09 Feb 2023 20:52:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676004767; cv=none; d=google.com; s=arc-20160816; b=pZ7+ImWiYHLYwFKQo4sHhvzy8sHO3iGgZtjplbtroQjiZF9YRATJ0rmPcXfKr/ff7+ p7U1hdp4Vy8OE3Vt2lyPiNPKbbMScjbdCBag1TVbuuJpbQO3AKv1gAfunYO7g9Wy35U+ YtDrDViSWZ+LHSW3xk8Cl6CL9YQ8OO/Nfr6h5IEVpvE+v5VNqWN8jo9J6RBME5GF0IqS SQq76MMZ7YJTmZeK+49WHcJ0EwYfx3ezI2PlCgsUunbptaPJfn1+hOKApdG9iPp0mWpJ ixPIeO4HVRyhIFpBIN7+8KPVvfCx+r9/oVrhlcPbrfPgAZxm0bvH7xGLO2/QlOTK1fq6 4H1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sE4704yMcD8OhEtSdIHgmuAh40caq0AjoSbBLrO0PpE=; b=H5Z8sqddQnamA2UostN4YBMYYwQitBZoNa0QKCKHnmD3UGyfZKI5y/sRkxhnOW9V+v cIP3n/47yDUs7au9qjn18wHC1ZYWnLY5nUjx7eLtalCsQMORQgYBQ2pNzf7XQsCqJgND z2LHQz1lJ3lfzOBgTzdofdLtV2PsjVNj5TATal90TYJtuu4YCTuveG44VqfzIbqvlbFm trE30zcOCfAm4C6XaW+aUr5iyvlMnNuyCPkpdLxtltqh++i+VPthkwLzikcp9Iq1GD4C 9Y/NjlpDLcYzkC1LipAK6KakquSb2TgVJwgmZkfYt7Mgr8cy9zQq1aDu8FGBX8aMxcIh 5qHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=B07TtWs0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d8-20020a17090692c800b008876a55dcfesi4574856ejx.87.2023.02.09.20.52.24; Thu, 09 Feb 2023 20:52:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=B07TtWs0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231274AbjBJEvX (ORCPT + 99 others); Thu, 9 Feb 2023 23:51:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231269AbjBJEvH (ORCPT ); Thu, 9 Feb 2023 23:51:07 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79BAA6E98B; Thu, 9 Feb 2023 20:50:48 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id q9so2974158pgq.5; Thu, 09 Feb 2023 20:50:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sE4704yMcD8OhEtSdIHgmuAh40caq0AjoSbBLrO0PpE=; b=B07TtWs0e5YqEoHY0pl9umYy3Y4kVoKOXCI+ufw8+ducRUqCUUMQUAurZt/rS3orVs 6dBeAs1kD/xQ+1IwMyqIuQxioJjgxJ22r6v6gOOuUdm7xjBjBfkq8rV2dSi4mSGgIlMM sVuHKT4hGDGQMumOgK84e1Ek/taIl6gUet2+h56Llgs2XE7NFMm5DhsSpn/NWYlUs3oS 5N2XN+oORiRhXrMvwPY8ZXJU7S16ovhWn9XyMZSYBSwFbbPG1V71CofozZup4QQw5fQ1 QgBa5iy3Jjn9FqZGRZlEeGcysIKlzgyZqejaCVTLgUJCFwArmizwgE/Rz9xvhjXZkDwW LUAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sE4704yMcD8OhEtSdIHgmuAh40caq0AjoSbBLrO0PpE=; b=G+jtpkSHuQ0zhLVkoBkqxEv46ni0CabhTvmunNidjlHVjfMxipPJ7HfppTWu0Qm+yk hD1knNzkqmb1ZsRAdYk7OAcC4gyJO3sg0I+U4ApAgl2YFRd/cq+YM6h+CTj9ybNneA9N R4PdLI1R9FcVEdnOOT6AQfujtYtiQviJIntFkoqSmw3WJjwePRuytOQrHjdjhlkbaxIg qffOYzVhNEthdp+jD0OzaVZ+vehZb/qM9p6+quTuH/t7CRh6oz+TS87lAa7B54271wuY 4peeE+exSRiKAPagxHbB+K2gGD5UjEOr5hLAy1ztNhg6xshro4BmCDehmFS1EViKaP8p yQFQ== X-Gm-Message-State: AO0yUKWZzP42zp/jKsLnRQiNPgj4z+YfindPbdAww6ZmJyykhekuTaYJ QphYNcMGyIvR1sdYjUOwYpAGhm61CG1jbQ== X-Received: by 2002:aa7:96c3:0:b0:581:a8dc:8f95 with SMTP id h3-20020aa796c3000000b00581a8dc8f95mr12954481pfq.12.1676004647757; Thu, 09 Feb 2023 20:50:47 -0800 (PST) Received: from localhost.localdomain ([202.53.32.211]) by smtp.gmail.com with ESMTPSA id t13-20020a62ea0d000000b0057fec210d33sm2269218pfh.152.2023.02.09.20.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 20:50:47 -0800 (PST) From: Orlando Chamberlain To: platform-driver-x86@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org Cc: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Hans de Goede , Mark Gross , Jaroslav Kysela , Takashi Iwai , Hawking Zhang , Andrey Grodzovsky , Lijo Lazar , YiPeng Chai , Somalapuram Amaranath , Mario Limonciello , Bokun Zhang , Jack Xiao , Kai Vehmanen , Pierre-Louis Bossart , Rander Wang , Ranjani Sridharan , =?utf-8?q?Amadeusz_S?= =?utf-8?q?=C5=82awi=C5=84ski?= , Yong Zhi , Evan Quan , Kerem Karabay , Aditya Garg , Aun-Ali Zaidi , Orlando Chamberlain Subject: [RFC PATCH 5/9] apple-gmux: Use GMSP acpi method for interrupt clear Date: Fri, 10 Feb 2023 15:48:22 +1100 Message-Id: <20230210044826.9834-6-orlandoch.dev@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210044826.9834-1-orlandoch.dev@gmail.com> References: <20230210044826.9834-1-orlandoch.dev@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757418375139940185?= X-GMAIL-MSGID: =?utf-8?q?1757418375139940185?= This is needed for interrupts to be cleared correctly on MMIO based gmux's. It is untested if this helps/hinders other gmux types, but I have seen the GMSP method in the acpi tables of a MacBook with an indexed gmux. If this turns out to break support for older gmux's, this can instead be only done on MMIO gmux's. There is also a "GMLV" acpi method, and the "GMSP" method can be called with 1 as its argument, but the purposes of these aren't known and they don't seem to be needed. Signed-off-by: Orlando Chamberlain --- drivers/platform/x86/apple-gmux.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c index 760434a527c1..c605f036ea0b 100644 --- a/drivers/platform/x86/apple-gmux.c +++ b/drivers/platform/x86/apple-gmux.c @@ -494,8 +494,29 @@ static const struct apple_gmux_config apple_gmux_index = { * MCP79, on all following generations it's GPIO pin 6 of the Intel PCH. * The GPE merely signals that an interrupt occurred, the actual type of event * is identified by reading a gmux register. + * + * On MMIO gmux's, we also need to call the acpi method GMSP to properly clear + * interrupts. TODO: Do other types need this? Does this break other types? */ +static int gmux_call_acpi_gmsp(struct apple_gmux_data *gmux_data, int arg) +{ + acpi_status status = AE_OK; + union acpi_object arg0 = { ACPI_TYPE_INTEGER }; + struct acpi_object_list arg_list = { 1, &arg0 }; + + arg0.integer.value = arg; + + status = acpi_evaluate_object(gmux_data->dhandle, "GMSP", &arg_list, NULL); + if (ACPI_FAILURE(status)) { + pr_err("GMSP call failed: %s\n", + acpi_format_exception(status)); + return -ENODEV; + } + + return 0; +} + static inline void gmux_disable_interrupts(struct apple_gmux_data *gmux_data) { gmux_write8(gmux_data, GMUX_PORT_INTERRUPT_ENABLE, @@ -519,7 +540,10 @@ static void gmux_clear_interrupts(struct apple_gmux_data *gmux_data) /* to clear interrupts write back current status */ status = gmux_interrupt_get_status(gmux_data); - gmux_write8(gmux_data, GMUX_PORT_INTERRUPT_STATUS, status); + if (status) { + gmux_write8(gmux_data, GMUX_PORT_INTERRUPT_STATUS, status); + gmux_call_acpi_gmsp(gmux_data, 0); + } } static void gmux_notify_handler(acpi_handle device, u32 value, void *context) From patchwork Fri Feb 10 04:48:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orlando Chamberlain X-Patchwork-Id: 55219 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp755870wrn; Thu, 9 Feb 2023 20:52:44 -0800 (PST) X-Google-Smtp-Source: AK7set/YRi8a/Au83amcJFkT18PYdi/BAyOhxnMvjeWMi8gfyzER+BrX6oRVV+ytivamHVEkQ+lX X-Received: by 2002:a17:902:dad0:b0:199:1f42:8bed with SMTP id q16-20020a170902dad000b001991f428bedmr3900687plx.12.1676004764480; Thu, 09 Feb 2023 20:52:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676004764; cv=none; d=google.com; s=arc-20160816; b=gVq3Zxcdn0rNe5ddTB+zBJ56OEEISQfV7QtZOE14MgTry25AqEDIzZbBJgertrIw2b aQikyvZsVpaEmscmZouXkfgWQ5OSDJMDdEOhT2zqMyj+1dRDICk0cMdXzI71xAodm1xj O5bkekb7rq4ANkSrTA9zUcmERslGQBKL1xnPotTHtpS3u//uDn84yXbgryzSZK2ccjRv Hex4VzdvNsPnsw9H/Tq+6wIOMkYflBspo8Nn42SuEpdKKIE3FtWMh7qnoOAENteTwsid ooeTY0pspA7kCagLWPd+2YNIjgMNSrz/dmnTVVxEyJfr4oJpMyMxi8wW936SRCMvnecV lVvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=csEKku7VeftqKMa/oZ1aoU6u0+L74zJO0Dt8b/66dVA=; b=ay8Zer6Ea6kb+4wAQJNL2vkz48dVOX+2xD2YurOOIekWUKzmdd4bSQzTm63RedzTXP u1NIA6rEfUW5iSzqiGddY2QzZVgp08F4WIbTzBQm3MWNYcZjQgb9Zknh78fheJZodVFO m/wDB2vmo4jrOsRToxqoYTSNHWbpElj357yxTqWRxL7q2lW9rnI2H1pzbRb+EwdsAZdr jNqg6YNPWkSwJXm748Hbmz5USXeP9uBoWhJQ75rbER8VkHhQ/jbQSvlCOTNx+i/h1jNu CnnjPH/hAAxaZ2hvwMxdz/L5y4zViURouoD2ZkZpvYD10uBeAeRnZBZBNVqwtXn1iWu7 WSeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bSSBBpxu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j9-20020a170902da8900b00194c90ca322si4178662plx.210.2023.02.09.20.52.31; Thu, 09 Feb 2023 20:52:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bSSBBpxu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbjBJEvh (ORCPT + 99 others); Thu, 9 Feb 2023 23:51:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231253AbjBJEvV (ORCPT ); Thu, 9 Feb 2023 23:51:21 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C27777161; Thu, 9 Feb 2023 20:50:58 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id 78so2965228pgb.8; Thu, 09 Feb 2023 20:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=csEKku7VeftqKMa/oZ1aoU6u0+L74zJO0Dt8b/66dVA=; b=bSSBBpxuvLfNjDZVjz2+AmmgvNUi2UbO+qebR9jIEeWWG+ugnaK53p6mQpKFqVYTgh iuXQ4Y9y0HhXStihsMX1+bZmICz5JbJdj3Y5RDYwvHd0Fvm4BpohBTo0+84VXZE3pNkJ nHj3jMdQ2ECfz5zkBQU+zZ3Ou5aDNBg3gocOMdRkFgPV5bhYgSG4gvzu93r5S6Dh3JOb tLAJgLetD5xYT4Q8PSDp7jNYdLB5EoV7IW4Gq2iVdsp9WjCgK5g+crXN5OaIjS/YWKOv swXVeyoRy+mQbFKKCf26aGILb+pL93OyQTh9/2z5UaawmtNzWkhbwVdkID9qJ/kh2j6p N03Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=csEKku7VeftqKMa/oZ1aoU6u0+L74zJO0Dt8b/66dVA=; b=jb/9TBfRokH3vbPmHj1suLCvfLGwrd6TndvzqXslbcD46VVXSapt7EAzXN63QI2vGN 0pldOiQhXG2NplVAuieGUXvFV5ZyM+NzIYVTIq3P8vVcs5kqzWRsW4fq0o3bI4pSRZpm /gKxVtwe0sQJm+uZHzIQdEtVKBMFePLvwOCcVsrh9aawGHaeNdvkaWFfn/cJALng/kY2 S8D4G5zf6LHJ/wW+dgoHa4TZJ328Ikgs+i0RUeSBp3LyNaH4ayEHIQnWdk/ER9l3G5t9 PYFs1atI7UsuSf7xgt4S9WG0esZ2Z5PqVUGnakpM/+mL6L2WCGbcmwLfzcRwAkpC/1u/ pdYg== X-Gm-Message-State: AO0yUKVitpbkxIUgbmrnb5ZIfZp/iHH5tw00MQ5WeYJh/29O5Afv+oC6 TsAa/nAqs5wbB++v2k5fp8E/32FxxiSIPA== X-Received: by 2002:a62:2782:0:b0:5a8:16b7:ce6e with SMTP id n124-20020a622782000000b005a816b7ce6emr2853223pfn.10.1676004657775; Thu, 09 Feb 2023 20:50:57 -0800 (PST) Received: from localhost.localdomain ([202.53.32.211]) by smtp.gmail.com with ESMTPSA id t13-20020a62ea0d000000b0057fec210d33sm2269218pfh.152.2023.02.09.20.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 20:50:57 -0800 (PST) From: Orlando Chamberlain To: platform-driver-x86@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org Cc: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Hans de Goede , Mark Gross , Jaroslav Kysela , Takashi Iwai , Hawking Zhang , Andrey Grodzovsky , Lijo Lazar , YiPeng Chai , Somalapuram Amaranath , Mario Limonciello , Bokun Zhang , Jack Xiao , Kai Vehmanen , Pierre-Louis Bossart , Rander Wang , Ranjani Sridharan , =?utf-8?q?Amadeusz_S?= =?utf-8?q?=C5=82awi=C5=84ski?= , Yong Zhi , Evan Quan , Kerem Karabay , Aditya Garg , Aun-Ali Zaidi , Orlando Chamberlain Subject: [RFC PATCH 6/9] apple-gmux: support MMIO gmux on T2 Macs Date: Fri, 10 Feb 2023 15:48:23 +1100 Message-Id: <20230210044826.9834-7-orlandoch.dev@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210044826.9834-1-orlandoch.dev@gmail.com> References: <20230210044826.9834-1-orlandoch.dev@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757418371747834767?= X-GMAIL-MSGID: =?utf-8?q?1757418371747834767?= In some newer dual gpu MacBooks, gmux is controlled by the T2 security chip, and acessed with MMIO. Add support for these gmux controllers Interestingly, the ACPI table only allocates 8 bytes for GMUX, but we actually need 16, and as such we request 16 with request_mem_region. Reading and writing from ports: 16 bytes from 0xfe0b0200 are used. 0x0 to 0x4 are where data to read appears, and where data to write goes. Writing to 0xe sets the gmux port being accessed, and writing to 0xf sends commands. These commands are 0x40 & data_length for write, and data_length for read, where data_length is 1, 2 or 4. Once byte base+0xf is 0, the command is done. Interrupts: Clearing interrupts on T2 macs seems different to older models, 0 has to be written for them to stop, but this isn't what macOS does and further investigation may be needed. Issues: As with other retina models, we can't switch DDC lines so switching at runtime doesn't work if the inactive gpu driver already disabled eDP due to it not being connected when that driver loaded. Additionally, turning on the dgpu back on T2 macs doesn't work, and it fails in amdgpu's code for bringing the gpu back online. Signed-off-by: Orlando Chamberlain --- drivers/platform/x86/apple-gmux.c | 134 ++++++++++++++++++++++++++++-- include/linux/apple-gmux.h | 34 +++++--- 2 files changed, 149 insertions(+), 19 deletions(-) diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c index c605f036ea0b..c38d6ef0c15a 100644 --- a/drivers/platform/x86/apple-gmux.c +++ b/drivers/platform/x86/apple-gmux.c @@ -28,15 +28,17 @@ * DOC: Overview * * gmux is a microcontroller built into the MacBook Pro to support dual GPUs: - * A `Lattice XP2`_ on pre-retinas, a `Renesas R4F2113`_ on retinas. + * A `Lattice XP2`_ on pre-retinas, a `Renesas R4F2113`_ on pre-T2 retinas. + * The chip used on T2 Macs is not known. * * (The MacPro6,1 2013 also has a gmux, however it is unclear why since it has * dual GPUs but no built-in display.) * * gmux is connected to the LPC bus of the southbridge. Its I/O ports are * accessed differently depending on the microcontroller: Driver functions - * to access a pre-retina gmux are infixed ``_pio_``, those for a retina gmux - * are infixed ``_index_``. + * to access a pre-retina gmux are infixed ``_pio_``, those for a pre-T2 + * retina gmux are infixed ``_index_``, and those on T2 Macs are infixed + * with ``_mmio_``. * * .. _Lattice XP2: * http://www.latticesemi.com/en/Products/FPGAandCPLD/LatticeXP2.aspx @@ -47,6 +49,7 @@ struct apple_gmux_config; struct apple_gmux_data { + u8 *__iomem iomem_base; unsigned long iostart; unsigned long iolen; const struct apple_gmux_config *config; @@ -193,6 +196,79 @@ static void gmux_index_write32(struct apple_gmux_data *gmux_data, int port, mutex_unlock(&gmux_data->index_lock); } +static int gmux_mmio_wait(struct apple_gmux_data *gmux_data) +{ + int i = 200; + u8 gwr = ioread8(gmux_data->iomem_base + GMUX_MMIO_COMMAND_SEND); + + while (i && gwr) { + gwr = ioread8(gmux_data->iomem_base + GMUX_MMIO_COMMAND_SEND); + udelay(100); + i--; + } + + return !!i; +} + +static u8 gmux_mmio_read8(struct apple_gmux_data *gmux_data, int port) +{ + u8 val; + + mutex_lock(&gmux_data->index_lock); + gmux_mmio_wait(gmux_data); + iowrite8((port & 0xff), gmux_data->iomem_base + GMUX_MMIO_PORT_SELECT); + iowrite8(GMUX_MMIO_READ | sizeof(val), + gmux_data->iomem_base + GMUX_MMIO_COMMAND_SEND); + gmux_mmio_wait(gmux_data); + val = ioread8(gmux_data->iomem_base); + mutex_unlock(&gmux_data->index_lock); + + return val; +} + +static void gmux_mmio_write8(struct apple_gmux_data *gmux_data, int port, + u8 val) +{ + mutex_lock(&gmux_data->index_lock); + gmux_mmio_wait(gmux_data); + iowrite8(val, gmux_data->iomem_base); + + iowrite8(port & 0xff, gmux_data->iomem_base + GMUX_MMIO_PORT_SELECT); + iowrite8(GMUX_MMIO_WRITE | sizeof(val), + gmux_data->iomem_base + GMUX_MMIO_COMMAND_SEND); + + gmux_mmio_wait(gmux_data); + mutex_unlock(&gmux_data->index_lock); +} + +static u32 gmux_mmio_read32(struct apple_gmux_data *gmux_data, int port) +{ + u32 val; + + mutex_lock(&gmux_data->index_lock); + gmux_mmio_wait(gmux_data); + iowrite8((port & 0xff), gmux_data->iomem_base + GMUX_MMIO_PORT_SELECT); + iowrite8(GMUX_MMIO_READ | sizeof(val), + gmux_data->iomem_base + GMUX_MMIO_COMMAND_SEND); + gmux_mmio_wait(gmux_data); + val = be32_to_cpu(ioread32(gmux_data->iomem_base)); + mutex_unlock(&gmux_data->index_lock); + + return val; +} + +static void gmux_mmio_write32(struct apple_gmux_data *gmux_data, int port, + u32 val) +{ + mutex_lock(&gmux_data->index_lock); + iowrite32(cpu_to_be32(val), gmux_data->iomem_base); + iowrite8(port & 0xff, gmux_data->iomem_base + GMUX_MMIO_PORT_SELECT); + iowrite8(GMUX_MMIO_WRITE | sizeof(val), + gmux_data->iomem_base + GMUX_MMIO_COMMAND_SEND); + gmux_mmio_wait(gmux_data); + mutex_unlock(&gmux_data->index_lock); +} + static u8 gmux_read8(struct apple_gmux_data *gmux_data, int port) { return gmux_data->config->read8(gmux_data, port); @@ -486,6 +562,18 @@ static const struct apple_gmux_config apple_gmux_index = { .name = "indexed" }; +static const struct apple_gmux_config apple_gmux_mmio = { + .read8 = &gmux_mmio_read8, + .write8 = &gmux_mmio_write8, + .read32 = &gmux_mmio_read32, + .write32 = &gmux_mmio_write32, + .gmux_handler = &gmux_handler_no_ddc, + .handler_flags = VGA_SWITCHEROO_NEEDS_EDP_CONFIG, + .resource_type = IORESOURCE_MEM, + .name = "T2" +}; + + /** * DOC: Interrupt * @@ -538,7 +626,7 @@ static void gmux_clear_interrupts(struct apple_gmux_data *gmux_data) { u8 status; - /* to clear interrupts write back current status */ + /* to clear interrupts write back current status. */ status = gmux_interrupt_get_status(gmux_data); if (status) { gmux_write8(gmux_data, GMUX_PORT_INTERRUPT_STATUS, status); @@ -616,6 +704,25 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) pnp_set_drvdata(pnp, gmux_data); switch (type) { + case APPLE_GMUX_TYPE_MMIO: + gmux_data->config = &apple_gmux_mmio; + mutex_init(&gmux_data->index_lock); + + res = pnp_get_resource(pnp, IORESOURCE_MEM, 0); + gmux_data->iostart = res->start; + /* Although the ACPI table only allocates 8 bytes, we need 16. */ + gmux_data->iolen = 16; + if (!request_mem_region(gmux_data->iostart, gmux_data->iolen, + "Apple gmux")) { + pr_err("gmux I/O already in use\n"); + goto err_free; + } + gmux_data->iomem_base = ioremap(gmux_data->iostart, gmux_data->iolen); + if (!gmux_data->iomem_base) { + pr_err("couldn't remap gmux mmio region"); + goto err_release; + } + goto get_version; case APPLE_GMUX_TYPE_INDEXED: gmux_data->config = &apple_gmux_index; mutex_init(&gmux_data->index_lock); @@ -635,6 +742,7 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) goto err_free; } +get_version: version = gmux_read32(gmux_data, GMUX_PORT_VERSION_MAJOR); ver_major = (version >> 24) & 0xff; ver_minor = (version >> 16) & 0xff; @@ -660,7 +768,7 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) gmux_data, &gmux_bl_ops, &props); if (IS_ERR(bdev)) { ret = PTR_ERR(bdev); - goto err_release; + goto err_unmap; } gmux_data->bdev = bdev; @@ -727,7 +835,7 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) /* * Retina MacBook Pros cannot switch the panel's AUX separately * and need eDP pre-calibration. They are distinguishable from - * pre-retinas by having an "indexed" gmux. + * pre-retinas by having an "indexed" or "T2" gmux. * * Pre-retina MacBook Pros can switch the panel's DDC separately. */ @@ -752,8 +860,14 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) &gmux_notify_handler); err_notify: backlight_device_unregister(bdev); +err_unmap: + if (gmux_data->iomem_base) + iounmap(gmux_data->iomem_base); err_release: - release_region(gmux_data->iostart, gmux_data->iolen); + if (gmux_data->config->resource_type == IORESOURCE_MEM) + release_mem_region(gmux_data->iostart, gmux_data->iolen); + else + release_region(gmux_data->iostart, gmux_data->iolen); err_free: kfree(gmux_data); return ret; @@ -774,7 +888,11 @@ static void gmux_remove(struct pnp_dev *pnp) backlight_device_unregister(gmux_data->bdev); - release_region(gmux_data->iostart, gmux_data->iolen); + if (gmux_data->iomem_base) { + iounmap(gmux_data->iomem_base); + release_mem_region(gmux_data->iostart, gmux_data->iolen); + } else + release_region(gmux_data->iostart, gmux_data->iolen); apple_gmux_data = NULL; kfree(gmux_data); diff --git a/include/linux/apple-gmux.h b/include/linux/apple-gmux.h index 25c1de4a716e..55b18f0f320d 100644 --- a/include/linux/apple-gmux.h +++ b/include/linux/apple-gmux.h @@ -34,11 +34,18 @@ #define GMUX_PORT_READ 0xd0 #define GMUX_PORT_WRITE 0xd4 +#define GMUX_MMIO_PORT_SELECT 0x0e +#define GMUX_MMIO_COMMAND_SEND 0x0f + +#define GMUX_MMIO_READ 0x00 +#define GMUX_MMIO_WRITE 0x40 + #define GMUX_MIN_IO_LEN (GMUX_PORT_BRIGHTNESS + 4) enum apple_gmux_type { APPLE_GMUX_TYPE_PIO, - APPLE_GMUX_TYPE_INDEXED + APPLE_GMUX_TYPE_INDEXED, + APPLE_GMUX_TYPE_MMIO }; #if IS_ENABLED(CONFIG_APPLE_GMUX) @@ -92,16 +99,21 @@ static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, enum apple_gmux_ty } res = pnp_get_resource(pnp_dev, IORESOURCE_IO, 0); - if (!res || resource_size(res) < GMUX_MIN_IO_LEN) - goto out; - - /* - * Invalid version information may indicate either that the gmux - * device isn't present or that it's a new one that uses indexed io. - */ - if (!(~inl(res->start + GMUX_PORT_VERSION_MAJOR))) { - if (apple_gmux_is_indexed(res->start)) - type = APPLE_GMUX_TYPE_INDEXED; + if (res && resource_size(res) >= GMUX_MIN_IO_LEN) { + /* + * Invalid version information may indicate either that the gmux + * device isn't present or that it's a new one that uses indexed io. + */ + if (!(~inl(res->start + GMUX_PORT_VERSION_MAJOR))) { + if (apple_gmux_is_indexed(res->start)) + type = APPLE_GMUX_TYPE_INDEXED; + else + goto out; + } + } else { + res = pnp_get_resource(pnp_dev, IORESOURCE_MEM, 0); + if (res) + type = APPLE_GMUX_TYPE_MMIO; else goto out; } From patchwork Fri Feb 10 04:48:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orlando Chamberlain X-Patchwork-Id: 55223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp756343wrn; Thu, 9 Feb 2023 20:54:25 -0800 (PST) X-Google-Smtp-Source: AK7set+VWqiaDea0aiem0NgPesEnQabD2fczjGEmRyKkeybzdU9lXnUVA7R5hhNTECLqmphq9g/S X-Received: by 2002:a17:902:e383:b0:19a:703d:c1c6 with SMTP id g3-20020a170902e38300b0019a703dc1c6mr1144660ple.26.1676004865645; Thu, 09 Feb 2023 20:54:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676004865; cv=none; d=google.com; s=arc-20160816; b=EOBJfp98z9It11J9ouWnDPTGGEkOq9HYFgpZSXYLPis65gSphwMEYI/Fhn6T2erVlm IAVzpUuuWlZZxnqmapT7bZymOcUeS+fI1idl7ZkzvrO7TvutLPBbEw4iDN4K04c+E+Og bL0tlTWfNUg4njNYCWhNMWO3w5oH5IFfTUWf6t+UsVZYD5vbSMBX9h80vgzBzXsaAybj lOie46rBC9HWYIzVx1/oo7Haz2Umn8lptMxKj5UqJU+0+tYhhlu3iFiKVctAQd8qhU+b nZtP6A+TEii5AemouDyGz5tVuZpOel4JB7RUtzJJ9oCzVSpSMsjVeowx9+VLdDvcCcz7 PSVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tEls10WodkspsIvZIvxa4LCxo5R1yCy5xPl31tNRCfY=; b=NpWgGf25QCoPyHJgx9j7a+5oTexDctLBQqrUpiYe5y+DqpjqJjcdC2r5r7reKjyOd2 PceGjlhlsBAYmQc06KFkQKawBoUaZOPOoC7reLqSywNfahWQJv1Nrn1QxQdzok2jny3e YebQclnvFcKfhzlqfe7hM16K/9DF7j2c0jWA5MwWl3GpHCzJodgEJqg85sckGKWuNjOX EdOlR3jrnpDxv+D+2S6oPB2pm3DzMh0UZVnJx7Dbve4RWlzrEU98PFhz/xdFqz1oEt0O 9J8IQ7rBq0kLSeG/TTpYOOXe1X3rw5os9lwjy0uNYsFKwfG8lcr+ix9ecN3d6hBGKpM/ Bx4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AI5OkR5n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y11-20020a170902cacb00b0019a5f479dbfsi2759912pld.567.2023.02.09.20.54.13; Thu, 09 Feb 2023 20:54:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AI5OkR5n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231225AbjBJEv4 (ORCPT + 99 others); Thu, 9 Feb 2023 23:51:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231322AbjBJEve (ORCPT ); Thu, 9 Feb 2023 23:51:34 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CF0477164; Thu, 9 Feb 2023 20:51:08 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id s20so2770596pfe.2; Thu, 09 Feb 2023 20:51:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tEls10WodkspsIvZIvxa4LCxo5R1yCy5xPl31tNRCfY=; b=AI5OkR5ngOdIYwA82Bd2NHyMJ+O2BLu1AlHUiAUk5u2mES8050ILPnIi34V/HwnVmn UCnnl/NNHpnSFBN3X0R580Y09W5YGDjQXorCqi2JWHAwRM3mAVXKAyPB7q7B66d3DoWt zBvfn3AmAyRezdi5kNYRSaoRxCZe3u4hC11prURWNE0PK6ZNCw5117fr7UHA3ZhhHI6z ua9y3dmza6fdLajFD3iCgQy+ca3vadxm1QgxmG6b53N46lfItM+tP6BzFu/BuB6LbEC1 2TmnClABN6Fxc12v6c0kbWm8LL7Al2NDRYIr/vhwsP9jpjc8vOPXdePVWan8RRrIxgG1 ma/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tEls10WodkspsIvZIvxa4LCxo5R1yCy5xPl31tNRCfY=; b=lmJb34hiHE2MKpge1IHUKV2tS1XFwb8bxosbiT2J896tS7T4k1U1wPr3Bf+6Lr/v13 ajnq0VRLQP4Bkjnt4+ZgptsUptt1Uv748xgPMoPuWTonR+N6ntFNtVGXnkhV2NYzG6tf UPidFvVoer+ubY3u08cInx1573NX4KheBnSlyM6jgJiBm1EGg5je6X7RR3eAxo1A+lAp fSK5ReSVZZQNT6vQCcbY+CUp0bBShk6XhIcTWn2buGbR81l/UQm3oHRRiB4p84og0z4w RowDodSQ9l/6YqRtn6g13hXB89guG2iuJn4sJKwbtbLydC9ZisXXEy3om50TohOAUxfM abzw== X-Gm-Message-State: AO0yUKXbl0X9D01G7bu97r1DTU0rHQ4dyvDn3JUm2ZdS5mnQg7UrsrzJ e9EM2exKXpZPS8baTKcQsp4LYv9XdxQigg== X-Received: by 2002:a62:15d3:0:b0:5a8:4db3:266e with SMTP id 202-20020a6215d3000000b005a84db3266emr3828885pfv.10.1676004667360; Thu, 09 Feb 2023 20:51:07 -0800 (PST) Received: from localhost.localdomain ([202.53.32.211]) by smtp.gmail.com with ESMTPSA id t13-20020a62ea0d000000b0057fec210d33sm2269218pfh.152.2023.02.09.20.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 20:51:07 -0800 (PST) From: Orlando Chamberlain To: platform-driver-x86@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org Cc: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Hans de Goede , Mark Gross , Jaroslav Kysela , Takashi Iwai , Hawking Zhang , Andrey Grodzovsky , Lijo Lazar , YiPeng Chai , Somalapuram Amaranath , Mario Limonciello , Bokun Zhang , Jack Xiao , Kai Vehmanen , Pierre-Louis Bossart , Rander Wang , Ranjani Sridharan , =?utf-8?q?Amadeusz_S?= =?utf-8?q?=C5=82awi=C5=84ski?= , Yong Zhi , Evan Quan , Kerem Karabay , Aditya Garg , Aun-Ali Zaidi , Orlando Chamberlain Subject: [RFC PATCH 7/9] apple-gmux: add sysfs interface Date: Fri, 10 Feb 2023 15:48:24 +1100 Message-Id: <20230210044826.9834-8-orlandoch.dev@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210044826.9834-1-orlandoch.dev@gmail.com> References: <20230210044826.9834-1-orlandoch.dev@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757418477943310994?= X-GMAIL-MSGID: =?utf-8?q?1757418477943310994?= Allow reading gmux ports from userspace. When the unsafe module parameter allow_user_writes is true, writing 1 byte values is also allowed. For example: cd /sys/bus/acpi/devices/APP000B:00/physical_node/ echo 4 > gmux_selected_port cat gmux_selected_port_data | xxd -p Will show the gmux version information (00000005 in this case) Signed-off-by: Orlando Chamberlain --- drivers/platform/x86/apple-gmux.c | 129 ++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c index c38d6ef0c15a..756059d48393 100644 --- a/drivers/platform/x86/apple-gmux.c +++ b/drivers/platform/x86/apple-gmux.c @@ -66,6 +66,11 @@ struct apple_gmux_data { enum vga_switcheroo_client_id switch_state_external; enum vga_switcheroo_state power_state; struct completion powerchange_done; + +#ifdef CONFIG_SYSFS + /* sysfs data */ + int selected_port; +#endif /* CONFIG_SYSFS */ }; static struct apple_gmux_data *apple_gmux_data; @@ -651,6 +656,121 @@ static void gmux_notify_handler(acpi_handle device, u32 value, void *context) complete(&gmux_data->powerchange_done); } +/** + * DOC: Sysfs Interface + * + * gmux ports can be read from userspace as a sysfs interface. For example: + * + * # echo 4 > /sys/bus/acpi/devices/APP000B:00/physical_node/gmux_selected_port + * # cat /sys/bus/acpi/devices/APP000B:00/physical_node/gmux_selected_port_data | xxd -p + * 00000005 + * + * Reads 4 bytes from port 4 (GMUX_PORT_VERSION_MAJOR). + * + * Single byte writes are also supported, however this must be enabled with the + * unsafe allow_user_writes module parameter. + * + */ + +#ifdef CONFIG_SYSFS + +static bool allow_user_writes; +module_param_unsafe(allow_user_writes, bool, 0); +MODULE_PARM_DESC(allow_user_writes, "Allow userspace to write to gmux ports (default: false) (bool)"); + +static ssize_t gmux_selected_port_store(struct device *dev, + struct device_attribute *attr, const char *sysfsbuf, size_t count) +{ + struct apple_gmux_data *gmux_data = dev_get_drvdata(dev); + u8 port; + + if (kstrtou8(sysfsbuf, 10, &port) < 0) + return -EINVAL; + + /* On pio gmux's, make sure the user doesn't access too high of a port. */ + if ((gmux_data->config == &apple_gmux_pio) && + port > (gmux_data->iolen - 4)) + return -EINVAL; + + gmux_data->selected_port = port; + return count; +} + +static ssize_t gmux_selected_port_show(struct device *dev, + struct device_attribute *attr, char *sysfsbuf) +{ + struct apple_gmux_data *gmux_data = dev_get_drvdata(dev); + + return sysfs_emit(sysfsbuf, "%d\n", gmux_data->selected_port); +} + +DEVICE_ATTR_RW(gmux_selected_port); + +static ssize_t gmux_selected_port_data_store(struct device *dev, + struct device_attribute *attr, const char *sysfsbuf, size_t count) +{ + struct apple_gmux_data *gmux_data = dev_get_drvdata(dev); + + if (count == 1) + gmux_write8(gmux_data, gmux_data->selected_port, *sysfsbuf); + else + return -EINVAL; + + return count; +} + +static ssize_t gmux_selected_port_data_show(struct device *dev, + struct device_attribute *attr, char *sysfsbuf) +{ + struct apple_gmux_data *gmux_data = dev_get_drvdata(dev); + u32 data; + + data = gmux_read32(gmux_data, gmux_data->selected_port); + memcpy(sysfsbuf, &data, sizeof(data)); + + return sizeof(data); +} + +struct device_attribute dev_attr_gmux_selected_port_data_rw = __ATTR_RW(gmux_selected_port_data); +struct device_attribute dev_attr_gmux_selected_port_data_ro = __ATTR_RO(gmux_selected_port_data); + +static int gmux_init_sysfs(struct pnp_dev *pnp) +{ + int ret; + + ret = device_create_file(&pnp->dev, &dev_attr_gmux_selected_port); + if (ret) + return ret; + if (allow_user_writes) + ret = device_create_file(&pnp->dev, &dev_attr_gmux_selected_port_data_rw); + else + ret = device_create_file(&pnp->dev, &dev_attr_gmux_selected_port_data_ro); + if (ret) + device_remove_file(&pnp->dev, &dev_attr_gmux_selected_port); + return ret; +} + +static void gmux_fini_sysfs(struct pnp_dev *pnp) +{ + device_remove_file(&pnp->dev, &dev_attr_gmux_selected_port); + if (allow_user_writes) + device_remove_file(&pnp->dev, &dev_attr_gmux_selected_port_data_rw); + else + device_remove_file(&pnp->dev, &dev_attr_gmux_selected_port_data_ro); +} + +#else + +static int gmux_init_sysfs(struct pnp_dev *pnp) +{ + return 0; +} +static void gmux_fini_sysfs(struct pnp_dev *pnp) +{ +} + +#endif /* CONFIG_SYSFS */ + static int gmux_suspend(struct device *dev) { struct pnp_dev *pnp = to_pnp_dev(dev); @@ -846,8 +966,16 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) goto err_register_handler; } + ret = gmux_init_sysfs(pnp); + if (ret) { + pr_err("Failed to register gmux sysfs entries\n"); + goto err_sysfs; + } + return 0; +err_sysfs: + vga_switcheroo_unregister_handler(); err_register_handler: gmux_disable_interrupts(gmux_data); apple_gmux_data = NULL; @@ -877,6 +1005,7 @@ static void gmux_remove(struct pnp_dev *pnp) { struct apple_gmux_data *gmux_data = pnp_get_drvdata(pnp); + gmux_fini_sysfs(pnp); vga_switcheroo_unregister_handler(); gmux_disable_interrupts(gmux_data); if (gmux_data->gpe >= 0) { From patchwork Fri Feb 10 04:48:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orlando Chamberlain X-Patchwork-Id: 55222 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp756304wrn; Thu, 9 Feb 2023 20:54:19 -0800 (PST) X-Google-Smtp-Source: AK7set+OHOCO/hVLtxXeA2yS4TaY2xsnVcX/aMsVd2g4quMR4HHo193IwzY+vyS2sPhU3dIEA1qO X-Received: by 2002:a62:64d1:0:b0:5a8:6463:8f77 with SMTP id y200-20020a6264d1000000b005a864638f77mr2595710pfb.11.1676004859006; Thu, 09 Feb 2023 20:54:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676004858; cv=none; d=google.com; s=arc-20160816; b=XiE4JPBHquFrqIAmMmGqrSdzSf58YPHTU3J7CxG67z8ieApNb2XRfeZZVWdiOgqb+z 0zGdhes4nqNS2ys8LONyKXgF14NAwJWtQvXJNGILqNIFfLMbSc/B5jzSEMwgxafs47HE j7b/6r/x4nH2pKyYc868SQfWvNLpXaKNpj4krFbtiwX3gmIfxeT41aXiEYMQ7aDFe574 ikpSP5Qr2rQczK2TCEqlSHyS0kBrtu6LQvdZPNsSpNzWA+cjGJ4/ZPaTEcVbre4dPeHl EZ3AR+iR9U95pr/IpKRRdgZ7F+eoUfGeDKv8dlJ97KxzeAHR7sJc4a0qj+LeYSK0FyaP BkWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Y5Ha95DZYK/aP/j52BgmRVv3D+Ht1XBi+RBwbRpPJAA=; b=RTBiSd8I+hG8IDYUCGli9rp1E0gWGvQli6C3VDQhyUCFUVB4n9qAT+A3RJYPmzSq7J Dp5pvIgtjqJvHE+l8Lrx5VZ0FA3Ye5XfOYl7cR6sbnHYFCsBx6iQmGGDXV9HyOy+xwDA bMhOxodL0DJLLCYCPm5T8hS45SELv3MhOcInvWSXKZhoEyoxOgTshR58CDsf50MfBxFJ MfNUmAKiZQ2YIELSFHpWM40UttakvVPG80FMTCBsQpV0pqPYmRJLuN5KBv5tizC6kGfO 5oOBo7ISLlnj7+TSmzrweas2c9TzjCpK8bG7PDcpRadlP9pauOJ4cfzbGvqS+qKapHCm AIsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jeRCbikd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y6-20020aa79e06000000b0059392b3b758si4008409pfq.54.2023.02.09.20.54.06; Thu, 09 Feb 2023 20:54:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jeRCbikd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231356AbjBJEwO (ORCPT + 99 others); Thu, 9 Feb 2023 23:52:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231357AbjBJEvu (ORCPT ); Thu, 9 Feb 2023 23:51:50 -0500 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3A6477159; Thu, 9 Feb 2023 20:51:17 -0800 (PST) Received: by mail-pg1-x529.google.com with SMTP id n3so2959119pgr.9; Thu, 09 Feb 2023 20:51:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y5Ha95DZYK/aP/j52BgmRVv3D+Ht1XBi+RBwbRpPJAA=; b=jeRCbikd0l+NYcX61eSocwQ1WUxxnAWy9jXktGeo2f1Ks/WWMN6X5HONHK7QeGRFVt iOUduMbJJxxI+2VxjAve5WkgVa4Z8HQaJBB2RcPWhn9YEPeT1sC2wS0FJVXrcYX9rxuA Tn6jmBhZ2gZC8wfNCWtA8AtXpd5hbTGVhN/DYmqHGTf0a4gt1sTPPQUBMAzsmYB0YX+I d8Ee/B6UJqkuoQgF6ommsJa/FZIrubLdFKhd1po/LM+Zq0QPNY35bBSY9MRxn9TiBdWW TaE0Dw6cX55x7gagXpw485WSPfiwCzg6t2bL883xOej+5KbppjICobrr2oOeAvOAbz6C exQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y5Ha95DZYK/aP/j52BgmRVv3D+Ht1XBi+RBwbRpPJAA=; b=usGtuKZsa4Ixfe4xZQzeREsVXjLN7FwFW7KV65pIIea9JrcCY8d4IflSRD00jyyNUK yh6SmjaxXmHHbih2UIZNVnWBpqb+7fvEiP0ptS2SYJLSY2aFxRpnMIyjjgcUTsOwFfZ+ JVmkM1Dyw65mOHmgi2/0thlaWJ5ow13csLio8qEtUqjcFt/sWOyLb7mMfmq/NADn3MgC GoR7fcTV31S9iwF13c1uzxZ6zK8NkWysXmuQzUwYZufWgG8bAnK9RJFInzJlvWAorfkV wSnGitMmj8wP2B0scjPqZRO4wPVWY0XLMk2XLZOZG9NkxeInrQvn13rTMpJCdgBlMnEF t1tg== X-Gm-Message-State: AO0yUKWZAQPWAhnVzPvXH0NQ/5MFczZotngzI2GkOZVpH7E1VozHa+o4 XGlTkrIkRmPqc7pUQ+MfKKmyCHjxguihdg== X-Received: by 2002:a62:6d85:0:b0:590:7616:41eb with SMTP id i127-20020a626d85000000b00590761641ebmr10365952pfc.30.1676004676892; Thu, 09 Feb 2023 20:51:16 -0800 (PST) Received: from localhost.localdomain ([202.53.32.211]) by smtp.gmail.com with ESMTPSA id t13-20020a62ea0d000000b0057fec210d33sm2269218pfh.152.2023.02.09.20.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 20:51:16 -0800 (PST) From: Orlando Chamberlain To: platform-driver-x86@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org Cc: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Hans de Goede , Mark Gross , Jaroslav Kysela , Takashi Iwai , Hawking Zhang , Andrey Grodzovsky , Lijo Lazar , YiPeng Chai , Somalapuram Amaranath , Mario Limonciello , Bokun Zhang , Jack Xiao , Kai Vehmanen , Pierre-Louis Bossart , Rander Wang , Ranjani Sridharan , =?utf-8?q?Amadeusz_S?= =?utf-8?q?=C5=82awi=C5=84ski?= , Yong Zhi , Evan Quan , Kerem Karabay , Aditya Garg , Aun-Ali Zaidi , Orlando Chamberlain Subject: [RFC PATCH 8/9] hda/hdmi: Register with vga_switcheroo on Dual GPU Macbooks Date: Fri, 10 Feb 2023 15:48:25 +1100 Message-Id: <20230210044826.9834-9-orlandoch.dev@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210044826.9834-1-orlandoch.dev@gmail.com> References: <20230210044826.9834-1-orlandoch.dev@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757418471341384239?= X-GMAIL-MSGID: =?utf-8?q?1757418471341384239?= Commit 586bc4aab878 ("ALSA: hda/hdmi - fix vgaswitcheroo detection for AMD") caused only AMD gpu's with PX to have their audio component register with vga_switcheroo. This meant that Apple Macbooks with apple-gmux as the gpu switcher no longer had the audio client registering, so when the gpu is powered off by vga_switcheroo snd_hda_intel is unaware that it should have suspended the device: amdgpu: switched off snd_hda_intel 0000:03:00.1: Unable to change power state from D3hot to D0, device inaccessible snd_hda_intel 0000:03:00.1: CORB reset timeout#2, CORBRP = 65535 Simialar to ATPX, we use the presence of an acpi method (PWRD in this case) to ensure we only register with the correct devices. Fixes: 586bc4aab878 ("ALSA: hda/hdmi - fix vgaswitcheroo detection for AMD") Signed-off-by: Orlando Chamberlain --- sound/pci/hda/hda_intel.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 87002670c0c9..c97bbe60e603 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1435,11 +1435,25 @@ static bool atpx_present(void) } return false; } + +static bool pwrd_present(struct pci_dev *pci) +{ + acpi_handle pwrd_handle; + acpi_status status; + + status = acpi_get_handle(ACPI_HANDLE(&pci->dev), "PWRD", &pwrd_handle); + return ACPI_FAILURE(status) ? false : true; +} #else static bool atpx_present(void) { return false; } + +static bool pwrd_present(struct pci_dev *pci) +{ + return false; +} #endif /* @@ -1461,9 +1475,12 @@ static struct pci_dev *get_bound_vga(struct pci_dev *pci) * rather than the dGPU's namespace. However, * the dGPU is the one who is involved in * vgaswitcheroo. + * + * PWRD is in the dGPU's ACPI namespace on Apple + * Macbooks with dual gpu's. */ if (((p->class >> 16) == PCI_BASE_CLASS_DISPLAY) && - atpx_present()) + (atpx_present() || pwrd_present(p))) return p; pci_dev_put(p); } From patchwork Fri Feb 10 04:48:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orlando Chamberlain X-Patchwork-Id: 55224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp757398wrn; Thu, 9 Feb 2023 20:57:50 -0800 (PST) X-Google-Smtp-Source: AK7set+C1oHBojhx7mS3zYboXeED2RjWMTi8WDjenTtx3/yM09F2cBzfPX6dVlFsRSRYyBn7ISHa X-Received: by 2002:aa7:9ac2:0:b0:5a7:6ee6:66f9 with SMTP id x2-20020aa79ac2000000b005a76ee666f9mr12635050pfp.19.1676005070168; Thu, 09 Feb 2023 20:57:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676005070; cv=none; d=google.com; s=arc-20160816; b=s1SS7U8Kz7gZtRTfcd81cAfnqp5AcL8N3qKG5lDWIJniJK7whheBO0BtBvnJVrD/XL o/o/JdbmBZJPehSSovILHHXRv/1wAFPnES12//NWWMphh1Wro2wbE4wOGV5l5TEjzVcT qeTIGoBlGo2ZYDfkXgdxqIOGyTsYgSGzuw6zXOa7aqCoRlMU6vaU+dUCIUkaArDN3fGl idf+0EmUtDQPc2dagA6fWfMn0Te7ex9YJCyIT7itfSPoRJt6HriTMMU5dXr3f5t3kz/i UpDhWDfJiAvv8L0MFk0l1dHxkDmNKpz3JPdAfb6eWSaXRfivnaTdq7E/Ir8qW1OhSwow DP9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/p6GNpoWLwqRjkpemdg8r3B7YOn9VfnVEzWKh2GHgSQ=; b=lUEr/IcTiglBBVxWLOpVd7NWvJIxHjmDVrhwey7hPv94NvneTisBXU2ewo+LYwTsq+ +dNxvjM3Is4QlZFgdHA0GQxRzRExSwJKSSe+20qVikIznI0dxIhCKq5bvCYqBif4Tuvr +cCRim8XHVhlf+dY7ZDkM0X0VVQlog/Xt4s7CbEP7sO4zx8cNlB06bTBA0IuP4AWOjxo SGrgBx4K5NnXPCtgrevhP4wmDPornc4I8iECK5u0N3Y+0XjkY3CmGHWxaW57Ca5soTj+ Vs/0pf/g6uiYl8UM3bdCZ9kedUv+CHNyxB3Xe+uvfJ55WLJywTxsOVAJksbetpssXMrE PXvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mEtjIiol; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q20-20020aa79614000000b005a7e409a44asi3658358pfg.98.2023.02.09.20.57.36; Thu, 09 Feb 2023 20:57:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mEtjIiol; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbjBJEw0 (ORCPT + 99 others); Thu, 9 Feb 2023 23:52:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231244AbjBJEv4 (ORCPT ); Thu, 9 Feb 2023 23:51:56 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E91A77145; Thu, 9 Feb 2023 20:51:28 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id u9so5299679plr.9; Thu, 09 Feb 2023 20:51:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/p6GNpoWLwqRjkpemdg8r3B7YOn9VfnVEzWKh2GHgSQ=; b=mEtjIioleyGxYaWuQJaM9p/AxjJefiyXu8LvsMl3AaQryOfcQO+xfqyhuhj365eu1a VUd0vp9Y82wY4p5q7ciGrkQb3Q0pe2zuRNz7mpYuIUfypr4gKRJiSwcVFEEp3ROamt7m f2o0mcQ3EgkUlGtesmnyMPr6HrhJJA2Ruprd1ynnLyufZgZtgemKhsi3eDuODbrrNhHB mA/8oAfhdOG9+uUcSsPvyLanaDiqNIXatrwJlPNq1j9BVApCRbxk9iwtk5wWoRGELver 8DpVkbsJHDyhJi8Zb+iXnkLj1W5w3xGyD/F6OSgWf+nDQkwi/NcMbz19PXiTc5stxZbr dchA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/p6GNpoWLwqRjkpemdg8r3B7YOn9VfnVEzWKh2GHgSQ=; b=Te+QXIZLCwDQ8Cjsy/Yzi+1iRunLX9DmVgQXINzGqaK141irQHvDZr1rgScOHdKlMo WzIfWPanQu7C7NYlUNw6iS80ilpsOXPzojJzFDzvXXmERNSD4+/lNnKec/j/VtaF3oNW hFcn3sTpF0Xu9kCrlfxICv6FJxhF86JgU/udjV2GbUvqUwVorR7kvpcrTU4MTsDbOQIb SUHPzMh7vXB+nB5DvXUmYmP0UsTrxe3FaBz4pN7P2m/T5tHPa0E4I4ylf3UBwIKGUxy5 3qg2FtExRp+tN2klACSidWd94bbtlyg2B4lF68YYznATvDTDeLxVcOowySim0PftM7Yu DbCw== X-Gm-Message-State: AO0yUKWN92ZdK8GJ5sAQlGSbJ/NQ0UPe8cmhlQjzZ0Ngh3d0xvEAbdIz Opu7WvZoM86y2bFcLAtsQ1KiirvuHXUzdQ== X-Received: by 2002:a05:6a20:8f04:b0:bc:c07a:f6c with SMTP id b4-20020a056a208f0400b000bcc07a0f6cmr18379114pzk.16.1676004686432; Thu, 09 Feb 2023 20:51:26 -0800 (PST) Received: from localhost.localdomain ([202.53.32.211]) by smtp.gmail.com with ESMTPSA id t13-20020a62ea0d000000b0057fec210d33sm2269218pfh.152.2023.02.09.20.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 20:51:26 -0800 (PST) From: Orlando Chamberlain To: platform-driver-x86@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org Cc: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Hans de Goede , Mark Gross , Jaroslav Kysela , Takashi Iwai , Hawking Zhang , Andrey Grodzovsky , Lijo Lazar , YiPeng Chai , Somalapuram Amaranath , Mario Limonciello , Bokun Zhang , Jack Xiao , Kai Vehmanen , Pierre-Louis Bossart , Rander Wang , Ranjani Sridharan , =?utf-8?q?Amadeusz_S?= =?utf-8?q?=C5=82awi=C5=84ski?= , Yong Zhi , Evan Quan , Kerem Karabay , Aditya Garg , Aun-Ali Zaidi , Orlando Chamberlain Subject: [RFC PATCH 9/9] drm/amdgpu: register a vga_switcheroo client for all GPUs that are not thunderbolt attached Date: Fri, 10 Feb 2023 15:48:26 +1100 Message-Id: <20230210044826.9834-10-orlandoch.dev@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210044826.9834-1-orlandoch.dev@gmail.com> References: <20230210044826.9834-1-orlandoch.dev@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757418692487613692?= X-GMAIL-MSGID: =?utf-8?q?1757418692487613692?= From: Kerem Karabay Commit 3840c5bcc245 ("drm/amdgpu: disentangle runtime pm and vga_switcheroo") made amdgpu only register a vga_switcheroo client for GPU's with PX, however AMD GPUs in dual gpu Apple Macbooks do need to register, but don't have PX. Instead of AMD's PX, they use apple-gmux. Revert to the old logic of registering for all non-thunderbolt gpus, like radeon and nouveau. Fixes: 3840c5bcc245 ("drm/amdgpu: disentangle runtime pm and vga_switcheroo") Signed-off-by: Kerem Karabay [Orlando Chamberlain : add commit description] Signed-off-by: Orlando Chamberlain --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 2f28a8c02f64..0bb553a61552 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -3919,12 +3919,13 @@ int amdgpu_device_init(struct amdgpu_device *adev, if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) vga_client_register(adev->pdev, amdgpu_device_vga_set_decode); - if (amdgpu_device_supports_px(ddev)) { - px = true; - vga_switcheroo_register_client(adev->pdev, - &amdgpu_switcheroo_ops, px); + px = amdgpu_device_supports_px(ddev); + + if (!pci_is_thunderbolt_attached(adev->pdev)) + vga_switcheroo_register_client(adev->pdev, &amdgpu_switcheroo_ops, px); + + if (px) vga_switcheroo_init_domain_pm_ops(adev->dev, &adev->vga_pm_domain); - } if (adev->gmc.xgmi.pending_reset) queue_delayed_work(system_wq, &mgpu_info.delayed_reset_work, @@ -4048,10 +4049,13 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev) kfree(adev->bios); adev->bios = NULL; - if (amdgpu_device_supports_px(adev_to_drm(adev))) { + + if (!pci_is_thunderbolt_attached(adev->pdev)) vga_switcheroo_unregister_client(adev->pdev); + + if (amdgpu_device_supports_px(adev_to_drm(adev))) vga_switcheroo_fini_domain_pm_ops(adev->dev); - } + if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) vga_client_unregister(adev->pdev);