Example #1
0
//  ************************************************************ //
//  Device Init :
//  
//  
//
//  ************************************************************ //
static int __init gps_gpio_init(void)  
{  
    int result;  
        gps_dbg("gps_gpio_init\n"); 

  
	if (0 == gps_major)
	{
		/* auto select a major */
		result = alloc_chrdev_region(&dev, 0, 1, GPS_GPIO_DEV_NAME);
		gps_major = MAJOR(dev);
	}
	else
	{
		/* use load time defined major number */
		dev = MKDEV(gps_major, 0);
		result = register_chrdev_region(dev, 1, GPS_GPIO_DEV_NAME);
	}

	memset(&gps_cdev, 0, sizeof(gps_cdev));

	/* initialize our char dev data */
	cdev_init(&gps_cdev, &gps_gpio_fops);

	/* register char dev with the kernel */
	result = cdev_add(&gps_cdev, dev, 1);
    
	if (0 != result)
	{
		unregister_chrdev_region(dev, 1);
		gps_dbg("Error registrating mali device object with the kernel\n");
	}

    gps_class = class_create(THIS_MODULE, GPS_GPIO_DEV_NAME);
    device_create(gps_class, NULL, MKDEV(gps_major, MINOR(dev)), NULL,
                  GPS_GPIO_DEV_NAME);

    if (result < 0)
        return result;  

#if defined(CONFIG_MACH_TCC9300) || defined(CONFIG_MACH_TCC8800) || defined(CONFIG_MACH_TCC8920)
    if(machine_is_m801_88() || machine_is_m803()) // GPIOG[4]
    {
        gps_dbg("GPS_PWREN on\n");
        tcc_gpio_config(TCC_GPG(4), GPIO_FN(0));
        gpio_request(TCC_GPG(4), "GPIO_PWREN");
        gpio_direction_output(TCC_GPG(4), 0);
    }
    else if(machine_is_tcc8800() || machine_is_tcc8920()) 
    {
        gps_dbg("gpio_direction_output__gps\n");
        gpio_direction_output(TCC_GPEXT1(6), 0);    // GPS Power On
    }
#elif defined(CONFIG_MACH_TCC8900)
    if(machine_is_tcc8900())
    {
        gps_dbg("GPS_8900_PWREN on\n");
        tcc_gpio_config(TCC_GPD(25), GPIO_FN(0));
        gpio_request(TCC_GPD(25), "GPIO_PWREN");
        gpio_set_value(TCC_GPD(25), 0);
    }
#elif defined(CONFIG_MACH_M805_892X)
    if(machine_is_m805_892x())
    {
        gps_dbg("GPS_PWREN on\n");
		if (system_rev == 0x2002 || system_rev == 0x2003 || system_rev == 0x2004 || system_rev == 0x2005 || system_rev == 0x2006 || system_rev == 0x2007) {
			tcc_gpio_config(TCC_GPE(14), GPIO_FN(0));
			gpio_request(TCC_GPE(14), "GPIO_PWREN");
			gpio_direction_output(TCC_GPE(14), 0);

		} else if (system_rev == 0x2000 || system_rev == 0x2001) {
			tcc_gpio_config(TCC_GPC(6), GPIO_FN(0));
			gpio_request(TCC_GPC(6), "GPIO_PWREN");
			gpio_direction_output(TCC_GPC(6), 0);
		}
    }
#endif

    gps_dbg("GPS driver loaded\n");

    return 0;  
}  
Example #2
0
static int ltn070nl01_panel_probe(struct omap_dss_device *dssdev)
{
	int ret = 0;
	struct ltn070nl01 *lcd = NULL;

	struct backlight_properties props = {
		.brightness = BRIGHTNESS_DEFAULT,
		.max_brightness = 255,
		.type = BACKLIGHT_RAW,
	};
	pr_info("(%s): called (@%d)\n", __func__, __LINE__);
	dev_dbg(&dssdev->dev, "ltn070nl01_probe\n");

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

	if (dssdev->data == NULL) {
		dev_err(&dssdev->dev, "no platform data!\n");
		ret = -EINVAL;
		goto err_no_platform_data;
	}

	dssdev->panel.config = OMAP_DSS_LCD_TFT
			     | OMAP_DSS_LCD_IVS
			     /*| OMAP_DSS_LCD_IEO */
			     | OMAP_DSS_LCD_IPC
			     | OMAP_DSS_LCD_IHS
			     | OMAP_DSS_LCD_ONOFF;

	dssdev->panel.acb = 0;

	lcd->dssdev = dssdev;
	lcd->pdata = dssdev->data;

	ltn070nl01_brightness_data = lcd->pdata->brightness_table;

	lcd->bl = get_gamma_value_from_bl(props.brightness);

	ret = gpio_request(lcd->pdata->lvds_nshdn_gpio, "lvds_nshdn");
	if (ret < 0) {
		dev_err(&dssdev->dev, "gpio_request %d failed!\n",
			lcd->pdata->lvds_nshdn_gpio);
		goto err_no_platform_data;
	}
	gpio_direction_output(lcd->pdata->lvds_nshdn_gpio, 1);

	ret = gpio_request(lcd->pdata->led_backlight_reset_gpio,
		"led_backlight_reset");
	if (ret < 0) {
		dev_err(&dssdev->dev, "gpio_request %d failed!\n",
			lcd->pdata->led_backlight_reset_gpio);
		goto err_backlight_reset_gpio_request;
	}
	gpio_direction_output(lcd->pdata->led_backlight_reset_gpio, 1);

	mutex_init(&lcd->lock);

	dev_set_drvdata(&dssdev->dev, lcd);

	/* Register DSI backlight  control */
	lcd->bd = backlight_device_register("panel", &dssdev->dev, dssdev,
					    &ltn070nl01_backlight_ops, &props);
	if (IS_ERR(lcd->bd)) {
		ret = PTR_ERR(lcd->bd);
		goto err_backlight_device_register;
	}

	lcd->lcd_class = class_create(THIS_MODULE, "lcd");
	if (IS_ERR(lcd->lcd_class)) {
		pr_err("Failed to create lcd_class!");
		goto err_class_create;
	}

	lcd->dev = device_create(lcd->lcd_class, NULL, 0, NULL, "panel");
	if (IS_ERR(lcd->dev)) {
		pr_err("Failed to create device(panel)!\n");
		goto err_device_create;
	}

	dev_set_drvdata(lcd->dev, &dssdev->dev);

	ret = device_create_file(lcd->dev, &dev_attr_lcd_type);
	if (ret < 0) {
		dev_err(&dssdev->dev,
			"failed to add 'lcd_type' sysfs entries\n");
		goto err_lcd_device;
	}
	ret = device_create_file(lcd->dev, &dev_attr_lcd_power);
	if (ret < 0) {
		dev_err(&dssdev->dev,
			"failed to add 'lcd_power' sysfs entries\n");
		goto err_lcd_type;
	}

	ret = backlight_gptimer_init(dssdev);
	if (ret < 0) {
		dev_err(&dssdev->dev,
			"backlight_gptimer_init failed!\n");
		goto err_gptimer_init;
	}

	/*
	 * if lcd panel was on from bootloader like u-boot then
	 * do not lcd on.
	 */
	if (dssdev->skip_init)
		lcd->enabled = 1;

	update_brightness(dssdev);

	dev_dbg(&dssdev->dev, "%s\n", __func__);
	return ret;

err_gptimer_init:
	device_remove_file(&(lcd->bd->dev), &dev_attr_lcd_power);
err_lcd_type:
	device_remove_file(&(lcd->bd->dev), &dev_attr_lcd_type);
err_lcd_device:
	device_destroy(lcd->lcd_class, 0);
err_device_create:
	class_destroy(lcd->lcd_class);
err_class_create:
	backlight_device_unregister(lcd->bd);
err_backlight_device_register:
	mutex_destroy(&lcd->lock);
	gpio_free(lcd->pdata->led_backlight_reset_gpio);
err_backlight_reset_gpio_request:
	gpio_free(lcd->pdata->lvds_nshdn_gpio);
err_no_platform_data:
	kfree(lcd);

	return ret;
}

static void ltn070nl01_panel_remove(struct omap_dss_device *dssdev)
{
	struct ltn070nl01 *lcd = dev_get_drvdata(&dssdev->dev);
	device_remove_file(&(lcd->bd->dev), &dev_attr_lcd_power);
	device_remove_file(&(lcd->bd->dev), &dev_attr_lcd_type);
	device_destroy(lcd->lcd_class, 0);
	class_destroy(lcd->lcd_class);
	backlight_device_unregister(lcd->bd);
	mutex_destroy(&lcd->lock);
	gpio_free(lcd->pdata->led_backlight_reset_gpio);
	gpio_free(lcd->pdata->lvds_nshdn_gpio);
	kfree(lcd);
}

static int ltn070nl01_start(struct omap_dss_device *dssdev)
{
	int r = 0;

	r = ltn070nl01_power_on(dssdev);

	if (r) {
		dev_dbg(&dssdev->dev, "enable failed\n");
		dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
	} else {
		dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
		dssdev->manager->enable(dssdev->manager);
	}

	return r;
}
static int jpeg_probe(struct platform_device *pdev)
{
    struct class_device;
    
	int ret;
    struct class_device *class_dev = NULL;
    
    JPEG_MSG("-------------jpeg driver probe-------\n");
	ret = alloc_chrdev_region(&jpeg_devno, 0, 1, JPEG_DEVNAME);

	if(ret)
	{
	    JPEG_ERR("Error: Can't Get Major number for JPEG Device\n");
	}
	else
	{
	    JPEG_MSG("Get JPEG Device Major number (%d)\n", jpeg_devno);
    }

	jpeg_cdev = cdev_alloc();
    jpeg_cdev->owner = THIS_MODULE;
	jpeg_cdev->ops = &jpeg_fops;

	ret = cdev_add(jpeg_cdev, jpeg_devno, 1);

    jpeg_class = class_create(THIS_MODULE, JPEG_DEVNAME);
    class_dev = (struct class_device *)device_create(jpeg_class, NULL, jpeg_devno, NULL, JPEG_DEVNAME);

    spin_lock_init(&jpeg_dec_lock);
    spin_lock_init(&jpeg_enc_lock);

    // initial codec, register codec ISR
    dec_status = 0;
    enc_status = 0;
    _jpeg_dec_int_status = 0;
    _jpeg_enc_int_status = 0;
    _jpeg_dec_mode = 0;

#ifndef FPGA_VERSION
    init_waitqueue_head(&dec_wait_queue);
    init_waitqueue_head(&enc_wait_queue);  
    
    //mt6575_irq_set_sens(MT6575_JPEG_CODEC_IRQ_ID, MT65xx_LEVEL_SENSITIVE);
    //mt6575_irq_set_polarity(MT6575_JPEG_CODEC_IRQ_ID, MT65xx_POLARITY_LOW);
    //mt6575_irq_unmask(MT6575_JPEG_CODEC_IRQ_ID);
    JPEG_MSG("request JPEG Encoder IRQ \n");
    enable_irq(MT6589_JPEG_ENC_IRQ_ID);
    if(request_irq(MT6589_JPEG_ENC_IRQ_ID, jpeg_drv_enc_isr, IRQF_TRIGGER_LOW, "jpeg_enc_driver" , NULL))
    //if(request_irq(MT6589_JPEG_ENC_IRQ_ID, jpeg_drv_enc_isr, /*IRQF_TRIGGER_RISING*/ IRQF_TRIGGER_HIGH, "jpeg_enc_driver" , NULL))
    //if(request_irq(MT6589_JPEG_ENC_IRQ_ID, jpeg_drv_enc_isr, IRQF_TRIGGER_RISING , "jpeg_enc_driver" , NULL))
    {
        JPEG_ERR("JPEG ENC Driver request irq failed\n");
    }
    enable_irq(MT6589_JPEG_DEC_IRQ_ID);
    JPEG_MSG("request JPEG Decoder IRQ \n");
    //if(request_irq(MT6589_JPEG_DEC_IRQ_ID, jpeg_drv_dec_isr, IRQF_TRIGGER_LOW, "jpeg_dec_driver" , NULL))
    //if(request_irq(MT6589_JPEG_DEC_IRQ_ID, jpeg_drv_dec_isr, /*IRQF_TRIGGER_RISING*/ IRQF_TRIGGER_HIGH, "jpeg_dec_driver" , NULL))
    //if(request_irq(MT6589_JPEG_DEC_IRQ_ID, jpeg_drv_dec_isr, IRQF_TRIGGER_RISING , "jpeg_dec_driver" , NULL))
    if(request_irq(MT6589_JPEG_DEC_IRQ_ID, jpeg_drv_dec_isr, IRQF_TRIGGER_FALLING , "jpeg_dec_driver" , NULL))
    {
        JPEG_ERR("JPEG DEC Driver request irq failed\n");
    }    
    
#endif
	JPEG_MSG("JPEG Probe Done\n");

	NOT_REFERENCED(class_dev);
	return 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 gpio_keys_button *button = NULL;
    struct gpio_button_data *bdata = NULL ;
    struct device *dev = &pdev->dev;
    struct gpio_keys_platform_data alt_pdata;
    struct input_dev *input;
    int i, error;
    int wakeup = 0;
#ifdef CONFIG_SENSORS_HALL
    int ret;
    struct device *sec_key;
#endif

    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);
#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++) {
        button = &pdata->buttons[i];
        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
    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;
    }

    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 that are connected to GPIOs */
    for (i = 0; i < pdata->nbuttons; i++) {
        struct gpio_button_data *bdata = &ddata->data[i];
        if (gpio_is_valid(bdata->button->gpio))
            gpio_keys_gpio_report_event(bdata);
    }
    input_sync(input);

#ifdef CONFIG_SENSORS_HALL
    sec_key = device_create(sec_class, NULL, 0, NULL, "sec_key");
    if (IS_ERR(sec_key))
        pr_err("Failed to create device(sec_key)!\n");

    ret = device_create_file(sec_key, &dev_attr_hall_detect);
    if (ret < 0) {
        pr_err("Failed to create device file(%s)!, error: %d\n",
               dev_attr_hall_detect.attr.name, ret);
    }

    ret = device_create_file(sec_key, &dev_attr_sec_key_pressed);
    if (ret) {
        pr_err("Failed to create device file in sysfs entries(%s)!\n",
               dev_attr_sec_key_pressed.attr.name);
    }
    ret = device_create_file(sec_key, &dev_attr_wakeup_keys);
    if (ret < 0) {
        pr_err("Failed to create device file(%s), error: %d\n",
               dev_attr_wakeup_keys.attr.name, ret);
    }
    dev_set_drvdata(sec_key, ddata);
