-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[AS7326-56X] Support mulit PSU SN in PDDF #7966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jostar-yang
wants to merge
6
commits into
sonic-net:master
from
jostar-yang:as7326_20210624_pddf_multi_psu
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c09976b
[AS7326-56X] Support mulit PSU SN in PDDF
75bfb59
Modify to "data.model_name[0] = '\0'"
9112a00
Modify to "data.model_name[models[i].length]"
cd235ab
Modify YM-2651Y SN offet
25bcc0c
Modify SN offset and include path
4390758
Fix pddf-device bug
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
203 changes: 203 additions & 0 deletions
203
platform/broadcom/sonic-platform-modules-accton/as7326-56x/modules/pddf_custom_psu.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| #include <linux/module.h> | ||
| #include <linux/jiffies.h> | ||
| #include <linux/i2c.h> | ||
| #include <linux/hwmon.h> | ||
| #include <linux/hwmon-sysfs.h> | ||
| #include <linux/err.h> | ||
| #include <linux/delay.h> | ||
| #include <linux/mutex.h> | ||
| #include <linux/sysfs.h> | ||
| #include <linux/slab.h> | ||
| #include <linux/dmi.h> | ||
| #include "pddf_psu_defs.h" | ||
|
|
||
| ssize_t pddf_get_custom_psu_model_name(struct device *dev, struct device_attribute *da, char *buf); | ||
| ssize_t pddf_get_custom_psu_serial_num(struct device *dev, struct device_attribute *da, char *buf); | ||
| extern PSU_SYSFS_ATTR_DATA access_psu_model_name; | ||
| extern PSU_SYSFS_ATTR_DATA access_psu_serial_num; | ||
|
|
||
| #define MAX_MODEL_NAME 16 | ||
| #define MAX_SERIAL_NUMBER 19 | ||
|
|
||
| enum psu_type { | ||
| PSU_TYPE_AC_110V, | ||
| PSU_TYPE_DC_48V, | ||
| PSU_TYPE_DC_12V, | ||
| PSU_TYPE_AC_ACBEL_FSF019 | ||
| }; | ||
|
|
||
| struct model_name_info { | ||
| enum psu_type type; | ||
| u8 offset; | ||
| u8 length; | ||
| u8 chk_length; | ||
| char* model_name; | ||
| }; | ||
|
|
||
| struct serial_number_info { | ||
| enum psu_type type; | ||
| u8 offset; | ||
| u8 length; | ||
| u8 chk_length; | ||
| char* serial_number; | ||
| }; | ||
|
|
||
| struct model_name_info models[] = { | ||
| {PSU_TYPE_AC_110V, 0x20, 8, 8, "YM-2651Y"}, | ||
| {PSU_TYPE_DC_48V, 0x20, 8, 8, "YM-2651V"}, | ||
| {PSU_TYPE_DC_12V, 0x00, 11, 11, "PSU-12V-750"}, | ||
| {PSU_TYPE_AC_ACBEL_FSF019, 0x15, 10, 7, "FSF019-"} | ||
|
|
||
| }; | ||
|
|
||
| struct serial_number_info serials[] = { | ||
| {PSU_TYPE_AC_110V, 0x2e, 18, 18, "YM-2651Y"}, | ||
jostar-yang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {PSU_TYPE_DC_48V, 0x2e, 18, 18, "YM-2651V"}, | ||
| {PSU_TYPE_DC_12V, 0x2e, 18, 18, "PSU-12V-750"}, | ||
| {PSU_TYPE_AC_ACBEL_FSF019, 0x2e, 16, 16, "FSF019-"} | ||
|
|
||
| }; | ||
|
|
||
| struct pddf_psu_data { | ||
| char model_name[MAX_MODEL_NAME+1]; | ||
| char serial_number[MAX_SERIAL_NUMBER+1]; | ||
| }; | ||
|
|
||
|
|
||
| static int pddf_psu_read_block(struct i2c_client *client, u8 command, u8 *data, | ||
| int data_len) | ||
| { | ||
| int result = 0; | ||
| int retry_count = 10; | ||
|
|
||
| while (retry_count) { | ||
| retry_count--; | ||
|
|
||
| result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); | ||
|
|
||
| if (unlikely(result < 0)) { | ||
| msleep(10); | ||
| continue; | ||
| } | ||
|
|
||
| if (unlikely(result != data_len)) { | ||
| result = -EIO; | ||
| msleep(10); | ||
| continue; | ||
| } | ||
|
|
||
| result = 0; | ||
| break; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| ssize_t pddf_get_custom_psu_serial_num(struct device *dev, struct device_attribute *da, char *buf) | ||
| { | ||
| struct i2c_client *client = to_i2c_client(dev); | ||
| struct pddf_psu_data data; | ||
| int i, status; | ||
|
|
||
| for (i = 0; i < ARRAY_SIZE(models); i++) { | ||
| memset(data.serial_number, 0, sizeof(data.serial_number)); | ||
|
|
||
| status = pddf_psu_read_block(client, models[i].offset, | ||
| data.model_name, models[i].length); | ||
| if (status < 0) { | ||
| data.model_name[0] = '\0'; | ||
| dev_dbg(&client->dev, "unable to read model name from (0x%x) offset(0x%x)\n", | ||
| client->addr, models[i].offset); | ||
| return status; | ||
| } | ||
| else { | ||
| data.model_name[models[i].length] = '\0'; | ||
| } | ||
|
|
||
| /* Determine if the model name is known, if not, read next index | ||
| */ | ||
| if (strncmp(data.model_name, models[i].model_name, models[i].chk_length) == 0) { | ||
| status = pddf_psu_read_block(client, serials[i].offset, | ||
| data.serial_number, serials[i].length); | ||
|
|
||
| if (status < 0) { | ||
| data.serial_number[0] = '\0'; | ||
| dev_dbg(&client->dev, "unable to read serial num from (0x%x) offset(0x%x)\n", | ||
| client->addr, serials[i].offset); | ||
| return status; | ||
| } | ||
| else { | ||
| data.serial_number[serials[i].length] = '\0'; | ||
| return sprintf(buf, "%s\n", data.serial_number); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| else { | ||
| data.serial_number[0] = '\0'; | ||
| } | ||
| } | ||
|
|
||
| return -ENODATA; | ||
|
|
||
|
|
||
| } | ||
|
|
||
| ssize_t pddf_get_custom_psu_model_name(struct device *dev, struct device_attribute *da, char *buf) | ||
| { | ||
| struct i2c_client *client = to_i2c_client(dev); | ||
| struct pddf_psu_data data; | ||
| int i, status; | ||
|
|
||
| for (i = 0; i < ARRAY_SIZE(models); i++) { | ||
| memset(data.model_name, 0, sizeof(data.model_name)); | ||
|
|
||
| status = pddf_psu_read_block(client, models[i].offset, | ||
| data.model_name, models[i].length); | ||
| if (status < 0) { | ||
| data.model_name[0] = '\0'; | ||
| dev_dbg(&client->dev, "unable to read model name from (0x%x) offset(0x%x)\n", | ||
| client->addr, models[i].offset); | ||
| return status; | ||
| } | ||
| else { | ||
| data.model_name[models[i].length] = '\0'; | ||
| } | ||
|
|
||
| /* Determine if the model name is known, if not, read next index | ||
| */ | ||
| if (strncmp(data.model_name, models[i].model_name, models[i].chk_length) == 0) { | ||
| return sprintf(buf, "%s\n", data.model_name); | ||
| } | ||
| else { | ||
| data.model_name[0] = '\0'; | ||
| } | ||
| } | ||
|
|
||
| return -ENODATA; | ||
|
|
||
| } | ||
|
|
||
| static int __init pddf_custom_psu_init(void) | ||
| { | ||
| access_psu_serial_num.show = pddf_get_custom_psu_serial_num; | ||
| access_psu_serial_num.do_get = NULL; | ||
|
|
||
| access_psu_model_name.show = pddf_get_custom_psu_model_name; | ||
| access_psu_model_name.do_get = NULL; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static void __exit pddf_custom_psu_exit(void) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| MODULE_AUTHOR("Broadcom"); | ||
| MODULE_DESCRIPTION("pddf custom psu api"); | ||
| MODULE_LICENSE("GPL"); | ||
|
|
||
| module_init(pddf_custom_psu_init); | ||
| module_exit(pddf_custom_psu_exit); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.