Lines Matching +full:usb +full:- +full:attach

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
17 #include <linux/usb/role.h>
46 writel(EUD_ENABLE, priv->base + EUD_REG_CSR_EUD_EN); in enable_eud()
48 priv->base + EUD_REG_INT1_EN_MASK); in enable_eud()
49 writel(1, priv->mode_mgr + EUD_REG_EUD_EN2); in enable_eud()
51 return usb_role_switch_set_role(priv->role_sw, USB_ROLE_DEVICE); in enable_eud()
56 writel(0, priv->base + EUD_REG_CSR_EUD_EN); in disable_eud()
57 writel(0, priv->mode_mgr + EUD_REG_EUD_EN2); in disable_eud()
65 return sysfs_emit(buf, "%d\n", chip->enabled); in enable_show()
77 return -EINVAL; in enable_store()
82 chip->enabled = enable; in enable_store()
104 /* read ctl_out_1[4] to find USB attach or detach event */ in usb_attach_detach()
105 reg = readl(chip->base + EUD_REG_CTL_OUT_1); in usb_attach_detach()
106 chip->usb_attached = reg & EUD_INT_SAFE_MODE; in usb_attach_detach()
118 reg = readl(chip->base + EUD_REG_SW_ATTACH_DET); in pet_eud()
120 /* Detach & Attach pet for EUD */ in pet_eud()
121 writel(0, chip->base + EUD_REG_SW_ATTACH_DET); in pet_eud()
122 /* Delay to make sure detach pet is done before attach pet */ in pet_eud()
123 ret = readl_poll_timeout(chip->base + EUD_REG_SW_ATTACH_DET, in pet_eud()
126 dev_err(chip->dev, "Detach pet failed\n"); in pet_eud()
130 /* Attach pet for EUD */ in pet_eud()
131 writel(EUD_INT_PET_EUD, chip->base + EUD_REG_SW_ATTACH_DET); in pet_eud()
139 reg = readl(chip->base + EUD_REG_INT_STATUS_1); in handle_eud_irq()
157 if (chip->usb_attached) in handle_eud_irq_thread()
158 ret = usb_role_switch_set_role(chip->role_sw, USB_ROLE_DEVICE); in handle_eud_irq_thread()
160 ret = usb_role_switch_set_role(chip->role_sw, USB_ROLE_HOST); in handle_eud_irq_thread()
162 dev_err(chip->dev, "failed to set role switch\n"); in handle_eud_irq_thread()
165 writel(BIT(0), chip->base + EUD_REG_VBUS_INT_CLR); in handle_eud_irq_thread()
166 writel(0, chip->base + EUD_REG_VBUS_INT_CLR); in handle_eud_irq_thread()
175 usb_role_switch_put(chip->role_sw); in eud_role_switch_release()
183 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); in eud_probe()
185 return -ENOMEM; in eud_probe()
187 chip->dev = &pdev->dev; in eud_probe()
189 chip->role_sw = usb_role_switch_get(&pdev->dev); in eud_probe()
190 if (IS_ERR(chip->role_sw)) in eud_probe()
191 return dev_err_probe(chip->dev, PTR_ERR(chip->role_sw), in eud_probe()
194 ret = devm_add_action_or_reset(chip->dev, eud_role_switch_release, chip); in eud_probe()
196 return dev_err_probe(chip->dev, ret, in eud_probe()
199 chip->base = devm_platform_ioremap_resource(pdev, 0); in eud_probe()
200 if (IS_ERR(chip->base)) in eud_probe()
201 return PTR_ERR(chip->base); in eud_probe()
203 chip->mode_mgr = devm_platform_ioremap_resource(pdev, 1); in eud_probe()
204 if (IS_ERR(chip->mode_mgr)) in eud_probe()
205 return PTR_ERR(chip->mode_mgr); in eud_probe()
207 chip->irq = platform_get_irq(pdev, 0); in eud_probe()
208 if (chip->irq < 0) in eud_probe()
209 return chip->irq; in eud_probe()
211 ret = devm_request_threaded_irq(&pdev->dev, chip->irq, handle_eud_irq, in eud_probe()
214 return dev_err_probe(chip->dev, ret, "failed to allocate irq\n"); in eud_probe()
216 enable_irq_wake(chip->irq); in eud_probe()
227 if (chip->enabled) in eud_remove()
230 device_init_wakeup(&pdev->dev, false); in eud_remove()
231 disable_irq_wake(chip->irq); in eud_remove()