Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp677027imm; Wed, 11 Jul 2018 09:06:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfHEE9hNHSV/U/DubZnZzmI2opoGKZzCBuwDDFJLM8fPRoEhRCnWR5mrAMZFtZbfdUHdaXX X-Received: by 2002:a63:5922:: with SMTP id n34-v6mr27436057pgb.113.1531325194606; Wed, 11 Jul 2018 09:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531325194; cv=none; d=google.com; s=arc-20160816; b=sK1EFXyPZEr0MqNr5TxAArNhh/rheCERSxd/nJktNOuhMZxBs8ed1d2WetFGLgFnjw sLL6h1H7VX4cVVrO2Q08cgRC/AdtqGq3Kq8WKeTYeMY9+Uoy6Y0y1q0yzm5ZM+TUW5qy xfMeQkXGNCgCdJ0F/skUIOAZnWyZASNB/Zuv9TL+d3jeWwEuleAkTsDAA6560wW2+8qE eDnhiRDsAyAENqEmLAi+eakIawdZST/7/mUo4zdisHSwgC2Jw624hj/9e6AdfZ96p9X0 3j8yYo/ODK/t0RDruCUUBQz9JFVnu9sRNS9BovZ3FCTYz1NNscwaNGgB0xxbovApI3qK NzTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=iWFTKQRHaBZQE1vgO7dLmej6PjKPmQic46i7JMalPns=; b=a8XcqxYMt/Y4+y7xtsyhcYD5XzSnVceg91tDt4g58+P/MqoC/snUI172v9gNkdEzCZ w8IwA0FIjzrrCaRbbxE5SG7UnJmTW2LLr2Al4DHiJFhROpQqzLMTWjMmjNvMzdsFXxcr kKU247A1C5n/AfooHWm3/+f7rnzjonM2UZ80j21QyUYSbn4CBLgwNda6vbvYVP7Abnb4 i+smwDueD5kALZrT7dvNryx0gokHvojiiewv3rqrcFLb3ff88U6CQHvgULccZ/rpYfcn DC0EoRltMkM6gXXQWaPkfJmXe/fhKlYWi/tlE9WSQz5WVyZ85OI5eIzSU+luR75LM0LG E5FA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s22-v6si19303698plr.498.2018.07.11.09.06.03; Wed, 11 Jul 2018 09:06:34 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387684AbeGKNZB (ORCPT + 99 others); Wed, 11 Jul 2018 09:25:01 -0400 Received: from esa3.microchip.iphmx.com ([68.232.153.233]:21760 "EHLO esa3.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732562AbeGKNZA (ORCPT ); Wed, 11 Jul 2018 09:25:00 -0400 X-IronPort-AV: E=Sophos;i="5.51,338,1526367600"; d="scan'208";a="16189971" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 11 Jul 2018 06:20:40 -0700 Received: from ibiza.rfo.atmel.com (10.10.76.4) by chn-sv-exch06.mchp-main.com (10.10.76.107) with Microsoft SMTP Server id 14.3.352.0; Wed, 11 Jul 2018 06:20:40 -0700 From: Ludovic Desroches To: , , CC: , , , , , , , Ludovic Desroches Subject: [PATCH 1/3] tty/serial_core: add ISO7816 infrastructure Date: Wed, 11 Jul 2018 15:16:36 +0200 Message-ID: <20180711131638.12622-2-ludovic.desroches@microchip.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20180711131638.12622-1-ludovic.desroches@microchip.com> References: <20180711131638.12622-1-ludovic.desroches@microchip.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicolas Ferre Add the ISO7816 ioctl and associated accessors and data structure. Drivers can then use this common implementation to handle ISO7816. Signed-off-by: Nicolas Ferre [ludovic.desroches@microchip.com: squash and rebase, removal of gpios, checkpatch fixes] Signed-off-by: Ludovic Desroches --- drivers/tty/serial/serial_core.c | 49 +++++++++++++++++++++++++++++++++++++++ include/linux/serial_core.h | 3 +++ include/uapi/asm-generic/ioctls.h | 2 ++ include/uapi/linux/serial.h | 17 ++++++++++++++ 4 files changed, 71 insertions(+) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 9c14a453f73c..c89ac59f6f8c 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1301,6 +1301,47 @@ static int uart_set_rs485_config(struct uart_port *port, return 0; } +static int uart_get_iso7816_config(struct uart_port *port, + struct serial_iso7816 __user *iso7816) +{ + unsigned long flags; + struct serial_iso7816 aux; + + spin_lock_irqsave(&port->lock, flags); + aux = port->iso7816; + spin_unlock_irqrestore(&port->lock, flags); + + if (copy_to_user(iso7816, &aux, sizeof(aux))) + return -EFAULT; + + return 0; +} + +static int uart_set_iso7816_config(struct uart_port *port, + struct serial_iso7816 __user *iso7816_user) +{ + struct serial_iso7816 iso7816; + int ret; + unsigned long flags; + + if (!port->iso7816_config) + return -ENOIOCTLCMD; + + if (copy_from_user(&iso7816, iso7816_user, sizeof(*iso7816_user))) + return -EFAULT; + + spin_lock_irqsave(&port->lock, flags); + ret = port->iso7816_config(port, &iso7816); + spin_unlock_irqrestore(&port->lock, flags); + if (ret) + return ret; + + if (copy_to_user(iso7816_user, &port->iso7816, sizeof(port->iso7816))) + return -EFAULT; + + return 0; +} + /* * Called via sys_ioctl. We can use spin_lock_irq() here. */ @@ -1385,6 +1426,14 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) case TIOCSRS485: ret = uart_set_rs485_config(uport, uarg); break; + + case TIOCSISO7816: + ret = uart_set_iso7816_config(state->uart_port, uarg); + break; + + case TIOCGISO7816: + ret = uart_get_iso7816_config(state->uart_port, uarg); + break; default: if (uport->ops->ioctl) ret = uport->ops->ioctl(uport, cmd, arg); diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 06ea4eeb09ab..d6e7747ffd46 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -137,6 +137,8 @@ struct uart_port { void (*handle_break)(struct uart_port *); int (*rs485_config)(struct uart_port *, struct serial_rs485 *rs485); + int (*iso7816_config)(struct uart_port *, + struct serial_iso7816 *iso7816); unsigned int irq; /* irq number */ unsigned long irqflags; /* irq flags */ unsigned int uartclk; /* base uart clock */ @@ -253,6 +255,7 @@ struct uart_port { struct attribute_group *attr_group; /* port specific attributes */ const struct attribute_group **tty_groups; /* all attributes (serial core use only) */ struct serial_rs485 rs485; + struct serial_iso7816 iso7816; void *private_data; /* generic platform data pointer */ }; diff --git a/include/uapi/asm-generic/ioctls.h b/include/uapi/asm-generic/ioctls.h index 040651735662..0e5c79726c2d 100644 --- a/include/uapi/asm-generic/ioctls.h +++ b/include/uapi/asm-generic/ioctls.h @@ -66,6 +66,8 @@ #ifndef TIOCSRS485 #define TIOCSRS485 0x542F #endif +#define TIOCGISO7816 0x5430 +#define TIOCSISO7816 0x5431 #define TIOCGPTN _IOR('T', 0x30, unsigned int) /* Get Pty Number (of pty-mux device) */ #define TIOCSPTLCK _IOW('T', 0x31, int) /* Lock/unlock Pty */ #define TIOCGDEV _IOR('T', 0x32, unsigned int) /* Get primary device node of /dev/console */ diff --git a/include/uapi/linux/serial.h b/include/uapi/linux/serial.h index 3fdd0dee8b41..93eb3c496ff1 100644 --- a/include/uapi/linux/serial.h +++ b/include/uapi/linux/serial.h @@ -132,4 +132,21 @@ struct serial_rs485 { are a royal PITA .. */ }; +/* + * Serial interface for controlling ISO7816 settings on chips with suitable + * support. Set with TIOCSISO7816 and get with TIOCGISO7816 if supported by + * your platform. + */ +struct serial_iso7816 { + __u32 flags; /* ISO7816 feature flags */ +#define SER_ISO7816_ENABLED (1 << 0) +#define SER_ISO7816_T_PARAM (0x0f << 4) +#define SER_ISO7816_T(t) (((t) & 0x0f) << 4) + __u32 tg; + __u32 sc_fi; + __u32 sc_di; + __u32 clk; + __u32 reserved[5]; +}; + #endif /* _UAPI_LINUX_SERIAL_H */ -- 2.12.2