设为首页 加入收藏

TOP

在f1c100s芯片上移植spi网卡enc28j60的linux驱动(一)
2023-09-09 10:25:37 】 浏览:167
Tags:f1c100s spi 网卡 enc28j60 linux 驱动

前言

我个人与全志的芯片颇有故事。在我还是一个不懂事的高中生时,我看到荔枝派的官方文档,顿时被这小小的板子给吸引住。点开文档的初见:

荔枝派Nano(下面简称Nano)是一款精致迷你的 Arm9 核心板/开发板,可用于初学者学习linux或者商用于产品开发。 Nano 在与SD卡相当的尺寸上(25.4 * 33mm)提供了丰富的外设 (LCD,UART,SPI,I2C,PWM,SDIO,KEYADC...)和较为强劲的性能(24M~408MHz, 32MB DDR)。
Nano 延续并发展了Zero精巧的PCB设计,使得开发和使用非常方便:

2.54mm排针直插面包板
直插40P RGB LCD
使用OTG口进行供电和数据传输(虚拟串口,更新固件等)
可配合使用使用堆叠式的WiFi 模块联网
?可直接贴片

当时高一的我连什么是单片机和微处理器都分不清楚,只觉得好神奇,居然有这样一种单片机,性能居然这么强悍,芯片封装那么小,还能跑linux?于是速速下单买了一块荔枝派回来。拿到手也不咋会用,照着教程不是报错就是缺库,再加上学业繁重,就放在那吃灰了。

后来高二暑假,再次捡起这块板子,把uboot编译了,又把磕磕碰碰地把linux的设备树照抄过来,磕磕碰碰地开了两个窗口照抄内核配置。当时就是喜欢配内核,配来配去,虽然这个过程非常操蛋,但是当终于解决了好多文档里根本不提的问题(比如说regulator必须要在内核配置中打开等)后,又觉得人生十分圆满,我终于会搞嵌入式linux了。21年的高二暑假把内核和rootfs配好后,手上刚好又有个为了给单片机提供以太网用的enc28j60模块。刚好点开linux的menuconfig,也发现内核支持这个模块,从此就和enc28j60结下了梁子。

我用的内核版本是5.4

第一次移植过程

在我脑海中,我依稀记得当初有多稚嫩。我在whycan上翻来翻去,总算知道了给linux内核加驱动要改设备树。然后我去翻了半天linux的documentation,却还是没搞懂设备树到底要怎么写。这不纯纯坑人+浪费时间吗?当时高二期末考试前没事干,就用电脑一直翻torvalds/linux仓库的源码,把enc28j60的源码看了,看不懂,又去看设备树的源代码,那个更加是天书,不知道在说个啥。后来放假了,就动手开始移植,我首先打开了linux/Documentation/devicetree/bindings/net/microchip,enc28j60.txt,这个是驱动开发者为我们留下的文档,让我们看看他说了个啥

* Microchip ENC28J60

This is a standalone 10 MBit ethernet controller with SPI interface.

For each device connected to a SPI bus, define a child node within
the SPI master node.

Required properties:
- compatible: Should be "microchip,enc28j60"
- reg: Specify the SPI chip select the ENC28J60 is wired to
- interrupts: Specify the interrupt index within the interrupt controller (referred
              to above in interrupt-parent) and interrupt type. The ENC28J60 natively
              generates falling edge interrupts, however, additional board logic
              might invert the signal.
- pinctrl-names: List of assigned state names, see pinctrl binding documentation.
- pinctrl-0: List of phandles to configure the GPIO pin used as interrupt line,
             see also generic and your platform specific pinctrl binding
             documentation.

Optional properties:
- spi-max-frequency: Maximum frequency of the SPI bus when accessing the ENC28J60.
  According to the ENC28J80 datasheet, the chip allows a maximum of 20 MHz, however,
  board designs may need to limit this value.

The MAC address will be determined using the optional properties
defined in ethernet.txt.

Example (for NXP i.MX28 with pin control stuff for GPIO irq):

        ssp2: ssp@80014000 {
                compatible = "fsl,imx28-spi";
                pinctrl-names = "default";
                pinctrl-0 = <&spi2_pins_b &spi2_sck_cfg>;

                enc28j60: ethernet@0 {
                        compatible = "microchip,enc28j60";
                        pinctrl-names = "default";
                        pinctrl-0 = <&enc28j60_pins>;
                        reg = <0>;
                        interrupt-parent = <&gpio3>;
                        interrupts = <3 IRQ_TYPE_EDGE_FALLING>;
                        spi-max-frequency = <12000000>;
                };
        };

        pinctrl@80018000 {
                enc28j60_pins: enc28j60_pins@0 {
                        reg = <0>;
                        fsl,pinmux-ids = <
                                MX28_PAD_AUART0_RTS__GPIO_3_3    /* Interrupt */
                        >;
                        fsl,drive-strength = <MXS_DRIVE_4mA>;
                        fsl,voltage = <MXS_VOLTAGE_HIGH>;
                        fsl,pull-up = <MXS_PULL_DISABLE>;
                };
        };

我们发现配置好enc28j60模块,首先我们需要一个能用的spi设备节点。然后把我们的以太网设备挂在这个节点下,并且为它指定外部中断引脚。
于是我便照猫画虎,靠着代码能力把这一部分设备树的代码移植了过去。我知道这个设备树代码的意图是啥,但有的谜语是真的想不通:

  • 什么是ssp?我猜应该是spi吧
  • 为什么&ssp2enc28j60节点下都要塞一个pinctrl-names and pinctrl-0,这些是干嘛的
  • 为什么enc28j6
首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇使用Yocto进行嵌入式Linux开发3 T.. 下一篇S905L3A(M401A)拆解, 运行EmuELEC..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目