platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] platform/x86: add meraki-mx100 platform driver
@ 2021-08-06  0:57 Chris Blake
  2021-08-06  7:52 ` Andy Shevchenko
  2021-08-06 13:51 ` Hans de Goede
  0 siblings, 2 replies; 8+ messages in thread
From: Chris Blake @ 2021-08-06  0:57 UTC (permalink / raw)
  To: platform-driver-x86, linux-gpio, chunkeey, hdegoede; +Cc: Chris Blake

This adds platform support for the Cisco Meraki MX100 (Tinkerbell)
network appliance. This sets up the network LEDs and Reset
button. Note that this patch requires
mfd: lpc_ich: Enable GPIO driver for DH89xxCC which has been accepted
and is currently targeted for 5.15.

Signed-off-by: Chris Blake <chrisrblake93@gmail.com>
Co-developed-by: Christian Lamparter <chunkeey@gmail.com>
---

Changelog:
V2: Move to using gpiod lookup tables, misc cleanups
V1: Initial Patch

 drivers/platform/x86/Kconfig        |  13 ++
 drivers/platform/x86/Makefile       |   3 +
 drivers/platform/x86/meraki-mx100.c | 212 ++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 drivers/platform/x86/meraki-mx100.c

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 7d385c3b2239..8d70176e335f 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -302,6 +302,19 @@ config ASUS_NB_WMI
 	  If you have an ACPI-WMI compatible Asus Notebook, say Y or M
 	  here.
 
+config MERAKI_MX100
+	tristate "Cisco Meraki MX100 Platform Driver"
+	depends on GPIOLIB
+	depends on GPIO_ICH
+	depends on LEDS_CLASS
+	select LEDS_GPIO
+	help
+	  This driver provides support for the front button and LEDs on
+	  the Cisco Meraki MX100 (Tinkerbell) 1U appliance.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called meraki-mx100.
+
 config EEEPC_LAPTOP
 	tristate "Eee PC Hotkey Driver"
 	depends on ACPI
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index 7ee369aab10d..25c5aee1cde7 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -39,6 +39,9 @@ obj-$(CONFIG_ASUS_NB_WMI)	+= asus-nb-wmi.o
 obj-$(CONFIG_EEEPC_LAPTOP)	+= eeepc-laptop.o
 obj-$(CONFIG_EEEPC_WMI)		+= eeepc-wmi.o
 
+# Cisco/Meraki
+obj-$(CONFIG_MERAKI_MX100)	+= meraki-mx100.o
+
 # Dell
 obj-$(CONFIG_X86_PLATFORM_DRIVERS_DELL)		+= dell/
 
