powerpc: Move CPM command handling into the cpm drivers
Subsystems (2)
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.
---
arch/powerpc/sysdev/commproc.c | 27 +++++++++++++++++++++++++++ arch/powerpc/sysdev/cpm2_common.c | 24 ++++++++++++++++++++++++ drivers/net/fs_enet/mac-fcc.c | 10 +--------- drivers/net/fs_enet/mac-scc.c | 11 +---------- drivers/serial/cpm_uart/cpm_uart_cpm1.c | 6 +----- drivers/serial/cpm_uart/cpm_uart_cpm2.c | 8 +------- include/asm-powerpc/cpm.h | 1 + 7 files changed, 56 insertions(+), 31 deletions(-)
arch/powerpc/sysdev/commproc.c +0 -0
@@ -240,6 +240,33 @@ void __init cpm_reset(void)
#endif
}
+DEFINE_SPINLOCK(cmd_lock);
+
+#define MAX_CR_CMD_LOOPS 10000
+
+int cpm_command(u32 command, u8 opcode)
+{
+ int i;
+ unsigned long flags;
+
+ if (command & 0xffffff0f)
+ return -EINVAL;
+
+ spin_lock_irqsave(&cmd_lock, flags);
+
+ 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) {
+ spin_unlock_irqrestore(&cmd_lock, flags);
+ return 0;
+ }
+
+ printk(KERN_ERR "%s(): Not able to issue CPM command\n", __FUNCTION__);
+ spin_unlock_irqrestore(&cmd_lock, flags);
+ return -EIO;
+}
+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.
*/
arch/powerpc/sysdev/cpm2_common.c +0 -0
@@ -83,6 +83,30 @@ cpm2_reset(void)
cpmp = &cpm2_immr->im_cpm; }
+DEFINE_SPINLOCK(cmd_lock);
+
+#define MAX_CR_CMD_LOOPS 10000
+
+int cpm_command(u32 command, u8 opcode)
+{
+ int i;
+ unsigned long flags;
+
+ spin_lock_irqsave(&cmd_lock, flags);
+
+ 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) {
+ spin_unlock_irqrestore(&cmd_lock, flags);
+ return 0;
+ }
+
+ printk(KERN_ERR "%s(): Not able to issue CPM command\n", __FUNCTION__);
+ spin_unlock_irqrestore(&cmd_lock, flags);
+ return -EIO;
+}
+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
drivers/net/fs_enet/mac-fcc.c +0 -0
@@ -81,16 +81,8 @@
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)
drivers/net/fs_enet/mac-scc.c +0 -0
@@ -89,21 +89,12 @@* 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)
drivers/serial/cpm_uart/cpm_uart_cpm1.c +0 -0
@@ -52,11 +52,7 @@
#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)
drivers/serial/cpm_uart/cpm_uart_cpm2.c +0 -0
@@ -52,13 +52,7 @@
#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)
include/asm-powerpc/cpm.h +0 -0
@@ -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
Signature · 1 line
1.5.3.5
Quoted 3 lines · Jochen Friedrich
This patch moves the CPM command handling into
commproc.cfor CPM1 andcpm2_common.c. This is yet another preparation to get rid of drivers accessing the CPM via the global cpmp.
good stuff, just a little nitpicking below:
Quoted 1 line
+DEFINE_SPINLOCK(cmd_lock);
This should probably be a static variable. The name is too generic for a global identifier. If every use of the command register goes through the cpm_command function, you could even make it a static variable in that function.
Quoted 6 lines
(quoted diff) +6
-0+int cpm_command(u32 command, u8 opcode) +{ + int i; + unsigned long flags; + + if (command & 0xffffff0f)
Review
Quoted 10 lines
(quoted diff) +10
-0+ return -EINVAL; + + spin_lock_irqsave(&cmd_lock, flags); + + 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) { + spin_unlock_irqrestore(&cmd_lock, flags); + return 0; + }
Error handling in here is nicer if you do a goto that jumps to the unlock below. If the code ever gets more complex, this makes it easier to check if it's correct regarding locking.
Review
Quoted 5 lines
(quoted diff) +5
-0+ printk(KERN_ERR "%s(): Not able to issue CPM command\n", __FUNCTION__); + spin_unlock_irqrestore(&cmd_lock, flags); + return -EIO; +} +EXPORT_SYMBOL(cpm_command);
Why not EXPORT_SYMBOL_GPL?
Quoted 1 line
+DEFINE_SPINLOCK(cmd_lock);
see above
Quoted 12 lines
(quoted diff) +12
-0+ +#define MAX_CR_CMD_LOOPS 10000 + +int cpm_command(u32 command, u8 opcode) +{ + int i; + unsigned long flags; + + spin_lock_irqsave(&cmd_lock, flags); + + out_be32(&cpmp->cp_cpcr, command | opcode | CPM_CR_FLG); + for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
Review
Quoted 10 lines
(quoted diff) +10
-0+ if ((in_be32(&cpmp->cp_cpcr) & CPM_CR_FLG) == 0) { + spin_unlock_irqrestore(&cmd_lock, flags); + return 0; + } + + printk(KERN_ERR "%s(): Not able to issue CPM command\n", __FUNCTION__); + spin_unlock_irqrestore(&cmd_lock, flags); + return -EIO; +} +EXPORT_SYMBOL(cpm_command);
see above
Arnd <><