static int safe_prepare_write_buffer(struct usb_serial_port *port,
						void *dest, size_t size)
{
	unsigned char *buf = dest;
	int count;
	int trailer_len;
	int pkt_len;
	__u16 fcs;

	trailer_len = safe ? 2 : 0;

	count = kfifo_out_locked(&port->write_fifo, buf, size - trailer_len,
								&port->lock);
	if (!safe)
		return count;

	/* pad if necessary */
	if (padded) {
		pkt_len = size;
		memset(buf + count, '0', pkt_len - count - trailer_len);
	} else {
		pkt_len = count + trailer_len;
	}

	/* set count */
	buf[pkt_len - 2] = count << 2;
	buf[pkt_len - 1] = 0;

	/* compute fcs and insert into trailer */
	fcs = fcs_compute10(buf, pkt_len, CRC10_INITFCS);
	buf[pkt_len - 2] |= fcs >> 8;
	buf[pkt_len - 1] |= fcs & 0xff;

	return pkt_len;
}
/* Receiver */
static int cx25840_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
			      ssize_t *num)
{
	struct cx25840_ir_state *ir_state = to_ir_state(sd);
	bool invert;
	u16 divider;
	unsigned int i, n;
	union cx25840_ir_fifo_rec *p;
	unsigned u, v, w;

	if (ir_state == NULL)
		return -ENODEV;

	invert = (bool) atomic_read(&ir_state->rx_invert);
	divider = (u16) atomic_read(&ir_state->rxclk_divider);

	n = count / sizeof(union cx25840_ir_fifo_rec)
		* sizeof(union cx25840_ir_fifo_rec);
	if (n == 0) {
		*num = 0;
		return 0;
	}

	n = kfifo_out_locked(&ir_state->rx_kfifo, buf, n,
			     &ir_state->rx_kfifo_lock);

	n /= sizeof(union cx25840_ir_fifo_rec);
	*num = n * sizeof(union cx25840_ir_fifo_rec);

	for (p = (union cx25840_ir_fifo_rec *) buf, i = 0; i < n; p++, i++) {

		if ((p->hw_fifo_data & FIFO_RXTX_RTO) == FIFO_RXTX_RTO) {
			/* Assume RTO was because of no IR light input */
			u = 0;
			w = 1;
		} else {
			u = (p->hw_fifo_data & FIFO_RXTX_LVL) ? 1 : 0;
			if (invert)
				u = u ? 0 : 1;
			w = 0;
		}

		v = (unsigned) pulse_width_count_to_ns(
				  (u16) (p->hw_fifo_data & FIFO_RXTX), divider);
		if (v > IR_MAX_DURATION)
			v = IR_MAX_DURATION;

		init_ir_raw_event(&p->ir_core_data);
		p->ir_core_data.pulse = u;
		p->ir_core_data.duration = v;
		p->ir_core_data.timeout = w;

		v4l2_dbg(2, ir_debug, sd, "rx read: %10u ns  %s  %s\n",
			 v, u ? "mark" : "space", w ? "(timed out)" : "");
		if (w)
			v4l2_dbg(2, ir_debug, sd, "rx read: end of rx\n");
	}
	return 0;
}
static int klsi_105_prepare_write_buffer(struct usb_serial_port *port,
						void *dest, size_t size)
{
	unsigned char *buf = dest;
	int count;

	count = kfifo_out_locked(&port->write_fifo, buf + KLSI_HDR_LEN, size,
								&port->lock);
	put_unaligned_le16(count, buf);

	return count + KLSI_HDR_LEN;
}
示例#4
0
/**
 * usb_serial_generic_write_start - kick off an URB write
 * @port:	Pointer to the &struct usb_serial_port data
 *
 * Returns the number of bytes queued on success. This will be zero if there
 * was nothing to send. Otherwise, it returns a negative errno value
 */
