aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/upd64083.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/upd64083.c')
-rw-r--r--drivers/media/video/upd64083.c166
1 files changed, 97 insertions, 69 deletions
diff --git a/drivers/media/video/upd64083.c b/drivers/media/video/upd64083.c
index 9521ce004dcc..58412cb9c01a 100644
--- a/drivers/media/video/upd64083.c
+++ b/drivers/media/video/upd64083.c
@@ -26,7 +26,7 @@
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29#include <media/v4l2-common.h> 29#include <media/v4l2-device.h>
30#include <media/v4l2-chip-ident.h> 30#include <media/v4l2-chip-ident.h>
31#include <media/v4l2-i2c-drv.h> 31#include <media/v4l2-i2c-drv.h>
32#include <media/upd64083.h> 32#include <media/upd64083.h>
@@ -51,11 +51,17 @@ enum {
51}; 51};
52 52
53struct upd64083_state { 53struct upd64083_state {
54 struct v4l2_subdev sd;
54 u8 mode; 55 u8 mode;
55 u8 ext_y_adc; 56 u8 ext_y_adc;
56 u8 regs[TOT_REGS]; 57 u8 regs[TOT_REGS];
57}; 58};
58 59
60static inline struct upd64083_state *to_state(struct v4l2_subdev *sd)
61{
62 return container_of(sd, struct upd64083_state, sd);
63}
64
59/* Initial values when used in combination with the 65/* Initial values when used in combination with the
60 NEC upd64031a ghost reduction chip. */ 66 NEC upd64031a ghost reduction chip. */
61static u8 upd64083_init[] = { 67static u8 upd64083_init[] = {
@@ -68,34 +74,24 @@ static u8 upd64083_init[] = {
68 74
69/* ------------------------------------------------------------------------ */ 75/* ------------------------------------------------------------------------ */
70 76
71static void upd64083_log_status(struct i2c_client *client) 77static void upd64083_write(struct v4l2_subdev *sd, u8 reg, u8 val)
72{
73 u8 buf[7];
74
75 i2c_master_recv(client, buf, 7);
76 v4l_info(client, "Status: SA00=%02x SA01=%02x SA02=%02x SA03=%02x "
77 "SA04=%02x SA05=%02x SA06=%02x\n",
78 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
79}
80
81/* ------------------------------------------------------------------------ */
82
83static void upd64083_write(struct i2c_client *client, u8 reg, u8 val)
84{ 78{
79 struct i2c_client *client = v4l2_get_subdevdata(sd);
85 u8 buf[2]; 80 u8 buf[2];
86 81
87 buf[0] = reg; 82 buf[0] = reg;
88 buf[1] = val; 83 buf[1] = val;
89 v4l_dbg(1, debug, client, "write reg: %02x val: %02x\n", reg, val); 84 v4l2_dbg(1, debug, sd, "write reg: %02x val: %02x\n", reg, val);
90 if (i2c_master_send(client, buf, 2) != 2) 85 if (i2c_master_send(client, buf, 2) != 2)
91 v4l_err(client, "I/O error write 0x%02x/0x%02x\n", reg, val); 86 v4l2_err(sd, "I/O error write 0x%02x/0x%02x\n", reg, val);
92} 87}
93 88
94/* ------------------------------------------------------------------------ */ 89/* ------------------------------------------------------------------------ */
95 90
96#ifdef CONFIG_VIDEO_ADV_DEBUG 91#ifdef CONFIG_VIDEO_ADV_DEBUG
97static u8 upd64083_read(struct i2c_client *client, u8 reg) 92static u8 upd64083_read(struct v4l2_subdev *sd, u8 reg)
98{ 93{
94 struct i2c_client *client = v4l2_get_subdevdata(sd);
99 u8 buf[7]; 95 u8 buf[7];
100 96
101 if (reg >= sizeof(buf)) 97 if (reg >= sizeof(buf))
@@ -107,67 +103,94 @@ static u8 upd64083_read(struct i2c_client *client, u8 reg)
107 103
108/* ------------------------------------------------------------------------ */ 104/* ------------------------------------------------------------------------ */
109 105
110static int upd64083_command(struct i2c_client *client, unsigned cmd, void *arg) 106static int upd64083_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
111{ 107{
112 struct upd64083_state *state = i2c_get_clientdata(client); 108 struct upd64083_state *state = to_state(sd);
113 struct v4l2_routing *route = arg; 109 u8 r00, r02;
114 110
115 switch (cmd) { 111 if (route->input > 7 || (route->input & 6) == 6)
116 case VIDIOC_INT_G_VIDEO_ROUTING: 112 return -EINVAL;
117 route->input = (state->mode >> 6) | (state->ext_y_adc >> 3); 113 state->mode = (route->input & 3) << 6;
118 route->output = 0; 114 state->ext_y_adc = (route->input & UPD64083_EXT_Y_ADC) << 3;
119 break; 115 r00 = (state->regs[R00] & ~(3 << 6)) | state->mode;
120 116 r02 = (state->regs[R02] & ~(1 << 5)) | state->ext_y_adc;
121 case VIDIOC_INT_S_VIDEO_ROUTING: 117 upd64083_write(sd, R00, r00);
122 { 118 upd64083_write(sd, R02, r02);
123 u8 r00, r02; 119 return 0;
124 120}
125 if (route->input > 7 || (route->input & 6) == 6)
126 return -EINVAL;
127 state->mode = (route->input & 3) << 6;
128 state->ext_y_adc = (route->input & UPD64083_EXT_Y_ADC) << 3;
129 r00 = (state->regs[R00] & ~(3 << 6)) | state->mode;
130 r02 = (state->regs[R02] & ~(1 << 5)) | state->ext_y_adc;
131 upd64083_write(client, R00, r00);
132 upd64083_write(client, R02, r02);
133 break;
134 }
135
136 case VIDIOC_LOG_STATUS:
137 upd64083_log_status(client);
138 break;
139 121
140#ifdef CONFIG_VIDEO_ADV_DEBUG 122#ifdef CONFIG_VIDEO_ADV_DEBUG
141 case VIDIOC_DBG_G_REGISTER: 123static int upd64083_g_register(struct v4l2_subdev *sd, struct v4l2_register *reg)
142 case VIDIOC_DBG_S_REGISTER: 124{
143 { 125 struct i2c_client *client = v4l2_get_subdevdata(sd);
144 struct v4l2_register *reg = arg; 126
127 if (!v4l2_chip_match_i2c_client(client,
128 reg->match_type, reg->match_chip))
129 return -EINVAL;
130 if (!capable(CAP_SYS_ADMIN))
131 return -EPERM;
132 reg->val = upd64083_read(sd, reg->reg & 0xff);
133 return 0;
134}
145 135
146 if (!v4l2_chip_match_i2c_client(client, 136static int upd64083_s_register(struct v4l2_subdev *sd, struct v4l2_register *reg)
137{
138 struct i2c_client *client = v4l2_get_subdevdata(sd);
139
140 if (!v4l2_chip_match_i2c_client(client,
147 reg->match_type, reg->match_chip)) 141 reg->match_type, reg->match_chip))
148 return -EINVAL; 142 return -EINVAL;
149 if (!capable(CAP_SYS_ADMIN)) 143 if (!capable(CAP_SYS_ADMIN))
150 return -EPERM; 144 return -EPERM;
151 if (cmd == VIDIOC_DBG_G_REGISTER) { 145 upd64083_write(sd, reg->reg & 0xff, reg->val & 0xff);
152 reg->val = upd64083_read(client, reg->reg & 0xff); 146 return 0;
153 break; 147}
154 }
155 upd64083_write(client, reg->reg & 0xff, reg->val & 0xff);
156 break;
157 }
158#endif 148#endif
159 149
160 case VIDIOC_G_CHIP_IDENT: 150static int upd64083_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_chip_ident *chip)
161 return v4l2_chip_ident_i2c_client(client, arg, 151{
162 V4L2_IDENT_UPD64083, 0); 152 struct i2c_client *client = v4l2_get_subdevdata(sd);
153
154 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_UPD64083, 0);
155}
163 156
164 default: 157static int upd64083_log_status(struct v4l2_subdev *sd)
165 break; 158{
166 } 159 struct i2c_client *client = v4l2_get_subdevdata(sd);
160 u8 buf[7];
167 161
162 i2c_master_recv(client, buf, 7);
163 v4l2_info(sd, "Status: SA00=%02x SA01=%02x SA02=%02x SA03=%02x "
164 "SA04=%02x SA05=%02x SA06=%02x\n",
165 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
168 return 0; 166 return 0;
169} 167}
170 168
169static int upd64083_command(struct i2c_client *client, unsigned cmd, void *arg)
170{
171 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
172}
173
174/* ----------------------------------------------------------------------- */
175
176static const struct v4l2_subdev_core_ops upd64083_core_ops = {
177 .log_status = upd64083_log_status,
178 .g_chip_ident = upd64083_g_chip_ident,
179#ifdef CONFIG_VIDEO_ADV_DEBUG
180 .g_register = upd64083_g_register,
181 .s_register = upd64083_s_register,
182#endif
183};
184
185static const struct v4l2_subdev_video_ops upd64083_video_ops = {
186 .s_routing = upd64083_s_routing,
187};
188
189static const struct v4l2_subdev_ops upd64083_ops = {
190 .core = &upd64083_core_ops,
191 .video = &upd64083_video_ops,
192};
193
171/* ------------------------------------------------------------------------ */ 194/* ------------------------------------------------------------------------ */
172 195
173/* i2c implementation */ 196/* i2c implementation */
@@ -176,6 +199,7 @@ static int upd64083_probe(struct i2c_client *client,
176 const struct i2c_device_id *id) 199 const struct i2c_device_id *id)
177{ 200{
178 struct upd64083_state *state; 201 struct upd64083_state *state;
202 struct v4l2_subdev *sd;
179 int i; 203 int i;
180 204
181 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 205 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
@@ -187,19 +211,23 @@ static int upd64083_probe(struct i2c_client *client,
187 state = kmalloc(sizeof(struct upd64083_state), GFP_KERNEL); 211 state = kmalloc(sizeof(struct upd64083_state), GFP_KERNEL);
188 if (state == NULL) 212 if (state == NULL)
189 return -ENOMEM; 213 return -ENOMEM;
190 i2c_set_clientdata(client, state); 214 sd = &state->sd;
215 v4l2_i2c_subdev_init(sd, client, &upd64083_ops);
191 /* Initially assume that a ghost reduction chip is present */ 216 /* Initially assume that a ghost reduction chip is present */
192 state->mode = 0; /* YCS mode */ 217 state->mode = 0; /* YCS mode */
193 state->ext_y_adc = (1 << 5); 218 state->ext_y_adc = (1 << 5);
194 memcpy(state->regs, upd64083_init, TOT_REGS); 219 memcpy(state->regs, upd64083_init, TOT_REGS);
195 for (i = 0; i < TOT_REGS; i++) 220 for (i = 0; i < TOT_REGS; i++)
196 upd64083_write(client, i, state->regs[i]); 221 upd64083_write(sd, i, state->regs[i]);
197 return 0; 222 return 0;
198} 223}
199 224
200static int upd64083_remove(struct i2c_client *client) 225static int upd64083_remove(struct i2c_client *client)
201{ 226{
202 kfree(i2c_get_clientdata(client)); 227 struct v4l2_subdev *sd = i2c_get_clientdata(client);
228
229 v4l2_device_unregister_subdev(sd);
230 kfree(to_state(sd));
203 return 0; 231 return 0;
204} 232}
205 233