Skip to content

Commit 86aa721

Browse files
committed
Merge tag 'chrome-platform-v6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux
Pull chrome platform updates from Tzung-Bi Shih: "New: - Support ECC in chromeos_pstore - Allow to control power and data role via sysfs in cros_ec_typec Improvements: - Defer probe when the dependencies are not ready in cros_ec_typec - Retry when a sensor is not ready in cros_ec_sensorhub Fixes: - Unregister the blocking notifier as well when unregistering the struct cros_ec_device. Cleanups: - Remove redundant code and leverage more suitable helper macro in chromeos_laptop - Fix typo" * tag 'chrome-platform-v6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux: platform/chrome: Fix typo in CROS_USBPD_NOTIFY help text platform/chrome: cros_ec_typec: Check ec platform device pointer platform/chrome: cros_ec: Unregister notifier in cros_ec_unregister() platform/chrome: cros_ec_typec: Add role swap ops platform/chrome: chromeos_laptop: Replace open coded variant of DEFINE_RES_IRQ() platform/chrome: chromeos_laptop: Remove duplicate check platform/chrome: cros_ec_sensorhub: Retries when a sensor is not ready platform/chrome: chromeos_pstore: Add ecc_size module parameter platform/chrome: cros_ec_typec: Defer probe on missing EC parent
2 parents 9669b24 + cc2d5b7 commit 86aa721

File tree

6 files changed

+121
-14
lines changed

6 files changed

+121
-14
lines changed

drivers/platform/chrome/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ config CROS_USBPD_NOTIFY
286286
default MFD_CROS_EC_DEV
287287
help
288288
If you say Y here, you get support for Type-C PD event notifications
289-
from the ChromeOS EC. On ACPI platorms this driver will bind to the
289+
from the ChromeOS EC. On ACPI platforms this driver will bind to the
290290
GOOG0003 ACPI device, and on platforms which don't have this device it
291291
will get initialized on ECs which support the feature
292292
EC_FEATURE_USB_PD.

drivers/platform/chrome/chromeos_laptop.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,9 @@ static int __init chromeos_laptop_setup_irq(struct i2c_peripheral *i2c_dev)
726726
if (irq < 0)
727727
return irq;
728728

