Linux Audio

Check our new training course

Loading...
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 *	Driver for Broadcom 63xx SOCs integrated PHYs
 
 
 
 
 
  4 */
  5#include "bcm-phy-lib.h"
  6#include <linux/module.h>
  7#include <linux/phy.h>
  8
  9#define MII_BCM63XX_IR		0x1a	/* interrupt register */
 10#define MII_BCM63XX_IR_EN	0x4000	/* global interrupt enable */
 11#define MII_BCM63XX_IR_DUPLEX	0x0800	/* duplex changed */
 12#define MII_BCM63XX_IR_SPEED	0x0400	/* speed changed */
 13#define MII_BCM63XX_IR_LINK	0x0200	/* link changed */
 14#define MII_BCM63XX_IR_GMASK	0x0100	/* global interrupt mask */
 15
 16MODULE_DESCRIPTION("Broadcom 63xx internal PHY driver");
 17MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>");
 18MODULE_LICENSE("GPL");
 19
 20static int bcm63xx_config_intr(struct phy_device *phydev)
 21{
 22	int reg, err;
 23
 24	reg = phy_read(phydev, MII_BCM63XX_IR);
 25	if (reg < 0)
 26		return reg;
 27
 28	if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
 29		err = bcm_phy_ack_intr(phydev);
 30		if (err)
 31			return err;
 32
 33		reg &= ~MII_BCM63XX_IR_GMASK;
 34		err = phy_write(phydev, MII_BCM63XX_IR, reg);
 35	} else {
 36		reg |= MII_BCM63XX_IR_GMASK;
 37		err = phy_write(phydev, MII_BCM63XX_IR, reg);
 38		if (err)
 39			return err;
 40
 41		err = bcm_phy_ack_intr(phydev);
 42	}
 43
 44	return err;
 45}
 46
 47static int bcm63xx_config_init(struct phy_device *phydev)
 48{
 49	int reg, err;
 50
 51	/* ASYM_PAUSE bit is marked RO in datasheet, so don't cheat */
 52	linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported);
 53
 54	reg = phy_read(phydev, MII_BCM63XX_IR);
 55	if (reg < 0)
 56		return reg;
 57
 58	/* Mask interrupts globally.  */
 59	reg |= MII_BCM63XX_IR_GMASK;
 60	err = phy_write(phydev, MII_BCM63XX_IR, reg);
 61	if (err < 0)
 62		return err;
 63
 64	/* Unmask events we are interested in  */
 65	reg = ~(MII_BCM63XX_IR_DUPLEX |
 66		MII_BCM63XX_IR_SPEED |
 67		MII_BCM63XX_IR_LINK) |
 68		MII_BCM63XX_IR_EN;
 69	return phy_write(phydev, MII_BCM63XX_IR, reg);
 70}
 71
 72static struct phy_driver bcm63xx_driver[] = {
 73{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 74	.phy_id		= 0x00406000,
 75	.phy_id_mask	= 0xfffffc00,
 76	.name		= "Broadcom BCM63XX (1)",
 77	/* PHY_BASIC_FEATURES */
 78	.flags		= PHY_IS_INTERNAL,
 
 79	.config_init	= bcm63xx_config_init,
 
 
 
 80	.config_intr	= bcm63xx_config_intr,
 81	.handle_interrupt = bcm_phy_handle_interrupt,
 82}, {
 83	/* same phy as above, with just a different OUI */
 
 
 84	.phy_id		= 0x002bdc00,
 85	.phy_id_mask	= 0xfffffc00,
 86	.name		= "Broadcom BCM63XX (2)",
 87	/* PHY_BASIC_FEATURES */
 88	.flags		= PHY_IS_INTERNAL,
 89	.config_init	= bcm63xx_config_init,
 
 
 
 90	.config_intr	= bcm63xx_config_intr,
 91	.handle_interrupt = bcm_phy_handle_interrupt,
 92} };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 93
 94module_phy_driver(bcm63xx_driver);
 
 95
 96static struct mdio_device_id __maybe_unused bcm63xx_tbl[] = {
 97	{ 0x00406000, 0xfffffc00 },
 98	{ 0x002bdc00, 0xfffffc00 },
 99	{ }
100};
101
102MODULE_DEVICE_TABLE(mdio, bcm63xx_tbl);
v3.5.6
 
  1/*
  2 *	Driver for Broadcom 63xx SOCs integrated PHYs
  3 *
  4 *	This program is free software; you can redistribute it and/or
  5 *	modify it under the terms of the GNU General Public License
  6 *	as published by the Free Software Foundation; either version
  7 *	2 of the License, or (at your option) any later version.
  8 */
 
  9#include <linux/module.h>
 10#include <linux/phy.h>
 11
 12#define MII_BCM63XX_IR		0x1a	/* interrupt register */
 13#define MII_BCM63XX_IR_EN	0x4000	/* global interrupt enable */
 14#define MII_BCM63XX_IR_DUPLEX	0x0800	/* duplex changed */
 15#define MII_BCM63XX_IR_SPEED	0x0400	/* speed changed */
 16#define MII_BCM63XX_IR_LINK	0x0200	/* link changed */
 17#define MII_BCM63XX_IR_GMASK	0x0100	/* global interrupt mask */
 18
 19MODULE_DESCRIPTION("Broadcom 63xx internal PHY driver");
 20MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>");
 21MODULE_LICENSE("GPL");
 22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 23static int bcm63xx_config_init(struct phy_device *phydev)
 24{
 25	int reg, err;
 26
 
 
 
 27	reg = phy_read(phydev, MII_BCM63XX_IR);
 28	if (reg < 0)
 29		return reg;
 30
 31	/* Mask interrupts globally.  */
 32	reg |= MII_BCM63XX_IR_GMASK;
 33	err = phy_write(phydev, MII_BCM63XX_IR, reg);
 34	if (err < 0)
 35		return err;
 36
 37	/* Unmask events we are interested in  */
 38	reg = ~(MII_BCM63XX_IR_DUPLEX |
 39		MII_BCM63XX_IR_SPEED |
 40		MII_BCM63XX_IR_LINK) |
 41		MII_BCM63XX_IR_EN;
 42	return phy_write(phydev, MII_BCM63XX_IR, reg);
 43}
 44
 45static int bcm63xx_ack_interrupt(struct phy_device *phydev)
 46{
 47	int reg;
 48
 49	/* Clear pending interrupts.  */
 50	reg = phy_read(phydev, MII_BCM63XX_IR);
 51	if (reg < 0)
 52		return reg;
 53
 54	return 0;
 55}
 56
 57static int bcm63xx_config_intr(struct phy_device *phydev)
 58{
 59	int reg, err;
 60
 61	reg = phy_read(phydev, MII_BCM63XX_IR);
 62	if (reg < 0)
 63		return reg;
 64
 65	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
 66		reg &= ~MII_BCM63XX_IR_GMASK;
 67	else
 68		reg |= MII_BCM63XX_IR_GMASK;
 69
 70	err = phy_write(phydev, MII_BCM63XX_IR, reg);
 71	return err;
 72}
 73
 74static struct phy_driver bcm63xx_1_driver = {
 75	.phy_id		= 0x00406000,
 76	.phy_id_mask	= 0xfffffc00,
 77	.name		= "Broadcom BCM63XX (1)",
 78	/* ASYM_PAUSE bit is marked RO in datasheet, so don't cheat */
 79	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause),
 80	.flags		= PHY_HAS_INTERRUPT,
 81	.config_init	= bcm63xx_config_init,
 82	.config_aneg	= genphy_config_aneg,
 83	.read_status	= genphy_read_status,
 84	.ack_interrupt	= bcm63xx_ack_interrupt,
 85	.config_intr	= bcm63xx_config_intr,
 86	.driver		= { .owner = THIS_MODULE },
 87};
 88
 89/* same phy as above, with just a different OUI */
 90static struct phy_driver bcm63xx_2_driver = {
 91	.phy_id		= 0x002bdc00,
 92	.phy_id_mask	= 0xfffffc00,
 93	.name		= "Broadcom BCM63XX (2)",
 94	.features	= (PHY_BASIC_FEATURES | SUPPORTED_Pause),
 95	.flags		= PHY_HAS_INTERRUPT,
 96	.config_init	= bcm63xx_config_init,
 97	.config_aneg	= genphy_config_aneg,
 98	.read_status	= genphy_read_status,
 99	.ack_interrupt	= bcm63xx_ack_interrupt,
100	.config_intr	= bcm63xx_config_intr,
101	.driver		= { .owner = THIS_MODULE },
102};
103
104static int __init bcm63xx_phy_init(void)
105{
106	int ret;
107
108	ret = phy_driver_register(&bcm63xx_1_driver);
109	if (ret)
110		goto out_63xx_1;
111	ret = phy_driver_register(&bcm63xx_2_driver);
112	if (ret)
113		goto out_63xx_2;
114	return ret;
115
116out_63xx_2:
117	phy_driver_unregister(&bcm63xx_1_driver);
118out_63xx_1:
119	return ret;
120}
121
122static void __exit bcm63xx_phy_exit(void)
123{
124	phy_driver_unregister(&bcm63xx_1_driver);
125	phy_driver_unregister(&bcm63xx_2_driver);
126}
127
128module_init(bcm63xx_phy_init);
129module_exit(bcm63xx_phy_exit);
130
131static struct mdio_device_id __maybe_unused bcm63xx_tbl[] = {
132	{ 0x00406000, 0xfffffc00 },
133	{ 0x002bdc00, 0xfffffc00 },
134	{ }
135};
136
137MODULE_DEVICE_TABLE(mdio, bcm63xx_tbl);