Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /* Linux driver for Philips webcam
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)    Decompression frontend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)    (C) 1999-2003 Nemosoft Unv.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)    (C) 2004-2006 Luc Saillard (luc@saillard.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)    NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)    driver and thus may have bugs that are not present in the original version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)    Please send bug reports and support requests to <luc@saillard.org>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)    The decompression routines have been implemented by reverse-engineering the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)    Nemosoft binary pwcx module. Caveat emptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)    vim: set ts=8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/current.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "pwc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "pwc-dec1.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "pwc-dec23.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int pwc_decompress(struct pwc_device *pdev, struct pwc_frame_buf *fbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	int n, line, col;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	void *yuv, *image;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	u16 *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	u16 *dsty, *dstu, *dstv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	image = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	yuv = fbuf->data + pdev->frame_header_size;  /* Skip header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	/* Raw format; that's easy... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	if (pdev->pixfmt != V4L2_PIX_FMT_YUV420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 		struct pwc_raw_frame *raw_frame = image;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		raw_frame->type = cpu_to_le16(pdev->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		raw_frame->vbandlength = cpu_to_le16(pdev->vbandlength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 			/* cmd_buf is always 4 bytes, but sometimes, only the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 			 * first 3 bytes is filled (Nala case). We can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 			 * determine this using the type of the webcam */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 		memcpy(raw_frame->cmd, pdev->cmd_buf, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 		memcpy(raw_frame+1, yuv, pdev->frame_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 			pdev->frame_size + sizeof(struct pwc_raw_frame));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 			      pdev->width * pdev->height * 3 / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	if (pdev->vbandlength == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 		/* Uncompressed mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		 * We do some byte shuffling here to go from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 		 * native format to YUV420P.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 		src = (u16 *)yuv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 		n = pdev->width * pdev->height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 		dsty = (u16 *)(image);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 		dstu = (u16 *)(image + n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 		dstv = (u16 *)(image + n + n / 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 		for (line = 0; line < pdev->height; line++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 			for (col = 0; col < pdev->width; col += 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 				*dsty++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 				*dsty++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 				if (line & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 					*dstv++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 					*dstu++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	 * Compressed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 	 * the decompressor routines will write the data in planar format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 	 * immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 	if (DEVICE_USE_CODEC1(pdev->type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 		/* TODO & FIXME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 		PWC_ERROR("This chipset is not supported for now\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 		return -ENXIO; /* No such device or address: missing decompressor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) 		pwc_dec23_decompress(pdev, yuv, image);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }