KSZ8895 PHY Driver Porting Guide v1.0

KSZ8895 PHY Driver Porting Guide v1.0
KSZ8895 Linux PHY Driver Porting Guide
Rev 1.0
January 11, 2013
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 1 -
 2013 Micrel Semiconductor
Table of Contents
1 2 3 4 Introduction.......................................................................................................................... 4 PHY Driver Source and Header File Description................................................................ 5 Porting KSZ8895 PHY Driver............................................................................................. 8 Running KSZ8895 PHY Driver......................................................................................... 14 Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 2 -
 2013 Micrel Semiconductor
Revision History
Revision
Date
Summary of Changes
1.0
11/19/12
Initial revision.
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 3 -
 2013 Micrel Semiconductor
1 Introduction
KSZ8895 Switch Device
The KSZ8895 (or KSZ8864) switch is an integrated 5-port (or 4-port) switch ICs. The port 5
(or port 4) can be interfaced as MII or RMII mode, connecting to a PHY or MAC device. For
the detail mode selection, please refer to KSZ8895 or KSZ8864 datasheet.
The KSZ8895 Linux PHY driver is for KSZ8895 or KSZ8864 as a PHY device driver to the
host processor MAC device.
PHY Abstraction Layer (PAL)
In Linux, the Physics Abstraction Layer provides a unified interface to a number of different
physical engines. For more information please see Documentation/networking/phy.txt in the
kernel source tree.
KSZ8895 PHY Device Driver
The KSZ8895 PHY driver follows Linux PAL standard, presents a generic frameworks which
can be used by any Ethernet MAC drivers to easily interface with the KSZ8895 PHY.
KSZ8895 PHY Management Interface
KSZ8895 Switch PHY registers can be accessed using "MDIO/MDC Interface" through the
Host MDIO/MDC controller. In additional to MDIO/MDC interface, SPI is available to
provide full access to the switch. Please see KSZ8895 (or KSZ8864) datasheet PS1/PS0 strap
pin option for how to configure KSZ8895/KSZ8864 management interface.
The KSZ8895 PHY driver is also a customer PHY driver. It allows user to access
KSZ8895/KSZ8864 PHY register either on MDIO/MDC, or SPI interface at KSZ8895 PHY’s
Kconfig selection.
The KSZ8895 PHY driver is developed base on linux 2.6.38. It works for KSZ8895 series
switch device which includes KSZ8895 or KSZ8864 switch.
The following section contains some information that developers can use when porting
KSZ8895 PHY driver to their Linux system.
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 4 -
 2013 Micrel Semiconductor
2 PHY Driver Source and Header File Description
Copy these files to your linux working directory as table description:
1. Using MDIO/MDC Interface:
Source file
ksz8895phy.c
ksz8895phy.h
ksz8895-Kconfig
Copy To
Linux/drivers/net/phy
Linux/drivers/net/phy
Linux/drivers/net/phy
2. Using SPI Interface:
Source file
ksz8895phy.c
ksz8895phy.h
ksz8895-spi.c
ksz8895-Kconfig
kswitch_spi.c
kswitch-spi-Kconfig
Copy To
Linux/drivers/net/phy
Linux/drivers/net/phy
Linux/drivers/net/phy
Linux/drivers/net/phy
Linux/drivers/spi
Linux/drivers/spi
 ksz8895phy.c
o Provide a MDIO bus probe function – set up things the bus driver needs, setup the
mii_bus struct, and register with PAL using mdiobus_register.
When setup mii_bus struct for PAL bus read and write function, initialize read and write
function pointer according to the management interfaces you selected from Kconfig.
For MDIO bus
read() → ksz8895_mii_read() : read KSZ8895 PHY register from MDIO/MDC bus.
write() → ksz8895_mii_write() : write to KSZ8895 PHY register from MDIO/MDC bus.
For SPI bus
read() → ksz8895_spibus_read() : read KSZ8895 PHY register from SPI or I2C bus.
write() → ksz8895_spibus_write() : write to KSZ8895 PHY register from SPI or I2C bus.
o Provide the I/O register read and write function pointer if MIIM interface is SPI bus.
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 5 -
 2013 Micrel Semiconductor
