Skip to content

Commit

Permalink
V4L/DVB (9091): gspca: Subdriver m5602 (ALi) added.
Browse files Browse the repository at this point in the history
This patch adds support for the ALi m5602 usb bridge and is based on
the gspca framework.
It contains code for communicating with 5 different sensors:
OmniVision OV9650, Pixel Plus PO1030, Samsung S5K83A, S5K4AA and
finally Micron MT9M111.

Signed-off-by: Erik Andren <erik.andren@gmail.com>
Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
[mchehab@redhat.com: fix m5602/Makefile]
[mchehab@redhat.com: extern debug caused conflicts. Renamed to m5602_debug]
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Erik Andren authored and Mauro Carvalho Chehab committed Oct 12, 2008
1 parent a3a5846 commit c109f81
Show file tree
Hide file tree
Showing 19 changed files with 5,441 additions and 0 deletions.
1 change: 1 addition & 0 deletions Documentation/video4linux/gspca.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The modules are:
xxxx vend:prod
----
spca501 0000:0000 MystFromOri Unknow Camera
m5602 0402:5602 ALi Video Camera Controller
spca501 040a:0002 Kodak DVC-325
spca500 040a:0300 Kodak EZ200
zc3xx 041e:041e Creative WebCam Live!
Expand Down
12 changes: 12 additions & 0 deletions Documentation/video4linux/m5602.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This document describes the ALi m5602 bridge connected
to the following supported sensors:
OmniVision OV9650,
Samsung s5k83a,
Samsung s5k4aa,
Micron mt9m111,
Pixel plus PO1030

This driver mimics the windows drivers, which have a braindead implementation sending bayer-encoded frames at VGA resolution.
In a perfect world we should be able to reprogram the m5602 and the connected sensor in hardware instead, supporting a range of resolutions and pixelformats

Anyway, have fun and please report any bugs to m560x-driver-devel@lists.sourceforge.net
3 changes: 3 additions & 0 deletions drivers/media/video/gspca/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ config USB_GSPCA

To compile this driver as modules, choose M here: the
modules will be called gspca_xxxx.

source "drivers/media/video/gspca/m5602/Kconfig"

3 changes: 3 additions & 0 deletions drivers/media/video/gspca/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ gspca_t613-objs := t613.o
gspca_tv8532-objs := tv8532.o
gspca_vc032x-objs := vc032x.o
gspca_zc3xx-objs := zc3xx.o

obj-$(CONFIG_USB_M5602) += m5602/

11 changes: 11 additions & 0 deletions drivers/media/video/gspca/m5602/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
config USB_M5602
tristate "USB ALi m5602 Webcam support"
depends on VIDEO_V4L2 && USB_GSPCA
help
Say Y here if you want support for cameras based on the
ALi m5602 connected to various image sensors.

See <file:Documentation/video4linux/m5602.txt> for more info.

To compile this driver as a module, choose M here: the
module will be called gspca-m5602.
11 changes: 11 additions & 0 deletions drivers/media/video/gspca/m5602/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
obj-$(CONFIG_USB_M5602) += gspca_m5602.o

gspca_m5602-objs := m5602_core.o \
m5602_ov9650.o \
m5602_mt9m111.o \
m5602_po1030.o \
m5602_s5k83a.o \
m5602_s5k4aa.o

EXTRA_CFLAGS += -Idrivers/media/video/gspca

180 changes: 180 additions & 0 deletions drivers/media/video/gspca/m5602/m5602_bridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
* USB Driver for ALi m5602 based webcams
*
* Copyright (C) 2008 Erik Andren
* Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
* Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
*
* Portions of code to USB interface and ALi driver software,
* Copyright (c) 2006 Willem Duinker
* v4l2 interface modeled after the V4L2 driver
* for SN9C10x PC Camera Controllers
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2.
*
*/

#ifndef M5602_BRIDGE_H_
#define M5602_BRIDGE_H_

#include "gspca.h"

#define MODULE_NAME "ALi m5602"

/*****************************************************************************/

#undef PDEBUG
#undef info
#undef err

#define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \
format "\n" , ## arg)
#define info(format, arg...) printk(KERN_INFO KBUILD_MODNAME ": " \
format "\n" , ## arg)

/* Debug parameters */
#define DBG_INIT 0x1
#define DBG_PROBE 0x2
#define DBG_V4L2 0x4
#define DBG_TRACE 0x8
#define DBG_DATA 0x10
#define DBG_V4L2_CID 0x20
#define DBG_GSPCA 0x40

