3G gpio Control 3G power-on in android
If it is a self-developed board and you need to use the GPIO pin to control the startup/shutdown of the 3G module, the following article will help you, taking the processor IMX6 and ZTE MG3732 modules as an example.
I. Pin Connection
The gpio3_GPIO [9] of the processor connects to the ON/OFF (29) pin of the 3G module to control the startup/shutdown of 3G.
II. On/Off machine conditions
For the ON/OFF pin, 2500 ~ Boot at a low level of 3500 milliseconds, and continue to the ON/OFF pin for 2500 ~ Shut down at a low level of 3500 milliseconds.
3. gpio driver
Gpio_3g.c
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Define GPIO_IOF_MAGIC 0xd0 # define export _input _ IO (GPIO_IOF_MAGIC, 8) # define export _output _ IO (GPIO_IOF_MAGIC, 9) # define Export (3,9) // The control pin is: 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 when _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 ); printk ("pai_on_off ioctl val = % d \ n", val); break; case when _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); printk ("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 handle (void) {int error; dev_t devno; devno = MKDEV (kernel, 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 = vertex (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"); device_create (my_class, NULL, MKDEV (gpio_major, gpio_minor), NULL, "gpio_3g"); if (gpio_request (3G_ON_OFF, "UnKnow") <0) {printk ("pai_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 (kernel, gpio_minor); gpio_free (kernel _on_off); cdev_del (& gpiocdev); kernel (devno, number_devices); device_destroy (my_class, devno ); class_destroy (my_class); printk (KERN_INFO "char device GPIO unregister \ n");} module_init (gpio_init); module_exit (gpio_exit );
4. Steps for adding the gpio driver to the kernel (android4.3 source code)
1. Place gpio_3g.c IN ~ /Myandroid/kernel_imx/drivers/char directory (assume that the source code is in ~ /Myandroid ).
2 ,~ Add the red box statement in/myandroid/kernel_imx/drivers/char/Konfig.
3 ~ Add the red box statement to/myandroid/kernel_imx/drivers/char/Makefile. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + ICAgICAgICAgICA8aW1nIHNyYz0 = "http://www.2cto.com/uploadfile/Collfiles/20141101/2014110108420589.png" width = "615" height = "125" alt = "\">
4 ~ Make menuconfig under/myandroid/kernel_imx to configure the kernel. After the configuration is complete, exit and save the configuration. For example:
5. Enter ~ /Myandroid/kernel_imx directory execution:
Cp. config arch/arm/configs/imx6_android_defconfig
After that, run the following command to compile:
Source build/enevsetup. sh
Lunch sabresb_6dq-user
Make
5. Compile the 3G module on/off program
1. program code
Pai_on_off.c
# Include
# Include
# Include
# Include
# Include
# Include
# Define pai_input _ IO (GPIO_IOF_MAGIC, 8) # define pai_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 to output high perror ("3G_OUTPUT ioctl: ");} sleep (3); if (ioctl (fd, 3G_OUTPUT, SET_OFF) <0) {// set this pin to output low perror (" 3G_OUTPUT ioctl: ");} if (ioctl (fd, 3G_INPUT, SET_OFF) <0) {// set this pin as input to prevent accidental tampering with 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 pai_on_off folder under/myandroid/external
3. Put the pai_on_off.c and Android. mk files in the new folder.
4. Execute the following command to compile:
Source build/enevsetup. sh
Lunch sabresb_6dq-user
Mmm external/3g_on_off
5. Run the generated executable program:
~ /Myandroid/out/target/product/sabresd_6dq/obj/EXECUTABLES/3g_on_off_intermediates/3g_on_off put
~ /Myandroid/out/target/product/sabresd_6dq/system
Run: make snod package
6. Download the image to the Development Board and run the 3g_on_off program to switch the 3G module.