Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4691613pxu; Tue, 13 Oct 2020 05:04:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycpsuQYav9tDuIQ2enIh2Er6vb59CGwjoWXLqI4dbmbbc7FbPXGFZQMKwJ77sJLveVqqO5 X-Received: by 2002:a17:906:1a11:: with SMTP id i17mr32257502ejf.381.1602590673675; Tue, 13 Oct 2020 05:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602590673; cv=none; d=google.com; s=arc-20160816; b=UPX80RRq750Vd3I3uAkHSKNOH7LE9YYBRM4BiYpFa0FEvkTCv+kRu9cDsC3rWqYcvd 1dXqnMQNOAux9qSKPgkNwaELyDTYj+NZ4MwMssX4UHZn8sypgMWCXpU25Tl0JLHv4/nL zbOXO3ZCM9vBj0c46mTQ6C5QevFjwev0l1JPqfrtUBnm3xnN9FQPweBhGWodeptjTzPK qu8SM5nrIDR7mBN6VK+Cq0ISLVCb1PD0Qq6gfSH4lTfppfgVVHT8sFooBevVrTWhCRjD ISSh1Hk3X42cs3zRs1dsC68BGeh9MFe8x2tDiOrIbH9FrGY9dqD/OgKpCyg87f7AaMjl gZQg== 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 :message-id:date:subject:cc:to:from; bh=JAjgcpFX3BxBQuUjnaqvKbe0K2HchjCFPhg2I2rbxVU=; b=0auZ0j+ERcrSjwY1ShL3fFkP1HEGEWzLn3aSk74JbAoAvKUNTVN88jWUX1vSrqxlZT 5sF9iYJ8ARknH0meX0G5FLlTiDUauqvNwnqyuDfPVsbqvyFlVr+8IXHNHfsgCC0ryRQK lPv8rkdwRWw5XBBxKJChFB+ZkoodC9rTskkTHhJRT3FmUwmN0f1prsjk0fvWD3SFNKzv 9PPGuJ1TNhWqSGOyfTMGY5M7T8M11l9Wz6M5nn2T1XUVDjSGa7u+QbkdUFdH9Wx46QBE YRz+0IzbumdR+ozZ97hbhsvlbdSmsQpY+BTXt3nyuu1JDSODbQGQmyBKDplsuThLJFFI 0lWw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n24si8882446eda.579.2020.10.13.05.04.10; Tue, 13 Oct 2020 05:04:33 -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; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727444AbgJMKFd (ORCPT + 99 others); Tue, 13 Oct 2020 06:05:33 -0400 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:57528 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726495AbgJMKFd (ORCPT ); Tue, 13 Oct 2020 06:05:33 -0400 Received: from taln60.nuvoton.co.il (ntil-fw [212.199.177.25]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 09DA3P1A022735; Tue, 13 Oct 2020 13:03:25 +0300 Received: by taln60.nuvoton.co.il (Postfix, from userid 20088) id 533D8639D6; Tue, 13 Oct 2020 13:03:25 +0300 (IDT) From: Tali Perry To: wsa@kernel.org, andriy.shevchenko@linux.intel.com, xqiu@google.com, kunyi@google.com, benjaminfair@google.com, avifishman70@gmail.com, joel@jms.id.au, tmaimon77@gmail.com Cc: linux-i2c@vger.kernel.org, openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Tali Perry Subject: [PATCH v2] i2c: npcm7xx: Support changing bus speed using debugfs. Date: Tue, 13 Oct 2020 13:03:14 +0300 Message-Id: <20201013100314.216154-1-tali.perry1@gmail.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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