From patchwork Mon Feb 10 14:59:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Stein X-Patchwork-Id: 13968051 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) (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 4C3D323CEF4; Mon, 10 Feb 2025 15:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.104.207.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739199629; cv=none; b=XqczrCy9kIWmpprtNhQ/jJkIUre776ORfCiljLgKfnN+cfYlYQ+hE1BBj42/EHsXQK3xUEC9PvFbE8f4vnilapCsx2DplPAvDCxUC+HkxXF6pPt4ms/j6lAGgvKxeY4lg78WS9HvclnNZQtFpMKPpJwMTmegtb0TtzT8+Adi1k8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739199629; c=relaxed/simple; bh=Wu/8x0tKfGZ8vQwjbXavFri9TuaV2YjlBE2HOdcaDzs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xzhqm51gBkfBiJXBXvUmoXYJZtIP1QJyn4dROZCkSeZuwdJGSCDHl3K/VYB7qgLQT6M+OZCoPkvMLjoLf+1sX/QVT/ImW9DtxRBaijyypRzPol9HFXeIPA9Q99b+/DBTb6Qw5y5pa0kH9mf0Tl8NI6UY0fY1WXHzpDMyIHjrTBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com; spf=pass smtp.mailfrom=ew.tq-group.com; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b=dzRdUblY; dkim=fail (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b=XyylDNkx reason="key not found in DNS"; arc=none smtp.client-ip=93.104.207.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="dzRdUblY"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b="XyylDNkx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1739199626; x=1770735626; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CXDFqYlNp+TrVoKDYxHCUwL/kqcqvFbl1BZczTsZMz8=; b=dzRdUblYv4IgJDVM+EWNLyAX9IyRu/O0VBfkpwF64/s1WGPYVbB9v5M+ sPZ6dT3fwpBhORL5IJhfFMWl1TjqYAMAdYXygS58wu0NYI2w61qPa8G4j Hd3TbqejWgJ4xXd83f4BcSOXhnXg6TUWkviWmVUGvA67GtMc0TVSMHf3O gHwdwsxrRgASq9tZTzlZuJiiBJJ8CoqtAnAKref1cDZft0ebLeK2r386M 3cJTXXKTeEzbNlIpGEvjtDgBGmeMK4w6/cqNo33gJQTpZyqy+C2Cf2hSg g1dHX+Uq//2DiSRwAzGOTM6kPHpiTwJ4zyKl/kRwWx8SRywVfp5OCOzGm Q==; X-CSE-ConnectionGUID: 477MuB47TtiAKlY1k0/nLw== X-CSE-MsgGUID: OnwByv64QQ+m64K2kC+RTg== X-IronPort-AV: E=Sophos;i="6.13,274,1732575600"; d="scan'208";a="41722355" Received: from vmailcow01.tq-net.de ([10.150.86.48]) by mx1.tq-group.com with ESMTP; 10 Feb 2025 16:00:23 +0100 X-CheckPoint: {67AA1487-1D-27DB3AF7-E9544489} X-MAIL-CPID: 5F26CA5C8F51C6DC4E3DB5F53EF510F7_5 X-Control-Analysis: str=0001.0A006378.67AA1488.0023,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 00BCB166BBA; Mon, 10 Feb 2025 16:00:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ew.tq-group.com; s=dkim; t=1739199619; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CXDFqYlNp+TrVoKDYxHCUwL/kqcqvFbl1BZczTsZMz8=; b=XyylDNkxO+9aRD1SG7gxpsk0RAYmxMp6NmPdFpF0/UkwoqzutDlNNemxtpbrJbPMndeOzX ko+WVSuHmYkcvj3boph+gLCz3JZcXypLTN4Q/c2Ee64yszCfU4xAFctQLSFB7GGm+soet3 7uDnflsShuhskEbSnbX7RusHJcCDDtbCWnQ/T6jtVVbzOZDb/mtHH26UyPWDYuJgABhzgj ybK7+WB16kPz8WkhJmZYR/KYZbXtwWwL6SHWshOo9twpazL3um56MlaNJHrfBzgewxwZ6C SIj1ENU7VAKui1Ayv6QDEO8sC6K41cGiJcha/SRLcurPWIsD9QI9kLCeL6OZiw== From: Alexander Stein To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Liam Girdwood , Mark Brown Cc: Alexander Stein , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] dt-bindings: hwmon: gpio-fan: Add optional regulator support Date: Mon, 10 Feb 2025 15:59:29 +0100 Message-Id: <20250210145934.761280-2-alexander.stein@ew.tq-group.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250210145934.761280-1-alexander.stein@ew.tq-group.com> References: <20250210145934.761280-1-alexander.stein@ew.tq-group.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 This adds an optional regulator support (e.g. switchable supply) to the GPIO fan binding. Signed-off-by: Alexander Stein Reviewed-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/hwmon/gpio-fan.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/gpio-fan.yaml b/Documentation/devicetree/bindings/hwmon/gpio-fan.yaml index 7f30cfc873506..d5386990ab153 100644 --- a/Documentation/devicetree/bindings/hwmon/gpio-fan.yaml +++ b/Documentation/devicetree/bindings/hwmon/gpio-fan.yaml @@ -23,6 +23,9 @@ properties: alarm-gpios: maxItems: 1 + fan-supply: + description: Phandle to the regulator that provides power to the fan. + gpio-fan,speed-map: $ref: /schemas/types.yaml#/definitions/uint32-matrix minItems: 2 From patchwork Mon Feb 10 14:59:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Stein X-Patchwork-Id: 13968052 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) (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 D8F4223CF08; Mon, 10 Feb 2025 15:00:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.104.207.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739199632; cv=none; b=OD/xPmmCEGHGDiypzLaJ275wC6AoXA8KGFnehhQ2NJ/PSLtd2HG4yH5xv817nnMFrfm4E5ypiLyPzVF5nTIeJ5lDy7VezI6FfMSpa7YLYHoofltB+4HP0GonPStw8O3KaM8S0Tq+2b4uEwMp3IxuYuN7dE5IAHq8DQoIPDH0Tkc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739199632; c=relaxed/simple; bh=je1TjdH+CB0VhROqa6xoLkzlRwEpMlNFVak/l0NPmXA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ChbT6twkN1KkePL93wmkGAWrrVuA+6ZrqLDQWbw0/8QlQKnoSi71+EKaT8OAbIXFdrF7tIDd88GXbN9fwGQwmGre5GP1gAU7pbEEX5AU1v2xqNvdZz/5EpbEy6Wn5c7JxyomMooY86/dWNnFpye/KLQlTVTW+Nf123j3g6Nyygw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com; spf=pass smtp.mailfrom=ew.tq-group.com; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b=EXBGQQh6; dkim=fail (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b=Wbyp/UYM reason="key not found in DNS"; arc=none smtp.client-ip=93.104.207.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="EXBGQQh6"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b="Wbyp/UYM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1739199630; x=1770735630; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SBg5ApdPVMTnLCtCYqyPBq1czt0gte8t4rojP/rLmB4=; b=EXBGQQh6hLpTHzTxlv3U9MYbyrJCm+UpzcvnBhDDAb9b7NSp84KD+NmJ Ue8THEhqA/FCm6rOR3H471Fw7MrOIGiChkHqeWW/eHyoPAaXDThiycnxL T4Dq0WtXufu5Aggv6RyWOVEZZzU+wR/jlFP5kIjrhNzjye1Ft4cfM8IXT xnT2/W8Yf4mkf28s6hAVur06UCGTw6Mpz1vTBEE/aoZpRS5N/chtC+zYN FDuuBHc3uh6VahNSmCc4jWxM8i+N8MF2oLzzsu93d4KyCNyISpcxHBFhM NReHlejcnF24np7aVopuZsmPCYvporF3Np0wC0jsSrL4KGfy1x0n73sZB w==; X-CSE-ConnectionGUID: J1bjCKPkTS2fdFiZJfiRHA== X-CSE-MsgGUID: Sm0f6sdfRZiFSssiESMyWA== X-IronPort-AV: E=Sophos;i="6.13,274,1732575600"; d="scan'208";a="41722356" Received: from vmailcow01.tq-net.de ([10.150.86.48]) by mx1.tq-group.com with ESMTP; 10 Feb 2025 16:00:28 +0100 X-CheckPoint: {67AA148C-26-5E7613A6-C613BD02} X-MAIL-CPID: 994425C9E64636E6E6464E64925E19D0_0 X-Control-Analysis: str=0001.0A006372.67AA148D.0083,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 10773169619; Mon, 10 Feb 2025 16:00:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ew.tq-group.com; s=dkim; t=1739199624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SBg5ApdPVMTnLCtCYqyPBq1czt0gte8t4rojP/rLmB4=; b=Wbyp/UYMciCUFlVXWfF4jYLp1od0qyyEcAI8zwXDhxGYV0AuMh+oPFnyqlO9OaLzbvz2Ak lbjBnj+0wuzmBEKe2jHPq91sLH/Pvmnq9RRlgJBp4fVsW911ulw490GWRq4lmU4mStb9CD qxf+Oz+lKf3CDiqds+KgVr5vnC4rnAC7/AVA12c5elLXBOF6+8f/hw7zzD/ww86+X7plrj cxBxh6s1q/23mjlgXtZLg5Yt26vHIUqQKseMBHf+TGV1Bl/7+6EYoelmCmImnxeKHpSNsX LYxjy+mZnU9DGTzwzbsYL3OAijqQ/YQ9sqY6U9OrkD64NhmnA59E2BhzfaXWBw== From: Alexander Stein To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Liam Girdwood , Mark Brown Cc: Alexander Stein , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] hwmon: (gpio-fan) Add missing mutex locks Date: Mon, 10 Feb 2025 15:59:30 +0100 Message-Id: <20250210145934.761280-3-alexander.stein@ew.tq-group.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250210145934.761280-1-alexander.stein@ew.tq-group.com> References: <20250210145934.761280-1-alexander.stein@ew.tq-group.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 set_fan_speed() is expected to be called with fan_data->lock being locked. Add locking for proper synchronization. Signed-off-by: Alexander Stein --- drivers/hwmon/gpio-fan.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index d92c536be9af7..b779240328d59 100644 --- a/drivers/hwmon/gpio-fan.c +++ b/drivers/hwmon/gpio-fan.c @@ -393,7 +393,12 @@ static int gpio_fan_set_cur_state(struct thermal_cooling_device *cdev, if (state >= fan_data->num_speed) return -EINVAL; + mutex_lock(&fan_data->lock); + set_fan_speed(fan_data, state); + + mutex_unlock(&fan_data->lock); + return 0; } @@ -489,7 +494,11 @@ MODULE_DEVICE_TABLE(of, of_gpio_fan_match); static void gpio_fan_stop(void *data) { + struct gpio_fan_data *fan_data = data; + + mutex_lock(&fan_data->lock); set_fan_speed(data, 0); + mutex_unlock(&fan_data->lock); } static int gpio_fan_probe(struct platform_device *pdev) @@ -562,7 +571,9 @@ static int gpio_fan_suspend(struct device *dev) if (fan_data->gpios) { fan_data->resume_speed = fan_data->speed_index; + mutex_lock(&fan_data->lock); set_fan_speed(fan_data, 0); + mutex_unlock(&fan_data->lock); } return 0; @@ -572,8 +583,11 @@ static int gpio_fan_resume(struct device *dev) { struct gpio_fan_data *fan_data = dev_get_drvdata(dev); - if (fan_data->gpios) + if (fan_data->gpios) { + mutex_lock(&fan_data->lock); set_fan_speed(fan_data, fan_data->resume_speed); + mutex_unlock(&fan_data->lock); + } return 0; } From patchwork Mon Feb 10 14:59:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Stein X-Patchwork-Id: 13968053 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) (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 791EE24113D; Mon, 10 Feb 2025 15:00:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.104.207.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739199637; cv=none; b=IwRIYAlh951xHOvQ7ON9Xn5OdRFxhHbNwl+xYbRkVn3l9PdUfg9CIJlpKdIhG1qsflJZdXuQPZVqfudo62BqRsRGAKrIbViu9DYxB6G0R7KpzSAiIjNuVSJljT5BM6f/g6ZY3yYjnV7yV2Xlu57oGYcHkHmH368zxqUK3PFCwOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739199637; c=relaxed/simple; bh=CpIY3VXhWV0zIQNk2Jdy6iSIOvKWKWRYF0BpjV11yt0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bSluvjUnJzFmamohbO60SPZ34SZjsKfHWCeNvAuhYY3r/2d7ctkh96krPm6grL9LgIetmH4Ew9+uLedJJP3ngyMI9UDD/Bu/kSLwYkYWYqHp7Opr39B4MZgmqoX1XOT/qLPkL/tHGiVp2sn6k5Zt8jelY9hXc7ROoKozvRvspJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com; spf=pass smtp.mailfrom=ew.tq-group.com; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b=ejVrayS0; dkim=fail (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b=cxZ/Rswo reason="key not found in DNS"; arc=none smtp.client-ip=93.104.207.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="ejVrayS0"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b="cxZ/Rswo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1739199635; x=1770735635; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7zhJkxN7M4AS4HKKzEz/t1x2Ieh8jUxa+UNprODpZG8=; b=ejVrayS00no5MA0AYWRsZP1/gEJ8iak65MyE0B3OCmrrAYktL5UETiUc fYkcCYF81rmks1gX9CpRA7YsyZPhbNzbjGQ9dlk6Vnw9ynJBT4vyEmntv 3Ci6h21Y/pnMvT1+j3tJRP8yE8LSPdMKjcFkMDvu7ce1QkVbeDILJupoF V6I8qvTcRaeLHUCearBGsEiiJY44ZWPHy1FtGYf5CHuWIhTRaMxMzLBZA oYFGeEx2lTaVuT3Npt+8sRaonODOk6t0DwfWeezbM8CksIO4iaW2+v6xT eqJIMRW+a+PgUMrdPDIObEuhwJQX8JpxqvgIk3/31fzLk3xpR9FQk+ZQz Q==; X-CSE-ConnectionGUID: kcsYhCceQzOrjtWek49g2w== X-CSE-MsgGUID: RaoQhQOLSPaTSKdKUeZ6fg== X-IronPort-AV: E=Sophos;i="6.13,274,1732575600"; d="scan'208";a="41722360" Received: from vmailcow01.tq-net.de ([10.150.86.48]) by mx1.tq-group.com with ESMTP; 10 Feb 2025 16:00:33 +0100 X-CheckPoint: {67AA1491-22-7866BB5F-D0C713E6} X-MAIL-CPID: 80C5FE1B7D4F1AE7214D1AD0A141B436_4 X-Control-Analysis: str=0001.0A006377.67AA1492.0019,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 09075169635; Mon, 10 Feb 2025 16:00:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ew.tq-group.com; s=dkim; t=1739199629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7zhJkxN7M4AS4HKKzEz/t1x2Ieh8jUxa+UNprODpZG8=; b=cxZ/RswohJFosoO7bLBuLSHwgIas+H89T1H8TNMhmdDoEXv5pTQ4woMobfOOF/LYjxXgkM pt3o1o/QO5A98SLD5+qulT5aO26pXv/CG9H+R0BrtfXUpknv+iOjgzLItnWorLUTbtF7SF /dxKeMTNLO+S3pg5UAFpzjvRyni9dPLNDyYJbhZT33KG9yga1CQEB7AHLYyCwO8pTXirHw vkkRNRHzJL2tC4MXCZj39CFumgc32DLm3pZ/i4T9fgCHCnuZlxwww7zI79EKQWeooBji6Z 2fH946fXb86o8wiKQA0353ljHhPeJ/ZIXulzx8wLVSyWtvgJUzNcr73izTX1Pg== From: Alexander Stein To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Liam Girdwood , Mark Brown Cc: Alexander Stein , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] hwmon: (gpio-fan) Ensure lock is held during set_fan_speed() Date: Mon, 10 Feb 2025 15:59:31 +0100 Message-Id: <20250210145934.761280-4-alexander.stein@ew.tq-group.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250210145934.761280-1-alexander.stein@ew.tq-group.com> References: <20250210145934.761280-1-alexander.stein@ew.tq-group.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 Instead of just documenting by comment, ensure locking per code. Signed-off-by: Alexander Stein --- drivers/hwmon/gpio-fan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index b779240328d59..322b161d5ca1f 100644 --- a/drivers/hwmon/gpio-fan.c +++ b/drivers/hwmon/gpio-fan.c @@ -124,9 +124,10 @@ static int __get_fan_ctrl(struct gpio_fan_data *fan_data) return ctrl_val; } -/* Must be called with fan_data->lock held, except during initialization. */ static void set_fan_speed(struct gpio_fan_data *fan_data, int speed_index) { + WARN_ON_ONCE(!mutex_is_locked(&fan_data->lock)); + if (fan_data->speed_index == speed_index) return; From patchwork Mon Feb 10 14:59:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Stein X-Patchwork-Id: 13968054 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) (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 707D124394C; Mon, 10 Feb 2025 15:00:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.104.207.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739199641; cv=none; b=hoWpR2KQmy1Cz1zu4W3HniejBYHK4Yccsz9ohMeOuXn6taBGiEwf54QVLJzyVndVn4jdSj0t6brXgFGIx8o/MU3PCxaNJ40zH9ZrJ3BbZyTfMmVQuy14EmwjVtbh/oGxCv9E7Q8XhwebhChj0Y3RdbYBzTtoaEWedQ9NVttdNyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739199641; c=relaxed/simple; bh=IlEH9UnHk+VkPH0rbc8UAMXFvI08ENUutZ/6vepeZN0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XmUTDNySQfjxyyD/CplFf8o3EK4Fil7AV79C8muJG9WJmT5hOmsyzPU6SzumC+V5k2L++V11xVb62YALj8/Zwlvz0me2DDW6I70UHPlDdH7tAo4ibKl84Wfgt/fEH+sKF5jV8gZHso8KXqetNxCpfe+8LmB0/mXP8XdlYtjMyGc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com; spf=pass smtp.mailfrom=ew.tq-group.com; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b=Yv33umHL; dkim=fail (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b=C/duP5Ab reason="key not found in DNS"; arc=none smtp.client-ip=93.104.207.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="Yv33umHL"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b="C/duP5Ab" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1739199640; x=1770735640; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wCA2u7BrMzwTbrY7qS2/tG6GLaz9EpT4QFmVke8rkzI=; b=Yv33umHLwKFt2Qphasbzxge0J2ABxqviA6UXGRqUMSzjT/Rg18MJRMgM xzOGXsMOvL+5ZDLaDU44tokz/x4lJGpG1MNRT/h5cs0GgAzqboPYmcf/8 +46FzJTg1rndgcNgX9TH0VME24sBf5zpgqeVvaOejYdAcLj1ouiFweCkZ /LDQ1N8JKWPpyjDRXofu2oZfuxKZ5e9wOtlcqIr+6iIB2VTww532y5DXo 57MBGiSxuoZRqtmq9KDGDA/NfKZNvWLNyPvWg+uzdLlhKVxTmGAlQq/Di YggjLZKYBDOefIkGGHvb+ZtSAppeyhf4SeXGlH2KtiQ96jb4mFbDRusho g==; X-CSE-ConnectionGUID: XHdI1dveQbChE7XARXrDeA== X-CSE-MsgGUID: sZIJ26gnTS6O/P8/T5fz3g== X-IronPort-AV: E=Sophos;i="6.13,274,1732575600"; d="scan'208";a="41722363" Received: from vmailcow01.tq-net.de ([10.150.86.48]) by mx1.tq-group.com with ESMTP; 10 Feb 2025 16:00:38 +0100 X-CheckPoint: {67AA1496-25-7866BB5F-D0C713E6} X-MAIL-CPID: FC6134356E81C2C52A1BA612175D2EC6_4 X-Control-Analysis: str=0001.0A006377.67AA1497.001B,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 11D7316964A; Mon, 10 Feb 2025 16:00:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ew.tq-group.com; s=dkim; t=1739199634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wCA2u7BrMzwTbrY7qS2/tG6GLaz9EpT4QFmVke8rkzI=; b=C/duP5AbfTsSAIxyoOMZwJL2ZYUjodKkmIvYubmDtXla5BmWenfXtN9iyIbmC27EQ1f+gm t/WxC2c+mpZd2yuBOfRxiX8HCQUaw2hT9wXgsPqg/OzLdSkTtMy519J/QL6BG1uEoyVOzt DQ1uQH21nbdhGM8ARZ3obzLciT6+ZOtJFSIRQv7W8w1UQM8aW68Ri/+ukc1dzw6YZ9xhLQ o+BHLoYCaisy6nxlnf++NgfN5SmsLAdFTmdN5giQA6YyOBsbo953wDIpY1LY/XV24sZw3z C5pIfH5EIMW8UzyeWfAlZAYU8fGtxl86sPRurGSQPfybpapBH/OCYqlUljr8/g== From: Alexander Stein To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Liam Girdwood , Mark Brown Cc: Alexander Stein , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] hwmon: (gpio-fan) Remove unnecessary comment Date: Mon, 10 Feb 2025 15:59:32 +0100 Message-Id: <20250210145934.761280-5-alexander.stein@ew.tq-group.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250210145934.761280-1-alexander.stein@ew.tq-group.com> References: <20250210145934.761280-1-alexander.stein@ew.tq-group.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 __set_fan_ctrl() is only called by set_fan_speed(), which ensures fan_data->lock is held already. Signed-off-by: Alexander Stein --- drivers/hwmon/gpio-fan.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index 322b161d5ca1f..4614d0ad86b3a 100644 --- a/drivers/hwmon/gpio-fan.c +++ b/drivers/hwmon/gpio-fan.c @@ -100,7 +100,6 @@ static int fan_alarm_init(struct gpio_fan_data *fan_data) * Control GPIOs. */ -/* Must be called with fan_data->lock held, except during initialization. */ static void __set_fan_ctrl(struct gpio_fan_data *fan_data, int ctrl_val) { int i; From patchwork Mon Feb 10 14:59:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Stein X-Patchwork-Id: 13968055 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) (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 B6E052441A1; Mon, 10 Feb 2025 15:00:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.104.207.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739199647; cv=none; b=P/HR9Jk0szrATQ/wMG3JXM7z16x2GMe73/BjCQo4je1j1paqTJGl6tJEN3n/BxuB88sLt3G4VuBadrf92X6v79NubzfPCWUwTUm1y5H1RlCnj9vJSEiPysBuSAP6BWuXBZQh8O3J1vg1SGPMynZ/w7N8BSIU8ZKFsM/ro5w47g8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739199647; c=relaxed/simple; bh=pddqfAGMHj8YYYp8C8hwTVOiAdmP2naJ4OoMdXU+dHs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NaqWyowC1foWbktkXKPnzHN9LwqHEPIrCTb1PH2C9U+3JZ8umLqeIqRdM+Cu07XgLD5AKXUeOVKrQ9D2ix1FDSUa0TWAYuQgqqpnYChIyotztUBvNAiHuXgC29S70HqWBWlh4HHlVK2KK5bJYV3s9xy96jyvXT25aCUXGW40diA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com; spf=pass smtp.mailfrom=ew.tq-group.com; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b=qX8d/Kyw; dkim=fail (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b=GlToWC3t reason="key not found in DNS"; arc=none smtp.client-ip=93.104.207.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="qX8d/Kyw"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b="GlToWC3t" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1739199645; x=1770735645; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zCIkKRFP/FaYbigx+wNQiUdAKh8KaKGOhBsdIu/hVl8=; b=qX8d/KyweaZVMtQPjaxpVIg6CRRV9SZ3pRs2kzM9u16S4ckQlR1GHdNs k9JNtquTo3C2yKwtmQ8KRIe4w9/kDbqxNuwiHv7r5WboAykJjl7pwP7rH hhXrybw/5LAU05CHh5SCsk/toyrd5hvmG6v82kFU3QH3XCpgO5teZohWD fzhLg9f4A8FrvU/ZN5TUe6+mAzDSyaBQTi1v5OH04NlvlTu29HA4XUdlz N7cMP2N5geNN/cgn7B6aRLMaS2BqXNzNNHi1jRY7eDO4PlVPNCiXG6ryR diTHLwr3TgkjSkwNsib5iRZeCUQeuxTyEqkOhsMSEv0CrV+rYXOeofR68 Q==; X-CSE-ConnectionGUID: hwUrE1KtTzWpuJ2F2FGJPg== X-CSE-MsgGUID: zNwR12AOTsilrpptPGA3Cw== X-IronPort-AV: E=Sophos;i="6.13,274,1732575600"; d="scan'208";a="41722365" Received: from vmailcow01.tq-net.de ([10.150.86.48]) by mx1.tq-group.com with ESMTP; 10 Feb 2025 16:00:43 +0100 X-CheckPoint: {67AA149B-24-BE46CFC6-C2AD582F} X-MAIL-CPID: 0CB0F94F2F3D2C15B55DE093C1FA3DD4_1 X-Control-Analysis: str=0001.0A00639A.67AA149C.0064,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 32EF016961E; Mon, 10 Feb 2025 16:00:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ew.tq-group.com; s=dkim; t=1739199639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zCIkKRFP/FaYbigx+wNQiUdAKh8KaKGOhBsdIu/hVl8=; b=GlToWC3tBBIBHKfc491bnZyjujwPlLUcmKixu1lEPoAdryqxXJwvI9ueDrBP93CsMh9V7l 9/DMmPcUxJZO8fSuO7QVjuSuHeEVFTID9PT8fmnW9STpZHoKJ5bx4Mkr1BasRZZ7+7WaZo zkXQfo8lEhmIzINOPdGdCjY2KQ6DLefpaLADQZHWszv3CNSIyt2bC/0i24RMrqhVWRRqRy UKVQw4Vp4czM27Y/Uw6pmwIhxsV5rEtsM9l+N2EbX0IZg6uzYcF1sOwe3otlSKwOw8bllf 7LhtEWd1NkRh/yMFYn3bmzAX3uKcKidLswUx8gBIQTDYM/FrD9OngX1zMj7YJQ== From: Alexander Stein To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Liam Girdwood , Mark Brown Cc: Alexander Stein , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] hwmon: (gpio-fan) Add regulator support Date: Mon, 10 Feb 2025 15:59:33 +0100 Message-Id: <20250210145934.761280-6-alexander.stein@ew.tq-group.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250210145934.761280-1-alexander.stein@ew.tq-group.com> References: <20250210145934.761280-1-alexander.stein@ew.tq-group.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 FANs might be supplied by a regulator which needs to be enabled as well. This is implemented using runtime PM. Every time speed_index changes from 0 to non-zero and vise versa RPM is resumed or suspended. Intitial RPM state is determined by initial value of speed_index. Signed-off-by: Alexander Stein --- drivers/hwmon/gpio-fan.c | 86 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index 4614d0ad86b3a..3d4719391ea90 100644 --- a/drivers/hwmon/gpio-fan.c +++ b/drivers/hwmon/gpio-fan.c @@ -20,6 +20,9 @@ #include #include #include +#include +#include +#include #include struct gpio_fan_speed { @@ -42,6 +45,7 @@ struct gpio_fan_data { bool pwm_enable; struct gpio_desc *alarm_gpio; struct work_struct alarm_work; + struct regulator *supply; }; /* @@ -123,15 +127,40 @@ static int __get_fan_ctrl(struct gpio_fan_data *fan_data) return ctrl_val; } -static void set_fan_speed(struct gpio_fan_data *fan_data, int speed_index) +static int set_fan_speed(struct gpio_fan_data *fan_data, int speed_index) { WARN_ON_ONCE(!mutex_is_locked(&fan_data->lock)); if (fan_data->speed_index == speed_index) - return; + return 0; + + if (fan_data->speed_index == 0 && speed_index > 0) { + int ret; + + ret = pm_runtime_resume_and_get(fan_data->dev); + if (ret < 0) { + dev_err(fan_data->dev, + "Failed to runtime_get device: %d\n", ret); + return ret; + } + } __set_fan_ctrl(fan_data, fan_data->speed[speed_index].ctrl_val); + + if (fan_data->speed_index > 0 && speed_index == 0) { + int ret; + + ret = pm_runtime_put_sync(fan_data->dev); + if (ret < 0) { + dev_err(fan_data->dev, + "Failed to runtime_put device: %d\n", ret); + return ret; + } + } + fan_data->speed_index = speed_index; + + return 0; } static int get_fan_speed_index(struct gpio_fan_data *fan_data) @@ -499,6 +528,8 @@ static void gpio_fan_stop(void *data) mutex_lock(&fan_data->lock); set_fan_speed(data, 0); mutex_unlock(&fan_data->lock); + + pm_runtime_disable(fan_data->dev); } static int gpio_fan_probe(struct platform_device *pdev) @@ -521,6 +552,16 @@ static int gpio_fan_probe(struct platform_device *pdev) platform_set_drvdata(pdev, fan_data); mutex_init(&fan_data->lock); + fan_data->supply = devm_regulator_get_optional(dev, "fan"); + if (IS_ERR(fan_data->supply)) { + err = PTR_ERR(fan_data->supply); + if (err != -ENODEV) + return dev_err_probe(dev, err, + "Failed to get fan-supply"); + + fan_data->supply = NULL; + } + /* Configure control GPIOs if available. */ if (fan_data->gpios && fan_data->num_gpios > 0) { if (!fan_data->speed || fan_data->num_speed <= 1) @@ -548,6 +589,17 @@ static int gpio_fan_probe(struct platform_device *pdev) return err; } + pm_runtime_set_suspended(&pdev->dev); + pm_runtime_enable(&pdev->dev); + /* If current GPIO state is active, mark RPM as active as well */ + if (fan_data->speed_index > 0) { + int ret; + + ret = pm_runtime_resume_and_get(&pdev->dev); + if (ret) + return ret; + } + /* Optional cooling device register for Device tree platforms */ fan_data->cdev = devm_thermal_of_cooling_device_register(dev, np, "gpio-fan", fan_data, &gpio_fan_cool_ops); @@ -565,6 +617,28 @@ static void gpio_fan_shutdown(struct platform_device *pdev) set_fan_speed(fan_data, 0); } +static int gpio_fan_runtime_suspend(struct device *dev) +{ + struct gpio_fan_data *fan_data = dev_get_drvdata(dev); + int ret = 0; + + if (fan_data->supply) + ret = regulator_disable(fan_data->supply); + + return ret; +} + +static int gpio_fan_runtime_resume(struct device *dev) +{ + struct gpio_fan_data *fan_data = dev_get_drvdata(dev); + int ret = 0; + + if (fan_data->supply) + ret = regulator_enable(fan_data->supply); + + return ret; +} + static int gpio_fan_suspend(struct device *dev) { struct gpio_fan_data *fan_data = dev_get_drvdata(dev); @@ -592,14 +666,18 @@ static int gpio_fan_resume(struct device *dev) return 0; } -static DEFINE_SIMPLE_DEV_PM_OPS(gpio_fan_pm, gpio_fan_suspend, gpio_fan_resume); +static const struct dev_pm_ops gpio_fan_pm = { + RUNTIME_PM_OPS(gpio_fan_runtime_suspend, + gpio_fan_runtime_resume, NULL) + SYSTEM_SLEEP_PM_OPS(gpio_fan_suspend, gpio_fan_resume) +}; static struct platform_driver gpio_fan_driver = { .probe = gpio_fan_probe, .shutdown = gpio_fan_shutdown, .driver = { .name = "gpio-fan", - .pm = pm_sleep_ptr(&gpio_fan_pm), + .pm = pm_ptr(&gpio_fan_pm), .of_match_table = of_gpio_fan_match, }, };