static int sdhci_acpi_add_own_cd(struct device *dev, struct mmc_host *mmc) { struct gpio_desc *desc; unsigned long flags; int err, irq; desc = devm_gpiod_get_index(dev, "sd_cd", 0); if (IS_ERR(desc)) { err = PTR_ERR(desc); goto out; } err = gpiod_direction_input(desc); if (err) goto out_free; irq = gpiod_to_irq(desc); if (irq < 0) { err = irq; goto out_free; } flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; err = devm_request_irq(dev, irq, sdhci_acpi_sd_cd, flags, "sd_cd", mmc); if (err) goto out_free; return 0; out_free: devm_gpiod_put(dev, desc); out: dev_warn(dev, "failed to setup card detect wake up\n"); return err; }
/** * mmc_gpiod_request_cd - request a gpio descriptor for card-detection * @host: mmc host * @con_id: function within the GPIO consumer * @idx: index of the GPIO to obtain in the consumer * @override_active_level: ignore %GPIO_ACTIVE_LOW flag * @debounce: debounce time in microseconds * @gpio_invert: will return whether the GPIO line is inverted or not, set * to NULL to ignore * * Use this function in place of mmc_gpio_request_cd() to use the GPIO * descriptor API. Note that it is paired with mmc_gpiod_free_cd() not * mmc_gpio_free_cd(). Note also that it must be called prior to mmc_add_host() * otherwise the caller must also call mmc_gpiod_request_cd_irq(). * * Returns zero on success, else an error. */ int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id, unsigned int idx, bool override_active_level, unsigned int debounce, bool *gpio_invert) { struct mmc_gpio *ctx; struct gpio_desc *desc; int ret; ret = mmc_gpio_alloc(host); if (ret < 0) return ret; ctx = host->slot.handler_priv; if (!con_id) con_id = ctx->cd_label; desc = devm_gpiod_get_index(host->parent, con_id, idx, GPIOD_IN); if (IS_ERR(desc)) return PTR_ERR(desc); if (debounce) { ret = gpiod_set_debounce(desc, debounce); if (ret < 0) return ret; } if (gpio_invert) *gpio_invert = !gpiod_is_active_low(desc); ctx->override_cd_active_level = override_active_level; ctx->cd_gpio = desc; return 0; }
/** * mmc_gpiod_request_ro - request a gpio descriptor for write protection * @host: mmc host * @con_id: function within the GPIO consumer * @idx: index of the GPIO to obtain in the consumer * @debounce: debounce time in microseconds * @gpio_invert: will return whether the GPIO line is inverted or not, * set to NULL to ignore * * Returns zero on success, else an error. */ int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id, unsigned int idx, unsigned int debounce, bool *gpio_invert) { struct mmc_gpio *ctx = host->slot.handler_priv; struct gpio_desc *desc; int ret; desc = devm_gpiod_get_index(host->parent, con_id, idx, GPIOD_IN); if (IS_ERR(desc)) return PTR_ERR(desc); if (debounce) { ret = gpiod_set_debounce(desc, debounce); if (ret < 0) return ret; } if (gpio_invert) *gpio_invert = !gpiod_is_active_low(desc); ctx->ro_gpio = desc; return 0; }
static int st_nci_i2c_acpi_request_resources(struct i2c_client *client) { struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); struct gpio_desc *gpiod_reset; struct device *dev = &client->dev; u8 tmp; /* Get RESET GPIO from ACPI */ gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, 1, GPIOD_OUT_HIGH); if (IS_ERR(gpiod_reset)) { nfc_err(dev, "Unable to get RESET GPIO\n"); return -ENODEV; } phy->gpio_reset = desc_to_gpio(gpiod_reset); phy->irq_polarity = irq_get_trigger_type(client->irq); phy->se_status.is_ese_present = false; phy->se_status.is_uicc_present = false; if (device_property_present(dev, "ese-present")) { device_property_read_u8(dev, "ese-present", &tmp); phy->se_status.is_ese_present = tmp; } if (device_property_present(dev, "uicc-present")) { device_property_read_u8(dev, "uicc-present", &tmp); phy->se_status.is_uicc_present = tmp; } return 0; }
static int nokia_modem_gpio_probe(struct device *dev) { struct device_node *np = dev->of_node; struct nokia_modem_device *modem = dev_get_drvdata(dev); int gpio_count, gpio_name_count, i, err; gpio_count = of_gpio_count(np); if (gpio_count < 0) { dev_err(dev, "missing gpios: %d\n", gpio_count); return gpio_count; } gpio_name_count = of_property_count_strings(np, "gpio-names"); if (gpio_count != gpio_name_count) { dev_err(dev, "number of gpios does not equal number of gpio names\n"); return -EINVAL; } modem->gpios = devm_kzalloc(dev, gpio_count * sizeof(struct nokia_modem_gpio), GFP_KERNEL); if (!modem->gpios) { dev_err(dev, "Could not allocate memory for gpios\n"); return -ENOMEM; } modem->gpio_amount = gpio_count; for (i = 0; i < gpio_count; i++) { modem->gpios[i].gpio = devm_gpiod_get_index(dev, NULL, i); if (IS_ERR(modem->gpios[i].gpio)) { dev_err(dev, "Could not get gpio %d\n", i); return PTR_ERR(modem->gpios[i].gpio); } err = of_property_read_string_index(np, "gpio-names", i, &(modem->gpios[i].name)); if (err) { dev_err(dev, "Could not get gpio name %d\n", i); return err; } err = gpiod_direction_output(modem->gpios[i].gpio, 0); if (err) return err; err = gpiod_export(modem->gpios[i].gpio, 0); if (err) return err; err = gpiod_export_link(dev, modem->gpios[i].name, modem->gpios[i].gpio); if (err) return err; } return 0; }
static int mdio_gpio_get_data(struct device *dev, struct mdio_gpio_info *bitbang) { bitbang->mdc = devm_gpiod_get_index(dev, NULL, MDIO_GPIO_MDC, GPIOD_OUT_LOW); if (IS_ERR(bitbang->mdc)) return PTR_ERR(bitbang->mdc); bitbang->mdio = devm_gpiod_get_index(dev, NULL, MDIO_GPIO_MDIO, GPIOD_IN); if (IS_ERR(bitbang->mdio)) return PTR_ERR(bitbang->mdio); bitbang->mdo = devm_gpiod_get_index_optional(dev, NULL, MDIO_GPIO_MDO, GPIOD_OUT_LOW); return PTR_ERR_OR_ZERO(bitbang->mdo); }
static int nxp_nci_i2c_acpi_config(struct nxp_nci_i2c_phy *phy) { struct i2c_client *client = phy->i2c_dev; struct gpio_desc *gpiod_en, *gpiod_fw; gpiod_en = devm_gpiod_get_index(&client->dev, NULL, 2, GPIOD_OUT_LOW); gpiod_fw = devm_gpiod_get_index(&client->dev, NULL, 1, GPIOD_OUT_LOW); if (IS_ERR(gpiod_en) || IS_ERR(gpiod_fw)) { nfc_err(&client->dev, "No GPIOs\n"); return -EINVAL; } phy->gpio_en = desc_to_gpio(gpiod_en); phy->gpio_fw = desc_to_gpio(gpiod_fw); return 0; }
static int bdw_rt5677_init(struct snd_soc_pcm_runtime *rtd) { struct bdw_rt5677_priv *bdw_rt5677 = snd_soc_card_get_drvdata(rtd->card); struct snd_soc_codec *codec = rtd->codec; struct snd_soc_dapm_context *dapm = &codec->dapm; /* Enable codec ASRC function for Stereo DAC/Stereo1 ADC/DMIC/I2S1. * The ASRC clock source is clk_i2s1_asrc. */ rt5677_sel_asrc_clk_src(codec, RT5677_DA_STEREO_FILTER | RT5677_AD_STEREO1_FILTER | RT5677_I2S1_SOURCE, RT5677_CLK_SEL_I2S1_ASRC); /* Request rt5677 GPIO for headphone amp control */ bdw_rt5677->gpio_hp_en = devm_gpiod_get_index(codec->dev, "RT5677_GPIO_HP_AMP_SHDN_L", RT5677_GPIO_HP_AMP_SHDN_L, GPIOD_ASIS); if (IS_ERR(bdw_rt5677->gpio_hp_en)) { dev_err(codec->dev, "Can't find HP_AMP_SHDN_L gpio\n"); return PTR_ERR(bdw_rt5677->gpio_hp_en); } gpiod_direction_output(bdw_rt5677->gpio_hp_en, 0); /* Create and initialize headphone jack */ if (!snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE, &headphone_jack)) { if (snd_soc_jack_add_pins(&headphone_jack, 1, &headphone_jack_pin)) dev_err(codec->dev, "Can't add headphone jack pin\n"); headphone_jack_gpio.gpiod_dev = codec->dev; if (snd_soc_jack_add_gpios(&headphone_jack, 1, &headphone_jack_gpio)) dev_err(codec->dev, "Can't add headphone jack gpio\n"); } else { dev_err(codec->dev, "Can't create headphone jack\n"); } /* Create and initialize mic jack */ if (!snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE, &mic_jack)) { if (snd_soc_jack_add_pins(&mic_jack, 1, &mic_jack_pin)) dev_err(codec->dev, "Can't add mic jack pin\n"); mic_jack_gpio.gpiod_dev = codec->dev; if (snd_soc_jack_add_gpios(&mic_jack, 1, &mic_jack_gpio)) dev_err(codec->dev, "Can't add mic jack gpio\n"); } else { dev_err(codec->dev, "Can't create mic jack\n"); } bdw_rt5677->codec = codec; snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); return 0; }
/** * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional() * @dev: GPIO consumer * @con_id: function within the GPIO consumer * @index: index of the GPIO to obtain in the consumer * @flags: optional GPIO initialization flags * * Managed gpiod_get_index_optional(). GPIO descriptors returned from this * function are automatically disposed on driver detach. See * gpiod_get_index_optional() for detailed information about behavior and * return values. */ struct gpio_desc *__must_check __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, unsigned int index, enum gpiod_flags flags) { struct gpio_desc *desc; desc = devm_gpiod_get_index(dev, con_id, index, flags); if (IS_ERR(desc)) { if (PTR_ERR(desc) == -ENOENT) return NULL; } return desc; }
static int gsl_ts_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct gsl_ts_data *ts; const struct firmware *fw = NULL; unsigned long irqflags; int error; bool acpipower; dev_warn(&client->dev, "%s: got a device named %s at address 0x%x, IRQ %d, flags 0x%x\n", __func__, client->name, client->addr, client->irq, client->flags); if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { dev_err(&client->dev, "%s: i2c check functionality error\n", __func__); error = -ENXIO; goto release; } if (client->irq <= 0) { dev_err(&client->dev, "%s: missing IRQ configuration\n", __func__); error = -ENODEV; goto release; } ts = devm_kzalloc(&client->dev, sizeof(struct gsl_ts_data), GFP_KERNEL); if (!ts) { error = -ENOMEM; goto release; } ts->client = client; i2c_set_clientdata(client, ts); if (gsl_fw_name != NULL) { strncpy(ts->fw_name, gsl_fw_name, sizeof(ts->fw_name)); } else { strncpy(ts->fw_name, GSL_FW_NAME_DEFAULT, sizeof(ts->fw_name)); } error = request_firmware(&fw, ts->fw_name, &ts->client->dev); if (error < 0) { dev_err(&client->dev, "%s: failed to load firmware: %d\n", __func__, error); goto release; } error = gsl_ts_init(ts, fw); if (error < 0) { dev_err(&client->dev, "%s: failed to initialize: %d\n", __func__, error); goto release; } ts->input = devm_input_allocate_device(&client->dev); if (!ts->input) { dev_err(&client->dev, "%s: failed to allocate input device\n", __func__); error = -ENOMEM; goto release; } ts->input->name = "Silead GSLx680 Touchscreen"; ts->input->id.bustype = BUS_I2C; ts->input->phys = "input/ts"; input_set_capability(ts->input, EV_ABS, ABS_X); input_set_capability(ts->input, EV_ABS, ABS_Y); input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, ts->x_max, ts->jitter, ts->deadzone); input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, ts->y_max, ts->jitter, ts->deadzone); input_mt_init_slots(ts->input, ts->multi_touches, INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED | INPUT_MT_TRACK); input_set_drvdata(ts->input, ts); error = input_register_device(ts->input); if (error) { dev_err(&client->dev, "%s: unable to register input device: %d\n", __func__, error); goto release; } /* Try to use ACPI power methods first */ acpipower = false; #ifdef CONFIG_ACPI if (ACPI_COMPANION(&client->dev)) { /* Wake the device up with a power on reset */ if (acpi_bus_set_power(ACPI_HANDLE(&client->dev), ACPI_STATE_D3)) { dev_warn(&client->dev, "%s: failed to wake up device through ACPI: %d, using GPIO controls instead\n", __func__, error); } else { acpipower = true; } } #endif /* Not available, use GPIO settings from DSDT/DT instead */ if (!acpipower) { #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) ts->gpio = devm_gpiod_get_index(&client->dev, GSL_PWR_GPIO, 0); #else ts->gpio = devm_gpiod_get_index(&client->dev, GSL_PWR_GPIO, 0, GPIOD_OUT_LOW); #endif if (IS_ERR(ts->gpio)) { dev_err(&client->dev, "%s: error obtaining power pin GPIO resource\n", __func__); error = PTR_ERR(ts->gpio); goto release; } #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) error = gpiod_direction_output(ts->gpio, 0); if (error < 0) { dev_err(&client->dev, "%s: error setting GPIO pin direction\n", __func__); goto release; } #endif } else { ts->gpio = NULL; } /* Enable power */ gsl_ts_power(client, false); /* Execute the controller startup sequence */ error = gsl_ts_reset_chip(client); if (error < 0) { dev_err(&client->dev, "%s: chip reset failed\n", __func__); goto release; } error = gsl_ts_write_fw(ts, fw); if (error < 0) { dev_err(&client->dev, "%s: firmware transfer failed\n", __func__); goto release; } error = gsl_ts_startup_chip(client); if (error < 0) { dev_err(&client->dev, "%s: chip startup failed\n", __func__); goto release; } /* * Systems using device tree should set up interrupt via DTS, * the rest will use the default falling edge interrupts. */ irqflags = client->dev.of_node ? 0 : IRQF_TRIGGER_FALLING; /* Set up interrupt handler - do we still need to account for shared interrupts? */ error = devm_request_threaded_irq( &client->dev, client->irq, NULL, gsl_ts_irq, irqflags | IRQF_ONESHOT, client->name, ts ); if (error) { dev_err(&client->dev, "%s: failed to register interrupt\n", __func__); goto release; } /* * Systems using device tree should set up wakeup via DTS, * the rest will configure device as wakeup source by default. */ if (!client->dev.of_node) { device_init_wakeup(&client->dev, true); } ts->state = GSL_TS_GREEN; release: if (fw) { release_firmware(fw); } if (error < 0) { return error; } return 0; }
/** * devm_gpiod_get - Resource-managed gpiod_get() * @dev: GPIO consumer * @con_id: function within the GPIO consumer * @flags: optional GPIO initialization flags * * Managed gpiod_get(). GPIO descriptors returned from this function are * automatically disposed on driver detach. See gpiod_get() for detailed * information about behavior and return values. */ struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, const char *con_id, enum gpiod_flags flags) { return devm_gpiod_get_index(dev, con_id, 0, flags); }
static int tpd_probe(struct platform_device *pdev) { struct omap_dss_device *in, *dssdev; struct panel_drv_data *ddata; int r; struct gpio_desc *gpio; ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); if (!ddata) return -ENOMEM; platform_set_drvdata(pdev, ddata); if (!pdev->dev.of_node) return -ENODEV; r = tpd_probe_of(pdev); if (r) return r; gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 0, GPIOD_OUT_LOW); if (IS_ERR(gpio)) { r = PTR_ERR(gpio); goto err_gpio; } ddata->ct_cp_hpd_gpio = gpio; gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 1, GPIOD_OUT_LOW); if (IS_ERR(gpio)) { r = PTR_ERR(gpio); goto err_gpio; } ddata->ls_oe_gpio = gpio; gpio = devm_gpiod_get_index(&pdev->dev, NULL, 2, GPIOD_IN); if (IS_ERR(gpio)) { r = PTR_ERR(gpio); goto err_gpio; } ddata->hpd_gpio = gpio; dssdev = &ddata->dssdev; dssdev->ops.hdmi = &tpd_hdmi_ops; dssdev->dev = &pdev->dev; dssdev->type = OMAP_DISPLAY_TYPE_HDMI; dssdev->output_type = OMAP_DISPLAY_TYPE_HDMI; dssdev->owner = THIS_MODULE; dssdev->port_num = 1; in = ddata->in; r = omapdss_register_output(dssdev); if (r) { dev_err(&pdev->dev, "Failed to register output\n"); goto err_reg; } return 0; err_reg: err_gpio: omap_dss_put_device(ddata->in); return r; }