mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
iio:common:ms_sensors:ms_sensors_i2c: rework CRC calculation helper
The CRC calculation always happens on 8 words which is why there is an extra element in the prom array of struct ms_tp_dev. However, on ms5637 and similar, only 7 words are readable. Then, set MS_SENSORS_TP_PROM_WORDS_NB to 8 and stop passing a len parameter to ms_sensors_tp_crc_valid as this simply hide the fact that it is hardcoded. Finally, use the newly introduced hw->prom_len to know how many words can be read. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20210109231148.1168104-5-alexandre.belloni@bootlin.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
committed by
Jonathan Cameron
parent
07498719be
commit
7ae7f75080
@@ -493,19 +493,18 @@ EXPORT_SYMBOL(ms_sensors_ht_read_humidity);
|
|||||||
* This function is only used when reading PROM coefficients
|
* This function is only used when reading PROM coefficients
|
||||||
*
|
*
|
||||||
* @prom: pointer to PROM coefficients array
|
* @prom: pointer to PROM coefficients array
|
||||||
* @len: length of PROM coefficients array
|
|
||||||
*
|
*
|
||||||
* Return: True if CRC is ok.
|
* Return: True if CRC is ok.
|
||||||
*/
|
*/
|
||||||
static bool ms_sensors_tp_crc_valid(u16 *prom, u8 len)
|
static bool ms_sensors_tp_crc_valid(u16 *prom)
|
||||||
{
|
{
|
||||||
unsigned int cnt, n_bit;
|
unsigned int cnt, n_bit;
|
||||||
u16 n_rem = 0x0000, crc_read = prom[0], crc = (*prom & 0xF000) >> 12;
|
u16 n_rem = 0x0000, crc_read = prom[0], crc = (*prom & 0xF000) >> 12;
|
||||||
|
|
||||||
prom[len - 1] = 0;
|
prom[MS_SENSORS_TP_PROM_WORDS_NB - 1] = 0;
|
||||||
prom[0] &= 0x0FFF; /* Clear the CRC computation part */
|
prom[0] &= 0x0FFF; /* Clear the CRC computation part */
|
||||||
|
|
||||||
for (cnt = 0; cnt < len * 2; cnt++) {
|
for (cnt = 0; cnt < MS_SENSORS_TP_PROM_WORDS_NB * 2; cnt++) {
|
||||||
if (cnt % 2 == 1)
|
if (cnt % 2 == 1)
|
||||||
n_rem ^= prom[cnt >> 1] & 0x00FF;
|
n_rem ^= prom[cnt >> 1] & 0x00FF;
|
||||||
else
|
else
|
||||||
@@ -537,7 +536,7 @@ int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data)
|
|||||||
{
|
{
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
for (i = 0; i < MS_SENSORS_TP_PROM_WORDS_NB; i++) {
|
for (i = 0; i < dev_data->hw->prom_len; i++) {
|
||||||
ret = ms_sensors_read_prom_word(
|
ret = ms_sensors_read_prom_word(
|
||||||
dev_data->client,
|
dev_data->client,
|
||||||
MS_SENSORS_TP_PROM_READ + (i << 1),
|
MS_SENSORS_TP_PROM_READ + (i << 1),
|
||||||
@@ -547,8 +546,7 @@ int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ms_sensors_tp_crc_valid(dev_data->prom,
|
if (!ms_sensors_tp_crc_valid(dev_data->prom)) {
|
||||||
MS_SENSORS_TP_PROM_WORDS_NB + 1)) {
|
|
||||||
dev_err(&dev_data->client->dev,
|
dev_err(&dev_data->client->dev,
|
||||||
"Calibration coefficients crc check error\n");
|
"Calibration coefficients crc check error\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
#include <linux/i2c.h>
|
#include <linux/i2c.h>
|
||||||
#include <linux/mutex.h>
|
#include <linux/mutex.h>
|
||||||
|
|
||||||
#define MS_SENSORS_TP_PROM_WORDS_NB 7
|
#define MS_SENSORS_TP_PROM_WORDS_NB 8
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct ms_ht_dev - Humidity/Temperature sensor device structure
|
* struct ms_ht_dev - Humidity/Temperature sensor device structure
|
||||||
@@ -47,7 +47,7 @@ struct ms_tp_dev {
|
|||||||
struct i2c_client *client;
|
struct i2c_client *client;
|
||||||
struct mutex lock;
|
struct mutex lock;
|
||||||
const struct ms_tp_hw_data *hw;
|
const struct ms_tp_hw_data *hw;
|
||||||
u16 prom[MS_SENSORS_TP_PROM_WORDS_NB + 1];
|
u16 prom[MS_SENSORS_TP_PROM_WORDS_NB];
|
||||||
u8 res_index;
|
u8 res_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user