home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / src / linux-headers-2.6.28-15 / arch / arm / plat-mxc / include / mach / sdma.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-09  |  13.8 KB  |  506 lines

  1.  
  2. /*
  3.  * Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
  4.  */
  5.  
  6. /*
  7.  * The code contained herein is licensed under the GNU General Public
  8.  * License. You may obtain a copy of the GNU General Public License
  9.  * Version 2 or later at the following locations:
  10.  *
  11.  * http://www.opensource.org/licenses/gpl-license.html
  12.  * http://www.gnu.org/copyleft/gpl.html
  13.  */
  14.  
  15. #ifndef __ASM_ARCH_MXC_SDMA_H__
  16. #define __ASM_ARCH_MXC_SDMA_H__
  17.  
  18. /*!
  19.  * @defgroup SDMA Smart Direct Memory Access (SDMA) Driver
  20.  */
  21.  
  22. /*!
  23.  * @file arch-mxc/sdma.h
  24.  *
  25.  * @brief This file contains the SDMA API declarations.
  26.  *
  27.  * SDMA is responsible on moving data between peripherals and memories (MCU, EMI and DSP).
  28.  *
  29.  * @ingroup SDMA
  30.  */
  31.  
  32. #include <linux/interrupt.h>
  33. #include <asm/dma.h>
  34. #include <stdarg.h>
  35.  
  36. #include <mach/hardware.h>
  37.  
  38. /*!
  39.  * This defines maximum DMA address
  40.  */
  41. #define MAX_DMA_ADDRESS 0xffffffff
  42.  
  43. /*!
  44.  * This defines maximum number of DMA channels
  45.  */
  46. #ifdef CONFIG_MXC_SDMA_API
  47. #define MAX_DMA_CHANNELS 32
  48. #define MAX_BD_NUMBER    16
  49. #define MXC_SDMA_DEFAULT_PRIORITY 1
  50. #define MXC_SDMA_MIN_PRIORITY 1
  51. #define MXC_SDMA_MAX_PRIORITY 7
  52. #else
  53. #define MAX_DMA_CHANNELS 0
  54. #endif
  55.  
  56. #define MXC_FIFO_MEM_DEST_FIXED   0x1
  57. #define MXC_FIFO_MEM_SRC_FIXED    0x2
  58. /*!
  59.  * This enumerates  transfer types
  60.  */
  61. typedef enum {
  62.     emi_2_per = 0,        /*!< EMI memory to peripheral */
  63.     emi_2_int,        /*!< EMI memory to internal RAM */
  64.     emi_2_emi,        /*!< EMI memory to EMI memory */
  65.     emi_2_dsp,        /*!< EMI memory to DSP memory */
  66.     per_2_int,        /*!< Peripheral to internal RAM */
  67.     per_2_emi,        /*!< Peripheral to internal EMI memory */
  68.     per_2_dsp,        /*!< Peripheral to DSP memory */
  69.     per_2_per,        /*!< Peripheral to Peripheral */
  70.     int_2_per,        /*!< Internal RAM to peripheral */
  71.     int_2_int,        /*!< Internal RAM to Internal RAM */
  72.     int_2_emi,        /*!< Internal RAM to EMI memory */
  73.     int_2_dsp,        /*!< Internal RAM to DSP memory */
  74.     dsp_2_per,        /*!< DSP memory to peripheral */
  75.     dsp_2_int,        /*!< DSP memory to internal RAM */
  76.     dsp_2_emi,        /*!< DSP memory to EMI memory */
  77.     dsp_2_dsp,        /*!< DSP memory to DSP memory */
  78.     emi_2_dsp_loop,        /*!< EMI memory to DSP memory loopback */
  79.     dsp_2_emi_loop,        /*!< DSP memory to EMI memory loopback */
  80.     dvfs_pll,        /*!< DVFS script with PLL change       */
  81.     dvfs_pdr        /*!< DVFS script without PLL change    */
  82. } sdma_transferT;
  83.  
  84. /*!
  85.  * This enumerates peripheral types
  86.  */
  87. typedef enum {
  88.     SSI,            /*!< MCU domain SSI */
  89.     SSI_SP,            /*!< Shared SSI */
  90.     MMC,            /*!< MMC */
  91.     SDHC,            /*!< SDHC */
  92.     UART,            /*!< MCU domain UART */
  93.     UART_SP,        /*!< Shared UART */
  94.     FIRI,            /*!< FIRI */
  95.     CSPI,            /*!< MCU domain CSPI */
  96.     CSPI_SP,        /*!< Shared CSPI */
  97.     SIM,            /*!< SIM */
  98.     ATA,            /*!< ATA */
  99.     CCM,            /*!< CCM */
  100.     EXT,            /*!< External peripheral */
  101.     MSHC,            /*!< Memory Stick Host Controller */
  102.     MSHC_SP,        /*!< Shared Memory Stick Host Controller */
  103.     DSP,            /*!< DSP */
  104.     MEMORY,            /*!< Memory */
  105.     FIFO_MEMORY,        /*!< FIFO type Memory */
  106.     SPDIF,            /*!< SPDIF */
  107.     IPU_MEMORY,        /*!< IPU Memory */
  108.     ASRC,            /*!< ASRC */
  109.     ESAI,            /*!< ESAI */
  110. } sdma_periphT;
  111.  
  112. #ifndef TRANSFER_32BIT
  113. /*!
  114.  * This defines SDMA access data size
  115.  */
  116. #define TRANSFER_32BIT      0x00
  117. #define TRANSFER_8BIT       0x01
  118. #define TRANSFER_16BIT      0x02
  119. #define TRANSFER_24BIT      0x03
  120.  
  121. #endif
  122.  
  123. /*!
  124.  * This defines maximum device name length passed during mxc_request_dma().
  125.  */
  126. #define MAX_DEVNAME_LENGTH 32
  127.  
  128. /*!
  129.  * This defines SDMA interrupt callback function prototype.
  130.  */
  131. typedef void (*dma_callback_t) (void *arg);
  132.  
  133. /*!
  134.  * Structure containing sdma channel parameters.
  135.  */
  136. typedef struct {
  137.     __u32 watermark_level;    /*!< Lower/upper threshold that
  138.                  *   triggers SDMA event
  139.                  */
  140.     __u32 per_address;    /*!< Peripheral source/destination
  141.                  *   physical address
  142.                  */
  143.     sdma_periphT peripheral_type;    /*!< Peripheral type */
  144.     sdma_transferT transfer_type;    /*!< Transfer type   */
  145.     int event_id;        /*!< Event number,
  146.                  *   needed by all channels
  147.                  *   that started by peripherals dma
  148.                  *   request (per_2_*,*_2_per)
  149.                  *   Not used for memory and DSP
  150.                  *   transfers.
  151.                  */
  152.     int event_id2;        /*!< Second event number,
  153.                  *   used in ATA scripts only.
  154.                  */
  155.     int bd_number;        /*!< Buffer descriptors number.
  156.                  *   If not set, single buffer
  157.                  *   descriptor will be used.
  158.                  */
  159.     dma_callback_t callback;    /*!   callback function            */
  160.     void *arg;        /*!   callback argument            */
  161.     unsigned long word_size:8;    /*!< SDMA data access word size    */
  162. } dma_channel_params;
  163.  
  164. /*!
  165.  * Structure containing sdma request  parameters.
  166.  */
  167. typedef struct {
  168.     /*!   physical source memory address        */
  169.     __u8 *sourceAddr;
  170.     /*!   physical destination memory address   */
  171.     __u8 *destAddr;
  172.     /*!   amount of data to transfer,
  173.      * updated during mxc_dma_get_config
  174.      */
  175.     __u16 count;
  176.     /*!< DONE bit of the buffer descriptor,
  177.      * updated during mxc_dma_get_config
  178.      * 0 - means the BD is done and closed by SDMA
  179.      * 1 - means the BD is still being processed by SDMA
  180.      */
  181.     int bd_done;
  182.     /*!< CONT bit of the buffer descriptor,
  183.      * set it if full multi-buffer descriptor mechanism
  184.      * required.
  185.      */
  186.     int bd_cont;
  187.     /*!< ERROR bit of the buffer descriptor,
  188.      * updated during mxc_dma_get_config.
  189.      * If it is set - there was an error during BD processing.
  190.      */
  191.     int bd_error;
  192. } dma_request_t;
  193.  
  194. /*!
  195.  * Structure containing sdma request  parameters.
  196.  */
  197. typedef struct {
  198.     /*! address of ap_2_ap script */
  199.     int mxc_sdma_ap_2_ap_addr;
  200.     /*! address of ap_2_bp script */
  201.     int mxc_sdma_ap_2_bp_addr;
  202.     /*! address of ap_2_ap_fixed script */
  203.     int mxc_sdma_ap_2_ap_fixed_addr;
  204.     /*! address of bp_2_ap script */
  205.     int mxc_sdma_bp_2_ap_addr;
  206.     /*! address of loopback_on_dsp_side script */
  207.     int mxc_sdma_loopback_on_dsp_side_addr;
  208.     /*! address of mcu_interrupt_only script */
  209.     int mxc_sdma_mcu_interrupt_only_addr;
  210.  
  211.     /*! address of firi_2_per script */
  212.     int mxc_sdma_firi_2_per_addr;
  213.     /*! address of firi_2_mcu script */
  214.     int mxc_sdma_firi_2_mcu_addr;
  215.     /*! address of per_2_firi script */
  216.     int mxc_sdma_per_2_firi_addr;
  217.     /*! address of mcu_2_firi script */
  218.     int mxc_sdma_mcu_2_firi_addr;
  219.  
  220.     /*! address of uart_2_per script */
  221.     int mxc_sdma_uart_2_per_addr;
  222.     /*! address of uart_2_mcu script */
  223.     int mxc_sdma_uart_2_mcu_addr;
  224.     /*! address of per_2_app script */
  225.     int mxc_sdma_per_2_app_addr;
  226.     /*! address of mcu_2_app script */
  227.     int mxc_sdma_mcu_2_app_addr;
  228.     /*! address of per_2_per script */
  229.     int mxc_sdma_per_2_per_addr;
  230.  
  231.     /*! address of uartsh_2_per script */
  232.     int mxc_sdma_uartsh_2_per_addr;
  233.     /*! address of uartsh_2_mcu script */
  234.     int mxc_sdma_uartsh_2_mcu_addr;
  235.     /*! address of per_2_shp script */
  236.     int mxc_sdma_per_2_shp_addr;
  237.     /*! address of mcu_2_shp script */
  238.     int mxc_sdma_mcu_2_shp_addr;
  239.  
  240.     /*! address of ata_2_mcu script */
  241.     int mxc_sdma_ata_2_mcu_addr;
  242.     /*! address of mcu_2_ata script */
  243.     int mxc_sdma_mcu_2_ata_addr;
  244.  
  245.     /*! address of app_2_per script */
  246.     int mxc_sdma_app_2_per_addr;
  247.     /*! address of app_2_mcu script */
  248.     int mxc_sdma_app_2_mcu_addr;
  249.     /*! address of shp_2_per script */
  250.     int mxc_sdma_shp_2_per_addr;
  251.     /*! address of shp_2_mcu script */
  252.     int mxc_sdma_shp_2_mcu_addr;
  253.  
  254.     /*! address of mshc_2_mcu script */
  255.     int mxc_sdma_mshc_2_mcu_addr;
  256.     /*! address of mcu_2_mshc script */
  257.     int mxc_sdma_mcu_2_mshc_addr;
  258.  
  259.     /*! address of spdif_2_mcu script */
  260.     int mxc_sdma_spdif_2_mcu_addr;
  261.     /*! address of mcu_2_spdif script */
  262.     int mxc_sdma_mcu_2_spdif_addr;
  263.  
  264.     /*! address of asrc_2_mcu script */
  265.     int mxc_sdma_asrc_2_mcu_addr;
  266.  
  267.     /*! address of ext_mem_2_ipu script */
  268.     int mxc_sdma_ext_mem_2_ipu_addr;
  269.  
  270.     /*! address of descrambler script */
  271.     int mxc_sdma_descrambler_addr;
  272.  
  273.     /*! address of dptc_dvfs script */
  274.     int mxc_sdma_dptc_dvfs_addr;
  275.  
  276.     int mxc_sdma_utra_addr;
  277.  
  278.     /*! address where ram code starts */
  279.     int mxc_sdma_ram_code_start_addr;
  280.     /*! size of the ram code */
  281.     int mxc_sdma_ram_code_size;
  282.     /*! RAM image address */
  283.     unsigned short *mxc_sdma_start_addr;
  284. } sdma_script_start_addrs;
  285.  
  286. /*! Structure to store the initialized dma_channel parameters */
  287. typedef struct mxc_sdma_channel_params {
  288.     /*! Channel params */
  289.     dma_channel_params chnl_params;
  290.     /*! Channel type (static channel number or dynamic channel) */
  291.     unsigned int channel_num;
  292.     /*! Channel priority [0x1(lowest) - 0x7(highest)] */
  293.     unsigned int chnl_priority;
  294. } mxc_sdma_channel_params_t;
  295.  
  296. /*! Private SDMA data structure */
  297. typedef struct mxc_dma_channel_private {
  298.     /*! ID of the buffer that was processed */
  299.     unsigned int buf_tail;
  300.     /*! Tasklet for the channel */
  301.     struct tasklet_struct chnl_tasklet;
  302.     /*! Flag indicates if interrupt is required after every BD transfer */
  303.     int intr_after_every_bd;
  304. } mxc_dma_channel_private_t;
  305.  
  306. /*!
  307.  * Setup channel according to parameters.
  308.  * Must be called once after mxc_request_dma()
  309.  *
  310.  * @param   channel           channel number
  311.  * @param   p                 channel parameters pointer
  312.  * @return  0 on success, error code on fail
  313.  */
  314. int mxc_dma_setup_channel(int channel, dma_channel_params * p);
  315.  
  316. /*!
  317.  * Setup the channel priority. This can be used to change the default priority
  318.  * for the channel.
  319.  *
  320.  * @param   channel           channel number
  321.  * @param   priority          priority to be set for the channel
  322.  *
  323.  * @return  0 on success, error code on failure
  324.  */
  325. int mxc_dma_set_channel_priority(unsigned int channel, unsigned int priority);
  326.  
  327. /*!
  328.  * Allocates dma channel.
  329.  * If channel's value is 0, then the function allocates a free channel
  330.  * dynamically and sets its value to channel.
  331.  * Else allocates requested channel if it is free.
  332.  * If the channel is busy or no free channels (in dynamic allocation) -EBUSY returned.
  333.  *
  334.  * @param   channel           pointer to channel number
  335.  * @param   devicename        device name
  336.  * @return  0 on success, error code on fail
  337.  */
  338. int mxc_request_dma(int *channel, const char *devicename);
  339.  
  340. /*!
  341.  * Configures request parameters. Can be called multiple times after
  342.  * mxc_request_dma() and mxc_dma_setup_channel().
  343.  *
  344.  *
  345.  * @param   channel           channel number
  346.  * @param   p                 request parameters pointer
  347.  * @param   bd_index          index of buffer descriptor to set
  348.  * @return  0 on success, error code on fail
  349.  */
  350. /* int mxc_dma_set_config(int channel, dma_request_t *p, int bd_index); */
  351. int mxc_dma_set_config(int channel, dma_request_t * p, int bd_index);
  352.  
  353. /*!
  354.  * Returns request parameters.
  355.  *
  356.  * @param   channel           channel number
  357.  * @param   p                 request parameters pointer
  358.  * @param   bd_index          index of buffer descriptor to get
  359.  * @return  0 on success, error code on fail
  360.  */
  361. /* int mxc_dma_get_config(int channel, dma_request_t *p, int bd_index); */
  362. int mxc_dma_get_config(int channel, dma_request_t * p, int bd_index);
  363.  
  364. /*!
  365.  * This function is used by MXC IPC's write_ex2. It passes the a pointer to the
  366.  * data control structure to iapi_write_ipcv2()
  367.  *
  368.  * @param channel  SDMA channel number
  369.  * @param ctrl_ptr Data Control structure pointer
  370.  */
  371. int mxc_sdma_write_ipcv2(int channel, void *ctrl_ptr);
  372.  
  373. /*!
  374.  * This function is used by MXC IPC's read_ex2. It passes the a pointer to the
  375.  * data control structure to iapi_read_ipcv2()
  376.  *
  377.  * @param channel   SDMA channel number
  378.  * @param ctrl_ptr  Data Control structure pointer
  379.  */
  380. int mxc_sdma_read_ipcv2(int channel, void *ctrl_ptr);
  381.  
  382. /*!
  383.  * Starts dma channel.
  384.  *
  385.  * @param   channel           channel number
  386.  */
  387. int mxc_dma_start(int channel);
  388.  
  389. /*!
  390.  * Stops dma channel.
  391.  *
  392.  * @param   channel           channel number
  393.  */
  394. int mxc_dma_stop(int channel);
  395.  
  396. /*!
  397.  * Frees dma channel.
  398.  *
  399.  * @param   channel           channel number
  400.  */
  401. void mxc_free_dma(int channel);
  402.  
  403. /*!
  404.  * Sets callback function. Used with standard dma api
  405.  *  for supporting interrupts
  406.  *
  407.  * @param   channel           channel number
  408.  * @param   callback          callback function pointer
  409.  * @param   arg               argument for callback function
  410.  */
  411. void mxc_dma_set_callback(int channel, dma_callback_t callback, void *arg);
  412.  
  413. /*!
  414.  * Allocates uncachable buffer. Uses hash table.
  415.  *
  416.  * @param   size    size of allocated buffer
  417.  * @return  pointer to buffer
  418.  */
  419. void *sdma_malloc(size_t size);
  420.  
  421. #ifdef CONFIG_SDMA_IRAM
  422. /*!
  423.  * Allocates uncachable buffer from IRAM..
  424.  *
  425.  * @param   size    size of allocated buffer
  426.  * @return  pointer to buffer
  427.  */
  428. void *sdma_iram_malloc(size_t size);
  429. #endif                /*CONFIG_SDMA_IRAM */
  430.  
  431. /*!
  432.  * Frees uncachable buffer. Uses hash table.
  433.  */
  434. void sdma_free(void *buf);
  435.  
  436. /*!
  437.  * Converts virtual to physical address. Uses hash table.
  438.  *
  439.  * @param   buf  virtual address pointer
  440.  * @return  physical address value
  441.  */
  442. unsigned long sdma_virt_to_phys(void *buf);
  443.  
  444. /*!
  445.  * Converts physical to virtual address. Uses hash table.
  446.  *
  447.  * @param   buf  physical address value
  448.  * @return  virtual address pointer
  449.  */
  450. void *sdma_phys_to_virt(unsigned long buf);
  451.  
  452. /*!
  453.  * Configures the BD_INTR bit on a buffer descriptor parameters.
  454.  *
  455.  *
  456.  * @param   channel           channel number
  457.  * @param   bd_index          index of buffer descriptor to set
  458.  * @param   bd_intr           flag to set or clear the BD_INTR bit
  459.  */
  460. void mxc_dma_set_bd_intr(int channel, int bd_index, int bd_intr);
  461.  
  462. /*!
  463.  * Gets the BD_INTR bit on a buffer descriptor.
  464.  *
  465.  *
  466.  * @param   channel           channel number
  467.  * @param   bd_index          index of buffer descriptor to set
  468.  *
  469.  * @return returns the BD_INTR bit status
  470.  */
  471. int mxc_dma_get_bd_intr(int channel, int bd_index);
  472.  
  473. /*!
  474.  * Stop the current transfer
  475.  *
  476.  * @param   channel           channel number
  477.  * @param   buffer_number     number of buffers (beginning with 0),
  478.  *                            whose done bits should be reset to 0
  479.  */
  480. int mxc_dma_reset(int channel, int buffer_number);
  481.  
  482. /*!
  483.  * This functions Returns the SDMA paramaters associated for a module
  484.  *
  485.  * @param channel_id the ID of the module requesting DMA
  486.  * @return returns the sdma parameters structure for the device
  487.  */
  488. mxc_sdma_channel_params_t *mxc_sdma_get_channel_params(mxc_dma_device_t
  489.                                channel_id);
  490.  
  491. /*!
  492.  * This functions marks the SDMA channels that are statically allocated
  493.  *
  494.  * @param chnl the channel array used to store channel information
  495.  */
  496. void mxc_get_static_channels(mxc_dma_channel_t * chnl);
  497.  
  498. /*!
  499.  * Initializes SDMA driver
  500.  */
  501. int __init sdma_init(void);
  502.  
  503. #define DEFAULT_ERR     1
  504.  
  505. #endif
  506.