Exemple #1
0
static int
saa7111_command (struct i2c_client *client,
                 unsigned int       cmd,
                 void              *arg)
{
    struct saa7111 *decoder = i2c_get_clientdata(client);

    switch (cmd) {

    case 0:
        break;
    case DECODER_INIT:
    {
        struct video_decoder_init *init = arg;
        if (NULL != init)
            return saa7111_init_decoder(client, init);
        else {
            struct video_decoder_init vdi;
            vdi.data = saa7111_i2c_init;
            vdi.len = sizeof(saa7111_i2c_init);
            return saa7111_init_decoder(client, &vdi);
        }
    }

    case DECODER_DUMP:
    {
        int i;

        for (i = 0; i < SAA7111_NR_REG; i += 16) {
            int j;

            printk(KERN_DEBUG "%s: %03x", I2C_NAME(client), i);
            for (j = 0; j < 16 && i + j < SAA7111_NR_REG; ++j) {
                printk(" %02x",
                       saa7111_read(client, i + j));
            }
            printk("\n");
        }
    }
    break;

    case DECODER_GET_CAPABILITIES:
    {
        struct video_decoder_capability *cap = arg;

        cap->flags = VIDEO_DECODER_PAL |
                     VIDEO_DECODER_NTSC |
                     VIDEO_DECODER_SECAM |
                     VIDEO_DECODER_AUTO |
                     VIDEO_DECODER_CCIR;
        cap->inputs = 8;
        cap->outputs = 1;
    }
    break;

    case DECODER_GET_STATUS:
    {
        int *iarg = arg;
        int status;
        int res;

        status = saa7111_read(client, 0x1f);
        dprintk(1, KERN_DEBUG "%s status: 0x%02x\n", I2C_NAME(client),
                status);
        res = 0;
        if ((status & (1 << 6)) == 0) {
            res |= DECODER_STATUS_GOOD;
        }
        switch (decoder->norm) {
        case VIDEO_MODE_NTSC:
            res |= DECODER_STATUS_NTSC;
            break;
        case VIDEO_MODE_PAL:
            res |= DECODER_STATUS_PAL;
            break;
        case VIDEO_MODE_SECAM:
            res |= DECODER_STATUS_SECAM;
            break;
        default:
        case VIDEO_MODE_AUTO:
            if ((status & (1 << 5)) != 0) {
                res |= DECODER_STATUS_NTSC;
            } else {
                res |= DECODER_STATUS_PAL;
            }
            break;
        }
        if ((status & (1 << 0)) != 0) {
            res |= DECODER_STATUS_COLOR;
        }
        *iarg = res;
    }
    break;

    case DECODER_SET_GPIO:
    {
        int *iarg = arg;
        if (0 != *iarg) {
            saa7111_write(client, 0x11,
                          (decoder->reg[0x11] | 0x80));
        } else {
            saa7111_write(client, 0x11,
                          (decoder->reg[0x11] & 0x7f));
        }
        break;
    }

    case DECODER_SET_VBI_BYPASS:
    {
        int *iarg = arg;
        if (0 != *iarg) {
            saa7111_write(client, 0x13,
                          (decoder->reg[0x13] & 0xf0) | 0x0a);
        } else {
            saa7111_write(client, 0x13,
                          (decoder->reg[0x13] & 0xf0));
        }
        break;
    }

    case DECODER_SET_NORM:
    {
        int *iarg = arg;

        switch (*iarg) {

        case VIDEO_MODE_NTSC:
            saa7111_write(client, 0x08,
                          (decoder->reg[0x08] & 0x3f) | 0x40);
            saa7111_write(client, 0x0e,
                          (decoder->reg[0x0e] & 0x8f));
            break;

        case VIDEO_MODE_PAL:
            saa7111_write(client, 0x08,
                          (decoder->reg[0x08] & 0x3f) | 0x00);
            saa7111_write(client, 0x0e,
                          (decoder->reg[0x0e] & 0x8f));
            break;

        case VIDEO_MODE_SECAM:
            saa7111_write(client, 0x08,
                          (decoder->reg[0x08] & 0x3f) | 0x00);
            saa7111_write(client, 0x0e,
                          (decoder->reg[0x0e] & 0x8f) | 0x50);
            break;

        case VIDEO_MODE_AUTO:
            saa7111_write(client, 0x08,
                          (decoder->reg[0x08] & 0x3f) | 0x80);
            saa7111_write(client, 0x0e,
                          (decoder->reg[0x0e] & 0x8f));
            break;

        default:
            return -EINVAL;

        }
        decoder->norm = *iarg;
    }
    break;

    case DECODER_SET_INPUT:
    {
        int *iarg = arg;

        if (*iarg < 0 || *iarg > 7) {
            return -EINVAL;
        }

        if (decoder->input != *iarg) {
            decoder->input = *iarg;
            /* select mode */
            saa7111_write(client, 0x02,
                          (decoder->
                           reg[0x02] & 0xf8) | decoder->input);
            /* bypass chrominance trap for modes 4..7 */
            saa7111_write(client, 0x09,
                          (decoder->
                           reg[0x09] & 0x7f) | ((decoder->
                                                 input >
                                                 3) ? 0x80 :
                                                0));
        }
    }
    break;

    case DECODER_SET_OUTPUT:
    {
        int *iarg = arg;

        /* not much choice of outputs */
        if (*iarg != 0) {
            return -EINVAL;
        }
    }
    break;

    case DECODER_ENABLE_OUTPUT:
    {
        int *iarg = arg;
        int enable = (*iarg != 0);

        if (decoder->enable != enable) {
            decoder->enable = enable;

            /* RJ: If output should be disabled (for
             * playing videos), we also need a open PLL.
             * The input is set to 0 (where no input
             * source is connected), although this
             * is not necessary.
             *
             * If output should be enabled, we have to
             * reverse the above.
             */

            if (decoder->enable) {
                saa7111_write(client, 0x02,
                              (decoder->
                               reg[0x02] & 0xf8) |
                              decoder->input);
                saa7111_write(client, 0x08,
                              (decoder->reg[0x08] & 0xfb));
                saa7111_write(client, 0x11,
                              (decoder->
                               reg[0x11] & 0xf3) | 0x0c);
            } else {
                saa7111_write(client, 0x02,
                              (decoder->reg[0x02] & 0xf8));
                saa7111_write(client, 0x08,
                              (decoder->
                               reg[0x08] & 0xfb) | 0x04);
                saa7111_write(client, 0x11,
                              (decoder->reg[0x11] & 0xf3));
            }
        }
    }
    break;

    case DECODER_SET_PICTURE:
    {
        struct video_picture *pic = arg;

        /* We want 0 to 255 we get 0-65535 */
        saa7111_write_if_changed(client, 0x0a, pic->brightness >> 8);
        /* We want 0 to 127 we get 0-65535 */
        saa7111_write(client, 0x0b, pic->contrast >> 9);
        /* We want 0 to 127 we get 0-65535 */
        saa7111_write(client, 0x0c, pic->colour >> 9);
        /* We want -128 to 127 we get 0-65535 */
        saa7111_write(client, 0x0d, (pic->hue - 32768) >> 8);
    }
    break;

    default:
        return -EINVAL;
    }

    return 0;
}
Exemple #2
0
static int saa7111_command(struct i2c_device *device, unsigned int cmd,
			   void *arg)
{
	struct saa7111 *decoder = device->data;

	switch (cmd) {

#if defined(DECODER_DUMP)
	case DECODER_DUMP:
		{
			int i;

			for (i = 0; i < 32; i += 16) {
				int j;

				printk("KERN_DEBUG %s: %03x", device->name,
				       i);
				for (j = 0; j < 16; ++j) {
					printk(" %02x",
					       saa7111_read(decoder,
							    i + j));
				}
				printk("\n");
			}
		}
		break;
#endif				/* defined(DECODER_DUMP) */

	case DECODER_GET_CAPABILITIES:
		{
			struct video_decoder_capability *cap = arg;

			cap->flags
			    = VIDEO_DECODER_PAL
			    | VIDEO_DECODER_NTSC
			    | VIDEO_DECODER_AUTO | VIDEO_DECODER_CCIR;
			cap->inputs = 8;
			cap->outputs = 1;
		}
		break;

	case DECODER_GET_STATUS:
		{
			int *iarg = arg;
			int status;
			int res;

			status = saa7111_read(decoder, 0x1f);
			res = 0;
			if ((status & (1 << 6)) == 0) {
				res |= DECODER_STATUS_GOOD;
			}
			switch (decoder->norm) {
			case VIDEO_MODE_NTSC:
				res |= DECODER_STATUS_NTSC;
				break;
			case VIDEO_MODE_PAL:
				res |= DECODER_STATUS_PAL;
				break;
			default:
			case VIDEO_MODE_AUTO:
				if ((status & (1 << 5)) != 0) {
					res |= DECODER_STATUS_NTSC;
				} else {
					res |= DECODER_STATUS_PAL;
				}
				break;
			}
			if ((status & (1 << 0)) != 0) {
				res |= DECODER_STATUS_COLOR;
			}
			*iarg = res;
		}
		break;

	case DECODER_SET_NORM:
		{
			int *iarg = arg;

			switch (*iarg) {

			case VIDEO_MODE_NTSC:
				saa7111_write(decoder, 0x08,
					      (decoder->
					       reg[0x08] & 0x3f) | 0x40);
				break;

			case VIDEO_MODE_PAL:
				saa7111_write(decoder, 0x08,
					      (decoder->
					       reg[0x08] & 0x3f) | 0x00);
				break;

			case VIDEO_MODE_AUTO:
				saa7111_write(decoder, 0x08,
					      (decoder->
					       reg[0x08] & 0x3f) | 0x80);
				break;

			default:
				return -EINVAL;

			}
			decoder->norm = *iarg;
		}
		break;

	case DECODER_SET_INPUT:
		{
			int *iarg = arg;

			if (*iarg < 0 || *iarg > 7) {
				return -EINVAL;
			}

			if (decoder->input != *iarg) {
				decoder->input = *iarg;
				/* select mode */
				saa7111_write(decoder, 0x02,
					      (decoder->
					       reg[0x02] & 0xf8) |
					      decoder->input);
				/* bypass chrominance trap for modes 4..7 */
				saa7111_write(decoder, 0x09,
					      (decoder->
					       reg[0x09] & 0x7f) |
					      ((decoder->input >
						3) ? 0x80 : 0));
			}
		}
		break;

	case DECODER_SET_OUTPUT:
		{
			int *iarg = arg;

			/* not much choice of outputs */
			if (*iarg != 0) {
				return -EINVAL;
			}
		}
		break;

	case DECODER_ENABLE_OUTPUT:
		{
			int *iarg = arg;
			int enable = (*iarg != 0);

			if (decoder->enable != enable) {
				decoder->enable = enable;

// RJ: If output should be disabled (for playing videos), we also need a open PLL.
//     The input is set to 0 (where no input source is connected), although this
//     is not necessary.
//
//     If output should be enabled, we have to reverse the above.

				if (decoder->enable) {
					saa7111_write(decoder, 0x02,
						      (decoder->
						       reg[0x02] & 0xf8) |
						      decoder->input);
					saa7111_write(decoder, 0x08,
						      (decoder->
						       reg[0x08] & 0xfb));
					saa7111_write(decoder, 0x11,
						      (decoder->
						       reg[0x11] & 0xf3) |
						      0x0c);
				} else {
					saa7111_write(decoder, 0x02,
						      (decoder->
						       reg[0x02] & 0xf8));
					saa7111_write(decoder, 0x08,
						      (decoder->
						       reg[0x08] & 0xfb) |
						      0x04);
					saa7111_write(decoder, 0x11,
						      (decoder->
						       reg[0x11] & 0xf3));
				}
			}
		}
		break;

	case DECODER_SET_PICTURE:
		{
			struct video_picture *pic = arg;

			if (decoder->bright != pic->brightness) {
				/* We want 0 to 255 we get 0-65535 */
				decoder->bright = pic->brightness;
				saa7111_write(decoder, 0x0a,
					      decoder->bright >> 8);
			}
			if (decoder->contrast != pic->contrast) {
				/* We want 0 to 127 we get 0-65535 */
				decoder->contrast = pic->contrast;
				saa7111_write(decoder, 0x0b,
					      decoder->contrast >> 9);
			}
			if (decoder->sat != pic->colour) {
				/* We want 0 to 127 we get 0-65535 */
				decoder->sat = pic->colour;
				saa7111_write(decoder, 0x0c,
					      decoder->sat >> 9);
			}