#endif
    device_init_wakeup(&pdev->dev, 1);

    return 0;

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

    platform_set_drvdata(pdev, NULL);
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;
}
static int __devinit ktd2026_probe(struct i2c_client *client,
	const struct i2c_device_id *id)
{
	struct ktd2026_data *data;
	int ret, i;

	pr_info("%s\n", __func__);
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		dev_err(&client->dev, "need I2C_FUNC_I2C.\n");
		return -ENODEV;
	}

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
		dev_err(&client->dev, "need I2C_FUNC_SMBUS_BYTE_DATA.\n");
		return -EIO;
	}

	data = kzalloc(sizeof(*data), GFP_KERNEL);
	if (!data) {
		dev_err(&client->adapter->dev,
			"failed to allocate driver data.\n");
		return -ENOMEM;
	}

	i2c_set_clientdata(client, data);
	data->client = client;
	b_client = client;

	mutex_init(&data->mutex);

	/* initialize LED */
	/* turn off all leds */
	ktd2026_leds_on(LED_R, LED_EN_OFF, 0);
	ktd2026_leds_on(LED_G, LED_EN_OFF, 0);
	ktd2026_leds_on(LED_B, LED_EN_OFF, 0);

	ktd2026_set_timerslot_control(0); /* Tslot1 */
	ktd2026_set_period(0);
	ktd2026_set_pwm_duty(PWM1, 0);
	ktd2026_set_pwm_duty(PWM2, 0);
	ktd2026_set_trise_tfall(0, 0, 0);

	for (i = 0; i < MAX_NUM_LEDS; i++) {

		ret = initialize_channel(client, &data->leds[i], i);

		if (ret < 0) {
			dev_err(&client->adapter->dev, "failure on initialization\n");
			goto exit;
		}
		INIT_WORK(&(data->leds[i].brightness_work),
				 ktd2026_led_brightness_work);
	}

	leds_i2c_write_all(client);

#ifdef SEC_LED_SPECIFIC
	led_dev = device_create(sec_class, NULL, 0, data, "led");
	if (IS_ERR(led_dev)) {
		dev_err(&client->dev,
			"Failed to create device for samsung specific led\n");
		ret = -ENODEV;
		goto exit;
	}
	ret = sysfs_create_group(&led_dev->kobj, &sec_led_attr_group);
	if (ret) {
		dev_err(&client->dev,
			"Failed to create sysfs group for samsung specific led\n");
		device_destroy(sec_class, 0);
		goto exit;
	}
#endif

	fading_status = 0;
	
	return ret;
exit:
	mutex_destroy(&data->mutex);
	kfree(data);
	return ret;
}
static int exynos_pd_power_on(struct device *dev, const char * device_name)
{
	struct exynos_pm_domain *pd_index = NULL;
	int ret = 0;
	struct gpd_timing_data gpd_td = {
		.stop_latency_ns = 50000,
		.start_latency_ns = 50000,
		.save_state_latency_ns = 500000,
		.restore_state_latency_ns = 500000,
	};

#ifdef CONFIG_SOC_EXYNOS5260
	if(soc_is_exynos5260())
		pd_index = exynos5260_pm_domain();
#endif

#ifdef CONFIG_SOC_EXYNOS4415
	if (soc_is_exynos4415())
		pd_index = exynos4415_pm_domain();
#endif

	if (!pd_index) {
		pr_err(PM_DOMAIN_PREFIX "domain data is not found\n");
		return -EINVAL;
	}

	/* lookup master pd */
	for_each_power_domain(pd_index) {
		/* skip unmanaged power domains */
		if (!pd_index->enable)
			continue;

		if (strcmp(pd_index->name, device_name)) {
			continue;
		}

		if (pd_index->check_status(pd_index)) {
			pr_err("PM DOMAIN: %s is already on.\n", pd_index->name);
			break;
		}

		while (1) {
			ret = __pm_genpd_add_device(&pd_index->genpd, dev, &gpd_td);
			if (ret != -EAGAIN)
				break;
			cond_resched();
		}
		if (!ret) {
			pm_genpd_dev_need_restore(dev, true);
			pr_info("PM DOMAIN: %s, Device : %s Registered\n", pd_index->name, dev_name(dev));
		} else
			pr_err("PM DOMAIN: %s cannot add device %s\n", pd_index->name, dev_name(dev));

		pm_runtime_enable(dev);
		pm_runtime_get_sync(dev);
		pr_info("%s: power on.\n", pd_index->name);
	}

	return ret;

}

static int exynos_pd_power_off(struct device *dev, const char * device_name)
{
	struct exynos_pm_domain *pd_index = NULL;
	int ret = 0;

#ifdef CONFIG_SOC_EXYNOS5260
	if(soc_is_exynos5260())
		pd_index = exynos5260_pm_domain();
#endif

#ifdef CONFIG_SOC_EXYNOS4415
	if (soc_is_exynos4415())
		pd_index = exynos4415_pm_domain();
#endif

	if (!pd_index) {
		pr_err(PM_DOMAIN_PREFIX "domain data is not found\n");
		return -EINVAL;
	}

	/* lookup master pd */
	for_each_power_domain(pd_index) {
		/* skip unmanaged power domains */
		if (!pd_index->enable)
			continue;

		if (strcmp(pd_index->name, device_name)) {
			continue;
		}

		if (!pd_index->check_status(pd_index)) {
			pr_err("PM DOMAIN: %s is already off.\n", pd_index->name);
			break;
		}

		pm_runtime_put_sync(dev);
		pm_runtime_disable(dev);

		while (1) {
			ret = pm_genpd_remove_device(&pd_index->genpd, dev);
			if (ret != -EAGAIN)
				break;
			cond_resched();
		}
		if (ret)
			pr_err("PM DOMAIN: %s cannot remove device %s\n", pd_index->name, dev_name(dev));
		pr_info("%s: power off.\n", pd_index->name);
	}

	return ret;

}

static int exynos_pd_longrun_test(struct device *dev, const char * device_name)
{
	struct exynos_pm_domain *pd_index = NULL;
	int i, ret = 0;
	struct gpd_timing_data gpd_td = {
		.stop_latency_ns = 50000,
		.start_latency_ns = 50000,
		.save_state_latency_ns = 500000,
		.restore_state_latency_ns = 500000,
	};

#ifdef CONFIG_SOC_EXYNOS5260
	if(soc_is_exynos5260())
		pd_index = exynos5260_pm_domain();
#endif

#ifdef CONFIG_SOC_EXYNOS4415
	if (soc_is_exynos4415())
		pd_index = exynos4415_pm_domain();
#endif

	if (!pd_index) {
		pr_err(PM_DOMAIN_PREFIX "domain data is not found\n");
		return -EINVAL;
	}

	/* lookup master pd */
	for_each_power_domain(pd_index) {
		/* skip unmanaged power domains */
		if (!pd_index->enable)
			continue;

		if (strcmp(pd_index->name, device_name)) {
			continue;
		}

		if (pd_index->check_status(pd_index)) {
			pr_err("PM DOMAIN: %s is working. Stop testing\n", pd_index->genpd.name);
			break;
		}

		while (1) {
			ret = __pm_genpd_add_device(&pd_index->genpd, dev, &gpd_td);
			if (ret != -EAGAIN)
				break;
			cond_resched();
		}
		if (!ret) {
			pm_genpd_dev_need_restore(dev, true);
			pr_info("PM DOMAIN: %s, Device : %s Registered\n", pd_index->genpd.name, dev_name(dev));
		} else
			pr_err("PM DOMAIN: %s cannot add device %s\n", pd_index->genpd.name, dev_name(dev));

		pr_info("%s: test start.\n", pd_index->genpd.name);
		pm_runtime_enable(dev);
		for (i=0; i<100; i++) {
			pm_runtime_get_sync(dev);
			mdelay(50);
			pm_runtime_put_sync(dev);
			mdelay(50);
		}
		pr_info("%s: test done.\n", pd_index->genpd.name);
		pm_runtime_disable(dev);

		while (1) {
			ret = pm_genpd_remove_device(&pd_index->genpd, dev);
			if (ret != -EAGAIN)
				break;
			cond_resched();
		}
		if (ret)
			pr_err("PM DOMAIN: %s cannot remove device %s\n", pd_index->name, dev_name(dev));
	}

	return ret;
}

static ssize_t store_power_domain_test(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
	char device_name[32], test_name[32];

	sscanf(buf, "%s %s", device_name, test_name);

	switch (test_name[0]) {
	case '1':
		exynos_pd_power_on(dev, device_name);
		break;

	case '0':
		exynos_pd_power_off(dev, device_name);
		break;

	case 't':
		exynos_pd_longrun_test(dev, device_name);
		break;

	default:
		printk("echo \"device\" \"test\" > control\n");
	}

	return count;
}

static DEVICE_ATTR(control, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, show_power_domain, store_power_domain_test);

static struct attribute *control_device_attrs[] = {
	&dev_attr_control.attr,
	NULL,
};

static const struct attribute_group control_device_attr_group = {
	.attrs = control_device_attrs,
};

static int runtime_pm_test_probe(struct platform_device *pdev)
{
	struct class *runtime_pm_class;
	struct device *runtime_pm_dev;
	int ret;

	runtime_pm_class = class_create(THIS_MODULE, "runtime_pm");
	runtime_pm_dev = device_create(runtime_pm_class, NULL, 0, NULL, "test");
	ret = sysfs_create_group(&runtime_pm_dev->kobj, &control_device_attr_group);
	if (ret) {
		pr_err("Runtime PM Test : error to create sysfs\n");
		return -EINVAL;
	}

	pm_runtime_enable(&pdev->dev);

	return 0;
}

static int runtime_pm_test_runtime_suspend(struct device *dev)
{
	pr_info("Runtime PM Test : Runtime_Suspend\n");
	return 0;
}
static int __devinit dock_keyboard_probe(struct platform_device *pdev)
{
//    struct dock_keyboard_data *data = pdev->dev.platform_data;
    struct dock_keyboard_data *data;
    struct input_dev *input;
    int i, error;
#if defined(ACC_INT_KBD)
    int gpio, irq;
#endif
    struct device *keyboard_dev;

    data = kzalloc(sizeof(struct dock_keyboard_data), GFP_KERNEL);
    if(NULL == data)
    {
        error = -ENOMEM;
        goto err_free_mem;
    }

    INIT_WORK(&data->work_msg, key_event_work);
    INIT_WORK(&data->work_led, led_work);

    input = input_allocate_device();
    if (!input)
    {
        printk(KERN_ERR "[Keyboard] Fail to allocate input device.\n");
        error = -ENOMEM;
        goto err_free_mem;
    }

    data->input_dev = input;
    data->kl = UNKOWN_KEYLAYOUT;

    input->name = pdev->name;
    input->dev.parent = &pdev->dev;
    input->id.bustype = BUS_RS232;

    set_bit(EV_SYN, input->evbit);
//    set_bit(EV_REP, input->evbit);
    set_bit(EV_KEY, input->evbit);

    for(i = 0; i < KEYBOARD_SIZE; i++)
    {
        if( KEY_RESERVED != dock_keycodes[i].keycode)
        {
            input_set_capability(input, EV_KEY, dock_keycodes[i].keycode);
        }
    }

    /* for the UK keyboard */
    input_set_capability(input, EV_KEY, KEY_NUMERIC_POUND);

    /* for the remaped keys */
    input_set_capability(input, EV_KEY, KEY_NEXTSONG);
    input_set_capability(input, EV_KEY, KEY_PREVIOUSSONG);

    error = input_register_device(data->input_dev);
    if(error<0)
    {
        printk(KERN_ERR "[Keyboard] Fail to register input device.\n");
        error = -ENOMEM;
        goto err_free_mem;
    }

    /* Accessory detect pin is used by dock accessory driver. */
#if defined(ACC_INT_KBD)
    gpio = GPIO_ACCESSORY_INT;
    s3c_gpio_cfgpin(gpio, S3C_GPIO_INPUT);
    s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
    irq = IRQ_EINT5;

    error = request_irq(irq, accessory_interrupt,
                    IRQF_SAMPLE_RANDOM|IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING,
			"p1_keyboard", data);
    if(error)
    {
        printk(KERN_ERR "[Keyboard] Fail to request irq : %d\n", error);
        error = -EINTR;
        goto err_free_mem;
    }
    data->gpio = gpio;
#else
    data->gpio = GPIO_ACCESSORY_INT;
#endif
    g_data = data;

    keyboard_dev = device_create(sec_class, NULL, 0, NULL, "keyboard");
    if (IS_ERR(keyboard_dev))
        pr_err("Failed to create device(ts)!\n");

    if (device_create_file(keyboard_dev, &dev_attr_keyboard_led) < 0)
        pr_err("Failed to create device file(%s)!\n", dev_attr_keyboard_led.attr.name);

#ifdef CONFIG_HAS_EARLYSUSPEND
	data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	data->early_suspend.suspend = keyboard_early_suspend;
	data->early_suspend.resume = keyboard_late_resume;
	register_early_suspend(&data->early_suspend);
#endif	/* CONFIG_HAS_EARLYSUSPEND */

    init_timer(&data->timer);
    data->timer.expires = jiffies + HZ * 5;
    data->timer.function = keyboard_timer;	/* timer handler */

    init_timer(&data->key_timer);
    data->key_timer.expires = jiffies + HZ/2;
    data->key_timer.function = remapkey_timer;

    boot_time = jiffies_to_msecs(jiffies);

    return 0;

err_free_mem:
    input_free_device(input);
    kfree(data);
    return error;

}
static int backlight_probe(struct i2c_client *client,
				  const struct i2c_device_id *id)
{
	struct backlight_platform_data *pdata;
	struct backlight_info *info;
	int error = 0;
#if defined(CONFIG_BLIC_TUNING)
	struct class *backlight_class;
	struct device *backlight_dev;
#endif
	struct samsung_display_driver_data *vdd = samsung_get_vdd();

	pr_info("%s", __func__);

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)){
		pr_err("[BACKLIGHT] failed to check i2c functionality!\n");
		return -EIO;
	}

	if (client->dev.of_node) {
		pdata = devm_kzalloc(&client->dev,
			sizeof(struct backlight_platform_data),
				GFP_KERNEL);
		if (!pdata) {
			dev_info(&client->dev, "Failed to allocate memory\n");
			return -ENOMEM;
		}

		error = backlight_parse_dt(&client->dev, pdata);
		if (error)
			return error;
	} else
		pdata = client->dev.platform_data;

	backlight_request_gpio(pdata);

	bl_info = info = kzalloc(sizeof(*info), GFP_KERNEL);
	if (!info) {
		dev_info(&client->dev, "%s: fail to memory allocation.\n", __func__);
		return -ENOMEM;
	}

	info->client = client;
	info->pdata = pdata;
	mdss_samsung_parse_backlight_settings(&client->dev,&info->bl_ic_settings,"backlight-ic-tuning");
	mdss_samsung_parse_backlight_settings(&client->dev,&info->bl_ic_outdoor_settings,"backlight-ic-tuning-outdoor");
	mdss_samsung_parse_backlight_settings(&client->dev,&info->bl_ic_normal_settings,"backlight-ic-tuning-normal");
	mdss_samsung_parse_backlight_settings(&client->dev,&info->bl_control,"backlight-i2c-bl-control");
#if defined(CONFIG_BLIC_TUNING)
	backlight_class = class_create(THIS_MODULE, "bl-dbg");
	backlight_dev = device_create(backlight_class, NULL, 0, NULL,  "ic-tuning");
	if (IS_ERR(backlight_dev))
		pr_err("Failed to create device(backlight_dev)!\n");
	else {
		if (device_create_file(backlight_dev, &dev_attr_bl_ic_tune) < 0)
			pr_err("Failed to create device file(%s)!\n", dev_attr_bl_ic_tune.attr.name);
		if (device_create_file(backlight_dev, &dev_attr_bl_ic_name) < 0)
			pr_err("Failed to create device file(%s)!\n", dev_attr_bl_ic_name.attr.name);
	}
