Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Mar 2017 15:34:32 +0000 (UTC)
From:      Michal Meloun <mmel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r314703 - head/sys/arm/nvidia
Message-ID:  <201703051534.v25FYWUj033242@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mmel
Date: Sun Mar  5 15:34:32 2017
New Revision: 314703
URL: https://svnweb.freebsd.org/changeset/base/314703

Log:
  Add support for card detect and write protect gpio pins to Tegra SDHCI.

Modified:
  head/sys/arm/nvidia/tegra_sdhci.c

Modified: head/sys/arm/nvidia/tegra_sdhci.c
==============================================================================
--- head/sys/arm/nvidia/tegra_sdhci.c	Sun Mar  5 13:14:18 2017	(r314702)
+++ head/sys/arm/nvidia/tegra_sdhci.c	Sun Mar  5 15:34:32 2017	(r314703)
@@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/types.h>
 #include <sys/bus.h>
 #include <sys/callout.h>
+#include <sys/gpio.h>
 #include <sys/kernel.h>
 #include <sys/lock.h>
 #include <sys/malloc.h>
@@ -60,6 +61,7 @@ __FBSDID("$FreeBSD$");
 #include <dev/ofw/ofw_bus.h>
 #include <dev/ofw/ofw_bus_subr.h>
 #include <dev/sdhci/sdhci.h>
+#include <dev/sdhci/sdhci_fdt_gpio.h>
 
 #include "sdhci_if.h"
 
@@ -107,9 +109,8 @@ struct tegra_sdhci_softc {
 	uint32_t		max_clk; /* Max possible freq */
 	clk_t			clk;
 	hwreset_t 		reset;
-	gpio_pin_t		gpio_cd;
-	gpio_pin_t		gpio_wp;
 	gpio_pin_t		gpio_power;
+	struct sdhci_fdt_gpio	*gpio;
 
 	int			force_card_present;
 	struct sdhci_slot	slot;
@@ -215,10 +216,19 @@ tegra_sdhci_intr(void *arg)
 }
 
 static int
-tegra_generic_get_ro(device_t brdev, device_t reqdev)
+tegra_sdhci_get_ro(device_t brdev, device_t reqdev)
 {
+	struct tegra_sdhci_softc *sc = device_get_softc(brdev);
 
-	return (0);
+	return (sdhci_fdt_gpio_get_readonly(sc->gpio));
+}
+
+static bool
+tegra_sdhci_get_card_present(device_t dev, struct sdhci_slot *slot)
+{
+	struct tegra_sdhci_softc *sc = device_get_softc(dev);
+
+	return (sdhci_fdt_gpio_get_present(sc->gpio));
 }
 
 static int
@@ -300,9 +310,7 @@ tegra_sdhci_attach(device_t dev)
 		goto fail;
 	}
 
-	gpio_pin_get_by_ofw_property(sc->dev, node, "cd-gpios", &sc->gpio_cd);
 	gpio_pin_get_by_ofw_property(sc->dev, node, "power-gpios", &sc->gpio_power);
-	gpio_pin_get_by_ofw_property(sc->dev, node, "wp-gpios", &sc->gpio_wp);
 
 	rv = clk_get_by_ofw_index(dev, 0, 0, &sc->clk);
 	if (rv != 0) {
@@ -374,6 +382,8 @@ tegra_sdhci_attach(device_t dev)
 		goto fail;
 	}
 
+	sc->gpio = sdhci_fdt_gpio_setup(sc->dev, &sc->slot);
+
 	bus_generic_probe(dev);
 	bus_generic_attach(dev);
 
@@ -382,18 +392,16 @@ tegra_sdhci_attach(device_t dev)
 	return (0);
 
 fail:
-	if (sc->gpio_cd != NULL)
-		gpio_pin_release(sc->gpio_cd);
-	if (sc->gpio_wp != NULL)
-		gpio_pin_release(sc->gpio_wp);
+	if (sc->gpio != NULL)
+		sdhci_fdt_gpio_teardown(sc->gpio);
+	if (sc->intr_cookie != NULL)
+		bus_teardown_intr(dev, sc->irq_res, sc->intr_cookie);
 	if (sc->gpio_power != NULL)
 		gpio_pin_release(sc->gpio_power);
 	if (sc->clk != NULL)
 		clk_release(sc->clk);
 	if (sc->reset != NULL)
 		hwreset_release(sc->reset);
-	if (sc->intr_cookie != NULL)
-		bus_teardown_intr(dev, sc->irq_res, sc->intr_cookie);
 	if (sc->irq_res != NULL)
 		bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
 	if (sc->mem_res != NULL)
@@ -409,6 +417,7 @@ tegra_sdhci_detach(device_t dev)
 	struct sdhci_slot *slot = &sc->slot;
 
 	bus_generic_detach(dev);
+	sdhci_fdt_gpio_teardown(sc->gpio);
 	clk_release(sc->clk);
 	bus_teardown_intr(dev, sc->irq_res, sc->intr_cookie);
 	bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(sc->irq_res),
@@ -434,7 +443,7 @@ static device_method_t tegra_sdhci_metho
 	/* MMC bridge interface */
 	DEVMETHOD(mmcbr_update_ios,	sdhci_generic_update_ios),
 	DEVMETHOD(mmcbr_request,	sdhci_generic_request),
-	DEVMETHOD(mmcbr_get_ro,		tegra_generic_get_ro),
+	DEVMETHOD(mmcbr_get_ro,		tegra_sdhci_get_ro),
 	DEVMETHOD(mmcbr_acquire_host,	sdhci_generic_acquire_host),
 	DEVMETHOD(mmcbr_release_host,	sdhci_generic_release_host),
 
@@ -447,6 +456,7 @@ static device_method_t tegra_sdhci_metho
 	DEVMETHOD(sdhci_write_2,	tegra_sdhci_write_2),
 	DEVMETHOD(sdhci_write_4,	tegra_sdhci_write_4),
 	DEVMETHOD(sdhci_write_multi_4,	tegra_sdhci_write_multi_4),
+	DEVMETHOD(sdhci_get_card_present, tegra_sdhci_get_card_present),
 
 	DEVMETHOD_END
 };



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703051534.v25FYWUj033242>