Skip to content

Commit fe2b0cd

Browse files
committed
Merge tag 'for-4.21/libata-20181221' of git://git.kernel.dk/linux-block
Pull libata updates from Jens Axboe: "Here are the libata changes for this merge window. Nothing major in here. This contains: - GPIO descriptor conversions (Linus Walleij) - rcar deferred probing fix (Sergei Shtylyov)" * tag 'for-4.21/libata-20181221' of git://git.kernel.dk/linux-block: sata_rcar: fix deferred probing ata: palmld: Introduce state container ata: palmld: Convert to GPIO descriptors ata: rb532_cf: Convert to use GPIO descriptors ata: sata_highbank: Convert to use GPIO descriptors ata: pxa: Drop <linux/gpio.h> include
2 parents 956eb6c + 9f83cfd commit fe2b0cd

9 files changed

Lines changed: 97 additions & 105 deletions

File tree

‎arch/arm/mach-pxa/palm27x.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#ifndef __INCLUDE_MACH_PALM27X__
1313
#define __INCLUDE_MACH_PALM27X__
1414

15+
#include <linux/gpio/machine.h>
16+
1517
#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
1618
extern void __init palm27x_mmc_init(int detect, int ro, int power,
1719
int power_inverted);

‎arch/arm/mach-pxa/palmld.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,20 @@ static struct platform_device palmld_ide_device = {
288288
.id = -1,
289289
};
290290

291+
static struct gpiod_lookup_table palmld_ide_gpio_table = {
292+
.dev_id = "pata_palmld",
293+
.table = {
294+
GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMLD_IDE_PWEN,
295+
"power", GPIO_ACTIVE_HIGH),
296+
GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMLD_IDE_RESET,
297+
"reset", GPIO_ACTIVE_LOW),
298+
{ },
299+
},
300+
};
301+
291302
static void __init palmld_ide_init(void)
292303
{
304+
gpiod_add_lookup_table(&palmld_ide_gpio_table);
293305
platform_device_register(&palmld_ide_device);
294306
}
295307
#else

‎arch/mips/include/asm/mach-rc32434/rb.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ struct korina_device {
7171
struct net_device *dev;
7272
};
7373

74-
struct cf_device {
75-
int gpio_pin;
76-
void *dev;
77-
struct gendisk *gd;
78-
};
79-
8074
struct mpmc_device {
8175
unsigned char state;
8276
spinlock_t lock;

‎arch/mips/rb532/devices.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/mtd/platnand.h>
2424
#include <linux/mtd/mtd.h>
2525
#include <linux/gpio.h>
26+
#include <linux/gpio/machine.h>
2627
#include <linux/gpio_keys.h>
2728
#include <linux/input.h>
2829
#include <linux/serial_8250.h>
@@ -127,14 +128,18 @@ static struct resource cf_slot0_res[] = {
127128
}
128129
};
129130

130-
static struct cf_device cf_slot0_data = {
131-
.gpio_pin = CF_GPIO_NUM
131+
static struct gpiod_lookup_table cf_slot0_gpio_table = {
132+
.dev_id = "pata-rb532-cf",
133+
.table = {
134+
GPIO_LOOKUP("gpio0", CF_GPIO_NUM,
135+
NULL, GPIO_ACTIVE_HIGH),
136+
{ },
137+
},
132138
};
133139

134140
static struct platform_device cf_slot0 = {
135141
.id = -1,
136142
.name = "pata-rb532-cf",
137-
.dev.platform_data = &cf_slot0_data,
138143
.resource = cf_slot0_res,
139144
.num_resources = ARRAY_SIZE(cf_slot0_res),
140145
};
@@ -305,6 +310,7 @@ static int __init plat_setup_devices(void)
305310

306311
dev_set_drvdata(&korina_dev0.dev, &korina_dev0_data);
307312

313+
gpiod_add_lookup_table(&cf_slot0_gpio_table);
308314
return platform_add_devices(rb532_devs, ARRAY_SIZE(rb532_devs));
309315
}
310316

‎drivers/ata/pata_palmld.c‎

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@
2626
#include <linux/irq.h>
2727
#include <linux/platform_device.h>
2828
#include <linux/delay.h>
29-
#include <linux/gpio.h>
29+
#include <linux/gpio/consumer.h>
3030

