示例#1
0
static int __devinit gpio_keys_probe(struct platform_device *pdev)
{
	const struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
	struct gpio_keys_drvdata *ddata;
	struct device *dev = &pdev->dev;
	struct gpio_keys_platform_data alt_pdata;
	struct input_dev *input;
	int i, error;
	int wakeup = 0;

	if (!pdata) {
		error = gpio_keys_get_devtree_pdata(dev, &alt_pdata);
		if (error)
			return error;
		pdata = &alt_pdata;
	}

	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
			pdata->nbuttons * sizeof(struct gpio_button_data),
			GFP_KERNEL);
	input = input_allocate_device();
	if (!ddata || !input) {
		dev_err(dev, "failed to allocate state\n");
		error = -ENOMEM;
		goto fail1;
	}

	ddata->input = input;
	ddata->n_buttons = pdata->nbuttons;
	ddata->enable = pdata->enable;
	ddata->disable = pdata->disable;
#ifdef CONFIG_SENSORS_HALL
	ddata->gpio_flip_cover = pdata->gpio_flip_cover;
	ddata->irq_flip_cover = gpio_to_irq(ddata->gpio_flip_cover);;

	wake_lock_init(&ddata->flip_wake_lock, WAKE_LOCK_SUSPEND,
		"flip wake lock");
#endif
	mutex_init(&ddata->disable_lock);

	platform_set_drvdata(pdev, ddata);
	input_set_drvdata(input, ddata);

	input->name = pdata->name ? : pdev->name;
	input->phys = "gpio-keys/input0";
	input->dev.parent = &pdev->dev;
#ifdef CONFIG_SENSORS_HALL
	input->evbit[0] |= BIT_MASK(EV_SW);
	input_set_capability(input, EV_SW, SW_FLIP);
#endif
	input->open = gpio_keys_open;
	input->close = gpio_keys_close;

	input->id.bustype = BUS_HOST;
	input->id.vendor = 0x0001;
	input->id.product = 0x0001;
	input->id.version = 0x0100;

	/* Enable auto repeat feature of Linux input subsystem */
	if (pdata->rep)
		__set_bit(EV_REP, input->evbit);

	for (i = 0; i < pdata->nbuttons; i++) {
		struct gpio_keys_button *button = &pdata->buttons[i];
		struct gpio_button_data *bdata = &ddata->data[i];

		error = gpio_keys_setup_key(pdev, input, bdata, button);
		if (error)
			goto fail2;

		if (button->wakeup)
			wakeup = 1;

#ifdef KEY_BOOSTER
		if (button->code == KEY_HOMEPAGE) {
			error = gpio_key_init_dvfs(bdata);
			if (error < 0) {
				dev_err(dev, "Fail get dvfs level for touch booster\n");
				goto fail2;
			}
		}
#endif
	}

	error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group);
	if (error) {
		dev_err(dev, "Unable to export keys/switches, error: %d\n",
			error);
		goto fail2;
	}

	ddata->sec_key =
	    device_create(sec_class, NULL, 0, ddata, "sec_key");
	if (IS_ERR(ddata->sec_key))
		dev_err(dev, "Failed to create sec_key device\n");

	error = sysfs_create_group(&ddata->sec_key->kobj, &sec_key_attr_group);
	if (error) {
		dev_err(dev, "Failed to create the test sysfs: %d\n",
			error);
		goto fail2;
	}

#ifdef CONFIG_SENSORS_HALL
	init_hall_ic_irq(input);
#endif

	error = input_register_device(input);
	if (error) {
		dev_err(dev, "Unable to register input device, error: %d\n",
			error);
		goto fail3;
	}

	/* get current state of buttons */
	for (i = 0; i < pdata->nbuttons; i++)
		gpio_keys_report_event(&ddata->data[i]);
	input_sync(input);

#ifdef CONFIG_FAST_BOOT
	/*Fake power off*/
	input_set_capability(input, EV_KEY, KEY_FAKE_PWR);
	setup_timer(&fake_timer, gpio_keys_fake_off_check,
			(unsigned long)input);
	wake_lock_init(&fake_lock, WAKE_LOCK_SUSPEND, "fake_lock");
#endif

	device_init_wakeup(&pdev->dev, wakeup);

#if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
#if defined(CONFIG_N1A) || defined(CONFIG_N2A)
	if(set_auto_power_on_off_powerkey_val) {
		init_timer(&poweroff_keypad_timer);
		poweroff_keypad_timer.function = poweroff_keypad_timer_handler;
		poweroff_keypad_timer.data = (unsigned long)&ddata->data[0];
		if(lpcharge)
			poweroff_keypad_timer.expires = jiffies + 20*HZ;
		else
			poweroff_keypad_timer.expires = jiffies + 40*HZ;
		add_timer(&poweroff_keypad_timer);
		printk("AUTO_POWER_ON_OFF_FLAG Test Start !!!\n");
	}
#endif
#endif
	return 0;

 fail3:
	sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
	sysfs_remove_group(&ddata->sec_key->kobj, &sec_key_attr_group);
 fail2:
	while (--i >= 0)
		gpio_remove_key(&ddata->data[i]);

	platform_set_drvdata(pdev, NULL);
#ifdef CONFIG_SENSORS_HALL
	wake_lock_destroy(&ddata->flip_wake_lock);
#endif
 fail1:
	input_free_device(input);
	kfree(ddata);
	/* If we have no platform_data, we allocated buttons dynamically. */
	if (!pdev->dev.platform_data)
		kfree(pdata->buttons);

	return error;
}
示例#2
0
static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
					 struct input_dev *input,
					 struct gpio_button_data *bdata,
					 const struct gpio_keys_button *button)
{
	const char *desc = button->desc ? button->desc : "gpio_keys";
	struct device *dev = &pdev->dev;
	irq_handler_t isr;
	unsigned long irqflags;
	int irq, error;

	bdata->input = input;
	bdata->button = button;
	spin_lock_init(&bdata->lock);

	if (gpio_is_valid(button->gpio)) {

		error = gpio_request(button->gpio, desc);
		if (error < 0) {
			dev_err(dev, "Failed to request GPIO %d, error %d\n",
				button->gpio, error);
			return error;
		}

		error = gpio_direction_input(button->gpio);
		if (error < 0) {
			dev_err(dev,
				"Failed to configure direction for GPIO %d, error %d\n",
				button->gpio, error);
			goto fail;
		}

		if (button->debounce_interval) {
			error = gpio_set_debounce(button->gpio,
					button->debounce_interval * 1000);
			/* use timer if gpiolib doesn't provide debounce */
			if (error < 0)
				bdata->timer_debounce =
						button->debounce_interval;
		}

		irq = gpio_to_irq(button->gpio);
		if (irq < 0) {
			error = irq;
			dev_err(dev,
				"Unable to get irq number for GPIO %d, error %d\n",
				button->gpio, error);
			goto fail;
		}
		bdata->irq = irq;

		INIT_WORK(&bdata->work, gpio_keys_gpio_work_func);
		setup_timer(&bdata->timer,
			    gpio_keys_gpio_timer, (unsigned long)bdata);

		isr = gpio_keys_gpio_isr;
		irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;

	} else {
		if (!button->irq) {
			dev_err(dev, "No IRQ specified\n");
			return -EINVAL;
		}
		bdata->irq = button->irq;

		if (button->type && button->type != EV_KEY) {
			dev_err(dev, "Only EV_KEY allowed for IRQ buttons.\n");
			return -EINVAL;
		}

		bdata->timer_debounce = button->debounce_interval;
		setup_timer(&bdata->timer,
			    gpio_keys_irq_timer, (unsigned long)bdata);

		isr = gpio_keys_irq_isr;
		irqflags = 0;
	}

	input_set_capability(input, button->type ?: EV_KEY, button->code);

	/*
	 * If platform has specified that the button can be disabled,
	 * we don't want it to share the interrupt line.
	 */
	if (!button->can_disable)
		irqflags |= IRQF_SHARED;

	error = request_any_context_irq(bdata->irq, isr, irqflags, desc, bdata);
	if (error < 0) {
		dev_err(dev, "Unable to claim irq %d; error %d\n",
			bdata->irq, error);
		goto fail;
	}

	return 0;

fail:
	if (gpio_is_valid(button->gpio))
		gpio_free(button->gpio);

	return error;
}
示例#3
0
文件: omap.c 项目: vineetnayak/linux
static int __devinit mmc_omap_new_slot(struct mmc_omap_host *host, int id)
{
	struct mmc_omap_slot *slot = NULL;
	struct mmc_host *mmc;
	int r;

	mmc = mmc_alloc_host(sizeof(struct mmc_omap_slot), host->dev);
	if (mmc == NULL)
		return -ENOMEM;

	slot = mmc_priv(mmc);
	slot->host = host;
	slot->mmc = mmc;
	slot->id = id;
	slot->pdata = &host->pdata->slots[id];

	host->slots[id] = slot;

	mmc->caps = 0;
	if (host->pdata->slots[id].wires >= 4)
		mmc->caps |= MMC_CAP_4_BIT_DATA;

	mmc->ops = &mmc_omap_ops;
	mmc->f_min = 400000;

	if (cpu_class_is_omap2())
		mmc->f_max = 48000000;
	else
		mmc->f_max = 24000000;
	if (host->pdata->max_freq)
		mmc->f_max = min(host->pdata->max_freq, mmc->f_max);
	mmc->ocr_avail = slot->pdata->ocr_mask;

	/* Use scatterlist DMA to reduce per-transfer costs.
	 * NOTE max_seg_size assumption that small blocks aren't
	 * normally used (except e.g. for reading SD registers).
	 */
	mmc->max_segs = 32;
	mmc->max_blk_size = 2048;	/* BLEN is 11 bits (+1) */
	mmc->max_blk_count = 2048;	/* NBLK is 11 bits (+1) */
	mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
	mmc->max_seg_size = mmc->max_req_size;

	r = mmc_add_host(mmc);
	if (r < 0)
		goto err_remove_host;

	if (slot->pdata->name != NULL) {
		r = device_create_file(&mmc->class_dev,
					&dev_attr_slot_name);
		if (r < 0)
			goto err_remove_host;
	}

	if (slot->pdata->get_cover_state != NULL) {
		r = device_create_file(&mmc->class_dev,
					&dev_attr_cover_switch);
		if (r < 0)
			goto err_remove_slot_name;

		setup_timer(&slot->cover_timer, mmc_omap_cover_timer,
			    (unsigned long)slot);
		tasklet_init(&slot->cover_tasklet, mmc_omap_cover_handler,
			     (unsigned long)slot);
		tasklet_schedule(&slot->cover_tasklet);
	}

	return 0;

err_remove_slot_name:
	if (slot->pdata->name != NULL)
		device_remove_file(&mmc->class_dev, &dev_attr_slot_name);
err_remove_host:
	mmc_remove_host(mmc);
	mmc_free_host(mmc);
	return r;
}
示例#4
0
static int __init hs_probe(struct platform_device *pdev)
{
	int result = 0;
	mic.hsmajor = 0;
	mic.headset_state = 0;
	mic.hsbtime.tv.sec = 0;
	mic.hsbtime.tv.nsec = 0;
	mic.headset_pd = NULL;
	mic.check_count = 0;

#ifdef CONFIG_SWITCH
	result = hs_switchinit(&mic);
	if (result < 0)
		return result;
#endif

	result = hs_inputdev(&mic);
	if (result < 0)
		goto err;

	result = register_chrdev(mic.hsmajor, "BrcmHeadset", &hs_fops);
	if(result < 0)
		goto err1;
	else if(result > 0 && (mic.hsmajor == 0))    /* this is for dynamic major */
		mic.hsmajor = result;

	wake_lock_init(&mic.det_wake_lock, WAKE_LOCK_SUSPEND, "sec_jack_det");
	INIT_DELAYED_WORK(&(mic.imsi_work), getIMSI_work_func);

	/* check if platform data is defined for a particular board variant */
	if (pdev->dev.platform_data)
	{
		mic.headset_pd = pdev->dev.platform_data;

		KEY_PRESS_THRESHOLD = mic.headset_pd->key_press_threshold;
		KEY_3POLE_THRESHOLD = mic.headset_pd->key_3pole_threshold;
		KEY1_THRESHOLD_L = mic.headset_pd->key1_threshold_l;
		KEY1_THRESHOLD_U = mic.headset_pd->key1_threshold_u;
		KEY2_THRESHOLD_L = mic.headset_pd->key2_threshold_l;
		KEY2_THRESHOLD_U = mic.headset_pd->key2_threshold_u;
		KEY3_THRESHOLD_L = mic.headset_pd->key3_threshold_l;
		KEY3_THRESHOLD_U = mic.headset_pd->key3_threshold_u;

		if (mic.headset_pd->hsgpio == 0)
			mic.hsirq = mic.headset_pd->hsirq;
		else
		{
			setup_timer(&mic.timer, gpio_jack_timer, (unsigned long)&mic); // timer register. 

			if (gpio_request(mic.headset_pd->hsgpio, "headset detect") < 0)
			{
				printk("%s: Could not reserve headset signal GPIO!\n", __func__);
				goto err2;
			}
			gpio_direction_input(mic.headset_pd->hsgpio);
			bcm_gpio_set_db_val(mic.headset_pd->hsgpio, 0x7);
			mic.hsirq = gpio_to_irq(mic.headset_pd->hsgpio);
		}
		mic.hsbirq = mic.headset_pd->hsbirq;
	}
	else
	{
		mic.hsirq = platform_get_irq(pdev, 0);
		mic.hsbirq = platform_get_irq(pdev, 1);
	}

	printk("%s: HS irq %d\n", __func__, mic.hsirq);
	printk("%s: HSB irq %d\n", __func__, mic.hsbirq);
	result = request_irq(mic.hsbirq, hs_buttonisr,  IRQF_NO_SUSPEND, "BrcmHeadsetButton",  (void *) NULL);
	mic.hsbst = DISABLE;

	if(result < 0)
		goto err2;

	result = request_irq(mic.hsirq, hs_isr,(IRQF_DISABLED | IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING | IRQF_NO_SUSPEND), "BrcmHeadset",  &mic);
	if(result < 0)
	{
		free_irq(mic.hsbirq, &mic);
		goto err2;
	}

	printk("%s: BrcmHeadset: module inserted >>>> . Major number is = %d\n", __func__, mic.hsmajor);

	/* Set the ANACR2 bit for mic power down */
	board_sysconfig(SYSCFG_AUXMIC, SYSCFG_INIT);
	board_sysconfig(SYSCFG_HEADSET, SYSCFG_INIT);

	/*Fix the audio path is wrong when headset already plugged in the device  then boot device case.*/
	if (mic.headset_pd->hsgpio != 0)
	{
		mic.headset_pd->check_hs_state(&mic.headset_state);
		printk("%s: headset_state:%d\n", __func__, mic.headset_state); 
		set_irq_type(mic.hsirq, (mic.headset_state) ? IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING);
		schedule_work(&(mic.switch_data.work));
		schedule_delayed_work(&(mic.imsi_work), GET_IMSI_REF_TIME);
	}

	return 0;

err2:   unregister_chrdev(mic.hsmajor,"BrcmHeadset");
	if(mic.headset_pd->hsgpio)
		del_timer_sync(&mic.timer);
err1:   hs_unreginputdev(&mic);
err:    hs_unregsysfs(&mic);
	return result;
}
示例#5
0
/**
 * __ir_input_register() - sets the IR keycode table and add the handlers
 *			    for keymap table get/set
 * @input_dev:	the struct input_dev descriptor of the device
 * @rc_tab:	the struct ir_scancode_table table of scancode/keymap
 *
 * This routine is used to initialize the input infrastructure
 * to work with an IR.
 * It will register the input/evdev interface for the device and
 * register the syfs code for IR class
 */
