wis-ov7640.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2005-2006 Micronas USA Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License (Version 2) as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software Foundation,
  15. * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/i2c.h>
  20. #include <linux/videodev2.h>
  21. #include "wis-i2c.h"
  22. struct wis_ov7640 {
  23. int brightness;
  24. int contrast;
  25. int saturation;
  26. int hue;
  27. };
  28. static u8 initial_registers[] =
  29. {
  30. 0x12, 0x80,
  31. 0x12, 0x54,
  32. 0x14, 0x24,
  33. 0x15, 0x01,
  34. 0x28, 0x20,
  35. 0x75, 0x82,
  36. 0xFF, 0xFF, /* Terminator (reg 0xFF is unused) */
  37. };
  38. static int write_regs(struct i2c_client *client, u8 *regs)
  39. {
  40. int i;
  41. for (i = 0; regs[i] != 0xFF; i += 2)
  42. if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0)
  43. return -1;
  44. return 0;
  45. }
  46. static int wis_ov7640_probe(struct i2c_client *client,
  47. const struct i2c_device_id *id)
  48. {
  49. struct i2c_adapter *adapter = client->adapter;
  50. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  51. return -ENODEV;
  52. client->flags = I2C_CLIENT_SCCB;
  53. printk(KERN_DEBUG
  54. "wis-ov7640: initializing OV7640 at address %d on %s\n",
  55. client->addr, adapter->name);
  56. if (write_regs(client, initial_registers) < 0) {
  57. printk(KERN_ERR "wis-ov7640: error initializing OV7640\n");
  58. return -ENODEV;
  59. }
  60. return 0;
  61. }
  62. static int wis_ov7640_remove(struct i2c_client *client)
  63. {
  64. return 0;
  65. }
  66. static const struct i2c_device_id wis_ov7640_id[] = {
  67. { "wis_ov7640", 0 },
  68. { }
  69. };
  70. MODULE_DEVICE_TABLE(i2c, wis_ov7640_id);
  71. static struct i2c_driver wis_ov7640_driver = {
  72. .driver = {
  73. .name = "WIS OV7640 I2C driver",
  74. },
  75. .probe = wis_ov7640_probe,
  76. .remove = wis_ov7640_remove,
  77. .id_table = wis_ov7640_id,
  78. };
  79. static int __init wis_ov7640_init(void)
  80. {
  81. return i2c_add_driver(&wis_ov7640_driver);
  82. }
  83. static void __exit wis_ov7640_cleanup(void)
  84. {
  85. i2c_del_driver(&wis_ov7640_driver);
  86. }
  87. module_init(wis_ov7640_init);
  88. module_exit(wis_ov7640_cleanup);
  89. MODULE_LICENSE("GPL v2");