For SPI bus
read() → ksz8895_spi_nread() : read KSZ8895 internal register from SPI bus.
write() → ksz8895_spi_nwrite() : write to KSZ8895 internal register from SPI bus.
o Provide connecting to a PHY, during linux startup, the MAC network driver needs to
establish a connection between the KSZ8895 PHY device, and your network device. At
this time, PHY’s bus and drivers need to all have been loaded.
o Provide KSZ8895 PAL driver. This PAL handles everything, and only calls the network
driver when the link state changes, so MAC driver can react from adjust_link() callback
function.
o Provide KSZ8895 PHY interrupt handler if you select the SPI bus management interfaces
from Kconfig.
 ksz8895phy.h
KSZ8895 PHY driver header file, define all KSZ8895 or KSZ8864 Port default PHY
address.
 ksz8895-spi.c
o Since KSZ8895 Switch provides full-sized internal management registers, can be
accessed by SPI bus, but PHY register only can be accessed by MDIO bus, not SPI bus,
this file provides a mapping mechanism to convert between PHY register and full-sized
internal registers.
o Read and write function set up by the mii_bus struct on SPI bus to access PHY registers
by above PHY registers mapping.
o SPI I/O access read and write function issue I/O requests to the SPI device using linux
“struct spi_message” with “struct spi_transfer” for linux SPI protocol operation to
communicate with KSZ8895 SPI device driver through SPI master controller.
 ksz8895-Kconfig
KSZ8895 PHY Layer Configuration file.
o CONFIG_MICREL_KSZ8895PHY – select ‘Yes’ if you choice KSZ8895 or KSZ8864
serial switch as your MAC PHY device.
o CONFIG_KSPHY_FOR_KSZ8864 – select ‘Yes’ if your device is KSZ8864 serial
switch.
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 6 -
 2013 Micrel Semiconductor
o CONFIG_ KSPHY_MULTI_ETH – KSZ8895 is 5-port switch, and KSZ8864 is 4-port
switch. If you want treat the switch as multiple isolated logical Network adaptor, and
each port is maintained by a linux Network interface MAC driver, like eth0, then select
‘Yes’. Otherwise, don’t select, the switch is treated as a single PHY device.
o CONFIG_ KSPHY_BUS_MDIO – KSZ8895 PHY driver access PHY register by
MDIO/MDC bus.
o CONFIG_ KSPHY_BUS_SPI – KSZ8895 PHY driver access PHY register by SPI bus.
Note: You ONLY can select one of interfaces from MDIO, or SP.
 ksswitch_spi.c
KSZ8895 SPI device driver if you select the SPI bus management interfaces from Kconfig.
o Provide a SPI probe function – allows to be bind this SPI device driver to your target
board init file whose “struct spi_board_info” gave a modalias of “ksSwitch_0”.
o Register SPI device driver as character special device, major number 153 with a
dynamically chosen minor device number. This is the node that userspace program can
open, created.
o Supports access to KSZ8895 (as SPI device) registers on SPI bus using normal userspace
I/O calls or access by kernel KSZ8895 PHY driver.
o Micrel also provides a full set of Command Line Interface (CLI) utility running on Linux
userspace to configure KSZ8895/KSZ8864 switch through this SPI device driver. Please
ask your Micrel FAE to get the Switch CLI utility package – source code and user guide
if you need to configure Switch other than just PHY register.
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 7 -
 2013 Micrel Semiconductor
3 Porting KSZ8895 PHY Driver
This section provides information, tips and tricks that developers can use to bind KSZ8895
PHY driver to their MAC network driver on their target platform which either support
MDIO/MDC controller or SPI master controller.
After copying KSZ8895 PHY driver files to your linux working directory as described earlier.

Modify “KSZ8895_IRQ” definition in ksz8895phy.h to your host system irq number
depends on how you wired KSZ8895 INTR_N pin if you select the SPI bus management
interfaces from Kconfig.
#define KSZ8895_IRQ

