aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/platform')
-rw-r--r--drivers/platform/x86/Kconfig4
-rw-r--r--drivers/platform/x86/compal-laptop.c43
2 files changed, 44 insertions, 3 deletions
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index c69bb703f483..2f9026d31444 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -309,8 +309,8 @@ config COMPAL_LAPTOP
309 This is a driver for laptops built by Compal, and some models by 309 This is a driver for laptops built by Compal, and some models by
310 other brands (e.g. Dell, Toshiba). 310 other brands (e.g. Dell, Toshiba).
311 311
312 It adds support for rfkill, Bluetooth, WLAN and LCD brightness 312 It adds support for rfkill, Bluetooth, WLAN, LCD brightness, hwmon
313 control. 313 and battery charging level control.
314 314
315 For a (possibly incomplete) list of supported laptops, please refer 315 For a (possibly incomplete) list of supported laptops, please refer
316 to: Documentation/platform/x86-laptop-drivers.txt 316 to: Documentation/platform/x86-laptop-drivers.txt
diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
index f2706d27adff..e1c2b6d4b24a 100644
--- a/drivers/platform/x86/compal-laptop.c
+++ b/drivers/platform/x86/compal-laptop.c
@@ -151,6 +151,8 @@
151#define BAT_STATUS2 0xF1 151#define BAT_STATUS2 0xF1
152#define BAT_STOP_CHARGE1 0xF2 152#define BAT_STOP_CHARGE1 0xF2
153#define BAT_STOP_CHARGE2 0xF3 153#define BAT_STOP_CHARGE2 0xF3
154#define BAT_CHARGE_LIMIT 0x03
155#define BAT_CHARGE_LIMIT_MAX 100
154 156
155#define BAT_S0_DISCHARGE (1 << 0) 157#define BAT_S0_DISCHARGE (1 << 0)
156#define BAT_S0_DISCHRG_CRITICAL (1 << 2) 158#define BAT_S0_DISCHRG_CRITICAL (1 << 2)
@@ -601,6 +603,12 @@ static int bat_get_property(struct power_supply *psy,
601 case POWER_SUPPLY_PROP_CHARGE_NOW: 603 case POWER_SUPPLY_PROP_CHARGE_NOW:
602 val->intval = ec_read_u16(BAT_CHARGE_NOW) * 1000; 604 val->intval = ec_read_u16(BAT_CHARGE_NOW) * 1000;
603 break; 605 break;
606 case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT:
607 val->intval = ec_read_u8(BAT_CHARGE_LIMIT);
608 break;
609 case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX:
610 val->intval = BAT_CHARGE_LIMIT_MAX;
611 break;
604 case POWER_SUPPLY_PROP_CAPACITY: 612 case POWER_SUPPLY_PROP_CAPACITY:
605 val->intval = ec_read_u8(BAT_CAPACITY); 613 val->intval = ec_read_u8(BAT_CAPACITY);
606 break; 614 break;
@@ -634,6 +642,36 @@ static int bat_get_property(struct power_supply *psy,
634 return 0; 642 return 0;
635} 643}
636 644
645static int bat_set_property(struct power_supply *psy,
646 enum power_supply_property psp,
647 const union power_supply_propval *val)
648{
649 int level;
650
651 switch (psp) {
652 case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT:
653 level = val->intval;
654 if (level < 0 || level > BAT_CHARGE_LIMIT_MAX)
655 return -EINVAL;
656 if (ec_write(BAT_CHARGE_LIMIT, level) < 0)
657 return -EIO;
658 break;
659 default:
660 break;
661 }
662 return 0;
663}
664
665static int bat_writeable_property(struct power_supply *psy,
666 enum power_supply_property psp)
667{
668 switch (psp) {
669 case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT:
670 return 1;
671 default:
672 return 0;
673 }
674}
637 675
638 676
639 677
@@ -726,6 +764,8 @@ static enum power_supply_property compal_bat_properties[] = {
726 POWER_SUPPLY_PROP_POWER_NOW, 764 POWER_SUPPLY_PROP_POWER_NOW,
727 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 765 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
728 POWER_SUPPLY_PROP_CHARGE_NOW, 766 POWER_SUPPLY_PROP_CHARGE_NOW,
767 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
768 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
729 POWER_SUPPLY_PROP_CAPACITY, 769 POWER_SUPPLY_PROP_CAPACITY,
730 POWER_SUPPLY_PROP_CAPACITY_LEVEL, 770 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
731 POWER_SUPPLY_PROP_TEMP, 771 POWER_SUPPLY_PROP_TEMP,
@@ -880,11 +920,12 @@ static const struct power_supply_desc psy_bat_desc = {
880 .properties = compal_bat_properties, 920 .properties = compal_bat_properties,
881 .num_properties = ARRAY_SIZE(compal_bat_properties), 921 .num_properties = ARRAY_SIZE(compal_bat_properties),
882 .get_property = bat_get_property, 922 .get_property = bat_get_property,
923 .set_property = bat_set_property,
924 .property_is_writeable = bat_writeable_property,
883}; 925};
884 926
885static void initialize_power_supply_data(struct compal_data *data) 927static void initialize_power_supply_data(struct compal_data *data)
886{ 928{
887
888 ec_read_sequence(BAT_MANUFACTURER_NAME_ADDR, 929 ec_read_sequence(BAT_MANUFACTURER_NAME_ADDR,
889 data->bat_manufacturer_name, 930 data->bat_manufacturer_name,
890 BAT_MANUFACTURER_NAME_LEN); 931 BAT_MANUFACTURER_NAME_LEN);