Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp81694pxb; Thu, 20 Jan 2022 09:18:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+arrzZhJHYTkDBDcsaI3oq7/h4csTpCmCd/0Wv48P+M8WNhwghc6yzVB3nanm0rm6agKY X-Received: by 2002:a17:902:9a0a:b0:149:7da0:af27 with SMTP id v10-20020a1709029a0a00b001497da0af27mr39163668plp.49.1642699095082; Thu, 20 Jan 2022 09:18:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642699095; cv=none; d=google.com; s=arc-20160816; b=GGsfS2gc6KBEb4OyWVTDcEqSr1JgNJrfZVNrzFkKDL1t+q25EnmGgGOVtLl/9NubAn M2X18KtjY280Tbz7iSTLwfw6rCw4tF/Hj2vSAMGtrWqd2yvPeuWc04Sj5phskmKksFaK HVS76e8pjTqVOYD+Xur7jB6VYoQhg8HTT7wMNNj6U+KMrdLZlsrY3ZF2sjAlzKAl01AZ zbYmZDFSLbE5sMAmlfB1yW4JFUKU3Zn2ERGQxWO3jsMmLNkmDpCCKfj7EKZrS9n8nOLB RcoQiV10wJR/I5CGHc3xJV6N6BRvdX0tNYb+bapnJRK/kxx6T5lBitHvTL35sh7anhc9 2uHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=wp6HFxmyH+W1ub29ho80GpkYopfq9hva3FLC/4l8FAI=; b=PAMlMlyDgN8Imrg6iJ8FqZVYfVMKJslE0tLOlK9FrJJbcXZhgBq2hmzxpRmnaykuQg Ka2nNX8VWb18GdCYTRphrp+HlD2Y8z0X3O+K01gHLsGLxWJuy4J6uCxCCfOZcoYcJoIA w48tXtn3XZqlbFgh9fXGt/nAI35Q3UFlr/e2HzbAdz2dnVToI19IKphydDybjgD/iuDN bjmBpgP9Z4812zVwbhia9ShoJ2D3l9z08kKxXEs4yITTCqLbDQ3x0LahyJadqTT0JabL nR1kMfXcKOYqp3AJyaKQ9iKAnemaS6JlZJKwDkzwKSJO1LFDtJ5set/k35hQK4fkCtiK rFvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Y3ZbxNIs; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v17si4191084pfu.177.2022.01.20.09.18.00; Thu, 20 Jan 2022 09:18:15 -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=@gmail.com header.s=20210112 header.b=Y3ZbxNIs; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347686AbiARQNn (ORCPT + 99 others); Tue, 18 Jan 2022 11:13:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347490AbiARQLo (ORCPT ); Tue, 18 Jan 2022 11:11:44 -0500 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83A9FC06177E; Tue, 18 Jan 2022 08:11:11 -0800 (PST) Received: by mail-ot1-x333.google.com with SMTP id i7-20020a9d68c7000000b0059396529af8so18143522oto.4; Tue, 18 Jan 2022 08:11:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=wp6HFxmyH+W1ub29ho80GpkYopfq9hva3FLC/4l8FAI=; b=Y3ZbxNIsunSk1AHrzp1Mc9h6nqKhsJ4J6fsnt8ib777zelc+5dHRP++k37sepQ8wJp wcMn84UMvEeeFV28PCgjriUw6EUKM9RjNunjfnUhBCEF5QcYwoEGkm3s3Y6BA2+HRRl6 xyL1BnRZHYUKduCq4THIUZrB7F1xLlikdweabk4NBkzMQ1TJW7afz1VEW1WG0IYLexkg kHeavdjYpdte4ZnZBWIj0gXOZAn2wKLgESfPlKBSM1iA+/F99hFH8oqjLyfHkLue+fqa nwcOCg5DEv6X/lH2Cfoyg6tDqmVBM6QuJ+zyBp3yxIoC5qh9OErg4qjPApfU9Ymr5yRv HeGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=wp6HFxmyH+W1ub29ho80GpkYopfq9hva3FLC/4l8FAI=; b=u80AqGi8WiXlm6lUwp6w8m4Vd4QEVLO52eDAgcGL9Cg9IdghuIKS7AcnqiaobqPds4 nq/oYc0DvTJSk4KxY/6HsjEBsy8XTjagb+11GNAoYwH3L+t+vEqLUm5x0Ti2BkL9pY/o N9/cbH9aJkzXrD1J5Un/vNH3NZR7pw9FRQi6K/vJu7+TPILvImkRety3whxRIHfZJfAi 5FFrrhMomFBPVcpeovv+4rADT+ymoXa+ekMMtMd1AnvY1ECack61JVyziy4celY4K41N WRmLzrQa6vU2YSmepbc5B53M+MWKhbO/CWhVKNqjAbs/1ruuxBJ9Y0p6Q0RG4jhQFrSz IVZg== X-Gm-Message-State: AOAM532/X69by2XBioWiIPVvQGnIqkxPyaKf7BLFP2x49USLc8oIlm+a BqGMAHJbzIx3j8Wkpm/3Olw= X-Received: by 2002:a9d:37a2:: with SMTP id x31mr20698547otb.51.1642522270894; Tue, 18 Jan 2022 08:11:10 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id s14sm2403902otd.0.2022.01.18.08.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 08:11:10 -0800 (PST) Sender: Guenter Roeck Date: Tue, 18 Jan 2022 08:11:08 -0800 From: Guenter Roeck To: Marcello Sylvester Bauer Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Patrick Rudolph , Jean Delvare , Liam Girdwood , Mark Brown Subject: Re: [PATCH v2 2/4] hwmon: (max6639) Add regulator support Message-ID: <20220118161108.GA4115171@roeck-us.net> References: <4c644f279f6e205d3c9540a4ad35825e4d5f2da1.1642413668.git.sylv@sylv.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4c644f279f6e205d3c9540a4ad35825e4d5f2da1.1642413668.git.sylv@sylv.io> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 17, 2022 at 11:40:24AM +0100, Marcello Sylvester Bauer wrote: > 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); This could be -EPROBE_DEFER. I do not think that warrants an error message. > + 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 */ >