Skip to content

Commit 7cb6e22

Browse files
andy-shevaxboe
authored andcommitted
xsysace: use platform_get_resource() and platform_get_irq_optional()
Use platform_get_resource() to fetch the memory resource and platform_get_irq_optional() to get optional IRQ instead of open-coded variants. IRQ is not supposed to be changed at runtime, so there is no functional change in ace_fsm_yieldirq(). On the other hand we now take first resources instead of last ones to proceed. I can't imagine how broken should be firmware to have a garbage in the first resource slots. But if it the case, it needs to be documented. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent aa1c09c commit 7cb6e22

1 file changed

Lines changed: 26 additions & 23 deletions

File tree

drivers/block/xsysace.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -443,22 +443,27 @@ static void ace_fix_driveid(u16 *id)
443443
#define ACE_FSM_NUM_STATES 11
444444

445445
/* Set flag to exit FSM loop and reschedule tasklet */
446-
static inline void ace_fsm_yield(struct ace_device *ace)
446+
static inline void ace_fsm_yieldpoll(struct ace_device *ace)
447447
{
448-
dev_dbg(ace->dev, "ace_fsm_yield()\n");
449448
tasklet_schedule(&ace->fsm_tasklet);
450449
ace->fsm_continue_flag = 0;
451450
}
452451

452+
static inline void ace_fsm_yield(struct ace_device *ace)
453+
{
454+
dev_dbg(ace->dev, "%s()\n", __func__);
455+
ace_fsm_yieldpoll(ace);
456+
}
457+
453458
/* Set flag to exit FSM loop and wait for IRQ to reschedule tasklet */
454459
static inline void ace_fsm_yieldirq(struct ace_device *ace)
455460
{
456461
dev_dbg(ace->dev, "ace_fsm_yieldirq()\n");
457462

458-
if (!ace->irq)
459-
/* No IRQ assigned, so need to poll */
460-
tasklet_schedule(&ace->fsm_tasklet);
461-
ace->fsm_continue_flag = 0;
463+
if (ace->irq > 0)
464+
ace->fsm_continue_flag = 0;
465+
else
466+
ace_fsm_yieldpoll(ace);
462467
}
463468

464469
static bool ace_has_next_request(struct request_queue *q)
@@ -1053,12 +1058,12 @@ static int ace_setup(struct ace_device *ace)
10531058
ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ);
10541059

10551060
/* Now we can hook up the irq handler */
1056-
if (ace->irq) {
1061+
if (ace->irq > 0) {
10571062
rc = request_irq(ace->irq, ace_interrupt, 0, "systemace", ace);
10581063
if (rc) {
10591064
/* Failure - fall back to polled mode */
10601065
dev_err(ace->dev, "request_irq failed\n");
1061-
ace->irq = 0;
1066+
ace->irq = rc;
10621067
}
10631068
}
10641069

@@ -1110,7 +1115,7 @@ static void ace_teardown(struct ace_device *ace)
11101115

11111116
tasklet_kill(&ace->fsm_tasklet);
11121117

1113-
if (ace->irq)
1118+
if (ace->irq > 0)
11141119
free_irq(ace->irq, ace);
11151120

11161121
iounmap(ace->baseaddr);
@@ -1123,11 +1128,6 @@ static int ace_alloc(struct device *dev, int id, resource_size_t physaddr,
11231128
int rc;
11241129
dev_dbg(dev, "ace_alloc(%p)\n", dev);
11251130

1126-
if (!physaddr) {
1127-
rc = -ENODEV;
1128-
goto err_noreg;
1129-
}
1130-
11311131
/* Allocate and initialize the ace device structure */
11321132
ace = kzalloc(sizeof(struct ace_device), GFP_KERNEL);
11331133
if (!ace) {
@@ -1153,7 +1153,6 @@ static int ace_alloc(struct device *dev, int id, resource_size_t physaddr,
11531153
dev_set_drvdata(dev, NULL);
11541154
kfree(ace);
11551155
err_alloc:
1156-
err_noreg:
11571156
dev_err(dev, "could not initialize device, err=%i\n", rc);
11581157
return rc;
11591158
}
@@ -1176,10 +1175,11 @@ static void ace_free(struct device *dev)
11761175

11771176
static int ace_probe(struct platform_device *dev)
11781177
{
1179-
resource_size_t physaddr = 0;
11801178
int bus_width = ACE_BUS_WIDTH_16; /* FIXME: should not be hard coded */
1179+
resource_size_t physaddr;
1180+
struct resource *res;
11811181
u32 id = dev->id;
1182-
int irq = 0;
1182+
int irq;
11831183
int i;
11841184

11851185
dev_dbg(&dev->dev, "ace_probe(%p)\n", dev);
@@ -1190,12 +1190,15 @@ static int ace_probe(struct platform_device *dev)
11901190
if (of_find_property(dev->dev.of_node, "8-bit", NULL))
11911191
bus_width = ACE_BUS_WIDTH_8;
11921192

1193-
for (i = 0; i < dev->num_resources; i++) {
1194-
if (dev->resource[i].flags & IORESOURCE_MEM)
1195-
physaddr = dev->resource[i].start;
1196-
if (dev->resource[i].flags & IORESOURCE_IRQ)
1197-
irq = dev->resource[i].start;
1198-
}
1193+
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
1194+
if (!res)
1195+
return -EINVAL;
1196+
1197+
physaddr = res->start;
1198+
if (!physaddr)
1199+
return -ENODEV;
1200+
1201+
irq = platform_get_irq_optional(dev, 0);
11991202

12001203
/* Call the bus-independent setup code */
12011204
return ace_alloc(&dev->dev, id, physaddr, irq, bus_width);

0 commit comments

Comments
 (0)