int __ir_input_register(struct input_dev *input_dev,
		      const struct ir_scancode_table *rc_tab,
		      struct ir_dev_props *props,
		      const char *driver_name)
{
	struct ir_input_dev *ir_dev;
	int rc;

	if (rc_tab->scan == NULL || !rc_tab->size)
		return -EINVAL;

	ir_dev = kzalloc(sizeof(*ir_dev), GFP_KERNEL);
	if (!ir_dev)
		return -ENOMEM;

	ir_dev->driver_name = kasprintf(GFP_KERNEL, "%s", driver_name);
	if (!ir_dev->driver_name) {
		rc = -ENOMEM;
		goto out_dev;
	}

	input_dev->getkeycode = ir_getkeycode;
	input_dev->setkeycode = ir_setkeycode;
	input_set_drvdata(input_dev, ir_dev);
	ir_dev->input_dev = input_dev;

	spin_lock_init(&ir_dev->rc_tab.lock);
	spin_lock_init(&ir_dev->keylock);
	setup_timer(&ir_dev->timer_keyup, ir_timer_keyup, (unsigned long)ir_dev);

	ir_dev->rc_tab.name = rc_tab->name;
	ir_dev->rc_tab.ir_type = rc_tab->ir_type;
	ir_dev->rc_tab.alloc = roundup_pow_of_two(rc_tab->size *
						  sizeof(struct ir_scancode));
	ir_dev->rc_tab.scan = kmalloc(ir_dev->rc_tab.alloc, GFP_KERNEL);
	ir_dev->rc_tab.size = ir_dev->rc_tab.alloc / sizeof(struct ir_scancode);
	if (props) {
		ir_dev->props = props;
		if (props->open)
			input_dev->open = ir_open;
		if (props->close)
			input_dev->close = ir_close;
	}

	if (!ir_dev->rc_tab.scan) {
		rc = -ENOMEM;
		goto out_name;
	}

	IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n",
		   ir_dev->rc_tab.size, ir_dev->rc_tab.alloc);

	set_bit(EV_KEY, input_dev->evbit);
	set_bit(EV_REP, input_dev->evbit);
	set_bit(EV_MSC, input_dev->evbit);
	set_bit(MSC_SCAN, input_dev->mscbit);

	if (ir_setkeytable(input_dev, &ir_dev->rc_tab, rc_tab)) {
		rc = -ENOMEM;
		goto out_table;
	}

	rc = ir_register_class(input_dev);
	if (rc < 0)
		goto out_table;

	if (ir_dev->props)
		if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW) {
			rc = ir_raw_event_register(input_dev);
			if (rc < 0)
				goto out_event;
		}

	IR_dprintk(1, "Registered input device on %s for %s remote%s.\n",
		   driver_name, rc_tab->name,
		   (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_IR_RAW) ?
			" in raw mode" : "");

	/*
	 * Default delay of 250ms is too short for some protocols, expecially
	 * since the timeout is currently set to 250ms. Increase it to 500ms,
	 * to avoid wrong repetition of the keycodes.
	 */
	input_dev->rep[REP_DELAY] = 500;

	return 0;

out_event:
	ir_unregister_class(input_dev);
out_table:
	kfree(ir_dev->rc_tab.scan);
out_name:
	kfree(ir_dev->driver_name);
out_dev:
	kfree(ir_dev);
	return rc;
}
示例#6
0
static int omap2430_musb_init(struct musb *musb)
{
	u32 l, status = 0;
	struct device *dev = musb->controller;
	struct musb_hdrc_platform_data *plat = dev->platform_data;
	struct omap_musb_board_data *data = plat->board_data;

	/* We require some kind of external transceiver, hooked
	 * up through ULPI.  TWL4030-family PMICs include one,
	 * which needs a driver, drivers aren't always needed.
	 */
	musb->xceiv = otg_get_transceiver();
	if (!musb->xceiv) {
		pr_err("HS USB OTG: no transceiver configured\n");
		return -ENODEV;
	}

	omap2430_low_level_init(musb);

	l = musb_readl(musb->mregs, OTG_SYSCONFIG);
	l &= ~ENABLEWAKEUP;	/* disable wakeup */
	l &= ~NOSTDBY;		/* remove possible nostdby */
	l |= SMARTSTDBY;	/* enable smart standby */
	l &= ~AUTOIDLE;		/* disable auto idle */
	l &= ~NOIDLE;		/* remove possible noidle */
	l |= SMARTIDLE;		/* enable smart idle */
	/*
	 * MUSB AUTOIDLE don't work in 3430.
	 * Workaround by Richard Woodruff/TI
	 */
	if (!cpu_is_omap3430())
		l |= AUTOIDLE;		/* enable auto idle */
	musb_writel(musb->mregs, OTG_SYSCONFIG, l);

	l = musb_readl(musb->mregs, OTG_INTERFSEL);

	if (data->interface_type == MUSB_INTERFACE_UTMI) {
		/* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
		l &= ~ULPI_12PIN;       /* Disable ULPI */
		l |= UTMI_8BIT;         /* Enable UTMI  */
	} else {
		l |= ULPI_12PIN;
	}

	musb_writel(musb->mregs, OTG_INTERFSEL, l);

	pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
			"sysstatus 0x%x, intrfsel 0x%x, simenable  0x%x\n",
			musb_readl(musb->mregs, OTG_REVISION),
			musb_readl(musb->mregs, OTG_SYSCONFIG),
			musb_readl(musb->mregs, OTG_SYSSTATUS),
			musb_readl(musb->mregs, OTG_INTERFSEL),
			musb_readl(musb->mregs, OTG_SIMENABLE));

	musb->nb.notifier_call = musb_otg_notifications;
	status = otg_register_notifier(musb->xceiv, &musb->nb);

	if (status)
		DBG(1, "notification register failed\n");

	/* check whether cable is already connected */
	if (musb->xceiv->state ==OTG_STATE_B_IDLE)
		musb_otg_notifications(&musb->nb, 1,
					musb->xceiv->gadget);

	setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);

	return 0;
}
示例#7
0
static int __devinit rk28_AD_button_probe(struct platform_device *pdev)
{
	struct rk28_AD_button *AD_button;
	struct input_dev *input_dev;
	int  error,i;
	AD_button = kzalloc(sizeof(struct rk28_AD_button), GFP_KERNEL);
	/* Create and register the input driver. */
	input_dev = input_allocate_device();
	if (!input_dev || !AD_button) {
		dev_err(&pdev->dev, "failed to allocate input device\n");
		error = -ENOMEM;
		goto failed1;
	}

    //a@nzy
	int ret = request_irq(IRQ_NR_ADC, rk28_AD_irq_handler, 0, "ADC", NULL);
	if (ret < 0) {
		printk(KERN_CRIT "Can't register IRQ for ADC\n");
		return ret;
	}
	
	memcpy(AD_button->keycodes, initkey_code, sizeof(AD_button->keycodes));
	input_dev->name = pdev->name;
	input_dev->open = rk28_AD_button_open;
	input_dev->close = rk28_AD_button_close;
	input_dev->dev.parent = &pdev->dev;
	input_dev->phys = KEY_PHYS_NAME;
	input_dev->id.vendor = 0x0001;
	input_dev->id.product = 0x0001;
	input_dev->id.version = 0x0100;
	input_dev->keycode = AD_button->keycodes;
	input_dev->keycodesize = sizeof(unsigned char);
	input_dev->keycodemax = ARRAY_SIZE(initkey_code);
	for (i = 0; i < ARRAY_SIZE(initkey_code); i++)
		set_bit(initkey_code[i], input_dev->keybit);
	clear_bit(0, input_dev->keybit);

	AD_button->input_dev = input_dev;
	input_set_drvdata(input_dev, AD_button);

	input_dev->evbit[0] = BIT_MASK(EV_KEY) ;

	platform_set_drvdata(pdev, AD_button);

	ADCInit();
	prockAD_button=AD_button;

	/* Register the input device */
	error = input_register_device(input_dev);
	if (error) {
		dev_err(&pdev->dev, "failed to register input device\n");
		goto failed2;
	}

	setup_timer(&AD_button->timer, rk28_adkeyscan_timer, (unsigned long)AD_button);
	//mod_timer(&AD_button->timer, 100);
	AD_button->timer.expires  = jiffies + 3;
	add_timer(&AD_button->timer);
#if 1
        error = request_gpio_irq(GPIOPortE_Pin2,rk28_AD_irq_handler,GPIOEdgelFalling,NULL);
	if(error)
	{
		printk("unable to request recover key IRQ\n");
		goto failed2;
	}	
#endif        

	return 0;

failed2:
	input_unregister_device(AD_button->input_dev);
	platform_set_drvdata(pdev, NULL);	
failed1:
	input_free_device(input_dev);
	kfree(AD_button);
	return error;
}
static int modem_boot_probe(struct platform_device *pdev)
{
    int ret = 0;
    struct device *dev = &pdev->dev;
    struct device_node *np = dev->of_node;

    vmdata = kzalloc(sizeof(struct viatel_modem_data), GFP_KERNEL);
    if(!vmdata)
    {
        ret = -ENOMEM;
        hwlog_err("No memory to alloc vmdata");
        goto err_create_vmdata;
    }

    vmdata->via_pdev = pdev;
    vmdata->tail = 0;
    vmdata->head = 0;

    ret = modem_data_init(vmdata);
    if(ret < 0)
    {
        hwlog_err("Fail to init modem data\n");
        goto err_init_modem_data;
    }

    ret = platform_device_register(&viacbp82d_3rd_modem_info);
    if (ret) {
        hwlog_err( "%s: platform_device_register failed, ret:%d.\n",
                __func__, ret);
        goto err_register_platform_device;
    }

    ret = sysfs_create_group(&viacbp82d_3rd_modem_info.dev.kobj, &viacbp82d_3rd_modem_node);
    if (ret) {
        hwlog_err( "sensor_input_info_init sysfs_create_group error ret =%d", ret);
        platform_device_unregister(&viacbp82d_3rd_modem_info);
        goto err_create_sysfs_group;
    }

    ret = of_property_read_u32(np, "via_reset_ind_connect_to_codec", &cbp_reset_ind_connect_to_codec);
    if(ret) {
        hwlog_err("can't get cbp_reset_ind_connect_to_codec property in viacbp82d_power device node\n");
        goto err_get_gpio;
    }

    hwlog_info("get cbp_reset_ind_connect_to_codec:%u\n", cbp_reset_ind_connect_to_codec);

    /* rst_ind is connect to hi6402 codec in fifa */
    cbp_rst_ind_gpio = of_get_named_gpio(np, "via_reset_ind", 0);//gpio is 254
    hwlog_info("%s get CBP_VIATEL_RST_IND_STR gpio %d\n", __func__, cbp_rst_ind_gpio);
    if(GPIO_OEM_VALID(cbp_rst_ind_gpio)){
        int irq = 0;
        ret = oem_gpio_request(cbp_rst_ind_gpio, "GPIO_VIATEL_MDM_RST_IND");
        if(ret < 0 )
        {
            hwlog_err("%s:%d gpio_request %d fail, return:%d\n", __func__, __LINE__, cbp_rst_ind_gpio, ret);
        }
        oem_gpio_irq_mask(cbp_rst_ind_gpio);
        ret = oem_gpio_direction_input_for_irq(cbp_rst_ind_gpio);
        if(ret < 0 )
        {
            hwlog_err("%s:%d gpio_direction_inout_for_irq %d fail, return:%d\n", __func__, __LINE__, cbp_rst_ind_gpio, ret);
        }

        irq = oem_gpio_to_irq(cbp_rst_ind_gpio);
        hwlog_info("%s:%d cbp_rst_ind_gpio:%d irq is:%d\n", __func__, __LINE__,  cbp_rst_ind_gpio, irq);

        oem_gpio_set_irq_type(cbp_rst_ind_gpio, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING);

        if( cbp_reset_ind_connect_to_codec ) {
            //connected to hi6402, then use task context api to register irq handler.
            ret = oem_gpio_request_threaded_irq(cbp_rst_ind_gpio, modem_reset_indication_irq, \
                            IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_TRIGGER_FALLING, \
                            "mdm_reset_ind", vmdata);
        } else {
            ret = oem_gpio_request_irq(cbp_rst_ind_gpio, modem_reset_indication_irq, \
                            IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_TRIGGER_FALLING, \
                            "mdm_reset_ind", vmdata);
        }

        oem_gpio_irq_unmask(cbp_rst_ind_gpio);

        if (ret < 0) {
            hwlog_err("%s:%d fail to request mdm_rst_ind %d irq, return:%d\n", __func__, __LINE__, cbp_rst_ind_gpio, ret);
        }
        hwlog_info("%s:%d gpio via_reset_ind %d init successfully\n", __func__, __LINE__, cbp_rst_ind_gpio);

        modem_register_notifier(&vmdata->rst_ntf);
    } else {
        hwlog_err("%s:%d via_reset_ind is invalid gpio\n", __func__, __LINE__);
        goto err_get_gpio;
    }

    cbp_pwr_en_gpio = of_get_named_gpio(np, "via_pwr_en", 0);
    hwlog_info("%s get CBP_VIATEL_PWR_EN_STR gpio %d\n", __func__, cbp_pwr_en_gpio);
    if(GPIO_OEM_VALID(cbp_pwr_en_gpio)){
        ret = oem_gpio_request(cbp_pwr_en_gpio, "GPIO_VIATEL_MDM_PWR_EN");
        if (0 > ret) {
            hwlog_err("%s: gpio request GPIO_VIATEL_MDM_PWR_EN failed", __FUNCTION__);
        }
        oem_gpio_direction_output(cbp_pwr_en_gpio, 0);
    } else {
        goto err_get_gpio;
    }

    cbp_rst_gpio = of_get_named_gpio(np, "via_rst_mdm", 0);
    hwlog_info("%s get CBP_VIATEL_CBP_RST_STR gpio %d\n", __func__, cbp_rst_gpio);
    if(GPIO_OEM_VALID(cbp_rst_gpio)){
        ret = oem_gpio_request(cbp_rst_gpio, "GPIO_VIATEL_MDM_RST");
        if (0 > ret) {
            hwlog_err("%s: gpio request GPIO_VIATEL_MDM_RST failed", __FUNCTION__);
        }
        oem_gpio_direction_output(cbp_rst_gpio, 0);
    } else {
        goto err_get_gpio;
    }

#if 0 //don't delete. there is no gpio for sim switch
    cbp_sim_switch_gpio = of_get_named_gpio(np, "via_sim_switch", 0);
    hwlog_info("%s get CBP_VIATEL_CBP_SIM_SWITCH gpio %d\n", __func__, cbp_sim_switch_gpio);
    if(GPIO_OEM_VALID(cbp_sim_switch_gpio)){
        ret = oem_gpio_request(cbp_sim_switch_gpio, "GPIO_VIATEL_MDM_SIM_SWITCH");
        if(0 > ret){
            hwlog_err("%s: gpio request GPIO_VIATEL_MDM_SIM_SWITCH failed", __FUNCTION__);
        }
        oem_gpio_direction_output(cbp_sim_switch_gpio, 0);
    } else {
        goto err_get_gpio;
    }
#endif

    /*add gpio function to make cp ramdump*/
    cbp_backup_gpio = of_get_named_gpio(np, "via_backup", 0);
    hwlog_info("%s get CBP_VIATEL_CBP_BACKUP gpio %d\n", __func__, cbp_backup_gpio);
    if(GPIO_OEM_VALID(cbp_backup_gpio)){
        ret = oem_gpio_request(cbp_backup_gpio, "gpio_cbp_crash");
        if(0 > ret){
            hwlog_err("%s: gpio request gpio_cbp_crash failed", __FUNCTION__);
        }
        oem_gpio_direction_output(cbp_backup_gpio, 0);
        setup_timer(&cbp_backup_timer, cbp_backup_check_ramdump_timer, (unsigned long)NULL);
    } else {
        goto err_get_gpio;
    }

    return 0;

err_get_gpio:
    sysfs_remove_group(&viacbp82d_3rd_modem_info.dev.kobj, &viacbp82d_3rd_modem_node);
err_create_sysfs_group:
    platform_device_unregister(&viacbp82d_3rd_modem_info);
err_register_platform_device:
err_init_modem_data:
    kfree(vmdata);
    vmdata = NULL;
err_create_vmdata:

    return ret;
}
示例#9
0
int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id,
		  struct regmap *regmap,
		  int (*tsc200x_cmd)(struct device *dev, u8 cmd))
{
	const struct tsc2005_platform_data *pdata = dev_get_platdata(dev);
	struct device_node *np = dev->of_node;

	struct tsc200x *ts;
	struct input_dev *input_dev;
	unsigned int max_x = MAX_12BIT;
	unsigned int max_y = MAX_12BIT;
	unsigned int max_p = MAX_12BIT;
	unsigned int fudge_x = TSC200X_DEF_X_FUZZ;
	unsigned int fudge_y = TSC200X_DEF_Y_FUZZ;
	unsigned int fudge_p = TSC200X_DEF_P_FUZZ;
	unsigned int x_plate_ohm = TSC200X_DEF_RESISTOR;
	unsigned int esd_timeout;
	int error;

	if (!np && !pdata) {
		dev_err(dev, "no platform data\n");
		return -ENODEV;
	}

	if (irq <= 0) {
		dev_err(dev, "no irq\n");
		return -ENODEV;
	}

	if (IS_ERR(regmap))
		return PTR_ERR(regmap);

	if (!tsc200x_cmd) {
		dev_err(dev, "no cmd function\n");
		return -ENODEV;
	}

	if (pdata) {
		fudge_x	= pdata->ts_x_fudge;
		fudge_y	= pdata->ts_y_fudge;
		fudge_p	= pdata->ts_pressure_fudge;
		max_x	= pdata->ts_x_max;
		max_y	= pdata->ts_y_max;
		max_p	= pdata->ts_pressure_max;
		x_plate_ohm = pdata->ts_x_plate_ohm;
		esd_timeout = pdata->esd_timeout_ms;
	} else {
		x_plate_ohm = TSC200X_DEF_RESISTOR;
		of_property_read_u32(np, "ti,x-plate-ohms", &x_plate_ohm);
		esd_timeout = 0;
		of_property_read_u32(np, "ti,esd-recovery-timeout-ms",
								&esd_timeout);
	}

	ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
	if (!ts)
		return -ENOMEM;

	input_dev = devm_input_allocate_device(dev);
	if (!input_dev)
		return -ENOMEM;

	ts->irq = irq;
	ts->dev = dev;
	ts->idev = input_dev;
	ts->regmap = regmap;
	ts->tsc200x_cmd = tsc200x_cmd;
	ts->x_plate_ohm = x_plate_ohm;
	ts->esd_timeout = esd_timeout;

	ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
	if (IS_ERR(ts->reset_gpio)) {
		error = PTR_ERR(ts->reset_gpio);
		dev_err(dev, "error acquiring reset gpio: %d\n", error);
		return error;
	}

	ts->vio = devm_regulator_get_optional(dev, "vio");
	if (IS_ERR(ts->vio)) {
		error = PTR_ERR(ts->vio);
		dev_err(dev, "vio regulator missing (%d)", error);
		return error;
	}

	if (!ts->reset_gpio && pdata)
		ts->set_reset = pdata->set_reset;

	mutex_init(&ts->mutex);

	spin_lock_init(&ts->lock);
	setup_timer(&ts->penup_timer, tsc200x_penup_timer, (unsigned long)ts);

	INIT_DELAYED_WORK(&ts->esd_work, tsc200x_esd_work);

	snprintf(ts->phys, sizeof(ts->phys),
		 "%s/input-ts", dev_name(dev));

	if (tsc_id->product == 2004) {
		input_dev->name = "TSC200X touchscreen";
	} else {
		input_dev->name = devm_kasprintf(dev, GFP_KERNEL,
						 "TSC%04d touchscreen",
						 tsc_id->product);
		if (!input_dev->name)
			return -ENOMEM;
	}

	input_dev->phys = ts->phys;
	input_dev->id = *tsc_id;
	input_dev->dev.parent = dev;
	input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
	input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);

	input_set_abs_params(input_dev, ABS_X, 0, max_x, fudge_x, 0);
	input_set_abs_params(input_dev, ABS_Y, 0, max_y, fudge_y, 0);
	input_set_abs_params(input_dev, ABS_PRESSURE, 0, max_p, fudge_p, 0);

	if (np)
		touchscreen_parse_properties(input_dev, false);

	input_dev->open = tsc200x_open;
	input_dev->close = tsc200x_close;

	input_set_drvdata(input_dev, ts);

	/* Ensure the touchscreen is off */
	tsc200x_stop_scan(ts);

	error = devm_request_threaded_irq(dev, irq, NULL,
					  tsc200x_irq_thread,
					  IRQF_TRIGGER_RISING | IRQF_ONESHOT,
					  "tsc200x", ts);
	if (error) {
		dev_err(dev, "Failed to request irq, err: %d\n", error);
		return error;
	}

	/* enable regulator for DT */
	if (ts->vio) {
		error = regulator_enable(ts->vio);
		if (error)
			return error;
	}

	dev_set_drvdata(dev, ts);
	error = sysfs_create_group(&dev->kobj, &tsc200x_attr_group);
	if (error) {
		dev_err(dev,
			"Failed to create sysfs attributes, err: %d\n", error);
		goto disable_regulator;
	}

	error = input_register_device(ts->idev);
	if (error) {
		dev_err(dev,
			"Failed to register input device, err: %d\n", error);
		goto err_remove_sysfs;
	}

	irq_set_irq_wake(irq, 1);
	return 0;

