/* * fw-test.c -FW Test Driver * * * Copyright (C) 2010, Intel Corporation. All rights reserved. * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * TODO * */ #include #include #include #include #include #include #include #include #include MODULE_AUTHOR("Tomas Winkler"); MODULE_DESCRIPTION("Firmware API Test Driver"); MODULE_LICENSE("GPL"); struct fw_test_dev { struct platform_device *p_dev; struct mutex mutex; const struct firmware *fw; }; static struct fw_test_dev fw_test; static ssize_t load_fw(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { struct fw_test_dev *priv = &fw_test; ssize_t ret; mutex_lock(&fw_test.mutex); ret = request_firmware(&priv->fw, buf, d); if (ret) printk(KERN_ERR "request fail %s ret=%zd", buf, ret); else ret = count; mutex_unlock(&fw_test.mutex); printk(KERN_INFO "FW-TEST LOAD"); return ret; } static ssize_t release_fw(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { struct fw_test_dev *priv = &fw_test; mutex_lock(&fw_test.mutex); release_firmware(priv->fw); priv->fw = NULL; mutex_unlock(&fw_test.mutex); printk(KERN_INFO "FW-TEST RELEASE"); return count; } static DEVICE_ATTR(load_fw, S_IWUGO, NULL, load_fw); static DEVICE_ATTR(release_fw, S_IWUGO, NULL, release_fw); static struct attribute *fw_test_sysfs_entries[] = { &dev_attr_load_fw.attr, &dev_attr_release_fw.attr, NULL }; static struct attribute_group fw_test_attribute_group = { .name = NULL, /* put in device directory */ .attrs = fw_test_sysfs_entries, }; static void fw_test_exit(void) { sysfs_remove_group(&fw_test.p_dev->dev.kobj, &fw_test_attribute_group); platform_device_unregister(fw_test.p_dev); printk(KERN_INFO "FW API Test Driver Unloaded"); return; } static int __init fw_test_init(void) { int ret; mutex_init(&fw_test.mutex); fw_test.p_dev = platform_device_register_simple("fw-test", -1, NULL, 0); if (IS_ERR(fw_test.p_dev)) { ret = PTR_ERR(fw_test.p_dev); printk(KERN_ERR "unable to register platform device\n"); fw_test.p_dev = NULL; fw_test_exit(); return ret; } ret = sysfs_create_group(&fw_test.p_dev->dev.kobj, &fw_test_attribute_group); if (ret) { printk(KERN_ERR "Failed to allocate SYSFS entry"); fw_test.p_dev = NULL; fw_test_exit(); return ret; } printk(KERN_INFO "FW API Test Driver Loaded"); return 0; } module_init(fw_test_init); module_exit(fw_test_exit);