ÆÄÀϸí : tas2559-core.c °ü·Ã ¼Ò½º ºÎºÐ int tas2559_set_program(struct tas2559_priv *pTAS2559, unsigned int nProgram, int nConfig) { struct TProgram *pProgram; struct TConfiguration *pConfiguration; unsigned int nConfiguration = 0; unsigned int nSampleRate = 0; bool bFound = false; int nResult = 0; if ((!pTAS2559->mpFirmware->mpPrograms) || (!pTAS2559->mpFirmware->mpConfigurations)) { dev_err(pTAS2559->dev, "Firmware not loaded\n"); nResult = 0; goto end; } if (nProgram >= pTAS2559->mpFirmware->mnPrograms) { dev_err(pTAS2559->dev, "TAS2559: Program %d doesn't exist\n", nProgram); nResult = 0; goto end; } if (nConfig < 0) { nSampleRate = pTAS2559->mnCurrentSampleRate; while (!bFound && (nConfiguration < pTAS2559->mpFirmware->mnConfigurations)) { if (pTAS2559->mpFirmware->mpConfigurations[nConfiguration].mnProgram == nProgram) { if (nSampleRate == 0) { bFound = true; dev_info(pTAS2559->dev, "find default configuration %d\n", nConfiguration); } else if (nSampleRate == pTAS2559->mpFirmware->mpConfigurations[nConfiguration].mnSamplingRate) { bFound = true; dev_info(pTAS2559->dev, "find matching configuration %d\n", nConfiguration); } else { nConfiguration++; } } else { nConfiguration++; } } if (!bFound) { dev_err(pTAS2559->dev, "Program %d, no valid configuration found for sample rate %d, ignore\n", nProgram, nSampleRate); nResult = 0; goto end; } } else { if (pTAS2559->mpFirmware->mpConfigurations[nConfig].mnProgram != nProgram) { dev_err(pTAS2559->dev, "%s, configuration program doesn't match\n", __func__); nResult = 0; goto end; } nConfiguration = nConfig; } pProgram = &(pTAS2559->mpFirmware->mpPrograms[nProgram]); if (pTAS2559->mbPowerUp) { dev_info(pTAS2559->dev, "device powered up, power down to load program %d (%s)\n", nProgram, pProgram->mpName); if (hrtimer_active(&pTAS2559->mtimer)) hrtimer_cancel(&pTAS2559->mtimer); if (pProgram->mnAppMode == TAS2559_APP_TUNINGMODE) pTAS2559->enableIRQ(pTAS2559, DevBoth, false); nResult = tas2559_DevShutdown(pTAS2559, DevBoth); if (nResult < 0) goto end; } pTAS2559->hw_reset(pTAS2559); nResult = pTAS2559->write(pTAS2559, DevBoth, TAS2559_SW_RESET_REG, 0x01); if (nResult < 0) goto end; msleep(1); nResult = tas2559_load_default(pTAS2559); if (nResult < 0) goto end; dev_info(pTAS2559->dev, "load program %d (%s)\n", nProgram, pProgram->mpName); nResult = tas2559_load_data(pTAS2559, &(pProgram->mData), TAS2559_BLOCK_PGM_DEV_A); if (nResult < 0) goto end; nResult = tas2559_load_data(pTAS2559, &(pProgram->mData), TAS2559_BLOCK_PGM_DEV_B); if (nResult < 0) goto end; pTAS2559->mnCurrentProgram = nProgram; pTAS2559->mnDevGain = 15; pTAS2559->mnDevCurrentGain = 15; nResult = tas2559_load_coefficient(pTAS2559, -1, nConfiguration, false); if (nResult < 0) goto end; tas2559_update_edge(pTAS2559, DevBoth); if (pTAS2559->mbPowerUp) { dev_info(pTAS2559->dev, "%s, load VBoost before power on %d\n", __func__, pTAS2559->mnVBoostState); nResult = tas2559_set_VBoost(pTAS2559, pTAS2559->mnVBoostState, false); if (nResult < 0) goto end; pTAS2559->clearIRQ(pTAS2559); pConfiguration = &(pTAS2559->mpFirmware->mpConfigurations[pTAS2559->mnCurrentConfiguration]); nResult = tas2559_DevStartup(pTAS2559, pConfiguration->mnDevices); if (nResult < 0) goto end; if (pProgram->mnAppMode == TAS2559_APP_TUNINGMODE) { nResult = tas2559_checkPLL(pTAS2559); if (nResult < 0) { nResult = tas2559_DevShutdown(pTAS2559, pConfiguration->mnDevices); pTAS2559->mbPowerUp = false; goto end; } } if (pConfiguration->mnDevices & DevB) { nResult = tas2559_load_data(pTAS2559, &(pConfiguration->mData), TAS2559_BLOCK_PST_POWERUP_DEV_B); if (nResult < 0) goto end; } nResult = tas2559_DevMute(pTAS2559, pConfiguration->mnDevices, false); if (nResult < 0) goto end; if (pProgram->mnAppMode == TAS2559_APP_TUNINGMODE) { pTAS2559->enableIRQ(pTAS2559, pConfiguration->mnDevices, true); if (!hrtimer_active(&pTAS2559->mtimer)) { pTAS2559->mnDieTvReadCounter = 0; hrtimer_start(&pTAS2559->mtimer, ns_to_ktime((u64)LOW_TEMPERATURE_CHECK_PERIOD * NSEC_PER_MSEC), HRTIMER_MODE_REL); } } } end: if (nResult < 0) { if (pTAS2559->mnErrCode & (ERROR_DEVA_I2C_COMM | ERROR_DEVB_I2C_COMM | ERROR_PRAM_CRCCHK | ERROR_YRAM_CRCCHK)) failsafe(pTAS2559); } return nResult; }