Ejemplo n.º 1
0
static int gps_probe(struct platform_device *pdev)
{
	int err = 0;
	struct gps_dev *dev = _gps_dev;
	struct gps_config_info *gps_info = &dev->gps_info;
	
	if(gps_info->gps_clk && strcmp(gps_info->gps_clk, "")){
		gps_32k = clk_get(NULL, gps_info->gps_clk);
		if (IS_ERR(gps_32k)){
			GPS_ERR("Get ap 32k clk out failed!\n");
			return -1;
		}
		enable_gps_32k(1);
	}

	GPS_DBG("set %s 32k out\n", gps_info->gps_clk);
	
	gps_power_init();
	create_sysfs_interfaces(&pdev->dev);

	return err;
}
static int __devinit mpu_input_init(struct mpu_data *mpu)
{
	int ret;
	struct device *dev = &mpu->client->dev;

	mpu->input_dev = input_allocate_device();
	if (!mpu->input_dev) {
		dev_err(dev, "input device allocation failed\n");
		ret = -ENOMEM;
		goto out;
	}

	mpu->input_dev->name = MPU_NAME;
	mpu->input_dev->id.bustype = BUS_I2C;
	mpu->input_dev->dev.parent = &mpu->client->dev;

	input_set_drvdata(mpu->input_dev, mpu);
	set_bit(EV_REL, mpu->input_dev->evbit);
	set_bit(REL_X, mpu->input_dev->relbit);
	set_bit(REL_Y, mpu->input_dev->relbit);
	set_bit(REL_Z, mpu->input_dev->relbit);
	ret = input_register_device(mpu->input_dev);
	if (ret) {
		dev_err(dev, "unable to register input device\n");
		input_free_device(mpu->input_dev);
		goto out;
	}

	ret = create_sysfs_interfaces(&mpu->client->dev);
	if (ret < 0) {
		dev_err(dev, "device gyro sysfs register failed\n");
		input_unregister_device(mpu->input_dev);
	}

out:
	return ret;
}
Ejemplo n.º 3
0
static int felica_probe(struct platform_device *pdev)
{
	int	ret;
	struct felica_dev *dev;
	struct felica_platform_data	*flc_pfdata;

	dev_info(&pdev->dev, "FeliCa driver ver %s being loaded\n",
							DRV_VERSION);

	flc_pfdata = pdev->dev.platform_data;
	if (NULL == flc_pfdata) {
		dev_err(&pdev->dev, "%s: No platform data\n", __func__);
		ret = -EINVAL;
		goto err_get_platform_data;
	}

	dev = kzalloc(sizeof(struct felica_dev), GFP_KERNEL);
	if (!dev) {
		dev_err(&pdev->dev, "%s: no memory\n", __func__);
		ret = -ENOMEM;
		goto err_alloc_data;
	}

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

	dev->device_cen.minor = MISC_DYNAMIC_MINOR;
	dev->device_cen.name = "felica_cen";
	dev->device_cen.fops = &felica_cen_fops;

	dev->device_pon.minor = MISC_DYNAMIC_MINOR;
	dev->device_pon.name = "felica_pon";
	dev->device_pon.fops = &felica_pon_fops;

	dev->device_rfs.minor = MISC_DYNAMIC_MINOR;
	dev->device_rfs.name = "felica_rfs";
	dev->device_rfs.fops = &felica_rfs_fops;

	dev->device_rws.minor = MISC_DYNAMIC_MINOR;
	dev->device_rws.name = "felica_rws";
	dev->device_rws.fops = &felica_rws_fops;

	dev->flcen = &flc_pfdata->cen_pfdata;
	dev->flpon = &flc_pfdata->pon_pfdata;
	dev->flrfs = &flc_pfdata->rfs_pfdata;
	dev->flint = &flc_pfdata->int_pfdata;

	/* GPIO setting of MSM & PM */
	ret = flc_pfdata->gpio_init(dev);
	if (ret && -EBUSY != ret) {
		dev_err(&pdev->dev, "%s: GPIO init failed\n", __func__);
		goto error_gpio_init;
	}

	/* Call initialization functions of each controller */
	ret = felica_cen_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: CEN probe failure\n", __func__);
		goto err_cen_probe;
	}

	ret = felica_pon_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: PON probe failure\n", __func__);
		goto err_pon_probe;
	}

	ret = felica_rfs_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: RFS probe failure\n", __func__);
		goto err_rfs_probe;
	}

	ret = felica_int_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: INT probe failure\n", __func__);
		goto err_int_probe;
	}

	ret = felica_rws_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: RWS probe failure\n", __func__);
		goto err_rws_probe;
	}

	/* Create dev. attrs for Reader/Writer mode */
	ret = create_sysfs_interfaces(&pdev->dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: failed to create dev. attrs\n",
				__func__);
		goto err_create_sysfs;
	}

	return 0;

/* Error handling */
err_create_sysfs:
	felica_rws_remove_func(dev);
err_rws_probe:
	felica_int_remove_func(dev);
err_int_probe:
	felica_rfs_remove_func(dev);
err_rfs_probe:
	felica_pon_remove_func(dev);
err_pon_probe:
	felica_cen_remove_func(dev);
err_cen_probe:
	flc_pfdata->reg_release(dev);
error_gpio_init:
	kfree(dev);
err_alloc_data:
err_get_platform_data:

	return ret;
}
Ejemplo n.º 4
0
static int simple_remote_probe(struct platform_device *pdev)
{
	int ret = 0;
	int size;
	void *v;
	struct simple_remote_driver *jack;

	dev_info(&pdev->dev, "**** Registering (headset) driver\n");

	jack = kzalloc(sizeof(struct simple_remote_driver), GFP_KERNEL);

	if (!jack)
		return -ENOMEM;

	mutex_init(&jack->simple_remote_mutex);

	if (!pdev->dev.platform_data)
		goto err_switch_dev_register;


	size = sizeof(*jack->interface) / sizeof(void *);
	v = (void *)pdev->dev.platform_data;

	for (; size > 0; size--)
		if (v++ == NULL)
			goto err_switch_dev_register;

	jack->interface = pdev->dev.platform_data;
	jack->dev = &pdev->dev;

	jack->plug_det_timer.function = simple_remote_plug_detect_tmr_func;
	jack->plug_det_timer.data = (unsigned long)jack;

	init_timer(&jack->plug_det_timer);

	/* Set flags */
	jack->current_accessory_state = NO_DEVICE;
	jack->pressed_button = 0xFF;

	/* Initialize work queue for Simple Remote Driver */
	INIT_WORK(&jack->plug_det_work,
			  simple_remote_plug_det_work);
	INIT_WORK(&jack->btn_det_work,
		  simple_remote_btn_det_work);

	/* device name */
	jack->swdev.name = "h2w";

	/* print function name */
	jack->swdev.print_name = simple_remote_print_name;

	ret = switch_dev_register(&jack->swdev);
	if (ret < 0) {
		dev_err(jack->dev, "switch_dev_register failed\n");
		goto err_switch_dev_register;
	}

	ret = create_sysfs_interfaces(&pdev->dev);
	if (ret) {
		dev_err(jack->dev,
			"create_sysfs_interfaces for input failed\n");
		goto err_switch_dev_register;
	}

	if (initialize_hardware(jack))
		dev_err(jack->dev, "Failed to set default values in HW "
			"components.");

	/* Create input device for normal key events. */
	jack->indev = input_allocate_device();
	if (!jack->indev) {
		ret = -ENOMEM;
		dev_err(jack->dev, "Failed to allocate input device\n");
		goto err_allocate_input_dev;
	}

	jack->indev->name = SIMPLE_REMOTE_NAME;
	jack->indev->evbit[0] = BIT_MASK(EV_KEY);
	jack->indev->keybit[BIT_WORD(KEY_MEDIA)] |= BIT_MASK(KEY_MEDIA);
	jack->indev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) |
		BIT_MASK(BTN_1) | BIT_MASK(BTN_2);

	jack->indev->open = simple_remote_open;
	jack->indev->close = simple_remote_close;

	input_set_drvdata(jack->indev, jack);
	platform_set_drvdata(pdev, jack);

	ret = input_register_device(jack->indev);
	if (ret) {
		dev_err(jack->dev, "input_register_device for input device "
			"failed\n");
		input_free_device(jack->indev);
		goto err_register_input_dev;
	}

	/* Create input device for application key events. */
	jack->indev_appkey = input_allocate_device();
	if (!jack->indev_appkey) {
		ret = -ENOMEM;
		dev_err(jack->dev, "Failed to allocate application key input "
			"device\n");
		goto err_allocate_input_appkey_dev;
	}

	jack->indev_appkey->name = SIMPLE_REMOTE_APPKEY_NAME;
	jack->indev_appkey->evbit[0] = BIT_MASK(EV_KEY);
	jack->indev_appkey->keybit[BIT_WORD(BTN_MISC)] |=
		BIT_MASK(SIMPLE_REMOTE_APPKEY);
	jack->indev_appkey->open = simple_remote_open;
	jack->indev_appkey->close = simple_remote_close;

	input_set_drvdata(jack->indev_appkey, jack);

	ret = input_register_device(jack->indev_appkey);
	if (ret) {
		dev_err(jack->dev, "input_register_device for application key "
				"input device failed\n");
		goto err_register_input_appkey_dev;
	}

	dev_info(jack->dev, "***** Successfully registered\n");

	atomic_set(&jack->initialized, 1);

	return ret;

err_register_input_appkey_dev:
	input_free_device(jack->indev_appkey);
err_allocate_input_appkey_dev:
	input_unregister_device(jack->indev);
