mirror of
https://github.com/qemu/qemu.git
synced 2025-07-27 12:20:07 +00:00

-----BEGIN PGP SIGNATURE----- iQJGBAABCAAwFiEEzS913cjjpNwuT1Fz8ww4vT8vvjwFAl9b0MsSHGxhdXJlbnRA dml2aWVyLmV1AAoJEPMMOL0/L748UH0QAIQYMn0U5eMWREg+DOEEj2n/6h04lTeE K93RsaQ9OsB0cZvwZ08sGoHI6FyfPR8S5yFe5as1ykGcGyO4vNwqxxPeRvqSfgwX 2nkldYwgkOLYsjOD+1G16f/TGJ3MWbUxyn6ta/cSVg+BhbSvMHT3SXTLQ3PB7Lvf 1j3Y3B0BUBAjPh1sNIvBkEV1ZGlV9tqu+XviUf4hfqZOVSTsSb7prtuGVYz9GsH2 RxEcPXQKNWei2eQET4l8otcBpV3dz0D/6sap8nAP8pz0VARn7hJXIn5f8USFHHfg LMWbXrB9I2bjqSmRqhGofxhGMaH2uKQvpv46MyCDel7eMENNj6F+ER2a+7J8Apy8 vVWYg8qVA85rfxQcb7nHuDrLQiD/C1o1uZcV1O/Mwkm7typUcpPn00pQLxhEDf9O xta1/EU8X+7kgTIKWMwpC0HwponOfHiG1TCyzbQ91FiTb/peeOzejTQi88YRNZFV NEg1XIo79Q/no05F/j3nrju2ESzBQTA1F+Jms8aI6Q40nXPaXEjg7IA510os7Py7 uCEtoQ7qEM4lHfuSl67AR2J/NVWlWbZDsjqhxiMsYLR85rkARIf/7fsVIi9ELKOQ AYZdfA/LebovUcp9kDfYHPvDzifGMmv2ppD3mcZWhGuuQTJ06sRMPxQbUF6LBVMc 64FEl8o3wFgv =/CqY -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/vivier2/tags/trivial-branch-for-5.2-pull-request' into staging trivial patches pull request 20200911 # gpg: Signature made Fri 11 Sep 2020 20:32:27 BST # gpg: using RSA key CD2F75DDC8E3A4DC2E4F5173F30C38BD3F2FBE3C # gpg: issuer "laurent@vivier.eu" # gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>" [full] # gpg: aka "Laurent Vivier <laurent@vivier.eu>" [full] # gpg: aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>" [full] # Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F 5173 F30C 38BD 3F2F BE3C * remotes/vivier2/tags/trivial-branch-for-5.2-pull-request: target/i386/kvm: Add missing fallthrough comment util/hexdump: Reorder qemu_hexdump() arguments util/hexdump: Convert to take a void pointer argument hw/arm/pxa2xx: Add missing fallthrough comment target/i386/kvm: Rename host_tsx_blacklisted() as host_tsx_broken() test-vmstate: remove unnecessary code in match_interval_mapping_node hw: hyperv: vmbus: Fix 32bit compilation kconfig: fix comment referring to old Makefiles meson.build: tweak sdl-image error message hw/net/e1000e: Remove duplicated write handler for FLSWDATA register hw/net/e1000e: Remove overwritten read handler for STATUS register Makefile: Skip the meson subdir in cscope/TAGS/ctags Makefile: Drop extra phony cscope hw/gpio/max7310: Replace disabled printf() by qemu_log_mask(UNIMP) hw/gpio/omap_gpio: Replace fprintf() by qemu_log_mask(GUEST_ERROR) hw/acpi/tco: Remove unused definitions hw/isa/isa-bus: Replace hw_error() by assert() hw/mips/fuloong2e: Convert pointless error message to an assert() Signed-off-by: Peter Maydell <peter.maydell@linaro.org> # Conflicts: # net/colo-compare.c
224 lines
5.2 KiB
C
224 lines
5.2 KiB
C
/*
|
|
* MAX7310 8-port GPIO expansion chip.
|
|
*
|
|
* Copyright (c) 2006 Openedhand Ltd.
|
|
* Written by Andrzej Zaborowski <balrog@zabor.org>
|
|
*
|
|
* This file is licensed under GNU GPL.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "hw/hw.h"
|
|
#include "hw/i2c/i2c.h"
|
|
#include "hw/hw.h"
|
|
#include "hw/irq.h"
|
|
#include "migration/vmstate.h"
|
|
#include "qemu/log.h"
|
|
#include "qemu/module.h"
|
|
#include "qom/object.h"
|
|
|
|
#define TYPE_MAX7310 "max7310"
|
|
typedef struct MAX7310State MAX7310State;
|
|
DECLARE_INSTANCE_CHECKER(MAX7310State, MAX7310,
|
|
TYPE_MAX7310)
|
|
|
|
struct MAX7310State {
|
|
I2CSlave parent_obj;
|
|
|
|
int i2c_command_byte;
|
|
int len;
|
|
|
|
uint8_t level;
|
|
uint8_t direction;
|
|
uint8_t polarity;
|
|
uint8_t status;
|
|
uint8_t command;
|
|
qemu_irq handler[8];
|
|
qemu_irq *gpio_in;
|
|
};
|
|
|
|
static void max7310_reset(DeviceState *dev)
|
|
{
|
|
MAX7310State *s = MAX7310(dev);
|
|
|
|
s->level &= s->direction;
|
|
s->direction = 0xff;
|
|
s->polarity = 0xf0;
|
|
s->status = 0x01;
|
|
s->command = 0x00;
|
|
}
|
|
|
|
static uint8_t max7310_rx(I2CSlave *i2c)
|
|
{
|
|
MAX7310State *s = MAX7310(i2c);
|
|
|
|
switch (s->command) {
|
|
case 0x00: /* Input port */
|
|
return s->level ^ s->polarity;
|
|
|
|
case 0x01: /* Output port */
|
|
return s->level & ~s->direction;
|
|
|
|
case 0x02: /* Polarity inversion */
|
|
return s->polarity;
|
|
|
|
case 0x03: /* Configuration */
|
|
return s->direction;
|
|
|
|
case 0x04: /* Timeout */
|
|
return s->status;
|
|
|
|
case 0xff: /* Reserved */
|
|
return 0xff;
|
|
|
|
default:
|
|
qemu_log_mask(LOG_UNIMP, "%s: Unsupported register 0x02%" PRIx8 "\n",
|
|
__func__, s->command);
|
|
break;
|
|
}
|
|
return 0xff;
|
|
}
|
|
|
|
static int max7310_tx(I2CSlave *i2c, uint8_t data)
|
|
{
|
|
MAX7310State *s = MAX7310(i2c);
|
|
uint8_t diff;
|
|
int line;
|
|
|
|
if (s->len ++ > 1) {
|
|
#ifdef VERBOSE
|
|
printf("%s: message too long (%i bytes)\n", __func__, s->len);
|
|
#endif
|
|
return 1;
|
|
}
|
|
|
|
if (s->i2c_command_byte) {
|
|
s->command = data;
|
|
s->i2c_command_byte = 0;
|
|
return 0;
|
|
}
|
|
|
|
switch (s->command) {
|
|
case 0x01: /* Output port */
|
|
for (diff = (data ^ s->level) & ~s->direction; diff;
|
|
diff &= ~(1 << line)) {
|
|
line = ctz32(diff);
|
|
if (s->handler[line])
|
|
qemu_set_irq(s->handler[line], (data >> line) & 1);
|
|
}
|
|
s->level = (s->level & s->direction) | (data & ~s->direction);
|
|
break;
|
|
|
|
case 0x02: /* Polarity inversion */
|
|
s->polarity = data;
|
|
break;
|
|
|
|
case 0x03: /* Configuration */
|
|
s->level &= ~(s->direction ^ data);
|
|
s->direction = data;
|
|
break;
|
|
|
|
case 0x04: /* Timeout */
|
|
s->status = data;
|
|
break;
|
|
|
|
case 0x00: /* Input port - ignore writes */
|
|
break;
|
|
default:
|
|
qemu_log_mask(LOG_UNIMP, "%s: Unsupported register 0x02%" PRIx8 "\n",
|
|
__func__, s->command);
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int max7310_event(I2CSlave *i2c, enum i2c_event event)
|
|
{
|
|
MAX7310State *s = MAX7310(i2c);
|
|
s->len = 0;
|
|
|
|
switch (event) {
|
|
case I2C_START_SEND:
|
|
s->i2c_command_byte = 1;
|
|
break;
|
|
case I2C_FINISH:
|
|
#ifdef VERBOSE
|
|
if (s->len == 1)
|
|
printf("%s: message too short (%i bytes)\n", __func__, s->len);
|
|
#endif
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const VMStateDescription vmstate_max7310 = {
|
|
.name = "max7310",
|
|
.version_id = 0,
|
|
.minimum_version_id = 0,
|
|
.fields = (VMStateField[]) {
|
|
VMSTATE_INT32(i2c_command_byte, MAX7310State),
|
|
VMSTATE_INT32(len, MAX7310State),
|
|
VMSTATE_UINT8(level, MAX7310State),
|
|
VMSTATE_UINT8(direction, MAX7310State),
|
|
VMSTATE_UINT8(polarity, MAX7310State),
|
|
VMSTATE_UINT8(status, MAX7310State),
|
|
VMSTATE_UINT8(command, MAX7310State),
|
|
VMSTATE_I2C_SLAVE(parent_obj, MAX7310State),
|
|
VMSTATE_END_OF_LIST()
|
|
}
|
|
};
|
|
|
|
static void max7310_gpio_set(void *opaque, int line, int level)
|
|
{
|
|
MAX7310State *s = (MAX7310State *) opaque;
|
|
if (line >= ARRAY_SIZE(s->handler) || line < 0)
|
|
hw_error("bad GPIO line");
|
|
|
|
if (level)
|
|
s->level |= s->direction & (1 << line);
|
|
else
|
|
s->level &= ~(s->direction & (1 << line));
|
|
}
|
|
|
|
/* MAX7310 is SMBus-compatible (can be used with only SMBus protocols),
|
|
* but also accepts sequences that are not SMBus so return an I2C device. */
|
|
static void max7310_realize(DeviceState *dev, Error **errp)
|
|
{
|
|
I2CSlave *i2c = I2C_SLAVE(dev);
|
|
MAX7310State *s = MAX7310(dev);
|
|
|
|
qdev_init_gpio_in(&i2c->qdev, max7310_gpio_set, 8);
|
|
qdev_init_gpio_out(&i2c->qdev, s->handler, 8);
|
|
}
|
|
|
|
static void max7310_class_init(ObjectClass *klass, void *data)
|
|
{
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
|
|
|
|
dc->realize = max7310_realize;
|
|
k->event = max7310_event;
|
|
k->recv = max7310_rx;
|
|
k->send = max7310_tx;
|
|
dc->reset = max7310_reset;
|
|
dc->vmsd = &vmstate_max7310;
|
|
}
|
|
|
|
static const TypeInfo max7310_info = {
|
|
.name = TYPE_MAX7310,
|
|
.parent = TYPE_I2C_SLAVE,
|
|
.instance_size = sizeof(MAX7310State),
|
|
.class_init = max7310_class_init,
|
|
};
|
|
|
|
static void max7310_register_types(void)
|
|
{
|
|
type_register_static(&max7310_info);
|
|
}
|
|
|
|
type_init(max7310_register_types)
|