⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ar531xgpio.c

📁 atheros ar531x gpio driver
💻 C
字号:
/* * This file is subject to the terms and conditions of the GNU General Public * License.  See the file "COPYING" in the main directory of this archive * for more details. * * Copyright © 2006 Atheros Communications, Inc.,  All Rights Reserved. *//******************************************************************************* * ar531x_proc provides a channel for communication between user-level * and this AR531X BSP.  Communication is through files in /proc/ar531x. */#include <linux/config.h>#include <linux/version.h>#include <linux/module.h>#include <linux/types.h>#include <linux/delay.h>#include <linux/fs.h>#include <linux/proc_fs.h>#include <linux/init.h>#include <asm/gdb-stub.h>#include "ar531xlnx.h"#include "ar531x.h"/* GPIO Control Register bit field definitions */#define GPIO_CR_M(x)    (1 << (x))                      /* mask for i/o */#define GPIO_CR_O(x)    (1 << (x))                      /* mask for output */#define GPIO_CR_I(x)    (0 << (x))                      /* mask for input */#define GPIO_CR_INT(x)  (1 << ((x)+8))                  /* mask for interrupt */#define GPIO_CR_UART(x) (1 << ((x)+16))                 /* uart multiplex */#define NUM_GPIO     7               /* 7 GPIO pins *//* Chun modify for PUSH-BUTTON LED  * Atheros driver use GPIO 1 and GPIO 3 as a tri-color LED * But, DIR-300 only use GPIO 3 as push_button LED and GPIO 1 for other purpose * Since each hardware may use different GPIO, we define the GPIO in bsp.h  *///#define TRICOLOR_LED_GREEN_PIN  1         /* GPIO 1 */ #ifdef BLW_54CW3#define TRICOLOR_LED_YELLOW_PIN 7         /* GPIO 7 */#else#define TRICOLOR_LED_YELLOW_PIN 3         /* GPIO 3 */#endif/* Chun end */#define OFF 0#define ON 1struct proc_dir_entry *ar531x_proc_entry=NULL;struct proc_dir_entry *ar531x_gpio_entry=NULL;/* Chun modify for PUSH-BUTTON LED *//* Chun commenttypedef enum {	LED_STATE_OFF	=	0,	LED_STATE_GREEN =	1,	LED_STATE_YELLOW = 	2,	LED_STATE_ORANGE =	3,	LED_STATE_MAX =		4} led_state_e;*//* Chun add */typedef enum {	LED_STATE_OFF	=	0,	LED_STATE_BLUE =	1,	LED_STATE_MAX =		2} led_state_e;/* Chun end */static led_state_e gpio_tricolorled = LED_STATE_OFF;/* * Configure GPIO Output lines */static intar531x_gpio_cfg_output( u_int32_t gpio_pin){        u_int32_t reg_val;        if( gpio_pin > NUM_GPIO)                return -EINVAL;        reg_val = sysRegRead(AR5315_GPIO_CR);        reg_val &= ~(GPIO_CR_M(gpio_pin) |		     GPIO_CR_UART(gpio_pin) |                     GPIO_CR_INT(gpio_pin));        reg_val |= GPIO_CR_O(gpio_pin);	sysRegWrite(AR5315_GPIO_CR, reg_val);        sysRegRead(AR5315_GPIO_CR);        return 1;}/* * Once configured for I/O - set output lines */static intar531x_gpio_write(u_int32_t gpio_pin, u_int32_t val){        u_int32_t reg_val;        if( gpio_pin > NUM_GPIO)                return -EINVAL;        reg_val = sysRegRead(AR5315_GPIO_DO);        reg_val &= ~(1 << gpio_pin);        reg_val |= (val&1) << gpio_pin;	sysRegWrite(AR5315_GPIO_DO, reg_val);        sysRegRead(AR5315_GPIO_DO);        return 1;}static intar531x_gpio_tricolorled_read(char *page, char **start, off_t off,               int count, int *eof, void *data){    return sprintf(page, "%d\n", gpio_tricolorled); }/* * Control tri color LED via /proc. * Example: echo 2 > /proc/ar531x/gpio/tricolor_led   for yellow color */static intar531x_gpio_tricolorled_write(struct file *file, const char *buf, unsigned long count, void *data){	u_int32_t val, green_led_onoff, yellow_led_onoff;    	if (sscanf(buf, "%d", &val) != 1)        	return -EINVAL;    	if (val >= LED_STATE_MAX)        	return -EINVAL;	if( val == gpio_tricolorled)		return count;/* Chun modify for PUSH-BUTTON LED *//* Chun add */	switch( val ) {	case LED_STATE_OFF :				yellow_led_onoff = OFF;		break;	case LED_STATE_BLUE:				yellow_led_onoff = ON;		break;	}/* Chun comment	switch( val ) {	case LED_STATE_OFF :		green_led_onoff = OFF;   // both LEDs OFF		yellow_led_onoff = OFF;		break;	case LED_STATE_GREEN:		green_led_onoff = ON;    // green ON, Yellow OFF		yellow_led_onoff = OFF;		break;	case LED_STATE_YELLOW:		green_led_onoff = OFF;   // green OFF, Yellow ON		yellow_led_onoff = ON;		break;	case LED_STATE_ORANGE:		green_led_onoff = ON;    // both LEDs ON		yellow_led_onoff = ON;		break;	}	ar531x_gpio_write( TRICOLOR_LED_GREEN_PIN, green_led_onoff);*/	ar531x_gpio_write( TRICOLOR_LED_YELLOW_PIN, yellow_led_onoff);        gpio_tricolorled = val;    	return count;}/******************************************************************************** ar531x_gpio_setup - Initialize the /proc files needed for AR531X.*/int __initar531x_gpio_setup(void){        struct proc_dir_entry *ar531x_gpio_entry, *ar531x_tricolorled_entry;	//printk ("\nGoing to gpio_proc_entry\n");	if (ar531x_proc_entry != NULL) {		printk ("Already have a proc entry for /proc/ar531x\n");		return -ENOENT;	}	ar531x_proc_entry = proc_mkdir("ar531x", NULL);	if (!ar531x_proc_entry) {		return -ENOENT;	}	// create /proc/ar531x/gpio	ar531x_gpio_entry = proc_mkdir("gpio", ar531x_proc_entry);	if (!ar531x_gpio_entry) {		return -ENOENT;	}		// create /proc/ar531x/gpio/tricolorled        ar531x_tricolorled_entry = create_proc_entry("tricolor_led", 0644, ar531x_gpio_entry);	if (!ar531x_tricolorled_entry) {		return -ENOENT;	}        ar531x_tricolorled_entry->write_proc = ar531x_gpio_tricolorled_write;        ar531x_tricolorled_entry->read_proc = ar531x_gpio_tricolorled_read;	// Configure GPIO 1 (green) GPIO3 (yellow) as outputs	//ar531x_gpio_cfg_output(TRICOLOR_LED_GREEN_PIN);	/* Chun comment for PUSH-BUTTON LED */	ar531x_gpio_cfg_output(TRICOLOR_LED_YELLOW_PIN);	// switch OFF both Yellow and Green LEDs        //ar531x_gpio_write( TRICOLOR_LED_GREEN_PIN, 0);	/* Chun comment for PUSH-BUTTON LED */        ar531x_gpio_write( TRICOLOR_LED_YELLOW_PIN, 0);    	return 0;}module_init(ar531x_gpio_setup);/** ar531x_gpio_unload - Remove the /proc files needed for AR531X and* for module unload*/static void __exitar531x_gpio_unload(void){    remove_proc_entry("tricolor_led", ar531x_gpio_entry);}module_exit(ar531x_gpio_unload);MODULE_AUTHOR("Atheros Communications, Inc.");MODULE_DESCRIPTION("Support for Atheros WiSoC GPIO");#ifdef MODULE_LICENSEMODULE_LICENSE("Atheros");#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -