dsk6x11_edma_ad535.c
上传用户:dahaojd
上传日期:2008-01-29
资源大小:14357k
文件大小:11k
- /*
- * Copyright 2003 by Texas Instruments Incorporated.
- * All rights reserved. Property of Texas Instruments Incorporated.
- * Restricted rights to use, duplicate or disclose this code are
- * granted through contract.
- *
- */
- /* "@(#) DDK 1.11.00.00 11-04-03 (ddk-b13)" */
- /*
- * ======== dsk6x11_edma_ad535.c ========
- *
- * Driver for the ad535 codec on the TMS320C6x11 DSK. Requires the
- * generic TMS320C6x1x McBSP driver.
- */
- #include <std.h>
- #include <iom.h>
- #include <csl.h>
- #include <csl_mcbsp.h>
- #include <csl_edma.h>
- #include <dsk6x11_edma_ad535.h>
- #include <c6x1x_edma_mcbsp.h>
- #define AD535RESET 0x0080 /* codec software reset */
- /*
- * Since the AD535 codec is master on the DSK6X11 we don't want to enable
- * the frame sync or sample rate generators since we don't use them (the
- * codec is master means that the mcbsp is externally clocked).
- */
- #define GENERICDEVPARAMS {
- C6X1X_EDMA_MCBSP_VERSION_1,/* Version Number.*/
- FALSE, /* True if buffers are in cacheable memory (set in mdBindDev) */
- FALSE, /* Driver should not enable the McBSP sample rate generator */
- FALSE, /* Driver should not enable the McBSP frame sync generator */
- 0, /* IRQ id to use for the EDMA (set in mdBindDev) */
- NULL, /* McBSP configuration for the codec (set in mdBindDev) */
- DSK6X11_EDMA_AD535_INTR_MASK_DEFAULT /* Interrupt mask for EDMA ISR */
- }
- /* Structure containing port specific variables */
- typedef struct {
- Ptr c6x1xPortObj;
- Int edmaPriority;
- } PortObj, *PortHandle;
- /* Declare the port structure */
- /* Only Mcbsp 0 is used */
- static PortObj port;
- DSK6X11_EDMA_AD535_DevParams DSK6X11_EDMA_AD535_DEVPARAMS =
- DSK6X11_EDMA_AD535_DEFAULT_DEVPARAMS;
- /* Local function prototypes */
- static Void codecControlWrite(MCBSP_Handle hMcbsp, Uns reg, Uns dataVal);
- static Uns spRead(MCBSP_Handle hMcbsp);
- static Void spWrite(MCBSP_Handle hMcbsp, Uns dataVal);
- /*
- * Forward declaration of the IOM interface functions. They are only
- * exposed via the IOM function table to avoid namespace pollution.
- */
- static Int mdBindDev(Ptr *devp, Int devid, Ptr devParams);
- static Int mdCreateChan(Ptr *chanp, Ptr devp, String name, Int mode,
- Ptr chanParams, IOM_TiomCallback cbFxn, Ptr cbArg);
- static Int mdSubmitChan(Ptr chanp, IOM_Packet *packet);
- /*
- * The codec driver function table. Notice how we copy most functions
- * from the generic c6x1x edma mcbsp driver.
- */
- IOM_Fxns DSK6X11_EDMA_AD535_FXNS = {
- &mdBindDev,
- NULL,
- NULL,
- &mdCreateChan,
- NULL,
- &mdSubmitChan
- };
- /*
- * ======== mdBindDev ========
- * This function allocates and configures the ad535 codec.
- */
- static Int mdBindDev(Ptr *devp, Int devid, Ptr devParams)
- {
- Int i;
- MCBSP_Handle hMcbsp;
- Int result;
- DSK6X11_EDMA_AD535_DevParams *params =
- (DSK6X11_EDMA_AD535_DevParams *) devParams;
- C6X1X_EDMA_MCBSP_DevParams genericParams = GENERICDEVPARAMS;
- MCBSP_Config mcbspCfg = {
- MCBSP_FMKS(SPCR, FREE, NO) |
- MCBSP_FMKS(SPCR, SOFT, NO) |
- MCBSP_FMKS(SPCR, FRST, YES) |
- MCBSP_FMKS(SPCR, GRST, YES) |
- MCBSP_FMKS(SPCR, XINTM, XRDY) |
- MCBSP_FMKS(SPCR, XSYNCERR, NO) |
- MCBSP_FMKS(SPCR, XRST, YES) |
- MCBSP_FMKS(SPCR, DLB, OFF) |
- MCBSP_FMKS(SPCR, RJUST, RZF) |
- MCBSP_FMKS(SPCR, CLKSTP, DISABLE) |
- MCBSP_FMKS(SPCR, DXENA, OFF) |
- MCBSP_FMKS(SPCR, RINTM, RRDY) |
- MCBSP_FMKS(SPCR, RSYNCERR, NO) |
- MCBSP_FMKS(SPCR, RRST, YES),
- MCBSP_FMKS(RCR, RPHASE, SINGLE) |
- MCBSP_FMKS(RCR, RFRLEN2, OF(0)) |
- MCBSP_FMKS(RCR, RWDLEN2, 8BIT) |
- MCBSP_FMKS(RCR, RCOMPAND, MSB) |
- MCBSP_FMKS(RCR, RFIG, YES) |
- MCBSP_FMKS(RCR, RDATDLY, 1BIT) |
- MCBSP_FMKS(RCR, RFRLEN1, OF(0)) |
- MCBSP_FMKS(RCR, RWDLEN1, 16BIT) |
- MCBSP_FMKS(RCR, RWDREVRS, DISABLE),
- MCBSP_FMKS(XCR, XPHASE, SINGLE) |
- MCBSP_FMKS(XCR, XFRLEN2, OF(0)) |
- MCBSP_FMKS(XCR, XWDLEN2, 8BIT) |
- MCBSP_FMKS(XCR, XCOMPAND, MSB) |
- MCBSP_FMKS(XCR, XFIG, YES) |
- MCBSP_FMKS(XCR, XDATDLY, 1BIT) |
- MCBSP_FMKS(XCR, XFRLEN1, OF(0)) |
- MCBSP_FMKS(XCR, XWDLEN1, 16BIT) |
- MCBSP_FMKS(XCR, XWDREVRS, DISABLE),
- MCBSP_SRGR_DEFAULT, /* Default SRGR value */
- MCBSP_MCR_DEFAULT, /* Default MCR value */
- MCBSP_RCER_DEFAULT, /* Default RCER value */
- MCBSP_XCER_DEFAULT, /* Default XCER value */
- MCBSP_PCR_DEFAULT /* Default PCR value */
- };
-
- /* If no device parameters are passed, use the defaults. */
- if (params == NULL) {
- params = &DSK6X11_EDMA_AD535_DEVPARAMS;
- }
- /* Check if the version is supported by the driver. */
- if(params->versionId != DSK6X11_EDMA_AD535_VERSION_1){
- /* Unsupported version */
- return(IOM_EBADARGS);
- }
- /* Open McBSP port 0 and reset it. */
- hMcbsp = MCBSP_open(MCBSP_DEV0, MCBSP_OPEN_RESET);
- /*
- * We can't abort or send an error code back from setup. Just send an
- * error message to notify if an error occurs.
- */
- if (hMcbsp == INV) {
- return (IOM_EALLOC);
- }
- /* Configure McBSP port 0 using the above specified parameters. */
- MCBSP_config(hMcbsp, &mcbspCfg);
- /*
- * Temporarily enable the McBSP transmitter and receiver so
- * that we can set up the codec.
- */
- MCBSP_start(hMcbsp, MCBSP_RCV_START | MCBSP_XMIT_START,
- MCBSP_SRGR_DEFAULT_DELAY);
- /* Software reset the codec */
- codecControlWrite(hMcbsp, 3, AD535RESET);
- /* Configure the codec using the McBSP */
- for (i=0; i < DSK6X11_EDMA_AD535_NUMREGS; i++) {
- codecControlWrite(hMcbsp, i, params->reg[i]);
- }
- /* Close the McBSP so that the generic driver can claim it */
- MCBSP_close(hMcbsp);
- /* Set the IRQ id to use for EDMA (default is 8) */
- genericParams.irqId = params->irqId;
-
- /* Set the interrupt mask to be used for EDMA ISR */
- genericParams.intrMask = params->intrMask;
- genericParams.cacheCalls = params->cacheCalls;
- genericParams.mcbspCfgPtr = &mcbspCfg;
- /* Call the generic mdBindDev to claim mcbsp port 0 */
- result = (C6X1X_EDMA_MCBSP_FXNS.mdBindDev)(&port.c6x1xPortObj, 0,
- &genericParams);
- /* Store the edma priority in PortObj */
- port.edmaPriority = params->edmaPriority;
- *devp = &port;
- return (result);
- }
- /*
- * ======== mdCreateChan ========
- * This function creates and configures a device channel.
- */
- static Int mdCreateChan(Ptr *chanp, Ptr devp, String name, Int mode,
- Ptr chanParams, IOM_TiomCallback cbFxn, Ptr cbArg)
- {
- Int result;
- C6X1X_EDMA_MCBSP_ChanParams genericParams;
- PortHandle localPort = (PortHandle) devp;
- EDMA_Config edmaCfg = {
- EDMA_FMKS(OPT, ESIZE, 16BIT) |
- EDMA_FMKS(OPT, 2DS, NO) |
- EDMA_FMKS(OPT, SUM, NONE) |
- EDMA_FMKS(OPT, 2DD, NO) |
- EDMA_FMKS(OPT, DUM, NONE) |
- EDMA_FMKS(OPT, TCINT, YES) |
- EDMA_FMK (OPT, TCC, NULL) |
- EDMA_FMKS(OPT, LINK, YES) |
- EDMA_FMKS(OPT, FS, NO),
- EDMA_FMK (SRC, SRC, NULL),
- EDMA_FMK (CNT, FRMCNT, NULL) |
- EDMA_FMK (CNT, ELECNT, NULL),
- EDMA_FMK(DST, DST, NULL),
- EDMA_FMKS(IDX, FRMIDX, DEFAULT) |
- EDMA_FMKS(IDX, ELEIDX, DEFAULT),
- EDMA_FMK (RLD, ELERLD, NULL) |
- EDMA_FMK (RLD, LINK, NULL)
- };
-
- if (mode == IOM_INPUT) {
- edmaCfg.opt |= EDMA_FMK(OPT, DUM, EDMA_OPT_DUM_INC);
- }
- else {
- edmaCfg.opt |= EDMA_FMK(OPT, SUM, EDMA_OPT_SUM_INC);
- }
-
- /* set the edma transfer priority */
- edmaCfg.opt |= EDMA_FMK(OPT, PRI, localPort->edmaPriority);
- /*
- * This codec is a mono codec, and therefore only uses 1 McBSP TDM
- * channel.
- */
- genericParams.tdmChans = 1;
- genericParams.edmaCfgPtr = &edmaCfg;
- result = (C6X1X_EDMA_MCBSP_FXNS.mdCreateChan)(chanp,
- localPort->c6x1xPortObj,name, mode,&genericParams,
- cbFxn, cbArg);
- return (result);
- }
- static Int mdSubmitChan(Ptr chanp, IOM_Packet *packet)
- {
- Int i;
- Int result;
- MdUns *localBuf;
-
- if (packet->cmd == IOM_WRITE) {
- /* Mask off the LSB */
- localBuf = packet->addr;
- for (i = 0; i < (packet->size / sizeof(MdUns)); i++) {
- localBuf[i] = localBuf[i] & 0xFFFE;
- }
- }
-
- result = (C6X1X_EDMA_MCBSP_FXNS.mdSubmitChan)(chanp, packet);
- return (result);
- }
- /*
- * ======== codecControlWrite ========
- */
- static Void codecControlWrite(MCBSP_Handle hMcbsp, Uns reg, Uns data)
- {
- Uns temp;
-
- temp = ((reg & 0x001F) << 8) | (data & 0x00ff);
- spWrite(hMcbsp, 0);
- spRead (hMcbsp);
- spWrite(hMcbsp, 1);
- spRead (hMcbsp);
- spWrite(hMcbsp, temp);
- spRead (hMcbsp);
- spWrite(hMcbsp, 0);
- spRead (hMcbsp);
- }
- /*
- * ======== spWrite ========
- * WARNING! Unbounded while loop!
- * spWrite() should only be called during init time.
- */
- static Void spWrite(MCBSP_Handle hMcbsp, Uns dataVal)
- {
- while(!(MCBSP_xrdy(hMcbsp))) {
- /* wait for TX ready */
- }
- MCBSP_write(hMcbsp, dataVal);
- }
- /*
- * ======== spRead ========
- * WARNING! Unbounded while loop!
- * spRead() should only be called during init time.
- */
- static Uns spRead(MCBSP_Handle hMcbsp)
- {
- while(!(MCBSP_rrdy(hMcbsp))) {
- /* wait for RX ready */
- }
- return MCBSP_read(hMcbsp);
- }
- /*
- * ======== DSK6X11_EDMA_AD535_init ========
- * This function initializes the driver's structures.
- */
- Void DSK6X11_EDMA_AD535_init()
- {
- /* Pass some IOM fxns straight to the generic driver */
- DSK6X11_EDMA_AD535_FXNS.mdControlChan =
- C6X1X_EDMA_MCBSP_FXNS.mdControlChan;
- DSK6X11_EDMA_AD535_FXNS.mdDeleteChan = C6X1X_EDMA_MCBSP_FXNS.mdDeleteChan;
- DSK6X11_EDMA_AD535_FXNS.mdUnBindDev = C6X1X_EDMA_MCBSP_FXNS.mdUnBindDev;
- C6X1X_EDMA_MCBSP_init();
- }