~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to arch/arm/mach-omap2/mailbox.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include <linux/platform_device.h>
16
16
#include <linux/io.h>
17
17
#include <linux/pm_runtime.h>
18
 
#include <linux/slab.h>
19
18
#include <plat/mailbox.h>
20
19
#include <mach/irqs.h>
21
20
 
22
21
#define MAILBOX_REVISION                0x000
23
 
#define MAILBOX_SYSCONFIG               0x010
24
 
#define MAILBOX_SYSSTATUS               0x014
25
 
#define MAILBOX_MESSAGE(m)              (0x040 + 0x4 * (m))
26
 
#define MAILBOX_FIFOSTATUS(m)           (0x080 + 0x4 * (m))
27
 
#define MAILBOX_MSGSTATUS(m)            (0x0c0 + 0x4 * (m))
28
 
#define MAILBOX_IRQSTATUS(u)            (0x100 + 0x8 * (u))
29
 
#define MAILBOX_IRQENABLE(u)            (0x104 + 0x8 * (u))
 
22
#define MAILBOX_MESSAGE(m)              (0x040 + 4 * (m))
 
23
#define MAILBOX_FIFOSTATUS(m)           (0x080 + 4 * (m))
 
24
#define MAILBOX_MSGSTATUS(m)            (0x0c0 + 4 * (m))
 
25
#define MAILBOX_IRQSTATUS(u)            (0x100 + 8 * (u))
 
26
#define MAILBOX_IRQENABLE(u)            (0x104 + 8 * (u))
30
27
 
31
 
#define OMAP4_MAILBOX_IRQSTATUS(u)      (0x104 + 0x10 * (u))
32
 
#define OMAP4_MAILBOX_IRQENABLE(u)      (0x108 + 0x10 * (u))
33
 
#define OMAP4_MAILBOX_IRQENABLE_CLR(u)  (0x10c + 0x10 * (u))
 
28
#define OMAP4_MAILBOX_IRQSTATUS(u)      (0x104 + 10 * (u))
 
29
#define OMAP4_MAILBOX_IRQENABLE(u)      (0x108 + 10 * (u))
 
30
#define OMAP4_MAILBOX_IRQENABLE_CLR(u)  (0x10c + 10 * (u))
34
31
 
35
32
#define MAILBOX_IRQ_NEWMSG(m)           (1 << (2 * (m)))
36
33
#define MAILBOX_IRQ_NOTFULL(m)          (1 << (2 * (m) + 1))
37
34
 
38
35
#define MBOX_REG_SIZE                   0x120
39
36
 
40
 
#define MBOX_NUM_USER                   2
41
 
#define OMAP4_MBOX_NUM_USER             3
42
 
 
43
37
#define OMAP4_MBOX_REG_SIZE             0x130
44
38
 
45
 
#define MBOX_NR_REGS                    2
46
 
#define OMAP4_MBOX_NR_REGS              3
47
 
 
48
 
/* SYSCONFIG: register bit definition */
49
 
#define AUTOIDLE        (1 << 0)
50
 
#define SOFTRESET       (1 << 1)
51
 
#define SMARTIDLE       (2 << 3)
52
 
#define OMAP4_SOFTRESET (1 << 0)
53
 
#define OMAP4_NOIDLE    (1 << 2)
54
 
#define OMAP4_SMARTIDLE (2 << 2)
55
 
 
56
 
#define RESETDONE       (1 << 0)
 
39
#define MBOX_NR_REGS                    (MBOX_REG_SIZE / sizeof(u32))
 
40
#define OMAP4_MBOX_NR_REGS              (OMAP4_MBOX_REG_SIZE / sizeof(u32))
57
41
 
58
42
static void __iomem *mbox_base;
59
 
static u32 *mbox_ctx;
60
 
static int nr_mbox_users;
61
 
static struct clk *mbox_ick_handle;
62
43
 
63
44
struct omap_mbox2_fifo {
64
45
        unsigned long msg;
73
54
        unsigned long irqstatus;
74
55
        u32 newmsg_bit;
75
56
        u32 notfull_bit;
 
57
        u32 ctx[OMAP4_MBOX_NR_REGS];
76
58
        unsigned long irqdisable;
77
59
};
78
60
 
