Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp480403pxb; Mon, 16 Aug 2021 09:44:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaRxZXwvV+pkOBFlUBhxcBkYvpTmZiLllhvzP+yyDHkIq4RJueN/Z6k0nhsYYTCo7QM778 X-Received: by 2002:a05:6e02:1bc5:: with SMTP id x5mr6432497ilv.167.1629132248868; Mon, 16 Aug 2021 09:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629132248; cv=none; d=google.com; s=arc-20160816; b=nsk1VghzuX7VQGI+N5MvAmqB++o+70R7mdsrLVu4oexAQAOKQOCFucGfvaTKFS655y UXENFY6fsDHZgi2LnmTCUfoPDXEOL8qWxe29z+Uktur/ociqVgkQb7p9Gpbd4FvsR1JG W5wW/kHXpSb6fbq+1F4KZ6kk0Ua+3YWpG26/c1Sv1ILxNLjPuMhp7TvrI2pLEQZQ7mmp JcgQaA1QVBheANjqmgrm6dKGwtcaPp+zY27vTZWbfpYf44T9RkAcowiPe5K2oedjr9MR V7me04nydVJ+Mm8bzg2ki7TZTGA/x8CfH6kmI6XgLMTGDMYIq+fqHaYCQGgI2U48qRcc hNhA== 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=LikR4SFj4ATUIJU/5gMV0mpJ4XVxM4lGIJAeQD6Dp3E=; b=fCuqztK3nC4TADKOQOi9dGN5wn6eCEp8a+SdUTYp7z0A2CWo2j1wCyFr+uwC56DJfT Lkp+HHa1lyeBhrwRlvUyZM7SjSAZQ7q4BGi9mNs1995+q3Q4I2UMiG+tjKu4oT/5bmq7 Mfx8t3ScmLF8AsL5izknxNHx22OKaZSWA0QXeKStFSK8GB8gAIf7aWUNLYw/uiJVVupb 8gNu7aI1pMeTglHjT47SD//BhnfXNz+lH5z78OF4rgu01qSTCPgRJGL/UsUT20QzyOss kxeVIDB9p5g84c2xmvBe4SfODEm64F5F3Auj6LN5Fgd8RrCWUeyACLK3l5QjrsddAaNu mCCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=VPHHAPln; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d3si11864889ilq.47.2021.08.16.09.43.54; Mon, 16 Aug 2021 09:44:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=VPHHAPln; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232083AbhHPQm0 (ORCPT + 99 others); Mon, 16 Aug 2021 12:42:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231648AbhHPQmW (ORCPT ); Mon, 16 Aug 2021 12:42:22 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B57FDC061764 for ; Mon, 16 Aug 2021 09:41:50 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id q11so24519312wrr.9 for ; Mon, 16 Aug 2021 09:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LikR4SFj4ATUIJU/5gMV0mpJ4XVxM4lGIJAeQD6Dp3E=; b=VPHHAPln+J/IXLEgdpzQwQhDbRCShoyhlbL0RBKIJrFq8hGBjg5TLVcXCKg9hpZtKM rACvFHgGQi9paw45pN+HOaOGhJEPSGcmeMnNhyy5jxCD1aB1LG8ng27lRXrM3CqGt+5i 4zq43Hy7/yZbg5mrbrJ6uDMj2DdGAi38o4k6C812DzB3zHEC18X8ut2IKML9FXkt8UKM nNavnuz6UWnn0qLYvt53mm+nB4gm6YcwvPut2TfpS5LuX7+hId4zNErIaI11x+gsvJZN T9tMvfDC53gVHeKr7S/Z2cdNBQbZjWXLF9Nywtot4qINlxhNIwHgNski6Isl12pnTc9z VQIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LikR4SFj4ATUIJU/5gMV0mpJ4XVxM4lGIJAeQD6Dp3E=; b=Wq64b+ngwY/SsJTd/R1bdKWHBlKYKDPhmKgbvcbYkigQ8sf8gJMx/qk0u8RfWyCLsj JrVmzwqmfLALMQ9QvE5TaovvWQuzsdiH6s3T2JmjycnsgmW9HrFTPBYbKN/+nlOLeyx9 lZC08JmarV8L/rAuFTBXhtQwV/Q8GU2jet1tibIMG8P4fSIDHd5bBl5Ju1w1CSHXsR8k 8By++wCLg9n0OAOWpMe0/vCkc5ekVQK5B2BDooTDUsYww7LyNo3CJ24+0eZQ18tzc3S7 PqXFpHsM3CF6OweEiHf64MooQMwnfYq5VR/JKF0pverTgUPrrcVMlRjCV03KPm/YffE9 jvrw== X-Gm-Message-State: AOAM530jxEGZxCJDq6mvWX9ix7IZi2bOfFoVZ/0vTQULmemslBjNdtit unNs+RouNGn+tZiftTgFrQQNXg== X-Received: by 2002:adf:f08e:: with SMTP id n14mr19280029wro.427.1629132109322; Mon, 16 Aug 2021 09:41:49 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3a81:3690:b885:8dcf:f8c6:7841]) by smtp.gmail.com with ESMTPSA id m10sm15211730wro.63.2021.08.16.09.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Aug 2021 09:41:48 -0700 (PDT) From: Alexandre Bailon To: rui.zhang@intel.com, daniel.lezcano@linaro.org, robh+dt@kernel.org, matthias.bgg@gmail.com Cc: ben.tseng@mediatek.com, michael.kao@mediatek.com, ethan.chang@mediatek.com, fparent@baylibre.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Alexandre Bailon Subject: [PATCH 2/3] thermal: mediatek: Add thermal zone settings for mt8195 Date: Mon, 16 Aug 2021 18:43:06 +0200 Message-Id: <20210816164307.557315-3-abailon@baylibre.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210816164307.557315-1-abailon@baylibre.com> References: <20210816164307.557315-1-abailon@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Kao Add thermal zone settings for mt8195 Signed-off-by: Michael Kao Signed-off-by: Ben Tseng Signed-off-by: Alexandre Bailon --- drivers/thermal/mediatek/soc_temp_lvts.c | 206 +++++++++++++++++++++-- 1 file changed, 192 insertions(+), 14 deletions(-) diff --git a/drivers/thermal/mediatek/soc_temp_lvts.c b/drivers/thermal/mediatek/soc_temp_lvts.c index 8153edaaf8150..ddcedcedbbc16 100644 --- a/drivers/thermal/mediatek/soc_temp_lvts.c +++ b/drivers/thermal/mediatek/soc_temp_lvts.c @@ -53,6 +53,7 @@ #define CLOCK_26MHZ_CYCLE_NS (38) #define BUS_ACCESS_US (2) +#define GOLDEN_TEMP_MAX (62) #define FEATURE_DEVICE_AUTO_RCK (BIT(0)) #define FEATURE_CK26M_ACTIVE (BIT(1)) @@ -577,21 +578,10 @@ static int prepare_calibration_data(struct lvts_data *lvts_data) if (!cal_data->count_rc) return -ENOMEM; - if (ops->efuse_to_cal_data) + if (ops->efuse_to_cal_data && !cal_data->use_fake_efuse) ops->efuse_to_cal_data(lvts_data); - - cal_data->use_fake_efuse = 1; - if (cal_data->golden_temp != 0) { - cal_data->use_fake_efuse = 0; - } else { - for (i = 0; i < lvts_data->num_sensor; i++) { - if (cal_data->count_r[i] != 0 || - cal_data->count_rc[i] != 0) { - cal_data->use_fake_efuse = 0; - break; - } - } - } + if (cal_data->golden_temp == 0 || cal_data->golden_temp > GOLDEN_TEMP_MAX) + cal_data->use_fake_efuse = 1; if (cal_data->use_fake_efuse) { /* It means all efuse data are equal to 0 */ @@ -1254,6 +1244,190 @@ static struct lvts_data mt6873_lvts_data = { }, }; +/*================================================== + * LVTS MT8195 + *================================================== + */ + +#define MT8195_NUM_LVTS (ARRAY_SIZE(mt8195_tc_settings)) + +enum mt8195_lvts_domain { + MT8195_AP_DOMAIN, + MT8195_MCU_DOMAIN, + MT8195_NUM_DOMAIN +}; + +enum mt8195_lvts_sensor_enum { + MT8195_TS1_0, + MT8195_TS1_1, + MT8195_TS2_0, + MT8195_TS2_1, + MT8195_TS3_0, + MT8195_TS3_1, + MT8195_TS3_2, + MT8195_TS3_3, + MT8195_TS4_0, + MT8195_TS4_1, + MT8195_TS5_0, + MT8195_TS5_1, + MT8195_TS6_0, + MT8195_TS6_1, + MT8195_TS6_2, + MT8195_TS7_0, + MT8195_TS7_1, + MT8195_NUM_TS +}; + +static void mt8195_efuse_to_cal_data(struct lvts_data *lvts_data) +{ + struct sensor_cal_data *cal_data = &lvts_data->cal_data; + + cal_data->golden_temp = GET_CAL_DATA_BITMASK(0, 31, 24); + cal_data->count_r[MT8195_TS1_0] = GET_CAL_DATA_BITMASK(1, 23, 0); + cal_data->count_r[MT8195_TS1_1] = (GET_CAL_DATA_BITMASK(2, 15, 0) << 8) + + GET_CAL_DATA_BITMASK(1, 31, 24); + cal_data->count_r[MT8195_TS2_0] = GET_CAL_DATA_BITMASK(3, 31, 8); + cal_data->count_r[MT8195_TS2_1] = GET_CAL_DATA_BITMASK(4, 23, 0); + cal_data->count_r[MT8195_TS3_0] = (GET_CAL_DATA_BITMASK(6, 7, 0) << 16) + + GET_CAL_DATA_BITMASK(5, 31, 16); + cal_data->count_r[MT8195_TS3_1] = GET_CAL_DATA_BITMASK(6, 31, 8); + cal_data->count_r[MT8195_TS3_2] = GET_CAL_DATA_BITMASK(7, 23, 0); + cal_data->count_r[MT8195_TS3_3] = (GET_CAL_DATA_BITMASK(8, 15, 0) << 8) + + GET_CAL_DATA_BITMASK(7, 31, 24); + cal_data->count_r[MT8195_TS4_0] = GET_CAL_DATA_BITMASK(9, 31, 8); + cal_data->count_r[MT8195_TS4_1] = GET_CAL_DATA_BITMASK(10, 23, 0); + cal_data->count_r[MT8195_TS5_0] = (GET_CAL_DATA_BITMASK(12, 7, 0) << 16) + + GET_CAL_DATA_BITMASK(11, 31, 16); + cal_data->count_r[MT8195_TS5_1] = GET_CAL_DATA_BITMASK(12, 31, 8); + cal_data->count_r[MT8195_TS6_0] = (GET_CAL_DATA_BITMASK(14, 15, 0) << 8) + + GET_CAL_DATA_BITMASK(13, 31, 24); + cal_data->count_r[MT8195_TS6_1] = (GET_CAL_DATA_BITMASK(15, 7, 0) << 16) + + GET_CAL_DATA_BITMASK(14, 31, 16); + cal_data->count_r[MT8195_TS6_2] = GET_CAL_DATA_BITMASK(15, 31, 8); + cal_data->count_r[MT8195_TS7_0] = (GET_CAL_DATA_BITMASK(17, 15, 0) << 8) + + GET_CAL_DATA_BITMASK(16, 31, 24); + cal_data->count_r[MT8195_TS7_1] = (GET_CAL_DATA_BITMASK(18, 7, 0) << 16) + + GET_CAL_DATA_BITMASK(17, 31, 16); + cal_data->count_rc[MT8195_TS1_0] = (GET_CAL_DATA_BITMASK(3, 7, 0) << 16) + + GET_CAL_DATA_BITMASK(2, 31, 16); + cal_data->count_rc[MT8195_TS2_0] = (GET_CAL_DATA_BITMASK(5, 15, 0) << 8) + + GET_CAL_DATA_BITMASK(4, 31, 24); + cal_data->count_rc[MT8195_TS3_0] = (GET_CAL_DATA_BITMASK(9, 7, 0) << 16) + + GET_CAL_DATA_BITMASK(8, 31, 16); + cal_data->count_rc[MT8195_TS4_0] = (GET_CAL_DATA_BITMASK(11, 15, 0) << 8) + + GET_CAL_DATA_BITMASK(10, 31, 24); + cal_data->count_rc[MT8195_TS5_0] = GET_CAL_DATA_BITMASK(13, 23, 0); + cal_data->count_rc[MT8195_TS6_0] = GET_CAL_DATA_BITMASK(16, 23, 0); + cal_data->count_rc[MT8195_TS7_0] = GET_CAL_DATA_BITMASK(18, 31, 8); +} + +static struct tc_settings mt8195_tc_settings[] = { + [0] = { + .domain_index = MT8195_MCU_DOMAIN, + .addr_offset = 0x0, + .num_sensor = 2, + .sensor_map = {MT8195_TS1_0, MT8195_TS1_1}, + .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT1, + .hw_reboot_trip_point = 117000, + .irq_bit = BIT(3), + }, + [1] = { + .domain_index = MT8195_MCU_DOMAIN, + .addr_offset = 0x100, + .num_sensor = 2, + .sensor_map = {MT8195_TS2_0, MT8195_TS2_1}, + .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT0, + .hw_reboot_trip_point = 117000, + .irq_bit = BIT(4), + }, + [2] = { + .domain_index = MT8195_MCU_DOMAIN, + .addr_offset = 0x200, + .num_sensor = 4, + .sensor_map = {MT8195_TS3_0, MT8195_TS3_1, MT8195_TS3_2, MT8195_TS3_3}, + .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT0, + .hw_reboot_trip_point = 117000, + .irq_bit = BIT(5), + }, + [3] = { + .domain_index = MT8195_AP_DOMAIN, + .addr_offset = 0x0, + .num_sensor = 2, + .sensor_map = {MT8195_TS4_0, MT8195_TS4_1}, + .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT0, + .hw_reboot_trip_point = 117000, + .irq_bit = BIT(3), + }, + [4] = { + .domain_index = MT8195_AP_DOMAIN, + .addr_offset = 0x100, + .num_sensor = 2, + .sensor_map = {MT8195_TS5_0, MT8195_TS5_1}, + .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT1, + .hw_reboot_trip_point = 117000, + .irq_bit = BIT(4), + }, + [5] = { + .domain_index = MT8195_AP_DOMAIN, + .addr_offset = 0x200, + .num_sensor = 3, + .sensor_map = {MT8195_TS6_0, MT8195_TS6_1, MT8195_TS6_2}, + .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT1, + .hw_reboot_trip_point = 117000, + .irq_bit = BIT(5), + }, + [6] = { + .domain_index = MT8195_AP_DOMAIN, + .addr_offset = 0x300, + .num_sensor = 2, + .sensor_map = {MT8195_TS7_0, MT8195_TS7_1}, + .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT0, + .hw_reboot_trip_point = 117000, + .irq_bit = BIT(6), + } +}; + +static struct lvts_data mt8195_lvts_data = { + .num_domain = MT8195_NUM_DOMAIN, + .num_tc = MT8195_NUM_LVTS, + .tc = mt8195_tc_settings, + .num_sensor = MT8195_NUM_TS, + .ops = { + .efuse_to_cal_data = mt8195_efuse_to_cal_data, + .device_enable_and_init = device_enable_and_init_v4, + .device_enable_auto_rck = device_enable_auto_rck_v4, + .device_read_count_rc_n = device_read_count_rc_n_v4, + .set_cal_data = set_calibration_data_v4, + .init_controller = init_controller_v4, + }, + .feature_bitmap = FEATURE_DEVICE_AUTO_RCK, + .num_efuse_addr = 22, + .num_efuse_block = 2, + .cal_data = { + .default_golden_temp = 50, + .default_count_r = 35000, + .default_count_rc = 2750, + }, + .coeff = { + .a = -250460, + .b = 250460, + }, +}; + /*================================================== *================================================== * Support chips @@ -1264,6 +1438,10 @@ static const struct of_device_id lvts_of_match[] = { .compatible = "mediatek,mt6873-lvts", .data = (void *)&mt6873_lvts_data, }, + { + .compatible = "mediatek,mt8195-lvts", + .data = (void *)&mt8195_lvts_data, + }, { }, }; -- 2.31.1