Skip to content

Commit 5ec966d

Browse files
author
Enric Balletbo i Serra
committed
Merge tag 'tag-ib-chrome-mfd-iio-input-5.5' into chrome-platform-5.5
IB between mfd, iio, input and chrome platform for cros-ec-sensorhub Signed-off-by: Enric Balletbo i Serra <[email protected]>
2 parents c2ce4d2 + 99cdb24 commit 5ec966d

File tree

17 files changed

+636
-421
lines changed

17 files changed

+636
-421
lines changed

drivers/iio/accel/cros_ec_accel_legacy.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,10 @@ static const struct iio_chan_spec cros_ec_accel_legacy_channels[] = {
163163
static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
164164
{
165165
struct device *dev = &pdev->dev;
166-
struct cros_ec_dev *ec = dev_get_drvdata(dev->parent);
167166
struct iio_dev *indio_dev;
168167
struct cros_ec_sensors_core_state *state;
169168
int ret;
170169

171-
if (!ec || !ec->ec_dev) {
172-
dev_warn(&pdev->dev, "No EC device found.\n");
173-
return -EINVAL;
174-
}
175-
176170
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*state));
177171
if (!indio_dev)
178172
return -ENOMEM;

drivers/iio/common/cros_ec_sensors/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
config IIO_CROS_EC_SENSORS_CORE
66
tristate "ChromeOS EC Sensors Core"
7-
depends on SYSFS && CROS_EC
7+
depends on SYSFS && CROS_EC_SENSORHUB
88
select IIO_BUFFER
99
select IIO_TRIGGERED_BUFFER
1010
help

drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,11 @@ static const struct iio_info ec_sensors_info = {
222222
static int cros_ec_sensors_probe(struct platform_device *pdev)
223223
{
224224
struct device *dev = &pdev->dev;
225-
struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
226225
struct iio_dev *indio_dev;
227226
struct cros_ec_sensors_state *state;
228227
struct iio_chan_spec *channel;
229228
int ret, i;
230229

231-
if (!ec_dev || !ec_dev->ec_dev) {
232-
dev_warn(&pdev->dev, "No CROS EC device found.\n");
233-
return -EINVAL;
234-
}
235-
236230
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*state));
237231
if (!indio_dev)
238232
return -ENOMEM;

drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/slab.h>
1919
#include <linux/platform_data/cros_ec_commands.h>
2020
#include <linux/platform_data/cros_ec_proto.h>
21+
#include <linux/platform_data/cros_ec_sensorhub.h>
2122
#include <linux/platform_device.h>
2223

