hm60x/hm801: Buttons rework.
[maemo-rb.git] / firmware / target / arm / imx233 / dma-imx233.h
blob05baea989c25367762327b1e526d1aa6bc232bf1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2011 by amaury Pouly
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
24 #ifndef __DMA_IMX233_H__
25 #define __DMA_IMX233_H__
27 #include "cpu.h"
28 #include "system.h"
29 #include "system-target.h"
31 /********
32 * APHB *
33 ********/
35 #define HW_APBH_BASE 0x80004000
37 /* APHB channels */
38 #define HW_APBH_SSP(ssp) ssp
40 #define HW_APBH_CTRL0 (*(volatile uint32_t *)(HW_APBH_BASE + 0x0))
41 #define HW_APBH_CTRL0__FREEZE_CHANNEL(i) (1 << (i))
42 #define HW_APBH_CTRL0__CLKGATE_CHANNEL(i) (1 << ((i) + 8))
43 #define HW_APBH_CTRL0__RESET_CHANNEL(i) (1 << ((i) + 16))
44 #define HW_APBH_CTRL0__APB_BURST4_EN (1 << 28)
45 #define HW_APBH_CTRL0__APB_BURST8_EN (1 << 29)
47 #define HW_APBH_CTRL1 (*(volatile uint32_t *)(HW_APBH_BASE + 0x10))
48 #define HW_APBH_CTRL1__CHx_CMDCMPLT_IRQ(i) (1 << (i))
49 #define HW_APBH_CTRL1__CHx_CMDCMPLT_IRQ_EN(i) (1 << ((i) + 16))
51 #define HW_APBH_CTRL2 (*(volatile uint32_t *)(HW_APBH_BASE + 0x20))
52 #define HW_APBH_CTRL2__CHx_ERROR_IRQ(i) (1 << (i))
53 #define HW_APBH_CTRL2__CHx_ERROR_STATUS(i) (1 << ((i) + 16))
55 #define HW_APBH_CHx_CURCMDAR(i) (*(volatile uint32_t *)(HW_APBH_BASE + 0x40 + 0x70 * (i)))
57 #define HW_APBH_CHx_NXTCMDAR(i) (*(volatile uint32_t *)(HW_APBH_BASE + 0x50 + 0x70 * (i)))
59 #define HW_APBH_CHx_CMD(i) (*(volatile uint32_t *)(HW_APBH_BASE + 0x60 + 0x70 * (i)))
61 #define HW_APBH_CHx_BAR(i) (*(volatile uint32_t *)(HW_APBH_BASE + 0x70 + 0x70 * (i)))
63 #define HW_APBH_CHx_SEMA(i) (*(volatile uint32_t *)(HW_APBH_BASE + 0x80 + 0x70 * (i)))
65 #define HW_APBH_CHx_DEBUG1(i) (*(volatile uint32_t *)(HW_APBH_BASE + 0x90 + 0x70 * (i)))
67 #define HW_APBH_CHx_DEBUG2(i) (*(volatile uint32_t *)(HW_APBH_BASE + 0xa0 + 0x70 * (i)))
68 #define HW_APBH_CHx_DEBUG2__AHB_BYTES_BP 0
69 #define HW_APBH_CHx_DEBUG2__AHB_BYTES_BM 0xffff
70 #define HW_APBH_CHx_DEBUG2__APB_BYTES_BP 16
71 #define HW_APBH_CHx_DEBUG2__APB_BYTES_BM 0xffff0000
73 /********
74 * APHX *
75 ********/
77 /* APHX channels */
78 #define HW_APBX_AUDIO_ADC 0
79 #define HW_APBX_AUDIO_DAC 1
80 #define HW_APBX_I2C 3
82 #define HW_APBX_BASE 0x80024000
84 #define HW_APBX_CTRL0 (*(volatile uint32_t *)(HW_APBX_BASE + 0x0))
86 #define HW_APBX_CTRL1 (*(volatile uint32_t *)(HW_APBX_BASE + 0x10))
87 #define HW_APBX_CTRL1__CHx_CMDCMPLT_IRQ(i) (1 << (i))
88 #define HW_APBX_CTRL1__CHx_CMDCMPLT_IRQ_EN(i) (1 << ((i) + 16))
90 #define HW_APBX_CTRL2 (*(volatile uint32_t *)(HW_APBX_BASE + 0x20))
91 #define HW_APBX_CTRL2__CHx_ERROR_IRQ(i) (1 << (i))
92 #define HW_APBX_CTRL2__CHx_ERROR_STATUS(i) (1 << ((i) + 16))
94 #define HW_APBX_CHANNEL_CTRL (*(volatile uint32_t *)(HW_APBX_BASE + 0x30))
95 #define HW_APBX_CHANNEL_CTRL__FREEZE_CHANNEL(i) (1 << (i))
96 #define HW_APBX_CHANNEL_CTRL__RESET_CHANNEL(i) (1 << ((i) + 16))
98 #define HW_APBX_CHx_CURCMDAR(i) (*(volatile uint32_t *)(HW_APBX_BASE + 0x100 + (i) * 0x70))
100 #define HW_APBX_CHx_NXTCMDAR(i) (*(volatile uint32_t *)(HW_APBX_BASE + 0x110 + (i) * 0x70))
102 #define HW_APBX_CHx_CMD(i) (*(volatile uint32_t *)(HW_APBX_BASE + 0x120 + (i) * 0x70))
104 #define HW_APBX_CHx_BAR(i) (*(volatile uint32_t *)(HW_APBX_BASE + 0x130 + (i) * 0x70))
106 #define HW_APBX_CHx_SEMA(i) (*(volatile uint32_t *)(HW_APBX_BASE + 0x140 + (i) * 0x70))
108 #define HW_APBX_CHx_DEBUG1(i) (*(volatile uint32_t *)(HW_APBX_BASE + 0x150 + (i) * 0x70))
110 #define HW_APBX_CHx_DEBUG2(i) (*(volatile uint32_t *)(HW_APBX_BASE + 0x160 + (i) * 0x70))
111 #define HW_APBX_CHx_DEBUG2__AHB_BYTES_BP 0
112 #define HW_APBX_CHx_DEBUG2__AHB_BYTES_BM 0xffff
113 #define HW_APBX_CHx_DEBUG2__APB_BYTES_BP 16
114 #define HW_APBX_CHx_DEBUG2__APB_BYTES_BM 0xffff0000
116 /**********
117 * COMMON *
118 **********/
120 struct apb_dma_command_t
122 struct apb_dma_command_t *next;
123 uint32_t cmd;
124 void *buffer;
125 /* PIO words follow */
128 #define DMA_INFO_CURCMDADDR (1 << 0)
129 #define DMA_INFO_NXTCMDADDR (1 << 1)
130 #define DMA_INFO_CMD (1 << 2)
131 #define DMA_INFO_BAR (1 << 3)
132 #define DMA_INFO_APB_BYTES (1 << 4)
133 #define DMA_INFO_AHB_BYTES (1 << 5)
134 #define DMA_INFO_FREEZED (1 << 6)
135 #define DMA_INFO_GATED (1 << 7)
136 #define DMA_INFO_INTERRUPT (1 << 8)
137 #define DMA_INFO_ALL 0x1ff
139 struct imx233_dma_info_t
141 unsigned long cur_cmd_addr;
142 unsigned long nxt_cmd_addr;
143 unsigned long cmd;
144 unsigned long bar;
145 unsigned apb_bytes;
146 unsigned ahb_bytes;
147 bool freezed;
148 bool gated;
149 bool int_enabled;
150 bool int_cmdcomplt;
151 bool int_error;
154 #define APBH_DMA_CHANNEL(i) i
155 #define APBX_DMA_CHANNEL(i) ((i) | 0x10)
156 #define APB_IS_APBX_CHANNEL(x) ((x) & 0x10)
157 #define APB_GET_DMA_CHANNEL(x) ((x) & 0xf)
159 #define APB_SSP(ssp) APBH_DMA_CHANNEL(HW_APBH_SSP(ssp))
160 #define APB_AUDIO_ADC APBX_DMA_CHANNEL(HW_APBX_AUDIO_ADC)
161 #define APB_AUDIO_DAC APBX_DMA_CHANNEL(HW_APBX_AUDIO_DAC)
162 #define APB_I2C APBX_DMA_CHANNEL(HW_APBX_I2C)
164 #define HW_APB_CHx_CMD__COMMAND_BM 0x3
165 #define HW_APB_CHx_CMD__COMMAND__NO_XFER 0
166 #define HW_APB_CHx_CMD__COMMAND__WRITE 1
167 #define HW_APB_CHx_CMD__COMMAND__READ 2
168 #define HW_APB_CHx_CMD__COMMAND__SENSE 3
169 #define HW_APB_CHx_CMD__CHAIN (1 << 2)
170 #define HW_APB_CHx_CMD__IRQONCMPLT (1 << 3)
171 /* those two are only available on APHB */
172 #define HW_APBH_CHx_CMD__NANDLOCK (1 << 4)
173 #define HW_APBH_CHx_CMD__NANDWAIT4READY (1 << 5)
174 #define HW_APB_CHx_CMD__SEMAPHORE (1 << 6)
175 #define HW_APB_CHx_CMD__WAIT4ENDCMD (1 << 7)
176 /* An errata advise not to use it */
177 //#define HW_APB_CHx_CMD__HALTONTERMINATE (1 << 8)
178 #define HW_APB_CHx_CMD__CMDWORDS_BM 0xf000
179 #define HW_APB_CHx_CMD__CMDWORDS_BP 12
180 #define HW_APB_CHx_CMD__XFER_COUNT_BM 0xffff0000
181 #define HW_APB_CHx_CMD__XFER_COUNT_BP 16
182 /* For software use */
183 #define HW_APB_CHx_CMD__UNUSED_BP 8
184 #define HW_APB_CHx_CMD__UNUSED_BM (0xf << 8)
185 #define HW_APB_CHx_CMD__UNUSED_MAGIC (0xa << 8)
187 #define HW_APB_CHx_SEMA__PHORE_BM 0xff0000
188 #define HW_APB_CHx_SEMA__PHORE_BP 16
190 /* A single descriptor cannot transfer more than 2^16 bytes */
191 #define IMX233_MAX_SINGLE_DMA_XFER_SIZE (1 << 16)
193 void imx233_dma_init(void);
194 void imx233_dma_reset_channel(unsigned chan);
195 /* only apbh channel have clkgate control */
196 void imx233_dma_clkgate_channel(unsigned chan, bool enable_clock);
198 void imx233_dma_freeze_channel(unsigned chan, bool freeze);
199 void imx233_dma_enable_channel_interrupt(unsigned chan, bool enable);
200 /* clear both channel complete and error bits */
201 void imx233_dma_clear_channel_interrupt(unsigned chan);
202 bool imx233_dma_is_channel_error_irq(unsigned chan);
203 /* assume no command is in progress */
204 void imx233_dma_start_command(unsigned chan, struct apb_dma_command_t *cmd);
205 void imx233_dma_wait_completion(unsigned chan);
206 /* get some info
207 * WARNING: if channel is not freezed, data might not be coherent ! */
208 struct imx233_dma_info_t imx233_dma_get_info(unsigned chan, unsigned flags);
210 #endif // __DMA_IMX233_H__