2019-05-27 08:55:01 +02:00
// SPDX-License-Identifier: GPL-2.0-or-later
2006-06-13 15:07:23 +08:00
/*
* tsi108 / 109 device setup code
*
* Maintained by Roy Zang < tie - fei . zang @ freescale . com >
*/
# include <linux/stddef.h>
# include <linux/kernel.h>
# include <linux/init.h>
# include <linux/errno.h>
# include <linux/major.h>
# include <linux/delay.h>
# include <linux/irq.h>
2011-07-22 18:24:23 -04:00
# include <linux/export.h>
2006-06-13 15:07:23 +08:00
# include <linux/device.h>
powerpc: tsi108: fix similar warning reported by kbuild test robot
This patch fixes following (similar) warning reported by kbuild test robot:
In function ‘memcpy’,
inlined from ‘smsc75xx_init_mac_address’ at drivers/net/usb/smsc75xx.c:778:3,
inlined from ‘smsc75xx_bind’ at drivers/net/usb/smsc75xx.c:1501:2:
./include/linux/string.h:355:9: warning: argument 2 null where non-null expected [-Wnonnull]
return __builtin_memcpy(p, q, size);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/usb/smsc75xx.c: In function ‘smsc75xx_bind’:
./include/linux/string.h:355:9: note: in a call to built-in function ‘__builtin_memcpy’
I've replaced the offending memcpy with ether_addr_copy, because I'm
100% sure, that of_get_mac_address can't return NULL as it returns valid
pointer or ERR_PTR encoded value, nothing else.
I'm hesitant to just change IS_ERR into IS_ERR_OR_NULL check, as this
would make the warning disappear also, but it would be confusing to
check for impossible return value just to make a compiler happy.
I'm now changing all occurencies of memcpy to ether_addr_copy after the
of_get_mac_address call, as it's very likely, that we're going to get
similar reports from kbuild test robot in the future.
Fixes: ea168cdf1299 ("powerpc: tsi108: support of_get_mac_address new ERR_PTR error")
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-05-10 11:35:16 +02:00
# include <linux/etherdevice.h>
2006-06-13 15:07:23 +08:00
# include <linux/platform_device.h>
2022-03-08 20:20:25 +01:00
# include <linux/of_address.h>
# include <linux/of_irq.h>
2010-10-26 15:07:13 -07:00
# include <linux/of_net.h>
2006-06-13 15:07:23 +08:00
# include <asm/tsi108.h>
2011-07-26 16:09:06 -07:00
# include <linux/atomic.h>
2006-06-13 15:07:23 +08:00
# include <asm/io.h>
# include <asm/irq.h>
# include <mm/mmu_decl.h>
# undef DEBUG
# ifdef DEBUG
# define DBG(fmt...) do { printk(fmt); } while(0)
# else
# define DBG(fmt...) do { } while(0)
# endif
static phys_addr_t tsi108_csr_base = - 1 ;
phys_addr_t get_csrbase ( void )
{
struct device_node * tsi ;
if ( tsi108_csr_base ! = - 1 )
return tsi108_csr_base ;
tsi = of_find_node_by_type ( NULL , " tsi-bridge " ) ;
if ( tsi ) {
unsigned int size ;
2007-04-03 22:26:41 +10:00
const void * prop = of_get_property ( tsi , " reg " , & size ) ;
2006-06-13 15:07:23 +08:00
tsi108_csr_base = of_translate_address ( tsi , prop ) ;
of_node_put ( tsi ) ;
2019-02-02 13:54:27 +01:00
}
2006-06-13 15:07:23 +08:00
return tsi108_csr_base ;
}
2021-11-14 19:56:16 +08:00
EXPORT_SYMBOL ( get_csrbase ) ;
2006-06-13 15:07:23 +08:00
u32 get_vir_csrbase ( void )
{
return ( u32 ) ( ioremap ( get_csrbase ( ) , 0x10000 ) ) ;
}
EXPORT_SYMBOL ( get_vir_csrbase ) ;
static int __init tsi108_eth_of_init ( void )
{
struct device_node * np ;
2007-11-30 06:44:36 +11:00
unsigned int i = 0 ;
2006-06-13 15:07:23 +08:00
struct platform_device * tsi_eth_dev ;
struct resource res ;
int ret ;
2007-11-30 06:44:36 +11:00
for_each_compatible_node ( np , " network " , " tsi108-ethernet " ) {
2006-06-13 15:07:23 +08:00
struct resource r [ 2 ] ;
[POWERPC] Fix problems with device tree representation of TSI-1xx bridges
This fixes some problems with the way the some things
represented in the device tree for the Holly and Taiga boards. This
means changes both to the dts files, and to the code which
instantiates the tsi108 ethernet platform devices based on the device
tree.
- First, and most importantly, the ethernet PHYs are given
with an identical 'reg' property. This reg currently encodes the
accessible register used to initiate mdio interaction with the PHYs,
rather than a meaningful address on the parent bus (mdio in this
case), which is incorrect. Instead we give the address of these
registers as 'reg' in the mdio node itself, and encode the ID of each
phy in their 'reg' propertyies.
- Currently the platform device constructor enables a
workaround in the tsi108 ethernet driver based on the compatible
property of the PHY. This is incorrect, because the workaround in
question is necessary due to the board's wiring of the PHY, not the
model of PHY itself. This patch alters the constructor to instead
enable the workaround based on a new special property in the PHY node.
- The compatible properties on a number of nodes in the device
tree are insufficiently precise. In particular the PHYs give only
"bcm54xx", which is broken, since there are many bcm54xx PHY models,
and they have differences which matter. The mdio had a compatible
property of "tsi-ethernet" identical to the ethernet MAC nodes, which
doesn't make sense. The ethernet, i2c, bridge and PCI nodes were
given only as "tsi-*" which is somewhat inprecise, we replace with
"tsi108-*" in the case of Taiga (which has a TSI108 bridge), and
"tsi109-*", "tsi108-*" in the case of Holly (which has a TSI109
bridge).
- We remove some "model" properties from the ethernets on
Taiga board which were neither useful nor adequately precise.
- On Holly we change to using a dtc label instead of a full
path to reference the MPIC node, which makes the dts a little more
readable.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-06-13 14:53:00 +10:00
struct device_node * phy , * mdio ;
2006-06-13 15:07:23 +08:00
hw_info tsi_eth_data ;
2007-04-03 22:26:41 +10:00
const unsigned int * phy_id ;
const phandle * ph ;
2006-06-13 15:07:23 +08:00
memset ( r , 0 , sizeof ( r ) ) ;
memset ( & tsi_eth_data , 0 , sizeof ( tsi_eth_data ) ) ;
ret = of_address_to_resource ( np , 0 , & r [ 0 ] ) ;
2010-11-12 14:49:19 +00:00
DBG ( " %s: name:start->end = %s:%pR \n " ,
__func__ , r [ 0 ] . name , & r [ 0 ] ) ;
2006-06-13 15:07:23 +08:00
if ( ret )
goto err ;
r [ 1 ] . name = " tx " ;
2006-08-23 10:19:50 +08:00
r [ 1 ] . start = irq_of_parse_and_map ( np , 0 ) ;
r [ 1 ] . end = irq_of_parse_and_map ( np , 0 ) ;
2006-06-13 15:07:23 +08:00
r [ 1 ] . flags = IORESOURCE_IRQ ;
2010-11-12 14:49:19 +00:00
DBG ( " %s: name:start->end = %s:%pR \n " ,
__func__ , r [ 1 ] . name , & r [ 1 ] ) ;
2006-06-13 15:07:23 +08:00
tsi_eth_dev =
2007-11-30 06:44:36 +11:00
platform_device_register_simple ( " tsi-ethernet " , i + + , & r [ 0 ] ,
2006-08-23 10:19:50 +08:00
1 ) ;
2006-06-13 15:07:23 +08:00
if ( IS_ERR ( tsi_eth_dev ) ) {
ret = PTR_ERR ( tsi_eth_dev ) ;
goto err ;
}
of: net: pass the dst buffer to of_get_mac_address()
of_get_mac_address() returns a "const void*" pointer to a MAC address.
Lately, support to fetch the MAC address by an NVMEM provider was added.
But this will only work with platform devices. It will not work with
PCI devices (e.g. of an integrated root complex) and esp. not with DSA
ports.
There is an of_* variant of the nvmem binding which works without
devices. The returned data of a nvmem_cell_read() has to be freed after
use. On the other hand the return of_get_mac_address() points to some
static data without a lifetime. The trick for now, was to allocate a
device resource managed buffer which is then returned. This will only
work if we have an actual device.
Change it, so that the caller of of_get_mac_address() has to supply a
buffer where the MAC address is written to. Unfortunately, this will
touch all drivers which use the of_get_mac_address().
Usually the code looks like:
const char *addr;
addr = of_get_mac_address(np);
if (!IS_ERR(addr))
ether_addr_copy(ndev->dev_addr, addr);
This can then be simply rewritten as:
of_get_mac_address(np, ndev->dev_addr);
Sometimes is_valid_ether_addr() is used to test the MAC address.
of_get_mac_address() already makes sure, it just returns a valid MAC
address. Thus we can just test its return code. But we have to be
careful if there are still other sources for the MAC address before the
of_get_mac_address(). In this case we have to keep the
is_valid_ether_addr() call.
The following coccinelle patch was used to convert common cases to the
new style. Afterwards, I've manually gone over the drivers and fixed the
return code variable: either used a new one or if one was already
available use that. Mansour Moufid, thanks for that coccinelle patch!
<spml>
@a@
identifier x;
expression y, z;
@@
- x = of_get_mac_address(y);
+ x = of_get_mac_address(y, z);
<...
- ether_addr_copy(z, x);
...>
@@
identifier a.x;
@@
- if (<+... x ...+>) {}
@@
identifier a.x;
@@
if (<+... x ...+>) {
...
}
- else {}
@@
identifier a.x;
expression e;
@@
- if (<+... x ...+>@e)
- {}
- else
+ if (!(e))
{...}
@@
expression x, y, z;
@@
- x = of_get_mac_address(y, z);
+ of_get_mac_address(y, z);
... when != x
</spml>
All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
compile-time tested.
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-12 19:47:17 +02:00
of_get_mac_address ( np , tsi_eth_data . mac_addr ) ;
2006-06-13 15:07:23 +08:00
[POWERPC] Fix problems with device tree representation of TSI-1xx bridges
This fixes some problems with the way the some things
represented in the device tree for the Holly and Taiga boards. This
means changes both to the dts files, and to the code which
instantiates the tsi108 ethernet platform devices based on the device
tree.
- First, and most importantly, the ethernet PHYs are given
with an identical 'reg' property. This reg currently encodes the
accessible register used to initiate mdio interaction with the PHYs,
rather than a meaningful address on the parent bus (mdio in this
case), which is incorrect. Instead we give the address of these
registers as 'reg' in the mdio node itself, and encode the ID of each
phy in their 'reg' propertyies.
- Currently the platform device constructor enables a
workaround in the tsi108 ethernet driver based on the compatible
property of the PHY. This is incorrect, because the workaround in
question is necessary due to the board's wiring of the PHY, not the
model of PHY itself. This patch alters the constructor to instead
enable the workaround based on a new special property in the PHY node.
- The compatible properties on a number of nodes in the device
tree are insufficiently precise. In particular the PHYs give only
"bcm54xx", which is broken, since there are many bcm54xx PHY models,
and they have differences which matter. The mdio had a compatible
property of "tsi-ethernet" identical to the ethernet MAC nodes, which
doesn't make sense. The ethernet, i2c, bridge and PCI nodes were
given only as "tsi-*" which is somewhat inprecise, we replace with
"tsi108-*" in the case of Taiga (which has a TSI108 bridge), and
"tsi109-*", "tsi108-*" in the case of Holly (which has a TSI109
bridge).
- We remove some "model" properties from the ethernets on
Taiga board which were neither useful nor adequately precise.
- On Holly we change to using a dtc label instead of a full
path to reference the MPIC node, which makes the dts a little more
readable.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-06-13 14:53:00 +10:00
ph = of_get_property ( np , " mdio-handle " , NULL ) ;
mdio = of_find_node_by_phandle ( * ph ) ;
ret = of_address_to_resource ( mdio , 0 , & res ) ;
of_node_put ( mdio ) ;
if ( ret )
goto unreg ;
2007-04-03 22:26:41 +10:00
ph = of_get_property ( np , " phy-handle " , NULL ) ;
2006-06-13 15:07:23 +08:00
phy = of_find_node_by_phandle ( * ph ) ;
if ( phy = = NULL ) {
ret = - ENODEV ;
goto unreg ;
}
[POWERPC] Fix problems with device tree representation of TSI-1xx bridges
This fixes some problems with the way the some things
represented in the device tree for the Holly and Taiga boards. This
means changes both to the dts files, and to the code which
instantiates the tsi108 ethernet platform devices based on the device
tree.
- First, and most importantly, the ethernet PHYs are given
with an identical 'reg' property. This reg currently encodes the
accessible register used to initiate mdio interaction with the PHYs,
rather than a meaningful address on the parent bus (mdio in this
case), which is incorrect. Instead we give the address of these
registers as 'reg' in the mdio node itself, and encode the ID of each
phy in their 'reg' propertyies.
- Currently the platform device constructor enables a
workaround in the tsi108 ethernet driver based on the compatible
property of the PHY. This is incorrect, because the workaround in
question is necessary due to the board's wiring of the PHY, not the
model of PHY itself. This patch alters the constructor to instead
enable the workaround based on a new special property in the PHY node.
- The compatible properties on a number of nodes in the device
tree are insufficiently precise. In particular the PHYs give only
"bcm54xx", which is broken, since there are many bcm54xx PHY models,
and they have differences which matter. The mdio had a compatible
property of "tsi-ethernet" identical to the ethernet MAC nodes, which
doesn't make sense. The ethernet, i2c, bridge and PCI nodes were
given only as "tsi-*" which is somewhat inprecise, we replace with
"tsi108-*" in the case of Taiga (which has a TSI108 bridge), and
"tsi109-*", "tsi108-*" in the case of Holly (which has a TSI109
bridge).
- We remove some "model" properties from the ethernets on
Taiga board which were neither useful nor adequately precise.
- On Holly we change to using a dtc label instead of a full
path to reference the MPIC node, which makes the dts a little more
readable.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-06-13 14:53:00 +10:00
phy_id = of_get_property ( phy , " reg " , NULL ) ;
2006-06-13 15:07:23 +08:00
tsi_eth_data . regs = r [ 0 ] . start ;
tsi_eth_data . phyregs = res . start ;
tsi_eth_data . phy = * phy_id ;
2006-08-23 10:19:50 +08:00
tsi_eth_data . irq_num = irq_of_parse_and_map ( np , 0 ) ;
[POWERPC] Fix problems with device tree representation of TSI-1xx bridges
This fixes some problems with the way the some things
represented in the device tree for the Holly and Taiga boards. This
means changes both to the dts files, and to the code which
instantiates the tsi108 ethernet platform devices based on the device
tree.
- First, and most importantly, the ethernet PHYs are given
with an identical 'reg' property. This reg currently encodes the
accessible register used to initiate mdio interaction with the PHYs,
rather than a meaningful address on the parent bus (mdio in this
case), which is incorrect. Instead we give the address of these
registers as 'reg' in the mdio node itself, and encode the ID of each
phy in their 'reg' propertyies.
- Currently the platform device constructor enables a
workaround in the tsi108 ethernet driver based on the compatible
property of the PHY. This is incorrect, because the workaround in
question is necessary due to the board's wiring of the PHY, not the
model of PHY itself. This patch alters the constructor to instead
enable the workaround based on a new special property in the PHY node.
- The compatible properties on a number of nodes in the device
tree are insufficiently precise. In particular the PHYs give only
"bcm54xx", which is broken, since there are many bcm54xx PHY models,
and they have differences which matter. The mdio had a compatible
property of "tsi-ethernet" identical to the ethernet MAC nodes, which
doesn't make sense. The ethernet, i2c, bridge and PCI nodes were
given only as "tsi-*" which is somewhat inprecise, we replace with
"tsi108-*" in the case of Taiga (which has a TSI108 bridge), and
"tsi109-*", "tsi108-*" in the case of Holly (which has a TSI109
bridge).
- We remove some "model" properties from the ethernets on
Taiga board which were neither useful nor adequately precise.
- On Holly we change to using a dtc label instead of a full
path to reference the MPIC node, which makes the dts a little more
readable.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-06-13 14:53:00 +10:00
/* Some boards with the TSI108 bridge (e.g. Holly)
* have a miswiring of the ethernet PHYs which
* requires a workaround . The special
* " txc-rxc-delay-disable " property enables this
* workaround . FIXME : Need to port the tsi108_eth
* driver itself to phylib and use a non - misleading
* name for the workaround flag - it ' s not actually to
* do with the model of PHY in use */
if ( of_get_property ( phy , " txc-rxc-delay-disable " , NULL ) )
2007-05-08 07:26:22 +10:00
tsi_eth_data . phy_type = TSI108_PHY_BCM54XX ;
2006-06-13 15:07:23 +08:00
of_node_put ( phy ) ;
[POWERPC] Fix problems with device tree representation of TSI-1xx bridges
This fixes some problems with the way the some things
represented in the device tree for the Holly and Taiga boards. This
means changes both to the dts files, and to the code which
instantiates the tsi108 ethernet platform devices based on the device
tree.
- First, and most importantly, the ethernet PHYs are given
with an identical 'reg' property. This reg currently encodes the
accessible register used to initiate mdio interaction with the PHYs,
rather than a meaningful address on the parent bus (mdio in this
case), which is incorrect. Instead we give the address of these
registers as 'reg' in the mdio node itself, and encode the ID of each
phy in their 'reg' propertyies.
- Currently the platform device constructor enables a
workaround in the tsi108 ethernet driver based on the compatible
property of the PHY. This is incorrect, because the workaround in
question is necessary due to the board's wiring of the PHY, not the
model of PHY itself. This patch alters the constructor to instead
enable the workaround based on a new special property in the PHY node.
- The compatible properties on a number of nodes in the device
tree are insufficiently precise. In particular the PHYs give only
"bcm54xx", which is broken, since there are many bcm54xx PHY models,
and they have differences which matter. The mdio had a compatible
property of "tsi-ethernet" identical to the ethernet MAC nodes, which
doesn't make sense. The ethernet, i2c, bridge and PCI nodes were
given only as "tsi-*" which is somewhat inprecise, we replace with
"tsi108-*" in the case of Taiga (which has a TSI108 bridge), and
"tsi109-*", "tsi108-*" in the case of Holly (which has a TSI109
bridge).
- We remove some "model" properties from the ethernets on
Taiga board which were neither useful nor adequately precise.
- On Holly we change to using a dtc label instead of a full
path to reference the MPIC node, which makes the dts a little more
readable.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-06-13 14:53:00 +10:00
2006-06-13 15:07:23 +08:00
ret =
platform_device_add_data ( tsi_eth_dev , & tsi_eth_data ,
sizeof ( hw_info ) ) ;
if ( ret )
goto unreg ;
}
return 0 ;
unreg :
platform_device_unregister ( tsi_eth_dev ) ;
err :
2007-11-30 06:44:36 +11:00
of_node_put ( np ) ;
2006-06-13 15:07:23 +08:00
return ret ;
}
arch_initcall ( tsi108_eth_of_init ) ;