Beispiel #1
0
static int gpio_read_io(int handle)
{
	unsigned int value;

	gp_gpio_set_input(handle,2);
	
	gp_gpio_get_value(handle,&value);
	//printk("read io 0x%x \r\n",value);
	return value;
}
Beispiel #2
0
/**
 * @brief   Gpio device ioctl function
 */
static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	long ret = 0;
	int handle;
	gpio_content_t ctx;

	switch (cmd) {
	case GPIO_IOCTL_SET_VALUE:
		{
			if (copy_from_user(&ctx, (void __user*)arg, sizeof(ctx))) 
			{
				ret = -EFAULT;
				break;
			}

			handle = gp_gpio_request(ctx.pin_index, NULL);
			if (IS_ERR_VALUE(handle)) 
			{
				ret = (long)handle; /* gpio request error code */
				break;
			}

			ret = gp_gpio_set_output(handle, ctx.value, 0);

			gp_gpio_release(handle);
		}
		break;

	case GPIO_IOCTL_GET_VALUE:
		{
			if (copy_from_user(&ctx, (void __user*)arg, sizeof(ctx))) 
			{
				ret = -EFAULT;
				break;
			}

			handle = gp_gpio_request(ctx.pin_index, NULL);
			if (IS_ERR_VALUE(handle)) 
			{
				ret = (long)handle; /* gpio request error code */
				break;
			}

			ret = gp_gpio_set_input(handle, GPIO_PULL_FLOATING);
			if (ret == 0) 
			{
				ret = gp_gpio_get_value(handle, &ctx.value);
				if (ret == 0) 
				{
					if (copy_to_user((void __user*)arg, &ctx, sizeof(ctx))) 
					{
						ret = -EFAULT;
					}
				}
			}

			gp_gpio_release(handle);
		}
		break;
	case GPIO_IOCTL_SET_INPUT:
		{
			if (copy_from_user(&ctx, (void __user*)arg, sizeof(ctx))) 
			{
				ret = -EFAULT;
				break;
			}

			handle = gp_gpio_request(ctx.pin_index, NULL);
			if (IS_ERR_VALUE(handle)) 
			{
				ret = (long)handle; /* gpio request error code */
				break;
			}
			ret = gp_gpio_set_input(handle, ctx.value);
			
			gp_gpio_release(handle);			
		}
		break;
		case GPIO_IOCTL_IRQ_TEST:
		{
			if (copy_from_user(&ctx, (void __user*)arg, sizeof(ctx))) 
			{
				ret = -EFAULT;
				break;
			}

			handle = gp_gpio_request(ctx.pin_index, "gpio_irq_test");
			if (IS_ERR_VALUE(handle)) 
			{
				ret = (long)handle; /* gpio request error code */
				break;
			}
			ret = gp_gpio_set_input(handle, ctx.value);
			if(ctx.value == 1)
			 gp_gpio_irq_property(handle, GPIO_IRQ_ACTIVE_FALING, NULL);//low triggle
			else
			 gp_gpio_irq_property(handle, GPIO_IRQ_ACTIVE_RISING, NULL);//high triggle
			 
			 gp_gpio_register_isr(handle, gpio_test_isr, (void *)handle);		
		}
		break;
#ifdef GPIO_IOCTL_TEST
	case GPIO_IOCTL_TEST:
		{
			static int p1 = 0;
			int p2;

			if (p1 == 0) 
			{
				printk("--- gpio test begin!\n");
				p2 = gp_gpio_request(MK_GPIO_INDEX(2,2,4,6), "gpio_test"); /* IOC6 */
				gp_gpio_set_output(p2, 0, 1);
				gp_gpio_release(p2);

				p1 = gp_gpio_request(MK_GPIO_INDEX(2,2,4,5), "gpio_test"); /* IOC5 */
				gp_gpio_set_input(p1, GPIO_PULL_LOW);
				gp_gpio_irq_property(p1, GPIO_IRQ_LEVEL_TRIGGER|GPIO_IRQ_LEVEL_HIGH, NULL);
				gp_gpio_register_isr(p1, gpio_test_isr, (void *)p1);
			}
			else 
			{
				gp_gpio_unregister_isr(p1);
				gp_gpio_release(p1);
				p1 = 0;
				printk("--- gpio test end!\n");
			}
		}
		break;
#endif
	default:
		ret = -ENOTTY; /* Inappropriate ioctl for device */
		break;
	}

	return ret;
}
static void gp_touchpad_gpioIrq(void *data)
{
	int ret,tmp;
	char datax[3];
	int *p;
	if (down_interruptible(&gp_touchpad_data->touchpad_sem) != 0) 
	{
		return;
	}
	gp_gpio_enable_irq(gp_touchpad_irq_data->gpiohd, 0);
	p = (int*)IO0_ADDRESS(0x5080);
	*p &= 0xf3ffffff;
	ret = gp_i2c_bus_read(iic_handle, (unsigned char*)&datax, 3);
	*p |= 0x0c000000;

	if((datax[1]&0x80) == 0)
	{
		tmp = (int)(datax[1]);
	}
	else
	{
		
		tmp = (int)(datax[1]);
		tmp -= 0xff;
	}
	input_report_rel((gp_touchpad_data->input), REL_X, tmp);
#if tp_debug_print
	printk("Xm:%3d-%x\n",tmp,tmp);
#endif

	if((datax[2]&0x80) == 0)
	{
		tmp = (int)(datax[2]);
	}
	else
	{
		tmp = (int)(datax[2]);
		tmp -= 0xff;
	}
	input_report_rel((gp_touchpad_data->input), REL_Y, tmp);
#if tp_debug_print
	printk("Ym:%3d-%x\n",tmp,tmp);
#endif

	//left button
	if(datax[0]&TP_LBTN)
	{
		input_report_key(gp_touchpad_data->input, BTN_LEFT,   1);
#if tp_debug_print
		printk("LB:+++\n");
#endif
	}
	else
	{
		input_report_key(gp_touchpad_data->input, BTN_LEFT,   0);
#if tp_debug_print
		printk("LB:...\n");
#endif
	}
	//right button
	if(datax[0]&TP_RBTN)
	{
		input_report_key(gp_touchpad_data->input, BTN_RIGHT,   1);
#if tp_debug_print
		printk("RB:+++\n");
#endif
	}
	else
	{
		input_report_key(gp_touchpad_data->input, BTN_RIGHT,   0);
#if tp_debug_print
		printk("RB:...\n");
#endif
	}
	//middle button
	if(datax[0]&TP_MBTN)
	{
		input_report_key(gp_touchpad_data->input, BTN_MIDDLE,   1);
#if tp_debug_print
		printk("MB:+++\n");
#endif
	}
	else
	{
		input_report_key(gp_touchpad_data->input, BTN_MIDDLE,   0);
#if tp_debug_print
		printk("MB:...\n");
#endif
	}

	input_sync(gp_touchpad_data->input);
#if tp_debug_print
	printk("cmd:%u,data0:%d,data1:%d\n",datax[0],datax[1],datax[2]);
#endif
	gp_gpio_set_direction(gp_touchpad_irq_data->gpiohd, GPIO_DIR_INPUT);
	gp_gpio_set_input(gp_touchpad_irq_data->gpiohd, 1);
	gp_gpio_enable_irq(gp_touchpad_irq_data->gpiohd, 1);
	up(&gp_touchpad_data->touchpad_sem);
	return;
}