^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * OPAL Operator Panel Display Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2016, Suraj Jitindar Singh, IBM Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/opal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * This driver creates a character device (/dev/op_panel) which exposes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * operator panel (character LCD display) on IBM Power Systems machines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * with FSPs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * A character buffer written to the device will be displayed on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * operator panel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static DEFINE_MUTEX(oppanel_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static u32 num_lines, oppanel_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static oppanel_line_t *oppanel_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static char *oppanel_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static loff_t oppanel_llseek(struct file *filp, loff_t offset, int whence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return fixed_size_llseek(filp, offset, whence, oppanel_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static ssize_t oppanel_read(struct file *filp, char __user *userbuf, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) loff_t *f_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return simple_read_from_buffer(userbuf, len, f_pos, oppanel_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) oppanel_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int __op_panel_update_display(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct opal_msg msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int rc, token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) token = opal_async_get_token_interruptible();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (token < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (token != -ERESTARTSYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) pr_debug("Couldn't get OPAL async token [token=%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) rc = opal_write_oppanel_async(token, oppanel_lines, num_lines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) switch (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) case OPAL_ASYNC_COMPLETION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) rc = opal_async_wait_response(token, &msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) pr_debug("Failed to wait for async response [rc=%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) rc = opal_get_async_rc(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (rc != OPAL_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) pr_debug("OPAL async call returned failed [rc=%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) case OPAL_SUCCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) pr_debug("OPAL write op-panel call failed [rc=%d]\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) opal_async_release_token(token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static ssize_t oppanel_write(struct file *filp, const char __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) size_t len, loff_t *f_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) loff_t f_pos_prev = *f_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (!*f_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) memset(oppanel_data, ' ', oppanel_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) else if (*f_pos >= oppanel_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return -EFBIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ret = simple_write_to_buffer(oppanel_data, oppanel_size, f_pos, userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) rc = __op_panel_update_display();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (rc != OPAL_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) pr_err_ratelimited("OPAL call failed to write to op panel display [rc=%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *f_pos = f_pos_prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int oppanel_open(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (!mutex_trylock(&oppanel_mutex)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) pr_debug("Device Busy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static int oppanel_release(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) mutex_unlock(&oppanel_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static const struct file_operations oppanel_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .llseek = oppanel_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .read = oppanel_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .write = oppanel_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .open = oppanel_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .release = oppanel_release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static struct miscdevice oppanel_dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .minor = MISC_DYNAMIC_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .name = "op_panel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .fops = &oppanel_fops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static int oppanel_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) u32 line_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) int rc, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) rc = of_property_read_u32(np, "#length", &line_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) pr_err_ratelimited("Operator panel length property not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) rc = of_property_read_u32(np, "#lines", &num_lines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) pr_err_ratelimited("Operator panel lines property not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) oppanel_size = line_len * num_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) pr_devel("Operator panel of size %u found with %u lines of length %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) oppanel_size, num_lines, line_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) oppanel_data = kcalloc(oppanel_size, sizeof(*oppanel_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (!oppanel_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) oppanel_lines = kcalloc(num_lines, sizeof(oppanel_line_t), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (!oppanel_lines) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) goto free_oppanel_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) memset(oppanel_data, ' ', oppanel_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) for (i = 0; i < num_lines; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) oppanel_lines[i].line_len = cpu_to_be64(line_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) oppanel_lines[i].line = cpu_to_be64(__pa(&oppanel_data[i *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) line_len]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) rc = misc_register(&oppanel_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) pr_err_ratelimited("Failed to register as misc device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) goto free_oppanel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) free_oppanel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) kfree(oppanel_lines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) free_oppanel_data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) kfree(oppanel_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static int oppanel_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) misc_deregister(&oppanel_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) kfree(oppanel_lines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) kfree(oppanel_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static const struct of_device_id oppanel_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) { .compatible = "ibm,opal-oppanel" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static struct platform_driver oppanel_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) .name = "powernv-op-panel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) .of_match_table = oppanel_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) .probe = oppanel_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .remove = oppanel_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) module_platform_driver(oppanel_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) MODULE_DEVICE_TABLE(of, oppanel_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) MODULE_DESCRIPTION("PowerNV Operator Panel LCD Display Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) MODULE_AUTHOR("Suraj Jitindar Singh <sjitindarsingh@gmail.com>");