2 * QEMU st STDS75 Digital temperature sensor and thermal watchdog emulation
4 * Copyright (c) 2009 yajin <yajin@vm-kernel.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 #include "qemu-timer.h"
50 static void stds75_event(i2c_slave
* i2c
, enum i2c_event event
)
52 struct stds75_s
*s
= (struct stds75_s
*) i2c
;
53 printf("stds75_event %d \n", event
);
54 if (event
== I2C_START_SEND
)
58 static int stds75_rx(i2c_slave
* i2c
)
60 struct stds75_s
*s
= (struct stds75_s
*) i2c
;
61 printf("stds75_rx s->reg %d \n", s
->reg
);
67 ret
= (s
->temp
>> ((1 - s
->index
) * 8)) & 0xff;
73 /*first byte is the MSB */
74 ret
= (s
->thys
>> ((1 - s
->index
) * 8)) & 0xff;
77 ret
= (s
->tos
>> ((1 - s
->index
) * 8)) & 0xff;
80 fprintf(stderr
, "%s: read from index %d of stds75 \n",
81 __FUNCTION__
, s
->reg
);
88 static int stds75_tx(i2c_slave
* i2c
, uint8_t data
)
90 struct stds75_s
*s
= (struct stds75_s
*) i2c
;
91 printf("stds75_tx %d \n", data
);
103 fprintf(stderr
, "%s: write to index 0 of stds75 \n", __FUNCTION__
);
109 /*first byte is the MSB */
110 s
->thys
&= (0xff) << (s
->index
* 8);
111 s
->thys
|= data
<< ((1 - s
->index
) * 8);
115 s
->tos
&= (0xff) << (s
->index
* 8);
116 s
->tos
|= data
<< ((1 - s
->index
) * 8);
120 fprintf(stderr
, "%s: write to index %d of stds75 \n",
121 __FUNCTION__
, s
->reg
);
132 static void stds75_reset(struct stds75_s
*s
)
138 i2c_slave
*stds75_init(i2c_bus
* bus
, qemu_irq irq
, int i2c_address
)
140 struct stds75_s
*s
= (struct stds75_s
*)
141 i2c_slave_init(bus
, i2c_address
, sizeof(struct stds75_s
));
143 s
->i2c
.event
= stds75_event
;
144 s
->i2c
.recv
= stds75_rx
;
145 s
->i2c
.send
= stds75_tx
;
151 //register_savevm("menelaus", -1, 0, menelaus_save, menelaus_load, s);