From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFC9634C981 for ; Wed, 20 May 2026 15:55:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779292559; cv=none; b=PXECMUw8W6UYHCO0u/BoskUyMDu6YDqRxmYkNlsnwz6RR9ebUSCYgQNDkWBTKEpgq7xMkc/WJEg0HS/QMrDiE0dRv93a6j8I2UFfSV7jOAZHNxaxw/hDLtTHgNyqkPXcehZ4at7bS5Y5/PYQXUh7EPXKlXufnUTVmu/rvN1rA74= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779292559; c=relaxed/simple; bh=XuOknPD1hS2q5HwdOufPrXyYQTeSyWpjJoiPkpF0LtA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OGbe0OhZhvRrQoEazQp1K6U46/u8gA4P7PMs7v9rVz91j+F2fiUx85MVoNc6uqcM0uFrJmOZ10KHpAERJdCSraQ24Z+hIJXa45Mkzs55qUOmDsF/dyjM+DZogvdnYxKcYPG6e3KTsNyJhb1/LKUnpVKyEDt5t5OyzbLHmcAWyZo= 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=Pm2Fzgjy; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pm2Fzgjy" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-48fde648a71so37470435e9.0 for ; Wed, 20 May 2026 08:55:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779292554; x=1779897354; 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=7oxMnXh4V+hcg0T9wDKZ3oIMULl0k+cYP8lb8bHQAhQ=; b=Pm2Fzgjy/qxSGmL47dONlTu+SaND63j1lRkdIvmWtzFgTUrCNiRx1vSoc3HhFUONea SiRo7Tib8kO+bWnu6sv+lTcdqduvkC1QYmHd2LexNTsBoSznP6bHOfU0kGZuahk4l2GQ X6wtRU0nFbw0qPVvwm+FUYL/6uzetfbKWIOgMHGhzmTrDZkX6LdQnwoxOshICwV9BT8M FYXYXXhexoDqXI6EX64EpNetUcDcbjYVOY69EbzVeD/d0OexV7dLjp25rTjM7NZCSQT/ EtiS0JwhhKay8xLefhwuRgufBkyjwHLYbR1qp4VPj53aJjjGXd/4gGwKeanPbB0OhcVQ wzkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779292554; x=1779897354; 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=7oxMnXh4V+hcg0T9wDKZ3oIMULl0k+cYP8lb8bHQAhQ=; b=RHEPN4i5+Lf8TSOX8nlPRplxA5BnAbLGvXeiGcBLfaQyB9DzCnDpL25OWDWA4SuhXk g/ZT5ff0pp03S/B0R23DeDfDqTj4rqyuznEAnvydHTF2kV5a/ncD5R0LvjB5yJ6EWr5c 5lxrOcBma+RmTDwc2TFU0p5wZP6n/D1SUYsXAQsCMcSs7V92KOaNRgu/L6gzj38qWql4 8TRHNb4t72xuxJbIwui+kbyba4sivu5jGaF2dP5jCsHpQoQOKDB+2mjzcBx42mU7XggW v+n3R9aU0TQyithjqxk+TLoCTkN6GzsCfZjS/rUiwK3SgjbAxzNv6Lbtff3JpD2WuXf1 nr/Q== X-Forwarded-Encrypted: i=1; AFNElJ8UALvkUo1OG4oCqfwdSKhVAyfjBXQmkBNs0ZL6oRBIPYc9ddx40QmbXq3Igd6mSA+UYKS1aIbMjPWJ7iQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yydj5XpTQStjDNU3OU9XNQ4lTWQJPli9tar+eCWUrHtd+9AATq0 qJEQEwj7byZUphbIvCn/gWhfwH6CI4OZ37/sHbSxwQY35ckHreXXJ5+z X-Gm-Gg: Acq92OHA6i1mnYqYaVRxWuoBh8b42JVgRWtTIXbrutS1kkcIKapU3L7k/WX0IlLY8zE A0wTgjlX65WoN3k7ZJuCgdBa3pBPJzWfzFny4HtOHisD7zi2LOnJu1frSzss9bQteon+DizS+FC 9xByNMkrhzDW3HiPFE7Z7lETxYzOsXKLT5qdDJ6DN0MuZ+Tn/Ovt0p+GtkMHo6/S5Jl2xEtsAnq F9oTDKqXvvN3PIuELtlmgIiqzsd4dCpEPEA3Y7lyq1CLT7jTJLvqmWVNfPYf2BN6hMOKF7hxxH7 l+tl6eXBh+uPepcvYpaEsbNQYeIIInhu61bIlYxqSa21soVxyjCi513aAbl6+sa+umPBBIwOWig VZar8Jlg9I99xjLMW/eVAu+CEPrRruIBSYmZ2aEN1AaarfZECZlWSVBIX6RC87N9swkiR43B3Z2 Jhy+dNhbS00N1cDljCjWV8gjId7dhK8ZsqbuQZcUbE3uDEYOe3llqT51ASAYDslRY= X-Received: by 2002:a05:600c:4e01:b0:489:32b:ac0b with SMTP id 5b1f17b1804b1-49033d14eaamr1858425e9.6.1779292553709; Wed, 20 May 2026 08:55:53 -0700 (PDT) Received: from Ansuel-XPS24 (host-79-22-5-99.retail.telecomitalia.it. [79.22.5.99]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-48fed253f93sm132123215e9.16.2026.05.20.08.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 08:55:53 -0700 (PDT) From: Christian Marangi To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Christian Marangi , Lorenzo Bianconi , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v5 4/7] thermal/drivers: airoha: Generalize probe function Date: Wed, 20 May 2026 17:55:17 +0200 Message-ID: <20260520155525.22239-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260520155525.22239-1-ansuelsmth@gmail.com> References: <20260520155525.22239-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: 8bit 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 b63893a8997a..ebb47ae5f2ce 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 = 0; @@ -357,7 +369,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, @@ -412,30 +424,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); @@ -455,18 +463,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); @@ -474,15 +519,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); -- 2.53.0