18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * drivers/net/phy/cicada.c 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Driver for Cicada PHYs 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Author: Andy Fleming 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Copyright (c) 2004 Freescale Semiconductor, Inc. 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci#include <linux/kernel.h> 128c2ecf20Sopenharmony_ci#include <linux/string.h> 138c2ecf20Sopenharmony_ci#include <linux/errno.h> 148c2ecf20Sopenharmony_ci#include <linux/unistd.h> 158c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 168c2ecf20Sopenharmony_ci#include <linux/init.h> 178c2ecf20Sopenharmony_ci#include <linux/delay.h> 188c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 198c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 208c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 218c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 228c2ecf20Sopenharmony_ci#include <linux/mm.h> 238c2ecf20Sopenharmony_ci#include <linux/module.h> 248c2ecf20Sopenharmony_ci#include <linux/mii.h> 258c2ecf20Sopenharmony_ci#include <linux/ethtool.h> 268c2ecf20Sopenharmony_ci#include <linux/phy.h> 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include <linux/io.h> 298c2ecf20Sopenharmony_ci#include <asm/irq.h> 308c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/* Cicada Extended Control Register 1 */ 338c2ecf20Sopenharmony_ci#define MII_CIS8201_EXT_CON1 0x17 348c2ecf20Sopenharmony_ci#define MII_CIS8201_EXTCON1_INIT 0x0000 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci/* Cicada Interrupt Mask Register */ 378c2ecf20Sopenharmony_ci#define MII_CIS8201_IMASK 0x19 388c2ecf20Sopenharmony_ci#define MII_CIS8201_IMASK_IEN 0x8000 398c2ecf20Sopenharmony_ci#define MII_CIS8201_IMASK_SPEED 0x4000 408c2ecf20Sopenharmony_ci#define MII_CIS8201_IMASK_LINK 0x2000 418c2ecf20Sopenharmony_ci#define MII_CIS8201_IMASK_DUPLEX 0x1000 428c2ecf20Sopenharmony_ci#define MII_CIS8201_IMASK_MASK 0xf000 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* Cicada Interrupt Status Register */ 458c2ecf20Sopenharmony_ci#define MII_CIS8201_ISTAT 0x1a 468c2ecf20Sopenharmony_ci#define MII_CIS8201_ISTAT_STATUS 0x8000 478c2ecf20Sopenharmony_ci#define MII_CIS8201_ISTAT_SPEED 0x4000 488c2ecf20Sopenharmony_ci#define MII_CIS8201_ISTAT_LINK 0x2000 498c2ecf20Sopenharmony_ci#define MII_CIS8201_ISTAT_DUPLEX 0x1000 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/* Cicada Auxiliary Control/Status Register */ 528c2ecf20Sopenharmony_ci#define MII_CIS8201_AUX_CONSTAT 0x1c 538c2ecf20Sopenharmony_ci#define MII_CIS8201_AUXCONSTAT_INIT 0x0004 548c2ecf20Sopenharmony_ci#define MII_CIS8201_AUXCONSTAT_DUPLEX 0x0020 558c2ecf20Sopenharmony_ci#define MII_CIS8201_AUXCONSTAT_SPEED 0x0018 568c2ecf20Sopenharmony_ci#define MII_CIS8201_AUXCONSTAT_GBIT 0x0010 578c2ecf20Sopenharmony_ci#define MII_CIS8201_AUXCONSTAT_100 0x0008 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Cicadia PHY driver"); 608c2ecf20Sopenharmony_ciMODULE_AUTHOR("Andy Fleming"); 618c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistatic int cis820x_config_init(struct phy_device *phydev) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci int err; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci err = phy_write(phydev, MII_CIS8201_AUX_CONSTAT, 688c2ecf20Sopenharmony_ci MII_CIS8201_AUXCONSTAT_INIT); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci if (err < 0) 718c2ecf20Sopenharmony_ci return err; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci err = phy_write(phydev, MII_CIS8201_EXT_CON1, 748c2ecf20Sopenharmony_ci MII_CIS8201_EXTCON1_INIT); 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci return err; 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic int cis820x_ack_interrupt(struct phy_device *phydev) 808c2ecf20Sopenharmony_ci{ 818c2ecf20Sopenharmony_ci int err = phy_read(phydev, MII_CIS8201_ISTAT); 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci return (err < 0) ? err : 0; 848c2ecf20Sopenharmony_ci} 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cistatic int cis820x_config_intr(struct phy_device *phydev) 878c2ecf20Sopenharmony_ci{ 888c2ecf20Sopenharmony_ci int err; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci if (phydev->interrupts == PHY_INTERRUPT_ENABLED) 918c2ecf20Sopenharmony_ci err = phy_write(phydev, MII_CIS8201_IMASK, 928c2ecf20Sopenharmony_ci MII_CIS8201_IMASK_MASK); 938c2ecf20Sopenharmony_ci else 948c2ecf20Sopenharmony_ci err = phy_write(phydev, MII_CIS8201_IMASK, 0); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci return err; 978c2ecf20Sopenharmony_ci} 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* Cicada 8201, a.k.a Vitesse VSC8201 */ 1008c2ecf20Sopenharmony_cistatic struct phy_driver cis820x_driver[] = { 1018c2ecf20Sopenharmony_ci{ 1028c2ecf20Sopenharmony_ci .phy_id = 0x000fc410, 1038c2ecf20Sopenharmony_ci .name = "Cicada Cis8201", 1048c2ecf20Sopenharmony_ci .phy_id_mask = 0x000ffff0, 1058c2ecf20Sopenharmony_ci /* PHY_GBIT_FEATURES */ 1068c2ecf20Sopenharmony_ci .config_init = &cis820x_config_init, 1078c2ecf20Sopenharmony_ci .ack_interrupt = &cis820x_ack_interrupt, 1088c2ecf20Sopenharmony_ci .config_intr = &cis820x_config_intr, 1098c2ecf20Sopenharmony_ci}, { 1108c2ecf20Sopenharmony_ci .phy_id = 0x000fc440, 1118c2ecf20Sopenharmony_ci .name = "Cicada Cis8204", 1128c2ecf20Sopenharmony_ci .phy_id_mask = 0x000fffc0, 1138c2ecf20Sopenharmony_ci /* PHY_GBIT_FEATURES */ 1148c2ecf20Sopenharmony_ci .config_init = &cis820x_config_init, 1158c2ecf20Sopenharmony_ci .ack_interrupt = &cis820x_ack_interrupt, 1168c2ecf20Sopenharmony_ci .config_intr = &cis820x_config_intr, 1178c2ecf20Sopenharmony_ci} }; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cimodule_phy_driver(cis820x_driver); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cistatic struct mdio_device_id __maybe_unused cicada_tbl[] = { 1228c2ecf20Sopenharmony_ci { 0x000fc410, 0x000ffff0 }, 1238c2ecf20Sopenharmony_ci { 0x000fc440, 0x000fffc0 }, 1248c2ecf20Sopenharmony_ci { } 1258c2ecf20Sopenharmony_ci}; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(mdio, cicada_tbl); 128