Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Media Vision Pro Movie Studio |
| 3 | * or |
| 4 | * "all you need is an I2C bus some RAM and a prayer" |
| 5 | * |
| 6 | * This draws heavily on code |
| 7 | * |
| 8 | * (c) Wolfgang Koehler, wolf@first.gmd.de, Dec. 1994 |
| 9 | * Kiefernring 15 |
| 10 | * 14478 Potsdam, Germany |
| 11 | * |
| 12 | * Most of this code is directly derived from his userspace driver. |
Alan Cox | d9b0144 | 2008-10-27 15:13:47 -0300 | [diff] [blame] | 13 | * His driver works so send any reports to alan@lxorguk.ukuu.org.uk |
| 14 | * unless the userspace driver also doesn't work for you... |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 15 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * Changes: |
| 17 | * 08/07/2003 Daniele Bellucci <bellucda@tiscali.it> |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 18 | * - pms_capture: report back -EFAULT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/slab.h> |
| 27 | #include <linux/mm.h> |
| 28 | #include <linux/ioport.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/videodev.h> |
Mauro Carvalho Chehab | 5e87efa | 2006-06-05 10:26:32 -0300 | [diff] [blame] | 32 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 33 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 34 | #include <media/v4l2-device.h> |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 35 | #include <linux/mutex.h> |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <asm/uaccess.h> |
| 38 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 39 | MODULE_LICENSE("GPL"); |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | #define MOTOROLA 1 |
| 43 | #define PHILIPS2 2 |
| 44 | #define PHILIPS1 3 |
| 45 | #define MVVMEMORYWIDTH 0x40 /* 512 bytes */ |
| 46 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 47 | struct i2c_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | u8 slave; |
| 49 | u8 sub; |
| 50 | u8 data; |
| 51 | u8 hits; |
| 52 | }; |
| 53 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 54 | struct pms { |
| 55 | struct v4l2_device v4l2_dev; |
| 56 | struct video_device vdev; |
| 57 | struct video_picture picture; |
| 58 | int height; |
| 59 | int width; |
| 60 | unsigned long in_use; |
| 61 | struct mutex lock; |
| 62 | int i2c_count; |
| 63 | struct i2c_info i2cinfo[64]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 65 | int decoder; |
| 66 | int standard; /* 0 - auto 1 - ntsc 2 - pal 3 - secam */ |
| 67 | int io; |
| 68 | int data; |
| 69 | void __iomem *mem; |
| 70 | }; |
| 71 | |
| 72 | static struct pms pms_card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * I/O ports and Shared Memory |
| 76 | */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 77 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 78 | static int io_port = 0x250; |
| 79 | module_param(io_port, int, 0); |
| 80 | |
| 81 | static int mem_base = 0xc8000; |
| 82 | module_param(mem_base, int, 0); |
| 83 | |
| 84 | static int video_nr = -1; |
| 85 | module_param(video_nr, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 87 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 88 | static inline void mvv_write(struct pms *dev, u8 index, u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 90 | outw(index | (value << 8), dev->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 93 | static inline u8 mvv_read(struct pms *dev, u8 index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 95 | outb(index, dev->io); |
| 96 | return inb(dev->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 99 | static int pms_i2c_stat(struct pms *dev, u8 slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 101 | int counter = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | int i; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 103 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 104 | outb(0x28, dev->io); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 105 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 106 | while ((inb(dev->data) & 0x01) == 0) |
| 107 | if (counter++ == 256) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | break; |
| 109 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 110 | while ((inb(dev->data) & 0x01) != 0) |
| 111 | if (counter++ == 256) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | break; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 113 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 114 | outb(slave, dev->io); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 115 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 116 | counter = 0; |
| 117 | while ((inb(dev->data) & 0x01) == 0) |
| 118 | if (counter++ == 256) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | break; |
| 120 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 121 | while ((inb(dev->data) & 0x01) != 0) |
| 122 | if (counter++ == 256) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | break; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 124 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 125 | for (i = 0; i < 12; i++) { |
| 126 | char st = inb(dev->data); |
| 127 | |
| 128 | if ((st & 2) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | return -1; |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 130 | if ((st & 1) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | break; |
| 132 | } |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 133 | outb(0x29, dev->io); |
| 134 | return inb(dev->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 137 | static int pms_i2c_write(struct pms *dev, u16 slave, u16 sub, u16 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 139 | int skip = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | int count; |
| 141 | int i; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 142 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 143 | for (i = 0; i < dev->i2c_count; i++) { |
| 144 | if ((dev->i2cinfo[i].slave == slave) && |
| 145 | (dev->i2cinfo[i].sub == sub)) { |
| 146 | if (dev->i2cinfo[i].data == data) |
| 147 | skip = 1; |
| 148 | dev->i2cinfo[i].data = data; |
| 149 | i = dev->i2c_count + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 152 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 153 | if (i == dev->i2c_count && dev->i2c_count < 64) { |
| 154 | dev->i2cinfo[dev->i2c_count].slave = slave; |
| 155 | dev->i2cinfo[dev->i2c_count].sub = sub; |
| 156 | dev->i2cinfo[dev->i2c_count].data = data; |
| 157 | dev->i2c_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 159 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 160 | if (skip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | return 0; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 162 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 163 | mvv_write(dev, 0x29, sub); |
| 164 | mvv_write(dev, 0x2A, data); |
| 165 | mvv_write(dev, 0x28, slave); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 166 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 167 | outb(0x28, dev->io); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 168 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 169 | count = 0; |
| 170 | while ((inb(dev->data) & 1) == 0) |
| 171 | if (count > 255) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | break; |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 173 | while ((inb(dev->data) & 1) != 0) |
| 174 | if (count > 255) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | break; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 176 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 177 | count = inb(dev->data); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 178 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 179 | if (count & 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | return -1; |
| 181 | return count; |
| 182 | } |
| 183 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 184 | static int pms_i2c_read(struct pms *dev, int slave, int sub) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 186 | int i; |
| 187 | |
| 188 | for (i = 0; i < dev->i2c_count; i++) { |
| 189 | if (dev->i2cinfo[i].slave == slave && dev->i2cinfo[i].sub == sub) |
| 190 | return dev->i2cinfo[i].data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 196 | static void pms_i2c_andor(struct pms *dev, int slave, int sub, int and, int or) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 198 | u8 tmp; |
| 199 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 200 | tmp = pms_i2c_read(dev, slave, sub); |
| 201 | tmp = (tmp & and) | or; |
| 202 | pms_i2c_write(dev, slave, sub, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /* |
| 206 | * Control functions |
| 207 | */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 210 | static void pms_videosource(struct pms *dev, short source) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 212 | mvv_write(dev, 0x2E, source ? 0x31 : 0x30); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 215 | static void pms_hue(struct pms *dev, short hue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 217 | switch (dev->decoder) { |
| 218 | case MOTOROLA: |
| 219 | pms_i2c_write(dev, 0x8a, 0x00, hue); |
| 220 | break; |
| 221 | case PHILIPS2: |
| 222 | pms_i2c_write(dev, 0x8a, 0x07, hue); |
| 223 | break; |
| 224 | case PHILIPS1: |
| 225 | pms_i2c_write(dev, 0x42, 0x07, hue); |
| 226 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 230 | static void pms_colour(struct pms *dev, short colour) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 232 | switch (dev->decoder) { |
| 233 | case MOTOROLA: |
| 234 | pms_i2c_write(dev, 0x8a, 0x00, colour); |
| 235 | break; |
| 236 | case PHILIPS1: |
| 237 | pms_i2c_write(dev, 0x42, 0x12, colour); |
| 238 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 241 | |
| 242 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 243 | static void pms_contrast(struct pms *dev, short contrast) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 245 | switch (dev->decoder) { |
| 246 | case MOTOROLA: |
| 247 | pms_i2c_write(dev, 0x8a, 0x00, contrast); |
| 248 | break; |
| 249 | case PHILIPS1: |
| 250 | pms_i2c_write(dev, 0x42, 0x13, contrast); |
| 251 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 255 | static void pms_brightness(struct pms *dev, short brightness) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 257 | switch (dev->decoder) { |
| 258 | case MOTOROLA: |
| 259 | pms_i2c_write(dev, 0x8a, 0x00, brightness); |
| 260 | pms_i2c_write(dev, 0x8a, 0x00, brightness); |
| 261 | pms_i2c_write(dev, 0x8a, 0x00, brightness); |
| 262 | break; |
| 263 | case PHILIPS1: |
| 264 | pms_i2c_write(dev, 0x42, 0x19, brightness); |
| 265 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
| 269 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 270 | static void pms_format(struct pms *dev, short format) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { |
| 272 | int target; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 273 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 274 | dev->standard = format; |
| 275 | |
| 276 | if (dev->decoder == PHILIPS1) |
| 277 | target = 0x42; |
| 278 | else if (dev->decoder == PHILIPS2) |
| 279 | target = 0x8a; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | else |
| 281 | return; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 282 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 283 | switch (format) { |
| 284 | case 0: /* Auto */ |
| 285 | pms_i2c_andor(dev, target, 0x0d, 0xfe, 0x00); |
| 286 | pms_i2c_andor(dev, target, 0x0f, 0x3f, 0x80); |
| 287 | break; |
| 288 | case 1: /* NTSC */ |
| 289 | pms_i2c_andor(dev, target, 0x0d, 0xfe, 0x00); |
| 290 | pms_i2c_andor(dev, target, 0x0f, 0x3f, 0x40); |
| 291 | break; |
| 292 | case 2: /* PAL */ |
| 293 | pms_i2c_andor(dev, target, 0x0d, 0xfe, 0x00); |
| 294 | pms_i2c_andor(dev, target, 0x0f, 0x3f, 0x00); |
| 295 | break; |
| 296 | case 3: /* SECAM */ |
| 297 | pms_i2c_andor(dev, target, 0x0d, 0xfe, 0x01); |
| 298 | pms_i2c_andor(dev, target, 0x0f, 0x3f, 0x00); |
| 299 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
| 303 | #ifdef FOR_FUTURE_EXPANSION |
| 304 | |
| 305 | /* |
| 306 | * These features of the PMS card are not currently exposes. They |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 307 | * could become a private v4l ioctl for PMSCONFIG or somesuch if |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | * people need it. We also don't yet use the PMS interrupt. |
| 309 | */ |
| 310 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 311 | static void pms_hstart(struct pms *dev, short start) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 313 | switch (dev->decoder) { |
| 314 | case PHILIPS1: |
| 315 | pms_i2c_write(dev, 0x8a, 0x05, start); |
| 316 | pms_i2c_write(dev, 0x8a, 0x18, start); |
| 317 | break; |
| 318 | case PHILIPS2: |
| 319 | pms_i2c_write(dev, 0x42, 0x05, start); |
| 320 | pms_i2c_write(dev, 0x42, 0x18, start); |
| 321 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | /* |
| 326 | * Bandpass filters |
| 327 | */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 328 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 329 | static void pms_bandpass(struct pms *dev, short pass) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 331 | if (dev->decoder == PHILIPS2) |
| 332 | pms_i2c_andor(dev, 0x8a, 0x06, 0xcf, (pass & 0x03) << 4); |
| 333 | else if (dev->decoder == PHILIPS1) |
| 334 | pms_i2c_andor(dev, 0x42, 0x06, 0xcf, (pass & 0x03) << 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 337 | static void pms_antisnow(struct pms *dev, short snow) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 339 | if (dev->decoder == PHILIPS2) |
| 340 | pms_i2c_andor(dev, 0x8a, 0x06, 0xf3, (snow & 0x03) << 2); |
| 341 | else if (dev->decoder == PHILIPS1) |
| 342 | pms_i2c_andor(dev, 0x42, 0x06, 0xf3, (snow & 0x03) << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 345 | static void pms_sharpness(struct pms *dev, short sharp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 347 | if (dev->decoder == PHILIPS2) |
| 348 | pms_i2c_andor(dev, 0x8a, 0x06, 0xfc, sharp & 0x03); |
| 349 | else if (dev->decoder == PHILIPS1) |
| 350 | pms_i2c_andor(dev, 0x42, 0x06, 0xfc, sharp & 0x03); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 353 | static void pms_chromaagc(struct pms *dev, short agc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 355 | if (dev->decoder == PHILIPS2) |
| 356 | pms_i2c_andor(dev, 0x8a, 0x0c, 0x9f, (agc & 0x03) << 5); |
| 357 | else if (dev->decoder == PHILIPS1) |
| 358 | pms_i2c_andor(dev, 0x42, 0x0c, 0x9f, (agc & 0x03) << 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 361 | static void pms_vertnoise(struct pms *dev, short noise) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 363 | if (dev->decoder == PHILIPS2) |
| 364 | pms_i2c_andor(dev, 0x8a, 0x10, 0xfc, noise & 3); |
| 365 | else if (dev->decoder == PHILIPS1) |
| 366 | pms_i2c_andor(dev, 0x42, 0x10, 0xfc, noise & 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 369 | static void pms_forcecolour(struct pms *dev, short colour) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 371 | if (dev->decoder == PHILIPS2) |
| 372 | pms_i2c_andor(dev, 0x8a, 0x0c, 0x7f, (colour & 1) << 7); |
| 373 | else if (dev->decoder == PHILIPS1) |
| 374 | pms_i2c_andor(dev, 0x42, 0x0c, 0x7, (colour & 1) << 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 377 | static void pms_antigamma(struct pms *dev, short gamma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 379 | if (dev->decoder == PHILIPS2) |
| 380 | pms_i2c_andor(dev, 0xb8, 0x00, 0x7f, (gamma & 1) << 7); |
| 381 | else if (dev->decoder == PHILIPS1) |
| 382 | pms_i2c_andor(dev, 0x42, 0x20, 0x7, (gamma & 1) << 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 385 | static void pms_prefilter(struct pms *dev, short filter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 387 | if (dev->decoder == PHILIPS2) |
| 388 | pms_i2c_andor(dev, 0x8a, 0x06, 0xbf, (filter & 1) << 6); |
| 389 | else if (dev->decoder == PHILIPS1) |
| 390 | pms_i2c_andor(dev, 0x42, 0x06, 0xbf, (filter & 1) << 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 393 | static void pms_hfilter(struct pms *dev, short filter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 395 | if (dev->decoder == PHILIPS2) |
| 396 | pms_i2c_andor(dev, 0xb8, 0x04, 0x1f, (filter & 7) << 5); |
| 397 | else if (dev->decoder == PHILIPS1) |
| 398 | pms_i2c_andor(dev, 0x42, 0x24, 0x1f, (filter & 7) << 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 401 | static void pms_vfilter(struct pms *dev, short filter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 403 | if (dev->decoder == PHILIPS2) |
| 404 | pms_i2c_andor(dev, 0xb8, 0x08, 0x9f, (filter & 3) << 5); |
| 405 | else if (dev->decoder == PHILIPS1) |
| 406 | pms_i2c_andor(dev, 0x42, 0x28, 0x9f, (filter & 3) << 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 409 | static void pms_killcolour(struct pms *dev, short colour) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 411 | if (dev->decoder == PHILIPS2) { |
| 412 | pms_i2c_andor(dev, 0x8a, 0x08, 0x07, (colour & 0x1f) << 3); |
| 413 | pms_i2c_andor(dev, 0x8a, 0x09, 0x07, (colour & 0x1f) << 3); |
| 414 | } else if (dev->decoder == PHILIPS1) { |
| 415 | pms_i2c_andor(dev, 0x42, 0x08, 0x07, (colour & 0x1f) << 3); |
| 416 | pms_i2c_andor(dev, 0x42, 0x09, 0x07, (colour & 0x1f) << 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 420 | static void pms_chromagain(struct pms *dev, short chroma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 422 | if (dev->decoder == PHILIPS2) |
| 423 | pms_i2c_write(dev, 0x8a, 0x11, chroma); |
| 424 | else if (dev->decoder == PHILIPS1) |
| 425 | pms_i2c_write(dev, 0x42, 0x11, chroma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 429 | static void pms_spacialcompl(struct pms *dev, short data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 431 | mvv_write(dev, 0x3b, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 434 | static void pms_spacialcomph(struct pms *dev, short data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 436 | mvv_write(dev, 0x3a, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 439 | static void pms_vstart(struct pms *dev, short start) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 441 | mvv_write(dev, 0x16, start); |
| 442 | mvv_write(dev, 0x17, (start >> 8) & 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | #endif |
| 446 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 447 | static void pms_secamcross(struct pms *dev, short cross) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 449 | if (dev->decoder == PHILIPS2) |
| 450 | pms_i2c_andor(dev, 0x8a, 0x0f, 0xdf, (cross & 1) << 5); |
| 451 | else if (dev->decoder == PHILIPS1) |
| 452 | pms_i2c_andor(dev, 0x42, 0x0f, 0xdf, (cross & 1) << 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 456 | static void pms_swsense(struct pms *dev, short sense) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 458 | if (dev->decoder == PHILIPS2) { |
| 459 | pms_i2c_write(dev, 0x8a, 0x0a, sense); |
| 460 | pms_i2c_write(dev, 0x8a, 0x0b, sense); |
| 461 | } else if (dev->decoder == PHILIPS1) { |
| 462 | pms_i2c_write(dev, 0x42, 0x0a, sense); |
| 463 | pms_i2c_write(dev, 0x42, 0x0b, sense); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
| 467 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 468 | static void pms_framerate(struct pms *dev, short frr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 470 | int fps = (dev->standard == 1) ? 30 : 25; |
| 471 | |
| 472 | if (frr == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | return; |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 474 | fps = fps/frr; |
| 475 | mvv_write(dev, 0x14, 0x80 | fps); |
| 476 | mvv_write(dev, 0x15, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 479 | static void pms_vert(struct pms *dev, u8 deciden, u8 decinum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 481 | mvv_write(dev, 0x1c, deciden); /* Denominator */ |
| 482 | mvv_write(dev, 0x1d, decinum); /* Numerator */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /* |
| 486 | * Turn 16bit ratios into best small ratio the chipset can grok |
| 487 | */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 488 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 489 | static void pms_vertdeci(struct pms *dev, unsigned short decinum, unsigned short deciden) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 491 | /* Knock it down by / 5 once */ |
| 492 | if (decinum % 5 == 0) { |
| 493 | deciden /= 5; |
| 494 | decinum /= 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
| 496 | /* |
| 497 | * 3's |
| 498 | */ |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 499 | while (decinum % 3 == 0 && deciden % 3 == 0) { |
| 500 | deciden /= 3; |
| 501 | decinum /= 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } |
| 503 | /* |
| 504 | * 2's |
| 505 | */ |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 506 | while (decinum % 2 == 0 && deciden % 2 == 0) { |
| 507 | decinum /= 2; |
| 508 | deciden /= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
| 510 | /* |
| 511 | * Fudgyify |
| 512 | */ |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 513 | while (deciden > 32) { |
| 514 | deciden /= 2; |
| 515 | decinum = (decinum + 1) / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | } |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 517 | if (deciden == 32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | deciden--; |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 519 | pms_vert(dev, deciden, decinum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 522 | static void pms_horzdeci(struct pms *dev, short decinum, short deciden) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 524 | if (decinum <= 512) { |
| 525 | if (decinum % 5 == 0) { |
| 526 | decinum /= 5; |
| 527 | deciden /= 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 529 | } else { |
| 530 | decinum = 512; |
| 531 | deciden = 640; /* 768 would be ideal */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 533 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 534 | while (((decinum | deciden) & 1) == 0) { |
| 535 | decinum >>= 1; |
| 536 | deciden >>= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 538 | while (deciden > 32) { |
| 539 | deciden >>= 1; |
| 540 | decinum = (decinum + 1) >> 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | } |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 542 | if (deciden == 32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | deciden--; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 544 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 545 | mvv_write(dev, 0x24, 0x80 | deciden); |
| 546 | mvv_write(dev, 0x25, decinum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 549 | static void pms_resolution(struct pms *dev, short width, short height) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
| 551 | int fg_height; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 552 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 553 | fg_height = height; |
| 554 | if (fg_height > 280) |
| 555 | fg_height = 280; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 556 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 557 | mvv_write(dev, 0x18, fg_height); |
| 558 | mvv_write(dev, 0x19, fg_height >> 8); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 559 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 560 | if (dev->standard == 1) { |
| 561 | mvv_write(dev, 0x1a, 0xfc); |
| 562 | mvv_write(dev, 0x1b, 0x00); |
| 563 | if (height > fg_height) |
| 564 | pms_vertdeci(dev, 240, 240); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | else |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 566 | pms_vertdeci(dev, fg_height, 240); |
| 567 | } else { |
| 568 | mvv_write(dev, 0x1a, 0x1a); |
| 569 | mvv_write(dev, 0x1b, 0x01); |
| 570 | if (fg_height > 256) |
| 571 | pms_vertdeci(dev, 270, 270); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | else |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 573 | pms_vertdeci(dev, fg_height, 270); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 575 | mvv_write(dev, 0x12, 0); |
| 576 | mvv_write(dev, 0x13, MVVMEMORYWIDTH); |
| 577 | mvv_write(dev, 0x42, 0x00); |
| 578 | mvv_write(dev, 0x43, 0x00); |
| 579 | mvv_write(dev, 0x44, MVVMEMORYWIDTH); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 580 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 581 | mvv_write(dev, 0x22, width + 8); |
| 582 | mvv_write(dev, 0x23, (width + 8) >> 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 584 | if (dev->standard == 1) |
| 585 | pms_horzdeci(dev, width, 640); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | else |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 587 | pms_horzdeci(dev, width + 8, 768); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 589 | mvv_write(dev, 0x30, mvv_read(dev, 0x30) & 0xfe); |
| 590 | mvv_write(dev, 0x08, mvv_read(dev, 0x08) | 0x01); |
| 591 | mvv_write(dev, 0x01, mvv_read(dev, 0x01) & 0xfd); |
| 592 | mvv_write(dev, 0x32, 0x00); |
| 593 | mvv_write(dev, 0x33, MVVMEMORYWIDTH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | |
| 597 | /* |
| 598 | * Set Input |
| 599 | */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 600 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 601 | static void pms_vcrinput(struct pms *dev, short input) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 603 | if (dev->decoder == PHILIPS2) |
| 604 | pms_i2c_andor(dev, 0x8a, 0x0d, 0x7f, (input & 1) << 7); |
| 605 | else if (dev->decoder == PHILIPS1) |
| 606 | pms_i2c_andor(dev, 0x42, 0x0d, 0x7f, (input & 1) << 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 610 | static int pms_capture(struct pms *dev, char __user *buf, int rgb555, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | { |
| 612 | int y; |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 613 | int dw = 2 * dev->width; |
| 614 | char tmp[dw + 32]; /* using a temp buffer is faster than direct */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | int cnt = 0; |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 616 | int len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | unsigned char r8 = 0x5; /* value for reg8 */ |
| 618 | |
| 619 | if (rgb555) |
| 620 | r8 |= 0x20; /* else use untranslated rgb = 565 */ |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 621 | mvv_write(dev, 0x08, r8); /* capture rgb555/565, init DRAM, PC enable */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
| 623 | /* printf("%d %d %d %d %d %x %x\n",width,height,voff,nom,den,mvv_buf); */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 624 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 625 | for (y = 0; y < dev->height; y++) { |
| 626 | writeb(0, dev->mem); /* synchronisiert neue Zeile */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | /* |
| 629 | * This is in truth a fifo, be very careful as if you |
| 630 | * forgot this odd things will occur 8) |
| 631 | */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 632 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 633 | memcpy_fromio(tmp, dev->mem, dw + 32); /* discard 16 word */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | cnt -= dev->height; |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 635 | while (cnt <= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | /* |
| 637 | * Don't copy too far |
| 638 | */ |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 639 | int dt = dw; |
| 640 | if (dt + len > count) |
| 641 | dt = count - len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | cnt += dev->height; |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 643 | if (copy_to_user(buf, tmp + 32, dt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | return len ? len : -EFAULT; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 645 | buf += dt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | len += dt; |
| 647 | } |
| 648 | } |
| 649 | return len; |
| 650 | } |
| 651 | |
| 652 | |
| 653 | /* |
| 654 | * Video4linux interfacing |
| 655 | */ |
| 656 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 657 | static long pms_do_ioctl(struct file *file, unsigned int cmd, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 659 | struct pms *dev = video_drvdata(file); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 660 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 661 | switch (cmd) { |
| 662 | case VIDIOCGCAP: { |
| 663 | struct video_capability *b = arg; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 664 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 665 | strcpy(b->name, "Mediavision PMS"); |
| 666 | b->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES; |
| 667 | b->channels = 4; |
| 668 | b->audios = 0; |
| 669 | b->maxwidth = 640; |
| 670 | b->maxheight = 480; |
| 671 | b->minwidth = 16; |
| 672 | b->minheight = 16; |
| 673 | return 0; |
| 674 | } |
| 675 | case VIDIOCGCHAN: { |
| 676 | struct video_channel *v = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 678 | if (v->channel < 0 || v->channel > 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | return -EINVAL; |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 680 | v->flags = 0; |
| 681 | v->tuners = 1; |
| 682 | /* Good question.. its composite or SVHS so.. */ |
| 683 | v->type = VIDEO_TYPE_CAMERA; |
| 684 | switch (v->channel) { |
| 685 | case 0: |
| 686 | strcpy(v->name, "Composite"); |
| 687 | break; |
| 688 | case 1: |
| 689 | strcpy(v->name, "SVideo"); |
| 690 | break; |
| 691 | case 2: |
| 692 | strcpy(v->name, "Composite(VCR)"); |
| 693 | break; |
| 694 | case 3: |
| 695 | strcpy(v->name, "SVideo(VCR)"); |
| 696 | break; |
| 697 | } |
| 698 | return 0; |
| 699 | } |
| 700 | case VIDIOCSCHAN: { |
| 701 | struct video_channel *v = arg; |
| 702 | |
| 703 | if (v->channel < 0 || v->channel > 3) |
| 704 | return -EINVAL; |
| 705 | mutex_lock(&dev->lock); |
| 706 | pms_videosource(dev, v->channel & 1); |
| 707 | pms_vcrinput(dev, v->channel >> 1); |
| 708 | mutex_unlock(&dev->lock); |
| 709 | return 0; |
| 710 | } |
| 711 | case VIDIOCGTUNER: { |
| 712 | struct video_tuner *v = arg; |
| 713 | |
| 714 | if (v->tuner) |
| 715 | return -EINVAL; |
| 716 | strcpy(v->name, "Format"); |
| 717 | v->rangelow = 0; |
| 718 | v->rangehigh = 0; |
| 719 | v->flags = VIDEO_TUNER_PAL | VIDEO_TUNER_NTSC | VIDEO_TUNER_SECAM; |
| 720 | switch (dev->standard) { |
| 721 | case 0: |
| 722 | v->mode = VIDEO_MODE_AUTO; |
| 723 | break; |
| 724 | case 1: |
| 725 | v->mode = VIDEO_MODE_NTSC; |
| 726 | break; |
| 727 | case 2: |
| 728 | v->mode = VIDEO_MODE_PAL; |
| 729 | break; |
| 730 | case 3: |
| 731 | v->mode = VIDEO_MODE_SECAM; |
| 732 | break; |
| 733 | } |
| 734 | return 0; |
| 735 | } |
| 736 | case VIDIOCSTUNER: { |
| 737 | struct video_tuner *v = arg; |
| 738 | |
| 739 | if (v->tuner) |
| 740 | return -EINVAL; |
| 741 | mutex_lock(&dev->lock); |
| 742 | switch (v->mode) { |
| 743 | case VIDEO_MODE_AUTO: |
| 744 | pms_framerate(dev, 25); |
| 745 | pms_secamcross(dev, 0); |
| 746 | pms_format(dev, 0); |
| 747 | break; |
| 748 | case VIDEO_MODE_NTSC: |
| 749 | pms_framerate(dev, 30); |
| 750 | pms_secamcross(dev, 0); |
| 751 | pms_format(dev, 1); |
| 752 | break; |
| 753 | case VIDEO_MODE_PAL: |
| 754 | pms_framerate(dev, 25); |
| 755 | pms_secamcross(dev, 0); |
| 756 | pms_format(dev, 2); |
| 757 | break; |
| 758 | case VIDEO_MODE_SECAM: |
| 759 | pms_framerate(dev, 25); |
| 760 | pms_secamcross(dev, 1); |
| 761 | pms_format(dev, 2); |
| 762 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | default: |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 764 | mutex_unlock(&dev->lock); |
| 765 | return -EINVAL; |
| 766 | } |
| 767 | mutex_unlock(&dev->lock); |
| 768 | return 0; |
| 769 | } |
| 770 | case VIDIOCGPICT: { |
| 771 | struct video_picture *p = arg; |
| 772 | |
| 773 | *p = dev->picture; |
| 774 | return 0; |
| 775 | } |
| 776 | case VIDIOCSPICT: { |
| 777 | struct video_picture *p = arg; |
| 778 | |
| 779 | if (!((p->palette == VIDEO_PALETTE_RGB565 && p->depth == 16) || |
| 780 | (p->palette == VIDEO_PALETTE_RGB555 && p->depth == 15))) |
| 781 | return -EINVAL; |
| 782 | dev->picture = *p; |
| 783 | |
| 784 | /* |
| 785 | * Now load the card. |
| 786 | */ |
| 787 | |
| 788 | mutex_lock(&dev->lock); |
| 789 | pms_brightness(dev, p->brightness >> 8); |
| 790 | pms_hue(dev, p->hue >> 8); |
| 791 | pms_colour(dev, p->colour >> 8); |
| 792 | pms_contrast(dev, p->contrast >> 8); |
| 793 | mutex_unlock(&dev->lock); |
| 794 | return 0; |
| 795 | } |
| 796 | case VIDIOCSWIN: { |
| 797 | struct video_window *vw = arg; |
| 798 | |
| 799 | if (vw->flags) |
| 800 | return -EINVAL; |
| 801 | if (vw->clipcount) |
| 802 | return -EINVAL; |
| 803 | if (vw->height < 16 || vw->height > 480) |
| 804 | return -EINVAL; |
| 805 | if (vw->width < 16 || vw->width > 640) |
| 806 | return -EINVAL; |
| 807 | dev->width = vw->width; |
| 808 | dev->height = vw->height; |
| 809 | mutex_lock(&dev->lock); |
| 810 | pms_resolution(dev, dev->width, dev->height); |
| 811 | /* Ok we figured out what to use from our wide choice */ |
| 812 | mutex_unlock(&dev->lock); |
| 813 | return 0; |
| 814 | } |
| 815 | case VIDIOCGWIN: { |
| 816 | struct video_window *vw = arg; |
| 817 | |
| 818 | memset(vw, 0, sizeof(*vw)); |
| 819 | vw->width = dev->width; |
| 820 | vw->height = dev->height; |
| 821 | return 0; |
| 822 | } |
| 823 | case VIDIOCKEY: |
| 824 | return 0; |
| 825 | case VIDIOCCAPTURE: |
| 826 | case VIDIOCGFBUF: |
| 827 | case VIDIOCSFBUF: |
| 828 | case VIDIOCGFREQ: |
| 829 | case VIDIOCSFREQ: |
| 830 | case VIDIOCGAUDIO: |
| 831 | case VIDIOCSAUDIO: |
| 832 | return -EINVAL; |
| 833 | default: |
| 834 | return -ENOIOCTLCMD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | } |
| 836 | return 0; |
| 837 | } |
| 838 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 839 | static long pms_ioctl(struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | unsigned int cmd, unsigned long arg) |
| 841 | { |
Hans Verkuil | f473bf7 | 2008-11-01 08:25:11 -0300 | [diff] [blame] | 842 | return video_usercopy(file, cmd, arg, pms_do_ioctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | static ssize_t pms_read(struct file *file, char __user *buf, |
| 846 | size_t count, loff_t *ppos) |
| 847 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 848 | struct pms *dev = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | int len; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 850 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 851 | mutex_lock(&dev->lock); |
| 852 | len = pms_capture(dev, buf, (dev->picture.depth == 16) ? 0 : 1, count); |
| 853 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | return len; |
| 855 | } |
| 856 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 857 | static int pms_exclusive_open(struct file *file) |
Hans Verkuil | 7d43cd5 | 2008-08-23 05:31:47 -0300 | [diff] [blame] | 858 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 859 | struct pms *dev = video_drvdata(file); |
Hans Verkuil | 7d43cd5 | 2008-08-23 05:31:47 -0300 | [diff] [blame] | 860 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 861 | return test_and_set_bit(0, &dev->in_use) ? -EBUSY : 0; |
Hans Verkuil | 7d43cd5 | 2008-08-23 05:31:47 -0300 | [diff] [blame] | 862 | } |
| 863 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 864 | static int pms_exclusive_release(struct file *file) |
Hans Verkuil | 7d43cd5 | 2008-08-23 05:31:47 -0300 | [diff] [blame] | 865 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 866 | struct pms *dev = video_drvdata(file); |
Hans Verkuil | 7d43cd5 | 2008-08-23 05:31:47 -0300 | [diff] [blame] | 867 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 868 | clear_bit(0, &dev->in_use); |
Hans Verkuil | 7d43cd5 | 2008-08-23 05:31:47 -0300 | [diff] [blame] | 869 | return 0; |
| 870 | } |
| 871 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 872 | static const struct v4l2_file_operations pms_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | .owner = THIS_MODULE, |
Hans Verkuil | 7d43cd5 | 2008-08-23 05:31:47 -0300 | [diff] [blame] | 874 | .open = pms_exclusive_open, |
| 875 | .release = pms_exclusive_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | .ioctl = pms_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | .read = pms_read, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | }; |
| 879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
| 881 | /* |
| 882 | * Probe for and initialise the Mediavision PMS |
| 883 | */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 884 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 885 | static int init_mediavision(struct pms *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | { |
| 887 | int id; |
| 888 | int idec, decst; |
| 889 | int i; |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 890 | static const unsigned char i2c_defs[] = { |
| 891 | 0x4c, 0x30, 0x00, 0xe8, |
| 892 | 0xb6, 0xe2, 0x00, 0x00, |
| 893 | 0xff, 0xff, 0x00, 0x00, |
| 894 | 0x00, 0x00, 0x78, 0x98, |
| 895 | 0x00, 0x00, 0x00, 0x00, |
| 896 | 0x34, 0x0a, 0xf4, 0xce, |
| 897 | 0xe4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | }; |
| 899 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 900 | dev->mem = ioremap(mem_base, 0x800); |
| 901 | if (!dev->mem) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | return -ENOMEM; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 903 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 904 | if (!request_region(0x9a01, 1, "Mediavision PMS config")) { |
| 905 | printk(KERN_WARNING "mediavision: unable to detect: 0x9a01 in use.\n"); |
| 906 | iounmap(dev->mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | return -EBUSY; |
| 908 | } |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 909 | if (!request_region(dev->io, 3, "Mediavision PMS")) { |
| 910 | printk(KERN_WARNING "mediavision: I/O port %d in use.\n", dev->io); |
| 911 | release_region(0x9a01, 1); |
| 912 | iounmap(dev->mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | return -EBUSY; |
| 914 | } |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 915 | outb(0xb8, 0x9a01); /* Unlock */ |
| 916 | outb(dev->io >> 4, 0x9a01); /* Set IO port */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 917 | |
| 918 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 919 | id = mvv_read(dev, 3); |
| 920 | decst = pms_i2c_stat(dev, 0x43); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 921 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 922 | if (decst != -1) |
| 923 | idec = 2; |
| 924 | else if (pms_i2c_stat(dev, 0xb9) != -1) |
| 925 | idec = 3; |
| 926 | else if (pms_i2c_stat(dev, 0x8b) != -1) |
| 927 | idec = 1; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 928 | else |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 929 | idec = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
| 931 | printk(KERN_INFO "PMS type is %d\n", idec); |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 932 | if (idec == 0) { |
| 933 | release_region(dev->io, 3); |
| 934 | release_region(0x9a01, 1); |
| 935 | iounmap(dev->mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | return -ENODEV; |
| 937 | } |
| 938 | |
| 939 | /* |
| 940 | * Ok we have a PMS of some sort |
| 941 | */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 942 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 943 | mvv_write(dev, 0x04, mem_base >> 12); /* Set the memory area */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | /* Ok now load the defaults */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 946 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 947 | for (i = 0; i < 0x19; i++) { |
| 948 | if (i2c_defs[i] == 0xff) |
| 949 | pms_i2c_andor(dev, 0x8a, i, 0x07, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | else |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 951 | pms_i2c_write(dev, 0x8a, i, i2c_defs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 953 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 954 | pms_i2c_write(dev, 0xb8, 0x00, 0x12); |
| 955 | pms_i2c_write(dev, 0xb8, 0x04, 0x00); |
| 956 | pms_i2c_write(dev, 0xb8, 0x07, 0x00); |
| 957 | pms_i2c_write(dev, 0xb8, 0x08, 0x00); |
| 958 | pms_i2c_write(dev, 0xb8, 0x09, 0xff); |
| 959 | pms_i2c_write(dev, 0xb8, 0x0a, 0x00); |
| 960 | pms_i2c_write(dev, 0xb8, 0x0b, 0x10); |
| 961 | pms_i2c_write(dev, 0xb8, 0x10, 0x03); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 962 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 963 | mvv_write(dev, 0x01, 0x00); |
| 964 | mvv_write(dev, 0x05, 0xa0); |
| 965 | mvv_write(dev, 0x08, 0x25); |
| 966 | mvv_write(dev, 0x09, 0x00); |
| 967 | mvv_write(dev, 0x0a, 0x20 | MVVMEMORYWIDTH); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 968 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 969 | mvv_write(dev, 0x10, 0x02); |
| 970 | mvv_write(dev, 0x1e, 0x0c); |
| 971 | mvv_write(dev, 0x1f, 0x03); |
| 972 | mvv_write(dev, 0x26, 0x06); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 973 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 974 | mvv_write(dev, 0x2b, 0x00); |
| 975 | mvv_write(dev, 0x2c, 0x20); |
| 976 | mvv_write(dev, 0x2d, 0x00); |
| 977 | mvv_write(dev, 0x2f, 0x70); |
| 978 | mvv_write(dev, 0x32, 0x00); |
| 979 | mvv_write(dev, 0x33, MVVMEMORYWIDTH); |
| 980 | mvv_write(dev, 0x34, 0x00); |
| 981 | mvv_write(dev, 0x35, 0x00); |
| 982 | mvv_write(dev, 0x3a, 0x80); |
| 983 | mvv_write(dev, 0x3b, 0x10); |
| 984 | mvv_write(dev, 0x20, 0x00); |
| 985 | mvv_write(dev, 0x21, 0x00); |
| 986 | mvv_write(dev, 0x30, 0x22); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | return 0; |
| 988 | } |
| 989 | |
| 990 | /* |
| 991 | * Initialization and module stuff |
| 992 | */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 993 | |
Rene Herman | b54ff93 | 2008-09-03 16:48:21 -0300 | [diff] [blame] | 994 | #ifndef MODULE |
| 995 | static int enable; |
| 996 | module_param(enable, int, 0); |
| 997 | #endif |
| 998 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 999 | static int __init pms_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 1001 | struct pms *dev = &pms_card; |
| 1002 | struct v4l2_device *v4l2_dev = &dev->v4l2_dev; |
| 1003 | int res; |
| 1004 | |
| 1005 | strlcpy(v4l2_dev->name, "pms", sizeof(v4l2_dev->name)); |
| 1006 | |
| 1007 | v4l2_info(v4l2_dev, "Mediavision Pro Movie Studio driver 0.03\n"); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1008 | |
Rene Herman | b54ff93 | 2008-09-03 16:48:21 -0300 | [diff] [blame] | 1009 | #ifndef MODULE |
| 1010 | if (!enable) { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 1011 | v4l2_err(v4l2_dev, |
| 1012 | "PMS: not enabled, use pms.enable=1 to probe\n"); |
Rene Herman | b54ff93 | 2008-09-03 16:48:21 -0300 | [diff] [blame] | 1013 | return -ENODEV; |
| 1014 | } |
| 1015 | #endif |
| 1016 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 1017 | dev->decoder = PHILIPS2; |
| 1018 | dev->io = io_port; |
| 1019 | dev->data = io_port + 1; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1020 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 1021 | if (init_mediavision(dev)) { |
| 1022 | v4l2_err(v4l2_dev, "Board not found.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | return -ENODEV; |
| 1024 | } |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 1025 | |
| 1026 | res = v4l2_device_register(NULL, v4l2_dev); |
| 1027 | if (res < 0) { |
| 1028 | v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); |
| 1029 | return res; |
| 1030 | } |
| 1031 | |
| 1032 | strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name)); |
| 1033 | dev->vdev.v4l2_dev = v4l2_dev; |
| 1034 | dev->vdev.fops = &pms_fops; |
| 1035 | dev->vdev.release = video_device_release_empty; |
| 1036 | video_set_drvdata(&dev->vdev, dev); |
| 1037 | mutex_init(&dev->lock); |
| 1038 | dev->height = 240; |
| 1039 | dev->width = 320; |
| 1040 | pms_swsense(dev, 75); |
| 1041 | pms_resolution(dev, 320, 240); |
| 1042 | pms_videosource(dev, 0); |
| 1043 | pms_vcrinput(dev, 0); |
| 1044 | if (video_register_device(&dev->vdev, VFL_TYPE_GRABBER, video_nr) < 0) { |
| 1045 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1046 | release_region(dev->io, 3); |
| 1047 | release_region(0x9a01, 1); |
| 1048 | iounmap(dev->mem); |
| 1049 | return -EINVAL; |
| 1050 | } |
| 1051 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 1054 | static void __exit pms_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | { |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 1056 | struct pms *dev = &pms_card; |
| 1057 | |
| 1058 | video_unregister_device(&dev->vdev); |
| 1059 | release_region(dev->io, 3); |
| 1060 | release_region(0x9a01, 1); |
| 1061 | iounmap(dev->mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Hans Verkuil | 1ce7981 | 2009-11-25 12:37:00 -0300 | [diff] [blame^] | 1064 | module_init(pms_init); |
| 1065 | module_exit(pms_exit); |