Skip to content

Commit

Permalink
sound_control: initial code push for Headphones gain userspace interf…
Browse files Browse the repository at this point in the history
…ace.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>

sound_control: add headset, speaker and mic gain interfaces. Also add the sysfs control file.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>

sound_control: add workaround to prevent audio resets after using custom values. Based on faux123/Nexus_5@33407fd

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>

sound: wcd9320: tidy up things a little bit. Only accept signed values from now on. The 'headset gain' will only be used to remove some gain noise, increasing it beyond 1 step above the default doesn't make a difference so rather just have it decrease the gain.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>

sound_control: clean the code

* proper 80-char indentation
* add module_exit
* clean up the store functions using proper and modern kstroul
* use unsigned boost vars since we're not accepting negative
values anymore
* remove that stupid and useless version define

sound_control: goodbye externs

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>

Conflicts:

	drivers/misc/Makefile

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
  • Loading branch information
franciscofranco authored and RealJohnGalt committed May 31, 2016
1 parent 4b5c248 commit 478f731
Show file tree
Hide file tree
Showing 4 changed files with 385 additions and 1 deletion.
1 change: 1 addition & 0 deletions drivers/misc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ obj-$(CONFIG_TI_DRV2667) += ti_drv2667.o
obj-$(CONFIG_QPNP_MISC) += qpnp-misc.o
obj-$(CONFIG_EARJACK_DEBUGGER) += earjack_debugger.o
obj-$(CONFIG_FAN48632_BOOST) += fan48632_boost.o
obj-y += sound_control.o
199 changes: 199 additions & 0 deletions drivers/misc/sound_control.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
* Copyright 2013-2014 Francisco Franco
* franciscofranco.1990@gmail.com
*
* 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.
*/

#include <linux/init.h>
#include <linux/device.h>
#include <linux/miscdevice.h>
#include <linux/sound_control.h>

#define MAX_VALUE 20

/*
* Volume boost value
*/

unsigned int headphones_boost = 0;

/*
* Headset boost value
*/
unsigned int headset_boost = 0;

/*
* Speaker boost value
*/
unsigned int speaker_boost = 0;

/*
* Mic boost value
*/
unsigned int mic_boost = 0;

/*
* Sysfs get/set entries
*/

static ssize_t headphones_boost_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d\n", headphones_boost);
}

static ssize_t headphones_boost_store(struct device * dev,
struct device_attribute * attr, const char * buf, size_t size)
{
int ret;
unsigned long val;

ret = kstrtoul(buf, 0, &val);
if (ret < 0)
return ret;

headphones_boost = val > MAX_VALUE ? MAX_VALUE : val;

update_headphones_volume_boost(headphones_boost);

pr_info("%s: %d\n", __func__, headphones_boost);

return size;
}

static ssize_t headset_boost_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d\n", headset_boost);
}

static ssize_t headset_boost_store(struct device * dev,
struct device_attribute * attr, const char * buf, size_t size)
{
int ret;
unsigned long val;

ret = kstrtoul(buf, 0, &val);
if (ret < 0)
return ret;

headset_boost = val > MAX_VALUE ? MAX_VALUE : val;

update_headset_boost(headphones_boost);

pr_info("%s: %d\n", __func__, headset_boost);

return size;
}

static ssize_t speaker_boost_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d\n", speaker_boost);
}

static ssize_t speaker_boost_store(struct device * dev,
struct device_attribute * attr, const char * buf, size_t size)
{
int ret;
unsigned long val;

ret = kstrtoul(buf, 0, &val);
if (ret < 0)
return ret;

speaker_boost = val > MAX_VALUE ? MAX_VALUE : val;

update_speaker_gain(speaker_boost);

pr_info("%s: %d\n", __func__, speaker_boost);

return size;
}

static ssize_t mic_boost_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d\n", mic_boost);
}

static ssize_t mic_boost_store(struct device * dev,
struct device_attribute * attr, const char * buf, size_t size)
{
int ret;
unsigned long val;

ret = kstrtoul(buf, 0, &val);
if (ret < 0)
return ret;

mic_boost = val > MAX_VALUE ? MAX_VALUE : val;

update_mic_gain(mic_boost);

pr_info("%s: %d\n", __func__, mic_boost);

return size;
}

static DEVICE_ATTR(volume_boost, 0664, headphones_boost_show,
headphones_boost_store);
static DEVICE_ATTR(headset_boost, 0664, headset_boost_show,
headset_boost_store);
static DEVICE_ATTR(speaker_boost, 0664, speaker_boost_show,
speaker_boost_store);
static DEVICE_ATTR(mic_boost, 0664, mic_boost_show, mic_boost_store);

static struct attribute *soundcontrol_attributes[] =
{
&dev_attr_volume_boost.attr,
&dev_attr_headset_boost.attr,
&dev_attr_speaker_boost.attr,
&dev_attr_mic_boost.attr,
NULL
};

static struct attribute_group soundcontrol_group =
{
.attrs = soundcontrol_attributes,
};

static struct miscdevice soundcontrol_device =
{
.minor = MISC_DYNAMIC_MINOR,
.name = "soundcontrol",
};

static void __exit soundcontrol_exit(void)
{
misc_deregister(&soundcontrol_device);
}

static int __init soundcontrol_init(void)
{
int ret;

pr_info("%s misc_register(%s)\n", __FUNCTION__, soundcontrol_device.name);

ret = misc_register(&soundcontrol_device);

if (ret) {
pr_err("%s misc_register(%s) fail\n", __FUNCTION__,
soundcontrol_device.name);
return 1;
}

if (sysfs_create_group(&soundcontrol_device.this_device->kobj,
&soundcontrol_group) < 0) {
pr_err("%s sysfs_create_group fail\n", __FUNCTION__);
pr_err("Failed to create sysfs group for device (%s)!\n",
soundcontrol_device.name);
}

return 0;
}
late_initcall(soundcontrol_init);
module_exit(soundcontrol_exit);
18 changes: 18 additions & 0 deletions include/linux/sound_control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* linux/include/linux/sound_control.h
*
* franciscofranco.1990@gmail.com
*
* 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.
*/
#ifndef _LINUX_SOUNT_CONTROL_H
#define _LINUX_SOUNT_CONTROL_H

void update_headphones_volume_boost(int vol_boost);
void update_headset_boost(int vol_boost);
void update_speaker_gain(int vol_boost);
void update_mic_gain(int vol_boost);

#endif
Loading

0 comments on commit 478f731

Please sign in to comment.