static int lp8720_set_bits(struct lp8720 *lp8720, u8 reg, u16 mask, u16 val) { u8 tmp; int ret; mutex_lock(&lp8720->io_lock); ret = lp8720_i2c_read(lp8720->i2c, reg, 1, &tmp); tmp = (tmp & ~mask) | val; if (ret == 0) { ret = lp8720_i2c_write(lp8720->i2c, reg, 1, tmp); dev_dbg(lp8720->dev, "reg write 0x%02x -> 0x%02x\n", (int)reg, (unsigned)val & 0xff); } mutex_unlock(&lp8720->io_lock); return ret; }
static int mc7_sensor_power_on_off(int onoff, const struct msm_camera_sensor_info *data) { unsigned int mclk_cfg; int rc = 0; //FUNC_ENTER(); if (gpio_request(data->vcm_enable, "lsi_mc7")) printk(KERN_ERR "LSI-MC7: %s: gpio request 'vcm_enable' failed\n", __func__); if (gpio_request(data->sensor_reset, "lsi_mc7")) printk(KERN_ERR "LSI-MC7: %s: gpio request 'sensor_reset' failed\n", __func__); if (onoff) { printk(KERN_ERR "LSI-MC7: %s: POWER ON.\n", __func__); mclk_cfg = GPIO_CFG(15, 1, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA); gpio_direction_output(data->vcm_enable, 0); gpio_direction_output(data->sensor_reset, 0); /* By default BUCK is 1.2V so no need to configure the voltage; only change the start up time from NO start */ rc = lp8720_i2c_write(0x06, 0x1A); /* BUCK: no delay for 1.2v */ if (rc < 0) printk(KERN_ERR "%s: lp8720_i2c_write failed: %d\n",__func__, rc); lp8720_i2c_write(0x07, 0x09); /* BUCK:1.2v ; Not required by default it is 0x09 */ lp8720_i2c_write(0x05, 0x2C); /* LDO5:1.8V, delay of 1 'time step' ts */ lp8720_i2c_write(0x03, 0x2C); /* for janice 0.0 board 2011-01-20*/ lp8720_i2c_write(0x01, 0x19); /* LDO1:2.8v, no delay; For AF */ lp8720_i2c_write(0x02, 0x19); /* LDO2:2.8v, no delay; For the sensor */ //lp8720_i2c_write(0x08, 0xB3); /* Enable all voltages except LDO3 and LDO4 */ lp8720_i2c_write(0x08, 0xB7); /* for janice 0.0 board 2011-01-20*/ gpio_set_value(data->vcm_enable, 1); usleep(200); /* Enable MCLK */ gpio_tlmm_config(mclk_cfg, GPIO_CFG_ENABLE); udelay(50); /* Make RST pin high */ gpio_set_value(data->sensor_reset, 1); } else { printk(KERN_ERR "LSI-MC7: %s: POWER OFF.\n", __func__); gpio_direction_output(data->vcm_enable, 1); gpio_direction_output(data->sensor_reset, 1); mclk_cfg = GPIO_CFG(15, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA); /* Make RST pin low */ gpio_set_value(data->sensor_reset, 0); /* Disable MCLK */ gpio_tlmm_config(mclk_cfg, GPIO_CFG_ENABLE); udelay(50); /* Disable 1.8v, AF 2.8v and Sensor 2.8v */ lp8720_i2c_write(0x08, 0xA0); udelay(50); /* Disable 1.2v */ lp8720_i2c_write(0x08, 0x80); /* Disable lp8720 */ gpio_set_value(data->vcm_enable, 0); } gpio_free(data->vcm_enable); gpio_free(data->sensor_reset); return rc; }
static int __devinit lp8720_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct lp8720 *lp8720; struct lp8720_platform_data *pdata = i2c->dev.platform_data; int ret; u8 readbyte = 0; u8 enable = 0; if (!pdata) { dev_dbg(&i2c->dev, "No platform init data supplied\n"); return -ENODEV; } lp8720 = kzalloc(sizeof(struct lp8720), GFP_KERNEL); if (!lp8720) return -ENOMEM; lp8720->i2c = i2c; lp8720->dev = &i2c->dev; mutex_init(&lp8720->io_lock); #if 0 /* don't verify pmic register because pmic register is changed by bootloader */ ret = lp8720_i2c_read(i2c, 0x00, 1, &readbyte); if (ret == 0 && readbyte != 0x05) { ret = -ENODEV; dev_err(&i2c->dev, "chip reported: [00h]= 0x%x\n", readbyte); } if (ret < 0) { dev_err(&i2c->dev, "failed to detect device. ret = %d\n", ret); goto err_detect; } #endif ret = setup_regulators(lp8720, pdata); if (ret < 0) goto err_detect; i2c_set_clientdata(i2c, lp8720); ret = gpio_request(pdata->en_pin, pdata->name); if (ret) { printk(KERN_ERR "%s, ERROR [%s] - gpio_request(%d) failed\n", __func__, pdata->name, pdata->en_pin); } ret = gpio_direction_output(pdata->en_pin, 1); if (ret) { printk(KERN_ERR "%s, ERROR [%s] - gpio_direction_output(%d) failed\n", __func__, pdata->name, pdata->en_pin); } /* EXT_DVS_CTRL, EXT_SLEEP_CTRL => serial interface control */ lp8720_i2c_read(i2c, LP8720_GENERAL_SETTINGS_REG, 1, &readbyte); enable = readbyte & ~0x06; lp8720_i2c_write(i2c, LP8720_GENERAL_SETTINGS_REG, 1, enable); #if 0 /* keep pmic state set by bootloader */ /* all ldo & buck disabled */ lp8720_i2c_read(i2c, LP8720_ENABLE_REG, 1, &readbyte); enable = readbyte & 0xC0; lp8720_i2c_write(i2c, LP8720_ENABLE_REG, 1, enable); #endif lp8720_i2c_read(i2c, LP8720_ENABLE_REG, 1, &readbyte); printk(KERN_DEBUG "%s, [%s] - ENABLE_REG : 0x%2x\n", __func__, pdata->name, readbyte); return 0; err_detect: kfree(lp8720); return ret; }