2 * m52790 i2c ivtv driver.
3 * Copyright (C) 2007 Hans Verkuil
5 * A/V source switching Mitsubishi M52790SP/FP
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/ioctl.h>
26 #include <asm/uaccess.h>
27 #include <linux/i2c.h>
28 #include <linux/i2c-id.h>
29 #include <linux/videodev.h>
30 #include <media/m52790.h>
31 #include <media/v4l2-common.h>
32 #include <media/v4l2-chip-ident.h>
33 #include <media/v4l2-i2c-drv.h>
35 MODULE_DESCRIPTION("i2c device driver for m52790 A/V switch");
36 MODULE_AUTHOR("Hans Verkuil");
37 MODULE_LICENSE("GPL");
45 /* ----------------------------------------------------------------------- */
47 static int m52790_write(struct i2c_client *client)
49 struct m52790_state *state = i2c_get_clientdata(client);
50 u8 sw1 = (state->input | state->output) & 0xff;
51 u8 sw2 = (state->input | state->output) >> 8;
53 return i2c_smbus_write_byte_data(client, sw1, sw2);
56 static int m52790_command(struct i2c_client *client, unsigned int cmd,
59 struct m52790_state *state = i2c_get_clientdata(client);
60 struct v4l2_routing *route = arg;
62 /* Note: audio and video are linked and cannot be switched separately.
63 So audio and video routing commands are identical for this chip.
64 In theory the video amplifier and audio modes could be handled
65 separately for the output, but that seems to be overkill right now.
66 The same holds for implementing an audio mute control, this is now
67 part of the audio output routing. The normal case is that another
68 chip takes care of the actual muting so making it part of the
69 output routing seems to be the right thing to do for now. */
71 case VIDIOC_INT_G_AUDIO_ROUTING:
72 case VIDIOC_INT_G_VIDEO_ROUTING:
73 route->input = state->input;
74 route->output = state->output;
77 case VIDIOC_INT_S_AUDIO_ROUTING:
78 case VIDIOC_INT_S_VIDEO_ROUTING:
79 state->input = route->input;
80 state->output = route->output;
84 #ifdef CONFIG_VIDEO_ADV_DEBUG
85 case VIDIOC_DBG_G_REGISTER:
86 case VIDIOC_DBG_S_REGISTER:
88 struct v4l2_register *reg = arg;
90 if (!v4l2_chip_match_i2c_client(client,
91 reg->match_type, reg->match_chip))
93 if (!capable(CAP_SYS_ADMIN))
97 if (cmd == VIDIOC_DBG_G_REGISTER)
98 reg->val = state->input | state->output;
100 state->input = reg->val & 0x0303;
101 state->output = reg->val & ~0x0303;
102 m52790_write(client);
108 case VIDIOC_G_CHIP_IDENT:
109 return v4l2_chip_ident_i2c_client(client, arg,
110 V4L2_IDENT_M52790, 0);
112 case VIDIOC_LOG_STATUS:
113 v4l_info(client, "Switch 1: %02x\n",
114 (state->input | state->output) & 0xff);
115 v4l_info(client, "Switch 2: %02x\n",
116 (state->input | state->output) >> 8);
125 /* ----------------------------------------------------------------------- */
127 /* i2c implementation */
129 static int m52790_probe(struct i2c_client *client,
130 const struct i2c_device_id *id)
132 struct m52790_state *state;
134 /* Check if the adapter supports the needed features */
135 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
138 snprintf(client->name, sizeof(client->name) - 1, "m52790");
140 v4l_info(client, "chip found @ 0x%x (%s)\n",
141 client->addr << 1, client->adapter->name);
143 state = kmalloc(sizeof(struct m52790_state), GFP_KERNEL);
147 state->input = M52790_IN_TUNER;
148 state->output = M52790_OUT_STEREO;
149 i2c_set_clientdata(client, state);
150 m52790_write(client);
154 static int m52790_remove(struct i2c_client *client)
156 kfree(i2c_get_clientdata(client));
160 /* ----------------------------------------------------------------------- */
162 static struct v4l2_i2c_driver_data v4l2_i2c_data = {
164 .driverid = I2C_DRIVERID_M52790,
165 .command = m52790_command,
166 .probe = m52790_probe,
167 .remove = m52790_remove,