Re: [PATCH 2/2] mmc: sdhci-milbeaut: add Milbeaut SD controller driver

2019-05-07 Thread orito.takao

Thank you for reviewing my patches.

> [...]
> 
> > +
> > +static void sdhci_milbeaut_power_off(struct sdhci_host *host)
> > +{
> > +   struct f_sdhost_priv *priv = sdhci_priv(host);
> > +
> > +   gpiod_set_value(priv->power_gpio, 0);
> > +   udelay(1000);
> > +}
> > +
> > +static void sdhci_milbeaut_power_on(struct sdhci_host *host)
> > +{
> > +   struct f_sdhost_priv *priv = sdhci_priv(host);
> > +
> > +   gpiod_set_value(priv->power_gpio, 1);
> > +}
> > +
> 
> As stated for the DT doc patch, please use a fixed GPIO regulator
> instead. In this way you will also get a the OCR mask based upon the
> GPIO regulator, which is parsed out by the mmc core when sdhci calls
> mmc_regulator_get_supply().

I see. I will update this part too at the view point of using regurator.

Thanks
Orito

> 
> Otherwise, this looks good to me.
> 
> [...]
> 
> Kind regards
> Uffe

-- 
Takao Orito 


Re: [PATCH 2/2] mmc: sdhci-milbeaut: add Milbeaut SD controller driver

2019-04-29 Thread Ulf Hansson
[...]

> +
> +static void sdhci_milbeaut_power_off(struct sdhci_host *host)
> +{
> +   struct f_sdhost_priv *priv = sdhci_priv(host);
> +
> +   gpiod_set_value(priv->power_gpio, 0);
> +   udelay(1000);
> +}
> +
> +static void sdhci_milbeaut_power_on(struct sdhci_host *host)
> +{
> +   struct f_sdhost_priv *priv = sdhci_priv(host);
> +
> +   gpiod_set_value(priv->power_gpio, 1);
> +}
> +

As stated for the DT doc patch, please use a fixed GPIO regulator
instead. In this way you will also get a the OCR mask based upon the
GPIO regulator, which is parsed out by the mmc core when sdhci calls
mmc_regulator_get_supply().

Otherwise, this looks good to me.

[...]

Kind regards
Uffe


[PATCH 2/2] mmc: sdhci-milbeaut: add Milbeaut SD controller driver

2019-04-25 Thread Takao Orito
SD Host controller on Milbeaut is consist of two controller parts.
One is core controller F_SDH30, this is similar to sdhci-fujitsu
controller.
Another is bridge controller.
This bridge controller is not compatible with sdhci-fujitsu controller.
This is special for Milbeaut series. This has some functions.
For example, reset control, clock enable/select for SDR50/25/12, set
property of SD physical pins, retuning control, set capabilityies.

This bridge controller requires special procedures at reset or clock
enablement or change for further tuning of clock.

This new driver uses GPIO descriptor from platform data to switch
the power.

Signed-off-by: Takao Orito 
---
 drivers/mmc/host/Kconfig  |  11 ++
 drivers/mmc/host/Makefile |   1 +
 drivers/mmc/host/sdhci-milbeaut.c | 393 ++
 drivers/mmc/host/sdhci_f_sdh30.c  |  26 +--
 drivers/mmc/host/sdhci_f_sdh30.h  |  32 
 5 files changed, 438 insertions(+), 25 deletions(-)
 create mode 100644 drivers/mmc/host/sdhci-milbeaut.c
 create mode 100644 drivers/mmc/host/sdhci_f_sdh30.h

diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 28fcd8f..9b39111 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -353,6 +353,17 @@ config MMC_SDHCI_F_SDH30
 
  If unsure, say N.
 
+config MMC_SDHCI_MILBEAUT
+   tristate "SDHCI support for Socionext Milbeaut Serieas using F_SDH30"
+   depends on MMC_SDHCI_PLTFM
+   depends on OF
+   help
+ This selects the Secure Digital Host Controller Interface (SDHCI)
+ Needed by Milbeaut SoC for MMC / SD / SDIO support.
+ If you have a controller with this interface, say Y or M here.
+
+ If unsure, say N.
+
 config MMC_SDHCI_IPROC
