Received: by 10.223.164.202 with SMTP id h10csp1561497wrb; Wed, 15 Nov 2017 23:48:53 -0800 (PST) X-Google-Smtp-Source: AGs4zMZXragewDd/OllCqKjZOz3nvYYtOS0jM2NMll91GOk1ARV2vOsdq2T7hHyGQJPRgq1Fsx4b X-Received: by 10.99.9.130 with SMTP id 124mr843771pgj.324.1510818533184; Wed, 15 Nov 2017 23:48:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510818533; cv=none; d=google.com; s=arc-20160816; b=Wu8ovvXktZuhQkqL9qLpQi8/TExJbwdkNiyuvMy0gh0o2nN9NWDj0yS9Fo3gSXNbH9 l9lvsi/FTFgcmV1QyAkUgS00awzvWqInBZszivl5OutTLG0SxGgeGpLmIWUvoCgEaAJo GWsGcYBfH33Mxw7HYkZ9tE0PU/5RPitJYOfI1ve5wz5EYAmXdo3gA6OkMMf4al4nrvds WxnsKHom6OJI5tA0nyOs55KTO910BpGqlKMPM2iPHtBQ/s+U8qpCPtbfntP8L/1RCXPL p07Z31xxuReg5kZGk9nMRj3Ux7PCFpx4xlc9ydqryDuSwG0HFNQ8F+tlf6vwyBd1BQsx Bn3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=l+57wB90VDzbPUEkuzy396TqvikmT5u1Em3r+CuOz+g=; b=bHenC0RbOIQAk3Uxn2Ix3T1UqO5pZK4ug5Wfj4uJmHvBUWAWS6+3HW6n8OE7A8+a4f sxOm2vzrCVHe+Kj9P+/ErKpjv7yh7i4WahTG00oqTmNN0LVeRwbd5iv8k3agUgElNDQF W+3UG44bU97mzJApAjx3swKUX+qOVZzUKWsa6hHIA09KiJl04r0hTXsIpeSQJFbcu0eq 8ZTRW9nj25HYG+Gz86yxCExe1zyY1Q2iEvqamM71TmOzP0oX5gxGd/Z3hG+eqTlyMB3q GjXzHQimMXOCkCoqqCRyp5fePcZuBTqMcF3GAVu3ON3ytUTZPeT6+bRsL+nMVMelL2PW 0wpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JvbiHaKh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i1si422077pgp.722.2017.11.15.23.48.40; Wed, 15 Nov 2017 23:48:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JvbiHaKh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759269AbdKPHql (ORCPT + 91 others); Thu, 16 Nov 2017 02:46:41 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:51397 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758992AbdKPHq0 (ORCPT ); Thu, 16 Nov 2017 02:46:26 -0500 Received: by mail-pg0-f67.google.com with SMTP id p9so19996609pgc.8; Wed, 15 Nov 2017 23:46:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l+57wB90VDzbPUEkuzy396TqvikmT5u1Em3r+CuOz+g=; b=JvbiHaKh7huRlfLipq2OZUjJP1Id8gxLwdA6bWqew63uaoy2EXPBKaK/SkmfeEY8q7 WOsziHz4AAoIqMNR5qdDuKhFkPFBgdICzg3OFVejYMVDsOkUhharl/qWzpFE3B2T67P6 gpVKrCDGtDJGyy4W3AjoPa7Tkg5akxlkoa8SGgAQJmpWp1tv1Wo5e0LV2Umil0VPfJl3 FZHGvTrHX8hiOUKctjXt9VmLUp+B0JCmVdrqiHA9nqNhsH/+I1hTrRM8PFm32mdeIWvh J4zvwfRSiDhNVc4tiS8aXx42ePCEF3CxfLzfWxengxhOQOQGC5bHRV4E1dUVgjUe4jQu /qBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=l+57wB90VDzbPUEkuzy396TqvikmT5u1Em3r+CuOz+g=; b=hyYv+tPmTUMkHqGKXvG9oXTwIOeUcqZndQpOuwe1D5NGmy8/OcQ6l33RkTywI2+XHM a/lhhhkDoFmuADjS5yDJwa6gMBQe+Zeh8xzDhYSFaWLNjkg9XjTrkjTueYT03gcXLSGl t87yHVpB+O6XF55ZUa44KDmts86X72ez7QLFcRl4R9mqfp5vNsey3Wnsx2Y9NCEby6Qv 2ezlFF/h9x0xpNWPpLh8sJfOD/0M62jWaQV7nysQMmispn1ETbu4/Pu2sUKgSgjOv+F3 bd7eUpA8LQEkioejBUV+c6Xrqn+L/Ymk97Sv6UVOXkRyw/y5vhqqmqm49ai2szl5cFpw 5Dlg== X-Gm-Message-State: AJaThX5H461kmRS6ZQiPEmVXqe95pAMwK0f1Gju4Ruvi9EOMgkI6ATRX AeLuRqiDdtWWrx8zZHf0h/I= X-Received: by 10.159.211.71 with SMTP id g7mr813234plp.15.1510818384904; Wed, 15 Nov 2017 23:46:24 -0800 (PST) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id w9sm1442867pfl.19.2017.11.15.23.46.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Nov 2017 23:46:24 -0800 (PST) From: "Ji-Ze Hong (Peter Hong)" X-Google-Original-From: "Ji-Ze Hong (Peter Hong)" To: johan@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Ji-Ze Hong (Peter Hong)" Subject: [PATCH V1 3/4] usb: serial: f81534: add output pin control Date: Thu, 16 Nov 2017 15:46:08 +0800 Message-Id: <1510818369-10323-3-git-send-email-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510818369-10323-1-git-send-email-hpeter+linux_kernel@gmail.com> References: <1510818369-10323-1-git-send-email-hpeter+linux_kernel@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The F81532/534 had 3 output pin (M0/SD, M1, M2) with open-drain mode to control transceiver. We'll read it from internal Flash with address 0x2f05~0x2f08 for 4 ports. The value is range from 0 to 7. The M0/SD is MSB of this value. For a examples, If read value is 6, we'll write M0/SD, M1, M2 as 1, 1, 0. Register mapping for output value: Port 0: M2: 0x2ae8 bit7, M1: 0x2a90 bit5, M0/SD: 0x2a90 bit4 Port 1: M2: 0x2ae8 bit6, M1: 0x2ae8 bit0, M0/SD: 0x2ae8 bit3 Port 2: M2: 0x2a90 bit0, M1: 0x2ae8 bit2, M0/SD: 0x2a80 bit6 Port 3: M2: 0x2a90 bit3, M1: 0x2a90 bit2, M0/SD: 0x2a90 bit1 Signed-off-by: Ji-Ze Hong (Peter Hong) --- drivers/usb/serial/f81534.c | 67 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/f81534.c b/drivers/usb/serial/f81534.c index b2d10309c335..30b966d71ae8 100644 --- a/drivers/usb/serial/f81534.c +++ b/drivers/usb/serial/f81534.c @@ -56,6 +56,7 @@ #define F81534_CUSTOM_NO_CUSTOM_DATA 0xff #define F81534_CUSTOM_VALID_TOKEN 0xf0 #define F81534_CONF_OFFSET 1 +#define F81534_CONF_GPIO_OFFSET 4 #define F81534_MAX_DATA_BLOCK 64 #define F81534_MAX_BUS_RETRY 20 @@ -166,6 +167,23 @@ struct f81534_port_private { u8 phy_num; }; +struct f81534_pin_data { + const u16 reg_addr; + const u16 reg_mask; +}; + +struct f81534_port_out_pin { + struct f81534_pin_data pin[3]; +}; + +/* Pin output value for M2/M1/M0(SD) */ +static const struct f81534_port_out_pin f81534_port_out_pins[] = { + {{{0x2ae8, BIT(7)}, {0x2a90, BIT(5)}, {0x2a90, BIT(4) } } }, + {{{0x2ae8, BIT(6)}, {0x2ae8, BIT(0)}, {0x2ae8, BIT(3) } } }, + {{{0x2a90, BIT(0)}, {0x2ae8, BIT(2)}, {0x2a80, BIT(6) } } }, + {{{0x2a90, BIT(3)}, {0x2a90, BIT(2)}, {0x2a90, BIT(1) } } }, +}; + static int f81534_logic_to_phy_port(struct usb_serial *serial, struct usb_serial_port *port) { @@ -271,6 +289,22 @@ static int f81534_get_register(struct usb_serial *serial, u16 reg, u8 *data) return status; } +static int f81534_set_mask_register(struct usb_serial *serial, u16 reg, + u8 mask, u8 data) +{ + int status; + u8 tmp; + + status = f81534_get_register(serial, reg, &tmp); + if (status) + return status; + + tmp &= ~mask; + tmp |= (mask & data); + + return f81534_set_register(serial, reg, tmp); +} + static int f81534_set_port_register(struct usb_serial_port *port, u16 reg, u8 data) { @@ -1299,6 +1333,37 @@ static void f81534_lsr_worker(struct work_struct *work) dev_warn(&port->dev, "read LSR failed: %d\n", status); } +static int f81534_set_port_output_pin(struct usb_serial_port *port) +{ + struct f81534_serial_private *serial_priv; + struct f81534_port_private *port_priv; + struct usb_serial *serial; + const struct f81534_port_out_pin *pins; + int status; + int i; + u8 value; + u8 idx; + + serial = port->serial; + serial_priv = usb_get_serial_data(serial); + port_priv = usb_get_serial_port_data(port); + + idx = F81534_CONF_GPIO_OFFSET + port_priv->phy_num; + value = serial_priv->conf_data[idx]; + pins = &f81534_port_out_pins[port_priv->phy_num]; + + for (i = 0; i < ARRAY_SIZE(pins->pin); ++i) { + status = f81534_set_mask_register(serial, + pins->pin[i].reg_addr, pins->pin[i].reg_mask, + value & BIT(i) ? pins->pin[i].reg_mask : 0); + if (status) + return status; + } + + dev_info(&port->dev, "Output pin (M0/M1/M2): %d\n", value); + return 0; +} + static int f81534_port_probe(struct usb_serial_port *port) { struct f81534_serial_private *serial_priv; @@ -1354,7 +1419,7 @@ static int f81534_port_probe(struct usb_serial_port *port) break; } - return 0; + return f81534_set_port_output_pin(port); } static int f81534_port_remove(struct usb_serial_port *port) -- 2.7.4 From 1584080878117062824@xxx Tue Nov 14 22:07:28 +0000 2017 X-GM-THRID: 1584080878117062824 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread