static ssize_t vdd_opp_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { unsigned short value; int flags = 0; if (sscanf(buf, "%hu", &value) != 1) return -EINVAL; /* Check locks */ if (attr == &vdd1_lock_attr) { flags = OPP_IGNORE_LOCK; attr = &vdd1_opp_attr; if (vdd1_locked && value == 0) { resource_unlock_opp(PRCM_VDD1); resource_refresh(); vdd1_locked = 0; return n; } if (vdd1_locked == 0 && value != 0) { resource_lock_opp(PRCM_VDD1); vdd1_locked = 1; } } else if (attr == &vdd2_lock_attr) { flags = OPP_IGNORE_LOCK; attr = &vdd2_opp_attr; if (vdd2_locked && value == 0) { resource_unlock_opp(PRCM_VDD2); resource_refresh(); vdd2_locked = 0; return n; } if (vdd2_locked == 0 && value != 0) { resource_lock_opp(PRCM_VDD2); vdd2_locked = 1; } } if (attr == &vdd1_opp_attr) { if (value < 1 || value > 5) { printk(KERN_ERR "vdd_opp_store: Invalid value\n"); return -EINVAL; } resource_set_opp_level(PRCM_VDD1, value, flags); } else if (attr == &vdd2_opp_attr) { if (value < 1 || value > 3) { printk(KERN_ERR "vdd_opp_store: Invalid value\n"); return -EINVAL; } resource_set_opp_level(PRCM_VDD2, value, flags); } else { return -EINVAL; } return n; }
/** * resource_test_7 - Tests the resource_refresh API * @res_name: Name of the resource requested ("vdd1_opp"/"vdd2_opp") * @req_lvl1: Requested lower level for the resource * @req_lvl2: Requested higher level for the resource * * Device 1 requests the resource for the given lower level, * locks the resource. Meanwhile device 2 requests the reource for a * higher level. * Verifies if the resource's current level is same as the requested * higher level after device 1 unlocks the resource * * Returns 0 on success, -1 on failure */ static int resource_test_7(const char *res_name, unsigned long req_lvl1, unsigned long req_lvl2) { int ret, cur_lvl, result = TEST_PASS; int lock_val; struct device dev1, dev2; printk(KERN_INFO "Entry resource_test_7 \n"); if (!strcmp(res_name, "vdd1_opp")) lock_val = VDD1_OPP; else if (!strcmp(res_name, "vdd2_opp")) lock_val = VDD2_OPP; else { printk(KERN_ERR "FAILED!!!! invalid resource name\n"); return TEST_FAIL; } ret = resource_request(res_name, &dev1, req_lvl1); if (ret) { printk(KERN_ERR "FAILED!!!! resource1 request for %s failed" " with value %d\n", res_name, ret); return TEST_FAIL; } cur_lvl = resource_get_level(res_name); if (cur_lvl != req_lvl1) { printk(KERN_ERR "FAILED!!!! resource %s current level:%d" " req lvl:%d\n", res_name, cur_lvl, (int)req_lvl1); result = TEST_FAIL; } if (result == TEST_PASS) { ret = resource_access_opp_lock(lock_val, 1); if (ret < 0) { printk(KERN_ERR "FAILED!!!! resource %s lock failed" " with value %d\n", res_name, ret); result = TEST_FAIL; } } if (result == TEST_PASS) { ret = resource_request(res_name, &dev2, req_lvl2); if (ret) { printk(KERN_ERR "FAILED!!!! resource2 request %s failed" " with value %d\n", res_name, ret); ret = resource_access_opp_lock(lock_val, -1); if (ret < 0) printk(KERN_ERR "FAILED!!!! resource unlock" "for %s failed\n", res_name); result = TEST_FAIL; } } if (result == TEST_PASS) { cur_lvl = resource_get_level(res_name); if (cur_lvl != req_lvl1) { printk(KERN_ERR "FAILED!!!! %s current level:%d" " req lvl:%d\n", res_name, cur_lvl, (int)req_lvl1); result = TEST_FAIL; } ret = resource_access_opp_lock(lock_val, -1); if (ret < 0) { printk(KERN_ERR "FAILED!!!! resource unlock %s failed" " with value %d\n", res_name, ret); result = TEST_FAIL; } ret = resource_refresh(); if (ret) { printk(KERN_ERR "FAILED!!!! resource refresh failed" " with value %d\n", ret); result = TEST_FAIL; } cur_lvl = resource_get_level(res_name); if (cur_lvl != req_lvl2) { printk(KERN_ERR "FAILED!!!! %s current level:%d" " req lvl:%d\n", res_name, cur_lvl, (int)req_lvl2); result = TEST_FAIL; } } ret = resource_release(res_name, &dev1); if (ret) { printk(KERN_ERR "FAILED!!!! resource1 release for %s failed" " with value %d\n", res_name, ret); result = TEST_FAIL; } ret = resource_release(res_name, &dev2); if (ret) { printk(KERN_ERR "FAILED!!!! resource2 release for %s failed" " with value %d\n", res_name, ret); result = TEST_FAIL; } if (!result) printk(KERN_INFO "resource_test_7 PASSED for %s\n", res_name); return result; }