err_register_input_dev:
err_allocate_input_dev:
err_switch_dev_register:
	dev_err(&pdev->dev, "***** Failed to initialize\n");
	kzfree(jack);

	return ret;
}
Ejemplo n.º 5
0
static int anx7808_i2c_probe(struct i2c_client *client,
			const struct i2c_device_id *id)
{

	struct anx7808_data *anx7808;
	struct anx7808_platform_data *pdata;
	int ret = 0;
	int sbl_cable_type = 0;

#ifdef SP_REGISTER_SET_TEST
	val_SP_TX_LT_CTRL_REG0 = 0x19;
	val_SP_TX_LT_CTRL_REG10 = 0x00;
	val_SP_TX_LT_CTRL_REG11 = 0x00;
	val_SP_TX_LT_CTRL_REG2 = 0x36;
	val_SP_TX_LT_CTRL_REG12 = 0x00;
	val_SP_TX_LT_CTRL_REG1 = 0x26;
	val_SP_TX_LT_CTRL_REG6 = 0x3c;
	val_SP_TX_LT_CTRL_REG16 = 0x18;
	val_SP_TX_LT_CTRL_REG5 = 0x28;
	val_SP_TX_LT_CTRL_REG8 = 0x2F;
	val_SP_TX_LT_CTRL_REG15 = 0x10;
	val_SP_TX_LT_CTRL_REG18 = 0x1F;
#endif
	if (!i2c_check_functionality(client->adapter,
		I2C_FUNC_SMBUS_I2C_BLOCK)) {
		pr_err("%s: i2c bus does not support the anx7808\n", __func__);
		ret = -ENODEV;
		goto exit;
	}

	anx7808 = kzalloc(sizeof(struct anx7808_data), GFP_KERNEL);
	if (!anx7808) {
		pr_err("%s: failed to allocate driver data\n", __func__);
		ret = -ENOMEM;
		goto exit;
	}

	if (client->dev.of_node) {
		pdata = devm_kzalloc(&client->dev,
							 sizeof(struct anx7808_platform_data),
							 GFP_KERNEL);
		if (!pdata) {
			pr_err("%s: Failed to allocate memory\n", __func__);
			return -ENOMEM;
		}
		client->dev.platform_data = pdata;
	/* device tree parsing function call */
		ret = anx7808_parse_dt(&client->dev, pdata);
		if (ret != 0) /* if occurs error */
			goto err0;

		anx7808->pdata = pdata;
	} else {
		anx7808->pdata = client->dev.platform_data;
	}

	/* to access global platform data */
	g_pdata = anx7808->pdata;

	anx7808_client = client;

	mutex_init(&anx7808->lock);

	if (!anx7808->pdata) {
		ret = -EINVAL;
		goto err0;
	}

	ret = anx7808_init_gpio(anx7808);
	if (ret) {
		pr_err("%s: failed to initialize gpio\n", __func__);
		goto err0;
	}

	INIT_DELAYED_WORK(&anx7808->work, anx7808_work_func);
	INIT_DELAYED_WORK(&anx7808->dwc3_ref_clk_work, dwc3_ref_clk_work_func);

	anx7808->workqueue = create_singlethread_workqueue("anx7808_work");
	if (anx7808->workqueue == NULL) {
		pr_err("%s: failed to create work queue\n", __func__);
		ret = -ENOMEM;
		goto err1;
	}

	anx7808->pdata->avdd_power(1);
	anx7808->pdata->dvdd_power(1);

	ret = anx7808_system_init();
	if (ret) {
		pr_err("%s: failed to initialize anx7808\n", __func__);
		goto err2;
	}

	client->irq = gpio_to_irq(anx7808->pdata->gpio_cbl_det);
	if (client->irq < 0) {
		pr_err("%s : failed to get gpio irq\n", __func__);
		goto err2;
	}

	wake_lock_init(&anx7808->slimport_lock,
				WAKE_LOCK_SUSPEND,
				"slimport_wake_lock");

	sbl_cable_type = anx7808_get_sbl_cable_type();

	if ((lge_get_laf_mode() != LGE_LAF_MODE_LAF) &&
		(sbl_cable_type != CBL_910K)) {

		ret = request_threaded_irq(client->irq, NULL, anx7808_cbl_det_isr,
						IRQF_TRIGGER_RISING
						| IRQF_TRIGGER_FALLING
						| IRQF_ONESHOT,
						"anx7808", anx7808);
		if (ret  < 0) {
			pr_err("%s : failed to request irq\n", __func__);
			goto err2;
		}

		ret = irq_set_irq_wake(client->irq, 1);
		if (ret  < 0) {
			pr_err("%s : Request irq for cable detect", __func__);
			pr_err("interrupt wake set fail\n");
			goto err3;
		}

		ret = enable_irq_wake(client->irq);
		if (ret  < 0) {
			pr_err("%s : Enable irq for cable detect", __func__);
			pr_err("interrupt wake enable fail\n");
			goto err3;
		}
	} else {
		pr_err("%s %s : %s, Disable cbl det irq!!\n", LOG_TAG, __func__,
			sbl_cable_type == CBL_910K ? "910K Cable Connected" : "Laf Mode");
	}

	ret = create_sysfs_interfaces(&client->dev);
	if (ret < 0) {
		pr_err("%s : sysfs register failed", __func__);
		goto err3;
	}
#ifdef CONFIG_SLIMPORT_DYNAMIC_HPD
	hdmi_slimport_ops = devm_kzalloc(&client->dev,
				    sizeof(struct msm_hdmi_slimport_ops),
				    GFP_KERNEL);
	if (!hdmi_slimport_ops) {
		pr_err("%s: alloc hdmi slimport ops failed\n", __func__);
		ret = -ENOMEM;
		goto err3;
	}

	if (anx7808->pdata->hdmi_pdev) {
		ret = msm_hdmi_register_slimport(anx7808->pdata->hdmi_pdev,
					   hdmi_slimport_ops, anx7808);
		if (ret) {
			pr_err("%s: register with hdmi failed\n", __func__);
			ret = -EPROBE_DEFER;
			goto err3;
		}
	}
#endif

	goto exit;

err3:
	free_irq(client->irq, anx7808);
err2:
	destroy_workqueue(anx7808->workqueue);
err1:
	anx7808_free_gpio(anx7808);
err0:
	anx7808_client = NULL;
	kfree(anx7808);
exit:
	return ret;
}
static int __devinit mipi_r63306_lcd_probe(struct platform_device *pdev)
{
	int ret;
	struct lcd_panel_platform_data *platform_data;
	struct mipi_dsi_data *dsi_data;
	struct platform_device *fb_pdev;

	platform_data = pdev->dev.platform_data;
	if (platform_data == NULL)
		return -EINVAL;

	dsi_data = kzalloc(sizeof(struct mipi_dsi_data), GFP_KERNEL);
	if (dsi_data == NULL)
		return -ENOMEM;
	dsi_data->panel_data.on = mipi_r63306_lcd_on;
	dsi_data->panel_data.off = mipi_r63306_lcd_off;
	dsi_data->default_panels = platform_data->default_panels;
	dsi_data->panels = platform_data->panels;
	dsi_data->lcd_power = platform_data->lcd_power;
	dsi_data->lcd_reset = platform_data->lcd_reset;
	dsi_data->eco_mode_switch = mipi_dsi_eco_mode_switch;
	if (mipi_dsi_need_detect_panel(dsi_data->panels)) {
		dsi_data->panel_data.panel_detect = mipi_dsi_detect_panel;
		dsi_data->panel_data.update_panel = mipi_dsi_update_panel;
		dsi_data->panel_detecting = true;
	} else {
		dev_info(&pdev->dev, "no need to detect panel\n");
	}
#ifdef CONFIG_FB_MSM_RECOVER_PANEL
	dsi_data->is_nvm_ok = mipi_r63303_is_nvm_ok;
	dsi_data->backup_nvm_to_ram = mipi_r63306_backup_nvm_to_ram;
	dsi_data->get_nvm_backup = mipi_r63303_get_nvm_backup;
	dsi_data->override_nvm_data = mipi_r63306_nvm_override_data;
	dsi_data->nvm_erase_all = mipi_r63306_nvm_erase_all;
	dsi_data->nvm_write_trim_area = mipi_r63306_nvm_write_trim_area;
	dsi_data->nvm_write_user_area = mipi_r63306_nvm_write_user_area;
	dsi_data->panel_nvm_ok = true;
	dsi_data->panel_nvm_backup_ok = false;
#endif
	ret = mipi_dsi_buf_alloc(&dsi_data->tx_buf, DSI_BUF_SIZE);
	if (ret <= 0) {
		dev_err(&pdev->dev, "mipi_dsi_buf_alloc(tx) failed!\n");
		goto err_dsibuf_free;
	}

	ret = mipi_dsi_buf_alloc(&dsi_data->rx_buf, DSI_BUF_SIZE);
	if (ret <= 0) {
		dev_err(&pdev->dev, "mipi_dsi_buf_alloc(rx) failed!\n");
		goto err_txbuf_free;
	}

	platform_set_drvdata(pdev, dsi_data);

	mipi_dsi_set_default_panel(dsi_data);

	ret = platform_device_add_data(pdev, &dsi_data->panel_data,
		sizeof(dsi_data->panel_data));
	if (ret) {
		dev_err(&pdev->dev,
			"platform_device_add_data failed!\n");
		goto err_rxbuf_free;
	}
	fb_pdev = msm_fb_add_device(pdev);
#ifdef CONFIG_FB_MSM_PANEL_ECO_MODE
	eco_mode_sysfs_register(&fb_pdev->dev);
#endif
#ifdef CONFIG_FB_MSM_RECOVER_PANEL
	create_sysfs_interfaces(&fb_pdev->dev);
#endif
#ifdef CONFIG_DEBUG_FS
	mipi_dsi_panel_create_debugfs(fb_pdev, "mipi_r63306");
#endif

	return 0;
err_rxbuf_free:
	mipi_dsi_buf_release(&dsi_data->rx_buf);
err_txbuf_free:
	mipi_dsi_buf_release(&dsi_data->tx_buf);
err_dsibuf_free:
	kfree(dsi_data);
	return ret;
}
Ejemplo n.º 7
0
static int  mma8452_probe(struct i2c_client *client ,
                                  const struct i2c_device_id *id)
{
    int err=-1,client_id;
    struct i2c_adapter *adapter;
    struct gs_mma8452_data *mma;
    struct mma8452_acc_platform_data *devpd =client->dev.platform_data;
    pr_info("%s: probe start.\n", MMA8452_ACC_DEV_NAME);

    if (!devpd)
    {
        dev_err(&client->dev, "No platfrom data!\n");
        err=-ENODEV;
        goto err_get_power_fail;
    }
    /*get power*/
    if(devpd->power_on)
    {
        err = devpd->power_on(&client->dev);
        if(err < 0)
        {
            dev_err(&client->dev, "mma8452_acc_probe: get power fail! result=%d\n", err);
            goto err_get_power_fail;
        }
        dev_dbg(&client->dev,"mma8452_acc_probe: get power success! \n");
    }
    dev_info(&client->dev, "mma8452_acc_probe: get power success! result=%d\n", err);

    /*check functionality*/
    adapter = to_i2c_adapter(client->dev.parent);
    err = i2c_check_functionality(adapter,
                     I2C_FUNC_SMBUS_BYTE |
                     I2C_FUNC_SMBUS_BYTE_DATA);
    if (!err)
    {
        dev_err(&client->dev, "client not i2c capable\n");
        err=-ENODEV;
        goto err_out;
    }

    msleep(5);

    client_id = i2c_smbus_read_byte_data(client, MMA8452_WHO_AM_I);     // MMA8452_WHO_AM_I=3A
    if (client_id != MMA8452_ID)
    {
        dev_err(&client->dev,
            "read chip ID 0x%x is not equal to 0x%x or 0x%x!\n",
            err, MMA8452_ID, MMA8452_ID);
        err = -EINVAL;
        goto err_out;
    }
	dev_info(&client->dev, "Read mma8452 chip ok, ID is 0x%x\n", client_id);
	err = set_sensor_chip_info(ACC, "FREESCALE MMA8452");
	if (err) {
		dev_err(&client->dev, "set_sensor_chip_info error \n");
	}
    /*allocate memory*/
    mma=kzalloc(sizeof(struct gs_mma8452_data), GFP_KERNEL);
    if (!mma)
    {
        err = -ENOMEM;
        dev_err(&client->dev,
                "failed to allocate memory for module data: "
                    "%d\n",err);
        goto err_out;
    }
	err =  i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG3, 0x2);
	if (err < 0) {
		dev_err(&client->dev, "%s: failed to selects the polarity of the interrupt signal\n", __func__);
		goto err_out;
	}
    mutex_init(&mma->lock);
    mma->client=client;
    i2c_set_clientdata(client,mma);
    /* Initialize the MMA8452 chip */
    err = mma8452_hw_init(mma);      // MOD_2G     0
    if (err<0)
    {
        dev_err(&client->dev,
            "error mma8452_hw_init init chip failed:(%d)\n", err);
        goto err_init;
    }

    /*Initialize the input device */
    err=mma8452_input_init(mma);
    if(err<0)
    {
        dev_err(&client->dev,"input init failed \n");
        goto err_init;
    }

    err = create_sysfs_interfaces(&client->dev);
    if (err < 0)
    {
        dev_err(&client->dev, "device MMA8452_ACC_DEV_NAME sysfs register failed\n");
        goto err_create_sysfs;
    }
    dev_info(&client->dev, "create_sysfs_interfaces: create interfaces success! ");
    mma->mma_status.position = devpd->config_mxc_mma_position;

    #ifdef CONFIG_HAS_EARLYSUSPEND
    mma->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
    mma->early_suspend.suspend = mma8452_early_suspend;
    mma->early_suspend.resume = mma8452_early_resume;
    register_early_suspend(&mma->early_suspend);
    #endif
