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