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
22 #define MODEM_EARPHOEN 0 //ÌýͲµç»°
\r
23 #define MODEM_HANDFREE 1 //ÃâÌá
\r
24 #define MODEM_HPPHONE 2 //¶ú»úµç»°
\r
25 #define MODEM_BTPHONE 3 //À¶ÑÀµç»°
\r
26 #define MODEM_STOP_PHONE 4 //ֹͣͨ»°
\r
31 static struct modem_sound_data *modem_sound;
\r
32 #ifdef CONFIG_SND_RK_SOC_RK2928
\r
33 extern void call_set_spk(bool on);
\r
35 int modem_sound_spkctl(int status)
\r
37 if(status == ENABLE)
\r
38 gpio_direction_output(modem_sound->spkctl_io,GPIO_HIGH);//modem_sound->spkctl_io? GPIO_HIGH:GPIO_LOW);
\r
40 gpio_direction_output(modem_sound->spkctl_io,GPIO_LOW); //modem_sound->spkctl_io? GPIO_LOW:GPIO_HIGH);
\r
45 static void modem_sound_delay_power_downup(struct work_struct *work)
\r
47 struct modem_sound_data *pdata = container_of(work, struct modem_sound_data, work);
\r
48 if (pdata == NULL) {
\r
49 printk("%s: pdata = NULL\n", __func__);
\r
53 down(&pdata->power_sem);
\r
54 up(&pdata->power_sem);
\r
57 static int modem_sound_open(struct inode *inode, struct file *filp)
\r
59 DBG("modem_sound_open\n");
\r
64 static ssize_t modem_sound_read(struct file *filp, char __user *ptr, size_t size, loff_t *pos)
\r
67 printk("%s: user space address is NULL\n", __func__);
\r
71 static long modem_sound_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
\r
74 struct modem_sound_data *pdata = modem_sound;
\r
76 DBG("modem_sound_ioctl: cmd = %d arg = %ld\n",cmd, arg);
\r
78 ret = down_interruptible(&pdata->power_sem);
\r
80 printk("%s: down power_sem error ret = %ld\n", __func__, ret);
\r
85 case MODEM_EARPHOEN:
\r
86 DBG("modem_sound_ioctl: MODEM_EAR_PHONE\n");
\r
88 modem_sound_spkctl(DISABLE);
\r
90 case MODEM_HANDFREE:
\r
91 DBG("modem_sound_ioctl: MODEM_SPK_PHONE\n");
\r
93 modem_sound_spkctl(ENABLE);
\r
96 DBG("modem_sound_ioctl: MODEM_HP_PHONE\n");
\r
98 modem_sound_spkctl(DISABLE);
\r
101 case MODEM_BTPHONE:
\r
103 modem_sound_spkctl(DISABLE);
\r
104 DBG("modem_sound_ioctl: MODEM_BT_PHONE\n");
\r
106 case MODEM_STOP_PHONE:
\r
107 DBG("modem_sound_ioctl: MODEM_STOP_PHONE\n");
\r
112 printk("unknown ioctl cmd!\n");
\r
113 up(&pdata->power_sem);
\r
118 up(&pdata->power_sem);
\r
123 static int modem_sound_release(struct inode *inode, struct file *filp)
\r
125 DBG("modem_sound_release\n");
\r
130 static struct file_operations modem_sound_fops = {
\r
131 .owner = THIS_MODULE,
\r
132 .open = modem_sound_open,
\r
133 .read = modem_sound_read,
\r
134 .unlocked_ioctl = modem_sound_ioctl,
\r
135 .release = modem_sound_release,
\r
138 static struct miscdevice modem_sound_dev =
\r
140 .minor = MISC_DYNAMIC_MINOR,
\r
141 .name = "modem_sound",
\r
142 .fops = &modem_sound_fops,
\r
145 static int modem_sound_probe(struct platform_device *pdev)
\r
148 struct modem_sound_data *pdata = pdev->dev.platform_data;
\r
152 ret = misc_register(&modem_sound_dev);
\r
154 printk("modem register err!\n");
\r
158 sema_init(&pdata->power_sem,1);
\r
159 pdata->wq = create_freezable_workqueue("modem_sound");
\r
160 INIT_WORK(&pdata->work, modem_sound_delay_power_downup);
\r
161 modem_sound = pdata;
\r
162 printk("%s:modem sound initialized\n",__FUNCTION__);
\r
167 static int modem_sound_suspend(struct platform_device *pdev, pm_message_t state)
\r
169 struct modem_sound_data *pdata = pdev->dev.platform_data;
\r
172 printk("%s: pdata = NULL ...... \n", __func__);
\r
175 printk("%s\n",__FUNCTION__);
\r
179 static int modem_sound_resume(struct platform_device *pdev)
\r
181 struct modem_sound_data *pdata = pdev->dev.platform_data;
\r
184 printk("%s: pdata = NULL ...... \n", __func__);
\r
187 printk("%s\n",__FUNCTION__);
\r
191 static int modem_sound_remove(struct platform_device *pdev)
\r
193 struct modem_sound_data *pdata = pdev->dev.platform_data;
\r
197 misc_deregister(&modem_sound_dev);
\r
202 static struct platform_driver modem_sound_driver = {
\r
203 .probe = modem_sound_probe,
\r
204 .remove = modem_sound_remove,
\r
205 .suspend = modem_sound_suspend,
\r
206 .resume = modem_sound_resume,
\r
208 .name = "modem_sound",
\r
209 .owner = THIS_MODULE,
\r
213 static int __init modem_sound_init(void)
\r
215 return platform_driver_register(&modem_sound_driver);
\r
218 static void __exit modem_sound_exit(void)
\r
220 platform_driver_unregister(&modem_sound_driver);
\r
223 module_init(modem_sound_init);
\r
224 module_exit(modem_sound_exit);
\r
225 MODULE_DESCRIPTION ("modem sound driver");
\r
226 MODULE_LICENSE("GPL");
\r