From patchwork Thu Sep 10 15:29:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Gorski X-Patchwork-Id: 7154821 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6AA479F326 for ; Thu, 10 Sep 2015 15:29:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7D1EE2085B for ; Thu, 10 Sep 2015 15:29:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D7DE2089F for ; Thu, 10 Sep 2015 15:29:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753024AbbIJP3w (ORCPT ); Thu, 10 Sep 2015 11:29:52 -0400 Received: from arrakis.dune.hu ([78.24.191.176]:57678 "EHLO arrakis.dune.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751981AbbIJP3v (ORCPT ); Thu, 10 Sep 2015 11:29:51 -0400 Received: from localhost (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 2D1DE283F0C; Thu, 10 Sep 2015 17:28:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Virus-Scanned: at arrakis.dune.hu Received: from localhost.localdomain (dslb-088-073-016-160.088.073.pools.vodafone-ip.de [88.73.16.160]) by arrakis.dune.hu (Postfix) with ESMTPSA id DC39228BB92; Thu, 10 Sep 2015 17:28:33 +0200 (CEST) From: Jonas Gorski To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: Mark Brown , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Florian Fainelli Subject: [PATCH 2/2] spi/bcm63xx: add support for probing through devicetree Date: Thu, 10 Sep 2015 17:29:35 +0200 Message-Id: <1441898975-22540-3-git-send-email-jogo@openwrt.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1441898975-22540-1-git-send-email-jogo@openwrt.org> References: <1441898975-22540-1-git-send-email-jogo@openwrt.org> 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 Add required binding support to probe through device tree. Use the compatible instead of the resource size for identifiying the block type, and allow reducing the number of cs lines through OF. Signed-off-by: Jonas Gorski Reviewed-by: Florian Fainelli --- drivers/spi/spi-bcm63xx.c | 56 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/drivers/spi/spi-bcm63xx.c b/drivers/spi/spi-bcm63xx.c index 42f33bc..ec094b1 100644 --- a/drivers/spi/spi-bcm63xx.c +++ b/drivers/spi/spi-bcm63xx.c @@ -26,6 +26,7 @@ #include #include #include +#include /* BCM 6338/6348 SPI core */ #define SPI_6348_RSET_SIZE 64 @@ -465,6 +466,12 @@ static const unsigned long bcm6358_spi_reg_offsets[] = { [SPI_MSG_DATA_SIZE] = SPI_6358_MSG_DATA_SIZE, }; +static const struct of_device_id bcm63xx_spi_of_match[] = { + { .compatible = "brcm,bcm6348-spi", .data = &bcm6348_spi_reg_offsets }, + { .compatible = "brcm,bcm6358-spi", .data = &bcm6358_spi_reg_offsets }, + { }, +}; + static int bcm63xx_spi_probe(struct platform_device *pdev) { struct resource *r; @@ -474,6 +481,7 @@ static int bcm63xx_spi_probe(struct platform_device *pdev) struct clk *clk; struct bcm63xx_spi *bs; int ret; + u32 num_cs = BCM63XX_SPI_MAX_CS; irq = platform_get_irq(pdev, 0); if (irq < 0) { @@ -516,27 +524,46 @@ static int bcm63xx_spi_probe(struct platform_device *pdev) goto out_err; } - master->bus_num = BCM63XX_SPI_BUS_NUM; - master->num_chipselect = BCM63XX_SPI_MAX_CS; master->transfer_one_message = bcm63xx_spi_transfer_one; master->mode_bits = MODEBITS; master->bits_per_word_mask = SPI_BPW_MASK(8); master->auto_runtime_pm = true; - switch (resource_size(r)) { - case SPI_6348_RSET_SIZE: - bs->reg_offsets = bcm6348_spi_reg_offsets; - break; - case SPI_6358_RSET_SIZE: - bs->reg_offsets = bcm6358_spi_reg_offsets; - break; - default: - ret = -EINVAL; - dev_err(dev, "unsupported register size: %i\n", - resource_size(r)); - goto out_err; + if (dev->of_node) { + const struct of_device_id *match; + + match = of_match_node(bcm63xx_spi_of_match, dev->of_node); + if (!match) { + ret = -EINVAL; + goto out_err; + } + bs->reg_offsets = match->data; + master->dev.of_node = dev->of_node; + of_property_read_u32(dev->of_node, "num-cs", &num_cs); + if (num_cs > BCM63XX_SPI_MAX_CS) { + dev_warn(dev, "unsupported number of cs (%i), reducing to 8\n", + num_cs); + num_cs = BCM63XX_SPI_MAX_CS; + } + } else { + master->bus_num = BCM63XX_SPI_BUS_NUM; + + switch (resource_size(r)) { + case SPI_6348_RSET_SIZE: + bs->reg_offsets = bcm6348_spi_reg_offsets; + break; + case SPI_6358_RSET_SIZE: + bs->reg_offsets = bcm6358_spi_reg_offsets; + break; + default: + ret = -EINVAL; + dev_err(dev, "unsupported register size: %i\n", + resource_size(r)); + goto out_err; + } } + master->num_chipselect = num_cs; bs->msg_type_shift = bs->reg_offsets[SPI_MSG_TYPE_SHIFT]; bs->msg_ctl_width = bs->reg_offsets[SPI_MSG_CTL_WIDTH]; bs->fifo_size = bs->reg_offsets[SPI_MSG_DATA_SIZE]; @@ -621,6 +648,7 @@ static struct platform_driver bcm63xx_spi_driver = { .driver = { .name = "bcm63xx-spi", .pm = &bcm63xx_spi_pm_ops, + .of_match_table = bcm63xx_spi_of_match, }, .probe = bcm63xx_spi_probe, .remove = bcm63xx_spi_remove,