Lines Matching +full:light +full:- +full:sensor

1 // SPDX-License-Identifier: GPL-2.0
3 * ROHM BH1710/BH1715/BH1721/BH1750/BH1751 ambient light sensor driver
8 * http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1710fvc-e.pdf
9 * http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1715fvc-e.pdf
10 * http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1721fvc-e.pdf
11 * http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1750fvi-e.pdf
12 * http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1751fvi-e.pdf
14 * 7-bit I2C slave addresses:
27 #define BH1750_ONE_TIME_H_RES_MODE 0x20 /* auto-mode for BH1721 */
75 const struct bh1750_chip_info *chip_info = data->chip_info; in bh1750_change_int_time()
77 if ((usec % chip_info->mtreg_to_usec) != 0) in bh1750_change_int_time()
78 return -EINVAL; in bh1750_change_int_time()
80 val = usec / chip_info->mtreg_to_usec; in bh1750_change_int_time()
81 if (val < chip_info->mtreg_min || val > chip_info->mtreg_max) in bh1750_change_int_time()
82 return -EINVAL; in bh1750_change_int_time()
84 ret = i2c_smbus_write_byte(data->client, BH1750_POWER_DOWN); in bh1750_change_int_time()
88 regval = (val & chip_info->int_time_high_mask) >> 5; in bh1750_change_int_time()
89 ret = i2c_smbus_write_byte(data->client, in bh1750_change_int_time()
94 regval = val & chip_info->int_time_low_mask; in bh1750_change_int_time()
95 ret = i2c_smbus_write_byte(data->client, in bh1750_change_int_time()
100 data->mtreg = val; in bh1750_change_int_time()
109 const struct bh1750_chip_info *chip_info = data->chip_info; in bh1750_read()
110 unsigned long delay = chip_info->mtreg_to_usec * data->mtreg; in bh1750_read()
116 ret = i2c_smbus_write_byte(data->client, BH1750_ONE_TIME_H_RES_MODE); in bh1750_read()
122 ret = i2c_master_recv(data->client, (char *)&result, 2); in bh1750_read()
137 const struct bh1750_chip_info *chip_info = data->chip_info; in bh1750_read_raw()
141 switch (chan->type) { in bh1750_read_raw()
143 mutex_lock(&data->lock); in bh1750_read_raw()
145 mutex_unlock(&data->lock); in bh1750_read_raw()
151 return -EINVAL; in bh1750_read_raw()
154 tmp = chip_info->mtreg_to_scale / data->mtreg; in bh1750_read_raw()
160 *val2 = chip_info->mtreg_to_usec * data->mtreg; in bh1750_read_raw()
163 return -EINVAL; in bh1750_read_raw()
177 return -EINVAL; in bh1750_write_raw()
179 mutex_lock(&data->lock); in bh1750_write_raw()
181 mutex_unlock(&data->lock); in bh1750_write_raw()
184 return -EINVAL; in bh1750_write_raw()
194 const struct bh1750_chip_info *chip_info = data->chip_info; in bh1750_show_int_time_available()
196 for (i = chip_info->mtreg_min; i <= chip_info->mtreg_max; i += chip_info->inc) in bh1750_show_int_time_available()
197 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06d ", in bh1750_show_int_time_available()
198 chip_info->mtreg_to_usec * i); in bh1750_show_int_time_available()
200 buf[len - 1] = '\n'; in bh1750_show_int_time_available()
238 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | in bh1750_probe()
240 return -EOPNOTSUPP; in bh1750_probe()
242 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in bh1750_probe()
244 return -ENOMEM; in bh1750_probe()
248 data->client = client; in bh1750_probe()
249 data->chip_info = &bh1750_chip_info_tbl[id->driver_data]; in bh1750_probe()
251 usec = data->chip_info->mtreg_to_usec * data->chip_info->mtreg_default; in bh1750_probe()
256 mutex_init(&data->lock); in bh1750_probe()
257 indio_dev->info = &bh1750_info; in bh1750_probe()
258 indio_dev->name = id->name; in bh1750_probe()
259 indio_dev->channels = bh1750_channels; in bh1750_probe()
260 indio_dev->num_channels = ARRAY_SIZE(bh1750_channels); in bh1750_probe()
261 indio_dev->modes = INDIO_DIRECT_MODE; in bh1750_probe()
273 mutex_lock(&data->lock); in bh1750_remove()
275 mutex_unlock(&data->lock); in bh1750_remove()
288 mutex_lock(&data->lock); in bh1750_suspend()
289 ret = i2c_smbus_write_byte(data->client, BH1750_POWER_DOWN); in bh1750_suspend()
290 mutex_unlock(&data->lock); in bh1750_suspend()