Commit e809285d4942cbd6c3efb381bd48dcf8294639a7

Authored by Bartosz Golaszewski
Committed by Joe Hershberger
1 parent 53fd12cfe1

net: davinci_emac: convert to using the driver model

Now that we removed all legacy boards selecting TI_EMAC we can
completely convert the driver code to using the driver model.
This patch also updates all remaining users of davinci_emac.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Tested-by: Adam Ford <aford173@gmail.com> #am3517-evm & da850-evm
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

Showing 15 changed files with 51 additions and 74 deletions Side-by-side Diff

arch/arm/mach-davinci/cpu.c
... ... @@ -5,7 +5,6 @@
5 5 */
6 6  
7 7 #include <common.h>
8   -#include <netdev.h>
9 8 #include <asm/arch/hardware.h>
10 9 #include <asm/io.h>
11 10  
... ... @@ -88,18 +87,6 @@
88 87 gd->bd->bi_ddr_freq = cpu_is_da830() ? 0 :
89 88 (clk_get(DAVINCI_DDR_CLKID) / 1000000);
90 89 gd->bd->bi_dsp_freq = 0;
91   - return 0;
92   -}
93   -
94   -/*
95   - * Initializes on-chip ethernet controllers.
96   - * to override, implement board_eth_init()
97   - */
98   -int cpu_eth_init(bd_t *bis)
99   -{
100   -#if defined(CONFIG_DRIVER_TI_EMAC)
101   - davinci_emac_initialize();
102   -#endif
103 90 return 0;
104 91 }
arch/arm/mach-omap2/omap3/emac.c
... ... @@ -7,7 +7,6 @@
7 7 */
8 8  
9 9 #include <common.h>
10   -#include <netdev.h>
11 10 #include <asm/io.h>
12 11 #include <asm/arch/am35x_def.h>
13 12  
... ... @@ -24,6 +23,6 @@
24 23 reset &= ~CPGMACSS_SW_RST;
25 24 writel(reset, &am35x_scm_general_regs->ip_sw_reset);
26 25  
27   - return davinci_emac_initialize();
  26 + return 0;
28 27 }
board/davinci/da8xxevm/da850evm.c
... ... @@ -13,7 +13,6 @@
13 13 #include <environment.h>
14 14 #include <i2c.h>
15 15 #include <net.h>
16   -#include <netdev.h>
17 16 #include <spi.h>
18 17 #include <spi_flash.h>
19 18 #include <asm/arch/hardware.h>
... ... @@ -482,11 +481,6 @@
482 481 if (rmii_hw_init())
483 482 printf("RMII hardware init failed!!!\n");
484 483 #endif
485   - if (!davinci_emac_initialize()) {
486   - printf("Error: Ethernet init failed!\n");
487   - return -1;
488   - }
489   -
490 484 return 0;
491 485 }
492 486 #endif /* CONFIG_DRIVER_TI_EMAC */
board/davinci/da8xxevm/omapl138_lcdk.c
... ... @@ -11,7 +11,6 @@
11 11 #include <common.h>
12 12 #include <i2c.h>
13 13 #include <net.h>
14   -#include <netdev.h>
15 14 #include <spi.h>
16 15 #include <spi_flash.h>
17 16 #include <asm/arch/hardware.h>
... ... @@ -228,19 +227,6 @@
228 227 }
229 228  
230 229 #ifdef CONFIG_DRIVER_TI_EMAC
231   -
232   -/*
233   - * Initializes on-board ethernet controllers.
234   - */
235   -int board_eth_init(bd_t *bis)
236   -{
237   - if (!davinci_emac_initialize()) {
238   - printf("Error: Ethernet init failed!\n");
239   - return -1;
240   - }
241   -
242   - return 0;
243   -}
244 230  
245 231 #endif /* CONFIG_DRIVER_TI_EMAC */
246 232  
board/logicpd/am3517evm/am3517evm.c
... ... @@ -28,7 +28,6 @@
28 28 #include <linux/usb/gadget.h>
29 29 #include <linux/usb/musb.h>
30 30 #include <i2c.h>
31   -#include <netdev.h>
32 31 #include "am3517evm.h"
33 32  
34 33 DECLARE_GLOBAL_DATA_PTR;
board/ti/ti816x/evm.c
... ... @@ -9,7 +9,6 @@
9 9 #include <common.h>
10 10 #include <environment.h>
11 11 #include <spl.h>
12   -#include <netdev.h>
13 12 #include <asm/cache.h>
14 13 #include <asm/io.h>
15 14 #include <asm/arch/clock.h>
... ... @@ -56,7 +55,7 @@
56 55 printf("Unable to read MAC address. Set <ethaddr>\n");
57 56 }
58 57  
59   - return davinci_emac_initialize();
  58 + return 0;
