Lines Matching +full:data +full:- +full:role
1 // SPDX-License-Identifier: GPL-2.0+
3 * Intel XHCI (Cherry Trail, Broxton and others) USB OTG role switch driver
5 * Copyright (c) 2016-2017 Hans de Goede <hdegoede@redhat.com>
23 #include <linux/usb/role.h>
52 "intel-xhci-usb-sw",
56 enum usb_role role) in intel_xhci_usb_set_role() argument
58 struct intel_xhci_usb_data *data = usb_role_switch_get_drvdata(sw); in intel_xhci_usb_set_role() local
71 dev_err(data->dev, "Error could not acquire lock\n"); in intel_xhci_usb_set_role()
72 return -EIO; in intel_xhci_usb_set_role()
75 pm_runtime_get_sync(data->dev); in intel_xhci_usb_set_role()
80 * SW_SWITCH_EN bits to be zero for role switch, in intel_xhci_usb_set_role()
83 val = readl(data->base + DUAL_ROLE_CFG0); in intel_xhci_usb_set_role()
84 switch (role) { in intel_xhci_usb_set_role()
102 if (data->enable_sw_switch) { in intel_xhci_usb_set_role()
106 writel(val, data->base + DUAL_ROLE_CFG0); in intel_xhci_usb_set_role()
115 val = readl(data->base + DUAL_ROLE_CFG1); in intel_xhci_usb_set_role()
116 if (!!(val & HOST_MODE) == (role == USB_ROLE_HOST)) { in intel_xhci_usb_set_role()
117 pm_runtime_put(data->dev); in intel_xhci_usb_set_role()
121 /* Interval for polling is set to about 5 - 10 ms */ in intel_xhci_usb_set_role()
125 pm_runtime_put(data->dev); in intel_xhci_usb_set_role()
127 dev_warn(data->dev, "Timeout waiting for role-switch\n"); in intel_xhci_usb_set_role()
128 return -ETIMEDOUT; in intel_xhci_usb_set_role()
133 struct intel_xhci_usb_data *data = usb_role_switch_get_drvdata(sw); in intel_xhci_usb_get_role() local
134 enum usb_role role; in intel_xhci_usb_get_role() local
137 pm_runtime_get_sync(data->dev); in intel_xhci_usb_get_role()
138 val = readl(data->base + DUAL_ROLE_CFG0); in intel_xhci_usb_get_role()
139 pm_runtime_put(data->dev); in intel_xhci_usb_get_role()
142 role = USB_ROLE_HOST; in intel_xhci_usb_get_role()
144 role = USB_ROLE_DEVICE; in intel_xhci_usb_get_role()
146 role = USB_ROLE_NONE; in intel_xhci_usb_get_role()
148 return role; in intel_xhci_usb_get_role()
154 struct device *dev = &pdev->dev; in intel_xhci_usb_probe()
155 struct intel_xhci_usb_data *data; in intel_xhci_usb_probe() local
159 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); in intel_xhci_usb_probe()
160 if (!data) in intel_xhci_usb_probe()
161 return -ENOMEM; in intel_xhci_usb_probe()
165 return -EINVAL; in intel_xhci_usb_probe()
166 data->base = devm_ioremap(dev, res->start, resource_size(res)); in intel_xhci_usb_probe()
167 if (!data->base) in intel_xhci_usb_probe()
168 return -ENOMEM; in intel_xhci_usb_probe()
170 platform_set_drvdata(pdev, data); in intel_xhci_usb_probe()
180 sw_desc.driver_data = data; in intel_xhci_usb_probe()
182 data->dev = dev; in intel_xhci_usb_probe()
183 data->enable_sw_switch = !device_property_read_bool(dev, in intel_xhci_usb_probe()
186 data->role_sw = usb_role_switch_register(dev, &sw_desc); in intel_xhci_usb_probe()
187 if (IS_ERR(data->role_sw)) { in intel_xhci_usb_probe()
189 return PTR_ERR(data->role_sw); in intel_xhci_usb_probe()
200 struct intel_xhci_usb_data *data = platform_get_drvdata(pdev); in intel_xhci_usb_remove() local
202 pm_runtime_disable(&pdev->dev); in intel_xhci_usb_remove()
204 usb_role_switch_unregister(data->role_sw); in intel_xhci_usb_remove()
228 MODULE_DESCRIPTION("Intel XHCI USB role switch driver");