19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
49 static const struct ctrl s5k83a_ctrls[] = {
62 .set = s5k83a_set_gain,
63 .get = s5k83a_get_gain
66 #define BRIGHTNESS_IDX 1
78 .set = s5k83a_set_brightness,
79 .get = s5k83a_get_brightness,
81 #define EXPOSURE_IDX 2
93 .set = s5k83a_set_exposure,
94 .get = s5k83a_get_exposure
101 .name =
"horizontal flip",
107 .set = s5k83a_set_hflip,
108 .get = s5k83a_get_hflip
115 .name =
"vertical flip",
121 .set = s5k83a_set_vflip,
122 .get = s5k83a_get_vflip
126 static void s5k83a_dump_registers(
struct sd *
sd);
128 static int s5k83a_set_led_indication(
struct sd *
sd,
u8 val);
135 u8 prod_id = 0, ver_id = 0;
140 pr_info(
"Forcing a %s sensor\n", s5k83a.name);
148 PDEBUG(D_PROBE,
"Probing for a s5k83a sensor");
152 u8 data[2] = {preinit_s5k83a[
i][2], preinit_s5k83a[
i][3]};
153 if (preinit_s5k83a[i][0] ==
SENSOR)
170 if ((prod_id == 0xff) || (ver_id == 0xff))
173 pr_info(
"Detected a s5k83a sensor\n");
188 sd->
gspca_dev.cam.cam_mode = s5k83a_modes;
190 sd->
desc->ctrls = s5k83a_ctrls;
196 for (i = 0; i <
ARRAY_SIZE(s5k83a_ctrls); i++)
197 sens_priv->
settings[i] = s5k83a_ctrls[i].
qctrl.default_value;
206 s32 *sensor_settings =
210 u8 data[2] = {0x00, 0x00};
212 switch (init_s5k83a[i][0]) {
220 data[0] = init_s5k83a[
i][2];
222 init_s5k83a[i][1], data, 1);
226 data[0] = init_s5k83a[
i][2];
227 data[1] = init_s5k83a[
i][3];
229 init_s5k83a[i][1], data, 2);
232 pr_info(
"Invalid stream command, exiting init\n");
238 s5k83a_dump_registers(sd);
244 err = s5k83a_set_brightness(&sd->
gspca_dev,
249 err = s5k83a_set_exposure(&sd->
gspca_dev,
263 static int rotation_thread_function(
void *
data)
265 struct sd *
sd = (
struct sd *) data;
267 u8 reg, previous_rotation = 0;
275 s5k83a_get_rotation(sd, ®);
276 if (previous_rotation != reg) {
277 previous_rotation =
reg;
278 pr_info(
"Camera was flipped\n");
280 s5k83a_get_vflip((
struct gspca_dev *) sd, &vflip);
281 s5k83a_get_hflip((
struct gspca_dev *) sd, &hflip);
287 s5k83a_set_flip_real((
struct gspca_dev *) sd,
296 if (previous_rotation) {
297 s5k83a_get_vflip((
struct gspca_dev *) sd, &vflip);
298 s5k83a_get_hflip((
struct gspca_dev *) sd, &hflip);
299 s5k83a_set_flip_real((
struct gspca_dev *) sd, vflip, hflip);
315 sd,
"rotation thread");
320 u8 data[2] = {start_s5k83a[
i][2], start_s5k83a[
i][3]};
321 if (start_s5k83a[i][0] ==
SENSOR)
331 return s5k83a_set_led_indication(sd, 1);
341 return s5k83a_set_led_indication(sd, 0);
357 struct sd *sd = (
struct sd *) gspca_dev;
368 struct sd *sd = (
struct sd *) gspca_dev;
394 static int s5k83a_get_brightness(
struct gspca_dev *gspca_dev,
__s32 *val)
396 struct sd *sd = (
struct sd *) gspca_dev;
403 static int s5k83a_set_brightness(
struct gspca_dev *gspca_dev,
__s32 val)
407 struct sd *sd = (
struct sd *) gspca_dev;
416 static int s5k83a_get_exposure(
struct gspca_dev *gspca_dev,
__s32 *val)
418 struct sd *sd = (
struct sd *) gspca_dev;
425 static int s5k83a_set_exposure(
struct gspca_dev *gspca_dev,
__s32 val)
429 struct sd *sd = (
struct sd *) gspca_dev;
439 static int s5k83a_get_vflip(
struct gspca_dev *gspca_dev,
__s32 *val)
441 struct sd *sd = (
struct sd *) gspca_dev;
448 static int s5k83a_set_flip_real(
struct gspca_dev *gspca_dev,
453 struct sd *sd = (
struct sd *) gspca_dev;
462 data[0] = (
vflip) ? data[0] | 0x40 : data[0];
463 data[0] = (
hflip) ? data[0] | 0x80 : data[0];
469 data[0] = (
vflip) ? 0x0b : 0x0a;
474 data[0] = (
hflip) ? 0x0a : 0x0b;
479 static int s5k83a_set_vflip(
struct gspca_dev *gspca_dev,
__s32 val)
484 struct sd *sd = (
struct sd *) gspca_dev;
489 s5k83a_get_hflip(gspca_dev, &hflip);
491 err = s5k83a_get_rotation(sd, ®);
499 err = s5k83a_set_flip_real(gspca_dev, val, hflip);
503 static int s5k83a_get_hflip(
struct gspca_dev *gspca_dev,
__s32 *val)
505 struct sd *sd = (
struct sd *) gspca_dev;
512 static int s5k83a_set_hflip(
struct gspca_dev *gspca_dev,
__s32 val)
517 struct sd *sd = (
struct sd *) gspca_dev;
522 s5k83a_get_vflip(gspca_dev, &vflip);
524 err = s5k83a_get_rotation(sd, ®);
532 err = s5k83a_set_flip_real(gspca_dev, vflip, val);
536 static int s5k83a_set_led_indication(
struct sd *sd,
u8 val)
556 static int s5k83a_get_rotation(
struct sd *sd,
u8 *
reg_data)
563 static void s5k83a_dump_registers(
struct sd *sd)
569 for (page = 0; page < 16; page++) {
571 pr_info(
"Dumping the s5k83a register state for page 0x%x\n",
573 for (address = 0; address <= 0xff; address++) {
576 pr_info(
"register 0x%x contains 0x%x\n", address, val);
579 pr_info(
"s5k83a register state dump complete\n");
581 for (page = 0; page < 16; page++) {
583 pr_info(
"Probing for which registers that are read/write for page 0x%x\n",
585 for (address = 0; address <= 0xff; address++) {
586 u8 old_val, ctrl_val, test_val = 0xff;
592 if (ctrl_val == test_val)
593 pr_info(
"register 0x%x is writeable\n",
596 pr_info(
"register 0x%x is read only\n",
603 pr_info(
"Read/write register probing complete\n");