93
75
static int omap2_mbox_startup(struct omap_mbox *mbox)
94
76
{
95
77
        u32 l;
96
 
        unsigned long timeout;
97
78
 
98
79
        pm_runtime_enable(mbox->dev->parent);
99
80
        pm_runtime_get_sync(mbox->dev->parent);
100
 
        
101
 
        if (!cpu_is_omap44xx()) {
102
 
                mbox_ick_handle = clk_get(NULL, "mailboxes_ick");
103
 
                if (IS_ERR(mbox_ick_handle)) {
104
 
                        printk(KERN_ERR "Could not get mailboxes_ick: %ld\n",
105
 
                                PTR_ERR(mbox_ick_handle));
106
 
                        return PTR_ERR(mbox_ick_handle);
107
 
                }
108
 
                clk_enable(mbox_ick_handle);
109
 
        }
110
 
 
111
 
        if (cpu_is_omap44xx()) {
112
 
                mbox_write_reg(OMAP4_SOFTRESET, MAILBOX_SYSCONFIG);
113
 
                timeout = jiffies + msecs_to_jiffies(20);
114
 
                do {
115
 
                        l = mbox_read_reg(MAILBOX_SYSCONFIG);
116
 
                        if (!(l & OMAP4_SOFTRESET))
117
 
                                break;
118
 
                } while (!time_after(jiffies, timeout));
119
 
 
120
 
                if (l & OMAP4_SOFTRESET) {
121
 
                        pr_err("Can't take mailbox out of reset\n");
122
 
                        return -ENODEV;
123
 
                }
124
 
        } else {
125
 
                mbox_write_reg(SOFTRESET, MAILBOX_SYSCONFIG);
126
 
                timeout = jiffies + msecs_to_jiffies(20);
127
 
                do {
128
 
                        l = mbox_read_reg(MAILBOX_SYSSTATUS);
129
 
                        if (l & RESETDONE)
130
 
                                break;
131
 
                } while (!time_after(jiffies, timeout));
132
 
 
133
 
                if (!(l & RESETDONE)) {
134
 
                        pr_err("Can't take mailbox out of reset\n");
135
 
                        return -ENODEV;
136
 
                }
137
 
        }
138
81
 
139
82
        l = mbox_read_reg(MAILBOX_REVISION);
140
 
        pr_info("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f));
 
83
        pr_debug("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f));
141
84
 
142
85
        omap2_mbox_enable_irq(mbox, IRQ_RX);
143
86
 
148
91
{
149
92
        pm_runtime_put_sync(mbox->dev->parent);
150
93
        pm_runtime_disable(mbox->dev->parent);
151
 
 
152
 
        if (!cpu_is_omap44xx()) {
153
 
                clk_disable(mbox_ick_handle);
154
 
                clk_put(mbox_ick_handle);
155
 
                mbox_ick_handle = NULL;
156
 
        }
157
94
}
158
95
 
159
96
/* Mailbox FIFO handle functions */
234
171
 
235
172
static void omap2_mbox_save_ctx(struct omap_mbox *mbox)
236
173
{
237
 
        int i, j;
238
 
 
239
 
        /* Save irqs per user */
240
 
        for (j = 0, i = 0; j < nr_mbox_users; i++, j++) {
241
 
                if (cpu_is_omap44xx())
242
 
                        mbox_ctx[i] = mbox_read_reg(OMAP4_MAILBOX_IRQENABLE(j));
243
 
                else
244
 
                        mbox_ctx[i] = mbox_read_reg(MAILBOX_IRQENABLE(j));
 
174
        int i;
 
175
        struct omap_mbox2_priv *p = mbox->priv;
 
176
        int nr_regs;
 
177
        if (cpu_is_omap44xx())
 
178
                nr_regs = OMAP4_MBOX_NR_REGS;
 
179
        else
 
180
                nr_regs = MBOX_NR_REGS;
 
181
        for (i = 0; i < nr_regs; i++) {
 
182
                p->ctx[i] = mbox_read_reg(i * sizeof(u32));
245
183
 
246
184
                dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
247
 
                        i, mbox_ctx[i]);
 
185
                        i, p->ctx[i]);
248
186
        }
249
 
 
250
 
        omap2_mbox_shutdown(mbox);
251
187
}
252
188
 
253
189
static void omap2_mbox_restore_ctx(struct omap_mbox *mbox)
254
190
{
255
 
        int i, j;
256
 
 
257
 
        omap2_mbox_startup(mbox);
258
 
 
259
 
        /* Restore irqs per user */
260
 
        for (j = 0, i = 0; j < nr_mbox_users; i++, j++) {
261
 
                if (cpu_is_omap44xx())
262
 
                        mbox_write_reg(mbox_ctx[i], OMAP4_MAILBOX_IRQENABLE(j));
263
 
                else
264
 
                        mbox_write_reg(mbox_ctx[i], MAILBOX_IRQENABLE(j));
 
191
        int i;
 
192
        struct omap_mbox2_priv *p = mbox->priv;
 
193
        int nr_regs;
 
194
        if (cpu_is_omap44xx())
 
195
                nr_regs = OMAP4_MBOX_NR_REGS;
 
196
        else
 
197
                nr_regs = MBOX_NR_REGS;
 
198
        for (i = 0; i < nr_regs; i++) {
 
199
                mbox_write_reg(p->ctx[i], i * sizeof(u32));
265
200
 
266
201
                dev_dbg(mbox->dev, "%s: [%02x] %08x\n", __func__,
267
 
                                i, mbox_ctx[i]);
 
202
                        i, p->ctx[i]);
268
203
        }
269
204
}
270
205