From 3e216263ce7707b243dec2dc23b55f660631e856 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Tue, 13 Nov 2018 14:17:41 +0100 Subject: ata: pxa: Drop include This driver does not use GPIO or anything from the GPIO header. Drop the include. Signed-off-by: Linus Walleij Signed-off-by: Jens Axboe --- drivers/ata/pata_pxa.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/ata') diff --git a/drivers/ata/pata_pxa.c b/drivers/ata/pata_pxa.c index e8b6a2e464c9..4b9b9e120188 100644 --- a/drivers/ata/pata_pxa.c +++ b/drivers/ata/pata_pxa.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include -- cgit v1.2.3 From 83a7faace12e1bca6f659e117cde85769385fe08 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Wed, 14 Nov 2018 01:02:41 +0100 Subject: ata: sata_highbank: Convert to use GPIO descriptors This pure device tree driver is simple to convert to use just GPIO descriptors instead of GPIO numbers. So let's just do it. Cc: Mark Langsdorf Acked-by: Rob Herring Signed-off-by: Linus Walleij Signed-off-by: Jens Axboe --- drivers/ata/sata_highbank.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/sata_highbank.c b/drivers/ata/sata_highbank.c index e67815b896fc..c8fc9280d6e4 100644 --- a/drivers/ata/sata_highbank.c +++ b/drivers/ata/sata_highbank.c @@ -31,8 +31,7 @@ #include #include #include -#include -#include +#include #include "ahci.h" @@ -85,7 +84,7 @@ struct ecx_plat_data { /* number of extra clocks that the SGPIO PIC controller expects */ u32 pre_clocks; u32 post_clocks; - unsigned sgpio_gpio[SGPIO_PINS]; + struct gpio_desc *sgpio_gpiod[SGPIO_PINS]; u32 sgpio_pattern; u32 port_to_sgpio[SGPIO_PORTS]; }; @@ -131,9 +130,9 @@ static void ecx_parse_sgpio(struct ecx_plat_data *pdata, u32 port, u32 state) */ static void ecx_led_cycle_clock(struct ecx_plat_data *pdata) { - gpio_set_value(pdata->sgpio_gpio[SCLOCK], 1); + gpiod_set_value(pdata->sgpio_gpiod[SCLOCK], 1); udelay(50); - gpio_set_value(pdata->sgpio_gpio[SCLOCK], 0); + gpiod_set_value(pdata->sgpio_gpiod[SCLOCK], 0); udelay(50); } @@ -164,15 +163,15 @@ static ssize_t ecx_transmit_led_message(struct ata_port *ap, u32 state, for (i = 0; i < pdata->pre_clocks; i++) ecx_led_cycle_clock(pdata); - gpio_set_value(pdata->sgpio_gpio[SLOAD], 1); + gpiod_set_value(pdata->sgpio_gpiod[SLOAD], 1); ecx_led_cycle_clock(pdata); - gpio_set_value(pdata->sgpio_gpio[SLOAD], 0); + gpiod_set_value(pdata->sgpio_gpiod[SLOAD], 0); /* * bit-bang out the SGPIO pattern, by consuming a bit and then * clocking it out. */ for (i = 0; i < (SGPIO_SIGNALS * pdata->n_ports); i++) { - gpio_set_value(pdata->sgpio_gpio[SDATA], sgpio_out & 1); + gpiod_set_value(pdata->sgpio_gpiod[SDATA], sgpio_out & 1); sgpio_out >>= 1; ecx_led_cycle_clock(pdata); } @@ -193,21 +192,19 @@ static void highbank_set_em_messages(struct device *dev, struct device_node *np = dev->of_node; struct ecx_plat_data *pdata = hpriv->plat_data; int i; - int err; for (i = 0; i < SGPIO_PINS; i++) { - err = of_get_named_gpio(np, "calxeda,sgpio-gpio", i); - if (err < 0) - return; - - pdata->sgpio_gpio[i] = err; - err = gpio_request(pdata->sgpio_gpio[i], "CX SGPIO"); - if (err) { - pr_err("sata_highbank gpio_request %d failed: %d\n", - i, err); - return; + struct gpio_desc *gpiod; + + gpiod = devm_gpiod_get_index(dev, "calxeda,sgpio", i, + GPIOD_OUT_HIGH); + if (IS_ERR(gpiod)) { + dev_err(dev, "failed to get GPIO %d\n", i); + continue; } - gpio_direction_output(pdata->sgpio_gpio[i], 1); + gpiod_set_consumer_name(gpiod, "CX SGPIO"); + + pdata->sgpio_gpiod[i] = gpiod; } of_property_read_u32_array(np, "calxeda,led-order", pdata->port_to_sgpio, -- cgit v1.2.3 From cd56f35e52d9496cbf5c85d27af9bdb064bec8df Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Tue, 20 Nov 2018 08:47:32 +0100 Subject: ata: rb532_cf: Convert to use GPIO descriptors 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 Cc: Waldemar Brodkorb Cc: Matt Redfearn Signed-off-by: Linus Walleij Signed-off-by: Jens Axboe --- arch/mips/include/asm/mach-rc32434/rb.h | 6 ----- arch/mips/rb532/devices.c | 12 ++++++--- drivers/ata/pata_rb532_cf.c | 45 ++++++++------------------------- 3 files changed, 19 insertions(+), 44 deletions(-) (limited to 'drivers/ata') diff --git a/arch/mips/include/asm/mach-rc32434/rb.h b/arch/mips/include/asm/mach-rc32434/rb.h index aac8ce8902e7..5dfd4d66d6fc 100644 --- a/arch/mips/include/asm/mach-rc32434/rb.h +++ b/arch/mips/include/asm/mach-rc32434/rb.h @@ -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; diff --git a/arch/mips/rb532/devices.c b/arch/mips/rb532/devices.c index 2b23ad640f39..828d8cc3a5df 100644 --- a/arch/mips/rb532/devices.c +++ b/arch/mips/rb532/devices.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -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), }; @@ -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)); } diff --git a/drivers/ata/pata_rb532_cf.c b/drivers/ata/pata_rb532_cf.c index 653b9a0bf727..66bb5bff126b 100644 --- a/drivers/ata/pata_rb532_cf.c +++ b/drivers/ata/pata_rb532_cf.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -49,7 +49,7 @@ struct rb532_cf_info { void __iomem *iobase; - unsigned int gpio_line; + struct gpio_desc *gpio_line; unsigned int irq; }; @@ -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 { @@ -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; @@ -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); @@ -153,7 +141,7 @@ 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, @@ -161,26 +149,14 @@ static int rb532_pata_driver_probe(struct platform_device *pdev) 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) @@ -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; } -- cgit v1.2.3 From f43e4b007a943b00a7562025ed036a9c1ee2950f Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Tue, 13 Nov 2018 14:01:02 +0100 Subject: ata: palmld: Convert to GPIO descriptors Instead of passing GPIO numbers directly to the PalmLD ATA driver, pass GPIO descriptors from the board file and handle these in the driver. Cc: Marek Vasut Signed-off-by: Linus Walleij Signed-off-by: Jens Axboe --- arch/arm/mach-pxa/palm27x.h | 2 ++ arch/arm/mach-pxa/palmld.c | 12 ++++++++++ drivers/ata/pata_palmld.c | 58 +++++++++++++++++++-------------------------- 3 files changed, 39 insertions(+), 33 deletions(-) (limited to 'drivers/ata') diff --git a/arch/arm/mach-pxa/palm27x.h b/arch/arm/mach-pxa/palm27x.h index d4eac3d6ffb5..3316ed2016f3 100644 --- a/arch/arm/mach-pxa/palm27x.h +++ b/arch/arm/mach-pxa/palm27x.h @@ -12,6 +12,8 @@ #ifndef __INCLUDE_MACH_PALM27X__ #define __INCLUDE_MACH_PALM27X__ +#include + #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE) extern void __init palm27x_mmc_init(int detect, int ro, int power, int power_inverted); diff --git a/arch/arm/mach-pxa/palmld.c b/arch/arm/mach-pxa/palmld.c index 980f2847f5b5..a37ceec22903 100644 --- a/arch/arm/mach-pxa/palmld.c +++ b/arch/arm/mach-pxa/palmld.c @@ -288,8 +288,20 @@ static struct platform_device palmld_ide_device = { .id = -1, }; +static struct gpiod_lookup_table palmld_ide_gpio_table = { + .dev_id = "pata_palmld", + .table = { + GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMLD_IDE_PWEN, + "power", GPIO_ACTIVE_HIGH), + GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMLD_IDE_RESET, + "reset", GPIO_ACTIVE_LOW), + { }, + }, +}; + static void __init palmld_ide_init(void) { + gpiod_add_lookup_table(&palmld_ide_gpio_table); platform_device_register(&palmld_ide_device); } #else diff --git a/drivers/ata/pata_palmld.c b/drivers/ata/pata_palmld.c index d071ab6864a8..e2933c324d41 100644 --- a/drivers/ata/pata_palmld.c +++ b/drivers/ata/pata_palmld.c @@ -26,17 +26,14 @@ #include #include #include -#include +#include #include #include #define DRV_NAME "pata_palmld" -static struct gpio palmld_hdd_gpios[] = { - { GPIO_NR_PALMLD_IDE_PWEN, GPIOF_INIT_HIGH, "HDD Power" }, - { GPIO_NR_PALMLD_IDE_RESET, GPIOF_INIT_LOW, "HDD Reset" }, -}; +static struct gpio_desc *palmld_pata_power; static struct scsi_host_template palmld_sht = { ATA_PIO_SHT(DRV_NAME), @@ -53,32 +50,34 @@ static int palmld_pata_probe(struct platform_device *pdev) struct ata_host *host; struct ata_port *ap; void __iomem *mem; + struct device *dev = &pdev->dev; + struct gpio_desc *reset; int ret; /* allocate host */ - host = ata_host_alloc(&pdev->dev, 1); - if (!host) { - ret = -ENOMEM; - goto err1; - } + host = ata_host_alloc(dev, 1); + if (!host) + return -ENOMEM; /* remap drive's physical memory address */ - mem = devm_ioremap(&pdev->dev, PALMLD_IDE_PHYS, 0x1000); - if (!mem) { - ret = -ENOMEM; - goto err1; + mem = devm_ioremap(dev, PALMLD_IDE_PHYS, 0x1000); + if (!mem) + return -ENOMEM; + + /* request and activate power and reset GPIOs */ + palmld_pata_power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH); + if (IS_ERR(palmld_pata_power)) + return PTR_ERR(palmld_pata_power); + reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(reset)) { + gpiod_set_value(palmld_pata_power, 0); + return PTR_ERR(reset); } - /* request and activate power GPIO, IRQ GPIO */ - ret = gpio_request_array(palmld_hdd_gpios, - ARRAY_SIZE(palmld_hdd_gpios)); - if (ret) - goto err1; - - /* reset the drive */ - gpio_set_value(GPIO_NR_PALMLD_IDE_RESET, 0); + /* Assert reset to reset the drive */ + gpiod_set_value(reset, 1); msleep(30); - gpio_set_value(GPIO_NR_PALMLD_IDE_RESET, 1); + gpiod_set_value(reset, 0); msleep(30); /* setup the ata port */ @@ -98,14 +97,9 @@ static int palmld_pata_probe(struct platform_device *pdev) /* activate host */ ret = ata_host_activate(host, 0, NULL, IRQF_TRIGGER_RISING, &palmld_sht); + /* power down on failure */ if (ret) - goto err2; - - return ret; - -err2: - gpio_free_array(palmld_hdd_gpios, ARRAY_SIZE(palmld_hdd_gpios)); -err1: + gpiod_set_value(palmld_pata_power, 0); return ret; } @@ -114,9 +108,7 @@ static int palmld_pata_remove(struct platform_device *dev) ata_platform_remove_one(dev); /* power down the HDD */ - gpio_set_value(GPIO_NR_PALMLD_IDE_PWEN, 0); - - gpio_free_array(palmld_hdd_gpios, ARRAY_SIZE(palmld_hdd_gpios)); + gpiod_set_value(palmld_pata_power, 0); return 0; } -- cgit v1.2.3 From 614c61a6514e05a4bb0cd8989159f986da132215 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Wed, 5 Dec 2018 09:49:11 +0100 Subject: ata: palmld: Introduce state container This creates a state container struct for the Palm LifeDrive ATA controller, and puts the ATA host and the two GPIO descriptors into this container. This avoids using a singleton so potentially multiple PATA interfaces can be instantiated. Suggested-by: Marek Vasut Reviewed-by: Marek Vasut Signed-off-by: Linus Walleij Signed-off-by: Jens Axboe --- drivers/ata/pata_palmld.c | 59 +++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 23 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/pata_palmld.c b/drivers/ata/pata_palmld.c index e2933c324d41..26817fd91700 100644 --- a/drivers/ata/pata_palmld.c +++ b/drivers/ata/pata_palmld.c @@ -33,7 +33,11 @@ #define DRV_NAME "pata_palmld" -static struct gpio_desc *palmld_pata_power; +struct palmld_pata { + struct ata_host *host; + struct gpio_desc *power; + struct gpio_desc *reset; +}; static struct scsi_host_template palmld_sht = { ATA_PIO_SHT(DRV_NAME), @@ -47,16 +51,19 @@ static struct ata_port_operations palmld_port_ops = { static int palmld_pata_probe(struct platform_device *pdev) { - struct ata_host *host; + struct palmld_pata *lda; struct ata_port *ap; void __iomem *mem; struct device *dev = &pdev->dev; - struct gpio_desc *reset; int ret; + lda = devm_kzalloc(dev, sizeof(*lda), GFP_KERNEL); + if (!lda) + return -ENOMEM; + /* allocate host */ - host = ata_host_alloc(dev, 1); - if (!host) + lda->host = ata_host_alloc(dev, 1); + if (!lda->host) return -ENOMEM; /* remap drive's physical memory address */ @@ -65,23 +72,23 @@ static int palmld_pata_probe(struct platform_device *pdev) return -ENOMEM; /* request and activate power and reset GPIOs */ - palmld_pata_power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH); - if (IS_ERR(palmld_pata_power)) - return PTR_ERR(palmld_pata_power); - reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); - if (IS_ERR(reset)) { - gpiod_set_value(palmld_pata_power, 0); - return PTR_ERR(reset); + lda->power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH); + if (IS_ERR(lda->power)) + return PTR_ERR(lda->power); + lda->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(lda->reset)) { + gpiod_set_value(lda->power, 0); + return PTR_ERR(lda->reset); } /* Assert reset to reset the drive */ - gpiod_set_value(reset, 1); + gpiod_set_value(lda->reset, 1); msleep(30); - gpiod_set_value(reset, 0); + gpiod_set_value(lda->reset, 0); msleep(30); /* setup the ata port */ - ap = host->ports[0]; + ap = lda->host->ports[0]; ap->ops = &palmld_port_ops; ap->pio_mask = ATA_PIO4; ap->flags |= ATA_FLAG_PIO_POLLING; @@ -95,20 +102,26 @@ static int palmld_pata_probe(struct platform_device *pdev) ata_sff_std_ports(&ap->ioaddr); /* activate host */ - ret = ata_host_activate(host, 0, NULL, IRQF_TRIGGER_RISING, - &palmld_sht); + ret = ata_host_activate(lda->host, 0, NULL, IRQF_TRIGGER_RISING, + &palmld_sht); /* power down on failure */ - if (ret) - gpiod_set_value(palmld_pata_power, 0); - return ret; + if (ret) { + gpiod_set_value(lda->power, 0); + return ret; + } + + platform_set_drvdata(pdev, lda); + return 0; } -static int palmld_pata_remove(struct platform_device *dev) +static int palmld_pata_remove(struct platform_device *pdev) { - ata_platform_remove_one(dev); + struct palmld_pata *lda = platform_get_drvdata(pdev); + + ata_platform_remove_one(pdev); /* power down the HDD */ - gpiod_set_value(palmld_pata_power, 0); + gpiod_set_value(lda->power, 0); return 0; } -- cgit v1.2.3 From 9f83cfdb1ace3ef268ecc6fda50058d2ec37d603 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sat, 24 Nov 2018 21:14:16 +0300 Subject: sata_rcar: fix deferred probing The driver overrides the error codes returned by platform_get_irq() to -EINVAL, so if it returns -EPROBE_DEFER, the driver would fail the probe permanently instead of the deferred probing. Switch to propagating the error code upstream, still checking/overriding IRQ0 as libata regards it as "no IRQ" (thus polling) anyway... Fixes: 9ec36cafe43b ("of/irq: do irq resolution in platform_get_irq") Reviewed-by: Simon Horman Reviewed-by: Geert Uytterhoeven Signed-off-by: Sergei Shtylyov Signed-off-by: Jens Axboe --- drivers/ata/sata_rcar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers/ata') diff --git a/drivers/ata/sata_rcar.c b/drivers/ata/sata_rcar.c index 4b1ff5bc256a..59b2317acea9 100644 --- a/drivers/ata/sata_rcar.c +++ b/drivers/ata/sata_rcar.c @@ -891,7 +891,9 @@ static int sata_rcar_probe(struct platform_device *pdev) int ret = 0; irq = platform_get_irq(pdev, 0); - if (irq <= 0) + if (irq < 0) + return irq; + if (!irq) return -EINVAL; priv = devm_kzalloc(dev, sizeof(struct sata_rcar_priv), GFP_KERNEL); -- cgit v1.2.3