60 59 }
61 60  
62 61 #ifdef CONFIG_SPL_BUILD
configs/am3517_evm_defconfig
... ... @@ -44,6 +44,7 @@
44 44 CONFIG_SYS_NAND_U_BOOT_LOCATIONS=y
45 45 CONFIG_SYS_NAND_U_BOOT_OFFS=0x80000
46 46 CONFIG_SPL_NAND_SIMPLE=y
  47 +CONFIG_DM_ETH=y
47 48 CONFIG_MII=y
48 49 CONFIG_DRIVER_TI_EMAC=y
49 50 CONFIG_PINCTRL=y
configs/da850_am18xxevm_defconfig
... ... @@ -50,6 +50,7 @@
50 50 CONFIG_SPI_FLASH=y
51 51 CONFIG_SPI_FLASH_STMICRO=y
52 52 CONFIG_SPI_FLASH_WINBOND=y
  53 +CONFIG_DM_ETH=y
53 54 CONFIG_MII=y
54 55 CONFIG_DRIVER_TI_EMAC=y
55 56 CONFIG_DM_SERIAL=y
configs/da850evm_defconfig
... ... @@ -59,6 +59,7 @@
59 59 CONFIG_SPI_FLASH_STMICRO=y
60 60 CONFIG_SPI_FLASH_WINBOND=y
61 61 CONFIG_SPI_FLASH_MTD=y
  62 +CONFIG_DM_ETH=y
62 63 CONFIG_MII=y
63 64 CONFIG_DRIVER_TI_EMAC=y
64 65 CONFIG_PINCTRL=y
configs/da850evm_direct_nor_defconfig
... ... @@ -50,6 +50,7 @@
50 50 CONFIG_SPI_FLASH=y
51 51 CONFIG_SPI_FLASH_STMICRO=y
52 52 CONFIG_SPI_FLASH_WINBOND=y
  53 +CONFIG_DM_ETH=y
53 54 CONFIG_MII=y
54 55 CONFIG_DRIVER_TI_EMAC=y
55 56 CONFIG_PINCTRL=y
configs/da850evm_nand_defconfig
... ... @@ -59,6 +59,7 @@
59 59 CONFIG_SPI_FLASH_STMICRO=y
60 60 CONFIG_SPI_FLASH_WINBOND=y
61 61 CONFIG_SPI_FLASH_MTD=y
  62 +CONFIG_DM_ETH=y
62 63 CONFIG_PINCTRL=y
63 64 CONFIG_PINCTRL_SINGLE=y
64 65 CONFIG_DM_SERIAL=y
configs/omapl138_lcdk_defconfig
... ... @@ -49,6 +49,7 @@
49 49 CONFIG_SF_DEFAULT_SPEED=30000000
50 50 CONFIG_SPI_FLASH_STMICRO=y
51 51 CONFIG_SPI_FLASH_WINBOND=y
  52 +CONFIG_DM_ETH=y
52 53 CONFIG_MII=y
53 54 CONFIG_DRIVER_TI_EMAC=y
54 55 CONFIG_DM_SERIAL=y
configs/ti816x_evm_defconfig
... ... @@ -47,6 +47,7 @@
47 47 CONFIG_MMC_OMAP_HS=y
48 48 CONFIG_NAND=y
49 49 CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
  50 +CONFIG_DM_ETH=y
