Commit f6811370 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'chrome-platform-for-linus-4.17' of...

Merge tag 'chrome-platform-for-linus-4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/bleung/chrome-platform

Pull chrome platform updates from Benson Leung:

 - a series from Dmitry to remove platform data from chromeos_laptop.c,
   which was the only user of platform data for the atmel_mxt_ts driver.

 - a series to clean up sysfs and debugfs for cros_ec

 - other misc cleanups

* tag 'chrome-platform-for-linus-4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/bleung/chrome-platform: (22 commits)
  platform/chrome: mfd/cros_ec_dev: Add sysfs entry to set keyboard wake lid angle
  platform/chrome: cros_ec_debugfs: Add PD port info to debugfs
  platform/chrome: cros_ec_debugfs: Use octal permissions '0444'
  platform/chrome: cros_ec_sysfs: use permission-specific DEVICE_ATTR variants
  platform/chrome: cros_ec_sysfs: introduce to_cros_ec_dev define.
  platform/chrome: cros_ec_sysfs: Modify error handling
  platform/chrome: cros_ec_lpc: Add support for Google devices using custom coreboot firmware
  platform/chrome: cros_ec_lpc: wake up from s2idle on Chrome EC
  Input: atmel_mxt_ts - remove platform data support
  platform/chrome: chromeos_laptop - discard data for unneeded boards
  platform/chrome: chromeos_laptop - use device properties for Pixel
  platform/chrome: chromeos_laptop - rely on I2C to set up interrupt trigger
  platform/chrome: chromeos_laptop - use I2C notifier to create devices
  platform/chrome: chromeos_laptop - parse DMI IRQ data once
  platform/chrome: chromeos_laptop - rework i2c peripherals initialization
  platform/chrome: chromeos_laptop - factor out getting IRQ from DMI
  platform/chrome: chromeos_laptop - introduce pr_fmt()
  platform/chrome: chromeos_laptop - stop setting suspend mode for Atmel devices
  platform/chrome: chromeos_laptop - add SPDX identifier
  Input: atmel_mxt_ts - switch ChromeOS ACPI devices to generic props
  ...
