Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3863767iob; Tue, 17 May 2022 08:42:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxp8nuWhlUe3S4fuvADjiekPZqSf4Sc31bQRDpLNfFvCY9Sc54I013/4ZsXAycdgCxcTUuN X-Received: by 2002:a17:903:2288:b0:15e:8da2:fcc0 with SMTP id b8-20020a170903228800b0015e8da2fcc0mr23486862plh.125.1652802164080; Tue, 17 May 2022 08:42:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652802164; cv=none; d=google.com; s=arc-20160816; b=LhU2mnE5F3yt/q8TvXS3fCE99T5Q7CThqbV8FL6pQ9Q+KHVAtNOBIndFT1ayRUZtBe JuqOFkFeIJcL/aJY5+85sxyQgvOGAKRHBxUb6grywPZ+3o6slvkxY1dG+x2pXhb/wtpj G1Fg6z/OQERlAdmxMJkFavizhkpT4TC57Ifum7arhlPqWhuRl7+5lKFhHOVuXSicHgMV Rek77ZO0PQPytZWWfBV1srsQJU4/QHeeYs8cjJP9puV7ZP1qpjf6rn63zg3wJJsSGMhY i1juzvuOGJBhLd2agUpcTQmxSe/Nxx9j5Nxx4Sr8nMuFAhQGY5y2fvclHCL2XWL17IuO F/pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=RIGSmdJeUWUk9ww1S0t3EkB8CmRkroCvFd+vm4c7BjY=; b=Pps7lAIjqQNCh9Z9n5W917aVrkczg9WzqeufqIPXjBf3G0yrveugJSxU8WVuCVoVJK wb8fsKSXmRFp8Lp5mGcPP3qcdUL6EXugnIWiyJZ7RsuWbVXu7Zw7N7Vw0vzVp9QFPK46 QHsuOIShQXULTt7IU/rjr77n6bpv9uLHlSpf7nP3Taeqgzy5h5Givfxoghy0ArAr91GG 1Rwrj37wPO0MUIZb4aUsuJXPb5V2ijTEjXMOw3f0EkKy4feh8osA18y+DqwZDofkM4yD OpEDx7Vx02zscPYQ/vez3jvmvk+t85/NkPycfxxMVSswQWKfT7wnSeb070JpSPrbRlgk GWgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gMBQaU2f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d10-20020a656b8a000000b003db43f9cc0asi16721307pgw.169.2022.05.17.08.42.31; Tue, 17 May 2022 08:42:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gMBQaU2f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343793AbiEQKOz (ORCPT + 99 others); Tue, 17 May 2022 06:14:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343900AbiEQKMw (ORCPT ); Tue, 17 May 2022 06:12:52 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C88FF1D331; Tue, 17 May 2022 03:12:10 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id n8so16915449plh.1; Tue, 17 May 2022 03:12:10 -0700 (PDT) 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=RIGSmdJeUWUk9ww1S0t3EkB8CmRkroCvFd+vm4c7BjY=; b=gMBQaU2fD+ZA5lzPjHY29ZXw4cA4rqt52oT2CCUVzgHE/p4JOvjJMzBgg/Ay89GW74 FeorbsdbBUcIMcSCIgH5Uq3vKxg5zG3ERs11Ed8duJlX/UPh6KkRcF6NnwKgYX9wqUUM /8BB/qnBn2txG98uXvDfgY0vg8HQ831kLNpPEg2NfrBRh598QpbMwwhrUwnQ6oW+AB0p dgjJWyPl2gGQN/OXXHERvO4M6WF8WpaqQhG3KHA/Ojxi52f/d9YFz0I26s/HzrS8utai zLbIP2mRW7cAZFghuj4NLn0fN3o4SVReBnWx4xDMdvSfDleFKBscNvVe1VInP/F1hn6E S1oQ== 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=RIGSmdJeUWUk9ww1S0t3EkB8CmRkroCvFd+vm4c7BjY=; b=NXg9V/RPnM2lmgyTAR8BJeqQ7TlVXMQhMhB1p6DCT6VL6tLZ5TNAKUUBuMSP5kcnpi 4wixtbTIJixVqB9I5mTiD2QqH24o1HLDvlxjsgtPiq3tQ6Pi7ahsBleEPI5EeDz2k1Hu mrmn1DuIoIpdTksC+UAc8uYsTXak1E+Mt5Wx7kqGq0SzbmhDPsf7c+D7atMOB2QjjK8h z8ybXw/Em6iMyK2Wy0HOpNY38iTGfYaqrrc6ZW1Dib1t2qhNvAW9C18oVWIR451STs2/ Lr3JGxMq5Z6jNf4Lq395pvGnZpoKLGAIOfIfHLk3j5I3DEPzhimte/F79iXjCqcXrXm5 3P9Q== X-Gm-Message-State: AOAM5300UmRCXzz2vONwTLFq0LjSwcnDNf2Ac5XMtU/AuZomfXVTw7KN Sm/buw8E2FEbuZno1DgMXQ== X-Received: by 2002:a17:90b:3e84:b0:1dc:5942:af0e with SMTP id rj4-20020a17090b3e8400b001dc5942af0emr24076312pjb.61.1652782330081; Tue, 17 May 2022 03:12:10 -0700 (PDT) Received: from localhost (220-133-130-217.hinet-ip.hinet.net. [220.133.130.217]) by smtp.gmail.com with ESMTPSA id a12-20020a170902710c00b0015f2b3bc97asm6232708pll.13.2022.05.17.03.12.09 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 May 2022 03:12:09 -0700 (PDT) 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+dt@linaro.org, wsa@kernel.org, andriy.shevchenko@linux.intel.com, jarkko.nikula@linux.intel.com, semen.protsenko@linaro.org, rafal@milecki.pl, sven@svenpeter.dev, jsd@semihalf.com, jie.deng@intel.com, lukas.bulwahn@gmail.com, arnd@arndb.de, olof@lixom.net, 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 v5 08/10] i2c: npcm: Remove own slave addresses 2:10 Date: Tue, 17 May 2022 18:11:40 +0800 Message-Id: <20220517101142.28421-9-warp5tw@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220517101142.28421-1-warp5tw@gmail.com> References: <20220517101142.28421-1-warp5tw@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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. Remove some comment since the bank selection is not required. The bank selection is not required since the supported slave addresses are reduced. 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 | 43 +++++++++++++++----------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 5960ccde6574..3f86895f5e64 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, @@ -392,14 +394,10 @@ static void npcm_i2c_disable(struct npcm_i2c *bus) #if IS_ENABLED(CONFIG_I2C_SLAVE) 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 +602,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 +611,17 @@ 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 than 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 +844,11 @@ 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 than 2 SA 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 +858,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 +918,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 +974,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 */ -- 2.17.1