Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Sep 2nd, 2010 | Syntax: None | Size: 14.44 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.  
  160.         //TODO: this number should be there when not playing/recording
  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 __init init_mic_bias_on()
  201. {
  202.         struct msm_dex_command dex;
  203.         unsigned int i;
  204.         printk("init mic bias on\n");
  205.  
  206.         unsigned int audparms[] = {0x301000E1,0x00000001,0x00000001,0x00000000,0x00000000,
  207.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  208.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  209.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  210.                                 0x00000000,0x00000001,0x00000000,0x00000000,0x00000000,
  211.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  212.                                 0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,
  213.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  214.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  215.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  216.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  217.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  218.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x40000005,
  219.                                 0x00004000,0x00004000,0x7F650000,0x07800000,0x1B0CFF9A,
  220.                                 0x01ECF333,0x200AFFEE,0x00007F65,0x0000ED00,0x7F650000,
  221.                                 0x07800000,0x1B0CFF9A,0x01ECF333,0x200AFFEE,0x7FFF7F65,
  222.                                 0x7FFF0800,0x0000149F,0x08000014,0x20002000,0x004600FA,
  223.                                 0x02FF0001,0x00200040,0x00404650,0x080041A0,0x4E200063,
  224.                                 0x00014E20,0x17704A38,0x01000000,0x04000100,0x04000200,
  225.                                 0x02580300,0x1CA80190,0x2EE001C2,0x00000FA0,0x00000000,
  226.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  227.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  228.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  229.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  230.                                 0x00000000,0x00020000,0x00020002,0x00000002,0x00000000,
  231.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  232.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  233.                                 0x00000000,0x00000000,0x00000000,0x00020000,0x00020002,
  234.                                 0xFFFF0002,0x00000000,0x00000000,0x00000000,0x00000000,
  235.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  236.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  237.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  238.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  239.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  240.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  241.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  242.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  243.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  244.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  245.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  246.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  247.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  248.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  249.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  250.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  251.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  252.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  253.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
  254.                                    
  255.         for(i=0; i < 175; i++)
  256.         {
  257.                 writel(audparms[i],MSM_SHARED_RAM_BASE + 0xfc200 + i*4);
  258.         }
  259.  
  260.        
  261.         printk("DBGTABLE 0x%X, 0x%X, 0x%X, 0x%X\n", audparms[0x138>>2], audparms[0x188>>2], audparms[0x228>>2], audparms[0x230>>2]);
  262.         dex.cmd=PCOM_UPDATE_AUDIO;
  263.         dex.has_data=1;
  264.  
  265.         printk("MICDUMP: 0x%8.8X, 0x%8.8X, 0x%8.8X\n",
  266.                 *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset),
  267.                 *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x4),
  268.                 *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x8));
  269.  
  270.         //TODO: this number should be there when not playing/recording
  271.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset)=0x07930093;
  272.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x4)=0x07930193;
  273.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x8)=0x0000FFFF;
  274.  
  275.         printk("ADIEDUMP: 0x%8.8X, 0x%8.8X\n",
  276.                 *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0b8),
  277.                 *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0d0));
  278.  
  279.  
  280.         *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0b8)=0x00000073;//Some kind of PLL
  281.         *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0d0)=0x40000004;//ADIE update
  282.  
  283.         dex.data=0x10;
  284.         msm_proc_comm_wince(&dex,0);
  285.  
  286.         return 0;
  287. }
  288.  
  289.  
  290. static int acoustic_mmap(struct file *file, struct vm_area_struct *vma)
  291. {
  292.         unsigned long pgoff, delta;
  293.         int rc = -EINVAL;
  294.         size_t size;
  295.  
  296.         D("mmap\n");
  297.  
  298.         mutex_lock(&api_lock);
  299.  
  300.         size = vma->vm_end - vma->vm_start;
  301.  
  302.         if (vma->vm_pgoff != 0) {
  303.                 E("mmap failed: page offset %lx\n", vma->vm_pgoff);
  304.                 goto done;
  305.         }
  306.  
  307.         if (!htc_acoustic_vir_addr) {
  308.                 E("mmap failed: smem region not allocated\n");
  309.                 rc = -EIO;
  310.                 goto done;
  311.         }
  312.  
  313.         pgoff = MSM_SHARED_RAM_PHYS +
  314.                 (htc_acoustic_vir_addr - (uint32_t)MSM_SHARED_RAM_BASE);
  315.         delta = PAGE_ALIGN(pgoff) - pgoff;
  316.  
  317.         if (size + delta > HTC_ACOUSTIC_TABLE_SIZE) {
  318.                 E("mmap failed: size %d\n", size);
  319.                 goto done;
  320.         }
  321.  
  322.         pgoff += delta;
  323.         vma->vm_flags |= VM_IO | VM_RESERVED;
  324.  
  325.         rc = io_remap_pfn_range(vma, vma->vm_start, pgoff >> PAGE_SHIFT,
  326.                       size, vma->vm_page_prot);
  327.  
  328.         if (rc < 0)
  329.                 E("mmap failed: remap error %d\n", rc);
  330.  
  331. done:   mutex_unlock(&api_lock);
  332.         return rc;
  333. }
  334.  
  335. static int acoustic_open(struct inode *inode, struct file *file)
  336. {
  337.         int rc = -EIO;
  338.         struct set_smem_req req_smem;
  339.         struct set_smem_rep rep_smem;
  340.  
  341.         D("open\n");
  342.  
  343.         mutex_lock(&api_lock);
  344.  
  345.         BUG_ON(!htc_acoustic_vir_addr);
  346.  
  347.         rc = 0;
  348. done:
  349.         mutex_unlock(&api_lock);
  350.         return rc;
  351. }
  352.  
  353. static int acoustic_release(struct inode *inode, struct file *file)
  354. {
  355.         D("release\n");
  356.         return 0;
  357. }
  358.  
  359. static long acoustic_ioctl(struct file *file, unsigned int cmd,
  360.                            unsigned long arg)
  361. {
  362.         int rc, reply_value;
  363.         struct set_acoustic_req req;
  364.         struct set_acoustic_rep rep;
  365.  
  366.         D("ioctl\n");
  367.  
  368.         mutex_lock(&api_lock);
  369.  
  370.         switch (cmd) {
  371.         case ACOUSTIC_ARM11_DONE:
  372.                 D("ioctl: ACOUSTIC_ARM11_DONE called %d.\n", current->pid);
  373.                 struct msm_dex_command dex;
  374.                 dex.cmd=PCOM_UPDATE_AUDIO;
  375.                 dex.has_data=1;
  376.                 dex.data=0x10;
  377.                 msm_proc_comm_wince(&dex,0);
  378.                 break;
  379.         default:
  380.                 E("ioctl: invalid command\n");
  381.                 rc = -EINVAL;
  382.         }
  383.  
  384.         mutex_unlock(&api_lock);
  385.         return 0;
  386. }
  387.  
  388.  
  389. static struct file_operations acoustic_fops = {
  390.         .owner = THIS_MODULE,
  391.         .open = acoustic_open,
  392.         .release = acoustic_release,
  393.         .mmap = acoustic_mmap,
  394.         .unlocked_ioctl = acoustic_ioctl,
  395. };
  396.  
  397. static struct miscdevice acoustic_misc = {
  398.         .minor = MISC_DYNAMIC_MINOR,
  399.         .name = "htc-acoustic",
  400.         .fops = &acoustic_fops,
  401. };
  402.  
  403. static int __init acoustic_init(void)
  404. {
  405.         switch(__machine_arch_type) {
  406.                 case MACH_TYPE_HTCTOPAZ:
  407.                 case MACH_TYPE_HTCRHODIUM:
  408.                         htc_acoustic_vir_addr=(void *)(MSM_SHARED_RAM_BASE+0xfc300);
  409.                         mic_offset = 0xfb9c0;
  410.                         break;
  411.                 case MACH_TYPE_HTCRAPHAEL:
  412.                 case MACH_TYPE_HTCDIAMOND_CDMA:
  413.                 case MACH_TYPE_HTCDIAMOND:
  414.                 case MACH_TYPE_HTCBLACKSTONE:
  415.                 case MACH_TYPE_HTCRAPHAEL_CDMA:
  416.                 case MACH_TYPE_HTCRAPHAEL_CDMA500:
  417.                 case MACH_TYPE_HTCKOVSKY:
  418.                         mic_offset = 0xfed00;
  419.                         htc_acoustic_vir_addr=(void *)(MSM_SHARED_RAM_BASE+0xfc300);
  420.                         break;
  421.                 default:
  422.                         printk(KERN_ERR "Unsupported device for htc_acoustic driver\n");
  423.                         return -1;
  424.                         break;
  425.         }
  426.         mutex_init(&api_lock);
  427.         mutex_init(&rpc_connect_mutex);
  428.         //No seriously, you don't want htc_acoustic yet.
  429.         //Most likely needs a rewritten libhtc_acoustic
  430.         //return misc_register(&acoustic_misc);
  431.         return 0;
  432. }
  433.  
  434. static void __exit acoustic_exit(void)
  435. {
  436.         misc_deregister(&acoustic_misc);
  437. }
  438.  
  439. module_init(acoustic_init);
  440. module_exit(acoustic_exit);
  441.  
  442. late_initcall(init_mic_bias_on);
  443.  
  444. MODULE_AUTHOR("Laurence Chen <Laurence_Chen@htc.com>");
  445. MODULE_DESCRIPTION("HTC acoustic driver");
  446. MODULE_LICENSE("GPL");