Skip to content

Commit

Permalink
pcmcia: soc_common: switch to using gpio_descs
Browse files Browse the repository at this point in the history
Switch to using the gpiod_* consumer API rather than the legacy API.

Signed-off-by: Russell King <[email protected]>
  • Loading branch information
Russell King committed Sep 22, 2016
1 parent 59ecfef commit 45ca753
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
49 changes: 38 additions & 11 deletions drivers/pcmcia/soc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <linux/cpufreq.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/io.h>
Expand Down Expand Up @@ -126,6 +127,30 @@ static void soc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
__soc_pcmcia_hw_shutdown(skt, ARRAY_SIZE(skt->stat));
}

int soc_pcmcia_request_gpiods(struct soc_pcmcia_socket *skt)
{
struct device *dev = skt->socket.dev.parent;
struct gpio_desc *desc;
int i;

for (i = 0; i < ARRAY_SIZE(skt->stat); i++) {
if (!skt->stat[i].name)
continue;

desc = devm_gpiod_get(dev, skt->stat[i].name, GPIOD_IN);
if (IS_ERR(desc)) {
dev_err(dev, "Failed to get GPIO for %s: %ld\n",
skt->stat[i].name, PTR_ERR(desc));
return PTR_ERR(desc);
}

skt->stat[i].desc = desc;
}

return 0;
}
EXPORT_SYMBOL_GPL(soc_pcmcia_request_gpiods);

static int soc_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
{
int ret = 0, i;
Expand All @@ -140,8 +165,6 @@ static int soc_pcmcia_hw_init(struct soc_pcmcia_socket *skt)

for (i = 0; i < ARRAY_SIZE(skt->stat); i++) {
if (gpio_is_valid(skt->stat[i].gpio)) {
int irq;

ret = devm_gpio_request_one(skt->socket.dev.parent,
skt->stat[i].gpio, GPIOF_IN,
skt->stat[i].name);
Expand All @@ -150,7 +173,11 @@ static int soc_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
return ret;
}

irq = gpio_to_irq(skt->stat[i].gpio);
skt->stat[i].desc = gpio_to_desc(skt->stat[i].gpio);
}

if (skt->stat[i].desc) {
int irq = gpiod_to_irq(skt->stat[i].desc);

if (i == SOC_STAT_RDY)
skt->socket.pci_irq = irq;
Expand Down Expand Up @@ -205,16 +232,16 @@ static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt)
state.bvd2 = 1;

/* CD is active low by default */
if (gpio_is_valid(skt->stat[SOC_STAT_CD].gpio))
state.detect = !gpio_get_value(skt->stat[SOC_STAT_CD].gpio);
if (skt->stat[SOC_STAT_CD].desc)
state.detect = !gpiod_get_raw_value(skt->stat[SOC_STAT_CD].desc);

/* RDY and BVD are active high by default */
if (gpio_is_valid(skt->stat[SOC_STAT_RDY].gpio))
state.ready = !!gpio_get_value(skt->stat[SOC_STAT_RDY].gpio);
if (gpio_is_valid(skt->stat[SOC_STAT_BVD1].gpio))
state.bvd1 = !!gpio_get_value(skt->stat[SOC_STAT_BVD1].gpio);
if (gpio_is_valid(skt->stat[SOC_STAT_BVD2].gpio))
state.bvd2 = !!gpio_get_value(skt->stat[SOC_STAT_BVD2].gpio);
if (skt->stat[SOC_STAT_RDY].desc)
state.ready = !!gpiod_get_value(skt->stat[SOC_STAT_RDY].desc);
if (skt->stat[SOC_STAT_BVD1].desc)
state.bvd1 = !!gpiod_get_value(skt->stat[SOC_STAT_BVD1].desc);
if (skt->stat[SOC_STAT_BVD2].desc)
state.bvd2 = !!gpiod_get_value(skt->stat[SOC_STAT_BVD2].desc);

skt->ops->socket_state(skt, &state);

Expand Down
3 changes: 3 additions & 0 deletions drivers/pcmcia/soc_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


struct device;
struct gpio_desc;
struct pcmcia_low_level;

/*
Expand Down Expand Up @@ -52,6 +53,7 @@ struct soc_pcmcia_socket {

struct {
int gpio;
struct gpio_desc *desc;
unsigned int irq;
const char *name;
} stat[4];
Expand Down Expand Up @@ -136,6 +138,7 @@ void soc_pcmcia_init_one(struct soc_pcmcia_socket *skt,
struct pcmcia_low_level *ops, struct device *dev);
void soc_pcmcia_remove_one(struct soc_pcmcia_socket *skt);
int soc_pcmcia_add_one(struct soc_pcmcia_socket *skt);
int soc_pcmcia_request_gpiods(struct soc_pcmcia_socket *skt);


#ifdef CONFIG_PCMCIA_DEBUG
Expand Down

0 comments on commit 45ca753

Please sign in to comment.