Skip to content

Commit 204b779

Browse files
elbeastoSarah Sharp
authored andcommitted
xhci: replace xhci_writel() with writel()
Function xhci_writel() is used to write a 32bit value in xHC registers residing in MMIO address space. It takes as first argument a pointer to the xhci_hcd although it does not use it. xhci_writel() internally simply calls writel(). This creates an illusion that xhci_writel() is an xhci specific function that has to be called in a context where a pointer to xhci_hcd is available. Remove xhci_writel() wrapper function and replace its calls with calls to writel() to make the code more straight-forward. Signed-off-by: Xenia Ragiadakou <[email protected]> Signed-off-by: Sarah Sharp <[email protected]>
1 parent b0ba972 commit 204b779

File tree

5 files changed

+47
-61
lines changed

5 files changed

+47
-61
lines changed

drivers/usb/host/xhci-hub.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ static void xhci_disable_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
342342
}
343343

344344
/* Write 1 to disable the port */
345-
xhci_writel(xhci, port_status | PORT_PE, addr);
345+
writel(port_status | PORT_PE, addr);
346346
port_status = readl(addr);
347347
xhci_dbg(xhci, "disable port, actual port %d status = 0x%x\n",
348348
wIndex, port_status);
@@ -388,7 +388,7 @@ static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue,
388388
return;
389389
}
390390
/* Change bits are all write 1 to clear */
391-
xhci_writel(xhci, port_status | status, addr);
391+
writel(port_status | status, addr);
392392
port_status = readl(addr);
393393
xhci_dbg(xhci, "clear port %s change, actual port %d status = 0x%x\n",
394394
port_change_bit, wIndex, port_status);
@@ -419,7 +419,7 @@ void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array,
419419
temp = xhci_port_state_to_neutral(temp);
420420
temp &= ~PORT_PLS_MASK;
421421
temp |= PORT_LINK_STROBE | link_state;
422-
xhci_writel(xhci, temp, port_array[port_id]);
422+
writel(temp, port_array[port_id]);
423423
}
424424

425425
static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci,
@@ -445,7 +445,7 @@ static void xhci_set_remote_wake_mask(struct xhci_hcd *xhci,
445445
else
446446
temp &= ~PORT_WKOC_E;
447447

448-
xhci_writel(xhci, temp, port_array[port_id]);
448+
writel(temp, port_array[port_id]);
449449
}
450450

451451
/* Test and clear port RWC bit */
@@ -458,7 +458,7 @@ void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array,
458458
if (temp & port_bit) {
459459
temp = xhci_port_state_to_neutral(temp);
460460
temp |= port_bit;
461-
xhci_writel(xhci, temp, port_array[port_id]);
461+
writel(temp, port_array[port_id]);
462462
}
463463
}
464464

@@ -838,8 +838,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
838838
temp |= PORT_CSC | PORT_PEC | PORT_WRC |
839839
PORT_OCC | PORT_RC | PORT_PLC |
840840
PORT_CEC;
841-
xhci_writel(xhci, temp | PORT_PE,
842-
port_array[wIndex]);
841+
writel(temp | PORT_PE, port_array[wIndex]);
843842
temp = readl(port_array[wIndex]);
844843
break;
845844
}
@@ -894,8 +893,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
894893
* However, khubd will ignore the roothub events until
895894
* the roothub is registered.
896895
*/
897-
xhci_writel(xhci, temp | PORT_POWER,
898-
port_array[wIndex]);
896+
writel(temp | PORT_POWER, port_array[wIndex]);
899897

900898
temp = readl(port_array[wIndex]);
901899
xhci_dbg(xhci, "set port power, actual port %d status = 0x%x\n", wIndex, temp);
@@ -910,7 +908,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
910908
break;
911909
case USB_PORT_FEAT_RESET:
912910
temp = (temp | PORT_RESET);
913-
xhci_writel(xhci, temp, port_array[wIndex]);
911+
writel(temp, port_array[wIndex]);
914912

