forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/iio/light/ltr501.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * ltr501.c - Support for Lite-On LTR501 ambient light and proximity sensor
34 *
45 * 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.
96 *
107 * 7-bit I2C slave address 0x23
118 *
....@@ -107,12 +104,12 @@
107104 int uscale;
108105 };
109106
110
-static struct ltr501_gain ltr501_als_gain_tbl[] = {
107
+static const struct ltr501_gain ltr501_als_gain_tbl[] = {
111108 {1, 0},
112109 {0, 5000},
113110 };
114111
115
-static struct ltr501_gain ltr559_als_gain_tbl[] = {
112
+static const struct ltr501_gain ltr559_als_gain_tbl[] = {
116113 {1, 0},
117114 {0, 500000},
118115 {0, 250000},
....@@ -123,14 +120,14 @@
123120 {0, 10000},
124121 };
125122
126
-static struct ltr501_gain ltr501_ps_gain_tbl[] = {
123
+static const struct ltr501_gain ltr501_ps_gain_tbl[] = {
127124 {1, 0},
128125 {0, 250000},
129126 {0, 125000},
130127 {0, 62500},
131128 };
132129
133
-static struct ltr501_gain ltr559_ps_gain_tbl[] = {
130
+static const struct ltr501_gain ltr559_ps_gain_tbl[] = {
134131 {0, 62500}, /* x16 gain */
135132 {0, 31250}, /* x32 gain */
136133 {0, 15625}, /* bits X1 are for x64 gain */
....@@ -139,9 +136,9 @@
139136
140137 struct ltr501_chip_info {
141138 u8 partid;
142
- struct ltr501_gain *als_gain;
139
+ const struct ltr501_gain *als_gain;
143140 int als_gain_tbl_size;
144
- struct ltr501_gain *ps_gain;
141
+ const struct ltr501_gain *ps_gain;
145142 int ps_gain_tbl_size;
146143 u8 als_mode_active;
147144 u8 als_gain_mask;
....@@ -198,7 +195,7 @@
198195 return -EINVAL;
199196 }
200197
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,
202199 int *val, int *val2)
203200 {
204201 int ret, i;
....@@ -216,7 +213,7 @@
216213 return IIO_VAL_INT_PLUS_MICRO;
217214 }
218215
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,
220217 int *val, int *val2)
221218 {
222219 int ret, i;
....@@ -272,7 +269,7 @@
272269 return ret;
273270 }
274271
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)
276273 {
277274 int ret, i;
278275
....@@ -288,7 +285,7 @@
288285 return IIO_VAL_INT;
289286 }
290287
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)
292289 {
293290 int ret, i;
294291
....@@ -327,7 +324,7 @@
327324 return lux / 1000;
328325 }
329326
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)
331328 {
332329 int tries = 100;
333330 int ret, status;
....@@ -379,7 +376,8 @@
379376 }
380377
381378 /* 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)
383381 {
384382 int ret, index;
385383
....@@ -397,7 +395,7 @@
397395 return IIO_VAL_INT_PLUS_MICRO;
398396 }
399397
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])
401399 {
402400 int ret;
403401
....@@ -409,7 +407,7 @@
409407 buf, 2 * sizeof(__le16));
410408 }
411409
412
-static int ltr501_read_ps(struct ltr501_data *data)
410
+static int ltr501_read_ps(const struct ltr501_data *data)
413411 {
414412 __le16 status;
415413 int ret;
....@@ -426,7 +424,7 @@
426424 return le16_to_cpu(status);
427425 }
428426
429
-static int ltr501_read_intr_prst(struct ltr501_data *data,
427
+static int ltr501_read_intr_prst(const struct ltr501_data *data,
430428 enum iio_chan_type type,
431429 int *val2)
432430 {
....@@ -723,7 +721,7 @@
723721 return -EINVAL;
724722 }
725723
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,
727725 int val, int val2)
728726 {
729727 int i;
....@@ -855,14 +853,14 @@
855853 return ret;
856854 }
857855
858
-static int ltr501_read_thresh(struct iio_dev *indio_dev,
856
+static int ltr501_read_thresh(const struct iio_dev *indio_dev,
859857 const struct iio_chan_spec *chan,
860858 enum iio_event_type type,
861859 enum iio_event_direction dir,
862860 enum iio_event_info info,
863861 int *val, int *val2)
864862 {
865
- struct ltr501_data *data = iio_priv(indio_dev);
863
+ const struct ltr501_data *data = iio_priv(indio_dev);
866864 int ret, thresh_data;
867865
868866 switch (chan->type) {
....@@ -1273,7 +1271,7 @@
12731271
12741272 if (mask & LTR501_STATUS_ALS_RDY) {
12751273 ret = regmap_bulk_read(data->regmap, LTR501_ALS_DATA1,
1276
- (u8 *)als_buf, sizeof(als_buf));
1274
+ als_buf, sizeof(als_buf));
12771275 if (ret < 0)
12781276 goto done;
12791277 if (test_bit(0, indio_dev->active_scan_mask))
....@@ -1372,7 +1370,7 @@
13721370 }
13731371 }
13741372
1375
-static struct regmap_config ltr501_regmap_config = {
1373
+static const struct regmap_config ltr501_regmap_config = {
13761374 .name = LTR501_REGMAP_NAME,
13771375 .reg_bits = 8,
13781376 .val_bits = 8,
....@@ -1492,7 +1490,6 @@
14921490 if ((partid >> 4) != data->chip_info->partid)
14931491 return -ENODEV;
14941492
1495
- indio_dev->dev.parent = &client->dev;
14961493 indio_dev->info = data->chip_info->info;
14971494 indio_dev->channels = data->chip_info->channels;
14981495 indio_dev->num_channels = data->chip_info->no_channels;