729-
i2c_dev->irq_resource = (struct resource)
730-
DEFINE_RES_NAMED(irq, 1, NULL,
731-
IORESOURCE_IRQ | i2c_dev->irqflags);
729+
i2c_dev->irq_resource = DEFINE_RES_IRQ(irq);
730+
i2c_dev->irq_resource.flags |= i2c_dev->irqflags;
731+
732732
i2c_dev->board_info.resources = &i2c_dev->irq_resource;
733733
i2c_dev->board_info.num_resources = 1;
734734
}
@@ -782,8 +782,7 @@ chromeos_laptop_prepare_i2c_peripherals(struct chromeos_laptop *cros_laptop,
782782
while (--i >= 0) {
783783
i2c_dev = &i2c_peripherals[i];
784784
info = &i2c_dev->board_info;
785-
if (!IS_ERR_OR_NULL(info->fwnode))
786-
fwnode_remove_software_node(info->fwnode);
785+
fwnode_remove_software_node(info->fwnode);
787786
}
788787
kfree(i2c_peripherals);
789788
return error;

drivers/platform/chrome/chromeos_pstore.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include <linux/platform_device.h>
1010
#include <linux/pstore_ram.h>
1111

12+
static int ecc_size;
13+
module_param(ecc_size, int, 0400);
14+
MODULE_PARM_DESC(ecc_size, "ECC parity data size in bytes. A positive value enables ECC for the ramoops region.");
15+
1216
static const struct dmi_system_id chromeos_pstore_dmi_table[] __initconst = {
1317
{
1418
/*
@@ -117,6 +121,9 @@ static int __init chromeos_pstore_init(void)
117121
{
118122
bool acpi_dev_found;
119123

124+
if (ecc_size > 0)
125+
chromeos_ramoops_data.ecc_info.ecc_size = ecc_size;
126+
120127
/* First check ACPI for non-hardcoded values from firmware. */
121128
acpi_dev_found = chromeos_check_acpi();
122129

drivers/platform/chrome/cros_ec.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ EXPORT_SYMBOL(cros_ec_register);
318318
*/
319319
void cros_ec_unregister(struct cros_ec_device *ec_dev)
320320
{
321+
if (ec_dev->mkbp_event_supported)
322+
blocking_notifier_chain_unregister(&ec_dev->event_notifier,
323+
&ec_dev->notifier_ready);
321324
platform_device_unregister(ec_dev->pd);
322325
platform_device_unregister(ec_dev->ec);
323326
mutex_destroy(&ec_dev->lock);

drivers/platform/chrome/cros_ec_sensorhub.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/init.h>
1010
#include <linux/device.h>
11+
#include <linux/delay.h>
1112
#include <linux/mod_devicetable.h>
1213
#include <linux/module.h>
1314
#include <linux/platform_data/cros_ec_commands.h>
@@ -18,6 +19,7 @@
1819
#include <linux/types.h>
1920

2021
#define DRV_NAME "cros-ec-sensorhub"
22+
#define CROS_EC_CMD_INFO_RETRIES 50
2123

2224
static void cros_ec_sensorhub_free_sensor(void *arg)
2325
{
@@ -53,7 +55,7 @@ static int cros_ec_sensorhub_register(struct device *dev,
5355
int sensor_type[MOTIONSENSE_TYPE_MAX] = { 0 };
5456
struct cros_ec_command *msg = sensorhub->msg;
5557
struct cros_ec_dev *ec = sensorhub->ec;
56-
int ret, i;
58+
int ret, i, retries;
5759
char *name;
5860

5961

@@ -65,12 +67,25 @@ static int cros_ec_sensorhub_register(struct device *dev,
6567
sensorhub->params->cmd = MOTIONSENSE_CMD_INFO;
6668
sensorhub->params->info.sensor_num = i;
6769

68-
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
70+
retries = CROS_EC_CMD_INFO_RETRIES;
71+
do {
72+
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
73+
if (ret == -EBUSY) {
74+
/* The EC is still busy initializing sensors. */
75+
usleep_range(5000, 6000);
76+
retries--;
77+
}
78+
} while (ret == -EBUSY && retries);
79+
6980
if (ret < 0) {
70-
dev_warn(dev, "no info for EC sensor %d : %d/%d\n",
71-
i, ret, msg->result);
81+
dev_err(dev, "no info for EC sensor %d : %d/%d\n",
82+
i, ret, msg->result);
7283
continue;
7384
}
85+
if (retries < CROS_EC_CMD_INFO_RETRIES) {
86+
dev_warn(dev, "%d retries needed to bring up sensor %d\n",
87+
CROS_EC_CMD_INFO_RETRIES - retries, i);
88+
}
7489

7590
switch (sensorhub->resp->info.type) {
7691
case MOTIONSENSE_TYPE_ACCEL:

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,91 @@ static int cros_typec_enter_usb_mode(struct typec_port *tc_port, enum usb_mode m
5858
&req, sizeof(req), NULL, 0);
5959
}
6060

61+
static int cros_typec_perform_role_swap(struct typec_port *tc_port, int target_role, u8 swap_type)
62+
{
63+
struct cros_typec_port *port = typec_get_drvdata(tc_port);
64+
struct cros_typec_data *data = port->typec_data;
65+
struct ec_response_usb_pd_control_v2 resp;
66+
struct ec_params_usb_pd_control req;
67+
int role, ret;
68+
69+
/* Must be at least v1 to support role swap. */
70+
if (!data->pd_ctrl_ver)
71+
return -EOPNOTSUPP;
72+
73+
/* First query the state */
74+
req.port = port->port_num;
75+
req.role = USB_PD_CTRL_ROLE_NO_CHANGE;
76+
req.mux = USB_PD_CTRL_MUX_NO_CHANGE;
77+
req.swap = USB_PD_CTRL_SWAP_NONE;
78+
79+
ret = cros_ec_cmd(data->ec, data->pd_ctrl_ver, EC_CMD_USB_PD_CONTROL,
80+
&req, sizeof(req), &resp, sizeof(resp));
81+
if (ret < 0)
82+
return ret;
83+
84+
switch (swap_type) {
85+
case USB_PD_CTRL_SWAP_DATA:
86+
role = (resp.role & PD_CTRL_RESP_ROLE_DATA) ? TYPEC_HOST :
87+
TYPEC_DEVICE;
88+
break;
89+
case USB_PD_CTRL_SWAP_POWER:
90+
role = (resp.role & PD_CTRL_RESP_ROLE_POWER) ? TYPEC_SOURCE :
91+
TYPEC_SINK;
92+
break;
93+
default:
94+
dev_warn(data->dev, "Unsupported role swap type %d\n", swap_type);
95+
return -EOPNOTSUPP;
96+
}
97+
98+
if (role == target_role)
99+
return 0;
100+
101+
req.swap = swap_type;
102+
ret = cros_ec_cmd(data->ec, data->pd_ctrl_ver, EC_CMD_USB_PD_CONTROL,
103+
&req, sizeof(req), &resp, sizeof(resp));
104+
if (ret < 0)
105+
return ret;
106+
107+
switch (swap_type) {
108+
case USB_PD_CTRL_SWAP_DATA:
109+
role = resp.role & PD_CTRL_RESP_ROLE_DATA ? TYPEC_HOST : TYPEC_DEVICE;
110+
if (role != target_role) {
111+
dev_err(data->dev, "Data role swap failed despite EC returning success\n");
112+
return -EIO;
113+
}
114+
typec_set_data_role(tc_port, target_role);
115+
break;
116+
case USB_PD_CTRL_SWAP_POWER:
117+
role = resp.role & PD_CTRL_RESP_ROLE_POWER ? TYPEC_SOURCE : TYPEC_SINK;
118+
if (role != target_role) {
119+
dev_err(data->dev, "Power role swap failed despite EC returning success\n");
120+
return -EIO;
121+
}
122+
typec_set_pwr_role(tc_port, target_role);
123+
break;
124+
default:
125+
/* Should never execute */
126+
break;
127+
}
128+
129+
return 0;
130+
}
131+
132+
static int cros_typec_dr_swap(struct typec_port *port, enum typec_data_role role)
133+
{
134+
return cros_typec_perform_role_swap(port, role, USB_PD_CTRL_SWAP_DATA);
135+
}
136+
137+
static int cros_typec_pr_swap(struct typec_port *port, enum typec_role role)
138+
{
139+
return cros_typec_perform_role_swap(port, role, USB_PD_CTRL_SWAP_POWER);
140+
}
141+
61142
static const struct typec_operations cros_typec_usb_mode_ops = {
62-
.enter_usb_mode = cros_typec_enter_usb_mode
143+
.enter_usb_mode = cros_typec_enter_usb_mode,
144+
.dr_set = cros_typec_dr_swap,
145+
.pr_set = cros_typec_pr_swap,
63146
};
64147

65148
static int cros_typec_parse_port_props(struct typec_capability *cap,
@@ -1271,9 +1354,9 @@ static int cros_typec_probe(struct platform_device *pdev)
12711354
typec->dev = dev;
12721355

12731356
typec->ec = dev_get_drvdata(pdev->dev.parent);
1274-
if (!typec->ec) {
1275-
dev_err(dev, "couldn't find parent EC device\n");
1276-
return -ENODEV;
1357+
if (!typec->ec || !typec->ec->ec) {
1358+
dev_warn(dev, "couldn't find parent EC device\n");
1359+
return -EPROBE_DEFER;
12771360
}
12781361

12791362
platform_set_drvdata(pdev, typec);

0 commit comments

Comments
 (0)