Skip to content

Commit bfc4f96

Browse files
committed
[AS5835-54T/X] support fan direction of DC PSU
1 parent 67b19b5 commit bfc4f96

File tree

4 files changed

+322
-8
lines changed

4 files changed

+322
-8
lines changed

device/accton/x86_64-accton_as5835_54t-r0/pddf/pddf-device.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@
245245
"attr_list":
246246
[
247247
{ "attr_name":"psu_present", "attr_devaddr":"0x60", "attr_devtype":"cpld", "attr_offset":"0x2", "attr_mask":"0x1", "attr_cmpval":"0x0", "attr_len":"1"},
248-
{ "attr_name":"psu_model_name", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0x9a", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"10" },
249248
{ "attr_name":"psu_power_good", "attr_devaddr":"0x60", "attr_devtype":"cpld", "attr_offset":"0x2", "attr_mask":"0x2", "attr_cmpval":"0x2", "attr_len":"1"},
250249
{ "attr_name":"psu_mfr_id", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0X99", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"10" },
251250
{ "attr_name":"psu_fan_dir", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0xc3", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"5"},
@@ -271,7 +270,8 @@
271270
"topo_info":{ "parent_bus":"0xb", "dev_addr":"0x50", "dev_type":"psu_eeprom"},
272271
"attr_list":
273272
[
274-
{ "attr_name":"psu_serial_num", "attr_devaddr":"0x50", "attr_devtype":"eeprom", "attr_offset":"0x35", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"19" }
273+
{ "attr_name":"psu_serial_num", "attr_devaddr":"0x50", "attr_devtype":"eeprom", "attr_offset":"0x35", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"19" },
274+
{ "attr_name":"psu_model_name", "attr_devaddr":"0x50", "attr_devtype":"eeprom", "attr_offset":"0x20", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"12" }
275275
]
276276
}
277277
},
@@ -299,7 +299,6 @@
299299
"attr_list":
300300
[
301301
{ "attr_name":"psu_present", "attr_devaddr":"0x60", "attr_devtype":"cpld", "attr_offset":"0x2", "attr_mask":"0x10", "attr_cmpval":"0x0", "attr_len":"1"},
302-
{ "attr_name":"psu_model_name", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0x9a", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"10" },
303302
{ "attr_name":"psu_power_good", "attr_devaddr":"0x60", "attr_devtype":"cpld", "attr_offset":"0x2", "attr_mask":"0x20", "attr_cmpval":"0x20", "attr_len":"1"},
304303
{ "attr_name":"psu_mfr_id", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0X99", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"10" },
305304
{ "attr_name":"psu_fan_dir", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0xc3", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"5"},
@@ -324,7 +323,8 @@
324323
"topo_info":{ "parent_bus":"0xc", "dev_addr":"0x53", "dev_type":"psu_eeprom"},
325324
"attr_list":
326325
[
327-
{ "attr_name":"psu_serial_num", "attr_devaddr":"0x53", "attr_devtype":"eeprom", "attr_offset":"0x35", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"19" }
326+
{ "attr_name":"psu_serial_num", "attr_devaddr":"0x53", "attr_devtype":"eeprom", "attr_offset":"0x35", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"19" },
327+
{ "attr_name":"psu_model_name", "attr_devaddr":"0x53", "attr_devtype":"eeprom", "attr_offset":"0x20", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"12" }
328328
]
329329
}
330330
},

device/accton/x86_64-accton_as5835_54x-r0/pddf/pddf-device.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@
165165
"attr_list":
166166
[
167167
{ "attr_name":"psu_present", "attr_devaddr":"0x60", "attr_devtype":"cpld", "attr_offset":"0x2", "attr_mask":"0x1", "attr_cmpval":"0x0", "attr_len":"1"},
168-
{ "attr_name":"psu_model_name", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0x9a", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"10" },
169168
{ "attr_name":"psu_power_good", "attr_devaddr":"0x60", "attr_devtype":"cpld", "attr_offset":"0x2", "attr_mask":"0x2", "attr_cmpval":"0x2", "attr_len":"1"},
170169
{ "attr_name":"psu_mfr_id", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0X99", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"10" },
171170
{ "attr_name":"psu_fan_dir", "attr_devaddr":"0x58", "attr_devtype":"pmbus", "attr_offset":"0xc3", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"5"},
@@ -189,7 +188,8 @@
189188
"topo_info":{ "parent_bus":"0xb", "dev_addr":"0x50", "dev_type":"psu_eeprom"},
190189
"attr_list":
191190
[
192-
{ "attr_name":"psu_serial_num", "attr_devaddr":"0x50", "attr_devtype":"eeprom", "attr_offset":"0x35", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"19" }
191+
{ "attr_name":"psu_serial_num", "attr_devaddr":"0x50", "attr_devtype":"eeprom", "attr_offset":"0x35", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"19" },
192+
{ "attr_name":"psu_model_name", "attr_devaddr":"0x50", "attr_devtype":"eeprom", "attr_offset":"0x20", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"12" }
193193
]
194194
}
195195
},
@@ -217,7 +217,6 @@
217217
"attr_list":
218218
[
219219
{ "attr_name":"psu_present", "attr_devaddr":"0x60", "attr_devtype":"cpld", "attr_offset":"0x2", "attr_mask":"0x10", "attr_cmpval":"0x0", "attr_len":"1"},
220-
{ "attr_name":"psu_model_name", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0x9a", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"10" },
221220
{ "attr_name":"psu_power_good", "attr_devaddr":"0x60", "attr_devtype":"cpld", "attr_offset":"0x2", "attr_mask":"0x20", "attr_cmpval":"0x20", "attr_len":"1"},
222221
{ "attr_name":"psu_mfr_id", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0X99", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"10" },
223222
{ "attr_name":"psu_fan_dir", "attr_devaddr":"0x5b", "attr_devtype":"pmbus", "attr_offset":"0xc3", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"5"},
@@ -241,7 +240,8 @@
241240
"topo_info":{ "parent_bus":"0xc", "dev_addr":"0x53", "dev_type":"psu_eeprom"},
242241
"attr_list":
243242
[
244-
{ "attr_name":"psu_serial_num", "attr_devaddr":"0x53", "attr_devtype":"eeprom", "attr_offset":"0x35", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"19" }
243+
{ "attr_name":"psu_serial_num", "attr_devaddr":"0x53", "attr_devtype":"eeprom", "attr_offset":"0x35", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"19" },
244+
{ "attr_name":"psu_model_name", "attr_devaddr":"0x53", "attr_devtype":"eeprom", "attr_offset":"0x20", "attr_mask":"0x0", "attr_cmpval":"0xff", "attr_len":"12" }
245245
]
246246
}
247247
},

platform/broadcom/sonic-platform-modules-accton/as5835-54t/modules/pddf_custom_psu.c

+157
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,31 @@
99
#include <linux/sysfs.h>
1010
#include <linux/slab.h>
1111
#include <linux/dmi.h>
12+
#include "pddf_client_defs.h"
1213
#include "pddf_psu_defs.h"
14+
#include "pddf_psu_driver.h"
15+
#include "pddf_psu_api.h"
1316

1417
ssize_t pddf_show_custom_psu_v_out(struct device *dev, struct device_attribute *da, char *buf);
1518
extern PSU_SYSFS_ATTR_DATA access_psu_v_out;
19+
int pddf_post_get_custom_psu_model_name(void *i2c_client, PSU_DATA_ATTR *adata, void *data);
20+
extern PSU_SYSFS_ATTR_DATA access_psu_model_name;
21+
int pddf_post_get_custom_psu_fan_dir(void *i2c_client, PSU_DATA_ATTR *adata, void *data);
22+
extern PSU_SYSFS_ATTR_DATA access_psu_fan_dir;
23+
int pddf_custom_psu_post_probe(struct i2c_client *client, const struct i2c_device_id *dev_id);
24+
int pddf_custom_psu_post_remove(struct i2c_client *client);
25+
extern struct pddf_ops_t pddf_psu_ops;
26+
27+
const char FAN_DIR_F2B[] = "F2B\0";
28+
const char FAN_DIR_B2F[] = "B2F\0";
29+
30+
static LIST_HEAD(psu_eeprom_client_list);
31+
static struct mutex list_lock;
32+
33+
struct psu_eeprom_client_node {
34+
struct i2c_client *client;
35+
struct list_head list;
36+
};
1637

1738
static int two_complement_to_int(u16 data, u8 valid_bit, int mask)
1839
{
@@ -95,11 +116,147 @@ ssize_t pddf_show_custom_psu_v_out(struct device *dev, struct device_attribute *
95116
}
96117

97118

119+
int pddf_post_get_custom_psu_model_name(void *i2c_client, PSU_DATA_ATTR *adata, void *data)
120+
{
121+
struct psu_attr_info *sysfs_attr_info = (struct psu_attr_info *)data;
122+
123+
if (strlen(sysfs_attr_info->val.strval) > 8) {
124+
sysfs_attr_info->val.strval[8] = '-';
125+
}
126+
127+
return 0;
128+
}
129+
130+
/*
131+
* Get the PSU EEPROM I2C client with the same bus number.
132+
*/
133+
static struct i2c_client *find_psu_eeprom_client(struct i2c_client *pmbus_client)
134+
{
135+
struct list_head *list_node = NULL;
136+
struct psu_eeprom_client_node *psu_eeprom_node = NULL;
137+
struct i2c_client *eeprom_client = NULL;
138+
139+
mutex_lock(&list_lock);
140+
list_for_each(list_node, &psu_eeprom_client_list) {
141+
psu_eeprom_node = list_entry(list_node, struct psu_eeprom_client_node, list);
142+
/* Check if the bus adapter is the same or not. */
143+
if (psu_eeprom_node->client->adapter == pmbus_client->adapter) {
144+
eeprom_client = psu_eeprom_node->client;
145+
break;
146+
}
147+
}
148+
mutex_unlock(&list_lock);
149+
150+
return eeprom_client;
151+
}
152+
153+
int pddf_post_get_custom_psu_fan_dir(void *i2c_client, PSU_DATA_ATTR *adata, void *data)
154+
{
155+
int i;
156+
struct i2c_client *client = (struct i2c_client *)i2c_client;
157+
struct psu_attr_info *psu_fan_dir_attr_info = (struct psu_attr_info *)data;
158+
struct psu_data *psu_eeprom_client_data = NULL;
159+
struct psu_attr_info *psu_eeprom_model_name = NULL;
160+
struct i2c_client *psu_eeprom_client = NULL;
161+
162+
psu_eeprom_client = find_psu_eeprom_client(client);
163+
if (!psu_eeprom_client) {
164+
return 0;
165+
}
166+
167+
/*
168+
* Get the model name from the PSU EEPROM I2C client.
169+
*/
170+
psu_eeprom_client_data = i2c_get_clientdata(psu_eeprom_client);
171+
if (!psu_eeprom_client_data) {
172+
return 0;
173+
}
174+
for (i = 0; i < psu_eeprom_client_data->num_attr; i++) {
175+
if (strcmp(psu_eeprom_client_data->attr_info[i].name, "psu_model_name") == 0) {
176+
psu_eeprom_model_name = &psu_eeprom_client_data->attr_info[i];
177+
break;
178+
}
179+
}
180+
if (!psu_eeprom_model_name) {
181+
return 0;
182+
}
183+
184+
/*
185+
* Compare the model name, then replace the content of psu_fan_dir.
186+
*/
187+
if (strcmp(psu_eeprom_model_name->val.strval, "YM-2401H-CR") == 0) {
188+
strscpy(psu_fan_dir_attr_info->val.strval,
189+
FAN_DIR_F2B,
190+
sizeof(psu_fan_dir_attr_info->val.strval));
191+
} else if (strcmp(psu_eeprom_model_name->val.strval, "YM-2401H-DR") == 0) {
192+
strscpy(psu_fan_dir_attr_info->val.strval,
193+
FAN_DIR_B2F,
194+
sizeof(psu_fan_dir_attr_info->val.strval));
195+
}
196+
197+
return 0;
198+
}
199+
200+
int pddf_custom_psu_post_probe(struct i2c_client *client, const struct i2c_device_id *dev_id)
201+
{
202+
struct psu_eeprom_client_node *psu_eeprom_node;
203+
204+
if (strcmp(dev_id->name, "psu_eeprom") != 0) {
205+
return 0;
206+
}
207+
208+
psu_eeprom_node = kzalloc(sizeof(struct psu_eeprom_client_node), GFP_KERNEL);
209+
if (!psu_eeprom_node) {
210+
dev_dbg(&client->dev, "Can't allocate psu_eeprom_client_node (0x%x)\n", client->addr);
211+
return -ENOMEM;
212+
}
213+
214+
psu_eeprom_node->client = client;
215+
216+
mutex_lock(&list_lock);
217+
list_add(&psu_eeprom_node->list, &psu_eeprom_client_list);
218+
mutex_unlock(&list_lock);
219+
220+
return 0;
221+
}
222+
223+
int pddf_custom_psu_post_remove(struct i2c_client *client)
224+
{
225+
struct list_head *list_node = NULL;
226+
struct psu_eeprom_client_node *psu_eeprom_node = NULL;
227+
int found = 0;
228+
229+
mutex_lock(&list_lock);
230+
231+
list_for_each(list_node, &psu_eeprom_client_list) {
232+
psu_eeprom_node = list_entry(list_node, struct psu_eeprom_client_node, list);
233+
234+
if (psu_eeprom_node->client == client) {
235+
list_del_init(&psu_eeprom_node->list);
236+
found = 1;
237+
break;
238+
}
239+
}
240+
241+
if (found) {
242+
kfree(psu_eeprom_node);
243+
}
244+
245+
mutex_unlock(&list_lock);
246+
247+
return 0;
248+
}
249+
98250

99251
static int __init pddf_custom_psu_init(void)
100252
{
253+
mutex_init(&list_lock);
101254
access_psu_v_out.show = pddf_show_custom_psu_v_out;
102255
access_psu_v_out.do_get = NULL;
256+
access_psu_model_name.post_get = pddf_post_get_custom_psu_model_name;
257+
access_psu_fan_dir.post_get = pddf_post_get_custom_psu_fan_dir;
258+
pddf_psu_ops.post_probe = pddf_custom_psu_post_probe;
259+
pddf_psu_ops.post_remove = pddf_custom_psu_post_remove;
103260
return 0;
104261
}
105262

0 commit comments

Comments
 (0)