diff --git a/drivers/platform/x86/meraki-mx100.c b/drivers/platform/x86/meraki-mx100.c
new file mode 100644
index 000000000000..d64508aeb92c
--- /dev/null
+++ b/drivers/platform/x86/meraki-mx100.c
@@ -0,0 +1,212 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ * Cisco Meraki MX100 (Tinkerbell) board platform driver
+ *
+ * Based off of arch/x86/platform/meraki/tink.c from the
+ * Meraki GPL release meraki-firmware-sources-r23-20150601
+ *
+ * Format inspired by platform/x86/pcengines-apuv2.c
+ *
+ * Copyright (C) 2021 Chris Blake <chrisrblake93@gmail.com>
+ */
+
+#define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
+
+#include <linux/dmi.h>
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/gpio_keys.h>
+#include <linux/gpio/machine.h>
+#include <linux/input.h>
+#include <linux/kernel.h>
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+#define TINK_GPIO_DRIVER_NAME "gpio_ich"
+
+/* LEDs */
+static const struct gpio_led tink_leds[] = {
+	{
+		.name = "mx100:green:internet",
+		.default_trigger = "default-on",
+	},
+	{
+		.name = "mx100:green:lan2",
+	},
+	{
+		.name = "mx100:green:lan3",
+	},
+	{
+		.name = "mx100:green:lan4",
+	},
+	{
+		.name = "mx100:green:lan5",
+	},
+	{
+		.name = "mx100:green:lan6",
+	},
+	{
+		.name = "mx100:green:lan7",
+	},
+	{
+		.name = "mx100:green:lan8",
+	},
+	{
+		.name = "mx100:green:lan9",
+	},
+	{
+		.name = "mx100:green:lan10",
+	},
+	{
+		.name = "mx100:green:lan11",
+	},
+};
+
+static const struct gpio_led_platform_data tink_leds_pdata = {
+	.num_leds	= ARRAY_SIZE(tink_leds),
+	.leds		= tink_leds,
+};
+
+static struct gpiod_lookup_table tink_leds_table = {
+	.dev_id = "leds-gpio",
+	.table = {
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 11,
+				NULL, 0, GPIO_ACTIVE_LOW),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 18,
+				NULL, 1, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 20,
+				NULL, 2, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 22,
+				NULL, 3, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 23,
+				NULL, 4, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 32,
+				NULL, 5, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 34,
+				NULL, 6, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 35,
+				NULL, 7, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 36,
+				NULL, 8, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 37,
+				NULL, 9, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 48,
+				NULL, 10, GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 16,
+				NULL, 11, GPIO_ACTIVE_LOW),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 7,
+				NULL, 12, GPIO_ACTIVE_LOW),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 21,
+				NULL, 13, GPIO_ACTIVE_LOW),
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 19,
+				NULL, 14, GPIO_ACTIVE_LOW),
+	}
+};
+
+/* Reset Button */
+static struct gpio_keys_button tink_buttons[] = {
+	{
+		.desc			= "Reset",
+		.type			= EV_KEY,
+		.code			= KEY_RESTART,
+		.active_low             = 1,
+		.debounce_interval      = 100,
+	},
+};
+
+static const struct gpio_keys_platform_data tink_buttons_pdata = {
+	.buttons	= tink_buttons,
+	.nbuttons	= ARRAY_SIZE(tink_buttons),
+	.poll_interval  = 20,
+	.rep		= 0,
+	.name		= "mx100-keys",
+};
+
+static struct gpiod_lookup_table tink_keys_table = {
+	.dev_id = "gpio-keys-polled",
+	.table = {
+		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 60,
+				NULL, 0, GPIO_ACTIVE_LOW),
+	}
+};
+
+/* Board setup */
+
+static const struct dmi_system_id tink_systems[] __initconst = {
+	{
+		.matches = {
+			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Cisco"),
+			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MX100-HW"),
+		},
+	},
+	{} /* Terminating entry */
+};
+
+static struct platform_device *tink_leds_pdev;
+static struct platform_device *tink_keys_pdev;
+
+static struct platform_device * __init tink_create_dev(
+	const char *name,
+	const void *pdata,
+	size_t sz)
+{
+	struct platform_device *pdev;
+
+	pdev = platform_device_register_data(NULL,
+		name,
+		PLATFORM_DEVID_NONE,
+		pdata,
+		sz);
+
+	if (IS_ERR(pdev))
+		pr_err("failed registering %s: %ld\n", name, PTR_ERR(pdev));
+
+	return pdev;
+}
+
+static int __init tink_board_init(void)
+{
+	if (!dmi_first_match(tink_systems))
+                return -ENODEV;
+
+	/* We need to make sure that GPIO60 isn't set to native mode as is default since it's our 
+	 * Reset Button. To do this, write to GPIO_USE_SEL2 to have GPIO60 set to GPIO mode.
+	 * This is documented on page 1609 of the PCH datasheet, order number 327879-005US
+	 */
+	outl(inl(0x530) | BIT(28), 0x530);
+
+	gpiod_add_lookup_table(&tink_leds_table);
+	gpiod_add_lookup_table(&tink_keys_table);
+
+	tink_leds_pdev = tink_create_dev(
+		"leds-gpio",
+		&tink_leds_pdata,
+		sizeof(tink_leds_pdata));
+
+	tink_keys_pdev = tink_create_dev(
+		"gpio-keys-polled",
+		&tink_buttons_pdata,
+		sizeof(tink_buttons_pdata));
+
+	return 0;
+}
+
+static void __exit tink_board_exit(void)
+{
+	platform_device_unregister(tink_keys_pdev);
+	platform_device_unregister(tink_leds_pdev);
+	gpiod_remove_lookup_table(&tink_keys_table);
+	gpiod_remove_lookup_table(&tink_leds_table);
+}
+
+module_init(tink_board_init);
+module_exit(tink_board_exit);
+
+MODULE_AUTHOR("Chris Blake <chrisrblake93@gmail.com>");
+MODULE_DESCRIPTION("Cisco Meraki MX100 Platform Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:meraki-mx100");
+MODULE_DEVICE_TABLE(dmi, tink_systems);
+MODULE_SOFTDEP("pre: platform:" TINK_GPIO_DRIVER_NAME);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] platform/x86: add meraki-mx100 platform driver
  2021-08-06  0:57 [PATCH v2] platform/x86: add meraki-mx100 platform driver Chris Blake
