Coding Style cleanup: remove trailing white space
[platform/kernel/u-boot.git] / drivers / net / dc2114x.c
index d5275dc..799839c 100644 (file)
@@ -1,30 +1,11 @@
 /*
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * 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; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
-
-#if defined(CONFIG_CMD_NET) \
-       && defined(CONFIG_NET_MULTI) && defined(CONFIG_TULIP)
-
 #include <malloc.h>
 #include <net.h>
+#include <netdev.h>
 #include <pci.h>
 
 #undef DEBUG_SROM
@@ -178,7 +159,7 @@ static void  read_hw_addr(struct eth_device* dev, bd_t * bis);
 static void  send_setup_frame(struct eth_device* dev, bd_t * bis);
 
 static int   dc21x4x_init(struct eth_device* dev, bd_t* bis);
-static int   dc21x4x_send(struct eth_device* dev, volatile void *packet, int length);
+static int   dc21x4x_send(struct eth_device *dev, void *packet, int length);
 static int   dc21x4x_recv(struct eth_device* dev);
 static void  dc21x4x_halt(struct eth_device* dev);
 #ifdef CONFIG_TULIP_SELECT_MEDIA
@@ -212,14 +193,14 @@ static struct pci_device_id supported[] = {
 
 int dc21x4x_initialize(bd_t *bis)
 {
-       int                     idx=0;
-       int                     card_number = 0;
-       unsigned int            cfrv;
-       unsigned char           timer;
+       int                     idx=0;
+       int                     card_number = 0;
+       unsigned int            cfrv;
+       unsigned char           timer;
        pci_dev_t               devbusfn;
        unsigned int            iobase;
        unsigned short          status;
-       struct eth_device*      dev;
+       struct eth_device*      dev;
 
        while(1) {
                devbusfn =  pci_find_devices(supported, idx++);
@@ -248,15 +229,17 @@ int dc21x4x_initialize(bd_t *bis)
                pci_write_config_word(devbusfn, PCI_COMMAND, status);
 
                pci_read_config_word(devbusfn, PCI_COMMAND, &status);
+#ifdef CONFIG_TULIP_USE_IO
                if (!(status & PCI_COMMAND_IO)) {
                        printf("Error: Can not enable I/O access.\n");
                        continue;
                }
-
-               if (!(status & PCI_COMMAND_IO)) {
-                       printf("Error: Can not enable I/O access.\n");
+#else
+               if (!(status & PCI_COMMAND_MEMORY)) {
+                       printf("Error: Can not enable MEMORY access.\n");
                        continue;
                }
+#endif
 
                if (!(status & PCI_COMMAND_MASTER)) {
                        printf("Error: Can not enable Bus Mastering.\n");
@@ -283,6 +266,12 @@ int dc21x4x_initialize(bd_t *bis)
 
                dev = (struct eth_device*) malloc(sizeof *dev);
 
+               if (!dev) {
+                       printf("Can not allocalte memory of dc21x4x\n");
+                       break;
+               }
+               memset(dev, 0, sizeof(*dev));
+
 #ifdef CONFIG_TULIP_FIX_DAVICOM
                sprintf(dev->name, "Davicom#%d", card_number);
 #else
@@ -332,7 +321,7 @@ static int dc21x4x_init(struct eth_device* dev, bd_t* bis)
 
        if ((INL(dev, DE4X5_STS) & (STS_TS | STS_RS)) != 0) {
                printf("Error: Cannot reset ethernet controller.\n");
-               return 0;
+               return -1;
        }
 
 #ifdef CONFIG_TULIP_SELECT_MEDIA
@@ -382,10 +371,10 @@ static int dc21x4x_init(struct eth_device* dev, bd_t* bis)
 
        send_setup_frame(dev, bis);
 
-       return 1;
+       return 0;
 }
 
-static int dc21x4x_send(struct eth_device* dev, volatile void *packet, int length)
+static int dc21x4x_send(struct eth_device *dev, void *packet, int length)
 {
        int             status = -1;
        int             i;
@@ -490,7 +479,7 @@ static void send_setup_frame(struct eth_device* dev, bd_t *bis)
 {
        int             i;
        char    setup_frame[SETUP_FRAME_LEN];
-       char    *pa = &setup_frame[0];
+       char    *pa = &setup_frame[0];
 
        memset(pa, 0xff, SETUP_FRAME_LEN);
 
@@ -738,34 +727,34 @@ static void update_srom(struct eth_device *dev, bd_t *bis)
 {
        int i;
        static unsigned short eeprom[0x40] = {
-               0x140b, 0x6610, 0x0000, 0x0000,         /* 00 */
-               0x0000, 0x0000, 0x0000, 0x0000,         /* 04 */
-               0x00a3, 0x0103, 0x0000, 0x0000,         /* 08 */
-               0x0000, 0x1f00, 0x0000, 0x0000,         /* 0c */
-               0x0108, 0x038d, 0x0000, 0x0000,         /* 10 */
-               0xe078, 0x0001, 0x0040, 0x0018,         /* 14 */
-               0x0000, 0x0000, 0x0000, 0x0000,         /* 18 */
-               0x0000, 0x0000, 0x0000, 0x0000,         /* 1c */
-               0x0000, 0x0000, 0x0000, 0x0000,         /* 20 */
-               0x0000, 0x0000, 0x0000, 0x0000,         /* 24 */
-               0x0000, 0x0000, 0x0000, 0x0000,         /* 28 */
-               0x0000, 0x0000, 0x0000, 0x0000,         /* 2c */
-               0x0000, 0x0000, 0x0000, 0x0000,         /* 30 */
-               0x0000, 0x0000, 0x0000, 0x0000,         /* 34 */
-               0x0000, 0x0000, 0x0000, 0x0000,         /* 38 */
-               0x0000, 0x0000, 0x0000, 0x4e07,         /* 3c */
+               0x140b, 0x6610, 0x0000, 0x0000, /* 00 */
+               0x0000, 0x0000, 0x0000, 0x0000, /* 04 */
+               0x00a3, 0x0103, 0x0000, 0x0000, /* 08 */
+               0x0000, 0x1f00, 0x0000, 0x0000, /* 0c */
+               0x0108, 0x038d, 0x0000, 0x0000, /* 10 */
+               0xe078, 0x0001, 0x0040, 0x0018, /* 14 */
+               0x0000, 0x0000, 0x0000, 0x0000, /* 18 */
+               0x0000, 0x0000, 0x0000, 0x0000, /* 1c */
+               0x0000, 0x0000, 0x0000, 0x0000, /* 20 */
+               0x0000, 0x0000, 0x0000, 0x0000, /* 24 */
+               0x0000, 0x0000, 0x0000, 0x0000, /* 28 */
+               0x0000, 0x0000, 0x0000, 0x0000, /* 2c */
+               0x0000, 0x0000, 0x0000, 0x0000, /* 30 */
+               0x0000, 0x0000, 0x0000, 0x0000, /* 34 */
+               0x0000, 0x0000, 0x0000, 0x0000, /* 38 */
+               0x0000, 0x0000, 0x0000, 0x4e07, /* 3c */
        };
+       uchar enetaddr[6];
 
        /* Ethernet Addr... */
-       eeprom[0x0a] = ((bis->bi_enetaddr[1] & 0xff) << 8) | (bis->bi_enetaddr[0] & 0xff);
-       eeprom[0x0b] = ((bis->bi_enetaddr[3] & 0xff) << 8) | (bis->bi_enetaddr[2] & 0xff);
-       eeprom[0x0c] = ((bis->bi_enetaddr[5] & 0xff) << 8) | (bis->bi_enetaddr[4] & 0xff);
+       if (!eth_getenv_enetaddr("ethaddr", enetaddr))
+               return;
+       eeprom[0x0a] = (enetaddr[1] << 8) | enetaddr[0];
+       eeprom[0x0b] = (enetaddr[3] << 8) | enetaddr[2];
+       eeprom[0x0c] = (enetaddr[5] << 8) | enetaddr[4];
 
-       for (i=0; i<0x40; i++)
-       {
+       for (i=0; i<0x40; i++) {
                write_srom(dev, DE4X5_APROM, i, eeprom[i]);
        }
 }
 #endif /* UPDATE_SROM */
-
-#endif