Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Sep 2nd, 2010 | Syntax: None | Size: 7.45 KB | Hits: 31 | Expires: Never
This paste has a previous version, view the difference. 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.  
  27. #if 1
  28.  #define DHTC(fmt, arg...) printk(KERN_DEBUG "[HTC] %s: " fmt "\n", __FUNCTION__, ## arg)
  29. #else
  30.  #define DHTC(fmt, arg...) do {} while (0)
  31. #endif
  32.  
  33. static htc_hw_pdata_t *htc_hw_pdata;
  34. static int force_cdma=0;
  35. module_param(force_cdma, int, S_IRUGO | S_IWUSR | S_IWGRP);
  36.  
  37. static int call_vol=5;
  38. module_param(call_vol, int, S_IRUGO | S_IWUSR | S_IWGRP);
  39.  
  40. static int handsfree=1;
  41. module_param(handsfree, int, S_IRUGO | S_IWUSR | S_IWGRP);
  42.  
  43. extern void micropklt_lcd_ctrl(int);
  44.  
  45. static ssize_t test_store(struct class *class, const char *buf, size_t count)
  46. {
  47.         int v;
  48.         sscanf(buf, "%d", &v);
  49.         micropklt_lcd_ctrl(v);
  50.         return 1;
  51. }
  52.  
  53. static ssize_t flash_store(struct class *class, const char *buf, size_t count)
  54. {
  55.         int v;
  56.         sscanf(buf, "%d", &v);
  57.         gpio_set_value(0x3a, !!v);
  58.         return 1;
  59. }
  60.  
  61. static ssize_t vibrate_store(struct class *class, const char *buf, size_t count)
  62. {
  63.         uint32_t vibrate;
  64.         if (sscanf(buf, "%d", &vibrate) != 1 || vibrate < 0 || vibrate > 0xb22)
  65.                 return -EINVAL;
  66.         if (!htc_hw_pdata->set_vibrate)
  67.                 return -ENOTSUPP;
  68.         if (vibrate == 0) {
  69.                 htc_hw_pdata->set_vibrate(0);
  70.         } else if (vibrate == 1) {
  71.                 htc_hw_pdata->set_vibrate(1);
  72.         } else if (vibrate <= 0xb22) {
  73.                 htc_hw_pdata->set_vibrate(vibrate);
  74.         }
  75.         return count;
  76. }
  77.  
  78. static ssize_t radio_show(struct class *class, char *buf)
  79. {
  80.         char *radio_type = ((machine_is_htcraphael_cdma() || machine_is_htcraphael_cdma500()) ||
  81.                             machine_is_htcdiamond_cdma() || force_cdma) ? "CDMA" : "GSM";
  82.         return sprintf(buf, "%s\n", radio_type);
  83. }
  84.  
  85. static ssize_t machtype_show(struct class *class, char *buf)
  86. {
  87.         return sprintf(buf, "%d\n", machine_arch_type);
  88. }
  89.  
  90. extern unsigned int __amss_version; // amss_para.c
  91. static ssize_t amss_show(struct class *class, char *buf)
  92. {
  93.         return sprintf(buf, "%d\n", __amss_version);
  94. }
  95.  
  96. static ssize_t battery_show(struct class *class, char *buf)
  97. {
  98.         int *values_32;
  99.         short *values_16;
  100.         void *smem_ptr;
  101.         int x;
  102.         struct msm_dex_command dex;
  103.  
  104.         dex.cmd = PCOM_GET_BATTERY_DATA;
  105.         msm_proc_comm_wince(&dex, 0);
  106.  
  107.         smem_ptr = (void *)(MSM_SHARED_RAM_BASE + htc_hw_pdata->battery_smem_offset);
  108.  
  109.         if (htc_hw_pdata->battery_smem_field_size == 4) {
  110.                 values_32 = (int *)(smem_ptr);
  111.                 x = readl(MSM_SHARED_RAM_BASE + 0xfc0e0);
  112.                 return sprintf(buf, "+0xfc0e0: %08x\n"
  113.                                     "%p: %08x %08x %08x %08x %08x\n",
  114.                         x, smem_ptr, values_32[0], values_32[1], values_32[2],
  115.                         values_32[3], values_32[4] );
  116.         } else {
  117.                 values_16 = (short *)(smem_ptr);
  118.                 return sprintf(buf, "%p: %04x %04x %04x %04x %04x\n", smem_ptr,
  119.                         values_16[0], values_16[1], values_16[2], values_16[3], values_16[4]);
  120.         }
  121. }
  122.  
  123. static struct class_attribute htc_hw_class_attrs[] = {
  124.         __ATTR_RO(battery),
  125.         __ATTR_RO(radio),
  126.         __ATTR_RO(machtype),
  127.         __ATTR_RO(amss),
  128.         __ATTR(vibrate, 0222, NULL, vibrate_store),
  129.         __ATTR(flash, 0222, NULL, flash_store),
  130.         __ATTR(test,0222, NULL, test_store),
  131.         __ATTR_NULL,
  132. };
  133.  
  134. static struct class htc_hw_class = {
  135.         .name = "htc_hw",
  136.         .class_attrs = htc_hw_class_attrs,
  137. };
  138.  
  139. static ssize_t gsmphone_show(struct class *class, char *buf) {
  140.         return sprintf(buf, "%d\n", machine_arch_type);
  141. }
  142.  
  143. static void set_audio_parameters(char *name) {
  144.         int i;
  145.         for(i=0;i<ARRAY_SIZE(audioparams);i++)
  146.                 if(!strcmp(name,audioparams[i].name))
  147.                         break;
  148.         if(i==ARRAY_SIZE(audioparams)) {
  149.                 printk("Unknown audio parameter: %s\n",name);
  150.                 return;
  151.         }
  152.         memcpy((void *)(MSM_SHARED_RAM_BASE+0xfc300),audioparams[i].data,0x140);
  153. }
  154. #ifdef CONFIG_MSM_ADSP
  155. void snd_set_device(int device,int ear_mute, int mic_mute);
  156. int snd_ini();
  157. #else
  158. void snd_set_device(int device, int ear_mute, int mic_mute) {};
  159. int snd_ini() {}
  160. #endif
  161. //htc_hw.c
  162. int turn_mic_bias_on(int on);
  163.  
  164. void set_mic_path( )
  165. {
  166.      pr_info( "+++%s\n", __func__ );
  167.  
  168.      set_audio_parameters("CE_REC_INC_MIC");
  169.      turn_mic_bias_on(1);
  170.  
  171.      snd_ini();
  172.      snd_set_device(0,SND_MUTE_MUTED,SND_MUTE_UNMUTED); /* "HANDSET" */
  173.      pr_info( "---%s\n", __func__ );
  174. }
  175.  
  176. static int last_path=0;
  177. void msm_audio_path_vupdate() {
  178.         char* sparameter= "PHONE_HANDSFREE_VOL5";
  179.         int i = last_path;
  180.  
  181.         printk("Sound: %d, Vol: %d, Handsfree: %d\n",i, call_vol, handsfree);
  182.         if(!handsfree)
  183.                 strcpy(sparameter, "PHONE_EARCUPLE_VOL5");
  184.  
  185.         if(call_vol>=0 && call_vol<=5)
  186.                 sparameter[strlen(sparameter)-1]=call_vol+'0';
  187.        
  188.         struct msm_dex_command dex;
  189.         dex.cmd=PCOM_UPDATE_AUDIO;
  190.         dex.has_data=1;
  191.  
  192.         switch (i) {
  193.                 case 2: // Phone Audio Start
  194.                   printk(KERN_ERR "PARAMETER: %s\n", sparameter);
  195.                         set_audio_parameters(sparameter);
  196.                         //dex.data=0x10;
  197.                         //msm_proc_comm_wince(&dex,0);
  198.  
  199.                         turn_mic_bias_on(1);
  200.                         snd_ini();
  201.                         snd_set_device(0,SND_MUTE_UNMUTED,SND_MUTE_UNMUTED); /* "HANDSET" */
  202.                         break;
  203.                 case 5: // Phone Audio End
  204.                         set_audio_parameters("CE_PLAYBACK_HANDSFREE");
  205.                         //dex.data=0x10;
  206.                         //msm_proc_comm_wince(&dex,0);
  207.                         //Really turn mic off?
  208.                         //Some soft apps might want that too.
  209.                         turn_mic_bias_on(0);
  210.  
  211.                         snd_ini();
  212.                         snd_set_device(1,SND_MUTE_MUTED,SND_MUTE_MUTED); /* "SPEAKER" */
  213.                         break;
  214.         }
  215. }
  216.  
  217. void msm_audio_path(int i){
  218.         last_path = i;
  219.  
  220.         msm_audio_path_vupdate();
  221. }
  222.  
  223.  
  224. void platform_vol(int vol)
  225. {
  226.         call_vol = vol;
  227.         msm_audio_path_vupdate();
  228. }
  229.  
  230. static ssize_t audio_store(struct class *class,
  231.                                    const char *buf,
  232.                                    size_t count)
  233. {
  234.         uint32_t audio;
  235.         if (sscanf(buf, "%d", &audio) != 1)
  236.                 return -EINVAL;
  237.         msm_audio_path(audio);
  238.         return count;
  239. }
  240.  
  241.  
  242. // these are for compatability with the vogue ril
  243. static struct class_attribute vogue_hw_class_attrs[] = {
  244.         __ATTR(audio, 0222, NULL, audio_store),
  245.         __ATTR_RO(gsmphone),
  246.         __ATTR_NULL,
  247. };
  248.  
  249. static struct class vogue_hw_class = {
  250.         .name = "vogue_hw",
  251.         .class_attrs = vogue_hw_class_attrs,
  252. };
  253.  
  254. static int __init htc_hw_probe(struct platform_device *pdev)
  255. {
  256.         int ret;
  257.         htc_hw_pdata = (htc_hw_pdata_t *)pdev->dev.platform_data;
  258.         ret = class_register(&htc_hw_class);
  259.         ret = class_register(&vogue_hw_class);
  260.         if (ret)
  261.                 printk(KERN_ERR "%s: class init failed: %d\n", __func__, ret);
  262.         DHTC("done");
  263.         return ret;
  264. }
  265.  
  266. static struct platform_driver htc_hw_driver = {
  267.         .probe = htc_hw_probe,
  268.         .driver = {
  269.                 .name = "htc_hw",
  270.                 .owner = THIS_MODULE,
  271.         },
  272. };
  273.  
  274. static int __init htc_hw_init(void)
  275. {
  276.         DHTC("Initializing HTC hardware platform driver");
  277.         return platform_driver_register(&htc_hw_driver);
  278. }
  279.  
  280. module_init(htc_hw_init);
  281. MODULE_DESCRIPTION("HTC hardware platform driver");
  282. MODULE_AUTHOR("Joe Hansche <madcoder@gmail.com>");
  283. MODULE_LICENSE("GPL");