[email protected] writes:
> From: Chaithrika U S <[email protected]>
>
> EMAC platform device definitions have been moved to the respective SoC
> specific
> files, also the resource structures have been simplified to represent a single
> contiguous memory region.
>
> Platform data has been suitably modified to add module offsets. PHY
> address mask and maximum MDIO clock value has also been included in the
> platform data structure.
>
> Signed-off-by: Chaithrika U S <[email protected]>
> ---
> arch/arm/mach-davinci/board-dm644x-evm.c | 10 ++
> arch/arm/mach-davinci/board-dm646x-evm.c | 10 ++
> arch/arm/mach-davinci/board-sffsdr.c | 12 +++
> arch/arm/mach-davinci/devices.c | 127
> ++++-----------------------
> arch/arm/mach-davinci/dm644x.c | 49 ++++++++++
> arch/arm/mach-davinci/dm646x.c | 63 +++++++++++++
> arch/arm/mach-davinci/include/mach/dm644x.h | 2 +
> arch/arm/mach-davinci/include/mach/dm646x.h | 2 +
> arch/arm/mach-davinci/include/mach/emac.h | 7 ++
> 9 files changed, 171 insertions(+), 111 deletions(-)
>
> diff --git a/arch/arm/mach-davinci/board-dm644x-evm.c
> b/arch/arm/mach-davinci/board-dm644x-evm.c
> index 20ec961..789f178 100644
> --- a/arch/arm/mach-davinci/board-dm644x-evm.c
> +++ b/arch/arm/mach-davinci/board-dm644x-evm.c
> @@ -45,6 +45,9 @@
> #include <mach/nand.h>
> #include <mach/mmc.h>
>
> +#define DAVINCI_EVM_PHY_MASK 0x2
> +#define EMAC_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency
> */
> +
> #define DAVINCI_CFC_ATA_BASE 0x01C66000
>
> #define DAVINCI_ASYNC_EMIF_CONTROL_BASE 0x01e00000
> @@ -410,6 +413,8 @@ static int at24_setup(struct at24_iface *iface, void
> *context)
> {
> DECLARE_MAC_BUF(mac_str);
> char mac_addr[6];
> + struct platform_device *pdev;
> + struct emac_platform_data *pdata;
>
> at24_if = iface;
>
> @@ -418,6 +423,11 @@ static int at24_setup(struct at24_iface *iface, void
> *context)
> printk(KERN_INFO "Read MAC addr from EEPROM: %s\n",
> print_mac(mac_str, mac_addr));
>
> + pdev = dm644x_get_emac_pdev();
> + pdata = pdev->dev.platform_data;
> + pdata->phy_mask = DAVINCI_EVM_PHY_MASK;
> + pdata->mdio_max_freq = EMAC_EVM_MDIO_FREQUENCY;
> +
> davinci_init_emac(mac_addr);
> }
at24_setup() is not the right place for this. For example, if no
EEPROM is detected then these values will not be setup correctly.
These should be set separately from the EEPROM setup.
I think that a reasonable default should be set in the dm<soc>.c file
and then a way for the board code to override the defaults. I'm not
crazy about the dm<soc>_get_emac_pdev().
I think I would rather see davinci_init_emac() expanded to take some
sort of 'emac_init' struct which contains the MAC, and these new
parameters. If the values are non-zero (or not -1) then
davinci_init_emac() updates the pdata before the
platform_device_register().
> diff --git a/arch/arm/mach-davinci/board-dm646x-evm.c
> b/arch/arm/mach-davinci/board-dm646x-evm.c
> index 907f424..b4e884a 100644
> --- a/arch/arm/mach-davinci/board-dm646x-evm.c
> +++ b/arch/arm/mach-davinci/board-dm646x-evm.c
> @@ -46,6 +46,9 @@
> #include <linux/etherdevice.h>
> #include <mach/emac.h>
>
> +#define DAVINCI_EVM_PHY_MASK 0x2
> +#define EMAC_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency
> */
> +
> static struct davinci_uart_config uart_config __initdata = {
> .enabled_uarts = (1 << 0),
> };
> @@ -60,6 +63,8 @@ static int at24_setup(struct at24_iface *iface, void
> *context)
> {
> DECLARE_MAC_BUF(mac_str);
> char mac_addr[6];
> + struct platform_device *pdev;
> + struct emac_platform_data *pdata;
>
> at24_if = iface;
>
> @@ -68,6 +73,11 @@ static int at24_setup(struct at24_iface *iface, void
> *context)
> printk(KERN_INFO "Read MAC addr from EEPROM: %s\n",
> print_mac(mac_str, mac_addr));
>
> + pdev = dm646x_get_emac_pdev();
> + pdata = pdev->dev.platform_data;
> + pdata->phy_mask = DAVINCI_EVM_PHY_MASK;
> + pdata->mdio_max_freq = EMAC_EVM_MDIO_FREQUENCY;
> +
> davinci_init_emac(mac_addr);
> }
> return 0;
> diff --git a/arch/arm/mach-davinci/board-sffsdr.c
> b/arch/arm/mach-davinci/board-sffsdr.c
> index 0d83cb0..8e64d48 100644
> --- a/arch/arm/mach-davinci/board-sffsdr.c
> +++ b/arch/arm/mach-davinci/board-sffsdr.c
> @@ -54,6 +54,9 @@
> #include <mach/psc.h>
> #include <mach/mux.h>
>
> +#define DAVINCI_EVM_PHY_MASK 0x2
> +#define EMAC_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency
> */
> +
> #define DAVINCI_ASYNC_EMIF_CONTROL_BASE 0x01e00000
> #define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE 0x02000000
>
> @@ -153,10 +156,19 @@ static void __init davinci_sffsdr_map_io(void)
>
> static __init void davinci_sffsdr_init(void)
> {
> + struct platform_device *pdev;
> + struct emac_platform_data *pdata;
> +
> platform_add_devices(davinci_sffsdr_devices,
> ARRAY_SIZE(davinci_sffsdr_devices));
> sffsdr_init_i2c();
> davinci_serial_init(&uart_config);
> +
> + pdev = dm644x_get_emac_pdev();
> + pdata = pdev->dev.platform_data;
> + pdata->phy_mask = DAVINCI_EVM_PHY_MASK;
> + pdata->mdio_max_freq = EMAC_EVM_MDIO_FREQUENCY;
> +
> davinci_init_emac(davinci_sffsdr_mac_addr);
> setup_usb(0, 0); /* We support only peripheral mode. */
>
> diff --git a/arch/arm/mach-davinci/devices.c b/arch/arm/mach-davinci/devices.c
> index a0f5a60..22c2deb 100644
> --- a/arch/arm/mach-davinci/devices.c
> +++ b/arch/arm/mach-davinci/devices.c
> @@ -29,6 +29,7 @@
> #include <mach/cpu.h>
> #include <mach/mux.h>
> #include <mach/mmc.h>
> +#include <mach/dm646x.h>
>
> #include "clock.h"
>
> @@ -252,131 +253,35 @@ static void davinci_init_wdt(void)
>
> #if defined(CONFIG_TI_DAVINCI_EMAC) || defined(CONFIG_TI_DAVINCI_EMAC_MODULE)
>
> -static struct resource emac_resources[] = {
> - {
> - .start = DAVINCI_EMAC_CNTRL_REGS_BASE,
> - .end = DAVINCI_EMAC_CNTRL_REGS_BASE + 0x0fff,
> - .flags = IORESOURCE_MEM,
> - .name = "ctrl_regs"
> - },
> - {
> - .start = DAVINCI_EMAC_CNTRL_MOD_REGS_BASE,
> - .end = DAVINCI_EMAC_CNTRL_MOD_REGS_BASE + 0x0fff,
> - .flags = IORESOURCE_MEM,
> - .name = "ctrl_module_regs"
> - },
> - {
> - .start = DAVINCI_EMAC_CNTRL_RAM_BASE,
> - .end = DAVINCI_EMAC_CNTRL_RAM_BASE + 0x1fff,
> - .flags = IORESOURCE_MEM,
> - .name = "ctrl_ram"
> - },
> - {
> - .start = DAVINCI_EMAC_MDIO_REGS_BASE,
> - .end = DAVINCI_EMAC_MDIO_REGS_BASE + 0x07ff,
> - .flags = IORESOURCE_MEM,
> - .name = "mdio_regs"
> - },
> - {
> - .start = IRQ_EMACINT,
> - .end = IRQ_EMACINT,
> - .flags = IORESOURCE_IRQ,
> - },
> -};
> -
> -static struct emac_platform_data emac_pdata;
> -
> -static struct platform_device davinci_emac_device = {
> - .name = "davinci_emac",
> - .id = 1,
> - .num_resources = ARRAY_SIZE(emac_resources),
> - .resource = emac_resources,
> - .dev = {
> - .platform_data = &emac_pdata,
> - }
> -};
> -
> -static struct resource dm646x_emac_resources[] = {
> - {
> - .start = DAVINCI_EMAC_CNTRL_REGS_BASE,
> - .end = DAVINCI_EMAC_CNTRL_REGS_BASE + 0x0fff,
> - .flags = IORESOURCE_MEM,
> - .name = "ctrl_regs"
> - },
> - {
> - .start = DAVINCI_EMAC_CNTRL_MOD_REGS_BASE,
> - .end = DAVINCI_EMAC_CNTRL_MOD_REGS_BASE + 0x0fff,
> - .flags = IORESOURCE_MEM,
> - .name = "ctrl_module_regs"
> - },
> - {
> - .start = DAVINCI_EMAC_CNTRL_RAM_BASE,
> - .end = DAVINCI_EMAC_CNTRL_RAM_BASE + 0x1fff,
> - .flags = IORESOURCE_MEM,
> - .name = "ctrl_ram"
> - },
> - {
> - .start = DAVINCI_EMAC_MDIO_REGS_BASE,
> - .end = DAVINCI_EMAC_MDIO_REGS_BASE + 0x07ff,
> - .flags = IORESOURCE_MEM,
> - .name = "mdio_regs"
> - },
> - {
> - .start = IRQ_DM646X_EMACRXTHINT,
> - .end = IRQ_DM646X_EMACRXTHINT,
> - .flags = IORESOURCE_IRQ,
> - },
> - {
> - .start = IRQ_DM646X_EMACRXINT,
> - .end = IRQ_DM646X_EMACRXINT,
> - .flags = IORESOURCE_IRQ,
> - },
> - {
> - .start = IRQ_DM646X_EMACTXINT,
> - .end = IRQ_DM646X_EMACTXINT,
> - .flags = IORESOURCE_IRQ,
> - },
> - {
> - .start = IRQ_DM646X_EMACMISCINT,
> - .end = IRQ_DM646X_EMACMISCINT,
> - .flags = IORESOURCE_IRQ,
> - },
> -};
> -
> -static struct platform_device dm646x_emac_device = {
> - .name = "davinci_emac",
> - .id = 1,
> - .num_resources = ARRAY_SIZE(dm646x_emac_resources),
> - .resource = dm646x_emac_resources,
> - .dev = {
> - .platform_data = &emac_pdata,
> - }
> -};
> -
> void davinci_init_emac(char *mac_addr)
> {
> + struct platform_device *pdev;
> + struct emac_platform_data *pdata;
> +
> DECLARE_MAC_BUF(buf);
>
> - if (!(cpu_is_davinci_dm644x() || cpu_is_davinci_dm646x()))
> - return;
> + if (cpu_is_davinci_dm644x())
> + pdev = dm644x_get_emac_pdev();
> + else if (cpu_is_davinci_dm646x())
> + pdev = dm646x_get_emac_pdev();
> +
> + pdata = pdev->dev.platform_data;
>
> /* if valid MAC exists, don't re-register */
> - if (is_valid_ether_addr(emac_pdata.mac_addr))
> + if (is_valid_ether_addr(pdata->mac_addr))
> return;
>
> if (mac_addr && is_valid_ether_addr(mac_addr))
> - memcpy(emac_pdata.mac_addr, mac_addr, 6);
> + memcpy(pdata->mac_addr, mac_addr, 6);
> else {
> /* Use random MAC if none passed */
> - random_ether_addr(emac_pdata.mac_addr);
> + random_ether_addr(pdata->mac_addr);
>
> printk(KERN_WARNING "%s: using random MAC addr: %s\n",
> - __func__, print_mac(buf, emac_pdata.mac_addr));
> + __func__, print_mac(buf, pdata->mac_addr));
> }
> - if ((cpu_is_davinci_dm644x()))
> - (void) platform_device_register(&davinci_emac_device);
> - else
> - (void) platform_device_register(&dm646x_emac_device);
> +
> + (void) platform_device_register(pdev);
> }
>
> #else
> diff --git a/arch/arm/mach-davinci/dm644x.c b/arch/arm/mach-davinci/dm644x.c
> index 7251b82..cec9584 100644
> --- a/arch/arm/mach-davinci/dm644x.c
> +++ b/arch/arm/mach-davinci/dm644x.c
> @@ -11,11 +11,14 @@
> #include <linux/kernel.h>
> #include <linux/init.h>
> #include <linux/clk.h>
> +#include <linux/platform_device.h>
>
> #include <mach/dm644x.h>
> #include <mach/clock.h>
> #include <mach/psc.h>
> #include <mach/mux.h>
> +#include <mach/irqs.h>
> +#include <mach/emac.h>
>
> #include "clock.h"
> #include "mux.h"
> @@ -24,6 +27,12 @@
> * Device specific clocks
> */
> #define DM644X_REF_FREQ 27000000
> +#define DAVINCI_EMAC_BASE 0x01C80000
> +#define DAVINCI_EMAC_CNTRL_OFFSET 0x0000
> +#define DAVINCI_EMAC_CNTRL_MOD_OFFSET 0x1000
> +#define DAVINCI_EMAC_CNTRL_RAM_OFFSET 0x2000
> +#define DAVINCI_EMAC_MDIO_OFFSET 0x4000
> +#define DAVINCI_EMAC_CNTRL_RAM_SIZE 0x2000
Let's move these to dm644x.h
> static struct pll_data pll1_data = {
> .num = 1,
> @@ -306,6 +315,46 @@ static struct clk *dm644x_clks[] __initdata = {
> NULL,
> };
>
> +#if defined(CONFIG_TI_DAVINCI_EMAC) || defined(CONFIG_TI_DAVINCI_EMAC_MODULE)
> +
> +static struct resource dm644x_emac_resources[] = {
> + {
> + .start = DAVINCI_EMAC_BASE,
> + .end = DAVINCI_EMAC_BASE + 0x47ff,
> + .flags = IORESOURCE_MEM,
> + },
> + {
> + .start = IRQ_EMACINT,
> + .end = IRQ_EMACINT,
> + .flags = IORESOURCE_IRQ,
> + },
> +};
> +
> +static struct emac_platform_data dm644x_emac_pdata = {
> + .ctrl_reg_offset = DAVINCI_EMAC_CNTRL_OFFSET,
> + .ctrl_mod_reg_offset = DAVINCI_EMAC_CNTRL_MOD_OFFSET,
> + .ctrl_ram_offset = DAVINCI_EMAC_CNTRL_RAM_OFFSET,
> + .mdio_reg_offset = DAVINCI_EMAC_MDIO_OFFSET,
> + .ctrl_ram_size = DAVINCI_EMAC_CNTRL_RAM_SIZE,
> +};
> +
> +static struct platform_device dm644x_emac_device = {
> + .name = "davinci_emac",
> + .id = 1,
> + .num_resources = ARRAY_SIZE(dm644x_emac_resources),
> + .resource = dm644x_emac_resources,
> + .dev = {
> + .platform_data = &dm644x_emac_pdata,
> + }
> +};
> +
> +struct platform_device *dm644x_get_emac_pdev(void)
> +{
> + return &dm644x_emac_device;
> +}
> +
> +#endif
> +
> /*
> * Device specific mux setup
> *
> diff --git a/arch/arm/mach-davinci/dm646x.c b/arch/arm/mach-davinci/dm646x.c
> index 6b13bcc..903a254 100644
> --- a/arch/arm/mach-davinci/dm646x.c
> +++ b/arch/arm/mach-davinci/dm646x.c
> @@ -11,11 +11,14 @@
> #include <linux/kernel.h>
> #include <linux/init.h>
> #include <linux/clk.h>
> +#include <linux/platform_device.h>
>
> #include <mach/dm644x.h>
> #include <mach/clock.h>
> #include <mach/psc.h>
> #include <mach/mux.h>
> +#include <mach/irqs.h>
> +#include <mach/emac.h>
>
> #include "clock.h"
> #include "mux.h"
> @@ -25,6 +28,12 @@
> */
> #define DM646X_REF_FREQ 27000000
> #define DM646X_AUX_FREQ 24000000
> +#define DAVINCI_EMAC_BASE 0x01C80000
> +#define DAVINCI_EMAC_CNTRL_OFFSET 0x0000
> +#define DAVINCI_EMAC_CNTRL_MOD_OFFSET 0x1000
> +#define DAVINCI_EMAC_CNTRL_RAM_OFFSET 0x2000
> +#define DAVINCI_EMAC_MDIO_OFFSET 0x4000
> +#define DAVINCI_EMAC_CNTRL_RAM_SIZE 0x2000
... and these to dm646x.h
> static struct pll_data pll1_data = {
> .num = 1,
> @@ -252,6 +261,60 @@ static struct clk *dm646x_clks[] __initdata = {
> NULL,
> };
>
> +#if defined(CONFIG_TI_DAVINCI_EMAC) || defined(CONFIG_TI_DAVINCI_EMAC_MODULE)
> +static struct resource dm646x_emac_resources[] = {
> + {
> + .start = DAVINCI_EMAC_BASE,
> + .end = DAVINCI_EMAC_BASE + 0x47ff,
> + .flags = IORESOURCE_MEM,
> + },
> + {
> + .start = IRQ_DM646X_EMACRXTHINT,
> + .end = IRQ_DM646X_EMACRXTHINT,
> + .flags = IORESOURCE_IRQ,
> + },
> + {
> + .start = IRQ_DM646X_EMACRXINT,
> + .end = IRQ_DM646X_EMACRXINT,
> + .flags = IORESOURCE_IRQ,
> + },
> + {
> + .start = IRQ_DM646X_EMACTXINT,
> + .end = IRQ_DM646X_EMACTXINT,
> + .flags = IORESOURCE_IRQ,
> + },
> + {
> + .start = IRQ_DM646X_EMACMISCINT,
> + .end = IRQ_DM646X_EMACMISCINT,
> + .flags = IORESOURCE_IRQ,
> + },
> +};
> +
> +static struct emac_platform_data dm646x_emac_pdata = {
> + .ctrl_reg_offset = DAVINCI_EMAC_CNTRL_OFFSET,
> + .ctrl_mod_reg_offset = DAVINCI_EMAC_CNTRL_MOD_OFFSET,
> + .ctrl_ram_offset = DAVINCI_EMAC_CNTRL_RAM_OFFSET,
> + .mdio_reg_offset = DAVINCI_EMAC_MDIO_OFFSET,
> + .ctrl_ram_size = DAVINCI_EMAC_CNTRL_RAM_SIZE,
> +};
> +
> +static struct platform_device dm646x_emac_device = {
> + .name = "davinci_emac",
> + .id = 1,
> + .num_resources = ARRAY_SIZE(dm646x_emac_resources),
> + .resource = dm646x_emac_resources,
> + .dev = {
> + .platform_data = &dm646x_emac_pdata,
> + }
> +};
> +
> +struct platform_device *dm646x_get_emac_pdev(void)
> +{
> + return &dm646x_emac_device;
> +}
> +
> +#endif
> +
> /*
> * Device specific mux setup
> *
> diff --git a/arch/arm/mach-davinci/include/mach/dm644x.h
> b/arch/arm/mach-davinci/include/mach/dm644x.h
> index 5b3d512..0d91114 100644
> --- a/arch/arm/mach-davinci/include/mach/dm644x.h
> +++ b/arch/arm/mach-davinci/include/mach/dm644x.h
> @@ -22,8 +22,10 @@
> #ifndef __ASM_ARCH_DM644X_H
> #define __ASM_ARCH_DM644X_H
>
> +#include <linux/platform_device.h>
> #include <mach/hardware.h>
>
> void __init dm644x_init(void);
> +struct platform_device *dm644x_get_emac_pdev(void);
>
> #endif /* __ASM_ARCH_DM644X_H */
> diff --git a/arch/arm/mach-davinci/include/mach/dm646x.h
> b/arch/arm/mach-davinci/include/mach/dm646x.h
> index d917939..c1cb916 100644
> --- a/arch/arm/mach-davinci/include/mach/dm646x.h
> +++ b/arch/arm/mach-davinci/include/mach/dm646x.h
> @@ -11,8 +11,10 @@
> #ifndef __ASM_ARCH_DM646X_H
> #define __ASM_ARCH_DM646X_H
>
> +#include <linux/platform_device.h>
> #include <mach/hardware.h>
>
> void __init dm646x_init(void);
> +struct platform_device *dm646x_get_emac_pdev(void);
>
> #endif /* __ASM_ARCH_DM646X_H */
> diff --git a/arch/arm/mach-davinci/include/mach/emac.h
> b/arch/arm/mach-davinci/include/mach/emac.h
> index 226d2f8..eb1a719 100644
> --- a/arch/arm/mach-davinci/include/mach/emac.h
> +++ b/arch/arm/mach-davinci/include/mach/emac.h
> @@ -13,6 +13,13 @@
>
> struct emac_platform_data {
> char mac_addr[6];
> + u32 ctrl_reg_offset;
> + u32 ctrl_mod_reg_offset;
> + u32 ctrl_ram_offset;
> + u32 mdio_reg_offset;
> + u32 ctrl_ram_size;
> + u32 phy_mask;
> + u32 mdio_max_freq;
> };
>
> void davinci_init_emac(char *mac_addr);
> --
> 1.5.6
>
> _______________________________________________
> Davinci-linux-open-source mailing list
> [email protected]
> http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source