From patchwork Mon Nov 9 11:43:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lee X-Patchwork-Id: 11891341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA0A5C2D0A3 for ; Mon, 9 Nov 2020 11:46:57 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5BB5920731 for ; Mon, 9 Nov 2020 11:46:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="w6kZyRGO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5BB5920731 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=allwinnertech.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=BzkITCUIZcnT2Qh/hOqpOc3je6Clk73S2WQVdf8yPdA=; b=w6kZyRGO++pYQovMRUFpLsz/xu yAyeRNB6znuxw7q4rvlJB+qCWXwPTGHFK39vVxek5AehnpkdC6eXvZxLZa6iw87suIWf+Ati9qlhw ewmEXVvHei+UugJxJ+mFNpdTcTx+0AWHtgxfk1VHQGIcGSyRjytq28Re9LK5lUT+fI7/NXK8Ida1t HIBpz3fcJjl7Bcg8dgpEDXIDicrRMS17eDpFoVLd64+RlLQp17G5+gc88FRPgdsrfaQqX9jrVtXVg jOniF3HB0s0u7tNfLi4sypQTLnERQg0xhYqMnHZLX6BEGTUUqWOVSJGGRnYxV7KdaPWEz4Y9VaTfM uead8aSg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5cx-0002tu-Fu; Mon, 09 Nov 2020 11:46:27 +0000 Received: from smtp2207-205.mail.aliyun.com ([121.197.207.205]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5a6-0001AK-Gm for linux-arm-kernel@lists.infradead.org; Mon, 09 Nov 2020 11:43:49 +0000 X-Alimail-AntiSpam: AC=CONTINUE; BC=0.07436321|-1; CH=green; DM=|CONTINUE|false|; DS=CONTINUE|ham_system_inform|0.119563-0.00233504-0.878102; FP=0|0|0|0|0|-1|-1|-1; HT=ay29a033018047199; MF=frank@allwinnertech.com; NM=1; PH=DS; RN=11; RT=11; SR=0; TI=SMTPD_---.IuVCLW3_1604922186; Received: from allwinnertech.com(mailfrom:frank@allwinnertech.com fp:SMTPD_---.IuVCLW3_1604922186) by smtp.aliyun-inc.com(10.147.44.129); Mon, 09 Nov 2020 19:43:12 +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 Subject: [PATCH] thermal: sun8i: Use bitmap API instead of open code Date: Mon, 9 Nov 2020 19:43:02 +0800 Message-Id: <20201109114302.22740-1-frank@allwinnertech.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201109_064330_847972_1CDB7640 X-CRM114-Status: GOOD ( 13.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yangtao Li , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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;