Guest
Public paste!

Woz

By: a guest | Aug 31st, 2010 | Syntax: None | Size: 9.78 KB | Hits: 34 | Expires: Never
Copy text to clipboard
  1. /* arch/arm/mach-msm/htc_acoustic.c
  2.  *
  3.  * Copyright (C) 2007-2008 HTC Corporation
  4.  * Author: Laurence Chen <Laurence_Chen@htc.com>
  5.  *
  6.  * This software is licensed under the terms of the GNU General Public
  7.  * License version 2, as published by the Free Software Foundation, and
  8.  * may be copied, distributed, and modified under those terms.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  */
  16. #include <linux/device.h>
  17. #include <linux/fs.h>
  18. #include <linux/module.h>
  19. #include <linux/miscdevice.h>
  20. #include <linux/mm.h>
  21. #include <linux/err.h>
  22. #include <linux/delay.h>
  23. #include <linux/kernel.h>
  24. #include <linux/uaccess.h>
  25. #include <linux/io.h>
  26. #include <linux/mutex.h>
  27.  
  28. #include <mach/msm_smd.h>
  29. #include <mach/msm_rpcrouter.h>
  30. #include <mach/msm_iomap.h>
  31. #include <asm/mach-types.h>
  32. #include "proc_comm_wince.h"
  33.  
  34. #include "smd_private.h"
  35.  
  36. #define ACOUSTIC_IOCTL_MAGIC 'p'
  37. #define ACOUSTIC_ARM11_DONE     _IOW(ACOUSTIC_IOCTL_MAGIC, 22, unsigned int)
  38.  
  39. #define HTCRPOG 0x30100002
  40. #define HTCVERS 0
  41. #define ONCRPC_SET_MIC_BIAS_PROC       (1)
  42. #define ONCRPC_ACOUSTIC_INIT_PROC      (5)
  43. #define ONCRPC_ALLOC_ACOUSTIC_MEM_PROC (6)
  44.  
  45. #define HTC_ACOUSTIC_TABLE_SIZE        (0x10000)
  46.  
  47. #define D(fmt, args...) printk(KERN_INFO "htc-acoustic: "fmt, ##args)
  48. #define E(fmt, args...) printk(KERN_ERR "htc-acoustic: "fmt, ##args)
  49.  
  50. struct set_smem_req {
  51.         struct rpc_request_hdr hdr;
  52.         uint32_t size;
  53. };
  54.  
  55. struct set_smem_rep {
  56.         struct rpc_reply_hdr hdr;
  57.         int n;
  58. };
  59.  
  60. struct set_acoustic_req {
  61.         struct rpc_request_hdr hdr;
  62. };
  63.  
  64. struct set_acoustic_rep {
  65.         struct rpc_reply_hdr hdr;
  66.         int n;
  67. };
  68.  
  69. static uint32_t htc_acoustic_vir_addr;
  70. static struct msm_rpc_endpoint *endpoint = NULL;
  71. static struct mutex api_lock;
  72. static struct mutex rpc_connect_mutex;
  73. static unsigned int mic_offset;
  74.  
  75. int turn_mic_bias_on(int on)
  76. {
  77.         struct msm_dex_command dex;
  78.         unsigned int i;
  79.         printk("Turnin mic bias on %d\n", on);
  80.  
  81.         printk("acoustic dump: you know you want it\n");
  82.         printk("unsigned int audparms[] = {\n");
  83. /*
  84.         for(i=0; i < 1024; i++)
  85.         {
  86.                 if(i%5==0)
  87.                         printk("\t");
  88.                 printk("0x%8.8X,",readl(MSM_SHARED_RAM_BASE + 0xfc200 + i*4));
  89.                 if(i%5==4)
  90.                         printk("\n");
  91.         }
  92. */
  93.         unsigned int audparms[] = {0x301000E1,0x00000001,0x00000001,0x00000000,0x00000000,
  94.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  95.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  96.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  97.                                 0x00000000,0x00000001,0x00000000,0x00000000,0x00000000,
  98.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  99.                                 0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,
  100.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  101.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  102.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  103.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  104.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  105.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x40000005,
  106.                                 0x00004000,0x00004000,0x7F650000,0x07800000,0x1B0CFF9A,
  107.                                 0x01ECF333,0x200AFFEE,0x00007F65,0x0000ED00,0x7F650000,
  108.                                 0x07800000,0x1B0CFF9A,0x01ECF333,0x200AFFEE,0x7FFF7F65,
  109.                                 0x7FFF0800,0x0000149F,0x08000014,0x20002000,0x004600FA,
  110.                                 0x02FF0001,0x00200040,0x00404650,0x080041A0,0x4E200063,
  111.                                 0x00014E20,0x17704A38,0x01000000,0x04000100,0x04000200,
  112.                                 0x02580300,0x1CA80190,0x2EE001C2,0x00000FA0,0x00000000,
  113.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  114.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  115.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  116.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  117.                                 0x00000000,0x00020000,0x00020002,0x00000002,0x00000000,
  118.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  119.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  120.                                 0x00000000,0x00000000,0x00000000,0x00020000,0x00020002,
  121.                                 0xFFFF0002,0x00000000,0x00000000,0x00000000,0x00000000,
  122.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  123.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  124.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  125.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  126.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  127.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  128.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  129.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  130.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  131.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  132.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  133.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  134.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  135.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  136.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  137.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  138.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  139.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  140.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
  141.                                    
  142.         for(i=0; i < 175; i++)
  143.         {
  144.                 writel(audparms[i],MSM_SHARED_RAM_BASE + 0xfc200 + i*4);
  145.         }
  146.  
  147.        
  148.         printk("DBGTABLE 0x%X, 0x%X, 0x%X, 0x%X\n", audparms[0x138>>2], audparms[0x188>>2], audparms[0x228>>2], audparms[0x230>>2]);
  149.         dex.cmd=PCOM_UPDATE_AUDIO;
  150.         dex.has_data=1;
  151.  
  152.         /*  enable handset mic */
  153.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset)=0xffff0080 | (on?0x100:0);
  154.         //*(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset)=0x93009307;
  155.         //*(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x4)=0x93019307;
  156.         //*(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x8)=0xFFFF0000;
  157.  
  158.         dex.data=0x10;
  159.         msm_proc_comm_wince(&dex,0);
  160.  
  161.         /* some devices needs pm_mic_en */
  162.         if (machine_is_htcdiamond_cdma() || machine_is_htcraphael_cdma() || machine_is_htcraphael_cdma500() || machine_is_htckovsky())
  163.         {
  164.                 int ret;
  165.                 struct {
  166.                         struct rpc_request_hdr hdr;
  167.                         uint32_t data;
  168.                 } req;
  169.  
  170.                 if (!endpoint)
  171.                         endpoint = msm_rpc_connect(0x30000061, 0x0, 0);
  172.                 if (!endpoint) {
  173.                         printk("Couldn't open rpc endpoint\n");
  174.                         return -EIO;
  175.                 }
  176.                 req.data=cpu_to_be32(0x1);
  177.                 ret = msm_rpc_call(endpoint, 0x1c, &req, sizeof(req), 5 * HZ);
  178.         }
  179.  
  180.         return 0;
  181. }
  182.  
  183. EXPORT_SYMBOL(turn_mic_bias_on);
  184.  
  185. static int acoustic_mmap(struct file *file, struct vm_area_struct *vma)
  186. {
  187.         unsigned long pgoff, delta;
  188.         int rc = -EINVAL;
  189.         size_t size;
  190.  
  191.         D("mmap\n");
  192.  
  193.         mutex_lock(&api_lock);
  194.  
  195.         size = vma->vm_end - vma->vm_start;
  196.  
  197.         if (vma->vm_pgoff != 0) {
  198.                 E("mmap failed: page offset %lx\n", vma->vm_pgoff);
  199.                 goto done;
  200.         }
  201.  
  202.         if (!htc_acoustic_vir_addr) {
  203.                 E("mmap failed: smem region not allocated\n");
  204.                 rc = -EIO;
  205.                 goto done;
  206.         }
  207.  
  208.         pgoff = MSM_SHARED_RAM_PHYS +
  209.                 (htc_acoustic_vir_addr - (uint32_t)MSM_SHARED_RAM_BASE);
  210.         delta = PAGE_ALIGN(pgoff) - pgoff;
  211.  
  212.         if (size + delta > HTC_ACOUSTIC_TABLE_SIZE) {
  213.                 E("mmap failed: size %d\n", size);
  214.                 goto done;
  215.         }
  216.  
  217.         pgoff += delta;
  218.         vma->vm_flags |= VM_IO | VM_RESERVED;
  219.  
  220.         rc = io_remap_pfn_range(vma, vma->vm_start, pgoff >> PAGE_SHIFT,
  221.                       size, vma->vm_page_prot);
  222.  
  223.         if (rc < 0)
  224.                 E("mmap failed: remap error %d\n", rc);
  225.  
  226. done:   mutex_unlock(&api_lock);
  227.         return rc;
  228. }
  229.  
  230. static int acoustic_open(struct inode *inode, struct file *file)
  231. {
  232.         int rc = -EIO;
  233.         struct set_smem_req req_smem;
  234.         struct set_smem_rep rep_smem;
  235.  
  236.         D("open\n");
  237.  
  238.         mutex_lock(&api_lock);
  239.  
  240.         BUG_ON(!htc_acoustic_vir_addr);
  241.  
  242.         rc = 0;
  243. done:
  244.         mutex_unlock(&api_lock);
  245.         return rc;
  246. }
  247.  
  248. static int acoustic_release(struct inode *inode, struct file *file)
  249. {
  250.         D("release\n");
  251.         return 0;
  252. }
  253.  
  254. static long acoustic_ioctl(struct file *file, unsigned int cmd,
  255.                            unsigned long arg)
  256. {
  257.         int rc, reply_value;
  258.         struct set_acoustic_req req;
  259.         struct set_acoustic_rep rep;
  260.  
  261.         D("ioctl\n");
  262.  
  263.         mutex_lock(&api_lock);
  264.  
  265.         switch (cmd) {
  266.         case ACOUSTIC_ARM11_DONE:
  267.                 D("ioctl: ACOUSTIC_ARM11_DONE called %d.\n", current->pid);
  268.                 struct msm_dex_command dex;
  269.                 dex.cmd=PCOM_UPDATE_AUDIO;
  270.                 dex.has_data=1;
  271.                 dex.data=0x10;
  272.                 msm_proc_comm_wince(&dex,0);
  273.                 break;
  274.         default:
  275.                 E("ioctl: invalid command\n");
  276.                 rc = -EINVAL;
  277.         }
  278.  
  279.         mutex_unlock(&api_lock);
  280.         return 0;
  281. }
  282.  
  283.  
  284. static struct file_operations acoustic_fops = {
  285.         .owner = THIS_MODULE,
  286.         .open = acoustic_open,
  287.         .release = acoustic_release,
  288.         .mmap = acoustic_mmap,
  289.         .unlocked_ioctl = acoustic_ioctl,
  290. };
  291.  
  292. static struct miscdevice acoustic_misc = {
  293.         .minor = MISC_DYNAMIC_MINOR,
  294.         .name = "htc-acoustic",
  295.         .fops = &acoustic_fops,
  296. };
  297.  
  298. static int __init acoustic_init(void)
  299. {
  300.         switch(__machine_arch_type) {
  301.                 case MACH_TYPE_HTCTOPAZ:
  302.                 case MACH_TYPE_HTCRHODIUM:
  303.                         htc_acoustic_vir_addr=(void *)(MSM_SHARED_RAM_BASE+0xfc300);
  304.                         mic_offset = 0xfb9c0;
  305.                         break;
  306.                 case MACH_TYPE_HTCRAPHAEL:
  307.                 case MACH_TYPE_HTCDIAMOND_CDMA:
  308.                 case MACH_TYPE_HTCDIAMOND:
  309.                 case MACH_TYPE_HTCBLACKSTONE:
  310.                 case MACH_TYPE_HTCRAPHAEL_CDMA:
  311.                 case MACH_TYPE_HTCRAPHAEL_CDMA500:
  312.                 case MACH_TYPE_HTCKOVSKY:
  313.                         mic_offset = 0xfed00;
  314.                         htc_acoustic_vir_addr=(void *)(MSM_SHARED_RAM_BASE+0xfc300);
  315.                         break;
  316.                 default:
  317.                         printk(KERN_ERR "Unsupported device for htc_acoustic driver\n");
  318.                         return -1;
  319.                         break;
  320.         }
  321.         mutex_init(&api_lock);
  322.         mutex_init(&rpc_connect_mutex);
  323.         //No seriously, you don't want htc_acoustic yet.
  324.         //Most likely needs a rewritten libhtc_acoustic
  325.         //return misc_register(&acoustic_misc);
  326.         return 0;
  327. }
  328.  
  329. static void __exit acoustic_exit(void)
  330. {
  331.         misc_deregister(&acoustic_misc);
  332. }
  333.  
  334. module_init(acoustic_init);
  335. module_exit(acoustic_exit);
  336.  
  337. MODULE_AUTHOR("Laurence Chen <Laurence_Chen@htc.com>");
  338. MODULE_DESCRIPTION("HTC acoustic driver");
  339. MODULE_LICENSE("GPL");