cregit-Linux how code gets into the kernel

Release 4.11 drivers/net/ethernet/ti/netcp_sgmii.c

/*
 * SGMI module initialisation
 *
 * Copyright (C) 2014 Texas Instruments Incorporated
 * Authors:     Sandeep Nair <sandeep_n@ti.com>
 *              Sandeep Paulraj <s-paulraj@ti.com>
 *              Wingman Kwok <w-kwok2@ti.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation version 2.
 *
 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
 * kind, whether express or implied; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include "netcp.h"


#define SGMII_SRESET_RESET		BIT(0)

#define SGMII_SRESET_RTRESET		BIT(1)


#define SGMII_REG_STATUS_LOCK		BIT(4)

#define	SGMII_REG_STATUS_LINK		BIT(0)

#define SGMII_REG_STATUS_AUTONEG	BIT(2)

#define SGMII_REG_CONTROL_AUTONEG	BIT(0)


#define SGMII23_OFFSET(x)	((x - 2) * 0x100)

#define SGMII_OFFSET(x)		((x <= 1) ? (x * 0x100) : (SGMII23_OFFSET(x)))

/* SGMII registers */

#define SGMII_SRESET_REG(x)   (SGMII_OFFSET(x) + 0x004)

#define SGMII_CTL_REG(x)      (SGMII_OFFSET(x) + 0x010)

#define SGMII_STATUS_REG(x)   (SGMII_OFFSET(x) + 0x014)

#define SGMII_MRADV_REG(x)    (SGMII_OFFSET(x) + 0x018)


static void sgmii_write_reg(void __iomem *base, int reg, u32 val) { writel(val, base + reg); }

Contributors

PersonTokensPropCommitsCommitProp
WingMan Kwok26100.00%1100.00%
Total26100.00%1100.00%


static u32 sgmii_read_reg(void __iomem *base, int reg) { return readl(base + reg); }

Contributors

PersonTokensPropCommitsCommitProp
WingMan Kwok22100.00%1100.00%
Total22100.00%1100.00%


static void sgmii_write_reg_bit(void __iomem *base, int reg, u32 val) { writel((readl(base + reg) | val), base + reg); }

Contributors

PersonTokensPropCommitsCommitProp
WingMan Kwok35100.00%1100.00%
Total35100.00%1100.00%

/* port is 0 based */
int netcp_sgmii_reset(void __iomem *sgmii_ofs, int port) { /* Soft reset */ sgmii_write_reg_bit(sgmii_ofs, SGMII_SRESET_REG(port), SGMII_SRESET_RESET); while ((sgmii_read_reg(sgmii_ofs, SGMII_SRESET_REG(port)) & SGMII_SRESET_RESET) != 0x0) ; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
WingMan Kwok48100.00%2100.00%
Total48100.00%2100.00%

/* port is 0 based */
bool netcp_sgmii_rtreset(void __iomem *sgmii_ofs, int port, bool set) { u32 reg; bool oldval; /* Initiate a soft reset */ reg = sgmii_read_reg(sgmii_ofs, SGMII_SRESET_REG(port)); oldval = (reg & SGMII_SRESET_RTRESET) != 0x0; if (set) reg |= SGMII_SRESET_RTRESET; else reg &= ~SGMII_SRESET_RTRESET; sgmii_write_reg(sgmii_ofs, SGMII_SRESET_REG(port), reg); wmb(); return oldval; }

Contributors

PersonTokensPropCommitsCommitProp
WingMan Kwok77100.00%1100.00%
Total77100.00%1100.00%


int netcp_sgmii_get_port_link(void __iomem *sgmii_ofs, int port) { u32 status = 0, link = 0; status = sgmii_read_reg(sgmii_ofs, SGMII_STATUS_REG(port)); if ((status & SGMII_REG_STATUS_LINK) != 0) link = 1; return link; }

Contributors

PersonTokensPropCommitsCommitProp
WingMan Kwok51100.00%1100.00%
Total51100.00%1100.00%


int netcp_sgmii_config(void __iomem *sgmii_ofs, int port, u32 interface) { unsigned int i, status, mask; u32 mr_adv_ability; u32 control; switch (interface) { case SGMII_LINK_MAC_MAC_AUTONEG: mr_adv_ability = 0x9801; control = 0x21; break; case SGMII_LINK_MAC_PHY: case SGMII_LINK_MAC_PHY_NO_MDIO: mr_adv_ability = 1; control = 1; break; case SGMII_LINK_MAC_MAC_FORCED: mr_adv_ability = 0x9801; control = 0x20; break; case SGMII_LINK_MAC_FIBER: mr_adv_ability = 0x20; control = 0x1; break; default: WARN_ONCE(1, "Invalid sgmii interface: %d\n", interface); return -EINVAL; } sgmii_write_reg(sgmii_ofs, SGMII_CTL_REG(port), 0); /* Wait for the SerDes pll to lock */ for (i = 0; i < 1000; i++) { usleep_range(1000, 2000); status = sgmii_read_reg(sgmii_ofs, SGMII_STATUS_REG(port)); if ((status & SGMII_REG_STATUS_LOCK) != 0) break; } if ((status & SGMII_REG_STATUS_LOCK) == 0) pr_err("serdes PLL not locked\n"); sgmii_write_reg(sgmii_ofs, SGMII_MRADV_REG(port), mr_adv_ability); sgmii_write_reg(sgmii_ofs, SGMII_CTL_REG(port), control); mask = SGMII_REG_STATUS_LINK; if (control & SGMII_REG_CONTROL_AUTONEG) mask |= SGMII_REG_STATUS_AUTONEG; for (i = 0; i < 1000; i++) { usleep_range(200, 500); status = sgmii_read_reg(sgmii_ofs, SGMII_STATUS_REG(port)); if ((status & mask) == mask) break; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
WingMan Kwok260100.00%1100.00%
Total260100.00%1100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
WingMan Kwok592100.00%2100.00%
Total592100.00%2100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.