From patchwork Wed Jan 13 23:25:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 567197 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 6FC321401CA for ; Thu, 14 Jan 2016 10:46:26 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=gAh80AsZ; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 92EC162262; Thu, 14 Jan 2016 00:46:24 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t_Xpdp3zSZFS; Thu, 14 Jan 2016 00:46:24 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B3559622B7; Thu, 14 Jan 2016 00:40:42 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EFF36621F6 for ; Thu, 14 Jan 2016 00:36:29 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lI9D77X1aZHx for ; Thu, 14 Jan 2016 00:36:29 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-oi0-f50.google.com (mail-oi0-f50.google.com [209.85.218.50]) by theia.denx.de (Postfix) with ESMTPS id 086C16221E for ; Thu, 14 Jan 2016 00:33:31 +0100 (CET) Received: by mail-oi0-f50.google.com with SMTP id k206so104906810oia.1 for ; Wed, 13 Jan 2016 15:33:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=uneGhKdDpN/w6XrkmZgOnq2jF215BJ23v78Xd1hqcwg=; b=gAh80AsZIq9M+TPDx36TCQRK/qOGDsekX85jRJPUlYZsKZQhp+yvpl8EHV+f1J9biX 9WZ/RqkiWWk1Nng8ulqFnxFYzboMOUIr3GEjguBi+hp7IuUVt0Vx004oX9cCNw7q/oW5 8WG0MhIx5HdaqYpbFSMDC1KRIWrHffOgSqHdTYRYtxR2L4o11Q+6s1at1ukFKkSFXF2Z y3sSJ2pMxjzxnrWV2Lqfe271KDufmujPRCO89sgMwBp5rsSII43IOqXUWxldArRYvD1v 2CcFg+v+Y4LesCosrNJO7iwV+hzIWlmHk6q12Cw2EaHmHIMRjpbeUMEmYrZyjsLr0RWo 8b8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=uneGhKdDpN/w6XrkmZgOnq2jF215BJ23v78Xd1hqcwg=; b=juVVHnpujM2DabcieoFB6v3LkU2p7AxwPS/UEaRtH66QYUITFntxwC6OEPuXY7K2dX ETL0VhtNVMqXMjJaurLIJax7lofqUFHuPqUS6wKt2wyFTxbVmxt/3c/l9wzGUe+94Lz8 URkpBm8Xa5461At36MX6NGBEjG23TOxxrGL8ZENk+1vFTZ8sXratiyU8sDXTZDspE8aQ gXsljCEJX5xjhwHCmxCD/eNc10lX+0MPOxAGzrnllQBlvR+TXruIF5mqykMiLb9yiJam 9svdtypdKwgWc7TSgsf4W3v3W7Xh1oPhcXv40963greQ6jVOFAlMwiG4KMhvzCB49MWp foLA== X-Gm-Message-State: ALoCoQmnD1pxuBCiHIxK5hKEPaCwJTyjtpHLodTlT66TLMMTSszCam6vDUHW6FcNh60aXNmuiNuziz62NRDBObVJI8mnIH8GxQ== X-Received: by 10.202.72.14 with SMTP id v14mr695188oia.120.1452728009509; Wed, 13 Jan 2016 15:33:29 -0800 (PST) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by smtp.gmail.com with ESMTPSA id e195sm1904880oic.1.2016.01.13.15.33.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jan 2016 15:33:26 -0800 (PST) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id B340122231F; Wed, 13 Jan 2016 16:26:26 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Wed, 13 Jan 2016 16:25:37 -0700 Message-Id: <1452727540-3249-48-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 In-Reply-To: <1452727540-3249-1-git-send-email-sjg@chromium.org> References: <1452727540-3249-1-git-send-email-sjg@chromium.org> Cc: Jeffy Chen , Jagan Teki Subject: [U-Boot] [PATCH 47/50] rockchip: spi: Implement the delays X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Some devices need delays before and after activiation. Implement these features in the SPI driver so that we will be able to enable the Chrome OS EC. Signed-off-by: Simon Glass --- drivers/spi/rk_spi.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/spi/rk_spi.c b/drivers/spi/rk_spi.c index 2570ca3..91538b4 100644 --- a/drivers/spi/rk_spi.c +++ b/drivers/spi/rk_spi.c @@ -32,6 +32,7 @@ struct rockchip_spi_platdata { s32 frequency; /* Default clock frequency, -1 for none */ fdt_addr_t base; uint deactivate_delay_us; /* Delay to wait after deactivate */ + uint activate_delay_us; /* Delay to wait after activate */ }; struct rockchip_spi_priv { @@ -101,16 +102,32 @@ static int rkspi_wait_till_not_busy(struct rockchip_spi *regs) return 0; } -static void spi_cs_activate(struct rockchip_spi *regs, uint cs) +static void spi_cs_activate(struct udevice *dev, uint cs) { + struct udevice *bus = dev->parent; + struct rockchip_spi_platdata *plat = bus->platdata; + struct rockchip_spi_priv *priv = dev_get_priv(bus); + struct rockchip_spi *regs = priv->regs; + debug("activate cs%u\n", cs); writel(1 << cs, ®s->ser); + if (plat->activate_delay_us) + udelay(plat->activate_delay_us); } -static void spi_cs_deactivate(struct rockchip_spi *regs, uint cs) +static void spi_cs_deactivate(struct udevice *dev, uint cs) { + struct udevice *bus = dev->parent; + struct rockchip_spi_platdata *plat = bus->platdata; + struct rockchip_spi_priv *priv = dev_get_priv(bus); + struct rockchip_spi *regs = priv->regs; + debug("deactivate cs%u\n", cs); writel(0, ®s->ser); + + /* Remember time of this transaction so we can honour the bus delay */ + if (plat->deactivate_delay_us) + priv->last_transaction_us = timer_get_us(); } static int rockchip_spi_ofdata_to_platdata(struct udevice *bus) @@ -144,6 +161,8 @@ static int rockchip_spi_ofdata_to_platdata(struct udevice *bus) 50000000); plat->deactivate_delay_us = fdtdec_get_int(blob, node, "spi-deactivate-delay", 0); + plat->activate_delay_us = fdtdec_get_int(blob, node, + "spi-activate-delay", 0); debug("%s: base=%x, periph_id=%d, max-frequency=%d, deactivate_delay=%d\n", __func__, (uint)plat->base, plat->periph_id, plat->frequency, plat->deactivate_delay_us); @@ -289,7 +308,7 @@ static int rockchip_spi_xfer(struct udevice *dev, unsigned int bitlen, /* Assert CS before transfer */ if (flags & SPI_XFER_BEGIN) - spi_cs_activate(regs, slave_plat->cs); + spi_cs_activate(dev, slave_plat->cs); while (len > 0) { int todo = min(len, 0xffff); @@ -323,7 +342,7 @@ static int rockchip_spi_xfer(struct udevice *dev, unsigned int bitlen, /* Deassert CS after transfer */ if (flags & SPI_XFER_END) - spi_cs_deactivate(regs, slave_plat->cs); + spi_cs_deactivate(dev, slave_plat->cs); rkspi_enable_chip(regs, false);