Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/bhnd/cores/chipc/chipc_cfi.c
| Show All 34 Lines | |||||
| #include <sys/kernel.h> | #include <sys/kernel.h> | ||||
| #include <sys/module.h> | #include <sys/module.h> | ||||
| #include <sys/bus.h> | #include <sys/bus.h> | ||||
| #include <sys/rman.h> | #include <sys/rman.h> | ||||
| #include <sys/conf.h> | #include <sys/conf.h> | ||||
| #include <machine/bus.h> | #include <machine/bus.h> | ||||
| #include <dev/bhnd/bhnd_debug.h> | |||||
| #include <dev/cfi/cfi_var.h> | #include <dev/cfi/cfi_var.h> | ||||
| #include "bhnd_chipc_if.h" | #include "bhnd_chipc_if.h" | ||||
| #include "chipc_slicer.h" | |||||
| #include "chipcreg.h" | #include "chipcreg.h" | ||||
| #include "chipcvar.h" | #include "chipcvar.h" | ||||
| #include "chipc_slicer.h" | |||||
| /* | |||||
| * **************************** PROTOTYPES **************************** | |||||
| */ | |||||
| static void chipc_cfi_identify(driver_t *driver, device_t parent); | |||||
| static int chipc_cfi_probe(device_t dev); | |||||
| static int chipc_cfi_attach(device_t dev); | |||||
| /* | |||||
| * **************************** IMPLEMENTATION ************************ | |||||
| */ | |||||
| static void | |||||
| chipc_cfi_identify(driver_t *driver, device_t parent) | |||||
| { | |||||
| struct chipc_caps *caps; | |||||
| if (device_find_child(parent, cfi_driver_name, -1) != NULL) | |||||
| return; | |||||
| caps = BHND_CHIPC_GET_CAPS(parent); | |||||
| if (caps == NULL) | |||||
| return; | |||||
| if (caps->flash_type != CHIPC_PFLASH_CFI) | |||||
| return; | |||||
| BUS_ADD_CHILD(parent, 0, cfi_driver_name, -1); | |||||
| return; | |||||
| } | |||||
| static int | static int | ||||
| chipc_cfi_probe(device_t dev) | chipc_cfi_probe(device_t dev) | ||||
| { | { | ||||
| int error; | |||||
| int enabled; | |||||
| int byteswap; | |||||
| uint32_t flash_config; | |||||
| struct cfi_softc *sc; | struct cfi_softc *sc; | ||||
| int error; | |||||
| sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
| flash_config = BHND_CHIPC_GET_FLASH_CFG(device_get_parent(dev)); | |||||
| enabled = (flash_config & CHIPC_CF_EN); | |||||
| byteswap = (flash_config & CHIPC_CF_BS); | |||||
| if (enabled == 0) | |||||
| device_disable(dev); | |||||
| BHND_DEBUG_DEV(dev, "trying attach flash enabled=%d swapbytes=%d", | |||||
| enabled, byteswap); | |||||
| sc->sc_width = 0; | sc->sc_width = 0; | ||||
| error = cfi_probe(dev); | if ((error = cfi_probe(dev)) > 0) | ||||
| if (error == 0) | |||||
| device_set_desc(dev, "ChipCommon CFI"); | |||||
| return (error); | return (error); | ||||
| device_set_desc(dev, "Broadcom ChipCommon CFI"); | |||||
| return (error); | |||||
| } | } | ||||
| static int | static int | ||||
| chipc_cfi_attach(device_t dev) | chipc_cfi_attach(device_t dev) | ||||
| { | { | ||||
| int error; | chipc_register_slicer(CHIPC_PFLASH_CFI); | ||||
| return (cfi_attach(dev)); | |||||
| error = cfi_attach(dev); | |||||
| if (error) | |||||
| return (error); | |||||
| flash_register_slicer(chipc_slicer_cfi); | |||||
| return (0); | |||||
| } | } | ||||
| static device_method_t chipc_cfi_methods[] = { | static device_method_t chipc_cfi_methods[] = { | ||||
| /* device interface */ | /* device interface */ | ||||
| DEVMETHOD(device_identify, chipc_cfi_identify), | |||||
| DEVMETHOD(device_probe, chipc_cfi_probe), | DEVMETHOD(device_probe, chipc_cfi_probe), | ||||
| DEVMETHOD(device_attach, chipc_cfi_attach), | DEVMETHOD(device_attach, chipc_cfi_attach), | ||||
| DEVMETHOD(device_detach, cfi_detach), | DEVMETHOD(device_detach, cfi_detach), | ||||
| {0, 0} | {0, 0} | ||||
| }; | }; | ||||
| static driver_t chipc_cfi_driver = { | static driver_t chipc_cfi_driver = { | ||||
| cfi_driver_name, | cfi_driver_name, | ||||
| chipc_cfi_methods, | chipc_cfi_methods, | ||||
| sizeof(struct cfi_softc), | sizeof(struct cfi_softc), | ||||
| }; | }; | ||||
| DRIVER_MODULE(cfi, bhnd_chipc, chipc_cfi_driver, cfi_devclass, 0, 0); | DRIVER_MODULE(cfi, bhnd_chipc, chipc_cfi_driver, cfi_devclass, 0, 0); | ||||