Skip to content

Commit

Permalink
ata: rb532_cf: Convert to use GPIO descriptors
Browse files Browse the repository at this point in the history
Pass a GPIO descriptor for the device instead of a hardcoded
GPIO number from the global GPIO numberspace. Use gpio
descriptors throughout.

Cut the now completely unused platform data for the CF slot.

Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Waldemar Brodkorb <wbx@openadk.org>
Cc: Matt Redfearn <matt.redfearn@mips.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Linus Walleij authored and Jens Axboe committed Dec 5, 2018
1 parent 83a7faa commit cd56f35
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 44 deletions.
6 changes: 0 additions & 6 deletions arch/mips/include/asm/mach-rc32434/rb.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ struct korina_device {
struct net_device *dev;
};

struct cf_device {
int gpio_pin;
void *dev;
struct gendisk *gd;
};

struct mpmc_device {
unsigned char state;
spinlock_t lock;
Expand Down
12 changes: 9 additions & 3 deletions arch/mips/rb532/devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/mtd/platnand.h>
#include <linux/mtd/mtd.h>
#include <linux/gpio.h>
#include <linux/gpio/machine.h>
#include <linux/gpio_keys.h>
#include <linux/input.h>
#include <linux/serial_8250.h>
Expand Down Expand Up @@ -127,14 +128,18 @@ static struct resource cf_slot0_res[] = {
}
};

static struct cf_device cf_slot0_data = {
.gpio_pin = CF_GPIO_NUM
static struct gpiod_lookup_table cf_slot0_gpio_table = {
.dev_id = "pata-rb532-cf",
.table = {
GPIO_LOOKUP("gpio0", CF_GPIO_NUM,
NULL, GPIO_ACTIVE_HIGH),
{ },
},
};

static struct platform_device cf_slot0 = {
.id = -1,
.name = "pata-rb532-cf",
.dev.platform_data = &cf_slot0_data,
.resource = cf_slot0_res,
.num_resources = ARRAY_SIZE(cf_slot0_res),
};
Expand Down Expand Up @@ -305,6 +310,7 @@ static int __init plat_setup_devices(void)

dev_set_drvdata(&korina_dev0.dev, &korina_dev0_data);

gpiod_add_lookup_table(&cf_slot0_gpio_table);
return platform_add_devices(rb532_devs, ARRAY_SIZE(rb532_devs));
}

Expand Down
45 changes: 10 additions & 35 deletions drivers/ata/pata_rb532_cf.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <linux/io.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>

#include <linux/libata.h>
#include <scsi/scsi_host.h>
Expand All @@ -49,7 +49,7 @@

struct rb532_cf_info {
void __iomem *iobase;
unsigned int gpio_line;
struct gpio_desc *gpio_line;
unsigned int irq;
};

Expand All @@ -60,7 +60,7 @@ static irqreturn_t rb532_pata_irq_handler(int irq, void *dev_instance)
struct ata_host *ah = dev_instance;
struct rb532_cf_info *info = ah->private_data;

if (gpio_get_value(info->gpio_line)) {
if (gpiod_get_value(info->gpio_line)) {
irq_set_irq_type(info->irq, IRQ_TYPE_LEVEL_LOW);
ata_sff_interrupt(info->irq, dev_instance);
} else {
Expand Down Expand Up @@ -106,10 +106,9 @@ static void rb532_pata_setup_ports(struct ata_host *ah)
static int rb532_pata_driver_probe(struct platform_device *pdev)
{
int irq;
int gpio;
struct gpio_desc *gpiod;
struct resource *res;
struct ata_host *ah;
struct cf_device *pdata;
struct rb532_cf_info *info;
int ret;

Expand All @@ -125,23 +124,12 @@ static int rb532_pata_driver_probe(struct platform_device *pdev)
return -ENOENT;
}

pdata = dev_get_platdata(&pdev->dev);
if (!pdata) {
dev_err(&pdev->dev, "no platform data specified\n");
return -EINVAL;
}

gpio = pdata->gpio_pin;
if (gpio < 0) {
gpiod = devm_gpiod_get(&pdev->dev, NULL, GPIOD_IN);
if (IS_ERR(gpiod)) {
dev_err(&pdev->dev, "no GPIO found for irq%d\n", irq);
return -ENOENT;
}

ret = gpio_request(gpio, DRV_NAME);
if (ret) {
dev_err(&pdev->dev, "GPIO request failed\n");
return ret;
return PTR_ERR(gpiod);
}
gpiod_set_consumer_name(gpiod, DRV_NAME);

/* allocate host */
ah = ata_host_alloc(&pdev->dev, RB500_CF_MAXPORTS);
Expand All @@ -153,34 +141,22 @@ static int rb532_pata_driver_probe(struct platform_device *pdev)
return -ENOMEM;

ah->private_data = info;
info->gpio_line = gpio;
info->gpio_line = gpiod;
info->irq = irq;

info->iobase = devm_ioremap_nocache(&pdev->dev, res->start,
resource_size(res));
if (!info->iobase)
return -ENOMEM;

ret = gpio_direction_input(gpio);
if (ret) {
dev_err(&pdev->dev, "unable to set GPIO direction, err=%d\n",
ret);
goto err_free_gpio;
}

rb532_pata_setup_ports(ah);

ret = ata_host_activate(ah, irq, rb532_pata_irq_handler,
IRQF_TRIGGER_LOW, &rb532_pata_sht);
if (ret)
goto err_free_gpio;
return ret;

return 0;

err_free_gpio:
gpio_free(gpio);

return ret;
}

static int rb532_pata_driver_remove(struct platform_device *pdev)
Expand All @@ -189,7 +165,6 @@ static int rb532_pata_driver_remove(struct platform_device *pdev)
struct rb532_cf_info *info = ah->private_data;

ata_host_detach(ah);
gpio_free(info->gpio_line);

return 0;
}
Expand Down

0 comments on commit cd56f35

Please sign in to comment.