#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined(CONFIG_PM_WAKELOCKS) #include #else #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include "adc_detect_gms.h" /*---------------------------------------------------------------------- static variable defination ----------------------------------------------------------------------*/ //#define gms_detection_DEVNAME "gms_detection_dev" #define EN_DEBUG #if defined(EN_DEBUG) #define TRACE_FUNC printk("[gms_detection_dev] function: %s, line: %d \n", __func__, __LINE__); #define gms_detection_DEBUG printk #else #define TRACE_FUNC(x,...) #define gms_detection_DEBUG(x,...) #endif struct iio_channel *air_channel = NULL; static int gms_adc_vol_max_value; static int gms_adc_vol_min_value; int gms_detection_getadc_v(void); int gms_detection_getadc(void); //prize add by lipengpeng 20210229 start int gms_detection_getadc_v(void){ int ret = 0; int val = 0; if (!IS_ERR_OR_NULL(air_channel)){ ret = iio_read_channel_processed(air_channel, &val); if (ret < 0) { printk("%s:Busy/Timeout, IIO ch read failed %d\n", __func__, ret); return ret; } printk("lpp-----get gms detect vol xx=%d\n", val); /*val * 1500 / 4096*/ ///ret = (val * 1450) >> 12; //max 1.45V } return val; } EXPORT_SYMBOL_GPL(gms_detection_getadc_v); int gms_detection_getadc(void){ int ret = 0; int val = 0; if (!IS_ERR_OR_NULL(air_channel)){ ret = iio_read_channel_processed(air_channel, &val); if (ret < 0) { printk("%s:Busy/Timeout, IIO ch read failed %d\n", __func__, ret); return ret; } //1764 0.64 printk("lpp-----get gms detect vol=%d\n", val); // ret = (val * 1450) >> 12; //max 1.45V } return 1800-val; } EXPORT_SYMBOL_GPL(gms_detection_getadc); int is_gms_board(void){ if ((gms_detection_getadc_v() < gms_adc_vol_max_value)&&(gms_detection_getadc_v() > gms_adc_vol_min_value) ) { printk("gms board\n"); return 1; }else{ printk("not gms_board\n"); return 0; } } EXPORT_SYMBOL_GPL(is_gms_board); static int gms_detection_probe(struct platform_device *pdev) { int ret = 0; struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; printk("gms_detection_probe start\n"); air_channel = iio_channel_get(&pdev->dev, "air-ch"); if (IS_ERR(air_channel)) { ret = PTR_ERR(air_channel); printk("[%s] lpp fail to get auxadc iio ch5: %d, %p\n", __func__, ret, air_channel); return ret; } ret = of_property_read_u32(np,"gms_adc_vol_max",&gms_adc_vol_max_value); if(ret < 0){ printk("[%s] lpp fail to get auxadc gms_adc_vol_max failed\n"); }else{ printk("[%s] lpp get auxadc gms_adc_vol_max = %d\n",gms_adc_vol_max_value); } ret = of_property_read_u32(np,"gms_adc_vol_min",&gms_adc_vol_min_value); if(ret < 0){ printk("[%s] lpp fail to get auxadc gms_adc_vol_min failed\n"); }else{ printk("[%s] lpp get auxadc gms_adc_vol_min = %d\n",gms_adc_vol_min_value); } printk("gms_detection_probe end\n"); return 0; } static int gms_detection_remove(struct platform_device *dev) { gms_detection_DEBUG("[gms_detection_dev]:gms_detection_remove start!\n"); gms_detection_DEBUG("[gms_detection_dev]:gms_detection_remove end!\n"); return 0; } static const struct of_device_id gms_detection_dt_match[] = { {.compatible = "prize,gms_detection"}, {}, }; static struct platform_driver gms_detection_driver = { .probe = gms_detection_probe, .remove = gms_detection_remove, .driver = { .name = "gms_detection_driver", .of_match_table = of_match_ptr(gms_detection_dt_match), }, }; static int __init gms_detection_init(void) { int retval = 0; printk("gms_detection_init, retval=%d \n!",retval); if (retval != 0) { return retval; } platform_driver_register(&gms_detection_driver); return 0; } static void __exit gms_detection_exit(void) { printk("gms_detection_exit start\n"); platform_driver_unregister(&gms_detection_driver); } module_init(gms_detection_init); module_exit(gms_detection_exit); MODULE_DESCRIPTION("AIR QUALITY driver"); MODULE_AUTHOR("lipengpeng "); MODULE_LICENSE("GPL"); //MODULE_SUPPORTED_DEVICE("AIRQUALITYDEVICE");