Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4631900rwb; Tue, 6 Sep 2022 10:08:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR76/zVmP8hj5z7ZgFYKPl/cPNKN5cKj31RbWWTAK0E8UjCxiq14U9XyMP/kuUmpmIkDjKrR X-Received: by 2002:a17:90b:4a4e:b0:1fe:24b4:bf6a with SMTP id lb14-20020a17090b4a4e00b001fe24b4bf6amr25614716pjb.137.1662484094792; Tue, 06 Sep 2022 10:08:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662484094; cv=none; d=google.com; s=arc-20160816; b=R4bmQjBHLhG38dceKWQFIbo+AV4pJcCzQR+44uBFi1M/cAeYOapxw9lu7vBPDgK/+u AJJR2hhmOdurI1ZEOAGwiA4otS2LWOJpR1Lj7mRUSEvJxdst+iIcAe9Juo2RNNyGxF9N cVP2QqwELi0WlFCL9QsZDBCzqlc+p/Etum/Um910yj8A5jl4qHYbQDaeVnq3XbX7Cs+3 rPplRDmq+r30a1/Z2AmDW0E/SXt0bHGg14R9MlpWW63tWLjOXsp0Se7+zNkP0QXPRwIh iC4r27ZYGyfjucD1psgEIXRlaUW4TOcVx8Bvijkyiu1pLYxIdz5LSUCt10/v5xRMsWVy EPeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xYvlHjUzJ1gAdl8KtmAH0mCHcP29B+tCMOTUThwt7jg=; b=wry1ZdRB/K770sHja3hBNtYpJrc97e5zTe9YUe74ZxXUtwlRebUSV9EO53pPNhdLTC Hl7+6ADtP54c9pJTdqpuCAozCRG+hVnJ2a+HC5jiO2C/WmVRsCELp5QUoW01WYNpPVwy wSfzz5Ba4csWWcc80F55GqRL04QaCRAa4PtBd/rtlRQsdtnDyfsIWkemi71C3z2FHxFX 9q6m164LREy1eFo2BRw6kTqg9/nsH2jcZEUdFIRlDj6d6pgSBy66j3cwdhgRVVm1cTkM kqQVi+ZpAjpBjVgWYaiYLUJgamWyvXOnC1k5kgj3drwauTlKM2s3s868cfcMGB56Rm4b bseg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=moC3maNb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f128-20020a636a86000000b0042b6b0d00adsi2169341pgc.639.2022.09.06.10.08.02; Tue, 06 Sep 2022 10:08:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=moC3maNb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237992AbiIFRDA (ORCPT + 99 others); Tue, 6 Sep 2022 13:03:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239042AbiIFRBG (ORCPT ); Tue, 6 Sep 2022 13:01:06 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E21F28E20 for ; Tue, 6 Sep 2022 09:48:06 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id t7so11325958wrm.10 for ; Tue, 06 Sep 2022 09:48:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=xYvlHjUzJ1gAdl8KtmAH0mCHcP29B+tCMOTUThwt7jg=; b=moC3maNbMcCB2llQTrHIAjv3Uko04+bbQ646kv8FkteCDfagAT5TuR7KeM23KlIEs/ OcplE2OdFRxYUK6Cg/2IuVMhTGDjoH21fZKUyuvenj5cpjTWIuIxuH2aAv7K1yDJfGCr G8Ohjwk6vJ8MEic+RtNdArmxMQRjK0wR0jAEp62+xhwzGmXdD2UBnh6H7Dyg9bhVqh+m joPUUT36PL9VaUS5MrMM6o1mTJIn4xTfsRE7i4JzXmRSW2ZHcn3fHSnUE6s6C0hli7+D rqyNNpI5T2r1/Hzam7+RFXcoLjPardiDeGl+Rl3r9uX5bcqwrocZ7rEEZuLi4kngkmvx 0RjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=xYvlHjUzJ1gAdl8KtmAH0mCHcP29B+tCMOTUThwt7jg=; b=xaqCHISA5+kpoNrz2iLndj/sZT44PgEL7urSXo2iwQV2c78U/tneAsii3rdv1rYitc hTXvLsYt8i1lOH7MxTQ8wm7BCKN3IA3fmyjBw0qgHY9YUrvpMJUy3C/pJVyGUUaZKJc9 B7VIU1gLIiVC2NpK+8kkbX7EZJwf/BSk636cLbK2W1Z3Z+RByZKwW6g850lF7VUaGckt nQhsAJnZEAtvhy6likC8Bpr2Q27cofSUOlscSEnp6KtBLHGqdqkfFhA/EexeoGoMsvoe A9KuzbTXWIL4IVa7vMao6Qf/EFW6x/ZwPD5ZxyPUIVtQROZ+9OV+1uLPjDbQWSWy+e/1 MguA== X-Gm-Message-State: ACgBeo3pXcUBoGhSAby/X0A0WLjU+9n/1JujDWqPro2OuRuX+C0QarND wsaKr9wzQ+zEuM1Ugr0ZPtXfLQ== X-Received: by 2002:a5d:47ce:0:b0:228:5769:489e with SMTP id o14-20020a5d47ce000000b002285769489emr9127537wrc.188.1662482884940; Tue, 06 Sep 2022 09:48:04 -0700 (PDT) Received: from localhost.localdomain (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id e27-20020adf9bdb000000b0021f0ff1bc6csm7426600wrc.41.2022.09.06.09.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 09:48:04 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Amit Kucheria , Zhang Rui , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , linux-arm-kernel@lists.infradead.org (moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE) Subject: [PATCH v3 22/30] thermal/drivers/imx: Use generic thermal_zone_get_trip() function Date: Tue, 6 Sep 2022 18:47:12 +0200 Message-Id: <20220906164720.330701-23-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220906164720.330701-1-daniel.lezcano@linaro.org> References: <20220906164720.330701-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The thermal framework gives the possibility to register the trip points with the thermal zone. When that is done, no get_trip_* ops are needed and they can be removed. Convert ops content logic into generic trip points and register them with the thermal zone. Signed-off-by: Daniel Lezcano --- drivers/thermal/imx_thermal.c | 72 +++++++++++++---------------------- 1 file changed, 27 insertions(+), 45 deletions(-) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 16663373b682..fb0d5cab70af 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -76,7 +76,6 @@ enum imx_thermal_trip { IMX_TRIP_PASSIVE, IMX_TRIP_CRITICAL, - IMX_TRIP_NUM, }; #define IMX_POLLING_DELAY 2000 /* millisecond */ @@ -115,6 +114,11 @@ struct thermal_soc_data { u32 low_alarm_shift; }; +static struct thermal_trip trips[] = { + [IMX_TRIP_PASSIVE] = { .type = THERMAL_TRIP_PASSIVE }, + [IMX_TRIP_CRITICAL] = { .type = THERMAL_TRIP_CRITICAL }, +}; + static struct thermal_soc_data thermal_imx6q_data = { .version = TEMPMON_IMX6Q, @@ -201,8 +205,6 @@ struct imx_thermal_data { struct thermal_cooling_device *cdev; struct regmap *tempmon; u32 c1, c2; /* See formula in imx_init_calib() */ - int temp_passive; - int temp_critical; int temp_max; int alarm_temp; int last_temp; @@ -279,12 +281,12 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) /* Update alarm value to next higher trip point for TEMPMON_IMX6Q */ if (data->socdata->version == TEMPMON_IMX6Q) { - if (data->alarm_temp == data->temp_passive && - *temp >= data->temp_passive) - imx_set_alarm_temp(data, data->temp_critical); - if (data->alarm_temp == data->temp_critical && - *temp < data->temp_passive) { - imx_set_alarm_temp(data, data->temp_passive); + if (data->alarm_temp == trips[IMX_TRIP_PASSIVE].temperature && + *temp >= trips[IMX_TRIP_PASSIVE].temperature) + imx_set_alarm_temp(data, trips[IMX_TRIP_CRITICAL].temperature); + if (data->alarm_temp == trips[IMX_TRIP_CRITICAL].temperature && + *temp < trips[IMX_TRIP_PASSIVE].temperature) { + imx_set_alarm_temp(data, trips[IMX_TRIP_PASSIVE].temperature); dev_dbg(&tz->device, "thermal alarm off: T < %d\n", data->alarm_temp / 1000); } @@ -330,29 +332,10 @@ static int imx_change_mode(struct thermal_zone_device *tz, return 0; } -static int imx_get_trip_type(struct thermal_zone_device *tz, int trip, - enum thermal_trip_type *type) -{ - *type = (trip == IMX_TRIP_PASSIVE) ? THERMAL_TRIP_PASSIVE : - THERMAL_TRIP_CRITICAL; - return 0; -} - static int imx_get_crit_temp(struct thermal_zone_device *tz, int *temp) { - struct imx_thermal_data *data = tz->devdata; - - *temp = data->temp_critical; - return 0; -} - -static int imx_get_trip_temp(struct thermal_zone_device *tz, int trip, - int *temp) -{ - struct imx_thermal_data *data = tz->devdata; + *temp = trips[IMX_TRIP_CRITICAL].temperature; - *temp = (trip == IMX_TRIP_PASSIVE) ? data->temp_passive : - data->temp_critical; return 0; } @@ -371,10 +354,10 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip, return -EPERM; /* do not allow passive to be set higher than critical */ - if (temp < 0 || temp > data->temp_critical) + if (temp < 0 || temp > trips[IMX_TRIP_CRITICAL].temperature) return -EINVAL; - data->temp_passive = temp; + trips[IMX_TRIP_PASSIVE].temperature = temp; imx_set_alarm_temp(data, temp); @@ -423,8 +406,6 @@ static struct thermal_zone_device_ops imx_tz_ops = { .unbind = imx_unbind, .get_temp = imx_get_temp, .change_mode = imx_change_mode, - .get_trip_type = imx_get_trip_type, - .get_trip_temp = imx_get_trip_temp, .get_crit_temp = imx_get_crit_temp, .set_trip_temp = imx_set_trip_temp, }; @@ -507,8 +488,8 @@ static void imx_init_temp_grade(struct platform_device *pdev, u32 ocotp_mem0) * Set the critical trip point at 5 °C under max * Set the passive trip point at 10 °C under max (changeable via sysfs) */ - data->temp_critical = data->temp_max - (1000 * 5); - data->temp_passive = data->temp_max - (1000 * 10); + trips[IMX_TRIP_PASSIVE].temperature = data->temp_max - (1000 * 10); + trips[IMX_TRIP_CRITICAL].temperature = data->temp_max - (1000 * 5); } static int imx_init_from_tempmon_data(struct platform_device *pdev) @@ -743,12 +724,13 @@ static int imx_thermal_probe(struct platform_device *pdev) goto legacy_cleanup; } - data->tz = thermal_zone_device_register("imx_thermal_zone", - IMX_TRIP_NUM, - BIT(IMX_TRIP_PASSIVE), data, - &imx_tz_ops, NULL, - IMX_PASSIVE_DELAY, - IMX_POLLING_DELAY); + data->tz = thermal_zone_device_register_with_trips("imx_thermal_zone", + trips, + ARRAY_SIZE(trips), + BIT(IMX_TRIP_PASSIVE), data, + &imx_tz_ops, NULL, + IMX_PASSIVE_DELAY, + IMX_POLLING_DELAY); if (IS_ERR(data->tz)) { ret = PTR_ERR(data->tz); dev_err(&pdev->dev, @@ -758,8 +740,8 @@ static int imx_thermal_probe(struct platform_device *pdev) dev_info(&pdev->dev, "%s CPU temperature grade - max:%dC" " critical:%dC passive:%dC\n", data->temp_grade, - data->temp_max / 1000, data->temp_critical / 1000, - data->temp_passive / 1000); + data->temp_max / 1000, trips[IMX_TRIP_CRITICAL].temperature / 1000, + trips[IMX_TRIP_PASSIVE].temperature / 1000); /* Enable measurements at ~ 10 Hz */ regmap_write(map, data->socdata->measure_freq_ctrl + REG_CLR, @@ -767,10 +749,10 @@ static int imx_thermal_probe(struct platform_device *pdev) measure_freq = DIV_ROUND_UP(32768, 10); /* 10 Hz */ regmap_write(map, data->socdata->measure_freq_ctrl + REG_SET, measure_freq << data->socdata->measure_freq_shift); - imx_set_alarm_temp(data, data->temp_passive); + imx_set_alarm_temp(data, trips[IMX_TRIP_PASSIVE].temperature); if (data->socdata->version == TEMPMON_IMX6SX) - imx_set_panic_temp(data, data->temp_critical); + imx_set_panic_temp(data, trips[IMX_TRIP_CRITICAL].temperature); regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, data->socdata->power_down_mask); -- 2.34.1