From patchwork Tue Aug 6 21:40:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 2839670 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 18A689F479 for ; Tue, 6 Aug 2013 21:47:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EF0F7201FE for ; Tue, 6 Aug 2013 21:47:40 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B2B00201FC for ; Tue, 6 Aug 2013 21:47:39 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6p64-0006Kc-Ct; Tue, 06 Aug 2013 21:47:16 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6p5u-00030p-WA; Tue, 06 Aug 2013 21:47:07 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6p5m-0002xn-7c for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2013 21:47:00 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id r76LkcIi014405; Tue, 6 Aug 2013 16:46:38 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id r76LkcvD017024; Tue, 6 Aug 2013 16:46:38 -0500 Received: from dlelxv22.itg.ti.com (172.17.1.197) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.2.342.3; Tue, 6 Aug 2013 16:46:38 -0500 Received: from localhost (irmo.am.dhcp.ti.com [128.247.74.241]) by dlelxv22.itg.ti.com (8.13.8/8.13.8) with ESMTP id r76LkcJb024192; Tue, 6 Aug 2013 16:46:38 -0500 From: Suman Anna To: Tony Lindgren , Benoit Cousson Subject: [PATCHv3 2/8] mailbox/omap: add support for parsing dt devices Date: Tue, 6 Aug 2013 16:40:16 -0500 Message-ID: <1375825216-18119-1-git-send-email-s-anna@ti.com> X-Mailer: git-send-email 1.8.3.3 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130806_174658_454372_7DD96C3C X-CRM114-Status: GOOD ( 22.48 ) X-Spam-Score: -6.9 (------) Cc: Ohad Ben-Cohen , devicetree@vger.kernel.org, Paul Walmsley , Suman Anna , Jassi Brar , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Logic has been added to the OMAP2+ mailbox code to parse the mailbox dt nodes and construct the different mailboxes associated with the instance. The design is based on gathering the same information that was being passed previously through the platform data, except for the interrupt type configuration information. Signed-off-by: Suman Anna --- .../devicetree/bindings/mailbox/omap-mailbox.txt | 43 +++++++ drivers/mailbox/mailbox-omap2.c | 130 ++++++++++++++++++--- 2 files changed, 158 insertions(+), 15 deletions(-) create mode 100644 Documentation/devicetree/bindings/mailbox/omap-mailbox.txt diff --git a/Documentation/devicetree/bindings/mailbox/omap-mailbox.txt b/Documentation/devicetree/bindings/mailbox/omap-mailbox.txt new file mode 100644 index 0000000..8ffb08a --- /dev/null +++ b/Documentation/devicetree/bindings/mailbox/omap-mailbox.txt @@ -0,0 +1,43 @@ +OMAP2+ Mailbox Driver + +Required properties: +- compatible: Should be one of the following, + "ti,omap2-mailbox" for + OMAP2420, OMAP2430, OMAP3430, OMAP3630 SoCs + "ti,omap4-mailbox" for + OMAP44xx, OMAP54xx, AM33xx, AM43xx, DRA7xx SoCs +- reg: Contains the mailbox register address range (base address + and length) +- interrupts: Contains the interrupt information for the mailbox + device. The format is dependent on which interrupt + controller the OMAP device uses +- ti,hwmods: Name of the hwmod associated with the mailbox +- ti,mbox-num-users: Number of targets (processor devices) that the mailbox device + can interrupt +- ti,mbox-num-fifos: Number of h/w fifos within the mailbox device +- ti,mbox-names: Array of the names of the mailboxes +- ti,mbox-data: Mailbox descriptor data private to each mailbox. The 4 + cells represent the following data, + Cell #1 (tx_id) - mailbox fifo id used for + transmitting messages + Cell #2 (rx_id) - mailbox fifo id on which messages + are received + Cell #3 (irq_id) - irq identifier index number to use + from the interrupts data + Cell #4 (usr_id) - mailbox user id for identifying the + interrupt into the MPU interrupt + controller. + +Example: + +/* OMAP4 */ +mailbox: mailbox@4a0f4000 { + compatible = "ti,omap4-mailbox"; + reg = <0x4a0f4000 0x200>; + interrupts = ; + ti,hwmods = "mailbox"; + ti,mbox-num-users = <3>; + ti,mbox-num-fifos = <8>; + ti,mbox-names = "mbox-ipu", "mbox-dsp"; + ti,mbox-data = <0 1 0 0>, <3 2 0 0>; +}; diff --git a/drivers/mailbox/mailbox-omap2.c b/drivers/mailbox/mailbox-omap2.c index 6c0687c..759f72c 100644 --- a/drivers/mailbox/mailbox-omap2.c +++ b/drivers/mailbox/mailbox-omap2.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -222,6 +223,21 @@ static struct omap_mbox_ops omap2_mbox_ops = { .restore_ctx = omap2_mbox_restore_ctx, }; +static const struct of_device_id omap_mailbox_of_match[] = { + { + .compatible = "ti,omap2-mailbox", + .data = (void *) MBOX_INTR_CFG_TYPE1, + }, + { + .compatible = "ti,omap4-mailbox", + .data = (void *) MBOX_INTR_CFG_TYPE2, + }, + { + /* end */ + }, +}; +MODULE_DEVICE_TABLE(of, omap_mailbox_of_match); + static int omap2_mbox_probe(struct platform_device *pdev) { struct resource *mem; @@ -229,47 +245,127 @@ static int omap2_mbox_probe(struct platform_device *pdev) struct omap_mbox **list, *mbox, *mboxblk; struct omap_mbox2_priv *priv, *privblk; struct omap_mbox_pdata *pdata = pdev->dev.platform_data; - struct omap_mbox_dev_info *info; struct omap_mbox_device *mdev; - int i; - - if (!pdata || !pdata->info_cnt || !pdata->info) { + struct omap_mbox_dev_info *info, *of_info = NULL; + struct device_node *node = pdev->dev.of_node; + int i, j; + u32 info_count = 0, intr_type = 0; + u32 num_users = 0, num_fifos = 0; + u32 dlen, dsize = 4; + u32 *tmp; + const __be32 *mbox_data; + + if (!node && (!pdata || !pdata->info_cnt || !pdata->info)) { pr_err("%s: platform not supported\n", __func__); return -ENODEV; } + if (node) { + intr_type = (u32)of_match_device(omap_mailbox_of_match, + &pdev->dev)->data; + if (intr_type != 0 && intr_type != 1) { + dev_err(&pdev->dev, "invalid match data value\n"); + return -EINVAL; + } + + if (of_property_read_u32(node, "ti,mbox-num-users", + &num_users)) { + dev_err(&pdev->dev, + "no ti,mbox-num-users configuration found\n"); + return -ENODEV; + } + + if (of_property_read_u32(node, "ti,mbox-num-fifos", + &num_fifos)) { + dev_err(&pdev->dev, + "no ti,mbox-num-fifos configuration found\n"); + return -ENODEV; + } + + info_count = of_property_count_strings(node, "ti,mbox-names"); + if (!info_count) { + dev_err(&pdev->dev, "no mbox devices found\n"); + return -ENODEV; + } + + mbox_data = of_get_property(node, "ti,mbox-data", &dlen); + if (!mbox_data) { + dev_err(&pdev->dev, "no mbox device data found\n"); + return -ENODEV; + } + dlen /= sizeof(dsize); + if (dlen != dsize * info_count) { + dev_err(&pdev->dev, "mbox device data is truncated\n"); + return -ENODEV; + } + + of_info = kzalloc(info_count * sizeof(*of_info), GFP_KERNEL); + if (!of_info) + return -ENOMEM; + + i = 0; + while (i < info_count) { + info = of_info + i; + if (of_property_read_string_index(node, + "ti,mbox-names", i, &info->name)) { + dev_err(&pdev->dev, + "mbox_name [%d] read failed\n", i); + ret = -ENODEV; + goto free_of; + } + + tmp = &info->tx_id; + for (j = 0; j < dsize; j++) { + tmp[j] = of_read_number( + mbox_data + j + (i * dsize), 1); + } + i++; + } + } + + if (!node) { /* non-DT device creation */ + info_count = pdata->info_cnt; + info = pdata->info; + intr_type = pdata->intr_type; + num_users = pdata->num_users; + num_fifos = pdata->num_fifos; + } else { + info = of_info; + } + mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); - if (!mdev) - return -ENOMEM; + if (!mdev) { + ret = -ENOMEM; + goto free_of; + } /* allocate one extra for marking end of list */ - list = kzalloc((pdata->info_cnt + 1) * sizeof(*list), GFP_KERNEL); + list = kzalloc((info_count + 1) * sizeof(*list), GFP_KERNEL); if (!list) { ret = -ENOMEM; goto free_mdev; } - mboxblk = mbox = kzalloc(pdata->info_cnt * sizeof(*mbox), GFP_KERNEL); + mboxblk = mbox = kzalloc(info_count * sizeof(*mbox), GFP_KERNEL); if (!mboxblk) { ret = -ENOMEM; goto free_list; } - privblk = priv = kzalloc(pdata->info_cnt * sizeof(*priv), GFP_KERNEL); + privblk = priv = kzalloc(info_count * sizeof(*priv), GFP_KERNEL); if (!privblk) { ret = -ENOMEM; goto free_mboxblk; } - info = pdata->info; - for (i = 0; i < pdata->info_cnt; i++, info++, priv++) { + for (i = 0; i < info_count; i++, info++, priv++) { priv->tx_fifo.msg = MAILBOX_MESSAGE(info->tx_id); priv->tx_fifo.fifo_stat = MAILBOX_FIFOSTATUS(info->tx_id); priv->rx_fifo.msg = MAILBOX_MESSAGE(info->rx_id); priv->rx_fifo.msg_stat = MAILBOX_MSGSTATUS(info->rx_id); priv->notfull_bit = MAILBOX_IRQ_NOTFULL(info->tx_id); priv->newmsg_bit = MAILBOX_IRQ_NEWMSG(info->rx_id); - if (pdata->intr_type) { + if (intr_type) { priv->irqenable = OMAP4_MAILBOX_IRQENABLE(info->usr_id); priv->irqstatus = OMAP4_MAILBOX_IRQSTATUS(info->usr_id); priv->irqdisable = @@ -279,7 +375,7 @@ static int omap2_mbox_probe(struct platform_device *pdev) priv->irqstatus = MAILBOX_IRQSTATUS(info->usr_id); priv->irqdisable = MAILBOX_IRQENABLE(info->usr_id); } - priv->intr_type = pdata->intr_type; + priv->intr_type = intr_type; mbox->priv = priv; mbox->parent = mdev; @@ -307,8 +403,8 @@ static int omap2_mbox_probe(struct platform_device *pdev) mutex_init(&mdev->cfg_lock); mdev->dev = &pdev->dev; - mdev->num_users = pdata->num_users; - mdev->num_fifos = pdata->num_fifos; + mdev->num_users = num_users; + mdev->num_fifos = num_fifos; mdev->mboxes = list; ret = omap_mbox_register(&pdev->dev, list); if (ret) @@ -317,6 +413,7 @@ static int omap2_mbox_probe(struct platform_device *pdev) pm_runtime_enable(mdev->dev); + kfree(of_info); return 0; unmap_mbox: @@ -329,6 +426,8 @@ free_list: kfree(list); free_mdev: kfree(mdev); +free_of: + kfree(of_info); return ret; } @@ -358,6 +457,7 @@ static struct platform_driver omap2_mbox_driver = { .remove = omap2_mbox_remove, .driver = { .name = "omap-mailbox", + .of_match_table = omap_mailbox_of_match, }, };