aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-12 00:55:47 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-12 00:55:47 -0400
commite86908614f2c7fec401827e5cefd7a6ea9407f85 (patch)
treefcb5d9e52422b37bdaf0e647126ebdfc1680f162 /drivers/serial
parent547307420931344a868275bd7ea7a30f117a15a9 (diff)
parent9b4b8feb962f4b3e74768b7205f1f8f6cce87238 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
* 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc: (408 commits) [POWERPC] Add memchr() to the bootwrapper [POWERPC] Implement logging of unhandled signals [POWERPC] Add legacy serial support for OPB with flattened device tree [POWERPC] Use 1TB segments [POWERPC] XilinxFB: Allow fixed framebuffer base address [POWERPC] XilinxFB: Add support for custom screen resolution [POWERPC] XilinxFB: Use pdata to pass around framebuffer parameters [POWERPC] PCI: Add 64-bit physical address support to setup_indirect_pci [POWERPC] 4xx: Kilauea defconfig file [POWERPC] 4xx: Kilauea DTS [POWERPC] 4xx: Add AMCC Kilauea eval board support to platforms/40x [POWERPC] 4xx: Add AMCC 405EX support to cputable.c [POWERPC] Adjust TASK_SIZE on ppc32 systems to 3GB that are capable [POWERPC] Use PAGE_OFFSET to tell if an address is user/kernel in SW TLB handlers [POWERPC] 85xx: Enable FP emulation in MPC8560 ADS defconfig [POWERPC] 85xx: Killed <asm/mpc85xx.h> [POWERPC] 85xx: Add cpm nodes for 8541/8555 CDS [POWERPC] 85xx: Convert mpc8560ads to the new CPM binding. [POWERPC] mpc8272ads: Remove muram from the CPM reg property. [POWERPC] Make clockevents work on PPC601 processors ... Fixed up conflict in Documentation/powerpc/booting-without-of.txt manually.
Diffstat (limited to 'drivers/serial')
-rw-r--r--drivers/serial/Kconfig25
-rw-r--r--drivers/serial/cpm_uart/cpm_uart.h48
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_core.c539
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm1.c18
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm1.h16
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm2.c24
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm2.h16
-rw-r--r--drivers/serial/mpc52xx_uart.c2
-rw-r--r--drivers/serial/pmac_zilog.c22
-rw-r--r--drivers/serial/uartlite.c286
10 files changed, 735 insertions, 261 deletions
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 81b52b7cca21..d6ae38e55d01 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -986,6 +986,31 @@ config SERIAL_PMACZILOG
986 PowerMac machines. 986 PowerMac machines.
987 Say Y or M if you want to be able to these serial ports. 987 Say Y or M if you want to be able to these serial ports.
988 988
989config SERIAL_PMACZILOG_TTYS
990 bool "Use ttySn device nodes for Zilog z85c30"
991 depends on SERIAL_PMACZILOG
992 help
993 The pmac_zilog driver for the z85C30 chip on many powermacs
994 historically used the device numbers for /dev/ttySn. The
995 8250 serial port driver also uses these numbers, which means
996 the two drivers being unable to coexist; you could not use
997 both z85C30 and 8250 type ports at the same time.
998
999 If this option is not selected, the pmac_zilog driver will
1000 use the device numbers allocated for /dev/ttyPZn. This allows
1001 the pmac_zilog and 8250 drivers to co-exist, but may cause
1002 existing userspace setups to break. Programs that need to
1003 access the built-in serial ports on powermacs will need to
1004 be reconfigured to use /dev/ttyPZn instead of /dev/ttySn.
1005
1006 If you enable this option, any z85c30 ports in the system will
1007 be registered as ttyS0 onwards as in the past, and you will be
1008 unable to use the 8250 module for PCMCIA or other 16C550-style
1009 UARTs.
1010
1011 Say N unless you need the z85c30 ports on your powermac
1012 to appear as /dev/ttySn.
1013
989config SERIAL_PMACZILOG_CONSOLE 1014config SERIAL_PMACZILOG_CONSOLE
990 bool "Console on PowerMac z85c30 serial port" 1015 bool "Console on PowerMac z85c30 serial port"
991 depends on SERIAL_PMACZILOG=y 1016 depends on SERIAL_PMACZILOG=y
diff --git a/drivers/serial/cpm_uart/cpm_uart.h b/drivers/serial/cpm_uart/cpm_uart.h
index a8f894c78194..32b9737759c4 100644
--- a/drivers/serial/cpm_uart/cpm_uart.h
+++ b/drivers/serial/cpm_uart/cpm_uart.h
@@ -56,21 +56,21 @@ struct uart_cpm_port {
56 u16 rx_fifosize; 56 u16 rx_fifosize;
57 u16 tx_nrfifos; 57 u16 tx_nrfifos;
58 u16 tx_fifosize; 58 u16 tx_fifosize;
59 smc_t *smcp; 59 smc_t __iomem *smcp;
60 smc_uart_t *smcup; 60 smc_uart_t __iomem *smcup;
61 scc_t *sccp; 61 scc_t __iomem *sccp;
62 scc_uart_t *sccup; 62 scc_uart_t __iomem *sccup;
63 volatile cbd_t *rx_bd_base; 63 cbd_t __iomem *rx_bd_base;
64 volatile cbd_t *rx_cur; 64 cbd_t __iomem *rx_cur;
65 volatile cbd_t *tx_bd_base; 65 cbd_t __iomem *tx_bd_base;
66 volatile cbd_t *tx_cur; 66 cbd_t __iomem *tx_cur;
67 unsigned char *tx_buf; 67 unsigned char *tx_buf;
68 unsigned char *rx_buf; 68 unsigned char *rx_buf;
69 u32 flags; 69 u32 flags;
70 void (*set_lineif)(struct uart_cpm_port *); 70 void (*set_lineif)(struct uart_cpm_port *);
71 u8 brg; 71 u8 brg;
72 uint dp_addr; 72 uint dp_addr;
73 void *mem_addr; 73 void *mem_addr;
74 dma_addr_t dma_addr; 74 dma_addr_t dma_addr;
75 u32 mem_size; 75 u32 mem_size;
76 /* helpers */ 76 /* helpers */
@@ -80,14 +80,18 @@ struct uart_cpm_port {
80 int is_portb; 80 int is_portb;
81 /* wait on close if needed */ 81 /* wait on close if needed */
82 int wait_closing; 82 int wait_closing;
83 /* value to combine with opcode to form cpm command */
84 u32 command;
83}; 85};
84 86
87#ifndef CONFIG_PPC_CPM_NEW_BINDING
85extern int cpm_uart_port_map[UART_NR]; 88extern int cpm_uart_port_map[UART_NR];
89#endif
86extern int cpm_uart_nr; 90extern int cpm_uart_nr;
87extern struct uart_cpm_port cpm_uart_ports[UART_NR]; 91extern struct uart_cpm_port cpm_uart_ports[UART_NR];
88 92
89/* these are located in their respective files */ 93/* these are located in their respective files */
90void cpm_line_cr_cmd(int line, int cmd); 94void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd);
91int cpm_uart_init_portdesc(void); 95int cpm_uart_init_portdesc(void);
92int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con); 96int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con);
93void cpm_uart_freebuf(struct uart_cpm_port *pinfo); 97void cpm_uart_freebuf(struct uart_cpm_port *pinfo);
@@ -102,34 +106,36 @@ void scc4_lineif(struct uart_cpm_port *pinfo);
102/* 106/*
103 virtual to phys transtalion 107 virtual to phys transtalion
104*/ 108*/
105static inline unsigned long cpu2cpm_addr(void* addr, struct uart_cpm_port *pinfo) 109static inline unsigned long cpu2cpm_addr(void *addr,
110 struct uart_cpm_port *pinfo)
106{ 111{
107 int offset; 112 int offset;
108 u32 val = (u32)addr; 113 u32 val = (u32)addr;
114 u32 mem = (u32)pinfo->mem_addr;
109 /* sane check */ 115 /* sane check */
110 if (likely((val >= (u32)pinfo->mem_addr)) && 116 if (likely(val >= mem && val < mem + pinfo->mem_size)) {
111 (val<((u32)pinfo->mem_addr + pinfo->mem_size))) { 117 offset = val - mem;
112 offset = val - (u32)pinfo->mem_addr; 118 return pinfo->dma_addr + offset;
113 return pinfo->dma_addr+offset;
114 } 119 }
115 /* something nasty happened */ 120 /* something nasty happened */
116 BUG(); 121 BUG();
117 return 0; 122 return 0;
118} 123}
119 124
120static inline void *cpm2cpu_addr(unsigned long addr, struct uart_cpm_port *pinfo) 125static inline void *cpm2cpu_addr(unsigned long addr,
126 struct uart_cpm_port *pinfo)
121{ 127{
122 int offset; 128 int offset;
123 u32 val = addr; 129 u32 val = addr;
130 u32 dma = (u32)pinfo->dma_addr;
124 /* sane check */ 131 /* sane check */
125 if (likely((val >= pinfo->dma_addr) && 132 if (likely(val >= dma && val < dma + pinfo->mem_size)) {
126 (val<(pinfo->dma_addr + pinfo->mem_size)))) { 133 offset = val - dma;
127 offset = val - (u32)pinfo->dma_addr; 134 return pinfo->mem_addr + offset;
128 return (void*)(pinfo->mem_addr+offset);
129 } 135 }
130 /* something nasty happened */ 136 /* something nasty happened */
131 BUG(); 137 BUG();
132 return 0; 138 return NULL;
133} 139}
134 140
135 141
diff --git a/drivers/serial/cpm_uart/cpm_uart_core.c b/drivers/serial/cpm_uart/cpm_uart_core.c
index cefde58dbad2..b5e4478de0e3 100644
--- a/drivers/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/serial/cpm_uart/cpm_uart_core.c
@@ -10,7 +10,7 @@
10 * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2) 10 * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2)
11 * Pantelis Antoniou (panto@intracom.gr) (CPM1) 11 * Pantelis Antoniou (panto@intracom.gr) (CPM1)
12 * 12 *
13 * Copyright (C) 2004 Freescale Semiconductor, Inc. 13 * Copyright (C) 2004, 2007 Freescale Semiconductor, Inc.
14 * (C) 2004 Intracom, S.A. 14 * (C) 2004 Intracom, S.A.
15 * (C) 2005-2006 MontaVista Software, Inc. 15 * (C) 2005-2006 MontaVista Software, Inc.
16 * Vitaly Bordug <vbordug@ru.mvista.com> 16 * Vitaly Bordug <vbordug@ru.mvista.com>
@@ -47,6 +47,11 @@
47#include <asm/irq.h> 47#include <asm/irq.h>
48#include <asm/delay.h> 48#include <asm/delay.h>
49#include <asm/fs_pd.h> 49#include <asm/fs_pd.h>
50#include <asm/udbg.h>
51
52#ifdef CONFIG_PPC_CPM_NEW_BINDING
53#include <linux/of_platform.h>
54#endif
50 55
51#if defined(CONFIG_SERIAL_CPM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 56#if defined(CONFIG_SERIAL_CPM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
52#define SUPPORT_SYSRQ 57#define SUPPORT_SYSRQ
@@ -57,12 +62,6 @@
57 62
58#include "cpm_uart.h" 63#include "cpm_uart.h"
59 64
60/***********************************************************************/
61
62/* Track which ports are configured as uarts */
63int cpm_uart_port_map[UART_NR];
64/* How many ports did we config as uarts */
65int cpm_uart_nr = 0;
66 65
67/**************************************************************/ 66/**************************************************************/
68 67
@@ -73,6 +72,11 @@ static void cpm_uart_initbd(struct uart_cpm_port *pinfo);
73 72
74/**************************************************************/ 73/**************************************************************/
75 74
75#ifndef CONFIG_PPC_CPM_NEW_BINDING
76/* Track which ports are configured as uarts */
77int cpm_uart_port_map[UART_NR];
78/* How many ports did we config as uarts */
79int cpm_uart_nr;
76 80
77/* Place-holder for board-specific stuff */ 81/* Place-holder for board-specific stuff */
78struct platform_device* __attribute__ ((weak)) __init 82struct platform_device* __attribute__ ((weak)) __init
@@ -119,6 +123,7 @@ static int cpm_uart_id2nr(int id)
119 /* not found or invalid argument */ 123 /* not found or invalid argument */
120 return -1; 124 return -1;
121} 125}
126#endif
122 127
123/* 128/*
124 * Check, if transmit buffers are processed 129 * Check, if transmit buffers are processed
@@ -126,14 +131,14 @@ static int cpm_uart_id2nr(int id)
126static unsigned int cpm_uart_tx_empty(struct uart_port *port) 131static unsigned int cpm_uart_tx_empty(struct uart_port *port)
127{ 132{
128 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 133 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
129 volatile cbd_t *bdp = pinfo->tx_bd_base; 134 cbd_t __iomem *bdp = pinfo->tx_bd_base;
130 int ret = 0; 135 int ret = 0;
131 136
132 while (1) { 137 while (1) {
133 if (bdp->cbd_sc & BD_SC_READY) 138 if (in_be16(&bdp->cbd_sc) & BD_SC_READY)
134 break; 139 break;
135 140
136 if (bdp->cbd_sc & BD_SC_WRAP) { 141 if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP) {
137 ret = TIOCSER_TEMT; 142 ret = TIOCSER_TEMT;
138 break; 143 break;
139 } 144 }
@@ -162,15 +167,15 @@ static unsigned int cpm_uart_get_mctrl(struct uart_port *port)
162static void cpm_uart_stop_tx(struct uart_port *port) 167static void cpm_uart_stop_tx(struct uart_port *port)
163{ 168{
164 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 169 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
165 volatile smc_t *smcp = pinfo->smcp; 170 smc_t __iomem *smcp = pinfo->smcp;
166 volatile scc_t *sccp = pinfo->sccp; 171 scc_t __iomem *sccp = pinfo->sccp;
167 172
168 pr_debug("CPM uart[%d]:stop tx\n", port->line); 173 pr_debug("CPM uart[%d]:stop tx\n", port->line);
169 174
170 if (IS_SMC(pinfo)) 175 if (IS_SMC(pinfo))
171 smcp->smc_smcm &= ~SMCM_TX; 176 clrbits8(&smcp->smc_smcm, SMCM_TX);
172 else 177 else
173 sccp->scc_sccm &= ~UART_SCCM_TX; 178 clrbits16(&sccp->scc_sccm, UART_SCCM_TX);
174} 179}
175 180
176/* 181/*
@@ -179,24 +184,24 @@ static void cpm_uart_stop_tx(struct uart_port *port)
179static void cpm_uart_start_tx(struct uart_port *port) 184static void cpm_uart_start_tx(struct uart_port *port)
180{ 185{
181 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 186 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
182 volatile smc_t *smcp = pinfo->smcp; 187 smc_t __iomem *smcp = pinfo->smcp;
183 volatile scc_t *sccp = pinfo->sccp; 188 scc_t __iomem *sccp = pinfo->sccp;
184 189
185 pr_debug("CPM uart[%d]:start tx\n", port->line); 190 pr_debug("CPM uart[%d]:start tx\n", port->line);
186 191
187 if (IS_SMC(pinfo)) { 192 if (IS_SMC(pinfo)) {
188 if (smcp->smc_smcm & SMCM_TX) 193 if (in_8(&smcp->smc_smcm) & SMCM_TX)
189 return; 194 return;
190 } else { 195 } else {
191 if (sccp->scc_sccm & UART_SCCM_TX) 196 if (in_be16(&sccp->scc_sccm) & UART_SCCM_TX)
192 return; 197 return;
193 } 198 }
194 199
195 if (cpm_uart_tx_pump(port) != 0) { 200 if (cpm_uart_tx_pump(port) != 0) {
196 if (IS_SMC(pinfo)) { 201 if (IS_SMC(pinfo)) {
197 smcp->smc_smcm |= SMCM_TX; 202 setbits8(&smcp->smc_smcm, SMCM_TX);
198 } else { 203 } else {
199 sccp->scc_sccm |= UART_SCCM_TX; 204 setbits16(&sccp->scc_sccm, UART_SCCM_TX);
200 } 205 }
201 } 206 }
202} 207}
@@ -207,15 +212,15 @@ static void cpm_uart_start_tx(struct uart_port *port)
207static void cpm_uart_stop_rx(struct uart_port *port) 212static void cpm_uart_stop_rx(struct uart_port *port)
208{ 213{
209 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 214 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
210 volatile smc_t *smcp = pinfo->smcp; 215 smc_t __iomem *smcp = pinfo->smcp;
211 volatile scc_t *sccp = pinfo->sccp; 216 scc_t __iomem *sccp = pinfo->sccp;
212 217
213 pr_debug("CPM uart[%d]:stop rx\n", port->line); 218 pr_debug("CPM uart[%d]:stop rx\n", port->line);
214 219
215 if (IS_SMC(pinfo)) 220 if (IS_SMC(pinfo))
216 smcp->smc_smcm &= ~SMCM_RX; 221 clrbits8(&smcp->smc_smcm, SMCM_RX);
217 else 222 else
218 sccp->scc_sccm &= ~UART_SCCM_RX; 223 clrbits16(&sccp->scc_sccm, UART_SCCM_RX);
219} 224}
220 225
221/* 226/*
@@ -232,15 +237,14 @@ static void cpm_uart_enable_ms(struct uart_port *port)
232static void cpm_uart_break_ctl(struct uart_port *port, int break_state) 237static void cpm_uart_break_ctl(struct uart_port *port, int break_state)
233{ 238{
234 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 239 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
235 int line = pinfo - cpm_uart_ports;
236 240
237 pr_debug("CPM uart[%d]:break ctrl, break_state: %d\n", port->line, 241 pr_debug("CPM uart[%d]:break ctrl, break_state: %d\n", port->line,
238 break_state); 242 break_state);
239 243
240 if (break_state) 244 if (break_state)
241 cpm_line_cr_cmd(line, CPM_CR_STOP_TX); 245 cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX);
242 else 246 else
243 cpm_line_cr_cmd(line, CPM_CR_RESTART_TX); 247 cpm_line_cr_cmd(pinfo, CPM_CR_RESTART_TX);
244} 248}
245 249
246/* 250/*
@@ -259,10 +263,11 @@ static void cpm_uart_int_tx(struct uart_port *port)
259static void cpm_uart_int_rx(struct uart_port *port) 263static void cpm_uart_int_rx(struct uart_port *port)
260{ 264{
261 int i; 265 int i;
262 unsigned char ch, *cp; 266 unsigned char ch;
267 u8 *cp;
263 struct tty_struct *tty = port->info->tty; 268 struct tty_struct *tty = port->info->tty;
264 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 269 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
265 volatile cbd_t *bdp; 270 cbd_t __iomem *bdp;
266 u16 status; 271 u16 status;
267 unsigned int flg; 272 unsigned int flg;
268 273
@@ -274,13 +279,13 @@ static void cpm_uart_int_rx(struct uart_port *port)
274 bdp = pinfo->rx_cur; 279 bdp = pinfo->rx_cur;
275 for (;;) { 280 for (;;) {
276 /* get status */ 281 /* get status */
277 status = bdp->cbd_sc; 282 status = in_be16(&bdp->cbd_sc);
278 /* If this one is empty, return happy */ 283 /* If this one is empty, return happy */
279 if (status & BD_SC_EMPTY) 284 if (status & BD_SC_EMPTY)
280 break; 285 break;
281 286
282 /* get number of characters, and check spce in flip-buffer */ 287 /* get number of characters, and check spce in flip-buffer */
283 i = bdp->cbd_datlen; 288 i = in_be16(&bdp->cbd_datlen);
284 289
285 /* If we have not enough room in tty flip buffer, then we try 290 /* If we have not enough room in tty flip buffer, then we try
286 * later, which will be the next rx-interrupt or a timeout 291 * later, which will be the next rx-interrupt or a timeout
@@ -291,7 +296,7 @@ static void cpm_uart_int_rx(struct uart_port *port)
291 } 296 }
292 297
293 /* get pointer */ 298 /* get pointer */
294 cp = cpm2cpu_addr(bdp->cbd_bufaddr, pinfo); 299 cp = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo);
295 300
296 /* loop through the buffer */ 301 /* loop through the buffer */
297 while (i-- > 0) { 302 while (i-- > 0) {
@@ -311,10 +316,11 @@ static void cpm_uart_int_rx(struct uart_port *port)
311 } /* End while (i--) */ 316 } /* End while (i--) */
312 317
313 /* This BD is ready to be used again. Clear status. get next */ 318 /* This BD is ready to be used again. Clear status. get next */
314 bdp->cbd_sc &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV | BD_SC_ID); 319 clrbits16(&bdp->cbd_sc, BD_SC_BR | BD_SC_FR | BD_SC_PR |
315 bdp->cbd_sc |= BD_SC_EMPTY; 320 BD_SC_OV | BD_SC_ID);
321 setbits16(&bdp->cbd_sc, BD_SC_EMPTY);
316 322
317 if (bdp->cbd_sc & BD_SC_WRAP) 323 if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP)
318 bdp = pinfo->rx_bd_base; 324 bdp = pinfo->rx_bd_base;
319 else 325 else
320 bdp++; 326 bdp++;
@@ -322,7 +328,7 @@ static void cpm_uart_int_rx(struct uart_port *port)
322 } /* End for (;;) */ 328 } /* End for (;;) */
323 329
324 /* Write back buffer pointer */ 330 /* Write back buffer pointer */
325 pinfo->rx_cur = (volatile cbd_t *) bdp; 331 pinfo->rx_cur = bdp;
326 332
327 /* activate BH processing */ 333 /* activate BH processing */
328 tty_flip_buffer_push(tty); 334 tty_flip_buffer_push(tty);
@@ -376,14 +382,14 @@ static irqreturn_t cpm_uart_int(int irq, void *data)
376 u8 events; 382 u8 events;
377 struct uart_port *port = (struct uart_port *)data; 383 struct uart_port *port = (struct uart_port *)data;
378 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 384 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
379 volatile smc_t *smcp = pinfo->smcp; 385 smc_t __iomem *smcp = pinfo->smcp;
380 volatile scc_t *sccp = pinfo->sccp; 386 scc_t __iomem *sccp = pinfo->sccp;
381 387
382 pr_debug("CPM uart[%d]:IRQ\n", port->line); 388 pr_debug("CPM uart[%d]:IRQ\n", port->line);
383 389
384 if (IS_SMC(pinfo)) { 390 if (IS_SMC(pinfo)) {
385 events = smcp->smc_smce; 391 events = in_8(&smcp->smc_smce);
386 smcp->smc_smce = events; 392 out_8(&smcp->smc_smce, events);
387 if (events & SMCM_BRKE) 393 if (events & SMCM_BRKE)
388 uart_handle_break(port); 394 uart_handle_break(port);
389 if (events & SMCM_RX) 395 if (events & SMCM_RX)
@@ -391,8 +397,8 @@ static irqreturn_t cpm_uart_int(int irq, void *data)
391 if (events & SMCM_TX) 397 if (events & SMCM_TX)
392 cpm_uart_int_tx(port); 398 cpm_uart_int_tx(port);
393 } else { 399 } else {
394 events = sccp->scc_scce; 400 events = in_be16(&sccp->scc_scce);
395 sccp->scc_scce = events; 401 out_be16(&sccp->scc_scce, events);
396 if (events & UART_SCCM_BRKE) 402 if (events & UART_SCCM_BRKE)
397 uart_handle_break(port); 403 uart_handle_break(port);
398 if (events & UART_SCCM_RX) 404 if (events & UART_SCCM_RX)
@@ -407,7 +413,6 @@ static int cpm_uart_startup(struct uart_port *port)
407{ 413{
408 int retval; 414 int retval;
409 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 415 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
410 int line = pinfo - cpm_uart_ports;
411 416
412 pr_debug("CPM uart[%d]:startup\n", port->line); 417 pr_debug("CPM uart[%d]:startup\n", port->line);
413 418
@@ -418,15 +423,15 @@ static int cpm_uart_startup(struct uart_port *port)
418 423
419 /* Startup rx-int */ 424 /* Startup rx-int */
420 if (IS_SMC(pinfo)) { 425 if (IS_SMC(pinfo)) {
421 pinfo->smcp->smc_smcm |= SMCM_RX; 426 setbits8(&pinfo->smcp->smc_smcm, SMCM_RX);
422 pinfo->smcp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN); 427 setbits16(&pinfo->smcp->smc_smcmr, (SMCMR_REN | SMCMR_TEN));
423 } else { 428 } else {
424 pinfo->sccp->scc_sccm |= UART_SCCM_RX; 429 setbits16(&pinfo->sccp->scc_sccm, UART_SCCM_RX);
425 pinfo->sccp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT); 430 setbits32(&pinfo->sccp->scc_gsmrl, (SCC_GSMRL_ENR | SCC_GSMRL_ENT));
426 } 431 }
427 432
428 if (!(pinfo->flags & FLAG_CONSOLE)) 433 if (!(pinfo->flags & FLAG_CONSOLE))
429 cpm_line_cr_cmd(line,CPM_CR_INIT_TRX); 434 cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX);
430 return 0; 435 return 0;
431} 436}
432 437
@@ -442,7 +447,6 @@ inline void cpm_uart_wait_until_send(struct uart_cpm_port *pinfo)
442static void cpm_uart_shutdown(struct uart_port *port) 447static void cpm_uart_shutdown(struct uart_port *port)
443{ 448{
444 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 449 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
445 int line = pinfo - cpm_uart_ports;
446 450
447 pr_debug("CPM uart[%d]:shutdown\n", port->line); 451 pr_debug("CPM uart[%d]:shutdown\n", port->line);
448 452
@@ -462,20 +466,20 @@ static void cpm_uart_shutdown(struct uart_port *port)
462 466
463 /* Stop uarts */ 467 /* Stop uarts */
464 if (IS_SMC(pinfo)) { 468 if (IS_SMC(pinfo)) {
465 volatile smc_t *smcp = pinfo->smcp; 469 smc_t __iomem *smcp = pinfo->smcp;
466 smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN); 470 clrbits16(&smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN);
467 smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX); 471 clrbits8(&smcp->smc_smcm, SMCM_RX | SMCM_TX);
468 } else { 472 } else {
469 volatile scc_t *sccp = pinfo->sccp; 473 scc_t __iomem *sccp = pinfo->sccp;
470 sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT); 474 clrbits32(&sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
471 sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX); 475 clrbits16(&sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX);
472 } 476 }
473 477
474 /* Shut them really down and reinit buffer descriptors */ 478 /* Shut them really down and reinit buffer descriptors */
475 if (IS_SMC(pinfo)) 479 if (IS_SMC(pinfo))
476 cpm_line_cr_cmd(line, CPM_CR_STOP_TX); 480 cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX);
477 else 481 else
478 cpm_line_cr_cmd(line, CPM_CR_GRA_STOP_TX); 482 cpm_line_cr_cmd(pinfo, CPM_CR_GRA_STOP_TX);
479 483
480 cpm_uart_initbd(pinfo); 484 cpm_uart_initbd(pinfo);
481 } 485 }
@@ -490,8 +494,8 @@ static void cpm_uart_set_termios(struct uart_port *port,
490 u16 cval, scval, prev_mode; 494 u16 cval, scval, prev_mode;
491 int bits, sbits; 495 int bits, sbits;
492 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 496 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
493 volatile smc_t *smcp = pinfo->smcp; 497 smc_t __iomem *smcp = pinfo->smcp;
494 volatile scc_t *sccp = pinfo->sccp; 498 scc_t __iomem *sccp = pinfo->sccp;
495 499
496 pr_debug("CPM uart[%d]:set_termios\n", port->line); 500 pr_debug("CPM uart[%d]:set_termios\n", port->line);
497 501
@@ -586,16 +590,15 @@ static void cpm_uart_set_termios(struct uart_port *port,
586 * enables, because we want to put them back if they were 590 * enables, because we want to put them back if they were
587 * present. 591 * present.
588 */ 592 */
589 prev_mode = smcp->smc_smcmr; 593 prev_mode = in_be16(&smcp->smc_smcmr);
590 smcp->smc_smcmr = smcr_mk_clen(bits) | cval | SMCMR_SM_UART; 594 out_be16(&smcp->smc_smcmr, smcr_mk_clen(bits) | cval | SMCMR_SM_UART);
591 smcp->smc_smcmr |= (prev_mode & (SMCMR_REN | SMCMR_TEN)); 595 setbits16(&smcp->smc_smcmr, (prev_mode & (SMCMR_REN | SMCMR_TEN)));
592 } else { 596 } else {
593 sccp->scc_psmr = (sbits << 12) | scval; 597 out_be16(&sccp->scc_psmr, (sbits << 12) | scval);
594 } 598 }
595 599
596 cpm_set_brg(pinfo->brg - 1, baud); 600 cpm_set_brg(pinfo->brg - 1, baud);
597 spin_unlock_irqrestore(&port->lock, flags); 601 spin_unlock_irqrestore(&port->lock, flags);
598
599} 602}
600 603
601static const char *cpm_uart_type(struct uart_port *port) 604static const char *cpm_uart_type(struct uart_port *port)
@@ -629,8 +632,8 @@ static int cpm_uart_verify_port(struct uart_port *port,
629 */ 632 */
630static int cpm_uart_tx_pump(struct uart_port *port) 633static int cpm_uart_tx_pump(struct uart_port *port)
631{ 634{
632 volatile cbd_t *bdp; 635 cbd_t __iomem *bdp;
633 unsigned char *p; 636 u8 *p;
634 int count; 637 int count;
635 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 638 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
636 struct circ_buf *xmit = &port->info->xmit; 639 struct circ_buf *xmit = &port->info->xmit;
@@ -640,13 +643,14 @@ static int cpm_uart_tx_pump(struct uart_port *port)
640 /* Pick next descriptor and fill from buffer */ 643 /* Pick next descriptor and fill from buffer */
641 bdp = pinfo->tx_cur; 644 bdp = pinfo->tx_cur;
642 645
643 p = cpm2cpu_addr(bdp->cbd_bufaddr, pinfo); 646 p = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo);
644 647
645 *p++ = port->x_char; 648 *p++ = port->x_char;
646 bdp->cbd_datlen = 1; 649
647 bdp->cbd_sc |= BD_SC_READY; 650 out_be16(&bdp->cbd_datlen, 1);
651 setbits16(&bdp->cbd_sc, BD_SC_READY);
648 /* Get next BD. */ 652 /* Get next BD. */
649 if (bdp->cbd_sc & BD_SC_WRAP) 653 if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP)
650 bdp = pinfo->tx_bd_base; 654 bdp = pinfo->tx_bd_base;
651 else 655 else
652 bdp++; 656 bdp++;
@@ -665,9 +669,10 @@ static int cpm_uart_tx_pump(struct uart_port *port)
665 /* Pick next descriptor and fill from buffer */ 669 /* Pick next descriptor and fill from buffer */
666 bdp = pinfo->tx_cur; 670 bdp = pinfo->tx_cur;
667 671
668 while (!(bdp->cbd_sc & BD_SC_READY) && (xmit->tail != xmit->head)) { 672 while (!(in_be16(&bdp->cbd_sc) & BD_SC_READY) &&
673 xmit->tail != xmit->head) {
669 count = 0; 674 count = 0;
670 p = cpm2cpu_addr(bdp->cbd_bufaddr, pinfo); 675 p = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo);
671 while (count < pinfo->tx_fifosize) { 676 while (count < pinfo->tx_fifosize) {
672 *p++ = xmit->buf[xmit->tail]; 677 *p++ = xmit->buf[xmit->tail];
673 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 678 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
@@ -676,11 +681,10 @@ static int cpm_uart_tx_pump(struct uart_port *port)
676 if (xmit->head == xmit->tail) 681 if (xmit->head == xmit->tail)
677 break; 682 break;
678 } 683 }
679 bdp->cbd_datlen = count; 684 out_be16(&bdp->cbd_datlen, count);
680 bdp->cbd_sc |= BD_SC_READY; 685 setbits16(&bdp->cbd_sc, BD_SC_READY);
681 eieio();
682 /* Get next BD. */ 686 /* Get next BD. */
683 if (bdp->cbd_sc & BD_SC_WRAP) 687 if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP)
684 bdp = pinfo->tx_bd_base; 688 bdp = pinfo->tx_bd_base;
685 else 689 else
686 bdp++; 690 bdp++;
@@ -705,7 +709,7 @@ static void cpm_uart_initbd(struct uart_cpm_port *pinfo)
705{ 709{
706 int i; 710 int i;
707 u8 *mem_addr; 711 u8 *mem_addr;
708 volatile cbd_t *bdp; 712 cbd_t __iomem *bdp;
709 713
710 pr_debug("CPM uart[%d]:initbd\n", pinfo->port.line); 714 pr_debug("CPM uart[%d]:initbd\n", pinfo->port.line);
711 715
@@ -716,13 +720,13 @@ static void cpm_uart_initbd(struct uart_cpm_port *pinfo)
716 mem_addr = pinfo->mem_addr; 720 mem_addr = pinfo->mem_addr;
717 bdp = pinfo->rx_cur = pinfo->rx_bd_base; 721 bdp = pinfo->rx_cur = pinfo->rx_bd_base;
718 for (i = 0; i < (pinfo->rx_nrfifos - 1); i++, bdp++) { 722 for (i = 0; i < (pinfo->rx_nrfifos - 1); i++, bdp++) {
719 bdp->cbd_bufaddr = cpu2cpm_addr(mem_addr, pinfo); 723 out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo));
720 bdp->cbd_sc = BD_SC_EMPTY | BD_SC_INTRPT; 724 out_be16(&bdp->cbd_sc, BD_SC_EMPTY | BD_SC_INTRPT);
721 mem_addr += pinfo->rx_fifosize; 725 mem_addr += pinfo->rx_fifosize;
722 } 726 }
723 727
724 bdp->cbd_bufaddr = cpu2cpm_addr(mem_addr, pinfo); 728 out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo));
725 bdp->cbd_sc = BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT; 729 out_be16(&bdp->cbd_sc, BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT);
726 730
727 /* Set the physical address of the host memory 731 /* Set the physical address of the host memory
728 * buffers in the buffer descriptors, and the 732 * buffers in the buffer descriptors, and the
@@ -731,20 +735,19 @@ static void cpm_uart_initbd(struct uart_cpm_port *pinfo)
731 mem_addr = pinfo->mem_addr + L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize); 735 mem_addr = pinfo->mem_addr + L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize);
732 bdp = pinfo->tx_cur = pinfo->tx_bd_base; 736 bdp = pinfo->tx_cur = pinfo->tx_bd_base;
733 for (i = 0; i < (pinfo->tx_nrfifos - 1); i++, bdp++) { 737 for (i = 0; i < (pinfo->tx_nrfifos - 1); i++, bdp++) {
734 bdp->cbd_bufaddr = cpu2cpm_addr(mem_addr, pinfo); 738 out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo));
735 bdp->cbd_sc = BD_SC_INTRPT; 739 out_be16(&bdp->cbd_sc, BD_SC_INTRPT);
736 mem_addr += pinfo->tx_fifosize; 740 mem_addr += pinfo->tx_fifosize;
737 } 741 }
738 742
739 bdp->cbd_bufaddr = cpu2cpm_addr(mem_addr, pinfo); 743 out_be32(&bdp->cbd_bufaddr, cpu2cpm_addr(mem_addr, pinfo));
740 bdp->cbd_sc = BD_SC_WRAP | BD_SC_INTRPT; 744 out_be16(&bdp->cbd_sc, BD_SC_WRAP | BD_SC_INTRPT);
741} 745}
742 746
743static void cpm_uart_init_scc(struct uart_cpm_port *pinfo) 747static void cpm_uart_init_scc(struct uart_cpm_port *pinfo)
744{ 748{
745 int line = pinfo - cpm_uart_ports; 749 scc_t __iomem *scp;
746 volatile scc_t *scp; 750 scc_uart_t __iomem *sup;
747 volatile scc_uart_t *sup;
748 751
749 pr_debug("CPM uart[%d]:init_scc\n", pinfo->port.line); 752 pr_debug("CPM uart[%d]:init_scc\n", pinfo->port.line);
750 753
@@ -752,8 +755,10 @@ static void cpm_uart_init_scc(struct uart_cpm_port *pinfo)
752 sup = pinfo->sccup; 755 sup = pinfo->sccup;
753 756
754 /* Store address */ 757 /* Store address */
755 pinfo->sccup->scc_genscc.scc_rbase = (unsigned char *)pinfo->rx_bd_base - DPRAM_BASE; 758 out_be16(&pinfo->sccup->scc_genscc.scc_rbase,
756 pinfo->sccup->scc_genscc.scc_tbase = (unsigned char *)pinfo->tx_bd_base - DPRAM_BASE; 759 (u8 __iomem *)pinfo->rx_bd_base - DPRAM_BASE);
760 out_be16(&pinfo->sccup->scc_genscc.scc_tbase,
761 (u8 __iomem *)pinfo->tx_bd_base - DPRAM_BASE);
757 762
758 /* Set up the uart parameters in the 763 /* Set up the uart parameters in the
759 * parameter ram. 764 * parameter ram.
@@ -761,51 +766,50 @@ static void cpm_uart_init_scc(struct uart_cpm_port *pinfo)
761 766
762 cpm_set_scc_fcr(sup); 767 cpm_set_scc_fcr(sup);
763 768
764 sup->scc_genscc.scc_mrblr = pinfo->rx_fifosize; 769 out_be16(&sup->scc_genscc.scc_mrblr, pinfo->rx_fifosize);
765 sup->scc_maxidl = pinfo->rx_fifosize; 770 out_be16(&sup->scc_maxidl, pinfo->rx_fifosize);
766 sup->scc_brkcr = 1; 771 out_be16(&sup->scc_brkcr, 1);
767 sup->scc_parec = 0; 772 out_be16(&sup->scc_parec, 0);
768 sup->scc_frmec = 0; 773 out_be16(&sup->scc_frmec, 0);
769 sup->scc_nosec = 0; 774 out_be16(&sup->scc_nosec, 0);
770 sup->scc_brkec = 0; 775 out_be16(&sup->scc_brkec, 0);
771 sup->scc_uaddr1 = 0; 776 out_be16(&sup->scc_uaddr1, 0);
772 sup->scc_uaddr2 = 0; 777 out_be16(&sup->scc_uaddr2, 0);
773 sup->scc_toseq = 0; 778 out_be16(&sup->scc_toseq, 0);
774 sup->scc_char1 = 0x8000; 779 out_be16(&sup->scc_char1, 0x8000);
775 sup->scc_char2 = 0x8000; 780 out_be16(&sup->scc_char2, 0x8000);
776 sup->scc_char3 = 0x8000; 781 out_be16(&sup->scc_char3, 0x8000);
777 sup->scc_char4 = 0x8000; 782 out_be16(&sup->scc_char4, 0x8000);
778 sup->scc_char5 = 0x8000; 783 out_be16(&sup->scc_char5, 0x8000);
779 sup->scc_char6 = 0x8000; 784 out_be16(&sup->scc_char6, 0x8000);
780 sup->scc_char7 = 0x8000; 785 out_be16(&sup->scc_char7, 0x8000);
781 sup->scc_char8 = 0x8000; 786 out_be16(&sup->scc_char8, 0x8000);
782 sup->scc_rccm = 0xc0ff; 787 out_be16(&sup->scc_rccm, 0xc0ff);
783 788
784 /* Send the CPM an initialize command. 789 /* Send the CPM an initialize command.
785 */ 790 */
786 cpm_line_cr_cmd(line, CPM_CR_INIT_TRX); 791 cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX);
787 792
788 /* Set UART mode, 8 bit, no parity, one stop. 793 /* Set UART mode, 8 bit, no parity, one stop.
789 * Enable receive and transmit. 794 * Enable receive and transmit.
790 */ 795 */
791 scp->scc_gsmrh = 0; 796 out_be32(&scp->scc_gsmrh, 0);
792 scp->scc_gsmrl = 797 out_be32(&scp->scc_gsmrl,
793 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16); 798 SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
794 799
795 /* Enable rx interrupts and clear all pending events. */ 800 /* Enable rx interrupts and clear all pending events. */
796 scp->scc_sccm = 0; 801 out_be16(&scp->scc_sccm, 0);
797 scp->scc_scce = 0xffff; 802 out_be16(&scp->scc_scce, 0xffff);
798 scp->scc_dsr = 0x7e7e; 803 out_be16(&scp->scc_dsr, 0x7e7e);
799 scp->scc_psmr = 0x3000; 804 out_be16(&scp->scc_psmr, 0x3000);
800 805
801 scp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT); 806 setbits32(&scp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
802} 807}
803 808
804static void cpm_uart_init_smc(struct uart_cpm_port *pinfo) 809static void cpm_uart_init_smc(struct uart_cpm_port *pinfo)
805{ 810{
806 int line = pinfo - cpm_uart_ports; 811 smc_t __iomem *sp;
807 volatile smc_t *sp; 812 smc_uart_t __iomem *up;
808 volatile smc_uart_t *up;
809 813
810 pr_debug("CPM uart[%d]:init_smc\n", pinfo->port.line); 814 pr_debug("CPM uart[%d]:init_smc\n", pinfo->port.line);
811 815
@@ -813,19 +817,21 @@ static void cpm_uart_init_smc(struct uart_cpm_port *pinfo)
813 up = pinfo->smcup; 817 up = pinfo->smcup;
814 818
815 /* Store address */ 819 /* Store address */
816 pinfo->smcup->smc_rbase = (u_char *)pinfo->rx_bd_base - DPRAM_BASE; 820 out_be16(&pinfo->smcup->smc_rbase,
817 pinfo->smcup->smc_tbase = (u_char *)pinfo->tx_bd_base - DPRAM_BASE; 821 (u8 __iomem *)pinfo->rx_bd_base - DPRAM_BASE);
822 out_be16(&pinfo->smcup->smc_tbase,
823 (u8 __iomem *)pinfo->tx_bd_base - DPRAM_BASE);
818 824
819/* 825/*
820 * In case SMC1 is being relocated... 826 * In case SMC1 is being relocated...
821 */ 827 */
822#if defined (CONFIG_I2C_SPI_SMC1_UCODE_PATCH) 828#if defined (CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
823 up->smc_rbptr = pinfo->smcup->smc_rbase; 829 out_be16(&up->smc_rbptr, in_be16(&pinfo->smcup->smc_rbase));
824 up->smc_tbptr = pinfo->smcup->smc_tbase; 830 out_be16(&up->smc_tbptr, in_be16(&pinfo->smcup->smc_tbase));
825 up->smc_rstate = 0; 831 out_be32(&up->smc_rstate, 0);
826 up->smc_tstate = 0; 832 out_be32(&up->smc_tstate, 0);
827 up->smc_brkcr = 1; /* number of break chars */ 833 out_be16(&up->smc_brkcr, 1); /* number of break chars */
828 up->smc_brkec = 0; 834 out_be16(&up->smc_brkec, 0);
829#endif 835#endif
830 836
831 /* Set up the uart parameters in the 837 /* Set up the uart parameters in the
@@ -834,24 +840,24 @@ static void cpm_uart_init_smc(struct uart_cpm_port *pinfo)
834 cpm_set_smc_fcr(up); 840 cpm_set_smc_fcr(up);
835 841
836 /* Using idle charater time requires some additional tuning. */ 842 /* Using idle charater time requires some additional tuning. */
837 up->smc_mrblr = pinfo->rx_fifosize; 843 out_be16(&up->smc_mrblr, pinfo->rx_fifosize);
838 up->smc_maxidl = pinfo->rx_fifosize; 844 out_be16(&up->smc_maxidl, pinfo->rx_fifosize);
839 up->smc_brklen = 0; 845 out_be16(&up->smc_brklen, 0);
840 up->smc_brkec = 0; 846 out_be16(&up->smc_brkec, 0);
841 up->smc_brkcr = 1; 847 out_be16(&up->smc_brkcr, 1);
842 848
843 cpm_line_cr_cmd(line, CPM_CR_INIT_TRX); 849 cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX);
844 850
845 /* Set UART mode, 8 bit, no parity, one stop. 851 /* Set UART mode, 8 bit, no parity, one stop.
846 * Enable receive and transmit. 852 * Enable receive and transmit.
847 */ 853 */
848 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART; 854 out_be16(&sp->smc_smcmr, smcr_mk_clen(9) | SMCMR_SM_UART);
849 855
850 /* Enable only rx interrupts clear all pending events. */ 856 /* Enable only rx interrupts clear all pending events. */
851 sp->smc_smcm = 0; 857 out_8(&sp->smc_smcm, 0);
852 sp->smc_smce = 0xff; 858 out_8(&sp->smc_smce, 0xff);
853 859
854 sp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN); 860 setbits16(&sp->smc_smcmr, SMCMR_REN | SMCMR_TEN);
855} 861}
856 862
857/* 863/*
@@ -869,11 +875,11 @@ static int cpm_uart_request_port(struct uart_port *port)
869 return 0; 875 return 0;
870 876
871 if (IS_SMC(pinfo)) { 877 if (IS_SMC(pinfo)) {
872 pinfo->smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX); 878 clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX | SMCM_TX);
873 pinfo->smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN); 879 clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN);
874 } else { 880 } else {
875 pinfo->sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX); 881 clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX);
876 pinfo->sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT); 882 clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
877 } 883 }
878 884
879 ret = cpm_uart_allocbuf(pinfo, 0); 885 ret = cpm_uart_allocbuf(pinfo, 0);
@@ -929,6 +935,86 @@ static struct uart_ops cpm_uart_pops = {
929 .verify_port = cpm_uart_verify_port, 935 .verify_port = cpm_uart_verify_port,
930}; 936};
931 937
938#ifdef CONFIG_PPC_CPM_NEW_BINDING
939struct uart_cpm_port cpm_uart_ports[UART_NR];
940
941static int cpm_uart_init_port(struct device_node *np,
942 struct uart_cpm_port *pinfo)
943{
944 const u32 *data;
945 void __iomem *mem, *pram;
946 int len;
947 int ret;
948
949 data = of_get_property(np, "fsl,cpm-brg", &len);
950 if (!data || len != 4) {
951 printk(KERN_ERR "CPM UART %s has no/invalid "
952 "fsl,cpm-brg property.\n", np->name);
953 return -EINVAL;
954 }
955 pinfo->brg = *data;
956
957 data = of_get_property(np, "fsl,cpm-command", &len);
958 if (!data || len != 4) {
959 printk(KERN_ERR "CPM UART %s has no/invalid "
960 "fsl,cpm-command property.\n", np->name);
961 return -EINVAL;
962 }
963 pinfo->command = *data;
964
965 mem = of_iomap(np, 0);
966 if (!mem)
967 return -ENOMEM;
968
969 pram = of_iomap(np, 1);
970 if (!pram) {
971 ret = -ENOMEM;
972 goto out_mem;
973 }
974
975 if (of_device_is_compatible(np, "fsl,cpm1-scc-uart") ||
976 of_device_is_compatible(np, "fsl,cpm2-scc-uart")) {
977 pinfo->sccp = mem;
978 pinfo->sccup = pram;
979 } else if (of_device_is_compatible(np, "fsl,cpm1-smc-uart") ||
980 of_device_is_compatible(np, "fsl,cpm2-smc-uart")) {
981 pinfo->flags |= FLAG_SMC;
982 pinfo->smcp = mem;
983 pinfo->smcup = pram;
984 } else {
985 ret = -ENODEV;
986 goto out_pram;
987 }
988
989 pinfo->tx_nrfifos = TX_NUM_FIFO;
990 pinfo->tx_fifosize = TX_BUF_SIZE;
991 pinfo->rx_nrfifos = RX_NUM_FIFO;
992 pinfo->rx_fifosize = RX_BUF_SIZE;
993
994 pinfo->port.uartclk = ppc_proc_freq;
995 pinfo->port.mapbase = (unsigned long)mem;
996 pinfo->port.type = PORT_CPM;
997 pinfo->port.ops = &cpm_uart_pops,
998 pinfo->port.iotype = UPIO_MEM;
999 spin_lock_init(&pinfo->port.lock);
1000
1001 pinfo->port.irq = of_irq_to_resource(np, 0, NULL);
1002 if (pinfo->port.irq == NO_IRQ) {
1003 ret = -EINVAL;
1004 goto out_pram;
1005 }
1006
1007 return cpm_uart_request_port(&pinfo->port);
1008
1009out_pram:
1010 iounmap(pram);
1011out_mem:
1012 iounmap(mem);
1013 return ret;
1014}
1015
1016#else
1017
932struct uart_cpm_port cpm_uart_ports[UART_NR] = { 1018struct uart_cpm_port cpm_uart_ports[UART_NR] = {
933 [UART_SMC1] = { 1019 [UART_SMC1] = {
934 .port = { 1020 .port = {
@@ -1072,6 +1158,7 @@ int cpm_uart_drv_get_platform_data(struct platform_device *pdev, int is_con)
1072 1158
1073 return 0; 1159 return 0;
1074} 1160}
1161#endif
1075 1162
1076#ifdef CONFIG_SERIAL_CPM_CONSOLE 1163#ifdef CONFIG_SERIAL_CPM_CONSOLE
1077/* 1164/*
@@ -1083,11 +1170,15 @@ int cpm_uart_drv_get_platform_data(struct platform_device *pdev, int is_con)
1083static void cpm_uart_console_write(struct console *co, const char *s, 1170static void cpm_uart_console_write(struct console *co, const char *s,
1084 u_int count) 1171 u_int count)
1085{ 1172{
1173#ifdef CONFIG_PPC_CPM_NEW_BINDING
1174 struct uart_cpm_port *pinfo = &cpm_uart_ports[co->index];
1175#else
1086 struct uart_cpm_port *pinfo = 1176 struct uart_cpm_port *pinfo =
1087 &cpm_uart_ports[cpm_uart_port_map[co->index]]; 1177 &cpm_uart_ports[cpm_uart_port_map[co->index]];
1178#endif
1088 unsigned int i; 1179 unsigned int i;
1089 volatile cbd_t *bdp, *bdbase; 1180 cbd_t __iomem *bdp, *bdbase;
1090 volatile unsigned char *cp; 1181 unsigned char *cp;
1091 1182
1092 /* Get the address of the host memory buffer. 1183 /* Get the address of the host memory buffer.
1093 */ 1184 */
@@ -1105,37 +1196,36 @@ static void cpm_uart_console_write(struct console *co, const char *s,
1105 * Ready indicates output is ready, and xmt is doing 1196 * Ready indicates output is ready, and xmt is doing
1106 * that, not that it is ready for us to send. 1197 * that, not that it is ready for us to send.
1107 */ 1198 */
1108 while ((bdp->cbd_sc & BD_SC_READY) != 0) 1199 while ((in_be16(&bdp->cbd_sc) & BD_SC_READY) != 0)
1109 ; 1200 ;
1110 1201
1111 /* Send the character out. 1202 /* Send the character out.
1112 * If the buffer address is in the CPM DPRAM, don't 1203 * If the buffer address is in the CPM DPRAM, don't
1113 * convert it. 1204 * convert it.
1114 */ 1205 */
1115 cp = cpm2cpu_addr(bdp->cbd_bufaddr, pinfo); 1206 cp = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo);
1116
1117 *cp = *s; 1207 *cp = *s;
1118 1208
1119 bdp->cbd_datlen = 1; 1209 out_be16(&bdp->cbd_datlen, 1);
1120 bdp->cbd_sc |= BD_SC_READY; 1210 setbits16(&bdp->cbd_sc, BD_SC_READY);
1121 1211
1122 if (bdp->cbd_sc & BD_SC_WRAP) 1212 if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP)
1123 bdp = bdbase; 1213 bdp = bdbase;
1124 else 1214 else
1125 bdp++; 1215 bdp++;
1126 1216
1127 /* if a LF, also do CR... */ 1217 /* if a LF, also do CR... */
1128 if (*s == 10) { 1218 if (*s == 10) {
1129 while ((bdp->cbd_sc & BD_SC_READY) != 0) 1219 while ((in_be16(&bdp->cbd_sc) & BD_SC_READY) != 0)
1130 ; 1220 ;
1131 1221
1132 cp = cpm2cpu_addr(bdp->cbd_bufaddr, pinfo); 1222 cp = cpm2cpu_addr(in_be32(&bdp->cbd_bufaddr), pinfo);
1133
1134 *cp = 13; 1223 *cp = 13;
1135 bdp->cbd_datlen = 1;
1136 bdp->cbd_sc |= BD_SC_READY;
1137 1224
1138 if (bdp->cbd_sc & BD_SC_WRAP) 1225 out_be16(&bdp->cbd_datlen, 1);
1226 setbits16(&bdp->cbd_sc, BD_SC_READY);
1227
1228 if (in_be16(&bdp->cbd_sc) & BD_SC_WRAP)
1139 bdp = bdbase; 1229 bdp = bdbase;
1140 else 1230 else
1141 bdp++; 1231 bdp++;
@@ -1146,22 +1236,56 @@ static void cpm_uart_console_write(struct console *co, const char *s,
1146 * Finally, Wait for transmitter & holding register to empty 1236 * Finally, Wait for transmitter & holding register to empty
1147 * and restore the IER 1237 * and restore the IER
1148 */ 1238 */
1149 while ((bdp->cbd_sc & BD_SC_READY) != 0) 1239 while ((in_be16(&bdp->cbd_sc) & BD_SC_READY) != 0)
1150 ; 1240 ;
1151 1241
1152 pinfo->tx_cur = (volatile cbd_t *) bdp; 1242 pinfo->tx_cur = bdp;
1153} 1243}
1154 1244
1155 1245
1156static int __init cpm_uart_console_setup(struct console *co, char *options) 1246static int __init cpm_uart_console_setup(struct console *co, char *options)
1157{ 1247{
1158 struct uart_port *port;
1159 struct uart_cpm_port *pinfo;
1160 int baud = 38400; 1248 int baud = 38400;
1161 int bits = 8; 1249 int bits = 8;
1162 int parity = 'n'; 1250 int parity = 'n';
1163 int flow = 'n'; 1251 int flow = 'n';
1164 int ret; 1252 int ret;
1253 struct uart_cpm_port *pinfo;
1254 struct uart_port *port;
1255
1256#ifdef CONFIG_PPC_CPM_NEW_BINDING
1257 struct device_node *np = NULL;
1258 int i = 0;
1259
1260 if (co->index >= UART_NR) {
1261 printk(KERN_ERR "cpm_uart: console index %d too high\n",
1262 co->index);
1263 return -ENODEV;
1264 }
1265
1266 do {
1267 np = of_find_node_by_type(np, "serial");
1268 if (!np)
1269 return -ENODEV;
1270
1271 if (!of_device_is_compatible(np, "fsl,cpm1-smc-uart") &&
1272 !of_device_is_compatible(np, "fsl,cpm1-scc-uart") &&
1273 !of_device_is_compatible(np, "fsl,cpm2-smc-uart") &&
1274 !of_device_is_compatible(np, "fsl,cpm2-scc-uart"))
1275 i--;
1276 } while (i++ != co->index);
1277
1278 pinfo = &cpm_uart_ports[co->index];
1279
1280 pinfo->flags |= FLAG_CONSOLE;
1281 port = &pinfo->port;
1282
1283 ret = cpm_uart_init_port(np, pinfo);
1284 of_node_put(np);
1285 if (ret)
1286 return ret;
1287
1288#else
1165 1289
1166 struct fs_uart_platform_info *pdata; 1290 struct fs_uart_platform_info *pdata;
1167 struct platform_device* pdev = early_uart_get_pdev(co->index); 1291 struct platform_device* pdev = early_uart_get_pdev(co->index);
@@ -1188,6 +1312,7 @@ static int __init cpm_uart_console_setup(struct console *co, char *options)
1188 } 1312 }
1189 1313
1190 pinfo->flags |= FLAG_CONSOLE; 1314 pinfo->flags |= FLAG_CONSOLE;
1315#endif
1191 1316
1192 if (options) { 1317 if (options) {
1193 uart_parse_options(options, &baud, &parity, &bits, &flow); 1318 uart_parse_options(options, &baud, &parity, &bits, &flow);
@@ -1196,12 +1321,18 @@ static int __init cpm_uart_console_setup(struct console *co, char *options)
1196 baud = 9600; 1321 baud = 9600;
1197 } 1322 }
1198 1323
1324#ifdef CONFIG_PPC_EARLY_DEBUG_CPM
1325 udbg_putc = NULL;
1326#endif
1327
1328 cpm_line_cr_cmd(pinfo, CPM_CR_STOP_TX);
1329
1199 if (IS_SMC(pinfo)) { 1330 if (IS_SMC(pinfo)) {
1200 pinfo->smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX); 1331 clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX | SMCM_TX);
1201 pinfo->smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN); 1332 clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN | SMCMR_TEN);
1202 } else { 1333 } else {
1203 pinfo->sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX); 1334 clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_TX | UART_SCCM_RX);
1204 pinfo->sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT); 1335 clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
1205 } 1336 }
1206 1337
1207 ret = cpm_uart_allocbuf(pinfo, 1); 1338 ret = cpm_uart_allocbuf(pinfo, 1);
@@ -1217,6 +1348,7 @@ static int __init cpm_uart_console_setup(struct console *co, char *options)
1217 cpm_uart_init_scc(pinfo); 1348 cpm_uart_init_scc(pinfo);
1218 1349
1219 uart_set_options(port, co, baud, parity, bits, flow); 1350 uart_set_options(port, co, baud, parity, bits, flow);
1351 cpm_line_cr_cmd(pinfo, CPM_CR_RESTART_TX);
1220 1352
1221 return 0; 1353 return 0;
1222} 1354}
@@ -1232,7 +1364,7 @@ static struct console cpm_scc_uart_console = {
1232 .data = &cpm_reg, 1364 .data = &cpm_reg,
1233}; 1365};
1234 1366
1235int __init cpm_uart_console_init(void) 1367static int __init cpm_uart_console_init(void)
1236{ 1368{
1237 register_console(&cpm_scc_uart_console); 1369 register_console(&cpm_scc_uart_console);
1238 return 0; 1370 return 0;
@@ -1252,7 +1384,81 @@ static struct uart_driver cpm_reg = {
1252 .major = SERIAL_CPM_MAJOR, 1384 .major = SERIAL_CPM_MAJOR,
1253 .minor = SERIAL_CPM_MINOR, 1385 .minor = SERIAL_CPM_MINOR,
1254 .cons = CPM_UART_CONSOLE, 1386 .cons = CPM_UART_CONSOLE,
1387 .nr = UART_NR,
1255}; 1388};
1389
1390#ifdef CONFIG_PPC_CPM_NEW_BINDING
1391static int probe_index;
1392
1393static int __devinit cpm_uart_probe(struct of_device *ofdev,
1394 const struct of_device_id *match)
1395{
1396 int index = probe_index++;
1397 struct uart_cpm_port *pinfo = &cpm_uart_ports[index];
1398 int ret;
1399
1400 pinfo->port.line = index;
1401
1402 if (index >= UART_NR)
1403 return -ENODEV;
1404
1405 dev_set_drvdata(&ofdev->dev, pinfo);
1406
1407 ret = cpm_uart_init_port(ofdev->node, pinfo);
1408 if (ret)
1409 return ret;
1410
1411 return uart_add_one_port(&cpm_reg, &pinfo->port);
1412}
1413
1414static int __devexit cpm_uart_remove(struct of_device *ofdev)
1415{
1416 struct uart_cpm_port *pinfo = dev_get_drvdata(&ofdev->dev);
1417 return uart_remove_one_port(&cpm_reg, &pinfo->port);
1418}
1419
1420static struct of_device_id cpm_uart_match[] = {
1421 {
1422 .compatible = "fsl,cpm1-smc-uart",
1423 },
1424 {
1425 .compatible = "fsl,cpm1-scc-uart",
1426 },
1427 {
1428 .compatible = "fsl,cpm2-smc-uart",
1429 },
1430 {
1431 .compatible = "fsl,cpm2-scc-uart",
1432 },
1433 {}
1434};
1435
1436static struct of_platform_driver cpm_uart_driver = {
1437 .name = "cpm_uart",
1438 .match_table = cpm_uart_match,
1439 .probe = cpm_uart_probe,
1440 .remove = cpm_uart_remove,
1441 };
1442
1443static int __init cpm_uart_init(void)
1444{
1445 int ret = uart_register_driver(&cpm_reg);
1446 if (ret)
1447 return ret;
1448
1449 ret = of_register_platform_driver(&cpm_uart_driver);
1450 if (ret)
1451 uart_unregister_driver(&cpm_reg);
1452
1453 return ret;
1454}
1455
1456static void __exit cpm_uart_exit(void)
1457{
1458 of_unregister_platform_driver(&cpm_uart_driver);
1459 uart_unregister_driver(&cpm_reg);
1460}
1461#else
1256static int cpm_uart_drv_probe(struct device *dev) 1462static int cpm_uart_drv_probe(struct device *dev)
1257{ 1463{
1258 struct platform_device *pdev = to_platform_device(dev); 1464 struct platform_device *pdev = to_platform_device(dev);
@@ -1380,6 +1586,7 @@ static void __exit cpm_uart_exit(void)
1380 driver_unregister(&cpm_smc_uart_driver); 1586 driver_unregister(&cpm_smc_uart_driver);
1381 uart_unregister_driver(&cpm_reg); 1587 uart_unregister_driver(&cpm_reg);
1382} 1588}
1589#endif
1383 1590
1384module_init(cpm_uart_init); 1591module_init(cpm_uart_init);
1385module_exit(cpm_uart_exit); 1592module_exit(cpm_uart_exit);
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm1.c b/drivers/serial/cpm_uart/cpm_uart_cpm1.c
index 8c6324ed0202..52fb044bb79a 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm1.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm1.c
@@ -49,9 +49,20 @@
49 49
50/**************************************************************/ 50/**************************************************************/
51 51
52void cpm_line_cr_cmd(int line, int cmd) 52#ifdef CONFIG_PPC_CPM_NEW_BINDING
53void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
54{
55 u16 __iomem *cpcr = &cpmp->cp_cpcr;
56
57 out_be16(cpcr, port->command | (cmd << 8) | CPM_CR_FLG);
58 while (in_be16(cpcr) & CPM_CR_FLG)
59 ;
60}
61#else
62void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
53{ 63{
54 ushort val; 64 ushort val;
65 int line = port - cpm_uart_ports;
55 volatile cpm8xx_t *cp = cpmp; 66 volatile cpm8xx_t *cp = cpmp;
56 67
57 switch (line) { 68 switch (line) {
@@ -114,6 +125,7 @@ void scc4_lineif(struct uart_cpm_port *pinfo)
114 /* XXX SCC4: insert port configuration here */ 125 /* XXX SCC4: insert port configuration here */
115 pinfo->brg = 4; 126 pinfo->brg = 4;
116} 127}
128#endif
117 129
118/* 130/*
119 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and 131 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
@@ -167,7 +179,7 @@ int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
167 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos 179 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
168 * pinfo->rx_fifosize); 180 * pinfo->rx_fifosize);
169 181
170 pinfo->rx_bd_base = (volatile cbd_t *)dp_mem; 182 pinfo->rx_bd_base = (cbd_t __iomem __force *)dp_mem;
171 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos; 183 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
172 184
173 return 0; 185 return 0;
@@ -184,6 +196,7 @@ void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
184 cpm_dpfree(pinfo->dp_addr); 196 cpm_dpfree(pinfo->dp_addr);
185} 197}
186 198
199#ifndef CONFIG_PPC_CPM_NEW_BINDING
187/* Setup any dynamic params in the uart desc */ 200/* Setup any dynamic params in the uart desc */
188int cpm_uart_init_portdesc(void) 201int cpm_uart_init_portdesc(void)
189{ 202{
@@ -279,3 +292,4 @@ int cpm_uart_init_portdesc(void)
279#endif 292#endif
280 return 0; 293 return 0;
281} 294}
295#endif
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm1.h b/drivers/serial/cpm_uart/cpm_uart_cpm1.h
index 2a6477834c3e..9b5465fb0bbb 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm1.h
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm1.h
@@ -13,30 +13,32 @@
13#include <asm/commproc.h> 13#include <asm/commproc.h>
14 14
15/* defines for IRQs */ 15/* defines for IRQs */
16#ifndef CONFIG_PPC_CPM_NEW_BINDING
16#define SMC1_IRQ (CPM_IRQ_OFFSET + CPMVEC_SMC1) 17#define SMC1_IRQ (CPM_IRQ_OFFSET + CPMVEC_SMC1)
17#define SMC2_IRQ (CPM_IRQ_OFFSET + CPMVEC_SMC2) 18#define SMC2_IRQ (CPM_IRQ_OFFSET + CPMVEC_SMC2)
18#define SCC1_IRQ (CPM_IRQ_OFFSET + CPMVEC_SCC1) 19#define SCC1_IRQ (CPM_IRQ_OFFSET + CPMVEC_SCC1)
19#define SCC2_IRQ (CPM_IRQ_OFFSET + CPMVEC_SCC2) 20#define SCC2_IRQ (CPM_IRQ_OFFSET + CPMVEC_SCC2)
20#define SCC3_IRQ (CPM_IRQ_OFFSET + CPMVEC_SCC3) 21#define SCC3_IRQ (CPM_IRQ_OFFSET + CPMVEC_SCC3)
21#define SCC4_IRQ (CPM_IRQ_OFFSET + CPMVEC_SCC4) 22#define SCC4_IRQ (CPM_IRQ_OFFSET + CPMVEC_SCC4)
23#endif
22 24
23static inline void cpm_set_brg(int brg, int baud) 25static inline void cpm_set_brg(int brg, int baud)
24{ 26{
25 cpm_setbrg(brg, baud); 27 cpm_setbrg(brg, baud);
26} 28}
27 29
28static inline void cpm_set_scc_fcr(volatile scc_uart_t * sup) 30static inline void cpm_set_scc_fcr(scc_uart_t __iomem * sup)
29{ 31{
30 sup->scc_genscc.scc_rfcr = SMC_EB; 32 out_8(&sup->scc_genscc.scc_rfcr, SMC_EB);
31 sup->scc_genscc.scc_tfcr = SMC_EB; 33 out_8(&sup->scc_genscc.scc_tfcr, SMC_EB);
32} 34}
33 35
34static inline void cpm_set_smc_fcr(volatile smc_uart_t * up) 36static inline void cpm_set_smc_fcr(smc_uart_t __iomem * up)
35{ 37{
36 up->smc_rfcr = SMC_EB; 38 out_8(&up->smc_rfcr, SMC_EB);
37 up->smc_tfcr = SMC_EB; 39 out_8(&up->smc_tfcr, SMC_EB);
38} 40}
39 41
40#define DPRAM_BASE ((unsigned char *)cpm_dpram_addr(0)) 42#define DPRAM_BASE ((u8 __iomem __force *)cpm_dpram_addr(0))
41 43
42#endif 44#endif
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm2.c b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
index 7b61d805ebe9..882dbc17d590 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm2.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
@@ -49,9 +49,22 @@
49 49
50/**************************************************************/ 50/**************************************************************/
51 51
52void cpm_line_cr_cmd(int line, int cmd) 52#ifdef CONFIG_PPC_CPM_NEW_BINDING
53void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
54{
55 cpm_cpm2_t __iomem *cp = cpm2_map(im_cpm);
56
57 out_be32(&cp->cp_cpcr, port->command | cmd | CPM_CR_FLG);
58 while (in_be32(&cp->cp_cpcr) & CPM_CR_FLG)
59 ;
60
61 cpm2_unmap(cp);
62}
63#else
64void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
53{ 65{
54 ulong val; 66 ulong val;
67 int line = port - cpm_uart_ports;
55 volatile cpm_cpm2_t *cp = cpm2_map(im_cpm); 68 volatile cpm_cpm2_t *cp = cpm2_map(im_cpm);
56 69
57 70
@@ -211,6 +224,7 @@ void scc4_lineif(struct uart_cpm_port *pinfo)
211 cpm2_unmap(cpmux); 224 cpm2_unmap(cpmux);
212 cpm2_unmap(io); 225 cpm2_unmap(io);
213} 226}
227#endif
214 228
215/* 229/*
216 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and 230 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
@@ -221,7 +235,7 @@ void scc4_lineif(struct uart_cpm_port *pinfo)
221int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con) 235int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
222{ 236{
223 int dpmemsz, memsz; 237 int dpmemsz, memsz;
224 u8 *dp_mem; 238 u8 __iomem *dp_mem;
225 unsigned long dp_offset; 239 unsigned long dp_offset;
226 u8 *mem_addr; 240 u8 *mem_addr;
227 dma_addr_t dma_addr = 0; 241 dma_addr_t dma_addr = 0;
@@ -264,7 +278,7 @@ int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
264 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos 278 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
265 * pinfo->rx_fifosize); 279 * pinfo->rx_fifosize);
266 280
267 pinfo->rx_bd_base = (volatile cbd_t *)dp_mem; 281 pinfo->rx_bd_base = (cbd_t __iomem *)dp_mem;
268 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos; 282 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
269 283
270 return 0; 284 return 0;
@@ -275,12 +289,13 @@ void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
275 dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos * 289 dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
276 pinfo->rx_fifosize) + 290 pinfo->rx_fifosize) +
277 L1_CACHE_ALIGN(pinfo->tx_nrfifos * 291 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
278 pinfo->tx_fifosize), pinfo->mem_addr, 292 pinfo->tx_fifosize), (void __force *)pinfo->mem_addr,
279 pinfo->dma_addr); 293 pinfo->dma_addr);
280 294
281 cpm_dpfree(pinfo->dp_addr); 295 cpm_dpfree(pinfo->dp_addr);
282} 296}
283 297
298#ifndef CONFIG_PPC_CPM_NEW_BINDING
284/* Setup any dynamic params in the uart desc */ 299/* Setup any dynamic params in the uart desc */
285int cpm_uart_init_portdesc(void) 300int cpm_uart_init_portdesc(void)
286{ 301{
@@ -386,3 +401,4 @@ int cpm_uart_init_portdesc(void)
386 401
387 return 0; 402 return 0;
388} 403}
404#endif
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm2.h b/drivers/serial/cpm_uart/cpm_uart_cpm2.h
index 1b3219f56c81..40006a7dce46 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm2.h
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm2.h
@@ -13,30 +13,32 @@
13#include <asm/cpm2.h> 13#include <asm/cpm2.h>
14 14
15/* defines for IRQs */ 15/* defines for IRQs */
16#ifndef CONFIG_PPC_CPM_NEW_BINDING
16#define SMC1_IRQ SIU_INT_SMC1 17#define SMC1_IRQ SIU_INT_SMC1
17#define SMC2_IRQ SIU_INT_SMC2 18#define SMC2_IRQ SIU_INT_SMC2
18#define SCC1_IRQ SIU_INT_SCC1 19#define SCC1_IRQ SIU_INT_SCC1
19#define SCC2_IRQ SIU_INT_SCC2 20#define SCC2_IRQ SIU_INT_SCC2
20#define SCC3_IRQ SIU_INT_SCC3 21#define SCC3_IRQ SIU_INT_SCC3
21#define SCC4_IRQ SIU_INT_SCC4 22#define SCC4_IRQ SIU_INT_SCC4
23#endif
22 24
23static inline void cpm_set_brg(int brg, int baud) 25static inline void cpm_set_brg(int brg, int baud)
24{ 26{
25 cpm_setbrg(brg, baud); 27 cpm_setbrg(brg, baud);
26} 28}
27 29
28static inline void cpm_set_scc_fcr(volatile scc_uart_t * sup) 30static inline void cpm_set_scc_fcr(scc_uart_t __iomem *sup)
29{ 31{
30 sup->scc_genscc.scc_rfcr = CPMFCR_GBL | CPMFCR_EB; 32 out_8(&sup->scc_genscc.scc_rfcr, CPMFCR_GBL | CPMFCR_EB);
31 sup->scc_genscc.scc_tfcr = CPMFCR_GBL | CPMFCR_EB; 33 out_8(&sup->scc_genscc.scc_tfcr, CPMFCR_GBL | CPMFCR_EB);
32} 34}
33 35
34static inline void cpm_set_smc_fcr(volatile smc_uart_t * up) 36static inline void cpm_set_smc_fcr(smc_uart_t __iomem *up)
35{ 37{
36 up->smc_rfcr = CPMFCR_GBL | CPMFCR_EB; 38 out_8(&up->smc_rfcr, CPMFCR_GBL | CPMFCR_EB);
37 up->smc_tfcr = CPMFCR_GBL | CPMFCR_EB; 39 out_8(&up->smc_tfcr, CPMFCR_GBL | CPMFCR_EB);
38} 40}
39 41
40#define DPRAM_BASE ((unsigned char *)cpm_dpram_addr(0)) 42#define DPRAM_BASE ((u8 __iomem __force *)cpm_dpram_addr(0))
41 43
42#endif 44#endif
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 35f8b86cc78f..035cca028199 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -1051,7 +1051,7 @@ mpc52xx_uart_of_assign(struct device_node *np, int idx)
1051 /* If the slot is already occupied, then swap slots */ 1051 /* If the slot is already occupied, then swap slots */
1052 if (mpc52xx_uart_nodes[idx] && (free_idx != -1)) 1052 if (mpc52xx_uart_nodes[idx] && (free_idx != -1))
1053 mpc52xx_uart_nodes[free_idx] = mpc52xx_uart_nodes[idx]; 1053 mpc52xx_uart_nodes[free_idx] = mpc52xx_uart_nodes[idx];
1054 mpc52xx_uart_nodes[i] = np; 1054 mpc52xx_uart_nodes[idx] = np;
1055} 1055}
1056 1056
1057static void 1057static void
diff --git a/drivers/serial/pmac_zilog.c b/drivers/serial/pmac_zilog.c
index 0fa9f6761763..794bd0f50d73 100644
--- a/drivers/serial/pmac_zilog.c
+++ b/drivers/serial/pmac_zilog.c
@@ -88,6 +88,16 @@ MODULE_LICENSE("GPL");
88 88
89#define PWRDBG(fmt, arg...) printk(KERN_DEBUG fmt , ## arg) 89#define PWRDBG(fmt, arg...) printk(KERN_DEBUG fmt , ## arg)
90 90
91#ifdef CONFIG_SERIAL_PMACZILOG_TTYS
92#define PMACZILOG_MAJOR TTY_MAJOR
93#define PMACZILOG_MINOR 64
94#define PMACZILOG_NAME "ttyS"
95#else
96#define PMACZILOG_MAJOR 204
97#define PMACZILOG_MINOR 192
98#define PMACZILOG_NAME "ttyPZ"
99#endif
100
91 101
92/* 102/*
93 * For the sake of early serial console, we can do a pre-probe 103 * For the sake of early serial console, we can do a pre-probe
@@ -99,9 +109,10 @@ static DEFINE_MUTEX(pmz_irq_mutex);
99 109
100static struct uart_driver pmz_uart_reg = { 110static struct uart_driver pmz_uart_reg = {
101 .owner = THIS_MODULE, 111 .owner = THIS_MODULE,
102 .driver_name = "ttyS", 112 .driver_name = PMACZILOG_NAME,
103 .dev_name = "ttyS", 113 .dev_name = PMACZILOG_NAME,
104 .major = TTY_MAJOR, 114 .major = PMACZILOG_MAJOR,
115 .minor = PMACZILOG_MINOR,
105}; 116};
106 117
107 118
@@ -1587,7 +1598,7 @@ static int pmz_suspend(struct macio_dev *mdev, pm_message_t pm_state)
1587 if (pm_state.event == mdev->ofdev.dev.power.power_state.event) 1598 if (pm_state.event == mdev->ofdev.dev.power.power_state.event)
1588 return 0; 1599 return 0;
1589 1600
1590 pmz_debug("suspend, switching to state %d\n", pm_state); 1601 pmz_debug("suspend, switching to state %d\n", pm_state.event);
1591 1602
1592 state = pmz_uart_reg.state + uap->port.line; 1603 state = pmz_uart_reg.state + uap->port.line;
1593 1604
@@ -1778,7 +1789,7 @@ static void pmz_console_write(struct console *con, const char *s, unsigned int c
1778static int __init pmz_console_setup(struct console *co, char *options); 1789static int __init pmz_console_setup(struct console *co, char *options);
1779 1790
1780static struct console pmz_console = { 1791static struct console pmz_console = {
1781 .name = "ttyS", 1792 .name = PMACZILOG_NAME,
1782 .write = pmz_console_write, 1793 .write = pmz_console_write,
1783 .device = uart_console_device, 1794 .device = uart_console_device,
1784 .setup = pmz_console_setup, 1795 .setup = pmz_console_setup,
@@ -1802,7 +1813,6 @@ static int __init pmz_register(void)
1802 1813
1803 pmz_uart_reg.nr = pmz_ports_count; 1814 pmz_uart_reg.nr = pmz_ports_count;
1804 pmz_uart_reg.cons = PMACZILOG_CONSOLE; 1815 pmz_uart_reg.cons = PMACZILOG_CONSOLE;
1805 pmz_uart_reg.minor = 64;
1806 1816
1807 /* 1817 /*
1808 * Register this driver with the serial core 1818 * Register this driver with the serial core
diff --git a/drivers/serial/uartlite.c b/drivers/serial/uartlite.c
index f5051cf1a0c8..dfef83f14960 100644
--- a/drivers/serial/uartlite.c
+++ b/drivers/serial/uartlite.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * uartlite.c: Serial driver for Xilinx uartlite serial controller 2 * uartlite.c: Serial driver for Xilinx uartlite serial controller
3 * 3 *
4 * Peter Korsgaard <jacmet@sunsite.dk> 4 * Copyright (C) 2006 Peter Korsgaard <jacmet@sunsite.dk>
5 * Copyright (C) 2007 Secret Lab Technologies Ltd.
5 * 6 *
6 * This file is licensed under the terms of the GNU General Public License 7 * This file is licensed under the terms of the GNU General Public License
7 * version 2. This program is licensed "as is" without any warranty of any 8 * version 2. This program is licensed "as is" without any warranty of any
@@ -17,14 +18,23 @@
17#include <linux/delay.h> 18#include <linux/delay.h>
18#include <linux/interrupt.h> 19#include <linux/interrupt.h>
19#include <asm/io.h> 20#include <asm/io.h>
21#if defined(CONFIG_OF)
22#include <linux/of_device.h>
23#include <linux/of_platform.h>
24#endif
20 25
26#define ULITE_NAME "ttyUL"
21#define ULITE_MAJOR 204 27#define ULITE_MAJOR 204
22#define ULITE_MINOR 187 28#define ULITE_MINOR 187
23#define ULITE_NR_UARTS 4 29#define ULITE_NR_UARTS 4
24 30
25/* For register details see datasheet: 31/* ---------------------------------------------------------------------
26 http://www.xilinx.com/bvdocs/ipcenter/data_sheet/opb_uartlite.pdf 32 * Register definitions
27*/ 33 *
34 * For register details see datasheet:
35 * http://www.xilinx.com/bvdocs/ipcenter/data_sheet/opb_uartlite.pdf
36 */
37
28#define ULITE_RX 0x00 38#define ULITE_RX 0x00
29#define ULITE_TX 0x04 39#define ULITE_TX 0x04
30#define ULITE_STATUS 0x08 40#define ULITE_STATUS 0x08
@@ -46,7 +56,11 @@
46#define ULITE_CONTROL_IE 0x10 56#define ULITE_CONTROL_IE 0x10
47 57
48 58
49static struct uart_port ports[ULITE_NR_UARTS]; 59static struct uart_port ulite_ports[ULITE_NR_UARTS];
60
61/* ---------------------------------------------------------------------
62 * Core UART driver operations
63 */
50 64
51static int ulite_receive(struct uart_port *port, int stat) 65static int ulite_receive(struct uart_port *port, int stat)
52{ 66{
@@ -307,6 +321,10 @@ static struct uart_ops ulite_ops = {
307 .verify_port = ulite_verify_port 321 .verify_port = ulite_verify_port
308}; 322};
309 323
324/* ---------------------------------------------------------------------
325 * Console driver operations
326 */
327
310#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE 328#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
311static void ulite_console_wait_tx(struct uart_port *port) 329static void ulite_console_wait_tx(struct uart_port *port)
312{ 330{
@@ -329,7 +347,7 @@ static void ulite_console_putchar(struct uart_port *port, int ch)
329static void ulite_console_write(struct console *co, const char *s, 347static void ulite_console_write(struct console *co, const char *s,
330 unsigned int count) 348 unsigned int count)
331{ 349{
332 struct uart_port *port = &ports[co->index]; 350 struct uart_port *port = &ulite_ports[co->index];
333 unsigned long flags; 351 unsigned long flags;
334 unsigned int ier; 352 unsigned int ier;
335 int locked = 1; 353 int locked = 1;
@@ -355,6 +373,31 @@ static void ulite_console_write(struct console *co, const char *s,
355 spin_unlock_irqrestore(&port->lock, flags); 373 spin_unlock_irqrestore(&port->lock, flags);
356} 374}
357 375
376#if defined(CONFIG_OF)
377static inline void __init ulite_console_of_find_device(int id)
378{
379 struct device_node *np;
380 struct resource res;
381 const unsigned int *of_id;
382 int rc;
383
384 for_each_compatible_node(np, NULL, "xilinx,uartlite") {
385 of_id = of_get_property(np, "port-number", NULL);
386 if ((!of_id) || (*of_id != id))
387 continue;
388
389 rc = of_address_to_resource(np, 0, &res);
390 if (rc)
391 continue;
392
393 ulite_ports[id].mapbase = res.start;
394 return;
395 }
396}
397#else /* CONFIG_OF */
398static inline void __init ulite_console_of_find_device(int id) { /* do nothing */ }
399#endif /* CONFIG_OF */
400
358static int __init ulite_console_setup(struct console *co, char *options) 401static int __init ulite_console_setup(struct console *co, char *options)
359{ 402{
360 struct uart_port *port; 403 struct uart_port *port;
@@ -366,11 +409,23 @@ static int __init ulite_console_setup(struct console *co, char *options)
366 if (co->index < 0 || co->index >= ULITE_NR_UARTS) 409 if (co->index < 0 || co->index >= ULITE_NR_UARTS)
367 return -EINVAL; 410 return -EINVAL;
368 411
369 port = &ports[co->index]; 412 port = &ulite_ports[co->index];
370 413
371 /* not initialized yet? */ 414 /* Check if it is an OF device */
372 if (!port->membase) 415 if (!port->mapbase)
416 ulite_console_of_find_device(co->index);
417
418 /* Do we have a device now? */
419 if (!port->mapbase) {
420 pr_debug("console on ttyUL%i not present\n", co->index);
373 return -ENODEV; 421 return -ENODEV;
422 }
423
424 /* not initialized yet? */
425 if (!port->membase) {
426 if (ulite_request_port(port))
427 return -ENODEV;
428 }
374 429
375 if (options) 430 if (options)
376 uart_parse_options(options, &baud, &parity, &bits, &flow); 431 uart_parse_options(options, &baud, &parity, &bits, &flow);
@@ -381,7 +436,7 @@ static int __init ulite_console_setup(struct console *co, char *options)
381static struct uart_driver ulite_uart_driver; 436static struct uart_driver ulite_uart_driver;
382 437
383static struct console ulite_console = { 438static struct console ulite_console = {
384 .name = "ttyUL", 439 .name = ULITE_NAME,
385 .write = ulite_console_write, 440 .write = ulite_console_write,
386 .device = uart_console_device, 441 .device = uart_console_device,
387 .setup = ulite_console_setup, 442 .setup = ulite_console_setup,
@@ -403,7 +458,7 @@ console_initcall(ulite_console_init);
403static struct uart_driver ulite_uart_driver = { 458static struct uart_driver ulite_uart_driver = {
404 .owner = THIS_MODULE, 459 .owner = THIS_MODULE,
405 .driver_name = "uartlite", 460 .driver_name = "uartlite",
406 .dev_name = "ttyUL", 461 .dev_name = ULITE_NAME,
407 .major = ULITE_MAJOR, 462 .major = ULITE_MAJOR,
408 .minor = ULITE_MINOR, 463 .minor = ULITE_MINOR,
409 .nr = ULITE_NR_UARTS, 464 .nr = ULITE_NR_UARTS,
@@ -412,59 +467,111 @@ static struct uart_driver ulite_uart_driver = {
412#endif 467#endif
413}; 468};
414 469
415static int __devinit ulite_probe(struct platform_device *pdev) 470/* ---------------------------------------------------------------------
471 * Port assignment functions (mapping devices to uart_port structures)
472 */
473
474/** ulite_assign: register a uartlite device with the driver
475 *
476 * @dev: pointer to device structure
477 * @id: requested id number. Pass -1 for automatic port assignment
478 * @base: base address of uartlite registers
479 * @irq: irq number for uartlite
480 *
481 * Returns: 0 on success, <0 otherwise
482 */
483static int __devinit ulite_assign(struct device *dev, int id, u32 base, int irq)
416{ 484{
417 struct resource *res, *res2;
418 struct uart_port *port; 485 struct uart_port *port;
486 int rc;
419 487
420 if (pdev->id < 0 || pdev->id >= ULITE_NR_UARTS) 488 /* if id = -1; then scan for a free id and use that */
489 if (id < 0) {
490 for (id = 0; id < ULITE_NR_UARTS; id++)
491 if (ulite_ports[id].mapbase == 0)
492 break;
493 }
494 if (id < 0 || id >= ULITE_NR_UARTS) {
495 dev_err(dev, "%s%i too large\n", ULITE_NAME, id);
421 return -EINVAL; 496 return -EINVAL;
497 }
422 498
423 if (ports[pdev->id].membase) 499 if ((ulite_ports[id].mapbase) && (ulite_ports[id].mapbase != base)) {
500 dev_err(dev, "cannot assign to %s%i; it is already in use\n",
501 ULITE_NAME, id);
424 return -EBUSY; 502 return -EBUSY;
503 }
425 504
426 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 505 port = &ulite_ports[id];
427 if (!res)
428 return -ENODEV;
429 506
430 res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 507 spin_lock_init(&port->lock);
431 if (!res2) 508 port->fifosize = 16;
432 return -ENODEV; 509 port->regshift = 2;
510 port->iotype = UPIO_MEM;
511 port->iobase = 1; /* mark port in use */
512 port->mapbase = base;
513 port->membase = NULL;
514 port->ops = &ulite_ops;
515 port->irq = irq;
516 port->flags = UPF_BOOT_AUTOCONF;
517 port->dev = dev;
518 port->type = PORT_UNKNOWN;
519 port->line = id;
520
521 dev_set_drvdata(dev, port);
522
523 /* Register the port */
524 rc = uart_add_one_port(&ulite_uart_driver, port);
525 if (rc) {
526 dev_err(dev, "uart_add_one_port() failed; err=%i\n", rc);
527 port->mapbase = 0;
528 dev_set_drvdata(dev, NULL);
529 return rc;
530 }
433 531
434 port = &ports[pdev->id]; 532 return 0;
533}
435 534
436 port->fifosize = 16; 535/** ulite_release: register a uartlite device with the driver
437 port->regshift = 2; 536 *
438 port->iotype = UPIO_MEM; 537 * @dev: pointer to device structure
439 port->iobase = 1; /* mark port in use */ 538 */
440 port->mapbase = res->start; 539static int __devinit ulite_release(struct device *dev)
441 port->membase = NULL; 540{
442 port->ops = &ulite_ops; 541 struct uart_port *port = dev_get_drvdata(dev);
443 port->irq = res2->start; 542 int rc = 0;
444 port->flags = UPF_BOOT_AUTOCONF;
445 port->dev = &pdev->dev;
446 port->type = PORT_UNKNOWN;
447 port->line = pdev->id;
448 543
449 uart_add_one_port(&ulite_uart_driver, port); 544 if (port) {
450 platform_set_drvdata(pdev, port); 545 rc = uart_remove_one_port(&ulite_uart_driver, port);
546 dev_set_drvdata(dev, NULL);
547 port->mapbase = 0;
548 }
451 549
452 return 0; 550 return rc;
453} 551}
454 552
455static int ulite_remove(struct platform_device *pdev) 553/* ---------------------------------------------------------------------
554 * Platform bus binding
555 */
556
557static int __devinit ulite_probe(struct platform_device *pdev)
456{ 558{
457 struct uart_port *port = platform_get_drvdata(pdev); 559 struct resource *res, *res2;
458 560
459 platform_set_drvdata(pdev, NULL); 561 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
562 if (!res)
563 return -ENODEV;
460 564
461 if (port) 565 res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
462 uart_remove_one_port(&ulite_uart_driver, port); 566 if (!res2)
567 return -ENODEV;
463 568
464 /* mark port as free */ 569 return ulite_assign(&pdev->dev, pdev->id, res->start, res2->start);
465 port->membase = NULL; 570}
466 571
467 return 0; 572static int ulite_remove(struct platform_device *pdev)
573{
574 return ulite_release(&pdev->dev);
468} 575}
469 576
470static struct platform_driver ulite_platform_driver = { 577static struct platform_driver ulite_platform_driver = {
@@ -476,24 +583,109 @@ static struct platform_driver ulite_platform_driver = {
476 }, 583 },
477}; 584};
478 585
586/* ---------------------------------------------------------------------
587 * OF bus bindings
588 */
589#if defined(CONFIG_OF)
590static int __devinit
591ulite_of_probe(struct of_device *op, const struct of_device_id *match)
592{
593 struct resource res;
594 const unsigned int *id;
595 int irq, rc;
596
597 dev_dbg(&op->dev, "%s(%p, %p)\n", __FUNCTION__, op, match);
598
599 rc = of_address_to_resource(op->node, 0, &res);
600 if (rc) {
601 dev_err(&op->dev, "invalid address\n");
602 return rc;
603 }
604
605 irq = irq_of_parse_and_map(op->node, 0);
606
607 id = of_get_property(op->node, "port-number", NULL);
608
609 return ulite_assign(&op->dev, id ? *id : -1, res.start+3, irq);
610}
611
612static int __devexit ulite_of_remove(struct of_device *op)
613{
614 return ulite_release(&op->dev);
615}
616
617/* Match table for of_platform binding */
618static struct of_device_id __devinit ulite_of_match[] = {
619 { .type = "serial", .compatible = "xilinx,uartlite", },
620 {},
621};
622MODULE_DEVICE_TABLE(of, ulite_of_match);
623
624static struct of_platform_driver ulite_of_driver = {
625 .owner = THIS_MODULE,
626 .name = "uartlite",
627 .match_table = ulite_of_match,
628 .probe = ulite_of_probe,
629 .remove = __devexit_p(ulite_of_remove),
630 .driver = {
631 .name = "uartlite",
632 },
633};
634
635/* Registration helpers to keep the number of #ifdefs to a minimum */
636static inline int __init ulite_of_register(void)
637{
638 pr_debug("uartlite: calling of_register_platform_driver()\n");
639 return of_register_platform_driver(&ulite_of_driver);
640}
641
642static inline void __exit ulite_of_unregister(void)
643{
644 of_unregister_platform_driver(&ulite_of_driver);
645}
646#else /* CONFIG_OF */
647/* CONFIG_OF not enabled; do nothing helpers */
648static inline int __init ulite_of_register(void) { return 0; }
649static inline void __exit ulite_of_unregister(void) { }
650#endif /* CONFIG_OF */
651
652/* ---------------------------------------------------------------------
653 * Module setup/teardown
654 */
655
479int __init ulite_init(void) 656int __init ulite_init(void)
480{ 657{
481 int ret; 658 int ret;
482 659
660 pr_debug("uartlite: calling uart_register_driver()\n");
483 ret = uart_register_driver(&ulite_uart_driver); 661 ret = uart_register_driver(&ulite_uart_driver);
484 if (ret) 662 if (ret)
485 return ret; 663 goto err_uart;
486 664
665 ret = ulite_of_register();
666 if (ret)
667 goto err_of;
668
669 pr_debug("uartlite: calling platform_driver_register()\n");
487 ret = platform_driver_register(&ulite_platform_driver); 670 ret = platform_driver_register(&ulite_platform_driver);
488 if (ret) 671 if (ret)
489 uart_unregister_driver(&ulite_uart_driver); 672 goto err_plat;
490 673
674 return 0;
675
676err_plat:
677 ulite_of_unregister();
678err_of:
679 uart_unregister_driver(&ulite_uart_driver);
680err_uart:
681 printk(KERN_ERR "registering uartlite driver failed: err=%i", ret);
491 return ret; 682 return ret;
492} 683}
493 684
494void __exit ulite_exit(void) 685void __exit ulite_exit(void)
495{ 686{
496 platform_driver_unregister(&ulite_platform_driver); 687 platform_driver_unregister(&ulite_platform_driver);
688 ulite_of_unregister();
497 uart_unregister_driver(&ulite_uart_driver); 689 uart_unregister_driver(&ulite_uart_driver);
498} 690}
499 691