1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/delay.h>
17#include <linux/gpio/consumer.h>
18#include <linux/io.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/slab.h>
22#include <linux/usb.h>
23
24#include "isp1760-core.h"
25#include "isp1760-hcd.h"
26#include "isp1760-regs.h"
27#include "isp1760-udc.h"
28
29static void isp1760_init_core(struct isp1760_device *isp)
30{
31 u32 otgctrl;
32 u32 hwmode;
33
34
35 if (isp->rst_gpio) {
36 gpiod_set_value_cansleep(isp->rst_gpio, 1);
37 mdelay(50);
38 gpiod_set_value_cansleep(isp->rst_gpio, 0);
39 }
40
41
42
43
44
45 isp1760_write32(isp->regs, HC_RESET_REG, SW_RESET_RESET_ALL);
46 msleep(100);
47
48
49 hwmode = HW_DATA_BUS_32BIT;
50
51 if (isp->devflags & ISP1760_FLAG_BUS_WIDTH_16)
52 hwmode &= ~HW_DATA_BUS_32BIT;
53 if (isp->devflags & ISP1760_FLAG_ANALOG_OC)
54 hwmode |= HW_ANA_DIGI_OC;
55 if (isp->devflags & ISP1760_FLAG_DACK_POL_HIGH)
56 hwmode |= HW_DACK_POL_HIGH;
57 if (isp->devflags & ISP1760_FLAG_DREQ_POL_HIGH)
58 hwmode |= HW_DREQ_POL_HIGH;
59 if (isp->devflags & ISP1760_FLAG_INTR_POL_HIGH)
60 hwmode |= HW_INTR_HIGH_ACT;
61 if (isp->devflags & ISP1760_FLAG_INTR_EDGE_TRIG)
62 hwmode |= HW_INTR_EDGE_TRIG;
63
64
65
66
67
68
69
70 if (isp->devflags & ISP1760_FLAG_ISP1761) {
71 isp1760_write32(isp->regs, DC_MODE, 0);
72 hwmode |= HW_COMN_IRQ;
73 }
74
75
76
77
78
79
80 isp1760_write32(isp->regs, HC_HW_MODE_CTRL, hwmode);
81 isp1760_write32(isp->regs, HC_HW_MODE_CTRL, hwmode);
82
83
84
85
86
87
88
89
90 if ((isp->devflags & ISP1760_FLAG_ISP1761) &&
91 (isp->devflags & ISP1760_FLAG_OTG_EN))
92 otgctrl = ((HW_DM_PULLDOWN | HW_DP_PULLDOWN) << 16)
93 | HW_OTG_DISABLE;
94 else
95 otgctrl = (HW_SW_SEL_HC_DC << 16)
96 | (HW_VBUS_DRV | HW_SEL_CP_EXT);
97
98 isp1760_write32(isp->regs, HC_PORT1_CTRL, otgctrl);
99
100 dev_info(isp->dev, "bus width: %u, oc: %s\n",
101 isp->devflags & ISP1760_FLAG_BUS_WIDTH_16 ? 16 : 32,
102 isp->devflags & ISP1760_FLAG_ANALOG_OC ? "analog" : "digital");
103}
104
105void isp1760_set_pullup(struct isp1760_device *isp, bool enable)
106{
107 isp1760_write32(isp->regs, HW_OTG_CTRL_SET,
108 enable ? HW_DP_PULLUP : HW_DP_PULLUP << 16);
109}
110
111int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
112 struct device *dev, unsigned int devflags)
113{
114 struct isp1760_device *isp;
115 bool udc_disabled = !(devflags & ISP1760_FLAG_ISP1761);
116 int ret;
117
118
119
120
121
122 if ((!IS_ENABLED(CONFIG_USB_ISP1760_HCD) || usb_disabled()) &&
123 (!IS_ENABLED(CONFIG_USB_ISP1761_UDC) || udc_disabled))
124 return -ENODEV;
125
126
127 dev->dma_mask = NULL;
128
129 isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL);
130 if (!isp)
131 return -ENOMEM;
132
133 isp->dev = dev;
134 isp->devflags = devflags;
135
136 isp->rst_gpio = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH);
137 if (IS_ERR(isp->rst_gpio))
138 return PTR_ERR(isp->rst_gpio);
139
140 isp->regs = devm_ioremap_resource(dev, mem);
141 if (IS_ERR(isp->regs))
142 return PTR_ERR(isp->regs);
143
144 isp1760_init_core(isp);
145
146 if (IS_ENABLED(CONFIG_USB_ISP1760_HCD) && !usb_disabled()) {
147 ret = isp1760_hcd_register(&isp->hcd, isp->regs, mem, irq,
148 irqflags | IRQF_SHARED, dev);
149 if (ret < 0)
150 return ret;
151 }
152
153 if (IS_ENABLED(CONFIG_USB_ISP1761_UDC) && !udc_disabled) {
154 ret = isp1760_udc_register(isp, irq, irqflags);
155 if (ret < 0) {
156 isp1760_hcd_unregister(&isp->hcd);
157 return ret;
158 }
159 }
160
161 dev_set_drvdata(dev, isp);
162
163 return 0;
164}
165
166void isp1760_unregister(struct device *dev)
167{
168 struct isp1760_device *isp = dev_get_drvdata(dev);
169
170 isp1760_udc_unregister(isp);
171 isp1760_hcd_unregister(&isp->hcd);
172}
173
174MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP");
175MODULE_AUTHOR("Sebastian Siewior <bigeasy@linuxtronix.de>");
176MODULE_LICENSE("GPL v2");
177