From patchwork Mon Mar 25 23:00:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Brugger X-Patchwork-Id: 2333891 Return-Path: X-Original-To: patchwork-spi-devel-general@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by patchwork2.kernel.org (Postfix) with ESMTP id 65FEDDF24C for ; Mon, 25 Mar 2013 23:00:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1UKGNg-0000yY-1w; Mon, 25 Mar 2013 23:00:44 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1UKGNe-0000yP-LO for spi-devel-general@lists.sourceforge.net; Mon, 25 Mar 2013 23:00:42 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of gmail.com designates 209.85.212.170 as permitted sender) client-ip=209.85.212.170; envelope-from=matthias.bgg@gmail.com; helo=mail-wi0-f170.google.com; Received: from mail-wi0-f170.google.com ([209.85.212.170]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1UKGNd-0004h4-QE for spi-devel-general@lists.sourceforge.net; Mon, 25 Mar 2013 23:00:42 +0000 Received: by mail-wi0-f170.google.com with SMTP id hm11so11686017wib.5 for ; Mon, 25 Mar 2013 16:00:35 -0700 (PDT) X-Received: by 10.194.95.198 with SMTP id dm6mr21128464wjb.6.1364252435625; Mon, 25 Mar 2013 16:00:35 -0700 (PDT) Received: from ubi.home (32.pool85-58-18.dynamic.orange.es. [85.58.18.32]) by mx.google.com with ESMTPS id g9sm16662061wix.1.2013.03.25.16.00.33 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 25 Mar 2013 16:00:35 -0700 (PDT) From: Matthias Brugger To: Grant Likely , Rob Herring , Rob Landley , Mark Brown , Daniel Mack , Matthias Brugger , "Enric Balletbo Serra" , "Javier Martinez Canillas" , devicetree-discuss@lists.ozlabs.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, spi-devel-general@lists.sourceforge.net, linux-omap@vger.kernel.org, ezequiel.garcia@free-electrons.com Subject: [PATCH] spi: spi-omap2-mcspi.c: Add dts for slave device configuration. Date: Tue, 26 Mar 2013 00:00:15 +0100 Message-Id: <1364252415-3613-1-git-send-email-matthias.bgg@gmail.com> X-Mailer: git-send-email 1.7.11.7 X-Spam-Score: -1.6 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (matthias.bgg[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1UKGNd-0004h4-QE X-BeenThere: spi-devel-general@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux SPI core/device drivers discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: spi-devel-general-bounces@lists.sourceforge.net TI omap2 mcspi allows the slave devices to configure the behavior of the SPI master. This patch adds device tree support to the existing options. Signed-off-by: Matthias Brugger --- Documentation/devicetree/bindings/spi/omap-spi.txt | 23 ++++++++++++ drivers/spi/spi-omap2-mcspi.c | 41 ++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/Documentation/devicetree/bindings/spi/omap-spi.txt b/Documentation/devicetree/bindings/spi/omap-spi.txt index 938809c..fef16bf 100644 --- a/Documentation/devicetree/bindings/spi/omap-spi.txt +++ b/Documentation/devicetree/bindings/spi/omap-spi.txt @@ -10,8 +10,20 @@ Required properties: input. The default is D0 as input and D1 as output. +SPI Controller specific data in SPI slave nodes: + +- The spi slave nodes can provide the following information which is used + by the spi controller. + +- ti,spi-cs-per-word: Set chipselect to be toggled on every word send. + +- ti,spi-turbo-mode: Set turbo mode for this device. + + Example: +- SoC Specific Portion: + mcspi1: mcspi@1 { #address-cells = <1>; #size-cells = <0>; @@ -20,3 +32,14 @@ mcspi1: mcspi@1 { ti,spi-num-cs = <4>; }; +- Board Specific Portion: + + spi-device@0 { + #address-cells = <1>; + #size-cells = <1>; + + controller-data { + ti,spi-cs-per-word = <1>; + ti,spi-turbo-mode = <0>; + }; + }; diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index 893c3d7..1ae5009 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -731,11 +731,47 @@ static u32 omap2_mcspi_calc_divisor(u32 speed_hz) return 15; } +static struct omap2_mcspi_device_config *omap2_mcspi_get_slave_ctrldata( + struct spi_device *spi) +{ + struct omap2_mcspi_device_config *cd; + struct device_node *slave_np, *data_np = NULL; + + slave_np = spi->dev.of_node; + if (!slave_np) { + dev_err(&spi->dev, "device node not found\n"); + return ERR_PTR(-EINVAL); + } + + data_np = of_get_child_by_name(slave_np, "controller-data"); + if (!data_np) { + dev_err(&spi->dev, "child node 'controller-data' not found\n"); + return ERR_PTR(-EINVAL); + } + + cd = kzalloc(sizeof(*cd), GFP_KERNEL); + if (!cd) { + dev_err(&spi->dev, "could not allocate memory for controller data\n"); + of_node_put(data_np); + return ERR_PTR(-ENOMEM); + } + + if (of_get_property(data_np, "ti,spi-cs-per-word", NULL)) + cd->cs_per_word = 1; + + if (of_get_property(data_np, "ti,spi-turbo-mode", NULL)) + cd->turbo_mode = 1; + + of_node_put(data_np); + return cd; +} + /* called only when no transfer is active to this device */ static int omap2_mcspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) { struct omap2_mcspi_cs *cs = spi->controller_state; + struct omap2_mcspi_device_config *cd = spi->controller_data; struct omap2_mcspi *mcspi; struct spi_master *spi_cntrl; u32 l = 0, div = 0; @@ -745,6 +781,11 @@ static int omap2_mcspi_setup_transfer(struct spi_device *spi, mcspi = spi_master_get_devdata(spi->master); spi_cntrl = mcspi->master; + if (!cd && spi->dev.of_node) { + cd = omap2_mcspi_get_slave_ctrldata(spi); + spi->controller_data = cd; + } + if (t != NULL && t->bits_per_word) word_len = t->bits_per_word;