915913
temp = readl(port_array[wIndex]);
916914
xhci_dbg(xhci, "set port reset, actual port %d status = 0x%x\n", wIndex, temp);
@@ -925,7 +923,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
925923
break;
926924
case USB_PORT_FEAT_BH_PORT_RESET:
927925
temp |= PORT_WR;
928-
xhci_writel(xhci, temp, port_array[wIndex]);
926+
writel(temp, port_array[wIndex]);
929927

930928
temp = readl(port_array[wIndex]);
931929
break;
@@ -935,15 +933,15 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
935933
temp = readl(port_array[wIndex] + PORTPMSC);
936934
temp &= ~PORT_U1_TIMEOUT_MASK;
937935
temp |= PORT_U1_TIMEOUT(timeout);
938-
xhci_writel(xhci, temp, port_array[wIndex] + PORTPMSC);
936+
writel(temp, port_array[wIndex] + PORTPMSC);
939937
break;
940938
case USB_PORT_FEAT_U2_TIMEOUT:
941939
if (hcd->speed != HCD_USB3)
942940
goto error;
943941
temp = readl(port_array[wIndex] + PORTPMSC);
944942
temp &= ~PORT_U2_TIMEOUT_MASK;
945943
temp |= PORT_U2_TIMEOUT(timeout);
946-
xhci_writel(xhci, temp, port_array[wIndex] + PORTPMSC);
944+
writel(temp, port_array[wIndex] + PORTPMSC);
947945
break;
948946
default:
949947
goto error;
@@ -1007,8 +1005,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
10071005
port_array[wIndex], temp);
10081006
break;
10091007
case USB_PORT_FEAT_POWER:
1010-
xhci_writel(xhci, temp & ~PORT_POWER,
1011-
port_array[wIndex]);
1008+
writel(temp & ~PORT_POWER, port_array[wIndex]);
10121009

10131010
spin_unlock_irqrestore(&xhci->lock, flags);
10141011
temp = usb_acpi_power_manageable(hcd->self.root_hub,
@@ -1156,7 +1153,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
11561153

11571154
t1 = xhci_port_state_to_neutral(t1);
11581155
if (t1 != t2)
1159-
xhci_writel(xhci, t2, port_array[port_index]);
1156+
writel(t2, port_array[port_index]);
11601157
}
11611158
hcd->state = HC_STATE_SUSPENDED;
11621159
bus_state->next_statechange = jiffies + msecs_to_jiffies(10);
@@ -1188,7 +1185,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
11881185
/* delay the irqs */
11891186
temp = readl(&xhci->op_regs->command);
11901187
temp &= ~CMD_EIE;
1191-
xhci_writel(xhci, temp, &xhci->op_regs->command);
1188+
writel(temp, &xhci->op_regs->command);
11921189

11931190
port_index = max_ports;
11941191
while (port_index--) {
@@ -1234,7 +1231,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
12341231
if (slot_id)
12351232
xhci_ring_device(xhci, slot_id);
12361233
} else
1237-
xhci_writel(xhci, temp, port_array[port_index]);
1234+
writel(temp, port_array[port_index]);
12381235
}
12391236

12401237
(void) readl(&xhci->op_regs->command);
@@ -1243,7 +1240,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
12431240
/* re-enable irqs */
12441241
temp = readl(&xhci->op_regs->command);
12451242
temp |= CMD_EIE;
1246-
xhci_writel(xhci, temp, &xhci->op_regs->command);
1243+
writel(temp, &xhci->op_regs->command);
12471244
temp = readl(&xhci->op_regs->command);
12481245

12491246
spin_unlock_irqrestore(&xhci->lock, flags);

drivers/usb/host/xhci-mem.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
22542254
val |= (val2 & ~HCS_SLOTS_MASK);
22552255
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
22562256
"// Setting Max device slots reg = 0x%x.", val);
2257-
xhci_writel(xhci, val, &xhci->op_regs->config_reg);
2257+
writel(val, &xhci->op_regs->config_reg);
22582258

