<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 12, 2016 at 5:41 PM, Jaghathiswari Rankappagounder Natarajan <span dir="ltr"><<a href="mailto:jaghu@google.com" target="_blank">jaghu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Character driver - On state change, the BMC will write its POST code to the<br>
character device. The POST code is then sent to update-postcard platform<br>
driver for display on the POST card. The BMC POST code consists of 3 digits<br>
<br>
Signed-off-by: Jaghathiswari Rankappagounder Natarajan <<a href="mailto:jaghu@google.com">jaghu@google.com</a>><br>
---<br>
 drivers/misc/Kconfig               |   8 +++<br>
 drivers/misc/Makefile              |   1 +<br>
 drivers/misc/update-bmc-<wbr>postcode.c | 123 ++++++++++++++++++++++++++++++<wbr>+++++++<br>
 3 files changed, 132 insertions(+)<br>
 create mode 100644 drivers/misc/update-bmc-<wbr>postcode.c<br>
<br>
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig<br>
index d65b83f..69dc3b6 100644<br>
--- a/drivers/misc/Kconfig<br>
+++ b/drivers/misc/Kconfig<br>
@@ -815,6 +815,14 @@ config ASPEED_BT_IPMI_HOST<br>
        help<br>
          Support for the Aspeed BT ipmi host.<br>
<br>
+config ASPEED_UPDATE_BMC_POSTCODE<br>
+       tristate "Character driver for BMC POST code update"<br>
+       depends on ASPEED_UPDATE_POSTCARD<br>
+       help<br>
+        On state change, the BMC will write its POST code to the<br>
+        character device. The POST code is then sent to update-postcard platform<br>
+        driver for display on the POST card<br>
+<br></blockquote><div><br></div><div>Again, not specific to Aspeed.  Maybe this should be SEVEN_SEGMENT_DISPLAY and the other driver should be SEVEN_SEGMENT_SGPIO.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 source "drivers/misc/c2port/Kconfig"<br>
 source "drivers/misc/eeprom/Kconfig"<br>
 source "drivers/misc/cb710/Kconfig"<br>
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile<br>
index 730c6c2..dce20cb 100644<br>
--- a/drivers/misc/Makefile<br>
+++ b/drivers/misc/Makefile<br>
@@ -59,3 +59,4 @@ obj-$(CONFIG_CXL_BASE)                += cxl/<br>
 obj-$(CONFIG_PANEL)             += panel.o<br>
 obj-$(CONFIG_ASPEED_UPDATE_<wbr>POSTCARD)    += update-postcard.o<br>
 obj-$(CONFIG_ASPEED_BT_IPMI_<wbr>HOST)      += bt-host.o<br>
