2 * Copyright (C) 2014 Rockchip Corporation.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/init.h>
18 #include <linux/delay.h>
20 #include <linux/i2c.h>
21 #include <linux/spi/spi.h>
22 #include <linux/platform_device.h>
23 #include <linux/errno.h>
24 #include <linux/err.h>
25 #include <linux/debugfs.h>
26 #include "rk_headset.h"
27 #include <linux/of_gpio.h>
28 #include <linux/gpio.h>
31 #define DBG(x...) printk(x)
33 #define DBG(x...) do { } while (0)
38 compatible = "rockchip_headset";
40 headset_insert_type = ; // 0 = low 1 = high
42 hook_down_type = ; //interrupt hook key down status
43 hook_adc_chn = ;//adc channel
47 hook_key_code = KEY_MEDIA;
50 struct rk_headset_pdata *pdata_info;
52 static int rockchip_headset_probe(struct platform_device *pdev)
54 struct device_node *node = pdev->dev.of_node;
55 struct rk_headset_pdata *pdata;
57 enum of_gpio_flags flags;
59 pdata = kzalloc(sizeof(struct rk_headset_pdata), GFP_KERNEL);
61 printk("%s failed to allocate driver data\n",__FUNCTION__);
64 memset(pdata,0,sizeof(struct rk_headset_pdata));
67 ret = of_get_named_gpio_flags(node, "headset_gpio", 0, &flags);
69 printk("%s() Can not read property headset_gpio\n", __FUNCTION__);
72 pdata->headset_gpio = ret;
73 ret = devm_gpio_request(&pdev->dev, pdata->headset_gpio, "headset_gpio");
75 printk("%s() devm_gpio_request headset_gpio request ERROR\n", __FUNCTION__);
78 //gpio_pull_updown(pdata->headset_gpio, PullDisable);
79 ret = gpio_direction_input(pdata->headset_gpio);
81 printk("%s() gpio_direction_input headset_gpio set ERROR\n", __FUNCTION__);
86 ret = of_property_read_u32(node, "headset_insert_type", &pdata->headset_insert_type);
88 DBG("%s() have not set headset_insert_type,set >headset< insert type low level default\n", __FUNCTION__);
89 pdata->headset_insert_type = 0;
92 ret = of_get_named_gpio_flags(node, "hook_gpio", 0, &pdata->hook_gpio);
94 DBG("%s() Can not read property hook_gpio\n", __FUNCTION__);
97 ret = of_property_read_u32(node, "hook_adc_chn", &pdata->hook_adc_chn);
99 DBG("%s() have not set hook_adc_chn\n", __FUNCTION__);
100 pdata->hook_adc_chn = -1;
103 ret = of_property_read_u32(node, "hook_down_type", &pdata->hook_down_type);
105 DBG("%s() have not set hook_down_type,set >hook< insert type low level default\n", __FUNCTION__);
106 pdata->hook_down_type = 0;
108 ret = devm_gpio_request(&pdev->dev, pdata->hook_gpio, "hook_gpio");
110 printk("%s() devm_gpio_request hook_gpio request ERROR\n", __FUNCTION__);
113 //gpio_pull_updown(pdata->hook_gpio, PullDisable);
114 ret = gpio_direction_input(pdata->hook_gpio);
116 printk("%s() gpio_direction_input hook_gpio set ERROR\n", __FUNCTION__);
120 #ifdef CONFIG_MODEM_MIC_SWITCH
122 ret = of_get_named_gpio_flags(node, "mic_switch_gpio", 0, &flags);
124 DBG("%s() Can not read property mic_switch_gpio\n", __FUNCTION__);
126 pdata->headset_gpio = ret;
127 ret = of_property_read_u32(node, "hp_mic_io_value", &pdata->hp_mic_io_value);
129 DBG("%s() have not set hp_mic_io_value ,so default set pull down low level\n", __FUNCTION__);
130 pdata->hp_mic_io_value = 0;
132 ret = of_property_read_u32(node, "main_mic_io_value", &pdata->main_mic_io_value);
134 DBG("%s() have not set main_mic_io_value ,so default set pull down low level\n", __FUNCTION__);
135 pdata->main_mic_io_value = 1;
139 if(pdata->hook_adc_chn >= 0)
141 printk("%s() headset have hook adc mode\n",__FUNCTION__);
142 ret = rk_headset_adc_probe(pdev,pdata);
149 {//hook interrupt mode and not hook
150 printk("%s() headset have %s mode\n",__FUNCTION__,pdata->hook_gpio?"interrupt hook":"no hook");
151 ret = rk_headset_probe(pdev,pdata);
164 static int rockchip_headset_remove(struct platform_device *pdev)
171 static int rockchip_headset_suspend(struct platform_device *pdev, pm_message_t state)
173 DBG("%s----%d\n",__FUNCTION__,__LINE__);
174 if(pdata_info->hook_adc_chn >= 0)
176 return rk_headset_adc_suspend(pdev,state);
181 static int rockchip_headset_resume(struct platform_device *pdev)
183 DBG("%s----%d\n",__FUNCTION__,__LINE__);
184 if(pdata_info->hook_adc_chn >= 0)
186 return rk_headset_adc_resume(pdev);
191 static const struct of_device_id rockchip_headset_of_match[] = {
192 { .compatible = "rockchip_headset", },
195 MODULE_DEVICE_TABLE(of, rockchip_headset_of_match);
197 static struct platform_driver rockchip_headset_driver = {
198 .probe = rockchip_headset_probe,
199 .remove = rockchip_headset_remove,
200 .resume = rockchip_headset_resume,
201 .suspend = rockchip_headset_suspend,
203 .name = "rockchip_headset",
204 .owner = THIS_MODULE,
205 .of_match_table = of_match_ptr(rockchip_headset_of_match),
209 static int __init rockchip_headset_init(void)
211 platform_driver_register(&rockchip_headset_driver);
215 static void __exit rockchip_headset_exit(void)
217 platform_driver_unregister(&rockchip_headset_driver);
220 late_initcall(rockchip_headset_init);
221 MODULE_DESCRIPTION("Rockchip Headset Core Driver");
222 MODULE_LICENSE("GPL");