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