Kernel->HDMIIN:support HDMIIN record video

This commit is contained in:
zouxf
2015-12-29 17:25:13 +08:00
parent 8280196215
commit e5e47c724a
11 changed files with 168 additions and 86 deletions

View File

@ -1149,10 +1149,23 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
property_get("media.audio.close", value, NULL);
if (atoi(value) == 1) {
int camsys_fd;
const char HdmiAudioFilePath[] = "/sys/class/hdmiin_reg/hdmiin_audio";
ALOGD("hdmiin audio in");
//standby all out audio
property_set("media.audio.close", "3");
do_out_standby(out);
//reset_bitstream_buf(out);
//open hdmiin audio in kernel
//audio hw stop must before hdmiin audio start
ALOGD("open TC358749XBG camsys");
camsys_fd = open(HdmiAudioFilePath, O_RDWR);
if (camsys_fd < 0) {
ALOGD("open TC358749XBG camsys fail");
} else {
write(camsys_fd,"2",1);
close(camsys_fd);
}
} else if (atoi(value) == 2) {
ALOGD("hdmiin audio out");
property_set("media.audio.close", "0");

View File

@ -163,7 +163,7 @@ struct pcm_config pcm_config_in = {
.channels = 2,
.rate = 44100,
.period_size = 1024,
.period_count = 4,
.period_count = 2,
.format = PCM_FORMAT_S16_LE,
};

View File

@ -108,6 +108,7 @@ int CameraIspAdapter::cameraCreate(int cameraId)
HalPara_t isp_halpara;
int mipiLaneNum = 0;
int i =0;
char value[PROPERTY_VALUE_MAX];
hdmiIn_Exit = true;
preview_frame_inval = pCamInfo->mHardInfo.mSensorInfo.awb_frame_skip;
@ -130,13 +131,28 @@ int CameraIspAdapter::cameraCreate(int cameraId)
//load sensor
loadSensor( cameraId);
{
rk_cam_total_info *pCamInfo = gCamInfos[cameraId].pcam_total_info;
property_get("sys.boot_completed", value, NULL);
if (atoi(value) > 0) {
rk_cam_total_info *pCamInfo = gCamInfos[mCamId].pcam_total_info;
LOGE("sensor name %s",pCamInfo->mHardInfo.mSensorInfo.mSensorName);
if((strcmp(pCamInfo->mHardInfo.mSensorInfo.mSensorName,"TC358749XBG")==0)) {
int camsys_fd;
const char HdmiAudioFilePath[] = "/sys/class/hdmiin_reg/hdmiin_audio";
LOGE("open TC358749XBG camsys");
//audio hw stop must before hdmiin audio start
property_set("media.audio.close", "1");
hdmiIn_Exit = false;
camsys_fd = open(HdmiAudioFilePath, O_RDWR);
if (camsys_fd < 0) {
LOGE("open TC358749XBG camsys fail");
} else {
write(camsys_fd,"1",1);
close(camsys_fd);
}
}
}
//open image
//openImage("/system/lib/libisp_isi_drv_OV8825.so");
@ -180,7 +196,24 @@ int CameraIspAdapter::cameraDestroy()
mAfListenerThread.clear();
}
//hdmiin thread
hdmiIn_Exit = true;
if (hdmiIn_Exit == false) {
int camsys_fd;
const char HdmiAudioFilePath[] = "/sys/class/hdmiin_reg/hdmiin_audio";
LOGE("open TC358749XBG camsys");
camsys_fd = open(HdmiAudioFilePath, O_RDWR);
if (camsys_fd < 0) {
LOGE("open TC358749XBG camsys fail");
} else {
write(camsys_fd,"0",1);
close(camsys_fd);
}
//audio hw restart must below hdmiin audio stop
property_set("media.audio.close", "2");
hdmiIn_Exit = true;
}
if(mHdmiinListenerThread!= NULL){
mHdmiinListenerThread->requestExitAndWait();
mHdmiinListenerThread.clear();
@ -315,25 +348,7 @@ status_t CameraIspAdapter::startPreview(int preview_w,int preview_h,int w, int h
cameraCreate(mCamId);
}
{
rk_cam_total_info *pCamInfo = gCamInfos[mCamId].pcam_total_info;
LOGE("sensor name %s",pCamInfo->mHardInfo.mSensorInfo.mSensorName);
if((strcmp(pCamInfo->mHardInfo.mSensorInfo.mSensorName,"TC358749XBG")==0)) {
int camsys_fd;
const char HdmiAudioFilePath[] = "/sys/class/hdmiin_reg/hdmiin_audio";
LOGE("open TC358749XBG camsys");
//audio hw stop must before hdmiin audio start
property_set("media.audio.close", "1");
camsys_fd = open(HdmiAudioFilePath, O_RDWR);
if (camsys_fd < 0) {
LOGE("open TC358749XBG camsys fail");
} else {
write(camsys_fd,"1",1);
close(camsys_fd);
}
}
}
is_video = (((preview_w == 1920) && (preview_h == 1080)) ||
((preview_w == 1280) && (preview_h == 720)));
@ -509,25 +524,6 @@ status_t CameraIspAdapter::stopPreview()
return -1;
clearFrameArray();
{
rk_cam_total_info *pCamInfo = gCamInfos[mCamId].pcam_total_info;
LOGE("sensor name %s",pCamInfo->mHardInfo.mSensorInfo.mSensorName);
if((strcmp(pCamInfo->mHardInfo.mSensorInfo.mSensorName,"TC358749XBG")==0)) {
int camsys_fd;
const char HdmiAudioFilePath[] = "/sys/class/hdmiin_reg/hdmiin_audio";
LOGE("open TC358749XBG camsys");
camsys_fd = open(HdmiAudioFilePath, O_RDWR);
if (camsys_fd < 0) {
LOGE("open TC358749XBG camsys fail");
} else {
write(camsys_fd,"0",1);
close(camsys_fd);
}
//audio hw restart must below hdmiin audio stop
property_set("media.audio.close", "2");
}
}
}
mPreviewRunning = 0;

View File

@ -1163,7 +1163,7 @@ int collect_all_zones( hwcContext * Context,hwc_display_contents_1_t * list)
break;
default:
ALOGD("Unsupport transform=0x%x",layer->transform);
//ALOGD("Unsupport transform=0x%x",layer->transform);
return -1;
}
ALOGV("layer->transform=%d",layer->transform);

