forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/iio/pressure/ms5611_i2c.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * MS5611 pressure and temperature sensor driver (I2C 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 * 7-bit I2C slave addresses:
118 *
....@@ -17,21 +14,21 @@
1714 #include <linux/delay.h>
1815 #include <linux/i2c.h>
1916 #include <linux/module.h>
20
-#include <linux/of_device.h>
17
+#include <linux/mod_devicetable.h>
18
+
19
+#include <asm/unaligned.h>
2120
2221 #include "ms5611.h"
2322
24
-static int ms5611_i2c_reset(struct device *dev)
23
+static int ms5611_i2c_reset(struct ms5611_state *st)
2524 {
26
- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev));
27
-
2825 return i2c_smbus_write_byte(st->client, MS5611_RESET);
2926 }
3027
31
-static int ms5611_i2c_read_prom_word(struct device *dev, int index, u16 *word)
28
+static int ms5611_i2c_read_prom_word(struct ms5611_state *st, int index,
29
+ u16 *word)
3230 {
3331 int ret;
34
- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev));
3532
3633 ret = i2c_smbus_read_word_swapped(st->client,
3734 MS5611_READ_PROM_WORD + (index << 1));
....@@ -53,16 +50,15 @@
5350 if (ret < 0)
5451 return ret;
5552
56
- *val = (buf[0] << 16) | (buf[1] << 8) | buf[2];
53
+ *val = get_unaligned_be24(&buf[0]);
5754
5855 return 0;
5956 }
6057
61
-static int ms5611_i2c_read_adc_temp_and_pressure(struct device *dev,
58
+static int ms5611_i2c_read_adc_temp_and_pressure(struct ms5611_state *st,
6259 s32 *temp, s32 *pressure)
6360 {
6461 int ret;
65
- struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev));
6662 const struct ms5611_osr *osr = st->temp_osr;
6763
6864 ret = i2c_smbus_write_byte(st->client, osr->cmd);
....@@ -114,16 +110,12 @@
114110 return ms5611_remove(i2c_get_clientdata(client));
115111 }
116112
117
-#if defined(CONFIG_OF)
118113 static const struct of_device_id ms5611_i2c_matches[] = {
119114 { .compatible = "meas,ms5611" },
120
- { .compatible = "ms5611" },
121115 { .compatible = "meas,ms5607" },
122
- { .compatible = "ms5607" },
123116 { }
124117 };
125118 MODULE_DEVICE_TABLE(of, ms5611_i2c_matches);
126
-#endif
127119
128120 static const struct i2c_device_id ms5611_id[] = {
129121 { "ms5611", MS5611 },
....@@ -135,7 +127,7 @@
135127 static struct i2c_driver ms5611_driver = {
136128 .driver = {
137129 .name = "ms5611",
138
- .of_match_table = of_match_ptr(ms5611_i2c_matches)
130
+ .of_match_table = ms5611_i2c_matches,
139131 },
140132 .id_table = ms5611_id,
141133 .probe = ms5611_i2c_probe,