From patchwork Fri Sep 20 14:03:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parker Newman X-Patchwork-Id: 829976 Received: from mout.perfora.net (mout.perfora.net [74.208.4.196]) (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 5340117BEBF; Fri, 20 Sep 2024 14:04:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.208.4.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726841061; cv=none; b=j97AGLgKInQJ3k7In2OmVS15Tj3H6fRhN9zKqyvcLnsleb0nptkELCGRowafAhIHnmEmchJ4NQ74SoeKCKVQBlnERU1xV4iOhP8mHVR6kCRtA5BTLdZoT3iRcr40EGHZr4ZrgjNGgpWV0mclSa7HHF7604/9WlWmuwQNSiV3YgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726841061; c=relaxed/simple; bh=3tMpMExSP8vnlpdIaroyNHu0kVRPvDaPDScagyoRV0U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rVjBs/sSZREpIq36mKmQ8Mxp8j2J1tnoj9sS4EX3rHwg23THfnjWfAyVoxCwqftjpDGp1bAGB00YxGvT7PXUCwn093I2zWUhUNskVjcU4a2ElKq8rkBtsnzNEfsyj9q7iED6mbc+ulSa1o6RqWoMwD8IhdJigyDmJizGLDvbcGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=finest.io; spf=pass smtp.mailfrom=finest.io; dkim=pass (2048-bit key) header.d=finest.io header.i=parker@finest.io header.b=o0+m8dkP; arc=none smtp.client-ip=74.208.4.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=finest.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=finest.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=finest.io header.i=parker@finest.io header.b="o0+m8dkP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=finest.io; s=s1-ionos; t=1726841037; x=1727445837; i=parker@finest.io; bh=Do9t6U2j/JcAt3TP89H4VkzWO/23+OkcmaE5mLIMiK8=; 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=o0+m8dkPC9StY3YIjiXCqowoWKwYGwdzhhS4olxRrZzxxyduAkzQXkCCNUPSprce epMHi3yzd8BpUdCcU2JU5NyqKIJqai8xrJOtt1YQ4jWt7Ihd08VfW+64tIW5K6wol 4Y81V0m66lkXLC4tuJqaK3n18H9DxlgymzARBlwmhV2ntQww39vAroo7dKde1aN10 AlcQhZhOT+rCPds+UsXyDhNEFgUM0HxpTgYWXrawFlT+C7rqbjSwIxi8cb7NNTTFY cz4JXUvthLbexmlXyN8/LVDFAAvy+i4CztdrBFpvp0JAHBxd+iFfWvbHHgPDL6/BN UT+PzaksTa+/uIagOA== X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from finest.io ([98.159.241.229]) by mrelay.perfora.net (mreueus002 [74.208.5.2]) with ESMTPSA (Nemesis) id 0M55Ka-1s2SpP0QQg-011Hx7; Fri, 20 Sep 2024 16:03:57 +0200 From: Parker Newman To: Greg Kroah-Hartman , Jiri Slaby , Arnd Bergmann , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Cc: Parker Newman Subject: [PATCH v2 1/4] misc: eeprom: eeprom_93cx6: Add quirk for extra read clock cycle Date: Fri, 20 Sep 2024 10:03:21 -0400 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-ser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hXdoNr6BsJua9ch8dwi3C/Q/wQA+hOCwdfrXy/KP A6uGgrUA3KEQY0ojZ1EWgpdRrTHYvUPsw== From: Parker Newman This patch adds a quirk similar to eeprom_93xx46 to add an extra clock cycle before reading data from the EEPROM. The 93Cx6 family of EEPROMs output a "dummy 0 bit" between the writing of the op-code/address from the host to the EEPROM and the reading of the actual data from the EEPROM. More info can be found on page 6 of the AT93C46 datasheet (linked below). Similar notes are found in other 93xx6 datasheets. In summary the read operation for a 93Cx6 EEPROM is: Write to EEPROM: 110[A5-A0] (9 bits) Read from EEPROM: 0[D15-D0] (17 bits) Where: 110 is the start bit and READ OpCode [A5-A0] is the address to read from 0 is a "dummy bit" preceding the actual data [D15-D0] is the actual data. Looking at the READ timing diagrams in the 93Cx6 datasheets the dummy bit should be clocked out on the last address bit clock cycle meaning it should be discarded naturally. However, depending on the hardware configuration sometimes this dummy bit is not discarded. This is the case with Exar PCI UARTs which require an extra clock cycle between sending the address and reading the data. Link: https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-5193-SEEPROM-AT93C46D-Datasheet.pdf Signed-off-by: Parker Newman Reviewed-by: Andy Shevchenko --- Changes in v2: - Moved quirk define into struct eeprom_93cx6. - Moved has_quirk_extra_read_cycle() from eeprom_93cx6.c into eeprom_93cx6.h. - Fixed commit message formatting. drivers/misc/eeprom/eeprom_93cx6.c | 10 ++++++++++ include/linux/eeprom_93cx6.h | 12 ++++++++++++ 2 files changed, 22 insertions(+) -- 2.46.0 diff --git a/drivers/misc/eeprom/eeprom_93cx6.c b/drivers/misc/eeprom/eeprom_93cx6.c index 9627294fe3e9..4c9827fe9217 100644 --- a/drivers/misc/eeprom/eeprom_93cx6.c +++ b/drivers/misc/eeprom/eeprom_93cx6.c @@ -186,6 +186,11 @@ void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom, const u8 word, eeprom_93cx6_write_bits(eeprom, command, PCI_EEPROM_WIDTH_OPCODE + eeprom->width); + if (has_quirk_extra_read_cycle(eeprom)) { + eeprom_93cx6_pulse_high(eeprom); + eeprom_93cx6_pulse_low(eeprom); + } + /* * Read the requested 16 bits. */ @@ -252,6 +257,11 @@ void eeprom_93cx6_readb(struct eeprom_93cx6 *eeprom, const u8 byte, eeprom_93cx6_write_bits(eeprom, command, PCI_EEPROM_WIDTH_OPCODE + eeprom->width + 1); + if (has_quirk_extra_read_cycle(eeprom)) { + eeprom_93cx6_pulse_high(eeprom); + eeprom_93cx6_pulse_low(eeprom); + } + /* * Read the requested 8 bits. */ diff --git a/include/linux/eeprom_93cx6.h b/include/linux/eeprom_93cx6.h index c860c72a921d..4d141345f4d4 100644 --- a/include/linux/eeprom_93cx6.h +++ b/include/linux/eeprom_93cx6.h @@ -11,6 +11,8 @@ Supported chipsets: 93c46, 93c56 and 93c66. */ +#include + /* * EEPROM operation defines. */ @@ -34,6 +36,7 @@ * @register_write(struct eeprom_93cx6 *eeprom): handler to * write to the eeprom register by using all reg_* fields. * @width: eeprom width, should be one of the PCI_EEPROM_WIDTH_* defines + * @quirks: eeprom or controller quirks * @drive_data: Set if we're driving the data line. * @reg_data_in: register field to indicate data input * @reg_data_out: register field to indicate data output @@ -50,6 +53,9 @@ struct eeprom_93cx6 { void (*register_write)(struct eeprom_93cx6 *eeprom); int width; + unsigned int quirks; +/* Some EEPROMs require an extra clock cycle before reading */ +#define PCI_EEPROM_QUIRK_EXTRA_READ_CYCLE BIT(0) char drive_data; char reg_data_in; @@ -71,3 +77,9 @@ extern void eeprom_93cx6_wren(struct eeprom_93cx6 *eeprom, bool enable); extern void eeprom_93cx6_write(struct eeprom_93cx6 *eeprom, u8 addr, u16 data); + +static inline bool has_quirk_extra_read_cycle(struct eeprom_93cx6 *eeprom) +{ + return eeprom->quirks & PCI_EEPROM_QUIRK_EXTRA_READ_CYCLE; +} + From patchwork Fri Sep 20 14:03:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parker Newman X-Patchwork-Id: 830316 Received: from mout.perfora.net (mout.perfora.net [74.208.4.197]) (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 DD14D2AE69; Fri, 20 Sep 2024 14:04:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.208.4.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726841058; cv=none; b=phBOKjSnlIw3Ry8fPyOLFUBNQeSEuokTmUphTz+Gph8zcL+lL72eu+MuhkVynNdU5e4ZU1rW5DMjmA8OVAxnP9I5yD+F/iZTw29ZP9OGyJOgBuTV0m2iTCaTzCHIeYjFTmUsqrKjdtUamMhUofH3m6U1rni/KIpuJTykiklY/kQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726841058; c=relaxed/simple; bh=PUPG6M15p+uvnOpnoGrSj/aP7/FefHXOvVcbz2G0/zo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hLcLvyoEOeYDuzi/vIqOrZofiENgrpUiefa1nyIE0EabqoYKvxOEysEgbId0iThwmsAHkD0w7LZ7b/bVyRmxwGYkzKc0HLbo+a//OEooeYxAGNko2ibQ5EqBd92p0DBoedZ9W58GgGybmTI1eJS+8s7o4wU46j/SOYzNU3gIXVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=finest.io; spf=pass smtp.mailfrom=finest.io; dkim=pass (2048-bit key) header.d=finest.io header.i=parker@finest.io header.b=n+DpnBEO; arc=none smtp.client-ip=74.208.4.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=finest.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=finest.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=finest.io header.i=parker@finest.io header.b="n+DpnBEO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=finest.io; s=s1-ionos; t=1726841037; x=1727445837; i=parker@finest.io; bh=Oh8wCdTiw7MRiL8RwHCp3icYa+qrj95ZJRnetzTNmZg=; 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=n+DpnBEOe012DfzRWrHa+vFuIMrJT3Nf4dsa2qKBSrFmYUXrdBu/zuQGnAySjdrc PxJ9GBp2nOwspRQ7F221ELLYW9nhb12/bFCYhrDxw0ENlzAJjthnrbZKr0ANn9cYH SFdMDeDzybGF9/CFBqc4p9pzQUUtWIyWhLACVdqV0c0JYW6ObBDx1OjJKaprmzOX2 zKFgJ3qgcoa9usUDJHRId9KKrOEKXjyoVuzh7gPnjeDtt7P07IXHN5e6mMQKW7S/V QhgRNaerPl2oC3TzJ/WUPv2XQg3bdD3Yz4Z0RXriZnJkygNJ5e70qkV8d2YrfZJUZ BGgpODaIYQEvZ9sOew== X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from finest.io ([98.159.241.229]) by mrelay.perfora.net (mreueus002 [74.208.5.2]) with ESMTPSA (Nemesis) id 0M3ys8-1s1Klb2GN0-016nir; Fri, 20 Sep 2024 16:03:57 +0200 From: Parker Newman To: Greg Kroah-Hartman , Jiri Slaby , Arnd Bergmann , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Cc: Parker Newman Subject: [PATCH v2 2/4] misc: eeprom: eeprom_93cx6: Switch to BIT() macro Date: Fri, 20 Sep 2024 10:03:22 -0400 Message-ID: <1c2406fc139015988b996b26b240963b9a35d754.1726838531.git.pnewman@connecttech.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X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: Parker Newman Use the BIT() macro rather than (1 << (i - 1)). Signed-off-by: Parker Newman --- drivers/misc/eeprom/eeprom_93cx6.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.46.0 diff --git a/drivers/misc/eeprom/eeprom_93cx6.c b/drivers/misc/eeprom/eeprom_93cx6.c index 4c9827fe9217..e6f0e0fc1ca2 100644 --- a/drivers/misc/eeprom/eeprom_93cx6.c +++ b/drivers/misc/eeprom/eeprom_93cx6.c @@ -8,6 +8,7 @@ * Supported chipsets: 93c46 & 93c66. */ +#include #include #include #include @@ -102,7 +103,7 @@ static void eeprom_93cx6_write_bits(struct eeprom_93cx6 *eeprom, /* * Check if this bit needs to be set. */ - eeprom->reg_data_in = !!(data & (1 << (i - 1))); + eeprom->reg_data_in = !!(data & BIT(i - 1)); /* * Write the bit to the eeprom register. @@ -152,7 +153,7 @@ static void eeprom_93cx6_read_bits(struct eeprom_93cx6 *eeprom, * Read if the bit has been set. */ if (eeprom->reg_data_out) - buf |= (1 << (i - 1)); + buf |= BIT(i - 1); eeprom_93cx6_pulse_low(eeprom); } From patchwork Fri Sep 20 14:03:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parker Newman X-Patchwork-Id: 830314 Received: from mout.perfora.net (mout.perfora.net [74.208.4.194]) (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 A75AF17BED4; Fri, 20 Sep 2024 14:04:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.208.4.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726841061; cv=none; b=A65guLQuy0shLPG/Po2n+jOkCmez52wabaQPNnEilYDpiz0vdZrWji4aE1gUTdNrJKOCpF+lIEdvtJ2R75Ja7M/gbTyK4BQdzDskti4yJyImQRFBdbyPBDfM7OWlAMRwzW3N2gwsQ5SIE/n+2pXrkFe6cNSmw8p/qbeJvJfFWmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726841061; c=relaxed/simple; bh=QQ1yP34mU3jOu426r3UpaGZPUduk+xkR7IRq7celwUI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RpD/Ppo6IafZ185UDz1l27ed4H/yi5NOh8Z4rle2gsKlIqLT5e5MN3kdJQlAP7EIVvoAN3mKJq+iIhYW81sBbBnF8btOoQsw7gbNnuQbQbDYcEaayaT+nu1zBRhlLHKCqWqacDYaqLFrqq+Xj49oJrpez34kC0suTsXNyazcuj0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=finest.io; spf=pass smtp.mailfrom=finest.io; dkim=pass (2048-bit key) header.d=finest.io header.i=parker@finest.io header.b=TtH4RoCV; arc=none smtp.client-ip=74.208.4.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=finest.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=finest.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=finest.io header.i=parker@finest.io header.b="TtH4RoCV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=finest.io; s=s1-ionos; t=1726841038; x=1727445838; i=parker@finest.io; bh=00qz7bDIYoKPye2tJW00roRkQAakW3RHPiLKFE5Bw1E=; 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=TtH4RoCVyEPWoxREEmGNrOpDL0hi4gV0I4jVYVO0oCq9LtZdKIABFO//U5cZHccu tolLvD+aWkbKe9SohujMzM97XmgVwrVEx2uZWQ2lC8AhrvAZYL8cP+OHb5Jwt68Jh BSqmWIuRljPUX7pBpKnmgW2Y2maUYHgBgdUAxg+LsAfWt8AuOtfu+HKPoN/IGI32U weiL9oBc4BQW63fC8U9YYqmC6hILdP9yoTuOHq1Vt5e06xP8yOuknRhimyJqapgmq iKFizWSeMhTM6qGWdlV1tVeojQIVdFRvt16Q62q4FS/nKPPw89dd820zOWS2HdaDB SqPp8dFinsZUVa8cRA== X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from finest.io ([98.159.241.229]) by mrelay.perfora.net (mreueus002 [74.208.5.2]) with ESMTPSA (Nemesis) id 0Lm2cB-1sI2RA3paL-00p01S; Fri, 20 Sep 2024 16:03:58 +0200 From: Parker Newman To: Greg Kroah-Hartman , Jiri Slaby , Arnd Bergmann , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Cc: Parker Newman Subject: [PATCH v2 3/4] serial: 8250_exar: Replace custom EEPROM read with eeprom_93cx6 Date: Fri, 20 Sep 2024 10:03:23 -0400 Message-ID: <87719d2113970b6ff4979329fb96346a0aca9775.1726838531.git.pnewman@connecttech.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:AiAODdBHDMYoChooQk6Aj/0l4ha0/f2Zix056vZ4fDV201FgFaq 8F96vzBEv3/roAjLo46YSbE3RMhiNhTEq7AsOwSnmBjew3nMQPevijNSwUW2A6jQfVXoun0 rBnX0gpRvgU90Lgnq7bQJKrU+pVakTsEDYd7CqAPOnNdmFX/Jy4N99fGzMgsTc/Grfe50Bb YoCVUDmzh4mAkmn60LuWA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:pG9E6vvS4BQ=;zbAl1AgWUlC17tbYrmbVHkgXpgO +7Ql10VdwRgttXqi3SaDeDqgJOKF4V4C+6Ua7GPigIjDMbCW5LItlIG4ue2lZke3ordUWHqkl MfjA6pyxH+mSPj1UWqryteBdGLg5We7VRCeTefgKLjIv4f8zhcdbLJVE/zqpqH7IJKlBeTq5u tTMQruX4RBs5pwNWdKDPSOHgefLYmSgPL2RgYOWcZd2+5bMQjehqA2XhJJphvpG6MpFNKBioL 9s/eCDe9MNQQ0JHq+LyjiLqbEVcHH/iTQc2I8uqYXVaUHzSjj1QSyLY+RbF6+8PcRh4oz+T+9 l4mDtQaNG2/RbCHUQGhj6mk51RBelm7PsqV+hRiltQHq2oTaCI1JACwv2OLAi45hpfqpmHi8D vJFi+XDs/eXb9pJ78boc6l/bML8mgQANsGJXR+hmW3Tuzmdyn+YhJVxBCnic2abLv6PNl6nSd zovNwn2+qOaiUeucOG7iDlLSnc31gTy6hfgOc24udFFbK42cmNwsyL+ug+5xquM6Z2P7+JUJT KUOQOdM0bveucTXpy0OaUsvPKnGD4XI7OLVfFOA5+da+Yx7v2wTjCMbhJ9pwq+lE8w+P8P+xd 7VaEeT394ZmmXMfbZoLdbQwx6bbwK3xtpcAvbeAaqOyZgrX3mtd+oHTZ8rODqS0MnaIdFCERR put8PqXnt+2Wb8eFfTFlFSU68WZA3pZx8elIV+47V/J+CNP53vDkmyVE+qVatbDLlaNIpdbzA paQAoH2qk5FMGzzp/bjs9RNvqHuYwSSaQ== From: Parker Newman Replace the custom 93cx6 EEPROM read functions with the eeprom_93cx6 driver. This removes duplicate code and improves code readability. exar_ee_read() calls are replaced with eeprom_93cx6_read() or eeprom_93cx6_multiread(). Add "select EEPROM_93CX6" to config SERIAL_8250_EXAR to ensure eeprom_93cx6 driver is also compiled when 8250_exar driver is selected. Note: Old exar_ee_read() and associated functions are removed in next patch in this series. Link to mailing list discussion with Andy Shevchenko for reference. Link: https://lore.kernel.org/linux-serial/Ztr5u2wEt8VF1IdI@black.fi.intel.com/ Signed-off-by: Parker Newman --- Changes in v2: - Refactored cti_read_osc_freq() based on feedback. - Moved Kconfig change into this patch. - Sorted headers. - Fixed comment. drivers/tty/serial/8250/8250_exar.c | 55 +++++++++++++++++++++++------ drivers/tty/serial/8250/Kconfig | 1 + 2 files changed, 45 insertions(+), 11 deletions(-) -- 2.46.0 diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/8250_exar.c index b7a75db15249..c40e86920110 100644 --- a/drivers/tty/serial/8250/8250_exar.c +++ b/drivers/tty/serial/8250/8250_exar.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -252,6 +253,7 @@ struct exar8250 { unsigned int nr; unsigned int osc_freq; struct exar8250_board *board; + struct eeprom_93cx6 eeprom; void __iomem *virt; int line[]; }; @@ -355,6 +357,39 @@ static u16 exar_ee_read(struct exar8250 *priv, u8 ee_addr) return data; } +static void exar_eeprom_93cx6_reg_read(struct eeprom_93cx6 *eeprom) +{ + struct exar8250 *priv = eeprom->data; + u8 regb = exar_read_reg(priv, UART_EXAR_REGB); + + /* EECK and EECS always read 0 from REGB so only set EEDO */ + eeprom->reg_data_out = regb & UART_EXAR_REGB_EEDO; +} + +static void exar_eeprom_93cx6_reg_write(struct eeprom_93cx6 *eeprom) +{ + struct exar8250 *priv = eeprom->data; + u8 regb = 0; + + if (eeprom->reg_data_in) + regb |= UART_EXAR_REGB_EEDI; + if (eeprom->reg_data_clock) + regb |= UART_EXAR_REGB_EECK; + if (eeprom->reg_chip_select) + regb |= UART_EXAR_REGB_EECS; + + exar_write_reg(priv, UART_EXAR_REGB, regb); +} + +static void exar_eeprom_init(struct exar8250 *priv) +{ + priv->eeprom.data = priv; + priv->eeprom.register_read = exar_eeprom_93cx6_reg_read; + priv->eeprom.register_write = exar_eeprom_93cx6_reg_write; + priv->eeprom.width = PCI_EEPROM_WIDTH_93C46; + priv->eeprom.quirks |= PCI_EEPROM_QUIRK_EXTRA_READ_CYCLE; +} + /** * exar_mpio_config_output() - Configure an Exar MPIO as an output * @priv: Device's private structure @@ -696,20 +731,16 @@ static int cti_plx_int_enable(struct exar8250 *priv) */ static int cti_read_osc_freq(struct exar8250 *priv, u8 eeprom_offset) { - u16 lower_word; - u16 upper_word; + __le16 ee_words[2]; + u32 osc_freq; - lower_word = exar_ee_read(priv, eeprom_offset); - // Check if EEPROM word was blank - if (lower_word == 0xFFFF) - return -EIO; + eeprom_93cx6_multiread(&priv->eeprom, eeprom_offset, ee_words, ARRAY_SIZE(ee_words)); - upper_word = exar_ee_read(priv, (eeprom_offset + 1)); - if (upper_word == 0xFFFF) + osc_freq = le16_to_cpu(ee_words[0]) | (le16_to_cpu(ee_words[1]) << 16); + if (osc_freq == GENMASK(31, 0)) return -EIO; - return FIELD_PREP(CTI_EE_MASK_OSC_FREQ_LOWER, lower_word) | - FIELD_PREP(CTI_EE_MASK_OSC_FREQ_UPPER, upper_word); + return osc_freq; } /** @@ -833,7 +864,7 @@ static enum cti_port_type cti_get_port_type_xr17v35x(struct exar8250 *priv, u8 offset; offset = CTI_EE_OFF_XR17V35X_PORT_FLAGS + port_num; - port_flags = exar_ee_read(priv, offset); + eeprom_93cx6_read(&priv->eeprom, offset, &port_flags); port_type = FIELD_GET(CTI_EE_MASK_PORT_FLAGS_TYPE, port_flags); if (CTI_PORT_TYPE_VALID(port_type)) @@ -1551,6 +1582,8 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) if (rc) return rc; + exar_eeprom_init(priv); + for (i = 0; i < nr_ports && i < maxnr; i++) { rc = board->setup(priv, pcidev, &uart, i); if (rc) { diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig index 47ff50763c04..94910ced8238 100644 --- a/drivers/tty/serial/8250/Kconfig +++ b/drivers/tty/serial/8250/Kconfig @@ -150,6 +150,7 @@ config SERIAL_8250_EXAR tristate "8250/16550 Exar/Commtech PCI/PCIe device support" depends on SERIAL_8250 && PCI select SERIAL_8250_PCILIB + select EEPROM_93CX6 default SERIAL_8250 help This builds support for XR17C1xx, XR17V3xx and some Commtech From patchwork Fri Sep 20 14:03:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parker Newman X-Patchwork-Id: 830315 Received: from mout.perfora.net (mout.perfora.net [74.208.4.196]) (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 63EFA61FCF; Fri, 20 Sep 2024 14:04:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.208.4.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726841060; cv=none; b=nQmMMSgBUIBxyeeJlzfrPt9UrqbEMRV/0C/clH4T8TLdkpF9bc8RalSbEWOs5NNuLHwlSIirA9BlY0Ya24SLI/w+Hg9/K+9xkgKtvv0mkw53TOTaKfEx+NTLjc6r3kyW+IqrfsZwQjzFTYtBE0XNqTclPkPG8g6Lbx57qDPdT7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726841060; c=relaxed/simple; bh=ZNqCSDM1HQEjbF6HFOmsZ/LVqnwVg1FikcCEkoZppec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gawy5SHwH/U/qu9I4LEQxMdYxcq76aonzPszAHeJijs0AGXEBTUncI36Rxddd7oCERkPgIYrWpYiYdy+hlLnq50pYSJEiwlE5VPkBxwW9tNlk2jXu4tjj2MWwirQFcg96yj+BThFPcIlyDbuosg/S3IQ5doRMBBd1/rZ3ofxFbM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=finest.io; spf=pass smtp.mailfrom=finest.io; dkim=pass (2048-bit key) header.d=finest.io header.i=parker@finest.io header.b=OrxjBtJa; arc=none smtp.client-ip=74.208.4.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=finest.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=finest.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=finest.io header.i=parker@finest.io header.b="OrxjBtJa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=finest.io; s=s1-ionos; t=1726841038; x=1727445838; i=parker@finest.io; bh=HXD1LgVa7vJ6hdhMC83sJKrCbgCM2HfctXEdwMy4OaU=; 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=OrxjBtJaODg3Kdi9Hm8FQegGMBhCx8gJUyRctNjaI70mU8grgR0c4ssDFdXOGFdy RsXl0HwewDwGYmbabGQYpsFD+Mr0JW1ooVERfhGLW1xx1amYLg+OSXYb5PeVMY/6s ofYXKJS20TGsflbaMwiUPeySJqPUoCg0Np2oWovzQh+Njyt3ZVEIInAbPYfFlzHao pZIz7NViv2CAemjFcSRoeGZEi4MEPJKPzG+4xI3DpPGMZByDmE8OJi4vYtztrmwO8 blDGX1kJOkEgxtMsa/+kkDCw9l9DGezLxd1/aU+PfWmxDCG1P87uyeZ32cMvZ17BC 23Ekr6OVH2HCMPG9cw== X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from finest.io ([98.159.241.229]) by mrelay.perfora.net (mreueus002 [74.208.5.2]) with ESMTPSA (Nemesis) id 0Lj04u-1sFZrM1Ufm-00oAwf; Fri, 20 Sep 2024 16:03:58 +0200 From: Parker Newman To: Greg Kroah-Hartman , Jiri Slaby , Arnd Bergmann , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Cc: Parker Newman Subject: [PATCH v2 4/4] serial: 8250_exar: Remove old exar_ee_read() and other unneeded code Date: Fri, 20 Sep 2024 10:03:24 -0400 Message-ID: <3edee1e670cc214f73a13c0bf127f4ad8e6bce7f.1726838531.git.pnewman@connecttech.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:SkJqHJQLDsZ+n0F8cDzXKeIyax70ZUOKiZGtZRj3gT9hojm3Iey sXfOSIpXzWEUFOuFZ43cNfOnJrhhFg0yMpaagRo9xSXfgHdM/uU3Pq3O99RX0+4AO03xqmb QSXs1hA7QqQ0S5oXPa+DCbCfR/irXwbRxI5VYg/CBBJxBS4S5Mi8CIwN9edzMTZ9EFJ6UOW wQfRww2/OIUYSZPrbEz2w== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:NqPGd6OTug4=;RJQyuzIqFs4R4DRRLxaAOv4gsxj Gu4Il7/XKwfG4DuFikjFicsKgBmi7bYYKZNVAG9HbSqr5jfKtdEm6180bAxUCyr8C/xbWm1gj 22k/XGUBayCSabDKrnmth1IdcbFkQbA/Wrt2C2BEO5XpJ7tmdUWuz30TSwrVXPQv5hMcNZ5N+ ug7ywkahGh7Oo1tvG66qQgQI2S755x1H9IsJkhRqwD6wgSg9DUZX0PNjcjSqSOTy2Tp4dV5Sv JApCjQ7N7XBmyw0a3XBmOQR3eZPTojA1pO9yJAtB4oZFhovc9iXuqq11ANyElSt7GmLitAcCq Y95eL3PAPYttWMYunurfKX8YlcC0l/B2K7spe7nYWi3pB2WZ70D6UhlWl3qj3XsN9a/smp0uH 5FOKmd0RUo/O3T86MBTmUHTLuzTHPrj07p5xlTe+QtenfuDiUMN62mec15eXusdp1siYzNYYx d9E9ZgsHjrwYz8av0I0eIFGSkUmfHUWCO37rNp54fp37bKm8xBz4v0s06G+7XaT5ybeU9lX7z SnABGQk8OisXtnC2XV3ZteoDFpi7ZUNMRHOn0c3+C85QG3Azpj5Ht1cj4foPFtTFKUHDRX/UA lSERa2l0B2BzwgduUcJ64THBTOtsKaJVebNUDMsLAA8JgP/y37/oid2qjUpqwBcEoY8uO+3po 0AFMjWrUGRVhmj5EuTUzuNNiw/WOLxQ8It2sUBZU6NYKR2uabSm4KydsNSm3OyeABNtypbgUf +63VqvXZG2USOwy1c1BIlYP1Llnok9eJw== From: Parker Newman Remove the old exar_ee_read() and associated helper functions as well as some defines that are no longer needed after the switch to using the eeprom_93cx6 driver. Signed-off-by: Parker Newman --- drivers/tty/serial/8250/8250_exar.c | 90 ----------------------------- 1 file changed, 90 deletions(-) -- 2.46.0 diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/8250_exar.c index c40e86920110..659a44b52f8d 100644 --- a/drivers/tty/serial/8250/8250_exar.c +++ b/drivers/tty/serial/8250/8250_exar.c @@ -136,8 +136,6 @@ #define UART_EXAR_REGB_EECS BIT(5) #define UART_EXAR_REGB_EEDI BIT(6) #define UART_EXAR_REGB_EEDO BIT(7) -#define UART_EXAR_REGB_EE_ADDR_SIZE 6 -#define UART_EXAR_REGB_EE_DATA_SIZE 16 #define UART_EXAR_XR17C15X_PORT_OFFSET 0x200 #define UART_EXAR_XR17V25X_PORT_OFFSET 0x200 @@ -269,94 +267,6 @@ static inline u8 exar_read_reg(struct exar8250 *priv, unsigned int reg) return readb(priv->virt + reg); } -static inline void exar_ee_select(struct exar8250 *priv) -{ - // Set chip select pin high to enable EEPROM reads/writes - exar_write_reg(priv, UART_EXAR_REGB, UART_EXAR_REGB_EECS); - // Min ~500ns delay needed between CS assert and EEPROM access - udelay(1); -} - -static inline void exar_ee_deselect(struct exar8250 *priv) -{ - exar_write_reg(priv, UART_EXAR_REGB, 0x00); -} - -static inline void exar_ee_write_bit(struct exar8250 *priv, u8 bit) -{ - u8 value = UART_EXAR_REGB_EECS; - - if (bit) - value |= UART_EXAR_REGB_EEDI; - - // Clock out the bit on the EEPROM interface - exar_write_reg(priv, UART_EXAR_REGB, value); - // 2us delay = ~500khz clock speed - udelay(2); - - value |= UART_EXAR_REGB_EECK; - - exar_write_reg(priv, UART_EXAR_REGB, value); - udelay(2); -} - -static inline u8 exar_ee_read_bit(struct exar8250 *priv) -{ - u8 regb; - u8 value = UART_EXAR_REGB_EECS; - - // Clock in the bit on the EEPROM interface - exar_write_reg(priv, UART_EXAR_REGB, value); - // 2us delay = ~500khz clock speed - udelay(2); - - value |= UART_EXAR_REGB_EECK; - - exar_write_reg(priv, UART_EXAR_REGB, value); - udelay(2); - - regb = exar_read_reg(priv, UART_EXAR_REGB); - - return (regb & UART_EXAR_REGB_EEDO ? 1 : 0); -} - -/** - * exar_ee_read() - Read a word from the EEPROM - * @priv: Device's private structure - * @ee_addr: Offset of EEPROM to read word from - * - * Read a single 16bit word from an Exar UART's EEPROM. - * The type of the EEPROM is AT93C46D. - * - * Return: EEPROM word - */ -static u16 exar_ee_read(struct exar8250 *priv, u8 ee_addr) -{ - int i; - u16 data = 0; - - exar_ee_select(priv); - - // Send read command (opcode 110) - exar_ee_write_bit(priv, 1); - exar_ee_write_bit(priv, 1); - exar_ee_write_bit(priv, 0); - - // Send address to read from - for (i = UART_EXAR_REGB_EE_ADDR_SIZE - 1; i >= 0; i--) - exar_ee_write_bit(priv, ee_addr & BIT(i)); - - // Read data 1 bit at a time starting with a dummy bit - for (i = UART_EXAR_REGB_EE_DATA_SIZE; i >= 0; i--) { - if (exar_ee_read_bit(priv)) - data |= BIT(i); - } - - exar_ee_deselect(priv); - - return data; -} - static void exar_eeprom_93cx6_reg_read(struct eeprom_93cx6 *eeprom) { struct exar8250 *priv = eeprom->data;