linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] using mii-bitbang on different processor ports
@ 2007-10-30 16:09 Sergej Stepanov
  2007-10-30 16:32 ` Scott Wood
  2007-10-31  2:50 ` Stephen Rothwell
  0 siblings, 2 replies; 5+ messages in thread
From: Sergej Stepanov @ 2007-10-30 16:09 UTC (permalink / raw)
  To: linuxppc-dev

The patch makes possible to have mdio and mdc pins on different physical ports
also for CONFIG_PPC_CPM_NEW_BINDING.
To setup it in the device tree:
reg = <10d40 14 10d60 14>; // mdc-offset: 0x10d40, mdio-offset: 0x10d60
or
reg = <10d40 14>; // mdc and mdio have the same offset 0x10d40
The approach was taken from older version.

Signed-off-by: Sergej Stepanov <Sergej.Stepanov@ids.de>
--
diff --git a/drivers/net/fs_enet/mii-bitbang.c b/drivers/net/fs_enet/mii-bitbang.c
index b8e4a73..86b73ea 100644
--- a/drivers/net/fs_enet/mii-bitbang.c
+++ b/drivers/net/fs_enet/mii-bitbang.c
@@ -29,12 +29,16 @@
 
 #include "fs_enet.h"
 
-struct bb_info {
-	struct mdiobb_ctrl ctrl;
+struct bb_port {
 	__be32 __iomem *dir;
 	__be32 __iomem *dat;
-	u32 mdio_msk;
-	u32 mdc_msk;
+	u32 msk;
+};
+
+struct bb_info {
+	struct mdiobb_ctrl ctrl;
+	struct bb_port mdc;
+	struct bb_port mdio;
 };
 
 /* FIXME: If any other users of GPIO crop up, then these will have to
@@ -62,18 +66,18 @@ static inline void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
 	struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
 
 	if (dir)
-		bb_set(bitbang->dir, bitbang->mdio_msk);
+		bb_set(bitbang->mdio.dir, bitbang->mdio.msk);
 	else
-		bb_clr(bitbang->dir, bitbang->mdio_msk);
+		bb_clr(bitbang->mdio.dir, bitbang->mdio.msk);
 
 	/* Read back to flush the write. */
-	in_be32(bitbang->dir);
+	in_be32(bitbang->mdio.dir);
 }
 
 static inline int mdio_read(struct mdiobb_ctrl *ctrl)
 {
 	struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
-	return bb_read(bitbang->dat, bitbang->mdio_msk);
+	return bb_read(bitbang->mdio.dat, bitbang->mdio.msk);
 }
 
 static inline void mdio(struct mdiobb_ctrl *ctrl, int what)
@@ -81,12 +85,12 @@ static inline void mdio(struct mdiobb_ctrl *ctrl, int what)
 	struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
 
 	if (what)
-		bb_set(bitbang->dat, bitbang->mdio_msk);
+		bb_set(bitbang->mdio.dat, bitbang->mdio.msk);
 	else
-		bb_clr(bitbang->dat, bitbang->mdio_msk);
+		bb_clr(bitbang->mdio.dat, bitbang->mdio.msk);
 
 	/* Read back to flush the write. */
-	in_be32(bitbang->dat);
+	in_be32(bitbang->mdio.dat);
 }
 
 static inline void mdc(struct mdiobb_ctrl *ctrl, int what)
@@ -94,12 +98,12 @@ static inline void mdc(struct mdiobb_ctrl *ctrl, int what)
 	struct bb_info *bitbang = container_of(ctrl, struct bb_info, ctrl);
 
 	if (what)
-		bb_set(bitbang->dat, bitbang->mdc_msk);
+		bb_set(bitbang->mdc.dat, bitbang->mdc.msk);
 	else
-		bb_clr(bitbang->dat, bitbang->mdc_msk);
+		bb_clr(bitbang->mdc.dat, bitbang->mdc.msk);
 
 	/* Read back to flush the write. */