parents ca4e7c51 c171d3b8
...@@ -2426,7 +2426,6 @@ T: git git://github.com/ndyer/linux.git ...@@ -2426,7 +2426,6 @@ T: git git://github.com/ndyer/linux.git
S: Maintained S: Maintained
F: Documentation/devicetree/bindings/input/atmel,maxtouch.txt F: Documentation/devicetree/bindings/input/atmel,maxtouch.txt
F: drivers/input/touchscreen/atmel_mxt_ts.c F: drivers/input/touchscreen/atmel_mxt_ts.c
F: include/linux/platform_data/atmel_mxt_ts.h
ATMEL SAMA5D2 ADC DRIVER ATMEL SAMA5D2 ADC DRIVER
M: Ludovic Desroches <ludovic.desroches@microchip.com> M: Ludovic Desroches <ludovic.desroches@microchip.com>
......
...@@ -23,12 +23,13 @@ ...@@ -23,12 +23,13 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/firmware.h> #include <linux/firmware.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/platform_data/atmel_mxt_ts.h>
#include <linux/input/mt.h> #include <linux/input/mt.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/property.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/property.h>
#include <asm/unaligned.h> #include <asm/unaligned.h>
#include <media/v4l2-device.h> #include <media/v4l2-device.h>
#include <media/v4l2-ioctl.h> #include <media/v4l2-ioctl.h>
...@@ -268,12 +269,16 @@ static const struct v4l2_file_operations mxt_video_fops = { ...@@ -268,12 +269,16 @@ static const struct v4l2_file_operations mxt_video_fops = {
.poll = vb2_fop_poll, .poll = vb2_fop_poll,
}; };
enum mxt_suspend_mode {
MXT_SUSPEND_DEEP_SLEEP = 0,
MXT_SUSPEND_T9_CTRL = 1,
};
/* Each client has this additional data */ /* Each client has this additional data */
struct mxt_data { struct mxt_data {
struct i2c_client *client; struct i2c_client *client;
struct input_dev *input_dev; struct input_dev *input_dev;
char phys[64]; /* device physical location */ char phys[64]; /* device physical location */
const struct mxt_platform_data *pdata;
struct mxt_object *object_table; struct mxt_object *object_table;
struct mxt_info info; struct mxt_info info;
unsigned int irq; unsigned int irq;
...@@ -324,6 +329,11 @@ struct mxt_data { ...@@ -324,6 +329,11 @@ struct mxt_data {
/* for config update handling */ /* for config update handling */
struct completion crc_completion; struct completion crc_completion;
u32 *t19_keymap;
unsigned int t19_num_keys;
enum mxt_suspend_mode suspend_mode;
}; };
struct mxt_vb2_buffer { struct mxt_vb2_buffer {
...@@ -742,15 +752,14 @@ static int mxt_write_object(struct mxt_data *data, ...@@ -742,15 +752,14 @@ static int mxt_write_object(struct mxt_data *data,
static void mxt_input_button(struct mxt_data *data, u8 *message) static void mxt_input_button(struct mxt_data *data, u8 *message)
{ {
struct input_dev *input = data->input_dev; struct input_dev *input = data->input_dev;
const struct mxt_platform_data *pdata = data->pdata;
int i; int i;
for (i = 0; i < pdata->t19_num_keys; i++) { for (i = 0; i < data->t19_num_keys; i++) {
if (pdata->t19_keymap[i] == KEY_RESERVED) if (data->t19_keymap[i] == KEY_RESERVED)
continue; continue;
/* Active-low switch */ /* Active-low switch */
input_report_key(input, pdata->t19_keymap[i], input_report_key(input, data->t19_keymap[i],
!(message[1] & BIT(i))); !(message[1] & BIT(i)));
} }
} }
...@@ -758,7 +767,7 @@ static void mxt_input_button(struct mxt_data *data, u8 *message) ...@@ -758,7 +767,7 @@ static void mxt_input_button(struct mxt_data *data, u8 *message)
static void mxt_input_sync(struct mxt_data *data) static void mxt_input_sync(struct mxt_data *data)
{ {
input_mt_report_pointer_emulation(data->input_dev, input_mt_report_pointer_emulation(data->input_dev,
data->pdata->t19_num_keys); data->t19_num_keys);
input_sync(data->input_dev); input_sync(data->input_dev);
} }
...@@ -1858,7 +1867,6 @@ static void mxt_input_close(struct input_dev *dev); ...@@ -1858,7 +1867,6 @@ static void mxt_input_close(struct input_dev *dev);
static void mxt_set_up_as_touchpad(struct input_dev *input_dev, static void mxt_set_up_as_touchpad(struct input_dev *input_dev,
struct mxt_data *data) struct mxt_data *data)
{ {
const struct mxt_platform_data *pdata = data->pdata;
int i; int i;
input_dev->name = "Atmel maXTouch Touchpad"; input_dev->name = "Atmel maXTouch Touchpad";
...@@ -1872,15 +1880,14 @@ static void mxt_set_up_as_touchpad(struct input_dev *input_dev, ...@@ -1872,15 +1880,14 @@ static void mxt_set_up_as_touchpad(struct input_dev *input_dev,
input_abs_set_res(input_dev, ABS_MT_POSITION_Y, input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
MXT_PIXELS_PER_MM); MXT_PIXELS_PER_MM);
for (i = 0; i < pdata->t19_num_keys; i++) for (i = 0; i < data->t19_num_keys; i++)
if (pdata->t19_keymap[i] != KEY_RESERVED) if (data->t19_keymap[i] != KEY_RESERVED)
input_set_capability(input_dev, EV_KEY, input_set_capability(input_dev, EV_KEY,
pdata->t19_keymap[i]); data->t19_keymap[i]);
} }
static int mxt_initialize_input_device(struct mxt_data *data) static int mxt_initialize_input_device(struct mxt_data *data)
{ {
const struct mxt_platform_data *pdata = data->pdata;
struct device *dev = &data->client->dev; struct device *dev = &data->client->dev;
struct input_dev *input_dev; struct input_dev *input_dev;
int error; int error;
...@@ -1946,7 +1953,7 @@ static int mxt_initialize_input_device(struct mxt_data *data) ...@@ -1946,7 +1953,7 @@ static int mxt_initialize_input_device(struct mxt_data *data)
} }
/* If device has buttons we assume it is a touchpad */ /* If device has buttons we assume it is a touchpad */
if (pdata->t19_num_keys) { if (data->t19_num_keys) {
mxt_set_up_as_touchpad(input_dev, data); mxt_set_up_as_touchpad(input_dev, data);
mt_flags |= INPUT_MT_POINTER; mt_flags |= INPUT_MT_POINTER;
} else { } else {
...@@ -2868,7 +2875,7 @@ static const struct attribute_group mxt_attr_group = { ...@@ -2868,7 +2875,7 @@ static const struct attribute_group mxt_attr_group = {
static void mxt_start(struct mxt_data *data) static void mxt_start(struct mxt_data *data)
{ {
switch (data->pdata->suspend_mode) { switch (data->suspend_mode) {
case MXT_SUSPEND_T9_CTRL: case MXT_SUSPEND_T9_CTRL:
mxt_soft_reset(data); mxt_soft_reset(data);
...@@ -2886,12 +2893,11 @@ static void mxt_start(struct mxt_data *data) ...@@ -2886,12 +2893,11 @@ static void mxt_start(struct mxt_data *data)
mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false); mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false);
break; break;
} }
} }
static void mxt_stop(struct mxt_data *data) static void mxt_stop(struct mxt_data *data)
{ {
switch (data->pdata->suspend_mode) { switch (data->suspend_mode) {
case MXT_SUSPEND_T9_CTRL: case MXT_SUSPEND_T9_CTRL:
/* Touch disable */ /* Touch disable */
mxt_write_object(data, mxt_write_object(data,
...@@ -2921,55 +2927,49 @@ static void mxt_input_close(struct input_dev *dev) ...@@ -2921,55 +2927,49 @@ static void mxt_input_close(struct input_dev *dev)
mxt_stop(data); mxt_stop(data);
} }
#ifdef CONFIG_OF static int mxt_parse_device_properties(struct mxt_data *data)
static const struct mxt_platform_data *mxt_parse_dt(struct i2c_client *client)
{ {
struct mxt_platform_data *pdata; static const char keymap_property[] = "linux,gpio-keymap";
struct device_node *np = client->dev.of_node; struct device *dev = &data->client->dev;
u32 *keymap; u32 *keymap;
int proplen, ret; int n_keys;
int error;
if (!np)
return ERR_PTR(-ENOENT);
pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return ERR_PTR(-ENOMEM);
if (of_find_property(np, "linux,gpio-keymap", &proplen)) { if (device_property_present(dev, keymap_property)) {
pdata->t19_num_keys = proplen / sizeof(u32); n_keys = device_property_read_u32_array(dev, keymap_property,
NULL, 0);
if (n_keys <= 0) {
error = n_keys < 0 ? n_keys : -EINVAL;
dev_err(dev, "invalid/malformed '%s' property: %d\n",
keymap_property, error);
return error;
}
keymap = devm_kzalloc(&client->dev, keymap = devm_kmalloc_array(dev, n_keys, sizeof(*keymap),
pdata->t19_num_keys * sizeof(keymap[0]), GFP_KERNEL);
GFP_KERNEL);
if (!keymap) if (!keymap)
return ERR_PTR(-ENOMEM); return -ENOMEM;
ret = of_property_read_u32_array(np, "linux,gpio-keymap", error = device_property_read_u32_array(dev, keymap_property,
keymap, pdata->t19_num_keys); keymap, n_keys);
if (ret) if (error) {
dev_warn(&client->dev, dev_err(dev, "failed to parse '%s' property: %d\n",
"Couldn't read linux,gpio-keymap: %d\n", ret); keymap_property, error);
return error;
}
pdata->t19_keymap = keymap; data->t19_keymap = keymap;
data->t19_num_keys = n_keys;
} }
pdata->suspend_mode = MXT_SUSPEND_DEEP_SLEEP; return 0;
return pdata;
}
#else
static const struct mxt_platform_data *mxt_parse_dt(struct i2c_client *client)
{
return ERR_PTR(-ENOENT);
} }
#endif
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
struct mxt_acpi_platform_data { struct mxt_acpi_platform_data {
const char *hid; const char *hid;
struct mxt_platform_data pdata; const struct property_entry *props;
}; };
static unsigned int samus_touchpad_buttons[] = { static unsigned int samus_touchpad_buttons[] = {
...@@ -2979,14 +2979,16 @@ static unsigned int samus_touchpad_buttons[] = { ...@@ -2979,14 +2979,16 @@ static unsigned int samus_touchpad_buttons[] = {
BTN_LEFT BTN_LEFT
}; };
static const struct property_entry samus_touchpad_props[] = {
PROPERTY_ENTRY_U32_ARRAY("linux,gpio-keymap", samus_touchpad_buttons),
{ }
};
static struct mxt_acpi_platform_data samus_platform_data[] = { static struct mxt_acpi_platform_data samus_platform_data[] = {
{ {
/* Touchpad */ /* Touchpad */
.hid = "ATML0000", .hid = "ATML0000",
.pdata = { .props = samus_touchpad_props,
.t19_num_keys = ARRAY_SIZE(samus_touchpad_buttons),
.t19_keymap = samus_touchpad_buttons,
},
}, },
{ {
/* Touchscreen */ /* Touchscreen */
...@@ -3004,14 +3006,16 @@ static unsigned int chromebook_tp_buttons[] = { ...@@ -3004,14 +3006,16 @@ static unsigned int chromebook_tp_buttons[] = {
BTN_LEFT BTN_LEFT
}; };
static const struct property_entry chromebook_tp_props[] = {
PROPERTY_ENTRY_U32_ARRAY("linux,gpio-keymap", chromebook_tp_buttons),
{ }
};
static struct mxt_acpi_platform_data chromebook_platform_data[] = { static struct mxt_acpi_platform_data chromebook_platform_data[] = {
{ {
/* Touchpad */ /* Touchpad */
.hid = "ATML0000", .hid = "ATML0000",
.pdata = { .props = chromebook_tp_props,
.t19_num_keys = ARRAY_SIZE(chromebook_tp_buttons),
.t19_keymap = chromebook_tp_buttons,
},
}, },
{ {
/* Touchscreen */ /* Touchscreen */
...@@ -3041,83 +3045,85 @@ static const struct dmi_system_id mxt_dmi_table[] = { ...@@ -3041,83 +3045,85 @@ static const struct dmi_system_id mxt_dmi_table[] = {
{ } { }
}; };
static const struct mxt_platform_data *mxt_parse_acpi(struct i2c_client *client) static int mxt_prepare_acpi_properties(struct i2c_client *client)
{ {
struct acpi_device *adev; struct acpi_device *adev;
const struct dmi_system_id *system_id; const struct dmi_system_id *system_id;
const struct mxt_acpi_platform_data *acpi_pdata; const struct mxt_acpi_platform_data *acpi_pdata;
/*
* Ignore ACPI devices representing bootloader mode.
*
* This is a bit of a hack: Google Chromebook BIOS creates ACPI
* devices for both application and bootloader modes, but we are
* interested in application mode only (if device is in bootloader
* mode we'll end up switching into application anyway). So far
* application mode addresses were all above 0x40, so we'll use it
* as a threshold.
*/
if (client->addr < 0x40)
return ERR_PTR(-ENXIO);
adev = ACPI_COMPANION(&client->dev); adev = ACPI_COMPANION(&client->dev);
if (!adev) if (!adev)
return ERR_PTR(-ENOENT); return -ENOENT;
system_id = dmi_first_match(mxt_dmi_table); system_id = dmi_first_match(mxt_dmi_table);
if (!system_id) if (!system_id)
return ERR_PTR(-ENOENT); return -ENOENT;
acpi_pdata = system_id->driver_data; acpi_pdata = system_id->driver_data;
if (!acpi_pdata) if (!acpi_pdata)
return ERR_PTR(-ENOENT); return -ENOENT;
while (acpi_pdata->hid) { while (acpi_pdata->hid) {
if (!strcmp(acpi_device_hid(adev), acpi_pdata->hid)) if (!strcmp(acpi_device_hid(adev), acpi_pdata->hid)) {
return &acpi_pdata->pdata; /*
* Remove previously installed properties if we
* are probing this device not for the very first
* time.
*/
device_remove_properties(&client->dev);
/*
* Now install the platform-specific properties
* that are missing from ACPI.
*/
device_add_properties(&client->dev, acpi_pdata->props);
break;
}
acpi_pdata++; acpi_pdata++;
} }
return ERR_PTR(-ENOENT); return 0;
} }
#else #else
static const struct mxt_platform_data *mxt_parse_acpi(struct i2c_client *client) static int mxt_prepare_acpi_properties(struct i2c_client *client)
{ {
return ERR_PTR(-ENOENT); return -ENOENT;
} }
#endif #endif
static const struct mxt_platform_data * static const struct dmi_system_id chromebook_T9_suspend_dmi[] = {
mxt_get_platform_data(struct i2c_client *client) {
{ .matches = {
const struct mxt_platform_data *pdata; DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
pdata = dev_get_platdata(&client->dev); },
if (pdata) },
return pdata; {
.matches = {
pdata = mxt_parse_dt(client); DMI_MATCH(DMI_PRODUCT_NAME, "Peppy"),
if (!IS_ERR(pdata) || PTR_ERR(pdata) != -ENOENT) },
return pdata; },
{ }
pdata = mxt_parse_acpi(client); };
if (!IS_ERR(pdata) || PTR_ERR(pdata) != -ENOENT)
return pdata;
dev_err(&client->dev, "No platform data specified\n");
return ERR_PTR(-EINVAL);
}
static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
{ {
struct mxt_data *data; struct mxt_data *data;
const struct mxt_platform_data *pdata;
int error; int error;
pdata = mxt_get_platform_data(client); /*
if (IS_ERR(pdata)) * Ignore ACPI devices representing bootloader mode.
return PTR_ERR(pdata); *
* This is a bit of a hack: Google Chromebook BIOS creates ACPI
* devices for both application and bootloader modes, but we are
* interested in application mode only (if device is in bootloader
* mode we'll end up switching into application anyway). So far
* application mode addresses were all above 0x40, so we'll use it
* as a threshold.
*/
if (ACPI_COMPANION(&client->dev) && client->addr < 0x40)
return -ENXIO;
data = devm_kzalloc(&client->dev, sizeof(struct mxt_data), GFP_KERNEL); data = devm_kzalloc(&client->dev, sizeof(struct mxt_data), GFP_KERNEL);
if (!data) if (!data)
...@@ -3127,7 +3133,6 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -3127,7 +3133,6 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
client->adapter->nr, client->addr); client->adapter->nr, client->addr);
data->client = client; data->client = client;
data->pdata = pdata;
data->irq = client->irq; data->irq = client->irq;
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
...@@ -3135,6 +3140,17 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -3135,6 +3140,17 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
init_completion(&data->reset_completion); init_completion(&data->reset_completion);
init_completion(&data->crc_completion); init_completion(&data->crc_completion);
data->suspend_mode = dmi_check_system(chromebook_T9_suspend_dmi) ?
MXT_SUSPEND_T9_CTRL : MXT_SUSPEND_DEEP_SLEEP;
error = mxt_prepare_acpi_properties(client);
if (error && error != -ENOENT)
return error;
error = mxt_parse_device_properties(data);
if (error)
return error;
data->reset_gpio = devm_gpiod_get_optional(&client->dev, data->reset_gpio = devm_gpiod_get_optional(&client->dev,
"reset", GPIOD_OUT_LOW); "reset", GPIOD_OUT_LOW);
if (IS_ERR(data->reset_gpio)) { if (IS_ERR(data->reset_gpio)) {
...@@ -3144,8 +3160,7 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -3144,8 +3160,7 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
} }
error = devm_request_threaded_irq(&client->dev, client->irq, error = devm_request_threaded_irq(&client->dev, client->irq,
NULL, mxt_interrupt, NULL, mxt_interrupt, IRQF_ONESHOT,
pdata->irqflags | IRQF_ONESHOT,
client->name, data); client->name, data);
if (error) { if (error) {
dev_err(&client->dev, "Failed to register interrupt\n"); dev_err(&client->dev, "Failed to register interrupt\n");
...@@ -3265,7 +3280,7 @@ MODULE_DEVICE_TABLE(i2c, mxt_id); ...@@ -3265,7 +3280,7 @@ MODULE_DEVICE_TABLE(i2c, mxt_id);
static struct i2c_driver mxt_driver = { static struct i2c_driver mxt_driver = {
.driver = { .driver = {
.name = "atmel_mxt_ts", .name = "atmel_mxt_ts",
.of_match_table = of_match_ptr(mxt_of_match), .of_match_table = mxt_of_match,
.acpi_match_table = ACPI_PTR(mxt_acpi_id), .acpi_match_table = ACPI_PTR(mxt_acpi_id),
.pm = &mxt_pm_ops, .pm = &mxt_pm_ops,
}, },
......
...@@ -305,8 +305,8 @@ static void cros_ec_sensors_register(struct cros_ec_dev *ec) ...@@ -305,8 +305,8 @@ static void cros_ec_sensors_register(struct cros_ec_dev *ec)
resp = (struct ec_response_motion_sense *)msg->data; resp = (struct ec_response_motion_sense *)msg->data;
sensor_num = resp->dump.sensor_count; sensor_num = resp->dump.sensor_count;
/* Allocate 2 extra sensors in case lid angle or FIFO are needed */ /* Allocate 1 extra sensors in FIFO are needed */
sensor_cells = kzalloc(sizeof(struct mfd_cell) * (sensor_num + 2), sensor_cells = kzalloc(sizeof(struct mfd_cell) * (sensor_num + 1),
GFP_KERNEL); GFP_KERNEL);
if (sensor_cells == NULL) if (sensor_cells == NULL)
goto error; goto error;
...@@ -362,16 +362,10 @@ static void cros_ec_sensors_register(struct cros_ec_dev *ec) ...@@ -362,16 +362,10 @@ static void cros_ec_sensors_register(struct cros_ec_dev *ec)
sensor_type[resp->info.type]++; sensor_type[resp->info.type]++;
id++; id++;
} }
if (sensor_type[MOTIONSENSE_TYPE_ACCEL] >= 2) {
sensor_platforms[id].sensor_num = sensor_num;
sensor_cells[id].name = "cros-ec-angle"; if (sensor_type[MOTIONSENSE_TYPE_ACCEL] >= 2)
sensor_cells[id].id = 0; ec->has_kb_wake_angle = true;
sensor_cells[id].platform_data = &sensor_platforms[id];
sensor_cells[id].pdata_size =
sizeof(struct cros_ec_sensor_platform);
id++;
}
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) { if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
sensor_cells[id].name = "cros-ec-ring"; sensor_cells[id].name = "cros-ec-ring";
id++; id++;
...@@ -424,6 +418,14 @@ static int ec_device_probe(struct platform_device *pdev) ...@@ -424,6 +418,14 @@ static int ec_device_probe(struct platform_device *pdev)
goto failed; goto failed;
} }
/* check whether this EC is a sensor hub. */
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE))
cros_ec_sensors_register(ec);
/* Take control of the lightbar from the EC. */
lb_manual_suspend_ctrl(ec, 1);
/* We can now add the sysfs class, we know which parameter to show */
retval = cdev_device_add(&ec->cdev, &ec->class_dev); retval = cdev_device_add(&ec->cdev, &ec->class_dev);
if (retval) { if (retval) {
dev_err(dev, "cdev_device_add failed => %d\n", retval); dev_err(dev, "cdev_device_add failed => %d\n", retval);
...@@ -433,13 +435,6 @@ static int ec_device_probe(struct platform_device *pdev) ...@@ -433,13 +435,6 @@ static int ec_device_probe(struct platform_device *pdev)
if (cros_ec_debugfs_init(ec)) if (cros_ec_debugfs_init(ec))
dev_warn(dev, "failed to create debugfs directory\n"); dev_warn(dev, "failed to create debugfs directory\n");
/* check whether this EC is a sensor hub. */
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE))
cros_ec_sensors_register(ec);
/* Take control of the lightbar from the EC. */
lb_manual_suspend_ctrl(ec, 1);
return 0; return 0;
failed: failed:
......
/* // SPDX-License-Identifier: GPL-2.0+
* chromeos_laptop.c - Driver to instantiate Chromebook i2c/smbus devices. // Driver to instantiate Chromebook i2c/smbus devices.
* //
* Author : Benson Leung <bleung@chromium.org> // Copyright (C) 2012 Google, Inc.
* // Author: Benson Leung <bleung@chromium.org>
* Copyright (C) 2012 Google, Inc.
* #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <linux/dmi.h> #include <linux/dmi.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/platform_data/atmel_mxt_ts.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/pci.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/property.h>
#define ATMEL_TP_I2C_ADDR 0x4b #define ATMEL_TP_I2C_ADDR 0x4b
#define ATMEL_TP_I2C_BL_ADDR 0x25 #define ATMEL_TP_I2C_BL_ADDR 0x25
...@@ -38,18 +25,11 @@ ...@@ -38,18 +25,11 @@
#define ISL_ALS_I2C_ADDR 0x44 #define ISL_ALS_I2C_ADDR 0x44
#define TAOS_ALS_I2C_ADDR 0x29 #define TAOS_ALS_I2C_ADDR 0x29
#define MAX_I2C_DEVICE_DEFERRALS 5
static struct i2c_client *als;
static struct i2c_client *tp;
static struct i2c_client *ts;
static const char *i2c_adapter_names[] = { static const char *i2c_adapter_names[] = {
"SMBus I801 adapter", "SMBus I801 adapter",
"i915 gmbus vga", "i915 gmbus vga",
"i915 gmbus panel", "i915 gmbus panel",
"Synopsys DesignWare I2C adapter", "Synopsys DesignWare I2C adapter",
"Synopsys DesignWare I2C adapter",
}; };
/* Keep this enum consistent with i2c_adapter_names */ /* Keep this enum consistent with i2c_adapter_names */
...@@ -57,126 +37,41 @@ enum i2c_adapter_type { ...@@ -57,126 +37,41 @@ enum i2c_adapter_type {
I2C_ADAPTER_SMBUS = 0, I2C_ADAPTER_SMBUS = 0,
I2C_ADAPTER_VGADDC, I2C_ADAPTER_VGADDC,
I2C_ADAPTER_PANEL, I2C_ADAPTER_PANEL,
I2C_ADAPTER_DESIGNWARE_0, I2C_ADAPTER_DESIGNWARE,
I2C_ADAPTER_DESIGNWARE_1,
};
enum i2c_peripheral_state {
UNPROBED = 0,
PROBED,
TIMEDOUT,
}; };
struct i2c_peripheral { struct i2c_peripheral {
int (*add)(enum i2c_adapter_type type); struct i2c_board_info board_info;
enum i2c_adapter_type type; unsigned short alt_addr;
enum i2c_peripheral_state state;
int tries;
};
#define MAX_I2C_PERIPHERALS 4
struct chromeos_laptop { const char *dmi_name;
struct i2c_peripheral i2c_peripherals[MAX_I2C_PERIPHERALS]; unsigned long irqflags;
}; struct resource irq_resource;
static struct chromeos_laptop *cros_laptop;
static struct i2c_board_info cyapa_device = {
I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
.flags = I2C_CLIENT_WAKE,
};
static struct i2c_board_info elantech_device = { enum i2c_adapter_type type;
I2C_BOARD_INFO("elan_i2c", ELAN_TP_I2C_ADDR), u32 pci_devid;
.flags = I2C_CLIENT_WAKE,
};
static struct i2c_board_info isl_als_device = {
I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
};
static struct i2c_board_info tsl2583_als_device = {
I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
};
static struct i2c_board_info tsl2563_als_device = {
I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
};
static int mxt_t19_keys[] = {
KEY_RESERVED,
KEY_RESERVED,
KEY_RESERVED,
KEY_RESERVED,
KEY_RESERVED,
BTN_LEFT
};
static struct mxt_platform_data atmel_224s_tp_platform_data = {
.irqflags = IRQF_TRIGGER_FALLING,
.t19_num_keys = ARRAY_SIZE(mxt_t19_keys),
.t19_keymap = mxt_t19_keys,
.suspend_mode = MXT_SUSPEND_T9_CTRL,
};
static struct i2c_board_info atmel_224s_tp_device = { struct i2c_client *client;
I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
.platform_data = &atmel_224s_tp_platform_data,
.flags = I2C_CLIENT_WAKE,
}; };
static struct mxt_platform_data atmel_1664s_platform_data = { struct chromeos_laptop {
.irqflags = IRQF_TRIGGER_FALLING, /*
.suspend_mode = MXT_SUSPEND_T9_CTRL, * Note that we can't mark this pointer as const because
* i2c_new_probed_device() changes passed in I2C board info, so.
*/
struct i2c_peripheral *i2c_peripherals;
unsigned int num_i2c_peripherals;
}; };
static struct i2c_board_info atmel_1664s_device = { static const struct chromeos_laptop *cros_laptop;
I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR),
.platform_data = &atmel_1664s_platform_data,
.flags = I2C_CLIENT_WAKE,
};
static struct i2c_client *__add_probed_i2c_device( static struct i2c_client *
const char *name, chromes_laptop_instantiate_i2c_device(struct i2c_adapter *adapter,
int bus, struct i2c_board_info *info,
struct i2c_board_info *info, unsigned short alt_addr)
const unsigned short *alt_addr_list)
{ {
const struct dmi_device *dmi_dev;
const struct dmi_dev_onboard *dev_data;
struct i2c_adapter *adapter;
struct i2c_client *client = NULL;
const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END }; const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
struct i2c_client *client;
if (bus < 0)
return NULL;
/*
* If a name is specified, look for irq platform information stashed
* in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
*/
if (name) {
dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
if (!dmi_dev) {
pr_err("%s failed to dmi find device %s.\n",
__func__,
name);
return NULL;
}
dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
if (!dev_data) {
pr_err("%s failed to get data from dmi for %s.\n",
__func__, name);
return NULL;
}
info->irq = dev_data->instance;
}
adapter = i2c_get_adapter(bus);
if (!adapter) {
pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
return NULL;
}
/* /*
* Add the i2c device. If we can't detect it at the primary * Add the i2c device. If we can't detect it at the primary
...@@ -184,339 +79,345 @@ static struct i2c_client *__add_probed_i2c_device( ...@@ -184,339 +79,345 @@ static struct i2c_client *__add_probed_i2c_device(
* structure gets assigned primary address. * structure gets assigned primary address.
*/ */
client = i2c_new_probed_device(adapter, info, addr_list, NULL); client = i2c_new_probed_device(adapter, info, addr_list, NULL);
if (!client && alt_addr_list) { if (!client && alt_addr) {
struct i2c_board_info dummy_info = { struct i2c_board_info dummy_info = {
I2C_BOARD_INFO("dummy", info->addr), I2C_BOARD_INFO("dummy", info->addr),
}; };
const unsigned short alt_addr_list[] = {
alt_addr, I2C_CLIENT_END
};
struct i2c_client *dummy; struct i2c_client *dummy;
dummy = i2c_new_probed_device(adapter, &dummy_info, dummy = i2c_new_probed_device(adapter, &dummy_info,
alt_addr_list, NULL); alt_addr_list, NULL);
if (dummy) { if (dummy) {
pr_debug("%s %d-%02x is probed at %02x\n", pr_debug("%d-%02x is probed at %02x\n",
__func__, bus, info->addr, dummy->addr); adapter->nr, info->addr, dummy->addr);
i2c_unregister_device(dummy); i2c_unregister_device(dummy);
client = i2c_new_device(adapter, info); client = i2c_new_device(adapter, info);
} }
} }
if (!client) if (!client)
pr_notice("%s failed to register device %d-%02x\n", pr_debug("failed to register device %d-%02x\n",
__func__, bus, info->addr); adapter->nr, info->addr);
else else
pr_debug("%s added i2c device %d-%02x\n", pr_debug("added i2c device %d-%02x\n",
__func__, bus, info->addr); adapter->nr, info->addr);
i2c_put_adapter(adapter);
return client; return client;
} }
struct i2c_lookup { static bool chromeos_laptop_match_adapter_devid(struct device *dev, u32 devid)
const char *name;
int instance;
int n;
};
static int __find_i2c_adap(struct device *dev, void *data)
{
struct i2c_lookup *lookup = data;
static const char *prefix = "i2c-";
struct i2c_adapter *adapter;
if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
return 0;
adapter = to_i2c_adapter(dev);
if (strncmp(adapter->name, lookup->name, strlen(lookup->name)) == 0 &&
lookup->n++ == lookup->instance)
return 1;
return 0;
}
static int find_i2c_adapter_num(enum i2c_adapter_type type)
{
struct device *dev = NULL;
struct i2c_adapter *adapter;
struct i2c_lookup lookup;
memset(&lookup, 0, sizeof(lookup));
lookup.name = i2c_adapter_names[type];
lookup.instance = (type == I2C_ADAPTER_DESIGNWARE_1) ? 1 : 0;
/* find the adapter by name */
dev = bus_find_device(&i2c_bus_type, NULL, &lookup, __find_i2c_adap);
if (!dev) {
/* Adapters may appear later. Deferred probing will retry */
pr_notice("%s: i2c adapter %s not found on system.\n", __func__,
lookup.name);
return -ENODEV;
}
adapter = to_i2c_adapter(dev);
return adapter->nr;
}
/*
* Takes a list of addresses in addrs as such :
* { addr1, ... , addrn, I2C_CLIENT_END };
* add_probed_i2c_device will use i2c_new_probed_device
* and probe for devices at all of the addresses listed.
* Returns NULL if no devices found.
* See Documentation/i2c/instantiating-devices for more information.
*/
static struct i2c_client *add_probed_i2c_device(
const char *name,
enum i2c_adapter_type type,
struct i2c_board_info *info,
const unsigned short *addrs)
{ {
return __add_probed_i2c_device(name, struct pci_dev *pdev;
find_i2c_adapter_num(type),
info,
addrs);
}
/* if (!dev_is_pci(dev))
* Probes for a device at a single address, the one provided by return false;
* info->addr.
* Returns NULL if no device found.
*/
static struct i2c_client *add_i2c_device(const char *name,
enum i2c_adapter_type type,
struct i2c_board_info *info)
{
return __add_probed_i2c_device(name,
find_i2c_adapter_num(type),
info,
NULL);
}
static int setup_cyapa_tp(enum i2c_adapter_type type)
{
if (tp)
return 0;
/* add cyapa touchpad */ pdev = to_pci_dev(dev);
tp = add_i2c_device("trackpad", type, &cyapa_device); return devid == PCI_DEVID(pdev->bus->number, pdev->devfn);
return (!tp) ? -EAGAIN : 0;
} }
static int setup_atmel_224s_tp(enum i2c_adapter_type type) static void chromeos_laptop_check_adapter(struct i2c_adapter *adapter)
{ {
const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR, struct i2c_peripheral *i2c_dev;
I2C_CLIENT_END }; int i;
if (tp)
return 0;
/* add atmel mxt touchpad */
tp = add_probed_i2c_device("trackpad", type,
&atmel_224s_tp_device, addr_list);
return (!tp) ? -EAGAIN : 0;
}
static int setup_elantech_tp(enum i2c_adapter_type type) for (i = 0; i < cros_laptop->num_i2c_peripherals; i++) {
{ i2c_dev = &cros_laptop->i2c_peripherals[i];
if (tp)
return 0;
/* add elantech touchpad */ /* Skip devices already created */
tp = add_i2c_device("trackpad", type, &elantech_device); if (i2c_dev->client)
return (!tp) ? -EAGAIN : 0; continue;
}
static int setup_atmel_1664s_ts(enum i2c_adapter_type type) if (strncmp(adapter->name, i2c_adapter_names[i2c_dev->type],
{ strlen(i2c_adapter_names[i2c_dev->type])))
const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR, continue;
I2C_CLIENT_END };
if (ts)
return 0;
/* add atmel mxt touch device */
ts = add_probed_i2c_device("touchscreen", type,
&atmel_1664s_device, addr_list);
return (!ts) ? -EAGAIN : 0;
}
static int setup_isl29018_als(enum i2c_adapter_type type) if (i2c_dev->pci_devid &&
{ !chromeos_laptop_match_adapter_devid(adapter->dev.parent,
if (als) i2c_dev->pci_devid)) {
return 0; continue;
}
/* add isl29018 light sensor */ i2c_dev->client =
als = add_i2c_device("lightsensor", type, &isl_als_device); chromes_laptop_instantiate_i2c_device(adapter,
return (!als) ? -EAGAIN : 0; &i2c_dev->board_info,
i2c_dev->alt_addr);
}
} }
static int setup_tsl2583_als(enum i2c_adapter_type type) static void chromeos_laptop_detach_i2c_client(struct i2c_client *client)
{ {
if (als) struct i2c_peripheral *i2c_dev;
return 0; int i;
/* add tsl2583 light sensor */
als = add_i2c_device(NULL, type, &tsl2583_als_device);
return (!als) ? -EAGAIN : 0;
}
static int setup_tsl2563_als(enum i2c_adapter_type type) for (i = 0; i < cros_laptop->num_i2c_peripherals; i++) {
{ i2c_dev = &cros_laptop->i2c_peripherals[i];
if (als)
return 0;
/* add tsl2563 light sensor */ if (i2c_dev->client == client)
als = add_i2c_device(NULL, type, &tsl2563_als_device); i2c_dev->client = NULL;
return (!als) ? -EAGAIN : 0; }
} }
static int __init chromeos_laptop_dmi_matched(const struct dmi_system_id *id) static int chromeos_laptop_i2c_notifier_call(struct notifier_block *nb,
unsigned long action, void *data)
{ {
cros_laptop = (void *)id->driver_data; struct device *dev = data;
pr_debug("DMI Matched %s.\n", id->ident);
switch (action) {
case BUS_NOTIFY_ADD_DEVICE:
if (dev->type == &i2c_adapter_type)
chromeos_laptop_check_adapter(to_i2c_adapter(dev));
break;
case BUS_NOTIFY_REMOVED_DEVICE:
if (dev->type == &i2c_client_type)
chromeos_laptop_detach_i2c_client(to_i2c_client(dev));
break;
}
/* Indicate to dmi_scan that processing is done. */ return 0;
return 1;
} }
static int chromeos_laptop_probe(struct platform_device *pdev) static struct notifier_block chromeos_laptop_i2c_notifier = {
{ .notifier_call = chromeos_laptop_i2c_notifier_call,
int i; };
int ret = 0;
for (i = 0; i < MAX_I2C_PERIPHERALS; i++) {
struct i2c_peripheral *i2c_dev;
i2c_dev = &cros_laptop->i2c_peripherals[i];
/* No more peripherals. */
if (i2c_dev->add == NULL)
break;
if (i2c_dev->state == TIMEDOUT || i2c_dev->state == PROBED)
continue;
/*
* Check that the i2c adapter is present.
* -EPROBE_DEFER if missing as the adapter may appear much
* later.
*/
if (find_i2c_adapter_num(i2c_dev->type) == -ENODEV) {
ret = -EPROBE_DEFER;
continue;
}
/* Add the device. */
if (i2c_dev->add(i2c_dev->type) == -EAGAIN) {
/*
* Set -EPROBE_DEFER a limited num of times
* if device is not successfully added.
*/
if (++i2c_dev->tries < MAX_I2C_DEVICE_DEFERRALS) {
ret = -EPROBE_DEFER;
} else {
/* Ran out of tries. */
pr_notice("%s: Ran out of tries for device.\n",
__func__);
i2c_dev->state = TIMEDOUT;
}
} else {
i2c_dev->state = PROBED;
}
}
return ret; #define DECLARE_CROS_LAPTOP(_name) \
static const struct chromeos_laptop _name __initconst = { \
.i2c_peripherals = _name##_peripherals, \
.num_i2c_peripherals = ARRAY_SIZE(_name##_peripherals), \
} }
static struct chromeos_laptop samsung_series_5_550 = { static struct i2c_peripheral samsung_series_5_550_peripherals[] __initdata = {
.i2c_peripherals = { /* Touchpad. */
/* Touchpad. */ {
{ .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS }, .board_info = {
/* Light Sensor. */ I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
{ .add = setup_isl29018_als, I2C_ADAPTER_SMBUS }, .flags = I2C_CLIENT_WAKE,
},
.dmi_name = "trackpad",
.type = I2C_ADAPTER_SMBUS,
},
/* Light Sensor. */
{
.board_info = {
I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
},
.dmi_name = "lightsensor",
.type = I2C_ADAPTER_SMBUS,
}, },
}; };
DECLARE_CROS_LAPTOP(samsung_series_5_550);
static struct chromeos_laptop samsung_series_5 = { static struct i2c_peripheral samsung_series_5_peripherals[] __initdata = {
.i2c_peripherals = { /* Light Sensor. */
/* Light Sensor. */ {
{ .add = setup_tsl2583_als, I2C_ADAPTER_SMBUS }, .board_info = {
I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
},
.type = I2C_ADAPTER_SMBUS,
}, },
}; };
DECLARE_CROS_LAPTOP(samsung_series_5);
static struct chromeos_laptop chromebook_pixel = { static const int chromebook_pixel_tp_keys[] __initconst = {
.i2c_peripherals = { KEY_RESERVED,
/* Touch Screen. */ KEY_RESERVED,
{ .add = setup_atmel_1664s_ts, I2C_ADAPTER_PANEL }, KEY_RESERVED,
/* Touchpad. */ KEY_RESERVED,
{ .add = setup_atmel_224s_tp, I2C_ADAPTER_VGADDC }, KEY_RESERVED,
/* Light Sensor. */ BTN_LEFT
{ .add = setup_isl29018_als, I2C_ADAPTER_PANEL },
},
}; };
static struct chromeos_laptop hp_chromebook_14 = { static const struct property_entry
.i2c_peripherals = { chromebook_pixel_trackpad_props[] __initconst = {
/* Touchpad. */ PROPERTY_ENTRY_U32_ARRAY("linux,gpio-keymap", chromebook_pixel_tp_keys),
{ .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, { }
};
static struct i2c_peripheral chromebook_pixel_peripherals[] __initdata = {
/* Touch Screen. */
{
.board_info = {
I2C_BOARD_INFO("atmel_mxt_ts",
ATMEL_TS_I2C_ADDR),
.flags = I2C_CLIENT_WAKE,
},
.dmi_name = "touchscreen",
.irqflags = IRQF_TRIGGER_FALLING,
.type = I2C_ADAPTER_PANEL,
.alt_addr = ATMEL_TS_I2C_BL_ADDR,
},
/* Touchpad. */
{
.board_info = {
I2C_BOARD_INFO("atmel_mxt_tp",
ATMEL_TP_I2C_ADDR),
.properties =
chromebook_pixel_trackpad_props,
.flags = I2C_CLIENT_WAKE,
},
.dmi_name = "trackpad",
.irqflags = IRQF_TRIGGER_FALLING,
.type = I2C_ADAPTER_VGADDC,
.alt_addr = ATMEL_TP_I2C_BL_ADDR,
},
/* Light Sensor. */
{
.board_info = {
I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
},
.dmi_name = "lightsensor",
.type = I2C_ADAPTER_PANEL,
}, },
}; };
DECLARE_CROS_LAPTOP(chromebook_pixel);
static struct chromeos_laptop dell_chromebook_11 = { static struct i2c_peripheral hp_chromebook_14_peripherals[] __initdata = {
.i2c_peripherals = { /* Touchpad. */
/* Touchpad. */ {
{ .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, .board_info = {
/* Elan Touchpad option. */ I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
{ .add = setup_elantech_tp, I2C_ADAPTER_DESIGNWARE_0 }, .flags = I2C_CLIENT_WAKE,
},
.dmi_name = "trackpad",
.type = I2C_ADAPTER_DESIGNWARE,
}, },
}; };
DECLARE_CROS_LAPTOP(hp_chromebook_14);
static struct chromeos_laptop toshiba_cb35 = { static struct i2c_peripheral dell_chromebook_11_peripherals[] __initdata = {
.i2c_peripherals = { /* Touchpad. */
/* Touchpad. */ {
{ .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, .board_info = {
I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
.flags = I2C_CLIENT_WAKE,
},
.dmi_name = "trackpad",
.type = I2C_ADAPTER_DESIGNWARE,
},
/* Elan Touchpad option. */
{
.board_info = {
I2C_BOARD_INFO("elan_i2c", ELAN_TP_I2C_ADDR),
.flags = I2C_CLIENT_WAKE,
},
.dmi_name = "trackpad",
.type = I2C_ADAPTER_DESIGNWARE,
}, },
}; };
DECLARE_CROS_LAPTOP(dell_chromebook_11);
static struct chromeos_laptop acer_c7_chromebook = { static struct i2c_peripheral toshiba_cb35_peripherals[] __initdata = {
.i2c_peripherals = { /* Touchpad. */
/* Touchpad. */ {
{ .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS }, .board_info = {
I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
.flags = I2C_CLIENT_WAKE,
},
.dmi_name = "trackpad",
.type = I2C_ADAPTER_DESIGNWARE,
}, },
}; };
DECLARE_CROS_LAPTOP(toshiba_cb35);
static struct chromeos_laptop acer_ac700 = { static struct i2c_peripheral acer_c7_chromebook_peripherals[] __initdata = {
.i2c_peripherals = { /* Touchpad. */
/* Light Sensor. */ {
{ .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS }, .board_info = {
I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
.flags = I2C_CLIENT_WAKE,
},
.dmi_name = "trackpad",
.type = I2C_ADAPTER_SMBUS,
}, },
}; };
DECLARE_CROS_LAPTOP(acer_c7_chromebook);
static struct chromeos_laptop acer_c720 = { static struct i2c_peripheral acer_ac700_peripherals[] __initdata = {
.i2c_peripherals = { /* Light Sensor. */
/* Touchscreen. */ {
{ .add = setup_atmel_1664s_ts, I2C_ADAPTER_DESIGNWARE_1 }, .board_info = {
/* Touchpad. */ I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
{ .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, },
/* Elan Touchpad option. */ .type = I2C_ADAPTER_SMBUS,
{ .add = setup_elantech_tp, I2C_ADAPTER_DESIGNWARE_0 },
/* Light Sensor. */
{ .add = setup_isl29018_als, I2C_ADAPTER_DESIGNWARE_1 },
}, },
}; };
DECLARE_CROS_LAPTOP(acer_ac700);
static struct chromeos_laptop hp_pavilion_14_chromebook = { static struct i2c_peripheral acer_c720_peripherals[] __initdata = {
.i2c_peripherals = { /* Touchscreen. */
/* Touchpad. */ {
{ .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS }, .board_info = {
I2C_BOARD_INFO("atmel_mxt_ts",
ATMEL_TS_I2C_ADDR),
.flags = I2C_CLIENT_WAKE,
},
.dmi_name = "touchscreen",
.irqflags = IRQF_TRIGGER_FALLING,
.type = I2C_ADAPTER_DESIGNWARE,
.pci_devid = PCI_DEVID(0, PCI_DEVFN(0x15, 0x2)),
.alt_addr = ATMEL_TS_I2C_BL_ADDR,
},
/* Touchpad. */
{
.board_info = {
I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
.flags = I2C_CLIENT_WAKE,
},
.dmi_name = "trackpad",
.type = I2C_ADAPTER_DESIGNWARE,
.pci_devid = PCI_DEVID(0, PCI_DEVFN(0x15, 0x1)),
},
/* Elan Touchpad option. */
{
.board_info = {
I2C_BOARD_INFO("elan_i2c", ELAN_TP_I2C_ADDR),
.flags = I2C_CLIENT_WAKE,
},
.dmi_name = "trackpad",
.type = I2C_ADAPTER_DESIGNWARE,
.pci_devid = PCI_DEVID(0, PCI_DEVFN(0x15, 0x1)),
},
/* Light Sensor. */
{
.board_info = {
I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
},
.dmi_name = "lightsensor",
.type = I2C_ADAPTER_DESIGNWARE,
.pci_devid = PCI_DEVID(0, PCI_DEVFN(0x15, 0x2)),
}, },
}; };
DECLARE_CROS_LAPTOP(acer_c720);
static struct chromeos_laptop cr48 = { static struct i2c_peripheral
.i2c_peripherals = { hp_pavilion_14_chromebook_peripherals[] __initdata = {
/* Light Sensor. */ /* Touchpad. */
{ .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS }, {
.board_info = {
I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
.flags = I2C_CLIENT_WAKE,
},
.dmi_name = "trackpad",
.type = I2C_ADAPTER_SMBUS,
}, },
}; };
DECLARE_CROS_LAPTOP(hp_pavilion_14_chromebook);
#define _CBDD(board_) \ static struct i2c_peripheral cr48_peripherals[] __initdata = {
.callback = chromeos_laptop_dmi_matched, \ /* Light Sensor. */
.driver_data = (void *)&board_ {
.board_info = {
I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
},
.type = I2C_ADAPTER_SMBUS,
},
};
DECLARE_CROS_LAPTOP(cr48);
static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
{ {
...@@ -525,14 +426,14 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { ...@@ -525,14 +426,14 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"), DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"), DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
}, },
_CBDD(samsung_series_5_550), .driver_data = (void *)&samsung_series_5_550,
}, },
{ {
.ident = "Samsung Series 5", .ident = "Samsung Series 5",
.matches = { .matches = {
DMI_MATCH(DMI_PRODUCT_NAME, "Alex"), DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
}, },
_CBDD(samsung_series_5), .driver_data = (void *)&samsung_series_5,
}, },
{ {
.ident = "Chromebook Pixel", .ident = "Chromebook Pixel",
...@@ -540,7 +441,7 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { ...@@ -540,7 +441,7 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"), DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
DMI_MATCH(DMI_PRODUCT_NAME, "Link"), DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
}, },
_CBDD(chromebook_pixel), .driver_data = (void *)&chromebook_pixel,
}, },
{ {
.ident = "Wolf", .ident = "Wolf",
...@@ -548,7 +449,7 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { ...@@ -548,7 +449,7 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"), DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"),
DMI_MATCH(DMI_PRODUCT_NAME, "Wolf"), DMI_MATCH(DMI_PRODUCT_NAME, "Wolf"),
}, },
_CBDD(dell_chromebook_11), .driver_data = (void *)&dell_chromebook_11,
}, },
{ {
.ident = "HP Chromebook 14", .ident = "HP Chromebook 14",
...@@ -556,7 +457,7 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { ...@@ -556,7 +457,7 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"), DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"),
DMI_MATCH(DMI_PRODUCT_NAME, "Falco"), DMI_MATCH(DMI_PRODUCT_NAME, "Falco"),
}, },
_CBDD(hp_chromebook_14), .driver_data = (void *)&hp_chromebook_14,
}, },
{ {
.ident = "Toshiba CB35", .ident = "Toshiba CB35",
...@@ -564,99 +465,214 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { ...@@ -564,99 +465,214 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"), DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"),
DMI_MATCH(DMI_PRODUCT_NAME, "Leon"), DMI_MATCH(DMI_PRODUCT_NAME, "Leon"),
}, },
_CBDD(toshiba_cb35), .driver_data = (void *)&toshiba_cb35,
}, },
{ {
.ident = "Acer C7 Chromebook", .ident = "Acer C7 Chromebook",
.matches = { .matches = {
DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"), DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
}, },
_CBDD(acer_c7_chromebook), .driver_data = (void *)&acer_c7_chromebook,
}, },
{ {
.ident = "Acer AC700", .ident = "Acer AC700",
.matches = { .matches = {
DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"), DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
}, },
_CBDD(acer_ac700), .driver_data = (void *)&acer_ac700,
}, },
{ {
.ident = "Acer C720", .ident = "Acer C720",
.matches = { .matches = {
DMI_MATCH(DMI_PRODUCT_NAME, "Peppy"), DMI_MATCH(DMI_PRODUCT_NAME, "Peppy"),
}, },
_CBDD(acer_c720), .driver_data = (void *)&acer_c720,
}, },
{ {
.ident = "HP Pavilion 14 Chromebook", .ident = "HP Pavilion 14 Chromebook",
.matches = { .matches = {
DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"), DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
}, },
_CBDD(hp_pavilion_14_chromebook), .driver_data = (void *)&hp_pavilion_14_chromebook,
}, },
{ {
.ident = "Cr-48", .ident = "Cr-48",
.matches = { .matches = {
DMI_MATCH(DMI_PRODUCT_NAME, "Mario"), DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
}, },
_CBDD(cr48), .driver_data = (void *)&cr48,
}, },
{ } { }
}; };
MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table); MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
static struct platform_device *cros_platform_device; static int __init chromeos_laptop_scan_adapter(struct device *dev, void *data)
{
struct i2c_adapter *adapter;
static struct platform_driver cros_platform_driver = { adapter = i2c_verify_adapter(dev);
.driver = { if (adapter)
.name = "chromeos_laptop", chromeos_laptop_check_adapter(adapter);
},
.probe = chromeos_laptop_probe, return 0;
}; }
static int __init chromeos_laptop_get_irq_from_dmi(const char *dmi_name)
{
const struct dmi_device *dmi_dev;
const struct dmi_dev_onboard *dev_data;
dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, dmi_name, NULL);
if (!dmi_dev) {
pr_err("failed to find DMI device '%s'\n", dmi_name);
return -ENOENT;
}
dev_data = dmi_dev->device_data;
if (!dev_data) {
pr_err("failed to get data from DMI for '%s'\n", dmi_name);
return -EINVAL;
}
return dev_data->instance;
}
static int __init chromeos_laptop_setup_irq(struct i2c_peripheral *i2c_dev)
{
int irq;
if (i2c_dev->dmi_name) {
irq = chromeos_laptop_get_irq_from_dmi(i2c_dev->dmi_name);
if (irq < 0)
return irq;
i2c_dev->irq_resource = (struct resource)
DEFINE_RES_NAMED(irq, 1, NULL,
IORESOURCE_IRQ | i2c_dev->irqflags);
i2c_dev->board_info.resources = &i2c_dev->irq_resource;
i2c_dev->board_info.num_resources = 1;
}
return 0;
}
static struct chromeos_laptop * __init
chromeos_laptop_prepare(const struct chromeos_laptop *src)
{
struct chromeos_laptop *cros_laptop;
struct i2c_peripheral *i2c_dev;
struct i2c_board_info *info;
int error;
int i;
cros_laptop = kzalloc(sizeof(*cros_laptop), GFP_KERNEL);
if (!cros_laptop)
return ERR_PTR(-ENOMEM);
cros_laptop->i2c_peripherals = kmemdup(src->i2c_peripherals,
src->num_i2c_peripherals *
sizeof(*src->i2c_peripherals),
GFP_KERNEL);
if (!cros_laptop->i2c_peripherals) {
error = -ENOMEM;
goto err_free_cros_laptop;
}
cros_laptop->num_i2c_peripherals = src->num_i2c_peripherals;
for (i = 0; i < cros_laptop->num_i2c_peripherals; i++) {
i2c_dev = &cros_laptop->i2c_peripherals[i];
info = &i2c_dev->board_info;
error = chromeos_laptop_setup_irq(i2c_dev);
if (error)
goto err_destroy_cros_peripherals;
/* We need to deep-copy properties */
if (info->properties) {
info->properties =
property_entries_dup(info->properties);
if (IS_ERR(info->properties)) {
error = PTR_ERR(info->properties);
goto err_destroy_cros_peripherals;
}
}
}
return cros_laptop;
err_destroy_cros_peripherals:
while (--i >= 0) {
i2c_dev = &cros_laptop->i2c_peripherals[i];
info = &i2c_dev->board_info;
if (info->properties)
property_entries_free(info->properties);
}
kfree(cros_laptop->i2c_peripherals);
err_free_cros_laptop:
kfree(cros_laptop);
return ERR_PTR(error);
}
static void chromeos_laptop_destroy(const struct chromeos_laptop *cros_laptop)
{
struct i2c_peripheral *i2c_dev;
struct i2c_board_info *info;
int i;
for (i = 0; i < cros_laptop->num_i2c_peripherals; i++) {
i2c_dev = &cros_laptop->i2c_peripherals[i];
info = &i2c_dev->board_info;
if (i2c_dev->client)
i2c_unregister_device(i2c_dev->client);
if (info->properties)
property_entries_free(info->properties);
}
kfree(cros_laptop->i2c_peripherals);
kfree(cros_laptop);
}
static int __init chromeos_laptop_init(void) static int __init chromeos_laptop_init(void)
{ {
int ret; const struct dmi_system_id *dmi_id;
int error;
if (!dmi_check_system(chromeos_laptop_dmi_table)) { dmi_id = dmi_first_match(chromeos_laptop_dmi_table);
pr_debug("%s unsupported system.\n", __func__); if (!dmi_id) {
pr_debug("unsupported system\n");
return -ENODEV; return -ENODEV;
} }
ret = platform_driver_register(&cros_platform_driver); pr_debug("DMI Matched %s\n", dmi_id->ident);
if (ret)
return ret; cros_laptop = chromeos_laptop_prepare((void *)dmi_id->driver_data);
if (IS_ERR(cros_laptop))
return PTR_ERR(cros_laptop);
cros_platform_device = platform_device_alloc("chromeos_laptop", -1); error = bus_register_notifier(&i2c_bus_type,
if (!cros_platform_device) { &chromeos_laptop_i2c_notifier);
ret = -ENOMEM; if (error) {
goto fail_platform_device1; pr_err("failed to register i2c bus notifier: %d\n", error);
chromeos_laptop_destroy(cros_laptop);
return error;
} }
ret = platform_device_add(cros_platform_device); /*
if (ret) * Scan adapters that have been registered before we installed
goto fail_platform_device2; * the notifier to make sure we do not miss any devices.
*/
i2c_for_each_dev(NULL, chromeos_laptop_scan_adapter);
return 0; return 0;
fail_platform_device2:
platform_device_put(cros_platform_device);
fail_platform_device1:
platform_driver_unregister(&cros_platform_driver);
return ret;
} }
static void __exit chromeos_laptop_exit(void) static void __exit chromeos_laptop_exit(void)
{ {
if (als) bus_unregister_notifier(&i2c_bus_type, &chromeos_laptop_i2c_notifier);
i2c_unregister_device(als); chromeos_laptop_destroy(cros_laptop);
if (tp)
i2c_unregister_device(tp);
if (ts)
i2c_unregister_device(ts);
platform_device_unregister(cros_platform_device);
platform_driver_unregister(&cros_platform_driver);
} }
module_init(chromeos_laptop_init); module_init(chromeos_laptop_init);
......
...@@ -211,6 +211,58 @@ static int cros_ec_console_log_release(struct inode *inode, struct file *file) ...@@ -211,6 +211,58 @@ static int cros_ec_console_log_release(struct inode *inode, struct file *file)
return 0; return 0;
} }
static ssize_t cros_ec_pdinfo_read(struct file *file,
char __user *user_buf,
size_t count,
loff_t *ppos)
{
char read_buf[EC_USB_PD_MAX_PORTS * 40], *p = read_buf;
struct cros_ec_debugfs *debug_info = file->private_data;
struct cros_ec_device *ec_dev = debug_info->ec->ec_dev;
struct {
struct cros_ec_command msg;
union {
struct ec_response_usb_pd_control_v1 resp;
struct ec_params_usb_pd_control params;
};
} __packed ec_buf;
struct cros_ec_command *msg;
struct ec_response_usb_pd_control_v1 *resp;
struct ec_params_usb_pd_control *params;
int i;
msg = &ec_buf.msg;
params = (struct ec_params_usb_pd_control *)msg->data;
resp = (struct ec_response_usb_pd_control_v1 *)msg->data;
msg->command = EC_CMD_USB_PD_CONTROL;
msg->version = 1;
msg->insize = sizeof(*resp);
msg->outsize = sizeof(*params);
/*
* Read status from all PD ports until failure, typically caused
* by attempting to read status on a port that doesn't exist.
*/
for (i = 0; i < EC_USB_PD_MAX_PORTS; ++i) {
params->port = i;
params->role = 0;
params->mux = 0;
params->swap = 0;
if (cros_ec_cmd_xfer_status(ec_dev, msg) < 0)
break;
p += scnprintf(p, sizeof(read_buf) + read_buf - p,
"p%d: %s en:%.2x role:%.2x pol:%.2x\n", i,
resp->state, resp->enabled, resp->role,
resp->polarity);
}
return simple_read_from_buffer(user_buf, count, ppos,
read_buf, p - read_buf);
}
const struct file_operations cros_ec_console_log_fops = { const struct file_operations cros_ec_console_log_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = cros_ec_console_log_open, .open = cros_ec_console_log_open,
...@@ -220,6 +272,13 @@ const struct file_operations cros_ec_console_log_fops = { ...@@ -220,6 +272,13 @@ const struct file_operations cros_ec_console_log_fops = {
.release = cros_ec_console_log_release, .release = cros_ec_console_log_release,
}; };
const struct file_operations cros_ec_pdinfo_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.read = cros_ec_pdinfo_read,
.llseek = default_llseek,
};
static int ec_read_version_supported(struct cros_ec_dev *ec) static int ec_read_version_supported(struct cros_ec_dev *ec)
{ {
struct ec_params_get_cmd_versions_v1 *params; struct ec_params_get_cmd_versions_v1 *params;
...@@ -288,7 +347,7 @@ static int cros_ec_create_console_log(struct cros_ec_debugfs *debug_info) ...@@ -288,7 +347,7 @@ static int cros_ec_create_console_log(struct cros_ec_debugfs *debug_info)
init_waitqueue_head(&debug_info->log_wq); init_waitqueue_head(&debug_info->log_wq);
if (!debugfs_create_file("console_log", if (!debugfs_create_file("console_log",
S_IFREG | S_IRUGO, S_IFREG | 0444,
debug_info->dir, debug_info->dir,
debug_info, debug_info,
&cros_ec_console_log_fops)) &cros_ec_console_log_fops))
...@@ -341,7 +400,7 @@ static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info) ...@@ -341,7 +400,7 @@ static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info)
debug_info->panicinfo_blob.size = ret; debug_info->panicinfo_blob.size = ret;
if (!debugfs_create_blob("panicinfo", if (!debugfs_create_blob("panicinfo",
S_IFREG | S_IRUGO, S_IFREG | 0444,
debug_info->dir, debug_info->dir,
&debug_info->panicinfo_blob)) { &debug_info->panicinfo_blob)) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -355,6 +414,15 @@ static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info) ...@@ -355,6 +414,15 @@ static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info)
return ret; return ret;
} }
static int cros_ec_create_pdinfo(struct cros_ec_debugfs *debug_info)
{
if (!debugfs_create_file("pdinfo", 0444, debug_info->dir, debug_info,
&cros_ec_pdinfo_fops))
return -ENOMEM;
return 0;
}
int cros_ec_debugfs_init(struct cros_ec_dev *ec) int cros_ec_debugfs_init(struct cros_ec_dev *ec)
{ {
struct cros_ec_platform *ec_platform = dev_get_platdata(ec->dev); struct cros_ec_platform *ec_platform = dev_get_platdata(ec->dev);
...@@ -379,6 +447,10 @@ int cros_ec_debugfs_init(struct cros_ec_dev *ec) ...@@ -379,6 +447,10 @@ int cros_ec_debugfs_init(struct cros_ec_dev *ec)
if (ret) if (ret)
goto remove_debugfs; goto remove_debugfs;
ret = cros_ec_create_pdinfo(debug_info);
if (ret)
goto remove_debugfs;
ec->debug_info = debug_info; ec->debug_info = debug_info;
return 0; return 0;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/printk.h> #include <linux/printk.h>
#include <linux/suspend.h>
#define DRV_NAME "cros_ec_lpcs" #define DRV_NAME "cros_ec_lpcs"
#define ACPI_DRV_NAME "GOOG0004" #define ACPI_DRV_NAME "GOOG0004"
...@@ -235,6 +236,9 @@ static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data) ...@@ -235,6 +236,9 @@ static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
cros_ec_get_next_event(ec_dev, NULL) > 0) cros_ec_get_next_event(ec_dev, NULL) > 0)
blocking_notifier_call_chain(&ec_dev->event_notifier, 0, blocking_notifier_call_chain(&ec_dev->event_notifier, 0,
ec_dev); ec_dev);
if (value == ACPI_NOTIFY_DEVICE_WAKE)
pm_system_wakeup();
} }
static int cros_ec_lpc_probe(struct platform_device *pdev) static int cros_ec_lpc_probe(struct platform_device *pdev)
...@@ -341,6 +345,18 @@ static const struct dmi_system_id cros_ec_lpc_dmi_table[] __initconst = { ...@@ -341,6 +345,18 @@ static const struct dmi_system_id cros_ec_lpc_dmi_table[] __initconst = {
DMI_MATCH(DMI_BIOS_VERSION, "Google_"), DMI_MATCH(DMI_BIOS_VERSION, "Google_"),
}, },
}, },
{
/*
* If the box is running custom coreboot firmware then the
* DMI BIOS version string will not be matched by "Google_",
* but the system vendor string will still be matched by
* "GOOGLE".
*/
.matches = {
DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"),
DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
},
},
{ {
/* x86-link, the Chromebook Pixel. */ /* x86-link, the Chromebook Pixel. */
.matches = { .matches = {
......
...@@ -34,10 +34,12 @@ ...@@ -34,10 +34,12 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev)
/* Accessor functions */ /* Accessor functions */
static ssize_t show_ec_reboot(struct device *dev, static ssize_t reboot_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
int count = 0; int count = 0;
...@@ -48,9 +50,9 @@ static ssize_t show_ec_reboot(struct device *dev, ...@@ -48,9 +50,9 @@ static ssize_t show_ec_reboot(struct device *dev,
return count; return count;
} }
static ssize_t store_ec_reboot(struct device *dev, static ssize_t reboot_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
static const struct { static const struct {
const char * const str; const char * const str;
...@@ -70,8 +72,7 @@ static ssize_t store_ec_reboot(struct device *dev, ...@@ -70,8 +72,7 @@ static ssize_t store_ec_reboot(struct device *dev,
int got_cmd = 0, offset = 0; int got_cmd = 0, offset = 0;
int i; int i;
int ret; int ret;
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct cros_ec_dev, class_dev);
msg = kmalloc(sizeof(*msg) + sizeof(*param), GFP_KERNEL); msg = kmalloc(sizeof(*msg) + sizeof(*param), GFP_KERNEL);
if (!msg) if (!msg)
...@@ -114,22 +115,16 @@ static ssize_t store_ec_reboot(struct device *dev, ...@@ -114,22 +115,16 @@ static ssize_t store_ec_reboot(struct device *dev,
msg->command = EC_CMD_REBOOT_EC + ec->cmd_offset; msg->command = EC_CMD_REBOOT_EC + ec->cmd_offset;
msg->outsize = sizeof(*param); msg->outsize = sizeof(*param);
msg->insize = 0; msg->insize = 0;
ret = cros_ec_cmd_xfer(ec->ec_dev, msg); ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0) { if (ret < 0)
count = ret; count = ret;
goto exit;
}
if (msg->result != EC_RES_SUCCESS) {
dev_dbg(ec->dev, "EC result %d\n", msg->result);
count = -EINVAL;
}
exit: exit:
kfree(msg); kfree(msg);
return count; return count;
} }
static ssize_t show_ec_version(struct device *dev, static ssize_t version_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
static const char * const image_names[] = {"unknown", "RO", "RW"}; static const char * const image_names[] = {"unknown", "RO", "RW"};
struct ec_response_get_version *r_ver; struct ec_response_get_version *r_ver;
...@@ -138,8 +133,7 @@ static ssize_t show_ec_version(struct device *dev, ...@@ -138,8 +133,7 @@ static ssize_t show_ec_version(struct device *dev,
struct cros_ec_command *msg; struct cros_ec_command *msg;
int ret; int ret;
int count = 0; int count = 0;
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct cros_ec_dev, class_dev);
msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL); msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
if (!msg) if (!msg)
...@@ -150,17 +144,11 @@ static ssize_t show_ec_version(struct device *dev, ...@@ -150,17 +144,11 @@ static ssize_t show_ec_version(struct device *dev,
msg->command = EC_CMD_GET_VERSION + ec->cmd_offset; msg->command = EC_CMD_GET_VERSION + ec->cmd_offset;
msg->insize = sizeof(*r_ver); msg->insize = sizeof(*r_ver);
msg->outsize = 0; msg->outsize = 0;
ret = cros_ec_cmd_xfer(ec->ec_dev, msg); ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0) { if (ret < 0) {
count = ret; count = ret;
goto exit; goto exit;
} }
if (msg->result != EC_RES_SUCCESS) {
count = scnprintf(buf, PAGE_SIZE,
"ERROR: EC returned %d\n", msg->result);
goto exit;
}
r_ver = (struct ec_response_get_version *)msg->data; r_ver = (struct ec_response_get_version *)msg->data;
/* Strings should be null-terminated, but let's be sure. */ /* Strings should be null-terminated, but let's be sure. */
r_ver->version_string_ro[sizeof(r_ver->version_string_ro) - 1] = '\0'; r_ver->version_string_ro[sizeof(r_ver->version_string_ro) - 1] = '\0';
...@@ -237,14 +225,13 @@ static ssize_t show_ec_version(struct device *dev, ...@@ -237,14 +225,13 @@ static ssize_t show_ec_version(struct device *dev,
return count; return count;
} }
static ssize_t show_ec_flashinfo(struct device *dev, static ssize_t flashinfo_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct ec_response_flash_info *resp; struct ec_response_flash_info *resp;
struct cros_ec_command *msg; struct cros_ec_command *msg;
int ret; int ret;
struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct cros_ec_dev, class_dev);
msg = kmalloc(sizeof(*msg) + sizeof(*resp), GFP_KERNEL); msg = kmalloc(sizeof(*msg) + sizeof(*resp), GFP_KERNEL);
if (!msg) if (!msg)
...@@ -255,14 +242,9 @@ static ssize_t show_ec_flashinfo(struct device *dev, ...@@ -255,14 +242,9 @@ static ssize_t show_ec_flashinfo(struct device *dev,
msg->command = EC_CMD_FLASH_INFO + ec->cmd_offset; msg->command = EC_CMD_FLASH_INFO + ec->cmd_offset;
msg->insize = sizeof(*resp); msg->insize = sizeof(*resp);
msg->outsize = 0; msg->outsize = 0;
ret = cros_ec_cmd_xfer(ec->ec_dev, msg); ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0) if (ret < 0)
goto exit; goto exit;
if (msg->result != EC_RES_SUCCESS) {
ret = scnprintf(buf, PAGE_SIZE,
"ERROR: EC returned %d\n", msg->result);
goto exit;
}
resp = (struct ec_response_flash_info *)msg->data; resp = (struct ec_response_flash_info *)msg->data;
...@@ -276,21 +258,102 @@ static ssize_t show_ec_flashinfo(struct device *dev, ...@@ -276,21 +258,102 @@ static ssize_t show_ec_flashinfo(struct device *dev,
return ret; return ret;
} }
/* Keyboard wake angle control */
static ssize_t kb_wake_angle_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct ec_response_motion_sense *resp;
struct ec_params_motion_sense *param;
struct cros_ec_command *msg;
int ret;
msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
if (!msg)
return -ENOMEM;
param = (struct ec_params_motion_sense *)msg->data;
msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
msg->version = 2;
param->cmd = MOTIONSENSE_CMD_KB_WAKE_ANGLE;
param->kb_wake_angle.data = EC_MOTION_SENSE_NO_VALUE;
msg->outsize = sizeof(*param);
msg->insize = sizeof(*resp);
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0)
goto exit;
resp = (struct ec_response_motion_sense *)msg->data;
ret = scnprintf(buf, PAGE_SIZE, "%d\n", resp->kb_wake_angle.ret);
exit:
kfree(msg);
return ret;
}
static ssize_t kb_wake_angle_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct ec_params_motion_sense *param;
struct cros_ec_command *msg;
u16 angle;
int ret;
ret = kstrtou16(buf, 0, &angle);
if (ret)
return ret;
msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
if (!msg)
return -ENOMEM;
param = (struct ec_params_motion_sense *)msg->data;
msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
msg->version = 2;
param->cmd = MOTIONSENSE_CMD_KB_WAKE_ANGLE;
param->kb_wake_angle.data = angle;
msg->outsize = sizeof(*param);
msg->insize = sizeof(struct ec_response_motion_sense);
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
kfree(msg);
if (ret < 0)
return ret;
return count;
}
/* Module initialization */ /* Module initialization */
static DEVICE_ATTR(reboot, S_IWUSR | S_IRUGO, show_ec_reboot, store_ec_reboot); static DEVICE_ATTR_RW(reboot);
static DEVICE_ATTR(version, S_IRUGO, show_ec_version, NULL); static DEVICE_ATTR_RO(version);
static DEVICE_ATTR(flashinfo, S_IRUGO, show_ec_flashinfo, NULL); static DEVICE_ATTR_RO(flashinfo);
static DEVICE_ATTR_RW(kb_wake_angle);
static struct attribute *__ec_attrs[] = { static struct attribute *__ec_attrs[] = {
&dev_attr_kb_wake_angle.attr,
&dev_attr_reboot.attr, &dev_attr_reboot.attr,
&dev_attr_version.attr, &dev_attr_version.attr,
&dev_attr_flashinfo.attr, &dev_attr_flashinfo.attr,
NULL, NULL,
}; };
static umode_t cros_ec_ctrl_visible(struct kobject *kobj,
struct attribute *a, int n)
{
struct device *dev = container_of(kobj, struct device, kobj);
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
if (a == &dev_attr_kb_wake_angle.attr && !ec->has_kb_wake_angle)
return 0;
return a->mode;
}
struct attribute_group cros_ec_attr_group = { struct attribute_group cros_ec_attr_group = {
.attrs = __ec_attrs, .attrs = __ec_attrs,
.is_visible = cros_ec_ctrl_visible,
}; };
EXPORT_SYMBOL(cros_ec_attr_group); EXPORT_SYMBOL(cros_ec_attr_group);
......
...@@ -183,6 +183,7 @@ struct cros_ec_debugfs; ...@@ -183,6 +183,7 @@ struct cros_ec_debugfs;
* @ec_dev: cros_ec_device structure to talk to the physical device * @ec_dev: cros_ec_device structure to talk to the physical device
* @dev: pointer to the platform device * @dev: pointer to the platform device
* @debug_info: cros_ec_debugfs structure for debugging information * @debug_info: cros_ec_debugfs structure for debugging information
* @has_kb_wake_angle: true if at least 2 accelerometer are connected to the EC.
* @cmd_offset: offset to apply for each command. * @cmd_offset: offset to apply for each command.
*/ */
struct cros_ec_dev { struct cros_ec_dev {
...@@ -191,6 +192,7 @@ struct cros_ec_dev { ...@@ -191,6 +192,7 @@ struct cros_ec_dev {
struct cros_ec_device *ec_dev; struct cros_ec_device *ec_dev;
struct device *dev; struct device *dev;
struct cros_ec_debugfs *debug_info; struct cros_ec_debugfs *debug_info;
bool has_kb_wake_angle;
u16 cmd_offset; u16 cmd_offset;
u32 features[2]; u32 features[2];
}; };
......
...@@ -2948,6 +2948,9 @@ struct ec_response_usb_pd_control_v1 { ...@@ -2948,6 +2948,9 @@ struct ec_response_usb_pd_control_v1 {
#define EC_CMD_USB_PD_PORTS 0x102 #define EC_CMD_USB_PD_PORTS 0x102
/* Maximum number of PD ports on a device, num_ports will be <= this */
#define EC_USB_PD_MAX_PORTS 8
struct ec_response_usb_pd_ports { struct ec_response_usb_pd_ports {
uint8_t num_ports; uint8_t num_ports;
} __packed; } __packed;
......
/*
* Atmel maXTouch Touchscreen driver
*
* Copyright (C) 2010 Samsung Electronics Co.Ltd
* Author: Joonyoung Shim <jy0922.shim@samsung.com>
*
* 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.
*/
#ifndef __LINUX_PLATFORM_DATA_ATMEL_MXT_TS_H
#define __LINUX_PLATFORM_DATA_ATMEL_MXT_TS_H
#include <linux/types.h>
enum mxt_suspend_mode {
MXT_SUSPEND_DEEP_SLEEP = 0,
MXT_SUSPEND_T9_CTRL = 1,
};
/* The platform data for the Atmel maXTouch touchscreen driver */
struct mxt_platform_data {
unsigned long irqflags;
u8 t19_num_keys;
const unsigned int *t19_keymap;
enum mxt_suspend_mode suspend_mode;
};
#endif /* __LINUX_PLATFORM_DATA_ATMEL_MXT_TS_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment