Message ID | 1358370073-32545-1-git-send-email-jacmet@sunsite.dk (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi Peter, I made changes to cpsw driver two weeks ago, which add support for reading MAC address from CPU and also I posted it to review. You can find patch here : https://patchwork.kernel.org/patch/1966481/ I will create updated patch next week, depended on reactions. Can you try that patch? I'll be glad to hear your opinion. Michal -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>> "Michal" == Michal Bachraty <michal.bachraty@gmail.com> writes:
Hi Michael,
Michal> I made changes to cpsw driver two weeks ago, which add support
Michal> for reading MAC address from CPU and also I posted it to
Michal> review. You can find patch here :
Michal> https://patchwork.kernel.org/patch/1966481/ I will create
Michal> updated patch next week, depended on reactions. Can you try
Michal> that patch? I'll be glad to hear your opinion.
Thanks, I missed that patch. Functionality wise the patches do the same,
but I must say I find my patch cleaner, as it doesn't involve any new dt
bindings or access to the am33xx specific control module registers from
the cpsw driver.
The way I've handled it is similar to how it is done on atleast one
other arm subarchicture, see
arch/arm/mach-mxs/mach-mxs.c::update_fec_mac_prop()
* Peter Korsgaard <jacmet@sunsite.dk> [130117 08:46]: > >>>>> "Michal" == Michal Bachraty <michal.bachraty@gmail.com> writes: > > Hi Michael, > > Michal> I made changes to cpsw driver two weeks ago, which add support > Michal> for reading MAC address from CPU and also I posted it to > Michal> review. You can find patch here : > Michal> https://patchwork.kernel.org/patch/1966481/ I will create > Michal> updated patch next week, depended on reactions. Can you try > Michal> that patch? I'll be glad to hear your opinion. > > Thanks, I missed that patch. Functionality wise the patches do the same, > but I must say I find my patch cleaner, as it doesn't involve any new dt > bindings or access to the am33xx specific control module registers from > the cpsw driver. > > The way I've handled it is similar to how it is done on atleast one > other arm subarchicture, see > arch/arm/mach-mxs/mach-mxs.c::update_fec_mac_prop() Cool this seems like the cleanest way to deal with it so far. Can you please resend with also linux-net and DT list Cc:d too? Also the arch_initcall should be omap_arch_initcall in linux next for consistency if we ever have SoC specific sections for those. Regards, Tony -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>> "Tony" == Tony Lindgren <tony@atomide.com> writes: Hi, >> The way I've handled it is similar to how it is done on atleast one >> other arm subarchicture, see >> arch/arm/mach-mxs/mach-mxs.c::update_fec_mac_prop() Tony> Cool this seems like the cleanest way to deal with it so far. Can Tony> you please resend with also linux-net and DT list Cc:d too? Tony> Also the arch_initcall should be omap_arch_initcall in linux next Tony> for consistency if we ever have SoC specific sections for those. Sure, resent with the initcall change and netdev/devicetree-discuss added.
>>>>> "Michal" == Michal Bachraty <michal.bachraty@gmail.com> writes:
Hi,
Michal> I'm ok with your changes. Have you tried to set MAC from
Michal> u-boot? I haven't seen any code for that purpose in cpsw. I
Michal> tried put MAC with kernel command parameter (in u-boot), but
Michal> nothing happen.
I didn't actually try, but mainline U-Boot has support for updating the
mac-address properties if you:
- build U-Boot with dt support (CONFIG_OF_LIBFDT)
- use a seperate .dtb file
- add aliases called ethernet{0,1} to the 2 cpsw slaves in the dts
(this should arguable be done in am33xx.dtsi) - E.G.:
aliases {
..
ethernet0 = &cpsw_emac0;
ethernet1 = &cpsw_emac1;
};
Then U-boot will set the mac-address properties to the content of the
ethaddr / eth1addr environment variables. See fdt_fixup_ethernet() for
details.
diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile index 65fb6fb..54fb2ee 100644 --- a/arch/arm/mach-omap2/Makefile +++ b/arch/arm/mach-omap2/Makefile @@ -298,4 +298,7 @@ endif emac-$(CONFIG_TI_DAVINCI_EMAC) := am35xx-emac.o obj-y += $(emac-m) $(emac-y) +cpsw-$(CONFIG_TI_CPSW) := am33xx-cpsw.o +obj-y += $(cpsw-m) $(cpsw-y) + obj-y += common-board-devices.o twl-common.o dss-common.o diff --git a/arch/arm/mach-omap2/am33xx-cpsw.c b/arch/arm/mach-omap2/am33xx-cpsw.c new file mode 100644 index 0000000..5a674d9 --- /dev/null +++ b/arch/arm/mach-omap2/am33xx-cpsw.c @@ -0,0 +1,94 @@ +/* + * am335x specific cpsw dt fixups + * + * 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 version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/etherdevice.h> +#include <linux/of.h> +#include <linux/of_net.h> + +#include "soc.h" +#include "control.h" + +/** + * am33xx_dt_cpsw_set_mac_from_efuse - Add mac-address property using + * ethernet hwaddr from efuse + * @np: Pointer to the cpsw slave to set mac address of + * @idx: Mac address index to use from efuse + */ +static void am33xx_dt_cpsw_set_mac_from_efuse(struct device_node *np, int idx) +{ + struct property *prop; + u32 lo, hi; + u8 *mac; + + switch (idx) { + case 0: + lo = omap_ctrl_readl(AM33XX_CONTROL_MAC_ID0_LOW); + hi = omap_ctrl_readl(AM33XX_CONTROL_MAC_ID0_HIGH); + break; + + case 1: + lo = omap_ctrl_readl(AM33XX_CONTROL_MAC_ID1_LOW); + hi = omap_ctrl_readl(AM33XX_CONTROL_MAC_ID1_HIGH); + break; + + default: + pr_err("cpsw.%d: too many slaves found\n", idx); + return; + } + + prop = kzalloc(sizeof(*prop) + ETH_ALEN, GFP_KERNEL); + if (!prop) + return; + + prop->value = prop + 1; + prop->length = ETH_ALEN; + prop->name = kstrdup("mac-address", GFP_KERNEL); + if (!prop->name) { + kfree(prop); + return; + } + + mac = prop->value; + + mac[0] = hi; + mac[1] = hi >> 8; + mac[2] = hi >> 16; + mac[3] = hi >> 24; + mac[4] = lo; + mac[5] = lo >> 8; + + of_update_property(np, prop); + + pr_info("cpsw.%d: No hwaddr in dt. Using %pM from efuse\n", idx, mac); +} + +static int __init am33xx_dt_cpsw_mac_fixup(void) +{ + struct device_node *np, *slave; + int idx = 0; + + if (!soc_is_am33xx()) + return -ENODEV; + + for_each_compatible_node(np, NULL, "ti,cpsw") + for_each_node_by_name(slave, "slave") { + if (!of_get_mac_address(slave)) + am33xx_dt_cpsw_set_mac_from_efuse(slave, idx); + idx++; + } + + return 0; +} +arch_initcall(am33xx_dt_cpsw_mac_fixup); diff --git a/arch/arm/mach-omap2/control.h b/arch/arm/mach-omap2/control.h index e6c3281..266d512 100644 --- a/arch/arm/mach-omap2/control.h +++ b/arch/arm/mach-omap2/control.h @@ -352,6 +352,10 @@ /* AM33XX CONTROL_STATUS register */ #define AM33XX_CONTROL_STATUS 0x040 #define AM33XX_CONTROL_SEC_CLK_CTRL 0x1bc +#define AM33XX_CONTROL_MAC_ID0_LOW 0x630 +#define AM33XX_CONTROL_MAC_ID0_HIGH 0x634 +#define AM33XX_CONTROL_MAC_ID1_LOW 0x638 +#define AM33XX_CONTROL_MAC_ID1_HIGH 0x63c /* AM33XX CONTROL_STATUS bitfields (partial) */ #define AM33XX_CONTROL_STATUS_SYSBOOT1_SHIFT 22
When booting with CONFIG_ARM_APPENDED_DTB (either because of using an old U-Boot, not wanting the hassle of 2 files or when using Falcon fast boot mode in U-Boot), nothing updates the ethernet hwaddr specified for the CPSW slaves, causing the driver to use a random hwaddr, which is some times troublesome. The am33xx has unique ethernet hwaddrs programmed in the efuse, so it makes more sense to default to these rather than random ones. Add a fixup step which adds mac-address dt properties using the efuse addresses if the DTB didn't contain valid ones. Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk> --- arch/arm/mach-omap2/Makefile | 3 ++ arch/arm/mach-omap2/am33xx-cpsw.c | 94 +++++++++++++++++++++++++++++++++++++ arch/arm/mach-omap2/control.h | 4 ++ 3 files changed, 101 insertions(+) create mode 100644 arch/arm/mach-omap2/am33xx-cpsw.c