22592259
/*
22602260
* Section 5.4.8 - doorbell array must be
@@ -2388,7 +2388,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
23882388
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
23892389
"// Write ERST size = %i to ir_set 0 (some bits preserved)",
23902390
val);
2391-
xhci_writel(xhci, val, &xhci->ir_set->erst_size);
2391+
writel(val, &xhci->ir_set->erst_size);
23922392

23932393
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
23942394
"// Set ERST entries to point to event ring.");
@@ -2434,7 +2434,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
24342434
temp = readl(&xhci->op_regs->dev_notification);
24352435
temp &= ~DEV_NOTE_MASK;
24362436
temp |= DEV_NOTE_FWAKE;
2437-
xhci_writel(xhci, temp, &xhci->op_regs->dev_notification);
2437+
writel(temp, &xhci->op_regs->dev_notification);
24382438

24392439
return 0;
24402440

drivers/usb/host/xhci-ring.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ void xhci_ring_cmd_db(struct xhci_hcd *xhci)
295295
return;
296296

297297
xhci_dbg(xhci, "// Ding dong!\n");
298-
xhci_writel(xhci, DB_VALUE_HOST, &xhci->dba->doorbell[0]);
298+
writel(DB_VALUE_HOST, &xhci->dba->doorbell[0]);
299299
/* Flush PCI posted writes */
300300
readl(&xhci->dba->doorbell[0]);
301301
}
@@ -427,7 +427,7 @@ void xhci_ring_ep_doorbell(struct xhci_hcd *xhci,
427427
if ((ep_state & EP_HALT_PENDING) || (ep_state & SET_DEQ_PENDING) ||
428428
(ep_state & EP_HALTED))
429429
return;
430-
xhci_writel(xhci, DB_VALUE(ep_index, stream_id), db_addr);
430+
writel(DB_VALUE(ep_index, stream_id), db_addr);
431431
/* The CPU has better things to do at this point than wait for a
432432
* write-posting flush. It'll get there soon enough.
433433
*/
@@ -2853,7 +2853,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
28532853
* Write 1 to clear the interrupt status.
28542854
*/
28552855
status |= STS_EINT;
2856-
xhci_writel(xhci, status, &xhci->op_regs->status);
2856+
writel(status, &xhci->op_regs->status);
28572857
/* FIXME when MSI-X is supported and there are multiple vectors */
28582858
/* Clear the MSI-X event interrupt status */
28592859

@@ -2862,7 +2862,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
28622862
/* Acknowledge the PCI interrupt */
28632863
irq_pending = readl(&xhci->ir_set->irq_pending);
28642864
irq_pending |= IMAN_IP;
2865-
xhci_writel(xhci, irq_pending, &xhci->ir_set->irq_pending);
2865+
writel(irq_pending, &xhci->ir_set->irq_pending);
28662866
}
28672867

28682868
if (xhci->xhc_state & XHCI_STATE_DYING) {

drivers/usb/host/xhci.c

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void xhci_quiesce(struct xhci_hcd *xhci)
8888

8989
cmd = readl(&xhci->op_regs->command);
9090
cmd &= mask;
91-
xhci_writel(xhci, cmd, &xhci->op_regs->command);
91+
writel(cmd, &xhci->op_regs->command);
9292
}
9393

9494
/*
@@ -128,7 +128,7 @@ static int xhci_start(struct xhci_hcd *xhci)
128128
temp |= (CMD_RUN);
129129
xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Turn on HC, cmd = 0x%x.",
130130
temp);
131-
xhci_writel(xhci, temp, &xhci->op_regs->command);
131+
writel(temp, &xhci->op_regs->command);
132132

133133
/*
134134
* Wait for the HCHalted Status bit to be 0 to indicate the host is
@@ -167,7 +167,7 @@ int xhci_reset(struct xhci_hcd *xhci)
167167
xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Reset the HC");
168168
command = readl(&xhci->op_regs->command);
169169
command |= CMD_RESET;
170-
xhci_writel(xhci, command, &xhci->op_regs->command);
170+
writel(command, &xhci->op_regs->command);
171171

172172
ret = xhci_handshake(xhci, &xhci->op_regs->command,
173173
CMD_RESET, 0, 10 * 1000 * 1000);
@@ -614,21 +614,20 @@ int xhci_run(struct usb_hcd *hcd)
614614
temp = readl(&xhci->ir_set->irq_control);
615615
temp &= ~ER_IRQ_INTERVAL_MASK;
616616
temp |= (u32) 160;
617-
xhci_writel(xhci, temp, &xhci->ir_set->irq_control);
617+
writel(temp, &xhci->ir_set->irq_control);
618618

619619
/* Set the HCD state before we enable the irqs */
620620
temp = readl(&xhci->op_regs->command);
621621
temp |= (CMD_EIE);
622622
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
623623
"// Enable interrupts, cmd = 0x%x.", temp);
624-
xhci_writel(xhci, temp, &xhci->op_regs->command);
624+
writel(temp, &xhci->op_regs->command);
625625