(LOW_IRQS + KS8692_INT_EXT_INT0)
In your MAC network driver “probe” function, to connect KSZ8895 PAL, call this
function:
phydev = ksz8895_mii_connect(pdev, netdev, phy_addr, phy_mode );
o phydev is a pointer to the “struct phy_device” structure which represents the PHY. If
phy_connect is successful, it will return the pointer. Otherwise, it return a dummy PHY
pointer, link is always up, can’t configure PHY registers.
o pdev is a pointer to the “struct platform_device” structure from your platform device
struct that you need to provide.
o netdev is a pointer to the “struct net_device” structure from your network DEVICE
struct that you need to provide.
o phy_addr is KSZ8895 PHY address that you need to provide. By device default, “0x1”
for PHY1 (port 1) and “0x2” for PHY2 (port 2). If you don’t change default PHY
address,
Pass “0x01” for KSZ8895 device, when CONFIG_ KSPHY_MULTI_ETH=n;
Pass “0x02” for KSZ8864 device when CONFIG_ KSPHY_MULTI_ETH=n;
Pass “0x01” to connect to KSZ8895 PAL PHY 1 (port 1), pass “0x02” to PAL PHY 2
(port 2), pass “0x03” to PAL PHY 3 (port 3), pass “0x04” to PAL PHY 4 (port 4)
when CONFIG_ KSPHY_MULTI_ETH=y.
Pass “0x02” to connect to KSZ8864 PAL PHY 1 (port 1), pass “0x03” to PAL PHY 2
(port 2), pass “0x04” to PAL PHY 3 (port 3) when CONFIG_
KSPHY_MULTI_ETH=y.
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 8 -
 2013 Micrel Semiconductor
o phy_mode is how processor MAC connected to the KSZ8895 Switch through MII or
RMII interface that you need to provide.
Pass “PHY_INTERFACE_MODE_MII” if MII interface;
Pass “PHY_INTERFACE_MODE_RMII” if RMII interface.

In your MAC network driver “open” network device function, add call this function to
start KSZ8895 PAL state machine after your MAC device is ready to operation.
phy_start(phydev );
o phydev is a pointer return from ksz8895_mii_connect ().

In your MAC network driver “remove” network device function, add call this function to
stop KSZ8895 PAL state machine before stop your MAC device operation.
phy_stop(phydev );
o phydev is a pointer return from ksz8895_mii_connect ().

In your MAC network driver “remove” network device function, add call this function to
remove KSZ8895 PAL driver before remove your MAC driver.
ksz8895_mii_exit(pdev);
o pdev is a pointer to the “struct platform_device” structure from your platform device
struct that you need to provide.

Implement platform_mac_adjust_link(netdev), KSZ8895 PAL callback function for MAC
driver reaction when the link state changes, like, link up or down status, flow control
support feature.
By KSZ8895 default, MII/RMII interface is in 100BT speed and full duplex mode, always
set target MAC to these configuration – 100BT/Full duplex.
Refer to ksz9692_mac_adjust_link() as sample code base on Micrel KSZ9692 Soc LAN
MAC controller.
o netdev is a pointer to the “struct net_device” structure from your network DEVICE
struct.

Add following line into the “project/linux/drivers/net/phy/Kconfig”:
source " linux/drivers/net/phy/ksz8895-Kconfig"
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 9 -
 2013 Micrel Semiconductor

Add following lines into the “linux/drivers/net/phy/Makefile” to include compilation of the
KSZ8895 PHY driver file:
obj-$(CONFIG_MICREL_KSZ8895PHY) += ksz8895phy.o
obj-$(CONFIG_KSPHY_BUS_SPI) += ksz8895-spi.o

Invoke kernel menuconfig to select the KSZ8895 PHY driver to be build into kernel:
Select Device Drives → Select Network device support → Select PHY devicesupport and
infrastructure → Select Driver for Micrel KSZ8895 Switch PHYs
Then
If KSZ8895 PHY Management Interface is MDIO bus through your platform MDIO
controller,
Select MDIO bus driver for Micrel KSZ8895 Switch PHYs
If KSZ8895 PHY Management Interface is SPI bus through your platform SPI controller,
Select SPI bus driver for Micrel KSZ8895 Switch PHYs
If your device is KSZ8864,
Select Driver for Micrel KSZ8864 Switch PHYs
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 10 -
 2013 Micrel Semiconductor
