static int adv7180_suspend(struct soc_camera_device *icd, pm_message_t pm_msg) { DBG("%s", __FUNCTION__); if (pm_msg.event == PM_EVENT_SUSPEND) { adv7180_pwr_ctl(icd, 0); } return 0; }
static long adv7180_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) { struct i2c_client *client = v4l2_get_subdevdata(sd); struct soc_camera_device *icd = client->dev.platform_data; DBG("%s cmd %x", __FUNCTION__, cmd); if(cmd == RK29_CAM_SUBDEV_DEACTIVATE) adv7180_pwr_ctl(icd, 0); return 0; }
static int adv7180_v412_init(struct v4l2_subdev *sd, u32 val) { struct i2c_client *client = v4l2_get_subdevdata(sd); struct soc_camera_device *icd = client->dev.platform_data; struct adv7180_state *state = to_state(sd); int ret; DBG("%s val %d", __FUNCTION__, val); adv7180_pwr_ctl(icd, 1); /* Initialize adv7180 */ /* Enable autodetection */ ret = i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG, ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM_PED); if (ret < 0) goto err_unreg_subdev; ret = i2c_smbus_write_byte_data(client, ADV7180_AUTODETECT_ENABLE_REG, ADV7180_AUTODETECT_DEFAULT); if (ret < 0) goto err_unreg_subdev; /* ITU-R BT.656-4 compatible */ ret = i2c_smbus_write_byte_data(client, ADV7180_EXTENDED_OUTPUT_CONTROL_REG, ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS); if (ret < 0) goto err_unreg_subdev; /* set vs/field pin output vsync */ ret = i2c_smbus_write_byte_data(client, ADV7180_VS_FIELD_PIN_REG, ADV7180_VS_OUTPUT); if (ret < 0) goto err_unreg_subdev; /* set vs/hs polarity */ // ret = i2c_smbus_write_byte_data(client, // ADV7180_POLARITY_REG, // ADV7180_PCLK_NORMAIL | ADV7180_PVSYNC_LOW | ADV7180_PHSYNC_LOW); // if (ret < 0) // goto err_unreg_subdev; msleep(100); /* read current norm */ __adv7180_status(client, NULL, &state->curr_norm); return 0; err_unreg_subdev: return ret; }
static int adv7180_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct adv7180_state *state; struct v4l2_subdev *sd; struct soc_camera_device *icd = client->dev.platform_data; struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); int ret; printk("%s %d\n", __func__, __LINE__); /* Check if the adapter supports the needed features */ if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; printk("%s %d\n", __func__, __LINE__); v4l_info(client, "chip found @ 0x%02x (%s)\n", client->addr << 1, client->adapter->name); printk("%s %d\n", __func__, __LINE__); state = kzalloc(sizeof(struct adv7180_state), GFP_KERNEL); if (state == NULL) { ret = -ENOMEM; goto err; } printk("%s %d\n", __func__, __LINE__); rk30_mux_api_set(GPIO0B7_I2S8CHSDO3_NAME, GPIO0B_GPIO0B7); ret = gpio_request(ADV7180_CVBS_IN_DET, "ADV_CVBS_INT"); if (ret != 0) { gpio_free(ADV7180_CVBS_IN_DET); printk(KERN_ERR "request ADV7180_CVBS_IN_DET pin fail!\n"); return -1; } gpio_direction_input(ADV7180_CVBS_IN_DET); ret = gpio_request(ADV7180_YCRCB_IN_DET, "ADV_YCRCB_INT"); if (ret != 0) { gpio_free(ADV7180_YCRCB_IN_DET); printk(KERN_ERR "request ADV7180_YCRCB_IN_DET pin fail!\n"); return -1; } gpio_direction_input(ADV7180_YCRCB_IN_DET); state->cvbs_irq = gpio_to_irq(ADV7180_CVBS_IN_DET); state->ycrcb_irq = gpio_to_irq(ADV7180_YCRCB_IN_DET); INIT_WORK(&state->cvbs_work, adv7180_cvbs_work); INIT_WORK(&state->ycrcb_work, adv7180_ycrcb_work); mutex_init(&state->mutex); state->autodetect = true; sd = &state->sd; v4l2_i2c_subdev_init(sd, client, &adv7180_ops); state->icd = icd; icd->ops = &adv7180_sensor_ops; icd->user_width = adv7180_pic_sizes[0].width; icd->user_height = adv7180_pic_sizes[0].height; icd->colorspace = adv7180_colour_fmts[0].colorspace; adv7180_pwr_ctl(icd, 1); ret = 0; printk("%s %d\n", __func__, __LINE__); ret = i2c_smbus_read_byte_data(client, ADV7180_IDENT_REG); /* if (ret != ADV7180_ID_7180) goto err_unreg_subdev; */ printk("%s %d\n", __func__, __LINE__); ret = i2c_smbus_write_byte_data(client, 0x1d, 0x00); /* 27M/28M crystal */ int i; if(gpio_get_value(ADV7180_YCRCB_IN_DET)==GPIO_LOW) { printk("adv7180 ycrcb init\n"); for(i=0; i<15; i++) i2c_smbus_write_byte_data(client, init_ycrcb[i].reg, init_ycrcb[i].val); } else { printk("adv7180 cvbs init\n"); for(i=0; i<15; i++) i2c_smbus_write_byte_data(client, init_cvbs[i].reg, init_cvbs[i].val); } #if 0 /* register for interrupts */ if (state->irq > 0) { ret = request_irq(state->irq, adv7180_irq, 0, DRIVER_NAME, state); if (ret) goto err_unreg_subdev; printk("%s %d\n", __func__, __LINE__); ret = i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG, ADV7180_ADI_CTRL_IRQ_SPACE); if (ret < 0) goto err_unreg_subdev; printk("%s %d\n", __func__, __LINE__); /* config the Interrupt pin to be active low */ ret = i2c_smbus_write_byte_data(client, ADV7180_ICONF1_ADI, ADV7180_ICONF1_ACTIVE_LOW | ADV7180_ICONF1_PSYNC_ONLY); if (ret < 0) goto err_unreg_subdev; printk("%s %d\n", __func__, __LINE__); ret = i2c_smbus_write_byte_data(client, ADV7180_IMR1_ADI, 0); if (ret < 0) goto err_unreg_subdev; printk("%s %d\n", __func__, __LINE__); ret = i2c_smbus_write_byte_data(client, ADV7180_IMR2_ADI, 0); if (ret < 0) goto err_unreg_subdev; printk("%s %d\n", __func__, __LINE__); /* enable AD change interrupts interrupts */ ret = i2c_smbus_write_byte_data(client, ADV7180_IMR3_ADI, ADV7180_IRQ3_AD_CHANGE); if (ret < 0) goto err_unreg_subdev; printk("%s %d\n", __func__, __LINE__); ret = i2c_smbus_write_byte_data(client, ADV7180_IMR4_ADI, 0); if (ret < 0) goto err_unreg_subdev; printk("%s %d\n", __func__, __LINE__); ret = i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG, 0); if (ret < 0) goto err_unreg_subdev; printk("%s %d\n", __func__, __LINE__); } #endif adv7180_pwr_ctl(icd, 0); ret = device_create_file(&client->dev, &adv7180_dev_attr); if (ret) { printk("create device file failed!\n"); } v4l_info(client, "chip probe success @ 0x%02x (%s)\n", client->addr << 1, client->adapter->name); return 0; err_unreg_subdev: adv7180_pwr_ctl(icd, 0); mutex_destroy(&state->mutex); v4l2_device_unregister_subdev(sd); kfree(state); err: printk(KERN_ERR DRIVER_NAME ": Failed to probe: %d\n", ret); return ret; }
static int adv7180_resume(struct soc_camera_device *icd) { DBG("%s", __FUNCTION__); adv7180_pwr_ctl(icd, 1); return 0; }
static __devinit int adv7180_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct adv7180_state *state; struct v4l2_subdev *sd; struct soc_camera_device *icd = client->dev.platform_data; int ret; #ifndef CONFIG_ARCH_RK29 /* Check if the adapter supports the needed features */ if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EIO; #endif v4l_info(client, "chip found @ 0x%02x (%s)\n", client->addr << 1, client->adapter->name); state = kzalloc(sizeof(struct adv7180_state), GFP_KERNEL); if (state == NULL) { ret = -ENOMEM; goto err; } state->irq = client->irq; INIT_WORK(&state->work, adv7180_work); mutex_init(&state->mutex); state->autodetect = true; sd = &state->sd; v4l2_i2c_subdev_init(sd, client, &adv7180_ops); state->icd = icd; icd->ops = &adv7180_sensor_ops; icd->user_width = adv7180_pic_sizes[0].width; icd->user_height = adv7180_pic_sizes[0].height; icd->colorspace = adv7180_colour_fmts[0].colorspace; adv7180_pwr_ctl(icd, 1); ret = 0; ret = i2c_smbus_read_byte_data(client, ADV7180_IDENT_REG); if (ret != ADV7180_ID_7180) goto err_unreg_subdev; /* register for interrupts */ if (state->irq > 0) { ret = request_irq(state->irq, adv7180_irq, 0, DRIVER_NAME, state); if (ret) goto err_unreg_subdev; ret = i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG, ADV7180_ADI_CTRL_IRQ_SPACE); if (ret < 0) goto err_unreg_subdev; /* config the Interrupt pin to be active low */ ret = i2c_smbus_write_byte_data(client, ADV7180_ICONF1_ADI, ADV7180_ICONF1_ACTIVE_LOW | ADV7180_ICONF1_PSYNC_ONLY); if (ret < 0) goto err_unreg_subdev; ret = i2c_smbus_write_byte_data(client, ADV7180_IMR1_ADI, 0); if (ret < 0) goto err_unreg_subdev; ret = i2c_smbus_write_byte_data(client, ADV7180_IMR2_ADI, 0); if (ret < 0) goto err_unreg_subdev; /* enable AD change interrupts interrupts */ ret = i2c_smbus_write_byte_data(client, ADV7180_IMR3_ADI, ADV7180_IRQ3_AD_CHANGE); if (ret < 0) goto err_unreg_subdev; ret = i2c_smbus_write_byte_data(client, ADV7180_IMR4_ADI, 0); if (ret < 0) goto err_unreg_subdev; ret = i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG, 0); if (ret < 0) goto err_unreg_subdev; } adv7180_pwr_ctl(icd, 0); v4l_info(client, "chip probe success @ 0x%02x (%s)\n", client->addr << 1, client->adapter->name); return 0; err_unreg_subdev: adv7180_pwr_ctl(icd, 0); mutex_destroy(&state->mutex); v4l2_device_unregister_subdev(sd); kfree(state); err: printk(KERN_ERR DRIVER_NAME ": Failed to probe: %d\n", ret); return ret; }