tristate "SDHCI support for the BCM2835 & iProc SD/MMC Controller"
depends on ARCH_BCM2835 || ARCH_BCM_IPROC || COMPILE_TEST
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index 7357871..db98e8a 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_MMC_SDHCI_PXAV2) += sdhci-pxav2.o
 obj-$(CONFIG_MMC_SDHCI_S3C)+= sdhci-s3c.o
 obj-$(CONFIG_MMC_SDHCI_SIRF)   += sdhci-sirf.o
 obj-$(CONFIG_MMC_SDHCI_F_SDH30)+= sdhci_f_sdh30.o
+obj-$(CONFIG_MMC_SDHCI_MILBEAUT)   += sdhci-milbeaut.o
 obj-$(CONFIG_MMC_SDHCI_SPEAR)  += sdhci-spear.o
 obj-$(CONFIG_MMC_SDHCI_AM654)  += sdhci_am654.o
 obj-$(CONFIG_MMC_WBSD) += wbsd.o
diff --git a/drivers/mmc/host/sdhci-milbeaut.c 
b/drivers/mmc/host/sdhci-milbeaut.c
new file mode 100644
index 000..0bdb168
--- /dev/null
+++ b/drivers/mmc/host/sdhci-milbeaut.c
@@ -0,0 +1,393 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2013 - 2015 Fujitsu Semiconductor, Ltd
+ *  Vincent Yang 
+ * Copyright (C) 2015 Linaro Ltd  Andy Green 
+ * Copyright (C) 2019 Socionext Inc.
+ *  Takao Orito 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "sdhci-pltfm.h"
+#include "sdhci_f_sdh30.h"
+
+/* milbeaut bridge controller register */
+#define MLB_SOFT_RESET 0x0200
+#define  MLB_SOFT_RESET_RSTX   BIT(0)
+
+#define MLB_WP_CD_LED_SET  0x0210
+#define  MLB_WP_CD_LED_SET_LED_INV  BIT(2)
+
+#define MLB_CR_SET 0x0220
+#define  MLB_CR_SET_CR_TOCLKUNIT   BIT(24)
+#define  MLB_CR_SET_CR_TOCLKFREQ_SFT   (16)
+#define  MLB_CR_SET_CR_TOCLKFREQ_MASK  (0x3F << MLB_CR_SET_CR_TOCLKFREQ_SFT)
+#define  MLB_CR_SET_CR_BCLKFREQ_SFT(8)
+#define  MLB_CR_SET_CR_BCLKFREQ_MASK   (0xFF << MLB_CR_SET_CR_BCLKFREQ_SFT)
+#define  MLB_CR_SET_CR_RTUNTIMER_SFT   (4)
+#define  MLB_CR_SET_CR_RTUNTIMER_MASK  (0xF << MLB_CR_SET_CR_RTUNTIMER_SFT)
+
+#define MLB_SD_TOCLK_I_DIV  16
+#define MLB_TOCLKFREQ_UNIT_THRES1600
+#define MLB_CAL_TOCLKFREQ_MHZ(rate) (rate / MLB_SD_TOCLK_I_DIV / 100)
+#define MLB_CAL_TOCLKFREQ_KHZ(rate) (rate / MLB_SD_TOCLK_I_DIV / 1000)
+#define MLB_TOCLKFREQ_MAX   63
+#define MLB_TOCLKFREQ_MIN1
+
+#define MLB_SD_BCLK_I_DIV   4
+#define MLB_CAL_BCLKFREQ(rate)  (rate / MLB_SD_BCLK_I_DIV / 100)
+#define MLB_BCLKFREQ_MAX255
+#define MLB_BCLKFREQ_MIN  1
+
+#define MLB_CDR_SET0x0230
+#define MLB_CDR_SET_CLK2POW16  3
+
+struct f_sdhost_priv {
+   struct clk *clk_iface;
+   struct clk *clk;
+   struct device *dev;
+   bool enable_cmd_dat_delay;
+   struct gpio_desc *power_gpio;
+};
+
+static void sdhci_milbeaut_soft_voltage_switch(struct sdhci_host *host)
+{
+   u32 ctrl = 0;
+
+   usleep_range(2500, 3000);
+   ctrl = sdhci_readl(host, F_SDH30_IO_CONTROL2);
+   ctrl |= F_SDH30_CRES_O_DN;
+   sdhci_writel(host, ctrl, F_SDH30_IO_CONTROL2);
+   ctrl |= F_SDH30_MSEL_O_1_8;
+   sdhci_writel(host, ctrl, F_SDH30_IO_CONTROL2);
+
+   ctrl &= ~F_SDH30_CRES_O_DN;
+   sdhci_writel(host, ctrl, F_SDH30_IO_CONTROL2);
+   usleep_range(25