Android under Debug 3G Gpio control 3G Power on

Source: Internet
Author: User

If you are developing your own board, you need to use the GPIO pin to control the 3G module boot/shutdown, the following article will be helpful to you, is the processor IMX6 and ZTE MG3732 module as an example.

One, pin connection

The processor's gpio3_gpio[9] connects the on/off (29) pin of the 3G module to control the power on/off of the 3G.

Second, switch machine conditions

The On/off pin is turned on continuously 2500~3500 milliseconds low, and the on/ off pins are switched off continuously 2500~3500 milliseconds low.

Third, Gpio driver

gpio_3g.c  

#include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/fs.h > #include <linux/cdev.h> #include <linux/device.h> #include <asm/io.h> #include <linux/mm.h > #include <asm/uaccess.h> #include <linux/gpio.h> #define Gpio_iof_magic 0xd0#define 3g_input _io (gpio_ iof_magic,8) #define 3g_output _io (gpio_iof_magic,9) #define 3G_ON_OFFIMX_GPIO_NR (3,9)//Control pin: Gpio3[9]module_ LICENSE ("GPL"), int gpio_major=2555;int gpio_minor=0;int number_devices=1;struct Cdev gpiocdev;struct class *my_class; static int Gpio_open (struct inode *inode,struct file *file) {PRINTK (kern_info "Gpio device opened\n"); if (gpio_direction_  Output (3g_on_off,0x00) <0) {PRINTK ("3g_on_off Set Direction failed\n");} return 0;} Static long gpio_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {int VAL;PRINTK ("Gpio:ioctl running....\n"); Switch (CMD) {case 3g_input:if (gpio_direction_input (3g_on_off) <0) {PRINTK ("3g_on_off set INPUT failed\n");} If(arg>0) {Gpio_set_value (3g_on_off,0x01);} Else{gpio_set_value (3g_on_off,0x00);} Val=gpio_get_value (3g_on_off);p RINTK ("3g_on_off ioctl val=%d\n", Val); Break;case 3g_output:if (Gpio_direction_ Output (3g_on_off,0x00) <0) {PRINTK ("3g_on_off Set Direction failed\n");} if (arg>0) {gpio_set_value (3g_on_off,0x01);} Else{gpio_set_value (3g_on_off,0x00);} Val=gpio_get_value (3g_on_off);p RINTK ("3g_on_off ioctl val=%d\n", Val); BREAK;DEFAULT:PRINTK ("Cmd is not exist\n"); return-1;} return Val;}  static int gpio_release (struct inode *inode, struct file *file) {PRINTK (kern_info "Gpio device closed\n"); return 0;} struct File_operations gpio_fops = {. Owner=this_module,.open=gpio_open,.release=gpio_release,.unlocked_ioctl=gpio_ ioctl,};static void Char_reg_setup_cdev (void) {int error;dev_t devno;devno=mkdev (gpio_major,gpio_minor); Cdev_init ( &gpiocdev,&gpio_fops); Gpiocdev.owner=this_module;error=cdev_add (&gpiocdev,devno,1); if (error) PRINTK (kern_notice "error%d adding char device GPIO", Error);} Static INT __init gpio_init (void) {int result;dev_t devno;devno=mkdev (gpio_major,gpio_minor); if (gpio_major) {Result=register _chrdev_region (devno,number_devices, "gpio_3g");} Else{result=alloc_chrdev_region (&devno,0,number_devices, "gpio_3g"); Gpio_major=major (DEVNO);} if (result<0) {PRINTK (kern_warning "Gpio:can ' t get major number%d\n", gpio_major); return result;} Char_reg_setup_cdev (); My_class=class_create (This_module, "Gpioclass");d evice_create (My_class,null,mkdev (gpio_ Major,gpio_minor), NULL, "gpio_3g"), if (Gpio_request (3g_on_off, "Unknow") <0) {PRINTK ("3g_on_off request failed\n") ;} PRINTK (kern_info "char device GPIO registered\n"); return 0;} static void __exit gpio_exit (void) {dev_t devno=mkdev (gpio_major,gpio_minor); Gpio_free (3g_on_off); Cdev_del (& Gpiocdev); Unregister_chrdev_region (devno,number_devices);d Evice_destroy (MY_CLASS,DEVNO); Class_destroy (My_class );p RINTK (kern_info "char device GPIO unregister\n");} Module_init (Gpio_init); Module_exit (Gpio_exit);


Iv. kernel Add gpio driver Step (android4.3 source)

1, put gpio_3g.c into the ~/myandroid/kernel_imx/drivers/char directory (assuming the source code under ~/myandroid).

2, ~/myandroid/kernel_imx/drivers/char/konfig the last Add the red box part of the statement.

3, add a red box part of the statement in ~/myandroid/kernel_imx/drivers/char/makefile.

4, under ~/MYANDROID/KERNEL_IMX make menuconfig to configure the kernel, after the configuration is complete, exit and save. Such as:

5, in the Entry ~/myandroid/kernel_imx directory execution:

cp. config Arch/arm/configs/imx6_android_defconfig

After that, the following command compiles:

SOURCE build/enevsetup.sh

Lunch Sabresb_6dq-user

Make

Five, compile 3G module switch machine program

1. Program code

3g_on_off.c

#include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <sys/ ioctl.h> #include <sys/types.h> #define 3g_input     _io (gpio_iof_magic,8) #define 3g_output    _io (gpio_ iof_magic,9) #define SET_ON           0x01#define set_off          0x00int Main (int argc, char *argv[]) {int Fd;fd=open ("/dev/gpio _3g ", O_RDWR); Open the GPIO_3G device file if (fd<0) {perror ("open:");} if (IOCTL (fd,3g_output,set_on) <0) {//Set this PIN for output high perror ("3g_output ioctl:");} Sleep (3); if (IOCTL (Fd,3g_output,set_off) <0) {//Set this pin as output low perror ("3g_output ioctl:");} if (IOCTL (Fd,3g_input,set_off) <0) {//Set this pin as input to prevent accidental tampering perror ("3g_input ioctl:");} Close (FD); return 0;}

Android.mk

local_path:=$ (call My-dir) include$ (clear_vars) local_module_tages:=optionallocal_module:=3g_on_offlocal_src_ files:=3g_on_off.cinclude$ (build_executable)

2. Create the 3g_on_off folder under ~/myandroid/external

3. Place the 3G_ON_OFF.C and android.mk files under the new folder.

4. Execute the following command to compile:

SOURCE build/enevsetup.sh

Lunch Sabresb_6dq-user

Mmm External/3g_on_off

5, the generated executable program:

~/myandroid/out/target/product/sabresd_6dq/obj/executables/3g_on_off_intermediates/3g_on_off put it in

~/myandroid/out/target/product/sabresd_6dq/system inside

Execution: Make Snod packaging

Six, burn write image to the development Board, execute the 3G_ON_OFF program to switch the 3G module to operate.

Android under Debug 3G Gpio control 3G Power on

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.