Skip to contentSkip to conversation

POST card display support

PATCH In review Jaghathiswari Rankappagounder Natarajan 4 participants 13 messages Oct 13, 2016 – Nov 1, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Platform driver in patch 1/3 periodically updates the most current POST code from either the BMC or host to the POST card display.
The POST card hardware assumed is 74HC164 wired to two 7-segment displays.

(to get POST codes from bmc) On BMC state change, the character driver in patch 2/3 is the interface to which the systemd (in openbmc) will write the POST codes. When a new POST code is written to the character device, the update_postcode function in patch 1/3 is called to update the post code.

(to get POST codes from host) When the host writes to port80, the lpc driver can directly call update_postcode function in patch 1/3 to update the POST code (will be written after lpc driver is finished);

patch 3/3 has devicetree info for controlling the POST card hardware on zaius

#1 lore raw

PATCH 1/3 drivers: misc: Platform driver to update display on the POST card

Platform driver to periodically update the display on the POST card. POST card hardware assumed is 74HC164 wired to two 7-segment displays.

---
 drivers/misc/Kconfig           |   6 ++
 drivers/misc/Makefile          |   1 +
 drivers/misc/update-postcard.c | 219 +++++++++++++++++++++++++++++++++++++++++
 drivers/misc/update-postcard.h |   1 +
 4 files changed, 227 insertions(+)
 create mode 100644 drivers/misc/update-postcard.c
 create mode 100644 drivers/misc/update-postcard.h
drivers/misc/Kconfig +6 -0
index 4617ddc..d65b83f 100644
@@ -804,6 +804,12 @@ config PANEL_BOOT_MESSAGE
 	  An empty message will only clear the display at driver init time. Any other
 	  printf()-formatted message is valid with newline and escape codes.
 
+config ASPEED_UPDATE_POSTCARD
+	tristate "Platform driver to update POST card"
+	help
+	 Support to periodically update display on the POST card. The POST card
+	 hardware assumed is 74HC164 wired to two 7-segment displays.
+
 config ASPEED_BT_IPMI_HOST
 	tristate "BT IPMI host driver"
 	help
drivers/misc/Makefile +1 -0
index 724861b..730c6c2 100644
@@ -57,4 +57,5 @@ obj-$(CONFIG_ECHO)		+= echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)	+= vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)		+= cxl/
 obj-$(CONFIG_PANEL)             += panel.o
+obj-$(CONFIG_ASPEED_UPDATE_POSTCARD)    += update-postcard.o
 obj-$(CONFIG_ASPEED_BT_IPMI_HOST)	+= bt-host.o
drivers/misc/update-postcard.c new file +219 -0

219 lines not on this page · raw message

drivers/misc/update-postcard.h new file +1 -0
new file mode 100644
index 0000000..ef82e9091d
@@ -0,0 +1 @@
+void update_postcode(char *buf);

--
2.8.0.rc3.226.g39d4020

#2 lore raw

Re: [PATCH linux v1 1/3] drivers: misc: Platform driver to update display on the POST card

Quoted 30 lines · Jaghathiswari Rankappagounder Natarajan

Platform driver to periodically update the display on the POST card. POST card hardware assumed is 74HC164 wired to two 7-segment displays.

---
 drivers/misc/Kconfig           |   6 ++
 drivers/misc/Makefile          |   1 +
 drivers/misc/update-postcard.c | 219 ++++++++++++++++++++++++++++++
+++++++++++
 drivers/misc/update-postcard.h |   1 +
 4 files changed, 227 insertions(+)
 create mode 100644 drivers/misc/update-postcard.c
 create mode 100644 drivers/misc/update-postcard.h
drivers/misc/Kconfig +0 -0
index 4617ddc..d65b83f 100644
@@ -804,6 +804,12 @@ config PANEL_BOOT_MESSAGE
          An empty message will only clear the display at driver init

time. Any other
printf()-formatted message is valid with newline and escape
codes.

drivers/misc/Kconfig +4 -0
+config ASPEED_UPDATE_POSTCARD
+       tristate "Platform driver to update POST card"
+       help
+        Support to periodically update display on the POST card. The POST

card

drivers/misc/Kconfig config PANEL_BOOT_MESSAGE · line 812

Quoted 2 lines
drivers/misc/Kconfig +2 -0
+        hardware assumed is 74HC164 wired to two 7-segment displays.
+

Nothing about this driver is associated with Aspeed. UPDATE_POSTCARD reads to me as describing an action, not a device. Maybe SEVEN_SEGMENT_DISPLAY?

Quoted 45 lines

config ASPEED_BT_IPMI_HOST
tristate "BT IPMI host driver"
help

drivers/misc/Makefile +1 -0
index 724861b..730c6c2 100644
@@ -57,4 +57,5 @@ obj-$(CONFIG_ECHO)            += echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)  += vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)         += cxl/
 obj-$(CONFIG_PANEL)             += panel.o
+obj-$(CONFIG_ASPEED_UPDATE_POSTCARD)    += update-postcard.o
 obj-$(CONFIG_ASPEED_BT_IPMI_HOST)      += bt-host.o
drivers/misc/update- renamed from drivers/misc/update-postcard.c +0 -0

postcard.c
new file mode 100644
index 0000000..3516c24

drivers/misc/update-postcard.c new file +24 -0
@@ -0,0 +1,219 @@
+/* Platform driver to periodically update the display on the POST card.
+ * POST card hardware assumed is 74HC164 wired to two 7-segment displays.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/timer.h>
+#include <linux/jiffies.h>
+#include <linux/sizes.h>
+#include <linux/map_to_7segment.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
+#include <linux/mutex.h>
+#include <linux/of_platform.h>
+#include <linux/gpio/consumer.h>
+
+#define POST_CODE_UPDATE_INTVL 1000
+
+#define MAX_PC_SIZE 3
+
+#define LED_DOT 0x01
+
+#define CLOCK_GPIO_NAME "clk"

drivers/misc/update-postcard.c line 34

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+#define DATA_GPIO_NAME "data"
+#define CLEAR_GPIO_NAME "clr"
+
+static struct mutex mutex;
+
+static struct timer_list update_timer;
+
+static char curr_postcode[3];
+static u8 pc_valid;
+

+static struct gpio_desc *clk_gpio;

drivers/misc/update-postcard.c line 37

Quoted 3 lines
drivers/misc/update-postcard.c new file +2 -0
+static struct gpio_desc *data_gpio;
+static struct gpio_desc *clr_gpio;

I realize there should really only ever be one of these in a system but static data members in modules bug me. I'd much rather see all this configuration and these buffers in a struct that is saved with platform_set_drvdata().

Quoted 69 lines
drivers/misc/update-postcard.c new file +68 -0
+
+/*
+ * 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+ *  _       _   _       _   _   _   _   _   _       _       _   _
+ * | |   |  _|  _| |_| |_  |_    | |_| |_| |_| |_  |    _| |_  |_
+ * |_|   | |_   _|   |  _| |_|   | |_|   | | | |_| |_  |_| |_  |
+ *
+ * data[7:1] = led[a:g]
+ * lookup table used for both bytes of lpc post code and lower byte of
+ * bmc post code
+ */
+const u8 seven_seg_bits[] = {
+       0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0,
+       0xFE, 0xF6, 0xEE, 0x3E, 0x9C, 0x7A, 0x9E, 0x8E
+       };
+
+/*
+ * 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+ *      _       _   _                              _            _
+ *     |   |_  |_| |_  _   _   _   _   _   _   _  |_    _|  _| | |
+ *     |_  |_  |   |                               _|  |_| |_| | |
+ *
+ * data[7:1] = led[a:g]
+ * lookup table used for higher byte of bmc post code
+ */
+const u8 special_seven_seg_bits[] = {
+       0x00, 0x9C, 0x1E, 0xCE, 0x8E, 0x02, 0x02, 0x02,
+       0x02, 0x02, 0x02, 0x02, 0xB6, 0x7A, 0x7A, 0xEC
+       };
+
+void update_postcode(char *buf)
+{
+       mutex_lock(&mutex);
+       strncpy(curr_postcode, buf, sizeof(curr_postcode));
+       mutex_unlock(&mutex);
+       pc_valid = 1;
+}
+EXPORT_SYMBOL(update_postcode);
+
+/* convert postcode to led pattern
+ * 7-bits used for each 7-seg display and
+ * 1 bit used for the 'dot' on both digits.
+ *
+ *  @param N/A
+ *  @return N/A
+ */
+static u16 postcode_to_led_signal(void)
+{
+       u8 low_display;
+       u8 high_display;
+       u16 led_value;
+       char buf[3];
+
+       mutex_lock(&mutex);
+       strncpy(buf, curr_postcode, sizeof(buf));
+       mutex_unlock(&mutex);
+
+       low_display = seven_seg_bits[hex_to_bin(buf[2])];
+
+       high_display = (buf[0] == '1') ?
+               special_seven_seg_bits[hex_to_bin(buf[1])] :
+               seven_seg_bits[hex_to_bin(buf[1])];
+
+       led_value = low_display | (high_display << 8);
+       if (buf[0] == '1') {
+               led_value |= LED_DOT | (LED_DOT << 8);
+       }
+

drivers/misc/update-postcard.c line 115

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+       return led_value;
+}
+
+static void update_sgpio(void)
+{
+       u16 led_signal;
+       int i;
+
+       /* Convert two bytes of post code to 16 bit led pattern */
+       led_signal = postcode_to_led_signal();

Why do you wait until the display update to convert the string to the LED bit pattern? For that matter, why does update_postcode() take a string at all? If you can only display at most a 16-bit number, take a u16 and have the caller deal with whatever processing they need.

Quoted 27 lines
drivers/misc/update-postcard.c new file +26 -0
+
+       /* Set the clear signal to low */
+       gpiod_set_value(clr_gpio, 0);
+       udelay(1);
+       /* Set the clear clear to high */
+       gpiod_set_value(clr_gpio, 1);
+       udelay(1);
+
+       /* Bitbang the 16 bit led pattern
+        * 7-bits used for each 7-seg display
+        * 1 bit used for the 'dot' on both digits
+        */
+       for (i = 0; i < 16; i++) {
+               if (led_signal & 0x01) {
+                       /* Set the data signal to high */
+                       gpiod_set_value(data_gpio, 1);
+               } else {
+                       /* Set the data signal to low */
+                       gpiod_set_value(data_gpio, 0);
+               }
+               udelay(1);
+
+               /* Set the clock signal to low */
+               gpiod_set_value(clk_gpio, 0);
+               udelay(1);
+               /* Set the clock signal to high */

drivers/misc/update-postcard.c line 151

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+               gpiod_set_value(clk_gpio, 1);
+               udelay(1);
+
+               led_signal >>= 1;
+       }
+}
+
+static void update_timer_handler(unsigned long data)
+{
+       if (pc_valid == 1) {

Is this to avoid the time after the driver is register until update_postcode() is called the first time? Is there an API for clearing the display?

Quoted 54 lines
drivers/misc/update-postcard.c new file +54 -0
+               update_sgpio();
+       }
+       mod_timer(&update_timer,
+               jiffies + msecs_to_jiffies(POST_CODE_UPDATE_INTVL));
+}
+
+static const struct of_device_id of_postcard_match[] = {
+               { .compatible = "postcard-display" },
+                       {},
+};
+
+MODULE_DEVICE_TABLE(of, of_postcard_match);
+
+static int postcard_probe(struct platform_device *pdev)
+{
+       int result;
+       struct device *dev = &pdev->dev;
+
+       /* Requesting the clock gpio */
+       clk_gpio = devm_gpiod_get(dev, CLOCK_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(clk_gpio))
+               return PTR_ERR(data_gpio);
+
+       /* Requesting the data gpio */
+       data_gpio = devm_gpiod_get(dev, DATA_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(data_gpio))
+               return PTR_ERR(data_gpio);
+
+       /* Requesting the clear gpio */
+       clr_gpio = devm_gpiod_get(dev, CLEAR_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(clr_gpio))
+               return PTR_ERR(clr_gpio);
+
+       /* Start timer to update post code every second */
+       setup_timer(&update_timer, update_timer_handler, 0);
+       result = mod_timer(&update_timer,
+               jiffies + msecs_to_jiffies(POST_CODE_UPDATE_INTVL));
+
+       if (result)
+               return result;
+
+       mutex_init(&mutex);
+
+       return 0;
+}
+
+static void postcard_remove(struct platform_device *pdev)
+{
+       del_timer(&update_timer);
+}
+

