Re: svn commit: r348882 - head/sys/dev/sdhci

2019-06-21 Thread Luiz Otavio O Souza
On Fri, 14 Jun 2019 at 05:25, Bjoern A. Zeeb
 wrote:
>
> On 10 Jun 2019, at 21:50, Luiz Otavio O Souza wrote:
>
> > Author: loos
> > Date: Mon Jun 10 21:50:07 2019
> > New Revision: 348882
> > URL: https://svnweb.freebsd.org/changeset/base/348882
> >
> > Log:
> >   Add support for the GPIO SD Card VCC regulator/switch and the GPIO
> > SD Card
> >   detection pins to the Marvell Xenon SDHCI controller.
> >
> >   These features are enable by 'vqmmc-supply' and 'cd-gpios'
> > properties in the
> >   DTS.
> >
> >   This fixes the SD Card detection on espressobin.
>
> Do you have a copy or a reference to such a (working) dts file?

I'm using the in tree DTS for the espresso bin:
sys/gnu/dts/arm64/marvell/armada-3720-espressobin.dts

Now that it works, I think we could build it by default.

Luiz
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r348882 - head/sys/dev/sdhci

2019-06-14 Thread Bjoern A. Zeeb

On 10 Jun 2019, at 21:50, Luiz Otavio O Souza wrote:


Author: loos
Date: Mon Jun 10 21:50:07 2019
New Revision: 348882
URL: https://svnweb.freebsd.org/changeset/base/348882

Log:
  Add support for the GPIO SD Card VCC regulator/switch and the GPIO 
SD Card

  detection pins to the Marvell Xenon SDHCI controller.

  These features are enable by 'vqmmc-supply' and 'cd-gpios' 
properties in the

  DTS.

  This fixes the SD Card detection on espressobin.


Do you have a copy or a reference to such a (working) dts file?

Thanks,
Bjoern
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r348882 - head/sys/dev/sdhci

2019-06-10 Thread Luiz Otavio O Souza
Author: loos
Date: Mon Jun 10 21:50:07 2019
New Revision: 348882
URL: https://svnweb.freebsd.org/changeset/base/348882

Log:
  Add support for the GPIO SD Card VCC regulator/switch and the GPIO SD Card
  detection pins to the Marvell Xenon SDHCI controller.
  
  These features are enable by 'vqmmc-supply' and 'cd-gpios' properties in the
  DTS.
  
  This fixes the SD Card detection on espressobin.
  
  Sponsored by: Rubicon Communications, LLC (Netgate)

Modified:
  head/sys/dev/sdhci/sdhci_xenon.c

Modified: head/sys/dev/sdhci/sdhci_xenon.c
==
--- head/sys/dev/sdhci/sdhci_xenon.cMon Jun 10 21:34:07 2019
(r348881)
+++ head/sys/dev/sdhci/sdhci_xenon.cMon Jun 10 21:50:07 2019
(r348882)
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -56,6 +57,7 @@ __FBSDID("$FreeBSD$");
 #include 
 
 #include 
+#include 
 #include 
 
 #include "mmcbr_if.h"
@@ -84,10 +86,12 @@ struct sdhci_xenon_softc {
uint32_tmax_clk;/* Max possible freq */
struct resource *irq_res;   /* IRQ resource */
void*intrhand;  /* Interrupt handle */
+   struct sdhci_fdt_gpio *gpio;/* GPIO pins for CD detection. */
 
struct sdhci_slot *slot;/* SDHCI internal data */
struct resource *mem_res;   /* Memory resource */
 
+   regulator_t reg_vqmmc;  /* vqmmc-supply regulator */
uint8_t znr;/* PHY ZNR */
uint8_t zpr;/* PHY ZPR */
boolno_18v; /* No 1.8V support */
@@ -188,6 +192,14 @@ sdhci_xenon_get_ro(device_t bus, device_t dev)
return (sdhci_generic_get_ro(bus, dev) ^ sc->wp_inverted);
 }
 
+static bool
+sdhci_xenon_get_card_present(device_t dev, struct sdhci_slot *slot)
+{
+   struct sdhci_xenon_softc *sc = device_get_softc(dev);
+
+   return (sdhci_fdt_gpio_get_present(sc->gpio));
+}
+
 static int
 sdhci_xenon_phy_init(device_t brdev, struct mmc_ios *ios)
 {
@@ -337,6 +349,25 @@ sdhci_xenon_update_ios(device_t brdev, device_t reqdev
slot = device_get_ivars(reqdev);
ios = &slot->host.ios;
 
+   switch (ios->power_mode) {
+   case power_on:
+   break;
+   case power_off:
+   if (bootverbose)
+   device_printf(sc->dev, "Powering down sd/mmc\n");
+
+   if (sc->reg_vqmmc)
+   regulator_disable(sc->reg_vqmmc);
+   break;
+   case power_up:
+   if (bootverbose)
+   device_printf(sc->dev, "Powering up sd/mmc\n");
+
+   if (sc->reg_vqmmc)
+   regulator_enable(sc->reg_vqmmc);
+   break;
+   };
+
/* Update the PHY settings. */
if (ios->clock != 0)
sdhci_xenon_phy_set(brdev, ios);
@@ -352,6 +383,42 @@ sdhci_xenon_update_ios(device_t brdev, device_t reqdev
 }
 
 static int
+sdhci_xenon_switch_vccq(device_t brdev, device_t reqdev)
+{
+   struct sdhci_xenon_softc *sc;
+   struct sdhci_slot *slot;
+   int uvolt, err;
+
+   sc = device_get_softc(brdev);
+
+if (sc->reg_vqmmc == NULL)
+   return EOPNOTSUPP;
+
+   slot = device_get_ivars(reqdev);
+   switch (slot->host.ios.vccq) {
+   case vccq_180:
+   uvolt = 180;
+   break;
+   case vccq_330:
+   uvolt = 330;
+   break;
+   default:
+   return EINVAL;
+   }
+
+   err = regulator_set_voltage(sc->reg_vqmmc, uvolt, uvolt);
+   if (err != 0) {
+   device_printf(sc->dev,
+   "Cannot set vqmmc to %d<->%d\n",
+   uvolt,
+   uvolt);
+   return (err);
+   }
+
+   return (0);
+}
+
+static int
 sdhci_xenon_probe(device_t dev)
 {
struct sdhci_xenon_softc *sc = device_get_softc(dev);
@@ -389,6 +456,11 @@ sdhci_xenon_probe(device_t dev)
if ((OF_getencprop(sc->node, "marvell,xenon-phy-zpr", &cid,
sizeof(cid))) > 0)
sc->zpr = cid & XENON_ZPR_MASK;
+   if (regulator_get_by_ofw_property(dev, 0, "vqmmc-supply",
+   &sc->reg_vqmmc) == 0 && bootverbose) {
+   if (bootverbose)
+   device_printf(dev, "vqmmc-supply regulator found\n");
+   }
 
return (0);
 }
@@ -437,6 +509,12 @@ sdhci_xenon_attach(device_t dev)
slot->max_clk = sc->max_clk;
sc->slot = slot;
 
+   /*
+* Set up any gpio pin handling described in the FDT data. This cannot
+* fail; see comments in sdhci_fdt_gpio.h for details.
+*/
+   sc->gpio = sdhci_fdt_gpio_setup(dev, slot);
+
if (sdhci_init_slot(dev, sc->slot, 0))
goto fail;
 
@@ -497,6 +575,9 @@ sdhci_xenon_detach(device_t dev)
 {
struct sdhci_