11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
20c0d06caSMauro Carvalho Chehab /* Linux driver for Philips webcam
30c0d06caSMauro Carvalho Chehab Decompression frontend.
40c0d06caSMauro Carvalho Chehab (C) 1999-2003 Nemosoft Unv.
50c0d06caSMauro Carvalho Chehab (C) 2004-2006 Luc Saillard (luc@saillard.org)
60c0d06caSMauro Carvalho Chehab
70c0d06caSMauro Carvalho Chehab NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
80c0d06caSMauro Carvalho Chehab driver and thus may have bugs that are not present in the original version.
90c0d06caSMauro Carvalho Chehab Please send bug reports and support requests to <luc@saillard.org>.
100c0d06caSMauro Carvalho Chehab The decompression routines have been implemented by reverse-engineering the
110c0d06caSMauro Carvalho Chehab Nemosoft binary pwcx module. Caveat emptor.
120c0d06caSMauro Carvalho Chehab */
130c0d06caSMauro Carvalho Chehab
140c0d06caSMauro Carvalho Chehab #include <asm/current.h>
150c0d06caSMauro Carvalho Chehab #include <asm/types.h>
160c0d06caSMauro Carvalho Chehab
170c0d06caSMauro Carvalho Chehab #include "pwc.h"
180c0d06caSMauro Carvalho Chehab #include "pwc-dec1.h"
190c0d06caSMauro Carvalho Chehab #include "pwc-dec23.h"
200c0d06caSMauro Carvalho Chehab
pwc_decompress(struct pwc_device * pdev,struct pwc_frame_buf * fbuf)210c0d06caSMauro Carvalho Chehab int pwc_decompress(struct pwc_device *pdev, struct pwc_frame_buf *fbuf)
220c0d06caSMauro Carvalho Chehab {
230c0d06caSMauro Carvalho Chehab int n, line, col;
240c0d06caSMauro Carvalho Chehab void *yuv, *image;
250c0d06caSMauro Carvalho Chehab u16 *src;
260c0d06caSMauro Carvalho Chehab u16 *dsty, *dstu, *dstv;
270c0d06caSMauro Carvalho Chehab
282d700715SJunghak Sung image = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
290c0d06caSMauro Carvalho Chehab
300c0d06caSMauro Carvalho Chehab yuv = fbuf->data + pdev->frame_header_size; /* Skip header */
310c0d06caSMauro Carvalho Chehab
320c0d06caSMauro Carvalho Chehab /* Raw format; that's easy... */
330c0d06caSMauro Carvalho Chehab if (pdev->pixfmt != V4L2_PIX_FMT_YUV420)
340c0d06caSMauro Carvalho Chehab {
350c0d06caSMauro Carvalho Chehab struct pwc_raw_frame *raw_frame = image;
360c0d06caSMauro Carvalho Chehab raw_frame->type = cpu_to_le16(pdev->type);
370c0d06caSMauro Carvalho Chehab raw_frame->vbandlength = cpu_to_le16(pdev->vbandlength);
380c0d06caSMauro Carvalho Chehab /* cmd_buf is always 4 bytes, but sometimes, only the
390c0d06caSMauro Carvalho Chehab * first 3 bytes is filled (Nala case). We can
400c0d06caSMauro Carvalho Chehab * determine this using the type of the webcam */
410c0d06caSMauro Carvalho Chehab memcpy(raw_frame->cmd, pdev->cmd_buf, 4);
42*389b6a22SGustavo A. R. Silva memcpy(raw_frame->rawframe, yuv, pdev->frame_size);
432d700715SJunghak Sung vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
44dca4f5fdSGustavo A. R. Silva struct_size(raw_frame, rawframe, pdev->frame_size));
450c0d06caSMauro Carvalho Chehab return 0;
460c0d06caSMauro Carvalho Chehab }
470c0d06caSMauro Carvalho Chehab
482d700715SJunghak Sung vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
490c0d06caSMauro Carvalho Chehab pdev->width * pdev->height * 3 / 2);
500c0d06caSMauro Carvalho Chehab
510c0d06caSMauro Carvalho Chehab if (pdev->vbandlength == 0) {
520c0d06caSMauro Carvalho Chehab /* Uncompressed mode.
530c0d06caSMauro Carvalho Chehab *
540c0d06caSMauro Carvalho Chehab * We do some byte shuffling here to go from the
550c0d06caSMauro Carvalho Chehab * native format to YUV420P.
560c0d06caSMauro Carvalho Chehab */
570c0d06caSMauro Carvalho Chehab src = (u16 *)yuv;
580c0d06caSMauro Carvalho Chehab n = pdev->width * pdev->height;
590c0d06caSMauro Carvalho Chehab dsty = (u16 *)(image);
600c0d06caSMauro Carvalho Chehab dstu = (u16 *)(image + n);
610c0d06caSMauro Carvalho Chehab dstv = (u16 *)(image + n + n / 4);
620c0d06caSMauro Carvalho Chehab
630c0d06caSMauro Carvalho Chehab for (line = 0; line < pdev->height; line++) {
640c0d06caSMauro Carvalho Chehab for (col = 0; col < pdev->width; col += 4) {
650c0d06caSMauro Carvalho Chehab *dsty++ = *src++;
660c0d06caSMauro Carvalho Chehab *dsty++ = *src++;
670c0d06caSMauro Carvalho Chehab if (line & 1)
680c0d06caSMauro Carvalho Chehab *dstv++ = *src++;
690c0d06caSMauro Carvalho Chehab else
700c0d06caSMauro Carvalho Chehab *dstu++ = *src++;
710c0d06caSMauro Carvalho Chehab }
720c0d06caSMauro Carvalho Chehab }
730c0d06caSMauro Carvalho Chehab
740c0d06caSMauro Carvalho Chehab return 0;
750c0d06caSMauro Carvalho Chehab }
760c0d06caSMauro Carvalho Chehab
770c0d06caSMauro Carvalho Chehab /*
780c0d06caSMauro Carvalho Chehab * Compressed;
790c0d06caSMauro Carvalho Chehab * the decompressor routines will write the data in planar format
800c0d06caSMauro Carvalho Chehab * immediately.
810c0d06caSMauro Carvalho Chehab */
820c0d06caSMauro Carvalho Chehab if (DEVICE_USE_CODEC1(pdev->type)) {
830c0d06caSMauro Carvalho Chehab
840c0d06caSMauro Carvalho Chehab /* TODO & FIXME */
850c0d06caSMauro Carvalho Chehab PWC_ERROR("This chipset is not supported for now\n");
860c0d06caSMauro Carvalho Chehab return -ENXIO; /* No such device or address: missing decompressor */
870c0d06caSMauro Carvalho Chehab
880c0d06caSMauro Carvalho Chehab } else {
890c0d06caSMauro Carvalho Chehab pwc_dec23_decompress(pdev, yuv, image);
900c0d06caSMauro Carvalho Chehab }
910c0d06caSMauro Carvalho Chehab return 0;
920c0d06caSMauro Carvalho Chehab }
93