drivers/misc/update-postcard.c line 215

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+static struct platform_driver postcard_display_driver = {
+       .probe          = postcard_probe,
+       .shutdown       = postcard_remove,
+       .driver         = {
+               .name   = "postcard-display",
+               .of_match_table = of_postcard_match,
+       },
+};
+
+module_platform_driver(postcard_display_driver);

+

Quoted 20 lines
drivers/misc/update-postcard.c new file +2 -0
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <[email protected]
Quoted 1 line

");

drivers/misc/update-postcard.c new file +1 -0
+MODULE_DESCRIPTION("Post card display update driver");
drivers/misc/update- renamed from drivers/misc/update-postcard.h +0 -0

postcard.h
new file mode 100644
index 0000000..ef82e9091d

drivers/misc/update-postcard.h new file +1 -1
@@ -0,0 +1 @@
+void update_postcode(char *buf);
--

2.8.0.rc3.226.g39d4020

_______________________________________________
openbmc mailing list
[email protected]
https://lists.ozlabs.org/listinfo/openbmc

#3 lore raw

Re: [PATCH linux v1 1/3] drivers: misc: Platform driver to update display on the POST card

Quoted 227 lines · Rick Altherr
Quoted 30 lines · Jaghathiswari Rankappagounder Natarajan

Platform driver to periodically update the display on the POST card. POST card hardware assumed is 74HC164 wired to two 7-segment displays.

---
 drivers/misc/Kconfig           |   6 ++
 drivers/misc/Makefile          |   1 +
 drivers/misc/update-postcard.c | 219 ++++++++++++++++++++++++++++++
+++++++++++
 drivers/misc/update-postcard.h |   1 +
 4 files changed, 227 insertions(+)
 create mode 100644 drivers/misc/update-postcard.c
 create mode 100644 drivers/misc/update-postcard.h
drivers/misc/Kconfig +0 -0
index 4617ddc..d65b83f 100644
@@ -804,6 +804,12 @@ config PANEL_BOOT_MESSAGE
          An empty message will only clear the display at driver init

time. Any other
printf()-formatted message is valid with newline and escape
codes.

drivers/misc/Kconfig +4 -0
+config ASPEED_UPDATE_POSTCARD
+       tristate "Platform driver to update POST card"
+       help
+        Support to periodically update display on the POST card. The

POST card

drivers/misc/Kconfig config PANEL_BOOT_MESSAGE · line 812

Quoted 2 lines
drivers/misc/Kconfig +2 -0
+        hardware assumed is 74HC164 wired to two 7-segment displays.
+

Nothing about this driver is associated with Aspeed. UPDATE_POSTCARD reads to me as describing an action, not a device. Maybe SEVEN_SEGMENT_DISPLAY?

Quoted 45 lines

config ASPEED_BT_IPMI_HOST
tristate "BT IPMI host driver"
help

drivers/misc/Makefile +1 -0
index 724861b..730c6c2 100644
@@ -57,4 +57,5 @@ obj-$(CONFIG_ECHO)            += echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)  += vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)         += cxl/
 obj-$(CONFIG_PANEL)             += panel.o
+obj-$(CONFIG_ASPEED_UPDATE_POSTCARD)    += update-postcard.o
 obj-$(CONFIG_ASPEED_BT_IPMI_HOST)      += bt-host.o
drivers/misc/update-postcard.c new file +24 -0
new file mode 100644
index 0000000..3516c24
@@ -0,0 +1,219 @@
+/* Platform driver to periodically update the display on the POST card.
+ * POST card hardware assumed is 74HC164 wired to two 7-segment displays.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/timer.h>
+#include <linux/jiffies.h>
+#include <linux/sizes.h>
+#include <linux/map_to_7segment.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
+#include <linux/mutex.h>
+#include <linux/of_platform.h>
+#include <linux/gpio/consumer.h>
+
+#define POST_CODE_UPDATE_INTVL 1000
+
+#define MAX_PC_SIZE 3
+
+#define LED_DOT 0x01
+
+#define CLOCK_GPIO_NAME "clk"

drivers/misc/update-postcard.c line 34

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+#define DATA_GPIO_NAME "data"
+#define CLEAR_GPIO_NAME "clr"
+
+static struct mutex mutex;
+
+static struct timer_list update_timer;
+
+static char curr_postcode[3];
+static u8 pc_valid;
+

+static struct gpio_desc *clk_gpio;

drivers/misc/update-postcard.c line 37

Quoted 3 lines
drivers/misc/update-postcard.c new file +2 -0
+static struct gpio_desc *data_gpio;
+static struct gpio_desc *clr_gpio;

I realize there should really only ever be one of these in a system but static data members in modules bug me. I'd much rather see all this configuration and these buffers in a struct that is saved with platform_set_drvdata().

Quoted 69 lines
drivers/misc/update-postcard.c new file +68 -0
+
+/*
+ * 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+ *  _       _   _       _   _   _   _   _   _       _       _   _
+ * | |   |  _|  _| |_| |_  |_    | |_| |_| |_| |_  |    _| |_  |_
+ * |_|   | |_   _|   |  _| |_|   | |_|   | | | |_| |_  |_| |_  |
+ *
+ * data[7:1] = led[a:g]
+ * lookup table used for both bytes of lpc post code and lower byte of
+ * bmc post code
+ */
+const u8 seven_seg_bits[] = {
+       0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0,
+       0xFE, 0xF6, 0xEE, 0x3E, 0x9C, 0x7A, 0x9E, 0x8E
+       };
+
+/*
+ * 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+ *      _       _   _                              _            _
+ *     |   |_  |_| |_  _   _   _   _   _   _   _  |_    _|  _| | |
+ *     |_  |_  |   |                               _|  |_| |_| | |
+ *
+ * data[7:1] = led[a:g]
+ * lookup table used for higher byte of bmc post code
+ */
+const u8 special_seven_seg_bits[] = {
+       0x00, 0x9C, 0x1E, 0xCE, 0x8E, 0x02, 0x02, 0x02,
+       0x02, 0x02, 0x02, 0x02, 0xB6, 0x7A, 0x7A, 0xEC
+       };
+
+void update_postcode(char *buf)
+{
+       mutex_lock(&mutex);
+       strncpy(curr_postcode, buf, sizeof(curr_postcode));
+       mutex_unlock(&mutex);
+       pc_valid = 1;
+}
+EXPORT_SYMBOL(update_postcode);
+
+/* convert postcode to led pattern
+ * 7-bits used for each 7-seg display and
+ * 1 bit used for the 'dot' on both digits.
+ *
+ *  @param N/A
+ *  @return N/A
+ */
+static u16 postcode_to_led_signal(void)
+{
+       u8 low_display;
+       u8 high_display;
+       u16 led_value;
+       char buf[3];
+
+       mutex_lock(&mutex);
+       strncpy(buf, curr_postcode, sizeof(buf));
+       mutex_unlock(&mutex);
+
+       low_display = seven_seg_bits[hex_to_bin(buf[2])];
+
+       high_display = (buf[0] == '1') ?
+               special_seven_seg_bits[hex_to_bin(buf[1])] :
+               seven_seg_bits[hex_to_bin(buf[1])];
+
+       led_value = low_display | (high_display << 8);
+       if (buf[0] == '1') {
+               led_value |= LED_DOT | (LED_DOT << 8);
+       }
+

drivers/misc/update-postcard.c line 115

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+       return led_value;
+}
+
+static void update_sgpio(void)
+{
+       u16 led_signal;
+       int i;
+
+       /* Convert two bytes of post code to 16 bit led pattern */
+       led_signal = postcode_to_led_signal();

Why do you wait until the display update to convert the string to the LED bit pattern? For that matter, why does update_postcode() take a string at all? If you can only display at most a 16-bit number, take a u16 and have the caller deal with whatever processing they need.

Quoted 33 lines
drivers/misc/update-postcard.c new file +33 -0
+
+       /* Set the clear signal to low */
+       gpiod_set_value(clr_gpio, 0);
+       udelay(1);
+       /* Set the clear clear to high */
+       gpiod_set_value(clr_gpio, 1);
+       udelay(1);
+
+       /* Bitbang the 16 bit led pattern
+        * 7-bits used for each 7-seg display
+        * 1 bit used for the 'dot' on both digits
+        */
+       for (i = 0; i < 16; i++) {
+               if (led_signal & 0x01) {
+                       /* Set the data signal to high */
+                       gpiod_set_value(data_gpio, 1);
+               } else {
+                       /* Set the data signal to low */
+                       gpiod_set_value(data_gpio, 0);
+               }
+               udelay(1);
+
+               /* Set the clock signal to low */
+               gpiod_set_value(clk_gpio, 0);
+               udelay(1);
+               /* Set the clock signal to high */
+               gpiod_set_value(clk_gpio, 1);
+               udelay(1);
+
+               led_signal >>= 1;
+       }
+}
+
Quoted 9 lines

drivers/misc/update-postcard.c line 151

Quoted 4 lines
drivers/misc/update-postcard.c new file +3 -0
+static void update_timer_handler(unsigned long data)
+{
+       if (pc_valid == 1) {

Is this to avoid the time after the driver is register until update_postcode() is called the first time? Is there an API for clearing the display?

Yes, this is to wait until the user gives a valid display data. I have included an API for clearing the display in the next patch.

Quoted 90 lines
Quoted 56 lines
drivers/misc/update-postcard.c new file +54 -0
+               update_sgpio();
+       }
+       mod_timer(&update_timer,
+               jiffies + msecs_to_jiffies(POST_CODE_UPDATE_INTVL));
+}
+
+static const struct of_device_id of_postcard_match[] = {
+               { .compatible = "postcard-display" },
+                       {},
+};
+
+MODULE_DEVICE_TABLE(of, of_postcard_match);
+
+static int postcard_probe(struct platform_device *pdev)
+{
+       int result;
+       struct device *dev = &pdev->dev;
+
+       /* Requesting the clock gpio */
+       clk_gpio = devm_gpiod_get(dev, CLOCK_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(clk_gpio))
+               return PTR_ERR(data_gpio);
+
+       /* Requesting the data gpio */
+       data_gpio = devm_gpiod_get(dev, DATA_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(data_gpio))
+               return PTR_ERR(data_gpio);
+
+       /* Requesting the clear gpio */
+       clr_gpio = devm_gpiod_get(dev, CLEAR_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(clr_gpio))
+               return PTR_ERR(clr_gpio);
+
+       /* Start timer to update post code every second */
+       setup_timer(&update_timer, update_timer_handler, 0);
+       result = mod_timer(&update_timer,
+               jiffies + msecs_to_jiffies(POST_CODE_UPDATE_INTVL));
+
+       if (result)
+               return result;
+
+       mutex_init(&mutex);
+
+       return 0;
+}
+
+static void postcard_remove(struct platform_device *pdev)
+{
+       del_timer(&update_timer);
+}
+

drivers/misc/update-postcard.c line 215

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+static struct platform_driver postcard_display_driver = {
+       .probe          = postcard_probe,
+       .shutdown       = postcard_remove,
+       .driver         = {
+               .name   = "postcard-display",
+               .of_match_table = of_postcard_match,
+       },
+};
+
+module_platform_driver(postcard_display_driver);

+

Quoted 20 lines
drivers/misc/update-postcard.c new file +2 -0
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <[email protected]
Quoted 1 line

");

drivers/misc/update-postcard.c new file +1 -0
+MODULE_DESCRIPTION("Post card display update driver");
drivers/misc/update-postcard.h new file +1 -1
new file mode 100644
index 0000000..ef82e9091d
@@ -0,0 +1 @@
+void update_postcode(char *buf);
--

2.8.0.rc3.226.g39d4020

_______________________________________________
openbmc mailing list
[email protected]
https://lists.ozlabs.org/listinfo/openbmc

#4 lore raw

Re: [PATCH linux v1 1/3] drivers: misc: Platform driver to update display on the POST card

In reply to Jaghathiswari Rankappagounder Natarajan

with Hi Jagha,

Quoted 5 lines · Jaghathiswari Rankappagounder Natarajan

Platform driver to periodically update the display on the POST card. POST card hardware assumed is 74HC164 wired to two 7-segment displays.

Quoted 8 lines
---
 drivers/misc/Kconfig           |   6 ++
 drivers/misc/Makefile          |   1 +
 drivers/misc/update-postcard.c | 219 +++++++++++++++++++++++++++++++++++++++++
 drivers/misc/update-postcard.h |   1 +
 4 files changed, 227 insertions(+)
 create mode 100644 drivers/misc/update-postcard.c
 create mode 100644 drivers/misc/update-postcard.h

I agree with what Rick said. You should consider reframing the driver as a general purpose "bitbang shift register-attached 7-segment LEDs" driver and not mention POST codes in here.

This will be more clear to other kernel reviewers because

1) they probably don't know what a "POST card" is
2) they're not thinking of BMCs, so they'll confused as to why Linux would want to display POST codes (usually precedes Linux)

drivers/misc/Kconfig

Quoted 6 lines
drivers/misc/Kconfig +0 -0
index 4617ddc..d65b83f 100644

Does drivers/misc make sense? Your driver is most similar to those described in http://lxr.free-electrons.com/source/Documentation/gpio/drivers-on-gpio.txt

I'm genuinely uncertain since I have little upstream Linux experience.

Quoted 37 lines
drivers/misc/Kconfig +6 -0
@@ -804,6 +804,12 @@ config PANEL_BOOT_MESSAGE
          An empty message will only clear the display at driver init time. Any other
          printf()-formatted message is valid with newline and escape codes.
 
+config ASPEED_UPDATE_POSTCARD
+       tristate "Platform driver to update POST card"
+       help
+        Support to periodically update display on the POST card. The POST card
+        hardware assumed is 74HC164 wired to two 7-segment displays.
+
 config ASPEED_BT_IPMI_HOST
        tristate "BT IPMI host driver"
        help
drivers/misc/Makefile +1 -0
index 724861b..730c6c2 100644
@@ -57,4 +57,5 @@ obj-$(CONFIG_ECHO)            += echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)  += vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)         += cxl/
 obj-$(CONFIG_PANEL)             += panel.o
+obj-$(CONFIG_ASPEED_UPDATE_POSTCARD)    += update-postcard.o
 obj-$(CONFIG_ASPEED_BT_IPMI_HOST)      += bt-host.o
drivers/misc/update-postcard.c new file +8 -0
new file mode 100644
index 0000000..3516c24
@@ -0,0 +1,219 @@
+/* Platform driver to periodically update the display on the POST card.
+ * POST card hardware assumed is 74HC164 wired to two 7-segment displays.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/timer.h>
+#include <linux/jiffies.h>

drivers/misc/update-postcard.c line 18

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+#include <linux/sizes.h>
+#include <linux/map_to_7segment.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
+#include <linux/mutex.h>
+#include <linux/of_platform.h>
+#include <linux/gpio/consumer.h>
+
+#define POST_CODE_UPDATE_INTVL 1000

Maybe make this an optional device tree property with 1000 as the default value. Please also suffix with units (*_ms).

Quoted 9 lines
drivers/misc/update-postcard.c new file +9 -0
+
+#define MAX_PC_SIZE 3
+
+#define LED_DOT 0x01
+
+#define CLOCK_GPIO_NAME "clk"
+#define DATA_GPIO_NAME "data"
+#define CLEAR_GPIO_NAME "clr"
+

drivers/misc/update-postcard.c line 37

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+static struct mutex mutex;
+
+static struct timer_list update_timer;
+
+static char curr_postcode[3];
+static u8 pc_valid;
+
+static struct gpio_desc *clk_gpio;
+static struct gpio_desc *data_gpio;
+static struct gpio_desc *clr_gpio;

Agree that these should be wrapped up into a struct. It'll then be easier to turn this into a module or to support multiple shift register 7seg displays (not that we want those things right now).

Quoted 62 lines
drivers/misc/update-postcard.c new file +62 -0
+
+/*
+ * 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+ *  _       _   _       _   _   _   _   _   _       _       _   _
+ * | |   |  _|  _| |_| |_  |_    | |_| |_| |_| |_  |    _| |_  |_
+ * |_|   | |_   _|   |  _| |_|   | |_|   | | | |_| |_  |_| |_  |
+ *
+ * data[7:1] = led[a:g]
+ * lookup table used for both bytes of lpc post code and lower byte of
+ * bmc post code
+ */
+const u8 seven_seg_bits[] = {
+       0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0,
+       0xFE, 0xF6, 0xEE, 0x3E, 0x9C, 0x7A, 0x9E, 0x8E
+       };
+
+/*
+ * 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+ *      _       _   _                              _            _
+ *     |   |_  |_| |_  _   _   _   _   _   _   _  |_    _|  _| | |
+ *     |_  |_  |   |                               _|  |_| |_| | |
+ *
+ * data[7:1] = led[a:g]
+ * lookup table used for higher byte of bmc post code
+ */
+const u8 special_seven_seg_bits[] = {
+       0x00, 0x9C, 0x1E, 0xCE, 0x8E, 0x02, 0x02, 0x02,
+       0x02, 0x02, 0x02, 0x02, 0xB6, 0x7A, 0x7A, 0xEC
+       };
+
+void update_postcode(char *buf)
+{
+       mutex_lock(&mutex);
+       strncpy(curr_postcode, buf, sizeof(curr_postcode));
+       mutex_unlock(&mutex);
+       pc_valid = 1;
+}
+EXPORT_SYMBOL(update_postcode);
+
+/* convert postcode to led pattern
+ * 7-bits used for each 7-seg display and
+ * 1 bit used for the 'dot' on both digits.
+ *
+ *  @param N/A
+ *  @return N/A
+ */
+static u16 postcode_to_led_signal(void)
+{
+       u8 low_display;
+       u8 high_display;
+       u16 led_value;
+       char buf[3];
+
+       mutex_lock(&mutex);
+       strncpy(buf, curr_postcode, sizeof(buf));
+       mutex_unlock(&mutex);
+
+       low_display = seven_seg_bits[hex_to_bin(buf[2])];
+
+       high_display = (buf[0] == '1') ?
+               special_seven_seg_bits[hex_to_bin(buf[1])] :
+               seven_seg_bits[hex_to_bin(buf[1])];

drivers/misc/update-postcard.c line 109

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+
+       led_value = low_display | (high_display << 8);
+       if (buf[0] == '1') {
+               led_value |= LED_DOT | (LED_DOT << 8);
+       }
+
+       return led_value;
+}
+
+static void update_sgpio(void)

Since you're no longer using the Serial GPIO peripheral, please rename this to something more descriptive like "write_..._display"

