Skip to content

Commit 8494baf

Browse files
committed
Merge remote-tracking branch 'upstream/hx20' into hx20
2 parents 6be7a57 + 9f8cf53 commit 8494baf

File tree

9 files changed

+442
-160
lines changed

9 files changed

+442
-160
lines changed

.github/workflows/cla.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "CLA Assistant"
2+
on:
3+
issue_comment:
4+
types: [created]
5+
pull_request_target:
6+
types: [opened,closed,synchronize]
7+
8+
jobs:
9+
CLAssistant:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: "CLA Assistant"
13+
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
14+
# Beta Release
15+
uses: cla-assistant/github-action@v2.1.3-beta
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
# the below token should have repo scope and must be manually added by you in the repository's secret
19+
PERSONAL_ACCESS_TOKEN : ${{ secrets.PERSONAL_ACCESS_TOKEN }}
20+
with:
21+
path-to-signatures: 'vendor/framework/signatures/version1/clamembers.json'
22+
path-to-document: 'https://github.com/FrameworkComputer/EmbeddedController/blob/hx20/FrameworkContributionLicenseAgreement.md' # e.g. a CLA or a DCO document
23+
# branch should not be protected
24+
branch: 'framework-cla'
25+
allowlist: kiram9,eclecticc,blue1112,Ko_Ko,Josh-Tsai,LeoCX-Tsai,MattWangGitHub,silverlee35
26+
27+
#below are the optional inputs - If the optional inputs are not given, then default values will be taken
28+
remote-organization-name: 'FrameworkComputer'
29+
remote-repository-name: 'EmbeddedController'
30+
#create-file-commit-message: 'For example: Creating file for storing CLA Signatures'
31+
#signed-commit-message: 'For example: $contributorName has signed the CLA in #$pullRequestNo'
32+
#custom-notsigned-prcomment: 'pull request comment with Introductory message to ask new contributors to sign'
33+
#custom-pr-sign-comment: 'The signature to be committed in order to sign the CLA'
34+
#custom-allsigned-prcomment: 'pull request comment when all contributors has signed, defaults to **CLA Assistant Lite bot** All Contributors have signed the CLA.'
35+
#lock-pullrequest-aftermerge: false - if you don't want this bot to automatically lock the pull request after merging (default - true)
36+
#use-dco-flag: true - If you are using DCO instead of CLA
37+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Contribution License Agreement
2+
3+
This Contribution License Agreement (“Agreement”) is agreed to by the party signing (“You”), and conveys certain license rights to Framework Computer Inc and its affiliates (“Framework”) for Your contributions to Framework open source projects. This Agreement is effective as of the latest signature date.
4+
5+
1. Definitions.
6+
7+
“Code” means the computer software code, whether in human-readable or machine-executable form, that is delivered by You to Framework under this Agreement.
8+
9+
“Project” means any of the projects owned or managed by Framework in which software is offered under a license approved by the Open Source Initiative (OSI) (www.opensource.org) and documentation offered under an OSI or a Creative Commons license (https://creativecommons.org/licenses).
10+
11+
“Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any Project, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of discussing and improving that Project, but excluding communication that is conspicuously marked or otherwise designated in writing by You as “Not a Submission.”
12+
13+
“Submission” means the Code and any other copyrightable material Submitted by You, including any associated comments and documentation.
14+
15+
2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any Project. This Agreement covers any and all Submissions that You, now or in the future (except as described in Section 4 below), Submit to any Project.
16+
17+
3. Originality of Work. You represent that each of Your Submissions is entirely Your original work. Should You wish to Submit materials that are not Your original work,You may Submit them separately to the Project if You (a) retain all copyright and license information that was in the materials as You received them, (b) in the description accompanying Your Submission, include the phrase “Submission containing materials of a third party:” followed by the names of the third party and any licenses or other restrictions of which You are aware, and (c) follow any other instructions in the Project’s written guidelines concerning Submissions.
18+
19+
4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your Submission is made in the course of Your work for an employer or Your employer has intellectual property rights in Your Submission by contract or applicable law, You must secure permission from Your employer to make the Submission before signing this Agreement. In that case, the term “You” in this Agreement will refer to You and the employer collectively. If You change employers in the future and desire to Submit additional Submissions for the new employer,then You agree to sign a new Agreement and secure permission from the new employer before Submitting those Submissions.
20+
21+
5. Licenses.
22+
23+
a. Copyright License. You grant Framework, and those who receive the Submission directly or indirectly from Framework, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the Submission to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute the Submission and such derivative works, and to sublicense any or all of the foregoing rights to third parties.
24+
25+
b. Patent License. You grant Framework, and those who receive the Submission directly or indirectly from Framework, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under Your patent claims that are necessarily infringed by the Submission or the combination of the Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and import or otherwise dispose of the Submission alone or with the Project.
26+
27+
c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are granted by implication, exhaustion, estoppel or otherwise.
28+
29+
6. Representations and Warranties. You represent that You are legally entitled to grant the above licenses.You represent that each of Your Submissions is entirely Your original work (except as You may have disclosed under Section 3). You represent that You have secured permission from Your employer to make the Submission in cases where Your Submission is made in the course of Your work for Your employer or Your employer has intellectual property rights in Your Submission by contract or applicable law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You have the necessary authority to bind the listed employer to the obligations contained in this Agreement. You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES EXPRESSLY STATED IN SECTIONS 3, 4, AND 6,THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
30+
31+
7. Notice to Framework. You agree to notify Framework in writing of any facts or circumstances of which You later become aware that would make Your representations in this Agreement inaccurate in any respect.
32+
33+
8. Information about Submissions. You agree that contributions to Projects and information about contributions may be maintained indefinitely and disclosed publicly, including Your name and other information that You submit with Your Submission.
34+
35+
9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of California, and the parties consent to exclusive jurisdiction and venue in the federal courts sitting in San Francisco County, California, unless no federal subject matter jurisdiction exists, in which case the parties consent to exclusive jurisdiction and venue in the Superior Court of California. The parties waive all defenses of lack of personal jurisdiction and forum non-conveniens.
36+
37+
10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and supersedes any and all prior agreements, understandings or communications, written or oral, between the parties relating to the subject matter hereof. This Agreement may be assigned by Framework.

board/hx20/battery.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ void battery_customize(struct charge_state_data *emi_info)
229229

230230
static void battery_percentage_control(void)
231231
{
232-
static enum ec_charge_control_mode before_mode;
233232
enum ec_charge_control_mode new_mode;
234233
int rv;
235234

@@ -250,15 +249,14 @@ static void battery_percentage_control(void)
250249
else
251250
new_mode = CHARGE_CONTROL_NORMAL;
252251

253-
if (before_mode != new_mode) {
254-
before_mode = new_mode;
255-
set_chg_ctrl_mode(before_mode);
252+
ccprints("Charge Limit mode = %d", new_mode);
253+
254+
set_chg_ctrl_mode(new_mode);
256255
#ifdef CONFIG_CHARGER_DISCHARGE_ON_AC
257-
rv = charger_discharge_on_ac(before_mode == CHARGE_CONTROL_DISCHARGE);
256+
rv = charger_discharge_on_ac(new_mode == CHARGE_CONTROL_DISCHARGE);
258257
#endif
259-
if (rv != EC_SUCCESS)
260-
ccprintf("fail to discharge.");
261-
}
258+
if (rv != EC_SUCCESS)
259+
ccprintf("fail to discharge.");
262260
}
263261
DECLARE_HOOK(HOOK_AC_CHANGE, battery_percentage_control, HOOK_PRIO_DEFAULT);
264262
DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, battery_percentage_control, HOOK_PRIO_DEFAULT);

