linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/7] OMAP: mailbox: removing static declarations
@ 2011-06-25  1:17 Omar Ramirez Luna
  2011-06-25  1:17 ` [RFC PATCH 1/7] OMAP2+: hwmod_data: define number of mailboxes Omar Ramirez Luna
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Omar Ramirez Luna @ 2011-06-25  1:17 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

This is the first attempt in making the omap mailbox framework generic
enough to support other mailbox drivers, in this series the way the mailbox
are defined and registered is changed to support requests of mailboxes through
an id. So far, the mailbox static declarations have been removed allowing
a dynamic mailbox configuration.

The next steps would involve removing omap references in the code and omap
specific fields (like "type" embedded in the operations structure) along with
a trivial cleanup.

The end goal would be moving the mailbox driver into drivers folder and also
converting other mailbox drivers to reuse this code, the first candidate being
ux-500 mailbox driver (arch/arm/mach-ux500/mbox-db5500.c).

Tested using one patch on top of Kevin Hilman mailbox loopback test, can be
found at: https://gitorious.org/~or.rmz/omap-test/mbox-test-clone

If accepted patches 5 to 7 should be a single patch, to avoid compilation issues.

I'll appreciate any comments or suggestions.

Omar Ramirez Luna (7):
  OMAP2+: hwmod_data: define number of mailboxes
  OMAP2+: devices: get the number of supported mailboxes
  OMAP: mailbox: use OMAP's naming convention for devices
  OMAP: mailbox: move framework functions under header file
  OMAP: mailbox: implement dynamic mailbox configuration
  OMAP1: mailbox: adapt to dynamic mailbox requests
  OMAP2+: mailbox: remove mailbox static declarations

 arch/arm/mach-omap1/mailbox.c              |   94 +++++----
 arch/arm/mach-omap2/devices.c              |    8 +-
 arch/arm/mach-omap2/mailbox.c              |  212 +++++---------------
 arch/arm/mach-omap2/omap_hwmod_2420_data.c |    6 +
 arch/arm/mach-omap2/omap_hwmod_2430_data.c |    6 +
 arch/arm/mach-omap2/omap_hwmod_3xxx_data.c |    6 +
 arch/arm/mach-omap2/omap_hwmod_44xx_data.c |    6 +
 arch/arm/plat-omap/include/plat/mailbox.h  |   62 +++----
 arch/arm/plat-omap/mailbox.c               |  298 ++++++++++++++++++----------
 9 files changed, 364 insertions(+), 334 deletions(-)

Regards,

Omar

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [RFC PATCH 1/7] OMAP2+: hwmod_data: define number of mailboxes
  2011-06-25  1:17 [RFC PATCH 0/7] OMAP: mailbox: removing static declarations Omar Ramirez Luna
@ 2011-06-25  1:17 ` Omar Ramirez Luna
  2011-06-25  1:17 ` [RFC PATCH 2/7] OMAP2+: devices: get the number of supported mailboxes Omar Ramirez Luna
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Omar Ramirez Luna @ 2011-06-25  1:17 UTC (permalink / raw)
  To: linux-arm-kernel

Define number of mailboxes available to a specific chip.

Signed-off-by: Omar Ramirez Luna <omar.ramirez@ti.com>
---
 arch/arm/mach-omap2/omap_hwmod_2420_data.c |    6 ++++++
 arch/arm/mach-omap2/omap_hwmod_2430_data.c |    6 ++++++
 arch/arm/mach-omap2/omap_hwmod_3xxx_data.c |    6 ++++++
 arch/arm/mach-omap2/omap_hwmod_44xx_data.c |    6 ++++++
 arch/arm/plat-omap/include/plat/mailbox.h  |    8 ++++++++
 5 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-omap2/omap_hwmod_2420_data.c b/arch/arm/mach-omap2/omap_hwmod_2420_data.c
index c4d0ae8..6493eb5 100644
--- a/arch/arm/mach-omap2/omap_hwmod_2420_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_2420_data.c
@@ -18,6 +18,7 @@
 #include <plat/serial.h>
 #include <plat/i2c.h>
 #include <plat/gpio.h>
+#include <plat/mailbox.h>
 #include <plat/mcspi.h>
 #include <plat/dmtimer.h>
 #include <plat/l3_2xxx.h>
@@ -1855,6 +1856,10 @@ static struct omap_hwmod_class omap2420_mailbox_hwmod_class = {
 	.sysc = &omap2420_mailbox_sysc,
 };
 
+static struct omap_mailbox_dev_attr mailbox_dev_attr = {
+	.nr_mbox	= 6,
+};
+
 /* mailbox */
 static struct omap_hwmod omap2420_mailbox_hwmod;
 static struct omap_hwmod_irq_info omap2420_mailbox_irqs[] = {
@@ -1899,6 +1904,7 @@ static struct omap_hwmod omap2420_mailbox_hwmod = {
 			.idlest_idle_bit = OMAP24XX_ST_MAILBOXES_SHIFT,
 		},
 	},
+	.dev_attr	= &mailbox_dev_attr,
 	.slaves		= omap2420_mailbox_slaves,
 	.slaves_cnt	= ARRAY_SIZE(omap2420_mailbox_slaves),
 	.omap_chip	= OMAP_CHIP_INIT(CHIP_IS_OMAP2420),
diff --git a/arch/arm/mach-omap2/omap_hwmod_2430_data.c b/arch/arm/mach-omap2/omap_hwmod_2430_data.c
index 9682dd5..8d9d455 100644
--- a/arch/arm/mach-omap2/omap_hwmod_2430_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_2430_data.c
@@ -18,6 +18,7 @@
 #include <plat/serial.h>
 #include <plat/i2c.h>
 #include <plat/gpio.h>
+#include <plat/mailbox.h>
 #include <plat/mcbsp.h>
 #include <plat/mcspi.h>
 #include <plat/dmtimer.h>
@@ -1989,6 +1990,10 @@ static struct omap_hwmod_class omap2430_mailbox_hwmod_class = {
 	.sysc = &omap2430_mailbox_sysc,
 };
 
+static struct omap_mailbox_dev_attr mailbox_dev_attr = {
+	.nr_mbox	= 6,
+};
+
 /* mailbox */
 static struct omap_hwmod omap2430_mailbox_hwmod;
 static struct omap_hwmod_irq_info omap2430_mailbox_irqs[] = {
@@ -2032,6 +2037,7 @@ static struct omap_hwmod omap2430_mailbox_hwmod = {
 			.idlest_idle_bit = OMAP24XX_ST_MAILBOXES_SHIFT,
 		},
 	},
+	.dev_attr	= &mailbox_dev_attr,
 	.slaves		= omap2430_mailbox_slaves,
 	.slaves_cnt	= ARRAY_SIZE(omap2430_mailbox_slaves),
 	.omap_chip	= OMAP_CHIP_INIT(CHIP_IS_OMAP2430),
diff --git a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
index 909a84d..d7fa0ae 100644
--- a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
@@ -22,6 +22,7 @@
 #include <plat/l4_3xxx.h>
 #include <plat/i2c.h>
 #include <plat/gpio.h>
+#include <plat/mailbox.h>
 #include <plat/mmc.h>
 #include <plat/mcbsp.h>
 #include <plat/mcspi.h>
@@ -3022,6 +3023,10 @@ static struct omap_hwmod_class omap3xxx_mailbox_hwmod_class = {
 	.sysc = &omap3xxx_mailbox_sysc,
 };
 
+static struct omap_mailbox_dev_attr mailbox_dev_attr = {
+	.nr_mbox	= 6,
+};
+
 static struct omap_hwmod omap3xxx_mailbox_hwmod;
 static struct omap_hwmod_irq_info omap3xxx_mailbox_irqs[] = {
 	{ .irq = 26 },
@@ -3064,6 +3069,7 @@ static struct omap_hwmod omap3xxx_mailbox_hwmod = {
 			.idlest_idle_bit = OMAP3430_ST_MAILBOXES_SHIFT,
 		},
 	},
+	.dev_attr	= &mailbox_dev_attr,
 	.slaves		= omap3xxx_mailbox_slaves,
 	.slaves_cnt	= ARRAY_SIZE(omap3xxx_mailbox_slaves),
 	.omap_chip	= OMAP_CHIP_INIT(CHIP_IS_OMAP3430),
diff --git a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
index e1c69ff..eb279f0 100644
--- a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
@@ -24,6 +24,7 @@
 #include <plat/cpu.h>
 #include <plat/gpio.h>
 #include <plat/dma.h>
+#include <plat/mailbox.h>
 #include <plat/mcspi.h>
 #include <plat/mcbsp.h>
 #include <plat/mmc.h>
@@ -2717,6 +2718,10 @@ static struct omap_hwmod_class omap44xx_mailbox_hwmod_class = {
 	.sysc	= &omap44xx_mailbox_sysc,
 };
 
+static struct omap_mailbox_dev_attr mailbox_dev_attr = {
+	.nr_mbox	= 8,
+};
+
 /* mailbox */
 static struct omap_hwmod omap44xx_mailbox_hwmod;
 static struct omap_hwmod_irq_info omap44xx_mailbox_irqs[] = {
@@ -2756,6 +2761,7 @@ static struct omap_hwmod omap44xx_mailbox_hwmod = {
 			.clkctrl_reg = OMAP4430_CM_L4CFG_MAILBOX_CLKCTRL,
 		},
 	},
+	.dev_attr	= &mailbox_dev_attr,
 	.slaves		= omap44xx_mailbox_slaves,
 	.slaves_cnt	= ARRAY_SIZE(omap44xx_mailbox_slaves),
 	.omap_chip	= OMAP_CHIP_INIT(CHIP_IS_OMAP4430),
diff --git a/arch/arm/plat-omap/include/plat/mailbox.h b/arch/arm/plat-omap/include/plat/mailbox.h
index cc3921e..337b93c 100644
--- a/arch/arm/plat-omap/include/plat/mailbox.h
+++ b/arch/arm/plat-omap/include/plat/mailbox.h
@@ -41,6 +41,14 @@ struct omap_mbox_ops {
 	void		(*restore_ctx)(struct omap_mbox *mbox);
 };
 
+struct omap_mailbox_dev_attr {
+	u16		nr_mbox;
+};
+
+struct omap_mailbox_platform_data {
+	u16		nr_mbox;
+};
+
 struct omap_mbox_queue {
 	spinlock_t		lock;
 	struct kfifo		fifo;
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH 2/7] OMAP2+: devices: get the number of supported mailboxes
  2011-06-25  1:17 [RFC PATCH 0/7] OMAP: mailbox: removing static declarations Omar Ramirez Luna
  2011-06-25  1:17 ` [RFC PATCH 1/7] OMAP2+: hwmod_data: define number of mailboxes Omar Ramirez Luna