#define PDEBUG(level, fmt, args...) \
do { \
if (m5602_debug & level) \
info("[%s:%d] " fmt, __func__, __LINE__ , \
## args); \
} while (0)

/*****************************************************************************/

#define M5602_XB_SENSOR_TYPE 0x00
#define M5602_XB_SENSOR_CTRL 0x01
#define M5602_XB_LINE_OF_FRAME_H 0x02
#define M5602_XB_LINE_OF_FRAME_L 0x03
#define M5602_XB_PIX_OF_LINE_H 0x04
#define M5602_XB_PIX_OF_LINE_L 0x05
#define M5602_XB_VSYNC_PARA 0x06
#define M5602_XB_HSYNC_PARA 0x07
#define M5602_XB_TEST_MODE_1 0x08
#define M5602_XB_TEST_MODE_2 0x09
#define M5602_XB_SIG_INI 0x0a
#define M5602_XB_DS_PARA 0x0e
#define M5602_XB_TRIG_PARA 0x0f
#define M5602_XB_CLK_PD 0x10
#define M5602_XB_MCU_CLK_CTRL 0x12
#define M5602_XB_MCU_CLK_DIV 0x13
#define M5602_XB_SEN_CLK_CTRL 0x14
#define M5602_XB_SEN_CLK_DIV 0x15
#define M5602_XB_AUD_CLK_CTRL 0x16
#define M5602_XB_AUD_CLK_DIV 0x17
#define M5602_XB_DEVCTR1 0x41
#define M5602_XB_EPSETR0 0x42
#define M5602_XB_EPAFCTR 0x47
#define M5602_XB_EPBFCTR 0x49
#define M5602_XB_EPEFCTR 0x4f
#define M5602_XB_TEST_REG 0x53
#define M5602_XB_ALT2SIZE 0x54
#define M5602_XB_ALT3SIZE 0x55
#define M5602_XB_OBSFRAME 0x56
#define M5602_XB_PWR_CTL 0x59
#define M5602_XB_ADC_CTRL 0x60
#define M5602_XB_ADC_DATA 0x61
#define M5602_XB_MISC_CTRL 0x62
#define M5602_XB_SNAPSHOT 0x63
#define M5602_XB_SCRATCH_1 0x64
#define M5602_XB_SCRATCH_2 0x65
#define M5602_XB_SCRATCH_3 0x66
#define M5602_XB_SCRATCH_4 0x67
#define M5602_XB_I2C_CTRL 0x68
#define M5602_XB_I2C_CLK_DIV 0x69
#define M5602_XB_I2C_DEV_ADDR 0x6a
#define M5602_XB_I2C_REG_ADDR 0x6b
#define M5602_XB_I2C_DATA 0x6c
#define M5602_XB_I2C_STATUS 0x6d
#define M5602_XB_GPIO_DAT_H 0x70
#define M5602_XB_GPIO_DAT_L 0x71
#define M5602_XB_GPIO_DIR_H 0x72
#define M5602_XB_GPIO_DIR_L 0x73
#define M5602_XB_GPIO_EN_H 0x74
#define M5602_XB_GPIO_EN_L 0x75
#define M5602_XB_GPIO_DAT 0x76
#define M5602_XB_GPIO_DIR 0x77
#define M5602_XB_MISC_CTL 0x70

#define I2C_BUSY 0x80

/*****************************************************************************/

/* Driver info */
#define DRIVER_AUTHOR "ALi m5602 Linux Driver Project"
#define DRIVER_DESC "ALi m5602 webcam driver"

#define M5602_ISOC_ENDPOINT_ADDR 0x81
#define M5602_INTR_ENDPOINT_ADDR 0x82

#define M5602_MAX_FRAMES 32
#define M5602_URBS 2
#define M5602_ISOC_PACKETS 14

#define M5602_URB_TIMEOUT msecs_to_jiffies(2 * M5602_ISOC_PACKETS)
#define M5602_URB_MSG_TIMEOUT 5000
#define M5602_FRAME_TIMEOUT 2

/*****************************************************************************/

/* A skeleton used for sending messages to the m5602 bridge */
static const unsigned char bridge_urb_skeleton[] = {
0x13, 0x00, 0x81, 0x00
};

/* A skeleton used for sending messages to the sensor */
static const unsigned char sensor_urb_skeleton[] = {
0x23, M5602_XB_GPIO_EN_H, 0x81, 0x06,
0x23, M5602_XB_MISC_CTRL, 0x81, 0x80,
0x13, M5602_XB_I2C_DEV_ADDR, 0x81, 0x00,
0x13, M5602_XB_I2C_REG_ADDR, 0x81, 0x00,
0x13, M5602_XB_I2C_DATA, 0x81, 0x00,
0x13, M5602_XB_I2C_CTRL, 0x81, 0x11
};

/* m5602 device descriptor, currently it just wraps the m5602_camera struct */
struct sd {
struct gspca_dev gspca_dev;

/* The name of the m5602 camera */
char *name;

/* A pointer to the currently connected sensor */
struct m5602_sensor *sensor;

/* The current frame's id, used to detect frame boundaries */
u8 frame_id;

/* The current frame count */
u32 frame_count;
};

int m5602_read_bridge(
struct sd *sd, u8 address, u8 *i2c_data);

int m5602_write_bridge(
struct sd *sd, u8 address, u8 i2c_data);

int m5602_configure(struct gspca_dev *gspca_dev,
const struct usb_device_id *id);

int m5602_init(struct gspca_dev *gspca_dev);

void m5602_start_transfer(struct gspca_dev *gspca_dev);

void m5602_stop_transfer(struct gspca_dev *gspca_dev);

void m5602_urb_complete(struct gspca_dev *gspca_dev, struct gspca_frame *frame,
__u8 *data, int len);

#endif
Loading

0 comments on commit c109f81

Please sign in to comment.