netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hayes Wang <hayeswang@realtek.com>
To: <netdev@vger.kernel.org>
Cc: <nic_swsd@realtek.com>, <linux-kernel@vger.kernel.org>,
	<linux-usb@vger.kernel.org>, Hayes Wang <hayeswang@realtek.com>
Subject: [PATCH net-next 4/6] r8152: add rtl_ops
Date: Fri, 27 Dec 2013 10:34:08 +0800	[thread overview]
Message-ID: <1388111649-1014-5-git-send-email-hayeswang@realtek.com> (raw)
In-Reply-To: <1388111649-1014-1-git-send-email-hayeswang@realtek.com>

The different chips may have different settings. This makes it easy
to let different chips have the same flow with differnt settings.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/r8152.c | 56 ++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 49 insertions(+), 7 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index a8ea848..040ef73 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -367,6 +367,15 @@ struct r8152 {
 	spinlock_t rx_lock, tx_lock;
 	struct delayed_work schedule;
 	struct mii_if_info mii;
+
+	struct rtl_ops {
+		void (*init)(struct r8152 *);
+		int (*enable)(struct r8152 *);
+		void (*disable)(struct r8152 *);
+		void (*down)(struct r8152 *);
+		void (*unload)(struct r8152 *);
+	} rtl_ops;
+
 	int intr_interval;
 	u32 msg_enable;
 	u32 tx_qlen;
@@ -1751,7 +1760,7 @@ static void set_carrier(struct r8152 *tp)
 
 	if (speed & LINK_STATUS) {
 		if (!(tp->speed & LINK_STATUS)) {
-			rtl8152_enable(tp);
+			tp->rtl_ops.enable(tp);
 			set_bit(RTL8152_SET_RX_MODE, &tp->flags);
 			netif_carrier_on(netdev);
 		}
@@ -1759,7 +1768,7 @@ static void set_carrier(struct r8152 *tp)
 		if (tp->speed & LINK_STATUS) {
 			netif_carrier_off(netdev);
 			tasklet_disable(&tp->tl);
-			rtl8152_disable(tp);
+			tp->rtl_ops.disable(tp);
 			tasklet_enable(&tp->tl);
 		}
 	}
@@ -1819,7 +1828,7 @@ static int rtl8152_close(struct net_device *netdev)
 	cancel_delayed_work_sync(&tp->schedule);
 	netif_stop_queue(netdev);
 	tasklet_disable(&tp->tl);
-	rtl8152_disable(tp);
+	tp->rtl_ops.disable(tp);
 	tasklet_enable(&tp->tl);
 
 	return res;
@@ -1945,7 +1954,7 @@ static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message)
 		tasklet_disable(&tp->tl);
 	}
 
-	rtl8152_down(tp);
+	tp->rtl_ops.down(tp);
 
 	return 0;
 }
@@ -1954,7 +1963,7 @@ static int rtl8152_resume(struct usb_interface *intf)
 {
 	struct r8152 *tp = usb_get_intfdata(intf);
 
-	r8152b_init(tp);
+	tp->rtl_ops.init(tp);
 	netif_device_attach(tp->netdev);
 	if (netif_running(tp->netdev)) {
 		rtl8152_set_speed(tp, AUTONEG_ENABLE, SPEED_100, DUPLEX_FULL);
@@ -2083,6 +2092,34 @@ static void rtl8152_unload(struct r8152 *tp)
 	ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data);
 }
 