err_remove_sysfs:
	sysfs_remove_group(&dev->kobj, &tsc200x_attr_group);
disable_regulator:
	if (ts->vio)
		regulator_disable(ts->vio);
	return error;
}
示例#10
0
int hea_eq0_alloc(struct rhea_eq0 *eq0, struct hea_adapter *ap)
{
    int rc;
    struct hea_eq_context context_eq;
    struct hea_process process = { 0 };

    if (NULL == eq0) {
        rhea_error("Invalid parameters passed in");
        return -EINVAL;
    }

    rhea_debug("Create EQ0 for hypervisor");

    context_eq.cfg.eqe_count = 16;
    context_eq.cfg.coalesing2_delay = HEA_EQ_COALESING_DELAY_0;

    context_eq.cfg.generate_completion_events =
        HEA_EQ_GEN_COM_EVENT_DISABLE;

    context_eq.cfg.irq_type = HEA_IRQ_COALESING_2;

    /* make sure we create a real EQ0 */
    process.lpar = 0xFF;

    eq0->eq = rhea_eq_create(&process, &context_eq.cfg);
    if (NULL == eq0->eq) {
        rhea_error("Was not able to allocate EQ0");
        return -ENOMEM;
    }

    /* make sure that this EQ is released again */
    if (0 != eq0->eq->id) {
        rhea_error("Was not able to get EQ0");
        rhea_eq_destroy(eq0->eq);
        return -EPERM;
    }

    /* set base information */
    eq0->q.q_begin = (unsigned char *) eq0->eq->q.va;
    eq0->q.qe_size = sizeof(struct hea_eqe);
    eq0->q.qe_count = eq0->eq->q.size / sizeof(struct hea_eqe);

    /* initialise rest */
    heaq_init(&eq0->q);

    eq0->irq_workqueue = create_singlethread_workqueue("EQ0");
    if (NULL == eq0->irq_workqueue) {
        rhea_error("Was not able to allocate workqueue");
        return -ENOMEM;
    }

    /* prepare work queue */
    INIT_DELAYED_WORK(&eq0->irq_work, &eq0_scan_eq);
    PREPARE_DELAYED_WORK(&eq0->irq_work, &eq0_scan_eq);

    INIT_WORK(&eq0->timer_work, &hea_eq0_timer_pport_event);
    PREPARE_WORK(&eq0->timer_work, &hea_eq0_timer_pport_event);

    /* timer */
    setup_timer(&eq0->timer,
                hea_eq0_timer_callback, (ulong) eq0);

    rc = mod_timer(&eq0->timer,
                   jiffies +
                   msecs_to_jiffies(CONFIG_POWEREN_RHEA_TIMER_MS));
    if (rc) {
        rhea_error("Error in mod_timer");
        goto out;
    }


    rc = rhea_interrupts_setup(eq0->eq, ap->name, ap->hwirq_base,
                               ap->hwirq_count, eq0_irq_handler, eq0);
    if (rc) {
        rhea_error("Was not able to register interupt "
                   "handler for EQ0");
        goto out;
    }

    spin_lock_init(&eq0->lock);

    return 0;
out:
    if (eq0->eq)
        rhea_eq_destroy(eq0->eq);

    if (eq0->irq_workqueue)
        destroy_workqueue(eq0->irq_workqueue);

    del_timer(&eq0->timer);

    return rc;
}
示例#11
0
int  init_service(int isparent)
{

	if (!isparent) {

        DEBUG_LOG("INIT_SERVICE");
	    const char *ip= get_ip_ex(0x01);
	    if ( strncmp( ip,"10.",3 )==0 ) {
	        g_is_test_env=true;
			DEBUG_LOG("=============TEST ENV TRUE =============");
	    }else{
	        g_is_test_env=false;
			DEBUG_LOG("=============TEST ENV FALSE =============");
	    }

		g_log_send_buf_hex_flag=g_is_test_env?1:0;
	



		if (sizeof(sprite_t) >= SPRITE_STRUCT_LEN - 800 || sizeof(grp_loop_t) != VIP_BUFF_LEN) {
			ERROR_RETURN(("sprite struct not big enough\t[%lu %u]", sizeof(sprite_t), SPRITE_STRUCT_LEN), -1);
		}
		srand(time(0) * get_server_id());
		setup_timer();
		INIT_LIST_HEAD(&(g_events.timer_list));
		INIT_LIST_HEAD(&active_box_list);
		if ( config_get_strval("_use_lua_config") ==NULL  ){
			config_init("./conf/common.conf");
		}

		statistic_logfile = config_get_strval("statistic_file");
		if (!statistic_logfile)
			return -1;
		if ((init_cli_proto_handles(0) == -1)	|| 
			(init_db_proto_handles(0) == -1)		||
			(init_home_handle_funs() == -1)		||
			(init_switch_handle_funs() == -1)		||
			(init_all_timer_type() == -1)			||
			(init_magic_code_proto_handles(0) == -1) ||
			(init_spacetime_code_proto_handles(0) == -1) ||
			(init_mall_proto_handles(0) == -1)
			) {
			return -1;
		}
		init_sprites();
		init_exp_lv();
		init_home_maps();
		init_all_items();
		init_beast_grp();
		init_rand_infos();
		init_npcs();
		init_all_skills();
		init_all_clothes();
		init_sys_info();
		init_all_tasks();
		init_mail();
		init_shops();
		init_vip_items();
		init_products();

		idc_type = config_get_intval("idc_type" ,1);
		KDEBUG_LOG(0, "ONLINE START\t[%lu %d]", sizeof(sprite_t), idc_type);

		if (
			//11
			(load_xmlconf("./conf/items.xml", load_items) == -1)
			|| (load_xmlconf("./conf/clothes.xml", load_clothes) == -1)
			|| (load_xmlconf("./conf/beasts.xml", load_beasts) == -1)
			//
			|| (load_xmlconf("./conf/pet_exchange.xml", load_pet_exchange) == -1)//3M
			|| (load_xmlconf("./conf/pet_exchange_egg.xml", load_pet_exchange_egg) == -1)
			//62
			|| (load_xmlconf("./conf/gplan.xml", load_rare_beasts) == -1)
			|| (load_xmlconf("./conf/titles.xml", load_honor_titles) == -1)
			|| (load_xmlconf("./conf/picsrv.xml", load_picsrv_config) == -1)
			) {
			return -1;
		}
		if (
				load_xmlconf("./conf/beastgrp.xml", load_beast_grp) == -1 
				|| (load_xmlconf("./conf/handbook.xml", load_handbook) == -1)
				|| (load_xmlconf("./conf/suits.xml", load_suit) == -1)
				|| ( load_xmlconf("./conf/maps.xml", load_maps) == -1)
				|| (load_xmlconf("./conf/rand_item.xml", load_rand_item) == -1)
				|| (load_xmlconf("./conf/vip_item.xml", load_vip_item) == -1)
				|| (load_xmlconf("./conf/commodity.xml", load_products) == -1)
				|| (load_xmlconf("./conf/skills_price.xml", load_all_skills) == -1)
				|| (load_xmlconf("./conf/tasks_new.xml", load_tasks) == -1)//task:12M
				|| (load_xmlconf("./conf/tasks_new.xml", load_task_loops) == -1)
				|| (load_xmlconf("./conf/holiday.xml", load_holiday_factor) == -1)
				|| (load_xmlconf("./conf/box.xml", load_box) == -1)
				|| (load_xmlconf("./conf/exchanges.xml", load_exchange_info) == -1)
				|| (load_xmlconf("./conf/npc.xml", load_npc) == -1)
				|| (load_xmlconf("./conf/npcSkills.xml", load_shop_skill) == -1)
				|| (load_xmlconf("./conf/npcShop.xml", load_shop_item) == -1)
				|| (load_xmlconf("./conf/mail.xml", load_sys_mail) == -1)
				|| (load_xmlconf("./conf/sysinfo.xml", load_sys_info) == -1)
				|| (load_xmlconf("./conf/fishGame.xml", load_fish_info) == -1)
				|| (load_xmlconf("./conf/professtion.xml", load_init_prof_info) == -1)
				|| (load_xmlconf("./conf/maze.xml", load_maze_xml) == -1)
				|| (load_xmlconf("./conf/mapcopy.xml", load_map_copy) == -1)
			)

			return -1;

	//	sleep(1000);
		activate_boxes();
		start_maze_timer();

		/*
		if(tm_load_dirty("./data/tm_dirty.dat") < 0){
			KERROR_LOG(0, "Failed to load drity word file!");
			return -1;
		}
		*/
		
		init_batter_teams();
		init_batter_infos();
		connect_to_switch_timely(0, 0);
		regist_timers();
		udp_report_fd = create_udp_socket(&udp_report_addr, config_get_strval("report_svr_ip"), config_get_intval("report_svr_port", 0));
		udp_post_fd = create_udp_socket(&udp_post_addr, config_get_strval("post_svr_ip"), config_get_intval("post_svr_port", 0));
		switch (idc_type) {
		case idc_type_dx:
			chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("dx_chat_svr_ip"), config_get_intval("chat_svr_port", 0));
			break;
		case idc_type_wt:
			chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("wt_chat_svr_ip"), config_get_intval("chat_svr_port", 0));
			break;
		case idc_type_internal:
		case idc_type_internal + 1:
			chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("in_chat_svr_ip"), config_get_intval("chat_svr_port", 0));
			break;
		default:
			return -1;
		}
	}

	return 0;
}
示例#12
0
static int __devinit tsc2005_ts_init(struct tsc2005 *ts,
				     struct tsc2005_platform_data *pdata)
{
	struct input_dev *idev;
	int r;
	int x_max, y_max;

	init_timer(&ts->penup_timer);
	setup_timer(&ts->penup_timer, tsc2005_ts_penup_timer_handler,
			(unsigned long)ts);

	spin_lock_init(&ts->lock);
	mutex_init(&ts->mutex);