@ 2021-08-06  7:52 ` Andy Shevchenko
  2021-08-06 13:55   ` Hans de Goede
  2021-08-06 13:51 ` Hans de Goede
  1 sibling, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2021-08-06  7:52 UTC (permalink / raw)
  To: Chris Blake
  Cc: Platform Driver, open list:GPIO SUBSYSTEM, Christian Lamparter,
	Hans de Goede

On Fri, Aug 6, 2021 at 5:47 AM Chris Blake <chrisrblake93@gmail.com> wrote:
>
> This adds platform support for the Cisco Meraki MX100 (Tinkerbell)
> network appliance. This sets up the network LEDs and Reset
> button. Note that this patch requires

> mfd: lpc_ich: Enable GPIO driver for DH89xxCC

Use standard format for the commits, and you may find its SHA in the
repository of respective maintainer I suppose.

> which has been accepted
> and is currently targeted for 5.15.
>
> Signed-off-by: Chris Blake <chrisrblake93@gmail.com>

> Co-developed-by: Christian Lamparter <chunkeey@gmail.com>

Missed SoB of co-developer.

...

> +#include <linux/gpio.h>

This is wrong. Mustn't be included in the new code.

> +#include <linux/gpio_keys.h>

> +#include <linux/gpio/machine.h>

Does this provide a GPIO controller driver? I don't think so.

> +#include <linux/input.h>
> +#include <linux/kernel.h>
> +#include <linux/leds.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>

...

> +static struct platform_device * __init tink_create_dev(
> +       const char *name,
> +       const void *pdata,
> +       size_t sz)

Use less LOCs for this...

...

> +       pdev = platform_device_register_data(NULL,
> +               name,
> +               PLATFORM_DEVID_NONE,
> +               pdata,
> +               sz);

...and for this (put name and sz to the respective previous lines).

> +

Unneeded blank line.

> +       if (IS_ERR(pdev))
> +               pr_err("failed registering %s: %ld\n", name, PTR_ERR(pdev));
> +

...

> +       /* We need to make sure that GPIO60 isn't set to native mode as is default since it's our
> +        * Reset Button. To do this, write to GPIO_USE_SEL2 to have GPIO60 set to GPIO mode.
> +        * This is documented on page 1609 of the PCH datasheet, order number 327879-005US
> +        */

/*
 * Multi-line comment style is not
 * for this subsystem.
 */

...

> +       tink_leds_pdev = tink_create_dev(
> +               "leds-gpio",
> +               &tink_leds_pdata,
> +               sizeof(tink_leds_pdata));
> +
> +       tink_keys_pdev = tink_create_dev(
> +               "gpio-keys-polled",
> +               &tink_buttons_pdata,
> +               sizeof(tink_buttons_pdata));

Again, use less LOCs.

...

> +

Unneeded blank line, attach the below to the respective functions

> +module_init(tink_board_init);
> +module_exit(tink_board_exit);

...

> +MODULE_DEVICE_TABLE(dmi, tink_systems);
Put this closer to the structure.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] platform/x86: add meraki-mx100 platform driver
  2021-08-06  0:57 [PATCH v2] platform/x86: add meraki-mx100 platform driver Chris Blake
  2021-08-06  7:52 ` Andy Shevchenko
