xref: /openbmc/linux/drivers/ps3/vuart.h (revision 6baa5ecd6e9631a71423578a4a95dc8b179df386)
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 
34ea1547d3SGeoff Levand struct ps3_vuart_work {
35ea1547d3SGeoff Levand 	struct work_struct work;
36ea1547d3SGeoff Levand 	unsigned long trigger;
377626e78dSGeoff Levand 	struct ps3_system_bus_device *dev; /* to convert work to device */
3875c86e74SGeoff Levand };
3975c86e74SGeoff Levand 
4074e95d5dSGeoff Levand /**
4174e95d5dSGeoff Levand  * struct ps3_vuart_port_driver - a driver for a device on a vuart port
4274e95d5dSGeoff Levand  */
4374e95d5dSGeoff Levand 
4474e95d5dSGeoff Levand struct ps3_vuart_port_driver {
457626e78dSGeoff Levand 	struct ps3_system_bus_driver core;
467626e78dSGeoff Levand 	int (*probe)(struct ps3_system_bus_device *);
477626e78dSGeoff Levand 	int (*remove)(struct ps3_system_bus_device *);
487626e78dSGeoff Levand 	void (*shutdown)(struct ps3_system_bus_device *);
497626e78dSGeoff Levand 	void (*work)(struct ps3_system_bus_device *);
507626e78dSGeoff Levand 	/* int (*tx_event)(struct ps3_system_bus_device *dev); */
517626e78dSGeoff Levand 	/* int (*rx_event)(struct ps3_system_bus_device *dev); */
527626e78dSGeoff Levand 	/* int (*disconnect_event)(struct ps3_system_bus_device *dev); */
537626e78dSGeoff Levand 	/* int (*suspend)(struct ps3_system_bus_device *, pm_message_t); */
547626e78dSGeoff Levand 	/* int (*resume)(struct ps3_system_bus_device *); */
5574e95d5dSGeoff Levand };
5674e95d5dSGeoff Levand 
5774e95d5dSGeoff Levand int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv);
5874e95d5dSGeoff Levand void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv);
5997ec1675SGeoff Levand 
607626e78dSGeoff Levand static inline struct ps3_vuart_port_driver *
617626e78dSGeoff Levand 	ps3_system_bus_dev_to_vuart_drv(struct ps3_system_bus_device *_dev)
6274e95d5dSGeoff Levand {
637626e78dSGeoff Levand 	struct ps3_system_bus_driver *sbd =
647626e78dSGeoff Levand 		ps3_system_bus_dev_to_system_bus_drv(_dev);
657626e78dSGeoff Levand 	BUG_ON(!sbd);
667626e78dSGeoff Levand 	return container_of(sbd, struct ps3_vuart_port_driver, core);
6774e95d5dSGeoff Levand }
687626e78dSGeoff Levand static inline struct ps3_system_bus_device *ps3_vuart_work_to_system_bus_dev(
69ea1547d3SGeoff Levand 	struct work_struct *_work)
70ea1547d3SGeoff Levand {
71ea1547d3SGeoff Levand 	struct ps3_vuart_work *vw = container_of(_work, struct ps3_vuart_work,
72ea1547d3SGeoff Levand 		work);
73ea1547d3SGeoff Levand 	return vw->dev;
74ea1547d3SGeoff Levand }
75ea1547d3SGeoff Levand 
767626e78dSGeoff Levand int ps3_vuart_write(struct ps3_system_bus_device *dev, const void *buf,
77ea1547d3SGeoff Levand 	unsigned int bytes);
787626e78dSGeoff Levand int ps3_vuart_read(struct ps3_system_bus_device *dev, void *buf,
79ea1547d3SGeoff Levand 	unsigned int bytes);
807626e78dSGeoff Levand int ps3_vuart_read_async(struct ps3_system_bus_device *dev, unsigned int bytes);
817626e78dSGeoff Levand void ps3_vuart_cancel_async(struct ps3_system_bus_device *dev);
827626e78dSGeoff Levand void ps3_vuart_clear_rx_bytes(struct ps3_system_bus_device *dev,
83ea1547d3SGeoff Levand 	unsigned int bytes);
8474e95d5dSGeoff Levand 
85*6baa5ecdSGeoff Levand struct vuart_triggers {
86*6baa5ecdSGeoff Levand 	unsigned long rx;
87*6baa5ecdSGeoff Levand 	unsigned long tx;
88*6baa5ecdSGeoff Levand };
89*6baa5ecdSGeoff Levand 
90*6baa5ecdSGeoff Levand int ps3_vuart_get_triggers(struct ps3_system_bus_device *dev,
91*6baa5ecdSGeoff Levand 	struct vuart_triggers *trig);
92*6baa5ecdSGeoff Levand int ps3_vuart_set_triggers(struct ps3_system_bus_device *dev, unsigned int tx,
93*6baa5ecdSGeoff Levand 	unsigned int rx);
94*6baa5ecdSGeoff Levand int ps3_vuart_enable_interrupt_tx(struct ps3_system_bus_device *dev);
95*6baa5ecdSGeoff Levand int ps3_vuart_disable_interrupt_tx(struct ps3_system_bus_device *dev);
96*6baa5ecdSGeoff Levand int ps3_vuart_enable_interrupt_rx(struct ps3_system_bus_device *dev);
97*6baa5ecdSGeoff Levand int ps3_vuart_disable_interrupt_rx(struct ps3_system_bus_device *dev);
98*6baa5ecdSGeoff Levand int ps3_vuart_enable_interrupt_disconnect(struct ps3_system_bus_device *dev);
99*6baa5ecdSGeoff Levand int ps3_vuart_disable_interrupt_disconnect(struct ps3_system_bus_device *dev);
100*6baa5ecdSGeoff Levand 
10174e95d5dSGeoff Levand #endif
102