#endif
	i2c_set_clientdata(client, info);

	vdd->panel_func.samsung_bl_ic_pwm_en = pwm_backlight_control;
	vdd->panel_func.samsung_bl_ic_i2c_ctrl = pwm_backlight_control_i2c;
	vdd->panel_func.samsung_bl_ic_outdoor = pwm_backlight_outdoor_control;

	return error;
}
Example #9
0
static int p3_probe(struct spi_device *spi)
{
	int ret = -1;
	//struct p3_spi_platform_data *platform_data = NULL;
	//struct p3_spi_platform_data platform_data1;
	struct p3_dev *p3_dev = NULL;

	P3_DBG_MSG("%s chip select : %d , bus number = %d \n",
		__FUNCTION__, spi->chip_select, spi->master->bus_num);

	p3_dev = kzalloc(sizeof(*p3_dev), GFP_KERNEL);
	if (p3_dev == NULL)
	{
		P3_ERR_MSG("failed to allocate memory for module data\n");
		ret = -ENOMEM;
		goto err_exit;
	}

	ret = p3_regulator_onoff(p3_dev, 1);
	if (ret) {
		P3_ERR_MSG("%s - Failed to enable regulator\n", __func__);
		goto p3_parse_dt_failed;
	}

	ret = p3_parse_dt(&spi->dev, p3_dev);
	if (ret) {
		P3_ERR_MSG("%s - Failed to parse DT\n", __func__);
		goto p3_parse_dt_failed;
	}
	P3_DBG_MSG("%s: tz_mode=%d, isGpio_cfgDone:%d\n", __func__,
			p3_dev->tz_mode, p3_dev->isGpio_cfgDone);

	//P3_DBG_MSG("%s ------\n", __FUNCTION__);	
#if 0
	ret = p3_hw_setup (platform_data, p3_dev, spi);
	if (ret < 0)
	{
		P3_ERR_MSG("Failed to enable IRQ_ENABLE\n");
		goto err_exit0;
	}
#endif
	//usleep_range(3000,3100);
	//gpio_direction_output(p3_dev->cs_gpio, 1);

	spi->bits_per_word = 8;
	spi->mode = SPI_MODE_3;
	spi->max_speed_hz = 1000000L;
	ret = spi_setup(spi);
	if (ret < 0)
	{
		P3_ERR_MSG("failed to do spi_setup()\n");
		goto p3_spi_setup_failed;
	}

	p3_dev -> spi = spi;
	p3_dev -> p3_device.minor = MISC_DYNAMIC_MINOR;
	p3_dev -> p3_device.name = "p3";
	p3_dev -> p3_device.fops = &p3_dev_fops;
	p3_dev -> p3_device.parent = &spi->dev;

	dev_set_drvdata(&spi->dev, p3_dev);

	/* init mutex and queues */
	init_waitqueue_head(&p3_dev->read_wq);
	mutex_init(&p3_dev->buffer_mutex);
	spin_lock_init(&p3_dev->ese_spi_lock);
#ifdef FEATURE_ESE_WAKELOCK
	wake_lock_init(&p3_dev->ese_lock,
		WAKE_LOCK_SUSPEND, "ese_wake_lock");
#endif

#ifdef P3_IRQ_ENABLE
	spin_lock_init(&p3_dev->irq_enabled_lock);
#endif

	ret = misc_register(&p3_dev->p3_device);
	if (ret < 0)
	{
		P3_ERR_MSG("misc_register failed! %d\n", ret);
		goto err_exit0;
	}

#if 0 //test
{
	struct device *dev;

	p3_device_class = class_create(THIS_MODULE, "ese");
	if (IS_ERR(p3_device_class)) {
		P3_ERR_MSG("%s class_create() is failed:%lu\n",
			__func__,  PTR_ERR(p3_device_class));
		//status = PTR_ERR(p3_device_class);
		//goto vfsspi_probe_class_create_failed;
	}
	dev = device_create(p3_device_class, NULL,
			    0, p3_dev, "p3");
		P3_ERR_MSG("%s device_create() is failed:%lu\n",
			__func__,  PTR_ERR(dev));

	if ((device_create_file(dev, &dev_attr_test)) < 0)
		P3_ERR_MSG("%s device_create_file failed !!!\n", __func__); 
	else
		P3_DBG_MSG("%s device_create_file success.\n", __func__);
	//ret = sysfs_create_group(&spi->dev.kobj,
	//		&p3_attribute_group);
	//if (ret < 0)
	//	P3_ERR_MSG("%s class_create() is failed - \n",
	//		__func__,  PTR_ERR(p3_device_class));
}
#endif

#ifdef ENABLE_ESE_P3_EXYNO_SPI
{
	void __iomem *gpg4con, *gpg4dat;

	gpg4con = ioremap(0x14c90000, SZ_4);
	gpg4dat = ioremap(0x14c90004, SZ_4);
	__raw_writel(0x1111, gpg4con);
	__raw_writel(0x0, gpg4dat);

	iounmap(gpg4con);
	iounmap(gpg4dat);
}
#endif
	gpio_direction_output(p3_dev->cs_gpio, 0);

	ret = p3_regulator_onoff(p3_dev, 0);
	if(ret < 0)
		P3_ERR_MSG(" test: failed to turn off LDO()\n");

	p3_dev-> enable_poll_mode = 1; /* Default IRQ read mode */
	P3_DBG_MSG("%s finished...\n", __FUNCTION__);
	return ret;

	/*err_exit1:*/
	misc_deregister(&p3_dev->p3_device);
	err_exit0:
#ifdef FEATURE_ESE_WAKELOCK
	wake_lock_destroy(&p3_dev->ese_lock);
#endif
	mutex_destroy(&p3_dev->buffer_mutex);
	p3_spi_setup_failed:
	p3_parse_dt_failed:
	kfree(p3_dev);
	err_exit:
	P3_DBG_MSG("ERROR: Exit : %s ret %d\n", __FUNCTION__, ret);
	return ret;
}
Example #10
0
int akm8975_probe(struct i2c_client *client,
		const struct i2c_device_id *devid)
{
	struct akm8975_data *akm;
	int err;

	if (client->dev.platform_data == NULL) {
		dev_err(&client->dev, "platform data is NULL. exiting.\n");
		err = -ENODEV;
		goto exit_platform_data_null;
	}

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		dev_err(&client->dev, "I2C check failed, exiting.\n");
		err = -ENODEV;
		goto exit_check_functionality_failed;
	}

	akm = kzalloc(sizeof(struct akm8975_data), GFP_KERNEL);
	if (!akm) {
		dev_err(&client->dev,
			"failed to allocate memory for module data\n");
		err = -ENOMEM;
		goto exit_alloc_data_failed;
	}

	akm->pdata = client->dev.platform_data;
	mutex_init(&akm->lock);
	init_completion(&akm->data_ready);

	i2c_set_clientdata(client, akm);
	akm->this_client = client;

	err = akm8975_ecs_set_mode_power_down(akm);
	if (err < 0)
		goto exit_set_mode_power_down_failed;

	akm->irq = client->irq;
	err = akm8975_setup_irq(akm);
	if (err) {
		pr_err("%s: could not setup irq\n", __func__);
		goto exit_setup_irq;
	}

	akm->akmd_device.minor = MISC_DYNAMIC_MINOR;
	akm->akmd_device.name = "akm8975";
	akm->akmd_device.fops = &akmd_fops;

	err = misc_register(&akm->akmd_device);
	if (err)
		goto exit_akmd_device_register_failed;

	init_waitqueue_head(&akm->state_wq);

	/* put into fuse access mode to read asa data */
	err = i2c_smbus_write_byte_data(client, AK8975_REG_CNTL,
					REG_CNTL_MODE_FUSE_ROM);
	if (err)
		pr_err("%s: unable to enter fuse rom mode\n", __func__);

	err = i2c_smbus_read_i2c_block_data(client, AK8975_REG_ASAX,
					sizeof(akm->asa), akm->asa);
	if (err != sizeof(akm->asa))
		pr_err("%s: unable to load factory sensitivity adjust values\n",
			__func__);
	else
		pr_debug("%s: asa_x = %d, asa_y = %d, asa_z = %d\n", __func__,
			akm->asa[0], akm->asa[1], akm->asa[2]);

	err = i2c_smbus_write_byte_data(client, AK8975_REG_CNTL,
					REG_CNTL_MODE_POWER_DOWN);
	if (err) {
		dev_err(&client->dev, "Error in setting power down mode\n");
		goto exit_device_create_file2;
	}

#if (defined DEBUG) || (defined FACTORY_TEST)
	ak8975c_selftest(akm);
#endif

#ifdef FACTORY_TEST
	err = sensors_register(magnetic_sensor_device, akm, magnetic_sensor_attrs, "magnetic_sensor");
	if(err) {
		printk(KERN_ERR "%s: cound not register magnetic sensor device(%d).\n", __func__, err);
	}
	
	sec_ak8975_dev = device_create(sec_class, NULL, 0, akm,
			"sec_ak8975");
	if (IS_ERR(sec_ak8975_dev))
		printk("Failed to create device!");

	if (device_create_file(sec_ak8975_dev, &dev_attr_ak8975_asa) < 0) {
		printk("Failed to create device file(%s)! \n",
			dev_attr_ak8975_asa.attr.name);
		goto exit_device_create_file2;
	}
	if (device_create_file(sec_ak8975_dev, &dev_attr_ak8975_selftest) < 0) {
		printk("Failed to create device file(%s)! \n",
			dev_attr_ak8975_selftest.attr.name);
		device_remove_file(sec_ak8975_dev, &dev_attr_ak8975_asa);
		goto exit_device_create_file2;
	}
	if (device_create_file(sec_ak8975_dev, &dev_attr_ak8975_chk_registers) < 0) {
		printk("Failed to create device file(%s)! \n",
			dev_attr_ak8975_chk_registers.attr.name);
		device_remove_file(sec_ak8975_dev, &dev_attr_ak8975_asa);
		device_remove_file(sec_ak8975_dev, &dev_attr_ak8975_selftest);
		goto exit_device_create_file2;
	}
	if (device_create_file(sec_ak8975_dev, &dev_attr_ak8975_chk_cntl) < 0) {
		printk("Failed to create device file(%s)! \n",
			dev_attr_ak8975_chk_cntl.attr.name);
		device_remove_file(sec_ak8975_dev, &dev_attr_ak8975_asa);
		device_remove_file(sec_ak8975_dev, &dev_attr_ak8975_selftest);
		device_remove_file(sec_ak8975_dev, &dev_attr_ak8975_chk_registers);
		goto exit_device_create_file2;
	}
#endif

	return 0;

exit_device_create_file2:
exit_akmd_device_register_failed:
	free_irq(akm->irq, akm);
	gpio_free(akm->pdata->gpio_data_ready_int);
exit_setup_irq:
exit_set_mode_power_down_failed:
	mutex_destroy(&akm->lock);
	kfree(akm);
exit_alloc_data_failed:
exit_check_functionality_failed:
exit_platform_data_null:
	return err;
}
static int __devinit ktd2026_probe(struct i2c_client *client,
	const struct i2c_device_id *id)
{
	struct ktd2026_data *data;
	int ret, i;

	pr_info("%s\n", __func__);
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		dev_err(&client->dev, "need I2C_FUNC_I2C.\n");
		return -ENODEV;
	}

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
		dev_err(&client->dev, "need I2C_FUNC_SMBUS_BYTE_DATA.\n");
		return -EIO;
	}

	if (client->dev.of_node) {
		data = kzalloc(sizeof(*data), GFP_KERNEL);
		if (!data) {
			dev_err(&client->adapter->dev,
					"failed to allocate driver data.\n");
			return -ENOMEM;
		}
	} else
		data = client->dev.platform_data;

	i2c_set_clientdata(client, data);
	data->client = client;
	b_client = client;

	mutex_init(&data->mutex);

	/* initialize LED */
	/* turn off all leds */
	ktd2026_leds_on(LED_R, LED_EN_OFF, 0);
#if defined(CONFIG_SEC_FACTORY)
#if defined (CONFIG_SEC_ATLANTIC_PROJECT)
	if(batt_id_value == 0)
		ret = 1;
	else
		ret = 0;
#if defined(CONFIG_FB_MSM8x26_MDSS_CHECK_LCD_CONNECTION)
	if(get_lcd_attached() == 0)     // When LCD Not connected turning RED LED on
		ret++;;
#endif

	if(jig_power_on_value == 0)
		ret++;
	if(ret == 3)	// case when LCD not connected,battery power on and jig off
		ktd2026_leds_on(LED_R, LED_EN_ON, 30);
#endif		//ATLANTIC FLAG
#endif
	ktd2026_leds_on(LED_G, LED_EN_OFF, 0);
	ktd2026_leds_on(LED_B, LED_EN_OFF, 0);

	ktd2026_set_timerslot_control(0); /* Tslot1 */
	ktd2026_set_period(0);
	ktd2026_set_pwm_duty(PWM1, 0);
	ktd2026_set_pwm_duty(PWM2, 0);
	ktd2026_set_trise_tfall(0, 0, 0);

	for (i = 0; i < MAX_NUM_LEDS; i++) {

		ret = initialize_channel(client, &data->leds[i], i);

		if (ret < 0) {
			dev_err(&client->adapter->dev, "failure on initialization\n");
			goto exit;
		}
		INIT_WORK(&(data->leds[i].brightness_work),
				 ktd2026_led_brightness_work);
	}

	leds_i2c_write_all(client);

#ifdef SEC_LED_SPECIFIC
	led_dev = device_create(sec_class, NULL, 0, data, "led");
	if (IS_ERR(led_dev)) {
		dev_err(&client->dev,
			"Failed to create device for samsung specific led\n");
		ret = -ENODEV;
		goto exit;
	}
	ret = sysfs_create_group(&led_dev->kobj, &sec_led_attr_group);
	if (ret) {
		dev_err(&client->dev,
			"Failed to create sysfs group for samsung specific led\n");
		goto exit;
	}
#endif
	return ret;
exit:
	mutex_destroy(&data->mutex);
	kfree(data);
	return ret;
}
void cabc_tuning_init(struct mdss_dsi_ctrl_pdata *dsi_pdata)
{
	pr_info("%s : dsi dest = %d\n", __func__,
					dsi_pdata->panel_data.panel_info.pdest);

	if(dsi_pdata->panel_data.panel_info.pdest == MASTER_DSI_PDEST) {
		pr_debug("%s : Master DSI Ctrl Copy \n", __func__);
		cabc_master_dsi_ctrl = dsi_pdata;
	} else {
		pr_debug("%s : Slave DSI Ctrl Copy \n", __func__);
		cabc_slave_dsi_ctrl = dsi_pdata;
	}

	if (!cabc_tun_state.cabc_enable) {
		pr_info("%s : First Init \n", __func__);
		mutex_init(&cabc_tun_state.cabc_mutex);

		cabc_class = class_create(THIS_MODULE, "tcon");
		if (IS_ERR(cabc_class))
			pr_err("Failed to create class(cabc)!\n");

		/* Using for CABC Key String */
		mdnie_class = class_create(THIS_MODULE, "mdnie");
		if (IS_ERR(mdnie_class))
			pr_err("Failed to create class(mdnie)!\n");

		tune_cabc_dev = device_create(cabc_class, NULL, 0, NULL,
			  "tcon");

		if (IS_ERR(tune_cabc_dev))
			pr_err("Failed to create device(cabc)!\n");

		/* Using for CABC Key String */
		tune_mdnie_dev = device_create(mdnie_class, NULL, 0, NULL,
			  "mdnie");

		if (IS_ERR(tune_mdnie_dev))
			pr_err("Failed to create device(mdnie)!\n");

		if (device_create_file
		    (tune_cabc_dev, &dev_attr_auto_br) < 0)
			pr_err("Failed to create device file(%s)!\n",
		       dev_attr_auto_br.attr.name);

		if (device_create_file
		    (tune_cabc_dev, &dev_attr_lux) < 0)
			pr_err("Failed to create device file(%s)!\n",
		       dev_attr_lux.attr.name);

		if (device_create_file
		    (tune_cabc_dev, &dev_attr_mode) < 0)
			pr_err("Failed to create device file(%s)!\n",
		       dev_attr_mode.attr.name);

		if (device_create_file
		    (tune_cabc_dev,
		     &dev_attr_cetuning) < 0)
			pr_err("Failed to create device file(%s)!\n",
				dev_attr_cetuning.attr.name);

		if (device_create_file
		    (tune_cabc_dev, &dev_attr_cabctuning) < 0)
			pr_err("Failed to create device file(%s)!\n",
				dev_attr_cabctuning.attr.name);

		/* Using for CABC Key String */
		if (device_create_file
		    (tune_mdnie_dev, &dev_attr_cabc) < 0)
			pr_err("Failed to create device file(%s)!\n",
				dev_attr_cabc.attr.name);

		if (device_create_file
		    (tune_mdnie_dev, &dev_attr_accessibility) < 0)
			pr_err("Failed to create device file(%s)!\n",
				dev_attr_cabc.attr.name);

		cabc_tun_state.cabc_enable=1;
	}
}
Example #13
0
File: tty.c Project: AndrewD/prex
/*
 * Register tty device.
 */
