Beispiel #1
0
static void Po188_resume(struct early_suspend *h)
{
    int ret = 0;
    if( po188_driver.status_on )
    {
        ret = regulator_enable(gPo188Regulator);
        if (ret < 0) {
            PO188_ERRMSG("enable po188 vcc drive error");
            return;
        }

        ret = k3_adc_open_channel(PO188_ADC_CHANNEL);
        if (ret < 0)
        {
            PO188_ERRMSG("k3_adc_open_channel error\n");
            regulator_disable(gPo188Regulator);
            return;
        }
        mod_timer(&po188_driver.timer, jiffies + msecs_to_jiffies(po188_driver.delay_time));
    }
}
/* getting the major version by channel number */
static int  hw_major_version_get(int channel_no)
{
    unsigned char reserve = 0;
    int value = 0;    
    int ret = 0;

    /* open adc channel */
    ret = k3_adc_open_channel(channel_no);
    if (ret < 0)
    {
        printk(KERN_ERR "%s:open adc channel failed(ret=%d channel_no=%d)\n", __func__, ret, channel_no);
	 return ret;
    }
    /* get the volatge value by adc channel */
    value = k3_adc_get_value(channel_no, &reserve);
    /* close the adc channel */
    ret = k3_adc_close_channal(channel_no);
    if (ret < 0)
    {
        printk(KERN_ERR "%s:close adc channel failed(ret=%d channel_no=%d)\n", __func__, ret, channel_no);
	 return ret;
    }
    return value;
}
Beispiel #3
0
static long po188_ioctl(struct file* file, unsigned int cmd, unsigned long param)
{
    int ret = 0;
    int flags = 0;
    void __user *argp = (void __user *)param;
    int iDelayTime = 0;

    switch (cmd)
    {
        case LIGHTSENSOR_IOCTL_ENABLE:              
            if (copy_from_user(&flags, argp, sizeof(flags))) 
            {
                ret = -EFAULT;
            }
            else
            {
                if ( 0==flags )
                {    
                    PO188_DMSG("active disable pol88\n");

                    spin_lock(&po188_driver.s_lock);
                    po188_driver.status_on = false;
                    spin_unlock(&po188_driver.s_lock);
                    cancel_work_sync(&po188_cb_work);
                    flush_workqueue(po188_driver.po188_wq);
                    del_timer(&po188_driver.timer);

                    ret = k3_adc_close_channal(PO188_ADC_CHANNEL);
                    if (ret < 0)
                    {
                        PO188_ERRMSG("k3_adc_close_channal error\n");
                    }

                    ret = regulator_disable(gPo188Regulator);
                    if (ret < 0) {
                        PO188_ERRMSG("disable po188 vcc drive error"); 
                    }
                }
                else if (1 == flags)
                {
                    PO188_DMSG("active enable pol88\n");
                    ret = regulator_enable(gPo188Regulator);
                    if (ret < 0) {
                        PO188_ERRMSG("enable po188 vcc drive error");            
                        return ret;//regulator_enable error, return.
                    }

                    ret = k3_adc_open_channel(PO188_ADC_CHANNEL);
                    if (ret < 0)
                    {
                        PO188_ERRMSG("k3_adc_open_channel error\n");
                        regulator_disable(gPo188Regulator);
                        return ret;
                    } 

                    mod_timer(&po188_driver.timer, jiffies + msecs_to_jiffies(po188_driver.delay_time));
                    spin_lock(&po188_driver.s_lock);
                    po188_driver.status_on = true;
                    spin_unlock(&po188_driver.s_lock);
                }
            }
            break;

        case LIGHTSENSOR_IOCTL_GET_ENABLED:            
            spin_lock(&po188_driver.s_lock);
            flags = po188_driver.status_on;
            spin_unlock(&po188_driver.s_lock);
            if (copy_to_user(argp, &flags, sizeof(flags))) 
            {
                ret = -EFAULT;
            }
            break;

        case LIGHTSENSOR_IOCTL_GET_DELAY:
            spin_lock(&po188_driver.s_lock);
            iDelayTime = po188_driver.delay_time;
            spin_unlock(&po188_driver.s_lock);
            if (copy_to_user(argp, &iDelayTime, sizeof(iDelayTime))) 
            {
                ret = -EFAULT;
            }     

            break;

        case LIGHTSENSOR_IOCTL_SET_DELAY:

            if (copy_from_user(&iDelayTime, argp, sizeof(iDelayTime))) 
            {
                ret =  -EFAULT;
            }
            else
            {
                spin_lock(&po188_driver.s_lock);
                po188_driver.delay_time = iDelayTime;
                spin_unlock(&po188_driver.s_lock);
            }
            break;
        default:
            PO188_ERRMSG("CMD INVALID.\n");
            ret = -EINVAL;
            break;
    }

    return ret;
}