50 51 CONFIG_MII=y
51 52 CONFIG_DRIVER_TI_EMAC=y
52 53 CONFIG_SYS_NS16550=y
drivers/net/ti/davinci_emac.c
... ... @@ -26,7 +26,6 @@
26 26 #include <net.h>
27 27 #include <miiphy.h>
28 28 #include <malloc.h>
29   -#include <netdev.h>
30 29 #include <linux/compiler.h>
31 30 #include <asm/arch/emac_defs.h>
32 31 #include <asm/io.h>
33 32  
... ... @@ -107,8 +106,9 @@
107 106  
108 107 phy_t phy[CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT];
109 108  
110   -static int davinci_eth_set_mac_addr(struct eth_device *dev)
  109 +static int davinci_emac_write_hwaddr(struct udevice *dev)
111 110 {
  111 + struct eth_pdata *pdata = dev_get_platdata(dev);
112 112 unsigned long mac_hi;
113 113 unsigned long mac_lo;
114 114  
... ... @@ -118,12 +118,12 @@
118 118 * Using channel 0 only - other channels are disabled
119 119 * */
120 120 writel(0, &adap_emac->MACINDEX);
121   - mac_hi = (dev->enetaddr[3] << 24) |
122   - (dev->enetaddr[2] << 16) |
123   - (dev->enetaddr[1] << 8) |
124   - (dev->enetaddr[0]);
125   - mac_lo = (dev->enetaddr[5] << 8) |
126   - (dev->enetaddr[4]);
  121 + mac_hi = (pdata->enetaddr[3] << 24) |
  122 + (pdata->enetaddr[2] << 16) |
  123 + (pdata->enetaddr[1] << 8) |
  124 + (pdata->enetaddr[0]);
  125 + mac_lo = (pdata->enetaddr[5] << 8) |
  126 + (pdata->enetaddr[4]);
127 127  
128 128 writel(mac_hi, &adap_emac->MACADDRHI);
129 129 #if defined(DAVINCI_EMAC_VERSION2)
... ... @@ -411,7 +411,7 @@
411 411 }
412 412  
413 413 /* Eth device open */
414   -static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
  414 +static int davinci_emac_start(struct udevice *dev)
415 415 {
416 416 dv_reg_p addr;
417 417 u_int32_t clkdiv, cnt, mac_control;
... ... @@ -447,7 +447,7 @@
447 447 writel(1, &adap_emac->TXCONTROL);
448 448 writel(1, &adap_emac->RXCONTROL);
449 449  
450   - davinci_eth_set_mac_addr(dev);
  450 + davinci_emac_write_hwaddr(dev);
451 451  
452 452 /* Set DMA 8 TX / 8 RX Head pointers to 0 */
453 453 addr = &adap_emac->TX0HDP;
... ... @@ -588,7 +588,7 @@
588 588 }
589 589  
590 590 /* Eth device close */
591   -static void davinci_eth_close(struct eth_device *dev)
  591 +static void davinci_emac_stop(struct udevice *dev)