If you select the MDIO bus management interfaces from Kconfig:

Implement read and write function. Read and write function is dependant on your target
MDIO driver.
Refer to ksz9692_mdio_read() and ksz9692_mdio_write() as sample code base on Micrel
KSZ9692 Soc MDIO controller.
static int platform_mdio_read(struct mii_bus *bus, int phy_id, int regnum);
static int platform_mdio_write(struct mii_bus *bus, int phy_id, int regnum, u16 val);
o bus is a pointer to the “struct mii_bus”.
o phy_id is PHY address.
o regnum is PHY register offset.
o val is value going to write PHY register.
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 11 -
 2013 Micrel Semiconductor
If you select the SPI bus management interfaces from Kconfig:

Copy following code to your target board init file bind this KSZ8895 SPI device driver to
your target board. The target board init file is usually at “arch/.../mach-*/board-*.c”.
#if defined(CONFIG_SPI_KSSWITCH) || defined(CONFIG_SPI_KSSWITCH_MODULE)
/* SPI userspace device driver to access ks8692 spi master controller */
static struct ks8692_spi_tranf_config spi_ks8692_chip = {
.operation
= SPI_PREPARE_TO_READ,
.read_len
= 2,
};
static struct spi_board_info ksswitch_info[] __initdata = {
[0] = {
.modalias
= "ksSwitch_0",
.max_speed_hz = 12000000,
/* 12MHZ */
.chip_select
= 0,
.bus_num
= 0,
.mode
= SPI_MODE_3,
.controller_data = &spi_ks8692_chip,
},
};
static int __init pegasus_spi_init(void)
{
spi_register_board_info(ksswitch_info, ARRAY_SIZE(ksswitch_info));
return 0;
}
arch_initcall(pegasus_spi_init);
#endif
You need to modify following parameters which are depended on your SPI master
controller.
o max_speed_hz is a SPI clock that SPI master generate. The maximum SPI clock that
KSZ8895 SPI can support is 25Mhz.
o bus_num is SPI bus number that KSZ8895 SPI device is assigned from your SPI
master controller configuration. It might be not ‘0’ if your SPI controller have multiple
SPI controllers.
o chip_select is SPI_CS number that KSZ8895 SPI device is assigned from your SPI
master controller configuration. It might be not ‘0’ if your SPI controller have multiple
SPI channels per SPI controller.
o controller_data is private controller data is need by your SPI master controller
hardware setup. Set to ‘NULL’ if not need private controller data for your SPI master
controller.
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 12 -
 2013 Micrel Semiconductor

Add following line into “project/linux/drivers/spi/Makefile” to build ksswitch_spi driver
to linux kernel.
obj-$(CONFIG_SPI_KSSWITCH) += ksswitch_spi.o

Add following line into your “project/linux/drivers/spi/Kconfig”:
source "drivers/spi/ksswitch-spi-Kconfig"

Invoke kernel menuconfig to select the build ksswitch_spi driver to be build into kernel:
Select Device Drives → Select SPI supports → Select User mode Micrel Switch SPI device
driver support

Please refer “Micrel Switch CLI User Guide” on how to build KSZ8895or KSZ8864 CLI
utility running in the Linux userspace from the Switch CLI utility package.
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 13 -
 2013 Micrel Semiconductor
4 Running KSZ8895 PHY Driver
After you finished porting by above section according to your KSZ8895 PHY bus interface,
you should see following KSZ8895 PHY driver hooking up status message at linux booting:
If you select the MDIO bus management interfaces from Kconfig:
KSZ8895 PHY driver version 1.0.0 on mdio_bus
eth0: attached PHY driver [Micrel KSZ8895 or KSZ8864] (mdio_bus:phy_addr=mdio:01,
irq=-2)
If you select the SPI bus management interfaces from Kconfig:
KSZ8895 PHY driver version 1.0.1 on spi_bus
eth0: attached PHY driver [Micrel KSZ8895 or KSZ8864] (spi_bus:phy_addr=mdio:01,
irq=34)
Confidential Information
2180 Fortune Drive, San Jose CA95131, USA (408)944-0800  http://www.micrel.com
- Page 14 -
 2013 Micrel Semiconductor
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement