linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joseph CHANG <josright123@gmail.com>
To: Peter Korsgaard <jacmet@sunsite.dk>,
	netdev@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Joseph CHANG <josright123@gmail.com>
Cc: Joseph Chang <joseph_chang@davicom.com.tw>
Subject: [PATCH 2/3] dm9601: manage eeprom to assure the chip for correct operation
Date: Thu, 10 Mar 2016 19:23:58 +0800	[thread overview]
Message-ID: <1457609038-3636-1-git-send-email-josright123@gmail.com> (raw)

Add to maintain variant eeprom adapters which may have not right
dm962x's format.

Signed-off-by: Joseph CHANG <josright123@gmail.com>
---
 drivers/net/usb/dm9601.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/drivers/net/usb/dm9601.c b/drivers/net/usb/dm9601.c
index 520de4f..50095df 100644
--- a/drivers/net/usb/dm9601.c
+++ b/drivers/net/usb/dm9601.c
@@ -60,6 +60,7 @@
 #define DM_TX_OVERHEAD	2	/* 2 byte header */
 #define DM_RX_OVERHEAD	7	/* 3 byte header + 4 byte crc tail */
 #define DM_TIMEOUT	1000
+#define	DM_EP3I_VAL	0x07
 
 static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data)
 {
@@ -193,6 +194,75 @@ static int dm_read_eeprom_word(struct usbnet *dev, u8 offset, void *value)
 	return dm_read_shared_word(dev, 0, offset, value);
 }
 
+static void dm_write_eeprom_word(struct usbnet *dev, u8 offset, __le16 data)
+{
+	dm_write_shared_word(dev, 0, offset, data);
+}
+
+static int dm_render_write(struct usbnet *dev, u8 wordoffset, u16 mask_word,
+			   u16 orset_word, u16 *pmd)
+{
+	u16 srom;
+
+	dm_read_eeprom_word(dev, wordoffset, &srom);
+	if ((srom & mask_word) == orset_word)
+		return 0;
+
+	srom &= ~mask_word;
+	srom |= orset_word;
+
+	dm_write_eeprom_word(dev, wordoffset, srom);
+	*pmd = srom;
+	return 1;
+}
+
+static void dm_render_report(struct usbnet *dev, u8 wordoffset, u16 md)
+{
+	int i = 0;
+	u16 srom;
+
+	do {
+		i++;
+		usleep_range(100, 200);
+		dm_read_eeprom_word(dev, wordoffset, &srom);
+		if (i == 8)
+			break;
+	} while (srom != md);
+
+	if (srom == md) {
+		netdev_info(dev->net, "set eeprom word%d 0x%04x\n",
+			    wordoffset, md);
+	} else {
+		netdev_info(dev->net, "warning - set eeprom word%d 0x%04x\n",
+			    wordoffset, md);
+		netdev_info(dev->net, "warning - fail as eeprom word%d 0x%04x\n",
+			    wordoffset, srom);
+	}
+}
+
+static void dm_eeprom_render(struct usbnet *dev, u8 wordoffset,
+			     u16 orset_word, u16 mask_word)
+{
+	u16 m;
+
+	if (!dm_render_write(dev, wordoffset, mask_word, orset_word, &m))
+		return;
+
+	dm_render_report(dev, wordoffset, m);
+}
+
+static void dm_render_begin(struct usbnet *dev)
+{
+	/* Render eeprom if need, WORD3 render, set D[15:14] 01b */
+	dm_eeprom_render(dev, 3, 0x4000, 0xc000);
+	/* Render eeprom if need, WORD7 render, clear D[10] */
+	dm_eeprom_render(dev, 7, 0x0000, 0x0400);
+	/* Render eeprom if need, WORD11 render, need 0x005a */
+	dm_eeprom_render(dev, 11, 0x005a, 0xffff);
+	/* Render eeprom if need, WORD12 render, need 0x0007 */
+	dm_eeprom_render(dev, 12, DM_EP3I_VAL, 0xffff);
+}
+
 
 
 static int dm9601_get_eeprom_len(struct net_device *dev)
@@ -420,6 +490,8 @@ static int dm9601_bind(struct usbnet *dev, struct usb_interface *intf)
 
 		/* Always return 8-bytes data to host per interrupt-interval */
 		dm_write_reg(dev, DM_USB_CTRL, USB_CTRL_EP3ACK);
+
+		dm_render_begin(dev);
 	}
 
 	/* power up phy */
-- 
2.1.4

             reply	other threads:[~2016-03-10 11:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-10 11:23 Joseph CHANG [this message]
2016-03-10 18:36 ` Peter Korsgaard
2016-03-11 10:56   ` Joseph Chang

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=1457609038-3636-1-git-send-email-josright123@gmail.com \
    --to=josright123@gmail.com \
    --cc=jacmet@sunsite.dk \
    --cc=joseph_chang@davicom.com.tw \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --subject='Re: [PATCH 2/3] dm9601: manage eeprom to assure the chip for correct operation' \
    /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

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox