Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp329010pxu; Wed, 14 Oct 2020 02:24:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfm1M6rGXd/yqf4DkeWvvocmR8ABb9RjxoNNfYqX+xdong38s4GwqeBA9ZyyNJ9PAaI2Gl X-Received: by 2002:a17:906:b1a:: with SMTP id u26mr4264067ejg.23.1602667455433; Wed, 14 Oct 2020 02:24:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602667455; cv=none; d=google.com; s=arc-20160816; b=Noxzcr8Lf3AT1b1mf2FvhCk2q9mKOcrizX0uZhXL4xB31fgzbg8VM7I60kZuzdAOlO H5hkMO0eKKaETZ9J8OZNlv9wMJIZb4QCkjBorMn1f3XBHtf/dZGidaQIqczH51K8zk1v mpFsx3sSWdvcqVxppg1PMLrmMC0XGSz1qaULWGqYF/kh6+C18ZwiEEKmdXe5AOYw+L5b EsONkYvNU2Ru6MccZtk13aDhSvHhIz38ym18FK/BL5uiGNO6PCi4UA6XczFeOfsrT5Xk +X1N2GDYDl125G543hH/ZMA6j6JT//gC/W63l7B2sTgEmEEmDlMLP9cxMbQ4n/foJKi8 3KMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=74gtbcSoQxBU/Zm+4MVD4nGSWX1uGiDbcEQFSH2Vxhw=; b=Hkq8EX+CmWs+Xfpii0PP/mGwmjIe/1Bclw64FDCzuDKfYBSt/WZe2ATO7Wtn0bsvVX FH7GsFpBTQ8VOB3PcbBhdhkjnelD293hmyvHfXyijVk9baJFAqTmipQRAcXGc6EG88yb AO0AalMNJeoGQqz4Qgz4ikEqZZOAUbX84vOLMi1kXBf4XKjKCqKEgHqo9zbGYw2Jo373 1AQM6i/oHlkssRMlZ58FJA0fRjoKKHyILN3PjWvEUoDOr4GYXpRKOXASeqD4AFCvyH32 othv6KsDjk9E7iK4NkPeNEvtOQrKD4sT+4/xIguzBZA7nfPOO1qjJnZUwuVCLRGYHCqv pvEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jms.id.au header.s=google header.b=W1bbLqtM; 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 cm10si1799562edb.559.2020.10.14.02.23.52; Wed, 14 Oct 2020 02:24:15 -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=@jms.id.au header.s=google header.b=W1bbLqtM; 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 S1729080AbgJNJJm (ORCPT + 99 others); Wed, 14 Oct 2020 05:09:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728264AbgJNJJh (ORCPT ); Wed, 14 Oct 2020 05:09:37 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 304A6C04585E; Tue, 13 Oct 2020 22:30:54 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id m65so1494768qte.11; Tue, 13 Oct 2020 22:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jms.id.au; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=74gtbcSoQxBU/Zm+4MVD4nGSWX1uGiDbcEQFSH2Vxhw=; b=W1bbLqtMmSL+ANSOQe8P5DwLGGiKKtcj7T8ijYHZ+Cjn35VQJt1HwpuWShCRVQQHDr IZc1oYF2nVGSp8zrVWaPHXXaqWNiWZROH7EvKmO4qSK7YfIWL8MGSNpN86/pjw/F1+Sx Pbt1X2n0rA5hwuFs4X3TC/ar8/JQa4xo5EWLM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=74gtbcSoQxBU/Zm+4MVD4nGSWX1uGiDbcEQFSH2Vxhw=; b=rKlQPEZBzdovP6Cpv6L+ZyTbYWjvhTpfSWVNhKWuYPxnYby0kZBPm2Rqhbht7/zgt2 Ie2AgbrkLGnphq0zoHYOBJN4pW6LQo3SMZLWuE0D1rkHKsS2asoDmel5qZB2VM1iXRvz XOt7guPi49wPkoyumYjtDgJtlPqkcyLUpGl1+kv8+qDbyv9w2KXoRCsHZeMGzJt8E6vr t2F620jOVl8y0iM3YxQVMcwAFMrbOmv0tpXavSXqdMEST1eO5ngfJ4dC+OzKzUItDdaL huokNguTW1bA0XaDlpsCQbxPLYSdIY2PZmZiYSY8B60jRn5waCo0uqlrTPlxm26WW+w8 0f4Q== X-Gm-Message-State: AOAM533YwofzzJ7L3ZfSrLaLHeFIQrviiZ1Udg96zHu14VCzxDw9RfR1 JpIyM08siwsHZhspNxFSAO7k3EzlWeGFQhOe7DM= X-Received: by 2002:ac8:5b82:: with SMTP id a2mr3268208qta.176.1602653453244; Tue, 13 Oct 2020 22:30:53 -0700 (PDT) MIME-Version: 1.0 References: <20201013100314.216154-1-tali.perry1@gmail.com> In-Reply-To: <20201013100314.216154-1-tali.perry1@gmail.com> From: Joel Stanley Date: Wed, 14 Oct 2020 05:30:41 +0000 Message-ID: Subject: Re: [PATCH v2] i2c: npcm7xx: Support changing bus speed using debugfs. To: Tali Perry Cc: wsa@kernel.org, andriy.shevchenko@linux.intel.com, xqiu@google.com, Kun Yi , Benjamin Fair , Avi Fishman , Tomer Maimon , linux-i2c@vger.kernel.org, OpenBMC Maillist , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 13 Oct 2020 at 10:03, Tali Perry wrote: > > Systems that can dynamically add and remove slave devices > often need to change the bus speed in runtime. > This patch expose the bus frequency to the user. > This feature can also be used for test automation. > > -- > v2 -> v1: > - Fix typos. > - Remove casting to u64. > > v1: initial version > > Fixes: 56a1485b102e (i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver) > Signed-off-by: Tali Perry Reviewed-by: Joel Stanley I'm not sure that the Fixes tag is quite correct, but it's no biggie. > --- > drivers/i2c/busses/i2c-npcm7xx.c | 35 ++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c > index 2ad166355ec9..633ac67153e2 100644 > --- a/drivers/i2c/busses/i2c-npcm7xx.c > +++ b/drivers/i2c/busses/i2c-npcm7xx.c > @@ -2208,6 +2208,40 @@ static const struct i2c_algorithm npcm_i2c_algo = { > /* i2c debugfs directory: used to keep health monitor of i2c devices */ > static struct dentry *npcm_i2c_debugfs_dir; > > +static int i2c_speed_get(void *data, u64 *val) > +{ > + struct npcm_i2c *bus = data; > + > + *val = bus->bus_freq; > + return 0; > +} > + > +static int i2c_speed_set(void *data, u64 val) > +{ > + struct npcm_i2c *bus = data; > + int ret; > + > + if (val < I2C_FREQ_MIN_HZ || val > I2C_FREQ_MAX_HZ) > + return -EINVAL; > + > + if (val == bus->bus_freq) > + return 0; > + > + i2c_lock_bus(&bus->adap, I2C_LOCK_ROOT_ADAPTER); > + > + npcm_i2c_int_enable(bus, false); > + > + ret = npcm_i2c_init_module(bus, I2C_MASTER, (u32)val); > + > + i2c_unlock_bus(&bus->adap, I2C_LOCK_ROOT_ADAPTER); > + > + if (ret) > + return -EAGAIN; > + > + return 0; > +} > +DEFINE_DEBUGFS_ATTRIBUTE(i2c_clock_ops, i2c_speed_get, i2c_speed_set, "%llu\n"); > + > static void npcm_i2c_init_debugfs(struct platform_device *pdev, > struct npcm_i2c *bus) > { > @@ -2223,6 +2257,7 @@ static void npcm_i2c_init_debugfs(struct platform_device *pdev, > debugfs_create_u64("rec_succ_cnt", 0444, d, &bus->rec_succ_cnt); > debugfs_create_u64("rec_fail_cnt", 0444, d, &bus->rec_fail_cnt); > debugfs_create_u64("timeout_cnt", 0444, d, &bus->timeout_cnt); > + debugfs_create_file("i2c_speed", 0644, d, bus, &i2c_clock_ops); > > bus->debugfs = d; > } > > base-commit: 865c50e1d279671728c2936cb7680eb89355eeea > -- > 2.22.0 >