device_t
tty_attach(const char *name, struct tty *tp)
{

	return device_create(&tty_io, name, DF_CHR, tp);
}
Example #14
0
static int __init touchkey_init(void)
{
	int ret = 0;
	//int retry = 3;
	//char data[3] = { 0, };


	//gpio_request(_3_TOUCH_SDA_28V, "_3_TOUCH_SDA_28V");
	//gpio_request(_3_TOUCH_SCL_28V, "_3_TOUCH_SCL_28V");
	//gpio_request(_3_GPIO_TOUCH_EN, "_3_GPIO_TOUCH_EN");
	gpio_request(_3_GPIO_TOUCH_INT, "_3_GPIO_TOUCH_INT");

    sec_touchkey= device_create(sec_class, NULL, 0, NULL, "sec_touchkey");
	if (IS_ERR(sec_touchkey))
	{
		printk(KERN_ERR "Failed to create device(sec_touchkey)!\n");
	}
	if (device_create_file(sec_touchkey, &dev_attr_touchkey_firm_update)< 0) {
		printk(KERN_ERR "Failed to create device file(%s)!\n", dev_attr_touchkey_firm_update.attr.name);
	}
	if (device_create_file(sec_touchkey, &dev_attr_touchkey_firm_update_status)< 0)	{
		printk(KERN_ERR "Failed to create device file(%s)!\n", dev_attr_touchkey_firm_update_status.attr.name);
	}
	if (device_create_file(sec_touchkey, &dev_attr_touchkey_firm_version_phone)< 0)	{
		printk(KERN_ERR "Failed to create device file(%s)!\n", dev_attr_touchkey_firm_version_phone.attr.name);
	}
	if (device_create_file(sec_touchkey, &dev_attr_touchkey_firm_version_panel)< 0)	{
		printk(KERN_ERR "Failed to create device file(%s)!\n", dev_attr_touchkey_firm_version_panel.attr.name);
	}
	if (device_create_file(sec_touchkey, &dev_attr_touchkey_autocal_start) < 0) {
		printk(KERN_ERR "Failed to create device file(%s)!\n", dev_attr_touchkey_autocal_start.attr.name);
	}


	ret = misc_register(&touchkey_update_device);
	if (ret) {
		printk(KERN_ERR "[TouchKey] %s misc_register fail\n", __func__);
	}

	/* version, update, brightness, enabledisable */
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touch_version) < 0) {
		printk(KERN_ERR "[TouchKey] %s device_create_file fail dev_attr_touch_version\n", __func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touch_version.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touch_update) < 0) {
		printk(KERN_ERR "[TouchKey] %s device_create_file fail dev_attr_touch_update\n", __func__);
		pr_err("Failed to create device file(%s)!\n",dev_attr_touch_update.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_brightness) < 0) {
		printk(KERN_ERR "[TouchKey] %s device_create_file fail dev_attr_touch_update\n", __func__);
		pr_err("Failed to create device file(%s)!\n",dev_attr_brightness.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_enable_disable) < 0) {
		printk(KERN_ERR"[TouchKey] %s device_create_file fail dev_attr_touch_update\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_enable_disable.attr.name);
	}

	/* menu, home, back, search, sensitivity */
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_menu) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_menu\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_menu.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_back) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_back\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_back.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_home) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_home\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_home.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_search) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_search\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_search.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touch_sensitivity) < 0) {
		printk("%s device_create_file fail dev_attr_touch_sensitivity\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touch_sensitivity.attr.name);
	}

	/* rewdata, idac value x4, threshold */
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_raw_data0) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_raw_data0\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_raw_data0.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_raw_data1) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_raw_data1\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_raw_data1.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_raw_data2) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_raw_data2\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_raw_data2.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_raw_data3) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_raw_data3\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_raw_data3.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_idac0) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_idac0\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_idac0.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_idac1) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_idac1\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_idac1.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_idac2) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_idac2\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_idac2.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_idac3) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_idac3\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_idac3.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touchkey_threshold) < 0) {
		printk(KERN_ERR"%s device_create_file fail dev_attr_touchkey_threshold\n",__func__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touchkey_threshold.attr.name);
	}

	touchkey_wq = create_singlethread_workqueue("melfas_touchkey_wq");
	if (!touchkey_wq) {
		return -ENOMEM;
	}

	INIT_WORK(&touchkey_work, touchkey_work_func);

	init_hw();

	ret = i2c_add_driver(&touchkey_i2c_driver);

	if (ret) {
		printk(KERN_ERR"[TouchKey] melfas touch keypad registration failed, module not inserted.ret= %d\n",ret);
	}
	/* Cypress Firmware Update>>>>>>>>>>
		i2c_touchkey_read(KEYCODE_REG, data, 3);
		printk(KERN_ERR"%s F/W version: 0x%x, Module version:0x%x\n", __FUNCTION__, data[1], data[2]);
		retry = 3;

		touch_version = data[1];
		module_version = data[2];

		// Firmware check & Update
		if((module_version == DOOSUNGTECH_TOUCH_V1_2)&& (touch_version != TOUCH_FIRMWARE_V04)){
			touchkey_update_status=1;
			while (retry--) {
				if (ISSP_main() == 0) {
					printk(KERN_ERR"[TOUCHKEY]Touchkey_update succeeded\n");
					touchkey_update_status=0;
					break;
				}
				printk(KERN_ERR"touchkey_update failed... retry...\n");
		   }
			if (retry <= 0) {
				// disable ldo11
				touchkey_ldo_on(0);
				touchkey_update_status=-1;
				msleep(300);

			}

			init_hw();	//after update, re initalize.
		}else {
			if(module_version != DOOSUNGTECH_TOUCH_V1_2){
				printk(KERN_ERR "[TouchKey] Not F/W update. Cypess touch-key module is not DOOSUNG TECH. \n");
			} else if(touch_version == TOUCH_FIRMWARE_V04){
				printk(KERN_ERR "[TouchKey] Not F/W update. Cypess touch-key F/W version is latest. \n");
			} else {
				printk(KERN_ERR "[TouchKey] Not F/W update. Cypess touch-key version(module or F/W) is not valid. \n");
			}
		}

	 <<<<<<<<<<<<<< Cypress Firmware Update */

	{
		unsigned char get_touch = 0x40;
		i2c_touchkey_write(&get_touch, 1);
	}

	return ret;

}
Example #15
0
static int wacom_i2c_probe(struct i2c_client *client,
			   const struct i2c_device_id *id)
{
	struct wacom_g5_platform_data *pdata = client->dev.platform_data;
	struct wacom_i2c *wac_i2c;
	struct input_dev *input;
	int ret = 0;
#if defined(CONFIG_MACH_T0)
	int digitizer_type = 0;
#endif

	firmware_updating_state = false;

	if (pdata == NULL) {
		printk(KERN_ERR "%s: no pdata\n", __func__);
		ret = -ENODEV;
		goto err_i2c_fail;
	}

	/*Check I2C functionality */
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		printk(KERN_ERR "[E-PEN] No I2C functionality found\n");
		ret = -ENODEV;
		goto err_i2c_fail;
	}

	/*Obtain kernel memory space for wacom i2c */
	wac_i2c = kzalloc(sizeof(struct wacom_i2c), GFP_KERNEL);
	if (NULL == wac_i2c) {
		printk(KERN_ERR "[E-PEN] failed to allocate wac_i2c.\n");
		ret = -ENOMEM;
		goto err_freemem;
	}

	wac_i2c->client_boot = i2c_new_dummy(client->adapter,
		WACOM_I2C_BOOT);
	if (!wac_i2c->client_boot) {
		dev_err(&client->dev, "Fail to register sub client[0x%x]\n",
			 WACOM_I2C_BOOT);
	}

	input = input_allocate_device();
	if (NULL == input) {
		printk(KERN_ERR "[E-PEN] failed to allocate input device.\n");
		ret = -ENOMEM;
		goto err_input_allocate_device;
	} else
		wacom_i2c_set_input_values(client, wac_i2c, input);

	wac_i2c->wac_feature = &wacom_feature_EMR;
	wac_i2c->wac_pdata = pdata;
	wac_i2c->input_dev = input;
	wac_i2c->client = client;
	wac_i2c->irq = client->irq;
#ifdef WACOM_PDCT_WORK_AROUND
	wac_i2c->irq_pdct = gpio_to_irq(pdata->gpio_pendct);
#endif

#ifdef WACOM_PEN_DETECT
	wac_i2c->gpio_pen_insert = pdata->gpio_pen_insert;
#endif

#ifdef WACOM_HAVE_FWE_PIN
	wac_i2c->have_fwe_pin = true;
#ifdef CONFIG_MACH_T0
	if (system_rev < WACOM_FWE1_HWID)
		wac_i2c->have_fwe_pin = false;
#endif
#endif

	/*Change below if irq is needed */
	wac_i2c->irq_flag = 1;

	/*Register callbacks */
	wac_i2c->callbacks.check_prox = wacom_check_emr_prox;
	if (wac_i2c->wac_pdata->register_cb)
		wac_i2c->wac_pdata->register_cb(&wac_i2c->callbacks);

	/* Firmware Feature */
	wacom_i2c_init_firm_data();
#ifdef WACOM_IMPORT_FW_ALGO
	wac_i2c->use_offset_table = true;
	wac_i2c->use_aveTransition = false;
#endif

#if defined(CONFIG_MACH_Q1_BD)
	/* Change Origin offset by rev */
	if (system_rev < 6) {
		origin_offset[0] = origin_offset_48[0];
		origin_offset[1] = origin_offset_48[1];
	}
	/* Reset IC */
	wacom_i2c_reset_hw(wac_i2c->wac_pdata);
#elif defined(CONFIG_MACH_T0)
	wac_i2c->wac_pdata->late_resume_platform_hw();
	msleep(200);

	/*Set data by digitizer type*/
	digitizer_type = wacom_i2c_get_digitizer_type();

	if (digitizer_type == EPEN_DTYPE_B746) {
		printk(KERN_DEBUG"[E-PEN] Use Box filter\n");
		wac_i2c->use_aveTransition = true;
	} else if (digitizer_type == EPEN_DTYPE_B713) {
		printk(KERN_DEBUG"[E-PEN] Reset tilt for B713\n");

		/*Change tuning version for B713*/
		tuning_version = tuning_version_B713;

		memcpy(tilt_offsetX, tilt_offsetX_B713, sizeof(tilt_offsetX));
		memcpy(tilt_offsetY, tilt_offsetY_B713, sizeof(tilt_offsetY));
	} else if (digitizer_type == EPEN_DTYPE_B660) {
		printk(KERN_DEBUG"[E-PEN] Reset tilt and origin for B660\n");

		origin_offset[0] = EPEN_B660_ORG_X;
		origin_offset[1] = EPEN_B660_ORG_Y;
		memset(tilt_offsetX, 0, sizeof(tilt_offsetX));
		memset(tilt_offsetY, 0, sizeof(tilt_offsetY));
		wac_i2c->use_offset_table = false;
	}

	/*Set switch type*/
	wac_i2c->invert_pen_insert = wacom_i2c_invert_by_switch_type();
#elif defined(CONFIG_MACH_KONA)
	wac_i2c->wac_pdata->late_resume_platform_hw();
	msleep(200);
#endif
#ifdef WACOM_PDCT_WORK_AROUND
	wac_i2c->pen_pdct = PDCT_NOSIGNAL;
#endif

#if defined(CONFIG_MACH_P4NOTE)
	wac_i2c->wac_pdata->resume_platform_hw();
	msleep(200);
#endif
	wac_i2c->power_enable = true;

	ret = wacom_i2c_query(wac_i2c);

	if (ret < 0)
		epen_reset_result = false;
	else
		epen_reset_result = true;

#if defined(CONFIG_MACH_P4NOTE)
	input_set_abs_params(input, ABS_X, WACOM_POSX_OFFSET,
			     wac_i2c->wac_feature->x_max, 4, 0);
	input_set_abs_params(input, ABS_Y, WACOM_POSY_OFFSET,
			     wac_i2c->wac_feature->y_max, 4, 0);
	input_set_abs_params(input, ABS_PRESSURE, 0,
			     WACOM_MAX_PRESSURE, 0, 0);
#else
	input_set_abs_params(wac_i2c->input_dev, ABS_X, pdata->min_x,
			     pdata->max_x, 4, 0);
	input_set_abs_params(wac_i2c->input_dev, ABS_Y, pdata->min_y,
			     pdata->max_y, 4, 0);
#ifdef CONFIG_MACH_T0
	input_set_abs_params(wac_i2c->input_dev, ABS_PRESSURE,
			0, wac_i2c->wac_feature->pressure_max, 0, 0);
#else
	input_set_abs_params(wac_i2c->input_dev, ABS_PRESSURE,
			     pdata->min_pressure, pdata->max_pressure, 0, 0);
#endif
#endif
	input_set_drvdata(input, wac_i2c);

	/*Before registering input device, data in each input_dev must be set */
	ret = input_register_device(input);
	if (ret) {
		pr_err("[E-PEN] failed to register input device.\n");
		goto err_register_device;
	}

	/*Change below if irq is needed */
	wac_i2c->irq_flag = 1;

	/*Set client data */
	i2c_set_clientdata(client, wac_i2c);
	i2c_set_clientdata(wac_i2c->client_boot, wac_i2c);

	/*Initializing for semaphor */
	mutex_init(&wac_i2c->lock);
	wake_lock_init(&wac_i2c->wakelock, WAKE_LOCK_SUSPEND, "wacom");
	INIT_DELAYED_WORK(&wac_i2c->resume_work, wacom_i2c_resume_work);
#if defined(WACOM_IRQ_WORK_AROUND)
	INIT_DELAYED_WORK(&wac_i2c->pendct_dwork, wacom_i2c_pendct_work);
#endif
#ifdef WACOM_STATE_CHECK
	INIT_DELAYED_WORK(&wac_i2c->wac_statecheck_work, wac_statecheck_work);
#endif


