Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Micrel KS8851_MLL 16bit Network driver |
| 4 | * Copyright (c) 2011 Roberto Cerati <roberto.cerati@bticino.it> |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 7 | #include <log.h> |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 8 | #include <asm/io.h> |
| 9 | #include <common.h> |
| 10 | #include <command.h> |
| 11 | #include <malloc.h> |
| 12 | #include <net.h> |
| 13 | #include <miiphy.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 14 | #include <linux/delay.h> |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 15 | |
| 16 | #include "ks8851_mll.h" |
| 17 | |
| 18 | #define DRIVERNAME "ks8851_mll" |
| 19 | |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 20 | #define RX_BUF_SIZE 2000 |
| 21 | |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 22 | /* |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 23 | * struct ks_net - KS8851 driver private data |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 24 | * @dev : legacy non-DM ethernet device structure |
| 25 | * @iobase : register base |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 26 | * @bus_width : i/o bus width. |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 27 | * @sharedbus : Multipex(addr and data bus) mode indicator. |
Marek Vasut | 21bf578 | 2020-03-25 17:23:11 +0100 | [diff] [blame] | 28 | * @extra_byte : number of extra byte prepended rx pkt. |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 29 | */ |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 30 | struct ks_net { |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 31 | struct eth_device dev; |
| 32 | phys_addr_t iobase; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 33 | int bus_width; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 34 | u16 sharedbus; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 35 | u8 extra_byte; |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 36 | }; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 37 | |
| 38 | #define BE3 0x8000 /* Byte Enable 3 */ |
| 39 | #define BE2 0x4000 /* Byte Enable 2 */ |
| 40 | #define BE1 0x2000 /* Byte Enable 1 */ |
| 41 | #define BE0 0x1000 /* Byte Enable 0 */ |
| 42 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 43 | static u8 ks_rdreg8(struct ks_net *ks, u16 offset) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 44 | { |
| 45 | u8 shift_bit = offset & 0x03; |
| 46 | u8 shift_data = (offset & 1) << 3; |
| 47 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 48 | writew(offset | (BE0 << shift_bit), ks->iobase + 2); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 49 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 50 | return (u8)(readw(ks->iobase) >> shift_data); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 51 | } |
| 52 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 53 | static u16 ks_rdreg16(struct ks_net *ks, u16 offset) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 54 | { |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 55 | writew(offset | ((BE1 | BE0) << (offset & 0x02)), ks->iobase + 2); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 56 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 57 | return readw(ks->iobase); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 58 | } |
| 59 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 60 | static void ks_wrreg16(struct ks_net *ks, u16 offset, u16 val) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 61 | { |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 62 | writew(offset | ((BE1 | BE0) << (offset & 0x02)), ks->iobase + 2); |
| 63 | writew(val, ks->iobase); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /* |
| 67 | * ks_inblk - read a block of data from QMU. This is called after sudo DMA mode |
| 68 | * enabled. |
| 69 | * @ks: The chip state |
| 70 | * @wptr: buffer address to save data |
| 71 | * @len: length in byte to read |
| 72 | */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 73 | static inline void ks_inblk(struct ks_net *ks, u16 *wptr, u32 len) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 74 | { |
| 75 | len >>= 1; |
| 76 | |
| 77 | while (len--) |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 78 | *wptr++ = readw(ks->iobase); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /* |
| 82 | * ks_outblk - write data to QMU. This is called after sudo DMA mode enabled. |
| 83 | * @ks: The chip information |
| 84 | * @wptr: buffer address |
| 85 | * @len: length in byte to write |
| 86 | */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 87 | static inline void ks_outblk(struct ks_net *ks, u16 *wptr, u32 len) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 88 | { |
| 89 | len >>= 1; |
| 90 | |
| 91 | while (len--) |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 92 | writew(*wptr++, ks->iobase); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 93 | } |
| 94 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 95 | static void ks_enable_int(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 96 | { |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 97 | ks_wrreg16(ks, KS_IER, IRQ_LCI | IRQ_TXI | IRQ_RXI); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 98 | } |
| 99 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 100 | static void ks_set_powermode(struct ks_net *ks, unsigned int pwrmode) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 101 | { |
Marek Vasut | e457cb1 | 2020-03-25 17:25:29 +0100 | [diff] [blame] | 102 | unsigned int pmecr; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 103 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 104 | ks_rdreg16(ks, KS_GRR); |
| 105 | pmecr = ks_rdreg16(ks, KS_PMECR); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 106 | pmecr &= ~PMECR_PM_MASK; |
| 107 | pmecr |= pwrmode; |
| 108 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 109 | ks_wrreg16(ks, KS_PMECR, pmecr); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* |
| 113 | * ks_read_config - read chip configuration of bus width. |
| 114 | * @ks: The chip information |
| 115 | */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 116 | static void ks_read_config(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 117 | { |
| 118 | u16 reg_data = 0; |
| 119 | |
| 120 | /* Regardless of bus width, 8 bit read should always work. */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 121 | reg_data = ks_rdreg8(ks, KS_CCR) & 0x00FF; |
| 122 | reg_data |= ks_rdreg8(ks, KS_CCR + 1) << 8; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 123 | |
| 124 | /* addr/data bus are multiplexed */ |
| 125 | ks->sharedbus = (reg_data & CCR_SHARED) == CCR_SHARED; |
| 126 | |
| 127 | /* |
| 128 | * There are garbage data when reading data from QMU, |
| 129 | * depending on bus-width. |
| 130 | */ |
| 131 | if (reg_data & CCR_8BIT) { |
| 132 | ks->bus_width = ENUM_BUS_8BIT; |
| 133 | ks->extra_byte = 1; |
| 134 | } else if (reg_data & CCR_16BIT) { |
| 135 | ks->bus_width = ENUM_BUS_16BIT; |
| 136 | ks->extra_byte = 2; |
| 137 | } else { |
| 138 | ks->bus_width = ENUM_BUS_32BIT; |
| 139 | ks->extra_byte = 4; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * ks_soft_reset - issue one of the soft reset to the device |
| 145 | * @ks: The device state. |
| 146 | * @op: The bit(s) to set in the GRR |
| 147 | * |
| 148 | * Issue the relevant soft-reset command to the device's GRR register |
| 149 | * specified by @op. |
| 150 | * |
| 151 | * Note, the delays are in there as a caution to ensure that the reset |
| 152 | * has time to take effect and then complete. Since the datasheet does |
| 153 | * not currently specify the exact sequence, we have chosen something |
| 154 | * that seems to work with our device. |
| 155 | */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 156 | static void ks_soft_reset(struct ks_net *ks, unsigned int op) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 157 | { |
| 158 | /* Disable interrupt first */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 159 | ks_wrreg16(ks, KS_IER, 0x0000); |
| 160 | ks_wrreg16(ks, KS_GRR, op); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 161 | mdelay(10); /* wait a short time to effect reset */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 162 | ks_wrreg16(ks, KS_GRR, 0); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 163 | mdelay(1); /* wait for condition to clear */ |
| 164 | } |
| 165 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 166 | void ks_enable_qmu(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 167 | { |
| 168 | u16 w; |
| 169 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 170 | w = ks_rdreg16(ks, KS_TXCR); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 171 | |
| 172 | /* Enables QMU Transmit (TXCR). */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 173 | ks_wrreg16(ks, KS_TXCR, w | TXCR_TXE); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 174 | |
| 175 | /* Enable RX Frame Count Threshold and Auto-Dequeue RXQ Frame */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 176 | w = ks_rdreg16(ks, KS_RXQCR); |
| 177 | ks_wrreg16(ks, KS_RXQCR, w | RXQCR_RXFCTE); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 178 | |
| 179 | /* Enables QMU Receive (RXCR1). */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 180 | w = ks_rdreg16(ks, KS_RXCR1); |
| 181 | ks_wrreg16(ks, KS_RXCR1, w | RXCR1_RXE); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 182 | } |
| 183 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 184 | static void ks_disable_qmu(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 185 | { |
| 186 | u16 w; |
| 187 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 188 | w = ks_rdreg16(ks, KS_TXCR); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 189 | |
| 190 | /* Disables QMU Transmit (TXCR). */ |
| 191 | w &= ~TXCR_TXE; |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 192 | ks_wrreg16(ks, KS_TXCR, w); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 193 | |
| 194 | /* Disables QMU Receive (RXCR1). */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 195 | w = ks_rdreg16(ks, KS_RXCR1); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 196 | w &= ~RXCR1_RXE; |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 197 | ks_wrreg16(ks, KS_RXCR1, w); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 198 | } |
| 199 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 200 | static inline void ks_read_qmu(struct ks_net *ks, u16 *buf, u32 len) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 201 | { |
| 202 | u32 r = ks->extra_byte & 0x1; |
| 203 | u32 w = ks->extra_byte - r; |
| 204 | |
| 205 | /* 1. set sudo DMA mode */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 206 | ks_wrreg16(ks, KS_RXFDPR, RXFDPR_RXFPAI); |
| 207 | ks_wrreg16(ks, KS_RXQCR, RXQCR_CMD_CNTL | RXQCR_SDA); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * 2. read prepend data |
| 211 | * |
| 212 | * read 4 + extra bytes and discard them. |
| 213 | * extra bytes for dummy, 2 for status, 2 for len |
| 214 | */ |
| 215 | |
| 216 | if (r) |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 217 | ks_rdreg8(ks, 0); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 218 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 219 | ks_inblk(ks, buf, w + 2 + 2); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 220 | |
| 221 | /* 3. read pkt data */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 222 | ks_inblk(ks, buf, ALIGN(len, 4)); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 223 | |
| 224 | /* 4. reset sudo DMA Mode */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 225 | ks_wrreg16(ks, KS_RXQCR, RXQCR_CMD_CNTL); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 226 | } |
| 227 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 228 | static void ks_rcv(struct ks_net *ks, uchar **pv_data) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 229 | { |
Marek Vasut | 1994c90 | 2020-03-25 17:18:55 +0100 | [diff] [blame] | 230 | unsigned int frame_cnt; |
Marek Vasut | 21bf578 | 2020-03-25 17:23:11 +0100 | [diff] [blame] | 231 | u16 sts, len; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 232 | int i; |
| 233 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 234 | frame_cnt = ks_rdreg16(ks, KS_RXFCTR) >> 8; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 235 | |
| 236 | /* read all header information */ |
Marek Vasut | 1994c90 | 2020-03-25 17:18:55 +0100 | [diff] [blame] | 237 | for (i = 0; i < frame_cnt; i++) { |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 238 | /* Checking Received packet status */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 239 | sts = ks_rdreg16(ks, KS_RXFHSR); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 240 | /* Get packet len from hardware */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 241 | len = ks_rdreg16(ks, KS_RXFHBCR); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 242 | |
Marek Vasut | 21bf578 | 2020-03-25 17:23:11 +0100 | [diff] [blame] | 243 | if ((sts & RXFSHR_RXFV) && len && (len < RX_BUF_SIZE)) { |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 244 | /* read data block including CRC 4 bytes */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 245 | ks_read_qmu(ks, (u16 *)(*pv_data), len); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 246 | |
Joe Hershberger | 9f09a36 | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 247 | /* net_rx_packets buffer size is ok (*pv_data) */ |
Marek Vasut | 21bf578 | 2020-03-25 17:23:11 +0100 | [diff] [blame] | 248 | net_process_received_packet(*pv_data, len); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 249 | pv_data++; |
| 250 | } else { |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 251 | ks_wrreg16(ks, KS_RXQCR, RXQCR_CMD_CNTL | RXQCR_RRXEF); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 252 | printf(DRIVERNAME ": bad packet\n"); |
| 253 | } |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | * ks_read_selftest - read the selftest memory info. |
| 259 | * @ks: The device state |
| 260 | * |
| 261 | * Read and check the TX/RX memory selftest information. |
| 262 | */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 263 | static int ks_read_selftest(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 264 | { |
| 265 | u16 both_done = MBIR_TXMBF | MBIR_RXMBF; |
| 266 | u16 mbir; |
| 267 | int ret = 0; |
| 268 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 269 | mbir = ks_rdreg16(ks, KS_MBIR); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 270 | |
| 271 | if ((mbir & both_done) != both_done) { |
| 272 | printf(DRIVERNAME ": Memory selftest not finished\n"); |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | if (mbir & MBIR_TXMBFA) { |
| 277 | printf(DRIVERNAME ": TX memory selftest fails\n"); |
| 278 | ret |= 1; |
| 279 | } |
| 280 | |
| 281 | if (mbir & MBIR_RXMBFA) { |
| 282 | printf(DRIVERNAME ": RX memory selftest fails\n"); |
| 283 | ret |= 2; |
| 284 | } |
| 285 | |
| 286 | debug(DRIVERNAME ": the selftest passes\n"); |
| 287 | |
| 288 | return ret; |
| 289 | } |
| 290 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 291 | static void ks_setup(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 292 | { |
| 293 | u16 w; |
| 294 | |
| 295 | /* Setup Transmit Frame Data Pointer Auto-Increment (TXFDPR) */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 296 | ks_wrreg16(ks, KS_TXFDPR, TXFDPR_TXFPAI); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 297 | |
| 298 | /* Setup Receive Frame Data Pointer Auto-Increment */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 299 | ks_wrreg16(ks, KS_RXFDPR, RXFDPR_RXFPAI); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 300 | |
| 301 | /* Setup Receive Frame Threshold - 1 frame (RXFCTFC) */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 302 | ks_wrreg16(ks, KS_RXFCTR, 1 & RXFCTR_THRESHOLD_MASK); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 303 | |
| 304 | /* Setup RxQ Command Control (RXQCR) */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 305 | ks_wrreg16(ks, KS_RXQCR, RXQCR_CMD_CNTL); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 306 | |
| 307 | /* |
| 308 | * set the force mode to half duplex, default is full duplex |
| 309 | * because if the auto-negotiation fails, most switch uses |
| 310 | * half-duplex. |
| 311 | */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 312 | w = ks_rdreg16(ks, KS_P1MBCR); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 313 | w &= ~P1MBCR_FORCE_FDX; |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 314 | ks_wrreg16(ks, KS_P1MBCR, w); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 315 | |
| 316 | w = TXCR_TXFCE | TXCR_TXPE | TXCR_TXCRC | TXCR_TCGIP; |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 317 | ks_wrreg16(ks, KS_TXCR, w); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 318 | |
| 319 | w = RXCR1_RXFCE | RXCR1_RXBE | RXCR1_RXUE | RXCR1_RXME | RXCR1_RXIPFCC; |
| 320 | |
| 321 | /* Normal mode */ |
| 322 | w |= RXCR1_RXPAFMA; |
| 323 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 324 | ks_wrreg16(ks, KS_RXCR1, w); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 325 | } |
| 326 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 327 | static void ks_setup_int(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 328 | { |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 329 | /* Clear the interrupts status of the hardware. */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 330 | ks_wrreg16(ks, KS_ISR, 0xffff); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 331 | } |
| 332 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 333 | static int ks8851_mll_detect_chip(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 334 | { |
Marek Vasut | b4ba60b | 2020-03-25 18:15:46 +0100 | [diff] [blame] | 335 | unsigned short val; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 336 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 337 | ks_read_config(ks); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 338 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 339 | val = ks_rdreg16(ks, KS_CIDER); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 340 | |
| 341 | if (val == 0xffff) { |
| 342 | /* Special case -- no chip present */ |
| 343 | printf(DRIVERNAME ": is chip mounted ?\n"); |
| 344 | return -1; |
| 345 | } else if ((val & 0xfff0) != CIDER_ID) { |
| 346 | printf(DRIVERNAME ": Invalid chip id 0x%04x\n", val); |
| 347 | return -1; |
| 348 | } |
| 349 | |
| 350 | debug("Read back KS8851 id 0x%x\n", val); |
| 351 | |
Marek Vasut | b4ba60b | 2020-03-25 18:15:46 +0100 | [diff] [blame] | 352 | if ((val & 0xfff0) != CIDER_ID) { |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 353 | printf(DRIVERNAME ": Unknown chip ID %04x\n", val); |
| 354 | return -1; |
| 355 | } |
| 356 | |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 357 | return 0; |
| 358 | } |
| 359 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 360 | static void ks8851_mll_reset(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 361 | { |
| 362 | /* wake up powermode to normal mode */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 363 | ks_set_powermode(ks, PMECR_PM_NORMAL); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 364 | mdelay(1); /* wait for normal mode to take effect */ |
| 365 | |
| 366 | /* Disable interrupt and reset */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 367 | ks_soft_reset(ks, GRR_GSR); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 368 | |
| 369 | /* turn off the IRQs and ack any outstanding */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 370 | ks_wrreg16(ks, KS_IER, 0x0000); |
| 371 | ks_wrreg16(ks, KS_ISR, 0xffff); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 372 | |
| 373 | /* shutdown RX/TX QMU */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 374 | ks_disable_qmu(ks); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 375 | } |
| 376 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 377 | static void ks8851_mll_phy_configure(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 378 | { |
| 379 | u16 data; |
| 380 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 381 | ks_setup(ks); |
| 382 | ks_setup_int(ks); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 383 | |
| 384 | /* Probing the phy */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 385 | data = ks_rdreg16(ks, KS_OBCR); |
| 386 | ks_wrreg16(ks, KS_OBCR, data | OBCR_ODS_16MA); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 387 | |
| 388 | debug(DRIVERNAME ": phy initialized\n"); |
| 389 | } |
| 390 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 391 | static void ks8851_mll_enable(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 392 | { |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 393 | ks_wrreg16(ks, KS_ISR, 0xffff); |
| 394 | ks_enable_int(ks); |
| 395 | ks_enable_qmu(ks); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 396 | } |
| 397 | |
Marek Vasut | c0bb0d9 | 2020-03-25 17:54:45 +0100 | [diff] [blame^] | 398 | static int ks8851_mll_init_common(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 399 | { |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 400 | if (ks_read_selftest(ks)) { |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 401 | printf(DRIVERNAME ": Selftest failed\n"); |
| 402 | return -1; |
| 403 | } |
| 404 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 405 | ks8851_mll_reset(ks); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 406 | |
| 407 | /* Configure the PHY, initialize the link state */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 408 | ks8851_mll_phy_configure(ks); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 409 | |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 410 | /* Turn on Tx + Rx */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 411 | ks8851_mll_enable(ks); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 416 | static void ks_write_qmu(struct ks_net *ks, u8 *pdata, u16 len) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 417 | { |
Marek Vasut | 1994c90 | 2020-03-25 17:18:55 +0100 | [diff] [blame] | 418 | __le16 txw[2]; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 419 | /* start header at txb[0] to align txw entries */ |
Marek Vasut | 1994c90 | 2020-03-25 17:18:55 +0100 | [diff] [blame] | 420 | txw[0] = 0; |
| 421 | txw[1] = cpu_to_le16(len); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 422 | |
| 423 | /* 1. set sudo-DMA mode */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 424 | ks_wrreg16(ks, KS_TXFDPR, TXFDPR_TXFPAI); |
| 425 | ks_wrreg16(ks, KS_RXQCR, RXQCR_CMD_CNTL | RXQCR_SDA); |
Marek Vasut | e457cb1 | 2020-03-25 17:25:29 +0100 | [diff] [blame] | 426 | /* 2. write status/length info */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 427 | ks_outblk(ks, txw, 4); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 428 | /* 3. write pkt data */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 429 | ks_outblk(ks, (u16 *)pdata, ALIGN(len, 4)); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 430 | /* 4. reset sudo-DMA mode */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 431 | ks_wrreg16(ks, KS_RXQCR, RXQCR_CMD_CNTL); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 432 | /* 5. Enqueue Tx(move the pkt from TX buffer into TXQ) */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 433 | ks_wrreg16(ks, KS_TXQCR, TXQCR_METFE); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 434 | /* 6. wait until TXQCR_METFE is auto-cleared */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 435 | do { } while (ks_rdreg16(ks, KS_TXQCR) & TXQCR_METFE); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 436 | } |
| 437 | |
Marek Vasut | c0bb0d9 | 2020-03-25 17:54:45 +0100 | [diff] [blame^] | 438 | static int ks8851_mll_send_common(struct ks_net *ks, void *packet, int length) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 439 | { |
| 440 | u8 *data = (u8 *)packet; |
| 441 | u16 tmplen = (u16)length; |
| 442 | u16 retv; |
| 443 | |
| 444 | /* |
| 445 | * Extra space are required: |
| 446 | * 4 byte for alignment, 4 for status/length, 4 for CRC |
| 447 | */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 448 | retv = ks_rdreg16(ks, KS_TXMIR) & 0x1fff; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 449 | if (retv >= tmplen + 12) { |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 450 | ks_write_qmu(ks, data, tmplen); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 451 | return 0; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 452 | } |
Marek Vasut | e457cb1 | 2020-03-25 17:25:29 +0100 | [diff] [blame] | 453 | |
| 454 | printf(DRIVERNAME ": failed to send packet: No buffer\n"); |
| 455 | return -1; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 456 | } |
| 457 | |
Marek Vasut | c0bb0d9 | 2020-03-25 17:54:45 +0100 | [diff] [blame^] | 458 | static void ks8851_mll_halt_common(struct ks_net *ks) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 459 | { |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 460 | ks8851_mll_reset(ks); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | /* |
| 464 | * Maximum receive ring size; that is, the number of packets |
| 465 | * we can buffer before overflow happens. Basically, this just |
| 466 | * needs to be enough to prevent a packet being discarded while |
| 467 | * we are processing the previous one. |
| 468 | */ |
Marek Vasut | c0bb0d9 | 2020-03-25 17:54:45 +0100 | [diff] [blame^] | 469 | static int ks8851_mll_recv_common(struct ks_net *ks, uchar **data) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 470 | { |
| 471 | u16 status; |
| 472 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 473 | status = ks_rdreg16(ks, KS_ISR); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 474 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 475 | ks_wrreg16(ks, KS_ISR, status); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 476 | |
Marek Vasut | e457cb1 | 2020-03-25 17:25:29 +0100 | [diff] [blame] | 477 | if (status & IRQ_RXI) |
Marek Vasut | c0bb0d9 | 2020-03-25 17:54:45 +0100 | [diff] [blame^] | 478 | ks_rcv(ks, data); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 479 | |
Marek Vasut | e457cb1 | 2020-03-25 17:25:29 +0100 | [diff] [blame] | 480 | if (status & IRQ_LDI) { |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 481 | u16 pmecr = ks_rdreg16(ks, KS_PMECR); |
Marek Vasut | e457cb1 | 2020-03-25 17:25:29 +0100 | [diff] [blame] | 482 | |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 483 | pmecr &= ~PMECR_WKEVT_MASK; |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 484 | ks_wrreg16(ks, KS_PMECR, pmecr | PMECR_WKEVT_LINK); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | return 0; |
| 488 | } |
| 489 | |
Marek Vasut | c0bb0d9 | 2020-03-25 17:54:45 +0100 | [diff] [blame^] | 490 | static void ks8851_mll_write_hwaddr_common(struct ks_net *ks, u8 enetaddr[6]) |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 491 | { |
| 492 | u16 addrl, addrm, addrh; |
| 493 | |
Marek Vasut | c0bb0d9 | 2020-03-25 17:54:45 +0100 | [diff] [blame^] | 494 | addrh = (enetaddr[0] << 8) | enetaddr[1]; |
| 495 | addrm = (enetaddr[2] << 8) | enetaddr[3]; |
| 496 | addrl = (enetaddr[4] << 8) | enetaddr[5]; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 497 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 498 | ks_wrreg16(ks, KS_MARH, addrh); |
| 499 | ks_wrreg16(ks, KS_MARM, addrm); |
| 500 | ks_wrreg16(ks, KS_MARL, addrl); |
Marek Vasut | c0bb0d9 | 2020-03-25 17:54:45 +0100 | [diff] [blame^] | 501 | } |
| 502 | |
| 503 | static int ks8851_mll_init(struct eth_device *dev, bd_t *bd) |
| 504 | { |
| 505 | struct ks_net *ks = container_of(dev, struct ks_net, dev); |
| 506 | |
| 507 | return ks8851_mll_init_common(ks); |
| 508 | } |
| 509 | |
| 510 | static void ks8851_mll_halt(struct eth_device *dev) |
| 511 | { |
| 512 | struct ks_net *ks = container_of(dev, struct ks_net, dev); |
| 513 | |
| 514 | ks8851_mll_halt_common(ks); |
| 515 | } |
| 516 | |
| 517 | static int ks8851_mll_send(struct eth_device *dev, void *packet, int length) |
| 518 | { |
| 519 | struct ks_net *ks = container_of(dev, struct ks_net, dev); |
| 520 | |
| 521 | return ks8851_mll_send_common(ks, packet, length); |
| 522 | } |
| 523 | |
| 524 | static int ks8851_mll_recv(struct eth_device *dev) |
| 525 | { |
| 526 | struct ks_net *ks = container_of(dev, struct ks_net, dev); |
| 527 | |
| 528 | return ks8851_mll_recv_common(ks, (uchar **)net_rx_packets); |
| 529 | } |
| 530 | |
| 531 | static int ks8851_mll_write_hwaddr(struct eth_device *dev) |
| 532 | { |
| 533 | struct ks_net *ks = container_of(dev, struct ks_net, dev); |
| 534 | |
| 535 | ks8851_mll_write_hwaddr_common(ks, ks->dev.enetaddr); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | int ks8851_mll_initialize(u8 dev_num, int base_addr) |
| 541 | { |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 542 | struct ks_net *ks; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 543 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 544 | ks = calloc(1, sizeof(*ks)); |
| 545 | if (!ks) |
Marek Vasut | 033a879 | 2020-03-25 16:52:38 +0100 | [diff] [blame] | 546 | return -ENOMEM; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 547 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 548 | ks->iobase = base_addr; |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 549 | |
| 550 | /* Try to detect chip. Will fail if not present. */ |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 551 | if (ks8851_mll_detect_chip(ks)) { |
| 552 | free(ks); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 553 | return -1; |
| 554 | } |
| 555 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 556 | ks->dev.init = ks8851_mll_init; |
| 557 | ks->dev.halt = ks8851_mll_halt; |
| 558 | ks->dev.send = ks8851_mll_send; |
| 559 | ks->dev.recv = ks8851_mll_recv; |
| 560 | ks->dev.write_hwaddr = ks8851_mll_write_hwaddr; |
| 561 | sprintf(ks->dev.name, "%s-%hu", DRIVERNAME, dev_num); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 562 | |
Marek Vasut | 1e1693e | 2020-03-25 17:35:00 +0100 | [diff] [blame] | 563 | eth_register(&ks->dev); |
Roberto Cerati | b1eee65 | 2013-04-24 10:46:17 +0800 | [diff] [blame] | 564 | |
| 565 | return 0; |
| 566 | } |