| @@ -2,7 +2,7 @@ · 1 unmodified line |
| 2 | 2 | * OMAP mailbox driver |
| 3 | 3 | * |
| 4 | 4 | * Copyright (C) 2006-2009 Nokia Corporation. All rights reserved. |
| 5 | | − * Copyright (C) 2013-2014 Texas Instruments Inc. |
| 5 | + * Copyright (C) 2013-2016 Texas Instruments Incorporated - http://www.ti.com |
| 6 | 6 | * |
| 7 | 7 | * Contact: Hiroshi DOYU <Hiroshi.DOYU@nokia.com> |
| 8 | 8 | * Suman Anna <s-anna@ti.com> |
| @@ -15,12 +15,6 @@ · 6 unmodified lines |
| 15 | 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | 17 | * General Public License for more details. |
| 18 | | − * |
| 19 | | − * You should have received a copy of the GNU General Public License |
| 20 | | − * along with this program; if not, write to the Free Software |
| 21 | | − * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 22 | | − * 02110-1301 USA |
| 23 | | − * |
| 24 | 18 | */ |
| 25 | 19 | |
| 26 | 20 | #include <linux/interrupt.h> |
| @@ -33,7 +27,6 @@ · 6 unmodified lines |
| 33 | 27 | #include <linux/of_device.h> |
| 34 | 28 | #include <linux/platform_device.h> |
| 35 | 29 | #include <linux/pm_runtime.h> |
| 36 | | −#include <linux/platform_data/mailbox-omap.h> |
| 37 | 30 | #include <linux/omap-mailbox.h> |
| 38 | 31 | #include <linux/mailbox_controller.h> |
| 39 | 32 | #include <linux/mailbox_client.h> |
| @@ -62,12 +55,9 @@ · 22 unmodified lines |
| 62 | 55 | #define MAILBOX_IRQ_NEWMSG(m) (1 << (2 * (m))) |
| 63 | 56 | #define MAILBOX_IRQ_NOTFULL(m) (1 << (2 * (m) + 1)) |
| 64 | 57 | |
| 65 | | −#define MBOX_REG_SIZE 0x120 |
| 66 | | − |
| 67 | | −#define OMAP4_MBOX_REG_SIZE 0x130 |
| 68 | | − |
| 69 | | −#define MBOX_NR_REGS (MBOX_REG_SIZE / sizeof(u32)) |
| 70 | | −#define OMAP4_MBOX_NR_REGS (OMAP4_MBOX_REG_SIZE / sizeof(u32)) |
| 58 | +/* Interrupt register configuration types */ |
| 59 | +#define MBOX_INTR_CFG_TYPE1 0 |
| 60 | +#define MBOX_INTR_CFG_TYPE2 1 |
| 71 | 61 | |
| 72 | 62 | struct omap_mbox_fifo { |
| 73 | 63 | unsigned long msg; |
| @@ -91,8 +81,10 @@ struct omap_mbox_device { · 17 unmodified lines |
| 91 | 81 | struct device *dev; |
| 92 | 82 | struct mutex cfg_lock; |
| 93 | 83 | void __iomem *mbox_base; |
| 84 | + u32 *irq_ctx; |
| 94 | 85 | u32 num_users; |
| 95 | 86 | u32 num_fifos; |
| 87 | + u32 intr_type; |
| 96 | 88 | struct omap_mbox **mboxes; |
| 97 | 89 | struct mbox_controller controller; |
| 98 | 90 | struct list_head elem; |
| @@ -119,7 +111,6 @@ struct omap_mbox { · 20 unmodified lines |
| 119 | 111 | struct omap_mbox_device *parent; |
| 120 | 112 | struct omap_mbox_fifo tx_fifo; |
| 121 | 113 | struct omap_mbox_fifo rx_fifo; |
| 122 | | − u32 ctx[OMAP4_MBOX_NR_REGS]; |
| 123 | 114 | u32 intr_type; |
| 124 | 115 | struct mbox_chan *chan; |
| 125 | 116 | bool send_no_irq; |
| @@ -157,24 +148,28 @@ void mbox_write_reg(struct omap_mbox_device *mdev, u32 val, size_t ofs) · 31 unmodified lines |
| 157 | 148 | static mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox) |
| 158 | 149 | { |
| 159 | 150 | struct omap_mbox_fifo *fifo = &mbox->rx_fifo; |
| 160 | | − return (mbox_msg_t) mbox_read_reg(mbox->parent, fifo->msg); |
| 151 | + |
| 152 | + return (mbox_msg_t)mbox_read_reg(mbox->parent, fifo->msg); |
| 161 | 153 | } |
| 162 | 154 | |
| 163 | 155 | static void mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg) |
| 164 | 156 | { |
| 165 | 157 | struct omap_mbox_fifo *fifo = &mbox->tx_fifo; |
| 158 | + |
| 166 | 159 | mbox_write_reg(mbox->parent, msg, fifo->msg); |
| 167 | 160 | } |
| 168 | 161 | |
| 169 | 162 | static int mbox_fifo_empty(struct omap_mbox *mbox) |
| 170 | 163 | { |
| 171 | 164 | struct omap_mbox_fifo *fifo = &mbox->rx_fifo; |
| 165 | + |
| 172 | 166 | return (mbox_read_reg(mbox->parent, fifo->msg_stat) == 0); |
| 173 | 167 | } |
| 174 | 168 | |
| 175 | 169 | static int mbox_fifo_full(struct omap_mbox *mbox) |
| 176 | 170 | { |
| 177 | 171 | struct omap_mbox_fifo *fifo = &mbox->tx_fifo; |
| 172 | + |
| 178 | 173 | return mbox_read_reg(mbox->parent, fifo->fifo_stat); |
| 179 | 174 | } |
| 180 | 175 | |
| @@ -206,49 +201,6 @@ static int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) · 25 unmodified lines |
| 206 | 201 | return (int)(enable & status & bit); |
| 207 | 202 | } |
| 208 | 203 | |
| 209 | | −void omap_mbox_save_ctx(struct mbox_chan *chan) |
| 210 | | −{ |
| 211 | | − int i; |
| 212 | | − int nr_regs; |
| 213 | | − struct omap_mbox *mbox = mbox_chan_to_omap_mbox(chan); |
| 214 | | − |
| 215 | | − if (WARN_ON(!mbox)) |
| 216 | | − return; |
| 217 | | − |
| 218 | | − if (mbox->intr_type) |
| 219 | | − nr_regs = OMAP4_MBOX_NR_REGS; |
| 220 | | − else |
| 221 | | − nr_regs = MBOX_NR_REGS; |
| 222 | | − for (i = 0; i < nr_regs; i++) { |
| 223 | | − mbox->ctx[i] = mbox_read_reg(mbox->parent, i * sizeof(u32)); |
| 224 | | − |
| 225 | | − dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__, |
| 226 | | − i, mbox->ctx[i]); |
| 227 | | − } |
| 228 | | −} |
| 229 | | −EXPORT_SYMBOL(omap_mbox_save_ctx); |
| 230 | | − |
| 231 | | −void omap_mbox_restore_ctx(struct mbox_chan *chan) |
| 232 | | −{ |
| 233 | | − int i; |
| 234 | | − int nr_regs; |
| 235 | | − struct omap_mbox *mbox = mbox_chan_to_omap_mbox(chan); |
| 236 | | − |
| 237 | | − if (WARN_ON(!mbox)) |
| 238 | | − return; |
| 239 | | − |
| 240 | | − if (mbox->intr_type) |
| 241 | | − nr_regs = OMAP4_MBOX_NR_REGS; |
| 242 | | − else |
| 243 | | − nr_regs = MBOX_NR_REGS; |
| 244 | | − for (i = 0; i < nr_regs; i++) { |
| 245 | | − mbox_write_reg(mbox->parent, mbox->ctx[i], i * sizeof(u32)); |
| 246 | | − dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__, |
| 247 | | − i, mbox->ctx[i]); |
| 248 | | − } |
| 249 | | −} |
| 250 | | −EXPORT_SYMBOL(omap_mbox_restore_ctx); |
| 251 | | − |
| 252 | 204 | static void _omap_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) |
| 253 | 205 | { |
| 254 | 206 | u32 l; |
| @@ -381,7 +333,7 @@ static struct omap_mbox_queue *mbox_queue_alloc(struct omap_mbox *mbox, · 126 unmodified lines |
| 381 | 333 | if (!work) |
| 382 | 334 | return NULL; |
| 383 | 335 | |
| 384 | | − mq = kzalloc(sizeof(struct omap_mbox_queue), GFP_KERNEL); |
| 336 | + mq = kzalloc(sizeof(*mq), GFP_KERNEL); |
| 385 | 337 | if (!mq) |
| 386 | 338 | return NULL; |
| 387 | 339 | |
| @@ -525,6 +477,7 @@ static int omap_mbox_register(struct omap_mbox_device *mdev) · 137 unmodified lines |
| 525 | 477 | mboxes = mdev->mboxes; |
| 526 | 478 | for (i = 0; mboxes[i]; i++) { |
| 527 | 479 | struct omap_mbox *mbox = mboxes[i]; |
| 480 | + |
| 528 | 481 | mbox->dev = device_create(&omap_mbox_class, mdev->dev, |
| 529 | 482 | 0, mbox, "%s", mbox->name); |
| 530 | 483 | if (IS_ERR(mbox->dev)) { |
| @@ -647,6 +600,52 @@ static const struct mbox_chan_ops omap_mbox_chan_ops = { · 116 unmodified lines |
| 647 | 600 | .shutdown = omap_mbox_chan_shutdown, |
| 648 | 601 | }; |
| 649 | 602 | |
| 603 | +#ifdef CONFIG_PM_SLEEP |
| 604 | +static int omap_mbox_suspend(struct device *dev) |
| 605 | +{ |
| 606 | + struct omap_mbox_device *mdev = dev_get_drvdata(dev); |
| 607 | + u32 usr, fifo, reg; |
| 608 | + |
| 609 | + if (pm_runtime_status_suspended(dev)) |
| 610 | + return 0; |
| 611 | + |
| 612 | + for (fifo = 0; fifo < mdev->num_fifos; fifo++) { |
| 613 | + if (mbox_read_reg(mdev, MAILBOX_MSGSTATUS(fifo))) { |
| 614 | + dev_err(mdev->dev, "fifo %d has unexpected unread messages\n", |
| 615 | + fifo); |
| 616 | + return -EBUSY; |
| 617 | + } |
| 618 | + } |
| 619 | + |
| 620 | + for (usr = 0; usr < mdev->num_users; usr++) { |
| 621 | + reg = MAILBOX_IRQENABLE(mdev->intr_type, usr); |
| 622 | + mdev->irq_ctx[usr] = mbox_read_reg(mdev, reg); |
| 623 | + } |
| 624 | + |
| 625 | + return 0; |
| 626 | +} |
| 627 | + |
| 628 | +static int omap_mbox_resume(struct device *dev) |
| 629 | +{ |
| 630 | + struct omap_mbox_device *mdev = dev_get_drvdata(dev); |
| 631 | + u32 usr, reg; |
| 632 | + |
| 633 | + if (pm_runtime_status_suspended(dev)) |
| 634 | + return 0; |
| 635 | + |
| 636 | + for (usr = 0; usr < mdev->num_users; usr++) { |
| 637 | + reg = MAILBOX_IRQENABLE(mdev->intr_type, usr); |
| 638 | + mbox_write_reg(mdev, mdev->irq_ctx[usr], reg); |
| 639 | + } |
| 640 | + |
| 641 | + return 0; |
| 642 | +} |
| 643 | +#endif |
| 644 | + |
| 645 | +static const struct dev_pm_ops omap_mbox_pm_ops = { |
| 646 | + SET_SYSTEM_SLEEP_PM_OPS(omap_mbox_suspend, omap_mbox_resume) |
| 647 | +}; |
| 648 | + |
| 650 | 649 | static const struct of_device_id omap_mailbox_of_match[] = { |
| 651 | 650 | { |
| 652 | 651 | .compatible = "ti,omap2-mailbox", |
| @@ -696,8 +695,6 @@ static int omap_mbox_probe(struct platform_device *pdev) · 43 unmodified lines |
| 696 | 695 | int ret; |
| 697 | 696 | struct mbox_chan *chnls; |
| 698 | 697 | struct omap_mbox **list, *mbox, *mboxblk; |
| 699 | | − struct omap_mbox_pdata *pdata = pdev->dev.platform_data; |
| 700 | | − struct omap_mbox_dev_info *info = NULL; |
| 701 | 698 | struct omap_mbox_fifo_info *finfo, *finfoblk; |
| 702 | 699 | struct omap_mbox_device *mdev; |
| 703 | 700 | struct omap_mbox_fifo *fifo; |
| @@ -710,36 +707,26 @@ static int omap_mbox_probe(struct platform_device *pdev) · 6 unmodified lines |
| 710 | 707 | u32 l; |
| 711 | 708 | int i; |
| 712 | 709 | |
| 713 | | − if (!node && (!pdata || !pdata->info_cnt || !pdata->info)) { |
| 714 | | − pr_err("%s: platform not supported\n", __func__); |
| 710 | + if (!node) { |
| 711 | + pr_err("%s: only DT-based devices are supported\n", __func__); |
| 715 | 712 | return -ENODEV; |
| 716 | 713 | } |
| 717 | 714 | |
| 718 | | − if (node) { |
| 719 | | − match = of_match_device(omap_mailbox_of_match, &pdev->dev); |
| 720 | | − if (!match) |
| 721 | | − return -ENODEV; |
| 722 | | − intr_type = (u32)match->data; |
| 715 | + match = of_match_device(omap_mailbox_of_match, &pdev->dev); |
| 716 | + if (!match) |
| 717 | + return -ENODEV; |
| 718 | + intr_type = (u32)match->data; |
| 723 | 719 | |
| 724 | | − if (of_property_read_u32(node, "ti,mbox-num-users", |
| 725 | | − &num_users)) |
| 726 | | − return -ENODEV; |
| 720 | + if (of_property_read_u32(node, "ti,mbox-num-users", &num_users)) |
| 721 | + return -ENODEV; |
| 727 | 722 | |
| 728 | | − if (of_property_read_u32(node, "ti,mbox-num-fifos", |
| 729 | | − &num_fifos)) |
| 730 | | − return -ENODEV; |
| 723 | + if (of_property_read_u32(node, "ti,mbox-num-fifos", &num_fifos)) |
| 724 | + return -ENODEV; |
| 731 | 725 | |
| 732 | | − info_count = of_get_available_child_count(node); |
| 733 | | − if (!info_count) { |
| 734 | | − dev_err(&pdev->dev, "no available mbox devices found\n"); |
| 735 | | − return -ENODEV; |
| 736 | | − } |
| 737 | | − } else { /* non-DT device creation */ |
| 738 | | − info_count = pdata->info_cnt; |
| 739 | | − info = pdata->info; |
| 740 | | − intr_type = pdata->intr_type; |
| 741 | | − num_users = pdata->num_users; |
| 742 | | − num_fifos = pdata->num_fifos; |
| 726 | + info_count = of_get_available_child_count(node); |
| 727 | + if (!info_count) { |
| 728 | + dev_err(&pdev->dev, "no available mbox devices found\n"); |
| 729 | + return -ENODEV; |
| 743 | 730 | } |
| 744 | 731 | |
| 745 | 732 | finfoblk = devm_kzalloc(&pdev->dev, info_count * sizeof(*finfoblk), |
| @@ -750,38 +737,28 @@ static int omap_mbox_probe(struct platform_device *pdev) · 4 unmodified lines |
| 750 | 737 | finfo = finfoblk; |
| 751 | 738 | child = NULL; |
| 752 | 739 | for (i = 0; i < info_count; i++, finfo++) { |
| 753 | | − if (node) { |
| 754 | | − child = of_get_next_available_child(node, child); |
| 755 | | − ret = of_property_read_u32_array(child, "ti,mbox-tx", |
| 756 | | − tmp, ARRAY_SIZE(tmp)); |
| 757 | | − if (ret) |
| 758 | | − return ret; |
| 759 | | − finfo->tx_id = tmp[0]; |
| 760 | | − finfo->tx_irq = tmp[1]; |
| 761 | | − finfo->tx_usr = tmp[2]; |
| 762 | | − |
| 763 | | − ret = of_property_read_u32_array(child, "ti,mbox-rx", |
| 764 | | − tmp, ARRAY_SIZE(tmp)); |
| 765 | | − if (ret) |
| 766 | | − return ret; |
| 767 | | − finfo->rx_id = tmp[0]; |
| 768 | | − finfo->rx_irq = tmp[1]; |
| 769 | | − finfo->rx_usr = tmp[2]; |
| 770 | | − |
| 771 | | − finfo->name = child->name; |
| 772 | | − |
| 773 | | − if (of_find_property(child, "ti,mbox-send-noirq", NULL)) |
| 774 | | − finfo->send_no_irq = true; |
| 775 | | − } else { |
| 776 | | − finfo->tx_id = info->tx_id; |
| 777 | | − finfo->rx_id = info->rx_id; |
| 778 | | − finfo->tx_usr = info->usr_id; |
| 779 | | − finfo->tx_irq = info->irq_id; |
| 780 | | − finfo->rx_usr = info->usr_id; |
| 781 | | − finfo->rx_irq = info->irq_id; |
| 782 | | − finfo->name = info->name; |
| 783 | | − info++; |
| 784 | | − } |
| 740 | + child = of_get_next_available_child(node, child); |
| 741 | + ret = of_property_read_u32_array(child, "ti,mbox-tx", tmp, |
| 742 | + ARRAY_SIZE(tmp)); |
| 743 | + if (ret) |
| 744 | + return ret; |
| 745 | + finfo->tx_id = tmp[0]; |
| 746 | + finfo->tx_irq = tmp[1]; |
| 747 | + finfo->tx_usr = tmp[2]; |
| 748 | + |
| 749 | + ret = of_property_read_u32_array(child, "ti,mbox-rx", tmp, |
| 750 | + ARRAY_SIZE(tmp)); |
| 751 | + if (ret) |
| 752 | + return ret; |
| 753 | + finfo->rx_id = tmp[0]; |
| 754 | + finfo->rx_irq = tmp[1]; |
| 755 | + finfo->rx_usr = tmp[2]; |
| 756 | + |
| 757 | + finfo->name = child->name; |
| 758 | + |
| 759 | + if (of_find_property(child, "ti,mbox-send-noirq", NULL)) |
| 760 | + finfo->send_no_irq = true; |
| 761 | + |
| 785 | 762 | if (finfo->tx_id >= num_fifos || finfo->rx_id >= num_fifos || |
| 786 | 763 | finfo->tx_usr >= num_users || finfo->rx_usr >= num_users) |
| 787 | 764 | return -EINVAL; |
| @@ -796,6 +773,11 @@ static int omap_mbox_probe(struct platform_device *pdev) · 8 unmodified lines |
| 796 | 773 | if (IS_ERR(mdev->mbox_base)) |
| 797 | 774 | return PTR_ERR(mdev->mbox_base); |
| 798 | 775 | |
| 776 | + mdev->irq_ctx = devm_kzalloc(&pdev->dev, num_users * sizeof(u32), |
| 777 | + GFP_KERNEL); |
| 778 | + if (!mdev->irq_ctx) |
| 779 | + return -ENOMEM; |
| 780 | + |
| 799 | 781 | /* allocate one extra for marking end of list */ |
| 800 | 782 | list = devm_kzalloc(&pdev->dev, (info_count + 1) * sizeof(*list), |
| 801 | 783 | GFP_KERNEL); |
| @@ -848,6 +830,7 @@ static int omap_mbox_probe(struct platform_device *pdev) · 46 unmodified lines |
| 848 | 830 | mdev->dev = &pdev->dev; |
| 849 | 831 | mdev->num_users = num_users; |
| 850 | 832 | mdev->num_fifos = num_fifos; |
| 833 | + mdev->intr_type = intr_type; |
| 851 | 834 | mdev->mboxes = list; |
| 852 | 835 | |
| 853 | 836 | /* OMAP does not have a Tx-Done IRQ, but rather a Tx-Ready IRQ */ |
| @@ -905,6 +888,7 @@ static struct platform_driver omap_mbox_driver = { · 51 unmodified lines |
| 905 | 888 | .remove = omap_mbox_remove, |
| 906 | 889 | .driver = { |
| 907 | 890 | .name = "omap-mailbox", |
| 891 | + .pm = &omap_mbox_pm_ops, |
| 908 | 892 | .of_match_table = of_match_ptr(omap_mailbox_of_match), |
| 909 | 893 | }, |
| 910 | 894 | }; |