#ifdef CONFIG_HAS_EARLYSUSPEND
	wac_i2c->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	wac_i2c->early_suspend.suspend = wacom_i2c_early_suspend;
	wac_i2c->early_suspend.resume = wacom_i2c_late_resume;
	register_early_suspend(&wac_i2c->early_suspend);
#endif

	wac_i2c->dev = device_create(sec_class, NULL, 0, NULL, "sec_epen");
	if (IS_ERR(wac_i2c->dev)) {
		printk(KERN_ERR "Failed to create device(wac_i2c->dev)!\n");
		goto err_sysfs_create_group;
	} else {
		dev_set_drvdata(wac_i2c->dev, wac_i2c);
		ret = sysfs_create_group(&wac_i2c->dev->kobj, &epen_attr_group);
		if (ret) {
			printk(KERN_ERR
			       "[E-PEN]: failed to create sysfs group\n");
			goto err_sysfs_create_group;
		}
	}

	/* firmware info */
	printk(KERN_NOTICE "[E-PEN] wacom fw ver : 0x%x, new fw ver : 0x%x\n",
	       wac_i2c->wac_feature->fw_version, Firmware_version_of_file);

#ifdef CONFIG_SEC_TOUCHSCREEN_DVFS_LOCK
	INIT_DELAYED_WORK(&wac_i2c->dvfs_work, free_dvfs_lock);
	if (exynos_cpufreq_get_level(WACOM_DVFS_LOCK_FREQ,
			&wac_i2c->cpufreq_level))
		printk(KERN_ERR "[E-PEN] exynos_cpufreq_get_level Error\n");
#ifdef SEC_BUS_LOCK
	wac_i2c->dvfs_lock_status = false;
#if defined(CONFIG_MACH_P4NOTE) || defined(CONFIG_MACH_KONA)
	wac_i2c->bus_dev = dev_get("exynos-busfreq");
#endif	/* CONFIG_MACH_P4NOTE */
#endif	/* SEC_BUS_LOCK */
#endif	/* CONFIG_SEC_TOUCHSCREEN_DVFS_LOCK */

	/*Request IRQ */
	if (wac_i2c->irq_flag) {
		ret =
		    request_threaded_irq(wac_i2c->irq, NULL, wacom_interrupt,
					 IRQF_DISABLED | IRQF_TRIGGER_RISING |
					 IRQF_ONESHOT, wac_i2c->name, wac_i2c);
		if (ret < 0) {
			printk(KERN_ERR
			       "[E-PEN] failed to request irq(%d) - %d\n",
			       wac_i2c->irq, ret);
			goto err_request_irq;
		}

#if defined(WACOM_PDCT_WORK_AROUND)
		ret =
			request_threaded_irq(wac_i2c->irq_pdct, NULL,
					wacom_interrupt_pdct,
					IRQF_DISABLED | IRQF_TRIGGER_RISING |
					IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
					wac_i2c->name, wac_i2c);
		if (ret < 0) {
			printk(KERN_ERR
				"[E-PEN] failed to request irq(%d) - %d\n",
				wac_i2c->irq_pdct, ret);
			goto err_request_irq;
		}
#endif
	}

#ifdef WACOM_DEBOUNCEINT_BY_ESD
	/*Invert gpio value for  first irq.
	    schedule_delayed_work in wacom_i2c_input_open*/
	pen_insert_state = gpio_get_value(wac_i2c->gpio_pen_insert);
	wac_i2c->pen_insert = pen_insert_state;
#if defined(CONFIG_MACH_T0)
	if (wac_i2c->invert_pen_insert) {
		wac_i2c->pen_insert = !wac_i2c->pen_insert;
		pen_insert_state = wac_i2c->pen_insert;
	}
#endif
#endif

	return 0;

 err_request_irq:
 err_sysfs_create_group:
 err_register_device:
	input_unregister_device(input);
 err_input_allocate_device:
	input_free_device(input);
 err_freemem:
	kfree(wac_i2c);
 err_i2c_fail:
	return ret;
}
Example #16
0
/*
 * create everything concerning the dev interface
 *
 */
static int create_dev_nodes(void)
{
	int err;
	struct device* device;

	dev_t write_num = MKDEV(FIFO_MAJOR, WRITE_END);
	dev_t read_num = MKDEV(FIFO_MAJOR, READ_END);

	cdev_write = cdev_alloc();
	cdev_read = cdev_alloc();

	if (0 == cdev_write || 0 == cdev_read)
	{
		printk(KERN_INFO "--- %s: cdev_alloc failed!\n", mod_name);
		return ENOMEM;
	}

	// get the write dev class
	class_write = class_create(THIS_MODULE, WRITE_NAME);
	if (IS_ERR(class_write))
	{
		destroy_dev_nodes(0, 0);
		return PTR_ERR(class_write);
	}
	class_write->dev_uevent = write_permission;

	// get the read dev class
	class_read = class_create(THIS_MODULE, READ_NAME);
	if (IS_ERR(class_read))
	{
		destroy_dev_nodes(0, 0);
		return PTR_ERR(class_write);
	}
	class_read->dev_uevent = read_permission;

	// initialize structs
	cdev_init(cdev_write, &fifo_write_fops);
	cdev_init(cdev_read, &fifo_read_fops);

	// adds dev to system, makes it live
	err = cdev_add(cdev_write, write_num, 1);
	if (err)
	{
		destroy_dev_nodes(0, 0);
		return err;
	}
	err = cdev_add(cdev_read, read_num, 1);
	if (err)
	{
		destroy_dev_nodes(0, 1);
		return err;
	}

	// add /dev/fifo0
	device = device_create(class_write, 
							0, 				// parent device
							write_num,
							0, 				// additional data
							WRITE_NAME);
	if (IS_ERR(device))
	{
		destroy_dev_nodes(1, 1);
		return PTR_ERR(device);
	}

	// add /dev/fifo1
	device = device_create(class_read, 
							0, 				// parent device
							read_num,
							0, 				// additional data
							READ_NAME);
	if (IS_ERR(device))
	{
		destroy_dev_nodes(1, 2);
		return PTR_ERR(device);
	}

	return 0;
}
Example #17
0
static ssize_t adg739_write(struct file *filp, const char __user *buf, size_t count, loff_t *fpos)
{
	char buf_term[NUM_MULTIPLEXER];	//буфер, куда копируются сообщения из пользовательского пространства, и где они проходят предварительное форматирование
	int status = 0;
	int i =0;
	struct spi_transfer t = {		//формируется передача
			.tx_buf = adg739_status->buffer,
			.len = NUM_MULTIPLEXER * 2,
	};
	struct spi_message	m;	// сообщение
	DECLARE_COMPLETION_ONSTACK(done);	//объявляется и инициализуется условная переменная
	//проверка на достоверность переданного буфера
	if (count > NUM_MULTIPLEXER)
		return (-EMSGSIZE);
	if (copy_from_user(buf_term, buf, count))
		return (-EFAULT);
	for (i=0; i<count; i++)
	{
		switch(buf_term[i])
		{
		case 's':
			buf_term[i] = 0x11;
			break;
		case 'v':
			buf_term[i] = 0x82;
			break;
		case 'g':
			buf_term[i] = 0x88;
			break;
		default:
			return (-EINVAL);
		}
	}
	//передача сообщения драйверу контроллера
	mutex_lock(&device_lockk);
	for (i=0; i<count; i++) {
		adg739_status->buffer[i]= buf_term[i];
		adg739_status->buffer[i+4]= buf_term[i];
	}

	spi_message_init(&m);	//инициализация сообщения
	spi_message_add_tail(&t, &m);	//постановка передачи в очередь сообщения
	m.complete = adg739_complete;
	m.context = &done;
	if (adg739_status->spi == NULL)
		status = -ESHUTDOWN;
	else
	{
		status = spi_async(adg739_status->spi, &m);	//передача сообщения
		printk(KERN_INFO "Status function spi_async = %d\n", status);	
	}
	if (status == 0) {
		wait_for_completion(&done);	//ожидание обработки сообщения контроллером spi
		status = m.status;
		printk(KERN_INFO "Status message = %d\n", status);
		if (status == 0)
			status = m.actual_length/2;
	}
	mutex_unlock(&device_lockk);
	return (status);
}

//ФУНКЦИИ СТРУКТУРЫ SPI_DRIVER

static int	__devinit adg739_probe(struct spi_device *spi)
{
	int status, dev;
	//регистрация устройства
	dev =device_create(devclass, &spi->dev, dev_adg739, NULL, MULTIPLEXER_NAME);	//создание устройства
	status = IS_ERR(dev) ? PTR_ERR(dev) : 0;
	if(status != 0)
	{
		printk(KERN_ERR "The device_create function failed\n");
		return (status);
	}
	//инициализация членов структуры состояния драйвера
	mutex_lock(&device_lockk);
	adg739_status->users = 0;
	adg739_status->spi = spi;
	spi->bits_per_word = 16;
	spi->max_speed_hz = 700000;
	spin_lock_init(&adg739_status->spi_lock);
	memset(adg739_status->buffer, 0, sizeof(adg739_status->buffer));
	spi_set_drvdata(spi, adg739_status);	//присваевает указателю spi->dev->driver_data значение adg739_status
	mutex_unlock(&device_lockk);
	return (0);
}
Example #18
0
static int __devinit goldfish_switch_probe(struct platform_device *pdev)
{
	int ret;
	struct resource *r;
	struct goldfish_switch *qs;
	uint32_t base;
	uint32_t name_len;

	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if(r == NULL) {
		ret = -ENODEV;
		goto err_no_io_base;
	}
	base = IO_ADDRESS(r->start - IO_START);
	name_len = readl(base + SW_NAME_LEN);

	qs = kzalloc(sizeof(*qs) + name_len + 1, GFP_KERNEL);
	if(qs == NULL) {
		ret = -ENOMEM;
		goto err_qs_alloc_failed;
	}
	platform_set_drvdata(pdev, qs);
	qs->base = base;
	r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
	if(r == NULL) {
		ret = -ENODEV;
		goto err_no_irq;
	}
	qs->irq = r->start;

	writel(qs->name, base + SW_NAME_PTR);
	qs->name[name_len] = '\0';
	writel(0, base + SW_INT_ENABLE);

	qs->flags = readl(base + SW_FLAGS);
	qs->state = readl(base + SW_STATE);
	INIT_WORK(&qs->work, goldfish_switch_work);

	qs->cdev = device_create(goldfish_switch_class, &pdev->dev, 0,
						NULL, "%s", qs->name);
	if(unlikely(IS_ERR(qs->cdev))) {
		ret = PTR_ERR(qs->cdev);
		goto err_device_create_failed;
	}
	dev_set_drvdata(qs->cdev, qs);

	ret = device_create_file(qs->cdev, &dev_attr_state);
	if(ret)
		goto err_device_create_file_failed;

	ret = device_create_file(qs->cdev, &dev_attr_direction);
	if(ret)
		goto err_device_create_file_failed;
	
	ret = request_irq(qs->irq, goldfish_switch_interrupt, IRQF_SHARED, "goldfish_switch", qs);
	if(ret)
		goto err_request_irq_failed;
	writel(1, base + SW_INT_ENABLE);

	return 0;


//	free_irq(qs->irq, qs);
err_request_irq_failed:
err_device_create_file_failed:
	device_unregister(qs->cdev);
err_device_create_failed:
err_no_irq:
	kfree(qs);
err_qs_alloc_failed:
err_no_io_base:
	printk("goldfish_switch_probe failed %d\n", ret);
	return ret;
}
Example #19
0
File: pty.c Project: SelfImp/m75
static void __init unix98_pty_init(void)
{
	ptm_driver = tty_alloc_driver(NR_UNIX98_PTY_MAX,
			TTY_DRIVER_RESET_TERMIOS |
			TTY_DRIVER_REAL_RAW |
			TTY_DRIVER_DYNAMIC_DEV |
			TTY_DRIVER_DEVPTS_MEM |
			TTY_DRIVER_DYNAMIC_ALLOC);
	if (IS_ERR(ptm_driver))
		panic("Couldn't allocate Unix98 ptm driver");
	pts_driver = tty_alloc_driver(NR_UNIX98_PTY_MAX,
			TTY_DRIVER_RESET_TERMIOS |
			TTY_DRIVER_REAL_RAW |
			TTY_DRIVER_DYNAMIC_DEV |
			TTY_DRIVER_DEVPTS_MEM |
			TTY_DRIVER_DYNAMIC_ALLOC);
	if (IS_ERR(pts_driver))
		panic("Couldn't allocate Unix98 pts driver");

	ptm_driver->owner = THIS_MODULE;
	ptm_driver->driver_name = "pty_master";
	ptm_driver->name = "ptm";
	ptm_driver->major = UNIX98_PTY_MASTER_MAJOR;
	ptm_driver->minor_start = 0;
	ptm_driver->type = TTY_DRIVER_TYPE_PTY;
	ptm_driver->subtype = PTY_TYPE_MASTER;
	ptm_driver->init_termios = tty_std_termios;
	ptm_driver->init_termios.c_iflag = 0;
	ptm_driver->init_termios.c_oflag = 0;
	ptm_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
	ptm_driver->init_termios.c_lflag = 0;
	ptm_driver->init_termios.c_ispeed = 38400;
	ptm_driver->init_termios.c_ospeed = 38400;
	ptm_driver->other = pts_driver;
	tty_set_operations(ptm_driver, &ptm_unix98_ops);

	pts_driver->owner = THIS_MODULE;
	pts_driver->driver_name = "pty_slave";
	pts_driver->name = "pts";
	pts_driver->major = UNIX98_PTY_SLAVE_MAJOR;
	pts_driver->minor_start = 0;
	pts_driver->type = TTY_DRIVER_TYPE_PTY;
	pts_driver->subtype = PTY_TYPE_SLAVE;
	pts_driver->init_termios = tty_std_termios;
	pts_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
	pts_driver->init_termios.c_ispeed = 38400;
	pts_driver->init_termios.c_ospeed = 38400;
	pts_driver->other = ptm_driver;
	tty_set_operations(pts_driver, &pty_unix98_ops);

	if (tty_register_driver(ptm_driver))
		panic("Couldn't register Unix98 ptm driver");
	if (tty_register_driver(pts_driver))
		panic("Couldn't register Unix98 pts driver");

	/* Now create the /dev/ptmx special device */
	tty_default_fops(&ptmx_fops);
	ptmx_fops.open = ptmx_open;

	cdev_init(&ptmx_cdev, &ptmx_fops);
	if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
		panic("Couldn't register /dev/ptmx driver");
	device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
}
Example #20
0
int rmnet_usb_ctrl_init(void)
{
	struct rmnet_ctrl_dev	*dev;
	int			n;
	int			status;

	for (n = 0; n < NUM_CTRL_CHANNELS; ++n) {

		dev = kzalloc(sizeof(*dev), GFP_KERNEL);
		if (!dev) {
			status = -ENOMEM;
			goto error0;
		}
		/*for debug purpose*/
		snprintf(dev->name, CTRL_DEV_MAX_LEN, "hsicctl%d", n);

		mutex_init(&dev->dev_lock);
		spin_lock_init(&dev->rx_lock);
		init_waitqueue_head(&dev->read_wait_queue);
		init_waitqueue_head(&dev->open_wait_queue);
		INIT_LIST_HEAD(&dev->rx_list);
		init_usb_anchor(&dev->tx_submitted);

		status = rmnet_usb_ctrl_alloc_rx(dev);
		if (status < 0) {
			kfree(dev);
			goto error0;
		}

		ctrl_dev[n] = dev;
	}

	status = alloc_chrdev_region(&ctrldev_num, 0, NUM_CTRL_CHANNELS,
			DEVICE_NAME);
	if (IS_ERR_VALUE(status)) {
		pr_err("ERROR:%s: alloc_chrdev_region() ret %i.\n",
		       __func__, status);
		goto error0;
	}

	ctrldev_classp = class_create(THIS_MODULE, DEVICE_NAME);
	if (IS_ERR(ctrldev_classp)) {
		pr_err("ERROR:%s: class_create() ENOMEM\n", __func__);
		status = -ENOMEM;
		goto error1;
	}
	for (n = 0; n < NUM_CTRL_CHANNELS; ++n) {
		cdev_init(&ctrl_dev[n]->cdev, &ctrldev_fops);
		ctrl_dev[n]->cdev.owner = THIS_MODULE;

		status = cdev_add(&ctrl_dev[n]->cdev, (ctrldev_num + n), 1);

		if (IS_ERR_VALUE(status)) {
			pr_err("%s: cdev_add() ret %i\n", __func__, status);
			kfree(ctrl_dev[n]);
			goto error2;
		}

		ctrl_dev[n]->devicep =
				device_create(ctrldev_classp, NULL,
				(ctrldev_num + n), NULL,
				DEVICE_NAME "%d", n);

		if (IS_ERR(ctrl_dev[n]->devicep)) {
			pr_err("%s: device_create() ENOMEM\n", __func__);
			status = -ENOMEM;
			cdev_del(&ctrl_dev[n]->cdev);
			kfree(ctrl_dev[n]);
			goto error2;
		}
		/*create /sys/class/hsicctl/hsicctlx/modem_wait*/
		status = device_create_file(ctrl_dev[n]->devicep,
					&dev_attr_modem_wait);
		if (status) {
			device_destroy(ctrldev_classp,
				MKDEV(MAJOR(ctrldev_num), n));
			cdev_del(&ctrl_dev[n]->cdev);
			kfree(ctrl_dev[n]);
			goto error2;
		}
		dev_set_drvdata(ctrl_dev[n]->devicep, ctrl_dev[n]);
	}

	rmnet_usb_ctrl_debugfs_init();
	pr_info("rmnet usb ctrl Initialized.\n");
	return 0;

error2:
		while (--n >= 0) {
			cdev_del(&ctrl_dev[n]->cdev);
			device_destroy(ctrldev_classp,
				MKDEV(MAJOR(ctrldev_num), n));
		}

		class_destroy(ctrldev_classp);
		n = NUM_CTRL_CHANNELS;
error1:
	unregister_chrdev_region(MAJOR(ctrldev_num), NUM_CTRL_CHANNELS);
error0:
	while (--n >= 0)
		kfree(ctrl_dev[n]);

	return status;
}
Example #21
0
struct c2port_device *c2port_device_register(char *name,
					struct c2port_ops *ops, void *devdata)
{
	struct c2port_device *c2dev;
	int id, ret;

