From patchwork Mon Nov 9 11:46:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lee X-Patchwork-Id: 11891363 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 5F42AC2D0A3 for ; Mon, 9 Nov 2020 12:02:55 +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 D9AAE20789 for ; Mon, 9 Nov 2020 12:02:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="vlVFuVv1"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ArdUuToY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9AAE20789 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=vlVFuVv1H73j58KJX1ya+kWPQ0 BsUPS7Jod8rkZLlayZ8a+rz9Mys3rDdkRq86wPjYxlqLHl6sbwNZVCBMyHpamZMvQ6cpt0WHP9BfD K7ggoB/ctM9k2RsJvpsCG4xUOvykBHzT0CyH3ECjRV+Q6pAtV3Nvrvb3Xqe1gGtlkuDAx1gMYhUBV FEPB1Mmhj//uLDRvhRpu3gfDeEZAdARnJg33pJ4Li1AoGHYnNitr4ykc2Q0rWM7nOUdIgl8ozKCy3 pBl5HTyVFYgb9qh5d7HCrBrsHxs0jI606vXzFNbj5qT+gsri69aokYBWbk4fWvn9Mmkbrd+xTEJbr qKDNp+0g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5rg-0005yC-3R; Mon, 09 Nov 2020 12:01:40 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5rf-0005wf-5q for linux-arm-kernel@merlin.infradead.org; Mon, 09 Nov 2020 12:01:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=giOAbvvkjX66gUb2He/SdCtlL8SdD+wVXjo0Oag+VQw=; b=ArdUuToY7324N+q8A+dTcA8Z/s SbqxH3WYw3UEfNV1p9Lpypu2Me1CJStyRsNM9tprZu85xNzZOXmnS8nroIbB9sWhzSr6RShoEkdpO 8kgSC7KcR7Brn8TNWfOES8HBxD3JSMWG+C+THP6rUmCuugUcDfUyZIPWQlCRzZBaeUN+6QQGuLcS/ kHRXWLjzoy7Cmk+31J+ph9u1MrE9sN7PU/TzXpgQckzTMcP3v4MKWshRM9lXRKMDcLZyfEsZzxpl6 qLm778nwtRwFGfCs3reKsvNSZWhhjmDH8YB49t+shVYCK7O86Y/DemvLQRv4f2AsQikTLxy1hSCoD GYwtQ4JA==; Received: from smtp2207-205.mail.aliyun.com ([121.197.207.205]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5dS-0007SR-Nu for linux-arm-kernel@lists.infradead.org; Mon, 09 Nov 2020 11:47:02 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201109_114659_256561_E62A049C X-CRM114-Status: GOOD ( 13.88 ) 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 Acked-by: Maxime Ripard --- 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;