Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp497789pxu; Wed, 7 Oct 2020 08:25:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy36e0iPhxDpObyqAjHd9FHxKxm8PGhauQI4nGuOzY6DPiCQDxG0UNiTnARS8xP/oJIPpNx X-Received: by 2002:a17:906:d8a3:: with SMTP id qc3mr3932652ejb.183.1602084312463; Wed, 07 Oct 2020 08:25:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602084312; cv=none; d=google.com; s=arc-20160816; b=TBSepGLXiY+fs05R8ujW5rXNl/orqoI2qXHoBXW+5bDzQyN8jIzSqCNE4agEMNxiCc MQZeEeRkrU9Ya68w3c7tEo9ww9QMmPAvdurUNDkJ1CauiBRX+ojbmnf9O3rlUgWWrU0F cdgI+YyEQzAYpEg9NgN1FAAyOJlCdEa0ZTmIuo8bOjFxMLTJoDwosO8AjZnfi348vWvF SrwWrm4KXKK6Sd2CjhfAI2nPS+Ut2nPG2NSjOXc/IOhK69N4US1JpRABa6+IVp+u6naB 8nx8XmxdTthql39wm83hc8IgG3zSsBKmhOPAOlNH5JXD1aqJ2A9pjp5YfvoL3kDzzIrp awaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZhbU6JmaVfKgD1s4cybkcHTBk+tY6By/eFQji3AClKY=; b=vAnrh/vz7SDqnBkJ16Ui7SnVzTOXis6qdT+fOA1CGVTausT9g63eFLLz5YZRkup+Yv 9oQpQZmOuRDbIoVdeGyDpDqp3NVuzykCqwSdI/KLXXn4pLShedW5GJ+Nmhxc4RvbOo4u w16PMz2pSSxATKl8tkJs49qGKp5qhPTll8qVzRKRRtNvaOvtf8j64h/4bn8QbKS2dW52 wTqzqZ3RHvpg5aP3KazZ86uBG7AxMY/KPzJ4mkPtetUJQgiVE+5usD1oQL2pnpcE71sp AS5NyIp6KV1xOQSFk5sa01xXfQ8ROrJbopEcSVNfHJ7RQHxxohGg+YFInlcaLvzIWMys f1qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b="j1ZHC/Pl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o2si1628906eda.463.2020.10.07.08.24.49; Wed, 07 Oct 2020 08:25:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b="j1ZHC/Pl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727422AbgJGIIR (ORCPT + 99 others); Wed, 7 Oct 2020 04:08:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726096AbgJGIIM (ORCPT ); Wed, 7 Oct 2020 04:08:12 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B062BC0613D3 for ; Wed, 7 Oct 2020 01:08:10 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id i5so1202074edr.5 for ; Wed, 07 Oct 2020 01:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZhbU6JmaVfKgD1s4cybkcHTBk+tY6By/eFQji3AClKY=; b=j1ZHC/Plvx7SgnRFbucisI2F2GM2pxPOw0vRjiREHyMPuFtNMjkipgmBzOHJa/VcAi FJqJ7PJrOdaLjZnGcPG8L2qFMIp16S/A+06M+a5G+WQtwkIKheWGILG89/UVb7V298tf Nzj4aDM7+puXmcfD2kVkm90kdtH8z3HuE34USZLscGcU5WH+wzCfrnSiy5Z7CO9aTqgU NLca3DEDaNIqyGlboBbdI6tOT31AbHnwtuA1Ub+mYRtY3sLUMub7XvCfmvX0yXHeP4s0 QmE6pVN0y2nDyVSAKQy8sLD6Q6giiQy9lu8IbqlrTRql76vwYnvcfQSJ1McPiTlEJnLX amPw== 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:mime-version:content-transfer-encoding; bh=ZhbU6JmaVfKgD1s4cybkcHTBk+tY6By/eFQji3AClKY=; b=bu2QD4XMtqR7jPBsJ44Mjkbb03xU0tDDvFsrV8pv8o/YVQxnU5eLXErzdxdbF8H4Z5 CzE8qX0hEUIkeQSqso683iadxHCr4RSrXlYxUOBQUcHXH0zzQOpQpYFc1177MBSCjgTt fsh/D82I6+olFwtRURpH8/96FfVSHA7XIViEbWEAbwvBo4QekmBaZ5VZ9KCcOcA9ph6U pVDlMwnS93/85auRthB3M81HwRsKKbB5arZLietPYjQdee+zQZ2VPhgf6rBRspNx+sfM zwU/KkQNJawtM4x6B4pyPDjqrbjRbQQtHcNsP5QTpHg/r1cHWMhQkfT3lKlUClgoBoOq 4Xmw== X-Gm-Message-State: AOAM533/RmasqVzY+MCjYN+gyCXNjN0tUkOuwjz/AiXoXuLM0n2EOW71 s0Mrsa9zG3xo9BOX+mlpix/Blg== X-Received: by 2002:a50:c309:: with SMTP id a9mr2285070edb.199.1602058089334; Wed, 07 Oct 2020 01:08:09 -0700 (PDT) Received: from starbuck.lan (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id p11sm888645edu.93.2020.10.07.01.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 01:08:08 -0700 (PDT) From: Jerome Brunet To: Wolfram Sang , Kevin Hilman Cc: Jerome Brunet , Nicolas Belin , linux-i2c@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] i2c: meson: fix clock setting overwrite Date: Wed, 7 Oct 2020 10:07:49 +0200 Message-Id: <20201007080751.1259442-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201007080751.1259442-1-jbrunet@baylibre.com> References: <20201007080751.1259442-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the slave address is written in do_start(), SLAVE_ADDR is written completely. This may overwrite some setting related to the clock rate or signal filtering. Fix this by writing only the bits related to slave address. To avoid causing unexpected changed, explicitly disable filtering or high/low clock mode which may have been left over by the bootloader. Fixes: 30021e3707a7 ("i2c: add support for Amlogic Meson I2C controller") Signed-off-by: Jerome Brunet --- drivers/i2c/busses/i2c-meson.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-meson.c b/drivers/i2c/busses/i2c-meson.c index c5dec572fc48..dac0d2a00cec 100644 --- a/drivers/i2c/busses/i2c-meson.c +++ b/drivers/i2c/busses/i2c-meson.c @@ -5,6 +5,7 @@ * Copyright (C) 2014 Beniamino Galvani */ +#include #include #include #include @@ -38,6 +39,12 @@ #define REG_CTRL_CLKDIVEXT_SHIFT 28 #define REG_CTRL_CLKDIVEXT_MASK GENMASK(29, 28) +#define REG_SLV_ADDR GENMASK(7, 0) +#define REG_SLV_SDA_FILTER GENMASK(10, 8) +#define REG_SLV_SCL_FILTER GENMASK(13, 11) +#define REG_SLV_SCL_LOW GENMASK(27, 16) +#define REG_SLV_SCL_LOW_EN BIT(28) + #define I2C_TIMEOUT_MS 500 enum { @@ -147,6 +154,9 @@ static void meson_i2c_set_clk_div(struct meson_i2c *i2c, unsigned int freq) meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIVEXT_MASK, (div >> 10) << REG_CTRL_CLKDIVEXT_SHIFT); + /* Disable HIGH/LOW mode */ + meson_i2c_set_mask(i2c, REG_SLAVE_ADDR, REG_SLV_SCL_LOW_EN, 0); + dev_dbg(i2c->dev, "%s: clk %lu, freq %u, div %u\n", __func__, clk_rate, freq, div); } @@ -280,7 +290,10 @@ static void meson_i2c_do_start(struct meson_i2c *i2c, struct i2c_msg *msg) token = (msg->flags & I2C_M_RD) ? TOKEN_SLAVE_ADDR_READ : TOKEN_SLAVE_ADDR_WRITE; - writel(msg->addr << 1, i2c->regs + REG_SLAVE_ADDR); + + meson_i2c_set_mask(i2c, REG_SLAVE_ADDR, REG_SLV_ADDR, + FIELD_PREP(REG_SLV_ADDR, msg->addr << 1)); + meson_i2c_add_token(i2c, TOKEN_START); meson_i2c_add_token(i2c, token); } @@ -461,6 +474,10 @@ static int meson_i2c_probe(struct platform_device *pdev) return ret; } + /* Disable filtering */ + meson_i2c_set_mask(i2c, REG_SLAVE_ADDR, + REG_SLV_SDA_FILTER | REG_SLV_SCL_FILTER, 0); + meson_i2c_set_clk_div(i2c, timings.bus_freq_hz); return 0; -- 2.25.4