summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/sht15.c
diff options
context:
space:
mode:
authoryalin wang <yalin.wang2010@gmail.com>2015-08-10 10:41:43 -0400
committerGuenter Roeck <linux@roeck-us.net>2015-08-11 02:00:10 -0400
commit33836ee98533fd27baa89dabca48f8d4e69dd438 (patch)
treec9744a046946cbba09459dc2831baa22537e5701 /drivers/hwmon/sht15.c
parentcfca3789e0678c57e09dfb1a09fdfce427b7c92e (diff)
hwmon:change sht15_reverse()
This change sht15_reverse() to be generic bitrev8(). Signed-off-by: yalin wang <yalin.wang2010@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/sht15.c')
-rw-r--r--drivers/hwmon/sht15.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
index 497a7f822a12..a2fdbb7d20ed 100644
--- a/drivers/hwmon/sht15.c
+++ b/drivers/hwmon/sht15.c
@@ -33,6 +33,7 @@
33#include <linux/regulator/consumer.h> 33#include <linux/regulator/consumer.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/atomic.h> 35#include <linux/atomic.h>
36#include <linux/bitrev.h>
36 37
37/* Commands */ 38/* Commands */
38#define SHT15_MEASURE_TEMP 0x03 39#define SHT15_MEASURE_TEMP 0x03
@@ -173,19 +174,6 @@ struct sht15_data {
173}; 174};
174 175
175/** 176/**
176 * sht15_reverse() - reverse a byte
177 * @byte: byte to reverse.
178 */
179static u8 sht15_reverse(u8 byte)
180{
181 u8 i, c;
182
183 for (c = 0, i = 0; i < 8; i++)
184 c |= (!!(byte & (1 << i))) << (7 - i);
185 return c;
186}
187
188/**
189 * sht15_crc8() - compute crc8 177 * sht15_crc8() - compute crc8
190 * @data: sht15 specific data. 178 * @data: sht15 specific data.
191 * @value: sht15 retrieved data. 179 * @value: sht15 retrieved data.
@@ -196,7 +184,7 @@ static u8 sht15_crc8(struct sht15_data *data,
196 const u8 *value, 184 const u8 *value,
197 int len) 185 int len)
198{ 186{
199 u8 crc = sht15_reverse(data->val_status & 0x0F); 187 u8 crc = bitrev8(data->val_status & 0x0F);
200 188
201 while (len--) { 189 while (len--) {
202 crc = sht15_crc8_table[*value ^ crc]; 190 crc = sht15_crc8_table[*value ^ crc];
@@ -477,7 +465,7 @@ static int sht15_update_status(struct sht15_data *data)
477 465
478 if (data->checksumming) { 466 if (data->checksumming) {
479 sht15_ack(data); 467 sht15_ack(data);
480 dev_checksum = sht15_reverse(sht15_read_byte(data)); 468 dev_checksum = bitrev8(sht15_read_byte(data));
481 checksum_vals[0] = SHT15_READ_STATUS; 469 checksum_vals[0] = SHT15_READ_STATUS;
482 checksum_vals[1] = status; 470 checksum_vals[1] = status;
483 data->checksum_ok = (sht15_crc8(data, checksum_vals, 2) 471 data->checksum_ok = (sht15_crc8(data, checksum_vals, 2)
@@ -864,7 +852,7 @@ static void sht15_bh_read_data(struct work_struct *work_s)
864 */ 852 */
865 if (sht15_ack(data)) 853 if (sht15_ack(data))
866 goto wakeup; 854 goto wakeup;
867 dev_checksum = sht15_reverse(sht15_read_byte(data)); 855 dev_checksum = bitrev8(sht15_read_byte(data));
868 checksum_vals[0] = (data->state == SHT15_READING_TEMP) ? 856 checksum_vals[0] = (data->state == SHT15_READING_TEMP) ?
869 SHT15_MEASURE_TEMP : SHT15_MEASURE_RH; 857 SHT15_MEASURE_TEMP : SHT15_MEASURE_RH;
870 checksum_vals[1] = (u8) (val >> 8); 858 checksum_vals[1] = (u8) (val >> 8);