summaryrefslogtreecommitdiff
path: root/packages/linux/linux-2.6.24/ts72xx/ts72xx-rs485.patch
blob: 17ee397f459b80739e728ff245b6b2829968355e (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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
RS485 auto mode support ported from 2.4 (diff against 2.6.19-rc6-git10)

Signed-off-by: Petr Stetiar <ynezz@true.cz>

diff --git a/drivers/serial/amba-pl010.c b/drivers/serial/amba-pl010.c
index 4213fab..5b3c5ff 100644
--- a/drivers/serial/amba-pl010.c
+++ b/drivers/serial/amba-pl010.c
@@ -50,6 +50,7 @@
 #include <linux/amba/serial.h>
 
 #include <asm/io.h>
+#include <asm/hardware.h>
 
 #define UART_NR		8
 
@@ -65,6 +66,11 @@
 #define UART_DUMMY_RSR_RX	256
 #define UART_PORT_SIZE		64
 
+#ifdef CONFIG_MACH_TS72XX
+static void __iomem *ts_rs485_data9_register;
+static void __iomem *ts_rs485_control_register;
+#endif
+
 /*
  * We wrap our port structure around the generic uart_port.
  */
@@ -487,6 +493,107 @@ static int pl010_verify_port(struct uart
 	return ret;
 }
 
+#ifdef CONFIG_MACH_TS72XX
+static int ts72xx_rs485_init(void)
+{
+	ts_rs485_data9_register = ioremap(TS72XX_RS485_DATA9_PHYS_BASE, 4096);
+	if (ts_rs485_data9_register == NULL) {
+		return -1;
+	}
+
+	ts_rs485_control_register = ioremap(TS72XX_RS485_CONTROL_PHYS_BASE, 4096);
+	if (ts_rs485_control_register == NULL) {
+		iounmap(ts_rs485_data9_register);
+		return -1;
+	}
+
+	return 0;
+}
+
+static int ts72xx_auto485(struct uart_port *port, unsigned int cmd, unsigned long *arg)
+{
+	int baud, cflag, mode;
+	int datalength;
+
+	mode = (int)*arg;
+	if (!is_rs485_installed()) {
+		printk("amba-pl010.c: this board does not support RS485 auto mode\n");
+		return -EINVAL;
+	}
+
+	if (port->line != 1) {
+		printk("amba-pl010.c: auto RS485 mode is only supported on second port (/dev/ttyAM1)\n");
+		return -EINVAL;
+	}
+
+	datalength = 8;
+	cflag = port->info->tty->termios->c_cflag ;
+	if (cflag & PARENB)
+		datalength++;
+
+	if (cflag & CSTOPB)
+		datalength++;
+
+	baud = tty_get_baud_rate(port->info->tty);
+
+	switch (cmd) {
+		case TIOC_SBCC485:
+			if ((mode & TS72XX_RS485_AUTO485FD) || (mode & TS72XX_RS485_AUTO485HD)) {
+				printk("amba-pl010.c: unsetting auto RS485 mode\n");
+				__raw_writew(TS72XX_RS485_MODE_RS232, ts_rs485_control_register);
+				__raw_writew(TS72XX_RS485_MODE_RS232, ts_rs485_data9_register);
+			}
+			break;
+		case TIOC_SBCS485:
+			if (mode & TS72XX_RS485_AUTO485FD) {
+				printk ("amba-pl010.c: setting FULL duplex auto RS485 mode\n");
+				__raw_writew(TS72XX_RS485_MODE_FD, ts_rs485_control_register);
+				if (datalength > 8)
+					__raw_writew(TS72XX_RS485_MODE_FD, ts_rs485_data9_register);
+			} else if (mode & TS72XX_RS485_AUTO485HD) {
+				printk("amba-pl010.c: setting HALF DUPLEX auto RS485 mode\n");
+				switch (baud) {
+					case 9600:
+						__raw_writew(TS72XX_RS485_MODE_9600_HD, ts_rs485_control_register);
+						break;
+					case 19200:
+						__raw_writew(TS72XX_RS485_MODE_19200_HD, ts_rs485_control_register);
+						break;
+					case 57600:
+						__raw_writew(TS72XX_RS485_MODE_57600_HD, ts_rs485_control_register);
+						break;
+					case 115200:
+						__raw_writew(TS72XX_RS485_MODE_115200_HD, ts_rs485_control_register);
+						break;
+					default:
+					printk("amba-pl010.c: %d baud rate is not supported for auto RS485 mode\n", baud);
+					return -1;
+				}
+				if (datalength > 8)
+					__raw_writew(TS72XX_RS485_MODE_FD, ts_rs485_data9_register);
+			}
+			break;
+	}
+
+	return 0;
+}
+#endif
+
+int pl010_ioctl(struct uart_port *port, unsigned int cmd, unsigned long arg)
+{
+#ifdef CONFIG_MACH_TS72XX
+	switch (cmd) {
+		case TIOC_SBCC485:
+		case TIOC_SBCS485:
+			return ts72xx_auto485(port, cmd, (unsigned long *)arg);
+			break;
+		default:
+			return -ENOIOCTLCMD;
+	}
+#endif
+	return -ENOIOCTLCMD;
+}
+
 static struct uart_ops amba_pl010_pops = {
 	.tx_empty	= pl010_tx_empty,
 	.set_mctrl	= pl010_set_mctrl,
@@ -504,6 +611,7 @@ static struct uart_ops amba_pl010_pops =
 	.request_port	= pl010_request_port,
 	.config_port	= pl010_config_port,
 	.verify_port	= pl010_verify_port,
+	.ioctl		= pl010_ioctl,
 };
 
 static struct uart_amba_port *amba_ports[UART_NR];
@@ -746,6 +854,15 @@ static int __init pl010_init(void)
 	ret = uart_register_driver(&amba_reg);
 	if (ret == 0) {
 		ret = amba_driver_register(&pl010_driver);
+#ifdef CONFIG_MACH_TS72XX
+		if (!ret && is_rs485_installed()) {
+			ret = ts72xx_rs485_init();
+			if (ret)
+				printk("amba-pl010.c: ts72xx_rs485_init() failed\n");
+			else
+				printk("amba-pl010.c: auto RS485 mode initialized\n");
+		}
+#endif
 		if (ret)
 			uart_unregister_driver(&amba_reg);
 	}
@@ -756,6 +873,10 @@ static void __exit pl010_exit(void)
 {
 	amba_driver_unregister(&pl010_driver);
 	uart_unregister_driver(&amba_reg);
+#ifdef CONFIG_MACH_TS72XX
+	iounmap(ts_rs485_data9_register);
+	iounmap(ts_rs485_control_register);
+#endif
 }
 
 module_init(pl010_init);
diff --git a/include/asm-arm/arch-ep93xx/ts72xx.h b/include/asm-arm/arch-ep93xx/ts72xx.h
index a94f63f..4c9396b 100644
--- a/include/asm-arm/arch-ep93xx/ts72xx.h
+++ b/include/asm-arm/arch-ep93xx/ts72xx.h
@@ -68,6 +68,16 @@
 #define TS72XX_RTC_DATA_PHYS_BASE	0x11700000
 #define TS72XX_RTC_DATA_SIZE		0x00001000
 
+#define TS72XX_RS485_CONTROL_PHYS_BASE	0x22C00000
+#define TS72XX_RS485_DATA9_PHYS_BASE	0x23000000
+#define TS72XX_RS485_AUTO485FD		1
+#define TS72XX_RS485_AUTO485HD		2
+#define TS72XX_RS485_MODE_RS232	0x00
+#define TS72XX_RS485_MODE_FD		0x01
+#define TS72XX_RS485_MODE_9600_HD	0x04
+#define TS72XX_RS485_MODE_19200_HD	0x05
+#define TS72XX_RS485_MODE_57600_HD	0x06
+#define TS72XX_RS485_MODE_115200_HD	0x07
 
 #ifndef __ASSEMBLY__
 #include <asm/io.h>
@@ -87,6 +100,12 @@ static inline int board_is_ts7260(void)
 	return __raw_readb(TS72XX_MODEL_VIRT_BASE) == TS72XX_MODEL_TS7260;
 }
 
