From: Kitae Kim Date: Mon, 25 Nov 2013 05:54:34 +0000 (+0900) Subject: maru_jack: source clean-up X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1409158b16b0be3878826a4139a134f6cee8af94;p=sdk%2Femulator%2Femulator-kernel.git maru_jack: source clean-up Changed name of some functions, because of sysfs_test_xxx is ambiguous and the name is the same as other modules such as power_supply, usb_mode and etc.. In addition to this, update authors's name. Change-Id: I1c27f3ce0409a477f67a4b74a421b6c2abe1e6cc Signed-off-by: Kitae Kim --- diff --git a/drivers/maru/maru_jack.c b/drivers/maru/maru_jack.c index 6f4526e3e146..f60265a56cf0 100644 --- a/drivers/maru/maru_jack.c +++ b/drivers/maru/maru_jack.c @@ -1,233 +1,256 @@ -/* - * Virtual device node for event injector of emulator - * - * Copyright (c) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * Sungmin Ha - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Contributors: - * - S-Core Co., Ltd - */ - -#include -#include -#include -#include -#include - -int charger_online = 0; -int earjack_online = 0; -int earkey_online = 0; -int hdmi_online = 0; -int usb_online = 0; - -struct my_data { - int no; - char test[50]; -}; - -static ssize_t show_charger_online(struct device *dev, - struct device_attribute *attr, char *buf) -{ - printk("[%s] \n", __FUNCTION__); - return snprintf(buf, PAGE_SIZE, "%d", charger_online); -} - -static ssize_t store_charger_online(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - printk("[%s] \n", __FUNCTION__); - sscanf(buf, "%d", &charger_online); - return strnlen(buf, PAGE_SIZE); -} - -static ssize_t show_earjack_online(struct device *dev, - struct device_attribute *attr, char *buf) -{ - printk("[%s] \n", __FUNCTION__); - return snprintf(buf, PAGE_SIZE, "%d", earjack_online); -} - -static ssize_t store_earjack_online(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - printk("[%s] \n", __FUNCTION__); - sscanf(buf, "%d", &earjack_online); - return strnlen(buf, PAGE_SIZE); -} - -static ssize_t show_earkey_online(struct device *dev, - struct device_attribute *attr, char *buf) -{ - printk("[%s] \n", __FUNCTION__); - return snprintf(buf, PAGE_SIZE, "%d", earkey_online); -} - -static ssize_t store_earkey_online(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - printk("[%s] \n", __FUNCTION__); - sscanf(buf, "%d", &earkey_online); - return strnlen(buf, PAGE_SIZE); -} - -static ssize_t show_hdmi_online(struct device *dev, - struct device_attribute *attr, char *buf) -{ - printk("[%s] \n", __FUNCTION__); - return snprintf(buf, PAGE_SIZE, "%d", hdmi_online); -} - -static ssize_t store_hdmi_online(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - printk("[%s] \n", __FUNCTION__); - sscanf(buf, "%d", &hdmi_online); - return strnlen(buf, PAGE_SIZE); -} - -static ssize_t show_usb_online(struct device *dev, - struct device_attribute *attr, char *buf) -{ - printk("[%s] \n", __FUNCTION__); - return snprintf(buf, PAGE_SIZE, "%d", usb_online); -} - -static ssize_t store_usb_online(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - printk("[%s] \n", __FUNCTION__); - sscanf(buf, "%d", &usb_online); - return strnlen(buf, PAGE_SIZE); -} -static DEVICE_ATTR(charger_online, S_IRUGO | S_IWUSR, show_charger_online, store_charger_online); -static DEVICE_ATTR(earjack_online, S_IRUGO | S_IWUSR, show_earjack_online, store_earjack_online); -static DEVICE_ATTR(earkey_online, S_IRUGO | S_IWUSR, show_earkey_online, store_earkey_online); -static DEVICE_ATTR(hdmi_online, S_IRUGO | S_IWUSR, show_hdmi_online, store_hdmi_online); -static DEVICE_ATTR(usb_online, S_IRUGO | S_IWUSR, show_usb_online, store_usb_online); - -static int sysfs_test_create_file(struct device *dev) -{ - int result = 0; - - printk("[%d] [%s] \n", __LINE__, __FUNCTION__); - - result = device_create_file(dev, &dev_attr_charger_online); - if (result){ - printk("[%d] [%s] error \n", __LINE__, __FUNCTION__); - return result; - } - - result = device_create_file(dev, &dev_attr_earjack_online); - if (result){ - printk("[%d] [%s] error \n", __LINE__, __FUNCTION__); - return result; - } - - result = device_create_file(dev, &dev_attr_earkey_online); - if (result){ - printk("[%d] [%s] error \n", __LINE__, __FUNCTION__); - return result; - } - - result = device_create_file(dev, &dev_attr_hdmi_online); - if (result){ - printk("[%d] [%s] error \n", __LINE__, __FUNCTION__); - return result; - } - - result = device_create_file(dev, &dev_attr_usb_online); - if (result){ - printk("[%d] [%s] error \n", __LINE__, __FUNCTION__); - return result; - } - - return 0; -} - - -static void sysfs_test_remove_file(struct device *dev) -{ - printk("[%s] \n", __FUNCTION__); - device_remove_file(dev, &dev_attr_charger_online); - device_remove_file(dev, &dev_attr_earjack_online); - device_remove_file(dev, &dev_attr_earkey_online); - device_remove_file(dev, &dev_attr_hdmi_online); - device_remove_file(dev, &dev_attr_usb_online); -} - -static void sysfs_test_dev_release(struct device *dev) {} - -static struct platform_device the_pdev = { - .name = "jack", - .id = -1, - .dev = { - .release = sysfs_test_dev_release, - } -}; - -static int __init sysfs_test_init(void) -{ - int err = 0; - struct my_data *data; - - printk("[%s] \n", __FUNCTION__); - - err = platform_device_register(&the_pdev); - if (err) { - printk("platform_device_register error\n"); - return err; - } - - data = kzalloc(sizeof(struct my_data), GFP_KERNEL); - if (!data) { - printk("[%s] kzalloc error\n", __FUNCTION__); - err = -ENOMEM; - platform_device_unregister(&the_pdev); - return err; - } - - dev_set_drvdata(&the_pdev.dev, (void*)data); - - err = sysfs_test_create_file(&the_pdev.dev); - if (err) { - printk("sysfs_create_file error\n"); - kfree(data); - } - - return 0; -} - -static void __exit sysfs_test_exit(void) -{ - void *data = dev_get_drvdata(&the_pdev.dev); - - printk("[%s] \n", __FUNCTION__); - - kfree(data); - sysfs_test_remove_file(&the_pdev.dev); - platform_device_unregister(&the_pdev); -} - -module_init(sysfs_test_init); -module_exit(sysfs_test_exit); - - -MODULE_LICENSE("GPL"); - - +/* + * Virtual device node for event injector of emulator + * + * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JinHyung Choi + * Sungmin Ha + * YeongKyoon Lee +#include +#include +#include +#include + +int charger_online = 0; +int earjack_online = 0; +int earkey_online = 0; +int hdmi_online = 0; +int usb_online = 0; + +struct jack_data { + int no; + char buffer[50]; +}; + +#define DEVICE_NAME "jack" +#define JACK_DEBUG + +#ifdef JACK_DEBUG +#define DLOG(level, fmt, ...) \ + printk(level "maru_%s: " fmt, DEVICE_NAME, ##__VA_ARGS__) +#else +// do nothing +#define DLOG(level, fmt, ...) +#endif + +static ssize_t show_charger_online(struct device *dev, + struct device_attribute *attr, char *buf) +{ + DLOG(KERN_INFO, "get charger_online: %d\n", charger_online); + return snprintf(buf, PAGE_SIZE, "%d", charger_online); +} + +static ssize_t store_charger_online(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + sscanf(buf, "%d", &charger_online); + DLOG(KERN_INFO, "set charger_online: %d\n", charger_online); + + return strnlen(buf, PAGE_SIZE); +} + +static ssize_t show_earjack_online(struct device *dev, + struct device_attribute *attr, char *buf) +{ + DLOG(KERN_INFO, "get earjack_online: %d\n", earjack_online); + return snprintf(buf, PAGE_SIZE, "%d", earjack_online); +} + +static ssize_t store_earjack_online(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + sscanf(buf, "%d", &earjack_online); + DLOG(KERN_INFO, "set earjack_online: %d\n", earjack_online); + + return strnlen(buf, PAGE_SIZE); +} + +static ssize_t show_earkey_online(struct device *dev, + struct device_attribute *attr, char *buf) +{ + DLOG(KERN_INFO, "get earkey_online: %d\n", earkey_online); + return snprintf(buf, PAGE_SIZE, "%d", earkey_online); +} + +static ssize_t store_earkey_online(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + sscanf(buf, "%d", &earkey_online); + DLOG(KERN_INFO, "set earkey_online: %d\n", earkey_online); + + return strnlen(buf, PAGE_SIZE); +} + +static ssize_t show_hdmi_online(struct device *dev, + struct device_attribute *attr, char *buf) +{ + DLOG(KERN_INFO, "get hdmi_online: %d\n", hdmi_online); + return snprintf(buf, PAGE_SIZE, "%d", hdmi_online); +} + +static ssize_t store_hdmi_online(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + sscanf(buf, "%d", &hdmi_online); + DLOG(KERN_INFO, "set hdmi_online: %d\n", hdmi_online); + + return strnlen(buf, PAGE_SIZE); +} + +static ssize_t show_usb_online(struct device *dev, + struct device_attribute *attr, char *buf) +{ + DLOG(KERN_INFO, "get usb_online: %d\n", usb_online); + return snprintf(buf, PAGE_SIZE, "%d", usb_online); +} + +static ssize_t store_usb_online(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + sscanf(buf, "%d", &usb_online); + DLOG(KERN_INFO, "set usb_online: %d\n", usb_online); + + return strnlen(buf, PAGE_SIZE); +} +static DEVICE_ATTR(charger_online, S_IRUGO | S_IWUSR, show_charger_online, store_charger_online); +static DEVICE_ATTR(earjack_online, S_IRUGO | S_IWUSR, show_earjack_online, store_earjack_online); +static DEVICE_ATTR(earkey_online, S_IRUGO | S_IWUSR, show_earkey_online, store_earkey_online); +static DEVICE_ATTR(hdmi_online, S_IRUGO | S_IWUSR, show_hdmi_online, store_hdmi_online); +static DEVICE_ATTR(usb_online, S_IRUGO | S_IWUSR, show_usb_online, store_usb_online); + +static int maru_jack_sysfs_create_file(struct device *dev) +{ + int result = 0; + + DLOG(KERN_INFO, "sysfs_create_file\n"); + + result = device_create_file(dev, &dev_attr_charger_online); + if (result){ + DLOG(KERN_ERR, "failed to create charger_online file\n"); + return result; + } + + result = device_create_file(dev, &dev_attr_earjack_online); + if (result){ + DLOG(KERN_ERR, "failed to create earjack_online file\n"); + return result; + } + + result = device_create_file(dev, &dev_attr_earkey_online); + if (result){ + DLOG(KERN_ERR, "failed to create earkey_online file\n"); + return result; + } + + result = device_create_file(dev, &dev_attr_hdmi_online); + if (result){ + DLOG(KERN_ERR, "failed to create hdmi_online file\n"); + return result; + } + + result = device_create_file(dev, &dev_attr_usb_online); + if (result){ + DLOG(KERN_ERR, "failed to create usb_online file\n"); + return result; + } + + return 0; +} + + +static void maru_jack_sysfs_remove_file(struct device *dev) +{ + DLOG(KERN_INFO, "sysfs_remove_file\n"); + + device_remove_file(dev, &dev_attr_charger_online); + device_remove_file(dev, &dev_attr_earjack_online); + device_remove_file(dev, &dev_attr_earkey_online); + device_remove_file(dev, &dev_attr_hdmi_online); + device_remove_file(dev, &dev_attr_usb_online); +} + +static void maru_jack_sysfs_dev_release(struct device *dev) +{ + DLOG(KERN_INFO, "sysfs_dev_release\n"); +} + +static struct platform_device the_pdev = { + .name = DEVICE_NAME, + .id = -1, + .dev = { + .release = maru_jack_sysfs_dev_release, + } +}; + +static int __init maru_jack_sysfs_init(void) +{ + int err = 0; + struct jack_data *data; + + DLOG(KERN_INFO, "sysfs_init\n"); + + err = platform_device_register(&the_pdev); + if (err) { + DLOG(KERN_ERR, "platform_device_register failure\n"); + return err; + } + + data = kzalloc(sizeof(struct jack_data), GFP_KERNEL); + if (!data) { + DLOG(KERN_ERR, "kzalloc failure\n"); + platform_device_unregister(&the_pdev); + return -ENOMEM; + } + + dev_set_drvdata(&the_pdev.dev, (void*)data); + + err = maru_jack_sysfs_create_file(&the_pdev.dev); + if (err) { + DLOG(KERN_ERR, "sysfs_create_file failure\n"); + kfree(data); + platform_device_unregister(&the_pdev); + return err; + } + + return 0; +} + +static void __exit maru_jack_sysfs_exit(void) +{ + void *data = dev_get_drvdata(&the_pdev.dev); + + DLOG(KERN_INFO, "sysfs_exit\n"); + + if (data) { + kfree(data); + } + maru_jack_sysfs_remove_file(&the_pdev.dev); + platform_device_unregister(&the_pdev); +} + +module_init(maru_jack_sysfs_init); +module_exit(maru_jack_sysfs_exit); + +MODULE_LICENSE("GPL");