From patchwork Mon Dec 10 15:00:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Adamski X-Patchwork-Id: 1010450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nokia.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nokia.onmicrosoft.com header.i=@nokia.onmicrosoft.com header.b="kw5l57Br"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43D5qg22ypz9s47 for ; Tue, 11 Dec 2018 02:01:03 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726602AbeLJPBC (ORCPT ); Mon, 10 Dec 2018 10:01:02 -0500 Received: from mail-eopbgr70117.outbound.protection.outlook.com ([40.107.7.117]:51573 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726607AbeLJPBC (ORCPT ); Mon, 10 Dec 2018 10:01:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.onmicrosoft.com; s=selector1-nokia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HIZ9UvLOH5jxbvlq0lVZ6pj4uSQXmcxCqU5COVJFm8w=; b=kw5l57BrRvcHXjP5k9PMkZHkaAPOqsk0YT63b7LAjO7lvEhcsyJCDLL7/Q17/SSc1vs9ofjSm6SO9ctz9RndgYbASPB0yHpmZuDyXM/2xV+pyPawO+OwJ05Kwuzru/UcA8iYGhqsN02g+32lKGDdzx7/gE3HlZlxHSF3bzJtROQ= Received: from HE1PR07MB3434.eurprd07.prod.outlook.com (10.170.247.141) by HE1PR07MB3225.eurprd07.prod.outlook.com (10.170.246.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.9; Mon, 10 Dec 2018 15:00:52 +0000 Received: from HE1PR07MB3434.eurprd07.prod.outlook.com ([fe80::e491:596c:4d4e:ffdb]) by HE1PR07MB3434.eurprd07.prod.outlook.com ([fe80::e491:596c:4d4e:ffdb%2]) with mapi id 15.20.1425.016; Mon, 10 Dec 2018 15:00:52 +0000 From: "Adamski, Krzysztof (Nokia - PL/Wroclaw)" To: Wolfram Sang , "Sverdlin, Alexander (Nokia - DE/Ulm)" CC: "linux-i2c@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Linus Walleij , Guenter Roeck , Tobias Jordan , Peter Rosin Subject: [PATCH 1/3] i2c-axxia: dedicated function to set client addr Thread-Topic: [PATCH 1/3] i2c-axxia: dedicated function to set client addr Thread-Index: AQHUkJkkbqmsp7kY3UehxKpVxU5xqg== Date: Mon, 10 Dec 2018 15:00:52 +0000 Message-ID: <120bc3dbc7fad29807ff9f7c74575a66e6da15a6.1544453688.git.krzysztof.adamski@nokia.com> References: In-Reply-To: Accept-Language: pl-PL, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1P189CA0004.EURP189.PROD.OUTLOOK.COM (2603:10a6:7:53::17) To HE1PR07MB3434.eurprd07.prod.outlook.com (2603:10a6:7:2c::13) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [131.228.32.190] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1PR07MB3225; 6:L3R6/LhovvgKAfGvfjjSIsBXPKck1TJ5+SMRfWZsIX9xypOHmMmB85eyUm62O+r/hQP2T3M4uoSbOolMufLwP/DI/JLRtMpsbcV8m7eqWObZ5gFLX3ZqQ7IJpGBa6pZn5CZJU+3dJPtrEab1UOvSOhl5xETxLhauqxRLkkxjKCo4Lc86tDofndPHg04kXAvjEwQoVuvltMZDHvj+lFCBsGzf+IOCIYUgqroTL2fO3MTf1otKHzN+ak9aHcTmjEb5wSJN+AHE+udkCgE4H9Nlh3VKgiQQ+hof4F4dut35UeNMw0+BtYsnHNbh0DVL724bSDC3PgEGHefTbV0v6AfjcvyYS3myWvFWpp6xr8hTKB73OVK8HTn4zlfFH/v8yi13rxid3wEJz3hYi47o1eYa532jcLUjuoYqPLlXWyJ5gtLmeQqGlK3l5KXAWBz2HDEzBPNhInCK8pPHzPJ+PLONlQ==; 5:z8Fo49bXNg7Ld6EYGIzeoRx7eX3wC1HjM9VAaiWDURTEblHw/ydK2WEeIFsaHU18J513cf7WJ5qgHDguzjozsf2IQ3S4PCdjI0UvNkYLZEOLV3NZbDQwPRrErCeKkbPBBcDM/XtCgJzOV2ieH96GjfSAQAmr3/iHo6dpUM5b098=; 7:xuLgsuOY1fouBvmeWRJ8azzUfDA6zmLxixfWmlQHbbbiieL2XmrypPzA5LOw25DTvWtkK9DnKpj016DaI6yRS8H2DFRCWM1qJDC/OfdBt3lJxUeKWW2WUqUfZAg1MnNJgpcto8zrYJw/qvtA3iSaSQ== x-ms-office365-filtering-correlation-id: 957e32f7-4ce6-4dae-dfab-08d65eb04742 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7193020); SRVR:HE1PR07MB3225; x-ms-traffictypediagnostic: HE1PR07MB3225: authentication-results: spf=none (sender IP is ) smtp.mailfrom=krzysztof.adamski@nokia.com; x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230017)(999002)(11241501185)(806100)(6040522)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3002001)(3231472)(944501520)(52105112)(6055026)(148016)(149066)(150057)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(201708071742011)(7699051)(76991095); SRVR:HE1PR07MB3225; BCL:0; PCL:0; RULEID:; SRVR:HE1PR07MB3225; x-forefront-prvs: 08828D20BC x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(346002)(366004)(136003)(39860400002)(376002)(199004)(189003)(478600001)(186003)(68736007)(2616005)(102836004)(11346002)(105586002)(6636002)(476003)(446003)(25786009)(26005)(486006)(14454004)(76176011)(54906003)(110136005)(97736004)(52116002)(256004)(386003)(86362001)(6512007)(106356001)(6506007)(316002)(36756003)(8676002)(2906002)(7736002)(6486002)(118296001)(5660300001)(53936002)(4326008)(8936002)(305945005)(81156014)(99286004)(66066001)(71200400001)(3846002)(6436002)(6116002)(81166006)(71190400001); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR07MB3225; H:HE1PR07MB3434.eurprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nokia.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: CVK/hzJmT36l0uGpbT8SYgtat7H8qfav09tBuN8ApbWkhudLOOoI/HXWBvWyU8RXtI6+pK2EMplrhlRemdnUFMYvxbdRk4kYusD/r5o8DcTGLDeCgCzqwltAfv2RMK+tHVVgdEZ3MJAzvr0kr7uirixWxRO4J1DDy1h257DDL2cZu4wN/mlZEVxeERP1dnt/6vC23N04NCBeFoqQ6/h+Xvph3D2Es/v8PJedg6mof2k0kXA+OgQVMZTrOGpWcgVvH52bQ43VIXFFrOcA03GkttF5i+Xo9qnVeflbO4OwRI0tK0AlXkP/AcLfIHZT+OoY spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: MIME-Version: 1.0 X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 957e32f7-4ce6-4dae-dfab-08d65eb04742 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Dec 2018 15:00:52.5115 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR07MB3225 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This patch moves configuration of hardware registers used for setting i2c client address to separate function. It is preparatory change for next commit. Signed-off-by: Krzysztof Adamski Reviewed-by: Alexander Sverdlin --- drivers/i2c/busses/i2c-axxia.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/i2c/busses/i2c-axxia.c b/drivers/i2c/busses/i2c-axxia.c index 51d34959709b..d37caf694fbf 100644 --- a/drivers/i2c/busses/i2c-axxia.c +++ b/drivers/i2c/busses/i2c-axxia.c @@ -337,17 +337,9 @@ static irqreturn_t axxia_i2c_isr(int irq, void *_dev) return IRQ_HANDLED; } -static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg) +static void axxia_i2c_set_addr(struct axxia_i2c_dev *idev, struct i2c_msg *msg) { - u32 int_mask = MST_STATUS_ERR | MST_STATUS_SNS; - u32 rx_xfer, tx_xfer; u32 addr_1, addr_2; - unsigned long time_left; - unsigned int wt_value; - - idev->msg = msg; - idev->msg_xfrd = 0; - reinit_completion(&idev->msg_complete); if (i2c_m_ten(msg)) { /* 10-bit address @@ -367,6 +359,23 @@ static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg) addr_2 = 0; } + writel(addr_1, idev->base + MST_ADDR_1); + writel(addr_2, idev->base + MST_ADDR_2); +} + +static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg) +{ + u32 int_mask = MST_STATUS_ERR | MST_STATUS_SNS; + u32 rx_xfer, tx_xfer; + unsigned long time_left; + unsigned int wt_value; + + idev->msg = msg; + idev->msg_xfrd = 0; + reinit_completion(&idev->msg_complete); + + axxia_i2c_set_addr(idev, msg); + if (i2c_m_rd(msg)) { /* I2C read transfer */ rx_xfer = i2c_m_recv_len(msg) ? I2C_SMBUS_BLOCK_MAX : msg->len; @@ -379,8 +388,6 @@ static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg) writel(rx_xfer, idev->base + MST_RX_XFER); writel(tx_xfer, idev->base + MST_TX_XFER); - writel(addr_1, idev->base + MST_ADDR_1); - writel(addr_2, idev->base + MST_ADDR_2); if (i2c_m_rd(msg)) int_mask |= MST_STATUS_RFL; From patchwork Mon Dec 10 15:01:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Adamski X-Patchwork-Id: 1010451 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nokia.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nokia.onmicrosoft.com header.i=@nokia.onmicrosoft.com header.b="PVYdJyQp"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43D5rD2d5pz9s47 for ; Tue, 11 Dec 2018 02:01:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727081AbeLJPBb (ORCPT ); Mon, 10 Dec 2018 10:01:31 -0500 Received: from mail-eopbgr70114.outbound.protection.outlook.com ([40.107.7.114]:57776 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726607AbeLJPBb (ORCPT ); Mon, 10 Dec 2018 10:01:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.onmicrosoft.com; s=selector1-nokia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oXEiv2kWI2IBla9ApAa5x5G3BZGhnX3KrzBf507bpo4=; b=PVYdJyQpCRT8ExvgDGI0YWT/8U5T6xq2QCyePtZDnsF/H6s8jpeKoWqg6Ep8J6ut7+9EjMiRw9qVS6MhvohBNqrKbahCZPrGUabSTmyFl2u7pOFp2P7/8M/A4FCbFwsIWEL+FX0bHvc9wSOrRGbWGRlfBZv1AP8cPwHmVsMP3gs= Received: from HE1PR07MB3434.eurprd07.prod.outlook.com (10.170.247.141) by HE1PR07MB3225.eurprd07.prod.outlook.com (10.170.246.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.9; Mon, 10 Dec 2018 15:01:27 +0000 Received: from HE1PR07MB3434.eurprd07.prod.outlook.com ([fe80::e491:596c:4d4e:ffdb]) by HE1PR07MB3434.eurprd07.prod.outlook.com ([fe80::e491:596c:4d4e:ffdb%2]) with mapi id 15.20.1425.016; Mon, 10 Dec 2018 15:01:27 +0000 From: "Adamski, Krzysztof (Nokia - PL/Wroclaw)" To: Wolfram Sang , "Sverdlin, Alexander (Nokia - DE/Ulm)" CC: "linux-i2c@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Linus Walleij , Guenter Roeck , Tobias Jordan , Peter Rosin Subject: [PATCH 2/3] i2c-axxia: check for error conditions first Thread-Topic: [PATCH 2/3] i2c-axxia: check for error conditions first Thread-Index: AQHUkJk55tLaS8VlUEGNHY3SdbedeQ== Date: Mon, 10 Dec 2018 15:01:27 +0000 Message-ID: References: In-Reply-To: Accept-Language: pl-PL, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1PR0402CA0022.eurprd04.prod.outlook.com (2603:10a6:3:d0::32) To HE1PR07MB3434.eurprd07.prod.outlook.com (2603:10a6:7:2c::13) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [131.228.32.190] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1PR07MB3225; 6:0QjNqLU9L1fo/km3cjtqGehWIluunNhBVO9qCBvCd7ImXXrEWqI7xyHUkvSO2Y8IwRpFqX0S1fDXVjMCGHxsHGYgOhE89PbdV513pdqNNFLEF207WIjqM6w85m8TbiLOuCyHUUo3oos3lr6orU+Fi1RRJUWkE15RgRHI20Qd8pwhYnJWYCCct+Ux5AAO4GpiN3YYEUtpI0vmp+PZRbko+2tIefjfMcfPqFOtYCVvPCesTdfRWBUAZlF3KKcROxhxisN46qnglNp/2o5xmOWwBI+N8o1RjlsXuPr6AC46uLs3sqmU86els9nc/6BB/ovBuRgw4sdulRLhvl1Xe6chcIPscIUk0akQgff1sFU1Qw4VrCeA96HcNW59FU3jJwf3F9lLGoKPGPF1ol5r0AkvK4zhGreu+mVbfSAAUw7QRn6jPplbCzQplrcc4owvVp8tH5SD1YnTRGn30kJUXcHyaw==; 5:bbfCbBaGOnTTe6NMAja01lQjXT11a4gdIDsQlncfawLwppKpE9r1bYd2gswvnRgwpd2labOfzpmSuUI24DCbpBhRbOTicGQ4e8gzzuP2mb3biA4Lxa0R1RY2LtFF3fo184d/2ge1kBqa+wlQ+xShx6yI2vTOT5RYJSe7zgcQ3ZQ=; 7:evlUrz5HxmtkAyAXXxy8VdPqvWKzVBL+dNlSZ0X6NRroS8UaqE78EEC4OcOymZdS7R38ergswy/gos1whcawFuOF3aeXu245BbNnbCHuZvc24R97umUKWFNWbneZuf2cxuGU8hCtRlvO9EGoMki/IA== x-ms-office365-filtering-correlation-id: 083144f6-cf88-4441-f118-08d65eb05bd5 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7193020); SRVR:HE1PR07MB3225; x-ms-traffictypediagnostic: HE1PR07MB3225: authentication-results: spf=none (sender IP is ) smtp.mailfrom=krzysztof.adamski@nokia.com; x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230017)(999002)(11241501185)(806100)(6040522)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3002001)(3231472)(944501520)(52105112)(6055026)(148016)(149066)(150057)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(201708071742011)(7699051)(76991095); SRVR:HE1PR07MB3225; BCL:0; PCL:0; RULEID:; SRVR:HE1PR07MB3225; x-forefront-prvs: 08828D20BC x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(346002)(366004)(136003)(39860400002)(376002)(199004)(189003)(478600001)(186003)(68736007)(2616005)(102836004)(11346002)(105586002)(6636002)(476003)(446003)(25786009)(26005)(486006)(14454004)(76176011)(54906003)(110136005)(97736004)(52116002)(256004)(14444005)(386003)(86362001)(6512007)(106356001)(6506007)(316002)(36756003)(8676002)(2906002)(7736002)(6486002)(118296001)(5660300001)(53936002)(4326008)(8936002)(305945005)(81156014)(99286004)(66066001)(71200400001)(3846002)(6436002)(6116002)(81166006)(71190400001); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR07MB3225; H:HE1PR07MB3434.eurprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nokia.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 7Zx1aftXvxU6fX0blE3rng0TP6g8aVSdXTrSajyzgOalSI+k2yEe00lum1yFFONTFoVzhG0foZzbpUQdPTbxgb1cp9g6Mlr4y3NbHOD9KxerSXeNwVW67L++By+DDO8hzQZiagGEW8pivGupPqW+fXSBhiItIiWjV3DjfdZ/be5GQnSFHfYXEQy4txE6skNouQIvKTpf8UMpaTO1gOTgR8ubywrodEmkiqEmNuJCS9znv1S9KHp2Lg3Ez27DP6t30mb742DXv5LQ635JSZKu6u0gQen6r3VcMt2yYmlcm5wwjY86RZfDW9vzInpXq9Rk spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <483A37907C106B439A2559E2FA27B219@eurprd07.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 083144f6-cf88-4441-f118-08d65eb05bd5 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Dec 2018 15:01:27.0158 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR07MB3225 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org It was observed that when using seqentional mode contrary to the documentation, the SS bit (which is supposed to only be set if automatic/sequence command completed normally), is sometimes set together with NA (NAK in address phase) causing transfer to falsely be considered successful. My assumption is that this does not happen during manual mode since the controller is stopping its work the moment it sets NA/ND bit in status register. This is not the case in Automatic/Sequentional mode where it is still working to send STOP condition and the actual status we get depends on the time when the ISR is run. This patch changes the order of checking status bits in ISR - error conditions are checked first and only if none of them occurred, the transfer may be considered successful. This is required to introduce using of sequentional mode in next patch. Signed-off-by: Krzysztof Adamski Reviewed-by: Alexander Sverdlin --- drivers/i2c/busses/i2c-axxia.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/i2c/busses/i2c-axxia.c b/drivers/i2c/busses/i2c-axxia.c index d37caf694fbf..35258321e81b 100644 --- a/drivers/i2c/busses/i2c-axxia.c +++ b/drivers/i2c/busses/i2c-axxia.c @@ -296,22 +296,7 @@ static irqreturn_t axxia_i2c_isr(int irq, void *_dev) i2c_int_disable(idev, MST_STATUS_TFL); } - if (status & MST_STATUS_SCC) { - /* Stop completed */ - i2c_int_disable(idev, ~MST_STATUS_TSS); - complete(&idev->msg_complete); - } else if (status & MST_STATUS_SNS) { - /* Transfer done */ - i2c_int_disable(idev, ~MST_STATUS_TSS); - if (i2c_m_rd(idev->msg) && idev->msg_xfrd < idev->msg->len) - axxia_i2c_empty_rx_fifo(idev); - complete(&idev->msg_complete); - } else if (status & MST_STATUS_TSS) { - /* Transfer timeout */ - idev->msg_err = -ETIMEDOUT; - i2c_int_disable(idev, ~MST_STATUS_TSS); - complete(&idev->msg_complete); - } else if (unlikely(status & MST_STATUS_ERR)) { + if (unlikely(status & MST_STATUS_ERR)) { /* Transfer error */ i2c_int_disable(idev, ~0); if (status & MST_STATUS_AL) @@ -328,6 +313,21 @@ static irqreturn_t axxia_i2c_isr(int irq, void *_dev) readl(idev->base + MST_TX_BYTES_XFRD), readl(idev->base + MST_TX_XFER)); complete(&idev->msg_complete); + } else if (status & MST_STATUS_SCC) { + /* Stop completed */ + i2c_int_disable(idev, ~MST_STATUS_TSS); + complete(&idev->msg_complete); + } else if (status & MST_STATUS_SNS) { + /* Transfer done */ + i2c_int_disable(idev, ~MST_STATUS_TSS); + if (i2c_m_rd(idev->msg) && idev->msg_xfrd < idev->msg->len) + axxia_i2c_empty_rx_fifo(idev); + complete(&idev->msg_complete); + } else if (status & MST_STATUS_TSS) { + /* Transfer timeout */ + idev->msg_err = -ETIMEDOUT; + i2c_int_disable(idev, ~MST_STATUS_TSS); + complete(&idev->msg_complete); } out: From patchwork Mon Dec 10 15:05:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Krzysztof Adamski X-Patchwork-Id: 1010452 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nokia.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nokia.onmicrosoft.com header.i=@nokia.onmicrosoft.com header.b="qwObSNhK"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43D5wp3lBFz9s47 for ; Tue, 11 Dec 2018 02:05:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727174AbeLJPF3 (ORCPT ); Mon, 10 Dec 2018 10:05:29 -0500 Received: from mail-eopbgr140105.outbound.protection.outlook.com ([40.107.14.105]:45634 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726978AbeLJPF2 (ORCPT ); Mon, 10 Dec 2018 10:05:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.onmicrosoft.com; s=selector1-nokia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=edIp+aqyaMQywj8lZl4k2cLT186xBR7S/o6IMS7TmDk=; b=qwObSNhKu+7Z71QHJYt0q8mkjrmRObCeqzt1a7i/8APDD3ftINXX4UEzNgrEzbj0ULOg7a6VYVqQ4gEVXepq218hebY40Qw7r77DrWd1S3+/IixT9UJqwjeP+lJHze1qgb+sxtVAsnSJpaU4STbZlfPdkaC0LWkyvOkf7570Y60= Received: from HE1PR07MB3434.eurprd07.prod.outlook.com (10.170.247.141) by HE1PR07MB3338.eurprd07.prod.outlook.com (10.170.247.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.9; Mon, 10 Dec 2018 15:05:23 +0000 Received: from HE1PR07MB3434.eurprd07.prod.outlook.com ([fe80::e491:596c:4d4e:ffdb]) by HE1PR07MB3434.eurprd07.prod.outlook.com ([fe80::e491:596c:4d4e:ffdb%2]) with mapi id 15.20.1425.016; Mon, 10 Dec 2018 15:05:23 +0000 From: "Adamski, Krzysztof (Nokia - PL/Wroclaw)" To: Wolfram Sang , "Sverdlin, Alexander (Nokia - DE/Ulm)" CC: "linux-i2c@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Linus Walleij , Guenter Roeck , Tobias Jordan , Peter Rosin Subject: [PATCH 3/3] i2c-axxia: support sequence command mode Thread-Topic: [PATCH 3/3] i2c-axxia: support sequence command mode Thread-Index: AQHUkJnGbS63ysGb7E6mOzAbaTpNEg== Date: Mon, 10 Dec 2018 15:05:23 +0000 Message-ID: <8515ba7093f5be3ad7bd31d68efedcbe17958282.1544453688.git.krzysztof.adamski@nokia.com> References: In-Reply-To: Accept-Language: pl-PL, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1PR02CA0113.eurprd02.prod.outlook.com (2603:10a6:7:29::42) To HE1PR07MB3434.eurprd07.prod.outlook.com (2603:10a6:7:2c::13) authentication-results: spf=none (sender IP is ) smtp.mailfrom=krzysztof.adamski@nokia.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [131.228.32.190] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1PR07MB3338; 6:uzIzGJsh1JaYNf0Nq6ewmTL6cWDa/sGCp6lhqeAh+8iqblFiWJ8ZsmLf58rQr1xx4dFmlMf+BZBVGbcaWY7VpE4Bf1oW9BpMU0n8tp0yzOfr59WmQge5YJjhirRRBmV4mJoPg8iyYS6nNbKOAqNLNoi4fc1IBDNwPisf9u94HtdOfhfJCfgibHspeu0C6/P2A5zNMWc5EzwF4guNU+GYZEjlNSfEUyf6NLOLK3edDtyrTRiug6g5ctMG34Y/+YzbtbiPS7dV44r6WM/RMaptfNSmz1UcUWH3HFLj5Bo+K85XamIlrgrjwbwCkYskvktljzigbqhJCP36PFdEV/k0U6lFv8KM9VsM0s+oTfcS2F1tyUMWjHtopOkj1dddiGKL++lnxxhowCeARtP8WLDj4gJfoeTcs8G8MdNdWI2kOThG3CpMB9qLXM14sr2amc+4XuAVbDayKw+izpDOkjCRTA==; 5:jLLvfa6195wc/udQqPPL3ejT5Z5w9G55UA2TqRQTgHMTV29AktBERToIlvSQZmFjlerxJD0rnP7YkFyL6iyiXFhWM/xmG9fP7AOZMw7SHkEPCJLJ6cM+GVa1J97YLgBbLqdP3fPahhi5n5laPj8f2ZRsID7xvA0/KGFhHLJjQ3k=; 7:qSpJ1KHYR7HtvRayD5DIjrcyO0gOYJ6q7umsskXU0JohRTtvnbp3j5tOn+GhT7aCkOkLyqKeEc/CWP1oGV9N4qOvjnHtt3eyDaoO6EqmcGEWantlVEScfAgyrqF6R4OcSQTYM49d3SYYOAkfa87yYQ== x-ms-office365-filtering-correlation-id: 26909b10-30fd-4256-f5aa-08d65eb0e8e4 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7193020); SRVR:HE1PR07MB3338; x-ms-traffictypediagnostic: HE1PR07MB3338: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231455)(999002)(11241501185)(806100)(944501520)(52105112)(3002001)(10201501046)(6055026)(148016)(149066)(150057)(6041310)(20161123564045)(20161123562045)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095); SRVR:HE1PR07MB3338; BCL:0; PCL:0; RULEID:; SRVR:HE1PR07MB3338; x-forefront-prvs: 08828D20BC x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(366004)(346002)(39860400002)(136003)(376002)(199004)(189003)(68736007)(81166006)(8676002)(8936002)(256004)(81156014)(11346002)(4326008)(5660300001)(6486002)(486006)(476003)(446003)(2616005)(305945005)(25786009)(6436002)(76176011)(575784001)(99286004)(86362001)(2906002)(52116002)(6636002)(316002)(71190400001)(6116002)(3846002)(110136005)(54906003)(71200400001)(14454004)(551934003)(66066001)(106356001)(97736004)(118296001)(105586002)(6512007)(7736002)(186003)(53936002)(478600001)(14444005)(6506007)(102836004)(36756003)(26005)(386003); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR07MB3338; H:HE1PR07MB3434.eurprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nokia.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: cW+KK6wrrM+ssAI6JfDJkMVmnOCWnC5XuD3aCeIhSP14Ub/mjE3urDrfgvnrBhgUHAFNnmDy+VwfFsxVeGJmbFqYVliVyCDhL+c8+ySlubMQ45Bt1GZhqmq9ldL3pxbiFjm8ot0CrLBVP5ZJPMS59QKc0YqYvHxO/SdbSxaZSWp8BVTMPndWLGJZCr/HvPknPTQ/IhXQjaP/JJywvdVpS0V8uX+DTjBKaMlV/gFSQ3kxf3q+wZx4PTbSxiUs+Zu+6WRLbeLqtCjo/V69f+ZAqDqATT0U8BTwRlB17CPYKUFGcVFbcKs0MCw5Zc1aQEjS spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <5BA719FC6E688A4F92C22D826E1A4A0F@eurprd07.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26909b10-30fd-4256-f5aa-08d65eb0e8e4 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Dec 2018 15:05:23.6709 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR07MB3338 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org In order to comply with SMBus specification, the Axxia I²C module will abort the multi message transfer if the delay between finishing sending one message and starting another is longer than 25ms. Unfortunately it isn't that hard to trigger this situation on a busy system. In order to fix this problem, we should make sure hardware does whole transaction without waiting for software to fill some data. Fortunately, in addition to Manual mode that is currently used by the driver to perform I²C transfers, the module supports also so called Sequence mode. In this mode, the module automatically performs predefined sequence of operations - it sends a slave address, transmits specified number of bytes from the FIFO, changes transfer direction, resends the slave address and then reads specified number of bytes to FIFO. While very inflexible, this does fit a most common case of multi message transfer - the one where you first write a register number you want to read and then read it. To use this mode effectively, a number of conditions must be met to ensure the transaction does fit the predefined sequence. In case this is not the case, a fallback to manual mode is used. The initialization of this mode is very similar to Manual mode. The most notable difference is different bit in the Master Interrupt Status designating finishing of transaction. Also some of the errors, like TSS, cannot happen in this mode. While it is possible to support transactions requesting a read of any size (RFL interrupt will be generated when FIFO size is not enough) the TFL interrupt is not available in this mode, thus the write part of the transaction cannot exceed FIFO_SIZE (8). Note that in case of a NAK during transaction, the NA/ND status bits will be set before STOP command is generated, triggering an interrupt while the controller is still busy. Current solution for this problem is to actively wait for this command to stop before leaving xfer callback. Signed-off-by: Krzysztof Adamski Reviewed-by: Alexander Sverdlin --- drivers/i2c/busses/i2c-axxia.c | 100 ++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-axxia.c b/drivers/i2c/busses/i2c-axxia.c index 35258321e81b..64779819a948 100644 --- a/drivers/i2c/busses/i2c-axxia.c +++ b/drivers/i2c/busses/i2c-axxia.c @@ -12,6 +12,7 @@ */ #include #include +#include #include #include #include @@ -25,6 +26,7 @@ #define I2C_XFER_TIMEOUT (msecs_to_jiffies(250)) #define I2C_STOP_TIMEOUT (msecs_to_jiffies(100)) #define FIFO_SIZE 8 +#define SEQ_LEN 2 #define GLOBAL_CONTROL 0x00 #define GLOBAL_MST_EN BIT(0) @@ -51,6 +53,7 @@ #define CMD_BUSY (1<<3) #define CMD_MANUAL (0x00 | CMD_BUSY) #define CMD_AUTO (0x01 | CMD_BUSY) +#define CMD_SEQUENCE (0x02 | CMD_BUSY) #define MST_RX_XFER 0x2c #define MST_TX_XFER 0x30 #define MST_ADDR_1 0x34 @@ -87,7 +90,9 @@ * axxia_i2c_dev - I2C device context * @base: pointer to register struct * @msg: pointer to current message - * @msg_xfrd: number of bytes transferred in msg + * @msg_r: pointer to current read message (sequence transfer) + * @msg_xfrd: number of bytes transferred in tx_fifo + * @msg_xfrd_r: number of bytes transferred in rx_fifo * @msg_err: error code for completed message * @msg_complete: xfer completion object * @dev: device reference @@ -98,7 +103,9 @@ struct axxia_i2c_dev { void __iomem *base; struct i2c_msg *msg; + struct i2c_msg *msg_r; size_t msg_xfrd; + size_t msg_xfrd_r; int msg_err; struct completion msg_complete; struct device *dev; @@ -227,14 +234,14 @@ static int i2c_m_recv_len(const struct i2c_msg *msg) */ static int axxia_i2c_empty_rx_fifo(struct axxia_i2c_dev *idev) { - struct i2c_msg *msg = idev->msg; + struct i2c_msg *msg = idev->msg_r; size_t rx_fifo_avail = readl(idev->base + MST_RX_FIFO); - int bytes_to_transfer = min(rx_fifo_avail, msg->len - idev->msg_xfrd); + int bytes_to_transfer = min(rx_fifo_avail, msg->len - idev->msg_xfrd_r); while (bytes_to_transfer-- > 0) { int c = readl(idev->base + MST_DATA); - if (idev->msg_xfrd == 0 && i2c_m_recv_len(msg)) { + if (idev->msg_xfrd_r == 0 && i2c_m_recv_len(msg)) { /* * Check length byte for SMBus block read */ @@ -247,7 +254,7 @@ static int axxia_i2c_empty_rx_fifo(struct axxia_i2c_dev *idev) msg->len = 1 + c; writel(msg->len, idev->base + MST_RX_XFER); } - msg->buf[idev->msg_xfrd++] = c; + msg->buf[idev->msg_xfrd_r++] = c; } return 0; @@ -287,7 +294,7 @@ static irqreturn_t axxia_i2c_isr(int irq, void *_dev) } /* RX FIFO needs service? */ - if (i2c_m_rd(idev->msg) && (status & MST_STATUS_RFL)) + if (i2c_m_rd(idev->msg_r) && (status & MST_STATUS_RFL)) axxia_i2c_empty_rx_fifo(idev); /* TX FIFO needs service? */ @@ -320,9 +327,12 @@ static irqreturn_t axxia_i2c_isr(int irq, void *_dev) } else if (status & MST_STATUS_SNS) { /* Transfer done */ i2c_int_disable(idev, ~MST_STATUS_TSS); - if (i2c_m_rd(idev->msg) && idev->msg_xfrd < idev->msg->len) + if (i2c_m_rd(idev->msg_r) && idev->msg_xfrd_r < idev->msg_r->len) axxia_i2c_empty_rx_fifo(idev); complete(&idev->msg_complete); + } else if (status & MST_STATUS_SS) { + /* Auto/Sequence transfer done */ + complete(&idev->msg_complete); } else if (status & MST_STATUS_TSS) { /* Transfer timeout */ idev->msg_err = -ETIMEDOUT; @@ -363,6 +373,62 @@ static void axxia_i2c_set_addr(struct axxia_i2c_dev *idev, struct i2c_msg *msg) writel(addr_2, idev->base + MST_ADDR_2); } +/* The NAK interrupt will be sent _before_ issuing STOP command + * so the controller might still be busy processing it. No + * interrupt will be sent at the end so we have to poll for it + */ +static void axxia_i2c_handle_seq_nak(struct axxia_i2c_dev *idev) +{ + while (readl(idev->base + MST_COMMAND) & CMD_BUSY) + udelay(100); +} + +static int axxia_i2c_xfer_seq(struct axxia_i2c_dev *idev, struct i2c_msg msgs[]) +{ + u32 int_mask = MST_STATUS_ERR | MST_STATUS_SS | MST_STATUS_RFL; + u32 rlen = i2c_m_recv_len(&msgs[1]) ? I2C_SMBUS_BLOCK_MAX : msgs[1].len; + unsigned long time_left; + + axxia_i2c_set_addr(idev, &msgs[0]); + + writel(msgs[0].len, idev->base + MST_TX_XFER); + writel(rlen, idev->base + MST_RX_XFER); + + idev->msg = &msgs[0]; + idev->msg_r = &msgs[1]; + idev->msg_xfrd = 0; + idev->msg_xfrd_r = 0; + axxia_i2c_fill_tx_fifo(idev); + + writel(CMD_SEQUENCE, idev->base + MST_COMMAND); + + reinit_completion(&idev->msg_complete); + i2c_int_enable(idev, int_mask); + + time_left = wait_for_completion_timeout(&idev->msg_complete, + I2C_XFER_TIMEOUT); + + i2c_int_disable(idev, int_mask); + + axxia_i2c_empty_rx_fifo(idev); + + if (idev->msg_err == -ENXIO) + axxia_i2c_handle_seq_nak(idev); + else if (readl(idev->base + MST_COMMAND) & CMD_BUSY) + dev_warn(idev->dev, "busy after xfer\n"); + + if (time_left == 0) { + idev->msg_err = -ETIMEDOUT; + i2c_recover_bus(&idev->adapter); + axxia_i2c_init(idev); + } + + if (unlikely(idev->msg_err) && idev->msg_err != -ENXIO) + axxia_i2c_init(idev); + + return idev->msg_err; +} + static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg) { u32 int_mask = MST_STATUS_ERR | MST_STATUS_SNS; @@ -371,7 +437,9 @@ static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg) unsigned int wt_value; idev->msg = msg; + idev->msg_r = msg; idev->msg_xfrd = 0; + idev->msg_xfrd_r = 0; reinit_completion(&idev->msg_complete); axxia_i2c_set_addr(idev, msg); @@ -452,6 +520,18 @@ static int axxia_i2c_stop(struct axxia_i2c_dev *idev) return 0; } +/* This function checks if the msgs[] array contains messages compatible with + * Sequence mode of operation. This mode assumes there will be exactly one + * write of non-zero length followed by exactly one read of non-zero length, + * both targeted at the same client device. + */ +static bool axxia_i2c_sequence_ok(struct i2c_msg msgs[], int num) +{ + return num == SEQ_LEN && !i2c_m_rd(&msgs[0]) && i2c_m_rd(&msgs[1]) && + msgs[0].len > 0 && msgs[0].len <= FIFO_SIZE && + msgs[1].len > 0 && msgs[0].addr == msgs[1].addr; +} + static int axxia_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) { @@ -460,6 +540,12 @@ axxia_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) int ret = 0; idev->msg_err = 0; + + if (axxia_i2c_sequence_ok(msgs, num)) { + ret = axxia_i2c_xfer_seq(idev, msgs); + return ret ? : SEQ_LEN; + } + i2c_int_enable(idev, MST_STATUS_TSS); for (i = 0; ret == 0 && i < num; ++i)