Changeset View
Changeset View
Standalone View
Standalone View
sys/arm/allwinner/aw_usbphy.c
Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | |||||
DEFINE_CLASS_1(awusbphy_phynode, awusbphy_phynode_class, awusbphy_phynode_methods, | DEFINE_CLASS_1(awusbphy_phynode, awusbphy_phynode_class, awusbphy_phynode_methods, | ||||
0, phynode_class); | 0, phynode_class); | ||||
#define RD4(res, o) bus_read_4(res, (o)) | #define RD4(res, o) bus_read_4(res, (o)) | ||||
#define WR4(res, o, v) bus_write_4(res, (o), (v)) | #define WR4(res, o, v) bus_write_4(res, (o), (v)) | ||||
#define CLR4(res, o, m) WR4(res, o, RD4(res, o) & ~(m)) | #define CLR4(res, o, m) WR4(res, o, RD4(res, o) & ~(m)) | ||||
#define SET4(res, o, m) WR4(res, o, RD4(res, o) | (m)) | #define SET4(res, o, m) WR4(res, o, RD4(res, o) | (m)) | ||||
#define PHY_CSR 0x00 | |||||
#define ID_PULLUP_EN (1 << 17) | |||||
#define DPDM_PULLUP_EN (1 << 16) | |||||
#define FORCE_ID (0x3 << 14) | |||||
#define FORCE_ID_SHIFT 14 | |||||
#define FORCE_ID_LOW 2 | |||||
#define FORCE_VBUS_VALID (0x3 << 12) | |||||
#define FORCE_VBUS_VALID_SHIFT 12 | |||||
#define FORCE_VBUS_VALID_HIGH 3 | |||||
#define VBUS_CHANGE_DET (1 << 6) | |||||
#define ID_CHANGE_DET (1 << 5) | |||||
#define DPDM_CHANGE_DET (1 << 4) | |||||
#define OTG_PHY_CFG 0x20 | #define OTG_PHY_CFG 0x20 | ||||
#define OTG_PHY_ROUTE_OTG (1 << 0) | #define OTG_PHY_ROUTE_OTG (1 << 0) | ||||
#define PMU_IRQ_ENABLE 0x00 | #define PMU_IRQ_ENABLE 0x00 | ||||
#define PMU_AHB_INCR8 (1 << 10) | #define PMU_AHB_INCR8 (1 << 10) | ||||
#define PMU_AHB_INCR4 (1 << 9) | #define PMU_AHB_INCR4 (1 << 9) | ||||
#define PMU_AHB_INCRX_ALIGN (1 << 8) | #define PMU_AHB_INCRX_ALIGN (1 << 8) | ||||
#define PMU_ULPI_BYPASS (1 << 0) | #define PMU_ULPI_BYPASS (1 << 0) | ||||
#define PMU_UNK_H3 0x10 | #define PMU_UNK_H3 0x10 | ||||
Show All 17 Lines | |||||
} | } | ||||
static int | static int | ||||
awusbphy_init(device_t dev) | awusbphy_init(device_t dev) | ||||
{ | { | ||||
struct awusbphy_softc *sc; | struct awusbphy_softc *sc; | ||||
phandle_t node; | phandle_t node; | ||||
char pname[20]; | char pname[20]; | ||||
uint32_t val; | |||||
int error, off, rid; | int error, off, rid; | ||||
regulator_t reg; | regulator_t reg; | ||||
hwreset_t rst; | hwreset_t rst; | ||||
clk_t clk; | clk_t clk; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
node = ofw_bus_get_node(dev); | node = ofw_bus_get_node(dev); | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | for (off = 0; off < sc->phy_conf->num_phys; off++) { | ||||
sc->pmu[off] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, | sc->pmu[off] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, | ||||
RF_ACTIVE); | RF_ACTIVE); | ||||
if (sc->pmu[off] == NULL) { | if (sc->pmu[off] == NULL) { | ||||
device_printf(dev, "Cannot allocate resource\n"); | device_printf(dev, "Cannot allocate resource\n"); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
} | } | ||||
/* Enable OTG PHY for host mode */ | |||||
val = bus_read_4(sc->phy_ctrl, PHY_CSR); | |||||
val &= ~(VBUS_CHANGE_DET | ID_CHANGE_DET | DPDM_CHANGE_DET); | |||||
val |= (ID_PULLUP_EN | DPDM_PULLUP_EN); | |||||
val &= ~FORCE_ID; | |||||
val |= (FORCE_ID_LOW << FORCE_ID_SHIFT); | |||||
val &= ~FORCE_VBUS_VALID; | |||||
val |= (FORCE_VBUS_VALID_HIGH << FORCE_VBUS_VALID_SHIFT); | |||||
bus_write_4(sc->phy_ctrl, PHY_CSR, val); | |||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
awusbphy_vbus_detect(device_t dev, int *val) | awusbphy_vbus_detect(device_t dev, int *val) | ||||
{ | { | ||||
struct awusbphy_softc *sc; | struct awusbphy_softc *sc; | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | awusbphy_attach(device_t dev) | ||||
} | } | ||||
return (error); | return (error); | ||||
} | } | ||||
static device_method_t awusbphy_methods[] = { | static device_method_t awusbphy_methods[] = { | ||||
/* Device interface */ | /* Device interface */ | ||||
DEVMETHOD(device_probe, awusbphy_probe), | DEVMETHOD(device_probe, awusbphy_probe), | ||||
DEVMETHOD(device_attach, awusbphy_attach), | DEVMETHOD(device_attach, awusbphy_attach), | ||||
hselasky: Should the device_resume and device_suspend methods do anything? | |||||
Not Done Inline ActionsSuspend/resume not yet supported on the Allwinner port. jmcneill: Suspend/resume not yet supported on the Allwinner port. | |||||
DEVMETHOD_END | DEVMETHOD_END | ||||
}; | }; | ||||
static driver_t awusbphy_driver = { | static driver_t awusbphy_driver = { | ||||
"awusbphy", | "awusbphy", | ||||
Not Done Inline ActionsI like better when you initialize by record: driver = { Current code is OK. Same with other drivers in this patch. hselasky: I like better when you initialize by record:
driver = {
.name = "",
.xxxx
.size = ....
}… | |||||
Not Done Inline ActionsAgree, but following style used in the rest of sys/arm/allwinner. Would it be alright if I changed musb_otg_allwinner.c to use C99 initializers and left awusbphy.c as-is? jmcneill: Agree, but following style used in the rest of sys/arm/allwinner. Would it be alright if I… | |||||
awusbphy_methods, | awusbphy_methods, | ||||
sizeof(struct awusbphy_softc) | sizeof(struct awusbphy_softc) | ||||
}; | }; | ||||
static devclass_t awusbphy_devclass; | static devclass_t awusbphy_devclass; | ||||
/* aw_usbphy needs to come up after regulators/gpio/etc, but before ehci/ohci */ | /* aw_usbphy needs to come up after regulators/gpio/etc, but before ehci/ohci */ | ||||
EARLY_DRIVER_MODULE(awusbphy, simplebus, awusbphy_driver, awusbphy_devclass, | EARLY_DRIVER_MODULE(awusbphy, simplebus, awusbphy_driver, awusbphy_devclass, | ||||
0, 0, BUS_PASS_SUPPORTDEV + BUS_PASS_ORDER_MIDDLE); | 0, 0, BUS_PASS_SUPPORTDEV + BUS_PASS_ORDER_MIDDLE); | ||||
MODULE_VERSION(awusbphy, 1); | MODULE_VERSION(awusbphy, 1); |
Should the device_resume and device_suspend methods do anything?