Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * indycam.c - Silicon Graphics IndyCam digital camera driver |
| 3 | * |
| 4 | * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org> |
| 5 | * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi> |
| 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 version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 12 | #include <linux/delay.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/fs.h> |
Ladislav Michl | 495515b | 2005-09-23 10:52:27 +0000 | [diff] [blame] | 15 | #include <linux/init.h> |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 16 | #include <linux/kernel.h> |
| 17 | #include <linux/major.h> |
Ladislav Michl | 495515b | 2005-09-23 10:52:27 +0000 | [diff] [blame] | 18 | #include <linux/module.h> |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 19 | #include <linux/mm.h> |
Ladislav Michl | 495515b | 2005-09-23 10:52:27 +0000 | [diff] [blame] | 20 | #include <linux/slab.h> |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 21 | |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 22 | /* IndyCam decodes stream of photons into digital image representation ;-) */ |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 23 | #include <linux/videodev2.h> |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 24 | #include <linux/i2c.h> |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 25 | #include <media/v4l2-device.h> |
| 26 | #include <media/v4l2-chip-ident.h> |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 27 | |
| 28 | #include "indycam.h" |
| 29 | |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 30 | #define INDYCAM_MODULE_VERSION "0.0.5" |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 31 | |
| 32 | MODULE_DESCRIPTION("SGI IndyCam driver"); |
| 33 | MODULE_VERSION(INDYCAM_MODULE_VERSION); |
| 34 | MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>"); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 37 | |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 38 | // #define INDYCAM_DEBUG |
| 39 | |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 40 | #ifdef INDYCAM_DEBUG |
| 41 | #define dprintk(x...) printk("IndyCam: " x); |
| 42 | #define indycam_regdump(client) indycam_regdump_debug(client) |
| 43 | #else |
| 44 | #define dprintk(x...) |
| 45 | #define indycam_regdump(client) |
| 46 | #endif |
| 47 | |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 48 | struct indycam { |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 49 | struct v4l2_subdev sd; |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 50 | u8 version; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 53 | static inline struct indycam *to_indycam(struct v4l2_subdev *sd) |
| 54 | { |
| 55 | return container_of(sd, struct indycam, sd); |
| 56 | } |
| 57 | |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 58 | static const u8 initseq[] = { |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 59 | INDYCAM_CONTROL_AGCENA, /* INDYCAM_CONTROL */ |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 60 | INDYCAM_SHUTTER_60, /* INDYCAM_SHUTTER */ |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 61 | INDYCAM_GAIN_DEFAULT, /* INDYCAM_GAIN */ |
| 62 | 0x00, /* INDYCAM_BRIGHTNESS (read-only) */ |
| 63 | INDYCAM_RED_BALANCE_DEFAULT, /* INDYCAM_RED_BALANCE */ |
| 64 | INDYCAM_BLUE_BALANCE_DEFAULT, /* INDYCAM_BLUE_BALANCE */ |
| 65 | INDYCAM_RED_SATURATION_DEFAULT, /* INDYCAM_RED_SATURATION */ |
| 66 | INDYCAM_BLUE_SATURATION_DEFAULT,/* INDYCAM_BLUE_SATURATION */ |
| 67 | }; |
| 68 | |
| 69 | /* IndyCam register handling */ |
| 70 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 71 | static int indycam_read_reg(struct v4l2_subdev *sd, u8 reg, u8 *value) |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 72 | { |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 73 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 74 | int ret; |
| 75 | |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 76 | if (reg == INDYCAM_REG_RESET) { |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 77 | dprintk("indycam_read_reg(): " |
| 78 | "skipping write-only register %d\n", reg); |
| 79 | *value = 0; |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | ret = i2c_smbus_read_byte_data(client, reg); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 84 | |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 85 | if (ret < 0) { |
| 86 | printk(KERN_ERR "IndyCam: indycam_read_reg(): read failed, " |
| 87 | "register = 0x%02x\n", reg); |
| 88 | return ret; |
| 89 | } |
| 90 | |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 91 | *value = (u8)ret; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 96 | static int indycam_write_reg(struct v4l2_subdev *sd, u8 reg, u8 value) |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 97 | { |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 98 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 99 | int err; |
| 100 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 101 | if (reg == INDYCAM_REG_BRIGHTNESS || reg == INDYCAM_REG_VERSION) { |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 102 | dprintk("indycam_write_reg(): " |
| 103 | "skipping read-only register %d\n", reg); |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | dprintk("Writing Reg %d = 0x%02x\n", reg, value); |
| 108 | err = i2c_smbus_write_byte_data(client, reg, value); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 109 | |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 110 | if (err) { |
| 111 | printk(KERN_ERR "IndyCam: indycam_write_reg(): write failed, " |
| 112 | "register = 0x%02x, value = 0x%02x\n", reg, value); |
| 113 | } |
| 114 | return err; |
| 115 | } |
| 116 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 117 | static int indycam_write_block(struct v4l2_subdev *sd, u8 reg, |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 118 | u8 length, u8 *data) |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 119 | { |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 120 | int i, err; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 121 | |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 122 | for (i = 0; i < length; i++) { |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 123 | err = indycam_write_reg(sd, reg + i, data[i]); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 124 | if (err) |
| 125 | return err; |
| 126 | } |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | /* Helper functions */ |
| 132 | |
| 133 | #ifdef INDYCAM_DEBUG |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 134 | static void indycam_regdump_debug(struct v4l2_subdev *sd) |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 135 | { |
| 136 | int i; |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 137 | u8 val; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 138 | |
| 139 | for (i = 0; i < 9; i++) { |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 140 | indycam_read_reg(sd, i, &val); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 141 | dprintk("Reg %d = 0x%02x\n", i, val); |
| 142 | } |
| 143 | } |
| 144 | #endif |
| 145 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 146 | static int indycam_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 147 | { |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 148 | struct indycam *camera = to_indycam(sd); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 149 | u8 reg; |
| 150 | int ret = 0; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 151 | |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 152 | switch (ctrl->id) { |
| 153 | case V4L2_CID_AUTOGAIN: |
| 154 | case V4L2_CID_AUTO_WHITE_BALANCE: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 155 | ret = indycam_read_reg(sd, INDYCAM_REG_CONTROL, ®); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 156 | if (ret) |
| 157 | return -EIO; |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 158 | if (ctrl->id == V4L2_CID_AUTOGAIN) |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 159 | ctrl->value = (reg & INDYCAM_CONTROL_AGCENA) |
| 160 | ? 1 : 0; |
| 161 | else |
| 162 | ctrl->value = (reg & INDYCAM_CONTROL_AWBCTL) |
| 163 | ? 1 : 0; |
| 164 | break; |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 165 | case V4L2_CID_EXPOSURE: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 166 | ret = indycam_read_reg(sd, INDYCAM_REG_SHUTTER, ®); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 167 | if (ret) |
| 168 | return -EIO; |
| 169 | ctrl->value = ((s32)reg == 0x00) ? 0xff : ((s32)reg - 1); |
| 170 | break; |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 171 | case V4L2_CID_GAIN: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 172 | ret = indycam_read_reg(sd, INDYCAM_REG_GAIN, ®); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 173 | if (ret) |
| 174 | return -EIO; |
| 175 | ctrl->value = (s32)reg; |
| 176 | break; |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 177 | case V4L2_CID_RED_BALANCE: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 178 | ret = indycam_read_reg(sd, INDYCAM_REG_RED_BALANCE, ®); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 179 | if (ret) |
| 180 | return -EIO; |
| 181 | ctrl->value = (s32)reg; |
| 182 | break; |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 183 | case V4L2_CID_BLUE_BALANCE: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 184 | ret = indycam_read_reg(sd, INDYCAM_REG_BLUE_BALANCE, ®); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 185 | if (ret) |
| 186 | return -EIO; |
| 187 | ctrl->value = (s32)reg; |
| 188 | break; |
| 189 | case INDYCAM_CONTROL_RED_SATURATION: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 190 | ret = indycam_read_reg(sd, |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 191 | INDYCAM_REG_RED_SATURATION, ®); |
| 192 | if (ret) |
| 193 | return -EIO; |
| 194 | ctrl->value = (s32)reg; |
| 195 | break; |
| 196 | case INDYCAM_CONTROL_BLUE_SATURATION: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 197 | ret = indycam_read_reg(sd, |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 198 | INDYCAM_REG_BLUE_SATURATION, ®); |
| 199 | if (ret) |
| 200 | return -EIO; |
| 201 | ctrl->value = (s32)reg; |
| 202 | break; |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 203 | case V4L2_CID_GAMMA: |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 204 | if (camera->version == CAMERA_VERSION_MOOSE) { |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 205 | ret = indycam_read_reg(sd, |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 206 | INDYCAM_REG_GAMMA, ®); |
| 207 | if (ret) |
| 208 | return -EIO; |
| 209 | ctrl->value = (s32)reg; |
| 210 | } else { |
| 211 | ctrl->value = INDYCAM_GAMMA_DEFAULT; |
| 212 | } |
| 213 | break; |
| 214 | default: |
| 215 | ret = -EINVAL; |
| 216 | } |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 217 | |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 218 | return ret; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 221 | static int indycam_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 222 | { |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 223 | struct indycam *camera = to_indycam(sd); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 224 | u8 reg; |
| 225 | int ret = 0; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 226 | |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 227 | switch (ctrl->id) { |
| 228 | case V4L2_CID_AUTOGAIN: |
| 229 | case V4L2_CID_AUTO_WHITE_BALANCE: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 230 | ret = indycam_read_reg(sd, INDYCAM_REG_CONTROL, ®); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 231 | if (ret) |
| 232 | break; |
| 233 | |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 234 | if (ctrl->id == V4L2_CID_AUTOGAIN) { |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 235 | if (ctrl->value) |
| 236 | reg |= INDYCAM_CONTROL_AGCENA; |
| 237 | else |
| 238 | reg &= ~INDYCAM_CONTROL_AGCENA; |
| 239 | } else { |
| 240 | if (ctrl->value) |
| 241 | reg |= INDYCAM_CONTROL_AWBCTL; |
| 242 | else |
| 243 | reg &= ~INDYCAM_CONTROL_AWBCTL; |
| 244 | } |
| 245 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 246 | ret = indycam_write_reg(sd, INDYCAM_REG_CONTROL, reg); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 247 | break; |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 248 | case V4L2_CID_EXPOSURE: |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 249 | reg = (ctrl->value == 0xff) ? 0x00 : (ctrl->value + 1); |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 250 | ret = indycam_write_reg(sd, INDYCAM_REG_SHUTTER, reg); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 251 | break; |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 252 | case V4L2_CID_GAIN: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 253 | ret = indycam_write_reg(sd, INDYCAM_REG_GAIN, ctrl->value); |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 254 | break; |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 255 | case V4L2_CID_RED_BALANCE: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 256 | ret = indycam_write_reg(sd, INDYCAM_REG_RED_BALANCE, |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 257 | ctrl->value); |
| 258 | break; |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 259 | case V4L2_CID_BLUE_BALANCE: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 260 | ret = indycam_write_reg(sd, INDYCAM_REG_BLUE_BALANCE, |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 261 | ctrl->value); |
| 262 | break; |
| 263 | case INDYCAM_CONTROL_RED_SATURATION: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 264 | ret = indycam_write_reg(sd, INDYCAM_REG_RED_SATURATION, |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 265 | ctrl->value); |
| 266 | break; |
| 267 | case INDYCAM_CONTROL_BLUE_SATURATION: |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 268 | ret = indycam_write_reg(sd, INDYCAM_REG_BLUE_SATURATION, |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 269 | ctrl->value); |
| 270 | break; |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 271 | case V4L2_CID_GAMMA: |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 272 | if (camera->version == CAMERA_VERSION_MOOSE) { |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 273 | ret = indycam_write_reg(sd, INDYCAM_REG_GAMMA, |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 274 | ctrl->value); |
| 275 | } |
| 276 | break; |
| 277 | default: |
| 278 | ret = -EINVAL; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 279 | } |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 280 | |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 281 | return ret; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /* I2C-interface */ |
| 285 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 286 | static int indycam_g_chip_ident(struct v4l2_subdev *sd, |
| 287 | struct v4l2_dbg_chip_ident *chip) |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 288 | { |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 289 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 290 | struct indycam *camera = to_indycam(sd); |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 291 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 292 | return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_INDYCAM, |
| 293 | camera->version); |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 294 | } |
| 295 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 296 | /* ----------------------------------------------------------------------- */ |
| 297 | |
| 298 | static const struct v4l2_subdev_core_ops indycam_core_ops = { |
| 299 | .g_chip_ident = indycam_g_chip_ident, |
| 300 | .g_ctrl = indycam_g_ctrl, |
| 301 | .s_ctrl = indycam_s_ctrl, |
| 302 | }; |
| 303 | |
| 304 | static const struct v4l2_subdev_ops indycam_ops = { |
| 305 | .core = &indycam_core_ops, |
| 306 | }; |
| 307 | |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 308 | static int indycam_probe(struct i2c_client *client, |
| 309 | const struct i2c_device_id *id) |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 310 | { |
| 311 | int err = 0; |
| 312 | struct indycam *camera; |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 313 | struct v4l2_subdev *sd; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 314 | |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 315 | v4l_info(client, "chip found @ 0x%x (%s)\n", |
| 316 | client->addr << 1, client->adapter->name); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 317 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 318 | camera = kzalloc(sizeof(struct indycam), GFP_KERNEL); |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 319 | if (!camera) |
| 320 | return -ENOMEM; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 321 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 322 | sd = &camera->sd; |
| 323 | v4l2_i2c_subdev_init(sd, client, &indycam_ops); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 324 | |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 325 | camera->version = i2c_smbus_read_byte_data(client, |
| 326 | INDYCAM_REG_VERSION); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 327 | if (camera->version != CAMERA_VERSION_INDY && |
| 328 | camera->version != CAMERA_VERSION_MOOSE) { |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 329 | kfree(camera); |
| 330 | return -ENODEV; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 331 | } |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 332 | |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 333 | printk(KERN_INFO "IndyCam v%d.%d detected\n", |
| 334 | INDYCAM_VERSION_MAJOR(camera->version), |
| 335 | INDYCAM_VERSION_MINOR(camera->version)); |
| 336 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 337 | indycam_regdump(sd); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 338 | |
| 339 | // initialize |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 340 | err = indycam_write_block(sd, 0, sizeof(initseq), (u8 *)&initseq); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 341 | if (err) { |
Joe Perches | c84e603 | 2008-02-03 17:18:59 +0200 | [diff] [blame] | 342 | printk(KERN_ERR "IndyCam initialization failed\n"); |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 343 | kfree(camera); |
| 344 | return -EIO; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 347 | indycam_regdump(sd); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 348 | |
| 349 | // white balance |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 350 | err = indycam_write_reg(sd, INDYCAM_REG_CONTROL, |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 351 | INDYCAM_CONTROL_AGCENA | INDYCAM_CONTROL_AWBCTL); |
| 352 | if (err) { |
Ladislav Michl | a637a11 | 2005-09-01 15:07:34 +0000 | [diff] [blame] | 353 | printk(KERN_ERR "IndyCam: White balancing camera failed\n"); |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 354 | kfree(camera); |
| 355 | return -EIO; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 358 | indycam_regdump(sd); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 359 | |
| 360 | printk(KERN_INFO "IndyCam initialized\n"); |
| 361 | |
| 362 | return 0; |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 365 | static int indycam_remove(struct i2c_client *client) |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 366 | { |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 367 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 368 | |
Hans Verkuil | 2b80a19 | 2009-02-13 19:38:10 -0300 | [diff] [blame] | 369 | v4l2_device_unregister_subdev(sd); |
| 370 | kfree(to_indycam(sd)); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 371 | return 0; |
| 372 | } |
| 373 | |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 374 | static const struct i2c_device_id indycam_id[] = { |
| 375 | { "indycam", 0 }, |
| 376 | { } |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 377 | }; |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 378 | MODULE_DEVICE_TABLE(i2c, indycam_id); |
Ralf Baechle | d203a7e | 2005-09-06 15:19:37 -0700 | [diff] [blame] | 379 | |
Hans Verkuil | 9f490cd | 2010-09-15 15:17:19 -0300 | [diff] [blame] | 380 | static struct i2c_driver indycam_driver = { |
| 381 | .driver = { |
| 382 | .owner = THIS_MODULE, |
| 383 | .name = "indycam", |
| 384 | }, |
| 385 | .probe = indycam_probe, |
| 386 | .remove = indycam_remove, |
| 387 | .id_table = indycam_id, |
Hans Verkuil | cf4e948 | 2009-02-27 09:05:10 -0300 | [diff] [blame] | 388 | }; |
Hans Verkuil | 9f490cd | 2010-09-15 15:17:19 -0300 | [diff] [blame] | 389 | |
| 390 | static __init int init_indycam(void) |
| 391 | { |
| 392 | return i2c_add_driver(&indycam_driver); |
| 393 | } |
| 394 | |
| 395 | static __exit void exit_indycam(void) |
| 396 | { |
| 397 | i2c_del_driver(&indycam_driver); |
| 398 | } |
| 399 | |
| 400 | module_init(init_indycam); |
| 401 | module_exit(exit_indycam); |