gp2ap30_light.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2012, Samsung Electronics Co. Ltd. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  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/init.h>
  16. #include <linux/module.h>
  17. #include "adsp.h"
  18. #define VENDOR "Sharp"
  19. #define CHIP_ID "GP2AP30"
  20. static ssize_t light_vendor_show(struct device *dev,
  21. struct device_attribute *attr, char *buf)
  22. {
  23. return sprintf(buf, "%s\n", VENDOR);
  24. }
  25. static ssize_t light_name_show(struct device *dev,
  26. struct device_attribute *attr, char *buf)
  27. {
  28. return sprintf(buf, "%s\n", CHIP_ID);
  29. }
  30. static ssize_t light_lux_show(struct device *dev,
  31. struct device_attribute *attr, char *buf)
  32. {
  33. /* struct cm3323_p *data = dev_get_drvdata(dev);
  34. return snprintf(buf, PAGE_SIZE, "%u,%u,%u,%u\n",
  35. data->color[0], data->color[1],
  36. data->color[2], data->color[3]);*/
  37. return 0;
  38. }
  39. static ssize_t light_data_show(struct device *dev,
  40. struct device_attribute *attr, char *buf)
  41. {
  42. struct adsp_data *data = dev_get_drvdata(dev);
  43. if( !(data->data_ready_flag & 1 << ADSP_FACTORY_MODE_LIGHT) ){
  44. adsp_unicast(ADSP_FACTORY_MODE_LIGHT,NETLINK_MESSAGE_GET_RAW_DATA,0,0);
  45. }
  46. while( !(data->data_ready_flag & 1 << ADSP_FACTORY_MODE_LIGHT) )
  47. msleep(20);
  48. return snprintf(buf, PAGE_SIZE, "%d,%d\n",
  49. data->sensor_data[ADSP_FACTORY_MODE_LIGHT].y,
  50. data->sensor_data[ADSP_FACTORY_MODE_LIGHT].z);
  51. return 0;
  52. }
  53. int light_factory_init(struct adsp_data *data)
  54. {
  55. return 0;
  56. }
  57. int light_factory_exit(struct adsp_data *data)
  58. {
  59. return 0;
  60. }
  61. int light_factory_receive_data(struct adsp_data *data)
  62. {
  63. pr_err("(%s): factory \n", __func__);
  64. return 0;
  65. }
  66. static struct adsp_fac_ctl adsp_fact_cb = {
  67. .init_fnc = light_factory_init,
  68. .exit_fnc = light_factory_exit,
  69. .receive_data_fnc = light_factory_receive_data
  70. };
  71. static DEVICE_ATTR(name, 0664, light_name_show, NULL);
  72. static DEVICE_ATTR(vendor, 0664, light_vendor_show, NULL);
  73. static DEVICE_ATTR(lux, 0664, light_lux_show, NULL);
  74. static DEVICE_ATTR(raw_data, 0664, light_data_show, NULL);
  75. static struct device_attribute *light_attrs[] = {
  76. &dev_attr_name,
  77. &dev_attr_vendor,
  78. &dev_attr_lux,
  79. &dev_attr_raw_data,
  80. NULL,
  81. };
  82. static int __devinit gp2alight_factory_init(void)
  83. {
  84. adsp_factory_register("light_sensor",ADSP_FACTORY_MODE_LIGHT,light_attrs,&adsp_fact_cb);
  85. pr_err("(%s): factory \n", __func__);
  86. return 0;
  87. }
  88. static void __devexit gp2alight_factory_exit(void)
  89. {
  90. pr_err("(%s): factory \n", __func__);
  91. }
  92. module_init(gp2alight_factory_init);
  93. module_exit(gp2alight_factory_exit);