From patchwork Thu Apr 4 19:11:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13618176 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 AE02112D1FA; Thu, 4 Apr 2024 19:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712258010; cv=none; b=gJt/KXMFHRRkhL05Fh2m/MUSGrrOSfnrnOId0t/CkSKi3TNnL5K+s63QXFuMbCkZneLpnPDO8do2IJnUQb5UbsIIFkI+syiJ2wVvR422Sl6W2zH4dMCTAVouih5c0Cpf7RnX1DBiwbFwMGaprW5Y62jiNLDEMRHXrSy+/mWVFSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712258010; c=relaxed/simple; bh=ASOgen0Mpri82vcRR7Jkdi+CxzjQPTB2Og1Pn2zqEpo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aaYLHY3qXRvKdfVWPx9d6xDOaRP2BmgyAq8OjxEdPfB1xdp0pphZQ8Vv7rr03K3EnLcZyw2osbObal3SdbOIo54hjgZj9rhPlWOH+xqUd8iOvm+UvrGevtwhHfN1aPK0XU2fEwgRtkg7c5laqfsMU82NxNRNYI6iLuzcciP3EQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=CLX5xfo9; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CLX5xfo9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712258009; x=1743794009; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ASOgen0Mpri82vcRR7Jkdi+CxzjQPTB2Og1Pn2zqEpo=; b=CLX5xfo9aa+g8trmuRvWlyMfAd6u6clB8CDHazmnKFz+0zzzMyd8tN/H LDTXElO/qEQpJ8K3H1f3xiOjzP/KxNYlr3QTtUR8fAmaxjwKCZJkOyNv2 SB52qvNgxUHyaDTsjiH43PQ5kD2qqk1P9frexThHXcLUBo+kvPq3MJYui q9IrT9M5US0FGFKBkzESKLhoBn80Dc2o83TDhwXlBOlTpfcmM+sOKz76U 0dIHx1oKctCFv5nS+Hfh0PaAIlpb9VGJjuvlTNAh0h3EfNkogS2c66ABa F3VyPeJDDMs9NNJGyVmyw2oUaU3eUxRnrcyc6C6nW96TNQCP1yY2WFtTC g==; X-CSE-ConnectionGUID: l9kr0PF5RxmNIOIpaLL7zg== X-CSE-MsgGUID: +2PlK/hVSxit3h6717i3Yw== X-IronPort-AV: E=McAfee;i="6600,9927,11034"; a="18709368" X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="18709368" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2024 12:13:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11034"; a="937087025" X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="937087025" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 04 Apr 2024 12:13:26 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 7BAD23E5; Thu, 4 Apr 2024 22:13:25 +0300 (EEST) From: Andy Shevchenko To: Guenter Roeck , Andy Shevchenko , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jean Delvare Subject: [PATCH v2 1/2] hwmon: (pwm-fan) Convert to use of_property_read_u32_array() Date: Thu, 4 Apr 2024 22:11:38 +0300 Message-ID: <20240404191323.3547465-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240404191323.3547465-1-andriy.shevchenko@linux.intel.com> References: <20240404191323.3547465-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is a preparatory change to fulfill further conversion the driver to be OF-independent. The independent code has no analogue API that can read the value by index in the device property array. Suggested-by: Guenter Roeck Signed-off-by: Andy Shevchenko --- drivers/hwmon/pwm-fan.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index b67bc9e833c0..bf902610cd07 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -25,7 +25,6 @@ struct pwm_fan_tach { int irq; atomic_t pulses; unsigned int rpm; - u8 pulses_per_revolution; }; enum pwm_fan_enable_mode { @@ -48,6 +47,7 @@ struct pwm_fan_ctx { int tach_count; struct pwm_fan_tach *tachs; + u32 *pulses_per_revolution; ktime_t sample_start; struct timer_list rpm_timer; @@ -85,7 +85,7 @@ static void sample_timer(struct timer_list *t) pulses = atomic_read(&tach->pulses); atomic_sub(pulses, &tach->pulses); tach->rpm = (unsigned int)(pulses * 1000 * 60) / - (tach->pulses_per_revolution * delta); + (ctx->pulses_per_revolution[i] * delta); } ctx->sample_start = ktime_get(); @@ -562,6 +562,20 @@ static int pwm_fan_probe(struct platform_device *pdev) if (!fan_channel_config) return -ENOMEM; ctx->fan_channel.config = fan_channel_config; + + ctx->pulses_per_revolution = devm_kmalloc_array(dev, + ctx->tach_count, + sizeof(*ctx->pulses_per_revolution), + GFP_KERNEL); + if (!ctx->pulses_per_revolution) + return -ENOMEM; + + /* Setup default pulses per revolution */ + for (i = 0; i < ctx->tach_count; i++) + ctx->pulses_per_revolution[i] = 2; + + of_property_read_u32_array(dev->of_node, "pulses-per-revolution", + ctx->pulses_per_revolution, ctx->tach_count); } channels = devm_kcalloc(dev, channel_count + 1, @@ -573,7 +587,6 @@ static int pwm_fan_probe(struct platform_device *pdev) for (i = 0; i < ctx->tach_count; i++) { struct pwm_fan_tach *tach = &ctx->tachs[i]; - u32 ppr = 2; tach->irq = platform_get_irq(pdev, i); if (tach->irq == -EPROBE_DEFER) @@ -589,12 +602,7 @@ static int pwm_fan_probe(struct platform_device *pdev) } } - of_property_read_u32_index(dev->of_node, - "pulses-per-revolution", - i, - &ppr); - tach->pulses_per_revolution = ppr; - if (!tach->pulses_per_revolution) { + if (!ctx->pulses_per_revolution[i]) { dev_err(dev, "pulses-per-revolution can't be zero.\n"); return -EINVAL; } @@ -602,7 +610,7 @@ static int pwm_fan_probe(struct platform_device *pdev) fan_channel_config[i] = HWMON_F_INPUT; dev_dbg(dev, "tach%d: irq=%d, pulses_per_revolution=%d\n", - i, tach->irq, tach->pulses_per_revolution); + i, tach->irq, ctx->pulses_per_revolution[i]); } if (ctx->tach_count > 0) { From patchwork Thu Apr 4 19:11:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13618178 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 80F17133424; Thu, 4 Apr 2024 19:13:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712258013; cv=none; b=QZkjaaS/m1A6agLTB4/ecUrVNW04k+5n62Jv8K7mSzih9/5NtkrkSNc/dbhXZTPvg9PS0BPKm/fXWtJySPxaXkF2gl3Rh0EApV2AOoQncav9FSA0k8hsrl4EAIjHaSD0un3brodz8L+EmM0+YWkoZS+ubPvE8B3Wp/X7ghWU498= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712258013; c=relaxed/simple; bh=BeJDiaZ5Jkmnb3C7Z91MeyQopFXvWSPHUzMeaIHYLXA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NetrDN6+yCf98DG3G0TsEl0orB31wG7Cwk9p5F0QlNiJwvzgb48x9WJrrJav7U1exgegrbkcwrlQRSB5vbg9rA/Ak6Zels2glQukoafClVJkvWYtwHoRNUdQ9GdRHFKk8sDlR6WVnZRNOl0xcXsHvqdP5758R2ZthgBGdivwLmk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZRWrqi0v; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZRWrqi0v" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712258011; x=1743794011; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BeJDiaZ5Jkmnb3C7Z91MeyQopFXvWSPHUzMeaIHYLXA=; b=ZRWrqi0v9tDH9F7jlahe2pOmKgIv++mGtBf5OrAALTbHstfYOOxUFevM p2j6IR7SS1ThukrsiqIbpRpY9eDaBZk6s7tevVoWanoCFScG9Y1+K3LSO 6GmYvIXTYhoB1Sn85gSb7q/mBglIt2wR03IoHumW9D6Xr15C+okgpFWr1 nwUnBpwuivwxUWEe5VCoLx7J9GnbUj1ugDgIFRGtAWavanz6Sx3baStbd P0OgGwGYuDZWYxIMPpPldqcEM+Oy/kJwgbsy57O2ZLRwE5o60URkTkUvu YN84jcWrKznybwBay5sB/boSEq+Jvc6SffC6JhxQ6r6RyGpCungtr9Mt2 g==; X-CSE-ConnectionGUID: GDo3op+3S42zpGFkogNzbA== X-CSE-MsgGUID: 1OX68lXzSqe19th3iDsj0A== X-IronPort-AV: E=McAfee;i="6600,9927,11034"; a="18709374" X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="18709374" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2024 12:13:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11034"; a="937087027" X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="937087027" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 04 Apr 2024 12:13:26 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8E125B56; Thu, 4 Apr 2024 22:13:25 +0300 (EEST) From: Andy Shevchenko To: Guenter Roeck , Andy Shevchenko , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jean Delvare , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Subject: [PATCH v2 2/2] hwmon: (pwm-fan) Make use of device properties Date: Thu, 4 Apr 2024 22:11:39 +0300 Message-ID: <20240404191323.3547465-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240404191323.3547465-1-andriy.shevchenko@linux.intel.com> References: <20240404191323.3547465-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Convert the module to be property provider agnostic and allow it to be used on non-OF platforms. Add mod_devicetable.h include. Signed-off-by: Andy Shevchenko Acked-by: Uwe Kleine-König --- drivers/hwmon/Kconfig | 2 +- drivers/hwmon/pwm-fan.c | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 83945397b6eb..960539bd40ab 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1778,7 +1778,7 @@ config SENSORS_PT5161L config SENSORS_PWM_FAN tristate "PWM fan" - depends on (PWM && OF) || COMPILE_TEST + depends on PWM || COMPILE_TEST depends on THERMAL || THERMAL=n help If you say yes here you get support for fans connected to PWM lines. diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index bf902610cd07..a1712649b07e 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -9,10 +9,11 @@ #include #include +#include #include #include -#include #include +#include #include #include #include @@ -421,16 +422,14 @@ static const struct thermal_cooling_device_ops pwm_fan_cooling_ops = { .set_cur_state = pwm_fan_set_cur_state, }; -static int pwm_fan_of_get_cooling_data(struct device *dev, - struct pwm_fan_ctx *ctx) +static int pwm_fan_get_cooling_data(struct device *dev, struct pwm_fan_ctx *ctx) { - struct device_node *np = dev->of_node; int num, i, ret; - if (!of_property_present(np, "cooling-levels")) + if (!device_property_present(dev, "cooling-levels")) return 0; - ret = of_property_count_u32_elems(np, "cooling-levels"); + ret = device_property_count_u32(dev, "cooling-levels"); if (ret <= 0) { dev_err(dev, "Wrong data!\n"); return ret ? : -EINVAL; @@ -442,8 +441,8 @@ static int pwm_fan_of_get_cooling_data(struct device *dev, if (!ctx->pwm_fan_cooling_levels) return -ENOMEM; - ret = of_property_read_u32_array(np, "cooling-levels", - ctx->pwm_fan_cooling_levels, num); + ret = device_property_read_u32_array(dev, "cooling-levels", + ctx->pwm_fan_cooling_levels, num); if (ret) { dev_err(dev, "Property 'cooling-levels' cannot be read!\n"); return ret; @@ -574,8 +573,8 @@ static int pwm_fan_probe(struct platform_device *pdev) for (i = 0; i < ctx->tach_count; i++) ctx->pulses_per_revolution[i] = 2; - of_property_read_u32_array(dev->of_node, "pulses-per-revolution", - ctx->pulses_per_revolution, ctx->tach_count); + device_property_read_u32_array(dev, "pulses-per-revolution", + ctx->pulses_per_revolution, ctx->tach_count); } channels = devm_kcalloc(dev, channel_count + 1, @@ -630,7 +629,7 @@ static int pwm_fan_probe(struct platform_device *pdev) return PTR_ERR(hwmon); } - ret = pwm_fan_of_get_cooling_data(dev, ctx); + ret = pwm_fan_get_cooling_data(dev, ctx); if (ret) return ret;