626626
temp = readl(&xhci->ir_set->irq_pending);
627627
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
628628
"// Enabling event ring interrupter %p by writing 0x%x to irq_pending",
629629
xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp));
630-
xhci_writel(xhci, ER_IRQ_ENABLE(temp),
631-
&xhci->ir_set->irq_pending);
630+
writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending);
632631
xhci_print_ir_set(xhci, 0);
633632

634633
if (xhci->quirks & XHCI_NEC_HOST)
@@ -699,10 +698,9 @@ void xhci_stop(struct usb_hcd *hcd)
699698
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
700699
"// Disabling event ring interrupts");
701700
temp = readl(&xhci->op_regs->status);
702-
xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status);
701+
writel(temp & ~STS_EINT, &xhci->op_regs->status);
703702
temp = readl(&xhci->ir_set->irq_pending);
704-
xhci_writel(xhci, ER_IRQ_DISABLE(temp),
705-
&xhci->ir_set->irq_pending);
703+
writel(ER_IRQ_DISABLE(temp), &xhci->ir_set->irq_pending);
706704
xhci_print_ir_set(xhci, 0);
707705

708706
xhci_dbg_trace(xhci, trace_xhci_dbg_init, "cleaning up memory");
@@ -762,15 +760,15 @@ static void xhci_save_registers(struct xhci_hcd *xhci)
762760

763761
static void xhci_restore_registers(struct xhci_hcd *xhci)
764762
{
765-
xhci_writel(xhci, xhci->s3.command, &xhci->op_regs->command);
766-
xhci_writel(xhci, xhci->s3.dev_nt, &xhci->op_regs->dev_notification);
763+
writel(xhci->s3.command, &xhci->op_regs->command);
764+
writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification);
767765
xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr);
768-
xhci_writel(xhci, xhci->s3.config_reg, &xhci->op_regs->config_reg);
769-
xhci_writel(xhci, xhci->s3.erst_size, &xhci->ir_set->erst_size);
766+
writel(xhci->s3.config_reg, &xhci->op_regs->config_reg);
767+
writel(xhci->s3.erst_size, &xhci->ir_set->erst_size);
770768
xhci_write_64(xhci, xhci->s3.erst_base, &xhci->ir_set->erst_base);
771769
xhci_write_64(xhci, xhci->s3.erst_dequeue, &xhci->ir_set->erst_dequeue);
772-
xhci_writel(xhci, xhci->s3.irq_pending, &xhci->ir_set->irq_pending);
773-
xhci_writel(xhci, xhci->s3.irq_control, &xhci->ir_set->irq_control);
770+
writel(xhci->s3.irq_pending, &xhci->ir_set->irq_pending);
771+
writel(xhci->s3.irq_control, &xhci->ir_set->irq_control);
774772
}
775773

776774
static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci)
@@ -868,7 +866,7 @@ int xhci_suspend(struct xhci_hcd *xhci)
868866
/* step 2: clear Run/Stop bit */
869867
command = readl(&xhci->op_regs->command);
870868
command &= ~CMD_RUN;
871-
xhci_writel(xhci, command, &xhci->op_regs->command);
869+
writel(command, &xhci->op_regs->command);
872870