	ts->x_plate_ohm		= pdata->ts_x_plate_ohm ? : 280;
	ts->hw_avg_max		= pdata->ts_hw_avg;
	ts->stab_time		= pdata->ts_stab_time;
	x_max			= pdata->ts_x_max ? : 4096;
	ts->fudge_x		= pdata->ts_x_fudge ? : 4;
	y_max			= pdata->ts_y_max ? : 4096;
	ts->fudge_y		= pdata->ts_y_fudge ? : 8;
	ts->p_max		= pdata->ts_pressure_max ? : MAX_12BIT;
	ts->touch_pressure	= pdata->ts_touch_pressure ? : ts->p_max;
	ts->fudge_p		= pdata->ts_pressure_fudge ? : 2;

	ts->set_reset		= pdata->set_reset;

	if (prescale) {
		x_max = x_size;
		y_max = y_size;
	}

	idev = input_allocate_device();
	if (idev == NULL) {
		r = -ENOMEM;
		goto err1;
	}

	idev->name = "TSC2005 touchscreen";
	snprintf(ts->phys, sizeof(ts->phys), "%s/input-ts",
		 ts->spi->dev.bus_id);
	idev->phys = ts->phys;

	idev->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY);
	idev->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | BIT_MASK(ABS_PRESSURE);
	idev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
	ts->idev = idev;

	tsc2005_ts_setup_spi_xfer(ts);

	input_set_abs_params(idev, ABS_X, 0, x_max, ts->fudge_x, 0);
	input_set_abs_params(idev, ABS_Y, 0, y_max, ts->fudge_y, 0);
	input_set_abs_params(idev, ABS_PRESSURE, 0, ts->p_max, ts->fudge_p, 0);

	tsc2005_start_scan(ts);

	r = request_irq(ts->spi->irq, tsc2005_ts_irq_handler,
			(((TSC2005_CFR2_INITVALUE & TSC2005_CFR2_IRQ_MASK) ==
			  TSC2005_CFR2_IRQ_PENDAV)
			 ? IRQF_TRIGGER_RISING
			 : IRQF_TRIGGER_FALLING) |
			IRQF_DISABLED | IRQF_SAMPLE_RANDOM, "tsc2005", ts);
	if (r < 0) {
		dev_err(&ts->spi->dev, "unable to get DAV IRQ");
		goto err2;
	}

	set_irq_wake(ts->spi->irq, 1);

	r = input_register_device(idev);
	if (r < 0) {
		dev_err(&ts->spi->dev, "can't register touchscreen device\n");
		goto err3;
	}

	/* We can tolerate these failing */
	r = device_create_file(&ts->spi->dev, &dev_attr_ts_ctrl_selftest);
	if (r < 0)
		dev_warn(&ts->spi->dev, "can't create sysfs file for %s: %d\n",
			 dev_attr_ts_ctrl_selftest.attr.name, r);

	r = device_create_file(&ts->spi->dev, &dev_attr_pen_down);
	if (r < 0)
		dev_warn(&ts->spi->dev, "can't create sysfs file for %s: %d\n",
			 dev_attr_pen_down.attr.name, r);

	r = device_create_file(&ts->spi->dev, &dev_attr_disable_ts);
	if (r < 0)
		dev_warn(&ts->spi->dev, "can't create sysfs file for %s: %d\n",
			 dev_attr_disable_ts.attr.name, r);

	/* Finally, configure and start the optional EDD watchdog. */
	ts->esd_timeout = pdata->esd_timeout;
	if (ts->esd_timeout && ts->set_reset) {
		unsigned long wdj;
		setup_timer(&ts->esd_timer, tsc2005_esd_timer_handler,
			    (unsigned long)ts);
		INIT_WORK(&ts->esd_work, tsc2005_rst_handler);
		wdj = msecs_to_jiffies(ts->esd_timeout);
		ts->esd_timer.expires = round_jiffies(jiffies+wdj);
		add_timer(&ts->esd_timer);
	}

	return 0;
err3:
	free_irq(ts->spi->irq, ts);
err2:
	tsc2005_stop_scan(ts);
	input_free_device(idev);
err1:
	return r;
}
示例#13
0
static int imx_keypad_probe(struct platform_device *pdev)
{
	const struct matrix_keymap_data *keymap_data =
			dev_get_platdata(&pdev->dev);
	struct imx_keypad *keypad;
	struct input_dev *input_dev;
	struct resource *res;
	int irq, error, i, row, col;

	if (!keymap_data && !pdev->dev.of_node) {
		dev_err(&pdev->dev, "no keymap defined\n");
		return -EINVAL;
	}

	irq = platform_get_irq(pdev, 0);
	if (irq < 0) {
		dev_err(&pdev->dev, "no irq defined in platform data\n");
		return irq;
	}

	input_dev = devm_input_allocate_device(&pdev->dev);
	if (!input_dev) {
		dev_err(&pdev->dev, "failed to allocate the input device\n");
		return -ENOMEM;
	}

	keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL);
	if (!keypad) {
		dev_err(&pdev->dev, "not enough memory for driver data\n");
		return -ENOMEM;
	}

	keypad->input_dev = input_dev;
	keypad->irq = irq;
	keypad->stable_count = 0;

	setup_timer(&keypad->check_matrix_timer,
		    imx_keypad_check_for_events, (unsigned long) keypad);

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	keypad->mmio_base = devm_ioremap_resource(&pdev->dev, res);
	if (IS_ERR(keypad->mmio_base))
		return PTR_ERR(keypad->mmio_base);

	keypad->clk = devm_clk_get(&pdev->dev, NULL);
	if (IS_ERR(keypad->clk)) {
		dev_err(&pdev->dev, "failed to get keypad clock\n");
		return PTR_ERR(keypad->clk);
	}

	/* Init the Input device */
	input_dev->name = pdev->name;
	input_dev->id.bustype = BUS_HOST;
	input_dev->dev.parent = &pdev->dev;
	input_dev->open = imx_keypad_open;
	input_dev->close = imx_keypad_close;

	error = matrix_keypad_build_keymap(keymap_data, NULL,
					   MAX_MATRIX_KEY_ROWS,
					   MAX_MATRIX_KEY_COLS,
					   keypad->keycodes, input_dev);
	if (error) {
		dev_err(&pdev->dev, "failed to build keymap\n");
		return error;
	}

	/* Search for rows and cols enabled */
	for (row = 0; row < MAX_MATRIX_KEY_ROWS; row++) {
		for (col = 0; col < MAX_MATRIX_KEY_COLS; col++) {
			i = MATRIX_SCAN_CODE(row, col, MATRIX_ROW_SHIFT);
			if (keypad->keycodes[i] != KEY_RESERVED) {
				keypad->rows_en_mask |= 1 << row;
				keypad->cols_en_mask |= 1 << col;
			}
		}
	}
	dev_dbg(&pdev->dev, "enabled rows mask: %x\n", keypad->rows_en_mask);
	dev_dbg(&pdev->dev, "enabled cols mask: %x\n", keypad->cols_en_mask);

	__set_bit(EV_REP, input_dev->evbit);
	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
	input_set_drvdata(input_dev, keypad);

	/* Ensure that the keypad will stay dormant until opened */
	error = clk_prepare_enable(keypad->clk);
	if (error)
		return error;
	imx_keypad_inhibit(keypad);
	clk_disable_unprepare(keypad->clk);

	error = devm_request_irq(&pdev->dev, irq, imx_keypad_irq_handler, 0,
			    pdev->name, keypad);
	if (error) {
		dev_err(&pdev->dev, "failed to request IRQ\n");
		return error;
	}

	/* Register the input device */
	error = input_register_device(input_dev);
	if (error) {
		dev_err(&pdev->dev, "failed to register input device\n");
		return error;
	}

	platform_set_drvdata(pdev, keypad);
	device_init_wakeup(&pdev->dev, 1);

	return 0;
}
static int rk2918_battery_probe(struct platform_device *pdev)
{
	int ret;
	struct adc_client *client;
	struct rk2918_battery_data *data;
	struct rk2918_battery_platform_data *pdata = pdev->dev.platform_data;
	int irq_flag;
	int i = 0;
	
	dprint("func=%s, line=%d :\n", __func__, __LINE__);
	
	data = kzalloc(sizeof(*data), GFP_KERNEL);
	if (data == NULL) {
		ret = -ENOMEM;
		goto err_data_alloc_failed;
	}
	gBatteryData = data;

    //clear io
    data->dc_det_pin     = INVALID_GPIO;
    data->batt_low_pin   = INVALID_GPIO;
    data->charge_set_pin = INVALID_GPIO;
	data->charge_ok_pin  = INVALID_GPIO;
	
	if (pdata && pdata->io_init) {
		ret = pdata->io_init();
		if (ret) 
			goto err_free_gpio1;		
	}
	
	//dc det
	if (pdata->dc_det_pin != INVALID_GPIO)
	{
	#ifndef DC_DET_WITH_USB_INT
    	ret = gpio_request(pdata->dc_det_pin, NULL);
    	if (ret) {
    		printk("failed to request dc_det gpio\n");
    		goto err_free_gpio1;
    	}
	#endif
		if(pdata->dc_det_level)
    		gpio_pull_updown(pdata->dc_det_pin, 0);//important
    	else
			gpio_pull_updown(pdata->dc_det_pin, GPIOPullUp);//important
    	ret = gpio_direction_input(pdata->dc_det_pin);
    	if (ret) {
    		printk("failed to set gpio dc_det input\n");
    		goto err_free_gpio1;
    	}
    	data->dc_det_pin   = pdata->dc_det_pin;
    	data->dc_det_level = pdata->dc_det_level;
    }

	if (pdata->charge_cur_ctl != INVALID_GPIO) {

		ret = gpio_request(pdata->charge_cur_ctl, "DC_CURRENT_CONTROL");
		if (ret < 0) {
    		printk("failed to request charge current control gpio\n");
    		goto err_free_gpio2;
		}

		ret = gpio_direction_output(pdata->charge_cur_ctl, !pdata->charge_cur_ctl_level);
		if (ret < 0) {
			printk("rk29_battery: failed to set charge current control gpio\n");
    		goto err_free_gpio2;
		}
		gpio_pull_updown(pdata->charge_cur_ctl, !pdata->charge_cur_ctl_level);
		gpio_set_value(pdata->charge_cur_ctl, !pdata->charge_cur_ctl_level);
		data->charge_cur_ctl = pdata->charge_cur_ctl;
		data->charge_cur_ctl_level = pdata->charge_cur_ctl_level;
	}
	
	//charge set for usb charge
	if (pdata->charge_set_pin != INVALID_GPIO)
	{
    	ret = gpio_request(pdata->charge_set_pin, NULL);
    	if (ret) {
    		printk("failed to request dc_det gpio\n");
    		goto err_free_gpio2;
    	}
    	data->charge_set_pin = pdata->charge_set_pin;
    	data->charge_set_level = pdata->charge_set_level;
    	gpio_direction_output(pdata->charge_set_pin, 1 - pdata->charge_set_level);
    }
	
	//charge_ok
	if (pdata->charge_ok_pin != INVALID_GPIO)
	{
        ret = gpio_request(pdata->charge_ok_pin, NULL);
    	if (ret) {
    		printk("failed to request charge_ok gpio\n");
    		goto err_free_gpio3;
    	}
	
    	gpio_pull_updown(pdata->charge_ok_pin, GPIOPullUp);//important
    	ret = gpio_direction_input(pdata->charge_ok_pin);
    	if (ret) {
    		printk("failed to set gpio charge_ok input\n");
    		goto err_free_gpio3;
    	}
    	data->charge_ok_pin   = pdata->charge_ok_pin;
    	data->charge_ok_level = pdata->charge_ok_level;
    }
    
	client = adc_register(0, rk2918_battery_callback, NULL);
    if(!client)
		goto err_adc_register_failed;
    
	memset(gBatVoltageSamples, 0, sizeof(gBatVoltageSamples));
	spin_lock_init(&data->lock);
    data->adc_val = adc_sync_read(client);
	data->client = client;
    data->battery.properties = rk2918_battery_props;
	data->battery.num_properties = ARRAY_SIZE(rk2918_battery_props);
	data->battery.get_property = rk2918_battery_get_property;
	data->battery.name = "battery";
	data->battery.type = POWER_SUPPLY_TYPE_BATTERY;
	data->adc_bat_divider = 414;
	data->bat_max = BATT_MAX_VOL_VALUE;
	data->bat_min = BATT_ZERO_VOL_VALUE;
	DBG("bat_min = %d\n",data->bat_min);
	
#ifdef RK29_USB_CHARGE_SUPPORT
	data->usb.properties = rk2918_usb_props;
	data->usb.num_properties = ARRAY_SIZE(rk2918_usb_props);
	data->usb.get_property = rk2918_usb_get_property;
	data->usb.name = "usb";
	data->usb.type = POWER_SUPPLY_TYPE_USB;
#endif

	data->ac.properties = rk2918_ac_props;
	data->ac.num_properties = ARRAY_SIZE(rk2918_ac_props);
	data->ac.get_property = rk2918_ac_get_property;
	data->ac.name = "ac";
	data->ac.type = POWER_SUPPLY_TYPE_MAINS;	
	
	rk2918_low_battery_check();
    
	ret = power_supply_register(&pdev->dev, &data->ac);
	if (ret)
	{
		printk(KERN_INFO "fail to ac power_supply_register\n");
		goto err_ac_failed;
	}
#if 0
	ret = power_supply_register(&pdev->dev, &data->usb);
	if (ret)
	{
		printk(KERN_INFO "fail to usb power_supply_register\n");
		goto err_usb_failed;
	}
#endif

	ret = power_supply_register(&pdev->dev, &data->battery);
	if (ret)
	{
		printk(KERN_INFO "fail to battery power_supply_register\n");
		goto err_battery_failed;
	}

	platform_set_drvdata(pdev, data);
	
//    irq_flag = (pdata->charge_ok_level) ? IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
//	ret = request_irq(gpio_to_irq(pdata->charge_ok_pin), rk2918_battery_interrupt, irq_flag, "rk2918_battery", data);
//	if (ret) {
//		printk("failed to request irq\n");
//		goto err_irq_failed;
//	}
#ifndef DC_DET_WITH_USB_INT
    if (pdata->dc_det_pin != INVALID_GPIO)
    {
        irq_flag = (!gpio_get_value (pdata->dc_det_pin)) ? IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
    	ret = request_irq(gpio_to_irq(pdata->dc_det_pin), rk2918_dc_wakeup, irq_flag, "rk2918_battery", data);
    	if (ret) {
    		printk("failed to request dc det irq\n");
    		goto err_dcirq_failed;
    	}
    	data->dc_det_irq = gpio_to_irq(pdata->dc_det_pin);
    	//data->wq = create_rt_workqueue("rk2918_battery");
    	data->wq = create_workqueue("rk2918_battery");
    	INIT_DELAYED_WORK(&data->work, rk2918_battery_work);
    	
    	enable_irq_wake(gpio_to_irq(pdata->dc_det_pin));
    }
#endif

	setup_timer(&data->timer, rk2918_batscan_timer, (unsigned long)data);
	// changed to notify android of status....
	data->timer.expires  = jiffies + 5000; // 2000
	add_timer(&data->timer);
   
	INIT_WORK(&data->timer_work, rk2918_battery_timer_work);   
   
    rk29_battery_dbg_class = class_create(THIS_MODULE, "rk29_battery");
	battery_dev = device_create(rk29_battery_dbg_class, NULL, MKDEV(0, 1), NULL, "battery");
	ret = device_create_file(battery_dev, &dev_attr_rk29_battery_dbg);
	if (ret)
	{
		printk("create file sys failed!!! \n");
		goto err_dcirq_failed;
	}
	for(i = 0; i<10; i++)
	{
		ret = device_create_file(&pdev->dev, &dev_attr_startget);
		if (ret)
		{
			printk("make a mistake in creating devices  attr file, failed times: %d\n\n ", i+1);
			continue;
		}
		break;
	}
	printk(KERN_INFO "rk2918_battery: driver initialized\n");
	
	return 0;
	
err_dcirq_failed:
    free_irq(gpio_to_irq(pdata->dc_det_pin), data);
    
err_irq_failed:
	free_irq(gpio_to_irq(pdata->charge_ok_pin), data);
    
err_battery_failed:
//	power_supply_unregister(&data->usb);
//err_usb_failed:
err_ac_failed:
	power_supply_unregister(&data->ac);
	
err_adc_register_failed:
err_free_gpio3:
	gpio_free(pdata->charge_ok_pin);
err_free_gpio2:
	gpio_free(pdata->charge_cur_ctl);
err_free_gpio1:
    gpio_free(pdata->dc_det_pin);
    
err_data_alloc_failed:
	kfree(data);

    printk("rk2918_battery: error!\n");
    
	return ret;
}
示例#15
0
void intel_uncore_init(struct drm_device *dev)
{
	struct drm_i915_private *dev_priv = dev->dev_private;

	setup_timer(&dev_priv->uncore.force_wake_timer,
		    gen6_force_wake_timer, (unsigned long)dev_priv);

	__intel_uncore_early_sanitize(dev, false);

	if (IS_GEN9(dev)) {
		dev_priv->uncore.funcs.force_wake_get = __gen9_force_wake_get;
		dev_priv->uncore.funcs.force_wake_put = __gen9_force_wake_put;
	} else if (IS_VALLEYVIEW(dev)) {
		dev_priv->uncore.funcs.force_wake_get = __vlv_force_wake_get;
		dev_priv->uncore.funcs.force_wake_put = __vlv_force_wake_put;
	} else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
		dev_priv->uncore.funcs.force_wake_get = __gen7_gt_force_wake_mt_get;
		dev_priv->uncore.funcs.force_wake_put = __gen7_gt_force_wake_mt_put;
	} else if (IS_IVYBRIDGE(dev)) {
		u32 ecobus;

		/* IVB configs may use multi-threaded forcewake */

		/* A small trick here - if the bios hasn't configured
		 * MT forcewake, and if the device is in RC6, then
		 * force_wake_mt_get will not wake the device and the
		 * ECOBUS read will return zero. Which will be
		 * (correctly) interpreted by the test below as MT
		 * forcewake being disabled.
		 */
		mutex_lock(&dev->struct_mutex);
		__gen7_gt_force_wake_mt_get(dev_priv, FORCEWAKE_ALL);
		ecobus = __raw_i915_read32(dev_priv, ECOBUS);
		__gen7_gt_force_wake_mt_put(dev_priv, FORCEWAKE_ALL);
		mutex_unlock(&dev->struct_mutex);

		if (ecobus & FORCEWAKE_MT_ENABLE) {
			dev_priv->uncore.funcs.force_wake_get =
				__gen7_gt_force_wake_mt_get;
			dev_priv->uncore.funcs.force_wake_put =
				__gen7_gt_force_wake_mt_put;
		} else {
			DRM_INFO("No MT forcewake available on Ivybridge, this can result in issues\n");
			DRM_INFO("when using vblank-synced partial screen updates.\n");
			dev_priv->uncore.funcs.force_wake_get =
				__gen6_gt_force_wake_get;
			dev_priv->uncore.funcs.force_wake_put =
				__gen6_gt_force_wake_put;
		}
	} else if (IS_GEN6(dev)) {
		dev_priv->uncore.funcs.force_wake_get =
			__gen6_gt_force_wake_get;
		dev_priv->uncore.funcs.force_wake_put =
			__gen6_gt_force_wake_put;
	}

	switch (INTEL_INFO(dev)->gen) {
	default:
		WARN_ON(1);
		return;
	case 9:
		ASSIGN_WRITE_MMIO_VFUNCS(gen9);
		ASSIGN_READ_MMIO_VFUNCS(gen9);
		break;
	case 8:
		if (IS_CHERRYVIEW(dev)) {
			ASSIGN_WRITE_MMIO_VFUNCS(chv);
			ASSIGN_READ_MMIO_VFUNCS(chv);

		} else {
			ASSIGN_WRITE_MMIO_VFUNCS(gen8);
			ASSIGN_READ_MMIO_VFUNCS(gen6);
		}
		break;
	case 7:
	case 6:
		if (IS_HASWELL(dev)) {
			ASSIGN_WRITE_MMIO_VFUNCS(hsw);
		} else {
			ASSIGN_WRITE_MMIO_VFUNCS(gen6);
		}

		if (IS_VALLEYVIEW(dev)) {
			ASSIGN_READ_MMIO_VFUNCS(vlv);
		} else {
			ASSIGN_READ_MMIO_VFUNCS(gen6);
		}
		break;
	case 5:
		ASSIGN_WRITE_MMIO_VFUNCS(gen5);
		ASSIGN_READ_MMIO_VFUNCS(gen5);
		break;
	case 4:
	case 3:
	case 2:
		ASSIGN_WRITE_MMIO_VFUNCS(gen4);
		ASSIGN_READ_MMIO_VFUNCS(gen4);
		break;
	}

	i915_check_and_clear_faults(dev);
}
示例#16
0
static int __devinit fnic_probe(struct pci_dev *pdev,
				const struct pci_device_id *ent)
{
	struct Scsi_Host *host;
	struct fc_lport *lp;
	struct fnic *fnic;
	mempool_t *pool;
	int err;
	int i;
	unsigned long flags;

	/*
	 * Allocate SCSI Host and set up association between host,
	 * local port, and fnic
	 */
	lp = libfc_host_alloc(&fnic_host_template, sizeof(struct fnic));
	if (!lp) {
;
		err = -ENOMEM;
		goto err_out;
	}
	host = lp->host;
	fnic = lport_priv(lp);
	fnic->lport = lp;
	fnic->ctlr.lp = lp;

	snprintf(fnic->name, sizeof(fnic->name) - 1, "%s%d", DRV_NAME,
		 host->host_no);

	host->transportt = fnic_fc_transport;

	err = scsi_init_shared_tag_map(host, FNIC_MAX_IO_REQ);
	if (err) {
//		shost_printk(KERN_ERR, fnic->lport->host,
;
		goto err_out_free_hba;
	}

	/* Setup PCI resources */
	pci_set_drvdata(pdev, fnic);

	fnic->pdev = pdev;

	err = pci_enable_device(pdev);
	if (err) {
//		shost_printk(KERN_ERR, fnic->lport->host,
;
		goto err_out_free_hba;
	}

	err = pci_request_regions(pdev, DRV_NAME);
	if (err) {
//		shost_printk(KERN_ERR, fnic->lport->host,
;
		goto err_out_disable_device;
	}

	pci_set_master(pdev);

	/* Query PCI controller on system for DMA addressing
	 * limitation for the device.  Try 40-bit first, and
	 * fail to 32-bit.
	 */
	err = pci_set_dma_mask(pdev, DMA_BIT_MASK(40));
	if (err) {
		err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
		if (err) {
//			shost_printk(KERN_ERR, fnic->lport->host,
//				     "No usable DMA configuration "
;
			goto err_out_release_regions;
		}
		err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
		if (err) {
//			shost_printk(KERN_ERR, fnic->lport->host,
//				     "Unable to obtain 32-bit DMA "
;
			goto err_out_release_regions;
		}
	} else {
		err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(40));
		if (err) {
//			shost_printk(KERN_ERR, fnic->lport->host,
//				     "Unable to obtain 40-bit DMA "
;
			goto err_out_release_regions;
		}
	}

	/* Map vNIC resources from BAR0 */
	if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
