From patchwork Fri Oct 28 06:54:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milo Kim X-Patchwork-Id: 9401287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F02086022E for ; Fri, 28 Oct 2016 06:55:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD3F82A5B7 for ; Fri, 28 Oct 2016 06:55:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1EAC2A5BB; Fri, 28 Oct 2016 06:55:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9C9C2A5B7 for ; Fri, 28 Oct 2016 06:55:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757670AbcJ1GzK (ORCPT ); Fri, 28 Oct 2016 02:55:10 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33811 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757640AbcJ1GzF (ORCPT ); Fri, 28 Oct 2016 02:55:05 -0400 Received: by mail-pf0-f195.google.com with SMTP id u84so381296pfj.1; Thu, 27 Oct 2016 23:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1DSrJdQWhBaRcI4LRAygIi+36lwJh2wghOh68gjHM0o=; b=kx0+K0qRHwV3R8B3e7KOWzAdGZE7dSNs7kr/5a4nDHSj4Kp5VBPfw0msIAi2wzgeUb Sf6u8mhRhcKxwTi4BKWXSPJYNa7NXPciWAOAFBTgSKFiXkobnLkC8bdZRPJ6sLGSuvpO czrUoilTZ2v7Y4Hdd5uukjf62LxVxRd9SOopzrwMsxEYPnoGuppM/E3tkiwLdAli8NMw iTxSk+DsXpSVRkGXhBnuS1/8uPTV9QCZQBSI0s8CTkEvBFGq8jx7TpNBnAm2QRZ/KTmd HI/2BJR6DxqZOveLAdUghyYUq8pMy1Tu0bl009QVwsIara1KpF1Myq+T6/lJM52TEHo+ j6VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1DSrJdQWhBaRcI4LRAygIi+36lwJh2wghOh68gjHM0o=; b=dztFg/7304hOLE8MMU09AxRmm7bqzBOG6QkNqk53kpQHSRLzmb9EvP7o/NIYTkOMOG K7Ixu+7l8htDTlb9LwU6UzXjRTfXUZmcj+usdsa7PQIr0ZqO7bHVxeS5l8fFrQIEzrJH nuWtXJORrHUac2hPiJb4sYnZmXcdgmGAPZDT/8X8chcg/guadxBsGT87SP0zcqzA/Z3t Azk3etUbSLkB2vG0kkQoSP1ZCBLaHDN7bGER0nbKYaqflo2HIHoNeBJdTX1eGqtqye/T 2SwIoExQr4iNk5dlePLjb8PoNVoh0cb+okfLpn8l2Kt042TYzr/YAJaaNCGMBqQdZJQk MpHg== X-Gm-Message-State: ABUngvf60YUq1XOYSki5uRf1mUksxSEPE4QmowaHHK2jkMvgmnRgzBLDUVhPqt5T6gEvxA== X-Received: by 10.99.117.71 with SMTP id f7mr17954570pgn.75.1477637704671; Thu, 27 Oct 2016 23:55:04 -0700 (PDT) Received: from localhost.localdomain ([175.223.26.221]) by smtp.gmail.com with ESMTPSA id fg2sm16210184pad.23.2016.10.27.23.55.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Oct 2016 23:55:04 -0700 (PDT) From: Milo Kim To: Maxime Ripard , Chen-Yu Tsai , Mark Brown Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Milo Kim Subject: [PATCH v2 4/4] spi: sun6i: Support Allwinner H3 SPI controller Date: Fri, 28 Oct 2016 15:54:12 +0900 Message-Id: <20161028065412.23008-5-woogyom.kim@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161028065412.23008-1-woogyom.kim@gmail.com> References: <20161028065412.23008-1-woogyom.kim@gmail.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP H3 has two SPI controllers. The size of the buffer is 64 * 8. (8 bit transfer by 64 entry FIFO) A31 has four controllers. The size of the buffer is 128 * 8. (8 bit transfer by 128 entry FIFO) Register maps are sharable, so sun6i SPI driver is reusable with device configuration. Use the variable, 'fifo_depth' instead of fixed value to support both SPI controllers. Cc: Mark Brown Cc: Maxime Ripard Cc: Chen-Yu Tsai Signed-off-by: Milo Kim Acked-by: Maxime Ripard --- drivers/spi/spi-sun6i.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c index 9918a57..e311483 100644 --- a/drivers/spi/spi-sun6i.c +++ b/drivers/spi/spi-sun6i.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,7 @@ #include #define SUN6I_FIFO_DEPTH 128 +#define SUN8I_FIFO_DEPTH 64 #define SUN6I_GBL_CTL_REG 0x04 #define SUN6I_GBL_CTL_BUS_ENABLE BIT(0) @@ -90,6 +92,7 @@ struct sun6i_spi { const u8 *tx_buf; u8 *rx_buf; int len; + unsigned long fifo_depth; }; static inline u32 sun6i_spi_read(struct sun6i_spi *sspi, u32 reg) @@ -155,7 +158,9 @@ static void sun6i_spi_set_cs(struct spi_device *spi, bool enable) static size_t sun6i_spi_max_transfer_size(struct spi_device *spi) { - return SUN6I_FIFO_DEPTH - 1; + struct sun6i_spi *sspi = spi_master_get_devdata(spi->master); + + return sspi->fifo_depth - 1; } static int sun6i_spi_transfer_one(struct spi_master *master, @@ -170,7 +175,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master, u32 reg; /* We don't support transfer larger than the FIFO */ - if (tfr->len > SUN6I_FIFO_DEPTH) + if (tfr->len > sspi->fifo_depth) return -EINVAL; reinit_completion(&sspi->done); @@ -265,7 +270,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master, SUN6I_BURST_CTL_CNT_STC(tx_len)); /* Fill the TX FIFO */ - sun6i_spi_fill_fifo(sspi, SUN6I_FIFO_DEPTH); + sun6i_spi_fill_fifo(sspi, sspi->fifo_depth); /* Enable the interrupts */ sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, SUN6I_INT_CTL_TC); @@ -288,7 +293,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master, goto out; } - sun6i_spi_drain_fifo(sspi, SUN6I_FIFO_DEPTH); + sun6i_spi_drain_fifo(sspi, sspi->fifo_depth); out: sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, 0); @@ -398,6 +403,8 @@ static int sun6i_spi_probe(struct platform_device *pdev) } sspi->master = master; + sspi->fifo_depth = (unsigned long)of_device_get_match_data(&pdev->dev); + master->max_speed_hz = 100 * 1000 * 1000; master->min_speed_hz = 3 * 1000; master->set_cs = sun6i_spi_set_cs; @@ -470,7 +477,8 @@ static int sun6i_spi_remove(struct platform_device *pdev) } static const struct of_device_id sun6i_spi_match[] = { - { .compatible = "allwinner,sun6i-a31-spi", }, + { .compatible = "allwinner,sun6i-a31-spi", .data = (void *)SUN6I_FIFO_DEPTH }, + { .compatible = "allwinner,sun8i-h3-spi", .data = (void *)SUN8I_FIFO_DEPTH }, {} }; MODULE_DEVICE_TABLE(of, sun6i_spi_match);