Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2967804pxb; Mon, 17 Jan 2022 09:09:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGx4Nh4UWQaNKNwwOCQDcKR4O2BKp3PoyRESxiWygXcaxXHcwkJS0ohRgTKD17h5KqefC1 X-Received: by 2002:a62:ab02:0:b0:4c0:1cd9:2f82 with SMTP id p2-20020a62ab02000000b004c01cd92f82mr22062858pff.8.1642439376176; Mon, 17 Jan 2022 09:09:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642439376; cv=none; d=google.com; s=arc-20160816; b=ZtyPt2o8HoDDciiVV980SRPMgk9KS8uvOYBY0a2nrj1RF0wVxi9cxQ2EoKh4QVDFzv Gyt1KNCAN6EFIbEMNtV6H6L5y1Wvqka5IeN0wLCZkQDXCJ/QMHFUmJZAu7OS54pLTSJs aBX757OKQ89bkzef32/jpfGGj4BXFg3RBvYqY2147/eZCTbukHtKU2Ug79gWkiFF3TgL MftOX3e9W9H8mqsD55y59W7ZydmPWaWEd3OsdrC6wx3avLRrVHr3MOCPV1MjgNp1Yyt6 4xH9Dm74HbM/2Lj0ta3fOcwjaFcXJp1czTWZasImCLxCSfELbT1W8e+TQQVWd22Q/SV5 4HKw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vJPqdtXimTgX1JvnFhivqUBJea/o8yZVEVyqYw+RAsA=; b=ApfPmWgJ6EJ8twQjIcVZMlnCnqREa+zhq0jeg8xU6EL+z7QsXTLruDAV16hVoMy8QN 6J0nWMNop7Ts1nrHBTQ2gI+sNVd+O3EwOVGuuS5l+Lmw7/GLEXd/7vio+A6GZV/oOGoA LSuELH7MtbCCmL680vbqdE2+wAW1yQ7KpkLbz7//RSmHDTmwna/RmgztlwF+fkgMVtJ/ DCGdftTetXqBv2mRkqlyfMgR+S+h/HcZeWV0cG63krAkHjmfFfcuAIhSSL9b8PJOUUMS Q/17OsIIlVwCLROC4NL9kFwWh6iF0qQKHwcJTlfs3G4LjU6wDGElTTKCmABJ9CVDcuoW kd1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sylv.io header.s=MBO0001 header.b=j8bHj2Wt; 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=pass (p=NONE sp=NONE dis=NONE) header.from=sylv.io Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i23si15869438pgl.299.2022.01.17.09.09.23; Mon, 17 Jan 2022 09:09:36 -0800 (PST) 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=@sylv.io header.s=MBO0001 header.b=j8bHj2Wt; 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=pass (p=NONE sp=NONE dis=NONE) header.from=sylv.io Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238723AbiAQKlG (ORCPT + 99 others); Mon, 17 Jan 2022 05:41:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238703AbiAQKlD (ORCPT ); Mon, 17 Jan 2022 05:41:03 -0500 Received: from mout-y-209.mailbox.org (mout-y-209.mailbox.org [IPv6:2001:67c:2050:1::465:209]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 132F2C06161C; Mon, 17 Jan 2022 02:41:03 -0800 (PST) Received: from smtp202.mailbox.org (unknown [91.198.250.118]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-y-209.mailbox.org (Postfix) with ESMTPS id 4JcpNF1CkLzQjgQ; Mon, 17 Jan 2022 11:41:01 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sylv.io; s=MBO0001; t=1642416059; 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=vJPqdtXimTgX1JvnFhivqUBJea/o8yZVEVyqYw+RAsA=; b=j8bHj2WtOqj5k+4cfNwYLo/4G/Ki6PSuFP/7XvCExJ6z74sDZ2WAMELjsUXJ87qBZM220q BVgoUxBHzcX/IKY4H+5riklQ3Df+olNWEm7jrhMrbsLlTn5LIp0sfCVRBxk+sEdKtvnLkF cHaYlxoIIxocZixdTnGLLzOEkRguJyhpmBbt3amqJ1INLKm6xgIRqo4FPaaPiVHRbhjjA4 nbq3KVkBEK0IxfSbyUNxHdyiAUyVF18LwZp8Y1iYJnAz8+aXUZZWiqIE9gM/zxNMnhbDyo 1seY7xB8RHRAI1irYnvcWcDRJVq1Uq/f1K9dopPGQM312GSzbQZRPjkS3277vA== From: Marcello Sylvester Bauer To: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Patrick Rudolph , Jean Delvare , Guenter Roeck , Liam Girdwood , Mark Brown Subject: [PATCH v2 2/4] hwmon: (max6639) Add regulator support Date: Mon, 17 Jan 2022 11:40:24 +0100 Message-Id: <4c644f279f6e205d3c9540a4ad35825e4d5f2da1.1642413668.git.sylv@sylv.io> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add regulator support for boards where the fan-supply have to be powered up before it can be used. Signed-off-by: Patrick Rudolph Signed-off-by: Marcello Sylvester Bauer --- drivers/hwmon/max6639.c | 64 +++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c index ccc0f047bd44..0b241f029229 100644 --- a/drivers/hwmon/max6639.c +++ b/drivers/hwmon/max6639.c @@ -87,6 +87,9 @@ struct max6639_data { /* Register values initialized only once */ u8 ppr; /* Pulses per rotation 0..3 for 1..4 ppr */ u8 rpm_range; /* Index in above rpm_ranges table */ + + /* Optional regulator for FAN supply */ + struct regulator *reg; }; static struct max6639_data *max6639_update_device(struct device *dev) @@ -516,6 +519,11 @@ static int max6639_detect(struct i2c_client *client, return 0; } +static void max6639_regulator_disable(void *data) +{ + regulator_disable(data); +} + static int max6639_probe(struct i2c_client *client) { struct device *dev = &client->dev; @@ -528,6 +536,30 @@ static int max6639_probe(struct i2c_client *client) return -ENOMEM; data->client = client; + + data->reg = devm_regulator_get_optional(dev, "fan"); + if (IS_ERR(data->reg)) { + if (PTR_ERR(data->reg) != -ENODEV) { + err = (int)PTR_ERR(data->reg); + dev_warn(dev, "Failed looking up fan supply: %d\n", err); + return err; + } + data->reg = NULL; + } else { + /* Spin up fans */ + err = regulator_enable(data->reg); + if (err) { + dev_err(dev, "Failed to enable fan supply: %d\n", err); + return err; + } + err = devm_add_action_or_reset(dev, max6639_regulator_disable, + data->reg); + if (err) { + dev_err(dev, "Failed to register action: %d\n", err); + return err; + } + } + mutex_init(&data->update_lock); /* Initialize the max6639 chip */ @@ -545,23 +577,39 @@ static int max6639_probe(struct i2c_client *client) static int max6639_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); - int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG); - if (data < 0) - return data; + struct max6639_data *data = dev_get_drvdata(dev); + int ret = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG); + + if (ret < 0) + return ret; + + if (data->reg) + regulator_disable(data->reg); return i2c_smbus_write_byte_data(client, - MAX6639_REG_GCONFIG, data | MAX6639_GCONFIG_STANDBY); + MAX6639_REG_GCONFIG, ret | MAX6639_GCONFIG_STANDBY); } static int max6639_resume(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); - int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG); - if (data < 0) - return data; + struct max6639_data *data = dev_get_drvdata(dev); + int ret; + + if (data->reg) { + ret = regulator_enable(data->reg); + if (ret) { + dev_err(dev, "Failed to enable fan supply: %d\n", ret); + return ret; + } + } + + ret = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG); + if (ret < 0) + return ret; return i2c_smbus_write_byte_data(client, - MAX6639_REG_GCONFIG, data & ~MAX6639_GCONFIG_STANDBY); + MAX6639_REG_GCONFIG, ret & ~MAX6639_GCONFIG_STANDBY); } #endif /* CONFIG_PM_SLEEP */ -- 2.33.1