Quoted 21 lines
drivers/misc/update-postcard.c new file +21 -0
+{
+       u16 led_signal;
+       int i;
+
+       /* Convert two bytes of post code to 16 bit led pattern */
+       led_signal = postcode_to_led_signal();
+
+       /* Set the clear signal to low */
+       gpiod_set_value(clr_gpio, 0);
+       udelay(1);
+       /* Set the clear clear to high */
+       gpiod_set_value(clr_gpio, 1);
+       udelay(1);
+
+       /* Bitbang the 16 bit led pattern
+        * 7-bits used for each 7-seg display
+        * 1 bit used for the 'dot' on both digits
+        */
+       for (i = 0; i < 16; i++) {
+               if (led_signal & 0x01) {
+                       /* Set the data signal to high */

drivers/misc/update-postcard.c line 140

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+                       gpiod_set_value(data_gpio, 1);
+               } else {
+                       /* Set the data signal to low */
+                       gpiod_set_value(data_gpio, 0);
+               }
+               udelay(1);
+
+               /* Set the clock signal to low */
+               gpiod_set_value(clk_gpio, 0);
+               udelay(1);

Please name this delay value as a constant (or make it configurable, up to you).

Quoted 89 lines
drivers/misc/update-postcard.c new file +79 -0
+               /* Set the clock signal to high */
+               gpiod_set_value(clk_gpio, 1);
+               udelay(1);
+
+               led_signal >>= 1;
+       }
+}
+
+static void update_timer_handler(unsigned long data)
+{
+       if (pc_valid == 1) {
+               update_sgpio();
+       }
+       mod_timer(&update_timer,
+               jiffies + msecs_to_jiffies(POST_CODE_UPDATE_INTVL));
+}
+
+static const struct of_device_id of_postcard_match[] = {
+               { .compatible = "postcard-display" },
+                       {},
+};
+
+MODULE_DEVICE_TABLE(of, of_postcard_match);
+
+static int postcard_probe(struct platform_device *pdev)
+{
+       int result;
+       struct device *dev = &pdev->dev;
+
+       /* Requesting the clock gpio */
+       clk_gpio = devm_gpiod_get(dev, CLOCK_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(clk_gpio))
+               return PTR_ERR(data_gpio);
+
+       /* Requesting the data gpio */
+       data_gpio = devm_gpiod_get(dev, DATA_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(data_gpio))
+               return PTR_ERR(data_gpio);
+
+       /* Requesting the clear gpio */
+       clr_gpio = devm_gpiod_get(dev, CLEAR_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(clr_gpio))
+               return PTR_ERR(clr_gpio);
+
+       /* Start timer to update post code every second */
+       setup_timer(&update_timer, update_timer_handler, 0);
+       result = mod_timer(&update_timer,
+               jiffies + msecs_to_jiffies(POST_CODE_UPDATE_INTVL));
+
+       if (result)
+               return result;
+
+       mutex_init(&mutex);
+
+       return 0;
+}
+
+static void postcard_remove(struct platform_device *pdev)
+{
+       del_timer(&update_timer);
+}
+
+static struct platform_driver postcard_display_driver = {
+       .probe          = postcard_probe,
+       .shutdown       = postcard_remove,
+       .driver         = {
+               .name   = "postcard-display",
+               .of_match_table = of_postcard_match,
+       },
+};
+
+module_platform_driver(postcard_display_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <[email protected]>");
+MODULE_DESCRIPTION("Post card display update driver");
drivers/misc/update-postcard.h new file +1 -1
new file mode 100644
index 0000000..ef82e9091d
@@ -0,0 +1 @@
+void update_postcode(char *buf);
--

2.8.0.rc3.226.g39d4020

Quoted 4 lines

_______________________________________________
openbmc mailing list
[email protected]
https://lists.ozlabs.org/listinfo/openbmc

cheers
xo

#5 lore raw

Re: [PATCH linux v1 1/3] drivers: misc: Platform driver to update display on the POST card

Quoted 41 lines · Xo Wang

with Hi Jagha,

Quoted 10 lines · Jaghathiswari Rankappagounder Natarajan

Platform driver to periodically update the display on the POST card. POST card hardware assumed is 74HC164 wired to two 7-segment displays.

---
 drivers/misc/Kconfig           |   6 ++
 drivers/misc/Makefile          |   1 +
 drivers/misc/update-postcard.c | 219 ++++++++++++++++++++++++++++++

+++++++++++

Quoted 4 lines
 drivers/misc/update-postcard.h |   1 +
 4 files changed, 227 insertions(+)
 create mode 100644 drivers/misc/update-postcard.c
 create mode 100644 drivers/misc/update-postcard.h

I agree with what Rick said. You should consider reframing the driver as a general purpose "bitbang shift register-attached 7-segment LEDs" driver and not mention POST codes in here.

This will be more clear to other kernel reviewers because

1) they probably don't know what a "POST card" is
2) they're not thinking of BMCs, so they'll confused as to why Linux would want to display POST codes (usually precedes Linux)

drivers/misc/Kconfig

Quoted 6 lines
drivers/misc/Kconfig +0 -0
index 4617ddc..d65b83f 100644

Does drivers/misc make sense? Your driver is most similar to those described in http://lxr.free-electrons.com/source/Documentation/gpio/
drivers-on-gpio.txt

Quoted 1 line

I'm genuinely uncertain since I have little upstream Linux experience.

I looked at the other drivers given in the link you mentioned. But they do not seem relevant. So I have put them in drivers/misc

Quoted 290 lines

drivers/misc/Kconfig config PANEL_BOOT_MESSAGE · line 804

Quoted 2 lines
drivers/misc/Kconfig +0 -0
@@ -804,6 +804,12 @@ config PANEL_BOOT_MESSAGE
          An empty message will only clear the display at driver init

time. Any other

drivers/misc/Kconfig config PANEL_BOOT_MESSAGE · line 805

Quoted 1 line
drivers/misc/Kconfig +0 -0
          printf()-formatted message is valid with newline and escape

codes.

drivers/misc/Kconfig config PANEL_BOOT_MESSAGE

Quoted 5 lines
drivers/misc/Kconfig +4 -0
+config ASPEED_UPDATE_POSTCARD
+       tristate "Platform driver to update POST card"
+       help
+        Support to periodically update display on the POST card. The

POST card

drivers/misc/update-

Quoted 16 lines
drivers/misc/Kconfig +2 -0
+        hardware assumed is 74HC164 wired to two 7-segment displays.
+
 config ASPEED_BT_IPMI_HOST
        tristate "BT IPMI host driver"
        help
drivers/misc/Makefile +1 -0
index 724861b..730c6c2 100644
@@ -57,4 +57,5 @@ obj-$(CONFIG_ECHO)            += echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)  += vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)         += cxl/
 obj-$(CONFIG_PANEL)             += panel.o
+obj-$(CONFIG_ASPEED_UPDATE_POSTCARD)    += update-postcard.o
 obj-$(CONFIG_ASPEED_BT_IPMI_HOST)      += bt-host.o
drivers/misc/update- renamed from drivers/misc/update-postcard.c +0 -0

postcard.c

drivers/misc/update-postcard.c line 2

Quoted 7 lines

new file mode 100644
index 0000000..3516c24

drivers/misc/update-postcard.c new file +2 -0
@@ -0,0 +1,219 @@
+/* Platform driver to periodically update the display on the POST card.
+ * POST card hardware assumed is 74HC164 wired to two 7-segment

displays.

Quoted 6 lines
drivers/misc/update-postcard.c new file +6 -0
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/timer.h>
+#include <linux/jiffies.h>

drivers/misc/update-postcard.c line 18

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+#include <linux/sizes.h>
+#include <linux/map_to_7segment.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
+#include <linux/mutex.h>
+#include <linux/of_platform.h>
+#include <linux/gpio/consumer.h>
+
+#define POST_CODE_UPDATE_INTVL 1000

Maybe make this an optional device tree property with 1000 as the default value. Please also suffix with units (*_ms).

Quoted 9 lines
drivers/misc/update-postcard.c new file +9 -0
+
+#define MAX_PC_SIZE 3
+
+#define LED_DOT 0x01
+
+#define CLOCK_GPIO_NAME "clk"
+#define DATA_GPIO_NAME "data"
+#define CLEAR_GPIO_NAME "clr"
+

drivers/misc/update-postcard.c line 37

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+static struct mutex mutex;
+
+static struct timer_list update_timer;
+
+static char curr_postcode[3];
+static u8 pc_valid;
+
+static struct gpio_desc *clk_gpio;
+static struct gpio_desc *data_gpio;
+static struct gpio_desc *clr_gpio;

Agree that these should be wrapped up into a struct. It'll then be easier to turn this into a module or to support multiple shift register 7seg displays (not that we want those things right now).

Quoted 62 lines
drivers/misc/update-postcard.c new file +62 -0
+
+/*
+ * 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+ *  _       _   _       _   _   _   _   _   _       _       _   _
+ * | |   |  _|  _| |_| |_  |_    | |_| |_| |_| |_  |    _| |_  |_
+ * |_|   | |_   _|   |  _| |_|   | |_|   | | | |_| |_  |_| |_  |
+ *
+ * data[7:1] = led[a:g]
+ * lookup table used for both bytes of lpc post code and lower byte of
+ * bmc post code
+ */
+const u8 seven_seg_bits[] = {
+       0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0,
+       0xFE, 0xF6, 0xEE, 0x3E, 0x9C, 0x7A, 0x9E, 0x8E
+       };
+
+/*
+ * 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+ *      _       _   _                              _            _
+ *     |   |_  |_| |_  _   _   _   _   _   _   _  |_    _|  _| | |
+ *     |_  |_  |   |                               _|  |_| |_| | |
+ *
+ * data[7:1] = led[a:g]
+ * lookup table used for higher byte of bmc post code
+ */
+const u8 special_seven_seg_bits[] = {
+       0x00, 0x9C, 0x1E, 0xCE, 0x8E, 0x02, 0x02, 0x02,
+       0x02, 0x02, 0x02, 0x02, 0xB6, 0x7A, 0x7A, 0xEC
+       };
+
+void update_postcode(char *buf)
+{
+       mutex_lock(&mutex);
+       strncpy(curr_postcode, buf, sizeof(curr_postcode));
+       mutex_unlock(&mutex);
+       pc_valid = 1;
+}
+EXPORT_SYMBOL(update_postcode);
+
+/* convert postcode to led pattern
+ * 7-bits used for each 7-seg display and
+ * 1 bit used for the 'dot' on both digits.
+ *
+ *  @param N/A
+ *  @return N/A
+ */
+static u16 postcode_to_led_signal(void)
+{
+       u8 low_display;
+       u8 high_display;
+       u16 led_value;
+       char buf[3];
+
+       mutex_lock(&mutex);
+       strncpy(buf, curr_postcode, sizeof(buf));
+       mutex_unlock(&mutex);
+
+       low_display = seven_seg_bits[hex_to_bin(buf[2])];
+
+       high_display = (buf[0] == '1') ?
+               special_seven_seg_bits[hex_to_bin(buf[1])] :
+               seven_seg_bits[hex_to_bin(buf[1])];

drivers/misc/update-postcard.c line 109

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+
+       led_value = low_display | (high_display << 8);
+       if (buf[0] == '1') {
+               led_value |= LED_DOT | (LED_DOT << 8);
+       }
+
+       return led_value;
+}
+
+static void update_sgpio(void)

Since you're no longer using the Serial GPIO peripheral, please rename this to something more descriptive like "write_..._display"

Quoted 21 lines
drivers/misc/update-postcard.c new file +21 -0
+{
+       u16 led_signal;
+       int i;
+
+       /* Convert two bytes of post code to 16 bit led pattern */
+       led_signal = postcode_to_led_signal();
+
+       /* Set the clear signal to low */
+       gpiod_set_value(clr_gpio, 0);
+       udelay(1);
+       /* Set the clear clear to high */
+       gpiod_set_value(clr_gpio, 1);
+       udelay(1);
+
+       /* Bitbang the 16 bit led pattern
+        * 7-bits used for each 7-seg display
+        * 1 bit used for the 'dot' on both digits
+        */
+       for (i = 0; i < 16; i++) {
+               if (led_signal & 0x01) {
+                       /* Set the data signal to high */

drivers/misc/update-postcard.c line 140

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+                       gpiod_set_value(data_gpio, 1);
+               } else {
+                       /* Set the data signal to low */
+                       gpiod_set_value(data_gpio, 0);
+               }
+               udelay(1);
+
+               /* Set the clock signal to low */
+               gpiod_set_value(clk_gpio, 0);
+               udelay(1);

Please name this delay value as a constant (or make it configurable, up to you).

Quoted 68 lines
drivers/misc/update-postcard.c new file +68 -0
+               /* Set the clock signal to high */
+               gpiod_set_value(clk_gpio, 1);
+               udelay(1);
+
+               led_signal >>= 1;
+       }
+}
+
+static void update_timer_handler(unsigned long data)
+{
+       if (pc_valid == 1) {
+               update_sgpio();
+       }
+       mod_timer(&update_timer,
+               jiffies + msecs_to_jiffies(POST_CODE_UPDATE_INTVL));
+}
+
+static const struct of_device_id of_postcard_match[] = {
+               { .compatible = "postcard-display" },
+                       {},
+};
+
+MODULE_DEVICE_TABLE(of, of_postcard_match);
+
+static int postcard_probe(struct platform_device *pdev)
+{
+       int result;
+       struct device *dev = &pdev->dev;
+
+       /* Requesting the clock gpio */
+       clk_gpio = devm_gpiod_get(dev, CLOCK_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(clk_gpio))
+               return PTR_ERR(data_gpio);
+
+       /* Requesting the data gpio */
+       data_gpio = devm_gpiod_get(dev, DATA_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(data_gpio))
+               return PTR_ERR(data_gpio);
+
+       /* Requesting the clear gpio */
+       clr_gpio = devm_gpiod_get(dev, CLEAR_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(clr_gpio))
+               return PTR_ERR(clr_gpio);
+
+       /* Start timer to update post code every second */
+       setup_timer(&update_timer, update_timer_handler, 0);
+       result = mod_timer(&update_timer,
+               jiffies + msecs_to_jiffies(POST_CODE_UPDATE_INTVL));
+
+       if (result)
+               return result;
+
+       mutex_init(&mutex);
+
+       return 0;
+}
+
+static void postcard_remove(struct platform_device *pdev)
+{
+       del_timer(&update_timer);
+}
+
+static struct platform_driver postcard_display_driver = {
+       .probe          = postcard_probe,
+       .shutdown       = postcard_remove,

drivers/misc/update-postcard.c

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+       .driver         = {
+               .name   = "postcard-display",
+               .of_match_table = of_postcard_match,
+       },
+};
+
+module_platform_driver(postcard_display_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <

[email protected]>");

drivers/misc/update-

Quoted 2 lines
drivers/misc/update-postcard.c new file +1 -0
+MODULE_DESCRIPTION("Post card display update driver");
drivers/misc/update- renamed from drivers/misc/update-postcard.h +0 -0

postcard.h

Quoted 9 lines

new file mode 100644
index 0000000..ef82e9091d

drivers/misc/update-postcard.h new file +1 -1
@@ -0,0 +1 @@
+void update_postcode(char *buf);
--

2.8.0.rc3.226.g39d4020

Quoted 4 lines

_______________________________________________
openbmc mailing list
[email protected]
https://lists.ozlabs.org/listinfo/openbmc

cheers
xo

maintainer
#6 lore raw

Re: [PATCH linux v1 1/3] drivers: misc: Platform driver to update display on the POST card

In reply to Jaghathiswari Rankappagounder Natarajan

Hello,

Quoted 4 lines · Jaghathiswari Rankappagounder Natarajan

Platform driver to periodically update the display on the POST card. POST card hardware assumed is 74HC164 wired to two 7-segment displays.

A good start. In addition to the other reviews, I have some comments below.

drivers/misc/update-postcard.c

Quoted 42 lines
---
 drivers/misc/Kconfig           |   6 ++
 drivers/misc/Makefile          |   1 +
 drivers/misc/update-postcard.c | 219 +++++++++++++++++++++++++++++++++++++++++
 drivers/misc/update-postcard.h |   1 +
 4 files changed, 227 insertions(+)
 create mode 100644 drivers/misc/update-postcard.c
 create mode 100644 drivers/misc/update-postcard.h
drivers/misc/Kconfig +6 -0
index 4617ddc..d65b83f 100644
@@ -804,6 +804,12 @@ config PANEL_BOOT_MESSAGE
          An empty message will only clear the display at driver init time. Any other
          printf()-formatted message is valid with newline and escape codes.
 
+config ASPEED_UPDATE_POSTCARD
+       tristate "Platform driver to update POST card"
+       help
+        Support to periodically update display on the POST card. The POST card
+        hardware assumed is 74HC164 wired to two 7-segment displays.
+
 config ASPEED_BT_IPMI_HOST
        tristate "BT IPMI host driver"
        help
drivers/misc/Makefile +1 -0
index 724861b..730c6c2 100644
@@ -57,4 +57,5 @@ obj-$(CONFIG_ECHO)            += echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)  += vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)         += cxl/
 obj-$(CONFIG_PANEL)             += panel.o
+obj-$(CONFIG_ASPEED_UPDATE_POSTCARD)    += update-postcard.o
 obj-$(CONFIG_ASPEED_BT_IPMI_HOST)      += bt-host.o
drivers/misc/update-postcard.c new file +0 -0
new file mode 100644
index 0000000..3516c24
@@ -0,0 +1,219 @@

You need a copyright header here.

Quoted 73 lines
drivers/misc/update-postcard.c new file +73 -0
+/* Platform driver to periodically update the display on the POST card.
+ * POST card hardware assumed is 74HC164 wired to two 7-segment displays.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/timer.h>
+#include <linux/jiffies.h>
+#include <linux/sizes.h>
+#include <linux/map_to_7segment.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
+#include <linux/mutex.h>
+#include <linux/of_platform.h>
+#include <linux/gpio/consumer.h>
+
+#define POST_CODE_UPDATE_INTVL 1000
+
+#define MAX_PC_SIZE 3
+
+#define LED_DOT 0x01
+
+#define CLOCK_GPIO_NAME "clk"
+#define DATA_GPIO_NAME "data"
+#define CLEAR_GPIO_NAME "clr"
+
+static struct mutex mutex;
+
+static struct timer_list update_timer;
+
+static char curr_postcode[3];
+static u8 pc_valid;
+
+static struct gpio_desc *clk_gpio;
+static struct gpio_desc *data_gpio;
+static struct gpio_desc *clr_gpio;
+
+/*
+ * 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+ *  _       _   _       _   _   _   _   _   _       _       _   _
+ * | |   |  _|  _| |_| |_  |_    | |_| |_| |_| |_  |    _| |_  |_
+ * |_|   | |_   _|   |  _| |_|   | |_|   | | | |_| |_  |_| |_  |
+ *
+ * data[7:1] = led[a:g]
+ * lookup table used for both bytes of lpc post code and lower byte of
+ * bmc post code
+ */
+const u8 seven_seg_bits[] = {
+       0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0,
+       0xFE, 0xF6, 0xEE, 0x3E, 0x9C, 0x7A, 0x9E, 0x8E
+       };
+
+/*
+ * 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
+ *      _       _   _                              _            _
+ *     |   |_  |_| |_  _   _   _   _   _   _   _  |_    _|  _| | |
+ *     |_  |_  |   |                               _|  |_| |_| | |
+ *
+ * data[7:1] = led[a:g]
+ * lookup table used for higher byte of bmc post code
+ */
+const u8 special_seven_seg_bits[] = {
+       0x00, 0x9C, 0x1E, 0xCE, 0x8E, 0x02, 0x02, 0x02,
+       0x02, 0x02, 0x02, 0x02, 0xB6, 0x7A, 0x7A, 0xEC
+       };
+
+void update_postcode(char *buf)
+{
+       mutex_lock(&mutex);
+       strncpy(curr_postcode, buf, sizeof(curr_postcode));
+       mutex_unlock(&mutex);
+       pc_valid = 1;

drivers/misc/update-postcard.c line 83

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+}
+EXPORT_SYMBOL(update_postcode);
+
+/* convert postcode to led pattern
+ * 7-bits used for each 7-seg display and
+ * 1 bit used for the 'dot' on both digits.
+ *
+ *  @param N/A
+ *  @return N/A
+ */

Kernel style for multi-line comments is like this:

/*
* convert postcode to led pattern
* * 7-bits used for each 7-seg display and
* * 1 bit used for the 'dot' on both digits.
*/

Drop the @param/@return annotations.

Quoted 6 lines
drivers/misc/update-postcard.c new file +6 -0
+static u16 postcode_to_led_signal(void)
+{
+       u8 low_display;
+       u8 high_display;
+       u16 led_value;
+       char buf[3];

drivers/misc/update-postcard.c line 99

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+
+       mutex_lock(&mutex);
+       strncpy(buf, curr_postcode, sizeof(buf));
+       mutex_unlock(&mutex);
+
+       low_display = seven_seg_bits[hex_to_bin(buf[2])];
+
+       high_display = (buf[0] == '1') ?
+               special_seven_seg_bits[hex_to_bin(buf[1])] :
+               seven_seg_bits[hex_to_bin(buf[1])];

This could be clearer if you used if()

Quoted 25 lines
drivers/misc/update-postcard.c new file +25 -0
+
+       led_value = low_display | (high_display << 8);
+       if (buf[0] == '1') {
+               led_value |= LED_DOT | (LED_DOT << 8);
+       }
+
+       return led_value;
+}
+
+static void update_sgpio(void)
+{
+       u16 led_signal;
+       int i;
+
+       /* Convert two bytes of post code to 16 bit led pattern */
+       led_signal = postcode_to_led_signal();
+
+       /* Set the clear signal to low */
+       gpiod_set_value(clr_gpio, 0);
+       udelay(1);
+       /* Set the clear clear to high */
+       gpiod_set_value(clr_gpio, 1);
+       udelay(1);
+
+       /* Bitbang the 16 bit led pattern

drivers/misc/update-postcard.c line 134

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+        * 7-bits used for each 7-seg display
+        * 1 bit used for the 'dot' on both digits
+        */
+       for (i = 0; i < 16; i++) {
+               if (led_signal & 0x01) {
+                       /* Set the data signal to high */
+                       gpiod_set_value(data_gpio, 1);
+               } else {
+                       /* Set the data signal to low */
+                       gpiod_set_value(data_gpio, 0);

These comments are unnecessary - it's obvious what the code is doing.

Quoted 15 lines
drivers/misc/update-postcard.c new file +15 -0
+               }
+               udelay(1);
+
+               /* Set the clock signal to low */
+               gpiod_set_value(clk_gpio, 0);
+               udelay(1);
+               /* Set the clock signal to high */
+               gpiod_set_value(clk_gpio, 1);
+               udelay(1);
+
+               led_signal >>= 1;
+       }
+}
+
+static void update_timer_handler(unsigned long data)