#ifdef CONFIG_HUAWEI_HW_DEV_DCT
        /* detect current device successful, set the flag as present */
    set_hw_dev_flag(DEV_I2C_G_SENSOR);
#endif
    pr_info("%s: probe success.\n", MMA8452_ACC_DEV_NAME);
    return 0;

err_create_sysfs:
       remove_sysfs_interfaces(&client->dev);
       input_unregister_device(mma->input_dev);
       input_free_device(mma->input_dev);
err_init:
    kfree(mma);
err_out:
    if(devpd->power_off)
          devpd->power_off();
err_get_power_fail:
    return err;
}
Ejemplo n.º 8
0
static int l3g4200d_probe(struct i2c_client *client,
		const struct i2c_device_id *devid)
{
	int err;
	struct l3g4200d_data *gyro;

	dev_info(&client->dev, "probe start.\n");

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

	if (!i2c_check_functionality(client->adapter,
				I2C_FUNC_I2C | I2C_FUNC_SMBUS_I2C_BLOCK)) {
		dev_err(&client->dev, "client not i2c capable.\n");
		err = -ENODEV;
		goto err_out;
	}

	gyro = kzalloc(sizeof(*gyro), GFP_KERNEL);
	if (gyro == NULL) {
		dev_err(&client->dev, "failed to allocate memory.\n");
		err = -ENOMEM;
		goto err_out;
	}

	gyro->pdata = kmalloc(sizeof(*gyro->pdata), GFP_KERNEL);
	if (gyro->pdata == NULL) {
		dev_err(&client->dev, "failed to allocate memory for pdata.");
		err = -ENOMEM;
		goto err_free_gyro;
	}
	memcpy(gyro->pdata, client->dev.platform_data, sizeof(*gyro->pdata));

	err = l3g4200d_validate_pdata(gyro);
	if (err < 0) {
		dev_err(&client->dev, "failed to validate platform data.\n");
		goto err_free_pdata;
	}

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

	err = l3g4200d_input_init(gyro);
	if (err < 0)
		goto err_free_pdata;

	err = l3g4200d_hw_init(gyro);
	if (err < 0) {
		dev_err(&client->dev, "failed to init l3g4200d hardware.\n");
		goto err_clean_input;
	}

	err = create_sysfs_interfaces(&client->dev);
	if (err < 0)
		goto err_clean_input;

	mutex_init(&gyro->lock);
	INIT_DELAYED_WORK(&gyro->work, l3g4200d_poll_work);

	gyro->es.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 10;
	gyro->es.suspend = l3g4200d_early_suspend;
	gyro->es.resume = l3g4200d_late_resume;
	register_early_suspend(&gyro->es);

	dev_info(&client->dev, "probed.\n");
	return 0;

err_clean_input:
	input_unregister_device(gyro->input_dev);
err_free_pdata:
	kfree(gyro->pdata);
err_free_gyro:
	kfree(gyro);
err_out:
	dev_err(&client->dev, "Driver Initialization failed, %d\n", err);
	return err;
}
Ejemplo n.º 9
0
static int yas_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
{
	struct yas_state *st;
	struct iio_dev *indio_dev;
	int ret, i;
	s8 *bias;
	struct yas_acc_platform_data *pdata;

	I("%s\n", __func__);

	this_client = i2c;
	indio_dev = iio_device_alloc(sizeof(*st));
	if (!indio_dev) {
		ret = -ENOMEM;
		goto error_ret;
	}
	i2c_set_clientdata(i2c, indio_dev);

	indio_dev->name = id->name;
	indio_dev->dev.parent = &i2c->dev;
	indio_dev->info = &yas_info;
	indio_dev->channels = yas_channels;
	indio_dev->num_channels = ARRAY_SIZE(yas_channels);
	indio_dev->modes = INDIO_DIRECT_MODE;

	st = iio_priv(indio_dev);
	st->client = i2c;
	st->sampling_frequency = 20;
	st->acc.callback.device_open = yas_device_open;
	st->acc.callback.device_close = yas_device_close;
	st->acc.callback.device_read = yas_device_read;
	st->acc.callback.device_write = yas_device_write;
	st->acc.callback.usleep = yas_usleep;
	st->acc.callback.current_time = yas_current_time;
	st->indio_dev = indio_dev;
	INIT_DELAYED_WORK(&st->work, yas_work_func);
	INIT_WORK(&st->resume_work, yas_resume_work_func);
	mutex_init(&st->lock);
#ifdef CONFIG_HAS_EARLYSUSPEND
	st->sus.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	st->sus.suspend = yas_early_suspend;
	st->sus.resume = yas_late_resume;
	register_early_suspend(&st->sus);
#endif
	ret = yas_probe_buffer(indio_dev);
	if (ret)
		goto error_free_dev;
	ret = yas_probe_trigger(indio_dev);
	if (ret)
		goto error_remove_buffer;
	ret = iio_device_register(indio_dev);
	if (ret)
		goto error_remove_trigger;
	ret = yas_acc_driver_init(&st->acc);
	if (ret < 0) {
		ret = -EFAULT;
		goto error_unregister_iio;
	}
	ret = st->acc.init();
	if (ret < 0) {
		ret = -EFAULT;
		goto error_unregister_iio;
	}
	ret = st->acc.set_enable(1);
	if (ret < 0) {
		ret = -EFAULT;
		goto error_driver_term;
	}

	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
	if (pdata == NULL)
		E("%s: memory allocation for pdata failed.", __func__);
	else
		yas_parse_dt(&i2c->dev, pdata);

	for (i = 0; i < 3; i++) {
		st->accel_data[i] = 0;
		bias = (s8 *)&pdata->gs_kvalue;
		st->calib_bias[i] = -(bias[2-i] *
					YAS_GRAVITY_EARTH / 256);
		I("%s: calib_bias[%d] = %d\n", __func__, i, st->calib_bias[i]);
	}

	mutex_lock(&st->lock);
	if ((pdata->placement < 8) && (pdata->placement >= 0)) {
		ret = st->acc.set_position(pdata->placement);
		I("%s: set position = %d\n", __func__, pdata->placement);
	} else {
		ret = st->acc.set_position(5);
		D("%s: set default position = 5\n", __func__);
	}
	mutex_unlock(&st->lock);

#ifdef CONFIG_CIR_ALWAYS_READY
	
	module.IRQ = pdata->intr;
	I("%s: IRQ = %d\n", __func__, module.IRQ);
	ret = request_irq(module.IRQ, kxtj2_irq_handler, IRQF_TRIGGER_RISING,
			"kxtj2", &module);
	enable_irq_wake(module.IRQ);
	if (ret)
		E("%s: Could not request irq = %d\n", __func__, module.IRQ);

	module.kxtj2_wq = create_singlethread_workqueue("kxtj2_wq");
	if (!module.kxtj2_wq) {
		E("%s: Can't create workqueue\n", __func__);
		ret = -ENOMEM;
		goto error_create_singlethread_workqueue;
	}
#endif

	init_irq_work(&st->iio_irq_work, iio_trigger_work);
	g_st = st;

	ret = create_sysfs_interfaces(st);
	if (ret) {
		E("%s: create_sysfs_interfaces fail, ret = %d\n",
		  __func__, ret);
		goto err_create_fixed_sysfs;
	}

	I("%s: Successfully probe\n", __func__);


	return 0;

err_create_fixed_sysfs:

#ifdef CONFIG_CIR_ALWAYS_READY
	if (module.kxtj2_wq)
		destroy_workqueue(module.kxtj2_wq);
error_create_singlethread_workqueue:
#endif
	kfree(pdata);
error_driver_term:
	st->acc.term();
error_unregister_iio:
	iio_device_unregister(indio_dev);
error_remove_trigger:
	yas_remove_trigger(indio_dev);
error_remove_buffer:
	yas_remove_buffer(indio_dev);
error_free_dev:
#ifdef CONFIG_HAS_EARLYSUSPEND
	unregister_early_suspend(&st->sus);
#endif
	iio_device_free(indio_dev);
error_ret:
	i2c_set_clientdata(i2c, NULL);
	this_client = NULL;
	return ret;
}
Ejemplo n.º 10
0
static int anx7816_i2c_probe(struct i2c_client *client,
			const struct i2c_device_id *id)
{

	struct anx7816_data *anx7816;
	struct anx7816_platform_data *pdata;
	struct msm_hdmi_sp_ops *hdmi_sp_ops = NULL; // slimport changes
	int ret = 0;

	pr_info("%s %s start\n", LOG_TAG, __func__);

#ifdef SP_REGISTER_SET_TEST
	val_SP_TX_LT_CTRL_REG0 = 0x19;
	val_SP_TX_LT_CTRL_REG10 = 0x00;
	val_SP_TX_LT_CTRL_REG11 = 0x00;
	val_SP_TX_LT_CTRL_REG2 = 0x36;
	val_SP_TX_LT_CTRL_REG12 = 0x00;
	val_SP_TX_LT_CTRL_REG1 = 0x26;
	val_SP_TX_LT_CTRL_REG6 = 0x3c;
	val_SP_TX_LT_CTRL_REG16 = 0x18;
	val_SP_TX_LT_CTRL_REG5 = 0x28;
	val_SP_TX_LT_CTRL_REG8 = 0x2F;
	val_SP_TX_LT_CTRL_REG15 = 0x10;
	val_SP_TX_LT_CTRL_REG18 = 0x1F;
#endif
	if (!i2c_check_functionality(client->adapter,
		I2C_FUNC_SMBUS_I2C_BLOCK)) {
		pr_err("%s: i2c bus does not support the anx7816\n", __func__);
		ret = -ENODEV;
		goto exit;
	}

	anx7816 = kzalloc(sizeof(struct anx7816_data), GFP_KERNEL);
	if (!anx7816) {
		pr_err("%s: failed to allocate driver data\n", __func__);
		ret = -ENOMEM;
		goto exit;
	}

	if (client->dev.of_node) {
		pdata = devm_kzalloc(&client->dev,
							 sizeof(struct anx7816_platform_data),
							 GFP_KERNEL);
		if (!pdata) {
			pr_err("%s: Failed to allocate memory\n", __func__);
			return -ENOMEM;
		}
		client->dev.platform_data = pdata;
	/* device tree parsing function call */
		ret = anx7816_parse_dt(&client->dev, pdata, anx7816);
		if (ret != 0) /* if occurs error */
			goto err0;

		anx7816->pdata = pdata;
	} else {
		anx7816->pdata = client->dev.platform_data;
	}

	/* to access global platform data */
	g_pdata = anx7816->pdata;

	anx7816_client = client;

	mutex_init(&anx7816->lock);

	if (!anx7816->pdata) {
		ret = -EINVAL;
		goto err0;
	}

/* slimport start*/
/* initialize hdmi_sp_ops */
        hdmi_sp_ops = devm_kzalloc(&client->dev,
                                   sizeof(struct msm_hdmi_sp_ops),
                                   GFP_KERNEL);
        if (!hdmi_sp_ops) {
                pr_err("alloc hdmi sp ops failed\n");
                goto err0;
        }

        if (anx7816->hdmi_pdev) {
                ret = msm_hdmi_register_sp(anx7816->hdmi_pdev,
                                          hdmi_sp_ops);
                if (ret) {
                        pr_err("register with hdmi_failed\n");
                        goto err0;
                }
        }

        anx7816->hdmi_sp_ops = hdmi_sp_ops;
/* slimport end*/

	ret = anx7816_init_gpio(anx7816);
	if (ret) {
		pr_err("%s: failed to initialize gpio\n", __func__);
		goto err0;
	}

	INIT_DELAYED_WORK(&anx7816->work, anx7816_work_func);

	anx7816->workqueue = create_singlethread_workqueue("anx7816_work");
	if (anx7816->workqueue == NULL) {
		pr_err("%s: failed to create work queue\n", __func__);
		ret = -ENOMEM;
		goto err1;
	}

//	anx7816->pdata->avdd_power(1);
//	anx7816->pdata->dvdd_power(1);

	ret = anx7816_system_init();
	if (ret) {
		pr_err("%s: failed to initialize anx7816\n", __func__);
		goto err2;
	}

	client->irq = gpio_to_irq(anx7816->pdata->gpio_cbl_det);
	if (client->irq < 0) {
		pr_err("%s : failed to get gpio irq\n", __func__);
		goto err2;
	}

	wake_lock_init(&anx7816->slimport_lock,
				WAKE_LOCK_SUSPEND,
				"slimport_wake_lock");


	ret = request_threaded_irq(client->irq, NULL, anx7816_cbl_det_isr,
						IRQF_TRIGGER_RISING
						| IRQF_TRIGGER_FALLING
						| IRQF_ONESHOT,
						"anx7816", anx7816);
	if (ret  < 0) {
		pr_err("%s : failed to request irq\n", __func__);
		goto err2;
	}

	ret = irq_set_irq_wake(client->irq, 1);
	if (ret  < 0) {
		pr_err("%s : Request irq for cable detect", __func__);
		pr_err("interrupt wake set fail\n");
		goto err3;
	}

	ret = enable_irq_wake(client->irq);
	if (ret  < 0) {
		pr_err("%s : Enable irq for cable detect", __func__);
		pr_err("interrupt wake enable fail\n");
		goto err3;
	}

	ret = create_sysfs_interfaces(&client->dev);
	if (ret < 0) {
		pr_err("%s : sysfs register failed", __func__);
		goto err3;
	}

	pr_info("%s %s end\n", LOG_TAG, __func__);
	goto exit;

err3:
	free_irq(client->irq, anx7816);
err2:
	destroy_workqueue(anx7816->workqueue);
err1:
	anx7816_free_gpio(anx7816);
err0:
	anx7816_client = NULL;
	kfree(anx7816);
exit:
	return ret;
}
Ejemplo n.º 11
0
static int __devinit hall_device_probe(struct i2c_client *client,
                  const struct i2c_device_id *id)
{
    int ret = 0;
	static struct hall_device_chip *chip;

    SENSOR_LOG_INFO("prob start\n");

    chip = kzalloc(sizeof(struct hall_device_chip), GFP_KERNEL);
    if (!chip) {
        ret = -ENOMEM;
        goto malloc_failed;
    }

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

    hall_device_chip_data_init(chip);

    hall_device_parse_dt(chip);

    SENSOR_LOG_INFO("hall_device_int_s is %d",chip->irq_s.irq_pin);
    SENSOR_LOG_INFO("hall_device_int_n is %d",chip->irq_n.irq_pin);

	mutex_init(&chip->lock);


    hall_device_class   = class_create(THIS_MODULE, "hall_device");

    chip->hall_device_dev = device_create(hall_device_class, NULL, hall_device_dev_t, &hall_device_driver ,"hall_device");
    if (IS_ERR(chip->hall_device_dev)) 
    {
       ret = PTR_ERR(chip->hall_device_dev);
       goto create_hall_device_dev_failed;
    }

	dev_set_drvdata(chip->hall_device_dev, chip);


    ret = gpio_request(chip->irq_s.irq_pin, "chip->irq_s.irq_pin");
    if (ret)    
    {
        SENSOR_LOG_INFO("gpio %d is busy and then to free it\n",chip->irq_s.irq_pin);
        
        gpio_free(chip->irq_s.irq_pin);
        ret = gpio_request(chip->irq_s.irq_pin, "chip->irq_s.irq_pin");
        if (ret) 
        {
            SENSOR_LOG_INFO("gpio %d is busy and then to free it\n",chip->irq_s.irq_pin);
            return ret;
        }
    }
    
    ret = gpio_tlmm_config(GPIO_CFG(chip->irq_s.irq_pin, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA), GPIO_CFG_ENABLE);

    chip->irq_s.irq_num = gpio_to_irq(chip->irq_s.irq_pin);
    INIT_WORK(&chip->irq_work_s, hall_device_irq_work_s);
    ret = request_threaded_irq(chip->irq_s.irq_num, NULL, &hall_device_irq_s, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT, "hall_device_irq_s", chip);
    if (ret) {
        SENSOR_LOG_ERROR("Failed to request irq %d\n", chip->irq_s.irq_num);
        goto irq_s_register_fail;
    }


    ret = gpio_request(chip->irq_n.irq_pin, "chip->irq_n.irq_pin");
    if (ret)    
    {
        SENSOR_LOG_INFO("gpio %d is busy and then to free it\n",chip->irq_n.irq_pin);
        
        gpio_free(chip->irq_n.irq_pin);
        ret = gpio_request(chip->irq_n.irq_pin, "chip->irq_n.irq_pin");
        if (ret) 
        {
            SENSOR_LOG_INFO("gpio %d is busy and then to free it\n",chip->irq_n.irq_pin);
            return ret;
        }
    }
    
    ret = gpio_tlmm_config(GPIO_CFG(chip->irq_n.irq_pin, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA), GPIO_CFG_ENABLE);

    chip->irq_n.irq_num = gpio_to_irq(chip->irq_n.irq_pin);
    INIT_WORK(&chip->irq_work_n, hall_device_irq_work_n);
    ret = request_threaded_irq(chip->irq_n.irq_num , NULL, &hall_device_irq_n, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT, "hall_device_irq_n", chip);
    if (ret) {
        SENSOR_LOG_ERROR("Failed to request irq %d\n", chip->irq_n.irq_num );
        goto irq_n_register_fail;
    }

    chip->idev = input_allocate_device();
    if (!chip->idev) 
    {
        SENSOR_LOG_ERROR("no memory for idev\n");
        ret = -ENODEV;
        goto input_alloc_failed;
    }
    chip->idev->name = "hall_device";
    chip->idev->id.bustype = BUS_I2C;

    set_bit(EV_REL,     chip->idev->evbit);
    set_bit(REL_RX,     chip->idev->relbit);  //NEAR
    set_bit(REL_RY,     chip->idev->relbit);  //FAR


    ret = input_register_device(chip->idev);
    if (ret) {
        input_free_device(chip->idev);
        SENSOR_LOG_ERROR("cant register input '%s'\n",chip->idev->name);
        goto input_register_failed;
    }

    create_sysfs_interfaces(chip->hall_device_dev);

    hall_device_irq_enable(&(chip->irq_s), false, true);
    hall_device_irq_enable(&(chip->irq_n), false, true);

    wake_lock_init(&chip->wakeup_wakelock.lock, WAKE_LOCK_SUSPEND, chip->wakeup_wakelock.name);
    hrtimer_init(&chip->unlock_wakelock_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
    chip->unlock_wakelock_timer.function = hall_device_unlock_wakelock_work_func;


    SENSOR_LOG_INFO("prob success\n");

    return 0;

input_register_failed:
    input_free_device(chip->idev);
input_alloc_failed:
malloc_failed:
irq_n_register_fail:
irq_s_register_fail:
create_hall_device_dev_failed:
    chip->hall_device_dev = NULL;
    class_destroy(hall_device_class);
    SENSOR_LOG_INFO("prob failed\n");

    return -1;

}
/*
int anx7816_get_sbl_cable_type(void)
{
	int cable_type = 0;
	unsigned int *p_cable_type = (unsigned int *)
		(smem_get_entry(SMEM_ID_VENDOR1, &cable_smem_size));

	if (p_cable_type)
		cable_type = *p_cable_type;
	else
		cable_type = 0;

	return cable_type;
}
*/
static int anx7816_i2c_probe(struct i2c_client *client,
			const struct i2c_device_id *id)
{

	struct anx7816_data *anx7816;
	struct anx7816_platform_data *pdata;
	int ret = 0;
	//int sbl_cable_type = 0;

	pr_err("%s %s start\n", LOG_TAG, __func__);

#ifdef SP_REGISTER_SET_TEST
	val_SP_TX_LT_CTRL_REG0 = 0x01;
	val_SP_TX_LT_CTRL_REG1 = 0x03;
	val_SP_TX_LT_CTRL_REG2 = 0x57;
	val_SP_TX_LT_CTRL_REG3 = 0x7f;
	val_SP_TX_LT_CTRL_REG4 = 0x71;
	val_SP_TX_LT_CTRL_REG5 = 0x6b;
	val_SP_TX_LT_CTRL_REG6 = 0x7f;
	val_SP_TX_LT_CTRL_REG7 = 0x73;
	val_SP_TX_LT_CTRL_REG8 = 0x7f;
	val_SP_TX_LT_CTRL_REG9 = 0x7f;
	val_SP_TX_LT_CTRL_REG10 = 0x00;
	val_SP_TX_LT_CTRL_REG11 = 0x00;
	val_SP_TX_LT_CTRL_REG12 = 0x02;
	val_SP_TX_LT_CTRL_REG13 = 0x00;
	val_SP_TX_LT_CTRL_REG14 = 0x0c;
	val_SP_TX_LT_CTRL_REG15 = 0x42;
	val_SP_TX_LT_CTRL_REG16 = 0x2f;
	val_SP_TX_LT_CTRL_REG17 = 0x3e;
	val_SP_TX_LT_CTRL_REG18 = 0x77;
	val_SP_TX_LT_CTRL_REG19 = 0x7e;
#endif
	if (!i2c_check_functionality(client->adapter,
		I2C_FUNC_SMBUS_I2C_BLOCK)) {
		pr_err("%s: i2c bus does not support the anx7816\n", __func__);
		ret = -ENODEV;
		goto exit;
	}

	anx7816 = kzalloc(sizeof(struct anx7816_data), GFP_KERNEL);
	if (!anx7816) {
		pr_err("%s: failed to allocate driver data\n", __func__);
		ret = -ENOMEM;
		goto exit;
	}

	if (client->dev.of_node) {
		pdata = devm_kzalloc(&client->dev,
							 sizeof(struct anx7816_platform_data),
							 GFP_KERNEL);
		if (!pdata) {
			pr_err("%s: Failed to allocate memory\n", __func__);
			ret = -ENOMEM;
			goto err0;
		}
		client->dev.platform_data = pdata;
	/* device tree parsing function call */
		ret = anx7816_parse_dt(&client->dev, pdata);
		if (ret != 0) /* if occurs error */
			goto err0;

		anx7816->pdata = pdata;
	} else {
		anx7816->pdata = client->dev.platform_data;
	}

	/* to access global platform data */
	g_pdata = anx7816->pdata;

	anx7816_client = client;

	mutex_init(&anx7816->lock);

	if (!anx7816->pdata) {
		ret = -EINVAL;
		goto err0;
	}

	ret = anx7816_init_gpio(anx7816);
	if (ret) {
		pr_err("%s: failed to initialize gpio\n", __func__);
		goto err0;
	}

	INIT_DELAYED_WORK(&anx7816->work, anx7816_work_func);
/*	INIT_DELAYED_WORK(&anx7816->dwc3_ref_clk_work, dwc3_ref_clk_work_func); */

	anx7816->workqueue = create_singlethread_workqueue("anx7816_work");
	if (anx7816->workqueue == NULL) {
		pr_err("%s: failed to create work queue\n", __func__);
		ret = -ENOMEM;
		goto err1;
	}

	//anx7816->pdata->avdd_power(1);
	//anx7816->pdata->dvdd_power(1);

	ret = anx7816_system_init();
	if (ret) {
		pr_err("%s: failed to initialize anx7816\n", __func__);
		goto err2;
	}

	client->irq = gpio_to_irq(anx7816->pdata->gpio_cbl_det);
	if (client->irq < 0) {
		pr_err("%s : failed to get gpio irq\n", __func__);
		goto err2;
	}

	wake_lock_init(&anx7816->slimport_lock,
				WAKE_LOCK_SUSPEND,
				"slimport_wake_lock");

#if 0
	sbl_cable_type = anx7816_get_sbl_cable_type();

	if ((lge_get_laf_mode() != LGE_LAF_MODE_LAF) &&
	(sbl_cable_type != CBL_910K)) {
#else
	if ((lge_get_boot_mode() != LGE_BOOT_MODE_QEM_910K) &&
	(lge_get_boot_mode() != LGE_BOOT_MODE_PIF_910K)) {
#endif
		ret = request_threaded_irq(client->irq, NULL, anx7816_cbl_det_isr,
						IRQF_TRIGGER_RISING
						| IRQF_TRIGGER_FALLING
						| IRQF_ONESHOT,
						"anx7816", anx7816);
		if (ret  < 0) {
			pr_err("%s : failed to request irq\n", __func__);
			goto err2;
		}

		ret = irq_set_irq_wake(client->irq, 1);
		if (ret  < 0) {
			pr_err("%s : Request irq for cable detect", __func__);
			pr_err("interrupt wake set fail\n");
			goto err3;
		}

		ret = enable_irq_wake(client->irq);
		if (ret  < 0) {
			pr_err("%s : Enable irq for cable detect", __func__);
			pr_err("interrupt wake enable fail\n");
			goto err3;
		}
	} else {
#if 0
		pr_err("%s %s : %s, Disable cbl det irq!!\n", LOG_TAG, __func__,
			sbl_cable_type == CBL_910K ? "910K Cable Connected" : "Laf Mode");
#else
		pr_err("%s %s: 910K Cable Connected. Disable cbl det irq!!\n", LOG_TAG, __func__);
#endif
	}

	ret = create_sysfs_interfaces(&client->dev);
	if (ret < 0) {
		pr_err("%s : sysfs register failed", __func__);
		goto err3;
	}
#ifdef CONFIG_SLIMPORT_DYNAMIC_HPD
	hdmi_slimport_ops = devm_kzalloc(&client->dev,
				    sizeof(struct msm_hdmi_slimport_ops),
				    GFP_KERNEL);
	if (!hdmi_slimport_ops) {
		pr_err("%s: alloc hdmi slimport ops failed\n", __func__);
		ret = -ENOMEM;
		goto err3;
	}

	if (anx7816->pdata->hdmi_pdev) {
		ret = msm_hdmi_register_slimport(anx7816->pdata->hdmi_pdev,
					   hdmi_slimport_ops, anx7816);
		if (ret) {
			pr_err("%s: register with hdmi failed\n", __func__);
			ret = -EPROBE_DEFER;
			goto err3;
		}
	}
#endif
	pr_info("%s %s end\n", LOG_TAG, __func__);
	goto exit;

err3:
	free_irq(client->irq, anx7816);
err2:
	destroy_workqueue(anx7816->workqueue);
err1:
	anx7816_free_gpio(anx7816);
err0:
	anx7816_client = NULL;
	kfree(anx7816);
exit:
	return ret;
}

static int anx7816_i2c_remove(struct i2c_client *client)
{
	struct anx7816_data *anx7816 = i2c_get_clientdata(client);
	int i = 0;
	for (i = 0; i < ARRAY_SIZE(slimport_device_attrs); i++)
		device_remove_file(&client->dev, &slimport_device_attrs[i]);
	pr_err("anx7816_i2c_remove\n");
	sp_tx_clean_state_machine();
	destroy_workqueue(anx7816->workqueue);
	sp_tx_hardware_powerdown();
	free_irq(client->irq, anx7816);
	anx7816_free_gpio(anx7816);
	wake_lock_destroy(&anx7816->slimport_lock);
	kfree(anx7816);
	return 0;
}

bool is_slimport_vga(void)
{
	return ((sp_tx_cur_cable_type() == DWN_STRM_IS_VGA_9832)
		|| (sp_tx_cur_cable_type() == DWN_STRM_IS_ANALOG)) ? 1 : 0;
}
/* 0x01: hdmi device is attached
    0x02: DP device is attached
    0x03: Old VGA device is attached // RX_VGA_9832
    0x04: new combo VGA device is attached // RX_VGA_GEN
    0x00: unknow device            */
EXPORT_SYMBOL(is_slimport_vga);
bool is_slimport_dp(void)
{
	return (sp_tx_cur_cable_type() == DWN_STRM_IS_DIGITAL) ? TRUE : FALSE;
}
EXPORT_SYMBOL(is_slimport_dp);
unchar sp_get_link_bw(void)
{
	return sp_tx_cur_bw();
}
EXPORT_SYMBOL(sp_get_link_bw);
void sp_set_link_bw(unchar link_bw)
{
	sp_tx_set_bw(link_bw);
}
Ejemplo n.º 13
0
static int yas_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
{
	struct yas_state *st;
	struct iio_dev *indio_dev;
	int ret, i;
	struct yas_acc_platform_data *pdata;

	this_client = i2c;
	printk("%s: yas_kionix_accel_probe start ---\n", __FUNCTION__);

	indio_dev = iio_device_alloc(sizeof(*st));
	if (!indio_dev) {
		ret = -ENOMEM;
		goto error_ret;
	}
	i2c_set_clientdata(i2c, indio_dev);

	indio_dev->name = id->name;
	indio_dev->dev.parent = &i2c->dev;
	indio_dev->info = &yas_info;
	indio_dev->channels = yas_channels;
	indio_dev->num_channels = ARRAY_SIZE(yas_channels);
	indio_dev->modes = INDIO_DIRECT_MODE;

	st = iio_priv(indio_dev);
	st->client = i2c;
	st->sampling_frequency = 20;
	st->acc.callback.device_open = yas_device_open;
	st->acc.callback.device_close = yas_device_close;
	st->acc.callback.device_read = yas_device_read;
	st->acc.callback.device_write = yas_device_write;
	st->acc.callback.usleep = yas_usleep;
	st->acc.callback.current_time = yas_current_time;
	st->indio_dev = indio_dev;
	INIT_DELAYED_WORK(&st->work, yas_work_func);
	mutex_init(&st->lock);
#ifdef CONFIG_HAS_EARLYSUSPEND
	st->sus.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	st->sus.suspend = yas_early_suspend;
	st->sus.resume = yas_late_resume;
	register_early_suspend(&st->sus);
#endif
	for (i = 0; i < 3; i++) {
		st->compass_data[i] = 0;
		st->calib_bias[i] = 0;
	}

	ret = yas_probe_buffer(indio_dev);
	if (ret)
		goto error_free_dev;
	ret = yas_probe_trigger(indio_dev);
	if (ret)
		goto error_remove_buffer;
	ret = iio_device_register(indio_dev);
	if (ret)
		goto error_remove_trigger;
	ret = yas_acc_driver_init(&st->acc);
	if (ret < 0) {
		ret = -EFAULT;
		goto error_unregister_iio;
	}
	ret = st->acc.init();
	if (ret < 0) {
		ret = -EFAULT;
		goto error_unregister_iio;
	}
	ret = st->acc.set_enable(1);
	if (ret < 0) {
		ret = -EFAULT;
		goto error_driver_term;
	}

	init_irq_work(&st->iio_irq_work, iio_trigger_work);
	g_st = st;

	ret = create_sysfs_interfaces(st);
	if (ret) {
		printk(KERN_ERR"%s: create_sysfs_interfaces fail, ret = %d\n",
		  __func__, ret);
		goto err_create_fixed_sysfs;
	}

	return 0;

err_create_fixed_sysfs:
	kfree(pdata);
error_driver_term:
	st->acc.term();
error_unregister_iio:
	iio_device_unregister(indio_dev);
error_remove_trigger:
	yas_remove_trigger(indio_dev);
error_remove_buffer:
	yas_remove_buffer(indio_dev);
error_free_dev:
#ifdef CONFIG_HAS_EARLYSUSPEND
	unregister_early_suspend(&st->sus);
#endif
	iio_device_free(indio_dev);
error_ret:
	i2c_set_clientdata(i2c, NULL);
	this_client = NULL;
	return ret;
}
static int felica_probe(struct platform_device *pdev)
{
	int ret;
	struct felica_dev *dev;
	struct felica_platform_data *flc_pfdata;

	dev_info(&pdev->dev, "FeliCa driver being loaded\n");

	flc_pfdata = pdev->dev.platform_data;
	if (NULL == flc_pfdata) {
		dev_err(&pdev->dev, "%s: No platform data\n", __func__);
		ret = -EINVAL;
		goto err_get_platform_data;
	}

	dev = kzalloc(sizeof(struct felica_dev), GFP_KERNEL);
	if (!dev) {
		dev_err(&pdev->dev, "%s: no memory\n", __func__);
		ret = -ENOMEM;
		goto err_alloc_data;
	}

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

	dev->device_cen.minor = MISC_DYNAMIC_MINOR;
	dev->device_cen.name = "felica_cen";
	dev->device_cen.fops = &felica_cen_fops;

	dev->device_pon.minor = MISC_DYNAMIC_MINOR;
	dev->device_pon.name = "felica_pon";
	dev->device_pon.fops = &felica_pon_fops;

	dev->device_rfs.minor = MISC_DYNAMIC_MINOR;
	dev->device_rfs.name = "felica_rfs";
	dev->device_rfs.fops = &felica_rfs_fops;

	dev->device_rws.minor = MISC_DYNAMIC_MINOR;
	dev->device_rws.name = "felica_rws";
	dev->device_rws.fops = &felica_rws_fops;

#ifdef CONFIG_SONY_FELICA_NFC_SUPPORT
	dev->device_hsel.minor = MISC_DYNAMIC_MINOR;
	dev->device_hsel.name = "snfc_hsel";
	dev->device_hsel.fops = &snfc_hsel_fops;

	dev->device_intu_poll.minor = MISC_DYNAMIC_MINOR;
	dev->device_intu_poll.name = "snfc_intu_poll";
	dev->device_intu_poll.fops = &snfc_intu_poll_fops;

	dev->device_available_poll.minor = MISC_DYNAMIC_MINOR;
	dev->device_available_poll.name = "snfc_available_poll";
	dev->device_available_poll.fops = &snfc_available_poll_fops;
#endif

	dev->flcen = &flc_pfdata->cen_pfdata;
	dev->flpon = &flc_pfdata->pon_pfdata;
	dev->flrfs = &flc_pfdata->rfs_pfdata;
	dev->flint = &flc_pfdata->int_pfdata;
#ifdef CONFIG_SONY_FELICA_NFC_SUPPORT
	dev->flintu = &flc_pfdata->intu_pfdata;
	dev->flhsel = &flc_pfdata->hsel_pfdata;
	dev->flldo = &flc_pfdata->ldo_pfdata;
#endif

	ret = flc_pfdata->gpio_init(dev);
	if (ret && -EBUSY != ret) {
		dev_err(&pdev->dev, "%s: GPIO init failed\n", __func__);
		goto error_gpio_init;
	}

	ret = felica_cen_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: CEN probe failure\n", __func__);
		goto err_cen_probe;
	}

	ret = felica_pon_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: PON probe failure\n", __func__);
		goto err_pon_probe;
	}

	ret = felica_rfs_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: RFS probe failure\n", __func__);
		goto err_rfs_probe;
	}

	ret = felica_int_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: INT probe failure\n", __func__);
		goto err_int_probe;
	}

	ret = felica_rws_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: RWS probe failure\n", __func__);
		goto err_rws_probe;
	}

