Subject: Re: change proposal sys/arch/arm/ep93xx
To: None <joff@embeddedARM.com, martin@duskware.de>
From: HAMAJIMA Katsuomi <hamajima@nagoya.bug.gr.jp>
List: port-arm
Date: 11/07/2005 06:18:22
----Next_Part(Mon_Nov__7_06:18:22_2005_278)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I will commit if there is no suggestion.

>> B. modify MDCDIV (mdcdiv.diff)
>> MDCDIV is fixed with 32 in epe.c.  I want to change it in config file.
> 
> The name of the option could be ... slightly more descriptive, I think.
> Out of curiosity, are the choices arbitrary, or could you offer a fixed
> set selected by "flag" values in the config instead? (I don't have any idea
> what that clock does, sorry if this is a stupid question)

I changed it to use flags.

> For the device order issue, this sounds like you are trying to do a half
> direct, half indirect config scan - so maybe there are better solutions
> to the problem?

I used config_found_sm_loc() and attach epclk and epgpio first.
I^2C device require microtime(), so I attach epclk too.

And I set mac address if property is set.


----Next_Part(Mon_Nov__7_06:18:22_2005_278)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="mdcdiv.diff"

Index: sys/arch/arm/ep93xx/epe.c
diff -u sys/arch/arm/ep93xx/epe.c:1.1.1.2 sys/arch/arm/ep93xx/epe.c:1.1.2.9
--- sys/arch/arm/ep93xx/epe.c:1.1.1.2	Mon Jan 31 01:52:20 2005
+++ sys/arch/arm/ep93xx/epe.c	Tue Oct 25 01:14:14 2005
@@ -93,6 +93,8 @@
 #include <arm/ep93xx/epereg.h> 
 #include <arm/ep93xx/epevar.h> 
 
+#define DEFAULT_MDCDIV	32
+
 #ifndef EPE_FAST
 #define EPE_FAST
 #endif
@@ -299,6 +309,7 @@
 	caddr_t addr;
 	int rsegs, err, i;
 	struct ifnet * ifp = &sc->sc_ec.ec_if;
+	int mdcdiv = DEFAULT_MDCDIV;
 
 	callout_init(&sc->epe_tick_ch);
 
@@ -406,7 +417,9 @@
 	}
 
 	/* Divide HCLK by 32 for MDC clock */
-	EPE_WRITE(SelfCtl, (SelfCtl_MDCDIV(32)|SelfCtl_PSPRS));
+	if (sc->sc_dev.dv_cfdata->cf_flags)
+		mdcdiv = sc->sc_dev.dv_cfdata->cf_flags;
+	EPE_WRITE(SelfCtl, (SelfCtl_MDCDIV(mdcdiv)|SelfCtl_PSPRS));
 
 	sc->sc_mii.mii_ifp = ifp;
 	sc->sc_mii.mii_readreg = epe_mii_readreg;

----Next_Part(Mon_Nov__7_06:18:22_2005_278)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="attach.diff"

Index: sys/arch/arm/ep93xx/epsoc.c
diff -u sys/arch/arm/ep93xx/epsoc.c:1.1.1.3 sys/arch/arm/ep93xx/epsoc.c:1.1.2.7
--- sys/arch/arm/ep93xx/epsoc.c:1.1.1.3	Sat Oct  8 14:41:46 2005
+++ sys/arch/arm/ep93xx/epsoc.c	Tue Oct 25 03:29:54 2005
@@ -59,6 +59,8 @@
 static int	epsoc_search(struct device *, struct cfdata *,
 			     const int *, void *);
 static int	epsoc_print(void *, const char *);
+static int	epsoc_submatch(struct device *, struct cfdata *,
+			       const int *, void *);
 
 CFATTACH_DECL(epsoc, sizeof(struct epsoc_softc),
     epsoc_match, epsoc_attach, NULL, NULL);
@@ -86,7 +88,8 @@
 	u_int64_t		fclk, pclk, hclk;
 	u_int32_t		id, clkset1;
 	const char		*rev;
-
+	int			locs[EPSOCCF_NLOCS];
+	struct epsoc_attach_args sa;
 
 	sc = (struct epsoc_softc*) self;
 
@@ -164,31 +167,55 @@
 
 	/*
 	 *  Attach each devices
+	 *	some device is used by other system device. so attach first.
 	 */
