Subject: Re: [RFC/Patch] ppc4xx_pm.c

From: akuster <[email-masked]>
Date: Fri, 26 Jul 2002 16:35:16 -0700

akuster wrote:
>
> I am in the process of fixing the init of the pm for 4xx in ppc4xx_pm.c
> so that it can be used and I and others have discussed having the
> drivers enable/disable their own power managment bits at init & exit times.
>

>
> 2) update ocp drivers to enable/disable their pm settings and remove
> their enable bits from the default bitmap in the core headers.

Here are the ocp driver changes to help support enabling/disabling the
device clock.  currently these wount work on the 440 until a soon to
follow on 440 patch is checked in

armin

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux 2.4 for PowerPC development tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.1096  -> 1.1097
#	drivers/net/ibm_ocp/ibm_ocp_enet.c	1.53    -> 1.54
#	drivers/net/ibm_ocp/ibm_ocp_enet.h	1.29    -> 1.30
#	drivers/i2c/i2c-adap-ibm_ocp.c	1.9     -> 1.10
#	drivers/char/ibm_ocp_gpio.c	1.13    -> 1.14
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/07/26	[email-masked]	1.1097
# udated drivers for CPM support
# --------------------------------------------
#
diff -Nru a/drivers/char/ibm_ocp_gpio.c b/drivers/char/ibm_ocp_gpio.c
--- a/drivers/char/ibm_ocp_gpio.c	Fri Jul 26 10:04:10 2002
+++ b/drivers/char/ibm_ocp_gpio.c	Fri Jul 26 10:04:10 2002
@@ -58,9 +58,12 @@
  *	an accessible area.  Add ioctl to configure
  *	multiplexed GPIO pins.
  *
+ *	1.7 07/25/02 - Armin
+ *	added CPM to enable/disable in init/exit
+ *
  */

-#define VUFX "06.04.02"
+#define VUFX "07.25.02"

 #include <linux/module.h>
 #include <linux/config.h>
@@ -283,7 +286,7 @@
 			return -EFAULT;

 		return ibm_gpio_config(ioctl_data.device,
-					 ioctl_data.mask, ioctl_data.data);
+				       ioctl_data.mask, ioctl_data.data);

 		break;

@@ -322,7 +325,12 @@
 			ibm_gpio_miscdev.fops = &ibm_gpio_fops;
 			misc_register(&ibm_gpio_miscdev);	/*ibm_gpio_miscdev); */

-			gpiop = (struct gpio_regs *)ioremap(gpio_dev->paddr, sizeof(struct gpio_regs));
+			gpiop =
+			    (struct gpio_regs *) ioremap(gpio_dev->paddr,
+							 sizeof (struct
+								 gpio_regs));
+			mtdcr(DCRN_CPMFR,
+			      mfdcr(DCRN_CPMFR) & ~ocp_get_pm(GPIO, curr_gpio));
 			printk("GPIO #%d at 0x%lx\n", curr_gpio,
 			       (unsigned long) gpiop);

@@ -341,6 +349,7 @@
 	for (i = 0; i < ocp_get_max(GPIO); i++) {
 		gpio_dev = ocp_get_dev(GPIO, i);
 		misc_deregister(&ibm_gpio_miscdev);
+		mtdcr(DCRN_CPMFR, mfdcr(DCRN_CPMFR) | ocp_get_pm(GPIO, i));
 		ocp_unregister(gpio_dev);
 	}
 }
diff -Nru a/drivers/i2c/i2c-adap-ibm_ocp.c b/drivers/i2c/i2c-adap-ibm_ocp.c
--- a/drivers/i2c/i2c-adap-ibm_ocp.c	Fri Jul 26 10:04:10 2002
+++ b/drivers/i2c/i2c-adap-ibm_ocp.c	Fri Jul 26 10:04:10 2002
@@ -66,6 +66,9 @@
     Version: 1.9 - Armin
        changed irq_resource to just irq

+    Version: 2.0 - Armin
+    	added CPM enable/disable in init/exit
+
    TODO: add PM hooks

 */
