Commit 65582920 authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Benson Leung

platform/chrome: chromeos_laptop - parse DMI IRQ data once

Instead of trying to parse DMI IRQ data every time we try to instantiate a
device, let's do it once, when we identify the device we are working with.
This allows us to mark chromeos_laptop_get_irq_from_dmi() as __init and
discard it once module is initialized.
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarBenson Leung <bleung@chromium.org>
parent 28cd38f1
...@@ -68,26 +68,6 @@ struct chromeos_laptop { ...@@ -68,26 +68,6 @@ struct chromeos_laptop {
static struct chromeos_laptop *cros_laptop; static struct chromeos_laptop *cros_laptop;
static int 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 struct i2c_client * static struct i2c_client *
chromes_laptop_instantiate_i2c_device(int bus, chromes_laptop_instantiate_i2c_device(int bus,
struct i2c_board_info *info, struct i2c_board_info *info,
...@@ -185,7 +165,6 @@ static int chromeos_laptop_add_peripheral(struct i2c_peripheral *i2c_dev) ...@@ -185,7 +165,6 @@ static int chromeos_laptop_add_peripheral(struct i2c_peripheral *i2c_dev)
{ {
struct i2c_client *client; struct i2c_client *client;
int bus; int bus;
int irq;
/* /*
* Check that the i2c adapter is present. * Check that the i2c adapter is present.
...@@ -196,16 +175,6 @@ static int chromeos_laptop_add_peripheral(struct i2c_peripheral *i2c_dev) ...@@ -196,16 +175,6 @@ static int chromeos_laptop_add_peripheral(struct i2c_peripheral *i2c_dev)
if (bus < 0) if (bus < 0)
return bus == -ENODEV ? -EPROBE_DEFER : bus; return bus == -ENODEV ? -EPROBE_DEFER : bus;
if (i2c_dev->dmi_name) {
irq = chromeos_laptop_get_irq_from_dmi(i2c_dev->dmi_name);
if (irq < 0) {
i2c_dev->state = FAILED;
return irq;
}
i2c_dev->board_info.irq = irq;
}
client = chromes_laptop_instantiate_i2c_device(bus, client = chromes_laptop_instantiate_i2c_device(bus,
&i2c_dev->board_info, &i2c_dev->board_info,
i2c_dev->alt_addr); i2c_dev->alt_addr);
...@@ -230,15 +199,6 @@ static int chromeos_laptop_add_peripheral(struct i2c_peripheral *i2c_dev) ...@@ -230,15 +199,6 @@ static int chromeos_laptop_add_peripheral(struct i2c_peripheral *i2c_dev)
return 0; return 0;
} }
static int __init chromeos_laptop_dmi_matched(const struct dmi_system_id *id)
{
cros_laptop = (void *)id->driver_data;
pr_debug("DMI Matched %s\n", id->ident);
/* Indicate to dmi_scan that processing is done. */
return 1;
}
static int chromeos_laptop_probe(struct platform_device *pdev) static int chromeos_laptop_probe(struct platform_device *pdev)
{ {
struct i2c_peripheral *i2c_dev; struct i2c_peripheral *i2c_dev;
...@@ -499,10 +459,6 @@ static struct chromeos_laptop cr48 = { ...@@ -499,10 +459,6 @@ static struct chromeos_laptop cr48 = {
}, },
}; };
#define _CBDD(board_) \
.callback = chromeos_laptop_dmi_matched, \
.driver_data = (void *)&board_
static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
{ {
.ident = "Samsung Series 5 550", .ident = "Samsung Series 5 550",
...@@ -510,14 +466,14 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { ...@@ -510,14 +466,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",
...@@ -525,7 +481,7 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { ...@@ -525,7 +481,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",
...@@ -533,7 +489,7 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { ...@@ -533,7 +489,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",
...@@ -541,7 +497,7 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { ...@@ -541,7 +497,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",
...@@ -549,42 +505,42 @@ static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { ...@@ -549,42 +505,42 @@ 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,
}, },
{ } { }
}; };
...@@ -599,15 +555,67 @@ static struct platform_driver cros_platform_driver = { ...@@ -599,15 +555,67 @@ static struct platform_driver cros_platform_driver = {
.probe = chromeos_laptop_probe, .probe = chromeos_laptop_probe,
}; };
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 struct chromeos_laptop * __init
chromeos_laptop_prepare(const struct dmi_system_id *id)
{
struct i2c_peripheral *i2c_dev;
int irq;
int i;
cros_laptop = (void *)id->driver_data;
for (i = 0; i < MAX_I2C_PERIPHERALS; i++) {
i2c_dev = &cros_laptop->i2c_peripherals[i];
if (!i2c_dev->dmi_name)
continue;
irq = chromeos_laptop_get_irq_from_dmi(i2c_dev->dmi_name);
if (irq < 0)
return ERR_PTR(irq);
}
return cros_laptop;
}
static int __init chromeos_laptop_init(void) static int __init chromeos_laptop_init(void)
{ {
const struct dmi_system_id *dmi_id;
int ret; int ret;
if (!dmi_check_system(chromeos_laptop_dmi_table)) { dmi_id = dmi_first_match(chromeos_laptop_dmi_table);
if (!dmi_id) {
pr_debug("unsupported system\n"); pr_debug("unsupported system\n");
return -ENODEV; return -ENODEV;
} }
pr_debug("DMI Matched %s\n", dmi_id->ident);
cros_laptop = chromeos_laptop_prepare(dmi_id->driver_data);
if (IS_ERR(cros_laptop))
return PTR_ERR(cros_laptop);
ret = platform_driver_register(&cros_platform_driver); ret = platform_driver_register(&cros_platform_driver);
if (ret) if (ret)
return ret; return ret;
......
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