-	in_be32(bitbang->dat);
+	in_be32(bitbang->mdc.dat);
 }
 
 static struct mdiobb_ops bb_ops = {
@@ -114,23 +118,23 @@ static struct mdiobb_ops bb_ops = {
 static int __devinit fs_mii_bitbang_init(struct mii_bus *bus,
                                          struct device_node *np)
 {
-	struct resource res;
+	struct resource res[2];
 	const u32 *data;
 	int mdio_pin, mdc_pin, len;
 	struct bb_info *bitbang = bus->priv;
 
-	int ret = of_address_to_resource(np, 0, &res);
+	int ret = of_address_to_resource(np, 0, &res[0]);
 	if (ret)
 		return ret;
 
-	if (res.end - res.start < 13)
+	if (res[0].end - res[0].start < 13)
 		return -ENODEV;
 
 	/* This should really encode the pin number as well, but all
 	 * we get is an int, and the odds of multiple bitbang mdio buses
 	 * is low enough that it's not worth going too crazy.
 	 */
-	bus->id = res.start;
+	bus->id = res[0].start;
 
 	data = of_get_property(np, "fsl,mdio-pin", &len);
 	if (!data || len != 4)
@@ -142,13 +146,27 @@ static int __devinit fs_mii_bitbang_init(struct mii_bus *bus,
 		return -ENODEV;
 	mdc_pin = *data;
 
-	bitbang->dir = ioremap(res.start, res.end - res.start + 1);
-	if (!bitbang->dir)
+	bitbang->mdc.dir = ioremap(res[0].start, res[0].end - res[0].start + 1);
+	if (!bitbang->mdc.dir)
 		return -ENOMEM;
 
-	bitbang->dat = bitbang->dir + 4;
-	bitbang->mdio_msk = 1 << (31 - mdio_pin);
-	bitbang->mdc_msk = 1 << (31 - mdc_pin);
+	bitbang->mdc.dat = bitbang->mdc.dir + 4;
+	if( !of_address_to_resource(np, 1, &res[1]))
+	{
+		bitbang->mdio.dir = ioremap(res[1].start, res[1].end - res[1].start + 1);
+		if (!bitbang->mdio.dir)
+		{
+			iounmap(bitbang->mdc.dir);
+			return -ENOMEM;
+		}
+		bitbang->mdio.dat = bitbang->mdio.dir + 4;
+	}
+	else{
+		bitbang->mdio.dir = bitbang->mdc.dir;
+		bitbang->mdio.dat = bitbang->mdc.dat;
+	}
+	bitbang->mdio.msk = 1 << (31 - mdio_pin);
+	bitbang->mdc.msk = 1 << (31 - mdc_pin);
 
 	return 0;
 }
@@ -220,7 +238,9 @@ out_free_irqs:
 	dev_set_drvdata(&ofdev->dev, NULL);
 	kfree(new_bus->irq);
 out_unmap_regs:
-	iounmap(bitbang->dir);
+	if ( bitbang->mdio.dir != bitbang->mdc.dir)
+		iounmap(bitbang->mdio.dir);
+	iounmap(bitbang->mdc.dir);
 out_free_bus:
 	kfree(new_bus);
 out_free_priv:
@@ -238,7 +258,9 @@ static int fs_enet_mdio_remove(struct of_device *ofdev)
 	free_mdio_bitbang(bus);
 	dev_set_drvdata(&ofdev->dev, NULL);
 	kfree(bus->irq);
-	iounmap(bitbang->dir);
+	if ( bitbang->mdio.dir != bitbang->mdc.dir)
+		iounmap(bitbang->mdio.dir);
+	iounmap(bitbang->mdc.dir);
 	kfree(bitbang);
 	kfree(bus);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] using mii-bitbang on different processor ports
  2007-10-30 16:09 [PATCH] using mii-bitbang on different processor ports Sergej Stepanov
@ 2007-10-30 16:32 ` Scott Wood
  2007-10-30 16:58   ` Sergej Stepanov
  2007-10-31  2:50 ` Stephen Rothwell
  1 sibling, 1 reply; 5+ messages in thread
From: Scott Wood @ 2007-10-30 16:32 UTC (permalink / raw)
  To: Sergej Stepanov; +Cc: linuxppc-dev

On Tue, Oct 30, 2007 at 05:09:19PM +0100, Sergej Stepanov wrote:
> The patch makes possible to have mdio and mdc pins on different physical ports
> also for CONFIG_PPC_CPM_NEW_BINDING.
> To setup it in the device tree:
> reg = <10d40 14 10d60 14>; // mdc-offset: 0x10d40, mdio-offset: 0x10d60
> or
> reg = <10d40 14>; // mdc and mdio have the same offset 0x10d40
> The approach was taken from older version.

There are some formatting issues in fs_mii_bitbang_init(), but otherwise it
looks good.  It'll need to be sent to Jeff Garzik and the netdev list, not
just linuxppc-dev, though.

Also, please update Documentation/powerpc/booting-without-of.txt (probably
in a separate patch, since that one would go through Paul).

> @@ -142,13 +146,27 @@ static int __devinit fs_mii_bitbang_init(struct mii_bus *bus,
>  		return -ENODEV;
>  	mdc_pin = *data;
>  
> -	bitbang->dir = ioremap(res.start, res.end - res.start + 1);
> -	if (!bitbang->dir)
> +	bitbang->mdc.dir = ioremap(res[0].start, res[0].end - res[0].start + 1);
> +	if (!bitbang->mdc.dir)
>  		return -ENOMEM;
>  
> -	bitbang->dat = bitbang->dir + 4;
> -	bitbang->mdio_msk = 1 << (31 - mdio_pin);
> -	bitbang->mdc_msk = 1 << (31 - mdc_pin);
> +	bitbang->mdc.dat = bitbang->mdc.dir + 4;
> +	if( !of_address_to_resource(np, 1, &res[1]))

Space before the '(', not after.  A newline after the previous line would be
nice, too.

> +	{

Brace at the end of the previous line.

> +		bitbang->mdio.dir = ioremap(res[1].start, res[1].end - res[1].start + 1);
> +		if (!bitbang->mdio.dir)
> +		{

Likewise.

You could just use of_iomap() for the second one, since we don't need
the physical address for bus->id.

> +			iounmap(bitbang->mdc.dir);
> +			return -ENOMEM;

Please use the goto-style error handling that's used elsewhere in the
function.

> +		}
> +		bitbang->mdio.dat = bitbang->mdio.dir + 4;
> +	}
> +	else{

} else {

>  out_unmap_regs:
> -	iounmap(bitbang->dir);
> +	if ( bitbang->mdio.dir != bitbang->mdc.dir)
> +		iounmap(bitbang->mdio.dir);
> +	iounmap(bitbang->mdc.dir);
>  out_free_bus:
>  	kfree(new_bus);
>  out_free_priv:
> @@ -238,7 +258,9 @@ static int fs_enet_mdio_remove(struct of_device *ofdev)
>  	free_mdio_bitbang(bus);
>  	dev_set_drvdata(&ofdev->dev, NULL);
>  	kfree(bus->irq);
> -	iounmap(bitbang->dir);
> +	if ( bitbang->mdio.dir != bitbang->mdc.dir)
> +		iounmap(bitbang->mdio.dir);
> +	iounmap(bitbang->mdc.dir);
>  	kfree(bitbang);
>  	kfree(bus);

"if (bitbang", not "if ( bitbang".

-Scott

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] using mii-bitbang on different processor ports
  2007-10-30 16:32 ` Scott Wood
@ 2007-10-30 16:58   ` Sergej Stepanov
  2007-10-30 17:16     ` Scott Wood
  0 siblings, 1 reply; 5+ messages in thread
From: Sergej Stepanov @ 2007-10-30 16:58 UTC (permalink / raw)
  To: linuxppc-dev

Hello Scott.
Thank you for reply.
Am Dienstag, den 30.10.2007, 11:32 -0500 schrieb Scott Wood:
> On Tue, Oct 30, 2007 at 05:09:19PM +0100, Sergej Stepanov wrote:

> You could just use of_iomap() for the second one, since we don't need
> the physical address for bus->id.
Nice tip.
Than it would be needless-------
				|
				\/
> > +			iounmap(bitbang->mdc.dir);
> > +			return -ENOMEM;
> 
> Please use the goto-style error handling that's used elsewhere in the
> function.
Regards
Sergej.
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] using mii-bitbang on different processor ports
  2007-10-30 16:58   ` Sergej Stepanov
@ 2007-10-30 17:16     ` Scott Wood
  0 siblings, 0 replies; 5+ messages in thread
From: Scott Wood @ 2007-10-30 17:16 UTC (permalink / raw)
  To: Sergej Stepanov; +Cc: linuxppc-dev

Sergej Stepanov wrote:
> Hello Scott.
> Thank you for reply.
> Am Dienstag, den 30.10.2007, 11:32 -0500 schrieb Scott Wood:
>> On Tue, Oct 30, 2007 at 05:09:19PM +0100, Sergej Stepanov wrote:
> 
>> You could just use of_iomap() for the second one, since we don't need
>> the physical address for bus->id.
> Nice tip.
> Than it would be needless-------
> 				|
> 				\/
>>> +			iounmap(bitbang->mdc.dir);
>>> +			return -ENOMEM;
>> Please use the goto-style error handling that's used elsewhere in the
>> function.

Hmm... in this case, it'd be impossible to tell using of_iomap() whether 
a failure was due to reg only having one resource (and thus meaning the 
same one should be used for both), or due to ioremap() failure.  Maybe 
we should keep it separate.

-Scott

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] using mii-bitbang on different processor ports
  2007-10-30 16:09 [PATCH] using mii-bitbang on different processor ports Sergej Stepanov
  2007-10-30 16:32 ` Scott Wood
@ 2007-10-31  2:50 ` Stephen Rothwell
  1 sibling, 0 replies; 5+ messages in thread