@ 2021-08-06 13:51 ` Hans de Goede
  1 sibling, 0 replies; 8+ messages in thread
From: Hans de Goede @ 2021-08-06 13:51 UTC (permalink / raw)
  To: Chris Blake, platform-driver-x86, linux-gpio, chunkeey

Hi Chris,

On 8/6/21 2:57 AM, Chris Blake wrote:
> This adds platform support for the Cisco Meraki MX100 (Tinkerbell)
> network appliance. This sets up the network LEDs and Reset
> button. Note that this patch requires
> mfd: lpc_ich: Enable GPIO driver for DH89xxCC which has been accepted
> and is currently targeted for 5.15.
> 
> Signed-off-by: Chris Blake <chrisrblake93@gmail.com>
> Co-developed-by: Christian Lamparter <chunkeey@gmail.com>
> ---
> 
> Changelog:
> V2: Move to using gpiod lookup tables, misc cleanups

Thank you, I've 2 small remarks and Andy has a couple of remarks
as well. If you can do a v3 with our remarks addressed then I believe
that that v3 will be ready for merging.

> V1: Initial Patch
> 
>  drivers/platform/x86/Kconfig        |  13 ++
>  drivers/platform/x86/Makefile       |   3 +
>  drivers/platform/x86/meraki-mx100.c | 212 ++++++++++++++++++++++++++++
>  3 files changed, 228 insertions(+)
>  create mode 100644 drivers/platform/x86/meraki-mx100.c
> 
> diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
> index 7d385c3b2239..8d70176e335f 100644
> --- a/drivers/platform/x86/Kconfig
> +++ b/drivers/platform/x86/Kconfig
> @@ -302,6 +302,19 @@ config ASUS_NB_WMI
>  	  If you have an ACPI-WMI compatible Asus Notebook, say Y or M
>  	  here.
>  
> +config MERAKI_MX100
> +	tristate "Cisco Meraki MX100 Platform Driver"
> +	depends on GPIOLIB
> +	depends on GPIO_ICH
> +	depends on LEDS_CLASS
> +	select LEDS_GPIO
> +	help
> +	  This driver provides support for the front button and LEDs on
> +	  the Cisco Meraki MX100 (Tinkerbell) 1U appliance.
> +
> +	  To compile this driver as a module, choose M here: the module
> +	  will be called meraki-mx100.
> +
>  config EEEPC_LAPTOP
>  	tristate "Eee PC Hotkey Driver"
>  	depends on ACPI
> diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
> index 7ee369aab10d..25c5aee1cde7 100644
> --- a/drivers/platform/x86/Makefile
> +++ b/drivers/platform/x86/Makefile
> @@ -39,6 +39,9 @@ obj-$(CONFIG_ASUS_NB_WMI)	+= asus-nb-wmi.o
>  obj-$(CONFIG_EEEPC_LAPTOP)	+= eeepc-laptop.o
>  obj-$(CONFIG_EEEPC_WMI)		+= eeepc-wmi.o
>  
> +# Cisco/Meraki
> +obj-$(CONFIG_MERAKI_MX100)	+= meraki-mx100.o
> +
>  # Dell
>  obj-$(CONFIG_X86_PLATFORM_DRIVERS_DELL)		+= dell/
>  
> diff --git a/drivers/platform/x86/meraki-mx100.c b/drivers/platform/x86/meraki-mx100.c
> new file mode 100644
> index 000000000000..d64508aeb92c
> --- /dev/null
> +++ b/drivers/platform/x86/meraki-mx100.c
> @@ -0,0 +1,212 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +
> +/*
> + * Cisco Meraki MX100 (Tinkerbell) board platform driver
> + *
> + * Based off of arch/x86/platform/meraki/tink.c from the
> + * Meraki GPL release meraki-firmware-sources-r23-20150601
> + *
> + * Format inspired by platform/x86/pcengines-apuv2.c
> + *
> + * Copyright (C) 2021 Chris Blake <chrisrblake93@gmail.com>
> + */
> +
> +#define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
> +
> +#include <linux/dmi.h>
> +#include <linux/err.h>
> +#include <linux/gpio.h>
> +#include <linux/gpio_keys.h>
> +#include <linux/gpio/machine.h>
> +#include <linux/input.h>
> +#include <linux/kernel.h>
> +#include <linux/leds.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +
> +#define TINK_GPIO_DRIVER_NAME "gpio_ich"
> +
> +/* LEDs */
> +static const struct gpio_led tink_leds[] = {
> +	{
> +		.name = "mx100:green:internet",
> +		.default_trigger = "default-on",
> +	},
> +	{
> +		.name = "mx100:green:lan2",
> +	},
> +	{
> +		.name = "mx100:green:lan3",
> +	},
> +	{
> +		.name = "mx100:green:lan4",
> +	},
> +	{
> +		.name = "mx100:green:lan5",
> +	},
> +	{
> +		.name = "mx100:green:lan6",
> +	},
> +	{
> +		.name = "mx100:green:lan7",
> +	},
> +	{
> +		.name = "mx100:green:lan8",
> +	},
> +	{
> +		.name = "mx100:green:lan9",
> +	},
> +	{
> +		.name = "mx100:green:lan10",
> +	},
> +	{
> +		.name = "mx100:green:lan11",
> +	},
> +};
> +
> +static const struct gpio_led_platform_data tink_leds_pdata = {
> +	.num_leds	= ARRAY_SIZE(tink_leds),
> +	.leds		= tink_leds,
> +};
> +
> +static struct gpiod_lookup_table tink_leds_table = {
> +	.dev_id = "leds-gpio",
> +	.table = {
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 11,
> +				NULL, 0, GPIO_ACTIVE_LOW),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 18,
> +				NULL, 1, GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 20,
> +				NULL, 2, GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 22,
> +				NULL, 3, GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 23,
> +				NULL, 4, GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 32,
> +				NULL, 5, GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 34,
> +				NULL, 6, GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 35,
> +				NULL, 7, GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 36,
> +				NULL, 8, GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 37,
> +				NULL, 9, GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 48,
> +				NULL, 10, GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 16,
> +				NULL, 11, GPIO_ACTIVE_LOW),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 7,
> +				NULL, 12, GPIO_ACTIVE_LOW),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 21,
> +				NULL, 13, GPIO_ACTIVE_LOW),
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 19,
> +				NULL, 14, GPIO_ACTIVE_LOW),

gpiod_lookup_table.table-s needed to be terminated with an
empty entry, add a line like this, like how it is done for
the dmi_system_id table:

		{} /* Terminating entry */


> +	}
> +};
> +
> +/* Reset Button */
> +static struct gpio_keys_button tink_buttons[] = {
> +	{
> +		.desc			= "Reset",
> +		.type			= EV_KEY,
> +		.code			= KEY_RESTART,
> +		.active_low             = 1,
> +		.debounce_interval      = 100,
> +	},
> +};
> +
> +static const struct gpio_keys_platform_data tink_buttons_pdata = {
> +	.buttons	= tink_buttons,
> +	.nbuttons	= ARRAY_SIZE(tink_buttons),
> +	.poll_interval  = 20,
> +	.rep		= 0,
> +	.name		= "mx100-keys",
> +};
> +
> +static struct gpiod_lookup_table tink_keys_table = {
> +	.dev_id = "gpio-keys-polled",
> +	.table = {
> +		GPIO_LOOKUP_IDX(TINK_GPIO_DRIVER_NAME, 60,
> +				NULL, 0, GPIO_ACTIVE_LOW),

Idem.

> +	}
> +};
> +
> +/* Board setup */
> +
> +static const struct dmi_system_id tink_systems[] __initconst = {
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Cisco"),
> +			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MX100-HW"),
> +		},
> +	},
> +	{} /* Terminating entry */
> +};
> +
> +static struct platform_device *tink_leds_pdev;
> +static struct platform_device *tink_keys_pdev;
> +
> +static struct platform_device * __init tink_create_dev(
> +	const char *name,
> +	const void *pdata,
> +	size_t sz)
> +{
> +	struct platform_device *pdev;
> +
> +	pdev = platform_device_register_data(NULL,
> +		name,
> +		PLATFORM_DEVID_NONE,
> +		pdata,
> +		sz);
> +
> +	if (IS_ERR(pdev))
> +		pr_err("failed registering %s: %ld\n", name, PTR_ERR(pdev));
> +
> +	return pdev;
> +}
> +
> +static int __init tink_board_init(void)
> +{
> +	if (!dmi_first_match(tink_systems))
> +                return -ENODEV;
> +
> +	/* We need to make sure that GPIO60 isn't set to native mode as is default since it's our 
> +	 * Reset Button. To do this, write to GPIO_USE_SEL2 to have GPIO60 set to GPIO mode.
> +	 * This is documented on page 1609 of the PCH datasheet, order number 327879-005US
> +	 */
> +	outl(inl(0x530) | BIT(28), 0x530);
> +
> +	gpiod_add_lookup_table(&tink_leds_table);
> +	gpiod_add_lookup_table(&tink_keys_table);
> +
> +	tink_leds_pdev = tink_create_dev(
> +		"leds-gpio",
> +		&tink_leds_pdata,
> +		sizeof(tink_leds_pdata));
> +
> +	tink_keys_pdev = tink_create_dev(
> +		"gpio-keys-polled",
> +		&tink_buttons_pdata,
> +		sizeof(tink_buttons_pdata));
> +
> +	return 0;
> +}
> +
> +static void __exit tink_board_exit(void)
> +{
> +	platform_device_unregister(tink_keys_pdev);
> +	platform_device_unregister(tink_leds_pdev);
> +	gpiod_remove_lookup_table(&tink_keys_table);
> +	gpiod_remove_lookup_table(&tink_leds_table);
> +}
> +
> +module_init(tink_board_init);
> +module_exit(tink_board_exit);
> +
> +MODULE_AUTHOR("Chris Blake <chrisrblake93@gmail.com>");
> +MODULE_DESCRIPTION("Cisco Meraki MX100 Platform Driver");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:meraki-mx100");
> +MODULE_DEVICE_TABLE(dmi, tink_systems);
> +MODULE_SOFTDEP("pre: platform:" TINK_GPIO_DRIVER_NAME);

This SOFTDEP should not be necessary, the platform devices
will be created regardless of the GPIO driver already having
loaded and if the request_gpio in the gpio_keys/_leds fails,
then it should fail with -EPROBE_DEFER and then the kernel
will retry to bind those drivers to the created platform-
devices later (until it succeeds).

So please give things a try without this line.

Regards,

Hans


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] platform/x86: add meraki-mx100 platform driver
  2021-08-06  7:52 ` Andy Shevchenko
