Guest

Untitled

By: a guest on Sep 1st, 2010  |  syntax: None  |  size: 6.93 KB  |  hits: 46  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  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 msm_audio_path(int i) {
  165.         char* sparameter= "PHONE_HANDSFREE_VOL5";
  166.         if(!handsfree)
  167.                 strcpy(sparameter, "PHONE_EARCUPLE_VOL5");
  168.         if(call_vol>=0 && call_vol<=5)
  169.                 sparameter[strlen(sparameter)-1]=call_vol+'0';
  170.        
  171.         struct msm_dex_command dex;
  172.         dex.cmd=PCOM_UPDATE_AUDIO;
  173.         dex.has_data=1;
  174.  
  175.         switch (i) {
  176.                 case 2: // Phone Audio Start
  177.                   printk(KERN_ERR "PARAMETER: %s\n", sparameter);
  178.                 //      set_audio_parameters(sparameter);
  179.                 //      dex.data=0x01;
  180.                 //      msm_proc_comm_wince(&dex,0);
  181.  
  182.                         turn_mic_bias_on(1);
  183.                         snd_ini();
  184.                         snd_set_device(0,SND_MUTE_UNMUTED,SND_MUTE_UNMUTED); /* "HANDSET" */
  185.                         break;
  186.                 case 5: // Phone Audio End
  187.                   //      set_audio_parameters("CE_PLAYBACK_HANDSFREE");
  188.                   //    dex.data=0x01;
  189.                   //    msm_proc_comm_wince(&dex,0);
  190.                         //Really turn mic off?
  191.                         //Some soft apps might want that too.
  192.                         turn_mic_bias_on(0);
  193.  
  194.                         snd_ini();
  195.                         snd_set_device(1,SND_MUTE_MUTED,SND_MUTE_MUTED); /* "SPEAKER" */
  196.                         break;
  197.         }
  198. }
  199.  
  200. static ssize_t audio_store(struct class *class,
  201.                                    const char *buf,
  202.                                    size_t count)
  203. {
  204.         uint32_t audio;
  205.         if (sscanf(buf, "%d", &audio) != 1)
  206.                 return -EINVAL;
  207.         printk("Sound: %d\n",audio);
  208.         msm_audio_path(audio);
  209.         return count;
  210. }
  211.  
  212.  
  213. // these are for compatability with the vogue ril
  214. static struct class_attribute vogue_hw_class_attrs[] = {
  215.         __ATTR(audio, 0222, NULL, audio_store),
  216.         __ATTR_RO(gsmphone),
  217.         __ATTR_NULL,
  218. };
  219.  
  220. static struct class vogue_hw_class = {
  221.         .name = "vogue_hw",
  222.         .class_attrs = vogue_hw_class_attrs,
  223. };
  224.  
  225. static int __init htc_hw_probe(struct platform_device *pdev)
  226. {
  227.         int ret;
  228.         htc_hw_pdata = (htc_hw_pdata_t *)pdev->dev.platform_data;
  229.         ret = class_register(&htc_hw_class);
  230.         ret = class_register(&vogue_hw_class);
  231.         if (ret)
  232.                 printk(KERN_ERR "%s: class init failed: %d\n", __func__, ret);
  233.         DHTC("done");
  234.         return ret;
  235. }
  236.  
  237. static struct platform_driver htc_hw_driver = {
  238.         .probe = htc_hw_probe,
  239.         .driver = {
  240.                 .name = "htc_hw",
  241.                 .owner = THIS_MODULE,
  242.         },
  243. };
  244.  
  245. static int __init htc_hw_init(void)
  246. {
  247.         DHTC("Initializing HTC hardware platform driver");
  248.         return platform_driver_register(&htc_hw_driver);
  249. }
  250.  
  251. module_init(htc_hw_init);
  252. MODULE_DESCRIPTION("HTC hardware platform driver");
  253. MODULE_AUTHOR("Joe Hansche <madcoder@gmail.com>");
  254. MODULE_LICENSE("GPL");