Exemple #1
0
static int p61_remove(struct spi_device *spi)
{
    struct p61_dev *p61_dev = p61_get_data(spi);
    P61_DBG_MSG("Entry : %s\n", __FUNCTION__);

#ifdef P61_HARD_RESET
    if (p61_regulator != NULL)
    {
        regulator_disable(p61_regulator);
        regulator_put(p61_regulator);
    }
    else
    {
        P61_ERR_MSG("ERROR %s p61_regulator not enabled \n", __FUNCTION__);
    }
#endif
    gpio_free(p61_dev->rst_gpio);


#ifdef P61_IRQ_ENABLE
    free_irq(p61_dev->spi->irq, p61_dev);
    gpio_free(p61_dev->irq_gpio);
#endif

    mutex_destroy(&p61_dev->read_mutex);
    misc_deregister(&p61_dev->p61_device);

    if(p61_dev != NULL)
        kfree(p61_dev);
    P61_DBG_MSG("Exit : %s\n", __FUNCTION__);
    return 0;
}
Exemple #2
0
static ssize_t p61_dev_write(struct file *filp, const char *buf, size_t count,
        loff_t *offset)
{

    int ret = -1;
    struct p61_dev *p61_dev;
    unsigned char tx_buffer[MAX_BUFFER_SIZE];

    P61_DBG_MSG(KERN_ALERT "p61_dev_write -Enter count %d\n", count);

    p61_dev = filp->private_data;

    mutex_lock(&p61_dev->write_mutex);
    if (count > MAX_BUFFER_SIZE)
        count = MAX_BUFFER_SIZE;

    memset(&tx_buffer[0], 0, sizeof(tx_buffer));
    if (copy_from_user(&tx_buffer[0], &buf[0], count))
    {
        P61_ERR_MSG("%s : failed to copy from user space\n", __func__);
        mutex_unlock(&p61_dev->write_mutex);
        return -EFAULT;
    }
    if(p61_through_put_t.enable_through_put_measure)
        p61_start_throughput_measurement(WRITE_THROUGH_PUT);
    /* Write data */
    ret = spi_write(p61_dev->spi, &tx_buffer[0], count);
    if (ret < 0)
    {
        ret = -EIO;
    }
    else
    {
        ret = count;
        if(p61_through_put_t.enable_through_put_measure)
            p61_stop_throughput_measurement(WRITE_THROUGH_PUT, ret);
    }

    mutex_unlock(&p61_dev->write_mutex);
    P61_DBG_MSG(KERN_ALERT "p61_dev_write ret %d- Exit \n", ret);
    return ret;
}
Exemple #3
0
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;
}
Exemple #4
0
static int p61_hw_setup(struct p61_spi_platform_data *platform_data,
       struct p61_dev *p61_dev, struct spi_device *spi)
{
    int ret = -1;

    P61_DBG_MSG("Entry : %s\n", __FUNCTION__);
#ifdef P61_IRQ_ENABLE
    ret = gpio_request(platform_data->irq_gpio, "p61 irq");
    if (ret < 0)
    {
        P61_ERR_MSG("gpio request failed gpio = 0x%x\n", platform_data->irq_gpio);
        goto fail;
    }

    ret = gpio_direction_input(platform_data->irq_gpio);
    if (ret < 0)
    {
        P61_ERR_MSG("gpio request failed gpio = 0x%x\n", platform_data->irq_gpio);
        goto fail_irq;
    }
#endif

#ifdef P61_HARD_RESET
    /* RC : platform specific settings need to be declare */
#if !DRAGON_P61
    p61_regulator = regulator_get( &spi->dev, "vaux3");
#else
    p61_regulator = regulator_get( &spi->dev, "8941_l18");
#endif
    if (IS_ERR(p61_regulator))
    {
        ret = PTR_ERR(p61_regulator);
#if !DRAGON_P61
        P61_ERR_MSG(" Error to get vaux3 (error code) = %d\n", ret);
#else
        P61_ERR_MSG(" Error to get 8941_l18 (error code) = %d\n", ret);
#endif
        return  -ENODEV;
    }
    else
    {
        P61_DBG_MSG("successfully got regulator\n");
    }

