openBMC source code

简介: 1、fand1)main函数read_sysfs_int("/sys/bus/i2c/drivers/cmmcpld/13-003e/slotid", &sysfs_value)write_fan_speed(fan + fan_offset, fan_speed)write_fan_le...

1、fand

1)main函数

read_sysfs_int("/sys/bus/i2c/drivers/cmmcpld/13-003e/slotid", &sysfs_value)

write_fan_speed(fan + fan_offset, fan_speed)

write_fan_led(fan + fan_offset, FAN_LED_BLUE)

start_watchdog(0)

while(1){

critical_temp = read_critical_max_temp();
alarm_temp = read_alarm_max_temp();

raising_pwm = calculate_raising_fan_pwm(critical_temp);
falling_pwm = calculate_falling_fan_pwm(critical_temp);

write_fan_led(fan + fan_offset, FAN_LED_RED);

}

 

2)write_fan_speed

int write_fan_speed(const int fan, const int value) {
int unit = value * PWM_UNIT_MAX / 100;

if (unit == PWM_UNIT_MAX)
unit--;

return galaxy100_set_fan_sysfs(fan, unit);
}

 

3)galaxy100_set_fan_sysfs

info = &galaxy100_fantray_info[fan];
channel = &info->channel_info;

snprintf(fullpath, PATH_CACHE_SIZE, "%s/%s", channel->prefix, "fantray1_pwm");
ret = write_sysfs_int(fullpath, value);

snprintf(fullpath, PATH_CACHE_SIZE, "%s/%s", channel->prefix, "fantray2_pwm");
ret = write_sysfs_int(fullpath, value);

snprintf(fullpath, PATH_CACHE_SIZE, "%s/%s", channel->prefix, "fantray3_pwm");
ret = write_sysfs_int(fullpath, value);

 

4) write_sysfs_int

int write_sysfs_int(char *sysfs_path, int buffer)
{
int rc = 0;
char writeBuf[PATH_CACHE_SIZE];
snprintf(writeBuf, PATH_CACHE_SIZE, "%d", buffer);
return write_sysfs_raw(sysfs_path, writeBuf);
}

 

int write_sysfs_raw_internal(const char *device, char *value, int log)

fp = fopen(device, "w");

rc = fputs(value, fp);
fclose(fp);

 

5)  fancpld_attr_table

typedef struct i2c_dev_attr_st_ {
  const char *ida_name;
  const char *ida_help;
  i2c_dev_attr_show_fn ida_show;
  i2c_dev_attr_store_fn ida_store;
  int ida_reg;
  int ida_bit_offset;
  int ida_n_bits;
} i2c_dev_attr_st;

const i2c_dev_attr_st fancpld_attr_table[] = {
  {
    "fantray1_pwm",
    FANTRAY_PWM_HELP,
    I2C_DEV_ATTR_SHOW_DEFAULT,
    I2C_DEV_ATTR_STORE_DEFAULT,
    0x20, 0, 5,
  },
}

static int fancpld_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int n_attrs = sizeof(fancpld_attr_table) / sizeof(fancpld_attr_table[0]);
return i2c_dev_sysfs_data_init(client, &fancpld_data,
fancpld_attr_table, n_attrs);
}

 

static struct i2c_driver fancpld_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "fancpld",
},
.probe = fancpld_probe,
.remove = fancpld_remove,
.id_table = fancpld_id,
.detect = fancpld_detect,
.address_list = normal_i2c,
};

static int __init fancpld_mod_init(void)
{
return i2c_add_driver(&fancpld_driver);
}

 

 

6) i2c_dev_sysfs_store

static ssize_t i2c_dev_sysfs_store(struct device *dev,
                                   struct device_attribute *attr,
                                   const char *buf, size_t count)

if (dev_attr->ida_store != I2C_DEV_ATTR_STORE_DEFAULT) {
return dev_attr->ida_store(dev, attr, buf, count);
}

/* default handling, first read back the current value */
val = i2c_smbus_read_byte_data(client, dev_attr->ida_reg);

 

/* mask out all bits for the value requested */
val &= ~(req_val_mask << dev_attr->ida_bit_offset);
val |= req_val << dev_attr->ida_bit_offset;

val = i2c_smbus_write_byte_data(client, dev_attr->ida_reg, val);

 

7)module_init

