From patchwork Mon Dec 19 18:13:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 636188 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C29E0C4332F for ; Mon, 19 Dec 2022 18:23:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230470AbiLSSW7 (ORCPT ); Mon, 19 Dec 2022 13:22:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229624AbiLSSW6 (ORCPT ); Mon, 19 Dec 2022 13:22:58 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 298C5614D for ; Mon, 19 Dec 2022 10:22:57 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id e13so14113855edj.7 for ; Mon, 19 Dec 2022 10:22:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=2CDnj2dm5dbh1+Vu4PBJuDR7da2c7xAZwDxTtO2AJvg=; b=TvhhNzYJepZ3y+Gve/WVHqWHbypcI5w9Oq43cdmIN2cm8RgGm0lxQkKvQUleatkdgS yYTbh4C+Co49xjwogUTRlh4nYTOLhsqTAeFOoTBL47zLfrxful1IVFHoEbruDex0KeZy b7QI2Qw6F2hgonAAIDhYxy8F2IsWlAhmPLJmIxSW3tWu6b2wMNPBct4XJYDCju5vqysP WlcmwKWRdLvxKNCIGsp6MJSUe+Jq3TCW/wIWM1il+W5/3PlZTfeCrzLd8x5jszpF4zy5 FRVs9dL48g0p9hfDcCR/OfP6VBAv9EktX3EuzP7ZjwZd1RAIBU9v0Ibx/5eSFmN9I9Zc c3Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2CDnj2dm5dbh1+Vu4PBJuDR7da2c7xAZwDxTtO2AJvg=; b=hyfzTxofQKeAupAn8MI7MxY1wUjv2ma5kw5+FIvr7gVeWtEyLFMj6x3k6chPPEMNm2 hgqpKBoz46An0HORNu0o+xbh/Pgljlq44yutAGjfAh2WxGhIwPlY6k3/6L4JjHWHGsDp k7IewxK0a3vYcZDYZFmsdi8TQUK1ti/+uut7QBwl1APCuANMfJ0ec72bropOaoHjAi7+ ynLkZ1zasixH0UAx49VN2EuNDTtnhQFa/Ny+rudxgfdF+wBU0B0Wf3v+A89/vCedKnNP TIRgjL0b3JcNrHq1FMgt1vgWUc0pCuLUmJ5UswXPbMG1aQhVLxBATM2caG84mt+8bTjr 4AAA== X-Gm-Message-State: ANoB5pmAs1Qqgd66SQbMJNKUm/WalRVIUcCVvuPl0aXJxZhf6M98pZdN iJLBnBYyXwhA7sIKCDIxvHZCL0SBxM4= X-Google-Smtp-Source: AA0mqf4gFLSbW9cpuD0MEl3XLbny8b8bFzMdMY4Ru91HiH9ZdCnwIPBUMG/3z6aYkPWeOaP70XX02g== X-Received: by 2002:a05:6402:2034:b0:470:49a2:ad70 with SMTP id ay20-20020a056402203400b0047049a2ad70mr21820088edb.5.1671474175600; Mon, 19 Dec 2022 10:22:55 -0800 (PST) Received: from ?IPV6:2a01:c23:c0aa:f200:2422:8cf4:48af:d322? (dynamic-2a01-0c23-c0aa-f200-2422-8cf4-48af-d322.c23.pool.telefonica.de. [2a01:c23:c0aa:f200:2422:8cf4:48af:d322]) by smtp.googlemail.com with ESMTPSA id e2-20020a50ec82000000b0045723aa48ccsm4627660edr.93.2022.12.19.10.22.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Dec 2022 10:22:55 -0800 (PST) Message-ID: Date: Mon, 19 Dec 2022 19:13:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH v2 01/10] i2c: i801: improve interrupt handler Content-Language: en-US From: Heiner Kallweit To: Jean Delvare Cc: "linux-i2c@vger.kernel.org" References: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> In-Reply-To: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Not sure if it can happen, but better play safe: If SMBHSTSTS_BYTE_DONE and an error flag is set, then don't trust the result and skip calling i801_isr_byte_done(). In addition clear status bit SMBHSTSTS_BYTE_DONE in the main interrupt handler, this allows to simplify the code a little. Signed-off-by: Heiner Kallweit Reviewed-by: Jean Delvare --- v2: - change one expression for generating less binary code --- drivers/i2c/busses/i2c-i801.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 1fda1eaa6..da773c563 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -558,9 +558,6 @@ static void i801_isr_byte_done(struct i801_priv *priv) /* Write next byte, except for IRQ after last byte */ outb_p(priv->data[++priv->count], SMBBLKDAT(priv)); } - - /* Clear BYTE_DONE to continue with next byte */ - outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv)); } static irqreturn_t i801_host_notify_isr(struct i801_priv *priv) @@ -590,7 +587,6 @@ static irqreturn_t i801_host_notify_isr(struct i801_priv *priv) * BUS_ERR - SMI# transaction collision * FAILED - transaction was canceled due to a KILL request * When any of these occur, update ->status and signal completion. - * ->status must be cleared before kicking off the next transaction. * * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt * occurs for each byte of a byte-by-byte to prepare the next byte. @@ -615,23 +611,18 @@ static irqreturn_t i801_isr(int irq, void *dev_id) } status = inb_p(SMBHSTSTS(priv)); - if (status & SMBHSTSTS_BYTE_DONE) + if ((status & (SMBHSTSTS_BYTE_DONE | STATUS_ERROR_FLAGS)) == SMBHSTSTS_BYTE_DONE) i801_isr_byte_done(priv); /* - * Clear remaining IRQ sources: Completion of last command, errors - * and the SMB_ALERT signal. SMB_ALERT status is set after signal - * assertion independently of the interrupt generation being blocked - * or not so clear it always when the status is set. - */ - status &= SMBHSTSTS_INTR | STATUS_ERROR_FLAGS | SMBHSTSTS_SMBALERT_STS; - if (status) - outb_p(status, SMBHSTSTS(priv)); - status &= ~SMBHSTSTS_SMBALERT_STS; /* SMB_ALERT not reported */ - /* - * Report transaction result. - * ->status must be cleared before the next transaction is started. + * Clear IRQ sources: SMB_ALERT status is set after signal assertion + * independently of the interrupt generation being blocked or not + * so clear it always when the status is set. */ + status &= STATUS_FLAGS | SMBHSTSTS_SMBALERT_STS; + outb_p(status, SMBHSTSTS(priv)); + + status &= STATUS_ERROR_FLAGS | SMBHSTSTS_INTR; if (status) { priv->status = status; complete(&priv->done); From patchwork Mon Dec 19 18:14:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 635325 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05CE6C10F1B for ; Mon, 19 Dec 2022 18:23:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231821AbiLSSXA (ORCPT ); Mon, 19 Dec 2022 13:23:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231305AbiLSSW7 (ORCPT ); Mon, 19 Dec 2022 13:22:59 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 149E412759 for ; Mon, 19 Dec 2022 10:22:58 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id n20so23719655ejh.0 for ; Mon, 19 Dec 2022 10:22:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=eI1YfqyG5mIVwPKtGL78y4jWQQ3prftvFp9hWN3KBnM=; b=k/pCpuVCDO0brV+dXfKRhqHssUXvBICycJABEIxx/Wp7i73ST3HXoNa7VB24Ohdwfv mqsqELbBc1YcuOBoeHgh1viCi8m7T0tKYXh6H5SE2qt17U/4Et1Uh2piC98SxuNzokb6 uwirAeFTtb6QPavYFAbgT/iZhR20G/B/fum4j7WVPEG8fMO0OUEQwUqEdg+Edb/+BfhH t57tcwYQNbMjLAlCxutj8vouFbdJI9Y5K6tEWr2hVqAbIvQGRdWN2HTY4I2mG/yp5+rH 3kIx6XPWuuatYfUDgZHa9uSdDIKNEArBXmAxjw7sf7mIbjtVosiEreVTBoh+x0MX0cUa 7ocw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eI1YfqyG5mIVwPKtGL78y4jWQQ3prftvFp9hWN3KBnM=; b=roemf+IyCKmLWAtJeMWMiT7A755GqV1l3yQIy1DyN2NGrMph06AVmvtTbq/DqrzBGV wMDTGyZTSOta2ZIduQGvxz6L8vpWO0RTm1pzXwc9F9X6yMhAIWYv16V7H9IgUpbOF7Pn EmkNYSj5LE6zy/HiTR/MWtYWOV1DJ7tJ1kr2NuG32us5kaEwRpBeB8we5wTg131BVlCh 6cZA4uVskTWf9wx6d/tQ/ipDDwKh/dlZP2DGqbe/eMfDkPZrvON2OL4aJQ6HugdtJBS+ TnH1TEdz2Y7AiMZSJjxaXWO2dwsG1gckT4zEcGOGpNyQYMdDPzKqegVcUL2v0JVHFbFN UevA== X-Gm-Message-State: ANoB5pnchc2wC7lmco5yIkMuU1mXPNCVzM5yuA6dgT1pRqcZVPZfADnn sloCifO9Ty/lWrrC+Wl3cUKypjFGdNs= X-Google-Smtp-Source: AA0mqf4pJ+CmE5wvWv3ff2AUv51a4OZ9TdsukJ3esgPgB4i3dxsFceae1L+52Duu+cw/fEwRE24ajQ== X-Received: by 2002:a17:906:298c:b0:7c1:9eb:845b with SMTP id x12-20020a170906298c00b007c109eb845bmr35480746eje.16.1671474176662; Mon, 19 Dec 2022 10:22:56 -0800 (PST) Received: from ?IPV6:2a01:c23:c0aa:f200:2422:8cf4:48af:d322? (dynamic-2a01-0c23-c0aa-f200-2422-8cf4-48af-d322.c23.pool.telefonica.de. [2a01:c23:c0aa:f200:2422:8cf4:48af:d322]) by smtp.googlemail.com with ESMTPSA id kx16-20020a170907775000b007e57d6e3724sm4367190ejc.116.2022.12.19.10.22.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Dec 2022 10:22:56 -0800 (PST) Message-ID: <2f09691a-c0f5-4aa1-8338-1066c0a6c63d@gmail.com> Date: Mon, 19 Dec 2022 19:14:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH v2 02/10] i2c: i801: make FEATURE_HOST_NOTIFY dependent on FEATURE_IRQ Content-Language: en-US From: Heiner Kallweit To: Jean Delvare Cc: "linux-i2c@vger.kernel.org" References: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> In-Reply-To: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Host notification uses an interrupt, therefore it makes sense only if interrupts are enabled. Make this dependency explicit by removing FEATURE_HOST_NOTIFY if FEATURE_IRQ isn't set. Signed-off-by: Heiner Kallweit Reviewed-by: Jean Delvare --- v2: - add a commit message part as comment to the code - make changed code cleaner --- drivers/i2c/busses/i2c-i801.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index da773c563..45c2ebe40 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -1705,11 +1705,6 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) outb_p(inb_p(SMBAUXCTL(priv)) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv)); - /* Remember original Interrupt and Host Notify settings */ - priv->original_hstcnt = inb_p(SMBHSTCNT(priv)) & ~SMBHSTCNT_KILL; - if (priv->features & FEATURE_HOST_NOTIFY) - priv->original_slvcmd = inb_p(SMBSLVCMD(priv)); - /* Default timeout in interrupt mode: 200 ms */ priv->adapter.timeout = HZ / 5; @@ -1739,6 +1734,15 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) dev_info(&dev->dev, "SMBus using %s\n", priv->features & FEATURE_IRQ ? "PCI interrupt" : "polling"); + /* Host notification uses an interrupt */ + if (!(priv->features & FEATURE_IRQ)) + priv->features &= ~FEATURE_HOST_NOTIFY; + + /* Remember original Interrupt and Host Notify settings */ + priv->original_hstcnt = inb_p(SMBHSTCNT(priv)) & ~SMBHSTCNT_KILL; + if (priv->features & FEATURE_HOST_NOTIFY) + priv->original_slvcmd = inb_p(SMBSLVCMD(priv)); + i801_add_tco(priv); snprintf(priv->adapter.name, sizeof(priv->adapter.name), From patchwork Mon Dec 19 18:15:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 636187 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A07EC4332F for ; Mon, 19 Dec 2022 18:23:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231305AbiLSSXB (ORCPT ); Mon, 19 Dec 2022 13:23:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229624AbiLSSW7 (ORCPT ); Mon, 19 Dec 2022 13:22:59 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1942614D for ; Mon, 19 Dec 2022 10:22:58 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id z92so14166305ede.1 for ; Mon, 19 Dec 2022 10:22:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=SRkiotbrUUp0sb70imF1w8M08b21bs17EMmpEaHpu4k=; b=dP/FImugsXEMHFV1SN3U+JbaiAwtmbQsobic1sTDOF7JuxRblf5SHzYTXEfxYzYVQQ vUdZf1QtgAiEoHZnQBGTRF6q1ByPl+OecrvxAgafjO9tODhRJcKrTxtElLwEmfz56tft Pt1/7TPTZTDK0oLFbOGh0LI1WUu/8FtwVJEeltdq9QmMXtukE+xqs8OBI7l6ao+I4eUK Yc88/nwJMbfhOV7tsJoQzWXKnLGya0dTgE9Q/ftvsjJrEO2WNk3r7JAM7PdKR4CQPXK4 P0ZVsnu1DZQ+PaJgUF5R3tcNGzcmdLae3e+pfr2ZjCO/FJY/qht6k4vfoNtqbH4UvjQl V+Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SRkiotbrUUp0sb70imF1w8M08b21bs17EMmpEaHpu4k=; b=w/0yRfIejnQ6gRZSUczp4iW86yM0A4VCCM8RWxYZiOpufAdItCWWtQD+D0V/t6oexD BQ0ok45Fy8KA5D82974zI/FevULER72JNPQK2DELrX0MsaYm4h2FJgNQxJNZoULDU8wD qB3NSJ9CeDartkp+KgfdOypwWUCBR6AoKDFTXIfBhyTRhOtjsxVAfbVsQcW8Q01v88uf 9Qe8CPhvSzWkZ2RwhxLgWOYEezlf/dvIkmHEvK0zAy15I01yMIJ0m88XUkyVop3pNHpg CDH5XYNc8RQ3c5YnwAvWBftPBZPWZpPeX5KLIth8MOyVJih+bGg0QbB9aZ68myh8esqr Jakw== X-Gm-Message-State: ANoB5pltqPjNLWicqFE1Uu5g4lz83DI9+UjkCAGmir4Rfg/iWQ8pLMuI jjJwHoP18pkRVUMoAFD0FDHNH7HDNvs= X-Google-Smtp-Source: AA0mqf64L3J71+qWIKF0k+DO4RmVusnpHPaEyHlQ4ziKtceuIubAzohPhutVd349mEo+/wZZ5wKbww== X-Received: by 2002:a05:6402:f24:b0:46d:ca42:2e59 with SMTP id i36-20020a0564020f2400b0046dca422e59mr43019080eda.11.1671474177407; Mon, 19 Dec 2022 10:22:57 -0800 (PST) Received: from ?IPV6:2a01:c23:c0aa:f200:2422:8cf4:48af:d322? (dynamic-2a01-0c23-c0aa-f200-2422-8cf4-48af-d322.c23.pool.telefonica.de. [2a01:c23:c0aa:f200:2422:8cf4:48af:d322]) by smtp.googlemail.com with ESMTPSA id u10-20020a056402110a00b0046aa78ecd8asm4653991edv.3.2022.12.19.10.22.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Dec 2022 10:22:57 -0800 (PST) Message-ID: <50f333a1-2f62-4a2d-5527-7a17eb49ec68@gmail.com> Date: Mon, 19 Dec 2022 19:15:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH v2 03/10] i2c: i801: make FEATURE_BLOCK_PROC dependent on FEATURE_BLOCK_BUFFER Content-Language: en-US From: Heiner Kallweit To: Jean Delvare Cc: "linux-i2c@vger.kernel.org" References: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> In-Reply-To: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org According to the datasheet the block process call requires block buffer mode. The user may disable block buffer mode by module parameter disable_features, in such a case we have to clear FEATURE_BLOCK_PROC. Signed-off-by: Heiner Kallweit Reviewed-by: Jean Delvare --- v2: - add a commit message part as comment to the code --- drivers/i2c/busses/i2c-i801.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 45c2ebe40..2e9c5856a 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -1658,6 +1658,10 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) } priv->features &= ~disable_features; + /* The block process call uses block buffer mode */ + if (!(priv->features & FEATURE_BLOCK_BUFFER)) + priv->features &= ~FEATURE_BLOCK_PROC; + err = pcim_enable_device(dev); if (err) { dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n", From patchwork Mon Dec 19 18:16:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 635324 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 389E0C3DA71 for ; Mon, 19 Dec 2022 18:23:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232125AbiLSSXC (ORCPT ); Mon, 19 Dec 2022 13:23:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231967AbiLSSXB (ORCPT ); Mon, 19 Dec 2022 13:23:01 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A82B912759 for ; Mon, 19 Dec 2022 10:22:59 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id tz12so23579637ejc.9 for ; Mon, 19 Dec 2022 10:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=PaSmqAatSCj4anXV7b20JkZxNTXxGyvaUfheL/BGHUo=; b=En+P0V6sqroL81T+eyjKw/zEMCukm02Dg8vdjObZDIybDT+1TV3bTev1ByWcpCRi1e 9QjQlz1uElRrKneVCFsAHj+jjgeNccKa9VoEgwGYx+axifofr6aKthZbHS7/O8fqTFgC wib/aPa6we3BYbt5FRAuVfURKDnpv16YqR5nMqA9SVAhWA6ZvQdxcs7/uI9i8pm+GRPn jx0krOTsInWCBxb6Ek10XnRTDKdC4sCdCsDx7JAy5Eedpf9lc0lm4HcBMIQPb+RXp6DO RipcmtIdvDzBME70sInqnSXaYSLJcOvcjSzFBqSvtiyUTiEP2C6zVY0NGOMYDr0XTJSe OdBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PaSmqAatSCj4anXV7b20JkZxNTXxGyvaUfheL/BGHUo=; b=LGahOhgSb0v6/zZ87Qp5Zc58RUhr53N5r6axvU4NuLD7LBKQ8nikWJbp54kDlEiExs guyjrHtzhWddBNLRjjhULux61CO8ltSjScg0xyaI6FSDWn9MI9Yey++bZEXexbU17S7N 0TAV3J6U+ylfn0L2CSO+YQ5qAJK4GGH6H3XC0RQpL093WeBWseNh5DVLfQG/DTyOXOiD danPFNtAXVEokiCWmI3EIid9LVfKe/AuygOtH4rtFmbQ91RmOedLE4VOBzOyGUfDBJFO TJX7RBFQQYz2NNNpnBhFSQA73BBQ48vSiIK8aa3dObghlcy+BxhQ/Kc9mEtxsgAukxHi tBtw== X-Gm-Message-State: AFqh2kryBqpccx1i/HE7TZY5nrT91eUmgnBe+5u8DJ7WbtvJZz98tens /RuFiBQbrCp6Dmfedtd/EMuyqb/FdVw= X-Google-Smtp-Source: AMrXdXswsymM+Uwzx4UXyP1SzqItpIpHNUzFykp3DxUzmfO2pfKEccTYV3PSiO77OX+lGqPT29pORg== X-Received: by 2002:a17:906:9f26:b0:7cd:dbe8:e4f7 with SMTP id fy38-20020a1709069f2600b007cddbe8e4f7mr19190136ejc.77.1671474178232; Mon, 19 Dec 2022 10:22:58 -0800 (PST) Received: from ?IPV6:2a01:c23:c0aa:f200:2422:8cf4:48af:d322? (dynamic-2a01-0c23-c0aa-f200-2422-8cf4-48af-d322.c23.pool.telefonica.de. [2a01:c23:c0aa:f200:2422:8cf4:48af:d322]) by smtp.googlemail.com with ESMTPSA id sy26-20020a1709076f1a00b007c0b530f3cfsm4673233ejc.72.2022.12.19.10.22.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Dec 2022 10:22:57 -0800 (PST) Message-ID: <042ba587-7428-5b44-56b3-061be22fd958@gmail.com> Date: Mon, 19 Dec 2022 19:16:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH v2 04/10] i2c: i801: add helper i801_set_hstadd() Content-Language: en-US From: Heiner Kallweit To: Jean Delvare Cc: "linux-i2c@vger.kernel.org" References: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> In-Reply-To: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Factor out setting SMBHSTADD to a helper. The current code makes the assumption that constant I2C_SMBUS_READ has bit 0 set, that's not ideal. Therefore let the new helper explicitly check for I2C_SMBUS_READ. Signed-off-by: Heiner Kallweit Reviewed-by: Jean Delvare --- v2: - change expressions for generating less binary code --- drivers/i2c/busses/i2c-i801.c | 36 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 2e9c5856a..882cf5135 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -727,6 +727,11 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv, return i801_check_post(priv, status); } +static void i801_set_hstadd(struct i801_priv *priv, u8 addr, char read_write) +{ + outb_p((addr << 1) | (read_write & 0x01), SMBHSTADD(priv)); +} + /* Block transaction function */ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *data, char read_write, int command) @@ -797,28 +802,24 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, switch (size) { case I2C_SMBUS_QUICK: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), - SMBHSTADD(priv)); + i801_set_hstadd(priv, addr, read_write); xact = I801_QUICK; break; case I2C_SMBUS_BYTE: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), - SMBHSTADD(priv)); + i801_set_hstadd(priv, addr, read_write); if (read_write == I2C_SMBUS_WRITE) outb_p(command, SMBHSTCMD(priv)); xact = I801_BYTE; break; case I2C_SMBUS_BYTE_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), - SMBHSTADD(priv)); + i801_set_hstadd(priv, addr, read_write); outb_p(command, SMBHSTCMD(priv)); if (read_write == I2C_SMBUS_WRITE) outb_p(data->byte, SMBHSTDAT0(priv)); xact = I801_BYTE_DATA; break; case I2C_SMBUS_WORD_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), - SMBHSTADD(priv)); + i801_set_hstadd(priv, addr, read_write); outb_p(command, SMBHSTCMD(priv)); if (read_write == I2C_SMBUS_WRITE) { outb_p(data->word & 0xff, SMBHSTDAT0(priv)); @@ -827,7 +828,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, xact = I801_WORD_DATA; break; case I2C_SMBUS_PROC_CALL: - outb_p((addr & 0x7f) << 1, SMBHSTADD(priv)); + i801_set_hstadd(priv, addr, I2C_SMBUS_WRITE); outb_p(command, SMBHSTCMD(priv)); outb_p(data->word & 0xff, SMBHSTDAT0(priv)); outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); @@ -835,8 +836,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, read_write = I2C_SMBUS_READ; break; case I2C_SMBUS_BLOCK_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), - SMBHSTADD(priv)); + i801_set_hstadd(priv, addr, read_write); outb_p(command, SMBHSTCMD(priv)); block = 1; break; @@ -847,10 +847,9 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, * However if SPD Write Disable is set (Lynx Point and later), * the read will fail if we don't set the R/#W bit. */ - outb_p(((addr & 0x7f) << 1) | - ((priv->original_hstcfg & SMBHSTCFG_SPD_WD) ? - (read_write & 0x01) : 0), - SMBHSTADD(priv)); + i801_set_hstadd(priv, addr, + priv->original_hstcfg & SMBHSTCFG_SPD_WD ? + read_write : I2C_SMBUS_WRITE); if (read_write == I2C_SMBUS_READ) { /* NB: page 240 of ICH5 datasheet also shows * that DATA1 is the cmd field when reading */ @@ -860,11 +859,8 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, block = 1; break; case I2C_SMBUS_BLOCK_PROC_CALL: - /* - * Bit 0 of the slave address register always indicate a write - * command. - */ - outb_p((addr & 0x7f) << 1, SMBHSTADD(priv)); + /* Needs to be flagged as write transaction */ + i801_set_hstadd(priv, addr, I2C_SMBUS_WRITE); outb_p(command, SMBHSTCMD(priv)); block = 1; break; From patchwork Mon Dec 19 18:17:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 636185 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 933B3C10F1B for ; Mon, 19 Dec 2022 18:23:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231726AbiLSSXH (ORCPT ); Mon, 19 Dec 2022 13:23:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229624AbiLSSXE (ORCPT ); Mon, 19 Dec 2022 13:23:04 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72803C2C for ; Mon, 19 Dec 2022 10:23:00 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id b69so14120450edf.6 for ; Mon, 19 Dec 2022 10:23:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=6MqbZ7zxisw40O+aWNampSBdXjbwB1sxUwh2dkiU38Q=; b=BhT1c/qsGSiJL/wzdLe0NrIkVmpfbz06VCVTX4ObsT33nS2K42EfPGTTUiQfPH2q1X 3VnwVeiCf3Nn7z9ATFJiRg3cCc6vEI9yKVoTWXgdvJuYs7roo5fXDE5aOUos1H0VGjU8 pT5zdmWYNDS6O5WZnFQVNbDF1XN8Ripu6Cx6iyZRawSZo+WeA1M8VeoMzrTekO7agTnO RonPozVVL87QeprBAR2B7hjdw3McNrF9K4UxeLzuRJa2C67UFlHWWHivlNY44WyS+Sqb u9AK03hRQQzUvHA9HGotQaQNsYmbTCt7aZmTbIQqTHfA0bXkjf6n839uQyJkmsdj4V2H XmUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6MqbZ7zxisw40O+aWNampSBdXjbwB1sxUwh2dkiU38Q=; b=g9BuIjf+N/U/UHLXjTsUZtogRgYbdpmnzZWB0fOKNIBzKxyHQrVwJmMrt1RD8UC4+G wqPrNZZU+lkCcB2BMAuPJYJxogxDCDufp/zjXHAFFQw3EpoKDpO1ToaY4QVosJ/IoIXp lNxjNIw+B0gra2EzBuiuapGaJ2a6yb76FOFs1r1N1iv78v8JF5jGccL0S4zaPFa/zm9R n4fCnXOZ64Op8zmAmjIUDE1AiTR/jXO/hKVH22nEP/9KttnSiN5TW3lxohTgCDsxTlPe ru92z+4wEMFOB2VvR0rx/U1Aj6uMbKcH9mPUN95LjAQMwWW9qWlz9Jvo0FzKji7a0ru3 /ocQ== X-Gm-Message-State: ANoB5pnu0VGtIoluysARWFJzgPIdGJ4zwnkYhHZgjcvvHAO40QezU3dp cy1gDhbNy14joCZjJxnnNkApOodaYMI= X-Google-Smtp-Source: AA0mqf6KCwj0VeKN3jPWspJZRg+OF12KRqkKdEP6nXEp73NXd52KE8R+JnKYnzb4xBjfXPgjI78Msw== X-Received: by 2002:aa7:cb54:0:b0:46a:96b3:22bf with SMTP id w20-20020aa7cb54000000b0046a96b322bfmr38244355edt.17.1671474179013; Mon, 19 Dec 2022 10:22:59 -0800 (PST) Received: from ?IPV6:2a01:c23:c0aa:f200:2422:8cf4:48af:d322? (dynamic-2a01-0c23-c0aa-f200-2422-8cf4-48af-d322.c23.pool.telefonica.de. [2a01:c23:c0aa:f200:2422:8cf4:48af:d322]) by smtp.googlemail.com with ESMTPSA id e2-20020a50ec82000000b0045723aa48ccsm4627715edr.93.2022.12.19.10.22.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Dec 2022 10:22:58 -0800 (PST) Message-ID: Date: Mon, 19 Dec 2022 19:17:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH v2 05/10] i2c: i801: add i801_simple_transaction(), complementing i801_block_transaction() Content-Language: en-US From: Heiner Kallweit To: Jean Delvare Cc: "linux-i2c@vger.kernel.org" References: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> In-Reply-To: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This patch factors out non-block pre/post processing to a new function i801_simple_transaction(), complementing existing function i801_block_transaction(). This makes i801_access() better readable. Signed-off-by: Heiner Kallweit --- v2: - rename new function to i801_simple_transaction - code style fixes --- drivers/i2c/busses/i2c-i801.c | 92 +++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 37 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 882cf5135..d934d410b 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -732,6 +732,59 @@ static void i801_set_hstadd(struct i801_priv *priv, u8 addr, char read_write) outb_p((addr << 1) | (read_write & 0x01), SMBHSTADD(priv)); } +/* Single value transaction function */ +static int i801_simple_transaction(struct i801_priv *priv, union i2c_smbus_data *data, + char read_write, int command) +{ + int xact, ret; + + switch (command) { + case I2C_SMBUS_QUICK: + xact = I801_QUICK; + break; + case I2C_SMBUS_BYTE: + xact = I801_BYTE; + break; + case I2C_SMBUS_BYTE_DATA: + if (read_write == I2C_SMBUS_WRITE) + outb_p(data->byte, SMBHSTDAT0(priv)); + xact = I801_BYTE_DATA; + break; + case I2C_SMBUS_WORD_DATA: + if (read_write == I2C_SMBUS_WRITE) { + outb_p(data->word & 0xff, SMBHSTDAT0(priv)); + outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); + } + xact = I801_WORD_DATA; + break; + case I2C_SMBUS_PROC_CALL: + outb_p(data->word & 0xff, SMBHSTDAT0(priv)); + outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); + xact = I801_PROC_CALL; + break; + default: + return -EOPNOTSUPP; + } + + ret = i801_transaction(priv, xact); + if (ret || read_write == I2C_SMBUS_WRITE) + return ret; + + switch (command) { + case I2C_SMBUS_BYTE: + case I2C_SMBUS_BYTE_DATA: + data->byte = inb_p(SMBHSTDAT0(priv)); + break; + case I2C_SMBUS_WORD_DATA: + case I2C_SMBUS_PROC_CALL: + data->word = inb_p(SMBHSTDAT0(priv)) + + (inb_p(SMBHSTDAT1(priv)) << 8); + break; + } + + return 0; +} + /* Block transaction function */ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *data, char read_write, int command) @@ -783,9 +836,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, unsigned short flags, char read_write, u8 command, int size, union i2c_smbus_data *data) { - int hwpec; - int block = 0; - int ret, xact; + int hwpec, ret, block = 0; struct i801_priv *priv = i2c_get_adapdata(adap); mutex_lock(&priv->acpi_lock); @@ -803,36 +854,23 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, switch (size) { case I2C_SMBUS_QUICK: i801_set_hstadd(priv, addr, read_write); - xact = I801_QUICK; break; case I2C_SMBUS_BYTE: i801_set_hstadd(priv, addr, read_write); if (read_write == I2C_SMBUS_WRITE) outb_p(command, SMBHSTCMD(priv)); - xact = I801_BYTE; break; case I2C_SMBUS_BYTE_DATA: i801_set_hstadd(priv, addr, read_write); outb_p(command, SMBHSTCMD(priv)); - if (read_write == I2C_SMBUS_WRITE) - outb_p(data->byte, SMBHSTDAT0(priv)); - xact = I801_BYTE_DATA; break; case I2C_SMBUS_WORD_DATA: i801_set_hstadd(priv, addr, read_write); outb_p(command, SMBHSTCMD(priv)); - if (read_write == I2C_SMBUS_WRITE) { - outb_p(data->word & 0xff, SMBHSTDAT0(priv)); - outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); - } - xact = I801_WORD_DATA; break; case I2C_SMBUS_PROC_CALL: i801_set_hstadd(priv, addr, I2C_SMBUS_WRITE); outb_p(command, SMBHSTCMD(priv)); - outb_p(data->word & 0xff, SMBHSTDAT0(priv)); - outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); - xact = I801_PROC_CALL; read_write = I2C_SMBUS_READ; break; case I2C_SMBUS_BLOCK_DATA: @@ -880,7 +918,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, if (block) ret = i801_block_transaction(priv, data, read_write, size); else - ret = i801_transaction(priv, xact); + ret = i801_simple_transaction(priv, data, read_write, size); /* Some BIOSes don't like it when PEC is enabled at reboot or resume time, so we forcibly disable it after every transaction. Turn off @@ -888,26 +926,6 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, if (hwpec || block) outb_p(inb_p(SMBAUXCTL(priv)) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv)); - - if (block) - goto out; - if (ret) - goto out; - if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) - goto out; - - switch (xact) { - case I801_BYTE: /* Result put in SMBHSTDAT0 */ - case I801_BYTE_DATA: - data->byte = inb_p(SMBHSTDAT0(priv)); - break; - case I801_WORD_DATA: - case I801_PROC_CALL: - data->word = inb_p(SMBHSTDAT0(priv)) + - (inb_p(SMBHSTDAT1(priv)) << 8); - break; - } - out: /* * Unlock the SMBus device for use by BIOS/ACPI, From patchwork Mon Dec 19 18:20:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 636186 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DF77C4167B for ; Mon, 19 Dec 2022 18:23:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231967AbiLSSXD (ORCPT ); Mon, 19 Dec 2022 13:23:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229624AbiLSSXC (ORCPT ); Mon, 19 Dec 2022 13:23:02 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EBFD614D for ; Mon, 19 Dec 2022 10:23:01 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id tz12so23579803ejc.9 for ; Mon, 19 Dec 2022 10:23:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=jK6KmbWQc12uPIL5Io/OFJx758G/bZ5ohdHTweC19WI=; b=aiCrjE4XspXfTtLUOkwHjpvPb2cYRW2a2bTssMz9BD/YAhEjCCpU1vN5uZITQoak9N I02l9hY12BQBGwQ78YlTSAxuJFDkcwmnFbAPk5ju3LxN3HnQC2p7XQsnEbEEWiZlzqJM HVLHZ+wVp+/5IQrvOBcaR2lSbEPfKCggGKWVjS/0DTTr+YDyGlua3SJB6oLOZU1F9b47 tgBGftxT3uuk4xfWph35sGR61DjeSR1+hsC+2uy62VzBBKbLjK0HilmkTudPkBgLX2aF tV1D7QXdSQAbntIhPyrcMg+dGBG8PMexT1pglAHl4ug5PN0HEOec0Q6MydHanWoFv3gs 81Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jK6KmbWQc12uPIL5Io/OFJx758G/bZ5ohdHTweC19WI=; b=kPpvCg9CEhdO0b8Fu3/eBAnX7K+iWBzmx8/4+UQ1Ly57FFVtQjf+EFF/RTvBD5E5y8 XkQDfMqvsqRGdg3r7YoQ/+FXqAzZurx2AKrOvb0W7JJgtFduqVqWOV66yjKFWNPMJqqp fFcu7OFB5mTxY2D5cjI2ozqfke1w1soR613KESlyaNP0WObkkRPPUKS9QOTtiBqDf2Sx jfVSa+TG2llJG8cvAHLaqJGveXCavbogPqoNN13XppB7uPv8+0qPOfvje7P0Gp/mius6 VdD4BROLqoE8+LgIxsEQ7rTT0tL0s6fdahHQJ0pvmrbLZZP/tSbOsPq8P+Jwp52tHoau 0z9w== X-Gm-Message-State: AFqh2kq48K1C1AGYNrR3FwR852505MR5Ywcu4UoZq+ynePigiqPI2w2T o9Ohh0GQPohUwrC/2pZNVTyXFRgnOGE= X-Google-Smtp-Source: AMrXdXuFlobrcqAPsB0MYJy/a6zmrIcZmslhxaygLzyDjW7BzDW8tvu5+lItK/Hv+antE3UG9F0rcQ== X-Received: by 2002:a17:907:110a:b0:7c1:4bb2:f62b with SMTP id qu10-20020a170907110a00b007c14bb2f62bmr2482137ejb.27.1671474179760; Mon, 19 Dec 2022 10:22:59 -0800 (PST) Received: from ?IPV6:2a01:c23:c0aa:f200:2422:8cf4:48af:d322? (dynamic-2a01-0c23-c0aa-f200-2422-8cf4-48af-d322.c23.pool.telefonica.de. [2a01:c23:c0aa:f200:2422:8cf4:48af:d322]) by smtp.googlemail.com with ESMTPSA id f3-20020a17090631c300b007c0f2d051f4sm4642048ejf.203.2022.12.19.10.22.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Dec 2022 10:22:59 -0800 (PST) Message-ID: <0ef3e6f9-471f-ff05-0cf0-046d79a4c820@gmail.com> Date: Mon, 19 Dec 2022 19:20:10 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH v2 06/10] i2c: i801: handle SMBAUXCTL_E32B in i801_block_transaction_by_block only Content-Language: en-US From: Heiner Kallweit To: Jean Delvare Cc: "linux-i2c@vger.kernel.org" References: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> In-Reply-To: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Currently we touch SMBAUXCTL even if not needed. That's the case for block commands that don't use block buffer mode, either because block buffer mode isn't available or because it's not supported for the respective command (e.g. I2C block transfer). Improve this by setting/resetting SMBAUXCTL_E32B in i801_block_transaction_by_block() only. Small downside is that we know access SMBAUXCTL twice for transactions that use PEC and block buffer mode. But this should a rather rare case and the impact is negligible. Signed-off-by: Heiner Kallweit --- drivers/i2c/busses/i2c-i801.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index d934d410b..d7182f7c8 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -511,19 +511,23 @@ static int i801_block_transaction_by_block(struct i801_priv *priv, status = i801_transaction(priv, xact); if (status) - return status; + goto out; if (read_write == I2C_SMBUS_READ || command == I2C_SMBUS_BLOCK_PROC_CALL) { len = inb_p(SMBHSTDAT0(priv)); - if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) - return -EPROTO; + if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) { + status = -EPROTO; + goto out; + } data->block[0] = len; for (i = 0; i < len; i++) data->block[i + 1] = inb_p(SMBBLKDAT(priv)); } - return 0; +out: + outb_p(inb_p(SMBAUXCTL(priv)) & ~SMBAUXCTL_E32B, SMBAUXCTL(priv)); + return status; } static void i801_isr_byte_done(struct i801_priv *priv) @@ -921,11 +925,10 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, ret = i801_simple_transaction(priv, data, read_write, size); /* Some BIOSes don't like it when PEC is enabled at reboot or resume - time, so we forcibly disable it after every transaction. Turn off - E32B for the same reason. */ - if (hwpec || block) - outb_p(inb_p(SMBAUXCTL(priv)) & - ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv)); + * time, so we forcibly disable it after every transaction. + */ + if (hwpec) + outb_p(inb_p(SMBAUXCTL(priv)) & ~SMBAUXCTL_CRC, SMBAUXCTL(priv)); out: /* * Unlock the SMBus device for use by BIOS/ACPI, From patchwork Mon Dec 19 18:20:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 635323 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BB9BC4332F for ; Mon, 19 Dec 2022 18:23:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232249AbiLSSXF (ORCPT ); Mon, 19 Dec 2022 13:23:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231726AbiLSSXF (ORCPT ); Mon, 19 Dec 2022 13:23:05 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD3BD12759 for ; Mon, 19 Dec 2022 10:23:01 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id m18so23614522eji.5 for ; Mon, 19 Dec 2022 10:23:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=U8VbXn8XScU5BLKHdRb3w1AK1xB72QQTuKSLXd0r5pY=; b=NYcnqH1X7t6/iWfiQUfxu/xemUGAfzFuHxybzpkRisGvBr4Lpvb8gDx4YMuJfsawLF fu/Y8WPCVPLWW/7hlW2ZIj2CLgAgs7fxIfkyFGw+7YwwELV/rxLQk6FjFIBWiGF43KiR hhoneWUvU5rK1XP5KjlDqjmGpWowmsaCF86O7wtilzrIn/cR9/BMgVDjBbLA0ErGYcB9 mesb/TMOtYebvv/XZ1CwlZzdR128QOsGa+hH9ct4h5KBQdCszu5VmAVqDYFIXzMZfZUJ oSjUdl6bvdc6kNFXi8ECdRwuO4jHdhliiuy41obhnHO0ZXtfF1vsYvUVLmA0D3r2Qx+o 5aMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U8VbXn8XScU5BLKHdRb3w1AK1xB72QQTuKSLXd0r5pY=; b=br+TADZ0S0fn1ivmQt+OdvVbSB7tdz80fmVZgmqCrGxnubm/n7ryZg2pvbt0tm+85o sosVXdH7M5gtk2hHLy6gwe/m8mkmaF4RCnmG7yuckhuNqwUe2jCXvwMKbTE4A6/Ct/jb 1j5H1gZgXZ0H0k9HulU1+Ys888YRuRixsPab1KCnOwjH97H6JAV3XwALLLcHddRQwbIC F3K5vABN9wEvykvdmNdcDXIXjytCcSaqicPRME6zzyYCbILJvhOYd/OVGvXHacBFK4h9 BdVLFZNnIR3zXTcP02vU+rplw2uzKiDss3DQQPFyW5dyAgPoxNvSgWWyVpiJmzpu0HoK 0Oag== X-Gm-Message-State: AFqh2koKMk3cEmSOzpdzHbm2pqg0pijMLQL3PvjY0ZJPKA9kUWe3WXPf PCSL8FUZbPj26TAvF73stzoTe9M44RE= X-Google-Smtp-Source: AMrXdXtsfOZMQrHsku9liuJepvLOfAF3/te2DaN6qSw0xoESiC/MVj0IrAjuPAt3ueEe5cgkeBARvA== X-Received: by 2002:a17:906:a4d:b0:7f7:a985:1849 with SMTP id x13-20020a1709060a4d00b007f7a9851849mr11805787ejf.24.1671474180448; Mon, 19 Dec 2022 10:23:00 -0800 (PST) Received: from ?IPV6:2a01:c23:c0aa:f200:2422:8cf4:48af:d322? (dynamic-2a01-0c23-c0aa-f200-2422-8cf4-48af-d322.c23.pool.telefonica.de. [2a01:c23:c0aa:f200:2422:8cf4:48af:d322]) by smtp.googlemail.com with ESMTPSA id i7-20020a1709063c4700b007c08439161dsm4680738ejg.50.2022.12.19.10.23.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Dec 2022 10:23:00 -0800 (PST) Message-ID: <2fca168d-9f31-1c50-ebde-3e4023d84423@gmail.com> Date: Mon, 19 Dec 2022 19:20:55 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH v2 07/10] i2c: i801: centralize configuring non-block commands in i801_simple_transaction Content-Language: en-US From: Heiner Kallweit To: Jean Delvare Cc: "linux-i2c@vger.kernel.org" References: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> In-Reply-To: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Currently configuring command register settings is disributed over multiple functions. At first cetralize this for non-block commands in i801_simple_transaction(). Signed-off-by: Heiner Kallweit Reviewed-by: Jean Delvare --- drivers/i2c/busses/i2c-i801.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index d7182f7c8..0d49e9587 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -738,35 +738,47 @@ static void i801_set_hstadd(struct i801_priv *priv, u8 addr, char read_write) /* Single value transaction function */ static int i801_simple_transaction(struct i801_priv *priv, union i2c_smbus_data *data, - char read_write, int command) + u8 addr, u8 hstcmd, char read_write, int command) { int xact, ret; switch (command) { case I2C_SMBUS_QUICK: + i801_set_hstadd(priv, addr, read_write); xact = I801_QUICK; break; case I2C_SMBUS_BYTE: + i801_set_hstadd(priv, addr, read_write); + if (read_write == I2C_SMBUS_WRITE) + outb_p(hstcmd, SMBHSTCMD(priv)); xact = I801_BYTE; break; case I2C_SMBUS_BYTE_DATA: + i801_set_hstadd(priv, addr, read_write); if (read_write == I2C_SMBUS_WRITE) outb_p(data->byte, SMBHSTDAT0(priv)); + outb_p(hstcmd, SMBHSTCMD(priv)); xact = I801_BYTE_DATA; break; case I2C_SMBUS_WORD_DATA: + i801_set_hstadd(priv, addr, read_write); if (read_write == I2C_SMBUS_WRITE) { outb_p(data->word & 0xff, SMBHSTDAT0(priv)); outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); } + outb_p(hstcmd, SMBHSTCMD(priv)); xact = I801_WORD_DATA; break; case I2C_SMBUS_PROC_CALL: + i801_set_hstadd(priv, addr, I2C_SMBUS_WRITE); outb_p(data->word & 0xff, SMBHSTDAT0(priv)); outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); + outb_p(hstcmd, SMBHSTCMD(priv)); + read_write = I2C_SMBUS_READ; xact = I801_PROC_CALL; break; default: + pci_err(priv->pci_dev, "Unsupported transaction %d\n", command); return -EOPNOTSUPP; } @@ -857,25 +869,10 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, switch (size) { case I2C_SMBUS_QUICK: - i801_set_hstadd(priv, addr, read_write); - break; case I2C_SMBUS_BYTE: - i801_set_hstadd(priv, addr, read_write); - if (read_write == I2C_SMBUS_WRITE) - outb_p(command, SMBHSTCMD(priv)); - break; case I2C_SMBUS_BYTE_DATA: - i801_set_hstadd(priv, addr, read_write); - outb_p(command, SMBHSTCMD(priv)); - break; case I2C_SMBUS_WORD_DATA: - i801_set_hstadd(priv, addr, read_write); - outb_p(command, SMBHSTCMD(priv)); - break; case I2C_SMBUS_PROC_CALL: - i801_set_hstadd(priv, addr, I2C_SMBUS_WRITE); - outb_p(command, SMBHSTCMD(priv)); - read_write = I2C_SMBUS_READ; break; case I2C_SMBUS_BLOCK_DATA: i801_set_hstadd(priv, addr, read_write); @@ -922,7 +919,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, if (block) ret = i801_block_transaction(priv, data, read_write, size); else - ret = i801_simple_transaction(priv, data, read_write, size); + ret = i801_simple_transaction(priv, data, addr, command, read_write, size); /* Some BIOSes don't like it when PEC is enabled at reboot or resume * time, so we forcibly disable it after every transaction. From patchwork Mon Dec 19 18:21:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 635321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C1E8C10F1B for ; Mon, 19 Dec 2022 18:23:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231670AbiLSSXJ (ORCPT ); Mon, 19 Dec 2022 13:23:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232245AbiLSSXF (ORCPT ); Mon, 19 Dec 2022 13:23:05 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A15C1614D for ; Mon, 19 Dec 2022 10:23:02 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id d20so14207332edn.0 for ; Mon, 19 Dec 2022 10:23:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=SS8F1eybluXikfga57LpXk9XR7mh2jagKkWcoJ9oiAc=; b=TKM+/gw99y1/S2Z9/idq5l0mDuLtKJe47xObG4PEiFzu/OnEo3XvDVqqDeXnTeb5SB /Eb9OQIN4OaAp9He6CmZuHIGELR2L/AcwNLox0Bdlapmq1uhyYgG8yHkt62wOA5Yj1qp 3EopDC7xDleNmv/aoYDWky52dAV+1K16iih9VnrH+g1Xgh8mQAdOjw1qYKQjObeov6ab yh1kgluXHQ2/fhE8QJKAvC5UMPTCbzDjXeP/9swJg/gKS+ZHXYZMhuDGh6B+s/j8f82r 99/Pw1TKcFI36+QM6ZUB+qhHHYK+5IyMXCXn4ZFfeS5+9gfKJ9WRFajhYb/CPa61MzDn 9u/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SS8F1eybluXikfga57LpXk9XR7mh2jagKkWcoJ9oiAc=; b=gDzDWEdXFHBJC7tEbTTSqr8n9n5T62vT5lQASJpe7NVwdDvnmJGlVHPC8KIf3ILgCc b49+loMjG9TAJhEUH1kxZUmWnZw/0Vqx/uYjd59829SAFNFXgouGAP9A9vDPRgMlDlq7 v9uVu3kFR/0AKdeC0J/a8yddYsiAMnqMnwM76hVOLHXjT0mUSGK8GbsgQZ+AWN+sryYP p5KcLOfiSuqunpWryFpRn9nMQYjtsdhazWmKDWABeB6/YAA8Vo9/SvTeCdLLX71QxeWu b9dQBbMZe+5Ji+QfzVClz/P2FWY6SMQmkh0VKU5DVGs6nfJWVjbIu5xTqUD1ggDqD4rX 87Gw== X-Gm-Message-State: ANoB5pkEsp9ccsBf818FSxseQcBP6mPz88ytAeqpV6liYcFsRHyJv328 VeCpg8qsJ12wMoqNXbTicXdBLq7GxPY= X-Google-Smtp-Source: AA0mqf7R7JY3viUROQbCyPcI6cHrFgKRK4QBLpIs7XVxNKQKkHqNhZCv6SfDwOm+ptaIoOwn8IBAmA== X-Received: by 2002:a05:6402:2b8b:b0:468:58d4:a0f2 with SMTP id fj11-20020a0564022b8b00b0046858d4a0f2mr32835779edb.23.1671474181221; Mon, 19 Dec 2022 10:23:01 -0800 (PST) Received: from ?IPV6:2a01:c23:c0aa:f200:2422:8cf4:48af:d322? (dynamic-2a01-0c23-c0aa-f200-2422-8cf4-48af-d322.c23.pool.telefonica.de. [2a01:c23:c0aa:f200:2422:8cf4:48af:d322]) by smtp.googlemail.com with ESMTPSA id f4-20020a17090631c400b007adf2e4c6f7sm4674920ejf.195.2022.12.19.10.23.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Dec 2022 10:23:00 -0800 (PST) Message-ID: <83fd2bd5-1f49-4943-ca67-e774f98905cb@gmail.com> Date: Mon, 19 Dec 2022 19:21:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH v2 08/10] i2c: i801: centralize configuring block commands in i801_block_transaction Content-Language: en-US From: Heiner Kallweit To: Jean Delvare Cc: "linux-i2c@vger.kernel.org" References: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> In-Reply-To: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Similar to the patch for non-block commands, centralize block command register settings in i801_block_transaction(). Signed-off-by: Heiner Kallweit --- drivers/i2c/busses/i2c-i801.c | 85 +++++++++++++++-------------------- 1 file changed, 36 insertions(+), 49 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 0d49e9587..78663d8df 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -803,7 +803,7 @@ static int i801_simple_transaction(struct i801_priv *priv, union i2c_smbus_data /* Block transaction function */ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *data, - char read_write, int command) + u8 addr, u8 hstcmd, char read_write, int command) { int result = 0; unsigned char hostc; @@ -813,7 +813,29 @@ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data * else if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX) return -EPROTO; - if (command == I2C_SMBUS_I2C_BLOCK_DATA) { + switch (command) { + case I2C_SMBUS_BLOCK_DATA: + i801_set_hstadd(priv, addr, read_write); + outb_p(hstcmd, SMBHSTCMD(priv)); + break; + case I2C_SMBUS_I2C_BLOCK_DATA: + /* + * NB: page 240 of ICH5 datasheet shows that the R/#W + * bit should be cleared here, even when reading. + * However if SPD Write Disable is set (Lynx Point and later), + * the read will fail if we don't set the R/#W bit. + */ + i801_set_hstadd(priv, addr, + priv->original_hstcfg & SMBHSTCFG_SPD_WD ? + read_write : I2C_SMBUS_WRITE); + if (read_write == I2C_SMBUS_READ) { + /* NB: page 240 of ICH5 datasheet also shows + * that DATA1 is the cmd field when reading + */ + outb_p(hstcmd, SMBHSTDAT1(priv)); + } else + outb_p(hstcmd, SMBHSTCMD(priv)); + if (read_write == I2C_SMBUS_WRITE) { /* set I2C_EN bit in configuration register */ pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc); @@ -824,6 +846,13 @@ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data * "I2C block read is unsupported!\n"); return -EOPNOTSUPP; } + + break; + case I2C_SMBUS_BLOCK_PROC_CALL: + /* Needs to be flagged as write transaction */ + i801_set_hstadd(priv, addr, I2C_SMBUS_WRITE); + outb_p(hstcmd, SMBHSTCMD(priv)); + break; } /* Experience has shown that the block buffer can only be used for @@ -852,7 +881,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, unsigned short flags, char read_write, u8 command, int size, union i2c_smbus_data *data) { - int hwpec, ret, block = 0; + int hwpec, ret; struct i801_priv *priv = i2c_get_adapdata(adap); mutex_lock(&priv->acpi_lock); @@ -867,57 +896,16 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, && size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA; - switch (size) { - case I2C_SMBUS_QUICK: - case I2C_SMBUS_BYTE: - case I2C_SMBUS_BYTE_DATA: - case I2C_SMBUS_WORD_DATA: - case I2C_SMBUS_PROC_CALL: - break; - case I2C_SMBUS_BLOCK_DATA: - i801_set_hstadd(priv, addr, read_write); - outb_p(command, SMBHSTCMD(priv)); - block = 1; - break; - case I2C_SMBUS_I2C_BLOCK_DATA: - /* - * NB: page 240 of ICH5 datasheet shows that the R/#W - * bit should be cleared here, even when reading. - * However if SPD Write Disable is set (Lynx Point and later), - * the read will fail if we don't set the R/#W bit. - */ - i801_set_hstadd(priv, addr, - priv->original_hstcfg & SMBHSTCFG_SPD_WD ? - read_write : I2C_SMBUS_WRITE); - if (read_write == I2C_SMBUS_READ) { - /* NB: page 240 of ICH5 datasheet also shows - * that DATA1 is the cmd field when reading */ - outb_p(command, SMBHSTDAT1(priv)); - } else - outb_p(command, SMBHSTCMD(priv)); - block = 1; - break; - case I2C_SMBUS_BLOCK_PROC_CALL: - /* Needs to be flagged as write transaction */ - i801_set_hstadd(priv, addr, I2C_SMBUS_WRITE); - outb_p(command, SMBHSTCMD(priv)); - block = 1; - break; - default: - dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n", - size); - ret = -EOPNOTSUPP; - goto out; - } - if (hwpec) /* enable/disable hardware PEC */ outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv)); else outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC), SMBAUXCTL(priv)); - if (block) - ret = i801_block_transaction(priv, data, read_write, size); + if (size == I2C_SMBUS_BLOCK_DATA || + size == I2C_SMBUS_I2C_BLOCK_DATA || + size == I2C_SMBUS_BLOCK_PROC_CALL) + ret = i801_block_transaction(priv, data, addr, command, read_write, size); else ret = i801_simple_transaction(priv, data, addr, command, read_write, size); @@ -926,7 +914,6 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, */ if (hwpec) outb_p(inb_p(SMBAUXCTL(priv)) & ~SMBAUXCTL_CRC, SMBAUXCTL(priv)); -out: /* * Unlock the SMBus device for use by BIOS/ACPI, * and clear status flags if not done already. From patchwork Mon Dec 19 18:22:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 635322 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F387CC4167B for ; Mon, 19 Dec 2022 18:23:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229624AbiLSSXH (ORCPT ); Mon, 19 Dec 2022 13:23:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232243AbiLSSXF (ORCPT ); Mon, 19 Dec 2022 13:23:05 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50F3513D74 for ; Mon, 19 Dec 2022 10:23:03 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id r26so14091464edc.10 for ; Mon, 19 Dec 2022 10:23:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=GLFbHxD8YKH/9Oz6exMSfQ6VVx7Z2wXPdU8AOvF1u/Q=; b=pvXna3RxNpn25KSSOpXXEsLcWXZArFBsgDj9SCkGuRCCjXXpGKxQJh+tE7upmjzhqT 1mLnzpZwpduhlwNS1OQ0fc+QKpxxkC8xHvoLQQgSvsdpGTIZB4mZKEaBV3LfUDy5T0hF VGyj6ZIb3FlWW9xD+fVZkGQmOOBufwZmTQ15Y51LAaJCbe3xSyUKewTJO0/AHbpRKt0z J60yQ0QZQJs7tl3BDDrQOfKkYrXfwaumYHvP3Rr8sZcjScfiPiQUeWSYc+s4jMzaTeZu EHFdJ/h+i1xMaIMim8Ee8pzC6kWsZcP5WyNl0aWucLMI902/5XaiaChBNGGK+sHd21oU QTPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GLFbHxD8YKH/9Oz6exMSfQ6VVx7Z2wXPdU8AOvF1u/Q=; b=Po/Hmgn4WEpirsdEnYdAEactC8sO8tGVM1k6kUZ2Pw0g7Yn2jVrdosZ6GS65nzbHMg gL0K4/+3Pb7iZXGmlxxKzxivUZ7B3pIhICRHAfjGyfginatqpVcslngZ72DiOGE4hd6V Tp22J6c2Kq6dR0W+wfYv+MGoaexFbM1O/n1SoUBZKt/8Z7CKNiaUoRDafCjx+3jNhRF6 GI5gpmCzVL6jvPYOVlVHAe/DPtZ6OjiNekcWUMkBCKZ7WVM4xYGAkeHCRktAmZa/7oNk ZDvy+fKZvtv2d/4RpD1gxa+P1qvNUXj5yu8afl6BfHFy2IJaO1AQWRnJt6BGurxuPQb9 KRKA== X-Gm-Message-State: AFqh2kr7NBrPEZJAhPEE0WupaA3tGwuxCrJf3ylHDoo3JbT0jl3/YMR1 Owr+IFAdRVOiFUgbmKC5icW+U0nNn8s= X-Google-Smtp-Source: AMrXdXuGB/fUdGcP2CZYyxA3VD8vE3S1NBv852LebOlwYrD/hk+ljLK2k8vh7kJRnr2mc8M4H9Pzqg== X-Received: by 2002:a05:6402:1944:b0:475:7dbf:7040 with SMTP id f4-20020a056402194400b004757dbf7040mr13771135edz.42.1671474181926; Mon, 19 Dec 2022 10:23:01 -0800 (PST) Received: from ?IPV6:2a01:c23:c0aa:f200:2422:8cf4:48af:d322? (dynamic-2a01-0c23-c0aa-f200-2422-8cf4-48af-d322.c23.pool.telefonica.de. [2a01:c23:c0aa:f200:2422:8cf4:48af:d322]) by smtp.googlemail.com with ESMTPSA id j21-20020aa7ca55000000b0045c47b2a800sm4609723edt.67.2022.12.19.10.23.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Dec 2022 10:23:01 -0800 (PST) Message-ID: <6ce494a1-6d7e-4a87-f6ed-ffee176c163c@gmail.com> Date: Mon, 19 Dec 2022 19:22:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH v2 09/10] i2c: i801: call i801_check_pre() from i801_access() Content-Language: en-US From: Heiner Kallweit To: Jean Delvare Cc: "linux-i2c@vger.kernel.org" References: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> In-Reply-To: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This avoids code duplication, in a next step we'll call i801_check_post() from i801_transaction() as well. Reviewed-by: Jean Delvare Signed-off-by: Heiner Kallweit --- drivers/i2c/busses/i2c-i801.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 78663d8df..4b5fb2c61 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -462,10 +462,6 @@ static int i801_transaction(struct i801_priv *priv, int xact) unsigned long result; const struct i2c_adapter *adap = &priv->adapter; - status = i801_check_pre(priv); - if (status < 0) - return status; - if (priv->features & FEATURE_IRQ) { reinit_completion(&priv->done); outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START, @@ -653,10 +649,6 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv, if (command == I2C_SMBUS_BLOCK_PROC_CALL) return -EOPNOTSUPP; - status = i801_check_pre(priv); - if (status < 0) - return status; - len = data->block[0]; if (read_write == I2C_SMBUS_WRITE) { @@ -892,6 +884,10 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, pm_runtime_get_sync(&priv->pci_dev->dev); + ret = i801_check_pre(priv); + if (ret) + goto out; + hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA; @@ -914,6 +910,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, */ if (hwpec) outb_p(inb_p(SMBAUXCTL(priv)) & ~SMBAUXCTL_CRC, SMBAUXCTL(priv)); +out: /* * Unlock the SMBus device for use by BIOS/ACPI, * and clear status flags if not done already. From patchwork Mon Dec 19 18:22:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 636184 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB903C4332F for ; Mon, 19 Dec 2022 18:23:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232243AbiLSSXI (ORCPT ); Mon, 19 Dec 2022 13:23:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232225AbiLSSXF (ORCPT ); Mon, 19 Dec 2022 13:23:05 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B70B13D64 for ; Mon, 19 Dec 2022 10:23:03 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id n20so23720282ejh.0 for ; Mon, 19 Dec 2022 10:23:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=16C8DHb//JLX5SNLT9iZxVSsHPYyMhSVUrSupsu/ioc=; b=AodjOFiVuPqz8RNKks5H0vHgWCLGrXbTDhX2YJbI4SbWvzBpN0CdGiPYz5tGO0O3NU fDX0ZchwcgbpsarooryQ9PziMi2wmjDGUY6Q6I4fqchrfMZy6hyK5FoiBwsJHWZE97Aj W5OaVhODHnn9Y+ct3rxCR+LTQQYUZ4cmXXdUVxxDRG+dLvVh4LjFTddiT0SDpCeTFuFV FtSY5Tldmyzp1WqDX6eIU0AakBShTxGYfzm8mGnAFAiZpiXVkORQNyewa8ziFjYqAqH2 /rxB1hTSEh2s2GkmAAnGK3SclBoyVkeNbjQbnx/g6gkDYg6L+BRTA7YRXC7NAssLDYUL TiFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=16C8DHb//JLX5SNLT9iZxVSsHPYyMhSVUrSupsu/ioc=; b=rJotDl6TubEtniYrVaCJ/vJwvHNIqmBiSLOAOA2+iLGDE7SnnswzQFFhTW+DGvsqtf i6M3jHQmIeAq1B6SAzXjQ2DfG2e3sEmEOCQzrOsufuHLhked2aHT1Y1DoBKuT4cPT8QI PwXpj2yc26y4iyk0fvmKtTOoWYeKb16cFFYz2lT7QoQMli8RsC3zyrMFmysXd+4PI7zk l46gZZVDQT2nkxqsPuQgAfKzn55M9HikOcUh61qxr3RXzOltYrXek2Z6D29ZMAJ4/kz9 dVvmKhfD5fpcncqo0jrbo0OYYmQL6W2Tn7oJ2BpYJTZny5zwQQJ/eMwjKXhmil6pMNj9 /g+Q== X-Gm-Message-State: ANoB5pnWBBibaaMIJpV8nk1qSzIcjpwfO5K9PIFzXS6FBs1bVOn4WEBc qiBZ5xfzslaANzHPZvs9MGrMkvDlDB4= X-Google-Smtp-Source: AA0mqf7QMnZE1CshD+l4T3/EXD5J6zKsHtRTJJIn/1vaY4Aiv8DMlMaYMXbQN4S0T3RLn+TGSU8l/w== X-Received: by 2002:a17:906:ae46:b0:7c0:aa0b:b0d7 with SMTP id lf6-20020a170906ae4600b007c0aa0bb0d7mr22211866ejb.50.1671474182682; Mon, 19 Dec 2022 10:23:02 -0800 (PST) Received: from ?IPV6:2a01:c23:c0aa:f200:2422:8cf4:48af:d322? (dynamic-2a01-0c23-c0aa-f200-2422-8cf4-48af-d322.c23.pool.telefonica.de. [2a01:c23:c0aa:f200:2422:8cf4:48af:d322]) by smtp.googlemail.com with ESMTPSA id kz6-20020a17090777c600b007c0aefd9339sm4763220ejc.175.2022.12.19.10.23.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Dec 2022 10:23:02 -0800 (PST) Message-ID: <0a170b74-c105-7ca3-9811-a370c81462b8@gmail.com> Date: Mon, 19 Dec 2022 19:22:42 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH v2 10/10] i2c: i801: call i801_check_post() from i801_access() Content-Language: en-US From: Heiner Kallweit To: Jean Delvare Cc: "linux-i2c@vger.kernel.org" References: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> In-Reply-To: <8db86d89-d083-2a65-76a1-6db34f433604@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Avoid code duplication by calling i801_check_post() from i801_access(). Signed-off-by: Heiner Kallweit Reviewed-by: Jean Delvare --- drivers/i2c/busses/i2c-i801.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 4b5fb2c61..7313efadf 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -434,7 +434,7 @@ static int i801_wait_intr(struct i801_priv *priv) busy = status & SMBHSTSTS_HOST_BUSY; status &= STATUS_ERROR_FLAGS | SMBHSTSTS_INTR; if (!busy && status) - return status; + return status & STATUS_ERROR_FLAGS; } while (time_is_after_eq_jiffies(timeout)); return -ETIMEDOUT; @@ -458,7 +458,6 @@ static int i801_wait_byte_done(struct i801_priv *priv) static int i801_transaction(struct i801_priv *priv, int xact) { - int status; unsigned long result; const struct i2c_adapter *adap = &priv->adapter; @@ -467,13 +466,12 @@ static int i801_transaction(struct i801_priv *priv, int xact) outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START, SMBHSTCNT(priv)); result = wait_for_completion_timeout(&priv->done, adap->timeout); - return i801_check_post(priv, result ? priv->status : -ETIMEDOUT); + return result ? priv->status : -ETIMEDOUT; } outb_p(xact | SMBHSTCNT_START, SMBHSTCNT(priv)); - status = i801_wait_intr(priv); - return i801_check_post(priv, status); + return i801_wait_intr(priv); } static int i801_block_transaction_by_block(struct i801_priv *priv, @@ -624,7 +622,7 @@ static irqreturn_t i801_isr(int irq, void *dev_id) status &= STATUS_ERROR_FLAGS | SMBHSTSTS_INTR; if (status) { - priv->status = status; + priv->status = status & STATUS_ERROR_FLAGS; complete(&priv->done); } @@ -674,7 +672,7 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv, reinit_completion(&priv->done); outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv)); result = wait_for_completion_timeout(&priv->done, adap->timeout); - return i801_check_post(priv, result ? priv->status : -ETIMEDOUT); + return result ? priv->status : -ETIMEDOUT; } for (i = 1; i <= len; i++) { @@ -688,7 +686,7 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv, status = i801_wait_byte_done(priv); if (status) - goto exit; + return status; if (i == 1 && read_write == I2C_SMBUS_READ && command != I2C_SMBUS_I2C_BLOCK_DATA) { @@ -718,9 +716,7 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv, outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv)); } - status = i801_wait_intr(priv); -exit: - return i801_check_post(priv, status); + return i801_wait_intr(priv); } static void i801_set_hstadd(struct i801_priv *priv, u8 addr, char read_write) @@ -905,6 +901,8 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, else ret = i801_simple_transaction(priv, data, addr, command, read_write, size); + ret = i801_check_post(priv, ret); + /* Some BIOSes don't like it when PEC is enabled at reboot or resume * time, so we forcibly disable it after every transaction. */