Skip to contentSkip to conversation

FS_ENET: phydev pointer may be dereferenced without NULL check

PATCH In review Vitaly Bordug 3 participants 14 messages Jun 23, 2006 – Jun 26, 2006 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/6 PAL: Support of the fixed PHY

This makes it possible for HW PHY-less boards to utilize PAL goodies. Generic routines to connect to fixed PHY are provided, as well as ability to specify software callback that fills up link, speed, etc. information into PHY descriptor (the latter feature not tested so far).

---

 drivers/net/phy/Kconfig      |   17 ++++++++++++++
 drivers/net/phy/phy_device.c |   51 +++++++++++++++++++++++++-----------------
 include/linux/phy.h          |    1 +
 3 files changed, 48 insertions(+), 21 deletions(-)
drivers/net/phy/Kconfig +17 -0
index 76e51b1..e977fe1 100644
@@ -50,5 +50,22 @@ config VITESSE_PHY
         ---help---
           Currently supports the vsc8244
 
+config FIXED_PHY
+	tristate "Drivers for PHY emulation on fixed speed/link"
+	depends on PHYLIB
+	---help---
+	  Adds the driver to PHY layer to cover the boards that do not have any PHY bound,
+	  but with the ability to manipulate with speed/link in software. The relavant MII
+	  speed/duplex parameters could be effectively handled in user-specified  fuction.
+	  Currently tested with mpc866ads.
+
+config FIXED_MII_10_FDX
+	bool "Emulation for 10M Fdx fixed PHY behavior"
+	depends on FIXED_PHY
+
+config FIXED_MII_100_FDX
+	bool "Emulation for 100M Fdx fixed PHY behavior"
+	depends on FIXED_PHY
+
 endmenu
 
drivers/net/phy/phy_device.c +30 -21

64 lines not on this page · raw message

include/linux/phy.h +1 -0
index 331521a..9447a57 100644
@@ -378,6 +378,7 @@ int phy_mii_ioctl(struct phy_device *phy
 		struct mii_ioctl_data *mii_data, int cmd);
 int phy_start_interrupts(struct phy_device *phydev);
 void phy_print_status(struct phy_device *phydev);
+struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id);
 
 extern struct bus_type mdio_bus_type;
 #endif /* __PHY_H */
#2 lore raw

PATCH 2/6 FS_ENET: Utilize Phy abstraction

In reply to a message not in the archive

This part has modifications necessary to make fs_enet use Phy Abstraction Layer. All mdio trasports were supported, including FEC and bitbanging via GPIO.

---

 drivers/net/fs_enet/Makefile       |    6 
 drivers/net/fs_enet/fec.h          |   42 +++
 drivers/net/fs_enet/fs_enet-main.c |  207 +++++++++------
 drivers/net/fs_enet/fs_enet-mii.c  |  507 ------------------------------------
 drivers/net/fs_enet/fs_enet.h      |   40 ++-
 drivers/net/fs_enet/mac-fcc.c      |   32 ++
 drivers/net/fs_enet/mac-fec.c      |  132 +--------
 drivers/net/fs_enet/mac-scc.c      |    4 
 drivers/net/fs_enet/mii-bitbang.c  |  462 +++++++++++++++++----------------
 drivers/net/fs_enet/mii-fec.c      |  243 +++++++++++++++++
 drivers/net/fs_enet/mii-fixed.c    |   92 -------
 11 files changed, 713 insertions(+), 1054 deletions(-)
drivers/net/fs_enet/Makefile +3 -3
index d6dd3f2..02d4dc1 100644
@@ -4,7 +4,7 @@ #
 
 obj-$(CONFIG_FS_ENET) += fs_enet.o
 
-obj-$(CONFIG_8xx) += mac-fec.o mac-scc.o
-obj-$(CONFIG_8260) += mac-fcc.o
+obj-$(CONFIG_8xx) += mac-fec.o mac-scc.o mii-fec.o
+obj-$(CONFIG_CPM2) += mac-fcc.o mii-bitbang.o
 
-fs_enet-objs := fs_enet-main.o fs_enet-mii.o mii-bitbang.o mii-fixed.o
+fs_enet-objs := fs_enet-main.o
drivers/net/fs_enet/fec.h new file +42 -0

42 lines not on this page · raw message

drivers/net/fs_enet/fs_enet-main.c +129 -78

314 lines not on this page · raw message

drivers/net/fs_enet/fs_enet-mii.c deleted +0 -507

507 lines not on this page · raw message

drivers/net/fs_enet/fs_enet.h +25 -15
index e7ec96c..95022c0 100644
@@ -5,6 +5,7 @@ #include <linux/mii.h>
 #include <linux/netdevice.h>
 #include <linux/types.h>
 #include <linux/list.h>
+#include <linux/phy.h>
 
 #include <linux/fs_enet_pd.h>
 
@@ -12,11 +13,29 @@ #include <asm/dma-mapping.h>
 
 #ifdef CONFIG_CPM1
 #include <asm/commproc.h>
+
+struct fec_info {
+        fec_t*  fecp;
+	u32     mii_speed;
+};
 #endif
 
 #ifdef CONFIG_CPM2
 #include <asm/cpm2.h>
 #endif
+
+/* This is used to operate with pins.
+  Note that the actual port size may
+    be different; cpm(s) handle it OK  */
+struct bb_info {
+	u8 mdio_dat_msk;
+	u8 mdio_dir_msk;
+	u8 *mdio_dir;
+	u8 *mdio_dat;
+	u8 mdc_msk;
+	u8 *mdc_dat;
+	int delay;
+};
 
 /* hw driver ops */
 struct fs_ops {
@@ -25,6 +44,7 @@ struct fs_ops {
 	void (*free_bd)(struct net_device *dev);
 	void (*cleanup_data)(struct net_device *dev);
 	void (*set_multicast_list)(struct net_device *dev);
+	void (*adjust_link)(struct net_device *dev);
 	void (*restart)(struct net_device *dev);
 	void (*stop)(struct net_device *dev);
 	void (*pre_request_irq)(struct net_device *dev, int irq);
@@ -99,10 +119,6 @@ struct fs_enet_mii_bus {
 		} fixed;
 	};
 };
