Skip to content

Commit 10fa5bf

Browse files
lunndavem330
authored andcommitted
net: dsa: mv88e6xxx: Move phy functions into phy.[ch]
The upcoming SERDES support will need to make use of PHY functions. Move them out into a file of there own. No code changes. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 03d1da3 commit 10fa5bf

File tree

5 files changed

+287
-232
lines changed

5 files changed

+287
-232
lines changed

drivers/net/dsa/mv88e6xxx/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ mv88e6xxx-objs += global1.o
44
mv88e6xxx-objs += global1_atu.o
55
mv88e6xxx-objs += global1_vtu.o
66
mv88e6xxx-$(CONFIG_NET_DSA_MV88E6XXX_GLOBAL2) += global2.o
7+
mv88e6xxx-objs += phy.o
78
mv88e6xxx-objs += port.o

drivers/net/dsa/mv88e6xxx/chip.c

Lines changed: 2 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "mv88e6xxx.h"
3737
#include "global1.h"
3838
#include "global2.h"
39+
#include "phy.h"
3940
#include "port.h"
4041

4142
static void assert_reg_lock(struct mv88e6xxx_chip *chip)
@@ -221,21 +222,7 @@ int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
221222
return 0;
222223
}
223224

224-
static int mv88e6165_phy_read(struct mv88e6xxx_chip *chip,
225-
struct mii_bus *bus,
226-
int addr, int reg, u16 *val)
227-
{
228-
return mv88e6xxx_read(chip, addr, reg, val);
229-
}
230-
231-
static int mv88e6165_phy_write(struct mv88e6xxx_chip *chip,
232-
struct mii_bus *bus,
233-
int addr, int reg, u16 val)
234-
{
235-
return mv88e6xxx_write(chip, addr, reg, val);
236-
}
237-
238-
static struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
225+
struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
239226
{
240227
struct mv88e6xxx_mdio_bus *mdio_bus;
241228

@@ -247,94 +234,6 @@ static struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
247234
return mdio_bus->bus;
248235
}
249236

