From nobody Sun Dec 14 19:21:53 2025 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 6048C3016E1 for ; Thu, 6 Nov 2025 22:59:40 +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=1762469983; cv=none; b=spShm/g4fFQy3agcRt70kHGP57t4cG3jjKSnciZ7zN93FVGVK/uLZ6LtyAG6VpQjqcEP8wqYjaa0OumcHlw6Pw+abqjNAaxJb8yS0hGytjxHOqK604nZCgVYwFDjb/7dkXOBU79WTSe32s7GeeXU2skYcNX7IpcQUpusxS8aPX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762469983; c=relaxed/simple; bh=jPfKF8pnLyQ0CZOQltmMuX5kCAPhjPVB3UjoDZYqqDk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=samWh8bVGjJl4ngjKaWaOUbey7ZusHtRWPAC6pW8sIgkl87VkbUUicM/yv0GnE5oBkCmF2W7LdYxcJ5Q+iaOemE3RsryqYdIanIjLsvNxm5pdqQJan8jywfhyk/4y7qCt405WiS8Nv1BRe0ieVFgC6kopCEwcuJOIUp7H+u07TM= 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=EPLT4HXQ; 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="EPLT4HXQ" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-471191ac79dso1385025e9.3 for ; Thu, 06 Nov 2025 14:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762469979; x=1763074779; 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=DcNqxELVDSK7RhV1ekY6lA9dpVwVz2jR8jDfVBLjBqs=; b=EPLT4HXQQzKHxbiJ4oWgcMwA4lJHoK8M7RrHcCAbtTkvq2sXlWDTdmv09PYb43EeDL tQw6TNc35NEqdx5wxhgzEJhcwGYWaVZ0P2bojD4WCp0wB8ogXYlmjjq6IozvDFR0JEmx 4nUPqPkhYAi1xNukB0JFk/46Ru8JhCcbKBIhgYDym7G4+vMLW2U4ATHPbpLjWQojsNWL gRppItFjigSTYb4LfR65pU49WHn32mTfbf6CE/TBKvo+y3smiTR9lh6NxYP14p2f8rpj hFAXhMdVKdwvT7eGfGiCPmQFMhJNPyCTwOKIAXw03eVZYFkt3OgaQaHx51vzvHYUQoW0 uLog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762469979; x=1763074779; 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=DcNqxELVDSK7RhV1ekY6lA9dpVwVz2jR8jDfVBLjBqs=; b=LqaT/r8wvp0SWh0VEGDQ0UAwMXn1ElBBSj8nBfs6cO1a5yPj1x6ziDY4+PEBwl69r7 x8ET/Wcy86ols+gAJIctLa8VzB9TQN/9mwd4BOsxFgVxNW9JSS1pOokNXh/FDq3xhxBl 9zHGwgR5ls/SNcejMB6HyauBgdJ8D45CGqfeyzqOirf11MvQ6v8OkPWjq1pGYPw6z6T/ ND0nUHcYhNyC4aWfyGVQXkptHbjGhRAU+axYkvlOImVnEjy21kmuuYYhHIKdJadHuHA1 aqrQdN+sD/Ql9Qe9FbeZKIC20WnrhaZOraGlcNUhlw0iBomfNWHjIibNgn7TaTJnkRTz A8bA== X-Forwarded-Encrypted: i=1; AJvYcCWwBDiiUcg4btfhldXhnjHwfwY0YGtdF5pnqqHKYP/SqhP6okdrxq4M8eh6qTZf1rrSvAjJQ5pIPMPb6yY=@vger.kernel.org X-Gm-Message-State: AOJu0YyfVdci2oY+Wr6K8aoRlt/ecF6GOeUws8tRQD1cHfermwaXGUiV glJpL0MY5HxFbNVVL7qbPBEfGCNa7g7e75vgK9jpde2yqJ30qx8Ylc4a X-Gm-Gg: ASbGncupgT8A60/XgKXTeMqcefIuHj9BnN087++wpe83/F4P3be/cpRBpr7gY481ylx W2ZPsfmbUSDIAha+8pIs0xT5ZOmqHUB95LjEVLiBS0EVu3aGgfdgmbomecAFq8UXbapFSSjh0Sa bmHfq89CiKJRMnCeVjIoU11+mHkvHMtk+hRKEm1JHOQ6c/173NZDcpcV9Z0d00LLddpTZ/1FJ7V XiUO5afex+RLzeEbjwKnAldrIBwWvykefLDQ9Chb9cnpNVv3cYrawXj5JnW/lVuFt4XNCqTSCqB DfXkLeBl403TVLdOX2vdZd1kGNtzU1fdg+42Cfn3LO90rmOxJLtOUY52lp4A1NBVPccxuJHdmBU 5jDn1ZCWN1Zo5nqvMAiZjvn84HbsE4TVTZhbhoANgJmMyOsX/So3L3Sy53dnnz5YN6w9B+ELXXG Y7q5Wb1yX4r0rjKX6r6dT32pNw7cv+RA== X-Google-Smtp-Source: AGHT+IF0RVDx0rGAdoRCaZtp3Ji9kzDVVQPOYw+EacR7N0DDTcC02D7/7z7qNkmWA+StqlM6DGi6Xw== X-Received: by 2002:a05:600c:b8d:b0:471:115e:624b with SMTP id 5b1f17b1804b1-4776bca4c9emr8667645e9.17.1762469978539; Thu, 06 Nov 2025 14:59:38 -0800 (PST) Received: from Ansuel-XPS24 (93-34-90-37.ip49.fastwebnet.it. [93.34.90.37]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-42ac6794f63sm1640000f8f.42.2025.11.06.14.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Nov 2025 14:59:38 -0800 (PST) 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 v3 1/5] thermal/drivers: airoha: Convert to regmap API Date: Thu, 6 Nov 2025 23:59:10 +0100 Message-ID: <20251106225929.1778398-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251106225929.1778398-1-ansuelsmth@gmail.com> References: <20251106225929.1778398-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.51.0 From nobody Sun Dec 14 19:21:53 2025 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 5C9FA34F265 for ; Thu, 6 Nov 2025 22:59:41 +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=1762469983; cv=none; b=D7BLHBLSuKJ+btBiEVOElthhINqSf6o6c17XLrXjEVNxZlP4AbXe3TaCC1hXH2O6tMMxG4ZVy78h44QF5Eaml0CsYyYagSPZVxu8Hs2BNQbfp6oWgS9Rb81Fc9a5dIO2ERRjUG61tqm2Rbn1SR/2WY4e99+rwhbPHwcOheokUoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762469983; c=relaxed/simple; bh=ov/G0hDuU0nQGs+JmamLVAzk9gma0Qv9zbfpoNew/Cs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rxh2e/FIrwuKcTzy/lsIYq7SfslCOvVVlo+25SH6WcOqHjZkTtGKZb2MLV/DSiLNYMP0o9WW3SZw0PRxiSV56YpX7+6lMbE6ZEf4ohe9ZAEinXiUDIzaBB+m2VwkCYctnICBzmOaV3v2ijyHLaQdK5fMn8V7hzYLihNbScTHiRI= 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=Ju36i+jW; 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="Ju36i+jW" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4711b95226dso1324225e9.0 for ; Thu, 06 Nov 2025 14:59:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762469980; x=1763074780; 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=7cVrYKCDf26X1CEz4gIXYqRKkJM6oG31pvZvMj/HDTc=; b=Ju36i+jWY2o0ujUWNVQD/KwGDxN/67Ih0ZnFQSyROePAi6Bk6T1qW+ePwsk944nvgP Cn8vDiSwlXBHQ9+JFnb8hoRpbUq8yhBMlRPuUJdktFXZArM2JBZyHCdUrlVcQw/cfqew v6Kgk27hyIXiTyIASVDjNvcZNgZ2KAHgqXPQXV6D6n7/4R04SQ8bgUadXk0/2AvgPWck Si7pBpcS9E2WKgsflH7acFpgiLqxZe/11PCR3AfQSrTVJ8I32YkJlQnvui27SVKnplJj 9h4UV68bry8cPBMTLES6cJNTiEx5xuF0GWjUNyhjyxiM3Kis27qJJkPGVbuy/k7goVSD 0o2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762469980; x=1763074780; 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=7cVrYKCDf26X1CEz4gIXYqRKkJM6oG31pvZvMj/HDTc=; b=QhStfrZt7x+qfc/zxoxUZ/ojxt9Wa12/e5Z5+zPOv+xnwS1npJPbo2knjvjaOUWExp MUN/Cv0Gd/PW56vbI55EjXUp3GjwYv33unF2LR9s93BduDelWRWNlYgmCCtl3JTajeJP W7ws/Mi60ccqRhy1lFzVi58NnOcMZq1S610OpfwUBoEs9GW3+RfG24/Y2zFLsBab6p6i 40hkDzP5bM16+lrnqkT+3Ze9OT8OU6cU0Ki0yhISPvdH7NVCjFWL0fnEsEQjOl38NNa3 ERG3NvO9H+y2sf9Y0GxTZ1y9GDIfTakhFaIr1ZkwseVovFkdhlvd7ecDJ69N4eiVkNEr l3tQ== X-Forwarded-Encrypted: i=1; AJvYcCXB/VZRPgvMhxxFseIaFJlnqIHlMzFHH8EcAgMCv9IIdWy3kIW4rT51/WMoAemZLF9nxLj53Wif7ayNWgI=@vger.kernel.org X-Gm-Message-State: AOJu0YxKejPbbxXtg9mJUaMbA0L9HP2J9KCpgNmMk+rp2RPqN0bp3eTy QgNkLNAoehv9GfXrmJcFAU+WEMnwjr/Ui+cbnne4BwZPTU35nHj3Toum X-Gm-Gg: ASbGncu9IFLnsQtW3Cwvc7mVzdrqEPGc1a8CKPoFxnkjmzqu3HvVYceTWm5g9u5NyU/ n8nZQzdfA6P6wlg94oyOyn6A8H8bmNmw0Tho2IRFN/j7ojTgVcAEios7MFjeVxUEGENgjMdOGWE VjOCEJTIn7MZZULzrmBIoW4LCZSjyZLeZjgPO2WxT3nDYbnAkfjBgnGTJ1j57zEc3OYY/FyIQER 5hAworvjYIaGWUyiT6wIBNdglbUTc44JAq31qpvZqliYe6lM6mHvU3QUnMMaxt44uIXX+VJFw/X mu8G58k3Mb8l4ptfLpVbaxmuWq3GeUQr74wMitYulYs+kATDrHwg819jOT3a0JgseMrqalAV/9Y Lao53bvTikPmCU9bAH71p3xEzwUMz0Q6xmYKzu0dh0QxdCcHvi03SJf/cFh1BEyOxsJ8A9TSad4 Cwccn70OLmFGC7+gv0DExouoJI4RiCMA== X-Google-Smtp-Source: AGHT+IEYNkiROjyYi24J3DgMM8wSu9Ju/AT9fVlW79l7q+ZTlrVR2euaTguLNQt+vAS6VM2MZVpojQ== X-Received: by 2002:a05:6000:2209:b0:429:c0f1:fd39 with SMTP id ffacd0b85a97d-42ae5af4c6bmr845703f8f.62.1762469979625; Thu, 06 Nov 2025 14:59:39 -0800 (PST) Received: from Ansuel-XPS24 (93-34-90-37.ip49.fastwebnet.it. [93.34.90.37]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-42ac6794f63sm1640000f8f.42.2025.11.06.14.59.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Nov 2025 14:59:39 -0800 (PST) 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 v3 2/5] thermal/drivers: airoha: Generalize probe function Date: Thu, 6 Nov 2025 23:59:11 +0100 Message-ID: <20251106225929.1778398-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251106225929.1778398-1-ansuelsmth@gmail.com> References: <20251106225929.1778398-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.51.0 From nobody Sun Dec 14 19:21:53 2025 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 892393502A9 for ; Thu, 6 Nov 2025 22:59:42 +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=1762469984; cv=none; b=MBs1zfV+8/5gomUz39JwGU3RfomPO+pU0EoEs/G3eP++4WxrSp2BPspqydx86FUQtyXniwZJPpI7mHZ8V6DP6RiN9t1foid4bCQucO0C3xX+uHWIqwPQ/NWmgc8Gew+mPiCw17AAGOzUY9qRp6pf26jXppf5Y01lolG4FY70MhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762469984; c=relaxed/simple; bh=ufIvFFHkbZ8SPrXnxKoHOjRLGsK5oIeuWrLoO3TsjPo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MC7v9EZZpto8yJzvRQSFD5yZeXl2vc1aNXqrB4ZjpWvWzq9B1dBv294LaXrsls+Zc2VmNAFwgsbx64NiY5vXG9vPT7lrZv22GQCO0dpM643yHPXV8C5sT0Ee2tHE/9QBwsBIRIrPOgiY7Vx6g8bTtq8oVO4FUbXFWsNtq0T+vQc= 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=baOr273e; 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="baOr273e" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-47754e9cc7fso855805e9.2 for ; Thu, 06 Nov 2025 14:59:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762469981; x=1763074781; 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=E0nJS+a2wrY+OCu17/ASVfzPnVrSQorpggCTxleeXyA=; b=baOr273emL1VOWOYd5H2sLS5BkdoGrVcuq0yI/vbNulhl8W5DpxzvSlOhlgrtbYNIZ CCzYYtSCUTYNIP/5lyiSNTPvdHR3iN2bxaocUliaSwVCiuHdDPTVw2MrxftO3j5TiGHm jhU6sc2HJlJb9hLwRaDD8e/o4t/zv8zrwYRcA1NzjCqboo3QTayGef6qTRVuUYS/Vspl vCXGpF/Meg4W5RSfx3Nh+6YRWyK8waQNzjIDhiyYjfNsJ9kAT0Tj8r8eDM60ntW2BQzP 3yGbymwXYlwiQAGmOlk/i3hsysW6xIw/5pjgu21gl+W/on/p7DPO8LlDd0A0t9d7Ylhb 1mWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762469981; x=1763074781; 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=E0nJS+a2wrY+OCu17/ASVfzPnVrSQorpggCTxleeXyA=; b=KeTNvPH3JiA53YN6sSfqsJV1TJPKPVD4//Okvf/xdSRBWIfOT0cydUzI2/9E/N5C1e TKhBQOCdrURj06UmBLeFWhT6ig0IvgQXPmUQGd9082KVp9pR0P0GMhuxfny3plqZ7a0B M/vVN0Doy591wCl7b8IghULruUGjokbKFSpTTt+AZ2FH8d3+TkKLSPQt7J6pmXGO0jYw jWQYPppII8JSzNS735YryrlLxf/i/RcCkrSy0GgQWPxZvgnr373UeaBgY/Tx9pav+CV2 nQQ6ltSJ1Cyrif/gIDaaaRaXZI4j8TDpQ1sFAT7GLg02aLcctJiBwgs7mnLWM+l7uSKp oZdw== X-Forwarded-Encrypted: i=1; AJvYcCWPguQOiDgtWlnewO6VoGD9ONkZqXUwwX4gp3wCcgynatVLq2Ea6+8hJdppnvNphLpgzzLofQQQ16qRjvg=@vger.kernel.org X-Gm-Message-State: AOJu0YyYAnBB8zlNPQp6llSaNQZlvK/Nb/ilh72OGW1ZFQ1PNHZ4+P49 lME2mveVNFgjVNIR86FHGQdrDCucN9OtfTnqIRf6RxJDTMx46EYLzbXl X-Gm-Gg: ASbGnctujNRSssecFwnBJhqUGegoXnYG6nSOvW76iYfMeeDoEeru8t5OdiLMIuz0zv7 dXfk68OUu0SSkZYHCJJvItPk0qkesyAeLNOaUdcms2NB+6/JwBIHx7f8yOkSqbTsv6cofwvCDXO RZsztv7NAB9XL1qXa82vpl3a/VvnNlOBt5hO0G2Ne3gYCmHU/15bDCBfkDhD+VCz/+LG0ue3BV3 /LTQsroIrqi0ixXT8qnjm4N8p7MwFmr+/oFlJN+M0twnZcqcqH7a8RbnR5uMjvsSpHqz68fGf3g mw3T4vKbiD0EISxySOUwZGKqHnFIMkSh6uEJK8BYJO4PqE5zwTSGTm039sDGEvqvIYEKZd4Rsi9 A03qdV6u8pqTb0KP6dDcqSzyMWIniR7VbBvu7NbutziS7jesvnfRE91EcaFxjluPpkWkSXGR7Bc kssWosNwLxqsyTyeoJuXvsunWqGY1EQQ== X-Google-Smtp-Source: AGHT+IGP5v4e7GyVgRGWXfvWoW/ZVT1r9DKTfFFQz7PGqnWFrENBgTn+y3PnZMBKWoKvJ7AofF4Vhg== X-Received: by 2002:a05:600c:46ce:b0:475:da13:257c with SMTP id 5b1f17b1804b1-4776bcc369emr7344765e9.27.1762469980616; Thu, 06 Nov 2025 14:59:40 -0800 (PST) Received: from Ansuel-XPS24 (93-34-90-37.ip49.fastwebnet.it. [93.34.90.37]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-42ac6794f63sm1640000f8f.42.2025.11.06.14.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Nov 2025 14:59:40 -0800 (PST) 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 v3 3/5] thermal/drivers: airoha: Generalize get_thermal_ADC and set_mux function Date: Thu, 6 Nov 2025 23:59:12 +0100 Message-ID: <20251106225929.1778398-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251106225929.1778398-1-ansuelsmth@gmail.com> References: <20251106225929.1778398-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.51.0 From nobody Sun Dec 14 19:21:53 2025 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 0B7A4350D74 for ; Thu, 6 Nov 2025 22:59:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762469985; cv=none; b=AoZIpaNeBmxo/D8LUq/toacPMMQv6pYAaCTJjXBQdRmyBrRkRJL/hIMstzxZZApFF/I1krdGPiNQybh+gVCn9umba7oti/jiy4qIeTSS5FfI7sJEAnrH0qQQRzVac0G3oCKY5cTDAxTmIA4go5KjZ4Ln4QgpNdjfzq2LAL+CJPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762469985; c=relaxed/simple; bh=+bnTZyQICeowwwYQLMCKPFQJkT5wEjHLAFKEoSLLAEo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gsy1ypE7/5OpALtad/CY60iD8fCPOeqgnn/XSzA74RS4zkLjDLP/qbTTyRRz+joUKQVwh07G4Hv3rAGjKUu3N2X3oUWha912tchXhzLTy4VTmJzLChJQ02+rF+6ixbMMtR4hzpR3uqY2rRL9j+/nvF4dELDwfXYwoB64+S3UJWg= 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=lPtDDeTy; arc=none smtp.client-ip=209.85.221.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="lPtDDeTy" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-429c7f4f8a2so64688f8f.0 for ; Thu, 06 Nov 2025 14:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762469982; x=1763074782; 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=NL4ceoBRc0C/nkwU3+YZ9NqssX+vPCISopwMoiY25Rk=; b=lPtDDeTymU1Cq9i7xi9Ofr086SvH9UbG6fwuxSPYHHfutqa7RhLwbJFZX2E49uInUB cucgAlG0+jy0d5C/HGyRPxahD7BPliPZrqaHzd250EjpQi7muKfPuYDdbILKdEcWEWfk PDXLGikMzapMreuVOXL7KrlSKz1yz7J04teHI2vupCG0wlpZMIRzh+0wY8GzX+5Fm8L2 Fi50sSIbmATjIa9RtKjePrAqk2iTv6DYCVEQYQiLYol/vOAsqWCvJiM4yLzXG+QFaA0k m4CgS7sIahDmsTiYdtMO/gVcxvB0By3YWCnkKID/3YwDaw1AOmqdORXao2kB80Xyjzgv TLxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762469982; x=1763074782; 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=NL4ceoBRc0C/nkwU3+YZ9NqssX+vPCISopwMoiY25Rk=; b=E1hk0YPRIRJ4DhT8771n9NcTvGnD362rDI8qiT0cL+FyduipAxCATS/YF+S3/QiIVN 5qGzUvVspjGUumW6NrvWcM5VTJOGOskeVSA5NJ8dApdNsL7r+zGHUlBc0dfmYgynz0nO i4pngq1WMF//iZZUGCjx05g9YelN8MX/EotR3YqD1CJCirou6N5tGzZQFAWH1+1moXHk hjOSk+EpOx1A+6B2Xw7hjb2kWE4Yxjtv2D+a6Zj0qyrlL5B5QkHNCHwWg/WsDKvSxd6p 3GRzeTKdRUR7xdtSeHd0BPYp5oCEzpGeUTkHt/x0aSYKNSYfZo9VGPyAlS30nja9nQn8 UxBA== X-Forwarded-Encrypted: i=1; AJvYcCUy1NdVBKns8qeIrvZUXa7vVI2d813dW615rUXvN2hSKG8tP2kMxPhk/h2k02u/8psOI/3SMkx8Bu3zzxw=@vger.kernel.org X-Gm-Message-State: AOJu0YxOBq4VZyLeWj5NBG6iyGQiZXko/UmP8+BVPXf6/5L1WdAS6Njn k+RfoH6DEmsj7PL0jr4IAHlV6p8xM1Mx1XZEUaxCAZ1zbkDG4ckZW3PN X-Gm-Gg: ASbGnctfyZwCuW4Mr/tONGES+HIK9Mk64BDTa7EthCKXwyAE5WuwR8VGZKxqCibybtC nMdyKSyPyQBVMSGPhMXX4If3tGrv95ZE3zohS2d1OWEW1n9jJeD530jgqZvWctVJSIzd8bpdCxj n4W1bgu8YzeZ9PPI6TGG76+lEaTkCgMHEkJ+BM70QCw1EI1Z2fgbxkwNerLiYij+bAFaY/n5Z/h AKnx25rtWC/QwZqhL5z7JoaqDu0/wrXiGzIOAtm0X0lL5J4KqXj6tkS/viJZA+zl25hXnH5tuGC 0EC1WoDhz5L8vK+wa5l+6aqXgSAorsMssNlersR6odAcBljs0DWYQASQgHnYSveIT+dluR0KLHx KESlBBsr4H3kIWu7Bg2Sg6NdH5ZVouwjiN3iLaIZkL8BUaB8NI4XEpn9LUamyP+biAvgw/P7DXq rxgvUC9wczcGtT2GZ7iL9U/McZtkNVoQ== X-Google-Smtp-Source: AGHT+IHaRadCNFbOU7XwnhOefNWC39AvuhSs+DGIQ7TUB4uKubfoPpSUFGQJuVgfwconMXMRFYM53Q== X-Received: by 2002:a05:6000:2506:b0:414:c2e8:a739 with SMTP id ffacd0b85a97d-42a957abc0fmr1388930f8f.31.1762469982247; Thu, 06 Nov 2025 14:59:42 -0800 (PST) Received: from Ansuel-XPS24 (93-34-90-37.ip49.fastwebnet.it. [93.34.90.37]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-42ac6794f63sm1640000f8f.42.2025.11.06.14.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Nov 2025 14:59:41 -0800 (PST) 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 v3 4/5] dt-bindings: arm: airoha: Add the chip-scu node for AN7583 SoC Date: Thu, 6 Nov 2025 23:59:13 +0100 Message-ID: <20251106225929.1778398-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251106225929.1778398-1-ansuelsmth@gmail.com> References: <20251106225929.1778398-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 Reviewed-by: Krzysztof Kozlowski --- .../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.51.0 From nobody Sun Dec 14 19:21:53 2025 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 B65F9355035 for ; Thu, 6 Nov 2025 22:59:45 +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=1762469987; cv=none; b=P1ht5ii5x+t8gs5Iltf6nCXOLds3wg5zyy4J45wogNr8UL4z9SaFNidX/NwkxWlSCZsD+5d/Ory1WjmiweEeJoTHL+My9lgz7FWRd/nX8rgip/1NLwYKX9HQceOWVsf8z1vKW+N3NUIjpX2JrI/DFsHIk1FWBwpaXRCRFQKFDS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762469987; c=relaxed/simple; bh=b+MSBxV5Mft7tnlCEnM4CK9pEtwgD/mLZOO0TRxa2ek=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g8dy4tGMXTqupLIkcchgr45ZO9bfk/PiiVUrXwUSKjT0HwNFGhagcXCyc4JVO0vfx5urdG94fjFrY+QlahfojE620q1mrfm56csYDMC+zybjz1oF7xoWDyHT5ZMWnzSHODaXr8xcFe2SZDMAoH/3sPS+wq/ZlFzShgVjo/0/eE0= 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=JQxsApTb; 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="JQxsApTb" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-47112a73785so743065e9.3 for ; Thu, 06 Nov 2025 14:59:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762469984; x=1763074784; 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=oMsSmseR9QHY+HZa+ss2GWQw1aiE3hwhHgWcJtl8K7g=; b=JQxsApTbHX3F9TsCWN4TkPUlM7q+RfRmqlSlUdhJRTv+6Etp8r9wtvVNVofxlKDab+ 1ZND1YdX+vLXbOmDhMt/SUeqQFTO49M3RoktCbnZjD7koB3wE2DNoqKjtL0IBYgsa4I2 sKaQMRMQVDuGVGx+Bug9eRzCD86A2HcbbTcpt8BXlz4IasDGTMU8OWrkbWL61FyTMCTP J+tRedxf0ZEUALTBx/rB8ncwIIndNn7jxCf0E9rR/XD3xdAOhzky1boKNtP8kb5mPDIY M/iu8VnfaBe1Kl3uQWGBjXQV3PO1zhbojCHxyTurbhFdkmy8X7o9KArVmADn1Na5yE0q oq0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762469984; x=1763074784; 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=oMsSmseR9QHY+HZa+ss2GWQw1aiE3hwhHgWcJtl8K7g=; b=D1n+YMWEn5Q4q2zqBL9eVqvWBdy/+TNBW36ENbLuCF8qvlUrdvb+UeIBlE/O3zhNMa 2BsXtT8lmfs7be0L+ULgSNu8Sbjgdde+MsHobwvk6SQ3eSsVquvqOLKJappffoVlViv+ DMJezxd7VQF/ZwBS50s3uo3DIH1hLtW9DxdXvCq6IzTzp4uvEaqpLMAWMYIjzF7pbBm9 Q2m2q2XqNfAFa4tAsdo0oXYg7wEMRcM4UCXMYIwu9YmNtOAB0jRxS+6YwidKqwmFJuhf 27ce7xbDyszSx4XuY2as/r99i0XqkbqGTZMgPOCmIE627XPxbqYS2I4CuTooabkFqmep QXIg== X-Forwarded-Encrypted: i=1; AJvYcCWwC9+UT1Bxa2Dgd3kcy/pqPNUMS375ZoQg8QDAwlF/OeHBSl+tgMxQNsSOlCpm3u0kCJwYHu9qUlk4yro=@vger.kernel.org X-Gm-Message-State: AOJu0YxQLJcqku/bQVRjl3fR2OHpmDe7FDK7INmHvtVxQLk0FdUdoeQ8 vTWKwAC5voRPpFfFffJiPnjunYUV50PLfY0q7AIoRK28DnRfXMCGQ4I5 X-Gm-Gg: ASbGnctj90sS72DS2DzcLBMe9cGxSVEMCCdAHT1XKsW+1U0BRD1q/HfMboIDqp68+IM w/imL2nTbyhA9NwcFIkIUNKrbtNkmyyPFh0jroFEtGJuLmxNxxaueRPyyAgR96gphmClJLuDU4T NZA/hJhROAuFN1hd4/k1XK1VzaswWaaN8s9Qotc0zKtLbMo6+BShVuy1yy86CkoBSKSR83A98lC BXVNYgvzv6Ej2GZl5B+9njYOaoiOtOpBVBH5iVJasxkHSXZ7WhsPqW/r06VS3hnT4NmQtaFTgjo 18CdvI1wk2RJ/hU8VSjiiZ59zs4PzOmKp1GbeD1Z46G/NH58/TM2bQrVqFbd1Ba+XMOVK5vegMG WJoWVH4t5bN/S3zQAWkBaD0P4E8jHI0QDu3vu76ZKh12nJ5toD87IhPEw/om2c2pq06YDLARdc4 0VebgOAT9jM0PJI1Pc1MLAntPnn4vTJA== X-Google-Smtp-Source: AGHT+IHkk3R9oebXFo4lLMo9Gkif1lXQaXrfZ/UrpasowwO7k0I79dLv8Iz0jVn90sCMyMCkllA9JQ== X-Received: by 2002:a05:600c:1d0d:b0:45c:4470:271c with SMTP id 5b1f17b1804b1-4776bcc3c58mr6660315e9.18.1762469984018; Thu, 06 Nov 2025 14:59:44 -0800 (PST) Received: from Ansuel-XPS24 (93-34-90-37.ip49.fastwebnet.it. [93.34.90.37]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-42ac6794f63sm1640000f8f.42.2025.11.06.14.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Nov 2025 14:59:43 -0800 (PST) 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 v3 5/5] thermal/drivers: airoha: Add support for AN7583 Thermal Sensor Date: Thu, 6 Nov 2025 23:59:14 +0100 Message-ID: <20251106225929.1778398-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251106225929.1778398-1-ansuelsmth@gmail.com> References: <20251106225929.1778398-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.51.0