Commit 6e197696 authored by Vitaly Bordug's avatar Vitaly Bordug Committed by Paul Mackerras

[PATCH] ppc32 CPM_UART: fixes and improvements

A number of small issues are fixed, and added the header file, missed from the
original series. With this, driver should be pretty stable as tested among
both platform-device-driven and "old way" boards. Also added missing GPL
statement , and updated year field on existing ones to reflect
code update.
Signed-off-by: default avatarVitaly Bordug <vbordug@ru.mvista.com>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent 61f5657c
...@@ -378,7 +378,7 @@ int __init mpc866ads_init(void) ...@@ -378,7 +378,7 @@ int __init mpc866ads_init(void)
ppc_sys_device_setfunc(MPC8xx_CPM_SMC1, PPC_SYS_FUNC_UART); ppc_sys_device_setfunc(MPC8xx_CPM_SMC1, PPC_SYS_FUNC_UART);
#endif #endif
#ifdef CONFIG_SERIAL_CPM_SMCer #ifdef CONFIG_SERIAL_CPM_SMC
ppc_sys_device_enable(MPC8xx_CPM_SMC2); ppc_sys_device_enable(MPC8xx_CPM_SMC2);
ppc_sys_device_setfunc(MPC8xx_CPM_SMC2, PPC_SYS_FUNC_UART); ppc_sys_device_setfunc(MPC8xx_CPM_SMC2, PPC_SYS_FUNC_UART);
#endif #endif
......
...@@ -5,6 +5,13 @@ ...@@ -5,6 +5,13 @@
* *
* Copyright (C) 2004 Freescale Semiconductor, Inc. * Copyright (C) 2004 Freescale Semiconductor, Inc.
* *
* 2006 (c) MontaVista Software, Inc.
* Vitaly Bordug <vbordug@ru.mvista.com>
*
* This file is licensed under the terms of the GNU General Public License
* version 2. This program is licensed "as is" without any warranty of any
* kind, whether express or implied.
*
*/ */
#ifndef CPM_UART_H #ifndef CPM_UART_H
#define CPM_UART_H #define CPM_UART_H
...@@ -101,12 +108,13 @@ static inline unsigned long cpu2cpm_addr(void* addr, struct uart_cpm_port *pinfo ...@@ -101,12 +108,13 @@ static inline unsigned long cpu2cpm_addr(void* addr, struct uart_cpm_port *pinfo
int offset; int offset;
u32 val = (u32)addr; u32 val = (u32)addr;
/* sane check */ /* sane check */
if ((val >= (u32)pinfo->mem_addr) && if (likely((val >= (u32)pinfo->mem_addr)) &&
(val<((u32)pinfo->mem_addr + pinfo->mem_size))) { (val<((u32)pinfo->mem_addr + pinfo->mem_size))) {
offset = val - (u32)pinfo->mem_addr; offset = val - (u32)pinfo->mem_addr;
return pinfo->dma_addr+offset; return pinfo->dma_addr+offset;
} }
printk("%s(): address %x to translate out of range!\n", __FUNCTION__, val); /* something nasty happened */
BUG();
return 0; return 0;
} }
...@@ -115,12 +123,13 @@ static inline void *cpm2cpu_addr(unsigned long addr, struct uart_cpm_port *pinfo ...@@ -115,12 +123,13 @@ static inline void *cpm2cpu_addr(unsigned long addr, struct uart_cpm_port *pinfo
int offset; int offset;
u32 val = addr; u32 val = addr;
/* sane check */ /* sane check */
if ((val >= pinfo->dma_addr) && if (likely((val >= pinfo->dma_addr) &&
(val<(pinfo->dma_addr + pinfo->mem_size))) { (val<(pinfo->dma_addr + pinfo->mem_size)))) {
offset = val - (u32)pinfo->dma_addr; offset = val - (u32)pinfo->dma_addr;
return (void*)(pinfo->mem_addr+offset); return (void*)(pinfo->mem_addr+offset);
} }
printk("%s(): address %x to translate out of range!\n", __FUNCTION__, val); /* something nasty happened */
BUG();
return 0; return 0;
} }
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
* *
* Copyright (C) 2004 Freescale Semiconductor, Inc. * Copyright (C) 2004 Freescale Semiconductor, Inc.
* (C) 2004 Intracom, S.A. * (C) 2004 Intracom, S.A.
* (C) 2005 MontaVista Software, Inc. by Vitaly Bordug <vbordug@ru.mvista.com> * (C) 2005-2006 MontaVista Software, Inc.
* Vitaly Bordug <vbordug@ru.mvista.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -81,7 +82,7 @@ early_uart_get_pdev(int index) ...@@ -81,7 +82,7 @@ early_uart_get_pdev(int index)
} }
void cpm_uart_count(void) static void cpm_uart_count(void)
{ {
cpm_uart_nr = 0; cpm_uart_nr = 0;
#ifdef CONFIG_SERIAL_CPM_SMC1 #ifdef CONFIG_SERIAL_CPM_SMC1
...@@ -104,6 +105,21 @@ void cpm_uart_count(void) ...@@ -104,6 +105,21 @@ void cpm_uart_count(void)
#endif #endif
} }
/* Get UART number by its id */
static int cpm_uart_id2nr(int id)
{
int i;
if (id < UART_NR) {
for (i=0; i<UART_NR; i++) {
if (cpm_uart_port_map[i] == id)
return i;
}
}
/* not found or invalid argument */
return -1;
}
/* /*
* Check, if transmit buffers are processed * Check, if transmit buffers are processed
*/ */
...@@ -1012,7 +1028,11 @@ int cpm_uart_drv_get_platform_data(struct platform_device *pdev, int is_con) ...@@ -1012,7 +1028,11 @@ int cpm_uart_drv_get_platform_data(struct platform_device *pdev, int is_con)
int line; int line;
u32 mem, pram; u32 mem, pram;
for (line=0; line<UART_NR && cpm_uart_port_map[line]!=pdata->fs_no; line++); line = cpm_uart_id2nr(idx);
if(line < 0) {
printk(KERN_ERR"%s(): port %d is not registered", __FUNCTION__, idx);
return -1;
}
pinfo = (struct uart_cpm_port *) &cpm_uart_ports[idx]; pinfo = (struct uart_cpm_port *) &cpm_uart_ports[idx];
...@@ -1245,8 +1265,7 @@ static int cpm_uart_drv_probe(struct device *dev) ...@@ -1245,8 +1265,7 @@ static int cpm_uart_drv_probe(struct device *dev)
} }
pdata = pdev->dev.platform_data; pdata = pdev->dev.platform_data;
pr_debug("cpm_uart_drv_probe: Adding CPM UART %d\n", pr_debug("cpm_uart_drv_probe: Adding CPM UART %d\n", cpm_uart_id2nr(pdata->fs_no));
cpm_uart_port_map[pdata->fs_no]);
if ((ret = cpm_uart_drv_get_platform_data(pdev, 0))) if ((ret = cpm_uart_drv_get_platform_data(pdev, 0)))
return ret; return ret;
...@@ -1265,7 +1284,7 @@ static int cpm_uart_drv_remove(struct device *dev) ...@@ -1265,7 +1284,7 @@ static int cpm_uart_drv_remove(struct device *dev)
struct fs_uart_platform_info *pdata = pdev->dev.platform_data; struct fs_uart_platform_info *pdata = pdev->dev.platform_data;
pr_debug("cpm_uart_drv_remove: Removing CPM UART %d\n", pr_debug("cpm_uart_drv_remove: Removing CPM UART %d\n",
cpm_uart_port_map[pdata->fs_no]); cpm_uart_id2nr(pdata->fs_no));
uart_remove_one_port(&cpm_reg, &cpm_uart_ports[pdata->fs_no].port); uart_remove_one_port(&cpm_reg, &cpm_uart_ports[pdata->fs_no].port);
return 0; return 0;
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
* *
* Copyright (C) 2004 Freescale Semiconductor, Inc. * Copyright (C) 2004 Freescale Semiconductor, Inc.
* (C) 2004 Intracom, S.A. * (C) 2004 Intracom, S.A.
* (C) 2006 MontaVista Software, Inc.
* Vitaly Bordug <vbordug@ru.mvista.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
* *
* Copyright (C) 2004 Freescale Semiconductor, Inc. * Copyright (C) 2004 Freescale Semiconductor, Inc.
* (C) 2004 Intracom, S.A. * (C) 2004 Intracom, S.A.
* (C) 2006 MontaVista Software, Inc.
* Vitaly Bordug <vbordug@ru.mvista.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/*
* Platform information definitions for the CPM Uart driver.
*
* 2006 (c) MontaVista Software, Inc.
* Vitaly Bordug <vbordug@ru.mvista.com>
*
* This file is licensed under the terms of the GNU General Public License
* version 2. This program is licensed "as is" without any warranty of any
* kind, whether express or implied.
*/
#ifndef FS_UART_PD_H
#define FS_UART_PD_H
#include <linux/version.h>
#include <asm/types.h>
enum fs_uart_id {
fsid_smc1_uart,
fsid_smc2_uart,
fsid_scc1_uart,
fsid_scc2_uart,
fsid_scc3_uart,
fsid_scc4_uart,
fs_uart_nr,
};
static inline int fs_uart_id_scc2fsid(int id)
{
return fsid_scc1_uart + id - 1;
}
static inline int fs_uart_id_fsid2scc(int id)
{
return id - fsid_scc1_uart + 1;
}
static inline int fs_uart_id_smc2fsid(int id)
{
return fsid_smc1_uart + id - 1;
}
static inline int fs_uart_id_fsid2smc(int id)
{
return id - fsid_smc1_uart + 1;
}
struct fs_uart_platform_info {
void(*init_ioports)(void);
/* device specific information */
int fs_no; /* controller index */
u32 uart_clk;
u8 tx_num_fifo;
u8 tx_buf_size;
u8 rx_num_fifo;
u8 rx_buf_size;
u8 brg;
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment