Linux enc28j60网卡驱动移植(硬件spi和模拟spi)(2)

/* [cgw]:  */
static struct s3c2410_spigpio_info spi_dev = {
    .pin_clk = S3C2410_GPG7,
    .pin_mosi = S3C2410_GPG6,
    .pin_miso = S3C2410_GPG5,
    .board_size = 1,                    /* [cgw]: 设置板上spi接口数量为1 */
    .board_info = &board_info[0],
    .chip_select = enc28j60_chip_select
};

static void spi_dev_release(struct device * dev)
{
    printk("spi_dev_release! \n");
}

/* [cgw]: 分配一个平台设备 */
static struct platform_device spi_platform_dev = {
    .name        = "s3c24xx-spi-gpio",        /* [cgw]: 设置平台设备名,和平台驱动名对应 */
    .id          = -1,
    .dev = {
        .release = spi_dev_release,
        .platform_data = (void *)&spi_dev,      /* [cgw]: 通过platform_data传递spi_dev给平台驱动
                                                * 平台驱动可以访问spi_dev
                                                */
    },
};


static int spi_dev_init(void)
{
    s3c2410_gpio_cfgpin(S3C2410_GPF2, S3C2410_GPF2_EINT2);

/* [cgw]: 注册spi_platform_dev平台设备 */
    platform_device_register(&spi_platform_dev);
    return 0;
}

static void spi_dev_exit(void)
{
    /* [cgw]: 注销spi_platform_dev平台设备 */
    platform_device_unregister(&spi_platform_dev);
}

module_init(spi_dev_init);
module_exit(spi_dev_exit);

MODULE_LICENSE("GPL");

makefile:

KERN_DIR = /work/system/linux-2.6.22.6

all:
    make -C $(KERN_DIR) M=`pwd` modules

clean:
    make -C $(KERN_DIR) M=`pwd` modules clean
    rm -rf modules.order

obj-m    += spi_platform_dev.o
obj-m    += spi_s3c24xx_gpio.o
obj-m    += spi_bitbang.o
obj-m    += enc28j60.o

硬件spi的模式下的spi_platform_dev.c

#include <linux/module.h>
#include <linux/version.h>

#include <linux/init.h>

#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/interrupt.h>
#include <linux/list.h>
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/serial_core.h>
#include <linux/platform_device.h>
#include <linux/irq.h>

#include <asm/gpio.h>
#include <asm/io.h>
#include <asm/arch/regs-gpio.h>

#include <linux/spi/spi.h>
#include <linux/spi/spi_bitbang.h>

#include <asm/arch/regs-spi.h>
#include <asm/arch/spi.h>
#include <asm/arch/spi-gpio.h>


/* SPI (1) */

static struct resource s3c_spi1_resource[] = {
    [0] = {
        .start = S3C2410_PA_SPI + S3C2410_SPI1,
        .end  = S3C2410_PA_SPI + S3C2410_SPI1 + 0x1f,
        .flags = IORESOURCE_MEM,
    },
    [1] = {
        .start = IRQ_SPI1,
        .end  = IRQ_SPI1,
        .flags = IORESOURCE_IRQ,
    }

};


static struct spi_board_info board_info[1] = {
    {
    .modalias = "enc28j60",    /* [cgw]: spi设备名,和设备驱动名对应 */
    .bus_num = 0,                /* [cgw]: spi总线号,即spi0 */
    .chip_select = 2,            /* [cgw]: spi总线上的设备号,即spi0.2 */
    .max_speed_hz    = 50000,    /* [cgw]: spi时钟 */
    .mode = SPI_MODE_0,          /* [cgw]: spi数据模式 */
    .irq = IRQ_EINT2,
    },
};

static struct s3c2410_spi_info spi_info = {
    .pin_cs = S3C2410_GPG2,    /* simple gpio cs */
    .board_size = ARRAY_SIZE(board_info),
    .board_info = &board_info[0],
    .set_cs = NULL
};


static void spi_dev_release(struct device * dev)
{
    printk("spi_dev_release! \n");
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/f35ac51569f8836409444b2e674f14c2.html