Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/bhnd/cores/chipc/chipc_slicer.c
| Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
| #include <dev/bhnd/bhnd_debug.h> | #include <dev/bhnd/bhnd_debug.h> | ||||
| #include "chipc_slicer.h" | #include "chipc_slicer.h" | ||||
| #include <dev/cfi/cfi_var.h> | #include <dev/cfi/cfi_var.h> | ||||
| #include "chipc_spi.h" | #include "chipc_spi.h" | ||||
| static int chipc_slicer_walk(device_t dev, struct resource* res, | static int chipc_slicer_walk(device_t dev, struct resource *res, | ||||
| struct flash_slice *slices, int *nslices); | struct flash_slice *slices, int *nslices); | ||||
| void | |||||
| chipc_register_slicer(chipc_flash flash_type) | |||||
| { | |||||
| switch (flash_type) { | |||||
| case CHIPC_SFLASH_AT: | |||||
| case CHIPC_SFLASH_ST: | |||||
| flash_register_slicer(chipc_slicer_spi); | |||||
| break; | |||||
| case CHIPC_PFLASH_CFI: | |||||
| flash_register_slicer(chipc_slicer_cfi); | |||||
| break; | |||||
| default: | |||||
| /* Unsupported */ | |||||
| break; | |||||
| } | |||||
| } | |||||
| int | int | ||||
| chipc_slicer_cfi(device_t dev, struct flash_slice *slices, int *nslices) | chipc_slicer_cfi(device_t dev, struct flash_slice *slices, int *nslices) | ||||
| { | { | ||||
| struct cfi_softc *sc; | struct cfi_softc *sc; | ||||
| device_t parent; | |||||
| if (strcmp("cfi", device_get_name(dev)) != 0) | /* must be CFI flash */ | ||||
| return (0); | if (device_get_devclass(dev) != devclass_find("cfi")) | ||||
| return (ENXIO); | |||||
| sc = device_get_softc(dev); | /* must be attached to chipc */ | ||||
| if ((parent = device_get_parent(dev)) == NULL) { | |||||
| BHND_ERROR_DEV(dev, "no found ChipCommon device"); | |||||
| return (ENXIO); | |||||
| } | |||||
| if (device_get_devclass(parent) != devclass_find("bhnd_chipc")) { | |||||
| BHND_ERROR_DEV(dev, "no found ChipCommon device"); | |||||
| return (ENXIO); | |||||
| } | |||||
| sc = device_get_softc(dev); | |||||
| return (chipc_slicer_walk(dev, sc->sc_res, slices, nslices)); | return (chipc_slicer_walk(dev, sc->sc_res, slices, nslices)); | ||||
| } | } | ||||
| int | int | ||||
| chipc_slicer_spi(device_t dev, struct flash_slice *slices, int *nslices) | chipc_slicer_spi(device_t dev, struct flash_slice *slices, int *nslices) | ||||
| { | { | ||||
| /* flash(mx25l) <- spibus <- chipc_spi */ | |||||
| device_t spibus; | |||||
| device_t chipc_spi; | |||||
| struct chipc_spi_softc *sc; | struct chipc_spi_softc *sc; | ||||
| device_t chipc, spi, spibus; | |||||
| BHND_DEBUG_DEV(dev, "initting SPI slicer: %s", device_get_name(dev)); | BHND_DEBUG_DEV(dev, "initting SPI slicer: %s", device_get_name(dev)); | ||||
| if (strcmp("mx25l", device_get_name(dev)) != 0) | /* must be SPI-attached flash */ | ||||
| return (EINVAL); | |||||
| spibus = device_get_parent(dev); | spibus = device_get_parent(dev); | ||||
| if (spibus == NULL) { | if (spibus == NULL) { | ||||
| BHND_ERROR_DEV(dev, "no found ChipCommon SPI BUS device"); | BHND_ERROR_DEV(dev, "no found ChipCommon SPI BUS device"); | ||||
| return (EINVAL); | return (ENXIO); | ||||
| } | } | ||||
| chipc_spi = device_get_parent(spibus); | spi = device_get_parent(spibus); | ||||
| if (chipc_spi == NULL) { | if (spi == NULL) { | ||||
| BHND_ERROR_DEV(spibus, "no found ChipCommon SPI device"); | BHND_ERROR_DEV(dev, "no found ChipCommon SPI device"); | ||||
| return (EINVAL); | return (ENXIO); | ||||
| } | } | ||||
| sc = device_get_softc(chipc_spi); | chipc = device_get_parent(spi); | ||||
| if (device_get_devclass(chipc) != devclass_find("bhnd_chipc")) { | |||||
| BHND_ERROR_DEV(dev, "no found ChipCommon device"); | |||||
| return (ENXIO); | |||||
| } | |||||
| return (chipc_slicer_walk(dev, sc->sc_res, slices, nslices)); | sc = device_get_softc(spi); | ||||
| return (chipc_slicer_walk(dev, sc->sc_flash_res, slices, nslices)); | |||||
| } | } | ||||
| /* | /* | ||||
| * Main processing part | * Main processing part | ||||
| */ | */ | ||||
| static int | static int | ||||
| chipc_slicer_walk(device_t dev, struct resource* res, | chipc_slicer_walk(device_t dev, struct resource *res, | ||||
| struct flash_slice *slices, int *nslices) | struct flash_slice *slices, int *nslices) | ||||
| { | { | ||||
| uint32_t fw_len; | uint32_t fw_len; | ||||
| uint32_t fs_ofs; | uint32_t fs_ofs; | ||||
| uint32_t val; | uint32_t val; | ||||
| uint32_t ofs_trx; | uint32_t ofs_trx; | ||||
| int flash_size; | int flash_size; | ||||
| *nslices = 0; | *nslices = 0; | ||||
| ▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines | |||||