4 * Copyright (C) 2006 Sony Computer Entertainment Inc.
5 * Copyright 2006 Sony Corp.
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.
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.
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
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/interrupt.h>
26 #include <asm/firmware.h>
27 #include <asm/lv1call.h>
28 #include <asm/bitops.h>
32 MODULE_AUTHOR("Sony Corporation");
33 MODULE_LICENSE("GPL v2");
34 MODULE_DESCRIPTION("PS3 vuart");
37 * vuart - An inter-partition data link service.
38 * port 0: PS3 AV Settings.
39 * port 2: PS3 System Manager.
41 * The vuart provides a bi-directional byte stream data link between logical
42 * partitions. Its primary role is as a communications link between the guest
43 * OS and the system policy module. The current HV does not support any
44 * connections other than those listed.
47 enum {PORT_COUNT = 3,};
52 PARAM_INTERRUPT_MASK = 2,
53 PARAM_RX_BUF_SIZE = 3, /* read only */
54 PARAM_RX_BYTES = 4, /* read only */
55 PARAM_TX_BUF_SIZE = 5, /* read only */
56 PARAM_TX_BYTES = 6, /* read only */
57 PARAM_INTERRUPT_STATUS = 7, /* read only */
60 enum vuart_interrupt_bit {
63 INTERRUPT_BIT_DISCONNECT = 2,
66 enum vuart_interrupt_mask {
67 INTERRUPT_MASK_TX = 1,
68 INTERRUPT_MASK_RX = 2,
69 INTERRUPT_MASK_DISCONNECT = 4,
73 * struct ports_bmp - bitmap indicating ports needing service.
75 * A 256 bit read only bitmap indicating ports needing service. Do not write
76 * to these bits. Must not cross a page boundary.
82 } __attribute__ ((aligned (32)));
84 /* redefine dev_dbg to do a syntax check */
88 static inline int __attribute__ ((format (printf, 2, 3))) dev_dbg(
89 const struct device *_dev, const char *fmt, ...) {return 0;}
92 #define dump_ports_bmp(_b) _dump_ports_bmp(_b, __func__, __LINE__)
93 static void __attribute__ ((unused)) _dump_ports_bmp(
94 const struct ports_bmp* bmp, const char* func, int line)
96 pr_debug("%s:%d: ports_bmp: %016lxh\n", func, line, bmp->status);
99 static int ps3_vuart_match_id_to_port(enum ps3_match_id match_id,
100 unsigned int *port_number)
103 case PS3_MATCH_ID_AV_SETTINGS:
106 case PS3_MATCH_ID_SYSTEM_MANAGER:
111 *port_number = UINT_MAX;
116 #define dump_port_params(_b) _dump_port_params(_b, __func__, __LINE__)
117 static void __attribute__ ((unused)) _dump_port_params(unsigned int port_number,
118 const char* func, int line)
121 static const char *strings[] = {
135 for (i = 0; i < ARRAY_SIZE(strings); i++) {
136 result = lv1_get_virtual_uart_param(port_number, i, &value);
139 pr_debug("%s:%d: port_%u: %s failed: %s\n", func, line,
140 port_number, strings[i], ps3_result(result));
143 pr_debug("%s:%d: port_%u: %s = %lxh\n",
144 func, line, port_number, strings[i], value);
149 struct vuart_triggers {
154 int ps3_vuart_get_triggers(struct ps3_vuart_port_device *dev,
155 struct vuart_triggers *trig)
161 result = lv1_get_virtual_uart_param(dev->priv->port_number,
162 PARAM_TX_TRIGGER, &trig->tx);
165 dev_dbg(&dev->core, "%s:%d: tx_trigger failed: %s\n",
166 __func__, __LINE__, ps3_result(result));
170 result = lv1_get_virtual_uart_param(dev->priv->port_number,
171 PARAM_RX_BUF_SIZE, &size);
174 dev_dbg(&dev->core, "%s:%d: tx_buf_size failed: %s\n",
175 __func__, __LINE__, ps3_result(result));
179 result = lv1_get_virtual_uart_param(dev->priv->port_number,
180 PARAM_RX_TRIGGER, &val);
183 dev_dbg(&dev->core, "%s:%d: rx_trigger failed: %s\n",
184 __func__, __LINE__, ps3_result(result));
188 trig->rx = size - val;
190 dev_dbg(&dev->core, "%s:%d: tx %lxh, rx %lxh\n", __func__, __LINE__,
196 int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
202 result = lv1_set_virtual_uart_param(dev->priv->port_number,
203 PARAM_TX_TRIGGER, tx);
206 dev_dbg(&dev->core, "%s:%d: tx_trigger failed: %s\n",
207 __func__, __LINE__, ps3_result(result));
211 result = lv1_get_virtual_uart_param(dev->priv->port_number,
212 PARAM_RX_BUF_SIZE, &size);
215 dev_dbg(&dev->core, "%s:%d: tx_buf_size failed: %s\n",
216 __func__, __LINE__, ps3_result(result));
220 result = lv1_set_virtual_uart_param(dev->priv->port_number,
221 PARAM_RX_TRIGGER, size - rx);
224 dev_dbg(&dev->core, "%s:%d: rx_trigger failed: %s\n",
225 __func__, __LINE__, ps3_result(result));
229 dev_dbg(&dev->core, "%s:%d: tx %xh, rx %xh\n", __func__, __LINE__,
235 static int ps3_vuart_get_rx_bytes_waiting(struct ps3_vuart_port_device *dev,
238 int result = lv1_get_virtual_uart_param(dev->priv->port_number,
239 PARAM_RX_BYTES, bytes_waiting);
242 dev_dbg(&dev->core, "%s:%d: rx_bytes failed: %s\n",
243 __func__, __LINE__, ps3_result(result));
245 dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__,
250 static int ps3_vuart_set_interrupt_mask(struct ps3_vuart_port_device *dev,
255 dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__, mask);
257 dev->priv->interrupt_mask = mask;
259 result = lv1_set_virtual_uart_param(dev->priv->port_number,
260 PARAM_INTERRUPT_MASK, dev->priv->interrupt_mask);
263 dev_dbg(&dev->core, "%s:%d: interrupt_mask failed: %s\n",
264 __func__, __LINE__, ps3_result(result));
269 static int ps3_vuart_get_interrupt_status(struct ps3_vuart_port_device *dev,
270 unsigned long *status)
273 int result = lv1_get_virtual_uart_param(dev->priv->port_number,
274 PARAM_INTERRUPT_STATUS, &tmp);
277 dev_dbg(&dev->core, "%s:%d: interrupt_status failed: %s\n",
278 __func__, __LINE__, ps3_result(result));
280 *status = tmp & dev->priv->interrupt_mask;
282 dev_dbg(&dev->core, "%s:%d: m %lxh, s %lxh, m&s %lxh\n",
283 __func__, __LINE__, dev->priv->interrupt_mask, tmp, *status);
288 int ps3_vuart_enable_interrupt_tx(struct ps3_vuart_port_device *dev)
290 return (dev->priv->interrupt_mask & INTERRUPT_MASK_TX) ? 0
291 : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
292 | INTERRUPT_MASK_TX);
295 int ps3_vuart_enable_interrupt_rx(struct ps3_vuart_port_device *dev)
297 return (dev->priv->interrupt_mask & INTERRUPT_MASK_RX) ? 0
298 : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
299 | INTERRUPT_MASK_RX);
302 int ps3_vuart_enable_interrupt_disconnect(struct ps3_vuart_port_device *dev)
304 return (dev->priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT) ? 0
305 : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
306 | INTERRUPT_MASK_DISCONNECT);
309 int ps3_vuart_disable_interrupt_tx(struct ps3_vuart_port_device *dev)
311 return (dev->priv->interrupt_mask & INTERRUPT_MASK_TX)
312 ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
313 & ~INTERRUPT_MASK_TX) : 0;
316 int ps3_vuart_disable_interrupt_rx(struct ps3_vuart_port_device *dev)
318 return (dev->priv->interrupt_mask & INTERRUPT_MASK_RX)
319 ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
320 & ~INTERRUPT_MASK_RX) : 0;
323 int ps3_vuart_disable_interrupt_disconnect(struct ps3_vuart_port_device *dev)
325 return (dev->priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT)
326 ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
327 & ~INTERRUPT_MASK_DISCONNECT) : 0;
331 * ps3_vuart_raw_write - Low level write helper.
333 * Do not call ps3_vuart_raw_write directly, use ps3_vuart_write.
336 static int ps3_vuart_raw_write(struct ps3_vuart_port_device *dev,
337 const void* buf, unsigned int bytes, unsigned long *bytes_written)
341 result = lv1_write_virtual_uart(dev->priv->port_number,
342 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_written);
345 dev_dbg(&dev->core, "%s:%d: lv1_write_virtual_uart failed: "
346 "%s\n", __func__, __LINE__, ps3_result(result));
350 dev->priv->stats.bytes_written += *bytes_written;
352 dev_dbg(&dev->core, "%s:%d: wrote %lxh/%xh=>%lxh\n", __func__, __LINE__,
353 *bytes_written, bytes, dev->priv->stats.bytes_written);
359 * ps3_vuart_raw_read - Low level read helper.
361 * Do not call ps3_vuart_raw_read directly, use ps3_vuart_read.
364 static int ps3_vuart_raw_read(struct ps3_vuart_port_device *dev, void* buf,
365 unsigned int bytes, unsigned long *bytes_read)
369 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes);
371 result = lv1_read_virtual_uart(dev->priv->port_number,
372 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_read);
375 dev_dbg(&dev->core, "%s:%d: lv1_read_virtual_uart failed: %s\n",
376 __func__, __LINE__, ps3_result(result));
380 dev->priv->stats.bytes_read += *bytes_read;
382 dev_dbg(&dev->core, "%s:%d: read %lxh/%xh=>%lxh\n", __func__, __LINE__,
383 *bytes_read, bytes, dev->priv->stats.bytes_read);
389 * ps3_vuart_clear_rx_bytes - Discard bytes received.
390 * @bytes: Max byte count to discard, zero = all pending.
392 * Used to clear pending rx interrupt source. Will not block.
395 void ps3_vuart_clear_rx_bytes(struct ps3_vuart_port_device *dev,
402 result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes_waiting);
406 bytes = bytes ? min(bytes, (unsigned int)bytes_waiting) : bytes_waiting;
408 dev_dbg(&dev->core, "%s:%d: %u\n", __func__, __LINE__, bytes);
413 /* Add some extra space for recently arrived data. */
417 tmp = kmalloc(bytes, GFP_KERNEL);
422 ps3_vuart_raw_read(dev, tmp, bytes, &bytes_waiting);
426 /* Don't include these bytes in the stats. */
428 dev->priv->stats.bytes_read -= bytes_waiting;
432 * struct list_buffer - An element for a port device fifo buffer list.
436 struct list_head link;
437 const unsigned char *head;
438 const unsigned char *tail;
439 unsigned long dbg_number;
440 unsigned char data[];
444 * ps3_vuart_write - the entry point for writing data to a port
446 * If the port is idle on entry as much of the incoming data is written to
447 * the port as the port will accept. Otherwise a list buffer is created
448 * and any remaning incoming data is copied to that buffer. The buffer is
449 * then enqueued for transmision via the transmit interrupt.
452 int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
455 static unsigned long dbg_number;
458 struct list_buffer *lb;
460 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
463 spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
465 if (list_empty(&dev->priv->tx_list.head)) {
466 unsigned long bytes_written;
468 result = ps3_vuart_raw_write(dev, buf, bytes, &bytes_written);
470 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
474 "%s:%d: ps3_vuart_raw_write failed\n",
479 if (bytes_written == bytes) {
480 dev_dbg(&dev->core, "%s:%d: wrote %xh bytes\n",
481 __func__, __LINE__, bytes);
485 bytes -= bytes_written;
486 buf += bytes_written;
488 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
490 lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_KERNEL);
496 memcpy(lb->data, buf, bytes);
498 lb->tail = lb->data + bytes;
499 lb->dbg_number = ++dbg_number;
501 spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
502 list_add_tail(&lb->link, &dev->priv->tx_list.head);
503 ps3_vuart_enable_interrupt_tx(dev);
504 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
506 dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %xh bytes\n",
507 __func__, __LINE__, lb->dbg_number, bytes);
513 * ps3_vuart_read - the entry point for reading data from a port
515 * If enough bytes to satisfy the request are held in the buffer list those
516 * bytes are dequeued and copied to the caller's buffer. Emptied list buffers
517 * are retiered. If the request cannot be statified by bytes held in the list
518 * buffers -EAGAIN is returned.
521 int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
525 struct list_buffer *lb, *n;
526 unsigned long bytes_read;
528 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
531 spin_lock_irqsave(&dev->priv->rx_list.lock, flags);
533 if (dev->priv->rx_list.bytes_held < bytes) {
534 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
535 dev_dbg(&dev->core, "%s:%d: starved for %lxh bytes\n",
537 bytes - dev->priv->rx_list.bytes_held);
541 list_for_each_entry_safe(lb, n, &dev->priv->rx_list.head, link) {
542 bytes_read = min((unsigned int)(lb->tail - lb->head), bytes);
544 memcpy(buf, lb->head, bytes_read);
547 dev->priv->rx_list.bytes_held -= bytes_read;
549 if (bytes_read < lb->tail - lb->head) {
550 lb->head += bytes_read;
551 dev_dbg(&dev->core, "%s:%d: buf_%lu: dequeued %lxh "
552 "bytes\n", __func__, __LINE__, lb->dbg_number,
554 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
558 dev_dbg(&dev->core, "%s:%d: buf_%lu: free, dequeued %lxh "
559 "bytes\n", __func__, __LINE__, lb->dbg_number,
566 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
571 * ps3_vuart_handle_interrupt_tx - third stage transmit interrupt handler
573 * Services the transmit interrupt for the port. Writes as much data from the
574 * buffer list as the port will accept. Retires any emptied list buffers and
575 * adjusts the final list buffer state for a partial write.
578 static int ps3_vuart_handle_interrupt_tx(struct ps3_vuart_port_device *dev)
582 struct list_buffer *lb, *n;
583 unsigned long bytes_total = 0;
585 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
587 spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
589 list_for_each_entry_safe(lb, n, &dev->priv->tx_list.head, link) {
591 unsigned long bytes_written;
593 result = ps3_vuart_raw_write(dev, lb->head, lb->tail - lb->head,
598 "%s:%d: ps3_vuart_raw_write failed\n",
603 bytes_total += bytes_written;
605 if (bytes_written < lb->tail - lb->head) {
606 lb->head += bytes_written;
608 "%s:%d cleared buf_%lu, %lxh bytes\n",
609 __func__, __LINE__, lb->dbg_number,
614 dev_dbg(&dev->core, "%s:%d free buf_%lu\n", __func__, __LINE__,
621 ps3_vuart_disable_interrupt_tx(dev);
623 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
624 dev_dbg(&dev->core, "%s:%d wrote %lxh bytes total\n",
625 __func__, __LINE__, bytes_total);
630 * ps3_vuart_handle_interrupt_rx - third stage receive interrupt handler
632 * Services the receive interrupt for the port. Creates a list buffer and
633 * copies all waiting port data to that buffer and enqueues the buffer in the
634 * buffer list. Buffer list data is dequeued via ps3_vuart_read.
637 static int ps3_vuart_handle_interrupt_rx(struct ps3_vuart_port_device *dev)
639 static unsigned long dbg_number;
642 struct list_buffer *lb;
645 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
647 result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes);
654 /* Add some extra space for recently arrived data. */
658 lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_ATOMIC);
663 ps3_vuart_raw_read(dev, lb->data, bytes, &bytes);
666 lb->tail = lb->data + bytes;
667 lb->dbg_number = ++dbg_number;
669 spin_lock_irqsave(&dev->priv->rx_list.lock, flags);
670 list_add_tail(&lb->link, &dev->priv->rx_list.head);
671 dev->priv->rx_list.bytes_held += bytes;
672 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
674 dev_dbg(&dev->core, "%s:%d: buf_%lu: queued %lxh bytes\n",
675 __func__, __LINE__, lb->dbg_number, bytes);
680 static int ps3_vuart_handle_interrupt_disconnect(
681 struct ps3_vuart_port_device *dev)
683 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
684 BUG_ON("no support");
689 * ps3_vuart_handle_port_interrupt - second stage interrupt handler
691 * Services any pending interrupt types for the port. Passes control to the
692 * third stage type specific interrupt handler. Returns control to the first
693 * stage handler after one iteration.
696 static int ps3_vuart_handle_port_interrupt(struct ps3_vuart_port_device *dev)
699 unsigned long status;
701 result = ps3_vuart_get_interrupt_status(dev, &status);
706 dev_dbg(&dev->core, "%s:%d: status: %lxh\n", __func__, __LINE__,
709 if (status & INTERRUPT_MASK_DISCONNECT) {
710 dev->priv->stats.disconnect_interrupts++;
711 result = ps3_vuart_handle_interrupt_disconnect(dev);
713 ps3_vuart_disable_interrupt_disconnect(dev);
716 if (status & INTERRUPT_MASK_TX) {
717 dev->priv->stats.tx_interrupts++;
718 result = ps3_vuart_handle_interrupt_tx(dev);
720 ps3_vuart_disable_interrupt_tx(dev);
723 if (status & INTERRUPT_MASK_RX) {
724 dev->priv->stats.rx_interrupts++;
725 result = ps3_vuart_handle_interrupt_rx(dev);
727 ps3_vuart_disable_interrupt_rx(dev);
733 struct vuart_bus_priv {
734 const struct ports_bmp bmp;
736 struct semaphore probe_mutex;
738 struct ps3_vuart_port_device *devices[PORT_COUNT];
739 } static vuart_bus_priv;
742 * ps3_vuart_irq_handler - first stage interrupt handler
744 * Loops finding any interrupting port and its associated instance data.
745 * Passes control to the second stage port specific interrupt handler. Loops
746 * until all outstanding interrupts are serviced.
749 static irqreturn_t ps3_vuart_irq_handler(int irq, void *_private)
751 struct vuart_bus_priv *bus_priv;
754 bus_priv = (struct vuart_bus_priv *)_private;
759 dump_ports_bmp(&bus_priv->bmp);
761 port = (BITS_PER_LONG - 1) - __ilog2(bus_priv->bmp.status);
763 if (port == BITS_PER_LONG)
766 BUG_ON(port >= PORT_COUNT);
767 BUG_ON(!bus_priv->devices[port]);
769 ps3_vuart_handle_port_interrupt(bus_priv->devices[port]);
775 static int ps3_vuart_match(struct device *_dev, struct device_driver *_drv)
778 struct ps3_vuart_port_driver *drv = to_ps3_vuart_port_driver(_drv);
779 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
781 result = dev->match_id == drv->match_id;
783 dev_info(&dev->core, "%s:%d: dev=%u(%s), drv=%u(%s): %s\n", __func__,
784 __LINE__, dev->match_id, dev->core.bus_id, drv->match_id,
785 drv->core.name, (result ? "match" : "miss"));
790 static int ps3_vuart_probe(struct device *_dev)
793 unsigned int port_number;
794 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
795 struct ps3_vuart_port_driver *drv =
796 to_ps3_vuart_port_driver(_dev->driver);
798 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
802 down(&vuart_bus_priv.probe_mutex);
804 /* Setup vuart_bus_priv.devices[]. */
806 result = ps3_vuart_match_id_to_port(dev->match_id,
810 dev_dbg(&dev->core, "%s:%d: unknown match_id (%d)\n",
811 __func__, __LINE__, dev->match_id);
816 if (vuart_bus_priv.devices[port_number]) {
817 dev_dbg(&dev->core, "%s:%d: port busy (%d)\n", __func__,
818 __LINE__, port_number);
823 vuart_bus_priv.devices[port_number] = dev;
825 /* Setup dev->priv. */
827 dev->priv = kzalloc(sizeof(struct ps3_vuart_port_priv), GFP_KERNEL);
834 dev->priv->port_number = port_number;
836 INIT_LIST_HEAD(&dev->priv->tx_list.head);
837 spin_lock_init(&dev->priv->tx_list.lock);
839 INIT_LIST_HEAD(&dev->priv->rx_list.head);
840 spin_lock_init(&dev->priv->rx_list.lock);
842 if (++vuart_bus_priv.use_count == 1) {
844 result = ps3_alloc_vuart_irq(PS3_BINDING_CPU_ANY,
845 (void*)&vuart_bus_priv.bmp.status, &vuart_bus_priv.virq);
849 "%s:%d: ps3_alloc_vuart_irq failed (%d)\n",
850 __func__, __LINE__, result);
855 result = request_irq(vuart_bus_priv.virq, ps3_vuart_irq_handler,
856 IRQF_DISABLED, "vuart", &vuart_bus_priv);
859 dev_info(&dev->core, "%s:%d: request_irq failed (%d)\n",
860 __func__, __LINE__, result);
861 goto fail_request_irq;
865 /* clear stale pending interrupts */
867 ps3_vuart_clear_rx_bytes(dev, 0);
869 ps3_vuart_set_interrupt_mask(dev, INTERRUPT_MASK_RX);
871 ps3_vuart_set_triggers(dev, 1, 1);
874 result = drv->probe(dev);
877 dev_info(&dev->core, "%s:%d: no probe method\n", __func__,
882 dev_dbg(&dev->core, "%s:%d: drv->probe failed\n",
884 down(&vuart_bus_priv.probe_mutex);
888 up(&vuart_bus_priv.probe_mutex);
893 ps3_vuart_set_interrupt_mask(dev, 0);
895 ps3_free_vuart_irq(vuart_bus_priv.virq);
896 vuart_bus_priv.virq = NO_IRQ;
898 --vuart_bus_priv.use_count;
902 vuart_bus_priv.devices[port_number] = 0;
904 up(&vuart_bus_priv.probe_mutex);
905 dev_dbg(&dev->core, "%s:%d failed\n", __func__, __LINE__);
909 static int ps3_vuart_remove(struct device *_dev)
911 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
912 struct ps3_vuart_port_driver *drv =
913 to_ps3_vuart_port_driver(_dev->driver);
915 down(&vuart_bus_priv.probe_mutex);
917 dev_dbg(&dev->core, "%s:%d: %s\n", __func__, __LINE__,
920 BUG_ON(vuart_bus_priv.use_count < 1);
925 dev_dbg(&dev->core, "%s:%d: %s no remove method\n", __func__,
926 __LINE__, dev->core.bus_id);
928 vuart_bus_priv.devices[dev->priv->port_number] = 0;
930 if (--vuart_bus_priv.use_count == 0) {
932 free_irq(vuart_bus_priv.virq, &vuart_bus_priv);
933 ps3_free_vuart_irq(vuart_bus_priv.virq);
934 vuart_bus_priv.virq = NO_IRQ;
940 up(&vuart_bus_priv.probe_mutex);
944 static void ps3_vuart_shutdown(struct device *_dev)
946 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
947 struct ps3_vuart_port_driver *drv =
948 to_ps3_vuart_port_driver(_dev->driver);
950 dev_dbg(&dev->core, "%s:%d: %s\n", __func__, __LINE__,
956 dev_dbg(&dev->core, "%s:%d: %s no shutdown method\n", __func__,
957 __LINE__, dev->core.bus_id);
961 * ps3_vuart_bus - The vuart bus instance.
963 * The vuart is managed as a bus that port devices connect to.
966 struct bus_type ps3_vuart_bus = {
968 .match = ps3_vuart_match,
969 .probe = ps3_vuart_probe,
970 .remove = ps3_vuart_remove,
971 .shutdown = ps3_vuart_shutdown,
974 int __init ps3_vuart_bus_init(void)
978 pr_debug("%s:%d:\n", __func__, __LINE__);
980 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
983 init_MUTEX(&vuart_bus_priv.probe_mutex);
984 result = bus_register(&ps3_vuart_bus);
990 void __exit ps3_vuart_bus_exit(void)
992 pr_debug("%s:%d:\n", __func__, __LINE__);
993 bus_unregister(&ps3_vuart_bus);
996 core_initcall(ps3_vuart_bus_init);
997 module_exit(ps3_vuart_bus_exit);
1000 * ps3_vuart_port_release_device - Remove a vuart port device.
1003 static void ps3_vuart_port_release_device(struct device *_dev)
1006 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
1008 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
1010 BUG_ON(dev->priv && "forgot to free");
1011 memset(&dev->core, 0, sizeof(dev->core));
1016 * ps3_vuart_port_device_register - Add a vuart port device.
1019 int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev)
1021 static unsigned int dev_count = 1;
1023 BUG_ON(dev->priv && "forgot to free");
1025 dev->core.parent = NULL;
1026 dev->core.bus = &ps3_vuart_bus;
1027 dev->core.release = ps3_vuart_port_release_device;
1029 snprintf(dev->core.bus_id, sizeof(dev->core.bus_id), "vuart_%02x",
1032 dev_dbg(&dev->core, "%s:%d register\n", __func__, __LINE__);
1034 return device_register(&dev->core);
1037 EXPORT_SYMBOL_GPL(ps3_vuart_port_device_register);
1040 * ps3_vuart_port_driver_register - Add a vuart port device driver.
1043 int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv)
1047 pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name);
1048 drv->core.bus = &ps3_vuart_bus;
1049 result = driver_register(&drv->core);
1053 EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_register);
1056 * ps3_vuart_port_driver_unregister - Remove a vuart port device driver.
1059 void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv)
1061 pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name);
1062 driver_unregister(&drv->core);
1065 EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_unregister);