Guest
Public paste!

Untitled

By: a guest | Sep 3rd, 2010 | Syntax: None | Size: 7.53 KB | Hits: 35 | Expires: Never
Copy text to clipboard
  1. /* arch/arm/mach-msm/htc_hw.c
  2.  * Author: Joe Hansche <madcoder@gmail.com>
  3.  * Based on vogue-hw.c by Martin Johnson <M.J.Jonson@massey.ac.nz>
  4.  *
  5.  * This software is licensed under the terms of the GNU General Public
  6.  * License version 2, as published by the Free Software Foundation, and
  7.  * may be copied, distributed, and modified under those terms.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  */
  14.  
  15. #include <linux/platform_device.h>
  16. #include <linux/sysfs.h>
  17. #include <linux/io.h>
  18. #include "proc_comm_wince.h"
  19. #include <asm/mach-types.h>
  20. #include <mach/msm_iomap.h>
  21.  
  22. #include "htc_hw.h"
  23. #include "AudioPara.c"
  24. #include <linux/msm_audio.h>
  25. #include <asm/gpio.h>
  26. #include "qdsp5/snd_state.h"
  27.  
  28. #if 1
  29.  #define DHTC(fmt, arg...) printk(KERN_DEBUG "[HTC] %s: " fmt "\n", __FUNCTION__, ## arg)
  30. #else
  31.  #define DHTC(fmt, arg...) do {} while (0)
  32. #endif
  33.  
  34. static htc_hw_pdata_t *htc_hw_pdata;
  35. static int force_cdma=0;
  36. module_param(force_cdma, int, S_IRUGO | S_IWUSR | S_IWGRP);
  37.  
  38. int call_vol=5;
  39. module_param(call_vol, int, S_IRUGO | S_IWUSR | S_IWGRP);
  40.  
  41. static int handsfree=1;
  42. module_param(handsfree, int, S_IRUGO | S_IWUSR | S_IWGRP);
  43.  
  44. extern void micropklt_lcd_ctrl(int);
  45.  
  46. static ssize_t test_store(struct class *class, const char *buf, size_t count)
  47. {
  48.         int v;
  49.         sscanf(buf, "%d", &v);
  50.         micropklt_lcd_ctrl(v);
  51.         return 1;
  52. }
  53.  
  54. static ssize_t flash_store(struct class *class, const char *buf, size_t count)
  55. {
  56.         int v;
  57.         sscanf(buf, "%d", &v);
  58.         gpio_set_value(0x3a, !!v);
  59.         return 1;
  60. }
  61.  
  62. static ssize_t vibrate_store(struct class *class, const char *buf, size_t count)
  63. {
  64.         uint32_t vibrate;
  65.         if (sscanf(buf, "%d", &vibrate) != 1 || vibrate < 0 || vibrate > 0xb22)
  66.                 return -EINVAL;
  67.         if (!htc_hw_pdata->set_vibrate)
  68.                 return -ENOTSUPP;
  69.         if (vibrate == 0) {
  70.                 htc_hw_pdata->set_vibrate(0);
  71.         } else if (vibrate == 1) {
  72.                 htc_hw_pdata->set_vibrate(1);
  73.         } else if (vibrate <= 0xb22) {
  74.                 htc_hw_pdata->set_vibrate(vibrate);
  75.         }
  76.         return count;
  77. }
  78.  
  79. static ssize_t radio_show(struct class *class, char *buf)
  80. {
  81.         char *radio_type = ((machine_is_htcraphael_cdma() || machine_is_htcraphael_cdma500()) ||
  82.                             machine_is_htcdiamond_cdma() || force_cdma) ? "CDMA" : "GSM";
  83.         return sprintf(buf, "%s\n", radio_type);
  84. }
  85.  
  86. static ssize_t machtype_show(struct class *class, char *buf)
  87. {
  88.         return sprintf(buf, "%d\n", machine_arch_type);
  89. }
  90.  
  91. extern unsigned int __amss_version; // amss_para.c
  92. static ssize_t amss_show(struct class *class, char *buf)
  93. {
  94.         return sprintf(buf, "%d\n", __amss_version);
  95. }
  96.  
  97. static ssize_t battery_show(struct class *class, char *buf)
  98. {
  99.         int *values_32;
  100.         short *values_16;
  101.         void *smem_ptr;
  102.         int x;
  103.         struct msm_dex_command dex;
  104.  
  105.         dex.cmd = PCOM_GET_BATTERY_DATA;
  106.         msm_proc_comm_wince(&dex, 0);
  107.  
  108.         smem_ptr = (void *)(MSM_SHARED_RAM_BASE + htc_hw_pdata->battery_smem_offset);
  109.  
  110.         if (htc_hw_pdata->battery_smem_field_size == 4) {
  111.                 values_32 = (int *)(smem_ptr);
  112.                 x = readl(MSM_SHARED_RAM_BASE + 0xfc0e0);
  113.                 return sprintf(buf, "+0xfc0e0: %08x\n"
  114.                                     "%p: %08x %08x %08x %08x %08x\n",
  115.                         x, smem_ptr, values_32[0], values_32[1], values_32[2],
  116.                         values_32[3], values_32[4] );
  117.         } else {
  118.                 values_16 = (short *)(smem_ptr);
  119.                 return sprintf(buf, "%p: %04x %04x %04x %04x %04x\n", smem_ptr,
  120.                         values_16[0], values_16[1], values_16[2], values_16[3], values_16[4]);
  121.         }
  122. }
  123.  
  124. static ssize_t machine_variant_show(struct class *class, char *buf)
  125.  
  126. {
  127.         char machine_variant[20];
  128.         int i;
  129.         if(!machine_is_htcrhodium())
  130.                 return;
  131.        
  132.         for(i=0; i < 20; i++)
  133.         {
  134.                 machine_variant[i] = (char)*(unsigned short*)(MSM_SPL_BASE + 0x81068 + i*2);
  135.         }
  136.         machine_variant[19] = 0;
  137.  
  138.  
  139.         return sprintf(buf, "%s\n", machine_variant);
  140.  
  141. }
  142.  
  143. static struct class_attribute htc_hw_class_attrs[] = {
  144.         __ATTR_RO(battery),
  145.         __ATTR_RO(radio),
  146.         __ATTR_RO(machtype),
  147.         __ATTR_RO(amss),
  148.         __ATTR_RO(machine_variant),
  149.         __ATTR(vibrate, 0222, NULL, vibrate_store),
  150.         __ATTR(flash, 0222, NULL, flash_store),
  151.         __ATTR(test,0222, NULL, test_store),
  152.         __ATTR_NULL,
  153. };
  154.  
  155. static struct class htc_hw_class = {
  156.         .name = "htc_hw",
  157.         .class_attrs = htc_hw_class_attrs,
  158. };
  159.  
  160. static ssize_t gsmphone_show(struct class *class, char *buf) {
  161.         return sprintf(buf, "%d\n", machine_arch_type);
  162. }
  163.  
  164. static void set_audio_parameters(char *name) {
  165.         int i;
  166.         for(i=0;i<ARRAY_SIZE(audioparams);i++)
  167.                 if(!strcmp(name,audioparams[i].name))
  168.                         break;
  169.         if(i==ARRAY_SIZE(audioparams)) {
  170.                 printk("Unknown audio parameter: %s\n",name);
  171.                 return;
  172.         }
  173.         memcpy((void *)(MSM_SHARED_RAM_BASE+0xfc300),audioparams[i].data,0x140);
  174. }
  175.  
  176.  
  177. //htc_hw.c
  178. int turn_mic_bias_on(int on);
  179.  
  180. void msm_setup_audio( )
  181. {
  182.     char *sparam = "";
  183.     pr_info( "+++ %s -- 0x%x\n", __func__, snd_state );
  184.     if( ( snd_state & SND_STATE_INCALL ) )
  185.     {
  186.         sparam = "PHONE_EARCUPLE_VOL5";
  187.         if( snd_state & SND_STATE_SPEAKER )
  188.         {
  189.             sparam = "PHONE_HANDSFREE_VOL5";
  190.         }
  191.  
  192.         if( call_vol >= 0 && call_vol <= 5 )
  193.         {
  194.             sparam[strlen(sparam)-1] = call_vol + '0';
  195.         }
  196.     }
  197.     else if( snd_state & SND_STATE_PLAYBACK )
  198.     {
  199.         sparam = "CE_PLAYBACK_HANDSFREE";
  200.     }
  201.     else if( snd_state & SND_STATE_RECORD )
  202.     {
  203.         sparam = "CE_REC_INC_MIC";
  204.     }
  205.  
  206.     if( strlen(sparam) > 0 )
  207.     {
  208.         pr_info( "%s - Param is: %s\n", __func__,sparam );
  209.         set_audio_parameters( sparam );
  210.         turn_mic_bias_on( (snd_state & SND_STATE_RECORD) ? 1 : 0 );
  211.     }
  212.  
  213.     pr_info( "--- %s -- 0x%x\n", __func__, snd_state );
  214. }
  215.  
  216.  
  217.  
  218. void msm_audio_path(int i) {
  219.  
  220.         switch (i) {
  221.  
  222.                 case 2: // Phone Audio Start
  223.  
  224.  
  225.  
  226.                         snd_state |= (SND_STATE_INCALL | SND_STATE_RECORD);
  227.  
  228.                         pr_info( "++ IN CALL: 0x%x ++\n", snd_state );
  229.  
  230.                         // Let snd_ioctl handle the snd_set_device stuff
  231.  
  232.                         break;
  233.  
  234.                 case 5: // Phone Audio End
  235.  
  236.                         snd_state = SND_STATE_IDLE;
  237.  
  238.                         pr_info( "-- END CALL : 0x%x--\n", snd_state );
  239.  
  240.                         break;
  241.  
  242.         }
  243.  
  244. }
  245.  
  246.  
  247. static ssize_t audio_store(struct class *class,
  248.                                    const char *buf,
  249.                                    size_t count)
  250. {
  251.         uint32_t audio;
  252.         if (sscanf(buf, "%d", &audio) != 1)
  253.                 return -EINVAL;
  254.         msm_audio_path(audio);
  255.         return count;
  256. }
  257.  
  258.  
  259. // these are for compatability with the vogue ril
  260. static struct class_attribute vogue_hw_class_attrs[] = {
  261.         __ATTR(audio, 0222, NULL, audio_store),
  262.         __ATTR_RO(gsmphone),
  263.         __ATTR_NULL,
  264. };
  265.  
  266. static struct class vogue_hw_class = {
  267.         .name = "vogue_hw",
  268.         .class_attrs = vogue_hw_class_attrs,
  269. };
  270.  
  271. static int __init htc_hw_probe(struct platform_device *pdev)
  272. {
  273.         int ret;
  274.         htc_hw_pdata = (htc_hw_pdata_t *)pdev->dev.platform_data;
  275.         ret = class_register(&htc_hw_class);
  276.         ret = class_register(&vogue_hw_class);
  277.         if (ret)
  278.                 printk(KERN_ERR "%s: class init failed: %d\n", __func__, ret);
  279.         DHTC("done");
  280.         return ret;
  281. }
  282.  
  283. static struct platform_driver htc_hw_driver = {
  284.         .probe = htc_hw_probe,
  285.         .driver = {
  286.                 .name = "htc_hw",
  287.                 .owner = THIS_MODULE,
  288.         },
  289. };
  290.  
  291. static int __init htc_hw_init(void)
  292. {
  293.         DHTC("Initializing HTC hardware platform driver");
  294.         return platform_driver_register(&htc_hw_driver);
  295. }
  296.  
  297. module_init(htc_hw_init);
  298. MODULE_DESCRIPTION("HTC hardware platform driver");
  299. MODULE_AUTHOR("Joe Hansche <madcoder@gmail.com>");
  300. MODULE_LICENSE("GPL");