108 lines
3.0 KiB
C
108 lines
3.0 KiB
C
/*
|
|
* Apple S5L8950X USB PHY (minimal SecureROM-facing model)
|
|
*
|
|
* The SecureROM samples bit 0 of register 0x28 to determine whether a USB
|
|
* cable is present before honoring the recovery-button GPIO and entering DFU.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "hw/arm/s5l8950x.h"
|
|
#include "hw/core/qdev-properties.h"
|
|
#include "hw/core/sysbus.h"
|
|
#include "qom/object.h"
|
|
|
|
#define S5L8950X_USB_PHY_REGION_SIZE 0x1000
|
|
#define S5L8950X_USB_PHY_NUM_REGS \
|
|
(S5L8950X_USB_PHY_REGION_SIZE / sizeof(uint32_t))
|
|
#define S5L8950X_USB_PHY_CABLE_STATUS 0x28
|
|
#define S5L8950X_USB_PHY_CABLE_PRESENT BIT(0)
|
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(S5L8950XUSBPHYState, S5L8950X_USB_PHY)
|
|
|
|
struct S5L8950XUSBPHYState {
|
|
SysBusDevice parent_obj;
|
|
MemoryRegion iomem;
|
|
uint32_t regs[S5L8950X_USB_PHY_NUM_REGS];
|
|
bool cable_connected;
|
|
};
|
|
|
|
static uint64_t s5l8950x_usb_phy_read(void *opaque, hwaddr offset,
|
|
unsigned size)
|
|
{
|
|
S5L8950XUSBPHYState *s = opaque;
|
|
uint32_t value = s->regs[offset / sizeof(uint32_t)];
|
|
|
|
if (offset == S5L8950X_USB_PHY_CABLE_STATUS && s->cable_connected) {
|
|
value |= S5L8950X_USB_PHY_CABLE_PRESENT;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
static void s5l8950x_usb_phy_write(void *opaque, hwaddr offset,
|
|
uint64_t value, unsigned size)
|
|
{
|
|
S5L8950XUSBPHYState *s = opaque;
|
|
|
|
s->regs[offset / sizeof(uint32_t)] = value;
|
|
}
|
|
|
|
static const MemoryRegionOps s5l8950x_usb_phy_ops = {
|
|
.read = s5l8950x_usb_phy_read,
|
|
.write = s5l8950x_usb_phy_write,
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
.valid = {
|
|
.min_access_size = 4,
|
|
.max_access_size = 4,
|
|
},
|
|
.impl = {
|
|
.min_access_size = 4,
|
|
.max_access_size = 4,
|
|
},
|
|
};
|
|
|
|
static const Property s5l8950x_usb_phy_properties[] = {
|
|
DEFINE_PROP_BOOL("cable-connected", S5L8950XUSBPHYState,
|
|
cable_connected, false),
|
|
};
|
|
|
|
static void s5l8950x_usb_phy_reset(DeviceState *dev)
|
|
{
|
|
S5L8950XUSBPHYState *s = S5L8950X_USB_PHY(dev);
|
|
|
|
memset(s->regs, 0, sizeof(s->regs));
|
|
}
|
|
|
|
static void s5l8950x_usb_phy_init(Object *obj)
|
|
{
|
|
S5L8950XUSBPHYState *s = S5L8950X_USB_PHY(obj);
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
|
|
|
memory_region_init_io(&s->iomem, obj, &s5l8950x_usb_phy_ops, s,
|
|
TYPE_S5L8950X_USB_PHY,
|
|
S5L8950X_USB_PHY_REGION_SIZE);
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
|
}
|
|
|
|
static void s5l8950x_usb_phy_class_init(ObjectClass *klass, const void *data)
|
|
{
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
device_class_set_legacy_reset(dc, s5l8950x_usb_phy_reset);
|
|
device_class_set_props(dc, s5l8950x_usb_phy_properties);
|
|
}
|
|
|
|
static const TypeInfo s5l8950x_usb_phy_info = {
|
|
.name = TYPE_S5L8950X_USB_PHY,
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
.instance_size = sizeof(S5L8950XUSBPHYState),
|
|
.instance_init = s5l8950x_usb_phy_init,
|
|
.class_init = s5l8950x_usb_phy_class_init,
|
|
};
|
|
|
|
static void s5l8950x_usb_phy_register_types(void)
|
|
{
|
|
type_register_static(&s5l8950x_usb_phy_info);
|
|
}
|
|
|
|
type_init(s5l8950x_usb_phy_register_types)
|