18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * drivers/net/phy/qsemi.c
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Driver for Quality Semiconductor 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 <asm/io.h>
298c2ecf20Sopenharmony_ci#include <asm/irq.h>
308c2ecf20Sopenharmony_ci#include <linux/uaccess.h>
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/* ------------------------------------------------------------------------- */
338c2ecf20Sopenharmony_ci/* The Quality Semiconductor QS6612 is used on the RPX CLLF                  */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* register definitions */
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define MII_QS6612_MCR		17  /* Mode Control Register      */
388c2ecf20Sopenharmony_ci#define MII_QS6612_FTR		27  /* Factory Test Register      */
398c2ecf20Sopenharmony_ci#define MII_QS6612_MCO		28  /* Misc. Control Register     */
408c2ecf20Sopenharmony_ci#define MII_QS6612_ISR		29  /* Interrupt Source Register  */
418c2ecf20Sopenharmony_ci#define MII_QS6612_IMR		30  /* Interrupt Mask Register    */
428c2ecf20Sopenharmony_ci#define MII_QS6612_IMR_INIT	0x003a
438c2ecf20Sopenharmony_ci#define MII_QS6612_PCR		31  /* 100BaseTx PHY Control Reg. */
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define QS6612_PCR_AN_COMPLETE	0x1000
468c2ecf20Sopenharmony_ci#define QS6612_PCR_RLBEN	0x0200
478c2ecf20Sopenharmony_ci#define QS6612_PCR_DCREN	0x0100
488c2ecf20Sopenharmony_ci#define QS6612_PCR_4B5BEN	0x0040
498c2ecf20Sopenharmony_ci#define QS6612_PCR_TX_ISOLATE	0x0020
508c2ecf20Sopenharmony_ci#define QS6612_PCR_MLT3_DIS	0x0002
518c2ecf20Sopenharmony_ci#define QS6612_PCR_SCRM_DESCRM	0x0001
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Quality Semiconductor PHY driver");
548c2ecf20Sopenharmony_ciMODULE_AUTHOR("Andy Fleming");
558c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* Returns 0, unless there's a write error */
588c2ecf20Sopenharmony_cistatic int qs6612_config_init(struct phy_device *phydev)
598c2ecf20Sopenharmony_ci{
608c2ecf20Sopenharmony_ci	/* The PHY powers up isolated on the RPX,
618c2ecf20Sopenharmony_ci	 * so send a command to allow operation.
628c2ecf20Sopenharmony_ci	 * XXX - My docs indicate this should be 0x0940
638c2ecf20Sopenharmony_ci	 * ...or something.  The current value sets three
648c2ecf20Sopenharmony_ci	 * reserved bits, bit 11, which specifies it should be
658c2ecf20Sopenharmony_ci	 * set to one, bit 10, which specifies it should be set
668c2ecf20Sopenharmony_ci	 * to 0, and bit 7, which doesn't specify.  However, my
678c2ecf20Sopenharmony_ci	 * docs are preliminary, and I will leave it like this
688c2ecf20Sopenharmony_ci	 * until someone more knowledgable corrects me or it.
698c2ecf20Sopenharmony_ci	 * -- Andy Fleming
708c2ecf20Sopenharmony_ci	 */
718c2ecf20Sopenharmony_ci	return phy_write(phydev, MII_QS6612_PCR, 0x0dc0);
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistatic int qs6612_ack_interrupt(struct phy_device *phydev)
758c2ecf20Sopenharmony_ci{
768c2ecf20Sopenharmony_ci	int err;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	err = phy_read(phydev, MII_QS6612_ISR);
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	if (err < 0)
818c2ecf20Sopenharmony_ci		return err;
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	err = phy_read(phydev, MII_BMSR);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	if (err < 0)
868c2ecf20Sopenharmony_ci		return err;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	err = phy_read(phydev, MII_EXPANSION);
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	if (err < 0)
918c2ecf20Sopenharmony_ci		return err;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	return 0;
948c2ecf20Sopenharmony_ci}
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cistatic int qs6612_config_intr(struct phy_device *phydev)
978c2ecf20Sopenharmony_ci{
988c2ecf20Sopenharmony_ci	int err;
998c2ecf20Sopenharmony_ci	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
1008c2ecf20Sopenharmony_ci		err = phy_write(phydev, MII_QS6612_IMR,
1018c2ecf20Sopenharmony_ci				MII_QS6612_IMR_INIT);
1028c2ecf20Sopenharmony_ci	else
1038c2ecf20Sopenharmony_ci		err = phy_write(phydev, MII_QS6612_IMR, 0);
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	return err;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistatic struct phy_driver qs6612_driver[] = { {
1108c2ecf20Sopenharmony_ci	.phy_id		= 0x00181440,
1118c2ecf20Sopenharmony_ci	.name		= "QS6612",
1128c2ecf20Sopenharmony_ci	.phy_id_mask	= 0xfffffff0,
1138c2ecf20Sopenharmony_ci	/* PHY_BASIC_FEATURES */
1148c2ecf20Sopenharmony_ci	.config_init	= qs6612_config_init,
1158c2ecf20Sopenharmony_ci	.ack_interrupt	= qs6612_ack_interrupt,
1168c2ecf20Sopenharmony_ci	.config_intr	= qs6612_config_intr,
1178c2ecf20Sopenharmony_ci} };
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cimodule_phy_driver(qs6612_driver);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistatic struct mdio_device_id __maybe_unused qs6612_tbl[] = {
1228c2ecf20Sopenharmony_ci	{ 0x00181440, 0xfffffff0 },
1238c2ecf20Sopenharmony_ci	{ }
1248c2ecf20Sopenharmony_ci};
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(mdio, qs6612_tbl);
127