From patchwork Thu Sep 20 08:41:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 972233 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RSKQY2q0"; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42G9F43jrxz9sBv; Thu, 20 Sep 2018 18:41:28 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1g2uWY-0006U8-KL; Thu, 20 Sep 2018 08:41:22 +0000 Received: from mail-ed1-f67.google.com ([209.85.208.67]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1g2uWW-0006Ti-1W for kernel-team@lists.ubuntu.com; Thu, 20 Sep 2018 08:41:20 +0000 Received: by mail-ed1-f67.google.com with SMTP id s10-v6so7122539edb.11 for ; Thu, 20 Sep 2018 01:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=l6COz5YEvGuXkPX01ZbbS8iie0H909vKisn+JLnegtw=; b=RSKQY2q0Eu3vRcdpj+ufa/cwrYLlbILOabQfEoPQvQP3xEBBCwS/LHro/Ny768cXi6 GTVIS/cmcqsfLIIv/8FA3tmI/qipZLO8Uuo9s4Z73qrrLguIs0wWC212ARC5A45Iv1gv Iq28O0IiBO5PvycIpmn8LEb5g+L1/SfNhAmjlObw1s801BPuqxoY+l5cqGeGhGFaH3A2 hqPLx4aQTEVTiTD4GTCpRiA3xJ1T5QxNhiUfz8xLfWO1IcvWN8xr72NmoCqDUWBeh5Lr asg4FA9solvjfXdM85w7pvoyWBsql92eCZJiRtU6NBAKKwA41rrGRVwGRh8ejwjextWS R+fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=l6COz5YEvGuXkPX01ZbbS8iie0H909vKisn+JLnegtw=; b=myQA9czDUhbeGNZU3+e4OrRXHCEhS0rbmpXcoKHv6zXcDVxVdmO5MrJSC3jM4aIWL8 wCxprAz6gx/80cjhEkRVVAe0kXoeVYrtt5SnPIbqkVW3nU1uGqWjQ1+n1xfZ7JZHud+h CuAWe1dXBXziVlvt4yk/J2B7mGxUGQgQfwXn0u1vYVm2i1h0X7FwJrtB4wo8wTorBi6v 0N+4HgQHS/m2P+04Rmt4YpqtmuSOgB/WcGdn6r5fzPbo6kI/EQyrGuWa5gnLKCAQne9V ah5n64XcWslp7U6I6427Y9rrCP1U3zT0p0LyJfwe7sHTiUIlO37gwMCjJblDOxpC8O83 FPbA== X-Gm-Message-State: APzg51D7c7hFU1I1JFTq2pDWpCMTgrTGDkrmj3RMLJCWKUcFB+kSD1mQ qZKoxG0SASxEo/p+oWKeBR9LgVVYIzM= X-Google-Smtp-Source: ANB0VdZi8SyJ+CZcyUzxtc+x/peKc55qXqoPNsM3B0pPBZgX4BOgRfUQMy3kW2QzDqAiu0xQTNFgrw== X-Received: by 2002:a50:aba3:: with SMTP id u32-v6mr2786001edc.257.1537432878570; Thu, 20 Sep 2018 01:41:18 -0700 (PDT) Received: from localhost (84-199-88-153.iFiber.telenet-ops.be. [84.199.88.153]) by smtp.gmail.com with ESMTPSA id i19-v6sm600929edg.64.2018.09.20.01.41.17 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 01:41:17 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH v4 1/2][SRU][Bionic]UBUNTU: SAUCE: platform/x86: dell-uart-backlight: new backlight driver for DELL AIO Date: Thu, 20 Sep 2018 16:41:14 +0800 Message-Id: <20180920084115.1895-2-acelan.kao@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920084115.1895-1-acelan.kao@canonical.com> References: <20180920084115.1895-1-acelan.kao@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/1727235 The Dell AIO machines released after 2017 come with a UART interface to communicate with the backlight scalar board. This driver creates a standard backlight interface and talks to the scalar board through UART. In DSDT this uart port will be defined as Name (_HID, "DELL0501") Name (_CID, EisaId ("PNP0501") The 8250 PNP driver will be loaded by default, and this driver uses "DELL0501" to confirm the uart port is a backlight interface and leverage the port created by 8250 PNP driver to communicate with the scalar board. v2: 1. move struct uart_cmd to .c file 2. make dell_uart_get_bl_power() inline 3. add space to ternary operator "bl_cmd->cmd[2] = power ? 0 : 1;" 4. check return value of kzalloc() 5. add kzfree() 6. check return value of backlight_device_register() 7. check return value of filp_open() at init v3: 1. Fix compiling warning. v4: 1. make *tty and *ftty static 2. bl_cmd->ret[0] will never be less than 0, fixed the if statement 3. fix some line over 80 chars warnings. Signed-off-by: AceLan Kao --- drivers/platform/x86/Kconfig | 14 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/dell-uart-backlight.c | 471 +++++++++++++++++++++ drivers/platform/x86/dell-uart-backlight.h | 36 ++ 4 files changed, 522 insertions(+) create mode 100644 drivers/platform/x86/dell-uart-backlight.c create mode 100644 drivers/platform/x86/dell-uart-backlight.h diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index b6ac37a5d06d..b6ce1a5b01e5 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -199,6 +199,20 @@ config DELL_RBTN To compile this driver as a module, choose M here: the module will be called dell-rbtn. +config DELL_UART_BACKLIGHT + tristate "Dell AIO UART Backlight driver" + depends on SERIAL_8250 + depends on ACPI + ---help--- + Say Y here if you want to support Dell AIO UART backlight interface. + The Dell AIO machines released after 2017 come with a UART interface + to communicate with the backlight scalar board. This driver creates + a standard backlight interface and talks to the scalar board through + UART to adjust the AIO screen brightness. + + To compile this driver as a module, choose M here: the module will + be called dell_uart_backlight. + config FUJITSU_LAPTOP tristate "Fujitsu Laptop Extras" diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index c32b34a72467..85329fd26afd 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -22,6 +22,7 @@ obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o obj-$(CONFIG_DELL_SMO8800) += dell-smo8800.o obj-$(CONFIG_DELL_RBTN) += dell-rbtn.o +obj-$(CONFIG_DELL_UART_BACKLIGHT) += dell-uart-backlight.o obj-$(CONFIG_ACER_WMI) += acer-wmi.o obj-$(CONFIG_ACERHDF) += acerhdf.o obj-$(CONFIG_HP_ACCEL) += hp_accel.o diff --git a/drivers/platform/x86/dell-uart-backlight.c b/drivers/platform/x86/dell-uart-backlight.c new file mode 100644 index 000000000000..ce9a5e200af8 --- /dev/null +++ b/drivers/platform/x86/dell-uart-backlight.c @@ -0,0 +1,471 @@ +/* + * Dell AIO Serial Backlight Driver + * + * Copyright (C) 2017 AceLan Kao + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "dell-uart-backlight.h" + +struct dell_uart_backlight { + struct device *dev; + struct backlight_device *dell_uart_bd; + struct mutex brightness_mutex; + int line; + int bl_power; +}; +struct uart_8250_port *serial8250_get_port(int line); +static struct tty_struct *tty; +static struct file *ftty; + +unsigned int (*io_serial_in)(struct uart_port *p, int offset); +int (*uart_write)(struct tty_struct *tty, const unsigned char *buf, int count); +int (*uart_chars_in_buffer)(struct tty_struct *tty); + +static struct dell_uart_bl_cmd uart_cmd[] = { + /* + * Get Firmware Version: Tool uses this command to get firmware version. + * Command: 0x6A 0x06 0x8F (Length:3 Type: 0x0A, Cmd:6 Checksum:0x8F) + * Return data: 0x0D 0x06 Data checksum (Length:13,Cmd:0x06, + * Data :F/W version(APRILIA=APR27-VXXX,PHINE=PHI23-VXXX), + * checksum:SUM(Length and Cmd and Data)xor 0xFF . + */ + [DELL_UART_GET_FIRMWARE_VER] = { + .cmd = {0x6A, 0x06, 0x8F}, + .tx_len = 3, + }, + /* + * Get Brightness level: Application uses this command for scaler to + * get brightness. + * Command: 0x6A 0x0C 0x89 + * (Length:3 Type: 0x0A, Cmd:0x0C, Checksum:0x89) + * Return data: 0x04 0x0C Data checksum + * (Length:4 Cmd: 0x0C Data: brightness level + * checksum: SUM(Length and Cmd and Data)xor 0xFF) + * brightness level which ranges from 0~100. + */ + [DELL_UART_GET_BRIGHTNESS] = { + .cmd = {0x6A, 0x0C, 0x89}, + .ret = {0x04, 0x0C, 0x00, 0x00}, + .tx_len = 3, + .rx_len = 4, + }, + /* Set Brightness level: Application uses this command for scaler to + * set brightness. + * Command: 0x8A 0x0B Byte2 Checksum (Length:4 Type: 0x0A, Cmd:0x0B) + * where Byte2 is the brightness level which ranges from 0~100. + * Return data: 0x03 0x0B 0xF1(Length:3,Cmd:B,checksum:0xF1) + * Scaler must send the 3bytes ack within 1 second when success, + * other value if error + */ + [DELL_UART_SET_BRIGHTNESS] = { + .cmd = {0x8A, 0x0B, 0x0, 0x0}, + .ret = {0x03, 0x0B, 0xF1}, + .tx_len = 4, + .rx_len = 3, + }, + /* + * Screen ON/OFF Control: Application uses this command to control + * screen ON or OFF. + * Command: 0x8A 0x0E Byte2 Checksum (Length:4 Type: 0x0A, Cmd:0x0E) + * where + * Byte2=0 to turn OFF the screen. + * Byte2=1 to turn ON the screen + * Other value of Byte2 is reserved and invalid. + * Return data: 0x03 0x0E 0xEE(Length:3,Cmd:E,checksum:0xEE) + */ + [DELL_UART_SET_BACKLIGHT_POWER] = { + .cmd = {0x8A, 0x0E, 0x00, 0x0}, + .ret = {0x03, 0x0E, 0xEE}, + .tx_len = 4, + .rx_len = 3, + }, +}; + +static int dell_uart_write(struct uart_8250_port *up, __u8 *buf, int len) +{ + int actual = 0; + struct uart_port *port = &up->port; + + tty_port_tty_wakeup(&port->state->port); + tty = tty_port_tty_get(&port->state->port); + actual = uart_write(tty, buf, len); + while (uart_chars_in_buffer(tty)) + udelay(10); + + return actual; +} + +static int dell_uart_read(struct uart_8250_port *up, __u8 *buf, int len) +{ + int i, retry; + unsigned long flags; + + spin_lock_irqsave(&up->port.lock, flags); + for (i = 0; i < len; i++) { + retry = 10; + while (!(io_serial_in(&up->port, UART_LSR) & UART_LSR_DR)) { + if (--retry == 0) + break; + mdelay(20); + } + + if (retry == 0) + break; + buf[i] = io_serial_in(&up->port, UART_RX); + } + spin_unlock_irqrestore(&up->port.lock, flags); + + return i; +} + +static void dell_uart_dump_cmd(const char *func, const char *prefix, + const char *cmd, int len) +{ + char buf[80]; + + snprintf(buf, 80, "dell_uart_backlight:%s:%s", func, prefix); + if (len != 0) + print_hex_dump_debug(buf, DUMP_PREFIX_NONE, + 16, 1, cmd, len, false); + else + pr_debug("dell_uart_backlight:%s:%sNULL\n", func, prefix); + +} + +/* + * checksum: SUM(Length and Cmd and Data)xor 0xFF) + */ +static unsigned char dell_uart_checksum(unsigned char *buf, int len) +{ + unsigned char val = 0; + + while (len-- > 0) + val += buf[len]; + + return val ^ 0xff; +} + +/* + * There is no command to get backlight power status, + * so we set the backlight power to "on" while initializing, + * and then track and report its status by bl_power variable + */ +static inline int dell_uart_get_bl_power(struct dell_uart_backlight *dell_pdata) +{ + return dell_pdata->bl_power; +} + +static int dell_uart_set_bl_power(struct backlight_device *bd, int power) +{ + struct dell_uart_bl_cmd *bl_cmd = + &uart_cmd[DELL_UART_SET_BACKLIGHT_POWER]; + struct dell_uart_backlight *dell_pdata = bl_get_data(bd); + struct uart_8250_port *uart = serial8250_get_port(dell_pdata->line); + int rx_len; + + if (power != FB_BLANK_POWERDOWN) + power = FB_BLANK_UNBLANK; + + bl_cmd->cmd[2] = power ? 0 : 1; + bl_cmd->cmd[3] = dell_uart_checksum(bl_cmd->cmd, bl_cmd->tx_len - 1); + + dell_uart_dump_cmd(__func__, "tx: ", bl_cmd->cmd, bl_cmd->tx_len); + + if (mutex_lock_killable(&dell_pdata->brightness_mutex) < 0) { + pr_debug("Failed to get mutex_lock"); + return 0; + } + + dell_uart_write(uart, bl_cmd->cmd, bl_cmd->tx_len); + rx_len = dell_uart_read(uart, bl_cmd->ret, bl_cmd->rx_len); + + mutex_unlock(&dell_pdata->brightness_mutex); + + dell_uart_dump_cmd(__func__, "rx: ", bl_cmd->ret, rx_len); + + bd->props.power = power; + dell_pdata->bl_power = power; + + return 0; +} + +static int dell_uart_get_brightness(struct backlight_device *bd) +{ + struct dell_uart_bl_cmd *bl_cmd = &uart_cmd[DELL_UART_GET_BRIGHTNESS]; + struct dell_uart_backlight *dell_pdata = bl_get_data(bd); + struct uart_8250_port *uart = serial8250_get_port(dell_pdata->line); + int rx_len, brightness = 0; + + dell_uart_dump_cmd(__func__, "tx: ", bl_cmd->cmd, bl_cmd->tx_len); + + if (mutex_lock_killable(&dell_pdata->brightness_mutex) < 0) { + pr_debug("Failed to get mutex_lock"); + return 0; + } + + dell_uart_write(uart, bl_cmd->cmd, bl_cmd->tx_len); + rx_len = dell_uart_read(uart, bl_cmd->ret, bl_cmd->rx_len); + + mutex_unlock(&dell_pdata->brightness_mutex); + + dell_uart_dump_cmd(__func__, "rx: ", bl_cmd->ret, rx_len); + + brightness = (unsigned int)bl_cmd->ret[2]; + + return brightness; +} + +static int dell_uart_update_status(struct backlight_device *bd) +{ + struct dell_uart_bl_cmd *bl_cmd = &uart_cmd[DELL_UART_SET_BRIGHTNESS]; + struct dell_uart_backlight *dell_pdata = bl_get_data(bd); + struct uart_8250_port *uart = serial8250_get_port(dell_pdata->line); + int rx_len; + + bl_cmd->cmd[2] = bd->props.brightness; + bl_cmd->cmd[3] = dell_uart_checksum(bl_cmd->cmd, bl_cmd->tx_len - 1); + + dell_uart_dump_cmd(__func__, "tx: ", bl_cmd->cmd, bl_cmd->tx_len); + + if (mutex_lock_killable(&dell_pdata->brightness_mutex) < 0) { + pr_debug("Failed to get mutex_lock"); + return 0; + } + + dell_uart_write(uart, bl_cmd->cmd, bl_cmd->tx_len); + rx_len = dell_uart_read(uart, bl_cmd->ret, bl_cmd->rx_len); + + mutex_unlock(&dell_pdata->brightness_mutex); + + dell_uart_dump_cmd(__func__, "rx: ", bl_cmd->ret, rx_len); + + if (bd->props.power != dell_uart_get_bl_power(dell_pdata)) + dell_uart_set_bl_power(bd, bd->props.power); + + return 0; +} + +static int dell_uart_get_scalar_status(struct dell_uart_backlight *dell_pdata) +{ + struct dell_uart_bl_cmd *bl_cmd = &uart_cmd[DELL_UART_GET_SCALAR]; + struct uart_8250_port *uart = serial8250_get_port(dell_pdata->line); + int rx_len; + /* assume the scalar IC controls backlight if the command failed */ + int status = 1; + + dell_uart_dump_cmd(__func__, "tx: ", bl_cmd->cmd, bl_cmd->tx_len); + + if (mutex_lock_killable(&dell_pdata->brightness_mutex) < 0) { + pr_debug("Failed to get mutex_lock"); + return 0; + } + + dell_uart_write(uart, bl_cmd->cmd, bl_cmd->tx_len); + rx_len = dell_uart_read(uart, bl_cmd->ret, bl_cmd->rx_len); + + mutex_unlock(&dell_pdata->brightness_mutex); + + dell_uart_dump_cmd(__func__, "rx: ", bl_cmd->ret, rx_len); + + if (rx_len == 4) + status = (unsigned int)bl_cmd->ret[2]; + + return status; +} + +static int dell_uart_show_firmware_ver(struct dell_uart_backlight *dell_pdata) +{ + struct dell_uart_bl_cmd *bl_cmd = &uart_cmd[DELL_UART_GET_FIRMWARE_VER]; + struct uart_8250_port *uart = serial8250_get_port(dell_pdata->line); + int rx_len = 0, retry = 10; + + dell_uart_dump_cmd(__func__, "tx: ", bl_cmd->cmd, bl_cmd->tx_len); + + if (mutex_lock_killable(&dell_pdata->brightness_mutex) < 0) { + pr_debug("Failed to get mutex_lock"); + return -1; + } + + dell_uart_write(uart, bl_cmd->cmd, bl_cmd->tx_len); + while (retry-- > 0) { + /* first byte is data length */ + dell_uart_read(uart, bl_cmd->ret, 1); + rx_len = (int)bl_cmd->ret[0]; + if (bl_cmd->ret[0] > 80 || bl_cmd->ret[0] == 0) { + pr_debug("Failed to get firmware version\n"); + if (retry == 0) { + mutex_unlock(&dell_pdata->brightness_mutex); + return -1; + } + msleep(100); + continue; + } + + dell_uart_read(uart, bl_cmd->ret+1, rx_len-1); + break; + } + mutex_unlock(&dell_pdata->brightness_mutex); + + dell_uart_dump_cmd(__func__, "rx: ", bl_cmd->ret, rx_len); + + pr_debug("Firmare str(%d)= %s\n", (int)bl_cmd->ret[0], bl_cmd->ret+2); + return rx_len; +} + +static const struct backlight_ops dell_uart_backlight_ops = { + .get_brightness = dell_uart_get_brightness, + .update_status = dell_uart_update_status, +}; + +static int dell_uart_startup(struct dell_uart_backlight *dell_pdata) +{ + struct uart_8250_port *uartp; + struct uart_port *port; + + dell_pdata->line = 0; + uartp = serial8250_get_port(dell_pdata->line); + port = &uartp->port; + tty = port->state->port.tty; + io_serial_in = port->serial_in; + uart_write = tty->driver->ops->write; + uart_chars_in_buffer = tty->driver->ops->chars_in_buffer; + + return 0; +} + +static int dell_uart_bl_add(struct acpi_device *dev) +{ + struct dell_uart_backlight *dell_pdata; + struct backlight_properties props; + struct backlight_device *dell_uart_bd; + + dell_pdata = kzalloc(sizeof(struct dell_uart_backlight), GFP_KERNEL); + if (!dell_pdata) { + pr_debug("Failed to allocate memory for dell_uart_backlight\n"); + return -1; + } + dell_pdata->dev = &dev->dev; + dell_uart_startup(dell_pdata); + dev->driver_data = dell_pdata; + + mutex_init(&dell_pdata->brightness_mutex); + + if (!dell_uart_get_scalar_status(dell_pdata)) { + udelay(50); + /* try another command to make sure there is no scalar IC */ + if (dell_uart_show_firmware_ver(dell_pdata) <= 0) { + pr_debug("Scalar is not in charge of brightness adjustment.\n"); + kzfree(dell_pdata); + return -1; + } + } + + memset(&props, 0, sizeof(struct backlight_properties)); + props.type = BACKLIGHT_PLATFORM; + props.max_brightness = 100; + + dell_uart_bd = backlight_device_register("dell_uart_backlight", + &dev->dev, + dell_pdata, + &dell_uart_backlight_ops, + &props); + if (IS_ERR(dell_uart_bd)) { + kzfree(dell_pdata); + pr_debug("Backlight registration failed\n"); + return -1; + } + + dell_pdata->dell_uart_bd = dell_uart_bd; + + dell_uart_set_bl_power(dell_uart_bd, FB_BLANK_UNBLANK); + dell_uart_bd->props.brightness = 100; + backlight_update_status(dell_uart_bd); + + /* unregister acpi backlight interface */ + acpi_video_set_dmi_backlight_type(acpi_backlight_vendor); + + return 0; +} + +static int dell_uart_bl_remove(struct acpi_device *dev) +{ + struct dell_uart_backlight *dell_pdata = dev->driver_data; + + backlight_device_unregister(dell_pdata->dell_uart_bd); + kzfree(dell_pdata); + + return 0; +} + +static int dell_uart_bl_suspend(struct device *dev) +{ + filp_close(ftty, NULL); + return 0; +} + +static int dell_uart_bl_resume(struct device *dev) +{ + ftty = filp_open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY, 0); + return 0; +} + +static SIMPLE_DEV_PM_OPS(dell_uart_bl_pm, dell_uart_bl_suspend, dell_uart_bl_resume); + +static const struct acpi_device_id dell_uart_bl_ids[] = { + {"DELL0501", 0}, + {"", 0}, +}; + +static struct acpi_driver dell_uart_backlight_driver = { + .name = "Dell AIO serial backlight", + .ids = dell_uart_bl_ids, + .ops = { + .add = dell_uart_bl_add, + .remove = dell_uart_bl_remove, + }, + .drv.pm = &dell_uart_bl_pm, +}; + +static int __init dell_uart_bl_init(void) +{ + ftty = filp_open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY, 0); + if (IS_ERR(ftty)) { + pr_debug("cannot open /dev/ttyS0\n"); + return -EINVAL; + } + + return acpi_bus_register_driver(&dell_uart_backlight_driver); +} + +static void __exit dell_uart_bl_exit(void) +{ + filp_close(ftty, NULL); + + acpi_bus_unregister_driver(&dell_uart_backlight_driver); +} + +module_init(dell_uart_bl_init); +module_exit(dell_uart_bl_exit); +MODULE_DEVICE_TABLE(acpi, dell_uart_bl_ids); +MODULE_DESCRIPTION("Dell AIO Serial Backlight module"); +MODULE_AUTHOR("AceLan Kao "); +MODULE_LICENSE("GPL"); diff --git a/drivers/platform/x86/dell-uart-backlight.h b/drivers/platform/x86/dell-uart-backlight.h new file mode 100644 index 000000000000..e4fe74fae6a8 --- /dev/null +++ b/drivers/platform/x86/dell-uart-backlight.h @@ -0,0 +1,36 @@ +/* + * Dell AIO Serial Backlight Driver + * + * Copyright (C) 2017 AceLan Kao + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef _DELL_UART_BACKLIGHT_H_ +#define _DELL_UART_BACKLIGHT_H_ + +enum { + DELL_UART_GET_FIRMWARE_VER, + DELL_UART_GET_SCALAR, + DELL_UART_GET_BRIGHTNESS, + DELL_UART_SET_BRIGHTNESS, + DELL_UART_SET_BACKLIGHT_POWER, +}; + +struct dell_uart_bl_cmd { + unsigned char cmd[10]; + unsigned char ret[80]; + unsigned short tx_len; + unsigned short rx_len; +}; + +#endif /* _DELL_UART_BACKLIGHT_H_ */ From patchwork Thu Sep 20 08:41:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 972234 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Ls2AccgV"; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42G9F50jr4z9sBn; Thu, 20 Sep 2018 18:41:29 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1g2uWZ-0006Ut-Q7; Thu, 20 Sep 2018 08:41:23 +0000 Received: from mail-ed1-f44.google.com ([209.85.208.44]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1g2uWW-0006Tu-R7 for kernel-team@lists.ubuntu.com; Thu, 20 Sep 2018 08:41:20 +0000 Received: by mail-ed1-f44.google.com with SMTP id j62-v6so7129226edd.7 for ; Thu, 20 Sep 2018 01:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=eK/GaIFltOCn8c5aXXRFBL5nIGnnRyj1YgTB9UtnJeA=; b=Ls2AccgVcTa72OLeq55lcN0G34k/4kb17TqQpMsxsf25wUyV8vlj6FHrXXMMVm8WeO 0IXjk4IsBbL9SpxqovaIN6vnZgLkDrSJee9TB+IJaVhixDrreDnX38xur8kkgaYZBD8y /OFEV6xHoEm7ei4nK+FM5CA39gBvlx6qOIbanMqIZQ07uxavc+ATunoWwnyknJwFF/iR 0EhJ8iNra21XVhHgRk2/4bT/ayxl/Ot3UKAEQ/oxuMQSTd01/kilaUGfDmKeL9ONua2l L3S2bO3N3VCDe5CaAe88IjYJrP3p7xkOAX1vv2pcmjOaR+oUdORb+r23m5UcYxPZ6rTu pWUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=eK/GaIFltOCn8c5aXXRFBL5nIGnnRyj1YgTB9UtnJeA=; b=FHCXZLJMCW2iyC4P3o4GUk720jM16kzrpsg458yXdc4Li66uVHs6zIvRnjukFyNyWc RaTexSPkUZNsFwVD/upmmbU+9MpPM79ixvmwISwVfxKOCwgYm08Z/qCFqYsx33BBrP1+ IfYAlUeNL7fczrpy+Rg4XBwjBDiGR2yoCIQThRgNN3pF+/EvUikXyNJ0suF9/PVdTv7r x35rkV1u7OD2U5A6K/dxpNoN57OAdZ3EjrABE+qNL3OrXXKUSNhQ3wsUiLpbWFRhFdZl BOiv1ML06SZGaCRY4twcIynUsss/dmHG9kZrvNJCApHD/vLgd8Fk9qYrsLuj4TIV0pkT cGBg== X-Gm-Message-State: APzg51A1zadnISTc/exZM/GUydqCav8CB2lsiNqwZ+9EHMrbmIB8Sj0I sdpNHbnxFLTmAH6/vFSaSQ8pn8e289A= X-Google-Smtp-Source: ANB0Vdab5/Y5/qLxl62b0gDG48tiiztoFZS6cworLT/dYLeOsDTX5ceAok2T2YbTgsWhYfLBz1RF5Q== X-Received: by 2002:a50:b410:: with SMTP id b16-v6mr3076246edh.190.1537432879802; Thu, 20 Sep 2018 01:41:19 -0700 (PDT) Received: from localhost (84-199-88-153.iFiber.telenet-ops.be. [84.199.88.153]) by smtp.gmail.com with ESMTPSA id 25-v6sm791314edz.45.2018.09.20.01.41.18 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 01:41:18 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH v4 2/2][SRU][Bionic]UBUNTU: updateconfigs for Dell UART backlight driver Date: Thu, 20 Sep 2018 16:41:15 +0800 Message-Id: <20180920084115.1895-3-acelan.kao@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920084115.1895-1-acelan.kao@canonical.com> References: <20180920084115.1895-1-acelan.kao@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/1727235 Signed-off-by: AceLan Kao --- debian.master/config/config.common.ubuntu | 1 + 1 file changed, 1 insertion(+) diff --git a/debian.master/config/config.common.ubuntu b/debian.master/config/config.common.ubuntu index c4ce582d5d90..49e10e43ebeb 100644 --- a/debian.master/config/config.common.ubuntu +++ b/debian.master/config/config.common.ubuntu @@ -2123,6 +2123,7 @@ CONFIG_DELL_SMBIOS=m CONFIG_DELL_SMBIOS_SMM=m CONFIG_DELL_SMBIOS_WMI=m CONFIG_DELL_SMO8800=m +CONFIG_DELL_UART_BACKLIGHT=m CONFIG_DELL_WMI=m CONFIG_DELL_WMI_AIO=m CONFIG_DELL_WMI_DESCRIPTOR=m