Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Andy Shevchenko and committed by
Jens Axboe
7cb6e22b aa1c09cb

+26 -23
+26 -23
drivers/block/xsysace.c
··· 443 443 #define ACE_FSM_NUM_STATES 11 444 444 445 445 /* 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) 447 447 { 448 - dev_dbg(ace->dev, "ace_fsm_yield()\n"); 449 448 tasklet_schedule(&ace->fsm_tasklet); 450 449 ace->fsm_continue_flag = 0; 450 + } 451 + 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); 451 456 } 452 457 453 458 /* Set flag to exit FSM loop and wait for IRQ to reschedule tasklet */ ··· 460 455 { 461 456 dev_dbg(ace->dev, "ace_fsm_yieldirq()\n"); 462 457 463 - if (!ace->irq) 464 - /* No IRQ assigned, so need to poll */ 465 - tasklet_schedule(&ace->fsm_tasklet); 466 - ace->fsm_continue_flag = 0; 458 + if (ace->irq > 0) 459 + ace->fsm_continue_flag = 0; 460 + else 461 + ace_fsm_yieldpoll(ace); 467 462 } 468 463 469 464 static bool ace_has_next_request(struct request_queue *q) ··· 1058 1053 ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ); 1059 1054 1060 1055 /* Now we can hook up the irq handler */ 1061 - if (ace->irq) { 1056 + if (ace->irq > 0) { 1062 1057 rc = request_irq(ace->irq, ace_interrupt, 0, "systemace", ace); 1063 1058 if (rc) { 1064 1059 /* Failure - fall back to polled mode */ 1065 1060 dev_err(ace->dev, "request_irq failed\n"); 1066 - ace->irq = 0; 1061 + ace->irq = rc; 1067 1062 } 1068 1063 } 1069 1064 ··· 1115 1110 1116 1111 tasklet_kill(&ace->fsm_tasklet); 1117 1112 1118 - if (ace->irq) 1113 + if (ace->irq > 0) 1119 1114 free_irq(ace->irq, ace); 1120 1115 1121 1116 iounmap(ace->baseaddr); ··· 1127 1122 struct ace_device *ace; 1128 1123 int rc; 1129 1124 dev_dbg(dev, "ace_alloc(%p)\n", dev); 1130 - 1131 - if (!physaddr) { 1132 - rc = -ENODEV; 1133 - goto err_noreg; 1134 - } 1135 1125 1136 1126 /* Allocate and initialize the ace device structure */ 1137 1127 ace = kzalloc(sizeof(struct ace_device), GFP_KERNEL); ··· 1153 1153 dev_set_drvdata(dev, NULL); 1154 1154 kfree(ace); 1155 1155 err_alloc: 1156 - err_noreg: 1157 1156 dev_err(dev, "could not initialize device, err=%i\n", rc); 1158 1157 return rc; 1159 1158 } ··· 1175 1176 1176 1177 static int ace_probe(struct platform_device *dev) 1177 1178 { 1178 - resource_size_t physaddr = 0; 1179 1179 int bus_width = ACE_BUS_WIDTH_16; /* FIXME: should not be hard coded */ 1180 + resource_size_t physaddr; 1181 + struct resource *res; 1180 1182 u32 id = dev->id; 1181 - int irq = 0; 1183 + int irq; 1182 1184 int i; 1183 1185 1184 1186 dev_dbg(&dev->dev, "ace_probe(%p)\n", dev); ··· 1190 1190 if (of_find_property(dev->dev.of_node, "8-bit", NULL)) 1191 1191 bus_width = ACE_BUS_WIDTH_8; 1192 1192 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); 1199 1202 1200 1203 /* Call the bus-independent setup code */ 1201 1204 return ace_alloc(&dev->dev, id, physaddr, irq, bus_width);