2324
static char *cros_ec_loc[] = {
@@ -88,7 +89,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
8889
{
8990
struct device *dev = &pdev->dev;
9091
struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
91-
struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent);
92+
struct cros_ec_sensorhub *sensor_hub = dev_get_drvdata(dev->parent);
93+
struct cros_ec_dev *ec = sensor_hub->ec;
9294
struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
9395
u32 ver_mask;
9496
int ret, i;

drivers/iio/light/cros_ec_light_prox.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,11 @@ static const struct iio_info cros_ec_light_prox_info = {
169169
static int cros_ec_light_prox_probe(struct platform_device *pdev)
170170
{
171171
struct device *dev = &pdev->dev;
172-
struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
173172
struct iio_dev *indio_dev;
174173
struct cros_ec_light_prox_state *state;
175174
struct iio_chan_spec *channel;
176175
int ret;
177176

178-
if (!ec_dev || !ec_dev->ec_dev) {
179-
dev_warn(dev, "No CROS EC device found.\n");
180-
return -EINVAL;
181-
}
182-
183177
indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
184178
if (!indio_dev)
185179
return -ENOMEM;

drivers/input/keyboard/cros_ec_keyb.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ static int cros_ec_keyb_work(struct notifier_block *nb,
226226
{
227227
struct cros_ec_keyb *ckdev = container_of(nb, struct cros_ec_keyb,
228228
notifier);
229-
uint8_t mkbp_event_type = ckdev->ec->event_data.event_type &
230-
EC_MKBP_EVENT_TYPE_MASK;
231229
u32 val;
232230
unsigned int ev_type;
233231

@@ -239,7 +237,7 @@ static int cros_ec_keyb_work(struct notifier_block *nb,
239237
if (queued_during_suspend && !device_may_wakeup(ckdev->dev))
240238
return NOTIFY_OK;
241239

242-
switch (mkbp_event_type) {
240+
switch (ckdev->ec->event_data.event_type) {
243241
case EC_MKBP_EVENT_KEY_MATRIX:
244242
pm_wakeup_event(ckdev->dev, 0);
245243

@@ -266,7 +264,7 @@ static int cros_ec_keyb_work(struct notifier_block *nb,
266264
case EC_MKBP_EVENT_SWITCH:
267265
pm_wakeup_event(ckdev->dev, 0);
268266

269-
if (mkbp_event_type == EC_MKBP_EVENT_BUTTON) {
267+
if (ckdev->ec->event_data.event_type == EC_MKBP_EVENT_BUTTON) {
270268
val = get_unaligned_le32(
271269
&ckdev->ec->event_data.data.buttons);
272270
ev_type = EV_KEY;

drivers/mfd/cros_ec_dev.c

Lines changed: 12 additions & 223 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ static const struct mfd_cell cros_ec_rtc_cells[] = {
7878
{ .name = "cros-ec-rtc", },
7979
};
8080

81+
static const struct mfd_cell cros_ec_sensorhub_cells[] = {
82+
{ .name = "cros-ec-sensorhub", },
83+
};
84+
8185
static const struct mfd_cell cros_usbpd_charger_cells[] = {
8286
{ .name = "cros-usbpd-charger", },
8387
{ .name = "cros-usbpd-logger", },
@@ -112,229 +116,11 @@ static const struct mfd_cell cros_ec_vbc_cells[] = {
112116
{ .name = "cros-ec-vbc", }
113117
};
114118

115-
static int cros_ec_check_features(struct cros_ec_dev *ec, int feature)
116-
{
117-
struct cros_ec_command *msg;
118-
int ret;
119-
120-
if (ec->features[0] == -1U && ec->features[1] == -1U) {
121-
/* features bitmap not read yet */
122-
msg = kzalloc(sizeof(*msg) + sizeof(ec->features), GFP_KERNEL);
123-
if (!msg)
124-
return -ENOMEM;
125-
126-
msg->command = EC_CMD_GET_FEATURES + ec->cmd_offset;
127-
msg->insize = sizeof(ec->features);
128-
129-
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
130-
if (ret < 0) {
131-
dev_warn(ec->dev, "cannot get EC features: %d/%d\n",
132-
ret, msg->result);
133-
memset(ec->features, 0, sizeof(ec->features));
134-
} else {
135-
memcpy(ec->features, msg->data, sizeof(ec->features));
136-
}
137-
138-
dev_dbg(ec->dev, "EC features %08x %08x\n",
139-
ec->features[0], ec->features[1]);
140-
141-
kfree(msg);
142-
}
143-
144-
return ec->features[feature / 32] & EC_FEATURE_MASK_0(feature);
145-
}
146-
147119
static void cros_ec_class_release(struct device *dev)
148120
{
149121
kfree(to_cros_ec_dev(dev));
150122
}
151123

152-
static void cros_ec_sensors_register(struct cros_ec_dev *ec)
153-
{
154-
/*
155-
* Issue a command to get the number of sensor reported.
156-
* Build an array of sensors driver and register them all.
157-
*/
158-
int ret, i, id, sensor_num;
159-
struct mfd_cell *sensor_cells;
160-
struct cros_ec_sensor_platform *sensor_platforms;
161-
int sensor_type[MOTIONSENSE_TYPE_MAX];
162-
struct ec_params_motion_sense *params;
163-
struct ec_response_motion_sense *resp;
164-
struct cros_ec_command *msg;
165-
166-
msg = kzalloc(sizeof(struct cros_ec_command) +
167-
max(sizeof(*params), sizeof(*resp)), GFP_KERNEL);
168-
if (msg == NULL)
169-
return;
170-
171-
msg->version = 2;
172-
msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
173-
msg->outsize = sizeof(*params);
174-
msg->insize = sizeof(*resp);
175-
176-
params = (struct ec_params_motion_sense *)msg->data;
177-
params->cmd = MOTIONSENSE_CMD_DUMP;
178-
179-
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
180-
if (ret < 0) {
181-
dev_warn(ec->dev, "cannot get EC sensor information: %d/%d\n",
182-
ret, msg->result);
183-
goto error;
184-
}
185-
186-
resp = (struct ec_response_motion_sense *)msg->data;
187-
sensor_num = resp->dump.sensor_count;
188-
/*
189-
* Allocate 2 extra sensors if lid angle sensor and/or FIFO are needed.
190-
*/
191-
sensor_cells = kcalloc(sensor_num + 2, sizeof(struct mfd_cell),
192-
GFP_KERNEL);
193-
if (sensor_cells == NULL)
194-
goto error;
195-
196-
sensor_platforms = kcalloc(sensor_num,
197-
sizeof(struct cros_ec_sensor_platform),
198-
GFP_KERNEL);
199-
if (sensor_platforms == NULL)
200-
goto error_platforms;
201-
202-
memset(sensor_type, 0, sizeof(sensor_type));
203-
id = 0;
204-
for (i = 0; i < sensor_num; i++) {
205-
params->cmd = MOTIONSENSE_CMD_INFO;
206-
params->info.sensor_num = i;
207-
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
208-
if (ret < 0) {
209-
dev_warn(ec->dev, "no info for EC sensor %d : %d/%d\n",
210-
i, ret, msg->result);
211-
continue;
212-
}
213-
switch (resp->info.type) {
214-
case MOTIONSENSE_TYPE_ACCEL:
215-
sensor_cells[id].name = "cros-ec-accel";
216-
break;
217-
case MOTIONSENSE_TYPE_BARO:
218-
sensor_cells[id].name = "cros-ec-baro";
219-
break;
220-
case MOTIONSENSE_TYPE_GYRO:
221-
sensor_cells[id].name = "cros-ec-gyro";
222-
break;
223-
case MOTIONSENSE_TYPE_MAG:
224-
sensor_cells[id].name = "cros-ec-mag";
225-
break;
226-
case MOTIONSENSE_TYPE_PROX:
227-
sensor_cells[id].name = "cros-ec-prox";
228-
break;
229-
case MOTIONSENSE_TYPE_LIGHT:
230-
sensor_cells[id].name = "cros-ec-light";
231-
break;
232-
case MOTIONSENSE_TYPE_ACTIVITY:
233-
sensor_cells[id].name = "cros-ec-activity";
234-
break;
235-
default:
236-
dev_warn(ec->dev, "unknown type %d\n", resp->info.type);
237-
continue;
238-
}
239-
sensor_platforms[id].sensor_num = i;
240-
sensor_cells[id].id = sensor_type[resp->info.type];
241-
sensor_cells[id].platform_data = &sensor_platforms[id];
242-
sensor_cells[id].pdata_size =
243-
sizeof(struct cros_ec_sensor_platform);
244-
245-
sensor_type[resp->info.type]++;
246-
id++;
247-
}
248-
249-
if (sensor_type[MOTIONSENSE_TYPE_ACCEL] >= 2)
250-
ec->has_kb_wake_angle = true;
251-
252-
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
253-
sensor_cells[id].name = "cros-ec-ring";
254-
id++;
255-
}
256-
if (cros_ec_check_features(ec,
257-
EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS)) {
258-
sensor_cells[id].name = "cros-ec-lid-angle";
259-
id++;
260-
}
261-
262-
ret = mfd_add_devices(ec->dev, 0, sensor_cells, id,
263-
NULL, 0, NULL);
264-
if (ret)
265-
dev_err(ec->dev, "failed to add EC sensors\n");
266-
267-
kfree(sensor_platforms);
268-
error_platforms:
269-
kfree(sensor_cells);
270-
error:
271-
kfree(msg);
272-
}
273-
274-
static struct cros_ec_sensor_platform sensor_platforms[] = {
275-
{ .sensor_num = 0 },
276-
{ .sensor_num = 1 }
277-
};
278-
279-
static const struct mfd_cell cros_ec_accel_legacy_cells[] = {
280-
{
281-
.name = "cros-ec-accel-legacy",
282-
.platform_data = &sensor_platforms[0],
283-
.pdata_size = sizeof(struct cros_ec_sensor_platform),
284-
},
285-
{
286-
.name = "cros-ec-accel-legacy",
287-
.platform_data = &sensor_platforms[1],
288-
.pdata_size = sizeof(struct cros_ec_sensor_platform),
289-
}
290-
};
291-
292-
static void cros_ec_accel_legacy_register(struct cros_ec_dev *ec)
293-
{
294-
struct cros_ec_device *ec_dev = ec->ec_dev;
295-
u8 status;
296-
int ret;
297-
298-
/*
299-
* ECs that need legacy support are the main EC, directly connected to
300-
* the AP.
301-
*/
302-
if (ec->cmd_offset != 0)
303-
return;
304-
305-
/*
306-
* Check if EC supports direct memory reads and if EC has
307-
* accelerometers.
308-
*/
309-
if (ec_dev->cmd_readmem) {
310-
ret = ec_dev->cmd_readmem(ec_dev, EC_MEMMAP_ACC_STATUS, 1,
311-
&status);
312-
if (ret < 0) {
313-
dev_warn(ec->dev, "EC direct read error.\n");
314-
return;
315-
}
316-
317-
/* Check if EC has accelerometers. */
318-
if (!(status & EC_MEMMAP_ACC_STATUS_PRESENCE_BIT)) {
319-
dev_info(ec->dev, "EC does not have accelerometers.\n");
320-
return;
321-
}
322-
}
323-
324-
/*
325-
* The device may still support accelerometers:
326-
* it would be an older ARM based device that do not suppor the
327-
* EC_CMD_GET_FEATURES command.
328-
*
329-
* Register 2 accelerometers, we will fail in the IIO driver if there
330-
* are no sensors.
331-
*/
332-
ret = mfd_add_hotplug_devices(ec->dev, cros_ec_accel_legacy_cells,
333-
ARRAY_SIZE(cros_ec_accel_legacy_cells));
334-
if (ret)
335-
dev_err(ec_dev->dev, "failed to add EC sensors\n");
336-
}
337-
338124
static int ec_device_probe(struct platform_device *pdev)
339125
{
340126
int retval = -ENOMEM;
@@ -390,11 +176,14 @@ static int ec_device_probe(struct platform_device *pdev)
390176
goto failed;
391177

392178
/* check whether this EC is a sensor hub. */
393-
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE))
394-
cros_ec_sensors_register(ec);
395-
else
396-
/* Workaroud for older EC firmware */
397-
cros_ec_accel_legacy_register(ec);
179+
if (cros_ec_get_sensor_count(ec) > 0) {
180+
retval = mfd_add_hotplug_devices(ec->dev,
181+
cros_ec_sensorhub_cells,
182+
ARRAY_SIZE(cros_ec_sensorhub_cells));
183+
if (retval)
184+
dev_err(ec->dev, "failed to add %s subdevice: %d\n",
185+
cros_ec_sensorhub_cells->name, retval);
186+
}
398187

399188
/*
400189
* The following subdevices can be detected by sending the

drivers/platform/chrome/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@ config CROS_EC_DEBUGFS
190190
To compile this driver as a module, choose M here: the
191191
module will be called cros_ec_debugfs.
192192

193+
config CROS_EC_SENSORHUB
194+
tristate "ChromeOS EC MEMS Sensor Hub"
195+
depends on CROS_EC
196+
help
197+
Allow loading IIO sensors. This driver is loaded by MFD and will in
198+
turn query the EC and register the sensors.
199+
It also spreads the sensor data coming from the EC to the IIO sensor
200+
object.
201+
202+
To compile this driver as a module, choose M here: the
203+
module will be called cros_ec_sensorhub.
204+
193205
config CROS_EC_SYSFS
194206
tristate "ChromeOS EC control and information through sysfs"
195207
depends on MFD_CROS_EC_DEV && SYSFS

drivers/platform/chrome/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ obj-$(CONFIG_CROS_EC_CHARDEV) += cros_ec_chardev.o
1919
obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o
2020
obj-$(CONFIG_CROS_EC_VBC) += cros_ec_vbc.o
2121
obj-$(CONFIG_CROS_EC_DEBUGFS) += cros_ec_debugfs.o
22+
obj-$(CONFIG_CROS_EC_SENSORHUB) += cros_ec_sensorhub.o
2223
obj-$(CONFIG_CROS_EC_SYSFS) += cros_ec_sysfs.o
2324
obj-$(CONFIG_CROS_USBPD_LOGGER) += cros_usbpd_logger.o
2425

0 commit comments

Comments
 (0)