/*------------------------------------------------------------------------------------------*\ * * Copyright (C) 2006 AVM GmbH * * 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 #include #include #include #include #include "avm_sammel.h" #include "avm_led.h" #include "avm_led_driver.h" /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) #include #else #include #include #endif struct _asm_led_gpio_bit_context { unsigned int gpio_bit; unsigned int pos; unsigned int reverse; char name[32]; }; /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ int avm_led_gpio_bit_driver_init(unsigned int gpio_bit, unsigned int pos, char *name) { struct _asm_led_gpio_bit_context *context; context = (struct _asm_led_gpio_bit_context *)kmalloc(sizeof(struct _asm_led_gpio_bit_context), GFP_ATOMIC); avm_gpio_ctrl(gpio_bit, GPIO_PIN, GPIO_OUTPUT_PIN); if(gpio_bit == 7) { context->reverse = 0; } else { context->reverse = 1; } context->gpio_bit = gpio_bit; context->pos = pos; memcpy(context->name, name, sizeof(context->name)); context->name[sizeof(context->name) - 1] = '\0'; avm_led_gpio_bit_driver_action((unsigned int)context, 0); return (int)context; } /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ char *avm_led_gpio_bit_driver_show(unsigned int handle, unsigned int *pPos) { struct _asm_led_gpio_bit_context *context = (struct _asm_led_gpio_bit_context *)handle; if(pPos) *pPos = context->pos; DEB_NOTE("[avm_led]: single gpio driver: GPIO %u %s (pin %u \"%s\")\n", context->gpio_bit, context->reverse ? "inverted" : "normal", context->pos, context->name); return context->name; } /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ void avm_led_gpio_bit_driver_exit(unsigned int handle) { if(handle) kfree((void *)handle); } /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ int avm_led_gpio_bit_driver_action(unsigned int handle, unsigned int on) { struct _asm_led_gpio_bit_context *context = (struct _asm_led_gpio_bit_context *)handle; on = on ? 1 : 0; on = context->reverse ? !on : on; return avm_gpio_out_bit(context->gpio_bit, on); } /*------------------------------------------------------------------------------------------*\ \*------------------------------------------------------------------------------------------*/ int avm_led_gpio_bit_driver_sync(unsigned int handle, unsigned int state_id) { return 0; }