LAN969x I2C

1. LAN969x I2C

1.1. SoC Resources

LAN969X SoC have 4 FLEXCOMs (Flexible Serial Communication Controller). Each flexcom supports three serial communication protocols that includes

  1. USART(Universal Synchronous Asynchronous Receiver Transceiver).

  2. SPI(Serial Peripheral Interface).

  3. TWI(Two-wire Interface) or I2C(Inter Integrated Circuit).

In order to use a I2C interface, a specific flexcom should be configured in I2C mode.

1.2. Kernel configurations

Following kernel config options should be enabled to use LAN969x I2C interface:

  • CONFIG_MFD_ATMEL_FLEXCOM - Flexcom driver config option.

  • CONFIG_I2C_AT91 - I2C driver config option.

  • Corresponding flash driver should be enabled. Below example explains I2C with a EEPROM device for which CONFIG_EEPROM_AT24 config option is required.

1.3. Devicetree Configuration

To use I2C interface, following configurations are required in device tree.

  • Each of the flexcom flx0, flx1, flx2 and flx3 nodes can be configured in I2C mode ATMEL_FLEXCOM_MODE_TWI to use I2C interface.

  • compatible string must be set to microchip,sam9x60-i2c.

  • reg property must be set with register address and length as <0x600 0x200>

  • GPIO pins for TXD, RXD should be configured to pinctrl-0 property.. List of possible pin mappings are as in below table:

FLEXCOM ID ALT Mode RXD pin TXD pin

flx0

ALT 2

GPIO3

GPIO4

flx2

ALT 3

GPIO15

GPIO16

flx1

ALT 2

GPIO28

GPIO29

flx3

ALT 2

GPIO55

GPIO56

flx2

ALT 1

GPIO65

GPIO66

  • interrupts property must set with interrupt details. Interrupt lines[CPU INTR] corresponding to a flexcom must be configured as defined in below table:

FLEXCOM ID Shared Peripheral Interrupt CPU INTR

flx0

78

46

flx1

79

47

flx2

80

48

flx3

81

49

Note that Shared peripheral interrupt lines start at index ID32. So, CPU INTR must be calculated as [Shared peripheral interrupt number - 32].

  • Input clock clocks property must be set to &fabric_clk. Note that Fabric clock (250Mhz) is clock used by AXI, AHB fabric and APB bridges which connects all peripherals. clock-names must be set to usart.

  • GPIO flexcom shared pins should be configured as per board design.

1.3.2. Example

Following example shows how a flexcom I2C should be defined in DT to use SFP devices via an i2c MUX on the EVB-LAN9696-24port board:

/ {
&flx3 {
	atmel,flexcom-mode = <ATMEL_FLEXCOM_MODE_TWI>;
	status = "okay";

	i2c3: i2c@600 {
		pinctrl-0 = <&fc3_pins>;
		pinctrl-names = "default";
		i2c-analog-filter;
		i2c-digital-filter;
		i2c-digital-filter-width-ns = <35>;
		i2c-sda-hold-time-ns = <1500>;
		status = "okay";
	};
};

&gpio {
	fc3_pins: fc3-pins {
		pins = "GPIO_55", "GPIO_56";
		function = "fc";
	};
};

1.4. UserSpace

1.4.1. Confirm instances are created

The SFP devices are assigned each to a separate channel by the I2C controller, so you will be able to see 4 devices besides the 2c controller and the i2c mux.

# cat /sys/bus/i2c/devices/i2c-0/i2c-1/name
i2c-0-mux (chan_id 0)

The i2cdetect tool will also list all the devices:

# i2cdetect -l
i2c-3   i2c             i2c-0-mux (chan_id 2)                   I2C adapter
i2c-1   i2c             i2c-0-mux (chan_id 0)                   I2C adapter
i2c-4   i2c             i2c-0-mux (chan_id 3)                   I2C adapter
i2c-2   i2c             i2c-0-mux (chan_id 1)                   I2C adapter
i2c-0   i2c             AT91                                    I2C adapter
i2c-5   i2c             i2c-0-mux (chan_id 7)                   I2C adapter

1.4.2. Show the SFP eeprom

This dumps the content of one of the SFP eeproms, to verify that the device is accessible:

# i2cdump 0 0x50
i2cdump: WARNING! This program can confuse your I2C bus
Continue? [y/N] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 03 04 21 01 00 00 00 00 04 00 00 00 67 00 00 00    ??!?....?...g...
10: 00 00 01 00 46 53 20 20 20 20 20 20 20 20 20 20    ..?.FS
20: 20 20 20 20 00 00 40 20 53 46 50 50 2d 50 43 30        ..@ SFPP-PC0
30: 31 20 20 20 20 20 20 20 41 20 20 20 00 00 00 29    1       A   ...)
40: 00 00 00 00 46 32 30 31 31 31 33 35 31 39 36 2d    ....F2011135196-
50: 31 20 20 20 32 30 30 39 32 39 20 20 00 00 00 77    1   200929  ...w
60: 37 34 30 2d 30 33 31 38 35 32 20 52 45 56 20 30    740-031852 REV 0
70: 31 20 ff ff ff ff ff ff ff ff ff ff ff ff ff 00    1 ..............
80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
#