Skip to content

Commit 74ac367

Browse files
3x380Vtsbogend
authored andcommitted
MIPS: OCTEON: octeon-usb: use bitfields for host config register
Use Linux standard bitfield access macros to manipulate host config register. Signed-off-by: Ladislav Michl <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]>
1 parent ce942c0 commit 74ac367

File tree

1 file changed

+38
-45
lines changed

1 file changed

+38
-45
lines changed

arch/mips/cavium-octeon/octeon-usb.c

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -126,47 +126,36 @@
126126
#define USBDRD_UCTL_PORT_CFG_SS(port) (0x48 + (0x20 * port))
127127
#define USBDRD_UCTL_PORT_CR_DBG_CFG(port) (0x50 + (0x20 * port))
128128
#define USBDRD_UCTL_PORT_CR_DBG_STATUS(port) (0x58 + (0x20 * port))
129+
130+
/*
131+
* UCTL Configuration Register
132+
*/
129133
#define USBDRD_UCTL_HOST_CFG 0xe0
134+
/* Indicates minimum value of all received BELT values */
135+
# define USBDRD_UCTL_HOST_CFG_HOST_CURRENT_BELT GENMASK(59, 48)
136+
/* HS jitter adjustment */
137+
# define USBDRD_UCTL_HOST_CFG_FLA GENMASK(37, 32)
138+
/* Bus-master enable: 0x0 = Disabled (stall DMAs), 0x1 = enabled */
139+
# define USBDRD_UCTL_HOST_CFG_BME BIT(28)
140+
/* Overcurrent protection enable: 0x0 = unavailable, 0x1 = available */
141+
# define USBDRD_UCTL_HOST_OCI_EN BIT(27)
142+
/* Overcurrent sene selection:
143+
* 0x0 = Overcurrent indication from off-chip is active-low
144+
* 0x1 = Overcurrent indication from off-chip is active-high
145+
*/
146+
# define USBDRD_UCTL_HOST_OCI_ACTIVE_HIGH_EN BIT(26)
147+
/* Port power control enable: 0x0 = unavailable, 0x1 = available */
148+
# define USBDRD_UCTL_HOST_PPC_EN BIT(25)
149+
/* Port power control sense selection:
150+
* 0x0 = Port power to off-chip is active-low
151+
* 0x1 = Port power to off-chip is active-high
152+
*/
153+
# define USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN BIT(24)
154+
130155
#define USBDRD_UCTL_SHIM_CFG 0xe8
131156
#define USBDRD_UCTL_ECC 0xf0
132157
#define USBDRD_UCTL_SPARE1 0xf8
133158

134-
/* UAHC Configuration Register */
135-
union cvm_usbdrd_uctl_host_cfg {
136-
uint64_t u64;
137-
struct cvm_usbdrd_uctl_host_cfg_s {
138-
/* Reserved */
139-
__BITFIELD_FIELD(uint64_t reserved_60_63:4,
140-
/* Indicates minimum value of all received BELT values */
141-
__BITFIELD_FIELD(uint64_t host_current_belt:12,
142-
/* Reserved */
143-
__BITFIELD_FIELD(uint64_t reserved_38_47:10,
144-
/* HS jitter adjustment */
145-
__BITFIELD_FIELD(uint64_t fla:6,
146-
/* Reserved */
147-
__BITFIELD_FIELD(uint64_t reserved_29_31:3,
148-
/* Bus-master enable: 0x0 = Disabled (stall DMAs), 0x1 = enabled */
149-
__BITFIELD_FIELD(uint64_t bme:1,
150-
/* Overcurrent protection enable: 0x0 = unavailable, 0x1 = available */
151-
__BITFIELD_FIELD(uint64_t oci_en:1,
152-
/* Overcurrent sene selection:
153-
* 0x0 = Overcurrent indication from off-chip is active-low
154-
* 0x1 = Overcurrent indication from off-chip is active-high
155-
*/
156-
__BITFIELD_FIELD(uint64_t oci_active_high_en:1,
157-
/* Port power control enable: 0x0 = unavailable, 0x1 = available */
158-
__BITFIELD_FIELD(uint64_t ppc_en:1,
159-
/* Port power control sense selection:
160-
* 0x0 = Port power to off-chip is active-low
161-
* 0x1 = Port power to off-chip is active-high
162-
*/
163-
__BITFIELD_FIELD(uint64_t ppc_active_high_en:1,
164-
/* Reserved */
165-
__BITFIELD_FIELD(uint64_t reserved_0_23:24,
166-
;)))))))))))
167-
} s;
168-
};
169-
170159
/* UCTL Shim Features Register */
171160
union cvm_usbdrd_uctl_shim_cfg {
172161
uint64_t u64;
@@ -224,12 +213,13 @@ static uint8_t clk_div[OCTEON_H_CLKDIV_SEL] = {1, 2, 4, 6, 8, 16, 24, 32};
224213

225214
static int dwc3_octeon_config_power(struct device *dev, u64 base)
226215
{
227-
union cvm_usbdrd_uctl_host_cfg uctl_host_cfg;
228216
union cvmx_gpio_bit_cfgx gpio_bit;
229217
uint32_t gpio_pwr[3];
230218
int gpio, len, power_active_low;
231219
struct device_node *node = dev->of_node;
232220
int index = (base >> 24) & 1;
221+
u64 val;
222+
u64 uctl_host_cfg_reg = base + USBDRD_UCTL_HOST_CFG;
233223

234224
if (of_find_property(node, "power", &len) != NULL) {
235225
if (len == 12) {
@@ -264,16 +254,19 @@ static int dwc3_octeon_config_power(struct device *dev, u64 base)
264254
}
265255

266256
/* Enable XHCI power control and set if active high or low. */
267-
uctl_host_cfg.u64 = cvmx_read_csr(base + USBDRD_UCTL_HOST_CFG);
268-
uctl_host_cfg.s.ppc_en = 1;
269-
uctl_host_cfg.s.ppc_active_high_en = !power_active_low;
270-
cvmx_write_csr(base + USBDRD_UCTL_HOST_CFG, uctl_host_cfg.u64);
257+
val = cvmx_read_csr(uctl_host_cfg_reg);
258+
val |= USBDRD_UCTL_HOST_PPC_EN;
259+
if (power_active_low)
260+
val &= ~USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN;
261+
else
262+
val |= USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN;
263+
cvmx_write_csr(uctl_host_cfg_reg, val);
271264
} else {
272265
/* Disable XHCI power control and set if active high. */
273-
uctl_host_cfg.u64 = cvmx_read_csr(base + USBDRD_UCTL_HOST_CFG);
274-
uctl_host_cfg.s.ppc_en = 0;
275-
uctl_host_cfg.s.ppc_active_high_en = 0;
276-
cvmx_write_csr(base + USBDRD_UCTL_HOST_CFG, uctl_host_cfg.u64);
266+
val = cvmx_read_csr(uctl_host_cfg_reg);
267+
val &= ~USBDRD_UCTL_HOST_PPC_EN;
268+
val &= ~USBDRD_UCTL_HOST_PPC_ACTIVE_HIGH_EN;
269+
cvmx_write_csr(uctl_host_cfg_reg, val);
277270
dev_info(dev, "power control disabled\n");
278271
}
279272
return 0;

0 commit comments

Comments
 (0)