+static inline int is_rs485_installed(void)
+{
+	return !!(__raw_readb(TS72XX_OPTIONS_VIRT_BASE) &
+					TS72XX_OPTIONS_COM2_RS485);
+}
+
 static inline int is_max197_installed(void)
 {
 	return !!(__raw_readb(TS72XX_OPTIONS_VIRT_BASE) &
diff --git a/include/asm-arm/ioctls.h b/include/asm-arm/ioctls.h
index bb9a7aa..4d7dad1 100644
--- a/include/asm-arm/ioctls.h
+++ b/include/asm-arm/ioctls.h
@@ -66,6 +66,9 @@
 #define TIOCGICOUNT	0x545D	/* read serial port inline interrupt counts */
 #define FIOQSIZE	0x545E
 
+#define TIOC_SBCC485	0x545F /* TS72xx RTS/485 mode clear */
+#define TIOC_SBCS485	0x5460 /* TS72xx RTS/485 mode set */
+
 /* Used for packet mode */
 #define TIOCPKT_DATA		 0
 #define TIOCPKT_FLUSHREAD	 1
RS485 auto mode support ported from 2.4 (diff against 2.6.19-rc6-git10)

Signed-off-by: Petr Stetiar <ynezz@true.cz>

diff --git a/drivers/serial/amba-pl010.c b/drivers/serial/amba-pl010.c
index 4213fab..5b3c5ff 100644
--- a/drivers/serial/amba-pl010.c
+++ b/drivers/serial/amba-pl010.c
@@ -50,6 +50,7 @@
 #include <linux/amba/serial.h>
 
 #include <asm/io.h>
+#include <asm/hardware.h>
 
 #define UART_NR		8
 
@@ -65,6 +66,11 @@
 #define UART_DUMMY_RSR_RX	256
 #define UART_PORT_SIZE		64
 
+#ifdef CONFIG_MACH_TS72XX
+static void __iomem *ts_rs485_data9_register;
+static void __iomem *ts_rs485_control_register;
+#endif
+
 /*
  * We wrap our port structure around the generic uart_port.
  */
@@ -487,6 +493,107 @@ static int pl010_verify_port(struct uart
 	return ret;
 }
 
+#ifdef CONFIG_MACH_TS72XX
+static int ts72xx_rs485_init(void)
+{
+	ts_rs485_data9_register = ioremap(TS72XX_RS485_DATA9_PHYS_BASE, 4096);
+	if (ts_rs485_data9_register == NULL) {
+		return -1;
+	}
+
+	ts_rs485_control_register = ioremap(TS72XX_RS485_CONTROL_PHYS_BASE, 4096);
+	if (ts_rs485_control_register == NULL) {
+		iounmap(ts_rs485_data9_register);
+		return -1;
+	}
+
+	return 0;
+}
+
+static int ts72xx_auto485(struct uart_port *port, unsigned int cmd, unsigned long *arg)
+{
+	int baud, cflag, mode;
+	int datalength;
+
+	mode = (int)*arg;
+	if (!is_rs485_installed()) {
+		printk("amba-pl010.c: this board does not support RS485 auto mode\n");
+		return -EINVAL;
+	}
+
+	if (port->line != 1) {
+		printk("amba-pl010.c: auto RS485 mode is only supported on second port (/dev/ttyAM1)\n");
+		return -EINVAL;
+	}
+
+	datalength = 8;
+	cflag = port->info->tty->termios->c_cflag ;
+	if (cflag & PARENB)
+		datalength++;
+
+	if (cflag & CSTOPB)
+		datalength++;
+
+	baud = tty_get_baud_rate(port->info->tty);
+
+	switch (cmd) {
+		case TIOC_SBCC485:
+			if ((mode & TS72XX_RS485_AUTO485FD) || (mode & TS72XX_RS485_AUTO485HD)) {
+				printk("amba-pl010.c: unsetting auto RS485 mode\n");
+				__raw_writew(TS72XX_RS485_MODE_RS232, ts_rs485_control_register);
+				__raw_writew(TS72XX_RS485_MODE_RS232, ts_rs485_data9_register);
+			}
+			break;
+		case TIOC_SBCS485:
+			if (mode & TS72XX_RS485_AUTO485FD) {
+				printk ("amba-pl010.c: setting FULL duplex auto RS485 mode\n");
+				__raw_writew(TS72XX_RS485_MODE_FD, ts_rs485_control_register);
+				if (datalength > 8)
+					__raw_writew(TS72XX_RS485_MODE_FD, ts_rs485_data9_register);
+			} else if (mode & TS72XX_RS485_AUTO485HD) {
+				printk("amba-pl010.c: setting HALF DUPLEX auto RS485 mode\n");
+				switch (baud) {
+					case 9600:
+						__raw_writew(TS72XX_RS485_MODE_9600_HD, ts_rs485_control_register);
+						break;
+					case 19200:
+						__raw_writew(TS72XX_RS485_MODE_19200_HD, ts_rs485_control_register);
+						break;
+					case 57600:
+						__raw_writew(TS72XX_RS485_MODE_57600_HD, ts_rs485_control_register);
+						break;
+					case 115200:
+						__raw_writew(TS72XX_RS485_MODE_115200_HD, ts_rs485_control_register);
+						break;
+					default:
+					printk("amba-pl010.c: %d baud rate is not supported for auto RS485 mode\n", baud);
+					return -1;
+				}
+				if (datalength > 8)
+					__raw_writew(TS72XX_RS485_MODE_FD, ts_rs485_data9_register);
+			}
+			break;
+	}
+
+	return 0;
+}
+#endif
+
+int pl010_ioctl(struct uart_port *port, unsigned int cmd, unsigned long arg)
+{
+#ifdef CONFIG_MACH_TS72XX
+	switch (cmd) {
+		case TIOC_SBCC485:
+		case TIOC_SBCS485:
+			return ts72xx_auto485(port, cmd, (unsigned long *)arg);
+			break;
+		default:
+			return -ENOIOCTLCMD;
+	}
+#endif
+	return -ENOIOCTLCMD;
+}
+
 static struct uart_ops amba_pl010_pops = {
 	.tx_empty	= pl010_tx_empty,
 	.set_mctrl	= pl010_set_mctrl,
@@ -504,6 +611,7 @@ static struct uart_ops amba_pl010_pops =
 	.request_port	= pl010_request_port,
 	.config_port	= pl010_config_port,
 	.verify_port	= pl010_verify_port,
+	.ioctl		= pl010_ioctl,
 };
 
 static struct uart_amba_port *amba_ports[UART_NR];
@@ -746,6 +854,15 @@ static int __init pl010_init(void)
 	ret = uart_register_driver(&amba_reg);
 	if (ret == 0) {
 		ret = amba_driver_register(&pl010_driver);
+#ifdef CONFIG_MACH_TS72XX
+		if (!ret && is_rs485_installed()) {
+			ret = ts72xx_rs485_init();
+			if (ret)
+				printk("amba-pl010.c: ts72xx_rs485_init() failed\n");
+			else
+				printk("amba-pl010.c: auto RS485 mode initialized\n");
+		}
+#endif
 		if (ret)
 			uart_unregister_driver(&amba_reg);
 	}
@@ -756,6 +873,10 @@ static void __exit pl010_exit(void)
 {
 	amba_driver_unregister(&pl010_driver);
 	uart_unregister_driver(&amba_reg);
+#ifdef CONFIG_MACH_TS72XX
+	iounmap(ts_rs485_data9_register);
+	iounmap(ts_rs485_control_register);
+#endif
 }
 
 module_init(pl010_init);
diff --git a/include/asm-arm/arch-ep93xx/ts72xx.h b/include/asm-arm/arch-ep93xx/ts72xx.h
index a94f63f..4c9396b 100644
--- a/include/asm-arm/arch-ep93xx/ts72xx.h
+++ b/include/asm-arm/arch-ep93xx/ts72xx.h
@@ -68,6 +68,16 @@
 #define TS72XX_RTC_DATA_PHYS_BASE	0x11700000
 #define TS72XX_RTC_DATA_SIZE		0x00001000
 
+#define TS72XX_RS485_CONTROL_PHYS_BASE	0x22C00000
+#define TS72XX_RS485_DATA9_PHYS_BASE	0x23000000
+#define TS72XX_RS485_AUTO485FD		1
+#define TS72XX_RS485_AUTO485HD		2
+#define TS72XX_RS485_MODE_RS232	0x00
+#define TS72XX_RS485_MODE_FD		0x01
+#define TS72XX_RS485_MODE_9600_HD	0x04
+#define TS72XX_RS485_MODE_19200_HD	0x05
+#define TS72XX_RS485_MODE_57600_HD	0x06
+#define TS72XX_RS485_MODE_115200_HD	0x07
 
 #ifndef __ASSEMBLY__
 #include <asm/io.h>
@@ -87,6 +100,12 @@ static inline int board_is_ts7260(void)
 	return __raw_readb(TS72XX_MODEL_VIRT_BASE) == TS72XX_MODEL_TS7260;
 }
 
+static inline int is_rs485_installed(void)
+{
+	return !!(__raw_readb(TS72XX_OPTIONS_VIRT_BASE) &
+					TS72XX_OPTIONS_COM2_RS485);
+}
+
 static inline int is_max197_installed(void)
 {
 	return !!(__raw_readb(TS72XX_OPTIONS_VIRT_BASE) &
diff --git a/include/asm-arm/ioctls.h b/include/asm-arm/ioctls.h
index bb9a7aa..4d7dad1 100644
--- a/include/asm-arm/ioctls.h
+++ b/include/asm-arm/ioctls.h
@@ -66,6 +66,9 @@
 #define TIOCGICOUNT	0x545D	/* read serial port inline interrupt counts */
 #define FIOQSIZE	0x545E
 
+#define TIOC_SBCC485	0x545F /* TS72xx RTS/485 mode clear */
+#define TIOC_SBCS485	0x5460 /* TS72xx RTS/485 mode set */
+
 /* Used for packet mode */
 #define TIOCPKT_DATA		 0
 #define TIOCPKT_FLUSHREAD	 1