From patchwork Tue May 27 21:52:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 892888 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 F003E214814; Tue, 27 May 2025 21:53:10 +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=1748382794; cv=none; b=VaXCejLjrfbqAVaRn/AxPKXG2vQYCp1u9WqIYTEgWvnf9OP5O/kUNtVte49TkgCALJa1GfZzuGMuDiJcZ08VmoEqFNCDtkZoK8IVW6GnxKraueEAEd+CIFc3PgPyfYN1a1r+owJ43SLvuDbSy6mMMokVlOF1LLyGsKcoGmHzHck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748382794; c=relaxed/simple; bh=NFoge0TAAOxil832I375a1uGhWyZY9zmeg3YifnMATo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NUbVuMXu4+ncPuYuUOzRfeIbp+y6SCej9UzourKpwUsMWaMY/clfetUJe5lZJMUtDqRh/SvNY+Gk2cLOeNchjVM9vQpu9wR4dh9tZ24hfarGPAGoFzVeYUU5Buvl2jTulgwRV9cTPbVX7DeldBtwqc4lE+cHSpIiuiV22nCVVrE= 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=Qip/s355; 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="Qip/s355" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-43d0618746bso31650795e9.2; Tue, 27 May 2025 14:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748382789; x=1748987589; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3KjsrRqkqh+4w7zYTnKXGm12Hu5UeqaTDd57FU942h0=; b=Qip/s355T8YW4P6VV5SW9B1+loTY1o3JvA8jh/039Wd719Eb1xWvITAt+AkNZXDxEd rEp8Ht85Y8O/stl5jKy8tvq1P5QA+0HOqDiVYlP1joAUP+921OJD3LuJU507rIDc90SE BHjM7AlDMkw34ansiyq7Q7LGLGxiWsdsaffgbm2eCJc5f33N4eSA+ZM5StfKE7t5YkQA elWZyxykY6wGM4YWe7OKJQTe4ca8fq+ZnJPwNnY3w7cUKYcXhG+J9uNEiK7uuPK1rLaP PsJsd+f6yOx2h2B5qm/28ajiphaozu1P1UfeMBL0DTPivALGibT+Y6YHib94NhTQLCxe BSkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748382789; x=1748987589; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3KjsrRqkqh+4w7zYTnKXGm12Hu5UeqaTDd57FU942h0=; b=gU6nsgnSF8JtnOdM4fd5CNV6oTVh7NuDqUVWYmSciFL7EkxSyHIsmazly+a23LXDTC DCbWF7TZE2cw3nCjuI1Ea+NnKJvkHxz/Hfva3hyRcYVBiwNSfuPPIkBYacbNI5CJVgYk xCuii2M/K5N3qFjGGk5vdsi35aWiOPtCKiaWLJpwkZJ74ANOMKRiFFACjPRlYA6hlMNw yeyis9JOMcS/w1ZHyYEFVLu0MNDLEgkh5OTWzJcrAB8RgHw++EvfF4Z2TNqBvm9GLsyh IcogkU/RkEsRu2/1cR4Ao3eIeBNgmetwIJF/xfa8OJ9JjOQDha3wtvWNamGMwte/J7rj V6WA== X-Forwarded-Encrypted: i=1; AJvYcCUXIMfJoP7xoWzhu4lbZUY1U5AhDP+3DJn5uDVLanfpvPYdvgiNUa3wSVnqU3f/HMXeBdtiHBLymZw8lyut@vger.kernel.org, AJvYcCVITq/KjwFC6AiekVsAqu9HJ5UvlSUNx5Dso5M1BTjAhfaz9N/XwQQo1TjFMNIYu1nia88V+VsOmOo=@vger.kernel.org, AJvYcCVYhecKOM7afFKJyCpaNl6PG77cz9Y3wxswJcgJ4kNEZerUJIlnYsfcP/JJZ/E9ckd1JpczSb5DCidE@vger.kernel.org X-Gm-Message-State: AOJu0Yy/v/dLNXzV7Sb7uwrsDJGU02SyGIgppJMKGW5hbmGqvs6JvPLh DppwZN+2gc6tYQMlZYDyzS2FcDAAewInvdM6LAl20l1l8R2WFLa7mPvD X-Gm-Gg: ASbGncs0CkNVvc90YN7plGQrVl17/x22OOwSueeiUrwEOo7zyJK/1WYV/8MWUcpLYOW Gt3H3cBteP2RO9iI2AIvBGHbUTRNYR5vA7wEC1zOs0BViGu8QJ6gWGqXeEBcaijpJt4EedDV5Ec RR+kJHGXhoO6+Emo8IpRhGpWkaQWQAmtXzpznD4YaOA4bXbhoNF6JB0fwShYEjXJmOaD0ZQNa9C YFsF/z6a82CVM+gFZxaRKfB7Gib09JU5iTjtmJPgmFmBQqLLGH8eZN1xVogwp2qwhEqR7cMWQiq 0XHvTgUvXoMn1tw5bJReqzIxX6zSWTU35AUvcX+hI1Mg3Ie4G+BUFpEynObY7AXBLug1U+6zPYv qv80XfsPihN3GRzfSMT7AuO8jpzSCYF8= X-Google-Smtp-Source: AGHT+IH9rVnmfkUcHSNbUn8fV7xapZ6bFvwLY0rRLSokxz8DMe3pEERywRLtY4xhJGcv6ctBs7lJug== X-Received: by 2002:a05:600c:5395:b0:43d:9d5:474d with SMTP id 5b1f17b1804b1-44c90a7d192mr136136705e9.0.1748382789005; Tue, 27 May 2025 14:53:09 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a4e8b8dcdasm206656f8f.11.2025.05.27.14.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 14:53:08 -0700 (PDT) From: Christian Marangi To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/5] thermal: airoha: Convert to regmap API Date: Tue, 27 May 2025 23:52:35 +0200 Message-ID: <20250527215241.25767-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250527215241.25767-1-ansuelsmth@gmail.com> References: <20250527215241.25767-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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_thermal.c index 9a7a702a17de..04bda890dbb1 100644 --- a/drivers/thermal/airoha_thermal.c +++ b/drivers/thermal/airoha_thermal.c @@ -194,7 +194,7 @@ #define AIROHA_MAX_SAMPLES 6 struct airoha_thermal_priv { - void __iomem *base; + struct regmap *map; struct regmap *chip_scu; struct resource scu_adc_res; @@ -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))); /* We offset the high temp of 1°C 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); enable_monitor = true; } @@ -277,15 +277,15 @@ static int airoha_thermal_set_trips(struct thermal_zone_device *tz, int low, RAW_TO_TEMP(priv, FIELD_MAX(EN7581_DOUT_TADC_MASK))); /* We offset the low temp of 1°C 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); enable_monitor = true; } /* 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); return 0; } @@ -302,7 +302,7 @@ static irqreturn_t airoha_thermal_irq(int irq, void *data) bool update = false; u32 status; - status = readl(priv->base + EN7581_TEMPMONINTSTS); + regmap_read(priv->map, EN7581_TEMPMONINTSTS, &status); switch (status & (EN7581_HOFSINTSTS0 | EN7581_LOFSINTSTS0)) { case EN7581_HOFSINTSTS0: event = THERMAL_TRIP_VIOLATED; @@ -318,7 +318,7 @@ static irqreturn_t airoha_thermal_irq(int irq, void *data) } /* Reset Interrupt */ - writel(status, priv->base + EN7581_TEMPMONINTSTS); + regmap_write(priv->map, EN7581_TEMPMONINTSTS, status); if (update) thermal_zone_device_update(priv->tz, event); @@ -336,11 +336,11 @@ static void airoha_thermal_setup_adc_val(struct device *dev, /* sleep 10 ms for ADC to enable */ usleep_range(10 * USEC_PER_MSEC, 11 * USEC_PER_MSEC); - efuse_calib_info = 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 = FIELD_GET(EN7581_EFUSE_TEMP_OFFSET, efuse_calib_info); /* Different slope are applied if the sensor is used for CPU or for package */ - cpu_sensor = 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 = EN7581_SLOPE_X100_DIO_DEFAULT; priv->init_temp = 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)); /* * Configure ADC valid reading addr @@ -375,15 +375,15 @@ static void airoha_thermal_setup_monitor(struct airoha_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); /* * 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)); /* * AHB supports max 12 bytes for ADC voltage. Shift the read @@ -391,40 +391,52 @@ static void airoha_thermal_setup_monitor(struct airoha_thermal_priv *priv) * in the order of half a °C 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)); /* BUS clock is 300MHz counting unit is 3 * 68.64 * 256 = 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)); /* * filt interval is 1 * 52.715us = 52.715us, * sen interval is 379 * 52.715us = 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)); /* AHB poll is set to 146 * 68.64 = 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)); } +static const struct regmap_config airoha_thermal_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, +}; + static int airoha_thermal_probe(struct platform_device *pdev) { struct airoha_thermal_priv *priv; struct device_node *chip_scu_np; struct device *dev = &pdev->dev; + void __iomem *base; int irq, ret; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; - priv->base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(priv->base)) - return PTR_ERR(priv->base); + base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base)) + return PTR_ERR(base); + + priv->map = devm_regmap_init_mmio(dev, base, + &airoha_thermal_regmap_config); + if (IS_ERR(priv->map)) + return PTR_ERR(priv->map); chip_scu_np = 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); /* Enable LOW and HIGH interrupt */ - writel(EN7581_HOFSINTEN0 | EN7581_LOFSINTEN0, - priv->base + EN7581_TEMPMONINT); + regmap_write(priv->map, EN7581_TEMPMONINT, + EN7581_HOFSINTEN0 | EN7581_LOFSINTEN0); return 0; } From patchwork Tue May 27 21:52:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 893538 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9A7A214812; Tue, 27 May 2025 21:53:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748382793; cv=none; b=APQZQ2T1DKl6PIdmdKRxLC1f2fn+zejZb1urduxM+wkhKCvrrbZSIGmgj3zWK26PxxOwDcVf/IDOFuAVG0EgEe8foPoLoevogF52Flpev/uDk/MdmEFcJYCx6W3f+fOkfAt8wXRHP0Gs/Q6gLQTl9apjX8B+DW2EUbmaVTmfM5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748382793; c=relaxed/simple; bh=XA27u/VOEH9VoBWsiugWrpftUIiRrwvmykvq6UgMRpg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f7sYo85IMyVZyatyBgTYBSiwNWOR6hAldgxwxY6NahmCW5RsMcX0olAeRywpFQo7cLYLYie1SCAvc95WKkI6ArFhlBIPcuF2cte+CwHYtxsiRjjRb2sNkRBbjJVFqyWv2/cG4XVpW3pjtHsrnQ22QU7z70Kk2YcAFu/K+PIQrwo= 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=aUwAsnyC; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aUwAsnyC" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3a361b8a664so3921521f8f.3; Tue, 27 May 2025 14:53:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748382790; x=1748987590; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=/vr7W9LI+qlsRFn4c9Ws/BXSMWXobP4FxVmqkbUjGpg=; b=aUwAsnyCuR2bEVP6zuC8I0DV7OkBPPQ42vQIzMScYGc9/bLkusosC9sajNK++wRIr/ u38X2CKzXzQySrhXju+QwgCySmdpdhHsB7xq4DsOZvggm9CDurIX44cunrcFczV5cJ2z QAVZUIWRfU8xQhn2628aB9I7Kgi+r0go37eoIwGun3d87Xfynl+TQEyw+9JTHGb1PpHw qE0A2yYpGe1zLy5eS/vEjw2yhi2NisrYC1kp2icR8EPcyths0VSdzq5HFBVRVurqcKtn /zCcEV4cEkvusCI4EO0Q/gJRTPryDhCEQ0PR9zmkbvTdRjGc8mJtFF4W3CK5WMeRlzci 5fJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748382790; x=1748987590; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/vr7W9LI+qlsRFn4c9Ws/BXSMWXobP4FxVmqkbUjGpg=; b=VAKQQ9w85wZIfunagkmbFH+W1SbVhWtCtyGGYQd5KK0iTM2SRsc6hxH4Ics31H4kmt HOhQyYSGjQw+fUMqwqDSfVMIJgAMbBvlphgZ5fxoWiInREheLZPsFc/tdr5bnOPpUqwp DW+QYKeH3WbUjek+GS5LyeEhGxoRJu37Zyf98PCsBFXWimgKmlBTn97GnVEKb+jepALG 3IujGR+ctbLg1xGd8IM9j72PlXE5xcY0d3H8+SBG8gJEOay42prpEzoSIcEfgUiTi6P6 3ljM70uiR3y6aM18A9i7qlyE3YLWR/3fx695gvegCHwH4w5a4LxcqIsHs/vSXApOmbUG IrTA== X-Forwarded-Encrypted: i=1; AJvYcCV6QgzQE7AMWMsFEXSeXDCzCFGItrJkQvHLf5ORSlsD8rfsReNPF/xK/CZ2IIBlSryhF0zdZhoWgig=@vger.kernel.org, AJvYcCVVWz+QDQkzmnEpmRmmOtlBgaDwM+UkPUV9dxjdkWv46vVsPWINdIIaSztWpRvJw6kYT8qf9LHx+aVwxq/U@vger.kernel.org, AJvYcCWogKzjKgM14W07eY1MIq0UO0P42Hm8NZ3O7dvfFyS+beWS+boo4Ie9VWbHUBNv6HQNCIaTgaoPbzOo@vger.kernel.org X-Gm-Message-State: AOJu0Yy/CJAXdStj22MqoFSDo0PwcVoq44cyfBYz7692qNoQU9mttDuD WMmP1Y8T1PYtecLjrxBtC3u4PUp7hxHCoo3kWAbpKVwzHP9ZewvNI2CS X-Gm-Gg: ASbGncvJl4T0KqoaePqtPZNfjQYAtVrYLNCOCWdNn4/lq/3W3RzoBrgjk88bi4idafB FRKbaBXK5sJpF+V9IXkCM7CWxDWPxeS+4pAJbsSArdZNY3PuGgBFSyFVPr6o3iZpKf3OZzAOsXI PXE4NBbTRsMW9FyGtwIFfIX8gXu8iibpJ1I5ts+HhPbCO+BU6XCQAj8ho/wgrmogvqp2oSyQbCO lPjro9+xhUtYDcZIc0zjlSAK00HRyxN757EQLUOZufow/gcpY3GNSU3vST1T/c+oQ6sJp1T/cHo ezEVn9x593HFvSU5K4F1N6apcPkVWLlC/syB1XDsSoJ6iPtDPfAAnmwK+mH+U3Z9tIz9QbyDg6V bFUpfuV+9TE5yVPra7x4x X-Google-Smtp-Source: AGHT+IE6QOQz+a1kye7D3ulzyyMOIW7d/Ze4H3u6DTzGuKGl3DXiuLYMpFBoawkartGvPgUf69RB9Q== X-Received: by 2002:a05:6000:290d:b0:3a4:d85e:9afd with SMTP id ffacd0b85a97d-3a4d85e9dc4mr8065793f8f.33.1748382790116; Tue, 27 May 2025 14:53:10 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a4e8b8dcdasm206656f8f.11.2025.05.27.14.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 14:53:09 -0700 (PDT) From: Christian Marangi To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/5] thermal/drivers: airoha: Generalize probe function Date: Tue, 27 May 2025 23:52:36 +0200 Message-ID: <20250527215241.25767-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250527215241.25767-1-ansuelsmth@gmail.com> References: <20250527215241.25767-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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_thermal.c index 04bda890dbb1..9bfa59b97032 100644 --- a/drivers/thermal/airoha_thermal.c +++ b/drivers/thermal/airoha_thermal.c @@ -198,12 +198,23 @@ struct airoha_thermal_priv { struct regmap *chip_scu; struct resource scu_adc_res; + u32 pllrg_protect; + struct thermal_zone_device *tz; int init_temp; int default_slope; int default_offset; }; +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); /* Give access to thermal regs */ - regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, EN7581_SCU_THERMAL_PROTECT_KEY); + regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, + priv->pllrg_protect); adc_mux = FIELD_PREP(EN7581_MUX_TADC, EN7581_SCU_THERMAL_MUX_DIODE1); regmap_write(priv->chip_scu, EN7581_PWD_TADC, adc_mux); @@ -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); } -static int airoha_thermal_get_temp(struct thermal_zone_device *tz, int *temp) +static int en7581_thermal_get_temp(struct thermal_zone_device *tz, int *temp) { struct airoha_thermal_priv *priv = 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; } -static int airoha_thermal_set_trips(struct thermal_zone_device *tz, int low, +static int en7581_thermal_set_trips(struct thermal_zone_device *tz, int low, int high) { struct airoha_thermal_priv *priv = thermal_zone_device_priv(tz); @@ -290,12 +302,12 @@ static int airoha_thermal_set_trips(struct thermal_zone_device *tz, int low, return 0; } -static const struct thermal_zone_device_ops thdev_ops = { - .get_temp = airoha_thermal_get_temp, - .set_trips = airoha_thermal_set_trips, +static const struct thermal_zone_device_ops en7581_thdev_ops = { + .get_temp = en7581_thermal_get_temp, + .set_trips = en7581_thermal_set_trips, }; -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 = data; enum thermal_notify_event event; @@ -326,7 +338,7 @@ static irqreturn_t airoha_thermal_irq(int irq, void *data) return IRQ_HANDLED; } -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, } } -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 airoha_thermal_priv *priv) FIELD_PREP(EN7581_ADC_POLL_INTVL, 146)); } -static const struct regmap_config airoha_thermal_regmap_config = { +static const struct regmap_config en7581_thermal_regmap_config = { .reg_bits = 32, .reg_stride = 4, .val_bits = 32, }; -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 = &pdev->dev; void __iomem *base; int irq, ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(base)) return PTR_ERR(base); priv->map = devm_regmap_init_mmio(dev, base, - &airoha_thermal_regmap_config); + &en7581_thermal_regmap_config); if (IS_ERR(priv->map)) return PTR_ERR(priv->map); @@ -454,18 +462,55 @@ static int airoha_thermal_probe(struct platform_device *pdev) return irq; ret = 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; } - 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 = 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 = &pdev->dev; + int ret; + + soc_data = device_get_match_data(dev); + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->pllrg_protect = soc_data->pllrg_protect; + + if (!soc_data->probe) + return -EINVAL; + + ret = soc_data->probe(pdev, priv); + if (ret) + return ret; /* register of thermal sensor and get info from DT */ - priv->tz = devm_thermal_of_zone_register(dev, 0, priv, &thdev_ops); + priv->tz = 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_device *pdev) platform_set_drvdata(pdev, priv); - /* 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; } +static const struct airoha_thermal_soc_data en7581_data = { + .pllrg_protect = EN7581_SCU_THERMAL_PROTECT_KEY, + .thdev_ops = &en7581_thdev_ops, + .probe = &en7581_thermal_probe, + .post_probe = &en7581_thermal_post_probe, +}; + static const struct of_device_id airoha_thermal_match[] = { - { .compatible = "airoha,en7581-thermal" }, + { .compatible = "airoha,en7581-thermal", .data = &en7581_data }, {}, }; MODULE_DEVICE_TABLE(of, airoha_thermal_match); From patchwork Tue May 27 21:52:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 893537 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 87D2F1F7580; Tue, 27 May 2025 21:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748382795; cv=none; b=P3uioyR7dWc9DTOKXWRdJf9PqQ/C3kwhBH/DcoxgAgKI3DoO+JLDobIytyBVdIe2FydxSy4sabyymktMLBTV7lFlhDwSS+In/tlwCHEDubh2RkH4CvKaJUP7tRR7s9hb0p5oEmD3GW10wFTfirmToScy0MXtXFekF9CY/F5e4c0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748382795; c=relaxed/simple; bh=ekBKR7Lv9oRac0ZLGP9CYgwGxje7bKMozV4NKyoCQ8Q=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tMHGgPAV2OZxOOZVWOvhPKPiJJNp2Qhvi95iS1I667HirX0m1gEmA3/ivKnpu8VtTbQMbWWg40Q2MbdvfG2II4dFUlyU37YB0BjNpsuhlTQnVIaEgrBMvD00UBQEVnHjmSgdS45BGLApd9FCEQbd2nBjPlCAIvLFllw8C83IBp0= 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=gQhPU/Rb; arc=none smtp.client-ip=209.85.221.48 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="gQhPU/Rb" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3a4dc0f164fso2160992f8f.3; Tue, 27 May 2025 14:53:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748382792; x=1748987592; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ZQ8QlcBdWd0Fx5MdvLJdxsCqqhtJN4mycD+l4My2cUw=; b=gQhPU/RbqH1TmrTgwdZx5PcEoobNFjVtv9vROUoZSiGkUEUGJs7TvdfGWsn1FA1ArT m5D0wJJMLc7rmW2bvK1HalP5bpwWzw1Zag+ljMZx9Q8FBHN3jgDEtAitTKWbZdZpgIF3 4r+420xq/xLz1pXL+r3qczB+WEmJM305MNNmfP9uH0KgyDFufQOeIFkW9IpeEEW62R+Z UIW7B4wte2Fqz0Eo9UV0KhwFzJRjtSLlgWaUj2fCMiLA1nyCLALG7IoyvtQRVHHEAiZY uktWAC2kdmghPK8qPPDBjTWDIJB9Z42zCAiMH/eaPylL7SzWXVxjy3oWc6maSh2IysSr qm1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748382792; x=1748987592; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZQ8QlcBdWd0Fx5MdvLJdxsCqqhtJN4mycD+l4My2cUw=; b=EHGGHnagzJuEAyrHu779bMkmtGXGMg/reHE4y7ELOCHCBOYUkb8HJzTHdMUp5RI8XC Lircl6v9JZQ3SzQ9I+1YECFkAuAvhvMy/wZyZ3meF9YlZsNpivp4/zb9/2PbcEViJddW HmUpdpy/aVsvu4/vvtL6YXhI/iW5StxICLzn9FxeAx7ljnRrYRyElWppHgPrvPWUdp8Q 3Sqp6Nf+hMfMyCeOwibCKjtjx8rRAEv2SVubKedpjEUvQdAjG5/ledhERkGXeTVeyACg lOBf6qhsFkojQJBoUpzO0ugothstKB356668GtBMOqekkRsUMOUmynfX3jq6dIBkW8xB YN2A== X-Forwarded-Encrypted: i=1; AJvYcCVrBMkLIv6pgoya0oe2xcwkIjtn41vOAcbdUS5xPpjUYBQ8SaN5WGurbp+HM11cxC3eRjKZZk6fjYckzYQ+@vger.kernel.org, AJvYcCVrEinrK956BnYdIO4nCTndIPfyEnJYc1VC7RvJXX9C8p+3U1GNQbS8mGB7MG9pMKR34Ahf47GpAuIC@vger.kernel.org, AJvYcCXvz6yFut5mY3OVpABACGMe+IRDtBqgfeQnpkCnu8gyV7AdXsAt59K7UyXsELS7kv9ocCYqcCbS9cs=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6cCZWP2joWxUHtBJgqy9760jke759bLTjVxV31vjtmCQo7u8f zR1fV9FXIqADrhiOedOij+Au4ra38uWxtPrnotANOgAOZmhUzU+IpfnA X-Gm-Gg: ASbGnct2qIVn/gQe1wuZuf07JCetdz8ppo/6Qko4gOq2VOJeS+6Zbdr5LD/eO+Sn3Dz 1OfDmsagUDEahnyf0kQwqZWL1tXZSh6Ae4T68uNfLXizL5VgqIZrhl/5cDssTIUXBM75A0m7JHc iBHPIfZTjCplaANdiAqfaUe7YbtbTCsR3K19wC9GPNdsQdfe+BJyU1ESVRCSAe6e/vmQtyIopDb M7cgFrDtvvNFyxbPtgytrqn0jzvxZ6sRJiQKQ7COcy4o28zKkR294X3/xh+kwBZRO+FPS8djaJX j1nFeT3RriJEclS82QSWbaRIBEZ6n9i/EG1RQnMchmDSafMh/eAO+2jqITUSJHH9YK4H/M1wth5 fAlM3pExdsEXLEt7Poes4GjKX91bKsRQ= X-Google-Smtp-Source: AGHT+IHwdlIjl4XdhfQz3skBsBAaA2A6LDfME6WNoDpTGosbqtfqEag4vHLNAhvHpnxTCUxQLVnrPA== X-Received: by 2002:a05:6000:2dc7:b0:3a4:e6e6:a026 with SMTP id ffacd0b85a97d-3a4e6e6a0dbmr1016333f8f.28.1748382791535; Tue, 27 May 2025 14:53:11 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a4e8b8dcdasm206656f8f.11.2025.05.27.14.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 14:53:11 -0700 (PDT) From: Christian Marangi To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/5] thermal/drivers: airoha: Generalize get_thermal_ADC and set_mux function Date: Tue, 27 May 2025 23:52:37 +0200 Message-ID: <20250527215241.25767-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250527215241.25767-1-ansuelsmth@gmail.com> References: <20250527215241.25767-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In preparation for support of Airoha AN7583, generalize get_thermal_ADC() and set_thermal_mux() with the use of reg_field API. This is to account the same logic between the current supported SoC and the new one but with different register address. While at it also further improve some comments and move sleep inside the set_thermal_mux function. Signed-off-by: Christian Marangi --- drivers/thermal/airoha_thermal.c | 54 +++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/drivers/thermal/airoha_thermal.c b/drivers/thermal/airoha_thermal.c index 9bfa59b97032..4c973cce106a 100644 --- a/drivers/thermal/airoha_thermal.c +++ b/drivers/thermal/airoha_thermal.c @@ -193,9 +193,18 @@ #define AIROHA_MAX_SAMPLES 6 +enum airoha_thermal_chip_scu_field { + AIROHA_THERMAL_DOUT_TADC, + AIROHA_THERMAL_MUX_TADC, + + /* keep last */ + AIROHA_THERMAL_FIELD_MAX, +}; + struct airoha_thermal_priv { struct regmap *map; struct regmap *chip_scu; + struct regmap_field *chip_scu_fields[AIROHA_THERMAL_FIELD_MAX]; struct resource scu_adc_res; u32 pllrg_protect; @@ -219,22 +228,29 @@ static int airoha_get_thermal_ADC(struct airoha_thermal_priv *priv) { u32 val; - regmap_read(priv->chip_scu, EN7581_DOUT_TADC, &val); - return FIELD_GET(EN7581_DOUT_TADC_MASK, val); + regmap_field_read(priv->chip_scu_fields[AIROHA_THERMAL_DOUT_TADC], + &val); + return val; } -static void airoha_init_thermal_ADC_mode(struct airoha_thermal_priv *priv) +static void airoha_set_thermal_mux(struct airoha_thermal_priv *priv, + int tdac_idx) { - u32 adc_mux, pllrg; + u32 pllrg; /* Save PLLRG current value */ regmap_read(priv->chip_scu, EN7581_PLLRG_PROTECT, &pllrg); - /* Give access to thermal regs */ + /* Give access to Thermal regs */ regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, priv->pllrg_protect); - adc_mux = FIELD_PREP(EN7581_MUX_TADC, EN7581_SCU_THERMAL_MUX_DIODE1); - regmap_write(priv->chip_scu, EN7581_PWD_TADC, adc_mux); + + /* Configure Thermal ADC mux to tdac_idx */ + regmap_field_write(priv->chip_scu_fields[AIROHA_THERMAL_MUX_TADC], + tdac_idx); + + /* Sleep 10 ms for Thermal ADC to enable */ + usleep_range(10 * USEC_PER_MSEC, 11 * USEC_PER_MSEC); /* Restore PLLRG value on exit */ regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, pllrg); @@ -343,10 +359,8 @@ static void en7581_thermal_setup_adc_val(struct device *dev, { u32 efuse_calib_info, cpu_sensor; - /* Setup thermal sensor to ADC mode and setup the mux to DIODE1 */ - airoha_init_thermal_ADC_mode(priv); - /* sleep 10 ms for ADC to enable */ - usleep_range(10 * USEC_PER_MSEC, 11 * USEC_PER_MSEC); + /* Setup Thermal Sensor to ADC mode and setup the mux to DIODE1 */ + airoha_set_thermal_mux(priv, EN7581_SCU_THERMAL_MUX_DIODE1); regmap_read(priv->map, EN7581_EFUSE_TEMP_OFFSET_REG, &efuse_calib_info); if (efuse_calib_info) { @@ -429,13 +443,18 @@ static const struct regmap_config en7581_thermal_regmap_config = { .val_bits = 32, }; +static const struct reg_field en7581_chip_scu_fields[AIROHA_THERMAL_FIELD_MAX] = { + [AIROHA_THERMAL_DOUT_TADC] = REG_FIELD(EN7581_DOUT_TADC, 0, 15), + [AIROHA_THERMAL_MUX_TADC] = REG_FIELD(EN7581_PWD_TADC, 1, 3), +}; + static int en7581_thermal_probe(struct platform_device *pdev, struct airoha_thermal_priv *priv) { struct device_node *chip_scu_np; struct device *dev = &pdev->dev; void __iomem *base; - int irq, ret; + int i, irq, ret; base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(base)) @@ -454,6 +473,17 @@ static int en7581_thermal_probe(struct platform_device *pdev, if (IS_ERR(priv->chip_scu)) return PTR_ERR(priv->chip_scu); + for (i = 0; i < AIROHA_THERMAL_FIELD_MAX; i++) { + struct regmap_field *field; + + field = devm_regmap_field_alloc(dev, priv->chip_scu, + en7581_chip_scu_fields[i]); + if (IS_ERR(field)) + return PTR_ERR(field); + + priv->chip_scu_fields[i] = field; + } + of_address_to_resource(chip_scu_np, 0, &priv->scu_adc_res); of_node_put(chip_scu_np); From patchwork Tue May 27 21:52:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 892887 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B828215F7D; Tue, 27 May 2025 21:53:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748382796; cv=none; b=Vb8+pF6UW3LPEcAY/TKgkcrqqLOR/hhoZuTmJqqmjnrSk4jN9CgqyKzovrR8MjkMcoKt31QJGhF3qzBKrdonS9Wqp7opEFT1KIBUIWbe0EofH7mkcQak0uAvAR5ICmZMR2ohp9H6cUb7sRO7vpT1YPr8uIL4mnvGMrXtpCxqHyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748382796; c=relaxed/simple; bh=KVB9knIN20EJn4MFg0e51m0GM1UWg3GyhnYxI4POLhI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TEMeJoqnxH45NOIsmBOx0YAfYpphN8YQVss3qKtWyNxuz2sLpFsqP9WdWcxaSC4i4vZoRbOZip+o0eda26HdF6wwTDYwTmpmvZFJI/m6tERCI7A96xcRVOy99xlKlPWqQjv/udCWvoe1vU9rKZKbKejvSM6tR9OEZ0BvVE54oQU= 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=OHP1SUDD; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OHP1SUDD" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3a37ed01aa0so3769175f8f.2; Tue, 27 May 2025 14:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748382793; x=1748987593; 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=9Wk226ElMjpVIGD7BaKvZ9Z3Q9dYE/ETf8tcRXkIeEA=; b=OHP1SUDDQMk2AeJ9OYmE7sEsm2a0oLT7ATUxZvWjN+Wcm9Dq9Q8MqEmvx7B9Wn5HGY oeRIhJKrERLlnvBtyi0AHhCMDMxsceVfwg9ahzY5bjUw3pb9il1ZoZDqFoEpzmOoKln0 Kp9q65F32+h061QEB2uaUzacRXHqXbtVBYg8hz3VAcH1K01xdcoxxiwJsnr3Sf1KhPAt L932asHYSwA52HkGrzMVRkf+mrbzEE7U33q9da1wCC/Bxc3C/nlPIqv7Em2Aomh3fFjp RX92hAVHQvWo8xWwBgMAOso87zKkXLaWRWqWQn8aeLv6KMAOUnakLZ5ltnZIvmTZMyKN INEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748382793; x=1748987593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9Wk226ElMjpVIGD7BaKvZ9Z3Q9dYE/ETf8tcRXkIeEA=; b=GbM5EiPRw1dle2Ett4sQe8NytIhhs/sKddv5+PQwmvV2kCIyJmpEvzsMRzws1wcGBj qs/zd17gC0Fus8Q0sq6ZuwO2Vy1sDh4tWOT3wjHT6iRULIVByMJpv4l4CuDI49S2NU6L Me0cIl3DOY0Ea3XFgPunC6UF8N0XLsm7r3EwYrjes63LGYHSUYQdMb5dgGHJYnLmwUJi zckf6dT74nzZmWG85wKpie49G8ayvEeBXvtCxA1OFAF1jnov9OKAHuGByX/FPe8o5XeX DE3WzL0bWnrhs05r1y2CPbk2lEwT9UxPc0t+bmo8wRxHEva6C03XA2GNNFDil39PYC8I ZvcA== X-Forwarded-Encrypted: i=1; AJvYcCWBhsaKWcCbiaq79582O0NZsL29ABB7sURx1hPkCKAKV+qa0rE+/d/qtRQKEt1sSebazPS9bsU3gqJs8sLI@vger.kernel.org, AJvYcCWf17zremIb0/Y6s5Ic26nl2k17/P6HT4hc/V4e43DU9VxrlIvA/wWhFpYZXmSNGwl3dRyj56E73SDE@vger.kernel.org, AJvYcCXMtXZ9A97qKdn3o93wPejiAyZFK1B3eg8xXD/6Dm7QWgEFxc63WIFTIKojPXTCkWFToZO3POwguO0=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2H/pkYYMxZogGff/7fI1SwsQkLgwfNZw+EmJkk9nhXE3lwer8 BNX99mqgPDNsFU6I5rE5cfdj/U8U1x3eegRFvvlv9IGfmpgd8KF3VMVs X-Gm-Gg: ASbGncuaa1iC7nxMfjHVSVpOtTZYfAkhuh+XoT430pU3wgYWIwrms7ld4cuCkpix5qV AtB/2HXmYPIuyr2gvRX54ptI19L+vkiOgoqjnPFCuTmAb+bu8nII966ELESnazEL6sbE/cfSic0 iHEc581tMtIGseveSvgTULXhxZxmy+HRkW5lLLgi4BWO9+34Hb3spEXb7tRiN61BZOmbVYaXGTd PMSThACyZAB2tol+4TVLvtHmodVhpNkZCp62iG/2Ht3+bwwShJtH+xJcsa743c2hDHAynk76pmG awjmo4jX8Rx+LlLGTySXDSAEO85Wllp+gThdTiiyoAI+JVzqsDuJqC3hC+QGu9FxNErof+4gev6 4Nu/ypxCPWzUjexoaJ5x+ X-Google-Smtp-Source: AGHT+IGzdRmpIiChZHvMpjw4//1BMh2wxfIxE1BvnrYjHNrpYnZI5pBznt8DKI9NHAcUBdgEeJZlyw== X-Received: by 2002:a05:6000:2911:b0:3a4:e65d:5d8c with SMTP id ffacd0b85a97d-3a4e65d5d9emr1716337f8f.40.1748382792639; Tue, 27 May 2025 14:53:12 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a4e8b8dcdasm206656f8f.11.2025.05.27.14.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 14:53:12 -0700 (PDT) From: Christian Marangi To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/5] dt-bindings: thermal: Document Airoha AN7583 support Date: Tue, 27 May 2025 23:52:38 +0200 Message-ID: <20250527215241.25767-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250527215241.25767-1-ansuelsmth@gmail.com> References: <20250527215241.25767-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Document support for Airoha AN7583 thermal driver. Airoha AN7583 follow the same logic of Airoha EN7581 to read the temperature but lack all the support for the PTP_THERMAL used to monitor and react when trip point are triggered. Also the Airoha AN7583 lives entirely under the Chip SCU SoC register space hence a dedicated schema is introduced. Signed-off-by: Christian Marangi --- .../thermal/airoha,an7583-thermal.yaml | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/airoha,an7583-thermal.yaml diff --git a/Documentation/devicetree/bindings/thermal/airoha,an7583-thermal.yaml b/Documentation/devicetree/bindings/thermal/airoha,an7583-thermal.yaml new file mode 100644 index 000000000000..cfd37e33c541 --- /dev/null +++ b/Documentation/devicetree/bindings/thermal/airoha,an7583-thermal.yaml @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/thermal/airoha,an7583-thermal.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha Thermal Sensor and Monitor + +maintainers: + - Christian Marangi + +properties: + compatible: + const: airoha,an7583-thermal + + '#thermal-sensor-cells': + const: 0 + +required: + - compatible + - '#thermal-sensor-cells' + +additionalProperties: false + +examples: + - | + thermal-sensor { + compatible = "airoha,an7583-thermal"; + + #thermal-sensor-cells = <0>; + }; From patchwork Tue May 27 21:52:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 893536 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 E233021885D; Tue, 27 May 2025 21:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748382800; cv=none; b=Ha04q7YVIk7MtG/VyVU8FfANPMKVFTRYZ6y66VTUZPeaU/12VDChNWLloUZYyU9FyY5drRSJX5m03FTXOQ9I/7X2TPaiHbB6rG+lSXQE97ocDqD1Cxb7ZP337RqsQFBQ8aHD80VoGYiKuJY8sDLYxExJDqC98Xnvf3YyHyyyR9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748382800; c=relaxed/simple; bh=zmNS/g/uQIEqjg8pv8e9ZCmB4hQz9Fpeoy2dOjmOTf0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=imPs4HwQs+AuT7peCcFtpxmnCE8mMD3J08/evq7x46Urxx9q7MUpoDoUR+gS9nFnjzFnZQKeXquJ+DysB5uuDMDWfAW8AMedp/jHNslOmV15FVZK2kwkIhr1eF6zHmTQMXvzv9jWBPCXMkDBywv+IgPnTInu4peXWN6oQO+R91U= 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=HeMQqt9i; arc=none smtp.client-ip=209.85.128.51 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="HeMQqt9i" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-43cf680d351so1955395e9.0; Tue, 27 May 2025 14:53:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748382794; x=1748987594; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Gq4Q+VNy6npC1ksfAe5OpC6UqFwfJyc/g1FQnGCBY/w=; b=HeMQqt9iti7KNNeoSsXhrB9lh1VE8L8DcE5uKZblgI4Nvt2Cgsp9WVqs6RsuWpCP4x G2tcHNBuuHVS4lfWih4Plr8XEOU3whagD/5XHjTqjee8gr2VxMuvdLZRxtWlvqGP5/MD 6taGYxy/3aQiL1l3fuejwiML8VMag1nAOIoog03xGWTRSICxR8NCZqBw1mqpimEHuVda UNAm8AzMREdrIx8x7ZhB33DixuScYidjfMwgmNpJ0DeuRvLu1UfNOt3GPeFhN87HSJ1a qbAVAfHxPrcBdP3l7M6B4Mn/JT6PH6c6uSOK98qH9pO3V9Q83uhnInlts2v4FGRtHd/g OS1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748382794; x=1748987594; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gq4Q+VNy6npC1ksfAe5OpC6UqFwfJyc/g1FQnGCBY/w=; b=UnLTAUfdUfXGjKwHPozvsT8MsxsvgERWq7i2eNxYDs5T+nakTpFWaMCB/iuOdT6nfF ig377kYjSuNrvHonaBbv3NqnRKSkx0iq8YoOFEWkO7Fwdw96lXyyTgLHzajDlHP9KRQq geJWRoDfgJIgUVGrVy8KTODLiuSNj+YhX6NH8casMfZnERDjGMCPEPa4ZJGr8DXKkjFy RYErCTNlKTLfbMj1QnkJ1yLQBPIOeFWNxK8hTMYd6jxXiIRErGRgEaIFf0kwGH895t7D M5Ga3eWFOwIBJA+3p1F9vaKHkWR41PseDey/rpAbgYfVUSKte0f2dPPM2fH/KFZoTr6r 8TzQ== X-Forwarded-Encrypted: i=1; AJvYcCUXK4i17YeBOqHHRwhLhbAs6eLJ7Epsqq0C0KQvxE2cB2SlouMMyMvM57zxzE7Rq/xDJlPVn6evUbw=@vger.kernel.org, AJvYcCVvOgVqPStKBksI/96d04HIdBdKKBZq1+sZUP/pn3JE0xVsrEWTY7Yhv5ZLX5RweYOX2IO66X8cDfNO@vger.kernel.org, AJvYcCWckJ0ib1FZd793J8VLDv7MH66MldVR/r4KHZfQYdsCMUMIR1Z9P9aNYaAfrTU7SsYex+0/KoXVlqOw9HrV@vger.kernel.org X-Gm-Message-State: AOJu0Yz/zltN+0v1+hx8WwKnNpH3EF+k6ODIiBdH8RRA38FCVk4sObBZ hWplYDzQnw2X8JigK4jDhoJf51BkNGhjI6iNIlJ0p6idMCYHYyidq4MNlhjf3A== X-Gm-Gg: ASbGncsqMAiIH2ils2DS2Kz78w8YKZCrJ7FScbZZgcDKVdFy4d0HJgD736a5SAgCIDT Yok4YnPSJTeKbs9w+eO12b0mqz5c7CzmcwICmVjHpabUS7AuI6J4GfNNjLePPLYs/Uy5ZbFcLTx 4sShfWu1GYrd7YVK26FRKjuwUrMpepnKmkQtgnmEA3FpBP+RTOETGhKmT2rigrgM5TlM53iNuDe 0ove9o7kLG/am48G3pImhgNMpZq3DTseNFrJIdEIvJMx1XC4SsfQngckEj5TTcko/BzQ7oy/lEw YO+AMWQf8jPqx8N+WsECUzmOfQx3yvlXp0cnUI6mZ1JpQy372s79HgO1eQ3glQSGGWtbrZt3gk3 NxYJot0P/EcXk2G7JMZyT X-Google-Smtp-Source: AGHT+IHL/zXQxdrX/xfFoSnEBrs97F+A5I3OaSukghEzTxZ95IFMQvVQRnrHOcpwVxdVHqvUd3ByPQ== X-Received: by 2002:a05:6000:230b:b0:3a4:d045:6462 with SMTP id ffacd0b85a97d-3a4e5e9cbddmr2459193f8f.14.1748382793993; Tue, 27 May 2025 14:53:13 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a4e8b8dcdasm206656f8f.11.2025.05.27.14.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 14:53:13 -0700 (PDT) From: Christian Marangi To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Christian Marangi , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] thermal/drivers: airoha: Add support for AN7583 Thermal Sensor Date: Tue, 27 May 2025 23:52:39 +0200 Message-ID: <20250527215241.25767-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250527215241.25767-1-ansuelsmth@gmail.com> References: <20250527215241.25767-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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_thermal.c index 4c973cce106a..e71548f9cee1 100644 --- a/drivers/thermal/airoha_thermal.c +++ b/drivers/thermal/airoha_thermal.c @@ -18,6 +18,12 @@ #define EN7581_DOUT_TADC 0x2f8 #define EN7581_DOUT_TADC_MASK GENMASK(15, 0) +#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 +#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) * slope) / 1000) + offset */ #define TEMP_TO_RAW(priv, temp) ((((((temp) / 100) - (priv)->init_temp) * \ (priv)->default_slope) / 1000) + \ @@ -193,8 +204,39 @@ #define AIROHA_MAX_SAMPLES 6 +/* + * 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, /* keep last */ @@ -208,6 +250,7 @@ struct airoha_thermal_priv { struct resource scu_adc_res; u32 pllrg_protect; + int current_adc; struct thermal_zone_device *tz; int init_temp; @@ -224,6 +267,24 @@ struct airoha_thermal_soc_data { int (*post_probe)(struct platform_device *pdev); }; +static const unsigned int an7583_thermal_coeff[AN7583_ADC_MUX_MAX] = { + [AN7583_BGP_TEMP_SENSOR] = 973, + [AN7583_GBE_TEMP_SENSOR] = 995, + [AN7583_CPU_TEMP_SENSOR] = 1035, +}; + +static const unsigned int an7583_thermal_slope[AN7583_ADC_MUX_MAX] = { + [AN7583_BGP_TEMP_SENSOR] = 7440, + [AN7583_GBE_TEMP_SENSOR] = 7620, + [AN7583_CPU_TEMP_SENSOR] = 8390, +}; + +static const unsigned int an7583_thermal_offset[AN7583_ADC_MUX_MAX] = { + [AN7583_BGP_TEMP_SENSOR] = 294, + [AN7583_GBE_TEMP_SENSOR] = 298, + [AN7583_CPU_TEMP_SENSOR] = 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) } static void airoha_set_thermal_mux(struct airoha_thermal_priv *priv, - int tdac_idx) + int tdac_idx, int sensor_idx) { u32 pllrg; @@ -245,9 +306,20 @@ static void airoha_set_thermal_mux(struct airoha_thermal_priv *priv, regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, priv->pllrg_protect); + /* + * Configure Thermal Sensor mux to sensor_idx. + * (if not supported, sensor_idx is AIROHA_THERMAL_NO_MUX_SENSOR) + */ + if (sensor_idx != 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 != tdac_idx) { + regmap_field_write(priv->chip_scu_fields[AIROHA_THERMAL_MUX_TADC], + tdac_idx); + priv->current_adc = tdac_idx; + } /* 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; /* 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); 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 = 0; i < AIROHA_THERMAL_FIELD_MAX; i++) { struct regmap_field *field; + /* Skip registering MUX_SENSOR field as not supported */ + if (i == AIROHA_THERMAL_MUX_SENSOR) + continue; + field = 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_device *pdev) return 0; } +static int an7583_thermal_get_temp(struct thermal_zone_device *tz, int *temp) +{ + struct airoha_thermal_priv *priv = 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 = AN7583_BGP_TEMP_SENSOR; + + coeff = an7583_thermal_coeff[sensor_idx]; + slope = an7583_thermal_slope[sensor_idx]; + offset = an7583_thermal_offset[sensor_idx]; + + airoha_set_thermal_mux(priv, sensor_idx, AN7583_ZERO_TADC); + diode_zero = airoha_get_thermal_ADC(priv); + airoha_set_thermal_mux(priv, sensor_idx, AN7583_D0_TADC); + diode_d0 = airoha_get_thermal_ADC(priv); + airoha_set_thermal_mux(priv, sensor_idx, AN7583_D1_TADC); + diode_d1 = airoha_get_thermal_ADC(priv); + + delta_diode = diode_d1 - diode_d0; + delta_gain = (delta_diode * coeff) / 100 + (diode_zero - diode_d1); + *temp = (slope * delta_diode * 10) / delta_gain - offset * 10; + *temp *= 100; + + return 0; +} + +static const struct thermal_zone_device_ops an7583_tz_ops = { + .get_temp = an7583_thermal_get_temp, +}; + +static const struct reg_field an7583_chip_scu_fields[AIROHA_THERMAL_FIELD_MAX] = { + [AIROHA_THERMAL_DOUT_TADC] = REG_FIELD(AN7583_DOUT_TADC, 0, 31), + [AIROHA_THERMAL_MUX_TADC] = REG_FIELD(AN7583_MUX_TADC, 1, 3), + [AIROHA_THERMAL_MUX_SENSOR] = REG_FIELD(AN7583_MUX_SENSOR, 2, 3), +}; + +static int an7583_thermal_probe(struct platform_device *pdev, + struct airoha_thermal_priv *priv) +{ + struct device *dev = &pdev->dev; + int i; + + priv->chip_scu = device_node_to_regmap(dev->parent->of_node); + if (IS_ERR(priv->map)) + return PTR_ERR(priv->map); + + for (i = 0; i < AIROHA_THERMAL_FIELD_MAX; i++) { + struct regmap_field *field; + + field = 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] = 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; priv->pllrg_protect = soc_data->pllrg_protect; + priv->current_adc = -1; if (!soc_data->probe) return -EINVAL; @@ -558,8 +701,15 @@ static const struct airoha_thermal_soc_data en7581_data = { .post_probe = &en7581_thermal_post_probe, }; +static const struct airoha_thermal_soc_data an7583_data = { + .pllrg_protect = AN7583_SCU_THERMAL_PROTECT_KEY, + .thdev_ops = &an7583_tz_ops, + .probe = &an7583_thermal_probe, +}; + static const struct of_device_id airoha_thermal_match[] = { { .compatible = "airoha,en7581-thermal", .data = &en7581_data }, + { .compatible = "airoha,an7583-thermal", .data = &an7583_data }, {}, }; MODULE_DEVICE_TABLE(of, airoha_thermal_match);