#ifdef CONFIG_SONY_FELICA_NFC_SUPPORT
	ret = snfc_hsel_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: SNFC HSEL probe failure\n",
				__func__);
		goto err_snfc_hsel_probe;
	}

	ret = snfc_intu_poll_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: SNFC INTU POLL probe failure\n",
				__func__);
		goto err_snfc_intu_poll_probe;
	}

	ret = snfc_available_poll_probe_func(dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: SNFC AVAILABLE POLL probe failure\n",
				__func__);
		goto err_snfc_available_poll_probe;
	}

	init_waitqueue_head(&dev->available_poll_wait);
	dev->available_poll_snfc = 0;
#endif

	ret = create_sysfs_interfaces(&pdev->dev);
	if (ret) {
		dev_err(&pdev->dev, "%s: failed to create dev. attrs\n",
				__func__);
		goto err_create_sysfs;
	}

	return 0;

err_create_sysfs:
#ifdef CONFIG_SONY_FELICA_NFC_SUPPORT
	snfc_available_poll_remove_func(dev);
err_snfc_available_poll_probe:
	snfc_intu_poll_remove_func(dev);
err_snfc_intu_poll_probe:
	snfc_hsel_remove_func(dev);
err_snfc_hsel_probe:
#endif
	felica_rws_remove_func(dev);