@ 2011-06-25  1:17 ` Omar Ramirez Luna
  2011-06-25  1:17 ` [RFC PATCH 3/7] OMAP: mailbox: use OMAP's naming convention for devices Omar Ramirez Luna
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Omar Ramirez Luna @ 2011-06-25  1:17 UTC (permalink / raw)
  To: linux-arm-kernel

Use hwmod data attributes to get the defined number of mailboxes on
our current chip, and pass it through platform data.

Signed-off-by: Omar Ramirez Luna <omar.ramirez@ti.com>
---
 arch/arm/mach-omap2/devices.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index 5b8ca68..e1110f2 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -25,6 +25,7 @@
 
 #include <plat/tc.h>
 #include <plat/board.h>
+#include <plat/mailbox.h>
 #include <plat/mcbsp.h>
 #include <mach/gpio.h>
 #include <plat/mmc.h>
@@ -274,6 +275,8 @@ static inline void omap_init_mbox(void)
 {
 	struct omap_hwmod *oh;
 	struct omap_device *od;
+	struct omap_mailbox_dev_attr *mb_attr;
+	struct omap_mailbox_platform_data pdata;
 
 	oh = omap_hwmod_lookup("mailbox");
 	if (!oh) {
@@ -281,7 +284,10 @@ static inline void omap_init_mbox(void)
 		return;
 	}
 
-	od = omap_device_build("omap-mailbox", -1, oh, NULL, 0,
+	mb_attr = oh->dev_attr;
+	pdata.nr_mbox = mb_attr->nr_mbox;
+
+	od = omap_device_build("omap-mailbox", -1, oh, &pdata, sizeof(pdata),
 				mbox_latencies, ARRAY_SIZE(mbox_latencies), 0);
 	WARN(IS_ERR(od), "%s: could not build device, err %ld\n",
 						__func__, PTR_ERR(od));
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH 3/7] OMAP: mailbox: use OMAP's naming convention for devices
  2011-06-25  1:17 [RFC PATCH 0/7] OMAP: mailbox: removing static declarations Omar Ramirez Luna
  2011-06-25  1:17 ` [RFC PATCH 1/7] OMAP2+: hwmod_data: define number of mailboxes Omar Ramirez Luna
  2011-06-25  1:17 ` [RFC PATCH 2/7] OMAP2+: devices: get the number of supported mailboxes Omar Ramirez Luna
@ 2011-06-25  1:17 ` Omar Ramirez Luna
  2011-06-25  1:17 ` [RFC PATCH 4/7] OMAP: mailbox: move framework functions under header file Omar Ramirez Luna
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Omar Ramirez Luna @ 2011-06-25  1:17 UTC (permalink / raw)
  To: linux-arm-kernel

Use "omap_XXX" as the OMAP device naming convention.

Signed-off-by: Omar Ramirez Luna <omar.ramirez@ti.com>
---
 arch/arm/mach-omap1/mailbox.c |    2 +-
 arch/arm/mach-omap2/devices.c |    2 +-
 arch/arm/mach-omap2/mailbox.c |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-omap1/mailbox.c b/arch/arm/mach-omap1/mailbox.c
index c0e1f48..2845652 100644
--- a/arch/arm/mach-omap1/mailbox.c
+++ b/arch/arm/mach-omap1/mailbox.c
@@ -175,7 +175,7 @@ static struct platform_driver omap1_mbox_driver = {
 	.probe	= omap1_mbox_probe,
 	.remove	= __devexit_p(omap1_mbox_remove),
 	.driver	= {
-		.name	= "omap-mailbox",
+		.name	= "omap_mailbox",
 	},
 };
 
diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index e1110f2..779b2f3 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -287,7 +287,7 @@ static inline void omap_init_mbox(void)
 	mb_attr = oh->dev_attr;
 	pdata.nr_mbox = mb_attr->nr_mbox;
 
-	od = omap_device_build("omap-mailbox", -1, oh, &pdata, sizeof(pdata),
+	od = omap_device_build("omap_mailbox", -1, oh, &pdata, sizeof(pdata),
 				mbox_latencies, ARRAY_SIZE(mbox_latencies), 0);
 	WARN(IS_ERR(od), "%s: could not build device, err %ld\n",
 						__func__, PTR_ERR(od));
diff --git a/arch/arm/mach-omap2/mailbox.c b/arch/arm/mach-omap2/mailbox.c
index 86d564a..946a70a 100644
--- a/arch/arm/mach-omap2/mailbox.c
+++ b/arch/arm/mach-omap2/mailbox.c
@@ -397,7 +397,7 @@ static struct platform_driver omap2_mbox_driver = {
 	.probe = omap2_mbox_probe,
 	.remove = __devexit_p(omap2_mbox_remove),
 	.driver = {
-		.name = "omap-mailbox",
+		.name = "omap_mailbox",
 	},
 };
 
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH 4/7] OMAP: mailbox: move framework functions under header file
  2011-06-25  1:17 [RFC PATCH 0/7] OMAP: mailbox: removing static declarations Omar Ramirez Luna
                   ` (2 preceding siblings ...)
  2011-06-25  1:17 ` [RFC PATCH 3/7] OMAP: mailbox: use OMAP's naming convention for devices Omar Ramirez Luna
@ 2011-06-25  1:17 ` Omar Ramirez Luna
  2011-06-25  1:17 ` [RFC PATCH 5/7] OMAP: mailbox: implement dynamic mailbox configuration Omar Ramirez Luna
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Omar Ramirez Luna @ 2011-06-25  1:17 UTC (permalink / raw)
  To: linux-arm-kernel

Move API functions to common framework like save/restore_ctx,
enable/disable_irq instead of being under a header file. While
at it dropping their static inline declarations.

Signed-off-by: Omar Ramirez Luna <omar.ramirez@ti.com>
---
 arch/arm/plat-omap/include/plat/mailbox.h |   35 +++-------------------------
 arch/arm/plat-omap/mailbox.c              |   35 +++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 31 deletions(-)

diff --git a/arch/arm/plat-omap/include/plat/mailbox.h b/arch/arm/plat-omap/include/plat/mailbox.h
index 337b93c..271905a 100644
--- a/arch/arm/plat-omap/include/plat/mailbox.h
+++ b/arch/arm/plat-omap/include/plat/mailbox.h
@@ -78,36 +78,9 @@ void omap_mbox_put(struct omap_mbox *mbox, struct notifier_block *nb);
 int omap_mbox_register(struct device *parent, struct omap_mbox **);
 int omap_mbox_unregister(void);
 
-static inline void omap_mbox_save_ctx(struct omap_mbox *mbox)
-{
-	if (!mbox->ops->save_ctx) {
-		dev_err(mbox->dev, "%s:\tno save\n", __func__);
-		return;
-	}
-
-	mbox->ops->save_ctx(mbox);
-}
-
-static inline void omap_mbox_restore_ctx(struct omap_mbox *mbox)
-{
-	if (!mbox->ops->restore_ctx) {
-		dev_err(mbox->dev, "%s:\tno restore\n", __func__);
-		return;
-	}
-
-	mbox->ops->restore_ctx(mbox);
-}
-
-static inline void omap_mbox_enable_irq(struct omap_mbox *mbox,
-					omap_mbox_irq_t irq)
-{
-	mbox->ops->enable_irq(mbox, irq);
-}
-
-static inline void omap_mbox_disable_irq(struct omap_mbox *mbox,
-					 omap_mbox_irq_t irq)
-{
-	mbox->ops->disable_irq(mbox, irq);
-}
+void omap_mbox_save_ctx(struct omap_mbox *mbox);
+void omap_mbox_restore_ctx(struct omap_mbox *mbox);
+void omap_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq);
+void omap_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq);
 
 #endif /* MAILBOX_H */
diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c
index 69ddc9f..98b36dc 100644
--- a/arch/arm/plat-omap/mailbox.c
+++ b/arch/arm/plat-omap/mailbox.c
@@ -60,6 +60,18 @@ static inline int mbox_fifo_full(struct omap_mbox *mbox)
 }
 
 /* Mailbox IRQ handle functions */
+void omap_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
+{
+	mbox->ops->enable_irq(mbox, irq);
+}
+EXPORT_SYMBOL(omap_mbox_enable_irq);
+
+void omap_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
+{
+	mbox->ops->disable_irq(mbox, irq);
+}
+EXPORT_SYMBOL(omap_mbox_disable_irq);
+
 static inline void ack_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
 {
 	if (mbox->ops->ack_irq)
@@ -70,6 +82,29 @@ static inline int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
 	return mbox->ops->is_irq(mbox, irq);
 }
 
+/* Mailbox context functions */
+void omap_mbox_save_ctx(struct omap_mbox *mbox)
+{
+	if (!mbox->ops->save_ctx) {
+		dev_err(mbox->dev, "%s:\tno save\n", __func__);
+		return;
+	}
+
+	mbox->ops->save_ctx(mbox);
+}
+EXPORT_SYMBOL(omap_mbox_save_ctx);
+
+void omap_mbox_restore_ctx(struct omap_mbox *mbox)
+{
+	if (!mbox->ops->restore_ctx) {
+		dev_err(mbox->dev, "%s:\tno restore\n", __func__);
+		return;
+	}
+
+	mbox->ops->restore_ctx(mbox);
+}
+EXPORT_SYMBOL(omap_mbox_restore_ctx);
+
 /*
  * message sender
  */
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH 5/7] OMAP: mailbox: implement dynamic mailbox configuration
  2011-06-25  1:17 [RFC PATCH 0/7] OMAP: mailbox: removing static declarations Omar Ramirez Luna
                   ` (3 preceding siblings ...)
  2011-06-25  1:17 ` [RFC PATCH 4/7] OMAP: mailbox: move framework functions under header file Omar Ramirez Luna
