{
struct comedi_async *async = s->async;
unsigned int count = 0;
- const unsigned num_sample_bytes = bytes_per_sample(s);
+ const unsigned num_sample_bytes = comedi_bytes_per_sample(s);
if (!s->munge || (async->cmd.flags & CMDF_RAWDATA)) {
async->munge_count += num_bytes;
* If not, clamp the nsamples to the number that will fit, flag the
* buffer overrun and add the samples that fit.
*/
- max_samples = comedi_buf_write_n_available(s) / bytes_per_sample(s);
+ max_samples = comedi_bytes_to_samples(s,
+ comedi_buf_write_n_available(s));
if (nsamples > max_samples) {
dev_warn(s->device->class_dev, "buffer overrun\n");
s->async->events |= COMEDI_CB_OVERFLOW;
if (nsamples == 0)
return 0;
- nbytes = comedi_buf_write_alloc(s, nsamples * bytes_per_sample(s));
+ nbytes = comedi_buf_write_alloc(s,
+ comedi_samples_to_bytes(s, nsamples));
comedi_buf_memcpy_to(s, data, nbytes);
comedi_buf_write_free(s, nbytes);
comedi_inc_scan_progress(s, nbytes);
unsigned int nbytes;
/* clamp nsamples to the number of full samples available */
- max_samples = comedi_buf_read_n_available(s) / bytes_per_sample(s);
+ max_samples = comedi_bytes_to_samples(s,
+ comedi_buf_read_n_available(s));
if (nsamples > max_samples)
nsamples = max_samples;
if (nsamples == 0)
return 0;
- nbytes = comedi_buf_read_alloc(s, nsamples * bytes_per_sample(s));
+ nbytes = comedi_buf_read_alloc(s,
+ comedi_samples_to_bytes(s, nsamples));
comedi_buf_memcpy_from(s, data, nbytes);
comedi_buf_read_free(s, nbytes);
comedi_inc_scan_progress(s, nbytes);
s = comedi_write_subdevice(dev, minor);
if (s && s->async) {
- unsigned int bps = bytes_per_sample(s);
+ unsigned int bps = comedi_bytes_per_sample(s);
poll_wait(file, &s->async->wait_head, wait);
comedi_buf_write_alloc(s, s->async->prealloc_bufsz);
return s->subdev_flags & SDF_LSAMPL ? sizeof(int) : sizeof(short);
}
-/* to be removed */
-static inline unsigned int bytes_per_sample(struct comedi_subdevice *s)
-{
- return comedi_bytes_per_sample(s);
-}
-
/**
* comedi_sample_shift - determine log2 of subdevice sample size
* @s: comedi_subdevice struct
case COMEDI_SUBD_DI:
case COMEDI_SUBD_DO:
case COMEDI_SUBD_DIO:
- bits_per_sample = 8 * bytes_per_sample(s);
+ bits_per_sample = 8 * comedi_bytes_per_sample(s);
num_samples = DIV_ROUND_UP(cmd->chanlist_len, bits_per_sample);
break;
default:
num_samples = cmd->chanlist_len;
break;
}
- return num_samples * bytes_per_sample(s);
+ return comedi_samples_to_bytes(s, num_samples);
}
EXPORT_SYMBOL_GPL(comedi_bytes_per_scan);
nsamples = devpriv->ao_count;
nbytes = comedi_buf_read_samples(s, devpriv->ao_buffer, nsamples);
- nsamples = nbytes / bytes_per_sample(s);
+ nsamples = comedi_bytes_to_samples(s, nbytes);
if (cmd->stop_src == TRIG_COUNT)
devpriv->ao_count -= nsamples;
{
struct pcidas64_private *devpriv = dev->private;
struct comedi_cmd *cmd = &s->async->cmd;
- unsigned int nsamples = max_bytes / bytes_per_sample(s);
+ unsigned int nsamples = comedi_bytes_to_samples(s, max_bytes);
unsigned int actual_bytes;
if (cmd->stop_src == TRIG_COUNT && devpriv->ao_count < nsamples)
nsamples = devpriv->ao_count;
actual_bytes = comedi_buf_read_samples(s, dest, nsamples);
- nsamples = actual_bytes / bytes_per_sample(s);
+ nsamples = comedi_bytes_to_samples(s, actual_bytes);
if (cmd->stop_src == TRIG_COUNT)
devpriv->ao_count -= nsamples;
if (nsamples == 0)
return 0;
- nbytes = nsamples * bytes_per_sample(s);
+ nbytes = comedi_samples_to_bytes(s, nsamples);
devpriv->ao_dma_desc[buffer_index].transfer_size = cpu_to_le32(nbytes);
/* set end of chain bit so we catch underruns */
next_bits = le32_to_cpu(devpriv->ao_dma_desc[buffer_index].next);
spin_unlock_irqrestore(&dev->spinlock, spin_flags);
- nsamples = num_bytes / bytes_per_sample(s);
+ nsamples = comedi_bytes_to_samples(s, num_bytes);
comedi_buf_write_samples(s, devpriv->dma_buffer[buffer_index],
nsamples);
{
struct dt282x_private *devpriv = dev->private;
void *ptr = devpriv->dma[cur_dma].buf;
- unsigned int nsamples = devpriv->dma_maxsize / bytes_per_sample(s);
+ unsigned int nsamples = comedi_bytes_to_samples(s, devpriv->dma_maxsize);
unsigned int nbytes;
nbytes = comedi_buf_read_samples(s, ptr, nsamples);
int cur_dma = devpriv->current_dma_index;
void *ptr = devpriv->dma[cur_dma].buf;
int size = devpriv->dma[cur_dma].size;
- unsigned int nsamples = size / bytes_per_sample(s);
+ unsigned int nsamples = comedi_bytes_to_samples(s, size);
int ret;
outw(devpriv->supcsr | DT2821_SUPCSR_CLRDMADNE,
struct ni_private *devpriv = dev->private;
struct comedi_async *async = s->async;
struct comedi_cmd *cmd = &async->cmd;
- unsigned int length = num_bytes / bytes_per_sample(s);
+ unsigned int nsamples = comedi_bytes_to_samples(s, num_bytes);
unsigned short *array = data;
unsigned int *larray = data;
unsigned int i;
- for (i = 0; i < length; i++) {
+ for (i = 0; i < nsamples; i++) {
#ifdef PCIDMA
if (s->subdev_flags & SDF_LSAMPL)
larray[i] = le32_to_cpu(larray[i]);
unsigned int chan_index)
{
struct comedi_cmd *cmd = &s->async->cmd;
- unsigned int length = num_bytes / bytes_per_sample(s);
+ unsigned int nsamples = comedi_bytes_to_samples(s, num_bytes);
unsigned short *array = data;
unsigned int i;
- for (i = 0; i < length; i++) {
+ for (i = 0; i < nsamples; i++) {
unsigned int range = CR_RANGE(cmd->chanlist[chan_index]);
unsigned short val = array[i];
if (devpriv->ignore) {
devpriv->ignore--;
} else {
- unsigned int nbytes = urb->actual_length;
- unsigned int nsamples = nbytes / bytes_per_sample(s);
+ unsigned int nsamples;
+ nsamples = comedi_bytes_to_samples(s, urb->actual_length);
if (cmd->stop_src == TRIG_COUNT) {
if (devpriv->ai_sample_count < nsamples) {
nsamples = devpriv->ai_sample_count;