From patchwork Sun Apr 28 09:37:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oswald Buddenhagen X-Patchwork-Id: 13645964 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5219B54F86 for ; Sun, 28 Apr 2024 09:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714297047; cv=none; b=uK29nz9P49BrYCGXDacakDDJp4sC7AKvqxxhxPap4cI+ALuh/N94FjBx7dGL2LxxzvAg5kIh4Wu+GefoV8/ww/0UhshKh8k0BuZW6jMj5Wk+I+KEsJuTOHKTu1osYkeKb6cf5I7uhe7CPut5Gmz++DrpLUfe8tfxgeEVZUbeFcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714297047; c=relaxed/simple; bh=ZjlktYOkymbuVC/0Yq1DisTzunF2Vvg5gIYZDC9QWrY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cIN3VDqcSny3h8gDTK0kB3QLrZcGPUrfoufafsmlJokr2XeBhZ2dhIVdBaCKAsiUQVwZl//cWrlQpBWbDml2wiJ1SdUIcO6M8bKqktEI2H63aa4W1FfAMEc3/6Ii84gWsByGb+zUn0RNGXkKsl0/qXvr9OmUXSOVDHOFP4scajU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=oswald.buddenhagen@gmx.de header.b=O15hEXE7; arc=none smtp.client-ip=212.227.17.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=oswald.buddenhagen@gmx.de header.b="O15hEXE7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1714297037; x=1714901837; i=oswald.buddenhagen@gmx.de; bh=d1y2Sl4aPtixLg10f/epbjxh9byB+m2lFU0ZQvAkpMs=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=O15hEXE79uxKNJbre5v85jMT4hEj5fA0oXUnJnCQFpIig+Hl4dW3T0vrIaLWr5zr uwyJIueYptbvCbEAgo8vQ78PDP0nq5QRDjlmJxB1XoW044L477phk/LW6TfdIuVb9 d7Lz12FS7OjhEhaYwkM6Yt3c7xrLVn4LbeWTRiq6ddst0MURCUlKpbrYs9St9l77V tjNZyJPSIkJV9nsn+N2ZFQNTfiq6Fp46iCMxPx5ZLjmF1eupZxO9l23U4qBu4itCP 1QwoaNZ+38JKskEqeWFA3gFtCjZTtwmiimvmLsL++N9yB8LC/i/NpuZpKdmaV0g48 wBULjYfwjzcMdmC1PA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from ugly.fritz.box ([89.247.162.124]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N17YY-1sgUmV0goc-012Wog; Sun, 28 Apr 2024 11:37:17 +0200 Received: by ugly.fritz.box (masqmail 0.3.6-dev, from userid 1000) id 1s10yC-Q7i-00; Sun, 28 Apr 2024 11:37:16 +0200 From: Oswald Buddenhagen To: linux-sound@vger.kernel.org Cc: Takashi Iwai , Jaroslav Kysela , Pietro Caruso Subject: [PATCH v2 1/6] ALSA: emu10k1: fix E-MU card dock presence monitoring Date: Sun, 28 Apr 2024 11:37:11 +0200 Message-ID: <20240428093716.3198666-2-oswald.buddenhagen@gmx.de> X-Mailer: git-send-email 2.44.0.701.g2cf7baacf3.dirty In-Reply-To: <20240428093716.3198666-1-oswald.buddenhagen@gmx.de> References: <20240428093716.3198666-1-oswald.buddenhagen@gmx.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:ePNZuKFlcBP7sZfHG9OW1IWcnPTQzjBCBVD8CCaqGHsinBfzej2 a9pXbiS03zud+YkSfKjHUw57IV/bboejlMjWLSZ3rqWVPSOSU67rfH/mr0ub4rG6FcrSs+V ZiEUQMuTp7hINLqlny4yTuwaKeVYVunabYb+UtBIqkEjnUMlUydvynuODg3+g9/tylFGVJW bA7l0AIFYU3+4HqePvo6Q== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:783CvpRIXU0=;upyYVDiFVCCmkvPeznzctJVAt9s IQwKK9SSKHRA+ony+iD6zCkyyz98TYGfD0/YdX5iXdK3nRhgIqJ76GkY8wPvccYIHUUYkocXJ wtZGoJ5U9AZfXkfQGZmKb2fXJJsQiP5c0tEyNu2tONCgKcDTLTzT6Vxfq/VC3JNTU9Uv+/ah2 pWG6RbXCUoknqJGkhERxPiM7RM/RoGYWWObLBikAIdsBzFBkIGG1LsKKWjUWr0qAqbUtgWCcE hJ0seUTgJt43hcsVL/XfEWyptzdEMEDeJ8CaR/PGoLCtpVWOcSTkyxXdziWCTllAhzdqGhTYx iLuip/mKRIoiNduYqmjBa/Lum6IJ+nK7y6KIrSmQwC9qbOI2vlpChZzo2UaOZXiER7EAiNaJa aZr3aEqtK6PDwDciDL4Lm6Yt4Uv0S/xXMn84wG/GIZmp7Yc4wBLt6lTyI2IIgiK9iyqEGVXrj nEb2sDQwATRWBajDVi2esVLqPnYih/0hclh8Kz/dv3lFBeALQkGIdDTQ5aom8gA3PswHvOSzD BxdXeqaCfP88TvJKJJ+ygVLIk5fES+ND43cLDY4RNx5olXWZG/WQ0dvMpzHvvk3dK+eWhVWhs eNlgImF+BnYc7f9z8Jw3Tg515BlOVaDGzC8oE3ukd1YEvs0c/gx7UYEJzyepacAS/y4XdqaxS 23bxv/w+WOVLU4c0SUs3j6PMMAmd8UZAaf7V7TNFctRn5nLyXtb3DBYDs06IbKQVjqWlccR56 IP3mBkj6deHixGQHOazrq83leZIt2dAuL1kbOMx0G+LE75WT39Zs2M0NVmc+48tYv+92MuR+p 7z8cau6txo9sUBDtm5jLWlx2xQ0eJmspvuIL6ijtXLD3Y= While there are two separate IRQ status bits for dock attach and detach, the hardware appears to mix them up more or less randomly, making them useless for tracking what actually happened. It is much safer to check the dock status separately and proceed based on that, as the old polling code did. Note that the code assumes that only the dock can be hot-plugged - if other option card bits changed, the logic would break. Fixes: fbb64eedf5a3 ("ALSA: emu10k1: make E-MU dock monitoring interrupt-driven") Link: https://bugzilla.kernel.org/show_bug.cgi?id=218584 Signed-off-by: Oswald Buddenhagen --- sound/pci/emu10k1/emu10k1_main.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c index de5c41e578e1..85f70368a27d 100644 --- a/sound/pci/emu10k1/emu10k1_main.c +++ b/sound/pci/emu10k1/emu10k1_main.c @@ -778,6 +778,11 @@ static void emu1010_firmware_work(struct work_struct *work) msleep(10); /* Unmute all. Default is muted after a firmware load */ snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE); + } else if (!(reg & EMU_HANA_OPTION_DOCK_ONLINE)) { + /* Audio Dock removed */ + dev_info(emu->card->dev, "emu1010: Audio Dock detached\n"); + /* The hardware auto-mutes all, so we unmute again */ + snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE); } } @@ -810,14 +815,12 @@ static void emu1010_interrupt(struct snd_emu10k1 *emu) u32 sts; snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &sts); - if (sts & EMU_HANA_IRQ_DOCK_LOST) { - /* Audio Dock removed */ - dev_info(emu->card->dev, "emu1010: Audio Dock detached\n"); - /* The hardware auto-mutes all, so we unmute again */ - snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE); - } else if (sts & EMU_HANA_IRQ_DOCK) { + + // The distinction of the IRQ status bits is unreliable, + // so we dispatch later based on option card status. + if (sts & (EMU_HANA_IRQ_DOCK | EMU_HANA_IRQ_DOCK_LOST)) schedule_work(&emu->emu1010.firmware_work); - } + if (sts & EMU_HANA_IRQ_WCLK_CHANGED) schedule_work(&emu->emu1010.clock_work); } From patchwork Sun Apr 28 09:37:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oswald Buddenhagen X-Patchwork-Id: 13645965 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6FE754F92 for ; Sun, 28 Apr 2024 09:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714297047; cv=none; b=df4xO0YTPwxyNtFOx5vc7ked7pmgLzJU+F5Ng0XFe528V958VgQBbdPhV1shjsEPAgWkYiQvRzPCkN/2O1zFwTn3YByJg5FU17qHHiDX3Xv8gwttmwC3msRSBeDL2yD5DHK9/GVjqKU1ITaFN49ORb9fBGMfablAstK7UizYmYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714297047; c=relaxed/simple; bh=Wzv4gj0mV9Z58lx920WEk0lWIzjM971IT7wlVNeuh88=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MtB3q2DnFtRzYds6B33irdFOlpCARUQxqjrRnCWaeQ0TcUUWFDLl7iwL2hvgOvCItb2mJeeKCdD00FIcHnlpDMQPmRzqyjhfLxvY+DCIdZ/MsOQvPKl4i2nW+TpsN+GTFAvNNUwr2p006trSCT6IyLpbsR/IJl29agCG999080w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=oswald.buddenhagen@gmx.de header.b=mgYqIPcG; arc=none smtp.client-ip=212.227.17.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=oswald.buddenhagen@gmx.de header.b="mgYqIPcG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1714297037; x=1714901837; i=oswald.buddenhagen@gmx.de; bh=fGHERi1PjWp+/PQ5g1r8VQ2KTJJr7IvUwf0ttM0VbIE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=mgYqIPcGH629HjkK63IXN31XVBck/4XSIRBjOcuTAidCTtmbodnQuIhhjgKDDNCu CpJ+Fqh3abWhUKJrtNsNn+ijzLKeO8cbnsOUm9lraYWlwQJSmzX70f9w1jOrFJiRS h0BOec50r0kPIZgdj2EygLKvEclT9EVkdFlaBWD68fGOCcmfNdorTuS+i8tJdvu27 ogoQbN26eWn+CdBs9q4qOP0CQNuTiivxa5VHMTd6MlPDsxxPmGYNuOQdbkny29/aX 5D6g5TM9EM3p2IKvsoXamoAlX4I/TkBG/T8kiZZkJC+6KisjFcn0SR3xm9vHC184u FUdTL4QPm97bmddm8g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from ugly.fritz.box ([89.247.162.124]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MEFvp-1rrQjI0fAL-00AHjH; Sun, 28 Apr 2024 11:37:17 +0200 Received: by ugly.fritz.box (masqmail 0.3.6-dev, from userid 1000) id 1s10yC-Q7n-00; Sun, 28 Apr 2024 11:37:16 +0200 From: Oswald Buddenhagen To: linux-sound@vger.kernel.org Cc: Takashi Iwai , Jaroslav Kysela , Pietro Caruso Subject: [PATCH v2 2/6] ALSA: emu10k1: factor out snd_emu1010_load_dock_firmware() Date: Sun, 28 Apr 2024 11:37:12 +0200 Message-ID: <20240428093716.3198666-3-oswald.buddenhagen@gmx.de> X-Mailer: git-send-email 2.44.0.701.g2cf7baacf3.dirty In-Reply-To: <20240428093716.3198666-1-oswald.buddenhagen@gmx.de> References: <20240428093716.3198666-1-oswald.buddenhagen@gmx.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:8KEv9t2mHzAHEkx7SPIwS6SQmhAl8YsEzbvbRkzdsIXl6TFm7T4 nAh2n9cT+FwXqV+tS0csmo7ISOO6htmnXIrerQVvI28BvpCsjRW+LE+Sf0o25bspAOOuQNH E2xLI8TUIm79AGqOEfHJotriCO9ERq33psjNv/a63Gqeb0OtUL1PBPTcdmaae13S+aH6Ik4 CtJP95mpm7iMrqYzukSIw== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:uWplMJV8fAI=;nr5G/Z419vIXtuZaqCAbu2dgUmg rrSc9euPlePqUp8p4SC86z5NwmVI1BExd8uNc+/IT5pqxbzFLf7B1xmctSaG5m8jKmW+uNAZG J1lqPRqeupCUCt1uAE0gC6TS5qvFyLgC5SAf+teGjVA5EZrGGR+Demz4hv7ii4oM7CxT4mqKc JI5HMCDDzh2Cutywl3jOkFgb/KDKdgNRn+TBxxsn7k5NpIJRk9r3IAsFZY7A/gyXjQPq/e8Ux uxo+Fb0BUhBVG0S487xBRQrEPnAPosp9pXjjR9+WLV6+zeQGkR2HSHWB3v7l51BwRYAKcz0uM x2HM4fBuPr/u1R+uuEJ3ttuTK/ujTYqnwsVUf0W5DL08SpuOi+59eIeC7FdGtZuN6OGBwAEXR l1vwnN2UyGxqQQsnUUTrtBb+IfG2sG+Zjdx3JhnRxFS0h+uEBEfiryY+o8mKHN3vxd+tlZOaI aX7Z6ufiljaLrbVMhhWAOxn1S6P4yW4x2eNapmOXqkarUcUqKnOrCh9PCR9Nv4Nd3hkdcUysr V4k9OMyEpSRF5el+CW4NH+aoz4IOnaWX22ospj8+1dcJpwTUiKEiBUqSvO2AS0oiOyfz9cEOQ Z0QzcDWVxtR+o45lRuc8BWJzDIW884wXH2pSn7E5lPeZD3EMFNiT5XgdHvP26S4Ep5swxYYJh dz1kVaclgk8JjcIUscaaomIpGOHuY4NqVkT5jJfQkrrlOdNyOii89TOarjw5UtLQYB0ca8TsW 0DLHkIkZX34k6cAZpCPyO/a7m/GT9FkRU+TlymM1J4r8gtvONCXdNf0FdFMHfjC395v3Bd2wd 0cZq6JmDbXPbOJcKgsNwR5KrNbo96VWPkOfcKUe3GeT6g= Pulled out of the next patch to improve its legibility. As the function is now available, call it directly from snd_emu10k1_emu1010_init(), thus making the MicroDock firmware loading synchronous - there isn't really a reason not to. Note that this does not affect the AudioDocks of rev1 cards, as these have no independent power supplies, and thus come up only a while after the main card is initialized. As a drive-by, adjust the priorities of two messages to better reflect their impact. Signed-off-by: Oswald Buddenhagen --- sound/pci/emu10k1/emu10k1_main.c | 66 +++++++++++++++++--------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c index 85f70368a27d..6265fc9ae260 100644 --- a/sound/pci/emu10k1/emu10k1_main.c +++ b/sound/pci/emu10k1/emu10k1_main.c @@ -732,11 +732,43 @@ static int snd_emu1010_load_firmware(struct snd_emu10k1 *emu, int dock, return snd_emu1010_load_firmware_entry(emu, *fw); } +static void snd_emu1010_load_dock_firmware(struct snd_emu10k1 *emu) +{ + u32 tmp, tmp2; + int err; + + dev_info(emu->card->dev, "emu1010: Loading Audio Dock Firmware\n"); + /* Return to Audio Dock programming mode */ + snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, + EMU_HANA_FPGA_CONFIG_AUDIODOCK); + err = snd_emu1010_load_firmware(emu, 1, &emu->dock_fw); + if (err < 0) + return; + snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0); + + snd_emu1010_fpga_read(emu, EMU_HANA_ID, &tmp); + dev_dbg(emu->card->dev, "emu1010: EMU_HANA+DOCK_ID = 0x%x\n", tmp); + if ((tmp & 0x1f) != 0x15) { + /* FPGA failed to be programmed */ + dev_err(emu->card->dev, + "emu1010: Loading Audio Dock Firmware failed, reg = 0x%x\n", + tmp); + return; + } + dev_info(emu->card->dev, "emu1010: Audio Dock Firmware loaded\n"); + + snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp); + snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2); + dev_info(emu->card->dev, "Audio Dock ver: %u.%u\n", tmp, tmp2); + + /* Allow DLL to settle, to sync clocking between 1010 and Dock */ + msleep(10); +} + static void emu1010_firmware_work(struct work_struct *work) { struct snd_emu10k1 *emu; - u32 tmp, tmp2, reg; - int err; + u32 reg; emu = container_of(work, struct snd_emu10k1, emu1010.firmware_work); @@ -749,33 +781,7 @@ static void emu1010_firmware_work(struct work_struct *work) snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, ®); /* OPTIONS: Which cards are attached to the EMU */ if (reg & EMU_HANA_OPTION_DOCK_OFFLINE) { /* Audio Dock attached */ - /* Return to Audio Dock programming mode */ - dev_info(emu->card->dev, - "emu1010: Loading Audio Dock Firmware\n"); - snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, - EMU_HANA_FPGA_CONFIG_AUDIODOCK); - err = snd_emu1010_load_firmware(emu, 1, &emu->dock_fw); - if (err < 0) - return; - snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0); - snd_emu1010_fpga_read(emu, EMU_HANA_ID, &tmp); - dev_info(emu->card->dev, - "emu1010: EMU_HANA+DOCK_ID = 0x%x\n", tmp); - if ((tmp & 0x1f) != 0x15) { - /* FPGA failed to be programmed */ - dev_info(emu->card->dev, - "emu1010: Loading Audio Dock Firmware file failed, reg = 0x%x\n", - tmp); - return; - } - dev_info(emu->card->dev, - "emu1010: Audio Dock Firmware loaded\n"); - snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp); - snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2); - dev_info(emu->card->dev, "Audio Dock ver: %u.%u\n", tmp, tmp2); - /* Sync clocking between 1010 and Dock */ - /* Allow DLL to settle */ - msleep(10); + snd_emu1010_load_dock_firmware(emu); /* Unmute all. Default is muted after a firmware load */ snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE); } else if (!(reg & EMU_HANA_OPTION_DOCK_ONLINE)) { @@ -892,7 +898,7 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu) snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, ®); dev_info(emu->card->dev, "emu1010: Card options = 0x%x\n", reg); if (reg & EMU_HANA_OPTION_DOCK_OFFLINE) - schedule_work(&emu->emu1010.firmware_work); + snd_emu1010_load_dock_firmware(emu); if (emu->card_capabilities->no_adat) { emu->emu1010.optical_in = 0; /* IN_SPDIF */ emu->emu1010.optical_out = 0; /* OUT_SPDIF */ From patchwork Sun Apr 28 09:37:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oswald Buddenhagen X-Patchwork-Id: 13645967 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F5B054F96 for ; Sun, 28 Apr 2024 09:37:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714297048; cv=none; b=ZXDCOYIlW0vmKywaJaRuYshK8sAo4F6x9tQiaeqLBaJeN1E7jeqCfFISQ3hkKOyYZvvYkRaDWlJV3A8j5wdbvYcX8oKVGcKrMIMMh3KagaflqYdZdm28Ni1HWC4t+CemYr8ZKwtqQtqSx+CHXRrX7/8kldzIF6EoRD7bEGVlSWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714297048; c=relaxed/simple; bh=m/NnbNKzr6mqiumaZe68IAVng0yB5sa9bXPbvI5QMNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OTRdGmsXf5HLJdCEZTzrtr5DaAvNDEFS2v5BBEy12iL0nqhWQ8SMU2Iw+gtxYDafoGpla+tP6/d9RdrwVR9fO6nIAb8Ox29Vg9Bf/P9ljZh6pMNg2102WssJ7HtqtqQ622G3T884q6dju+oQW3oOI/BJg10Bb/QEhM7CcQDXZq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=oswald.buddenhagen@gmx.de header.b=Azqxjyom; arc=none smtp.client-ip=212.227.17.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=oswald.buddenhagen@gmx.de header.b="Azqxjyom" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1714297037; x=1714901837; i=oswald.buddenhagen@gmx.de; bh=CZ4Ww9XzCqPHyzemBB+Spep8HrJD6dF6Bu9QTOJ8vO4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=AzqxjyomUk9f7Lzd9iqxJw6ldt+5B2ykX7mKsJnBrT5UFsI5zA6ZWiFmgQEms38I HGKqvY438xohDD93F0xxp2rQmNCHWJsR0ABp0ui6BmgNp+k6I8LDPtx5kFMtWHj0z B26mx+pfnCYSrzwiZhhvZ/EjwX4+52wWrshL9l3TawkGExceOn+e7ayX+NdyMBUOc qJdhp3Db4MtYJsgzEBrhixR1e0A6aDWlSlw2tGqXowOTe/xEIX+x4M+H5Co8flOtn aZIRVRpZ4TSeuyfA7JwFcm6sjRl5CeUBxGqOpByymC/O4S4WbAfWfA0zHNb5t24QD 8ssVDH4mmFvRLJWCiQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from ugly.fritz.box ([89.247.162.124]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MeU0q-1sZFn712xw-00a15z; Sun, 28 Apr 2024 11:37:17 +0200 Received: by ugly.fritz.box (masqmail 0.3.6-dev, from userid 1000) id 1s10yC-Q7s-00; Sun, 28 Apr 2024 11:37:16 +0200 From: Oswald Buddenhagen To: linux-sound@vger.kernel.org Cc: Takashi Iwai , Jaroslav Kysela , Pietro Caruso Subject: [PATCH v2 3/6] ALSA: emu10k1: move the whole GPIO event handling to the workqueue Date: Sun, 28 Apr 2024 11:37:13 +0200 Message-ID: <20240428093716.3198666-4-oswald.buddenhagen@gmx.de> X-Mailer: git-send-email 2.44.0.701.g2cf7baacf3.dirty In-Reply-To: <20240428093716.3198666-1-oswald.buddenhagen@gmx.de> References: <20240428093716.3198666-1-oswald.buddenhagen@gmx.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:MXRbo0RuMbDkwX0dXpQ0/9UVPVFryPsAi4PATI++ATHsNJByaVW UZvvzgcsVBkQHMu6JZ2X3TfBAVfv4zJnVcNyYK9ypZXpsG9WOMBl23+wYBNosCusXYlmPuk CZvcgUWA5g+L4tFMUpNrVdHdU5zHLFZ8cIpKzoaNJwcf2aep9vHCf2E5pprvTNORYotowlj Bc97TOO3HEDLOjscWU3kg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:Si6uIeMi7ZE=;p9AqzMfPtuRyO107aZdvU5SLsXD zE4aefIs70G1zwox0M8nzclgb3ozzHr9Udysck10HBkDunqqP30kmWeAh2ZzG+1ab/rgJ4cnM hIWweMAFkVng1aFq6sNy8B2rnDnnkRDc4IZo77wVrWbBfbEPQftKhd0G5sR4F7M0JX/FeIpXC tMuKS5MDwaJ4z5ahcfol2/rV1gmub7YAgZMK6NbiYF3TGx1Zr0RiYwh3QYWai/1Ar8qj/IZLC WEqAcEmJm+X8ogv3UAiBjZKwSolqbGO0Yc8G+WR0XCHOpubGxM9NeIxYUAf3xw9gw464uEKXq JSdvJDd91Eb0b/cnk4DeeOzVRYH9YBKcFp741wK6/QDcs7c1VirY86e7aLzQIyZaTek9Ml87r OIsf30wIvZ0cJ7Een4aJtUfwgcP0iDmKmYLAAovSY1u7lCCRAh5ur0ZLcIGqu2Gq2UYwS5Q6f D6EA7+1F85EqgbCqXtvSaLElZd5zkiVM8TwMRiqezpm9LrVPTuGKYD2wOSFmC1brFp+DxTkZF uwL0oTlvCrRQPNYGWq0sPg37QFjvcG5N698Kk28W2fbfoBwIKXGE35uNOYqdkFnjH5M1z913v H/Is8HiimZP0AS1y+G69NoXicekkYok8qhkjoNVxAuEYdHNI+vUtHnG2i9xY5nK4KC4TkWIjl apIAgt3rNvwWorp+4yxz0vh3T/V8g016flolV4phljdepDDjEmSw+H/OkCN85jJrxC1CMy4WA uks1WSomIygCxXuo+U5onm+f/YhhgquEOQJwIwE7Ky7t5/aN7ZcUuKbg5kGyl7ygdCzbYViJw Dx+iCcb+pRTurJGZorposNGte7oxronWitjgsmr7dFcVs= The actual event processing was already done by workqueue items. We can move the event dispatching there as well, rather than doing it already in the interrupt handler callback. This change has a rather profound "side effect" on the reliability of the FPGA programming: once we enter programming mode, we must not issue any snd_emu1010_fpga_{read,write}() calls until we're done, as these would badly mess up the programming protocol. But exactly that would happen when trying to program the dock, as that triggers GPIO interrupts as a side effect. This is mitigated by deferring the actual interrupt handling, as workqueue items are not re-entrant. To avoid scheduling the dispatcher on non-events, we now explicitly ignore GPIO IRQs triggered by "uninteresting" pins, which happens a lot as a side effect of calling snd_emu1010_fpga_{read,write}(). Fixes: fbb64eedf5a3 ("ALSA: emu10k1: make E-MU dock monitoring interrupt-driven") Link: https://bugzilla.kernel.org/show_bug.cgi?id=218584 Signed-off-by: Oswald Buddenhagen --- include/sound/emu10k1.h | 3 +- sound/pci/emu10k1/emu10k1.c | 3 +- sound/pci/emu10k1/emu10k1_main.c | 56 ++++++++++++++++---------------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/include/sound/emu10k1.h b/include/sound/emu10k1.h index 1af9e6819392..9cc10fab01a8 100644 --- a/include/sound/emu10k1.h +++ b/include/sound/emu10k1.h @@ -1684,8 +1684,7 @@ struct snd_emu1010 { unsigned int clock_fallback; unsigned int optical_in; /* 0:SPDIF, 1:ADAT */ unsigned int optical_out; /* 0:SPDIF, 1:ADAT */ - struct work_struct firmware_work; - struct work_struct clock_work; + struct work_struct work; }; struct snd_emu10k1 { diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c index fe72e7d77241..dadeda7758ce 100644 --- a/sound/pci/emu10k1/emu10k1.c +++ b/sound/pci/emu10k1/emu10k1.c @@ -189,8 +189,7 @@ static int snd_emu10k1_suspend(struct device *dev) emu->suspend = 1; - cancel_work_sync(&emu->emu1010.firmware_work); - cancel_work_sync(&emu->emu1010.clock_work); + cancel_work_sync(&emu->emu1010.work); snd_ac97_suspend(emu->ac97); diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c index 6265fc9ae260..86eaf5963502 100644 --- a/sound/pci/emu10k1/emu10k1_main.c +++ b/sound/pci/emu10k1/emu10k1_main.c @@ -765,19 +765,10 @@ static void snd_emu1010_load_dock_firmware(struct snd_emu10k1 *emu) msleep(10); } -static void emu1010_firmware_work(struct work_struct *work) +static void emu1010_dock_event(struct snd_emu10k1 *emu) { - struct snd_emu10k1 *emu; u32 reg; - emu = container_of(work, struct snd_emu10k1, - emu1010.firmware_work); - if (emu->card->shutdown) - return; -#ifdef CONFIG_PM_SLEEP - if (emu->suspend) - return; -#endif snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, ®); /* OPTIONS: Which cards are attached to the EMU */ if (reg & EMU_HANA_OPTION_DOCK_OFFLINE) { /* Audio Dock attached */ @@ -792,43 +783,54 @@ static void emu1010_firmware_work(struct work_struct *work) } } -static void emu1010_clock_work(struct work_struct *work) +static void emu1010_clock_event(struct snd_emu10k1 *emu) { - struct snd_emu10k1 *emu; struct snd_ctl_elem_id id; - emu = container_of(work, struct snd_emu10k1, - emu1010.clock_work); - if (emu->card->shutdown) - return; -#ifdef CONFIG_PM_SLEEP - if (emu->suspend) - return; -#endif - spin_lock_irq(&emu->reg_lock); // This is the only thing that can actually happen. emu->emu1010.clock_source = emu->emu1010.clock_fallback; emu->emu1010.wclock = 1 - emu->emu1010.clock_source; snd_emu1010_update_clock(emu); spin_unlock_irq(&emu->reg_lock); snd_ctl_build_ioff(&id, emu->ctl_clock_source, 0); snd_ctl_notify(emu->card, SNDRV_CTL_EVENT_MASK_VALUE, &id); } -static void emu1010_interrupt(struct snd_emu10k1 *emu) +static void emu1010_work(struct work_struct *work) { + struct snd_emu10k1 *emu; u32 sts; + emu = container_of(work, struct snd_emu10k1, emu1010.work); + if (emu->card->shutdown) + return; +#ifdef CONFIG_PM_SLEEP + if (emu->suspend) + return; +#endif + snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &sts); // The distinction of the IRQ status bits is unreliable, // so we dispatch later based on option card status. if (sts & (EMU_HANA_IRQ_DOCK | EMU_HANA_IRQ_DOCK_LOST)) - schedule_work(&emu->emu1010.firmware_work); + emu1010_dock_event(emu); if (sts & EMU_HANA_IRQ_WCLK_CHANGED) - schedule_work(&emu->emu1010.clock_work); + emu1010_clock_event(emu); +} + +static void emu1010_interrupt(struct snd_emu10k1 *emu) +{ + // We get an interrupt on each GPIO input pin change, but we + // care only about the ones triggered by the dedicated pin. + u16 sts = inw(emu->port + A_GPIO); + u16 bit = emu->card_capabilities->ca0108_chip ? 0x2000 : 0x8000; + if (!(sts & bit)) + return; + + schedule_work(&emu->emu1010.work); } /* @@ -969,8 +971,7 @@ static void snd_emu10k1_free(struct snd_card *card) /* Disable 48Volt power to Audio Dock */ snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0); } - cancel_work_sync(&emu->emu1010.firmware_work); - cancel_work_sync(&emu->emu1010.clock_work); + cancel_work_sync(&emu->emu1010.work); release_firmware(emu->firmware); release_firmware(emu->dock_fw); snd_util_memhdr_free(emu->memhdr); @@ -1549,8 +1550,7 @@ int snd_emu10k1_create(struct snd_card *card, emu->irq = -1; emu->synth = NULL; emu->get_synth_voice = NULL; - INIT_WORK(&emu->emu1010.firmware_work, emu1010_firmware_work); - INIT_WORK(&emu->emu1010.clock_work, emu1010_clock_work); + INIT_WORK(&emu->emu1010.work, emu1010_work); /* read revision & serial */ emu->revision = pci->revision; pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial); From patchwork Sun Apr 28 09:37:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oswald Buddenhagen X-Patchwork-Id: 13645970 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3642E54F96 for ; Sun, 28 Apr 2024 09:37:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714297051; cv=none; b=ku/K3lx6aFPbLyF16HwfPX+T5URiLLRf5DMbpBpSVIs8f/dR5THmUk38MgH/vH5DQqHNkMc+yRbFNh3EM++uIvWiOLeZjxo/Dq0ZTOAnAklkRHWVHsQLuQObp/oPVhSX6kHNNsjD01H+n4xKirzPWflJvpV1FAG7gq+tK7g3LA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714297051; c=relaxed/simple; bh=6Whqz2ZCi/Ix53tWYVXjN7jsXzfFy3B7urkt8bRKw2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W5o/D+DF6cWioUlACf/pSOBGrofs+vL3Z//xaOJwDEMpaSw+za9x0dw3c+0YaDo+RMjGFAKXD/YEi6farjzCtHl/A1aqIEFOmq//NUI7S1zICHJhUUABNws+BTM1FCs7UhyW7P/TMl68f0wt0U0HuAvTmjFAVzkc8UZ80ULyQLw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=oswald.buddenhagen@gmx.de header.b=Wbk8W1dU; arc=none smtp.client-ip=212.227.17.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=oswald.buddenhagen@gmx.de header.b="Wbk8W1dU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1714297037; x=1714901837; i=oswald.buddenhagen@gmx.de; bh=3uuDPCjnGjcfwNPYols0Uc2AljpaqiCPqPtNjipgA5Y=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=Wbk8W1dUOMlOlo3G6sBxoEzTeus9sB1I6fN0ZVskMLv3ZB8+0aDFX6A3Hhew2CbV MwKlrPD82v17aChQuEtkP3uDQ5IKy6rQdCsfEycG8aO99ZIdX45FGzb0scuU6iaDP VLCiC+MutBXE0VxnTM805dvFd7bTswfVHb/1iFgsDJyj4va130FxdcBbgcGoY0mmw sT5Mllf1Y1KgAp6yxnrPhyCj9VQ+SIH8A9xmBSe8QL4yqz4UjuZFuMmm2QBk23gS/ F5G4nsK6U0IMi3wD6UyUMSUrx0atMGyZzR5GXdglyDbH9FJ7nJY4+0dgh2qd1XrBn ro52X9psHMzq9XZn9A== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from ugly.fritz.box ([89.247.162.124]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MxUnp-1suT0W0YUD-00xpqq; Sun, 28 Apr 2024 11:37:17 +0200 Received: by ugly.fritz.box (masqmail 0.3.6-dev, from userid 1000) id 1s10yC-Q7x-00; Sun, 28 Apr 2024 11:37:16 +0200 From: Oswald Buddenhagen To: linux-sound@vger.kernel.org Cc: Takashi Iwai , Jaroslav Kysela , Pietro Caruso Subject: [PATCH v2 4/6] ALSA: emu10k1: use mutex for E-MU FPGA access locking Date: Sun, 28 Apr 2024 11:37:14 +0200 Message-ID: <20240428093716.3198666-5-oswald.buddenhagen@gmx.de> X-Mailer: git-send-email 2.44.0.701.g2cf7baacf3.dirty In-Reply-To: <20240428093716.3198666-1-oswald.buddenhagen@gmx.de> References: <20240428093716.3198666-1-oswald.buddenhagen@gmx.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:U+6ydy+aj6z8Tt0tNxXupbQMxb0TNSunmdf9oLdkvzs2ZobcVuk lnnTvsGdlr2dFIdhHXcH3Ql1/nKi1ZfkeG6sXyok6kNmHqrabQfqUvEFsIoikeuhskRNNew 3eSSlR3IVLfAYHGoat6H8B/SvmS9EW+1jLeI6UiI9nTrYvOvZnYPtlkDt6jlbKntMVGXeug f4pyxn1CddcYaNnV6gpRQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:iNLsTaKhHiQ=;7omYpZc5g2WlAVEna9eIIVvcN+q KG4w52JuwR+9+nAQS6A+RZT8aw78R4FQrP8vAJcxZ294sJkvl1MVftty72VdE/nbNpRE1VCpb V06Brdk+qZyKn2z1Erjz5NnS0QFsTK5KDzPzTScJjUCcsKtdY8XmLc9AsZh5dFbravyC7RtOW UJ7EZBfQJCdV2uXlFCwXx1DtlzriCVUGkYf80qV0iYDsSn4lSY2GGmNQMtMlWCJvvulrl1Qnz qpY0Mg5p0VvxqsUpZ/Al1D5gIgaC8shKNkj8pi5vSQcsA7TTsz1nmdDwSAiPJL3Q8S2pCnTTj zFoMsC9mahvNeGys9AcBjvd6JGWHWXv9iyCRZlJtrpxm5Y5UsJzdrb6FFQ14dLr5vAMY6IMoj ANquIuzUer7L+FPPdYUx4ImY61htJ7Pt7TZV4encqYaK5Q36dy6qquK6yuGsZlmJgmUEu1yQa ig3+65kJz7uE8y0Ijzq93VqvJ8QBYxCD+xrSgIpmA3CYNFiSmtncE6AFlUYKcfmMIjyedPy3n IQzk6UZZj/kVn/mVWKlcEdvyBw6LR5jNRyEyb6tfU+dIgdjIkZ4vcfJ+YC61NPjkcIRFIeye8 dDbF3kKRCwA9ghClEHy9D4pnUrKWiLbwufSKi9JqJ4+Bb/R+PaIImcZ/PS25uq+kOe8hO/Pga yeUpKJs05A+4Esg1E4SZpaJSUD+0ARbDRgVUxlnIwrZWstCyVNx5IgRFnivqdvpf2XoWz04be jTDgZRyyccZGUhSvi/U7G9RPPl1HGMg1w2d+J8g47anqYnr1QhfJqAelJ7XfcpSomWJSZAyG0 YvbIPYsThHCBA5VTZ6YJufQCZGF8v+TOSGIpbk4T+TZcw= The FPGA access through the GPIO port does not interfere with other sound processor register access, so there is no need to subject it to emu_lock. And after moving all FPGA access out of the interrupt handler, it does not need to be IRQ-safe, either. What's more, attaching the dock causes a firmware upload, which takes several seconds. We really don't want to disable IRQs for this long, and even less also have someone else spin with IRQs disabled waiting for us. Therefore, use a mutex for FPGA access locking. This makes the code somewhat more noisy, as we need to wrap bigger sections into the mutex, as it needs to enclose the spinlocks. The latter has the "side effect" of fixing dock FPGA programming in a corner case: a really badly timed mixer access right between entering FPGA programming mode and uploading the netlist would mess up the protocol. Signed-off-by: Oswald Buddenhagen --- include/sound/emu10k1.h | 4 +++ sound/pci/emu10k1/emu10k1_main.c | 19 +++++++++--- sound/pci/emu10k1/emumixer.c | 18 ++++++++---- sound/pci/emu10k1/emuproc.c | 9 ++++++ sound/pci/emu10k1/io.c | 50 ++++++++++++++------------------ 5 files changed, 62 insertions(+), 38 deletions(-) diff --git a/include/sound/emu10k1.h b/include/sound/emu10k1.h index 9cc10fab01a8..234b5baea69c 100644 --- a/include/sound/emu10k1.h +++ b/include/sound/emu10k1.h @@ -1685,6 +1685,7 @@ struct snd_emu1010 { unsigned int optical_in; /* 0:SPDIF, 1:ADAT */ unsigned int optical_out; /* 0:SPDIF, 1:ADAT */ struct work_struct work; + struct mutex lock; }; struct snd_emu10k1 { @@ -1833,6 +1834,9 @@ unsigned int snd_emu10k1_ptr20_read(struct snd_emu10k1 * emu, unsigned int reg, void snd_emu10k1_ptr20_write(struct snd_emu10k1 *emu, unsigned int reg, unsigned int chn, unsigned int data); int snd_emu10k1_spi_write(struct snd_emu10k1 * emu, unsigned int data); int snd_emu10k1_i2c_write(struct snd_emu10k1 *emu, u32 reg, u32 value); +static inline void snd_emu1010_fpga_lock(struct snd_emu10k1 *emu) { mutex_lock(&emu->emu1010.lock); }; +static inline void snd_emu1010_fpga_unlock(struct snd_emu10k1 *emu) { mutex_unlock(&emu->emu1010.lock); }; +void snd_emu1010_fpga_write_lock(struct snd_emu10k1 *emu, u32 reg, u32 value); void snd_emu1010_fpga_write(struct snd_emu10k1 *emu, u32 reg, u32 value); void snd_emu1010_fpga_read(struct snd_emu10k1 *emu, u32 reg, u32 *value); void snd_emu1010_fpga_link_dst_src_write(struct snd_emu10k1 *emu, u32 dst, u32 src); diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c index 86eaf5963502..1a2905e8672b 100644 --- a/sound/pci/emu10k1/emu10k1_main.c +++ b/sound/pci/emu10k1/emu10k1_main.c @@ -810,15 +810,19 @@ static void emu1010_work(struct work_struct *work) return; #endif + snd_emu1010_fpga_lock(emu); + snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &sts); // The distinction of the IRQ status bits is unreliable, // so we dispatch later based on option card status. if (sts & (EMU_HANA_IRQ_DOCK | EMU_HANA_IRQ_DOCK_LOST)) emu1010_dock_event(emu); if (sts & EMU_HANA_IRQ_WCLK_CHANGED) emu1010_clock_event(emu); + + snd_emu1010_fpga_unlock(emu); } static void emu1010_interrupt(struct snd_emu10k1 *emu) @@ -852,6 +856,8 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu) * Proper init follows in snd_emu10k1_init(). */ outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK, emu->port + HCFG); + snd_emu1010_fpga_lock(emu); + /* Disable 48Volt power to Audio Dock */ snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0); @@ -877,17 +883,18 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu) err = snd_emu1010_load_firmware(emu, 0, &emu->firmware); if (err < 0) { dev_info(emu->card->dev, "emu1010: Loading Firmware failed\n"); - return err; + goto fail; } /* ID, should read & 0x7f = 0x55 when FPGA programmed. */ snd_emu1010_fpga_read(emu, EMU_HANA_ID, ®); if ((reg & 0x3f) != 0x15) { /* FPGA failed to be programmed */ dev_info(emu->card->dev, "emu1010: Loading Hana Firmware file failed, reg = 0x%x\n", reg); - return -ENODEV; + err = -ENODEV; + goto fail; } dev_info(emu->card->dev, "emu1010: Hana Firmware loaded\n"); @@ -947,7 +954,9 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu) // so it is safe to simply enable the outputs. snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE); - return 0; +fail: + snd_emu1010_fpga_unlock(emu); + return err; } /* * Create the EMU10K1 instance @@ -969,9 +978,10 @@ static void snd_emu10k1_free(struct snd_card *card) } if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1010) { /* Disable 48Volt power to Audio Dock */ - snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0); + snd_emu1010_fpga_write_lock(emu, EMU_HANA_DOCK_PWR, 0); } cancel_work_sync(&emu->emu1010.work); + mutex_destroy(&emu->emu1010.lock); release_firmware(emu->firmware); release_firmware(emu->dock_fw); snd_util_memhdr_free(emu->memhdr); @@ -1551,6 +1561,7 @@ int snd_emu10k1_create(struct snd_card *card, emu->synth = NULL; emu->get_synth_voice = NULL; INIT_WORK(&emu->emu1010.work, emu1010_work); + mutex_init(&emu->emu1010.lock); /* read revision & serial */ emu->revision = pci->revision; pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial); diff --git a/sound/pci/emu10k1/emumixer.c b/sound/pci/emu10k1/emumixer.c index 0a32ea53d8c6..05b98d9b547b 100644 --- a/sound/pci/emu10k1/emumixer.c +++ b/sound/pci/emu10k1/emumixer.c @@ -661,7 +661,9 @@ static int snd_emu1010_output_source_put(struct snd_kcontrol *kcontrol, change = (emu->emu1010.output_source[channel] != val); if (change) { emu->emu1010.output_source[channel] = val; + snd_emu1010_fpga_lock(emu); snd_emu1010_output_source_apply(emu, channel, val); + snd_emu1010_fpga_unlock(emu); } return change; } @@ -705,7 +707,9 @@ static int snd_emu1010_input_source_put(struct snd_kcontrol *kcontrol, change = (emu->emu1010.input_source[channel] != val); if (change) { emu->emu1010.input_source[channel] = val; + snd_emu1010_fpga_lock(emu); snd_emu1010_input_source_apply(emu, channel, val); + snd_emu1010_fpga_unlock(emu); } return change; } @@ -774,7 +778,7 @@ static int snd_emu1010_adc_pads_put(struct snd_kcontrol *kcontrol, struct snd_ct cache = cache & ~mask; change = (cache != emu->emu1010.adc_pads); if (change) { - snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, cache ); + snd_emu1010_fpga_write_lock(emu, EMU_HANA_ADC_PADS, cache ); emu->emu1010.adc_pads = cache; } @@ -832,7 +836,7 @@ static int snd_emu1010_dac_pads_put(struct snd_kcontrol *kcontrol, struct snd_ct cache = cache & ~mask; change = (cache != emu->emu1010.dac_pads); if (change) { - snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, cache ); + snd_emu1010_fpga_write_lock(emu, EMU_HANA_DAC_PADS, cache ); emu->emu1010.dac_pads = cache; } @@ -980,6 +984,7 @@ static int snd_emu1010_clock_source_put(struct snd_kcontrol *kcontrol, val = ucontrol->value.enumerated.item[0] ; if (val >= emu_ci->num) return -EINVAL; + snd_emu1010_fpga_lock(emu); spin_lock_irq(&emu->reg_lock); change = (emu->emu1010.clock_source != val); if (change) { @@ -996,6 +1001,7 @@ static int snd_emu1010_clock_source_put(struct snd_kcontrol *kcontrol, } else { spin_unlock_irq(&emu->reg_lock); } + snd_emu1010_fpga_unlock(emu); return change; } @@ -1041,7 +1047,7 @@ static int snd_emu1010_clock_fallback_put(struct snd_kcontrol *kcontrol, change = (emu->emu1010.clock_fallback != val); if (change) { emu->emu1010.clock_fallback = val; - snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 1 - val); + snd_emu1010_fpga_write_lock(emu, EMU_HANA_DEFCLOCK, 1 - val); } return change; } @@ -1093,7 +1099,7 @@ static int snd_emu1010_optical_out_put(struct snd_kcontrol *kcontrol, emu->emu1010.optical_out = val; tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : EMU_HANA_OPTICAL_IN_SPDIF) | (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : EMU_HANA_OPTICAL_OUT_SPDIF); - snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp); + snd_emu1010_fpga_write_lock(emu, EMU_HANA_OPTICAL_TYPE, tmp); } return change; } @@ -1144,7 +1150,7 @@ static int snd_emu1010_optical_in_put(struct snd_kcontrol *kcontrol, emu->emu1010.optical_in = val; tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : EMU_HANA_OPTICAL_IN_SPDIF) | (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : EMU_HANA_OPTICAL_OUT_SPDIF); - snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp); + snd_emu1010_fpga_write_lock(emu, EMU_HANA_OPTICAL_TYPE, tmp); } return change; } @@ -2323,7 +2329,9 @@ int snd_emu10k1_mixer(struct snd_emu10k1 *emu, for (i = 0; i < emu_ri->n_outs; i++) emu->emu1010.output_source[i] = emu1010_map_source(emu_ri, emu_ri->out_dflts[i]); + snd_emu1010_fpga_lock(emu); snd_emu1010_apply_sources(emu); + snd_emu1010_fpga_unlock(emu); kctl = emu->ctl_clock_source = snd_ctl_new1(&snd_emu1010_clock_source, emu); err = snd_ctl_add(card, kctl); diff --git a/sound/pci/emu10k1/emuproc.c b/sound/pci/emu10k1/emuproc.c index 2f80fd91017c..737c28d31b41 100644 --- a/sound/pci/emu10k1/emuproc.c +++ b/sound/pci/emu10k1/emuproc.c @@ -165,6 +165,8 @@ static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry, u32 value2; if (emu->card_capabilities->emu_model) { + snd_emu1010_fpga_lock(emu); + // This represents the S/PDIF lock status on 0404b, which is // kinda weird and unhelpful, because monitoring it via IRQ is // impractical (one gets an IRQ flood as long as it is desynced). @@ -197,6 +199,8 @@ static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry, snd_iprintf(buffer, "\nS/PDIF mode: %s%s\n", value & EMU_HANA_SPDIF_MODE_RX_PRO ? "professional" : "consumer", value & EMU_HANA_SPDIF_MODE_RX_NOCOPY ? ", no copy" : ""); + + snd_emu1010_fpga_unlock(emu); } else { snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF In", CDCS, CDSRCS); snd_emu10k1_proc_spdif_status(emu, buffer, "Optical or Coax S/PDIF In", GPSCS, GPSRCS); @@ -458,6 +462,9 @@ static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry, struct snd_emu10k1 *emu = entry->private_data; u32 value; int i; + + snd_emu1010_fpga_lock(emu); + snd_iprintf(buffer, "EMU1010 Registers:\n\n"); for(i = 0; i < 0x40; i+=1) { @@ -496,6 +503,8 @@ static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry, snd_emu_proc_emu1010_link_read(emu, buffer, 0x701); } } + + snd_emu1010_fpga_unlock(emu); } static void snd_emu_proc_io_reg_read(struct snd_info_entry *entry, diff --git a/sound/pci/emu10k1/io.c b/sound/pci/emu10k1/io.c index 74df2330015f..f3260a81e47b 100644 --- a/sound/pci/emu10k1/io.c +++ b/sound/pci/emu10k1/io.c @@ -289,71 +289,63 @@ static void snd_emu1010_fpga_write_locked(struct snd_emu10k1 *emu, u32 reg, u32 void snd_emu1010_fpga_write(struct snd_emu10k1 *emu, u32 reg, u32 value) { - unsigned long flags; - - spin_lock_irqsave(&emu->emu_lock, flags); + if (snd_BUG_ON(!mutex_is_locked(&emu->emu1010.lock))) + return; snd_emu1010_fpga_write_locked(emu, reg, value); - spin_unlock_irqrestore(&emu->emu_lock, flags); } -static void snd_emu1010_fpga_read_locked(struct snd_emu10k1 *emu, u32 reg, u32 *value) +void snd_emu1010_fpga_write_lock(struct snd_emu10k1 *emu, u32 reg, u32 value) +{ + snd_emu1010_fpga_lock(emu); + snd_emu1010_fpga_write_locked(emu, reg, value); + snd_emu1010_fpga_unlock(emu); +} + +void snd_emu1010_fpga_read(struct snd_emu10k1 *emu, u32 reg, u32 *value) { // The higest input pin is used as the designated interrupt trigger, // so it needs to be masked out. // But note that any other input pin change will also cause an IRQ, // so using this function often causes an IRQ as a side effect. u32 mask = emu->card_capabilities->ca0108_chip ? 0x1f : 0x7f; + + if (snd_BUG_ON(!mutex_is_locked(&emu->emu1010.lock))) + return; if (snd_BUG_ON(reg > 0x3f)) return; reg += 0x40; /* 0x40 upwards are registers. */ outw(reg, emu->port + A_GPIO); udelay(10); outw(reg | 0x80, emu->port + A_GPIO); /* High bit clocks the value into the fpga. */ udelay(10); *value = ((inw(emu->port + A_GPIO) >> 8) & mask); } -void snd_emu1010_fpga_read(struct snd_emu10k1 *emu, u32 reg, u32 *value) -{ - unsigned long flags; - - spin_lock_irqsave(&emu->emu_lock, flags); - snd_emu1010_fpga_read_locked(emu, reg, value); - spin_unlock_irqrestore(&emu->emu_lock, flags); -} - /* Each Destination has one and only one Source, * but one Source can feed any number of Destinations simultaneously. */ void snd_emu1010_fpga_link_dst_src_write(struct snd_emu10k1 *emu, u32 dst, u32 src) { - unsigned long flags; - if (snd_BUG_ON(dst & ~0x71f)) return; if (snd_BUG_ON(src & ~0x71f)) return; - spin_lock_irqsave(&emu->emu_lock, flags); - snd_emu1010_fpga_write_locked(emu, EMU_HANA_DESTHI, dst >> 8); - snd_emu1010_fpga_write_locked(emu, EMU_HANA_DESTLO, dst & 0x1f); - snd_emu1010_fpga_write_locked(emu, EMU_HANA_SRCHI, src >> 8); - snd_emu1010_fpga_write_locked(emu, EMU_HANA_SRCLO, src & 0x1f); - spin_unlock_irqrestore(&emu->emu_lock, flags); + snd_emu1010_fpga_write(emu, EMU_HANA_DESTHI, dst >> 8); + snd_emu1010_fpga_write(emu, EMU_HANA_DESTLO, dst & 0x1f); + snd_emu1010_fpga_write(emu, EMU_HANA_SRCHI, src >> 8); + snd_emu1010_fpga_write(emu, EMU_HANA_SRCLO, src & 0x1f); } u32 snd_emu1010_fpga_link_dst_src_read(struct snd_emu10k1 *emu, u32 dst) { - unsigned long flags; u32 hi, lo; if (snd_BUG_ON(dst & ~0x71f)) return 0; - spin_lock_irqsave(&emu->emu_lock, flags); - snd_emu1010_fpga_write_locked(emu, EMU_HANA_DESTHI, dst >> 8); - snd_emu1010_fpga_write_locked(emu, EMU_HANA_DESTLO, dst & 0x1f); - snd_emu1010_fpga_read_locked(emu, EMU_HANA_SRCHI, &hi); - snd_emu1010_fpga_read_locked(emu, EMU_HANA_SRCLO, &lo); - spin_unlock_irqrestore(&emu->emu_lock, flags); + snd_emu1010_fpga_write(emu, EMU_HANA_DESTHI, dst >> 8); + snd_emu1010_fpga_write(emu, EMU_HANA_DESTLO, dst & 0x1f); + snd_emu1010_fpga_read(emu, EMU_HANA_SRCHI, &hi); + snd_emu1010_fpga_read(emu, EMU_HANA_SRCLO, &lo); return (hi << 8) | lo; } From patchwork Sun Apr 28 09:37:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oswald Buddenhagen X-Patchwork-Id: 13645963 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 554B654F8A for ; Sun, 28 Apr 2024 09:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714297047; cv=none; b=qI4oRIRwyQbPFZo6f3qhew+IncZjJqC36iIrB6koifeiTLVz8pEZA0PUhlxTWrH5SPDdftZDXRIWP4F/8iwwaxuTVuhXT73l7T6K+Ug4GocHZ+GDcclH8BtlUX12eXlHHNba4BelXZJT1K0YH2wOp/8AJAMlU0YEQJQHqnbOZnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714297047; c=relaxed/simple; bh=SE0SXUkxnDZd817aCrCKn0NTuKBcuIO2/NfZcCFhkzw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bDeYF0rFsn06goAKR5XWWzRWdGY+GDn3IeWReByDSWE03U4dPO4/JxtsCePbAPtd52gaRRTSlmakXGKLNErElg/z6TuFMzRFTluIvJo/XWRZsvwiZuY/18uCg77XezeSmt1krMdxTU8K4BC4q5Wrcg46yf6lz9DciBTE/o9Ljkc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=oswald.buddenhagen@gmx.de header.b=Um8lCkwP; arc=none smtp.client-ip=212.227.17.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=oswald.buddenhagen@gmx.de header.b="Um8lCkwP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1714297037; x=1714901837; i=oswald.buddenhagen@gmx.de; bh=BMzvz6wnwe8VER5NTkYyoyOodsE+w5l22zH97WlkjAM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=Um8lCkwP73IxrW1pzRs4yCWxTRJVUpE+1jScYk7DEgdQsTxknoD3g0TtkODhhCEf +yd+n/T05kxZyu33FAEKf71ruwZi4dsm0G1sxE2dnHGLkdZ8JSbvJHDxSU4l4uOYT I+kFpjkxoJL3VUE5hOfWY0g1q0fAdKOLY1Hx11nXa+BJ/ItIBHoamJHCaar9dtUWg isorfh2UaqxvSrGgIc/+A3W77Q81/v1SeUnbyQ7WmDuPws2J/sFEX+Cv58kYusPcR qr4qGm+XJ3AMTLZInBbSZJS3O8SuCdQwqjVh0ep6+CmGhJbKb/JrdaDA8s3xqOBr8 ZnBTpte0uJcXuBicnQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from ugly.fritz.box ([89.247.162.124]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M42jQ-1s10yD12CO-001miQ; Sun, 28 Apr 2024 11:37:17 +0200 Received: by ugly.fritz.box (masqmail 0.3.6-dev, from userid 1000) id 1s10yC-Q82-00; Sun, 28 Apr 2024 11:37:16 +0200 From: Oswald Buddenhagen To: linux-sound@vger.kernel.org Cc: Takashi Iwai , Jaroslav Kysela , Pietro Caruso Subject: [PATCH v2 5/6] ALSA: emu10k1: fix E-MU dock initialization Date: Sun, 28 Apr 2024 11:37:15 +0200 Message-ID: <20240428093716.3198666-6-oswald.buddenhagen@gmx.de> X-Mailer: git-send-email 2.44.0.701.g2cf7baacf3.dirty In-Reply-To: <20240428093716.3198666-1-oswald.buddenhagen@gmx.de> References: <20240428093716.3198666-1-oswald.buddenhagen@gmx.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:PyCsN2p4JowsAYCgZEAaV78xgeKUzBsTjtywsqyWJjxPgy6pL5I Rfw4Yue5BICFjbTDu9Uhh8nJyADZ7Hq0EHi46e3fsb9z1sXz1iLWwuOI8ZkdRIgpfYWIf/u ZPK4A6TOJPMHyabON7oOBUeStJYnRjHDw5aYLI+nWCo0zM79/Zw9a8VsrEykmIN+Oc+8W09 /al4Pm+PXwBGH2nFUiMrA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:Tutk/opZKLs=;PZfqIKePWNz/OXpPqIlRDRGSmzL P2tHriXBY9CSKcxFl3Gns+h2jrQRD/HyA8rqYhk4n8NS3pIQDDvc6vBFWjYkbApIuCivw7twI A/O91ZEBWSoM7hE+NjR6vgOsW5Yi0s3Z1QdeuEzRywf5BwWcb8QuEqtOzT7GkCaRAEAqhuthz csr9MI75r+ow3U76FmlKX2gKS3K59NN/mSSUtG4ue8mSC4ZoYb8rv5CvY7BGgxGUUqRqASqDT PwlZsGrw4wer6xJh9FOMLj7LZ6QyzIJQOzXtpLwaJzcCf2f33kYzcaoUol//N0NLJ70VdK3yb TST4iqpqJTv9B4zKkZVpVp7YgoPjfstSsQg6yKzQzj1OO3MoXbGRgGB3Fzc6M1BgjHDjjlq+q bSEasr1xOvyn7EUGiaFgA4JBbtW5EjwQ/PL6FsWphke0B4vOPD4kIDUlhlNu0gofVFZdEYP7j oz4Uo82Z7X0zigS8afRvqhmvn4llYqMCl2KYVJp4RLNAMKjaLETJbNS/L7OnkWMgY5WmmEXK/ RYX6EcKuI6s3/dIvPNYljWOFmaZh4VZsgho8oRPEwk2W2MLSdAMDghsKLhSqZMMoB7FpEq5Od ST8RKRAXAeTPbrJyWEOjDORrN/JzpT/f+PhVxjlSffN1SaEndnGc3nPsG2CNg/myCpLc40Qg1 AMLIM6T+4E9XYVAOwbq+qD/OQ78nvjL+G2iImHQsqv7KqgP3QYQ8lFHFErj/gahGTOuXn/JNt EpcZgF8lS6CLUROPPY0TdDxlkutvpLyccBZUlIqqfZNbHvhP4SrNpYSvGh5mK5mKIo/ermlXv 41cp25+JoQGVR+M61ancpJMHku9V2CdKVjCjPjnTwaNU8= A side effect of making the dock monitoring interrupt-driven was that we'd be very quick to program a freshly connected dock. However, for unclear reasons, the dock does not work when we do that - despite the FPGA netlist upload going just fine. We work around this by adding a delay before programming the dock; for safety, the value is several times as much as was determined empirically. Note that a badly timed dock hot-plug would have triggered the problem even before the referenced commit - but now it would happen 100% instead of about 3% of the time, thus making it impossible to work around by re-plugging. Fixes: fbb64eedf5a3 ("ALSA: emu10k1: make E-MU dock monitoring interrupt-driven") Link: https://bugzilla.kernel.org/show_bug.cgi?id=218584 Signed-off-by: Oswald Buddenhagen --- sound/pci/emu10k1/emu10k1_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c index 1a2905e8672b..8ccc0178360c 100644 --- a/sound/pci/emu10k1/emu10k1_main.c +++ b/sound/pci/emu10k1/emu10k1_main.c @@ -737,6 +737,12 @@ static void snd_emu1010_load_dock_firmware(struct snd_emu10k1 *emu) u32 tmp, tmp2; int err; + // The docking events clearly arrive prematurely - while the + // Dock's FPGA seems to be successfully programmed, the Dock + // fails to initialize subsequently if we don't give it some + // time to "warm up" here. + msleep(200); + dev_info(emu->card->dev, "emu1010: Loading Audio Dock Firmware\n"); /* Return to Audio Dock programming mode */ snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, From patchwork Sun Apr 28 09:37:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oswald Buddenhagen X-Patchwork-Id: 13645966 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38F6A54BFD for ; Sun, 28 Apr 2024 09:37:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714297048; cv=none; b=K7eNoYJwwwBkbVvYeBAtdtePgl98MrmbOb2ziOryX1W1CLwxKiPJ7WblLi7GlSUSNFKwZ60TUO7w2JoPII8MlKpvTvL4V/tQt1rkY+nKPmCBQylSKsBgXCEPxlsx0eyFo2mlIK/6jTAdW483waV3v61Mpjky0GogSOErHzxI5kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714297048; c=relaxed/simple; bh=sfDQbY6VCB3N7eo24ujXH2nq8aM3/YOx0Cj5g6lF7Mw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bSoxhsRO9wYD/OYWKjT3TOrg4CjIjpA32SWWrcX8qbwIA6bsglKb0vk6GCJjkn9Pjg8KXpOmYnH+WDob+4Pxgtr2P0Vql0D5yaVFEdond2JhjOxsubNk1lZOFcyugP88zwNNDg2jAOMUzczYR+RWEWc8sqGfssSKfCqmmg70Nec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=oswald.buddenhagen@gmx.de header.b=r3PeMX0I; arc=none smtp.client-ip=212.227.17.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=oswald.buddenhagen@gmx.de header.b="r3PeMX0I" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1714297037; x=1714901837; i=oswald.buddenhagen@gmx.de; bh=z6fsEp7F209GNonUXHk4ngmpHbXVhgOgbIpkS5X8kYQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=r3PeMX0IFqwUXZ44xDcibjSeI7EvgFU+Jtw4MgahpxousT/Rs3san53NnfYMiBMd VEqYvZLlnX8apGnHHOa01BHeWrZ4+VPbb3W9diPp0c3REKCbZniw0PPbbERpIqOIZ w0277DmrKTS2EPnv+YLdWwaoR6VPsZKyOBp59ea2Wp8zfZTisAxDhWSMHz8m+A+pP 6SSZndvjHLg1IUSrjCfm3aczMBq3MR+N71xwlhPTQilf2GYtj4TkbmfuCygohaktJ Rz33NOCRMt/dckvWAw3xzHKEfqCh5/tB0x6wD1AWeQjbcj/Bc/3tyg6diqTYJEZuh IfMReNei1LXfzZ33kA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from ugly.fritz.box ([89.247.162.124]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mn2WF-1sQDW60cfX-00k5Qv; Sun, 28 Apr 2024 11:37:17 +0200 Received: by ugly.fritz.box (masqmail 0.3.6-dev, from userid 1000) id 1s10yC-Q87-00; Sun, 28 Apr 2024 11:37:16 +0200 From: Oswald Buddenhagen To: linux-sound@vger.kernel.org Cc: Takashi Iwai , Jaroslav Kysela , Pietro Caruso Subject: [PATCH v2 6/6] ALSA: emu10k1: make E-MU FPGA writes potentially more reliable Date: Sun, 28 Apr 2024 11:37:16 +0200 Message-ID: <20240428093716.3198666-7-oswald.buddenhagen@gmx.de> X-Mailer: git-send-email 2.44.0.701.g2cf7baacf3.dirty In-Reply-To: <20240428093716.3198666-1-oswald.buddenhagen@gmx.de> References: <20240428093716.3198666-1-oswald.buddenhagen@gmx.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:B/I12cegK16dgzZXvHO8K1Pl9Grb1a+LqIE9+biHqZzmZzD4hzj Hi778mbWpam/vzz99QnRfI83XQxZcwll8Y9sXjbt4gmUgSGfKT2QJ6SX2MLgcyE0ApfBhrR HUJYDIJiFLxm9JSs3ARwN/adcuBoGlswDIK2IFSfwGtA7402Hx4FUBKd8HJUBNW8ZNcBvD3 5EfStkUXVp8paar78LWxQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:t+h+LXpqGaE=;gYncK7BDRm9lLZnRsUGZ8zdx8ow X8Dy6053RgnKTMuq3IftCvvSuoSQ3KNFzTL609x8x7dwpYLTsFouC1FSxmbcXf0HfZUxN1I3a k6mU+6dvsAbu/EegdYBOjOauUIfXGm9Gr69sFCKb5WHRTEroDKZh2NvwM+esu+9DqOu85mIhK UiUSI386EZDRf9IcGvPZH/Dsp86kPieX63Fkul6c2q62CqKIDcqoARQDVeNyi58MPwGkgD93J tOsijF2kplzDNM9KTArGkaoiZbpFAqPUnog42RXO7zitYsKiDLNHsksYYTsXfVUS4KhS0S6FS XY3qHdggzFeh4IP6CmJ2UVwLs/wGi2ecHAGizRgJ5sVhbJddTQbtDC0/bR1zBOv2rgpLyujbn BWpOzsduNNxYFiSX6WhPCDV+ABzMEhrqXARdOuGenA4p/NkTpYuwB1K3ProkwYOwISrdziAx5 4Fwrl1vaD1+diJs4sLmmPJWJOyiN4h2gx+Btg2mRT8Y7eDrWpB6zWXZN+LU4ulqt67JaUbuS2 LO76AC7mnsyXKsNlu3ldWC34JhHa8UHhtXzaG8/g5wSvvUgLpkPctDEHhaStp+Tud2egAGrc1 mC5QI+WTY6P65jIOR5K1JX1Duu/i7BJuDDuP1tSy87LO+ZWqz1/k3Nn90TGEEfeOAfUidU6MO AkhSYBF+eYtaD6WS5vaNmuMMaXDscs8ZUgKhVFLO63UOmyGUqiPxViefC7n6TxgA/uGzp2n+o 2M0vXkr5iIT5dh7xBo5E1G7/z4hnvx5v8fvp8eh+mY7ckPI2pxLxzQv1U5huVst9BVvydfsKF A4KWguT6hS5KtSsvtJKE5e/ijStiPi4Asmo/Br2S5lPAw= We did not delay after the second strobe signal, so another immediately following access could potentially corrupt the written value. This is a purely speculative fix with no supporting evidence, but after taking out the spinlocks around the writes, it seems plausible that a modern processor could be actually too fast. Also, it's just cleaner to be consistent. Signed-off-by: Oswald Buddenhagen --- sound/pci/emu10k1/io.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/pci/emu10k1/io.c b/sound/pci/emu10k1/io.c index f3260a81e47b..f4a1c2d4b078 100644 --- a/sound/pci/emu10k1/io.c +++ b/sound/pci/emu10k1/io.c @@ -285,6 +285,7 @@ static void snd_emu1010_fpga_write_locked(struct snd_emu10k1 *emu, u32 reg, u32 outw(value, emu->port + A_GPIO); udelay(10); outw(value | 0x80 , emu->port + A_GPIO); /* High bit clocks the value into the fpga. */ + udelay(10); } void snd_emu1010_fpga_write(struct snd_emu10k1 *emu, u32 reg, u32 value)