.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * ltr501.c - Support for Lite-On LTR501 ambient light and proximity sensor |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright 2014 Peter Meerwald <pmeerw@pmeerw.net> |
---|
5 | | - * |
---|
6 | | - * This file is subject to the terms and conditions of version 2 of |
---|
7 | | - * the GNU General Public License. See the file COPYING in the main |
---|
8 | | - * directory of this archive for more details. |
---|
9 | 6 | * |
---|
10 | 7 | * 7-bit I2C slave address 0x23 |
---|
11 | 8 | * |
---|
.. | .. |
---|
107 | 104 | int uscale; |
---|
108 | 105 | }; |
---|
109 | 106 | |
---|
110 | | -static struct ltr501_gain ltr501_als_gain_tbl[] = { |
---|
| 107 | +static const struct ltr501_gain ltr501_als_gain_tbl[] = { |
---|
111 | 108 | {1, 0}, |
---|
112 | 109 | {0, 5000}, |
---|
113 | 110 | }; |
---|
114 | 111 | |
---|
115 | | -static struct ltr501_gain ltr559_als_gain_tbl[] = { |
---|
| 112 | +static const struct ltr501_gain ltr559_als_gain_tbl[] = { |
---|
116 | 113 | {1, 0}, |
---|
117 | 114 | {0, 500000}, |
---|
118 | 115 | {0, 250000}, |
---|
.. | .. |
---|
123 | 120 | {0, 10000}, |
---|
124 | 121 | }; |
---|
125 | 122 | |
---|
126 | | -static struct ltr501_gain ltr501_ps_gain_tbl[] = { |
---|
| 123 | +static const struct ltr501_gain ltr501_ps_gain_tbl[] = { |
---|
127 | 124 | {1, 0}, |
---|
128 | 125 | {0, 250000}, |
---|
129 | 126 | {0, 125000}, |
---|
130 | 127 | {0, 62500}, |
---|
131 | 128 | }; |
---|
132 | 129 | |
---|
133 | | -static struct ltr501_gain ltr559_ps_gain_tbl[] = { |
---|
| 130 | +static const struct ltr501_gain ltr559_ps_gain_tbl[] = { |
---|
134 | 131 | {0, 62500}, /* x16 gain */ |
---|
135 | 132 | {0, 31250}, /* x32 gain */ |
---|
136 | 133 | {0, 15625}, /* bits X1 are for x64 gain */ |
---|
.. | .. |
---|
139 | 136 | |
---|
140 | 137 | struct ltr501_chip_info { |
---|
141 | 138 | u8 partid; |
---|
142 | | - struct ltr501_gain *als_gain; |
---|
| 139 | + const struct ltr501_gain *als_gain; |
---|
143 | 140 | int als_gain_tbl_size; |
---|
144 | | - struct ltr501_gain *ps_gain; |
---|
| 141 | + const struct ltr501_gain *ps_gain; |
---|
145 | 142 | int ps_gain_tbl_size; |
---|
146 | 143 | u8 als_mode_active; |
---|
147 | 144 | u8 als_gain_mask; |
---|
.. | .. |
---|
198 | 195 | return -EINVAL; |
---|
199 | 196 | } |
---|
200 | 197 | |
---|
201 | | -static int ltr501_als_read_samp_freq(struct ltr501_data *data, |
---|
| 198 | +static int ltr501_als_read_samp_freq(const struct ltr501_data *data, |
---|
202 | 199 | int *val, int *val2) |
---|
203 | 200 | { |
---|
204 | 201 | int ret, i; |
---|
.. | .. |
---|
216 | 213 | return IIO_VAL_INT_PLUS_MICRO; |
---|
217 | 214 | } |
---|
218 | 215 | |
---|
219 | | -static int ltr501_ps_read_samp_freq(struct ltr501_data *data, |
---|
| 216 | +static int ltr501_ps_read_samp_freq(const struct ltr501_data *data, |
---|
220 | 217 | int *val, int *val2) |
---|
221 | 218 | { |
---|
222 | 219 | int ret, i; |
---|
.. | .. |
---|
272 | 269 | return ret; |
---|
273 | 270 | } |
---|
274 | 271 | |
---|
275 | | -static int ltr501_als_read_samp_period(struct ltr501_data *data, int *val) |
---|
| 272 | +static int ltr501_als_read_samp_period(const struct ltr501_data *data, int *val) |
---|
276 | 273 | { |
---|
277 | 274 | int ret, i; |
---|
278 | 275 | |
---|
.. | .. |
---|
288 | 285 | return IIO_VAL_INT; |
---|
289 | 286 | } |
---|
290 | 287 | |
---|
291 | | -static int ltr501_ps_read_samp_period(struct ltr501_data *data, int *val) |
---|
| 288 | +static int ltr501_ps_read_samp_period(const struct ltr501_data *data, int *val) |
---|
292 | 289 | { |
---|
293 | 290 | int ret, i; |
---|
294 | 291 | |
---|
.. | .. |
---|
327 | 324 | return lux / 1000; |
---|
328 | 325 | } |
---|
329 | 326 | |
---|
330 | | -static int ltr501_drdy(struct ltr501_data *data, u8 drdy_mask) |
---|
| 327 | +static int ltr501_drdy(const struct ltr501_data *data, u8 drdy_mask) |
---|
331 | 328 | { |
---|
332 | 329 | int tries = 100; |
---|
333 | 330 | int ret, status; |
---|
.. | .. |
---|
379 | 376 | } |
---|
380 | 377 | |
---|
381 | 378 | /* read int time in micro seconds */ |
---|
382 | | -static int ltr501_read_it_time(struct ltr501_data *data, int *val, int *val2) |
---|
| 379 | +static int ltr501_read_it_time(const struct ltr501_data *data, |
---|
| 380 | + int *val, int *val2) |
---|
383 | 381 | { |
---|
384 | 382 | int ret, index; |
---|
385 | 383 | |
---|
.. | .. |
---|
397 | 395 | return IIO_VAL_INT_PLUS_MICRO; |
---|
398 | 396 | } |
---|
399 | 397 | |
---|
400 | | -static int ltr501_read_als(struct ltr501_data *data, __le16 buf[2]) |
---|
| 398 | +static int ltr501_read_als(const struct ltr501_data *data, __le16 buf[2]) |
---|
401 | 399 | { |
---|
402 | 400 | int ret; |
---|
403 | 401 | |
---|
.. | .. |
---|
409 | 407 | buf, 2 * sizeof(__le16)); |
---|
410 | 408 | } |
---|
411 | 409 | |
---|
412 | | -static int ltr501_read_ps(struct ltr501_data *data) |
---|
| 410 | +static int ltr501_read_ps(const struct ltr501_data *data) |
---|
413 | 411 | { |
---|
414 | 412 | __le16 status; |
---|
415 | 413 | int ret; |
---|
.. | .. |
---|
426 | 424 | return le16_to_cpu(status); |
---|
427 | 425 | } |
---|
428 | 426 | |
---|
429 | | -static int ltr501_read_intr_prst(struct ltr501_data *data, |
---|
| 427 | +static int ltr501_read_intr_prst(const struct ltr501_data *data, |
---|
430 | 428 | enum iio_chan_type type, |
---|
431 | 429 | int *val2) |
---|
432 | 430 | { |
---|
.. | .. |
---|
723 | 721 | return -EINVAL; |
---|
724 | 722 | } |
---|
725 | 723 | |
---|
726 | | -static int ltr501_get_gain_index(struct ltr501_gain *gain, int size, |
---|
| 724 | +static int ltr501_get_gain_index(const struct ltr501_gain *gain, int size, |
---|
727 | 725 | int val, int val2) |
---|
728 | 726 | { |
---|
729 | 727 | int i; |
---|
.. | .. |
---|
855 | 853 | return ret; |
---|
856 | 854 | } |
---|
857 | 855 | |
---|
858 | | -static int ltr501_read_thresh(struct iio_dev *indio_dev, |
---|
| 856 | +static int ltr501_read_thresh(const struct iio_dev *indio_dev, |
---|
859 | 857 | const struct iio_chan_spec *chan, |
---|
860 | 858 | enum iio_event_type type, |
---|
861 | 859 | enum iio_event_direction dir, |
---|
862 | 860 | enum iio_event_info info, |
---|
863 | 861 | int *val, int *val2) |
---|
864 | 862 | { |
---|
865 | | - struct ltr501_data *data = iio_priv(indio_dev); |
---|
| 863 | + const struct ltr501_data *data = iio_priv(indio_dev); |
---|
866 | 864 | int ret, thresh_data; |
---|
867 | 865 | |
---|
868 | 866 | switch (chan->type) { |
---|
.. | .. |
---|
1273 | 1271 | |
---|
1274 | 1272 | if (mask & LTR501_STATUS_ALS_RDY) { |
---|
1275 | 1273 | ret = regmap_bulk_read(data->regmap, LTR501_ALS_DATA1, |
---|
1276 | | - (u8 *)als_buf, sizeof(als_buf)); |
---|
| 1274 | + als_buf, sizeof(als_buf)); |
---|
1277 | 1275 | if (ret < 0) |
---|
1278 | 1276 | goto done; |
---|
1279 | 1277 | if (test_bit(0, indio_dev->active_scan_mask)) |
---|
.. | .. |
---|
1372 | 1370 | } |
---|
1373 | 1371 | } |
---|
1374 | 1372 | |
---|
1375 | | -static struct regmap_config ltr501_regmap_config = { |
---|
| 1373 | +static const struct regmap_config ltr501_regmap_config = { |
---|
1376 | 1374 | .name = LTR501_REGMAP_NAME, |
---|
1377 | 1375 | .reg_bits = 8, |
---|
1378 | 1376 | .val_bits = 8, |
---|
.. | .. |
---|
1492 | 1490 | if ((partid >> 4) != data->chip_info->partid) |
---|
1493 | 1491 | return -ENODEV; |
---|
1494 | 1492 | |
---|
1495 | | - indio_dev->dev.parent = &client->dev; |
---|
1496 | 1493 | indio_dev->info = data->chip_info->info; |
---|
1497 | 1494 | indio_dev->channels = data->chip_info->channels; |
---|
1498 | 1495 | indio_dev->num_channels = data->chip_info->no_channels; |
---|