| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * MS5611 pressure and temperature sensor driver (I2C bus) |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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. |
|---|
| 9 | 6 | * |
|---|
| 10 | 7 | * 7-bit I2C slave addresses: |
|---|
| 11 | 8 | * |
|---|
| .. | .. |
|---|
| 17 | 14 | #include <linux/delay.h> |
|---|
| 18 | 15 | #include <linux/i2c.h> |
|---|
| 19 | 16 | #include <linux/module.h> |
|---|
| 20 | | -#include <linux/of_device.h> |
|---|
| 17 | +#include <linux/mod_devicetable.h> |
|---|
| 18 | + |
|---|
| 19 | +#include <asm/unaligned.h> |
|---|
| 21 | 20 | |
|---|
| 22 | 21 | #include "ms5611.h" |
|---|
| 23 | 22 | |
|---|
| 24 | | -static int ms5611_i2c_reset(struct device *dev) |
|---|
| 23 | +static int ms5611_i2c_reset(struct ms5611_state *st) |
|---|
| 25 | 24 | { |
|---|
| 26 | | - struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); |
|---|
| 27 | | - |
|---|
| 28 | 25 | return i2c_smbus_write_byte(st->client, MS5611_RESET); |
|---|
| 29 | 26 | } |
|---|
| 30 | 27 | |
|---|
| 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) |
|---|
| 32 | 30 | { |
|---|
| 33 | 31 | int ret; |
|---|
| 34 | | - struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); |
|---|
| 35 | 32 | |
|---|
| 36 | 33 | ret = i2c_smbus_read_word_swapped(st->client, |
|---|
| 37 | 34 | MS5611_READ_PROM_WORD + (index << 1)); |
|---|
| .. | .. |
|---|
| 53 | 50 | if (ret < 0) |
|---|
| 54 | 51 | return ret; |
|---|
| 55 | 52 | |
|---|
| 56 | | - *val = (buf[0] << 16) | (buf[1] << 8) | buf[2]; |
|---|
| 53 | + *val = get_unaligned_be24(&buf[0]); |
|---|
| 57 | 54 | |
|---|
| 58 | 55 | return 0; |
|---|
| 59 | 56 | } |
|---|
| 60 | 57 | |
|---|
| 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, |
|---|
| 62 | 59 | s32 *temp, s32 *pressure) |
|---|
| 63 | 60 | { |
|---|
| 64 | 61 | int ret; |
|---|
| 65 | | - struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev)); |
|---|
| 66 | 62 | const struct ms5611_osr *osr = st->temp_osr; |
|---|
| 67 | 63 | |
|---|
| 68 | 64 | ret = i2c_smbus_write_byte(st->client, osr->cmd); |
|---|
| .. | .. |
|---|
| 114 | 110 | return ms5611_remove(i2c_get_clientdata(client)); |
|---|
| 115 | 111 | } |
|---|
| 116 | 112 | |
|---|
| 117 | | -#if defined(CONFIG_OF) |
|---|
| 118 | 113 | static const struct of_device_id ms5611_i2c_matches[] = { |
|---|
| 119 | 114 | { .compatible = "meas,ms5611" }, |
|---|
| 120 | | - { .compatible = "ms5611" }, |
|---|
| 121 | 115 | { .compatible = "meas,ms5607" }, |
|---|
| 122 | | - { .compatible = "ms5607" }, |
|---|
| 123 | 116 | { } |
|---|
| 124 | 117 | }; |
|---|
| 125 | 118 | MODULE_DEVICE_TABLE(of, ms5611_i2c_matches); |
|---|
| 126 | | -#endif |
|---|
| 127 | 119 | |
|---|
| 128 | 120 | static const struct i2c_device_id ms5611_id[] = { |
|---|
| 129 | 121 | { "ms5611", MS5611 }, |
|---|
| .. | .. |
|---|
| 135 | 127 | static struct i2c_driver ms5611_driver = { |
|---|
| 136 | 128 | .driver = { |
|---|
| 137 | 129 | .name = "ms5611", |
|---|
| 138 | | - .of_match_table = of_match_ptr(ms5611_i2c_matches) |
|---|
| 130 | + .of_match_table = ms5611_i2c_matches, |
|---|
| 139 | 131 | }, |
|---|
| 140 | 132 | .id_table = ms5611_id, |
|---|
| 141 | 133 | .probe = ms5611_i2c_probe, |
|---|