aboutsummaryrefslogtreecommitdiff
path: root/hw/tmp105.c
diff options
context:
space:
mode:
authorAlex Horn <alex.horn@cs.ox.ac.uk>2012-12-05 12:34:06 +0000
committerAnthony Liguori <aliguori@us.ibm.com>2012-12-23 14:37:51 -0600
commit2915efbfa8efadaa2806e827ba92b8dba4f7cd52 (patch)
treec3887980d6b85ae57fb749ac3e0b74492c6cd7ed /hw/tmp105.c
parenteac236ea7bfc1902126be70459e320591078df5c (diff)
downloadqemu-2915efbfa8efadaa2806e827ba92b8dba4f7cd52.zip
qemu-2915efbfa8efadaa2806e827ba92b8dba4f7cd52.tar.gz
qemu-2915efbfa8efadaa2806e827ba92b8dba4f7cd52.tar.bz2
tmp105: Create API for TMP105 temperature sensor.
* Define enum for TMP105 registers * Move tmp105_set() from I2C to TMP105 header * Document units and range of temperature as preconditions Reviewed-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Alex Horn <alex.horn@cs.ox.ac.uk> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/tmp105.c')
-rw-r--r--hw/tmp105.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/hw/tmp105.c b/hw/tmp105.c
index 8e8dbd9..9c67e64 100644
--- a/hw/tmp105.c
+++ b/hw/tmp105.c
@@ -20,6 +20,7 @@
#include "hw.h"
#include "i2c.h"
+#include "tmp105.h"
typedef struct {
I2CSlave i2c;
@@ -92,22 +93,22 @@ static void tmp105_read(TMP105State *s)
}
switch (s->pointer & 3) {
- case 0: /* Temperature */
+ case TMP105_REG_TEMPERATURE:
s->buf[s->len ++] = (((uint16_t) s->temperature) >> 8);
s->buf[s->len ++] = (((uint16_t) s->temperature) >> 0) &
(0xf0 << ((~s->config >> 5) & 3)); /* R */
break;
- case 1: /* Configuration */
+ case TMP105_REG_CONFIG:
s->buf[s->len ++] = s->config;
break;
- case 2: /* T_LOW */
+ case TMP105_REG_T_LOW:
s->buf[s->len ++] = ((uint16_t) s->limit[0]) >> 8;
s->buf[s->len ++] = ((uint16_t) s->limit[0]) >> 0;
break;
- case 3: /* T_HIGH */
+ case TMP105_REG_T_HIGH:
s->buf[s->len ++] = ((uint16_t) s->limit[1]) >> 8;
s->buf[s->len ++] = ((uint16_t) s->limit[1]) >> 0;
break;
@@ -117,10 +118,10 @@ static void tmp105_read(TMP105State *s)
static void tmp105_write(TMP105State *s)
{
switch (s->pointer & 3) {
- case 0: /* Temperature */
+ case TMP105_REG_TEMPERATURE:
break;
- case 1: /* Configuration */
+ case TMP105_REG_CONFIG:
if (s->buf[0] & ~s->config & (1 << 0)) /* SD */
printf("%s: TMP105 shutdown\n", __FUNCTION__);
s->config = s->buf[0];
@@ -128,8 +129,8 @@ static void tmp105_write(TMP105State *s)
tmp105_alarm_update(s);
break;
- case 2: /* T_LOW */
- case 3: /* T_HIGH */
+ case TMP105_REG_T_LOW:
+ case TMP105_REG_T_HIGH:
if (s->len >= 3)
s->limit[s->pointer & 1] = (int16_t)
((((uint16_t) s->buf[0]) << 8) | s->buf[1]);