static inline int s5k6aafx_write(struct i2c_client *client, unsigned long packet) { unsigned char buf[4]; int err = 0; int retry_count = 5; struct i2c_msg msg = { .addr = client->addr, .flags = 0, .buf = buf, .len = 4, }; // printk("%s: %d Start 1 \n", __func__, __LINE__); if (!client->adapter) { dev_err(&client->dev, "%s: can't search i2c client adapter\n", __func__); return -EIO; } while(retry_count--) { *(unsigned long *)buf = cpu_to_be32(packet); err = i2c_transfer(client->adapter, &msg, 1); if (likely(err == 1)) { // printk("%s: %d Start 2 \n", __func__, __LINE__); break; } mdelay(10); // printk("%s: %d Start 3 \n", __func__, __LINE__); } if (unlikely(err < 0)) { dev_err(&client->dev, "%s: 0x%08x write failed\n", __func__, (unsigned int)packet); return err; } // printk("%s: %d Start 4 %d \n", __func__, __LINE__,err); return (err != 1) ? -1 : 0; } /* program multiple registers */ static int s5k6aafx_write_regs( unsigned long *packet, unsigned int num) { struct i2c_client *client = s5k6aafx_client; int ret = -EAGAIN; /* FIXME */ unsigned long temp; char delay = 0; while (num--) { temp = *packet++; /* if ((temp & S5K6AAFX_DELAY) == S5K6AAFX_DELAY) { if (temp & 0x1) { dev_info(&client->dev, "delay for 100msec\n"); msleep(100); continue; } else { dev_info(&client->dev, "delay for 10msec\n"); msleep(10); continue; } } */ #if 1 if ((temp & S5K6AAFX_DELAY) == S5K6AAFX_DELAY) { delay = temp & 0xFFFF; //printk("func(%s):line(%d):delay(0x%x):delay(%d)\n",__func__,__LINE__,delay,delay); msleep(delay); continue; } #endif ret = s5k6aafx_write(client, temp); /* In error circumstances */ /* Give second shot */ if (unlikely(ret)) { dev_info(&client->dev, "s5k6aafx i2c retry one more time\n"); ret = s5k6aafx_write(client, temp); /* Give it one more shot */ if (unlikely(ret)) { dev_info(&client->dev, "s5k6aafx i2c retry twice\n"); ret = s5k6aafx_write(client, temp); break; } } } dev_info(&client->dev, "S5K6AAFX register programming ends up\n"); if( ret < 0) return -EIO; return ret; /* FIXME */ } static int s5k6aafx_set_capture_start() { struct i2c_client *client = s5k6aafx_client; int err = -EINVAL; unsigned short lvalue = 0; s5k6aafx_write(client, 0x002C7000); s5k6aafx_write(client, 0x002E1AAA); //read light value s5k6aafx_read(client, 0x0F12, &lvalue); printk("%s : light value is %x\n", __func__, lvalue); /* set initial regster value */ err = s5k6aafx_write_regs(s5k6aafx_capture, sizeof(s5k6aafx_capture) / sizeof(s5k6aafx_capture[0])); if (lvalue < 0x40) { printk("\n----- low light -----\n\n"); mdelay(100);//add 100 ms delay for capture sequence } else { printk("\n----- normal light -----\n\n"); mdelay(50); } if (unlikely(err)) { printk("%s: failed to make capture\n", __func__); return err; } return err; } static int s5k6aafx_set_preview_start() { // struct i2c_client *client = s5k6aafx_client; int err = -EINVAL; printk("%s: set_Preview_start\n", __func__); #if 0 if(state->check_dataline) // Output Test Pattern from VGA sensor { printk(" pattern on setting~~~~~~~~~~~\n"); err = s5k6aafx_write_regs(sd, s5k6aafx_pattern_on, sizeof(s5k6aafx_pattern_on) / sizeof(s5k6aafx_pattern_on[0])); // mdelay(200); } else { #endif /* set initial regster value */ err = s5k6aafx_write_regs(s5k6aafx_preview, sizeof(s5k6aafx_preview) / sizeof(s5k6aafx_preview[0])); if (unlikely(err)) { printk("%s: failed to make preview\n", __func__); return err; } // } // mdelay(200); // add 200 ms for displaying preview return err; } static int s5k6aafx_set_preview_stop() { int err = 0; return err; }
static inline int s5k6aafx_write(struct i2c_client *client, unsigned long packet) { unsigned char buf[4]; int err = 0; int retry_count = 5; struct i2c_msg msg = { .addr = client->addr, .flags = 0, .buf = buf, .len = 4, }; if (!client->adapter) { dev_err(&client->dev, "%s: can't search i2c client adapter\n", __func__); return -EIO; } while(retry_count--) { *(unsigned long *)buf = cpu_to_be32(packet); err = i2c_transfer(client->adapter, &msg, 1); if (likely(err == 1)) break; mdelay(10); } if (unlikely(err < 0)) { dev_err(&client->dev, "%s: 0x%08x write failed\n", __func__, (unsigned int)packet); return err; } return (err != 1) ? -1 : 0; } #ifdef CONFIG_LOAD_FILE static int s5k6aafx_write_regs_from_sd(struct v4l2_subdev *sd, char s_name[]) { struct i2c_client *client = v4l2_get_subdevdata(sd); struct test *tempData; int ret = -EAGAIN; unsigned long temp; char delay = 0; char data[11]; int searched = 0; int size = strlen(s_name); int i; FUNC_ENTR(); printk("size = %d, string = %s\n", size, s_name); tempData = &testBuf[0]; while(!searched) { searched = 1; for (i = 0; i < size; i++) { if (tempData->data != s_name[i]) { searched = 0; break; } tempData = tempData->nextBuf; } tempData = tempData->nextBuf; } //structure is get.. while(1) { if (tempData->data == '{') { break; } else { tempData = tempData->nextBuf; } } while (1) { searched = 0; while (1) { if (tempData->data == 'x') { //get 10 strings data[0] = '0'; for (i = 1; i < 11; i++) { data[i] = tempData->data; tempData = tempData->nextBuf; } //printk("%s\n", data); temp = simple_strtoul(data, NULL, 16); break; } else if (tempData->data == '}') { searched = 1; break; } else { tempData = tempData->nextBuf; } if (tempData->nextBuf == NULL) { return -1; } } if (searched) { break; } //let search... if ((temp & S5K6AAFX_DELAY) == S5K6AAFX_DELAY) { delay = temp & 0xFFFF; //printk("func(%s):line(%d):delay(0x%x):delay(%d)\n",__func__,__LINE__,delay,delay); msleep(delay); continue; } ret = s5k6aafx_write(client, temp); /* In error circumstances */ /* Give second shot */ if (unlikely(ret)) { dev_info(&client->dev, "s5k6aafx i2c retry one more time\n"); ret = s5k6aafx_write(client, temp); /* Give it one more shot */ if (unlikely(ret)) { dev_info(&client->dev, "s5k6aafx i2c retry twice\n"); ret = s5k6aafx_write(client, temp); } } } return ret; } #endif /* program multiple registers */ static int s5k6aafx_write_regs(struct v4l2_subdev *sd, unsigned long *packet, unsigned int num) { struct i2c_client *client = v4l2_get_subdevdata(sd); int ret = -EAGAIN; /* FIXME */ unsigned long temp; char delay = 0; while (num--) { temp = *packet++; /* if ((temp & S5K6AAFX_DELAY) == S5K6AAFX_DELAY) { if (temp & 0x1) { dev_info(&client->dev, "delay for 100msec\n"); msleep(100); continue; } else { dev_info(&client->dev, "delay for 10msec\n"); msleep(10); continue; } } */ #if 1 if ((temp & S5K6AAFX_DELAY) == S5K6AAFX_DELAY) { delay = temp & 0xFFFF; //printk("func(%s):line(%d):delay(0x%x):delay(%d)\n",__func__,__LINE__,delay,delay); msleep(delay); continue; } #endif ret = s5k6aafx_write(client, temp); /* In error circumstances */ /* Give second shot */ if (unlikely(ret)) { dev_info(&client->dev, "s5k6aafx i2c retry one more time\n"); ret = s5k6aafx_write(client, temp); /* Give it one more shot */ if (unlikely(ret)) { dev_info(&client->dev, "s5k6aafx i2c retry twice\n"); ret = s5k6aafx_write(client, temp); break; } } } dev_info(&client->dev, "S5K6AAFX register programming ends up\n"); if( ret < 0) return -EIO; return ret; /* FIXME */ } static int s5k6aafx_set_capture_start(struct v4l2_subdev *sd, struct v4l2_control *ctrl) { struct i2c_client *client = v4l2_get_subdevdata(sd); struct s5k6aafx_state *state = to_state(sd); int err = -EINVAL; unsigned short lvalue = 0; FUNC_ENTR(); s5k6aafx_write(client, 0x002C7000); s5k6aafx_write(client, 0x002E1AAA); //read light value s5k6aafx_read(client, 0x0F12, &lvalue); printk("%s : light value is %x\n", __func__, lvalue); /* set initial regster value */ #ifdef CONFIG_LOAD_FILE err = s5k6aafx_write_regs_from_sd(sd, "s5k6aafx_capture"); #else err = s5k6aafx_write_regs(sd, s5k6aafx_capture, sizeof(s5k6aafx_capture) / sizeof(s5k6aafx_capture[0])); #endif if (lvalue < 0x40) { printk("\n----- low light -----\n\n"); mdelay(100);//add 100 ms delay for capture sequence } else { printk("\n----- normal light -----\n\n"); mdelay(50); } if (unlikely(err)) { printk("%s: failed to make capture\n", __func__); return err; } state->runmode = S5K6AAFX_RUNMODE_IDLE; return err; } static int s5k6aafx_set_preview_start(struct v4l2_subdev *sd) { struct i2c_client *client = v4l2_get_subdevdata(sd); struct s5k6aafx_state *state = to_state(sd); int err = -EINVAL; FUNC_ENTR(); dev_info(&client->dev, "%s: set_Preview_start\n", __func__); if(state->check_dataline) // Output Test Pattern from VGA sensor { printk(" pattern on setting~~~~~~~~~~~\n"); err = s5k6aafx_write_regs(sd, s5k6aafx_pattern_on, sizeof(s5k6aafx_pattern_on) / sizeof(s5k6aafx_pattern_on[0])); // mdelay(200); } else { /* set initial regster value */ #ifdef CONFIG_LOAD_FILE err = s5k6aafx_write_regs_from_sd(sd, "s5k6aafx_preview"); #else err = s5k6aafx_write_regs(sd, s5k6aafx_preview, sizeof(s5k6aafx_preview) / sizeof(s5k6aafx_preview[0])); #endif if (unlikely(err)) { printk("%s: failed to make preview\n", __func__); return err; } } if(state->set_vhflip == 1) { err = s5k6aafx_write_regs(sd, s5k6aafx_vhflip_on, sizeof(s5k6aafx_vhflip_on) / sizeof(s5k6aafx_vhflip_on[0])); } state->runmode = S5K6AAFX_RUNMODE_RUNNING; // mdelay(200); // add 200 ms for displaying preview return err; } static int s5k6aafx_set_preview_stop(struct v4l2_subdev *sd) { struct s5k6aafx_state *state = to_state(sd); int err = 0; state->runmode = S5K6AAFX_RUNMODE_IDLE; return err; } #if 0 static int s5k6aafx_s_crystal_freq(struct v4l2_subdev *sd, u32 freq, u32 flags) { int err = -EINVAL; FUNC_ENTR(); return err; }