static int __devinit cyttsp_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct cyttsp_i2c *ts; int retval; dev_dbg(&client->dev, "%s: enter\n", __func__); if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) return -EIO; /* allocate and clear memory */ ts = kzalloc(sizeof(*ts), GFP_KERNEL); if (ts == NULL) { printk(KERN_ERR "%s: Error, kzalloc.\n", __func__); retval = -ENOMEM; goto error_alloc_data_failed; } /* register driver_data */ ts->client = client; ts->ops.write = ttsp_i2c_write_block_data; ts->ops.read = ttsp_i2c_read_block_data; ts->ops.ext = ttsp_i2c_tch_ext; retval = cyttsp_core_init((void *)ts, &ts->ops, &client->dev); if (retval) goto ttsp_core_err; dev_info(&client->dev, "successful registration\n"); return 0; ttsp_core_err: kfree(ts); error_alloc_data_failed: return retval; }
static int cyttsp_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct cyttsp_i2c *ts; #ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP3_DEVICETREE_SUPPORT struct device *dev = &client->dev; const struct of_device_id *match; #endif int retval = 0; pr_info("%s: Starting %s probe...\n", __func__, CY_I2C_NAME); /*** ZTEMT Added by lixin, 2015/12/02 ***/ retval = cyttsp3_pinctrl_init(&client->dev); if (retval < 0){ return retval; } retval = pinctrl_select_state(cyttsp3_pctrl.pinctrl,cyttsp3_pctrl.gpio_state_active); if (retval){ pr_err("%s:%d cyttsp3 cannot set pin to gpio_state_active state\n",__func__, __LINE__); return -EIO; } /*** ZTEMT END ***/ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("%s: fail check I2C functionality\n", __func__); retval = -EIO; goto cyttsp_i2c_probe_exit; } #ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP3_DEVICETREE_SUPPORT match = of_match_device(of_match_ptr(cyttsp3_i2c_of_match), dev); if (match) { retval = cyttsp3_devtree_create_and_get_pdata(dev); if (retval < 0) return retval; } #endif retval = cyttsp_power_on(&client->dev); if (retval){ pr_err("%s:%d cyttsp3 power on failed \n",__func__, __LINE__); return -EIO; } /* allocate and clear memory */ ts = kzalloc(sizeof(struct cyttsp_i2c), GFP_KERNEL); if (ts == NULL) { pr_err("%s: Error, kzalloc.\n", __func__); retval = -ENOMEM; goto cyttsp_i2c_probe_exit; } /* register driver_data */ ts->client = client; i2c_set_clientdata(client, ts); ts->ops.write = ttsp_i2c_write_block_data; ts->ops.read = ttsp_i2c_read_block_data; ts->ops.dev = &client->dev; ts->ops.dev->bus = &i2c_bus_type; ts->ttsp_client = cyttsp_core_init(&ts->ops, &client->dev, client->irq, client->name); if (ts->ttsp_client == NULL) { kfree(ts); ts = NULL; #ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP3_DEVICETREE_SUPPORT if (match) cyttsp3_devtree_clean_pdata(dev); #endif retval = -ENODATA; pr_err("%s: Registration fail ret=%d\n", __func__, retval); goto cyttsp_i2c_probe_exit; } /*** ZTEMT start ***/ if(!gpio_is_valid(rst_gpio_number)) return -ENODEV; retval = gpio_request(rst_gpio_number, "CYTTSP3_I2C_RST_GPIO"); if (retval < 0) { printk("Failed to request GPIO:%d, ERRNO:%d", (s32)rst_gpio_number, retval); retval = -ENODEV; } else { gpio_direction_output(rst_gpio_number, 1); } if(!gpio_is_valid(irq_gpio_number)) return -ENODEV; retval = gpio_request(irq_gpio_number, "CYTTSP3_I2C_IRQ_GPIO"); if (retval < 0) { printk("Failed request CYTTSP3_I2C_IRQ_GPIO.\n"); return -ENODEV; } gpio_direction_input(irq_gpio_number); id_number = 0; /*ZTEMT end*/ pr_info("%s: Registration complete\n", __func__); cyttsp_i2c_probe_exit: return retval; }