Lines Matching +full:cpm +full:- +full:command

1 // SPDX-License-Identifier: GPL-2.0-only
58 /* CPM0 Index 0: device-id (3218 or 32181), 1: Unknown, 2: init_regs_bitmap */
95 * cm32181_acpi_get_cpm() - Get CPM object from ACPI
101 * Convert ACPI CPM table to array.
103 * Return: -ENODEV for fail. Otherwise is number of elements.
109 union acpi_object *cpm, *elem; in cm32181_acpi_get_cpm() local
116 return -ENODEV; in cm32181_acpi_get_cpm()
121 return -ENODEV; in cm32181_acpi_get_cpm()
124 cpm = buffer.pointer; in cm32181_acpi_get_cpm()
125 if (cpm->package.count > count) in cm32181_acpi_get_cpm()
127 obj_name, cpm->package.count, count); in cm32181_acpi_get_cpm()
129 count = min_t(int, cpm->package.count, count); in cm32181_acpi_get_cpm()
131 elem = &(cpm->package.elements[i]); in cm32181_acpi_get_cpm()
132 values[i] = elem->integer.value; in cm32181_acpi_get_cpm()
143 struct device *dev = cm32181->dev; in cm32181_acpi_parse_cpm_tables()
150 count -= CPM0_HEADER_SIZE; in cm32181_acpi_parse_cpm_tables()
152 cm32181->init_regs_bitmap = vals[CPM0_REGS_BITMAP]; in cm32181_acpi_parse_cpm_tables()
153 cm32181->init_regs_bitmap &= GENMASK(count - 1, 0); in cm32181_acpi_parse_cpm_tables()
154 for_each_set_bit(i, &cm32181->init_regs_bitmap, count) in cm32181_acpi_parse_cpm_tables()
155 cm32181->conf_regs[i] = vals[CPM0_HEADER_SIZE + i]; in cm32181_acpi_parse_cpm_tables()
161 cm32181->lux_per_bit = vals[CPM1_LUX_PER_BIT]; in cm32181_acpi_parse_cpm_tables()
167 cm32181->calibscale = vals[CPM1_CALIBSCALE]; in cm32181_acpi_parse_cpm_tables()
169 cm32181_read_als_it(cm32181, &cm32181->lux_per_bit_base_it); in cm32181_acpi_parse_cpm_tables()
178 * cm32181_reg_init() - Initialize CM32181 registers
187 struct i2c_client *client = cm32181->client; in cm32181_reg_init()
198 cm32181->num_als_it = ARRAY_SIZE(cm3218_als_it_bits); in cm32181_reg_init()
199 cm32181->als_it_bits = cm3218_als_it_bits; in cm32181_reg_init()
200 cm32181->als_it_values = cm3218_als_it_values; in cm32181_reg_init()
204 cm32181->num_als_it = ARRAY_SIZE(cm32181_als_it_bits); in cm32181_reg_init()
205 cm32181->als_it_bits = cm32181_als_it_bits; in cm32181_reg_init()
206 cm32181->als_it_values = cm32181_als_it_values; in cm32181_reg_init()
209 return -ENODEV; in cm32181_reg_init()
213 cm32181->conf_regs[CM32181_REG_ADDR_CMD] = in cm32181_reg_init()
215 cm32181->init_regs_bitmap = BIT(CM32181_REG_ADDR_CMD); in cm32181_reg_init()
216 cm32181->calibscale = CM32181_CALIBSCALE_DEFAULT; in cm32181_reg_init()
217 cm32181->lux_per_bit = CM32181_LUX_PER_BIT; in cm32181_reg_init()
218 cm32181->lux_per_bit_base_it = CM32181_LUX_PER_BIT_BASE_IT; in cm32181_reg_init()
220 if (ACPI_HANDLE(cm32181->dev)) in cm32181_reg_init()
224 for_each_set_bit(i, &cm32181->init_regs_bitmap, CM32181_CONF_REG_NUM) { in cm32181_reg_init()
226 cm32181->conf_regs[i]); in cm32181_reg_init()
235 * cm32181_read_als_it() - Get sensor integration time (ms)
241 * Return: IIO_VAL_INT_PLUS_MICRO for success, otherwise -EINVAL.
248 als_it = cm32181->conf_regs[CM32181_REG_ADDR_CMD]; in cm32181_read_als_it()
251 for (i = 0; i < cm32181->num_als_it; i++) { in cm32181_read_als_it()
252 if (als_it == cm32181->als_it_bits[i]) { in cm32181_read_als_it()
253 *val2 = cm32181->als_it_values[i]; in cm32181_read_als_it()
258 return -EINVAL; in cm32181_read_als_it()
262 * cm32181_write_als_it() - Write sensor integration time
268 * Return: i2c_smbus_write_word_data command return value.
272 struct i2c_client *client = cm32181->client; in cm32181_write_als_it()
276 n = cm32181->num_als_it; in cm32181_write_als_it()
278 if (val <= cm32181->als_it_values[i]) in cm32181_write_als_it()
281 i = n - 1; in cm32181_write_als_it()
283 als_it = cm32181->als_it_bits[i]; in cm32181_write_als_it()
286 mutex_lock(&cm32181->lock); in cm32181_write_als_it()
287 cm32181->conf_regs[CM32181_REG_ADDR_CMD] &= in cm32181_write_als_it()
289 cm32181->conf_regs[CM32181_REG_ADDR_CMD] |= in cm32181_write_als_it()
292 cm32181->conf_regs[CM32181_REG_ADDR_CMD]); in cm32181_write_als_it()
293 mutex_unlock(&cm32181->lock); in cm32181_write_als_it()
299 * cm32181_get_lux() - report current lux value
309 struct i2c_client *client = cm32181->client; in cm32181_get_lux()
316 return -EINVAL; in cm32181_get_lux()
318 lux = cm32181->lux_per_bit; in cm32181_get_lux()
319 lux *= cm32181->lux_per_bit_base_it; in cm32181_get_lux()
327 lux *= cm32181->calibscale; in cm32181_get_lux()
352 *val = cm32181->calibscale; in cm32181_read_raw()
360 return -EINVAL; in cm32181_read_raw()
372 cm32181->calibscale = val; in cm32181_write_raw()
379 return -EINVAL; in cm32181_write_raw()
383 * cm32181_get_it_available() - Get available ALS IT value
398 n = cm32181->num_als_it; in cm32181_get_it_available()
400 len += sprintf(buf + len, "0.%06u ", cm32181->als_it_values[i]); in cm32181_get_it_available()
442 struct device *dev = &client->dev; in cm32181_probe()
449 return -ENOMEM; in cm32181_probe()
463 if (ACPI_HANDLE(dev) && client->addr == SMBUS_ALERT_RESPONSE_ADDRESS) { in cm32181_probe()
478 cm32181->client = client; in cm32181_probe()
479 cm32181->dev = dev; in cm32181_probe()
481 mutex_init(&cm32181->lock); in cm32181_probe()
482 indio_dev->channels = cm32181_channels; in cm32181_probe()
483 indio_dev->num_channels = ARRAY_SIZE(cm32181_channels); in cm32181_probe()
484 indio_dev->info = &cm32181_info; in cm32181_probe()
485 indio_dev->name = dev_name(dev); in cm32181_probe()
486 indio_dev->modes = INDIO_DIRECT_MODE; in cm32181_probe()
506 struct i2c_client *client = cm32181->client; in cm32181_suspend()
515 struct i2c_client *client = cm32181->client; in cm32181_resume()
518 cm32181->conf_regs[CM32181_REG_ADDR_CMD]); in cm32181_resume()