Skip to content

Commit

Permalink
OMAP: mailbox: use runtime pm for clk and sysc handling
Browse files Browse the repository at this point in the history
Use runtime pm APIs to enable/disable mailbox clocks and
to configure SYSC register.

Based on the patch sent by Felipe Contreras:
https://patchwork.kernel.org/patch/101662/

Signed-off-by: Omar Ramirez Luna <omar.ramirez@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
  • Loading branch information
Omar Ramirez Luna authored and Tony Lindgren committed Feb 24, 2011
1 parent 69dbf85 commit 82d2a5d
Showing 1 changed file with 5 additions and 60 deletions.
65 changes: 5 additions & 60 deletions arch/arm/mach-omap2/mailbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/pm_runtime.h>
#include <plat/mailbox.h>
#include <mach/irqs.h>

#define MAILBOX_REVISION 0x000
#define MAILBOX_SYSCONFIG 0x010
#define MAILBOX_SYSSTATUS 0x014
#define MAILBOX_MESSAGE(m) (0x040 + 4 * (m))
#define MAILBOX_FIFOSTATUS(m) (0x080 + 4 * (m))
#define MAILBOX_MSGSTATUS(m) (0x0c0 + 4 * (m))
Expand All @@ -33,17 +32,6 @@
#define MAILBOX_IRQ_NEWMSG(m) (1 << (2 * (m)))
#define MAILBOX_IRQ_NOTFULL(m) (1 << (2 * (m) + 1))

/* SYSCONFIG: register bit definition */
#define AUTOIDLE (1 << 0)
#define SOFTRESET (1 << 1)
#define SMARTIDLE (2 << 3)
#define OMAP4_SOFTRESET (1 << 0)
#define OMAP4_NOIDLE (1 << 2)
#define OMAP4_SMARTIDLE (2 << 2)

/* SYSSTATUS: register bit definition */
#define RESETDONE (1 << 0)

#define MBOX_REG_SIZE 0x120

#define OMAP4_MBOX_REG_SIZE 0x130
Expand All @@ -70,8 +58,6 @@ struct omap_mbox2_priv {
unsigned long irqdisable;
};

static struct clk *mbox_ick_handle;

static void omap2_mbox_enable_irq(struct omap_mbox *mbox,
omap_mbox_type_t irq);

Expand All @@ -89,63 +75,22 @@ static inline void mbox_write_reg(u32 val, size_t ofs)
static int omap2_mbox_startup(struct omap_mbox *mbox)
{
u32 l;
unsigned long timeout;

mbox_ick_handle = clk_get(NULL, "mailboxes_ick");
if (IS_ERR(mbox_ick_handle)) {
printk(KERN_ERR "Could not get mailboxes_ick: %ld\n",
PTR_ERR(mbox_ick_handle));
return PTR_ERR(mbox_ick_handle);
}
clk_enable(mbox_ick_handle);

if (cpu_is_omap44xx()) {
mbox_write_reg(OMAP4_SOFTRESET, MAILBOX_SYSCONFIG);
timeout = jiffies + msecs_to_jiffies(20);
do {
l = mbox_read_reg(MAILBOX_SYSCONFIG);
if (!(l & OMAP4_SOFTRESET))
break;
} while (!time_after(jiffies, timeout));

if (l & OMAP4_SOFTRESET) {
pr_err("Can't take mailbox out of reset\n");
return -ENODEV;
}
} else {
mbox_write_reg(SOFTRESET, MAILBOX_SYSCONFIG);
timeout = jiffies + msecs_to_jiffies(20);
do {
l = mbox_read_reg(MAILBOX_SYSSTATUS);
if (l & RESETDONE)
break;
} while (!time_after(jiffies, timeout));

if (!(l & RESETDONE)) {
pr_err("Can't take mailbox out of reset\n");
return -ENODEV;
}
}
pm_runtime_enable(mbox->dev->parent);
pm_runtime_get_sync(mbox->dev->parent);

l = mbox_read_reg(MAILBOX_REVISION);
pr_debug("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f));

if (cpu_is_omap44xx())
l = OMAP4_SMARTIDLE;
else
l = SMARTIDLE | AUTOIDLE;
mbox_write_reg(l, MAILBOX_SYSCONFIG);

omap2_mbox_enable_irq(mbox, IRQ_RX);

return 0;
}

static void omap2_mbox_shutdown(struct omap_mbox *mbox)
{
clk_disable(mbox_ick_handle);
clk_put(mbox_ick_handle);
mbox_ick_handle = NULL;
pm_runtime_put_sync(mbox->dev->parent);
pm_runtime_disable(mbox->dev->parent);
}

/* Mailbox FIFO handle functions */
Expand Down

0 comments on commit 82d2a5d

Please sign in to comment.