From patchwork Mon Apr 27 15:50:33 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: 11512893 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 CEC9215E6 for ; Mon, 27 Apr 2020 15:51:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B7B692064C for ; Mon, 27 Apr 2020 15:51:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="U/yocaQ0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728469AbgD0PvW (ORCPT ); Mon, 27 Apr 2020 11:51:22 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:33688 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728466AbgD0Pu4 (ORCPT ); Mon, 27 Apr 2020 11:50:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588002655; 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=uVbZSaI2POy6fJtwh+hojPBmfthgWVtJ9egPhBMBtdg=; b=U/yocaQ0bO2Z0XbQbSNMPvX53CAMu7f6coKGCf/KY5ByGvkjFmOJ0ixN4ApOE6XR0rKFJE dVE4KUzWKV/cL/0nhpiZiyqTI+yeHJy4q9zkNCZk/9HhtZqH1+R2eePvh+jWdd7pO3yG4J LJ4sruKkSTqjz+7N8Llly5f11aPFNqg= 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-395-F3ejC_FSN4yQldq6iUzilg-1; Mon, 27 Apr 2020 11:50:52 -0400 X-MC-Unique: F3ejC_FSN4yQldq6iUzilg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5538C835B40; Mon, 27 Apr 2020 15:50:50 +0000 (UTC) Received: from x1.localdomain.com (ovpn-114-38.ams2.redhat.com [10.36.114.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id C704660BEC; Mon, 27 Apr 2020 15:50:47 +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 v2 4/8] iio: light: cm32181: Change reg_init to use a bitmap of which registers to init Date: Mon, 27 Apr 2020 17:50:33 +0200 Message-Id: <20200427155037.218390-4-hdegoede@redhat.com> In-Reply-To: <20200427155037.218390-1-hdegoede@redhat.com> References: <20200427155037.218390-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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 4c26a4a8a070..194aa5a0ad08 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, -}; - /* CM3218 Family */ static const int cm3218_als_it_bits[] = { 0, 1, 2, 3 }; static const int cm3218_als_it_values[] = { 100000, 200000, 400000, 800000 }; @@ -71,6 +67,7 @@ struct cm32181_chip { struct i2c_client *client; struct mutex lock; u16 conf_regs[CM32181_CONF_REG_NUM]; + unsigned long init_regs_bitmap; int calibscale; int num_als_it; const int *als_it_bits; @@ -117,12 +114,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; }