Lines Matching +full:lx2160a +full:- +full:fspi
1 /*-
66 {"nxp,lx2160a-fspi", true},
136 return ((bus_read_4(sc->mem_res, offset))); in read_reg()
143 bus_write_4(sc->mem_res, offset, (value)); in write_reg()
164 } while (condition && (--iterations > 0)); in reg_read_poll_tout()
175 ret |= clk_disable(sc->fspi_clk_en); in flex_spi_clk_setup()
176 ret |= clk_disable(sc->fspi_clk); in flex_spi_clk_setup()
178 ret |= clk_set_freq(sc->fspi_clk, rate, 0); in flex_spi_clk_setup()
179 sc->fspi_clk_hz = rate; in flex_spi_clk_setup()
182 ret |= clk_enable(sc->fspi_clk_en); in flex_spi_clk_setup()
183 ret |= clk_enable(sc->fspi_clk); in flex_spi_clk_setup()
301 device_printf(sc->dev, in flex_spi_read_rxfifo()
313 memcpy(buf + i, ®, size - i); in flex_spi_read_rxfifo()
344 device_printf(sc->dev, in flex_spi_write_txfifo()
352 memcpy(®, buf + i, size - i); in flex_spi_write_txfifo()
409 } while (--cnt); in flex_spi_do_op()
411 device_printf(sc->dev, "timed out waiting for command completion\n"); in flex_spi_do_op()
442 device_printf(sc->dev, "%s: timed out waiting for controller", __func__); in flex_spi_wait_for_flash()
450 device_printf(sc->dev, "ERROR: failed to get flash status\n"); in flex_spi_wait_for_flash()
468 device_printf(sc->dev, "ERROR: failed to identify device\n"); in flex_spi_identify()
473 while (finfo->jedecid != 0) { in flex_spi_identify()
474 if (id == finfo->jedecid) { in flex_spi_identify()
475 device_printf(sc->dev, "found %s Flash\n", finfo->name); in flex_spi_identify()
476 sc->sectorsize = finfo->sectorsize; in flex_spi_identify()
477 sc->sectorcount = finfo->sectorcount; in flex_spi_identify()
478 sc->erasesize = finfo->erasesize; in flex_spi_identify()
479 sc->fspi_max_clk = finfo->maxclk; in flex_spi_identify()
492 if (sc->quirks & FSPI_QUIRK_USE_IP_ONLY) in flex_spi_force_ip_mode()
510 device_printf(sc->dev, in flex_spi_read()
517 *(uint8_t*)data = bus_read_1(sc->ahb_mem_res, offset); in flex_spi_read()
519 count--; in flex_spi_read()
522 *(uint32_t*)data = bus_read_4(sc->ahb_mem_res, offset); in flex_spi_read()
524 count -= 4; in flex_spi_read()
540 count -= len; in flex_spi_read()
557 device_printf(sc->dev, "ERROR: failed to enable writes\n"); in flex_spi_write()
562 /* per-sector write */ in flex_spi_write()
564 uint32_t sector_base = rounddown2(offset, sc->erasesize); in flex_spi_write()
567 if (size_in_sector + offset > sector_base + sc->erasesize) in flex_spi_write()
568 size_in_sector = sector_base + sc->erasesize - offset; in flex_spi_write()
571 ret = flex_spi_read(sc, sector_base, sc->buf, sc->erasesize); in flex_spi_write()
573 device_printf(sc->dev, "ERROR: failed to read sector %d\n", in flex_spi_write()
583 device_printf(sc->dev, "ERROR: failed to erase sector %d\n", in flex_spi_write()
589 memcpy(sc->buf + (offset - sector_base), data, size_in_sector); in flex_spi_write()
593 * across 256-byte page boundary in flex_spi_write()
595 for (ptr = 0; ptr < sc->erasesize; ptr += 32) { in flex_spi_write()
598 sector_base + ptr, (void*)(sc->buf + ptr), 32, DIR_WRITE); in flex_spi_write()
600 device_printf(sc->dev, "ERROR: failed to write address %ld\n", in flex_spi_write()
607 size = size - size_in_sector; in flex_spi_write()
612 ret = flex_spi_do_op(sc, LUT_FLASH_CMD_WRITE_DISABLE, offset, (void*)sc->buf, in flex_spi_write()
615 device_printf(sc->dev, "ERROR: failed to disable writes\n"); in flex_spi_write()
643 device_printf(sc->dev, "time out waiting for reset"); in flex_spi_default_setup()
680 /* AHB Read - Set lut sequence ID for all CS. */ in flex_spi_default_setup()
700 if (!ofw_bus_search_compatible(dev, flex_spi_compat_data)->ocd_data) in flex_spi_probe()
717 sc->dev = dev; in flex_spi_attach()
719 mtx_init(&sc->disk_mtx, "flex_spi_DISK", "QSPI disk mtx", MTX_DEF); in flex_spi_attach()
723 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in flex_spi_attach()
727 sc->ahb_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in flex_spi_attach()
730 if (sc->mem_res == NULL || sc->ahb_mem_res == NULL) { in flex_spi_attach()
737 if ((clk_get_by_ofw_name(dev, node, "fspi_en", &sc->fspi_clk_en) != 0) in flex_spi_attach()
738 || (clk_get_freq(sc->fspi_clk_en, &sc->fspi_clk_en_hz) != 0)) { in flex_spi_attach()
743 if ((clk_get_by_ofw_name(dev, node, "fspi", &sc->fspi_clk) != 0) in flex_spi_attach()
744 || (clk_get_freq(sc->fspi_clk, &sc->fspi_clk_hz) != 0)) { in flex_spi_attach()
745 device_printf(dev, "could not get fspi clock\n"); in flex_spi_attach()
751 if (clk_enable(sc->fspi_clk_en) != 0 || in flex_spi_attach()
752 clk_enable(sc->fspi_clk) != 0) { in flex_spi_attach()
765 device_printf(sc->dev, "Unable to initialize defaults\n"); in flex_spi_attach()
772 device_printf(sc->dev, "Unable to identify Flash\n"); in flex_spi_attach()
777 if (flex_spi_clk_setup(sc, sc->fspi_max_clk) != 0) { in flex_spi_attach()
778 device_printf(sc->dev, "Unable to set up SPI max clock\n"); in flex_spi_attach()
783 sc->buf = malloc(sc->erasesize, SECTOR_BUFFER, M_WAITOK); in flex_spi_attach()
784 /* Move it to per-flash */ in flex_spi_attach()
785 sc->disk = disk_alloc(); in flex_spi_attach()
786 sc->disk->d_open = flex_spi_open; in flex_spi_attach()
787 sc->disk->d_close = flex_spi_close; in flex_spi_attach()
788 sc->disk->d_strategy = flex_spi_strategy; in flex_spi_attach()
789 sc->disk->d_getattr = flex_spi_getattr; in flex_spi_attach()
790 sc->disk->d_ioctl = flex_spi_ioctl; in flex_spi_attach()
791 sc->disk->d_name = "flash/qspi"; in flex_spi_attach()
792 sc->disk->d_drv1 = sc; in flex_spi_attach()
794 sc->disk->d_maxsize = DFLTPHYS; in flex_spi_attach()
795 sc->disk->d_sectorsize = FLASH_SECTORSIZE; in flex_spi_attach()
796 sc->disk->d_unit = device_get_unit(sc->dev); in flex_spi_attach()
797 sc->disk->d_dump = NULL; in flex_spi_attach()
799 sc->disk->d_mediasize = sc->sectorsize * sc->sectorcount; in flex_spi_attach()
800 sc->disk->d_stripesize = sc->erasesize; in flex_spi_attach()
802 bioq_init(&sc->bio_queue); in flex_spi_attach()
803 sc->taskstate = TSTATE_RUNNING; in flex_spi_attach()
804 kproc_create(&flex_spi_task, sc, &sc->p, 0, 0, "task: qspi flash"); in flex_spi_attach()
805 disk_create(sc->disk, DISK_VERSION); in flex_spi_attach()
822 mtx_lock(&sc->disk_mtx); in flex_spi_detach()
823 if (sc->taskstate == TSTATE_RUNNING) { in flex_spi_detach()
824 sc->taskstate = TSTATE_STOPPING; in flex_spi_detach()
825 wakeup(sc->disk); in flex_spi_detach()
826 while (err == 0 && sc->taskstate != TSTATE_STOPPED) { in flex_spi_detach()
827 err = mtx_sleep(sc->disk, &sc->disk_mtx, 0, "flex_spi", in flex_spi_detach()
830 sc->taskstate = TSTATE_RUNNING; in flex_spi_detach()
831 device_printf(sc->dev, in flex_spi_detach()
837 mtx_unlock(&sc->disk_mtx); in flex_spi_detach()
838 mtx_destroy(&sc->disk_mtx); in flex_spi_detach()
840 if (err == 0 && sc->taskstate == TSTATE_STOPPED) { in flex_spi_detach()
841 disk_destroy(sc->disk); in flex_spi_detach()
842 bioq_flush(&sc->bio_queue, NULL, ENXIO); in flex_spi_detach()
848 if (sc->mem_res != NULL) in flex_spi_detach()
850 rman_get_rid(sc->mem_res), sc->mem_res); in flex_spi_detach()
852 if (sc->ahb_mem_res != NULL) in flex_spi_detach()
854 rman_get_rid(sc->ahb_mem_res), sc->ahb_mem_res); in flex_spi_detach()
857 if (sc->fspi_clk_en_hz) in flex_spi_detach()
858 clk_disable(sc->fspi_clk_en); in flex_spi_detach()
859 if (sc->fspi_clk_hz) in flex_spi_detach()
860 clk_disable(sc->fspi_clk); in flex_spi_detach()
862 free(sc->buf, SECTOR_BUFFER); in flex_spi_detach()
894 sc = (struct flex_spi_softc *)bp->bio_disk->d_drv1; in flex_spi_strategy()
895 mtx_lock(&sc->disk_mtx); in flex_spi_strategy()
896 bioq_disksort(&sc->bio_queue, bp); in flex_spi_strategy()
897 mtx_unlock(&sc->disk_mtx); in flex_spi_strategy()
898 wakeup(sc->disk); in flex_spi_strategy()
907 if (bp->bio_disk == NULL || bp->bio_disk->d_drv1 == NULL) { in flex_spi_getattr()
911 sc = bp->bio_disk->d_drv1; in flex_spi_getattr()
912 dev = sc->dev; in flex_spi_getattr()
914 if (strcmp(bp->bio_attribute, "SPI::device") != 0) { in flex_spi_getattr()
915 return (-1); in flex_spi_getattr()
918 if (bp->bio_length != sizeof(dev)) { in flex_spi_getattr()
922 bcopy(&dev, bp->bio_data, sizeof(dev)); in flex_spi_getattr()
935 mtx_lock(&sc->disk_mtx); in flex_spi_task()
937 if (sc->taskstate == TSTATE_STOPPING) { in flex_spi_task()
938 sc->taskstate = TSTATE_STOPPED; in flex_spi_task()
939 mtx_unlock(&sc->disk_mtx); in flex_spi_task()
940 wakeup(sc->disk); in flex_spi_task()
943 bp = bioq_first(&sc->bio_queue); in flex_spi_task()
945 mtx_sleep(sc->disk, &sc->disk_mtx, PRIBIO, in flex_spi_task()
948 bioq_remove(&sc->bio_queue, bp); in flex_spi_task()
949 mtx_unlock(&sc->disk_mtx); in flex_spi_task()
951 switch (bp->bio_cmd) { in flex_spi_task()
953 bp->bio_error = flex_spi_read(sc, bp->bio_offset, in flex_spi_task()
954 bp->bio_data, bp->bio_bcount); in flex_spi_task()
957 bp->bio_error = flex_spi_write(sc, bp->bio_offset, in flex_spi_task()
958 bp->bio_data, bp->bio_bcount); in flex_spi_task()
961 bp->bio_error = EINVAL; in flex_spi_task()