From patchwork Mon Feb 7 06:33:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 540622 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 72065C4167B for ; Mon, 7 Feb 2022 06:56:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237729AbiBGG4O (ORCPT ); Mon, 7 Feb 2022 01:56:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241646AbiBGGdx (ORCPT ); Mon, 7 Feb 2022 01:33:53 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C400DC043187; Sun, 6 Feb 2022 22:33:52 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id w1so833614plb.6; Sun, 06 Feb 2022 22:33:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0TH+KvK70vqF4R3xRGxJlT+5PeKHKYQ4Msc0Pdr7t5o=; b=iGQGr9yTud19lEw7Dzfe5qe038Er/9pvs3h8C7e0pWiTdPaUGN2IEVMolqlvz99+Y6 tK7qS1nMdqUQyNLrVdRrMnFqel0S3jLhmpVpUHBBb2dR05fkqnzBU/aM7w+9WR1tS7e0 KGMtPoortuyKjv+zYfywy21NoWucdf3Y8BGMoATM0kauUin7LrFTjqllS4lAPTV47Bx+ obA3zAzgjlvjQyZRkzO4aHpgLM3TFrdNyOnwxD/Z1nETDY7UzSvEd8NRWM5VCefEHaOE Y+8ls8E5ujDrKHLlaewlDheGpptcJ+S0fsF2mSvkfFp6VlGHMYu/A8ONI8iAjJzWoVAx kPWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0TH+KvK70vqF4R3xRGxJlT+5PeKHKYQ4Msc0Pdr7t5o=; b=ATaTBTPjBTUwoGMa60wFHlcizJl+qYmaRH9ANc77ZtB+4KVm896Fy62+Ad+WV3udnK naU9KBcDmQVaaQRGIp09rmgLBOBMm6obUqHYFSghcTcd38TeTzmTXpWRFsdjdAFLrJeE C5un2J2Gf/hVHvkE5jLZi5atGlWWnK4kZ9Nw3VNan/iNEFM8HEVsupN7YHX2qTeI5khR sU9RpXh+DbEugnHjddI7c+Uy63DG8PPg/nTFQ1oy0cBrDxnUEoyvyOizhnsi0xWKqVX0 Z7LEuXH8/GSLQsI0q8YhYzHgaKJJpZgiXQpfapj8Pt6WdgtNhLuGxxgjRHbQGuas9NAX qTXQ== X-Gm-Message-State: AOAM531LM1a0BChwDIdFQlMhwa5pkCOvcLy/tCaQ3STrf785Ac6jasoK ZMRpTz9vwSbCDAn6V9k0EA== X-Google-Smtp-Source: ABdhPJzUhSzyUpEEAxtg0HDIK8h5MPdNrBH+uypOcMLHVjdwOPcOsEkbt23+dU/LCDKF6LYh4HwjqA== X-Received: by 2002:a17:903:404b:: with SMTP id n11mr14679060pla.129.1644215632267; Sun, 06 Feb 2022 22:33:52 -0800 (PST) Received: from localhost ([2401:e180:8894:9737:7848:1ec7:b697:7d50]) by smtp.gmail.com with ESMTPSA id i12sm914768pjw.25.2022.02.06.22.33.51 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 06 Feb 2022 22:33:51 -0800 (PST) From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski@canonical.com, semen.protsenko@linaro.org, yangyicong@hisilicon.com, wsa@kernel.org, jie.deng@intel.com, sven@svenpeter.dev, bence98@sch.bme.hu, lukas.bulwahn@gmail.com, arnd@arndb.de, olof@lixom.net, andriy.shevchenko@linux.intel.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/6] i2c: npcm: Fix timeout calculation Date: Mon, 7 Feb 2022 14:33:34 +0800 Message-Id: <20220207063338.6570-3-warp5tw@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220207063338.6570-1-warp5tw@gmail.com> References: <20220207063338.6570-1-warp5tw@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Tali Perry Use adap.timeout for timeout calculation instead of hard-coded value of 35ms. Use syscon to access gcr, instead of "compatible". Fixes: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver") Signed-off-by: Tali Perry Signed-off-by: Tyrone Ting --- drivers/i2c/busses/i2c-npcm7xx.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 2ad166355ec9..ddeee6f53621 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2047,7 +2047,7 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, u16 nwrite, nread; u8 *write_data, *read_data; u8 slave_addr; - int timeout; + unsigned long timeout; int ret = 0; bool read_block = false; bool read_PEC = false; @@ -2099,13 +2099,13 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, * 9: bits per transaction (including the ack/nack) */ timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite); - timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec)); + timeout = max(bus->adap.timeout, usecs_to_jiffies(timeout_usec)); if (nwrite >= 32 * 1024 || nread >= 32 * 1024) { dev_err(bus->dev, "i2c%d buffer too big\n", bus->num); return -EINVAL; } - time_left = jiffies + msecs_to_jiffies(DEFAULT_STALL_COUNT) + 1; + time_left = jiffies + timeout + 1; do { /* * we must clear slave address immediately when the bus is not @@ -2131,7 +2131,7 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, } npcm_i2c_init_params(bus); - bus->dest_addr = slave_addr; + bus->dest_addr = slave_addr << 1; bus->msgs = msgs; bus->msgs_num = num; bus->cmd_err = 0; @@ -2233,9 +2233,9 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev) struct i2c_adapter *adap; struct clk *i2c_clk; static struct regmap *gcr_regmap; - static struct regmap *clk_regmap; int irq; int ret; + struct device_node *np = pdev->dev.of_node; bus = devm_kzalloc(&pdev->dev, sizeof(*bus), GFP_KERNEL); if (!bus) @@ -2250,15 +2250,11 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev) return PTR_ERR(i2c_clk); bus->apb_clk = clk_get_rate(i2c_clk); - gcr_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-gcr"); + gcr_regmap = syscon_regmap_lookup_by_phandle(np, "syscon"); if (IS_ERR(gcr_regmap)) return PTR_ERR(gcr_regmap); regmap_write(gcr_regmap, NPCM_I2CSEGCTL, NPCM_I2CSEGCTL_INIT_VAL); - clk_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-clk"); - if (IS_ERR(clk_regmap)) - return PTR_ERR(clk_regmap); - bus->reg = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(bus->reg)) return PTR_ERR(bus->reg); @@ -2269,7 +2265,7 @@ static int npcm_i2c_probe_bus(struct platform_device *pdev) adap = &bus->adap; adap->owner = THIS_MODULE; adap->retries = 3; - adap->timeout = HZ; + adap->timeout = msecs_to_jiffies(35); adap->algo = &npcm_i2c_algo; adap->quirks = &npcm_i2c_quirks; adap->algo_data = bus; From patchwork Mon Feb 7 06:33:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 540623 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 9FABCC433EF for ; Mon, 7 Feb 2022 06:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231408AbiBGGy7 (ORCPT ); Mon, 7 Feb 2022 01:54:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241814AbiBGGd6 (ORCPT ); Mon, 7 Feb 2022 01:33:58 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5577C043184; Sun, 6 Feb 2022 22:33:57 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id i30so11299800pfk.8; Sun, 06 Feb 2022 22:33:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qlN75CsLXoZ8b2tnKBNp17X1wC9KO37usZLYNCoKx88=; b=gAMQM2ZZDEBpY9C97KfQaZ5RtMwvF8HhABYLHimmnFQ8YTY1/NX2bcxmcJuRlBiLoS bvl9ITfB4v5f+CJenqN8XIByNBVfgBEEv+v4kDdw3qm4EV9TsSAn8pQpPRuG/1i4Uz/9 g8MibHIiM9DSN5Srr79pVTH9b53s2iXNQBWfjfwL3DZWmel9vg1rw39u843caqSY4nve uliOaCpQbDyXFIEWzjxAt/7Vc0fXVfSxkY2FysZX+lB2VoGzbItNscVigCEJW+9UQfhV 4bmIsFQEorLN3l5gA7CmIFpCE2AF82WF1LqhV0FxjrRNI9w+wgI/zLFMCgzJCCk3SqV8 Wl3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qlN75CsLXoZ8b2tnKBNp17X1wC9KO37usZLYNCoKx88=; b=ahJQTp/BG8x5eN6jOpvJ9nTkdDMTyTCg5ggRxruWUmiw1GmppLtcMLhy7dladHU5qF tc3g4qmuXVEE+hLQvCBskKYUyZBTqDVsbavAtTCqgqiH/mAZhBStkcYnHQFjrSbweG00 qzOTpZXPXjl74QLDlrWv4V7Lat6ghgfATYGOe/9f7CIMTRdkAGUErxxT36MLSvLynDWJ UJflXMchcyC+/eB+b8xPofI2R/prkYEJBbCgTIMhlqumebXAJQVt9hIpi7G4rkgewr+x pIC2q9yBkXU0toE929F+V53irNVi+MewWvW292vDSlvHpRnDTEg7cl2pVqocmGYQJmqP 9eIg== X-Gm-Message-State: AOAM533uRwe6P8OxFXu+YodwsFrmCW2dU8KLe5pQ38433ae/ouT05UAV NQQqtpy5vpzle7AQE4isHBy/i+LzYs0crno= X-Google-Smtp-Source: ABdhPJwVu/dblxj+rjmT9D41ENsuEDMzdHSjCqqnU9RJZ1n2ONjWs+Q1nr5jf53P79BDwaYF5VlkAw== X-Received: by 2002:aa7:8490:: with SMTP id u16mr14254701pfn.1.1644215637318; Sun, 06 Feb 2022 22:33:57 -0800 (PST) Received: from localhost ([2401:e180:8894:9737:7848:1ec7:b697:7d50]) by smtp.gmail.com with ESMTPSA id 204sm10654051pfu.91.2022.02.06.22.33.56 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 06 Feb 2022 22:33:57 -0800 (PST) From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski@canonical.com, semen.protsenko@linaro.org, yangyicong@hisilicon.com, wsa@kernel.org, jie.deng@intel.com, sven@svenpeter.dev, bence98@sch.bme.hu, lukas.bulwahn@gmail.com, arnd@arndb.de, olof@lixom.net, andriy.shevchenko@linux.intel.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 4/6] i2c: npcm: Handle spurious interrupts Date: Mon, 7 Feb 2022 14:33:36 +0800 Message-Id: <20220207063338.6570-5-warp5tw@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220207063338.6570-1-warp5tw@gmail.com> References: <20220207063338.6570-1-warp5tw@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Tali Perry In order to better handle spurious interrupts: 1. Disable incoming interrupts in master only mode. 2. Clear EOB after every interrupt. 3. Return correct status during interrupt. Fixes: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver") Signed-off-by: Tali Perry Signed-off-by: Tyrone Ting --- drivers/i2c/busses/i2c-npcm7xx.c | 96 +++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 31 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 5c22e69afe34..1ddf309b91a3 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -360,14 +360,14 @@ static int npcm_i2c_get_SCL(struct i2c_adapter *_adap) { struct npcm_i2c *bus = container_of(_adap, struct npcm_i2c, adap); - return !!(I2CCTL3_SCL_LVL & ioread32(bus->reg + NPCM_I2CCTL3)); + return !!(I2CCTL3_SCL_LVL & ioread8(bus->reg + NPCM_I2CCTL3)); } static int npcm_i2c_get_SDA(struct i2c_adapter *_adap) { struct npcm_i2c *bus = container_of(_adap, struct npcm_i2c, adap); - return !!(I2CCTL3_SDA_LVL & ioread32(bus->reg + NPCM_I2CCTL3)); + return !!(I2CCTL3_SDA_LVL & ioread8(bus->reg + NPCM_I2CCTL3)); } static inline u16 npcm_i2c_get_index(struct npcm_i2c *bus) @@ -564,6 +564,15 @@ static inline void npcm_i2c_nack(struct npcm_i2c *bus) iowrite8(val, bus->reg + NPCM_I2CCTL1); } +static inline void npcm_i2c_clear_master_status(struct npcm_i2c *bus) +{ + u8 val; + + /* Clear NEGACK, STASTR and BER bits */ + val = NPCM_I2CST_BER | NPCM_I2CST_NEGACK | NPCM_I2CST_STASTR; + iowrite8(val, bus->reg + NPCM_I2CST); +} + #if IS_ENABLED(CONFIG_I2C_SLAVE) static void npcm_i2c_slave_int_enable(struct npcm_i2c *bus, bool enable) { @@ -643,8 +652,8 @@ static void npcm_i2c_reset(struct npcm_i2c *bus) iowrite8(NPCM_I2CCST_BB, bus->reg + NPCM_I2CCST); iowrite8(0xFF, bus->reg + NPCM_I2CST); - /* Clear EOB bit */ - iowrite8(NPCM_I2CCST3_EO_BUSY, bus->reg + NPCM_I2CCST3); + /* Clear and disable EOB */ + npcm_i2c_eob_int(bus, false); /* Clear all fifo bits: */ iowrite8(NPCM_I2CFIF_CTS_CLR_FIFO, bus->reg + NPCM_I2CFIF_CTS); @@ -656,6 +665,9 @@ static void npcm_i2c_reset(struct npcm_i2c *bus) } #endif + /* clear status bits for spurious interrupts */ + npcm_i2c_clear_master_status(bus); + bus->state = I2C_IDLE; } @@ -818,15 +830,6 @@ static void npcm_i2c_read_fifo(struct npcm_i2c *bus, u8 bytes_in_fifo) } } -static inline void npcm_i2c_clear_master_status(struct npcm_i2c *bus) -{ - u8 val; - - /* Clear NEGACK, STASTR and BER bits */ - val = NPCM_I2CST_BER | NPCM_I2CST_NEGACK | NPCM_I2CST_STASTR; - iowrite8(val, bus->reg + NPCM_I2CST); -} - static void npcm_i2c_master_abort(struct npcm_i2c *bus) { /* Only current master is allowed to issue a stop condition */ @@ -1234,7 +1237,16 @@ static irqreturn_t npcm_i2c_int_slave_handler(struct npcm_i2c *bus) ret = IRQ_HANDLED; } /* SDAST */ - return ret; + /* + * if irq is not one of the above, make sure EOB is disabled and all + * status bits are cleared. + */ + if (ret == IRQ_NONE) { + npcm_i2c_eob_int(bus, false); + npcm_i2c_clear_master_status(bus); + } + + return IRQ_HANDLED; } static int npcm_i2c_reg_slave(struct i2c_client *client) @@ -1470,6 +1482,9 @@ static void npcm_i2c_irq_handle_nack(struct npcm_i2c *bus) npcm_i2c_eob_int(bus, false); npcm_i2c_master_stop(bus); + /* Clear SDA Status bit (by reading dummy byte) */ + npcm_i2c_rd_byte(bus); + /* * The bus is released from stall only after the SW clears * NEGACK bit. Then a Stop condition is sent. @@ -1477,6 +1492,8 @@ static void npcm_i2c_irq_handle_nack(struct npcm_i2c *bus) npcm_i2c_clear_master_status(bus); readx_poll_timeout_atomic(ioread8, bus->reg + NPCM_I2CCST, val, !(val & NPCM_I2CCST_BUSY), 10, 200); + /* verify no status bits are still set after bus is released */ + npcm_i2c_clear_master_status(bus); } bus->state = I2C_IDLE; @@ -1675,10 +1692,10 @@ static int npcm_i2c_recovery_tgclk(struct i2c_adapter *_adap) int iter = 27; if ((npcm_i2c_get_SDA(_adap) == 1) && (npcm_i2c_get_SCL(_adap) == 1)) { - dev_dbg(bus->dev, "bus%d recovery skipped, bus not stuck", - bus->num); + dev_dbg(bus->dev, "bus%d-0x%x recovery skipped, bus not stuck", + bus->num, bus->dest_addr); npcm_i2c_reset(bus); - return status; + return 0; } npcm_i2c_int_enable(bus, false); @@ -1912,6 +1929,7 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode, bus_freq_hz < I2C_FREQ_MIN_HZ || bus_freq_hz > I2C_FREQ_MAX_HZ) return -EINVAL; + npcm_i2c_int_enable(bus, false); npcm_i2c_disable(bus); /* Configure FIFO mode : */ @@ -1940,10 +1958,18 @@ static int npcm_i2c_init_module(struct npcm_i2c *bus, enum i2c_mode mode, val = (val | NPCM_I2CCTL1_NMINTE) & ~NPCM_I2CCTL1_RWS; iowrite8(val, bus->reg + NPCM_I2CCTL1); - npcm_i2c_int_enable(bus, true); - npcm_i2c_reset(bus); + /* check HW is OK: SDA and SCL should be high at this point. */ + if ((npcm_i2c_get_SDA(&bus->adap) == 0) || + (npcm_i2c_get_SCL(&bus->adap) == 0)) { + dev_err(bus->dev, "I2C%d init fail: lines are low", bus->num); + dev_err(bus->dev, "SDA=%d SCL=%d", npcm_i2c_get_SDA(&bus->adap), + npcm_i2c_get_SCL(&bus->adap)); + return -ENXIO; + } + + npcm_i2c_int_enable(bus, true); return 0; } @@ -1991,10 +2017,14 @@ static irqreturn_t npcm_i2c_bus_irq(int irq, void *dev_id) #if IS_ENABLED(CONFIG_I2C_SLAVE) if (bus->slave) { bus->master_or_slave = I2C_SLAVE; - return npcm_i2c_int_slave_handler(bus); + if (npcm_i2c_int_slave_handler(bus)) + return IRQ_HANDLED; } #endif - return IRQ_NONE; + /* clear status bits for spurious interrupts */ + npcm_i2c_clear_master_status(bus); + + return IRQ_HANDLED; } static bool npcm_i2c_master_start_xmit(struct npcm_i2c *bus, @@ -2051,7 +2081,6 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, u8 *write_data, *read_data; u8 slave_addr; unsigned long timeout; - int ret = 0; bool read_block = false; bool read_PEC = false; u8 bus_busy; @@ -2141,12 +2170,12 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, bus->read_block_use = read_block; reinit_completion(&bus->cmd_complete); - if (!npcm_i2c_master_start_xmit(bus, slave_addr, nwrite, nread, - write_data, read_data, read_PEC, - read_block)) - ret = -EBUSY; - if (ret != -EBUSY) { + npcm_i2c_int_enable(bus, true); + + if (npcm_i2c_master_start_xmit(bus, slave_addr, nwrite, nread, + write_data, read_data, read_PEC, + read_block)) { time_left = wait_for_completion_timeout(&bus->cmd_complete, timeout); @@ -2160,26 +2189,31 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, } } } - ret = bus->cmd_err; /* if there was BER, check if need to recover the bus: */ if (bus->cmd_err == -EAGAIN) - ret = i2c_recover_bus(adap); + bus->cmd_err = i2c_recover_bus(adap); /* * After any type of error, check if LAST bit is still set, * due to a HW issue. * It cannot be cleared without resetting the module. */ - if (bus->cmd_err && - (NPCM_I2CRXF_CTL_LAST_PEC & ioread8(bus->reg + NPCM_I2CRXF_CTL))) + else if (bus->cmd_err && + (NPCM_I2CRXF_CTL_LAST_PEC & ioread8(bus->reg + NPCM_I2CRXF_CTL))) npcm_i2c_reset(bus); + /* after any xfer, successful or not, stall and EOB must be disabled */ + npcm_i2c_stall_after_start(bus, false); + npcm_i2c_eob_int(bus, false); + #if IS_ENABLED(CONFIG_I2C_SLAVE) /* reenable slave if it was enabled */ if (bus->slave) iowrite8((bus->slave->addr & 0x7F) | NPCM_I2CADDR_SAEN, bus->reg + NPCM_I2CADDR1); +#else + npcm_i2c_int_enable(bus, false); #endif return bus->cmd_err; } From patchwork Mon Feb 7 06:33:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 540620 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 81C91C4321E for ; Mon, 7 Feb 2022 06:56:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235412AbiBGG4N (ORCPT ); Mon, 7 Feb 2022 01:56:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241891AbiBGGeB (ORCPT ); Mon, 7 Feb 2022 01:34:01 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AA12C043184; Sun, 6 Feb 2022 22:34:00 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id y7so5129950plp.2; Sun, 06 Feb 2022 22:34:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+MqqM6tGyjbKjTboDXjFmiWET4pIP1qrQBFIZ6c46cU=; b=P5bnYBJfDsOkUTYIaJSy2VvWW6Wvh+nbRYCQSGnR2534RfjwGkvzzMq4LHkL2/jvmL IGGGq5CA3TPG8U3jqleottZ+CMFBfuUOjh5soppe68jXg92Z2Gq/EHXhqaSbR4TbSNjc Sn/dOR7lMKK9jfaaFuAfp9LrNl3FnJiYagFq/S30TNOh49id2d83TOe9VOHVhr8Nl2IR cbptwC0i/cY2aoZZDSP23ZLSGUaPLVRE7ZJtmdOGFoBPIzMuQ0pAx0aLHIlg2D7cxD1f JlGfOEXt1DSzUFGy6PJkxGN9H/9ALtDSKzXH2nD+dHDWUwX+D+it29GLEwPa5RdCVAAb bh4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+MqqM6tGyjbKjTboDXjFmiWET4pIP1qrQBFIZ6c46cU=; b=j3mJqauV5vtCsmEAmakEXJ05xapjxKuyoTbqdoW3A8GObnYc+b7fLbjRzlwJpkSsyo xJ0wXs/uuLkGSFvVQrIkmN3FQurC9T/gi5uLo6iRiU2Y6/x+vUR+KUdZbY8VPqJ9V9nn 7BcCoc10BY2RU3jpqPNeqmQpZ9D8T6FLW57dJzzL0f2amIrf9gr6FbBGR8nkePIaUTaz j9KgbPpmd2ckndR5mxXNRVfUizePX2e54e/8hEja9oyhyRe2vXsvgC0M55VXYnqe5Mf/ ZzLL10RYC0/+KUHNnV7HaluaTXmhjyr7aUlE3/nLXgurkf7xKjJTT/UTAQ0jxJhplo2T BtjQ== X-Gm-Message-State: AOAM531SDiDbQY79JznTxVg9cUnETP9qKtjXXiNoRFGy9IVNKqGwGdku 3r0lOCs6AhyGmetD6dm9oXjRqXGuXMfjMlw= X-Google-Smtp-Source: ABdhPJxlUUaid24a39E6u5RfKpUrqK+tScS5xaa9m6Q/VX1CeNlx7GBM6zh5bvKdVgUmtzRktoxi6g== X-Received: by 2002:a17:902:d641:: with SMTP id y1mr14826366plh.64.1644215639633; Sun, 06 Feb 2022 22:33:59 -0800 (PST) Received: from localhost ([2401:e180:8894:9737:7848:1ec7:b697:7d50]) by smtp.gmail.com with ESMTPSA id e14sm10546295pfv.219.2022.02.06.22.33.58 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 06 Feb 2022 22:33:59 -0800 (PST) From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski@canonical.com, semen.protsenko@linaro.org, yangyicong@hisilicon.com, wsa@kernel.org, jie.deng@intel.com, sven@svenpeter.dev, bence98@sch.bme.hu, lukas.bulwahn@gmail.com, arnd@arndb.de, olof@lixom.net, andriy.shevchenko@linux.intel.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 5/6] i2c: npcm: Remove own slave addresses 2:10 Date: Mon, 7 Feb 2022 14:33:37 +0800 Message-Id: <20220207063338.6570-6-warp5tw@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220207063338.6570-1-warp5tw@gmail.com> References: <20220207063338.6570-1-warp5tw@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Tali Perry NPCM can support up to 10 own slave addresses. In practice, only one address is actually being used. In order to access addresses 2 and above, need to switch register banks. The switch needs spinlock. To avoid using spinlock for this useless feature removed support of SA >= 2. Also fix returned slave event enum. Fixes: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver") Signed-off-by: Tali Perry Signed-off-by: Tyrone Ting --- drivers/i2c/busses/i2c-npcm7xx.c | 44 +++++++++++++++++--------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 1ddf309b91a3..0af97f179af2 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -124,6 +124,8 @@ enum i2c_addr { * use this array to get the address or each register. */ #define I2C_NUM_OWN_ADDR 10 +#define I2C_NUM_OWN_ADDR_SUPPORTED 2 + static const int npcm_i2caddr[I2C_NUM_OWN_ADDR] = { NPCM_I2CADDR1, NPCM_I2CADDR2, NPCM_I2CADDR3, NPCM_I2CADDR4, NPCM_I2CADDR5, NPCM_I2CADDR6, NPCM_I2CADDR7, NPCM_I2CADDR8, @@ -393,13 +395,11 @@ static void npcm_i2c_disable(struct npcm_i2c *bus) int i; /* select bank 0 for I2C addresses */ - npcm_i2c_select_bank(bus, I2C_BANK_0); /* Slave addresses removal */ - for (i = I2C_SLAVE_ADDR1; i < I2C_NUM_OWN_ADDR; i++) + for (i = I2C_SLAVE_ADDR1; i < I2C_NUM_OWN_ADDR_SUPPORTED; i++) iowrite8(0, bus->reg + npcm_i2caddr[i]); - npcm_i2c_select_bank(bus, I2C_BANK_1); #endif /* Disable module */ i2cctl2 = ioread8(bus->reg + NPCM_I2CCTL2); @@ -604,8 +604,7 @@ static int npcm_i2c_slave_enable(struct npcm_i2c *bus, enum i2c_addr addr_type, i2cctl1 &= ~NPCM_I2CCTL1_GCMEN; iowrite8(i2cctl1, bus->reg + NPCM_I2CCTL1); return 0; - } - if (addr_type == I2C_ARP_ADDR) { + } else if (addr_type == I2C_ARP_ADDR) { i2cctl3 = ioread8(bus->reg + NPCM_I2CCTL3); if (enable) i2cctl3 |= I2CCTL3_ARPMEN; @@ -614,16 +613,18 @@ static int npcm_i2c_slave_enable(struct npcm_i2c *bus, enum i2c_addr addr_type, iowrite8(i2cctl3, bus->reg + NPCM_I2CCTL3); return 0; } + if (addr_type > I2C_SLAVE_ADDR2 && addr_type <= I2C_SLAVE_ADDR10) { + dev_err(bus->dev, + "try to enable more then 2 SA not supported\n"); + } if (addr_type >= I2C_ARP_ADDR) return -EFAULT; /* select bank 0 for address 3 to 10 */ - if (addr_type > I2C_SLAVE_ADDR2) - npcm_i2c_select_bank(bus, I2C_BANK_0); + /* Set and enable the address */ iowrite8(sa_reg, bus->reg + npcm_i2caddr[addr_type]); npcm_i2c_slave_int_enable(bus, enable); - if (addr_type > I2C_SLAVE_ADDR2) - npcm_i2c_select_bank(bus, I2C_BANK_1); + return 0; } #endif @@ -846,15 +847,13 @@ static u8 npcm_i2c_get_slave_addr(struct npcm_i2c *bus, enum i2c_addr addr_type) { u8 slave_add; - /* select bank 0 for address 3 to 10 */ - if (addr_type > I2C_SLAVE_ADDR2) - npcm_i2c_select_bank(bus, I2C_BANK_0); + if (addr_type > I2C_SLAVE_ADDR2 && addr_type <= I2C_SLAVE_ADDR10) { + dev_err(bus->dev, + "get slave: try to use more then 2 slave addresses not supported\n"); + } slave_add = ioread8(bus->reg + npcm_i2caddr[(int)addr_type]); - if (addr_type > I2C_SLAVE_ADDR2) - npcm_i2c_select_bank(bus, I2C_BANK_1); - return slave_add; } @@ -864,12 +863,12 @@ static int npcm_i2c_remove_slave_addr(struct npcm_i2c *bus, u8 slave_add) /* Set the enable bit */ slave_add |= 0x80; - npcm_i2c_select_bank(bus, I2C_BANK_0); - for (i = I2C_SLAVE_ADDR1; i < I2C_NUM_OWN_ADDR; i++) { + + for (i = I2C_SLAVE_ADDR1; i < I2C_NUM_OWN_ADDR_SUPPORTED; i++) { if (ioread8(bus->reg + npcm_i2caddr[i]) == slave_add) iowrite8(0, bus->reg + npcm_i2caddr[i]); } - npcm_i2c_select_bank(bus, I2C_BANK_1); + return 0; } @@ -924,11 +923,15 @@ static int npcm_i2c_slave_get_wr_buf(struct npcm_i2c *bus) for (i = 0; i < I2C_HW_FIFO_SIZE; i++) { if (bus->slv_wr_size >= I2C_HW_FIFO_SIZE) break; - i2c_slave_event(bus->slave, I2C_SLAVE_READ_REQUESTED, &value); + if (bus->state == I2C_SLAVE_MATCH) { + i2c_slave_event(bus->slave, I2C_SLAVE_READ_REQUESTED, &value); + bus->state = I2C_OPER_STARTED; + } else { + i2c_slave_event(bus->slave, I2C_SLAVE_READ_PROCESSED, &value); + } ind = (bus->slv_wr_ind + bus->slv_wr_size) % I2C_HW_FIFO_SIZE; bus->slv_wr_buf[ind] = value; bus->slv_wr_size++; - i2c_slave_event(bus->slave, I2C_SLAVE_READ_PROCESSED, &value); } return I2C_HW_FIFO_SIZE - ret; } @@ -976,7 +979,6 @@ static void npcm_i2c_slave_xmit(struct npcm_i2c *bus, u16 nwrite, if (nwrite == 0) return; - bus->state = I2C_OPER_STARTED; bus->operation = I2C_WRITE_OPER; /* get the next buffer */ From patchwork Mon Feb 7 06:33:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyrone Ting X-Patchwork-Id: 540621 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 624F8C43217 for ; Mon, 7 Feb 2022 06:56:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237919AbiBGG4P (ORCPT ); Mon, 7 Feb 2022 01:56:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241904AbiBGGeC (ORCPT ); Mon, 7 Feb 2022 01:34:02 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CB4CC043184; Sun, 6 Feb 2022 22:34:02 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id y5so10387700pfe.4; Sun, 06 Feb 2022 22:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mhJRr6Ju7YTAqWP+NHZiUEBspRCG8tPgABYtYdOV4pU=; b=kgv9qIxcOAl00fJbBE36HCUZIex7mzcHlsxsDC4PI0wk0AxU79tg/Oz/hMwL/J9DSo Z/rL7sJIm75pwHpfZ3y7CYxmhVLwBrKKDbKhcZFGJX4SsC+5o0zmNbsWb3Hj90+liiJi lu6kFMsi1om2bS6Ff/z+HQ0+OiXmUXVa42q/j28HEWD1asLat4xY2r6jd5v1+7lSB7lp wBT/s0AbcMLDG+oxQXSPEghinlicKL35vdg3evTgK1MVK1I4KtNmepIZuRWatnaGlEe5 u07RCM3VApz4wjMzMKhWFiE2ErShnwzPA7+kXIQVLyCMNRGCHz9fCTMQm0gBz3BJiHuZ GJCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mhJRr6Ju7YTAqWP+NHZiUEBspRCG8tPgABYtYdOV4pU=; b=MXsTssc1P4sYXs+AuorwFmIU6CZN+Y71WabOP9AqGLPgbXEUhY1SXwhu2hG8H+e4/R 7BJgFlL6LWssUSetK8nP+7rSctFtvdW+VsJzGDv9jnFpoh/5IftMw6rV6DWrqjJDpNvf tVWbtUdxM0BPj+Y0NXqHiXph+ClV527CSGq8QULRqcGy9o+a9FcOIMI/hMBRlx4L1WxF MTfemMc0sQADW5rKvA4CXH7lNT6DCe7auHS+nwfe6nMoAAzvORLiDsCkzRjXnbuqBWOr fkqksVd1z5ODbnZVewiy7HePhRBK5XwnGvBBEGxcRq0Df9kS2PkDXRGW7hi7tblnlGFR /Jjw== X-Gm-Message-State: AOAM532Z81v7pZgnQjTeJESkvPLKYOHvbg6PbVlfuB7sfRQ+gNUDO9wK t6hSnCAdnLMsWaTRa9t8ZA== X-Google-Smtp-Source: ABdhPJz6k1PrV83uFSGzfl5ns0STtTqZJNu/qmyGba9TES0tLiKROkRMHkZJ/jKpSYvMiKf9q9DPzQ== X-Received: by 2002:aa7:8582:: with SMTP id w2mr14514042pfn.3.1644215641791; Sun, 06 Feb 2022 22:34:01 -0800 (PST) Received: from localhost ([2401:e180:8894:9737:7848:1ec7:b697:7d50]) by smtp.gmail.com with ESMTPSA id u11sm10827033pfg.171.2022.02.06.22.34.01 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 06 Feb 2022 22:34:01 -0800 (PST) From: Tyrone Ting To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski@canonical.com, semen.protsenko@linaro.org, yangyicong@hisilicon.com, wsa@kernel.org, jie.deng@intel.com, sven@svenpeter.dev, bence98@sch.bme.hu, lukas.bulwahn@gmail.com, arnd@arndb.de, olof@lixom.net, andriy.shevchenko@linux.intel.com, warp5tw@gmail.com, tali.perry@nuvoton.com, Avi.Fishman@nuvoton.com, tomer.maimon@nuvoton.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, kfting@nuvoton.com Cc: openbmc@lists.ozlabs.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 6/6] i2c: npcm: Support NPCM845 Date: Mon, 7 Feb 2022 14:33:38 +0800 Message-Id: <20220207063338.6570-7-warp5tw@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220207063338.6570-1-warp5tw@gmail.com> References: <20220207063338.6570-1-warp5tw@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Tyrone Ting NPCM8XX uses a similar i2c module as NPCM7XX. The only difference is that the internal HW FIFO is larger. Related Makefile and Kconfig files are modified to support as well. Fixes: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver") Signed-off-by: Tyrone Ting Signed-off-by: Tali Perry --- drivers/i2c/busses/Kconfig | 8 ++++---- drivers/i2c/busses/Makefile | 2 +- drivers/i2c/busses/i2c-npcm7xx.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 42da31c1ab70..ab9ee2de5e00 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -817,13 +817,13 @@ config I2C_NOMADIK I2C interface from ST-Ericsson's Nomadik and Ux500 architectures, as well as the STA2X11 PCIe I/O HUB. -config I2C_NPCM7XX +config I2C_NPCM tristate "Nuvoton I2C Controller" - depends on ARCH_NPCM7XX || COMPILE_TEST + depends on ARCH_NPCM || COMPILE_TEST help If you say yes to this option, support will be included for the - Nuvoton I2C controller, which is available on the NPCM7xx BMC - controller. + Nuvoton I2C controller, which is available on the NPCM BMC + controllers. Driver can also support slave mode (select I2C_SLAVE). config I2C_OCORES diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 1d00dce77098..01fdf74a5565 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -80,7 +80,7 @@ obj-$(CONFIG_I2C_MT7621) += i2c-mt7621.o obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o obj-$(CONFIG_I2C_MXS) += i2c-mxs.o obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o -obj-$(CONFIG_I2C_NPCM7XX) += i2c-npcm7xx.o +obj-$(CONFIG_I2C_NPCM) += i2c-npcm7xx.o obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o obj-$(CONFIG_I2C_OMAP) += i2c-omap.o obj-$(CONFIG_I2C_OWL) += i2c-owl.o diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 0af97f179af2..4e0148ccc215 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -91,7 +91,11 @@ enum i2c_addr { /* init register and default value required to enable module */ #define NPCM_I2CSEGCTL 0xE4 +#ifdef CONFIG_ARCH_NPCM7XX #define NPCM_I2CSEGCTL_INIT_VAL 0x0333F000 +#else +#define NPCM_I2CSEGCTL_INIT_VAL 0x9333F000 +#endif /* Common regs */ #define NPCM_I2CSDA 0x00 @@ -229,7 +233,11 @@ static const int npcm_i2caddr[I2C_NUM_OWN_ADDR] = { #define NPCM_I2CFIF_CTS_SLVRSTR BIT(7) /* NPCM_I2CTXF_CTL reg fields */ +#ifdef CONFIG_ARCH_NPCM7XX #define NPCM_I2CTXF_CTL_TX_THR GENMASK(4, 0) +#else +#define NPCM_I2CTXF_CTL_TX_THR GENMASK(5, 0) +#endif /*CONFIG_ARCH_NPCM7XX*/ #define NPCM_I2CTXF_CTL_THR_TXIE BIT(6) /* NPCM_I2CT_OUT reg fields */ @@ -238,22 +246,42 @@ static const int npcm_i2caddr[I2C_NUM_OWN_ADDR] = { #define NPCM_I2CT_OUT_T_OUTST BIT(7) /* NPCM_I2CTXF_STS reg fields */ +#ifdef CONFIG_ARCH_NPCM7XX #define NPCM_I2CTXF_STS_TX_BYTES GENMASK(4, 0) +#else +#define NPCM_I2CTXF_STS_TX_BYTES GENMASK(5, 0) +#endif /*CONFIG_ARCH_NPCM7XX*/ #define NPCM_I2CTXF_STS_TX_THST BIT(6) /* NPCM_I2CRXF_STS reg fields */ +#ifdef CONFIG_ARCH_NPCM7XX #define NPCM_I2CRXF_STS_RX_BYTES GENMASK(4, 0) +#else +#define NPCM_I2CRXF_STS_RX_BYTES GENMASK(5, 0) +#endif /*CONFIG_ARCH_NPCM7XX*/ #define NPCM_I2CRXF_STS_RX_THST BIT(6) /* NPCM_I2CFIF_CTL reg fields */ #define NPCM_I2CFIF_CTL_FIFO_EN BIT(4) /* NPCM_I2CRXF_CTL reg fields */ +#ifdef CONFIG_ARCH_NPCM7XX #define NPCM_I2CRXF_CTL_RX_THR GENMASK(4, 0) +#else +#define NPCM_I2CRXF_CTL_RX_THR GENMASK(5, 0) +#endif /*CONFIG_ARCH_NPCM7XX*/ +#ifdef CONFIG_ARCH_NPCM7XX #define NPCM_I2CRXF_CTL_LAST_PEC BIT(5) +#else +#define NPCM_I2CRXF_CTL_LAST_PEC BIT(7) +#endif /*CONFIG_ARCH_NPCM7XX*/ #define NPCM_I2CRXF_CTL_THR_RXIE BIT(6) +#ifdef CONFIG_ARCH_NPCM7XX #define I2C_HW_FIFO_SIZE 16 +#else +#define I2C_HW_FIFO_SIZE 32 +#endif /* CONFIG_ARCH_NPCM7XX */ /* I2C_VER reg fields */ #define I2C_VER_VERSION GENMASK(6, 0) @@ -2356,6 +2384,7 @@ static int npcm_i2c_remove_bus(struct platform_device *pdev) static const struct of_device_id npcm_i2c_bus_of_table[] = { { .compatible = "nuvoton,npcm750-i2c", }, + { .compatible = "nuvoton,npcm845-i2c", }, {} }; MODULE_DEVICE_TABLE(of, npcm_i2c_bus_of_table);