592 592 {
593 593 debug_emac("+ emac_close\n");
594 594  
... ... @@ -619,8 +619,8 @@
619 619 * This function sends a single packet on the network and returns
620 620 * positive number (number of bytes transmitted) or negative for error
621 621 */
622   -static int davinci_eth_send_packet (struct eth_device *dev,
623   - void *packet, int length)
  622 +static int davinci_emac_send(struct udevice *dev,
  623 + void *packet, int length)
624 624 {
625 625 int ret_status = -1;
626 626 int index;
... ... @@ -672,7 +672,7 @@
672 672 /*
673 673 * This function handles receipt of a packet from the network
674 674 */
675   -static int davinci_eth_rcv_packet (struct eth_device *dev)
  675 +static int davinci_emac_recv(struct udevice *dev, int flags, uchar **packetp)
676 676 {
677 677 volatile emac_desc *rx_curr_desc;
678 678 volatile emac_desc *curr_desc;
... ... @@ -682,6 +682,7 @@
682 682 rx_curr_desc = emac_rx_active_head;
683 683 if (!rx_curr_desc)
684 684 return 0;
  685 + *packetp = rx_curr_desc->buffer;
685 686 status = rx_curr_desc->pkt_flag_len;
686 687 if ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0) {
687 688 if (status & EMAC_CPPI_RX_ERROR_FRAME) {
... ... @@ -693,7 +694,6 @@
693 694 rx_curr_desc->buff_off_len & 0xffff;
694 695  
695 696 invalidate_dcache_range(tmp, tmp + ALIGN(len, PKTALIGN));
696   - net_process_received_packet(rx_curr_desc->buffer, len);
697 697 ret = len;
698 698 }
699 699  
... ... @@ -742,6 +742,7 @@
742 742 }
743 743 return (ret);
744 744 }
  745 +
745 746 return (0);
746 747 }
747 748  
748 749  
749 750  
... ... @@ -750,31 +751,13 @@
750 751 * EMAC modules power or pin multiplexors, that is done by board_init()
751 752 * much earlier in bootup process. Returns 1 on success, 0 otherwise.
752 753 */
753   -int davinci_emac_initialize(void)
  754 +static int davinci_emac_probe(struct udevice *dev)
754 755 {
755 756 u_int32_t phy_id;
756 757 u_int16_t tmp;
757 758 int i;
758 759 int ret;
759   - struct eth_device *dev;
760 760  
761   - dev = malloc(sizeof *dev);
762   -
763   - if (dev == NULL)
764   - return -1;
765   -
766   - memset(dev, 0, sizeof *dev);
767   - strcpy(dev->name, "DaVinci-EMAC");
768   -
769   - dev->iobase = 0;
770   - dev->init = davinci_eth_open;
771   - dev->halt = davinci_eth_close;
772   - dev->send = davinci_eth_send_packet;
773   - dev->recv = davinci_eth_rcv_packet;
774   - dev->write_hwaddr = davinci_eth_set_mac_addr;
775   -
776   - eth_register(dev);
777   -
778 761 davinci_eth_mdio_enable();
779 762  
780 763 /* let the EMAC detect the PHYs */
781 764  
... ... @@ -854,6 +837,30 @@
854 837 phy[i].auto_negotiate(i);
855 838 }
856 839 #endif
857   - return(1);
  840 + return 0;
858 841 }
  842 +
  843 +static const struct eth_ops davinci_emac_ops = {
  844 + .start = davinci_emac_start,
  845 + .send = davinci_emac_send,
  846 + .recv = davinci_emac_recv,
  847 + .stop = davinci_emac_stop,
  848 + .write_hwaddr = davinci_emac_write_hwaddr,
  849 +};
  850 +
  851 +static const struct udevice_id davinci_emac_ids[] = {
  852 + { .compatible = "ti,davinci-dm6467-emac" },
  853 + { .compatible = "ti,am3517-emac", },
  854 + { .compatible = "ti,dm816-emac", },
  855 + { }
  856 +};
  857 +
  858 +U_BOOT_DRIVER(davinci_emac) = {
  859 + .name = "davinci_emac",
  860 + .id = UCLASS_ETH,
  861 + .of_match = davinci_emac_ids,
  862 + .probe = davinci_emac_probe,
  863 + .ops = &davinci_emac_ops,
  864 + .platdata_auto_alloc_size = sizeof(struct eth_pdata),
  865 +};
... ... @@ -30,7 +30,6 @@
30 30 int bfin_EMAC_initialize(bd_t *bis);
31 31 int calxedaxgmac_initialize(u32 id, ulong base_addr);
32 32 int cs8900_initialize(u8 dev_num, int base_addr);
33   -int davinci_emac_initialize(void);
34 33 int dc21x4x_initialize(bd_t *bis);
35 34 int designware_initialize(ulong base_addr, u32 interface);
36 35 int dm9000_initialize(bd_t *bis);