示例#1
0
/*
 * TSC-specific code to read the ID eeprom on the mainboard and extract the
 * unit's EUI-64 which gets translated into a MAC-48 for ethernet.
 */
static void
eeprom_init(void)
{
	const uint32_t twiHz    = 400000;
	const uint32_t twiCkDiv = 1 << 16;
	const uint32_t twiChDiv = ((at91_master_clock / twiHz) - 2) << 8;
	const uint32_t twiClDiv = ((at91_master_clock / twiHz) - 2);

	/*
	 * Set the TWCK and TWD lines for Periph A, no pullup, open-drain.
	 */
	at91_pio_use_periph_a(AT91RM92_PIOA_BASE,
	    AT91C_PIO_PA25 | AT91C_PIO_PA26, 0);
	at91_pio_gpio_high_z(AT91RM92_PIOA_BASE, AT91C_PIO_PA25, 1);

	/*
	 * Enable TWI power (irq numbers are also device IDs for power)
	 */
	WR4HW(AT91RM92_PMC_BASE, PMC_PCER, 1u << AT91RM92_IRQ_TWI);

	/*
	 * Disable TWI interrupts, reset device, enable Master mode,
	 * disable Slave mode, set the clock.
	 */
	WR4HW(AT91RM92_TWI_BASE, TWI_IDR, 0xffffffff);
	WR4HW(AT91RM92_TWI_BASE, TWI_CR, TWI_CR_SWRST);
	WR4HW(AT91RM92_TWI_BASE, TWI_CR, TWI_CR_MSEN | TWI_CR_SVDIS);
	WR4HW(AT91RM92_TWI_BASE, TWI_CWGR, twiCkDiv | twiChDiv | twiClDiv);
}
示例#2
0
static int
pinctrl_configure_pins(device_t bus, phandle_t cfgxref)
{
	struct pinctrl_softc *sc;
	struct pincfg *cfg, *cfgdata;
	char name[32];
	phandle_t node;
	ssize_t npins;
	int i;

	sc = device_get_softc(bus);
	node = OF_node_from_xref(cfgxref);
	memset(name, 0, sizeof(name));
	OF_getprop(node, "name", name, sizeof(name));
	npins = OF_getencprop_alloc(node, "atmel,pins", sizeof(*cfgdata),
	    (void **)&cfgdata);
	if (npins < 0) {
		printf("We're doing it wrong %s\n", name);
		return (ENXIO);
	}
	if (npins == 0)
		return (0);
	for (i = 0, cfg = cfgdata; i < npins; i++, cfg++) {
		uint32_t pio;
		pio = (0xfffffff & sc->ranges[0].bus) + 0x200 * cfg->unit;
		printf("P%c%d %s %#x\n", cfg->unit + 'A', cfg->pin,
		    periphs[cfg->periph], cfg->flags);
		switch (cfg->periph) {
		case 0:
			at91_pio_use_gpio(pio, 1u << cfg->pin);
			at91_pio_gpio_pullup(pio, 1u << cfg->pin,
			    !!(cfg->flags & 1));
			at91_pio_gpio_high_z(pio, 1u << cfg->pin,
			    !!(cfg->flags & 2));
			at91_pio_gpio_set_deglitch(pio,
			    1u << cfg->pin, !!(cfg->flags & 4));
//			at91_pio_gpio_pulldown(pio, 1u << cfg->pin,
//			    !!(cfg->flags & 8));
//			at91_pio_gpio_dis_schmidt(pio,
//			    1u << cfg->pin, !!(cfg->flags & 16));
			break;
		case 1:
			at91_pio_use_periph_a(pio, 1u << cfg->pin, cfg->flags);
			break;
		case 2:
			at91_pio_use_periph_b(pio, 1u << cfg->pin, cfg->flags);
			break;
		}
	}
	OF_prop_free(cfgdata);
	return (0);
}