9
9
10
10
#include <linux/bitfield.h>
11
11
#include <linux/bitops.h>
12
+ #include <linux/delay.h>
12
13
#include <linux/io.h>
14
+ #include <linux/iopoll.h>
13
15
#include <linux/kernel.h>
14
16
#include <linux/module.h>
15
17
#include <linux/pci.h>
16
18
#include <linux/serial_core.h>
19
+ #include <linux/serial_reg.h>
20
+ #include <linux/serial_8250.h>
17
21
#include <linux/slab.h>
18
22
#include <linux/string.h>
19
23
#include <linux/units.h>
20
24
#include <linux/tty.h>
25
+ #include <linux/tty_flip.h>
26
+ #include <linux/8250_pci.h>
21
27
22
28
#include <asm/byteorder.h>
23
29
52
58
#define PCI_SUBDEVICE_ID_EFAR_PCI11400 PCI_DEVICE_ID_EFAR_PCI11400
53
59
#define PCI_SUBDEVICE_ID_EFAR_PCI11414 PCI_DEVICE_ID_EFAR_PCI11414
54
60
61
+ #define UART_SYSTEM_ADDR_BASE 0x1000
62
+ #define UART_DEV_REV_REG (UART_SYSTEM_ADDR_BASE + 0x00)
63
+ #define UART_DEV_REV_MASK GENMASK(7, 0)
64
+ #define UART_SYSLOCK_REG (UART_SYSTEM_ADDR_BASE + 0xA0)
65
+ #define UART_SYSLOCK BIT(2)
66
+ #define SYSLOCK_SLEEP_TIMEOUT 100
67
+ #define SYSLOCK_RETRY_CNT 1000
68
+
55
69
#define UART_ACTV_REG 0x11
56
70
#define UART_BLOCK_SET_ACTIVE BIT(0)
57
71
87
101
88
102
struct pci1xxxx_8250 {
89
103
unsigned int nr ;
104
+ u8 dev_rev ;
105
+ u8 pad [3 ];
90
106
void __iomem * membase ;
91
107
int line [] __counted_by (nr );
92
108
};
@@ -98,6 +114,27 @@ static const struct serial_rs485 pci1xxxx_rs485_supported = {
98
114
/* Delay RTS before send is not supported */
99
115
};
100
116
117
+ static int pci1xxxx_set_sys_lock (struct pci1xxxx_8250 * port )
118
+ {
119
+ writel (UART_SYSLOCK , port -> membase + UART_SYSLOCK_REG );
120
+ return readl (port -> membase + UART_SYSLOCK_REG );
121
+ }
122
+
123
+ static int pci1xxxx_acquire_sys_lock (struct pci1xxxx_8250 * port )
124
+ {
125
+ u32 regval ;
126
+
127
+ return readx_poll_timeout (pci1xxxx_set_sys_lock , port , regval ,
128
+ (regval & UART_SYSLOCK ),
129
+ SYSLOCK_SLEEP_TIMEOUT ,
130
+ SYSLOCK_RETRY_CNT * SYSLOCK_SLEEP_TIMEOUT );
131
+ }
132
+
133
+ static void pci1xxxx_release_sys_lock (struct pci1xxxx_8250 * port )
134
+ {
135
+ writel (0x0 , port -> membase + UART_SYSLOCK_REG );
136
+ }
137
+
101
138
static const int logical_to_physical_port_idx [][MAX_PORTS ] = {
102
139
{0 , 1 , 2 , 3 }, /* PCI12000, PCI11010, PCI11101, PCI11400, PCI11414 */
103
140
{0 , 1 , 2 , 3 }, /* PCI4p */
@@ -370,6 +407,27 @@ static int pci1xxxx_logical_to_physical_port_translate(int subsys_dev, int port)
370
407
return logical_to_physical_port_idx [0 ][port ];
371
408
}
372
409
410
+ static int pci1xxxx_get_device_revision (struct pci1xxxx_8250 * priv )
411
+ {
412
+ u32 regval ;
413
+ int ret ;
414
+
415
+ /*
416
+ * DEV REV is a system register, HW Syslock bit
417
+ * should be acquired before accessing the register
418
+ */
419
+ ret = pci1xxxx_acquire_sys_lock (priv );
420
+ if (ret )
421
+ return ret ;
422
+
423
+ regval = readl (priv -> membase + UART_DEV_REV_REG );
424
+ priv -> dev_rev = regval & UART_DEV_REV_MASK ;
425
+
426
+ pci1xxxx_release_sys_lock (priv );
427
+
428
+ return 0 ;
429
+ }
430
+
373
431
static int pci1xxxx_serial_probe (struct pci_dev * pdev ,
374
432
const struct pci_device_id * id )
375
433
{
@@ -381,6 +439,7 @@ static int pci1xxxx_serial_probe(struct pci_dev *pdev,
381
439
int num_vectors ;
382
440
int subsys_dev ;
383
441
int port_idx ;
442
+ int ret ;
384
443
int rc ;
385
444
386
445
rc = pcim_enable_device (pdev );
@@ -397,6 +456,10 @@ static int pci1xxxx_serial_probe(struct pci_dev *pdev,
397
456
if (!priv -> membase )
398
457
return - ENOMEM ;
399
458
459
+ ret = pci1xxxx_get_device_revision (priv );
460
+ if (ret )
461
+ return ret ;
462
+
400
463
pci_set_master (pdev );
401
464
402
465
priv -> nr = nr_ports ;
0 commit comments