	if (unlikely(!ops) || unlikely(!ops->access) || \
		unlikely(!ops->c2d_dir) || unlikely(!ops->c2ck_set) || \
		unlikely(!ops->c2d_get) || unlikely(!ops->c2d_set))
		return ERR_PTR(-EINVAL);

	c2dev = kmalloc(sizeof(struct c2port_device), GFP_KERNEL);
	kmemcheck_annotate_bitfield(c2dev, flags);
	if (unlikely(!c2dev))
		return ERR_PTR(-ENOMEM);

	ret = idr_pre_get(&c2port_idr, GFP_KERNEL);
	if (!ret) {
		ret = -ENOMEM;
		goto error_idr_get_new;
	}

	spin_lock_irq(&c2port_idr_lock);
	ret = idr_get_new(&c2port_idr, c2dev, &id);
	spin_unlock_irq(&c2port_idr_lock);

	if (ret < 0)
		goto error_idr_get_new;
	c2dev->id = id;

	c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
					"c2port%d", id);
	if (unlikely(!c2dev->dev)) {
		ret = -ENOMEM;
		goto error_device_create;
	}
	dev_set_drvdata(c2dev->dev, c2dev);

	strncpy(c2dev->name, name, C2PORT_NAME_LEN);
	c2dev->ops = ops;
	mutex_init(&c2dev->mutex);

	/* Create binary file */
	c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
	ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
	if (unlikely(ret))
		goto error_device_create_bin_file;

	/* By default C2 port access is off */
	c2dev->access = c2dev->flash_access = 0;
	ops->access(c2dev, 0);

	dev_info(c2dev->dev, "C2 port %s added\n", name);
	dev_info(c2dev->dev, "%s flash has %d blocks x %d bytes "
				"(%d bytes total)\n",
				name, ops->blocks_num, ops->block_size,
				ops->blocks_num * ops->block_size);

	return c2dev;

error_device_create_bin_file:
	device_destroy(c2port_class, 0);

error_device_create:
	spin_lock_irq(&c2port_idr_lock);
	idr_remove(&c2port_idr, id);
	spin_unlock_irq(&c2port_idr_lock);

error_idr_get_new:
	kfree(c2dev);

	return ERR_PTR(ret);
}
/**
 * platform driver
 *
 */
static int __devinit dsps_probe(struct platform_device *pdev)
{
	int ret;

	pr_debug("%s.\n", __func__);

	if (pdev->dev.platform_data == NULL) {
		pr_err("%s: platform data is NULL.\n", __func__);
		return -ENODEV;
	}

	drv = kzalloc(sizeof(*drv), GFP_KERNEL);
	if (drv == NULL) {
		pr_err("%s: kzalloc fail.\n", __func__);
		goto alloc_err;
	}
	drv->pdata = pdev->dev.platform_data;

	drv->dev_class = class_create(THIS_MODULE, DRV_NAME);
	if (drv->dev_class == NULL) {
		pr_err("%s: class_create fail.\n", __func__);
		goto res_err;
	}

	ret = alloc_chrdev_region(&drv->dev_num, 0, 1, DRV_NAME);
	if (ret) {
		pr_err("%s: alloc_chrdev_region fail.\n", __func__);
		goto alloc_chrdev_region_err;
	}

	drv->dev = device_create(drv->dev_class, NULL,
				     drv->dev_num,
				     drv, DRV_NAME);
	if (IS_ERR(drv->dev)) {
		pr_err("%s: device_create fail.\n", __func__);
		goto device_create_err;
	}

	drv->cdev = cdev_alloc();
	if (drv->cdev == NULL) {
		pr_err("%s: cdev_alloc fail.\n", __func__);
		goto cdev_alloc_err;
	}
	cdev_init(drv->cdev, &dsps_fops);
	drv->cdev->owner = THIS_MODULE;

	ret = cdev_add(drv->cdev, drv->dev_num, 1);
	if (ret) {
		pr_err("%s: cdev_add fail.\n", __func__);
		goto cdev_add_err;
	}

	ret = dsps_alloc_resources(pdev);
	if (ret) {
		pr_err("%s: failed to allocate dsps resources.\n", __func__);
		goto cdev_add_err;
	}

	ret =
	    smsm_state_cb_register(SMSM_DSPS_STATE, SMSM_RESET,
				   dsps_smsm_state_cb, 0);
	if (ret) {
		pr_err("%s: smsm_state_cb_register fail %d\n", __func__,
		       ret);
		goto smsm_register_err;
	}

	ret = ssr_register_subsystem(&dsps_ssrops);
	if (ret) {
		pr_err("%s: ssr_register_subsystem fail %d\n", __func__,
		       ret);
		goto ssr_register_err;
	}

	return 0;

ssr_register_err:
	smsm_state_cb_deregister(SMSM_DSPS_STATE, SMSM_RESET,
				 dsps_smsm_state_cb,
				 0);
smsm_register_err:
	cdev_del(drv->cdev);
cdev_add_err:
	kfree(drv->cdev);
cdev_alloc_err:
	device_destroy(drv->dev_class, drv->dev_num);
device_create_err:
	unregister_chrdev_region(drv->dev_num, 1);
alloc_chrdev_region_err:
	class_destroy(drv->dev_class);
res_err:
	kfree(drv);
	drv = NULL;
alloc_err:
	return -ENODEV;
}
static int __init sunxi_pwm_init(void) 
{ 
	int init_enable, init_duty_percent, init_period;
	struct sun4i_pwm_available_channel *chan;
	int err = 0;

	pwm_setup_available_channels(); 

	//PWM 0
	//printk("pwm-sunxi: configuring pwm0...\n");
	chan = &pwm_available_chan[0];
 	
	init_enable=0;
	init_period=0;
	init_duty_percent=100;

	err = script_parser_fetch("pwm0_para", "pwm_used", &init_enable,sizeof(init_enable)/sizeof(int));
	if (err == 0 && init_enable) {
		sunxi_pwm_register_class();
		pwm0 = device_create(&pwm_class, NULL,
				MKDEV(0, 0), &pwm_available_chan[0], "pwm0");
		err = sysfs_create_group(&pwm0->kobj, &pwm_attr_group);
		if (err)
			pr_err("pwm-sunxi: sysfs_create_group(pwm0) err %d\n",
			       err);

		err = script_parser_fetch("pwm0_para", "pwm_period", &init_period,sizeof(init_period)/sizeof(int));
		if (err) {
			pr_err("%s script_parser_fetch '[pwm0_para]' 'pwm_period' err - using 10000\n",	__func__);
			init_period=10000;
		}

		err = script_parser_fetch("pwm0_para", "pwm_duty_percent", &init_duty_percent,sizeof(init_duty_percent)/sizeof(int));
		if (err) {
			pr_err("%s script_parser_fetch '[pwm0_para]' 'pwm_duty_percent' err - using 100\n",	__func__);
			init_duty_percent=100;
		}

		chan->duty_percent=init_duty_percent;
		chan->period = init_period; 
		chan->prescale = pwm_get_best_prescale(init_period); 
		fixup_duty(chan); 
#ifdef SUNXI_PWM_DEBUG
		printk("pwm-sunxi: pwm0 set initial values\n");
#endif
		pwm_set_mode(init_enable,chan); 
		printk("pwm-sunxi: pwm0 configured - period: %ld, duty_percent: %d, duty: %ld\n",
			chan->period, chan->duty_percent, chan->duty);
	}

	if (sunxi_is_sun5i()) /* Only 1 pwm on the A13 / A10s */
		return 0;

	//PWM 1
	//printk("pwm-sunxi: configuring pwm1...\n");
	chan = &pwm_available_chan[1];
 	
	init_enable=0;
	init_period=0;
	init_duty_percent=100;

	err = script_parser_fetch("pwm1_para", "pwm_used", &init_enable,sizeof(init_enable)/sizeof(int));
	if (err == 0 && init_enable) {
		sunxi_pwm_register_class();
		pwm1 = device_create(&pwm_class, NULL,
				MKDEV(0, 0), &pwm_available_chan[1], "pwm1");
		err = sysfs_create_group(&pwm1->kobj, &pwm_attr_group);
		if (err)
			pr_err("pwm-sunxi: sysfs_create_group(pwm1) err %d\n",
			       err);

		err = script_parser_fetch("pwm1_para", "pwm_period", &init_period,sizeof(init_period)/sizeof(int));
		if (err) {
			pr_err("%s script_parser_fetch '[pwm1_para]' 'pwm_period' err - using 10000\n",	__func__);
			init_period=10000;
		}

		err = script_parser_fetch("pwm1_para", "pwm_duty_percent", &init_duty_percent,sizeof(init_duty_percent)/sizeof(int));
		if (err) {
			pr_err("%s script_parser_fetch '[pwm1_para]' 'pwm_duty_percent' err - using 100\n",	__func__);
			init_duty_percent=100;
		}

		chan->duty_percent=init_duty_percent;
		chan->period = init_period; 
		chan->prescale = pwm_get_best_prescale(init_period); 
		fixup_duty(chan); 
#ifdef SUNXI_PWM_DEBUG
		printk("pwm-sunxi: pwm0 set initial values\n");
#endif
		pwm_set_mode(init_enable,chan); 
		printk("pwm-sunxi: pwm1 configured - period: %ld, duty_percent: %d, duty: %ld\n",
			chan->period, chan->duty_percent, chan->duty);
	}
	return 0;
} 
Example #24
0
struct tape_class_device *register_tape_dev(
	struct device *		device,
	dev_t			dev,
	const struct file_operations *fops,
	char *			device_name,
	char *			mode_name)
{
	struct tape_class_device *	tcd;
	int		rc;
	char *		s;

	tcd = kzalloc(sizeof(struct tape_class_device), GFP_KERNEL);
	if (!tcd)
		return ERR_PTR(-ENOMEM);

	strncpy(tcd->device_name, device_name, TAPECLASS_NAME_LEN);
	for (s = strchr(tcd->device_name, '/'); s; s = strchr(s, '/'))
		*s = '!';
	strncpy(tcd->mode_name, mode_name, TAPECLASS_NAME_LEN);
	for (s = strchr(tcd->mode_name, '/'); s; s = strchr(s, '/'))
		*s = '!';

	tcd->char_device = cdev_alloc();
	if (!tcd->char_device) {
		rc = -ENOMEM;
		goto fail_with_tcd;
	}

	tcd->char_device->owner = fops->owner;
	tcd->char_device->ops   = fops;
	tcd->char_device->dev   = dev;

	rc = cdev_add(tcd->char_device, tcd->char_device->dev, 1);
	if (rc)
		goto fail_with_cdev;

	tcd->class_device = device_create(tape_class, device,
					  tcd->char_device->dev, NULL,
					  "%s", tcd->device_name);
	rc = IS_ERR(tcd->class_device) ? PTR_ERR(tcd->class_device) : 0;
	if (rc)
		goto fail_with_cdev;
	rc = sysfs_create_link(
		&device->kobj,
		&tcd->class_device->kobj,
		tcd->mode_name
	);
	if (rc)
		goto fail_with_class_device;

	return tcd;

fail_with_class_device:
	device_destroy(tape_class, tcd->char_device->dev);

fail_with_cdev:
	cdev_del(tcd->char_device);

fail_with_tcd:
	kfree(tcd);

	return ERR_PTR(rc);
}
Example #25
0
static int __devinit an30259a_probe(struct i2c_client *client,
	const struct i2c_device_id *id)
{
	struct an30259a_data *data;
	int ret, i;

	dev_dbg(&client->adapter->dev, "%s\n", __func__);
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		dev_err(&client->dev, "need I2C_FUNC_I2C.\n");
		return -ENODEV;
	}

	data = kzalloc(sizeof(*data), GFP_KERNEL);
	if (!data) {
		dev_err(&client->adapter->dev,
			"failed to allocate driver data.\n");
		return -ENOMEM;
	}

	i2c_set_clientdata(client, data);
	data->client = client;
	b_client = client;

	mutex_init(&data->mutex);
	/* initialize LED */
	for (i = 0; i < MAX_NUM_LEDS; i++) {

		ret = an30259a_initialize(client, &data->leds[i], i);

		if (ret < 0) {
			dev_err(&client->adapter->dev, "failure on initialization\n");
			goto exit;
		}
		INIT_WORK(&(data->leds[i].brightness_work),
				 an30259a_led_brightness_work);
	}

#ifdef SEC_LED_SPECIFIC
	led_enable_fade = 0;  /* default to stock behaviour = blink */
