174e95d5dSGeoff Levand /* 274e95d5dSGeoff Levand * PS3 virtual uart 374e95d5dSGeoff Levand * 474e95d5dSGeoff Levand * Copyright (C) 2006 Sony Computer Entertainment Inc. 574e95d5dSGeoff Levand * Copyright 2006 Sony Corp. 674e95d5dSGeoff Levand * 774e95d5dSGeoff Levand * This program is free software; you can redistribute it and/or modify 874e95d5dSGeoff Levand * it under the terms of the GNU General Public License as published by 974e95d5dSGeoff Levand * the Free Software Foundation; version 2 of the License. 1074e95d5dSGeoff Levand * 1174e95d5dSGeoff Levand * This program is distributed in the hope that it will be useful, 1274e95d5dSGeoff Levand * but WITHOUT ANY WARRANTY; without even the implied warranty of 1374e95d5dSGeoff Levand * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1474e95d5dSGeoff Levand * GNU General Public License for more details. 1574e95d5dSGeoff Levand * 1674e95d5dSGeoff Levand * You should have received a copy of the GNU General Public License 1774e95d5dSGeoff Levand * along with this program; if not, write to the Free Software 1874e95d5dSGeoff Levand * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1974e95d5dSGeoff Levand */ 2074e95d5dSGeoff Levand 2174e95d5dSGeoff Levand #if !defined(_PS3_VUART_H) 2274e95d5dSGeoff Levand #define _PS3_VUART_H 2374e95d5dSGeoff Levand 2475c86e74SGeoff Levand #include <asm/ps3.h> 2575c86e74SGeoff Levand 2675c86e74SGeoff Levand struct ps3_vuart_stats { 2775c86e74SGeoff Levand unsigned long bytes_written; 2875c86e74SGeoff Levand unsigned long bytes_read; 2975c86e74SGeoff Levand unsigned long tx_interrupts; 3075c86e74SGeoff Levand unsigned long rx_interrupts; 3175c86e74SGeoff Levand unsigned long disconnect_interrupts; 3275c86e74SGeoff Levand }; 3375c86e74SGeoff Levand 34*ea1547d3SGeoff Levand struct ps3_vuart_work { 35*ea1547d3SGeoff Levand struct work_struct work; 36*ea1547d3SGeoff Levand unsigned long trigger; 37*ea1547d3SGeoff Levand spinlock_t lock; 38*ea1547d3SGeoff Levand struct ps3_vuart_port_device* dev; /* to convert work to device */ 39*ea1547d3SGeoff Levand }; 40*ea1547d3SGeoff Levand 4175c86e74SGeoff Levand /** 4275c86e74SGeoff Levand * struct ps3_vuart_port_priv - private vuart device data. 4375c86e74SGeoff Levand */ 4475c86e74SGeoff Levand 4575c86e74SGeoff Levand struct ps3_vuart_port_priv { 4675c86e74SGeoff Levand unsigned int port_number; 4775c86e74SGeoff Levand u64 interrupt_mask; 4875c86e74SGeoff Levand 4975c86e74SGeoff Levand struct { 5075c86e74SGeoff Levand spinlock_t lock; 5175c86e74SGeoff Levand struct list_head head; 5275c86e74SGeoff Levand } tx_list; 5375c86e74SGeoff Levand struct { 5475c86e74SGeoff Levand unsigned long bytes_held; 5575c86e74SGeoff Levand spinlock_t lock; 5675c86e74SGeoff Levand struct list_head head; 5775c86e74SGeoff Levand } rx_list; 5875c86e74SGeoff Levand struct ps3_vuart_stats stats; 59*ea1547d3SGeoff Levand struct ps3_vuart_work work; 6075c86e74SGeoff Levand }; 6175c86e74SGeoff Levand 6274e95d5dSGeoff Levand /** 6374e95d5dSGeoff Levand * struct ps3_vuart_port_driver - a driver for a device on a vuart port 6474e95d5dSGeoff Levand */ 6574e95d5dSGeoff Levand 6674e95d5dSGeoff Levand struct ps3_vuart_port_driver { 6774e95d5dSGeoff Levand enum ps3_match_id match_id; 6874e95d5dSGeoff Levand struct device_driver core; 6974e95d5dSGeoff Levand int (*probe)(struct ps3_vuart_port_device *); 7074e95d5dSGeoff Levand int (*remove)(struct ps3_vuart_port_device *); 715b8e8ee6SGeert Uytterhoeven void (*shutdown)(struct ps3_vuart_port_device *); 7274e95d5dSGeoff Levand int (*tx_event)(struct ps3_vuart_port_device *dev); 7374e95d5dSGeoff Levand int (*rx_event)(struct ps3_vuart_port_device *dev); 7474e95d5dSGeoff Levand int (*disconnect_event)(struct ps3_vuart_port_device *dev); 7574e95d5dSGeoff Levand /* int (*suspend)(struct ps3_vuart_port_device *, pm_message_t); */ 7674e95d5dSGeoff Levand /* int (*resume)(struct ps3_vuart_port_device *); */ 7774e95d5dSGeoff Levand }; 7874e95d5dSGeoff Levand 7974e95d5dSGeoff Levand int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv); 8074e95d5dSGeoff Levand void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv); 8197ec1675SGeoff Levand 8274e95d5dSGeoff Levand static inline struct ps3_vuart_port_driver *to_ps3_vuart_port_driver( 8374e95d5dSGeoff Levand struct device_driver *_drv) 8474e95d5dSGeoff Levand { 8574e95d5dSGeoff Levand return container_of(_drv, struct ps3_vuart_port_driver, core); 8674e95d5dSGeoff Levand } 8774e95d5dSGeoff Levand static inline struct ps3_vuart_port_device *to_ps3_vuart_port_device( 8874e95d5dSGeoff Levand struct device *_dev) 8974e95d5dSGeoff Levand { 9074e95d5dSGeoff Levand return container_of(_dev, struct ps3_vuart_port_device, core); 9174e95d5dSGeoff Levand } 92*ea1547d3SGeoff Levand static inline struct ps3_vuart_port_device *ps3_vuart_work_to_port_device( 93*ea1547d3SGeoff Levand struct work_struct *_work) 94*ea1547d3SGeoff Levand { 95*ea1547d3SGeoff Levand struct ps3_vuart_work *vw = container_of(_work, struct ps3_vuart_work, 96*ea1547d3SGeoff Levand work); 97*ea1547d3SGeoff Levand return vw->dev; 98*ea1547d3SGeoff Levand } 99*ea1547d3SGeoff Levand 100*ea1547d3SGeoff Levand int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf, 101*ea1547d3SGeoff Levand unsigned int bytes); 102*ea1547d3SGeoff Levand int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf, 103*ea1547d3SGeoff Levand unsigned int bytes); 104*ea1547d3SGeoff Levand int ps3_vuart_read_async(struct ps3_vuart_port_device *dev, work_func_t func, 105*ea1547d3SGeoff Levand unsigned int bytes); 106*ea1547d3SGeoff Levand void ps3_vuart_cancel_async(struct ps3_vuart_port_device *dev); 107*ea1547d3SGeoff Levand void ps3_vuart_clear_rx_bytes(struct ps3_vuart_port_device *dev, 108*ea1547d3SGeoff Levand unsigned int bytes); 10974e95d5dSGeoff Levand 11074e95d5dSGeoff Levand #endif 111