mirror of https://gitee.com/openkylin/linux.git
serial/8250_fintek: Support for any io address.
Fintek chip can be configured for io addresses different than the standard. Query the chip for the configured addresses and try to match it with the pnp address. Reported-by: Peter Hong <peter_hong@fintek.com.tw> Reviewed-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
ce8c267e2e
commit
29d58642f1
|
@ -28,6 +28,8 @@
|
||||||
#define VENDOR_ID1_VAL 0x19
|
#define VENDOR_ID1_VAL 0x19
|
||||||
#define VENDOR_ID2 0x24
|
#define VENDOR_ID2 0x24
|
||||||
#define VENDOR_ID2_VAL 0x34
|
#define VENDOR_ID2_VAL 0x34
|
||||||
|
#define IO_ADDR1 0x61
|
||||||
|
#define IO_ADDR2 0x60
|
||||||
#define LDN 0x7
|
#define LDN 0x7
|
||||||
|
|
||||||
#define RS485 0xF0
|
#define RS485 0xF0
|
||||||
|
@ -63,18 +65,6 @@ static void fintek_8250_exit_key(u16 base_port)
|
||||||
release_region(base_port + ADDR_PORT, 2);
|
release_region(base_port + ADDR_PORT, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fintek_8250_get_index(resource_size_t base_addr)
|
|
||||||
{
|
|
||||||
resource_size_t base[] = {0x3f8, 0x2f8, 0x3e8, 0x2e8};
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(base); i++)
|
|
||||||
if (base_addr == base[i])
|
|
||||||
return i;
|
|
||||||
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int fintek_8250_check_id(u16 base_port)
|
static int fintek_8250_check_id(u16 base_port)
|
||||||
{
|
{
|
||||||
u16 chip;
|
u16 chip;
|
||||||
|
@ -148,24 +138,41 @@ static int fintek_8250_rs485_config(struct uart_port *port,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fintek_8250_base_port(u8 *key)
|
static int fintek_8250_base_port(u16 io_address, u8 *key, u8 *index)
|
||||||
{
|
{
|
||||||
static const u16 addr[] = {0x4e, 0x2e};
|
static const u16 addr[] = {0x4e, 0x2e};
|
||||||
static const u8 keys[] = {0x77, 0xa0, 0x87, 0x67};
|
static const u8 keys[] = {0x77, 0xa0, 0x87, 0x67};
|
||||||
int i, j;
|
int i, j, k;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(addr); i++) {
|
for (i = 0; i < ARRAY_SIZE(addr); i++) {
|
||||||
for (j = 0; j < ARRAY_SIZE(keys); j++) {
|
for (j = 0; j < ARRAY_SIZE(keys); j++) {
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (fintek_8250_enter_key(addr[i], keys[j]))
|
if (fintek_8250_enter_key(addr[i], keys[j]))
|
||||||
continue;
|
continue;
|
||||||
ret = fintek_8250_check_id(addr[i]);
|
if (fintek_8250_check_id(addr[i])) {
|
||||||
fintek_8250_exit_key(addr[i]);
|
fintek_8250_exit_key(addr[i]);
|
||||||
if (!ret) {
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (k = 0; k < 4; k++) {
|
||||||
|
u16 aux;
|
||||||
|
|
||||||
|
outb(LDN, addr[i] + ADDR_PORT);
|
||||||
|
outb(k, addr[i] + DATA_PORT);
|
||||||
|
|
||||||
|
outb(IO_ADDR1, addr[i] + ADDR_PORT);
|
||||||
|
aux = inb(addr[i] + DATA_PORT);
|
||||||
|
outb(IO_ADDR2, addr[i] + ADDR_PORT);
|
||||||
|
aux |= inb(addr[i] + DATA_PORT) << 8;
|
||||||
|
if (aux != io_address)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
fintek_8250_exit_key(addr[i]);
|
||||||
*key = keys[j];
|
*key = keys[j];
|
||||||
|
*index = k;
|
||||||
return addr[i];
|
return addr[i];
|
||||||
}
|
}
|
||||||
|
fintek_8250_exit_key(addr[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,21 +184,17 @@ fintek_8250_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
|
||||||
{
|
{
|
||||||
struct uart_8250_port uart;
|
struct uart_8250_port uart;
|
||||||
struct fintek_8250 *pdata;
|
struct fintek_8250 *pdata;
|
||||||
int index;
|
|
||||||
int base_port;
|
int base_port;
|
||||||
u8 key;
|
u8 key;
|
||||||
|
u8 index;
|
||||||
|
|
||||||
if (!pnp_port_valid(dev, 0))
|
if (!pnp_port_valid(dev, 0))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
base_port = fintek_8250_base_port(&key);
|
base_port = fintek_8250_base_port(pnp_port_start(dev, 0), &key, &index);
|
||||||
if (base_port < 0)
|
if (base_port < 0)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
index = fintek_8250_get_index(pnp_port_start(dev, 0));
|
|
||||||
if (index < 0)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
memset(&uart, 0, sizeof(uart));
|
memset(&uart, 0, sizeof(uart));
|
||||||
|
|
||||||
pdata = devm_kzalloc(&dev->dev, sizeof(*pdata), GFP_KERNEL);
|
pdata = devm_kzalloc(&dev->dev, sizeof(*pdata), GFP_KERNEL);
|
||||||
|
|
Loading…
Reference in New Issue