@ 2021-08-06 13:55   ` Hans de Goede
  2021-08-06 13:58     ` Andy Shevchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Hans de Goede @ 2021-08-06 13:55 UTC (permalink / raw)
  To: Andy Shevchenko, Chris Blake
  Cc: Platform Driver, open list:GPIO SUBSYSTEM, Christian Lamparter

Hi,

On 8/6/21 9:52 AM, Andy Shevchenko wrote:
> On Fri, Aug 6, 2021 at 5:47 AM Chris Blake <chrisrblake93@gmail.com> wrote:
>>
>> This adds platform support for the Cisco Meraki MX100 (Tinkerbell)
>> network appliance. This sets up the network LEDs and Reset
>> button. Note that this patch requires
> 
>> mfd: lpc_ich: Enable GPIO driver for DH89xxCC
> 
> Use standard format for the commits, and you may find its SHA in the
> repository of respective maintainer I suppose.
> 
>> which has been accepted
>> and is currently targeted for 5.15.
>>
>> Signed-off-by: Chris Blake <chrisrblake93@gmail.com>
> 
>> Co-developed-by: Christian Lamparter <chunkeey@gmail.com>
> 
> Missed SoB of co-developer.
> 
> ...
> 
>> +#include <linux/gpio.h>
> 
> This is wrong. Mustn't be included in the new code.

