]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
[POWERPC] Move CPM command handling into the cpm drivers
authorJochen Friedrich <jochen@scram.de>
Mon, 26 Nov 2007 17:03:40 +0000 (18:03 +0100)
committerKumar Gala <galak@kernel.crashing.org>
Fri, 14 Dec 2007 04:47:16 +0000 (22:47 -0600)
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>
arch/powerpc/sysdev/commproc.c
arch/powerpc/sysdev/cpm2_common.c
drivers/net/fs_enet/mac-fcc.c
drivers/net/fs_enet/mac-scc.c
drivers/serial/cpm_uart/cpm_uart_cpm1.c
drivers/serial/cpm_uart/cpm_uart_cpm2.c
include/asm-powerpc/cpm.h

index 74d9372493489d280a3b7c8ef19f44c7e69ab91b..621bc6c1d4083601dcbfc24ebefdddb8c8e519f0 100644 (file)
@@ -240,6 +240,34 @@ void __init cpm_reset(void)
 #endif
 }
 
+static DEFINE_SPINLOCK(cmd_lock);
+
+#define MAX_CR_CMD_LOOPS        10000
+
+int cpm_command(u32 command, u8 opcode)
+{
+       int i, ret;
+       unsigned long flags;
+
+       if (command & 0xffffff0f)
+               return -EINVAL;
+
+       spin_lock_irqsave(&cmd_lock, flags);
+
+       ret = 0;
+       out_be16(&cpmp->cp_cpcr, command | CPM_CR_FLG | (opcode << 8));
+       for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
+               if ((in_be16(&cpmp->cp_cpcr) & CPM_CR_FLG) == 0)
+                       goto out;
+
+       printk(KERN_ERR "%s(): Not able to issue CPM command\n", __FUNCTION__);
+       ret = -EIO;
+out:
+       spin_unlock_irqrestore(&cmd_lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL(cpm_command);
+
 /* We used to do this earlier, but have to postpone as long as possible
  * to ensure the kernel VM is now running.
  */
index 859362fecb7c659a6e546ef92dc5610b843109ea..0a7054579d9892c92db58cd1422c927bcb81ba63 100644 (file)
@@ -83,6 +83,31 @@ cpm2_reset(void)
        cpmp = &cpm2_immr->im_cpm;
 }
 
+static DEFINE_SPINLOCK(cmd_lock);
+
+#define MAX_CR_CMD_LOOPS        10000
+
+int cpm_command(u32 command, u8 opcode)
+{
+       int i, ret;
+       unsigned long flags;
+
+       spin_lock_irqsave(&cmd_lock, flags);
+
+       ret = 0;
+       out_be32(&cpmp->cp_cpcr, command | opcode | CPM_CR_FLG);
+       for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
+               if ((in_be32(&cpmp->cp_cpcr) & CPM_CR_FLG) == 0)
+                       goto out;
+
+       printk(KERN_ERR "%s(): Not able to issue CPM command\n", __FUNCTION__);
+       ret = -EIO;
+out:
+       spin_unlock_irqrestore(&cmd_lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL(cpm_command);
+
 /* Set a baud rate generator.  This needs lots of work.  There are
  * eight BRGs, which can be connected to the CPM channels or output
  * as clocks.  The BRGs are in two different block of internal
index da4efbca646e3b666fa7e9b2c947e2a8a66ab761..e36321152d504cf0f9a23b880f07e6afbba5b565 100644 (file)
 static inline int fcc_cr_cmd(struct fs_enet_private *fep, u32 op)
 {
        const struct fs_platform_info *fpi = fep->fpi;
-       int i;
-
-       W32(cpmp, cp_cpcr, fpi->cp_command | op | CPM_CR_FLG);
-       for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
-               if ((R32(cpmp, cp_cpcr) & CPM_CR_FLG) == 0)
-                       return 0;
 
-       printk(KERN_ERR "%s(): Not able to issue CPM command\n",
-              __FUNCTION__);
-       return 1;
+       return cpm_command(fpi->cp_command, op);
 }
 
 static int do_pd_setup(struct fs_enet_private *fep)
index 03134f47a4eb602489f3ca2c10f4ebcbe8076bd6..5ff856d7590bf9eaaf31c340cdcd5cd707308b85 100644 (file)
  * Delay to wait for SCC reset command to complete (in us)
  */
 #define SCC_RESET_DELAY                50
-#define MAX_CR_CMD_LOOPS       10000
 
 static inline int scc_cr_cmd(struct fs_enet_private *fep, u32 op)
 {
        const struct fs_platform_info *fpi = fep->fpi;
-       int i;
-
-       W16(cpmp, cp_cpcr, fpi->cp_command | CPM_CR_FLG | (op << 8));
-       for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
-               if ((R16(cpmp, cp_cpcr) & CPM_CR_FLG) == 0)
-                       return 0;
 
-       printk(KERN_ERR "%s(): Not able to issue CPM command\n",
-               __FUNCTION__);
-       return 1;
+       return cpm_command(fpi->cp_command, op);
 }
 
 static int do_pd_setup(struct fs_enet_private *fep)
index 52fb044bb79a917333788d033217016fefce868f..6ea0366e26ae68ab52f05c915c53058e4817942f 100644 (file)
 #ifdef CONFIG_PPC_CPM_NEW_BINDING
 void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
 {
-       u16 __iomem *cpcr = &cpmp->cp_cpcr;
-
-       out_be16(cpcr, port->command | (cmd << 8) | CPM_CR_FLG);
-       while (in_be16(cpcr) & CPM_CR_FLG)
-               ;
+       cpm_command(port->command, cmd);
 }
 #else
 void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
index 882dbc17d590bc700e5c6d8af6fa086314197924..def01582de5ccd6c121f6906ebd262de5a66c5df 100644 (file)
 #ifdef CONFIG_PPC_CPM_NEW_BINDING
 void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
 {
-       cpm_cpm2_t __iomem *cp = cpm2_map(im_cpm);
-
-       out_be32(&cp->cp_cpcr, port->command | cmd | CPM_CR_FLG);
-       while (in_be32(&cp->cp_cpcr) & CPM_CR_FLG)
-               ;
-
-       cpm2_unmap(cp);
+       cpm_command(port->command, cmd);
 }
 #else
 void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
index 48df9f330e76a57d0a4608ec53e1c203b5356a92..fae83b137337287f675a2ad94c629ec05968410b 100644 (file)
@@ -10,5 +10,6 @@ int cpm_muram_free(unsigned long offset);
 unsigned long cpm_muram_alloc_fixed(unsigned long offset, unsigned long size);
 void __iomem *cpm_muram_addr(unsigned long offset);
 dma_addr_t cpm_muram_dma(void __iomem *addr);
+int cpm_command(u32 command, u8 opcode);
 
 #endif