From: Stephen Rothwell @ 2007-10-31  2:50 UTC (permalink / raw)
  To: Sergej Stepanov; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 945 bytes --]

On Tue, 30 Oct 2007 17:09:19 +0100 Sergej Stepanov <Sergej.Stepanov@ids.de> wrote:
>
>  static int __devinit fs_mii_bitbang_init(struct mii_bus *bus,
>                                           struct device_node *np)
>  {
> -	struct resource res;
> +	struct resource res[2];

Why not just reuse the same resource structure?  You don't seem to need
them both at the same time.

> +	if( !of_address_to_resource(np, 1, &res[1]))
> +	{
> +		bitbang->mdio.dir = ioremap(res[1].start, res[1].end - res[1].start + 1);
> +		if (!bitbang->mdio.dir)
> +		{
> +			iounmap(bitbang->mdc.dir);
> +			return -ENOMEM;
> +		}
> +		bitbang->mdio.dat = bitbang->mdio.dir + 4;
> +	}
> +	else{

Formatting:
	if () {
	} else {
	}
> +	if ( bitbang->mdio.dir != bitbang->mdc.dir)

No spaces after (, please.  Here and elsewhere.

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-11-02 18:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-30 16:09 [PATCH] using mii-bitbang on different processor ports Sergej Stepanov
2007-10-30 16:32 ` Scott Wood
2007-10-30 16:58   ` Sergej Stepanov
2007-10-30 17:16     ` Scott Wood
2007-10-31  2:50 ` Stephen Rothwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).