//	led_intensity =  0;   /* default to CM behaviour = brighter blink intensity allowed */
	led_intensity = 40;   /* default to Samsung behaviour = normal intensity */
	led_speed = 1;        /* default to stock behaviour = normal blinking/fading speed */
	led_slope_up_1 = 1;   /* default slope durations for fading */
	led_slope_up_2 = 1;
	led_slope_down_1 = 1;
	led_slope_down_2 = 1;
	
	led_dev = device_create(sec_class, NULL, 0, data, "led");
	if (IS_ERR(led_dev)) {
		dev_err(&client->dev,
			"Failed to create device for samsung specific led\n");
		ret = -ENODEV;
		goto exit;
	}
	ret = sysfs_create_group(&led_dev->kobj, &sec_led_attr_group);
	if (ret) {
		dev_err(&client->dev,
			"Failed to create sysfs group for samsung specific led\n");
		goto exit;
	}
#endif
	return ret;
exit:
	mutex_destroy(&data->mutex);
	kfree(data);
	return ret;
}
static int gp2a_opt_probe(struct platform_device *pdev)
{
	struct gp2a_data *gp2a;
	struct gp2a_platform_data *pdata = pdev->dev.platform_data;
	u8 value = 0;
	int err = 0;

	printk(KERN_INFO"[GP2A] %s : probe start!\n", __func__);

	if (!pdata) {
		pr_err("%s: missing pdata!\n", __func__);
		return err;
	}

        /*PROXY_EN*/
	if (gpio_request(pdata ->power_gpio, "PROXY_EN")) {
		printk(KERN_ERR "Request GPIO_%d failed!\n", pdata ->power_gpio);
	}

	if (pdata->gp2a_led_on)
		pdata->gp2a_led_on(1);

#ifndef CONFIG_MACH_HENNESSY_DUOS_CTC
	if (pdata->gp2a_get_threshold) {
		gp2a_update_threshold(pdata->gp2a_get_threshold(), false);
	}
#endif
	/* allocate driver_data */
	gp2a = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL);
	if (!gp2a) {
		pr_err("kzalloc error\n");
		return -ENOMEM;
	}

	gp2a->proximity_enabled = 0;
	gp2a->pdata = pdata;

	gp2a->light_enabled = 0;
	gp2a->light_delay = SENSOR_DEFAULT_DELAY;
	gp2a->testmode = 0;
	gp2a->light_level_state = 0;

	if (pdata->power_on) {
		pdata->power_on(1);
        	msleep(5);
	}

	INIT_DELAYED_WORK(&gp2a->light_work, gp2a_work_func_light);
	INIT_WORK(&gp2a->proximity_work, gp2a_work_func_prox);

	/*misc device registration*/
        err = misc_register(&gp2a_opt_misc_device);
	if( err < 0 )
		goto error_setup_reg_misc;

	err = proximity_input_init(gp2a);
	if (err < 0)
		goto error_setup_reg_prox;

	err = light_input_init(gp2a);
	if (err < 0)
		goto error_setup_reg_light;

	err = sysfs_create_group(&gp2a->proximity_input_dev->dev.kobj,
				 &proximity_attribute_group);
	if (err < 0)
		goto err_sysfs_create_group_proximity;

	err = sysfs_create_group(&gp2a->light_input_dev->dev.kobj,
				&lightsensor_attribute_group);
	if (err)
		goto err_sysfs_create_group_light;

	mutex_init(&gp2a->light_mutex);
	mutex_init(&gp2a->data_mutex);

	/* set platdata */
	platform_set_drvdata(pdev, gp2a);

	/* wake lock init */
	wake_lock_init(&gp2a->prx_wake_lock, WAKE_LOCK_SUSPEND,
		"prx_wake_lock");

	/* init i2c */
	err = opt_i2c_init();
	if(err < 0)
	{
		pr_err("opt_probe failed : i2c_client is NULL\n"); 
		goto err_no_device;        
	}
	else
		printk(KERN_INFO "[GP2A] opt_i2c_client : (0x%p)\n",opt_i2c_client);
	
	/* GP2A Regs INIT SETTINGS  and Check I2C communication */

	value = 0x00;
	err = opt_i2c_write((u8) (COMMAND1), &value);	/* shutdown mode op[3]=0 */
	if (err < 0) {
		pr_err("%s failed : threre is no such device.\n", __func__);
		goto err_no_device;
	}

	/* Setup irq */
	err = gp2a_setup_irq(gp2a);
	if (err) {
		pr_err("%s: could not setup irq\n", __func__);
		goto err_setup_irq;
	}

	/* set sysfs for proximity sensor */
	gp2a->proximity_dev = device_create(sensors_class,
					    NULL, 0, NULL, "proximity_sensor");
	if (IS_ERR(gp2a->proximity_dev)) {
		pr_err("%s: could not create proximity_dev\n", __func__);
		goto err_proximity_device_create;
	}

	gp2a->light_dev = device_create(sensors_class,
					NULL, 0, NULL, "light_sensor");
	if (IS_ERR(gp2a->light_dev)) {
		pr_err("%s: could not create light_dev\n", __func__);
		goto err_light_device_create;
	}


	if (device_create_file(gp2a->proximity_dev,
		&dev_attr_state) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
		       dev_attr_state.attr.name);
		goto err_proximity_device_create_file1;
	}

	if (device_create_file(gp2a->proximity_dev,
		&dev_attr_prox_avg) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
		       dev_attr_prox_avg.attr.name);
		goto err_proximity_device_create_file2;
	}

	if (device_create_file(gp2a->proximity_dev,
		&dev_attr_proximity_enable) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
		       dev_attr_proximity_enable.attr.name);
		goto err_proximity_device_create_file3;
	}

	if (device_create_file(gp2a->proximity_dev,
		&dev_attr_vendor) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
		       dev_attr_vendor.attr.name);
		goto err_proximity_device_create_file4;
	}

	if (device_create_file(gp2a->proximity_dev,
		&dev_attr_name) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
		       dev_attr_name.attr.name);
		goto err_proximity_device_create_file5;
	}

	if (device_create_file(gp2a->proximity_dev,
		&dev_attr_prox_cal) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
			dev_attr_prox_cal.attr.name);
		goto err_proximity_device_create_file6;
	}

	if (device_create_file(gp2a->proximity_dev,
		&dev_attr_prox_offset_pass) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
			dev_attr_prox_offset_pass.attr.name);
		goto err_proximity_device_create_file7;
	}

	if (device_create_file(gp2a->proximity_dev,
		&dev_attr_prox_thresh) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
			dev_attr_prox_thresh.attr.name);
		goto err_proximity_device_create_file8;
	}
   
	if (device_create_file(gp2a->light_dev,
		&dev_attr_lux) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
		       dev_attr_lux.attr.name);
		goto err_light_device_create_file1;
	}

	if (device_create_file(gp2a->light_dev,
		&dev_attr_light_enable) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
		       dev_attr_light_enable.attr.name);
		goto err_light_device_create_file2;
	}

	if (device_create_file(gp2a->light_dev,
		&dev_attr_vendor) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
		       dev_attr_vendor.attr.name);
		goto err_light_device_create_file3;
	}

	if (device_create_file(gp2a->light_dev,
		&dev_attr_name) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
		       dev_attr_name.attr.name);
		goto err_light_device_create_file4;
	}

	if (device_create_file(gp2a->light_dev,
		&dev_attr_raw_data) < 0) {
		pr_err("%s: could not create device file(%s)!\n", __func__,
		       dev_attr_raw_data.attr.name);
		goto err_light_device_create_file5;
	}

	dev_set_drvdata(gp2a->proximity_dev, gp2a);
	dev_set_drvdata(gp2a->light_dev, gp2a);

	device_init_wakeup(&pdev->dev, 1);

	if (pdata->gp2a_led_on) {       
            pdata->gp2a_led_on(0);   
            printk(KERN_INFO "[GP2A] gpio_get_value of GPIO(%d) is %d\n",pdata ->power_gpio, 
                gpio_get_value(pdata ->power_gpio));
	}

	/* set initial proximity value as 1 */
	input_report_abs(gp2a->proximity_input_dev, ABS_DISTANCE, 1);
	input_sync(gp2a->proximity_input_dev);

        gp2a_opt_data = gp2a;
        
	printk(KERN_INFO"[GP2A] %s : probe success!\n", __func__);

	return 0;

err_light_device_create_file5:
	device_remove_file(gp2a->light_dev, &dev_attr_name);
err_light_device_create_file4:
	device_remove_file(gp2a->light_dev, &dev_attr_vendor);
err_light_device_create_file3:
	device_remove_file(gp2a->light_dev, &dev_attr_light_enable);
err_light_device_create_file2:
	device_remove_file(gp2a->light_dev, &dev_attr_lux);
err_light_device_create_file1:
	device_remove_file(gp2a->proximity_dev, &dev_attr_prox_thresh);
err_proximity_device_create_file8:
	device_remove_file(gp2a->proximity_dev, &dev_attr_prox_offset_pass);
err_proximity_device_create_file7:
	device_remove_file(gp2a->proximity_dev, &dev_attr_prox_cal);
err_proximity_device_create_file6:
	device_remove_file(gp2a->proximity_dev, &dev_attr_name);
err_proximity_device_create_file5:
	device_remove_file(gp2a->proximity_dev, &dev_attr_vendor);
err_proximity_device_create_file4:
	device_remove_file(gp2a->proximity_dev, &dev_attr_proximity_enable);
err_proximity_device_create_file3:
	device_remove_file(gp2a->proximity_dev, &dev_attr_prox_avg);
err_proximity_device_create_file2:
	device_remove_file(gp2a->proximity_dev, &dev_attr_state);
err_proximity_device_create_file1:
err_light_device_create:
	device_destroy(sensors_class, 0);
err_proximity_device_create:
	gpio_free(pdata->p_out);
err_setup_irq:
err_no_device:
	wake_lock_destroy(&gp2a->prx_wake_lock);
	mutex_destroy(&gp2a->light_mutex);
	mutex_destroy(&gp2a->data_mutex);
	sysfs_remove_group(&gp2a->light_input_dev->dev.kobj,
			   &lightsensor_attribute_group);
err_sysfs_create_group_light:
	sysfs_remove_group(&gp2a->proximity_input_dev->dev.kobj,
			   &proximity_attribute_group);
err_sysfs_create_group_proximity:
	input_unregister_device(gp2a->light_input_dev);
error_setup_reg_light:
	input_unregister_device(gp2a->proximity_input_dev);
error_setup_reg_prox:
	misc_deregister(&gp2a_opt_misc_device);    
error_setup_reg_misc:
	if (pdata->power_on)
		pdata->power_on(0);
	kfree(gp2a);
	return err;
}
Example #27
0
/**************************************************************************
 *  SEC DRIVER INIT
 **************************************************************************/ 
static int sec_init(struct platform_device * dev)
{
    int ret = 0;
    dev_t id;    

    printk( "[%s] sec_init (%d)\n", SEC_DEV_NAME, ret);

    hacc_base = of_iomap(dev->dev.of_node, 0);
    if (!hacc_base) {
        printk(KERN_ERR "[%s] HACC register remapping failed\n", SEC_DEV_NAME);
        return -ENXIO;
    }

    id = MKDEV(SEC_MAJOR, 0);    
    ret = register_chrdev_region(id, 1, SEC_DEV_NAME);

    if (ret) 
    {
        printk(KERN_ERR "[%s] Regist Failed (%d)\n", SEC_DEV_NAME, ret);
	return ret;
    }

    sec_class = class_create(THIS_MODULE, SEC_DEV_NAME);
    if (NULL == sec_class)
    {
	printk(KERN_ERR "[%s] Create class failed(0x%x)\n", SEC_DEV_NAME, ret);
	ret = -1;
	return ret;
    }

    cdev_init(&sec_dev, &sec_fops);
    sec_dev.owner = THIS_MODULE;

    ret = cdev_add(&sec_dev, id, 1);
    if (ret < 0)
    {
        goto exit;
    }

    sec_device = device_create(sec_class, NULL, id, NULL, SEC_DEV_NAME);
    if (NULL == sec_class)
    {
	printk(KERN_ERR "[%s] Create device failed(0x%x)\n", SEC_DEV_NAME, ret);
	class_destroy(sec_class);
	ret = -1;
	return ret;
    }

    sec.id   = id;
    sec.init = 1;
    spin_lock_init(&sec.lock);

    proc_create("rid", 0, NULL, &sec_proc_rid_fops);

#ifdef MTK_SECURITY_MODULE_LITE
    printk("[MASP Lite] version '%s%s', enter.\n",BUILD_TIME,BUILD_BRANCH);
#endif

exit:
    if (ret != 0) 
    {
    	device_destroy(sec_class, id);
    	class_destroy(sec_class);
        unregister_chrdev_region(id, 1);
        memset(&sec, 0, sizeof(sec));
    }

    return ret;
}
Example #28
0
static int __devinit bh1721fvc_probe(struct i2c_client *client,
					const struct i2c_device_id *id)
{
	int err = 0;
	struct bh1721fvc_data *bh1721fvc;
	struct input_dev *input_dev;
	struct bh1721fvc_platform_data *pdata = client->dev.platform_data;
	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);

	if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
		return -EIO;

	bh1721fvc = kzalloc(sizeof(*bh1721fvc), GFP_KERNEL);
	if (!bh1721fvc) {
		pr_err("%s, failed to alloc memory for module data\n",
			__func__);
		return -ENOMEM;
	}

	bh1721fvc->reset = pdata->reset;
	if (!bh1721fvc->reset) {
		pr_err("%s: reset callback is null\n", __func__);
		err = -EIO;
		goto err_reset_null;
	}

	err = bh1721fvc->reset();
	if (err) {
		pr_err("%s: Failed to reset\n", __func__);
		goto err_reset_failed;
	}

	bh1721fvc->client = client;
	i2c_set_clientdata(client, bh1721fvc);

	mutex_init(&bh1721fvc->lock);
	bh1721fvc->state = POWER_DOWN;
	bh1721fvc->measure_mode = AUTO_MEASURE;

	err = bh1721fvc_test_luxvalue(bh1721fvc);
	if (err < 0) {
		pr_err("%s: No search bh1721fvc lightsensor!\n", __func__);
		goto err_test_lightsensor;
	} else {
		printk(KERN_ERR"Lux : %d\n", err);
	}

	hrtimer_init(&bh1721fvc->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);

	bh1721fvc->light_poll_delay = ns_to_ktime(200 * NSEC_PER_MSEC);
	bh1721fvc->timer.function = bh1721fvc_timer_func;

	bh1721fvc->wq = alloc_workqueue("bh1721fvc_wq",
		WQ_UNBOUND | WQ_RESCUER, 1);
	if (!bh1721fvc->wq) {
		err = -ENOMEM;
		pr_err("%s: could not create workqueue\n", __func__);
		goto err_create_workqueue;
	}

	INIT_WORK(&bh1721fvc->work_light, bh1721fvc_work_func_light);

	input_dev = input_allocate_device();
	if (!input_dev) {
		pr_err("%s: could not allocate input device\n", __func__);
		err = -ENOMEM;
		goto err_input_allocate_device_light;
	}
	input_set_drvdata(input_dev, bh1721fvc);
	input_dev->name = "light_sensor";
	input_set_capability(input_dev, EV_ABS, ABS_MISC);
	input_set_abs_params(input_dev, ABS_MISC,
		LUX_MIN_VALUE, LUX_MAX_VALUE, 0, 0);
	bh1721fvc_dbmsg("registering lightsensor-level input device\n");
	err = input_register_device(input_dev);
	if (err < 0) {
		pr_err("%s: could not register input device\n", __func__);
		input_free_device(input_dev);
		goto err_input_register_device_light;
	}
	bh1721fvc->input_dev = input_dev;
	err = sysfs_create_group(&input_dev->dev.kobj,
		&bh1721fvc_attribute_group);
	if (err) {
		pr_err("%s: could not create sysfs group\n", __func__);
		goto err_sysfs_create_group_light;
	}

	bh1721fvc->factory_class = class_create(THIS_MODULE, "lightsensor");

	if (IS_ERR(bh1721fvc->factory_class)) {
		pr_err("Failed to create class(lightsensor)!\n");
		err = PTR_ERR(bh1721fvc->factory_class);
		goto err_factory_sysfs_create;
	}

	bh1721fvc->factory_dev = device_create(bh1721fvc->factory_class, NULL,
			0, bh1721fvc, "switch_cmd");

	if (IS_ERR(bh1721fvc->factory_dev)) {
		pr_err("Failed to create device(switch_cmd_dev)!\n");
		err = PTR_ERR(bh1721fvc->factory_dev);
		goto err_factory_device_create;
	}

	err = device_create_file(bh1721fvc->factory_dev,
			&dev_attr_lightsensor_file_cmd);

	if (err < 0) {
		pr_err("Failed to create device file(%s)!\n",
				dev_attr_lightsensor_file_cmd.attr.name);
		goto err_file_cmd_attr_create;
	}

	err = device_create_file(bh1721fvc->factory_dev,
			&dev_attr_lightsensor_file_illuminance);

	if (err < 0) {
		pr_err("Failed to create device file(%s)!\n",
			dev_attr_lightsensor_file_illuminance.attr.name);
		goto err_illuminance_attr_create;
	}

	err = device_create_file(bh1721fvc->factory_dev,
			&dev_attr_sensor_info);
	if (err < 0) {
		pr_err("Failed to create device file(%s)!\n",
			dev_attr_sensor_info.attr.name);
		goto err_sensor_info_attr_create;
	}

	printk(KERN_INFO"%s: success!\n", __func__);


	goto done;