    ret = regulator_set_voltage(p61_regulator, 1800000, 1800000);
    if (ret != 0)
    {
        P61_ERR_MSG("Error setting the regulator voltage %d\n", ret);
        regulator_put(p61_regulator);
        return ret;
    }
    else
    {
        regulator_enable(p61_regulator);
        P61_DBG_MSG("successfully set regulator voltage\n");

    }
#endif
    ret = gpio_request( platform_data->rst_gpio, "p61 reset");
    if (ret < 0)
    {
        P61_ERR_MSG("gpio reset request failed = 0x%x\n", platform_data->rst_gpio);
        goto fail_gpio;
    }

    /*soft reset gpio is set to default high*/
    ret = gpio_direction_output(platform_data->rst_gpio,1);
    if (ret < 0)
    {
        P61_ERR_MSG("gpio rst request failed gpio = 0x%x\n", platform_data->rst_gpio);
        goto fail_gpio;
    }


    ret = 0;
    P61_DBG_MSG("Exit : %s\n", __FUNCTION__);
    return ret;


    fail_gpio:
    gpio_free(platform_data->rst_gpio);

#ifdef P61_IRQ_ENABLE
    fail_irq:
    gpio_free(platform_data->irq_gpio);
    fail:
    P61_ERR_MSG("p61_hw_setup failed\n");
#endif
    return ret;
}
Exemple #5
0
static ssize_t p61_dev_read(struct file *filp, char *buf, size_t count,
        loff_t *offset)
{
    int ret = -EIO;
    struct p61_dev *p61_dev = filp->private_data;
    unsigned char rx_buffer[MAX_BUFFER_SIZE];

    P61_DBG_MSG("p61_dev_read count %d - Enter \n", count);

    mutex_lock(&p61_dev->read_mutex);
    if (count > MAX_BUFFER_SIZE)
    {
        count = MAX_BUFFER_SIZE;
    }

    memset(&rx_buffer[0], 0x00, sizeof(rx_buffer));

    if (p61_dev->enable_poll_mode)
    {
        P61_DBG_MSG(" %s Poll Mode Enabled \n", __FUNCTION__);

        P61_DBG_MSG(KERN_INFO"SPI_READ returned 0x%x", count);
        ret = spi_read(p61_dev->spi, (void *)&rx_buffer[0], count);
        if (0 > ret)
        {
            P61_ERR_MSG(KERN_ALERT "spi_read failed [SOF] \n");
            goto fail;
        }
    }
    else
    {
#ifdef P61_IRQ_ENABLE
        P61_DBG_MSG(" %s Interrrupt Mode Enabled \n", __FUNCTION__);
        if (!gpio_get_value(p61_dev->irq_gpio))
        {
            if (filp->f_flags & O_NONBLOCK)
            {
                ret = -EAGAIN;
                goto fail;
            }
            while (1)
            {
                P61_DBG_MSG(" %s waiting for interrupt \n", __FUNCTION__);
                p61_dev->irq_enabled = true;
                enable_irq(p61_dev->spi->irq);
                ret = wait_event_interruptible(p61_dev->read_wq,!p61_dev->irq_enabled);
                p61_disable_irq(p61_dev);
                if (ret)
                {
                    P61_ERR_MSG("wait_event_interruptible() : Failed\n");
                    goto fail;
                }

                if (gpio_get_value(p61_dev->irq_gpio))
                    break;

                P61_ERR_MSG("%s: spurious interrupt detected\n", __func__);
            }
        }
#else
    P61_ERR_MSG(" %s P61_IRQ_ENABLE not Enabled \n", __FUNCTION__);
#endif
        ret = spi_read(p61_dev->spi, (void *)&rx_buffer[0], count);
        if (0 > ret)
        {
            P61_DBG_MSG(KERN_INFO"SPI_READ returned 0x%x", ret);
            ret = -EIO;
            goto fail;
        }
    }


    if(p61_through_put_t.enable_through_put_measure)
        p61_start_throughput_measurement(READ_THROUGH_PUT);

    if(p61_through_put_t.enable_through_put_measure)
        p61_stop_throughput_measurement (READ_THROUGH_PUT, count);
    P61_DBG_MSG(KERN_INFO"total_count = %d", count);

    if (copy_to_user(buf, &rx_buffer[0], count))
    {
        P61_ERR_MSG("%s : failed to copy to user space\n", __func__);
        ret = -EFAULT;
        goto fail;
    }
    P61_DBG_MSG("p61_dev_read ret %d Exit\n", ret);
    P61_DBG_MSG("p61_dev_read ret %d Exit\n", rx_buffer[0]);

    mutex_unlock(&p61_dev->read_mutex);

    return ret;

    fail:
    P61_ERR_MSG("Error p61_dev_read ret %d Exit\n", ret);
    mutex_unlock(&p61_dev->read_mutex);
    return ret;
}
Exemple #6
0
static long p61_dev_ioctl(struct file *filp, unsigned int cmd,
        unsigned long arg)
{
    int ret = 0;
    struct p61_dev *p61_dev = NULL;

    unsigned char buf[100];


    P61_DBG_MSG(KERN_ALERT "p61_dev_ioctl-Enter %u arg = %ld\n", cmd, arg);
    p61_dev = filp->private_data;

    switch (cmd) {
    case P61_SET_PWR:
        if (arg == 2)
        {
#ifdef P61_HARD_RESET
            P61_DBG_MSG(KERN_ALERT " Disabling p61_regulator");
            if (p61_regulator != NULL)
            {
                regulator_disable(p61_regulator);
                msleep(50);
                regulator_enable(p61_regulator);
                P61_DBG_MSG(KERN_ALERT " Enabling p61_regulator");
            }
            else
            {
                P61_ERR_MSG(KERN_ALERT " ERROR : p61_regulator is not enabled");
            }
#endif

        }
        else if (arg == 1)
        {
            P61_DBG_MSG(KERN_ALERT " Soft Reset");
            //gpio_set_value(p61_dev->rst_gpio, 1);
            //msleep(20);
            gpio_set_value(p61_dev->rst_gpio, 0);
            msleep(50);
            ret = spi_read (p61_dev -> spi,(void *) buf, sizeof(buf));
            msleep(50);
            gpio_set_value(p61_dev->rst_gpio, 1);
            msleep(20);

        }
        break;

    case P61_SET_DBG:
        debug_level = (unsigned char )arg;
        P61_DBG_MSG(KERN_INFO"[NXP-P61] -  Debug level %d", debug_level);
        break;

    case P61_SET_POLL:

        p61_dev-> enable_poll_mode = (unsigned char )arg;
        if (p61_dev-> enable_poll_mode == 0)
        {
            P61_DBG_MSG(KERN_INFO"[NXP-P61] - IRQ Mode is set \n");
        }
        else
        {
            P61_DBG_MSG(KERN_INFO"[NXP-P61] - Poll Mode is set \n");
            p61_dev->enable_poll_mode = 1;
        }
        break;
    case P61_SET_SPM_PWR:
        P61_DBG_MSG(KERN_ALERT " P61_SET_SPM_PWR: enter");
        ret = pn544_dev_ioctl(filp, P61_SET_SPI_PWR, arg);
        P61_DBG_MSG(KERN_ALERT " P61_SET_SPM_PWR: exit");
    break;
    case P61_GET_SPM_STATUS:
        P61_DBG_MSG(KERN_ALERT " P61_GET_SPM_STATUS: enter");
        ret = pn544_dev_ioctl(filp, P61_GET_PWR_STATUS, arg);
        P61_DBG_MSG(KERN_ALERT " P61_GET_SPM_STATUS: exit");
    break;
    case P61_SET_DWNLD_STATUS:
        P61_DBG_MSG(KERN_ALERT " P61_SET_DWNLD_STATUS: enter");
        ret = pn544_dev_ioctl(filp, PN544_SET_DWNLD_STATUS, arg);
        P61_DBG_MSG(KERN_ALERT " P61_SET_DWNLD_STATUS: =%d exit",arg);
    break;
    case P61_SET_THROUGHPUT:
        p61_through_put_t.enable_through_put_measure = true;
        P61_DBG_MSG(KERN_INFO"[NXP-P61] -  P61_SET_THROUGHPUT enable %d", p61_through_put_t.enable_through_put_measure);
        break;
    case P61_GET_ESE_ACCESS:
        P61_DBG_MSG(KERN_ALERT " P61_GET_ESE_ACCESS: enter");
        ret = pn544_dev_ioctl(filp, P544_GET_ESE_ACCESS, arg);
        P61_DBG_MSG(KERN_ALERT " P61_GET_ESE_ACCESS ret: %d exit",ret);
    break;
    case P61_SET_POWER_SCHEME:
        P61_DBG_MSG(KERN_ALERT " P61_SET_POWER_SCHEME: enter");
        ret = pn544_dev_ioctl(filp, P544_SET_POWER_SCHEME, arg);
        P61_DBG_MSG(KERN_ALERT " P61_SET_POWER_SCHEME ret: %d exit",ret);
    break;
    case P61_INHIBIT_PWR_CNTRL:
        P61_DBG_MSG(KERN_ALERT " P61_INHIBIT_PWR_CNTRL: enter");
        ret = pn544_dev_ioctl(filp, P544_SECURE_TIMER_SESSION, arg);
        P61_DBG_MSG(KERN_ALERT " P61_INHIBIT_PWR_CNTRL ret: %d exit", ret);
    break;
    default:
        P61_DBG_MSG(KERN_ALERT " Error case");
        ret = -EINVAL;
    }

    P61_DBG_MSG(KERN_ALERT "p61_dev_ioctl-exit %u arg = %ld\n", cmd, arg);
    return ret;
}
Exemple #7
0
static ssize_t p61_dev_read(struct file *filp, char *buf, size_t count,
                            loff_t *offset)
{
    int ret = -EIO;
    struct p61_dev *p61_dev = filp->private_data;
    unsigned char sof = 0x00;
    int total_count = 0;
    unsigned char rx_buffer[MAX_BUFFER_SIZE];

    P61_DBG_MSG("p61_dev_read count %zu - Enter \n", count);

    if (count < MAX_BUFFER_SIZE)
    {
        P61_ERR_MSG(KERN_ALERT "Invalid length (min : 258) [%zu] \n", count);
        return -EINVAL;
    }
    mutex_lock(&p61_dev->read_mutex);
    if (count > MAX_BUFFER_SIZE)
    {
        count = MAX_BUFFER_SIZE;
    }

    memset(&rx_buffer[0], 0x00, sizeof(rx_buffer));

    if (p61_dev->enable_poll_mode)
    {
        P61_DBG_MSG(" %s Poll Mode Enabled \n", __FUNCTION__);
        do
        {
            sof = 0x00;
            P61_DBG_MSG(KERN_INFO"SPI_READ returned 0x%x", sof);
            ret = spi_read(p61_dev->spi, (void *)&sof, 1);
            if (0 > ret)
            {
                P61_ERR_MSG(KERN_ALERT "spi_read failed [SOF] \n");
                goto fail;
            }
            P61_DBG_MSG(KERN_INFO"SPI_READ returned 0x%x", sof);
            /* if SOF not received, give some time to P61 */
            /* RC put the conditional delay only if SOF not received */
            if (sof != SOF)
                usleep_range(5000, 5100);
        } while(sof != SOF);
    }
    else
    {
#ifdef P61_IRQ_ENABLE
        P61_DBG_MSG(" %s Interrrupt Mode Enabled \n", __FUNCTION__);
        if (!gpio_get_value(p61_dev->irq_gpio))
        {
            if (filp->f_flags & O_NONBLOCK)
            {
                ret = -EAGAIN;
                goto fail;
            }
            while (1)
            {
                P61_DBG_MSG(" %s waiting for interrupt \n", __FUNCTION__);
                p61_dev->irq_enabled = true;
                enable_irq(p61_dev->spi->irq);
                ret = wait_event_interruptible(p61_dev->read_wq,!p61_dev->irq_enabled);
                p61_disable_irq(p61_dev);
                if (ret)
                {
                    P61_ERR_MSG("wait_event_interruptible() : Failed\n");
                    goto fail;
                }

                if (gpio_get_value(p61_dev->irq_gpio))
                    break;

                P61_ERR_MSG("%s: spurious interrupt detected\n", __func__);
            }
        }
#else
        P61_ERR_MSG(" %s P61_IRQ_ENABLE not Enabled \n", __FUNCTION__);
#endif
        /* read the SOF */
        sof = 0x00;
        ret = spi_read(p61_dev->spi, (void *)&sof, 1);
        if ((0 > ret) || (sof != SOF))
        {
            P61_DBG_MSG(KERN_INFO"SPI_READ returned 0x%x", sof);
            P61_ERR_MSG(KERN_ALERT "spi_read failed [SOF] 0x%x\n", ret);
            ret = -EIO;
            goto fail;
        }
    }


    total_count = 1;
    rx_buffer[0] = sof;
    /* Read the HEADR of Two bytes*/
    ret = spi_read(p61_dev->spi, (void *)&rx_buffer[1], 2);
    if (ret < 0)
    {
        P61_ERR_MSG(KERN_ALERT "spi_read fails after [PCB] \n");
        ret = -EIO;
        goto fail;
    }

    total_count += 2;
    /* Get the data length */
    count = rx_buffer[2];
    P61_DBG_MSG(KERN_INFO"Data Lenth = %zu", count);
    /* Read the availabe data along with one byte LRC */
    ret = spi_read(p61_dev->spi, (void *)&rx_buffer[3], (count+1));
    if (ret < 0)
    {
        P61_ERR_MSG("spi_read failed \n");
        ret = -EIO;
        goto fail;
    }
    total_count = (total_count + (count+1));
    P61_DBG_MSG(KERN_INFO"total_count = %d", total_count);

    if (copy_to_user(buf, &rx_buffer[0], total_count))
    {
        P61_ERR_MSG("%s : failed to copy to user space\n", __func__);
        ret = -EFAULT;
        goto fail;
    }
    ret = total_count;
    P61_DBG_MSG("p61_dev_read ret %d Exit\n", ret);

    mutex_unlock(&p61_dev->read_mutex);

    return ret;

fail:
    P61_ERR_MSG("Error p61_dev_read ret %d Exit\n", ret);
    mutex_unlock(&p61_dev->read_mutex);
    return ret;
}
Exemple #8
0
static long p61_dev_ioctl(struct file *filp, unsigned int cmd,
                          unsigned long arg)
{
    int ret = 0;
    struct p61_dev *p61_dev = NULL;
#ifdef P61_RST_ENABLE
    unsigned char buf[100];
#endif

    if (_IOC_TYPE(cmd) != P61_MAGIC) {
        pr_err("%s invalid magic. cmd=0x%X Received=0x%X Expected=0x%X\n",
               __func__, cmd, _IOC_TYPE(cmd), P61_MAGIC);
        return -ENOTTY;
    }
    P61_DBG_MSG(KERN_ALERT "p61_dev_ioctl-Enter %u arg = %ld\n", cmd, arg);
    p61_dev = filp->private_data;

    switch (cmd) {
    case P61_SET_PWR:
        if (arg == 2)
        {
#ifdef P61_HARD_RESET
            P61_DBG_MSG(KERN_ALERT " Disabling p61_regulator");
            if (p61_regulator != NULL)
            {
                regulator_disable(p61_regulator);
                msleep(50);
                regulator_enable(p61_regulator);
                P61_DBG_MSG(KERN_ALERT " Enabling p61_regulator");
            }
            else
            {
                P61_ERR_MSG(KERN_ALERT " ERROR : p61_regulator is not enabled");
            }
#endif
        }
#ifdef P61_RST_ENABLE
        else if (arg == 1)
        {
            P61_DBG_MSG(KERN_ALERT " Soft Reset");
            //gpio_set_value(p61_dev->rst_gpio, 1);
            //msleep(20);
            gpio_set_value(p61_dev->rst_gpio, 0);
            msleep(50);
            ret = spi_read (p61_dev -> spi,(void *) buf, sizeof(buf));
            msleep(50);
            gpio_set_value(p61_dev->rst_gpio, 1);
            msleep(20);
        }
#endif
        break;

    case P61_SET_DBG:
        debug_level = (unsigned char )arg;
        P61_DBG_MSG(KERN_INFO"[NXP-P61] -  Debug level %d", debug_level);
        break;
    case P61_SET_POLL:
        p61_dev-> enable_poll_mode = (unsigned char )arg;
        if (p61_dev-> enable_poll_mode == 0)
        {
            P61_DBG_MSG(KERN_INFO"[NXP-P61] - IRQ Mode is set \n");
        }
        else
        {
            P61_DBG_MSG(KERN_INFO"[NXP-P61] - Poll Mode is set \n");
            p61_dev->enable_poll_mode = 1;
        }
        break;
    /*non TZ */
    case P61_SET_SPI_CONFIG:
        p61_ioctl_config_spi_gpio(p61_dev);
        break;
    case P61_ENABLE_SPI_CLK:
        pr_info("%s P61_ENABLE_SPI_CLK\n", __func__);
        ret = p61_set_clk(p61_dev);
        break;
    case P61_DISABLE_SPI_CLK:
        pr_info("%s P61_DISABLE_SPI_CLK\n", __func__);
        ret = p61_disable_clk(p61_dev);
        break;

    case P61_RW_SPI_DATA:
        ret = p61_rw_spi_message(p61_dev, arg);
        break;

    default:
        pr_info("%s no matching ioctl!\n", __func__);
        ret = -EINVAL;
    }

    return ret;
}
Exemple #9
0
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;
}