aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/linux/linux-kexecboot-2.6.24/tosa/0045-Update-tmio_ohci.patch
blob: 10f483b89de256459f305cd24cafe4d3c2b14ff9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
From fe3c05491370965eb821aedc95f771b86ebab3ab Mon Sep 17 00:00:00 2001
From: Dmitry Baryshkov <dbaryshkov@gmail.com>
Date: Wed, 9 Jan 2008 02:01:44 +0300
Subject: [PATCH 45/64] Update tmio_ohci:
 Ports management.
 Basic support for ohci suspend/resume.

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
---
 drivers/mfd/tc6393xb.c       |   40 ++++++++
 drivers/usb/host/ohci-tmio.c |  206 +++++++++++++++++++++++++++++++++++++++---
 2 files changed, 235 insertions(+), 11 deletions(-)

diff --git a/drivers/mfd/tc6393xb.c b/drivers/mfd/tc6393xb.c
index 9439f39..5d17687 100644
--- a/drivers/mfd/tc6393xb.c
+++ b/drivers/mfd/tc6393xb.c
@@ -224,6 +224,44 @@ static int tc6393xb_ohci_enable(struct platform_device *ohci)
 	return 0;
 }
 
+static int tc6393xb_ohci_suspend(struct platform_device *ohci)
+{
+	struct platform_device		*dev	= to_platform_device(ohci->dev.parent);
+	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
+	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
+	union tc6393xb_scr_ccr		ccr;
+	unsigned long			flags;
+
+	spin_lock_irqsave(&tc6393xb->lock, flags);
+
+	ccr.raw = ioread16(&scr->ccr);
+	ccr.bits.usbcken = 0;
+	iowrite16(ccr.raw, &scr->ccr);
+
+	spin_unlock_irqrestore(&tc6393xb->lock, flags);
+
+	return 0;
+}
+
+static int tc6393xb_ohci_resume(struct platform_device *ohci)
+{
+	struct platform_device		*dev	= to_platform_device(ohci->dev.parent);
+	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
+	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
+	union tc6393xb_scr_ccr		ccr;
+	unsigned long			flags;
+
+	spin_lock_irqsave(&tc6393xb->lock, flags);
+
+	ccr.raw = ioread16(&scr->ccr);
+	ccr.bits.usbcken = 1;
+	iowrite16(ccr.raw, &scr->ccr);
+
+	spin_unlock_irqrestore(&tc6393xb->lock, flags);
+
+	return 0;
+}
+
 static int tc6393xb_fb_disable(struct platform_device *fb)
 {
 	struct platform_device		*dev	= to_platform_device(fb->dev.parent);
@@ -423,6 +461,8 @@ static struct mfd_cell tc6393xb_cells[] = {
 		.name = "tmio-ohci",
 		.enable = tc6393xb_ohci_enable,
 		.disable = tc6393xb_ohci_disable,
+		.suspend = tc6393xb_ohci_suspend,
+		.resume = tc6393xb_ohci_resume,
 		.num_resources = ARRAY_SIZE(tc6393xb_ohci_resources),
 		.resources = tc6393xb_ohci_resources,
 	},
diff --git a/drivers/usb/host/ohci-tmio.c b/drivers/usb/host/ohci-tmio.c
index be609f3..65e3cd3 100644
--- a/drivers/usb/host/ohci-tmio.c
+++ b/drivers/usb/host/ohci-tmio.c
@@ -75,10 +75,13 @@ struct tmio_uhccr {
 	u8 x07[3];
 } __attribute__((packed));
 
+#define MAX_TMIO_OHCI_PORTS	3
+
 #define UHCCR_PM_GKEN      0x0001
 #define UHCCR_PM_CKRNEN    0x0002
 #define UHCCR_PM_USBPW1    0x0004
 #define UHCCR_PM_USBPW2    0x0008
+#define UHCCR_PM_USBPW3    0x0008
 #define UHCCR_PM_PMEE      0x0100
 #define UHCCR_PM_PMES      0x8000
 
@@ -86,44 +89,96 @@ struct tmio_uhccr {
 
 struct tmio_hcd {
 	struct tmio_uhccr __iomem *ccr;
+	spinlock_t		lock; /* protects RMW cycles and disabled_ports data */
+	bool disabled_ports[MAX_TMIO_OHCI_PORTS];
 };
 
 #define hcd_to_tmio(hcd)	((struct tmio_hcd *)(hcd_to_ohci(hcd) + 1))
 #define ohci_to_tmio(ohci)	((struct tmio_hcd *)(ohci + 1))
 
+struct indexed_device_attribute{
+	struct device_attribute dev_attr;
+	int index;
+};
+#define to_indexed_dev_attr(_dev_attr) \
+	container_of(_dev_attr, struct indexed_device_attribute, dev_attr)
+
+#define INDEXED_ATTR(_name, _mode, _show, _store, _index)		\
+	{ .dev_attr = __ATTR(_name ## _index, _mode, _show, _store),	\
+	  .index = _index }
+
+#define INDEXED_DEVICE_ATTR(_name, _mode, _show, _store, _index)	\
+struct indexed_device_attribute dev_attr_##_name ## _index	\
+	= INDEXED_ATTR(_name, _mode, _show, _store, _index)
+
+static bool disabled_tmio_ports[MAX_TMIO_OHCI_PORTS];
+module_param_array(disabled_tmio_ports, bool, NULL, 0644);
+MODULE_PARM_DESC(disabled_tmio_ports,
+		"disable specified TC6393 usb ports (default: all enabled)");
+
 /*-------------------------------------------------------------------------*/
 
+static void tmio_write_pm(struct platform_device *dev)
+{
+	struct usb_hcd			*hcd	= platform_get_drvdata(dev);
+	struct tmio_hcd			*tmio	= hcd_to_tmio(hcd);
+	struct tmio_uhccr __iomem	*ccr	= tmio->ccr;
+	u16				pm;
+	unsigned long			flags;
+
+	spin_lock_irqsave(&tmio->lock, flags);
+
+	pm = UHCCR_PM_GKEN | UHCCR_PM_CKRNEN |
+	     UHCCR_PM_PMEE | UHCCR_PM_PMES;
+
+	if (tmio->disabled_ports[0])
+		pm |= UHCCR_PM_USBPW1;
+	if (tmio->disabled_ports[1])
+		pm |= UHCCR_PM_USBPW2;
+	if (tmio->disabled_ports[2])
+		pm |= UHCCR_PM_USBPW3;
+
+	iowrite16(pm,		&ccr->pm);
+	spin_unlock_irqrestore(&tmio->lock, flags);
+}
+
 static void tmio_stop_hc(struct platform_device *dev)
 {
 	struct mfd_cell			*cell	= mfd_get_cell(dev);
 	struct usb_hcd			*hcd	= platform_get_drvdata(dev);
+	struct ohci_hcd			*ohci	= hcd_to_ohci(hcd);
 	struct tmio_hcd			*tmio	= hcd_to_tmio(hcd);
 	struct tmio_uhccr __iomem	*ccr	= tmio->ccr;
 	u16				pm;
 
-	pm = UHCCR_PM_GKEN | UHCCR_PM_CKRNEN | UHCCR_PM_USBPW1 | UHCCR_PM_USBPW2;
+	pm = UHCCR_PM_GKEN | UHCCR_PM_CKRNEN;
+	switch (ohci->num_ports) {
+		default:
+			dev_err(&dev->dev, "Unsupported amount of ports: %d\n", ohci->num_ports);
+		case 3:
+			pm |= UHCCR_PM_USBPW3;
+		case 2:
+			pm |= UHCCR_PM_USBPW2;
+		case 1:
+			pm |= UHCCR_PM_USBPW1;
+	}
 	iowrite8(0,		&ccr->intc);
 	iowrite8(0,		&ccr->ilme);
 	iowrite16(0,		&ccr->basel);
 	iowrite16(0,		&ccr->baseh);
-	iowrite16(pm,	&ccr->pm);
+	iowrite16(pm,		&ccr->pm);
 
 	cell->disable(dev);
 }
 
 static void tmio_start_hc(struct platform_device *dev)
 {
-	struct mfd_cell			*cell	= mfd_get_cell(dev);
 	struct usb_hcd			*hcd	= platform_get_drvdata(dev);
 	struct tmio_hcd			*tmio	= hcd_to_tmio(hcd);
 	struct tmio_uhccr __iomem	*ccr	= tmio->ccr;
-	u16				pm;
 	unsigned long			base	= hcd->rsrc_start;
 
-	pm = UHCCR_PM_CKRNEN | UHCCR_PM_GKEN | UHCCR_PM_PMEE | UHCCR_PM_PMES;
-	cell->enable(dev);
-
-	iowrite16(pm,	&ccr->pm);
+	tmio_write_pm(dev);
 	iowrite16(base,		&ccr->basel);
 	iowrite16(base >> 16,	&ccr->baseh);
 	iowrite8(1,		&ccr->ilme);
@@ -133,9 +188,56 @@ static void tmio_start_hc(struct platform_device *dev)
 			ioread8(&ccr->revid), hcd->rsrc_start, hcd->irq);
 }
 
+static ssize_t tmio_disabled_port_show(struct device *dev,
+		struct device_attribute *attr,
+		char *buf)
+{
+	struct usb_hcd		*hcd	= dev_get_drvdata(dev);
+	struct tmio_hcd		*tmio	= hcd_to_tmio(hcd);
+	int			index	= to_indexed_dev_attr(attr)->index;
+	return snprintf(buf, PAGE_SIZE, "%c",
+			tmio->disabled_ports[index-1]? 'Y': 'N');
+}
+
+static ssize_t tmio_disabled_port_store(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t count)
+{
+	struct usb_hcd		*hcd	= dev_get_drvdata(dev);
+	struct tmio_hcd		*tmio	= hcd_to_tmio(hcd);
+	int			index	= to_indexed_dev_attr(attr)->index;
+
+	if (!count)
+		return -EINVAL;
+
+	switch (buf[0]) {
+	case 'y': case 'Y': case '1':
+		tmio->disabled_ports[index-1] = true;
+		break;
+	case 'n': case 'N': case '0':
+		tmio->disabled_ports[index-1] = false;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	tmio_write_pm(to_platform_device(dev));
+
+	return 1;
+}
+
+
+static INDEXED_DEVICE_ATTR(disabled_usb_port, S_IRUGO | S_IWUSR,
+		tmio_disabled_port_show, tmio_disabled_port_store, 1);
+static INDEXED_DEVICE_ATTR(disabled_usb_port, S_IRUGO | S_IWUSR,
+		tmio_disabled_port_show, tmio_disabled_port_store, 2);
+static INDEXED_DEVICE_ATTR(disabled_usb_port, S_IRUGO | S_IWUSR,
+		tmio_disabled_port_show, tmio_disabled_port_store, 3);
+
 static int usb_hcd_tmio_probe(const struct hc_driver *driver,
 		struct platform_device *dev)
 {
+	struct mfd_cell		*cell	= mfd_get_cell(dev);
 	struct resource		*config	= platform_get_resource_byname(dev, IORESOURCE_MEM, TMIO_OHCI_CONFIG);
 	struct resource		*regs	= platform_get_resource_byname(dev, IORESOURCE_MEM, TMIO_OHCI_CONTROL);
 	struct resource		*sram	= platform_get_resource_byname(dev, IORESOURCE_MEM, TMIO_OHCI_SRAM);
@@ -159,6 +261,12 @@ static int usb_hcd_tmio_probe(const struct hc_driver *driver,
 
 	tmio		= hcd_to_tmio(hcd);
 
+	spin_lock_init(&tmio->lock);
+
+	memcpy(tmio->disabled_ports,
+			disabled_tmio_ports,
+			sizeof(disabled_tmio_ports));
+
 	tmio->ccr = ioremap(config->start, config->end - config->start + 1);
 	if (!tmio->ccr) {
 		retval = -ENOMEM;
@@ -183,17 +291,46 @@ static int usb_hcd_tmio_probe(const struct hc_driver *driver,
 	if (retval)
 		goto err_dmabounce_register_dev;
 
+	retval = cell->enable(dev);
+	if (retval)
+		goto err_enable;
+
 	tmio_start_hc(dev);
 	ohci = hcd_to_ohci(hcd);
 	ohci_hcd_init(ohci);
 
 	retval = usb_add_hcd(hcd, irq, IRQF_DISABLED);
+	if (retval)
+		goto err_add_hcd;
+
+	switch (ohci->num_ports) {
+		default:
+			dev_err(&dev->dev, "Unsupported amount of ports: %d\n",
+					ohci->num_ports);
+		case 3:
+			retval |= device_create_file(&dev->dev,
+					&dev_attr_disabled_usb_port3.dev_attr);
+		case 2:
+			retval |= device_create_file(&dev->dev,
+					&dev_attr_disabled_usb_port2.dev_attr);
+		case 1:
+			retval |= device_create_file(&dev->dev,
+					&dev_attr_disabled_usb_port1.dev_attr);
+	}
 
 	if (retval == 0)
 		return retval;
 
-	tmio_stop_hc(dev);
+	device_remove_file(&dev->dev, &dev_attr_disabled_usb_port3.dev_attr);
+	device_remove_file(&dev->dev, &dev_attr_disabled_usb_port2.dev_attr);
+	device_remove_file(&dev->dev, &dev_attr_disabled_usb_port1.dev_attr);
+
+	usb_remove_hcd(hcd);
 
+err_add_hcd:
+	tmio_stop_hc(dev);
+	cell->disable(dev);
+err_enable:
 	dmabounce_unregister_dev(&dev->dev);
 err_dmabounce_register_dev:
 	dma_release_declared_memory(&dev->dev);
@@ -212,6 +349,9 @@ static void usb_hcd_tmio_remove(struct usb_hcd *hcd, struct platform_device *dev
 {
 	struct tmio_hcd		*tmio	= hcd_to_tmio(hcd);
 
+	device_remove_file(&dev->dev, &dev_attr_disabled_usb_port3.dev_attr);
+	device_remove_file(&dev->dev, &dev_attr_disabled_usb_port2.dev_attr);
+	device_remove_file(&dev->dev, &dev_attr_disabled_usb_port1.dev_attr);
 	usb_remove_hcd(hcd);
 	tmio_stop_hc(dev);
 	dmabounce_unregister_dev(&dev->dev);
@@ -297,13 +437,22 @@ static u64 dma_mask = DMA_32BIT_MASK;
 static int ohci_hcd_tmio_drv_probe(struct platform_device *dev)
 {
 	struct resource		*sram	= platform_get_resource_byname(dev, IORESOURCE_MEM, TMIO_OHCI_SRAM);
+	int retval;
 
 	dev->dev.dma_mask = &dma_mask;
 	dev->dev.coherent_dma_mask = DMA_32BIT_MASK;
 
+	/* FIXME: move dmabounce checkers to tc6393xb core? */
 	dmabounce_register_checker(tmio_dmabounce_check, sram);
 
-	return usb_hcd_tmio_probe(&ohci_tmio_hc_driver, dev);
+	retval = usb_hcd_tmio_probe(&ohci_tmio_hc_driver, dev);
+
+	if (retval == 0)
+		return retval;
+
+	dmabounce_remove_checker(tmio_dmabounce_check, sram);
+
+	return retval;
 }
 
 static int ohci_hcd_tmio_drv_remove(struct platform_device *dev)
@@ -323,14 +472,31 @@ static int ohci_hcd_tmio_drv_remove(struct platform_device *dev)
 #ifdef	CONFIG_PM
 static int ohci_hcd_tmio_drv_suspend(struct platform_device *dev, pm_message_t state)
 {
+	struct mfd_cell		*cell	= mfd_get_cell(dev);
 	struct usb_hcd		*hcd	= platform_get_drvdata(dev);
 	struct ohci_hcd		*ohci	= hcd_to_ohci(hcd);
+	struct tmio_hcd		*tmio	= hcd_to_tmio(hcd);
+	struct tmio_uhccr __iomem *ccr	= tmio->ccr;
+	unsigned long		flags;
+	u8			misc;
+	int			ret;
 
 	if (time_before(jiffies, ohci->next_statechange))
 		msleep(5);
 	ohci->next_statechange = jiffies;
 
-	tmio_stop_hc(dev);
+	spin_lock_irqsave(&tmio->lock, flags);
+
+	misc = ioread8(&ccr->misc);
+	misc |= 1 << 3; /* USSUSP */
+	iowrite8(misc, &ccr->misc);
+
+	spin_unlock_irqrestore(&tmio->lock, flags);
+
+	ret = cell->suspend(dev);
+	if (ret)
+		return ret;
+
 	hcd->state = HC_STATE_SUSPENDED;
 	dev->dev.power.power_state = PMSG_SUSPEND;
 
@@ -339,15 +505,33 @@ static int ohci_hcd_tmio_drv_suspend(struct platform_device *dev, pm_message_t s
 
 static int ohci_hcd_tmio_drv_resume(struct platform_device *dev)
 {
+	struct mfd_cell		*cell	= mfd_get_cell(dev);
 	struct usb_hcd		*hcd	= platform_get_drvdata(dev);
 	struct ohci_hcd		*ohci	= hcd_to_ohci(hcd);
+	struct tmio_hcd		*tmio	= hcd_to_tmio(hcd);
+	struct tmio_uhccr __iomem *ccr	= tmio->ccr;
+	unsigned long		flags;
+	u8			misc;
+	int			ret;
 
 	if (time_before(jiffies, ohci->next_statechange))
 		msleep(5);
 	ohci->next_statechange = jiffies;
 
+	ret = cell->resume(dev);
+	if (ret)
+		return ret;
+
 	tmio_start_hc(dev);
 
+	spin_lock_irqsave(&tmio->lock, flags);
+
+	misc = ioread8(&ccr->misc);
+	misc &= ~(1 << 3); /* USSUSP */
+	iowrite8(misc, &ccr->misc);
+
+	spin_unlock_irqrestore(&tmio->lock, flags);
+
 	dev->dev.power.power_state = PMSG_ON;
 	usb_hcd_resume_root_hub(hcd);
 
-- 
1.5.3.8