Subject: [PATCH 1/2] ks8842: Add flags in the platform data

From: Richard Röjfors<[email-masked]>
Date: Sat, 24 Jul 2010 22:25:23 +0200

Previously the driver did a write to a timberdale specific register.
Timberdale is a FPGA used in some hardware setup which communicates
to the ks8842 via VLB.

A flag field is introduced where it is possible to pass a flag if
the ks8842 is connected via timberdale. Otherwise the driver won't
try to access timberdale registers.

If the timberdale flag is passed the driver also acks interrupts
in the FPGA, this is a bit more polite to the FPGA state machine.

Signed-off-by: Richard Röjfors <[email-masked]>
---
diff --git a/drivers/net/ks8842.c b/drivers/net/ks8842.c
index 0be9261..48e4582 100644
--- a/drivers/net/ks8842.c
+++ b/drivers/net/ks8842.c
@@ -33,7 +33,13 @@
 #define DRV_NAME "ks8842"
 
 /* Timberdale specific Registers */
-#define REG_TIMB_RST	0x1c
+#define REG_TIMB_RST		0x1c
+#define REG_TIMB_FIFO		0x20
+#define REG_TIMB_ISR		0x24
+#define REG_TIMB_IER		0x28
+#define REG_TIMB_IAR		0x2C
+#define REQ_TIMB_DMA_RESUME	0x30
+
 
 /* KS8842 registers */
 
@@ -121,6 +127,7 @@ struct ks8842_adapter {
 	spinlock_t	lock; /* spinlock to be interrupt safe */
 	struct work_struct timeout_work;
 	struct net_device *netdev;
+	u8 flags;
 };
 
 static inline void ks8842_select_bank(struct ks8842_adapter *adapter, u16 bank)
@@ -195,12 +202,15 @@ static void ks8842_reset(struct ks8842_adapter *adapter)
 	/* The KS8842 goes haywire when doing softare reset
 	 * a work around in the timberdale IP is implemented to
 	 * do a hardware reset instead
-	ks8842_write16(adapter, 3, 1, REG_GRR);
-	msleep(10);
-	iowrite16(0, adapter->hw_addr + REG_GRR);
-	*/
-	iowrite32(0x1, adapter->hw_addr + REG_TIMB_RST);
-	msleep(20);
+	 */
+	if (adapter->flags & KS8842_FLAGS_TIMB) {
+		iowrite32(0x1, adapter->hw_addr + REG_TIMB_RST);
+		msleep(20);
+	} else {
+		ks8842_write16(adapter, 3, 1, REG_GRR);
+		msleep(10);
+		iowrite16(0, adapter->hw_addr + REG_GRR);
+	}
 }
 
 static void ks8842_update_link_status(struct net_device *netdev,
@@ -463,6 +473,10 @@ void ks8842_tasklet(unsigned long arg)
 	/* Ack */
 	ks8842_write16(adapter, 18, isr, REG_ISR);
 
+	/* Ack in the timberdale IP as well */
+	if (adapter->flags & KS8842_FLAGS_TIMB)
+		iowrite32(0x1, adapter->hw_addr + REG_TIMB_IAR);
+
 	if (!netif_running(netdev))
 		return;
 
@@ -687,6 +701,8 @@ static int __devinit ks8842_probe(struct platform_device *pdev)
 	/* Check if a mac address was given */
 	i = netdev->addr_len;
 	if (pdata) {
+		adapter->flags = pdata->flags;
+
 		for (i = 0; i < netdev->addr_len; i++)
 			if (pdata->macaddr[i] != 0)
 				break;
diff --git a/include/linux/ks8842.h b/include/linux/ks8842.h
index da0341b..12b4bda 100644
--- a/include/linux/ks8842.h
+++ b/include/linux/ks8842.h
@@ -21,14 +21,18 @@
 
 #include <linux/if_ether.h>
 
+#define KS8842_FLAGS_TIMB 0x01
+
 /**
  * struct ks8842_platform_data - Platform data of the KS8842 network driver
  * @macaddr:	The MAC address of the device, set to all 0:s to use the on in
  *		the chip.
+ * @flags:	Flags to the drivers which configures the hardware setup
  *
  */
 struct ks8842_platform_data {
 	u8 macaddr[ETH_ALEN];
+	u8 flags;
 };
 
 #endif