From patchwork Wed Nov 7 11:40:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastian Hecht X-Patchwork-Id: 1710201 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 9ABE8DFB7A for ; Wed, 7 Nov 2012 11:42:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754773Ab2KGLmU (ORCPT ); Wed, 7 Nov 2012 06:42:20 -0500 Received: from mail-bk0-f46.google.com ([209.85.214.46]:40222 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754815Ab2KGLmT (ORCPT ); Wed, 7 Nov 2012 06:42:19 -0500 Received: by mail-bk0-f46.google.com with SMTP id jk13so636954bkc.19 for ; Wed, 07 Nov 2012 03:42:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=8BangKwglFj0J18lLfIQ2GOscGkRzG/AURcTXyEZFwE=; b=DJV5cW/lYm5gibdfOpqtEav/A0zpC+Dm3tpwtObGz+I8LXh5WPMkl8FCeg+aODTNqK JACFOfuZxFsYzJqipZHpPXllj2KuurB9jGIO6mgJEhAzIwiTclYBZZMLyXV7/QlgeOA1 aS0QYqNrD+11XyeFMbzXqhkr93wIvXbX1C+cfRUQk523m0CjkpVFjtDmcfPJNjf7sNYh PKNtQZrBYuJlbMSmK4/r/nJwO7aJijhSggmVGSrzc4kFw28GAwkEtYAXhlOdRBjcOBZl W3K6H3cgVDIO+sPfZ1nHiaAKLID0ifQirnyLlJ1AktVVdSKjbeJBaFJ5SA7By/mm4g4I ICWg== Received: by 10.204.129.211 with SMTP id p19mr1057516bks.94.1352288538973; Wed, 07 Nov 2012 03:42:18 -0800 (PST) Received: from localhost.localdomain (p4FD24697.dip.t-dialin.net. [79.210.70.151]) by mx.google.com with ESMTPS id r15sm14130206bkw.9.2012.11.07.03.42.17 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 07 Nov 2012 03:42:18 -0800 (PST) From: Bastian Hecht To: spi-devel-general@lists.sourceforge.net Cc: linux-sh@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Magnus Damm Subject: [PATCH 3/4] spi: sh-msiof: Add device tree parsing to driver Date: Wed, 7 Nov 2012 12:40:06 +0100 Message-Id: <1352288407-20594-4-git-send-email-hechtb@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1352288407-20594-1-git-send-email-hechtb@gmail.com> References: <1352288407-20594-1-git-send-email-hechtb@gmail.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org This adds the capability to retrieve setup data from the device tree node. The usage of platform data is still available. Signed-off-by: Bastian Hecht --- drivers/spi/spi-sh-msiof.c | 54 +++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 53 insertions(+), 1 deletions(-) diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c index 96358d0..65cd19c 100644 --- a/drivers/spi/spi-sh-msiof.c +++ b/drivers/spi/spi-sh-msiof.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -592,6 +593,35 @@ static u32 sh_msiof_spi_txrx_word(struct spi_device *spi, unsigned nsecs, return 0; } +#ifdef CONFIG_OF +static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev) +{ + struct sh_msiof_spi_info *info; + struct device_node *np = dev->of_node; + u32 chipselect = 0; + + info = devm_kzalloc(dev, sizeof(struct sh_msiof_spi_info), GFP_KERNEL); + if (!info) { + dev_err(dev, "failed to allocate setup data\n"); + return NULL; + } + + /* Parse the MSIOF properties */ + of_property_read_u32(np, "chip-select", &chipselect); + of_property_read_u32(np, "tx_fifo_size", &info->tx_fifo_override); + of_property_read_u32(np, "rx_fifo_size", &info->rx_fifo_override); + + info->num_chipselect = chipselect; + + return info; +} +#else +static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev) +{ + return NULL; +} +#endif + static int sh_msiof_spi_probe(struct platform_device *pdev) { struct resource *r; @@ -610,7 +640,17 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) p = spi_master_get_devdata(master); platform_set_drvdata(pdev, p); - p->info = pdev->dev.platform_data; + if (pdev->dev.of_node) + p->info = sh_msiof_spi_parse_dt(&pdev->dev); + else + p->info = pdev->dev.platform_data; + + if (!p->info) { + dev_err(&pdev->dev, "failed to obtain device info\n"); + ret = -ENXIO; + goto err1; + } + init_completion(&p->done); p->clk = clk_get(&pdev->dev, NULL); @@ -715,6 +755,17 @@ static int sh_msiof_spi_runtime_nop(struct device *dev) return 0; } +#ifdef CONFIG_OF +static const struct of_device_id sh_msiof_match[] = { + { .compatible = "renesas,sh-msiof", }, + { .compatible = "renesas,sh-mobile-msiof", }, + {}, +}; +MODULE_DEVICE_TABLE(of, sh_msiof_match); +#else +#define sh_msiof_match NULL +#endif + static struct dev_pm_ops sh_msiof_spi_dev_pm_ops = { .runtime_suspend = sh_msiof_spi_runtime_nop, .runtime_resume = sh_msiof_spi_runtime_nop, @@ -727,6 +778,7 @@ static struct platform_driver sh_msiof_spi_drv = { .name = "spi_sh_msiof", .owner = THIS_MODULE, .pm = &sh_msiof_spi_dev_pm_ops, + .of_match_table = sh_msiof_match, }, }; module_platform_driver(sh_msiof_spi_drv);