software/drivers/sd8887/src/wlan/mlinux/moal_priv.c
/**
 *  @brief Cmd52 read/write register
 *
 *  @param priv         A pointer to moal_private structure
 *  @param wrq          A pointer to iwreq structure
 *  @return             MLAN_STATUS_SUCCESS --success, otherwise fail
 */
@brief Cmd52 read/write register
@param priv         A pointer to moal_private structure
@param wrq          A pointer to iwreq structure
@return             MLAN_STATUS_SUCCESS --success, otherwise fail
@brief Cmd52 read / write register @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure @return MLAN_STATUS_SUCCESS -- success otherwise fail
static int
woal_cmd52rdwr_ioctl(moal_private *priv, struct iwreq *wrq)
{
	t_u8 rw = 0, func, data = 0;
	int buf[3], reg, ret = MLAN_STATUS_SUCCESS;
	int data_length = wrq->u.data.length;
	ENTER();
	if (data_length < 2 || data_length > 3) {
		PRINTM(MERROR, "Invalid number of arguments\n");
		ret = -EINVAL;
		goto done;
	}
	if (copy_from_user(buf, wrq->u.data.pointer, sizeof(int) * data_length)) {
		PRINTM(MERROR, "Copy from user failed\n");
		ret = -EFAULT;
		goto done;
	}
	func = (t_u8)buf[0];
	if (func > 7) {
		PRINTM(MERROR, "Invalid function number!\n");
		ret = -EINVAL;
		goto done;
	}
	reg = (t_u32)buf[1];
	if (data_length == 2) {
		rw = 0;		
		PRINTM(MINFO, "Cmd52 read, func=%d, reg=0x%08X\n", func, reg);
	}
	if (data_length == 3) {
		rw = 1;		
		data = (t_u8)buf[2];
		PRINTM(MINFO, "Cmd52 write, func=%d, reg=0x%08X, data=0x%02X\n",
		       func, reg, data);
	}
	if (!rw) {
		sdio_claim_host(((struct sdio_mmc_card *)priv->phandle->card)->
				func);
		if (func)
			data = sdio_readb(((struct sdio_mmc_card *)priv->
					   phandle->card)->func, reg, &ret);
		else
			data = sdio_f0_readb(((struct sdio_mmc_card *)priv->
					      phandle->card)->func, reg, &ret);
		sdio_release_host(((struct sdio_mmc_card *)priv->phandle->
				   card)->func);
		if (ret) {
			PRINTM(MERROR,
			       "sdio_readb: reading register 0x%X failed\n",
			       reg);
			goto done;
		}
	} else {
		sdio_claim_host(((struct sdio_mmc_card *)priv->phandle->card)->
				func);
		if (func)
			sdio_writeb(((struct sdio_mmc_card *)priv->phandle->
				     card)->func, data, reg, &ret);
		else
			sdio_f0_writeb(((struct sdio_mmc_card *)priv->phandle->
					card)->func, data, reg, &ret);
		sdio_release_host(((struct sdio_mmc_card *)priv->phandle->
				   card)->func);
		if (ret) {
			PRINTM(MERROR,
			       "sdio_writeb: writing register 0x%X failed\n",
			       reg);
			goto done;
		}
	}
	buf[0] = data;
	wrq->u.data.length = 1;
	if (copy_to_user(wrq->u.data.pointer, buf, sizeof(int))) {
		PRINTM(MERROR, "Copy to user failed\n");
		ret = -EFAULT;
		goto done;
	}
done:
	LEAVE();
	return ret;
}
static int woal_cmd52rdwr_ioctl ( moal_private * priv , struct iwreq * wrq ) { t_u8 rw = 0 , func , data = 0 ; int buf [ 3 ] , reg , ret = MLAN_STATUS_SUCCESS ; int data_length = wrq -> u . data . length ; ENTER ( ) ; if ( data_length < 2 || data_length > 3 ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } if ( copy_from_user ( buf , wrq -> u . data . pointer , sizeof ( int ) * data_length ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } func = ( t_u8 ) buf [ 0 ] ; if ( func > 7 ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } reg = ( t_u32 ) buf [ 1 ] ; if ( data_length == 2 ) { rw = 0 ; PRINTM ( MINFO , " \n " , func , reg ) ; } if ( data_length == 3 ) { rw = 1 ; data = ( t_u8 ) buf [ 2 ] ; PRINTM ( MINFO , " \n " , func , reg , data ) ; } if ( ! rw ) { sdio_claim_host ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func ) ; if ( func ) data = sdio_readb ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func , reg , & ret ) ; else data = sdio_f0_readb ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func , reg , & ret ) ; sdio_release_host ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func ) ; if ( ret ) { PRINTM ( MERROR , " \n " , reg ) ; goto done ; } } else { sdio_claim_host ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func ) ; if ( func ) sdio_writeb ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func , data , reg , & ret ) ; else sdio_f0_writeb ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func , data , reg , & ret ) ; sdio_release_host ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func ) ; if ( ret ) { PRINTM ( MERROR , " \n " , reg ) ; goto done ; } } buf [ 0 ] = data ; wrq -> u . data . length = 1 ; if ( copy_to_user ( wrq -> u . data . pointer , buf , sizeof ( int ) ) ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } done : LEAVE ( ) ; return ret ; }
@brief Cmd52 read/write register
  @param priv         A pointer to moal_private structure
  @param wrq          A pointer to iwreq structure
  @return             MLAN_STATUS_SUCCESS --success, otherwise fail
@brief Cmd52 read / write register @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure @return MLAN_STATUS_SUCCESS -- success otherwise fail
/* CMD52 read */ /* CMD52 write */