FreeBSD/sys/arm/at91/board_tsc4370.c
/*
 * Assign SPI chip select pins based on which chip selects are found in hints.
 */
Assign SPI chip select pins based on which chip selects are found in hints.
Assign SPI chip select pins based on which chip selects are found in hints .
static void
assign_spi_pins(void)
{
	struct {
		uint32_t     num;
		const char * name;
	} chipsel_pins[] = {
		{ AT91C_PIO_PA3, "PA3", },
		{ AT91C_PIO_PA4, "PA4", },
		{ AT91C_PIO_PA5, "PA5", },
		{ AT91C_PIO_PA6, "PA6", },
	};
	int anchor = 0;
	uint32_t chipsel_inuse = 0;
	for (;;) {
		const char * rName = "";
		int unit = 0;
		int cs = 0;
		int ret;
		ret = resource_find_match(&anchor, &rName, &unit, "at", "spibus0");
		if (ret != 0)
			break;
		ret = resource_int_value(rName, unit, "cs", &cs);
		if (ret != 0) {
			printf( "Error: hint for SPI device %s%d "
				"without a chip select hint; "
				"device will not function.\n",
				rName, unit);
			continue;
		}
		if (cs < 0 || cs > 3) {
			printf( "Error: hint for SPI device %s%d "
				"contains an invalid chip select "
				"value: %d\n",
				rName, unit, cs);
			continue;
		}
		if (chipsel_inuse & (1 << cs)) {
			printf( "Error: hint for SPI device %s%d "
				"specifies chip select %d, which "
				"is already used by another device\n",
				rName, unit, cs);
			continue;
		}
		chipsel_inuse |= 1 << cs;
		at91_pio_use_periph_a(AT91RM92_PIOA_BASE, 
			chipsel_pins[cs].num, 1);
		printf( "Configured pin %s as SPI chip "
			"select %d for %s%d\n",
			chipsel_pins[cs].name, cs, rName, unit);
	}
	if (chipsel_inuse != 0) {
		at91_pio_use_periph_a(AT91RM92_PIOA_BASE, 
			AT91C_PIO_PA1 | AT91C_PIO_PA0 | AT91C_PIO_PA2, 0);
		WR4HW(AT91RM92_PMC_BASE, PMC_PCER, 1u << AT91RM92_IRQ_SPI);
	}
}
static void assign_spi_pins ( void ) { struct { uint32_t num ; const char * name ; } chipsel_pins [ ] = { { AT91C_PIO_PA3 , " " , } , { AT91C_PIO_PA4 , " " , } , { AT91C_PIO_PA5 , " " , } , { AT91C_PIO_PA6 , " " , } , } ; int anchor = 0 ; uint32_t chipsel_inuse = 0 ; for ( ; ; ) { const char * rName = " " ; int unit = 0 ; int cs = 0 ; int ret ; ret = resource_find_match ( & anchor , & rName , & unit , " " , " " ) ; if ( ret != 0 ) break ; ret = resource_int_value ( rName , unit , " " , & cs ) ; if ( ret != 0 ) { printf ( " " " " " \n " , rName , unit ) ; continue ; } if ( cs < 0 || cs > 3 ) { printf ( " " " " " \n " , rName , unit , cs ) ; continue ; } if ( chipsel_inuse & ( 1 << cs ) ) { printf ( " " " " " \n " , rName , unit , cs ) ; continue ; } chipsel_inuse |= 1 << cs ; at91_pio_use_periph_a ( AT91RM92_PIOA_BASE , chipsel_pins [ cs ] . num , 1 ) ; printf ( " " " \n " , chipsel_pins [ cs ] . name , cs , rName , unit ) ; } if ( chipsel_inuse != 0 ) { at91_pio_use_periph_a ( AT91RM92_PIOA_BASE , AT91C_PIO_PA1 | AT91C_PIO_PA0 | AT91C_PIO_PA2 , 0 ) ; WR4HW ( AT91RM92_PMC_BASE , PMC_PCER , 1u << AT91RM92_IRQ_SPI ) ; } }
Assign SPI chip select pins based on which chip selects are found in hints.
Assign SPI chip select pins based on which chip selects are found in hints .
/*
	 * Search through all device hints looking for any that have
	 * ".at=spibus0".  For each one found, ensure that there is also a
	 * chip select hint ".cs=<num>" and that <num> is 0-3, and assign the
	 * corresponding pin to the SPI peripheral.  Whine if we find a SPI
	 * device with a missing or invalid chipsel hint.
	 */ /*
	 * If there were hints for any SPI devices, assign the basic SPI IO pins
	 * and enable SPI power (irq numbers are also device IDs for power).
	 */