250-
static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
251-
int reg, u16 *val)
252-
{
253-
int addr = phy; /* PHY devices addresses start at 0x0 */
254-
struct mii_bus *bus;
255-
256-
bus = mv88e6xxx_default_mdio_bus(chip);
257-
if (!bus)
258-
return -EOPNOTSUPP;
259-
260-
if (!chip->info->ops->phy_read)
261-
return -EOPNOTSUPP;
262-
263-
return chip->info->ops->phy_read(chip, bus, addr, reg, val);
264-
}
265-
266-
static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
267-
int reg, u16 val)
268-
{
269-
int addr = phy; /* PHY devices addresses start at 0x0 */
270-
struct mii_bus *bus;
271-
272-
bus = mv88e6xxx_default_mdio_bus(chip);
273-
if (!bus)
274-
return -EOPNOTSUPP;
275-
276-
if (!chip->info->ops->phy_write)
277-
return -EOPNOTSUPP;
278-
279-
return chip->info->ops->phy_write(chip, bus, addr, reg, val);
280-
}
281-
282-
static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
283-
{
284-
if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_PHY_PAGE))
285-
return -EOPNOTSUPP;
286-
287-
return mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
288-
}
289-
290-
static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip *chip, int phy)
291-
{
292-
int err;
293-
294-
/* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
295-
err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, PHY_PAGE_COPPER);
296-
if (unlikely(err)) {
297-
dev_err(chip->dev, "failed to restore PHY %d page Copper (%d)\n",
298-
phy, err);
299-
}
300-
}
301-
302-
static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy,
303-
u8 page, int reg, u16 *val)
304-
{
305-
int err;
306-
307-
/* There is no paging for registers 22 */
308-
if (reg == PHY_PAGE)
309-
return -EINVAL;
310-
311-
err = mv88e6xxx_phy_page_get(chip, phy, page);
312-
if (!err) {
313-
err = mv88e6xxx_phy_read(chip, phy, reg, val);
314-
mv88e6xxx_phy_page_put(chip, phy);
315-
}
316-
317-
return err;
318-
}
319-
320-
static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy,
321-
u8 page, int reg, u16 val)
322-
{
323-
int err;
324-
325-
/* There is no paging for registers 22 */
326-
if (reg == PHY_PAGE)
327-
return -EINVAL;
328-
329-
err = mv88e6xxx_phy_page_get(chip, phy, page);
330-
if (!err) {
331-
err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
332-
mv88e6xxx_phy_page_put(chip, phy);
333-
}
334-
335-
return err;
336-
}
337-
338237
static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
339238
{
340239
return mv88e6xxx_phy_page_read(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
@@ -560,122 +459,6 @@ int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
560459
return mv88e6xxx_write(chip, addr, reg, val);
561460
}
562461

563-
static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
564-
{
565-
if (!chip->info->ops->ppu_disable)
566-
return 0;
567-
568-
return chip->info->ops->ppu_disable(chip);
569-
}
570-
571-
static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
572-
{
573-
if (!chip->info->ops->ppu_enable)
574-
return 0;
575-
576-
return chip->info->ops->ppu_enable(chip);
577-
}
578-
579-
static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
580-
{
581-
struct mv88e6xxx_chip *chip;
582-
583-
chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
584-
585-
mutex_lock(&chip->reg_lock);
586-
587-
if (mutex_trylock(&chip->ppu_mutex)) {
588-
if (mv88e6xxx_ppu_enable(chip) == 0)
589-
chip->ppu_disabled = 0;
590-
mutex_unlock(&chip->ppu_mutex);
591-
}
592-
593-
mutex_unlock(&chip->reg_lock);
594-
}
595-
596-
static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
597-
{
598-
struct mv88e6xxx_chip *chip = (void *)_ps;
599-
600-
schedule_work(&chip->ppu_work);
601-
}
602-
603-
static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
604-
{
605-
int ret;
606-
607-
mutex_lock(&chip->ppu_mutex);
608-
609-
/* If the PHY polling unit is enabled, disable it so that
610-
* we can access the PHY registers. If it was already
611-
* disabled, cancel the timer that is going to re-enable
612-
* it.
613-
*/
614-
if (!chip->ppu_disabled) {
615-
ret = mv88e6xxx_ppu_disable(chip);
616-
if (ret < 0) {
617-
mutex_unlock(&chip->ppu_mutex);
618-
return ret;
619-
}
620-
chip->ppu_disabled = 1;
621-
} else {
622-
del_timer(&chip->ppu_timer);
623-
ret = 0;
624-
}
625-
626-
return ret;
627-
}
628-
629-
static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
630-
{
631-
/* Schedule a timer to re-enable the PHY polling unit. */
632-
mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
633-
mutex_unlock(&chip->ppu_mutex);
634-
}
635-
636-
static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
637-
{
638-
mutex_init(&chip->ppu_mutex);
639-
INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
640-
setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
641-
(unsigned long)chip);
642-
}
643-
644-
static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
645-
{
646-
del_timer_sync(&chip->ppu_timer);
647-
}
648-
649-
static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip,
650-
struct mii_bus *bus,
651-
int addr, int reg, u16 *val)
652-
{
653-
int err;
654-
655-
err = mv88e6xxx_ppu_access_get(chip);
656-
if (!err) {
657-
err = mv88e6xxx_read(chip, addr, reg, val);
658-
mv88e6xxx_ppu_access_put(chip);
659-
}
660-
661-
return err;
662-
}
663-
664-
static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip,
665-
struct mii_bus *bus,
666-
int addr, int reg, u16 val)
667-
{
668-
int err;
669-
670-
err = mv88e6xxx_ppu_access_get(chip);
671-
if (!err) {
672-
err = mv88e6xxx_write(chip, addr, reg, val);
673-
mv88e6xxx_ppu_access_put(chip);
674-
}
675-
676-
return err;
677-
}
678-
679462
static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
680463
int link, int speed, int duplex,
681464
phy_interface_t mode)
@@ -3914,18 +3697,6 @@ static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
39143697
return chip;
39153698
}
39163699

3917-
static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
3918-
{
3919-
if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
3920-
mv88e6xxx_ppu_state_init(chip);
3921-
}
3922-
3923-
static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
3924-
{
3925-
if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
3926-
mv88e6xxx_ppu_state_destroy(chip);
3927-
}
3928-
39293700
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
39303701
struct mii_bus *bus, int sw_addr)
39313702
{

drivers/net/dsa/mv88e6xxx/mv88e6xxx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,5 +942,5 @@ int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
942942
int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg,
943943
u16 update);
944944
int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask);
945-
945+
struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip);
946946
#endif

0 commit comments

Comments
 (0)