1 /* drivers/net/ethernet/micrel/ks8851.c
3 * Copyright 2009 Simtec Electronics
4 * http://www.simtec.co.uk/
5 * Ben Dooks <ben@simtec.co.uk>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/interrupt.h>
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/netdevice.h>
20 #include <linux/etherdevice.h>
21 #include <linux/ethtool.h>
22 #include <linux/cache.h>
23 #include <linux/crc32.h>
24 #include <linux/mii.h>
25 #include <linux/eeprom_93cx6.h>
26 #include <linux/regulator/consumer.h>
28 #include <linux/spi/spi.h>
29 #include <linux/gpio.h>
30 #include <linux/of_gpio.h>
35 * struct ks8851_rxctrl - KS8851 driver rx control
36 * @mchash: Multicast hash-table data.
37 * @rxcr1: KS_RXCR1 register setting
38 * @rxcr2: KS_RXCR2 register setting
40 * Representation of the settings needs to control the receive filtering
41 * such as the multicast hash-filter and the receive register settings. This
42 * is used to make the job of working out if the receive settings change and
43 * then issuing the new settings to the worker that will send the necessary
46 struct ks8851_rxctrl
{
53 * union ks8851_tx_hdr - tx header data
54 * @txb: The header as bytes
55 * @txw: The header as 16bit, little-endian words
57 * A dual representation of the tx header data to allow
58 * access to individual bytes, and to allow 16bit accesses
59 * with 16bit alignment.
67 * struct ks8851_net - KS8851 driver private data
68 * @netdev: The network device we're bound to
69 * @spidev: The spi device we're bound to.
70 * @lock: Lock to ensure that the device is not accessed when busy.
71 * @statelock: Lock on this structure for tx list.
72 * @mii: The MII state information for the mii calls.
73 * @rxctrl: RX settings for @rxctrl_work.
74 * @tx_work: Work queue for tx packets
75 * @rxctrl_work: Work queue for updating RX mode and multicast lists
76 * @txq: Queue of packets for transmission.
77 * @spi_msg1: pre-setup SPI transfer with one message, @spi_xfer1.
78 * @spi_msg2: pre-setup SPI transfer with two messages, @spi_xfer2.
79 * @txh: Space for generating packet TX header in DMA-able data
80 * @rxd: Space for receiving SPI data, in DMA-able space.
81 * @txd: Space for transmitting SPI data, in DMA-able space.
82 * @msg_enable: The message flags controlling driver output (see ethtool).
83 * @fid: Incrementing frame id tag.
84 * @rc_ier: Cached copy of KS_IER.
85 * @rc_ccr: Cached copy of KS_CCR.
86 * @rc_rxqcr: Cached copy of KS_RXQCR.
87 * @eeprom_size: Companion eeprom size in Bytes, 0 if no eeprom
88 * @eeprom: 93CX6 EEPROM state for accessing on-board EEPROM.
89 * @vdd_reg: Optional regulator supplying the chip
90 * @vdd_io: Optional digital power supply for IO
91 * @gpio: Optional reset_n gpio
93 * The @lock ensures that the chip is protected when certain operations are
94 * in progress. When the read or write packet transfer is in progress, most
95 * of the chip registers are not ccessible until the transfer is finished and
96 * the DMA has been de-asserted.
98 * The @statelock is used to protect information in the structure which may
99 * need to be accessed via several sources, such as the network driver layer
100 * or one of the work queues.
102 * We align the buffers we may use for rx/tx to ensure that if the SPI driver
103 * wants to DMA map them, it will not have any problems with data the driver
107 struct net_device
*netdev
;
108 struct spi_device
*spidev
;
110 spinlock_t statelock
;
112 union ks8851_tx_hdr txh ____cacheline_aligned
;
116 u32 msg_enable ____cacheline_aligned
;
125 struct mii_if_info mii
;
126 struct ks8851_rxctrl rxctrl
;
128 struct work_struct tx_work
;
129 struct work_struct rxctrl_work
;
131 struct sk_buff_head txq
;
133 struct spi_message spi_msg1
;
134 struct spi_message spi_msg2
;
135 struct spi_transfer spi_xfer1
;
136 struct spi_transfer spi_xfer2
[2];
138 struct eeprom_93cx6 eeprom
;
139 struct regulator
*vdd_reg
;
140 struct regulator
*vdd_io
;
144 static int msg_enable
;
146 /* shift for byte-enable data */
147 #define BYTE_EN(_x) ((_x) << 2)
149 /* turn register number and byte-enable mask into data for start of packet */
150 #define MK_OP(_byteen, _reg) (BYTE_EN(_byteen) | (_reg) << (8+2) | (_reg) >> 6)
152 /* SPI register read/write calls.
154 * All these calls issue SPI transactions to access the chip's registers. They
155 * all require that the necessary lock is held to prevent accesses when the
156 * chip is busy transferring packet data (RX/TX FIFO accesses).
160 * ks8851_wrreg16 - write 16bit register value to chip
161 * @ks: The chip state
162 * @reg: The register address
163 * @val: The value to write
165 * Issue a write to put the value @val into the register specified in @reg.
167 static void ks8851_wrreg16(struct ks8851_net
*ks
, unsigned reg
, unsigned val
)
169 struct spi_transfer
*xfer
= &ks
->spi_xfer1
;
170 struct spi_message
*msg
= &ks
->spi_msg1
;
174 txb
[0] = cpu_to_le16(MK_OP(reg
& 2 ? 0xC : 0x03, reg
) | KS_SPIOP_WR
);
175 txb
[1] = cpu_to_le16(val
);
181 ret
= spi_sync(ks
->spidev
, msg
);
183 netdev_err(ks
->netdev
, "spi_sync() failed\n");
187 * ks8851_wrreg8 - write 8bit register value to chip
188 * @ks: The chip state
189 * @reg: The register address
190 * @val: The value to write
192 * Issue a write to put the value @val into the register specified in @reg.
194 static void ks8851_wrreg8(struct ks8851_net
*ks
, unsigned reg
, unsigned val
)
196 struct spi_transfer
*xfer
= &ks
->spi_xfer1
;
197 struct spi_message
*msg
= &ks
->spi_msg1
;
202 bit
= 1 << (reg
& 3);
204 txb
[0] = cpu_to_le16(MK_OP(bit
, reg
) | KS_SPIOP_WR
);
211 ret
= spi_sync(ks
->spidev
, msg
);
213 netdev_err(ks
->netdev
, "spi_sync() failed\n");
217 * ks8851_rx_1msg - select whether to use one or two messages for spi read
218 * @ks: The device structure
220 * Return whether to generate a single message with a tx and rx buffer
221 * supplied to spi_sync(), or alternatively send the tx and rx buffers
222 * as separate messages.
224 * Depending on the hardware in use, a single message may be more efficient
225 * on interrupts or work done by the driver.
227 * This currently always returns true until we add some per-device data passed
228 * from the platform code to specify which mode is better.
230 static inline bool ks8851_rx_1msg(struct ks8851_net
*ks
)
236 * ks8851_rdreg - issue read register command and return the data
237 * @ks: The device state
238 * @op: The register address and byte enables in message format.
239 * @rxb: The RX buffer to return the result into
240 * @rxl: The length of data expected.
242 * This is the low level read call that issues the necessary spi message(s)
243 * to read data from the register specified in @op.
245 static void ks8851_rdreg(struct ks8851_net
*ks
, unsigned op
,
246 u8
*rxb
, unsigned rxl
)
248 struct spi_transfer
*xfer
;
249 struct spi_message
*msg
;
250 __le16
*txb
= (__le16
*)ks
->txd
;
254 txb
[0] = cpu_to_le16(op
| KS_SPIOP_RD
);
256 if (ks8851_rx_1msg(ks
)) {
258 xfer
= &ks
->spi_xfer1
;
265 xfer
= ks
->spi_xfer2
;
277 ret
= spi_sync(ks
->spidev
, msg
);
279 netdev_err(ks
->netdev
, "read: spi_sync() failed\n");
280 else if (ks8851_rx_1msg(ks
))
281 memcpy(rxb
, trx
+ 2, rxl
);
283 memcpy(rxb
, trx
, rxl
);
287 * ks8851_rdreg8 - read 8 bit register from device
288 * @ks: The chip information
289 * @reg: The register address
291 * Read a 8bit register from the chip, returning the result
293 static unsigned ks8851_rdreg8(struct ks8851_net
*ks
, unsigned reg
)
297 ks8851_rdreg(ks
, MK_OP(1 << (reg
& 3), reg
), rxb
, 1);
302 * ks8851_rdreg16 - read 16 bit register from device
303 * @ks: The chip information
304 * @reg: The register address
306 * Read a 16bit register from the chip, returning the result
308 static unsigned ks8851_rdreg16(struct ks8851_net
*ks
, unsigned reg
)
312 ks8851_rdreg(ks
, MK_OP(reg
& 2 ? 0xC : 0x3, reg
), (u8
*)&rx
, 2);
313 return le16_to_cpu(rx
);
317 * ks8851_rdreg32 - read 32 bit register from device
318 * @ks: The chip information
319 * @reg: The register address
321 * Read a 32bit register from the chip.
323 * Note, this read requires the address be aligned to 4 bytes.
325 static unsigned ks8851_rdreg32(struct ks8851_net
*ks
, unsigned reg
)
331 ks8851_rdreg(ks
, MK_OP(0xf, reg
), (u8
*)&rx
, 4);
332 return le32_to_cpu(rx
);
336 * ks8851_soft_reset - issue one of the soft reset to the device
337 * @ks: The device state.
338 * @op: The bit(s) to set in the GRR
340 * Issue the relevant soft-reset command to the device's GRR register
343 * Note, the delays are in there as a caution to ensure that the reset
344 * has time to take effect and then complete. Since the datasheet does
345 * not currently specify the exact sequence, we have chosen something
346 * that seems to work with our device.
348 static void ks8851_soft_reset(struct ks8851_net
*ks
, unsigned op
)
350 ks8851_wrreg16(ks
, KS_GRR
, op
);
351 mdelay(1); /* wait a short time to effect reset */
352 ks8851_wrreg16(ks
, KS_GRR
, 0);
353 mdelay(1); /* wait for condition to clear */
357 * ks8851_set_powermode - set power mode of the device
358 * @ks: The device state
359 * @pwrmode: The power mode value to write to KS_PMECR.
361 * Change the power mode of the chip.
363 static void ks8851_set_powermode(struct ks8851_net
*ks
, unsigned pwrmode
)
367 netif_dbg(ks
, hw
, ks
->netdev
, "setting power mode %d\n", pwrmode
);
369 pmecr
= ks8851_rdreg16(ks
, KS_PMECR
);
370 pmecr
&= ~PMECR_PM_MASK
;
373 ks8851_wrreg16(ks
, KS_PMECR
, pmecr
);
377 * ks8851_write_mac_addr - write mac address to device registers
378 * @dev: The network device
380 * Update the KS8851 MAC address registers from the address in @dev.
382 * This call assumes that the chip is not running, so there is no need to
383 * shutdown the RXQ process whilst setting this.
385 static int ks8851_write_mac_addr(struct net_device
*dev
)
387 struct ks8851_net
*ks
= netdev_priv(dev
);
390 mutex_lock(&ks
->lock
);
393 * Wake up chip in case it was powered off when stopped; otherwise,
394 * the first write to the MAC address does not take effect.
396 ks8851_set_powermode(ks
, PMECR_PM_NORMAL
);
397 for (i
= 0; i
< ETH_ALEN
; i
++)
398 ks8851_wrreg8(ks
, KS_MAR(i
), dev
->dev_addr
[i
]);
399 if (!netif_running(dev
))
400 ks8851_set_powermode(ks
, PMECR_PM_SOFTDOWN
);
402 mutex_unlock(&ks
->lock
);
408 * ks8851_read_mac_addr - read mac address from device registers
409 * @dev: The network device
411 * Update our copy of the KS8851 MAC address from the registers of @dev.
413 static void ks8851_read_mac_addr(struct net_device
*dev
)
415 struct ks8851_net
*ks
= netdev_priv(dev
);
418 mutex_lock(&ks
->lock
);
420 for (i
= 0; i
< ETH_ALEN
; i
++)
421 dev
->dev_addr
[i
] = ks8851_rdreg8(ks
, KS_MAR(i
));
423 mutex_unlock(&ks
->lock
);
427 * ks8851_init_mac - initialise the mac address
428 * @ks: The device structure
430 * Get or create the initial mac address for the device and then set that
431 * into the station address register. If there is an EEPROM present, then
432 * we try that. If no valid mac address is found we use eth_random_addr()
433 * to create a new one.
435 static void ks8851_init_mac(struct ks8851_net
*ks
)
437 struct net_device
*dev
= ks
->netdev
;
439 /* first, try reading what we've got already */
440 if (ks
->rc_ccr
& CCR_EEPROM
) {
441 ks8851_read_mac_addr(dev
);
442 if (is_valid_ether_addr(dev
->dev_addr
))
445 netdev_err(ks
->netdev
, "invalid mac address read %pM\n",
449 eth_hw_addr_random(dev
);
450 ks8851_write_mac_addr(dev
);
454 * ks8851_rdfifo - read data from the receive fifo
455 * @ks: The device state.
456 * @buff: The buffer address
457 * @len: The length of the data to read
459 * Issue an RXQ FIFO read command and read the @len amount of data from
460 * the FIFO into the buffer specified by @buff.
462 static void ks8851_rdfifo(struct ks8851_net
*ks
, u8
*buff
, unsigned len
)
464 struct spi_transfer
*xfer
= ks
->spi_xfer2
;
465 struct spi_message
*msg
= &ks
->spi_msg2
;
469 netif_dbg(ks
, rx_status
, ks
->netdev
,
470 "%s: %d@%p\n", __func__
, len
, buff
);
472 /* set the operation we're issuing */
473 txb
[0] = KS_SPIOP_RXFIFO
;
484 ret
= spi_sync(ks
->spidev
, msg
);
486 netdev_err(ks
->netdev
, "%s: spi_sync() failed\n", __func__
);
490 * ks8851_dbg_dumpkkt - dump initial packet contents to debug
491 * @ks: The device state
492 * @rxpkt: The data for the received packet
494 * Dump the initial data from the packet to dev_dbg().
496 static void ks8851_dbg_dumpkkt(struct ks8851_net
*ks
, u8
*rxpkt
)
498 netdev_dbg(ks
->netdev
,
499 "pkt %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x\n",
500 rxpkt
[4], rxpkt
[5], rxpkt
[6], rxpkt
[7],
501 rxpkt
[8], rxpkt
[9], rxpkt
[10], rxpkt
[11],
502 rxpkt
[12], rxpkt
[13], rxpkt
[14], rxpkt
[15]);
506 * ks8851_rx_pkts - receive packets from the host
507 * @ks: The device information.
509 * This is called from the IRQ work queue when the system detects that there
510 * are packets in the receive queue. Find out how many packets there are and
511 * read them from the FIFO.
513 static void ks8851_rx_pkts(struct ks8851_net
*ks
)
522 rxfc
= ks8851_rdreg8(ks
, KS_RXFC
);
524 netif_dbg(ks
, rx_status
, ks
->netdev
,
525 "%s: %d packets\n", __func__
, rxfc
);
527 /* Currently we're issuing a read per packet, but we could possibly
528 * improve the code by issuing a single read, getting the receive
529 * header, allocating the packet and then reading the packet data
532 * This form of operation would require us to hold the SPI bus'
533 * chipselect low during the entie transaction to avoid any
534 * reset to the data stream coming from the chip.
537 for (; rxfc
!= 0; rxfc
--) {
538 rxh
= ks8851_rdreg32(ks
, KS_RXFHSR
);
539 rxstat
= rxh
& 0xffff;
540 rxlen
= (rxh
>> 16) & 0xfff;
542 netif_dbg(ks
, rx_status
, ks
->netdev
,
543 "rx: stat 0x%04x, len 0x%04x\n", rxstat
, rxlen
);
545 /* the length of the packet includes the 32bit CRC */
547 /* set dma read address */
548 ks8851_wrreg16(ks
, KS_RXFDPR
, RXFDPR_RXFPAI
| 0x00);
550 /* start the packet dma process, and set auto-dequeue rx */
551 ks8851_wrreg16(ks
, KS_RXQCR
,
552 ks
->rc_rxqcr
| RXQCR_SDA
| RXQCR_ADRFE
);
555 unsigned int rxalign
;
558 rxalign
= ALIGN(rxlen
, 4);
559 skb
= netdev_alloc_skb_ip_align(ks
->netdev
, rxalign
);
562 /* 4 bytes of status header + 4 bytes of
563 * garbage: we put them before ethernet
564 * header, so that they are copied,
568 rxpkt
= skb_put(skb
, rxlen
) - 8;
570 ks8851_rdfifo(ks
, rxpkt
, rxalign
+ 8);
572 if (netif_msg_pktdata(ks
))
573 ks8851_dbg_dumpkkt(ks
, rxpkt
);
575 skb
->protocol
= eth_type_trans(skb
, ks
->netdev
);
578 ks
->netdev
->stats
.rx_packets
++;
579 ks
->netdev
->stats
.rx_bytes
+= rxlen
;
583 ks8851_wrreg16(ks
, KS_RXQCR
, ks
->rc_rxqcr
);
588 * ks8851_irq - IRQ handler for dealing with interrupt requests
592 * This handler is invoked when the IRQ line asserts to find out what happened.
593 * As we cannot allow ourselves to sleep in HARDIRQ context, this handler runs
596 * Read the interrupt status, work out what needs to be done and then clear
597 * any of the interrupts that are not needed.
599 static irqreturn_t
ks8851_irq(int irq
, void *_ks
)
601 struct ks8851_net
*ks
= _ks
;
603 unsigned handled
= 0;
605 mutex_lock(&ks
->lock
);
607 status
= ks8851_rdreg16(ks
, KS_ISR
);
609 netif_dbg(ks
, intr
, ks
->netdev
,
610 "%s: status 0x%04x\n", __func__
, status
);
612 if (status
& IRQ_LCI
)
615 if (status
& IRQ_LDI
) {
616 u16 pmecr
= ks8851_rdreg16(ks
, KS_PMECR
);
617 pmecr
&= ~PMECR_WKEVT_MASK
;
618 ks8851_wrreg16(ks
, KS_PMECR
, pmecr
| PMECR_WKEVT_LINK
);
623 if (status
& IRQ_RXPSI
)
624 handled
|= IRQ_RXPSI
;
626 if (status
& IRQ_TXI
) {
629 /* no lock here, tx queue should have been stopped */
631 /* update our idea of how much tx space is available to the
633 ks
->tx_space
= ks8851_rdreg16(ks
, KS_TXMIR
);
635 netif_dbg(ks
, intr
, ks
->netdev
,
636 "%s: txspace %d\n", __func__
, ks
->tx_space
);
639 if (status
& IRQ_RXI
)
642 if (status
& IRQ_SPIBEI
) {
643 dev_err(&ks
->spidev
->dev
, "%s: spi bus error\n", __func__
);
644 handled
|= IRQ_SPIBEI
;
647 ks8851_wrreg16(ks
, KS_ISR
, handled
);
649 if (status
& IRQ_RXI
) {
650 /* the datasheet says to disable the rx interrupt during
651 * packet read-out, however we're masking the interrupt
652 * from the device so do not bother masking just the RX
653 * from the device. */
658 /* if something stopped the rx process, probably due to wanting
659 * to change the rx settings, then do something about restarting
661 if (status
& IRQ_RXPSI
) {
662 struct ks8851_rxctrl
*rxc
= &ks
->rxctrl
;
664 /* update the multicast hash table */
665 ks8851_wrreg16(ks
, KS_MAHTR0
, rxc
->mchash
[0]);
666 ks8851_wrreg16(ks
, KS_MAHTR1
, rxc
->mchash
[1]);
667 ks8851_wrreg16(ks
, KS_MAHTR2
, rxc
->mchash
[2]);
668 ks8851_wrreg16(ks
, KS_MAHTR3
, rxc
->mchash
[3]);
670 ks8851_wrreg16(ks
, KS_RXCR2
, rxc
->rxcr2
);
671 ks8851_wrreg16(ks
, KS_RXCR1
, rxc
->rxcr1
);
674 mutex_unlock(&ks
->lock
);
676 if (status
& IRQ_LCI
)
677 mii_check_link(&ks
->mii
);
679 if (status
& IRQ_TXI
)
680 netif_wake_queue(ks
->netdev
);
686 * calc_txlen - calculate size of message to send packet
687 * @len: Length of data
689 * Returns the size of the TXFIFO message needed to send
692 static inline unsigned calc_txlen(unsigned len
)
694 return ALIGN(len
+ 4, 4);
698 * ks8851_wrpkt - write packet to TX FIFO
699 * @ks: The device state.
700 * @txp: The sk_buff to transmit.
701 * @irq: IRQ on completion of the packet.
703 * Send the @txp to the chip. This means creating the relevant packet header
704 * specifying the length of the packet and the other information the chip
705 * needs, such as IRQ on completion. Send the header and the packet data to
708 static void ks8851_wrpkt(struct ks8851_net
*ks
, struct sk_buff
*txp
, bool irq
)
710 struct spi_transfer
*xfer
= ks
->spi_xfer2
;
711 struct spi_message
*msg
= &ks
->spi_msg2
;
715 netif_dbg(ks
, tx_queued
, ks
->netdev
, "%s: skb %p, %d@%p, irq %d\n",
716 __func__
, txp
, txp
->len
, txp
->data
, irq
);
719 fid
&= TXFR_TXFID_MASK
;
722 fid
|= TXFR_TXIC
; /* irq on completion */
724 /* start header at txb[1] to align txw entries */
725 ks
->txh
.txb
[1] = KS_SPIOP_TXFIFO
;
726 ks
->txh
.txw
[1] = cpu_to_le16(fid
);
727 ks
->txh
.txw
[2] = cpu_to_le16(txp
->len
);
729 xfer
->tx_buf
= &ks
->txh
.txb
[1];
734 xfer
->tx_buf
= txp
->data
;
736 xfer
->len
= ALIGN(txp
->len
, 4);
738 ret
= spi_sync(ks
->spidev
, msg
);
740 netdev_err(ks
->netdev
, "%s: spi_sync() failed\n", __func__
);
744 * ks8851_done_tx - update and then free skbuff after transmitting
745 * @ks: The device state
746 * @txb: The buffer transmitted
748 static void ks8851_done_tx(struct ks8851_net
*ks
, struct sk_buff
*txb
)
750 struct net_device
*dev
= ks
->netdev
;
752 dev
->stats
.tx_bytes
+= txb
->len
;
753 dev
->stats
.tx_packets
++;
759 * ks8851_tx_work - process tx packet(s)
760 * @work: The work strucutre what was scheduled.
762 * This is called when a number of packets have been scheduled for
763 * transmission and need to be sent to the device.
765 static void ks8851_tx_work(struct work_struct
*work
)
767 struct ks8851_net
*ks
= container_of(work
, struct ks8851_net
, tx_work
);
769 bool last
= skb_queue_empty(&ks
->txq
);
771 mutex_lock(&ks
->lock
);
774 txb
= skb_dequeue(&ks
->txq
);
775 last
= skb_queue_empty(&ks
->txq
);
778 ks8851_wrreg16(ks
, KS_RXQCR
, ks
->rc_rxqcr
| RXQCR_SDA
);
779 ks8851_wrpkt(ks
, txb
, last
);
780 ks8851_wrreg16(ks
, KS_RXQCR
, ks
->rc_rxqcr
);
781 ks8851_wrreg16(ks
, KS_TXQCR
, TXQCR_METFE
);
783 ks8851_done_tx(ks
, txb
);
787 mutex_unlock(&ks
->lock
);
791 * ks8851_net_open - open network device
792 * @dev: The network device being opened.
794 * Called when the network device is marked active, such as a user executing
795 * 'ifconfig up' on the device.
797 static int ks8851_net_open(struct net_device
*dev
)
799 struct ks8851_net
*ks
= netdev_priv(dev
);
801 /* lock the card, even if we may not actually be doing anything
802 * else at the moment */
803 mutex_lock(&ks
->lock
);
805 netif_dbg(ks
, ifup
, ks
->netdev
, "opening\n");
807 /* bring chip out of any power saving mode it was in */
808 ks8851_set_powermode(ks
, PMECR_PM_NORMAL
);
810 /* issue a soft reset to the RX/TX QMU to put it into a known
812 ks8851_soft_reset(ks
, GRR_QMU
);
814 /* setup transmission parameters */
816 ks8851_wrreg16(ks
, KS_TXCR
, (TXCR_TXE
| /* enable transmit process */
817 TXCR_TXPE
| /* pad to min length */
818 TXCR_TXCRC
| /* add CRC */
819 TXCR_TXFCE
)); /* enable flow control */
821 /* auto-increment tx data, reset tx pointer */
822 ks8851_wrreg16(ks
, KS_TXFDPR
, TXFDPR_TXFPAI
);
824 /* setup receiver control */
826 ks8851_wrreg16(ks
, KS_RXCR1
, (RXCR1_RXPAFMA
| /* from mac filter */
827 RXCR1_RXFCE
| /* enable flow control */
828 RXCR1_RXBE
| /* broadcast enable */
829 RXCR1_RXUE
| /* unicast enable */
830 RXCR1_RXE
)); /* enable rx block */
832 /* transfer entire frames out in one go */
833 ks8851_wrreg16(ks
, KS_RXCR2
, RXCR2_SRDBL_FRAME
);
835 /* set receive counter timeouts */
836 ks8851_wrreg16(ks
, KS_RXDTTR
, 1000); /* 1ms after first frame to IRQ */
837 ks8851_wrreg16(ks
, KS_RXDBCTR
, 4096); /* >4Kbytes in buffer to IRQ */
838 ks8851_wrreg16(ks
, KS_RXFCTR
, 10); /* 10 frames to IRQ */
840 ks
->rc_rxqcr
= (RXQCR_RXFCTE
| /* IRQ on frame count exceeded */
841 RXQCR_RXDBCTE
| /* IRQ on byte count exceeded */
842 RXQCR_RXDTTE
); /* IRQ on time exceeded */
844 ks8851_wrreg16(ks
, KS_RXQCR
, ks
->rc_rxqcr
);
846 /* clear then enable interrupts */
848 #define STD_IRQ (IRQ_LCI | /* Link Change */ \
849 IRQ_TXI | /* TX done */ \
850 IRQ_RXI | /* RX done */ \
851 IRQ_SPIBEI | /* SPI bus error */ \
852 IRQ_TXPSI | /* TX process stop */ \
853 IRQ_RXPSI) /* RX process stop */
855 ks
->rc_ier
= STD_IRQ
;
856 ks8851_wrreg16(ks
, KS_ISR
, STD_IRQ
);
857 ks8851_wrreg16(ks
, KS_IER
, STD_IRQ
);
859 netif_start_queue(ks
->netdev
);
861 netif_dbg(ks
, ifup
, ks
->netdev
, "network device up\n");
863 mutex_unlock(&ks
->lock
);
868 * ks8851_net_stop - close network device
869 * @dev: The device being closed.
871 * Called to close down a network device which has been active. Cancell any
872 * work, shutdown the RX and TX process and then place the chip into a low
873 * power state whilst it is not being used.
875 static int ks8851_net_stop(struct net_device
*dev
)
877 struct ks8851_net
*ks
= netdev_priv(dev
);
879 netif_info(ks
, ifdown
, dev
, "shutting down\n");
881 netif_stop_queue(dev
);
883 mutex_lock(&ks
->lock
);
884 /* turn off the IRQs and ack any outstanding */
885 ks8851_wrreg16(ks
, KS_IER
, 0x0000);
886 ks8851_wrreg16(ks
, KS_ISR
, 0xffff);
887 mutex_unlock(&ks
->lock
);
889 /* stop any outstanding work */
890 flush_work(&ks
->tx_work
);
891 flush_work(&ks
->rxctrl_work
);
893 mutex_lock(&ks
->lock
);
894 /* shutdown RX process */
895 ks8851_wrreg16(ks
, KS_RXCR1
, 0x0000);
897 /* shutdown TX process */
898 ks8851_wrreg16(ks
, KS_TXCR
, 0x0000);
900 /* set powermode to soft power down to save power */
901 ks8851_set_powermode(ks
, PMECR_PM_SOFTDOWN
);
902 mutex_unlock(&ks
->lock
);
904 /* ensure any queued tx buffers are dumped */
905 while (!skb_queue_empty(&ks
->txq
)) {
906 struct sk_buff
*txb
= skb_dequeue(&ks
->txq
);
908 netif_dbg(ks
, ifdown
, ks
->netdev
,
909 "%s: freeing txb %p\n", __func__
, txb
);
918 * ks8851_start_xmit - transmit packet
919 * @skb: The buffer to transmit
920 * @dev: The device used to transmit the packet.
922 * Called by the network layer to transmit the @skb. Queue the packet for
923 * the device and schedule the necessary work to transmit the packet when
926 * We do this to firstly avoid sleeping with the network device locked,
927 * and secondly so we can round up more than one packet to transmit which
928 * means we can try and avoid generating too many transmit done interrupts.
930 static netdev_tx_t
ks8851_start_xmit(struct sk_buff
*skb
,
931 struct net_device
*dev
)
933 struct ks8851_net
*ks
= netdev_priv(dev
);
934 unsigned needed
= calc_txlen(skb
->len
);
935 netdev_tx_t ret
= NETDEV_TX_OK
;
937 netif_dbg(ks
, tx_queued
, ks
->netdev
,
938 "%s: skb %p, %d@%p\n", __func__
, skb
, skb
->len
, skb
->data
);
940 spin_lock(&ks
->statelock
);
942 if (needed
> ks
->tx_space
) {
943 netif_stop_queue(dev
);
944 ret
= NETDEV_TX_BUSY
;
946 ks
->tx_space
-= needed
;
947 skb_queue_tail(&ks
->txq
, skb
);
950 spin_unlock(&ks
->statelock
);
951 schedule_work(&ks
->tx_work
);
957 * ks8851_rxctrl_work - work handler to change rx mode
958 * @work: The work structure this belongs to.
960 * Lock the device and issue the necessary changes to the receive mode from
961 * the network device layer. This is done so that we can do this without
962 * having to sleep whilst holding the network device lock.
964 * Since the recommendation from Micrel is that the RXQ is shutdown whilst the
965 * receive parameters are programmed, we issue a write to disable the RXQ and
966 * then wait for the interrupt handler to be triggered once the RXQ shutdown is
967 * complete. The interrupt handler then writes the new values into the chip.
969 static void ks8851_rxctrl_work(struct work_struct
*work
)
971 struct ks8851_net
*ks
= container_of(work
, struct ks8851_net
, rxctrl_work
);
973 mutex_lock(&ks
->lock
);
975 /* need to shutdown RXQ before modifying filter parameters */
976 ks8851_wrreg16(ks
, KS_RXCR1
, 0x00);
978 mutex_unlock(&ks
->lock
);
981 static void ks8851_set_rx_mode(struct net_device
*dev
)
983 struct ks8851_net
*ks
= netdev_priv(dev
);
984 struct ks8851_rxctrl rxctrl
;
986 memset(&rxctrl
, 0, sizeof(rxctrl
));
988 if (dev
->flags
& IFF_PROMISC
) {
989 /* interface to receive everything */
991 rxctrl
.rxcr1
= RXCR1_RXAE
| RXCR1_RXINVF
;
992 } else if (dev
->flags
& IFF_ALLMULTI
) {
993 /* accept all multicast packets */
995 rxctrl
.rxcr1
= (RXCR1_RXME
| RXCR1_RXAE
|
996 RXCR1_RXPAFMA
| RXCR1_RXMAFMA
);
997 } else if (dev
->flags
& IFF_MULTICAST
&& !netdev_mc_empty(dev
)) {
998 struct netdev_hw_addr
*ha
;
1001 /* accept some multicast */
1003 netdev_for_each_mc_addr(ha
, dev
) {
1004 crc
= ether_crc(ETH_ALEN
, ha
->addr
);
1005 crc
>>= (32 - 6); /* get top six bits */
1007 rxctrl
.mchash
[crc
>> 4] |= (1 << (crc
& 0xf));
1010 rxctrl
.rxcr1
= RXCR1_RXME
| RXCR1_RXPAFMA
;
1012 /* just accept broadcast / unicast */
1013 rxctrl
.rxcr1
= RXCR1_RXPAFMA
;
1016 rxctrl
.rxcr1
|= (RXCR1_RXUE
| /* unicast enable */
1017 RXCR1_RXBE
| /* broadcast enable */
1018 RXCR1_RXE
| /* RX process enable */
1019 RXCR1_RXFCE
); /* enable flow control */
1021 rxctrl
.rxcr2
|= RXCR2_SRDBL_FRAME
;
1023 /* schedule work to do the actual set of the data if needed */
1025 spin_lock(&ks
->statelock
);
1027 if (memcmp(&rxctrl
, &ks
->rxctrl
, sizeof(rxctrl
)) != 0) {
1028 memcpy(&ks
->rxctrl
, &rxctrl
, sizeof(ks
->rxctrl
));
1029 schedule_work(&ks
->rxctrl_work
);
1032 spin_unlock(&ks
->statelock
);
1035 static int ks8851_set_mac_address(struct net_device
*dev
, void *addr
)
1037 struct sockaddr
*sa
= addr
;
1039 if (netif_running(dev
))
1042 if (!is_valid_ether_addr(sa
->sa_data
))
1043 return -EADDRNOTAVAIL
;
1045 memcpy(dev
->dev_addr
, sa
->sa_data
, ETH_ALEN
);
1046 return ks8851_write_mac_addr(dev
);
1049 static int ks8851_net_ioctl(struct net_device
*dev
, struct ifreq
*req
, int cmd
)
1051 struct ks8851_net
*ks
= netdev_priv(dev
);
1053 if (!netif_running(dev
))
1056 return generic_mii_ioctl(&ks
->mii
, if_mii(req
), cmd
, NULL
);
1059 static const struct net_device_ops ks8851_netdev_ops
= {
1060 .ndo_open
= ks8851_net_open
,
1061 .ndo_stop
= ks8851_net_stop
,
1062 .ndo_do_ioctl
= ks8851_net_ioctl
,
1063 .ndo_start_xmit
= ks8851_start_xmit
,
1064 .ndo_set_mac_address
= ks8851_set_mac_address
,
1065 .ndo_set_rx_mode
= ks8851_set_rx_mode
,
1066 .ndo_change_mtu
= eth_change_mtu
,
1067 .ndo_validate_addr
= eth_validate_addr
,
1070 /* ethtool support */
1072 static void ks8851_get_drvinfo(struct net_device
*dev
,
1073 struct ethtool_drvinfo
*di
)
1075 strlcpy(di
->driver
, "KS8851", sizeof(di
->driver
));
1076 strlcpy(di
->version
, "1.00", sizeof(di
->version
));
1077 strlcpy(di
->bus_info
, dev_name(dev
->dev
.parent
), sizeof(di
->bus_info
));
1080 static u32
ks8851_get_msglevel(struct net_device
*dev
)
1082 struct ks8851_net
*ks
= netdev_priv(dev
);
1083 return ks
->msg_enable
;
1086 static void ks8851_set_msglevel(struct net_device
*dev
, u32 to
)
1088 struct ks8851_net
*ks
= netdev_priv(dev
);
1089 ks
->msg_enable
= to
;
1092 static int ks8851_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1094 struct ks8851_net
*ks
= netdev_priv(dev
);
1095 return mii_ethtool_gset(&ks
->mii
, cmd
);
1098 static int ks8851_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1100 struct ks8851_net
*ks
= netdev_priv(dev
);
1101 return mii_ethtool_sset(&ks
->mii
, cmd
);
1104 static u32
ks8851_get_link(struct net_device
*dev
)
1106 struct ks8851_net
*ks
= netdev_priv(dev
);
1107 return mii_link_ok(&ks
->mii
);
1110 static int ks8851_nway_reset(struct net_device
*dev
)
1112 struct ks8851_net
*ks
= netdev_priv(dev
);
1113 return mii_nway_restart(&ks
->mii
);
1116 /* EEPROM support */
1118 static void ks8851_eeprom_regread(struct eeprom_93cx6
*ee
)
1120 struct ks8851_net
*ks
= ee
->data
;
1123 val
= ks8851_rdreg16(ks
, KS_EEPCR
);
1125 ee
->reg_data_out
= (val
& EEPCR_EESB
) ? 1 : 0;
1126 ee
->reg_data_clock
= (val
& EEPCR_EESCK
) ? 1 : 0;
1127 ee
->reg_chip_select
= (val
& EEPCR_EECS
) ? 1 : 0;
1130 static void ks8851_eeprom_regwrite(struct eeprom_93cx6
*ee
)
1132 struct ks8851_net
*ks
= ee
->data
;
1133 unsigned val
= EEPCR_EESA
; /* default - eeprom access on */
1136 val
|= EEPCR_EESRWA
;
1137 if (ee
->reg_data_in
)
1139 if (ee
->reg_data_clock
)
1141 if (ee
->reg_chip_select
)
1144 ks8851_wrreg16(ks
, KS_EEPCR
, val
);
1148 * ks8851_eeprom_claim - claim device EEPROM and activate the interface
1149 * @ks: The network device state.
1151 * Check for the presence of an EEPROM, and then activate software access
1154 static int ks8851_eeprom_claim(struct ks8851_net
*ks
)
1156 if (!(ks
->rc_ccr
& CCR_EEPROM
))
1159 mutex_lock(&ks
->lock
);
1161 /* start with clock low, cs high */
1162 ks8851_wrreg16(ks
, KS_EEPCR
, EEPCR_EESA
| EEPCR_EECS
);
1167 * ks8851_eeprom_release - release the EEPROM interface
1168 * @ks: The device state
1170 * Release the software access to the device EEPROM
1172 static void ks8851_eeprom_release(struct ks8851_net
*ks
)
1174 unsigned val
= ks8851_rdreg16(ks
, KS_EEPCR
);
1176 ks8851_wrreg16(ks
, KS_EEPCR
, val
& ~EEPCR_EESA
);
1177 mutex_unlock(&ks
->lock
);
1180 #define KS_EEPROM_MAGIC (0x00008851)
1182 static int ks8851_set_eeprom(struct net_device
*dev
,
1183 struct ethtool_eeprom
*ee
, u8
*data
)
1185 struct ks8851_net
*ks
= netdev_priv(dev
);
1186 int offset
= ee
->offset
;
1190 /* currently only support byte writing */
1194 if (ee
->magic
!= KS_EEPROM_MAGIC
)
1197 if (ks8851_eeprom_claim(ks
))
1200 eeprom_93cx6_wren(&ks
->eeprom
, true);
1202 /* ethtool currently only supports writing bytes, which means
1203 * we have to read/modify/write our 16bit EEPROMs */
1205 eeprom_93cx6_read(&ks
->eeprom
, offset
/2, &tmp
);
1215 eeprom_93cx6_write(&ks
->eeprom
, offset
/2, tmp
);
1216 eeprom_93cx6_wren(&ks
->eeprom
, false);
1218 ks8851_eeprom_release(ks
);
1223 static int ks8851_get_eeprom(struct net_device
*dev
,
1224 struct ethtool_eeprom
*ee
, u8
*data
)
1226 struct ks8851_net
*ks
= netdev_priv(dev
);
1227 int offset
= ee
->offset
;
1230 /* must be 2 byte aligned */
1231 if (len
& 1 || offset
& 1)
1234 if (ks8851_eeprom_claim(ks
))
1237 ee
->magic
= KS_EEPROM_MAGIC
;
1239 eeprom_93cx6_multiread(&ks
->eeprom
, offset
/2, (__le16
*)data
, len
/2);
1240 ks8851_eeprom_release(ks
);
1245 static int ks8851_get_eeprom_len(struct net_device
*dev
)
1247 struct ks8851_net
*ks
= netdev_priv(dev
);
1249 /* currently, we assume it is an 93C46 attached, so return 128 */
1250 return ks
->rc_ccr
& CCR_EEPROM
? 128 : 0;
1253 static const struct ethtool_ops ks8851_ethtool_ops
= {
1254 .get_drvinfo
= ks8851_get_drvinfo
,
1255 .get_msglevel
= ks8851_get_msglevel
,
1256 .set_msglevel
= ks8851_set_msglevel
,
1257 .get_settings
= ks8851_get_settings
,
1258 .set_settings
= ks8851_set_settings
,
1259 .get_link
= ks8851_get_link
,
1260 .nway_reset
= ks8851_nway_reset
,
1261 .get_eeprom_len
= ks8851_get_eeprom_len
,
1262 .get_eeprom
= ks8851_get_eeprom
,
1263 .set_eeprom
= ks8851_set_eeprom
,
1266 /* MII interface controls */
1269 * ks8851_phy_reg - convert MII register into a KS8851 register
1270 * @reg: MII register number.
1272 * Return the KS8851 register number for the corresponding MII PHY register
1273 * if possible. Return zero if the MII register has no direct mapping to the
1274 * KS8851 register set.
1276 static int ks8851_phy_reg(int reg
)
1297 * ks8851_phy_read - MII interface PHY register read.
1298 * @dev: The network device the PHY is on.
1299 * @phy_addr: Address of PHY (ignored as we only have one)
1300 * @reg: The register to read.
1302 * This call reads data from the PHY register specified in @reg. Since the
1303 * device does not support all the MII registers, the non-existent values
1304 * are always returned as zero.
1306 * We return zero for unsupported registers as the MII code does not check
1307 * the value returned for any error status, and simply returns it to the
1308 * caller. The mii-tool that the driver was tested with takes any -ve error
1309 * as real PHY capabilities, thus displaying incorrect data to the user.
1311 static int ks8851_phy_read(struct net_device
*dev
, int phy_addr
, int reg
)
1313 struct ks8851_net
*ks
= netdev_priv(dev
);
1317 ksreg
= ks8851_phy_reg(reg
);
1319 return 0x0; /* no error return allowed, so use zero */
1321 mutex_lock(&ks
->lock
);
1322 result
= ks8851_rdreg16(ks
, ksreg
);
1323 mutex_unlock(&ks
->lock
);
1328 static void ks8851_phy_write(struct net_device
*dev
,
1329 int phy
, int reg
, int value
)
1331 struct ks8851_net
*ks
= netdev_priv(dev
);
1334 ksreg
= ks8851_phy_reg(reg
);
1336 mutex_lock(&ks
->lock
);
1337 ks8851_wrreg16(ks
, ksreg
, value
);
1338 mutex_unlock(&ks
->lock
);
1343 * ks8851_read_selftest - read the selftest memory info.
1344 * @ks: The device state
1346 * Read and check the TX/RX memory selftest information.
1348 static int ks8851_read_selftest(struct ks8851_net
*ks
)
1350 unsigned both_done
= MBIR_TXMBF
| MBIR_RXMBF
;
1354 rd
= ks8851_rdreg16(ks
, KS_MBIR
);
1356 if ((rd
& both_done
) != both_done
) {
1357 netdev_warn(ks
->netdev
, "Memory selftest not finished\n");
1361 if (rd
& MBIR_TXMBFA
) {
1362 netdev_err(ks
->netdev
, "TX memory selftest fail\n");
1366 if (rd
& MBIR_RXMBFA
) {
1367 netdev_err(ks
->netdev
, "RX memory selftest fail\n");
1374 /* driver bus management functions */
1376 #ifdef CONFIG_PM_SLEEP
1378 static int ks8851_suspend(struct device
*dev
)
1380 struct ks8851_net
*ks
= dev_get_drvdata(dev
);
1381 struct net_device
*netdev
= ks
->netdev
;
1383 if (netif_running(netdev
)) {
1384 netif_device_detach(netdev
);
1385 ks8851_net_stop(netdev
);
1391 static int ks8851_resume(struct device
*dev
)
1393 struct ks8851_net
*ks
= dev_get_drvdata(dev
);
1394 struct net_device
*netdev
= ks
->netdev
;
1396 if (netif_running(netdev
)) {
1397 ks8851_net_open(netdev
);
1398 netif_device_attach(netdev
);
1405 static SIMPLE_DEV_PM_OPS(ks8851_pm_ops
, ks8851_suspend
, ks8851_resume
);
1407 static int ks8851_probe(struct spi_device
*spi
)
1409 struct net_device
*ndev
;
1410 struct ks8851_net
*ks
;
1415 ndev
= alloc_etherdev(sizeof(struct ks8851_net
));
1419 spi
->bits_per_word
= 8;
1421 ks
= netdev_priv(ndev
);
1425 ks
->tx_space
= 6144;
1427 gpio
= of_get_named_gpio_flags(spi
->dev
.of_node
, "reset-gpios",
1429 if (gpio
== -EPROBE_DEFER
) {
1435 if (gpio_is_valid(gpio
)) {
1436 ret
= devm_gpio_request_one(&spi
->dev
, gpio
,
1437 GPIOF_OUT_INIT_LOW
, "ks8851_rst_n");
1439 dev_err(&spi
->dev
, "reset gpio request failed\n");
1444 ks
->vdd_io
= devm_regulator_get(&spi
->dev
, "vdd-io");
1445 if (IS_ERR(ks
->vdd_io
)) {
1446 ret
= PTR_ERR(ks
->vdd_io
);
1450 ret
= regulator_enable(ks
->vdd_io
);
1452 dev_err(&spi
->dev
, "regulator vdd_io enable fail: %d\n",
1457 ks
->vdd_reg
= devm_regulator_get(&spi
->dev
, "vdd");
1458 if (IS_ERR(ks
->vdd_reg
)) {
1459 ret
= PTR_ERR(ks
->vdd_reg
);
1463 ret
= regulator_enable(ks
->vdd_reg
);
1465 dev_err(&spi
->dev
, "regulator vdd enable fail: %d\n",
1470 if (gpio_is_valid(gpio
)) {
1471 usleep_range(10000, 11000);
1472 gpio_set_value(gpio
, 1);
1475 mutex_init(&ks
->lock
);
1476 spin_lock_init(&ks
->statelock
);
1478 INIT_WORK(&ks
->tx_work
, ks8851_tx_work
);
1479 INIT_WORK(&ks
->rxctrl_work
, ks8851_rxctrl_work
);
1481 /* initialise pre-made spi transfer messages */
1483 spi_message_init(&ks
->spi_msg1
);
1484 spi_message_add_tail(&ks
->spi_xfer1
, &ks
->spi_msg1
);
1486 spi_message_init(&ks
->spi_msg2
);
1487 spi_message_add_tail(&ks
->spi_xfer2
[0], &ks
->spi_msg2
);
1488 spi_message_add_tail(&ks
->spi_xfer2
[1], &ks
->spi_msg2
);
1490 /* setup EEPROM state */
1492 ks
->eeprom
.data
= ks
;
1493 ks
->eeprom
.width
= PCI_EEPROM_WIDTH_93C46
;
1494 ks
->eeprom
.register_read
= ks8851_eeprom_regread
;
1495 ks
->eeprom
.register_write
= ks8851_eeprom_regwrite
;
1497 /* setup mii state */
1500 ks
->mii
.phy_id_mask
= 1;
1501 ks
->mii
.reg_num_mask
= 0xf;
1502 ks
->mii
.mdio_read
= ks8851_phy_read
;
1503 ks
->mii
.mdio_write
= ks8851_phy_write
;
1505 dev_info(&spi
->dev
, "message enable is %d\n", msg_enable
);
1507 /* set the default message enable */
1508 ks
->msg_enable
= netif_msg_init(msg_enable
, (NETIF_MSG_DRV
|
1512 skb_queue_head_init(&ks
->txq
);
1514 ndev
->ethtool_ops
= &ks8851_ethtool_ops
;
1515 SET_NETDEV_DEV(ndev
, &spi
->dev
);
1517 spi_set_drvdata(spi
, ks
);
1519 ndev
->if_port
= IF_PORT_100BASET
;
1520 ndev
->netdev_ops
= &ks8851_netdev_ops
;
1521 ndev
->irq
= spi
->irq
;
1523 /* issue a global soft reset to reset the device. */
1524 ks8851_soft_reset(ks
, GRR_GSR
);
1526 /* simple check for a valid chip being connected to the bus */
1527 cider
= ks8851_rdreg16(ks
, KS_CIDER
);
1528 if ((cider
& ~CIDER_REV_MASK
) != CIDER_ID
) {
1529 dev_err(&spi
->dev
, "failed to read device ID\n");
1534 /* cache the contents of the CCR register for EEPROM, etc. */
1535 ks
->rc_ccr
= ks8851_rdreg16(ks
, KS_CCR
);
1537 if (ks
->rc_ccr
& CCR_EEPROM
)
1538 ks
->eeprom_size
= 128;
1540 ks
->eeprom_size
= 0;
1542 ks8851_read_selftest(ks
);
1543 ks8851_init_mac(ks
);
1545 ret
= request_threaded_irq(spi
->irq
, NULL
, ks8851_irq
,
1546 IRQF_TRIGGER_LOW
| IRQF_ONESHOT
,
1549 dev_err(&spi
->dev
, "failed to get irq\n");
1553 ret
= register_netdev(ndev
);
1555 dev_err(&spi
->dev
, "failed to register network device\n");
1559 netdev_info(ndev
, "revision %d, MAC %pM, IRQ %d, %s EEPROM\n",
1560 CIDER_REV_GET(cider
), ndev
->dev_addr
, ndev
->irq
,
1561 ks
->rc_ccr
& CCR_EEPROM
? "has" : "no");
1567 free_irq(ndev
->irq
, ks
);
1570 if (gpio_is_valid(gpio
))
1571 gpio_set_value(gpio
, 0);
1573 regulator_disable(ks
->vdd_reg
);
1575 regulator_disable(ks
->vdd_io
);
1582 static int ks8851_remove(struct spi_device
*spi
)
1584 struct ks8851_net
*priv
= spi_get_drvdata(spi
);
1586 if (netif_msg_drv(priv
))
1587 dev_info(&spi
->dev
, "remove\n");
1589 unregister_netdev(priv
->netdev
);
1590 free_irq(spi
->irq
, priv
);
1591 if (gpio_is_valid(priv
->gpio
))
1592 gpio_set_value(priv
->gpio
, 0);
1593 regulator_disable(priv
->vdd_reg
);
1594 regulator_disable(priv
->vdd_io
);
1595 free_netdev(priv
->netdev
);
1600 static const struct of_device_id ks8851_match_table
[] = {
1601 { .compatible
= "micrel,ks8851" },
1604 MODULE_DEVICE_TABLE(of
, ks8851_match_table
);
1606 static struct spi_driver ks8851_driver
= {
1609 .of_match_table
= ks8851_match_table
,
1610 .pm
= &ks8851_pm_ops
,
1612 .probe
= ks8851_probe
,
1613 .remove
= ks8851_remove
,
1615 module_spi_driver(ks8851_driver
);
1617 MODULE_DESCRIPTION("KS8851 Network driver");
1618 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
1619 MODULE_LICENSE("GPL");
1621 module_param_named(message
, msg_enable
, int, 0);
1622 MODULE_PARM_DESC(message
, "Message verbosity level (0=none, 31=all)");
1623 MODULE_ALIAS("spi:ks8851");