board/hx20/board.c

Lines changed: 147 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "als.h"
1616
#include "bd99992gw.h"
1717
#include "button.h"
18+
#include "battery.h"
1819
#include "charge_state.h"
1920
#include "charger.h"
2021
#include "chipset.h"
@@ -496,6 +497,123 @@ static void check_chassis_open(int init)
496497
}
497498
}
498499

500+
void charge_gate_onoff(uint8_t enable)
501+
{
502+
int control0 = 0x0000;
503+
int control1 = 0x0000;
504+
505+
if (i2c_read16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
506+
ISL9241_REG_CONTROL0, &control0)) {
507+
CPRINTS("read gate control1 fail");
508+
}
509+
510+
if (i2c_read16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
511+
ISL9241_REG_CONTROL1, &control1)) {
512+
CPRINTS("read gate control1 fail");
513+
}
514+
515+
if (enable) {
516+
control0 &= ~ISL9241_CONTROL0_NGATE;
517+
control1 &= ~ISL9241_CONTROL1_BGATE;
518+
CPRINTS("B&N Gate off");
519+
} else {
520+
control0 |= ISL9241_CONTROL0_NGATE;
521+
control1 |= ISL9241_CONTROL1_BGATE;
522+
CPRINTS("B&N Gate on");
523+
}
524+
525+
if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
526+
ISL9241_REG_CONTROL0, control0)) {
527+
CPRINTS("Update gate control0 fail");
528+
}
529+
530+
if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
531+
ISL9241_REG_CONTROL1, control1)) {
532+
CPRINTS("Update gate control1 fail");
533+
}
534+
535+
}
536+
537+
538+
void charge_psys_onoff(uint8_t enable)
539+
{
540+
int control1 = 0x0000;
541+
int control4 = 0x0000;
542+
int data = 0x0000;
543+
544+
if (i2c_read16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
545+
ISL9241_REG_CONTROL1, &control1)) {
546+
CPRINTS("read psys control1 fail");
547+
}
548+
549+
if (enable) {
550+
control1 &= ~ISL9241_CONTROL1_IMON;
551+
control1 |= ISL9241_CONTROL1_PSYS;
552+
control4 &= ~ISL9241_CONTROL4_GP_COMPARATOR;
553+
data = 0x0B00; /* Set ACOK reference to 4.544V */
554+
CPRINTS("Power saving disable");
555+
} else {
556+
control1 |= ISL9241_CONTROL1_IMON;
557+
control1 &= ~ISL9241_CONTROL1_PSYS;
558+
control4 |= ISL9241_CONTROL4_GP_COMPARATOR;
559+
data = 0x0000; /* Set ACOK reference to 0V */
560+
CPRINTS("Power saving enable");
561+
}
562+
563+
if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
564+
ISL9241_REG_ACOK_REFERENCE, data)) {
565+
CPRINTS("Update ACOK reference fail");
566+
}
567+
568+
if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
569+
ISL9241_REG_CONTROL1, control1)) {
570+
CPRINTS("Update psys control1 fail");
571+
}
572+
573+
if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
574+
ISL9241_REG_CONTROL4, control4)) {
575+
CPRINTS("Update psys control4 fail");
576+
}
577+
}
578+
579+
580+
/*
581+
* Charger Low Power Mode Process
582+
* modern standby should not turn off Bfet and Nfet
583+
* DC only at S5 need enable
584+
* AC+DC at S5 & Fully charge need enable
585+
* AC+DC at Modern standby & Fully charge need enable
586+
* AC only need disable
587+
*/
588+
void charger_low_power_update(void)
589+
{
590+
static int ac_state;
591+
static int dc_state;
592+
int batt_status;
593+
594+
ac_state = extpower_is_present();
595+
dc_state = battery_is_present();
596+
battery_status(&batt_status);
597+
598+
if (dc_state && !ac_state &&
599+
chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
600+
charge_gate_onoff(0);
601+
charge_psys_onoff(0);
602+
} else if (ac_state && dc_state &&
603+
batt_status & STATUS_FULLY_CHARGED) {
604+
if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
605+
charge_gate_onoff(0);
606+
charge_psys_onoff(0);
607+
} else if (chipset_in_state(CHIPSET_STATE_STANDBY))
608+
charge_psys_onoff(0);
609+
} else if (ac_state && !dc_state) {
610+
charge_gate_onoff(1);
611+
charge_psys_onoff(1);
612+
}
613+
}
614+
DECLARE_HOOK(HOOK_AC_CHANGE, charger_low_power_update, HOOK_PRIO_DEFAULT);
615+
DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, charger_low_power_update, HOOK_PRIO_DEFAULT);
616+
499617
/* Initialize board. */
500618
static void board_init(void)
501619
{
@@ -529,6 +647,8 @@ static void board_chipset_startup(void)
529647
if (version > 6)
530648
gpio_set_level(GPIO_EN_INVPWR, 1);
531649

650+
charge_gate_onoff(1);
651+
charge_psys_onoff(1);
532652
}
533653
DECLARE_HOOK(HOOK_CHIPSET_STARTUP,
534654
board_chipset_startup,
@@ -537,16 +657,21 @@ DECLARE_HOOK(HOOK_CHIPSET_STARTUP,
537657
/* Called on AP S3 -> S5 transition */
538658
static void board_chipset_shutdown(void)
539659
{
540-
int version = board_get_version();
660+
int batt_status;
661+
662+
battery_status(&batt_status);
541663

542664
CPRINTS(" HOOK_CHIPSET_SHUTDOWN board_chipset_shutdown");
543665

544666
#ifdef CONFIG_EMI_REGION1
545667
lpc_set_host_event_mask(LPC_HOST_EVENT_SCI, 0);
546668
#endif
547-
if (version > 6)
548-
gpio_set_level(GPIO_EN_INVPWR, 0);
549669

670+
/* avoid AC mode enable charger LPM when charging*/
671+
if (!extpower_is_present() || (batt_status & STATUS_FULLY_CHARGED)) {
672+
charge_gate_onoff(0);
673+
charge_psys_onoff(0);
674+
}
550675
}
551676
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN,
552677
board_chipset_shutdown,
@@ -559,6 +684,7 @@ static void board_chipset_resume(void)
559684
/*gpio_set_level(GPIO_ENABLE_BACKLIGHT, 1);*/
560685
gpio_set_level(GPIO_EC_MUTE_L, 1);
561686
gpio_set_level(GPIO_CAM_EN, 1);
687+
charge_psys_onoff(1);
562688
}
563689
DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume,
564690
MOTION_SENSE_HOOK_PRIO-1);
@@ -572,6 +698,7 @@ static void board_chipset_suspend(void)
572698
gpio_set_level(GPIO_EC_MUTE_L, 0);
573699
gpio_set_level(GPIO_CAM_EN, 0);
574700
}
701+
charge_psys_onoff(0);
575702
}
576703
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND,
577704
board_chipset_suspend,
@@ -640,22 +767,26 @@ BUILD_ASSERT(ARRAY_SIZE(hx20_board_versions) == BOARD_VERSION_COUNT);
640767