err_sensor_info_attr_create:
	device_remove_file(bh1721fvc->factory_dev,
			&dev_attr_lightsensor_file_illuminance);
err_illuminance_attr_create:
	device_remove_file(bh1721fvc->factory_dev,
			&dev_attr_lightsensor_file_cmd);
err_file_cmd_attr_create:
	device_destroy(bh1721fvc->factory_class, 0);
err_factory_device_create:
	class_destroy(bh1721fvc->factory_class);
err_factory_sysfs_create:
	sysfs_remove_group(&bh1721fvc->input_dev->dev.kobj,
				&bh1721fvc_attribute_group);
err_sysfs_create_group_light:
	input_unregister_device(bh1721fvc->input_dev);
err_input_register_device_light:
err_input_allocate_device_light:
	destroy_workqueue(bh1721fvc->wq);
err_create_workqueue:
err_test_lightsensor:
	mutex_destroy(&bh1721fvc->lock);
err_reset_failed:
err_reset_null:
	kfree(bh1721fvc);
done:
	return err;
}
Example #29
0
static int gpu_probe(struct platform_device *pdev)
{
    int i;
    struct resource *res;
    struct device *dev;
    struct mxc_gpu_platform_data *pdata;

    pdata = pdev->dev.platform_data;
    if (pdata) {
	z160_version = pdata->z160_revision;
	gpu_reserved_mem = pdata->reserved_mem_base;
	gpu_reserved_mem_size = pdata->reserved_mem_size;
    }

    for(i = 0; i < 2; i++){
        res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
        if (!res) {
            if (i == 0) {
                printk(KERN_ERR "gpu: unable to get gpu irq\n");
                return -ENODEV;
            } else {
                break;
            }
        }
        if(strcmp(res->name, "gpu_2d_irq") == 0){
            gpu_2d_irq = res->start;
        }else if(strcmp(res->name, "gpu_3d_irq") == 0){
            gpu_3d_irq = res->start;
        }
    }

    for (i = 0; i < 3; i++) {
        res = platform_get_resource(pdev, IORESOURCE_MEM, i);
        if (!res) {
            gpu_2d_regbase = 0;
            gpu_2d_regsize = 0;
            gpu_3d_regbase = 0;
            gpu_2d_regsize = 0;
            gmem_size = 0;
            gpu_reserved_mem = 0;
            gpu_reserved_mem_size = 0;
            break;
        }else{
            if(strcmp(res->name, "gpu_2d_registers") == 0){
                gpu_2d_regbase = res->start;
                gpu_2d_regsize = res->end - res->start + 1;
            }else if(strcmp(res->name, "gpu_3d_registers") == 0){
                gpu_3d_regbase = res->start;
                gpu_3d_regsize = res->end - res->start + 1;
            }else if(strcmp(res->name, "gpu_graphics_mem") == 0){
                gmem_size = res->end - res->start + 1;
            }
        }
    }

    if (gpu_3d_irq > 0)
    {
	if (request_irq(gpu_3d_irq, z430_irq_handler, 0, "ydx", NULL) < 0) {
	    printk(KERN_ERR "%s: request_irq error\n", __func__);
	    gpu_3d_irq = 0;
	    goto request_irq_error;
	}
    }

    if (gpu_2d_irq > 0)
    {
	if (request_irq(gpu_2d_irq, z160_irq_handler, 0, "g12", NULL) < 0) {
	    printk(KERN_ERR "DO NOT use uio_pdrv_genirq kernel module for X acceleration!\n");
	    gpu_2d_irq = 0;
	}
    }

    if (kgsl_driver_init() != GSL_SUCCESS) {
	printk(KERN_ERR "%s: kgsl_driver_init error\n", __func__);
	goto kgsl_driver_init_error;
    }

    gsl_kmod_major = register_chrdev(0, "gsl_kmod", &gsl_kmod_fops);
    gsl_kmod_vmops.fault = gsl_kmod_fault;

    if (gsl_kmod_major <= 0)
    {
        pr_err("%s: register_chrdev error\n", __func__);
        goto register_chrdev_error;
    }

    gsl_kmod_class = class_create(THIS_MODULE, "gsl_kmod");

    if (IS_ERR(gsl_kmod_class))
    {
        pr_err("%s: class_create error\n", __func__);
        goto class_create_error;
    }

    #if(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28))
        dev = device_create(gsl_kmod_class, NULL, MKDEV(gsl_kmod_major, 0), "gsl_kmod");
    #else
        dev = device_create(gsl_kmod_class, NULL, MKDEV(gsl_kmod_major, 0), NULL,"gsl_kmod");
    #endif

    if (!IS_ERR(dev))
    {
    //    gsl_kmod_data.device = dev;
        return 0;
    }

    pr_err("%s: device_create error\n", __func__);

class_create_error:
    class_destroy(gsl_kmod_class);

register_chrdev_error:
    unregister_chrdev(gsl_kmod_major, "gsl_kmod");

kgsl_driver_init_error:
    kgsl_driver_close();
    if (gpu_2d_irq > 0) {
	free_irq(gpu_2d_irq, NULL);
    }
    if (gpu_3d_irq > 0) {
	free_irq(gpu_3d_irq, NULL);
    }
request_irq_error:
    return 0;   // TODO: return proper error code
}
Example #30
0
static int __devinit crtouch_probe(struct i2c_client *client,
				 const struct i2c_device_id *id)
{

	int result;
	struct input_dev *input_dev;
	int error = 0;
	s32 mask_trigger = 0;


	/*to be able to communicate by i2c with crtouch (dev)*/
	client_public = client;

	crtouch = kzalloc(sizeof(struct crtouch_data), GFP_KERNEL);

	if (!crtouch)
		return -ENOMEM;

	input_dev = input_allocate_device();
	if (!input_dev) {
		result = -ENOMEM;
		goto err_free_mem;
	}

	crtouch->input_dev = input_dev;
	crtouch->client = client;
	crtouch->workqueue = create_singlethread_workqueue("crtouch");
	INIT_WORK(&crtouch->work, report_MT);

	if (crtouch->workqueue == NULL) {
		printk(KERN_DEBUG "couldn't create workqueue\n");
		result = -ENOMEM;
		goto err_wqueue;
	}

	error = read_resolution();
	if (error < 0) {
		printk(KERN_DEBUG "couldn't read size of screen\n");
		result = -EIO;
		goto err_free_wq;
	}

	data_configuration = i2c_smbus_read_byte_data(client, CONFIGURATION);
	data_configuration &= CLEAN_SLIDE_EVENTS;
	data_configuration |= SET_MULTITOUCH;
	i2c_smbus_write_byte_data(client, CONFIGURATION, data_configuration);

	mask_trigger = i2c_smbus_read_byte_data(client, TRIGGER_EVENTS);
	mask_trigger |= SET_TRIGGER_RESISTIVE;
	i2c_smbus_write_byte_data(client, TRIGGER_EVENTS, mask_trigger);

	i2c_smbus_write_byte_data(client, TRIGGER_EVENTS, mask_trigger);

	crtouch->input_dev->name = "CRTOUCH Input Device";
	crtouch->input_dev->id.bustype = BUS_I2C;

	__set_bit(EV_ABS, crtouch->input_dev->evbit);
	__set_bit(EV_KEY, crtouch->input_dev->evbit);
	__set_bit(BTN_TOUCH, crtouch->input_dev->keybit);
	__set_bit(ABS_X, crtouch->input_dev->absbit);
	__set_bit(ABS_Y, crtouch->input_dev->absbit);
	__set_bit(ABS_PRESSURE, crtouch->input_dev->absbit);
	__set_bit(EV_SYN, crtouch->input_dev->evbit);

	/*register keys that will be reported by crtouch*/
	__set_bit(KEY_A, crtouch->input_dev->keybit);
	__set_bit(KEY_B, crtouch->input_dev->keybit);
	__set_bit(KEY_C, crtouch->input_dev->keybit);
	__set_bit(KEY_D, crtouch->input_dev->keybit);
	__set_bit(KEY_E, crtouch->input_dev->keybit);
	__set_bit(KEY_F, crtouch->input_dev->keybit);
	__set_bit(KEY_G, crtouch->input_dev->keybit);
	__set_bit(KEY_H, crtouch->input_dev->keybit);
	__set_bit(KEY_I, crtouch->input_dev->keybit);
	__set_bit(KEY_J, crtouch->input_dev->keybit);
	__set_bit(KEY_K, crtouch->input_dev->keybit);
	__set_bit(KEY_L, crtouch->input_dev->keybit);

	input_set_abs_params(crtouch->input_dev, ABS_X, XMIN, xmax, 0, 0);
	input_set_abs_params(crtouch->input_dev, ABS_Y, YMIN, ymax, 0, 0);
	input_set_abs_params(crtouch->input_dev, ABS_MT_POSITION_X,
				XMIN, xmax, 0, 0);
	input_set_abs_params(crtouch->input_dev, ABS_MT_POSITION_Y,
				YMIN, ymax, 0, 0);
	input_set_abs_params(crtouch->input_dev, ABS_MT_TOUCH_MAJOR, 0, 1, 0, 0);
	input_set_abs_params(crtouch->input_dev, ABS_MT_TRACKING_ID, 0, 1, 0, 0);

	input_set_abs_params(crtouch->input_dev, ABS_PRESSURE, 0, 1, 0, 0);
	printk(KERN_DEBUG "CR-TOUCH max values X: %d Y: %d\n", xmax, ymax);

	result = input_register_device(crtouch->input_dev);
	if (result)
		goto err_free_wq;

	if (alloc_chrdev_region(&dev_number, 0, 2, DEV_NAME) < 0) {
		printk(KERN_DEBUG "couldn't allocate cr-touch device with dev\n");
		goto err_unr_dev;
	}

	cdev_init(&crtouch_cdev , &file_ops_crtouch);

	if (cdev_add(&crtouch_cdev, dev_number, 1)) {
		printk(KERN_DEBUG "couldn't register cr-touch device with dev\n");
		goto err_unr_chrdev;
	}

	crtouch_class = class_create(THIS_MODULE, DEV_NAME);

	if (crtouch_class == NULL) {
		printk(KERN_DEBUG "unable to create a class\n");
		goto err_unr_cdev;
	}

	if (device_create(crtouch_class, NULL, dev_number,
				NULL, DEV_NAME) == NULL) {
		printk(KERN_DEBUG "unable to create a device\n");
		goto err_unr_class;
	}

#ifdef WAKE_SIGNAL
	result = gpio_request(PIN_WAKE, "GPIO_WAKE_CRTOUCH");

	if (result != 0) {
		printk(KERN_DEBUG "error requesting GPIO %d\n", result);
		goto err_unr_createdev;
	}

	result = gpio_direction_output(PIN_WAKE, GPIOF_OUT_INIT_HIGH);

	if (result != 0) {
		printk(KERN_DEBUG "error config GPIO PIN direction %d\n", result);
		goto err_free_pin;
	}

	gpio_set_value(PIN_WAKE, VCC);
#endif /* WAKE_SIGNAL */


#ifdef IRQ_EVENT_HANDLING
	/*request gpio to used as interrupt*/
	result = gpio_request(GPIO_IRQ, "GPIO_INTERRUPT_CRTOUCH");

	if (result != 0) {
		printk(KERN_DEBUG "error requesting GPIO for IRQ %d\n", result);
		goto err_free_pin;
	}

	result = gpio_direction_input(GPIO_IRQ);

	if (result != 0) {
		printk(KERN_DEBUG "error config IRQ PIN direction %d\n", result);
		goto err_free_pinIrq;
	}

	/* request irq trigger falling */
	result = request_irq(gpio_to_irq(GPIO_IRQ), crtouch_irq,
				IRQF_TRIGGER_FALLING, IRQ_NAME, crtouch_irq);

	if (result < 0) {
		printk(KERN_DEBUG "unable to request IRQ\n");
		goto err_free_pinIrq;
	}
#else /* IRQ_EVENT_HANDLING */
	/*
	 * Register timer to implement IRQ polling
	 */
	init_timer(&tsc_poll_timer);
	tsc_poll_timer.function = tsc_poll_handler;
	tsc_poll_timer.expires = jiffies + IRQ_POLL_PERIOD;
	add_timer(&tsc_poll_timer);
#endif /* IRQ_EVENT_HANDLING */

	/*clean interrupt pin*/
	i2c_smbus_read_byte_data(client, STATUS_REGISTER_1);

	return 0;

#ifdef IRQ_EVENT_HANDLING
err_free_pinIrq:
	gpio_free(GPIO_IRQ);
#endif
#if defined(IRQ_EVENT_HANDLING) || defined(WAKE_SIGNAL)
err_free_pin:
#endif
#ifdef WAKE_SIGNAL
	gpio_free(PIN_WAKE);
err_unr_createdev:
#endif
#if defined(IRQ_EVENT_HANDLING) || defined(WAKE_SIGNAL)
	device_destroy(crtouch_class, dev_number);
#endif
err_unr_class:
	class_destroy(crtouch_class);
err_unr_cdev:
	cdev_del(&crtouch_cdev);
err_unr_chrdev:
	unregister_chrdev_region(dev_number, 1);
err_unr_dev:
	input_unregister_device(crtouch->input_dev);
err_free_wq:
	destroy_workqueue(crtouch->workqueue);
err_wqueue:
	input_free_device(crtouch->input_dev);
err_free_mem:
	kfree(crtouch);
	return result;
}