From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 44C392FB0B3 for ; Tue, 25 Nov 2025 21:20:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764105623; cv=none; b=J2LDTiZgAS9suVCJrnTeeLtvgSLPVqMYYmgTapIu2YKeFBKP+44jHMYnn58ChC128BJBO2FPTmNap726ft0ayqC8Dmtfj3/4uAbCxPlXVzzHGnyqJ5bTRnew+3ymMWecb0msQucwhxxJrElAhn9MdBymhsraVzwaZ/L3PGhPVQw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764105623; c=relaxed/simple; bh=XJW1618AeSh8p0FvIT2L/UOsZV0GPeMhh84mZiz4ecg=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=KODrG6YzuIueO/epC8DRNJam7NtKhKNTCUwF//8i43ecwrJh7A9TVbGRkiCz/ehTiD7zc70JlL8Vt33RfopjO5VVMDKeH6d/liT2xSy3Sdt3dlqO0r7V4MjwVKl8w1T+PWuAhQTMu2y9SQalp1FNmaYwyVS6jTXNsga7q7UUIlw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=za5VreFB; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="za5VreFB" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-47790b080e4so31916165e9.3 for ; Tue, 25 Nov 2025 13:20:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1764105619; x=1764710419; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=lgeyODjjwWGv2LqYAD1M4y/a4gMxr9izn+TjHICf2QA=; b=za5VreFBx7A+NbX4bmySWiHkFMr/Wt8BGG8fEda+vmHv+mYkBKmxcEVqvh2ruD3TmW ZtI7peF2UKpGSXQGwWKI9RGIpQBbwlgxHTP8Ma9zhknnPZiFGcsZKHoCIOTPVfrGQSFZ reX9WXpzyOM6avdYBl6JdWvHSimhr3MXrZ74Hs02uGn+xPU/yP2RzjJWi1PqpZ2jTKEQ vVlY8wXjWI08MOJNgeByAfSgE5Dw7XMjXBBLA8aO6PvcEjtt5kQhRwG+uR4oWiKfcFT7 ti397o+KHceuPRmATwrv4cDMQSLmbGUC6wI8vzDhXtLTsTqxJmTpotG0BnXpxHBEkHmV g/rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764105619; x=1764710419; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lgeyODjjwWGv2LqYAD1M4y/a4gMxr9izn+TjHICf2QA=; b=dUfCxzmLt347KghOq/L2dDOPo4/7QLIrHG5Xtt3vo57/nguBIThrM2WGka+P7/QZJJ mA8xFoLqE97ssu/tp4oX3qKsN/2CJxzYAhd4asd+CxTbMGUxp5jdytacRcgnCSNDi/I1 qVh385A6VoB7VOk+9vCCLoeefzH8ZFIE3zMUnXEQnUlac2NMKS/b0d0Ykdph4X6kazpz UaZySLxCjxvVdidG9wr7CwiQ/CmdP8Oyz5xr/ZWbtpl4Cth9To3xOpPvZGqGktEgV2a5 1l9cx9uOQVQAIw4yB2wSCSfiNH1BrhbXstivOerxMod1OmjmmEOS4OVlCqoGHuVLN6CH Y+BQ== X-Forwarded-Encrypted: i=1; AJvYcCW7oENqHk2OHQ73WULdIj8LqYA9Ghzzwaff4xeo34T+SqmHLZci9guCWkOJXrCuM0br7HzcHVMjTxP+4o8=@vger.kernel.org X-Gm-Message-State: AOJu0YxzyfaiaAftYnb1kd4Yhdpdm8OuF2qBajYe/7lKvrmVdu0zBNOz tjJuWeG5OhvbqAqWkS3EVNLJPaKhgaTZSE7MjtF+a38thnm1tCc4XvNt4JISLRfwMNE= X-Gm-Gg: ASbGncs7X3Y6QUC8zZ5lzbRTUjcYmUjcx4ItN8x9/vyxQZrevW4Hq0OA4WGlIv3Zux0 a0Pj7BbpISRm8KZIS47Ks6le1i2bgW9KTEF5w7n8RxHKpAt+1bFOXbD+XkZApgRiNKcktBTGdxN Jj2rcAMDEvjzexV59hKPqypxM99dYhfeU77js9bAfXiCVAG/mQSC1/XrbwAKs245bF66w+gFLJi 5cWLTPS/sXcFA/wHtmQ+ZppJmiC4xR74mMvSM02krGRENXGiOT9tOoSJRoNo2hpitvf+/SvpEVU WGPTueg5CRSVaBaagtatizRpurs6J+2gJpwcCmksrf0jOUXy9FbBcgAal3iE5o6+tBNYepny02p A1PrY7NHyqwebeEy1nAQnPjwtwPRxFAZjhrN7CDSkSgJWxWBL/rbpTpyIBZR0kXvrYZvTbvYe5c ZltXX3HLgkXHY4j5aicFPtSk21B6QA/Lf9Rd90Vi+tJH5W0+GmlXUQWVv8lxW11G+NZA== X-Google-Smtp-Source: AGHT+IFdWHejJYMhzJuTuSVlm6rwhlp+m0ckCKintINuBoyb0kMJ5cumF+USbjfNXBcVyPOJkM1Z+A== X-Received: by 2002:a05:600c:1f94:b0:471:1765:839c with SMTP id 5b1f17b1804b1-477c1117949mr131150635e9.20.1764105619440; Tue, 25 Nov 2025 13:20:19 -0800 (PST) Received: from ?IPV6:2a05:6e02:1041:c10:1d9d:2362:4539:c68d? ([2a05:6e02:1041:c10:1d9d:2362:4539:c68d]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-4790ab8bb21sm9790865e9.0.2025.11.25.13.20.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Nov 2025 13:20:18 -0800 (PST) Message-ID: Date: Tue, 25 Nov 2025 22:20:17 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 3/5] thermal/drivers: airoha: Generalize get_thermal_ADC and set_mux function To: Christian Marangi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Rafael J. Wysocki" , Zhang Rui , Lukasz Luba , Lorenzo Bianconi , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org References: <20251106225929.1778398-1-ansuelsmth@gmail.com> <20251106225929.1778398-4-ansuelsmth@gmail.com> Content-Language: en-US From: Daniel Lezcano In-Reply-To: <20251106225929.1778398-4-ansuelsmth@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/6/25 23:59, Christian Marangi wrote: > In preparation for support of Airoha AN7583, generalize > get_thermal_ADC() and set_thermal_mux() with the use of reg_field API. > > This is to account the same logic between the current supported SoC and > the new one but with different register address. > > While at it also further improve some comments and move sleep inside the > set_thermal_mux function. > > Signed-off-by: Christian Marangi > --- > drivers/thermal/airoha_thermal.c | 54 +++++++++++++++++++++++++------- > 1 file changed, 42 insertions(+), 12 deletions(-) > > diff --git a/drivers/thermal/airoha_thermal.c b/drivers/thermal/airoha_thermal.c > index 864a01fd8fd8..a062922cb116 100644 > --- a/drivers/thermal/airoha_thermal.c > +++ b/drivers/thermal/airoha_thermal.c > @@ -193,9 +193,18 @@ > > #define AIROHA_MAX_SAMPLES 6 > > +enum airoha_thermal_chip_scu_field { > + AIROHA_THERMAL_DOUT_TADC, > + AIROHA_THERMAL_MUX_TADC, > + > + /* keep last */ > + AIROHA_THERMAL_FIELD_MAX, nit: if last, no comma :) nit2: naming is not consistent > +}; > + > struct airoha_thermal_priv { > struct regmap *map; > struct regmap *chip_scu; > + struct regmap_field *chip_scu_fields[AIROHA_THERMAL_FIELD_MAX]; > struct resource scu_adc_res; > > u32 pllrg_protect; > @@ -219,22 +228,29 @@ static int airoha_get_thermal_ADC(struct airoha_thermal_priv *priv) > { > u32 val; > > - regmap_read(priv->chip_scu, EN7581_DOUT_TADC, &val); > - return FIELD_GET(EN7581_DOUT_TADC_MASK, val); > + regmap_field_read(priv->chip_scu_fields[AIROHA_THERMAL_DOUT_TADC], > + &val); > + return val; > } > > -static void airoha_init_thermal_ADC_mode(struct airoha_thermal_priv *priv) > +static void airoha_set_thermal_mux(struct airoha_thermal_priv *priv, > + int tdac_idx) > { > - u32 adc_mux, pllrg; > + u32 pllrg; > > /* Save PLLRG current value */ > regmap_read(priv->chip_scu, EN7581_PLLRG_PROTECT, &pllrg); > > - /* Give access to thermal regs */ > + /* Give access to Thermal regs */ > regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, > priv->pllrg_protect); > - adc_mux = FIELD_PREP(EN7581_MUX_TADC, EN7581_SCU_THERMAL_MUX_DIODE1); > - regmap_write(priv->chip_scu, EN7581_PWD_TADC, adc_mux); > + > + /* Configure Thermal ADC mux to tdac_idx */ > + regmap_field_write(priv->chip_scu_fields[AIROHA_THERMAL_MUX_TADC], > + tdac_idx); > + > + /* Sleep 10 ms for Thermal ADC to enable */ > + usleep_range(10 * USEC_PER_MSEC, 11 * USEC_PER_MSEC); 10ms ? It is a lot no ? > /* Restore PLLRG value on exit */ > regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, pllrg); > @@ -343,10 +359,8 @@ static void en7581_thermal_setup_adc_val(struct device *dev, > { > u32 efuse_calib_info, cpu_sensor; > > - /* Setup thermal sensor to ADC mode and setup the mux to DIODE1 */ > - airoha_init_thermal_ADC_mode(priv); > - /* sleep 10 ms for ADC to enable */ > - usleep_range(10 * USEC_PER_MSEC, 11 * USEC_PER_MSEC); > + /* Setup Thermal Sensor to ADC mode and setup the mux to DIODE1 */ > + airoha_set_thermal_mux(priv, EN7581_SCU_THERMAL_MUX_DIODE1); > > regmap_read(priv->map, EN7581_EFUSE_TEMP_OFFSET_REG, &efuse_calib_info); > if (efuse_calib_info) { > @@ -429,13 +443,18 @@ static const struct regmap_config en7581_thermal_regmap_config = { > .val_bits = 32, > }; > > +static const struct reg_field en7581_chip_scu_fields[AIROHA_THERMAL_FIELD_MAX] = { > + [AIROHA_THERMAL_DOUT_TADC] = REG_FIELD(EN7581_DOUT_TADC, 0, 15), > + [AIROHA_THERMAL_MUX_TADC] = REG_FIELD(EN7581_PWD_TADC, 1, 3), > +}; > + > static int en7581_thermal_probe(struct platform_device *pdev, > struct airoha_thermal_priv *priv) > { > struct device_node *chip_scu_np; > struct device *dev = &pdev->dev; > void __iomem *base; > - int irq, ret; > + int i, irq, ret; > > base = devm_platform_ioremap_resource(pdev, 0); > if (IS_ERR(base)) > @@ -454,6 +473,17 @@ static int en7581_thermal_probe(struct platform_device *pdev, > if (IS_ERR(priv->chip_scu)) > return PTR_ERR(priv->chip_scu); > > + for (i = 0; i < AIROHA_THERMAL_FIELD_MAX; i++) { > + struct regmap_field *field; > + > + field = devm_regmap_field_alloc(dev, priv->chip_scu, > + en7581_chip_scu_fields[i]); > + if (IS_ERR(field)) > + return PTR_ERR(field); > + > + priv->chip_scu_fields[i] = field; > + } > + > of_address_to_resource(chip_scu_np, 0, &priv->scu_adc_res); > of_node_put(chip_scu_np); > -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog