linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: add SGI IP30 led support
@ 2020-01-15 13:05 Thomas Bogendoerfer
  2020-01-15 13:46 ` Dan Murphy
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Bogendoerfer @ 2020-01-15 13:05 UTC (permalink / raw)
  To: Jacek Anaszewski, Pavel Machek, Dan Murphy, linux-kernel, linux-leds

This patch implemenets a driver to support the front panel LEDs of
SGI Octane (IP30) workstations.

Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 drivers/leds/Kconfig     | 11 ++++++
 drivers/leds/Makefile    |  1 +
 drivers/leds/leds-ip30.c | 82 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+)
 create mode 100644 drivers/leds/leds-ip30.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 4b68520ac251..8ef0fe900928 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -836,6 +836,17 @@ config LEDS_LM36274
 	  Say Y to enable the LM36274 LED driver for TI LMU devices.
 	  This supports the LED device LM36274.
 
+config LEDS_IP30
+	tristate "LED support for SGI Octane machines"
+	depends on LEDS_CLASS
+	depends on SGI_MFD_IOC3
+	help
+	  This option enables support for the Red and White LEDs of
+	  SGI Octane machines.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called leds-ip30.
+
 comment "LED Triggers"
 source "drivers/leds/trigger/Kconfig"
 
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 2da39e896ce8..89a527ac8ab6 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -85,6 +85,7 @@ obj-$(CONFIG_LEDS_LM3601X)		+= leds-lm3601x.o
 obj-$(CONFIG_LEDS_TI_LMU_COMMON)	+= leds-ti-lmu-common.o
 obj-$(CONFIG_LEDS_LM3697)		+= leds-lm3697.o
 obj-$(CONFIG_LEDS_LM36274)		+= leds-lm36274.o
+obj-$(CONFIG_LEDS_IP30)			+= leds-ip30.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_CR0014114)		+= leds-cr0014114.o
diff --git a/drivers/leds/leds-ip30.c b/drivers/leds/leds-ip30.c
new file mode 100644
index 000000000000..b0a83f78c439
--- /dev/null
+++ b/drivers/leds/leds-ip30.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * LED Driver for SGI Octane machines
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/leds.h>
+
+struct ip30_led {
+	struct led_classdev cdev;
+	u32 __iomem *reg;
+};
+
+static void ip30led_set(struct led_classdev *led_cdev,
+			enum led_brightness value)
+{
+	struct ip30_led *led = container_of(led_cdev, struct ip30_led, cdev);
+
+	if (value)
+		writel(1, led->reg);
+	else
+		writel(0, led->reg);
+}
+
+static int ip30led_create(struct platform_device *pdev, int num)
+{
+	struct resource *res;
+	struct ip30_led *data;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, num);
+	if (!res)
+		return -EBUSY;
+
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->reg = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(data->reg))
+		return PTR_ERR(data->reg);
+
+
+	if (num == 0) {
+		data->cdev.name = "ip30:white";
+		data->cdev.default_trigger = "default-on";
+	} else {
+		data->cdev.name = "ip30:red";
+		data->cdev.default_trigger = "panic";
+		writel(0, data->reg);
+	}
+	data->cdev.max_brightness = 1;
+	data->cdev.brightness_set = ip30led_set;
+
+	return devm_led_classdev_register(&pdev->dev, &data->cdev);
+}
+
+static int ip30led_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	ret = ip30led_create(pdev, 0);
+	if (ret < 0)
+		return ret;
+
+	return ip30led_create(pdev, 1);
+}
+
+static struct platform_driver ip30led_driver = {
+	.probe		= ip30led_probe,
+	.driver		= {
+		.name		= "ip30-leds",
+	},
+};
+
+module_platform_driver(ip30led_driver);
+
+MODULE_AUTHOR("Thomas Bogendoerfer <tbogendoerfer@suse.de>");
+MODULE_DESCRIPTION("SGI Octane LED driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:ip30-leds");
-- 
2.24.1


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

* Re: [PATCH] leds: add SGI IP30 led support
  2020-01-15 13:05 [PATCH] leds: add SGI IP30 led support Thomas Bogendoerfer
@ 2020-01-15 13:46 ` Dan Murphy
  2020-01-16 11:05   ` Thomas Bogendoerfer
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Murphy @ 2020-01-15 13:46 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Jacek Anaszewski, Pavel Machek,
	linux-kernel, linux-leds

Thomas

On 1/15/20 7:05 AM, Thomas Bogendoerfer wrote:
> This patch implemenets a driver to support the front panel LEDs of
> SGI Octane (IP30) workstations.

Thanks for the patch

Some nitpicks below


> Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
> ---
>   drivers/leds/Kconfig     | 11 ++++++
>   drivers/leds/Makefile    |  1 +
>   drivers/leds/leds-ip30.c | 82 ++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 94 insertions(+)
>   create mode 100644 drivers/leds/leds-ip30.c
>
> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index 4b68520ac251..8ef0fe900928 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -836,6 +836,17 @@ config LEDS_LM36274
>   	  Say Y to enable the LM36274 LED driver for TI LMU devices.
>   	  This supports the LED device LM36274.
>   
> +config LEDS_IP30
> +	tristate "LED support for SGI Octane machines"
> +	depends on LEDS_CLASS
> +	depends on SGI_MFD_IOC3
What is the dependency on the MFD?
> +	help
> +	  This option enables support for the Red and White LEDs of
> +	  SGI Octane machines.
> +
> +	  To compile this driver as a module, choose M here: the module
> +	  will be called leds-ip30.
> +
>   comment "LED Triggers"
>   source "drivers/leds/trigger/Kconfig"
>   
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index 2da39e896ce8..89a527ac8ab6 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -85,6 +85,7 @@ obj-$(CONFIG_LEDS_LM3601X)		+= leds-lm3601x.o
>   obj-$(CONFIG_LEDS_TI_LMU_COMMON)	+= leds-ti-lmu-common.o
>   obj-$(CONFIG_LEDS_LM3697)		+= leds-lm3697.o
>   obj-$(CONFIG_LEDS_LM36274)		+= leds-lm36274.o
> +obj-$(CONFIG_LEDS_IP30)			+= leds-ip30.o
>   

Extra tab


>   # LED SPI Drivers
>   obj-$(CONFIG_LEDS_CR0014114)		+= leds-cr0014114.o
> diff --git a/drivers/leds/leds-ip30.c b/drivers/leds/leds-ip30.c
> new file mode 100644
> index 000000000000..b0a83f78c439
> --- /dev/null
> +++ b/drivers/leds/leds-ip30.c
> @@ -0,0 +1,82 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * LED Driver for SGI Octane machines
> + */
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/platform_device.h>
> +#include <linux/leds.h>
> +
> +struct ip30_led {
> +	struct led_classdev cdev;
> +	u32 __iomem *reg;
> +};
> +
> +static void ip30led_set(struct led_classdev *led_cdev,
> +			enum led_brightness value)
> +{
> +	struct ip30_led *led = container_of(led_cdev, struct ip30_led, cdev);
> +
> +	if (value)
> +		writel(1, led->reg);
> +	else
> +		writel(0, led->reg);
> +}
> +
> +static int ip30led_create(struct platform_device *pdev, int num)
> +{
> +	struct resource *res;
> +	struct ip30_led *data;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, num);
> +	if (!res)
> +		return -EBUSY;
> +
> +	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> +	if (!data)
> +		return -ENOMEM;
> +
> +	data->reg = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(data->reg))
> +		return PTR_ERR(data->reg);
> +
> +
> +	if (num == 0) {
> +		data->cdev.name = "ip30:white";
This also needs a function as defined in dt-bindings/common.h
> +		data->cdev.default_trigger = "default-on";

The name, color, function and trigger can be pulled from the DT or Firmware.

The firmware should contain a node for each LED to be configured.

> +	} else {
> +		data->cdev.name = "ip30:red";
Same as above
> +		data->cdev.default_trigger = "panic";
> +		writel(0, data->reg);

Is the LED on by default?

Dan


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

* Re: [PATCH] leds: add SGI IP30 led support
  2020-01-15 13:46 ` Dan Murphy
@ 2020-01-16 11:05   ` Thomas Bogendoerfer
  2020-01-16 15:21     ` Dan Murphy
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Bogendoerfer @ 2020-01-16 11:05 UTC (permalink / raw)
  To: Dan Murphy; +Cc: Jacek Anaszewski, Pavel Machek, linux-kernel, linux-leds

On Wed, 15 Jan 2020 07:46:13 -0600
Dan Murphy <dmurphy@ti.com> wrote:

> Thomas
> 
> On 1/15/20 7:05 AM, Thomas Bogendoerfer wrote:
> > This patch implemenets a driver to support the front panel LEDs of
> > SGI Octane (IP30) workstations.
> 
> Thanks for the patch
> 
> Some nitpicks below
> 
> 
> > Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
> > ---
> >   drivers/leds/Kconfig     | 11 ++++++
> >   drivers/leds/Makefile    |  1 +
> >   drivers/leds/leds-ip30.c | 82 ++++++++++++++++++++++++++++++++++++++++
> >   3 files changed, 94 insertions(+)
> >   create mode 100644 drivers/leds/leds-ip30.c
> >
> > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> > index 4b68520ac251..8ef0fe900928 100644
> > --- a/drivers/leds/Kconfig
> > +++ b/drivers/leds/Kconfig
> > @@ -836,6 +836,17 @@ config LEDS_LM36274
> >   	  Say Y to enable the LM36274 LED driver for TI LMU devices.
> >   	  This supports the LED device LM36274.
> >   
> > +config LEDS_IP30
> > +	tristate "LED support for SGI Octane machines"
> > +	depends on LEDS_CLASS
> > +	depends on SGI_MFD_IOC3
> What is the dependency on the MFD?

the gpio lines where the leds are connected are managed by the mfd ioc3 driver.
So without that driver this led driver will not be started.

> > +
> > +
> > +	if (num == 0) {
> > +		data->cdev.name = "ip30:white";
> This also needs a function as defined in dt-bindings/common.h
> > +		data->cdev.default_trigger = "default-on";
> 
> The name, color, function and trigger can be pulled from the DT or Firmware.
> 
> The firmware should contain a node for each LED to be configured.

SGI Octanes don't have DT and the firmware just toggles some of the leds,
but doesn't provide informations about it. That's why this is hardcoded
in the driver. The MFD driver detects the ioc3 chip and knows it's a
SGI Octane mainboard and creates the led platform device.

How is the correct way to this without DT ?

> 
> > +	} else {
> > +		data->cdev.name = "ip30:red";
> Same as above
> > +		data->cdev.default_trigger = "panic";
> > +		writel(0, data->reg);
> 
> Is the LED on by default?

Depends on the hardware state. If PROM firmware detects some hardware issues,
it turns on the red LED. Otherwise it's off.

Thomas.

-- 
SUSE Software Solutions Germany GmbH
HRB 36809 (AG Nürnberg)
Geschäftsführer: Felix Imendörffer

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

* Re: [PATCH] leds: add SGI IP30 led support
  2020-01-16 11:05   ` Thomas Bogendoerfer
@ 2020-01-16 15:21     ` Dan Murphy
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Murphy @ 2020-01-16 15:21 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Jacek Anaszewski, Pavel Machek, linux-kernel, linux-leds

Thomas

On 1/16/20 5:05 AM, Thomas Bogendoerfer wrote:
> On Wed, 15 Jan 2020 07:46:13 -0600
> Dan Murphy <dmurphy@ti.com> wrote:
>
>> Thomas
>>
>> On 1/15/20 7:05 AM, Thomas Bogendoerfer wrote:
>>> This patch implemenets a driver to support the front panel LEDs of
>>> SGI Octane (IP30) workstations.
>> Thanks for the patch
>>
>> Some nitpicks below
>>
>>
>>> Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
>>> ---
>>>    drivers/leds/Kconfig     | 11 ++++++
>>>    drivers/leds/Makefile    |  1 +
>>>    drivers/leds/leds-ip30.c | 82 ++++++++++++++++++++++++++++++++++++++++
>>>    3 files changed, 94 insertions(+)
>>>    create mode 100644 drivers/leds/leds-ip30.c
>>>
>>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
>>> index 4b68520ac251..8ef0fe900928 100644
>>> --- a/drivers/leds/Kconfig
>>> +++ b/drivers/leds/Kconfig
>>> @@ -836,6 +836,17 @@ config LEDS_LM36274
>>>    	  Say Y to enable the LM36274 LED driver for TI LMU devices.
>>>    	  This supports the LED device LM36274.
>>>    
>>> +config LEDS_IP30
>>> +	tristate "LED support for SGI Octane machines"
>>> +	depends on LEDS_CLASS
>>> +	depends on SGI_MFD_IOC3
>> What is the dependency on the MFD?
> the gpio lines where the leds are connected are managed by the mfd ioc3 driver.
> So without that driver this led driver will not be started.
Ack
>
>>> +
>>> +
>>> +	if (num == 0) {
>>> +		data->cdev.name = "ip30:white";
>> This also needs a function as defined in dt-bindings/common.h
>>> +		data->cdev.default_trigger = "default-on";
>> The name, color, function and trigger can be pulled from the DT or Firmware.
>>
>> The firmware should contain a node for each LED to be configured.
> SGI Octanes don't have DT and the firmware just toggles some of the leds,
> but doesn't provide informations about it. That's why this is hardcoded
> in the driver. The MFD driver detects the ioc3 chip and knows it's a
> SGI Octane mainboard and creates the led platform device.
>
> How is the correct way to this without DT ?

Please refer to the leds-class document (1) under LED device naming 
convention

If you don't have a DT then set the name accordingly.  The functions are 
defined in the common.h and the colors are exported in the leds-class driver


1 https://www.kernel.org/doc/Documentation/leds/leds-class.rst

>
>>> +	} else {
>>> +		data->cdev.name = "ip30:red";
>> Same as above
>>> +		data->cdev.default_trigger = "panic";
>>> +		writel(0, data->reg);
>> Is the LED on by default?
> Depends on the hardware state. If PROM firmware detects some hardware issues,
> it turns on the red LED. Otherwise it's off.

So why would we turn it off if the PROM FW turned it on?

Dan



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

end of thread, other threads:[~2020-01-16 15:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15 13:05 [PATCH] leds: add SGI IP30 led support Thomas Bogendoerfer
2020-01-15 13:46 ` Dan Murphy
2020-01-16 11:05   ` Thomas Bogendoerfer
2020-01-16 15:21     ` Dan Murphy

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).