View File

@ -477,17 +477,19 @@ struct class_attribute *attr, const char *buf, size_t count)
int val;
val = simple_strtol(buf,&string,0);
if (val == 1) {
audio_start = 1;
pr_info("start hdmiin detect \n");
} else if (val == 0) {
if (val == 0) {
audio_start = 0;
snd_stop_hdmi_in_audio_route();
pr_info("end hdmiin detect \n");
} else if (val == 2) {
audio_start = 0;
es8323_codec_set_reg(1);
pr_info("capture \n");
} else if (val == 1) {
audio_start = 1;
pr_info("start hdmiin detect \n");
snd_start_hdmi_in_audio_route();
} else if (val == 2) {
audio_start = 1;
pr_info("stop local , then open hdmiin\n");
//snd_stop_hdmi_in_audio_route();
//snd_start_hdmi_in_audio_route();
}
return strnlen(buf, PAGE_SIZE);

View File

@ -158,11 +158,16 @@ struct dmaengine_hdmiin_audio_pcm_runtime_data {
struct snd_dma_buffer dma_buffer_b2;
};
int snd_dmaengine_hdmiin_audio_pcm_trigger(int cmd);
enum {
HDMIN_NORMAL_MODE = 0,
HDMIN_CAPTURE_MODE,
};
int snd_dmaengine_hdmiin_audio_pcm_trigger(int cmd, int mode);
int snd_dmaengine_hdmiin_audio_pcm_open(void);
int snd_dmaengine_hdmiin_audio_pcm_close(void);
int snd_get_hdmiin_audio_pcm_slave_config(struct dma_slave_config *slave_config, enum dma_chan_device_id id);
int dmaengine_hdmiin_audio_pcm_hw_params(void);
int dmaengine_hdmiin_audio_pcm_hw_params(int mode);
#define I2S_PLAYBACK_DMA_CHN "dma0chan0"
#define I2S_CAPTURE_DMA_CHN "dma0chan1"

View File

@ -2144,12 +2144,17 @@ static int snd_pcm_playback_open(struct inode *inode, struct file *file)
return err;
}
extern int snd_hdmiin_capture_mode(bool en);
static int snd_pcm_capture_open(struct inode *inode, struct file *file)
{
struct snd_pcm *pcm;
int err = nonseekable_open(inode, file);
if (err < 0)
return err;
snd_hdmiin_capture_mode(1);
pcm = snd_lookup_minor_data(iminor(inode),
SNDRV_DEVICE_TYPE_PCM_CAPTURE);
err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_CAPTURE);
@ -2220,11 +2225,13 @@ static int snd_pcm_release(struct inode *inode, struct file *file)
struct snd_pcm *pcm;
struct snd_pcm_substream *substream;
struct snd_pcm_file *pcm_file;
int stream = -1;
pcm_file = file->private_data;
substream = pcm_file->substream;
if (snd_BUG_ON(!substream))
return -ENXIO;
stream = substream->stream;
pcm = substream->pcm;
mutex_lock(&pcm->open_mutex);
snd_pcm_release_substream(substream);
@ -2233,6 +2240,9 @@ static int snd_pcm_release(struct inode *inode, struct file *file)
wake_up(&pcm->open_wait);
module_put(pcm->card->module);
snd_card_file_remove(pcm->card, file);
if (SNDRV_PCM_STREAM_CAPTURE == stream)
snd_hdmiin_capture_mode(0);
return 0;
}