Right I don't think you need this at all since I don't
think the code directly uses the GPIOs, but if
removing it gives issues then you will want to use:

#include <linux/gpio/consumer.h>


>> +#include <linux/gpio_keys.h>
> 
>> +#include <linux/gpio/machine.h>
> 
> Does this provide a GPIO controller driver? I don't think so.

Actually GPIO controller drivers use <linux/gpio/driver.h>
<linux/gpio/machine.h> for board files / glue code which
e.g. needs to add lookup-tables, which this code does,
so including this header is correct.

>> +#include <linux/input.h>
>> +#include <linux/kernel.h>
>> +#include <linux/leds.h>
>> +#include <linux/module.h>
>> +#include <linux/platform_device.h>
> 
> ...
> 
>> +static struct platform_device * __init tink_create_dev(
>> +       const char *name,
>> +       const void *pdata,
>> +       size_t sz)
> 
> Use less LOCs for this...
> 
> ...
> 
>> +       pdev = platform_device_register_data(NULL,
>> +               name,
>> +               PLATFORM_DEVID_NONE,
>> +               pdata,
>> +               sz);
> 
> ...and for this (put name and sz to the respective previous lines).
> 
>> +
> 
> Unneeded blank line.
> 
>> +       if (IS_ERR(pdev))
>> +               pr_err("failed registering %s: %ld\n", name, PTR_ERR(pdev));
>> +
> 
> ...
> 
>> +       /* We need to make sure that GPIO60 isn't set to native mode as is default since it's our
>> +        * Reset Button. To do this, write to GPIO_USE_SEL2 to have GPIO60 set to GPIO mode.
>> +        * This is documented on page 1609 of the PCH datasheet, order number 327879-005US
>> +        */
> 
> /*
>  * Multi-line comment style is not
>  * for this subsystem.
>  */
> 
> ...
> 
>> +       tink_leds_pdev = tink_create_dev(
>> +               "leds-gpio",
>> +               &tink_leds_pdata,
>> +               sizeof(tink_leds_pdata));
>> +
>> +       tink_keys_pdev = tink_create_dev(
>> +               "gpio-keys-polled",
>> +               &tink_buttons_pdata,
>> +               sizeof(tink_buttons_pdata));
> 
> Again, use less LOCs.
> 
> ...
> 
>> +
> 
> Unneeded blank line, attach the below to the respective functions
> 
>> +module_init(tink_board_init);
>> +module_exit(tink_board_exit);
> 
> ...
> 
>> +MODULE_DEVICE_TABLE(dmi, tink_systems);
> Put this closer to the structure.