//		shost_printk(KERN_ERR, fnic->lport->host,
;
		err = -ENODEV;
		goto err_out_release_regions;
	}

	fnic->bar0.vaddr = pci_iomap(pdev, 0, 0);
	fnic->bar0.bus_addr = pci_resource_start(pdev, 0);
	fnic->bar0.len = pci_resource_len(pdev, 0);

	if (!fnic->bar0.vaddr) {
//		shost_printk(KERN_ERR, fnic->lport->host,
//			     "Cannot memory-map BAR0 res hdr, "
;
		err = -ENODEV;
		goto err_out_release_regions;
	}

	fnic->vdev = vnic_dev_register(NULL, fnic, pdev, &fnic->bar0);
	if (!fnic->vdev) {
//		shost_printk(KERN_ERR, fnic->lport->host,
//			     "vNIC registration failed, "
;
		err = -ENODEV;
		goto err_out_iounmap;
	}

	err = fnic_dev_wait(fnic->vdev, vnic_dev_open,
			    vnic_dev_open_done, 0);
	if (err) {
//		shost_printk(KERN_ERR, fnic->lport->host,
;
		goto err_out_vnic_unregister;
	}

	err = vnic_dev_init(fnic->vdev, 0);
	if (err) {
//		shost_printk(KERN_ERR, fnic->lport->host,
;
		goto err_out_dev_close;
	}

	err = vnic_dev_mac_addr(fnic->vdev, fnic->ctlr.ctl_src_addr);
	if (err) {
//		shost_printk(KERN_ERR, fnic->lport->host,
;
		goto err_out_dev_close;
	}
	/* set data_src for point-to-point mode and to keep it non-zero */
	memcpy(fnic->data_src_addr, fnic->ctlr.ctl_src_addr, ETH_ALEN);

	/* Get vNIC configuration */
	err = fnic_get_vnic_config(fnic);
	if (err) {
//		shost_printk(KERN_ERR, fnic->lport->host,
//			     "Get vNIC configuration failed, "
;
		goto err_out_dev_close;
	}
	host->max_lun = fnic->config.luns_per_tgt;
	host->max_id = FNIC_MAX_FCP_TARGET;
	host->max_cmd_len = FCOE_MAX_CMD_LEN;

	fnic_get_res_counts(fnic);

	err = fnic_set_intr_mode(fnic);
	if (err) {
//		shost_printk(KERN_ERR, fnic->lport->host,
//			     "Failed to set intr mode, "
;
		goto err_out_dev_close;
	}

	err = fnic_alloc_vnic_resources(fnic);
	if (err) {
//		shost_printk(KERN_ERR, fnic->lport->host,
//			     "Failed to alloc vNIC resources, "
;
		goto err_out_clear_intr;
	}


	/* initialize all fnic locks */
	spin_lock_init(&fnic->fnic_lock);

	for (i = 0; i < FNIC_WQ_MAX; i++)
		spin_lock_init(&fnic->wq_lock[i]);

	for (i = 0; i < FNIC_WQ_COPY_MAX; i++) {
		spin_lock_init(&fnic->wq_copy_lock[i]);
		fnic->wq_copy_desc_low[i] = DESC_CLEAN_LOW_WATERMARK;
		fnic->fw_ack_recd[i] = 0;
		fnic->fw_ack_index[i] = -1;
	}

	for (i = 0; i < FNIC_IO_LOCKS; i++)
		spin_lock_init(&fnic->io_req_lock[i]);

	fnic->io_req_pool = mempool_create_slab_pool(2, fnic_io_req_cache);
	if (!fnic->io_req_pool)
		goto err_out_free_resources;

	pool = mempool_create(2, fnic_alloc_slab_dma, mempool_free_slab,
			      fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]);
	if (!pool)
		goto err_out_free_ioreq_pool;
	fnic->io_sgl_pool[FNIC_SGL_CACHE_DFLT] = pool;

	pool = mempool_create(2, fnic_alloc_slab_dma, mempool_free_slab,
			      fnic_sgl_cache[FNIC_SGL_CACHE_MAX]);
	if (!pool)
		goto err_out_free_dflt_pool;
	fnic->io_sgl_pool[FNIC_SGL_CACHE_MAX] = pool;

	/* setup vlan config, hw inserts vlan header */
	fnic->vlan_hw_insert = 1;
	fnic->vlan_id = 0;

	/* Initialize the FIP fcoe_ctrl struct */
	fnic->ctlr.send = fnic_eth_send;
	fnic->ctlr.update_mac = fnic_update_mac;
	fnic->ctlr.get_src_addr = fnic_get_mac;
	if (fnic->config.flags & VFCF_FIP_CAPABLE) {
//		shost_printk(KERN_INFO, fnic->lport->host,
;
		/* enable directed and multicast */
		vnic_dev_packet_filter(fnic->vdev, 1, 1, 0, 0, 0);
		vnic_dev_add_addr(fnic->vdev, FIP_ALL_ENODE_MACS);
		vnic_dev_add_addr(fnic->vdev, fnic->ctlr.ctl_src_addr);
		fcoe_ctlr_init(&fnic->ctlr, FIP_MODE_AUTO);
	} else {
//		shost_printk(KERN_INFO, fnic->lport->host,
;
		fcoe_ctlr_init(&fnic->ctlr, FIP_MODE_NON_FIP);
	}
	fnic->state = FNIC_IN_FC_MODE;

	/* Enable hardware stripping of vlan header on ingress */
	fnic_set_nic_config(fnic, 0, 0, 0, 0, 0, 0, 1);

	/* Setup notification buffer area */
	err = fnic_notify_set(fnic);
	if (err) {
//		shost_printk(KERN_ERR, fnic->lport->host,
;
		goto err_out_free_max_pool;
	}

	/* Setup notify timer when using MSI interrupts */
	if (vnic_dev_get_intr_mode(fnic->vdev) == VNIC_DEV_INTR_MODE_MSI)
		setup_timer(&fnic->notify_timer,
			    fnic_notify_timer, (unsigned long)fnic);

	/* allocate RQ buffers and post them to RQ*/
	for (i = 0; i < fnic->rq_count; i++) {
		err = vnic_rq_fill(&fnic->rq[i], fnic_alloc_rq_frame);
		if (err) {
//			shost_printk(KERN_ERR, fnic->lport->host,
//				     "fnic_alloc_rq_frame can't alloc "
;
			goto err_out_free_rq_buf;
		}
	}

	/*
	 * Initialization done with PCI system, hardware, firmware.
	 * Add host to SCSI
	 */
	err = scsi_add_host(lp->host, &pdev->dev);
	if (err) {
//		shost_printk(KERN_ERR, fnic->lport->host,
;
		goto err_out_free_rq_buf;
	}

	/* Start local port initiatialization */

	lp->link_up = 0;

	lp->max_retry_count = fnic->config.flogi_retries;
	lp->max_rport_retry_count = fnic->config.plogi_retries;
	lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
			      FCP_SPPF_CONF_COMPL);
	if (fnic->config.flags & VFCF_FCP_SEQ_LVL_ERR)
		lp->service_params |= FCP_SPPF_RETRY;

	lp->boot_time = jiffies;
	lp->e_d_tov = fnic->config.ed_tov;
	lp->r_a_tov = fnic->config.ra_tov;
	lp->link_supported_speeds = FC_PORTSPEED_10GBIT;
	fc_set_wwnn(lp, fnic->config.node_wwn);
	fc_set_wwpn(lp, fnic->config.port_wwn);

	fcoe_libfc_config(lp, &fnic->ctlr, &fnic_transport_template, 0);

	if (!fc_exch_mgr_alloc(lp, FC_CLASS_3, FCPIO_HOST_EXCH_RANGE_START,
			       FCPIO_HOST_EXCH_RANGE_END, NULL)) {
		err = -ENOMEM;
		goto err_out_remove_scsi_host;
	}

	fc_lport_init_stats(lp);

	fc_lport_config(lp);

	if (fc_set_mfs(lp, fnic->config.maxdatafieldsize +
		       sizeof(struct fc_frame_header))) {
		err = -EINVAL;
		goto err_out_free_exch_mgr;
	}
	fc_host_maxframe_size(lp->host) = lp->mfs;
	fc_host_dev_loss_tmo(lp->host) = fnic->config.port_down_timeout / 1000;

	sprintf(fc_host_symbolic_name(lp->host),
		DRV_NAME " v" DRV_VERSION " over %s", fnic->name);

	spin_lock_irqsave(&fnic_list_lock, flags);
	list_add_tail(&fnic->list, &fnic_list);
	spin_unlock_irqrestore(&fnic_list_lock, flags);

	INIT_WORK(&fnic->link_work, fnic_handle_link);
	INIT_WORK(&fnic->frame_work, fnic_handle_frame);
	skb_queue_head_init(&fnic->frame_queue);
	skb_queue_head_init(&fnic->tx_queue);

	/* Enable all queues */
	for (i = 0; i < fnic->raw_wq_count; i++)
		vnic_wq_enable(&fnic->wq[i]);
	for (i = 0; i < fnic->rq_count; i++)
		vnic_rq_enable(&fnic->rq[i]);
	for (i = 0; i < fnic->wq_copy_count; i++)
		vnic_wq_copy_enable(&fnic->wq_copy[i]);

	fc_fabric_login(lp);

	vnic_dev_enable(fnic->vdev);

	err = fnic_request_intr(fnic);
	if (err) {
//		shost_printk(KERN_ERR, fnic->lport->host,
;
		goto err_out_free_exch_mgr;
	}

	for (i = 0; i < fnic->intr_count; i++)
		vnic_intr_unmask(&fnic->intr[i]);

	fnic_notify_timer_start(fnic);

	return 0;