-
-int fs_mii_bitbang_init(struct fs_enet_mii_bus *bus);
-int fs_mii_fixed_init(struct fs_enet_mii_bus *bus);
-int fs_mii_fec_init(struct fs_enet_mii_bus *bus);
 
 struct fs_enet_private {
 	struct device *dev;	/* pointer back to the device (must be initialized first) */
@@ -130,7 +146,8 @@ struct fs_enet_private {
 	struct fs_enet_mii_bus *mii_bus;
 	int interrupt;
 
-	int duplex, speed;	/* current settings */
+	struct phy_device *phydev;
+	int oldduplex, oldspeed, oldlink;	/* current settings */
 
 	/* event masks */
 	u32 ev_napi_rx;		/* mask of NAPI rx events */
@@ -168,15 +185,9 @@ struct fs_enet_private {
 };
 
 /***************************************************************************/
-
-int fs_mii_read(struct net_device *dev, int phy_id, int location);
-void fs_mii_write(struct net_device *dev, int phy_id, int location, int value);
-
-void fs_mii_startup(struct net_device *dev);
-void fs_mii_shutdown(struct net_device *dev);
-void fs_mii_ack_int(struct net_device *dev);
-
-void fs_mii_link_status_change_check(struct net_device *dev, int init_media);
+int fs_enet_mdio_bb_init(void);
+int fs_mii_fixed_init(struct fs_enet_mii_bus *bus);
+int fs_enet_mdio_fec_init(void);
 
 void fs_init_bds(struct net_device *dev);
 void fs_cleanup_bds(struct net_device *dev);
@@ -194,7 +205,6 @@ int fs_enet_platform_init(void);
 void fs_enet_platform_cleanup(void);
 
 /***************************************************************************/
-
 /* buffer descriptor access macros */
 
 /* access macros */
drivers/net/fs_enet/mac-fcc.c +22 -10
index 95e2bb8..8bc711d 100644
@@ -35,6 +35,7 @@ #include <linux/ethtool.h>
 #include <linux/bitops.h>
 #include <linux/fs.h>
 #include <linux/platform_device.h>
+#include <linux/phy.h>
 
 #include <asm/immap_cpm2.h>
 #include <asm/mpc8260.h>
@@ -123,20 +124,30 @@ static int do_pd_setup(struct fs_enet_pr
 
 	/* Attach the memory for the FCC Parameter RAM */
 	r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_pram");
-	fep->fcc.ep = (void *)r->start;
-
+	fep->fcc.ep = (void *)ioremap(r->start, r->end - r->start + 1);
 	if (fep->fcc.ep == NULL)
 		return -EINVAL;
 
 	r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_regs");
-	fep->fcc.fccp = (void *)r->start;
-
+	fep->fcc.fccp = (void *)ioremap(r->start, r->end - r->start + 1);
 	if (fep->fcc.fccp == NULL)
 		return -EINVAL;
+
+	if (fep->fpi->fcc_regs_c) {
 
-	fep->fcc.fcccp = (void *)fep->fpi->fcc_regs_c;
+		fep->fcc.fcccp = (void *)fep->fpi->fcc_regs_c;
+	} else {
+		r = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+				"fcc_regs_c");
+		fep->fcc.fcccp = (void *)ioremap(r->start,
+				r->end - r->start + 1);
+	}
 
 	if (fep->fcc.fcccp == NULL)
+		return -EINVAL;
+
+	fep->fcc.mem = (void *)fep->fpi->mem_offset;
+	if (fep->fcc.mem == NULL)
 		return -EINVAL;
 
 	return 0;
@@ -156,8 +167,6 @@ static int setup_data(struct net_device 
 	if ((unsigned int)fep->fcc.idx >= 3)	/* max 3 FCCs */
 		return -EINVAL;
 
-	fep->fcc.mem = (void *)fpi->mem_offset;
-
 	if (do_pd_setup(fep) != 0)
 		return -EINVAL;
 
@@ -395,7 +404,7 @@ static void restart(struct net_device *d
 
 	/* adjust to speed (for RMII mode) */
 	if (fpi->use_rmii) {
-		if (fep->speed == 100)
+		if (fep->phydev->speed == 100)
 			C8(fcccp, fcc_gfemr, 0x20);
 		else
 			S8(fcccp, fcc_gfemr, 0x20);
@@ -421,7 +430,7 @@ static void restart(struct net_device *d
 		S32(fccp, fcc_fpsmr, FCC_PSMR_RMII);
 
 	/* adjust to duplex mode */
-	if (fep->duplex)
+	if (fep->phydev->duplex)
 		S32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
 	else
 		C32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
@@ -487,7 +496,10 @@ static void rx_bd_done(struct net_device
 
 static void tx_kickstart(struct net_device *dev)
 {
-	/* nothing */
+	struct fs_enet_private *fep = netdev_priv(dev);
+	fcc_t *fccp = fep->fcc.fccp;
+
+	S32(fccp, fcc_ftodr, 0x80);
 }
 
 static u32 get_int_events(struct net_device *dev)
drivers/net/fs_enet/mac-fec.c +13 -119

191 lines not on this page · raw message

drivers/net/fs_enet/mac-scc.c +3 -1
index a772b28..d829120 100644
@@ -370,7 +370,7 @@ static void restart(struct net_device *d
 	W16(sccp, scc_psmr, SCC_PSMR_ENCRC | SCC_PSMR_NIB22);
 
 	/* Set full duplex mode if needed */
-	if (fep->duplex)
+	if (fep->phydev->duplex)
 		S16(sccp, scc_psmr, SCC_PSMR_LPB | SCC_PSMR_FDE);
 
 	S32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
@@ -500,6 +500,8 @@ static void tx_restart(struct net_device
 
 	scc_cr_cmd(fep, CPM_CR_RESTART_TX);
 }
+
+
 
 /*************************************************************************/
 
drivers/net/fs_enet/mii-bitbang.c +233 -229

589 lines not on this page · raw message

drivers/net/fs_enet/mii-fec.c new file +243 -0

243 lines not on this page · raw message

drivers/net/fs_enet/mii-fixed.c deleted +0 -92

92 lines not on this page · raw message

#3 lore raw

PATCH 3/6 FS_ENET: use PAL for mii management (BSP part)

In reply to a message not in the archive

This patch should update the board-specific parts of fs_enet infrastructure to utilize Phy Abstraction Layer subsystem. Inside there are portions to respect driver changes for 8272ads, 885ads, 866ads, and 8560ads.

---

 arch/ppc/platforms/85xx/mpc8560_ads.c        |   89 ++++++++++++
 arch/ppc/platforms/85xx/mpc85xx_ads_common.h |   19 +++
 arch/ppc/platforms/mpc8272ads_setup.c        |  162 ++++++++++++----------
 arch/ppc/platforms/mpc866ads_setup.c         |  192 +++++++++++++-------------
 arch/ppc/platforms/mpc885ads_setup.c         |  177 +++++++++---------------
 arch/ppc/platforms/pq2ads_pd.h               |   82 -----------
 arch/ppc/syslib/mpc85xx_devices.c            |   89 ++++++++++++
 arch/ppc/syslib/mpc8xx_devices.c             |    8 +
 arch/ppc/syslib/mpc8xx_sys.c                 |    6 +
 arch/ppc/syslib/pq2_devices.c                |    5 +
 arch/ppc/syslib/pq2_sys.c                    |    3 
 include/asm-ppc/cpm2.h                       |   95 +++++++++++++
 include/asm-ppc/mpc8260.h                    |    1 
 include/asm-ppc/mpc8xx.h                     |    1 
 include/linux/fs_enet_pd.h                   |   54 +++----
 15 files changed, 585 insertions(+), 398 deletions(-)
arch/ppc/platforms/85xx/mpc8560_ads.c +89 -0
index 0cb2e86..92c46d8 100644
@@ -30,6 +30,7 @@ #include <linux/serial_core.h>
 #include <linux/initrd.h>
 #include <linux/module.h>
 #include <linux/fsl_devices.h>
+#include <linux/fs_enet_pd.h>
 
 #include <asm/system.h>
 #include <asm/pgtable.h>
@@ -59,6 +60,71 @@ #include <syslib/ppc85xx_setup.h>
  * Setup the architecture
  *
  */
+static void init_fcc_ioports(void)
+{
+	struct immap *immap;
+	struct io_port *io;
+	u32 tempval;
+
+	immap = cpm2_immr;
+
+	io = &immap->im_ioport;
+	/* FCC2/3 are on the ports B/C. */
+	tempval = in_be32(&io->iop_pdirb);
+	tempval &= ~PB2_DIRB0;
+	tempval |= PB2_DIRB1;
+	out_be32(&io->iop_pdirb, tempval);
+
+	tempval = in_be32(&io->iop_psorb);
+	tempval &= ~PB2_PSORB0;
+	tempval |= PB2_PSORB1;
+	out_be32(&io->iop_psorb, tempval);
+
+	tempval = in_be32(&io->iop_pparb);
+	tempval |= (PB2_DIRB0 | PB2_DIRB1);
+	out_be32(&io->iop_pparb, tempval);
+
+	tempval = in_be32(&io->iop_pdirb);
+	tempval &= ~PB3_DIRB0;
+	tempval |= PB3_DIRB1;
+	out_be32(&io->iop_pdirb, tempval);
+
+	tempval = in_be32(&io->iop_psorb);
+	tempval &= ~PB3_PSORB0;
+	tempval |= PB3_PSORB1;
+	out_be32(&io->iop_psorb, tempval);
+
+	tempval = in_be32(&io->iop_pparb);
+	tempval |= (PB3_DIRB0 | PB3_DIRB1);
+	out_be32(&io->iop_pparb, tempval);
+
+        tempval = in_be32(&io->iop_pdirc);
+        tempval |= PC3_DIRC1;
+        out_be32(&io->iop_pdirc, tempval);
+
+        tempval = in_be32(&io->iop_pparc);
+        tempval |= PC3_DIRC1;
+        out_be32(&io->iop_pparc, tempval);
+
+	/* Port C has clocks......  */
+	tempval = in_be32(&io->iop_psorc);
+	tempval &= ~(CLK_TRX);
+	out_be32(&io->iop_psorc, tempval);
+
+	tempval = in_be32(&io->iop_pdirc);
+	tempval &= ~(CLK_TRX);
+	out_be32(&io->iop_pdirc, tempval);
+	tempval = in_be32(&io->iop_pparc);
+	tempval |= (CLK_TRX);
+	out_be32(&io->iop_pparc, tempval);
+
+	/* Configure Serial Interface clock routing.
+	 * First,  clear all FCC bits to zero,
+	 * then set the ones we want.
+	 */
+	immap->im_cpmux.cmx_fcr &= ~(CPMUX_CLK_MASK);
+	immap->im_cpmux.cmx_fcr |= CPMUX_CLK_ROUTE;
+}
 
 static void __init
 mpc8560ads_setup_arch(void)
@@ -67,6 +133,7 @@ mpc8560ads_setup_arch(void)
 	unsigned int freq;
 	struct gianfar_platform_data *pdata;
 	struct gianfar_mdio_data *mdata;
+	struct fs_platform_info *fpi;
 
 	cpm2_reset();
 
@@ -109,6 +176,28 @@ #endif
 		pdata->bus_id = 0;
 		pdata->phy_id = 1;
 		memcpy(pdata->mac_addr, binfo->bi_enet1addr, 6);
+	}
+
+	init_fcc_ioports();
+	ppc_sys_device_remove(MPC85xx_CPM_FCC1);
+
+	fpi = (struct fs_platform_info *) ppc_sys_get_pdata(MPC85xx_CPM_FCC2);
+	if (fpi) {
+		memcpy(fpi->macaddr, binfo->bi_enet2addr, 6);
+		fpi->bus_id = "0:02";
+		fpi->phy_addr = 2;
+		fpi->dpram_offset = (u32)cpm2_immr->im_dprambase;
+		fpi->fcc_regs_c = (u32)&cpm2_immr->im_fcc_c[1];
+	}
+
+	fpi = (struct fs_platform_info *) ppc_sys_get_pdata(MPC85xx_CPM_FCC3);
+	if (fpi) {
+		memcpy(fpi->macaddr, binfo->bi_enet2addr, 6);
+		fpi->macaddr[5] += 1;
+		fpi->bus_id = "0:03";
+		fpi->phy_addr = 3;
+		fpi->dpram_offset = (u32)cpm2_immr->im_dprambase;
+		fpi->fcc_regs_c = (u32)&cpm2_immr->im_fcc_c[2];
 	}
 
 #ifdef CONFIG_BLK_DEV_INITRD
arch/ppc/platforms/85xx/mpc85xx_ads_common.h +19 -0
index de8d41a..86a4338 100644
@@ -46,4 +46,23 @@ #define MPC85XX_PCI1_MEM_OFFSET	0x000000
 
 #define MPC85XX_PCI1_IO_SIZE	0x01000000
 
+/* FCC1 Clock Source Configuration.  These can be
+ * redefined in the board specific file.
+ *    Can only choose from CLK9-12 */
+#define F1_RXCLK       12
+#define F1_TXCLK       11
+
+/* FCC2 Clock Source Configuration.  These can be
+ * redefined in the board specific file.
+ *    Can only choose from CLK13-16 */
+#define F2_RXCLK       13
+#define F2_TXCLK       14
+
+/* FCC3 Clock Source Configuration.  These can be
+ * redefined in the board specific file.
+ *    Can only choose from CLK13-16 */
+#define F3_RXCLK       15
+#define F3_TXCLK       16
+
+
 #endif				/* __MACH_MPC85XX_ADS_H__ */
arch/ppc/platforms/mpc8272ads_setup.c +89 -73

193 lines not on this page · raw message

arch/ppc/platforms/mpc866ads_setup.c +96 -96

249 lines not on this page · raw message

arch/ppc/platforms/mpc885ads_setup.c +67 -110

284 lines not on this page · raw message

arch/ppc/platforms/pq2ads_pd.h +0 -82

86 lines not on this page · raw message

arch/ppc/syslib/mpc85xx_devices.c +86 -3

155 lines not on this page · raw message

arch/ppc/syslib/mpc8xx_devices.c +8 -0
index 6f53638..cf5ab47 100644
@@ -218,6 +218,14 @@ struct platform_device ppc_sys_platform_
 			},
 		},
 	},
+
+        [MPC8xx_MDIO_FEC] = {
+                .name = "fsl-cpm-fec-mdio",
+                .id = 0,
+                .num_resources = 0,
+
+        },
+
 };
 
 static int __init mach_mpc8xx_fixup(struct platform_device *pdev)
arch/ppc/syslib/mpc8xx_sys.c +4 -2
index eee2132..18ba1d7 100644
@@ -22,7 +22,7 @@ struct ppc_sys_spec ppc_sys_specs[] = {
 		.ppc_sys_name	= "MPC86X",
 		.mask 		= 0xFFFFFFFF,
 		.value 		= 0x00000000,
-		.num_devices	= 7,
+		.num_devices	= 8,
 		.device_list	= (enum ppc_sys_devices[])
 		{
 			MPC8xx_CPM_FEC1,
@@ -32,13 +32,14 @@ struct ppc_sys_spec ppc_sys_specs[] = {
 			MPC8xx_CPM_SCC4,
 			MPC8xx_CPM_SMC1,
 			MPC8xx_CPM_SMC2,
+			MPC8xx_MDIO_FEC,
 		},
 	},
 	{
 		.ppc_sys_name	= "MPC885",
 		.mask 		= 0xFFFFFFFF,
 		.value 		= 0x00000000,
-		.num_devices	= 8,
+		.num_devices	= 9,
 		.device_list	= (enum ppc_sys_devices[])
 		{
 			MPC8xx_CPM_FEC1,
@@ -49,6 +50,7 @@ struct ppc_sys_spec ppc_sys_specs[] = {
 			MPC8xx_CPM_SCC4,
 			MPC8xx_CPM_SMC1,
 			MPC8xx_CPM_SMC2,
+			MPC8xx_MDIO_FEC,
 		},
 	},
 	{	/* default match */
arch/ppc/syslib/pq2_devices.c +5 -0
index 8692d00..fefbc21 100644
@@ -369,6 +369,11 @@ struct platform_device ppc_sys_platform_
 			},
 		},
 	},
+	[MPC82xx_MDIO_BB] = {
+		.name = "fsl-bb-mdio",
+		.id = 0,
+		.num_resources = 0,
+	},
 };
 
 static int __init mach_mpc82xx_fixup(struct platform_device *pdev)
arch/ppc/syslib/pq2_sys.c +2 -1
index fee8948..f52600c 100644
@@ -139,13 +139,14 @@ struct ppc_sys_spec ppc_sys_specs[] = {
 		.ppc_sys_name	= "8272",
 		.mask		= 0x0000ff00,
 		.value		= 0x00000c00,
-		.num_devices	= 12,
+		.num_devices	= 13,
 		.device_list = (enum ppc_sys_devices[])
 		{
 			MPC82xx_CPM_FCC1, MPC82xx_CPM_FCC2, MPC82xx_CPM_SCC1,
 			MPC82xx_CPM_SCC2, MPC82xx_CPM_SCC3, MPC82xx_CPM_SCC4,
 			MPC82xx_CPM_SMC1, MPC82xx_CPM_SMC2, MPC82xx_CPM_SPI,
 			MPC82xx_CPM_I2C, MPC82xx_CPM_USB, MPC82xx_SEC1,
+			MPC82xx_MDIO_BB,
 		},
 	},
 	/* below is a list of the 8280 family of processors */
include/asm-ppc/cpm2.h +95 -0

100 lines not on this page · raw message

include/asm-ppc/mpc8260.h +1 -0
index 6ba69a8..e4a897e 100644
@@ -83,6 +83,7 @@ enum ppc_sys_devices {
 	MPC82xx_CPM_SMC2,
 	MPC82xx_CPM_USB,
 	MPC82xx_SEC1,
+	MPC82xx_MDIO_BB,
 	NUM_PPC_SYS_DEVS,
 };
 
include/asm-ppc/mpc8xx.h +1 -0
index 3515a7f..8830dfe 100644
@@ -111,6 +111,7 @@ enum ppc_sys_devices {
 	MPC8xx_CPM_SMC1,
 	MPC8xx_CPM_SMC2,
 	MPC8xx_CPM_USB,
+	MPC8xx_MDIO_FEC,
 	NUM_PPC_SYS_DEVS,
 };
 
include/linux/fs_enet_pd.h +23 -31

71 lines not on this page · raw message

#4 lore raw

PATCH 4/6 FS_ENET: phydev pointer may be dereferenced without NULL check

In reply to a message not in the archive

When interface is down, phy is "disconnected" from the bus and phydev is NULL. But ethtool may try to get/set phy regs even at that time, which results in NULL pointer dereference and OOPS hereby.

---

 drivers/net/fs_enet/fs_enet-main.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/net/fs_enet/fs_enet-main.c +4 -0
index 302ecaa..e475e22 100644
@@ -882,12 +882,16 @@ static void fs_get_regs(struct net_devic
 static int fs_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
 	struct fs_enet_private *fep = netdev_priv(dev);
+	if (!fep->phydev)
+		return -EINVAL;
 	return phy_ethtool_gset(fep->phydev, cmd);
 }
 
 static int fs_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
 	struct fs_enet_private *fep = netdev_priv(dev);
+	if (!fep->phydev)
+		return -EINVAL;
 	phy_ethtool_sset(fep->phydev, cmd);
 	return 0;
 }
#5 lore raw

PATCH 5/6 CPM_UART: unify clock sources

In reply to a message not in the archive

In order to make it possible to utilize the driver from arch/powerpc yet not breaking existing ppc users, clock sources are unfied via macro, and resources ioremapped.

---

 drivers/serial/cpm_uart/cpm_uart_core.c |   11 ++++-------
 drivers/serial/cpm_uart/cpm_uart_cpm2.c |   13 +++++++------
 include/asm-powerpc/fs_pd.h             |   17 +++++++++++++++++
 include/asm-ppc/fs_pd.h                 |   17 +++++++++++++++++
 4 files changed, 45 insertions(+), 13 deletions(-)
drivers/serial/cpm_uart/cpm_uart_core.c +4 -7
index 5cba59a..0507f74 100644
@@ -47,6 +47,7 @@ #include <linux/fs_uart_pd.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/delay.h>
+#include <asm/fs_pd.h>
 
 #if defined(CONFIG_SERIAL_CPM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
 #define SUPPORT_SYSRQ
@@ -1045,11 +1046,11 @@ int cpm_uart_drv_get_platform_data(struc
 
 	if (!(r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs")))
 		return -EINVAL;
-	mem = r->start;
+	mem = ioremap(r->start, r->end - r->start + 1);
 
 	if (!(r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pram")))
 		return -EINVAL;
-	pram = r->start;
+	pram = ioremap(r->start, r->end - r->start + 1);
 
 	if(idx > fsid_smc2_uart) {
 		pinfo->sccp = (scc_t *)mem;
@@ -1190,11 +1191,7 @@ static int __init cpm_uart_console_setup
 	if (options) {
 		uart_parse_options(options, &baud, &parity, &bits, &flow);
 	} else {
-		bd_t *bd = (bd_t *) __res;
-
-		if (bd->bi_baudrate)
-			baud = bd->bi_baudrate;
-		else
+		if ((baud = GET_BAUDRATE()) == -1)
 			baud = 9600;
 	}
 
drivers/serial/cpm_uart/cpm_uart_cpm2.c +7 -6
index cdba128..29b89f0 100644
@@ -41,6 +41,7 @@ #include <linux/dma-mapping.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
+#include <asm/fs_pd.h>
 
 #include <linux/serial_core.h>
 #include <linux/kernel.h>
@@ -267,7 +268,7 @@ #ifdef CONFIG_SERIAL_CPM_SMC1
 	    (unsigned long)&cpm2_immr->im_smc[0];
 	cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
 	cpm_uart_ports[UART_SMC1].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
-	cpm_uart_ports[UART_SMC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
+	cpm_uart_ports[UART_SMC1].port.uartclk = FS_UART_CLK();
 	cpm_uart_port_map[cpm_uart_nr++] = UART_SMC1;
 #endif
 
@@ -280,7 +281,7 @@ #ifdef CONFIG_SERIAL_CPM_SMC2
 	    (unsigned long)&cpm2_immr->im_smc[1];
 	cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
 	cpm_uart_ports[UART_SMC2].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
-	cpm_uart_ports[UART_SMC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
+	cpm_uart_ports[UART_SMC2].port.uartclk = FS_UART_CLK();
 	cpm_uart_port_map[cpm_uart_nr++] = UART_SMC2;
 #endif
 
@@ -294,7 +295,7 @@ #ifdef CONFIG_SERIAL_CPM_SCC1
 	    ~(UART_SCCM_TX | UART_SCCM_RX);
 	cpm_uart_ports[UART_SCC1].sccp->scc_gsmrl &=
 	    ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
-	cpm_uart_ports[UART_SCC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
+	cpm_uart_ports[UART_SCC1].port.uartclk = FS_UART_CLK();
 	cpm_uart_port_map[cpm_uart_nr++] = UART_SCC1;
 #endif
 
@@ -308,7 +309,7 @@ #ifdef CONFIG_SERIAL_CPM_SCC2
 	    ~(UART_SCCM_TX | UART_SCCM_RX);
 	cpm_uart_ports[UART_SCC2].sccp->scc_gsmrl &=
 	    ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
-	cpm_uart_ports[UART_SCC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
+	cpm_uart_ports[UART_SCC2].port.uartclk = FS_UART_CLK();
 	cpm_uart_port_map[cpm_uart_nr++] = UART_SCC2;
 #endif
 
@@ -322,7 +323,7 @@ #ifdef CONFIG_SERIAL_CPM_SCC3
 	    ~(UART_SCCM_TX | UART_SCCM_RX);
 	cpm_uart_ports[UART_SCC3].sccp->scc_gsmrl &=
 	    ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
-	cpm_uart_ports[UART_SCC3].port.uartclk = (((bd_t *) __res)->bi_intfreq);
+	cpm_uart_ports[UART_SCC3].port.uartclk = FS_UART_CLK();
 	cpm_uart_port_map[cpm_uart_nr++] = UART_SCC3;
 #endif
 
@@ -336,7 +337,7 @@ #ifdef CONFIG_SERIAL_CPM_SCC4
 	    ~(UART_SCCM_TX | UART_SCCM_RX);
 	cpm_uart_ports[UART_SCC4].sccp->scc_gsmrl &=
 	    ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
-	cpm_uart_ports[UART_SCC4].port.uartclk = (((bd_t *) __res)->bi_intfreq);
+	cpm_uart_ports[UART_SCC4].port.uartclk = FS_UART_CLK();
 	cpm_uart_port_map[cpm_uart_nr++] = UART_SCC4;
 #endif
 
include/asm-powerpc/fs_pd.h new file +17 -0
new file mode 100644
index 0000000..b20d8da
@@ -0,0 +1,17 @@
+/*
+ * Platform information definitions.
+ *
+ * 2006 (c) MontaVista Software, Inc.
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */
+
+#ifndef FS_PD_H
+#define FS_PD_H
+
+#define GET_BAUDRATE()	get_baudrate()
+#define FS_UART_CLK()	get_intfreq()
+
+#endif
include/asm-ppc/fs_pd.h new file +17 -0
new file mode 100644
index 0000000..b1d550b
@@ -0,0 +1,17 @@
+/*
+ * Platform information definitions.
+ *
+ * 2006 (c) MontaVista Software, Inc.
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */
+
+#ifndef FS_PD_H
+#define FS_PD_H
+
+#define GET_BAUDRATE()	(((bd_t *) __res)->bi_baudrate ? ((bd_t *) __res)->bi_baudrate : -1)
+#define FS_UART_CLK()	(((bd_t *) __res)->bi_intfreq)
+
+#endif
#6 lore raw

Re: [PATCH 5/6] CPM_UART: unify clock sources

Quoted 177 lines · Vitaly Bordug

In order to make it possible to utilize the driver from arch/powerpc yet not breaking existing ppc users, clock sources are unfied via macro, and resources ioremapped.

---

 drivers/serial/cpm_uart/cpm_uart_core.c |   11 ++++-------
 drivers/serial/cpm_uart/cpm_uart_cpm2.c |   13 +++++++------
 include/asm-powerpc/fs_pd.h             |   17 +++++++++++++++++
 include/asm-ppc/fs_pd.h                 |   17 +++++++++++++++++
 4 files changed, 45 insertions(+), 13 deletions(-)
drivers/serial/cpm_uart/cpm_uart_core.c +3 -2
index 5cba59a..0507f74 100644
@@ -47,6 +47,7 @@ #include <linux/fs_uart_pd.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/delay.h>
+#include <asm/fs_pd.h>
 
 #if defined(CONFIG_SERIAL_CPM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
 #define SUPPORT_SYSRQ
@@ -1045,11 +1046,11 @@ int cpm_uart_drv_get_platform_data(struc
 
 	if (!(r = platform_get_resource_byname(pdev, IORESOURCE_MEM,  
 "regs")))
 		return -EINVAL;
-	mem = r->start;
+	mem = ioremap(r->start, r->end - r->start + 1);
 
 	if (!(r = platform_get_resource_byname(pdev, IORESOURCE_MEM,  
 "pram")))
 		return -EINVAL;
-	pram = r->start;
+	pram = ioremap(r->start, r->end - r->start + 1);
 
drivers/serial/cpm_uart/cpm_uart_core.c +1 -5
 	if(idx > fsid_smc2_uart) {
 		pinfo->sccp = (scc_t *)mem;
@@ -1190,11 +1191,7 @@ static int __init cpm_uart_console_setup
 	if (options) {
 		uart_parse_options(options, &baud, &parity, &bits, &flow);
 	} else {
-		bd_t *bd = (bd_t *) __res;
-
-		if (bd->bi_baudrate)
-			baud = bd->bi_baudrate;
-		else
+		if ((baud = GET_BAUDRATE()) == -1)
 			baud = 9600;
 	}
 
drivers/serial/cpm_uart/cpm_uart_cpm2.c +2 -1
index cdba128..29b89f0 100644
@@ -41,6 +41,7 @@ #include <linux/dma-mapping.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
+#include <asm/fs_pd.h>
 
 #include <linux/serial_core.h>
 #include <linux/kernel.h>
@@ -267,7 +268,7 @@ #ifdef CONFIG_SERIAL_CPM_SMC1
 	    (unsigned long)&cpm2_immr->im_smc[0];
 	cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
 	cpm_uart_ports[UART_SMC1].smcp->smc_smcmr &= ~(SMCMR_REN |  
 SMCMR_TEN);
-	cpm_uart_ports[UART_SMC1].port.uartclk = (((bd_t *) __res)- 
 >bi_intfreq);
+	cpm_uart_ports[UART_SMC1].port.uartclk = FS_UART_CLK();
 	cpm_uart_port_map[cpm_uart_nr++] = UART_SMC1;

#endif

drivers/serial/cpm_uart/cpm_uart_cpm2.c +1 -1
@@ -280,7 +281,7 @@ #ifdef CONFIG_SERIAL_CPM_SMC2
 	    (unsigned long)&cpm2_immr->im_smc[1];
 	cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
 	cpm_uart_ports[UART_SMC2].smcp->smc_smcmr &= ~(SMCMR_REN |  
 SMCMR_TEN);
-	cpm_uart_ports[UART_SMC2].port.uartclk = (((bd_t *) __res)- 
 >bi_intfreq);
+	cpm_uart_ports[UART_SMC2].port.uartclk = FS_UART_CLK();
 	cpm_uart_port_map[cpm_uart_nr++] = UART_SMC2;

#endif

drivers/serial/cpm_uart/cpm_uart_cpm2.c +4 -4
@@ -294,7 +295,7 @@ #ifdef CONFIG_SERIAL_CPM_SCC1
 	    ~(UART_SCCM_TX | UART_SCCM_RX);
 	cpm_uart_ports[UART_SCC1].sccp->scc_gsmrl &=
 	    ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
-	cpm_uart_ports[UART_SCC1].port.uartclk = (((bd_t *) __res)- 
 >bi_intfreq);
+	cpm_uart_ports[UART_SCC1].port.uartclk = FS_UART_CLK();
 	cpm_uart_port_map[cpm_uart_nr++] = UART_SCC1;
 #endif
@@ -308,7 +309,7 @@ #ifdef CONFIG_SERIAL_CPM_SCC2
 	    ~(UART_SCCM_TX | UART_SCCM_RX);
 	cpm_uart_ports[UART_SCC2].sccp->scc_gsmrl &=
 	    ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
-	cpm_uart_ports[UART_SCC2].port.uartclk = (((bd_t *) __res)- 
 >bi_intfreq);
+	cpm_uart_ports[UART_SCC2].port.uartclk = FS_UART_CLK();
 	cpm_uart_port_map[cpm_uart_nr++] = UART_SCC2;
 #endif
@@ -322,7 +323,7 @@ #ifdef CONFIG_SERIAL_CPM_SCC3
 	    ~(UART_SCCM_TX | UART_SCCM_RX);
 	cpm_uart_ports[UART_SCC3].sccp->scc_gsmrl &=
 	    ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
-	cpm_uart_ports[UART_SCC3].port.uartclk = (((bd_t *) __res)- 
 >bi_intfreq);
+	cpm_uart_ports[UART_SCC3].port.uartclk = FS_UART_CLK();
 	cpm_uart_port_map[cpm_uart_nr++] = UART_SCC3;
 #endif
@@ -336,7 +337,7 @@ #ifdef CONFIG_SERIAL_CPM_SCC4
 	    ~(UART_SCCM_TX | UART_SCCM_RX);
 	cpm_uart_ports[UART_SCC4].sccp->scc_gsmrl &=
 	    ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
-	cpm_uart_ports[UART_SCC4].port.uartclk = (((bd_t *) __res)- 
 >bi_intfreq);
+	cpm_uart_ports[UART_SCC4].port.uartclk = FS_UART_CLK();
 	cpm_uart_port_map[cpm_uart_nr++] = UART_SCC4;
 #endif
include/asm-powerpc/fs_pd.h new file +6 -0
new file mode 100644
index 0000000..b20d8da
@@ -0,0 +1,17 @@
+/*
+ * Platform information definitions.
+ *
+ * 2006 (c) MontaVista Software, Inc.
+ *
+ * This file is licensed under the terms of the GNU General Public  

License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */

include/asm-powerpc/fs_pd.h new file +8 -0
+
+#ifndef FS_PD_H
+#define FS_PD_H
+
+#define GET_BAUDRATE()	get_baudrate()
+#define FS_UART_CLK()	get_intfreq()
+
+#endif
include/asm-ppc/fs_pd.h new file +6 -0
new file mode 100644
index 0000000..b1d550b
@@ -0,0 +1,17 @@
+/*
+ * Platform information definitions.
+ *
+ * 2006 (c) MontaVista Software, Inc.
+ *
+ * This file is licensed under the terms of the GNU General Public  

License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */

include/asm-ppc/fs_pd.h new file +5 -0
+
+#ifndef FS_PD_H
+#define FS_PD_H
+
+#define GET_BAUDRATE()	(((bd_t *) __res)->bi_baudrate ? ((bd_t *)  

__res)->bi_baudrate : -1)

include/asm-ppc/fs_pd.h line 17

Quoted 3 lines
include/asm-ppc/fs_pd.h new file +3 -0
+#define FS_UART_CLK()	(((bd_t *) __res)->bi_intfreq)
+
+#endif

We shouldn't hide these differences in a header like this. As we slowly try to removing things from arch/ppc. Why not just add platform data for these two pieces of data and set it up like we do other platform data.

- k

#7 lore raw

Re: [PATCH 5/6] CPM_UART: unify clock sources

Kumar,

Thanks for feedback! My comment below.

On Sat, 24 Jun 2006 08:46:54 -0500
Kumar Gala <[email protected]> wrote:

[snip]

Quoted 6 lines
Quoted 6 lines
include/asm-powerpc/fs_pd.h new file +5 -0
+
+#ifndef FS_PD_H
+#define FS_PD_H
+
+#define GET_BAUDRATE()	(((bd_t *) __res)->bi_baudrate ?

((bd_t *) __res)->bi_baudrate : -1)

Quoted 9 lines

include/asm-ppc/fs_pd.h line 17

Quoted 3 lines
include/asm-ppc/fs_pd.h new file +3 -0
+#define FS_UART_CLK()	(((bd_t *) __res)->bi_intfreq)
+
+#endif

We shouldn't hide these differences in a header like this. As we slowly try to removing things from arch/ppc. Why not just add platform data for these two pieces of data and set it up like we do other platform data.

That was my first guess as well, but:
The aim is yet moving to powerpc not to break existing ppc/ stuff. So if alternatively platform_data may be utilized, all relevant ppc stuff that uses cpm uart should be updated. While doing the driver "platformize" trick, I made it possible to keep legacy behaviour (pd-less), this is not going to afford such a thing.

IOW, I don't see much sense in updating ppc/ BSP files, just to keep the right way. It does not look very neat now, but does the job of moving FW and keeping existing stuff sane. If there is better approach envisioned, I'll definitely follow..

--
Sincerely, Vitaly

#8 lore raw

Re: [PATCH 5/6] CPM_UART: unify clock sources

Quoted 30 lines · Vitaly Bordug

Kumar,

Thanks for feedback! My comment below.

On Sat, 24 Jun 2006 08:46:54 -0500
Kumar Gala <[email protected]> wrote:

[snip]

Quoted 6 lines
Quoted 6 lines
include/asm-powerpc/fs_pd.h new file +5 -0
+
+#ifndef FS_PD_H
+#define FS_PD_H
+
+#define GET_BAUDRATE()	(((bd_t *) __res)->bi_baudrate ?

((bd_t *) __res)->bi_baudrate : -1)

Quoted 9 lines

include/asm-ppc/fs_pd.h line 17

Quoted 3 lines
include/asm-ppc/fs_pd.h new file +3 -0
+#define FS_UART_CLK()	(((bd_t *) __res)->bi_intfreq)
+
+#endif

We shouldn't hide these differences in a header like this. As we slowly try to removing things from arch/ppc. Why not just add platform data for these two pieces of data and set it up like we do other platform data.

That was my first guess as well, but:
The aim is yet moving to powerpc not to break existing ppc/ stuff. So if alternatively platform_data may be utilized, all relevant ppc stuff that uses cpm uart should be updated. While doing the driver "platformize" trick, I made it possible to keep legacy behaviour (pd-less), this is not going to afford such a thing.

Quoted 4 lines

IOW, I don't see much sense in updating ppc/ BSP files, just to keep the right way. It does not look very neat now, but does the job of moving FW and keeping existing stuff sane. If there is better approach envisioned, I'll definitely follow..

Fair enough, then I would suggest getting ride of all this header/MACRO indirection and just implement these as functions with different implementations in arch/powerpc vs arch/ppc.

- k

#9 lore raw

Re: [PATCH 5/6] CPM_UART: unify clock sources

In reply to Vitaly Bordug

So, like, the other day Vitaly Bordug mumbled:

Quoted 11 lines

That was my first guess as well, but:
The aim is yet moving to powerpc not to break existing ppc/ stuff. So if alternatively platform_data may be utilized, all relevant ppc stuff that uses cpm uart should be updated. While doing the driver "platformize" trick, I made it possible to keep legacy behaviour (pd-less), this is not going to afford such a thing.

IOW, I don't see much sense in updating ppc/ BSP files, just to keep the right way. It does not look very neat now, but does the job of moving FW and keeping existing stuff sane. If there is better approach envisioned, I'll definitely follow..

And don't forget that the subsequent, follow-up patches will be to _remove_ the 85xx family from arch/ppc as well. The trick right now is simply to get it working in arch/powerpc so that we can move forward there. Worrying about absolute cleanliness in arch/ppc for 85xx shouldn't, in my opinion, be the highest concern.

Thanks,
jdl

#10 lore raw

Re: [PATCH 5/6] CPM_UART: unify clock sources

Quoted 13 lines · Jon Loeliger

So, like, the other day Vitaly Bordug mumbled:

Quoted 11 lines

That was my first guess as well, but:
The aim is yet moving to powerpc not to break existing ppc/ stuff. So if alternatively platform_data may be utilized, all relevant ppc stuff that uses cpm uart should be updated. While doing the driver "platformize" trick, I made it possible to keep legacy behaviour (pd-less), this is not going to afford such a thing.

IOW, I don't see much sense in updating ppc/ BSP files, just to keep the right way. It does not look very neat now, but does the job of moving FW and keeping existing stuff sane. If there is better approach envisioned, I'll definitely follow..

Quoted 6 lines

And don't forget that the subsequent, follow-up patches will be to _remove_ the 85xx family from arch/ppc as well. The trick right now is simply to get it working in arch/powerpc so that we can move forward there. Worrying about absolute cleanliness in arch/ppc for 85xx shouldn't, in my opinion, be the highest concern.

Its a concern until we have a way of booting existing 85xx systems w/their boot loaders using arch/powerpc kernels.

Also, CPM effects more than just 85xx so care needs to be taken for 8xx & 82xx.

- k

#11 lore raw

RFC PATCH 6/6 POWERPC: Add mpc8560 board support

In reply to a message not in the archive

This enables the mpc8560-specific bits in powerpc. The relevant cpm2 PIC and common utility were moved without or with minor changes, hereby not all the stuff have OF power utilized. Current functionality depends on the very latest fs_enet update, that will go through netdev (cc'd here as reference). Assuming all the preceeding stuff applied (PAL+fs_enet related
+ CPM_UART update), the both TSEC eth ,FCC Eths, and both SCC UARTs are working. The relevant drivers are still capable to drive users in ppc, which was verified with 8272ADS (SCC uart+FCC eth).

---

 arch/powerpc/lib/Makefile                 |    5 +
 arch/powerpc/platforms/85xx/Kconfig       |   11 +
 arch/powerpc/platforms/85xx/Makefile      |    1 
 arch/powerpc/platforms/85xx/mpc8560_ads.h |   54 +++++
 arch/powerpc/platforms/85xx/mpc85xx_ads.c |  107 +++++++++++
 arch/powerpc/sysdev/Makefile              |    7 +
 arch/powerpc/sysdev/cpm2_common.c         |  197 ++++++++++++++++++++
 arch/powerpc/sysdev/cpm2_pic.c            |  181 ++++++++++++++++++
 arch/powerpc/sysdev/cpm2_pic.h            |    8 +
 arch/powerpc/sysdev/fsl_soc.c             |  290 +++++++++++++++++++++++++++++
 include/asm-ppc/cpm2.h                    |    2 
 11 files changed, 860 insertions(+), 3 deletions(-)
arch/powerpc/lib/Makefile +5 -0
index ff70964..0993b3b 100644
@@ -21,3 +21,8 @@ ifeq ($(CONFIG_PPC64),y)
 obj-$(CONFIG_SMP)	+= locks.o
 obj-$(CONFIG_DEBUG_KERNEL) += sstep.o
 endif
+
+# Temporary hack until we have migrated to asm-powerpc
+ifeq ($(ARCH),powerpc)
+obj-$(CONFIG_CPM2)	+= rheap.o
+endif
arch/powerpc/platforms/85xx/Kconfig +11 -0
index 454fc53..3d440de 100644
@@ -11,6 +11,12 @@ config MPC8540_ADS
 	help
 	  This option enables support for the MPC 8540 ADS board
 
+config MPC8560_ADS
+	bool "Freescale MPC8560 ADS"
+	select DEFAULT_UIMAGE
+	help
+	  This option enables support for the MPC 8560 ADS board
+
 config MPC85xx_CDS
 	bool "Freescale MPC85xx CDS"
 	select DEFAULT_UIMAGE
@@ -25,6 +31,11 @@ config MPC8540
 	select PPC_UDBG_16550
 	select PPC_INDIRECT_PCI
 	default y if MPC8540_ADS || MPC85xx_CDS
+
+config MPC8560
+	bool
+	select PPC_INDIRECT_PCI
+	default y if MPC8560_ADS
 
 config PPC_INDIRECT_PCI_BE
 	bool
arch/powerpc/platforms/85xx/Makefile +1 -0
index 7615aa5..282f5d0 100644
@@ -3,4 +3,5 @@ # Makefile for the PowerPC 85xx linux ke
 #
 obj-$(CONFIG_PPC_85xx)	+= misc.o pci.o
 obj-$(CONFIG_MPC8540_ADS) += mpc85xx_ads.o
+obj-$(CONFIG_MPC8560_ADS) += mpc85xx_ads.o
 obj-$(CONFIG_MPC85xx_CDS) += mpc85xx_cds.o
arch/powerpc/platforms/85xx/mpc8560_ads.h new file +54 -0

54 lines not on this page · raw message

arch/powerpc/platforms/85xx/mpc85xx_ads.c +106 -1

154 lines not on this page · raw message

arch/powerpc/sysdev/Makefile +7 -0
index cef95b0..75dfe12 100644
@@ -12,3 +12,10 @@ obj-$(CONFIG_U3_DART)		+= dart_iommu.o
 obj-$(CONFIG_MMIO_NVRAM)	+= mmio_nvram.o
 obj-$(CONFIG_PPC_83xx)		+= ipic.o
 obj-$(CONFIG_FSL_SOC)		+= fsl_soc.o
+
+# Temporary hack until we have migrated to asm-powerpc
+ifeq ($(ARCH),powerpc)
+obj-$(CONFIG_CPM2)		+= cpm2_common.o cpm2_pic.o
+endif
+
+#obj-$(CONFIG_CPM2)		+= cpm2/			Yuri
arch/powerpc/sysdev/cpm2_common.c new file +197 -0

197 lines not on this page · raw message

arch/powerpc/sysdev/cpm2_pic.c new file +181 -0

181 lines not on this page · raw message

arch/powerpc/sysdev/cpm2_pic.h new file +8 -0
new file mode 100644
index 0000000..97cab8f
@@ -0,0 +1,8 @@
+#ifndef _PPC_KERNEL_CPM2_H
+#define _PPC_KERNEL_CPM2_H
+
+extern int cpm2_get_irq(struct pt_regs *regs);
+
+extern void cpm2_init_IRQ(void);
+
+#endif /* _PPC_KERNEL_CPM2_H */
arch/powerpc/sysdev/fsl_soc.c +289 -1

318 lines not on this page · raw message

include/asm-ppc/cpm2.h +1 -1
index f6a7ff0..8e6840b 100644
@@ -1186,7 +1186,7 @@ #define PC3_DIRC1	(PC3_TXDAT)
 #define FCC_MEM_OFFSET(x) (CPM_FCC_SPECIAL_BASE + (x*128))
 #define FCC1_MEM_OFFSET FCC_MEM_OFFSET(0)
 #define FCC2_MEM_OFFSET FCC_MEM_OFFSET(1)
-#define FCC2_MEM_OFFSET FCC_MEM_OFFSET(2)
+#define FCC3_MEM_OFFSET FCC_MEM_OFFSET(2)
 
 #endif /* __CPM2__ */
 #endif /* __KERNEL__ */
#12 lore raw

Re: [PATCH 6/6] [RFC] POWERPC: Add mpc8560 board support

Quoted 11 lines · Vitaly Bordug

This enables the mpc8560-specific bits in powerpc. The relevant cpm2 PIC and common utility were moved without or with minor changes, hereby not all the stuff have OF power utilized. Current functionality depends on the very latest fs_enet update, that will go through netdev (cc'd here as reference). Assuming all the preceeding stuff applied (PAL+fs_enet related
+ CPM_UART update), the both TSEC eth ,FCC Eths, and both SCC UARTs are
working. The relevant drivers are still capable to drive users in ppc, which was verified with 8272ADS (SCC uart+FCC eth).

Quoted 1 line

Can you break this patch up into its pieces (moving of cpm2* files), fsl_soc mods, 8560 additions.

Quoted 21 lines

---

 arch/powerpc/lib/Makefile                 |    5 +
 arch/powerpc/platforms/85xx/Kconfig       |   11 +
 arch/powerpc/platforms/85xx/Makefile      |    1
 arch/powerpc/platforms/85xx/mpc8560_ads.h |   54 +++++
 arch/powerpc/platforms/85xx/mpc85xx_ads.c |  107 +++++++++++
 arch/powerpc/sysdev/Makefile              |    7 +
 arch/powerpc/sysdev/cpm2_common.c         |  197 ++++++++++++++++++++
 arch/powerpc/sysdev/cpm2_pic.c            |  181 ++++++++++++++++++
 arch/powerpc/sysdev/cpm2_pic.h            |    8 +
 arch/powerpc/sysdev/fsl_soc.c             |  290 ++++++++++++++++++ 
+++++++++++
 include/asm-ppc/cpm2.h                    |    2
 11 files changed, 860 insertions(+), 3 deletions(-)
arch/powerpc/lib/Makefile +0 -0
index ff70964..0993b3b 100644

arch/powerpc/lib/Makefile ifeq ($(CONFIG_PPC64),y) · line 28

Quoted 8 lines
arch/powerpc/lib/Makefile +5 -0
@@ -21,3 +21,8 @@ ifeq ($(CONFIG_PPC64),y)
 obj-$(CONFIG_SMP)	+= locks.o
 obj-$(CONFIG_DEBUG_KERNEL) += sstep.o
 endif
+
+# Temporary hack until we have migrated to asm-powerpc
+ifeq ($(ARCH),powerpc)
+obj-$(CONFIG_CPM2)	+= rheap.o
+endif

Why not just move the file and build in arch/powerpc/lib/ for both arch/powerpc & arch/ppc. Same goes for cpm_* files.

Quoted 137 lines
arch/powerpc/platforms/85xx/Kconfig +11 -0
index 454fc53..3d440de 100644
@@ -11,6 +11,12 @@ config MPC8540_ADS
 	help
 	  This option enables support for the MPC 8540 ADS board
 
+config MPC8560_ADS
+	bool "Freescale MPC8560 ADS"
+	select DEFAULT_UIMAGE
+	help
+	  This option enables support for the MPC 8560 ADS board
+
 config MPC85xx_CDS
 	bool "Freescale MPC85xx CDS"
 	select DEFAULT_UIMAGE
@@ -25,6 +31,11 @@ config MPC8540
 	select PPC_UDBG_16550
 	select PPC_INDIRECT_PCI
 	default y if MPC8540_ADS || MPC85xx_CDS
+
+config MPC8560
+	bool
+	select PPC_INDIRECT_PCI
+	default y if MPC8560_ADS
 
 config PPC_INDIRECT_PCI_BE
 	bool
arch/powerpc/platforms/85xx/Makefile +1 -0
index 7615aa5..282f5d0 100644
@@ -3,4 +3,5 @@ # Makefile for the PowerPC 85xx linux ke
 #
 obj-$(CONFIG_PPC_85xx)	+= misc.o pci.o
 obj-$(CONFIG_MPC8540_ADS) += mpc85xx_ads.o
+obj-$(CONFIG_MPC8560_ADS) += mpc85xx_ads.o
 obj-$(CONFIG_MPC85xx_CDS) += mpc85xx_cds.o
arch/powerpc/platforms/85xx/mpc8560_ads.h new file +8 -0
new file mode 100644
index 0000000..4ebe710
@@ -0,0 +1,54 @@
+/*
+ * MPC8560ADS board definitions
+ *
+ * Maintainer: Kumar Gala <[email protected]>
+ *
+ * Copyright 2004 Freescale Semiconductor Inc.
+ *
+ * This program is free software; you can redistribute  it and/or  

modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */

arch/powerpc/platforms/85xx/mpc8560_ads.h new file +41 -0
+
+#ifndef __MACH_MPC8560ADS_H
+#define __MACH_MPC8560ADS_H
+
+#include <linux/config.h>
+#include <linux/initrd.h>
+
+#define BOARD_CCSRBAR		((uint)0xe0000000)
+#define BCSR_ADDR		((uint)0xf8000000)
+#define BCSR_SIZE		((uint)(32 * 1024))
+
+#define MPC85xx_CPM_OFFSET	(0x80000)
+
+/*XXX TODO: pull from OF*/
+#define CPM_MAP_ADDR		(BOARD_CCSRBAR + MPC85xx_CPM_OFFSET)
+
+/* PCI interrupt controller */
+#define PIRQA		MPC85xx_IRQ_EXT1
+#define PIRQB		MPC85xx_IRQ_EXT2
+#define PIRQC		MPC85xx_IRQ_EXT3
+#define PIRQD		MPC85xx_IRQ_EXT4
+
+/* FCC1 Clock Source Configuration.  These can be
+ * redefined in the board specific file.
+ *    Can only choose from CLK9-12 */
+#define F1_RXCLK       12
+#define F1_TXCLK       11
+
+/* FCC2 Clock Source Configuration.  These can be
+ * redefined in the board specific file.
+ *    Can only choose from CLK13-16 */
+#define F2_RXCLK       13
+#define F2_TXCLK       14
+
+/* FCC3 Clock Source Configuration.  These can be
+ * redefined in the board specific file.
+ *    Can only choose from CLK13-16 */
+#define F3_RXCLK       15
+#define F3_TXCLK       16
+
+#endif				/* __MACH_MPC8560ADS_H */
arch/powerpc/platforms/85xx/mpc85xx_ads.c +11 -0
index 5eeff37..352d0ae 100644
@@ -15,6 +15,7 @@ #include <linux/config.h>
 #include <linux/stddef.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
+#include <linux/interrupt.h>
 #include <linux/kdev_t.h>
 #include <linux/delay.h>
 #include <linux/seq_file.h>
@@ -30,6 +31,10 @@ #include <asm/mpic.h>
 #include <mm/mmu_decl.h>
 #include <asm/udbg.h>
 
+#ifdef CONFIG_CPM2
+#include <asm/cpm2.h>
+#endif
+
 #include <sysdev/fsl_soc.h>
 #include "mpc85xx.h"
 
@@ -121,8 +126,25 @@ mpc85xx_exclude_device(u_char bus, u_cha
 }
 
 #endif /* CONFIG_PCI */
+
+#ifdef CONFIG_CPM2
 
+static irqreturn_t cpm2_cascade(int irq, void *dev_id, struct  
 pt_regs *regs)
+{
+	while ((irq = cpm2_get_irq(regs)) >= 0)
+		__do_IRQ(irq, regs);

arch/powerpc/platforms/85xx/mpc85xx_ads.c mpc85xx_exclude_device(u_char bus, u_cha · line 146

Quoted 10 lines
arch/powerpc/platforms/85xx/mpc85xx_ads.c +9 -0
+	return IRQ_HANDLED;
+}
 
+static struct irqaction cpm2_irqaction = {
+	.handler = cpm2_cascade,
+	.flags = SA_INTERRUPT,
+	.mask = CPU_MASK_NONE,
+	.name = "cpm2_cascade",
+};
+

I'd prefer that we see Ben's new IRQ support before doing this, but ok for now.

Quoted 78 lines
arch/powerpc/platforms/85xx/mpc85xx_ads.c +2 -0
+#endif /* CONFIG_CPM2 */
+
 void __init mpc85xx_ads_pic_init(void)
 {
arch/powerpc/platforms/85xx/mpc85xx_ads.c +64 -1
 	struct mpic *mpic1;
@@ -158,15 +180,91 @@ void __init mpc85xx_ads_pic_init(void)
 	mpic_assign_isu(mpic1, 13, OpenPIC_PAddr + 0x10080);
 	mpic_assign_isu(mpic1, 14, OpenPIC_PAddr + 0x10100);
 	mpic_init(mpic1);
+
+#ifdef CONFIG_CPM2
+	/* Setup CPM2 PIC */
+
+        cpm2_init_IRQ();
+
+	setup_irq(MPC85xx_IRQ_CPM, &cpm2_irqaction);
+#endif
 }
 
 /*
  * Setup the architecture
- */
+ */
+static void init_fcc_ioports(void)
+{
+	struct immap *immap;
+	struct io_port *io;
+	u32 tempval;
+
+	immap = cpm2_immr;
+
+	io = &immap->im_ioport;
+	/* FCC2/3 are on the ports B/C. */
+	tempval = in_be32(&io->iop_pdirb);
+	tempval &= ~PB2_DIRB0;
+	tempval |= PB2_DIRB1;
+	out_be32(&io->iop_pdirb, tempval);
+
+	tempval = in_be32(&io->iop_psorb);
+	tempval &= ~PB2_PSORB0;
+	tempval |= PB2_PSORB1;
+	out_be32(&io->iop_psorb, tempval);
+
+	tempval = in_be32(&io->iop_pparb);
+	tempval |= (PB2_DIRB0 | PB2_DIRB1);
+	out_be32(&io->iop_pparb, tempval);
+
+	tempval = in_be32(&io->iop_pdirb);
+	tempval &= ~PB3_DIRB0;
+	tempval |= PB3_DIRB1;
+	out_be32(&io->iop_pdirb, tempval);
+
+	tempval = in_be32(&io->iop_psorb);
+	tempval &= ~PB3_PSORB0;
+	tempval |= PB3_PSORB1;
+	out_be32(&io->iop_psorb, tempval);
+
+	tempval = in_be32(&io->iop_pparb);
+	tempval |= (PB3_DIRB0 | PB3_DIRB1);
+	out_be32(&io->iop_pparb, tempval);
+
+	tempval = in_be32(&io->iop_pdirc);
+	tempval |= PC3_DIRC1;
+	out_be32(&io->iop_pdirc, tempval);
+
+	tempval = in_be32(&io->iop_pparc);
+	tempval |= PC3_DIRC1;
+	out_be32(&io->iop_pparc, tempval);
+
+	/* Port C has clocks......  */
+	tempval = in_be32(&io->iop_psorc);
+	tempval &= ~(CLK_TRX);
+	out_be32(&io->iop_psorc, tempval);
+
+	tempval = in_be32(&io->iop_pdirc);
+	tempval &= ~(CLK_TRX);
+	out_be32(&io->iop_pdirc, tempval);
+	tempval = in_be32(&io->iop_pparc);

arch/powerpc/platforms/85xx/mpc85xx_ads.c void __init mpc85xx_ads_pic_init(void) · line 260

Quoted 10 lines
arch/powerpc/platforms/85xx/mpc85xx_ads.c +10 -0
+	tempval |= (CLK_TRX);
+	out_be32(&io->iop_pparc, tempval);
+
+	/* Configure Serial Interface clock routing.
+	 * First,  clear all FCC bits to zero,
+	 * then set the ones we want.
+	 */
+	immap->im_cpmux.cmx_fcr &= ~(CPMUX_CLK_MASK);
+	immap->im_cpmux.cmx_fcr |= CPMUX_CLK_ROUTE;
+}

Can this be turned into some library function that uses some input that is board specific. U-boot has a table that looked like a reasonable approach.

Quoted 11 lines
arch/powerpc/platforms/85xx/mpc85xx_ads.c +3 -0
+
 static void __init mpc85xx_ads_setup_arch(void)
 {
 	struct device_node *cpu;
 	struct device_node *np;
+
+	cpm2_reset();
 
 	if (ppc_md.progress)
 		ppc_md.progress("mpc85xx_ads_setup_arch()", 0);

arch/powerpc/platforms/85xx/mpc85xx_ads.c static void __init mpc85xx_ads_setup_arc · line 291

Quoted 10 lines
arch/powerpc/platforms/85xx/mpc85xx_ads.c +5 -0
@@ -184,8 +282,13 @@ static void __init mpc85xx_ads_setup_arc
 	}
 
 #ifdef CONFIG_PCI
+
 	for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
 		add_bridge(np);
+
+#ifdef CONFIG_CPM2
+	init_fcc_ioports();
+#endif

This appears to be inside the CONFIG_PCI #ifdef, is that really what you want?

Quoted 15 lines
arch/powerpc/platforms/85xx/mpc85xx_ads.c +2 -0
 	ppc_md.pci_swizzle = common_swizzle;
 	ppc_md.pci_map_irq = mpc85xx_map_irq;
@@ -240,5 +343,7 @@ define_machine(mpc85xx_ads) {
 	.get_irq		= mpic_get_irq,
 	.restart		= mpc85xx_restart,
 	.calibrate_decr		= generic_calibrate_decr,
+#ifndef CONFIG_CPM2
 	.progress		= udbg_progress,
+#endif
 };
arch/powerpc/sysdev/Makefile +0 -0
index cef95b0..75dfe12 100644

arch/powerpc/sysdev/Makefile obj-$(CONFIG_U3_DART) += dart_iommu.o · line 19

Quoted 8 lines
arch/powerpc/sysdev/Makefile +5 -0
@@ -12,3 +12,10 @@ obj-$(CONFIG_U3_DART)		+= dart_iommu.o
 obj-$(CONFIG_MMIO_NVRAM)	+= mmio_nvram.o
 obj-$(CONFIG_PPC_83xx)		+= ipic.o
 obj-$(CONFIG_FSL_SOC)		+= fsl_soc.o
+
+# Temporary hack until we have migrated to asm-powerpc
+ifeq ($(ARCH),powerpc)
+obj-$(CONFIG_CPM2)		+= cpm2_common.o cpm2_pic.o
+endif

See earlier comments about just building in arch/powerpc

Quoted 46 lines
arch/powerpc/sysdev/Makefile +2 -0
+
+#obj-$(CONFIG_CPM2)		+= cpm2/			Yuri
arch/powerpc/sysdev/cpm2_common.c new file +38 -0
new file mode 100644
index 0000000..c755f65
@@ -0,0 +1,197 @@
+/*
+ * General Purpose functions for the global management of the
+ * 8260 Communication Processor Module.
+ * Copyright (c) 1999 Dan Malek ([email protected])
+ * Copyright (c) 2000 MontaVista Software, Inc ([email protected])
+ *	2.3.99 Updates
+ *
+ * In addition to the individual control of the communication
+ * channels, there are a few functions that globally affect the
+ * communication processor.
+ *
+ * Buffer descriptors must be allocated from the dual ported memory
+ * space.  The allocator for that is here.  When the communication
+ * process is reset, we reclaim the memory available.  There is
+ * currently no deallocator for this memory.
+ */
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/param.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/mpc8260.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+#include <asm/cpm2.h>
+#include <asm/rheap.h>
+
+static void cpm2_dpinit(void);
+cpm_cpm2_t	*cpmp;		/* Pointer to comm processor space */
+
+/* We allocate this here because it is used almost exclusively for
+ * the communication processor devices.
+ */

arch/powerpc/sysdev/cpm2_common.c line 48

Quoted 10 lines
arch/powerpc/sysdev/cpm2_common.c new file +10 -0
+cpm2_map_t *cpm2_immr;
+
+#define CPM_MAP_SIZE	(0x40000)	/* 256k - the PQ3 reserve this amount
+					   of space for CPM as it is larger
+					   than on PQ2 */
+
+void
+cpm2_reset(void)
+{
+	cpm2_immr = (cpm2_map_t *)ioremap(CPM_MAP_ADDR, CPM_MAP_SIZE);

You dont need the cast.

Quoted 404 lines
arch/powerpc/sysdev/cpm2_common.c new file +132 -0
+
+	/* Reclaim the DP memory for our use.
+	 */
+	cpm2_dpinit();
+
+	/* Tell everyone where the comm processor resides.
+	 */
+	cpmp = &cpm2_immr->im_cpm;
+}
+
+/* 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
+ * memory mapped space.
+ * The baud rate clock is the system clock divided by something.
+ * It was set up long ago during the initial boot phase and is
+ * is given to us.
+ * Baud rate clocks are zero-based in the driver code (as that maps
+ * to port numbers).  Documentation uses 1-based numbering.
+ */
+#define BRG_INT_CLK	(get_brgfreq())
+#define BRG_UART_CLK	(BRG_INT_CLK/16)
+
+/* This function is used by UARTS, or anything else that uses a 16x
+ * oversampled clock.
+ */
+void
+cpm_setbrg(uint brg, uint rate)
+{
+	volatile uint	*bp;
+
+	/* This is good enough to get SMCs running.....
+	*/
+	if (brg < 4) {
+		bp = (uint *)&cpm2_immr->im_brgc1;
+	}
+	else {
+		bp = (uint *)&cpm2_immr->im_brgc5;
+		brg -= 4;
+	}
+	bp += brg;
+	*bp = ((BRG_UART_CLK / rate) << 1) | CPM_BRG_EN;
+}
+
+/* This function is used to set high speed synchronous baud rate
+ * clocks.
+ */
+void
+cpm2_fastbrg(uint brg, uint rate, int div16)
+{
+	volatile uint	*bp;
+
+	if (brg < 4) {
+		bp = (uint *)&cpm2_immr->im_brgc1;
+	}
+	else {
+		bp = (uint *)&cpm2_immr->im_brgc5;
+		brg -= 4;
+	}
+	bp += brg;
+	*bp = ((BRG_INT_CLK / rate) << 1) | CPM_BRG_EN;
+	if (div16)
+		*bp |= CPM_BRG_DIV16;
+}
+
+/*
+ * dpalloc / dpfree bits.
+ */
+static spinlock_t cpm_dpmem_lock;
+/* 16 blocks should be enough to satisfy all requests
+ * until the memory subsystem goes up... */
+static rh_block_t cpm_boot_dpmem_rh_block[16];
+static rh_info_t cpm_dpmem_info;
+
+static void cpm2_dpinit(void)
+{
+	spin_lock_init(&cpm_dpmem_lock);
+
+	/* initialize the info header */
+	rh_init(&cpm_dpmem_info, 1,
+			sizeof(cpm_boot_dpmem_rh_block) /
+			sizeof(cpm_boot_dpmem_rh_block[0]),
+			cpm_boot_dpmem_rh_block);
+
+	/* Attach the usable dpmem area */
+	/* XXX: This is actually crap. CPM_DATAONLY_BASE and
+	 * CPM_DATAONLY_SIZE is only a subset of the available dpram. It
+	 * varies with the processor and the microcode patches activated.
+	 * But the following should be at least safe.
+	 */
+	rh_attach_region(&cpm_dpmem_info, (void *)CPM_DATAONLY_BASE,
+			CPM_DATAONLY_SIZE);
+}
+
+/* This function returns an index into the DPRAM area.
+ */
+uint cpm_dpalloc(uint size, uint align)
+{
+	void *start;
+	unsigned long flags;
+
+	spin_lock_irqsave(&cpm_dpmem_lock, flags);
+	cpm_dpmem_info.alignment = align;
+	start = rh_alloc(&cpm_dpmem_info, size, "commproc");
+	spin_unlock_irqrestore(&cpm_dpmem_lock, flags);
+
+	return (uint)start;
+}
+EXPORT_SYMBOL(cpm_dpalloc);
+
+int cpm_dpfree(uint offset)
+{
+	int ret;
+	unsigned long flags;
+
+	spin_lock_irqsave(&cpm_dpmem_lock, flags);
+	ret = rh_free(&cpm_dpmem_info, (void *)offset);
+	spin_unlock_irqrestore(&cpm_dpmem_lock, flags);
+
+	return ret;
+}
+EXPORT_SYMBOL(cpm_dpfree);
+
+/* not sure if this is ever needed */
+uint cpm_dpalloc_fixed(uint offset, uint size, uint align)
+{
+	void *start;
+	unsigned long flags;
+
+	spin_lock_irqsave(&cpm_dpmem_lock, flags);
+	cpm_dpmem_info.alignment = align;
+	start = rh_alloc_fixed(&cpm_dpmem_info, (void *)offset, size,  

"commproc");

arch/powerpc/sysdev/cpm2_common.c new file +17 -0
+	spin_unlock_irqrestore(&cpm_dpmem_lock, flags);
+
+	return (uint)start;
+}
+EXPORT_SYMBOL(cpm_dpalloc_fixed);
+
+void cpm_dpdump(void)
+{
+	rh_dump(&cpm_dpmem_info);
+}
+EXPORT_SYMBOL(cpm_dpdump);
+
+void *cpm_dpram_addr(uint offset)
+{
+	return (void *)&cpm2_immr->im_dprambase[offset];
+}
+EXPORT_SYMBOL(cpm_dpram_addr);
arch/powerpc/sysdev/cpm2_pic.c new file +36 -0
new file mode 100644
index 0000000..e0db594
@@ -0,0 +1,181 @@
+/* The CPM2 internal interrupt controller.  It is usually
+ * the only interrupt controller.
+ * There are two 32-bit registers (high/low) for up to 64
+ * possible interrupts.
+ *
+ * Now, the fun starts.....Interrupt Numbers DO NOT MAP
+ * in a simple arithmetic fashion to mask or pending registers.
+ * That is, interrupt 4 does not map to bit position 4.
+ * We create two tables, indexed by vector number, to indicate
+ * which register to use and which bit in the register to use.
+ */
+
+#include <linux/stddef.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/signal.h>
+#include <linux/irq.h>
+
+#include <asm/immap_cpm2.h>
+#include <asm/mpc8260.h>
+#include <asm/io.h>
+
+#include "cpm2_pic.h"
+
+static	u_char	irq_to_siureg[] = {
+	1, 1, 1, 1, 1, 1, 1, 1,
+	1, 1, 1, 1, 1, 1, 1, 1,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	1, 1, 1, 1, 1, 1, 1, 1,
+	1, 1, 1, 1, 1, 1, 1, 1,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/* bit numbers do not match the docs, these are precomputed so the  

bit for
+ * a given irq is (1 << irq_to_siubit[irq]) */

arch/powerpc/sysdev/cpm2_pic.c new file +144 -0
+static	u_char	irq_to_siubit[] = {
+	 0, 15, 14, 13, 12, 11, 10,  9,
+	 8,  7,  6,  5,  4,  3,  2,  1,
+	 2,  1,  0, 14, 13, 12, 11, 10,
+	 9,  8,  7,  6,  5,  4,  3,  0,
+	31, 30, 29, 28, 27, 26, 25, 24,
+	23, 22, 21, 20, 19, 18, 17, 16,
+	16, 17, 18, 19, 20, 21, 22, 23,
+	24, 25, 26, 27, 28, 29, 30, 31,
+};
+
+static void cpm2_mask_irq(unsigned int irq_nr)
+{
+	int	bit, word;
+	volatile uint	*simr;
+
+	irq_nr -= CPM_IRQ_OFFSET;
+
+	bit = irq_to_siubit[irq_nr];
+	word = irq_to_siureg[irq_nr];
+
+	simr = &(cpm2_immr->im_intctl.ic_simrh);
+	ppc_cached_irq_mask[word] &= ~(1 << bit);
+	simr[word] = ppc_cached_irq_mask[word];
+}
+
+static void cpm2_unmask_irq(unsigned int irq_nr)
+{
+	int	bit, word;
+	volatile uint	*simr;
+
+	irq_nr -= CPM_IRQ_OFFSET;
+
+	bit = irq_to_siubit[irq_nr];
+	word = irq_to_siureg[irq_nr];
+
+	simr = &(cpm2_immr->im_intctl.ic_simrh);
+	ppc_cached_irq_mask[word] |= 1 << bit;
+	simr[word] = ppc_cached_irq_mask[word];
+}
+
+static void cpm2_mask_and_ack(unsigned int irq_nr)
+{
+	int	bit, word;
+	volatile uint	*simr, *sipnr;
+
+	irq_nr -= CPM_IRQ_OFFSET;
+
+	bit = irq_to_siubit[irq_nr];
+	word = irq_to_siureg[irq_nr];
+
+	simr = &(cpm2_immr->im_intctl.ic_simrh);
+	sipnr = &(cpm2_immr->im_intctl.ic_sipnrh);
+	ppc_cached_irq_mask[word] &= ~(1 << bit);
+	simr[word] = ppc_cached_irq_mask[word];
+	sipnr[word] = 1 << bit;
+}
+
+static void cpm2_end_irq(unsigned int irq_nr)
+{
+	int	bit, word;
+	volatile uint	*simr;
+
+	if (!(irq_desc[irq_nr].status & (IRQ_DISABLED|IRQ_INPROGRESS))
+			&& irq_desc[irq_nr].action) {
+
+		irq_nr -= CPM_IRQ_OFFSET;
+		bit = irq_to_siubit[irq_nr];
+		word = irq_to_siureg[irq_nr];
+
+		simr = &(cpm2_immr->im_intctl.ic_simrh);
+		ppc_cached_irq_mask[word] |= 1 << bit;
+		simr[word] = ppc_cached_irq_mask[word];
+		/*
+		 * Work around large numbers of spurious IRQs on PowerPC 82xx
+		 * systems.
+		 */
+		mb();
+	}
+}
+
+static struct hw_interrupt_type cpm2_pic = {
+	.typename = " CPM2 SIU ",
+	.enable = cpm2_unmask_irq,
+	.disable = cpm2_mask_irq,
+	.ack = cpm2_mask_and_ack,
+	.end = cpm2_end_irq,
+};
+
+int cpm2_get_irq(struct pt_regs *regs)
+{
+	int irq;
+        unsigned long bits;
+
+        /* For CPM2, read the SIVEC register and shift the bits down
+         * to get the irq number.         */
+        bits = cpm2_immr->im_intctl.ic_sivec;
+        irq = bits >> 26;
+
+	if (irq == 0)
+		return(-1);
+	return irq+CPM_IRQ_OFFSET;
+}
+
+void cpm2_init_IRQ(void)
+{
+	int i;
+	u32 addr;
+
+	/* Clear the CPM IRQ controller, in case it has any bits set
+	 * from the bootloader
+	 */
+
+	/* Mask out everything */
+
+	cpm2_immr->im_intctl.ic_simrh = 0x00000000;
+	cpm2_immr->im_intctl.ic_simrl = 0x00000000;
+
+	wmb();
+
+	/* Ack everything */
+	cpm2_immr->im_intctl.ic_sipnrh = 0xffffffff;
+	cpm2_immr->im_intctl.ic_sipnrl = 0xffffffff;
+	wmb();
+
+	/* Dummy read of the vector */
+	i = cpm2_immr->im_intctl.ic_sivec;
+	rmb();
+
+	/* Initialize the default interrupt mapping priorities,
+	 * in case the boot rom changed something on us.
+	 */
+	cpm2_immr->im_intctl.ic_sicr = 0;
+	cpm2_immr->im_intctl.ic_scprrh = 0x05309770;
+	cpm2_immr->im_intctl.ic_scprrl = 0x05309770;
+
+
+	/* Enable chaining to OpenPIC, and make everything level
+	 */
+	for (i = 0; i < NR_CPM_INTS; i++) {
+		irq_desc[i+CPM_IRQ_OFFSET].handler = &cpm2_pic;
+		irq_desc[i+CPM_IRQ_OFFSET].status |= IRQ_LEVEL;
+	}
+}
arch/powerpc/sysdev/cpm2_pic.h new file +8 -0
new file mode 100644
index 0000000..97cab8f
@@ -0,0 +1,8 @@
+#ifndef _PPC_KERNEL_CPM2_H
+#define _PPC_KERNEL_CPM2_H
+
+extern int cpm2_get_irq(struct pt_regs *regs);
+
+extern void cpm2_init_IRQ(void);
+
+#endif /* _PPC_KERNEL_CPM2_H */
arch/powerpc/sysdev/fsl_soc.c +22 -1
index ceb5846..bab202d 100644
@@ -21,6 +21,8 @@ #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/platform_device.h>
 #include <linux/fsl_devices.h>
+#include <linux/fs_enet_pd.h>
+#include <linux/fs_uart_pd.h>
 
 #include <asm/system.h>
 #include <asm/atomic.h>
@@ -30,6 +32,10 @@ #include <asm/prom.h>
 #include <sysdev/fsl_soc.h>
 #include <mm/mmu_decl.h>
 
+#ifdef CONFIG_CPM2
+#include <asm/cpm2.h>
+#endif
+
 static phys_addr_t immrbase = -1;
 
 phys_addr_t get_immrbase(void)
@@ -43,7 +49,9 @@ phys_addr_t get_immrbase(void)
 	if (soc) {
 		unsigned int size;
 		void *prop = get_property(soc, "reg", &size);
-		immrbase = of_translate_address(soc, prop);
+
+		if (prop)
+			immrbase = of_translate_address(soc, prop);
 		of_node_put(soc);
 	};
 
@@ -51,7 +59,79 @@ phys_addr_t get_immrbase(void)
 }
 
 EXPORT_SYMBOL(get_immrbase);
+
+static u32 brgfreq = -1;
+
+u32 get_brgfreq(void)
+{
+	struct device_node *node;
+
+	if (brgfreq != -1)
+		return brgfreq;
+
+	node = of_find_node_by_type(NULL, "serial");
+	if (node) {
+		unsigned int size;

arch/powerpc/sysdev/fsl_soc.c phys_addr_t get_immrbase(void) · line 84

Quoted 10 lines
arch/powerpc/sysdev/fsl_soc.c +9 -0
+		unsigned int *prop = (unsigned int*)get_property(node, "clock- 
 frequency", &size);
+
+		if (prop)
+			brgfreq = *prop;
+		of_node_put(node);
+	};
+
+	return brgfreq;
+}

These seems broken on a system w/both CPM & 8250 style uarts.

Quoted 42 lines
arch/powerpc/sysdev/fsl_soc.c +39 -0
+
+EXPORT_SYMBOL(get_brgfreq);
+
+static u32 fs_baudrate = -1;
+
+u32 get_baudrate(void)
+{
+	struct device_node *node;
 
+	if (fs_baudrate != -1)
+		return fs_baudrate;
+
+	node = of_find_node_by_type(NULL, "serial");
+	if (node) {
+		unsigned int size;
+		unsigned int *prop = (unsigned int*)get_property(node, "current- 
 speed", &size);
+
+		if (prop)
+			fs_baudrate = *prop;
+		of_node_put(node);
+	};
+
+	return fs_baudrate;
+}
+
+EXPORT_SYMBOL(get_baudrate);
+
+static u32 intfreq = -1;
+
+u32 get_intfreq(void)
+{
+	struct device_node *node;
+
+	if (intfreq != -1)
+		return intfreq;
+
+	node = of_find_node_by_type(NULL, "cpu");
+	if (node) {
+		unsigned int size;
+		unsigned int *prop = (unsigned int*)get_property(node, "clock- 
 frequency", &size);

arch/powerpc/sysdev/fsl_soc.c phys_addr_t get_immrbase(void) · line 133

Quoted 10 lines
arch/powerpc/sysdev/fsl_soc.c +10 -0
+		if (prop)
+			intfreq = *prop;
+		of_node_put(node);
+	}
+
+	return intfreq;
+}
+
+EXPORT_SYMBOL(get_intfreq);
+

Don't we have something that reports "clock-frequency" elsewhere?

Quoted 116 lines
arch/powerpc/sysdev/fsl_soc.c +1 -0
+

static int __init gfar_mdio_of_init(void)
{

arch/powerpc/sysdev/fsl_soc.c +16 -0
 	struct device_node *np;
@@ -491,3 +571,211 @@ err:
 }
 
 arch_initcall(fsl_usb_dr_of_init);
+
+static const char *fcc_regs = "fcc_regs";
+static const char *fcc_regs_c = "fcc_regs_c";
+static const char *fcc_pram = "fcc_pram";
+static char bus_id[9][BUS_ID_SIZE];
+
+static int __init fs_enet_of_init(void)
+{
+	struct device_node *np;
+	unsigned int i;
+	struct platform_device *fs_enet_dev;
+	struct resource res;
+	int ret;
+
+	for (np = NULL, i = 0;
+	     (np = of_find_compatible_node(np, "network", "fs_enet")) !=  

NULL;

arch/powerpc/sysdev/fsl_soc.c +74 -0
+	     i++) {
+		struct resource r[4];
+		struct device_node *phy, *mdio;
+		struct fs_platform_info fs_enet_data;
+		unsigned int *id, *phy_addr;
+		void *mac_addr;
+		phandle *ph;
+		char *model;
+
+		memset(r, 0, sizeof(r));
+		memset(&fs_enet_data, 0, sizeof(fs_enet_data));
+
+		ret = of_address_to_resource(np, 0, &r[0]);
+		if (ret)
+			goto err;
+		r[0].name = fcc_regs;
+
+		ret = of_address_to_resource(np, 1, &r[1]);
+		if (ret)
+			goto err;
+		r[1].name = fcc_pram;
+
+		ret = of_address_to_resource(np, 2, &r[2]);
+		if (ret)
+			goto err;
+		r[2].name = fcc_regs_c;
+
+		r[3].start = np->intrs[0].line;
+		r[3].end = np->intrs[0].line;
+		r[3].flags = IORESOURCE_IRQ;
+
+		fs_enet_dev =
+		    platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
+
+		if (IS_ERR(fs_enet_dev)) {
+			ret = PTR_ERR(fs_enet_dev);
+			goto err;
+		}
+
+		model = get_property(np, "model", NULL);
+		if (model == NULL) {
+			ret = -ENODEV;
+			goto unreg;
+		}
+
+		mac_addr = get_property(np, "mac-address", NULL);
+		memcpy(fs_enet_data.macaddr, mac_addr, 6);
+
+		ph = (phandle *) get_property(np, "phy-handle", NULL);
+		phy = of_find_node_by_phandle(*ph);
+
+		if (phy == NULL) {
+			ret = -ENODEV;
+			goto unreg;
+		}
+
+		phy_addr = (u32 *) get_property(phy, "reg", NULL);
+		fs_enet_data.phy_addr = *phy_addr;
+
+		id = (u32 *) get_property(np, "device-id", NULL);
+		fs_enet_data.fs_no = *id;
+
+		mdio = of_get_parent(phy);
+                ret = of_address_to_resource(mdio, 0, &res);
+                if (ret) {
+                        of_node_put(phy);
+                        of_node_put(mdio);
+                        goto unreg;
+                }
+
+		switch (*id) {
+		case fsid_fcc1:
+			fs_enet_data.mem_offset = FCC1_MEM_OFFSET,
+			snprintf((char*)&bus_id[2], BUS_ID_SIZE, "%x:%02x", (u32) 

res.start, fs_enet_data.phy_addr);

arch/powerpc/sysdev/fsl_soc.c +7 -0
+			fs_enet_data.bus_id = (char*)&bus_id[2];
+			fs_enet_data.cp_page = CPM_CR_FCC1_PAGE;
+			fs_enet_data.cp_block = CPM_CR_FCC1_SBLOCK;
+			break;
+		case fsid_fcc2:
+			fs_enet_data.mem_offset = FCC2_MEM_OFFSET,
+			snprintf((char*)&bus_id[3], BUS_ID_SIZE, "%x:%02x", (u32) 

res.start, fs_enet_data.phy_addr);

arch/powerpc/sysdev/fsl_soc.c +7 -0
+			fs_enet_data.bus_id = (char*)&bus_id[3];
+			fs_enet_data.cp_page = CPM_CR_FCC2_PAGE;
+			fs_enet_data.cp_block = CPM_CR_FCC2_SBLOCK;
+			break;
+		case fsid_fcc3:
+			fs_enet_data.mem_offset = FCC3_MEM_OFFSET,
+			snprintf((char*)&bus_id[4], BUS_ID_SIZE, "%x:%02x", (u32) 

res.start, fs_enet_data.phy_addr);

arch/powerpc/sysdev/fsl_soc.c err: · line 682

Quoted 5 lines
arch/powerpc/sysdev/fsl_soc.c +5 -0
+			fs_enet_data.bus_id = (char*)&bus_id[4];
+			fs_enet_data.cp_page = CPM_CR_FCC3_PAGE;
+			fs_enet_data.cp_block = CPM_CR_FCC3_SBLOCK;
+			break;
+		}

this looks like a lot of effort to just encode a single integer (1, 2, 3) and then lookup the other information based on it.

Quoted 118 lines
arch/powerpc/sysdev/fsl_soc.c +42 -0
+
+		if (strstr(model, "FCC")) {
+			fs_enet_data.dpram_offset = (u32)cpm2_immr->im_dprambase;
+			fs_enet_data.rx_ring = 32;
+			fs_enet_data.tx_ring = 32;
+			fs_enet_data.rx_copybreak = 240;
+			fs_enet_data.use_napi = 0;
+			fs_enet_data.napi_weight = 17;
+		}
+
+		of_node_put(phy);
+		of_node_put(mdio);
+
+		ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
+					     sizeof(struct
+						    fs_platform_info));
+		if (ret)
+			goto unreg;
+	}
+	return 0;
+
+unreg:
+	platform_device_unregister(fs_enet_dev);
+err:
+	return ret;
+}
+
+arch_initcall(fs_enet_of_init);
+
+static const char *scc_regs = "regs";
+static const char *scc_pram = "pram";
+
+static int __init cpm_uart_of_init(void)
+{
+	struct device_node *np;
+	unsigned int i;
+	struct platform_device *cpm_uart_dev;
+	int ret;
+
+
+	for (np = NULL, i = 0;
+	     (np = of_find_compatible_node(np, "serial", "cpm_uart")) !=  

NULL;

arch/powerpc/sysdev/fsl_soc.c +25 -0
+	     i++) {
+		struct resource r[3];
+		struct fs_uart_platform_info cpm_uart_data;
+		int *id;
+
+		memset(r, 0, sizeof(r));
+		memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
+
+		ret = of_address_to_resource(np, 0, &r[0]);
+		if (ret)
+			goto err;
+
+		r[0].name = scc_regs;
+
+		ret = of_address_to_resource(np, 1, &r[1]);
+		if (ret)
+			goto err;
+		r[1].name = scc_pram;
+
+		r[2].start = np->intrs[0].line;
+		r[2].end = np->intrs[0].line;
+		r[2].flags = IORESOURCE_IRQ;
+
+		cpm_uart_dev =
+		    platform_device_register_simple("fsl-cpm-scc:uart", i, &r 

[0], 3);

arch/powerpc/sysdev/fsl_soc.c +32 -0
+
+		if (IS_ERR(cpm_uart_dev)) {
+			ret = PTR_ERR(cpm_uart_dev);
+			goto err;
+		}
+
+		id = get_property(np, "device-id", NULL);
+		cpm_uart_data.fs_no = *id;
+		cpm_uart_data.uart_clk = get_intfreq();
+
+		cpm_uart_data.tx_num_fifo = 4;
+		cpm_uart_data.tx_buf_size = 32;
+		cpm_uart_data.rx_num_fifo = 4;
+		cpm_uart_data.rx_buf_size = 32;
+
+		ret =
+		    platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
+					     sizeof(struct
+						    fs_uart_platform_info));
+		if (ret)
+			goto unreg;
+	}
+
+	return 0;
+
+unreg:
+	platform_device_unregister(cpm_uart_dev);
+err:
+	return ret;
+}
+
+arch_initcall(cpm_uart_of_init);
include/asm-ppc/cpm2.h +1 -1
index f6a7ff0..8e6840b 100644
@@ -1186,7 +1186,7 @@ #define PC3_DIRC1	(PC3_TXDAT)
 #define FCC_MEM_OFFSET(x) (CPM_FCC_SPECIAL_BASE + (x*128))
 #define FCC1_MEM_OFFSET FCC_MEM_OFFSET(0)
 #define FCC2_MEM_OFFSET FCC_MEM_OFFSET(1)
-#define FCC2_MEM_OFFSET FCC_MEM_OFFSET(2)
+#define FCC3_MEM_OFFSET FCC_MEM_OFFSET(2)
 
 #endif /* __CPM2__ */
 #endif /* __KERNEL__ */

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#13 lore raw

Re: [PATCH 6/6] [RFC] POWERPC: Add mpc8560 board support

На Sat, 24 Jun 2006 11:26:01 -0500
Kumar Gala <[email protected]> записано:

Quoted 18 lines · Vitaly Bordug
Quoted 16 lines

This enables the mpc8560-specific bits in powerpc. The relevant cpm2 PIC
and common utility were moved without or with minor changes, hereby not all
the stuff have OF power utilized. Current functionality depends on the very
latest fs_enet update, that will go through netdev (cc'd here as reference). Assuming all the preceeding stuff applied (PAL+fs_enet related
+ CPM_UART update), the both TSEC eth ,FCC Eths, and both SCC UARTs are
working. The relevant drivers are still capable to drive users in ppc, which was verified with 8272ADS (SCC uart+FCC eth).

Quoted 4 lines
Quoted 1 line

Can you break this patch up into its pieces (moving of cpm2* files), fsl_soc mods, 8560 additions.

OK.

Quoted 17 lines
Quoted 17 lines

---

 arch/powerpc/lib/Makefile                 |    5 +
 arch/powerpc/platforms/85xx/Kconfig       |   11 +
 arch/powerpc/platforms/85xx/Makefile      |    1
 arch/powerpc/platforms/85xx/mpc8560_ads.h |   54 +++++
 arch/powerpc/platforms/85xx/mpc85xx_ads.c |  107 +++++++++++
 arch/powerpc/sysdev/Makefile              |    7 +
 arch/powerpc/sysdev/cpm2_common.c         |  197

++++++++++++++++++++ arch/powerpc/sysdev/cpm2_pic.c |
181 ++++++++++++++++++ arch/powerpc/sysdev/cpm2_pic.h
| 8 + arch/powerpc/sysdev/fsl_soc.c | 290
++++++++++++++++++ +++++++++++

 include/asm-ppc/cpm2.h                    |    2
 11 files changed, 860 insertions(+), 3 deletions(-)
Quoted 17 lines

arch/powerpc/lib/Makefile ifeq ($(CONFIG_PPC64),y) · line 28

Quoted 13 lines
arch/powerpc/lib/Makefile +5 -0
index ff70964..0993b3b 100644
@@ -21,3 +21,8 @@ ifeq ($(CONFIG_PPC64),y)
 obj-$(CONFIG_SMP)	+= locks.o
 obj-$(CONFIG_DEBUG_KERNEL) += sstep.o
 endif
+
+# Temporary hack until we have migrated to asm-powerpc
+ifeq ($(ARCH),powerpc)
+obj-$(CONFIG_CPM2)	+= rheap.o
+endif

Why not just move the file and build in arch/powerpc/lib/ for both arch/powerpc & arch/ppc. Same goes for cpm_* files.

Makes sense to me...

Quoted 239 lines
Quoted 141 lines
arch/powerpc/ renamed from arch/powerpc/platforms/85xx/Kconfig +0 -0

platforms/85xx/Kconfig
index 454fc53..3d440de 100644

arch/powerpc/platforms/85xx/Kconfig +11 -0
@@ -11,6 +11,12 @@ config MPC8540_ADS
 	help
 	  This option enables support for the MPC 8540 ADS board
 
+config MPC8560_ADS
+	bool "Freescale MPC8560 ADS"
+	select DEFAULT_UIMAGE
+	help
+	  This option enables support for the MPC 8560 ADS board
+
 config MPC85xx_CDS
 	bool "Freescale MPC85xx CDS"
 	select DEFAULT_UIMAGE
@@ -25,6 +31,11 @@ config MPC8540
 	select PPC_UDBG_16550
 	select PPC_INDIRECT_PCI
 	default y if MPC8540_ADS || MPC85xx_CDS
+
+config MPC8560
+	bool
+	select PPC_INDIRECT_PCI
+	default y if MPC8560_ADS
 
 config PPC_INDIRECT_PCI_BE
 	bool
arch/powerpc/ renamed from arch/powerpc/platforms/85xx/Makefile +0 -0

platforms/85xx/Makefile
index 7615aa5..282f5d0 100644

arch/powerpc/platforms/85xx/Makefile +1 -0
@@ -3,4 +3,5 @@ # Makefile for the PowerPC 85xx linux ke
 #
 obj-$(CONFIG_PPC_85xx)	+= misc.o pci.o
 obj-$(CONFIG_MPC8540_ADS) += mpc85xx_ads.o
+obj-$(CONFIG_MPC8560_ADS) += mpc85xx_ads.o
 obj-$(CONFIG_MPC85xx_CDS) += mpc85xx_cds.o
arch/ renamed from arch/powerpc/platforms/85xx/mpc8560_ads.h +0 -0

powerpc/platforms/85xx/mpc8560_ads.h
new file mode 100644
index 0000000..4ebe710

arch/powerpc/platforms/85xx/mpc8560_ads.h new file +8 -0
@@ -0,0 +1,54 @@
+/*
+ * MPC8560ADS board definitions
+ *
+ * Maintainer: Kumar Gala <[email protected]>
+ *
+ * Copyright 2004 Freescale Semiconductor Inc.
+ *
+ * This program is free software; you can redistribute  it and/or  

modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */

arch/powerpc/platforms/85xx/mpc8560_ads.h new file +15 -0
+
+#ifndef __MACH_MPC8560ADS_H
+#define __MACH_MPC8560ADS_H
+
+#include <linux/config.h>
+#include <linux/initrd.h>
+
+#define BOARD_CCSRBAR		((uint)0xe0000000)
+#define BCSR_ADDR		((uint)0xf8000000)
+#define BCSR_SIZE		((uint)(32 * 1024))
+
+#define MPC85xx_CPM_OFFSET	(0x80000)
+
+/*XXX TODO: pull from OF*/
+#define CPM_MAP_ADDR		(BOARD_CCSRBAR +

MPC85xx_CPM_OFFSET) +

arch/powerpc/platforms/85xx/mpc8560_ads.h new file +25 -0
+/* PCI interrupt controller */
+#define PIRQA		MPC85xx_IRQ_EXT1
+#define PIRQB		MPC85xx_IRQ_EXT2
+#define PIRQC		MPC85xx_IRQ_EXT3
+#define PIRQD		MPC85xx_IRQ_EXT4
+
+/* FCC1 Clock Source Configuration.  These can be
+ * redefined in the board specific file.
+ *    Can only choose from CLK9-12 */
+#define F1_RXCLK       12
+#define F1_TXCLK       11
+
+/* FCC2 Clock Source Configuration.  These can be
+ * redefined in the board specific file.
+ *    Can only choose from CLK13-16 */
+#define F2_RXCLK       13
+#define F2_TXCLK       14
+
+/* FCC3 Clock Source Configuration.  These can be
+ * redefined in the board specific file.
+ *    Can only choose from CLK13-16 */
+#define F3_RXCLK       15
+#define F3_TXCLK       16
+
+#endif				/* __MACH_MPC8560ADS_H */
arch/ renamed from arch/powerpc/platforms/85xx/mpc85xx_ads.c +0 -0

powerpc/platforms/85xx/mpc85xx_ads.c
index 5eeff37..352d0ae 100644

arch/powerpc/platforms/85xx/mpc85xx_ads.c +11 -0
@@ -15,6 +15,7 @@ #include <linux/config.h>
 #include <linux/stddef.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
+#include <linux/interrupt.h>
 #include <linux/kdev_t.h>
 #include <linux/delay.h>
 #include <linux/seq_file.h>
@@ -30,6 +31,10 @@ #include <asm/mpic.h>
 #include <mm/mmu_decl.h>
 #include <asm/udbg.h>
 
+#ifdef CONFIG_CPM2
+#include <asm/cpm2.h>
+#endif
+
 #include <sysdev/fsl_soc.h>
 #include "mpc85xx.h"
 
@@ -121,8 +126,25 @@ mpc85xx_exclude_device(u_char bus, u_cha
 }
 
 #endif /* CONFIG_PCI */
+
+#ifdef CONFIG_CPM2
 
+static irqreturn_t cpm2_cascade(int irq, void *dev_id, struct  
 pt_regs *regs)
+{
+	while ((irq = cpm2_get_irq(regs)) >= 0)
+		__do_IRQ(irq, regs);

arch/powerpc/platforms/85xx/mpc85xx_ads.c mpc85xx_exclude_device(u_char bus, u_cha · line 146

Quoted 10 lines
arch/powerpc/platforms/85xx/mpc85xx_ads.c +9 -0
+	return IRQ_HANDLED;
+}
 
+static struct irqaction cpm2_irqaction = {
+	.handler = cpm2_cascade,
+	.flags = SA_INTERRUPT,
+	.mask = CPU_MASK_NONE,
+	.name = "cpm2_cascade",
+};
+

I'd prefer that we see Ben's new IRQ support before doing this, but ok for now.

Quoted 84 lines
arch/powerpc/platforms/85xx/mpc85xx_ads.c +2 -0
+#endif /* CONFIG_CPM2 */
+
 void __init mpc85xx_ads_pic_init(void)
 {
arch/powerpc/platforms/85xx/mpc85xx_ads.c +70 -1
 	struct mpic *mpic1;
@@ -158,15 +180,91 @@ void __init mpc85xx_ads_pic_init(void)
 	mpic_assign_isu(mpic1, 13, OpenPIC_PAddr + 0x10080);
 	mpic_assign_isu(mpic1, 14, OpenPIC_PAddr + 0x10100);
 	mpic_init(mpic1);
+
+#ifdef CONFIG_CPM2
+	/* Setup CPM2 PIC */
+
+        cpm2_init_IRQ();
+
+	setup_irq(MPC85xx_IRQ_CPM, &cpm2_irqaction);
+#endif
 }
 
 /*
  * Setup the architecture
- */
+ */
+static void init_fcc_ioports(void)
+{
+	struct immap *immap;
+	struct io_port *io;
+	u32 tempval;
+
+	immap = cpm2_immr;
+
+	io = &immap->im_ioport;
+	/* FCC2/3 are on the ports B/C. */
+	tempval = in_be32(&io->iop_pdirb);
+	tempval &= ~PB2_DIRB0;
+	tempval |= PB2_DIRB1;
+	out_be32(&io->iop_pdirb, tempval);
+
+	tempval = in_be32(&io->iop_psorb);
+	tempval &= ~PB2_PSORB0;
+	tempval |= PB2_PSORB1;
+	out_be32(&io->iop_psorb, tempval);
+
+	tempval = in_be32(&io->iop_pparb);
+	tempval |= (PB2_DIRB0 | PB2_DIRB1);
+	out_be32(&io->iop_pparb, tempval);
+
+	tempval = in_be32(&io->iop_pdirb);
+	tempval &= ~PB3_DIRB0;
+	tempval |= PB3_DIRB1;
+	out_be32(&io->iop_pdirb, tempval);
+
+	tempval = in_be32(&io->iop_psorb);
+	tempval &= ~PB3_PSORB0;
+	tempval |= PB3_PSORB1;
+	out_be32(&io->iop_psorb, tempval);
+
+	tempval = in_be32(&io->iop_pparb);
+	tempval |= (PB3_DIRB0 | PB3_DIRB1);
+	out_be32(&io->iop_pparb, tempval);
+
+	tempval = in_be32(&io->iop_pdirc);
+	tempval |= PC3_DIRC1;
+	out_be32(&io->iop_pdirc, tempval);
+
+	tempval = in_be32(&io->iop_pparc);
+	tempval |= PC3_DIRC1;
+	out_be32(&io->iop_pparc, tempval);
+
+	/* Port C has clocks......  */
+	tempval = in_be32(&io->iop_psorc);
+	tempval &= ~(CLK_TRX);
+	out_be32(&io->iop_psorc, tempval);
+
+	tempval = in_be32(&io->iop_pdirc);
+	tempval &= ~(CLK_TRX);
+	out_be32(&io->iop_pdirc, tempval);
+	tempval = in_be32(&io->iop_pparc);
+	tempval |= (CLK_TRX);
+	out_be32(&io->iop_pparc, tempval);
+
+	/* Configure Serial Interface clock routing.
+	 * First,  clear all FCC bits to zero,
+	 * then set the ones we want.
Quoted 9 lines

arch/powerpc/platforms/85xx/mpc85xx_ads.c void __init mpc85xx_ads_pic_init(void) · line 260

Quoted 4 lines
arch/powerpc/platforms/85xx/mpc85xx_ads.c +4 -0
+	 */
+	immap->im_cpmux.cmx_fcr &= ~(CPMUX_CLK_MASK);
+	immap->im_cpmux.cmx_fcr |= CPMUX_CLK_ROUTE;
+}

Can this be turned into some library function that uses some input that is board specific. U-boot has a table that looked like a reasonable approach.

It's in TBD list, but not of high urgency fairly. The approach will be what Dan suggested long ago - pmac-like feature_call that will behave like sort of BSP ioctl(). Guess it will be good as a next step after actual merge...

Quoted 13 lines
Quoted 13 lines
arch/powerpc/platforms/85xx/mpc85xx_ads.c +3 -0
+
 static void __init mpc85xx_ads_setup_arch(void)
 {
 	struct device_node *cpu;
 	struct device_node *np;
+
+	cpm2_reset();
 
 	if (ppc_md.progress)
 		ppc_md.progress("mpc85xx_ads_setup_arch()", 0);
@@ -184,8 +282,13 @@ static void __init mpc85xx_ads_setup_arc
 	}
 
Quoted 12 lines

arch/powerpc/platforms/85xx/mpc85xx_ads.c static void __init mpc85xx_ads_setup_arc · line 291

Quoted 8 lines
arch/powerpc/platforms/85xx/mpc85xx_ads.c +5 -0
 #ifdef CONFIG_PCI
+
 	for (np = NULL; (np = of_find_node_by_type(np, "pci")) !=
 NULL;) add_bridge(np);
+
+#ifdef CONFIG_CPM2
+	init_fcc_ioports();
+#endif

This appears to be inside the CONFIG_PCI #ifdef, is that really what you want?

touché :) Will fix...

Quoted 18 lines
Quoted 18 lines
arch/powerpc/platforms/85xx/mpc85xx_ads.c +2 -0
 	ppc_md.pci_swizzle = common_swizzle;
 	ppc_md.pci_map_irq = mpc85xx_map_irq;
@@ -240,5 +343,7 @@ define_machine(mpc85xx_ads) {
 	.get_irq		= mpic_get_irq,
 	.restart		= mpc85xx_restart,
 	.calibrate_decr		= generic_calibrate_decr,
+#ifndef CONFIG_CPM2
 	.progress		= udbg_progress,
+#endif
 };
arch/powerpc/sysdev/ renamed from arch/powerpc/sysdev/Makefile +0 -0

Makefile
index cef95b0..75dfe12 100644

arch/powerpc/sysdev/Makefile +0 -0
@@ -12,3 +12,10 @@ obj-$(CONFIG_U3_DART)		+=

dart_iommu.o obj-$(CONFIG_MMIO_NVRAM) += mmio_nvram.o
obj-$(CONFIG_PPC_83xx) += ipic.o

Quoted 9 lines

arch/powerpc/sysdev/Makefile obj-$(CONFIG_U3_DART) += dart_iommu.o · line 19

Quoted 6 lines

obj-$(CONFIG_FSL_SOC) += fsl_soc.o

arch/powerpc/sysdev/Makefile +5 -0
+
+# Temporary hack until we have migrated to asm-powerpc
+ifeq ($(ARCH),powerpc)
+obj-$(CONFIG_CPM2)		+= cpm2_common.o cpm2_pic.o
+endif

See earlier comments about just building in arch/powerpc

Hrm, here I am not completely sure it's a good thing. The point is that currently some OF-specific stuff is under construction to go into cpm2_common at least (for instance, getting rid of CPM_MAP_ADDR ioremap because the offset is available via oftree, and things like that).

Quoted 54 lines
Quoted 54 lines
arch/powerpc/sysdev/Makefile +2 -0
+
+#obj-$(CONFIG_CPM2)		+= cpm2/

Yuri diff --git a/arch/powerpc/sysdev/cpm2_common.c b/arch/powerpc/ sysdev/cpm2_common.c
new file mode 100644
index 0000000..c755f65

arch/powerpc/sysdev/cpm2_common.c new file +34 -0
@@ -0,0 +1,197 @@
+/*
+ * General Purpose functions for the global management of the
+ * 8260 Communication Processor Module.
+ * Copyright (c) 1999 Dan Malek ([email protected])
+ * Copyright (c) 2000 MontaVista Software, Inc ([email protected])
+ *	2.3.99 Updates
+ *
+ * In addition to the individual control of the communication
+ * channels, there are a few functions that globally affect the
+ * communication processor.
+ *
+ * Buffer descriptors must be allocated from the dual ported memory
+ * space.  The allocator for that is here.  When the communication
+ * process is reset, we reclaim the memory available.  There is
+ * currently no deallocator for this memory.
+ */
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/param.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/mpc8260.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+#include <asm/cpm2.h>
+#include <asm/rheap.h>
+
+static void cpm2_dpinit(void);
+cpm_cpm2_t	*cpmp;		/* Pointer to comm

processor space */ +

arch/powerpc/sysdev/cpm2_common.c new file +6 -0
+/* We allocate this here because it is used almost exclusively for
+ * the communication processor devices.
+ */
+cpm2_map_t *cpm2_immr;
+
+#define CPM_MAP_SIZE	(0x40000)	/* 256k - the PQ3

reserve this amount

arch/powerpc/sysdev/cpm2_common.c new file +1 -0
+					   of space for CPM as it

is larger

arch/powerpc/sysdev/cpm2_common.c new file +1 -0
+					   than on PQ2 */
Quoted 9 lines
Quoted 6 lines
arch/powerpc/sysdev/cpm2_common.c new file +5 -0
+
+void
+cpm2_reset(void)
+{
+	cpm2_immr = (cpm2_map_t *)ioremap(CPM_MAP_ADDR,

CPM_MAP_SIZE);

You dont need the cast.

Ok, but this is going to be changed as I said upper. We have enough info in dts to make this more sane. Actually, I do not like the idea of ioremapping the whole IMMR, but that improvements are for the future.

Quoted 418 lines
Quoted 418 lines
arch/powerpc/sysdev/cpm2_common.c new file +87 -0
+
+	/* Reclaim the DP memory for our use.
+	 */
+	cpm2_dpinit();
+
+	/* Tell everyone where the comm processor resides.
+	 */
+	cpmp = &cpm2_immr->im_cpm;
+}
+
+/* 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
+ * memory mapped space.
+ * The baud rate clock is the system clock divided by something.
+ * It was set up long ago during the initial boot phase and is
+ * is given to us.
+ * Baud rate clocks are zero-based in the driver code (as that maps
+ * to port numbers).  Documentation uses 1-based numbering.
+ */
+#define BRG_INT_CLK	(get_brgfreq())
+#define BRG_UART_CLK	(BRG_INT_CLK/16)
+
+/* This function is used by UARTS, or anything else that uses a 16x
+ * oversampled clock.
+ */
+void
+cpm_setbrg(uint brg, uint rate)
+{
+	volatile uint	*bp;
+
+	/* This is good enough to get SMCs running.....
+	*/
+	if (brg < 4) {
+		bp = (uint *)&cpm2_immr->im_brgc1;
+	}
+	else {
+		bp = (uint *)&cpm2_immr->im_brgc5;
+		brg -= 4;
+	}
+	bp += brg;
+	*bp = ((BRG_UART_CLK / rate) << 1) | CPM_BRG_EN;
+}
+
+/* This function is used to set high speed synchronous baud rate
+ * clocks.
+ */
+void
+cpm2_fastbrg(uint brg, uint rate, int div16)
+{
+	volatile uint	*bp;
+
+	if (brg < 4) {
+		bp = (uint *)&cpm2_immr->im_brgc1;
+	}
+	else {
+		bp = (uint *)&cpm2_immr->im_brgc5;
+		brg -= 4;
+	}
+	bp += brg;
+	*bp = ((BRG_INT_CLK / rate) << 1) | CPM_BRG_EN;
+	if (div16)
+		*bp |= CPM_BRG_DIV16;
+}
+
+/*
+ * dpalloc / dpfree bits.
+ */
+static spinlock_t cpm_dpmem_lock;
+/* 16 blocks should be enough to satisfy all requests
+ * until the memory subsystem goes up... */
+static rh_block_t cpm_boot_dpmem_rh_block[16];
+static rh_info_t cpm_dpmem_info;
+
+static void cpm2_dpinit(void)
+{
+	spin_lock_init(&cpm_dpmem_lock);
+
+	/* initialize the info header */
+	rh_init(&cpm_dpmem_info, 1,
+			sizeof(cpm_boot_dpmem_rh_block) /
+			sizeof(cpm_boot_dpmem_rh_block[0]),
+			cpm_boot_dpmem_rh_block);
+
+	/* Attach the usable dpmem area */
+	/* XXX: This is actually crap. CPM_DATAONLY_BASE and
+	 * CPM_DATAONLY_SIZE is only a subset of the available

dpram. It

arch/powerpc/sysdev/cpm2_common.c new file +1 -0
+	 * varies with the processor and the microcode patches

activated.

arch/powerpc/sysdev/cpm2_common.c new file +3 -0
+	 * But the following should be at least safe.
+	 */
+	rh_attach_region(&cpm_dpmem_info, (void

*)CPM_DATAONLY_BASE,

arch/powerpc/sysdev/cpm2_common.c new file +41 -0
+			CPM_DATAONLY_SIZE);
+}
+
+/* This function returns an index into the DPRAM area.
+ */
+uint cpm_dpalloc(uint size, uint align)
+{
+	void *start;
+	unsigned long flags;
+
+	spin_lock_irqsave(&cpm_dpmem_lock, flags);
+	cpm_dpmem_info.alignment = align;
+	start = rh_alloc(&cpm_dpmem_info, size, "commproc");
+	spin_unlock_irqrestore(&cpm_dpmem_lock, flags);
+
+	return (uint)start;
+}
+EXPORT_SYMBOL(cpm_dpalloc);
+
+int cpm_dpfree(uint offset)
+{
+	int ret;
+	unsigned long flags;
+
+	spin_lock_irqsave(&cpm_dpmem_lock, flags);
+	ret = rh_free(&cpm_dpmem_info, (void *)offset);
+	spin_unlock_irqrestore(&cpm_dpmem_lock, flags);
+
+	return ret;
+}
+EXPORT_SYMBOL(cpm_dpfree);
+
+/* not sure if this is ever needed */
+uint cpm_dpalloc_fixed(uint offset, uint size, uint align)
+{
+	void *start;
+	unsigned long flags;
+
+	spin_lock_irqsave(&cpm_dpmem_lock, flags);
+	cpm_dpmem_info.alignment = align;
+	start = rh_alloc_fixed(&cpm_dpmem_info, (void *)offset,

size, "commproc");

arch/powerpc/sysdev/cpm2_common.c new file +17 -0
+	spin_unlock_irqrestore(&cpm_dpmem_lock, flags);
+
+	return (uint)start;
+}
+EXPORT_SYMBOL(cpm_dpalloc_fixed);
+
+void cpm_dpdump(void)
+{
+	rh_dump(&cpm_dpmem_info);
+}
+EXPORT_SYMBOL(cpm_dpdump);
+
+void *cpm_dpram_addr(uint offset)
+{
+	return (void *)&cpm2_immr->im_dprambase[offset];
+}
+EXPORT_SYMBOL(cpm_dpram_addr);
arch/powerpc/sysdev/ renamed from arch/powerpc/sysdev/cpm2_pic.c +0 -0

cpm2_pic.c
new file mode 100644
index 0000000..e0db594

arch/powerpc/sysdev/cpm2_pic.c new file +36 -0
@@ -0,0 +1,181 @@
+/* The CPM2 internal interrupt controller.  It is usually
+ * the only interrupt controller.
+ * There are two 32-bit registers (high/low) for up to 64
+ * possible interrupts.
+ *
+ * Now, the fun starts.....Interrupt Numbers DO NOT MAP
+ * in a simple arithmetic fashion to mask or pending registers.
+ * That is, interrupt 4 does not map to bit position 4.
+ * We create two tables, indexed by vector number, to indicate
+ * which register to use and which bit in the register to use.
+ */
+
+#include <linux/stddef.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/signal.h>
+#include <linux/irq.h>
+
+#include <asm/immap_cpm2.h>
+#include <asm/mpc8260.h>
+#include <asm/io.h>
+
+#include "cpm2_pic.h"
+
+static	u_char	irq_to_siureg[] = {
+	1, 1, 1, 1, 1, 1, 1, 1,
+	1, 1, 1, 1, 1, 1, 1, 1,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	1, 1, 1, 1, 1, 1, 1, 1,
+	1, 1, 1, 1, 1, 1, 1, 1,
+	0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/* bit numbers do not match the docs, these are precomputed so

the bit for
+ * a given irq is (1 << irq_to_siubit[irq]) */

arch/powerpc/sysdev/cpm2_pic.c new file +64 -0
+static	u_char	irq_to_siubit[] = {
+	 0, 15, 14, 13, 12, 11, 10,  9,
+	 8,  7,  6,  5,  4,  3,  2,  1,
+	 2,  1,  0, 14, 13, 12, 11, 10,
+	 9,  8,  7,  6,  5,  4,  3,  0,
+	31, 30, 29, 28, 27, 26, 25, 24,
+	23, 22, 21, 20, 19, 18, 17, 16,
+	16, 17, 18, 19, 20, 21, 22, 23,
+	24, 25, 26, 27, 28, 29, 30, 31,
+};
+
+static void cpm2_mask_irq(unsigned int irq_nr)
+{
+	int	bit, word;
+	volatile uint	*simr;
+
+	irq_nr -= CPM_IRQ_OFFSET;
+
+	bit = irq_to_siubit[irq_nr];
+	word = irq_to_siureg[irq_nr];
+
+	simr = &(cpm2_immr->im_intctl.ic_simrh);
+	ppc_cached_irq_mask[word] &= ~(1 << bit);
+	simr[word] = ppc_cached_irq_mask[word];
+}
+
+static void cpm2_unmask_irq(unsigned int irq_nr)
+{
+	int	bit, word;
+	volatile uint	*simr;
+
+	irq_nr -= CPM_IRQ_OFFSET;
+
+	bit = irq_to_siubit[irq_nr];
+	word = irq_to_siureg[irq_nr];
+
+	simr = &(cpm2_immr->im_intctl.ic_simrh);
+	ppc_cached_irq_mask[word] |= 1 << bit;
+	simr[word] = ppc_cached_irq_mask[word];
+}
+
+static void cpm2_mask_and_ack(unsigned int irq_nr)
+{
+	int	bit, word;
+	volatile uint	*simr, *sipnr;
+
+	irq_nr -= CPM_IRQ_OFFSET;
+
+	bit = irq_to_siubit[irq_nr];
+	word = irq_to_siureg[irq_nr];
+
+	simr = &(cpm2_immr->im_intctl.ic_simrh);
+	sipnr = &(cpm2_immr->im_intctl.ic_sipnrh);
+	ppc_cached_irq_mask[word] &= ~(1 << bit);
+	simr[word] = ppc_cached_irq_mask[word];
+	sipnr[word] = 1 << bit;
+}
+
+static void cpm2_end_irq(unsigned int irq_nr)
+{
+	int	bit, word;
+	volatile uint	*simr;
+
+	if (!(irq_desc[irq_nr].status &

(IRQ_DISABLED|IRQ_INPROGRESS))

arch/powerpc/sysdev/cpm2_pic.c new file +11 -0
+			&& irq_desc[irq_nr].action) {
+
+		irq_nr -= CPM_IRQ_OFFSET;
+		bit = irq_to_siubit[irq_nr];
+		word = irq_to_siureg[irq_nr];
+
+		simr = &(cpm2_immr->im_intctl.ic_simrh);
+		ppc_cached_irq_mask[word] |= 1 << bit;
+		simr[word] = ppc_cached_irq_mask[word];
+		/*
+		 * Work around large numbers of spurious IRQs on

PowerPC 82xx

arch/powerpc/sysdev/cpm2_pic.c new file +20 -0
+		 * systems.
+		 */
+		mb();
+	}
+}
+
+static struct hw_interrupt_type cpm2_pic = {
+	.typename = " CPM2 SIU ",
+	.enable = cpm2_unmask_irq,
+	.disable = cpm2_mask_irq,
+	.ack = cpm2_mask_and_ack,
+	.end = cpm2_end_irq,
+};
+
+int cpm2_get_irq(struct pt_regs *regs)
+{
+	int irq;
+        unsigned long bits;
+
+        /* For CPM2, read the SIVEC register and shift the bits

down

arch/powerpc/sysdev/cpm2_pic.c new file +15 -0
+         * to get the irq number.         */
+        bits = cpm2_immr->im_intctl.ic_sivec;
+        irq = bits >> 26;
+
+	if (irq == 0)
+		return(-1);
+	return irq+CPM_IRQ_OFFSET;
+}
+
+void cpm2_init_IRQ(void)
+{
+	int i;
+	u32 addr;
+
+	/* Clear the CPM IRQ controller, in case it has any bits

set

arch/powerpc/sysdev/cpm2_pic.c new file +34 -0
+	 * from the bootloader
+	 */
+
+	/* Mask out everything */
+
+	cpm2_immr->im_intctl.ic_simrh = 0x00000000;
+	cpm2_immr->im_intctl.ic_simrl = 0x00000000;
+
+	wmb();
+
+	/* Ack everything */
+	cpm2_immr->im_intctl.ic_sipnrh = 0xffffffff;
+	cpm2_immr->im_intctl.ic_sipnrl = 0xffffffff;
+	wmb();
+
+	/* Dummy read of the vector */
+	i = cpm2_immr->im_intctl.ic_sivec;
+	rmb();
+
+	/* Initialize the default interrupt mapping priorities,
+	 * in case the boot rom changed something on us.
+	 */
+	cpm2_immr->im_intctl.ic_sicr = 0;
+	cpm2_immr->im_intctl.ic_scprrh = 0x05309770;
+	cpm2_immr->im_intctl.ic_scprrl = 0x05309770;
+
+
+	/* Enable chaining to OpenPIC, and make everything level
+	 */
+	for (i = 0; i < NR_CPM_INTS; i++) {
+		irq_desc[i+CPM_IRQ_OFFSET].handler = &cpm2_pic;
+		irq_desc[i+CPM_IRQ_OFFSET].status |= IRQ_LEVEL;
+	}
+}
arch/powerpc/sysdev/ renamed from arch/powerpc/sysdev/cpm2_pic.h +0 -0

cpm2_pic.h
new file mode 100644
index 0000000..97cab8f

arch/powerpc/sysdev/cpm2_pic.h new file +8 -0
@@ -0,0 +1,8 @@
+#ifndef _PPC_KERNEL_CPM2_H
+#define _PPC_KERNEL_CPM2_H
+
+extern int cpm2_get_irq(struct pt_regs *regs);
+
+extern void cpm2_init_IRQ(void);
+
+#endif /* _PPC_KERNEL_CPM2_H */
arch/powerpc/sysdev/ renamed from arch/powerpc/sysdev/fsl_soc.c +0 -0

fsl_soc.c
index ceb5846..bab202d 100644

arch/powerpc/sysdev/fsl_soc.c +25 -1
@@ -21,6 +21,8 @@ #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/platform_device.h>
 #include <linux/fsl_devices.h>
+#include <linux/fs_enet_pd.h>
+#include <linux/fs_uart_pd.h>
 
 #include <asm/system.h>
 #include <asm/atomic.h>
@@ -30,6 +32,10 @@ #include <asm/prom.h>
 #include <sysdev/fsl_soc.h>
 #include <mm/mmu_decl.h>
 
+#ifdef CONFIG_CPM2
+#include <asm/cpm2.h>
+#endif
+
 static phys_addr_t immrbase = -1;
 
 phys_addr_t get_immrbase(void)
@@ -43,7 +49,9 @@ phys_addr_t get_immrbase(void)
 	if (soc) {
 		unsigned int size;
 		void *prop = get_property(soc, "reg", &size);
-		immrbase = of_translate_address(soc, prop);
+
+		if (prop)
+			immrbase = of_translate_address(soc, prop);
 		of_node_put(soc);
 	};
 
@@ -51,7 +59,79 @@ phys_addr_t get_immrbase(void)
 }
 
 EXPORT_SYMBOL(get_immrbase);
+
+static u32 brgfreq = -1;
+
+u32 get_brgfreq(void)
+{
+	struct device_node *node;
+
+	if (brgfreq != -1)
+		return brgfreq;
+
+	node = of_find_node_by_type(NULL, "serial");
+	if (node) {
+		unsigned int size;
+		unsigned int *prop = (unsigned
 int*)get_property(node, "clock- frequency", &size);
+
+		if (prop)
Quoted 9 lines

arch/powerpc/sysdev/fsl_soc.c phys_addr_t get_immrbase(void) · line 83

Quoted 6 lines
arch/powerpc/sysdev/fsl_soc.c +6 -0
+			brgfreq = *prop;
+		of_node_put(node);
+	};
+
+	return brgfreq;
+}

These seems broken on a system w/both CPM & 8250 style uarts.

Yeah, missed that.

Quoted 46 lines
Quoted 46 lines
arch/powerpc/sysdev/fsl_soc.c +43 -0
+
+EXPORT_SYMBOL(get_brgfreq);
+
+static u32 fs_baudrate = -1;
+
+u32 get_baudrate(void)
+{
+	struct device_node *node;
 
+	if (fs_baudrate != -1)
+		return fs_baudrate;
+
+	node = of_find_node_by_type(NULL, "serial");
+	if (node) {
+		unsigned int size;
+		unsigned int *prop = (unsigned
 int*)get_property(node, "current- speed", &size);
+
+		if (prop)
+			fs_baudrate = *prop;
+		of_node_put(node);
+	};
+
+	return fs_baudrate;
+}
+
+EXPORT_SYMBOL(get_baudrate);
+
+static u32 intfreq = -1;
+
+u32 get_intfreq(void)
+{
+	struct device_node *node;
+
+	if (intfreq != -1)
+		return intfreq;
+
+	node = of_find_node_by_type(NULL, "cpu");
+	if (node) {
+		unsigned int size;
+		unsigned int *prop = (unsigned
 int*)get_property(node, "clock- frequency", &size);
+		if (prop)
+			intfreq = *prop;
+		of_node_put(node);
+	}
Quoted 9 lines

arch/powerpc/sysdev/fsl_soc.c phys_addr_t get_immrbase(void) · line 133

Quoted 6 lines
arch/powerpc/sysdev/fsl_soc.c +6 -0
+
+	return intfreq;
+}
+
+EXPORT_SYMBOL(get_intfreq);
+

Don't we have something that reports "clock-frequency" elsewhere?

If yes, I haven't found... Mind pointing where to look at?

Quoted 117 lines
Quoted 117 lines
arch/powerpc/sysdev/fsl_soc.c +1 -0
+

static int __init gfar_mdio_of_init(void)
{

arch/powerpc/sysdev/fsl_soc.c +16 -0
 	struct device_node *np;
@@ -491,3 +571,211 @@ err:
 }
 
 arch_initcall(fsl_usb_dr_of_init);
+
+static const char *fcc_regs = "fcc_regs";
+static const char *fcc_regs_c = "fcc_regs_c";
+static const char *fcc_pram = "fcc_pram";
+static char bus_id[9][BUS_ID_SIZE];
+
+static int __init fs_enet_of_init(void)
+{
+	struct device_node *np;
+	unsigned int i;
+	struct platform_device *fs_enet_dev;
+	struct resource res;
+	int ret;
+
+	for (np = NULL, i = 0;
+	     (np = of_find_compatible_node(np, "network",

"fs_enet")) != NULL;

arch/powerpc/sysdev/fsl_soc.c +33 -0
+	     i++) {
+		struct resource r[4];
+		struct device_node *phy, *mdio;
+		struct fs_platform_info fs_enet_data;
+		unsigned int *id, *phy_addr;
+		void *mac_addr;
+		phandle *ph;
+		char *model;
+
+		memset(r, 0, sizeof(r));
+		memset(&fs_enet_data, 0, sizeof(fs_enet_data));
+
+		ret = of_address_to_resource(np, 0, &r[0]);
+		if (ret)
+			goto err;
+		r[0].name = fcc_regs;
+
+		ret = of_address_to_resource(np, 1, &r[1]);
+		if (ret)
+			goto err;
+		r[1].name = fcc_pram;
+
+		ret = of_address_to_resource(np, 2, &r[2]);
+		if (ret)
+			goto err;
+		r[2].name = fcc_regs_c;
+
+		r[3].start = np->intrs[0].line;
+		r[3].end = np->intrs[0].line;
+		r[3].flags = IORESOURCE_IRQ;
+
+		fs_enet_dev =
+		    platform_device_register_simple("fsl-cpm-fcc",

i, &r[0], 4); +

arch/powerpc/sysdev/fsl_soc.c +15 -0
+		if (IS_ERR(fs_enet_dev)) {
+			ret = PTR_ERR(fs_enet_dev);
+			goto err;
+		}
+
+		model = get_property(np, "model", NULL);
+		if (model == NULL) {
+			ret = -ENODEV;
+			goto unreg;
+		}
+
+		mac_addr = get_property(np, "mac-address", NULL);
+		memcpy(fs_enet_data.macaddr, mac_addr, 6);
+
+		ph = (phandle *) get_property(np, "phy-handle",

NULL);

arch/powerpc/sysdev/fsl_soc.c +25 -0
+		phy = of_find_node_by_phandle(*ph);
+
+		if (phy == NULL) {
+			ret = -ENODEV;
+			goto unreg;
+		}
+
+		phy_addr = (u32 *) get_property(phy, "reg", NULL);
+		fs_enet_data.phy_addr = *phy_addr;
+
+		id = (u32 *) get_property(np, "device-id", NULL);
+		fs_enet_data.fs_no = *id;
+
+		mdio = of_get_parent(phy);
+                ret = of_address_to_resource(mdio, 0, &res);
+                if (ret) {
+                        of_node_put(phy);
+                        of_node_put(mdio);
+                        goto unreg;
+                }
+
+		switch (*id) {
+		case fsid_fcc1:
+			fs_enet_data.mem_offset = FCC1_MEM_OFFSET,
+			snprintf((char*)&bus_id[2], BUS_ID_SIZE,

"%x:%02x", (u32) res.start, fs_enet_data.phy_addr);

arch/powerpc/sysdev/fsl_soc.c +7 -0
+			fs_enet_data.bus_id = (char*)&bus_id[2];
+			fs_enet_data.cp_page = CPM_CR_FCC1_PAGE;
+			fs_enet_data.cp_block = CPM_CR_FCC1_SBLOCK;
+			break;
+		case fsid_fcc2:
+			fs_enet_data.mem_offset = FCC2_MEM_OFFSET,
+			snprintf((char*)&bus_id[3], BUS_ID_SIZE,

"%x:%02x", (u32) res.start, fs_enet_data.phy_addr);

arch/powerpc/sysdev/fsl_soc.c +7 -0
+			fs_enet_data.bus_id = (char*)&bus_id[3];
+			fs_enet_data.cp_page = CPM_CR_FCC2_PAGE;
+			fs_enet_data.cp_block = CPM_CR_FCC2_SBLOCK;
+			break;
+		case fsid_fcc3:
+			fs_enet_data.mem_offset = FCC3_MEM_OFFSET,
+			snprintf((char*)&bus_id[4], BUS_ID_SIZE,

"%x:%02x", (u32) res.start, fs_enet_data.phy_addr);

Quoted 9 lines

arch/powerpc/sysdev/fsl_soc.c err: · line 682

Quoted 5 lines
arch/powerpc/sysdev/fsl_soc.c +5 -0
+			fs_enet_data.bus_id = (char*)&bus_id[4];
+			fs_enet_data.cp_page = CPM_CR_FCC3_PAGE;
+			fs_enet_data.cp_block = CPM_CR_FCC3_SBLOCK;
+			break;
+		}

this looks like a lot of effort to just encode a single integer (1, 2, 3) and then lookup the other information based on it.

Not sure I am following what is suggested here. Could it be elaborated a little bit ?

Quoted 125 lines
Quoted 123 lines
arch/powerpc/sysdev/fsl_soc.c +3 -0
+
+		if (strstr(model, "FCC")) {
+			fs_enet_data.dpram_offset =

(u32)cpm2_immr->im_dprambase;

arch/powerpc/sysdev/fsl_soc.c +11 -0
+			fs_enet_data.rx_ring = 32;
+			fs_enet_data.tx_ring = 32;
+			fs_enet_data.rx_copybreak = 240;
+			fs_enet_data.use_napi = 0;
+			fs_enet_data.napi_weight = 17;
+		}
+
+		of_node_put(phy);
+		of_node_put(mdio);
+
+		ret = platform_device_add_data(fs_enet_dev,

&fs_enet_data,

arch/powerpc/sysdev/fsl_soc.c +2 -0
+					     sizeof(struct
+

fs_platform_info));

arch/powerpc/sysdev/fsl_soc.c +26 -0
+		if (ret)
+			goto unreg;
+	}
+	return 0;
+
+unreg:
+	platform_device_unregister(fs_enet_dev);
+err:
+	return ret;
+}
+
+arch_initcall(fs_enet_of_init);
+
+static const char *scc_regs = "regs";
+static const char *scc_pram = "pram";
+
+static int __init cpm_uart_of_init(void)
+{
+	struct device_node *np;
+	unsigned int i;
+	struct platform_device *cpm_uart_dev;
+	int ret;
+
+
+	for (np = NULL, i = 0;
+	     (np = of_find_compatible_node(np, "serial",

"cpm_uart")) != NULL;

arch/powerpc/sysdev/fsl_soc.c +25 -0
+	     i++) {
+		struct resource r[3];
+		struct fs_uart_platform_info cpm_uart_data;
+		int *id;
+
+		memset(r, 0, sizeof(r));
+		memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
+
+		ret = of_address_to_resource(np, 0, &r[0]);
+		if (ret)
+			goto err;
+
+		r[0].name = scc_regs;
+
+		ret = of_address_to_resource(np, 1, &r[1]);
+		if (ret)
+			goto err;
+		r[1].name = scc_pram;
+
+		r[2].start = np->intrs[0].line;
+		r[2].end = np->intrs[0].line;
+		r[2].flags = IORESOURCE_IRQ;
+
+		cpm_uart_dev =
+

platform_device_register_simple("fsl-cpm-scc:uart", i, &r [0], 3);

arch/powerpc/sysdev/fsl_soc.c +17 -0
+
+		if (IS_ERR(cpm_uart_dev)) {
+			ret = PTR_ERR(cpm_uart_dev);
+			goto err;
+		}
+
+		id = get_property(np, "device-id", NULL);
+		cpm_uart_data.fs_no = *id;
+		cpm_uart_data.uart_clk = get_intfreq();
+
+		cpm_uart_data.tx_num_fifo = 4;
+		cpm_uart_data.tx_buf_size = 32;
+		cpm_uart_data.rx_num_fifo = 4;
+		cpm_uart_data.rx_buf_size = 32;
+
+		ret =
+		    platform_device_add_data(cpm_uart_dev,

&cpm_uart_data,

arch/powerpc/sysdev/fsl_soc.c +2 -0
+					     sizeof(struct
+

fs_uart_platform_info));

arch/powerpc/sysdev/fsl_soc.c +13 -0
+		if (ret)
+			goto unreg;
+	}
+
+	return 0;
+
+unreg:
+	platform_device_unregister(cpm_uart_dev);
+err:
+	return ret;
+}
+
+arch_initcall(cpm_uart_of_init);
include/asm-ppc/cpm2.h +1 -1
index f6a7ff0..8e6840b 100644
@@ -1186,7 +1186,7 @@ #define PC3_DIRC1	(PC3_TXDAT)
 #define FCC_MEM_OFFSET(x) (CPM_FCC_SPECIAL_BASE + (x*128))
 #define FCC1_MEM_OFFSET FCC_MEM_OFFSET(0)
 #define FCC2_MEM_OFFSET FCC_MEM_OFFSET(1)
-#define FCC2_MEM_OFFSET FCC_MEM_OFFSET(2)
+#define FCC3_MEM_OFFSET FCC_MEM_OFFSET(2)
 
 #endif /* __CPM2__ */
 #endif /* __KERNEL__ */

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#14 lore raw

Re: [PATCH 6/6] [RFC] POWERPC: Add mpc8560 board support

[snip]

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
arch/powerpc/sysdev/ renamed from arch/powerpc/sysdev/Makefile +0 -0

Makefile
index cef95b0..75dfe12 100644

arch/powerpc/sysdev/Makefile +0 -0
@@ -12,3 +12,10 @@ obj-$(CONFIG_U3_DART)		+=

dart_iommu.o obj-$(CONFIG_MMIO_NVRAM) += mmio_nvram.o
obj-$(CONFIG_PPC_83xx) += ipic.o

Quoted 9 lines

arch/powerpc/sysdev/Makefile obj-$(CONFIG_U3_DART) += dart_iommu.o · line 19

Quoted 6 lines

obj-$(CONFIG_FSL_SOC) += fsl_soc.o

arch/powerpc/sysdev/Makefile +5 -0
+
+# Temporary hack until we have migrated to asm-powerpc
+ifeq ($(ARCH),powerpc)
+obj-$(CONFIG_CPM2)		+= cpm2_common.o cpm2_pic.o
+endif

See earlier comments about just building in arch/powerpc

Quoted 5 lines

Hrm, here I am not completely sure it's a good thing. The point is that currently some OF-specific stuff is under construction to go into cpm2_common at least (for instance, getting rid of CPM_MAP_ADDR ioremap because the offset is available via oftree, and things like that).

If that's the case, make a duplicate of cpm2_common.c, however I dont think you need the ifeq... to make that work.

Quoted 2 lines
Quoted 2 lines

arch/powerpc/sysdev/Makefile

Quoted 2 lines
arch/powerpc/sysdev/Makefile +2 -0
+
+#obj-$(CONFIG_CPM2)		+= cpm2/

what's in the cpm2 directory?

[snip]

Quoted 124 lines
Quoted 57 lines
Quoted 57 lines
arch/powerpc/sysdev/ renamed from arch/powerpc/sysdev/fsl_soc.c +0 -0

fsl_soc.c
index ceb5846..bab202d 100644

arch/powerpc/sysdev/fsl_soc.c +25 -1
@@ -21,6 +21,8 @@ #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/platform_device.h>
 #include <linux/fsl_devices.h>
+#include <linux/fs_enet_pd.h>
+#include <linux/fs_uart_pd.h>
 
 #include <asm/system.h>
 #include <asm/atomic.h>
@@ -30,6 +32,10 @@ #include <asm/prom.h>
 #include <sysdev/fsl_soc.h>
 #include <mm/mmu_decl.h>
 
+#ifdef CONFIG_CPM2
+#include <asm/cpm2.h>
+#endif
+
 static phys_addr_t immrbase = -1;
 
 phys_addr_t get_immrbase(void)
@@ -43,7 +49,9 @@ phys_addr_t get_immrbase(void)
 	if (soc) {
 		unsigned int size;
 		void *prop = get_property(soc, "reg", &size);
-		immrbase = of_translate_address(soc, prop);
+
+		if (prop)
+			immrbase = of_translate_address(soc, prop);
 		of_node_put(soc);
 	};
 
@@ -51,7 +59,79 @@ phys_addr_t get_immrbase(void)
 }
 
 EXPORT_SYMBOL(get_immrbase);
+
+static u32 brgfreq = -1;
+
+u32 get_brgfreq(void)
+{
+	struct device_node *node;
+
+	if (brgfreq != -1)
+		return brgfreq;
+
+	node = of_find_node_by_type(NULL, "serial");
+	if (node) {
+		unsigned int size;
+		unsigned int *prop = (unsigned
 int*)get_property(node, "clock- frequency", &size);
+
+		if (prop)
Quoted 9 lines

arch/powerpc/sysdev/fsl_soc.c phys_addr_t get_immrbase(void) · line 83

Quoted 6 lines
arch/powerpc/sysdev/fsl_soc.c +6 -0
+			brgfreq = *prop;
+		of_node_put(node);
+	};
+
+	return brgfreq;
+}

These seems broken on a system w/both CPM & 8250 style uarts.

Yeah, missed that.

Quoted 46 lines
Quoted 46 lines
arch/powerpc/sysdev/fsl_soc.c +43 -0
+
+EXPORT_SYMBOL(get_brgfreq);
+
+static u32 fs_baudrate = -1;
+
+u32 get_baudrate(void)
+{
+	struct device_node *node;
 
+	if (fs_baudrate != -1)
+		return fs_baudrate;
+
+	node = of_find_node_by_type(NULL, "serial");
+	if (node) {
+		unsigned int size;
+		unsigned int *prop = (unsigned
 int*)get_property(node, "current- speed", &size);
+
+		if (prop)
+			fs_baudrate = *prop;
+		of_node_put(node);
+	};
+
+	return fs_baudrate;
+}
+
+EXPORT_SYMBOL(get_baudrate);
+
+static u32 intfreq = -1;
+
+u32 get_intfreq(void)
+{
+	struct device_node *node;
+
+	if (intfreq != -1)
+		return intfreq;
+
+	node = of_find_node_by_type(NULL, "cpu");
+	if (node) {
+		unsigned int size;
+		unsigned int *prop = (unsigned
 int*)get_property(node, "clock- frequency", &size);
+		if (prop)
+			intfreq = *prop;
+		of_node_put(node);
+	}
Quoted 9 lines

arch/powerpc/sysdev/fsl_soc.c phys_addr_t get_immrbase(void) · line 133

Quoted 6 lines
arch/powerpc/sysdev/fsl_soc.c +6 -0
+
+	return intfreq;
+}
+
+EXPORT_SYMBOL(get_intfreq);
+

Don't we have something that reports "clock-frequency" elsewhere?

Quoted 1 line

If yes, I haven't found... Mind pointing where to look at?

ppc_proc_freq in kernel/time.c

Quoted 127 lines
Quoted 117 lines
Quoted 117 lines
arch/powerpc/sysdev/fsl_soc.c +1 -0
+

static int __init gfar_mdio_of_init(void)
{

arch/powerpc/sysdev/fsl_soc.c +16 -0
 	struct device_node *np;
@@ -491,3 +571,211 @@ err:
 }
 
 arch_initcall(fsl_usb_dr_of_init);
+
+static const char *fcc_regs = "fcc_regs";
+static const char *fcc_regs_c = "fcc_regs_c";
+static const char *fcc_pram = "fcc_pram";
+static char bus_id[9][BUS_ID_SIZE];
+
+static int __init fs_enet_of_init(void)
+{
+	struct device_node *np;
+	unsigned int i;
+	struct platform_device *fs_enet_dev;
+	struct resource res;
+	int ret;
+
+	for (np = NULL, i = 0;
+	     (np = of_find_compatible_node(np, "network",

"fs_enet")) != NULL;

arch/powerpc/sysdev/fsl_soc.c +33 -0
+	     i++) {
+		struct resource r[4];
+		struct device_node *phy, *mdio;
+		struct fs_platform_info fs_enet_data;
+		unsigned int *id, *phy_addr;
+		void *mac_addr;
+		phandle *ph;
+		char *model;
+
+		memset(r, 0, sizeof(r));
+		memset(&fs_enet_data, 0, sizeof(fs_enet_data));
+
+		ret = of_address_to_resource(np, 0, &r[0]);
+		if (ret)
+			goto err;
+		r[0].name = fcc_regs;
+
+		ret = of_address_to_resource(np, 1, &r[1]);
+		if (ret)
+			goto err;
+		r[1].name = fcc_pram;
+
+		ret = of_address_to_resource(np, 2, &r[2]);
+		if (ret)
+			goto err;
+		r[2].name = fcc_regs_c;
+
+		r[3].start = np->intrs[0].line;
+		r[3].end = np->intrs[0].line;
+		r[3].flags = IORESOURCE_IRQ;
+
+		fs_enet_dev =
+		    platform_device_register_simple("fsl-cpm-fcc",

i, &r[0], 4); +

arch/powerpc/sysdev/fsl_soc.c +15 -0
+		if (IS_ERR(fs_enet_dev)) {
+			ret = PTR_ERR(fs_enet_dev);
+			goto err;
+		}
+
+		model = get_property(np, "model", NULL);
+		if (model == NULL) {
+			ret = -ENODEV;
+			goto unreg;
+		}
+
+		mac_addr = get_property(np, "mac-address", NULL);
+		memcpy(fs_enet_data.macaddr, mac_addr, 6);
+
+		ph = (phandle *) get_property(np, "phy-handle",

NULL);

arch/powerpc/sysdev/fsl_soc.c +25 -0
+		phy = of_find_node_by_phandle(*ph);
+
+		if (phy == NULL) {
+			ret = -ENODEV;
+			goto unreg;
+		}
+
+		phy_addr = (u32 *) get_property(phy, "reg", NULL);
+		fs_enet_data.phy_addr = *phy_addr;
+
+		id = (u32 *) get_property(np, "device-id", NULL);
+		fs_enet_data.fs_no = *id;
+
+		mdio = of_get_parent(phy);
+                ret = of_address_to_resource(mdio, 0, &res);
+                if (ret) {
+                        of_node_put(phy);
+                        of_node_put(mdio);
+                        goto unreg;
+                }
+
+		switch (*id) {
+		case fsid_fcc1:
+			fs_enet_data.mem_offset = FCC1_MEM_OFFSET,
+			snprintf((char*)&bus_id[2], BUS_ID_SIZE,

"%x:%02x", (u32) res.start, fs_enet_data.phy_addr);

arch/powerpc/sysdev/fsl_soc.c +7 -0
+			fs_enet_data.bus_id = (char*)&bus_id[2];
+			fs_enet_data.cp_page = CPM_CR_FCC1_PAGE;
+			fs_enet_data.cp_block = CPM_CR_FCC1_SBLOCK;
+			break;
+		case fsid_fcc2:
+			fs_enet_data.mem_offset = FCC2_MEM_OFFSET,
+			snprintf((char*)&bus_id[3], BUS_ID_SIZE,

"%x:%02x", (u32) res.start, fs_enet_data.phy_addr);

arch/powerpc/sysdev/fsl_soc.c +7 -0
+			fs_enet_data.bus_id = (char*)&bus_id[3];
+			fs_enet_data.cp_page = CPM_CR_FCC2_PAGE;
+			fs_enet_data.cp_block = CPM_CR_FCC2_SBLOCK;
+			break;
+		case fsid_fcc3:
+			fs_enet_data.mem_offset = FCC3_MEM_OFFSET,
+			snprintf((char*)&bus_id[4], BUS_ID_SIZE,

"%x:%02x", (u32) res.start, fs_enet_data.phy_addr);

Quoted 9 lines

arch/powerpc/sysdev/fsl_soc.c err: · line 682

Quoted 5 lines
arch/powerpc/sysdev/fsl_soc.c +5 -0
+			fs_enet_data.bus_id = (char*)&bus_id[4];
+			fs_enet_data.cp_page = CPM_CR_FCC3_PAGE;
+			fs_enet_data.cp_block = CPM_CR_FCC3_SBLOCK;
+			break;
+		}

this looks like a lot of effort to just encode a single integer (1, 2, 3) and then lookup the other information based on it.

Quoted 2 lines

Not sure I am following what is suggested here. Could it be elaborated a little bit ?

I saying all you need to store is the fact that its a FCC and its number 1, 2, 3... after which we can have some table in cpm2_common.c that provides back cp_page, cp_block based on type and number. Encoding it fs_enet_data is just a duplication.

Quoted 125 lines
Quoted 125 lines
Quoted 123 lines
arch/powerpc/sysdev/fsl_soc.c +3 -0
+
+		if (strstr(model, "FCC")) {
+			fs_enet_data.dpram_offset =

(u32)cpm2_immr->im_dprambase;

arch/powerpc/sysdev/fsl_soc.c +11 -0
+			fs_enet_data.rx_ring = 32;
+			fs_enet_data.tx_ring = 32;
+			fs_enet_data.rx_copybreak = 240;
+			fs_enet_data.use_napi = 0;
+			fs_enet_data.napi_weight = 17;
+		}
+
+		of_node_put(phy);
+		of_node_put(mdio);
+
+		ret = platform_device_add_data(fs_enet_dev,

&fs_enet_data,

arch/powerpc/sysdev/fsl_soc.c +2 -0
+					     sizeof(struct
+

fs_platform_info));

arch/powerpc/sysdev/fsl_soc.c +26 -0
+		if (ret)
+			goto unreg;
+	}
+	return 0;
+
+unreg:
+	platform_device_unregister(fs_enet_dev);
+err:
+	return ret;
+}
+
+arch_initcall(fs_enet_of_init);
+
+static const char *scc_regs = "regs";
+static const char *scc_pram = "pram";
+
+static int __init cpm_uart_of_init(void)
+{
+	struct device_node *np;
+	unsigned int i;
+	struct platform_device *cpm_uart_dev;
+	int ret;
+
+
+	for (np = NULL, i = 0;
+	     (np = of_find_compatible_node(np, "serial",

"cpm_uart")) != NULL;

arch/powerpc/sysdev/fsl_soc.c +25 -0
+	     i++) {
+		struct resource r[3];
+		struct fs_uart_platform_info cpm_uart_data;
+		int *id;
+
+		memset(r, 0, sizeof(r));
+		memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
+
+		ret = of_address_to_resource(np, 0, &r[0]);
+		if (ret)
+			goto err;
+
+		r[0].name = scc_regs;
+
+		ret = of_address_to_resource(np, 1, &r[1]);
+		if (ret)
+			goto err;
+		r[1].name = scc_pram;
+
+		r[2].start = np->intrs[0].line;
+		r[2].end = np->intrs[0].line;
+		r[2].flags = IORESOURCE_IRQ;
+
+		cpm_uart_dev =
+

platform_device_register_simple("fsl-cpm-scc:uart", i, &r [0], 3);

arch/powerpc/sysdev/fsl_soc.c +17 -0
+
+		if (IS_ERR(cpm_uart_dev)) {
+			ret = PTR_ERR(cpm_uart_dev);
+			goto err;
+		}
+
+		id = get_property(np, "device-id", NULL);
+		cpm_uart_data.fs_no = *id;
+		cpm_uart_data.uart_clk = get_intfreq();
+
+		cpm_uart_data.tx_num_fifo = 4;
+		cpm_uart_data.tx_buf_size = 32;
+		cpm_uart_data.rx_num_fifo = 4;
+		cpm_uart_data.rx_buf_size = 32;
+
+		ret =
+		    platform_device_add_data(cpm_uart_dev,

&cpm_uart_data,

arch/powerpc/sysdev/fsl_soc.c +2 -0
+					     sizeof(struct
+

fs_uart_platform_info));

arch/powerpc/sysdev/fsl_soc.c +13 -0
+		if (ret)
+			goto unreg;
+	}
+
+	return 0;
+
+unreg:
+	platform_device_unregister(cpm_uart_dev);
+err:
+	return ret;
+}
+
+arch_initcall(cpm_uart_of_init);
include/asm-ppc/cpm2.h +1 -1
index f6a7ff0..8e6840b 100644
@@ -1186,7 +1186,7 @@ #define PC3_DIRC1	(PC3_TXDAT)
 #define FCC_MEM_OFFSET(x) (CPM_FCC_SPECIAL_BASE + (x*128))
 #define FCC1_MEM_OFFSET FCC_MEM_OFFSET(0)
 #define FCC2_MEM_OFFSET FCC_MEM_OFFSET(1)
-#define FCC2_MEM_OFFSET FCC_MEM_OFFSET(2)
+#define FCC3_MEM_OFFSET FCC_MEM_OFFSET(2)
 
 #endif /* __CPM2__ */
 #endif /* __KERNEL__ */

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev