|
|
@@ -10,7 +10,6 @@
|
|
|
|
|
|
extern struct kobject *hwmon_kobj;
|
|
|
|
|
|
-
|
|
|
/* Helper functions for IO access */
|
|
|
static uint8_t hwm_read_reg(uint16_t hwm_base, uint8_t reg)
|
|
|
{
|
|
|
@@ -18,16 +17,11 @@ static uint8_t hwm_read_reg(uint16_t hwm_base, uint8_t reg)
|
|
|
return inb(hwm_base + HWM_DATA_OFFSET);
|
|
|
}
|
|
|
|
|
|
-static void hwm_write_reg(uint16_t hwm_base, uint8_t reg, uint8_t val)
|
|
|
-{
|
|
|
- outb(reg, hwm_base + HWM_INDEX_OFFSET);
|
|
|
- outb(val, hwm_base + HWM_DATA_OFFSET);
|
|
|
-}
|
|
|
-
|
|
|
static uint8_t hwm_read_reg_retry(uint16_t hwm_base, uint8_t reg)
|
|
|
{
|
|
|
uint8_t v = hwm_read_reg(hwm_base, reg);
|
|
|
- if (v == 0xFF) {
|
|
|
+ if (v == 0xFF)
|
|
|
+ {
|
|
|
v = hwm_read_reg(hwm_base, reg);
|
|
|
}
|
|
|
return v;
|
|
|
@@ -36,212 +30,31 @@ static uint8_t hwm_read_reg_retry(uint16_t hwm_base, uint8_t reg)
|
|
|
static int vin_raw_to_volt(uint8_t raw, int r_top_kohm, int r_bottom_kohm)
|
|
|
{
|
|
|
int vm = raw * 11;
|
|
|
- if (r_top_kohm > 0 && r_bottom_kohm > 0) {
|
|
|
+ if (r_top_kohm > 0 && r_bottom_kohm > 0)
|
|
|
+ {
|
|
|
vm = (vm * (r_top_kohm + r_bottom_kohm)) / r_bottom_kohm;
|
|
|
}
|
|
|
return vm;
|
|
|
}
|
|
|
|
|
|
-static int ec_raw_to_volt(uint8_t raw, int r_top_kohm, int r_bottom_kohm)
|
|
|
-{
|
|
|
- int vm = raw * 12; /* EC unit: 10mV */
|
|
|
- vm = (vm * (r_top_kohm + r_bottom_kohm)) / r_bottom_kohm;
|
|
|
- return vm ;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static int ec_wait_ibf(void)
|
|
|
-{
|
|
|
- int i = 0;
|
|
|
- while (inb(EC_CMD_PORT) & EC_IBF) {
|
|
|
- if (++i > TIMEOUT_LOOPS) {
|
|
|
- printk("Error: EC IBF Timeout!\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- udelay(1);
|
|
|
- }
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int ec_wait_obf(void)
|
|
|
-{
|
|
|
- int i = 0;
|
|
|
- while (!(inb(EC_CMD_PORT) & EC_OBF)) {
|
|
|
- if (++i > TIMEOUT_LOOPS) {
|
|
|
- printk("Error: EC OBF Timeout!\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
- udelay(1);
|
|
|
- }
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static int wait_ibf(void)
|
|
|
-{
|
|
|
- int i = 0;
|
|
|
- while (inb(EC_CMD_PORT) & EC_IBF)
|
|
|
- {
|
|
|
- if (++i > TIMEOUT_LOOPS)
|
|
|
- {
|
|
|
- return -1;
|
|
|
- }
|
|
|
- udelay(1);
|
|
|
- }
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int wait_obf(void)
|
|
|
-{
|
|
|
- int i = 0;
|
|
|
- while (!(inb(EC_CMD_PORT) & EC_OBF))
|
|
|
- {
|
|
|
- if (++i > TIMEOUT_LOOPS)
|
|
|
- {
|
|
|
- return -1;
|
|
|
- }
|
|
|
- udelay(1);
|
|
|
- }
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int ec_read_ram(uint8_t offset, uint8_t *data)
|
|
|
-{
|
|
|
- if (wait_ibf() < 0)
|
|
|
- return -1;
|
|
|
- outb(CMD_READ_RAM, EC_CMD_PORT);
|
|
|
-
|
|
|
- if (wait_ibf() < 0)
|
|
|
- return -1;
|
|
|
- outb(offset, EC_DATA_PORT);
|
|
|
-
|
|
|
- if (wait_obf() < 0)
|
|
|
- return -1;
|
|
|
- *data = inb(EC_DATA_PORT);
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int ec_write_ram(uint8_t offset, uint8_t data)
|
|
|
-{
|
|
|
- if (wait_ibf() < 0)
|
|
|
- return -1;
|
|
|
- outb(CMD_WRITE_RAM, EC_CMD_PORT);
|
|
|
-
|
|
|
- if (wait_ibf() < 0)
|
|
|
- return -1;
|
|
|
- outb(offset, EC_DATA_PORT);
|
|
|
-
|
|
|
- if (wait_ibf() < 0)
|
|
|
- return -1;
|
|
|
- outb(data, EC_DATA_PORT);
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int oem_ec_read_ram(uint8_t page, uint8_t offset, uint8_t *data)
|
|
|
-{
|
|
|
- unsigned char WEC, REC;
|
|
|
- switch(page)
|
|
|
- {
|
|
|
- case 0:
|
|
|
- {
|
|
|
- WEC = 0x96;
|
|
|
- REC = 0x95;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- case 1:
|
|
|
- {
|
|
|
- WEC = 0x98;
|
|
|
- REC = 0x97;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- default:
|
|
|
- {
|
|
|
- WEC = 0x81;
|
|
|
- REC = 0x80;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (wait_ibf() < 0)
|
|
|
- return -1;
|
|
|
- outb(REC, EC_CMD_PORT);
|
|
|
-
|
|
|
- if (wait_ibf() < 0)
|
|
|
- return -1;
|
|
|
- outb(offset, EC_DATA_PORT);
|
|
|
-
|
|
|
- if (wait_obf() < 0)
|
|
|
- return -1;
|
|
|
- *data = inb(EC_DATA_PORT);
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int oem_ec_write_ram(uint8_t page, uint8_t offset, uint8_t data)
|
|
|
-{
|
|
|
- unsigned char WEC, REC;
|
|
|
- switch(page)
|
|
|
- {
|
|
|
- case 0:
|
|
|
- {
|
|
|
- WEC = 0x96;
|
|
|
- REC = 0x95;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- case 1:
|
|
|
- {
|
|
|
- WEC = 0x98;
|
|
|
- REC = 0x97;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- default:
|
|
|
- {
|
|
|
- WEC = 0x81;
|
|
|
- REC = 0x80;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (wait_ibf() < 0)
|
|
|
- return -1;
|
|
|
- outb(WEC, EC_CMD_PORT);
|
|
|
-
|
|
|
- if (wait_ibf() < 0)
|
|
|
- return -1;
|
|
|
- outb(offset, EC_DATA_PORT);
|
|
|
-
|
|
|
- if (wait_ibf() < 0)
|
|
|
- return -1;
|
|
|
- outb(data, EC_DATA_PORT);
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
static ssize_t voltage_vbat_show(struct kobject *kobj, struct kobj_attribute *attr,
|
|
|
- char *buf)
|
|
|
+ char *buf)
|
|
|
{
|
|
|
- int vlotage = 0;
|
|
|
+ int vlotage = 0;
|
|
|
uint8_t raw;
|
|
|
- raw = hwm_read_reg_retry(IT8786_HWM_BASE_DEFAULT, 0x28);
|
|
|
+ raw = hwm_read_reg_retry(IT8786_HWM_BASE_DEFAULT, 0x28);
|
|
|
|
|
|
- vlotage = vin_raw_to_volt(raw, 10, 10);
|
|
|
+ vlotage = vin_raw_to_volt(raw, 10, 10);
|
|
|
|
|
|
- return sprintf(buf, "%d\n", vlotage);
|
|
|
+ return sprintf(buf, "%d\n", vlotage);
|
|
|
}
|
|
|
|
|
|
static ssize_t voltage_vbat_store(struct kobject *kobj, struct kobj_attribute *attr,
|
|
|
- const char *buf, size_t count)
|
|
|
+ const char *buf, size_t count)
|
|
|
{
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
static struct kobj_attribute voltage_vbat =
|
|
|
__ATTR(voltage_vbat, 0644, voltage_vbat_show, voltage_vbat_store);
|
|
|
|