static int pn547_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret; int err; int addr; char tmp[4] = {0x20, 0x00, 0x01, 0x01}; int addrcnt; struct pn547_i2c_platform_data *platform_data; struct pn547_dev *pn547_dev; if (client->dev.of_node) { platform_data = devm_kzalloc(&client->dev, sizeof(struct pn547_i2c_platform_data), GFP_KERNEL); if (!platform_data) { dev_err(&client->dev, "Failed to allocate memory\n"); return -ENOMEM; } err = pn547_parse_dt(&client->dev, platform_data); if (err) return err; } else { platform_data = client->dev.platform_data; } if (platform_data == NULL) { pr_err("%s : nfc probe fail\n", __func__); return -ENODEV; } if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("%s : need I2C_FUNC_I2C\n", __func__); return -ENODEV; } ret = gpio_request(platform_data->irq_gpio, "nfc_int"); if (ret) return -ENODEV; ret = gpio_request(platform_data->ven_gpio, "nfc_ven"); if (ret) goto err_ven; ret = gpio_request(platform_data->firm_gpio, "nfc_firm"); if (ret) goto err_firm; #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST ret = gpio_request(platform_data->clk_req_gpio, "nfc_clk_req"); if (ret) goto err_clk_req; #endif #ifdef CONFIG_NFC_PN547_8226_USE_BBCLK2 ret = gpio_request(platform_data->clk_req_gpio, "nfc_clk_req"); if (ret) goto err_clk_req; #endif pn547_dev = kzalloc(sizeof(*pn547_dev), GFP_KERNEL); if (pn547_dev == NULL) { dev_err(&client->dev, "failed to allocate memory for module data\n"); ret = -ENOMEM; goto err_exit; } #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST pn547_dev->nfc_clock = msm_xo_get(MSM_XO_TCXO_A1, "nfc"); if (IS_ERR(pn547_dev->nfc_clock)) { ret = PTR_ERR(pn547_dev->nfc_clock); printk(KERN_ERR "%s: Couldn't get TCXO_A1 vote for NFC (%d)\n", __func__, ret); ret = -ENODEV; goto err_get_clock; } pn547_dev->clock_state = false; #endif #ifdef CONFIG_NFC_PN547_8226_USE_BBCLK2 pn547_dev->nfc_clock = clk_get(NULL, "nfc_clock"); if (IS_ERR(pn547_dev->nfc_clock)) { ret = PTR_ERR(pn547_dev->nfc_clock); printk(KERN_ERR "%s: Couldn't get D1 (%d)\n", __func__, ret); } else { if (clk_prepare_enable(pn547_dev->nfc_clock)) printk(KERN_ERR "%s: Couldn't prepare D1\n", __func__); } #endif #if defined(CONFIG_NFC_PN547_PMC8974_CLK_REQ) || defined(CONFIG_NFC_PN547_8084_USE_BBCLK2) #if defined(CONFIG_NFC_I2C_OVERWRITE) || defined(CONFIG_NFC_PN547_8084_USE_BBCLK2) pn547_dev->nfc_clk = clk_get(NULL, "nfc_clk"); #else pn547_dev->nfc_clk = clk_get(&client->dev, "nfc_clk"); #endif if (IS_ERR(pn547_dev->nfc_clk)) { ret = PTR_ERR(pn547_dev->nfc_clk); printk(KERN_ERR "%s: Couldn't get D1 (%d)\n", __func__, ret); } else { if (clk_prepare_enable(pn547_dev->nfc_clk)) printk(KERN_ERR "%s: Couldn't prepare D1\n", __func__); } #endif #if defined(CONFIG_GPIO_PCAL6416A) client->irq = gpio_to_irq(platform_data->irq_gpio); #endif pr_info("%s : IRQ num %d\n", __func__, client->irq); pn547_dev->irq_gpio = platform_data->irq_gpio; pn547_dev->ven_gpio = platform_data->ven_gpio; pn547_dev->firm_gpio = platform_data->firm_gpio; pn547_dev->conf_gpio = platform_data->conf_gpio; #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST pn547_dev->clk_req_gpio = platform_data->clk_req_gpio; pn547_dev->clk_req_irq = platform_data->clk_req_irq; #endif #ifdef CONFIG_SEC_K_PROJECT pn547_dev->scl_gpio = platform_data->scl_gpio; pn547_dev->sda_gpio = platform_data->sda_gpio; #endif #ifdef CONFIG_NFC_PN547_8226_USE_BBCLK2 pn547_dev->clk_req_gpio = platform_data->clk_req_gpio; #endif pn547_dev->client = client; /* init mutex and queues */ init_waitqueue_head(&pn547_dev->read_wq); mutex_init(&pn547_dev->read_mutex); pn547_dev->pn547_device.minor = MISC_DYNAMIC_MINOR; #ifdef CONFIG_NFC_PN547 pn547_dev->pn547_device.name = "pn547"; #else pn547_dev->pn547_device.name = "pn544"; #endif pn547_dev->pn547_device.fops = &pn547_dev_fops; ret = misc_register(&pn547_dev->pn547_device); if (ret) { pr_err("%s : misc_register failed\n", __FILE__); goto err_misc_register; } /* request irq. the irq is set whenever the chip has data available * for reading. it is cleared when all data has been read. */ pr_info("%s : requesting IRQ %d\n", __func__, client->irq); gpio_direction_input(pn547_dev->irq_gpio); gpio_direction_output(pn547_dev->ven_gpio, 0); gpio_direction_output(pn547_dev->firm_gpio, 0); #if defined(CONFIG_NFC_PN547_CLOCK_REQUEST) || defined(CONFIG_NFC_PN547_8226_USE_BBCLK2) gpio_direction_input(pn547_dev->clk_req_gpio); #endif i2c_set_clientdata(client, pn547_dev); wake_lock_init(&pn547_dev->nfc_wake_lock, WAKE_LOCK_SUSPEND, "nfc_wake_lock"); #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST pn547_dev->wq_clock = create_singlethread_workqueue("nfc_wq"); if (!pn547_dev->wq_clock) { ret = -ENOMEM; pr_err("%s: could not create workqueue\n", __func__); goto err_create_workqueue; } INIT_WORK(&pn547_dev->work_nfc_clock, nfc_work_func_clock); #endif ret = request_irq(client->irq, pn547_dev_irq_handler, IRQF_TRIGGER_RISING, "pn547", pn547_dev); if (ret) { dev_err(&client->dev, "request_irq failed\n"); goto err_request_irq_failed; } disable_irq_nosync(pn547_dev->client->irq); atomic_set(&pn547_dev->irq_enabled, 0); #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST ret = request_irq(pn547_dev->clk_req_irq, pn547_dev_clk_req_irq_handler, IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING , "pn547_clk_req", pn547_dev); if (ret) { dev_err(&client->dev, "request_irq(clk_req) failed\n"); goto err_request_irq_failed; } enable_irq_wake(pn547_dev->clk_req_irq); #endif gpio_set_value(pn547_dev->ven_gpio, 1); gpio_set_value(pn547_dev->firm_gpio, 1); /* add firmware pin */ usleep_range(4900, 5000); gpio_set_value(pn547_dev->ven_gpio, 0); usleep_range(4900, 5000); gpio_set_value(pn547_dev->ven_gpio, 1); usleep_range(4900, 5000); for (addr = 0x2B; addr > 0x27; addr--) { client->addr = addr; addrcnt = 2; do { ret = i2c_master_send(client, tmp, 4); if (ret > 0) { pr_info("%s : i2c addr=0x%X\n", __func__, client->addr); break; } } while (addrcnt--); if (ret > 0) break; } if(ret <= 0) client->addr = 0x2B; gpio_set_value(pn547_dev->ven_gpio, 0); gpio_set_value(pn547_dev->firm_gpio, 0); /* add */ if (ret < 0) pr_err("%s : fail to get i2c addr\n", __func__); /* goto err_request_irq_failed; */ else pr_info("%s : success\n", __func__); return 0; err_request_irq_failed: #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST err_create_workqueue: #endif misc_deregister(&pn547_dev->pn547_device); wake_lock_destroy(&pn547_dev->nfc_wake_lock); err_misc_register: mutex_destroy(&pn547_dev->read_mutex); #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST msm_xo_put(pn547_dev->nfc_clock); err_get_clock: #endif kfree(pn547_dev); err_exit: #if defined(CONFIG_NFC_PN547_CLOCK_REQUEST) || defined(CONFIG_NFC_PN547_8226_USE_BBCLK2) gpio_free(platform_data->clk_req_gpio); err_clk_req: #endif gpio_free(platform_data->firm_gpio); err_firm: gpio_free(platform_data->ven_gpio); err_ven: gpio_free(platform_data->irq_gpio); pr_err("[pn547] pn547_probe fail!\n"); return ret; }
static int pn547_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret; struct pn547_dev *pn547_dev = NULL; pn547_client = client; pr_info(PN547_DRV_NAME ": pn547_probe() start\n"); pn547_dev = kzalloc(sizeof(*pn547_dev), GFP_KERNEL); if (pn547_dev == NULL) { dev_err(&client->dev, "failed to allocate memory for module data\n"); ret = -ENOMEM; goto err_exit; } pn547_parse_dt(&client->dev, pn547_dev); pn547_dev->client = client; pr_info(PN547_DRV_NAME ":IRQ : %d\nVEN : %d\nFIRM : %d\n", pn547_dev->irq_gpio, pn547_dev->ven_gpio, pn547_dev->firm_gpio); ret = gpio_request(pn547_dev->irq_gpio, "nfc_int"); if (ret) { pr_info(PN547_DRV_NAME ":pn547_probe() : nfc_int request failed!\n"); goto err_int; } ret = gpio_request(pn547_dev->ven_gpio, "nfc_ven"); if (ret) { pr_info(PN547_DRV_NAME ":pn547_probe() : nfc_ven request failed!\n"); goto err_ven; } ret = gpio_request(pn547_dev->firm_gpio, "nfc_firm"); if (ret) { pr_info(PN547_DRV_NAME ":pn547_probe() : nfc_firm request failed!\n"); goto err_firm; } pn547_gpio_enable(pn547_dev); ret = gpio_direction_output(pn547_dev->ven_gpio,0); ret = gpio_direction_output(pn547_dev->firm_gpio,0); ret = gpio_direction_input(pn547_dev->irq_gpio); #ifdef CONFIG_LGE_NFC_USE_PMIC pn547_get_clk_source(pn547_client, pn547_dev); #endif /* init mutex and queues */ init_waitqueue_head(&pn547_dev->read_wq); mutex_init(&pn547_dev->read_mutex); spin_lock_init(&pn547_dev->irq_enabled_lock); pn547_dev->pn547_device.minor = MISC_DYNAMIC_MINOR; pn547_dev->pn547_device.name = PN547_DRV_NAME; pn547_dev->pn547_device.fops = &pn547_dev_fops; ret = misc_register(&pn547_dev->pn547_device); if (ret) { pr_err("%s : misc_register failed\n", __FILE__); goto err_misc_register; } wake_lock_init(&nfc_wake_lock, WAKE_LOCK_SUSPEND, "NFCWAKE"); /* request irq. the irq is set whenever the chip has data available * for reading. it is cleared when all data has been read. */ pr_info("%s : requesting IRQ %d\n", __func__, client->irq); pn547_dev->irq_enabled = true; ret = request_irq(pn547_gpio_to_irq(pn547_dev), pn547_dev_irq_handler, IRQF_TRIGGER_RISING|IRQF_NO_SUSPEND, client->name, pn547_dev); if (ret) { dev_err(&client->dev, "request_irq failed\n"); goto err_request_irq_failed; } enable_irq_wake(pn547_get_irq_pin(pn547_dev)); pn547_disable_irq(pn547_dev); i2c_set_clientdata(client, pn547_dev); pr_info(PN547_DRV_NAME ": pn547_probe() end\n"); return 0; err_request_irq_failed: misc_deregister(&pn547_dev->pn547_device); err_misc_register: mutex_destroy(&pn547_dev->read_mutex); gpio_free(pn547_dev->firm_gpio); err_firm: gpio_free(pn547_dev->ven_gpio); err_ven: gpio_free(pn547_dev->irq_gpio); err_int: kfree(pn547_dev); err_exit: pr_err(PN547_DRV_NAME ": pn547_dev is null\n"); pr_err(PN547_DRV_NAME ": pn547_probe() end with error!\n"); return ret; }
static int pn547_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret,err; struct pn547_i2c_platform_data *platform_data; struct pn547_dev *pn547_dev; #if defined (MULITPLE_ADDRESS_PN65T) int addr; char tmp[4] = {0x20, 0x00, 0x01, 0x01}; int addrcnt; #endif pr_info("%s started...\n", __func__); if (client->dev.of_node) { platform_data = devm_kzalloc(&client->dev, sizeof(struct pn547_i2c_platform_data), GFP_KERNEL); if (!platform_data) { dev_err(&client->dev, "Failed to allocate memory\n"); return -ENOMEM; } err = pn547_parse_dt(&client->dev, platform_data); if (err) return err; } else { platform_data = client->dev.platform_data; } if (platform_data == NULL) { dev_err(&client->dev, "%s : nfc probe fail\n", __func__); return -ENODEV; } if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { dev_err(&client->dev, "%s : need I2C_FUNC_I2C\n", __func__); return -ENODEV; } ret = gpio_request(platform_data->irq_gpio, "nfc_int"); if (ret) return -ENODEV; ret = gpio_request(platform_data->ven_gpio, "nfc_ven"); if (ret) goto err_ven; ret = gpio_request(platform_data->firm_gpio, "nfc_firm"); if (ret) goto err_firm; #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST if (platform_data->clk_use_check) { ret = gpio_request(platform_data->clk_req_gpio, "nfc_clk_req"); if (ret) goto err_clk_req; } #endif pn547_dev = kzalloc(sizeof(*pn547_dev), GFP_KERNEL); if (pn547_dev == NULL) { dev_err(&client->dev, "failed to allocate memory for module data\n"); ret = -ENOMEM; goto err_exit; } #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST #if defined(CONFIG_SOC_EXYNOS5430) pn547_dev->pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL); if (pn547_dev->pdev == NULL) { dev_err(&client->dev, "failed to allocate memory for module data\n"); ret = -ENOMEM; goto err_exit2; } else { pn547_dev->pdev->dev = client->dev; } #endif #endif pn547_dev->irq_gpio = platform_data->irq_gpio; pn547_dev->ven_gpio = platform_data->ven_gpio; pn547_dev->firm_gpio = platform_data->firm_gpio; #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST pn547_dev->clk_use_check = platform_data->clk_use_check; pn547_dev->clk_req_gpio = platform_data->clk_req_gpio; #endif pn547_dev->client = client; /* init mutex and queues */ init_waitqueue_head(&pn547_dev->read_wq); mutex_init(&pn547_dev->read_mutex); pn547_dev->pn547_device.minor = MISC_DYNAMIC_MINOR; pn547_dev->pn547_device.name = "pn547"; pn547_dev->pn547_device.fops = &pn547_dev_fops; ret = misc_register(&pn547_dev->pn547_device); if (ret) { dev_err(&client->dev, "%s : misc_register failed. ret = %d\n", __FILE__, ret); goto err_misc_register; } i2c_set_clientdata(client, pn547_dev); wake_lock_init(&pn547_dev->nfc_wake_lock, WAKE_LOCK_SUSPEND, "nfc_wake_lock"); gpio_direction_output(pn547_dev->ven_gpio, 0); gpio_direction_output(pn547_dev->firm_gpio, 0); /* request irq. the irq is set whenever the chip has data available * for reading. it is cleared when all data has been read. */ ret = gpio_direction_input(pn547_dev->irq_gpio); if (ret) { dev_err(&client->dev, "%s : gpio_direction_input failed. ret = %d\n", __FILE__, ret); goto err_request_irq_failed; } client->irq = gpio_to_irq(pn547_dev->irq_gpio); dev_info(&pn547_dev->client->dev, "%s : requesting IRQ %d\n", __func__, client->irq); ret = request_irq(client->irq, pn547_dev_irq_handler, IRQF_TRIGGER_RISING | IRQF_ONESHOT, "pn547", pn547_dev); if (ret) { dev_err(&client->dev, "request_irq failed. ret = %d\n", ret); goto err_request_irq_failed; } disable_irq_nosync(pn547_dev->client->irq); #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST if (pn547_dev->clk_use_check) { ret = pn547_clk_initialize(pn547_dev); if (ret) { dev_err(&client->dev, "%s : pn547_clk_initialize failed %d\n", __FILE__, ret); goto err_clk_get; } ret = gpio_direction_input(pn547_dev->clk_req_gpio); if (ret) { dev_err(&client->dev, "%s : gpio_direction_input failed. ret = %d\n", __FILE__, ret); goto err_request_clk_req_failed; } pn547_dev->clk_req_irq = gpio_to_irq(pn547_dev->clk_req_gpio); dev_info(&pn547_dev->client->dev, "%s : requesting clk_req irq %d\n", __func__, pn547_dev->clk_req_irq); ret = request_irq(pn547_dev->clk_req_irq, pn547_dev_clk_req_irq_handler, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |IRQF_ONESHOT, "pn547_clk_req", pn547_dev); if (ret) { dev_err(&client->dev, "clk_req request_irq failed. ret = %d\n", ret); goto err_request_clk_req_failed; } disable_irq_nosync(pn547_dev->clk_req_irq); } #endif atomic_set(&pn547_dev->irq_enabled, 0); #if defined (MULITPLE_ADDRESS_PN65T) gpio_set_value(pn547_dev->ven_gpio, 1); gpio_set_value(pn547_dev->firm_gpio, 1); /* add firmware pin */ usleep_range(4900, 5000); gpio_set_value(pn547_dev->ven_gpio, 0); usleep_range(4900, 5000); gpio_set_value(pn547_dev->ven_gpio, 1); usleep_range(4900, 5000); for (addr = 0x2B; addr > 0x27; addr--) { client->addr = addr; addrcnt = 2; do { ret = i2c_master_send(client, tmp, 4); if (ret > 0) { pr_info("%s : i2c addr=0x%X\n", __func__, client->addr); break; } } while (addrcnt--); if (ret > 0) break; } if (ret <= 0) client->addr = 0x2B; gpio_set_value(pn547_dev->ven_gpio, 0); gpio_set_value(pn547_dev->firm_gpio, 0); if (ret < 0) { pr_err("%s : fail to get i2c addr\n", __func__); goto err_search_requset_failed; } #endif pr_info("%s finished...\n",__func__); return 0; #if defined (MULITPLE_ADDRESS_PN65T) err_search_requset_failed: #endif #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST err_request_clk_req_failed: if (pn547_dev->clk_use_check) pn547_clk_uninitialize(pn547_dev); err_clk_get: free_irq(client->irq, pn547_dev); #endif err_request_irq_failed: wake_lock_destroy(&pn547_dev->nfc_wake_lock); misc_deregister(&pn547_dev->pn547_device); err_misc_register: mutex_destroy(&pn547_dev->read_mutex); #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST #if defined(CONFIG_SOC_EXYNOS5430) kfree(pn547_dev->pdev); err_exit2: #endif #endif kfree(pn547_dev); err_exit: #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST if (platform_data->clk_use_check) gpio_free(platform_data->clk_req_gpio); err_clk_req: #endif gpio_free(platform_data->firm_gpio); err_firm: gpio_free(platform_data->ven_gpio); err_ven: gpio_free(platform_data->irq_gpio); return ret; }
static int pn547_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct pn547_dev *dev; struct pn547_i2c_platform_data *pdata; struct clk *nfc_clk = NULL; int ret = 0; pdata = kzalloc(sizeof(struct pn547_i2c_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&client->dev, "failed to get allocate memory\n"); ret = -ENOMEM; goto probe_pdata; } ret = pn547_parse_dt(&client->dev, pdata); if (ret < 0) { dev_err(&client->dev, "failed to parse device tree: %d\n", ret); goto probe_parse_dt; } ret = board_nfc_parse_dt(&client->dev, pdata); if (ret < 0) { dev_err(&client->dev, "failed to parse device tree: %d\n", ret); goto probe_parse_dt; } if (pdata->dynamic_config) { ret = board_nfc_hw_lag_check(client, pdata); if (ret < 0) goto probe_hw_lag_check; } ret = pn547_gpio_request(&client->dev, pdata); if (ret) { dev_err(&client->dev, "failed to request gpio\n"); goto probe_gpio_request; } dev_dbg(&client->dev, "%s:\n", __func__); if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { dev_err(&client->dev, "%s: i2c check failed\n", __func__); ret = -ENODEV; goto probe_i2c; } dev = kzalloc(sizeof(struct pn547_dev), GFP_KERNEL); if (!dev) { dev_err(&client->dev, "%s: no memory\n", __func__); ret = -ENOMEM; goto probe_mem; } dev->i2c_client = client; dev->dev = &client->dev; dev->pdata = pdata; init_waitqueue_head(&dev->wq); wake_lock_init(&dev->wake_lock, WAKE_LOCK_SUSPEND, "pn547"); i2c_set_clientdata(client, dev); dev->state = PN547_STATE_UNKNOWN; ret = request_threaded_irq(client->irq, NULL, pn547_dev_irq_handler, IRQF_TRIGGER_RISING | IRQF_ONESHOT, client->name, dev); if (IS_ERR_VALUE(ret)) { dev_err(&client->dev, "%s: irq request err %d\n", __func__, ret); goto probe_irq; } nfc_clk = clk_get(&client->dev, "nfc_clk"); if (IS_ERR(nfc_clk)) { dev_err(&client->dev, "Couldn't get nfc_clk\n"); goto probe_clk; } ret = clk_prepare_enable(nfc_clk); if (ret) { dev_err(&client->dev, "nfc_clk enable is failed\n"); goto probe_clk_enable; } ret = pn547_dev_create_sysfs_entries(dev->i2c_client); if (IS_ERR_VALUE(ret)) { dev_err(&client->dev, "%s: create sysfs entries err %d\n", __func__, ret); goto probe_sysfs; } return ret; probe_sysfs: free_irq(client->irq, dev); probe_clk_enable: clk_put(nfc_clk); probe_clk: probe_irq: i2c_set_clientdata(client, NULL); wake_lock_destroy(&dev->wake_lock); kzfree(dev); probe_mem: probe_i2c: pn547_gpio_release(pdata); probe_gpio_request: probe_hw_lag_check: probe_parse_dt: kzfree(pdata); probe_pdata: dev_err(&client->dev, "%s: err %d\n", __func__, ret); return ret; }
static int pn547_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret; int err; struct pn547_i2c_platform_data *platform_data; struct pn547_dev *pn547_dev; if (client->dev.of_node) { platform_data = devm_kzalloc(&client->dev, sizeof(struct pn547_i2c_platform_data), GFP_KERNEL); if (!platform_data) { dev_err(&client->dev, "Failed to allocate memory\n"); return -ENOMEM; } err = pn547_parse_dt(&client->dev, platform_data); if (err) return err; } else { platform_data = client->dev.platform_data; } if (platform_data == NULL) { pr_err("%s : nfc probe fail\n", __func__); return -ENODEV; } if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("%s : need I2C_FUNC_I2C\n", __func__); return -ENODEV; } ret = gpio_request(platform_data->irq_gpio, "nfc_int"); if (ret) return -ENODEV; ret = gpio_request(platform_data->ven_gpio, "nfc_ven"); if (ret) goto err_ven; ret = gpio_request(platform_data->firm_gpio, "nfc_firm"); if (ret) goto err_firm; #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST ret = gpio_request(platform_data->clk_req_gpio, "nfc_clk_req"); if (ret) goto err_clk_req; #endif pn547_dev = kzalloc(sizeof(*pn547_dev), GFP_KERNEL); if (pn547_dev == NULL) { dev_err(&client->dev, "failed to allocate memory for module data\n"); ret = -ENOMEM; goto err_exit; } #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST pn547_dev->nfc_clock = msm_xo_get(MSM_XO_TCXO_A1, "nfc"); if (IS_ERR(pn547_dev->nfc_clock)) { ret = PTR_ERR(pn547_dev->nfc_clock); printk(KERN_ERR "%s: Couldn't get TCXO_A1 vote for NFC (%d)\n", __func__, ret); ret = -ENODEV; goto err_get_clock; } pn547_dev->clock_state = false; #endif #ifdef CONFIG_NFC_PN547_8941_CLOCK_REQUEST pn547_dev->nfc_clk = clk_get(NULL, "nfc_clk"); if (IS_ERR(pn547_dev->nfc_clk)) { ret = PTR_ERR(pn547_dev->nfc_clk); printk(KERN_ERR "%s: Couldn't get D1 (%d)\n", __func__, ret); } else { if (clk_prepare_enable(pn547_dev->nfc_clk)) printk(KERN_ERR "%s: Couldn't prepare D1\n", __func__); } #endif pr_info("%s : IRQ num %d\n", __func__, client->irq); pn547_dev->irq_gpio = platform_data->irq_gpio; pn547_dev->ven_gpio = platform_data->ven_gpio; pn547_dev->firm_gpio = platform_data->firm_gpio; pn547_dev->conf_gpio = platform_data->conf_gpio; #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST pn547_dev->clk_req_gpio = platform_data->clk_req_gpio; pn547_dev->clk_req_irq = platform_data->clk_req_irq; #endif pn547_dev->client = client; /* init mutex and queues */ init_waitqueue_head(&pn547_dev->read_wq); mutex_init(&pn547_dev->read_mutex); pn547_dev->pn547_device.minor = MISC_DYNAMIC_MINOR; #ifdef CONFIG_NFC_PN547 pn547_dev->pn547_device.name = "pn547"; #else pn547_dev->pn547_device.name = "pn544"; #endif pn547_dev->pn547_device.fops = &pn547_dev_fops; ret = misc_register(&pn547_dev->pn547_device); if (ret) { pr_err("%s : misc_register failed\n", __FILE__); goto err_misc_register; } /* request irq. the irq is set whenever the chip has data available * for reading. it is cleared when all data has been read. */ pr_info("%s : requesting IRQ %d\n", __func__, client->irq); gpio_direction_input(pn547_dev->irq_gpio); gpio_direction_output(pn547_dev->ven_gpio, 0); gpio_direction_output(pn547_dev->firm_gpio, 0); #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST gpio_direction_input(pn547_dev->clk_req_gpio); #endif i2c_set_clientdata(client, pn547_dev); wake_lock_init(&pn547_dev->nfc_wake_lock, WAKE_LOCK_SUSPEND, "nfc_wake_lock"); #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST pn547_dev->wq_clock = create_singlethread_workqueue("nfc_wq"); if (!pn547_dev->wq_clock) { ret = -ENOMEM; pr_err("%s: could not create workqueue\n", __func__); goto err_create_workqueue; } INIT_WORK(&pn547_dev->work_nfc_clock, nfc_work_func_clock); #endif ret = request_irq(client->irq, pn547_dev_irq_handler, IRQF_TRIGGER_RISING, "pn547", pn547_dev); if (ret) { dev_err(&client->dev, "request_irq failed\n"); goto err_request_irq_failed; } disable_irq_nosync(pn547_dev->client->irq); atomic_set(&pn547_dev->irq_enabled, 0); #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST ret = request_irq(pn547_dev->clk_req_irq, pn547_dev_clk_req_irq_handler, IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING , "pn547_clk_req", pn547_dev); if (ret) { dev_err(&client->dev, "request_irq(clk_req) failed\n"); goto err_request_irq_failed; } enable_irq_wake(pn547_dev->clk_req_irq); #endif pr_info("%s : success\n", __func__); return 0; err_request_irq_failed: #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST err_create_workqueue: #endif misc_deregister(&pn547_dev->pn547_device); wake_lock_destroy(&pn547_dev->nfc_wake_lock); err_misc_register: mutex_destroy(&pn547_dev->read_mutex); #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST msm_xo_put(pn547_dev->nfc_clock); err_get_clock: #endif kfree(pn547_dev); err_exit: #ifdef CONFIG_NFC_PN547_CLOCK_REQUEST gpio_free(platform_data->clk_req_gpio); err_clk_req: #endif gpio_free(platform_data->firm_gpio); err_firm: gpio_free(platform_data->ven_gpio); err_ven: gpio_free(platform_data->irq_gpio); pr_err("[pn547] pn547_probe fail!\n"); return ret; }
static int pn547_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret; int err; struct pn547_i2c_platform_data *platform_data; struct pn547_dev *pn547_dev; struct pinctrl *nfc_pinctrl; struct pinctrl_state *nfc_suspend; struct pinctrl_state *nfc_active; //nfc_power_onoff(1); //msleep(20); if (client->dev.of_node) { platform_data = devm_kzalloc(&client->dev, sizeof(struct pn547_i2c_platform_data), GFP_KERNEL); if (!platform_data) { dev_err(&client->dev, "Failed to allocate memory\n"); return -ENOMEM; } err = pn547_parse_dt(&client->dev, platform_data); if (err) return err; } else { platform_data = client->dev.platform_data; } if (platform_data == NULL) { pr_err("%s : nfc probe fail\n", __func__); return -ENODEV; } if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("%s : need I2C_FUNC_I2C\n", __func__); return -ENODEV; } ret = gpio_request(platform_data->irq_gpio, "nfc_int"); if (ret) return -ENODEV; ret = gpio_request(platform_data->ven_gpio, "nfc_ven"); if (ret) goto err_ven; ret = gpio_request(platform_data->firm_gpio, "nfc_firm"); if (ret) goto err_firm; /* Get pinctrl if target uses pinctrl */ nfc_pinctrl = devm_pinctrl_get(&client->dev); if (IS_ERR(nfc_pinctrl)) { pr_debug("Target does not use pinctrl\n"); nfc_pinctrl = NULL; } else { nfc_suspend = pinctrl_lookup_state(nfc_pinctrl, "nfc_suspend"); nfc_active = pinctrl_lookup_state(nfc_pinctrl, "nfc_active"); if (IS_ERR(nfc_suspend)) { pr_info("%s fail to suspend lookup_state\n", __func__); goto err_exit; } if (IS_ERR(nfc_active)) { pr_info("%s fail to active lookup_state\n", __func__); goto err_exit; } ret = pinctrl_select_state(nfc_pinctrl, nfc_suspend); if (ret != 0) { pr_err("%s: fail to select_state suspend\n", __func__); goto err_exit; } ret = pinctrl_select_state(nfc_pinctrl, nfc_active); if (ret != 0) { pr_err("%s: fail to select_state active\n", __func__); goto err_exit; } devm_pinctrl_put(nfc_pinctrl); } pn547_dev = kzalloc(sizeof(*pn547_dev), GFP_KERNEL); if (pn547_dev == NULL) { dev_err(&client->dev, "failed to allocate memory for module data\n"); ret = -ENOMEM; goto err_exit; } pr_info("%s : IRQ num %d\n", __func__, client->irq); pn547_dev->irq_gpio = platform_data->irq_gpio; pn547_dev->ven_gpio = platform_data->ven_gpio; pn547_dev->firm_gpio = platform_data->firm_gpio; pn547_dev->conf_gpio = platform_data->conf_gpio; pn547_dev->nfc_clock = platform_data->nfc_clock; pn547_dev->client = client; #ifdef CONFIG_NFC_PN547_8916_CLK_CTL pn547_dev->nfc_enable = 0; #endif /* init mutex and queues */ init_waitqueue_head(&pn547_dev->read_wq); mutex_init(&pn547_dev->read_mutex); pn547_dev->pn547_device.minor = MISC_DYNAMIC_MINOR; #ifdef CONFIG_NFC_PN547 pn547_dev->pn547_device.name = "pn547"; #else pn547_dev->pn547_device.name = "pn544"; #endif pn547_dev->pn547_device.fops = &pn547_dev_fops; ret = misc_register(&pn547_dev->pn547_device); if (ret) { pr_err("%s : misc_register failed\n", __FILE__); goto err_misc_register; } /* request irq. the irq is set whenever the chip has data available * for reading. it is cleared when all data has been read. */ pr_info("%s : requesting IRQ %d\n", __func__, client->irq); gpio_direction_input(pn547_dev->irq_gpio); gpio_direction_output(pn547_dev->ven_gpio, 0); gpio_direction_output(pn547_dev->firm_gpio, 0); i2c_set_clientdata(client, pn547_dev); wake_lock_init(&pn547_dev->nfc_wake_lock, WAKE_LOCK_SUSPEND, "nfc_wake_lock"); #if 0 nfc_power_onoff(pn547_dev,1); #endif ret = request_irq(client->irq, pn547_dev_irq_handler, IRQF_TRIGGER_RISING, "pn547", pn547_dev); if (ret) { dev_err(&client->dev, "request_irq failed\n"); goto err_request_irq_failed; } disable_irq_nosync(pn547_dev->client->irq); atomic_set(&pn547_dev->irq_enabled, 0); gpio_set_value(pn547_dev->firm_gpio, 1); /* add firmware pin */ msleep(20); gpio_set_value(pn547_dev->ven_gpio, 1); usleep_range(4900, 5000); gpio_set_value(pn547_dev->ven_gpio, 0); usleep_range(4900, 5000); gpio_set_value(pn547_dev->ven_gpio, 1); usleep_range(4900, 5000); gpio_set_value(pn547_dev->ven_gpio, 0); gpio_set_value(pn547_dev->firm_gpio, 0); /* add */ if (ret < 0) pr_err("%s : fail to get i2c addr\n", __func__); /* goto err_request_irq_failed; */ else pr_info("%s : success\n", __func__); return 0; err_request_irq_failed: misc_deregister(&pn547_dev->pn547_device); wake_lock_destroy(&pn547_dev->nfc_wake_lock); err_misc_register: mutex_destroy(&pn547_dev->read_mutex); kfree(pn547_dev); err_exit: gpio_free(platform_data->firm_gpio); err_firm: gpio_free(platform_data->ven_gpio); err_ven: gpio_free(platform_data->irq_gpio); pr_err("[pn547] pn547_probe fail!\n"); return ret; }
static int pn547_probe(struct i2c_client *client, const struct i2c_device_id *id) { int ret = 0; int rc = 0; struct clk *nfc_clk = NULL; struct pn547_i2c_platform_data *platform_data; struct pn547_dev *pn547_dev; printk("### %s begin! \n",__func__); dev_info(&client->dev, "%s ++\n", __func__); platform_data = kzalloc(sizeof(struct pn547_i2c_platform_data), GFP_KERNEL); if (platform_data == NULL) { dev_err(&client->dev, "failed to allocate memory\n"); ret = -ENOMEM; goto err_platform_data; } printk("### %s 11 begin! \n",__func__); ret = pn547_parse_dt(&client->dev, platform_data); if (ret < 0) { dev_err(&client->dev, "failed to parse device tree: %d\n", ret); goto err_parse_dt; } printk("pn547 dev kobj_name=%s,init_name=%s,id=%d\n",client->dev.kobj.name,client->dev.init_name, client->dev.id); nfc_clk = clk_get(&client->dev, "nfc_pn547clk"); if (nfc_clk == NULL) { dev_err(&client->dev, "failed to get clk: %d\n", ret); goto err_parse_dt; } rc = clk_set_rate(nfc_clk,19200000); if(rc){ dev_err(&client->dev, "Clock set rate failed: %d\n",rc); } ret = clk_prepare_enable(nfc_clk); if (ret) { dev_err(&client->dev, "failed to enable clk: %d\n", ret); goto err_parse_dt; } ret = pn547_gpio_request(&client->dev, platform_data); if (ret) { dev_err(&client->dev, "failed to request gpio\n"); goto err_gpio_request; } dev_dbg(&client->dev, "%s:\n", __func__); if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { dev_err(&client->dev, "%s: i2c check failed\n", __func__); ret = -ENODEV; goto err_i2c; } printk("### %s 22 begin! \n",__func__); pn547_dev = kzalloc(sizeof(*pn547_dev), GFP_KERNEL); if (pn547_dev == NULL) { dev_err(&client->dev, "failed to allocate memory for module data\n"); ret = -ENOMEM; goto err_exit; } client->irq = gpio_to_irq(platform_data->irq_gpio); pn547_dev->irq_gpio = platform_data->irq_gpio; pn547_dev->ven_gpio = platform_data->ven_gpio; pn547_dev->firm_gpio = platform_data->fwdl_en_gpio; pn547_dev->clk_req_gpio = platform_data->clk_req_gpio; pn547_dev->client = client; pn547_dev->dev = &client->dev; pn547_dev->do_reading = 0; /* Initialise mutex and work queue */ init_waitqueue_head(&pn547_dev->read_wq); mutex_init(&pn547_dev->read_mutex); spin_lock_init(&pn547_dev->irq_enabled_lock); wake_lock_init(&pn547_dev->wl,WAKE_LOCK_SUSPEND,"nfc_locker"); pn547_dev->pn547_device.minor = MISC_DYNAMIC_MINOR; pn547_dev->pn547_device.name = "pn544"; pn547_dev->pn547_device.fops = &pn547_dev_fops; printk("### %s 33 begin! \n",__func__); ret = misc_register(&pn547_dev->pn547_device); if (ret) { dev_err(&client->dev, "%s: misc_register err %d\n", __func__, ret); goto err_misc_register; } /* 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, "%s : requesting IRQ %d\n", __func__, client->irq); pn547_dev->irq_enabled = true; ret = request_irq(client->irq, pn547_dev_irq_handler, IRQF_TRIGGER_RISING | IRQF_NO_SUSPEND | IRQF_ONESHOT, client->name, pn547_dev); if (ret) { dev_err(&client->dev, "request_irq failed\n"); goto err_request_irq_failed; } pn547_disable_irq(pn547_dev); i2c_set_clientdata(client, pn547_dev); return 0; err_request_irq_failed: misc_deregister(&pn547_dev->pn547_device); err_misc_register: mutex_destroy(&pn547_dev->read_mutex); kfree(pn547_dev); err_exit: err_i2c: pn547_gpio_release(platform_data); err_gpio_request: err_parse_dt: kfree(platform_data); err_platform_data: dev_err(&client->dev, "%s: err %d\n", __func__, ret); return ret; }