+obj-$(CONFIG_ASPEED_UPDATE_<wbr>BMC_POSTCODE)       += update-bmc-postcode.o<br>
diff --git a/drivers/misc/update-bmc-<wbr>postcode.c b/drivers/misc/update-bmc-<wbr>postcode.c<br>
new file mode 100644<br>
index 0000000..8e368a4<br>
--- /dev/null<br>
+++ b/drivers/misc/update-bmc-<wbr>postcode.c<br>
@@ -0,0 +1,123 @@<br>
+/*<br>
+ * Character driver - On state change, the BMC will write its POST code to the<br>
+ * character device. The POST code is then sent to update-postcard platform<br>
+ * driver for display on the POST card. The BMC POST code consists of 3 digits.<br>
+ */<br>
+<br>
+#include <linux/module.h><br>
+#include <linux/version.h><br>
+#include <linux/kernel.h><br>
+#include <linux/types.h><br>
+#include <linux/kdev_t.h><br>
+#include <linux/fs.h><br>
+#include <linux/device.h><br>
+#include <linux/cdev.h><br>
+#include <linux/uaccess.h><br>
+#include <linux/ctype.h><br>
+<br>
+#include "update-postcard.h"<br>
+<br>
+#define MAX_POSTCODE_SIZE 3<br>
+<br>
+static dev_t bmc_state_dev;<br>
+static struct cdev c_dev;<br>
+static struct class *bmc_state_class;<br>
+<br>
+static int bmc_state_open(struct inode *i, struct file *f)<br>
+{<br>
+       return 0;<br>
+}<br>
+<br>
+static int bmc_state_close(struct inode *i, struct file *f)<br>
+{<br>
+       return 0;<br>
+}<br>
+<br>
+static ssize_t bmc_state_read(struct file *f, char __user *buf, size_t<br>
+                               len, loff_t *off)<br>
+{<br>
+       return 0;<br>
+}<br>
+<br>
+/* Write post code from bmc to the correct variable */<br>
+static ssize_t bmc_state_write(struct file *f, const char __user *buf,<br>
+                               size_t len, loff_t *off)<br>
+{<br>
+       char tmp[MAX_POSTCODE_SIZE];<br>
+       int length = len - 1;<br>
+       int i;<br>
+<br>
+       if (length != MAX_POSTCODE_SIZE) {<br>
+               return -EINVAL;<br>
+       }<br>
+<br>
+       if (copy_from_user(tmp, buf, length) != 0) {<br>
+               return -EFAULT;<br>
+       }<br>
+<br>
+       for (i = 0; i < MAX_POSTCODE_SIZE; i++) {<br>
+               if (!isxdigit(tmp[i]))<br>
+                       return -EINVAL;<br>
+       }<br>
+<br>
+       update_postcode(tmp);<br></blockquote><div><br></div><div>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.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+       return len;<br>
+}<br>
+<br>
+static const struct file_operations bmc_state_fops = {<br>
+<br>
+       .owner = THIS_MODULE,<br>
+       .open = bmc_state_open,<br>
+       .release = bmc_state_close,<br>
+       .read = bmc_state_read,<br>
+       .write = bmc_state_write<br>
+};<br>
+<br>
+static int __init update_bmc_pc_init(void)<br>
+{<br>
+       if (alloc_chrdev_region(&bmc_<wbr>state_dev, 0, 1, "bmc_state") < 0) {<br>
+               return -1;<br>
+       }<br>
+<br>
+       bmc_state_class = class_create(THIS_MODULE, "bmc_state");<br>
+       if (bmc_state_class == NULL) {<br>
+               goto unregister;<br>
+               return -1;<br>
+       }<br>
+<br>
+       if (device_create(bmc_state_<wbr>class, NULL, bmc_state_dev,<br>
+               NULL, "current_state") == NULL) {<br>
+               goto class_destroy;<br>
+               return -1;<br>
+       }<br>
+<br>
+       cdev_init(&c_dev, &bmc_state_fops);<br>
+       if (cdev_add(&c_dev, bmc_state_dev, 1) == -1) {<br>
+               goto device_destroy;<br>
+               return -1;<br>
+       }<br>
+<br>
+       return 0;<br>
+<br>
+device_destroy:<br>
+               device_destroy(bmc_state_<wbr>class, bmc_state_dev);<br>
+class_destroy:<br>
+               class_destroy(bmc_state_class)<wbr>;<br>
+unregister:<br>
+               unregister_chrdev_region(bmc_<wbr>state_dev, 1);<br>
+       return -1;<br>
+}<br>
+<br>
+static void __exit update_bmc_pc_exit(void)<br>
+{<br>
+       cdev_del(&c_dev);<br>
+       device_destroy(bmc_state_<wbr>class, bmc_state_dev);<br>
+       class_destroy(bmc_state_class)<wbr>;<br>
+       unregister_chrdev_region(bmc_<wbr>state_dev, 1);<br>
+}<br>
+<br>
+module_init(update_bmc_pc_<wbr>init);<br>
+module_exit(update_bmc_pc_<wbr>exit);<br>
+MODULE_LICENSE("GPL");<br>
+MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <<a href="mailto:jaghu@google.com">jaghu@google.com</a>>");<br>
+MODULE_DESCRIPTION("Character driver - update bmc postcode");<br>
--<br>
2.8.0.rc3.226.g39d4020<br>
<br>
______________________________<wbr>_________________<br>
openbmc mailing list<br>
<a href="mailto:openbmc@lists.ozlabs.org">openbmc@lists.ozlabs.org</a><br>
<a href="https://lists.ozlabs.org/listinfo/openbmc" rel="noreferrer" target="_blank">https://lists.ozlabs.org/<wbr>listinfo/openbmc</a><br>
</blockquote></div><br></div></div>