static int lm3554_s_flash_strobe(struct v4l2_subdev *sd, u32 val) { int ret, timer_pending; struct i2c_client *client = v4l2_get_subdevdata(sd); struct lm3554_priv *p_lm3554_priv = to_lm3554_priv(sd); struct camera_flash_platform_data *pdata = p_lm3554_priv->platform_data; /* * An abnormal high flash current is observed when strobe off the * flash. Workaround here is firstly set flash current to lower level, * wait a short moment, and then strobe off the flash. */ timer_pending = del_timer_sync(&p_lm3554_priv->flash_off_delay); /* Flash off */ if (!val) { /* set current to 70mA and wait a while */ ret = set_reg_field(sd, &flash_current, 0); if (ret < 0) goto err; mod_timer(&p_lm3554_priv->flash_off_delay, jiffies + msecs_to_jiffies(LM3554_TIMER_DELAY)); return 0; } /* Flash on */ /* * If timer is killed before run, flash is not strobe off, * so must strobe off here */ if (timer_pending != 0) { ret = set_gpio_output(pdata->gpio_strobe, "flash", 0); if (ret < 0) goto err; } /* Restore flash current settings */ ret = set_reg_field(sd, &flash_current, (u8)p_lm3554_priv->intensity); if (ret < 0) goto err; /* Strobe on Flash */ ret = set_gpio_output(pdata->gpio_strobe, "flash", val); if (ret < 0) goto err; return 0; err: dev_err(&client->dev, "failed to generate flash strobe (%d)\n", ret); return ret; }
static int lm3554_detect(struct i2c_client *client) { s32 status; struct i2c_adapter *adapter = client->adapter; struct v4l2_subdev *sd = i2c_get_clientdata(client); struct lm3554_priv *p_lm3554_priv = to_lm3554_priv(sd); struct camera_flash_platform_data *pdata = p_lm3554_priv->platform_data; int ret; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { dev_err(&client->dev, "lm3554_detect i2c error\n"); return -ENODEV; } lm3554_hw_reset(client); ret = set_gpio_output(pdata->gpio_strobe, "flash", 0); if (ret < 0) goto fail; ret = set_gpio_output(pdata->gpio_torch, "torch", 0); if (ret < 0) goto fail; /* Set to TX2 mode, then ENVM/TX2 pin is a power * amplifier sync input: * ENVM/TX pin asserted, flash forced into torch; * ENVM/TX pin desserted, flash set back; */ ret = set_reg_field(sd, &envm_tx2, 1); if (ret < 0) goto fail; ret = set_reg_field(sd, &tx2_polarity, 0); if (ret < 0) goto fail; /* set peak current limit to be 1000mA */ ret = set_reg_field(sd, ¤t_limit, 0); if (ret < 0) goto fail; /* clear the flags register */ ret = lm3554_g_flash_status(sd, &status); if (ret < 0) goto fail; dev_dbg(&client->dev, "Successfully detected lm3554 LED flash\n"); return 0; fail: dev_err(&client->dev, "gpio request/direction_output fail"); return ret; }
int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { int status = 0; if (strcmp(argv[1], "set") == 0) { u32 gpio_number = 0; u32 gpio_value = 0; if (argc != 4) { printf("error invalid usage\n"); return -1; } gpio_number = simple_strtoul(argv[2], NULL, 10); gpio_value = simple_strtoul(argv[3], NULL, 10); configure_pad_mode(gpio_number); configure_gpio_output(gpio_number); set_gpio_output(gpio_number, (gpio_value == 0) ? 0 : 1); }else if(strcmp(argv[1], "get") == 0){ u32 gpio_number = 0; if (argc != 3) { printf("error invalid usage\n"); return -1; } gpio_number = simple_strtoul(argv[2], NULL, 10); printf("Read GPIO Pin %d = 0x%x\n", gpio_number, get_gpio_value(gpio_number)); } return status; }
static void lm3554_flash_off_delay(long unsigned int arg) { struct i2c_client *client = (struct i2c_client *)arg; struct v4l2_subdev *sd = i2c_get_clientdata(client); struct lm3554_priv *p_lm3554_priv = to_lm3554_priv(sd); struct camera_flash_platform_data *pdata = p_lm3554_priv->platform_data; if (set_gpio_output(pdata->gpio_strobe, "flash", 0) < 0) dev_err(&client->dev, "failed to flash strobe off\n"); }
void HCA700_IO_init() { init_gpio_lib(); set_gpio_output(IO_PORT,WIFI_POWER_PIN, 1); set_gpio_output(IO_PORT,AMP_POWER_PIN, 1); set_gpio_output(IO_PORT,USB_SWITCH_EN_PIN, 0); //set_gpio_output(IO_PORT,USB_SWITCH_FUNCTION_PIN, 1); set_gpio_output(IO_PORT,WM8750_CLOCK_PIN, 1); set_gpio_output(IO_PORT,DEBUG_LED_PIN, 1); set_gpio_output(IO_PORT,SD_CARD_POWER_PIN, 0); set_gpio_input(IO_PORT,CHARGER_FULL_INDICATOR_PIN); set_gpio_input(IO_PORT,NO_BATTERY_INDICATOR_PIN); set_gpio_input(IO_PORT,KEY_VOL_DOWN_PIN); set_gpio_input(IO_PORT,KEY_VOL_UP_PIN); set_gpio_input(IO_PORT,KEY_VOL_POWER_PIN); set_gpio_input(IO_PORT,KEY_VOL_MUTE_PIN); set_gpio_input(IO_PORT,DC5V_PLUGIN_INDICATOR_PIN); set_gpio_input(IO_PORT,WIFI_OVER_CURRENT_INDICATOR_PIN); /* HCA700_wifi_power_on(); HCA700_AMP_power_on(); HCA700_USB_switch_on(); HCA700_USB_function_NONE(); HCA700_WM8750_on(); HCA700_SD_card_power_on(); */ }
static void write_gpio (uint8_t val) { //Set GPIO buffer to output set_gpio_output (); //Disable IC3 for a moment digitalWrite (IC3_CE, IC3_DISABLE); //Write to output buffer digitalWriteByte (val); output_waiting = true; //Clock the data into IC4, ready for the WPC to pick it up out_clk (); //Set GPIO buffer back to input digitalWrite (IC3_CE, IC3_ENABLE); set_gpio_input (); }
static int lm3554_remove(struct i2c_client *client) { struct v4l2_subdev *sd = i2c_get_clientdata(client); struct lm3554_priv *p_lm3554_priv = to_lm3554_priv(sd); struct camera_flash_platform_data *pdata = p_lm3554_priv->platform_data; int ret; media_entity_cleanup(&p_lm3554_priv->sd.entity); v4l2_device_unregister_subdev(sd); del_timer_sync(&p_lm3554_priv->flash_off_delay); ret = set_gpio_output(pdata->gpio_strobe, "flash", 0); if (ret < 0) goto fail; kfree(p_lm3554_priv); return 0; fail: dev_err(&client->dev, "gpio request/direction_output fail"); return ret; }