vt: vt_ioctl: fix VT_DISALLOCATE freeing in-use virtual console
[linux/fpc-iii.git] / drivers / media / i2c / m52790.c
bloba7a8f9a4e45cc52d79c321a2f79dca4d66c70a66
1 /*
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.
19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/slab.h>
22 #include <linux/ioctl.h>
23 #include <linux/uaccess.h>
24 #include <linux/i2c.h>
25 #include <linux/videodev2.h>
26 #include <media/i2c/m52790.h>
27 #include <media/v4l2-device.h>
29 MODULE_DESCRIPTION("i2c device driver for m52790 A/V switch");
30 MODULE_AUTHOR("Hans Verkuil");
31 MODULE_LICENSE("GPL");
34 struct m52790_state {
35 struct v4l2_subdev sd;
36 u16 input;
37 u16 output;
40 static inline struct m52790_state *to_state(struct v4l2_subdev *sd)
42 return container_of(sd, struct m52790_state, sd);
45 /* ----------------------------------------------------------------------- */
47 static int m52790_write(struct v4l2_subdev *sd)
49 struct m52790_state *state = to_state(sd);
50 struct i2c_client *client = v4l2_get_subdevdata(sd);
52 u8 sw1 = (state->input | state->output) & 0xff;
53 u8 sw2 = (state->input | state->output) >> 8;
55 return i2c_smbus_write_byte_data(client, sw1, sw2);
58 /* Note: audio and video are linked and cannot be switched separately.
59 So audio and video routing commands are identical for this chip.
60 In theory the video amplifier and audio modes could be handled
61 separately for the output, but that seems to be overkill right now.
62 The same holds for implementing an audio mute control, this is now
63 part of the audio output routing. The normal case is that another
64 chip takes care of the actual muting so making it part of the
65 output routing seems to be the right thing to do for now. */
66 static int m52790_s_routing(struct v4l2_subdev *sd,
67 u32 input, u32 output, u32 config)
69 struct m52790_state *state = to_state(sd);
71 state->input = input;
72 state->output = output;
73 m52790_write(sd);
74 return 0;
77 #ifdef CONFIG_VIDEO_ADV_DEBUG
78 static int m52790_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
80 struct m52790_state *state = to_state(sd);
82 if (reg->reg != 0)
83 return -EINVAL;
84 reg->size = 1;
85 reg->val = state->input | state->output;
86 return 0;
89 static int m52790_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
91 struct m52790_state *state = to_state(sd);
93 if (reg->reg != 0)
94 return -EINVAL;
95 state->input = reg->val & 0x0303;
96 state->output = reg->val & ~0x0303;
97 m52790_write(sd);
98 return 0;
100 #endif
102 static int m52790_log_status(struct v4l2_subdev *sd)
104 struct m52790_state *state = to_state(sd);
106 v4l2_info(sd, "Switch 1: %02x\n",
107 (state->input | state->output) & 0xff);
108 v4l2_info(sd, "Switch 2: %02x\n",
109 (state->input | state->output) >> 8);
110 return 0;
113 /* ----------------------------------------------------------------------- */
115 static const struct v4l2_subdev_core_ops m52790_core_ops = {
116 .log_status = m52790_log_status,
117 #ifdef CONFIG_VIDEO_ADV_DEBUG
118 .g_register = m52790_g_register,
119 .s_register = m52790_s_register,
120 #endif
123 static const struct v4l2_subdev_audio_ops m52790_audio_ops = {
124 .s_routing = m52790_s_routing,
127 static const struct v4l2_subdev_video_ops m52790_video_ops = {
128 .s_routing = m52790_s_routing,
131 static const struct v4l2_subdev_ops m52790_ops = {
132 .core = &m52790_core_ops,
133 .audio = &m52790_audio_ops,
134 .video = &m52790_video_ops,
137 /* ----------------------------------------------------------------------- */
139 /* i2c implementation */
141 static int m52790_probe(struct i2c_client *client,
142 const struct i2c_device_id *id)
144 struct m52790_state *state;
145 struct v4l2_subdev *sd;
147 /* Check if the adapter supports the needed features */
148 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
149 return -EIO;
151 v4l_info(client, "chip found @ 0x%x (%s)\n",
152 client->addr << 1, client->adapter->name);
154 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
155 if (state == NULL)
156 return -ENOMEM;
158 sd = &state->sd;
159 v4l2_i2c_subdev_init(sd, client, &m52790_ops);
160 state->input = M52790_IN_TUNER;
161 state->output = M52790_OUT_STEREO;
162 m52790_write(sd);
163 return 0;
166 static int m52790_remove(struct i2c_client *client)
168 struct v4l2_subdev *sd = i2c_get_clientdata(client);
170 v4l2_device_unregister_subdev(sd);
171 return 0;
174 /* ----------------------------------------------------------------------- */
176 static const struct i2c_device_id m52790_id[] = {
177 { "m52790", 0 },
180 MODULE_DEVICE_TABLE(i2c, m52790_id);
182 static struct i2c_driver m52790_driver = {
183 .driver = {
184 .name = "m52790",
186 .probe = m52790_probe,
187 .remove = m52790_remove,
188 .id_table = m52790_id,
191 module_i2c_driver(m52790_driver);