err_out_free_exch_mgr:
	fc_exch_mgr_free(lp);
err_out_remove_scsi_host:
	fc_remove_host(lp->host);
	scsi_remove_host(lp->host);
err_out_free_rq_buf:
	for (i = 0; i < fnic->rq_count; i++)
		vnic_rq_clean(&fnic->rq[i], fnic_free_rq_buf);
	vnic_dev_notify_unset(fnic->vdev);
err_out_free_max_pool:
	mempool_destroy(fnic->io_sgl_pool[FNIC_SGL_CACHE_MAX]);
err_out_free_dflt_pool:
	mempool_destroy(fnic->io_sgl_pool[FNIC_SGL_CACHE_DFLT]);
err_out_free_ioreq_pool:
	mempool_destroy(fnic->io_req_pool);
err_out_free_resources:
	fnic_free_vnic_resources(fnic);
err_out_clear_intr:
	fnic_clear_intr_mode(fnic);
err_out_dev_close:
	vnic_dev_close(fnic->vdev);
err_out_vnic_unregister:
	vnic_dev_unregister(fnic->vdev);
err_out_iounmap:
	fnic_iounmap(fnic);
err_out_release_regions:
	pci_release_regions(pdev);
err_out_disable_device:
	pci_disable_device(pdev);
err_out_free_hba:
	scsi_host_put(lp->host);
err_out:
	return err;
}
示例#17
0
/**
 * __ir_input_register() - sets the IR keycode table and add the handlers
 *			    for keymap table get/set
 * @input_dev:	the struct input_dev descriptor of the device
 * @rc_tab:	the struct ir_scancode_table table of scancode/keymap
 *
 * This routine is used to initialize the input infrastructure
 * to work with an IR.
 * It will register the input/evdev interface for the device and
 * register the syfs code for IR class
 */
int __ir_input_register(struct input_dev *input_dev,
		      const struct ir_scancode_table *rc_tab,
		      const struct ir_dev_props *props,
		      const char *driver_name)
{
	struct ir_input_dev *ir_dev;
	int rc;

	if (rc_tab->scan == NULL || !rc_tab->size)
		return -EINVAL;

	ir_dev = kzalloc(sizeof(*ir_dev), GFP_KERNEL);
	if (!ir_dev)
		return -ENOMEM;

	ir_dev->driver_name = kasprintf(GFP_KERNEL, "%s", driver_name);
	if (!ir_dev->driver_name) {
		rc = -ENOMEM;
		goto out_dev;
	}

	input_dev->getkeycode = ir_getkeycode;
	input_dev->setkeycode = ir_setkeycode;
	input_set_drvdata(input_dev, ir_dev);
	ir_dev->input_dev = input_dev;

	spin_lock_init(&ir_dev->rc_tab.lock);
	spin_lock_init(&ir_dev->keylock);
	setup_timer(&ir_dev->timer_keyup, ir_timer_keyup, (unsigned long)ir_dev);

	ir_dev->rc_tab.name = rc_tab->name;
	ir_dev->rc_tab.ir_type = rc_tab->ir_type;
	ir_dev->rc_tab.alloc = roundup_pow_of_two(rc_tab->size *
						  sizeof(struct ir_scancode));
	ir_dev->rc_tab.scan = kmalloc(ir_dev->rc_tab.alloc, GFP_KERNEL);
	ir_dev->rc_tab.size = ir_dev->rc_tab.alloc / sizeof(struct ir_scancode);
	if (props) {
		ir_dev->props = props;
		if (props->open)
			input_dev->open = ir_open;
		if (props->close)
			input_dev->close = ir_close;
	}

	if (!ir_dev->rc_tab.scan) {
		rc = -ENOMEM;
		goto out_name;
	}

	IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n",
		   ir_dev->rc_tab.size, ir_dev->rc_tab.alloc);

	set_bit(EV_KEY, input_dev->evbit);
	set_bit(EV_REP, input_dev->evbit);

	if (ir_setkeytable(input_dev, &ir_dev->rc_tab, rc_tab)) {
		rc = -ENOMEM;
		goto out_table;
	}

	rc = ir_register_class(input_dev);
	if (rc < 0)
		goto out_table;

	if (ir_dev->props)
		if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW) {
			rc = ir_raw_event_register(input_dev);
			if (rc < 0)
				goto out_event;
		}

	IR_dprintk(1, "Registered input device on %s for %s remote.\n",
		   driver_name, rc_tab->name);

	return 0;

out_event:
	ir_unregister_class(input_dev);
out_table:
	kfree(ir_dev->rc_tab.scan);
out_name:
	kfree(ir_dev->driver_name);
out_dev:
	kfree(ir_dev);
	return rc;
}
static int davinci_musb_init(struct musb *musb)
{
	void __iomem	*tibase = musb->ctrl_base;
	u32		revision;

	usb_nop_xceiv_register();
	musb->xceiv = usb_get_transceiver();
	if (!musb->xceiv)
		goto unregister;

	musb->mregs += DAVINCI_BASE_OFFSET;

	
	revision = musb_readl(tibase, DAVINCI_USB_VERSION_REG);
	if (revision == 0)
		goto fail;

	if (is_host_enabled(musb))
		setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);

	davinci_musb_source_power(musb, 0, 1);

	if (machine_is_davinci_dm355_evm()) {
		u32	phy_ctrl = __raw_readl(USB_PHY_CTRL);

		phy_ctrl &= ~(3 << 9);
		phy_ctrl |= USBPHY_DATAPOL;
		__raw_writel(phy_ctrl, USB_PHY_CTRL);
	}

	if (cpu_is_davinci_dm355()) {
		u32	deepsleep = __raw_readl(DM355_DEEPSLEEP);

		if (is_host_enabled(musb)) {
			deepsleep &= ~DRVVBUS_OVERRIDE;
		} else {
			deepsleep &= ~DRVVBUS_FORCE;
			deepsleep |= DRVVBUS_OVERRIDE;
		}
		__raw_writel(deepsleep, DM355_DEEPSLEEP);
	}

	
	musb_writel(tibase, DAVINCI_USB_CTRL_REG, 0x1);

	
	phy_on();

	msleep(5);

	
	pr_debug("DaVinci OTG revision %08x phy %03x control %02x\n",
		revision, __raw_readl(USB_PHY_CTRL),
		musb_readb(tibase, DAVINCI_USB_CTRL_REG));

	musb->isr = davinci_musb_interrupt;
	return 0;

fail:
	usb_put_transceiver(musb->xceiv);
