Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755819AbbEVAcC (ORCPT ); Thu, 21 May 2015 20:32:02 -0400 Received: from smtp107.biz.mail.bf1.yahoo.com ([98.139.244.55]:33447 "EHLO smtp107.biz.mail.bf1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753988AbbEVAb6 (ORCPT ); Thu, 21 May 2015 20:31:58 -0400 X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: jIoxBnsVM1nl7tMkR1tBAvb92wWsbFGDpvdYyb7AwhtRV4K im1xFsMb8wIuUFULe_errTbHHhXzmf5WctuuPTO0ETrXCQIqMSK0EGvbPWP3 MoYne3vc.Jvt9zXd7YcghE2m2Np7VUNDh5q8lQwbY4mj.UtC8nGBRvEo9oZx 6eEV2MfkAnM2t66lUsHxoFs9r5Eg_u9KRlJy03Ws3vDnHJUbpsAlV8Y4Xfk_ h5O69bg9SC.F9yRNm5uR07F2NaR93GWmrd1j8QALDzlVViCGQ6DCOq64_qB8 7sUC2RBYEBQe2Iuv2Wb.CdMqHDrKbUL7W9sEyKmS9z_6axK5CmncH600878c 64KzJ3Hr0DteD9EtflJ1T4D1BumPS4_tOYKgXvUH2xqBwLQvOWJ4eEgFx7cN 9PHbl65HA4cv9MtpShCheRobZZscLV5e3qxe1ct4vxKOS1DpWkCr.kdG9EnN nubCvJExSI1AJN5WNIBRexQW3U3tuDtQ5qg0NzEp1OkOG0CM1v3CJBdKWYfv qIENisxoYMtXgNaAenv5F X-Yahoo-SMTP: oqiDtsaswBDv2aVUlxVTYPpATqA- From: Kevin Tsai To: Kevin Tsai , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald , Andrew Morton , Greg KH , "David S. Miller" , Mauro Carvalho Chehab , Arnd Bergmann , Joe Perches , Jingoo Han , Daniel Baluta , Roberta Dobrescu , Kuppuswamy Sathyanarayanan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Subject: [PATCH 2/6] iio: light: Updated Vishay Capella cm32181 ambient light sensor driver. - Added cm32181_als_info structure. Date: Thu, 21 May 2015 17:30:41 -0700 Message-Id: <1432254645-5349-2-git-send-email-ktsai@capellamicro.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1432254645-5349-1-git-send-email-ktsai@capellamicro.com> References: <1432254645-5349-1-git-send-email-ktsai@capellamicro.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3606 Lines: 118 Signed-off-by: Kevin Tsai --- Added cm32181_als_info structure. drivers/iio/light/cm32181.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c index 0491d73..6b11145 100644 --- a/drivers/iio/light/cm32181.c +++ b/drivers/iio/light/cm32181.c @@ -48,6 +48,7 @@ #define CM32181_ALS_WL_DEFAULT 0x0000 /* Software parameters */ +#define CM32181_HW_ID 0x81 #define CM32181_MLUX_PER_BIT 5 /* ALS_SM=01 IT=800ms */ #define CM32181_MLUX_PER_BIT_BASE_IT 800000 /* Based on IT=800ms */ #define CM32181_CALIBSCALE_DEFAULT 1000 @@ -58,11 +59,31 @@ static const int als_it_bits[] = {12, 8, 0, 1, 2, 3}; static const int als_it_value[] = {25000, 50000, 100000, 200000, 400000, 800000}; +struct cm32181_als_info { + u8 hw_id; + u16 reg_cmd; + u16 reg_als_wh; + u16 reg_als_wl; + int calibscale; + int mlux_per_bit; + int mlux_per_bit_base_it; +}; + +static struct cm32181_als_info cm32181_als_info_default = { + .hw_id = CM32181_HW_ID, + .reg_cmd = CM32181_CMD_DEFAULT, + .reg_als_wh = CM32181_ALS_WH_DEFAULT, + .reg_als_wl = CM32181_ALS_WL_DEFAULT, + .calibscale = CM32181_CALIBSCALE_DEFAULT, + .mlux_per_bit = CM32181_MLUX_PER_BIT, + .mlux_per_bit_base_it = CM32181_MLUX_PER_BIT_BASE_IT, +}; + struct cm32181_chip { struct i2c_client *client; struct mutex lock; + struct cm32181_als_info *als_info; u16 conf_regs[CM32181_CONF_REG_NUM]; - int calibscale; }; /** @@ -76,22 +97,25 @@ struct cm32181_chip { static int cm32181_reg_init(struct cm32181_chip *chip) { struct i2c_client *client = chip->client; + struct cm32181_als_info *als_info; int i; s32 ret; + chip->als_info = &cm32181_als_info_default; + als_info = chip->als_info; + ret = i2c_smbus_read_word_data(client, CM32181_REG_ADDR_ID); if (ret < 0) return ret; /* check device ID */ - if ((ret & 0xFF) != 0x81) + if ((ret & 0xFF) != als_info->hw_id) return -ENODEV; /* Default Values */ - chip->conf_regs[CM32181_REG_ADDR_CMD] = CM32181_CMD_DEFAULT; - chip->conf_regs[CM32181_REG_ADDR_ALS_WH] = CM32181_ALS_WH_DEFAULT; - chip->conf_regs[CM32181_REG_ADDR_ALS_WL] = CM32181_ALS_WL_DEFAULT; - chip->calibscale = CM32181_CALIBSCALE_DEFAULT; + chip->conf_regs[CM32181_REG_ADDR_CMD] = als_info->reg_cmd; + chip->conf_regs[CM32181_REG_ADDR_ALS_WH] = als_info->reg_als_wh; + chip->conf_regs[CM32181_REG_ADDR_ALS_WL] = als_info->reg_als_wl; /* Initialize registers*/ for (i = 0; i < CM32181_CONF_REG_NUM; i++) { @@ -197,7 +221,7 @@ static int cm32181_get_lux(struct cm32181_chip *chip) return ret; lux *= ret; - lux *= chip->calibscale; + lux *= chip->als_info->calibscale; lux /= CM32181_CALIBSCALE_RESOLUTION; lux /= MLUX_PER_LUX; @@ -222,7 +246,7 @@ static int cm32181_read_raw(struct iio_dev *indio_dev, *val = ret; return IIO_VAL_INT; case IIO_CHAN_INFO_CALIBSCALE: - *val = chip->calibscale; + *val = chip->als_info->calibscale; return IIO_VAL_INT; case IIO_CHAN_INFO_INT_TIME: *val = 0; @@ -242,7 +266,7 @@ static int cm32181_write_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_CALIBSCALE: - chip->calibscale = val; + chip->als_info->calibscale = val; return val; case IIO_CHAN_INFO_INT_TIME: ret = cm32181_write_als_it(chip, val2); -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/