Exemple #1
0
static int Si4709_ioctl(struct inode *inode, struct file *filp, 
				unsigned int ioctl_cmd,  unsigned long arg)
{
	int ret = 0;
	void __user *argp = (void __user *)arg;   

	if( _IOC_TYPE(ioctl_cmd) != Si4709_IOC_MAGIC )
	{
		debug("Inappropriate ioctl 1 0x%x",ioctl_cmd);
		return -ENOTTY;
	}

	if( _IOC_NR(ioctl_cmd) > Si4709_IOC_NR_MAX )
	{
		debug("Inappropriate ioctl 2 0x%x",ioctl_cmd);	
		return -ENOTTY;
	}

	switch (ioctl_cmd)
	{
		case Si4709_IOC_POWERUP:
			error("Si4709_IOC_POWERUP called");      
	
			if( (ret = Si4709_dev_powerup()) < 0 )
				error("Si4709_IOC_POWERUP failed");
			break;

		case Si4709_IOC_POWERDOWN:
			error("Si4709_IOC_POWERDOWN called");      

			if( (ret = Si4709_dev_powerdown()) < 0 )
				error("Si4709_IOC_POWERDOWN failed");
			break;

		case Si4709_IOC_BAND_SET:
			{
				int band;
				error("Si4709_IOC_BAND_SET called");      

				if(copy_from_user((void*) &band, argp, sizeof(int)))
					ret = -EFAULT;
				else if( (ret = Si4709_dev_band_set(band)) < 0)
					error("Si4709_IOC_BAND_SET failed");

			}
			break;

		case Si4709_IOC_CHAN_SPACING_SET:
			{
				int ch_spacing;
				error("Si4709_IOC_CHAN_SPACING_SET called");      

				if( copy_from_user((void*) &ch_spacing, argp, sizeof(int)) )
					ret = -EFAULT;
				else if ((ret = Si4709_dev_ch_spacing_set(ch_spacing)) < 0)
					error("Si4709_IOC_CHAN_SPACING_SET failed");

			}
			break;

		case Si4709_IOC_CHAN_SELECT:
			{
				u32 frequency;
				error("Si4709_IOC_CHAN_SELECT called");      

				if( copy_from_user((void*) &frequency, argp, sizeof(u32)) )
					ret = -EFAULT;
				else if ( (ret = Si4709_dev_chan_select(frequency)) < 0 )
					error("Si4709_IOC_CHAN_SELECT failed");
			}
			break;            

		case Si4709_IOC_CHAN_GET:
			{
				u32 frequency;
				error("Si4709_IOC_CHAN_GET called");      

				if( (ret = Si4709_dev_chan_get(&frequency)) < 0)
					error("Si4709_IOC_CHAN_GET failed");
				else if( copy_to_user(argp, (void*) &frequency, sizeof(u32)))
					ret = -EFAULT;
			}
			break;

		case Si4709_IOC_SEEK_UP:
			{
				u32 frequency;
				error("Si4709_IOC_SEEK_UP called");

				if( (ret = Si4709_dev_seek_up(&frequency)) < 0)
					error("Si4709_IOC_SEEK_UP failed");
				else if( copy_to_user(argp, (void*) &frequency, sizeof(u32)) )
					ret = -EFAULT;
			} 
			break;

		case Si4709_IOC_SEEK_DOWN:
			{
				u32 frequency;
				error("Si4709_IOC_SEEK_DOWN called");

				if( (ret = Si4709_dev_seek_down(&frequency)) < 0)
					error("Si4709_IOC_SEEK_DOWN failed");
				else if( copy_to_user(argp, (void*) &frequency, sizeof(u32)) )
					ret = -EFAULT;
			}   
			break;

#if 0
        case Si4709_IOC_SEEK_AUTO:
        		  {
        		  	    u32 *seek_preset_user;
        		  	    int i = 0;
						
						debug("Si4709_IOC_SEEK_AUTO called");     
							
                 if( (seek_preset_user = (u32 *)kzalloc(sizeof(u32) * NUM_SEEK_PRESETS, 
                 	             GFP_KERNEL)) == NULL )
                 {
                     debug("Si4709_ioctl: no memory");
                     ret = -ENOMEM;
                 }            		   
                 else
                 {
                     if((ret = Si4709_dev_seek_auto(seek_preset_user)) < 0)
                     {
                         debug("Si4709_IOC_SEEK_AUTO failed");
                     }

                     else if ( copy_to_user(argp, (u32*) seek_preset_user, sizeof(int) * NUM_SEEK_PRESETS) )
                     {
                         ret = -EFAULT;
                     }
                     
                     kfree(seek_preset_user);
                 }
        	   }
            break;
#endif

		case Si4709_IOC_RSSI_SEEK_TH_SET:
			{
				u8 RSSI_seek_th;
				error("Si4709_IOC_RSSI_SEEK_TH_SET called");

				if( copy_from_user((void*) &RSSI_seek_th, argp, sizeof(u8)) )
					ret = -EFAULT;
				else if ( (ret = Si4709_dev_RSSI_seek_th_set(RSSI_seek_th)) < 0 )
					error("Si4709_IOC_RSSI_SEEK_TH_SET failed");
			}
			break;

		case Si4709_IOC_SEEK_SNR_SET:
			{
				u8 seek_SNR_th;
				error("Si4709_IOC_SEEK_SNR_SET called");

				if( copy_from_user((void*) &seek_SNR_th, argp, sizeof(u8)) )
					ret = -EFAULT;
				else if( (ret = Si4709_dev_seek_SNR_th_set(seek_SNR_th)) < 0 )
					error("Si4709_IOC_SEEK_SNR_SET failed");
			}
			break;

		case Si4709_IOC_SEEK_CNT_SET:
			{
				u8 seek_FM_ID_th;
				error("Si4709_IOC_SEEK_CNT_SET called");

				if( copy_from_user((void*) &seek_FM_ID_th, argp, sizeof(u8)) )
					ret = -EFAULT;
				else if ( (ret = Si4709_dev_seek_FM_ID_th_set(seek_FM_ID_th)) < 0 )
					error("Si4709_IOC_SEEK_CNT_SET failed");
			}  
			break;

		case Si4709_IOC_CUR_RSSI_GET:
			{
				rssi_snr_t  data;
				error("Si4709_IOC_CUR_RSSI_GET called");
             
				if( (ret = Si4709_dev_cur_RSSI_get(&data)) < 0)
					error("Si4709_IOC_CUR_RSSI_GET failed");
				else if( copy_to_user(argp, (void*) &data, sizeof(rssi_snr_t )) )
					ret = -EFAULT;
				
				error("curr_rssi:%d\ncurr_rssi_th:%d\ncurr_snr:%d\n",data.curr_rssi,data.curr_rssi_th,data.curr_snr);
			}
			break;

		case Si4709_IOC_VOLEXT_ENB:
			error("Si4709_IOC_VOLEXT_ENB called");      

			if( (ret = Si4709_dev_VOLEXT_ENB()) < 0 )
				error("Si4709_IOC_VOLEXT_ENB failed");
			break;

		case Si4709_IOC_VOLEXT_DISB:
			error("Si4709_IOC_VOLEXT_DISB called");      

			if( (ret = Si4709_dev_VOLEXT_DISB()) < 0 )
				error("Si4709_IOC_VOLEXT_DISB failed");
			break;

		case Si4709_IOC_VOLUME_SET:
			{
				u8 volume;
				error("Si4709_IOC_VOLUME_SET called");

				if( copy_from_user((void*) &volume, argp, sizeof(u8)) )
					ret = -EFAULT;
				else if ( (ret = Si4709_dev_volume_set(volume)) < 0 )
					error("Si4709_IOC_VOLUME_SET failed");
			}  
			break;

		case Si4709_IOC_VOLUME_GET:
			{
				u8 volume;
				error("Si4709_IOC_VOLUME_GET called");

				if( (ret = Si4709_dev_volume_get(&volume)) < 0)
					error("Si4709_IOC_VOLUME_GET failed");
				else if( copy_to_user(argp, (void*) &volume, sizeof(u8)) )
					ret = -EFAULT;
			}  
			break;

		case Si4709_IOC_DSMUTE_ON:
			error("Si4709_IOC_DSMUTE_ON called");      

			if( (ret = Si4709_dev_DSMUTE_ON()) < 0 )
				error("Si4709_IOC_DSMUTE_ON failed");
			break;

		case Si4709_IOC_DSMUTE_OFF:
			error("Si4709_IOC_DSMUTE_OFF called");      

			if( (ret = Si4709_dev_DSMUTE_OFF()) < 0 )
				error("Si4709_IOC_DSMUTE_OFF failed");
			break;

		case Si4709_IOC_MUTE_ON:
			error("Si4709_IOC_MUTE_ON called");      

			if( (ret = Si4709_dev_MUTE_ON()) < 0 )
				error("Si4709_IOC_MUTE_ON failed");
			break;

		case Si4709_IOC_MUTE_OFF:
			error("Si4709_IOC_MUTE_OFF called");      

			if( (ret = Si4709_dev_MUTE_OFF()) < 0 )
				error("Si4709_IOC_MUTE_OFF failed");
			break;

		case Si4709_IOC_MONO_SET:
			error("Si4709_IOC_MONO_SET called");      

			if( (ret = Si4709_dev_MONO_SET()) < 0 )
				error("Si4709_IOC_MONO_SET failed");
			break;

		case Si4709_IOC_STEREO_SET:
			error("Si4709_IOC_STEREO_SET called");      

			if( (ret = Si4709_dev_STEREO_SET()) < 0 )
				error("Si4709_IOC_STEREO_SET failed");
			break; 

		case Si4709_IOC_RSTATE_GET:
			{
				dev_state_t dev_state;

				error("Si4709_IOC_RSTATE_GET called");      

				if( (ret = Si4709_dev_rstate_get(&dev_state)) < 0)
					error("Si4709_IOC_RSTATE_GET failed");
				else if( copy_to_user(argp, (void*) &dev_state, sizeof(dev_state_t)) )
					ret = -EFAULT;
			}
			break;

		case Si4709_IOC_RDS_DATA_GET:
			{
				radio_data_t data;
				error("Si4709_IOC_RDS_DATA_GET called");      

				if( (ret = Si4709_dev_RDS_data_get(&data)) < 0)
					debug("Si4709_IOC_RDS_DATA_GET failed");
				else if( copy_to_user(argp, (void*) &data, sizeof(radio_data_t)) )
					ret = -EFAULT;
			}     
			break;
            
		case Si4709_IOC_RDS_ENABLE:
			error("Si4709_IOC_RDS_ENABLE called");      

			if( (ret = Si4709_dev_RDS_ENABLE()) < 0 )
				error("Si4709_IOC_RDS_ENABLE failed");   
			break; 

		case Si4709_IOC_RDS_DISABLE:
			error("Si4709_IOC_RDS_DISABLE called");      
 
			if( (ret = Si4709_dev_RDS_DISABLE()) < 0 )
				error("Si4709_IOC_RDS_DISABLE failed");		
			break; 

		case Si4709_IOC_RDS_TIMEOUT_SET:
          		{
				u32  time_out;
				error("Si4709_IOC_RDS_TIMEOUT_SET called");

				if( copy_from_user((void*) &time_out, argp, sizeof(u32)) )
					ret = -EFAULT;
				else if ( (ret = Si4709_dev_RDS_timeout_set(time_out)) < 0 )
					error("Si4709_IOC_RDS_TIMEOUT_SET failed");
			}
			break; 

		case Si4709_IOC_SEEK_CANCEL:
			error("Si4709_IOC_SEEK_CANCEL called");      

			if( Si4709_dev_wait_flag == SEEK_WAITING )
			{
				Si4709_dev_wait_flag = SEEK_CANCEL;
				wake_up_interruptible(&Si4709_waitq);
			}
			break;

		/*VNVS:START 13-OCT'09---- Switch Case statements for calling functions which reads device-id, 
								   chip-id,power configuration, system configuration2 registers */	
		case Si4709_IOC_CHIP_ID_GET:
			{
				chip_id chp_id;
				error("Si4709_IOC_CHIP_ID called");      

				if( (ret = Si4709_dev_chip_id(&chp_id)) < 0)
					error("Si4709_IOC_CHIP_ID failed");
				else if( copy_to_user(argp, (void*) &chp_id, sizeof(chip_id)) )
					ret = -EFAULT;
			}
			break;

		case Si4709_IOC_DEVICE_ID_GET:
			{
				device_id dev_id;
				error("Si4709_IOC_DEVICE_ID called");      

				if( (ret = Si4709_dev_device_id(&dev_id)) < 0)
					error("Si4709_IOC_DEVICE_ID failed");
				else if( copy_to_user(argp, (void*) &dev_id, sizeof(device_id)) )
					ret = -EFAULT;
			}
			break;                                                             

		case Si4709_IOC_SYS_CONFIG2_GET:
			{
				sys_config2 sys_conf2;
				error("Si4709_IOC_SYS_CONFIG2 called");

				if( (ret = Si4709_dev_sys_config2(&sys_conf2)) < 0)
					error("Si4709_IOC_SYS_CONFIG2 failed");
				else if( copy_to_user(argp, (void*) &sys_conf2, sizeof(sys_config2)) )
					ret = -EFAULT;
			}
			break;

		case Si4709_IOC_SYS_CONFIG3_GET:
			{
				sys_config3 sys_conf3;
				error("Si4709_IOC_SYS_CONFIG3 called");

				if( (ret = Si4709_dev_sys_config3(&sys_conf3)) < 0)
					error("Si4709_IOC_SYS_CONFIG3 failed");
				else if(copy_to_user(argp, (void*) &sys_conf3, sizeof(sys_config3)))
					ret = -EFAULT;
			}
			break;

		case Si4709_IOC_POWER_CONFIG_GET:
			{
				power_config pow_conf;
				error("Si4709_IOC_POWER_CONFIG called");      

				if( (ret = Si4709_dev_power_config(&pow_conf)) < 0)
					error("Si4709_IOC_POWER_CONFIG failed");
				else if( copy_to_user(argp, (void*) &pow_conf, sizeof(power_config)) )
					ret = -EFAULT;
			}
			break;
			/*VNVS:END*/
			/*VNVS:START 18-NOV'09*/ 
			/*Reading AFCRL Bit*/
		case Si4709_IOC_AFCRL_GET:
			{
				u8 afc;
				error("Si4709_IOC_AFCRL_GET called");

				if( (ret = Si4709_dev_AFCRL_get(&afc)) < 0)
					error("Si4709_IOC_AFCRL_GET failed");
				else if( copy_to_user(argp, (void*) &afc, sizeof(u8)) )
					ret = -EFAULT;
			}
			break;
		/*Setting DE-emphasis Time Constant. For DE=0,TC=50us(Europe,Japan,Australia) and DE=1,TC=75us(USA)*/
		case Si4709_IOC_DE_SET:
			{
				u8 de_tc;
				error("Si4709_IOC_DE_SET called");

				if( copy_from_user((void*) &de_tc, argp, sizeof(u8)) )
					ret = -EFAULT;
				else if ( (ret = Si4709_dev_DE_set(de_tc)) < 0 )
					error("Si4709_IOC_DE_SET failed");
			}
			break;

		case Si4709_IOC_STATUS_RSSI_GET:
			{
				status_rssi status;
				error("Si4709_IOC_STATUS_RSSI_GET called");

				if( (ret = Si4709_dev_status_rssi(&status)) < 0)
					error("Si4709_IOC_STATUS_RSSI_GET failed");
				else if(copy_to_user(argp, (void*) &status, sizeof(status_rssi)))
					ret = -EFAULT;
			}
			break;

		
		case Si4709_IOC_SYS_CONFIG2_SET:
			{
				sys_config2 sys_conf2;
				unsigned long n;
				error("Si4709_IOC_SYS_CONFIG2_SET called");

				n = copy_from_user((void*) &sys_conf2, argp, sizeof(sys_config2));
				
				if(n)
				{
					debug("Si4709_IOC_SYS_CONFIG2_SET() : copy_from_user() has error!!Failed to read [%d] byes!", n);
					ret = -EFAULT;
				}
				else 	if ( (ret = Si4709_dev_sys_config2_set(&sys_conf2)) < 0 )
					error("Si4709_IOC_SYS_CONFIG2_SET failed");
			}
			break;

		case Si4709_IOC_SYS_CONFIG3_SET:
			{
				sys_config3 sys_conf3;
				unsigned long n;
				
				error("Si4709_IOC_SYS_CONFIG3_SET called");

				n = copy_from_user((void*) &sys_conf3, argp, sizeof(sys_config3));

				if(n < 0)
				{
					debug("Si4709_IOC_SYS_CONFIG3_SET() : copy_from_user() has error!!Failed to read [%d] byes!", n);
					ret = -EFAULT;
				}else if ( (ret = Si4709_dev_sys_config3_set(&sys_conf3)) < 0 )
					error("Si4709_IOC_SYS_CONFIG3_SET failed");
			}
			break;
		/*Resetting the RDS Data Buffer*/
		case Si4709_IOC_RESET_RDS_DATA:
			{				
				error("Si4709_IOC_RESET_RDS_DATA called");
				
				if( (ret = Si4709_dev_reset_rds_data()) < 0)
					error("Si4709_IOC_RESET_RDS_DATA failed");
			}
			break;
		
		/*VNVS:END*/
		default:
			debug("  ioctl default");
			ret = -ENOTTY;
			break;
	}

	return ret;
}
Exemple #2
0
static int Si4709_ioctl(struct inode *inode, struct file *filp,
	unsigned int ioctl_cmd,  unsigned long arg)
{
	int ret = 0;
	void __user *argp = (void __user *)arg;

	if (_IOC_TYPE(ioctl_cmd) != Si4709_IOC_MAGIC) {
		pr_err("%s: invalid ioctl 1 0x%x\n", __func__, ioctl_cmd);
		return -ENOTTY;
	}

	if (_IOC_NR(ioctl_cmd) > Si4709_IOC_NR_MAX) {
		pr_err("%s: invalid ioctl 2 0x%x\n", __func__, ioctl_cmd);
		return -ENOTTY;
	}

	switch (ioctl_cmd) {
	case Si4709_IOC_POWERUP:
		printk("%s: IOC_POWERUP called\n", __func__);
		ret = Si4709_dev_powerup();
		if (ret < 0)
			pr_warn("%s: IOC_POWERUP failed\n", __func__);
		break;

	case Si4709_IOC_POWERDOWN:
		printk("%s: IOC_POWERDOWN called\n", __func__);
		ret = Si4709_dev_powerdown();
		if (ret < 0)
			pr_warn("%s: IOC_POWERDOWN failed\n", __func__);
		break;

	case Si4709_IOC_BAND_SET:
	{
		int band;
		printk("%s: IOC_BAND_SET called\n", __func__);

		if (copy_from_user((void *) &band, argp, sizeof(int)))
			ret = -EFAULT;
		else {
			ret = Si4709_dev_band_set(band);
			if (ret < 0)
				pr_warn("%s: IOC_BAND_SET failed\n", __func__);
		}
	}
		break;

	case Si4709_IOC_CHAN_SPACING_SET:
	{
		int ch_spacing;
		printk("%s: IOC_CHAN_SPACING_SET called\n", __func__);
		if (copy_from_user((void *) &ch_spacing, argp, sizeof(int)))
			ret = -EFAULT;
		else {
			ret =  Si4709_dev_ch_spacing_set(ch_spacing);
			if (ret < 0)
				pr_warn("%s: IOC_CHAN_SPACING_SET failed\n",
					__func__);
		}
	}
		break;

	case Si4709_IOC_CHAN_SELECT:
	{
		u32 frequency;
		printk("%s; IOC_CHAN_SELECT called\n", __func__);
		if (copy_from_user((void *) &frequency, argp, sizeof(u32)))
			ret = -EFAULT;
		else {
			ret = Si4709_dev_chan_select(frequency);
			if (ret < 0)
				pr_warn("%s: IOC_CHAN_SELECT failed\n",
					__func__);
		}
	}
		break;

	case Si4709_IOC_CHAN_GET:
	{
		u32 frequency;
		printk("%s: IOC_CHAN_GET called\n", __func__);
		ret = Si4709_dev_chan_get(&frequency);
		if (ret < 0)
			printk("%s: IOC_CHAN_GET failed\n", __func__);
		else if (copy_to_user(argp, (void *) &frequency, sizeof(u32)))
			ret = -EFAULT;
	}
		break;

	case Si4709_IOC_SEEK_UP:
	{
		u32 frequency;
		printk("%s: IOC_SEEK_UP called\n", __func__);

		ret = Si4709_dev_seek_up(&frequency);
		if (ret < 0)
			pr_warn("%s: IOC_SEEK_UP failed\n", __func__);
		else if (copy_to_user(argp, (void *) &frequency, sizeof(u32)))
			ret = -EFAULT;
	}
		break;

	case Si4709_IOC_SEEK_DOWN:
	{
		u32 frequency;
		printk("%s: IOC_SEEK_DOWN called\n", __func__);

		ret = Si4709_dev_seek_down(&frequency);
		if (ret < 0)
			pr_warn("%s: IOC_SEEK_DOWN failed\n", __func__);
		else if (copy_to_user(argp, (void *) &frequency, sizeof(u32)))
			ret = -EFAULT;
	}
		break;

	case Si4709_IOC_RSSI_SEEK_TH_SET:
	{
		u8 RSSI_seek_th;
		printk("%s: IOC_RSSI_SEEK_TH_SET called\n", __func__);

		if (copy_from_user((void *) &RSSI_seek_th, argp, sizeof(u8)))
			ret = -EFAULT;
		else {
			ret = Si4709_dev_RSSI_seek_th_set(RSSI_seek_th);
			if (ret < 0)
				pr_warn("%s: IOC_RSSI_SEEK_TH_SET failed\n",
					__func__);
		}
	}
		break;

	case Si4709_IOC_SEEK_SNR_SET:
	{
		u8 seek_SNR_th;
		printk("%s:_IOC_SEEK_SNR_SET called\n", __func__);

		if (copy_from_user((void *) &seek_SNR_th, argp, sizeof(u8)))
			ret = -EFAULT;
		else {
			ret = Si4709_dev_seek_SNR_th_set(seek_SNR_th);
			if (ret < 0)
				pr_warn("%s: IOC_SEEK_SNR_SET failed\n",
					__func__);
		}
	}
		break;

	case Si4709_IOC_SEEK_CNT_SET:
	{
		u8 seek_FM_ID_th;
		printk("%s: IOC_SEEK_CNT_SET called\n", __func__);

		if (copy_from_user((void *) &seek_FM_ID_th, argp, sizeof(u8)))
			ret = -EFAULT;
		else {
			ret = Si4709_dev_seek_FM_ID_th_set(seek_FM_ID_th);
			if (ret < 0)
				pr_warn("%s: IOC_SEEK_CNT_SET failed",
					__func__);
		}
	}
		break;

	case Si4709_IOC_CUR_RSSI_GET:
	{
		rssi_snr_t  data;
		printk("%s: IOC_CUR_RSSI_GET called\n", __func__);

		ret = Si4709_dev_cur_RSSI_get(&data);
		if (ret < 0)
			pr_warn("%s: IOC_CUR_RSSI_GET failed\n", __func__);
		else if (copy_to_user(argp, (void *) &data, sizeof(rssi_snr_t)))
			ret = -EFAULT;

		printk("curr_rssi:%d\ncurr_rssi_th:%d\ncurr_snr:%d\n",
			data.curr_rssi, data.curr_rssi_th, data.curr_snr);
	}
		break;

	case Si4709_IOC_VOLEXT_ENB:
		printk("%s: IOC_VOLEXT_ENB called\n", __func__);
		ret = Si4709_dev_VOLEXT_ENB();
		if (ret < 0)
			pr_warn("%s: IOC_VOLEXT_ENB failed\n", __func__);
		break;

	case Si4709_IOC_VOLEXT_DISB:
		printk("%s: IOC_VOLEXT_DISB called\n", __func__);
		ret = Si4709_dev_VOLEXT_DISB();
		if (ret < 0)
			pr_warn("%s: IOC_VOLEXT_DISB failed\n", __func__);
		break;

	case Si4709_IOC_VOLUME_SET:
	{
		u8 volume;
		printk("%s: IOC_VOLUME_SET called\n", __func__);

		if (copy_from_user((void *) &volume, argp, sizeof(u8)))
			ret = -EFAULT;
		else {
			ret = Si4709_dev_volume_set(volume);
			if (ret < 0)
				pr_warn("%s: IOC_VOLUME_SET failed\n",
					__func__);
		}
	}
		break;

	case Si4709_IOC_VOLUME_GET:
	{
		u8 volume;
		printk("%s: IOC_VOLUME_GET called\n", __func__);

		ret = Si4709_dev_volume_get(&volume);
		if (ret < 0)
			pr_warn("%s: IOC_VOLUME_GET failed\n", __func__);
		else if (copy_to_user(argp, (void *) &volume, sizeof(u8)))
			ret = -EFAULT;
	}
		break;

	case Si4709_IOC_DSMUTE_ON:
		printk("%s: IOC_DSMUTE_ON called\n", __func__);
		ret = Si4709_dev_DSMUTE_ON();
		if (ret < 0)
			pr_err("%s: IOC_DSMUTE_ON failed\n", __func__);
		break;

	case Si4709_IOC_DSMUTE_OFF:
		printk("%s: IOC_DSMUTE_OFF called\n", __func__);
		ret = Si4709_dev_DSMUTE_OFF();
		if (ret < 0)
			pr_err("%s: IOC_DSMUTE_OFF failed\n", __func__);
		break;

	case Si4709_IOC_MUTE_ON:
		printk("%s: IOC_MUTE_ON called\n", __func__);
		ret = Si4709_dev_MUTE_ON();
		if (ret < 0)
			pr_warn("%s: IOC_MUTE_ON failed\n", __func__);
		break;

	case Si4709_IOC_MUTE_OFF:
		printk("%s: IOC_MUTE_OFF called\n", __func__);
		ret = Si4709_dev_MUTE_OFF();
		if (ret < 0)
			pr_warn("%s: IOC_MUTE_OFF failed\n", __func__);
		break;

	case Si4709_IOC_MONO_SET:
		printk("%s: IOC_MONO_SET called\n", __func__);
		ret = Si4709_dev_MONO_SET();
		if (ret < 0)
			pr_warn("%s: IOC_MONO_SET failed\n", __func__);
		break;

	case Si4709_IOC_STEREO_SET:
		printk("%s: IOC_STEREO_SET called\n", __func__);
		ret = Si4709_dev_STEREO_SET();
		if (ret < 0)
			pr_warn("%s: IOC_STEREO_SET failed\n", __func__);
		break;

	case Si4709_IOC_RSTATE_GET:
	{
		dev_state_t dev_state;

		printk("%s: IOC_RSTATE_GET called\n", __func__);
		ret = Si4709_dev_rstate_get(&dev_state);
		if (ret < 0)
			pr_warn("%s: IOC_RSTATE_GET failed\n", __func__);
		else if (copy_to_user(argp, (void *) &dev_state,
			sizeof(dev_state_t)))
			ret = -EFAULT;
	}
		break;

	case Si4709_IOC_RDS_DATA_GET:
	{
		radio_data_t data;
		printk("%s: IOC_RDS_DATA_GET called\n", __func__);
		ret = Si4709_dev_RDS_data_get(&data);
		if (ret < 0)
			pr_warn("%s: IOC_RDS_DATA_GET failed\n", __func__);
		else if (copy_to_user(argp, (void *) &data,
			sizeof(radio_data_t)))
			ret = -EFAULT;
	}
		break;

	case Si4709_IOC_RDS_ENABLE:
		printk("%s: IOC_RDS_ENABLE called\n", __func__);

		ret = Si4709_dev_RDS_ENABLE();
		if (ret < 0)
			pr_warn("%s: IOC_RDS_ENABLE failed\n", __func__);
		break;

	case Si4709_IOC_RDS_DISABLE:
		printk("%s: IOC_RDS_DISABLE called\n", __func__);

		ret = Si4709_dev_RDS_DISABLE();
		if (ret < 0)
			pr_warn("%s :IOC_RDS_DISABLE failed\n", __func__);
		break;

	case Si4709_IOC_RDS_TIMEOUT_SET:
	{
		u32  time_out;
		printk("%s: IOC_RDS_TIMEOUT_SET called\n", __func__);

		if (copy_from_user((void *) &time_out, argp, sizeof(u32)))
			ret = -EFAULT;
		else {
			ret = Si4709_dev_RDS_timeout_set(time_out);
			if (ret < 0)
				pr_warn("%s: IOC_RDS_TIMEOUT_SET failed\n",
					__func__);
		}
	}
		break;

	case Si4709_IOC_SEEK_CANCEL:
		printk("%s: IOC_SEEK_CANCEL called\n", __func__);
		if (Si4709_dev_wait_flag == SEEK_WAITING) {
			Si4709_dev_wait_flag = SEEK_CANCEL;
			wake_up_interruptible(&Si4709_waitq);
		}
		break;

	/* Switch Case statements for calling functions which reads device-id,
	 * chip-id,power configuration, system configuration2 registers
	 */
	case Si4709_IOC_CHIP_ID_GET:
	{
		chip_id chp_id;
		printk("%s: IOC_CHIP_ID called\n", __func__);
		ret = Si4709_dev_chip_id(&chp_id);
		if (ret < 0)
			pr_warn("%s: IOC_CHIP_ID failed\n", __func__);
		else if (copy_to_user(argp, (void *) &chp_id, sizeof(chip_id)))
			ret = -EFAULT;
	}
		break;

	case Si4709_IOC_DEVICE_ID_GET:
	{
		device_id dev_id;
		printk("%s: IOC_DEVICE_ID called\n", __func__);

		ret = Si4709_dev_device_id(&dev_id);
		if (ret < 0)
			pr_warn("%s: IOC_DEVICE_ID failed\n", __func__);
		else if (copy_to_user(argp, (void *) &dev_id,
			sizeof(device_id)))
			ret = -EFAULT;
	}
		break;

	case Si4709_IOC_SYS_CONFIG2_GET:
	{
		sys_config2 sys_conf2;
		printk("%s: IOC_SYS_CONFIG2 called\n", __func__);

		ret = Si4709_dev_sys_config2(&sys_conf2);
		if (ret < 0)
			pr_warn("%s: IOC_SYS_CONFIG2 failed\n", __func__);
		else if (copy_to_user(argp, (void *) &sys_conf2,
			sizeof(sys_config2)))
			ret = -EFAULT;
	}
		break;

	case Si4709_IOC_SYS_CONFIG3_GET:
	{
		sys_config3 sys_conf3;
		printk("%s: IOC_SYS_CONFIG3 called", __func__);

		ret = Si4709_dev_sys_config3(&sys_conf3);
		if (ret < 0)
			pr_warn("%s: IOC_SYS_CONFIG3 failed\n", __func__);
		else if (copy_to_user(argp, (void *) &sys_conf3,
			sizeof(sys_config3)))
			ret = -EFAULT;
	}
		break;

	case Si4709_IOC_POWER_CONFIG_GET:
	{
		power_config pow_conf;
		printk("%s: IOC_POWER_CONFIG called", __func__);

		ret = Si4709_dev_power_config(&pow_conf);
		if (ret < 0)
			pr_warn("%s: IOC_POWER_CONFIG failed\n", __func__);
		else if (copy_to_user(argp, (void *) &pow_conf,
			sizeof(power_config)))
			ret = -EFAULT;
	}
		break;
	/* VNVS:END */
	/* VNVS:START 18-NOV'09 */
	/* Reading AFCRL Bit */
	case Si4709_IOC_AFCRL_GET:
	{
		u8 afc;
		printk("%s: IOC_AFCRL_GET called\n", __func__);

		ret = Si4709_dev_AFCRL_get(&afc);
		if (ret < 0)
			printk("%s: IOC_AFCRL_GET failed\n", __func__);
		else if (copy_to_user(argp, (void *) &afc, sizeof(u8)))
			ret = -EFAULT;
	}
		break;
	/* Setting DE-emphasis Time Constant.
	 * For DE=0,TC=50us(Europe,Japan,Australia) and DE=1,TC=75us(USA)
	 */
	case Si4709_IOC_DE_SET:
	{
		u8 de_tc;
		printk("%s: IOC_DE_SET called\n", __func__);

		if (copy_from_user((void *) &de_tc, argp, sizeof(u8)))
			ret = -EFAULT;
		else {
			ret = Si4709_dev_DE_set(de_tc);
			if (ret < 0)
				pr_warn("%s: IOC_DE_SET failed\n", __func__);
		}
	}
		break;

	case Si4709_IOC_STATUS_RSSI_GET:
	{
		status_rssi status;
		printk("%s: IOC_STATUS_RSSI_GET called\n", __func__);

		ret = Si4709_dev_status_rssi(&status);
		if (ret < 0)
			pr_warn("%s: IOC_STATUS_RSSI_GET failed\n", __func__);
		else if (copy_to_user(argp, (void *) &status,
			sizeof(status_rssi)))
			ret = -EFAULT;
	}
		break;


	case Si4709_IOC_SYS_CONFIG2_SET:
	{
		sys_config2 sys_conf2;
		unsigned long n;
		printk("%s: IOC_SYS_CONFIG2_SET called\n", __func__);

		n = copy_from_user((void *) &sys_conf2, argp,
			sizeof(sys_config2));
		if (n) {
			pr_err("%s: Failed to read [%d] byes!\n", __func__, n);
			ret = -EFAULT;
		} else {
			ret = Si4709_dev_sys_config2_set(&sys_conf2);
			if (ret < 0)
				pr_warn("%s: IOC_SYS_CONFIG2_SET failed\n",
					__func__);
		}
	}
		break;

	case Si4709_IOC_SYS_CONFIG3_SET:
	{
		sys_config3 sys_conf3;
		unsigned long n;
		printk("%s: IOC_SYS_CONFIG3_SET called", __func__);
		n = copy_from_user((void *) &sys_conf3, argp,
			sizeof(sys_config3));
		if (n < 0) {
			pr_err("%s: Failed to read [%d] byes!\n", __func__, n);
			ret = -EFAULT;
		} else {
			ret = Si4709_dev_sys_config3_set(&sys_conf3);
			if (ret < 0)
				pr_warn("%s: IOC_SYS_CONFIG3_SET failed\n",
					__func__);
		}
	}
	break;

	/*Resetting the RDS Data Buffer*/
	case Si4709_IOC_RESET_RDS_DATA:
		printk("%s: IOC_RESET_RDS_DATA called\n", __func__);
		ret = Si4709_dev_reset_rds_data();
		if (ret < 0)
			pr_warn("%s: IOC_RESET_RDS_DATA failed\n", __func__);
		break;

	default:
		pr_warn("%s: ioctl default\n", __func__);
		ret = -ENOTTY;
		break;
	}
	return ret;
}
Exemple #3
0
static int Si4709_ioctl(struct inode *inode, struct file *filp, 
	                        unsigned int ioctl_cmd,  unsigned long arg)
{
    int ret = 0;
    void __user *argp = (void __user *)arg;   
	   
    if( _IOC_TYPE(ioctl_cmd) != Si4709_IOC_MAGIC )
    {
        debug("Inappropriate ioctl 1 0x%x",ioctl_cmd);
        return -ENOTTY;
    }
    if( _IOC_NR(ioctl_cmd) > Si4709_IOC_NR_MAX )
    {
        debug("Inappropriate ioctl 2 0x%x",ioctl_cmd);	
        return -ENOTTY;
    }
	
    switch (ioctl_cmd)
    {
        case Si4709_IOC_POWERUP:
            if( (ret = Si4709_dev_powerup()) < 0 )
            {
                debug("Si4709_IOC_POWERUP failed");
            }
            break;

        case Si4709_IOC_POWERDOWN:
            if( (ret = Si4709_dev_powerdown()) < 0 )
            {
                debug("Si4709_IOC_POWERDOWN failed");
            }
            break;

        case Si4709_IOC_BAND_SET:
        	   {
        	   	   int band;
        	   	   
        	   	   if( copy_from_user((void*) &band, argp, sizeof(int)) )
        	   	   {
        	   	       ret = -EFAULT;
        	   	   }
                else if( (ret = Si4709_dev_band_set(band)) < 0)
                {
                    debug("Si4709_IOC_BAND_SET failed");
                }
        	   }
            break;
            
        case Si4709_IOC_CHAN_SPACING_SET:
        	   {
        	   	   int ch_spacing;
        	   	   
        	   	   if( copy_from_user((void*) &ch_spacing, argp, sizeof(int)) )
        	   	   {
        	   	       ret = -EFAULT;
        	   	   }
                else if ((ret = Si4709_dev_ch_spacing_set(ch_spacing)) < 0)
                {
                    debug("Si4709_IOC_CHAN_SPACING_SET failed");
                }
        	   }
            break;

        case Si4709_IOC_CHAN_SELECT:
        	   {
        	   	   u32 frequency;

        	   	   if( copy_from_user((void*) &frequency, argp, sizeof(u32)) )
        	   	   {
        	   	       ret = -EFAULT;
        	   	   }
                else if ( (ret = Si4709_dev_chan_select(frequency)) < 0 )
                {
                    debug("Si4709_IOC_CHAN_SELECT failed");
                }
        	   }
            break;            
            
        case Si4709_IOC_CHAN_GET:
         	  {
        	   	   u32 frequency;
        	   	   
                if( (ret = Si4709_dev_chan_get(&frequency)) < 0)
                {
                    debug("Si4709_IOC_CHAN_GET failed");
                }
                else if( copy_to_user(argp, (void*) &frequency, sizeof(u32)) )
                {
                    ret = -EFAULT;
                }
        	   } 
            break;

        case Si4709_IOC_SEEK_UP:
            {
                u32 frequency;
             
                if( (ret = Si4709_dev_seek_up(&frequency)) < 0)
                {
                    debug("Si4709_IOC_SEEK_UP failed");
                }
                else if( copy_to_user(argp, (void*) &frequency, sizeof(u32)) )
                {
                    ret = -EFAULT;
                }
            } 
            break;

        case Si4709_IOC_SEEK_DOWN:
            {
                u32 frequency;
             
                if( (ret = Si4709_dev_seek_down(&frequency)) < 0)
                {
                    debug("Si4709_IOC_SEEK_DOWN failed");
                }
                else if( copy_to_user(argp, (void*) &frequency, sizeof(u32)) )
                {
                    ret = -EFAULT;
                }
            }   
            break;

        case Si4709_IOC_SEEK_AUTO:
        		  {
        		  	    u32 *seek_preset_user;
        		  	    int i = 0;
			debug("Si4709_IOC_SEEK_AUTO called");
                 if( (seek_preset_user = (u32 *)kzalloc(sizeof(u32) * NUM_SEEK_PRESETS, 
                 	             GFP_KERNEL)) == NULL )
                 {
                     debug("Si4709_ioctl: no memory");
                     ret = -ENOMEM;
                 }            		   
                 else
                 {
                     if((ret = Si4709_dev_seek_auto(seek_preset_user)) < 0)
                     {
                         debug("Si4709_IOC_SEEK_AUTO failed");
                     }

                     else if ( copy_to_user(argp, (u32*) seek_preset_user, sizeof(int) * NUM_SEEK_PRESETS) )
                     {
                         ret = -EFAULT;
                     }
                     
                     kfree(seek_preset_user);
                 }
        	   }
            break;

        case Si4709_IOC_RSSI_SEEK_TH_SET:
            {
                u8 RSSI_seek_th;
         
                if( copy_from_user((void*) &RSSI_seek_th, argp, sizeof(u8)) )
                {
                    ret = -EFAULT;
                }
                else if ( (ret = Si4709_dev_RSSI_seek_th_set(RSSI_seek_th)) < 0 )
                {
                    debug("Si4709_IOC_RSSI_SEEK_TH_SET failed");
                }
            }
            break;   

        case Si4709_IOC_SEEK_SNR_SET:
            {
                u8 seek_SNR_th;
         
                if( copy_from_user((void*) &seek_SNR_th, argp, sizeof(u8)) )
                {
                    ret = -EFAULT;
                }
                else if( (ret = Si4709_dev_seek_SNR_th_set(seek_SNR_th)) < 0 )
                {
                    debug("Si4709_IOC_SEEK_SNR_SET failed");
                }
            }
            break;

        case Si4709_IOC_SEEK_CNT_SET:
            {
                u8 seek_FM_ID_th;
         
                if( copy_from_user((void*) &seek_FM_ID_th, argp, sizeof(u8)) )
                {
                    ret = -EFAULT;
                }
                else if ( (ret = Si4709_dev_seek_FM_ID_th_set(seek_FM_ID_th)) < 0 )
                {
                    debug("Si4709_IOC_SEEK_CNT_SET failed");
                }
            }  
            break;

        case Si4709_IOC_CUR_RSSI_GET:
            {
                u8  curr_rssi;
             
                if( (ret = Si4709_dev_cur_RSSI_get(&curr_rssi)) < 0)
                {
                    debug("Si4709_IOC_CUR_RSSI_GET failed");
                }
                else if( copy_to_user(argp, (void*) &curr_rssi, sizeof(u8 )) )
                {
                    ret = -EFAULT;
                }
            }     
            break;

	  case Si4709_IOC_AFCRL_GET:
            {
                u8  curr_afcrl;
             
                if( (ret = Si4709_dev_AFCRL_get(&curr_afcrl)) < 0)
                {
                    debug("Si4709_IOC_AFCRL_GET failed");
                }
                else if( copy_to_user(argp, (void*) &curr_afcrl, sizeof(u8 )) )
                {
                    ret = -EFAULT;
                }
                
            }     
            break;

        case Si4709_IOC_VOLEXT_ENB:
        	   if( (ret = Si4709_dev_VOLEXT_ENB()) < 0 )
        	   {
        	       debug("Si4709_IOC_VOLEXT_ENB failed");
        	   }  
            break;

        case Si4709_IOC_VOLEXT_DISB:
        	   if( (ret = Si4709_dev_VOLEXT_DISB()) < 0 )
        	   {
        	       debug("Si4709_IOC_VOLEXT_DISB failed");
        	   }
            break;

        case Si4709_IOC_VOLUME_SET:
            {
                u8 volume;
         
                if( copy_from_user((void*) &volume, argp, sizeof(u8)) )
                {
                    ret = -EFAULT;
                }
                else if ( (ret = Si4709_dev_volume_set(volume)) < 0 )
                {
                    debug("Si4709_IOC_VOLUME_SET failed");
                }
            }  
            break;

        case Si4709_IOC_VOLUME_GET:
            {
                u8 volume;
             
                if( (ret = Si4709_dev_volume_get(&volume)) < 0)
                {
                    debug("Si4709_IOC_VOLUME_GET failed");
                }
                else if( copy_to_user(argp, (void*) &volume, sizeof(u8)) )
                {
                    ret = -EFAULT;
                }
            }  
            break;

        case Si4709_IOC_MUTE_ON:
        	   if( (ret = Si4709_dev_MUTE_ON()) < 0 )
        	   {
        	       debug("Si4709_IOC_MUTE_ON failed");
        	   }  
            break;

        case Si4709_IOC_MUTE_OFF:
        	   if( (ret = Si4709_dev_MUTE_OFF()) < 0 )
        	   {
        	       debug("Si4709_IOC_MUTE_OFF failed");
        	   }    
            break;

        case Si4709_IOC_MONO_SET:
        	   if( (ret = Si4709_dev_MONO_SET()) < 0 )
        	   {
        	       debug("Si4709_IOC_MONO_SET failed");
        	   }   
            break;

        case Si4709_IOC_STEREO_SET:
        	   if( (ret = Si4709_dev_STEREO_SET()) < 0 )
        	   {
        	       debug("Si4709_IOC_STEREO_SET failed");
        	   }   
            break; 

        case Si4709_IOC_RSTATE_GET:
            {
                dev_state_t dev_state;
             
                if( (ret = Si4709_dev_rstate_get(&dev_state)) < 0)
                {
                    debug("Si4709_IOC_RSTATE_GET failed");
                }
                else if( copy_to_user(argp, (void*) &dev_state, sizeof(dev_state_t)) )
                {
                    ret = -EFAULT;
                }
            }    
            break;

        case Si4709_IOC_RDS_DATA_GET:
            {
                radio_data_t data;
             
                if( (ret = Si4709_dev_RDS_data_get(&data)) < 0)
                {
                    debug("Si4709_IOC_RDS_DATA_GET failed");
                }
                else if( copy_to_user(argp, (void*) &data, sizeof(radio_data_t)) )
                {
                    ret = -EFAULT;
                }
            }     
            break;
            
        case Si4709_IOC_RDS_ENABLE:
         	 if( (ret = Si4709_dev_RDS_ENABLE()) < 0 )
        	   {
        	       debug("Si4709_IOC_STEREO_SET failed");
        	   }   
            break; 

         case Si4709_IOC_RDS_DISABLE:
         	 if( (ret = Si4709_dev_RDS_DISABLE()) < 0 )
        	   {
        	       debug("Si4709_IOC_STEREO_SET failed");
        	   }   
            break; 

          case Si4709_IOC_RDS_TIMEOUT_SET:
          		{
          			   u32  time_out;
          			   debug("Switch case:Si4709_IOC_RDS_TIMEOUT_SET called");
          			   if( copy_from_user((void*) &time_out, argp, sizeof(u32)) )
                {
                    ret = -EFAULT;
                }
                else if ( (ret = Si4709_dev_RDS_timeout_set(time_out)) < 0 )
                {
                    debug("Si4709_IOC_RDS_TIMEOUT_SET failed");
                }
          	 }    
            break; 
           
        case Si4709_IOC_SEEK_CANCEL:
				if( Si4709_dev_wait_flag == SEEK_WAITING )
				{
					Si4709_dev_wait_flag = SEEK_CANCEL;
					wake_up_interruptible(&Si4709_waitq);
				}
            break;

	  case Si4709_IOC_SEEK_SNR_GET:
	  	{
			u8 snr_th;
			if( (ret = Si4709_dev_seek_snr_th_get(&snr_th)) < 0)
                	{
                    		debug("Si4709_IOC_SEEK_SNR_GET failed");
                	}
                	else if( copy_to_user(argp, (void*) &snr_th, sizeof(u8)) )
                	{
                    		ret = -EFAULT;
                	}
			
	  	}
	  break;

	  case Si4709_IOC_SEEK_CNT_GET :
	  	{
			u8 cnt_th;
			if( (ret = Si4709_dev_seek_cnt_th_get(&cnt_th)) < 0)
                	{
                    		debug("Si4709_IOC_SEEK_CNT_GET failed");
                	}
                	else if( copy_to_user(argp, (void*) &cnt_th, sizeof(u8)) )
                	{
                    		ret = -EFAULT;
                	}
			
	  	}
	  break;

	  case Si4709_IOC_RSSI_SEEK_TH_GET:
	  	{
			u8 rssi_th;
			if( (ret = Si4709_dev_rssi_seek_th_get(&rssi_th)) < 0)
                	{
                    		debug("Si4709_IOC_RSSI_SEEK_TH_GET failed");
                	}
                	else if( copy_to_user(argp, (void*) &rssi_th, sizeof(u8)) )
                	{
                    		ret = -EFAULT;
                	}			 			
	  	}
	  break;

	  case Si4709_IOC_CUR_SNR_GET:
		  {
			  u8  curr_snr;
		   
			  if( (ret = Si4709_dev_cur_SNR_get(&curr_snr)) < 0)
			  {
				  debug("Si4709_IOC_CUR_SNR_GET failed");
			  }
			  else if( copy_to_user(argp, (void*) &curr_snr, sizeof(u8)) )
			  {
				  ret = -EFAULT;
			  }
		  } 	
		  break;

        default:
            debug("  ioctl default");
            ret = -ENOTTY;
            break;
    }

    return ret;
}