@ 2011-06-25  1:17 ` Omar Ramirez Luna
  2011-06-25  1:17 ` [RFC PATCH 6/7] OMAP1: mailbox: adapt to dynamic mailbox requests Omar Ramirez Luna
  2011-06-25  1:17 ` [RFC PATCH 7/7] OMAP2+: mailbox: remove mailbox static declarations Omar Ramirez Luna
  6 siblings, 0 replies; 8+ messages in thread
From: Omar Ramirez Luna @ 2011-06-25  1:17 UTC (permalink / raw)
  To: linux-arm-kernel

So far, mailbox architecture dependent implementations have contained
static declarations for its supported mailbox and users, this has
affected the framework by extending the requests to match the hardcoded
names and only support the known users.

These changes try to provide a more generic mailbox driver which
diferentiates from its available queues instead of the name of the users
tied to a single pair.

Users of the mailbox need to supply a new struct mbox_info with the
common parameters needed by the framework to configure N number of queues.

All requests are made in function of the mailbox id needed, also a
request_byname is provided to cover the cases where there are multiple irqs
tied to a single mailbox block (i.e. OMAP2420).

Signed-off-by: Omar Ramirez Luna <omar.ramirez@ti.com>
---
 arch/arm/plat-omap/include/plat/mailbox.h |   19 ++-
 arch/arm/plat-omap/mailbox.c              |  275 +++++++++++++++++-----------
 2 files changed, 182 insertions(+), 112 deletions(-)

diff --git a/arch/arm/plat-omap/include/plat/mailbox.h b/arch/arm/plat-omap/include/plat/mailbox.h
index 271905a..5b77c80 100644
--- a/arch/arm/plat-omap/include/plat/mailbox.h
+++ b/arch/arm/plat-omap/include/plat/mailbox.h
@@ -39,6 +39,9 @@ struct omap_mbox_ops {
 	/* ctx */
 	void		(*save_ctx)(struct omap_mbox *mbox);
 	void		(*restore_ctx)(struct omap_mbox *mbox);
+
+	void            *(*request)(u16 id, u16 owner);
+	void            (*release)(void *priv);
 };
 
 struct omap_mailbox_dev_attr {
@@ -49,6 +52,14 @@ struct omap_mailbox_platform_data {
 	u16		nr_mbox;
 };
 
+struct mbox_info {
+	struct device           *dev;
+	struct omap_mbox_ops    *ops;
+	u32			kfifo_size;
+	u32			configured;
+	u16			nr_mbox;
+};
+
 struct omap_mbox_queue {
 	spinlock_t		lock;
 	struct kfifo		fifo;
@@ -60,9 +71,9 @@ struct omap_mbox_queue {
 
 struct omap_mbox {
 	char			*name;
+	u16			id;
 	unsigned int		irq;
 	struct omap_mbox_queue	*txq, *rxq;
-	struct omap_mbox_ops	*ops;
 	struct device		*dev;
 	void			*priv;
 	int			use_count;
@@ -72,10 +83,10 @@ struct omap_mbox {
 int omap_mbox_msg_send(struct omap_mbox *, mbox_msg_t msg);
 void omap_mbox_init_seq(struct omap_mbox *);
 
-struct omap_mbox *omap_mbox_get(const char *, struct notifier_block *nb);
-void omap_mbox_put(struct omap_mbox *mbox, struct notifier_block *nb);
+void *mbox_request(u16 id, u16 owner, struct notifier_block *nb);
+void mbox_release(struct omap_mbox *mbox, struct notifier_block *nb);
 
-int omap_mbox_register(struct device *parent, struct omap_mbox **);
+int omap_mbox_register(struct mbox_info *arch_mbi);
 int omap_mbox_unregister(void);
 
 void omap_mbox_save_ctx(struct omap_mbox *mbox);
diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c
index 98b36dc..3cfb405 100644
--- a/arch/arm/plat-omap/mailbox.c
+++ b/arch/arm/plat-omap/mailbox.c
@@ -29,79 +29,76 @@
 #include <linux/kfifo.h>
 #include <linux/err.h>
 #include <linux/notifier.h>
+#include <linux/platform_device.h>
 
 #include <plat/mailbox.h>
 
+static struct mbox_info *mbi;
 static struct omap_mbox **mboxes;
 
-static int mbox_configured;
 static DEFINE_MUTEX(mbox_configured_lock);
 
-static unsigned int mbox_kfifo_size = CONFIG_OMAP_MBOX_KFIFO_SIZE;
-module_param(mbox_kfifo_size, uint, S_IRUGO);
-MODULE_PARM_DESC(mbox_kfifo_size, "Size of omap's mailbox kfifo (bytes)");
-
 /* Mailbox FIFO handle functions */
 static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox)
 {
-	return mbox->ops->fifo_read(mbox);
+	return mbi->ops->fifo_read(mbox);
 }
 static inline void mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
 {
-	mbox->ops->fifo_write(mbox, msg);
+	mbi->ops->fifo_write(mbox, msg);
 }
 static inline int mbox_fifo_empty(struct omap_mbox *mbox)
 {
-	return mbox->ops->fifo_empty(mbox);
+	return mbi->ops->fifo_empty(mbox);
 }
 static inline int mbox_fifo_full(struct omap_mbox *mbox)
 {
-	return mbox->ops->fifo_full(mbox);
+	return mbi->ops->fifo_full(mbox);
 }
 
 /* Mailbox IRQ handle functions */
 void omap_mbox_enable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
 {
-	mbox->ops->enable_irq(mbox, irq);
+	mbi->ops->enable_irq(mbox, irq);
 }
 EXPORT_SYMBOL(omap_mbox_enable_irq);
 
 void omap_mbox_disable_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
 {
-	mbox->ops->disable_irq(mbox, irq);
+	mbi->ops->disable_irq(mbox, irq);
 }
 EXPORT_SYMBOL(omap_mbox_disable_irq);
 
 static inline void ack_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
 {
-	if (mbox->ops->ack_irq)
-		mbox->ops->ack_irq(mbox, irq);
+	if (mbi->ops->ack_irq)
+		mbi->ops->ack_irq(mbox, irq);
 }
 static inline int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
 {
-	return mbox->ops->is_irq(mbox, irq);
+	return mbi->ops->is_irq(mbox, irq);
 }
 
 /* Mailbox context functions */
 void omap_mbox_save_ctx(struct omap_mbox *mbox)
 {
-	if (!mbox->ops->save_ctx) {
+	if (!mbi->ops->save_ctx) {
 		dev_err(mbox->dev, "%s:\tno save\n", __func__);
 		return;
 	}
 
-	mbox->ops->save_ctx(mbox);
+	mbi->ops->save_ctx(mbox);
 }
 EXPORT_SYMBOL(omap_mbox_save_ctx);
 
 void omap_mbox_restore_ctx(struct omap_mbox *mbox)
 {
-	if (!mbox->ops->restore_ctx) {
+	if (!mbi->ops->restore_ctx) {
 		dev_err(mbox->dev, "%s:\tno restore\n", __func__);
 		return;
 	}
 
-	mbox->ops->restore_ctx(mbox);
+	mbi->ops->restore_ctx(mbox);
 }
 EXPORT_SYMBOL(omap_mbox_restore_ctx);
 
@@ -113,7 +110,7 @@ static int __mbox_poll_for_space(struct omap_mbox *mbox)
 	int ret = 0, i = 1000;
 
 	while (mbox_fifo_full(mbox)) {
-		if (mbox->ops->type == OMAP_MBOX_TYPE2)
+		if (mbi->ops->type == OMAP_MBOX_TYPE2)
 			return -1;
 		if (--i == 0)
 			return -1;
@@ -224,7 +221,7 @@ static void __mbox_rx_interrupt(struct omap_mbox *mbox)
 		len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
 		WARN_ON(len != sizeof(msg));
 
-		if (mbox->ops->type == OMAP_MBOX_TYPE1)
+		if (mbi->ops->type == OMAP_MBOX_TYPE1)
 			break;
 	}
 
@@ -259,7 +256,7 @@ static struct omap_mbox_queue *mbox_queue_alloc(struct omap_mbox *mbox,
 
 	spin_lock_init(&mq->lock);
 
-	if (kfifo_alloc(&mq->fifo, mbox_kfifo_size, GFP_KERNEL))
+	if (kfifo_alloc(&mq->fifo, mbi->kfifo_size, GFP_KERNEL))
 		goto error;
 
 	if (work)
@@ -284,17 +281,16 @@ static int omap_mbox_startup(struct omap_mbox *mbox)
 	int ret = 0;
 	struct omap_mbox_queue *mq;
 
-	mutex_lock(&mbox_configured_lock);
-	if (!mbox_configured++) {
-		if (likely(mbox->ops->startup)) {
-			ret = mbox->ops->startup(mbox);
+	if (!mbi->configured++) {
+		if (likely(mbi->ops->startup)) {
+			ret = mbi->ops->startup(mbox);
 			if (unlikely(ret))
 				goto fail_startup;
 		} else
 			goto fail_startup;
 	}
 
-	if (!mbox->use_count++) {
+	if (mbox->irq > 0) {
 		ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED,
 							mbox->name, mbox);
 		if (unlikely(ret)) {
@@ -302,135 +298,203 @@ static int omap_mbox_startup(struct omap_mbox *mbox)
 									ret);
 			goto fail_request_irq;
 		}
-		mq = mbox_queue_alloc(mbox, NULL, mbox_tx_tasklet);
-		if (!mq) {
-			ret = -ENOMEM;
-			goto fail_alloc_txq;
-		}
-		mbox->txq = mq;
+	}
 
-		mq = mbox_queue_alloc(mbox, mbox_rx_work, NULL);
-		if (!mq) {
-			ret = -ENOMEM;
-			goto fail_alloc_rxq;
-		}
-		mbox->rxq = mq;
-		mq->mbox = mbox;
+	mq = mbox_queue_alloc(mbox, NULL, mbox_tx_tasklet);
+	if (!mq) {
+		ret = -ENOMEM;
+		goto fail_alloc_txq;
 	}
-	mutex_unlock(&mbox_configured_lock);
+	mbox->txq = mq;
+
+	BLOCKING_INIT_NOTIFIER_HEAD(&mbox->notifier);
+	mq = mbox_queue_alloc(mbox, mbox_rx_work, NULL);
+	if (!mq) {
+		ret = -ENOMEM;
+		goto fail_alloc_rxq;
+	}
+	mbox->rxq = mq;
+	mq->mbox = mbox;
+
 	return 0;
 
 fail_alloc_rxq:
 	mbox_queue_free(mbox->txq);
 fail_alloc_txq:
-	free_irq(mbox->irq, mbox);
+	if (mbox->irq > 0)
+		free_irq(mbox->irq, mbox);
 fail_request_irq:
-	if (mbox->ops->shutdown)
-		mbox->ops->shutdown(mbox);
-	mbox->use_count--;
+	if (mbi->ops->shutdown)
+		mbi->ops->shutdown(mbox);
 fail_startup:
-	mbox_configured--;
-	mutex_unlock(&mbox_configured_lock);
+	mbi->configured--;
 	return ret;
 }
 
 static void omap_mbox_fini(struct omap_mbox *mbox)
 {
-	mutex_lock(&mbox_configured_lock);
-
-	if (!--mbox->use_count) {
+	if (mbox->irq > 0)
 		free_irq(mbox->irq, mbox);
-		tasklet_kill(&mbox->txq->tasklet);
+
+	tasklet_kill(&mbox->txq->tasklet);
 	flush_work_sync(&mbox->rxq->work);
-		mbox_queue_free(mbox->txq);
-		mbox_queue_free(mbox->rxq);
-	}
+	mbox_queue_free(mbox->txq);
+	mbox_queue_free(mbox->rxq);
 
-	if (likely(mbox->ops->shutdown)) {
-		if (!--mbox_configured)
-			mbox->ops->shutdown(mbox);
+	if (likely(mbi->ops->shutdown)) {
+		if (!--mbi->configured)
+			mbi->ops->shutdown(mbox);
 	}
-
-	mutex_unlock(&mbox_configured_lock);
 }
 
-struct omap_mbox *omap_mbox_get(const char *name, struct notifier_block *nb)
+struct omap_mbox *_mbox_request(u16 id, u16 owner, char *name,
+				struct notifier_block *nb)
 {
-	struct omap_mbox *_mbox, *mbox = NULL;
-	int i, ret;
+	struct omap_mbox *mbox;
+	struct platform_device *pdev;
+	int ret, len;
 
-	if (!mboxes)
-		return ERR_PTR(-EINVAL);
+	if (mbi->nr_mbox <= id)
+		return ERR_PTR(-EPERM);
 
-	for (i = 0; (_mbox = mboxes[i]); i++) {
-		if (!strcmp(_mbox->name, name)) {
-			mbox = _mbox;
-			break;
-		}
+	mutex_lock(&mbox_configured_lock);
+
+	if (mboxes[id]) {
+		mbox = mboxes[id];
+		goto unlock;
+	}
+
+	mbox = kzalloc(sizeof(struct omap_mbox), GFP_KERNEL);
+	if (!mbox) {
+		ret = -ENOMEM;
+		goto err1;
+	}
+
+	mbox->priv = mbi->ops->request(id, owner);
+	if (!mbox->priv) {
+		ret = -ENODEV;
+		goto err2;
 	}
 
-	if (!mbox)
-		return ERR_PTR(-ENOENT);
+	mbox->dev = mbi->dev;
+	pdev = container_of(mbox->dev, struct platform_device, dev);
+
+	if (name)
+		mbox->irq = platform_get_irq_byname(pdev, name);
+	else if (owner == 0)
+		mbox->irq = platform_get_irq(pdev, owner);
+	else
+		mbox->irq = 0;
+
+	if (IS_ERR_VALUE(mbox->irq)) {
+		ret = mbox->irq;
+		goto err3;
+	}
+
+	len = snprintf(NULL, 0, "mbox%d", id);
+	mbox->name = kzalloc(len + 1, GFP_KERNEL);
+	if (!mbox->name) {
+		ret = -ENOMEM;
+		goto err3;
+	}
+	snprintf(mbox->name, len + 1, "mbox%d", id);
 
 	ret = omap_mbox_startup(mbox);
 	if (ret)
-		return ERR_PTR(-ENODEV);
+		goto err4;
 
-	if (nb)
+	mbox->id = id;
+	mboxes[id] = mbox;
+
+unlock:
+	if (nb) {
 		blocking_notifier_chain_register(&mbox->notifier, nb);
+		omap_mbox_enable_irq(mbox, IRQ_RX);
+	}
+
+	mbox->use_count++;
+
+	mutex_unlock(&mbox_configured_lock);
 
 	return mbox;
+
+err4:
+	kfree(mbox->name);
+err3:
+	mbi->ops->release(mbox->priv);
+err2:
+	kfree(mbox);
+err1:
+	mutex_unlock(&mbox_configured_lock);
+	return ERR_PTR(ret);
+}
+
+struct omap_mbox *mbox_request_byname(u16 id, char *name,
+					struct notifier_block *nb)
+{
+	return _mbox_request(id, 0, name, nb);
 }
-EXPORT_SYMBOL(omap_mbox_get);
+EXPORT_SYMBOL(mbox_request_byname);
 
-void omap_mbox_put(struct omap_mbox *mbox, struct notifier_block *nb)
+void *mbox_request(u16 id, u16 owner, struct notifier_block *nb)
 {
-	blocking_notifier_chain_unregister(&mbox->notifier, nb);
-	omap_mbox_fini(mbox);
+	return _mbox_request(id, owner, NULL, nb);
 }
-EXPORT_SYMBOL(omap_mbox_put);
+EXPORT_SYMBOL(mbox_request);
+
+void mbox_release(struct omap_mbox *mbox, struct notifier_block *nb)
+{
+	mutex_lock(&mbox_configured_lock);
+
+	if (nb)
+		blocking_notifier_chain_unregister(&mbox->notifier, nb);
+
+	if (!--mbox->use_count) {
+		omap_mbox_disable_irq(mbox, IRQ_TX);
+		omap_mbox_disable_irq(mbox, IRQ_RX);
+		omap_mbox_fini(mbox);
+
+		mbi->ops->release(mbox->priv);
+		mboxes[mbox->id] = NULL;
+		kfree(mbox->name);
+		kfree(mbox);
+	}
+
+	mutex_unlock(&mbox_configured_lock);
+}
+EXPORT_SYMBOL(mbox_release);
 
 static struct class omap_mbox_class = { .name = "mbox", };
 
-int omap_mbox_register(struct device *parent, struct omap_mbox **list)
+int omap_mbox_register(struct mbox_info *arch_mbi)
 {
-	int ret;
-	int i;
+	if (!arch_mbi)
+		return -EFAULT;
 
-	mboxes = list;
-	if (!mboxes)
-		return -EINVAL;
+	mbi = arch_mbi;
 
-	for (i = 0; mboxes[i]; i++) {
-		struct omap_mbox *mbox = mboxes[i];
-		mbox->dev = device_create(&omap_mbox_class,
-				parent, 0, mbox, "%s", mbox->name);
-		if (IS_ERR(mbox->dev)) {
-			ret = PTR_ERR(mbox->dev);
-			goto err_out;
-		}
+	/* kfifo size sanity check: alignment and minimal size */
+	mbi->kfifo_size = ALIGN(mbi->kfifo_size, sizeof(mbox_msg_t));
+	mbi->kfifo_size = max_t(unsigned int, mbi->kfifo_size,
+							sizeof(mbox_msg_t));
 
-		BLOCKING_INIT_NOTIFIER_HEAD(&mbox->notifier);
+	mboxes = kzalloc(sizeof(struct omap_mbox *) * mbi->nr_mbox, GFP_KERNEL);
+	if (!mboxes) {
+		mbi = NULL;
+		return -ENOMEM;
 	}
-	return 0;
 
-err_out:
-	while (i--)
-		device_unregister(mboxes[i]->dev);
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL(omap_mbox_register);
 
 int omap_mbox_unregister(void)
 {
-	int i;
-
-	if (!mboxes)
+	if (!mbi)
 		return -EINVAL;
 
-	for (i = 0; mboxes[i]; i++)
-		device_unregister(mboxes[i]->dev);
-	mboxes = NULL;
+	mbi = NULL;
+
 	return 0;
 }
 EXPORT_SYMBOL(omap_mbox_unregister);
@@ -443,11 +507,6 @@ static int __init omap_mbox_init(void)
 	if (err)
 		return err;
 
-	/* kfifo size sanity check: alignment and minimal size */
-	mbox_kfifo_size = ALIGN(mbox_kfifo_size, sizeof(mbox_msg_t));
-	mbox_kfifo_size = max_t(unsigned int, mbox_kfifo_size,
-							sizeof(mbox_msg_t));
-
 	return 0;
 }
 subsys_initcall(omap_mbox_init);
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH 6/7] OMAP1: mailbox: adapt to dynamic mailbox requests
  2011-06-25  1:17 [RFC PATCH 0/7] OMAP: mailbox: removing static declarations Omar Ramirez Luna
                   ` (4 preceding siblings ...)
  2011-06-25  1:17 ` [RFC PATCH 5/7] OMAP: mailbox: implement dynamic mailbox configuration Omar Ramirez Luna
@ 2011-06-25  1:17 ` Omar Ramirez Luna
  2011-06-25  1:17 ` [RFC PATCH 7/7] OMAP2+: mailbox: remove mailbox static declarations Omar Ramirez Luna
  6 siblings, 0 replies; 8+ messages in thread
From: Omar Ramirez Luna @ 2011-06-25  1:17 UTC (permalink / raw)
  To: linux-arm-kernel

Remove mailbox static declarations, while at it, simplify the macros
to be reused in a cleaner way.

New approach configures available mailboxes per request.

Signed-off-by: Omar Ramirez Luna <omar.ramirez@ti.com>
---
 arch/arm/mach-omap1/mailbox.c |   92 ++++++++++++++++++++++++-----------------
 1 files changed, 54 insertions(+), 38 deletions(-)

diff --git a/arch/arm/mach-omap1/mailbox.c b/arch/arm/mach-omap1/mailbox.c
index 2845652..f3a40de 100644
--- a/arch/arm/mach-omap1/mailbox.c
+++ b/arch/arm/mach-omap1/mailbox.c
@@ -9,20 +9,23 @@
  * for more details.
  */
 
+#include <linux/err.h>
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
+#include <linux/slab.h>
 #include <plat/mailbox.h>
 
-#define MAILBOX_ARM2DSP1		0x00
-#define MAILBOX_ARM2DSP1b		0x04
-#define MAILBOX_DSP2ARM1		0x08
-#define MAILBOX_DSP2ARM1b		0x0c
-#define MAILBOX_DSP2ARM2		0x10
-#define MAILBOX_DSP2ARM2b		0x14
-#define MAILBOX_ARM2DSP1_Flag		0x18
-#define MAILBOX_DSP2ARM1_Flag		0x1c
-#define MAILBOX_DSP2ARM2_Flag		0x20
+#define MAILBOX_ARM2DSPm(m)		(0x24 * (m - 1))
+#define MAILBOX_DSP2ARMm(m)		(0x08 + 0x8 * (m - 1))
+#define MAILBOX_ARM2DSPmb(m)		(0x04 + 0x24 * (m - 1))
+#define MAILBOX_DSP2ARMmb(m)		(0x0c + 0x8 * (m - 1))
+#define MAILBOX_ARM2DSPm_Flag(m)	(0x18 + 0x14 * (m - 1))
+#define MAILBOX_DSP2ARMm_Flag(m)	(0x1c + 0x4 * (m - 1))
+
+static unsigned int mbox_kfifo_size = CONFIG_OMAP_MBOX_KFIFO_SIZE;
+module_param(mbox_kfifo_size, uint, S_IRUGO);
+MODULE_PARM_DESC(mbox_kfifo_size, "Size of omap's mailbox kfifo (bytes)");
 
 static void __iomem *mbox_base;
 
@@ -106,6 +109,32 @@ omap1_mbox_is_irq(struct omap_mbox *mbox, omap_mbox_type_t irq)
 	return 1;
 }
 
+struct device *mbox_dev;
+
+static void *omap1_mbox_request(u16 id, u16 owner)
+{
+	struct omap_mbox1_priv *p;
+
+	p = kzalloc(sizeof(struct omap_mbox1_priv), GFP_KERNEL);
+	if (!p)
+		return ERR_PTR(-ENOMEM);
+
+	p->tx_fifo.cmd	= MAILBOX_ARM2DSPmb(id);
+	p->tx_fifo.data	= MAILBOX_ARM2DSPm(id);
+	p->tx_fifo.flag	= MAILBOX_ARM2DSPm_Flag(id);
+	p->rx_fifo.cmd	= MAILBOX_DSP2ARMmb(id);
+	p->rx_fifo.data	= MAILBOX_DSP2ARMm(id);
+	p->rx_fifo.flag	= MAILBOX_DSP2ARMm_Flag(id);
+
+	return mbox;
+}
+
+static void omap1_mbox_release(void *priv)
+{
+	kfree(priv);
+	priv = NULL;
+}
+
 static struct omap_mbox_ops omap1_mbox_ops = {
 	.type		= OMAP_MBOX_TYPE1,
 	.fifo_read	= omap1_mbox_fifo_read,
@@ -115,48 +144,35 @@ static struct omap_mbox_ops omap1_mbox_ops = {
 	.enable_irq	= omap1_mbox_enable_irq,
 	.disable_irq	= omap1_mbox_disable_irq,
 	.is_irq		= omap1_mbox_is_irq,
+	.request	= omap1_mbox_request,
+	.release	= omap1_mbox_release,
 };
 
-/* FIXME: the following struct should be created automatically by the user id */
-
-/* DSP */
-static struct omap_mbox1_priv omap1_mbox_dsp_priv = {
-	.tx_fifo = {
-		.cmd	= MAILBOX_ARM2DSP1b,
-		.data	= MAILBOX_ARM2DSP1,
-		.flag	= MAILBOX_ARM2DSP1_Flag,
-	},
-	.rx_fifo = {
-		.cmd	= MAILBOX_DSP2ARM1b,
-		.data	= MAILBOX_DSP2ARM1,
-		.flag	= MAILBOX_DSP2ARM1_Flag,
-	},
-};
-
-static struct omap_mbox mbox_dsp_info = {
-	.name	= "dsp",
-	.ops	= &omap1_mbox_ops,
-	.priv	= &omap1_mbox_dsp_priv,
-};
-
-static struct omap_mbox *omap1_mboxes[] = { &mbox_dsp_info, NULL };
-
 static int __devinit omap1_mbox_probe(struct platform_device *pdev)
 {
 	struct resource *mem;
+	struct mbox_info *arch_mbi;
 	int ret;
-	struct omap_mbox **list;
-
-	list = omap1_mboxes;
-	list[0]->irq = platform_get_irq_byname(pdev, "dsp");
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	mbox_base = ioremap(mem->start, resource_size(mem));
 	if (!mbox_base)
 		return -ENOMEM;
 
-	ret = omap_mbox_register(&pdev->dev, list);
+	arch_mbi = kzalloc(sizeof(struct mbox_info), GFP_KERNEL);
+	if (!arch_mbi) {
+		iounmap(mbox_base);
+		return -ENOMEM;
+	}
+
+	arch_mbi->dev = &pdev->dev;
+	arch_mbi->ops = &omap1_mbox_ops;
+	arch_mbi->kfifo_size = mbox_kfifo_size;
+	arch_mbi->nr_mbox = 2;
+
+	ret = omap_mbox_register(arch_mbi);
 	if (ret) {
+		kfree(arch_mbi);
 		iounmap(mbox_base);
 		return ret;
 	}
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH 7/7] OMAP2+: mailbox: remove mailbox static declarations
  2011-06-25  1:17 [RFC PATCH 0/7] OMAP: mailbox: removing static declarations Omar Ramirez Luna
                   ` (5 preceding siblings ...)
  2011-06-25  1:17 ` [RFC PATCH 6/7] OMAP1: mailbox: adapt to dynamic mailbox requests Omar Ramirez Luna
@ 2011-06-25  1:17 ` Omar Ramirez Luna
  6 siblings, 0 replies; 8+ messages in thread
