~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/media/video/saa7185.c

Version: ~ [ 2.2.5 ] ~ [ 2.4.1 ] ~ [ 2.4.9 ] ~ [ 2.6.17.10 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* 
  2    saa7185 - Philips SAA7185B video encoder driver version 0.0.3
  3 
  4    Copyright (C) 1998 Dave Perks <dperks@ibm.net>
  5 
  6    This program is free software; you can redistribute it and/or modify
  7    it under the terms of the GNU General Public License as published by
  8    the Free Software Foundation; either version 2 of the License, or
  9    (at your option) any later version.
 10 
 11    This program is distributed in the hope that it will be useful,
 12    but WITHOUT ANY WARRANTY; without even the implied warranty of
 13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14    GNU General Public License for more details.
 15 
 16    You should have received a copy of the GNU General Public License
 17    along with this program; if not, write to the Free Software
 18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 19  */
 20 
 21 #include <linux/module.h>
 22 #include <linux/delay.h>
 23 #include <linux/errno.h>
 24 #include <linux/fs.h>
 25 #include <linux/kernel.h>
 26 #include <linux/major.h>
 27 #include <linux/malloc.h>
 28 #include <linux/mm.h>
 29 #include <linux/pci.h>
 30 #include <linux/signal.h>
 31 #include <asm/io.h>
 32 #include <asm/pgtable.h>
 33 #include <asm/page.h>
 34 #include <linux/sched.h>
 35 #include <asm/segment.h>
 36 #include <linux/types.h>
 37 #include <linux/wrapper.h>
 38 
 39 #include <linux/videodev.h>
 40 #include <linux/version.h>
 41 #include <asm/uaccess.h>
 42 
 43 #include <linux/i2c-old.h>
 44 #include <linux/video_encoder.h>
 45 
 46 #define DEBUG(x)   x            /* Debug driver */
 47 
 48 /* ----------------------------------------------------------------------- */
 49 
 50 struct saa7185 {
 51         struct i2c_bus *bus;
 52         int addr;
 53         unsigned char reg[128];
 54 
 55         int norm;
 56         int enable;
 57         int bright;
 58         int contrast;
 59         int hue;
 60         int sat;
 61 };
 62 
 63 #define   I2C_SAA7185        0x88
 64 
 65 #define I2C_DELAY   10
 66 
 67 /* ----------------------------------------------------------------------- */
 68 
 69 static int saa7185_write(struct saa7185 *dev, unsigned char subaddr, unsigned char data)
 70 {
 71         int ack;
 72 
 73         LOCK_I2C_BUS(dev->bus);
 74 
 75         i2c_start(dev->bus);
 76         i2c_sendbyte(dev->bus, dev->addr, I2C_DELAY);
 77         i2c_sendbyte(dev->bus, subaddr, I2C_DELAY);
 78         ack = i2c_sendbyte(dev->bus, data, I2C_DELAY);
 79         dev->reg[subaddr] = data;
 80         i2c_stop(dev->bus);
 81         UNLOCK_I2C_BUS(dev->bus);
 82         return ack;
 83 }
 84 
 85 static int saa7185_write_block(struct saa7185 *dev, unsigned const char *data, unsigned int len)
 86 {
 87         int ack = 0;
 88         unsigned subaddr;
 89 
 90         while (len > 1) {
 91                 LOCK_I2C_BUS(dev->bus);
 92                 i2c_start(dev->bus);
 93                 i2c_sendbyte(dev->bus, dev->addr, I2C_DELAY);
 94                 ack = i2c_sendbyte(dev->bus, (subaddr = *data++), I2C_DELAY);
 95                 ack = i2c_sendbyte(dev->bus, (dev->reg[subaddr] = *data++), I2C_DELAY);
 96                 len -= 2;
 97                 while (len > 1 && *data == ++subaddr) {
 98                         data++;
 99                         ack = i2c_sendbyte(dev->bus, (dev->reg[subaddr] = *data++), I2C_DELAY);
100                         len -= 2;
101                 }
102                 i2c_stop(dev->bus);
103                 UNLOCK_I2C_BUS(dev->bus);
104         }
105         return ack;
106 }
107 
108 /* ----------------------------------------------------------------------- */
109 
110 static const unsigned char init_common[] =
111 {
112         0x3a, 0x0f,             /* CBENB=0, V656=0, VY2C=1, YUV2C=1, MY2C=1, MUV2C=1 */
113 
114         0x42, 0x6b,             /* OVLY0=107 */
115         0x43, 0x00,             /* OVLU0=0     white */
116         0x44, 0x00,             /* OVLV0=0   */
117         0x45, 0x22,             /* OVLY1=34  */
118         0x46, 0xac,             /* OVLU1=172   yellow */
119         0x47, 0x0e,             /* OVLV1=14  */
120         0x48, 0x03,             /* OVLY2=3   */
121         0x49, 0x1d,             /* OVLU2=29    cyan */
122         0x4a, 0xac,             /* OVLV2=172 */
123         0x4b, 0xf0,             /* OVLY3=240 */
124         0x4c, 0xc8,             /* OVLU3=200   green */
125         0x4d, 0xb9,             /* OVLV3=185 */
126         0x4e, 0xd4,             /* OVLY4=212 */
127         0x4f, 0x38,             /* OVLU4=56    magenta */
128         0x50, 0x47,             /* OVLV4=71  */
129         0x51, 0xc1,             /* OVLY5=193 */
130         0x52, 0xe3,             /* OVLU5=227   red */
131         0x53, 0x54,             /* OVLV5=84  */
132         0x54, 0xa3,             /* OVLY6=163 */
133         0x55, 0x54,             /* OVLU6=84    blue */
134         0x56, 0xf2,             /* OVLV6=242 */
135         0x57, 0x90,             /* OVLY7=144 */
136         0x58, 0x00,             /* OVLU7=0     black */
137         0x59, 0x00,             /* OVLV7=0   */
138 
139         0x5a, 0x00,             /* CHPS=0    */
140         0x5b, 0x76,             /* GAINU=118 */
141         0x5c, 0xa5,             /* GAINV=165 */
142         0x5d, 0x3c,             /* BLCKL=60  */
143         0x5e, 0x3a,             /* BLNNL=58  */
144         0x5f, 0x3a,             /* CCRS=0, BLNVB=58 */
145         0x60, 0x00,             /* NULL      */
146 
147 /* 0x61 - 0x66 set according to norm */
148 
149         0x67, 0x00,             /* 0 : caption 1st byte odd  field */
150         0x68, 0x00,             /* 0 : caption 2nd byte odd  field */
151         0x69, 0x00,             /* 0 : caption 1st byte even field */
152         0x6a, 0x00,             /* 0 : caption 2nd byte even field */
153 
154         0x6b, 0x91,             /* MODIN=2, PCREF=0, SCCLN=17 */
155         0x6c, 0x20,             /* SRCV1=0, TRCV2=1, ORCV1=0, PRCV1=0, CBLF=0, ORCV2=0, PRCV2=0 */
156         0x6d, 0x00,             /* SRCM1=0, CCEN=0 */
157 
158         0x6e, 0x0e,             /* HTRIG=0x00e, approx. centered, at least for PAL */
159         0x6f, 0x00,             /* HTRIG upper bits */
160         0x70, 0x20,             /* PHRES=0, SBLN=1, VTRIG=0 */
161 
162 /* The following should not be needed */
163 
164         0x71, 0x15,             /* BMRQ=0x115 */
165         0x72, 0x90,             /* EMRQ=0x690 */
166         0x73, 0x61,             /* EMRQ=0x690, BMRQ=0x115 */
167         0x74, 0x00,             /* NULL       */
168         0x75, 0x00,             /* NULL       */
169         0x76, 0x00,             /* NULL       */
170         0x77, 0x15,             /* BRCV=0x115 */
171         0x78, 0x90,             /* ERCV=0x690 */
172         0x79, 0x61,             /* ERCV=0x690, BRCV=0x115 */
173 
174 /* Field length controls */
175 
176         0x7a, 0x70,             /* FLC=0 */
177 
178 /* The following should not be needed if SBLN = 1 */
179 
180         0x7b, 0x16,             /* FAL=22 */
181         0x7c, 0x35,             /* LAL=244 */
182         0x7d, 0x20,             /* LAL=244, FAL=22 */
183 };
184 
185 static const unsigned char init_pal[] =
186 {
187         0x61, 0x1e,             /* FISE=0, PAL=1, SCBW=1, RTCE=1, YGS=1, INPI=0, DOWN=0 */
188         0x62, 0xc8,             /* DECTYP=1, BSTA=72 */
189         0x63, 0xcb,             /* FSC0 */
190         0x64, 0x8a,             /* FSC1 */
191         0x65, 0x09,             /* FSC2 */
192         0x66, 0x2a,             /* FSC3 */
193 };
194 
195 static const unsigned char init_ntsc[] =
196 {
197         0x61, 0x1d,             /* FISE=1, PAL=0, SCBW=1, RTCE=1, YGS=1, INPI=0, DOWN=0 */
198         0x62, 0xe6,             /* DECTYP=1, BSTA=102 */
199         0x63, 0x1f,             /* FSC0 */
200         0x64, 0x7c,             /* FSC1 */
201         0x65, 0xf0,             /* FSC2 */
202         0x66, 0x21,             /* FSC3 */
203 };
204 
205 static int saa7185_attach(struct i2c_device *device)
206 {
207         int i;
208         struct saa7185 *encoder;
209 
210         device->data = encoder = kmalloc(sizeof(struct saa7185), GFP_KERNEL);
211         if (encoder == NULL) {
212                 return -ENOMEM;
213         }
214         MOD_INC_USE_COUNT;
215 
216         memset(encoder, 0, sizeof(struct saa7185));
217         strcpy(device->name, "saa7185");
218         encoder->bus = device->bus;
219         encoder->addr = device->addr;
220         encoder->norm = VIDEO_MODE_NTSC;
221         encoder->enable = 1;
222 
223         i = saa7185_write_block(encoder, init_common, sizeof(init_common));
224         if (i >= 0) {
225                 i = saa7185_write_block(encoder, init_ntsc, sizeof(init_ntsc));
226         }
227         if (i < 0) {
228                 printk(KERN_ERR "%s_attach: init error %d\n", device->name, i);
229         }
230         return 0;
231 }
232 
233 
234 static int saa7185_detach(struct i2c_device *device)
235 {
236         kfree(device->data);
237         MOD_DEC_USE_COUNT;
238         return 0;
239 }
240 
241 static int saa7185_command(struct i2c_device *device, unsigned int cmd, void *arg)
242 {
243         struct saa7185 *encoder = device->data;
244 
245         switch (cmd) {
246 
247         case ENCODER_GET_CAPABILITIES:
248                 {
249                         struct video_encoder_capability *cap = arg;
250 
251                         cap->flags
252                             = VIDEO_ENCODER_PAL
253                             | VIDEO_ENCODER_NTSC
254                             | VIDEO_ENCODER_SECAM
255                             | VIDEO_ENCODER_CCIR;
256                         cap->inputs = 1;
257                         cap->outputs = 1;
258                 }
259                 break;
260 
261         case ENCODER_SET_NORM:
262                 {
263                         int *iarg = arg;
264 
265                         switch (*iarg) {
266 
267                         case VIDEO_MODE_NTSC:
268                                 saa7185_write_block(encoder, init_ntsc, sizeof(init_ntsc));
269                                 break;
270 
271                         case VIDEO_MODE_PAL:
272                                 saa7185_write_block(encoder, init_pal, sizeof(init_pal));
273                                 break;
274 
275                         case VIDEO_MODE_SECAM:
276                         default:
277                                 return -EINVAL;
278 
279                         }
280                         encoder->norm = *iarg;
281                 }
282                 break;
283 
284         case ENCODER_SET_INPUT:
285                 {
286                         int *iarg = arg;
287 
288 #if 0
289                         /* not much choice of inputs */
290                         if (*iarg != 0) {
291                                 return -EINVAL;
292                         }
293 #else
294                         /* RJ: *iarg = 0: input is from SA7111
295                            *iarg = 1: input is from ZR36060 */
296 
297                         switch (*iarg) {
298 
299                         case 0:
300                                 /* Switch RTCE to 1 */
301                                 saa7185_write(encoder, 0x61, (encoder->reg[0x61] & 0xf7) | 0x08);
302                                 break;
303 
304                         case 1:
305                                 /* Switch RTCE to 0 */
306                                 saa7185_write(encoder, 0x61, (encoder->reg[0x61] & 0xf7) | 0x00);
307                                 break;
308 
309                         default:
310                                 return -EINVAL;
311 
312                         }
313 #endif
314                 }
315                 break;
316 
317         case ENCODER_SET_OUTPUT:
318                 {
319                         int *iarg = arg;
320 
321                         /* not much choice of outputs */
322                         if (*iarg != 0) {
323                                 return -EINVAL;
324                         }
325                 }
326                 break;
327 
328         case ENCODER_ENABLE_OUTPUT:
329                 {
330                         int *iarg = arg;
331 
332                         encoder->enable = !!*iarg;
333                         saa7185_write(encoder, 0x61, (encoder->reg[0x61] & 0xbf) | (encoder->enable ? 0x00 : 0x40));
334                 }
335                 break;
336 
337         default:
338                 return -EINVAL;
339         }
340 
341         return 0;
342 }
343 
344 /* ----------------------------------------------------------------------- */
345 
346 struct i2c_driver i2c_driver_saa7185 =
347 {
348         "saa7185",              /* name */
349         I2C_DRIVERID_VIDEOENCODER,      /* ID */
350         I2C_SAA7185, I2C_SAA7185 + 1,
351 
352         saa7185_attach,
353         saa7185_detach,
354         saa7185_command
355 };
356 
357 EXPORT_NO_SYMBOLS;
358 
359 #ifdef MODULE
360 int init_module(void)
361 #else
362 int saa7185_init(void)
363 #endif
364 {
365         return i2c_register_driver(&i2c_driver_saa7185);
366 }
367 
368 
369 
370 #ifdef MODULE
371 
372 void cleanup_module(void)
373 {
374         i2c_unregister_driver(&i2c_driver_saa7185);
375 }
376 
377 #endif
378 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.