Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp147249lqh; Thu, 30 May 2024 17:47:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWl/2gb7LFGAyWTwmN7AJDlKYEiaojks73j3rOgomrOSoFdzedujyPpL0uj/Du5JxYON1KhUKWVFiUmBQup97kMygoVIYjJr7Jxr6HiFA== X-Google-Smtp-Source: AGHT+IHTZUQ1xk0F7RPPsUijcxDft/pm11D93WG/9hVGg7NzQ9txHIfLVo8IsdZndDm6IMa0SFXF X-Received: by 2002:a05:6830:1d84:b0:6ef:9506:ca2c with SMTP id 46e09a7af769-6f911f3126fmr414954a34.10.1717116452564; Thu, 30 May 2024 17:47:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717116452; cv=pass; d=google.com; s=arc-20160816; b=h2IZfDS852nhuZUpHg5m3p3VaGhciLhAiKYefi/LFKyMXEQb/0Ol5gaJpXYIIWrn9V 4rGhTLvoviZiw+cOD6GvsaUYq6Db7caWxaCbHktYgAVtuL2gOQ5Tp5f5tIwlzu9RxLjZ nu2cbsFmpjrgqFc0KGZ4XozpjIHz4xoxdfOzpOdxOjmdsgKI43HWacKSm7xfYk66+Ind 21gTQYY2WeYELNb4s58K3ZpSHBt1r3IZ9rdXRuPS99VqkWYFohZ/ie3ZVxYhlFguySVl MhStraJ4xttQIl0Iqv06kZxvCs3DqwlLbtdQ9N9Cq8cAgcVg9IgbURImC8v++g3t8lTI teRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=K5IL9WVaL+MRAvoehS1X61pU+AcxiSLj6714R/XAATo=; fh=64fdlywoXs0X7wr/mPvLPT9IctYDckXfJ7HXUh1Qi08=; b=Oy3k6pxxMjzhk0dHdo6WEtq6SRFZwXD3wO2NK1O8vXNUUvJgpHweerDHz5yk+LX/9S z8lmiibgVBaK6JJjl8rlueoZQAJohlZ4jgMSg2hACEadu5dsDtVKcyXqeOfWz58NZDJO D24WegYK2m8g5Oig2/tL81Vr5PhQJgM1DW9rMSiXBx9/oGyqNHQChViY+CAZ4pP4nznM OSe9IJsaC31rHdbxcQTEOSw2zfnTaSYmCNyby2BXI5aoLZofJgsnOrZ9gPWS7nRFFlUd jA2SPwlq7R44UyTrM3bQmoDJxHfhangaZrjpUzQOw0QtcN9gTu0WceCChC1c6EXh5FJU cd4Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VVNSH0L5; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-196101-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196101-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c35c181d6esi512585a12.668.2024.05.30.17.47.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 17:47:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-196101-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VVNSH0L5; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-196101-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196101-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E0CC1287897 for ; Fri, 31 May 2024 00:47:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 76080EAC0; Fri, 31 May 2024 00:47:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VVNSH0L5" Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB5FD4C9D; Fri, 31 May 2024 00:47:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717116425; cv=none; b=p7YTQ3jWL47OMWElgfQ0ygXPGZ/sjIj8QtqNTfKbwMZZFaEIXiGmQJPr+UraC0sjKgMSB/vuJBUNR6WmYflT4b2hf8vB0TJPiyvSZMSNU3y9AN3CHySWcAFn1qPj8g9384EPN8iDV69U7mg1ulyrURxsGL4//0ta9dG6K4CuLzI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717116425; c=relaxed/simple; bh=DYn2aSysUxjoJXWq3Kj3csOOiFlPojw8oWHmMl9rv6w=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GwsRoAKR/cd/3mqSDuD+gEfSEeQzIuwGqnsjBDrQSaD61eyQnfQNxn1vcwUOa2RVGKxl/Rs2yUw0Q9TZkLvf8xm05A9IFfE8Ny2BPEPDu3H+BDA3AUG33jXcK0d4BpIiqb6eQq/saORx36yHE0JDlU+bKwZAZaeyckVUzItKU84= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VVNSH0L5; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-35dd0c06577so397562f8f.2; Thu, 30 May 2024 17:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717116422; x=1717721222; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=K5IL9WVaL+MRAvoehS1X61pU+AcxiSLj6714R/XAATo=; b=VVNSH0L5vCl4nsknyOLIb2GamWuASx0CwkvOuoQDDJ+z42qaP8RKzJN/Y8WO0XKe0x KDVYKcw08lDdmMN4ln3rvMRN2g48bHhUipPrXkp/ZqS+mWkvpfUwPvU408mlVDMQ2YL4 uYxGYKMVGo9R/jAbOhXX4Jg+8NC6dOu9SlgmyW7LPM0KWqk+XnSV4wqE92dpKBhbUj13 8LMdmHIYAsgUhV3pG1pL3q5cHWG/7QZiVlfEtV6shnyjYBs2gHXRoRolXgf8xVQm5iQK I0g/2/4hIYJht9Zr38xEyGBaBfMN13UZVfC3iMK8LRfwD76OFIQC6AP22nr4zV6J6yjd 7F4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717116422; x=1717721222; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K5IL9WVaL+MRAvoehS1X61pU+AcxiSLj6714R/XAATo=; b=hirggiyuGgnJLVZ2FFV+5K94wmTodrCz8dSHzl+w/6l9NLJa7U/dDD84uNjT1Qbj48 shRGCxvOknGMXlIGLNyyTFUEzhv0PaeP1kyuj7bj33rN3J5Yzl8xAVwk8oqyFzFcGKTb V2Ypqw+29YYIwi13wHti6E/n43DBnFxUZNu4G59vCZ0PyUaJJQfq79GrNYbVUS4Rb4nq eKykoM7KnEOqTrrKVmWiF87jLkjkYaHdmxOIxtbmNAMoVTkmCrWcgZAHJj8Jf5PL7Li1 Gmx3UB+1yBRx3tsAXBmCJppzQOj+rwlTAiHU7pgIAyuvv+q9P6roxP+g1H+Y07CSq/FH 2rlw== X-Forwarded-Encrypted: i=1; AJvYcCWb6fNbTAI+NOm04Qxb9fIBWq9hdvQxhIqQo7+deLWoJGDbz4bQdEIevwYB+YfexZxxdK2t3DcNjXaaaqdtJK2NCar9smHbSvAhQUSXknWqQluLLkajUZqzVyOvNw13TjAUBuDXjDp6lRAP95L7TI1wFyOlwll7Uo9k5BKejn0VaClpCn61 X-Gm-Message-State: AOJu0YwZcgu/lK/pMugNo9D8QKxmLfuVwDSNUbX859bYA2TwKKRTiqHy U2Npc247AnBPFQojnOpASVXr6SoB53U7cMIsUBaaGn8SSJFRXZB8 X-Received: by 2002:adf:fc4e:0:b0:354:e4e0:21dd with SMTP id ffacd0b85a97d-35e0f3162dcmr138784f8f.50.1717116421903; Thu, 30 May 2024 17:47:01 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-35dd04c0e84sm608486f8f.13.2024.05.30.17.47.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 17:47:01 -0700 (PDT) From: Christian Marangi To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] hwmon: g672: add support for g761 Date: Thu, 30 May 2024 23:16:52 +0200 Message-ID: <20240530211654.7946-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240530211654.7946-1-ansuelsmth@gmail.com> References: <20240530211654.7946-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add support for g761 PWM Fan Controller. The g761 is a copy of the g763 with the only difference of supporting and internal clock. The internal clock is used if no clocks property is defined in device node and in such case the required bit is enabled and clock handling is skipped. The internal clock oscillator runs at 31KHz. Signed-off-by: Christian Marangi --- Changes v2: - Rework handling of internal clock drivers/hwmon/g762.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/g762.c b/drivers/hwmon/g762.c index af1228708e25..a00cf3245eec 100644 --- a/drivers/hwmon/g762.c +++ b/drivers/hwmon/g762.c @@ -69,6 +69,7 @@ enum g762_regs { #define G762_REG_FAN_CMD1_PWM_POLARITY 0x02 /* PWM polarity */ #define G762_REG_FAN_CMD1_PULSE_PER_REV 0x01 /* pulse per fan revolution */ +#define G761_REG_FAN_CMD2_FAN_CLOCK 0x20 /* choose internal clock*/ #define G762_REG_FAN_CMD2_GEAR_MODE_1 0x08 /* fan gear mode */ #define G762_REG_FAN_CMD2_GEAR_MODE_0 0x04 #define G762_REG_FAN_CMD2_FAN_STARTV_1 0x02 /* fan startup voltage */ @@ -115,6 +116,7 @@ enum g762_regs { struct g762_data { struct i2c_client *client; + bool internal_clock; struct clk *clk; /* update mutex */ @@ -566,6 +568,7 @@ static int do_set_fan_startv(struct device *dev, unsigned long val) #ifdef CONFIG_OF static const struct of_device_id g762_dt_match[] = { + { .compatible = "gmt,g761" }, { .compatible = "gmt,g762" }, { .compatible = "gmt,g763" }, { }, @@ -597,6 +600,21 @@ static int g762_of_clock_enable(struct i2c_client *client) if (!client->dev.of_node) return 0; + data = i2c_get_clientdata(client); + + /* + * Skip CLK detection and handling if we use internal clock. + * This is only valid for g761. + */ + data->internal_clock = of_device_is_compatible(client->dev.of_node, + "gmt,g761") && + !of_property_present(client->dev.of_node, + "clocks"); + if (data->internal_clock) { + do_set_clk_freq(&client->dev, 32768); + return 0; + } + clk = of_clk_get(client->dev.of_node, 0); if (IS_ERR(clk)) { dev_err(&client->dev, "failed to get clock\n"); @@ -616,7 +634,6 @@ static int g762_of_clock_enable(struct i2c_client *client) goto clk_unprep; } - data = i2c_get_clientdata(client); data->clk = clk; ret = devm_add_action(&client->dev, g762_of_clock_disable, data); @@ -1025,16 +1042,26 @@ ATTRIBUTE_GROUPS(g762); static inline int g762_fan_init(struct device *dev) { struct g762_data *data = g762_update_client(dev); + int ret; if (IS_ERR(data)) return PTR_ERR(data); + /* internal_clock can only be set with compatible g761 */ + if (data->internal_clock) + data->fan_cmd2 |= G761_REG_FAN_CMD2_FAN_CLOCK; + data->fan_cmd1 |= G762_REG_FAN_CMD1_DET_FAN_FAIL; data->fan_cmd1 |= G762_REG_FAN_CMD1_DET_FAN_OOC; data->valid = false; - return i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1, - data->fan_cmd1); + ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1, + data->fan_cmd1); + if (ret) + return ret; + + return i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD2, + data->fan_cmd2); } static int g762_probe(struct i2c_client *client) -- 2.43.0