To clarify please put this immediately after the "};" line
terminating the id array declaration, like this:

static const struct dmi_system_id tink_systems[] __initconst = {
	{
		.matches = {
			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Cisco"),
			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MX100-HW"),
		},
	},
	{} /* Terminating entry */
};
MODULE_DEVICE_TABLE(dmi, tink_systems);

Regards,

Hans


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] platform/x86: add meraki-mx100 platform driver
  2021-08-06 13:55   ` Hans de Goede
@ 2021-08-06 13:58     ` Andy Shevchenko
  2021-08-06 15:37       ` Chris
  0 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2021-08-06 13:58 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Chris Blake, Platform Driver, open list:GPIO SUBSYSTEM,
	Christian Lamparter

On Fri, Aug 6, 2021 at 4:55 PM Hans de Goede <hdegoede@redhat.com> wrote:
> On 8/6/21 9:52 AM, Andy Shevchenko wrote:
> > On Fri, Aug 6, 2021 at 5:47 AM Chris Blake <chrisrblake93@gmail.com> wrote:

...

> >> +#include <linux/gpio/machine.h>
> >
> > Does this provide a GPIO controller driver? I don't think so.
>
> Actually GPIO controller drivers use <linux/gpio/driver.h>
> <linux/gpio/machine.h> for board files / glue code which
> e.g. needs to add lookup-tables, which this code does,
> so including this header is correct.

Ah, indeed. I stand corrected.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] platform/x86: add meraki-mx100 platform driver
  2021-08-06 13:58     ` Andy Shevchenko
@ 2021-08-06 15:37       ` Chris
  2021-08-06 15:44         ` Andy Shevchenko
  2021-08-09  9:05         ` Lee Jones
  0 siblings, 2 replies; 8+ messages in thread
From: Chris @ 2021-08-06 15:37 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Hans de Goede, Platform Driver, open list:GPIO SUBSYSTEM,
	Christian Lamparter, Lee Jones

On Fri, Aug 6, 2021 at 8:59 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Fri, Aug 6, 2021 at 4:55 PM Hans de Goede <hdegoede@redhat.com> wrote:
> > On 8/6/21 9:52 AM, Andy Shevchenko wrote:
> > > On Fri, Aug 6, 2021 at 5:47 AM Chris Blake <chrisrblake93@gmail.com> wrote:
>
> ...
>
> > >> +#include <linux/gpio/machine.h>
> > >
> > > Does this provide a GPIO controller driver? I don't think so.
> >
> > Actually GPIO controller drivers use <linux/gpio/driver.h>
> > <linux/gpio/machine.h> for board files / glue code which
> > e.g. needs to add lookup-tables, which this code does,
> > so including this header is correct.
>
> Ah, indeed. I stand corrected.
>
> --
> With Best Regards,
> Andy Shevchenko

Hello,

Thank you both for the feedback, i'll work on getting the fixes
implemented. The only one I have issues with is finding the git hash
for the dependency commit in mfd, since I don't see it merged up yet
to the maintainers staging branch at
https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git/.

@Lee, sorry to tag you in but any chance you have the git hash for the
PR I did earlier that you accepted for 5.15? It was named: mfd:
lpc_ich: Enable GPIO driver for DH89xxCC.

Regards,
Chris Blake

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] platform/x86: add meraki-mx100 platform driver
  2021-08-06 15:37       ` Chris
