blob: 1be992d568c8344afe0d280886ae7e869ea9fcb8 [file] [log] [blame]
Geoff Levand74e95d5d2006-12-08 18:27:47 -08001/*
2 * PS3 virtual uart
3 *
4 * Copyright (C) 2006 Sony Computer Entertainment Inc.
5 * Copyright 2006 Sony Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#if !defined(_PS3_VUART_H)
22#define _PS3_VUART_H
23
Geoff Levand75c86e72007-02-13 17:37:28 -080024#include <asm/ps3.h>
25
26struct ps3_vuart_stats {
27 unsigned long bytes_written;
28 unsigned long bytes_read;
29 unsigned long tx_interrupts;
30 unsigned long rx_interrupts;
31 unsigned long disconnect_interrupts;
32};
33
Geoff Levandea1547d2007-02-06 14:23:47 -080034struct ps3_vuart_work {
35 struct work_struct work;
36 unsigned long trigger;
37 spinlock_t lock;
38 struct ps3_vuart_port_device* dev; /* to convert work to device */
39};
40
Geoff Levand75c86e72007-02-13 17:37:28 -080041/**
42 * struct ps3_vuart_port_priv - private vuart device data.
43 */
44
45struct ps3_vuart_port_priv {
46 unsigned int port_number;
47 u64 interrupt_mask;
48
49 struct {
50 spinlock_t lock;
51 struct list_head head;
52 } tx_list;
53 struct {
54 unsigned long bytes_held;
55 spinlock_t lock;
56 struct list_head head;
57 } rx_list;
58 struct ps3_vuart_stats stats;
Geoff Levandea1547d2007-02-06 14:23:47 -080059 struct ps3_vuart_work work;
Geoff Levand75c86e72007-02-13 17:37:28 -080060};
61
Geoff Levand74e95d5d2006-12-08 18:27:47 -080062/**
63 * struct ps3_vuart_port_driver - a driver for a device on a vuart port
64 */
65
66struct ps3_vuart_port_driver {
67 enum ps3_match_id match_id;
68 struct device_driver core;
69 int (*probe)(struct ps3_vuart_port_device *);
70 int (*remove)(struct ps3_vuart_port_device *);
Geert Uytterhoeven5b8e8ee2007-02-12 00:55:15 -080071 void (*shutdown)(struct ps3_vuart_port_device *);
Geoff Levand74e95d5d2006-12-08 18:27:47 -080072 int (*tx_event)(struct ps3_vuart_port_device *dev);
73 int (*rx_event)(struct ps3_vuart_port_device *dev);
74 int (*disconnect_event)(struct ps3_vuart_port_device *dev);
75 /* int (*suspend)(struct ps3_vuart_port_device *, pm_message_t); */
76 /* int (*resume)(struct ps3_vuart_port_device *); */
77};
78
Geoff Levand74e95d5d2006-12-08 18:27:47 -080079int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv);
80void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv);
Geoff Levand97ec1672007-01-30 15:20:30 -080081
Geoff Levand74e95d5d2006-12-08 18:27:47 -080082static inline struct ps3_vuart_port_driver *to_ps3_vuart_port_driver(
83 struct device_driver *_drv)
84{
85 return container_of(_drv, struct ps3_vuart_port_driver, core);
86}
87static inline struct ps3_vuart_port_device *to_ps3_vuart_port_device(
88 struct device *_dev)
89{
90 return container_of(_dev, struct ps3_vuart_port_device, core);
91}
Geoff Levandea1547d2007-02-06 14:23:47 -080092static inline struct ps3_vuart_port_device *ps3_vuart_work_to_port_device(
93 struct work_struct *_work)
94{
95 struct ps3_vuart_work *vw = container_of(_work, struct ps3_vuart_work,
96 work);
97 return vw->dev;
98}
99
100int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
101 unsigned int bytes);
102int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
103 unsigned int bytes);
104int ps3_vuart_read_async(struct ps3_vuart_port_device *dev, work_func_t func,
105 unsigned int bytes);
106void ps3_vuart_cancel_async(struct ps3_vuart_port_device *dev);
107void ps3_vuart_clear_rx_bytes(struct ps3_vuart_port_device *dev,
108 unsigned int bytes);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800109
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800110#endif