Skip to content

Commit a648ab5

Browse files
committed
Merge branch 'minnow/net-next' of git://git.infradead.org/users/dvhart/linux-2.6 into minnow
Darren Hart says: ==================== Add support for the MinnowBoard in the pch_gbe driver. This was originally sent to LKML as part of the MinnowBoard support series. That is now partially merged and this version of the patch has been isolated from those changes and is now completely self-contained. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 452c447 + f1a26fd commit a648ab5

4 files changed

Lines changed: 164 additions & 1 deletion

File tree

‎drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,19 @@ struct pch_gbe_hw_stats {
581581
u32 intr_tcpip_err_count;
582582
};
583583

584+
/**
585+
* struct pch_gbe_privdata - PCI Device ID driver data
586+
* @phy_tx_clk_delay: Bool, configure the PHY TX delay in software
587+
* @phy_disable_hibernate: Bool, disable PHY hibernation
588+
* @platform_init: Platform initialization callback, called from
589+
* probe, prior to PHY initialization.
590+
*/
591+
struct pch_gbe_privdata {
592+
bool phy_tx_clk_delay;
593+
bool phy_disable_hibernate;
594+
int (*platform_init)(struct pci_dev *pdev);
595+
};
596+
584597
/**
585598
* struct pch_gbe_adapter - board specific private data structure
586599
* @stats_lock: Spinlock structure for status
@@ -604,6 +617,7 @@ struct pch_gbe_hw_stats {
604617
* @rx_buffer_len: Receive buffer length
605618
* @tx_queue_len: Transmit queue length
606619
* @have_msi: PCI MSI mode flag
620+
* @pch_gbe_privdata: PCI Device ID driver_data
607621
*/
608622

