From patchwork Mon May 4 12:55:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11525855 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B365015E6 for ; Mon, 4 May 2020 12:56:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 994F1208DB for ; Mon, 4 May 2020 12:56:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZSw/dqbP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728191AbgEDM4l (ORCPT ); Mon, 4 May 2020 08:56:41 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:24629 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726509AbgEDM4k (ORCPT ); Mon, 4 May 2020 08:56:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588596999; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RRsduTY4mcDOTKWscR+hBSS03aI89AMG50aPQqbJQlc=; b=ZSw/dqbPpuGNkUTzYXn/oL4GhwP1bY1RCXGTKCQxcB4+C8c11GapHxcc8oYmIIqnNqJBFQ uRRgZVI3Hs3FF5fzgcTC0UT83hvgzcwXSC0QigPi5IG+lsK+mDcGAGCJs+LUgKluPhjIw8 39t3UPS6OTPNQG57x3BhODlVL+KAVtA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-107-m5gYanChNgidUrlK_C-aaQ-1; Mon, 04 May 2020 08:56:26 -0400 X-MC-Unique: m5gYanChNgidUrlK_C-aaQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F09783DE6E; Mon, 4 May 2020 12:56:23 +0000 (UTC) Received: from x1.localdomain.com (ovpn-114-224.ams2.redhat.com [10.36.114.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE4865D9D5; Mon, 4 May 2020 12:56:20 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Darren Hart , Andy Shevchenko , Jonathan Cameron Cc: Hans de Goede , linux-acpi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, Andy Shevchenko Subject: [PATCH v4 07/11] iio: light: cm32181: Change reg_init to use a bitmap of which registers to init Date: Mon, 4 May 2020 14:55:47 +0200 Message-Id: <20200504125551.434647-7-hdegoede@redhat.com> In-Reply-To: <20200504125551.434647-1-hdegoede@redhat.com> References: <20200504125551.434647-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is a preparation patch for reading some ACPI tables which give init values for multiple registers. Reviewed-by: Andy Shevchenko Signed-off-by: Hans de Goede --- Changes in v2: - Use unsigned long for init_regs_bitmap - Use for_each_set_bit() --- drivers/iio/light/cm32181.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c index fd760e209dfa..f5af986e1ed4 100644 --- a/drivers/iio/light/cm32181.c +++ b/drivers/iio/light/cm32181.c @@ -26,7 +26,7 @@ #define CM32181_REG_ADDR_ID 0x07 /* Number of Configurable Registers */ -#define CM32181_CONF_REG_NUM 0x01 +#define CM32181_CONF_REG_NUM 4 /* CMD register */ #define CM32181_CMD_ALS_DISABLE BIT(0) @@ -53,10 +53,6 @@ #define SMBUS_ALERT_RESPONSE_ADDRESS 0x0c -static const u8 cm32181_reg[CM32181_CONF_REG_NUM] = { - CM32181_REG_ADDR_CMD, -}; - struct cm32181_chip_info { const char *name; const int *als_it_bits; @@ -69,6 +65,7 @@ struct cm32181_chip { const struct cm32181_chip_info *info; struct mutex lock; u16 conf_regs[CM32181_CONF_REG_NUM]; + unsigned long init_regs_bitmap; int calibscale; }; @@ -130,12 +127,13 @@ static int cm32181_reg_init(struct cm32181_chip *cm32181) /* Default Values */ cm32181->conf_regs[CM32181_REG_ADDR_CMD] = CM32181_CMD_ALS_IT_DEFAULT | CM32181_CMD_ALS_SM_DEFAULT; + cm32181->init_regs_bitmap = BIT(CM32181_REG_ADDR_CMD); cm32181->calibscale = CM32181_CALIBSCALE_DEFAULT; /* Initialize registers*/ - for (i = 0; i < CM32181_CONF_REG_NUM; i++) { - ret = i2c_smbus_write_word_data(client, cm32181_reg[i], - cm32181->conf_regs[i]); + for_each_set_bit(i, &cm32181->init_regs_bitmap, CM32181_CONF_REG_NUM) { + ret = i2c_smbus_write_word_data(client, i, + cm32181->conf_regs[i]); if (ret < 0) return ret; }