Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3140249pxb; Mon, 9 Nov 2020 03:49:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzG8TXKT67BF31+8v3NzdHjpel5r6WMHHQAS260onl1psaereW+jVZXB3B36WxNfrPIzLQ X-Received: by 2002:aa7:db57:: with SMTP id n23mr15520064edt.208.1604922560098; Mon, 09 Nov 2020 03:49:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604922560; cv=none; d=google.com; s=arc-20160816; b=SIBt8NS7qpwiq4qzFoqjoF7z+PaJflOmBEhKGkF71cGT+F5Q9dtmMdNRDWWvls/qzD mfgvGknGlnKIMvdo0Wd1e1y2wr8XxCbayVLjch1n2F1pKvE9GxxBd4HMGC6hqDvR4/UD 4eFzuCSp7Vx0Hj9M/POHOWj4KCOgsfaDqAIju2JFO1ZIMxNYTKb03cCi5x1XWtQ1F9ex va01GbJEMev7eACSkwCqidh8CLdCcdFEtUwTpLt7AFhJ3BMyQDO8RGhlLhwNI7twSvMo frLaQxLRrX/PNdP0clzLfSWL1kcaJBJaQEsAEM95ESnCFh3i9vgWh+qBaKfPqMm/jP9p vIjA== 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 :message-id:date:subject:cc:to:from; bh=giOAbvvkjX66gUb2He/SdCtlL8SdD+wVXjo0Oag+VQw=; b=wVZRz+6OgRiKDnOMtIuSVVw+8MEXmq0T4qAVykReechYKcrg613Xks5/RgWikyQMVm shFwJsAO/o8xsYZ8/Ls17Oy4hx6UjXOanj52x2ahSyKm/zlkQ6SpEklkJ0MOnWAhmQrQ sLCG1ejEtVeS1asyYxvtOnigqquHPBZpshF8quJzwvC7d9x/vmL32b9quJxi173hHlK5 +tB2+KyiWhqjzcWvUlwZtppif1RCsfNgx81y4izUOiBwaTA1kBANKvVWhGlSUZLJGMIB 58UHk848BcEfZ9fEMiYxwb7P2h13e8qsbHrs/8G6YxC9dNUSXqIFBlufZGvZWae4qngN Oi3Q== ARC-Authentication-Results: i=1; mx.google.com; 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 x16si7047767ejy.343.2020.11.09.03.48.57; Mon, 09 Nov 2020 03:49:20 -0800 (PST) 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; 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 S1729134AbgKILqo (ORCPT + 99 others); Mon, 9 Nov 2020 06:46:44 -0500 Received: from smtp2207-205.mail.aliyun.com ([121.197.207.205]:43987 "EHLO smtp2207-205.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727774AbgKILqo (ORCPT ); Mon, 9 Nov 2020 06:46:44 -0500 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07436324|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.119563-0.00233504-0.878102;FP=10095001690009343397|2|2|8|0|-1|-1|-1;HT=ay29a033018047187;MF=frank@allwinnertech.com;NM=1;PH=DS;RN=11;RT=11;SR=0;TI=SMTPD_---.IuV3ekO_1604922387; Received: from allwinnertech.com(mailfrom:frank@allwinnertech.com fp:SMTPD_---.IuV3ekO_1604922387) by smtp.aliyun-inc.com(10.147.41.187); Mon, 09 Nov 2020 19:46:37 +0800 From: Frank Lee To: anarsoul@gmail.com, tiny.windzz@gmail.com, rui.zhang@intel.com, daniel.lezcano@linaro.org, amitk@kernel.org, mripard@kernel.org, wens@csie.org Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v2] thermal: sun8i: Use bitmap API instead of open code Date: Mon, 9 Nov 2020 19:46:24 +0800 Message-Id: <20201109114624.23035-1-frank@allwinnertech.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yangtao Li The bitmap_* API is the standard way to access data in the bitfield. So convert irq_ack to return an unsigned long, and make things to use bitmap API. Signed-off-by: Yangtao Li --- v2: Make irq_ack to return an unsigned long --- drivers/thermal/sun8i_thermal.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index f8b13071a6f4..8c80bd06dd9f 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -8,6 +8,7 @@ * Based on the work of Josef Gajdusek */ +#include #include #include #include @@ -74,7 +75,7 @@ struct ths_thermal_chip { int (*calibrate)(struct ths_device *tmdev, u16 *caldata, int callen); int (*init)(struct ths_device *tmdev); - int (*irq_ack)(struct ths_device *tmdev); + unsigned long (*irq_ack)(struct ths_device *tmdev); int (*calc_temp)(struct ths_device *tmdev, int id, int reg); }; @@ -146,9 +147,10 @@ static const struct regmap_config config = { .max_register = 0xfc, }; -static int sun8i_h3_irq_ack(struct ths_device *tmdev) +static unsigned long sun8i_h3_irq_ack(struct ths_device *tmdev) { - int i, state, ret = 0; + unsigned long irq_bitmap = 0; + int i, state; regmap_read(tmdev->regmap, SUN8I_THS_IS, &state); @@ -156,16 +158,17 @@ static int sun8i_h3_irq_ack(struct ths_device *tmdev) if (state & SUN8I_THS_DATA_IRQ_STS(i)) { regmap_write(tmdev->regmap, SUN8I_THS_IS, SUN8I_THS_DATA_IRQ_STS(i)); - ret |= BIT(i); + bitmap_set(&irq_bitmap, i, 1); } } - return ret; + return irq_bitmap; } -static int sun50i_h6_irq_ack(struct ths_device *tmdev) +static unsigned long sun50i_h6_irq_ack(struct ths_device *tmdev) { - int i, state, ret = 0; + unsigned long irq_bitmap = 0; + int i, state; regmap_read(tmdev->regmap, SUN50I_H6_THS_DIS, &state); @@ -173,24 +176,22 @@ static int sun50i_h6_irq_ack(struct ths_device *tmdev) if (state & SUN50I_H6_THS_DATA_IRQ_STS(i)) { regmap_write(tmdev->regmap, SUN50I_H6_THS_DIS, SUN50I_H6_THS_DATA_IRQ_STS(i)); - ret |= BIT(i); + bitmap_set(&irq_bitmap, i, 1); } } - return ret; + return irq_bitmap; } static irqreturn_t sun8i_irq_thread(int irq, void *data) { struct ths_device *tmdev = data; - int i, state; - - state = tmdev->chip->irq_ack(tmdev); + unsigned long irq_bitmap = tmdev->chip->irq_ack(tmdev); + int i; - for (i = 0; i < tmdev->chip->sensor_num; i++) { - if (state & BIT(i)) - thermal_zone_device_update(tmdev->sensor[i].tzd, - THERMAL_EVENT_UNSPECIFIED); + for_each_set_bit(i, &irq_bitmap, tmdev->chip->sensor_num) { + thermal_zone_device_update(tmdev->sensor[i].tzd, + THERMAL_EVENT_UNSPECIFIED); } return IRQ_HANDLED; -- 2.28.0