#define BIT_EMAC_SPEED (1 << 1)
static int rk29_vmac_speed_switch(int speed)
{
- printk("%s--speed=%d\n", __FUNCTION__, speed);
+ //printk("%s--speed=%d\n", __FUNCTION__, speed);
if (10 == speed) {
writel_relaxed(readl_relaxed(RK30_GRF_BASE + GRF_SOC_CON1) & (~BIT_EMAC_SPEED), RK30_GRF_BASE + GRF_SOC_CON1);
} else {
help
MAC device present on rockchip rk29xx
+source "drivers/net/eth_mac/Kconfig"
config MACE
tristate "MACE (Power Mac ethernet) support"
obj-$(CONFIG_OCTEON_MGMT_ETHERNET) += octeon/
obj-$(CONFIG_PCH_GBE) += pch_gbe/
obj-$(CONFIG_TILE_NET) += tile/
+
+obj-$(CONFIG_RK29_VMAC) += eth_mac/
--- /dev/null
+#
+# set Ethernet mac source
+#
+choice
+ prompt "Ethernet mac source"
+ depends on NETDEV_10000 ||NETDEV_1000 ||NET_ETHERNET
+ default ETH_MAC_FROM_RANDOM
+
+ config ETH_MAC_FROM_RANDOM
+ bool "Random Ethernet mac "
+ ---help---
+ Say Y here if you want to set Random mac to Ethernet mac.
+
+ This option alone does not add any kernel code.
+
+ If you say N, all options in this submenu will be skipped and disabled.
+
+ config ETH_MAC_FROM_EEPROM
+ bool "Ethernet mac from EEPROM"
+ depends on EEPROM_AT24C16
+ ---help---
+ Say Y here if you want to set EEPROM mac to Ethernet mac,
+ when the EEPROM exsits and mac has been written in.
+
+ This option alone does not add any kernel code.
+
+ If you say N, all options in this submenu will be skipped and disabled.
+
+ config ETH_MAC_FROM_IDB
+ bool "Ethernet mac from IDB"
+ ---help---
+ Say Y here if you want to set IDB mac to Ethernet mac,
+ when the IDB mac has been written in.
+
+ This option alone does not add any kernel code.
+
+ If you say N, all options in this submenu will be skipped and disabled.
+
+ config ETH_MAC_FROM_WIFI_MAC
+ bool "Ethernet mac from Wifi mac"
+ ---help---
+ Say Y here if you want to set Wifi mac to Ethernet mac,
+ when the Wifi device exsits.
+ This option alone does not add any kernel code.
+
+ If you say N, all options in this submenu will be skipped and disabled.
+
+ config ETH_MAC_FROM_SECURE_CHIP
+ bool "Ethernet mac from Secure chip"
+ ---help---
+ Say Y here if you want to set Secure chip mac to Ethernet mac,
+ when the Secure chip exsits and mac has been written in.
+ This option alone does not add any kernel code.
+
+ If you say N, all options in this submenu will be skipped and disabled.
+
+endchoice
+
--- /dev/null
+obj-y += eth_mac.o
--- /dev/null
+/*\r
+ * Copyright (C) 2010 ROCKCHIP, Inc.\r
+ * Author: roger_chen <cz@rock-chips.com>\r
+ *\r
+ * This program is the virtual flash device \r
+ * used to store bd_addr or MAC\r
+ *\r
+ */\r
+\r
+\r
+#include <linux/module.h>\r
+#include <linux/kernel.h>\r
+#include <linux/errno.h>\r
+#include <linux/miscdevice.h>\r
+#include <linux/fs.h>\r
+#include <linux/platform_device.h>\r
+#include <asm/uaccess.h>\r
+#include <asm/io.h>\r
+#include <linux/fs.h>\r
+#include <linux/slab.h>\r
+#include "eth_mac.h"\r
+\r
+#if 1\r
+#define DBG(x...) printk("eth_mac:" x)\r
+#else\r
+#define DBG(x...)\r
+#endif\r
+\r
+#define VERSION "0.1"\r
+\r
+#define WLAN_MAC_FILE "/data/misc/wifi/wlan_mac"\r
+\r
+//extern char GetSNSectorInfo(char * pbuf);\r
+\r
+char GetSNSectorInfoBeforeNandInit(char * pbuf)\r
+{\r
+ char * sn_addr = ioremap(0x10501600,0x200);\r
+ memcpy(pbuf,sn_addr,0x200);\r
+ iounmap(sn_addr);\r
+ //print_hex_dump(KERN_WARNING, "sn:", DUMP_PREFIX_NONE, 16,1, sn_addr, 16, 0);\r
+ return 0;\r
+}\r
+\r
+int eth_mac_read_from_IDB(u8 *mac)\r
+{\r
+ int i;\r
+ char *tempBuf = kmalloc(512, GFP_KERNEL);\r
+ \r
+ if(mac == NULL)\r
+ return -EFAULT;\r
+\r
+ GetSNSectorInfoBeforeNandInit(tempBuf);\r
+ /*for (i = 0; i < 512; i++) {\r
+ printk("%02x, ", tempBuf[i]);\r
+ if(((i+1)%16) == 0) printk("\n");\r
+ }*/\r
+\r
+ for (i = 506; i <= 511; i++)\r
+ mac[i-506] = tempBuf[i];\r
+\r
+ kfree(tempBuf);\r
+ \r
+ return 0;\r
+}\r
+\r
+int eth_mac_idb(u8 *eth_mac)\r
+{\r
+ int i;\r
+ int err = 0;\r
+ memset(eth_mac, 0, 6);\r
+ err = eth_mac_read_from_IDB(eth_mac);\r
+ if (err)\r
+ return -1;\r
+ printk("Read the Ethernet MAC address from IDB:");\r
+ for (i = 0; i < 5; i++)\r
+ printk("%2.2x:", eth_mac[i]);\r
+ printk("%2.2x\n", eth_mac[i]);\r
+\r
+ return 0;\r
+}\r
+\r
+/**\r
+*大写转小写\r
+*\r
+*/\r
+void to_lower(char *str) \r
+{ \r
+ int i=0; \r
+ while(str[i]!=0) \r
+ { \r
+ if((str[i] >= 'A')&&(str[i] <= 'Z')) \r
+ str[i]+=32; \r
+ i++; \r
+ } \r
+} \r
+\r
+\r
+/**\r
+ *字符串格式转为mac 格式.\r
+ *\r
+ *\r
+ */\r
+void trans( char *src ,int * k) \r
+{\r
+ char c;\r
+ int i;\r
+ int temp;\r
+ int temp2;\r
+\r
+ if( (src == NULL) ||(strlen(src) <16 ) ) // 参数检查\r
+ {\r
+ printk( "Arg Error\n" );\r
+ return ;\r
+ }\r
+\r
+ for( i = 0; i < 6; i++ )\r
+ {\r
+ temp = 0;\r
+ temp2 = 0;\r
+ c = *src;\r
+ if( c == ':' ){\r
+ src++;\r
+ c = *src;\r
+ }\r
+ if( c >= 'a' && c <= 'f' ) // 两个字符中的第一个 比如 "0f" ,则表示是字符 '0'\r
+ temp = ( c - 'a' ) + 10; \r
+ else\r
+ temp = ( c - '0' ) ;\r
+ src++;\r
+ \r
+ c = *src;\r
+ if( i == 5){ //wifi mac 末尾加1\r
+ if(c =='f'){\r
+ c = '0';\r
+ } if (c == '9'){\r
+ c = 'a';\r
+ }else{\r
+ c = c + 1;\r
+ }\r
+ }\r
+ if( c >= 'a' && c <= 'f' ) // 两个字符中的第二个,如 "f8" ,那么表示字符 '8'\r
+ temp2 = ( c - 'a' ) + 10;\r
+ else\r
+ temp2 = ( c - '0' ) ;\r
+\r
+ temp = temp * 16;\r
+ temp += temp2;\r
+ src++;\r
+ *(k+i) = temp;\r
+\r
+ }\r
+\r
+}\r
+\r
+int eth_mac_wifi(u8 *eth_mac){\r
+ int i;\r
+ struct file *file = NULL;\r
+ char wifi_mac[32];\r
+ mm_segment_t old_fs;\r
+ ssize_t ret;\r
+\r
+ int *maci=(int *)kmalloc(6, GFP_KERNEL);\r
+\r
+ memset(eth_mac, 0, 6);\r
+ \r
+ file = filp_open(WLAN_MAC_FILE, O_RDWR,0);\r
+ if (IS_ERR(file))\r
+ {\r
+ printk("open %s failed.", WLAN_MAC_FILE);\r
+ return -ENOENT;\r
+ } \r
+\r
+ old_fs = get_fs();\r
+ set_fs(get_ds());\r
+ \r
+ file->f_op->llseek(file,0,0);\r
+ ret = file->f_op->read(file, wifi_mac, 32, &file->f_pos);\r
+ \r
+ set_fs(old_fs);\r
+ \r
+ if(ret > 0){\r
+ //printk("mac read from %s: %s\n", WLAN_MAC_FILE,wifi_mac);\r
+\r
+ to_lower(wifi_mac);\r
+ trans(wifi_mac,maci);\r
+ for (i = 0;i< 6;i++){\r
+ eth_mac[i] = maci[i];\r
+ }\r
+ \r
+ }\r
+ else if(ret == 0)\r
+ printk("read nothing from %s........\n",WLAN_MAC_FILE);\r
+ else \r
+ {\r
+ printk("read wifi mac error\n");\r
+ return -ENOENT;\r
+ }\r
+\r
+ kfree(maci);\r
+ filp_close(file,NULL);\r
+ return 0;\r
+ \r
+}\r
+\r
+\r
+\r
+\r
+\r
--- /dev/null
+#ifndef _ETH_MAC_H_
+#define _ETH_MAC_H_
+/*
+ * eth_mac/eth_mac.h
+ *
+ * Copyright (C) 2001 Russell King.
+ *
+ * This file is placed under the LGPL.
+ *
+ *
+ *
+ */
+//int eth_mac_read_from_IDB(u8 *mac)
+
+int eth_mac_idb(u8 *eth_mac);
+int eth_mac_wifi(u8 *eth_mac);
+#endif /* _ETH_MAC_H_ */
#include <mach/board.h>\r
\r
#include "rk29_vmac.h"\r
+#include "eth_mac/eth_mac.h"\r
\r
static struct wake_lock idlelock; /* add by lyx @ 20110302 */\r
\r
/* mac address intialize, set vmac_open */\r
read_mac_reg(dev, dev->dev_addr);\r
\r
- if (!is_valid_ether_addr(dev->dev_addr))\r
- random_ether_addr(dev->dev_addr);\r
+ if (!is_valid_ether_addr(dev->dev_addr)) {\r
+ //add by cx@rock-chips.com\r
+ \r
+ #ifdef CONFIG_ETH_MAC_FROM_EEPROM\r
+ ret = eeprom_read_data(0,dev->dev_addr,6);\r
+ if (ret != 6){\r
+ printk("read mac from Eeprom fail.\n");\r
+ }else {\r
+ if (is_valid_ether_addr(dev->dev_addr)){\r
+ printk("eth_mac_from_eeprom***********:%X:%X:%X:%X:%X:%X\n",dev->dev_addr[0],\r
+ dev->dev_addr[1],dev->dev_addr[2],dev->dev_addr[3],\r
+ dev->dev_addr[4],dev->dev_addr[5] );\r
+ }\r
+ }\r
+ #endif\r
+ \r
+ #ifdef CONFIG_ETH_MAC_FROM_IDB\r
+ err = eth_mac_idb(dev->dev_addr);\r
+ if (err) {\r
+ printk("read mac from IDB fail.\n");\r
+ } else {\r
+ if (is_valid_ether_addr(dev->dev_addr)) {\r
+ printk("eth_mac_from_idb***********:%X:%X:%X:%X:%X:%X\n",dev->dev_addr[0],\r
+ dev->dev_addr[1],dev->dev_addr[2],dev->dev_addr[3],\r
+ dev->dev_addr[4],dev->dev_addr[5] );\r
+ }\r
+ }\r
+ #endif\r
+ \r
+ #ifdef CONFIG_ETH_MAC_FROM_WIFI_MAC\r
+ err = eth_mac_wifi(dev->dev_addr);\r
+ if (err) {\r
+ printk("read mac from Wifi fail.\n");\r
+ } else {\r
+ if (is_valid_ether_addr(dev->dev_addr)) {\r
+ printk("eth_mac_from_wifi_mac***********:%X:%X:%X:%X:%X:%X\n",dev->dev_addr[0],\r
+ dev->dev_addr[1],dev->dev_addr[2],dev->dev_addr[3],\r
+ dev->dev_addr[4],dev->dev_addr[5] );\r
+ }\r
+ }\r
+ #endif\r
+ \r
+ #ifdef CONFIG_ETH_MAC_FROM_RANDOM\r
+ random_ether_addr(dev->dev_addr);\r
+ printk("random_ether_addr***********:%X:%X:%X:%X:%X:%X\n",dev->dev_addr[0],\r
+ dev->dev_addr[1],dev->dev_addr[2],dev->dev_addr[3],\r
+ dev->dev_addr[4],dev->dev_addr[5] ); \r
+ #endif\r
+ //add end \r
+ }\r
\r
err = register_netdev(dev);\r
if (err) {\r