GS270驱动

来源:互联网 发布:快压for mac 编辑:程序博客网 时间:2024/05/17 12:04
低电平开机
 开机前 :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 DEBUG0#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_namegs270.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 =%dgs270.power_io.port_num =%d \n",gs270.power_io.port,gs270.power_io.port_num);}printk("kevings270.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 0res = 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;}#endifif(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 0device_remove_file(GS270_DEV_NAME, &dev_attr_gs270);misc_deregister(&gs270_device);#endifreturn 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,}};#endifstatic 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");


 

原创粉丝点击