1 #include <linux/input.h>
\r
2 #include <linux/module.h>
\r
3 #include <linux/init.h>
\r
4 #include <linux/interrupt.h>
\r
5 #include <linux/kernel.h>
\r
6 #include <linux/fcntl.h>
\r
7 #include <linux/delay.h>
\r
8 #include <linux/device.h>
\r
9 #include <linux/miscdevice.h>
\r
10 #include <asm/types.h>
\r
11 #include <mach/gpio.h>
\r
12 #include <mach/iomux.h>
\r
13 #include <linux/platform_device.h>
\r
14 #include <asm/uaccess.h>
\r
15 #include <linux/wait.h>
\r
16 #include "modem_sound.h"
\r
18 #define DBG(x...) printk(KERN_INFO x)
\r
25 static struct modem_sound_data *modem_sound;
\r
26 #if defined(CONFIG_SND_RK_SOC_RK2928)|| defined(CONFIG_SND_RK29_SOC_RK610)
\r
27 extern void call_set_spk(int on);
\r
31 #if defined(CONFIG_MODEM_MIC_SWITCH)
\r
32 extern void Modem_Mic_switch(int value);
\r
33 extern void Modem_Mic_release(void);
\r
34 void Modem_Sound_Mic_switch(int value)
\r
36 Modem_Mic_switch(value);
\r
38 void Modem_Sound_Mic_release()
\r
40 Modem_Mic_release();
\r
43 void Modem_Sound_Mic_switch(int value)
\r
46 void Modem_Sound_Mic_release()
\r
51 int modem_sound_spkctl(int status)
\r
53 if(status == ENABLE)
\r
54 gpio_direction_output(modem_sound->spkctl_io,GPIO_HIGH);//modem_sound->spkctl_io? GPIO_HIGH:GPIO_LOW);
\r
56 gpio_direction_output(modem_sound->spkctl_io,GPIO_LOW); //modem_sound->spkctl_io? GPIO_LOW:GPIO_HIGH);
\r
61 static void modem_sound_delay_power_downup(struct work_struct *work)
\r
63 struct modem_sound_data *pdata = container_of(work, struct modem_sound_data, work);
\r
64 if (pdata == NULL) {
\r
65 printk("%s: pdata = NULL\n", __func__);
\r
69 down(&pdata->power_sem);
\r
70 up(&pdata->power_sem);
\r
73 static int modem_sound_open(struct inode *inode, struct file *filp)
\r
75 DBG("modem_sound_open\n");
\r
80 static ssize_t modem_sound_read(struct file *filp, char __user *ptr, size_t size, loff_t *pos)
\r
83 printk("%s: user space address is NULL\n", __func__);
\r
87 static long modem_sound_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
\r
90 struct modem_sound_data *pdata = modem_sound;
\r
92 DBG("modem_sound_ioctl: cmd = %d arg = %ld\n",cmd, arg);
\r
94 ret = down_interruptible(&pdata->power_sem);
\r
96 printk("%s: down power_sem error ret = %ld\n", __func__, ret);
\r
101 case IOCTL_MODEM_EAR_PHOEN:
\r
102 DBG("modem_sound_ioctl: MODEM_EAR_PHONE\n");
\r
103 Modem_Sound_Mic_switch(MAIN_MIC);
\r
105 modem_sound_spkctl(DISABLE);
\r
107 case IOCTL_MODEM_SPK_PHONE:
\r
108 DBG("modem_sound_ioctl: MODEM_SPK_PHONE\n");
\r
109 Modem_Sound_Mic_switch(MAIN_MIC);
\r
111 modem_sound_spkctl(ENABLE);
\r
113 case IOCTL_MODEM_HP_WITHMIC_PHONE:
\r
114 DBG("modem_sound_ioctl: MODEM_HP_WITHMIC_PHONE\n");
\r
115 Modem_Sound_Mic_switch(HP_MIC);
\r
117 modem_sound_spkctl(DISABLE);
\r
120 case IOCTL_MODEM_BT_PHONE:
\r
122 modem_sound_spkctl(DISABLE);
\r
123 DBG("modem_sound_ioctl: MODEM_BT_PHONE\n");
\r
125 case IOCTL_MODEM_STOP_PHONE:
\r
126 DBG("modem_sound_ioctl: MODEM_STOP_PHONE\n");
\r
127 Modem_Sound_Mic_release();
\r
129 modem_sound_spkctl(ENABLE);
\r
131 case IOCTL_MODEM_HP_NOMIC_PHONE:
\r
132 DBG("modem_sound_ioctl: MODEM_HP_NOMIC_PHONE\n");
\r
133 Modem_Sound_Mic_switch(MAIN_MIC);
\r
135 modem_sound_spkctl(DISABLE);
\r
140 printk("unknown ioctl cmd!\n");
\r
145 up(&pdata->power_sem);
\r
150 static int modem_sound_release(struct inode *inode, struct file *filp)
\r
152 DBG("modem_sound_release\n");
\r
157 static struct file_operations modem_sound_fops = {
\r
158 .owner = THIS_MODULE,
\r
159 .open = modem_sound_open,
\r
160 .read = modem_sound_read,
\r
161 .unlocked_ioctl = modem_sound_ioctl,
\r
162 .release = modem_sound_release,
\r
165 static struct miscdevice modem_sound_dev =
\r
167 .minor = MISC_DYNAMIC_MINOR,
\r
168 .name = "modem_sound",
\r
169 .fops = &modem_sound_fops,
\r
172 static int modem_sound_probe(struct platform_device *pdev)
\r
175 struct modem_sound_data *pdata = pdev->dev.platform_data;
\r
179 ret = misc_register(&modem_sound_dev);
\r
181 printk("modem register err!\n");
\r
185 sema_init(&pdata->power_sem,1);
\r
186 pdata->wq = create_freezable_workqueue("modem_sound");
\r
187 INIT_WORK(&pdata->work, modem_sound_delay_power_downup);
\r
188 modem_sound = pdata;
\r
189 printk("%s:modem sound initialized\n",__FUNCTION__);
\r
194 static int modem_sound_suspend(struct platform_device *pdev, pm_message_t state)
\r
196 struct modem_sound_data *pdata = pdev->dev.platform_data;
\r
199 printk("%s: pdata = NULL ...... \n", __func__);
\r
202 printk("%s\n",__FUNCTION__);
\r
206 static int modem_sound_resume(struct platform_device *pdev)
\r
208 struct modem_sound_data *pdata = pdev->dev.platform_data;
\r
211 printk("%s: pdata = NULL ...... \n", __func__);
\r
214 printk("%s\n",__FUNCTION__);
\r
218 static int modem_sound_remove(struct platform_device *pdev)
\r
220 struct modem_sound_data *pdata = pdev->dev.platform_data;
\r
224 misc_deregister(&modem_sound_dev);
\r
229 static struct platform_driver modem_sound_driver = {
\r
230 .probe = modem_sound_probe,
\r
231 .remove = modem_sound_remove,
\r
232 .suspend = modem_sound_suspend,
\r
233 .resume = modem_sound_resume,
\r
235 .name = "modem_sound",
\r
236 .owner = THIS_MODULE,
\r
240 static int __init modem_sound_init(void)
\r
242 return platform_driver_register(&modem_sound_driver);
\r
245 static void __exit modem_sound_exit(void)
\r
247 platform_driver_unregister(&modem_sound_driver);
\r
250 module_init(modem_sound_init);
\r
251 module_exit(modem_sound_exit);
\r
252 MODULE_DESCRIPTION ("modem sound driver");
\r
253 MODULE_LICENSE("GPL");
\r