873871
/* Some chips from Fresco Logic need an extraordinary delay */
874872
delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1;
@@ -887,7 +885,7 @@ int xhci_suspend(struct xhci_hcd *xhci)
887885
/* step 4: set CSS flag */
888886
command = readl(&xhci->op_regs->command);
889887
command |= CMD_CSS;
890-
xhci_writel(xhci, command, &xhci->op_regs->command);
888+
writel(command, &xhci->op_regs->command);
891889
if (xhci_handshake(xhci, &xhci->op_regs->status,
892890
STS_SAVE, 0, 10 * 1000)) {
893891
xhci_warn(xhci, "WARN: xHC save state timeout\n");
@@ -953,7 +951,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
953951
/* step 3: set CRS flag */
954952
command = readl(&xhci->op_regs->command);
955953
command |= CMD_CRS;
956-
xhci_writel(xhci, command, &xhci->op_regs->command);
954+
writel(command, &xhci->op_regs->command);
957955
if (xhci_handshake(xhci, &xhci->op_regs->status,
958956
STS_RESTORE, 0, 10 * 1000)) {
959957
xhci_warn(xhci, "WARN: xHC restore state timeout\n");
@@ -985,10 +983,9 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
985983

986984
xhci_dbg(xhci, "// Disabling event ring interrupts\n");
987985
temp = readl(&xhci->op_regs->status);
988-
xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status);
986+
writel(temp & ~STS_EINT, &xhci->op_regs->status);
989987
temp = readl(&xhci->ir_set->irq_pending);
990-
xhci_writel(xhci, ER_IRQ_DISABLE(temp),
991-
&xhci->ir_set->irq_pending);
988+
writel(ER_IRQ_DISABLE(temp), &xhci->ir_set->irq_pending);
992989
xhci_print_ir_set(xhci, 0);
993990

994991
xhci_dbg(xhci, "cleaning up memory\n");
@@ -1025,7 +1022,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
10251022
/* step 4: set Run/Stop bit */
10261023
command = readl(&xhci->op_regs->command);
10271024
command |= CMD_RUN;
1028-
xhci_writel(xhci, command, &xhci->op_regs->command);
1025+
writel(command, &xhci->op_regs->command);
10291026
xhci_handshake(xhci, &xhci->op_regs->status, STS_HALT,
10301027
0, 250 * 1000);
10311028

@@ -4082,7 +4079,7 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
40824079
spin_lock_irqsave(&xhci->lock, flags);
40834080

40844081
hlpm_val = xhci_calculate_usb2_hw_lpm_params(udev);
4085-
xhci_writel(xhci, hlpm_val, hlpm_addr);
4082+
writel(hlpm_val, hlpm_addr);
40864083
/* flush write */
40874084
readl(hlpm_addr);
40884085
} else {
@@ -4091,15 +4088,15 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
40914088

40924089
pm_val &= ~PORT_HIRD_MASK;
40934090
pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id);
4094-
xhci_writel(xhci, pm_val, pm_addr);
4091+
writel(pm_val, pm_addr);
40954092
pm_val = readl(pm_addr);
40964093
pm_val |= PORT_HLE;
4097-
xhci_writel(xhci, pm_val, pm_addr);
4094+
writel(pm_val, pm_addr);
40984095
/* flush write */
40994096
readl(pm_addr);
41004097
} else {
41014098
pm_val &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK | PORT_L1DS_MASK);
4102-
xhci_writel(xhci, pm_val, pm_addr);
4099+
writel(pm_val, pm_addr);
41034100
/* flush write */
41044101
readl(pm_addr);
41054102
if (udev->usb2_hw_lpm_besl_capable) {

drivers/usb/host/xhci.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,14 +1595,6 @@ static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
15951595
#define xhci_warn_ratelimited(xhci, fmt, args...) \
15961596
dev_warn_ratelimited(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
15971597

1598-
/* TODO: copied from ehci.h - can be refactored? */
1599-
/* xHCI spec says all registers are little endian */
1600-
static inline void xhci_writel(struct xhci_hcd *xhci,
1601-
const unsigned int val, __le32 __iomem *regs)
1602-
{
1603-
writel(val, regs);
1604-
}
1605-
16061598
/*
16071599
* Registers should always be accessed with double word or quad word accesses.
16081600
*

0 commit comments

Comments
 (0)