From 1b4680383338679104b565789768b1251e0f7c4f Mon Sep 17 00:00:00 2001 From: Adrian Chadd Date: Fri, 22 Jan 2016 03:15:53 +0000 Subject: [PATCH] [flash] Teach mx25l SPI flash driver to interact with fdt_slicer and geom_flashmap This teaches the mx25l driver (sys/dev/flash/mx25l.c) to interact with sys/dev/fdt/fdt_slicer.c and sys/geom/geom_flashmap.c. This allows systems with SPI flash to benefit from the possibility to define flash 'slices' via FDT, just the same way that it's currently possible for CFI and NAND flashes. Tested: * Carambola 2, AR9331 + SPI NOR flash PR: kern/206227 Submitted by: Stanislav Galabov --- sys/dev/flash/mx25l.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/sys/dev/flash/mx25l.c b/sys/dev/flash/mx25l.c index d9aaa1c24935..c4dad4b28775 100644 --- a/sys/dev/flash/mx25l.c +++ b/sys/dev/flash/mx25l.c @@ -93,6 +93,7 @@ static int mx25l_open(struct disk *dp); static int mx25l_close(struct disk *dp); static int mx25l_ioctl(struct disk *, u_long, void *, int, struct thread *); static void mx25l_strategy(struct bio *bp); +static int mx25l_getattr(struct bio *bp); static void mx25l_task(void *arg); struct mx25l_flash_ident flash_devices[] = { @@ -383,6 +384,7 @@ mx25l_attach(device_t dev) sc->sc_disk->d_open = mx25l_open; sc->sc_disk->d_close = mx25l_close; sc->sc_disk->d_strategy = mx25l_strategy; + sc->sc_disk->d_getattr = mx25l_getattr; sc->sc_disk->d_ioctl = mx25l_ioctl; sc->sc_disk->d_name = "flash/spi"; sc->sc_disk->d_drv1 = sc; @@ -448,6 +450,27 @@ mx25l_strategy(struct bio *bp) M25PXX_UNLOCK(sc); } +static int +mx25l_getattr(struct bio *bp) +{ + struct mx25l_softc *sc; + device_t dev; + + if (bp->bio_disk == NULL || bp->bio_disk->d_drv1 == NULL) + return (ENXIO); + + sc = bp->bio_disk->d_drv1; + dev = sc->sc_dev; + + if (strcmp(bp->bio_attribute, "SPI::device") == 0) { + if (bp->bio_length != sizeof(dev)) + return (EFAULT); + bcopy(&dev, bp->bio_data, sizeof(dev)); + } else + return (-1); + return (0); +} + static void mx25l_task(void *arg) {