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