Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Aug 31st, 2010 | Syntax: None | Size: 10.36 KB | Hits: 29 | 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.         printk("MICDUMP: 0x%8.8X, 0x%8.8X, 0x%8.8X\n",
  153.                 *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset),
  154.                 *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x4),
  155.                 *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x8));
  156.  
  157.         /*  enable handset mic */
  158. //      *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset)=0xffff0080 | (on?0x100:0);
  159. //      *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+4)=0;
  160. //      *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+8)=0;
  161.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset)=0x07930093;
  162.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x4)=0x07930193;
  163.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x8)=0x0000FFFF;
  164.  
  165.         printk("ADIEDUMP: 0x%8.8X, 0x%8.8X\n",
  166.                 *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0b8),
  167.                 *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0d0));
  168.  
  169.  
  170.         *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0b8)=0x00000073;//Some kind of PLL
  171.         *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0d0)=0x40000004;//ADIE update
  172.  
  173.         dex.data=0x10;
  174.         msm_proc_comm_wince(&dex,0);
  175.  
  176.         /* some devices needs pm_mic_en */
  177.         if (machine_is_htcdiamond_cdma() || machine_is_htcraphael_cdma() || machine_is_htcraphael_cdma500() || machine_is_htckovsky())
  178.         {
  179.                 int ret;
  180.                 struct {
  181.                         struct rpc_request_hdr hdr;
  182.                         uint32_t data;
  183.                 } req;
  184.  
  185.                 if (!endpoint)
  186.                         endpoint = msm_rpc_connect(0x30000061, 0x0, 0);
  187.                 if (!endpoint) {
  188.                         printk("Couldn't open rpc endpoint\n");
  189.                         return -EIO;
  190.                 }
  191.                 req.data=cpu_to_be32(0x1);
  192.                 ret = msm_rpc_call(endpoint, 0x1c, &req, sizeof(req), 5 * HZ);
  193.         }
  194.  
  195.         return 0;
  196. }
  197.  
  198. EXPORT_SYMBOL(turn_mic_bias_on);
  199.  
  200. static int acoustic_mmap(struct file *file, struct vm_area_struct *vma)
  201. {
  202.         unsigned long pgoff, delta;
  203.         int rc = -EINVAL;
  204.         size_t size;
  205.  
  206.         D("mmap\n");
  207.  
  208.         mutex_lock(&api_lock);
  209.  
  210.         size = vma->vm_end - vma->vm_start;
  211.  
  212.         if (vma->vm_pgoff != 0) {
  213.                 E("mmap failed: page offset %lx\n", vma->vm_pgoff);
  214.                 goto done;
  215.         }
  216.  
  217.         if (!htc_acoustic_vir_addr) {
  218.                 E("mmap failed: smem region not allocated\n");
  219.                 rc = -EIO;
  220.                 goto done;
  221.         }
  222.  
  223.         pgoff = MSM_SHARED_RAM_PHYS +
  224.                 (htc_acoustic_vir_addr - (uint32_t)MSM_SHARED_RAM_BASE);
  225.         delta = PAGE_ALIGN(pgoff) - pgoff;
  226.  
  227.         if (size + delta > HTC_ACOUSTIC_TABLE_SIZE) {
  228.                 E("mmap failed: size %d\n", size);
  229.                 goto done;
  230.         }
  231.  
  232.         pgoff += delta;
  233.         vma->vm_flags |= VM_IO | VM_RESERVED;
  234.  
  235.         rc = io_remap_pfn_range(vma, vma->vm_start, pgoff >> PAGE_SHIFT,
  236.                       size, vma->vm_page_prot);
  237.  
  238.         if (rc < 0)
  239.                 E("mmap failed: remap error %d\n", rc);
  240.  
  241. done:   mutex_unlock(&api_lock);
  242.         return rc;
  243. }
  244.  
  245. static int acoustic_open(struct inode *inode, struct file *file)
  246. {
  247.         int rc = -EIO;
  248.         struct set_smem_req req_smem;
  249.         struct set_smem_rep rep_smem;
  250.  
  251.         D("open\n");
  252.  
  253.         mutex_lock(&api_lock);
  254.  
  255.         BUG_ON(!htc_acoustic_vir_addr);
  256.  
  257.         rc = 0;
  258. done:
  259.         mutex_unlock(&api_lock);
  260.         return rc;
  261. }
  262.  
  263. static int acoustic_release(struct inode *inode, struct file *file)
  264. {
  265.         D("release\n");
  266.         return 0;
  267. }
  268.  
  269. static long acoustic_ioctl(struct file *file, unsigned int cmd,
  270.                            unsigned long arg)
  271. {
  272.         int rc, reply_value;
  273.         struct set_acoustic_req req;
  274.         struct set_acoustic_rep rep;
  275.  
  276.         D("ioctl\n");
  277.  
  278.         mutex_lock(&api_lock);
  279.  
  280.         switch (cmd) {
  281.         case ACOUSTIC_ARM11_DONE:
  282.                 D("ioctl: ACOUSTIC_ARM11_DONE called %d.\n", current->pid);
  283.                 struct msm_dex_command dex;
  284.                 dex.cmd=PCOM_UPDATE_AUDIO;
  285.                 dex.has_data=1;
  286.                 dex.data=0x10;
  287.                 msm_proc_comm_wince(&dex,0);
  288.                 break;
  289.         default:
  290.                 E("ioctl: invalid command\n");
  291.                 rc = -EINVAL;
  292.         }
  293.  
  294.         mutex_unlock(&api_lock);
  295.         return 0;
  296. }
  297.  
  298.  
  299. static struct file_operations acoustic_fops = {
  300.         .owner = THIS_MODULE,
  301.         .open = acoustic_open,
  302.         .release = acoustic_release,
  303.         .mmap = acoustic_mmap,
  304.         .unlocked_ioctl = acoustic_ioctl,
  305. };
  306.  
  307. static struct miscdevice acoustic_misc = {
  308.         .minor = MISC_DYNAMIC_MINOR,
  309.         .name = "htc-acoustic",
  310.         .fops = &acoustic_fops,
  311. };
  312.  
  313. static int __init acoustic_init(void)
  314. {
  315.         switch(__machine_arch_type) {
  316.                 case MACH_TYPE_HTCTOPAZ:
  317.                 case MACH_TYPE_HTCRHODIUM:
  318.                         htc_acoustic_vir_addr=(void *)(MSM_SHARED_RAM_BASE+0xfc300);
  319.                         mic_offset = 0xfb9c0;
  320.                         break;
  321.                 case MACH_TYPE_HTCRAPHAEL:
  322.                 case MACH_TYPE_HTCDIAMOND_CDMA:
  323.                 case MACH_TYPE_HTCDIAMOND:
  324.                 case MACH_TYPE_HTCBLACKSTONE:
  325.                 case MACH_TYPE_HTCRAPHAEL_CDMA:
  326.                 case MACH_TYPE_HTCRAPHAEL_CDMA500:
  327.                 case MACH_TYPE_HTCKOVSKY:
  328.                         mic_offset = 0xfed00;
  329.                         htc_acoustic_vir_addr=(void *)(MSM_SHARED_RAM_BASE+0xfc300);
  330.                         break;
  331.                 default:
  332.                         printk(KERN_ERR "Unsupported device for htc_acoustic driver\n");
  333.                         return -1;
  334.                         break;
  335.         }
  336.         mutex_init(&api_lock);
  337.         mutex_init(&rpc_connect_mutex);
  338.         //No seriously, you don't want htc_acoustic yet.
  339.         //Most likely needs a rewritten libhtc_acoustic
  340.         //return misc_register(&acoustic_misc);
  341.         return 0;
  342. }
  343.  
  344. static void __exit acoustic_exit(void)
  345. {
  346.         misc_deregister(&acoustic_misc);
  347. }
  348.  
  349. module_init(acoustic_init);
  350. module_exit(acoustic_exit);
  351.  
  352. MODULE_AUTHOR("Laurence Chen <Laurence_Chen@htc.com>");
  353. MODULE_DESCRIPTION("HTC acoustic driver");
  354. MODULE_LICENSE("GPL");