<html><body><p>Hi Stanley,<br><br>Thanks for your detailed comments. I will made changes based on your suggestions.<br><br>Yi Li (Adam)<br>OpenPower China Application Engineer Team<br>021-60928951<br>13524695440<br><br><br><img width="16" height="16" src="cid:3__=8FBBF59BDFC5AC088f9e8a93df938690918c8FB@" border="0" alt="Inactive hide details for Joel Stanley ---11/25/2015 07:35:17 AM---From: Joel Stanley <joel@jms.id.au> To: OpenBMC Patches <ope"><font color="#424282">Joel Stanley ---11/25/2015 07:35:17 AM---From: Joel Stanley <joel@jms.id.au> To: OpenBMC Patches <openbmc-patches@stwcx.xyz></font><br><br><font size="2" color="#5F5F5F">From:        </font><font size="2">Joel Stanley <joel@jms.id.au></font><br><font size="2" color="#5F5F5F">To:        </font><font size="2">OpenBMC Patches <openbmc-patches@stwcx.xyz></font><br><font size="2" color="#5F5F5F">Cc:        </font><font size="2">adamliyi <adamliyi@msn.com>, OpenBMC Maillist <openbmc@lists.ozlabs.org></font><br><font size="2" color="#5F5F5F">Date:        </font><font size="2">11/25/2015 07:35 AM</font><br><font size="2" color="#5F5F5F">Subject:        </font><font size="2">Re: [PATCH openbmc] add occ hwmon driver as kernel patch</font><br><font size="2" color="#5F5F5F">Sent by:        </font><font size="2">"openbmc" <openbmc-bounces+shliyi=cn.ibm.com@lists.ozlabs.org></font><br><hr width="100%" size="2" align="left" noshade style="color:#8091A5; "><br><br><br><tt>Hello Adam,<br><br>Thanks for posting your code.<br><br>I've had a quick look and pointed out some style related changes that<br>you can make. This is important in getting upstream to accept your<br>patch, but also to make the code clear.<br><br>Once you've made the fixes I suggest, try running your patch through<br>scripts/checkpatch.pl in the Linux source tree. This will point out<br>lines that do not confirm to the coding standards the kernel uses. Try<br>to fix all of these warnings, and send an updated version of the<br>patch.<br><br>Next time you send the patch, send it as a PR to the kernel tree at<br></tt><tt><a href="https://github.com/openbmc/linux">https://github.com/openbmc/linux</a></tt><tt>. This is easier than reading a<br>patch-against-patch, and it's good practice for submitting the patch<br>upstream.<br><br>Please jump on the IRC channel at #openbmc on irc.freenode.net if you<br>want do discuss any changes, or have any questions.<br><br>Once you've fixed up the style issues, we will see what changes need<br>to be made to the structure of the driver.<br><br>Cheers,<br><br>Joel<br><br>On Wed, Nov 25, 2015 at 3:10 AM, OpenBMC Patches<br><openbmc-patches@stwcx.xyz> wrote:<br>> +--- a/drivers/hwmon/Kconfig<br>> ++++ b/drivers/hwmon/Kconfig<br>> +@@ -1167,6 +1167,13 @@ config SENSORS_NCT7904<br>> +         This driver can also be built as a module.  If so, the module<br>> +         will be called nct7904.<br>> +<br>> ++config SENSORS_OCC<br>> ++      tristate "OCC sensor driver for IBM Power CPU"<br>> ++      depends on I2C<br>> ++      help<br>> ++        If you say yes here you get support for driver to read sensors in<br>> ++        IBM Power CPU On-Chip-Controller. module will be called occ.<br><br>Is this a driver for BMCs, or for the Power8 host? This should be made clear.<br><br>> ++<br>> + config SENSORS_PCF8591<br>> +       tristate "Philips PCF8591 ADC/DAC"<br>> +       depends on I2C<br>> +diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile<br>> +index 9e0f3dd..53dc3b3 100644<br>> +--- a/drivers/hwmon/Makefile<br>> ++++ b/drivers/hwmon/Makefile<br>> +@@ -123,6 +123,7 @@ obj-$(CONFIG_SENSORS_NCT6775)      += nct6775.o<br>> + obj-$(CONFIG_SENSORS_NCT7802) += nct7802.o<br>> + obj-$(CONFIG_SENSORS_NCT7904) += nct7904.o<br>> + obj-$(CONFIG_SENSORS_NTC_THERMISTOR)  += ntc_thermistor.o<br>> ++obj-$(CONFIG_SENSORS_OCC)     += occ.o<br>> + obj-$(CONFIG_SENSORS_PC87360) += pc87360.o<br>> + obj-$(CONFIG_SENSORS_PC87427) += pc87427.o<br>> + obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o<br>> +diff --git a/drivers/hwmon/occ.c b/drivers/hwmon/occ.c<br>> +new file mode 100644<br>> +index 0000000..f265ff3<br>> +--- /dev/null<br>> ++++ b/drivers/hwmon/occ.c<br>> +@@ -0,0 +1,1529 @@<br>> ++/*<br>> ++ * Open BMC OCC HWMON driver - read Power8 OCC (On Chip Controller) sensor data via i2c.<br>> ++ *<br>> ++ * Copyright (c) 2015 IBM (Alvin Wang, Li Yi)<br>> ++ *<br>> ++ * This program is free software; you can redistribute it and/or modify<br>> ++ * it under the terms of the GNU General Public License as published by<br>> ++ * the Free Software Foundation; either version 2 of the License, or<br>> ++ * (at your option) any later version.<br>> ++ *<br>> ++ * This program is distributed in the hope that it will be useful,<br>> ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>> ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>> ++ * GNU General Public License for more details.<br>> ++ *<br>> ++ * You should have received a copy of the GNU General Public License<br>> ++ * along with this program; if not, write to the Free Software<br>> ++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.<br>> ++ */<br>> ++<br>> ++#include <linux/module.h><br>> ++#include <linux/init.h><br>> ++#include <linux/slab.h><br>> ++#include <linux/jiffies.h><br>> ++#include <linux/i2c.h><br>> ++#include <linux/hwmon.h><br>> ++#include <linux/hwmon-sysfs.h><br>> ++#include <linux/err.h><br>> ++#include <linux/mutex.h><br>> ++#include <linux/of.h><br>> ++#include <linux/delay.h><br>> ++<br>> ++//#define DEBUG    1<br><br>No C++ comments please.<br><br>> ++<br>> ++/* ------------------------------------------------------------*/<br><br>Drop the ASCII art.<br><br>> ++/* OCC sensor data format */<br>> ++typedef struct {<br>> ++      uint16_t sensor_id;<br>> ++      uint16_t value;<br>> ++} occ_sensor;<br>> ++<br><br>In the kernel we tend not to typedef our structures. So this would be<br>"struct occ_sensor { ..."<br><br>The same comment applies to all of your structures.<br><br>> ++typedef struct {<br>> ++      uint16_t sensor_id;<br>> ++      uint32_t update_tag;<br>> ++      uint32_t accumulator;<br>> ++      uint16_t value;<br>> ++} powr_sensor;<br><br>I'll buy you a vowel. Call this "struct power_sensor".<br><br>> ++<br>> ++typedef struct {<br>> ++      uint16_t curr_powercap;<br>> ++      uint16_t curr_powerreading;<br>> ++      uint16_t norm_powercap;<br>> ++      uint16_t max_powercap;<br>> ++      uint16_t min_powercap;<br>> ++      uint16_t user_powerlimit;<br>> ++} caps_sensor;<br><br>typedef<br><br>> ++<br>> ++typedef struct {<br>> ++      char sensor_type[5];<br><br>uint8_t instead of a char?<br><br>> ++      uint8_t reserved0;<br>> ++      uint8_t sensor_format;<br>> ++      uint8_t sensor_length;<br>> ++      uint8_t num_of_sensors;<br>> ++      occ_sensor *sensor;<br>> ++      powr_sensor *powr;<br>> ++      caps_sensor *caps;<br>> ++} sensor_data_block;<br><br>typedef<br><br>> ++<br>> ++typedef struct {<br>> ++      uint8_t status;<br>> ++      uint8_t ext_status;<br>> ++      uint8_t occs_present;<br>> ++      uint8_t config;<br>> ++      uint8_t occ_state;<br>> ++      uint8_t reserved0;<br>> ++      uint8_t reserved1;<br>> ++      uint8_t error_log_id;<br>> ++      uint32_t error_log_addr_start;<br>> ++      uint16_t error_log_length;<br>> ++      uint8_t reserved2;<br>> ++      uint8_t reserved3;<br>> ++      char occ_code_level[17];<br><br>Code level is an IBM term. Perhaps call this version_string?<br><br>> ++      char sensor_eye_catcher[7];<br>> ++      uint8_t num_of_sensor_blocks;<br>> ++      uint8_t sensor_data_version;<br>> ++      sensor_data_block* blocks;<br>> ++} occ_poll_data;<br><br>typedef<br><br>> ++<br>> ++typedef struct {<br>> ++      uint8_t sequence_num;<br>> ++      uint8_t cmd_type;<br>> ++      uint8_t rtn_status;<br>> ++      uint16_t data_length;<br>> ++      occ_poll_data data;<br>> ++      uint16_t chk_sum;<br>> ++      int temp_block_id;<br>> ++      int freq_block_id;<br>> ++      int power_block_id;<br>> ++      int caps_block_id;<br>> ++} occ_response_t;<br><br>typedef<br><br>> ++<br>> ++//static occ_response_t occ_resp;<br><br>C++ comments.<br><br>> ++/* Each client has this additional data */<br><br>I don't understand this comment.<br><br>> ++struct occ_drv_data {<br>> ++      struct i2c_client       *client;<br>> ++      struct device           *hwmon_dev;<br>> ++      struct mutex            update_lock;<br>> ++      char                    valid;          /* !=0 if sensor data are valid */<br><br>make this a bool, and you can drop the comment.<br><br>> ++      unsigned long           last_updated;   /* In jiffies */<br>> ++      unsigned long           sample_time;    /* Mininum timer interval for sampling In jiffies */<br><br>Minimum.<br><br>> ++      occ_response_t          occ_resp;<br>> ++};<br>> ++<br>> ++/*-----------------------------------------------------------------------*/<br><br>Drop this.<br><br>> ++/* i2c read and write occ sensors */<br>> ++<br>> ++#define OCC_DATA_MAX 4096 /* 4KB at most */<br>> ++#define I2C_STATUS_REG 0x000d0001<br>> ++#define I2C_ERROR_REG  0x000d0002<br>> ++#define I2C_READ_ERROR 1<br>> ++#define I2C_WRITE_ERROR 2<br>> ++#define I2C_DATABUFFER_SIZE_ERROR 3<br>> ++<br>> ++/*<br><br>Why is this commented out?<br><br>> ++#define SCOM_OCC_SRAM_WOX  0x0006B013<br>> ++#define SCOM_OCC_SRAM_WAND 0x0006B012<br>> ++#define SCOM_OCC_SRAM_ADDR 0x0006B010<br>> ++#define SCOM_OCC_SRAM_DATA 0x0006B015<br>> ++*/<br>> ++<br>> ++// To generate attn to OCC<br><br>Use C commenting style.<br><br>> ++#define ATTN_DATA                0x0006B035<br>> ++<br>> ++// For BMC to read/write SRAM<br><br>Use C commenting style.<br><br>> ++#define OCB_ADDRESS              0x0006B070<br>> ++#define OCB_DATA                 0x0006B075<br>> ++#define OCB_STATUS_CONTROL_AND   0x0006B072<br>> ++#define OCB_STATUS_CONTROL_OR    0x0006B073<br>> ++<br>> ++#define OCC_COMMAND_ADDR 0xFFFF6000<br>> ++#define OCC_RESPONSE_ADDR 0xFFFF7000<br>> ++<br>> ++static int deinit_occ_resp_buf(occ_response_t *p)<br>> ++{<br>> ++      int b;<br>> ++<br>> ++      if (p == NULL)<br><br>You can check for null by just doing if (p).<br><br>> ++              return 0;<br><br>We normally return a negative number when there is an error.<br><br>This function only returns 0, which is not useful for the callee.<br><br>> ++<br>> ++      if (p->data.blocks == NULL)<br>> ++              return 0;<br>> ++<br>> ++      for(b = 0; b < p->data.num_of_sensor_blocks; b++) {<br>> ++              if (!p->data.blocks[b].sensor)<br>> ++                      kfree(p->data.blocks[b].sensor);<br>> ++              if (!p->data.blocks[b].powr)<br>> ++                      kfree(p->data.blocks[b].powr);<br>> ++              if (!p->data.blocks[b].caps)<br>> ++                      kfree(p->data.blocks[b].caps);<br>> ++      }<br>> ++<br>> ++      kfree(p->data.blocks);<br>> ++<br>> ++      memset(p, 0, sizeof(*p));<br>> ++<br>> ++<br>> ++      return 0;<br>> ++}<br>> ++<br>> ++static ssize_t occ_i2c_read(struct i2c_client *client, char *buf, size_t count)<br>> ++{<br>> ++      int ret = 0;<br>> ++<br>> ++      if (count > 8192)<br>> ++              count = 8192;<br><br>This should at least log an informative message.<br><br>> ++<br>> ++      //printk("i2c_read: reading %zu bytes @0x%x.\n", count, client->addr);<br><br>Delete it, or use dev_dbg() to make your debugging info dynamically<br>configurable.<br><br>> ++      ret = i2c_master_recv(client, buf, count);<br>> ++      return ret;<br><br>This can be one line.<br><br>> ++}<br>> ++<br>> ++static ssize_t occ_i2c_write(struct i2c_client *client, const char *buf, size_t count)<br>> ++{<br>> ++      int ret = 0;<br>> ++<br>> ++      if (count > 8192)<br>> ++              count = 8192;<br>> ++<br>> ++      //printk("i2c_write: writing %zu bytes @0x%x.\n", count, client->addr);<br>> ++      ret = i2c_master_send(client, buf, count);<br>> ++      return ret;<br><br>Similar comments to the occ_i2c_read.<br><br>> ++}<br>> ++<br>> ++/* read two 4-byte value */<br>> ++static int occ_getscom(struct i2c_client *client, uint32_t address, uint32_t *value0, uint32_t *value1)<br>> ++{<br>> ++      uint32_t ret = 0;<br>> ++      char buf[8];<br>> ++      const char* address_buf = (const char*)&address;<br>> ++<br>> ++      //P8 i2c slave requires address to be shifted by 1<br><br>C++ comments.<br><br>> ++      address = address << 1;<br>> ++<br>> ++      ret = occ_i2c_write(client, address_buf, sizeof(address));<br>> ++      /* FIXME: ast i2c driver does not read corret value */<br>> ++      //if (ret != sizeof(address))<br>> ++      //      return -I2C_WRITE_ERROR;<br>> ++<br>> ++      ret = occ_i2c_read(client, buf, sizeof(buf));<br>> ++      //if (ret != sizeof(buf))<br>> ++      //      return -I2C_READ_ERROR;<br><br>You've commented out the error handling here. Did you get to the<br>bottom of why you're not getting the return value you're expecting?<br><br>> ++<br>> ++      memcpy(value1, &buf[0], sizeof(*value1));<br>> ++      memcpy(value0, &buf[4], sizeof(*value0));<br><br>*value1 = buf[0]?<br><br>> ++<br>> ++      return 0;<br>> ++}<br>> ++<br>> ++/* read 8-byte value and put into data[offset] */<br>> ++static int occ_getscomb(struct i2c_client *client, uint32_t address, char* data, int offset)<br>> ++{<br><br>data is bytes, just make it u8.<br><br>> ++      uint32_t ret = 0;<br>> ++      const char* address_buf = (const char*)&address;<br>> ++      char buf[8];<br>> ++      int b = 0;<br><br>Convention is to use i for counters.<br><br>> ++<br>> ++      //P8 i2c slave requires address to be shifted by 1<br>> ++      address = address << 1;<br>> ++<br>> ++      ret = occ_i2c_write(client, address_buf, sizeof(address));<br>> ++      //if (ret != sizeof(address))<br>> ++      //      return -I2C_WRITE_ERROR;<br>> ++<br>> ++      ret = occ_i2c_read(client, buf, sizeof(buf));<br>> ++      //if (ret != sizeof(buf))<br>> ++      //      return -I2C_READ_ERROR;<br>> ++<br>> ++      for (b = 0; b < 8; b++) {<br>> ++              data[offset + b] = buf[7 - b];<br>> ++      }<br>> ++<br>> ++      return 0;<br>> ++}<br>> ++<br>> ++static int occ_putscom(struct i2c_client *client, uint32_t address, uint32_t data0, uint32_t data1)<br>> ++{<br>> ++      const char* address_buf = (const char*)&address;<br>> ++      const char* d0 = (const char*)&data0;<br>> ++      const char* d1 = (const char*)&data1;<br><br>This messing about with types is unnecessary.<br><br>> ++      char buf[12];<br>> ++      uint32_t ret = 0;<br>> ++<br>> ++      //P8 i2c slave requires address to be shifted by 1<br>> ++      address = address << 1;<br>> ++<br>> ++      memcpy(&buf[0], address_buf, sizeof(address));<br>> ++      memcpy(&buf[4], d1, sizeof(data1));<br>> ++      memcpy(&buf[8], d0, sizeof(data0));<br><br>I think there's a better way to create your buffer. This is not endian<br>safe, and it's hard to read.<br><br>> ++<br>> ++      ret = occ_i2c_write(client, buf, sizeof(buf));<br>> ++      //if (ret != sizeof(buf))<br>> ++      //      return I2C_WRITE_ERROR;<br>> ++<br>> ++      return 0;<br>> ++}<br>> ++<br>> ++static int occ_check_i2c_errors(struct i2c_client *client)<br>> ++{<br>> ++      uint32_t v0;<br>> ++      uint32_t v1;<br>> ++<br>> ++      occ_getscom(client, I2C_STATUS_REG, &v0, &v1);<br>> ++      if (v0 != 0x80000000) {<br><br>Create #defines for your magic number.<br><br>> ++              printk("ERROR present in P8 I2C Slave.  Clearing...\n");<br>> ++              occ_putscom(client, I2C_ERROR_REG, 0x00000000, 0x00000000);<br>> ++              occ_putscom(client, I2C_STATUS_REG, 0x00000000, 0x00000000);<br>> ++              return -1;<br>> ++      }<br>> ++<br>> ++      return 0;<br>> ++}<br>> ++<br>> ++<br>> ++static inline uint16_t get_occdata_length(char* d)<br><br>u8 instead of char.<br><br>> ++{<br>> ++      uint16_t data_length = 0;<br>> ++<br>> ++      data_length = d[3] << 8;<br>> ++      data_length = data_length | d[4];<br>> ++      return data_length;<br>> ++}<br>> ++<br>> ++<br>> ++static int parse_occ_response(char* d, occ_response_t* o)<br>> ++{<br>> ++      int b = 0;<br>> ++      int s = 0;<br>> ++      int ret = 0;<br>> ++      int dnum = 45;<br>> ++<br>> ++      o->sequence_num = d[0];<br>> ++      o->cmd_type = d[1];<br>> ++      o->rtn_status = d[2];<br>> ++      o->data_length = d[3] << 8;<br>> ++      o->data_length = o->data_length | d[4];<br>> ++      o->data.status = d[5];<br>> ++      o->data.ext_status = d[6];<br>> ++      o->data.occs_present = d[7];<br>> ++      o->data.config = d[8];<br>> ++      o->data.occ_state = d[9];<br>> ++      o->data.reserved0 = d[10];<br>> ++      o->data.reserved1 = d[11];<br>> ++      o->data.error_log_id = d[12];<br>> ++      o->data.error_log_addr_start = d[13] << 24;<br>> ++      o->data.error_log_addr_start = o->data.error_log_addr_start | d[14] << 16;<br>> ++      o->data.error_log_addr_start = o->data.error_log_addr_start | d[15] << 8;<br>> ++      o->data.error_log_addr_start = o->data.error_log_addr_start | d[16];<br>> ++      o->data.error_log_length = d[17] << 8;<br>> ++      o->data.error_log_length = o->data.error_log_length | d[18];<br>> ++      o->data.reserved2 = d[19];<br>> ++      o->data.reserved3 = d[20];<br>> ++      strncpy(&o->data.occ_code_level[0], (const char*)&d[21], 16);<br><br>You shouldn't need to play games with the types:<br><br> strncpy(o->data.occ_code_level, d[21], 16)<br><br>> ++      strncpy(&o->data.sensor_eye_catcher[0], (const char*)&d[37], 6);<br>> ++      o->data.sensor_eye_catcher[6]='\0';<br><br>use strscpy which provdies the null termination for you.<br><br>> ++      o->data.num_of_sensor_blocks=d[43];<br>> ++      o->data.sensor_data_version = d[44];<br>> ++<br>> ++      if (strcmp(o->data.sensor_eye_catcher, "SENSOR") != 0) {<br>> ++              printk("ERROR: SENSOR not found at byte 37 (%s)\n",o->data.sensor_eye_catcher);<br>> ++              return -1;<br>> ++      }<br>> ++<br>> ++      if (o->data.num_of_sensor_blocks == 0) {<br>> ++              printk("ERROR: SENSOR block num is 0\n");<br>> ++              return -1;<br>> ++      }<br><br>Should these checks be before you parse the data?<br><br>> ++<br>> ++      o->data.blocks = kzalloc(sizeof(sensor_data_block) * o->data.num_of_sensor_blocks, GFP_KERNEL);<br>> ++      if (o->data.blocks == NULL)<br>> ++              return -ENOMEM;<br>> ++<br>> ++      //printk("Reading %d sensor blocks\n", o->data.num_of_sensor_blocks);<br><br>use dev_dbg<br><br>> ++      o->temp_block_id = -1;<br>> ++      o->freq_block_id = -1;<br>> ++      o->power_block_id = -1;<br>> ++      o->caps_block_id = -1;<br>> ++      for(b = 0; b < o->data.num_of_sensor_blocks; b++) {<br>> ++              /* 8-byte sensor block head */<br>> ++              strncpy(&o->data.blocks[b].sensor_type[0], (const char*)&d[dnum], 4);<br>> ++              o->data.blocks[b].reserved0 = d[dnum+4];<br>> ++              o->data.blocks[b].sensor_format = d[dnum+5];<br>> ++              o->data.blocks[b].sensor_length = d[dnum+6];<br>> ++              o->data.blocks[b].num_of_sensors = d[dnum+7];<br>> ++              dnum = dnum + 8;<br>> ++<br>> ++              //printk("sensor block[%d]: type: %s, num_of_sensors: %d, sensor_length: %u\n",<br>> ++                      //b, o->data.blocks[b].sensor_type, o->data.blocks[b].num_of_sensors,<br>> ++                      //o->data.blocks[b].sensor_length);<br><br>dev_dbg<br><br>> ++<br>> ++              /* empty sensor block */<br>> ++              if (o->data.blocks[b].num_of_sensors <= 0)<br>> ++                      continue;<br>> ++              if (o->data.blocks[b].sensor_length == 0)<br>> ++                      continue;<br>> ++<br>> ++              if (strcmp(o->data.blocks[b].sensor_type, "FREQ") == 0) {<br>> ++                      o->data.blocks[b].sensor =<br>> ++                              kzalloc(sizeof(occ_sensor) * o->data.blocks[b].num_of_sensors, GFP_KERNEL);<br>> ++<br>> ++                      if (o->data.blocks[b].sensor == NULL) {<br>> ++                              ret = -ENOMEM;<br>> ++                              goto abort;<br><br>More commonly used is "out" or "error", but abort is fine if you want.<br><br>> ++                      }<br>> ++                      o->freq_block_id = b;<br>> ++                      for (s = 0; s < o->data.blocks[b].num_of_sensors; s++) {<br>> ++                              o->data.blocks[b].sensor[s].sensor_id = d[dnum] << 8;<br>> ++                              o->data.blocks[b].sensor[s].sensor_id =<br>> ++                                      o->data.blocks[b].sensor[s].sensor_id | d[dnum+1];<br>> ++                              o->data.blocks[b].sensor[s].value = d[dnum+2] << 8;<br>> ++                              o->data.blocks[b].sensor[s].value = o->data.blocks[b].sensor[s].value | d[dnum+3];<br>> ++                              //printk("sensor[%d]-[%d]: id: %u, value: %u\n",<br>> ++                              //      b, s, o->data.blocks[b].sensor[s].sensor_id, o->data.blocks[b].sensor[s].value);<br><br>dev_dbg<br><br>> ++                              dnum = dnum + o->data.blocks[b].sensor_length;<br>> ++                      }<br>> ++              }<br>> ++              else if (strcmp(o->data.blocks[b].sensor_type, "TEMP") == 0) {<br>> ++<br>> ++                      o->data.blocks[b].sensor =<br>> ++                              kzalloc(sizeof(occ_sensor) * o->data.blocks[b].num_of_sensors, GFP_KERNEL);<br>> ++<br>> ++                      if (o->data.blocks[b].sensor == NULL) {<br>> ++                              ret = -ENOMEM;<br>> ++                              goto abort;<br>> ++                      }<br>> ++<br>> ++                      o->temp_block_id = b;<br>> ++                      for (s = 0; s < o->data.blocks[b].num_of_sensors; s++) {<br>> ++                              o->data.blocks[b].sensor[s].sensor_id = d[dnum] << 8;<br>> ++                              o->data.blocks[b].sensor[s].sensor_id =<br>> ++                                      o->data.blocks[b].sensor[s].sensor_id | d[dnum+1];<br>> ++                              o->data.blocks[b].sensor[s].value = d[dnum+2] << 8;<br>> ++                              o->data.blocks[b].sensor[s].value = o->data.blocks[b].sensor[s].value | d[dnum+3];</tt><br><tt>> ++                              //printk("sensor[%d]-[%d]: id: %u, value: %u\n",<br>> ++                              //      b, s, o->data.blocks[b].sensor[s].sensor_id, o->data.blocks[b].sensor[s].value);<br>> ++                              dnum = dnum + o->data.blocks[b].sensor_length;<br>> ++                      }<br>> ++              }<br>> ++              else if (strcmp(o->data.blocks[b].sensor_type, "POWR") == 0) {<br>> ++<br>> ++                      o->data.blocks[b].powr =<br>> ++                              kzalloc(sizeof(powr_sensor) * o->data.blocks[b].num_of_sensors, GFP_KERNEL);<br>> ++<br>> ++                      if (o->data.blocks[b].powr == NULL) {<br>> ++                              ret = -ENOMEM;<br>> ++                              goto abort;<br>> ++                      }<br>> ++                      o->power_block_id = b;<br>> ++                      for (s = 0; s < o->data.blocks[b].num_of_sensors; s++) {<br>> ++                              o->data.blocks[b].powr[s].sensor_id = d[dnum] << 8;<br>> ++                              o->data.blocks[b].powr[s].sensor_id = o->data.blocks[b].powr[s].sensor_id | d[dnum+1];<br>> ++                              o->data.blocks[b].powr[s].update_tag = d[dnum+2] << 24;<br>> ++                              o->data.blocks[b].powr[s].update_tag = o->data.blocks[b].powr[s].update_tag | d[dnum+3] << 16;<br>> ++                              o->data.blocks[b].powr[s].update_tag = o->data.blocks[b].powr[s].update_tag | d[dnum+4] << 8;<br>> ++                              o->data.blocks[b].powr[s].update_tag = o->data.blocks[b].powr[s].update_tag | d[dnum+5];<br>> ++                              o->data.blocks[b].powr[s].accumulator = d[dnum+6] << 24;<br>> ++                              o->data.blocks[b].powr[s].accumulator = o->data.blocks[b].powr[s].accumulator | d[dnum+7] << 16;<br>> ++                              o->data.blocks[b].powr[s].accumulator = o->data.blocks[b].powr[s].accumulator | d[dnum+8] << 8;<br>> ++                              o->data.blocks[b].powr[s].accumulator = o->data.blocks[b].powr[s].accumulator | d[dnum+9];<br>> ++                              o->data.blocks[b].powr[s].value = d[dnum+10] << 8;<br>> ++                              o->data.blocks[b].powr[s].value = o->data.blocks[b].powr[s].value | d[dnum+11];<br>> ++<br>> ++                              //printk("sensor[%d]-[%d]: id: %u, value: %u\n",<br>> ++                              //      b, s, o->data.blocks[b].powr[s].sensor_id, o->data.blocks[b].powr[s].value);<br>> ++<br>> ++                              dnum = dnum + o->data.blocks[b].sensor_length;<br>> ++                      }<br>> ++              }<br>> ++              else if (strcmp(o->data.blocks[b].sensor_type, "CAPS") == 0) {<br>> ++<br>> ++                      o->data.blocks[b].caps =<br>> ++                              kzalloc(sizeof(caps_sensor) * o->data.blocks[b].num_of_sensors, GFP_KERNEL);<br>> ++<br>> ++                      if (o->data.blocks[b].caps == NULL) {<br>> ++                              ret = -ENOMEM;<br>> ++                              goto abort;<br>> ++                      }<br>> ++                      o->caps_block_id = b;<br>> ++                      for (s = 0; s < o->data.blocks[b].num_of_sensors; s++) {<br>> ++                              o->data.blocks[b].caps[s].curr_powercap = d[dnum] << 8;<br>> ++                              o->data.blocks[b].caps[s].curr_powercap = o->data.blocks[b].caps[s].curr_powercap | d[dnum+1];<br>> ++                              o->data.blocks[b].caps[s].curr_powerreading = d[dnum+2] << 8;<br>> ++                              o->data.blocks[b].caps[s].curr_powerreading = o->data.blocks[b].caps[s].curr_powerreading | d[dnum+3];<br>> ++                              o->data.blocks[b].caps[s].norm_powercap = d[dnum+4] << 8;<br>> ++                              o->data.blocks[b].caps[s].norm_powercap = o->data.blocks[b].caps[s].norm_powercap | d[dnum+5];<br>> ++                              o->data.blocks[b].caps[s].max_powercap = d[dnum+6] << 8;<br>> ++                              o->data.blocks[b].caps[s].max_powercap = o->data.blocks[b].caps[s].max_powercap| d[dnum+7];<br>> ++                              o->data.blocks[b].caps[s].min_powercap = d[dnum+8] << 8;<br>> ++                              o->data.blocks[b].caps[s].min_powercap = o->data.blocks[b].caps[s].min_powercap| d[dnum+9];<br>> ++                              o->data.blocks[b].caps[s].user_powerlimit = d[dnum+10] << 8;<br>> ++                              o->data.blocks[b].caps[s].user_powerlimit = o->data.blocks[b].caps[s].user_powerlimit| d[dnum+11];<br>> ++<br>> ++                              dnum = dnum + o->data.blocks[b].sensor_length;<br>> ++                              //printk("CAPS sensor #%d:\n", s);<br>> ++                              //printk("curr_powercap is %x \n", o->data.blocks[b].caps[s].curr_powercap);<br>> ++                              //printk("curr_powerreading is %x \n", o->data.blocks[b].caps[s].curr_powerreading);<br>> ++                              //printk("norm_powercap is %x \n", o->data.blocks[b].caps[s].norm_powercap);<br>> ++                              //printk("max_powercap is %x \n", o->data.blocks[b].caps[s].max_powercap);<br>> ++                              //printk("min_powercap is %x \n", o->data.blocks[b].caps[s].min_powercap);<br>> ++                              //printk("user_powerlimit is %x \n", o->data.blocks[b].caps[s].user_powerlimit);<br>> ++                      }<br>> ++<br>> ++              }<br>> ++              else {<br>> ++                      printk("ERROR: sensor type %s not supported\n", o->data.blocks[b].sensor_type);<br>> ++                      ret = -1;<br>> ++                      goto abort;<br>> ++              }<br>> ++      }<br>> ++<br>> ++      return 0;<br>> ++abort:<br>> ++      deinit_occ_resp_buf(o);<br>> ++      return ret;<br>> ++}<br>> ++<br>> ++/* us
ed for testing */<br>> ++char fake_occ_rsp[OCC_DATA_MAX] = {<br>> ++0x69, 0x00, 0x00, 0x00, 0xa4, 0xc3, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,<br>> ++0x00, 0x00, 0x00, 0x00, 0x00, 0x6f, 0x70, 0x5f, 0x6f, 0x63, 0x63, 0x5f, 0x31, 0x35, 0x30, 0x37,<br>> ++0x31, 0x36, 0x61, 0x00, 0x00, 0x53, 0x45, 0x4e, 0x53, 0x4f, 0x52, 0x04, 0x01, 0x54, 0x45, 0x4d,<br>> ++0x50, 0x00, 0x01, 0x04, 0x0a, 0x00 ,0x6a, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x6d, 0x00,<br>> ++0x00,0x00,0x6e,0x00, 0x00,0x00,0x6f,0x00, 0x00,0x00,0x70,0x00, 0x00,0x00,0x71,0x00,<br>> ++0x00,0x00,0x73,0x00, 0x00,0x00,0x74,0x00, 0x00,0x00,0x75,0x00, 0x00,0x46,0x52,0x45,<br>> ++0x51,0x00,0x01,0x04, 0x0a,0x00,0x76,0x00, 0x00,0x00,0x78,0x00, 0x00,0x00,0x79,0x00,<br>> ++0x00,0x00,0x7a,0x00, 0x00,0x00,0x7b,0x00, 0x00,0x00,0x7c,0x00, 0x00,0x00,0x7d,0x00,<br>> ++0x00,0x00,0x7f,0x00, 0x00,0x00,0x80,0x00, 0x00,0x00,0x81,0x00, 0x00,0x50,0x4f,0x57,<br>> ++0x52,0x00,0x01,0x0c, 0x00,0x43,0x41,0x50, 0x53,0x00,0x01,0x0c, 0x01,0x00,0x00,0x00,<br>> ++0x00,0x04,0xb0,0x09, 0x60,0x04,0x4c,0x00, 0x00,0x17,0xc5,};<br>> ++<br>> ++//#define DUMP_RAW 1<br>> ++<br>> ++static int occ_get_all(struct i2c_client *client, occ_response_t *occ_resp)<br>> ++{<br>> ++      char occ_data[OCC_DATA_MAX];<br>> ++      uint16_t num_bytes = 0;<br>> ++      int b = 0;<br>> ++      int ret = 0;<br>> ++/*<br>> ++      //Procedure to access SRAM where OCC data is located<br>> ++      occ_putscom(client, SCOM_OCC_SRAM_WOX, 0x08000000, 0x00000000);<br>> ++      occ_putscom(client, SCOM_OCC_SRAM_WAND, 0xFBFFFFFF, 0xFFFFFFFF);<br>> ++      occ_putscom(client, SCOM_OCC_SRAM_ADDR, OCC_RESPONSE_ADDR, 0x00000000);<br>> ++      occ_putscom(client, SCOM_OCC_SRAM_ADDR, OCC_RESPONSE_ADDR, 0x00000000);<br>> ++<br>> ++      occ_getscomb(client, SCOM_OCC_SRAM_DATA, occ_data, 0);<br>> ++<br>> ++*/<br><br>Remove commented out code.<br><br>> ++<br>> ++      // Init OCB<br>> ++      occ_putscom(client, OCB_STATUS_CONTROL_OR,  0x08000000, 0x00000000);<br>> ++      occ_putscom(client, OCB_STATUS_CONTROL_AND, 0xFBFFFFFF, 0xFFFFFFFF);<br>> ++<br>> ++      // Send poll command to OCC<br>> ++      occ_putscom(client, OCB_ADDRESS, OCC_COMMAND_ADDR, 0x00000000);<br>> ++      occ_putscom(client, OCB_ADDRESS, OCC_COMMAND_ADDR, 0x00000000);<br>> ++      occ_putscom(client, OCB_DATA, 0x00000001, 0x10001100);<br>> ++<br>> ++      // Trigger ATTN<br>> ++      occ_putscom(client, ATTN_DATA, 0x01010000, 0x00000000);<br>> ++<br>> ++      // TODO: check command status Refere to<br>> ++      // "1.6.2 OCC Command/Response Sequence" in OCC_OpenPwr_FW_Interfaces1.2.pdf<br><br>Use C style comments.<br><br>This needs more information as to why you're sleeping for so long.<br><br>> ++      // Use sleep as workaround<br>> ++      //msleep(2000);<br>> ++<br>> ++      // Get response data<br>> ++      occ_putscom(client, OCB_ADDRESS, OCC_RESPONSE_ADDR, 0x00000000);<br>> ++      occ_getscomb(client, OCB_DATA, occ_data, 0);<br>> ++<br>> ++      /* FIXME: use fake data to test driver without hw */<br>> ++      //printk("i2c-occ: using FAKE occ data\n");<br>> ++      //memcpy(&occ_data[0], &fake_occ_rsp[0], sizeof(occ_data));<br><br>Making your code testable is a good idea. We can't have commented out<br>code, but perhaps we could use debugfs to pass the driver fake data<br>from userspace?<br><br>> ++<br>> ++      num_bytes = get_occdata_length(occ_data);<br>> ++<br>> ++      //printk("OCC data length: %d\n", num_bytes);<br>> ++<br>> ++#ifdef DUMP_RAW<br>> ++      int i = 0;<br>> ++      printk("\nRAW data\n==================\n");<br>> ++      for (i = 0; i < 8; i++) {<br>> ++              if(i == 4) printk("  ");<br>> ++              printk("%02x", occ_data[i]);<br>> ++      }<br>> ++      printk("\n");<br>> ++#endif<br><br>Use something that can be run-time  enabled to dump this out. A sysfs file?<br><br>> ++<br>> ++      if (num_bytes > OCC_DATA_MAX) {<br>> ++              printk("ERROR: OCC data length must be < 4KB\n");<br>> ++              return -1;<br>> ++      }<br>> ++<br>> ++      if (num_bytes <= 0) {<br>> ++              printk("ERROR: OCC data length is zero\n");<br>> ++              return -1;<br>> ++      }<br>> ++<br>> ++      for (b = 8; b < num_bytes + 8; b = b + 8) {<br>> ++              //occ_getscomb(client, SCOM_OCC_SRAM_DATA, occ_data, b);<br>> ++              occ_getscomb(client, OCB_DATA, occ_data, b);<br>> ++#ifdef DUMP_RAW<br>> ++      for (i = 0; i < 8; i++) {<br>> ++              if(i == 4) printk("  ");<br>> ++              printk("%02x", occ_data[b+i]);<br>> ++      }<br>> ++      printk("\n");<br>> ++#endif<br>> ++<br>> ++      }<br>> ++<br>> ++      /* FIXME: use fake data to test driver without hw */<br>> ++      //memcpy(&occ_data[0], &fake_occ_rsp[0], sizeof(occ_data));<br>> ++<br>> ++      ret = parse_occ_response(occ_data, occ_resp);<br>> ++<br>> ++      return ret;<br>> ++}<br>> ++<br>> ++<br>> ++static int occ_update_device(struct device *dev)<br>> ++{<br>> ++      struct occ_drv_data *data = dev_get_drvdata(dev);<br>> ++      struct i2c_client *client = data->client;<br>> ++      int ret = 0;<br>> ++<br>> ++      mutex_lock(&data->update_lock);<br>> ++<br>> ++      if (time_after(jiffies, data->last_updated + data->sample_time)<br>> ++          || !data->valid) {<br>> ++              deinit_occ_resp_buf(&data->occ_resp);<br>> ++<br>> ++              ret = occ_get_all(client, &data->occ_resp);<br>> ++<br>> ++              data->last_updated = jiffies;<br>> ++              data->valid = 1;<br>> ++      }<br>> ++      mutex_unlock(&data->update_lock);<br>> ++<br>> ++      return ret;<br>> ++}<br>> ++<br>> ++/* ----------------------------------------------------------------------*/<br>> ++/* sysfs attributes for hwmon */<br>> ++<br>> ++static ssize_t show_occ_temp_input(struct device *hwmon_dev, struct device_attribute *da, char *buf)<br>> ++{<br>> ++      struct sensor_device_attribute *attr = to_sensor_dev_attr(da);<br>> ++      int n = attr->index;<br>> ++      struct device * dev = hwmon_dev->parent;<br>> ++      struct occ_drv_data *data = dev_get_drvdata(dev);<br>> ++      int ret = 0;<br>> ++      occ_sensor *sensor;<br>> ++      int val = 0;<br>> ++<br>> ++      ret = occ_update_device(dev);<br>> ++<br>> ++      if (ret != 0)<br>> ++      {<br>> ++              /* FIXME: to test fake data */<br>> ++              printk("ERROR: cannot get occ sensor data: %d\n", ret);<br>> ++              return ret;<br>> ++      }<br>> ++<br>> ++      if (data->occ_resp.data.blocks == NULL ||<br>> ++              data->occ_resp.data.blocks[data->occ_resp.temp_block_id].sensor == NULL)<br>> ++              return -1;<br>> ++<br>> ++      //printk("block_id: %d, sensor: %d\n", data->occ_resp.temp_block_id, n -1);<br>> ++      sensor = &data->occ_resp.data.blocks[data->occ_resp.temp_block_id].sensor[n - 1];<br>> ++      /* in millidegree Celsius */<br>> ++      val = sensor->value * 1000;<br>> ++      //printk("temp%d sensor value: %d\n", n, val);<br>> ++<br>> ++      //printk("------------- above are debug message, bellow is real output------------\n");<br>> ++      return sprintf(buf, "%d\n", val);<br>> ++}<br>> ++<br>> ++static ssize_t show_occ_temp_label(struct device *hwmon_dev, struct device_attribute *da, char *buf)<br>> ++{<br>> ++      struct sensor_device_attribute *attr = to_sensor_dev_attr(da);<br>> ++      int n = attr->index;<br>> ++      struct device *dev = hwmon_dev->parent;<br>> ++      struct occ_drv_data *data = dev_get_drvdata(dev);<br>> ++      int ret = 0;<br>> ++      occ_sensor *sensor;<br>> ++      int val = 0;<br>> ++<br>> ++      ret = occ_update_device(dev);<br>> ++<br>> ++      if (ret != 0)<br>> ++      {<br>> ++              /* FIXME: to test fake data */<br>> ++              printk("ERROR: cannot get occ sensor data: %d\n", ret);<br>> ++              return ret;<br>> ++      }<br>> ++<br>> ++      if (data->occ_resp.data.blocks == NULL ||<br>> ++              data->occ_resp.data.blocks[data->occ_resp.temp_block_id].sensor == NULL)<br>> ++              return -1;<br>> ++<br>> ++      //printk("temp_block_id: %d, sensor: %d\n", data->occ_resp.temp_block_id, n -1);<br>> ++      sensor = &data->occ_resp.data.blocks[data->occ_resp.temp_block_id].sensor[n - 1];<br>> ++      val = sensor->sensor_id;<br>> ++      //printk("temp%d sensor id: %d\n", n, val);<br>> ++<br>> ++      //printk("------------- above are debug message, bellow is real output------------\n");<br>> ++      return sprintf(buf, "%d\n", val);<br>> ++}<br>> ++<br>> ++static ssize_t show_occ_power_label(struct device *hwmon_dev, struct device_attribute *da, char *buf)<br>> ++{<br>> ++      struct sensor_device_attribute *attr = to_sensor_dev_attr(da);<br>> ++      int n = attr->index;<br>> ++      struct device *dev = hwmon_dev->parent;<br>> ++      struct occ_drv_data *data = dev_get_drvdata(dev);<br>> ++      int ret = 0;<br>> ++      powr_sensor *sensor;<br>> ++      int val = 0;<br>> ++<br>> ++      ret = occ_update_device(dev);<br>> ++<br>> ++      if (ret != 0)<br>> ++      {<br>> ++              /* FIXME: to test fake data */<br>> ++              printk("ERROR: cannot get occ sensor data: %d\n", ret);<br>> ++              return ret;<br>> ++      }<br>> ++<br>> ++      //printk("power_block_id: %d, sensor: %d\n", data->occ_resp.power_block_id, n -1);<br>> ++<br>> ++      if (data->occ_resp.data.blocks == NULL ||<br>> ++              data->occ_resp.data.blocks[data->occ_resp.power_block_id].powr == NULL)<br>> ++              return -1;<br>> ++<br>> ++      sensor = &data->occ_resp.data.blocks[data->occ_resp.power_block_id].powr[n - 1];<br>> ++      val = sensor->sensor_id;<br>> ++      //printk("power%d sensor id: %d\n", n, val);<br>> ++<br>> ++      //printk("------------- above are debug message, bellow is real output------------\n");<br>> ++      return sprintf(buf, "%d\n", val);<br>> ++}<br>> ++<br>> ++<br>> ++static ssize_t show_occ_power_input(struct device *hwmon_dev, struct device_attribute *da, char *buf)<br>> ++{<br>> ++      struct sensor_device_attribute *attr = to_sensor_dev_attr(da);<br>> ++      int n = attr->index;<br>> ++      struct device *dev = hwmon_dev->parent;<br>> ++      struct occ_drv_data *data = dev_get_drvdata(dev);<br>> ++      int ret = 0;<br>> ++      powr_sensor *sensor;<br>> ++      int val = 0;<br>> ++<br>> ++      ret = occ_update_device(dev);<br>> ++<br>> ++      if (ret != 0)<br>> ++      {<br>> ++              /* FIXME: to test fake data */<br>> ++              printk("ERROR: cannot get occ sensor data: %d\n", ret);<br>> ++              return ret;<br>> ++      }<br>> ++<br>> ++      //printk("power block_id: %d, sensor: %d\n", data->occ_resp.power_block_id, n -1);<br>> ++<br>> ++      if (data->occ_resp.data.blocks == NULL ||<br>> ++              data->occ_resp.data.blocks[data->occ_resp.power_block_id].powr == NULL)<br>> ++              return -1;<br>> ++<br>> ++<br>> ++      sensor = &data->occ_resp.data.blocks[data->occ_resp.power_block_id].powr[n - 1];<br>> ++      val = sensor->value;<br>> ++      //printk("power%d sensor value: %d\n", n, val);<br>> ++<br>> ++      //printk("------------- above are debug message, bellow is real output------------\n");<br>> ++      return sprintf(buf, "%d\n", val);<br>> ++}<br>> ++<br>> ++<br>> ++static ssize_t show_occ_freq_label(struct device *hwmon_dev, struct device_attribute *da, char *buf)<br>> ++{<br>> ++      struct sensor_device_attribute *attr = to_sensor_dev_attr(da);<br>> ++      int n = attr->index;<br>> ++      struct device *dev = hwmon_dev->parent;<br>> ++      struct occ_drv_data *data = dev_get_drvdata(dev);<br>> ++      int ret = 0;<br>> ++      occ_sensor *sensor;<br>> ++      int val = 0;<br>> ++<br>> ++      ret = occ_update_device(dev);<br>> ++<br>> ++      if (ret != 0)<br>> ++      {<br>> ++              /* FIXME: to test fake data */<br>> ++              printk("ERROR: cannot get occ sensor data: %d\n", ret);<br>> ++              return ret;<br>> ++      }<br>> ++<br>> ++      if (data->occ_resp.data.blocks == NULL ||<br>> ++              data->occ_resp.data.blocks[data->occ_resp.freq_block_id].sensor == NULL)<br>> ++              return -1;<br>> ++<br>> ++      //printk("freq_block_id: %d, sensor: %d\n", data->occ_resp.freq_block_id, n -1);<br>> ++      sensor = &data->occ_resp.data.blocks[data->occ_resp.freq_block_id].sensor[n - 1];<br>> ++      val = sensor->sensor_id;<br>> ++      //printk("freq%d sensor id: %d\n", n, val);<br>> ++<br>> ++      //printk("------------- above are debug message, bellow is real output------------\n");<br>> ++      return sprintf(buf, "%d\n", val);<br>> ++}<br>> ++<br>> ++<br>> ++static ssize_t show_occ_freq_input(struct device *hwmon_dev, struct device_attribute *da, char *buf)<br>> ++{<br>> ++      struct sensor_device_attribute *attr = to_sensor_dev_attr(da);<br>> ++      int n = attr->index;<br>> ++      struct device *dev = hwmon_dev->parent;<br>> ++      struct occ_drv_data *data = dev_get_drvdata(dev);<br>> ++      int ret = 0;<br>> ++      occ_sensor *sensor;<br>> ++      int val = 0;<br>> ++<br>> ++      ret = occ_update_device(dev);<br>> ++<br>> ++      if (ret != 0)<br>> ++      {<br>> ++              /* FIXME: to test fake data */<br>> ++              printk("ERROR: cannot get occ sensor data: %d\n", ret);<br>> ++              return ret;<br>> ++      }<br>> ++<br>> ++      if (data->occ_resp.data.blocks == NULL ||<br>> ++              data->occ_resp.data.blocks[data->occ_resp.freq_block_id].sensor == NULL)<br>> ++              return -1;<br>> ++<br>> ++      //printk("block_id: %d, sensor: %d\n", data->occ_resp.freq_block_id, n -1);<br>> ++      sensor = &data->occ_resp.data.blocks[data->occ_resp.freq_block_id].sensor[n - 1];<br>> ++      val = sensor->value;<br>> ++      //printk("freq%d sensor value: %d\n", n, val);<br>> ++<br>> ++      //printk("------------- above are debug message, bellow is real output------------\n");<br>> ++      return sprintf(buf, "%d\n", val);<br>> ++}<br>> ++<br>> ++static ssize_t show_occ_caps(struct device *hwmon_dev, struct device_attribute *da, char *buf)<br>> ++{<br>> ++      struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(da);<br>> ++      int nr = attr->nr;<br>> ++      int n = attr->index;<br>> ++      struct device *dev = hwmon_dev->parent;<br>> ++      struct occ_drv_data *data = dev_get_drvdata(dev);<br>> ++      int ret = 0;<br>> ++      caps_sensor *sensor;<br>> ++      int val = 0;<br>> ++<br>> ++      ret = occ_update_device(dev);<br>> ++      if (ret != 0)<br>> ++      {<br>> ++              /* FIXME: to test fake data */<br>> ++              printk("ERROR: cannot get occ sensor data: %d\n", ret);<br>> ++              return ret;<br>> ++      }<br>> ++<br>> ++      //printk("block_id: %d, sensor: %d, nr: %d\n", data->occ_resp.caps_block_id, n - 1, nr);<br>> ++      if (data->occ_resp.data.blocks == NULL ||<br>> ++              data->occ_resp.data.blocks[data->occ_resp.caps_block_id].caps == NULL)<br>> ++              return -1;<br>> ++<br>> ++      sensor = &data->occ_resp.data.blocks[data->occ_resp.caps_block_id].caps[n - 1];<br>> ++<br>> ++      switch (nr) {<br>> ++              case 0:<br>> ++                      val = sensor->curr_powercap;<br>> ++                      break;<br>> ++              case 1:<br>> ++                      val = sensor->curr_powerreading;<br>> ++                      break;<br>> ++              case 2:<br>> ++                      val = sensor->norm_powercap;<br>> ++                      break;<br>> ++              case 3:<br>> ++                      val = sensor->max_powercap;<br>> ++                      break;<br>> ++              case 4:<br>> ++                      val = sensor->min_powercap;<br>> ++                      break;<br>> ++              case 5:<br>> ++                      val = sensor->user_powerlimit;<br>> ++                      break;<br>> ++              default:<br>> ++                      val = 0;<br>> ++      }<br>> ++<br>> ++      //printk("caps%d sensor value: %d, nr: %d\n", n, val, nr);<br>> ++<br>> ++      //printk("------------- above are debug message, bellow is real output------------\n");<br>> ++      return sprintf(buf, "%d\n", val);<br>> ++}<br>> ++<br>> ++#if 0<br>> ++static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_occ_temp_input, NULL, 1);<br>> ++static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_occ_temp_input, NULL, 2);<br>> ++static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_occ_temp_input, NULL, 3);<br>> ++static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_occ_temp_input, NULL, 4);<br>> ++static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_occ_temp_input, NULL, 5);<br>> ++static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO, show_occ_temp_input, NULL, 6);<br>> ++static SENSOR_DEVICE_ATTR(temp7_input, S_IRUGO, show_occ_temp_input, NULL, 7);<br>> ++static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, show_occ_temp_input, NULL, 8);<br>> ++static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, show_occ_temp_input, NULL, 9);<br>> ++static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_occ_temp_label, NULL, 1);<br>> ++static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_occ_temp_label, NULL, 2);<br>> ++static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, show_occ_temp_label, NULL, 3);<br>> ++static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, show_occ_temp_label, NULL, 4);<br>> ++static SENSOR_DEVICE_ATTR(temp5_label, S_IRUGO, show_occ_temp_label, NULL, 5);<br>> ++static SENSOR_DEVICE_ATTR(temp6_label, S_IRUGO, show_occ_temp_label, NULL, 6);<br>> ++static SENSOR_DEVICE_ATTR(temp7_label, S_IRUGO, show_occ_temp_label, NULL, 7);<br>> ++static SENSOR_DEVICE_ATTR(temp8_label, S_IRUGO, show_occ_temp_label, NULL, 8);<br>> ++static SENSOR_DEVICE_ATTR(temp9_label, S_IRUGO, show_occ_temp_label, NULL, 9);<br>> ++<br>> ++static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, show_occ_power_input, NULL, 1);<br>> ++static SENSOR_DEVICE_ATTR(power1_label, S_IRUGO, show_occ_power_label, NULL, 1);<br>> ++static SENSOR_DEVICE_ATTR(power2_input, S_IRUGO, show_occ_power_input, NULL, 2);<br>> ++static SENSOR_DEVICE_ATTR(power2_label, S_IRUGO, show_occ_power_label, NULL, 2);<br>> ++static SENSOR_DEVICE_ATTR(power3_input, S_IRUGO, show_occ_power_input, NULL, 3);<br>> ++static SENSOR_DEVICE_ATTR(power3_label, S_IRUGO, show_occ_power_label, NULL, 3);<br>> ++static SENSOR_DEVICE_ATTR(power4_input, S_IRUGO, show_occ_power_input, NULL, 4);<br>> ++static SENSOR_DEVICE_ATTR(power4_label, S_IRUGO, show_occ_power_label, NULL, 4);<br>> ++<br>> ++static SENSOR_DEVICE_ATTR(freq1_input, S_IRUGO, show_occ_freq_input, NULL, 1);<br>> ++static SENSOR_DEVICE_ATTR(freq1_label, S_IRUGO, show_occ_freq_label, NULL, 1);<br>> ++static SENSOR_DEVICE_ATTR(freq2_input, S_IRUGO, show_occ_freq_input, NULL, 2);<br>> ++static SENSOR_DEVICE_ATTR(freq2_label, S_IRUGO, show_occ_freq_label, NULL, 2);<br>> ++static SENSOR_DEVICE_ATTR(freq3_input, S_IRUGO, show_occ_freq_input, NULL, 3);<br>> ++static SENSOR_DEVICE_ATTR(freq3_label, S_IRUGO, show_occ_freq_label, NULL, 3);<br>> ++static SENSOR_DEVICE_ATTR(freq4_input, S_IRUGO, show_occ_freq_input, NULL, 4);<br>> ++static SENSOR_DEVICE_ATTR(freq4_label, S_IRUGO, show_occ_freq_label, NULL, 4);<br>> ++<br>> ++static struct attribute *occ_attrs[] = {<br>> ++      &sensor_dev_attr_temp1_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp2_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp3_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp4_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp5_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp6_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp7_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp8_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp9_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp1_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp2_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp3_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp4_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp5_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp6_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp7_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp8_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_temp9_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_power1_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_power2_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_power3_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_power4_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_power1_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_power2_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_power3_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_power4_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_freq1_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_freq2_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_freq3_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_freq4_input.dev_attr.attr,<br>> ++      &sensor_dev_attr_freq1_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_freq2_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_freq3_label.dev_attr.attr,<br>> ++      &sensor_dev_attr_freq4_label.dev_attr.attr,<br>> ++<br>> ++      NULL<br>> ++};<br>> ++ATTRIBUTE_GROUPS(occ);<br>> ++<br>> ++#endif<br>> ++<br>> ++static struct sensor_device_attribute temp_input[] = {<br>> ++      SENSOR_ATTR(temp1_input, S_IRUGO, show_occ_temp_input, NULL, 1),<br>> ++      SENSOR_ATTR(temp2_input, S_IRUGO, show_occ_temp_input, NULL, 2),<br>> ++      SENSOR_ATTR(temp3_input, S_IRUGO, show_occ_temp_input, NULL, 3),<br>> ++      SENSOR_ATTR(temp4_input, S_IRUGO, show_occ_temp_input, NULL, 4),<br>> ++      SENSOR_ATTR(temp5_input, S_IRUGO, show_occ_temp_input, NULL, 5),<br>> ++      SENSOR_ATTR(temp6_input, S_IRUGO, show_occ_temp_input, NULL, 6),<br>> ++      SENSOR_ATTR(temp7_input, S_IRUGO, show_occ_temp_input, NULL, 7),<br>> ++      SENSOR_ATTR(temp8_input, S_IRUGO, show_occ_temp_input, NULL, 8),<br>> ++      SENSOR_ATTR(temp9_input, S_IRUGO, show_occ_temp_input, NULL, 9),<br>> ++      SENSOR_ATTR(temp10_input, S_IRUGO, show_occ_temp_input, NULL, 10),<br>> ++      SENSOR_ATTR(temp11_input, S_IRUGO, show_occ_temp_input, NULL, 11),<br>> ++      SENSOR_ATTR(temp12_input, S_IRUGO, show_occ_temp_input, NULL, 12),<br>> ++      SENSOR_ATTR(temp13_input, S_IRUGO, show_occ_temp_input, NULL, 13),<br>> ++      SENSOR_ATTR(temp14_input, S_IRUGO, show_occ_temp_input, NULL, 14),<br>> ++      SENSOR_ATTR(temp15_input, S_IRUGO, show_occ_temp_input, NULL, 15),<br>> ++      SENSOR_ATTR(temp16_input, S_IRUGO, show_occ_temp_input, NULL, 16),<br>> ++      SENSOR_ATTR(temp17_input, S_IRUGO, show_occ_temp_input, NULL, 17),<br>> ++      SENSOR_ATTR(temp18_input, S_IRUGO, show_occ_temp_input, NULL, 18),<br>> ++      SENSOR_ATTR(temp19_input, S_IRUGO, show_occ_temp_input, NULL, 19),<br>> ++      SENSOR_ATTR(temp20_input, S_IRUGO, show_occ_temp_input, NULL, 20),<br>> ++      SENSOR_ATTR(temp21_input, S_IRUGO, show_occ_temp_input, NULL, 21),<br>> ++      SENSOR_ATTR(temp22_input, S_IRUGO, show_occ_temp_input, NULL, 22),<br>> ++};<br>> ++<br>> ++static struct sensor_device_attribute temp_label[] = {<br>> ++      SENSOR_ATTR(temp1_label, S_IRUGO, show_occ_temp_label, NULL, 1),<br>> ++      SENSOR_ATTR(temp2_label, S_IRUGO, show_occ_temp_label, NULL, 2),<br>> ++      SENSOR_ATTR(temp3_label, S_IRUGO, show_occ_temp_label, NULL, 3),<br>> ++      SENSOR_ATTR(temp4_label, S_IRUGO, show_occ_temp_label, NULL, 4),<br>> ++      SENSOR_ATTR(temp5_label, S_IRUGO, show_occ_temp_label, NULL, 5),<br>> ++      SENSOR_ATTR(temp6_label, S_IRUGO, show_occ_temp_label, NULL, 6),<br>> ++      SENSOR_ATTR(temp7_label, S_IRUGO, show_occ_temp_label, NULL, 7),<br>> ++      SENSOR_ATTR(temp8_label, S_IRUGO, show_occ_temp_label, NULL, 8),<br>> ++      SENSOR_ATTR(temp9_label, S_IRUGO, show_occ_temp_label, NULL, 9),<br>> ++      SENSOR_ATTR(temp10_label, S_IRUGO, show_occ_temp_label, NULL, 10),<br>> ++      SENSOR_ATTR(temp11_label, S_IRUGO, show_occ_temp_label, NULL, 11),<br>> ++      SENSOR_ATTR(temp12_label, S_IRUGO, show_occ_temp_label, NULL, 12),</tt><br><tt>> ++      SENSOR_ATTR(temp13_label, S_IRUGO, show_occ_temp_label, NULL, 13),<br>> ++      SENSOR_ATTR(temp14_label, S_IRUGO, show_occ_temp_label, NULL, 14),<br>> ++      SENSOR_ATTR(temp15_label, S_IRUGO, show_occ_temp_label, NULL, 15),<br>> ++      SENSOR_ATTR(temp16_label, S_IRUGO, show_occ_temp_label, NULL, 16),<br>> ++      SENSOR_ATTR(temp17_label, S_IRUGO, show_occ_temp_label, NULL, 17),<br>> ++      SENSOR_ATTR(temp18_label, S_IRUGO, show_occ_temp_label, NULL, 18),<br>> ++      SENSOR_ATTR(temp19_label, S_IRUGO, show_occ_temp_label, NULL, 19),<br>> ++      SENSOR_ATTR(temp20_label, S_IRUGO, show_occ_temp_label, NULL, 20),<br>> ++      SENSOR_ATTR(temp21_label, S_IRUGO, show_occ_temp_label, NULL, 21),<br>> ++      SENSOR_ATTR(temp22_label, S_IRUGO, show_occ_temp_label, NULL, 22),<br>> ++<br>> ++};<br>> ++<br>> ++#define TEMP_UNIT_ATTRS(X)                      \<br>> ++{     &temp_input[X].dev_attr.attr,           \<br>> ++      &temp_label[X].dev_attr.attr,          \<br>> ++      NULL                                    \<br>> ++}<br>> ++<br>> ++/* 10-core CPU, occ has 22 temp sensors, more socket, more sensors */<br>> ++static struct attribute *occ_temp_attr[][3] = {<br>> ++      TEMP_UNIT_ATTRS(0),<br>> ++      TEMP_UNIT_ATTRS(1),<br>> ++      TEMP_UNIT_ATTRS(2),<br>> ++      TEMP_UNIT_ATTRS(3),<br>> ++      TEMP_UNIT_ATTRS(4),<br>> ++      TEMP_UNIT_ATTRS(5),<br>> ++      TEMP_UNIT_ATTRS(6),<br>> ++      TEMP_UNIT_ATTRS(7),<br>> ++      TEMP_UNIT_ATTRS(8),<br>> ++      TEMP_UNIT_ATTRS(9),<br>> ++      TEMP_UNIT_ATTRS(10),<br>> ++      TEMP_UNIT_ATTRS(11),<br>> ++      TEMP_UNIT_ATTRS(12),<br>> ++      TEMP_UNIT_ATTRS(13),<br>> ++      TEMP_UNIT_ATTRS(14),<br>> ++      TEMP_UNIT_ATTRS(15),<br>> ++      TEMP_UNIT_ATTRS(16),<br>> ++      TEMP_UNIT_ATTRS(17),<br>> ++      TEMP_UNIT_ATTRS(18),<br>> ++      TEMP_UNIT_ATTRS(19),<br>> ++      TEMP_UNIT_ATTRS(20),<br>> ++      TEMP_UNIT_ATTRS(21),<br>> ++};<br>> ++<br>> ++static const struct attribute_group occ_temp_attr_group[] = {<br>> ++      { .attrs = occ_temp_attr[0] },<br>> ++      { .attrs = occ_temp_attr[1] },<br>> ++      { .attrs = occ_temp_attr[2] },<br>> ++      { .attrs = occ_temp_attr[3] },<br>> ++      { .attrs = occ_temp_attr[4] },<br>> ++      { .attrs = occ_temp_attr[5] },<br>> ++      { .attrs = occ_temp_attr[6] },<br>> ++      { .attrs = occ_temp_attr[7] },<br>> ++      { .attrs = occ_temp_attr[8] },<br>> ++      { .attrs = occ_temp_attr[9] },<br>> ++      { .attrs = occ_temp_attr[10] },<br>> ++      { .attrs = occ_temp_attr[11] },<br>> ++      { .attrs = occ_temp_attr[12] },<br>> ++      { .attrs = occ_temp_attr[13] },<br>> ++      { .attrs = occ_temp_attr[14] },<br>> ++      { .attrs = occ_temp_attr[15] },<br>> ++      { .attrs = occ_temp_attr[16] },<br>> ++      { .attrs = occ_temp_attr[17] },<br>> ++      { .attrs = occ_temp_attr[18] },<br>> ++      { .attrs = occ_temp_attr[19] },<br>> ++      { .attrs = occ_temp_attr[20] },<br>> ++      { .attrs = occ_temp_attr[21] },<br>> ++};<br>> ++<br>> ++<br>> ++static struct sensor_device_attribute freq_input[] = {<br>> ++      SENSOR_ATTR(freq1_input, S_IRUGO, show_occ_freq_input, NULL, 1),<br>> ++      SENSOR_ATTR(freq2_input, S_IRUGO, show_occ_freq_input, NULL, 2),<br>> ++      SENSOR_ATTR(freq3_input, S_IRUGO, show_occ_freq_input, NULL, 3),<br>> ++      SENSOR_ATTR(freq4_input, S_IRUGO, show_occ_freq_input, NULL, 4),<br>> ++      SENSOR_ATTR(freq5_input, S_IRUGO, show_occ_freq_input, NULL, 5),<br>> ++      SENSOR_ATTR(freq6_input, S_IRUGO, show_occ_freq_input, NULL, 6),<br>> ++      SENSOR_ATTR(freq7_input, S_IRUGO, show_occ_freq_input, NULL, 7),<br>> ++      SENSOR_ATTR(freq8_input, S_IRUGO, show_occ_freq_input, NULL, 8),<br>> ++      SENSOR_ATTR(freq9_input, S_IRUGO, show_occ_freq_input, NULL, 9),<br>> ++      SENSOR_ATTR(freq10_input, S_IRUGO, show_occ_freq_input, NULL, 10),<br>> ++};<br>> ++<br>> ++static struct sensor_device_attribute freq_label[] = {<br>> ++      SENSOR_ATTR(freq1_label, S_IRUGO, show_occ_freq_label, NULL, 1),<br>> ++      SENSOR_ATTR(freq2_label, S_IRUGO, show_occ_freq_label, NULL, 2),<br>> ++      SENSOR_ATTR(freq3_label, S_IRUGO, show_occ_freq_label, NULL, 3),<br>> ++      SENSOR_ATTR(freq4_label, S_IRUGO, show_occ_freq_label, NULL, 4),<br>> ++      SENSOR_ATTR(freq5_label, S_IRUGO, show_occ_freq_label, NULL, 5),<br>> ++      SENSOR_ATTR(freq6_label, S_IRUGO, show_occ_freq_label, NULL, 6),<br>> ++      SENSOR_ATTR(freq7_label, S_IRUGO, show_occ_freq_label, NULL, 7),<br>> ++      SENSOR_ATTR(freq8_label, S_IRUGO, show_occ_freq_label, NULL, 8),<br>> ++      SENSOR_ATTR(freq9_label, S_IRUGO, show_occ_freq_label, NULL, 9),<br>> ++      SENSOR_ATTR(freq10_label, S_IRUGO, show_occ_freq_label, NULL, 10),<br>> ++<br>> ++};<br>> ++<br>> ++#define FREQ_UNIT_ATTRS(X)                      \<br>> ++{     &freq_input[X].dev_attr.attr,           \<br>> ++      &freq_label[X].dev_attr.attr,          \<br>> ++      NULL                                    \<br>> ++}<br>> ++<br>> ++/* 10-core CPU, occ has 22 freq sensors, more socket, more sensors */<br>> ++static struct attribute *occ_freq_attr[][3] = {<br>> ++      FREQ_UNIT_ATTRS(0),<br>> ++      FREQ_UNIT_ATTRS(1),<br>> ++      FREQ_UNIT_ATTRS(2),<br>> ++      FREQ_UNIT_ATTRS(3),<br>> ++      FREQ_UNIT_ATTRS(4),<br>> ++      FREQ_UNIT_ATTRS(5),<br>> ++      FREQ_UNIT_ATTRS(6),<br>> ++      FREQ_UNIT_ATTRS(7),<br>> ++      FREQ_UNIT_ATTRS(8),<br>> ++      FREQ_UNIT_ATTRS(9),<br>> ++};<br>> ++<br>> ++static const struct attribute_group occ_freq_attr_group[] = {<br>> ++      { .attrs = occ_freq_attr[0] },<br>> ++      { .attrs = occ_freq_attr[1] },<br>> ++      { .attrs = occ_freq_attr[2] },<br>> ++      { .attrs = occ_freq_attr[3] },<br>> ++      { .attrs = occ_freq_attr[4] },<br>> ++      { .attrs = occ_freq_attr[5] },<br>> ++      { .attrs = occ_freq_attr[6] },<br>> ++      { .attrs = occ_freq_attr[7] },<br>> ++      { .attrs = occ_freq_attr[8] },<br>> ++      { .attrs = occ_freq_attr[9] },<br>> ++};<br>> ++<br>> ++static struct sensor_device_attribute_2 caps_curr_powercap[] = {<br>> ++      SENSOR_ATTR_2(caps_curr_powercap, S_IRUGO, show_occ_caps, NULL, 0, 1),<br>> ++};<br>> ++static struct sensor_device_attribute_2 caps_curr_powerreading[] = {<br>> ++      SENSOR_ATTR_2(caps_curr_powerreading, S_IRUGO, show_occ_caps, NULL, 1, 1),<br>> ++};<br>> ++static struct sensor_device_attribute_2 caps_norm_powercap[] = {<br>> ++      SENSOR_ATTR_2(caps_norm_powercap, S_IRUGO, show_occ_caps, NULL, 2, 1),<br>> ++};<br>> ++static struct sensor_device_attribute_2 caps_max_powercap[] = {<br>> ++      SENSOR_ATTR_2(caps_max_powercap, S_IRUGO, show_occ_caps, NULL, 3, 1),<br>> ++};<br>> ++static struct sensor_device_attribute_2 caps_min_powercap[] = {<br>> ++      SENSOR_ATTR_2(caps_min_powercap, S_IRUGO, show_occ_caps, NULL, 4, 1),<br>> ++};<br>>
 ++static struct sensor_device_attribute_2 caps_user_powerlimit[] = {<br>> ++      SENSOR_ATTR_2(caps_user_powerlimit, S_IRUGO, show_occ_caps, NULL, 5, 1),<br>> ++};<br>> ++#define CAPS_UNIT_ATTRS(X)                      \<br>> ++{     &caps_curr_powercap[X].dev_attr.attr,           \<br>> ++      &caps_curr_powerreading[X].dev_attr.attr,           \<br>> ++      &caps_norm_powercap[X].dev_attr.attr,           \<br>> ++      &caps_max_powercap[X].dev_attr.attr,           \<br>> ++      &caps_min_powercap[X].dev_attr.attr,           \<br>> ++      &caps_user_powerlimit[X].dev_attr.attr,           \<br>> ++      NULL                                    \<br>> ++}<br>> ++<br>> ++/* 10-core CPU, occ has 1 caps sensors */<br>> ++static struct attribute *occ_caps_attr[][7] = {<br>> ++      CAPS_UNIT_ATTRS(0),<br>> ++};<br>> ++static const struct attribute_group occ_caps_attr_group[] = {<br>> ++      { .attrs = occ_caps_attr[0] },<br>> ++};<br>> ++<br>> ++static struct sensor_device_attribute power_input[] = {<br>> ++      SENSOR_ATTR(power1_input, S_IRUGO, show_occ_power_input, NULL, 1),<br>> ++      SENSOR_ATTR(power2_input, S_IRUGO, show_occ_power_input, NULL, 2),<br>> ++      SENSOR_ATTR(power3_input, S_IRUGO, show_occ_power_input, NULL, 3),<br>> ++      SENSOR_ATTR(power4_input, S_IRUGO, show_occ_power_input, NULL, 4),<br>> ++      SENSOR_ATTR(power5_input, S_IRUGO, show_occ_power_input, NULL, 5),<br>> ++      SENSOR_ATTR(power6_input, S_IRUGO, show_occ_power_input, NULL, 6),<br>> ++      SENSOR_ATTR(power7_input, S_IRUGO, show_occ_power_input, NULL, 7),<br>> ++      SENSOR_ATTR(power8_input, S_IRUGO, show_occ_power_input, NULL, 8),<br>> ++      SENSOR_ATTR(power9_input, S_IRUGO, show_occ_power_input, NULL, 9),<br>> ++      SENSOR_ATTR(power10_input, S_IRUGO, show_occ_power_input, NULL, 10),<br>> ++      SENSOR_ATTR(power11_input, S_IRUGO, show_occ_power_input, NULL, 11),<br>> ++};<br>> ++<br>> ++static struct sensor_device_attribute power_label[] = {<br>> ++      SENSOR_ATTR(power1_label, S_IRUGO, show_occ_power_label, NULL, 1),<br>> ++      SENSOR_ATTR(power2_label, S_IRUGO, show_occ_power_label, NULL, 2),<br>> ++      SENSOR_ATTR(power3_label, S_IRUGO, show_occ_power_label, NULL, 3),<br>> ++      SENSOR_ATTR(power4_label, S_IRUGO, show_occ_power_label, NULL, 4),<br>> ++      SENSOR_ATTR(power5_label, S_IRUGO, show_occ_power_label, NULL, 5),<br>> ++      SENSOR_ATTR(power6_label, S_IRUGO, show_occ_power_label, NULL, 6),<br>> ++      SENSOR_ATTR(power7_label, S_IRUGO, show_occ_power_label, NULL, 7),<br>> ++      SENSOR_ATTR(power8_label, S_IRUGO, show_occ_power_label, NULL, 8),<br>> ++      SENSOR_ATTR(power9_label, S_IRUGO, show_occ_power_label, NULL, 9),<br>> ++      SENSOR_ATTR(power10_label, S_IRUGO, show_occ_power_label, NULL, 10),<br>> ++      SENSOR_ATTR(power11_label, S_IRUGO, show_occ_power_label, NULL, 11),<br>> ++};<br>> ++<br>> ++#define POWER_UNIT_ATTRS(X)                      \<br>> ++{     &power_input[X].dev_attr.attr,           \<br>> ++      &power_label[X].dev_attr.attr,          \<br>> ++      NULL                                    \<br>> ++}<br>> ++<br>> ++/* 10-core CPU, occ has 11 power sensors, more socket, more sensors */<br>> ++static struct attribute *occ_power_attr[][3] = {<br>> ++      POWER_UNIT_ATTRS(0),<br>> ++      POWER_UNIT_ATTRS(1),<br>> ++      POWER_UNIT_ATTRS(2),<br>> ++      POWER_UNIT_ATTRS(3),<br>> ++      POWER_UNIT_ATTRS(4),<br>> ++      POWER_UNIT_ATTRS(5),<br>> ++      POWER_UNIT_ATTRS(6),<br>> ++      POWER_UNIT_ATTRS(7),<br>> ++      POWER_UNIT_ATTRS(8),<br>> ++      POWER_UNIT_ATTRS(9),<br>> ++      POWER_UNIT_ATTRS(10),<br>> ++};<br>> ++<br>> ++static const struct attribute_group occ_power_attr_group[] = {<br>> ++      { .attrs = occ_power_attr[0] },<br>> ++      { .attrs = occ_power_attr[1] },<br>> ++      { .attrs = occ_power_attr[2] },<br>> ++      { .attrs = occ_power_attr[3] },<br>> ++      { .attrs = occ_power_attr[4] },<br>> ++      { .attrs = occ_power_attr[5] },<br>> ++      { .attrs = occ_power_attr[6] },<br>> ++      { .attrs = occ_power_attr[7] },<br>> ++      { .attrs = occ_power_attr[8] },<br>> ++      { .attrs = occ_power_attr[9] },<br>> ++      { .attrs = occ_power_attr[10] },<br>> ++};<br>> ++<br>> ++static void occ_remove_sysfs_files(struct device *dev)<br>> ++{<br>> ++      int i = 0;<br>> ++<br>> ++      for (i = 0; i < ARRAY_SIZE(occ_temp_attr_group); i++)<br>> ++              sysfs_remove_group(&dev->kobj, &occ_temp_attr_group[i]);<br>> ++<br>> ++      for (i = 0; i < ARRAY_SIZE(occ_freq_attr_group); i++)<br>> ++              sysfs_remove_group(&dev->kobj, &occ_freq_attr_group[i]);<br>> ++<br>> ++      for (i = 0; i < ARRAY_SIZE(occ_power_attr_group); i++)<br>> ++              sysfs_remove_group(&dev->kobj, &occ_power_attr_group[i]);<br>> ++<br>> ++      for (i = 0; i < ARRAY_SIZE(occ_caps_attr_group); i++)<br>> ++              sysfs_remove_group(&dev->kobj, &occ_caps_attr_group[i]);<br>> ++}<br>> ++<br>> ++<br>> ++static int occ_create_sysfs_attribute(struct device *dev)<br>> ++{<br>> ++      /* The sensor number varies for different<br>> ++       * platform depending on core number. We'd better<br>> ++       * create them dynamically  */<br>> ++      struct occ_drv_data *data = dev_get_drvdata(dev);<br>> ++      int i = 0;<br>> ++      int num_of_sensors = 0;<br>> ++      int ret = 0;<br>> ++<br>> ++      /* get sensor number from occ. */<br>> ++      ret = occ_update_device(dev);<br>> ++      if (ret != 0)<br>> ++      {<br>> ++              /* FIXME: to test fake data */<br>> ++              printk("ERROR: cannot get occ sensor data: %d\n", ret);<br>> ++              return ret;<br>> ++      }<br>> ++<br>> ++      if (data->occ_resp.data.blocks == NULL)<br>> ++              return -1;<br>> ++<br>> ++      /* temp sensors */<br>> ++      if (data->occ_resp.temp_block_id >= 0)<br>> ++      {<br>> ++              num_of_sensors = data->occ_resp.data.blocks[data->occ_resp.temp_block_id].num_of_sensors;<br>> ++              for (i = 0; i < num_of_sensors; i++)<br>> ++              {<br>> ++                      //printk("create temp group: %d\n", i);<br>> ++                      //ret = sysfs_create_group(&dev->kobj, &occ_temp_attr_group[i]);<br>> ++                      ret = sysfs_create_group(&data->hwmon_dev->kobj, &occ_temp_attr_group[i]);<br>> ++                      if (ret)<br>> ++                      {<br>> ++                              dev_err(dev, "error create temp sysfs entry\n");<br>> ++                              goto error;<br>> ++                      }<br>> ++              }<br>> ++      }<br>> ++<br>> ++      /* freq sensors */<br>> ++      if (data->occ_resp.freq_block_id >= 0)<br>> ++      {<br>> ++              num_of_sensors = data->occ_resp.data.blocks[data->occ_resp.freq_block_id].num_of_sensors;<br>> ++              for (i = 0; i < num_of_sensors; i++)<br>> ++              {<br>> ++                      //printk("create freq group: %d\n", i);<br>> ++                      //ret = sysfs_create_group(&dev->kobj, &occ_temp_attr_group[i]);<br>> ++                      ret = sysfs_create_group(&data->hwmon_dev->kobj, &occ_freq_attr_group[i]);<br>> ++                      if (ret)<br>> ++                      {<br>> ++                              dev_err(dev, "error create freq sysfs entry\n");<br>> ++                              goto error;<br>> ++                      }<br>> ++              }<br>> ++      }<br>> ++<br>> ++      /* power sensors */<br>> ++      //printk("power_block_id: %d\n", data->occ_resp.power_block_id);<br>> ++      if (data->occ_resp.power_block_id >= 0)<br>> ++      {<br>> ++              num_of_sensors = data->occ_resp.data.blocks[data->occ_resp.power_block_id].num_of_sensors;<br>> ++              for (i = 0; i < num_of_sensors; i++)<br>> ++              {<br>> ++                      //printk("create power group: %d\n", i);<br>> ++                      //ret = sysfs_create_group(&dev->kobj, &occ_temp_attr_group[i]);<br>> ++                      ret = sysfs_create_group(&data->hwmon_dev->kobj, &occ_power_attr_group[i]);<br>> ++                      if (ret)<br>> ++                      {<br>> ++                              dev_err(dev, "error create power sysfs entry\n");<br>> ++                              goto error;<br>> ++                      }<br>> ++              }<br>> ++      }<br>> ++<br>> ++      /* caps sensors */<br>> ++      //printk("caps_block_id: %d\n", data->occ_resp.caps_block_id);<br>> ++      if (data->occ_resp.caps_block_id >= 0)<br>> ++      {<br>> ++              num_of_sensors = data->occ_resp.data.blocks[data->occ_resp.caps_block_id].num_of_sensors;<br>> ++              for (i = 0; i < num_of_sensors; i++)<br>> ++              {<br>> ++                      //printk("create caps group: %d\n", i);<br>> ++                      //ret = sysfs_create_group(&dev->kobj, &occ_temp_attr_group[i]);<br>> ++                      ret = sysfs_create_group(&data->hwmon_dev->kobj, &occ_caps_attr_group[i]);<br>> ++                      if (ret)<br>> ++                      {<br>> ++                              dev_err(dev, "error create caps sysfs entry\n");<br>> ++                              goto error;<br>> ++                      }<br>> ++              }<br>> ++      }<br>> ++<br>> ++      return 0;<br>> ++error:<br>> ++      occ_remove_sysfs_files(data->hwmon_dev);<br>> ++      return ret;<br>> ++}<br>> ++<br>> ++/*-----------------------------------------------------------------------*/<br>> ++/* device probe and removal */<br>> ++<br>> ++#define OCC_I2C_ADDR 0x50<br>> ++#define OCC_I2C_NAME "occ-i2c"<br>> ++<br>> ++enum occ_type {<br>> ++      occ_id,<br>> ++};<br>> ++<br>> ++static int occ_probe(struct i2c_client *client, const struct i2c_device_id *id)<br>> ++{<br>> ++      struct device *dev = &client->dev;<br>> ++      struct occ_drv_data *data;<br>> ++      unsigned long funcs;<br>> ++      struct device_node *np = dev->of_node;<br>> ++      //u32 pval = 0;<br>> ++      int ret = 0;<br>> ++<br>> ++      data = devm_kzalloc(dev, sizeof(struct occ_drv_data), GFP_KERNEL);<br>> ++      if (!data)<br>> ++              return -ENOMEM;<br>> ++<br>> ++      data->client = client;<br>> ++      i2c_set_clientdata(client, data);<br>> ++      mutex_init(&data->update_lock);<br>> ++      data->sample_time = HZ;<br>> ++<br>> ++      /* Yi: i2c-core should assign address to<br>> ++       * client when detection - but it does not work  FIXME  */<br>> ++      //client->addr = OCC_I2C_ADDR;<br>> ++<br>> ++      /* Yi: read address from device table */<br>> ++      //if (of_property_read_u32(np, "reg", &pval)) {<br>> ++      //      dev_err(&client->dev, "invalid reg\n");<br>> ++      //}<br>> ++      //client->addr = pval;<br>> ++<br>> ++      /* configure the driver */<br>> ++      //dev_dbg(dev, "occ register hwmon @0x%x\n", client->addr);<br>> ++      //data->hwmon_dev = hwmon_device_register_with_groups(dev, "occ",<br>> ++      //                                                  data, occ_groups);<br>> ++<br>> ++      /* Yi: try to create sysfs attributes dynamically */<br>> ++      data->hwmon_dev = hwmon_device_register(dev);<br>> ++      if (IS_ERR(data->hwmon_dev))<br>> ++              return PTR_ERR(data->hwmon_dev);<br>> ++<br>> ++      ret = occ_create_sysfs_attribute(dev);<br>> ++      if (ret)<br>> ++      {<br>> ++              hwmon_device_unregister(data->hwmon_dev);<br>> ++              return ret;<br>> ++      }<br>> ++<br>> ++      data->hwmon_dev->parent = dev;<br>> ++<br>> ++      //dev_dbg(dev, "%s: sensor '%s'\n",<br>> ++      //       dev_name(data->hwmon_dev), client->name);<br>> ++<br>> ++      funcs = i2c_get_functionality(client->adapter);<br>> ++      //dev_info(dev, "i2c adaptor supports function: 0x%lx\n", funcs);<br>> ++<br>> ++      /* Yi: seems always error? disable for now */<br>> ++      //occ_check_i2c_errors(client);<br>> ++<br>> ++      //dev_info(dev, "occ i2c driver ready: i2c addr@0x%x\n", client->addr);<br>> ++      printk("occ i2c driver ready: i2c addr@0x%x\n", client->addr);<br>> ++<br>> ++      return 0;<br>> ++}<br>> ++<br>> ++static int occ_remove(struct i2c_client *client)<br>> ++{<br>> ++      struct occ_drv_data *data = i2c_get_clientdata(client);<br>> ++<br>> ++      /* free allocated sensor memory */<br>> ++      deinit_occ_resp_buf(&data->occ_resp);<br>> ++<br>> ++      //occ_remove_sysfs_files(&client->dev);<br>> ++      occ_remove_sysfs_files(data->hwmon_dev);<br>> ++      hwmon_device_unregister(data->hwmon_dev);<br>> ++      return 0;<br>> ++}<br>> ++<br>> ++/* used for old-style board info */<br>> ++static const struct i2c_device_id occ_ids[] = {<br>> ++      { OCC_I2C_NAME, occ_id, },<br>> ++      { /* LIST END */ }<br>> ++};<br>> ++MODULE_DEVICE_TABLE(i2c, occ_ids);<br>> ++<br>> ++static const struct of_device_id i2c_occ_of_match[] = {<br>> ++      {.compatible = "ibm,occ-i2c"},<br>> ++      {},<br>> ++};<br>> ++<br>> ++MODULE_DEVICE_TABLE(of, i2c_occ_of_match);<br>> ++<br>> ++#ifdef CONFIG_PM<br>> ++static int occ_suspend(struct device *dev)<br>> ++{<br>> ++      //struct i2c_client *client = to_i2c_client(dev);<br>> ++      /* TODO */<br>> ++      return 0;<br>> ++}<br>> ++<br>> ++static int occ_resume(struct device *dev)<br>> ++{<br>> ++      //struct i2c_client *client = to_i2c_client(dev);<br>> ++      /* TODO */<br>> ++      return 0;<br>> ++}<br>> ++<br>> ++static const struct dev_pm_ops occ_dev_pm_ops = {<br>> ++      .suspend        = occ_suspend,<br>> ++      .resume         = occ_resume,<br>> ++};<br>> ++#define OCC_DEV_PM_OPS (&occ_dev_pm_ops)<br>> ++#else<br>> ++#define OCC_DEV_PM_OPS NULL<br>> ++#endif /* CONFIG_PM */<br>> ++<br>> ++/* Yi: i2c-core uses i2c-detect() to detect device in bellow address list.<br>> ++   If exists, address will be assigned to client.<br>> ++ * It is also possible to read address from device table. */<br>> ++static const unsigned short normal_i2c[] = {0x50, 0x51, I2C_CLIENT_END };<br>> ++<br>> ++/* Return 0 if detection is successful, -ENODEV otherwise */<br>> ++static int occ_detect(struct i2c_client *new_client,<br>> ++                     struct i2c_board_info *info)<br>> ++{<br>> ++      /* i2c-core need this function to create new device */<br>> ++      strncpy(info->type, OCC_I2C_NAME, sizeof(OCC_I2C_NAME));<br>> ++      return 0;<br>> ++}<br>> ++<br>> ++static struct i2c_driver occ_driver = {<br>> ++      .class          = I2C_CLASS_HWMON,<br>> ++      .driver = {<br>> ++              .name   = OCC_I2C_NAME,<br>> ++              .pm     = OCC_DEV_PM_OPS,<br>> ++              .of_match_table = i2c_occ_of_match,<br>> ++      },<br>> ++      .probe          = occ_probe,<br>> ++      .remove         = occ_remove,<br>> ++      .id_table       = occ_ids,<br>> ++      .address_list   = normal_i2c,<br>> ++      .detect         = occ_detect,<br>> ++};<br>> ++<br>> ++module_i2c_driver(occ_driver);<br>> ++<br>> ++#if 0<br>> ++/* Create new i2c device */<br>> ++static struct i2c_board_info my_dev_info[] __initdata = {<br>> ++      {<br>> ++              I2C_BOARD_INFO(OCC_I2C_NAME, 0x50),<br>> ++      },<br>> ++};<br>> ++<br>> ++static struct i2c_client *my_client;<br>> ++<br>> ++static int occ_init(void)<br>> ++{<br>> ++      static int sys_adap_bus_num = 3;<br>> ++      struct i2c_adapter* adap = i2c_get_adapter(sys_adap_bus_num);<br>> ++<br>> ++      if(adap==NULL) {<br>> ++              printk("[OCC-DEBUG] i2c_get_adapter fail!\n");<br>> ++              return -1;<br>> ++      }<br>> ++<br>> ++      my_client = i2c_new_device(adap, &my_dev_info[0]);<br>> ++      if( my_client==NULL ){<br>> ++              printk("[OCC-DEBUG] i2c_new_device fail!\n");<br>> ++              return -1;<br>> ++      }<br>> ++      i2c_put_adapter(adap);<br>> ++      return i2c_add_driver(&occ_driver);<br>> ++}<br>> ++<br>> ++static void __exit occ_exit(void)<br>> ++{<br>> ++      i2c_unregister_device(my_client);<br>> ++      i2c_del_driver(&occ_driver);<br>> ++}<br>> ++<br>> ++module_init(occ_init);<br>> ++module_exit(occ_exit);<br>> ++<br>> ++#endif<br>> ++<br>> ++MODULE_AUTHOR("Li Yi <shliyi@cn.ibm.com>");<br>> ++MODULE_DESCRIPTION("BMC OCC monitor driver");<br>> ++MODULE_LICENSE("GPL");<br>> diff --git a/meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/recipes-kernel/linux/linux-obmc_%.bbappend b/meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/recipes-kernel/linux/linux-obmc_%.bbappend<br>> index b106e5a..1099689 100644<br>> --- a/meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/recipes-kernel/linux/linux-obmc_%.bbappend<br>> +++ b/meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/recipes-kernel/linux/linux-obmc_%.bbappend<br>> @@ -1 +1,3 @@<br>>  FILESEXTRAPATHS_prepend := "${THISDIR}/linux-obmc:"<br>> +SRC_URI += "</tt><tt><a href="file://barreleye.cfg">file://barreleye.cfg</a></tt><tt>"<br>> +SRC_URI += "</tt><tt><a href="file://occ_hwmon.patch">file://occ_hwmon.patch</a></tt><tt>"<br>> --<br>> 2.6.3<br>><br>><br>> _______________________________________________<br>> openbmc mailing list<br>> openbmc@lists.ozlabs.org<br>> </tt><tt><a href="https://lists.ozlabs.org/listinfo/openbmc">https://lists.ozlabs.org/listinfo/openbmc</a></tt><tt><br>_______________________________________________<br>openbmc mailing list<br>openbmc@lists.ozlabs.org<br></tt><tt><a href="https://lists.ozlabs.org/listinfo/openbmc">https://lists.ozlabs.org/listinfo/openbmc</a></tt><tt><br></tt><br><BR>
</body></html>