From: Omar Ramirez Luna @ 2011-06-25  1:17 UTC (permalink / raw)
  To: linux-arm-kernel

Remove mailbox static declarations which limit the driver to
either work with 1 or 2 predefined mailboxes, even if there are
more mailboxes in hardware.

New approach configures available mailboxes per request.

Signed-off-by: Omar Ramirez Luna <omar.ramirez@ti.com>
---
 arch/arm/mach-omap2/mailbox.c |  210 +++++++++++------------------------------
 1 files changed, 54 insertions(+), 156 deletions(-)

diff --git a/arch/arm/mach-omap2/mailbox.c b/arch/arm/mach-omap2/mailbox.c
index 946a70a..b85e33b 100644
--- a/arch/arm/mach-omap2/mailbox.c
+++ b/arch/arm/mach-omap2/mailbox.c
@@ -15,6 +15,7 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/pm_runtime.h>
+#include <linux/slab.h>
 #include <plat/mailbox.h>
 #include <mach/irqs.h>
 
@@ -39,6 +40,10 @@
 #define MBOX_NR_REGS			(MBOX_REG_SIZE / sizeof(u32))
 #define OMAP4_MBOX_NR_REGS		(OMAP4_MBOX_REG_SIZE / sizeof(u32))
 
+static unsigned int mbox_kfifo_size = CONFIG_OMAP_MBOX_KFIFO_SIZE;
+module_param(mbox_kfifo_size, uint, S_IRUGO);
+MODULE_PARM_DESC(mbox_kfifo_size, "Size of omap's mailbox kfifo (bytes)");
+
 static void __iomem *mbox_base;
 
 struct omap_mbox2_fifo {
@@ -58,9 +63,6 @@ struct omap_mbox2_priv {
 	unsigned long irqdisable;
 };
 
-static void omap2_mbox_enable_irq(struct omap_mbox *mbox,
-				  omap_mbox_type_t irq);
-
 static inline unsigned int mbox_read_reg(size_t ofs)
 {
 	return __raw_readl(mbox_base + ofs);
@@ -76,21 +78,19 @@ static int omap2_mbox_startup(struct omap_mbox *mbox)
 {
 	u32 l;
 
-	pm_runtime_enable(mbox->dev->parent);
-	pm_runtime_get_sync(mbox->dev->parent);
+	pm_runtime_enable(mbox->dev);
+	pm_runtime_get_sync(mbox->dev);
 
 	l = mbox_read_reg(MAILBOX_REVISION);
 	pr_debug("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f));
 
-	omap2_mbox_enable_irq(mbox, IRQ_RX);
-
 	return 0;
 }
 
 static void omap2_mbox_shutdown(struct omap_mbox *mbox)
 {
-	pm_runtime_put_sync(mbox->dev->parent);
-	pm_runtime_disable(mbox->dev->parent);
+	pm_runtime_put_sync(mbox->dev);
+	pm_runtime_disable(mbox->dev);
 }
 
 /* Mailbox FIFO handle functions */
@@ -203,6 +203,33 @@ static void omap2_mbox_restore_ctx(struct omap_mbox *mbox)
 	}
 }
 
+static void *omap2_mbox_request(u16 id, u16 owner)
+{
+	struct omap_mbox2_priv *p;
+
+	p = kzalloc(sizeof(struct omap_mbox2_priv), GFP_KERNEL);
+	if (!p)
+		return ERR_PTR(-ENOMEM);
+
+	p->tx_fifo.msg = MAILBOX_MESSAGE(id);
+	p->tx_fifo.fifo_stat = MAILBOX_FIFOSTATUS(id);
+	p->notfull_bit = MAILBOX_IRQ_NOTFULL(id);
+	p->rx_fifo.msg = MAILBOX_MESSAGE(id);
+	p->rx_fifo.msg_stat = MAILBOX_MSGSTATUS(id);
+	p->newmsg_bit = MAILBOX_IRQ_NEWMSG(id);
+	p->irqenable = MAILBOX_IRQENABLE(owner);
+	p->irqstatus = MAILBOX_IRQSTATUS(owner);
+	p->irqdisable = MAILBOX_IRQENABLE(owner);
+
+	return p;
+}
+
+static void omap2_mbox_release(void *priv)
+{
+	kfree(priv);
+	priv = NULL;
+}
+
 static struct omap_mbox_ops omap2_mbox_ops = {
 	.type		= OMAP_MBOX_TYPE2,
 	.startup	= omap2_mbox_startup,
@@ -217,168 +244,39 @@ static struct omap_mbox_ops omap2_mbox_ops = {
 	.is_irq		= omap2_mbox_is_irq,
 	.save_ctx	= omap2_mbox_save_ctx,
 	.restore_ctx	= omap2_mbox_restore_ctx,
+	.request	= omap2_mbox_request,
+	.release	= omap2_mbox_release,
 };
 
-/*
- * MAILBOX 0: ARM -> DSP,
- * MAILBOX 1: ARM <- DSP.
- * MAILBOX 2: ARM -> IVA,
- * MAILBOX 3: ARM <- IVA.
- */
-
-/* FIXME: the following structs should be filled automatically by the user id */
-
-#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP2)
-/* DSP */
-static struct omap_mbox2_priv omap2_mbox_dsp_priv = {
-	.tx_fifo = {
-		.msg		= MAILBOX_MESSAGE(0),
-		.fifo_stat	= MAILBOX_FIFOSTATUS(0),
-	},
-	.rx_fifo = {
-		.msg		= MAILBOX_MESSAGE(1),
-		.msg_stat	= MAILBOX_MSGSTATUS(1),
-	},
-	.irqenable	= MAILBOX_IRQENABLE(0),
-	.irqstatus	= MAILBOX_IRQSTATUS(0),
-	.notfull_bit	= MAILBOX_IRQ_NOTFULL(0),
-	.newmsg_bit	= MAILBOX_IRQ_NEWMSG(1),
-	.irqdisable	= MAILBOX_IRQENABLE(0),
-};
-
-struct omap_mbox mbox_dsp_info = {
-	.name	= "dsp",
-	.ops	= &omap2_mbox_ops,
-	.priv	= &omap2_mbox_dsp_priv,
-};
-#endif
-
-#if defined(CONFIG_ARCH_OMAP3)
-struct omap_mbox *omap3_mboxes[] = { &mbox_dsp_info, NULL };
-#endif
-
-#if defined(CONFIG_SOC_OMAP2420)
-/* IVA */
-static struct omap_mbox2_priv omap2_mbox_iva_priv = {
-	.tx_fifo = {
-		.msg		= MAILBOX_MESSAGE(2),
-		.fifo_stat	= MAILBOX_FIFOSTATUS(2),
-	},
-	.rx_fifo = {
-		.msg		= MAILBOX_MESSAGE(3),
-		.msg_stat	= MAILBOX_MSGSTATUS(3),
-	},
-	.irqenable	= MAILBOX_IRQENABLE(3),
-	.irqstatus	= MAILBOX_IRQSTATUS(3),
-	.notfull_bit	= MAILBOX_IRQ_NOTFULL(2),
-	.newmsg_bit	= MAILBOX_IRQ_NEWMSG(3),
-	.irqdisable	= MAILBOX_IRQENABLE(3),
-};
-
-static struct omap_mbox mbox_iva_info = {
-	.name	= "iva",
-	.ops	= &omap2_mbox_ops,
-	.priv	= &omap2_mbox_iva_priv,
-};
-
-struct omap_mbox *omap2_mboxes[] = { &mbox_dsp_info, &mbox_iva_info, NULL };
-#endif
-
-#if defined(CONFIG_ARCH_OMAP4)
-/* OMAP4 */
-static struct omap_mbox2_priv omap2_mbox_1_priv = {
-	.tx_fifo = {
-		.msg		= MAILBOX_MESSAGE(0),
-		.fifo_stat	= MAILBOX_FIFOSTATUS(0),
-	},
-	.rx_fifo = {
-		.msg		= MAILBOX_MESSAGE(1),
-		.msg_stat	= MAILBOX_MSGSTATUS(1),
-	},
-	.irqenable	= OMAP4_MAILBOX_IRQENABLE(0),
-	.irqstatus	= OMAP4_MAILBOX_IRQSTATUS(0),
-	.notfull_bit	= MAILBOX_IRQ_NOTFULL(0),
-	.newmsg_bit	= MAILBOX_IRQ_NEWMSG(1),
-	.irqdisable	= OMAP4_MAILBOX_IRQENABLE_CLR(0),
-};
-
-struct omap_mbox mbox_1_info = {
-	.name	= "mailbox-1",
-	.ops	= &omap2_mbox_ops,
-	.priv	= &omap2_mbox_1_priv,
-};
-
-static struct omap_mbox2_priv omap2_mbox_2_priv = {
-	.tx_fifo = {
-		.msg		= MAILBOX_MESSAGE(3),
-		.fifo_stat	= MAILBOX_FIFOSTATUS(3),
-	},
-	.rx_fifo = {
-		.msg		= MAILBOX_MESSAGE(2),
-		.msg_stat	= MAILBOX_MSGSTATUS(2),
-	},
-	.irqenable	= OMAP4_MAILBOX_IRQENABLE(0),
-	.irqstatus	= OMAP4_MAILBOX_IRQSTATUS(0),
-	.notfull_bit	= MAILBOX_IRQ_NOTFULL(3),
-	.newmsg_bit	= MAILBOX_IRQ_NEWMSG(2),
-	.irqdisable     = OMAP4_MAILBOX_IRQENABLE_CLR(0),
-};
-
-struct omap_mbox mbox_2_info = {
-	.name	= "mailbox-2",
-	.ops	= &omap2_mbox_ops,
-	.priv	= &omap2_mbox_2_priv,
-};
-
-struct omap_mbox *omap4_mboxes[] = { &mbox_1_info, &mbox_2_info, NULL };
-#endif
-
 static int __devinit omap2_mbox_probe(struct platform_device *pdev)
 {
 	struct resource *mem;
+	struct mbox_info *arch_mbi;
+	struct omap_mailbox_platform_data *pdata = pdev->dev.platform_data;
 	int ret;
-	struct omap_mbox **list;
 
-	if (false)
-		;
-#if defined(CONFIG_ARCH_OMAP3)
-	else if (cpu_is_omap34xx()) {
-		list = omap3_mboxes;
-
-		list[0]->irq = platform_get_irq(pdev, 0);
-	}
-#endif
-#if defined(CONFIG_ARCH_OMAP2)
-	else if (cpu_is_omap2430()) {
-		list = omap2_mboxes;
-
-		list[0]->irq = platform_get_irq(pdev, 0);
-	} else if (cpu_is_omap2420()) {
-		list = omap2_mboxes;
-
-		list[0]->irq = platform_get_irq_byname(pdev, "dsp");
-		list[1]->irq = platform_get_irq_byname(pdev, "iva");
-	}
-#endif
-#if defined(CONFIG_ARCH_OMAP4)
-	else if (cpu_is_omap44xx()) {
-		list = omap4_mboxes;
-
-		list[0]->irq = list[1]->irq = platform_get_irq(pdev, 0);
-	}
-#endif
-	else {
-		pr_err("%s: platform not supported\n", __func__);
+	if (!pdata)
 		return -ENODEV;
-	}
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	mbox_base = ioremap(mem->start, resource_size(mem));
 	if (!mbox_base)
 		return -ENOMEM;
 
-	ret = omap_mbox_register(&pdev->dev, list);
+	arch_mbi = kzalloc(sizeof(struct mbox_info), GFP_KERNEL);
+	if (!arch_mbi) {
+		iounmap(mbox_base);
+		return -ENOMEM;
+	}
+
+	arch_mbi->dev = &pdev->dev;
+	arch_mbi->ops = &omap2_mbox_ops;
+	arch_mbi->kfifo_size = mbox_kfifo_size;
+	arch_mbi->nr_mbox = pdata->nr_mbox;
+
+	ret = omap_mbox_register(arch_mbi);
 	if (ret) {
+		kfree(arch_mbi);
 		iounmap(mbox_base);
 		return ret;
 	}
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-06-25  1:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-25  1:17 [RFC PATCH 0/7] OMAP: mailbox: removing static declarations Omar Ramirez Luna
2011-06-25  1:17 ` [RFC PATCH 1/7] OMAP2+: hwmod_data: define number of mailboxes Omar Ramirez Luna
2011-06-25  1:17 ` [RFC PATCH 2/7] OMAP2+: devices: get the number of supported mailboxes Omar Ramirez Luna
2011-06-25  1:17 ` [RFC PATCH 3/7] OMAP: mailbox: use OMAP's naming convention for devices Omar Ramirez Luna
2011-06-25  1:17 ` [RFC PATCH 4/7] OMAP: mailbox: move framework functions under header file Omar Ramirez Luna
2011-06-25  1:17 ` [RFC PATCH 5/7] OMAP: mailbox: implement dynamic mailbox configuration Omar Ramirez Luna
2011-06-25  1:17 ` [RFC PATCH 6/7] OMAP1: mailbox: adapt to dynamic mailbox requests Omar Ramirez Luna
2011-06-25  1:17 ` [RFC PATCH 7/7] OMAP2+: mailbox: remove mailbox static declarations Omar Ramirez Luna

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).