openBMC source code

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)
复制代码
posted @ 2018-09-16 00:12  heimafeitian  阅读(491)  评论(0编辑  收藏  举报