[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 02/14] hw/i2c/versatile_i2c: Add definitions for register addr
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v3 02/14] hw/i2c/versatile_i2c: Add definitions for register addresses |
Date: |
Wed, 17 Jun 2020 09:25:27 +0200 |
Use self-explicit definitions instead of magic values.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/i2c/versatile_i2c.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/hw/i2c/versatile_i2c.c b/hw/i2c/versatile_i2c.c
index 1ac2a6f59a..040139d701 100644
--- a/hw/i2c/versatile_i2c.c
+++ b/hw/i2c/versatile_i2c.c
@@ -24,6 +24,7 @@
#include "qemu/osdep.h"
#include "hw/sysbus.h"
#include "hw/i2c/bitbang_i2c.h"
+#include "hw/registerfields.h"
#include "qemu/log.h"
#include "qemu/module.h"
@@ -40,14 +41,19 @@ typedef struct VersatileI2CState {
int in;
} VersatileI2CState;
+REG32(CONTROL_GET, 0)
+REG32(CONTROL_SET, 0)
+REG32(CONTROL_CLR, 4)
+
static uint64_t versatile_i2c_read(void *opaque, hwaddr offset,
unsigned size)
{
VersatileI2CState *s = (VersatileI2CState *)opaque;
- if (offset == 0) {
+ switch (offset) {
+ case A_CONTROL_SET:
return (s->out & 1) | (s->in << 1);
- } else {
+ default:
qemu_log_mask(LOG_GUEST_ERROR,
"%s: Bad offset 0x%x\n", __func__, (int)offset);
return -1;
@@ -60,10 +66,10 @@ static void versatile_i2c_write(void *opaque, hwaddr offset,
VersatileI2CState *s = (VersatileI2CState *)opaque;
switch (offset) {
- case 0:
+ case A_CONTROL_SET:
s->out |= value & 3;
break;
- case 4:
+ case A_CONTROL_CLR:
s->out &= ~value;
break;
default:
--
2.21.3
- [PATCH v3 00/14] mps2: Add few more peripherals, Philippe Mathieu-Daudé, 2020/06/17
- [PATCH v3 01/14] hw/watchdog/cmsdk-apb-watchdog: Add trace event for lock status, Philippe Mathieu-Daudé, 2020/06/17
- [PATCH v3 02/14] hw/i2c/versatile_i2c: Add definitions for register addresses,
Philippe Mathieu-Daudé <=
- [PATCH v3 03/14] hw/i2c/versatile_i2c: Add SCL/SDA definitions, Philippe Mathieu-Daudé, 2020/06/17
- [PATCH v3 05/14] hw/arm: Use TYPE_VERSATILE_I2C instead of hardcoded string, Philippe Mathieu-Daudé, 2020/06/17
- [PATCH v3 04/14] hw/i2c: Add header for ARM SBCon two-wire serial bus interface, Philippe Mathieu-Daudé, 2020/06/17
- [PATCH v3 06/14] hw/arm/mps2: Document CMSDK/FPGA APB subsystem sections, Philippe Mathieu-Daudé, 2020/06/17
- [PATCH v3 08/14] hw/arm/mps2: Add CMSDK APB watchdog device, Philippe Mathieu-Daudé, 2020/06/17
- [PATCH v3 09/14] hw/arm/mps2: Add CMSDK AHB GPIO peripherals as unimplemented devices, Philippe Mathieu-Daudé, 2020/06/17
- [PATCH v3 07/14] hw/arm/mps2: Rename CMSDK AHB peripheral region, Philippe Mathieu-Daudé, 2020/06/17
- [PATCH v3 10/14] hw/arm/mps2: Map the FPGA I/O block, Philippe Mathieu-Daudé, 2020/06/17
- [PATCH v3 12/14] hw/arm/mps2: Add I2C devices, Philippe Mathieu-Daudé, 2020/06/17
- [PATCH v3 13/14] hw/arm/mps2: Add audio I2S interface as unimplemented device, Philippe Mathieu-Daudé, 2020/06/17