drivers/misc/update-postcard.c line 159

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+{
+       if (pc_valid == 1) {
+               update_sgpio();
+       }
+       mod_timer(&update_timer,
+               jiffies + msecs_to_jiffies(POST_CODE_UPDATE_INTVL));
+}
+
+static const struct of_device_id of_postcard_match[] = {
+               { .compatible = "postcard-display" },

We need to come up with a better string here. Along the lines of your other reviews, make it generic.

Quoted 34 lines
drivers/misc/update-postcard.c new file +34 -0
+                       {},
+};
+
+MODULE_DEVICE_TABLE(of, of_postcard_match);
+
+static int postcard_probe(struct platform_device *pdev)
+{
+       int result;
+       struct device *dev = &pdev->dev;
+
+       /* Requesting the clock gpio */
+       clk_gpio = devm_gpiod_get(dev, CLOCK_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(clk_gpio))
+               return PTR_ERR(data_gpio);
+
+       /* Requesting the data gpio */
+       data_gpio = devm_gpiod_get(dev, DATA_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(data_gpio))
+               return PTR_ERR(data_gpio);
+
+       /* Requesting the clear gpio */
+       clr_gpio = devm_gpiod_get(dev, CLEAR_GPIO_NAME,
+               GPIOD_OUT_HIGH);
+       if (IS_ERR(clr_gpio))
+               return PTR_ERR(clr_gpio);
+
+       /* Start timer to update post code every second */
+       setup_timer(&update_timer, update_timer_handler, 0);
+       result = mod_timer(&update_timer,
+               jiffies + msecs_to_jiffies(POST_CODE_UPDATE_INTVL));
+
+       if (result)

drivers/misc/update-postcard.c line 203

Quoted 10 lines
drivers/misc/update-postcard.c new file +10 -0
+               return result;
+
+       mutex_init(&mutex);
+
+       return 0;
+}
+
+static void postcard_remove(struct platform_device *pdev)
+{
+       del_timer(&update_timer);

I think we want del_timer_sync here.

Quoted 22 lines
drivers/misc/update-postcard.c new file +16 -0
+}
+
+static struct platform_driver postcard_display_driver = {
+       .probe          = postcard_probe,
+       .shutdown       = postcard_remove,
+       .driver         = {
+               .name   = "postcard-display",
+               .of_match_table = of_postcard_match,
+       },
+};
+
+module_platform_driver(postcard_display_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <[email protected]>");
+MODULE_DESCRIPTION("Post card display update driver");
drivers/misc/update-postcard.h new file +0 -0
new file mode 100644
index 0000000..ef82e9091d

drivers/misc/update-postcard.h line 1

Quoted 1 line
drivers/misc/update-postcard.h new file +1 -0
@@ -0,0 +1 @@
+void update_postcode(char *buf);

Kernel style is to not have headers unless there is a requirement to export outside of a file. This should go in the c file.

Cheers,

Joel

#7 lore raw

PATCH 2/3 drivers: misc: Character driver to update BMC post code

In reply to Jaghathiswari Rankappagounder Natarajan

Character driver - On state change, the BMC will write its POST code to the character device. The POST code is then sent to update-postcard platform driver for display on the POST card. The BMC POST code consists of 3 digits

---
 drivers/misc/Kconfig               |   8 +++
 drivers/misc/Makefile              |   1 +
 drivers/misc/update-bmc-postcode.c | 123 +++++++++++++++++++++++++++++++++++++
 3 files changed, 132 insertions(+)
 create mode 100644 drivers/misc/update-bmc-postcode.c
drivers/misc/Kconfig +8 -0
index d65b83f..69dc3b6 100644
@@ -815,6 +815,14 @@ config ASPEED_BT_IPMI_HOST
 	help
 	  Support for the Aspeed BT ipmi host.
 
+config ASPEED_UPDATE_BMC_POSTCODE
+	tristate "Character driver for BMC POST code update"
+	depends on ASPEED_UPDATE_POSTCARD
+	help
+	 On state change, the BMC will write its POST code to the
+	 character device. The POST code is then sent to update-postcard platform
+	 driver for display on the POST card
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index 730c6c2..dce20cb 100644
@@ -59,3 +59,4 @@ obj-$(CONFIG_CXL_BASE)		+= cxl/
 obj-$(CONFIG_PANEL)             += panel.o
 obj-$(CONFIG_ASPEED_UPDATE_POSTCARD)    += update-postcard.o
 obj-$(CONFIG_ASPEED_BT_IPMI_HOST)	+= bt-host.o
+obj-$(CONFIG_ASPEED_UPDATE_BMC_POSTCODE)	+= update-bmc-postcode.o
drivers/misc/update-bmc-postcode.c new file +123 -0

123 lines not on this page · raw message

--
2.8.0.rc3.226.g39d4020

#8 lore raw

Re: [PATCH linux v1 2/3] drivers: misc: Character driver to update BMC post code

Quoted 29 lines · Jaghathiswari Rankappagounder Natarajan

Character driver - On state change, the BMC will write its POST code to the character device. The POST code is then sent to update-postcard platform driver for display on the POST card. The BMC POST code consists of 3 digits

---
 drivers/misc/Kconfig               |   8 +++
 drivers/misc/Makefile              |   1 +
 drivers/misc/update-bmc-postcode.c | 123 ++++++++++++++++++++++++++++++
+++++++
 3 files changed, 132 insertions(+)
 create mode 100644 drivers/misc/update-bmc-postcode.c
drivers/misc/Kconfig +6 -0
index d65b83f..69dc3b6 100644
@@ -815,6 +815,14 @@ config ASPEED_BT_IPMI_HOST
        help
          Support for the Aspeed BT ipmi host.
 
+config ASPEED_UPDATE_BMC_POSTCODE
+       tristate "Character driver for BMC POST code update"
+       depends on ASPEED_UPDATE_POSTCARD
+       help
+        On state change, the BMC will write its POST code to the
+        character device. The POST code is then sent to update-postcard

platform

drivers/misc/Kconfig config ASPEED_BT_IPMI_HOST · line 825

Quoted 2 lines
drivers/misc/Kconfig +2 -0
+        driver for display on the POST card
+

Again, not specific to Aspeed. Maybe this should be SEVEN_SEGMENT_DISPLAY and the other driver should be SEVEN_SEGMENT_SGPIO.

Quoted 76 lines

source "drivers/misc/c2port/Kconfig"
source "drivers/misc/eeprom/Kconfig"
source "drivers/misc/cb710/Kconfig"

drivers/misc/Makefile +1 -0
index 730c6c2..dce20cb 100644
@@ -59,3 +59,4 @@ obj-$(CONFIG_CXL_BASE)                += cxl/
 obj-$(CONFIG_PANEL)             += panel.o
 obj-$(CONFIG_ASPEED_UPDATE_POSTCARD)    += update-postcard.o
 obj-$(CONFIG_ASPEED_BT_IPMI_HOST)      += bt-host.o
+obj-$(CONFIG_ASPEED_UPDATE_BMC_POSTCODE)       += update-bmc-postcode.o
drivers/misc/update-bmc- renamed from drivers/misc/update-bmc-postcode.c +0 -0

postcode.c
new file mode 100644
index 0000000..8e368a4

drivers/misc/update-bmc-postcode.c new file +2 -0
@@ -0,0 +1,123 @@
+/*
+ * Character driver - On state change, the BMC will write its POST code

to the
+ * character device. The POST code is then sent to update-postcard platform
+ * driver for display on the POST card. The BMC POST code consists of 3 digits.
+ */

drivers/misc/update-bmc-postcode.c new file +48 -0
+
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/kdev_t.h>
+#include <linux/fs.h>
+#include <linux/device.h>
+#include <linux/cdev.h>
+#include <linux/uaccess.h>
+#include <linux/ctype.h>
+
+#include "update-postcard.h"
+
+#define MAX_POSTCODE_SIZE 3
+
+static dev_t bmc_state_dev;
+static struct cdev c_dev;
+static struct class *bmc_state_class;
+
+static int bmc_state_open(struct inode *i, struct file *f)
+{
+       return 0;
+}
+
+static int bmc_state_close(struct inode *i, struct file *f)
+{
+       return 0;
+}
+
+static ssize_t bmc_state_read(struct file *f, char __user *buf, size_t
+                               len, loff_t *off)
+{
+       return 0;
+}
+
+/* Write post code from bmc to the correct variable */
+static ssize_t bmc_state_write(struct file *f, const char __user *buf,
+                               size_t len, loff_t *off)
+{
+       char tmp[MAX_POSTCODE_SIZE];
+       int length = len - 1;
+       int i;
+
+       if (length != MAX_POSTCODE_SIZE) {
+               return -EINVAL;
+       }
+

drivers/misc/update-bmc-postcode.c line 63

Quoted 10 lines
drivers/misc/update-bmc-postcode.c new file +10 -0
+       if (copy_from_user(tmp, buf, length) != 0) {
+               return -EFAULT;
+       }
+
+       for (i = 0; i < MAX_POSTCODE_SIZE; i++) {
+               if (!isxdigit(tmp[i]))
+                       return -EINVAL;
+       }
+
+       update_postcode(tmp);

As written, this is hard-coded to the bit-bang driver in your other patch. The concept is fairly generic though. If we switched to using a 74HC165 that is compatible with the Aspeed's built-in SGPIO hardware, ideally we'd only need to write a driver for the SGPIO. That implies you want this character device to attach to any compatible display drivers.

Quoted 69 lines
drivers/misc/update-bmc-postcode.c new file +59 -0
+       return len;
+}
+
+static const struct file_operations bmc_state_fops = {
+
+       .owner = THIS_MODULE,
+       .open = bmc_state_open,
+       .release = bmc_state_close,
+       .read = bmc_state_read,
+       .write = bmc_state_write
+};
+
+static int __init update_bmc_pc_init(void)
+{
+       if (alloc_chrdev_region(&bmc_state_dev, 0, 1, "bmc_state") < 0) {
+               return -1;
+       }
+
+       bmc_state_class = class_create(THIS_MODULE, "bmc_state");
+       if (bmc_state_class == NULL) {
+               goto unregister;
+               return -1;
+       }
+
+       if (device_create(bmc_state_class, NULL, bmc_state_dev,
+               NULL, "current_state") == NULL) {
+               goto class_destroy;
+               return -1;
+       }
+
+       cdev_init(&c_dev, &bmc_state_fops);
+       if (cdev_add(&c_dev, bmc_state_dev, 1) == -1) {
+               goto device_destroy;
+               return -1;
+       }
+
+       return 0;
+
+device_destroy:
+               device_destroy(bmc_state_class, bmc_state_dev);
+class_destroy:
+               class_destroy(bmc_state_class);
+unregister:
+               unregister_chrdev_region(bmc_state_dev, 1);
+       return -1;
+}
+
+static void __exit update_bmc_pc_exit(void)
+{
+       cdev_del(&c_dev);
+       device_destroy(bmc_state_class, bmc_state_dev);
+       class_destroy(bmc_state_class);
+       unregister_chrdev_region(bmc_state_dev, 1);
+}
+
+module_init(update_bmc_pc_init);
+module_exit(update_bmc_pc_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <[email protected]
Quoted 1 line

");

+MODULE_DESCRIPTION("Character driver - update bmc postcode"); --
2.8.0.rc3.226.g39d4020

_______________________________________________
openbmc mailing list
[email protected]
https://lists.ozlabs.org/listinfo/openbmc

#9 lore raw

Re: [PATCH linux v1 2/3] drivers: misc: Character driver to update BMC post code

By this comment "want this character device to attach to any compatible display drivers." , should I have a separate setup_character device function(add the platform device(display driver for GPIO) as the parent of the character device) and call this function from the corresponding display driver for GPIO? So display driver for GPIO will only setup this character device ?

I have moved the function to convert character buffer to led display pattern to this char driver. The display is very specific for BMC post codes( characters '14' is displayed as digits 't4' and the DOT lights up on two segment LEDs ) and generic for host POST codes(characters '14' is displayed as '14' and DOT doesn't light up). This info is present in the lookup table.
When display driver for GPIO wants to use a character device with different conversion(say to display '14' as '14 with DOTs light up) it needs a different character device(which does conversion differently) ?

should the mapping be like this char device(with a specific display pattern) can be used with any display driver(GPIO and SGPIO) and the GPIO driver/SGPIO driver can use any character device(with different display conversion patterns) ? is it better to do as above or keep as 1-1 mapping? or keep the conversion logic in BMC/Host side?

Quoted 208 lines · Rick Altherr
Quoted 31 lines · Jaghathiswari Rankappagounder Natarajan

Character driver - On state change, the BMC will write its POST code to the
character device. The POST code is then sent to update-postcard platform driver for display on the POST card. The BMC POST code consists of 3 digits

---
 drivers/misc/Kconfig               |   8 +++
 drivers/misc/Makefile              |   1 +
 drivers/misc/update-bmc-postcode.c | 123 ++++++++++++++++++++++++++++++
+++++++
 3 files changed, 132 insertions(+)
 create mode 100644 drivers/misc/update-bmc-postcode.c
drivers/misc/Kconfig +6 -0
index d65b83f..69dc3b6 100644
@@ -815,6 +815,14 @@ config ASPEED_BT_IPMI_HOST
        help
          Support for the Aspeed BT ipmi host.
 
+config ASPEED_UPDATE_BMC_POSTCODE
+       tristate "Character driver for BMC POST code update"
+       depends on ASPEED_UPDATE_POSTCARD
+       help
+        On state change, the BMC will write its POST code to the
+        character device. The POST code is then sent to update-postcard

platform

drivers/misc/Kconfig config ASPEED_BT_IPMI_HOST · line 825

Quoted 2 lines
drivers/misc/Kconfig +2 -0
+        driver for display on the POST card
+

Again, not specific to Aspeed. Maybe this should be SEVEN_SEGMENT_DISPLAY and the other driver should be SEVEN_SEGMENT_SGPIO.

Quoted 76 lines

source "drivers/misc/c2port/Kconfig"
source "drivers/misc/eeprom/Kconfig"
source "drivers/misc/cb710/Kconfig"

drivers/misc/Makefile +1 -0
index 730c6c2..dce20cb 100644
@@ -59,3 +59,4 @@ obj-$(CONFIG_CXL_BASE)                += cxl/
 obj-$(CONFIG_PANEL)             += panel.o
 obj-$(CONFIG_ASPEED_UPDATE_POSTCARD)    += update-postcard.o
 obj-$(CONFIG_ASPEED_BT_IPMI_HOST)      += bt-host.o
+obj-$(CONFIG_ASPEED_UPDATE_BMC_POSTCODE)       += update-bmc-postcode.o
drivers/misc/update-bmc-postcode.c new file +2 -0
new file mode 100644
index 0000000..8e368a4
@@ -0,0 +1,123 @@
+/*
+ * Character driver - On state change, the BMC will write its POST code

to the
+ * character device. The POST code is then sent to update-postcard platform
+ * driver for display on the POST card. The BMC POST code consists of 3 digits.
+ */

drivers/misc/update-bmc-postcode.c new file +48 -0
+
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/kdev_t.h>
+#include <linux/fs.h>
+#include <linux/device.h>
+#include <linux/cdev.h>
+#include <linux/uaccess.h>
+#include <linux/ctype.h>
+
+#include "update-postcard.h"
+
+#define MAX_POSTCODE_SIZE 3
+
+static dev_t bmc_state_dev;
+static struct cdev c_dev;
+static struct class *bmc_state_class;
+
+static int bmc_state_open(struct inode *i, struct file *f)
+{
+       return 0;
+}
+
+static int bmc_state_close(struct inode *i, struct file *f)
+{
+       return 0;
+}
+
+static ssize_t bmc_state_read(struct file *f, char __user *buf, size_t
+                               len, loff_t *off)
+{
+       return 0;
+}
+
+/* Write post code from bmc to the correct variable */
+static ssize_t bmc_state_write(struct file *f, const char __user *buf,
+                               size_t len, loff_t *off)
+{
+       char tmp[MAX_POSTCODE_SIZE];
+       int length = len - 1;
+       int i;
+
+       if (length != MAX_POSTCODE_SIZE) {
+               return -EINVAL;
+       }
+

drivers/misc/update-bmc-postcode.c line 63

Quoted 10 lines
drivers/misc/update-bmc-postcode.c new file +10 -0
+       if (copy_from_user(tmp, buf, length) != 0) {
+               return -EFAULT;
+       }
+
+       for (i = 0; i < MAX_POSTCODE_SIZE; i++) {
+               if (!isxdigit(tmp[i]))
+                       return -EINVAL;
+       }
+
+       update_postcode(tmp);

As written, this is hard-coded to the bit-bang driver in your other patch. The concept is fairly generic though. If we switched to using a 74HC165 that is compatible with the Aspeed's built-in SGPIO hardware, ideally we'd only need to write a driver for the SGPIO. That implies you want this character device to attach to any compatible display drivers.

Quoted 69 lines
drivers/misc/update-bmc-postcode.c new file +59 -0
+       return len;
+}
+
+static const struct file_operations bmc_state_fops = {
+
+       .owner = THIS_MODULE,
+       .open = bmc_state_open,
+       .release = bmc_state_close,
+       .read = bmc_state_read,
+       .write = bmc_state_write
+};
+
+static int __init update_bmc_pc_init(void)
+{
+       if (alloc_chrdev_region(&bmc_state_dev, 0, 1, "bmc_state") < 0) {
+               return -1;
+       }
+
+       bmc_state_class = class_create(THIS_MODULE, "bmc_state");
+       if (bmc_state_class == NULL) {
+               goto unregister;
+               return -1;
+       }
+
+       if (device_create(bmc_state_class, NULL, bmc_state_dev,
+               NULL, "current_state") == NULL) {
+               goto class_destroy;
+               return -1;
+       }
+
+       cdev_init(&c_dev, &bmc_state_fops);
+       if (cdev_add(&c_dev, bmc_state_dev, 1) == -1) {
+               goto device_destroy;
+               return -1;
+       }
+
+       return 0;
+
+device_destroy:
+               device_destroy(bmc_state_class, bmc_state_dev);
+class_destroy:
+               class_destroy(bmc_state_class);
+unregister:
+               unregister_chrdev_region(bmc_state_dev, 1);
+       return -1;
+}
+
+static void __exit update_bmc_pc_exit(void)
+{
+       cdev_del(&c_dev);
+       device_destroy(bmc_state_class, bmc_state_dev);
+       class_destroy(bmc_state_class);
+       unregister_chrdev_region(bmc_state_dev, 1);
+}
+
+module_init(update_bmc_pc_init);
+module_exit(update_bmc_pc_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <[email protected]
Quoted 1 line

");

+MODULE_DESCRIPTION("Character driver - update bmc postcode"); --
2.8.0.rc3.226.g39d4020

_______________________________________________
openbmc mailing list
[email protected]
https://lists.ozlabs.org/listinfo/openbmc

#10 lore raw

Re: [PATCH linux v1 2/3] drivers: misc: Character driver to update BMC post code

Quoted 8 lines · Jaghathiswari Rankappagounder Natarajan

By this comment "want this character device to attach to any compatible display drivers." , should I have a separate setup_character device function(add the platform device(display driver for GPIO) as the parent of the character device) and call this function from the corresponding display driver for GPIO? So display driver for GPIO will only setup this character device ?

I'm getting confused by the terminology here. I would expect a platform

driver that matches on the device tree node, provides an API for displaying on a 7-segment display, and implements the bit-banging necessary to do so. The character device driver would match on the previous platform driver and implement the user-space API for letting a user write to the display including any conversion methods necessary to map the user input to a 7-segment display.

Quoted 11 lines

I have moved the function to convert character buffer to led display pattern to this char driver. The display is very specific for BMC post codes( characters '14' is displayed as digits 't4' and the DOT lights up on two segment LEDs ) and generic for host POST codes(characters '14' is displayed as '14' and DOT doesn't light up). This info is present in the lookup table.
When display driver for GPIO wants to use a character device with different conversion(say to display '14' as '14 with DOTs light up) it needs a different character device(which does conversion differently) ?

Yes, the conversion should be associated with the character device. My

rationale is that the conversion used depends on how the user provided the data (free form string, fixed string, integer). If the user API is different, it should have a different character device so the user-space app knows what API it needs to implement.

Quoted 7 lines

should the mapping be like this char device(with a specific display pattern) can be used with any display driver(GPIO and SGPIO) and the GPIO driver/SGPIO driver can use any character device(with different display conversion patterns) ? is it better to do as above or keep as 1-1 mapping? or keep the conversion logic in BMC/Host side?

I was thinking of having a subsystem layer that abstracts interfacing with 7-segment displays. It probably isn't necessary today but would make it simpler to implement other output drivers (using a different shift register with the Aspeed SGPIO hardware, etc) or implement different user-space APIs.

Quoted 214 lines · Rick Altherr
Quoted 211 lines
Quoted 32 lines · Jaghathiswari Rankappagounder Natarajan

Character driver - On state change, the BMC will write its POST code to the
character device. The POST code is then sent to update-postcard platform driver for display on the POST card. The BMC POST code consists of 3 digits

Quoted 1 line
---
 drivers/misc/Kconfig               |   8 +++
 drivers/misc/Makefile              |   1 +
 drivers/misc/update-bmc-postcode.c | 123 ++++++++++++++++++++++++++++++
+++++++
 3 files changed, 132 insertions(+)
 create mode 100644 drivers/misc/update-bmc-postcode.c
drivers/misc/Kconfig +6 -0
index d65b83f..69dc3b6 100644
@@ -815,6 +815,14 @@ config ASPEED_BT_IPMI_HOST
        help
          Support for the Aspeed BT ipmi host.
 
+config ASPEED_UPDATE_BMC_POSTCODE
+       tristate "Character driver for BMC POST code update"
+       depends on ASPEED_UPDATE_POSTCARD
+       help
+        On state change, the BMC will write its POST code to the
+        character device. The POST code is then sent to update-postcard

platform

drivers/misc/Kconfig config ASPEED_BT_IPMI_HOST · line 825

Quoted 2 lines
drivers/misc/Kconfig +2 -0
+        driver for display on the POST card
+

Again, not specific to Aspeed. Maybe this should be SEVEN_SEGMENT_DISPLAY and the other driver should be SEVEN_SEGMENT_SGPIO.

Quoted 76 lines

source "drivers/misc/c2port/Kconfig"
source "drivers/misc/eeprom/Kconfig"
source "drivers/misc/cb710/Kconfig"

drivers/misc/Makefile +1 -0
index 730c6c2..dce20cb 100644
@@ -59,3 +59,4 @@ obj-$(CONFIG_CXL_BASE)                += cxl/
 obj-$(CONFIG_PANEL)             += panel.o
 obj-$(CONFIG_ASPEED_UPDATE_POSTCARD)    += update-postcard.o
 obj-$(CONFIG_ASPEED_BT_IPMI_HOST)      += bt-host.o
+obj-$(CONFIG_ASPEED_UPDATE_BMC_POSTCODE)       += update-bmc-postcode.o
drivers/misc/update-bmc-postcode.c new file +2 -0
new file mode 100644
index 0000000..8e368a4
@@ -0,0 +1,123 @@
+/*
+ * Character driver - On state change, the BMC will write its POST code

to the
+ * character device. The POST code is then sent to update-postcard platform
+ * driver for display on the POST card. The BMC POST code consists of 3 digits.
+ */

drivers/misc/update-bmc-postcode.c new file +48 -0
+
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/kdev_t.h>
+#include <linux/fs.h>
+#include <linux/device.h>
+#include <linux/cdev.h>
+#include <linux/uaccess.h>
+#include <linux/ctype.h>
+
+#include "update-postcard.h"
+
+#define MAX_POSTCODE_SIZE 3
+
+static dev_t bmc_state_dev;
+static struct cdev c_dev;
+static struct class *bmc_state_class;
+
+static int bmc_state_open(struct inode *i, struct file *f)
+{
+       return 0;
+}
+
+static int bmc_state_close(struct inode *i, struct file *f)
+{
+       return 0;
+}
+
+static ssize_t bmc_state_read(struct file *f, char __user *buf, size_t
+                               len, loff_t *off)
+{
+       return 0;
+}
+
+/* Write post code from bmc to the correct variable */
+static ssize_t bmc_state_write(struct file *f, const char __user *buf,
+                               size_t len, loff_t *off)
+{
+       char tmp[MAX_POSTCODE_SIZE];
+       int length = len - 1;
+       int i;
+
+       if (length != MAX_POSTCODE_SIZE) {
+               return -EINVAL;
+       }
+

drivers/misc/update-bmc-postcode.c line 63

Quoted 10 lines
drivers/misc/update-bmc-postcode.c new file +10 -0
+       if (copy_from_user(tmp, buf, length) != 0) {
+               return -EFAULT;
+       }
+
+       for (i = 0; i < MAX_POSTCODE_SIZE; i++) {
+               if (!isxdigit(tmp[i]))
+                       return -EINVAL;
+       }
+
+       update_postcode(tmp);

As written, this is hard-coded to the bit-bang driver in your other patch. The concept is fairly generic though. If we switched to using a 74HC165 that is compatible with the Aspeed's built-in SGPIO hardware, ideally we'd only need to write a driver for the SGPIO. That implies you want this character device to attach to any compatible display drivers.

Quoted 70 lines
drivers/misc/update-bmc-postcode.c new file +15 -0
+       return len;
+}
+
+static const struct file_operations bmc_state_fops = {
+
+       .owner = THIS_MODULE,
+       .open = bmc_state_open,
+       .release = bmc_state_close,
+       .read = bmc_state_read,
+       .write = bmc_state_write
+};
+
+static int __init update_bmc_pc_init(void)
+{
+       if (alloc_chrdev_region(&bmc_state_dev, 0, 1, "bmc_state") < 0)

{

drivers/misc/update-bmc-postcode.c new file +44 -0
+               return -1;
+       }
+
+       bmc_state_class = class_create(THIS_MODULE, "bmc_state");
+       if (bmc_state_class == NULL) {
+               goto unregister;
+               return -1;
+       }
+
+       if (device_create(bmc_state_class, NULL, bmc_state_dev,
+               NULL, "current_state") == NULL) {
+               goto class_destroy;
+               return -1;
+       }
+
+       cdev_init(&c_dev, &bmc_state_fops);
+       if (cdev_add(&c_dev, bmc_state_dev, 1) == -1) {
+               goto device_destroy;
+               return -1;
+       }
+
+       return 0;
+
+device_destroy:
+               device_destroy(bmc_state_class, bmc_state_dev);
+class_destroy:
+               class_destroy(bmc_state_class);
+unregister:
+               unregister_chrdev_region(bmc_state_dev, 1);
+       return -1;
+}
+
+static void __exit update_bmc_pc_exit(void)
+{
+       cdev_del(&c_dev);
+       device_destroy(bmc_state_class, bmc_state_dev);
+       class_destroy(bmc_state_class);
+       unregister_chrdev_region(bmc_state_dev, 1);
+}
+
+module_init(update_bmc_pc_init);
+module_exit(update_bmc_pc_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <

[email protected]>");
+MODULE_DESCRIPTION("Character driver - update bmc postcode"); --
2.8.0.rc3.226.g39d4020

_______________________________________________
openbmc mailing list
[email protected]
https://lists.ozlabs.org/listinfo/openbmc

#11 lore raw

PATCH 3/3 devicetree : Add device tree info for POST card display on zaius

In reply to Jaghathiswari Rankappagounder Natarajan

Add clock, data and clear signal lines to control POST card display on zaius

---
 .../devicetree/bindings/misc/postcard-disp.txt         | 18 ++++++++++++++++++
 arch/arm/boot/dts/aspeed-bmc-opp-zaius.dts             |  8 ++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/postcard-disp.txt
Documentation/devicetree/bindings/misc/postcard-disp.txt new file +18 -0
new file mode 100644
index 0000000..164449e
@@ -0,0 +1,18 @@
+POST card display (two seven segment LEDs) connected to GPIO lines
+
+Required properties:
+- compatible : should be "postcard-display".
+- clk-gpios :  Should specify the GPIO pin connected to the Clock line on the POST card.
+- data-gpios : Should specify the GPIO pin connected to Data line on the POST card.
+- clear-gpios : Should specify the GPIO pin connected to Clear line on the POST card.
+
+Examples:
+
+#include <dt-bindings/gpio/gpio.h>
+
+postcard {
+	compatible = "postcard-display";
+	clk-gpios = <&gpio 0 GPIO_ACTIVE_LOW>;
+	data-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
+	clear-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
+};
arch/arm/boot/dts/aspeed-bmc-opp-zaius.dts +8 -0
index 4c4754b..d555ff1 100644
@@ -1,6 +1,7 @@
 /dts-v1/;
 
 #include "aspeed-g5.dtsi"
+#include <dt-bindings/gpio/aspeed-gpio.h>
 
 / {
 	model = "Zaius BMC";
@@ -58,6 +59,13 @@
 			};
 		};
 	};
+
+	postcard {
+		compatible = "postcard-display";
+		clk-gpios = <&gpio ASPEED_GPIO(J, 0) GPIO_ACTIVE_HIGH>;
+		data-gpios = <&gpio ASPEED_GPIO(J, 2) GPIO_ACTIVE_HIGH>;
+		clr-gpios = <&gpio ASPEED_GPIO(J, 1) GPIO_ACTIVE_HIGH>;
+	};
 };
 
 &uart5 {

--
2.8.0.rc3.226.g39d4020

#12 lore raw

Re: [PATCH linux v1 3/3] devicetree : Add device tree info for POST card display on zaius

Hi Jagha,

Documentation/devicetree/bindings/misc/postcard-disp.txt

Quoted 19 lines · Jaghathiswari Rankappagounder Natarajan

Add clock, data and clear signal lines to control POST card display on zaius

---
 .../devicetree/bindings/misc/postcard-disp.txt         | 18
++++++++++++++++++
 arch/arm/boot/dts/aspeed-bmc-opp-zaius.dts             |  8 ++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/postcard-disp.

txt

Documentation/devicetree/bindings/misc/postcard-disp.txt new file +0 -0
new file mode 100644
index 0000000..164449e

This doc file belongs in the same commit as the driver that it describes. The Zaius dts change should stand alone.

Quoted 8 lines
Documentation/devicetree/bindings/misc/postcard-disp.txt new file +5 -0
@@ -0,0 +1,18 @@
+POST card display (two seven segment LEDs) connected to GPIO lines
+
+Required properties:
+- compatible : should be "postcard-display".
+- clk-gpios :  Should specify the GPIO pin connected to the Clock line on

the POST card.

For consistency and readability, please don't abbreviate these names. We should use "clock-gpios" instead of "clk-gpios."

Quoted 5 lines

+- data-gpios : Should specify the GPIO pin connected to Data line on the POST card.
+- clear-gpios : Should specify the GPIO pin connected to Clear line on the POST card.

Ex. you wrote "clear-gpios" here but the code uses "clr-gpios," which looks visually similar to "clk-gpios."

Documentation/devicetree/bindings/misc/postcard-disp.txt line 17

Quoted 11 lines
Documentation/devicetree/bindings/misc/postcard-disp.txt new file +10 -0
+
+Examples:
+
+#include <dt-bindings/gpio/gpio.h>
+
+postcard {
+       compatible = "postcard-display";
+       clk-gpios = <&gpio 0 GPIO_ACTIVE_LOW>;
+       data-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
+       clear-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;

This uses the same gpio designator (1) as the second -gpios property. I know it's example code but...

Quoted 15 lines
Documentation/devicetree/bindings/misc/postcard-disp.txt new file +1 -0
+};
arch/arm/boot/dts/aspeed-bmc-opp-zaius.dts +1 -0
index 4c4754b..d555ff1 100644
@@ -1,6 +1,7 @@
 /dts-v1/;
 
 #include "aspeed-g5.dtsi"
+#include <dt-bindings/gpio/aspeed-gpio.h>
 
 / {
        model = "Zaius BMC";

arch/arm/boot/dts/aspeed-bmc-opp-zaius.dts line 68

Quoted 10 lines
arch/arm/boot/dts/aspeed-bmc-opp-zaius.dts +6 -0
@@ -58,6 +59,13 @@
                        };
                };
        };
+
+       postcard {
+               compatible = "postcard-display";
+               clk-gpios = <&gpio ASPEED_GPIO(J, 0) GPIO_ACTIVE_HIGH>;
+               data-gpios = <&gpio ASPEED_GPIO(J, 2) GPIO_ACTIVE_HIGH>;
+               clr-gpios = <&gpio ASPEED_GPIO(J, 1) GPIO_ACTIVE_HIGH>;
 

This property should match up to the documentation.

Quoted 7 lines
arch/arm/boot/dts/aspeed-bmc-opp-zaius.dts +1 -0
+       };
 };
 

&uart5 {
--
2.8.0.rc3.226.g39d4020

Quoted 5 lines

_______________________________________________
openbmc mailing list
[email protected]
https://lists.ozlabs.org/listinfo/openbmc

cheers
xo