From mboxrd@z Thu Jan 1 00:00:00 1970 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=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 5F8EAC83001 for ; Tue, 28 Apr 2020 17:30:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FC022085B for ; Tue, 28 Apr 2020 17:30:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Iybj2KZN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728630AbgD1RaC (ORCPT ); Tue, 28 Apr 2020 13:30:02 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:48358 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728619AbgD1R37 (ORCPT ); Tue, 28 Apr 2020 13:29:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588094998; 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=MokJhYQfZkwA5aWDgmtqE721QUM4Xa11rqTt+C4uNts=; b=Iybj2KZN2WE+WjqzS74uNY5E6RBDHHWNrmbEt730Lkfbiz7lGYBsCHMTdiOU+pIYRg3ZmT KpNUaguj8FWxigyDrxY2jgPa02esgnRS335biz7gc1BKewZE7Xa6GDfbTHo2/qbBlT16+Z F5BX+xJo5/aYHGUtEYEk/4UPGwu2k44= 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-324-xCRCshAXMMK8ETyuxZ_Xbw-1; Tue, 28 Apr 2020 13:29:54 -0400 X-MC-Unique: xCRCshAXMMK8ETyuxZ_Xbw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F17F805725; Tue, 28 Apr 2020 17:29:52 +0000 (UTC) Received: from x1.localdomain.com (ovpn-114-62.ams2.redhat.com [10.36.114.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F6B25C220; Tue, 28 Apr 2020 17:29:48 +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 v3 08/11] iio: light: cm32181: Use units of 1/100000th for calibscale and lux_per_bit Date: Tue, 28 Apr 2020 19:29:20 +0200 Message-Id: <20200428172923.567806-8-hdegoede@redhat.com> In-Reply-To: <20200428172923.567806-1-hdegoede@redhat.com> References: <20200428172923.567806-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use units of 1/100000th for calibscale and lux_per_bit. The similar cm3232 driver already uses 1/100000th as unit for calibscale. This allows for higher-accuracy and makes it easier to add support for getting device-specific calibscale and lux_per_bit values from a device's ACPI tables, as the values in the ACPI tables also use 1/100000th units. This units change means that our intermediate values in cm32181_get_lux() may get quite big, change the type of the lux variable to a u64 to deal with this. Reviewed-by: Andy Shevchenko Signed-off-by: Hans de Goede --- drivers/iio/light/cm32181.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c index bcea669d20cb..1ad7d4582d1c 100644 --- a/drivers/iio/light/cm32181.c +++ b/drivers/iio/light/cm32181.c @@ -45,11 +45,11 @@ #define CM32181_CMD_ALS_SM_MASK (0x03 << CM32181_CMD_ALS_SM_SHIFT) #define CM32181_CMD_ALS_SM_DEFAULT (0x01 << CM32181_CMD_ALS_SM_SHIFT) =20 -#define CM32181_MLUX_PER_BIT 5 /* ALS_SM=3D01 IT=3D800ms */ -#define CM32181_MLUX_PER_BIT_BASE_IT 800000 /* Based on IT=3D800ms */ -#define CM32181_CALIBSCALE_DEFAULT 1000 -#define CM32181_CALIBSCALE_RESOLUTION 1000 -#define MLUX_PER_LUX 1000 +#define CM32181_LUX_PER_BIT 500 /* ALS_SM=3D01 IT=3D800ms */ +#define CM32181_LUX_PER_BIT_RESOLUTION 100000 +#define CM32181_LUX_PER_BIT_BASE_IT 800000 /* Based on IT=3D800ms */ +#define CM32181_CALIBSCALE_DEFAULT 100000 +#define CM32181_CALIBSCALE_RESOLUTION 100000 =20 #define SMBUS_ALERT_RESPONSE_ADDRESS 0x0c =20 @@ -204,15 +204,15 @@ static int cm32181_get_lux(struct cm32181_chip *cm3= 2181) struct i2c_client *client =3D cm32181->client; int ret; int als_it; - unsigned long lux; + u64 lux; =20 ret =3D cm32181_read_als_it(cm32181, &als_it); if (ret < 0) return -EINVAL; =20 - lux =3D CM32181_MLUX_PER_BIT; - lux *=3D CM32181_MLUX_PER_BIT_BASE_IT; - lux /=3D als_it; + lux =3D CM32181_LUX_PER_BIT; + lux *=3D CM32181_LUX_PER_BIT_BASE_IT; + lux =3D div_u64(lux, als_it); =20 ret =3D i2c_smbus_read_word_data(client, CM32181_REG_ADDR_ALS); if (ret < 0) @@ -220,8 +220,8 @@ static int cm32181_get_lux(struct cm32181_chip *cm321= 81) =20 lux *=3D ret; lux *=3D cm32181->calibscale; - lux /=3D CM32181_CALIBSCALE_RESOLUTION; - lux /=3D MLUX_PER_LUX; + lux =3D div_u64(lux, CM32181_CALIBSCALE_RESOLUTION); + lux =3D div_u64(lux, CM32181_LUX_PER_BIT_RESOLUTION); =20 if (lux > 0xFFFF) lux =3D 0xFFFF; --=20 2.26.0