unregister:
	usb_nop_xceiv_unregister();
	return -ENODEV;
}
示例#19
0
static int tegra_battery_probe(struct platform_device *pdev)
{
	int i, rc;
	NvBool result;

	batt_dev = kzalloc(sizeof(*batt_dev), GFP_KERNEL);
	if (!batt_dev) {
		return -ENOMEM;
	}
	memset(batt_dev, 0, sizeof(*batt_dev));

	/* Assume battery is present at start */
	batt_dev->present = 1;
	batt_dev->batt_id = 0;
	batt_dev->charging_source = NvCharger_Type_AC;
	batt_dev->charging_enabled = NvCharge_Control_Charging_Enable;
#if defined (CONFIG_MODEM_MDM)

	result = NvOdmBatteryDeviceOpen(&(batt_dev->hOdmBattDev), NULL);
	if (!result) {
		pr_err("NvOdmBatteryDeviceOpen FAILED\n");
		goto err;
	}
#endif

	for (i = 0; i < ARRAY_SIZE(tegra_supplies); i++) {
		rc = power_supply_register(&pdev->dev, &tegra_supplies[i]);
		if (rc) {
			printk(KERN_ERR "Failed to register power supply\n");
			while (i--)
				power_supply_unregister(&tegra_supplies[i]);
			kfree(batt_dev);
			return rc;
		}
	}
	printk(KERN_INFO "%s: battery driver registered\n", pdev->name);

	batt_dev->batt_status_poll_period = NVBATTERY_POLLING_INTERVAL;
	setup_timer(&(batt_dev->battery_poll_timer), tegra_battery_poll_timer_func, 0);
	mod_timer(&(batt_dev->battery_poll_timer),
		jiffies + msecs_to_jiffies(batt_dev->batt_status_poll_period));

	rc = device_create_file(&pdev->dev, &tegra_battery_attr);
	if (rc) {
		for (i = 0; i < ARRAY_SIZE(tegra_supplies); i++) {
			power_supply_unregister(&tegra_supplies[i]);
		}

		del_timer_sync(&(batt_dev->battery_poll_timer));

		pr_err("tegra_battery_probe:device_create_file FAILED");
		return rc;
	}

	return 0;
err:
	if (batt_dev) {
		kfree(batt_dev);
		batt_dev = NULL;
	}
	return -1;
}
示例#20
0
文件: sw.c 项目: elvismt/rtlwifi_new
int rtl88e_init_sw_vars(struct ieee80211_hw *hw)
{
	int err = 0;
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	u8 tid;
	char *fw_name;

	rtl8188ee_bt_reg_init(hw);
	rtlpriv->dm.dm_initialgain_enable = 1;
	rtlpriv->dm.dm_flag = 0;
	rtlpriv->dm.disable_framebursting = 0;
	rtlpriv->dm.thermalvalue = 0;
	rtlpci->transmit_config = CFENDFORM | BIT(15);

	/* compatible 5G band 88ce just 2.4G band & smsp */
	rtlpriv->rtlhal.current_bandtype = BAND_ON_2_4G;
	rtlpriv->rtlhal.bandset = BAND_ON_2_4G;
	rtlpriv->rtlhal.macphymode = SINGLEMAC_SINGLEPHY;

	rtlpci->receive_config = (RCR_APPFCS |
				  RCR_APP_MIC |
				  RCR_APP_ICV |
				  RCR_APP_PHYST_RXFF |
				  RCR_HTC_LOC_CTRL |
				  RCR_AMF |
				  RCR_ACF |
				  RCR_ADF |
				  RCR_AICV |
				  RCR_ACRC32 |
				  RCR_AB |
				  RCR_AM |
				  RCR_APM |
				  0);

	rtlpci->irq_mask[0] =
				(u32)(IMR_PSTIMEOUT	|
				IMR_HSISR_IND_ON_INT	|
				IMR_C2HCMD		|
				IMR_HIGHDOK		|
				IMR_MGNTDOK		|
				IMR_BKDOK		|
				IMR_BEDOK		|
				IMR_VIDOK		|
				IMR_VODOK		|
				IMR_RDU			|
				IMR_ROK			|
				0);
	rtlpci->irq_mask[1] = (u32) (IMR_RXFOVW | 0);
	rtlpci->sys_irq_mask = (u32) (HSIMR_PDN_INT_EN | HSIMR_RON_INT_EN);

	/* for debug level */
	rtlpriv->dbg.global_debuglevel = rtlpriv->cfg->mod_params->debug;
	/* for LPS & IPS */
	rtlpriv->psc.inactiveps = rtlpriv->cfg->mod_params->inactiveps;
	rtlpriv->psc.swctrl_lps = rtlpriv->cfg->mod_params->swctrl_lps;
	rtlpriv->psc.fwctrl_lps = rtlpriv->cfg->mod_params->fwctrl_lps;
	rtlpci->msi_support = rtlpriv->cfg->mod_params->msi_support;
	rtlpriv->cfg->mod_params->sw_crypto =
		rtlpriv->cfg->mod_params->sw_crypto;
	rtlpriv->cfg->mod_params->disable_watchdog =
		rtlpriv->cfg->mod_params->disable_watchdog;
	if (rtlpriv->cfg->mod_params->disable_watchdog)
		pr_info("watchdog disabled\n");
	if (!rtlpriv->psc.inactiveps)
		pr_info("rtl8188ee: Power Save off (module option)\n");
	if (!rtlpriv->psc.fwctrl_lps)
		pr_info("rtl8188ee: FW Power Save off (module option)\n");
	rtlpriv->psc.reg_fwctrl_lps = 3;
	rtlpriv->psc.reg_max_lps_awakeintvl = 5;
	/* for ASPM, you can close aspm through
	 * set const_support_pciaspm = 0
	 */
	rtl88e_init_aspm_vars(hw);

	if (rtlpriv->psc.reg_fwctrl_lps == 1)
		rtlpriv->psc.fwctrl_psmode = FW_PS_MIN_MODE;
	else if (rtlpriv->psc.reg_fwctrl_lps == 2)
		rtlpriv->psc.fwctrl_psmode = FW_PS_MAX_MODE;
	else if (rtlpriv->psc.reg_fwctrl_lps == 3)
		rtlpriv->psc.fwctrl_psmode = FW_PS_DTIM_MODE;

	/* for firmware buf */
	rtlpriv->rtlhal.pfirmware = vzalloc(0x8000);
	if (!rtlpriv->rtlhal.pfirmware) {
		pr_info("Can't alloc buffer for fw.\n");
		return 1;
	}

	fw_name = "rtlwifi/rtl8188efw.bin";
	rtlpriv->max_fw_size = 0x8000;
	pr_info("Using firmware %s\n", fw_name);
	err = request_firmware_nowait(THIS_MODULE, 1, fw_name,
				      rtlpriv->io.dev, GFP_KERNEL, hw,
				      rtl_fw_cb);
	if (err) {
		pr_info("Failed to request firmware!\n");
		return 1;
	}

	/* for early mode */
	rtlpriv->rtlhal.earlymode_enable = false;
	rtlpriv->rtlhal.max_earlymode_num = 10;
	for (tid = 0; tid < 8; tid++)
		skb_queue_head_init(&rtlpriv->mac80211.skb_waitq[tid]);

	/*low power */
	rtlpriv->psc.low_power_enable = false;
	if (rtlpriv->psc.low_power_enable) {
		init_timer(&rtlpriv->works.fw_clockoff_timer);
		setup_timer(&rtlpriv->works.fw_clockoff_timer,
			    rtl88ee_fw_clk_off_timer_callback,
			    (unsigned long)hw);
	}

	init_timer(&rtlpriv->works.fast_antenna_training_timer);
	setup_timer(&rtlpriv->works.fast_antenna_training_timer,
		    rtl88e_dm_fast_antenna_training_callback,
			(unsigned long)hw);
	return err;
}
示例#21
0
static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt)
{
	u32 tmp;
	u32 delta;
	u32 value;
	int err;
	u32 mask = wdt->mr_mask;
	unsigned long min_heartbeat = 1;
	unsigned long max_heartbeat;
	struct device *dev = &pdev->dev;

	tmp = wdt_read(wdt, AT91_WDT_MR);
	if ((tmp & mask) != (wdt->mr & mask)) {
		if (tmp == WDT_MR_RESET) {
			wdt_write(wdt, AT91_WDT_MR, wdt->mr);
			tmp = wdt_read(wdt, AT91_WDT_MR);
		}
	}

	if (tmp & AT91_WDT_WDDIS) {
		if (wdt->mr & AT91_WDT_WDDIS)
			return 0;
		dev_err(dev, "watchdog is disabled\n");
		return -EINVAL;
	}

	value = tmp & AT91_WDT_WDV;
	delta = (tmp & AT91_WDT_WDD) >> 16;

	if (delta < value)
		min_heartbeat = ticks_to_hz_roundup(value - delta);

	max_heartbeat = ticks_to_hz_rounddown(value);
	if (!max_heartbeat) {
		dev_err(dev,
			"heartbeat is too small for the system to handle it correctly\n");
		return -EINVAL;
	}

	/*
	 * Try to reset the watchdog counter 4 or 2 times more often than
	 * actually requested, to avoid spurious watchdog reset.
	 * If this is not possible because of the min_heartbeat value, reset
	 * it at the min_heartbeat period.
	 */
	if ((max_heartbeat / 4) >= min_heartbeat)
		wdt->heartbeat = max_heartbeat / 4;
	else if ((max_heartbeat / 2) >= min_heartbeat)
		wdt->heartbeat = max_heartbeat / 2;
	else
		wdt->heartbeat = min_heartbeat;

	if (max_heartbeat < min_heartbeat + 4)
		dev_warn(dev,
			 "min heartbeat and max heartbeat might be too close for the system to handle it correctly\n");

	if ((tmp & AT91_WDT_WDFIEN) && wdt->irq) {
		err = request_irq(wdt->irq, wdt_interrupt,
				  IRQF_SHARED | IRQF_IRQPOLL |
				  IRQF_NO_SUSPEND,
				  pdev->name, wdt);
		if (err)
			return err;
	}

	if ((tmp & wdt->mr_mask) != (wdt->mr & wdt->mr_mask))
		dev_warn(dev,
			 "watchdog already configured differently (mr = %x expecting %x)\n",
			 tmp & wdt->mr_mask, wdt->mr & wdt->mr_mask);

	setup_timer(&wdt->timer, at91_ping, (unsigned long)wdt);

	/*
	 * Use min_heartbeat the first time to avoid spurious watchdog reset:
	 * we don't know for how long the watchdog counter is running, and
	 *  - resetting it right now might trigger a watchdog fault reset
	 *  - waiting for heartbeat time might lead to a watchdog timeout
	 *    reset
	 */
	mod_timer(&wdt->timer, jiffies + min_heartbeat);

	/* Try to set timeout from device tree first */
	if (watchdog_init_timeout(&wdt->wdd, 0, dev))
		watchdog_init_timeout(&wdt->wdd, heartbeat, dev);
	watchdog_set_nowayout(&wdt->wdd, wdt->nowayout);
	err = watchdog_register_device(&wdt->wdd);
	if (err)
		goto out_stop_timer;

	wdt->next_heartbeat = jiffies + wdt->wdd.timeout * HZ;

	return 0;

out_stop_timer:
	del_timer(&wdt->timer);
	return err;
}
示例#22
0
static int __devinit gpio_keys_probe(struct platform_device *pdev)
{
	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
	struct input_dev *input;
	int i, error;
	int wakeup = 0;

	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
			pdata->nbuttons * sizeof(struct gpio_button_data),
			GFP_KERNEL);
	input = input_allocate_device();
	if (!ddata || !input) {
		error = -ENOMEM;
		goto fail1;
	}

	platform_set_drvdata(pdev, ddata);

	input->name = pdev->name;
	input->phys = "gpio-keys/input0";
	input->dev.parent = &pdev->dev;

	input->id.bustype = BUS_HOST;
	input->id.vendor = 0x0001;
	input->id.product = 0x0001;
	input->id.version = 0x0100;

	ddata->input = input;

	for (i = 0; i < pdata->nbuttons; i++) {
		struct gpio_keys_button *button = &pdata->buttons[i];
		struct gpio_button_data *bdata = &ddata->data[i];
		int irq;
		unsigned int type = button->type ?: EV_KEY;

		bdata->input = input;
		bdata->button = button;
		setup_timer(&bdata->timer,gpio_check_button, (unsigned long)bdata);

		error = gpio_request(button->gpio, button->desc ?: "gpio_keys");
		if (error < 0) {
			pr_err("gpio-keys: failed to request GPIO %d,"
				" error %d\n", button->gpio, error);
			goto fail2;
		}

		error = gpio_direction_input(button->gpio);
		if (error < 0) {
			pr_err("gpio-keys: failed to configure input"
				" direction for GPIO %d, error %d\n",
				button->gpio, error);
			gpio_free(button->gpio);
			goto fail2;
		}

		s3c_gpio_setpull(button->gpio, S3C_GPIO_PULL_NONE);
		button->last_state = gpio_get_value(button->gpio);
		
		irq = gpio_to_irq(button->gpio);
		if (irq < 0) {
			error = irq;
			pr_err("gpio-keys: Unable to get irq number"
				" for GPIO %d, error %d\n",
				button->gpio, error);
			gpio_free(button->gpio);
			goto fail2;
		}

		error = request_irq(irq, gpio_keys_isr,IRQF_SAMPLE_RANDOM | 
			IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING,
			button->desc ? button->desc : "gpio_keys",bdata);
		if (error) {
			pr_err("gpio-keys: Unable to claim irq %d; error %d\n",
				irq, error);
			gpio_free(button->gpio);
			goto fail2;
		}
		
		if (button->wakeup)
		{
			wakeup = 1;
		}

		input_set_capability(input, type, button->code);
	}

	add_fake_keys_capability(input);

	error = input_register_device(input);
	if (error) {
		pr_err("gpio-keys: Unable to register input device, "
			"error: %d\n", error);
		goto fail2;
	}

	device_init_wakeup(&pdev->dev, wakeup);

	return 0;

 fail2:
	while (--i >= 0) {
		free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
		if (pdata->buttons[i].debounce_interval)
			del_timer_sync(&ddata->data[i].timer);
		gpio_free(pdata->buttons[i].gpio);
	}

	platform_set_drvdata(pdev, NULL);
 fail1:
	input_free_device(input);
	kfree(ddata);

	return error;
}
示例#23
0
static int dsps_musb_init(struct musb *musb)
{
	struct device *dev = musb->controller;
	struct platform_device *pdev = to_platform_device(dev);
	struct dsps_glue *glue = dev_get_drvdata(dev->parent);
	const struct dsps_musb_wrapper *wrp = glue->wrp;
	void __iomem *reg_base = musb->ctrl_base;
	u32 rev, val;
	int status;

	/* mentor core register starts at offset of 0x400 from musb base */
	musb->mregs += wrp->musb_core_offset;

#if 1
	/* NOP driver needs change if supporting dual instance */
	if(!pdev->id) {
		usb_nop_xceiv_register();
	}
	musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
#else
	/* Get the NOP PHY */
	sprintf(name, "usb%d-phy", pdev->id);
	musb->xceiv = devm_usb_get_phy_by_phandle(&parent_pdev->dev, name);
#endif
	if (IS_ERR_OR_NULL(musb->xceiv)) {
		dev_err(dev, "%s:%d %s: FAIL\n", __FILE__, __LINE__, __func__);
		return -EPROBE_DEFER;
	}

	/* Returns zero if e.g. not clocked */
	rev = dsps_readl(reg_base, wrp->revision);
	if (!rev) {
		dev_err(dev, "%s:%d %s: FAIL\n", __FILE__, __LINE__, __func__);
		status = -ENODEV;
		goto err0;
	}

	dev_info(dev, "pdev->id = %d\n", pdev->id);

	setup_timer(&glue->timer[pdev->id], otg_timer, (unsigned long) musb);

	/* Reset the musb */
	dsps_writel(reg_base, wrp->control, (1 << wrp->reset));

	/* Start the on-chip PHY and its PLL. */
	musb_dsps_phy_control(glue, pdev->id, 1);

	musb->isr = dsps_interrupt;

	/* reset the otgdisable bit, needed for host mode to work */
	val = dsps_readl(reg_base, wrp->phy_utmi);
	val &= ~(1 << wrp->otg_disable);
	dsps_writel(musb->ctrl_base, wrp->phy_utmi, val);

	/* clear level interrupt */
	dsps_writel(reg_base, wrp->eoi, 0);

	dev_info(dev, "%s:%d %s: OK\n", __FILE__, __LINE__, __func__);

	return 0;
err0:
	usb_put_phy(musb->xceiv);
	if(!pdev->id) {
		usb_nop_xceiv_unregister();
	}
	return status;
}
示例#24
0
static int gpio_keys_setup_key(struct platform_device *pdev,
                               struct input_dev *input,
                               struct gpio_button_data *bdata,
                               const struct gpio_keys_button *button)
{
    const char *desc = button->desc ? button->desc : "gpio_keys";
    struct device *dev = &pdev->dev;
    irq_handler_t isr;
    unsigned long irqflags;
    int irq;
    int error;

    bdata->input = input;
    bdata->button = button;
    spin_lock_init(&bdata->lock);

    if (gpio_is_valid(button->gpio)) {

        error = devm_gpio_request_one(&pdev->dev, button->gpio,
                                      GPIOF_IN, desc);
        if (error < 0) {
            dev_err(dev, "Failed to request GPIO %d, error %d\n",
                    button->gpio, error);
            return error;
        }

        if (button->debounce_interval) {
            error = gpio_set_debounce(button->gpio,
                                      button->debounce_interval * 1000);
            /* use timer if gpiolib doesn't provide debounce */
            if (error < 0)
                bdata->software_debounce =
                    button->debounce_interval;
        }

        if (button->irq) {
            bdata->irq = button->irq;
        } else {
            irq = gpio_to_irq(button->gpio);
            if (irq < 0) {
                error = irq;
                dev_err(dev,
                        "Unable to get irq number for GPIO %d, error %d\n",
                        button->gpio, error);
                return error;
            }
            bdata->irq = irq;
        }

        INIT_DELAYED_WORK(&bdata->work, gpio_keys_gpio_work_func);

        isr = gpio_keys_gpio_isr;
        irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;

    } else {
        if (!button->irq) {
            dev_err(dev, "No IRQ specified\n");
            return -EINVAL;
        }
        bdata->irq = button->irq;

        if (button->type && button->type != EV_KEY) {
            dev_err(dev, "Only EV_KEY allowed for IRQ buttons.\n");
            return -EINVAL;
        }

        bdata->release_delay = button->debounce_interval;
        setup_timer(&bdata->release_timer,
                    gpio_keys_irq_timer, (unsigned long)bdata);

        isr = gpio_keys_irq_isr;
        irqflags = 0;
    }

    input_set_capability(input, button->type ?: EV_KEY, button->code);

    /*
     * Install custom action to cancel release timer and
     * workqueue item.
     */
    error = devm_add_action(&pdev->dev, gpio_keys_quiesce_key, bdata);
    if (error) {
        dev_err(&pdev->dev,
                "failed to register quiesce action, error: %d\n",
                error);
        return error;
    }

    /*
     * If platform has specified that the button can be disabled,
     * we don't want it to share the interrupt line.
     */
    if (!button->can_disable)
        irqflags |= IRQF_SHARED;

    error = devm_request_any_context_irq(&pdev->dev, bdata->irq,
                                         isr, irqflags, desc, bdata);
    if (error < 0) {
        dev_err(dev, "Unable to claim irq %d; error %d\n",
                bdata->irq, error);
        return error;
    }

    return 0;
}
示例#25
0
/*
 * Probe for the device
 */
static int __init at91_mci_probe(struct platform_device *pdev)
{
	struct mmc_host *mmc;
	struct at91mci_host *host;
	struct resource *res;
	int ret;

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!res)
		return -ENXIO;

	if (!request_mem_region(res->start, resource_size(res), DRIVER_NAME))
		return -EBUSY;

	mmc = mmc_alloc_host(sizeof(struct at91mci_host), &pdev->dev);
	if (!mmc) {
		ret = -ENOMEM;
		dev_dbg(&pdev->dev, "couldn't allocate mmc host\n");
		goto fail6;
	}

	mmc->ops = &at91_mci_ops;
	mmc->f_min = 375000;
	mmc->f_max = 25000000;
	mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
	mmc->caps = 0;

	mmc->max_blk_size  = MCI_MAXBLKSIZE;
	mmc->max_blk_count = MCI_BLKATONCE;
	mmc->max_req_size  = MCI_BUFSIZE;
	mmc->max_segs      = MCI_BLKATONCE;
	mmc->max_seg_size  = MCI_BUFSIZE;

	host = mmc_priv(mmc);
	host->mmc = mmc;
	host->bus_mode = 0;
	host->board = pdev->dev.platform_data;
	if (host->board->wire4) {
		if (at91mci_is_mci1rev2xx())
			mmc->caps |= MMC_CAP_4_BIT_DATA;
		else
			dev_warn(&pdev->dev, "4 wire bus mode not supported"
				" - using 1 wire\n");
	}

	host->buffer = dma_alloc_coherent(&pdev->dev, MCI_BUFSIZE,
					&host->physical_address, GFP_KERNEL);
	if (!host->buffer) {
		ret = -ENOMEM;
		dev_err(&pdev->dev, "Can't allocate transmit buffer\n");
		goto fail5;
	}

	/* Add SDIO capability when available */
	if (at91mci_is_mci1rev2xx()) {
		/* at91mci MCI1 rev2xx sdio interrupt erratum */
		if (host->board->wire4 || !host->board->slot_b)
			mmc->caps |= MMC_CAP_SDIO_IRQ;
	}

	/*
	 * Reserve GPIOs ... board init code makes sure these pins are set
	 * up as GPIOs with the right direction (input, except for vcc)
	 */
	if (host->board->det_pin) {
		ret = gpio_request(host->board->det_pin, "mmc_detect");
		if (ret < 0) {
			dev_dbg(&pdev->dev, "couldn't claim card detect pin\n");
			goto fail4b;
		}
	}
	if (host->board->wp_pin) {
		ret = gpio_request(host->board->wp_pin, "mmc_wp");
		if (ret < 0) {
			dev_dbg(&pdev->dev, "couldn't claim wp sense pin\n");
			goto fail4;
		}
	}
	if (host->board->vcc_pin) {
		ret = gpio_request(host->board->vcc_pin, "mmc_vcc");
		if (ret < 0) {
			dev_dbg(&pdev->dev, "couldn't claim vcc switch pin\n");
			goto fail3;
		}
	}

	/*
	 * Get Clock
	 */
	host->mci_clk = clk_get(&pdev->dev, "mci_clk");
	if (IS_ERR(host->mci_clk)) {
		ret = -ENODEV;
		dev_dbg(&pdev->dev, "no mci_clk?\n");
		goto fail2;
	}

	/*
	 * Map I/O region
	 */
	host->baseaddr = ioremap(res->start, resource_size(res));
	if (!host->baseaddr) {
		ret = -ENOMEM;
		goto fail1;
	}

	/*
	 * Reset hardware
	 */
	clk_enable(host->mci_clk);		/* Enable the peripheral clock */
	at91_mci_disable(host);
	at91_mci_enable(host);

	/*
	 * Allocate the MCI interrupt
	 */
	host->irq = platform_get_irq(pdev, 0);
	ret = request_irq(host->irq, at91_mci_irq, IRQF_SHARED,
			mmc_hostname(mmc), host);
	if (ret) {
		dev_dbg(&pdev->dev, "request MCI interrupt failed\n");
		goto fail0;
	}

	setup_timer(&host->timer, at91_timeout_timer, (unsigned long)host);

	platform_set_drvdata(pdev, mmc);

	/*
	 * Add host to MMC layer
	 */
	if (host->board->det_pin) {
		host->present = !gpio_get_value(host->board->det_pin);
	}
	else
		host->present = -1;

	mmc_add_host(mmc);

	/*
	 * monitor card insertion/removal if we can
	 */
	if (host->board->det_pin) {
		ret = request_irq(gpio_to_irq(host->board->det_pin),
				at91_mmc_det_irq, 0, mmc_hostname(mmc), host);
		if (ret)
			dev_warn(&pdev->dev, "request MMC detect irq failed\n");
		else
			device_init_wakeup(&pdev->dev, 1);
	}

	pr_debug("Added MCI driver\n");

	return 0;