View File

@ -364,7 +364,7 @@ static void rk_snd_spdif_txctrl(int on)
on, readl(regs + XFER), readl(regs + DMACR));
}
static int rk_hdmiin_audio_trigger(int cmd)
static int rk_hdmiin_audio_trigger(int cmd, int mode)
{
int ret = 0;
@ -372,13 +372,15 @@ static int rk_hdmiin_audio_trigger(int cmd)
switch (cmd)
{
case SNDRV_PCM_TRIGGER_START:
rk_snd_i2s_rxctrl(1);
if (HDMIN_NORMAL_MODE == mode)
rk_snd_i2s_rxctrl(1);
rk_snd_i2s_txctrl(1);
rk_snd_spdif_txctrl(1);
break;
case SNDRV_PCM_TRIGGER_STOP:
rk_snd_i2s_rxctrl(0);
if (HDMIN_NORMAL_MODE == mode)
rk_snd_i2s_rxctrl(0);
rk_snd_i2s_txctrl(0);
rk_snd_spdif_txctrl(0);
break;
@ -524,29 +526,41 @@ static int rk_hdmiin_audio_hw_params(struct snd_pcm_hw_params *params)
static int audio_route_active = 0;
extern void rk1000_audio_cfg(int loopback);
extern void es8323_codec_set_reg(int loopback);
static int hdmin_mode = HDMIN_NORMAL_MODE;
static DEFINE_MUTEX(hdmin_lock);
int snd_stop_hdmi_in_audio_route(void)
static int snd_stop_hdmi_in_audio_route_l(void)
{
if (!audio_route_active)
return 0;
// pr_info("%s\n", __func__);
snd_dmaengine_hdmiin_audio_pcm_trigger(SNDRV_PCM_TRIGGER_STOP);
rk_hdmiin_audio_trigger(SNDRV_PCM_TRIGGER_STOP);
snd_dmaengine_hdmiin_audio_pcm_trigger(SNDRV_PCM_TRIGGER_STOP, hdmin_mode);
rk_hdmiin_audio_trigger(SNDRV_PCM_TRIGGER_STOP, hdmin_mode);
es8323_codec_set_reg(0);
audio_route_active--;
return 0;
}
int snd_stop_hdmi_in_audio_route(void)
{
mutex_lock(&hdmin_lock);
snd_stop_hdmi_in_audio_route_l();
mutex_unlock(&hdmin_lock);
return 0;
}
EXPORT_SYMBOL(snd_stop_hdmi_in_audio_route);
int snd_start_hdmi_in_audio_route(void)
static int snd_start_hdmi_in_audio_route_l(int mode)
{
struct snd_pcm_hw_params params;
if (audio_route_active)
return 0;
hdmin_mode = mode;
audio_route_active++;
//rk1000_audio_cfg(1);
es8323_codec_set_reg(1);
@ -563,14 +577,47 @@ int snd_start_hdmi_in_audio_route(void)
snd_dmaengine_hdmiin_audio_pcm_open(); //dma set
rk_hdmiin_audio_hw_params(&params); //config hdmi in audio
snd_config_hdmi_audio(&params); //config hdmi out audio
dmaengine_hdmiin_audio_pcm_hw_params(); //
snd_dmaengine_hdmiin_audio_pcm_trigger(SNDRV_PCM_TRIGGER_START); //start dma engine
rk_hdmiin_audio_trigger(SNDRV_PCM_TRIGGER_START);
dmaengine_hdmiin_audio_pcm_hw_params(mode);
snd_dmaengine_hdmiin_audio_pcm_trigger(SNDRV_PCM_TRIGGER_START, mode);
rk_hdmiin_audio_trigger(SNDRV_PCM_TRIGGER_START, mode);
return 0;
}
int snd_start_hdmi_in_audio_route(void)
{
mutex_lock(&hdmin_lock);
snd_start_hdmi_in_audio_route_l(HDMIN_NORMAL_MODE);
mutex_unlock(&hdmin_lock);
return 0;
}
EXPORT_SYMBOL(snd_start_hdmi_in_audio_route);
int snd_hdmiin_capture_mode(bool en)
{
int mode;
printk("%s %d %d \n",__FUNCTION__,__LINE__,en);
mutex_lock(&hdmin_lock);
if (!audio_route_active) {
mutex_unlock(&hdmin_lock);
return 0;
}
if (en)
mode = HDMIN_CAPTURE_MODE;
else
mode = HDMIN_NORMAL_MODE;
snd_stop_hdmi_in_audio_route_l();
snd_start_hdmi_in_audio_route_l(mode);
mutex_unlock(&hdmin_lock);
return 0;
}
EXPORT_SYMBOL(snd_hdmiin_capture_mode);
int snd_get_hdmiin_audio_pcm_slave_config(struct dma_slave_config *slave_config, enum dma_chan_device_id id)
{
int ret = 0;

View File

@ -37,7 +37,7 @@ static const struct snd_pcm_hardware rockchip_pcm_hardware = {
.buffer_bytes_max = 2*1024*1024,/*128*1024,*/
.period_bytes_min = 64,
.period_bytes_max = 512*1024,/*32*1024,//2048*4,///PAGE_SIZE*2,*/
.periods_min = 3,
.periods_min = 2,
.periods_max = 128,
.fifo_size = 16,
};

View File

@ -430,7 +430,7 @@ static void dmaengine_hdmiin_audio_pcm_dma_complete_b(void *arg)
prtd->pos_b = 0;
}
static int dmaengine_hdmiin_audio_pcm_prepare_and_submit(void)
static int dmaengine_hdmiin_audio_pcm_prepare_and_submit(int mode)
{
struct dmaengine_hdmiin_audio_pcm_runtime_data *prtd = hdmiin_audio_prtd;
struct dma_chan *chan_c = prtd->dma_chan_c;
@ -446,20 +446,22 @@ static int dmaengine_hdmiin_audio_pcm_prepare_and_submit(void)
prtd->pos_b = 0;
prtd->pos_c = 0;
/* init capture */
direction = DMA_DEV_TO_MEM;
pr_info("dma_addr capture: %x\n", prtd->dma_buffer_c.addr);
desc_capture = dmaengine_prep_dma_cyclic(chan_c,
prtd->dma_buffer_c.addr,
HDMIIN_AUDIO_PERIOD_SIZE_BYTES*HDMIIN_AUDIO_PERIODS,
HDMIIN_AUDIO_PERIOD_SIZE_BYTES, direction, flags);
if (HDMIN_NORMAL_MODE == mode) {
/* init capture */
direction = DMA_DEV_TO_MEM;
pr_info("dma_addr capture: %x\n", prtd->dma_buffer_c.addr);
desc_capture = dmaengine_prep_dma_cyclic(chan_c,
prtd->dma_buffer_c.addr,
HDMIIN_AUDIO_PERIOD_SIZE_BYTES*HDMIIN_AUDIO_PERIODS,
HDMIIN_AUDIO_PERIOD_SIZE_BYTES, direction, flags);
if (!desc_capture)
return -ENOMEM;
if (!desc_capture)
return -ENOMEM;
desc_capture->callback = dmaengine_hdmiin_audio_pcm_dma_complete_c;
desc_capture->callback_param = NULL;
prtd->cookie_c = dmaengine_submit(desc_capture);
desc_capture->callback = dmaengine_hdmiin_audio_pcm_dma_complete_c;
desc_capture->callback_param = NULL;
prtd->cookie_c = dmaengine_submit(desc_capture);
}
/* init playback */
direction = DMA_MEM_TO_DEV;
@ -497,7 +499,7 @@ static int dmaengine_hdmiin_audio_pcm_prepare_and_submit(void)
return 0;
}
int snd_dmaengine_hdmiin_audio_pcm_trigger(int cmd)
int snd_dmaengine_hdmiin_audio_pcm_trigger(int cmd, int mode)
{
struct dmaengine_hdmiin_audio_pcm_runtime_data *prtd;
int ret;
@ -506,16 +508,19 @@ int snd_dmaengine_hdmiin_audio_pcm_trigger(int cmd)
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
ret = dmaengine_hdmiin_audio_pcm_prepare_and_submit();
ret = dmaengine_hdmiin_audio_pcm_prepare_and_submit(mode);
if (ret)
return ret;
dma_async_issue_pending(prtd->dma_chan_c);
if (HDMIN_NORMAL_MODE == mode)
dma_async_issue_pending(prtd->dma_chan_c);
dma_async_issue_pending(prtd->dma_chan_b);
dma_async_issue_pending(prtd->dma_chan_b2);
break;
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
dmaengine_resume(prtd->dma_chan_c);
if (HDMIN_NORMAL_MODE == mode)
dmaengine_resume(prtd->dma_chan_c);
dmaengine_resume(prtd->dma_chan_b);
dmaengine_resume(prtd->dma_chan_b2);
break;
@ -523,12 +528,14 @@ int snd_dmaengine_hdmiin_audio_pcm_trigger(int cmd)
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
dmaengine_pause(prtd->dma_chan_b2);
dmaengine_pause(prtd->dma_chan_b);
dmaengine_pause(prtd->dma_chan_c);
if (HDMIN_NORMAL_MODE == mode)
dmaengine_pause(prtd->dma_chan_c);
break;
case SNDRV_PCM_TRIGGER_STOP:
dmaengine_terminate_all(prtd->dma_chan_b2);
dmaengine_terminate_all(prtd->dma_chan_b);
dmaengine_terminate_all(prtd->dma_chan_c);
if (HDMIN_NORMAL_MODE == mode)
dmaengine_terminate_all(prtd->dma_chan_c);
break;
default:
return -EINVAL;

View File

@ -153,7 +153,7 @@ int snd_dmaengine_hdmiin_audio_pcm_open()
EXPORT_SYMBOL_GPL(snd_dmaengine_hdmiin_audio_pcm_open);
extern struct dmaengine_hdmiin_audio_pcm_runtime_data *hdmiin_audio_prtd;
int dmaengine_hdmiin_audio_pcm_hw_params()
int dmaengine_hdmiin_audio_pcm_hw_params(int mode)
{
struct dmaengine_hdmiin_audio_pcm_runtime_data *prtd = hdmiin_audio_prtd;
struct dma_chan *chan_c = prtd->dma_chan_c;
@ -164,11 +164,13 @@ int dmaengine_hdmiin_audio_pcm_hw_params()
struct dma_slave_config slave_config_b2;
int ret;
snd_get_hdmiin_audio_pcm_slave_config(&slave_config_c, I2S_CAPTURE);
if (HDMIN_NORMAL_MODE == mode)
snd_get_hdmiin_audio_pcm_slave_config(&slave_config_c, I2S_CAPTURE);
snd_get_hdmiin_audio_pcm_slave_config(&slave_config_b, I2S_PLAYBACK);
snd_get_hdmiin_audio_pcm_slave_config(&slave_config_b2, SPDIF_PLAYBACK);
ret = dmaengine_slave_config(chan_c, &slave_config_c);
if (HDMIN_NORMAL_MODE == mode)
ret = dmaengine_slave_config(chan_c, &slave_config_c);
ret = dmaengine_slave_config(chan_b, &slave_config_b);
ret = dmaengine_slave_config(chan_b2, &slave_config_b2);