Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1376658ybt; Sun, 14 Jun 2020 21:08:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynZh40CUJREupHD9YbMiRE95O+tUBBmFvaz0JAczxc75l888tVNYRKjhU3/gAptjhl/Xgg X-Received: by 2002:a17:906:55c9:: with SMTP id z9mr24998676ejp.276.1592194114333; Sun, 14 Jun 2020 21:08:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592194114; cv=none; d=google.com; s=arc-20160816; b=EHLVWrNHsqFze/r9Ql/vY+F36yf7njiOygD7HNGwu5BYHi0M192QhhoXvY9V6TkrNX 3OgRL9z4TkxJ6NT3HhYYkB2vDNdTPvMKeohawGwUbGaappzX8XL6TyHOuOcjAjZdZmRT HS798Ifg9VnohQZ1/jX/Z6m7jDkUMvmWBW2YSfuO+YtgUZTyAmsIV/ycvcVhOWk3UDBB aWvf1btDssjo2e4GXZOSFM2btd+WcyMdT/xEXJJf5ENSgd9Tfy5wpsfXBBccQmHE0FiS 3Cj3esWWwzW1mSVF5E35bwaLUYmZWeQYtzvaJz6Z8ij+da+ORLFyMn3jCif56O4n56iK 72yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BtcDdq8igGetN/jELHWNV2M1CB6861dCLDtHKsKlFzY=; b=mf1ZVyW9mPRYe48EmM0VLdOKGKdgARMucRS1nDfcHyNeuv+6k2B1WfEByobSrKVFK0 G77DtwsO4WTpPUEcU42E8CUxYr745bgPDOOa/lsXdw9oS6kc6n+GKyq6xTgtH2OzT+tn OOvTNP/b6BdnNwvrovQfkmpOLU2PmQHcUwsxNOu2pIq2ZJY06uznlrkh1y7pbV7vpIuZ E0pKIDAv/O2AlV2iHqq9rdlTXeMzrdcSkigKXTkMcq56BA5GtOQ8JZ5e7laMhn3CAddL 0jzh+QEJ0Rxzkh8zH95JhQPZ21W2seQ2MPAazqWo6cz0W5Cs7oZOOWG08cPVt9Vhcz1L pXQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alliedtelesis.co.nz header.s=mail181024 header.b=o62exfEM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alliedtelesis.co.nz Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qk2si8587587ejb.271.2020.06.14.21.08.12; Sun, 14 Jun 2020 21:08:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alliedtelesis.co.nz header.s=mail181024 header.b=o62exfEM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alliedtelesis.co.nz Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727971AbgFOEGE (ORCPT + 99 others); Mon, 15 Jun 2020 00:06:04 -0400 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:50502 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725294AbgFOEGB (ORCPT ); Mon, 15 Jun 2020 00:06:01 -0400 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 8F437891B0; Mon, 15 Jun 2020 16:05:57 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1592193957; bh=BtcDdq8igGetN/jELHWNV2M1CB6861dCLDtHKsKlFzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=o62exfEMNl+ll+E9nfhS4jp9iwhjYH/X8Sl8S1PEIk67KvmzTx9EkewxFwWISGeBn boACE7L2ZU4qwIcEdCYtrUoGQYJ3mNCv672JB9pvju+3E2AwumJ2I2DMdBwhqnus67 Tp1PVw0XVC6rfS07QqwA7iFqGel+RaiUW6FTBPGEk4sdocy7TsUXhzeQn3DMd0fsjB sXPcw5fnoj29PVQJvv+ROgnLmIogm+fgPvoGoXmr3QE3qx+cWPfl9KRbLrJ4xFTQBE /Df9VC+ejPrNBacXmgc34pOJDOBVC6LPfSePauvMD/sEGcsPDNF4uNx13+yFhUGqyr cCcFXZHeArgHg== Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7,5,8,10121) id ; Mon, 15 Jun 2020 16:05:57 +1200 Received: from markto-dl.ws.atlnz.lc (markto-dl.ws.atlnz.lc [10.33.23.25]) by smtp (Postfix) with ESMTP id 9AF4F13EEBA; Mon, 15 Jun 2020 16:05:56 +1200 (NZST) Received: by markto-dl.ws.atlnz.lc (Postfix, from userid 1155) id 4C90F341107; Mon, 15 Jun 2020 16:05:57 +1200 (NZST) From: Mark Tomlinson To: broonie@kernel.org, kdasu.kdev@gmail.com Cc: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Mark Tomlinson Subject: [PATCH 1/5] spi: bcm-qspi: Add support for setting BSPI clock Date: Mon, 15 Jun 2020 16:05:53 +1200 Message-Id: <20200615040557.2011-2-mark.tomlinson@alliedtelesis.co.nz> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200615040557.2011-1-mark.tomlinson@alliedtelesis.co.nz> References: <20200615040557.2011-1-mark.tomlinson@alliedtelesis.co.nz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable x-atlnz-ls: pat Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On iProc devices (unlike previous BCM SoCs) the clock rate of the SPI can be set. This patch adds the appropriate code for setting that. Reviewed-by: Callum Sinclair Reviewed-by: Chris Packham Signed-off-by: Mark Tomlinson --- drivers/spi/spi-bcm-qspi.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/spi/spi-bcm-qspi.c b/drivers/spi/spi-bcm-qspi.c index 681d09085175..8fc5b9b3757b 100644 --- a/drivers/spi/spi-bcm-qspi.c +++ b/drivers/spi/spi-bcm-qspi.c @@ -117,6 +117,13 @@ =20 #define MSPI_MSPI_STATUS_SPIF BIT(0) =20 +#define CRU_CTRL_REG 0x0 +#define QSPI_CLK_SEL_25M 0x00 +#define QSPI_CLK_SEL_50M 0x02 +#define QSPI_CLK_SEL_31M25 0x04 +#define QSPI_CLK_SEL_62M5 0x06 +#define QSPI_CLK_SEL_MASK 0x06 + #define INTR_BASE_BIT_SHIFT 0x02 #define INTR_COUNT 0x07 =20 @@ -170,6 +177,7 @@ enum base_type { MSPI, BSPI, CHIP_SELECT, + CRU_CTRL, BASEMAX, }; =20 @@ -625,6 +633,7 @@ static void bcm_qspi_update_parms(struct bcm_qspi *qs= pi, static int bcm_qspi_setup(struct spi_device *spi) { struct bcm_qspi_parms *xp; + struct bcm_qspi *qspi =3D spi_master_get_devdata(spi->master); =20 if (spi->bits_per_word > 16) return -EINVAL; @@ -639,6 +648,21 @@ static int bcm_qspi_setup(struct spi_device *spi) xp->speed_hz =3D spi->max_speed_hz; xp->mode =3D spi->mode; =20 + if (qspi->base[CRU_CTRL]) { + u32 tmp =3D bcm_qspi_read(qspi, CRU_CTRL, CRU_CTRL_REG); + + /* Set BSPI clock rate */ + tmp &=3D ~QSPI_CLK_SEL_MASK; + if (spi->max_speed_hz >=3D 62500000) + tmp |=3D QSPI_CLK_SEL_62M5; + else if (spi->max_speed_hz >=3D 50000000) + tmp |=3D QSPI_CLK_SEL_50M; + else if (spi->max_speed_hz >=3D 31250000) + tmp |=3D QSPI_CLK_SEL_31M25; + /* default is 25MHz */ + bcm_qspi_write(qspi, CRU_CTRL, CRU_CTRL_REG, tmp); + } + if (spi->bits_per_word) xp->bits_per_word =3D spi->bits_per_word; else @@ -1459,6 +1483,16 @@ int bcm_qspi_probe(struct platform_device *pdev, qspi->soc_intc =3D NULL; } =20 + /* iProc BSPI clock is set through CRU control */ + res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, "cru_ctrl"); + if (res) { + qspi->base[CRU_CTRL] =3D devm_ioremap_resource(dev, res); + if (IS_ERR(qspi->base[CRU_CTRL])) { + ret =3D PTR_ERR(qspi->base[CRU_CTRL]); + goto qspi_probe_err; + } + } + ret =3D clk_prepare_enable(qspi->clk); if (ret) { dev_err(dev, "failed to prepare clock\n"); --=20 2.27.0