Exemplo n.º 1
0
static int
a20_if_dwc_init(device_t dev)
{
    int clk;

    /* Activate GMAC clock and set the pin mux to rgmii. */
    switch (allwinner_soc_type()) {
#if defined(SOC_ALLWINNER_A10) || defined(SOC_ALLWINNER_A20)
    case ALLWINNERSOC_A10:
    case ALLWINNERSOC_A10S:
    case ALLWINNERSOC_A20:
        clk = a10_clk_gmac_activate(ofw_bus_get_node(dev));
        break;
#endif
#if defined(SOC_ALLWINNER_A31) || defined(SOC_ALLWINNER_A31S)
    case ALLWINNERSOC_A31:
    case ALLWINNERSOC_A31S:
        clk = a31_clk_gmac_activate(ofw_bus_get_node(dev));
        break;
#endif
    default:
        clk = -1;
    }
    if (clk != 0) {
        device_printf(dev, "could not activate gmac module\n");
        return (ENXIO);
    }

    return (0);
}
Exemplo n.º 2
0
static int
a10_gpio_attach(device_t dev)
{
	int rid;
	phandle_t gpio;
	struct a10_gpio_softc *sc;

	sc = device_get_softc(dev);
	sc->sc_dev = dev;

	mtx_init(&sc->sc_mtx, "a10 gpio", "gpio", MTX_SPIN);

	rid = 0;
	sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
	    RF_ACTIVE);
	if (!sc->sc_mem_res) {
		device_printf(dev, "cannot allocate memory window\n");
		goto fail;
	}

	sc->sc_bst = rman_get_bustag(sc->sc_mem_res);
	sc->sc_bsh = rman_get_bushandle(sc->sc_mem_res);

	rid = 0;
	sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
	    RF_ACTIVE);
	if (!sc->sc_irq_res) {
		device_printf(dev, "cannot allocate interrupt\n");
		goto fail;
	}

	/* Find our node. */
	gpio = ofw_bus_get_node(sc->sc_dev);
	if (!OF_hasprop(gpio, "gpio-controller"))
		/* Node is not a GPIO controller. */
		goto fail;

	/* Use the right pin data for the current SoC */
	switch (allwinner_soc_type()) {
#ifdef SOC_ALLWINNER_A10
	case ALLWINNERSOC_A10:
		sc->padconf = &a10_padconf;
		break;
#endif
#ifdef SOC_ALLWINNER_A20
	case ALLWINNERSOC_A20:
		sc->padconf = &a20_padconf;
		break;
#endif
#ifdef SOC_ALLWINNER_A31
	case ALLWINNERSOC_A31:
		sc->padconf = &a31_padconf;
		break;
#endif
#ifdef SOC_ALLWINNER_A31S
	case ALLWINNERSOC_A31S:
		sc->padconf = &a31s_padconf;
		break;
#endif
	default:
		return (ENOENT);
	}

	sc->sc_busdev = gpiobus_attach_bus(dev);
	if (sc->sc_busdev == NULL)
		goto fail;

	/*
	 * Register as a pinctrl device
	 */
	fdt_pinctrl_register(dev, "allwinner,pins");
	fdt_pinctrl_configure_tree(dev);

	return (0);

fail:
	if (sc->sc_irq_res)
		bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res);
	if (sc->sc_mem_res)
		bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
	mtx_destroy(&sc->sc_mtx);

	return (ENXIO);
}