609623
struct pch_gbe_adapter {
@@ -631,6 +645,7 @@ struct pch_gbe_adapter {
631645
int hwts_tx_en;
632646
int hwts_rx_en;
633647
struct pci_dev *ptp_pdev;
648+
struct pch_gbe_privdata *pdata;
634649
};
635650

636651
#define pch_gbe_hw_to_adapter(hw) container_of(hw, struct pch_gbe_adapter, hw)

‎drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/module.h>
2424
#include <linux/net_tstamp.h>
2525
#include <linux/ptp_classify.h>
26+
#include <linux/gpio.h>
2627

2728
#define DRV_VERSION "1.01"
2829
const char pch_driver_version[] = DRV_VERSION;
@@ -111,6 +112,8 @@ const char pch_driver_version[] = DRV_VERSION;
111112
#define PTP_L4_MULTICAST_SA "01:00:5e:00:01:81"
112113
#define PTP_L2_MULTICAST_SA "01:1b:19:00:00:00"
113114

115+
#define MINNOW_PHY_RESET_GPIO 13
116+
114117
static unsigned int copybreak __read_mostly = PCH_GBE_COPYBREAK_DEFAULT;
115118

116119
static int pch_gbe_mdio_read(struct net_device *netdev, int addr, int reg);
@@ -682,7 +685,7 @@ static int pch_gbe_init_phy(struct pch_gbe_adapter *adapter)
682685
}
683686
adapter->hw.phy.addr = adapter->mii.phy_id;
684687
netdev_dbg(netdev, "phy_addr = %d\n", adapter->mii.phy_id);
685-
if (addr == 32)
688+
if (addr == PCH_GBE_PHY_REGS_LEN)
686689
return -EAGAIN;
687690
/* Selected the phy and isolate the rest */
688691
for (addr = 0; addr < PCH_GBE_PHY_REGS_LEN; addr++) {
@@ -2635,6 +2638,9 @@ static int pch_gbe_probe(struct pci_dev *pdev,
26352638
adapter->pdev = pdev;
26362639
adapter->hw.back = adapter;
26372640
adapter->hw.reg = pcim_iomap_table(pdev)[PCH_GBE_PCI_BAR];
2641+
adapter->pdata = (struct pch_gbe_privdata *)pci_id->driver_data;
2642+
if (adapter->pdata && adapter->pdata->platform_init)
2643+
adapter->pdata->platform_init(pdev);
26382644

26392645
adapter->ptp_pdev = pci_get_bus_and_slot(adapter->pdev->bus->number,
26402646
PCI_DEVFN(12, 4));
@@ -2710,6 +2716,10 @@ static int pch_gbe_probe(struct pci_dev *pdev,
27102716

27112717
dev_dbg(&pdev->dev, "PCH Network Connection\n");
27122718

2719+
/* Disable hibernation on certain platforms */
2720+
if (adapter->pdata && adapter->pdata->phy_disable_hibernate)
2721+
pch_gbe_phy_disable_hibernate(&adapter->hw);
2722+
27132723
device_set_wakeup_enable(&pdev->dev, 1);
27142724
return 0;
27152725

@@ -2720,7 +2730,46 @@ static int pch_gbe_probe(struct pci_dev *pdev,
27202730
return ret;
27212731
}
27222732

2733+
/* The AR803X PHY on the MinnowBoard requires a physical pin to be toggled to
2734+
* ensure it is awake for probe and init. Request the line and reset the PHY.
2735+
*/
2736+
static int pch_gbe_minnow_platform_init(struct pci_dev *pdev)
2737+
{
2738+
unsigned long flags = GPIOF_DIR_OUT | GPIOF_INIT_HIGH | GPIOF_EXPORT;
2739+
unsigned gpio = MINNOW_PHY_RESET_GPIO;
2740+
int ret;
2741+
2742+
ret = devm_gpio_request_one(&pdev->dev, gpio, flags,
2743+
"minnow_phy_reset");
2744+
if (ret) {
2745+
dev_err(&pdev->dev,
2746+
"ERR: Can't request PHY reset GPIO line '%d'\n", gpio);
2747+
return ret;
2748+
}
2749+
2750+
gpio_set_value(gpio, 0);
2751+
usleep_range(1250, 1500);
2752+
gpio_set_value(gpio, 1);
2753+
usleep_range(1250, 1500);
2754+
2755+
return ret;
2756+
}
2757+
2758+
static struct pch_gbe_privdata pch_gbe_minnow_privdata = {
2759+
.phy_tx_clk_delay = true,
2760+
.phy_disable_hibernate = true,
2761+
.platform_init = pch_gbe_minnow_platform_init,
2762+
};
2763+
27232764
static DEFINE_PCI_DEVICE_TABLE(pch_gbe_pcidev_id) = {
2765+
{.vendor = PCI_VENDOR_ID_INTEL,
2766+
.device = PCI_DEVICE_ID_INTEL_IOH1_GBE,
2767+
.subvendor = PCI_VENDOR_ID_CIRCUITCO,
2768+
.subdevice = PCI_SUBSYSTEM_ID_CIRCUITCO_MINNOWBOARD,
2769+
.class = (PCI_CLASS_NETWORK_ETHERNET << 8),
2770+
.class_mask = (0xFFFF00),
2771+
.driver_data = (kernel_ulong_t)&pch_gbe_minnow_privdata
2772+
},
27242773
{.vendor = PCI_VENDOR_ID_INTEL,
27252774
.device = PCI_DEVICE_ID_INTEL_IOH1_GBE,
27262775
.subvendor = PCI_ANY_ID,

‎drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_phy.c‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@
7474
#define MII_SR_100X_FD_CAPS 0x4000 /* 100X Full Duplex Capable */
7575
#define MII_SR_100T4_CAPS 0x8000 /* 100T4 Capable */
7676

77+
/* AR8031 PHY Debug Registers */
78+
#define PHY_AR803X_ID 0x00001374
79+
#define PHY_AR8031_DBG_OFF 0x1D
80+
#define PHY_AR8031_DBG_DAT 0x1E
81+
#define PHY_AR8031_SERDES 0x05
82+
#define PHY_AR8031_HIBERNATE 0x0B
83+
#define PHY_AR8031_SERDES_TX_CLK_DLY 0x0100 /* TX clock delay of 2.0ns */
84+
#define PHY_AR8031_PS_HIB_EN 0x8000 /* Hibernate enable */
85+
7786
/* Phy Id Register (word 2) */
7887
#define PHY_REVISION_MASK 0x000F
7988

@@ -248,6 +257,51 @@ void pch_gbe_phy_set_rgmii(struct pch_gbe_hw *hw)
248257
pch_gbe_phy_sw_reset(hw);
249258
}
250259

260+
/**
261+
* pch_gbe_phy_tx_clk_delay - Setup TX clock delay via the PHY
262+
* @hw: Pointer to the HW structure
263+
* Returns
264+
* 0: Successful.
265+
* -EINVAL: Invalid argument.
266+
*/
267+
static int pch_gbe_phy_tx_clk_delay(struct pch_gbe_hw *hw)
268+
{
269+
/* The RGMII interface requires a ~2ns TX clock delay. This is typically
270+
* done in layout with a longer trace or via PHY strapping, but can also
271+
* be done via PHY configuration registers.
272+
*/
273+
struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
274+
u16 mii_reg;
275+
int ret = 0;
276+
277+
switch (hw->phy.id) {
278+
case PHY_AR803X_ID:
279+
netdev_dbg(adapter->netdev,
280+
"Configuring AR803X PHY for 2ns TX clock delay\n");
281+
pch_gbe_phy_read_reg_miic(hw, PHY_AR8031_DBG_OFF, &mii_reg);
282+
ret = pch_gbe_phy_write_reg_miic(hw, PHY_AR8031_DBG_OFF,
283+
PHY_AR8031_SERDES);
284+
if (ret)
285+
break;
286+
287+
pch_gbe_phy_read_reg_miic(hw, PHY_AR8031_DBG_DAT, &mii_reg);
288+
mii_reg |= PHY_AR8031_SERDES_TX_CLK_DLY;
289+
ret = pch_gbe_phy_write_reg_miic(hw, PHY_AR8031_DBG_DAT,
290+
mii_reg);
291+
break;
292+
default:
293+
netdev_err(adapter->netdev,
294+
"Unknown PHY (%x), could not set TX clock delay\n",
295+
hw->phy.id);
296+
return -EINVAL;
297+
}
298+
299+
if (ret)
300+
netdev_err(adapter->netdev,
301+
"Could not configure tx clock delay for PHY\n");
302+
return ret;
303+
}
304+
251305
/**
252306
* pch_gbe_phy_init_setting - PHY initial setting
253307
* @hw: Pointer to the HW structure
@@ -277,4 +331,48 @@ void pch_gbe_phy_init_setting(struct pch_gbe_hw *hw)
277331
pch_gbe_phy_read_reg_miic(hw, PHY_PHYSP_CONTROL, &mii_reg);
278332
mii_reg |= PHYSP_CTRL_ASSERT_CRS_TX;
279333
pch_gbe_phy_write_reg_miic(hw, PHY_PHYSP_CONTROL, mii_reg);
334+
335+
/* Setup a TX clock delay on certain platforms */
336+
if (adapter->pdata && adapter->pdata->phy_tx_clk_delay)
337+
pch_gbe_phy_tx_clk_delay(hw);
338+
}
339+
340+
/**
341+
* pch_gbe_phy_disable_hibernate - Disable the PHY low power state
342+
* @hw: Pointer to the HW structure
343+
* Returns
344+
* 0: Successful.
345+
* -EINVAL: Invalid argument.
346+
*/
347+
int pch_gbe_phy_disable_hibernate(struct pch_gbe_hw *hw)
348+
{
349+
struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
350+
u16 mii_reg;
351+
int ret = 0;
352+
353+
switch (hw->phy.id) {
354+
case PHY_AR803X_ID:
355+
netdev_dbg(adapter->netdev,
356+
"Disabling hibernation for AR803X PHY\n");
357+
ret = pch_gbe_phy_write_reg_miic(hw, PHY_AR8031_DBG_OFF,
358+
PHY_AR8031_HIBERNATE);
359+
if (ret)
360+
break;
361+
362+
pch_gbe_phy_read_reg_miic(hw, PHY_AR8031_DBG_DAT, &mii_reg);
363+
mii_reg &= ~PHY_AR8031_PS_HIB_EN;
364+
ret = pch_gbe_phy_write_reg_miic(hw, PHY_AR8031_DBG_DAT,
365+
mii_reg);
366+
break;
367+
default:
368+
netdev_err(adapter->netdev,
369+
"Unknown PHY (%x), could not disable hibernation\n",
370+
hw->phy.id);
371+
return -EINVAL;
372+
}
373+
374+
if (ret)
375+
netdev_err(adapter->netdev,
376+
"Could not disable PHY hibernation\n");
377+
return ret;
280378
}

‎drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_phy.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ void pch_gbe_phy_power_up(struct pch_gbe_hw *hw);
3333
void pch_gbe_phy_power_down(struct pch_gbe_hw *hw);
3434
void pch_gbe_phy_set_rgmii(struct pch_gbe_hw *hw);
3535
void pch_gbe_phy_init_setting(struct pch_gbe_hw *hw);
36+
int pch_gbe_phy_disable_hibernate(struct pch_gbe_hw *hw);
3637

3738
#endif /* _PCH_GBE_PHY_H_ */

0 commit comments

Comments
 (0)