smart210驱动(2) hello驱动-platform

Makefile

TARGET	:= hello_drv

obj-m	+= $(TARGET).o

ROOTFS	= /home/flinn/smart210-SDK/fs/drv
KERNEL	= /home/flinn/smart210-SDK/linux-3.10.79

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

clean:
	make -C $(KERNEL) M=`pwd` clean

install:
	sudo cp $(TARGET).ko $(ROOTFS)

make.sh

#!/bin/bash

echo -e "\e[1;31m##make clean \e[0m"
make clean

echo -e "\e[1;31m##make \e[0m"
make

echo -e "\e[1;31m##make install \e[0m"
make install

hello_dev.c

/*
* linux-3.10.27
* arm-linux-gcc-4.5.1
*
* @ hello driver
*/

#include <linux/module.h>
#include <linux/init.h>   /* module_init, ... */
#include <linux/kernel.h> /* everything */

#include <linux/cdev.h>   /* cdev_init, ... */
#include <linux/fs.h>     /* file_operations,  */
#include <linux/device.h>  /* class_create,... */
#include <linux/platform_device.h>


static void	hello_release(struct device *dev)
{
    /* 如果没有定义release, 加载会出错 */
}

static struct platform_device hello_dev = 
{
	.name = "hello",
	.dev = {
		.release = hello_release,    /* must BE */
	},
};

static int hello_dev_init(void)
{
	pr_info("%s called.\n", __func__);
	
	platform_device_register(&hello_dev);

	return 0;
}

static void hello_dev_exit(void)
{	
	pr_info("%s called.\n", __func__);
	
	platform_device_unregister(&hello_dev);
}

module_init(hello_dev_init);
module_exit(hello_dev_exit);
MODULE_LICENSE("GPL");

 

hello_drv.c

/*
* linux-3.10.27
* arm-linux-gcc-4.5.1
*
* @ hello driver
*/

#include <linux/module.h>
#include <linux/init.h>   /* module_init, ... */
#include <linux/kernel.h> /* everything */

#include <linux/cdev.h>   /* cdev_init, ... */
#include <linux/fs.h>     /* file_operations,  */
#include <linux/device.h>  /* class_create,... */
#include <linux/platform_device.h>

#define DEVICE_NAME		"hello"
struct priv_data
{
	char *name;

	int major;
	dev_t dev;
	struct cdev *cdev;
	struct class *pri_class;
};

static int hello_probe(struct platform_device *pdev)
{
	pr_info("%s called.\n", __func__);
	
	return 0;
}

static int hello_remove(struct platform_device *pdev)
{
	pr_info("%s called.\n", __func__);

	return 0;
}

static struct platform_driver hello_drv = 
{
	.driver = {
		.name = "hello",
		.owner = THIS_MODULE
	},

	.probe = hello_probe,
	.remove = hello_remove,
};

static int hello_drv_init(void)
{
	pr_info("%s called.\n", __func__);

	platform_driver_register(&hello_drv);
	return 0;
}

static void hello_drv_exit(void)
{
	pr_info("%s called.\n", __func__);

	platform_driver_unregister(&hello_drv);
}

module_init(hello_drv_init);
module_exit(hello_drv_exit);
MODULE_LICENSE("GPL");

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值