11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/module.h>
21 #include <linux/nubus.h>
22 #include <linux/slab.h>
34 #define DRV_MODULE_NAME "mac_esp"
35 #define PFX DRV_MODULE_NAME ": "
36 #define DRV_VERSION "1.000"
37 #define DRV_MODULE_RELDATE "Sept 15, 2007"
39 #define MAC_ESP_IO_BASE 0x50F00000
40 #define MAC_ESP_REGS_QUADRA (MAC_ESP_IO_BASE + 0x10000)
41 #define MAC_ESP_REGS_QUADRA2 (MAC_ESP_IO_BASE + 0xF000)
42 #define MAC_ESP_REGS_QUADRA3 (MAC_ESP_IO_BASE + 0x18000)
43 #define MAC_ESP_REGS_SPACING 0x402
44 #define MAC_ESP_PDMA_REG 0xF9800024
45 #define MAC_ESP_PDMA_REG_SPACING 0x4
46 #define MAC_ESP_PDMA_IO_OFFSET 0x100
48 #define esp_read8(REG) mac_esp_read8(esp, REG)
49 #define esp_write8(VAL, REG) mac_esp_write8(esp, VAL, REG)
57 static struct esp *esp_chips[2];
59 #define MAC_ESP_GET_PRIV(esp) ((struct mac_esp_priv *) \
60 platform_get_drvdata((struct platform_device *) \
63 static inline void mac_esp_write8(
struct esp *
esp,
u8 val,
unsigned long reg)
68 static inline u8 mac_esp_read8(
struct esp *
esp,
unsigned long reg)
83 static int mac_esp_map_sg(
struct esp *esp,
struct scatterlist *
sg,
88 for (i = 0; i < num_sg; i++)
99 static void mac_esp_unmap_sg(
struct esp *esp,
struct scatterlist *sg,
105 static void mac_esp_reset_dma(
struct esp *esp)
110 static void mac_esp_dma_drain(
struct esp *esp)
115 static void mac_esp_dma_invalidate(
struct esp *esp)
120 static int mac_esp_dma_error(
struct esp *esp)
125 static inline int mac_esp_wait_for_empty_fifo(
struct esp *esp)
146 static inline int mac_esp_wait_for_dreq(
struct esp *esp)
172 #define MAC_ESP_PDMA_LOOP(operands) \
176 "1: movew " operands " \n" \
177 "2: movew " operands " \n" \
178 "3: movew " operands " \n" \
179 "4: movew " operands " \n" \
180 "5: movew " operands " \n" \
181 "6: movew " operands " \n" \
182 "7: movew " operands " \n" \
183 "8: movew " operands " \n" \
184 "9: movew " operands " \n" \
185 "10: movew " operands " \n" \
186 "11: movew " operands " \n" \
187 "12: movew " operands " \n" \
188 "13: movew " operands " \n" \
189 "14: movew " operands " \n" \
190 "15: movew " operands " \n" \
191 "16: movew " operands " \n" \
196 "21: movew " operands " \n" \
201 "31: moveb " operands " \n" \
205 " .section __ex_table,\"a\" \n" \
216 " .long 10b,40b \n" \
217 " .long 11b,40b \n" \
218 " .long 12b,40b \n" \
219 " .long 13b,40b \n" \
220 " .long 14b,40b \n" \
221 " .long 15b,40b \n" \
222 " .long 16b,40b \n" \
223 " .long 21b,40b \n" \
224 " .long 31b,40b \n" \
225 " .long 32b,40b \n" \
227 : "+a" (addr), "+r" (count32), "+r" (count2) \
228 : "g" (count1), "a" (mep->pdma_io))
230 static void mac_esp_send_pdma_cmd(
struct esp *esp,
u32 addr,
u32 esp_count,
246 unsigned int count32 = esp_count >> 5;
247 unsigned int count2 = (esp_count & 0x1F) >> 1;
248 unsigned int count1 = esp_count & 1;
251 if (mac_esp_wait_for_dreq(esp))
263 if (mac_esp_wait_for_empty_fifo(esp))
267 addr = start_addr + esp_count -
n;
277 static inline unsigned int mac_esp_wait_for_fifo(
struct esp *esp)
295 static inline int mac_esp_wait_for_intr(
struct esp *esp)
313 #define MAC_ESP_PIO_LOOP(operands, reg1) \
315 "1: moveb " operands " \n" \
318 : "+a" (addr), "+r" (reg1) \
321 #define MAC_ESP_PIO_FILL(operands, reg1) \
323 " moveb " operands " \n" \
324 " moveb " operands " \n" \
325 " moveb " operands " \n" \
326 " moveb " operands " \n" \
327 " moveb " operands " \n" \
328 " moveb " operands " \n" \
329 " moveb " operands " \n" \
330 " moveb " operands " \n" \
331 " moveb " operands " \n" \
332 " moveb " operands " \n" \
333 " moveb " operands " \n" \
334 " moveb " operands " \n" \
335 " moveb " operands " \n" \
336 " moveb " operands " \n" \
337 " moveb " operands " \n" \
338 " moveb " operands " \n" \
341 : "+a" (addr), "+r" (reg1) \
344 #define MAC_ESP_FIFO_SIZE 16
346 static void mac_esp_send_pio_cmd(
struct esp *esp,
u32 addr,
u32 esp_count,
361 n = mac_esp_wait_for_fifo(esp);
374 if (mac_esp_wait_for_intr(esp))
401 if (mac_esp_wait_for_intr(esp))
430 static int mac_esp_irq_pending(
struct esp *esp)
439 return dma_len > 0xFFFF ? 0xFFFF : dma_len;
459 (mac_esp_read8(esp_chips[1],
ESP_STATUS) & ESP_STAT_INTR)) {
469 .esp_write8 = mac_esp_write8,
470 .esp_read8 = mac_esp_read8,
471 .map_single = mac_esp_map_single,
472 .map_sg = mac_esp_map_sg,
473 .unmap_single = mac_esp_unmap_single,
474 .unmap_sg = mac_esp_unmap_sg,
475 .irq_pending = mac_esp_irq_pending,
476 .dma_length_limit = mac_esp_dma_length_limit,
477 .reset_dma = mac_esp_reset_dma,
478 .dma_drain = mac_esp_dma_drain,
479 .dma_invalidate = mac_esp_dma_invalidate,
480 .send_dma_cmd = mac_esp_send_pdma_cmd,
481 .dma_error = mac_esp_dma_error,
506 esp = shost_priv(host);
522 goto fail_free_command_block;
524 platform_set_drvdata(dev, mep);
528 esp->
cfreq = 16500000;
534 esp->
cfreq = 25000000;
546 esp->
cfreq = 25000000;
553 esp->
ops = &mac_esp_ops;
565 esp_chips[dev->
id] =
esp;
567 if (esp_chips[!dev->
id] ==
NULL) {
570 esp_chips[dev->
id] =
NULL;
582 if (esp_chips[!dev->
id] ==
NULL)
586 fail_free_command_block:
597 struct esp *esp = mep->
esp;
598 unsigned int irq = esp->
host->irq;
602 esp_chips[dev->
id] =
NULL;
603 if (!(esp_chips[0] || esp_chips[1]))
616 .probe = esp_mac_probe,
624 static int __init mac_esp_init(
void)
629 static void __exit mac_esp_exit(
void)