Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 1 | /* |
| 2 | em28xx-camera.c - driver for Empia EM25xx/27xx/28xx USB video capture devices |
| 3 | |
| 4 | Copyright (C) 2009 Mauro Carvalho Chehab <mchehab@infradead.org> |
| 5 | Copyright (C) 2013 Frank Schäfer <fschaefer.oss@googlemail.com> |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
Mauro Carvalho Chehab | 8314d40 | 2016-10-12 07:26:47 -0300 | [diff] [blame] | 22 | #include "em28xx.h" |
| 23 | |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 24 | #include <linux/i2c.h> |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 25 | #include <linux/usb.h> |
Frank Schaefer | e4b7131 | 2013-03-27 17:06:36 -0300 | [diff] [blame] | 26 | #include <media/soc_camera.h> |
Mauro Carvalho Chehab | b5dcee2 | 2015-11-10 12:01:44 -0200 | [diff] [blame] | 27 | #include <media/i2c/mt9v011.h> |
Guennadi Liakhovetski | fc5d0f8 | 2013-08-28 10:28:28 -0300 | [diff] [blame] | 28 | #include <media/v4l2-clk.h> |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 29 | #include <media/v4l2-common.h> |
| 30 | |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 31 | /* Possible i2c addresses of Micron sensors */ |
| 32 | static unsigned short micron_sensor_addrs[] = { |
| 33 | 0xb8 >> 1, /* MT9V111, MT9V403 */ |
| 34 | 0xba >> 1, /* MT9M001/011/111/112, MT9V011/012/112, MT9D011 */ |
| 35 | 0x90 >> 1, /* MT9V012/112, MT9D011 (alternative address) */ |
| 36 | I2C_CLIENT_END |
| 37 | }; |
| 38 | |
Frank Schaefer | bde0368 | 2013-03-27 17:06:34 -0300 | [diff] [blame] | 39 | /* Possible i2c addresses of Omnivision sensors */ |
| 40 | static unsigned short omnivision_sensor_addrs[] = { |
| 41 | 0x42 >> 1, /* OV7725, OV7670/60/48 */ |
| 42 | 0x60 >> 1, /* OV2640, OV9650/53/55 */ |
| 43 | I2C_CLIENT_END |
| 44 | }; |
| 45 | |
Frank Schaefer | e4b7131 | 2013-03-27 17:06:36 -0300 | [diff] [blame] | 46 | static struct soc_camera_link camlink = { |
| 47 | .bus_id = 0, |
| 48 | .flags = 0, |
| 49 | .module_name = "em28xx", |
Guennadi Liakhovetski | be353fa | 2013-10-21 06:28:06 -0300 | [diff] [blame] | 50 | .unbalanced_power = true, |
Frank Schaefer | e4b7131 | 2013-03-27 17:06:36 -0300 | [diff] [blame] | 51 | }; |
| 52 | |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 53 | /* FIXME: Should be replaced by a proper mt9m111 driver */ |
| 54 | static int em28xx_initialize_mt9m111(struct em28xx *dev) |
| 55 | { |
| 56 | int i; |
| 57 | unsigned char regs[][3] = { |
| 58 | { 0x0d, 0x00, 0x01, }, /* reset and use defaults */ |
| 59 | { 0x0d, 0x00, 0x00, }, |
| 60 | { 0x0a, 0x00, 0x21, }, |
| 61 | { 0x21, 0x04, 0x00, }, /* full readout speed, no row/col skipping */ |
| 62 | }; |
| 63 | |
| 64 | for (i = 0; i < ARRAY_SIZE(regs); i++) |
| 65 | i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], |
| 66 | ®s[i][0], 3); |
| 67 | |
Mauro Carvalho Chehab | 37ecc7b | 2016-01-27 07:07:24 -0200 | [diff] [blame] | 68 | /* FIXME: This won't be creating a sensor at the media graph */ |
| 69 | |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 73 | /* FIXME: Should be replaced by a proper mt9m001 driver */ |
| 74 | static int em28xx_initialize_mt9m001(struct em28xx *dev) |
| 75 | { |
| 76 | int i; |
| 77 | unsigned char regs[][3] = { |
| 78 | { 0x0d, 0x00, 0x01, }, |
| 79 | { 0x0d, 0x00, 0x00, }, |
| 80 | { 0x04, 0x05, 0x00, }, /* hres = 1280 */ |
| 81 | { 0x03, 0x04, 0x00, }, /* vres = 1024 */ |
| 82 | { 0x20, 0x11, 0x00, }, |
| 83 | { 0x06, 0x00, 0x10, }, |
| 84 | { 0x2b, 0x00, 0x24, }, |
| 85 | { 0x2e, 0x00, 0x24, }, |
| 86 | { 0x35, 0x00, 0x24, }, |
| 87 | { 0x2d, 0x00, 0x20, }, |
| 88 | { 0x2c, 0x00, 0x20, }, |
| 89 | { 0x09, 0x0a, 0xd4, }, |
| 90 | { 0x35, 0x00, 0x57, }, |
| 91 | }; |
| 92 | |
| 93 | for (i = 0; i < ARRAY_SIZE(regs); i++) |
| 94 | i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], |
| 95 | ®s[i][0], 3); |
| 96 | |
Mauro Carvalho Chehab | 37ecc7b | 2016-01-27 07:07:24 -0200 | [diff] [blame] | 97 | /* FIXME: This won't be creating a sensor at the media graph */ |
| 98 | |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 99 | return 0; |
| 100 | } |
| 101 | |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 102 | /* |
Frank Schaefer | 0af0b25 | 2013-03-27 17:06:33 -0300 | [diff] [blame] | 103 | * Probes Micron sensors with 8 bit address and 16 bit register width |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 104 | */ |
Frank Schaefer | 0af0b25 | 2013-03-27 17:06:33 -0300 | [diff] [blame] | 105 | static int em28xx_probe_sensor_micron(struct em28xx *dev) |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 106 | { |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 107 | int ret, i; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 108 | char *name; |
| 109 | u8 reg; |
| 110 | __be16 id_be; |
| 111 | u16 id; |
| 112 | |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 113 | struct i2c_client client = dev->i2c_client[dev->def_i2c_bus]; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 114 | |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 115 | dev->em28xx_sensor = EM28XX_NOSENSOR; |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 116 | for (i = 0; micron_sensor_addrs[i] != I2C_CLIENT_END; i++) { |
| 117 | client.addr = micron_sensor_addrs[i]; |
| 118 | /* NOTE: i2c_smbus_read_word_data() doesn't work with BE data */ |
| 119 | /* Read chip ID from register 0x00 */ |
| 120 | reg = 0x00; |
| 121 | ret = i2c_master_send(&client, ®, 1); |
| 122 | if (ret < 0) { |
Frank Schaefer | cb497c7 | 2014-01-17 14:45:31 -0300 | [diff] [blame] | 123 | if (ret != -ENXIO) |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 124 | dev_err(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 125 | "couldn't read from i2c device 0x%02x: error %i\n", |
Mauro Carvalho Chehab | 2a96f60 | 2016-10-12 07:32:23 -0300 | [diff] [blame] | 126 | client.addr << 1, ret); |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 127 | continue; |
| 128 | } |
| 129 | ret = i2c_master_recv(&client, (u8 *)&id_be, 2); |
| 130 | if (ret < 0) { |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 131 | dev_err(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 132 | "couldn't read from i2c device 0x%02x: error %i\n", |
| 133 | client.addr << 1, ret); |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 134 | continue; |
| 135 | } |
| 136 | id = be16_to_cpu(id_be); |
| 137 | /* Read chip ID from register 0xff */ |
| 138 | reg = 0xff; |
| 139 | ret = i2c_master_send(&client, ®, 1); |
| 140 | if (ret < 0) { |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 141 | dev_err(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 142 | "couldn't read from i2c device 0x%02x: error %i\n", |
| 143 | client.addr << 1, ret); |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 144 | continue; |
| 145 | } |
| 146 | ret = i2c_master_recv(&client, (u8 *)&id_be, 2); |
| 147 | if (ret < 0) { |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 148 | dev_err(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 149 | "couldn't read from i2c device 0x%02x: error %i\n", |
| 150 | client.addr << 1, ret); |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 151 | continue; |
| 152 | } |
| 153 | /* Validate chip ID to be sure we have a Micron device */ |
| 154 | if (id != be16_to_cpu(id_be)) |
| 155 | continue; |
| 156 | /* Check chip ID */ |
| 157 | id = be16_to_cpu(id_be); |
| 158 | switch (id) { |
| 159 | case 0x1222: |
| 160 | name = "MT9V012"; /* MI370 */ /* 640x480 */ |
| 161 | break; |
| 162 | case 0x1229: |
| 163 | name = "MT9V112"; /* 640x480 */ |
| 164 | break; |
| 165 | case 0x1433: |
| 166 | name = "MT9M011"; /* 1280x1024 */ |
| 167 | break; |
| 168 | case 0x143a: /* found in the ECS G200 */ |
| 169 | name = "MT9M111"; /* MI1310 */ /* 1280x1024 */ |
| 170 | dev->em28xx_sensor = EM28XX_MT9M111; |
| 171 | break; |
| 172 | case 0x148c: |
| 173 | name = "MT9M112"; /* MI1320 */ /* 1280x1024 */ |
| 174 | break; |
| 175 | case 0x1511: |
| 176 | name = "MT9D011"; /* MI2010 */ /* 1600x1200 */ |
| 177 | break; |
| 178 | case 0x8232: |
| 179 | case 0x8243: /* rev B */ |
| 180 | name = "MT9V011"; /* MI360 */ /* 640x480 */ |
| 181 | dev->em28xx_sensor = EM28XX_MT9V011; |
| 182 | break; |
| 183 | case 0x8431: |
| 184 | name = "MT9M001"; /* 1280x1024 */ |
| 185 | dev->em28xx_sensor = EM28XX_MT9M001; |
| 186 | break; |
| 187 | default: |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 188 | dev_info(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 189 | "unknown Micron sensor detected: 0x%04x\n", id); |
Frank Schaefer | 0af0b25 | 2013-03-27 17:06:33 -0300 | [diff] [blame] | 190 | return 0; |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | if (dev->em28xx_sensor == EM28XX_NOSENSOR) |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 194 | dev_info(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 195 | "unsupported sensor detected: %s\n", name); |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 196 | else |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 197 | dev_info(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 198 | "sensor %s detected\n", name); |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 199 | |
| 200 | dev->i2c_client[dev->def_i2c_bus].addr = client.addr; |
| 201 | return 0; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 202 | } |
| 203 | |
Frank Schaefer | 176013b | 2013-03-27 17:06:32 -0300 | [diff] [blame] | 204 | return -ENODEV; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 205 | } |
| 206 | |
Frank Schaefer | 0af0b25 | 2013-03-27 17:06:33 -0300 | [diff] [blame] | 207 | /* |
Frank Schaefer | bde0368 | 2013-03-27 17:06:34 -0300 | [diff] [blame] | 208 | * Probes Omnivision sensors with 8 bit address and register width |
Frank Schaefer | 0af0b25 | 2013-03-27 17:06:33 -0300 | [diff] [blame] | 209 | */ |
Frank Schaefer | bde0368 | 2013-03-27 17:06:34 -0300 | [diff] [blame] | 210 | static int em28xx_probe_sensor_omnivision(struct em28xx *dev) |
| 211 | { |
| 212 | int ret, i; |
| 213 | char *name; |
| 214 | u8 reg; |
| 215 | u16 id; |
| 216 | struct i2c_client client = dev->i2c_client[dev->def_i2c_bus]; |
| 217 | |
| 218 | dev->em28xx_sensor = EM28XX_NOSENSOR; |
| 219 | /* NOTE: these devices have the register auto incrementation disabled |
| 220 | * by default, so we have to use single byte reads ! */ |
| 221 | for (i = 0; omnivision_sensor_addrs[i] != I2C_CLIENT_END; i++) { |
| 222 | client.addr = omnivision_sensor_addrs[i]; |
| 223 | /* Read manufacturer ID from registers 0x1c-0x1d (BE) */ |
| 224 | reg = 0x1c; |
| 225 | ret = i2c_smbus_read_byte_data(&client, reg); |
| 226 | if (ret < 0) { |
Frank Schaefer | cb497c7 | 2014-01-17 14:45:31 -0300 | [diff] [blame] | 227 | if (ret != -ENXIO) |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 228 | dev_err(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 229 | "couldn't read from i2c device 0x%02x: error %i\n", |
| 230 | client.addr << 1, ret); |
Frank Schaefer | bde0368 | 2013-03-27 17:06:34 -0300 | [diff] [blame] | 231 | continue; |
| 232 | } |
| 233 | id = ret << 8; |
| 234 | reg = 0x1d; |
| 235 | ret = i2c_smbus_read_byte_data(&client, reg); |
| 236 | if (ret < 0) { |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 237 | dev_err(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 238 | "couldn't read from i2c device 0x%02x: error %i\n", |
| 239 | client.addr << 1, ret); |
Frank Schaefer | bde0368 | 2013-03-27 17:06:34 -0300 | [diff] [blame] | 240 | continue; |
| 241 | } |
| 242 | id += ret; |
| 243 | /* Check manufacturer ID */ |
| 244 | if (id != 0x7fa2) |
| 245 | continue; |
| 246 | /* Read product ID from registers 0x0a-0x0b (BE) */ |
| 247 | reg = 0x0a; |
| 248 | ret = i2c_smbus_read_byte_data(&client, reg); |
| 249 | if (ret < 0) { |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 250 | dev_err(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 251 | "couldn't read from i2c device 0x%02x: error %i\n", |
| 252 | client.addr << 1, ret); |
Frank Schaefer | bde0368 | 2013-03-27 17:06:34 -0300 | [diff] [blame] | 253 | continue; |
| 254 | } |
| 255 | id = ret << 8; |
| 256 | reg = 0x0b; |
| 257 | ret = i2c_smbus_read_byte_data(&client, reg); |
| 258 | if (ret < 0) { |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 259 | dev_err(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 260 | "couldn't read from i2c device 0x%02x: error %i\n", |
| 261 | client.addr << 1, ret); |
Frank Schaefer | bde0368 | 2013-03-27 17:06:34 -0300 | [diff] [blame] | 262 | continue; |
| 263 | } |
| 264 | id += ret; |
| 265 | /* Check product ID */ |
| 266 | switch (id) { |
| 267 | case 0x2642: |
| 268 | name = "OV2640"; |
Frank Schaefer | e4b7131 | 2013-03-27 17:06:36 -0300 | [diff] [blame] | 269 | dev->em28xx_sensor = EM28XX_OV2640; |
Frank Schaefer | bde0368 | 2013-03-27 17:06:34 -0300 | [diff] [blame] | 270 | break; |
| 271 | case 0x7648: |
| 272 | name = "OV7648"; |
| 273 | break; |
| 274 | case 0x7660: |
| 275 | name = "OV7660"; |
| 276 | break; |
| 277 | case 0x7673: |
| 278 | name = "OV7670"; |
| 279 | break; |
| 280 | case 0x7720: |
| 281 | name = "OV7720"; |
| 282 | break; |
| 283 | case 0x7721: |
| 284 | name = "OV7725"; |
| 285 | break; |
| 286 | case 0x9648: /* Rev 2 */ |
| 287 | case 0x9649: /* Rev 3 */ |
| 288 | name = "OV9640"; |
| 289 | break; |
| 290 | case 0x9650: |
| 291 | case 0x9652: /* OV9653 */ |
| 292 | name = "OV9650"; |
| 293 | break; |
| 294 | case 0x9656: /* Rev 4 */ |
| 295 | case 0x9657: /* Rev 5 */ |
| 296 | name = "OV9655"; |
| 297 | break; |
| 298 | default: |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 299 | dev_info(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 300 | "unknown OmniVision sensor detected: 0x%04x\n", |
Mauro Carvalho Chehab | 2a96f60 | 2016-10-12 07:32:23 -0300 | [diff] [blame] | 301 | id); |
Frank Schaefer | bde0368 | 2013-03-27 17:06:34 -0300 | [diff] [blame] | 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | if (dev->em28xx_sensor == EM28XX_NOSENSOR) |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 306 | dev_info(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 307 | "unsupported sensor detected: %s\n", name); |
Frank Schaefer | bde0368 | 2013-03-27 17:06:34 -0300 | [diff] [blame] | 308 | else |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 309 | dev_info(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 310 | "sensor %s detected\n", name); |
Frank Schaefer | bde0368 | 2013-03-27 17:06:34 -0300 | [diff] [blame] | 311 | |
| 312 | dev->i2c_client[dev->def_i2c_bus].addr = client.addr; |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | return -ENODEV; |
| 317 | } |
| 318 | |
Frank Schaefer | 0af0b25 | 2013-03-27 17:06:33 -0300 | [diff] [blame] | 319 | int em28xx_detect_sensor(struct em28xx *dev) |
| 320 | { |
| 321 | int ret; |
| 322 | |
| 323 | ret = em28xx_probe_sensor_micron(dev); |
Frank Schaefer | bde0368 | 2013-03-27 17:06:34 -0300 | [diff] [blame] | 324 | |
| 325 | if (dev->em28xx_sensor == EM28XX_NOSENSOR && ret < 0) |
| 326 | ret = em28xx_probe_sensor_omnivision(dev); |
| 327 | |
Frank Schaefer | 52f1f23 | 2013-03-27 17:06:35 -0300 | [diff] [blame] | 328 | /* |
| 329 | * NOTE: the Windows driver also probes i2c addresses |
| 330 | * 0x22 (Samsung ?) and 0x66 (Kodak ?) |
| 331 | */ |
| 332 | |
Frank Schaefer | 0af0b25 | 2013-03-27 17:06:33 -0300 | [diff] [blame] | 333 | if (dev->em28xx_sensor == EM28XX_NOSENSOR && ret < 0) { |
Mauro Carvalho Chehab | 29b05e2 | 2016-12-07 13:48:10 -0200 | [diff] [blame^] | 334 | dev_info(&dev->intf->dev, |
Mauro Carvalho Chehab | ce8591f | 2016-10-20 08:42:03 -0200 | [diff] [blame] | 335 | "No sensor detected\n"); |
Frank Schaefer | 0af0b25 | 2013-03-27 17:06:33 -0300 | [diff] [blame] | 336 | return -ENODEV; |
| 337 | } |
| 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 342 | int em28xx_init_camera(struct em28xx *dev) |
| 343 | { |
Josh Wu | 3d83078 | 2015-10-28 07:48:54 -0200 | [diff] [blame] | 344 | char clk_name[V4L2_CLK_NAME_SIZE]; |
Guennadi Liakhovetski | fc5d0f8 | 2013-08-28 10:28:28 -0300 | [diff] [blame] | 345 | struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus]; |
| 346 | struct i2c_adapter *adap = &dev->i2c_adap[dev->def_i2c_bus]; |
Frank Schaefer | 2c52a2f | 2014-03-24 16:33:11 -0300 | [diff] [blame] | 347 | struct em28xx_v4l2 *v4l2 = dev->v4l2; |
Guennadi Liakhovetski | fc5d0f8 | 2013-08-28 10:28:28 -0300 | [diff] [blame] | 348 | int ret = 0; |
| 349 | |
| 350 | v4l2_clk_name_i2c(clk_name, sizeof(clk_name), |
| 351 | i2c_adapter_id(adap), client->addr); |
Guennadi Liakhovetski | a37462b | 2015-01-31 20:21:32 -0300 | [diff] [blame] | 352 | v4l2->clk = v4l2_clk_register_fixed(clk_name, -EINVAL); |
Frank Schaefer | 2c52a2f | 2014-03-24 16:33:11 -0300 | [diff] [blame] | 353 | if (IS_ERR(v4l2->clk)) |
| 354 | return PTR_ERR(v4l2->clk); |
Guennadi Liakhovetski | fc5d0f8 | 2013-08-28 10:28:28 -0300 | [diff] [blame] | 355 | |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 356 | switch (dev->em28xx_sensor) { |
| 357 | case EM28XX_MT9V011: |
| 358 | { |
| 359 | struct mt9v011_platform_data pdata; |
| 360 | struct i2c_board_info mt9v011_info = { |
| 361 | .type = "mt9v011", |
Guennadi Liakhovetski | fc5d0f8 | 2013-08-28 10:28:28 -0300 | [diff] [blame] | 362 | .addr = client->addr, |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 363 | .platform_data = &pdata, |
| 364 | }; |
| 365 | |
Frank Schaefer | d7dc18d | 2014-03-24 16:33:19 -0300 | [diff] [blame] | 366 | v4l2->sensor_xres = 640; |
| 367 | v4l2->sensor_yres = 480; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 368 | |
| 369 | /* |
| 370 | * FIXME: mt9v011 uses I2S speed as xtal clk - at least with |
| 371 | * the Silvercrest cam I have here for testing - for higher |
| 372 | * resolutions, a high clock cause horizontal artifacts, so we |
| 373 | * need to use a lower xclk frequency. |
| 374 | * Yet, it would be possible to adjust xclk depending on the |
| 375 | * desired resolution, since this affects directly the |
| 376 | * frame rate. |
| 377 | */ |
| 378 | dev->board.xclk = EM28XX_XCLK_FREQUENCY_4_3MHZ; |
| 379 | em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk); |
Frank Schaefer | d7dc18d | 2014-03-24 16:33:19 -0300 | [diff] [blame] | 380 | v4l2->sensor_xtal = 4300000; |
| 381 | pdata.xtal = v4l2->sensor_xtal; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 382 | if (NULL == |
Frank Schaefer | 5015389 | 2014-07-25 14:48:55 -0300 | [diff] [blame] | 383 | v4l2_i2c_new_subdev_board(&v4l2->v4l2_dev, adap, |
Guennadi Liakhovetski | fc5d0f8 | 2013-08-28 10:28:28 -0300 | [diff] [blame] | 384 | &mt9v011_info, NULL)) { |
| 385 | ret = -ENODEV; |
| 386 | break; |
| 387 | } |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 388 | /* probably means GRGB 16 bit bayer */ |
Frank Schaefer | 9297285 | 2014-03-24 16:33:15 -0300 | [diff] [blame] | 389 | v4l2->vinmode = 0x0d; |
| 390 | v4l2->vinctl = 0x00; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 391 | |
| 392 | break; |
| 393 | } |
| 394 | case EM28XX_MT9M001: |
Frank Schaefer | d7dc18d | 2014-03-24 16:33:19 -0300 | [diff] [blame] | 395 | v4l2->sensor_xres = 1280; |
| 396 | v4l2->sensor_yres = 1024; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 397 | |
| 398 | em28xx_initialize_mt9m001(dev); |
| 399 | |
| 400 | /* probably means BGGR 16 bit bayer */ |
Frank Schaefer | 9297285 | 2014-03-24 16:33:15 -0300 | [diff] [blame] | 401 | v4l2->vinmode = 0x0c; |
| 402 | v4l2->vinctl = 0x00; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 403 | |
| 404 | break; |
| 405 | case EM28XX_MT9M111: |
Frank Schaefer | d7dc18d | 2014-03-24 16:33:19 -0300 | [diff] [blame] | 406 | v4l2->sensor_xres = 640; |
| 407 | v4l2->sensor_yres = 512; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 408 | |
| 409 | dev->board.xclk = EM28XX_XCLK_FREQUENCY_48MHZ; |
| 410 | em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk); |
| 411 | em28xx_initialize_mt9m111(dev); |
| 412 | |
Frank Schaefer | 9297285 | 2014-03-24 16:33:15 -0300 | [diff] [blame] | 413 | v4l2->vinmode = 0x0a; |
| 414 | v4l2->vinctl = 0x00; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 415 | |
| 416 | break; |
Frank Schaefer | e4b7131 | 2013-03-27 17:06:36 -0300 | [diff] [blame] | 417 | case EM28XX_OV2640: |
| 418 | { |
| 419 | struct v4l2_subdev *subdev; |
| 420 | struct i2c_board_info ov2640_info = { |
| 421 | .type = "ov2640", |
| 422 | .flags = I2C_CLIENT_SCCB, |
Guennadi Liakhovetski | fc5d0f8 | 2013-08-28 10:28:28 -0300 | [diff] [blame] | 423 | .addr = client->addr, |
Frank Schaefer | e4b7131 | 2013-03-27 17:06:36 -0300 | [diff] [blame] | 424 | .platform_data = &camlink, |
| 425 | }; |
Hans Verkuil | ebf984b | 2015-04-09 04:05:59 -0300 | [diff] [blame] | 426 | struct v4l2_subdev_format format = { |
| 427 | .which = V4L2_SUBDEV_FORMAT_ACTIVE, |
| 428 | }; |
Frank Schaefer | e4b7131 | 2013-03-27 17:06:36 -0300 | [diff] [blame] | 429 | |
| 430 | /* |
| 431 | * FIXME: sensor supports resolutions up to 1600x1200, but |
| 432 | * resolution setting/switching needs to be modified to |
| 433 | * - switch sensor output resolution (including further |
| 434 | * configuration changes) |
| 435 | * - adjust bridge xclk |
| 436 | * - disable 16 bit (12 bit) output formats on high resolutions |
| 437 | */ |
Frank Schaefer | d7dc18d | 2014-03-24 16:33:19 -0300 | [diff] [blame] | 438 | v4l2->sensor_xres = 640; |
| 439 | v4l2->sensor_yres = 480; |
Frank Schaefer | e4b7131 | 2013-03-27 17:06:36 -0300 | [diff] [blame] | 440 | |
| 441 | subdev = |
Frank Schaefer | 5015389 | 2014-07-25 14:48:55 -0300 | [diff] [blame] | 442 | v4l2_i2c_new_subdev_board(&v4l2->v4l2_dev, adap, |
Frank Schaefer | e4b7131 | 2013-03-27 17:06:36 -0300 | [diff] [blame] | 443 | &ov2640_info, NULL); |
Guennadi Liakhovetski | fc5d0f8 | 2013-08-28 10:28:28 -0300 | [diff] [blame] | 444 | if (NULL == subdev) { |
| 445 | ret = -ENODEV; |
| 446 | break; |
| 447 | } |
Frank Schaefer | e4b7131 | 2013-03-27 17:06:36 -0300 | [diff] [blame] | 448 | |
Hans Verkuil | ebf984b | 2015-04-09 04:05:59 -0300 | [diff] [blame] | 449 | format.format.code = MEDIA_BUS_FMT_YUYV8_2X8; |
| 450 | format.format.width = 640; |
| 451 | format.format.height = 480; |
| 452 | v4l2_subdev_call(subdev, pad, set_fmt, NULL, &format); |
Frank Schaefer | e4b7131 | 2013-03-27 17:06:36 -0300 | [diff] [blame] | 453 | |
| 454 | /* NOTE: for UXGA=1600x1200 switch to 12MHz */ |
| 455 | dev->board.xclk = EM28XX_XCLK_FREQUENCY_24MHZ; |
| 456 | em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk); |
Frank Schaefer | 9297285 | 2014-03-24 16:33:15 -0300 | [diff] [blame] | 457 | v4l2->vinmode = 0x08; |
| 458 | v4l2->vinctl = 0x00; |
Frank Schaefer | e4b7131 | 2013-03-27 17:06:36 -0300 | [diff] [blame] | 459 | |
| 460 | break; |
| 461 | } |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 462 | case EM28XX_NOSENSOR: |
| 463 | default: |
Guennadi Liakhovetski | fc5d0f8 | 2013-08-28 10:28:28 -0300 | [diff] [blame] | 464 | ret = -EINVAL; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 465 | } |
| 466 | |
Guennadi Liakhovetski | fc5d0f8 | 2013-08-28 10:28:28 -0300 | [diff] [blame] | 467 | if (ret < 0) { |
Frank Schaefer | 2c52a2f | 2014-03-24 16:33:11 -0300 | [diff] [blame] | 468 | v4l2_clk_unregister_fixed(v4l2->clk); |
| 469 | v4l2->clk = NULL; |
Guennadi Liakhovetski | fc5d0f8 | 2013-08-28 10:28:28 -0300 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | return ret; |
Frank Schaefer | 855ff38 | 2013-03-27 17:06:31 -0300 | [diff] [blame] | 473 | } |
Mauro Carvalho Chehab | 01c2819 | 2013-12-22 13:27:02 -0300 | [diff] [blame] | 474 | EXPORT_SYMBOL_GPL(em28xx_init_camera); |