perf python: Do not force closing original perf descriptor in evlist.get_pollfd()
[linux/fpc-iii.git] / drivers / usb / chipidea / ulpi.c
blobdfec07e8ae1d268c459b495603bd5e8de154518f
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2016 Linaro Ltd.
4 */
6 #include <linux/device.h>
7 #include <linux/usb/chipidea.h>
8 #include <linux/ulpi/interface.h>
10 #include "ci.h"
12 #define ULPI_WAKEUP BIT(31)
13 #define ULPI_RUN BIT(30)
14 #define ULPI_WRITE BIT(29)
15 #define ULPI_SYNC_STATE BIT(27)
16 #define ULPI_ADDR(n) ((n) << 16)
17 #define ULPI_DATA(n) (n)
19 static int ci_ulpi_wait(struct ci_hdrc *ci, u32 mask)
21 unsigned long usec = 10000;
23 while (usec--) {
24 if (!hw_read(ci, OP_ULPI_VIEWPORT, mask))
25 return 0;
27 udelay(1);
30 return -ETIMEDOUT;
33 static int ci_ulpi_read(struct device *dev, u8 addr)
35 struct ci_hdrc *ci = dev_get_drvdata(dev);
36 int ret;
38 hw_write(ci, OP_ULPI_VIEWPORT, 0xffffffff, ULPI_WRITE | ULPI_WAKEUP);
39 ret = ci_ulpi_wait(ci, ULPI_WAKEUP);
40 if (ret)
41 return ret;
43 hw_write(ci, OP_ULPI_VIEWPORT, 0xffffffff, ULPI_RUN | ULPI_ADDR(addr));
44 ret = ci_ulpi_wait(ci, ULPI_RUN);
45 if (ret)
46 return ret;
48 return hw_read(ci, OP_ULPI_VIEWPORT, GENMASK(15, 8)) >> 8;
51 static int ci_ulpi_write(struct device *dev, u8 addr, u8 val)
53 struct ci_hdrc *ci = dev_get_drvdata(dev);
54 int ret;
56 hw_write(ci, OP_ULPI_VIEWPORT, 0xffffffff, ULPI_WRITE | ULPI_WAKEUP);
57 ret = ci_ulpi_wait(ci, ULPI_WAKEUP);
58 if (ret)
59 return ret;
61 hw_write(ci, OP_ULPI_VIEWPORT, 0xffffffff,
62 ULPI_RUN | ULPI_WRITE | ULPI_ADDR(addr) | val);
63 return ci_ulpi_wait(ci, ULPI_RUN);
66 int ci_ulpi_init(struct ci_hdrc *ci)
68 if (ci->platdata->phy_mode != USBPHY_INTERFACE_MODE_ULPI)
69 return 0;
72 * Set PORTSC correctly so we can read/write ULPI registers for
73 * identification purposes
75 hw_phymode_configure(ci);
77 ci->ulpi_ops.read = ci_ulpi_read;
78 ci->ulpi_ops.write = ci_ulpi_write;
79 ci->ulpi = ulpi_register_interface(ci->dev, &ci->ulpi_ops);
80 if (IS_ERR(ci->ulpi))
81 dev_err(ci->dev, "failed to register ULPI interface");
83 return PTR_ERR_OR_ZERO(ci->ulpi);
86 void ci_ulpi_exit(struct ci_hdrc *ci)
88 if (ci->ulpi) {
89 ulpi_unregister_interface(ci->ulpi);
90 ci->ulpi = NULL;
94 int ci_ulpi_resume(struct ci_hdrc *ci)
96 int cnt = 100000;
98 if (ci->platdata->phy_mode != USBPHY_INTERFACE_MODE_ULPI)
99 return 0;
101 while (cnt-- > 0) {
102 if (hw_read(ci, OP_ULPI_VIEWPORT, ULPI_SYNC_STATE))
103 return 0;
104 udelay(1);
107 return -ETIMEDOUT;