Guest
Public paste!

Untitled

By: a guest | Sep 2nd, 2010 | Syntax: None | Size: 10.93 KB | Hits: 31 | 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.  
  76. int turn_mic_bias_on(int on)
  77. {
  78.         struct msm_dex_command dex;
  79.         unsigned int i;
  80.         printk("Turnin mic bias on %d\n", on);
  81.  
  82.         printk("MICDUMP: 0x%8.8X, 0x%8.8X, 0x%8.8X\n",
  83.                 *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset),
  84.                 *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x4),
  85.                 *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x8));
  86.  
  87.         /*  enable handset mic */
  88.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset)=0xffff0080 | (on?0x100:0);
  89.  
  90.         //TODO: this number should be there when not playing/recording
  91. //      *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset)=0x07930093;
  92.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x4)=0x07930193;
  93.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x8)=0x0000FFFF;
  94.  
  95.         printk("ADIEDUMP: 0x%8.8X, 0x%8.8X\n",
  96.                 *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0b8),
  97.                 *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0d0));
  98.  
  99.         dex.cmd=PCOM_UPDATE_AUDIO;
  100.         dex.has_data=1;
  101.  
  102.  
  103.         dex.data=0x10;
  104.         msm_proc_comm_wince(&dex,0);
  105.  
  106.  
  107.         /* some devices needs pm_mic_en */
  108.         if (machine_is_htcdiamond_cdma() || machine_is_htcraphael_cdma() || machine_is_htcraphael_cdma500() || machine_is_htckovsky())
  109.         {
  110.                 int ret;
  111.                 struct {
  112.                         struct rpc_request_hdr hdr;
  113.                         uint32_t data;
  114.                 } req;
  115.  
  116.                 if (!endpoint)
  117.                         endpoint = msm_rpc_connect(0x30000061, 0x0, 0);
  118.                 if (!endpoint) {
  119.                         printk("Couldn't open rpc endpoint\n");
  120.                         return -EIO;
  121.                 }
  122.                 req.data=cpu_to_be32(0x1);
  123.                 ret = msm_rpc_call(endpoint, 0x1c, &req, sizeof(req), 5 * HZ);
  124.         }
  125.  
  126.         return 0;
  127. }
  128.  
  129. EXPORT_SYMBOL(turn_mic_bias_on);
  130.  
  131. static int __init init_mic_bias_on()
  132. {
  133.         struct msm_dex_command dex;
  134.         unsigned int i;
  135.         printk("init mic bias on\n");
  136.  
  137.         unsigned int audparms[] = {0x301000E1,0x00000001,0x00000001,0x00000000,0x00000000,
  138.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  139.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  140.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  141.                                 0x00000000,0x00000001,0x00000000,0x00000000,0x00000000,
  142.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  143.                                 0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,
  144.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  145.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  146.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  147.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  148.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  149.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x40000005,
  150.                                 0x00004000,0x00004000,0x7F650000,0x07800000,0x1B0CFF9A,
  151.                                 0x01ECF333,0x200AFFEE,0x00007F65,0x0000ED00,0x7F650000,
  152.                                 0x07800000,0x1B0CFF9A,0x01ECF333,0x200AFFEE,0x7FFF7F65,
  153.                                 0x7FFF0800,0x0000149F,0x08000014,0x20002000,0x004600FA,
  154.                                 0x02FF0001,0x00200040,0x00404650,0x080041A0,0x4E200063,
  155.                                 0x00014E20,0x17704A38,0x01000000,0x04000100,0x04000200,
  156.                                 0x02580300,0x1CA80190,0x2EE001C2,0x00000FA0,0x00000000,
  157.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  158.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  159.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  160.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  161.                                 0x00000000,0x00020000,0x00020002,0x00000002,0x00000000,
  162.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  163.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  164.                                 0x00000000,0x00000000,0x00000000,0x00020000,0x00020002,
  165.                                 0xFFFF0002,0x00000000,0x00000000,0x00000000,0x00000000,
  166.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  167.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  168.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  169.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  170.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  171.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  172.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  173.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  174.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  175.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  176.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  177.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  178.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  179.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  180.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  181.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  182.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  183.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
  184.                                 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
  185.                                    
  186.         for(i=0; i < 175; i++)
  187.         {
  188.                 writel(audparms[i],MSM_SHARED_RAM_BASE + 0xfc200 + i*4);
  189.         }
  190.  
  191.        
  192.         printk("DBGTABLE 0x%X, 0x%X, 0x%X, 0x%X\n", audparms[0x138>>2], audparms[0x188>>2], audparms[0x228>>2], audparms[0x230>>2]);
  193.         dex.cmd=PCOM_UPDATE_AUDIO;
  194.         dex.has_data=1;
  195.  
  196.         printk("MICDUMP: 0x%8.8X, 0x%8.8X, 0x%8.8X\n",
  197.                 *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset),
  198.                 *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x4),
  199.                 *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x8));
  200.  
  201.         //TODO: this number should be there when not playing/recording
  202.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset)=0x07930093;
  203.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x4)=0x07930193;
  204.         *(unsigned *)(MSM_SHARED_RAM_BASE+mic_offset+0x8)=0x0000FFFF;
  205.  
  206.         printk("ADIEDUMP: 0x%8.8X, 0x%8.8X\n",
  207.                 *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0b8),
  208.                 *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0d0));
  209.  
  210.  
  211.         *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0b8)=0x00000073;//Some kind of PLL
  212.         *(unsigned *)(MSM_SHARED_RAM_BASE+0xfc0d0)=0x40000004;//ADIE update
  213.  
  214.         dex.data=0x10;
  215.         msm_proc_comm_wince(&dex,0);
  216.  
  217.         return 0;
  218. }
  219.  
  220.  
  221. static int acoustic_mmap(struct file *file, struct vm_area_struct *vma)
  222. {
  223.         unsigned long pgoff, delta;
  224.         int rc = -EINVAL;
  225.         size_t size;
  226.  
  227.         D("mmap\n");
  228.  
  229.         mutex_lock(&api_lock);
  230.  
  231.         size = vma->vm_end - vma->vm_start;
  232.  
  233.         if (vma->vm_pgoff != 0) {
  234.                 E("mmap failed: page offset %lx\n", vma->vm_pgoff);
  235.                 goto done;
  236.         }
  237.  
  238.         if (!htc_acoustic_vir_addr) {
  239.                 E("mmap failed: smem region not allocated\n");
  240.                 rc = -EIO;
  241.                 goto done;
  242.         }
  243.  
  244.         pgoff = MSM_SHARED_RAM_PHYS +
  245.                 (htc_acoustic_vir_addr - (uint32_t)MSM_SHARED_RAM_BASE);
  246.         delta = PAGE_ALIGN(pgoff) - pgoff;
  247.  
  248.         if (size + delta > HTC_ACOUSTIC_TABLE_SIZE) {
  249.                 E("mmap failed: size %d\n", size);
  250.                 goto done;
  251.         }
  252.  
  253.         pgoff += delta;
  254.         vma->vm_flags |= VM_IO | VM_RESERVED;
  255.  
  256.         rc = io_remap_pfn_range(vma, vma->vm_start, pgoff >> PAGE_SHIFT,
  257.                       size, vma->vm_page_prot);
  258.  
  259.         if (rc < 0)
  260.                 E("mmap failed: remap error %d\n", rc);
  261.  
  262. done:   mutex_unlock(&api_lock);
  263.         return rc;
  264. }
  265.  
  266. static int acoustic_open(struct inode *inode, struct file *file)
  267. {
  268.         int rc = -EIO;
  269.         struct set_smem_req req_smem;
  270.         struct set_smem_rep rep_smem;
  271.  
  272.         D("open\n");
  273.  
  274.         mutex_lock(&api_lock);
  275.  
  276.         BUG_ON(!htc_acoustic_vir_addr);
  277.  
  278.         rc = 0;
  279. done:
  280.         mutex_unlock(&api_lock);
  281.         return rc;
  282. }
  283.  
  284. static int acoustic_release(struct inode *inode, struct file *file)
  285. {
  286.         D("release\n");
  287.         return 0;
  288. }
  289.  
  290. static long acoustic_ioctl(struct file *file, unsigned int cmd,
  291.                            unsigned long arg)
  292. {
  293.         int rc, reply_value;
  294.         struct set_acoustic_req req;
  295.         struct set_acoustic_rep rep;
  296.  
  297.         D("ioctl\n");
  298.  
  299.         mutex_lock(&api_lock);
  300.  
  301.         switch (cmd) {
  302.         case ACOUSTIC_ARM11_DONE:
  303.                 D("ioctl: ACOUSTIC_ARM11_DONE called %d.\n", current->pid);
  304.                 struct msm_dex_command dex;
  305.                 dex.cmd=PCOM_UPDATE_AUDIO;
  306.                 dex.has_data=1;
  307.                 dex.data=0x10;
  308.                 msm_proc_comm_wince(&dex,0);
  309.                 break;
  310.         default:
  311.                 E("ioctl: invalid command\n");
  312.                 rc = -EINVAL;
  313.         }
  314.  
  315.         mutex_unlock(&api_lock);
  316.         return 0;
  317. }
  318.  
  319.  
  320. static struct file_operations acoustic_fops = {
  321.         .owner = THIS_MODULE,
  322.         .open = acoustic_open,
  323.         .release = acoustic_release,
  324.         .mmap = acoustic_mmap,
  325.         .unlocked_ioctl = acoustic_ioctl,
  326. };
  327.  
  328. static struct miscdevice acoustic_misc = {
  329.         .minor = MISC_DYNAMIC_MINOR,
  330.         .name = "htc-acoustic",
  331.         .fops = &acoustic_fops,
  332. };
  333.  
  334. static int __init acoustic_init(void)
  335. {
  336.         switch(__machine_arch_type) {
  337.                 case MACH_TYPE_HTCTOPAZ:
  338.                 case MACH_TYPE_HTCRHODIUM:
  339.                         htc_acoustic_vir_addr=(void *)(MSM_SHARED_RAM_BASE+0xfc300);
  340.                         mic_offset = 0xfb9c0;
  341.                         break;
  342.                 case MACH_TYPE_HTCRAPHAEL:
  343.                 case MACH_TYPE_HTCDIAMOND_CDMA:
  344.                 case MACH_TYPE_HTCDIAMOND:
  345.                 case MACH_TYPE_HTCBLACKSTONE:
  346.                 case MACH_TYPE_HTCRAPHAEL_CDMA:
  347.                 case MACH_TYPE_HTCRAPHAEL_CDMA500:
  348.                 case MACH_TYPE_HTCKOVSKY:
  349.                         mic_offset = 0xfed00;
  350.                         htc_acoustic_vir_addr=(void *)(MSM_SHARED_RAM_BASE+0xfc300);
  351.                         break;
  352.                 default:
  353.                         printk(KERN_ERR "Unsupported device for htc_acoustic driver\n");
  354.                         return -1;
  355.                         break;
  356.         }
  357.         mutex_init(&api_lock);
  358.         mutex_init(&rpc_connect_mutex);
  359.         //No seriously, you don't want htc_acoustic yet.
  360.         //Most likely needs a rewritten libhtc_acoustic
  361.         //return misc_register(&acoustic_misc);
  362.         return 0;
  363. }
  364.  
  365. static void __exit acoustic_exit(void)
  366. {
  367.         misc_deregister(&acoustic_misc);
  368. }
  369.  
  370. module_init(acoustic_init);
  371. module_exit(acoustic_exit);
  372.  
  373. late_initcall(init_mic_bias_on);
  374.  
  375. MODULE_AUTHOR("Laurence Chen <Laurence_Chen@htc.com>");
  376. MODULE_DESCRIPTION("HTC acoustic driver");
  377. MODULE_LICENSE("GPL");