static int __devinit rmi_i2c_probe(struct i2c_client *client,
                                   const struct i2c_device_id *id)
{
    struct rmi_phys_device *rmi_phys;
    struct rmi_i2c_data *data;
    struct rmi_device_platform_data *pdata = client->dev.platform_data;
    int error;

    if (!pdata) {
        dev_err(&client->dev, "no platform data\n");
        return -EINVAL;
    }
    pr_info("%s: Probing %s at %#02x (IRQ %d).\n", __func__,
            pdata->sensor_name ? pdata->sensor_name : "-no name-",
            client->addr, pdata->attn_gpio);

    error = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
    if (!error) {
        dev_err(&client->dev, "i2c_check_functionality error %d.\n",
                error);
        return error;
    }

    rmi_phys = kzalloc(sizeof(struct rmi_phys_device), GFP_KERNEL);
    if (!rmi_phys)
        return -ENOMEM;

    data = kzalloc(sizeof(struct rmi_i2c_data), GFP_KERNEL);
    if (!data) {
        error = -ENOMEM;
        goto err_phys;
    }

    data->enabled = true;	/* We plan to come up enabled. */
    data->irq = gpio_to_irq(pdata->attn_gpio);
    data->irq_flags = (pdata->attn_polarity == RMI_ATTN_ACTIVE_HIGH) ?
                      IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
    data->phys = rmi_phys;

    rmi_phys->data = data;
    rmi_phys->dev = &client->dev;

    rmi_phys->write = rmi_i2c_write;
    rmi_phys->write_block = rmi_i2c_write_block;
    rmi_phys->read = rmi_i2c_read;
    rmi_phys->read_block = rmi_i2c_read_block;
    rmi_phys->enable_device = enable_device;
    rmi_phys->disable_device = disable_device;

    rmi_phys->info.proto = phys_proto_name;

    mutex_init(&data->page_mutex);

    mdelay(1000);

    /* Setting the page to zero will (a) make sure the PSR is in a
     * known state, and (b) make sure we can talk to the device.
     */
    error = rmi_set_page(rmi_phys, 0);
    if (error) {
        dev_err(&client->dev, "Failed to set page select to 0.\n");
        goto err_data;
    }

    if (pdata->gpio_config) {
        error = pdata->gpio_config(pdata->gpio_data, true);
        if (error < 0) {
            dev_err(&client->dev, "failed to setup irq %d\n",
                    pdata->attn_gpio);
            goto err_data;
        }
    }

    error = rmi_register_phys_device(rmi_phys);
    if (error) {
        dev_err(&client->dev,
                "failed to register physical driver at 0x%.2X.\n",
                client->addr);
        goto err_data;
    }
    i2c_set_clientdata(client, rmi_phys);

    if (pdata->attn_gpio > 0) {
        error = acquire_attn_irq(data);
        if (error < 0) {
            dev_err(&client->dev,
                    "request_threaded_irq failed %d\n",
                    pdata->attn_gpio);
            goto err_unregister;
        }
    }

#if defined(CONFIG_RMI4_DEV)
    error = gpio_export(pdata->attn_gpio, false);
    if (error) {
        dev_warn(&client->dev, "%s: WARNING: Failed to "
                 "export ATTN gpio!\n", __func__);
        error = 0;
    } else {
        error = gpio_export_link(&(rmi_phys->rmi_dev->dev), "attn",
                                 pdata->attn_gpio);
        if (error) {
            dev_warn(&(rmi_phys->rmi_dev->dev), "%s: WARNING: "
                     "Failed to symlink ATTN gpio!\n", __func__);
            error = 0;
        } else {
            dev_info(&(rmi_phys->rmi_dev->dev),
                     "%s: Exported GPIO %d.", __func__,
                     pdata->attn_gpio);
        }
    }
#endif /* CONFIG_RMI4_DEV */

    dev_info(&client->dev, "registered rmi i2c driver at 0x%.2X.\n",
             client->addr);
    return 0;

err_unregister:
    rmi_unregister_phys_device(rmi_phys);
err_data:
    kfree(data);
err_phys:
    kfree(rmi_phys);
    return error;
}
Example #2
0
static int __devinit rmi_i2c_probe(struct i2c_client *client,
				  const struct i2c_device_id *id)
{
	struct rmi_phys_device *rmi_phys;
	struct rmi_i2c_data *data;
	struct rmi_device_platform_data *pdata = client->dev.platform_data;
	int retval;

	if (!pdata) {
		dev_err(&client->dev, "no platform data\n");
		return -EINVAL;
	}
	dev_info(&client->dev, "Probing %s at %#02x (IRQ %d).\n",
		pdata->sensor_name ? pdata->sensor_name : "-no name-",
		client->addr, pdata->attn_gpio);

	if (pdata->gpio_config) {
		dev_info(&client->dev, "Configuring GPIOs.\n");
		retval = pdata->gpio_config(pdata->gpio_data, true);
		if (retval < 0) {
			dev_err(&client->dev, "Failed to configure GPIOs, code: %d.\n",
				retval);
			return retval;
		}
		dev_info(&client->dev, "Done with GPIO configuration.\n");
	}

	retval = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
	if (!retval) {
		dev_err(&client->dev, "i2c_check_functionality error %d.\n",
			retval);
		return retval;
	}

	rmi_phys = devm_kzalloc(&client->dev, sizeof(struct rmi_phys_device),
				GFP_KERNEL);

	if (!rmi_phys)
		return -ENOMEM;

	data = devm_kzalloc(&client->dev, sizeof(struct rmi_i2c_data),
				GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	data->phys = rmi_phys;

	rmi_phys->data = data;
	rmi_phys->dev = &client->dev;

	rmi_phys->write_block = rmi_i2c_write_block;
	rmi_phys->read_block = rmi_i2c_read_block;
	rmi_phys->info.proto = phys_proto_name;

	mutex_init(&data->page_mutex);

	/* Setting the page to zero will (a) make sure the PSR is in a
	 * known state, and (b) make sure we can talk to the device.
	 */
	retval = rmi_set_page(rmi_phys, 0);
	if (retval) {
		dev_err(&client->dev, "Failed to set page select to 0.\n");
		return retval;
	}

	retval = rmi_register_phys_device(rmi_phys);
	if (retval) {
		dev_err(&client->dev,
			"failed to register physical driver at 0x%.2X.\n",
			client->addr);
		goto err_gpio;
	}
	i2c_set_clientdata(client, rmi_phys);

	if (IS_ENABLED(CONFIG_RMI4_DEBUG))
		retval = setup_debugfs(rmi_phys->rmi_dev, data);

	dev_info(&client->dev, "registered rmi i2c driver at %#04x.\n",
			client->addr);
	return 0;

err_gpio:
	if (pdata->gpio_config)
		pdata->gpio_config(pdata->gpio_data, false);
	return retval;
}
Example #3
0
static int __devinit rmi_i2c_probe(struct i2c_client *client,
				  const struct i2c_device_id *id)
{
	struct rmi_phys_device *rmi_phys;
	struct rmi_i2c_data *data;
	struct rmi_device_platform_data *pdata = client->dev.platform_data;
	int error;

	if (!pdata) {
		dev_err(&client->dev, "no platform data\n");
		return -EINVAL;
	}
	if (!hsad_get_rmi_enable()) {
		dev_err(&client->dev, "rmi not exits\n");
		return -EINVAL;
	}

	dev_info(&client->dev, "Probing %s at %#02x (IRQ %d).\n",
		pdata->sensor_name ? pdata->sensor_name : "-no name-",
		client->addr, pdata->attn_gpio);
	error = set_touch_chip_info(TOUCH_INFO_RMI3250);
	if (error) {
		dev_err(&client->dev, "set_touch_chip_info error\n");
	}

	dev_info(&client->dev, "Configuring GPIOs.\n");
	error = synaptics_touchpad_gpio_setup(pdata->gpio_data);
	if (error < 0) {
		dev_err(&client->dev, "Failed to configure GPIOs, code: %d.\n",
			error);
		return error;
	}
	dev_info(&client->dev, "Done with GPIO configuration.\n");
	error = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
	if (!error) {
		dev_err(&client->dev, "i2c_check_functionality error %d.\n",
			error);
		return error;
	}

	rmi_phys = kzalloc(sizeof(struct rmi_phys_device), GFP_KERNEL);
	if (!rmi_phys)
		return -ENOMEM;

	data = kzalloc(sizeof(struct rmi_i2c_data), GFP_KERNEL);
	if (!data) {
		error = -ENOMEM;
		goto err_phys;
	}

	data->enabled = true;	/* We plan to come up enabled. */
	data->irq = gpio_to_irq(pdata->attn_gpio);
	if (pdata->level_triggered) {
		data->irq_flags = IRQF_ONESHOT |
			((pdata->attn_polarity == RMI_ATTN_ACTIVE_HIGH) ?
			IRQF_TRIGGER_HIGH : IRQF_TRIGGER_LOW);
	} else {
		data->irq_flags =
			(pdata->attn_polarity == RMI_ATTN_ACTIVE_HIGH) ?
			IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
	}
	data->phys = rmi_phys;

	rmi_phys->data = data;
	rmi_phys->dev = &client->dev;

	rmi_phys->write = rmi_i2c_write;
	rmi_phys->write_block = rmi_i2c_write_block;
	rmi_phys->read = rmi_i2c_read;
	rmi_phys->read_block = rmi_i2c_read_block;
	rmi_phys->enable_device = enable_device;
	rmi_phys->disable_device = disable_device;

	rmi_phys->info.proto = phys_proto_name;

	mutex_init(&data->page_mutex);

	/* Setting the page to zero will (a) make sure the PSR is in a
	 * known state, and (b) make sure we can talk to the device.
	 */
	msleep(100);
	error = rmi_set_page(rmi_phys, 0);
	if (error) {
		dev_err(&client->dev, "Failed to set page select to 0.\n");
		goto err_data;
	}

	error = rmi_register_phys_device(rmi_phys);
	if (error) {
		dev_err(&client->dev,
			"failed to register physical driver at 0x%.2X.\n",
			client->addr);
		goto err_gpio;
	}
	i2c_set_clientdata(client, rmi_phys);

	rmi_phys->rmi_task = kthread_create(rmi_irq_thread, data, "rmi_irq_thread");
	if (IS_ERR(rmi_phys->rmi_task)){
		dev_err(&client->dev,	"create thread failed!\n");
		goto err_unregister;
	}

	if (pdata->attn_gpio > 0) {
		error = acquire_attn_irq(data);
		if (error < 0) {
			dev_err(&client->dev,
				"request_threaded_irq failed %d\n",
				pdata->attn_gpio);
			goto err_unregister;
		}
	}

#if defined(CONFIG_RMI4_DEV)
	error = gpio_export(pdata->attn_gpio, false);
	if (error) {
		dev_warn(&client->dev,
			 "WARNING: Failed to export ATTN gpio!\n");
		error = 0;
	} else {
		error = gpio_export_link(&(rmi_phys->rmi_dev->dev), "attn",
					pdata->attn_gpio);
		if (error) {
			dev_warn(&(rmi_phys->rmi_dev->dev),
				 "WARNING: Failed to symlink ATTN gpio!\n");
			error = 0;
		} else {
			dev_info(&(rmi_phys->rmi_dev->dev),
				"%s: Exported ATTN GPIO %d.", __func__,
				pdata->attn_gpio);
		}
	}
#endif /* CONFIG_RMI4_DEV */

	dev_info(&client->dev, "registered rmi i2c driver at %#04x.\n",
			client->addr);
	return 0;

err_unregister:
	rmi_unregister_phys_device(rmi_phys);
err_gpio:
	synaptics_touchpad_gpio_free(pdata->gpio_data);
err_data:
	kfree(data);
err_phys:
	kfree(rmi_phys);
	return error;
}
Example #4
0
static int __devinit rmi_smb_probe(struct i2c_client *client,
				  const struct i2c_device_id *id)
{
	struct rmi_phys_device *rmi_phys;
	struct rmi_smb_data *data;
	struct rmi_device_platform_data *pdata = client->dev.platform_data;
	int retval;
	int smbus_version;
	if (!pdata) {
		dev_err(&client->dev, "no platform data\n");
		return -EINVAL;
	}
	pr_info("%s: Probing %s (IRQ %d).\n", __func__,
		pdata->sensor_name ? pdata->sensor_name : "-no name-",
		pdata->attn_gpio);

	retval = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
	if (!retval) {
		dev_err(&client->dev, "i2c_check_functionality error %d.\n",
				retval);
		return retval;
	}

	rmi_phys = devm_kzalloc(&client->dev, sizeof(struct rmi_phys_device),
			GFP_KERNEL);
	if (!rmi_phys)
		return -ENOMEM;

	data = devm_kzalloc(&client->dev, sizeof(struct rmi_smb_data),
				GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	data->enabled = true;	/* We plan to come up enabled. */
	data->phys = rmi_phys;

	rmi_phys->data = data;
	rmi_phys->dev = &client->dev;

	mutex_init(&data->page_mutex);
	mutex_init(&data->mappingtable_mutex);

	if (pdata->gpio_config) {
		retval = pdata->gpio_config(pdata->gpio_data, true);
		if (retval < 0) {
			dev_err(&client->dev, "failed to setup irq %d\n",
				pdata->attn_gpio);
			return retval;
		}
	}

	/* Check if for SMBus new version device by reading version byte. */
	retval = i2c_smbus_read_byte_data(client, SMB_PROTOCOL_VERSION_ADDRESS);
	if (retval < 0) {
		dev_err(&client->dev, "failed to get SMBus version number!\n");
		return retval;
	}
	smbus_version = retval + 1;
	dev_dbg(&client->dev, "Smbus version is %d", smbus_version);
	switch (smbus_version) {
	case 1:
		/* Setting the page to zero will (a) make sure the PSR is in a
		* known state, and (b) make sure we can talk to the device. */
		retval = rmi_set_page(rmi_phys, 0);
		if (retval) {
			dev_err(&client->dev, "Failed to set page select to 0.\n");
			return retval;
		}
		rmi_phys->write_block = rmi_smb_v1_write_block;
		rmi_phys->read_block = rmi_smb_v1_read_block;
		rmi_phys->info.proto = smb_v1_proto_name;
		break;
	case 2:
		/* SMBv2 */
		retval = i2c_check_functionality(client->adapter,
						I2C_FUNC_SMBUS_READ_BLOCK_DATA);
		if (retval < 0) {
			dev_err(&client->dev, "client's adapter does not support the I2C_FUNC_SMBUS_READ_BLOCK_DATA functionality.\n");
			return retval;
		}

		rmi_phys->write_block	= rmi_smb_v2_write_block;
		rmi_phys->read_block	= rmi_smb_v2_read_block;
		rmi_phys->info.proto	= smb_v2_proto_name;
		break;
	default:
		dev_err(&client->dev, "Unrecognized SMB version %d.\n",
				smbus_version);
		retval = -ENODEV;
		return retval;
	}
	/* End check if this is an SMBus device */

	retval = rmi_register_phys_device(rmi_phys);
	if (retval) {
		dev_err(&client->dev, "failed to register physical driver at 0x%.2X.\n",
			client->addr);
		return retval;
	}
	i2c_set_clientdata(client, rmi_phys);

	if (IS_ENABLED(CONFIG_RMI4_DEBUG))
		retval = setup_debugfs(rmi_phys->rmi_dev, data);

	dev_info(&client->dev, "registered rmi smb driver at 0x%.2X.\n",
			client->addr);
	return 0;
}
Example #5
0
static int __devinit rmi_i2c_probe(struct i2c_client *client,
				  const struct i2c_device_id *id)
{
	struct rmi_phys_device *rmi_phys;
	struct rmi_i2c_data *data;
	struct rmi_device_platform_data *pdata = client->dev.platform_data;
	int error;

	if (!pdata) {
		printk( "ITUCH : Device(%s) no platform data\n", dev_name( &client->dev ) );
		return -EINVAL;
	}
	printk( "ITUCH : Probing %s at %#02x (IRQ %d)\n", pdata->sensor_name ? pdata->sensor_name : "-no name-", client->addr, pdata->attn_gpio );

	error = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
	if (!error) {
		printk( "ITUCH : Device(%s) i2c_check_functionality error(%d)\n", dev_name( &client->dev ), error );
		return error;
	}

	rmi_phys = kzalloc(sizeof(struct rmi_phys_device), GFP_KERNEL);
	if (!rmi_phys)
		return -ENOMEM;

	data = kzalloc(sizeof(struct rmi_i2c_data), GFP_KERNEL);
	if (!data) {
		error = -ENOMEM;
		goto err_phys;
	}

	if( gpio_request( pdata->reset_gpio, "RMI4_RESET" ) )
		printk( "ITUCH : Unable to request gpio%d\n", pdata->reset_gpio );

	reset_touch( pdata );

	data->enabled = true;	/* We plan to come up enabled. */
	data->irq = gpio_to_irq(pdata->attn_gpio);
	if (pdata->level_triggered) {
		data->irq_flags = IRQF_ONESHOT |
			((pdata->attn_polarity == RMI_ATTN_ACTIVE_HIGH) ?
			IRQF_TRIGGER_HIGH : IRQF_TRIGGER_LOW);
	} else {
		data->irq_flags =
			(pdata->attn_polarity == RMI_ATTN_ACTIVE_HIGH) ?
			IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
	}
	data->phys = rmi_phys;

	rmi_phys->data = data;
	rmi_phys->dev = &client->dev;

	rmi_phys->write = rmi_i2c_write;
	rmi_phys->write_block = rmi_i2c_write_block;
	rmi_phys->read = rmi_i2c_read;
	rmi_phys->read_block = rmi_i2c_read_block;
	rmi_phys->enable_device = enable_device;
	rmi_phys->disable_device = disable_device;

	rmi_phys->info.proto = phys_proto_name;

	mutex_init(&data->page_mutex);

	/* Setting the page to zero will (a) make sure the PSR is in a
	 * known state, and (b) make sure we can talk to the device.
	 */
	error = rmi_set_page(rmi_phys, 0);
	if (error) {
		printk( "ITUCH : Device(%s) failed to set page select to 0\n", dev_name( &client->dev ) );
		goto err_data;
	}

	if (pdata->gpio_config) {
		error = pdata->gpio_config(pdata->gpio_data, true);
		if (error < 0) {
			printk( "ITUCH : Device(%s) failed to setup irq%d\n", dev_name( &client->dev ), pdata->attn_gpio );
			goto err_data;
		}
	}

	error = rmi_register_phys_device(rmi_phys);
	if (error) {
		printk( "ITUCH : Device(%s) failed to register physical driver at 0x%.2X\n", dev_name( &client->dev ), client->addr );
		goto err_gpio;
	}
	i2c_set_clientdata(client, rmi_phys);

	if (pdata->attn_gpio > 0) {
		error = acquire_attn_irq(data);
		if (error < 0) {
			printk( "ITUCH : Device(%s) request_threaded_irq(IRQ%d) failed\n", dev_name( &client->dev ), pdata->attn_gpio );
			goto err_unregister;
		}
	}

#if defined(CONFIG_RMI4_DEV)
	error = gpio_export(pdata->attn_gpio, false);
	if (error) {
		printk( "ITUCH : Device(%s) failed to export ATTN gpio\n", dev_name( &client->dev ) );
		error = 0;
	} else {
		error = gpio_export_link(&(rmi_phys->rmi_dev->dev), "attn",
					pdata->attn_gpio);
		if (error) {
			printk( "ITUCH : Device(%s) failed to symlink ATTN gpio\n", dev_name( &rmi_phys->rmi_dev->dev ) );
			error = 0;
		} else {
			printk( "ITUCH : Device(%s) exported GPIO-%d\n", dev_name( &rmi_phys->rmi_dev->dev ), pdata->attn_gpio );
		}
	}
#endif /* CONFIG_RMI4_DEV */

	printk( "ITUCH : Device(%s) registered rmi i2c driver at 0x%.2X\n", dev_name( &client->dev ), client->addr );
	return 0;

err_unregister:
	rmi_unregister_phys_device(rmi_phys);
err_gpio:
	if (pdata->gpio_config)
		pdata->gpio_config(pdata->gpio_data, false);
err_data:
	kfree(data);
err_phys:
	kfree(rmi_phys);
	return error;
}