static int p61_probe(struct spi_device *spi) { int ret = -1; struct p61_spi_platform_data *platform_data = NULL; struct p61_spi_platform_data platform_data1; struct p61_dev *p61_dev = NULL; #ifdef P61_IRQ_ENABLE unsigned int irq_flags; #endif P61_DBG_MSG("%s chip select : %d , bus number = %d \n", __FUNCTION__, spi->chip_select, spi->master->bus_num); #if !DRAGON_P61 platform_data = spi->dev.platform_data; if (platform_data == NULL) { /* RC : rename the platformdata1 name */ /* TBD: This is only for Panda as we are passing NULL for platform data */ P61_ERR_MSG("%s : p61 probe fail\n", __func__); platform_data1.irq_gpio = P61_IRQ; platform_data1.rst_gpio = P61_RST; platform_data = &platform_data1; P61_ERR_MSG("%s : p61 probe fail1\n", __func__); //return -ENODEV; } #else ret = p61_parse_dt(&spi->dev, &platform_data1); if (ret) { pr_err("%s - Failed to parse DT\n", __func__); goto err_exit; } platform_data = &platform_data1; #endif p61_dev = kzalloc(sizeof(*p61_dev), GFP_KERNEL); if (p61_dev == NULL) { P61_ERR_MSG("failed to allocate memory for module data\n"); ret = -ENOMEM; goto err_exit; } ret = p61_hw_setup (platform_data, p61_dev, spi); if (ret < 0) { P61_ERR_MSG("Failed to p61_enable_P61_IRQ_ENABLE\n"); goto err_exit0; } spi->bits_per_word = 8; spi->mode = SPI_MODE_0; spi->max_speed_hz = P61_SPI_CLOCK; //spi->chip_select = SPI_NO_CS; ret = spi_setup(spi); if (ret < 0) { P61_ERR_MSG("failed to do spi_setup()\n"); goto err_exit0; } p61_dev -> spi = spi; p61_dev -> p61_device.minor = MISC_DYNAMIC_MINOR; p61_dev -> p61_device.name = "p73"; p61_dev -> p61_device.fops = &p61_dev_fops; p61_dev -> p61_device.parent = &spi->dev; p61_dev->irq_gpio = platform_data->irq_gpio; p61_dev->rst_gpio = platform_data->rst_gpio; dev_set_drvdata(&spi->dev, p61_dev); /* init mutex and queues */ init_waitqueue_head(&p61_dev->read_wq); mutex_init(&p61_dev->read_mutex); mutex_init(&p61_dev->write_mutex); #ifdef P61_IRQ_ENABLE spin_lock_init(&p61_dev->irq_enabled_lock); #endif ret = misc_register(&p61_dev->p61_device); if (ret < 0) { P61_ERR_MSG("misc_register failed! %d\n", ret); goto err_exit0; } #ifdef P61_IRQ_ENABLE p61_dev->spi->irq = gpio_to_irq(platform_data->irq_gpio); if ( p61_dev->spi->irq < 0) { P61_ERR_MSG("gpio_to_irq request failed gpio = 0x%x\n", platform_data->irq_gpio); goto err_exit1; } /* request irq. the irq is set whenever the chip has data available * for reading. it is cleared when all data has been read. */ p61_dev->irq_enabled = true; p61_through_put_t.enable_through_put_measure = false; irq_flags = IRQF_TRIGGER_RISING | IRQF_ONESHOT; ret = request_irq(p61_dev->spi->irq, p61_dev_irq_handler, irq_flags, p61_dev -> p61_device.name, p61_dev); if (ret) { P61_ERR_MSG("request_irq failed\n"); goto err_exit1; } p61_disable_irq(p61_dev); #endif p61_dev-> enable_poll_mode = 0; /* Default IRQ read mode */ P61_DBG_MSG("Exit : %s\n", __FUNCTION__); return ret; err_exit1: misc_deregister(&p61_dev->p61_device); err_exit0: mutex_destroy(&p61_dev->read_mutex); mutex_destroy(&p61_dev->write_mutex); if(p61_dev != NULL) kfree(p61_dev); err_exit: P61_DBG_MSG("ERROR: Exit : %s ret %d\n", __FUNCTION__, ret); return ret; }
static int p61_probe(struct spi_device *spi) { int ret = -1; //struct p61_spi_platform_data *platform_data = NULL; //struct p61_spi_platform_data platform_data1; struct p61_dev *p61_dev = NULL; #ifdef P61_IRQ_ENABLE unsigned int irq_flags; #endif P61_DBG_MSG("%s chip select : %d , bus number = %d \n", __FUNCTION__, spi->chip_select, spi->master->bus_num); //platform_data = spi->dev.platform_data; #if 0 if (platform_data == NULL) { /* RC : rename the platformdata1 name */ /* TBD: This is only for Panda as we are passing NULL for platform data */ P61_ERR_MSG("%s : p61 probe fail\n", __func__); //platform_data1.irq_gpio = P61_IRQ; //platform_data1.rst_gpio = P61_RST; //platform_data = &platform_data1; P61_ERR_MSG("%s : p61 probe fail1\n", __func__); return -ENODEV; } #endif p61_dev = kzalloc(sizeof(*p61_dev), GFP_KERNEL); if (p61_dev == NULL) { P61_ERR_MSG("failed to allocate memory for module data\n"); ret = -ENOMEM; goto err_exit; } ret = p61_parse_dt(&spi->dev, p61_dev); if (ret) { pr_err("%s - Failed to parse DT\n", __func__); goto p61_parse_dt_failed; } pr_info("%s: tz_mode=%d, isGpio_cfgDone:%d\n", __func__, p61_dev->tz_mode, p61_dev->isGpio_cfgDone); #if 0 ret = p61_hw_setup (platform_data, p61_dev, spi); if (ret < 0) { P61_ERR_MSG("Failed to p61_enable_P61_IRQ_ENABLE\n"); goto err_exit0; } #endif spi->bits_per_word = 8; spi->mode = SPI_MODE_0; spi->max_speed_hz = P61_SPI_CLOCK; //spi->chip_select = SPI_NO_CS; ret = spi_setup(spi); if (ret < 0) { P61_ERR_MSG("failed to do spi_setup()\n"); goto p61_spi_setup_failed; } p61_dev -> spi = spi; p61_dev -> p61_device.minor = MISC_DYNAMIC_MINOR; p61_dev -> p61_device.name = "p61"; p61_dev -> p61_device.fops = &p61_dev_fops; p61_dev -> p61_device.parent = &spi->dev; // p61_dev->irq_gpio = platform_data->irq_gpio; //p61_dev->rst_gpio = platform_data->rst_gpio; dev_set_drvdata(&spi->dev, p61_dev); /* init mutex and queues */ init_waitqueue_head(&p61_dev->read_wq); mutex_init(&p61_dev->read_mutex); mutex_init(&p61_dev->write_mutex); spin_lock_init(&p61_dev->ese_spi_lock); #ifdef P61_IRQ_ENABLE spin_lock_init(&p61_dev->irq_enabled_lock); #endif wake_lock_init(&p61_dev->ese_lock, WAKE_LOCK_SUSPEND, "ese_wake_lock"); ret = misc_register(&p61_dev->p61_device); if (ret < 0) { P61_ERR_MSG("misc_register failed! %d\n", ret); goto err_exit0; } #if 0 //test { struct device *dev; p61_device_class = class_create(THIS_MODULE, "ese"); if (IS_ERR(p61_device_class)) { pr_err("%s class_create() is failed:%lu\n", __func__, PTR_ERR(p61_device_class)); //status = PTR_ERR(p61_device_class); //goto vfsspi_probe_class_create_failed; } dev = device_create(p61_device_class, NULL, 0, p61_dev, "p61"); pr_err("%s device_create() is failed:%lu\n", __func__, PTR_ERR(dev)); if ((device_create_file(dev, &dev_attr_test)) < 0) pr_err("%s device_create_file failed !!!\n", __func__); else pr_info("%s device_create_file success.\n", __func__); //ret = sysfs_create_group(&spi->dev.kobj, // &p61_attribute_group); //if (ret < 0) // pr_err("%s class_create() is failed - \n", // __func__, PTR_ERR(p61_device_class)); } #endif #ifdef P61_IRQ_ENABLE p61_dev->spi->irq = gpio_to_irq(platform_data->irq_gpio); if ( p61_dev->spi->irq < 0) { P61_ERR_MSG("gpio_to_irq request failed gpio = 0x%x\n", platform_data->irq_gpio); goto err_exit1; } /* request irq. the irq is set whenever the chip has data available * for reading. it is cleared when all data has been read. */ p61_dev->irq_enabled = true; irq_flags = IRQF_TRIGGER_RISING | IRQF_ONESHOT; ret = request_irq(p61_dev->spi->irq, p61_dev_irq_handler, irq_flags, p61_dev -> p61_device.name, p61_dev); if (ret) { P61_ERR_MSG("request_irq failed\n"); goto err_exit1; } p61_disable_irq(p61_dev); #endif p61_dev-> enable_poll_mode = 1; /* Default IRQ read mode */ P61_DBG_MSG("%s finished...\n", __FUNCTION__); return ret; //err_exit1: misc_deregister(&p61_dev->p61_device); err_exit0: mutex_destroy(&p61_dev->read_mutex); mutex_destroy(&p61_dev->write_mutex); wake_lock_destroy(&p61_dev->ese_lock); p61_spi_setup_failed: p61_parse_dt_failed: if(p61_dev != NULL) kfree(p61_dev); err_exit: P61_DBG_MSG("ERROR: Exit : %s ret %d\n", __FUNCTION__, ret); return ret; }