static int rmi_spi_read_block(struct rmi_transport_dev *xport, u16 addr, void *buf, size_t len) { struct rmi_spi_xport *rmi_spi = container_of(xport, struct rmi_spi_xport, xport); struct rmi_spi_cmd cmd; int ret; mutex_lock(&rmi_spi->page_mutex); if (RMI_SPI_PAGE(addr) != rmi_spi->page) { ret = rmi_set_page(rmi_spi, RMI_SPI_PAGE(addr)); if (ret) goto exit; } cmd.op = RMI_SPI_READ; cmd.addr = addr; ret = rmi_spi_xfer(rmi_spi, &cmd, NULL, 0, buf, len); exit: mutex_unlock(&rmi_spi->page_mutex); return ret; }
static int rmi_i2c_read_block(struct rmi_phys_device *phys, u16 addr, u8 *buf, int len) { struct i2c_client *client = to_i2c_client(phys->dev); struct rmi_i2c_data *data = phys->data; u8 txbuf[1] = {addr & 0xff}; int retval; #if COMMS_DEBUG char debug_buf[len*3 + 1]; char *temp = debug_buf; int i, n; #endif mutex_lock(&data->page_mutex); if (RMI_I2C_PAGE(addr) != data->page) { retval = rmi_set_page(phys, RMI_I2C_PAGE(addr)); if (retval < 0) goto exit; } #if COMMS_DEBUG dev_dbg(&client->dev, "RMI4 I2C writes 1 bytes: %02x\n", txbuf[0]); #endif phys->info.tx_count++; phys->info.tx_bytes += sizeof(txbuf); retval = i2c_master_send(client, txbuf, sizeof(txbuf)); if (retval != sizeof(txbuf)) { phys->info.tx_errs++; retval = (retval < 0) ? retval : -EIO; goto exit; } retval = i2c_master_recv(client, buf, len); phys->info.rx_count++; phys->info.rx_bytes += len; if (retval < 0) phys->info.rx_errs++; #if COMMS_DEBUG else { n = 0; for (i=0; i < len; i++) { n = sprintf(temp, " %02x", buf[i]); temp += n; } dev_dbg(&client->dev, "RMI4 I2C read %d bytes at %#06x:%s\n", len, addr, debug_buf); } #endif exit: mutex_unlock(&data->page_mutex); return retval; }
static int rmi_i2c_write_block(struct rmi_phys_device *phys, u16 addr, const void *buf, const int len) { struct i2c_client *client = to_i2c_client(phys->dev); struct rmi_i2c_data *data = phys->data; int retval; int tx_size = len + 1; mutex_lock(&data->page_mutex); if (!data->tx_buf || data->tx_buf_size < tx_size) { if (data->tx_buf) devm_kfree(&client->dev, data->tx_buf); data->tx_buf_size = tx_size + BUFFER_SIZE_INCREMENT; data->tx_buf = devm_kzalloc(&client->dev, data->tx_buf_size, GFP_KERNEL); if (!data->tx_buf) { data->tx_buf_size = 0; retval = -ENOMEM; goto exit; } } data->tx_buf[0] = addr & 0xff; memcpy(data->tx_buf + 1, buf, len); if (RMI_I2C_PAGE(addr) != data->page) { retval = rmi_set_page(phys, RMI_I2C_PAGE(addr)); if (retval < 0) goto exit; } if (COMMS_DEBUG(data)) { retval = copy_to_debug_buf(&client->dev, data, (u8 *) buf, len); if (!retval) dev_dbg(&client->dev, "writes %d bytes at %#06x:%s\n", len, addr, data->debug_buf); } phys->info.tx_count++; phys->info.tx_bytes += tx_size; retval = i2c_master_send(client, data->tx_buf, tx_size); if (retval < 0) phys->info.tx_errs++; else retval--; /* don't count the address byte */ exit: mutex_unlock(&data->page_mutex); return retval; }
int rmi_i2c_read_block(struct rmi_phys_device *phys, u16 addr, u8 *buf, int len) { struct i2c_client *client = to_i2c_client(phys->dev); struct rmi_i2c_data *data = phys->data; u8 txbuf[1] = {addr & 0xff}; int retval; #if COMMS_DEBUG int i; #endif mutex_lock(&data->page_mutex); if (RMI_I2C_PAGE(addr) != data->page) { retval = rmi_set_page(phys, RMI_I2C_PAGE(addr)); if (retval < 0) goto exit; } #if COMMS_DEBUG dev_dbg(&client->dev, "RMI4 I2C writes 1 bytes: %02x\n", txbuf[0]); #endif phys->info.tx_count++; phys->info.tx_bytes += sizeof(txbuf); retval = i2c_master_normal_send(client, txbuf, sizeof(txbuf), CONFIG_RMI4_I2C_SCL_RATE); if (retval != sizeof(txbuf)) { phys->info.tx_errs++; retval = (retval < 0) ? retval : -EIO; goto exit; } retval = i2c_master_normal_recv(client, buf, len, CONFIG_RMI4_I2C_SCL_RATE); phys->info.rx_count++; phys->info.rx_bytes += len; if (retval < 0) phys->info.rx_errs++; #if COMMS_DEBUG else { dev_dbg(&client->dev, "RMI4 I2C received %d bytes: ", len); for (i = 0; i < len; i++) dev_dbg(&client->dev, "%02x ", buf[i]); dev_dbg(&client->dev, "\n"); } #endif exit: mutex_unlock(&data->page_mutex); return retval; }
static int rmi_i2c_read_block(struct rmi_phys_device *phys, u16 addr, void *buf, const int len) { struct i2c_client *client = to_i2c_client(phys->dev); struct rmi_i2c_data *data = phys->data; u8 txbuf[1] = {addr & 0xff}; int retval; mutex_lock(&data->page_mutex); if (RMI_I2C_PAGE(addr) != data->page) { retval = rmi_set_page(phys, RMI_I2C_PAGE(addr)); if (retval < 0) goto exit; } if (COMMS_DEBUG(data)) dev_dbg(&client->dev, "writes 1 bytes: %02x\n", txbuf[0]); phys->info.tx_count++; phys->info.tx_bytes += sizeof(txbuf); retval = i2c_master_send(client, txbuf, sizeof(txbuf)); if (retval != sizeof(txbuf)) { phys->info.tx_errs++; retval = (retval < 0) ? retval : -EIO; goto exit; } retval = i2c_master_recv(client, (u8 *) buf, len); phys->info.rx_count++; phys->info.rx_bytes += len; if (retval < 0) phys->info.rx_errs++; else if (COMMS_DEBUG(data)) { retval = copy_to_debug_buf(&client->dev, data, (u8 *) buf, len); if (!retval) dev_dbg(&client->dev, "read %d bytes at %#06x:%s\n", len, addr, data->debug_buf); } exit: mutex_unlock(&data->page_mutex); return retval; }
static int rmi_i2c_write_block(struct rmi_phys_device *phys, u16 addr, u8 *buf, int len) { struct i2c_client *client = to_i2c_client(phys->dev); struct rmi_i2c_data *data = phys->data; u8 txbuf[len + 1]; int retval; #if COMMS_DEBUG char debug_buf[len*3 + 1]; int i, n; #endif txbuf[0] = addr & 0xff; memcpy(txbuf + 1, buf, len); mutex_lock(&data->page_mutex); if (RMI_I2C_PAGE(addr) != data->page) { retval = rmi_set_page(phys, RMI_I2C_PAGE(addr)); if (retval < 0) goto exit; } #if COMMS_DEBUG n = 0; for (i=0; i < len; i++) n = snprintf(debug_buf+n, 4, "%02x ", buf[i]); dev_dbg(&client->dev, "RMI4 I2C writes %d bytes at %#06x: %s\n", len, addr, debug_buf); #endif phys->info.tx_count++; phys->info.tx_bytes += sizeof(txbuf); retval = i2c_master_send(client, txbuf, sizeof(txbuf)); if (retval < 0) phys->info.tx_errs++; else retval--; /* don't count the address byte */ exit: mutex_unlock(&data->page_mutex); return retval; }
static int rmi_hid_write_block(struct rmi_transport_device *xport, u16 addr, const void *buf, const int len) { struct hid_device *hdev = to_hid_device(xport->dev); struct rmi_hid_data *data = xport->data; int ret; mutex_lock(&data->page_mutex); if (RMI_HID_PAGE(addr) != data->page) { ret = rmi_set_page(xport, RMI_HID_PAGE(addr)); if (ret < 0) goto exit; } if (COMMS_DEBUG(data)) { ret = copy_to_debug_buf(&hdev->dev, data, (u8 *) buf, len); if (!ret) dev_dbg(&hdev->dev, "writes %d bytes at %#06x:%s\n", len, addr, data->debug_buf); } xport->info.tx_count++; xport->info.tx_bytes += len; data->writeReport[RMI_HID_REPORT_ID] = RMI_WRITE_REPORT_ID; data->writeReport[RMI_HID_WRITE_OUTPUT_COUNT] = len; data->writeReport[RMI_HID_WRITE_OUTPUT_ADDR] = addr & 0xFF; data->writeReport[RMI_HID_WRITE_OUTPUT_ADDR + 1] = (addr >> 8) & 0xFF; memcpy(&data->writeReport[RMI_HID_WRITE_OUTPUT_DATA], buf, len); ret = rmi_hid_write_report(hdev, data->writeReport, data->output_report_size); if (ret != data->output_report_size) { dev_err(&hdev->dev, "failed to send output report (%d)\n", ret); goto exit; } exit: mutex_unlock(&data->page_mutex); return ret; }
int rmi_i2c_write_block(struct rmi_phys_device *phys, u16 addr, u8 *buf, int len) { struct i2c_client *client = to_i2c_client(phys->dev); struct rmi_i2c_data *data = phys->data; u8 txbuf[len + 1]; int retval; #if COMMS_DEBUG int i; #endif txbuf[0] = addr & 0xff; memcpy(txbuf + 1, buf, len); mutex_lock(&data->page_mutex); if (RMI_I2C_PAGE(addr) != data->page) { retval = rmi_set_page(phys, RMI_I2C_PAGE(addr)); if (retval < 0) goto exit; } #if COMMS_DEBUG dev_dbg(&client->dev, "RMI4 I2C writes %d bytes: ", sizeof(txbuf)); for (i = 0; i < sizeof(txbuf); i++) dev_dbg(&client->dev, "%02x ", txbuf[i]); dev_dbg(&client->dev, "\n"); #endif phys->info.tx_count++; phys->info.tx_bytes += sizeof(txbuf); retval = i2c_master_normal_send(client, txbuf, sizeof(txbuf), CONFIG_RMI4_I2C_SCL_RATE); if (retval < 0) phys->info.tx_errs++; else retval--; /* don't count the address byte */ exit: mutex_unlock(&data->page_mutex); return retval; }
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; }
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; }
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; }
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; }
static int rmi_hid_probe(struct hid_device *hdev, const struct hid_device_id *id) { struct rmi_transport_device *xport = NULL; struct rmi_hid_data *data = NULL; unsigned int connect_mask = HID_CONNECT_HIDRAW | HID_CONNECT_HIDDEV; int ret; dev_dbg(&hdev->dev, "%s\n", __func__); xport = devm_kzalloc(&hdev->dev, sizeof(struct rmi_transport_device), GFP_KERNEL); if (!xport) { ret = -ENOMEM; goto err; } data = devm_kzalloc(&hdev->dev, sizeof(struct rmi_hid_data), GFP_KERNEL); if (!data) { ret =-ENOMEM; goto err; } data->xport = xport; xport->data = data; xport->dev = &hdev->dev; xport->write_block = rmi_hid_write_block; xport->read_block = rmi_hid_read_block; xport->info.proto_type = RMI_PROTOCOL_HID; xport->info.proto = transport_proto_name; xport->post_reset = rmi_hid_post_reset; hid_set_drvdata(hdev, xport); ret = hid_parse(hdev); if (ret) { hid_err(hdev, "parse failed\n"); goto err; } data->input_report_size = (hdev->report_enum[HID_INPUT_REPORT] .report_id_hash[RMI_ATTN_REPORT_ID]->size >> 3) + 1 /* report id */; data->output_report_size = (hdev->report_enum[HID_OUTPUT_REPORT] .report_id_hash[RMI_WRITE_REPORT_ID]->size >> 3) + 1 /* report id */; data->feature_report_size = (hdev->report_enum[HID_FEATURE_REPORT] .report_id_hash[RMI_SET_RMI_MODE_REPORT_ID]->size >> 3) + 1 /* report id */; dev_dbg(&hdev->dev, "input report size %d\n", data->input_report_size); dev_dbg(&hdev->dev, "output report size %d\n", data->output_report_size); dev_dbg(&hdev->dev, "feature report size %d\n", data->feature_report_size); data->input_queue = devm_kzalloc(&hdev->dev, data->input_report_size * RMI_HID_INPUT_REPORT_QUEUE_LEN, GFP_KERNEL); if (!data->input_queue) { ret = -ENOMEM; goto err; } data->writeReport = devm_kzalloc(&hdev->dev, data->output_report_size, GFP_KERNEL); if (!data->writeReport) { ret = -ENOMEM; goto err; } data->readReport = devm_kzalloc(&hdev->dev, data->input_report_size, GFP_KERNEL); if (!data->readReport) { ret = -ENOMEM; goto err; } data->attnReport = devm_kzalloc(&hdev->dev, data->input_report_size, GFP_KERNEL); if (!data->attnReport) { ret = -ENOMEM; goto err; } tp_platformdata.pm_data = hdev; xport->dev->platform_data = &tp_platformdata; #ifdef TOUCHPAD_WAKE_SYSTEM if (tp_platformdata.f11_sensor_data[0].sensor_type == rmi_sensor_touchpad) { device_init_wakeup(hdev->dev.parent, 1); } #endif spin_lock_init(&data->input_queue_consumer_lock); spin_lock_init(&data->input_queue_producer_lock); data->input_queue_head = 0; data->input_queue_tail = 0; INIT_WORK(&data->attn_report_work, rmi_hid_attn_report_work); INIT_WORK(&data->reset_work, rmi_hid_reset_work); init_waitqueue_head(&data->wait); mutex_init(&data->page_mutex); ret = hid_hw_start(hdev, connect_mask); if (ret) { hid_err(hdev, "hw start failed\n"); goto err; } dev_dbg(&hdev->dev, "Opening low level driver\n"); hdev->ll_driver->open(hdev); /* Allow incoming hid reports */ hid_device_io_start(hdev); ret = rmi_hid_set_mode(hdev, RMI_HID_MODE_ATTN_REPORTS); if (ret < 0) { dev_err(&hdev->dev, "failed to set rmi mode\n"); goto rmi_read_failed; } ret = rmi_set_page(xport, 0); if (ret < 0) { dev_err(&hdev->dev, "failed to set page select to 0.\n"); goto rmi_read_failed; } ret = rmi_register_transport_device(xport); if (ret) { dev_err(&hdev->dev, "failed to register transport device at %s\n", hdev->phys); goto rmi_read_failed; } if (!xport->probe_succeeded) { dev_err(&hdev->dev, "Probe failed in rmi_driver\n"); ret = -ENODEV; goto rmi_driver_probe_failed; } set_bit(RMI_HID_STARTED, &data->flags); if (IS_ENABLED(CONFIG_RMI4_DEBUG)) ret = setup_debugfs(xport->rmi_dev, data); dev_info(&hdev->dev, "registered rmi hid driver at %s\n", hdev->phys); return 0; rmi_driver_probe_failed: rmi_unregister_transport_device(xport); rmi_read_failed: hdev->ll_driver->close(hdev); hid_hw_stop(hdev); err: return ret; }
static int rmi_hid_read_block(struct rmi_transport_device *xport, u16 addr, void *buf, const int len) { struct hid_device *hdev = to_hid_device(xport->dev); struct rmi_hid_data *data = xport->data; int ret; int bytes_read; int bytes_needed; int retries; int read_input_count; mutex_lock(&data->page_mutex); if (RMI_HID_PAGE(addr) != data->page) { ret = rmi_set_page(xport, RMI_HID_PAGE(addr)); if (ret < 0) goto exit; } for (retries = 5; retries > 0; retries--) { data->writeReport[RMI_HID_REPORT_ID] = RMI_READ_ADDR_REPORT_ID; data->writeReport[1] = 0; /* old 1 byte read count */ data->writeReport[RMI_HID_READ_OUTPUT_ADDR] = addr & 0xFF; data->writeReport[RMI_HID_READ_OUTPUT_ADDR + 1] = (addr >> 8) & 0xFF; data->writeReport[RMI_HID_READ_OUTPUT_COUNT] = len & 0xFF; data->writeReport[RMI_HID_READ_OUTPUT_COUNT + 1] = (len >> 8) & 0xFF; if (COMMS_DEBUG(data)) { ret = copy_to_debug_buf(&hdev->dev, data, data->writeReport, len); if (!ret) dev_dbg(&hdev->dev, "wrote %d bytes at %#06x:%s\n", len, addr, data->debug_buf); } set_bit(RMI_HID_READ_REQUEST_PENDING, &data->flags); ret = rmi_hid_write_report(hdev, data->writeReport, data->output_report_size); if (ret != data->output_report_size) { clear_bit(RMI_HID_READ_REQUEST_PENDING, &data->flags); dev_err(&hdev->dev, "failed to write request output report (%d)\n", ret); goto exit; } bytes_read = 0; bytes_needed = len; while (bytes_read < len) { if (!wait_event_timeout(data->wait, test_bit(RMI_HID_READ_DATA_PENDING, &data->flags), msecs_to_jiffies(1000))) { dev_info(&hdev->dev, "%s: timeout elapsed\n", __func__); ret = -ENODATA; break; } else { if (data->readReport[RMI_HID_REPORT_ID] != RMI_READ_DATA_REPORT_ID) { ret = -ENODATA; dev_err(&hdev->dev, "%s: Expected data report, but got" " report id %d instead", __func__, data->readReport[RMI_HID_REPORT_ID]); goto exit; } read_input_count = data->readReport[RMI_HID_READ_INPUT_COUNT]; memcpy(buf + bytes_read, &data->readReport[RMI_HID_READ_INPUT_DATA], read_input_count < bytes_needed ? read_input_count : bytes_needed); if (COMMS_DEBUG(data)) { ret = copy_to_debug_buf(&hdev->dev, data, (u8 *) buf + bytes_read, read_input_count); if (!ret) dev_dbg(&hdev->dev, "read %d bytes at %#06x:%s\n", read_input_count, addr, data->debug_buf); } bytes_read += read_input_count; bytes_needed -= read_input_count; clear_bit(RMI_HID_READ_DATA_PENDING, &data->flags); } } if (bytes_read == len) break; } if (bytes_read == len) { xport->info.rx_count++; xport->info.rx_bytes += len; ret = len; } exit: clear_bit(RMI_HID_READ_REQUEST_PENDING, &data->flags); mutex_unlock(&data->page_mutex); return ret; }
static int rmi_spi_probe(struct spi_device *spi) { struct rmi_spi_xport *rmi_spi; struct rmi_device_platform_data *pdata; struct rmi_device_platform_data *spi_pdata = spi->dev.platform_data; int retval; if (spi->master->flags & SPI_MASTER_HALF_DUPLEX) return -EINVAL; rmi_spi = devm_kzalloc(&spi->dev, sizeof(struct rmi_spi_xport), GFP_KERNEL); if (!rmi_spi) return -ENOMEM; pdata = &rmi_spi->xport.pdata; if (spi->dev.of_node) { retval = rmi_spi_of_probe(spi, pdata); if (retval) return retval; } else if (spi_pdata) { *pdata = *spi_pdata; } if (pdata->spi_data.bits_per_word) spi->bits_per_word = pdata->spi_data.bits_per_word; if (pdata->spi_data.mode) spi->mode = pdata->spi_data.mode; retval = spi_setup(spi); if (retval < 0) { dev_err(&spi->dev, "spi_setup failed!\n"); return retval; } if (spi->irq > 0) rmi_spi->irq = spi->irq; rmi_spi->spi = spi; mutex_init(&rmi_spi->page_mutex); rmi_spi->xport.dev = &spi->dev; rmi_spi->xport.proto_name = "spi"; rmi_spi->xport.ops = &rmi_spi_ops; spi_set_drvdata(spi, rmi_spi); retval = rmi_spi_manage_pools(rmi_spi, RMI_SPI_DEFAULT_XFER_BUF_SIZE); if (retval) return retval; /* * 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_spi, 0); if (retval) { dev_err(&spi->dev, "Failed to set page select to 0.\n"); return retval; } retval = rmi_register_transport_device(&rmi_spi->xport); if (retval) { dev_err(&spi->dev, "failed to register transport.\n"); return retval; } retval = rmi_spi_init_irq(spi); if (retval < 0) return retval; dev_info(&spi->dev, "registered RMI SPI driver\n"); return 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; }