コード例 #1
0
ファイル: zr36050.c プロジェクト: robacklin/ts7800
/* =========================================================================
   Setup function:

   Setup compression/decompression of Zoran's JPEG processor
   ( see also zoran 36050 manual )

   ... sorry for the spaghetti code ...
   ========================================================================= */
static void
zr36050_init (struct zr36050 *ptr)
{
	int sum = 0;
	long bitcnt, tmp;

	if (ptr->mode == CODEC_DO_COMPRESSION) {
		dprintk(2, "%s: COMPRESSION SETUP\n", ptr->name);

		/* 050 communicates with 057 in master mode */
		zr36050_write(ptr, ZR050_HARDWARE, ZR050_HW_MSTR);

		/* encoding table preload for compression */
		zr36050_write(ptr, ZR050_MODE,
			      ZR050_MO_COMP | ZR050_MO_TLM);
		zr36050_write(ptr, ZR050_OPTIONS, 0);

		/* disable all IRQs */
		zr36050_write(ptr, ZR050_INT_REQ_0, 0);
		zr36050_write(ptr, ZR050_INT_REQ_1, 3);	// low 2 bits always 1

		/* volume control settings */
		/*zr36050_write(ptr, ZR050_MBCV, ptr->max_block_vol);*/
		zr36050_write(ptr, ZR050_SF_HI, ptr->scalefact >> 8);
		zr36050_write(ptr, ZR050_SF_LO, ptr->scalefact & 0xff);

		zr36050_write(ptr, ZR050_AF_HI, 0xff);
		zr36050_write(ptr, ZR050_AF_M, 0xff);
		zr36050_write(ptr, ZR050_AF_LO, 0xff);

		/* setup the variable jpeg tables */
		sum += zr36050_set_sof(ptr);
		sum += zr36050_set_sos(ptr);
		sum += zr36050_set_dri(ptr);

		/* setup the fixed jpeg tables - maybe variable, though -
		 * (see table init section above) */
		dprintk(3, "%s: write DQT, DHT, APP\n", ptr->name);
		sum += zr36050_pushit(ptr, ZR050_DQT_IDX,
				      sizeof(zr36050_dqt), zr36050_dqt);
		sum += zr36050_pushit(ptr, ZR050_DHT_IDX,
				      sizeof(zr36050_dht), zr36050_dht);
		zr36050_write(ptr, ZR050_APP_IDX, 0xff);
		zr36050_write(ptr, ZR050_APP_IDX + 1, 0xe0 + ptr->app.appn);
		zr36050_write(ptr, ZR050_APP_IDX + 2, 0x00);
		zr36050_write(ptr, ZR050_APP_IDX + 3, ptr->app.len + 2);
		sum += zr36050_pushit(ptr, ZR050_APP_IDX + 4, 60,
				      ptr->app.data) + 4;
		zr36050_write(ptr, ZR050_COM_IDX, 0xff);
		zr36050_write(ptr, ZR050_COM_IDX + 1, 0xfe);
		zr36050_write(ptr, ZR050_COM_IDX + 2, 0x00);
		zr36050_write(ptr, ZR050_COM_IDX + 3, ptr->com.len + 2);
		sum += zr36050_pushit(ptr, ZR050_COM_IDX + 4, 60,
				      ptr->com.data) + 4;

		/* do the internal huffman table preload */
		zr36050_write(ptr, ZR050_MARKERS_EN, ZR050_ME_DHTI);

		zr36050_write(ptr, ZR050_GO, 1);	// launch codec
		zr36050_wait_end(ptr);
		dprintk(2, "%s: Status after table preload: 0x%02x\n",
			ptr->name, ptr->status1);

		if ((ptr->status1 & 0x4) == 0) {
			dprintk(1, KERN_ERR "%s: init aborted!\n",
				ptr->name);
			return;	// something is wrong, its timed out!!!!
		}

		/* setup misc. data for compression (target code sizes) */

		/* size of compressed code to reach without header data */
		sum = ptr->real_code_vol - sum;
		bitcnt = sum << 3;	/* need the size in bits */

		tmp = bitcnt >> 16;
		dprintk(3,
			"%s: code: csize=%d, tot=%d, bit=%ld, highbits=%ld\n",
			ptr->name, sum, ptr->real_code_vol, bitcnt, tmp);
		zr36050_write(ptr, ZR050_TCV_NET_HI, tmp >> 8);
		zr36050_write(ptr, ZR050_TCV_NET_MH, tmp & 0xff);
		tmp = bitcnt & 0xffff;
		zr36050_write(ptr, ZR050_TCV_NET_ML, tmp >> 8);
		zr36050_write(ptr, ZR050_TCV_NET_LO, tmp & 0xff);

		bitcnt -= bitcnt >> 7;	// bits without stuffing
		bitcnt -= ((bitcnt * 5) >> 6);	// bits without eob

		tmp = bitcnt >> 16;
		dprintk(3, "%s: code: nettobit=%ld, highnettobits=%ld\n",
			ptr->name, bitcnt, tmp);
		zr36050_write(ptr, ZR050_TCV_DATA_HI, tmp >> 8);
		zr36050_write(ptr, ZR050_TCV_DATA_MH, tmp & 0xff);
		tmp = bitcnt & 0xffff;
		zr36050_write(ptr, ZR050_TCV_DATA_ML, tmp >> 8);
		zr36050_write(ptr, ZR050_TCV_DATA_LO, tmp & 0xff);

		/* compression setup with or without bitrate control */
		zr36050_write(ptr, ZR050_MODE,
			      ZR050_MO_COMP | ZR050_MO_PASS2 |
			      (ptr->bitrate_ctrl ? ZR050_MO_BRC : 0));

		/* this headers seem to deliver "valid AVI" jpeg frames */
		zr36050_write(ptr, ZR050_MARKERS_EN,
			      ZR050_ME_DQT | ZR050_ME_DHT |
			      ((ptr->app.len > 0) ? ZR050_ME_APP : 0) |
			      ((ptr->com.len > 0) ? ZR050_ME_COM : 0));
	} else {
コード例 #2
0
static void
zr36050_init (struct zr36050 *ptr)
{
	int sum = 0;
	long bitcnt, tmp;

	if (ptr->mode == CODEC_DO_COMPRESSION) {
		dprintk(2, "%s: COMPRESSION SETUP\n", ptr->name);

		/*                                          */
		zr36050_write(ptr, ZR050_HARDWARE, ZR050_HW_MSTR);

		/*                                        */
		zr36050_write(ptr, ZR050_MODE,
			      ZR050_MO_COMP | ZR050_MO_TLM);
		zr36050_write(ptr, ZR050_OPTIONS, 0);

		/*                  */
		zr36050_write(ptr, ZR050_INT_REQ_0, 0);
		zr36050_write(ptr, ZR050_INT_REQ_1, 3);	//                    

		/*                         */
		/*                                                   */
		zr36050_write(ptr, ZR050_SF_HI, ptr->scalefact >> 8);
		zr36050_write(ptr, ZR050_SF_LO, ptr->scalefact & 0xff);

		zr36050_write(ptr, ZR050_AF_HI, 0xff);
		zr36050_write(ptr, ZR050_AF_M, 0xff);
		zr36050_write(ptr, ZR050_AF_LO, 0xff);

		/*                                */
		sum += zr36050_set_sof(ptr);
		sum += zr36050_set_sos(ptr);
		sum += zr36050_set_dri(ptr);

		/*                                                       
                                    */
		dprintk(3, "%s: write DQT, DHT, APP\n", ptr->name);
		sum += zr36050_pushit(ptr, ZR050_DQT_IDX,
				      sizeof(zr36050_dqt), zr36050_dqt);
		sum += zr36050_pushit(ptr, ZR050_DHT_IDX,
				      sizeof(zr36050_dht), zr36050_dht);
		zr36050_write(ptr, ZR050_APP_IDX, 0xff);
		zr36050_write(ptr, ZR050_APP_IDX + 1, 0xe0 + ptr->app.appn);
		zr36050_write(ptr, ZR050_APP_IDX + 2, 0x00);
		zr36050_write(ptr, ZR050_APP_IDX + 3, ptr->app.len + 2);
		sum += zr36050_pushit(ptr, ZR050_APP_IDX + 4, 60,
				      ptr->app.data) + 4;
		zr36050_write(ptr, ZR050_COM_IDX, 0xff);
		zr36050_write(ptr, ZR050_COM_IDX + 1, 0xfe);
		zr36050_write(ptr, ZR050_COM_IDX + 2, 0x00);
		zr36050_write(ptr, ZR050_COM_IDX + 3, ptr->com.len + 2);
		sum += zr36050_pushit(ptr, ZR050_COM_IDX + 4, 60,
				      ptr->com.data) + 4;

		/*                                       */
		zr36050_write(ptr, ZR050_MARKERS_EN, ZR050_ME_DHTI);

		zr36050_write(ptr, ZR050_GO, 1);	//             
		zr36050_wait_end(ptr);
		dprintk(2, "%s: Status after table preload: 0x%02x\n",
			ptr->name, ptr->status1);

		if ((ptr->status1 & 0x4) == 0) {
			dprintk(1, KERN_ERR "%s: init aborted!\n",
				ptr->name);
			return;	//                                      
		}

		/*                                                      */

		/*                                                      */
		sum = ptr->real_code_vol - sum;
		bitcnt = sum << 3;	/*                       */

		tmp = bitcnt >> 16;
		dprintk(3,
			"%s: code: csize=%d, tot=%d, bit=%ld, highbits=%ld\n",
			ptr->name, sum, ptr->real_code_vol, bitcnt, tmp);
		zr36050_write(ptr, ZR050_TCV_NET_HI, tmp >> 8);
		zr36050_write(ptr, ZR050_TCV_NET_MH, tmp & 0xff);
		tmp = bitcnt & 0xffff;
		zr36050_write(ptr, ZR050_TCV_NET_ML, tmp >> 8);
		zr36050_write(ptr, ZR050_TCV_NET_LO, tmp & 0xff);

		bitcnt -= bitcnt >> 7;	//                      
		bitcnt -= ((bitcnt * 5) >> 6);	//                 

		tmp = bitcnt >> 16;
		dprintk(3, "%s: code: nettobit=%ld, highnettobits=%ld\n",
			ptr->name, bitcnt, tmp);
		zr36050_write(ptr, ZR050_TCV_DATA_HI, tmp >> 8);
		zr36050_write(ptr, ZR050_TCV_DATA_MH, tmp & 0xff);
		tmp = bitcnt & 0xffff;
		zr36050_write(ptr, ZR050_TCV_DATA_ML, tmp >> 8);
		zr36050_write(ptr, ZR050_TCV_DATA_LO, tmp & 0xff);

		/*                                                   */
		zr36050_write(ptr, ZR050_MODE,
			      ZR050_MO_COMP | ZR050_MO_PASS2 |
			      (ptr->bitrate_ctrl ? ZR050_MO_BRC : 0));

		/*                                                      */
		zr36050_write(ptr, ZR050_MARKERS_EN,
			      ZR050_ME_DQT | ZR050_ME_DHT |
			      ((ptr->app.len > 0) ? ZR050_ME_APP : 0) |
			      ((ptr->com.len > 0) ? ZR050_ME_COM : 0));
	} else {