Commit 7e8b09ea authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

V4L/DVB (3276): Added new diagnositics macros, convert msp3400 to the new macros.


- Added new v4l_err, v4l_warn, v4l_info and v4l_dbg macros to
v4l2-common.h for use in v4l-dvb i2c drivers. This ensures
a unique prefix for each device instance.
- At a later stage these macros may be reimplemented using the
device-generic macros from device.h.
- Converted the msp3400 driver to the new macros.
Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@brturbo.com.br>
parent 53b0a1c6
...@@ -129,11 +129,11 @@ int msp_reset(struct i2c_client *client) ...@@ -129,11 +129,11 @@ int msp_reset(struct i2c_client *client)
{ client->addr, I2C_M_RD, 2, read }, { client->addr, I2C_M_RD, 2, read },
}; };
msp_dbg3("msp_reset\n"); v4l_dbg(3, client, "msp_reset\n");
if (i2c_transfer(client->adapter, &reset[0], 1) != 1 || if (i2c_transfer(client->adapter, &reset[0], 1) != 1 ||
i2c_transfer(client->adapter, &reset[1], 1) != 1 || i2c_transfer(client->adapter, &reset[1], 1) != 1 ||
i2c_transfer(client->adapter, test, 2) != 2) { i2c_transfer(client->adapter, test, 2) != 2) {
msp_err("chip reset failed\n"); v4l_err(client, "chip reset failed\n");
return -1; return -1;
} }
return 0; return 0;
...@@ -156,18 +156,18 @@ static int msp_read(struct i2c_client *client, int dev, int addr) ...@@ -156,18 +156,18 @@ static int msp_read(struct i2c_client *client, int dev, int addr)
for (err = 0; err < 3; err++) { for (err = 0; err < 3; err++) {
if (i2c_transfer(client->adapter, msgs, 2) == 2) if (i2c_transfer(client->adapter, msgs, 2) == 2)
break; break;
msp_warn("I/O error #%d (read 0x%02x/0x%02x)\n", err, v4l_warn(client, "I/O error #%d (read 0x%02x/0x%02x)\n", err,
dev, addr); dev, addr);
current->state = TASK_INTERRUPTIBLE; current->state = TASK_INTERRUPTIBLE;
schedule_timeout(msecs_to_jiffies(10)); schedule_timeout(msecs_to_jiffies(10));
} }
if (err == 3) { if (err == 3) {
msp_warn("giving up, resetting chip. Sound will go off, sorry folks :-|\n"); v4l_warn(client, "giving up, resetting chip. Sound will go off, sorry folks :-|\n");
msp_reset(client); msp_reset(client);
return -1; return -1;
} }
retval = read[0] << 8 | read[1]; retval = read[0] << 8 | read[1];
msp_dbg3("msp_read(0x%x, 0x%x): 0x%x\n", dev, addr, retval); v4l_dbg(3, client, "msp_read(0x%x, 0x%x): 0x%x\n", dev, addr, retval);
return retval; return retval;
} }
...@@ -192,17 +192,17 @@ static int msp_write(struct i2c_client *client, int dev, int addr, int val) ...@@ -192,17 +192,17 @@ static int msp_write(struct i2c_client *client, int dev, int addr, int val)
buffer[3] = val >> 8; buffer[3] = val >> 8;
buffer[4] = val & 0xff; buffer[4] = val & 0xff;
msp_dbg3("msp_write(0x%x, 0x%x, 0x%x)\n", dev, addr, val); v4l_dbg(3, client, "msp_write(0x%x, 0x%x, 0x%x)\n", dev, addr, val);
for (err = 0; err < 3; err++) { for (err = 0; err < 3; err++) {
if (i2c_master_send(client, buffer, 5) == 5) if (i2c_master_send(client, buffer, 5) == 5)
break; break;
msp_warn("I/O error #%d (write 0x%02x/0x%02x)\n", err, v4l_warn(client, "I/O error #%d (write 0x%02x/0x%02x)\n", err,
dev, addr); dev, addr);
current->state = TASK_INTERRUPTIBLE; current->state = TASK_INTERRUPTIBLE;
schedule_timeout(msecs_to_jiffies(10)); schedule_timeout(msecs_to_jiffies(10));
} }
if (err == 3) { if (err == 3) {
msp_warn("giving up, resetting chip. Sound will go off, sorry folks :-|\n"); v4l_warn(client, "giving up, resetting chip. Sound will go off, sorry folks :-|\n");
msp_reset(client); msp_reset(client);
return -1; return -1;
} }
...@@ -275,7 +275,7 @@ void msp_set_scart(struct i2c_client *client, int in, int out) ...@@ -275,7 +275,7 @@ void msp_set_scart(struct i2c_client *client, int in, int out)
} else } else
state->acb = 0xf60; /* Mute Input and SCART 1 Output */ state->acb = 0xf60; /* Mute Input and SCART 1 Output */
msp_dbg1("scart switch: %s => %d (ACB=0x%04x)\n", v4l_dbg(1, client, "scart switch: %s => %d (ACB=0x%04x)\n",
scart_names[in], out, state->acb); scart_names[in], out, state->acb);
msp_write_dsp(client, 0x13, state->acb); msp_write_dsp(client, 0x13, state->acb);
...@@ -285,7 +285,7 @@ void msp_set_scart(struct i2c_client *client, int in, int out) ...@@ -285,7 +285,7 @@ void msp_set_scart(struct i2c_client *client, int in, int out)
void msp_set_mute(struct i2c_client *client) void msp_set_mute(struct i2c_client *client)
{ {
msp_dbg1("mute audio\n"); v4l_dbg(1, client, "mute audio\n");
msp_write_dsp(client, 0x0000, 0); /* loudspeaker */ msp_write_dsp(client, 0x0000, 0); /* loudspeaker */
msp_write_dsp(client, 0x0006, 0); /* headphones */ msp_write_dsp(client, 0x0006, 0); /* headphones */
} }
...@@ -302,7 +302,7 @@ void msp_set_audio(struct i2c_client *client) ...@@ -302,7 +302,7 @@ void msp_set_audio(struct i2c_client *client)
bass = ((state->bass - 32768) * 0x60 / 65535) << 8; bass = ((state->bass - 32768) * 0x60 / 65535) << 8;
treble = ((state->treble - 32768) * 0x60 / 65535) << 8; treble = ((state->treble - 32768) * 0x60 / 65535) << 8;
msp_dbg1("mute=%s volume=%d balance=%d bass=%d treble=%d\n", v4l_dbg(1, client, "mute=%s volume=%d balance=%d bass=%d treble=%d\n",
state->muted ? "on" : "off", state->volume, state->balance, state->muted ? "on" : "off", state->volume, state->balance,
state->bass, state->treble); state->bass, state->treble);
...@@ -318,7 +318,7 @@ int msp_modus(struct i2c_client *client, int norm) ...@@ -318,7 +318,7 @@ int msp_modus(struct i2c_client *client, int norm)
{ {
switch (norm) { switch (norm) {
case VIDEO_MODE_PAL: case VIDEO_MODE_PAL:
msp_dbg1("video mode selected to PAL\n"); v4l_dbg(1, client, "video mode selected to PAL\n");
#if 1 #if 1
/* experimental: not sure this works with all chip versions */ /* experimental: not sure this works with all chip versions */
...@@ -328,16 +328,16 @@ int msp_modus(struct i2c_client *client, int norm) ...@@ -328,16 +328,16 @@ int msp_modus(struct i2c_client *client, int norm)
return 0x1003; return 0x1003;
#endif #endif
case VIDEO_MODE_NTSC: /* BTSC */ case VIDEO_MODE_NTSC: /* BTSC */
msp_dbg1("video mode selected to NTSC\n"); v4l_dbg(1, client, "video mode selected to NTSC\n");
return 0x2003; return 0x2003;
case VIDEO_MODE_SECAM: case VIDEO_MODE_SECAM:
msp_dbg1("video mode selected to SECAM\n"); v4l_dbg(1, client, "video mode selected to SECAM\n");
return 0x0003; return 0x0003;
case VIDEO_MODE_RADIO: case VIDEO_MODE_RADIO:
msp_dbg1("video mode selected to Radio\n"); v4l_dbg(1, client, "video mode selected to Radio\n");
return 0x0003; return 0x0003;
case VIDEO_MODE_AUTO: case VIDEO_MODE_AUTO:
msp_dbg1("video mode selected to Auto\n"); v4l_dbg(1, client, "video mode selected to Auto\n");
return 0x2003; return 0x2003;
default: default:
return 0x0003; return 0x0003;
...@@ -620,7 +620,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) ...@@ -620,7 +620,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
case AUDC_SET_RADIO: case AUDC_SET_RADIO:
state->norm = VIDEO_MODE_RADIO; state->norm = VIDEO_MODE_RADIO;
msp_dbg1("switching to radio mode\n"); v4l_dbg(1, client, "switching to radio mode\n");
state->watch_stereo = 0; state->watch_stereo = 0;
switch (state->opmode) { switch (state->opmode) {
case OPMODE_MANUAL: case OPMODE_MANUAL:
...@@ -875,7 +875,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) ...@@ -875,7 +875,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
if (a->index < 0 || a->index > 2) if (a->index < 0 || a->index > 2)
return -EINVAL; return -EINVAL;
msp_dbg1("Setting audio out on msp34xx to input %i\n", a->index); v4l_dbg(1, client, "Setting audio out on msp34xx to input %i\n", a->index);
msp_set_scart(client, state->in_scart, a->index + 1); msp_set_scart(client, state->in_scart, a->index + 1);
break; break;
...@@ -885,7 +885,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) ...@@ -885,7 +885,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
{ {
u32 *a = (u32 *)arg; u32 *a = (u32 *)arg;
msp_dbg1("Setting I2S speed to %d\n", *a); v4l_dbg(1, client, "Setting I2S speed to %d\n", *a);
switch (*a) { switch (*a) {
case 1024000: case 1024000:
...@@ -921,16 +921,16 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) ...@@ -921,16 +921,16 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
case VIDIOC_LOG_STATUS: case VIDIOC_LOG_STATUS:
msp_any_detect_stereo(client); msp_any_detect_stereo(client);
msp_info("%s rev1 = 0x%04x rev2 = 0x%04x\n", v4l_info(client, "%s rev1 = 0x%04x rev2 = 0x%04x\n",
client->name, state->rev1, state->rev2); client->name, state->rev1, state->rev2);
msp_info("Audio: volume %d balance %d bass %d treble %d%s\n", v4l_info(client, "Audio: volume %d balance %d bass %d treble %d%s\n",
state->volume, state->balance, state->volume, state->balance,
state->bass, state->treble, state->bass, state->treble,
state->muted ? " (muted)" : ""); state->muted ? " (muted)" : "");
msp_info("Mode: %s (%s%s)\n", msp_standard_mode_name(state->mode), v4l_info(client, "Mode: %s (%s%s)\n", msp_standard_mode_name(state->mode),
(state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono", (state->rxsubchans & V4L2_TUNER_SUB_STEREO) ? "stereo" : "mono",
(state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : ""); (state->rxsubchans & V4L2_TUNER_SUB_LANG2) ? ", dual" : "");
msp_info("ACB: 0x%04x\n", state->acb); v4l_info(client, "ACB: 0x%04x\n", state->acb);
break; break;
default: default:
...@@ -944,7 +944,7 @@ static int msp_suspend(struct device * dev, pm_message_t state) ...@@ -944,7 +944,7 @@ static int msp_suspend(struct device * dev, pm_message_t state)
{ {
struct i2c_client *client = container_of(dev, struct i2c_client, dev); struct i2c_client *client = container_of(dev, struct i2c_client, dev);
msp_dbg1("suspend\n"); v4l_dbg(1, client, "suspend\n");
msp_reset(client); msp_reset(client);
return 0; return 0;
} }
...@@ -953,7 +953,7 @@ static int msp_resume(struct device * dev) ...@@ -953,7 +953,7 @@ static int msp_resume(struct device * dev)
{ {
struct i2c_client *client = container_of(dev, struct i2c_client, dev); struct i2c_client *client = container_of(dev, struct i2c_client, dev);
msp_dbg1("resume\n"); v4l_dbg(1, client, "resume\n");
msp_wake_thread(client); msp_wake_thread(client);
return 0; return 0;
} }
...@@ -979,7 +979,7 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind) ...@@ -979,7 +979,7 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
snprintf(client->name, sizeof(client->name) - 1, "msp3400"); snprintf(client->name, sizeof(client->name) - 1, "msp3400");
if (msp_reset(client) == -1) { if (msp_reset(client) == -1) {
msp_dbg1("msp3400 not found\n"); v4l_dbg(1, client, "msp3400 not found\n");
kfree(client); kfree(client);
return -1; return -1;
} }
...@@ -1005,9 +1005,9 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind) ...@@ -1005,9 +1005,9 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
state->rev1 = msp_read_dsp(client, 0x1e); state->rev1 = msp_read_dsp(client, 0x1e);
if (state->rev1 != -1) if (state->rev1 != -1)
state->rev2 = msp_read_dsp(client, 0x1f); state->rev2 = msp_read_dsp(client, 0x1f);
msp_dbg1("rev1=0x%04x, rev2=0x%04x\n", state->rev1, state->rev2); v4l_dbg(1, client, "rev1=0x%04x, rev2=0x%04x\n", state->rev1, state->rev2);
if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) { if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) {
msp_dbg1("not an msp3400 (cannot read chip version)\n"); v4l_dbg(1, client, "not an msp3400 (cannot read chip version)\n");
kfree(state); kfree(state);
kfree(client); kfree(client);
return -1; return -1;
...@@ -1035,8 +1035,8 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind) ...@@ -1035,8 +1035,8 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
} }
/* hello world :-) */ /* hello world :-) */
msp_info("%s found @ 0x%x (%s)\n", client->name, address << 1, adapter->name); v4l_info(client, "%s found @ 0x%x (%s)\n", client->name, address << 1, adapter->name);
msp_info("%s ", client->name); v4l_info(client, "%s ", client->name);
if (HAVE_NICAM(state) && HAVE_RADIO(state)) if (HAVE_NICAM(state) && HAVE_RADIO(state))
printk("supports nicam and radio, "); printk("supports nicam and radio, ");
else if (HAVE_NICAM(state)) else if (HAVE_NICAM(state))
...@@ -1067,7 +1067,7 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind) ...@@ -1067,7 +1067,7 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
state->kthread = kthread_run(thread_func, client, "msp34xx"); state->kthread = kthread_run(thread_func, client, "msp34xx");
if (state->kthread == NULL) if (state->kthread == NULL)
msp_warn("kernel_thread() failed\n"); v4l_warn(client, "kernel_thread() failed\n");
msp_wake_thread(client); msp_wake_thread(client);
} }
......
This diff is collapsed.
...@@ -6,40 +6,6 @@ ...@@ -6,40 +6,6 @@
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
#define msp_err(fmt, arg...) \
printk(KERN_ERR "%s %d-%04x: " fmt, client->driver->driver.name, \
i2c_adapter_id(client->adapter), client->addr , ## arg)
#define msp_warn(fmt, arg...) \
printk(KERN_WARNING "%s %d-%04x: " fmt, client->driver->driver.name, \
i2c_adapter_id(client->adapter), client->addr , ## arg)
#define msp_info(fmt, arg...) \
printk(KERN_INFO "%s %d-%04x: " fmt, client->driver->driver.name, \
i2c_adapter_id(client->adapter), client->addr , ## arg)
/* level 1 debug. */
#define msp_dbg1(fmt, arg...) \
do { \
if (debug) \
printk(KERN_INFO "%s debug %d-%04x: " fmt, client->driver->driver.name, \
i2c_adapter_id(client->adapter), client->addr , ## arg); \
} while (0)
/* level 2 debug. */
#define msp_dbg2(fmt, arg...) \
do { \
if (debug >= 2) \
printk(KERN_INFO "%s debug %d-%04x: " fmt, client->driver->name, \
i2c_adapter_id(client->adapter), client->addr , ## arg); \
} while (0)
/* level 3 debug. Use with care. */
#define msp_dbg3(fmt, arg...) \
do { \
if (debug >= 16) \
printk(KERN_INFO "%s debug %d-%04x: " fmt, client->driver->name, \
i2c_adapter_id(client->adapter), client->addr , ## arg); \
} while (0)
struct msp_matrix { struct msp_matrix {
int input; int input;
int output; int output;
......
...@@ -26,6 +26,57 @@ ...@@ -26,6 +26,57 @@
#ifndef V4L2_COMMON_H_ #ifndef V4L2_COMMON_H_
#define V4L2_COMMON_H_ #define V4L2_COMMON_H_
/* v4l debugging and diagnostics */
/* Common printk constucts for v4l-i2c drivers. These macros create a unique
prefix consisting of the driver name, the adapter number and the i2c
address. */
#define v4l_printk(level, name, adapter, addr, fmt, arg...) \
printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg)
#define v4l_client_printk(level, client, fmt, arg...) \
v4l_printk(level, (client)->driver->driver.name, (client)->adapter, \
(client)->addr, fmt , ## arg)
#define v4l_err(client, fmt, arg...) \
v4l_client_printk(KERN_ERR, client, fmt , ## arg)
#define v4l_warn(client, fmt, arg...) \
v4l_client_printk(KERN_WARNING, client, fmt , ## arg)
#define v4l_info(client, fmt, arg...) \
v4l_client_printk(KERN_INFO, client, fmt , ## arg)
/* These three macros assume that the debug level is set with a module
parameter called 'debug'. */
#define v4l_dbg(level, client, fmt, arg...) \
do { \
if (debug >= (level)) \
v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \
} while (0)
/* Prints the ioctl in a human-readable format */
extern void v4l_printk_ioctl(unsigned int cmd);
/* Use this macro for non-I2C drivers. Pass the driver name as the first arg. */
#define v4l_print_ioctl(name, cmd) \
do { \
printk(KERN_DEBUG "%s: ", name); \
v4l_printk_ioctl(cmd); \
} while (0)
/* Use this macro in I2C drivers where 'client' is the struct i2c_client
pointer */
#define v4l_i2c_print_ioctl(client, cmd) \
do { \
v4l_client_printk(KERN_DEBUG, client, ""); \
v4l_printk_ioctl(cmd); \
} while (0)
/* ------------------------------------------------------------------------- */
/* Internal ioctls */
/* VIDIOC_INT_G_REGISTER and VIDIOC_INT_S_REGISTER */ /* VIDIOC_INT_G_REGISTER and VIDIOC_INT_S_REGISTER */
struct v4l2_register { struct v4l2_register {
u32 i2c_id; /* I2C driver ID of the I2C chip. 0 for the I2C adapter. */ u32 i2c_id; /* I2C driver ID of the I2C chip. 0 for the I2C adapter. */
...@@ -122,16 +173,4 @@ enum v4l2_chip_ident { ...@@ -122,16 +173,4 @@ enum v4l2_chip_ident {
If the frequency is not supported, then -EINVAL is returned. */ If the frequency is not supported, then -EINVAL is returned. */
#define VIDIOC_INT_I2S_CLOCK_FREQ _IOW ('d', 108, u32) #define VIDIOC_INT_I2S_CLOCK_FREQ _IOW ('d', 108, u32)
/* Prints used ioctl */
extern void v4l_printk_ioctl(unsigned int cmd);
#define v4l_print_ioctl(name,cmd) do {\
printk(KERN_DEBUG "%s: ", name); \
v4l_printk_ioctl(cmd); } while (0)
#define v4l_i2c_print_ioctl(client,cmd) do {\
printk(KERN_DEBUG "%s %d-%04x: ", (client)->driver->name, \
i2c_adapter_id((client)->adapter),(client)->addr); \
v4l_printk_ioctl(cmd); } while (0)
#endif /* V4L2_COMMON_H_ */ #endif /* V4L2_COMMON_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment