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

📄 hx4700_leds.c

📁 pocket pc hx4700 linux driver
💻 C
字号:
/* * HP iPAQ hx4700 LED support * * Copyright (C) 2005 Michael Opdenacker <michael@free-electrons.com> * * History: * * Feb 2005: Michael Opdenacker. First version from John Lenz's locomo LED driver * * 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. */#include <linux/config.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/platform_device.h>#include <linux/leds.h>#include <asm/hardware/ipaq-asic3.h>#include <linux/soc/asic3_base.h>#include <asm/mach-types.h>#include <asm/arch/ipaq.h>extern struct platform_device hx4700_asic3;struct hx4700_led_data {	int			hw_num;			// 0 (amber), 1 (green), 2 (blue)	int			duty_time;	int			cycle_time;	int			registered;	int			brightness;	int			color;	struct led_properties	props;};#define to_hx4700_led_data(d) container_of(d, struct hx4700_led_data, props)/* Low level access to hx4700 diodes * * Note that amber and green are implemented by the same physical led. * There are 2 independent asic3 registers for both, which can be configured independently. * If you switch both on, the led alternates between amber and green, * which may not look very clear to end users * * This conflict is handled by the generic led interface */void hx4700_set_led (int led_num, int duty_time, int cycle_time){	int value;	switch (led_num) {	case 0: // Amber (2nd physical LED)	case 1: // Green (Also, 2nd physical LED)	case 2: // Blue (3rd physical LED)		value = (1 << led_num);		ipaq_asic3_set_gpio_out_c(&hx4700_asic3.dev, value & 0x7, value & 0x7);		ipaq_asic3_set_led(&hx4700_asic3.dev, led_num, duty_time, cycle_time);		break;	default:		printk("%s: Unsupported LED number %d\n", __FUNCTION__, led_num);	}}/* As long as the generic interface is not in place */EXPORT_SYMBOL(hx4700_set_led);voidhx4700_clear_led (int led_num){	hx4700_set_led(led_num, 0, 16);}EXPORT_SYMBOL(hx4700_clear_led);/* Generic led model and sysfs interface */int hx4700_led_brightness_get(struct device *dev, struct led_properties *props){	struct hx4700_led_data *data = to_hx4700_led_data(props);	return data->brightness;}void hx4700_led_brightness_set(struct device *dev, struct led_properties *props, int value)/* Brightness levels supported by the hardware: 0 (off) and 100 (on)*/{	struct hx4700_led_data *data = to_hx4700_led_data(props);	int duty_time;	if (value > 0) {		data->brightness = 100;		duty_time = data->duty_time;	} else {		data->brightness = 0;		duty_time = 0;	}	hx4700_set_led(data->hw_num, duty_time, data->cycle_time);}int hx4700_led_color_get(struct device *dev, struct led_properties *props){	struct hx4700_led_data *data = to_hx4700_led_data(props);	return data->color;}void hx4700_led_color_set(struct device *dev, struct led_properties *props, int value)/* This function is only called on the amber/green led */{	struct hx4700_led_data *data = to_hx4700_led_data(props);	value = (value < 0) ? 0 : 1;	if (value != data->hw_num) {		/* Switch off the other led */		hx4700_set_led(data->hw_num, 0, data->cycle_time);		/* Switch on the other led if the brightness is non zero */		if (data->brightness) {			hx4700_set_led(value, data->duty_time, data->cycle_time);		}	}	data->hw_num = value;}/* Generic driver interface not implemented yetstatic struct hx4700_led_data leds[] = {       {	       .hw_num = 0,		// Amber color at initialization	       .duty_time = 8,		// Flashing at initialization	       .cycle_time = 4,		// Until flashing control supported by the interface	       .props  = {		       .owner	       = THIS_MODULE,		       .color	       = "amber/green",		       .brightness_get = hx4700_led_brightness_get,		       .brightness_set = hx4700_led_brightness_set,		       .color_get      = hx4700_led_color_get,		       .color_set      = hx4700_led_color_set,	       }       },       {	       .hw_num = 2,	       .duty_time = 8,		// Flashing at initialization	       .cycle_time = 4,		// Until flashing control supported by the interface	       .props  = {		       .owner	       = THIS_MODULE,		       .color	       = "blue",		       .brightness_get = hx4700_led_brightness_get,		       .brightness_set = hx4700_led_brightness_set,		       .color_get      = NULL,		       .color_set      = NULL,	       }       },};static int hx4700_led_probe(struct hx4700_dev *dev){       int i, ret = 0;       for (i = 0; i < ARRAY_SIZE(leds); i++) {	       ret = leds_device_register(&dev->dev, &leds[i].props);	       leds[i].registered = 1;	       if (unlikely(ret)) {		       printk(KERN_WARNING "Unable to register hx4700 led %s\n", leds[i].props.color);		       leds[i].registered = 0;	       }       }       return ret;}static int hx4700_led_remove(struct hx4700_dev *dev) {       int i;       for (i = 0; i < ARRAY_SIZE(leds); i++) {	       if (leds[i].registered) {		       leds_device_unregister(&leds[i].props);	       }       }       return 0;}static struct hx4700_driver hx4700_led_driver = {       .drv = {	       .name = "hx4700_led"       },       .devid  = HX4700_DEVID_LED,       .probe  = hx4700_led_probe,       .remove = hx4700_led_remove,};static int __init hx4700_led_init(void) {       return hx4700_driver_register(&hx4700_led_driver);}*//* Basic module initialization testing the low level led interface */static int led_num = 0;static int duty_time = 128;static int cycle_time = 256;module_param(led_num, uint, 0);module_param(duty_time, uint, 0);module_param(cycle_time, uint, 0);static int hx4700_led_init (void){	/* Turn on the LED controllers in CDEX */	asic3_set_clock_cdex(&hx4700_asic3.dev,		CLOCK_CDEX_LED0 | CLOCK_CDEX_LED1 | CLOCK_CDEX_LED2,		CLOCK_CDEX_LED0 | CLOCK_CDEX_LED1 | CLOCK_CDEX_LED2	);	hx4700_clear_led(0);	hx4700_clear_led(1);	hx4700_clear_led(2);	/* hx4700_set_led(led_num, duty_time, cycle_time); */	return 0;}static void hx4700_led_exit (void){	hx4700_clear_led(0);	hx4700_clear_led(1);	hx4700_clear_led(2);}module_init (hx4700_led_init);module_exit (hx4700_led_exit);MODULE_AUTHOR("Michael Opdenacker <michael@free-electrons.com>");MODULE_DESCRIPTION("HP iPAQ hx4700 LED driver");MODULE_LICENSE("GPL");/* vim600: set noexpandtab sw=8 ts=8 :*/

⌨️ 快捷键说明

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