Pull cpuidle into release branch
[linux-2.6] / arch / powerpc / sysdev / bestcomm / ata.c
1 /*
2  * Bestcomm ATA task driver
3  *
4  *
5  * Patterned after bestcomm/fec.c by Dale Farnsworth <dfarnsworth@mvista.com>
6  *                                   2003-2004 (c) MontaVista, Software, Inc.
7  *
8  * Copyright (C) 2006-2007 Sylvain Munaut <tnt@246tNt.com>
9  * Copyright (C) 2006      Freescale - John Rigby
10  *
11  * This file is licensed under the terms of the GNU General Public License
12  * version 2. This program is licensed "as is" without any warranty of any
13  * kind, whether express or implied.
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/types.h>
19 #include <asm/io.h>
20
21 #include "bestcomm.h"
22 #include "bestcomm_priv.h"
23 #include "ata.h"
24
25
26 /* ======================================================================== */
27 /* Task image/var/inc                                                       */
28 /* ======================================================================== */
29
30 /* ata task image */
31 extern u32 bcom_ata_task[];
32
33 /* ata task vars that need to be set before enabling the task */
34 struct bcom_ata_var {
35         u32 enable;             /* (u16*) address of task's control register */
36         u32 bd_base;            /* (struct bcom_bd*) beginning of ring buffer */
37         u32 bd_last;            /* (struct bcom_bd*) end of ring buffer */
38         u32 bd_start;           /* (struct bcom_bd*) current bd */
39         u32 buffer_size;        /* size of receive buffer */
40 };
41
42 /* ata task incs that need to be set before enabling the task */
43 struct bcom_ata_inc {
44         u16 pad0;
45         s16 incr_bytes;
46         u16 pad1;
47         s16 incr_dst;
48         u16 pad2;
49         s16 incr_src;
50 };
51
52
53 /* ======================================================================== */
54 /* Task support code                                                        */
55 /* ======================================================================== */
56
57 struct bcom_task *
58 bcom_ata_init(int queue_len, int maxbufsize)
59 {
60         struct bcom_task *tsk;
61         struct bcom_ata_var *var;
62         struct bcom_ata_inc *inc;
63
64         tsk = bcom_task_alloc(queue_len, sizeof(struct bcom_ata_bd), 0);
65         if (!tsk)
66                 return NULL;
67
68         tsk->flags = BCOM_FLAGS_NONE;
69
70         bcom_ata_reset_bd(tsk);
71
72         var = (struct bcom_ata_var *) bcom_task_var(tsk->tasknum);
73         inc = (struct bcom_ata_inc *) bcom_task_inc(tsk->tasknum);
74
75         if (bcom_load_image(tsk->tasknum, bcom_ata_task)) {
76                 bcom_task_free(tsk);
77                 return NULL;
78         }
79
80         var->enable     = bcom_eng->regs_base +
81                                 offsetof(struct mpc52xx_sdma, tcr[tsk->tasknum]);
82         var->bd_base    = tsk->bd_pa;
83         var->bd_last    = tsk->bd_pa + ((tsk->num_bd-1) * tsk->bd_size);
84         var->bd_start   = tsk->bd_pa;
85         var->buffer_size = maxbufsize;
86
87         /* Configure some stuff */
88         bcom_set_task_pragma(tsk->tasknum, BCOM_ATA_PRAGMA);
89         bcom_set_task_auto_start(tsk->tasknum, tsk->tasknum);
90
91         out_8(&bcom_eng->regs->ipr[BCOM_INITIATOR_ATA_RX], BCOM_IPR_ATA_RX);
92         out_8(&bcom_eng->regs->ipr[BCOM_INITIATOR_ATA_TX], BCOM_IPR_ATA_TX);
93
94         out_be32(&bcom_eng->regs->IntPend, 1<<tsk->tasknum); /* Clear ints */
95
96         return tsk;
97 }
98 EXPORT_SYMBOL_GPL(bcom_ata_init);
99
100 void bcom_ata_rx_prepare(struct bcom_task *tsk)
101 {
102         struct bcom_ata_inc *inc;
103
104         inc = (struct bcom_ata_inc *) bcom_task_inc(tsk->tasknum);
105
106         inc->incr_bytes = -(s16)sizeof(u32);
107         inc->incr_src   = 0;
108         inc->incr_dst   = sizeof(u32);
109
110         bcom_set_initiator(tsk->tasknum, BCOM_INITIATOR_ATA_RX);
111 }
112 EXPORT_SYMBOL_GPL(bcom_ata_rx_prepare);
113
114 void bcom_ata_tx_prepare(struct bcom_task *tsk)
115 {
116         struct bcom_ata_inc *inc;
117
118         inc = (struct bcom_ata_inc *) bcom_task_inc(tsk->tasknum);
119
120         inc->incr_bytes = -(s16)sizeof(u32);
121         inc->incr_src   = sizeof(u32);
122         inc->incr_dst   = 0;
123
124         bcom_set_initiator(tsk->tasknum, BCOM_INITIATOR_ATA_TX);
125 }
126 EXPORT_SYMBOL_GPL(bcom_ata_tx_prepare);
127
128 void bcom_ata_reset_bd(struct bcom_task *tsk)
129 {
130         struct bcom_ata_var *var;
131
132         /* Reset all BD */
133         memset(tsk->bd, 0x00, tsk->num_bd * tsk->bd_size);
134
135         tsk->index = 0;
136         tsk->outdex = 0;
137
138         var = (struct bcom_ata_var *) bcom_task_var(tsk->tasknum);
139         var->bd_start = var->bd_base;
140 }
141 EXPORT_SYMBOL_GPL(bcom_ata_reset_bd);
142
143 void bcom_ata_release(struct bcom_task *tsk)
144 {
145         /* Nothing special for the ATA tasks */
146         bcom_task_free(tsk);
147 }
148 EXPORT_SYMBOL_GPL(bcom_ata_release);
149
150
151 MODULE_DESCRIPTION("BestComm ATA task driver");
152 MODULE_AUTHOR("John Rigby");
153 MODULE_LICENSE("GPL v2");
154