static int usb_serial_generic_write_start(struct usb_serial_port *port)
{
	struct usb_serial *serial = port->serial;
	unsigned char *data;
	int result;
	int count;
	unsigned long flags;
	bool start_io;

	/* Atomically determine whether we can and need to start a USB
	 * operation. */
	spin_lock_irqsave(&port->lock, flags);
	if (port->write_urb_busy)
		start_io = false;
	else {
		start_io = (kfifo_len(&port->write_fifo) != 0);
		port->write_urb_busy = start_io;
	}
	spin_unlock_irqrestore(&port->lock, flags);

	if (!start_io)
		return 0;

	data = port->write_urb->transfer_buffer;
	count = kfifo_out_locked(&port->write_fifo, data, port->bulk_out_size, &port->lock);
	usb_serial_debug_data(debug, &port->dev, __func__, count, data);

	/* set up our urb */
	usb_fill_bulk_urb(port->write_urb, serial->dev,
			   usb_sndbulkpipe(serial->dev,
				port->bulk_out_endpointAddress),
			   port->write_urb->transfer_buffer, count,
			   ((serial->type->write_bulk_callback) ?
			     serial->type->write_bulk_callback :
			     usb_serial_generic_write_bulk_callback),
			   port);

	/* send the data out the bulk port */
	result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
	if (result) {
		dev_err(&port->dev,
			"%s - failed submitting write urb, error %d\n",
						__func__, result);
		/* don't have to grab the lock here, as we will
		   retry if != 0 */
		port->write_urb_busy = 0;
	} else
		result = count;

	return result;
}
static int aircable_prepare_write_buffer(struct usb_serial_port *port,
        void *dest, size_t size)
{
    int count;
    unsigned char *buf = dest;

    count = kfifo_out_locked(&port->write_fifo, buf + HCI_HEADER_LENGTH,
                             size - HCI_HEADER_LENGTH, &port->lock);
    buf[0] = TX_HEADER_0;
    buf[1] = TX_HEADER_1;
    put_unaligned_le16(count, &buf[2]);

    return count + HCI_HEADER_LENGTH;
}
示例#6
0
/* Receiver */
static int cx23888_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
			      ssize_t *num)
{
	struct cx23888_ir_state *state = to_state(sd);
	bool invert = (bool) atomic_read(&state->rx_invert);
	u16 divider = (u16) atomic_read(&state->rxclk_divider);

	unsigned int i, n;
	u32 *p;
	u32 u, v;

	n = count / sizeof(u32) * sizeof(u32);
	if (n == 0) {
		*num = 0;
		return 0;
	}

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
	n = kfifo_get(state->rx_kfifo, buf, n);
#else
	n = kfifo_out_locked(&state->rx_kfifo, buf, n, &state->rx_kfifo_lock);
#endif

	n /= sizeof(u32);
	*num = n * sizeof(u32);

	for (p = (u32 *) buf, i = 0; i < n; p++, i++) {
		if ((*p & FIFO_RXTX_RTO) == FIFO_RXTX_RTO) {
			*p = V4L2_SUBDEV_IR_PULSE_RX_SEQ_END;
			v4l2_dbg(2, ir_888_debug, sd, "rx read: end of rx\n");
			continue;
		}

		u = (*p & FIFO_RXTX_LVL) ? V4L2_SUBDEV_IR_PULSE_LEVEL_MASK : 0;
		if (invert)
			u = u ? 0 : V4L2_SUBDEV_IR_PULSE_LEVEL_MASK;

		v = (u32) pulse_width_count_to_ns((u16) (*p & FIFO_RXTX),
						  divider);
		if (v >= V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS)
			v = V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS - 1;

		*p = u | v;

		v4l2_dbg(2, ir_888_debug, sd, "rx read: %10u ns  %s\n",
			 v, u ? "mark" : "space");
	}
	return 0;
}
示例#7
0
struct iu_entry *srp_iu_get(struct srp_target *target)
{
    struct iu_entry *iue = NULL;

    if (kfifo_out_locked(&target->iu_queue.queue, (void *) &iue,
                         sizeof(void *), &target->iu_queue.lock) != sizeof(void *)) {
        WARN_ONCE(1, "unexpected fifo state");
        return NULL;
    }
    if (!iue)
        return iue;
    iue->target = target;
    INIT_LIST_HEAD(&iue->ilist);
    iue->flags = 0;
    return iue;
}
示例#8
0
static int ir_prepare_write_buffer(struct usb_serial_port *port,
						void *dest, size_t size)
{
	unsigned char *buf = dest;
	int count;

	/*
	 * The first byte of the packet we send to the device contains an
	 * inbound header which indicates an additional number of BOFs and
	 * a baud rate change.
	 *
	 * See section 5.4.2.2 of the USB IrDA spec.
	 */
	*buf = ir_xbof | ir_baud;

	count = kfifo_out_locked(&port->write_fifo, buf + 1, size - 1,
								&port->lock);
	return count + 1;
}
示例#9
0
struct iu_entry *srp_iu_get(struct srp_target *target)
{
	struct iu_entry *iue = NULL;

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
	kfifo_get(target->iu_queue.queue, (void *) &iue, sizeof(void *));
#else
	if (kfifo_out_locked(&target->iu_queue.queue, (void *) &iue,
		sizeof(void *), &target->iu_queue.lock) != sizeof(void *)) {
			WARN_ONCE(1, "unexpected fifo state");
			return NULL;
	}
#endif
	if (!iue)
		return iue;
	iue->target = target;
	iue->flags = 0;
	return iue;
}
示例#10
0
static ssize_t tmsi_read(struct file *file, char *buffer, size_t count, loff_t *ppos) {
    struct tmsi_data* dev;
    char* temp_buffer = NULL;
    int retval = 0;
    size_t true_count;
    dev = (struct tmsi_data*) file->private_data;
    if (down_timeout(dev->fifo_sem, HZ / 2) != 0)
        return -ETIME;
    while (down_trylock(dev->fifo_sem) == 0);

    temp_buffer = kmalloc(count, GFP_KERNEL);

    if (!temp_buffer) {
        retval = -ENOMEM;
        goto exit;
    }


#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
    true_count = kfifo_out_spinlocked(dev->packet_buffer, temp_buffer, count, &dev->buffer_lock);
#elif LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32)
    true_count = kfifo_out_locked(dev->packet_buffer, temp_buffer, count, &dev->buffer_lock);
#else
    true_count = kfifo_get(dev->packet_buffer, temp_buffer, count);
#endif


    /* if the read was successful, copy the data to userspace */
    if (copy_to_user(buffer, temp_buffer, true_count))
        retval = -EFAULT;
    else
        retval = true_count;

    kfree(temp_buffer);
exit:
    if (kfifo_len(dev->packet_buffer) > 0)
        up(dev->fifo_sem);
    return retval;
}
static ssize_t plp_kmem_read(struct file *filp, char __user *buf,size_t count, loff_t *pos)
{
	P_SERIAL_DEV *dev= filp->private_data;
	int bytes;
	printk (">>>>>>>>>>>In read call\n");
	 

	if (kfifo_is_empty(&(dev->read_kfifo)))
	{
		if (filp->f_flags & O_NONBLOCK)
			return -EAGAIN;
		else
			wait_event_interruptible(dev->read_queue, !kfifo_is_empty(&(dev->read_kfifo))) ;
	}

	if (access_ok (VERIFY_WRITE, (void __user *) buf, (unsigned long) count))
	{
		bytes = kfifo_out_locked(&(dev->read_kfifo),(void __user *) buf,count,&(dev->rd_spinlock));
		return bytes;
	}
	else
		return -EFAULT;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//AudioCtrlWorkThread
//	Worker thread, it query KFIFO for operation message and call HAL_AudioProcess.
//----------------------------------------------------------------
static void AudioCtrlWorkThread(struct work_struct *work)
{
	TMsgAudioCtrl	msgAudioCtrl;
	unsigned int len = 0;

    set_user_nice(current, -16);


	while(1)
	{
		//get operation code from fifo
		len = kfifo_out_locked(&sgThreadData.m_pkfifo, (unsigned char *)&msgAudioCtrl, sizeof(TMsgAudioCtrl), &sgThreadData.m_lock);
		if( (len != sizeof(TMsgAudioCtrl)) && (len!=0) )
			DEBUG("Error AUDIO_Ctrl len=%d expected %d in=%d, out=%d\n", len, sizeof(TMsgAudioCtrl), sgThreadData.m_pkfifo.in, sgThreadData.m_pkfifo.out);
		if(len == 0) //FIFO empty sleep
			return;
		
		//process the operation
		AUDIO_Ctrl_Process(msgAudioCtrl.action_code, &msgAudioCtrl.param, msgAudioCtrl.pCallBack,msgAudioCtrl.block);
	}

	return;
}
示例#13
0
int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port,
        void *dest, size_t size)
{
    return kfifo_out_locked(&port->write_fifo, dest, size, &port->lock);
}
irqreturn_t pseudo_serial_intr_handler(int irq_no, void *p_dev)
{
	int ret_val,i,j;
	irqreturn_t irq_r_flag=0;
	P_SERIAL_DEV *dev = (P_SERIAL_DEV *)p_dev;
	char lk_buff[HW_FIFO_SIZE];
	
	irq_r_flag |= IRQ_NONE;

printk("\n\n>in irqreturn_t...!\n");
	if(inb(base_addr+0x05) & 0x20) 		//comparing for Tx interrupt
	{
	printk("\n>in irqreturn_t    Tx interrupt...!\n");

		outb (0x01, base_addr + 1); //IER ,disabling Tx & enabling Rx buffer interrupt ERBFI & EXBFI
		
		//copying the data into local buffer from the kfifo buffer

		ret_val = kfifo_out_locked(&(dev->write_kfifo),lk_buff,HW_FIFO_SIZE, &(dev->wr_spinlock));

		printk("\n>in irqreturn_t    Tx interrupt   ret_val = kfifo_out_locked  %d...!\n", ret_val);
		if(ret_val > 0)
		{
			for(i = 0; i < ret_val ; i++)
				outb(lk_buff[i], base_addr+0x00);
		}
		
		wake_up_interruptible (&(dev->write_queue));
	  
		irq_r_flag |= IRQ_HANDLED; 
	}	


	if(inb(base_addr+0x05) & 0x01) 		//comparing for Rx interrupt
	{

	printk("\n>in irqreturn_t    Rx interrupt...!\n");

		for(j=0;j<16;j++)
		{
			if(inb(base_addr+0x05) & 0x01)
			{
				lk_buff[j] = inb(base_addr+0x00);
			}
			else
				break;
		}

		//copying the data from local buffer onto the kfifo buffer

		if(kfifo_is_full(&(dev->read_kfifo)))
			dropped += j;
		else
		{
			kfifo_in_locked(&(dev->read_kfifo),lk_buff,j,&(dev->rd_spinlock));
			received += j;
		}
	
		wake_up_interruptible(&(dev->read_queue));
	  
		irq_r_flag |= IRQ_HANDLED; 
	}

	

	return irq_r_flag; 
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//HAL_AUDIO_Ctrl
//	Client call this function to execute audio HAL functions.
//	This function for the message to worker thread to do actual work
//----------------------------------------------------------------
Result_t AUDIO_Ctrl_Trigger(
	BRCM_AUDIO_ACTION_en_t action_code,
	void *arg_param,
	void *callback,
    int block
	)
{
	TMsgAudioCtrl	msgAudioCtrl;
	Result_t status = RESULT_OK;
	unsigned int	len;
    OSStatus_t  osStatus;

	{
		//BRCM_AUDIO_Control_Params_un_t *paudioControlParam = (BRCM_AUDIO_Control_Params_un_t *)arg_param;
		DEBUG("AudioHalThread action=%d\r\n", action_code);
	}


	msgAudioCtrl.action_code = action_code;
	if(arg_param)
		memcpy(&msgAudioCtrl.param, arg_param, sizeof(BRCM_AUDIO_Control_Params_un_t));
	else
		memset(&msgAudioCtrl.param, 0, sizeof(BRCM_AUDIO_Control_Params_un_t));
	msgAudioCtrl.pCallBack = callback;
    msgAudioCtrl.block = block;

	len = kfifo_in_locked(&sgThreadData.m_pkfifo, (unsigned char *)&msgAudioCtrl, sizeof(TMsgAudioCtrl), &sgThreadData.m_lock);
	if(len != sizeof(TMsgAudioCtrl))
	{
		DEBUG("Error AUDIO_Ctrl_Trigger len=%d expected %d \n", len, sizeof(TMsgAudioCtrl));
		return RESULT_ERROR;
	}

	queue_work(sgThreadData.pWorkqueue_AudioControl, &sgThreadData.mwork);

    if(block)
    {
        // wait for 10sec
        osStatus = OSSEMAPHORE_Obtain(sgThreadData.action_complete,1280);
        if(osStatus != OSSTATUS_SUCCESS)
        {
            DEBUG("AUDIO_Ctrl_Trigger Timeout=%d\r\n",osStatus);
        }

        while(1)
	    {

            //wait for output from output fifo
		    len = kfifo_out_locked(&sgThreadData.m_pkfifo_out, (unsigned char *)&msgAudioCtrl, sizeof(TMsgAudioCtrl), &sgThreadData.m_lock_out);
		    if( (len != sizeof(TMsgAudioCtrl)) && (len!=0) )
			    DEBUG("Error AUDIO_Ctrl_Trigger len=%d expected %d in=%d, out=%d\n", len, sizeof(TMsgAudioCtrl), sgThreadData.m_pkfifo_out.in, sgThreadData.m_pkfifo_out.out);
		    if(len == 0) //FIFO empty sleep
			    return status;
            if(arg_param)
		        memcpy(arg_param,&msgAudioCtrl.param,  sizeof(BRCM_AUDIO_Control_Params_un_t));
	        else
		        memset(arg_param, 0, sizeof(BRCM_AUDIO_Control_Params_un_t));
	    }
    }
	
	return status;
}