-	config_search_ia(epsoc_search, self, "epsoc", NULL);
+	sa.sa_iot = sc->sc_iot;
+	sa.sa_dmat = sc->sc_dmat;
+	sa.sa_hclk = sc->sc_hclk;
+	sa.sa_pclk = sc->sc_pclk;
+	locs[EPSOCCF_ADDR] = EP93XX_APB_HWBASE + EP93XX_APB_TIMERS;
+	config_found_sm_loc(self, "epsoc", locs, &sa,
+			    epsoc_print, epsoc_submatch);
+	locs[EPSOCCF_ADDR] = EP93XX_APB_HWBASE + EP93XX_APB_GPIO;
+	config_found_sm_loc(self, "epsoc", locs, &sa,
+			    epsoc_print, epsoc_submatch);
+	config_search_ia(epsoc_search, self, "epsoc", &sa);
 	
 }
 
 int
+epsoc_submatch(parent, cf, ldesc, aux)
+	struct device *parent;
+	struct cfdata *cf;
+	const int *ldesc;
+	void *aux;
+{
+	struct epsoc_attach_args *sa = aux;
+
+	if (cf->cf_loc[EPSOCCF_ADDR] == ldesc[EPSOCCF_ADDR]) {
+		sa->sa_addr = cf->cf_loc[EPSOCCF_ADDR];
+		sa->sa_size = cf->cf_loc[EPSOCCF_SIZE];
+		sa->sa_intr = cf->cf_loc[EPSOCCF_INTR];
+		return (config_match(parent, cf, aux));
+	} else
+		return (0);
+}
+
+int
 epsoc_search(parent, cf, ldesc, aux)
 	struct device *parent;
 	struct cfdata *cf;
 	const int *ldesc;
 	void *aux;
 {
-	struct epsoc_softc *sc = (struct epsoc_softc *)parent;
-	struct epsoc_attach_args sa;
+	struct epsoc_attach_args *sa = aux;
 
-	sa.sa_iot = sc->sc_iot;
-	sa.sa_dmat = sc->sc_dmat;
-	sa.sa_addr = cf->cf_loc[EPSOCCF_ADDR];
-	sa.sa_size = cf->cf_loc[EPSOCCF_SIZE];
-	sa.sa_intr = cf->cf_loc[EPSOCCF_INTR];
-	sa.sa_hclk = sc->sc_hclk;
-	sa.sa_pclk = sc->sc_pclk;
+	sa->sa_addr = cf->cf_loc[EPSOCCF_ADDR];
+	sa->sa_size = cf->cf_loc[EPSOCCF_SIZE];
+	sa->sa_intr = cf->cf_loc[EPSOCCF_INTR];
 
-	if (config_match(parent, cf, &sa) > 0)
-		config_attach(parent, cf, &sa, epsoc_print);
+	if (config_match(parent, cf, aux) > 0)
+		config_attach(parent, cf, aux, epsoc_print);
 
 	return (0);
 }

----Next_Part(Mon_Nov__7_06:18:22_2005_278)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="mac-addr.diff"

Index: arch/arm/ep93xx/epe.c
diff -u arch/arm/ep93xx/epe.c:1.1.1.3 arch/arm/ep93xx/epe.c:1.1.2.10
--- arch/arm/ep93xx/epe.c:1.1.1.3	Tue Nov  1 23:38:15 2005
+++ arch/arm/ep93xx/epe.c	Tue Nov  1 23:53:19 2005
@@ -156,6 +158,14 @@
 		0, &sc->sc_ioh))
 		panic("%s: Cannot map registers", self->dv_xname);
 
+	/* Fetch the Ethernet address from property if set. */
+	if (prop_get(dev_propdb, 0, "mac-addr", sc->sc_enaddr,
+		       ETHER_ADDR_LEN, NULL) == ETHER_ADDR_LEN) {
+		bus_space_write_4(sc->sc_iot, sc->sc_ioh, EPE_AFP, 0);
+		bus_space_write_region_1(sc->sc_iot, sc->sc_ioh, EPE_IndAd,
+					 sc->sc_enaddr, ETHER_ADDR_LEN);
+	}
+
         ep93xx_intr_establish(sc->sc_intr, IPL_NET, epe_intr, sc);
 	epe_init(sc);
 }

----Next_Part(Mon_Nov__7_06:18:22_2005_278)----