/*
 * ./kernel_modules/qcom-adc/adc-averaging.c
 *
 * This file does some basic FIR averaging on a fifo; it is intended to be used
 * with the ADS7924 device driver
 *
 * Author: Cradlepoint Technology, Inc.  <source@cradlepoint.com>
 *		Kyle Swenson <kswenson@cradlepoint.com>
 *
 * Copyright 2017 Cradlepoint Technology, Inc.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 */
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/err.h>
#include <linux/slab.h>
#include "adc-averaging.h"


void free_adc_channel(struct adc_channel *ch)
{
	mutex_lock(&ch->lock);
	if (ch->samples) {
		devm_kfree(ch->parent, ch->samples);
		ch->samples = NULL;
	}
	mutex_unlock(&ch->lock);
	mutex_destroy(&ch->lock);
	devm_kfree(ch->parent, ch);
}

struct adc_channel *create_adc_channel(struct device * dev, uint16_t fifo_length)
{
	struct adc_channel *ch;
	if (fifo_length >= MAX_SAMPLE_LENGTH) {
		printk(KERN_ALERT "Requested a ADC buffer length (%u) exceedes max (%u)\n", fifo_length, MAX_SAMPLE_LENGTH);
		return NULL;

	}
	ch = devm_kzalloc(dev, sizeof(struct adc_channel), GFP_KERNEL);
	if (!ch)
		return NULL;

	ch->samples = devm_kzalloc(dev, sizeof(uint16_t) * fifo_length, GFP_KERNEL);
	if (!ch->samples)
		return NULL;

	ch->total_length = fifo_length;
	ch->index = 0;
	mutex_init(&ch->lock);
	ch->parent = dev;
	return ch;
}

uint16_t compute_average(struct adc_channel *ch)
{
	uint32_t sum=0;
	uint16_t average;
	int i = 0;
	mutex_lock(&ch->lock);
	for (i = 0; i < ch->total_length; i++) {
		sum += ch->samples[i];
	}
	average = DIV_ROUND_CLOSEST(sum, ch->total_length);
	mutex_unlock(&ch->lock);
	return average;
}

void add_sample(struct adc_channel *ch, uint16_t sample)
{
	mutex_lock(&ch->lock);
	ch->samples[ch->index++] = sample;
	if (ch->index >= ch->total_length)
		ch->index = 0;
	mutex_unlock(&ch->lock);
}
