From nobody Mon May 25 01:15:10 2026 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 8B73D3ED125 for ; Tue, 19 May 2026 22:24:49 +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=1779229491; cv=none; b=hb10lIYxaWyr6zUlWFtArdNqSattP8QIeJ+tEDtHtPqj58iYzgXOp9FA4K52cZdPEMmzMsCy678+OqFjLN/l2j8zvZGvVeg/lLn+YGKCzcNO0ueGpJg5g5IulAUaKx3RJtUWtglyL4qUY1pyf0pQxM0xddOvCMH2ZEWsVhzxG4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779229491; c=relaxed/simple; bh=htW4hYRWiUwplPFj0d2TFcKHJJnYxiOgcNIGqQlWOpw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OC0tWpjRdOfeuKVjk84WdQASxDBkmjJdCj9NCb9TTlmbeUvMav5NgVVOGOkYmy9YUGPVX2DZ046AMEfzLAeYEY2+I+MuF79lc3EIbqtigr5ID1WCt9TwSRLpY+M3ot7HCNSHZy5f6Vn/7ogtXXIITXnYDAtjEPFc308wVsy1+vM= 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=HnmdBpFX; 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="HnmdBpFX" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-48a3e9862f0so23918395e9.1 for ; Tue, 19 May 2026 15:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779229488; x=1779834288; 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=LbT6JFfEI94054ct5KRMwXyHu29ZqKoVeW1+JvOnT90=; b=HnmdBpFXPEqS4zuy6011Fz2KSaTkdrxS6r9OmUjbGVf/XuaTtp3al/f4Dp/DbaGh3P zkLPSwcNn9Qn4waP4MTunj0KAaT5oDUMEP8p0kLQVu79QBegjMGsTeRdOvA6w6/I/QaA CvnehZ3ajapeiMBDo1Gn9CNjcdCBYc/1ACvwmYM9KWyodiWY8afw7hU2sekb2WUhX3Jb oNyf5wVX9YqFRFq8JuigG+UYH0xlWA3uzxHI9Pq1pswr6WVrEH0aATd6hf/pgMhKrHGl N3x28btNkMK905oZB+0qeorXbnBJwrK1riXKicFL8+owfRLWViCTLlwa0d5MehPZMIkb DqyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779229488; x=1779834288; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=LbT6JFfEI94054ct5KRMwXyHu29ZqKoVeW1+JvOnT90=; b=SYAfIlJItBheUDkxAS7wFL4LowDaObfpe2ItwjDDLedGqpDDEjs6nbhFGobm5hifEd W30jVI6DfojkkQKoq8YmhJoeR7qh+CKz3YWPjHwywAK2SmTbztvIVip6Y+h8vpRj9zTs DVX0MrjjrlIcBCuyLVKpETAQEPt7DX5xKI9mJd91NgAwkwC9Hrc51+q1r+4kEVLgu8o8 szAUiM8Wam/9Be5rfbGuPjePof4d+X4z9wU56wflzSZrmVB9WtxuWwnlGBHPYEVDL1q1 dYlTV58tn+/vso9aTmDNJGdaG+zndrVIK0sOPxbrtPEgzdywQ5oKk2V/NRUaGNGQ7IxO EDEA== X-Forwarded-Encrypted: i=1; AFNElJ+hgOsHwyHC4V8l4lYVV7VnXfVEuQTvbQ+aSqH7IMe/8ljeICC85+qqtLeqK/UilGckYhZsPW/Rqmidbrk=@vger.kernel.org X-Gm-Message-State: AOJu0YykLmXcsftHMrT7pq4y1VgC+RQQ55UMgF3wiOOos4vT8p+BJDCD F1AeXL2Y1pDQyZZHbComlZ7+iSL6YKlwdoPubsug1VRln+rvWGIML5Uz X-Gm-Gg: Acq92OG/pSN+r+XClTBw1Z76cKUtT6RkPQ/+8LF1qSNc1bHH1znMTwacKr/7TT/iugY mqvFNy53cTMp2OUOt3yhU/uNUDYeIIsXyAKuY0YqMZWweJ35q4FcNT7UvYhDfkV4VsKCmrJNrLN cHBhz38hlG5PmvmCfvkUdtfjdWS56ejD90UKK1e/O8SUwbmdL2xFGhS7BvBUkm4PA2wdA6wTZM4 1ESnEPzJigeuNf6N0h/9sJLcMWDz9OHWmQZHdsRNBr5+6RHFxEh75Xi2bKC+zsf6zv1q9HWjsaV VQSPS4H001KqvJtvnFBPVe2xTCrsibMkUFy7xL5irp57Gu+fmD4L6c77/Yv16+ylu41CtMBFJjD 5W10yma9CeaQmFSNVnemMUtbKznuuMDdbr5vPPWfQWETERCIok1T9xooiXLV8LQYMZcPFx2DCRd KRtb8wjNdhyfrj9Wkg/ACZvCAUSFpRbYHw5EqI9qCWhEt378uQze8NYbmTdSRg0q3g5D929bc= X-Received: by 2002:a05:600c:83c7:b0:48f:e230:29f5 with SMTP id 5b1f17b1804b1-48fe53a8eccmr324459715e9.16.1779229487782; Tue, 19 May 2026 15:24:47 -0700 (PDT) Received: from Ansuel-XPS24 (host-82-55-252-101.retail.telecomitalia.it. [82.55.252.101]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-48fe4c834besm381097435e9.3.2026.05.19.15.24.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 15:24:47 -0700 (PDT) From: Christian Marangi To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Christian Marangi , Lorenzo Bianconi , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v4 1/5] thermal/drivers: airoha: Convert to regmap API Date: Wed, 20 May 2026 00:24:22 +0200 Message-ID: <20260519222433.29684-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260519222433.29684-1-ansuelsmth@gmail.com> References: <20260519222433.29684-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 b9fd6bfc88e5..01ed49a4887e 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.53.0 From nobody Mon May 25 01:15:10 2026 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 7A5BA3EE1C0 for ; Tue, 19 May 2026 22:24:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779229493; cv=none; b=h8Tq2+1zHJpzTqdOHSG5VLQtidQFwWCGaTFeWTR7Uqh/SyzKN8JHj5av1LUaqkA8hjlSeQE+ST4oWyqZX7Hy1Id9uUbXNGIfLink8WY2svEfd5K5H97XBINqu+usNv7x1ypznCN8dyQwyDH3MobPzyqW5Rut5s2JWbb0vVgvl0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779229493; c=relaxed/simple; bh=jZjVVRTMSOBTxHfQ9tWQQQ3/FZCaEcOCPXkupXgvp0Y=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nhl5Q4eXITzkhB4N7PxGwClGqXN9JrBYcwGeMcY2+qLk2+/BgRYAFwtMHmr2Rz5lyjui72AqUEEQWGwaaPqiSkTSM9C/0GvquzH7zQT/TIThUQVmt244kBz+oITWnO26wEdC48SQl01uor+RCVXxq5Al4fnleVGrCsouA6A0eK4= 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=tNCMoFEN; arc=none smtp.client-ip=209.85.128.52 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="tNCMoFEN" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-48fde648a71so30361735e9.0 for ; Tue, 19 May 2026 15:24:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779229490; x=1779834290; 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=EB72+GNLjTykeQdPDqWdzy0ATqpCM1uFByZoN9dOlQw=; b=tNCMoFENYqo1+Le4+Ckm3w9/A4wIgpjD15Mir8qdMLxO0049BcUGyNTVnXYVtuSR1r IRwnu+cZaoOIOcFkXL/ealHVIYZmegQSf7UrPu9diydRrdKkYMrCaSLXXRhC40XoeZXW 6PLWcJd3X1sKna23Rj3PJdgJ5uWBRTA/1ZAKl3JajF9XTi9SOIR5NO+pYWxm7ufQL+JP iLGFejwyUlnwdfQihjp1W1S2sKtYhzBFHX3/AJyiTQFEkXriyIubsa5yLeDgOcj43Cic whZ2xfk/875ikLOmpXkfABY7LCJnpapnXe4f5lG70aM2UJYrFaNlg2Nbqyw74B0xk8lq NG3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779229490; x=1779834290; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=EB72+GNLjTykeQdPDqWdzy0ATqpCM1uFByZoN9dOlQw=; b=YR8iRgZUFdkPsbxsYH+lfXeBKQ8wl9WrGYiYrWg+GbBrGSEOzIEx/lhxNjnFPc/Z0j +hc7zwGZR7XD0hxtzDigPlevabEMOe7ZpbILFDDr+dY34hfTSi/C7xta4JE79FxcXAmb ZStLNyZyhNoyQZlBIt6MMC+HncenzjDgNxv5Cl+qX0nY193lt4cIRNT76QYqlGzzmANA TDbuMA3XvYgq5GEOUOSP/rrPOLWny9gbq0uQLIDNTQ6QI0nDIS7TF5pOzb9ds3XSV96g ZPmjbXGh2IWEA2sbQY0y/p3zwTkMQUKM8peBo6v3frSJKkhPv3mslunIQ8I6UoEFmIUw 7hkA== X-Forwarded-Encrypted: i=1; AFNElJ/20CYIh8sjHAcijC40ASm7MksQxxQVNIY+D1q11Ybusygoe4gPnGPLamPxydSWSEgs6Yh3ut+SCu7/4UQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx83kCnH+NtQrhMbe65nz6XCCugcKk/8Lv3nFCtyVXueAbIxorI UjAdZEK7WPt07A5u70BBTVUsQaj1qkBQwr4MoTHYmXzPn6cLMrMer672 X-Gm-Gg: Acq92OG1pVSQ8LovMGpYm9IX7LTEYCzYFxN//bEqMGHEfOZyPs2lQLVzUrZP5xAtORs 1GfyDji3mYl6EGJ+4KT5QIWvekhqKqqz+Uf5xszjv64TZkIXYrV9aS532o2pfor88w65XGgqe19 krCPp4gopkv4T8oWhGLdbPpac1fTJ39KhBucUBxMPvqACv7QL7Td2/veA8IX9Lbsfs/XBHyCuIX iASbHSwhmohckPBXtVEneO2FEEh4xpf7974hWlhVNNIiTUXy7YNgyfd0Z0oeG61IDtDJtd+JOkD mn9/0urfNzmOp3jASEo7cQaANJx+OVpCvOzZMi5xT3S0ObLR6DntIIetHTTSFLozcBIyJ0m5ox7 DQ43YMB7tZCDI1MWPeUzZKC614umzooZqlqhobj7au3idOewG15J5T5tAloJGJhG+attAO//Hsk tD2iMw2OA8TwCTX6v1Oxni5M3aUi085SZcLkbAr8Sf2RrD2AnAQPIyuDYIYELVrIea3SigoiI= X-Received: by 2002:a05:600c:3b19:b0:490:f7c:b19 with SMTP id 5b1f17b1804b1-4900f7c0f52mr123899895e9.0.1779229489703; Tue, 19 May 2026 15:24:49 -0700 (PDT) Received: from Ansuel-XPS24 (host-82-55-252-101.retail.telecomitalia.it. [82.55.252.101]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-48fe4c834besm381097435e9.3.2026.05.19.15.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 15:24:48 -0700 (PDT) From: Christian Marangi To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Christian Marangi , Lorenzo Bianconi , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v4 2/5] thermal/drivers: airoha: Generalize probe function Date: Wed, 20 May 2026 00:24:23 +0200 Message-ID: <20260519222433.29684-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260519222433.29684-1-ansuelsmth@gmail.com> References: <20260519222433.29684-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 01ed49a4887e..864a01fd8fd8 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.53.0 From nobody Mon May 25 01:15:10 2026 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 B4B2D3EEAC8 for ; Tue, 19 May 2026 22:24:52 +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=1779229494; cv=none; b=cfVveFK8n48mmPMDO+pFeFkEqBEEfOPT0MFWPVQk9y74hYPlikp11LZG1KELzb0oel4yP7jP+6KyxshC+nuKWhUpcraNCiLA6IiZe6+CfZgcEdFpymYORLlCVybyAIfgnC9ZSS8l0a4uRkW7rMtN7ps0I74uuRR3fC7ipS8VMsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779229494; c=relaxed/simple; bh=OF1jcQiNuZ76zJkVKyHL6MQuNZTUl0y/mdnj3N/jK1k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hjf00B7G2XbbYs4R74/6EJcuL4EgzIbuy9RzL6DCKd/tqf/GyxuJkqPA4JdY2BljwDwUveb+i2BGryjW6HAiVPh2g6JJnLjVP2iWyJW8x2wsLNV28wdA9tm9/b7WET2xJ7hfGFYc4iEqzmHeGZE2vYzfD3JQf4hvAkBCV4km9ak= 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=YOEficZ/; arc=none smtp.client-ip=209.85.128.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="YOEficZ/" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-48ff4f8ef0dso47107635e9.3 for ; Tue, 19 May 2026 15:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779229491; x=1779834291; 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=JeJvbLLXeYwkiGt215xzsc9IViQy8pVQx2rwLoJOdxs=; b=YOEficZ/uxE8u+7DcSvo1VckuIUhBXxSQCirYRn2Rre72MUU7QmddIp+HliypWVhv7 h2R0wuFgNypZ9+uYeR25SP/IIZDSl23JXgM8rXPf/pMdFcs2K3lPagnEfEy3hmhhg8KB zS8m48YskyQIlWI80dSh/SWWVLJ/THq7qQj+M26P2WuUSaUm4bJcg6IKD5MbRGrw/JHC Xk9UPhGWVbrk10g3yEhpBzYX55ka0O+8SWJyDVBpIFXOaOzidOmnagHv2xi8snA/j4NS VHrmOn4A9Zkou0foGwtp+XDbPJYQ3h1TbR6OOWCzGwL31LW1TSvrVOSWalvOy4lue7Pb tY8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779229491; x=1779834291; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=JeJvbLLXeYwkiGt215xzsc9IViQy8pVQx2rwLoJOdxs=; b=fPWFZ9mndXpZGBPVpaSg5yR5oMRlOBCG9ubeCZHSDIdFWf2qcTOzHvgzGh1a6GJYJE CWXvwkZnSD01ZMBqKiukyDExDcQdxEljnQk30vCZ3gTNrjZUs0ocI3T0FDGCj8gCu4uJ Z8UXGqGazw11viPyMXHIFeAnLY1lHmk8PqpJHQPWQaZbMPrnjCax7o+6xIR/baS6mrFN KctdUG9Os8cp3SSqSmRj2RsaJ/mEW5+rhYqVUsrEN6+m/R1rTX/tmRu2vlmwdzmhSYxS pdeHWN0r9Z5ioamKkHMsCVGSOgRz814+Iqz9a18l5Uc5Tx3jyttgidUatU9nqBg3uUop oz1g== X-Forwarded-Encrypted: i=1; AFNElJ+gmgSMfuGqVtzk+nNeYyXDx9kjcgijHZdwss771Xy+KFkI8DAK8Lnqbccd+66r25jxBvfl0jOA2XYBur8=@vger.kernel.org X-Gm-Message-State: AOJu0YyoTmQn3ihJZgNoL9Goc3T5n/D2o1TYJ72hZ2JZRgbFrDRnB1yX sWPjpb3ufiaBfPERAGaGAjIOajtPmL8oiJVt3DncEcvlzHSaGfBR1Vca X-Gm-Gg: Acq92OG617Btu/ZuA2Iq9wnjyNXrlPgq7jp+47aXStd0nkhw0KSYCF3GV6xbVZ+W+vu LXutMu7POJrNx6r7Hd4UlQ9jqKkBzc1vhYFFWM1u2FMJQkVTXIiecJJSBXotbzak5K8FZjPD1v9 GnNF2/bn9krD+WhF/3n3GC3mgtDKwqcbKWyBcDb0kVcen+2X8gbBhBaxN2kKSIbgfhW55AEpXOA ZrqA39+E5ylzQrLZ+3VGpBdXr/tnCSigaM6MTqutmHSs7ojSpVLajsvE6lCL7PjbJyUafQVj9Mc Xp1OoVxShKZgTgmQIsssKf+YE+JBqy22NLCqztw9lKzzbp8KRyQzoCUbbceTbwMzCiDeKzSyfmt 1bNDo1d9Ou/vXgIfG/v4EMj3eWC4FBP4BpWo+3QQ54Qvat9JIbaetEE9qn/yc33Kwx5/OdZ2Glz jgmHJKGyH09BvaGFdv9n0/Fc160xIkuarskRDaKONsCrpt2ameqx1WcFAMpVnefjWvXB4IGSc= X-Received: by 2002:a05:600c:8905:b0:48e:5d91:cffb with SMTP id 5b1f17b1804b1-48fe60e7d6emr273378365e9.10.1779229490937; Tue, 19 May 2026 15:24:50 -0700 (PDT) Received: from Ansuel-XPS24 (host-82-55-252-101.retail.telecomitalia.it. [82.55.252.101]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-48fe4c834besm381097435e9.3.2026.05.19.15.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 15:24:50 -0700 (PDT) From: Christian Marangi To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Christian Marangi , Lorenzo Bianconi , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v4 3/5] thermal/drivers: airoha: Generalize get_thermal_ADC and set_mux function Date: Wed, 20 May 2026 00:24:24 +0200 Message-ID: <20260519222433.29684-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260519222433.29684-1-ansuelsmth@gmail.com> References: <20260519222433.29684-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 864a01fd8fd8..a062922cb116 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.53.0 From nobody Mon May 25 01:15:10 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 9D9F03EDADB for ; Tue, 19 May 2026 22:24:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779229495; cv=none; b=auPIgm3iKsaXgSr+6K1+qbN/skz1MalCBxM1wjDLZgOi7to4fqUb7PcQaWd2HwX7Z6kis8SCBHPt/W1xDTJUOZpJMJxmnIVtS9sl1Rdpt++2FFSbY4AGtegr+AtBava0r8iixOVdC3Q8exelKf95+KnRAJGA4eQ/lqrAcDUPqtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779229495; c=relaxed/simple; bh=7KRlzQ/CYy0m0GRFXFkovzRgNDiKVQyaq7IP7YBW5eU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lhg2iZBjoy5XLcAA5xKkXBpjDlLWU6OHfv2e0O0ov9ETUCk39PQMvazIErHRgE5rCuGpEk1TUbJS3ziGlKnyurySm0oeIku0VDpXWKdMYtEzCHa3PHsU8/4N7saguHqJRt4oOyuRUxLzTEyc27I/dIgaxUEPzh8bFCVwJ0PkQM0= 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=bqbO7TpH; arc=none smtp.client-ip=209.85.128.41 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="bqbO7TpH" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-488b8bc6bc9so24332135e9.3 for ; Tue, 19 May 2026 15:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779229492; x=1779834292; 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=b06Obgvy88lKtCoTzccRlIplQ4+h8fmj3ZHd9P9fJhI=; b=bqbO7TpHQvMXjVuO5pLHhPQ79Fk7Qpq/wKfrshkkNI27kf373/AkVhUrIuU57wX9ng VYAh8j2vevvBqXhE4g9ttiYjOECCwsdaKMsx6KnIIxmXP2Ymjatl2rgReVk02w/ievZW P1Egacr2H0xYoVrpWVyDrq+Vm+K5o6yElYn2th658PKirPpHElmhkxZC0vayauRIWzlC 4EPatbU1Vh4TJpU0z9fjVfjJm4yudRqpdGDLHN1lxhpsjKAkMTb3uEwSWhJ5p2h8Cu61 kUaP0KpmtHpxv85yEzwK6nG9+HmL8OKgl1+jp0w8fTc579wdCQLqrtuFlqh3LF2esJKH tnug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779229492; x=1779834292; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=b06Obgvy88lKtCoTzccRlIplQ4+h8fmj3ZHd9P9fJhI=; b=enXn3I3wkc7BalzSWlV4Zh7tcMLIxUEuFTHvwHUDWHmoyFybJILVF2MDnoSVYeLFLp 4/8E1RnGTAqY01N9pj5+wCGBKekAz15lGJRXkED+fnm9OM8VzmoLIblXdrsmB36TxITy YMhk1B5H37rEklZGyWzaDjd7Q8CYxKVmopcCgTwjzLHjYBHfRJVDxADTFlAf5C6+m/dE ZEQnd0DKs1Q+r7Fokt37UX70imuXvhLpOufPgMu7758CuKTznJLgNKTUZFd9NNuFuv2J O0c5YWJHygXO7zHTYLu9lA0lHDiQdobG9fS3xOohTvlaeyQpWQxcbZP5s3x65U9iLVS5 2sdQ== X-Forwarded-Encrypted: i=1; AFNElJ9qh/wfoKpwUCWtKXZRe0XMp8ousLtqOniRhdM3ybrdmhruAHjlUfuDX7/M88XRt2LBkIYHZd+p9fk48Gk=@vger.kernel.org X-Gm-Message-State: AOJu0YzxuSrAJKs2sabTc3SxDDnDRChrS2Qet+O1IAWYukSDoO/548qN MgyoUXOYGZobvHJFHSdin6A1Nbrf/cprAZ2i3cpLSDRu8Yh+LwB3ez9+ X-Gm-Gg: Acq92OHTNar0CQvcF84vY+wVJcF5nevQUHHR3h6K8uwpgAs5RUs5I7E9XZjUnF64KO8 TjmP+ZBwES+JoQ4NxPMebHhF7bmhF5o4xrNCi1H+pasEi1B6fPA9u8F2FIHCFiHNipBx36NgwaM OACqTwER4sTukePanEe3E0DGtxaBhmienAoU82tx+Ni9XQ38RnBOIZWPL/XVD9X2nCynnYP0Z8V feBrNCSvJCYZKQ+qpybJytAe8FR/F1OskZcTSG4UsAkjdGKtTLtwwdX8MYuVHFAdJWmqS23rLAK yQXXntAKex1Z+fUWL1Vnm/ZPNf/+NEOOrK5dEjxZ7xeLmf0iIHjmlPB8DkOCDmehvn2wK75ikNv h4repBjZNZZrRYVQ8Mj5xZIFfKntCc/ZVvLU2wdSNPmF/ZunDj2X8EH7CJpdMj/ztiRSIiTlen4 FYP796yS6X6qayTOrsICRQgjFTwD5lh374ch66Na6lkFsaFFaZSW+u5Nv6USzU/EAiAIo+WJs= X-Received: by 2002:a05:600c:34cf:b0:48e:5990:9698 with SMTP id 5b1f17b1804b1-48fe651588fmr340150505e9.24.1779229492142; Tue, 19 May 2026 15:24:52 -0700 (PDT) Received: from Ansuel-XPS24 (host-82-55-252-101.retail.telecomitalia.it. [82.55.252.101]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-48fe4c834besm381097435e9.3.2026.05.19.15.24.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 15:24:51 -0700 (PDT) From: Christian Marangi To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Christian Marangi , Lorenzo Bianconi , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v4 4/5] dt-bindings: arm: airoha: Add the chip-scu node for AN7583 SoC Date: Wed, 20 May 2026 00:24:25 +0200 Message-ID: <20260519222433.29684-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260519222433.29684-1-ansuelsmth@gmail.com> References: <20260519222433.29684-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" Document support for Airoha AN7583 chip-scu node. This is similar to Airoha EN7581 with the addition of the presence of thermal sensor in addition to controlling HW PIN and other miscellaneous pheriperals. Signed-off-by: Christian Marangi --- .../bindings/arm/airoha,en7581-chip-scu.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Documentation/devicetree/bindings/arm/airoha,en7581-chip-scu.y= aml b/Documentation/devicetree/bindings/arm/airoha,en7581-chip-scu.yaml index 67c449d804c2..0d042fb90a78 100644 --- a/Documentation/devicetree/bindings/arm/airoha,en7581-chip-scu.yaml +++ b/Documentation/devicetree/bindings/arm/airoha,en7581-chip-scu.yaml @@ -18,16 +18,30 @@ properties: compatible: items: - enum: + - airoha,an7583-chip-scu - airoha,en7581-chip-scu - const: syscon =20 reg: maxItems: 1 =20 + '#thermal-sensor-cells': + const: 0 + required: - compatible - reg =20 +if: + properties: + compatible: + contains: + const: airoha,en7581-chip-scu + +then: + properties: + '#thermal-sensor-cells': false + additionalProperties: false =20 examples: --=20 2.53.0 From nobody Mon May 25 01:15:10 2026 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 30E573EF0DC for ; Tue, 19 May 2026 22:24:55 +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=1779229497; cv=none; b=q7yyLKyamc3tKd1zOOKRGhsYAJsBWX7Z05CEj0SUi/6THHZkTv70SxxDWUZOQBqHE0hNhXFyzi+EP8fU93KyWmQOCAlt2FKOHLpqb+5+2+I6bQVXhOB4UK/4ctvpewHhTPSigDZrPLkSDQD9XIwC6nlcTSosoKn+4gzkOT2x0SE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779229497; c=relaxed/simple; bh=2QrxJ04gUsivjRWmGX+lX65XI8PHqJkzMXBht0ubDxw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kIjpptz7znxGy0NzSAU3FmWkVqgqDLDp/IuYciwyDhNoMdSFPSi+g3BI+NZdEa0mvLvVaLNrWnKCqmXvzV3HMOo1zKm+Hf9eqxJhK/AmstZONM47VMddYm9FHdVLJKaBDAnL2MazVgwoCpKe9wkB3sNHnhz5TYn2Cwkkl6vGGBg= 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=fFlp2fpc; 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="fFlp2fpc" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4891c00e7aeso30679735e9.2 for ; Tue, 19 May 2026 15:24:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779229494; x=1779834294; 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=/Y1t2qqzyl1q+h7yDIYdn/bWsIjxK4gxr9iT28eZ+QM=; b=fFlp2fpcG2urjonZmanRBahBUdlVCfbVxwQo7sMI0nrcr5oJRJzG3uQINsrbryloNM EYyAUH80vFDrMLt/fK692ZXagjh6nElrA0qcbkdFRhxEs+0Zgzm1XRoyLNM2dQnzXhD3 OmYJ3W151JAbBY5bL4TpUf7BkcGB97yipjcGKQeKgRkRrA76/UXLy7dlbHFtJYobCNED L1NPiHsSJ8wGYoanh610sf9fL3GG4CSSNP9ExwPcoohS1b+O8gdqLD3ljcyhr/r0VaYn vkGQrh/AGLI307wco/9Scj1PFMbRoSZxZNCttPkwkcDyaZMi97s+rSo0Pn9Z5S6uwEBC 1kkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779229494; x=1779834294; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=/Y1t2qqzyl1q+h7yDIYdn/bWsIjxK4gxr9iT28eZ+QM=; b=L5A40oX8Mwc7WjbSuvHxtyF5i+OYWoBmcIr0KTpgxWam6Ut/57LLnXsAPm5C26EY21 nW2RvEDJxIMThRWmIUfsSYARQRLDNRBasCrsXhrFkXiEI2QWVG7wq/ljx4H4U+/h9ni4 gRommyx/0V+nrVofX+D3p+NqS2+SrdThRAWKXxbeIUJxqjOiPIDHl3pOHJ2Qf/l4BbGb NvpgIOOBpzrw7imCbMt9QUZvXydVIC6hp2cw8huHJ8cQOxtdFhVt8fybasAyF1uNs01Z mOuo4ipeD0oSvglJW02eixLYx7ivHihta+9CovJmHxv2udhuokgdxQq4d25x43Yaf2YF mshA== X-Forwarded-Encrypted: i=1; AFNElJ8My7lb95ZbjzGBiVZMVzPFgwudlaAi5cXR493HTmbTxyOJAqkMkrK0pQURVdrL6nyY/98/fsCT9yl+xs0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxw7hVIhkleqauf324ayIV7iYWlfXujVyPONG71tIoZ6C2sRJgu 0dAovCVXUaJcJ7OcsCzSLoVHOtA211uq5jdkXNXRLzUlNz9hS5/85e6R X-Gm-Gg: Acq92OFMK9ZxZjS+82KlE5uKSoANFPJv2KyOUpeqRI1J4Arpx0O98ehzcUZicIloKrD ms0BrqiOIzlV0vPV7imSd5J1hy132hFibWlV+Y4SQdwd5MWPu4tuvtquuaLb/uqtB5c1Mmw7mRg 2asFIrwniwremlvYq25vNgarZ3a4nFtcy+aBxKzNENNX7qrS2pOsN+aDyKfwFiXQu0C9/NjF6Hw WW9Hg71X1VjU64NlowWPurBTwKa0HWEBzFjrbtRGm5BvYS2dxCPLfl1xGYTLDQjiebNcxdUCZ/j F9xvYzHrN+NksTUoy9MYVYPJS+7COdW5HgjxuMhZ8vSAc8YmRYB1ftHvRgo0YXMvq7lptOhv1rm +aF9u6K58BCi+/KSJEe0+Ac6xusoPKzkmnZKCibMxuBhC+a0xDN7fZ/aH7A/FfVQD9JG55+NLkX JZeZPJ1s//0pZpZQG2/jHrRWYJ1qll6hgOSDq8pi45EcMRdLy7pHhGp4vo2czYyag38FCVo8A= X-Received: by 2002:a05:600c:8189:b0:48e:89f9:9408 with SMTP id 5b1f17b1804b1-48fe632374fmr318299645e9.20.1779229493377; Tue, 19 May 2026 15:24:53 -0700 (PDT) Received: from Ansuel-XPS24 (host-82-55-252-101.retail.telecomitalia.it. [82.55.252.101]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-48fe4c834besm381097435e9.3.2026.05.19.15.24.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 15:24:53 -0700 (PDT) From: Christian Marangi To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Christian Marangi , Lorenzo Bianconi , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v4 5/5] thermal/drivers: airoha: Add support for AN7583 Thermal Sensor Date: Wed, 20 May 2026 00:24:26 +0200 Message-ID: <20260519222433.29684-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260519222433.29684-1-ansuelsmth@gmail.com> References: <20260519222433.29684-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 a062922cb116..c190b696d3a8 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->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-chip-scu", .data =3D &an7583_data }, {}, }; MODULE_DEVICE_TABLE(of, airoha_thermal_match); --=20 2.53.0