blob: 95273073a4af2184c4b5dbab1e2f2d7edd8b10e2 [file] [log] [blame]
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +08001/*
2 * I2C bridge driver for the Greybus "generic" I2C module.
3 *
4 * Copyright 2014 Google Inc.
5 *
6 * Released under the GPLv2 only.
7 */
8
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/tty.h>
13#include <linux/serial.h>
14#include <linux/tty_driver.h>
15#include <linux/tty_flip.h>
16#include "greybus.h"
17
18#define GB_TTY_MAJOR 180 /* FIXME use a real number!!! */
19
20struct gb_tty {
21 struct tty_port port;
22 struct greybus_device *gdev;
23 int cport;
24 unsigned int minor;
25 unsigned char clocal;
26 // FIXME locking!!!
27};
28
29static const struct greybus_device_id id_table[] = {
30 { GREYBUS_DEVICE(0x45, 0x45) }, /* make shit up */
31 { }, /* terminating NULL entry */
32};
33
34
35static const struct tty_operations gb_ops = {
36 .install = gb_tty_install,
37 .open = gb_tty_open,
38 .close = gb_tty_close,
39 .cleanup = gb_tty_cleanup,
40 .hangup = gb_tty_hangup,
41 .write = gb_tty_write,
42 .write_room = gb_tty_write_room,
43 .ioctl = gb_tty_ioctl,
44 .throttle = gb_tty_throttle,
45 .unthrottle = gb_tty_unthrottle,
46 .chars_in_buffer = gb_tty_chars_in_buffer,
47 .break_ctl = gb_tty_break_ctl,
48 .set_termios = gb_tty_set_termios,
49 .tiocmget = gb_tty_tiocmget,
50 .tiocmset = gb_tty_tiocmset,
51};
52
53static struct tty_driver *gb_tty_driver;
54static struct gb_tty *gb_tty_table[255];
55
56static int tty_gb_probe(struct greybus_device *gdev, const struct greybus_device_id *id)
57{
58 int retval;
59
60 //greybus_set_drvdata(gdev, i2c_gb_data);
61 return 0;
62}
63
64static void tty_gb_disconnect(struct greybus_device *gdev)
65{
66}
67
68static struct greybus_driver tty_gb_driver = {
69 .probe = tty_gb_probe,
70 .disconnect = tty_gb_disconnect,
71 .id_table = id_table,
72};
73
74
75static int __init gb_tty_init(void)
76{
77 int retval;
78
79 gb_tty_driver = alloc_tty_driver(255);
80 if (!gb_tty_driver)
81 return -ENOMEM;
82
83 gb_tty_driver->driver_name = "gb";
84 gb_tty_driver->name = "ttyGB";
85 gb_tty_driver->major = GB_TTY_MAJOR;
86 gb_tty_driver->minor_start = 0;
87 gb_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
88 gb_tty_driver->subtype = SERIAL_TYPE_NORMAL;
89 gb_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
90 gb_tty_driver->init_termios = tty_std_termios;
91 gb_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
92 tty_set_operations(gb_tty_driver, &gb_ops);
93
94 retval = tty_register_driver(gb_tty_driver);
95 if (retval) {
96 put_tty_driver(gb_tty_driver);
97 return retval;
98 }
99
100 retval = greybus_register(&tty_gb_driver);
101 if (retval) {
102 tty_unregister_driver(gb_tty_driver);
103 put_tty_driver(gb_tty_driver);
104 }
105 return retval;
106}
107
108static void __exit gb_tty_exit(void)
109{
110 greybus_deregister(&tty_gb_driver);
111 tty_unregister_driver(gb_tty_driver);
112 put_tty_driver(gb_tty_driver);
113}
114
115module_init(gb_tty_init);
116module_exit(gb_tty_exit);
117MODULE_LICENSE("GPL");
118MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>");