err_rws_probe:
	felica_int_remove_func(dev);
err_int_probe:
	felica_rfs_remove_func(dev);
err_rfs_probe:
	felica_pon_remove_func(dev);
err_pon_probe:
	felica_cen_remove_func(dev);
err_cen_probe:
	flc_pfdata->reg_release(dev);
error_gpio_init:
	kfree(dev);
err_alloc_data:
err_get_platform_data:

	return ret;
}
static int __devinit lsm303dlh_mag_probe(struct i2c_client *client,
				  const struct i2c_device_id *id)
{
	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
	struct lsm303dlh_mag_platform_data *pdata = client->dev.platform_data;
	struct lsm303dlh_mag_data *mag;
	int result = 0;

	dev_info(&client->dev, "%s\n", __func__);
	if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
		result = -EIO;
		goto err_check_functionality;
	}
	if (!pdata) {
		result = -EINVAL;
		dev_err(&client->dev, "%s: platform data required.\n",
			__func__);
		goto err_no_platform_data;
	}
	mag = kzalloc(sizeof(*mag), GFP_KERNEL);
	if (NULL == mag) {
		result = -ENOMEM;
		goto err_alloc_data_failed;
	}
	mag->client = client;
	mag->poll_interval_ms = pdata->poll_interval_ms;
	mag->range = pdata->range;
	i2c_set_clientdata(client, mag);
	if (pdata->power_on)
		mag->power_on = pdata->power_on;
	else
		mag->power_on = lsm303dlh_mag_power_stub;
	if (pdata->power_off)
		mag->power_off = pdata->power_off;
	else
		mag->power_off = lsm303dlh_mag_power_stub;
	mag->power_on();
	result = i2c_smbus_write_byte_data(client, MR_REG_M, IDLE_MODE);
	mag->power_off();
	if (result) {
		dev_err(&client->dev, "%s: Device not responding.\n",
			__func__);
		goto err_not_responding;
	}
	INIT_DELAYED_WORK(&mag->work, lsm303dlh_mag_poll_func);
	mutex_init(&mag->lock);
	result = create_sysfs_interfaces(&client->dev);
	if (result)
		goto err_sys_attr;
	mag->input_dev = input_allocate_device();
	if (!mag->input_dev) {
		dev_err(&client->dev, "%s: input_allocate_device failed\n",
			__func__);
		result = -ENOMEM;
		goto err_allocate_device;
	}
	input_set_drvdata(mag->input_dev, mag);

	mag->input_dev->open = lsm303dlh_mag_open;
	mag->input_dev->close = lsm303dlh_mag_close;
	mag->input_dev->name = LSM303DLH_MAG_DEV_NAME;
	set_bit(EV_ABS, mag->input_dev->evbit);
	set_bit(ABS_X, mag->input_dev->absbit);
	set_bit(ABS_Y, mag->input_dev->absbit);
	set_bit(ABS_Z, mag->input_dev->absbit);
	input_set_abs_params(mag->input_dev, ABS_X, -MAG_RANGE_MG,
			MAG_RANGE_MG - 1, 0, 0);
	input_set_abs_params(mag->input_dev, ABS_Y, -MAG_RANGE_MG,
			MAG_RANGE_MG - 1, 0, 0);
	input_set_abs_params(mag->input_dev, ABS_Z, -MAG_RANGE_MG,
			MAG_RANGE_MG - 1, 0, 0);

	result = input_register_device(mag->input_dev);
	if (result) {
		dev_err(&client->dev, "%s: input_register_device failed!",
			__func__);
		goto err_register_device;
	}

	dev_info(&client->dev, "%s completed.\n", __func__);
	return 0;

