Esempio n. 1
0
static int dmac_setup_xfer (dmac_dev_t * dmac_dev, paddr_t paddr, int len, int dir)
{
	int i, blknum = len/dmac_dev->blksz;

	dmac_dev->blknum = blknum;
	memset(dmac_dev->lli, 0, blknum * sizeof(at91sam9xx_dmac_bd_t));

	/* Resume Channel */
	dmac_dev->dmac->chdr = 1 << (dmac_dev->chid + 8);

	if (dir == DATA_READ) {		/* Block READ */
		/* Setup DMA direction */
		dmac_dev->dmac->lli[dmac_dev->chid].cfg &= ~(DMAC_DST_H2SEL_SW | DMAC_SRC_H2SEL_HW);
		dmac_dev->dmac->lli[dmac_dev->chid].cfg |= DMAC_DST_H2SEL_SW | DMAC_SRC_H2SEL_HW;

		/* Setup link list */
		for (i = 0; i < blknum; i++) {
			/* Set Source and address transfer size and modulo operation */
			dmac_dev->lli[i].ctrla = ((dmac_dev->blksz/4) & 0xffff)
				| SRC_WIDTH(2) | DST_WIDTH(2) | SCSIZE;
			dmac_dev->lli[i].ctrlb = DMAC_FC_PER2MEM | FLAG_SRC_INCREMENT
				| FLAG_DST_INCREMENT | SET_DST_DSCR;
			dmac_dev->lli[i].saddr = dmac_dev->io_addr;
			dmac_dev->lli[i].daddr = paddr + dmac_dev->blksz * i;

			if (i == blknum - 1)
				/* Set last lli descriptor to 0 to mark NULL */
				dmac_dev->lli[i].dscr = 0;
			else
				/* Set next lli descriptor */
				dmac_dev->lli[i].dscr = lli_mphy + (i + 1) * lli_size;
		}
	} else if (dir == DATA_WRITE) {	/* Block WRITE */
		/* Setup DMA direction */
		dmac_dev->dmac->lli[dmac_dev->chid].cfg &= ~(DMAC_DST_H2SEL_HW | DMAC_SRC_H2SEL_SW);
		dmac_dev->dmac->lli[dmac_dev->chid].cfg |= DMAC_DST_H2SEL_HW | DMAC_SRC_H2SEL_SW;

		for (i = 0; i < blknum; i++) {
			/* Set Source and address transfer size and modulo operation */
			dmac_dev->lli[i].ctrla = ((dmac_dev->blksz/4) & 0xffff)
				| SRC_WIDTH(2) | DST_WIDTH(2) | DCSIZE;
			dmac_dev->lli[i].ctrlb = DMAC_FC_MEM2PER | FLAG_SRC_INCREMENT
				| FLAG_DST_INCREMENT | SET_SRC_DSCR;
			dmac_dev->lli[i].saddr = paddr + dmac_dev->blksz * i;
			dmac_dev->lli[i].daddr = dmac_dev->io_addr;
			if (i == blknum - 1)
				/* Set last lli descriptor to 0 to mark NULL */
				dmac_dev->lli[i].dscr = 0;
			else
				/* Set next lli descriptor */
				dmac_dev->lli[i].dscr = lli_mphy + (i + 1) * lli_size;
		}
	} else {
		slogf (_SLOGC_SIM_MMC, _SLOG_ERROR, "MMC: DMA setup_xfer neither READ or WRITE\n");
		return -1;
	}

	return 0;
}
static POST_ERROR Post_update_condition(void)
{
    POST_ERROR error = POST_SUCCESS;

    unsigned int PreHozRatio, PreVerRatio;
    unsigned int MainHozShift, MainVerShift;

    POST_MSG((_T("[POST]++Post_update_condition()\n\r")));

    error = Post_get_prescaler_shiftvalue(&MainHozShift, g_PostConfig.SrcWidth, g_PostConfig.DstWidth);
    if (error == POST_SUCCESS)
    {
        PreHozRatio = (1<<MainHozShift);
        error = Post_get_prescaler_shiftvalue(&MainVerShift, g_PostConfig.SrcHeight, g_PostConfig.DstHeight);
        if (error == POST_SUCCESS)
        {
            PreVerRatio = (1<<MainVerShift);
            g_pPostReg->PreScale_Ratio = PRESCALE_V_RATIO(PreVerRatio) | PRESCALE_H_RATIO(PreHozRatio);
            g_pPostReg->PreScaleImgSize = PRESCALE_WIDTH(g_PostConfig.SrcWidth/PreHozRatio) | PRESCALE_HEIGHT(g_PostConfig.SrcHeight/PreVerRatio);
            g_pPostReg->SRCImgSize = SRC_WIDTH(g_PostConfig.SrcWidth) | SRC_HEIGHT(g_PostConfig.SrcHeight);
            g_pPostReg->MainScale_H_Ratio = MAINSCALE_H_RATIO((g_PostConfig.SrcWidth<<8)/(g_PostConfig.DstWidth<<MainHozShift));
            g_pPostReg->MainScale_V_Ratio = MAINSCALE_V_RATIO((g_PostConfig.SrcHeight<<8)/(g_PostConfig.DstHeight<<MainVerShift));
            g_pPostReg->DSTImgSize = DST_WIDTH(g_PostConfig.DstWidth) | DST_HEIGHT(g_PostConfig.DstHeight);
            g_pPostReg->PreScale_SHFactor = PRESCALE_SHFACTOR(10-(MainHozShift+MainVerShift));
        }
    }

    POST_MSG((_T("[POST]--Post_update_condition() : %d\n\r"), error));

    return error;
}
static TVSC_ERROR TVSC_update_condition(void)
{
	TVSC_ERROR error = TVSC_SUCCESS;

	unsigned int PreHozRatio, PreVerRatio;
	unsigned int MainHozShift, MainVerShift;

	TVSC_MSG((_T("[TVSC]++TVSC_update_condition()\n\r")));

	error = TVSC_get_prescaler_horizontal_value(&PreHozRatio, &MainHozShift);
	if (error == TVSC_SUCCESS)
	{
		error = TVSC_get_prescaler_vertical_value(&PreVerRatio, &MainVerShift);
		if (error == TVSC_SUCCESS)
		{
			g_pTVSCReg->PreScale_Ratio = PRESCALE_V_RATIO(PreVerRatio) | PRESCALE_H_RATIO(PreHozRatio);
			g_pTVSCReg->PreScaleImgSize = PRESCALE_WIDTH(g_TVSCConfig.SrcWidth/PreHozRatio) | PRESCALE_HEIGHT(g_TVSCConfig.SrcHeight/PreVerRatio);
			g_pTVSCReg->SRCImgSize = SRC_WIDTH(g_TVSCConfig.SrcWidth) | SRC_HEIGHT(g_TVSCConfig.SrcHeight);
			g_pTVSCReg->MainScale_H_Ratio = MAINSCALE_H_RATIO((g_TVSCConfig.SrcWidth<<8)/(g_TVSCConfig.DstWidth<<MainHozShift));
			g_pTVSCReg->MainScale_V_Ratio = MAINSCALE_V_RATIO((g_TVSCConfig.SrcHeight<<8)/(g_TVSCConfig.DstHeight<<MainVerShift));
			g_pTVSCReg->DSTImgSize = DST_WIDTH(g_TVSCConfig.DstWidth) | DST_HEIGHT(g_TVSCConfig.DstHeight);
			g_pTVSCReg->PreScale_SHFactor = PRESCALE_SHFACTOR(10-(MainHozShift+MainVerShift));
		}
	}

	TVSC_MSG((_T("[TVSC]--TVSC_update_condition() : %d\n\r"), error));

	return error;
}