From patchwork Wed Apr 3 01:18:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ray Jui X-Patchwork-Id: 10882523 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DFDEE1669 for ; Wed, 3 Apr 2019 01:20:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC862285B7 for ; Wed, 3 Apr 2019 01:20:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADE7D285EB; Wed, 3 Apr 2019 01:20:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2AFF6285B7 for ; Wed, 3 Apr 2019 01:20:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=2Ihfvmh8xvHyl02M0hIdf2BVsCqoMbhTEwvov7KRSlw=; b=T3oY7UDCxBgH72vWCL4jxX0ail i8Zch75/ZEhT7Ylq+dX3bkKpWPGFGV8Z0Ez1C1EWIxSxIjHf5By5nuMAUeRTcgKujow/QWZgItm1X /5UMX9Vm319DIgNtdSEX5pJ0i5MO2reY70GXm9PhT30nqpWWF9epTy4Qf8SNTMxyPXCnv9VOjKGnN /GdZUPRPInN5j9izX2Pj/nXOk69HylUVIiT17XSUkw6VnAmHN/qXbbYIiBd2g3WbOmmyhWEYnccWs z+5NbGzmatZg7hupSRTztCG/mDrj1+7ocinvT57EYTfOaWtpbab150yb4Rloo3GCVYKW8Eg9NRVyv gmBh2eig==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBUZk-0002wf-IJ; Wed, 03 Apr 2019 01:20:24 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBUYa-0000IZ-PI for linux-arm-kernel@lists.infradead.org; Wed, 03 Apr 2019 01:19:46 +0000 Received: by mail-pl1-x641.google.com with SMTP id b65so7147627plb.6 for ; Tue, 02 Apr 2019 18:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mS9RC9bQ7HGbKLDI0eFIMx9AuPi+28D39D6SdQFqmaw=; b=XilDYbNKVC+li380iKpO9emCX9eUABns4oap/dQdGHG3q9wDW3jZam+IwE5yyHsrw7 39ElK6uP8KtQTPu9fr4Oc2YqPibCxAXgnH50xZP1q96Sr2kX784a+dF0GolzhX5Vj940 39fSPkhH3sVOeHm0H5OSe9BWPd/Ft9gnljZLs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mS9RC9bQ7HGbKLDI0eFIMx9AuPi+28D39D6SdQFqmaw=; b=hAxxWBLZsIsNrOM+8+Nx6nPPZJ9ZM8ORA4jlAjtTdV7waesRSPCMN9rMOndDZ9n++V PLW4IjbtueeYmFe8jI7igTuS5SwjY5h9IzgBNkzj+dmqDb7WZ3xruSM3efSBLt7EhRny ggqfLwwZCT9tCYRuMLElLPcgoL/byM96gvF+4ylujZpud4iQhVrG3srhG/G5MT4IiwMR ZA3ytxcEZb7wOg5Ihz3wqk7lg4Qa9hsB0KIk9fjmyOMUzna2MVQEJpfT/RYzAzrz0Chv 0LIbQOrpL/8A91FR45QUowo34IUhpvQLDLrX1RCMzyYoL01MwjoaifsWdhUl5KNn8J6M FtjA== X-Gm-Message-State: APjAAAW6IEvCZ6yeuBUdYAfn3/55sfDI/DwRsDeZ2ZZ1k42GTWjX3JoD VYstmojBEW+wUe0w8wtDCwZO1g== X-Google-Smtp-Source: APXvYqz9zy4QDTyy1AsNtv+q2sre13FbbDiqCZLktsSCvz3tS0TPPT/39PaZV/SO9Iw9kd1IrgSmWg== X-Received: by 2002:a17:902:6b48:: with SMTP id g8mr73270177plt.21.1554254352092; Tue, 02 Apr 2019 18:19:12 -0700 (PDT) Received: from rj-aorus.ric.broadcom.com ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id 4sm19589046pfn.159.2019.04.02.18.19.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 18:19:11 -0700 (PDT) From: Ray Jui To: Wolfram Sang , Rob Herring , Mark Rutland Subject: [PATCH v6 8/9] i2c: iproc: add NIC I2C support Date: Tue, 2 Apr 2019 18:18:29 -0700 Message-Id: <20190403011830.3254-9-ray.jui@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190403011830.3254-1-ray.jui@broadcom.com> References: <20190403011830.3254-1-ray.jui@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190402_181913_478790_E06F81BB X-CRM114-Status: GOOD ( 19.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Rayagonda Kokatanur , linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-i2c@vger.kernel.org, Ray Jui , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rayagonda Kokatanur Add NIC I2C support to the iProc I2C driver. Access to the NIC I2C base registers requires going through the IDM wrapper to map into the NIC's address space Signed-off-by: Rayagonda Kokatanur Signed-off-by: Ray Jui --- drivers/i2c/busses/i2c-bcm-iproc.c | 80 ++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c index dba1a9d925b2..562942d0c05c 100644 --- a/drivers/i2c/busses/i2c-bcm-iproc.c +++ b/drivers/i2c/busses/i2c-bcm-iproc.c @@ -17,9 +17,11 @@ #include #include #include +#include #include #include +#define IDM_CTRL_DIRECT_OFFSET 0x00 #define CFG_OFFSET 0x00 #define CFG_RESET_SHIFT 31 #define CFG_EN_SHIFT 30 @@ -174,11 +176,23 @@ enum bus_speed_index { I2C_SPD_400K, }; +enum bcm_iproc_i2c_type { + IPROC_I2C, + IPROC_I2C_NIC +}; + struct bcm_iproc_i2c_dev { struct device *device; + enum bcm_iproc_i2c_type type; int irq; void __iomem *base; + void __iomem *idm_base; + + u32 ape_addr_mask; + + /* lock for indirect access through IDM */ + spinlock_t idm_lock; struct i2c_adapter adapter; unsigned int bus_speed; @@ -215,13 +229,33 @@ static void bcm_iproc_i2c_enable_disable(struct bcm_iproc_i2c_dev *iproc_i2c, static inline u32 iproc_i2c_rd_reg(struct bcm_iproc_i2c_dev *iproc_i2c, u32 offset) { - return readl(iproc_i2c->base + offset); + u32 val; + + if (iproc_i2c->idm_base) { + spin_lock(&iproc_i2c->idm_lock); + writel(iproc_i2c->ape_addr_mask, + iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET); + val = readl(iproc_i2c->base + offset); + spin_unlock(&iproc_i2c->idm_lock); + } else { + val = readl(iproc_i2c->base + offset); + } + + return val; } static inline void iproc_i2c_wr_reg(struct bcm_iproc_i2c_dev *iproc_i2c, u32 offset, u32 val) { - writel(val, iproc_i2c->base + offset); + if (iproc_i2c->idm_base) { + spin_lock(&iproc_i2c->idm_lock); + writel(iproc_i2c->ape_addr_mask, + iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET); + writel(val, iproc_i2c->base + offset); + spin_unlock(&iproc_i2c->idm_lock); + } else { + writel(val, iproc_i2c->base + offset); + } } static void bcm_iproc_i2c_slave_init( @@ -765,10 +799,15 @@ static int bcm_iproc_i2c_xfer(struct i2c_adapter *adapter, static uint32_t bcm_iproc_i2c_functionality(struct i2c_adapter *adap) { - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_SLAVE; + u32 val = I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; + + if (adap->algo->reg_slave) + val |= I2C_FUNC_SLAVE; + + return val; } -static const struct i2c_algorithm bcm_iproc_algo = { +static struct i2c_algorithm bcm_iproc_algo = { .master_xfer = bcm_iproc_i2c_xfer, .functionality = bcm_iproc_i2c_functionality, .reg_slave = bcm_iproc_i2c_reg_slave, @@ -828,6 +867,8 @@ static int bcm_iproc_i2c_probe(struct platform_device *pdev) platform_set_drvdata(pdev, iproc_i2c); iproc_i2c->device = &pdev->dev; + iproc_i2c->type = + (enum bcm_iproc_i2c_type)of_device_get_match_data(&pdev->dev); init_completion(&iproc_i2c->done); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -835,6 +876,29 @@ static int bcm_iproc_i2c_probe(struct platform_device *pdev) if (IS_ERR(iproc_i2c->base)) return PTR_ERR(iproc_i2c->base); + if (iproc_i2c->type == IPROC_I2C_NIC) { + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + iproc_i2c->idm_base = devm_ioremap_resource(iproc_i2c->device, + res); + if (IS_ERR(iproc_i2c->idm_base)) + return PTR_ERR(iproc_i2c->idm_base); + + ret = of_property_read_u32(iproc_i2c->device->of_node, + "brcm,ape-hsls-addr-mask", + &iproc_i2c->ape_addr_mask); + if (ret < 0) { + dev_err(iproc_i2c->device, + "'brcm,ape-hsls-addr-mask' missing\n"); + return -EINVAL; + } + + spin_lock_init(&iproc_i2c->idm_lock); + + /* no slave support */ + bcm_iproc_algo.reg_slave = NULL; + bcm_iproc_algo.unreg_slave = NULL; + } + ret = bcm_iproc_i2c_init(iproc_i2c); if (ret) return ret; @@ -991,7 +1055,13 @@ static int bcm_iproc_i2c_unreg_slave(struct i2c_client *slave) } static const struct of_device_id bcm_iproc_i2c_of_match[] = { - { .compatible = "brcm,iproc-i2c" }, + { + .compatible = "brcm,iproc-i2c", + .data = (int *)IPROC_I2C, + }, { + .compatible = "brcm,iproc-nic-i2c", + .data = (int *)IPROC_I2C_NIC, + }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, bcm_iproc_i2c_of_match);