diff options
author | Richard Röjfors <richard.rojfors@pelagicore.com> | 2010-04-21 19:33:29 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-04-21 19:33:29 -0400 |
commit | a1aa8822d577c8714f8d343eea028befbab3da9d (patch) | |
tree | f4af154b3354cfc1456a257604b348dd9c7e21dc | |
parent | 6846ad282693bd066645aff6f13d2b279d505314 (diff) |
ks8842: Add platform data for setting mac address
This patch adds platform data to the ks8842 driver.
Via the platform data a MAC address, to be used by the controller,
can be passed.
To ensure this MAC address is used, the MAC address is written
after each hardware reset.
Signed-off-by: Richard Röjfors <richard.rojfors@pelagicore.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/ks8842.c | 53 | ||||
-rw-r--r-- | include/linux/ks8842.h | 34 |
2 files changed, 76 insertions, 11 deletions
diff --git a/drivers/net/ks8842.c b/drivers/net/ks8842.c index b91492f4e48a..f852ab3ae9cf 100644 --- a/drivers/net/ks8842.c +++ b/drivers/net/ks8842.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * ks8842_main.c timberdale KS8842 ethernet driver | 2 | * ks8842.c timberdale KS8842 ethernet driver |
3 | * Copyright (c) 2009 Intel Corporation | 3 | * Copyright (c) 2009 Intel Corporation |
4 | * | 4 | * |
5 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/netdevice.h> | 28 | #include <linux/netdevice.h> |
29 | #include <linux/etherdevice.h> | 29 | #include <linux/etherdevice.h> |
30 | #include <linux/ethtool.h> | 30 | #include <linux/ethtool.h> |
31 | #include <linux/ks8842.h> | ||
31 | 32 | ||
32 | #define DRV_NAME "ks8842" | 33 | #define DRV_NAME "ks8842" |
33 | 34 | ||
@@ -304,6 +305,20 @@ static void ks8842_read_mac_addr(struct ks8842_adapter *adapter, u8 *dest) | |||
304 | ks8842_write16(adapter, 39, mac, REG_MACAR3); | 305 | ks8842_write16(adapter, 39, mac, REG_MACAR3); |
305 | } | 306 | } |
306 | 307 | ||
308 | static void ks8842_write_mac_addr(struct ks8842_adapter *adapter, u8 *mac) | ||
309 | { | ||
310 | unsigned long flags; | ||
311 | unsigned i; | ||
312 | |||
313 | spin_lock_irqsave(&adapter->lock, flags); | ||
314 | for (i = 0; i < ETH_ALEN; i++) { | ||
315 | ks8842_write8(adapter, 2, mac[ETH_ALEN - i - 1], REG_MARL + i); | ||
316 | ks8842_write8(adapter, 39, mac[ETH_ALEN - i - 1], | ||
317 | REG_MACAR1 + i); | ||
318 | } | ||
319 | spin_unlock_irqrestore(&adapter->lock, flags); | ||
320 | } | ||
321 | |||
307 | static inline u16 ks8842_tx_fifo_space(struct ks8842_adapter *adapter) | 322 | static inline u16 ks8842_tx_fifo_space(struct ks8842_adapter *adapter) |
308 | { | 323 | { |
309 | return ks8842_read16(adapter, 16, REG_TXMIR) & 0x1fff; | 324 | return ks8842_read16(adapter, 16, REG_TXMIR) & 0x1fff; |
@@ -522,6 +537,8 @@ static int ks8842_open(struct net_device *netdev) | |||
522 | /* reset the HW */ | 537 | /* reset the HW */ |
523 | ks8842_reset_hw(adapter); | 538 | ks8842_reset_hw(adapter); |
524 | 539 | ||
540 | ks8842_write_mac_addr(adapter, netdev->dev_addr); | ||
541 | |||
525 | ks8842_update_link_status(netdev, adapter); | 542 | ks8842_update_link_status(netdev, adapter); |
526 | 543 | ||
527 | err = request_irq(adapter->irq, ks8842_irq, IRQF_SHARED, DRV_NAME, | 544 | err = request_irq(adapter->irq, ks8842_irq, IRQF_SHARED, DRV_NAME, |
@@ -568,10 +585,8 @@ static netdev_tx_t ks8842_xmit_frame(struct sk_buff *skb, | |||
568 | static int ks8842_set_mac(struct net_device *netdev, void *p) | 585 | static int ks8842_set_mac(struct net_device *netdev, void *p) |
569 | { | 586 | { |
570 | struct ks8842_adapter *adapter = netdev_priv(netdev); | 587 | struct ks8842_adapter *adapter = netdev_priv(netdev); |
571 | unsigned long flags; | ||
572 | struct sockaddr *addr = p; | 588 | struct sockaddr *addr = p; |
573 | char *mac = (u8 *)addr->sa_data; | 589 | char *mac = (u8 *)addr->sa_data; |
574 | int i; | ||
575 | 590 | ||
576 | dev_dbg(&adapter->pdev->dev, "%s: entry\n", __func__); | 591 | dev_dbg(&adapter->pdev->dev, "%s: entry\n", __func__); |
577 | 592 | ||
@@ -580,13 +595,7 @@ static int ks8842_set_mac(struct net_device *netdev, void *p) | |||
580 | 595 | ||
581 | memcpy(netdev->dev_addr, mac, netdev->addr_len); | 596 | memcpy(netdev->dev_addr, mac, netdev->addr_len); |
582 | 597 | ||
583 | spin_lock_irqsave(&adapter->lock, flags); | 598 | ks8842_write_mac_addr(adapter, mac); |
584 | for (i = 0; i < ETH_ALEN; i++) { | ||
585 | ks8842_write8(adapter, 2, mac[ETH_ALEN - i - 1], REG_MARL + i); | ||
586 | ks8842_write8(adapter, 39, mac[ETH_ALEN - i - 1], | ||
587 | REG_MACAR1 + i); | ||
588 | } | ||
589 | spin_unlock_irqrestore(&adapter->lock, flags); | ||
590 | return 0; | 599 | return 0; |
591 | } | 600 | } |
592 | 601 | ||
@@ -605,6 +614,8 @@ static void ks8842_tx_timeout(struct net_device *netdev) | |||
605 | 614 | ||
606 | ks8842_reset_hw(adapter); | 615 | ks8842_reset_hw(adapter); |
607 | 616 | ||
617 | ks8842_write_mac_addr(adapter, netdev->dev_addr); | ||
618 | |||
608 | ks8842_update_link_status(netdev, adapter); | 619 | ks8842_update_link_status(netdev, adapter); |
609 | } | 620 | } |
610 | 621 | ||
@@ -627,7 +638,9 @@ static int __devinit ks8842_probe(struct platform_device *pdev) | |||
627 | struct resource *iomem; | 638 | struct resource *iomem; |
628 | struct net_device *netdev; | 639 | struct net_device *netdev; |
629 | struct ks8842_adapter *adapter; | 640 | struct ks8842_adapter *adapter; |
641 | struct ks8842_platform_data *pdata = pdev->dev.platform_data; | ||
630 | u16 id; | 642 | u16 id; |
643 | unsigned i; | ||
631 | 644 | ||
632 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 645 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
633 | if (!request_mem_region(iomem->start, resource_size(iomem), DRV_NAME)) | 646 | if (!request_mem_region(iomem->start, resource_size(iomem), DRV_NAME)) |
@@ -658,7 +671,25 @@ static int __devinit ks8842_probe(struct platform_device *pdev) | |||
658 | netdev->netdev_ops = &ks8842_netdev_ops; | 671 | netdev->netdev_ops = &ks8842_netdev_ops; |
659 | netdev->ethtool_ops = &ks8842_ethtool_ops; | 672 | netdev->ethtool_ops = &ks8842_ethtool_ops; |
660 | 673 | ||
661 | ks8842_read_mac_addr(adapter, netdev->dev_addr); | 674 | /* Check if a mac address was given */ |
675 | i = netdev->addr_len; | ||
676 | if (pdata) { | ||
677 | for (i = 0; i < netdev->addr_len; i++) | ||
678 | if (pdata->macaddr[i] != 0) | ||
679 | break; | ||
680 | |||
681 | if (i < netdev->addr_len) | ||
682 | /* an address was passed, use it */ | ||
683 | memcpy(netdev->dev_addr, pdata->macaddr, | ||
684 | netdev->addr_len); | ||
685 | } | ||
686 | |||
687 | if (i == netdev->addr_len) { | ||
688 | ks8842_read_mac_addr(adapter, netdev->dev_addr); | ||
689 | |||
690 | if (!is_valid_ether_addr(netdev->dev_addr)) | ||
691 | random_ether_addr(netdev->dev_addr); | ||
692 | } | ||
662 | 693 | ||
663 | id = ks8842_read16(adapter, 32, REG_SW_ID_AND_ENABLE); | 694 | id = ks8842_read16(adapter, 32, REG_SW_ID_AND_ENABLE); |
664 | 695 | ||
diff --git a/include/linux/ks8842.h b/include/linux/ks8842.h new file mode 100644 index 000000000000..da0341b8ca0a --- /dev/null +++ b/include/linux/ks8842.h | |||
@@ -0,0 +1,34 @@ | |||
1 | /* | ||
2 | * ks8842.h KS8842 platform data struct definition | ||
3 | * Copyright (c) 2010 Intel Corporation | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | #ifndef _LINUX_KS8842_H | ||
20 | #define _LINUX_KS8842_H | ||
21 | |||
22 | #include <linux/if_ether.h> | ||
23 | |||
24 | /** | ||
25 | * struct ks8842_platform_data - Platform data of the KS8842 network driver | ||
26 | * @macaddr: The MAC address of the device, set to all 0:s to use the on in | ||
27 | * the chip. | ||
28 | * | ||
29 | */ | ||
30 | struct ks8842_platform_data { | ||
31 | u8 macaddr[ETH_ALEN]; | ||
32 | }; | ||
33 | |||
34 | #endif | ||