fail0:
	clk_disable(host->mci_clk);
	iounmap(host->baseaddr);
fail1:
	clk_put(host->mci_clk);
fail2:
	if (host->board->vcc_pin)
		gpio_free(host->board->vcc_pin);
fail3:
	if (host->board->wp_pin)
		gpio_free(host->board->wp_pin);
fail4:
	if (host->board->det_pin)
		gpio_free(host->board->det_pin);
fail4b:
	if (host->buffer)
		dma_free_coherent(&pdev->dev, MCI_BUFSIZE,
				host->buffer, host->physical_address);
fail5:
	mmc_free_host(mmc);
fail6:
	release_mem_region(res->start, resource_size(res));
	dev_err(&pdev->dev, "probe failed, err %d\n", ret);
	return ret;
}
示例#26
0
文件: particles.cpp 项目: Scrik/godot
void Particles::set_emit_timeout(float p_timeout) {

	emit_timeout = p_timeout;
	setup_timer();
};
int __init musb_platform_init(struct musb *musb)
{
	u32 l;
	struct device *dev = musb->controller;
	struct musb_hdrc_platform_data *plat = dev->platform_data;
	struct omap_musb_board_data *data = plat->board_data;
	int status;
	u32 val;

	/* We require some kind of external transceiver, hooked
	 * up through ULPI.  TWL4030-family PMICs include one,
	 * which needs a driver, drivers aren't always needed.
	 */
	musb->xceiv = otg_get_transceiver();
	if (!musb->xceiv) {
		pr_err("HS USB OTG: no transceiver configured\n");
		return -ENODEV;
	}

	/* Fixme this can be enabled when load the gadget driver also*/
	musb_platform_resume(musb);

	/*powerup the phy as romcode would have put the phy in some state
	* which is impacting the core retention if the gadget driver is not
	* loaded.
	*/
	l = musb_readl(musb->mregs, OTG_INTERFSEL);

	if (data->interface_type == MUSB_INTERFACE_UTMI) {
		/* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
		l &= ~ULPI_12PIN;       /* Disable ULPI */
		l |= UTMI_8BIT;         /* Enable UTMI  */
	} else {
		l |= ULPI_12PIN;
	}

	musb_writel(musb->mregs, OTG_INTERFSEL, l);

	pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
			"sysstatus 0x%x, intrfsel 0x%x, simenable  0x%x\n",
			musb_readl(musb->mregs, OTG_REVISION),
			musb_readl(musb->mregs, OTG_SYSCONFIG),
			musb_readl(musb->mregs, OTG_SYSSTATUS),
			musb_readl(musb->mregs, OTG_INTERFSEL),
			musb_readl(musb->mregs, OTG_SIMENABLE));

	if (is_host_enabled(musb))
		musb->board_set_vbus = omap_set_vbus;

	setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
	plat->is_usb_active = is_musb_active;

	wake_lock_init(&plat->musb_lock, WAKE_LOCK_SUSPEND, "musb_wake_lock");
	if (cpu_is_omap44xx()) {
		phymux_base = ioremap(0x4A100000, SZ_1K);
		ctrl_base = ioremap(0x4A002000, SZ_1K);

		/* register for transciever notification*/
		status = otg_register_notifier(musb->xceiv, &musb->nb);

		if (status) {
			DBG(1, "notification register failed\n");
			wake_lock_destroy(&plat->musb_lock);
		}
		ctrl_base = ioremap(0x4A002000, SZ_1K);
		if (!ctrl_base) {
			dev_err(dev, "ioremap failed\n");
			return -ENOMEM;
		}
	}
	/* configure in force idle/ standby */
	musb_writel(musb->mregs, OTG_FORCESTDBY, 1);
	val = musb_readl(musb->mregs, OTG_SYSCONFIG);
	val &= ~(SMARTIDLEWKUP | NOSTDBY | ENABLEWAKEUP);
	val |= FORCEIDLE | FORCESTDBY;
	musb_writel(musb->mregs, OTG_SYSCONFIG,	val);
	return 0;
}
示例#28
0
static int dsps_musb_init(struct musb *musb)
{
    struct device *dev = musb->controller;
    struct dsps_glue *glue = dev_get_drvdata(dev->parent);
    struct platform_device *parent = to_platform_device(dev->parent);
    const struct dsps_musb_wrapper *wrp = glue->wrp;
    void __iomem *reg_base;
    struct resource *r;
    u32 rev, val;
    int ret;

    r = platform_get_resource_byname(parent, IORESOURCE_MEM, "control");
    if (!r)
        return -EINVAL;

    reg_base = devm_ioremap_resource(dev, r);
    if (IS_ERR(reg_base))
        return PTR_ERR(reg_base);
    musb->ctrl_base = reg_base;

    /* NOP driver needs change if supporting dual instance */
    musb->xceiv = devm_usb_get_phy_by_phandle(dev, "phys", 0);
    if (IS_ERR(musb->xceiv))
        return PTR_ERR(musb->xceiv);

    /* Returns zero if e.g. not clocked */
    rev = dsps_readl(reg_base, wrp->revision);
    if (!rev)
        return -ENODEV;

    usb_phy_init(musb->xceiv);
    setup_timer(&glue->timer, otg_timer, (unsigned long) musb);

    /* Reset the musb */
    dsps_writel(reg_base, wrp->control, (1 << wrp->reset));

    musb->isr = dsps_interrupt;

    /* reset the otgdisable bit, needed for host mode to work */
    val = dsps_readl(reg_base, wrp->phy_utmi);
    val &= ~(1 << wrp->otg_disable);
    dsps_writel(musb->ctrl_base, wrp->phy_utmi, val);

    /*
     *  Check whether the dsps version has babble control enabled.
     * In latest silicon revision the babble control logic is enabled.
     * If MUSB_BABBLE_CTL returns 0x4 then we have the babble control
     * logic enabled.
     */
    val = dsps_readb(musb->mregs, MUSB_BABBLE_CTL);
    if (val == MUSB_BABBLE_RCV_DISABLE) {
        glue->sw_babble_enabled = true;
        val |= MUSB_BABBLE_SW_SESSION_CTRL;
        dsps_writeb(musb->mregs, MUSB_BABBLE_CTL, val);
    }

    ret = dsps_musb_dbg_init(musb, glue);
    if (ret)
        return ret;

    return 0;
}
示例#29
-1
文件: omap.c 项目: vineetnayak/linux
static int __devinit mmc_omap_probe(struct platform_device *pdev)
{
	struct omap_mmc_platform_data *pdata = pdev->dev.platform_data;
	struct mmc_omap_host *host = NULL;
	struct resource *res;
	dma_cap_mask_t mask;
	unsigned sig;
	int i, ret = 0;
	int irq;

	if (pdata == NULL) {
		dev_err(&pdev->dev, "platform data missing\n");
		return -ENXIO;
	}
	if (pdata->nr_slots == 0) {
		dev_err(&pdev->dev, "no slots\n");
		return -ENXIO;
	}

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	irq = platform_get_irq(pdev, 0);
	if (res == NULL || irq < 0)
		return -ENXIO;

	res = request_mem_region(res->start, resource_size(res),
				 pdev->name);
	if (res == NULL)
		return -EBUSY;

	host = kzalloc(sizeof(struct mmc_omap_host), GFP_KERNEL);
	if (host == NULL) {
		ret = -ENOMEM;
		goto err_free_mem_region;
	}

	INIT_WORK(&host->slot_release_work, mmc_omap_slot_release_work);
	INIT_WORK(&host->send_stop_work, mmc_omap_send_stop_work);

	INIT_WORK(&host->cmd_abort_work, mmc_omap_abort_command);
	setup_timer(&host->cmd_abort_timer, mmc_omap_cmd_timer,
		    (unsigned long) host);

	spin_lock_init(&host->clk_lock);
	setup_timer(&host->clk_timer, mmc_omap_clk_timer, (unsigned long) host);

	spin_lock_init(&host->dma_lock);
	spin_lock_init(&host->slot_lock);
	init_waitqueue_head(&host->slot_wq);

	host->pdata = pdata;
	host->dev = &pdev->dev;
	platform_set_drvdata(pdev, host);

	host->id = pdev->id;
	host->mem_res = res;
	host->irq = irq;
	host->use_dma = 1;
	host->irq = irq;
	host->phys_base = host->mem_res->start;
	host->virt_base = ioremap(res->start, resource_size(res));
	if (!host->virt_base)
		goto err_ioremap;

	host->iclk = clk_get(&pdev->dev, "ick");
	if (IS_ERR(host->iclk)) {
		ret = PTR_ERR(host->iclk);
		goto err_free_mmc_host;
	}
	clk_enable(host->iclk);

	host->fclk = clk_get(&pdev->dev, "fck");
	if (IS_ERR(host->fclk)) {
		ret = PTR_ERR(host->fclk);
		goto err_free_iclk;
	}

	dma_cap_zero(mask);
	dma_cap_set(DMA_SLAVE, mask);

	host->dma_tx_burst = -1;
	host->dma_rx_burst = -1;

	if (cpu_is_omap24xx())
		sig = host->id == 0 ? OMAP24XX_DMA_MMC1_TX : OMAP24XX_DMA_MMC2_TX;
	else
		sig = host->id == 0 ? OMAP_DMA_MMC_TX : OMAP_DMA_MMC2_TX;
	host->dma_tx = dma_request_channel(mask, omap_dma_filter_fn, &sig);
#if 0
	if (!host->dma_tx) {
		dev_err(host->dev, "unable to obtain TX DMA engine channel %u\n",
			sig);
		goto err_dma;
	}
#else
	if (!host->dma_tx)
		dev_warn(host->dev, "unable to obtain TX DMA engine channel %u\n",
			sig);
#endif
	if (cpu_is_omap24xx())
		sig = host->id == 0 ? OMAP24XX_DMA_MMC1_RX : OMAP24XX_DMA_MMC2_RX;
	else
		sig = host->id == 0 ? OMAP_DMA_MMC_RX : OMAP_DMA_MMC2_RX;
	host->dma_rx = dma_request_channel(mask, omap_dma_filter_fn, &sig);
#if 0
	if (!host->dma_rx) {
		dev_err(host->dev, "unable to obtain RX DMA engine channel %u\n",
			sig);
		goto err_dma;
	}
#else
	if (!host->dma_rx)
		dev_warn(host->dev, "unable to obtain RX DMA engine channel %u\n",
			sig);
#endif

	ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host);
	if (ret)
		goto err_free_dma;

	if (pdata->init != NULL) {
		ret = pdata->init(&pdev->dev);
		if (ret < 0)
			goto err_free_irq;
	}

	host->nr_slots = pdata->nr_slots;
	host->reg_shift = (cpu_is_omap7xx() ? 1 : 2);

	host->mmc_omap_wq = alloc_workqueue("mmc_omap", 0, 0);
	if (!host->mmc_omap_wq)
		goto err_plat_cleanup;

	for (i = 0; i < pdata->nr_slots; i++) {
		ret = mmc_omap_new_slot(host, i);
		if (ret < 0) {
			while (--i >= 0)
				mmc_omap_remove_slot(host->slots[i]);

			goto err_destroy_wq;
		}
	}

	return 0;

err_destroy_wq:
	destroy_workqueue(host->mmc_omap_wq);
err_plat_cleanup:
	if (pdata->cleanup)
		pdata->cleanup(&pdev->dev);
err_free_irq:
	free_irq(host->irq, host);
err_free_dma:
	if (host->dma_tx)
		dma_release_channel(host->dma_tx);
	if (host->dma_rx)
		dma_release_channel(host->dma_rx);
	clk_put(host->fclk);
err_free_iclk:
	clk_disable(host->iclk);
	clk_put(host->iclk);
err_free_mmc_host:
	iounmap(host->virt_base);
err_ioremap:
	kfree(host);
err_free_mem_region:
	release_mem_region(res->start, resource_size(res));
	return ret;
}
示例#30
-1
static int igorplugusb_probe(struct usb_interface *intf,
					const struct usb_device_id *id)
{
	struct usb_device *udev;
	struct usb_host_interface *idesc;
	struct usb_endpoint_descriptor *ep;
	struct igorplugusb *ir;
	struct rc_dev *rc;
	int ret = -ENOMEM;

	udev = interface_to_usbdev(intf);
	idesc = intf->cur_altsetting;

	if (idesc->desc.bNumEndpoints != 1) {
		dev_err(&intf->dev, "incorrect number of endpoints");
		return -ENODEV;
	}

	ep = &idesc->endpoint[0].desc;
	if (!usb_endpoint_dir_in(ep) || !usb_endpoint_xfer_control(ep)) {
		dev_err(&intf->dev, "endpoint incorrect");
		return -ENODEV;
	}

	ir = devm_kzalloc(&intf->dev, sizeof(*ir), GFP_KERNEL);
	if (!ir)
		return -ENOMEM;

	ir->dev = &intf->dev;

	setup_timer(&ir->timer, igorplugusb_timer, (unsigned long)ir);

	ir->request.bRequest = GET_INFRACODE;
	ir->request.bRequestType = USB_TYPE_VENDOR | USB_DIR_IN;
	ir->request.wLength = cpu_to_le16(sizeof(ir->buf_in));

	ir->urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!ir->urb)
		goto fail;

	usb_fill_control_urb(ir->urb, udev,
		usb_rcvctrlpipe(udev, 0), (uint8_t *)&ir->request,
		ir->buf_in, sizeof(ir->buf_in), igorplugusb_callback, ir);

	usb_make_path(udev, ir->phys, sizeof(ir->phys));

	rc = rc_allocate_device(RC_DRIVER_IR_RAW);
	if (!rc)
		goto fail;

	rc->device_name = DRIVER_DESC;
	rc->input_phys = ir->phys;
	usb_to_input_id(udev, &rc->input_id);
	rc->dev.parent = &intf->dev;
	/*
	 * This device can only store 36 pulses + spaces, which is not enough
	 * for the NEC protocol and many others.
	 */
	rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER &
		~(RC_PROTO_BIT_NEC | RC_PROTO_BIT_NECX | RC_PROTO_BIT_NEC32 |
		  RC_PROTO_BIT_RC6_6A_20 | RC_PROTO_BIT_RC6_6A_24 |
		  RC_PROTO_BIT_RC6_6A_32 | RC_PROTO_BIT_RC6_MCE |
		  RC_PROTO_BIT_SONY20 | RC_PROTO_BIT_SANYO);

	rc->priv = ir;
	rc->driver_name = DRIVER_NAME;
	rc->map_name = RC_MAP_HAUPPAUGE;
	rc->timeout = MS_TO_NS(100);
	rc->rx_resolution = 85333;

	ir->rc = rc;
	ret = rc_register_device(rc);
	if (ret) {
		dev_err(&intf->dev, "failed to register rc device: %d", ret);
		goto fail;
	}

	usb_set_intfdata(intf, ir);

	igorplugusb_cmd(ir, SET_INFRABUFFER_EMPTY);

	return 0;
fail:
	rc_free_device(ir->rc);
	usb_free_urb(ir->urb);
	del_timer(&ir->timer);

	return ret;
}