@@ -269,6 +272,7 @@
 			adap->dec_use = iic_ibmocp_dec_use;
 			adap->client_register = iic_ibmocp_reg;
 			adap->client_unregister = iic_ibmocp_unreg;
+			mtdcr(DCRN_CPMFR, mfdcr(DCRN_CPMFR) & ~ocp_get_pm(IIC, curr_iic));

 			init_waitqueue_head(&(iic_wait[curr_iic]));

@@ -312,6 +316,7 @@
 		iic_drv = ocp_get_dev(IIC, i);
 		adap = (struct i2c_adapter *) iic_drv->ocpdev;
 		i2c_iic_del_bus(adap);
+		mtdcr(DCRN_CPMFR, mfdcr(DCRN_CPMFR) | ocp_get_pm(IIC, i));
 	}

 	iic_ibmocp_release();
diff -Nru a/drivers/net/ibm_ocp/ibm_ocp_enet.c b/drivers/net/ibm_ocp/ibm_ocp_enet.c
--- a/drivers/net/ibm_ocp/ibm_ocp_enet.c	Fri Jul 26 10:04:10 2002
+++ b/drivers/net/ibm_ocp/ibm_ocp_enet.c	Fri Jul 26 10:04:10 2002
@@ -167,6 +167,8 @@
  *      removed need for irq_resource
  *	removed need for loop in request & free irq
  *	changed interrupt handles to static
+ *	 Version 4.7 07/25/02 - Armin
+ *	    added CPM enable/diable in init/exit
  *
  */
 #include <linux/module.h>
@@ -619,6 +621,10 @@
 	rx_virt_addr = (mal_desc_t *)
 	    consistent_alloc(GFP_KERNEL, PAGE_SIZE * emac_max, &rx_phys_addr);
 	for (curr_emac = 0; curr_emac < emac_max; curr_emac++) {
+		if(ocp_get_pm(EMAC, curr_emac)){
+			mtdcr(DCRN_CPMFR,
+			      mfdcr(DCRN_CPMFR) & ~IBM_CPM_EMAC(ocp_get_pm(EMAC, curr_emac)));
+		}
 		ocp_enet_probe(curr_emac);
 	}

@@ -1193,6 +1199,17 @@
 static void __exit
 exit_ppc405_enet(void)
 {
+	int i;
+	struct ocp_dev *emac_dev;
+
+	for (i = 0; i < ocp_get_max(EMAC); i++) {
+		emac_dev = ocp_get_dev(EMAC, i);
+		if(ocp_get_pm(EMAC, i)){
+			mtdcr(DCRN_CPMFR, mfdcr(DCRN_CPMFR) | IBM_CPM_EMAC(ocp_get_pm(EMAC, i)));
+			ocp_unregister(emac_dev);
+		}
+	}
+
 	/*
 	 * Unmap the non cached memory space.
 	 */
diff -Nru a/drivers/net/ibm_ocp/ibm_ocp_enet.h b/drivers/net/ibm_ocp/ibm_ocp_enet.h
--- a/drivers/net/ibm_ocp/ibm_ocp_enet.h	Fri Jul 26 10:04:10 2002
+++ b/drivers/net/ibm_ocp/ibm_ocp_enet.h	Fri Jul 26 10:04:10 2002
@@ -93,6 +93,11 @@
 #define MDIO_DELAY		2
 #define NMII				20

+/* Power managment shift registers */
+#define IBM_CPM_EMMII	0	/* Shift value for MII */
+#define IBM_CPM_EMRX	1	/* Shift value for recv */
+#define IBM_CPM_EMTX	2	/* Shift value for MAC */
+#define IBM_CPM_EMAC(x)	(((x)<<IBM_CPM_EMMII) | ((x)<<IBM_CPM_EMRX) | ((x)<<IBM_CPM_EMTX))

 #ifdef CONFIG_IBM_OCP_ENET_ERROR_MSG
 void ppc405_serr_dump_0(struct net_device *dev);