-
Notifications
You must be signed in to change notification settings - Fork 124
[Deepin-Kernel-SIG] [linux 6.6-y] [UOS] sync and refactor ec support for phytium platform #1973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
opsiff
wants to merge
5
commits into
deepin-community:linux-6.6.y
Choose a base branch
from
opsiff:linux-6.6.y-2026-07-10-phytium-pio
base: linux-6.6.y
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9877848
ACPI: EC: workaround EC not work in phytium
opsiff 4fcf003
uos: phytium: ec: integrate EC/laptop driver over PIO port
opsiff dd845fa
phytium: ec: simplify EC core and laptop event/battery handling
opsiff 8e663d3
phytium: ec: use devm helpers and platform device parent for gsensor
opsiff 16e19a7
platform: arm64: phytium: move ec driver to platform directory
opsiff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17570,6 +17570,12 @@ F: drivers/usb/phytium/phytium_usb_v2* | |
| F: drivers/usb/typec/role-switch-phytium.c | ||
| F: arch/arm64/boot/dts/phytium/* | ||
| F: drivers/gpio/gpio-phytium* | ||
| F: drivers/platform/arm64/ | ||
| F: drivers/platform/arm64/phytium/* | ||
| F: include/linux/classtypes.h | ||
| F: include/linux/cputypes.h | ||
| F: lib/classtypes.c | ||
| F: lib/cputypes.c | ||
|
|
||
| QAT DRIVER | ||
| M: Giovanni Cabiddu <[email protected]> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # SPDX-License-Identifier: GPL-2.0-only | ||
|
|
||
| menuconfig ARM64_PLATFORM_DEVICES | ||
| bool "ARM64 platform devices" | ||
| depends on ARM64 | ||
| help | ||
| Say Y here to enable platform-specific drivers for ARM64 systems. | ||
| These drivers provide support for vendor-specific hardware that is | ||
| not covered by standard subsystem drivers, such as embedded | ||
| controllers, laptop hotkeys, backlight and power supply controls. | ||
|
|
||
| if ARM64_PLATFORM_DEVICES | ||
|
|
||
| config PHYTIUM_EC | ||
| bool "Phytium IT8528 Embedded Controller support" | ||
| depends on PHYTIUM_PIO | ||
| help | ||
| Enable support for the IT8528 Embedded Controller found on some | ||
| Phytium laptop platforms. This driver communicates with the EC | ||
| over the Phytium PIO (Programmed I/O) path and is required by the | ||
| Phytium laptop driver for battery, lid and hotkey support. | ||
|
|
||
| config PHYTIUM_LAPTOP | ||
| bool "Phytium laptop platform support" | ||
| depends on PHYTIUM_EC | ||
| select POWER_SUPPLY | ||
| select BACKLIGHT_CLASS_DEVICE | ||
| select INPUT_SPARSEKMAP | ||
| select HWMON | ||
| help | ||
| Enable laptop-specific support for Phytium platforms. This | ||
| provides power-supply reporting (AC and battery), backlight | ||
| control, lid status and Fn hotkey handling through the IT8528 | ||
| embedded controller. | ||
|
|
||
| endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # SPDX-License-Identifier: GPL-2.0 | ||
|
|
||
| obj-$(CONFIG_ARM64_PLATFORM_DEVICES) += phytium/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # SPDX-License-Identifier: GPL-2.0 | ||
| # | ||
| # Makefile for Phytium platform drivers. | ||
| # | ||
|
|
||
| obj-$(CONFIG_PHYTIUM_EC) += ec_it8528.o | ||
| obj-$(CONFIG_PHYTIUM_LAPTOP) += phyt_laptop.o ec_sensor.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,280 @@ | ||
| // SPDX-License-Identifier: GPL-2.0 | ||
| /* | ||
| * EC (Embedded Controller) for phytium platform | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation; either version 2 of the License, or | ||
| * (at your option) any later version. | ||
| */ | ||
|
|
||
| #include <linux/module.h> | ||
| #include <linux/spinlock.h> | ||
| #include <linux/delay.h> | ||
| #include <linux/io.h> | ||
| #include "ec_it8528.h" | ||
|
|
||
| /* This spinlock is dedicated for 62&66 ports and super io port access. */ | ||
| DEFINE_SPINLOCK(index_access_lock); | ||
|
|
||
| static int ec_wait_ibf_clear(void) | ||
| { | ||
| unsigned int timeout = EC_SEND_TIMEOUT; | ||
|
|
||
| while ((inb(EC_STS_PORT) & EC_IBF) && --timeout) | ||
| udelay(1); | ||
| if (!timeout) { | ||
| pr_err("Timeout waiting for EC IBF clear (status 0x%x)\n", | ||
| inb(EC_STS_PORT)); | ||
| return -ETIMEDOUT; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| static int ec_wait_obf_set(u8 *data) | ||
| { | ||
| unsigned int timeout = EC_RECV_TIMEOUT; | ||
|
|
||
| while (!(inb(EC_STS_PORT) & EC_OBF) && --timeout) | ||
| udelay(1); | ||
| if (!timeout) { | ||
| pr_err("Timeout waiting for EC OBF set (status 0x%x)\n", | ||
| inb(EC_STS_PORT)); | ||
| return -ETIMEDOUT; | ||
| } | ||
| *data = inb(EC_DAT_PORT); | ||
| return 0; | ||
| } | ||
|
|
||
| static int ec_send_byte(u8 byte, u16 port) | ||
| { | ||
| int ret = ec_wait_ibf_clear(); | ||
|
|
||
| if (ret) | ||
| return ret; | ||
| outb(byte, port); | ||
| return 0; | ||
| } | ||
|
|
||
| /* | ||
| * One EC transaction: command + optional write data + optional read data. | ||
| * The whole sequence is protected by index_access_lock. | ||
| */ | ||
| static int it8528_transaction(u8 command, const u8 *wdata, int wlen, | ||
| u8 *rdata, int rlen) | ||
| { | ||
| unsigned long flags; | ||
| int i, ret; | ||
| u8 val; | ||
|
|
||
| spin_lock_irqsave(&index_access_lock, flags); | ||
|
|
||
| ret = ec_send_byte(command, EC_CMD_PORT); | ||
| if (ret) | ||
| goto out; | ||
|
|
||
| for (i = 0; i < wlen; i++) { | ||
| ret = ec_send_byte(wdata[i], EC_DAT_PORT); | ||
| if (ret) | ||
| goto out; | ||
| } | ||
|
|
||
| for (i = 0; i < rlen; i++) { | ||
| ret = ec_wait_obf_set(&val); | ||
| if (ret) | ||
| goto out; | ||
| rdata[i] = val; | ||
| } | ||
|
|
||
| out: | ||
| spin_unlock_irqrestore(&index_access_lock, flags); | ||
| return ret; | ||
| } | ||
|
|
||
| unsigned char it8528_read(unsigned char index) | ||
| { | ||
| u8 value = 0; | ||
|
|
||
| it8528_transaction(CMD_READ_EC, &index, 1, &value, 1); | ||
| return value; | ||
| } | ||
| EXPORT_SYMBOL(it8528_read); | ||
|
|
||
| unsigned char it8528_read_all(unsigned char command, unsigned char index) | ||
| { | ||
| u8 value = 0; | ||
|
|
||
| it8528_transaction(command, &index, 1, &value, 1); | ||
| return value; | ||
| } | ||
| EXPORT_SYMBOL(it8528_read_all); | ||
|
|
||
| unsigned char it8528_read_noindex(unsigned char command) | ||
| { | ||
| u8 value = 0; | ||
|
|
||
| it8528_transaction(command, NULL, 0, &value, 1); | ||
| return value; | ||
| } | ||
| EXPORT_SYMBOL(it8528_read_noindex); | ||
|
|
||
| int it8528_write(unsigned char index, unsigned char data) | ||
| { | ||
| u8 wdata[2] = { index, data }; | ||
|
|
||
| return it8528_transaction(CMD_WRITE_EC, wdata, 2, NULL, 0); | ||
| } | ||
| EXPORT_SYMBOL(it8528_write); | ||
|
|
||
| int it8528_write_all(unsigned char command, unsigned char index, | ||
| unsigned char data) | ||
| { | ||
| u8 wdata[2] = { index, data }; | ||
|
|
||
| return it8528_transaction(command, wdata, 2, NULL, 0); | ||
| } | ||
| EXPORT_SYMBOL(it8528_write_all); | ||
|
|
||
| int it8528_write_noindex(unsigned char command, unsigned char data) | ||
| { | ||
| return it8528_transaction(command, &data, 1, NULL, 0); | ||
| } | ||
| EXPORT_SYMBOL(it8528_write_noindex); | ||
|
|
||
| bool it8528_get_ec_ibf_flags(void) | ||
| { | ||
| return !!(inb(EC_STS_PORT) & EC_IBF); | ||
| } | ||
| EXPORT_SYMBOL(it8528_get_ec_ibf_flags); | ||
|
|
||
| bool it8528_get_ec_obf_flags(void) | ||
| { | ||
| return !!(inb(EC_STS_PORT) & EC_OBF); | ||
| } | ||
| EXPORT_SYMBOL(it8528_get_ec_obf_flags); | ||
|
|
||
| bool it8528_get_ec_evt_flags(void) | ||
| { | ||
| return !!(inb(EC_STS_PORT) & EC_SCI_EVT); | ||
| } | ||
| EXPORT_SYMBOL(it8528_get_ec_evt_flags); | ||
|
|
||
| int it8528_query_get_event_num(void) | ||
| { | ||
| unsigned long flags; | ||
| unsigned int timeout; | ||
| u8 value = 0; | ||
| int ret; | ||
|
|
||
| spin_lock_irqsave(&index_access_lock, flags); | ||
|
|
||
| ret = ec_send_byte(CMD_GET_EVENT_NUM, EC_CMD_PORT); | ||
| if (ret) | ||
| goto out; | ||
|
|
||
| /* Give the EC a moment to consume the command. */ | ||
| timeout = EC_CMD_TIMEOUT; | ||
| while ((inb(EC_STS_PORT) & EC_IBF) && timeout--) | ||
| udelay(1); | ||
| if (!timeout) { | ||
| pr_err("EC QUERY SEQ: timeout\n"); | ||
| ret = -ETIMEDOUT; | ||
| goto out; | ||
| } | ||
|
|
||
| ret = ec_wait_obf_set(&value); | ||
| out: | ||
| spin_unlock_irqrestore(&index_access_lock, flags); | ||
| return ret ? ret : value; | ||
| } | ||
| EXPORT_SYMBOL(it8528_query_get_event_num); | ||
|
|
||
| int it8528_query_clean_event(void) | ||
| { | ||
| int ret; | ||
|
|
||
| while (inb(EC_STS_PORT) & EC_SCI_EVT) { | ||
| ret = it8528_query_get_event_num(); | ||
| if (ret <= 0) { | ||
| pr_info("Clean sci event done!\n"); | ||
| return ret; | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| EXPORT_SYMBOL(it8528_query_clean_event); | ||
|
|
||
| void it8528_ec_event_int_enable(void) | ||
| { | ||
| unsigned long flags; | ||
| unsigned int timeout; | ||
| int ret; | ||
|
|
||
| spin_lock_irqsave(&index_access_lock, flags); | ||
|
|
||
| ret = ec_send_byte(CMD_ENABLE_EVENT_EC, EC_CMD_PORT); | ||
| if (ret) | ||
| goto out; | ||
|
|
||
| timeout = EC_CMD_TIMEOUT; | ||
| while ((inb(EC_STS_PORT) & EC_IBF) && timeout--) | ||
| udelay(1); | ||
| if (!timeout) | ||
| pr_err("EC ENABLE EVENT INTERRUPT: timeout\n"); | ||
|
|
||
| out: | ||
| spin_unlock_irqrestore(&index_access_lock, flags); | ||
| } | ||
| EXPORT_SYMBOL(it8528_ec_event_int_enable); | ||
|
|
||
| void it8528_ec_event_int_disable(void) | ||
| { | ||
| unsigned long flags; | ||
| unsigned int timeout; | ||
| int ret; | ||
|
|
||
| spin_lock_irqsave(&index_access_lock, flags); | ||
|
|
||
| ret = ec_send_byte(CMD_DISABLE_EVENT_EC, EC_CMD_PORT); | ||
| if (ret) | ||
| goto out; | ||
|
|
||
| timeout = EC_CMD_TIMEOUT; | ||
| while ((inb(EC_STS_PORT) & EC_IBF) && timeout--) | ||
| udelay(1); | ||
| if (!timeout) | ||
| pr_err("EC DISABLE EVENT INTERRUPT: timeout\n"); | ||
|
|
||
| out: | ||
| spin_unlock_irqrestore(&index_access_lock, flags); | ||
| } | ||
| EXPORT_SYMBOL(it8528_ec_event_int_disable); | ||
|
|
||
| int it8528_init(void) | ||
| { | ||
| if (unlikely(!check_cpu_type())) { | ||
| pr_err("Stop init on non-Phytium CPU!\n"); | ||
| return -ENODEV; | ||
| } | ||
| return 0; | ||
| } | ||
| EXPORT_SYMBOL(it8528_init); | ||
|
|
||
| int lpc_ec_interrupt_occurs(void) | ||
| { | ||
| int data; | ||
|
|
||
| data = phytium_pio_get_int_status(); | ||
|
|
||
| if (data & EC_EVENT_BIT) | ||
| return 1; | ||
| return 0; | ||
| } | ||
| EXPORT_SYMBOL(lpc_ec_interrupt_occurs); | ||
|
|
||
| void lpc_interrupt_clear_all(void) | ||
| { | ||
| phytium_pio_clear_interrupt(0); | ||
| } | ||
| EXPORT_SYMBOL(lpc_interrupt_clear_all); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
U could create a new entry, since these patches r not authored by Phytium.