summaryrefslogtreecommitdiff
path: root/drivers/media/sprd_dcam/common/flash_test.c
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2017-08-30 08:25:59 +0000
committerYuval Adam <_@yuv.al>2017-08-30 08:25:59 +0000
commit8e4bff4cab0ddac6060645b0715210484d02ff40 (patch)
tree3a5c3024371a04692a3a6d9974d001cdff8ebf84 /drivers/media/sprd_dcam/common/flash_test.c
Initial file dump from open source releaseHEADmaster
Diffstat (limited to 'drivers/media/sprd_dcam/common/flash_test.c')
-rw-r--r--drivers/media/sprd_dcam/common/flash_test.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/drivers/media/sprd_dcam/common/flash_test.c b/drivers/media/sprd_dcam/common/flash_test.c
new file mode 100644
index 00000000..dc8be3ef
--- /dev/null
+++ b/drivers/media/sprd_dcam/common/flash_test.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2014 Spreadtrum Communications Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+/* notes : note location /sys/class/flash_test/flash_test/
+ * echo 0x11>flash_value
+ * cat flash_value
+ */
+#include "flash_test.h"
+#include "parse_hwinfo.h"
+#include <../flash/flash.h>
+
+#define SENSOR_K_SUCCESS 0
+#define SENSOR_K_FAIL (-1)
+#define SENSOR_K_FALSE 0
+#define SENSOR_K_TRUE 1
+
+
+static struct class* flash_test_class = NULL;
+static int g_flash_mode=0;
+
+int setflash(uint32_t flash_mode)
+{
+ switch (flash_mode) {
+ case FLASH_OPEN: /*flash on */
+ case FLASH_TORCH: /*for torch low light */
+ sprd_flash_on();
+ break;
+ case FLASH_HIGH_LIGHT: /*high light */
+ sprd_flash_on();
+ break;
+ case FLASH_CLOSE_AFTER_OPEN: /*close flash */
+ case FLASH_CLOSE_AFTER_AUTOFOCUS:
+ case FLASH_CLOSE:
+ sprd_flash_close();
+ break;
+ default:
+ printk("sprd_v4l2_setflash unknow mode:flash_mode 0x%x \n", flash_mode);
+ break;
+ }
+ return 0;
+}
+
+static ssize_t flash_test_show(struct device* dev,
+ struct device_attribute* attr, char* buf)
+{
+ return snprintf(buf, PAGE_SIZE, "flash_mode is :0x%x\n", g_flash_mode);
+}
+
+static ssize_t flash_test_store(struct device *dev,
+ struct device_attribute *attr, const char *buf,size_t c)
+{
+ int ret;
+ unsigned long flash_mode;
+ printk(KERN_ALERT"flash_test_store buf=%s line %d .\n",buf,__LINE__);
+ ret = kstrtoul(buf, 16, &flash_mode);
+ if (ret)
+ return ret;
+ g_flash_mode=flash_mode;
+ setflash(flash_mode);
+ return c;
+}
+static DEVICE_ATTR(flash_value, 0644, flash_test_show, flash_test_store);
+
+static int __init flash_test_init(void){
+ int err = -1;
+ dev_t dev_num = 0;
+ int flash_test_major = 0;
+ int flash_test_minor = 0;
+ struct device* flash_test_dev = NULL;
+ err = alloc_chrdev_region(&dev_num, 0, 1, FLASH_TEST_DEVICE_NODE_NAME);
+ if (err < 0) {
+ printk(KERN_ALERT"Failed to alloc char dev region.\n");
+ goto fail;
+ }
+ flash_test_major = MAJOR(dev_num);
+ flash_test_minor = MINOR(dev_num);
+ flash_test_class = class_create(THIS_MODULE, FLASH_TEST_DEVICE_CLASS_NAME);
+ if (IS_ERR(flash_test_class)) {
+ err = PTR_ERR(flash_test_class);
+ printk(KERN_ALERT"Failed to create flash_test class.\n");
+ goto destroy_class;
+ }
+ flash_test_dev = device_create(flash_test_class, NULL, dev_num, "%s", FLASH_TEST_DEVICE_FILE_NAME);
+ if (IS_ERR(flash_test_dev)) {
+ err = PTR_ERR(flash_test_dev);
+ printk(KERN_ALERT"Failed to create flash_test device.");
+ goto destroy_class;
+ }
+ err = device_create_file(flash_test_dev, &dev_attr_flash_value);
+ if (err < 0) {
+ printk(KERN_ALERT"Failed to create attribute val.");
+ goto destroy_device;
+ }
+ return 0;
+destroy_device:
+ device_destroy(flash_test_class, dev_num);
+destroy_class:
+ class_destroy(flash_test_class);
+ unregister_chrdev_region(MKDEV(flash_test_major, flash_test_minor), 1);
+fail:
+ return err;
+}
+module_init(flash_test_init);
+MODULE_AUTHOR("freed wang, spreadtrum");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Flash test Interface");