From nobody Sun Dec 14 19:24:22 2025 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 4942D296D10; Fri, 23 May 2025 18:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748025015; cv=none; b=Bbp0LB9PqR9WqS+ImqtXQ68HRvOk8IBHulJNmL3nDZh2Mcj8h7/Etg2YADWYjoYJaAPF2eq246EGY6Enkm0PfxK6gA+Lg9HIhHdRHj2CwWuF3tVvIBlVqTK41w0nLvQt0Vg/gL2f4eEbcS74vqibEjYmqM0WkH6cwM2knRfZX+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748025015; c=relaxed/simple; bh=NFoge0TAAOxil832I375a1uGhWyZY9zmeg3YifnMATo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hYEf8WKPOttI8wm6QfG/THLBeewWHJl5cO04t9c7yefqAy3aElq5SpV3HNxMMY7nXCIeI28f+ayrgnk0k3V1KyGS8h74bbjFpoLCQPS2DswRCODmlr2rsSFh7dBSsaqd4DUSe0SyfLOD9G3idy8uVXG/vD94us9hMF9N9nVypLM= 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=WbqTBxIC; arc=none smtp.client-ip=209.85.128.50 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WbqTBxIC" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-442ec3ce724so769915e9.0; Fri, 23 May 2025 11:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748025011; x=1748629811; 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=3KjsrRqkqh+4w7zYTnKXGm12Hu5UeqaTDd57FU942h0=; b=WbqTBxICrv9SpJbwWC5En1bJxZE57+Sca+M5+FzbgnFptPFjnFoBHoPtKljRMXAoLc UeqpWtW5oZbC0GVBNCOnIytiFPyHoLMJB0cTUnQXWUX7jWgnpqfK/jofQ1vq26d+Vutt YLv2988Fa8MWrhefH39BSt9h+pkVEbe5KjTyW70E6MuwU+XOf7M27TOdDeXr+Ud9D/Kn 5E9BxB17Wu6R/uUuucSGuy/QXaGi0HQtY2yFovWY+lpyA5e98aqMHCyArtEUYQn6yCCw tcn/9+HzkcC7KtpCcdka7l74wlb9oKbQSrge4rvvT3OVgv1sl6ITjAVGTNwr9uiy2qDK TN9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748025011; x=1748629811; 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=3KjsrRqkqh+4w7zYTnKXGm12Hu5UeqaTDd57FU942h0=; b=vzUwrpyTXtkQ+V9hJksHRsg0NVFKDsIpO/Nq1CRdy77Pf5JmT2ZXua5Rm+Ps1d0d4Z yDsVpy+t2bzAWHM3hd9V/wHRSwoj3T1LCLaDATFGp2req4U0+st/I2HtvDj5GoFNAcsH wnTI96mQwoI4Eapt7RpAR2jMDA5h5F+UlAvFkWLQFnPeBFgLs62IRmzTxeI3fTR75Le7 ANUmgMsIzpZ/amQDsD7zOSGh4p/6BTIFvvNvDNL0rgNq8coI9Krhj0p4U/mN38adtd7X jICDEDwU8cRUC7KdgZfaq5OgRiQh/c/ER4v5b9IUtslUSqNBvcDgirLGmWI6GiOsaHZv ITqg== X-Forwarded-Encrypted: i=1; AJvYcCW+Gj+2n5mB4ATrPs8UmFZ1j952A4HHNPMIycg2Ay6nR+SPEBvKncW7luNkqxvuRK5YRp7yL1Va3cdErA9Q@vger.kernel.org, AJvYcCW/fdBkW9k2agBmYkTRJI8jmMo3+jk/Xxf1234aA9OiDPvFJv5jkhHIyD3eEqaK4+ESG1SZaNVd2ig=@vger.kernel.org, AJvYcCWDrj1iBGKaSRpWjJCzQU/045aHy5gOkKA4l2mDagWQD9MHOkZhFeZJ1cnscaZtep1VSxgWOkG+Yiki@vger.kernel.org X-Gm-Message-State: AOJu0Yy4zoD1uG2q7hPhqeiwaMZGjM1Tvw/EyVDOsr/ROOzLngcwdm4F ORw9BnFG+P58A0j22OOR26Unq9lyv5HZnA1OEHpQUCf+02C0BdhUNy83c0DvmA== X-Gm-Gg: ASbGnctfufcIyCfgCnc4oLx8QB6EIqatMtf7E187mV2pHw8d2AVsZYjm5OLgq5BSq9v B42hMycZJPyG99Y9xnaV4cRxT+HH5SoE7dwUmDWLGeru8WwMtGspnVRHSph5tQGEByuqjlFe1t3 cSt/DFuYeV8VhSLKWhPUp9Rbm0O6Qe5WB8gePYFqsGe0g+3IjGEZOJR8u5E+GWJ/aopQhnRqBeW u/3I7cufrDGvuFS5tMUEkD6LHorqtvEgcIFFRuRjWmArr5zqBGg7ox2r6n07qAoyOA9L2KfIILn HTcvRZhnWSMrQ2SN64Sq6ybotoyaRbGs6e2SSPnF/qdZcLCbhjydapCL/92GKOEtxmkjHXFBBAS ZP2v2pys+177WcOFlVjJ/ X-Google-Smtp-Source: AGHT+IFo8PuFdgk+w6NWsh1CLxn0FAS77nlcKMO0nb/pSdkwAjMTSI07KjpWz5s3MTWiLdaw5CHpPg== X-Received: by 2002:a05:6000:1ac9:b0:3a3:7077:ab99 with SMTP id ffacd0b85a97d-3a4cb48445amr375282f8f.45.1748025011162; Fri, 23 May 2025 11:30:11 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a35ca4d2d1sm28180695f8f.19.2025.05.23.11.30.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 May 2025 11:30:10 -0700 (PDT) From: Christian Marangi To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] thermal: airoha: Convert to regmap API Date: Fri, 23 May 2025 20:29:29 +0200 Message-ID: <20250523182939.30489-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250523182939.30489-1-ansuelsmth@gmail.com> References: <20250523182939.30489-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable In preparation for support of Airoha AN7583, convert the driver to regmap API. This is needed as Airoha AN7583 will be based on syscon regmap. Signed-off-by: Christian Marangi --- drivers/thermal/airoha_thermal.c | 72 +++++++++++++++++++------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/drivers/thermal/airoha_thermal.c b/drivers/thermal/airoha_ther= mal.c index 9a7a702a17de..04bda890dbb1 100644 --- a/drivers/thermal/airoha_thermal.c +++ b/drivers/thermal/airoha_thermal.c @@ -194,7 +194,7 @@ #define AIROHA_MAX_SAMPLES 6 =20 struct airoha_thermal_priv { - void __iomem *base; + struct regmap *map; struct regmap *chip_scu; struct resource scu_adc_res; =20 @@ -265,8 +265,8 @@ static int airoha_thermal_set_trips(struct thermal_zone= _device *tz, int low, RAW_TO_TEMP(priv, FIELD_MAX(EN7581_DOUT_TADC_MASK))); =20 /* We offset the high temp of 1=C2=B0C to trigger correct event */ - writel(TEMP_TO_RAW(priv, high) >> 4, - priv->base + EN7581_TEMPOFFSETH); + regmap_write(priv->map, EN7581_TEMPOFFSETH, + TEMP_TO_RAW(priv, high) >> 4); =20 enable_monitor =3D true; } @@ -277,15 +277,15 @@ static int airoha_thermal_set_trips(struct thermal_zo= ne_device *tz, int low, RAW_TO_TEMP(priv, FIELD_MAX(EN7581_DOUT_TADC_MASK))); =20 /* We offset the low temp of 1=C2=B0C to trigger correct event */ - writel(TEMP_TO_RAW(priv, low) >> 4, - priv->base + EN7581_TEMPOFFSETL); + regmap_write(priv->map, EN7581_TEMPOFFSETL, + TEMP_TO_RAW(priv, high) >> 4); =20 enable_monitor =3D true; } =20 /* Enable sensor 0 monitor after trip are set */ if (enable_monitor) - writel(EN7581_SENSE0_EN, priv->base + EN7581_TEMPMONCTL0); + regmap_write(priv->map, EN7581_TEMPMONCTL0, EN7581_SENSE0_EN); =20 return 0; } @@ -302,7 +302,7 @@ static irqreturn_t airoha_thermal_irq(int irq, void *da= ta) bool update =3D false; u32 status; =20 - status =3D readl(priv->base + EN7581_TEMPMONINTSTS); + regmap_read(priv->map, EN7581_TEMPMONINTSTS, &status); switch (status & (EN7581_HOFSINTSTS0 | EN7581_LOFSINTSTS0)) { case EN7581_HOFSINTSTS0: event =3D THERMAL_TRIP_VIOLATED; @@ -318,7 +318,7 @@ static irqreturn_t airoha_thermal_irq(int irq, void *da= ta) } =20 /* Reset Interrupt */ - writel(status, priv->base + EN7581_TEMPMONINTSTS); + regmap_write(priv->map, EN7581_TEMPMONINTSTS, status); =20 if (update) thermal_zone_device_update(priv->tz, event); @@ -336,11 +336,11 @@ static void airoha_thermal_setup_adc_val(struct devic= e *dev, /* sleep 10 ms for ADC to enable */ usleep_range(10 * USEC_PER_MSEC, 11 * USEC_PER_MSEC); =20 - efuse_calib_info =3D readl(priv->base + EN7581_EFUSE_TEMP_OFFSET_REG); + regmap_read(priv->map, EN7581_EFUSE_TEMP_OFFSET_REG, &efuse_calib_info); if (efuse_calib_info) { priv->default_offset =3D FIELD_GET(EN7581_EFUSE_TEMP_OFFSET, efuse_calib= _info); /* Different slope are applied if the sensor is used for CPU or for pack= age */ - cpu_sensor =3D readl(priv->base + EN7581_EFUSE_TEMP_CPU_SENSOR_REG); + regmap_read(priv->map, EN7581_EFUSE_TEMP_CPU_SENSOR_REG, &cpu_sensor); if (cpu_sensor) { priv->default_slope =3D EN7581_SLOPE_X100_DIO_DEFAULT; priv->init_temp =3D EN7581_INIT_TEMP_FTK_X10; @@ -359,8 +359,8 @@ static void airoha_thermal_setup_adc_val(struct device = *dev, static void airoha_thermal_setup_monitor(struct airoha_thermal_priv *priv) { /* Set measure mode */ - writel(FIELD_PREP(EN7581_MSRCTL0, EN7581_MSRCTL_6SAMPLE_MAX_MIX_AVG4), - priv->base + EN7581_TEMPMSRCTL0); + regmap_write(priv->map, EN7581_TEMPMSRCTL0, + FIELD_PREP(EN7581_MSRCTL0, EN7581_MSRCTL_6SAMPLE_MAX_MIX_AVG4)); =20 /* * Configure ADC valid reading addr @@ -375,15 +375,15 @@ static void airoha_thermal_setup_monitor(struct airoh= a_thermal_priv *priv) * We set valid instead of volt as we don't enable valid/volt * split reading and AHB read valid addr in such case. */ - writel(priv->scu_adc_res.start + EN7581_DOUT_TADC, - priv->base + EN7581_TEMPADCVALIDADDR); + regmap_write(priv->map, EN7581_TEMPADCVALIDADDR, + priv->scu_adc_res.start + EN7581_DOUT_TADC); =20 /* * Configure valid bit on a fake value of bit 16. The ADC outputs * max of 2 bytes for voltage. */ - writel(FIELD_PREP(EN7581_ADV_RD_VALID_POS, 16), - priv->base + EN7581_TEMPADCVALIDMASK); + regmap_write(priv->map, EN7581_TEMPADCVALIDMASK, + FIELD_PREP(EN7581_ADV_RD_VALID_POS, 16)); =20 /* * AHB supports max 12 bytes for ADC voltage. Shift the read @@ -391,40 +391,52 @@ static void airoha_thermal_setup_monitor(struct airoh= a_thermal_priv *priv) * in the order of half a =C2=B0C and is acceptable in the context * of triggering interrupt in critical condition. */ - writel(FIELD_PREP(EN7581_ADC_VOLTAGE_SHIFT, 4), - priv->base + EN7581_TEMPADCVOLTAGESHIFT); + regmap_write(priv->map, EN7581_TEMPADCVOLTAGESHIFT, + FIELD_PREP(EN7581_ADC_VOLTAGE_SHIFT, 4)); =20 /* BUS clock is 300MHz counting unit is 3 * 68.64 * 256 =3D 52.715us */ - writel(FIELD_PREP(EN7581_PERIOD_UNIT, 3), - priv->base + EN7581_TEMPMONCTL1); + regmap_write(priv->map, EN7581_TEMPMONCTL1, + FIELD_PREP(EN7581_PERIOD_UNIT, 3)); =20 /* * filt interval is 1 * 52.715us =3D 52.715us, * sen interval is 379 * 52.715us =3D 19.97ms */ - writel(FIELD_PREP(EN7581_FILT_INTERVAL, 1) | - FIELD_PREP(EN7581_FILT_INTERVAL, 379), - priv->base + EN7581_TEMPMONCTL2); + regmap_write(priv->map, EN7581_TEMPMONCTL2, + FIELD_PREP(EN7581_FILT_INTERVAL, 1) | + FIELD_PREP(EN7581_FILT_INTERVAL, 379)); =20 /* AHB poll is set to 146 * 68.64 =3D 10.02us */ - writel(FIELD_PREP(EN7581_ADC_POLL_INTVL, 146), - priv->base + EN7581_TEMPAHBPOLL); + regmap_write(priv->map, EN7581_TEMPAHBPOLL, + FIELD_PREP(EN7581_ADC_POLL_INTVL, 146)); } =20 +static const struct regmap_config airoha_thermal_regmap_config =3D { + .reg_bits =3D 32, + .reg_stride =3D 4, + .val_bits =3D 32, +}; + static int airoha_thermal_probe(struct platform_device *pdev) { struct airoha_thermal_priv *priv; struct device_node *chip_scu_np; struct device *dev =3D &pdev->dev; + void __iomem *base; int irq, ret; =20 priv =3D devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; =20 - priv->base =3D devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(priv->base)) - return PTR_ERR(priv->base); + base =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base)) + return PTR_ERR(base); + + priv->map =3D devm_regmap_init_mmio(dev, base, + &airoha_thermal_regmap_config); + if (IS_ERR(priv->map)) + return PTR_ERR(priv->map); =20 chip_scu_np =3D of_parse_phandle(dev->of_node, "airoha,chip-scu", 0); if (!chip_scu_np) @@ -462,8 +474,8 @@ static int airoha_thermal_probe(struct platform_device = *pdev) platform_set_drvdata(pdev, priv); =20 /* Enable LOW and HIGH interrupt */ - writel(EN7581_HOFSINTEN0 | EN7581_LOFSINTEN0, - priv->base + EN7581_TEMPMONINT); + regmap_write(priv->map, EN7581_TEMPMONINT, + EN7581_HOFSINTEN0 | EN7581_LOFSINTEN0); =20 return 0; } --=20 2.48.1 From nobody Sun Dec 14 19:24:22 2025 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.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 31F8729A9F2; Fri, 23 May 2025 18:30:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748025016; cv=none; b=G9PD7FZyGIqR4KFJmIbA2G1EhjSF1GdUKdTHC2WHaUNwj7fK/S64Hi0loUH/zUO3GEJkCDOiC7ciIalRf6+3Sr4KUNcQrw1OStqOEE3UvPDEBcJFpL9USqTlobtS3nacIkMEdxzuQHkuV6ysKmwAwxQOrzO7SgddRnIPZEqEmUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748025016; c=relaxed/simple; bh=XA27u/VOEH9VoBWsiugWrpftUIiRrwvmykvq6UgMRpg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W2SxrlQvteSOvq+HOhIQouLdeeg4gBsB+FczsAyzraOUnWptmMGNa9KqfIzodxlWTUSEiup7R/Ue5nxBBZrlBXAX5nMgDCDMOpEsT3EshvESp99TqB4tzFTzC0f8ox85/50Sg/bfKHsRadZBK6NmvwT/+r0j+a08Itf0viHWMjE= 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=HVzGqJ5Y; arc=none smtp.client-ip=209.85.221.54 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HVzGqJ5Y" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3a37ed01aa0so169963f8f.2; Fri, 23 May 2025 11:30:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748025012; x=1748629812; 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=/vr7W9LI+qlsRFn4c9Ws/BXSMWXobP4FxVmqkbUjGpg=; b=HVzGqJ5YbUK+tpQf6nzC/U4/Cb0+RhX+vpBNTh/5zF4qnfwGe3oSe0vssUsyevgSos +6NyMP82aRrgjeglRk4k6wu06drJGZClvW8wMMdeLgiaRjSvMMUmB29f8er24NOtxov0 aip85uD+Uauo2lTGg767WG2JJnun6Y83zCKuD3t8WDoWDamARQdtIdqcXoONasARmI4C pXwtYQvOndKGJtkjt921IpruawCfFcQddtz/BMAzCVui9O7iI+wngufkmm/XIH8obFve arubhV5cRt0WFLIAoFNHWnjWuEWIgxIPZe2VbC9ud4o/4cqoJ5Trp06ZzzJQaPytX8NR N1bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748025012; x=1748629812; 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=/vr7W9LI+qlsRFn4c9Ws/BXSMWXobP4FxVmqkbUjGpg=; b=ECYEITZE/4s1wqLRUAtj0M9J7KBeEvnBCVAPH8XDbzoOSq9SFs3vBqm6+Gk8QSkMxW uAKQ6QZDW/fe8ptRDtCGAH34uyZbQds9VIayCeNwgf/xX7/YI+sqzbZjkNKiD+7tCx0F lHT6cBUJlL1tepVB+oKVo7mVx1tl3uka5eZlZ0isHmOpxYZg8WhTjOSN90HqbnMvqYzA 6in3sz2is2fErbizbAbqZF1evuSkuiwO/LdHgdus9CHJJVdsACQa/CllHfEgHal5Eze5 Qfw/dr/uAuUMTHeumySG6BrH/riG+fc/fglW8YIuVQdSTEbaA2HI0peOdA9c3fP2awdZ CXlQ== X-Forwarded-Encrypted: i=1; AJvYcCUbo4Z6NZyG8uVOVpQ63uDTL5HC1ZaS2JpgM2PCjcWCbdKrgtyCVWhn/XPqyRTN03kWkgUvCp8yC4UoLwfX@vger.kernel.org, AJvYcCUyycpKhfTlDpEz7GNUIKxDMIL224lNaqeVamlmd8F36MoF6pL7z102m7xeiLvSNya+NU70X/Ge0m4=@vger.kernel.org, AJvYcCVfKfZegArwYG3ydQZtB5OjcdqSJyce1SmoyauoS2Wp/Plenb+TJnxg/2vOyO0QqCPAl860vwSZFSpb@vger.kernel.org X-Gm-Message-State: AOJu0YynfWXJccKRU5BcN1Xgr32ipEIo9ZxEyReP7izhhd1gNLo1UJr3 zJDAVz1zqIMwBK6csuv52ch9FAvKuURCwlDSEsex+zxdZL5WvpdOsp7Z X-Gm-Gg: ASbGnct9XlOR5GgV7K8Pr+5DifMJoza9/oVK/ttfPhu0EnVxet1VZ/vY9i5BCTmCVzx 2kaKiqwjRwU5BtD1Cyjx7Bt7OCDb1bsaVxMPwJ0RvVsHFV2oudoHxywOJeBdgdM28TuSmIbh45f 3E2t3JBEjuSUklDr9xHXX+sQjv7jrriwupsRigeElwieepQ+NkXoqoOoDOE2kA//9YYMT2h8ZCu vQQQj+7YZKtOKfbXNRRObS3mP5Kpw/9lXr6v9fhSFdmZjV/KDbSOCzuu/lSBmuP3EJ4R9Uzv9gj djlbs9hbmH0bu1mJ7f3LqVNxxqrhQKBktMv3Vi9KJsEm9P3GFrFUA+JGQvIq0PT8Rr6ciQ5E+QP XpXbmLud74W2yG/E5WwLW X-Google-Smtp-Source: AGHT+IHTdDqy1RlQa0qSMaPoytM7r3Iiu2dONZ4cbSHo6s/eEXtNzmkE22JGoZfCCbSMaVbQf+6Imw== X-Received: by 2002:a05:6000:2512:b0:3a3:6a2b:ab25 with SMTP id ffacd0b85a97d-3a4cb4834c2mr369511f8f.45.1748025012278; Fri, 23 May 2025 11:30:12 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a35ca4d2d1sm28180695f8f.19.2025.05.23.11.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 May 2025 11:30:11 -0700 (PDT) From: Christian Marangi To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] thermal/drivers: airoha: Generalize probe function Date: Fri, 23 May 2025 20:29:30 +0200 Message-ID: <20250523182939.30489-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250523182939.30489-1-ansuelsmth@gmail.com> References: <20250523182939.30489-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: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for support of Airoha AN7583, generalize the probe function to address for the 2 SoC differece. Implement a match_data struct where it's possible to define a more specific probe and post_probe function and specific thermal ops and pllrg protect value. Signed-off-by: Christian Marangi --- drivers/thermal/airoha_thermal.c | 102 +++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 27 deletions(-) diff --git a/drivers/thermal/airoha_thermal.c b/drivers/thermal/airoha_ther= mal.c index 04bda890dbb1..9bfa59b97032 100644 --- a/drivers/thermal/airoha_thermal.c +++ b/drivers/thermal/airoha_thermal.c @@ -198,12 +198,23 @@ struct airoha_thermal_priv { struct regmap *chip_scu; struct resource scu_adc_res; =20 + u32 pllrg_protect; + struct thermal_zone_device *tz; int init_temp; int default_slope; int default_offset; }; =20 +struct airoha_thermal_soc_data { + u32 pllrg_protect; + + const struct thermal_zone_device_ops *thdev_ops; + int (*probe)(struct platform_device *pdev, + struct airoha_thermal_priv *priv); + int (*post_probe)(struct platform_device *pdev); +}; + static int airoha_get_thermal_ADC(struct airoha_thermal_priv *priv) { u32 val; @@ -220,7 +231,8 @@ static void airoha_init_thermal_ADC_mode(struct airoha_= thermal_priv *priv) regmap_read(priv->chip_scu, EN7581_PLLRG_PROTECT, &pllrg); =20 /* Give access to thermal regs */ - regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, EN7581_SCU_THERMAL_PRO= TECT_KEY); + regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, + priv->pllrg_protect); adc_mux =3D FIELD_PREP(EN7581_MUX_TADC, EN7581_SCU_THERMAL_MUX_DIODE1); regmap_write(priv->chip_scu, EN7581_PWD_TADC, adc_mux); =20 @@ -228,7 +240,7 @@ static void airoha_init_thermal_ADC_mode(struct airoha_= thermal_priv *priv) regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, pllrg); } =20 -static int airoha_thermal_get_temp(struct thermal_zone_device *tz, int *te= mp) +static int en7581_thermal_get_temp(struct thermal_zone_device *tz, int *te= mp) { struct airoha_thermal_priv *priv =3D thermal_zone_device_priv(tz); int min_value, max_value, avg_value, value; @@ -253,7 +265,7 @@ static int airoha_thermal_get_temp(struct thermal_zone_= device *tz, int *temp) return 0; } =20 -static int airoha_thermal_set_trips(struct thermal_zone_device *tz, int lo= w, +static int en7581_thermal_set_trips(struct thermal_zone_device *tz, int lo= w, int high) { struct airoha_thermal_priv *priv =3D thermal_zone_device_priv(tz); @@ -290,12 +302,12 @@ static int airoha_thermal_set_trips(struct thermal_zo= ne_device *tz, int low, return 0; } =20 -static const struct thermal_zone_device_ops thdev_ops =3D { - .get_temp =3D airoha_thermal_get_temp, - .set_trips =3D airoha_thermal_set_trips, +static const struct thermal_zone_device_ops en7581_thdev_ops =3D { + .get_temp =3D en7581_thermal_get_temp, + .set_trips =3D en7581_thermal_set_trips, }; =20 -static irqreturn_t airoha_thermal_irq(int irq, void *data) +static irqreturn_t en7581_thermal_irq(int irq, void *data) { struct airoha_thermal_priv *priv =3D data; enum thermal_notify_event event; @@ -326,7 +338,7 @@ static irqreturn_t airoha_thermal_irq(int irq, void *da= ta) return IRQ_HANDLED; } =20 -static void airoha_thermal_setup_adc_val(struct device *dev, +static void en7581_thermal_setup_adc_val(struct device *dev, struct airoha_thermal_priv *priv) { u32 efuse_calib_info, cpu_sensor; @@ -356,7 +368,7 @@ static void airoha_thermal_setup_adc_val(struct device = *dev, } } =20 -static void airoha_thermal_setup_monitor(struct airoha_thermal_priv *priv) +static void en7581_thermal_setup_monitor(struct airoha_thermal_priv *priv) { /* Set measure mode */ regmap_write(priv->map, EN7581_TEMPMSRCTL0, @@ -411,30 +423,26 @@ static void airoha_thermal_setup_monitor(struct airoh= a_thermal_priv *priv) FIELD_PREP(EN7581_ADC_POLL_INTVL, 146)); } =20 -static const struct regmap_config airoha_thermal_regmap_config =3D { +static const struct regmap_config en7581_thermal_regmap_config =3D { .reg_bits =3D 32, .reg_stride =3D 4, .val_bits =3D 32, }; =20 -static int airoha_thermal_probe(struct platform_device *pdev) +static int en7581_thermal_probe(struct platform_device *pdev, + struct airoha_thermal_priv *priv) { - struct airoha_thermal_priv *priv; struct device_node *chip_scu_np; struct device *dev =3D &pdev->dev; void __iomem *base; int irq, ret; =20 - priv =3D devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - base =3D devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(base)) return PTR_ERR(base); =20 priv->map =3D devm_regmap_init_mmio(dev, base, - &airoha_thermal_regmap_config); + &en7581_thermal_regmap_config); if (IS_ERR(priv->map)) return PTR_ERR(priv->map); =20 @@ -454,18 +462,55 @@ static int airoha_thermal_probe(struct platform_devic= e *pdev) return irq; =20 ret =3D devm_request_threaded_irq(&pdev->dev, irq, NULL, - airoha_thermal_irq, IRQF_ONESHOT, + en7581_thermal_irq, IRQF_ONESHOT, pdev->name, priv); if (ret) { dev_err(dev, "Can't get interrupt working.\n"); return ret; } =20 - airoha_thermal_setup_monitor(priv); - airoha_thermal_setup_adc_val(dev, priv); + en7581_thermal_setup_monitor(priv); + en7581_thermal_setup_adc_val(dev, priv); + + return 0; +} + +static int en7581_thermal_post_probe(struct platform_device *pdev) +{ + struct airoha_thermal_priv *priv =3D platform_get_drvdata(pdev); + + /* Enable LOW and HIGH interrupt (if supported) */ + regmap_write(priv->map, EN7581_TEMPMONINT, + EN7581_HOFSINTEN0 | EN7581_LOFSINTEN0); + + return 0; +} + +static int airoha_thermal_probe(struct platform_device *pdev) +{ + const struct airoha_thermal_soc_data *soc_data; + struct airoha_thermal_priv *priv; + struct device *dev =3D &pdev->dev; + int ret; + + soc_data =3D device_get_match_data(dev); + + priv =3D devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->pllrg_protect =3D soc_data->pllrg_protect; + + if (!soc_data->probe) + return -EINVAL; + + ret =3D soc_data->probe(pdev, priv); + if (ret) + return ret; =20 /* register of thermal sensor and get info from DT */ - priv->tz =3D devm_thermal_of_zone_register(dev, 0, priv, &thdev_ops); + priv->tz =3D devm_thermal_of_zone_register(dev, 0, priv, + soc_data->thdev_ops); if (IS_ERR(priv->tz)) { dev_err(dev, "register thermal zone sensor failed\n"); return PTR_ERR(priv->tz); @@ -473,15 +518,18 @@ static int airoha_thermal_probe(struct platform_devic= e *pdev) =20 platform_set_drvdata(pdev, priv); =20 - /* Enable LOW and HIGH interrupt */ - regmap_write(priv->map, EN7581_TEMPMONINT, - EN7581_HOFSINTEN0 | EN7581_LOFSINTEN0); - - return 0; + return soc_data->post_probe ? soc_data->post_probe(pdev) : 0; } =20 +static const struct airoha_thermal_soc_data en7581_data =3D { + .pllrg_protect =3D EN7581_SCU_THERMAL_PROTECT_KEY, + .thdev_ops =3D &en7581_thdev_ops, + .probe =3D &en7581_thermal_probe, + .post_probe =3D &en7581_thermal_post_probe, +}; + static const struct of_device_id airoha_thermal_match[] =3D { - { .compatible =3D "airoha,en7581-thermal" }, + { .compatible =3D "airoha,en7581-thermal", .data =3D &en7581_data }, {}, }; MODULE_DEVICE_TABLE(of, airoha_thermal_match); --=20 2.48.1 From nobody Sun Dec 14 19:24:22 2025 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 2E6AA29AAF0; Fri, 23 May 2025 18:30:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748025017; cv=none; b=UQ7Xvvz4x9MLHW8atzNP08k3sONPO2ggTRe+4phMrcN79wIIMqpypoFkiOxWBmSwLZun8bbAjYBWelVHsL7fhbwZYbfv432WVcQwaSJ1ZJLEoL0iGAdmv6tQ5pXI4XNofLGsUUyjYrJyEgSDcfxVYxEuBhZavcyFRalk1jIUCzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748025017; c=relaxed/simple; bh=ekBKR7Lv9oRac0ZLGP9CYgwGxje7bKMozV4NKyoCQ8Q=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DUV4GT9wjoVX/tSnQQH8gRZ71XYraMrYSfATtHnswhiiVUnSxtaWo19j+uL+BQsLrwSMfJV66BSu8ZIJjaQwguUb3k9RCeue8OuymoRmgVj4lBSsoXNEGJlwtxguDPQAr21Q0dwhBxHJwNPJRGOx7vNjpu4gLd1LsTa2NSjku3Q= 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=bmtkKzVG; arc=none smtp.client-ip=209.85.221.45 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bmtkKzVG" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3a4c4e6a0ccso140394f8f.3; Fri, 23 May 2025 11:30:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748025013; x=1748629813; 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=ZQ8QlcBdWd0Fx5MdvLJdxsCqqhtJN4mycD+l4My2cUw=; b=bmtkKzVG2W649Mj23WAxm7v1tDsDOFN5B8ss0+zP0m13DeLVrW5syU6si3oIh8bNV0 PXCfCP9CrGhORTx9KbGY2kDAKkOHdOg2InMNMgAy5ShtHAI1GWDxR1My6zZ3qK/bugwA q3pKZGVjheeoDrMUhvpJmPSQ1REHAxyGGkaSXEmGHqD8Ztb6nxoGriyeQ4AH7ZoCy1pz BBMkuqTEmX80CypiMZOxkVQxFv0Pu/Q9bRxk8iKfZU26GtuAx6NFkZLYA4XGtYQKucMt GTwNn5+CnFE1fs/gi9lWd3a5l/83Tvj0I2X7xp3wuDFRahiSQl9utwmlfXy1kblg/Nbe MhTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748025013; x=1748629813; 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=ZQ8QlcBdWd0Fx5MdvLJdxsCqqhtJN4mycD+l4My2cUw=; b=aKwrJjh4dXmM+k/aJM23doJNph4bmG7FmD5/vt2r+1fwcsU7AHYLg/2JKxElAs5YNw IDdreG2Hlnn6l9SEkNIaKPOV0bjXy3nn/uzoZSZD9Ml3hdpYDY8koxdDvbmSWRFE2IGj L4LB76JJJVtefCaL4CYm95AQQ+pf53xrqUj/b54Y1iHx0BoHVdlr5XLqszrlRd0L/hXn BdF4XoQzRgb9GKMGyh+zDqZj78ECEY7sv/WUorDXqTcJ5sy8KF2VtGj9J0p68YhTiCdO t5053rQELgxDO62ZUzFHlYK7cl8C/bMbD6S0XYHPR6hxMbMPPGYHgjbLCv4/dClXTYqm dySg== X-Forwarded-Encrypted: i=1; AJvYcCUS5tE2q8UKzRbbCtzH7jF1GCNJv1tV13Nic8TLT5tm42ejdMbmG5/XpNEi7JbKnRTHvD2omu42Fq8=@vger.kernel.org, AJvYcCV5e0TMeg86nKEjk6Nrzqgdomtg7WTzaEwI1lmIE7MFncFZ14gamIKHZjTTzemEU4P75j7oeQn8j+wn@vger.kernel.org, AJvYcCVGnFmqp4lFbGLJa1pIlCMMzctONxl1O8JmfMFWMGuXcYFUNvb77ty26lqsKIIxL+8YrDaa+9ntNtdp1Ub0@vger.kernel.org X-Gm-Message-State: AOJu0YypNuWvvMMLrqxsZ2fqh2kbL1pAVIQcwdMDc1Uk20IRQmNBZGBO KtJVQPSSHrLWDP+249ptip+7FqL0gs/pK/Gd5dza61g2jcwgwluGoCv3 X-Gm-Gg: ASbGncu8dDAI5X4V4CFaMjmPHyDwCRgXEwF/wz3TJjPDpxDlRSMhELhK/gsyopLhmB0 GRrXLTm3tZ/mLHOA3b5A+jhRUp3nf0i49kvR8cjD3ltojyIySANFQWQoslqv+BzmG6JlDp/SrbV 27oUJIk1tDtddr35hmA2avInxPgUdTU1ze1AWgrvnWzES2AlL/Ywco18s6I2NdT4T5owTZNuyVD mg4nQL60GURJZGgJMf6CSi5CqnS0fgQK53SqwsuvtrBRMielCwpYyloaqDMdC0OUeXuolU0EmYV xc7SNAZq5J+IVK6lR6xAEH3mofru2uW1ZFeESesPe4uZT5rnNjLXDUZdsElhcaTFV8scPiz+p+r b5JuoA/AiyXdVt00nTOr0 X-Google-Smtp-Source: AGHT+IGqlNjS3/yy5PC/pt+Pz4dbb96NoJVachaflRhm85TFP1ul3ISSryCigPrr0pO/3y09S+cMkQ== X-Received: by 2002:a05:6000:2283:b0:3a3:f692:c4ae with SMTP id ffacd0b85a97d-3a4cb454b8dmr240921f8f.18.1748025013326; Fri, 23 May 2025 11:30:13 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a35ca4d2d1sm28180695f8f.19.2025.05.23.11.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 May 2025 11:30:13 -0700 (PDT) From: Christian Marangi To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] thermal/drivers: airoha: Generalize get_thermal_ADC and set_mux function Date: Fri, 23 May 2025 20:29:31 +0200 Message-ID: <20250523182939.30489-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250523182939.30489-1-ansuelsmth@gmail.com> References: <20250523182939.30489-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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_ther= mal.c index 9bfa59b97032..4c973cce106a 100644 --- a/drivers/thermal/airoha_thermal.c +++ b/drivers/thermal/airoha_thermal.c @@ -193,9 +193,18 @@ =20 #define AIROHA_MAX_SAMPLES 6 =20 +enum airoha_thermal_chip_scu_field { + AIROHA_THERMAL_DOUT_TADC, + AIROHA_THERMAL_MUX_TADC, + + /* keep last */ + AIROHA_THERMAL_FIELD_MAX, +}; + 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; =20 u32 pllrg_protect; @@ -219,22 +228,29 @@ static int airoha_get_thermal_ADC(struct airoha_therm= al_priv *priv) { u32 val; =20 - 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; } =20 -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; =20 /* Save PLLRG current value */ regmap_read(priv->chip_scu, EN7581_PLLRG_PROTECT, &pllrg); =20 - /* Give access to thermal regs */ + /* Give access to Thermal regs */ regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, priv->pllrg_protect); - adc_mux =3D 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); =20 /* 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; =20 - /* 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); =20 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_regm= ap_config =3D { .val_bits =3D 32, }; =20 +static const struct reg_field en7581_chip_scu_fields[AIROHA_THERMAL_FIELD_= MAX] =3D { + [AIROHA_THERMAL_DOUT_TADC] =3D REG_FIELD(EN7581_DOUT_TADC, 0, 15), + [AIROHA_THERMAL_MUX_TADC] =3D 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 =3D &pdev->dev; void __iomem *base; - int irq, ret; + int i, irq, ret; =20 base =3D 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); =20 + for (i =3D 0; i < AIROHA_THERMAL_FIELD_MAX; i++) { + struct regmap_field *field; + + field =3D 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] =3D field; + } + of_address_to_resource(chip_scu_np, 0, &priv->scu_adc_res); of_node_put(chip_scu_np); =20 --=20 2.48.1 From nobody Sun Dec 14 19:24:22 2025 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 3450929B235; Fri, 23 May 2025 18:30:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748025018; cv=none; b=tN6xM2izZ3BGiwhkXZ/Dh7xCTtsanLgLtXRArCptoRKcKbPrd5XigeWZvt/l3442KWSTIc/QWQwiM3leLCT7yNCUS3s5KjQ6tdwg2bchtR1zTHPnj4utgQF6ExjCQV7ZDKVt8snnQaDIPLcIxA5Bn7pTPRYdNkf5G7isEyR0Qag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748025018; c=relaxed/simple; bh=FLtBxNr1ox9ojf6yRUY/yBsCghOboZfJHHj47uEu/Do=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B8cSUFKzwMUxtiyJXzvGd0rMCb8I4E3yfhPSn2WhgaEBR413nYlRf/GvBrc48lWaR3xGMsS8w0FGgJVexu7+AvyZpd3qKiIQz3qz3eEDLZjhP/lEA6Ay8d9TaoT1ndoEIu7+mHpV8Fv3EwZOQwC9n8tDb/2z5i127CU3je/Cb3Q= 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=FC3+3duZ; arc=none smtp.client-ip=209.85.221.49 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FC3+3duZ" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3a35c894313so155698f8f.2; Fri, 23 May 2025 11:30:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748025014; x=1748629814; 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=13JzDFAxV0mwWFnjAkxRyMC1mXnhBx1PDwFdeu7Nt1E=; b=FC3+3duZE/9Ljy5SyCMzO6VRf12obnJ6F/3GIKwd+5wx0Uj/kgTtoUZX1AsB0GnyLo paoVWcIKeDfsPnmzEWieJmy8UYbSGc5O2XEAZ+ZFllgUgHSkaVUOWf+3ogZ944rzZteL kkpXqr84gmhDJvcjoSUCQMRrUYGFfMBVWAc9dPqsc7e+xiw51MmN7ivQ24GOaVMHt+5s f2sJQkpeJXCwQ3Hj8lBlhoUU5hDRLVns3krftbqZR9dQh9gQUhKtYRlGVp53kBv4bKtu fbdyZPdZBIpwNjvHvJP1hUVBLVf5r9GdG5I7w66s8xqjSjG1S80nQzCvcbvN8GBiphSE 4B4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748025014; x=1748629814; 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=13JzDFAxV0mwWFnjAkxRyMC1mXnhBx1PDwFdeu7Nt1E=; b=w5VokZZcOJ9LzTyAyQ9pFivfBJpLQ6okwn37GK/L3WCdPUuIdp5lk/46bW5GkVaBNy Z0TtY1K0aERsGoryexxO3RKlOA4+mwQ8u/We5sMjhkJacMv0THrPEYnai0QEjQyyMbaO roSRWTJwdNyLS5UgNjLXmrgENTvwtynnuANAXvP4p1lqtBIcTnZo8PNfG+D/hlxlPLMo NOdOXq1Y9sQ54zqZjHAJxSa0Ote9QOiy+oR2bJ+Z7nLomvGEGqv7/AexMCoY/DmIFlXU LTe0fK8dCgkpqcbp6UhLhXgvHbFcPVHniGAObMT8uVI4p1OZWv04mrGtxoWpJH4ifjEd Hk0Q== X-Forwarded-Encrypted: i=1; AJvYcCUDQTNCC8tGMJhvIr1HVYkru6g4Qn6pOCFk14TNCR7NenwmIx/gjSzSpbyInBz5BvMDk+q1ZTFYRyg=@vger.kernel.org, AJvYcCUGQgen3aetFpf+JRXM7p9xtIAevA6p04WstpHkApg0oyqpL7DIiSdiOo/VO+ANOAPB08Upy5dW2dghuXaA@vger.kernel.org, AJvYcCVc9HbYtavSE04n5WMwJDR1Dp3cHisAmzgb9f6xrq79Sb3UrQJcTNWIBfWTebY/6+qUNxzFo+ChhtbK@vger.kernel.org X-Gm-Message-State: AOJu0Yy0y5MSzGREdaF/Sa01FwLJmP6t+RpKDctOohtX4ZhBsite+V8I QlojECdXd7TKT1jFFuQ68V0xT/oUdzoIqmiM0NCwCkB4KqNK4tahQ+K6 X-Gm-Gg: ASbGncvX62gicT1DGbOQ53oHqGXQz4BYIlK1x2qbTxlXjVea3k+6HZUJEz0FQMf2z9A /mEWFMEjAnVAD1cvko6tf1s18CDH732m9xOoFFkxT2ggv6HlV4SvqYGqo/wxPqCkRWoys5IJD8K rYSrhTZl5Ob5Gl9oxgcLaOrTomuJ+0tzynM+1wXJpybg9sCAi1Dd81y9NU+O438MmG9mxyYVO1m l1dnGPU/9k1FklIKju64Zlna7eAEClVxMfx5CL6A4bAtP7xSDzHbmoj70r0H9MCkWM5XE56lwb1 UhYjzam8WgV5Jzc+T2sgPpU63eGuz4XKvuZP78o1B922SK7GqtbdSGkZiMTx2R7NnEuBJ3T5Ih8 ltQtWPKE2dKvfYzkuAGnj X-Google-Smtp-Source: AGHT+IHcq5HBYMJjQGd2qkJkDWuaQYDC+rdEmaeEEgHWkBX8Y7pnBfoUlPsXAfPOJ4M0zrmqawdjlw== X-Received: by 2002:a05:6000:4282:b0:3a0:b4a7:6e56 with SMTP id ffacd0b85a97d-3a4cb4c59b7mr341434f8f.56.1748025014331; Fri, 23 May 2025 11:30:14 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a35ca4d2d1sm28180695f8f.19.2025.05.23.11.30.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 May 2025 11:30:14 -0700 (PDT) From: Christian Marangi To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] dt-bindings: thermal: airoha: Rename and Document AN7583 support Date: Fri, 23 May 2025 20:29:32 +0200 Message-ID: <20250523182939.30489-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250523182939.30489-1-ansuelsmth@gmail.com> References: <20250523182939.30489-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: quoted-printable Content-Type: text/plain; charset="utf-8" Rename .yaml to a more generic airoha-thermal and Document support for Airoha AN7583 thermal driver. Airoha AN7583 follow the same logic of Airoha EN7581 to read the temperature but lack all the support for the PTP_THERMAL used to monitor and react when trip point are triggered. Also the Airoha AN7583 lives entirely under the Chip SCU SoC register space. Signed-off-by: Christian Marangi --- ...n7581-thermal.yaml =3D> airoha-thermal.yaml} | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) rename Documentation/devicetree/bindings/thermal/{airoha,en7581-thermal.ya= ml =3D> airoha-thermal.yaml} (52%) diff --git a/Documentation/devicetree/bindings/thermal/airoha,en7581-therma= l.yaml b/Documentation/devicetree/bindings/thermal/airoha-thermal.yaml similarity index 52% rename from Documentation/devicetree/bindings/thermal/airoha,en7581-thermal= .yaml rename to Documentation/devicetree/bindings/thermal/airoha-thermal.yaml index ca0242ef0378..42f93b095783 100644 --- a/Documentation/devicetree/bindings/thermal/airoha,en7581-thermal.yaml +++ b/Documentation/devicetree/bindings/thermal/airoha-thermal.yaml @@ -1,17 +1,19 @@ # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) %YAML 1.2 --- -$id: http://devicetree.org/schemas/thermal/airoha,en7581-thermal.yaml# +$id: http://devicetree.org/schemas/thermal/airoha-thermal.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# =20 -title: Airoha EN7581 Thermal Sensor and Monitor +title: Airoha Thermal Sensor and Monitor =20 maintainers: - Christian Marangi =20 properties: compatible: - const: airoha,en7581-thermal + enum: + - airoha,en7581-thermal + - airoha,an7583-thermal =20 reg: maxItems: 1 @@ -28,9 +30,30 @@ properties: =20 required: - compatible - - reg - - interrupts - - airoha,chip-scu + - '#thermal-sensor-cells' + +allOf: + - if: + properties: + compatible: + contains: + const: airoha,en7581-thermal + then: + required: + - reg + - interrupts + - airoha,chip-scu + + - if: + properties: + compatible: + contains: + const: airoha,an7583-thermal + then: + properties: + reg: false + interrupts: false + airoha,chip-scu: false =20 additionalProperties: false =20 @@ -46,3 +69,10 @@ examples: =20 #thermal-sensor-cells =3D <0>; }; + + - | + thermal-sensor { + compatible =3D "airoha,an7583-thermal"; + + #thermal-sensor-cells =3D <0>; + }; --=20 2.48.1 From nobody Sun Dec 14 19:24:22 2025 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 75BE729B8E6; Fri, 23 May 2025 18:30:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748025019; cv=none; b=f9a5Fuyraq4D9qrRcLIxcR4WbXznrs4pqDgvuI4MrAebXxUrNruArQzFDhQgieTMZtJFkSE9qppz7MgFHUrJ3V/tR1MBxM0SbezQjkrf6CeoEMpy5E9k947848KsuhpMDDR8R2Y1tOoGqGqFW4lGV0D4zX0+4M05I9LAsCJpj7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748025019; c=relaxed/simple; bh=zmNS/g/uQIEqjg8pv8e9ZCmB4hQz9Fpeoy2dOjmOTf0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S+MRilXAMnDj2D//oqKY/wze7xBwa9lV0653aS3ugtDW+SkIUEVACUhMgbak3fRQYrjzrdQ1rYzEyLC5+2Jl0Vg3QlCDdSxmmM1gpsz9ZFa+4rHJhDS9NjZG+XC1jY0LGfGdh755llJMlnISGy7PXbbis0mel01OkAYeYbh6cgc= 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=ROKh0qzT; arc=none smtp.client-ip=209.85.221.42 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ROKh0qzT" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3a363d15c64so156317f8f.3; Fri, 23 May 2025 11:30:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748025016; x=1748629816; 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=Gq4Q+VNy6npC1ksfAe5OpC6UqFwfJyc/g1FQnGCBY/w=; b=ROKh0qzTRJV9sQu0M6nzo4kk29PZt3YST0OA8EAMTOx8qDpszaXzQSNeTVCPNwAuTc lL/XFBMMu2XyybpLM95DFOkqIWiKr7QiqoxJXKUE20k2qZS6IJdsB/R7uATmbytVbS+8 uyaZWuXFfgRm79HJaOpk2/KtzBUzOmF3Yzh6SYSutlC6iG9iINCSnegrNVZ33LrO5Ywf 2JzQHq3Gcb9q7GNq9NTvT9b3RDU7IKId4T8NDeSvLDh40LC8yOiM+zcLAMgFzWKBV3Mv Uwzr9qeI59qtxcygDZwVsIHJnYaa5BtblowFcU1xfL1V880e4P7LjHGD93N5wcvAVTSv 6LtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748025016; x=1748629816; 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=Gq4Q+VNy6npC1ksfAe5OpC6UqFwfJyc/g1FQnGCBY/w=; b=Gew5S/VRHVC6YwQ5ZTK0NKVfJdNG3Xq3L20D587fmi7KvAowOMufANpnKSQaOsR8Xv x2JRtErl3F80fCXdyxIMj4FYI9+9cO26Y6shW6Ir7cxegHUQ1qTjNwU6j9D0I35FWvzK WRXINr/y0SNpn+cBOgf2F3BZMoSO3/ijlWyoFvYHTJJ6DeZzXVpnNKvnc3NWfqYTqZrQ 6/VQYETNLCxtdInUdGlpgbi9ZskedLm2rWaMJkofPNdA+Llw54ZEsMRea66nJgdotTVB gkoEtjtNbYkF6IwpxJfNbKr0Th/nBiVYOdP/az1D6jp4UG+kIZrB+8IfzaxwNsl+Gp3g Buhw== X-Forwarded-Encrypted: i=1; AJvYcCWHYGCHrIL/+/2+6GvZoI+R/2y15lZl0iBnnoQRayEzytjxlWvWYqlAAwriHz9x6jTz/nrJSMjQfRE=@vger.kernel.org, AJvYcCWPxnMmR2axbDwsvG/TqlN57TpdU6ebqhp7rpQ5zZETdXxIO50K3k4xsbkEoFcILzQB3CEOAMfosNVT@vger.kernel.org, AJvYcCXNpfvg4GZUeNSdDWtgPspxzdFa9loyLED02Mvi1YkIFkCJc2IPYlR/zUmPXllF3WoQQXvaznUcMw3Kq0hW@vger.kernel.org X-Gm-Message-State: AOJu0YwLr30Cb9Z/Ad0r4a5RregFt2+s0d2ggXOy9YnmvlZzYNnjaexK /yn0nDA3V+9HSsI/+Usb94Gn93SlI+9JPd5z+OUUF92pVetITOIVnBRV X-Gm-Gg: ASbGncs7yU1b9iEgFAw+ia78CisaTTfekUqi88CITpwo54UDwyF4vL+xxhErB+iNJZf CJJH2f5Vd5vICfsLGvcdXwsTozy/ER2xui049kmqFFjv8H1+6GP27eQ8+wmA3dOEdp7F0Cx09cd 9chC38AElZqm+Dhzy/+HosU4/Kaote8SbllArxQLOS15JwHBzkvR3gb0Cwr5oczS+NfVKO5ncOq AtfWOYrG/wcfVvm9zsKzl5IkP8Ry5gbbEVCYGVRyME6nukR+i5ANuOo8Gy5lByOsTIPFPSNVaC1 rc51DPbrnSXdlhiySBE2njDEFC5RXcVnMKiAYSnJijfMJJB2F+sEi/Ju6h+cME0MVPM3UYcZ6OU AzMZPGhOxLiW3H+qKzG5x X-Google-Smtp-Source: AGHT+IGhLqeVA2dqfOk4B07OByc6JCSnVy/YZJShj/cVBgsybbIaiyYyTQenOoihvNnk7+r52GBR+g== X-Received: by 2002:a5d:5f8b:0:b0:3a4:bafb:adca with SMTP id ffacd0b85a97d-3a4caec3209mr416505f8f.0.1748025015426; Fri, 23 May 2025 11:30:15 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a35ca4d2d1sm28180695f8f.19.2025.05.23.11.30.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 May 2025 11:30:15 -0700 (PDT) From: Christian Marangi To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] thermal/drivers: airoha: Add support for AN7583 Thermal Sensor Date: Fri, 23 May 2025 20:29:33 +0200 Message-ID: <20250523182939.30489-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250523182939.30489-1-ansuelsmth@gmail.com> References: <20250523182939.30489-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: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for Airoha AN7583 Thermal driver. This apply similar logic on how to read the temperature but totally drop support for the PTP_THERMAL subsystem. PTP_THERMAL subsystem was a way to trigger trip point from hardware by configuring how to read the temperature internally. This subsystem has been totally removed from Airoha AN7583 permitting only to read the temperature. The SoC support up to 3 sensor but the original driver always read the BGA sensor hence it's currently implemented reading only this specific sensor. Reference and values for the other 2 sensor are defined for further implementation if confirmed working. set_thermal_mux() is extended to also address muxing the sensor as AN7583 use a different way to read the temperature from 3 different diode. The EN7581 code is updated to account for these changes. Signed-off-by: Christian Marangi --- drivers/thermal/airoha_thermal.c | 158 ++++++++++++++++++++++++++++++- 1 file changed, 154 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/airoha_thermal.c b/drivers/thermal/airoha_ther= mal.c index 4c973cce106a..e71548f9cee1 100644 --- a/drivers/thermal/airoha_thermal.c +++ b/drivers/thermal/airoha_thermal.c @@ -18,6 +18,12 @@ #define EN7581_DOUT_TADC 0x2f8 #define EN7581_DOUT_TADC_MASK GENMASK(15, 0) =20 +#define AN7583_MUX_SENSOR 0x2a0 +#define AN7583_LOAD_ADJ GENMASK(3, 2) +#define AN7583_MUX_TADC 0x2e4 +#define AN7583_MUX_TADC_MASK GENMASK(3, 1) +#define AN7583_DOUT_TADC 0x2f0 + /* PTP_THERMAL regs */ #define EN7581_TEMPMONCTL0 0x800 #define EN7581_SENSE3_EN BIT(3) @@ -181,6 +187,11 @@ #define EN7581_SCU_THERMAL_PROTECT_KEY 0x12 #define EN7581_SCU_THERMAL_MUX_DIODE1 0x7 =20 +#define AN7583_SCU_THERMAL_PROTECT_KEY 0x80 +#define AN7583_NUM_SENSOR 3 + +#define AIROHA_THERMAL_NO_MUX_SENSOR -1 + /* Convert temp to raw value as read from ADC ((((temp / 100) - init) * sl= ope) / 1000) + offset */ #define TEMP_TO_RAW(priv, temp) ((((((temp) / 100) - (priv)->init_temp) = * \ (priv)->default_slope) / 1000) + \ @@ -193,8 +204,39 @@ =20 #define AIROHA_MAX_SAMPLES 6 =20 +/* + * AN7583 supports all these ADC mux but the original driver + * always checked temp with the AN7583_BGP_TEMP_SENSOR. + * Assume using the other sensor temperature is invalid and + * always read from AN7583_BGP_TEMP_SENSOR. + * + * On top of this it's defined that AN7583 supports 3 + * sensor: AN7583_BGP_TEMP_SENSOR, AN7583_GBE_TEMP_SENSOR, + * AN7583_CPU_TEMP_SENSOR. + * + * Provide the ADC mux for reference. + */ +enum an7583_thermal_adc_mux { + AN7583_BGP_TEMP_SENSOR, + AN7583_PAD_AVS, + AN7583_CORE_POWER, + AN7583_AVSDAC_OUT, + AN7583_VCM, + AN7583_GBE_TEMP_SENSOR, + AN7583_CPU_TEMP_SENSOR, + + AN7583_ADC_MUX_MAX, +}; + +enum an7583_thermal_diode_mux { + AN7583_D0_TADC, + AN7583_ZERO_TADC, + AN7583_D1_TADC, +}; + enum airoha_thermal_chip_scu_field { AIROHA_THERMAL_DOUT_TADC, + AIROHA_THERMAL_MUX_SENSOR, AIROHA_THERMAL_MUX_TADC, =20 /* keep last */ @@ -208,6 +250,7 @@ struct airoha_thermal_priv { struct resource scu_adc_res; =20 u32 pllrg_protect; + int current_adc; =20 struct thermal_zone_device *tz; int init_temp; @@ -224,6 +267,24 @@ struct airoha_thermal_soc_data { int (*post_probe)(struct platform_device *pdev); }; =20 +static const unsigned int an7583_thermal_coeff[AN7583_ADC_MUX_MAX] =3D { + [AN7583_BGP_TEMP_SENSOR] =3D 973, + [AN7583_GBE_TEMP_SENSOR] =3D 995, + [AN7583_CPU_TEMP_SENSOR] =3D 1035, +}; + +static const unsigned int an7583_thermal_slope[AN7583_ADC_MUX_MAX] =3D { + [AN7583_BGP_TEMP_SENSOR] =3D 7440, + [AN7583_GBE_TEMP_SENSOR] =3D 7620, + [AN7583_CPU_TEMP_SENSOR] =3D 8390, +}; + +static const unsigned int an7583_thermal_offset[AN7583_ADC_MUX_MAX] =3D { + [AN7583_BGP_TEMP_SENSOR] =3D 294, + [AN7583_GBE_TEMP_SENSOR] =3D 298, + [AN7583_CPU_TEMP_SENSOR] =3D 344, +}; + static int airoha_get_thermal_ADC(struct airoha_thermal_priv *priv) { u32 val; @@ -234,7 +295,7 @@ static int airoha_get_thermal_ADC(struct airoha_thermal= _priv *priv) } =20 static void airoha_set_thermal_mux(struct airoha_thermal_priv *priv, - int tdac_idx) + int tdac_idx, int sensor_idx) { u32 pllrg; =20 @@ -245,9 +306,20 @@ static void airoha_set_thermal_mux(struct airoha_therm= al_priv *priv, regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, priv->pllrg_protect); =20 + /* + * Configure Thermal Sensor mux to sensor_idx. + * (if not supported, sensor_idx is AIROHA_THERMAL_NO_MUX_SENSOR) + */ + if (sensor_idx !=3D AIROHA_THERMAL_NO_MUX_SENSOR) + regmap_field_write(priv->chip_scu_fields[AIROHA_THERMAL_MUX_SENSOR], + sensor_idx); + /* Configure Thermal ADC mux to tdac_idx */ - regmap_field_write(priv->chip_scu_fields[AIROHA_THERMAL_MUX_TADC], - tdac_idx); + if (priv->current_adc !=3D tdac_idx) { + regmap_field_write(priv->chip_scu_fields[AIROHA_THERMAL_MUX_TADC], + tdac_idx); + priv->current_adc =3D tdac_idx; + } =20 /* Sleep 10 ms for Thermal ADC to enable */ usleep_range(10 * USEC_PER_MSEC, 11 * USEC_PER_MSEC); @@ -360,7 +432,8 @@ static void en7581_thermal_setup_adc_val(struct device = *dev, u32 efuse_calib_info, cpu_sensor; =20 /* Setup Thermal Sensor to ADC mode and setup the mux to DIODE1 */ - airoha_set_thermal_mux(priv, EN7581_SCU_THERMAL_MUX_DIODE1); + airoha_set_thermal_mux(priv, EN7581_SCU_THERMAL_MUX_DIODE1, + AIROHA_THERMAL_NO_MUX_SENSOR); =20 regmap_read(priv->map, EN7581_EFUSE_TEMP_OFFSET_REG, &efuse_calib_info); if (efuse_calib_info) { @@ -476,6 +549,10 @@ static int en7581_thermal_probe(struct platform_device= *pdev, for (i =3D 0; i < AIROHA_THERMAL_FIELD_MAX; i++) { struct regmap_field *field; =20 + /* Skip registering MUX_SENSOR field as not supported */ + if (i =3D=3D AIROHA_THERMAL_MUX_SENSOR) + continue; + field =3D devm_regmap_field_alloc(dev, priv->chip_scu, en7581_chip_scu_fields[i]); if (IS_ERR(field)) @@ -516,6 +593,71 @@ static int en7581_thermal_post_probe(struct platform_d= evice *pdev) return 0; } =20 +static int an7583_thermal_get_temp(struct thermal_zone_device *tz, int *te= mp) +{ + struct airoha_thermal_priv *priv =3D thermal_zone_device_priv(tz); + int sensor_idx; + int delta_diode, delta_gain; + int coeff, slope, offset; + + int diode_zero, diode_d0, diode_d1; + + /* Always read sensor AN7583_BGP_TEMP_SENSOR */ + sensor_idx =3D AN7583_BGP_TEMP_SENSOR; + + coeff =3D an7583_thermal_coeff[sensor_idx]; + slope =3D an7583_thermal_slope[sensor_idx]; + offset =3D an7583_thermal_offset[sensor_idx]; + + airoha_set_thermal_mux(priv, sensor_idx, AN7583_ZERO_TADC); + diode_zero =3D airoha_get_thermal_ADC(priv); + airoha_set_thermal_mux(priv, sensor_idx, AN7583_D0_TADC); + diode_d0 =3D airoha_get_thermal_ADC(priv); + airoha_set_thermal_mux(priv, sensor_idx, AN7583_D1_TADC); + diode_d1 =3D airoha_get_thermal_ADC(priv); + + delta_diode =3D diode_d1 - diode_d0; + delta_gain =3D (delta_diode * coeff) / 100 + (diode_zero - diode_d1); + *temp =3D (slope * delta_diode * 10) / delta_gain - offset * 10; + *temp *=3D 100; + + return 0; +} + +static const struct thermal_zone_device_ops an7583_tz_ops =3D { + .get_temp =3D an7583_thermal_get_temp, +}; + +static const struct reg_field an7583_chip_scu_fields[AIROHA_THERMAL_FIELD_= MAX] =3D { + [AIROHA_THERMAL_DOUT_TADC] =3D REG_FIELD(AN7583_DOUT_TADC, 0, 31), + [AIROHA_THERMAL_MUX_TADC] =3D REG_FIELD(AN7583_MUX_TADC, 1, 3), + [AIROHA_THERMAL_MUX_SENSOR] =3D REG_FIELD(AN7583_MUX_SENSOR, 2, 3), +}; + +static int an7583_thermal_probe(struct platform_device *pdev, + struct airoha_thermal_priv *priv) +{ + struct device *dev =3D &pdev->dev; + int i; + + priv->chip_scu =3D device_node_to_regmap(dev->parent->of_node); + if (IS_ERR(priv->map)) + return PTR_ERR(priv->map); + + for (i =3D 0; i < AIROHA_THERMAL_FIELD_MAX; i++) { + struct regmap_field *field; + + field =3D devm_regmap_field_alloc(dev, priv->chip_scu, + an7583_chip_scu_fields[i]); + if (IS_ERR(field)) + return PTR_ERR(field); + + priv->chip_scu_fields[i] =3D field; + } + + return 0; +} + static int airoha_thermal_probe(struct platform_device *pdev) { const struct airoha_thermal_soc_data *soc_data; @@ -530,6 +672,7 @@ static int airoha_thermal_probe(struct platform_device = *pdev) return -ENOMEM; =20 priv->pllrg_protect =3D soc_data->pllrg_protect; + priv->current_adc =3D -1; =20 if (!soc_data->probe) return -EINVAL; @@ -558,8 +701,15 @@ static const struct airoha_thermal_soc_data en7581_dat= a =3D { .post_probe =3D &en7581_thermal_post_probe, }; =20 +static const struct airoha_thermal_soc_data an7583_data =3D { + .pllrg_protect =3D AN7583_SCU_THERMAL_PROTECT_KEY, + .thdev_ops =3D &an7583_tz_ops, + .probe =3D &an7583_thermal_probe, +}; + static const struct of_device_id airoha_thermal_match[] =3D { { .compatible =3D "airoha,en7581-thermal", .data =3D &en7581_data }, + { .compatible =3D "airoha,an7583-thermal", .data =3D &an7583_data }, {}, }; MODULE_DEVICE_TABLE(of, airoha_thermal_match); --=20 2.48.1