@ 2021-08-06 15:44         ` Andy Shevchenko
  2021-08-09  9:05         ` Lee Jones
  1 sibling, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2021-08-06 15:44 UTC (permalink / raw)
  To: Chris
  Cc: Hans de Goede, Platform Driver, open list:GPIO SUBSYSTEM,
	Christian Lamparter, Lee Jones

On Fri, Aug 6, 2021 at 6:37 PM Chris <chrisrblake93@gmail.com> wrote:
> On Fri, Aug 6, 2021 at 8:59 AM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:

...

> The only one I have issues with is finding the git hash
> for the dependency commit in mfd, since I don't see it merged up yet
> to the maintainers staging branch at
> https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git/.

You are right to ask the respective maintainer :-)

Just realize that we have more or less established form of dependencies as
Depends-on:

$ git log --oneline --grep Depends-on | wc -l
71

> @Lee, sorry to tag you in but any chance you have the git hash for the
> PR I did earlier that you accepted for 5.15? It was named: mfd:
> lpc_ich: Enable GPIO driver for DH89xxCC.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] platform/x86: add meraki-mx100 platform driver
  2021-08-06 15:37       ` Chris
  2021-08-06 15:44         ` Andy Shevchenko
@ 2021-08-09  9:05         ` Lee Jones
  1 sibling, 0 replies; 8+ messages in thread
From: Lee Jones @ 2021-08-09  9:05 UTC (permalink / raw)
  To: Chris
  Cc: Andy Shevchenko, Hans de Goede, Platform Driver,
	open list:GPIO SUBSYSTEM, Christian Lamparter

On Fri, 06 Aug 2021, Chris wrote:

> On Fri, Aug 6, 2021 at 8:59 AM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> >
> > On Fri, Aug 6, 2021 at 4:55 PM Hans de Goede <hdegoede@redhat.com> wrote:
> > > On 8/6/21 9:52 AM, Andy Shevchenko wrote:
> > > > On Fri, Aug 6, 2021 at 5:47 AM Chris Blake <chrisrblake93@gmail.com> wrote:
> >
> > ...
> >
> > > >> +#include <linux/gpio/machine.h>
> > > >
> > > > Does this provide a GPIO controller driver? I don't think so.
> > >
> > > Actually GPIO controller drivers use <linux/gpio/driver.h>
> > > <linux/gpio/machine.h> for board files / glue code which
> > > e.g. needs to add lookup-tables, which this code does,
> > > so including this header is correct.
> >
> > Ah, indeed. I stand corrected.
> >
> 
> Hello,
> 
> Thank you both for the feedback, i'll work on getting the fixes
> implemented. The only one I have issues with is finding the git hash
> for the dependency commit in mfd, since I don't see it merged up yet
> to the maintainers staging branch at
> https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git/.

Check again. :)

> @Lee, sorry to tag you in but any chance you have the git hash for the
> PR I did earlier that you accepted for 5.15? It was named: mfd:
> lpc_ich: Enable GPIO driver for DH89xxCC.

ef0eea5b151ae ("mfd: lpc_ich: Enable GPIO driver for DH89xxCC")

-- 
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-08-09  9:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06  0:57 [PATCH v2] platform/x86: add meraki-mx100 platform driver Chris Blake
2021-08-06  7:52 ` Andy Shevchenko
2021-08-06 13:55   ` Hans de Goede
2021-08-06 13:58     ` Andy Shevchenko
2021-08-06 15:37       ` Chris
2021-08-06 15:44         ` Andy Shevchenko
2021-08-09  9:05         ` Lee Jones
2021-08-06 13:51 ` Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).