ata.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/types.h>
  18. #include <asm/io.h>
  19. #include <linux/fsl/bestcomm/bestcomm.h>
  20. #include <linux/fsl/bestcomm/bestcomm_priv.h>
  21. #include <linux/fsl/bestcomm/ata.h>
  22. /* ======================================================================== */
  23. /* Task image/var/inc */
  24. /* ======================================================================== */
  25. /* ata task image */
  26. extern u32 bcom_ata_task[];
  27. /* ata task vars that need to be set before enabling the task */
  28. struct bcom_ata_var {
  29. u32 enable; /* (u16*) address of task's control register */
  30. u32 bd_base; /* (struct bcom_bd*) beginning of ring buffer */
  31. u32 bd_last; /* (struct bcom_bd*) end of ring buffer */
  32. u32 bd_start; /* (struct bcom_bd*) current bd */
  33. u32 buffer_size; /* size of receive buffer */
  34. };
  35. /* ata task incs that need to be set before enabling the task */
  36. struct bcom_ata_inc {
  37. u16 pad0;
  38. s16 incr_bytes;
  39. u16 pad1;
  40. s16 incr_dst;
  41. u16 pad2;
  42. s16 incr_src;
  43. };
  44. /* ======================================================================== */
  45. /* Task support code */
  46. /* ======================================================================== */
  47. struct bcom_task *
  48. bcom_ata_init(int queue_len, int maxbufsize)
  49. {
  50. struct bcom_task *tsk;
  51. struct bcom_ata_var *var;
  52. struct bcom_ata_inc *inc;
  53. /* Prefetch breaks ATA DMA. Turn it off for ATA DMA */
  54. bcom_disable_prefetch();
  55. tsk = bcom_task_alloc(queue_len, sizeof(struct bcom_ata_bd), 0);
  56. if (!tsk)
  57. return NULL;
  58. tsk->flags = BCOM_FLAGS_NONE;
  59. bcom_ata_reset_bd(tsk);
  60. var = (struct bcom_ata_var *) bcom_task_var(tsk->tasknum);
  61. inc = (struct bcom_ata_inc *) bcom_task_inc(tsk->tasknum);
  62. if (bcom_load_image(tsk->tasknum, bcom_ata_task)) {
  63. bcom_task_free(tsk);
  64. return NULL;
  65. }
  66. var->enable = bcom_eng->regs_base +
  67. offsetof(struct mpc52xx_sdma, tcr[tsk->tasknum]);
  68. var->bd_base = tsk->bd_pa;
  69. var->bd_last = tsk->bd_pa + ((tsk->num_bd-1) * tsk->bd_size);
  70. var->bd_start = tsk->bd_pa;
  71. var->buffer_size = maxbufsize;
  72. /* Configure some stuff */
  73. bcom_set_task_pragma(tsk->tasknum, BCOM_ATA_PRAGMA);
  74. bcom_set_task_auto_start(tsk->tasknum, tsk->tasknum);
  75. out_8(&bcom_eng->regs->ipr[BCOM_INITIATOR_ATA_RX], BCOM_IPR_ATA_RX);
  76. out_8(&bcom_eng->regs->ipr[BCOM_INITIATOR_ATA_TX], BCOM_IPR_ATA_TX);
  77. out_be32(&bcom_eng->regs->IntPend, 1<<tsk->tasknum); /* Clear ints */
  78. return tsk;
  79. }
  80. EXPORT_SYMBOL_GPL(bcom_ata_init);
  81. void bcom_ata_rx_prepare(struct bcom_task *tsk)
  82. {
  83. struct bcom_ata_inc *inc;
  84. inc = (struct bcom_ata_inc *) bcom_task_inc(tsk->tasknum);
  85. inc->incr_bytes = -(s16)sizeof(u32);
  86. inc->incr_src = 0;
  87. inc->incr_dst = sizeof(u32);
  88. bcom_set_initiator(tsk->tasknum, BCOM_INITIATOR_ATA_RX);
  89. }
  90. EXPORT_SYMBOL_GPL(bcom_ata_rx_prepare);
  91. void bcom_ata_tx_prepare(struct bcom_task *tsk)
  92. {
  93. struct bcom_ata_inc *inc;
  94. inc = (struct bcom_ata_inc *) bcom_task_inc(tsk->tasknum);
  95. inc->incr_bytes = -(s16)sizeof(u32);
  96. inc->incr_src = sizeof(u32);
  97. inc->incr_dst = 0;
  98. bcom_set_initiator(tsk->tasknum, BCOM_INITIATOR_ATA_TX);
  99. }
  100. EXPORT_SYMBOL_GPL(bcom_ata_tx_prepare);
  101. void bcom_ata_reset_bd(struct bcom_task *tsk)
  102. {
  103. struct bcom_ata_var *var;
  104. /* Reset all BD */
  105. memset(tsk->bd, 0x00, tsk->num_bd * tsk->bd_size);
  106. tsk->index = 0;
  107. tsk->outdex = 0;
  108. var = (struct bcom_ata_var *) bcom_task_var(tsk->tasknum);
  109. var->bd_start = var->bd_base;
  110. }
  111. EXPORT_SYMBOL_GPL(bcom_ata_reset_bd);
  112. void bcom_ata_release(struct bcom_task *tsk)
  113. {
  114. /* Nothing special for the ATA tasks */
  115. bcom_task_free(tsk);
  116. }
  117. EXPORT_SYMBOL_GPL(bcom_ata_release);
  118. MODULE_DESCRIPTION("BestComm ATA task driver");
  119. MODULE_AUTHOR("John Rigby");
  120. MODULE_LICENSE("GPL v2");