Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1780214ybz; Sun, 26 Apr 2020 04:08:07 -0700 (PDT) X-Google-Smtp-Source: APiQypLWBdXsPUgNccJPeP7YDRZ9jwFCRnDEwl3x5cNY10OLQz/cR4+4Af8+WTKCc5h0P5EWyZIy X-Received: by 2002:a17:906:390a:: with SMTP id f10mr14678083eje.74.1587899287678; Sun, 26 Apr 2020 04:08:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587899287; cv=none; d=google.com; s=arc-20160816; b=BJPW3IXNLLNQGmM/KZG6wFstcCP7CAG3Cm0x4N0dnSZKIPGZAkyo9EC8Kbn/a1q9w5 Pr3SoQrAyhWiX5Xh+vSV36MYDdVgIBi8NrmIS2YuLS9n16ZRlz0rppRXNYjLjzcB4rFQ wYCpx8EqlvwmTtGA47UbeyyxU1SSfQffYd2xBfo1kJ6RIoBLgw2m9dlB8+X07KsHK4TS qV1MW/nupQZw6L0uOhZn5e3jsBKxTRzbpowNGDxza4o1cmzV2eaCywgSuR7fZAdVpmOw ClJt8aHkHLo1F5ji4ZFkD3Qh04FSGWpSuGWvXPbIK2zLXj0HE59j9UHVYGI3mjt++XmE L1YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LqJi1jdkBu28gQlf+yNbx1ibf6v89AoBY8YcRvOsu/g=; b=O5ZzlLI9tR/L/VVak+SC5tq1+bVzjhIjBf6dqmhlXBsc2Xe4Eg3jPV5rO5iXQ/+lch AshkHPlLS8nH4jd4H9yl3yzUAh+bde2+w1/HD7tKnn++3yRNCc+jR2zpi6UjFHhCx6yD 8op9+YwJT+VqvdbvXAVaW5BK9IjYgQ0imoD/vmpCkXaiYlMpGpRqePcWRViqlWiMRGnO tSsj1s7hK35o3FvjH5QovPBhIjNTeA5ruiKmiBPBRl/r77ZM3FVUFVDiyu2X4z9wbazr 5PjyRAXt63E8sr6fyXVh6/nn3DqA11eXv41NpzY8CJnfGumeba0ORGkW5y0HPkvPLqmf 45AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XFslh+nu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i7si6211296eja.355.2020.04.26.04.07.44; Sun, 26 Apr 2020 04:08:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XFslh+nu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726374AbgDZLDz (ORCPT + 99 others); Sun, 26 Apr 2020 07:03:55 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:59011 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726171AbgDZLDL (ORCPT ); Sun, 26 Apr 2020 07:03:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587898989; 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=LqJi1jdkBu28gQlf+yNbx1ibf6v89AoBY8YcRvOsu/g=; b=XFslh+nus/ls1/fWaMPb0Oxvw5N8ng5SlUxGf9VOPIh6WLeSgackXTXGops2bI2aJEeAtN lycbjGumf5PdmodtGcJiLyRObe0ktl22HuHIGN/IGyicIzHiUMMEjIFUHil9GYZl5EyL0v An5iutP9oi9zd36AhqZ5mqHjDnMn+8o= 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-501-pqup05g2OYaJJ6qe0sGN3Q-1; Sun, 26 Apr 2020 07:03:07 -0400 X-MC-Unique: pqup05g2OYaJJ6qe0sGN3Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A19A468; Sun, 26 Apr 2020 11:03:05 +0000 (UTC) Received: from x1.localdomain.com (ovpn-112-32.ams2.redhat.com [10.36.112.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0425D10013A1; Sun, 26 Apr 2020 11:03:02 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Len Brown , Darren Hart , Andy Shevchenko , Kevin Tsai , 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 Subject: [PATCH 2/8] iio: light: cm32181: Add support for the CM3218 Date: Sun, 26 Apr 2020 13:02:50 +0200 Message-Id: <20200426110256.218186-2-hdegoede@redhat.com> In-Reply-To: <20200426110256.218186-1-hdegoede@redhat.com> References: <20200426110256.218186-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for the CM3218 which is an older version of the CM32181. This is based on a newer version of cm32181.c, with a copyright of: * Copyright (C) 2014 Capella Microsystems Inc. * Author: Kevin Tsai * * This program is free software; you can redistribute it and/or modify i= t * under the terms of the GNU General Public License version 2, as publis= hed * by the Free Software Foundation. Which is floating around on the net in various places, but the changes from this newer version never made it upstream. This was tested on an Asus T100TA and an Asus T100CHI, which both come with the CM3218 variant of the light sensor. Signed-off-by: Hans de Goede --- drivers/iio/light/cm32181.c | 51 ++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c index ee386afe811e..fd371b36c7b3 100644 --- a/drivers/iio/light/cm32181.c +++ b/drivers/iio/light/cm32181.c @@ -55,15 +55,24 @@ static const u8 cm32181_reg[CM32181_CONF_REG_NUM] =3D= { CM32181_REG_ADDR_CMD, }; =20 -static const int als_it_bits[] =3D {12, 8, 0, 1, 2, 3}; -static const int als_it_value[] =3D {25000, 50000, 100000, 200000, 40000= 0, - 800000}; +/* CM3218 Family */ +static const int cm3218_als_it_bits[] =3D { 0, 1, 2, 3 }; +static const int cm3218_als_it_values[] =3D { 100000, 200000, 400000, 80= 0000 }; + +/* CM32181 Family */ +static const int cm32181_als_it_bits[] =3D { 12, 8, 0, 1, 2, 3 }; +static const int cm32181_als_it_values[] =3D { + 25000, 50000, 100000, 200000, 400000, 800000 +}; =20 struct cm32181_chip { struct i2c_client *client; struct mutex lock; u16 conf_regs[CM32181_CONF_REG_NUM]; int calibscale; + int num_als_it; + const int *als_it_bits; + const int *als_it_values; }; =20 /** @@ -85,8 +94,23 @@ static int cm32181_reg_init(struct cm32181_chip *cm321= 81) return ret; =20 /* check device ID */ - if ((ret & 0xFF) !=3D 0x81) + switch (ret & 0xFF) { + case 0x18: /* CM3218 */ + dev_info(&client->dev, "Detected CM3218\n"); + cm32181->num_als_it =3D ARRAY_SIZE(cm3218_als_it_bits); + cm32181->als_it_bits =3D cm3218_als_it_bits; + cm32181->als_it_values =3D cm3218_als_it_values; + break; + case 0x81: /* CM32181 */ + case 0x82: /* CM32182, fully compat. with CM32181 */ + dev_info(&client->dev, "Detected CM32181\n"); + cm32181->num_als_it =3D ARRAY_SIZE(cm32181_als_it_bits); + cm32181->als_it_bits =3D cm32181_als_it_bits; + cm32181->als_it_values =3D cm32181_als_it_values; + break; + default: return -ENODEV; + } =20 /* Default Values */ cm32181->conf_regs[CM32181_REG_ADDR_CMD] =3D @@ -121,9 +145,9 @@ static int cm32181_read_als_it(struct cm32181_chip *c= m32181, int *val2) als_it =3D cm32181->conf_regs[CM32181_REG_ADDR_CMD]; als_it &=3D CM32181_CMD_ALS_IT_MASK; als_it >>=3D CM32181_CMD_ALS_IT_SHIFT; - for (i =3D 0; i < ARRAY_SIZE(als_it_bits); i++) { - if (als_it =3D=3D als_it_bits[i]) { - *val2 =3D als_it_value[i]; + for (i =3D 0; i < cm32181->num_als_it; i++) { + if (als_it =3D=3D cm32181->als_it_bits[i]) { + *val2 =3D cm32181->als_it_values[i]; return IIO_VAL_INT_PLUS_MICRO; } } @@ -146,14 +170,14 @@ static int cm32181_write_als_it(struct cm32181_chip= *cm32181, int val) u16 als_it; int ret, i, n; =20 - n =3D ARRAY_SIZE(als_it_value); + n =3D cm32181->num_als_it; for (i =3D 0; i < n; i++) - if (val <=3D als_it_value[i]) + if (val <=3D cm32181->als_it_values[i]) break; if (i >=3D n) i =3D n - 1; =20 - als_it =3D als_it_bits[i]; + als_it =3D cm32181->als_it_bits[i]; als_it <<=3D CM32181_CMD_ALS_IT_SHIFT; =20 mutex_lock(&cm32181->lock); @@ -265,11 +289,12 @@ static int cm32181_write_raw(struct iio_dev *indio_= dev, static ssize_t cm32181_get_it_available(struct device *dev, struct device_attribute *attr, char *buf) { + struct cm32181_chip *cm32181 =3D iio_priv(dev_to_iio_dev(dev)); int i, n, len; =20 - n =3D ARRAY_SIZE(als_it_value); + n =3D cm32181->num_als_it; for (i =3D 0, len =3D 0; i < n; i++) - len +=3D sprintf(buf + len, "0.%06u ", als_it_value[i]); + len +=3D sprintf(buf + len, "0.%06u ", cm32181->als_it_values[i]); return len + sprintf(buf + len, "\n"); } =20 @@ -346,6 +371,7 @@ static int cm32181_probe(struct i2c_client *client, } =20 static const struct i2c_device_id cm32181_id[] =3D { + { "cm3218", 0 }, { "cm32181", 0 }, { } }; @@ -353,6 +379,7 @@ static const struct i2c_device_id cm32181_id[] =3D { MODULE_DEVICE_TABLE(i2c, cm32181_id); =20 static const struct of_device_id cm32181_of_match[] =3D { + { .compatible =3D "capella,cm3218" }, { .compatible =3D "capella,cm32181" }, { } }; --=20 2.26.0