641768
int get_hardware_id(enum adc_channel channel)
642769
{
643-
int version = BOARD_VERSION_UNKNOWN;
770+
int version[ADC_CH_COUNT] = {BOARD_VERSION_UNKNOWN};
644771
int mv;
645772
int i;
646773

647-
mv = adc_read_channel(ADC_AD_BID);
774+
if (channel >= ADC_CH_COUNT) {
775+
return BOARD_VERSION_UNKNOWN;
776+
}
777+
778+
mv = adc_read_channel(channel);
648779

649780
if (mv == ADC_READ_ERROR)
650781
return BOARD_VERSION_UNKNOWN;
651782

652783
for (i = 0; i < BOARD_VERSION_COUNT; i++)
653784
if (mv < hx20_board_versions[i].thresh_mv) {
654-
version = hx20_board_versions[i].version;
655-
return version;
785+
version[channel] = hx20_board_versions[i].version;
786+
return version[channel];
656787
}
657788

658-
return version;
789+
return version[channel];
659790
}
660791

661792
int board_get_version(void)
@@ -775,15 +906,20 @@ void charger_update(void)
775906
{
776907
static int pre_ac_state;
777908
static int pre_dc_state;
778-
uint16_t val = 0x0000;
909+
int val = 0x0000;
779910

780911
if (pre_ac_state != extpower_is_present() ||
781912
pre_dc_state != battery_is_present())
782913
{
783914
CPRINTS("update charger!!");
784915

785-
val = ISL9241_CONTROL1_PROCHOT_REF_6800 |
786-
ISL9241_CONTROL1_SWITCH_FREQ | ISL9241_CONTROL1_PSYS;
916+
if (i2c_read16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
917+
ISL9241_REG_CONTROL1, &val)) {
918+
CPRINTS("read charger control1 fail");
919+
}
920+
921+
val |= (ISL9241_CONTROL1_PROCHOT_REF_6800 |
922+
ISL9241_CONTROL1_SWITCH_FREQ);
787923

788924
if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
789925
ISL9241_REG_CONTROL1, val)) {

0 commit comments

Comments
 (0)