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