aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJochen Friedrich <jochen@scram.de>2007-11-26 12:03:40 -0500
committerKumar Gala <galak@kernel.crashing.org>2007-12-13 23:47:16 -0500
commit362f9b6fa8c9670cc5496390845021c2865d049b (patch)
treeea6a97b113aa8382aeddbcfa4faf2524bd2d96dc
parent721c0c8af1a27941a34af5046aae4a8369c8404c (diff)
[POWERPC] Move CPM command handling into the cpm drivers
This patch moves the CPM command handling into commproc.c for CPM1 and cpm2_common.c. This is yet another preparation to get rid of drivers accessing the CPM via the global cpmp. Signed-off-by: Jochen Friedrich <jochen@scram.de> Acked-by: Scott Wood <scottwood@freescale.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Vitaly Bordug <vitb@kernel.crashing.org>
-rw-r--r--arch/powerpc/sysdev/commproc.c28
-rw-r--r--arch/powerpc/sysdev/cpm2_common.c25
-rw-r--r--drivers/net/fs_enet/mac-fcc.c10
-rw-r--r--drivers/net/fs_enet/mac-scc.c11
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm1.c6
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm2.c8
-rw-r--r--include/asm-powerpc/cpm.h1
7 files changed, 58 insertions, 31 deletions
diff --git a/arch/powerpc/sysdev/commproc.c b/arch/powerpc/sysdev/commproc.c
index 74d937249348..621bc6c1d408 100644
--- a/arch/powerpc/sysdev/commproc.c
+++ b/arch/powerpc/sysdev/commproc.c
@@ -240,6 +240,34 @@ void __init cpm_reset(void)
240#endif 240#endif
241} 241}
242 242
243static DEFINE_SPINLOCK(cmd_lock);
244
245#define MAX_CR_CMD_LOOPS 10000
246
247int cpm_command(u32 command, u8 opcode)
248{
249 int i, ret;
250 unsigned long flags;
251
252 if (command & 0xffffff0f)
253 return -EINVAL;
254
255 spin_lock_irqsave(&cmd_lock, flags);
256
257 ret = 0;
258 out_be16(&cpmp->cp_cpcr, command | CPM_CR_FLG | (opcode << 8));
259 for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
260 if ((in_be16(&cpmp->cp_cpcr) & CPM_CR_FLG) == 0)
261 goto out;
262
263 printk(KERN_ERR "%s(): Not able to issue CPM command\n", __FUNCTION__);
264 ret = -EIO;
265out:
266 spin_unlock_irqrestore(&cmd_lock, flags);
267 return ret;
268}
269EXPORT_SYMBOL(cpm_command);
270
243/* We used to do this earlier, but have to postpone as long as possible 271/* We used to do this earlier, but have to postpone as long as possible
244 * to ensure the kernel VM is now running. 272 * to ensure the kernel VM is now running.
245 */ 273 */
diff --git a/arch/powerpc/sysdev/cpm2_common.c b/arch/powerpc/sysdev/cpm2_common.c
index 859362fecb7c..0a7054579d98 100644
--- a/arch/powerpc/sysdev/cpm2_common.c
+++ b/arch/powerpc/sysdev/cpm2_common.c
@@ -83,6 +83,31 @@ cpm2_reset(void)
83 cpmp = &cpm2_immr->im_cpm; 83 cpmp = &cpm2_immr->im_cpm;
84} 84}
85 85
86static DEFINE_SPINLOCK(cmd_lock);
87
88#define MAX_CR_CMD_LOOPS 10000
89
90int cpm_command(u32 command, u8 opcode)
91{
92 int i, ret;
93 unsigned long flags;
94
95 spin_lock_irqsave(&cmd_lock, flags);
96
97 ret = 0;
98 out_be32(&cpmp->cp_cpcr, command | opcode | CPM_CR_FLG);
99 for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
100 if ((in_be32(&cpmp->cp_cpcr) & CPM_CR_FLG) == 0)
101 goto out;
102
103 printk(KERN_ERR "%s(): Not able to issue CPM command\n", __FUNCTION__);
104 ret = -EIO;
105out:
106 spin_unlock_irqrestore(&cmd_lock, flags);
107 return ret;
108}
109EXPORT_SYMBOL(cpm_command);
110
86/* Set a baud rate generator. This needs lots of work. There are 111/* Set a baud rate generator. This needs lots of work. There are
87 * eight BRGs, which can be connected to the CPM channels or output 112 * eight BRGs, which can be connected to the CPM channels or output
88 * as clocks. The BRGs are in two different block of internal 113 * as clocks. The BRGs are in two different block of internal
diff --git a/drivers/net/fs_enet/mac-fcc.c b/drivers/net/fs_enet/mac-fcc.c
index da4efbca646e..e36321152d50 100644
--- a/drivers/net/fs_enet/mac-fcc.c
+++ b/drivers/net/fs_enet/mac-fcc.c
@@ -81,16 +81,8 @@
81static inline int fcc_cr_cmd(struct fs_enet_private *fep, u32 op) 81static inline int fcc_cr_cmd(struct fs_enet_private *fep, u32 op)
82{ 82{
83 const struct fs_platform_info *fpi = fep->fpi; 83 const struct fs_platform_info *fpi = fep->fpi;
84 int i;
85
86 W32(cpmp, cp_cpcr, fpi->cp_command | op | CPM_CR_FLG);
87 for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
88 if ((R32(cpmp, cp_cpcr) & CPM_CR_FLG) == 0)
89 return 0;
90 84
91 printk(KERN_ERR "%s(): Not able to issue CPM command\n", 85 return cpm_command(fpi->cp_command, op);
92 __FUNCTION__);
93 return 1;
94} 86}
95 87
96static int do_pd_setup(struct fs_enet_private *fep) 88static int do_pd_setup(struct fs_enet_private *fep)
diff --git a/drivers/net/fs_enet/mac-scc.c b/drivers/net/fs_enet/mac-scc.c
index 03134f47a4eb..5ff856d7590b 100644
--- a/drivers/net/fs_enet/mac-scc.c
+++ b/drivers/net/fs_enet/mac-scc.c
@@ -89,21 +89,12 @@
89 * Delay to wait for SCC reset command to complete (in us) 89 * Delay to wait for SCC reset command to complete (in us)
90 */ 90 */
91#define SCC_RESET_DELAY 50 91#define SCC_RESET_DELAY 50
92#define MAX_CR_CMD_LOOPS 10000
93 92
94static inline int scc_cr_cmd(struct fs_enet_private *fep, u32 op) 93static inline int scc_cr_cmd(struct fs_enet_private *fep, u32 op)
95{ 94{
96 const struct fs_platform_info *fpi = fep->fpi; 95 const struct fs_platform_info *fpi = fep->fpi;
97 int i;
98
99 W16(cpmp, cp_cpcr, fpi->cp_command | CPM_CR_FLG | (op << 8));
100 for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
101 if ((R16(cpmp, cp_cpcr) & CPM_CR_FLG) == 0)
102 return 0;
103 96
104 printk(KERN_ERR "%s(): Not able to issue CPM command\n", 97 return cpm_command(fpi->cp_command, op);
105 __FUNCTION__);
106 return 1;
107} 98}
108 99
109static int do_pd_setup(struct fs_enet_private *fep) 100static int do_pd_setup(struct fs_enet_private *fep)
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm1.c b/drivers/serial/cpm_uart/cpm_uart_cpm1.c
index 52fb044bb79a..6ea0366e26ae 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm1.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm1.c
@@ -52,11 +52,7 @@
52#ifdef CONFIG_PPC_CPM_NEW_BINDING 52#ifdef CONFIG_PPC_CPM_NEW_BINDING
53void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd) 53void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
54{ 54{
55 u16 __iomem *cpcr = &cpmp->cp_cpcr; 55 cpm_command(port->command, cmd);
56
57 out_be16(cpcr, port->command | (cmd << 8) | CPM_CR_FLG);
58 while (in_be16(cpcr) & CPM_CR_FLG)
59 ;
60} 56}
61#else 57#else
62void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd) 58void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm2.c b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
index 882dbc17d590..def01582de5c 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm2.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
@@ -52,13 +52,7 @@
52#ifdef CONFIG_PPC_CPM_NEW_BINDING 52#ifdef CONFIG_PPC_CPM_NEW_BINDING
53void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd) 53void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
54{ 54{
55 cpm_cpm2_t __iomem *cp = cpm2_map(im_cpm); 55 cpm_command(port->command, cmd);
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} 56}
63#else 57#else
64void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd) 58void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
diff --git a/include/asm-powerpc/cpm.h b/include/asm-powerpc/cpm.h
index 48df9f330e76..fae83b137337 100644
--- a/include/asm-powerpc/cpm.h
+++ b/include/asm-powerpc/cpm.h
@@ -10,5 +10,6 @@ int cpm_muram_free(unsigned long offset);
10unsigned long cpm_muram_alloc_fixed(unsigned long offset, unsigned long size); 10unsigned long cpm_muram_alloc_fixed(unsigned long offset, unsigned long size);
11void __iomem *cpm_muram_addr(unsigned long offset); 11void __iomem *cpm_muram_addr(unsigned long offset);
12dma_addr_t cpm_muram_dma(void __iomem *addr); 12dma_addr_t cpm_muram_dma(void __iomem *addr);
13int cpm_command(u32 command, u8 opcode);
13 14
14#endif 15#endif