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.
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
19 #include <linux/i2c.h>
20 #include <linux/spi/spi.h>
21 #include <linux/platform_device.h>
22 #include <linux/errno.h>
23 #include <linux/err.h>
24 #include <linux/debugfs.h>
25 #include "rk_headset.h"
26 #include <linux/of_gpio.h>
27 #include <linux/gpio.h>
28 #include <linux/iio/consumer.h>
32 #define DBG(x...) printk(x)
34 #define DBG(x...) do { } while (0)
37 struct rk_headset_pdata *pdata_info;
39 static int rockchip_headset_probe(struct platform_device *pdev)
41 struct device_node *node = pdev->dev.of_node;
42 struct rk_headset_pdata *pdata;
44 enum of_gpio_flags flags;
46 pdata = kzalloc(sizeof(struct rk_headset_pdata), GFP_KERNEL);
48 printk("%s failed to allocate driver data\n",__FUNCTION__);
51 memset(pdata,0,sizeof(struct rk_headset_pdata));
55 ret = of_get_named_gpio_flags(node, "headset_gpio", 0, &flags);
57 printk("%s() Can not read property headset_gpio\n", __FUNCTION__);
60 pdata->headset_gpio = ret;
61 ret = devm_gpio_request(&pdev->dev, pdata->headset_gpio, "headset_gpio");
63 printk("%s() devm_gpio_request headset_gpio request ERROR\n", __FUNCTION__);
67 ret = gpio_direction_input(pdata->headset_gpio);
69 printk("%s() gpio_direction_input headset_gpio set ERROR\n", __FUNCTION__);
73 pdata->headset_insert_type = (flags & OF_GPIO_ACTIVE_LOW) ? HEADSET_IN_LOW : HEADSET_IN_HIGH;
77 ret = of_get_named_gpio_flags(node, "hook_gpio", 0, &pdata->hook_gpio);
79 DBG("%s() Can not read property hook_gpio\n", __FUNCTION__);
82 pdata->chan = iio_channel_get(&pdev->dev, NULL);
83 if (IS_ERR(pdata->chan))
86 printk("%s() have not set adc chan\n", __FUNCTION__);
89 ret = of_property_read_u32(node, "hook_down_type", &pdata->hook_down_type);
91 DBG("%s() have not set hook_down_type,set >hook< insert type low level default\n", __FUNCTION__);
92 pdata->hook_down_type = 0;
94 ret = devm_gpio_request(&pdev->dev, pdata->hook_gpio, "hook_gpio");
96 printk("%s() devm_gpio_request hook_gpio request ERROR\n", __FUNCTION__);
99 ret = gpio_direction_input(pdata->hook_gpio);
101 printk("%s() gpio_direction_input hook_gpio set ERROR\n", __FUNCTION__);
106 #ifdef CONFIG_MODEM_MIC_SWITCH
108 ret = of_get_named_gpio_flags(node, "mic_switch_gpio", 0, &flags);
110 DBG("%s() Can not read property mic_switch_gpio\n", __FUNCTION__);
112 pdata->headset_gpio = ret;
113 ret = of_property_read_u32(node, "hp_mic_io_value", &pdata->hp_mic_io_value);
115 DBG("%s() have not set hp_mic_io_value ,so default set pull down low level\n", __FUNCTION__);
116 pdata->hp_mic_io_value = 0;
118 ret = of_property_read_u32(node, "main_mic_io_value", &pdata->main_mic_io_value);
120 DBG("%s() have not set main_mic_io_value ,so default set pull down low level\n", __FUNCTION__);
121 pdata->main_mic_io_value = 1;
126 ret = of_property_read_u32(node, "rockchip,headset_wakeup", &pdata->headset_wakeup);
128 pdata->headset_wakeup = 1;
130 if(pdata->chan != NULL)
132 printk("%s() headset have hook adc mode\n",__FUNCTION__);
133 ret = rk_headset_adc_probe(pdev,pdata);
141 {//hook interrupt mode and not hook
142 printk("%s() headset have %s mode\n",__FUNCTION__,pdata->hook_gpio?"interrupt hook":"no hook");
143 ret = rk_headset_probe(pdev,pdata);
156 static int rockchip_headset_remove(struct platform_device *pdev)
163 static int rockchip_headset_suspend(struct platform_device *pdev, pm_message_t state)
165 if(pdata_info->chan != 0)
167 return rk_headset_adc_suspend(pdev,state);
172 static int rockchip_headset_resume(struct platform_device *pdev)
174 if(pdata_info->chan != 0)
176 return rk_headset_adc_resume(pdev);
181 static const struct of_device_id rockchip_headset_of_match[] = {
182 { .compatible = "rockchip_headset", },
185 MODULE_DEVICE_TABLE(of, rockchip_headset_of_match);
187 static struct platform_driver rockchip_headset_driver = {
188 .probe = rockchip_headset_probe,
189 .remove = rockchip_headset_remove,
190 .resume = rockchip_headset_resume,
191 .suspend = rockchip_headset_suspend,
193 .name = "rockchip_headset",
194 .owner = THIS_MODULE,
195 .of_match_table = of_match_ptr(rockchip_headset_of_match),
199 static int __init rockchip_headset_init(void)
201 platform_driver_register(&rockchip_headset_driver);
205 static void __exit rockchip_headset_exit(void)
207 platform_driver_unregister(&rockchip_headset_driver);
209 late_initcall(rockchip_headset_init);
210 MODULE_DESCRIPTION("Rockchip Headset Core Driver");
211 MODULE_LICENSE("GPL");