Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3516236pxb; Mon, 4 Apr 2022 19:33:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz96uPhoYFSKF7WvvQBn0pzHuDLGjYW0vV3J7GF1pWV7pH3saW6rcyEljnsg19JeR0lzyZd X-Received: by 2002:a05:6a00:1ca1:b0:4fa:7e80:6957 with SMTP id y33-20020a056a001ca100b004fa7e806957mr1382536pfw.33.1649126001002; Mon, 04 Apr 2022 19:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649126000; cv=none; d=google.com; s=arc-20160816; b=cSKYJUo0HYYTu+UaMW2/0PkW1ip6PiZx5OfIqohKlV05kY0LhCjxHyHZl8EWap48bM 3BE4A250O2Ib1/Pgbc3JLUNmIl/jXheBPIzdVDijbwj7f7wFC7OgpNV4eKUm986+O7mm 18+p6SKoycl3PA0cKcrN6DWnyBNQ9Z5XflOH5ZhfKWGWqRTsN7j91BiFCBeOS8eUeDnu R4dsJcuisV+ONSGomDS/pltap0gfwMEGCfGfa+rSrP858v/uFfzWfAftFXpDWXicw4zk 2j43hD8lQoxQfvbGz1uxERxxreZBZaDDlIPr4xGLyl0cL/273sLkK8OQ/2Gfo54VnFQ5 upJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=g/IIwgDHytkQI9HfTfiqiWQG49DprqFxe9noAIe39lM=; b=O9psZsinijbScStheqYO+EnIFrjwSNr6scyP8DgVhsXyuZBRnsjmqlrBfxcX0+Rm8R PoxyfsglTezZWpTGvpCFGeg2mstDu4uveM0JG/w2rWIeUiLBqD/q9c1IIhMQyIpHveW/ KcDyosctmKVSdGotCfbifoqB10mciqcOSaOOsQ/3av713w1CQgHFK7e9g621f/GHZmhc ODWSDHdRQX8Yd0pSLtIS/DNJPX+qDKY0gPTPEWz54wGJMJ92DwhwCVgaOsnwOujBYZk0 nZYV4y8OFNNuNs1eSu8Q9Cuoy13RKhFwuuWv55yLqx5rdlbIWH70/HiXTb1WGdrJnE5g gCEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=uVZ9Gqzp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id p3-20020a170902b08300b00153b2d16461si8133772plr.105.2022.04.04.19.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 19:33:20 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=uVZ9Gqzp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A999C2F065C; Mon, 4 Apr 2022 17:56:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358856AbiDCNU2 (ORCPT + 99 others); Sun, 3 Apr 2022 09:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358861AbiDCNUY (ORCPT ); Sun, 3 Apr 2022 09:20:24 -0400 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60644F54; Sun, 3 Apr 2022 06:18:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1648991910; x=1680527910; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=g/IIwgDHytkQI9HfTfiqiWQG49DprqFxe9noAIe39lM=; b=uVZ9Gqzp33qwZLcysPaID3sLHZXeePR+C2+fl+BfS0rHinvTcwT2IpAr 13u7xBBoevNelNuGn3vXD4aB3ZAcrR9EeXwGaKXS0MPpC38Gew975rU7B zaWRR3UGEzsNFkRVLCze2MrYoNYPIcG+XexbZIxm1EoL577+aoWJ1s7Sb o=; Received: from unknown (HELO ironmsg-SD-alpha.qualcomm.com) ([10.53.140.30]) by alexa-out-sd-02.qualcomm.com with ESMTP; 03 Apr 2022 06:18:30 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg-SD-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2022 06:18:29 -0700 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Sun, 3 Apr 2022 06:18:29 -0700 Received: from jprakash-linux.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Sun, 3 Apr 2022 06:18:24 -0700 From: Jishnu Prakash To: , , , , , , , , , , , , , "Thara Gopinath" , "Rafael J. Wysocki" , , , CC: , Jishnu Prakash Subject: [RESEND PATCH V5 3/4] thermal: qcom: Add support for multiple generations of devices Date: Sun, 3 Apr 2022 18:47:48 +0530 Message-ID: <1648991869-20899-4-git-send-email-quic_jprakash@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1648991869-20899-1-git-send-email-quic_jprakash@quicinc.com> References: <1648991869-20899-1-git-send-email-quic_jprakash@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Refactor code to support multiple generations of ADC_TM devices by defining gen number, irq name and disable, configure, isr and init APIs in the individual data structs. Signed-off-by: Jishnu Prakash Reviewed-by: Jonathan Cameron Reviewed-by: Dmitry Baryshkov --- drivers/thermal/qcom/qcom-spmi-adc-tm5.c | 82 ++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c index 824671c..6d8fcf2 100644 --- a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c +++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c @@ -78,11 +78,10 @@ enum adc5_timer_select { ADC5_TIMER_SEL_NONE, }; -struct adc_tm5_data { - const u32 full_scale_code_volt; - unsigned int *decimation; - unsigned int *hw_settle; - bool is_hc; +enum adc5_gen { + ADC_TM5, + ADC_TM_HC, + ADC_TM5_MAX }; enum adc_tm5_cal_method { @@ -92,6 +91,19 @@ enum adc_tm5_cal_method { }; struct adc_tm5_chip; +struct adc_tm5_channel; + +struct adc_tm5_data { + const u32 full_scale_code_volt; + unsigned int *decimation; + unsigned int *hw_settle; + int (*disable_channel)(struct adc_tm5_channel *channel); + int (*configure)(struct adc_tm5_channel *channel, int low, int high); + irqreturn_t (*isr)(int irq, void *data); + int (*init)(struct adc_tm5_chip *chip); + char *irq_name; + int gen; +}; /** * struct adc_tm5_channel - ADC Thermal Monitoring channel data. @@ -139,22 +151,6 @@ struct adc_tm5_chip { u16 base; }; -static const struct adc_tm5_data adc_tm5_data_pmic = { - .full_scale_code_volt = 0x70e4, - .decimation = (unsigned int []) { 250, 420, 840 }, - .hw_settle = (unsigned int []) { 15, 100, 200, 300, 400, 500, 600, 700, - 1000, 2000, 4000, 8000, 16000, 32000, - 64000, 128000 }, -}; - -static const struct adc_tm5_data adc_tm_hc_data_pmic = { - .full_scale_code_volt = 0x70e4, - .decimation = (unsigned int []) { 256, 512, 1024 }, - .hw_settle = (unsigned int []) { 0, 100, 200, 300, 400, 500, 600, 700, - 1000, 2000, 4000, 6000, 8000, 10000 }, - .is_hc = true, -}; - static int adc_tm5_read(struct adc_tm5_chip *adc_tm, u16 offset, u8 *data, int len) { return regmap_bulk_read(adc_tm->regmap, adc_tm->base + offset, data, len); @@ -343,14 +339,14 @@ static int adc_tm5_set_trips(void *data, int low, int high) channel->channel, low, high); if (high == INT_MAX && low <= -INT_MAX) - ret = adc_tm5_disable_channel(channel); + ret = chip->data->disable_channel(channel); else - ret = adc_tm5_configure(channel, low, high); + ret = chip->data->configure(channel, low, high); return ret; } -static struct thermal_zone_of_device_ops adc_tm5_ops = { +static struct thermal_zone_of_device_ops adc_tm5_thermal_ops = { .get_temp = adc_tm5_get_temp, .set_trips = adc_tm5_set_trips, }; @@ -366,7 +362,7 @@ static int adc_tm5_register_tzd(struct adc_tm5_chip *adc_tm) tzd = devm_thermal_zone_of_sensor_register(adc_tm->dev, adc_tm->channels[i].channel, &adc_tm->channels[i], - &adc_tm5_ops); + &adc_tm5_thermal_ops); if (IS_ERR(tzd)) { if (PTR_ERR(tzd) == -ENODEV) { dev_warn(adc_tm->dev, "thermal sensor on channel %d is not used\n", @@ -526,6 +522,33 @@ static int adc_tm5_get_dt_channel_data(struct adc_tm5_chip *adc_tm, return 0; } +static const struct adc_tm5_data adc_tm5_data_pmic = { + .full_scale_code_volt = 0x70e4, + .decimation = (unsigned int []) { 250, 420, 840 }, + .hw_settle = (unsigned int []) { 15, 100, 200, 300, 400, 500, 600, 700, + 1000, 2000, 4000, 8000, 16000, 32000, + 64000, 128000 }, + .disable_channel = adc_tm5_disable_channel, + .configure = adc_tm5_configure, + .isr = adc_tm5_isr, + .init = adc_tm5_init, + .irq_name = "pm-adc-tm5", + .gen = ADC_TM5, +}; + +static const struct adc_tm5_data adc_tm_hc_data_pmic = { + .full_scale_code_volt = 0x70e4, + .decimation = (unsigned int []) { 256, 512, 1024 }, + .hw_settle = (unsigned int []) { 0, 100, 200, 300, 400, 500, 600, 700, + 1000, 2000, 4000, 6000, 8000, 10000 }, + .disable_channel = adc_tm5_disable_channel, + .configure = adc_tm5_configure, + .isr = adc_tm5_isr, + .init = adc_tm_hc_init, + .irq_name = "pm-adc-tm5", + .gen = ADC_TM_HC, +}; + static int adc_tm5_get_dt_data(struct adc_tm5_chip *adc_tm, struct device_node *node) { struct adc_tm5_channel *channels; @@ -623,10 +646,7 @@ static int adc_tm5_probe(struct platform_device *pdev) return ret; } - if (adc_tm->data->is_hc) - ret = adc_tm_hc_init(adc_tm); - else - ret = adc_tm5_init(adc_tm); + ret = adc_tm->data->init(adc_tm); if (ret) { dev_err(dev, "adc-tm init failed\n"); return ret; @@ -638,8 +658,8 @@ static int adc_tm5_probe(struct platform_device *pdev) return ret; } - return devm_request_threaded_irq(dev, irq, NULL, adc_tm5_isr, - IRQF_ONESHOT, "pm-adc-tm5", adc_tm); + return devm_request_threaded_irq(dev, irq, NULL, adc_tm->data->isr, + IRQF_ONESHOT, adc_tm->data->irq_name, adc_tm); } static const struct of_device_id adc_tm5_match_table[] = { -- 2.7.4