1 // SPDX-License-Identifier: GPL-2.0-only
3 * pti.c - PTI driver for cJTAG data extration
5 * Copyright (C) Intel 2010
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * The PTI (Parallel Trace Interface) driver directs trace data routed from
10 * various parts in the system out through the Intel Penwell PTI port and
11 * out of the mobile device for analysis with a debugging tool
12 * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
13 * compact JTAG, standard.
16 #include <linux/init.h>
17 #include <linux/sched.h>
18 #include <linux/interrupt.h>
19 #include <linux/console.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/tty.h>
23 #include <linux/tty_driver.h>
24 #include <linux/pci.h>
25 #include <linux/mutex.h>
26 #include <linux/miscdevice.h>
27 #include <linux/intel-pti.h>
28 #include <linux/slab.h>
29 #include <linux/uaccess.h>
31 #define DRIVERNAME "pti"
32 #define PCINAME "pciPTI"
33 #define TTYNAME "ttyPTI"
34 #define CHARNAME "pti"
35 #define PTITTY_MINOR_START 0
36 #define PTITTY_MINOR_NUM 2
37 #define MAX_APP_IDS 16 /* 128 channel ids / u8 bit size */
38 #define MAX_OS_IDS 16 /* 128 channel ids / u8 bit size */
39 #define MAX_MODEM_IDS 16 /* 128 channel ids / u8 bit size */
40 #define MODEM_BASE_ID 71 /* modem master ID address */
41 #define CONTROL_ID 72 /* control master ID address */
42 #define CONSOLE_ID 73 /* console master ID address */
43 #define OS_BASE_ID 74 /* base OS master ID address */
44 #define APP_BASE_ID 80 /* base App master ID address */
45 #define CONTROL_FRAME_LEN 32 /* PTI control frame maximum size */
46 #define USER_COPY_SIZE 8192 /* 8Kb buffer for user space copy */
47 #define APERTURE_14 0x3800000 /* offset to first OS write addr */
48 #define APERTURE_LEN 0x400000 /* address length */
51 struct pti_masterchannel
*mc
;
55 struct tty_port port
[PTITTY_MINOR_NUM
];
56 unsigned long pti_addr
;
57 unsigned long aperture_base
;
58 void __iomem
*pti_ioaddr
;
59 u8 ia_app
[MAX_APP_IDS
];
61 u8 ia_modem
[MAX_MODEM_IDS
];
65 * This protects access to ia_app, ia_os, and ia_modem,
66 * which keeps track of channels allocated in
67 * an aperture write id.
69 static DEFINE_MUTEX(alloclock
);
71 static const struct pci_device_id pci_ids
[] = {
72 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x82B)},
76 static struct tty_driver
*pti_tty_driver
;
77 static struct pti_dev
*drv_data
;
79 static unsigned int pti_console_channel
;
80 static unsigned int pti_control_channel
;
83 * pti_write_to_aperture()- The private write function to PTI HW.
85 * @mc: The 'aperture'. It's part of a write address that holds
86 * a master and channel ID.
87 * @buf: Data being written to the HW that will ultimately be seen
88 * in a debugging tool (Fido, Lauterbach).
89 * @len: Size of buffer.
91 * Since each aperture is specified by a unique
92 * master/channel ID, no two processes will be writing
93 * to the same aperture at the same time so no lock is required. The
94 * PTI-Output agent will send these out in the order that they arrived, and
95 * thus, it will intermix these messages. The debug tool can then later
96 * regroup the appropriate message segments together reconstituting each
99 static void pti_write_to_aperture(struct pti_masterchannel
*mc
,
107 u32 __iomem
*aperture
;
111 * calculate the aperture offset from the base using the master and
114 aperture
= drv_data
->pti_ioaddr
+ (mc
->master
<< 15)
115 + (mc
->channel
<< 8);
118 final
= len
- (dwordcnt
<< 2); /* final = trailing bytes */
119 if (final
== 0 && dwordcnt
!= 0) { /* always need a final dword */
124 for (i
= 0; i
< dwordcnt
; i
++) {
125 ptiword
= be32_to_cpu(*(u32
*)p
);
127 iowrite32(ptiword
, aperture
);
130 aperture
+= PTI_LASTDWORD_DTS
; /* adding DTS signals that is EOM */
133 for (i
= 0; i
< final
; i
++)
134 ptiword
|= *p
++ << (24-(8*i
));
136 iowrite32(ptiword
, aperture
);
141 * pti_control_frame_built_and_sent()- control frame build and send function.
143 * @mc: The master / channel structure on which the function
144 * built a control frame.
145 * @thread_name: The thread name associated with the master / channel or
146 * 'NULL' if using the 'current' global variable.
148 * To be able to post process the PTI contents on host side, a control frame
149 * is added before sending any PTI content. So the host side knows on
150 * each PTI frame the name of the thread using a dedicated master / channel.
151 * The thread name is retrieved from 'current' global variable if 'thread_name'
152 * is 'NULL', else it is retrieved from 'thread_name' parameter.
153 * This function builds this frame and sends it to a master ID CONTROL_ID.
154 * The overhead is only 32 bytes since the driver only writes to HW
157 static void pti_control_frame_built_and_sent(struct pti_masterchannel
*mc
,
158 const char *thread_name
)
161 * Since we access the comm member in current's task_struct, we only
162 * need to be as large as what 'comm' in that structure is.
164 char comm
[TASK_COMM_LEN
];
165 struct pti_masterchannel mccontrol
= {.master
= CONTROL_ID
,
167 const char *thread_name_p
;
168 const char *control_format
= "%3d %3d %s";
169 u8 control_frame
[CONTROL_FRAME_LEN
];
173 get_task_comm(comm
, current
);
175 strncpy(comm
, "Interrupt", TASK_COMM_LEN
);
177 /* Absolutely ensure our buffer is zero terminated. */
178 comm
[TASK_COMM_LEN
-1] = 0;
179 thread_name_p
= comm
;
181 thread_name_p
= thread_name
;
184 mccontrol
.channel
= pti_control_channel
;
185 pti_control_channel
= (pti_control_channel
+ 1) & 0x7f;
187 snprintf(control_frame
, CONTROL_FRAME_LEN
, control_format
, mc
->master
,
188 mc
->channel
, thread_name_p
);
189 pti_write_to_aperture(&mccontrol
, control_frame
, strlen(control_frame
));
193 * pti_write_full_frame_to_aperture()- high level function to
196 * @mc: The 'aperture'. It's part of a write address that holds
197 * a master and channel ID.
198 * @buf: Data being written to the HW that will ultimately be seen
199 * in a debugging tool (Fido, Lauterbach).
200 * @len: Size of buffer.
202 * All threads sending data (either console, user space application, ...)
203 * are calling the high level function to write to PTI meaning that it is
204 * possible to add a control frame before sending the content.
206 static void pti_write_full_frame_to_aperture(struct pti_masterchannel
*mc
,
207 const unsigned char *buf
,
210 pti_control_frame_built_and_sent(mc
, NULL
);
211 pti_write_to_aperture(mc
, (u8
*)buf
, len
);
215 * get_id()- Allocate a master and channel ID.
217 * @id_array: an array of bits representing what channel
218 * id's are allocated for writing.
219 * @max_ids: The max amount of available write IDs to use.
220 * @base_id: The starting SW channel ID, based on the Intel
222 * @thread_name: The thread name associated with the master / channel or
223 * 'NULL' if using the 'current' global variable.
226 * pti_masterchannel struct with master, channel ID address
229 * Each bit in the arrays ia_app and ia_os correspond to a master and
230 * channel id. The bit is one if the id is taken and 0 if free. For
231 * every master there are 128 channel id's.
233 static struct pti_masterchannel
*get_id(u8
*id_array
,
236 const char *thread_name
)
238 struct pti_masterchannel
*mc
;
241 mc
= kmalloc(sizeof(struct pti_masterchannel
), GFP_KERNEL
);
245 /* look for a byte with a free bit */
246 for (i
= 0; i
< max_ids
; i
++)
247 if (id_array
[i
] != 0xff)
253 /* find the bit in the 128 possible channel opportunities */
255 for (j
= 0; j
< 8; j
++) {
256 if ((id_array
[i
] & mask
) == 0)
263 mc
->master
= base_id
;
264 mc
->channel
= ((i
& 0xf)<<3) + j
;
265 /* write new master Id / channel Id allocation to channel control */
266 pti_control_frame_built_and_sent(mc
, thread_name
);
271 * The following three functions:
272 * pti_request_mastercahannel(), mipi_release_masterchannel()
273 * and pti_writedata() are an API for other kernel drivers to
278 * pti_request_masterchannel()- Kernel API function used to allocate
279 * a master, channel ID address
280 * to write to PTI HW.
282 * @type: 0- request Application master, channel aperture ID
284 * 1- request OS master, channel aperture ID write
286 * 2- request Modem master, channel aperture ID
288 * Other values, error.
289 * @thread_name: The thread name associated with the master / channel or
290 * 'NULL' if using the 'current' global variable.
293 * pti_masterchannel struct
296 struct pti_masterchannel
*pti_request_masterchannel(u8 type
,
297 const char *thread_name
)
299 struct pti_masterchannel
*mc
;
301 mutex_lock(&alloclock
);
306 mc
= get_id(drv_data
->ia_app
, MAX_APP_IDS
,
307 APP_BASE_ID
, thread_name
);
311 mc
= get_id(drv_data
->ia_os
, MAX_OS_IDS
,
312 OS_BASE_ID
, thread_name
);
316 mc
= get_id(drv_data
->ia_modem
, MAX_MODEM_IDS
,
317 MODEM_BASE_ID
, thread_name
);
323 mutex_unlock(&alloclock
);
326 EXPORT_SYMBOL_GPL(pti_request_masterchannel
);
329 * pti_release_masterchannel()- Kernel API function used to release
330 * a master, channel ID address
331 * used to write to PTI HW.
333 * @mc: master, channel apeture ID address to be released. This
334 * will de-allocate the structure via kfree().
336 void pti_release_masterchannel(struct pti_masterchannel
*mc
)
338 u8 master
, channel
, i
;
340 mutex_lock(&alloclock
);
344 channel
= mc
->channel
;
346 if (master
== APP_BASE_ID
) {
348 drv_data
->ia_app
[i
] &= ~(0x80>>(channel
& 0x7));
349 } else if (master
== OS_BASE_ID
) {
351 drv_data
->ia_os
[i
] &= ~(0x80>>(channel
& 0x7));
354 drv_data
->ia_modem
[i
] &= ~(0x80>>(channel
& 0x7));
360 mutex_unlock(&alloclock
);
362 EXPORT_SYMBOL_GPL(pti_release_masterchannel
);
365 * pti_writedata()- Kernel API function used to write trace
366 * debugging data to PTI HW.
368 * @mc: Master, channel aperture ID address to write to.
369 * Null value will return with no write occurring.
370 * @buf: Trace debuging data to write to the PTI HW.
371 * Null value will return with no write occurring.
372 * @count: Size of buf. Value of 0 or a negative number will
373 * return with no write occuring.
375 void pti_writedata(struct pti_masterchannel
*mc
, u8
*buf
, int count
)
378 * since this function is exported, this is treated like an
379 * API function, thus, all parameters should
380 * be checked for validity.
382 if ((mc
!= NULL
) && (buf
!= NULL
) && (count
> 0))
383 pti_write_to_aperture(mc
, buf
, count
);
386 EXPORT_SYMBOL_GPL(pti_writedata
);
389 * for the tty_driver_*() basic function descriptions, see tty_driver.h.
390 * Specific header comments made for PTI-related specifics.
394 * pti_tty_driver_open()- Open an Application master, channel aperture
395 * ID to the PTI device via tty device.
397 * @tty: tty interface.
398 * @filp: filp interface pased to tty_port_open() call.
402 * otherwise, fail value
404 * The main purpose of using the tty device interface is for
405 * each tty port to have a unique PTI write aperture. In an
406 * example use case, ttyPTI0 gets syslogd and an APP aperture
407 * ID and ttyPTI1 is where the n_tracesink ldisc hooks to route
408 * modem messages into PTI. Modem trace data does not have to
409 * go to ttyPTI1, but ttyPTI0 and ttyPTI1 do need to be distinct
410 * master IDs. These messages go through the PTI HW and out of
411 * the handheld platform and to the Fido/Lauterbach device.
413 static int pti_tty_driver_open(struct tty_struct
*tty
, struct file
*filp
)
416 * we actually want to allocate a new channel per open, per
417 * system arch. HW gives more than plenty channels for a single
418 * system task to have its own channel to write trace data. This
419 * also removes a locking requirement for the actual write
422 return tty_port_open(tty
->port
, tty
, filp
);
426 * pti_tty_driver_close()- close tty device and release Application
427 * master, channel aperture ID to the PTI device via tty device.
429 * @tty: tty interface.
430 * @filp: filp interface pased to tty_port_close() call.
432 * The main purpose of using the tty device interface is to route
433 * syslog daemon messages to the PTI HW and out of the handheld platform
434 * and to the Fido/Lauterbach device.
436 static void pti_tty_driver_close(struct tty_struct
*tty
, struct file
*filp
)
438 tty_port_close(tty
->port
, tty
, filp
);
442 * pti_tty_install()- Used to set up specific master-channels
443 * to tty ports for organizational purposes when
444 * tracing viewed from debuging tools.
446 * @driver: tty driver information.
447 * @tty: tty struct containing pti information.
453 static int pti_tty_install(struct tty_driver
*driver
, struct tty_struct
*tty
)
455 int idx
= tty
->index
;
456 struct pti_tty
*pti_tty_data
;
457 int ret
= tty_standard_install(driver
, tty
);
460 pti_tty_data
= kmalloc(sizeof(struct pti_tty
), GFP_KERNEL
);
461 if (pti_tty_data
== NULL
)
464 if (idx
== PTITTY_MINOR_START
)
465 pti_tty_data
->mc
= pti_request_masterchannel(0, NULL
);
467 pti_tty_data
->mc
= pti_request_masterchannel(2, NULL
);
469 if (pti_tty_data
->mc
== NULL
) {
473 tty
->driver_data
= pti_tty_data
;
480 * pti_tty_cleanup()- Used to de-allocate master-channel resources
481 * tied to tty's of this driver.
483 * @tty: tty struct containing pti information.
485 static void pti_tty_cleanup(struct tty_struct
*tty
)
487 struct pti_tty
*pti_tty_data
= tty
->driver_data
;
488 if (pti_tty_data
== NULL
)
490 pti_release_masterchannel(pti_tty_data
->mc
);
492 tty
->driver_data
= NULL
;
496 * pti_tty_driver_write()- Write trace debugging data through the char
497 * interface to the PTI HW. Part of the misc device implementation.
499 * @tty: tty struct containing pti information.
500 * @buf: trace data to be written.
501 * @len: # of byte to write.
504 * int, # of bytes written
507 static int pti_tty_driver_write(struct tty_struct
*tty
,
508 const unsigned char *buf
, int len
)
510 struct pti_tty
*pti_tty_data
= tty
->driver_data
;
511 if ((pti_tty_data
!= NULL
) && (pti_tty_data
->mc
!= NULL
)) {
512 pti_write_to_aperture(pti_tty_data
->mc
, (u8
*)buf
, len
);
516 * we can't write to the pti hardware if the private driver_data
517 * and the mc address is not there.
524 * pti_tty_write_room()- Always returns 2048.
526 * @tty: contains tty info of the pti driver.
528 static int pti_tty_write_room(struct tty_struct
*tty
)
534 * pti_char_open()- Open an Application master, channel aperture
535 * ID to the PTI device. Part of the misc device implementation.
538 * @filp: Output- will have a masterchannel struct set containing
539 * the allocated application PTI aperture write address.
543 * otherwise, a fail value
545 static int pti_char_open(struct inode
*inode
, struct file
*filp
)
547 struct pti_masterchannel
*mc
;
550 * We really do want to fail immediately if
551 * pti_request_masterchannel() fails,
552 * before assigning the value to filp->private_data.
553 * Slightly easier to debug if this driver needs debugging.
555 mc
= pti_request_masterchannel(0, NULL
);
558 filp
->private_data
= mc
;
563 * pti_char_release()- Close a char channel to the PTI device. Part
564 * of the misc device implementation.
566 * @inode: Not used in this implementaiton.
567 * @filp: Contains private_data that contains the master, channel
568 * ID to be released by the PTI device.
573 static int pti_char_release(struct inode
*inode
, struct file
*filp
)
575 pti_release_masterchannel(filp
->private_data
);
576 filp
->private_data
= NULL
;
581 * pti_char_write()- Write trace debugging data through the char
582 * interface to the PTI HW. Part of the misc device implementation.
584 * @filp: Contains private data which is used to obtain
585 * master, channel write ID.
586 * @data: trace data to be written.
587 * @len: # of byte to write.
588 * @ppose: Not used in this function implementation.
591 * int, # of bytes written
592 * otherwise, error value
594 * Notes: From side discussions with Alan Cox and experimenting
595 * with PTI debug HW like Nokia's Fido box and Lauterbach
596 * devices, 8192 byte write buffer used by USER_COPY_SIZE was
597 * deemed an appropriate size for this type of usage with
600 static ssize_t
pti_char_write(struct file
*filp
, const char __user
*data
,
601 size_t len
, loff_t
*ppose
)
603 struct pti_masterchannel
*mc
;
605 const char __user
*tmp
;
606 size_t size
= USER_COPY_SIZE
;
610 mc
= filp
->private_data
;
612 kbuf
= kmalloc(size
, GFP_KERNEL
);
614 pr_err("%s(%d): buf allocation failed\n",
620 if (len
- n
> USER_COPY_SIZE
)
621 size
= USER_COPY_SIZE
;
625 if (copy_from_user(kbuf
, tmp
, size
)) {
627 return n
? n
: -EFAULT
;
630 pti_write_to_aperture(mc
, kbuf
, size
);
640 static const struct tty_operations pti_tty_driver_ops
= {
641 .open
= pti_tty_driver_open
,
642 .close
= pti_tty_driver_close
,
643 .write
= pti_tty_driver_write
,
644 .write_room
= pti_tty_write_room
,
645 .install
= pti_tty_install
,
646 .cleanup
= pti_tty_cleanup
649 static const struct file_operations pti_char_driver_ops
= {
650 .owner
= THIS_MODULE
,
651 .write
= pti_char_write
,
652 .open
= pti_char_open
,
653 .release
= pti_char_release
,
656 static struct miscdevice pti_char_driver
= {
657 .minor
= MISC_DYNAMIC_MINOR
,
659 .fops
= &pti_char_driver_ops
663 * pti_console_write()- Write to the console that has been acquired.
665 * @c: Not used in this implementaiton.
666 * @buf: Data to be written.
667 * @len: Length of buf.
669 static void pti_console_write(struct console
*c
, const char *buf
, unsigned len
)
671 static struct pti_masterchannel mc
= {.master
= CONSOLE_ID
,
674 mc
.channel
= pti_console_channel
;
675 pti_console_channel
= (pti_console_channel
+ 1) & 0x7f;
677 pti_write_full_frame_to_aperture(&mc
, buf
, len
);
681 * pti_console_device()- Return the driver tty structure and set the
682 * associated index implementation.
684 * @c: Console device of the driver.
685 * @index: index associated with c.
688 * always value of pti_tty_driver structure when this function
691 static struct tty_driver
*pti_console_device(struct console
*c
, int *index
)
694 return pti_tty_driver
;
698 * pti_console_setup()- Initialize console variables used by the driver.
706 static int pti_console_setup(struct console
*c
, char *opts
)
708 pti_console_channel
= 0;
709 pti_control_channel
= 0;
714 * pti_console struct, used to capture OS printk()'s and shift
715 * out to the PTI device for debugging. This cannot be
716 * enabled upon boot because of the possibility of eating
717 * any serial console printk's (race condition discovered).
718 * The console should be enabled upon when the tty port is
719 * used for the first time. Since the primary purpose for
720 * the tty port is to hook up syslog to it, the tty port
721 * will be open for a really long time.
723 static struct console pti_console
= {
725 .write
= pti_console_write
,
726 .device
= pti_console_device
,
727 .setup
= pti_console_setup
,
728 .flags
= CON_PRINTBUFFER
,
733 * pti_port_activate()- Used to start/initialize any items upon
734 * first opening of tty_port().
736 * @port: The tty port number of the PTI device.
737 * @tty: The tty struct associated with this device.
742 * Notes: The primary purpose of the PTI tty port 0 is to hook
743 * the syslog daemon to it; thus this port will be open for a
746 static int pti_port_activate(struct tty_port
*port
, struct tty_struct
*tty
)
748 if (port
->tty
->index
== PTITTY_MINOR_START
)
749 console_start(&pti_console
);
754 * pti_port_shutdown()- Used to stop/shutdown any items upon the
755 * last tty port close.
757 * @port: The tty port number of the PTI device.
759 * Notes: The primary purpose of the PTI tty port 0 is to hook
760 * the syslog daemon to it; thus this port will be open for a
763 static void pti_port_shutdown(struct tty_port
*port
)
765 if (port
->tty
->index
== PTITTY_MINOR_START
)
766 console_stop(&pti_console
);
769 static const struct tty_port_operations tty_port_ops
= {
770 .activate
= pti_port_activate
,
771 .shutdown
= pti_port_shutdown
,
775 * Note the _probe() call sets everything up and ties the char and tty
776 * to successfully detecting the PTI device on the pci bus.
780 * pti_pci_probe()- Used to detect pti on the pci bus and set
781 * things up in the driver.
783 * @pdev: pci_dev struct values for pti.
784 * @ent: pci_device_id struct for pti driver.
790 static int pti_pci_probe(struct pci_dev
*pdev
,
791 const struct pci_device_id
*ent
)
797 dev_dbg(&pdev
->dev
, "%s %s(%d): PTI PCI ID %04x:%04x\n", __FILE__
,
798 __func__
, __LINE__
, pdev
->vendor
, pdev
->device
);
800 retval
= misc_register(&pti_char_driver
);
802 pr_err("%s(%d): CHAR registration failed of pti driver\n",
804 pr_err("%s(%d): Error value returned: %d\n",
805 __func__
, __LINE__
, retval
);
809 retval
= pci_enable_device(pdev
);
812 "%s: pci_enable_device() returned error %d\n",
817 drv_data
= kzalloc(sizeof(*drv_data
), GFP_KERNEL
);
818 if (drv_data
== NULL
) {
821 "%s(%d): kmalloc() returned NULL memory.\n",
823 goto err_disable_pci
;
825 drv_data
->pti_addr
= pci_resource_start(pdev
, pci_bar
);
827 retval
= pci_request_region(pdev
, pci_bar
, dev_name(&pdev
->dev
));
830 "%s(%d): pci_request_region() returned error %d\n",
831 __func__
, __LINE__
, retval
);
834 drv_data
->aperture_base
= drv_data
->pti_addr
+APERTURE_14
;
835 drv_data
->pti_ioaddr
=
836 ioremap((u32
)drv_data
->aperture_base
,
838 if (!drv_data
->pti_ioaddr
) {
843 pci_set_drvdata(pdev
, drv_data
);
845 for (a
= 0; a
< PTITTY_MINOR_NUM
; a
++) {
846 struct tty_port
*port
= &drv_data
->port
[a
];
848 port
->ops
= &tty_port_ops
;
850 tty_port_register_device(port
, pti_tty_driver
, a
, &pdev
->dev
);
853 register_console(&pti_console
);
857 pci_release_region(pdev
, pci_bar
);
861 pci_disable_device(pdev
);
863 misc_deregister(&pti_char_driver
);
869 * pti_pci_remove()- Driver exit method to remove PTI from
871 * @pdev: variable containing pci info of PTI.
873 static void pti_pci_remove(struct pci_dev
*pdev
)
875 struct pti_dev
*drv_data
= pci_get_drvdata(pdev
);
878 unregister_console(&pti_console
);
880 for (a
= 0; a
< PTITTY_MINOR_NUM
; a
++) {
881 tty_unregister_device(pti_tty_driver
, a
);
882 tty_port_destroy(&drv_data
->port
[a
]);
885 iounmap(drv_data
->pti_ioaddr
);
887 pci_release_region(pdev
, 1);
888 pci_disable_device(pdev
);
890 misc_deregister(&pti_char_driver
);
893 static struct pci_driver pti_pci_driver
= {
896 .probe
= pti_pci_probe
,
897 .remove
= pti_pci_remove
,
901 * pti_init()- Overall entry/init call to the pti driver.
902 * It starts the registration process with the kernel.
905 * int __init, 0 for success
906 * otherwise value is an error
909 static int __init
pti_init(void)
913 /* First register module as tty device */
915 pti_tty_driver
= alloc_tty_driver(PTITTY_MINOR_NUM
);
916 if (pti_tty_driver
== NULL
) {
917 pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n",
922 pti_tty_driver
->driver_name
= DRIVERNAME
;
923 pti_tty_driver
->name
= TTYNAME
;
924 pti_tty_driver
->major
= 0;
925 pti_tty_driver
->minor_start
= PTITTY_MINOR_START
;
926 pti_tty_driver
->type
= TTY_DRIVER_TYPE_SYSTEM
;
927 pti_tty_driver
->subtype
= SYSTEM_TYPE_SYSCONS
;
928 pti_tty_driver
->flags
= TTY_DRIVER_REAL_RAW
|
929 TTY_DRIVER_DYNAMIC_DEV
;
930 pti_tty_driver
->init_termios
= tty_std_termios
;
932 tty_set_operations(pti_tty_driver
, &pti_tty_driver_ops
);
934 retval
= tty_register_driver(pti_tty_driver
);
936 pr_err("%s(%d): TTY registration failed of pti driver\n",
938 pr_err("%s(%d): Error value returned: %d\n",
939 __func__
, __LINE__
, retval
);
944 retval
= pci_register_driver(&pti_pci_driver
);
946 pr_err("%s(%d): PCI registration failed of pti driver\n",
948 pr_err("%s(%d): Error value returned: %d\n",
949 __func__
, __LINE__
, retval
);
955 tty_unregister_driver(pti_tty_driver
);
957 put_tty_driver(pti_tty_driver
);
958 pti_tty_driver
= NULL
;
963 * pti_exit()- Unregisters this module as a tty and pci driver.
965 static void __exit
pti_exit(void)
967 tty_unregister_driver(pti_tty_driver
);
968 pci_unregister_driver(&pti_pci_driver
);
969 put_tty_driver(pti_tty_driver
);
972 module_init(pti_init
);
973 module_exit(pti_exit
);
975 MODULE_LICENSE("GPL");
976 MODULE_AUTHOR("Ken Mills, Jay Freyensee");
977 MODULE_DESCRIPTION("PTI Driver");