Mario Scheithauer | d4ab2ee | 2022-11-04 10:23:43 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Mario Scheithauer | 1a97c89 | 2022-11-08 13:50:06 +0100 | [diff] [blame] | 3 | #include <console/console.h> |
Mario Scheithauer | d4ab2ee | 2022-11-04 10:23:43 +0100 | [diff] [blame] | 4 | #include <device/device.h> |
Mario Scheithauer | 1a97c89 | 2022-11-08 13:50:06 +0100 | [diff] [blame] | 5 | #include <device/mdio.h> |
| 6 | #include <device/pci.h> |
| 7 | #include "chip.h" |
| 8 | #include "m88e1512.h" |
| 9 | |
| 10 | static void switch_page(struct device *dev, uint8_t page) |
| 11 | { |
| 12 | mdio_write(dev, PAGE_REG, page); |
| 13 | } |
Mario Scheithauer | d4ab2ee | 2022-11-04 10:23:43 +0100 | [diff] [blame] | 14 | |
| 15 | static void m88e1512_init(struct device *dev) |
| 16 | { |
Mario Scheithauer | 1a97c89 | 2022-11-08 13:50:06 +0100 | [diff] [blame] | 17 | struct drivers_net_phy_m88e1512_config *config = dev->chip_info; |
| 18 | uint16_t reg; |
| 19 | |
Mario Scheithauer | 16dd1c3 | 2022-11-21 16:22:03 +0100 | [diff] [blame] | 20 | /* 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(®, 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(®, SOFTWARE_RESET); |
| 38 | mdio_write(dev, COPPER_CTRL_REG, reg); |
| 39 | } |
| 40 | } |
| 41 | |
Mario Scheithauer | 1a97c89 | 2022-11-08 13:50:06 +0100 | [diff] [blame] | 42 | /* 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(®, 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); |
| 55 | |
| 56 | /* Switch back to page 0. */ |
| 57 | switch_page(dev, 0); |
| 58 | } |
Mario Scheithauer | 155cf5c | 2022-11-10 09:34:57 +0100 | [diff] [blame] | 59 | |
| 60 | /* INTn can be routed to LED[2] pin. */ |
| 61 | if (config->enable_int) { |
| 62 | printk(BIOS_DEBUG, "%s: INTn is routed to LED[2] pin %s.\n", |
| 63 | dev_path(dev->bus->dev), dev->chip_ops->name); |
| 64 | |
| 65 | /* Select page 3 to access LED function control register. */ |
| 66 | switch_page(dev, 3); |
| 67 | |
| 68 | reg = mdio_read(dev, LED_TIMER_CTRL_REG); |
| 69 | setbits16(®, LED_IRQ_ENABLE); |
| 70 | mdio_write(dev, LED_TIMER_CTRL_REG, reg); |
| 71 | |
| 72 | /* Switch back to page 0. */ |
| 73 | switch_page(dev, 0); |
| 74 | } |
Mario Scheithauer | d4ab2ee | 2022-11-04 10:23:43 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | struct device_operations m88e1512_ops = { |
| 78 | .read_resources = noop_read_resources, |
| 79 | .set_resources = noop_set_resources, |
| 80 | .init = m88e1512_init, |
| 81 | }; |
| 82 | |
| 83 | struct chip_operations drivers_net_phy_m88e1512_ops = { |
| 84 | CHIP_NAME("88E1512") |
| 85 | }; |