From patchwork Mon Oct 10 13:20:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UsOpdsOpc3osIExldmVudGU=?= X-Patchwork-Id: 614981 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 D60B7C433F5 for ; Mon, 10 Oct 2022 13:23:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229445AbiJJNXb (ORCPT ); Mon, 10 Oct 2022 09:23:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbiJJNXa (ORCPT ); Mon, 10 Oct 2022 09:23:30 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70052.outbound.protection.outlook.com [40.107.7.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D02D761D89 for ; Mon, 10 Oct 2022 06:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YtthNjOhbSIU62UIfBcNVuQu8ZvEuty+lNBRfSzaGG3X2rf7ddv0OM9ctpycCtjnJbhOX3339yqSQD6W+/Hrbq49om27Etz7Makhm/OGaZyKlZZ874nZ4xJWI+uLw3H2jh2/c4x2eemSkxOwriOBPRI8znunG2QRpp+LUK/Kx1BbP4pmmhuSFRDktFddOJuaL+tKnTmdkhKTDADLrneDtb1jCZeMRBNkEQcnvYVWLsyEv54GYpC4xIp7RtGkjiEU/8B/vgMfDBkgxYCyppFp4ONSOcYWlS5FLszeDvpteMvjZal4bLEjGd7zGP7CSqYRraf9PxKMW9NDDMBg00HmiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yXbzpbzMcICvshXte+nHJTbzEN9QlZRaUP8NeUbAunI=; b=EFduYJKq6X7PwiUJ4FpugEkEC5ICmIqBFVPCbPbS/PAY/RwgSkKdT57w1DarSTDITNwzgORUH1Ya/MBHbwNktYezSrCOrqokZokfb8EYz5cj1TWrivOMQjMj+LQ1RhffLcXsU20Q1X9ueQKi9+VPpgP3tLJUoJRmL97/87Oe5J4tVNGAO6EHjnTLWH4ZQUg915UZ9kl/ASjMMNy+2rrMk/ZVYAaxDXOGqHreGH/j1tIoDZRgQu2ipU7oBrNMfFx6bWM9q+B7qLgCccoW9UEdGsDuWw9E8OBcD0mZ9A6jp9JYH4zuG726wsWVHfROgCSP21anV2Zsp2VWYbHf8OAviQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=eilabs.com; dmarc=pass action=none header.from=eilabs.com; dkim=pass header.d=eilabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eilabs.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yXbzpbzMcICvshXte+nHJTbzEN9QlZRaUP8NeUbAunI=; b=Yp/q/C3ols8VN4blEWHz4uMyKW/YZ9/hoNpQEdGHBzpRTNrZU4OppECCOBvQowQuG6BIF5sllaZjBhV82DJ+KBPZiuMz5DWJpvmQ7+gBXlJWu2Dte3v5NCQOV/jyHaQ3uWFyvnVhUJD3IiuocYu/xyTxUWIZwRYFJ4nlBXq85Hw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=eilabs.com; Received: from VI1P194MB0655.EURP194.PROD.OUTLOOK.COM (2603:10a6:800:147::21) by VI1P194MB0656.EURP194.PROD.OUTLOOK.COM (2603:10a6:800:144::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Mon, 10 Oct 2022 13:23:24 +0000 Received: from VI1P194MB0655.EURP194.PROD.OUTLOOK.COM ([fe80::8dfd:7542:7a0c:1f04]) by VI1P194MB0655.EURP194.PROD.OUTLOOK.COM ([fe80::8dfd:7542:7a0c:1f04%6]) with mapi id 15.20.5709.015; Mon, 10 Oct 2022 13:23:24 +0000 From: =?utf-8?q?Levente_R=C3=A9v=C3=A9sz?= To: Linus Walleij , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, =?utf-8?q?Levente_R=C3=A9v=C3=A9sz?= Subject: [PATCH 1/2] gpio: pca953x: Generalize interrupt mask register handling Date: Mon, 10 Oct 2022 15:20:06 +0200 Message-Id: <20221010132007.924810-2-levente.revesz@eilabs.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221010132007.924810-1-levente.revesz@eilabs.com> References: <20221010132007.924810-1-levente.revesz@eilabs.com> X-ClientProxiedBy: VI1PR06CA0146.eurprd06.prod.outlook.com (2603:10a6:803:a0::39) To VI1P194MB0655.EURP194.PROD.OUTLOOK.COM (2603:10a6:800:147::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1P194MB0655:EE_|VI1P194MB0656:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e4dfaed-95b8-4597-8b46-08daaac29b9e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mwSpxjfkLbZWf1IUfk8A5finhQbtCC3yFHF+359b2rCY1/JVlNta28PY9bUY2Tt/P9obXmaB5Yk6ol9LNLB5KkLRebbXN69SW+PSKlv0KEKABTumkH313d8VkgTLIF935CkqWz726xDLCQY2F6/1H4VwfbBwC7mEkUru3/xEZwZDzP3URDEPr0o3OyLwOQcJ3Kb1xwzZ7wxB9PCMz9RLaXCjgwTnXkrxxJx9pE4NGtZG4OejX8Wp/EUklKuvaTgB3Dgg55GuVrexm6cK/qwDXk80ntE+zoJ+noy/vARGF2U7Bf69AHoM31+QN0rvW24+i4ZVPX2u3wMo/ca5XSVKDJYwY4pNmiE5WxSiEGshdiLSJdR8NcCeZj1ip46OD7Z9VLPYVP0zB8nsoGWdN7IPcMp65ea5RTFh5jQEBKjd3T6BozJU+T7/oSp0rWpPMe/RuH3ocWwRwSJLABqbZHtOywDV9h6Qz4JW/EO/TqRfiNN1DDhy9VfNv44/gOQ7tMS5Hu9W+E0Cp0VOgAv4zQQYvWAjKnyevevtuc1aYLsn9IZs+jb0H7PfQICdgr68p7cclOkkbVwc79/lY9ogd1npMPC4YwGu/qj4FjBa+c4xtNiQgUYpkoCex/9sUUmmZey9uFCdfyO/zpAZAC6YLArRQSKQQ9KzNN+5ZUA7//HgIzRx2r9ybDG60BI1ubja4DUp4pMU3ssyXWs4z4w6K3XMMwIROt72T6YA+ZLnbgVVRrvZz4EFQ0jbNYRcIUwiUtUK83yKtdAkRhWu1G5snvwbdg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1P194MB0655.EURP194.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230022)(366004)(346002)(136003)(39830400003)(396003)(376002)(451199015)(66556008)(316002)(66946007)(86362001)(66476007)(4326008)(36756003)(2906002)(5660300002)(8936002)(8676002)(110136005)(41300700001)(83380400001)(2616005)(1076003)(186003)(38100700002)(6506007)(38350700002)(478600001)(6486002)(52116002)(26005)(6512007)(6666004)(107886003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?bt8qAio+6FjSyoP4wK4lCVkR33B/?= =?utf-8?q?DIrOW8hpcca2DxpXMdA4BYz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+9PETUw+Ka6g4wCvugDu/mXOhX7B8eOVmkkjC1CR2q?= =?utf-8?q?im0qBrT+7sdDHR8n1HFPC2asEXXV2Xz/DbKkO28MjG6Ts5ZFMS6vulm20iNjvVBrR?= =?utf-8?q?FAlkEiMlstrUSYqKME3zZfiEyUORZ1udnBZvL5wZ1vMVR3D0lth3cgIZtAJikji0p?= =?utf-8?q?WXPp4CqvZjC3iQU6mMg69iW+2LxRR6MzWtlZtNFjoDjIflIY2lmMMsu7NY7EhCj7+?= =?utf-8?q?t2O8/g8Z9cienpJTwYvJFdw2QHdNFndRf9Waz84e4qW26NPFtnCFKxr4syK2ZsVph?= =?utf-8?q?wT5JrN5ditiChG6kYkSBcg8oBLD7eVAJuhKx5EHwVtN2s85VAMQ9MKWxAziJYBeBF?= =?utf-8?q?VV/rSjH34O2Vm+r/qTF2zgx1OrjYOljgaF061Ce7oOVBFjdl4XqyX6cC3fzFNO8Ct?= =?utf-8?q?I+1HU4C+PYJ/7jAxvNPwJ62oy31z677h9P93GwORe36XN9NI2t/ReG3VmI3sxIioh?= =?utf-8?q?XeYfG3GOue8vsc+TjwZXYDjQ+bhBZzZj8MxmyE1mnrMg6wtu48svjjrK7xuPtWEht?= =?utf-8?q?MaDis1iZui3Oi4sQJPk6p3DH4ZbHc8CO3/VxTen9VQvG0s9Z55RMz+AQb8F1C/vRO?= =?utf-8?q?PEMbNWbPz6ht6Fxlrg+HM+d+FzMNqmRIfw=3D=3D?= X-OriginatorOrg: eilabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e4dfaed-95b8-4597-8b46-08daaac29b9e X-MS-Exchange-CrossTenant-AuthSource: VI1P194MB0655.EURP194.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2022 13:23:23.8676 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 6ef6a9ce-c7b1-47cb-80ec-8c54be45d567 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bORIAN33yOdPqW6pFGsp9gKb6HXJ8AvnnaGNJNloxJXlrGNuzXiPbWBuEQjNh9QHeZLhV5guHY6f6aCUoc0b4EkZG/kHI7/01Mz0TEt7uoE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1P194MB0656 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This change is necessary for a following patch, which introduces an interrupt mask register different from what is already in the driver. Currenty the only interrupt mask register the driver handles is PCAL953x_INT_MASK present in the pcal chips. The functions handling this register can easily be made generic enough to handle the interrupt mask register of other chips that do not use the pcal register set, and have their interrupt mask register at a different address. Add bit flag PCA_HAS_INT_MASK, which is set for each chip with an interrupt mask register (including pcal chips). Define a convenience bitmask PCA_MASKED_INT similar to PCA_LATCH_INT. Add an int_mask member to struct pca953x_reg_config. This way interrupt mask handling code can work with registers at different addresses. Add separate pca953x_reg_config for pcal953x chips. This differs from the pca953x_regs in the new int_mask field. In pca953x_readable_register and pca953x_writeable_register only check for PCA_PCAL if the chip is not PCA957X_TYPE. No chip is both pca957x and pcal. This makes logic for adding a different interrupt mask register cleaner. Signed-off-by: Levente Révész --- drivers/gpio/gpio-pca953x.c | 64 +++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 61e874c0cde4..71bfc38c3930 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -63,7 +63,9 @@ #define PCA_INT BIT(8) #define PCA_PCAL BIT(9) -#define PCA_LATCH_INT (PCA_PCAL | PCA_INT) +#define PCA_HAS_INT_MASK BIT(10) +#define PCA_MASKED_INT (PCA_HAS_INT_MASK | PCA_INT) +#define PCA_LATCH_INT (PCA_PCAL | PCA_MASKED_INT) #define PCA953X_TYPE BIT(12) #define PCA957X_TYPE BIT(13) #define PCAL653X_TYPE BIT(14) @@ -177,6 +179,7 @@ struct pca953x_reg_config { int output; int input; int invert; + int int_mask; }; static const struct pca953x_reg_config pca953x_regs = { @@ -186,6 +189,14 @@ static const struct pca953x_reg_config pca953x_regs = { .invert = PCA953X_INVERT, }; +static const struct pca953x_reg_config pcal953x_regs = { + .direction = PCA953X_DIRECTION, + .output = PCA953X_OUTPUT, + .input = PCA953X_INPUT, + .invert = PCA953X_INVERT, + .int_mask = PCAL953X_INT_MASK, +}; + static const struct pca953x_reg_config pca957x_regs = { .direction = PCA957X_CFG, .output = PCA957X_OUT, @@ -356,12 +367,13 @@ static bool pca953x_readable_register(struct device *dev, unsigned int reg) } else { bank = PCA953x_BANK_INPUT | PCA953x_BANK_OUTPUT | PCA953x_BANK_POLARITY | PCA953x_BANK_CONFIG; - } - if (chip->driver_data & PCA_PCAL) { - bank |= PCAL9xxx_BANK_IN_LATCH | PCAL9xxx_BANK_PULL_EN | - PCAL9xxx_BANK_PULL_SEL | PCAL9xxx_BANK_IRQ_MASK | - PCAL9xxx_BANK_IRQ_STAT; + if (chip->driver_data & PCA_PCAL) + bank |= PCAL9xxx_BANK_IN_LATCH | + PCAL9xxx_BANK_PULL_EN | + PCAL9xxx_BANK_PULL_SEL | + PCAL9xxx_BANK_IRQ_MASK | + PCAL9xxx_BANK_IRQ_STAT; } return chip->check_reg(chip, reg, bank); @@ -378,11 +390,13 @@ static bool pca953x_writeable_register(struct device *dev, unsigned int reg) } else { bank = PCA953x_BANK_OUTPUT | PCA953x_BANK_POLARITY | PCA953x_BANK_CONFIG; - } - if (chip->driver_data & PCA_PCAL) - bank |= PCAL9xxx_BANK_IN_LATCH | PCAL9xxx_BANK_PULL_EN | - PCAL9xxx_BANK_PULL_SEL | PCAL9xxx_BANK_IRQ_MASK; + if (chip->driver_data & PCA_PCAL) + bank |= PCAL9xxx_BANK_IN_LATCH | + PCAL9xxx_BANK_PULL_EN | + PCAL9xxx_BANK_PULL_SEL | + PCAL9xxx_BANK_IRQ_MASK; + } return chip->check_reg(chip, reg, bank); } @@ -764,14 +778,16 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d) DECLARE_BITMAP(reg_direction, MAX_LINE); int level; - if (chip->driver_data & PCA_PCAL) { - /* Enable latch on interrupt-enabled inputs */ - pca953x_write_regs(chip, PCAL953X_IN_LATCH, chip->irq_mask); - + if (chip->driver_data & PCA_HAS_INT_MASK) { bitmap_complement(irq_mask, chip->irq_mask, gc->ngpio); /* Unmask enabled interrupts */ - pca953x_write_regs(chip, PCAL953X_INT_MASK, irq_mask); + pca953x_write_regs(chip, chip->regs->int_mask, irq_mask); + } + + if (chip->driver_data & PCA_PCAL) { + /* Enable latch on interrupt-enabled inputs */ + pca953x_write_regs(chip, PCAL953X_IN_LATCH, chip->irq_mask); } /* Switch direction to input if needed */ @@ -1171,7 +1187,11 @@ static int pca953x_probe(struct i2c_client *client, chip->regs = &pca957x_regs; ret = device_pca957x_init(chip, invert); } else { - chip->regs = &pca953x_regs; + if (chip->driver_data & PCA_PCAL) + chip->regs = &pcal953x_regs; + else + chip->regs = &pca953x_regs; + ret = device_pca95xx_init(chip, invert); } if (ret) @@ -1245,21 +1265,23 @@ static int pca953x_regcache_sync(struct device *dev) } #ifdef CONFIG_GPIO_PCA953X_IRQ - if (chip->driver_data & PCA_PCAL) { - regaddr = chip->recalc_addr(chip, PCAL953X_IN_LATCH, 0); + if (chip->driver_data & PCA_HAS_INT_MASK) { + regaddr = pca953x_recalc_addr(chip, chip->regs->int_mask, 0); ret = regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip) - 1); if (ret) { - dev_err(dev, "Failed to sync INT latch registers: %d\n", + dev_err(dev, "Failed to sync INT mask registers: %d\n", ret); return ret; } + } - regaddr = chip->recalc_addr(chip, PCAL953X_INT_MASK, 0); + if (chip->driver_data & PCA_PCAL) { + regaddr = chip->recalc_addr(chip, PCAL953X_IN_LATCH, 0); ret = regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip) - 1); if (ret) { - dev_err(dev, "Failed to sync INT mask registers: %d\n", + dev_err(dev, "Failed to sync INT latch registers: %d\n", ret); return ret; }