err_register_device:
	input_free_device(mag->input_dev);
err_allocate_device:
	remove_sysfs_interfaces(&client->dev);
err_sys_attr:
err_not_responding:
	kfree(mag);
err_alloc_data_failed:
err_no_platform_data:
err_check_functionality:
	dev_err(&client->dev, "%s failed.\n", __func__);
	return result;
}
Ejemplo n.º 16
0
static int bcm2079x_probe(struct i2c_client *client,
			   const struct i2c_device_id *id)
{
	int ret;
	struct bcm2079x_dev *bcm2079x_dev;
	struct bcm2079x_platform_data *platform_data;

	/*platform_data = client->dev.platform_data;

	dev_info(&client->dev, "%s, probing bcm2079x driver flags = %x\n", __func__, client->flags);
	if (platform_data == NULL) {
		dev_err(&client->dev, "nfc probe fail\n");
		return -ENODEV;
	}*/

	if (client ->dev.of_node) {
		platform_data = devm_kzalloc(&client ->dev,sizeof(struct bcm2079x_platform_data), GFP_KERNEL);
		if (!platform_data) {
			dev_err(&client ->dev, "Failed to allocate memory \n");
		return -ENOMEM;
		}
		
		ret = bcm2079x_parse_dt(&client ->dev, platform_data);
		
		if (ret)
			return ret;
	}

	nfc_pinctrl_init(&client->dev);
	
	//ret = pinctrl_select_state(bcm2079x_pctrl.pinctrl,
	//		bcm2079x_pctrl.nfc_gpio_state_active);
	//	if (ret)
	//		pr_err("%s:%d cannot set pin to nfc_gpio_state_active state",
	//			__func__, __LINE__);
	
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		dev_err(&client->dev, "need I2C_FUNC_I2C\n");
		return -ENODEV;
	}

	ret = gpio_request(platform_data->irq_gpio, "nfc_int");
	if (ret)
		return -ENODEV;
	ret = gpio_request(platform_data->en_gpio, "nfc_ven");
	if (ret)
		goto err_en;
	ret = gpio_request(platform_data->wake_gpio, "nfc_firm");
	if (ret)
		goto err_firm;

	gpio_direction_output(platform_data->en_gpio, 0 );
	gpio_direction_output(platform_data->wake_gpio, 0);
	gpio_set_value(platform_data->en_gpio, 0);
	gpio_set_value(platform_data->wake_gpio, 0);

	gpio_direction_input(platform_data->irq_gpio );

	bcm2079x_dev = kzalloc(sizeof(*bcm2079x_dev), GFP_KERNEL);
	if (bcm2079x_dev == NULL) {
		dev_err(&client->dev,
			"failed to allocate memory for module data\n");
		ret = -ENOMEM;
		goto err_exit;
	}

	bcm2079x_dev->wake_gpio = platform_data->wake_gpio;
	bcm2079x_dev->irq_gpio = platform_data->irq_gpio;
	bcm2079x_dev->en_gpio = platform_data->en_gpio;
	bcm2079x_dev->client = client;

	/* init mutex and queues */
	init_waitqueue_head(&bcm2079x_dev->read_wq);
	mutex_init(&bcm2079x_dev->read_mutex);
	spin_lock_init(&bcm2079x_dev->irq_enabled_lock);

	bcm2079x_dev->bcm2079x_device.minor = MISC_DYNAMIC_MINOR;
	bcm2079x_dev->bcm2079x_device.name = "bcm2079x";
	bcm2079x_dev->bcm2079x_device.fops = &bcm2079x_dev_fops;

	ret = misc_register(&bcm2079x_dev->bcm2079x_device);
	if (ret) {
		dev_err(&client->dev, "misc_register failed\n");
		goto err_misc_register;
	}

	dev_info(&client->dev,
		 "%s, saving address %d\n",
		 __func__, client->addr);
    bcm2079x_dev->original_address = client->addr;

	//enable clk 19.2M 
	printk("[dsc] enable clk 19.2M\n");
	nfc_rf_clk = clk_get(&client->dev, "ref_clk");
	if (nfc_rf_clk != NULL) {
		if (clk_prepare_enable(nfc_rf_clk))
			pr_err("failed request NFC_CLK.\n");
	} else {
			pr_err("%s:nfc_rf_clk is null\n",__FUNCTION__);
	}

	/* request irq.  the irq is set whenever the chip has data available
	 * for reading.  it is cleared when all data has been read.
	 */
	dev_info(&client->dev, "requesting IRQ %d with IRQF_NO_SUSPEND\n", client->irq);
	bcm2079x_dev->irq_enabled = true;
	ret = request_irq(client->irq, bcm2079x_dev_irq_handler,
			  IRQF_TRIGGER_RISING|IRQF_NO_SUSPEND, client->name, bcm2079x_dev);
	if (ret) {
		dev_err(&client->dev, "request_irq failed\n");
		goto err_request_irq_failed;
	}
	enable_irq_wake(client->irq);
	bcm2079x_disable_irq(bcm2079x_dev);
	i2c_set_clientdata(client, bcm2079x_dev);
