aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/sound_control.c
blob: 112c5df3f12d0cde7db986561cdb368bf3762ab1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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);