forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/iio/pressure/ms5611_spi.c
....@@ -1,33 +1,31 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * MS5611 pressure and temperature sensor driver (SPI bus)
34 *
45 * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
96 *
107 */
118
129 #include <linux/delay.h>
1310 #include <linux/module.h>
1411 #include <linux/spi/spi.h>
15
-#include <linux/of_device.h>
12
+#include <linux/mod_devicetable.h>
13
+
14
+#include <asm/unaligned.h>
1615
1716 #include "ms5611.h"
1817
19
-static int ms5611_spi_reset(struct device *dev)
18
+static int ms5611_spi_reset(struct ms5611_state *st)
2019 {
2120 u8 cmd = MS5611_RESET;
22
- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev));
2321
2422 return spi_write_then_read(st->client, &cmd, 1, NULL, 0);
2523 }
2624
27
-static int ms5611_spi_read_prom_word(struct device *dev, int index, u16 *word)
25
+static int ms5611_spi_read_prom_word(struct ms5611_state *st, int index,
26
+ u16 *word)
2827 {
2928 int ret;
30
- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev));
3129
3230 ret = spi_w8r16be(st->client, MS5611_READ_PROM_WORD + (index << 1));
3331 if (ret < 0)
....@@ -38,26 +36,24 @@
3836 return 0;
3937 }
4038
41
-static int ms5611_spi_read_adc(struct device *dev, s32 *val)
39
+static int ms5611_spi_read_adc(struct ms5611_state *st, s32 *val)
4240 {
4341 int ret;
4442 u8 buf[3] = { MS5611_READ_ADC };
45
- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev));
4643
4744 ret = spi_write_then_read(st->client, buf, 1, buf, 3);
4845 if (ret < 0)
4946 return ret;
5047
51
- *val = (buf[0] << 16) | (buf[1] << 8) | buf[2];
48
+ *val = get_unaligned_be24(&buf[0]);
5249
5350 return 0;
5451 }
5552
56
-static int ms5611_spi_read_adc_temp_and_pressure(struct device *dev,
53
+static int ms5611_spi_read_adc_temp_and_pressure(struct ms5611_state *st,
5754 s32 *temp, s32 *pressure)
5855 {
5956 int ret;
60
- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev));
6157 const struct ms5611_osr *osr = st->temp_osr;
6258
6359 /*
....@@ -69,7 +65,7 @@
6965 return ret;
7066
7167 usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL));
72
- ret = ms5611_spi_read_adc(dev, temp);
68
+ ret = ms5611_spi_read_adc(st, temp);
7369 if (ret < 0)
7470 return ret;
7571
....@@ -79,7 +75,7 @@
7975 return ret;
8076
8177 usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL));
82
- return ms5611_spi_read_adc(dev, pressure);
78
+ return ms5611_spi_read_adc(st, pressure);
8379 }
8480
8581 static int ms5611_spi_probe(struct spi_device *spi)
....@@ -95,7 +91,7 @@
9591 spi_set_drvdata(spi, indio_dev);
9692
9793 spi->mode = SPI_MODE_0;
98
- spi->max_speed_hz = 20000000;
94
+ spi->max_speed_hz = min(spi->max_speed_hz, 20000000U);
9995 spi->bits_per_word = 8;
10096 ret = spi_setup(spi);
10197 if (ret < 0)
....@@ -116,16 +112,12 @@
116112 return ms5611_remove(spi_get_drvdata(spi));
117113 }
118114
119
-#if defined(CONFIG_OF)
120115 static const struct of_device_id ms5611_spi_matches[] = {
121116 { .compatible = "meas,ms5611" },
122
- { .compatible = "ms5611" },
123117 { .compatible = "meas,ms5607" },
124
- { .compatible = "ms5607" },
125118 { }
126119 };
127120 MODULE_DEVICE_TABLE(of, ms5611_spi_matches);
128
-#endif
129121
130122 static const struct spi_device_id ms5611_id[] = {
131123 { "ms5611", MS5611 },
....@@ -137,7 +129,7 @@
137129 static struct spi_driver ms5611_driver = {
138130 .driver = {
139131 .name = "ms5611",
140
- .of_match_table = of_match_ptr(ms5611_spi_matches)
132
+ .of_match_table = ms5611_spi_matches
141133 },
142134 .id_table = ms5611_id,
143135 .probe = ms5611_spi_probe,