dsk6416_edma_aic23.c
上传用户:dahaojd
上传日期:2008-01-29
资源大小:14357k
文件大小:9k
- /*
- * 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)" */
- /*
- * ======== dsk6416_edma_aic23.c ========
- *
- * Driver for the aic23 codec on the TMS320C6416 DSK. Requires the
- * generic TMS320C6x1x McBSP driver.
- */
- #include <std.h>
- #include <iom.h>
- #include <csl.h>
- #include <csl_edma.h>
- #include <csl_mcbsp.h>
- #include <dsk6416_edma_aic23.h>
- #include <c6x1x_edma_mcbsp.h>
- #define GENERICDEVPARAMS {
- C6X1X_EDMA_MCBSP_VERSION_1, /* Version number of mcbsp driver */
- 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) */
- DSK6416_EDMA_AIC23_INTR_MASK_DEFAULT /* Interrupt mask */
- }
- /* Structure containing port specific variables */
- typedef struct {
- Ptr c6x1xPortObj;
- Int edmaPriority;
- } PortObj, *PortHandle;
- /* Declare the port structures */
- /* Only Mcbsp 2 is used */
- static PortObj port;
- DSK6416_EDMA_AIC23_DevParams DSK6416_EDMA_AIC23_DEVPARAMS =
- DSK6416_EDMA_AIC23_DEVPARAMS_DEFAULT;
- /*
- * 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);
- /*
- * The codec driver function table. Notice how we copy most functions
- * from the generic c6x1x edma mcbsp driver.
- */
- IOM_Fxns DSK6416_EDMA_AIC23_FXNS = {
- &mdBindDev,
- NULL,
- NULL,
- &mdCreateChan,
- NULL,
- NULL
- };
- static MCBSP_Config mcbspCfg2 = {
- 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, DEFAULT) |
- MCBSP_FMKS(RCR, RWDLEN2, DEFAULT) |
- MCBSP_FMKS(RCR, RCOMPAND, MSB) |
- MCBSP_FMKS(RCR, RFIG, NO) |
- MCBSP_FMKS(RCR, RDATDLY, 0BIT) |
- MCBSP_FMKS(RCR, RFRLEN1, OF(1)) |
- MCBSP_FMKS(RCR, RWDLEN1, 16BIT) |
- MCBSP_FMKS(RCR, RWDREVRS, DISABLE),
- MCBSP_FMKS(XCR, XPHASE, SINGLE) |
- MCBSP_FMKS(XCR, XFRLEN2, DEFAULT) |
- MCBSP_FMKS(XCR, XWDLEN2, DEFAULT) |
- MCBSP_FMKS(XCR, XCOMPAND, MSB) |
- MCBSP_FMKS(XCR, XFIG, NO) |
- MCBSP_FMKS(XCR, XDATDLY, 0BIT) |
- MCBSP_FMKS(XCR, XFRLEN1, OF(1)) |
- MCBSP_FMKS(XCR, XWDLEN1, 16BIT) |
- MCBSP_FMKS(XCR, XWDREVRS, DISABLE),
-
- MCBSP_FMKS(SRGR, GSYNC, DEFAULT) |
- MCBSP_FMKS(SRGR, CLKSP, DEFAULT) |
- MCBSP_FMKS(SRGR, CLKSM, DEFAULT) |
- MCBSP_FMKS(SRGR, FSGM, DEFAULT) |
- MCBSP_FMKS(SRGR, FPER, DEFAULT) |
- MCBSP_FMKS(SRGR, FWID, DEFAULT) |
- MCBSP_FMKS(SRGR, CLKGDV, DEFAULT),
- MCBSP_MCR_DEFAULT,
- MCBSP_RCERE0_DEFAULT,
- MCBSP_RCERE1_DEFAULT,
- MCBSP_RCERE2_DEFAULT,
- MCBSP_RCERE3_DEFAULT,
- MCBSP_XCERE0_DEFAULT,
- MCBSP_XCERE1_DEFAULT,
- MCBSP_XCERE2_DEFAULT,
- MCBSP_XCERE3_DEFAULT,
- MCBSP_FMKS(PCR, XIOEN, SP) |
- MCBSP_FMKS(PCR, RIOEN, SP) |
- MCBSP_FMKS(PCR, FSXM, EXTERNAL) |
- MCBSP_FMKS(PCR, FSRM, EXTERNAL) |
- MCBSP_FMKS(PCR, CLKXM, INPUT) |
- MCBSP_FMKS(PCR, CLKRM, INPUT) |
- MCBSP_FMKS(PCR, CLKSSTAT, DEFAULT) |
- MCBSP_FMKS(PCR, DXSTAT, DEFAULT) |
- MCBSP_FMKS(PCR, FSXP, ACTIVEHIGH) |
- MCBSP_FMKS(PCR, FSRP, ACTIVEHIGH) |
- MCBSP_FMKS(PCR, CLKXP, FALLING) |
- MCBSP_FMKS(PCR, CLKRP, RISING)
- };
- /*
- * ======== mdBindDev ========
- * This function allocates and configures the aic23 codec.
- */
- static Int mdBindDev(Ptr *devp, Int devid, Ptr devParams)
- {
- Int result;
- DSK6416_EDMA_AIC23_DevParams *params =
- (DSK6416_EDMA_AIC23_DevParams *) devParams;
- C6X1X_EDMA_MCBSP_DevParams genericParams = GENERICDEVPARAMS;
- /* If no device parameters are passed, use the defaults. */
- if (params == NULL) {
- params = &DSK6416_EDMA_AIC23_DEVPARAMS;
- }
- /* Check if the version is supported by the driver */
- if (params->versionId != DSK6416_EDMA_AIC23_VERSION_1) {
- /* Unsupported version */
- return(IOM_EBADIO);
- }
- /* Set codec parameters (this will also initialize the codec) */
- if (!AIC23_setParams(&(params->aic23)))
- return IOM_EALLOC;
- /* Set the IRQ id to use for EDMA (default is 8) */
- genericParams.irqId = params->irqId;
- genericParams.cacheCalls = params->cacheCalls;
- genericParams.mcbspCfgPtr = &mcbspCfg2;
- genericParams.intrMask = params->intrMask;
- /* Call the generic mdBindDev to claim mcbsp port 2 */
- result = (C6X1X_EDMA_MCBSP_FXNS.mdBindDev)(&port.c6x1xPortObj,
- MCBSP_PORT2, &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, TCCM, DEFAULT) |
- EDMA_FMKS(OPT, ATCINT, NO) |
- EDMA_FMKS(OPT, ATCC, DEFAULT) |
- EDMA_FMKS(OPT, PDTS, DEFAULT) |
- EDMA_FMKS(OPT, PDTD, DEFAULT) |
- 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);
- /* Configure parameters */
- genericParams.tdmChans = DSK6416_EDMA_AIC23_TDMCHANNELS;
- genericParams.edmaCfgPtr = &edmaCfg;
- result = (C6X1X_EDMA_MCBSP_FXNS.mdCreateChan)(chanp,
- localPort->c6x1xPortObj, name, mode,
- &genericParams, cbFxn, cbArg);
- return (result);
- }
- /*
- * ======== DSK6416_EDMA_AIC23_init ========
- * This function initializes the driver's structures.
- */
- Void DSK6416_EDMA_AIC23_init()
- {
- /* Pass some IOM fxns straight to the generic driver */
- DSK6416_EDMA_AIC23_FXNS.mdControlChan =
- C6X1X_EDMA_MCBSP_FXNS.mdControlChan;
- DSK6416_EDMA_AIC23_FXNS.mdDeleteChan =
- C6X1X_EDMA_MCBSP_FXNS.mdDeleteChan;
- DSK6416_EDMA_AIC23_FXNS.mdSubmitChan =
- C6X1X_EDMA_MCBSP_FXNS.mdSubmitChan;
- DSK6416_EDMA_AIC23_FXNS.mdUnBindDev =
- C6X1X_EDMA_MCBSP_FXNS.mdUnBindDev;
- C6X1X_EDMA_MCBSP_init();
- }