+static int rtl_ops_init(struct r8152 *tp, const struct usb_device_id *id)
+{
+	struct rtl_ops *ops = &tp->rtl_ops;
+	int ret = 0;
+
+	switch (id->idVendor) {
+	case VENDOR_ID_REALTEK:
+		switch (id->idProduct) {
+		case PRODUCT_ID_RTL8152:
+			ops->init		= r8152b_init;
+			ops->enable		= rtl8152_enable;
+			ops->disable		= rtl8152_disable;
+			ops->down		= rtl8152_down;
+			ops->unload		= rtl8152_unload;
+			break;
+		default:
+			ret = -EFAULT;
+			break;
+		}
+		break;
+
+	default:
+		ret = -EFAULT;
+		break;
+	}
+	return ret;
+}
+
 static int rtl8152_probe(struct usb_interface *intf,
 			 const struct usb_device_id *id)
 {
@@ -2106,6 +2143,11 @@ static int rtl8152_probe(struct usb_interface *intf,
 	tp = netdev_priv(netdev);
 	tp->msg_enable = 0x7FFF;
 
+	if (rtl_ops_init(tp, id)) {
+		netif_err(tp, probe, netdev, "Unknown Device");
+		return -ENODEV;
+	}
+
 	tasklet_init(&tp->tl, bottom_half, (unsigned long)tp);
 	INIT_DELAYED_WORK(&tp->schedule, rtl_work_func_t);
 
@@ -2128,7 +2170,7 @@ static int rtl8152_probe(struct usb_interface *intf,
 	tp->mii.supports_gmii = 0;
 
 	r8152b_get_version(tp);
-	r8152b_init(tp);
+	tp->rtl_ops.init(tp);
 	set_ethernet_addr(tp);
 
 	ret = alloc_all_mem(tp);
@@ -2163,7 +2205,7 @@ static void rtl8152_disconnect(struct usb_interface *intf)
 		set_bit(RTL8152_UNPLUG, &tp->flags);
 		tasklet_kill(&tp->tl);
 		unregister_netdev(tp->netdev);
-		rtl8152_unload(tp);
+		tp->rtl_ops.unload(tp);
 		free_all_mem(tp);
 		free_netdev(tp->netdev);
 	}
-- 
1.8.3.1

  parent reply	other threads:[~2013-12-27  2:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-27  2:34 [PATCH net-next 0/6] Support new chip Hayes Wang
     [not found] ` <1388111649-1014-1-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2013-12-27  2:34   ` [PATCH net-next 1/6] r8152: move rtl8152_unload and ocp_reg_write Hayes Wang
2013-12-27  2:34 ` [PATCH net-next 2/6] r8152: modify the method of accessing PHY Hayes Wang
2013-12-27  2:34 ` [PATCH net-next 3/6] r8152: change some definitions Hayes Wang
2013-12-27 18:57   ` Francois Romieu
2013-12-27  2:34 ` Hayes Wang [this message]
2013-12-27 17:28   ` [PATCH net-next 4/6] r8152: add rtl_ops David Miller
2013-12-27  2:34 ` [PATCH net-next 5/6] r8152: split rtl8152_enable Hayes Wang
2013-12-27  2:37 ` [PATCH net-next 6/6] r8152: support RTL8153 Hayes Wang
2013-12-27 19:08   ` Francois Romieu
2014-01-02  3:22 ` [PATCH net-next v2 0/6] support new chip Hayes Wang
2014-01-02  3:22   ` [PATCH net-next v2 1/6] r8152: move rtl8152_unload and ocp_reg_write Hayes Wang
2014-01-02  3:22   ` [PATCH net-next v2 2/6] r8152: modify the method of accessing PHY Hayes Wang
2014-01-02  3:22   ` [PATCH net-next v2 3/6] r8152: change some definitions Hayes Wang
2014-01-02  3:22   ` [PATCH net-next v2 4/6] r8152: add rtl_ops Hayes Wang
2014-01-02  3:22   ` [PATCH net-next v2 5/6] r8152: split rtl8152_enable Hayes Wang
2014-01-02  3:25   ` [PATCH net-next v2 6/6] r8152: support RTL8153 Hayes Wang
2014-01-02 14:25     ` Bjørn Mork
2014-01-03  2:56       ` hayeswang
2014-01-03  7:49         ` Bjørn Mork
2014-01-06  3:20           ` hayeswang
2014-01-06  9:21             ` Bjørn Mork
2014-01-07 12:35               ` hayeswang
     [not found]                 ` <749DBDC9792E47BBA5884BEC7CF2D639-Rasf1IRRPZGoECsaD+WFmw@public.gmane.org>
2014-01-08 18:24                   ` Ben Hutchings
     [not found]   ` <1388632963-1341-1-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2014-01-02  3:55     ` [PATCH net-next v2 0/6] support new chip David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1388111649-1014-5-git-send-email-hayeswang@realtek.com \
    --to=hayeswang@realtek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nic_swsd@realtek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).