#ifdef ZTEMT_FOR_NFC_PIN_TEST
	ret= create_sysfs_interfaces(&client->dev);
	if (ret < 0) 
    {
		dev_err(&client->dev,
		   "device drv2605 sysfs register failed\n");
		return ret;
	}
#endif 
	dev_info(&client->dev,
		 "%s, probing bcm2079x driver exited successfully\n",
		 __func__);

#ifdef USE_WAKE_LOCK
	wake_lock_init(&bcm2079x_dev->wake_lock , WAKE_LOCK_SUSPEND, "nfcwakelock" );
#endif
	return 0;

err_request_irq_failed:
	misc_deregister(&bcm2079x_dev->bcm2079x_device);
err_misc_register:
	mutex_destroy(&bcm2079x_dev->read_mutex);
	kfree(bcm2079x_dev);
err_exit:
	gpio_free(platform_data->wake_gpio);
err_firm:
	gpio_free(platform_data->en_gpio);
err_en:
	gpio_free(platform_data->irq_gpio);
	return ret;
}
int felica_snfc_register(struct device *dev, struct felica_data *felica_data)
{
	int ret;
	struct felica_dev *d;

	dev_dbg(dev, "%s\n", __func__);

	if (reg_device) {
		dev_err(dev, "%s: felica_snfc was registered.\n",  __func__);
		ret =  -EBUSY;
		goto err_inval;
	}

	if (!dev) {
		dev_err(dev, "%s: device is null.\n",  __func__);
		ret =  -EINVAL;
		goto err_inval;
	}
	if (!felica_data) {
		dev_err(dev, "%s: felica_data is null.\n",  __func__);
		ret =  -EINVAL;
		goto err_inval;
	}
	if (!felica_data->flcen || !felica_data->flpon ||
		!felica_data->flrfs || !felica_data->flint) {
		dev_err(dev, "%s: felica ops is null.\n",  __func__);
		ret =  -EINVAL;
		goto err_inval;
	}
	if (FELICA_SNFC == felica_data->type &&
		(!felica_data->flintu || !felica_data->flhsel ||
		!felica_data->flldo)) {
		dev_err(dev, "%s: nfc ops is null.\n",  __func__);
		ret =  -EINVAL;
		goto err_inval;
	}

	d = kzalloc(sizeof(struct felica_dev), GFP_KERNEL);
	if (!d) {
		dev_err(dev, "%s: no memory\n", __func__);
		ret = -ENOMEM;
		goto err_alloc;
	}
	d->felica_data = felica_data;
	d->irq_shutdown = true;

	d->device_cen.minor = MISC_DYNAMIC_MINOR;
	d->device_cen.name = "felica_cen";
	d->device_cen.fops = &felica_cen_fops;

	d->device_pon.minor = MISC_DYNAMIC_MINOR;
	d->device_pon.name = "felica_pon";
	d->device_pon.fops = &felica_pon_fops;

	d->device_rfs.minor = MISC_DYNAMIC_MINOR;
	d->device_rfs.name = "felica_rfs";
	d->device_rfs.fops = &felica_rfs_fops;

	d->device_rws.minor = MISC_DYNAMIC_MINOR;
	d->device_rws.name = "felica_rws";
	d->device_rws.fops = &felica_rws_fops;

	if (FELICA_SNFC == felica_data->type) {
		d->device_hsel.minor = MISC_DYNAMIC_MINOR;
		d->device_hsel.name = "snfc_hsel";
		d->device_hsel.fops = &nfc_hsel_fops;

		d->device_intu_poll.minor = MISC_DYNAMIC_MINOR;
		d->device_intu_poll.name = "snfc_intu_poll";
		d->device_intu_poll.fops = &nfc_intu_poll_fops;

		d->device_available_poll.minor = MISC_DYNAMIC_MINOR;
		d->device_available_poll.name = "snfc_available_poll";
		d->device_available_poll.fops = &nfc_available_poll_fops;
	}

	d->dev = dev;
	dev_set_drvdata(dev, d);

	ret = felica_cen_probe_func(d);
	if (ret) {
		dev_err(dev, "%s: CEN probe failure\n", __func__);
		goto err_cen_probe;
	}

	ret = felica_pon_probe_func(d);
	if (ret) {
		dev_err(dev, "%s: PON probe failure\n", __func__);
		goto err_pon_probe;
	}

	ret = felica_rfs_probe_func(d);
	if (ret) {
		dev_err(dev, "%s: RFS probe failure\n", __func__);
		goto err_rfs_probe;
	}

	ret = felica_int_probe_func(d);
	if (ret) {
		dev_err(dev, "%s: INT probe failure\n", __func__);
		goto err_int_probe;
	}

	ret = felica_rws_probe_func(d);
	if (ret) {
		dev_err(dev, "%s: RWS probe failure\n", __func__);
		goto err_rws_probe;
	}

	if (FELICA_SNFC == felica_data->type) {
		ret = nfc_hsel_probe_func(d);
		if (ret) {
			dev_err(dev, "%s: NFC HSEL probe failure\n", __func__);
			goto err_nfc_hsel_probe;
		}

		ret = nfc_intu_poll_probe_func(d);
		if (ret) {
			dev_err(dev, "%s: NFC INTU POLL probe failure\n",
				__func__);
			goto err_nfc_intu_poll_probe;
		}
		init_waitqueue_head(&d->intu_wait_queue);

		ret = nfc_available_poll_probe_func(d);
		if (ret) {
			dev_err(dev, "%s: NFC AVAILABLE POLL probe failure\n",
				__func__);
			goto err_nfc_available_poll_probe;
		}
		init_waitqueue_head(&d->available_poll_wait);
		d->available_poll_nfc = 0;
	}
	d->sysfs_dev.init_name = "felica_snfc";
	dev_set_drvdata(&d->sysfs_dev, d);
	ret = device_register(&d->sysfs_dev);
	if (ret) {
		dev_err(dev, "%s: failed to register device.\n", __func__);
		goto err_register_device;
	}

	ret = create_sysfs_interfaces(&d->sysfs_dev);
	if (ret) {
		dev_err(dev, "%s: failed to create dev.\n", __func__);
		goto err_create_sysfs;
	}

	reg_device = dev;

	return 0;

err_create_sysfs:
	device_unregister(&d->sysfs_dev);
err_register_device:
	nfc_available_poll_remove_func(d);
err_nfc_available_poll_probe:
	nfc_intu_poll_remove_func(d);
err_nfc_intu_poll_probe:
	nfc_hsel_remove_func(d);
err_nfc_hsel_probe:
	felica_rws_remove_func(d);
err_rws_probe:
	felica_int_remove_func(d);
err_int_probe:
	felica_rfs_remove_func(d);
err_rfs_probe:
	felica_pon_remove_func(d);
err_pon_probe:
	felica_cen_remove_func(d);
err_cen_probe:
	kfree(d);
err_alloc:
err_inval:
	return ret;
}
Ejemplo n.º 18
0
static int __devinit lsm303dlhc_mag_probe(struct i2c_client *client,
        const struct i2c_device_id *id)
{
    struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
    struct lsm303dlhc_mag_platform_data *pdata = client->dev.platform_data;
    struct lsm303dlhc_mag_data *mag;
    int result = 0;

    dev_info(&client->dev, "%s \n", __func__);

    if (!pdata) {
        result = -EINVAL;
        dev_err(&client->dev, "%s: platform data required.\n",
                __func__);
        goto err_no_platform_data;
    }
    mag = kzalloc(sizeof(*mag), GFP_KERNEL);
    if (NULL == mag) {
        result = -ENOMEM;
        goto err_alloc_data_failed;
    }
    mag->client = client;
    mag->poll_interval_ms = pdata->poll_interval_ms;
    mag->range = pdata->range;
    dev_info(&client->dev, "%s:pdata->range:%d\n", __func__, pdata->range);
    i2c_set_clientdata(client, mag);
    if (pdata->power_on)
        mag->power_on = pdata->power_on;
    else
        mag->power_on = lsm303dlhc_mag_power_stub;
    if (pdata->power_off)
        mag->power_off = pdata->power_off;
    else
        mag->power_off = lsm303dlhc_mag_power_stub;
    mag->power_on();
    lsm303dlhc_mag_config_regulator( mag , true);
    msleep(500);
    if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
        result = -EIO;
        goto err_check_functionality;
    }
    result = i2c_smbus_write_byte_data(client, MR_REG_M, IDLE_MODE);
    mag->power_off();
    lsm303dlhc_mag_config_regulator( mag , false);
    if (result) {
        dev_err(&client->dev, "%s: Device not responding.\n",
                __func__);
        goto err_not_responding;
    }
    INIT_DELAYED_WORK(&mag->work, lsm303dlhc_mag_poll_func);
    mutex_init(&mag->lock);

    mag->dev = sensors_classdev_register("magnetometer");

    result = create_sysfs_interfaces(mag->dev);
    if (result)
        goto err_sys_attr;
    dev_set_drvdata(mag->dev, mag);
    mag->input_dev = input_allocate_device();
    if (!mag->input_dev) {
        dev_err(&client->dev, "%s: input_allocate_device failed\n",
                __func__);
        result = -ENOMEM;
        goto err_allocate_device;
    }
    input_set_drvdata(mag->input_dev, mag);

    mag->input_dev->name = "magnetometer";
    set_bit(EV_ABS, mag->input_dev->evbit);
    set_bit(ABS_X, mag->input_dev->absbit);
    set_bit(ABS_Y, mag->input_dev->absbit);
    set_bit(ABS_Z, mag->input_dev->absbit);
    input_set_abs_params(mag->input_dev, ABS_X, -MAG_RANGE_MG,
                         MAG_RANGE_MG - 1, 0, 0);
    input_set_abs_params(mag->input_dev, ABS_Y, -MAG_RANGE_MG,
                         MAG_RANGE_MG - 1, 0, 0);
    input_set_abs_params(mag->input_dev, ABS_Z, -MAG_RANGE_MG,
                         MAG_RANGE_MG - 1, 0, 0);

    result = input_register_device(mag->input_dev);
    if (result) {
        dev_err(&client->dev, "%s: input_register_device failed!",
                __func__);
        goto err_register_device;
    }
    dev_set_drvdata(&mag->input_dev->dev, mag);

    if (device_create_file(&mag->input_dev->dev,
                           &dev_attr_enable) < 0) {
        pr_err("%s: Failed to create device file(%s)!\n", __func__,
               dev_attr_enable.attr.name);
        goto err_check_functionality;
    }

    mag->irq_m = pdata->irq_m;
    if (mag->irq_m > 0) { /* interrupt */

        mag->interruptible = true;
        result = request_threaded_irq(gpio_to_irq(mag->irq_m), NULL,
                                      lsm303dlhc_m_gpio_irq,
                                      IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "lsm303dlhc_m",
                                      mag);
        if (result) {
            dev_err(&client->dev, "request irq EGPIO_PIN_1 failed\n");
            goto err_check_functionality;
        }

        disable_irq(gpio_to_irq(mag->irq_m));
    }
    mag->interruptible = false;
    dev_info(&client->dev, "%s mag->interruptible=%d completed.\n", __func__, mag->interruptible);
    return 0;

err_register_device:
    input_free_device(mag->input_dev);
err_allocate_device:
    remove_sysfs_interfaces(mag->dev);
err_sys_attr:
err_not_responding:
    kfree(mag);
err_alloc_data_failed:
err_no_platform_data:
err_check_functionality:
    dev_err(&client->dev, "%s failed.\n", __func__);
    return result;
}