aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/console.h4
-rw-r--r--include/linux/serdev.h262
-rw-r--r--include/linux/serial_core.h2
-rw-r--r--include/linux/serial_sci.h15
-rw-r--r--include/linux/tty.h12
5 files changed, 277 insertions, 18 deletions
diff --git a/include/linux/console.h b/include/linux/console.h
index 9c26c6685587..5949d1855589 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -73,6 +73,10 @@ struct consw {
73 u16 *(*con_screen_pos)(struct vc_data *, int); 73 u16 *(*con_screen_pos)(struct vc_data *, int);
74 unsigned long (*con_getxy)(struct vc_data *, unsigned long, int *, int *); 74 unsigned long (*con_getxy)(struct vc_data *, unsigned long, int *, int *);
75 /* 75 /*
76 * Flush the video console driver's scrollback buffer
77 */
78 void (*con_flush_scrollback)(struct vc_data *);
79 /*
76 * Prepare the console for the debugger. This includes, but is not 80 * Prepare the console for the debugger. This includes, but is not
77 * limited to, unblanking the console, loading an appropriate 81 * limited to, unblanking the console, loading an appropriate
78 * palette, and allowing debugger generated output. 82 * palette, and allowing debugger generated output.
diff --git a/include/linux/serdev.h b/include/linux/serdev.h
new file mode 100644
index 000000000000..9519da6253a8
--- /dev/null
+++ b/include/linux/serdev.h
@@ -0,0 +1,262 @@
1/*
2 * Copyright (C) 2016-2017 Linaro Ltd., Rob Herring <robh@kernel.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13#ifndef _LINUX_SERDEV_H
14#define _LINUX_SERDEV_H
15
16#include <linux/types.h>
17#include <linux/device.h>
18
19struct serdev_controller;
20struct serdev_device;
21
22/*
23 * serdev device structures
24 */
25
26/**
27 * struct serdev_device_ops - Callback operations for a serdev device
28 * @receive_buf: Function called with data received from device.
29 * @write_wakeup: Function called when ready to transmit more data.
30 */
31struct serdev_device_ops {
32 int (*receive_buf)(struct serdev_device *, const unsigned char *, size_t);
33 void (*write_wakeup)(struct serdev_device *);
34};
35
36/**
37 * struct serdev_device - Basic representation of an serdev device
38 * @dev: Driver model representation of the device.
39 * @nr: Device number on serdev bus.
40 * @ctrl: serdev controller managing this device.
41 * @ops: Device operations.
42 */
43struct serdev_device {
44 struct device dev;
45 int nr;
46 struct serdev_controller *ctrl;
47 const struct serdev_device_ops *ops;
48};
49
50static inline struct serdev_device *to_serdev_device(struct device *d)
51{
52 return container_of(d, struct serdev_device, dev);
53}
54
55/**
56 * struct serdev_device_driver - serdev slave device driver
57 * @driver: serdev device drivers should initialize name field of this
58 * structure.
59 * @probe: binds this driver to a serdev device.
60 * @remove: unbinds this driver from the serdev device.
61 */
62struct serdev_device_driver {
63 struct device_driver driver;
64 int (*probe)(struct serdev_device *);
65 void (*remove)(struct serdev_device *);
66};
67
68static inline struct serdev_device_driver *to_serdev_device_driver(struct device_driver *d)
69{
70 return container_of(d, struct serdev_device_driver, driver);
71}
72
73/*
74 * serdev controller structures
75 */
76struct serdev_controller_ops {
77 int (*write_buf)(struct serdev_controller *, const unsigned char *, size_t);
78 void (*write_flush)(struct serdev_controller *);
79 int (*write_room)(struct serdev_controller *);
80 int (*open)(struct serdev_controller *);
81 void (*close)(struct serdev_controller *);
82 void (*set_flow_control)(struct serdev_controller *, bool);
83 unsigned int (*set_baudrate)(struct serdev_controller *, unsigned int);
84};
85
86/**
87 * struct serdev_controller - interface to the serdev controller
88 * @dev: Driver model representation of the device.
89 * @nr: number identifier for this controller/bus.
90 * @serdev: Pointer to slave device for this controller.
91 * @ops: Controller operations.
92 */
93struct serdev_controller {
94 struct device dev;
95 unsigned int nr;
96 struct serdev_device *serdev;
97 const struct serdev_controller_ops *ops;
98};
99
100static inline struct serdev_controller *to_serdev_controller(struct device *d)
101{
102 return container_of(d, struct serdev_controller, dev);
103}
104
105static inline void *serdev_device_get_drvdata(const struct serdev_device *serdev)
106{
107 return dev_get_drvdata(&serdev->dev);
108}
109
110static inline void serdev_device_set_drvdata(struct serdev_device *serdev, void *data)
111{
112 dev_set_drvdata(&serdev->dev, data);
113}
114
115/**
116 * serdev_device_put() - decrement serdev device refcount
117 * @serdev serdev device.
118 */
119static inline void serdev_device_put(struct serdev_device *serdev)
120{
121 if (serdev)
122 put_device(&serdev->dev);
123}
124
125static inline void serdev_device_set_client_ops(struct serdev_device *serdev,
126 const struct serdev_device_ops *ops)
127{
128 serdev->ops = ops;
129}
130
131static inline
132void *serdev_controller_get_drvdata(const struct serdev_controller *ctrl)
133{
134 return ctrl ? dev_get_drvdata(&ctrl->dev) : NULL;
135}
136
137static inline void serdev_controller_set_drvdata(struct serdev_controller *ctrl,
138 void *data)
139{
140 dev_set_drvdata(&ctrl->dev, data);
141}
142
143/**
144 * serdev_controller_put() - decrement controller refcount
145 * @ctrl serdev controller.
146 */
147static inline void serdev_controller_put(struct serdev_controller *ctrl)
148{
149 if (ctrl)
150 put_device(&ctrl->dev);
151}
152
153struct serdev_device *serdev_device_alloc(struct serdev_controller *);
154int serdev_device_add(struct serdev_device *);
155void serdev_device_remove(struct serdev_device *);
156
157struct serdev_controller *serdev_controller_alloc(struct device *, size_t);
158int serdev_controller_add(struct serdev_controller *);
159void serdev_controller_remove(struct serdev_controller *);
160
161static inline void serdev_controller_write_wakeup(struct serdev_controller *ctrl)
162{
163 struct serdev_device *serdev = ctrl->serdev;
164
165 if (!serdev || !serdev->ops->write_wakeup)
166 return;
167
168 serdev->ops->write_wakeup(ctrl->serdev);
169}
170
171static inline int serdev_controller_receive_buf(struct serdev_controller *ctrl,
172 const unsigned char *data,
173 size_t count)
174{
175 struct serdev_device *serdev = ctrl->serdev;
176
177 if (!serdev || !serdev->ops->receive_buf)
178 return -EINVAL;
179
180 return serdev->ops->receive_buf(ctrl->serdev, data, count);
181}
182
183#if IS_ENABLED(CONFIG_SERIAL_DEV_BUS)
184
185int serdev_device_open(struct serdev_device *);
186void serdev_device_close(struct serdev_device *);
187unsigned int serdev_device_set_baudrate(struct serdev_device *, unsigned int);
188void serdev_device_set_flow_control(struct serdev_device *, bool);
189int serdev_device_write_buf(struct serdev_device *, const unsigned char *, size_t);
190void serdev_device_write_flush(struct serdev_device *);
191int serdev_device_write_room(struct serdev_device *);
192
193/*
194 * serdev device driver functions
195 */
196int __serdev_device_driver_register(struct serdev_device_driver *, struct module *);
197#define serdev_device_driver_register(sdrv) \
198 __serdev_device_driver_register(sdrv, THIS_MODULE)
199
200/**
201 * serdev_device_driver_unregister() - unregister an serdev client driver
202 * @sdrv: the driver to unregister
203 */
204static inline void serdev_device_driver_unregister(struct serdev_device_driver *sdrv)
205{
206 if (sdrv)
207 driver_unregister(&sdrv->driver);
208}
209
210#define module_serdev_device_driver(__serdev_device_driver) \
211 module_driver(__serdev_device_driver, serdev_device_driver_register, \
212 serdev_device_driver_unregister)
213
214#else
215
216static inline int serdev_device_open(struct serdev_device *sdev)
217{
218 return -ENODEV;
219}
220static inline void serdev_device_close(struct serdev_device *sdev) {}
221static inline unsigned int serdev_device_set_baudrate(struct serdev_device *sdev, unsigned int baudrate)
222{
223 return 0;
224}
225static inline void serdev_device_set_flow_control(struct serdev_device *sdev, bool enable) {}
226static inline int serdev_device_write_buf(struct serdev_device *sdev, const unsigned char *buf, size_t count)
227{
228 return -ENODEV;
229}
230static inline void serdev_device_write_flush(struct serdev_device *sdev) {}
231static inline int serdev_device_write_room(struct serdev_device *sdev)
232{
233 return 0;
234}
235
236#define serdev_device_driver_register(x)
237#define serdev_device_driver_unregister(x)
238
239#endif /* CONFIG_SERIAL_DEV_BUS */
240
241/*
242 * serdev hooks into TTY core
243 */
244struct tty_port;
245struct tty_driver;
246
247#ifdef CONFIG_SERIAL_DEV_CTRL_TTYPORT
248struct device *serdev_tty_port_register(struct tty_port *port,
249 struct device *parent,
250 struct tty_driver *drv, int idx);
251void serdev_tty_port_unregister(struct tty_port *port);
252#else
253static inline struct device *serdev_tty_port_register(struct tty_port *port,
254 struct device *parent,
255 struct tty_driver *drv, int idx)
256{
257 return ERR_PTR(-ENODEV);
258}
259static inline void serdev_tty_port_unregister(struct tty_port *port) {}
260#endif /* CONFIG_SERIAL_DEV_CTRL_TTYPORT */
261
262#endif /*_LINUX_SERDEV_H */
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 5def8e830fb0..58484fb35cc8 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -450,7 +450,7 @@ extern void uart_handle_cts_change(struct uart_port *uport,
450extern void uart_insert_char(struct uart_port *port, unsigned int status, 450extern void uart_insert_char(struct uart_port *port, unsigned int status,
451 unsigned int overrun, unsigned int ch, unsigned int flag); 451 unsigned int overrun, unsigned int ch, unsigned int flag);
452 452
453#ifdef SUPPORT_SYSRQ 453#if defined(SUPPORT_SYSRQ) && defined(CONFIG_MAGIC_SYSRQ_SERIAL)
454static inline int 454static inline int
455uart_handle_sysrq_char(struct uart_port *port, unsigned int ch) 455uart_handle_sysrq_char(struct uart_port *port, unsigned int ch)
456{ 456{
diff --git a/include/linux/serial_sci.h b/include/linux/serial_sci.h
index 9f2bfd055742..e598eaef3962 100644
--- a/include/linux/serial_sci.h
+++ b/include/linux/serial_sci.h
@@ -9,8 +9,6 @@
9 * Generic header for SuperH (H)SCI(F) (used by sh/sh64 and related parts) 9 * Generic header for SuperH (H)SCI(F) (used by sh/sh64 and related parts)
10 */ 10 */
11 11
12#define SCIx_NOT_SUPPORTED (-1)
13
14/* Serial Control Register (@ = not supported by all parts) */ 12/* Serial Control Register (@ = not supported by all parts) */
15#define SCSCR_TIE BIT(7) /* Transmit Interrupt Enable */ 13#define SCSCR_TIE BIT(7) /* Transmit Interrupt Enable */
16#define SCSCR_RIE BIT(6) /* Receive Interrupt Enable */ 14#define SCSCR_RIE BIT(6) /* Receive Interrupt Enable */
@@ -41,24 +39,16 @@ enum {
41 SCIx_NR_REGTYPES, 39 SCIx_NR_REGTYPES,
42}; 40};
43 41
44struct device;
45
46struct plat_sci_port_ops { 42struct plat_sci_port_ops {
47 void (*init_pins)(struct uart_port *, unsigned int cflag); 43 void (*init_pins)(struct uart_port *, unsigned int cflag);
48}; 44};
49 45
50/* 46/*
51 * Port-specific capabilities
52 */
53#define SCIx_HAVE_RTSCTS BIT(0)
54
55/*
56 * Platform device specific platform_data struct 47 * Platform device specific platform_data struct
57 */ 48 */
58struct plat_sci_port { 49struct plat_sci_port {
59 unsigned int type; /* SCI / SCIF / IRDA / HSCIF */ 50 unsigned int type; /* SCI / SCIF / IRDA / HSCIF */
60 upf_t flags; /* UPF_* flags */ 51 upf_t flags; /* UPF_* flags */
61 unsigned long capabilities; /* Port features/capabilities */
62 52
63 unsigned int sampling_rate; 53 unsigned int sampling_rate;
64 unsigned int scscr; /* SCSCR initialization */ 54 unsigned int scscr; /* SCSCR initialization */
@@ -66,14 +56,9 @@ struct plat_sci_port {
66 /* 56 /*
67 * Platform overrides if necessary, defaults otherwise. 57 * Platform overrides if necessary, defaults otherwise.
68 */ 58 */
69 int port_reg;
70 unsigned char regshift;
71 unsigned char regtype; 59 unsigned char regtype;
72 60
73 struct plat_sci_port_ops *ops; 61 struct plat_sci_port_ops *ops;
74
75 unsigned int dma_slave_tx;
76 unsigned int dma_slave_rx;
77}; 62};
78 63
79#endif /* __LINUX_SERIAL_SCI_H */ 64#endif /* __LINUX_SERIAL_SCI_H */
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 40144f382516..1017e904c0a3 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -217,12 +217,18 @@ struct tty_port_operations {
217 /* Called on the final put of a port */ 217 /* Called on the final put of a port */
218 void (*destruct)(struct tty_port *port); 218 void (*destruct)(struct tty_port *port);
219}; 219};
220 220
221struct tty_port_client_operations {
222 int (*receive_buf)(struct tty_port *port, const unsigned char *, const unsigned char *, size_t);
223 void (*write_wakeup)(struct tty_port *port);
224};
225
221struct tty_port { 226struct tty_port {
222 struct tty_bufhead buf; /* Locked internally */ 227 struct tty_bufhead buf; /* Locked internally */
223 struct tty_struct *tty; /* Back pointer */ 228 struct tty_struct *tty; /* Back pointer */
224 struct tty_struct *itty; /* internal back ptr */ 229 struct tty_struct *itty; /* internal back ptr */
225 const struct tty_port_operations *ops; /* Port operations */ 230 const struct tty_port_operations *ops; /* Port operations */
231 const struct tty_port_client_operations *client_ops; /* Port client operations */
226 spinlock_t lock; /* Lock protecting tty field */ 232 spinlock_t lock; /* Lock protecting tty field */
227 int blocked_open; /* Waiting to open */ 233 int blocked_open; /* Waiting to open */
228 int count; /* Usage count */ 234 int count; /* Usage count */
@@ -241,6 +247,7 @@ struct tty_port {
241 based drain is needed else 247 based drain is needed else
242 set to size of fifo */ 248 set to size of fifo */
243 struct kref kref; /* Ref counter */ 249 struct kref kref; /* Ref counter */
250 void *client_data;
244}; 251};
245 252
246/* tty_port::iflags bits -- use atomic bit ops */ 253/* tty_port::iflags bits -- use atomic bit ops */
@@ -528,6 +535,7 @@ extern int tty_alloc_file(struct file *file);
528extern void tty_add_file(struct tty_struct *tty, struct file *file); 535extern void tty_add_file(struct tty_struct *tty, struct file *file);
529extern void tty_free_file(struct file *file); 536extern void tty_free_file(struct file *file);
530extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx); 537extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx);
538extern void tty_release_struct(struct tty_struct *tty, int idx);
531extern int tty_release(struct inode *inode, struct file *filp); 539extern int tty_release(struct inode *inode, struct file *filp);
532extern void tty_init_termios(struct tty_struct *tty); 540extern void tty_init_termios(struct tty_struct *tty);
533extern int tty_standard_install(struct tty_driver *driver, 541extern int tty_standard_install(struct tty_driver *driver,
@@ -656,7 +664,7 @@ extern int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty);
656extern void tty_ldisc_release(struct tty_struct *tty); 664extern void tty_ldisc_release(struct tty_struct *tty);
657extern void tty_ldisc_init(struct tty_struct *tty); 665extern void tty_ldisc_init(struct tty_struct *tty);
658extern void tty_ldisc_deinit(struct tty_struct *tty); 666extern void tty_ldisc_deinit(struct tty_struct *tty);
659extern int tty_ldisc_receive_buf(struct tty_ldisc *ld, unsigned char *p, 667extern int tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p,
660 char *f, int count); 668 char *f, int count);
661 669
662/* n_tty.c */ 670/* n_tty.c */