From patchwork Thu Dec 19 22:55:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13915925 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B02D61D2B2A for ; Thu, 19 Dec 2024 22:55:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734648954; cv=none; b=kEsTWtOvvr9n5Xls1ZN5C73dxEdp9jj2vr/5E/UWHe2+5JPid78mUhMh7OraZdnarNaFTUkzLz9ULnSUwtnTX91otIVE7m7NmAWjmpGAPI7o2o+9Kd9SYFLkq9fO2wfHyhb84ugvOBbZlrdZ/HtCD2KXR6u3ydRSnciASHXrcwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734648954; c=relaxed/simple; bh=fRaBiCoerYtSXXFqhmhM8BO1GEchg6Xp0E+QB3DJQ7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AViTQjqq0/EvPmwoFO4w0+jo6FWB2MYmJdk69JcIrkn+OfkDPcupjc8RjYBKzfN/uAFlJBmpK1Klg6BsrWU4JFN3ACFLzF8sDqvrXXVseL6oVTgVvJ1OD3uRjTKB2lH2Pj8pI5sNMdkq+1N4y65lGg9tMjI3v9gclZ6ks7yvXk8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=MgBBkrgO; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="MgBBkrgO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=PltsfRgtPshB11QnLxkk5tBvWzyj5OepdzLg0lgkrMg=; b=MgBBkr gOafqD55q41NXV3mUTZ2ktb7zze4pdzooD21gDjZ2i70dsPq/AWa6RDrHy6rFLEj T23rchTdUAzXNpQg4lFVPlzpuSyc5G5HbuMW+Vi7G/7FNCds1NrIkk6u9+oajBqh T70wRmJvkAVf71G/G2EExzC/mP1Ykv/xyHsWyLYlydDr0jO598tBJN1PukT/QaVj 8FRHUowzH//pAn5On1LtSiZl0dS8B7jm7ua24tful/qd7LkOfVps/G06U+QgSVKC cL2+02qMmriS+5Lkllc0gLpoZw1noRTu51DwqKiTjLmC0cFT2Vi2JAHbGvDwPM2R r4F+OG2pQWqxbEDw== Received: (qmail 826593 invoked from network); 19 Dec 2024 23:55:48 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 19 Dec 2024 23:55:48 +0100 X-UD-Smtp-Session: l3s3148p1@X1Rhbqcp+KgujnsY From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Wolfram Sang , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [RFC PATCH 1/5] hwmon: (lm75) simplify lm75_write_config() Date: Thu, 19 Dec 2024 23:55:23 +0100 Message-ID: <20241219225522.3490-8-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241219225522.3490-7-wsa+renesas@sang-engineering.com> References: <20241219225522.3490-7-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 After previous refactoring, it is now possible to make lm75_write_config() a simple inline function. Signed-off-by: Wolfram Sang Reviewed-by: Geert Uytterhoeven --- drivers/hwmon/lm75.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index b8889392d5da..b03e760cf3a1 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -340,17 +340,11 @@ static inline long lm75_reg_to_mc(s16 temp, u8 resolution) return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8); } -static int lm75_write_config(struct lm75_data *data, u16 set_mask, - u16 clr_mask) +static inline int lm75_write_config(struct lm75_data *data, u16 set_mask, + u16 clr_mask) { - int err; - - err = regmap_update_bits(data->regmap, LM75_REG_CONF, - clr_mask | LM75_SHUTDOWN, set_mask); - if (err) - return err; - - return 0; + return regmap_update_bits(data->regmap, LM75_REG_CONF, + clr_mask | LM75_SHUTDOWN, set_mask); } static irqreturn_t lm75_alarm_handler(int irq, void *private) From patchwork Thu Dec 19 22:55:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13915924 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68E731D79B1 for ; Thu, 19 Dec 2024 22:55:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734648953; cv=none; b=He6kBIHBu39s0PsoxfdjthvRhvXlOnI5xP5oBkvciKi0qbUtQINVgss+gCwfd1TzAkOPKC3Tb9sOuHZCWdipG0Ky6fdTfto2zmglm5FAIrI4Vf7TeRrPFc9IJ2Tmiivp3o3wvlnbODmy8mt2AcXMBHAiMzTYAf61ujIbEG4jW78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734648953; c=relaxed/simple; bh=gyI/pmtnVSGA6mAS+7tY1CpMr4yyGYniXxBfcG831+4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QyTyoWe52IClCkw3jXhsnrJVYQOckFULQQwOnfvLF49NZoQ8SIVa2KubA4o66k9GPduaw4cEIegLuMp3CCsQ98riF/GdTWFXdYMEcGGxKztvSgogvWusWTZK6PSwZZykkkdk6lCkeDtZDJwoH9SIzXHcf3NB17CpSdX66D/a+wM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=geuvYBIy; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="geuvYBIy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=EFtXOkS8o7zBjJldP7Zsy3cjh6NMxH47TTmDvMf8sZ4=; b=geuvYB Iy/n9pgK9qbjoIO+OM3kLFH+Kba0C0W7cmoMJWmx7THp2DBC2XfRfZhjqS/U9k6I IjaX86AToVN7GGWPHfTDIgs51ZmFRTwYMWatbES9SCHkN4GBrhmP24fRrvknVoEI bJlGf4PpUa1z1+Sy1jGlrVUYcux9rbs9FfP8ZElnZBbIt5dLJGitUmha8p+kmvdK 9ESQyDpiZnP/jvBsKre0z/64SCMQ/sSFV9aRRwb4a3LP7SOmcfNgD48Kqdbg3wbQ s+vtuCrLSxfxEnv3pKoEa+KRq94A0w0gGfZwRNQf+ITZSqaEahtYMXaTzO+t6Xik vim0HGR82PtvDwkA== Received: (qmail 826623 invoked from network); 19 Dec 2024 23:55:49 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 19 Dec 2024 23:55:49 +0100 X-UD-Smtp-Session: l3s3148p1@2cpubqcpBKkujnsY From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Wolfram Sang , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [RFC PATCH 2/5] hwmon: (lm75) simplify regulator handling Date: Thu, 19 Dec 2024 23:55:24 +0100 Message-ID: <20241219225522.3490-9-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241219225522.3490-7-wsa+renesas@sang-engineering.com> References: <20241219225522.3490-7-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 devm_regulator_get_enable() was introduced exactly to avoid open coding regulator handling like in this driver. Make use of this helper. Signed-off-by: Wolfram Sang Reviewed-by: Geert Uytterhoeven --- drivers/hwmon/lm75.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index b03e760cf3a1..4d0fd1c93c63 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -109,7 +109,6 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, struct lm75_data { struct i2c_client *client; struct regmap *regmap; - struct regulator *vs; u16 orig_conf; u8 resolution; /* In bits, 9 to 16 */ unsigned int sample_time; /* In ms */ @@ -621,13 +620,6 @@ static const struct regmap_bus lm75_i2c_regmap_bus = { .reg_write = lm75_i2c_reg_write, }; -static void lm75_disable_regulator(void *data) -{ - struct lm75_data *lm75 = data; - - regulator_disable(lm75->vs); -} - static void lm75_remove(void *data) { struct lm75_data *lm75 = data; @@ -656,9 +648,9 @@ static int lm75_probe(struct i2c_client *client) data->client = client; data->kind = (uintptr_t)i2c_get_match_data(client); - data->vs = devm_regulator_get(dev, "vs"); - if (IS_ERR(data->vs)) - return PTR_ERR(data->vs); + err = devm_regulator_get_enable(dev, "vs"); + if (err) + return err; data->regmap = devm_regmap_init(dev, &lm75_i2c_regmap_bus, data, &lm75_regmap_config); @@ -675,17 +667,6 @@ static int lm75_probe(struct i2c_client *client) data->sample_time = data->params->default_sample_time; data->resolution = data->params->default_resolution; - /* Enable the power */ - err = regulator_enable(data->vs); - if (err) { - dev_err(dev, "failed to enable regulator: %d\n", err); - return err; - } - - err = devm_add_action_or_reset(dev, lm75_disable_regulator, data); - if (err) - return err; - /* Cache original configuration */ err = regmap_read(data->regmap, LM75_REG_CONF, &status); if (err) From patchwork Thu Dec 19 22:55:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13915926 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C3731D8DF6 for ; Thu, 19 Dec 2024 22:55:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734648954; cv=none; b=oc9bJNbPz/IrlTd+8OX9QmL5rnWj5k2aLcvuLn5p3C6QY496QccxiII56R/Om21UaPAhW5cBpRKk48xw2vYbcoJ0HPTdcMxe2G57Iv70v/OelEcG3NJZCvAxhsv2QEg/L3hZRjrR4csudaNvEDif9/b+Jf4NVNPBOl9oLJf0S6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734648954; c=relaxed/simple; bh=Fn5Wn6TSgYD9f2tYs5wv0YsHVPJJxLKIv+f0K2Swvwg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bmJf6Qiiy12r1wzx0wrBQXHejmFnC7Qf/BWqCmYf8oKR+cewfsZSI8ZWRXA7S8KPAebyXczkOC0NEI/Sv89j6qU2t0+KXt+0Udjm98G3DyKEg45BCL+Imhw+cJTtgc6b9Lw3s8jTs2PQMegJtaeQA3JIog+sk/aU+iUGgadPs18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=K+whlpQc; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="K+whlpQc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=mQOUXsZbTYfWBSw0R4gk48zwein1ueWIbvR9w4WLCqM=; b=K+whlp QcsPfrz+NfY0Yf6fybzkinsoXfU777+xPKBS98M8ZFTDOPNUBuZ9MZzqxiHVzNXK 9CL/gAlTV3Iwn3KLHa650cg3YJlgITzQfTaNIHaSj8ZzmoreC5uqTzKpkA32aF1g tBGzfz1vKoxqbiCi/ZibubjL0BZv9XQyLP5GLYsNMzOKKeWQpg1x5RCI7DjM3RKD rp4KcboZa08mJZuELhJ7SP1QwVtkaDhxZghFdkDbor+uthFcVXkMr+0lmVBbIdO0 Uv1r+gbObJkj4eK4a1JpvnQ45WNFyuZ8/1uQWZe8AT3N0wLy/YyFeijpoeZilgwf miAwrwaQnoP4b84g== Received: (qmail 826652 invoked from network); 19 Dec 2024 23:55:50 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 19 Dec 2024 23:55:50 +0100 X-UD-Smtp-Session: l3s3148p1@Y495bqcpFKkujnsY From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Wolfram Sang , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [RFC PATCH 3/5] hwmon: (lm75) Remove superfluous 'client' member from private struct Date: Thu, 19 Dec 2024 23:55:25 +0100 Message-ID: <20241219225522.3490-10-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241219225522.3490-7-wsa+renesas@sang-engineering.com> References: <20241219225522.3490-7-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The regmap-only conversion allows us to store the client-pointer as the 'context' parameter for regmap. This not only makes the private struct smaller, but also allows proper separation of I2C and I3C in the future. Signed-off-by: Wolfram Sang --- drivers/hwmon/lm75.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 4d0fd1c93c63..0f034110daed 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -105,9 +105,7 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, #define LM75_REG_MAX 0x03 #define PCT2075_REG_IDLE 0x04 -/* Each client has this additional data */ struct lm75_data { - struct i2c_client *client; struct regmap *regmap; u16 orig_conf; u8 resolution; /* In bits, 9 to 16 */ @@ -572,8 +570,8 @@ static bool lm75_is_volatile_reg(struct device *dev, unsigned int reg) static int lm75_i2c_reg_read(void *context, unsigned int reg, unsigned int *val) { - struct lm75_data *data = context; - struct i2c_client *client = data->client; + struct i2c_client *client = context; + struct lm75_data *data = i2c_get_clientdata(client); int ret; if (reg == LM75_REG_CONF) { @@ -592,8 +590,8 @@ static int lm75_i2c_reg_read(void *context, unsigned int reg, unsigned int *val) static int lm75_i2c_reg_write(void *context, unsigned int reg, unsigned int val) { - struct lm75_data *data = context; - struct i2c_client *client = data->client; + struct i2c_client *client = context; + struct lm75_data *data = i2c_get_clientdata(client); if (reg == PCT2075_REG_IDLE || (reg == LM75_REG_CONF && !data->params->config_reg_16bits)) @@ -645,14 +643,13 @@ static int lm75_probe(struct i2c_client *client) /* needed by custom regmap callbacks */ dev_set_drvdata(dev, data); - data->client = client; data->kind = (uintptr_t)i2c_get_match_data(client); err = devm_regulator_get_enable(dev, "vs"); if (err) return err; - data->regmap = devm_regmap_init(dev, &lm75_i2c_regmap_bus, data, + data->regmap = devm_regmap_init(dev, &lm75_i2c_regmap_bus, client, &lm75_regmap_config); if (IS_ERR(data->regmap)) return PTR_ERR(data->regmap); From patchwork Thu Dec 19 22:55:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13915927 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA82F1DC990 for ; Thu, 19 Dec 2024 22:55:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734648954; cv=none; b=btRPPMqIax+66ee0pms/AkezREiOAbcwGhlWimU0ai956Jl0M+PrKCapCfU5PgbVs7otWrLGMVT8VepFRvZ2xCUU1878NarME4cLzBdWQGhWh9RlW89hrcpZjsOREfs8yfNzq7aMmCNyIjCxx91a1FVTBCQJspBY7N/99HZQRjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734648954; c=relaxed/simple; bh=vQ/R9ilHEn5q3VaWJzwuPPXkm2APrJFlVGTIYlssav8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BAGlbCU3ONcem4H95GSxv0sM8FkkmlqafEZDKqvPZqoTBUYd6VAonwCnvOBCaJcoWZSWrXlLZKL+EDYnN8c1+v8bFKlOZYoDChJqqgqwKGoKXyIgJr5zWZIWV/8yUbTzlcOZusTth57WaRLG6KHI+bga/aC78OnRJVfV2Mkdhpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=fdGPzZsG; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="fdGPzZsG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=sbDui2BU847sp3+zqR27cxvNTAZScJEEylWUFLTO20Q=; b=fdGPzZ sGE7NrO7faTHHJK5g9Dt7vO/AaVJlZEFjYHyYYuJ5b10XSG2j2zPE3m/YzK4Gcp8 5JhQWt9Ipg4hdlqk5RKFuE+2/8ZdxXjhCh/PV1HCyhaJMjsdYqc0OJdIKvaxSWY+ x9TbhPiLzcS0Ugf4GspV3+bFClIp8iGl8OdGGh7IV+IqUT3r/Tu0dNYrSc397ZWw RAgf/d8581QiLrjANVaZYMP6wxGaDoxAStajk89rGvwPKAIVLPvbSfebjs9p/pOL 0b+JxND//JPMG69Cab/DQG2rXtyMEpMyn1qMFG7E2YlFxB8rL9cMAH7Co4MMKHXo /Y3PnnK1HYPh/90A== Received: (qmail 826681 invoked from network); 19 Dec 2024 23:55:51 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 19 Dec 2024 23:55:51 +0100 X-UD-Smtp-Session: l3s3148p1@tJuFbqcpIqkujnsY From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Wolfram Sang , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [RFC PATCH 4/5] hwmon: (lm75) separate probe into common and I2C parts Date: Thu, 19 Dec 2024 23:55:26 +0100 Message-ID: <20241219225522.3490-11-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241219225522.3490-7-wsa+renesas@sang-engineering.com> References: <20241219225522.3490-7-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Put generic probe functionality into a separate function and let the I2C driver call it. This is a preparation for adding I3C support which will also use the generic probe function. Signed-off-by: Wolfram Sang --- drivers/hwmon/lm75.c | 68 +++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 0f034110daed..8b4f324524da 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -601,6 +601,11 @@ static int lm75_i2c_reg_write(void *context, unsigned int reg, unsigned int val) return i2c_smbus_write_word_swapped(client, reg, val); } +static const struct regmap_bus lm75_i2c_regmap_bus = { + .reg_read = lm75_i2c_reg_read, + .reg_write = lm75_i2c_reg_write, +}; + static const struct regmap_config lm75_regmap_config = { .reg_bits = 8, .val_bits = 16, @@ -613,11 +618,6 @@ static const struct regmap_config lm75_regmap_config = { .use_single_write = true, }; -static const struct regmap_bus lm75_i2c_regmap_bus = { - .reg_read = lm75_i2c_reg_read, - .reg_write = lm75_i2c_reg_write, -}; - static void lm75_remove(void *data) { struct lm75_data *lm75 = data; @@ -625,17 +625,13 @@ static void lm75_remove(void *data) regmap_write(lm75->regmap, LM75_REG_CONF, lm75->orig_conf); } -static int lm75_probe(struct i2c_client *client) +static int lm75_generic_probe(struct device *dev, const char *name, + const void *kind_ptr, int irq, struct regmap *regmap) { - struct device *dev = &client->dev; struct device *hwmon_dev; struct lm75_data *data; int status, err; - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) - return -EIO; - data = devm_kzalloc(dev, sizeof(struct lm75_data), GFP_KERNEL); if (!data) return -ENOMEM; @@ -643,17 +639,13 @@ static int lm75_probe(struct i2c_client *client) /* needed by custom regmap callbacks */ dev_set_drvdata(dev, data); - data->kind = (uintptr_t)i2c_get_match_data(client); + data->kind = (uintptr_t)kind_ptr; + data->regmap = regmap; err = devm_regulator_get_enable(dev, "vs"); if (err) return err; - data->regmap = devm_regmap_init(dev, &lm75_i2c_regmap_bus, client, - &lm75_regmap_config); - if (IS_ERR(data->regmap)) - return PTR_ERR(data->regmap); - /* Set to LM75 resolution (9 bits, 1/2 degree C) and range. * Then tweak to be more precise when appropriate. */ @@ -679,20 +671,19 @@ static int lm75_probe(struct i2c_client *client) if (err) return err; - hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, - data, &lm75_chip_info, - NULL); + hwmon_dev = devm_hwmon_device_register_with_info(dev, name, data, + &lm75_chip_info, NULL); if (IS_ERR(hwmon_dev)) return PTR_ERR(hwmon_dev); - if (client->irq) { + if (irq) { if (data->params->alarm) { err = devm_request_threaded_irq(dev, - client->irq, + irq, NULL, &lm75_alarm_handler, IRQF_ONESHOT, - client->name, + name, hwmon_dev); if (err) return err; @@ -702,12 +693,29 @@ static int lm75_probe(struct i2c_client *client) } } - dev_info(dev, "%s: sensor '%s'\n", dev_name(hwmon_dev), client->name); + dev_info(dev, "%s: sensor '%s'\n", dev_name(hwmon_dev), name); return 0; } -static const struct i2c_device_id lm75_ids[] = { +static int lm75_i2c_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct regmap *regmap; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) + return -EOPNOTSUPP; + + regmap = devm_regmap_init(dev, &lm75_i2c_regmap_bus, client, &lm75_regmap_config); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + return lm75_generic_probe(dev, client->name, i2c_get_match_data(client), + client->irq, regmap); +} + +static const struct i2c_device_id lm75_i2c_ids[] = { { "adt75", adt75, }, { "as6200", as6200, }, { "at30ts74", at30ts74, }, @@ -740,7 +748,7 @@ static const struct i2c_device_id lm75_ids[] = { { "tmp1075", tmp1075, }, { /* LIST END */ } }; -MODULE_DEVICE_TABLE(i2c, lm75_ids); +MODULE_DEVICE_TABLE(i2c, lm75_i2c_ids); static const struct of_device_id __maybe_unused lm75_of_match[] = { { @@ -987,20 +995,20 @@ static const struct dev_pm_ops lm75_dev_pm_ops = { #define LM75_DEV_PM_OPS NULL #endif /* CONFIG_PM */ -static struct i2c_driver lm75_driver = { +static struct i2c_driver lm75_i2c_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = "lm75", .of_match_table = of_match_ptr(lm75_of_match), .pm = LM75_DEV_PM_OPS, }, - .probe = lm75_probe, - .id_table = lm75_ids, + .probe = lm75_i2c_probe, + .id_table = lm75_i2c_ids, .detect = lm75_detect, .address_list = normal_i2c, }; -module_i2c_driver(lm75_driver); +module_i2c_driver(lm75_i2c_driver); MODULE_AUTHOR("Frodo Looijaard "); MODULE_DESCRIPTION("LM75 driver"); From patchwork Thu Dec 19 22:55:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13915928 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAD6D1D79B1 for ; Thu, 19 Dec 2024 22:55:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734648956; cv=none; b=fFhRELTgFD94xCoyZShW991h/2X5wYMXcVlmY2SMHmMvmpBn+74h/T3G0ago3gC0FnO8B5SM0PW5f4yOnOFiC50vKHgtU1VIyI/5bEaBW6VEVpEO2N9HcFEg6IlrUCUsaN5GJSTMUuTBE1OKvDpPCCJA7+o3/QIw01Ojos9ZhvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734648956; c=relaxed/simple; bh=IYutn8QVXUq1NW9w+oqTmRp9Vvw03U0/CgCCOfRgy4k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O1qrSYQd1eVOiS+RINyibsA8e26T8n0WgFsPb6MyXDWgO3uHVTHrt2z/Bb+UZ/h2Jdrdw8ixCVv+g36j0t3cZPOF8KT5zBXDTMcHSupSX13f884dLOYzhhIJ6Pq+ZlEvY2Wj704lnT9Qg6W+RMbOWY2tGa2u+At0Mw+5/3TRoXY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=hT2p9NjT; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="hT2p9NjT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=cCevjPCP/5BMXHpNkBn3G/0jFCQhE2W4vuag2CSBZ0Q=; b=hT2p9N jT4jjeoZfhuLYDU+al4pNn4PY99Qk2R4/7tkrTt5eW5ZqcK4vHHburwF5eyk1AdK KLkx/HCikMGoPL1v96JteC0FzVuCpkZLPwCSmGjs4mwtFVLjGyQePmuEtDDwtd9q fZWh9ZPw+KSls3CJ0PCqg61OrWi53XYLXq7sfJUcU1wFO3robZgIvLPaUqzDu1/z S/1cUTUG6piu9v6TfCrCWbBqgOJbTCJP1QvmznnCYRlonTSFzYKvKWUQIbmDZnZg fym7/8uhpznYrh/hZTISJuCBcWrpj9thVkToAKeE2wA0JUkW8CUmmGZmKj6+HJ9N 94+za9fv+3bD7l1Q== Received: (qmail 826711 invoked from network); 19 Dec 2024 23:55:51 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 19 Dec 2024 23:55:51 +0100 X-UD-Smtp-Session: l3s3148p1@7fOSbqcpKKkujnsY From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Wolfram Sang , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [RFC PATCH 5/5] hwmon: (lm75) add I3C support for P3T1755 Date: Thu, 19 Dec 2024 23:55:27 +0100 Message-ID: <20241219225522.3490-12-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241219225522.3490-7-wsa+renesas@sang-engineering.com> References: <20241219225522.3490-7-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce I3C support by defining I3C accessors for regmap and implementing an I3C driver. Enable I3C for the NXP P3T1755. Signed-off-by: Wolfram Sang Tested-by: to my patch, I'll queue it all up (except for this patch) --- Two things I would like to discuss: - Shall we reuse i2c_device_id's to get a proper name for the chip? Looks strange, but adding all the info again for I3C looks strange as well - are there some suitable kernel helpers for dealing with big/little endianess in lm75_i3c_regmap_bus? Note: I also tried to use the non-*_reg callbacks for the regmap bus. But the constified void-pointers make it ugly as we need to change buffers because some registers are big endian and some little endian. drivers/hwmon/Kconfig | 2 + drivers/hwmon/lm75.c | 114 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index dd376602f3f1..86897b4d105f 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1412,7 +1412,9 @@ config SENSORS_LM73 config SENSORS_LM75 tristate "National Semiconductor LM75 and compatibles" depends on I2C + depends on I3C || !I3C select REGMAP_I2C + select REGMAP_I3C if I3C help If you say yes here you get support for one common type of temperature sensor chip, with models including: diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 8b4f324524da..2979f1746585 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -112,6 +113,8 @@ struct lm75_data { unsigned int sample_time; /* In ms */ enum lm75_type kind; const struct lm75_params *params; + u8 reg_buf[1]; + u8 val_buf[3]; }; /*-----------------------------------------------------------------------*/ @@ -606,6 +609,77 @@ static const struct regmap_bus lm75_i2c_regmap_bus = { .reg_write = lm75_i2c_reg_write, }; +static int lm75_i3c_reg_read(void *context, unsigned int reg, unsigned int *val) +{ + struct i3c_device *i3cdev = context; + struct lm75_data *data = i3cdev_get_drvdata(i3cdev); + struct i3c_priv_xfer xfers[] = { + { + .rnw = false, + .len = 1, + .data.out = data->reg_buf, + }, + { + .rnw = true, + .len = 2, + .data.out = data->val_buf, + }, + }; + int ret; + + data->reg_buf[0] = reg; + + if (reg == LM75_REG_CONF && !data->params->config_reg_16bits) + xfers[1].len--; + + ret = i3c_device_do_priv_xfers(i3cdev, xfers, 2); + if (ret < 0) + return ret; + + if (reg == LM75_REG_CONF && !data->params->config_reg_16bits) + *val = data->val_buf[0]; + else if (reg == LM75_REG_CONF) + *val = data->val_buf[0] | (data->val_buf[1] << 8); + else + *val = data->val_buf[1] | (data->val_buf[0] << 8); + + return 0; +} + +static int lm75_i3c_reg_write(void *context, unsigned int reg, unsigned int val) +{ + struct i3c_device *i3cdev = context; + struct lm75_data *data = i3cdev_get_drvdata(i3cdev); + struct i3c_priv_xfer xfers[] = { + { + .rnw = false, + .len = 3, + .data.out = data->val_buf, + }, + }; + + data->val_buf[0] = reg; + + if (reg == PCT2075_REG_IDLE || + (reg == LM75_REG_CONF && !data->params->config_reg_16bits)) { + xfers[0].len--; + data->val_buf[1] = val & 0xff; + } else if (reg == LM75_REG_CONF) { + data->val_buf[1] = val & 0xff; + data->val_buf[2] = (val >> 8) & 0xff; + } else { + data->val_buf[2] = val & 0xff; + data->val_buf[1] = (val >> 8) & 0xff; + } + + return i3c_device_do_priv_xfers(i3cdev, xfers, 1); +} + +static const struct regmap_bus lm75_i3c_regmap_bus = { + .reg_read = lm75_i3c_reg_read, + .reg_write = lm75_i3c_reg_write, +}; + static const struct regmap_config lm75_regmap_config = { .reg_bits = 8, .val_bits = 16, @@ -750,6 +824,36 @@ static const struct i2c_device_id lm75_i2c_ids[] = { }; MODULE_DEVICE_TABLE(i2c, lm75_i2c_ids); +static const struct i3c_device_id lm75_i3c_ids[] = { + I3C_DEVICE(0x011b, 0x152a, (void *)p3t1755), + { /* LIST END */ } +}; +MODULE_DEVICE_TABLE(i3c, lm75_i3c_ids); + +static int lm75_i3c_probe(struct i3c_device *i3cdev) +{ + struct device *dev = i3cdev_to_dev(i3cdev); + const struct i3c_device_id *id; + struct regmap *regmap; + const char *name; + unsigned int i; + + regmap = devm_regmap_init(dev, &lm75_i3c_regmap_bus, i3cdev, &lm75_regmap_config); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + id = i3c_device_match_id(i3cdev, lm75_i3c_ids); + + /* Reuse i2c_device_ids is OK? Or do we want a third copy of this data in lm75_i3c_ids? */ + for (i = 0; lm75_i2c_ids[i].name[0]; i++) + if ((kernel_ulong_t)id->data == lm75_i2c_ids[i].driver_data) + break; + + name = lm75_i2c_ids[i].name[0] ? lm75_i2c_ids[i].name : "lm75compatible"; + + return lm75_generic_probe(dev, name, id->data, 0, regmap); +} + static const struct of_device_id __maybe_unused lm75_of_match[] = { { .compatible = "adi,adt75", @@ -1008,7 +1112,15 @@ static struct i2c_driver lm75_i2c_driver = { .address_list = normal_i2c, }; -module_i2c_driver(lm75_i2c_driver); +static struct i3c_driver lm75_i3c_driver = { + .driver = { + .name = "lm75_i3c", + }, + .probe = lm75_i3c_probe, + .id_table = lm75_i3c_ids, +}; + +module_i3c_i2c_driver(lm75_i3c_driver, &lm75_i2c_driver) MODULE_AUTHOR("Frodo Looijaard "); MODULE_DESCRIPTION("LM75 driver");