Esempio n. 1
0
static void
ramtron_attach(void)
{
	/* find the right spi */
#ifdef CONFIG_ARCH_BOARD_AEROCORE
	struct spi_dev_s *spi = up_spiinitialize(4);
#else
	struct spi_dev_s *spi = up_spiinitialize(2);
#endif
	/* this resets the spi bus, set correct bus speed again */
	SPI_SETFREQUENCY(spi, 10 * 1000 * 1000);
	SPI_SETBITS(spi, 8);
	SPI_SETMODE(spi, SPIDEV_MODE3);
	SPI_SELECT(spi, SPIDEV_FLASH, false);

	if (spi == NULL)
		errx(1, "failed to locate spi bus");

	/* start the RAMTRON driver, attempt 5 times */
	for (int i = 0; i < 5; i++) {
		mtd_dev = ramtron_initialize(spi);

		if (mtd_dev) {
			/* abort on first valid result */
			if (i > 0) {
				warnx("warning: mtd needed %d attempts to attach", i + 1);
			}

			break;
		}
	}

	/* if last attempt is still unsuccessful, abort */
	if (mtd_dev == NULL)
		errx(1, "failed to initialize mtd driver");

	int ret = mtd_dev->ioctl(mtd_dev, MTDIOC_SETSPEED, (unsigned long)10*1000*1000);
	if (ret != OK) {
		// FIXME: From the previous warnx call, it looked like this should have been an errx instead. Tried
		// that but setting the bug speed does fail all the time. Which was then exiting and the board would
		// not run correctly. So changed to warnx.
		warnx("failed to set bus speed");
	}

	attached = true;
}
Esempio n. 2
0
static void
ramtron_attach(void)
{
	/* find the right spi */
	struct spi_dev_s *spi = up_spiinitialize(4);
	/* this resets the spi bus, set correct bus speed again */
	SPI_SETFREQUENCY(spi, 10 * 1000 * 1000);
	SPI_SETBITS(spi, 8);
	SPI_SETMODE(spi, SPIDEV_MODE3);
	SPI_SELECT(spi, SPIDEV_FLASH, false);

	if (spi == NULL)
		errx(1, "failed to locate spi bus");

	/* start the RAMTRON driver, attempt 5 times */
	for (int i = 0; i < 5; i++) {
		mtd_dev = ramtron_initialize(spi);

		if (mtd_dev) {
			/* abort on first valid result */
			if (i > 0) {
				warnx("warning: mtd needed %d attempts to attach", i + 1);
			}

			break;
		}
	}

	/* if last attempt is still unsuccessful, abort */
	if (mtd_dev == NULL)
		errx(1, "failed to initialize mtd driver");

	int ret = mtd_dev->ioctl(mtd_dev, MTDIOC_SETSPEED, (unsigned long)10*1000*1000);
        if (ret != OK)
            warnx(1, "failed to set bus speed");

	attached = true;
}