2008-04-14 23:57:44 +02:00
|
|
|
/*
|
|
|
|
* Texas Instruments TMP105 temperature sensor.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Nokia Corporation
|
|
|
|
* Written by Andrzej Zaborowski <andrew@openedhand.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 or
|
|
|
|
* (at your option) version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-01-04 23:05:52 +01:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
2009-07-16 22:47:01 +02:00
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
2008-04-14 23:57:44 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:17 +01:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/i2c/i2c.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2013-03-18 17:36:02 +01:00
|
|
|
#include "tmp105.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2013-01-16 01:57:59 +01:00
|
|
|
#include "qapi/visitor.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2008-04-14 23:57:44 +02:00
|
|
|
|
2009-05-10 02:44:56 +02:00
|
|
|
static void tmp105_interrupt_update(TMP105State *s)
|
2008-04-14 23:57:44 +02:00
|
|
|
{
|
|
|
|
qemu_set_irq(s->pin, s->alarm ^ ((~s->config >> 2) & 1)); /* POL */
|
|
|
|
}
|
|
|
|
|
2009-05-10 02:44:56 +02:00
|
|
|
static void tmp105_alarm_update(TMP105State *s)
|
2008-04-14 23:57:44 +02:00
|
|
|
{
|
|
|
|
if ((s->config >> 0) & 1) { /* SD */
|
|
|
|
if ((s->config >> 7) & 1) /* OS */
|
|
|
|
s->config &= ~(1 << 7); /* OS */
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((s->config >> 1) & 1) { /* TM */
|
|
|
|
if (s->temperature >= s->limit[1])
|
|
|
|
s->alarm = 1;
|
|
|
|
else if (s->temperature < s->limit[0])
|
|
|
|
s->alarm = 1;
|
|
|
|
} else {
|
|
|
|
if (s->temperature >= s->limit[1])
|
|
|
|
s->alarm = 1;
|
|
|
|
else if (s->temperature < s->limit[0])
|
|
|
|
s->alarm = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp105_interrupt_update(s);
|
|
|
|
}
|
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void tmp105_get_temperature(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2013-01-16 01:57:59 +01:00
|
|
|
{
|
|
|
|
TMP105State *s = TMP105(obj);
|
2014-03-31 18:26:32 +02:00
|
|
|
int64_t value = s->temperature * 1000 / 256;
|
2013-01-16 01:57:59 +01:00
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_int(v, name, &value, errp);
|
2013-01-16 01:57:59 +01:00
|
|
|
}
|
|
|
|
|
2014-03-31 18:26:32 +02:00
|
|
|
/* Units are 0.001 centigrades relative to 0 C. s->temperature is 8.8
|
|
|
|
* fixed point, so units are 1/256 centigrades. A simple ratio will do.
|
|
|
|
*/
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void tmp105_set_temperature(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2008-04-14 23:57:44 +02:00
|
|
|
{
|
2013-01-16 01:57:59 +01:00
|
|
|
TMP105State *s = TMP105(obj);
|
|
|
|
int64_t temp;
|
2008-04-14 23:57:44 +02:00
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 18:06:02 +02:00
|
|
|
if (!visit_type_int(v, name, &temp, errp)) {
|
2013-01-16 01:57:59 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-04-14 23:57:44 +02:00
|
|
|
if (temp >= 128000 || temp < -128000) {
|
2018-11-20 21:36:28 +01:00
|
|
|
error_setg(errp, "value %" PRId64 ".%03" PRIu64 " C is out of range",
|
2013-01-16 01:57:59 +01:00
|
|
|
temp / 1000, temp % 1000);
|
|
|
|
return;
|
2008-04-14 23:57:44 +02:00
|
|
|
}
|
|
|
|
|
2014-03-31 18:26:32 +02:00
|
|
|
s->temperature = (int16_t) (temp * 256 / 1000);
|
2008-04-14 23:57:44 +02:00
|
|
|
|
|
|
|
tmp105_alarm_update(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int tmp105_faultq[4] = { 1, 2, 4, 6 };
|
|
|
|
|
2009-05-10 02:44:56 +02:00
|
|
|
static void tmp105_read(TMP105State *s)
|
2008-04-14 23:57:44 +02:00
|
|
|
{
|
|
|
|
s->len = 0;
|
|
|
|
|
|
|
|
if ((s->config >> 1) & 1) { /* TM */
|
|
|
|
s->alarm = 0;
|
|
|
|
tmp105_interrupt_update(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (s->pointer & 3) {
|
2012-12-05 13:34:06 +01:00
|
|
|
case TMP105_REG_TEMPERATURE:
|
2008-04-14 23:57:44 +02:00
|
|
|
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;
|
|
|
|
|
2012-12-05 13:34:06 +01:00
|
|
|
case TMP105_REG_CONFIG:
|
2008-04-14 23:57:44 +02:00
|
|
|
s->buf[s->len ++] = s->config;
|
|
|
|
break;
|
|
|
|
|
2012-12-05 13:34:06 +01:00
|
|
|
case TMP105_REG_T_LOW:
|
2008-04-14 23:57:44 +02:00
|
|
|
s->buf[s->len ++] = ((uint16_t) s->limit[0]) >> 8;
|
|
|
|
s->buf[s->len ++] = ((uint16_t) s->limit[0]) >> 0;
|
|
|
|
break;
|
|
|
|
|
2012-12-05 13:34:06 +01:00
|
|
|
case TMP105_REG_T_HIGH:
|
2008-04-14 23:57:44 +02:00
|
|
|
s->buf[s->len ++] = ((uint16_t) s->limit[1]) >> 8;
|
|
|
|
s->buf[s->len ++] = ((uint16_t) s->limit[1]) >> 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-10 02:44:56 +02:00
|
|
|
static void tmp105_write(TMP105State *s)
|
2008-04-14 23:57:44 +02:00
|
|
|
{
|
|
|
|
switch (s->pointer & 3) {
|
2012-12-05 13:34:06 +01:00
|
|
|
case TMP105_REG_TEMPERATURE:
|
2008-04-14 23:57:44 +02:00
|
|
|
break;
|
|
|
|
|
2012-12-05 13:34:06 +01:00
|
|
|
case TMP105_REG_CONFIG:
|
2008-04-14 23:57:44 +02:00
|
|
|
if (s->buf[0] & ~s->config & (1 << 0)) /* SD */
|
2017-11-08 23:56:31 +01:00
|
|
|
printf("%s: TMP105 shutdown\n", __func__);
|
2008-04-14 23:57:44 +02:00
|
|
|
s->config = s->buf[0];
|
|
|
|
s->faults = tmp105_faultq[(s->config >> 3) & 3]; /* F */
|
|
|
|
tmp105_alarm_update(s);
|
|
|
|
break;
|
|
|
|
|
2012-12-05 13:34:06 +01:00
|
|
|
case TMP105_REG_T_LOW:
|
|
|
|
case TMP105_REG_T_HIGH:
|
2008-04-14 23:57:44 +02:00
|
|
|
if (s->len >= 3)
|
|
|
|
s->limit[s->pointer & 1] = (int16_t)
|
|
|
|
((((uint16_t) s->buf[0]) << 8) | s->buf[1]);
|
|
|
|
tmp105_alarm_update(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-14 18:50:50 +01:00
|
|
|
static uint8_t tmp105_rx(I2CSlave *i2c)
|
2008-04-14 23:57:44 +02:00
|
|
|
{
|
2013-01-16 01:57:58 +01:00
|
|
|
TMP105State *s = TMP105(i2c);
|
2008-04-14 23:57:44 +02:00
|
|
|
|
2013-01-16 01:57:58 +01:00
|
|
|
if (s->len < 2) {
|
2008-04-14 23:57:44 +02:00
|
|
|
return s->buf[s->len ++];
|
2013-01-16 01:57:58 +01:00
|
|
|
} else {
|
2008-04-14 23:57:44 +02:00
|
|
|
return 0xff;
|
2013-01-16 01:57:58 +01:00
|
|
|
}
|
2008-04-14 23:57:44 +02:00
|
|
|
}
|
|
|
|
|
2011-12-05 03:28:27 +01:00
|
|
|
static int tmp105_tx(I2CSlave *i2c, uint8_t data)
|
2008-04-14 23:57:44 +02:00
|
|
|
{
|
2013-01-16 01:57:58 +01:00
|
|
|
TMP105State *s = TMP105(i2c);
|
2008-04-14 23:57:44 +02:00
|
|
|
|
2013-01-16 01:57:56 +01:00
|
|
|
if (s->len == 0) {
|
2008-04-14 23:57:44 +02:00
|
|
|
s->pointer = data;
|
2013-01-16 01:57:56 +01:00
|
|
|
s->len++;
|
|
|
|
} else {
|
|
|
|
if (s->len <= 2) {
|
2008-04-14 23:57:44 +02:00
|
|
|
s->buf[s->len - 1] = data;
|
2013-01-16 01:57:56 +01:00
|
|
|
}
|
|
|
|
s->len++;
|
2008-04-14 23:57:44 +02:00
|
|
|
tmp105_write(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-09 12:40:20 +01:00
|
|
|
static int tmp105_event(I2CSlave *i2c, enum i2c_event event)
|
2008-04-14 23:57:44 +02:00
|
|
|
{
|
2013-01-16 01:57:58 +01:00
|
|
|
TMP105State *s = TMP105(i2c);
|
2008-04-14 23:57:44 +02:00
|
|
|
|
2013-01-16 01:57:58 +01:00
|
|
|
if (event == I2C_START_RECV) {
|
2008-04-14 23:57:44 +02:00
|
|
|
tmp105_read(s);
|
2013-01-16 01:57:58 +01:00
|
|
|
}
|
2008-04-14 23:57:44 +02:00
|
|
|
|
|
|
|
s->len = 0;
|
2017-01-09 12:40:20 +01:00
|
|
|
return 0;
|
2008-04-14 23:57:44 +02:00
|
|
|
}
|
|
|
|
|
2009-09-29 22:48:38 +02:00
|
|
|
static int tmp105_post_load(void *opaque, int version_id)
|
2008-04-14 23:57:44 +02:00
|
|
|
{
|
2009-09-29 22:48:38 +02:00
|
|
|
TMP105State *s = opaque;
|
2008-04-14 23:57:44 +02:00
|
|
|
|
2010-05-15 14:31:27 +02:00
|
|
|
s->faults = tmp105_faultq[(s->config >> 3) & 3]; /* F */
|
|
|
|
|
2008-04-14 23:57:44 +02:00
|
|
|
tmp105_interrupt_update(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-29 22:48:38 +02:00
|
|
|
static const VMStateDescription vmstate_tmp105 = {
|
|
|
|
.name = "TMP105",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.post_load = tmp105_post_load,
|
2014-05-13 17:09:35 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2009-09-29 22:48:38 +02:00
|
|
|
VMSTATE_UINT8(len, TMP105State),
|
|
|
|
VMSTATE_UINT8_ARRAY(buf, TMP105State, 2),
|
|
|
|
VMSTATE_UINT8(pointer, TMP105State),
|
|
|
|
VMSTATE_UINT8(config, TMP105State),
|
|
|
|
VMSTATE_INT16(temperature, TMP105State),
|
|
|
|
VMSTATE_INT16_ARRAY(limit, TMP105State, 2),
|
|
|
|
VMSTATE_UINT8(alarm, TMP105State),
|
|
|
|
VMSTATE_I2C_SLAVE(i2c, TMP105State),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-05 03:28:27 +01:00
|
|
|
static void tmp105_reset(I2CSlave *i2c)
|
2008-04-14 23:57:44 +02:00
|
|
|
{
|
2013-01-16 01:57:58 +01:00
|
|
|
TMP105State *s = TMP105(i2c);
|
2008-04-14 23:57:44 +02:00
|
|
|
|
|
|
|
s->temperature = 0;
|
|
|
|
s->pointer = 0;
|
|
|
|
s->config = 0;
|
|
|
|
s->faults = tmp105_faultq[(s->config >> 3) & 3];
|
|
|
|
s->alarm = 0;
|
|
|
|
|
|
|
|
tmp105_interrupt_update(s);
|
|
|
|
}
|
|
|
|
|
2018-05-28 16:45:07 +02:00
|
|
|
static void tmp105_realize(DeviceState *dev, Error **errp)
|
2008-04-14 23:57:44 +02:00
|
|
|
{
|
2018-05-28 16:45:07 +02:00
|
|
|
I2CSlave *i2c = I2C_SLAVE(dev);
|
2013-01-16 01:57:58 +01:00
|
|
|
TMP105State *s = TMP105(i2c);
|
2008-04-14 23:57:44 +02:00
|
|
|
|
2009-05-14 23:35:08 +02:00
|
|
|
qdev_init_gpio_out(&i2c->qdev, &s->pin, 1);
|
2008-04-14 23:57:44 +02:00
|
|
|
|
|
|
|
tmp105_reset(&s->i2c);
|
2009-05-14 23:35:08 +02:00
|
|
|
}
|
|
|
|
|
2013-01-16 01:57:59 +01:00
|
|
|
static void tmp105_initfn(Object *obj)
|
|
|
|
{
|
|
|
|
object_property_add(obj, "temperature", "int",
|
|
|
|
tmp105_get_temperature,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 17:29:22 +02:00
|
|
|
tmp105_set_temperature, NULL, NULL);
|
2013-01-16 01:57:59 +01:00
|
|
|
}
|
|
|
|
|
2011-12-05 03:39:20 +01:00
|
|
|
static void tmp105_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-05 03:39:20 +01:00
|
|
|
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
|
|
|
|
|
2018-05-28 16:45:07 +02:00
|
|
|
dc->realize = tmp105_realize;
|
2011-12-05 03:39:20 +01:00
|
|
|
k->event = tmp105_event;
|
|
|
|
k->recv = tmp105_rx;
|
|
|
|
k->send = tmp105_tx;
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->vmsd = &vmstate_tmp105;
|
2011-12-05 03:39:20 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo tmp105_info = {
|
2013-01-16 01:57:58 +01:00
|
|
|
.name = TYPE_TMP105,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_I2C_SLAVE,
|
|
|
|
.instance_size = sizeof(TMP105State),
|
2013-01-16 01:57:59 +01:00
|
|
|
.instance_init = tmp105_initfn,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = tmp105_class_init,
|
2009-05-14 23:35:08 +02:00
|
|
|
};
|
2008-04-14 23:57:44 +02:00
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void tmp105_register_types(void)
|
2009-05-14 23:35:08 +02:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&tmp105_info);
|
2008-04-14 23:57:44 +02:00
|
|
|
}
|
2009-05-14 23:35:08 +02:00
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
type_init(tmp105_register_types)
|