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; }
void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios) { enum mctrl_gpio_idx i; for (i = 0; i < UART_GPIO_MAX; i++) { if (gpios->irq[i]) devm_free_irq(gpios->port->dev, gpios->irq[i], gpios); if (gpios->gpio[i]) devm_gpiod_put(dev, gpios->gpio[i]); } devm_kfree(dev, gpios); }
static int pimhyp3_ts_remove(struct i2c_client *client) { struct pimhyp3_ts_data *ts = i2c_get_clientdata(client); if (ts->gpiod_int) devm_gpiod_put(&client->dev, ts->gpiod_int); if (ts->use_poll) kthread_stop(ts->thread); else pimhyp3_free_irq(ts); return 0; }
static int rx51_aic34_init(struct snd_soc_pcm_runtime *rtd) { struct snd_soc_codec *codec = rtd->codec; struct snd_soc_card *card = rtd->card; struct rx51_audio_pdata *pdata = snd_soc_card_get_drvdata(card); struct snd_soc_dapm_context *dapm = &codec->dapm; int err; /* Set up NC codec pins */ snd_soc_dapm_nc_pin(dapm, "MIC3L"); snd_soc_dapm_nc_pin(dapm, "MIC3R"); snd_soc_dapm_nc_pin(dapm, "LINE1R"); err = tpa6130a2_add_controls(codec); if (err < 0) { dev_err(card->dev, "Failed to add TPA6130A2 controls\n"); return err; } snd_soc_limit_volume(codec, "TPA6130A2 Headphone Playback Volume", 42); err = omap_mcbsp_st_add_controls(rtd, 2); if (err < 0) { dev_err(card->dev, "Failed to add MCBSP controls\n"); return err; } /* AV jack detection */ err = snd_soc_jack_new(codec, "AV Jack", SND_JACK_HEADSET | SND_JACK_VIDEOOUT, &rx51_av_jack); if (err) { dev_err(card->dev, "Failed to add AV Jack\n"); return err; } /* prepare gpio for snd_soc_jack_add_gpios */ rx51_av_jack_gpios[0].gpio = desc_to_gpio(pdata->jack_detection_gpio); devm_gpiod_put(card->dev, pdata->jack_detection_gpio); err = snd_soc_jack_add_gpios(&rx51_av_jack, ARRAY_SIZE(rx51_av_jack_gpios), rx51_av_jack_gpios); if (err) { dev_err(card->dev, "Failed to add GPIOs\n"); return err; } return err; }
/** * mmc_gpiod_free_cd - free the card-detection gpio descriptor * @host: mmc host * * It's provided only for cases that client drivers need to manually free * up the card-detection gpio requested by mmc_gpiod_request_cd(). */ void mmc_gpiod_free_cd(struct mmc_host *host) { struct mmc_gpio *ctx = host->slot.handler_priv; if (!ctx || !ctx->cd_gpio) return; if (host->slot.cd_irq >= 0) { devm_free_irq(&host->class_dev, host->slot.cd_irq, host); host->slot.cd_irq = -EINVAL; } devm_gpiod_put(&host->class_dev, ctx->cd_gpio); ctx->cd_gpio = NULL; }
static void asc_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old) { struct asc_port *ascport = to_asc_port(port); struct device_node *np = port->dev->of_node; struct gpio_desc *gpiod; unsigned int baud; u32 ctrl_val; tcflag_t cflag; unsigned long flags; /* Update termios to reflect hardware capabilities */ termios->c_cflag &= ~(CMSPAR | (ascport->hw_flow_control ? 0 : CRTSCTS)); port->uartclk = clk_get_rate(ascport->clk); baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); cflag = termios->c_cflag; spin_lock_irqsave(&port->lock, flags); /* read control register */ ctrl_val = asc_in(port, ASC_CTL); /* stop serial port and reset value */ asc_out(port, ASC_CTL, (ctrl_val & ~ASC_CTL_RUN)); ctrl_val = ASC_CTL_RXENABLE | ASC_CTL_FIFOENABLE; /* reset fifo rx & tx */ asc_out(port, ASC_TXRESET, 1); asc_out(port, ASC_RXRESET, 1); /* set character length */ if ((cflag & CSIZE) == CS7) { ctrl_val |= ASC_CTL_MODE_7BIT_PAR; } else { ctrl_val |= (cflag & PARENB) ? ASC_CTL_MODE_8BIT_PAR : ASC_CTL_MODE_8BIT; } /* set stop bit */ ctrl_val |= (cflag & CSTOPB) ? ASC_CTL_STOP_2BIT : ASC_CTL_STOP_1BIT; /* odd parity */ if (cflag & PARODD) ctrl_val |= ASC_CTL_PARITYODD; /* hardware flow control */ if ((cflag & CRTSCTS)) { ctrl_val |= ASC_CTL_CTSENABLE; /* If flow-control selected, stop handling RTS manually */ if (ascport->rts) { devm_gpiod_put(port->dev, ascport->rts); ascport->rts = NULL; pinctrl_select_state(ascport->pinctrl, ascport->states[DEFAULT]); } } else { /* If flow-control disabled, it's safe to handle RTS manually */ if (!ascport->rts && ascport->states[NO_HW_FLOWCTRL]) { pinctrl_select_state(ascport->pinctrl, ascport->states[NO_HW_FLOWCTRL]); gpiod = devm_fwnode_get_gpiod_from_child(port->dev, "rts", &np->fwnode, GPIOD_OUT_LOW, np->name); if (!IS_ERR(gpiod)) ascport->rts = gpiod; } } if ((baud < 19200) && !ascport->force_m1) { asc_out(port, ASC_BAUDRATE, (port->uartclk / (16 * baud))); } else { /* * MODE 1: recommended for high bit rates (above 19.2K) * * baudrate * 16 * 2^16 * ASCBaudRate = ------------------------ * inputclock * * To keep maths inside 64bits, we divide inputclock by 16. */ u64 dividend = (u64)baud * (1 << 16); do_div(dividend, port->uartclk / 16); asc_out(port, ASC_BAUDRATE, dividend); ctrl_val |= ASC_CTL_BAUDMODE; } uart_update_timeout(port, cflag, baud); ascport->port.read_status_mask = ASC_RXBUF_DUMMY_OE; if (termios->c_iflag & INPCK) ascport->port.read_status_mask |= ASC_RXBUF_FE | ASC_RXBUF_PE; if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) ascport->port.read_status_mask |= ASC_RXBUF_DUMMY_BE; /* * Characters to ignore */ ascport->port.ignore_status_mask = 0; if (termios->c_iflag & IGNPAR) ascport->port.ignore_status_mask |= ASC_RXBUF_FE | ASC_RXBUF_PE; if (termios->c_iflag & IGNBRK) { ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_BE; /* * If we're ignoring parity and break indicators, * ignore overruns too (for real raw support). */ if (termios->c_iflag & IGNPAR) ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_OE; } /* * Ignore all characters if CREAD is not set. */ if (!(termios->c_cflag & CREAD)) ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_RX; /* Set the timeout */ asc_out(port, ASC_TIMEOUT, 20); /* write final value and enable port */ asc_out(port, ASC_CTL, (ctrl_val | ASC_CTL_RUN)); spin_unlock_irqrestore(&port->lock, flags); }