3131
#include <scsi/scsi_host.h>
3232
#include <mach/palmld.h>
3333

3434
#define DRV_NAME "pata_palmld"
3535

36-
static struct gpio palmld_hdd_gpios[] = {
37-
{ GPIO_NR_PALMLD_IDE_PWEN, GPIOF_INIT_HIGH, "HDD Power" },
38-
{ GPIO_NR_PALMLD_IDE_RESET, GPIOF_INIT_LOW, "HDD Reset" },
36+
struct palmld_pata {
37+
struct ata_host *host;
38+
struct gpio_desc *power;
39+
struct gpio_desc *reset;
3940
};
4041

4142
static struct scsi_host_template palmld_sht = {
@@ -50,39 +51,44 @@ static struct ata_port_operations palmld_port_ops = {
5051

5152
static int palmld_pata_probe(struct platform_device *pdev)
5253
{
53-
struct ata_host *host;
54+
struct palmld_pata *lda;
5455
struct ata_port *ap;
5556
void __iomem *mem;
57+
struct device *dev = &pdev->dev;
5658
int ret;
5759

60+
lda = devm_kzalloc(dev, sizeof(*lda), GFP_KERNEL);
61+
if (!lda)
62+
return -ENOMEM;
63+
5864
/* allocate host */
59-
host = ata_host_alloc(&pdev->dev, 1);
60-
if (!host) {
61-
ret = -ENOMEM;
62-
goto err1;
63-
}
65+
lda->host = ata_host_alloc(dev, 1);
66+
if (!lda->host)
67+
return -ENOMEM;
6468

6569
/* remap drive's physical memory address */
66-
mem = devm_ioremap(&pdev->dev, PALMLD_IDE_PHYS, 0x1000);
67-
if (!mem) {
68-
ret = -ENOMEM;
69-
goto err1;
70+
mem = devm_ioremap(dev, PALMLD_IDE_PHYS, 0x1000);
71+
if (!mem)
72+
return -ENOMEM;
73+
74+
/* request and activate power and reset GPIOs */
75+
lda->power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH);
76+
if (IS_ERR(lda->power))
77+
return PTR_ERR(lda->power);
78+
lda->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
79+
if (IS_ERR(lda->reset)) {
80+
gpiod_set_value(lda->power, 0);
81+
return PTR_ERR(lda->reset);
7082
}
7183

72-
/* request and activate power GPIO, IRQ GPIO */
73-
ret = gpio_request_array(palmld_hdd_gpios,
74-
ARRAY_SIZE(palmld_hdd_gpios));
75-
if (ret)
76-
goto err1;
77-
78-
/* reset the drive */
79-
gpio_set_value(GPIO_NR_PALMLD_IDE_RESET, 0);
84+
/* Assert reset to reset the drive */
85+
gpiod_set_value(lda->reset, 1);
8086
msleep(30);
81-
gpio_set_value(GPIO_NR_PALMLD_IDE_RESET, 1);
87+
gpiod_set_value(lda->reset, 0);
8288
msleep(30);
8389

8490
/* setup the ata port */
85-
ap = host->ports[0];
91+
ap = lda->host->ports[0];
8692
ap->ops = &palmld_port_ops;
8793
ap->pio_mask = ATA_PIO4;
8894
ap->flags |= ATA_FLAG_PIO_POLLING;
@@ -96,27 +102,26 @@ static int palmld_pata_probe(struct platform_device *pdev)
96102
ata_sff_std_ports(&ap->ioaddr);
97103

98104
/* activate host */
99-
ret = ata_host_activate(host, 0, NULL, IRQF_TRIGGER_RISING,
100-
&palmld_sht);
101-
if (ret)
102-
goto err2;
103-
104-
return ret;
105+
ret = ata_host_activate(lda->host, 0, NULL, IRQF_TRIGGER_RISING,
106+
&palmld_sht);
107+
/* power down on failure */
108+
if (ret) {
109+
gpiod_set_value(lda->power, 0);
110+
return ret;
111+
}
105112

106-
err2:
107-
gpio_free_array(palmld_hdd_gpios, ARRAY_SIZE(palmld_hdd_gpios));
108-
err1:
109-
return ret;
113+
platform_set_drvdata(pdev, lda);
114+
return 0;
110115
}
111116

112-
static int palmld_pata_remove(struct platform_device *dev)
117+
static int palmld_pata_remove(struct platform_device *pdev)
113118
{
114-
ata_platform_remove_one(dev);
119+
struct palmld_pata *lda = platform_get_drvdata(pdev);
115120

116-
/* power down the HDD */
117-
gpio_set_value(GPIO_NR_PALMLD_IDE_PWEN, 0);
121+
ata_platform_remove_one(pdev);
118122

119-
gpio_free_array(palmld_hdd_gpios, ARRAY_SIZE(palmld_hdd_gpios));
123+
/* power down the HDD */
124+
gpiod_set_value(lda->power, 0);
120125

121126
return 0;
122127
}

‎drivers/ata/pata_pxa.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <linux/libata.h>
2626
#include <linux/platform_device.h>
2727
#include <linux/dmaengine.h>
28-
#include <linux/gpio.h>
2928
#include <linux/slab.h>
3029
#include <linux/completion.h>
3130

‎drivers/ata/pata_rb532_cf.c‎

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <linux/io.h>
2828
#include <linux/interrupt.h>
2929
#include <linux/irq.h>
30-
#include <linux/gpio.h>
30+
#include <linux/gpio/consumer.h>
3131

3232
#include <linux/libata.h>
3333
#include <scsi/scsi_host.h>
@@ -49,7 +49,7 @@
4949

5050
struct rb532_cf_info {
5151
void __iomem *iobase;
52-
unsigned int gpio_line;
52+
struct gpio_desc *gpio_line;
5353
unsigned int irq;
5454
};
5555

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

63-
if (gpio_get_value(info->gpio_line)) {
63+
if (gpiod_get_value(info->gpio_line)) {
6464
irq_set_irq_type(info->irq, IRQ_TYPE_LEVEL_LOW);
6565
ata_sff_interrupt(info->irq, dev_instance);
6666
} else {
@@ -106,10 +106,9 @@ static void rb532_pata_setup_ports(struct ata_host *ah)
106106
static int rb532_pata_driver_probe(struct platform_device *pdev)
107107
{
108108
int irq;
109-
int gpio;
109+
struct gpio_desc *gpiod;
110110
struct resource *res;
111111
struct ata_host *ah;
112-
struct cf_device *pdata;
113112
struct rb532_cf_info *info;
114113
int ret;
115114

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

128-
pdata = dev_get_platdata(&pdev->dev);
129-
if (!pdata) {
130-
dev_err(&pdev->dev, "no platform data specified\n");
131-
return -EINVAL;
132-
}
133-
134-
gpio = pdata->gpio_pin;
135-
if (gpio < 0) {
127+
gpiod = devm_gpiod_get(&pdev->dev, NULL, GPIOD_IN);
128+
if (IS_ERR(gpiod)) {
136129
dev_err(&pdev->dev, "no GPIO found for irq%d\n", irq);
137-
return -ENOENT;
138-
}
139-
140-
ret = gpio_request(gpio, DRV_NAME);
141-
if (ret) {
142-
dev_err(&pdev->dev, "GPIO request failed\n");
143-
return ret;
130+
return PTR_ERR(gpiod);
144131
}
132+
gpiod_set_consumer_name(gpiod, DRV_NAME);
145133

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

155143
ah->private_data = info;
156-
info->gpio_line = gpio;
144+
info->gpio_line = gpiod;
157145
info->irq = irq;
158146

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

164-
ret = gpio_direction_input(gpio);
165-
if (ret) {
166-
dev_err(&pdev->dev, "unable to set GPIO direction, err=%d\n",
167-
ret);
168-
goto err_free_gpio;
169-
}
170-
171152
rb532_pata_setup_ports(ah);
172153

173154
ret = ata_host_activate(ah, irq, rb532_pata_irq_handler,
174155
IRQF_TRIGGER_LOW, &rb532_pata_sht);
175156
if (ret)
176-
goto err_free_gpio;
157+
return ret;
177158

178159
return 0;
179-
180-
err_free_gpio:
181-
gpio_free(gpio);
182-
183-
return ret;
184160
}
185161

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

191167
ata_host_detach(ah);
192-
gpio_free(info->gpio_line);
193168

194169
return 0;
195170
}

0 commit comments

Comments
 (0)