Cmmcpld.c (meta-facebook\meta-cmm\recipes-kernel\cpld-mod\files):module_init(cmmcpld_mod_init);
Com_e_driver.c (meta-facebook\meta-wedge100\recipes-kernel\com-e-mod\files):module_init(com_e_mod_init);
Fancpld.c (meta-facebook\meta-cmm\recipes-kernel\cpld-mod\files):module_init(fancpld_mod_init);
Fancpld.c (meta-facebook\meta-wedge100\recipes-kernel\cpld-mod\files):module_init(fancpld_mod_init);
Fb_panther_plus.c (meta-facebook\meta-wedge\recipes-kernel\fb-panther-mod\files):module_init(sensors_panther_plus_init);
Galaxy100_ec.c (meta-facebook\meta-galaxy100\recipes-kernel\i2c-mode\files):module_init(ec_mod_init); Ir358x.c (meta-facebook\meta-galaxy100\recipes-kernel\i2c-mode\files):module_init(ir358x_mod_init); Pwr1014a.c (meta-facebook\meta-galaxy100\recipes-kernel\i2c-mode\files):module_init(pwr1014a_mod_init); Scmcpld.c (meta-facebook\meta-galaxy100\recipes-kernel\cpld-mod\files):module_init(scmcpld_mod_init); Syscpld.c (meta-facebook\meta-galaxy100\recipes-kernel\cpld-mod\files):module_init(syscpld_mod_init); Syscpld.c (meta-facebook\meta-wedge100\recipes-kernel\cpld-mod\files):module_init(syscpld_mod_init);

每个文件对应某个单板的一个设备驱动,每个设备驱动定义一个i2c_dev_attr_st数组,支持用户态通过文件方式进行读写访问。

 

2、lib_ipmb_handle

1)int pal_read_cpu_temp(uint8_t snr_num, float *value)

req->cmd = CMD_NM_SEND_RAW_PECI;

lib_ipmb_handle(bus_id, tbuf, tlen+1, rbuf1, &rlen);

 

2) bic_set_gpio(uint8_t slot_id, uint8_t gpio, uint8_t value)

bic_ipmb_wrapper(slot_id, NETFN_OEM_1S_REQ, CMD_OEM_1S_SET_GPIO, tbuf, 11, rbuf, &rlen)

get_ipmb_bus_id(slot_id)

lib_ipmb_handle(bus_id, tbuf, tlen, &rbuf, &rlen)

// copy the received data back to caller
*rxlen = rlen - IPMB_HDR_SIZE - IPMI_RESP_HDR_SIZE;
memcpy(rxbuf, res->data, *rxlen);

 

3) void lib_ipmb_handle(unsigned char bus_id,

unsigned char *request, unsigned char req_len,
unsigned char *response, unsigned char *res_len) 

sprintf(sock_path, "%s_%d", SOCK_PATH_IPMB, bus_id);  //#define SOCK_PATH_IPMB "/tmp/ipmb_socket"

s = socket(AF_UNIX, SOCK_STREAM, 0)

connect(s, (struct sockaddr *)&remote, len)

send(s, request, req_len, 0)

recv(s, response, MAX_IPMB_RES_LEN, 0)

 

目录
相关文章
|
存储 编解码 监控
G-Code 详解
玩过一段时间3D打印机的朋友,都会接触到G-code文件。所谓G-code文件, 指的是3D模型在进入3D打印机实际打印之前,必须要经过切片器处理而成的一种中间格式文件。
4698 0
|
4月前
|
监控
常用T-code使用总结
常用T-code使用总结
29 1
|
Ubuntu 安全 IDE
被VS Code牢牢圈粉了!
一款得心应手的IDE,能够让开发者效率和幸福感得到极大的提升。 而VS Code这两年迅速的发展,使它俘获一大批忠实的用户。 本文,将从扩展、主题、图标等全面的介绍如何配置一款让人爽到起飞的VS Code。
被VS Code牢牢圈粉了!
|
JSON Java 程序员
code S: code style & code standard
关于代码风格与代码规范的二三事
262 0
|
Web App开发
Chrome source code map - fail - cannot debug
Chrome source code map - fail - cannot debug
Chrome source code map - fail - cannot debug
|
移动开发 前端开发 程序员
CODE大全
我本人自己是个程序猿,在这个互联网时代,我除了工作,业余时间都在自己的博客上编写文章,我以写博客文章赚点零花钱。这是一篇软文,主要用来推广一下我的第二个网站:CODE大全。说实话,我的文笔很水,从小写作文,到现在没有得过高分。也不知道从何处开始介绍 CODE大全 。CODE大全主要包含以下几个板块博客栏目:www.codedq.net其中博客栏目包括,首页,编程语言,WEB前端,数据库,架构设
1742 1
|
Android开发
1--debug时安卓源码不一致问题--Source code does not match the bytecode
AS--debug时:Source code does not match the bytecode 解决方案:保持模拟器与编译版本一致,即: 编译版本与运行版本一致
3326 0