blob: 07110c630ebedc8960b55857944419acf1d845f1 [file] [log] [blame]
Mario Scheithauerd4ab2ee2022-11-04 10:23:43 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2
Mario Scheithauer1a97c892022-11-08 13:50:06 +01003#include <console/console.h>
Mario Scheithauerd4ab2ee2022-11-04 10:23:43 +01004#include <device/device.h>
Mario Scheithauer1a97c892022-11-08 13:50:06 +01005#include <device/mdio.h>
6#include <device/pci.h>
7#include "chip.h"
8#include "m88e1512.h"
9
10static void switch_page(struct device *dev, uint8_t page)
11{
12 mdio_write(dev, PAGE_REG, page);
13}
Mario Scheithauerd4ab2ee2022-11-04 10:23:43 +010014
15static void m88e1512_init(struct device *dev)
16{
Mario Scheithauer1a97c892022-11-08 13:50:06 +010017 struct drivers_net_phy_m88e1512_config *config = dev->chip_info;
18 uint16_t reg;
19
Mario Scheithauer16dd1c32022-11-21 16:22:03 +010020 /* Enable downshift. */
21 if (config->downshift_cnt) {
22 if (config->downshift_cnt > DOWNSHIFT_CNT_MAX) {
23 printk(BIOS_INFO, "%s: Downshift counter for %s is too large.\n",
24 dev_path(dev->bus->dev), dev->chip_ops->name);
25 } else {
26 printk(BIOS_DEBUG, "%s: Enable downshift after %d attempts for %s.\n",
27 dev_path(dev->bus->dev), config->downshift_cnt,
28 dev->chip_ops->name);
29
30 reg = mdio_read(dev, COPPER_SPEC_CTRL_REG_1);
31 clrsetbits16(&reg, DOWNSHIFT_CNT_MASK,
32 DOWNSHIFT_CNT(config->downshift_cnt) | DOWNSHIFT_EN);
33 mdio_write(dev, COPPER_SPEC_CTRL_REG_1, reg);
34
35 /* Downshift enable requires a software reset to take effect. */
36 reg = mdio_read(dev, COPPER_CTRL_REG);
37 setbits16(&reg, SOFTWARE_RESET);
38 mdio_write(dev, COPPER_CTRL_REG, reg);
39 }
40 }
41
Mario Scheithauer1a97c892022-11-08 13:50:06 +010042 /* Configure LEDs if requested. */
43 if (config->configure_leds) {
44 printk(BIOS_DEBUG, "%s: Set a customized LED mode for %s.\n",
45 dev_path(dev->bus->dev), dev->chip_ops->name);
46
47 /* Select page 3 to access LED function control register. */
48 switch_page(dev, 3);
49
50 /* Modify PHY LED mode. */
51 reg = mdio_read(dev, LED_FUNC_CTRL_REG);
52 clrsetbits16(&reg, LED_FUNC_CTRL_MASK, config->led_0_ctrl |
53 (config->led_1_ctrl << 4) | (config->led_2_ctrl << 8));
54 mdio_write(dev, LED_FUNC_CTRL_REG, reg);
Mario Scheithauer1a97c892022-11-08 13:50:06 +010055 }
Mario Scheithauer155cf5c2022-11-10 09:34:57 +010056
57 /* INTn can be routed to LED[2] pin. */
58 if (config->enable_int) {
59 printk(BIOS_DEBUG, "%s: INTn is routed to LED[2] pin %s.\n",
60 dev_path(dev->bus->dev), dev->chip_ops->name);
61
62 /* Select page 3 to access LED function control register. */
63 switch_page(dev, 3);
64
65 reg = mdio_read(dev, LED_TIMER_CTRL_REG);
66 setbits16(&reg, LED_IRQ_ENABLE);
67 mdio_write(dev, LED_TIMER_CTRL_REG, reg);
Mario Scheithauer155cf5c2022-11-10 09:34:57 +010068 }
Mario Scheithauer33ef5c42023-01-25 10:19:51 +010069
Mario Scheithauer481bfe62023-01-25 11:43:51 +010070 /* Set RGMII output impedance manually. */
71 if (config->force_mos) {
72 printk(BIOS_DEBUG, "%s: Set RGMII driver strength manually for %s.\n",
73 dev_path(dev->bus->dev), dev->chip_ops->name);
74
75 /* Select page 2 to access RGMII output impedance calibration override
76 register. */
77 switch_page(dev, 2);
78
79 reg = mdio_read(dev, OUT_IMP_CAL_OVERRIDE_REG);
80 /* Set first only NMOS/PMOS values. */
81 clrsetbits16(&reg, MOS_VALUE_MASK, PMOS_VALUE(config->pmos_val) |
82 NMOS_VALUE(config->nmos_val));
83 mdio_write(dev, OUT_IMP_CAL_OVERRIDE_REG, reg);
84 /* Activate the new setting. */
85 setbits16(&reg, FORCE_MOS);
86 mdio_write(dev, OUT_IMP_CAL_OVERRIDE_REG, reg);
87 }
88
Mario Scheithauer33ef5c42023-01-25 10:19:51 +010089 /* Switch back to page 0. */
90 switch_page(dev, 0);
Mario Scheithauerd4ab2ee2022-11-04 10:23:43 +010091}
92
93struct device_operations m88e1512_ops = {
94 .read_resources = noop_read_resources,
95 .set_resources = noop_set_resources,
96 .init = m88e1512_init,
97};
98
99struct chip_operations drivers_net_phy_m88e1512_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900100 .name = "88E1512",
Mario Scheithauerd4ab2ee2022-11-04 10:23:43 +0100101};