0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #include <linux/init.h>
0034 #include <linux/export.h>
0035 #include <linux/kernel.h>
0036 #include <linux/errno.h>
0037 #include <linux/spinlock.h>
0038 #include <linux/interrupt.h>
0039
0040 #include <asm/mach-au1x00/au1000.h>
0041 #include <asm/mach-au1x00/au1000_dma.h>
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060 #define DMA_CHANNEL_LEN 0x00000100
0061
0062 DEFINE_SPINLOCK(au1000_dma_spin_lock);
0063
0064 struct dma_chan au1000_dma_table[NUM_AU1000_DMA_CHANNELS] = {
0065 {.dev_id = -1,},
0066 {.dev_id = -1,},
0067 {.dev_id = -1,},
0068 {.dev_id = -1,},
0069 {.dev_id = -1,},
0070 {.dev_id = -1,},
0071 {.dev_id = -1,},
0072 {.dev_id = -1,}
0073 };
0074 EXPORT_SYMBOL(au1000_dma_table);
0075
0076
0077 static const struct dma_dev {
0078 unsigned int fifo_addr;
0079 unsigned int dma_mode;
0080 } dma_dev_table[DMA_NUM_DEV] = {
0081 { AU1000_UART0_PHYS_ADDR + 0x04, DMA_DW8 },
0082 { AU1000_UART0_PHYS_ADDR + 0x00, DMA_DW8 | DMA_DR },
0083 { 0, 0 },
0084 { 0, 0 },
0085 { AU1000_AC97_PHYS_ADDR + 0x08, DMA_DW16 },
0086 { AU1000_AC97_PHYS_ADDR + 0x08, DMA_DW16 | DMA_DR },
0087 { AU1000_UART3_PHYS_ADDR + 0x04, DMA_DW8 | DMA_NC },
0088 { AU1000_UART3_PHYS_ADDR + 0x00, DMA_DW8 | DMA_NC | DMA_DR },
0089 { AU1000_USB_UDC_PHYS_ADDR + 0x00, DMA_DW8 | DMA_NC | DMA_DR },
0090 { AU1000_USB_UDC_PHYS_ADDR + 0x04, DMA_DW8 | DMA_NC },
0091 { AU1000_USB_UDC_PHYS_ADDR + 0x08, DMA_DW8 | DMA_NC },
0092 { AU1000_USB_UDC_PHYS_ADDR + 0x0c, DMA_DW8 | DMA_NC },
0093 { AU1000_USB_UDC_PHYS_ADDR + 0x10, DMA_DW8 | DMA_NC | DMA_DR },
0094 { AU1000_USB_UDC_PHYS_ADDR + 0x14, DMA_DW8 | DMA_NC | DMA_DR },
0095
0096 { AU1000_I2S_PHYS_ADDR + 0x00, DMA_DW32 | DMA_NC},
0097 { AU1000_I2S_PHYS_ADDR + 0x00, DMA_DW32 | DMA_NC | DMA_DR},
0098 };
0099
0100 int au1000_dma_read_proc(char *buf, char **start, off_t fpos,
0101 int length, int *eof, void *data)
0102 {
0103 int i, len = 0;
0104 struct dma_chan *chan;
0105
0106 for (i = 0; i < NUM_AU1000_DMA_CHANNELS; i++) {
0107 chan = get_dma_chan(i);
0108 if (chan != NULL)
0109 len += sprintf(buf + len, "%2d: %s\n",
0110 i, chan->dev_str);
0111 }
0112
0113 if (fpos >= len) {
0114 *start = buf;
0115 *eof = 1;
0116 return 0;
0117 }
0118 *start = buf + fpos;
0119 len -= fpos;
0120 if (len > length)
0121 return length;
0122 *eof = 1;
0123 return len;
0124 }
0125
0126
0127 static const struct dma_dev dma_dev_table_bank2[DMA_NUM_DEV_BANK2] = {
0128 { AU1100_SD0_PHYS_ADDR + 0x00, DMA_DS | DMA_DW8 },
0129 { AU1100_SD0_PHYS_ADDR + 0x04, DMA_DS | DMA_DW8 | DMA_DR },
0130 { AU1100_SD1_PHYS_ADDR + 0x00, DMA_DS | DMA_DW8 },
0131 { AU1100_SD1_PHYS_ADDR + 0x04, DMA_DS | DMA_DW8 | DMA_DR }
0132 };
0133
0134 void dump_au1000_dma_channel(unsigned int dmanr)
0135 {
0136 struct dma_chan *chan;
0137
0138 if (dmanr >= NUM_AU1000_DMA_CHANNELS)
0139 return;
0140 chan = &au1000_dma_table[dmanr];
0141
0142 printk(KERN_INFO "Au1000 DMA%d Register Dump:\n", dmanr);
0143 printk(KERN_INFO " mode = 0x%08x\n",
0144 __raw_readl(chan->io + DMA_MODE_SET));
0145 printk(KERN_INFO " addr = 0x%08x\n",
0146 __raw_readl(chan->io + DMA_PERIPHERAL_ADDR));
0147 printk(KERN_INFO " start0 = 0x%08x\n",
0148 __raw_readl(chan->io + DMA_BUFFER0_START));
0149 printk(KERN_INFO " start1 = 0x%08x\n",
0150 __raw_readl(chan->io + DMA_BUFFER1_START));
0151 printk(KERN_INFO " count0 = 0x%08x\n",
0152 __raw_readl(chan->io + DMA_BUFFER0_COUNT));
0153 printk(KERN_INFO " count1 = 0x%08x\n",
0154 __raw_readl(chan->io + DMA_BUFFER1_COUNT));
0155 }
0156
0157
0158
0159
0160
0161
0162 int request_au1000_dma(int dev_id, const char *dev_str,
0163 irq_handler_t irqhandler,
0164 unsigned long irqflags,
0165 void *irq_dev_id)
0166 {
0167 struct dma_chan *chan;
0168 const struct dma_dev *dev;
0169 int i, ret;
0170
0171 if (alchemy_get_cputype() == ALCHEMY_CPU_AU1100) {
0172 if (dev_id < 0 || dev_id >= (DMA_NUM_DEV + DMA_NUM_DEV_BANK2))
0173 return -EINVAL;
0174 } else {
0175 if (dev_id < 0 || dev_id >= DMA_NUM_DEV)
0176 return -EINVAL;
0177 }
0178
0179 for (i = 0; i < NUM_AU1000_DMA_CHANNELS; i++)
0180 if (au1000_dma_table[i].dev_id < 0)
0181 break;
0182
0183 if (i == NUM_AU1000_DMA_CHANNELS)
0184 return -ENODEV;
0185
0186 chan = &au1000_dma_table[i];
0187
0188 if (dev_id >= DMA_NUM_DEV) {
0189 dev_id -= DMA_NUM_DEV;
0190 dev = &dma_dev_table_bank2[dev_id];
0191 } else
0192 dev = &dma_dev_table[dev_id];
0193
0194 if (irqhandler) {
0195 chan->irq_dev = irq_dev_id;
0196 ret = request_irq(chan->irq, irqhandler, irqflags, dev_str,
0197 chan->irq_dev);
0198 if (ret) {
0199 chan->irq_dev = NULL;
0200 return ret;
0201 }
0202 } else {
0203 chan->irq_dev = NULL;
0204 }
0205
0206
0207 chan->io = (void __iomem *)(KSEG1ADDR(AU1000_DMA_PHYS_ADDR) +
0208 i * DMA_CHANNEL_LEN);
0209 chan->dev_id = dev_id;
0210 chan->dev_str = dev_str;
0211 chan->fifo_addr = dev->fifo_addr;
0212 chan->mode = dev->dma_mode;
0213
0214
0215 init_dma(i);
0216
0217 return i;
0218 }
0219 EXPORT_SYMBOL(request_au1000_dma);
0220
0221 void free_au1000_dma(unsigned int dmanr)
0222 {
0223 struct dma_chan *chan = get_dma_chan(dmanr);
0224
0225 if (!chan) {
0226 printk(KERN_ERR "Error trying to free DMA%d\n", dmanr);
0227 return;
0228 }
0229
0230 disable_dma(dmanr);
0231 if (chan->irq_dev)
0232 free_irq(chan->irq, chan->irq_dev);
0233
0234 chan->irq_dev = NULL;
0235 chan->dev_id = -1;
0236 }
0237 EXPORT_SYMBOL(free_au1000_dma);
0238
0239 static int __init au1000_dma_init(void)
0240 {
0241 int base, i;
0242
0243 switch (alchemy_get_cputype()) {
0244 case ALCHEMY_CPU_AU1000:
0245 base = AU1000_DMA_INT_BASE;
0246 break;
0247 case ALCHEMY_CPU_AU1500:
0248 base = AU1500_DMA_INT_BASE;
0249 break;
0250 case ALCHEMY_CPU_AU1100:
0251 base = AU1100_DMA_INT_BASE;
0252 break;
0253 default:
0254 goto out;
0255 }
0256
0257 for (i = 0; i < NUM_AU1000_DMA_CHANNELS; i++)
0258 au1000_dma_table[i].irq = base + i;
0259
0260 printk(KERN_INFO "Alchemy DMA initialized\n");
0261
0262 out:
0263 return 0;
0264 }
0265 arch_initcall(au1000_dma_init);