cm32181.c (f50f98310e51b3712a4e544c75615e89c8233125) | cm32181.c (63b1be78774f8c3bdb9efd862ba7dfe8e2c056ff) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * Copyright (C) 2013 Capella Microsystems Inc. 4 * Author: Kevin Tsai <ktsai@capellamicro.com> 5 */ 6 7#include <linux/delay.h> 8#include <linux/err.h> --- 56 unchanged lines hidden (view full) --- 65}; 66 67struct cm32181_chip { 68 struct i2c_client *client; 69 struct mutex lock; 70 u16 conf_regs[CM32181_CONF_REG_NUM]; 71 unsigned long init_regs_bitmap; 72 int calibscale; | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * Copyright (C) 2013 Capella Microsystems Inc. 4 * Author: Kevin Tsai <ktsai@capellamicro.com> 5 */ 6 7#include <linux/delay.h> 8#include <linux/err.h> --- 56 unchanged lines hidden (view full) --- 65}; 66 67struct cm32181_chip { 68 struct i2c_client *client; 69 struct mutex lock; 70 u16 conf_regs[CM32181_CONF_REG_NUM]; 71 unsigned long init_regs_bitmap; 72 int calibscale; |
73 int lux_per_bit; 74 int lux_per_bit_base_it; |
|
73 int num_als_it; 74 const int *als_it_bits; 75 const int *als_it_values; 76}; 77 78/** 79 * cm32181_reg_init() - Initialize CM32181 registers 80 * @cm32181: pointer of struct cm32181. --- 29 unchanged lines hidden (view full) --- 110 return -ENODEV; 111 } 112 113 /* Default Values */ 114 cm32181->conf_regs[CM32181_REG_ADDR_CMD] = 115 CM32181_CMD_ALS_IT_DEFAULT | CM32181_CMD_ALS_SM_DEFAULT; 116 cm32181->init_regs_bitmap = BIT(CM32181_REG_ADDR_CMD); 117 cm32181->calibscale = CM32181_CALIBSCALE_DEFAULT; | 75 int num_als_it; 76 const int *als_it_bits; 77 const int *als_it_values; 78}; 79 80/** 81 * cm32181_reg_init() - Initialize CM32181 registers 82 * @cm32181: pointer of struct cm32181. --- 29 unchanged lines hidden (view full) --- 112 return -ENODEV; 113 } 114 115 /* Default Values */ 116 cm32181->conf_regs[CM32181_REG_ADDR_CMD] = 117 CM32181_CMD_ALS_IT_DEFAULT | CM32181_CMD_ALS_SM_DEFAULT; 118 cm32181->init_regs_bitmap = BIT(CM32181_REG_ADDR_CMD); 119 cm32181->calibscale = CM32181_CALIBSCALE_DEFAULT; |
120 cm32181->lux_per_bit = CM32181_LUX_PER_BIT; 121 cm32181->lux_per_bit_base_it = CM32181_LUX_PER_BIT_BASE_IT; |
|
118 119 /* Initialize registers*/ 120 for_each_set_bit(i, &cm32181->init_regs_bitmap, CM32181_CONF_REG_NUM) { 121 ret = i2c_smbus_write_word_data(client, i, 122 cm32181->conf_regs[i]); 123 if (ret < 0) 124 return ret; 125 } --- 80 unchanged lines hidden (view full) --- 206 int ret; 207 int als_it; 208 u64 lux; 209 210 ret = cm32181_read_als_it(cm32181, &als_it); 211 if (ret < 0) 212 return -EINVAL; 213 | 122 123 /* Initialize registers*/ 124 for_each_set_bit(i, &cm32181->init_regs_bitmap, CM32181_CONF_REG_NUM) { 125 ret = i2c_smbus_write_word_data(client, i, 126 cm32181->conf_regs[i]); 127 if (ret < 0) 128 return ret; 129 } --- 80 unchanged lines hidden (view full) --- 210 int ret; 211 int als_it; 212 u64 lux; 213 214 ret = cm32181_read_als_it(cm32181, &als_it); 215 if (ret < 0) 216 return -EINVAL; 217 |
214 lux = CM32181_LUX_PER_BIT; 215 lux *= CM32181_LUX_PER_BIT_BASE_IT; | 218 lux = cm32181->lux_per_bit; 219 lux *= cm32181->lux_per_bit_base_it; |
216 lux = div_u64(lux, als_it); 217 218 ret = i2c_smbus_read_word_data(client, CM32181_REG_ADDR_ALS); 219 if (ret < 0) 220 return ret; 221 222 lux *= ret; 223 lux *= cm32181->calibscale; --- 190 unchanged lines hidden --- | 220 lux = div_u64(lux, als_it); 221 222 ret = i2c_smbus_read_word_data(client, CM32181_REG_ADDR_ALS); 223 if (ret < 0) 224 return ret; 225 226 lux *= ret; 227 lux *= cm32181->calibscale; --- 190 unchanged lines hidden --- |