Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0519C43217 for ; Mon, 29 Nov 2021 02:27:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240209AbhK2CaY (ORCPT ); Sun, 28 Nov 2021 21:30:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236803AbhK2C2W (ORCPT ); Sun, 28 Nov 2021 21:28:22 -0500 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D220CC061574 for ; Sun, 28 Nov 2021 18:25:05 -0800 (PST) Received: by mail-lj1-x235.google.com with SMTP id v15so31633985ljc.0 for ; Sun, 28 Nov 2021 18:25:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=rFDHshpl2dqAGPF3MoHGk3Vso6gtNhODB+79/AogQ9g=; b=XBoonPe1eIrnsHDCUwya0qnIP3hjiEyRPURX47zbUH0f58LGJuVJETenDe+4PXJ14k /bHpX3L8SJgD3IMgcd6mup+YgygXHlovZL2F1iQB8y5+Jq4d3Fe8jAPXcvB00GaGGJRT z2B0nnFYKIjih7idRXWK9YCOmAZv7ewoOG6E1Ez+FMEfDI9c9aTrdWwppa/zRR0yfUme RupkhNrKMioJ0mkKSswG+1Z1IDuL3QqtcJNGep+8MgwGTEXGDy9prqlZyG4bfLYKcqjI JSNg4Me74hl4btPVwq77eBXGI4p+Q5itN5Mjo6LOAxPcxQit4MdY+y9wOGLDoZRyADFR b5Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=rFDHshpl2dqAGPF3MoHGk3Vso6gtNhODB+79/AogQ9g=; b=dfg/vp9lGxDVicAZJFljSinUMqHwI8rZbo/Zxf6I1j6qy9oD1LwonGoYBM1PdQkEvR zVDtrUSgFWOg4CC0ZWE+UePYT5SuJio76YYW015oZRcX/Q9fJpVIibRKJi9zErGY1tGV DGSVigJzsC1/iMUqqQjJ9LNwzka9jjWGVRfT8PmHdFlZABCxF+/TIxbrjcLP1FE2mguY ZP/o6Sn8+rp39lYNUCgjCIr807THpNwTlePrt+QtFwTeyXmA9LkfeV4wnccHzmAXxJPA G0StMYZ+lrj20ONofRhtrmi43j6iGfTtItdrrLmbhbZc2QgB37tM9rzTHH4nMhsgpknl 0RaQ== X-Gm-Message-State: AOAM531a3ITn9DOJGAi6XeAy1LEtUAtd2lZO6E4ScGuY3No1Kuk8VFrV sXEHuRuVMTN53IKyxvIRJ+XjFw== X-Google-Smtp-Source: ABdhPJyNWsMZuDlI5sEJ6vas937eCxVotkiqOCL8L/+b7scSUgcDIF51Tfu40fRc9OcwqKFhApin4g== X-Received: by 2002:a2e:9197:: with SMTP id f23mr45782387ljg.235.1638152704037; Sun, 28 Nov 2021 18:25:04 -0800 (PST) Received: from [192.168.1.211] ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id m20sm1173100lfu.241.2021.11.28.18.25.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 28 Nov 2021 18:25:03 -0800 (PST) Subject: Re: [PATCH V3 3/4] thermal: qcom: Add support for multiple generations of devices To: Jishnu Prakash , agross@kernel.org, bjorn.andersson@linaro.org, devicetree@vger.kernel.org, mka@chromium.org, robh+dt@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, manivannan.sadhasivam@linaro.org, linus.walleij@linaro.org, quic_kgunda@quicinc.com, quic_aghayal@quicinc.com, daniel.lezcano@linaro.org, rui.zhang@intel.com, quic_subbaram@quicinc.com, jic23@kernel.org, amitk@kernel.org, Thara Gopinath , "Rafael J. Wysocki" , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-arm-msm-owner@vger.kernel.org, linux-iio@vger.kernel.org References: <1637647025-20409-1-git-send-email-quic_jprakash@quicinc.com> <1637647025-20409-4-git-send-email-quic_jprakash@quicinc.com> From: Dmitry Baryshkov Message-ID: <47228209-552e-b148-c93a-4fbb5a36583e@linaro.org> Date: Mon, 29 Nov 2021 05:25:02 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <1637647025-20409-4-git-send-email-quic_jprakash@quicinc.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/11/2021 08:57, Jishnu Prakash wrote: > Refactor code to support multiple generations of ADC_TM devices > by defining gen number, irq name and disable, configure and isr > APIs in the individual data structs. > > Signed-off-by: Jishnu Prakash Reviewed-by: Dmitry Baryshkov Minor question below. > --- > drivers/thermal/qcom/qcom-spmi-adc-tm5.c | 76 ++++++++++++++++++++------------ > 1 file changed, 48 insertions(+), 28 deletions(-) > > diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c > index 824671c..fc8cd45 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,18 @@ 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); > + char *irq_name; > + int gen; > +}; Any reason for moving the adc_tm5_data definition? It is still prefix with the adc_tmp5_channel declaration. > > /** > * struct adc_tm5_channel - ADC Thermal Monitoring channel data. > @@ -139,22 +150,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 +338,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 +361,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 +521,31 @@ 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, > + .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, > + .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,7 +643,7 @@ static int adc_tm5_probe(struct platform_device *pdev) > return ret; > } > > - if (adc_tm->data->is_hc) > + if (adc_tm->data->gen == ADC_TM_HC) > ret = adc_tm_hc_init(adc_tm); > else > ret = adc_tm5_init(adc_tm); > @@ -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[] = { > -- With best wishes Dmitry