Exemplo n.º 1
0
static int
awusbphy_init(device_t dev)
{
    struct awusbphy_softc *sc;
    phandle_t node;
    char pname[20];
    int error, off;
    regulator_t reg;
    hwreset_t rst;
    clk_t clk;

    sc = device_get_softc(dev);
    node = ofw_bus_get_node(dev);

    /* Enable clocks */
    for (off = 0; clk_get_by_ofw_index(dev, off, &clk) == 0; off++) {
        error = clk_enable(clk);
        if (error != 0) {
            device_printf(dev, "couldn't enable clock %s\n",
                          clk_get_name(clk));
            return (error);
        }
    }

    /* De-assert resets */
    for (off = 0; hwreset_get_by_ofw_idx(dev, off, &rst) == 0; off++) {
        error = hwreset_deassert(rst);
        if (error != 0) {
            device_printf(dev, "couldn't de-assert reset %d\n",
                          off);
            return (error);
        }
    }

    /* Get regulators */
    for (off = 0; off < USBPHY_NPHYS; off++) {
        snprintf(pname, sizeof(pname), "usb%d_vbus-supply", off);
        if (regulator_get_by_ofw_property(dev, pname, &reg) == 0)
            sc->reg[off] = reg;
    }

    /* Get GPIOs */
    error = gpio_pin_get_by_ofw_property(dev, node, "usb0_id_det-gpios",
                                         &sc->id_det_pin);
    if (error == 0)
        sc->id_det_valid = 1;
    error = gpio_pin_get_by_ofw_property(dev, node, "usb0_vbus_det-gpios",
                                         &sc->vbus_det_pin);
    if (error == 0)
        sc->vbus_det_valid = 1;

    return (0);
}
Exemplo n.º 2
0
int
tegra_drm_encoder_attach(struct tegra_drm_encoder *output, phandle_t node)
{
	int rv;
	phandle_t ddc;

	/* XXX parse output panel here */

	rv = OF_getencprop_alloc(node, "nvidia,edid",
	    (void **)&output->edid);

	/* EDID exist but have invalid size */
	if ((rv >= 0) && (rv != sizeof(struct edid))) {
		device_printf(output->dev,
		    "Malformed \"nvidia,edid\" property\n");
		if (output->edid != NULL)
			free(output->edid, M_OFWPROP);
		return (ENXIO);
	}

	gpio_pin_get_by_ofw_property(output->dev, node, "nvidia,hpd-gpio",
	    &output->gpio_hpd);
	ddc = 0;
	OF_getencprop(node, "nvidia,ddc-i2c-bus", &ddc, sizeof(ddc));
	if (ddc > 0)
		output->ddc = OF_device_from_xref(ddc);
	if ((output->edid == NULL) && (output->ddc == NULL))
		return (ENXIO);

	if (output->gpio_hpd != NULL) {
		output->connector.polled =
//		    DRM_CONNECTOR_POLL_HPD;
		    DRM_CONNECTOR_POLL_DISCONNECT |
		    DRM_CONNECTOR_POLL_CONNECT;
	}

	return (0);
}
Exemplo n.º 3
0
/*
 * Write protect setup.
 */
static void
wp_setup(struct sdhci_fdt_gpio *gpio, phandle_t node)
{
	device_t dev;

	dev = gpio->dev;

	if (OF_hasprop(node, "wp-disable")) {
		gpio->wp_disabled = true;
		if (bootverbose)
			device_printf(dev, "Write protect disabled\n");
		return;
	}

	if (gpio_pin_get_by_ofw_property(dev, node, "wp-gpios", &gpio->wp_pin))
		return;

	if (OF_hasprop(node, "wp-inverted"))
		gpio->wp_inverted = true;

	if (bootverbose)
		device_printf(dev, "Write protect switch on %s pin %u\n",
		    device_get_nameunit(gpio->wp_pin->dev), gpio->wp_pin->pin);
}
Exemplo n.º 4
0
/*
 * Card detect setup.
 */
static void
cd_setup(struct sdhci_fdt_gpio *gpio, phandle_t node)
{
	int pincaps;
	device_t dev;
	const char *cd_mode_str;

	dev = gpio->dev;

	/*
	 * If the device is flagged as non-removable, set that slot option, and
	 * set a flag to make sdhci_fdt_gpio_get_present() always return true.
	 */
	if (OF_hasprop(node, "non-removable")) {
		gpio->slot->opt |= SDHCI_NON_REMOVABLE;
		gpio->cd_disabled = true;
		if (bootverbose)
			device_printf(dev, "Non-removable media\n");
		return;
	}

	/*
	 * If there is no cd-gpios property, then presumably the hardware
	 * PRESENT_STATE register and interrupts will reflect card state
	 * properly, and there's nothing more for us to do.  Our get_present()
	 * will return sdhci_generic_get_card_present() because cd_pin is NULL.
	 *
	 * If there is a property, make sure we can read the pin.
	 */
	if (gpio_pin_get_by_ofw_property(dev, node, "cd-gpios", &gpio->cd_pin))
		return;

	if (gpio_pin_getcaps(gpio->cd_pin, &pincaps) != 0 ||
	    !(pincaps & GPIO_PIN_INPUT)) {
		device_printf(dev, "Cannot read card-detect gpio pin; "
		    "setting card-always-present flag.\n");
		gpio->cd_disabled = true;
		return;
	}

	if (OF_hasprop(node, "cd-inverted"))
		gpio->cd_inverted = true;

	/*
	 * If the pin can trigger an interrupt on both rising and falling edges,
	 * we can use it to detect card presence changes.  If not, we'll request
	 * card presence polling instead of using interrupts.
	 */
	if (!(pincaps & GPIO_INTR_EDGE_BOTH)) {
		if (bootverbose)
			device_printf(dev, "Cannot configure "
			    "GPIO_INTR_EDGE_BOTH for card detect\n");
		goto without_interrupts;
	}

	/*
	 * Create an interrupt resource from the pin and set up the interrupt.
	 */
	if ((gpio->cd_ires = gpio_alloc_intr_resource(dev, &gpio->cd_irid,
	    RF_ACTIVE, gpio->cd_pin, GPIO_INTR_EDGE_BOTH)) == NULL) {
		if (bootverbose)
			device_printf(dev, "Cannot allocate an IRQ for card "
			    "detect GPIO\n");
		goto without_interrupts;
	}

	if (bus_setup_intr(dev, gpio->cd_ires, INTR_TYPE_BIO | INTR_MPSAFE,
	    NULL, cd_intr, gpio, &gpio->cd_ihandler) != 0) {
		device_printf(dev, "Unable to setup card-detect irq handler\n");
		gpio->cd_ihandler = NULL;
		goto without_interrupts;
	}

without_interrupts:

	/*
	 * If we have a readable gpio pin, but didn't successfully configure
	 * gpio interrupts, ask the sdhci driver to poll from a callout.
	 */
	if (gpio->cd_ihandler == NULL) {
		cd_mode_str = "polling";
		gpio->slot->quirks |= SDHCI_QUIRK_POLL_CARD_PRESENT;
	} else {
		cd_mode_str = "interrupts";
	}

	if (bootverbose) {
		device_printf(dev, "Card presence detect on %s pin %u, "
		    "configured for %s.\n",
		    device_get_nameunit(gpio->cd_pin->dev), gpio->cd_pin->pin,
		    cd_mode_str);
	}
}