public inbox for linux-mmc@vger.kernel.org
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: Christian Daudt <csd@broadcom.com>
Cc: Grant Likely <grant.likely@secretlab.ca>,
	Rob Herring <rob.herring@calxeda.com>,
	Rob Landley <rob@landley.net>,
	Russell King <linux@arm.linux.org.uk>,
	Chris Ball <cjb@laptop.org>, Stephen Warren <swarren@nvidia.com>,
	Olof Johansson <olof@lixom.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Wei WANG <wei_wang@realsil.com.cn>,
	Ludovic Desroches <ludovic.desroches@atmel.com>,
	Arnd Bergmann <arnd@arndb.de>,
	"Mike A. Chan" <mikechan@google.com>,
	devicetree-discuss@lists.ozlabs.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-mmc@vger.kernel.org,
	csd_b@daudt.org
Subject: Re: [PATCH] ARM: mmc: bcm281xx SDHCI driver
Date: Fri, 10 May 2013 12:26:58 +0200	[thread overview]
Message-ID: <20130510102658.GK3041@game.jcrosoft.org> (raw)
In-Reply-To: <518CA1DF.5050008@broadcom.com>

On 00:29 Fri 10 May     , Christian Daudt wrote:
> Thanks for the feedback.
> 
> On 13-05-08 11:35 PM, Jean-Christophe PLAGNIOL-VILLARD wrote:
> >On 22:55 Wed 08 May     , Christian Daudt wrote:
> >>Add SDHCI driver for the Broadcom 281xx SoCs. Also
> >>add bindings for it into bcm281xx dts files.
> >>Still missing:
> >>  - power managemement
> >split the dts/dtsi in an other patch
> ok.
> >>Signed-off-by: Christian Daudt <csd@broadcom.com>
> >>
> >>diff --git a/arch/arm/configs/bcm_defconfig b/arch/arm/configs/bcm_defconfig
> >>index e3bf2d6..65edf6d 100644
> >>--- a/arch/arm/configs/bcm_defconfig
> >>+++ b/arch/arm/configs/bcm_defconfig
> >>@@ -78,6 +78,13 @@ CONFIG_BACKLIGHT_LCD_SUPPORT=y
> >>  CONFIG_LCD_CLASS_DEVICE=y
> >>  CONFIG_BACKLIGHT_CLASS_DEVICE=y
> >>  # CONFIG_USB_SUPPORT is not set
> >>+CONFIG_MMC=y
> >>+CONFIG_MMC_UNSAFE_RESUME=y
> >>+CONFIG_MMC_BLOCK_MINORS=32
> >>+CONFIG_MMC_TEST=y
> >>+CONFIG_MMC_SDHCI=y
> >>+CONFIG_MMC_SDHCI_PLTFM=y
> >>+CONFIG_MMC_SDHCI_BCM_KONA=y
> >>  CONFIG_NEW_LEDS=y
> >>  CONFIG_LEDS_CLASS=y
> >>  CONFIG_LEDS_TRIGGERS=y
> >>diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
> >>index d88219e..e067c5a 100644
> >>--- a/drivers/mmc/host/Kconfig
> >>+++ b/drivers/mmc/host/Kconfig
> >>@@ -238,6 +238,16 @@ config MMC_SDHCI_S3C_DMA
> >>  	  YMMV.
> >>+config MMC_SDHCI_BCM_KONA
> >>+	tristate "SDHCI support on Broadcom KONA platform"
> >>+	depends on ARCH_BCM && MMC_SDHCI_PLTFM
> >select MMC_SDHCI_PLTFM
> >will be better
> Ok - changed it. Why is the select is better than the depends ?
> >>+
> >>+static int sdhci_bcm_kona_sd_reset(struct sdhci_host *host)
> >>+{
> >>+	unsigned int val;
> >>+	unsigned long timeout;
> >>+
> >>+	/* This timeout should be sufficent for core to reset */
> >>+	timeout = jiffies + msecs_to_jiffies(100);
> >>+
> >>+	/* reset the host using the top level reset */
> >>+	val = sdhci_readl(host, KONA_SDHOST_CORECTRL);
> >>+	val |= KONA_SDHOST_RESET;
> >>+	sdhci_writel(host, val, KONA_SDHOST_CORECTRL);
> >>+
> >>+	while (!(sdhci_readl(host, KONA_SDHOST_CORECTRL) & KONA_SDHOST_RESET)) {
> >>+		if (time_is_before_jiffies(timeout)) {
> >>+			pr_err("Error: sd host is stuck in reset!!!\n");
> >>+			return -EFAULT;
> >>+		}
> >>+	}
> >>+
> >>+	/* bring the host out of reset */
> >>+	val = sdhci_readl(host, KONA_SDHOST_CORECTRL);
> >>+	val &= ~KONA_SDHOST_RESET;
> >>+
> >>+	/*
> >>+	 * Back-to-Back register write needs a delay of 1ms at bootup (min 10uS)
> >>+	 * Back-to-Back writes to same register needs delay when SD bus clock
> >>+	 * is very low w.r.t AHB clock, mainly during boot-time and during card
> >>+	 * insert-removal.
> >>+	 */
> >>+	udelay(1000);
> >really a udelay of 1ms
> I'm trying to clarify on whether this is really necessary but it
> does seem that this is the case. I'll send a follow-up patch if I
> manage to get confirmation on a smaller safe number.

a smaller delay will be better otherwise a msleep(1)

Best Regards,
J.
> 
> >>+	sdhci_writel(host, val, KONA_SDHOST_CORECTRL);
> >>+
> >>+	return 0;
> >>+}
> >>+
> >>+static void sdhci_bcm_kona_sd_init(struct sdhci_host *host)
> >>+{
> >>+	unsigned int val;
> >>+
> >>+	/* enable the interrupt from the IP core */
> >>+	val = sdhci_readl(host, KONA_SDHOST_COREIMR);
> >>+	val |= KONA_SDHOST_IP;
> >>+	sdhci_writel(host, val, KONA_SDHOST_COREIMR);
> >>+
> >>+	/* Enable the AHB clock gating module to the host */
> >>+	val = sdhci_readl(host, KONA_SDHOST_CORECTRL);
> >>+	val |= KONA_SDHOST_EN;
> >>+
> >>+	/*
> >>+	 * Back-to-Back register write needs a delay of 1ms at bootup (min 10uS)
> >>+	 * Back-to-Back writes to same register needs delay when SD bus clock
> >>+	 * is very low w.r.t AHB clock, mainly during boot-time and during card
> >>+	 * insert-removal.
> >>+	 */
> >>+	udelay(1000);
> >ditto
> see above
> >>+	sdhci_writel(host, val, KONA_SDHOST_CORECTRL);
> >>+}
> >>+
> >>+/*
> >>+ * Software emulation of the SD card insertion/removal. Set insert=1 for insert
> >>+ * and insert=0 for removal. The card detection is done by GPIO. For Broadcom
> >>+ * IP to function properly the bit 0 of CORESTAT register needs to be set/reset
> >>+ * to generate the CD IRQ handled in sdhci.c which schedules card_tasklet.
> >>+ */
> >>+static int sdhci_bcm_kona_sd_card_emulate(struct sdhci_host *host, int insert)
> >>+{
> >>+	struct sdhci_pltfm_host *pltfm_priv = sdhci_priv(host);
> >>+	struct sdhci_bcm_kona_dev *kona_dev = pltfm_priv->priv;
> >>+	u32 val;
> >>+	unsigned long flags;
> >>+
> >>+	/* this function can be called from various contexts including ISR */
> >>+	spin_lock_irqsave(&host->lock, flags);
> >>+	/* Ensure SD bus scanning to detect media change */
> >>+	host->mmc->rescan_disable = 0;
> >>+
> >>+	/*
> >>+	 * Back-to-Back register write needs a delay of min 10uS.
> >>+	 * Back-to-Back writes to same register needs delay when SD bus clock
> >>+	 * is very low w.r.t AHB clock, mainly during boot-time and during card
> >>+	 * insert-removal.
> >>+	 * We keep 20uS
> >>+	 */
> >>+	udelay(20);
> >>+	val = sdhci_readl(host, KONA_SDHOST_CORESTAT);
> >>+
> >>+	if (insert) {
> >>+		if (kona_dev->cfg->wp_gpio >= 0) {
> >gpio_is_valid
> done
> >>+			int wp_status = gpio_get_value(kona_dev->cfg->wp_gpio);
> >>+
> >>+			if (wp_status)
> >>+				val |= KONA_SDHOST_WP;
> >>+			else
> >>+				val &= ~KONA_SDHOST_WP;
> >>+		}
> >>+
> >>+		val |= KONA_SDHOST_CD_SW;
> >>+		sdhci_writel(host, val, KONA_SDHOST_CORESTAT);
> >>+	} else {
> >>+		val &= ~KONA_SDHOST_CD_SW;
> >>+		sdhci_writel(host, val, KONA_SDHOST_CORESTAT);
> >>+	}
> >>+	spin_unlock_irqrestore(&host->lock, flags);
> >>+
> >>+	return 0;
> >>+}
> >>+
> >>+/*
> >>+ * SD card detection interrupt handler
> >>+ */
> >>+static irqreturn_t sdhci_bcm_kona_pltfm_cd_interrupt(int irq, void *host)
> >>+{
> >>+	struct sdhci_pltfm_host *pltfm_priv = sdhci_priv(host);
> >>+	struct sdhci_bcm_kona_dev *kona_dev = pltfm_priv->priv;
> >>+
> >>+	if (gpio_get_value_cansleep(kona_dev->cfg->cd_gpio) == 0) {
> >>+		pr_debug("card inserted\n");
> >dev_dbg
> done
> >>+		sdhci_bcm_kona_sd_card_emulate(host, 1);
> >>+	} else {
> >>+		pr_debug("card removed\n");
> >ditto
> done
> >>+static struct sdhci_bcm_kona_cfg * __init sdhci_bcm_kona_parse_dt(
> >>+			struct platform_device *pdev)
> >>+{
> >>+	struct sdhci_bcm_kona_cfg *cfg;
> >>+	struct device_node *np = pdev->dev.of_node;
> >>+	u32 temp;
> >>+
> >>+	if (!np)
> >>+		return NULL;
> >>+
> >>+	cfg = devm_kzalloc(&pdev->dev, sizeof(*cfg), GFP_KERNEL);
> >>+	if (!cfg) {
> >>+		dev_err(&pdev->dev, "Can't allocate platform cfg\n");
> >>+		return NULL;
> >>+	}
> >>+
> >>+	cfg->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0);
> >>+	cfg->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0);
> >>+	if (of_get_property(np, "non-removable", NULL))
> >>+		cfg->non_removable = 1;
> >use of_property_read_bool
> done
> >>+		/* Sleep for 128ms to allow debounce to stabilize */
> >>+		msleep(SD_DETECT_GPIO_DEBOUNCE_128MS);
> >>+		/* request irq for cd_gpio after the gpio debounce is
> >>+		 * stabilized, otherwise, some bogus gpio interrupts might be
> >>+		 * triggered.
> >>+		 */
> >>+		irq = gpio_to_irq(kona_dev->cfg->cd_gpio);
> >>+		ret = devm_request_threaded_irq(dev,
> >>+				irq,
> >>+				NULL,
> >>+				sdhci_bcm_kona_pltfm_cd_interrupt,
> >>+				IRQF_TRIGGER_FALLING|
> >>+				IRQF_TRIGGER_RISING |
> >>+				IRQF_ONESHOT |
> >>+				IRQF_NO_SUSPEND, "sdio cd", host);
> >>+		if (ret) {
> >>+			dev_err(kona_dev->dev,
> >>+				"Unable to request card detection irq=%d"
> >>+				" for gpio=%d  ret=%d\n",
> >put the sting of the dev_err on one line so we can grep
> merged it into single line
> 
> 
>  Thanks,
>    csd
> 
> 

  reply	other threads:[~2013-05-10 10:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-09  5:55 [PATCH] ARM: mmc: bcm281xx SDHCI driver Christian Daudt
2013-05-09  6:35 ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-10  7:23   ` Christian Daudt
2013-05-10  7:29   ` Christian Daudt
2013-05-10 10:26     ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2013-05-10 14:37     ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-10  7:45   ` Christian Daudt
2013-05-11  4:28 ` Stephen Warren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130510102658.GK3041@game.jcrosoft.org \
    --to=plagnioj@jcrosoft.com \
    --cc=arnd@arndb.de \
    --cc=cjb@laptop.org \
    --cc=csd@broadcom.com \
    --cc=csd_b@daudt.org \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=ludovic.desroches@atmel.com \
    --cc=mikechan@google.com \
    --cc=olof@lixom.net \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=swarren@nvidia.com \
    --cc=wei_wang@realsil.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox