Exemple #1
0
static void accel_irq_config_edge(int *irq, int gpio, int irq_num, 
    void *data_id, irqreturn_t (*handler)(int, void*))
{
	char gpio_name[32];

	snprintf (gpio_name, 31, "%s:ACL_INT%d", MODULE_NAME, irq_num);

	/* configure GPIO */	
	if (gpio_request (gpio, gpio_name) == 0) {
		/* set gpio to input direction to allow irq signals */
		if (gpio_direction_input (gpio) == 0) {
			*irq = gpio_to_irq (gpio);

			vprintk ("GPIO %d configured as an interrupt line, irq %d, current value %d", 
				gpio, *irq, gpio_get_value (gpio));
		}else {
			fprintk ("error configuring gpio %d", gpio);
			return;
		}
	}else {
		fprintk ("failed to gpio_request %d", gpio);
	}

	if (*irq > 0) {
		if (request_irq (*irq, handler, IRQF_TRIGGER_RISING, MODULE_NAME, 
            data_id)) {
			fprintk ("can't access irq %d", *irq);
			*irq = -1;
		}else {
			vprintk ("irq = %d", *irq);
		}
	}
}
Exemple #2
0
int sys_waitpid(pid_t pid,unsigned long * stat_addr, int options)
{
	int flag, code;
	struct task_struct ** p;

	verify_area(stat_addr,4);
repeat:
	flag=0;
	for(p = &LAST_TASK ; p > &FIRST_TASK ; --p) {
		if (!*p || *p == current)
			continue;
		if ((*p)->father != current->pid)
			continue;
		if (pid>0) {
			if ((*p)->pid != pid)
				continue;
		} else if (!pid) {
			if ((*p)->pgrp != current->pgrp)
				continue;
		} else if (pid != -1) {
			if ((*p)->pgrp != -pid)
				continue;
		}
		switch ((*p)->state) {
			case TASK_STOPPED:
				if (!(options & WUNTRACED))
					continue;
				put_fs_long(0x7f,stat_addr);
				return (*p)->pid;
			case TASK_ZOMBIE:
				current->cutime += (*p)->utime;
				current->cstime += (*p)->stime;
				flag = (*p)->pid;
				code = (*p)->exit_code;
				release(*p);
				put_fs_long(code,stat_addr);
				return flag;
			default:
				flag=1;
				continue;
		}
	}
	if (flag) {
		if (options & WNOHANG)
			return 0;
		current->state=TASK_INTERRUPTIBLE;
		/*
		*当前进程 => 等待
		*/
		fprintk(3,"%d\tW\t%d\n",current->pid,jiffies);
		schedule();
		if (!(current->signal &= ~(1<<(SIGCHLD-1))))
			goto repeat;
		else
			return -EINTR;
	}
	return -ECHILD;
}
/*
 * Transmit the NWd<->Swd message to sst command
 */
static int parse_resp(
		struct te_request * request, 
		struct te_oper_param  *param, 
		cmd_t *cmd
		)
{
	__command_dump(cmd);
	fprintk("align_resp_buf 0x%x, cmd->resp_buf 0x%x\n",
			(unsigned int)align_resp_buf ,
			(unsigned int)cmd->resp_buf);
	if(cmd->resp_buf != NULL ){
		fprintk("Resp buferr ...");
		sst_memcpy(cmd->resp_buf, align_resp_buf, cmd->resp_buf_len);
		fprintk("copy done\n");
	}
	fprintk("Parse response done\n");
	return 0 ;
}
Exemple #4
0
int do_exit(long code)
{
	int i;
	free_page_tables(get_base(current->ldt[1]),get_limit(0x0f));
	free_page_tables(get_base(current->ldt[2]),get_limit(0x17));
	for (i=0 ; i<NR_TASKS ; i++)
		if (task[i] && task[i]->father == current->pid) {
			task[i]->father = 1;
			if (task[i]->state == TASK_ZOMBIE)
				{/* assumption task[1] is always init */
					(void) send_sig(SIGCHLD, task[1], 1);
				}
		}
	for (i=0 ; i<NR_OPEN ; i++)
		if (current->filp[i])
			sys_close(i);
	iput(current->pwd);
	current->pwd=NULL;
	iput(current->root);
	current->root=NULL;
	iput(current->executable);
	current->executable=NULL;
	if (current->leader && current->tty >= 0)
		tty_table[current->tty].pgrp = 0;
	if (last_task_used_math == current)
		last_task_used_math = NULL;
	if (current->leader)
		kill_session();
	current->state = TASK_ZOMBIE;
	/*
	*退出一个进程
	*/
	fprintk(3,"%d\tE\t%d\n",current->pid,jiffies);
	current->exit_code = code;
	tell_father(current->father);
	schedule();
	return (-1);	/* just to suppress warnings */
}
Exemple #5
0
/**
 * Probe implementation
 * Inits the character device and completes the I2C driver initialization
 * @return 0 in success, or negative error code
 */
