px30_oreo headser sound is too small

diff --git a/kernel/arch/arm64/boot/dts/rockchip/x30_evb.dts b/kernel/arch/arm64/boot/dts/rockchip/x30_evb.dts
index cfa7a38..9c54525 100755
--- a/kernel/arch/arm64/boot/dts/rockchip/x30_evb.dts
+++ b/kernel/arch/arm64/boot/dts/rockchip/x30_evb.dts
@@ -132,13 +132,24 @@
 	};
 
 	rk_headset {
+		status = "disabled";
 		compatible = "rockchip_headset";
 		headset_gpio = <&gpio2 RK_PB0 GPIO_ACTIVE_LOW>;
 		pinctrl-names = "default";
 		pinctrl-0 = <&hp_det>;
 		io-channels = <&saradc 1>;
 	};
-
+	
+   headset_det: headset-det {
+        compatible = "rockchip,key";
+        io-channels = <&saradc 1>;
+        jack-in-key {
+            linux,code = <120>; /* headset code */
+            label = "jack in";
+            rockchip,adc_value = <1>; /* ADC > 2.43v: plug in earphones */
+        };
+    };
+	
 	sdio_pwrseq: sdio-pwrseq {
 		compatible = "mmc-pwrseq-simple";
 		/*clocks = <&rk809 1>;*/
diff --git a/kernel/drivers/input/keyboard/rk_keys.c b/kernel/drivers/input/keyboard/rk_keys.c
old mode 100644
new mode 100755
index fed5ced..04c565b
--- a/kernel/drivers/input/keyboard/rk_keys.c
+++ b/kernel/drivers/input/keyboard/rk_keys.c
@@ -23,7 +23,9 @@
 #include <linux/input.h>
 #include <linux/adc.h>
 #include <linux/slab.h>
+#include <linux/switch.h>
 #include <linux/wakelock.h>
+#include <linux/switch.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/machine.h>
@@ -42,6 +44,7 @@
 #define INVALID_ADVALUE			-1
 #define EV_ENCALL			KEY_F4
 #define EV_MENU				KEY_F1
+#define DRIFT_ADVALUE 70
 
 #if 0
 #define key_dbg(bdata, format, arg...)		\
@@ -87,6 +90,8 @@ struct rk_keys_drvdata {
 	struct rk_keys_button button[0];
 };
 
+static struct switch_dev sdev;
+
 static struct input_dev *sinput_dev;
 
 void rk_send_power_key(int state)
@@ -209,16 +214,29 @@ static void adc_key_poll(struct work_struct *work)
 		if (result > INVALID_ADVALUE &&
 		    result < (EMPTY_DEFAULT_ADVALUE - ddata->drift_advalue))
 			ddata->result = result;
+			//printk("adc_key_poll result=0x%x,ddata->drift_advalue=0x%x\r\n",result,ddata->drift_advalue);
 		for (i = 0; i < ddata->nbuttons; i++) {
 			struct rk_keys_button *button = &ddata->button[i];
-
 			if (!button->adc_value)
 				continue;
 			if (result < button->adc_value + ddata->drift_advalue &&
-			    result > button->adc_value - ddata->drift_advalue)
-				button->adc_state = 1;
-			else
-				button->adc_state = 0;
+			    result > button->adc_value - DRIFT_ADVALUE) {
+					button->adc_state = 1;
+					if (button->code == 120) /* headset key code */
+						switch_set_state(&sdev, 1);
+						//printk("adc_key_poll headset key code=============\r\n");
+			}
+			else {
+		if (button->code != 120) /* adc key up */
+					button->adc_state = 0;
+				else {
+					if (result > 868) { /* ADC > 2.8v:  unplug a headset or headphones */
+					button->adc_state = 0;
+					switch_set_state(&sdev, 0);
+					//printk("adc_key_poll unplug a headset or headphones=============\r\n");
+					}
+				}
+		}
 			if (button->state != button->adc_state)
 				mod_timer(&button->timer,
 					  jiffies + DEBOUNCE_JIFFIES);
@@ -320,6 +338,11 @@ error_ret:
 	return ret;
 }
 
+static ssize_t h2w_print_name(struct switch_dev *sdev, char *buf)
+{
+return sprintf(buf, "Headset\n");
+}
+
 static int keys_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -328,7 +351,6 @@ static int keys_probe(struct platform_device *pdev)
 	struct input_dev *input = NULL;
 	int i, error = 0;
 	int wakeup, key_num = 0;
-
 	key_num = of_get_child_count(np);
 	if (key_num == 0)
 		dev_info(&pdev->dev, "no key defined\n");
@@ -348,7 +370,6 @@ static int keys_probe(struct platform_device *pdev)
 	input->name = "rk29-keypad";	/* pdev->name; */
 	input->phys = "gpio-keys/input0";
 	input->dev.parent = dev;
-
 	input->id.bustype = BUS_HOST;
 	input->id.vendor = 0x0001;
 	input->id.product = 0x0001;
@@ -372,7 +393,6 @@ static int keys_probe(struct platform_device *pdev)
 		goto fail0;
 	}
 	sinput_dev = input;
-
 	for (i = 0; i < ddata->nbuttons; i++) {
 		struct rk_keys_button *button = &ddata->button[i];
 
@@ -446,7 +466,9 @@ static int keys_probe(struct platform_device *pdev)
 		schedule_delayed_work(&ddata->adc_poll_work,
 				      ADC_SAMPLE_JIFFIES);
 	}
-
+	sdev.name = "h2w";
+	sdev.print_name = h2w_print_name;
+	switch_dev_register(&sdev);
 	return error;
 
 fail1:
@@ -470,8 +492,8 @@ static int keys_remove(struct platform_device *pdev)
 	device_init_wakeup(dev, 0);
 	for (i = 0; i < ddata->nbuttons; i++)
 		del_timer_sync(&ddata->button[i].timer);
-	if (ddata->chan)
-		cancel_delayed_work_sync(&ddata->adc_poll_work);
+	if (ddata->chan)cancel_delayed_work_sync(&ddata->adc_poll_work);
+		switch_dev_unregister(&sdev);
 	input_unregister_device(input);
 	wake_lock_destroy(&ddata->wake_lock);
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小猿东哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值