GS270驱动

低电平开机
 开机前 :poweron高电平       
 开机      :poweron  低电平
 开机后 :poweron高电平

poweron  高---低---高

=============================================================

1. sys_config1.fex添加字段

[2g_para]
2g_used                  = 1
2g_name                = "GS270"
2g_reset                 = port:PG10<1><default><default><0>
2g_poweron          = port:power2<1><0><default><1>
2g_wakeup            =

2.在init.sun5i.rc添加下面启动代码

 on boot

    #insmod gs270  driver
    insmod /system/vendor/modules/gs270.ko

3.在 linux/driver/misc下面添加 mkfile  kconfig

 

#ifndef __GS270_H__
#define __GS270_H__

#include <linux/ioctl.h>
#include <mach/sys_config.h>

struct gs270_config {
	char name[32];
	user_gpio_set_t power_io;
	user_gpio_set_t reset_io;
	user_gpio_set_t wake_io;
};



#endif /* __GS270_H__ */

4. 重点gs270.C文件

 

在gs270_init函数中注册

   ret = platform_device_register(&gs270_device);
   ret = platform_driver_register(&gs270_driver);

注册后会执行probe函数。

在gs270_exitt函数中注销

  platform_driver_unregister(&gs270_driver);
  platform_device_unregister(&gs270_device);

----------------------------------------------------------------------------

/*
 * Copyright (C) 2010 MEMSIC, Inc.
 *
 * Initial Code:
 *	Robbie Cao
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/jiffies.h>
#include <linux/miscdevice.h>
#include <linux/mutex.h>
#include <linux/mm.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include <linux/sysctl.h>
#include <asm/uaccess.h>
#include <linux/hrtimer.h>

#include "gs270.h"
#include <linux/platform_device.h>
#include "../power/axp_power/axp-gpio.h"

#define DEBUG			0
#define GS270_DEV_NAME	"gs270"
int gs270_used = 0;
struct gs270_config  gs270;

static int fetch_config()
{
	int input_num,ret;
	
	/* fetch device quatity issue */
	memset(gs270.name,0,32);

	ret = script_parser_fetch("2g_para","2g_name", gs270.name , 32);
	if (ret) {
		printk("kevin 2g_name				 \n");
	}	
     
	 printk("kevin 2g_name	gs270.name =%s			  \n",gs270.name );

	/* fetch reset/power/standby/flash/af io issue */
	ret = script_parser_fetch("2g_para","2g_reset", (int *)&gs270.reset_io , sizeof(user_gpio_set_t)/sizeof(int));
	if (ret) {
		printk("kevin csi_reset				 \n");
	}

	/* fetch reset/power/standby/flash/af io issue */
	ret = script_parser_fetch("2g_para","2g_poweron", (int *)&gs270.power_io , sizeof(user_gpio_set_t)/sizeof(int));
	if (ret) {
		printk("kevin 	gs270.power_io.port =%d		gs270.power_io.port_num =%d \n",gs270.power_io.port,gs270.power_io.port_num);
	}
	
	printk("kevin	gs270.power_io.port =%d 	gs270.power_io.port_num =%d \n",gs270.power_io.port,gs270.power_io.port_num);
	/* fetch reset/power/standby/flash/af io issue */
	ret = script_parser_fetch("2g_para","2g_wakeup", (int *)&gs270.wake_io , sizeof(user_gpio_set_t)/sizeof(int));
	if (ret) {
		printk("kevin 2g_wakeup				 \n");
	}

	return 0;
}

static int gs270_platform_probe(struct platform_device *pdev) 
{
	int res = 0;
	printk("kevin gs270_platform_probe                \n");
	fetch_config();
#if 0
	
	res = misc_register(&gs270_device);
	if (res) {
		printk("%s: gs270_device register failed\n", __FUNCTION__);
		goto out;
	}
	res = device_create_file(GS270_DEV_NAME, &dev_attr_gs270);
	if (res) {
		printk("%s: device_create_file failed\n", __FUNCTION__);
		goto out_deregister;
	}

#endif
	if(gs270.power_io.port == 0xffff) {
	  axp_gpio_set_io(gs270.power_io.port_num, 1);
	  axp_gpio_set_value(gs270.power_io.port_num,0); 
	}
	msleep(500);
	msleep(500);
	msleep(500);
	
	msleep(500);
	msleep(500);
	msleep(500);
	
	msleep(500);
	msleep(500);
	msleep(500);
	if(gs270.power_io.port == 0xffff) 
	axp_gpio_set_value(gs270.power_io.port_num,1); 
	
	return 0;
out:
	return res;
}

static int gs270_platform_remove(struct platform_device *pdev)
{
#if 0
	device_remove_file(GS270_DEV_NAME, &dev_attr_gs270);
	misc_deregister(&gs270_device);
#endif
	return 0;
}

static void gs270_platform_shutdown(struct platform_device *pdev) 
{
    return ;
}
static int gs270_platform_suspend(struct platform_device *pdev, pm_message_t state) 
{
    printk("kevin gs270_platform_suspend                \n");
    return 0;
}
static int gs270_platform_resume(struct platform_device *pdev)
{
    printk("kevin gs270_platform_resume                \n");
    return 0;
}
#if 0
/*----------------------------------------------------------------------------*/
static struct platform_driver gs270_driver = {
	.probe      = gs270_platform_probe,
	.remove     = gs270_platform_remove,    
	.shutdown   = gs270_platform_shutdown,
	.suspend    = gs270_platform_suspend,
	.resume     = gs270_platform_resume,
		
	.driver     = {
		.name  = "gs270",
		.owner = THIS_MODULE,
	}
};
#endif

static struct platform_driver gs270_driver = {
	.probe		= gs270_platform_probe,
	.remove		= __devexit_p(gs270_platform_remove),
	.shutdown	= gs270_platform_shutdown,
	.suspend	= gs270_platform_suspend,
	.resume 	= gs270_platform_resume,
	.driver		= {
		.name	= "gs270",
		.owner	= THIS_MODULE,
	},
};


static struct platform_device gs270_device = { 
    .name = "gs270",
    .dev = { 
            .platform_data = &gs270,
    }   
};

static int __init gs270_init(void)
{
	int ret = 0;
	ret = script_parser_fetch("2g_para","2g_used", &gs270_used, sizeof(int));
	printk(" gs270_used =%d \n",gs270_used);
	if (ret) {
        printk("[switch]switch_headset init fetch para using configuration failed\n");
        return -1;
    }
    if (gs270_used) {
		ret = platform_device_register(&gs270_device);
		if (ret == 0) {
			ret = platform_driver_register(&gs270_driver);
		}
	} else {
		printk("[switch]switch headset cannot find any using configuration for controllers, return directly!\n");
		return 0;
	}
	return ret;
}

static void __exit gs270_exit(void)
{
	printk("enter:%s,line:%d\n", __func__, __LINE__);
	if (gs270_used) {
		gs270_used = 0;
		platform_driver_unregister(&gs270_driver);
		platform_device_unregister(&gs270_device);
	
	}
}

module_init(gs270_init);
module_exit(gs270_exit);

MODULE_AUTHOR("kevin xiao<kevin.xxbo@gmail.com>");
MODULE_DESCRIPTION("MEMSIC gs270 gprs Driver");
MODULE_LICENSE("GPL");


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值