From patchwork Mon Dec 25 15:57:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: CAPDEVILLE Marc X-Patchwork-Id: 852833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z53fm54dQz9s0g for ; Tue, 26 Dec 2017 02:57:52 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752288AbdLYP5o (ORCPT ); Mon, 25 Dec 2017 10:57:44 -0500 Received: from smtp05.smtpout.orange.fr ([80.12.242.127]:42492 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752403AbdLYP5n (ORCPT ); Mon, 25 Dec 2017 10:57:43 -0500 Received: from azrael.lan ([90.14.74.106]) by mwinf5d28 with ME id qFxa1w00K2HbjxE03FxbPi; Mon, 25 Dec 2017 16:57:41 +0100 X-ME-Helo: azrael.lan X-ME-Date: Mon, 25 Dec 2017 16:57:41 +0100 X-ME-IP: 90.14.74.106 Received: (nullmailer pid 6383 invoked by uid 1000); Mon, 25 Dec 2017 15:57:31 -0000 From: Marc CAPDEVILLE To: Kevin Tsai Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Mika Westerberg , Wolfram Sang , linux-iio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc CAPDEVILLE Subject: [PATCH v6 1/4] i2c-core-acpi : Add i2c_acpi_set_connection Date: Mon, 25 Dec 2017 16:57:20 +0100 Message-Id: <20171225155723.6338-1-m.capdeville@no-log.org> X-Mailer: git-send-email 2.11.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add a methode to allow clients to change their connection address on same adapter. On ACPI enumerated device, when a device support smbus alert protocol, there are two acpi serial bus connection description. The order in which connection is given is not well defined and devices may be enumerated with the wrong address (the first one). So let the driver detect the unsupported address and request i2c acpi core to choose the second one at probing time. Signed-off-by: Marc CAPDEVILLE --- drivers/i2c/i2c-core-acpi.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/i2c.h | 10 +++++++++ 2 files changed, 60 insertions(+) diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c index a9126b3cda61..47bc0da12055 100644 --- a/drivers/i2c/i2c-core-acpi.c +++ b/drivers/i2c/i2c-core-acpi.c @@ -421,6 +421,56 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, } EXPORT_SYMBOL_GPL(i2c_acpi_new_device); +int i2c_acpi_set_connection(struct i2c_client *client, int index) +{ + struct i2c_acpi_lookup lookup; + struct i2c_adapter *adapter; + struct acpi_device *adev; + struct i2c_board_info info; + LIST_HEAD(resource_list); + int ret; + + if (!client) + return -ENODEV; + + adev = ACPI_COMPANION(&client->dev); + if (!adev) + return -ENODEV; + + memset(&info, 0, sizeof(info)); + memset(&lookup, 0, sizeof(lookup)); + lookup.info = &info; + lookup.device_handle = acpi_device_handle(adev); + lookup.index = index; + + ret = acpi_dev_get_resources(adev, &resource_list, + i2c_acpi_fill_info, &lookup); + acpi_dev_free_resource_list(&resource_list); + + adapter = i2c_acpi_find_adapter_by_handle(lookup.adapter_handle); + + if (ret < 0 || !info.addr) + return -EINVAL; + + /* Only accept connection on same adapter */ + if (adapter != client->adapter) + return -EINVAL; + + ret = i2c_check_addr_validity(info.addr, info.flags); + if (ret) { + dev_err(&client->dev, "Invalid %d-bit I2C address 0x%02hx\n", + info.flags & I2C_CLIENT_TEN ? 10 : 7, info.addr); + return -EINVAL; + } + + /* Set new address and flags */ + client->addr = info.addr; + client->flags = info.flags; + + return 0; +} +EXPORT_SYMBOL_GPL(i2c_acpi_set_connection); + #ifdef CONFIG_ACPI_I2C_OPREGION static int acpi_gsb_i2c_read_bytes(struct i2c_client *client, u8 cmd, u8 *data, u8 data_len) diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 0f774406fad0..618b453901da 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -595,6 +595,8 @@ struct i2c_adapter { const struct i2c_adapter_quirks *quirks; struct irq_domain *host_notify_domain; + + struct i2c_client *smbus_ara; /* ARA for SMBUS if present */ }; #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) @@ -839,16 +841,24 @@ static inline const struct of_device_id u32 i2c_acpi_find_bus_speed(struct device *dev); struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, struct i2c_board_info *info); + +int i2c_acpi_set_connection(struct i2c_client *client, int index); #else static inline u32 i2c_acpi_find_bus_speed(struct device *dev) { return 0; } + static inline struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, struct i2c_board_info *info) { return NULL; } + +static inline int i2c_acpi_set_connection(struct i2c_client *client, int index) +{ + return -EINVAL; +} #endif /* CONFIG_ACPI */ #endif /* _LINUX_I2C_H */ From patchwork Mon Dec 25 15:57:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: CAPDEVILLE Marc X-Patchwork-Id: 852834 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z53gJ2wt9z9s74 for ; Tue, 26 Dec 2017 02:58:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752931AbdLYP5z (ORCPT ); Mon, 25 Dec 2017 10:57:55 -0500 Received: from smtp05.smtpout.orange.fr ([80.12.242.127]:54525 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752547AbdLYP5q (ORCPT ); Mon, 25 Dec 2017 10:57:46 -0500 Received: from azrael.lan ([90.14.74.106]) by mwinf5d28 with ME id qFxi1w0082HbjxE03FxiRH; Mon, 25 Dec 2017 16:57:44 +0100 X-ME-Helo: azrael.lan X-ME-Date: Mon, 25 Dec 2017 16:57:44 +0100 X-ME-IP: 90.14.74.106 Received: (nullmailer pid 6386 invoked by uid 1000); Mon, 25 Dec 2017 15:57:39 -0000 From: Marc CAPDEVILLE To: Kevin Tsai Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Mika Westerberg , Wolfram Sang , linux-iio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc CAPDEVILLE Subject: [PATCH v6 2/4] i2c-smbus : Add client discovered ARA support Date: Mon, 25 Dec 2017 16:57:21 +0100 Message-Id: <20171225155723.6338-2-m.capdeville@no-log.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171225155723.6338-1-m.capdeville@no-log.org> References: <20171225155723.6338-1-m.capdeville@no-log.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This is from rfc by Alan Cox : https://patchwork.ozlabs.org/patch/381773 The idea is as follows (extract from above rfc) : - If an adapter knows about its ARA and smbus alerts then the adapter creates its own interrupt handler as before - If a client knows it needs smbus alerts it calls i2c_require_smbus_alert(). This ensures that there is an ARA handler registered and tells the client whether the adapter is handling it anyway or not. - When the client learns that an ARA event has occurred it calls i2c_smbus_alert_event() which uses the existing ARA mechanism to kick things off. Suggested-by: Alan Cox Signed-off-by: Marc CAPDEVILLE --- drivers/i2c/i2c-smbus.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/i2c-smbus.h | 15 +++++++++ 2 files changed, 98 insertions(+) diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c index 5a1dd7f13bac..e97fbafd10ef 100644 --- a/drivers/i2c/i2c-smbus.c +++ b/drivers/i2c/i2c-smbus.c @@ -161,6 +161,9 @@ static int smbalert_probe(struct i2c_client *ara, } i2c_set_clientdata(ara, alert); + + ara->adapter->smbus_ara = ara; + dev_info(&adapter->dev, "supports SMBALERT#\n"); return 0; @@ -172,6 +175,9 @@ static int smbalert_remove(struct i2c_client *ara) struct i2c_smbus_alert *alert = i2c_get_clientdata(ara); cancel_work_sync(&alert->alert); + + ara->adapter->smbus_ara = NULL; + return 0; } @@ -210,6 +216,83 @@ int i2c_handle_smbus_alert(struct i2c_client *ara) } EXPORT_SYMBOL_GPL(i2c_handle_smbus_alert); +/* + * i2c_require_smbus_alert - Client discovered SMBus alert + * @c: client requiring ARA + * + * When a client needs an ARA it calls this method. If the bus adapter + * supports ARA and already knows how to do so then it will already have + * configured for ARA and this is a no-op. If not then we set up an ARA + * on the adapter. + * + * We *cannot* simply register a new IRQ handler for this because we might + * have multiple GPIO interrupts to devices all of which trigger an ARA. + * + * Return: + * 0 if ara support already registered + * 1 if call register a new smbus_alert device + * <0 on error + */ +int i2c_require_smbus_alert(struct i2c_client *client) +{ + struct i2c_adapter *adapter = client->adapter; + struct i2c_smbus_alert_setup setup; + struct i2c_client *ara; + + /* ARA is already known and handled by the adapter (ideal case) + * or another client has specified ARA is needed + */ + if (adapter->smbus_ara) + return 0; + + /* Client driven, do not set up a new IRQ handler */ + setup.irq = 0; + + ara = i2c_setup_smbus_alert(adapter, &setup); + if (!ara) + return -ENODEV; + + return 1; +} +EXPORT_SYMBOL_GPL(i2c_require_smbus_alert); + +/* + * i2c_smbus_alert_event + * @client: the client who known of a probable ara event + * Context: can't sleep + * + * Helper function to be called from an I2C device driver's interrupt + * handler. It will schedule the alert work, in turn calling the + * corresponding I2C device driver's alert function. + * + * It is assumed that client is an i2c client who previously call + * i2c_require_smbus_alert(). + */ +int i2c_smbus_alert_event(struct i2c_client *client) +{ + struct i2c_adapter *adapter; + struct i2c_client *ara; + struct i2c_smbus_alert *alert; + + if (!client) + return -EINVAL; + + adapter = client->adapter; + if (!adapter) + return -EINVAL; + + ara = adapter->smbus_ara; + if (!ara) + return -EINVAL; + + alert = i2c_get_clientdata(ara); + if (!alert) + return -EINVAL; + + return schedule_work(&alert->alert); +} +EXPORT_SYMBOL_GPL(i2c_smbus_alert_event); + module_i2c_driver(smbalert_driver); MODULE_AUTHOR("Jean Delvare "); diff --git a/include/linux/i2c-smbus.h b/include/linux/i2c-smbus.h index fb0e040b1abb..49f362fa6ac5 100644 --- a/include/linux/i2c-smbus.h +++ b/include/linux/i2c-smbus.h @@ -58,4 +58,19 @@ static inline int of_i2c_setup_smbus_alert(struct i2c_adapter *adap) } #endif +#if IS_ENABLED(CONFIG_I2C_SMBUS) +int i2c_require_smbus_alert(struct i2c_client *client); +int i2c_smbus_alert_event(struct i2c_client *client); +#else +static inline int i2c_require_smbus_alert(struct i2c_client *client) +{ + return NULL; +} + +static inline int i2c_smbus_alert_event(struct i2c_client *client) +{ + return NULL; +} +#endif + #endif /* _LINUX_I2C_SMBUS_H */ From patchwork Mon Dec 25 15:57:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: CAPDEVILLE Marc X-Patchwork-Id: 852836 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z53gj24gGz9s0g for ; Tue, 26 Dec 2017 02:58:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753135AbdLYP60 (ORCPT ); Mon, 25 Dec 2017 10:58:26 -0500 Received: from smtp05.smtpout.orange.fr ([80.12.242.127]:37140 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752560AbdLYP5x (ORCPT ); Mon, 25 Dec 2017 10:57:53 -0500 Received: from azrael.lan ([90.14.74.106]) by mwinf5d28 with ME id qFxo1w0092HbjxE03FxoS6; Mon, 25 Dec 2017 16:57:51 +0100 X-ME-Helo: azrael.lan X-ME-Date: Mon, 25 Dec 2017 16:57:51 +0100 X-ME-IP: 90.14.74.106 Received: (nullmailer pid 6389 invoked by uid 1000); Mon, 25 Dec 2017 15:57:48 -0000 From: Marc CAPDEVILLE To: Kevin Tsai Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Mika Westerberg , Wolfram Sang , linux-iio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc CAPDEVILLE Subject: [PATCH v6 3/4] iio : Add cm3218 smbus ara and acpi support Date: Mon, 25 Dec 2017 16:57:22 +0100 Message-Id: <20171225155723.6338-3-m.capdeville@no-log.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171225155723.6338-1-m.capdeville@no-log.org> References: <20171225155723.6338-1-m.capdeville@no-log.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org On asus T100, Capella cm3218 chip is implemented as ambiant light sensor. This chip expose an smbus ARA protocol device on standard address 0x0c. The chip is not functional before all alerts are acknowledged. On asus T100, this device is enumerated on ACPI bus and the description give two I2C connection. The first is the connection to the ARA device and the second gives the real address of the device. So, on device probe,If the i2c address is the ARA address and the device is enumerated via acpi, we change address of the device for the one in the second acpi serial bus connection. This free the ara address so we can register with the smbus_alert driver. If an interrupt resource is given, and a smbus_alert device was found on the adapter, we request a treaded interrupt to call i2c_smbus_alert_event to handle the alert. In somme case, the treaded interrupt is not schedule before the driver try to initialize chip registers. So if first registers access fail, we call i2c_smbus_alert_event() to acknowledge initial alert, then retry register access. Signed-off-by: Marc CAPDEVILLE --- drivers/iio/light/cm32181.c | 120 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 5 deletions(-) diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c index aebf7dd071af..96c08755e6e3 100644 --- a/drivers/iio/light/cm32181.c +++ b/drivers/iio/light/cm32181.c @@ -18,6 +18,9 @@ #include #include #include +#include +#include +#include /* Registers Address */ #define CM32181_REG_ADDR_CMD 0x00 @@ -47,6 +50,11 @@ #define CM32181_CALIBSCALE_RESOLUTION 1000 #define MLUX_PER_LUX 1000 +#define CM32181_ID 0x81 +#define CM3218_ID 0x18 + +#define SMBUS_ARA_ADDR 0x0c + static const u8 cm32181_reg[CM32181_CONF_REG_NUM] = { CM32181_REG_ADDR_CMD, }; @@ -57,6 +65,7 @@ static const int als_it_value[] = {25000, 50000, 100000, 200000, 400000, struct cm32181_chip { struct i2c_client *client; + int chip_id; struct mutex lock; u16 conf_regs[CM32181_CONF_REG_NUM]; int calibscale; @@ -77,11 +86,22 @@ static int cm32181_reg_init(struct cm32181_chip *cm32181) s32 ret; ret = i2c_smbus_read_word_data(client, CM32181_REG_ADDR_ID); - if (ret < 0) - return ret; + if (ret < 0) { + if (cm32181->chip_id == CM3218_ID) { + /* + * On cm3218, smbus alert trigger after probing, + * so poll for first alert here, then retry. + */ + i2c_smbus_alert_event(client); + ret = i2c_smbus_read_word_data(client, + CM32181_REG_ADDR_ID); + } else { + return ret; + } + } /* check device ID */ - if ((ret & 0xFF) != 0x81) + if ((ret & 0xFF) != cm32181->chip_id) return -ENODEV; /* Default Values */ @@ -297,12 +317,36 @@ static const struct iio_info cm32181_info = { .attrs = &cm32181_attribute_group, }; +static void cm3218_alert(struct i2c_client *client, + enum i2c_alert_protocol type, + unsigned int data) +{ + /* + * nothing to do for now. + * This is just here to acknownledge the cm3218 alert. + */ +} + +static irqreturn_t cm32181_irq(int irq, void *d) +{ + struct cm32181_chip *cm32181 = d; + + if (cm32181->chip_id == CM3218_ID) { + /* This is cm3218 chip irq, so handle the smbus alert */ + i2c_smbus_alert_event(cm32181->client); + } + + return IRQ_HANDLED; +} + static int cm32181_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct cm32181_chip *cm32181; struct iio_dev *indio_dev; int ret; + const struct of_device_id *of_id; + const struct acpi_device_id *acpi_id; indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*cm32181)); if (!indio_dev) { @@ -322,6 +366,61 @@ static int cm32181_probe(struct i2c_client *client, indio_dev->name = id->name; indio_dev->modes = INDIO_DIRECT_MODE; + /* Lookup for chip ID from platform, acpi or of device table */ + if (id) { + cm32181->chip_id = id->driver_data; + } else if (ACPI_COMPANION(&client->dev)) { + acpi_id = acpi_match_device(client->dev.driver->acpi_match_table, + &client->dev); + if (!acpi_id) + return -ENODEV; + + cm32181->chip_id = (kernel_ulong_t)acpi_id->driver_data; + } else if (client->dev.of_node) { + of_id = of_match_device(client->dev.driver->of_match_table, + &client->dev); + if (!of_id) + return -ENODEV; + + cm32181->chip_id = (kernel_ulong_t)of_id->data; + } else { + return -ENODEV; + } + + if (cm32181->chip_id == CM3218_ID) { + if (ACPI_COMPANION(&client->dev) && + client->addr == SMBUS_ARA_ADDR) { + /* + * In case this device as been enumerated by acpi + * with the reserved smbus ARA address (first acpi + * connection), request change of address to the second + * connection. + */ + ret = i2c_acpi_set_connection(client, 1); + if (ret) + return ret; + } + + /* cm3218 chip require an ara device on his adapter */ + ret = i2c_require_smbus_alert(client); + if (ret < 0) + return ret; + + /* + * If irq is given, request a threaded irq handler to manage + * smbus alert. + */ + if (client->irq > 0) { + ret = devm_request_threaded_irq(&client->dev, + client->irq, + NULL, cm32181_irq, + IRQF_ONESHOT, + "cm32181", cm32181); + if (ret) + return ret; + } + } + ret = cm32181_reg_init(cm32181); if (ret) { dev_err(&client->dev, @@ -342,25 +441,36 @@ static int cm32181_probe(struct i2c_client *client, } static const struct i2c_device_id cm32181_id[] = { - { "cm32181", 0 }, + { "cm32181", CM32181_ID }, + { "cm3218", CM3218_ID }, { } }; MODULE_DEVICE_TABLE(i2c, cm32181_id); static const struct of_device_id cm32181_of_match[] = { - { .compatible = "capella,cm32181" }, + { .compatible = "capella,cm32181", (void *)CM32181_ID }, + { .compatible = "capella,cm3218", (void *)CM3218_ID }, { } }; MODULE_DEVICE_TABLE(of, cm32181_of_match); +static const struct acpi_device_id cm32181_acpi_match[] = { + { "CPLM3218", CM3218_ID }, + { } +}; + +MODULE_DEVICE_TABLE(acpi, cm32181_acpi_match); + static struct i2c_driver cm32181_driver = { .driver = { .name = "cm32181", .of_match_table = of_match_ptr(cm32181_of_match), + .acpi_match_table = ACPI_PTR(cm32181_acpi_match), }, .id_table = cm32181_id, .probe = cm32181_probe, + .alert = cm3218_alert, }; module_i2c_driver(cm32181_driver); From patchwork Mon Dec 25 15:57:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: CAPDEVILLE Marc X-Patchwork-Id: 852835 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z53gK748Lz9s7B for ; Tue, 26 Dec 2017 02:58:21 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753115AbdLYP6Q (ORCPT ); Mon, 25 Dec 2017 10:58:16 -0500 Received: from smtp05.smtpout.orange.fr ([80.12.242.127]:29896 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752718AbdLYP56 (ORCPT ); Mon, 25 Dec 2017 10:57:58 -0500 Received: from azrael.lan ([90.14.74.106]) by mwinf5d28 with ME id qFxu1w00E2HbjxE03FxvTV; Mon, 25 Dec 2017 16:57:56 +0100 X-ME-Helo: azrael.lan X-ME-Date: Mon, 25 Dec 2017 16:57:56 +0100 X-ME-IP: 90.14.74.106 Received: (nullmailer pid 6392 invoked by uid 1000); Mon, 25 Dec 2017 15:57:54 -0000 From: Marc CAPDEVILLE To: Kevin Tsai Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Mika Westerberg , Wolfram Sang , linux-iio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc CAPDEVILLE Subject: [PATCH v6 4/4] iio : cm32181 : cosmetic cleanup Date: Mon, 25 Dec 2017 16:57:23 +0100 Message-Id: <20171225155723.6338-4-m.capdeville@no-log.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171225155723.6338-1-m.capdeville@no-log.org> References: <20171225155723.6338-1-m.capdeville@no-log.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Somme cosmetic cleanup suggested by Peter Meerwald-Stadler. Macro name : MLUX_PER_LUX => CM32181_MLUX_PER_LUX Constante name : als_it_bits => cm32181_als_it_bits als_it_value => cm32181_als_it_value Comment : Registers Address => Register Addresses Suggested-by: Peter Meerwald-Stadler Signed-off-by: Marc CAPDEVILLE Acked-by: Jonathan Cameron --- drivers/iio/light/cm32181.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c index 96c08755e6e3..3e6b244d5cd1 100644 --- a/drivers/iio/light/cm32181.c +++ b/drivers/iio/light/cm32181.c @@ -22,7 +22,7 @@ #include #include -/* Registers Address */ +/* Register Addresses */ #define CM32181_REG_ADDR_CMD 0x00 #define CM32181_REG_ADDR_ALS 0x04 #define CM32181_REG_ADDR_STATUS 0x06 @@ -48,7 +48,7 @@ #define CM32181_MLUX_PER_BIT_BASE_IT 800000 /* Based on IT=800ms */ #define CM32181_CALIBSCALE_DEFAULT 1000 #define CM32181_CALIBSCALE_RESOLUTION 1000 -#define MLUX_PER_LUX 1000 +#define CM32181_MLUX_PER_LUX 1000 #define CM32181_ID 0x81 #define CM3218_ID 0x18 @@ -59,8 +59,8 @@ static const u8 cm32181_reg[CM32181_CONF_REG_NUM] = { CM32181_REG_ADDR_CMD, }; -static const int als_it_bits[] = {12, 8, 0, 1, 2, 3}; -static const int als_it_value[] = {25000, 50000, 100000, 200000, 400000, +static const int cm32181_als_it_bits[] = {12, 8, 0, 1, 2, 3}; +static const int cm32181_als_it_value[] = {25000, 50000, 100000, 200000, 400000, 800000}; struct cm32181_chip { @@ -137,9 +137,9 @@ static int cm32181_read_als_it(struct cm32181_chip *cm32181, int *val2) als_it = cm32181->conf_regs[CM32181_REG_ADDR_CMD]; als_it &= CM32181_CMD_ALS_IT_MASK; als_it >>= CM32181_CMD_ALS_IT_SHIFT; - for (i = 0; i < ARRAY_SIZE(als_it_bits); i++) { - if (als_it == als_it_bits[i]) { - *val2 = als_it_value[i]; + for (i = 0; i < ARRAY_SIZE(cm32181_als_it_bits); i++) { + if (als_it == cm32181_als_it_bits[i]) { + *val2 = cm32181_als_it_value[i]; return IIO_VAL_INT_PLUS_MICRO; } } @@ -162,14 +162,14 @@ static int cm32181_write_als_it(struct cm32181_chip *cm32181, int val) u16 als_it; int ret, i, n; - n = ARRAY_SIZE(als_it_value); + n = ARRAY_SIZE(cm32181_als_it_value); for (i = 0; i < n; i++) - if (val <= als_it_value[i]) + if (val <= cm32181_als_it_value[i]) break; if (i >= n) i = n - 1; - als_it = als_it_bits[i]; + als_it = cm32181_als_it_bits[i]; als_it <<= CM32181_CMD_ALS_IT_SHIFT; mutex_lock(&cm32181->lock); @@ -215,7 +215,7 @@ static int cm32181_get_lux(struct cm32181_chip *cm32181) lux *= ret; lux *= cm32181->calibscale; lux /= CM32181_CALIBSCALE_RESOLUTION; - lux /= MLUX_PER_LUX; + lux /= CM32181_MLUX_PER_LUX; if (lux > 0xFFFF) lux = 0xFFFF; @@ -283,9 +283,9 @@ static ssize_t cm32181_get_it_available(struct device *dev, { int i, n, len; - n = ARRAY_SIZE(als_it_value); + n = ARRAY_SIZE(cm32181_als_it_value); for (i = 0, len = 0; i < n; i++) - len += sprintf(buf + len, "0.%06u ", als_it_value[i]); + len += sprintf(buf + len, "0.%06u ", cm32181_als_it_value[i]); return len + sprintf(buf + len, "\n"); }