static int accel_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	int err=-ENOMEM;
	struct input_dev *idev;
    struct input_polled_dev *ipdev;
	struct platform_device *pdev;

	if (!i2c_check_functionality (client->adapter, I2C_FUNC_I2C)) {
		fprintk ("I2C function is not supported");
		return -ENOTSUPP;
	}

	memset (&accel_info, 0, sizeof (accel_data_t));
	accel_info.magic = ACCEL_MAGIC;
	accel_info.irq1 = accel_info.irq2 = -1;

	mutex_init (&accel_info.mlock);
	mutex_init (&pl);
    atomic_set (&accel_info.data_ready_enabled, 0);

	accel_info.i2c = client;
	i2c_set_clientdata (client, &accel_info);

	if (accel_i2c_who_am_i () != ACCEL_I_AM_THE_ONE) {
		fprintk ("I2C device with address 0x%x is not LIS331DLH", client->addr);
		err = -ENODEV;		
		goto exit;
	}else {
		vprintk ("I2C device with address 0x%x is LIS331DLH accelerometer", client->addr);
	}

	INIT_WORK (&accel_info.wq1, accel_irq_bottom_half);
#ifdef ACCEL_DATA_READY_IRQ
	INIT_WORK (&accel_info.wq2, accel_irq_data_ready_bottom_half);
#endif

//	sema_init (&accel_info.sema1, 1);
//	sema_init (&accel_info.sema2, 1);

	pdev = (struct platform_device *)client->dev.platform_data;
	/* 
	 * IRQ field contain information about swapped axes
	 */
	accel_param_swapped = pdev->id;
	fprintk ("swapped axes parameter 0x%02x", accel_param_swapped);

	if (pdev && pdev->num_resources && ! strcmp(pdev->name, "stmicro")) {
		struct resource *resource;
		
		vprintk ("platform data for '%s', num_resources %d", 
            pdev->name, pdev->num_resources);

		resource = platform_get_resource (pdev, IORESOURCE_IRQ, 0);
		if (resource) {
			accel_gpio_one = resource->start;
			accel_gpio_two = resource->end;

			accel_irq_config_edge (&accel_info.irq1, accel_gpio_one, 
                ACCEL_IRQ_INT1,
			    (void *)&accel_info.irq1_cnt, accel_irq_handler);
#ifdef ACCEL_DATA_READY_IRQ
            accel_irq_config_high (&accel_info.irq2, accel_gpio_two, 
                ACCEL_IRQ_INT2,
                (void *)&accel_info.irq2_cnt, 
                accel_irq_data_ready_handler);	
#endif
		} else {
			fprintk ("unable to obtain GPIO information; no IRQ support");
        }
	} else {
		fprintk ("platform data has no resources declared; no IRQ support");
    }

	if (accel_param_input) {
		/* take care of input device here */
		ipdev = input_allocate_polled_device ();

		if (! ipdev) {
			fprintk ("failed to allocate input device structure");
			err = -ENOMEM;
			goto exit_irqs;
		}
        ipdev->poll_interval = (int)-1;
        ipdev->poll = accel_poll_data_ready;
         
        idev = ipdev->input;

		idev->name = "accelerometer";
		idev->id.bustype = BUS_I2C;
		idev->id.vendor  = 0;
		idev->id.product = ACCEL_I_AM_THE_ONE;
        accel_info.idev = idev;
		accel_info.ipdev = ipdev;

		set_bit (EV_ABS, idev->evbit);
		set_bit (EV_SW,  idev->evbit);

		set_bit (6, idev->swbit);
		input_report_switch (idev, 6, TOGGLE_OFF);

		accel_input_params (idev, ABS_X, 3, ACCEL_2G_MAX);
		accel_input_params (idev, ABS_RX, 3, ACCEL_2G_MAX);
		accel_input_params (idev, ABS_TILT_X, 2, ACCEL_2G_MAX);

		if ((err = input_register_polled_device (ipdev))) {
			fprintk ("failed to register input device");
			goto exit_input;
		}
	}
    fprintk ("registered input device accelerometer\n");

    atomic_set (&accel_info.mode, 0);
    atomic_set (&accel_info.odr, 0);
    atomic_set (&accel_info.g_range, 1); // 4G
	accel_i2c_set_config (0, 0, 0, -1);

	/* create misc device and /dev/accelerometer file */
	if (misc_register (&accel_misc_driver)) {
		fprintk("can't register misc. device");
		goto exit_input;
	}
    fprintk ("registered misc device\n");

	/* Turn power on if forced to do so */
	if (accel_param_power) {
		/*enable all axises */
		accel_i2c_enable_axis (AXIS_XYZ);
		/* aplly power settings */
		accel_i2c_set_power_mode (accel_param_power);
	}

	/* Register sysfs hooks */
	if ((err = sysfs_create_group (&client->dev.kobj, &accel_defattr_group))) {
		fprintk ("failed to create a sysfs group");
		goto exit_input;
	}
    fprintk ("created sysfs group\n");

#ifdef  CONFIG_HAS_EARLYSUSPEND
	accel_info.early_suspend.suspend = accel_early_suspend;
	accel_info.early_suspend.resume = accel_early_resume;
	register_early_suspend (&(accel_info.early_suspend));
#endif

	printk (KERN_INFO "%s: driver probed successfully\n", __func__);

	return SUCCESS;

exit_input:
	if (accel_info.ipdev) {
		input_free_polled_device (accel_info.ipdev);
		accel_info.ipdev = NULL;
	}
exit_irqs:
	if (accel_info.irq1 > 0) {
		gpio_free (accel_gpio_one);
		free_irq (accel_info.irq1, (void *)&accel_info.irq1_cnt);
	}
#ifdef ACCEL_DATA_READY_IRQ
	if (accel_info.irq2 > 0) {
		gpio_free (accel_gpio_two);
		free_irq (accel_info.irq2, (void *)&accel_info.irq2_cnt);
	}
#endif
exit:
	return err;
}
void EXIT(int x)
{
  fprintk(stderr, "Press any key to exit.\n");
  _getch();
  exit(x);
}