misc: cs40l20: Add support for stored ReDC

Added the redc_stored sysfs control to expose access to the firmware's
stored ReDC input parameter.

Change-Id: Ifb6ca330f9b1a546c024d9e066dbb4da5fafe4c6
Signed-off-by: Jeff LaBundy <jeff.labundy@cirrus.com>
Signed-off-by: Ravi Vembu <raviv@motorola.com>
This commit is contained in:
Jeff LaBundy 2018-02-23 15:01:45 -06:00 • committed by a7301c
commit 81adc68352
2 changed files with 51 additions and 1 deletions

View file

@ -319,6 +319,53 @@ static ssize_t cs40l20_redc_measured_show(struct device *dev,
return snprintf(buf, PAGE_SIZE, "%d\n", redc_measured);
}
static ssize_t cs40l20_redc_stored_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct cs40l20_private *cs40l20 = cs40l20_get_private(dev);
int ret;
unsigned int val;
mutex_lock(&cs40l20->lock);
ret = regmap_read(cs40l20->regmap,
cs40l20_dsp_reg(cs40l20, "REDC_STORED",
CS40L20_XM_UNPACKED_TYPE), &val);
mutex_unlock(&cs40l20->lock);
if (ret) {
pr_err("Failed to read stored ReDC\n");
return ret;
}
return snprintf(buf, PAGE_SIZE, "%d\n", val);
}
static ssize_t cs40l20_redc_stored_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct cs40l20_private *cs40l20 = cs40l20_get_private(dev);
int ret;
unsigned int val;
ret = kstrtou32(buf, 10, &val);
if (ret)
return -EINVAL;
mutex_lock(&cs40l20->lock);
ret = regmap_write(cs40l20->regmap,
cs40l20_dsp_reg(cs40l20, "REDC_STORED",
CS40L20_XM_UNPACKED_TYPE), val);
mutex_unlock(&cs40l20->lock);
if (ret) {
pr_err("Failed to store ReDC\n");
return ret;
}
return count;
}
static ssize_t cs40l20_dig_scale_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@ -369,6 +416,8 @@ static DEVICE_ATTR(f0_measured, 0660, cs40l20_f0_measured_show, NULL);
static DEVICE_ATTR(f0_stored, 0660, cs40l20_f0_stored_show,
cs40l20_f0_stored_store);
static DEVICE_ATTR(redc_measured, 0660, cs40l20_redc_measured_show, NULL);
static DEVICE_ATTR(redc_stored, 0660, cs40l20_redc_stored_show,
cs40l20_redc_stored_store);
static DEVICE_ATTR(dig_scale, 0660, cs40l20_dig_scale_show,
cs40l20_dig_scale_store);
@ -379,6 +428,7 @@ static struct attribute *cs40l20_dev_attrs[] = {
&dev_attr_f0_measured.attr,
&dev_attr_f0_stored.attr,
&dev_attr_redc_measured.attr,
&dev_attr_redc_stored.attr,
&dev_attr_dig_scale.attr,
NULL,
};

View file

@ -697,7 +697,7 @@
#define CS40L20_XM_LIST_TERM 0xBEDEAD
#define CS40L20_NUM_ALGOS_MAX 16
#define CS40L20_FW_REV_MIN 0x000205
#define CS40L20_FW_REV_MIN 0x000300
#define CS40L20_ALGO_ID_SIZE 4
#define CS40L20_COEFF_COUNT_SIZE 4