blob: 90b3d1ca5172c2723d80a84842b9a4972171a59e [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#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/interrupt.h>
24#include <asm/ps3.h>
25
Geoff Levand75c86e72007-02-13 17:37:28 -080026#include <asm/firmware.h>
Geoff Levand74e95d5d2006-12-08 18:27:47 -080027#include <asm/lv1call.h>
28#include <asm/bitops.h>
29
30#include "vuart.h"
31
32MODULE_AUTHOR("Sony Corporation");
33MODULE_LICENSE("GPL v2");
Geoff Levand75c86e72007-02-13 17:37:28 -080034MODULE_DESCRIPTION("PS3 vuart");
Geoff Levand74e95d5d2006-12-08 18:27:47 -080035
36/**
37 * vuart - An inter-partition data link service.
38 * port 0: PS3 AV Settings.
39 * port 2: PS3 System Manager.
40 *
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.
45 */
46
47enum {PORT_COUNT = 3,};
48
49enum vuart_param {
50 PARAM_TX_TRIGGER = 0,
51 PARAM_RX_TRIGGER = 1,
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 */
58};
59
60enum vuart_interrupt_bit {
61 INTERRUPT_BIT_TX = 0,
62 INTERRUPT_BIT_RX = 1,
63 INTERRUPT_BIT_DISCONNECT = 2,
64};
65
66enum vuart_interrupt_mask {
67 INTERRUPT_MASK_TX = 1,
68 INTERRUPT_MASK_RX = 2,
69 INTERRUPT_MASK_DISCONNECT = 4,
70};
71
72/**
73 * struct ports_bmp - bitmap indicating ports needing service.
74 *
75 * A 256 bit read only bitmap indicating ports needing service. Do not write
76 * to these bits. Must not cross a page boundary.
77 */
78
79struct ports_bmp {
80 u64 status;
81 u64 unused[3];
82} __attribute__ ((aligned (32)));
83
84/* redefine dev_dbg to do a syntax check */
85
86#if !defined(DEBUG)
87#undef dev_dbg
88static inline int __attribute__ ((format (printf, 2, 3))) dev_dbg(
89 const struct device *_dev, const char *fmt, ...) {return 0;}
90#endif
91
92#define dump_ports_bmp(_b) _dump_ports_bmp(_b, __func__, __LINE__)
93static void __attribute__ ((unused)) _dump_ports_bmp(
94 const struct ports_bmp* bmp, const char* func, int line)
95{
96 pr_debug("%s:%d: ports_bmp: %016lxh\n", func, line, bmp->status);
97}
98
99static int ps3_vuart_match_id_to_port(enum ps3_match_id match_id,
100 unsigned int *port_number)
101{
102 switch(match_id) {
103 case PS3_MATCH_ID_AV_SETTINGS:
104 *port_number = 0;
105 return 0;
106 case PS3_MATCH_ID_SYSTEM_MANAGER:
107 *port_number = 2;
108 return 0;
109 default:
110 WARN_ON(1);
111 *port_number = UINT_MAX;
112 return -EINVAL;
113 };
114}
115
116#define dump_port_params(_b) _dump_port_params(_b, __func__, __LINE__)
117static void __attribute__ ((unused)) _dump_port_params(unsigned int port_number,
118 const char* func, int line)
119{
120#if defined(DEBUG)
121 static const char *strings[] = {
122 "tx_trigger ",
123 "rx_trigger ",
124 "interrupt_mask ",
125 "rx_buf_size ",
126 "rx_bytes ",
127 "tx_buf_size ",
128 "tx_bytes ",
129 "interrupt_status",
130 };
131 int result;
132 unsigned int i;
133 u64 value;
134
135 for (i = 0; i < ARRAY_SIZE(strings); i++) {
136 result = lv1_get_virtual_uart_param(port_number, i, &value);
137
138 if (result) {
139 pr_debug("%s:%d: port_%u: %s failed: %s\n", func, line,
140 port_number, strings[i], ps3_result(result));
141 continue;
142 }
143 pr_debug("%s:%d: port_%u: %s = %lxh\n",
144 func, line, port_number, strings[i], value);
145 }
146#endif
147}
148
149struct vuart_triggers {
150 unsigned long rx;
151 unsigned long tx;
152};
153
154int ps3_vuart_get_triggers(struct ps3_vuart_port_device *dev,
155 struct vuart_triggers *trig)
156{
157 int result;
158 unsigned long size;
159 unsigned long val;
160
Geoff Levand75c86e72007-02-13 17:37:28 -0800161 result = lv1_get_virtual_uart_param(dev->priv->port_number,
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800162 PARAM_TX_TRIGGER, &trig->tx);
163
164 if (result) {
165 dev_dbg(&dev->core, "%s:%d: tx_trigger failed: %s\n",
166 __func__, __LINE__, ps3_result(result));
167 return result;
168 }
169
Geoff Levand75c86e72007-02-13 17:37:28 -0800170 result = lv1_get_virtual_uart_param(dev->priv->port_number,
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800171 PARAM_RX_BUF_SIZE, &size);
172
173 if (result) {
174 dev_dbg(&dev->core, "%s:%d: tx_buf_size failed: %s\n",
175 __func__, __LINE__, ps3_result(result));
176 return result;
177 }
178
Geoff Levand75c86e72007-02-13 17:37:28 -0800179 result = lv1_get_virtual_uart_param(dev->priv->port_number,
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800180 PARAM_RX_TRIGGER, &val);
181
182 if (result) {
183 dev_dbg(&dev->core, "%s:%d: rx_trigger failed: %s\n",
184 __func__, __LINE__, ps3_result(result));
185 return result;
186 }
187
188 trig->rx = size - val;
189
190 dev_dbg(&dev->core, "%s:%d: tx %lxh, rx %lxh\n", __func__, __LINE__,
191 trig->tx, trig->rx);
192
193 return result;
194}
195
196int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
197 unsigned int rx)
198{
199 int result;
200 unsigned long size;
201
Geoff Levand75c86e72007-02-13 17:37:28 -0800202 result = lv1_set_virtual_uart_param(dev->priv->port_number,
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800203 PARAM_TX_TRIGGER, tx);
204
205 if (result) {
206 dev_dbg(&dev->core, "%s:%d: tx_trigger failed: %s\n",
207 __func__, __LINE__, ps3_result(result));
208 return result;
209 }
210
Geoff Levand75c86e72007-02-13 17:37:28 -0800211 result = lv1_get_virtual_uart_param(dev->priv->port_number,
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800212 PARAM_RX_BUF_SIZE, &size);
213
214 if (result) {
215 dev_dbg(&dev->core, "%s:%d: tx_buf_size failed: %s\n",
216 __func__, __LINE__, ps3_result(result));
217 return result;
218 }
219
Geoff Levand75c86e72007-02-13 17:37:28 -0800220 result = lv1_set_virtual_uart_param(dev->priv->port_number,
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800221 PARAM_RX_TRIGGER, size - rx);
222
223 if (result) {
224 dev_dbg(&dev->core, "%s:%d: rx_trigger failed: %s\n",
225 __func__, __LINE__, ps3_result(result));
226 return result;
227 }
228
229 dev_dbg(&dev->core, "%s:%d: tx %xh, rx %xh\n", __func__, __LINE__,
230 tx, rx);
231
232 return result;
233}
234
235static int ps3_vuart_get_rx_bytes_waiting(struct ps3_vuart_port_device *dev,
Geoff Levand75c86e72007-02-13 17:37:28 -0800236 u64 *bytes_waiting)
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800237{
Geoff Levand75c86e72007-02-13 17:37:28 -0800238 int result = lv1_get_virtual_uart_param(dev->priv->port_number,
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800239 PARAM_RX_BYTES, bytes_waiting);
240
241 if (result)
242 dev_dbg(&dev->core, "%s:%d: rx_bytes failed: %s\n",
243 __func__, __LINE__, ps3_result(result));
244
245 dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__,
246 *bytes_waiting);
247 return result;
248}
249
250static int ps3_vuart_set_interrupt_mask(struct ps3_vuart_port_device *dev,
251 unsigned long mask)
252{
253 int result;
254
255 dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__, mask);
256
Geoff Levand75c86e72007-02-13 17:37:28 -0800257 dev->priv->interrupt_mask = mask;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800258
Geoff Levand75c86e72007-02-13 17:37:28 -0800259 result = lv1_set_virtual_uart_param(dev->priv->port_number,
260 PARAM_INTERRUPT_MASK, dev->priv->interrupt_mask);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800261
262 if (result)
263 dev_dbg(&dev->core, "%s:%d: interrupt_mask failed: %s\n",
264 __func__, __LINE__, ps3_result(result));
265
266 return result;
267}
268
Geoff Levand75c86e72007-02-13 17:37:28 -0800269static int ps3_vuart_get_interrupt_status(struct ps3_vuart_port_device *dev,
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800270 unsigned long *status)
271{
Geoff Levand75c86e72007-02-13 17:37:28 -0800272 u64 tmp;
273 int result = lv1_get_virtual_uart_param(dev->priv->port_number,
274 PARAM_INTERRUPT_STATUS, &tmp);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800275
276 if (result)
277 dev_dbg(&dev->core, "%s:%d: interrupt_status failed: %s\n",
278 __func__, __LINE__, ps3_result(result));
279
Geoff Levand75c86e72007-02-13 17:37:28 -0800280 *status = tmp & dev->priv->interrupt_mask;
281
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800282 dev_dbg(&dev->core, "%s:%d: m %lxh, s %lxh, m&s %lxh\n",
Geoff Levand75c86e72007-02-13 17:37:28 -0800283 __func__, __LINE__, dev->priv->interrupt_mask, tmp, *status);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800284
285 return result;
286}
287
288int ps3_vuart_enable_interrupt_tx(struct ps3_vuart_port_device *dev)
289{
Geoff Levand75c86e72007-02-13 17:37:28 -0800290 return (dev->priv->interrupt_mask & INTERRUPT_MASK_TX) ? 0
291 : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800292 | INTERRUPT_MASK_TX);
293}
294
295int ps3_vuart_enable_interrupt_rx(struct ps3_vuart_port_device *dev)
296{
Geoff Levand75c86e72007-02-13 17:37:28 -0800297 return (dev->priv->interrupt_mask & INTERRUPT_MASK_RX) ? 0
298 : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800299 | INTERRUPT_MASK_RX);
300}
301
302int ps3_vuart_enable_interrupt_disconnect(struct ps3_vuart_port_device *dev)
303{
Geoff Levand75c86e72007-02-13 17:37:28 -0800304 return (dev->priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT) ? 0
305 : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800306 | INTERRUPT_MASK_DISCONNECT);
307}
308
309int ps3_vuart_disable_interrupt_tx(struct ps3_vuart_port_device *dev)
310{
Geoff Levand75c86e72007-02-13 17:37:28 -0800311 return (dev->priv->interrupt_mask & INTERRUPT_MASK_TX)
312 ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800313 & ~INTERRUPT_MASK_TX) : 0;
314}
315
316int ps3_vuart_disable_interrupt_rx(struct ps3_vuart_port_device *dev)
317{
Geoff Levand75c86e72007-02-13 17:37:28 -0800318 return (dev->priv->interrupt_mask & INTERRUPT_MASK_RX)
319 ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800320 & ~INTERRUPT_MASK_RX) : 0;
321}
322
323int ps3_vuart_disable_interrupt_disconnect(struct ps3_vuart_port_device *dev)
324{
Geoff Levand75c86e72007-02-13 17:37:28 -0800325 return (dev->priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT)
326 ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800327 & ~INTERRUPT_MASK_DISCONNECT) : 0;
328}
329
330/**
331 * ps3_vuart_raw_write - Low level write helper.
332 *
333 * Do not call ps3_vuart_raw_write directly, use ps3_vuart_write.
334 */
335
336static int ps3_vuart_raw_write(struct ps3_vuart_port_device *dev,
337 const void* buf, unsigned int bytes, unsigned long *bytes_written)
338{
339 int result;
340
Geoff Levand75c86e72007-02-13 17:37:28 -0800341 result = lv1_write_virtual_uart(dev->priv->port_number,
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800342 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_written);
343
344 if (result) {
345 dev_dbg(&dev->core, "%s:%d: lv1_write_virtual_uart failed: "
346 "%s\n", __func__, __LINE__, ps3_result(result));
347 return result;
348 }
349
Geoff Levand75c86e72007-02-13 17:37:28 -0800350 dev->priv->stats.bytes_written += *bytes_written;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800351
Geoff Levand75c86e72007-02-13 17:37:28 -0800352 dev_dbg(&dev->core, "%s:%d: wrote %lxh/%xh=>%lxh\n", __func__, __LINE__,
353 *bytes_written, bytes, dev->priv->stats.bytes_written);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800354
355 return result;
356}
357
358/**
359 * ps3_vuart_raw_read - Low level read helper.
360 *
361 * Do not call ps3_vuart_raw_read directly, use ps3_vuart_read.
362 */
363
364static int ps3_vuart_raw_read(struct ps3_vuart_port_device *dev, void* buf,
365 unsigned int bytes, unsigned long *bytes_read)
366{
367 int result;
368
369 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes);
370
Geoff Levand75c86e72007-02-13 17:37:28 -0800371 result = lv1_read_virtual_uart(dev->priv->port_number,
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800372 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_read);
373
374 if (result) {
375 dev_dbg(&dev->core, "%s:%d: lv1_read_virtual_uart failed: %s\n",
376 __func__, __LINE__, ps3_result(result));
377 return result;
378 }
379
Geoff Levand75c86e72007-02-13 17:37:28 -0800380 dev->priv->stats.bytes_read += *bytes_read;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800381
382 dev_dbg(&dev->core, "%s:%d: read %lxh/%xh=>%lxh\n", __func__, __LINE__,
Geoff Levand75c86e72007-02-13 17:37:28 -0800383 *bytes_read, bytes, dev->priv->stats.bytes_read);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800384
385 return result;
386}
387
388/**
Geoff Levand75c86e72007-02-13 17:37:28 -0800389 * ps3_vuart_clear_rx_bytes - Discard bytes received.
390 * @bytes: Max byte count to discard, zero = all pending.
391 *
392 * Used to clear pending rx interrupt source. Will not block.
393 */
394
395void ps3_vuart_clear_rx_bytes(struct ps3_vuart_port_device *dev,
396 unsigned int bytes)
397{
398 int result;
399 u64 bytes_waiting;
400 void* tmp;
401
402 result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes_waiting);
403
404 BUG_ON(result);
405
406 bytes = bytes ? min(bytes, (unsigned int)bytes_waiting) : bytes_waiting;
407
408 dev_dbg(&dev->core, "%s:%d: %u\n", __func__, __LINE__, bytes);
409
410 if (!bytes)
411 return;
412
413 /* Add some extra space for recently arrived data. */
414
415 bytes += 128;
416
417 tmp = kmalloc(bytes, GFP_KERNEL);
418
419 if (!tmp)
420 return;
421
422 ps3_vuart_raw_read(dev, tmp, bytes, &bytes_waiting);
423
424 kfree(tmp);
425
426 /* Don't include these bytes in the stats. */
427
428 dev->priv->stats.bytes_read -= bytes_waiting;
429}
430
431/**
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800432 * struct list_buffer - An element for a port device fifo buffer list.
433 */
434
435struct list_buffer {
436 struct list_head link;
437 const unsigned char *head;
438 const unsigned char *tail;
439 unsigned long dbg_number;
440 unsigned char data[];
441};
442
443/**
444 * ps3_vuart_write - the entry point for writing data to a port
445 *
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.
450 */
451
452int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
453 unsigned int bytes)
454{
455 static unsigned long dbg_number;
456 int result;
457 unsigned long flags;
458 struct list_buffer *lb;
459
460 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
461 bytes, bytes);
462
Geoff Levand75c86e72007-02-13 17:37:28 -0800463 spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800464
Geoff Levand75c86e72007-02-13 17:37:28 -0800465 if (list_empty(&dev->priv->tx_list.head)) {
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800466 unsigned long bytes_written;
467
468 result = ps3_vuart_raw_write(dev, buf, bytes, &bytes_written);
469
Geoff Levand75c86e72007-02-13 17:37:28 -0800470 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800471
472 if (result) {
473 dev_dbg(&dev->core,
474 "%s:%d: ps3_vuart_raw_write failed\n",
475 __func__, __LINE__);
476 return result;
477 }
478
479 if (bytes_written == bytes) {
480 dev_dbg(&dev->core, "%s:%d: wrote %xh bytes\n",
481 __func__, __LINE__, bytes);
482 return 0;
483 }
484
485 bytes -= bytes_written;
486 buf += bytes_written;
487 } else
Geoff Levand75c86e72007-02-13 17:37:28 -0800488 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800489
490 lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_KERNEL);
491
492 if (!lb) {
493 return -ENOMEM;
494 }
495
496 memcpy(lb->data, buf, bytes);
497 lb->head = lb->data;
498 lb->tail = lb->data + bytes;
499 lb->dbg_number = ++dbg_number;
500
Geoff Levand75c86e72007-02-13 17:37:28 -0800501 spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
502 list_add_tail(&lb->link, &dev->priv->tx_list.head);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800503 ps3_vuart_enable_interrupt_tx(dev);
Geoff Levand75c86e72007-02-13 17:37:28 -0800504 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800505
506 dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %xh bytes\n",
507 __func__, __LINE__, lb->dbg_number, bytes);
508
509 return 0;
510}
511
512/**
513 * ps3_vuart_read - the entry point for reading data from a port
514 *
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.
519 */
520
521int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
522 unsigned int bytes)
523{
524 unsigned long flags;
525 struct list_buffer *lb, *n;
526 unsigned long bytes_read;
527
528 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
529 bytes, bytes);
530
Geoff Levand75c86e72007-02-13 17:37:28 -0800531 spin_lock_irqsave(&dev->priv->rx_list.lock, flags);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800532
Geoff Levand75c86e72007-02-13 17:37:28 -0800533 if (dev->priv->rx_list.bytes_held < bytes) {
534 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800535 dev_dbg(&dev->core, "%s:%d: starved for %lxh bytes\n",
Geoff Levand75c86e72007-02-13 17:37:28 -0800536 __func__, __LINE__,
537 bytes - dev->priv->rx_list.bytes_held);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800538 return -EAGAIN;
539 }
540
Geoff Levand75c86e72007-02-13 17:37:28 -0800541 list_for_each_entry_safe(lb, n, &dev->priv->rx_list.head, link) {
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800542 bytes_read = min((unsigned int)(lb->tail - lb->head), bytes);
543
544 memcpy(buf, lb->head, bytes_read);
545 buf += bytes_read;
546 bytes -= bytes_read;
Geoff Levand75c86e72007-02-13 17:37:28 -0800547 dev->priv->rx_list.bytes_held -= bytes_read;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800548
549 if (bytes_read < lb->tail - lb->head) {
550 lb->head += bytes_read;
Geoff Levand75c86e72007-02-13 17:37:28 -0800551 dev_dbg(&dev->core, "%s:%d: buf_%lu: dequeued %lxh "
552 "bytes\n", __func__, __LINE__, lb->dbg_number,
553 bytes_read);
554 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800555 return 0;
556 }
557
Geoff Levand75c86e72007-02-13 17:37:28 -0800558 dev_dbg(&dev->core, "%s:%d: buf_%lu: free, dequeued %lxh "
559 "bytes\n", __func__, __LINE__, lb->dbg_number,
560 bytes_read);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800561
562 list_del(&lb->link);
563 kfree(lb);
564 }
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800565
Geoff Levand75c86e72007-02-13 17:37:28 -0800566 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800567 return 0;
568}
569
570/**
571 * ps3_vuart_handle_interrupt_tx - third stage transmit interrupt handler
572 *
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.
576 */
577
578static int ps3_vuart_handle_interrupt_tx(struct ps3_vuart_port_device *dev)
579{
580 int result = 0;
581 unsigned long flags;
582 struct list_buffer *lb, *n;
583 unsigned long bytes_total = 0;
584
585 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
586
Geoff Levand75c86e72007-02-13 17:37:28 -0800587 spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800588
Geoff Levand75c86e72007-02-13 17:37:28 -0800589 list_for_each_entry_safe(lb, n, &dev->priv->tx_list.head, link) {
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800590
591 unsigned long bytes_written;
592
593 result = ps3_vuart_raw_write(dev, lb->head, lb->tail - lb->head,
594 &bytes_written);
595
596 if (result) {
597 dev_dbg(&dev->core,
598 "%s:%d: ps3_vuart_raw_write failed\n",
599 __func__, __LINE__);
600 break;
601 }
602
603 bytes_total += bytes_written;
604
605 if (bytes_written < lb->tail - lb->head) {
606 lb->head += bytes_written;
607 dev_dbg(&dev->core,
608 "%s:%d cleared buf_%lu, %lxh bytes\n",
609 __func__, __LINE__, lb->dbg_number,
610 bytes_written);
611 goto port_full;
612 }
613
614 dev_dbg(&dev->core, "%s:%d free buf_%lu\n", __func__, __LINE__,
615 lb->dbg_number);
616
617 list_del(&lb->link);
618 kfree(lb);
619 }
620
621 ps3_vuart_disable_interrupt_tx(dev);
622port_full:
Geoff Levand75c86e72007-02-13 17:37:28 -0800623 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800624 dev_dbg(&dev->core, "%s:%d wrote %lxh bytes total\n",
625 __func__, __LINE__, bytes_total);
626 return result;
627}
628
629/**
630 * ps3_vuart_handle_interrupt_rx - third stage receive interrupt handler
631 *
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.
635 */
636
637static int ps3_vuart_handle_interrupt_rx(struct ps3_vuart_port_device *dev)
638{
639 static unsigned long dbg_number;
640 int result = 0;
641 unsigned long flags;
642 struct list_buffer *lb;
643 unsigned long bytes;
644
645 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
646
647 result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes);
648
649 if (result)
650 return -EIO;
651
652 BUG_ON(!bytes);
653
Geoff Levand75c86e72007-02-13 17:37:28 -0800654 /* Add some extra space for recently arrived data. */
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800655
656 bytes += 128;
657
658 lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_ATOMIC);
659
660 if (!lb)
661 return -ENOMEM;
662
663 ps3_vuart_raw_read(dev, lb->data, bytes, &bytes);
664
665 lb->head = lb->data;
666 lb->tail = lb->data + bytes;
667 lb->dbg_number = ++dbg_number;
668
Geoff Levand75c86e72007-02-13 17:37:28 -0800669 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);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800673
Geoff Levand75c86e72007-02-13 17:37:28 -0800674 dev_dbg(&dev->core, "%s:%d: buf_%lu: queued %lxh bytes\n",
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800675 __func__, __LINE__, lb->dbg_number, bytes);
676
677 return 0;
678}
679
680static int ps3_vuart_handle_interrupt_disconnect(
681 struct ps3_vuart_port_device *dev)
682{
683 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
684 BUG_ON("no support");
685 return -1;
686}
687
688/**
689 * ps3_vuart_handle_port_interrupt - second stage interrupt handler
690 *
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.
694 */
695
696static int ps3_vuart_handle_port_interrupt(struct ps3_vuart_port_device *dev)
697{
698 int result;
699 unsigned long status;
700
Geoff Levand75c86e72007-02-13 17:37:28 -0800701 result = ps3_vuart_get_interrupt_status(dev, &status);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800702
703 if (result)
704 return result;
705
706 dev_dbg(&dev->core, "%s:%d: status: %lxh\n", __func__, __LINE__,
707 status);
708
709 if (status & INTERRUPT_MASK_DISCONNECT) {
Geoff Levand75c86e72007-02-13 17:37:28 -0800710 dev->priv->stats.disconnect_interrupts++;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800711 result = ps3_vuart_handle_interrupt_disconnect(dev);
712 if (result)
713 ps3_vuart_disable_interrupt_disconnect(dev);
714 }
715
716 if (status & INTERRUPT_MASK_TX) {
Geoff Levand75c86e72007-02-13 17:37:28 -0800717 dev->priv->stats.tx_interrupts++;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800718 result = ps3_vuart_handle_interrupt_tx(dev);
719 if (result)
720 ps3_vuart_disable_interrupt_tx(dev);
721 }
722
723 if (status & INTERRUPT_MASK_RX) {
Geoff Levand75c86e72007-02-13 17:37:28 -0800724 dev->priv->stats.rx_interrupts++;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800725 result = ps3_vuart_handle_interrupt_rx(dev);
726 if (result)
727 ps3_vuart_disable_interrupt_rx(dev);
728 }
729
730 return 0;
731}
732
Geoff Levand75c86e72007-02-13 17:37:28 -0800733struct vuart_bus_priv {
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800734 const struct ports_bmp bmp;
Geoff Levand75c86e72007-02-13 17:37:28 -0800735 unsigned int virq;
736 struct semaphore probe_mutex;
737 int use_count;
738 struct ps3_vuart_port_device *devices[PORT_COUNT];
739} static vuart_bus_priv;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800740
741/**
742 * ps3_vuart_irq_handler - first stage interrupt handler
743 *
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.
747 */
748
749static irqreturn_t ps3_vuart_irq_handler(int irq, void *_private)
750{
Geoff Levand75c86e72007-02-13 17:37:28 -0800751 struct vuart_bus_priv *bus_priv;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800752
753 BUG_ON(!_private);
Geoff Levand75c86e72007-02-13 17:37:28 -0800754 bus_priv = (struct vuart_bus_priv *)_private;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800755
756 while (1) {
757 unsigned int port;
758
Geoff Levand75c86e72007-02-13 17:37:28 -0800759 dump_ports_bmp(&bus_priv->bmp);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800760
Geoff Levand75c86e72007-02-13 17:37:28 -0800761 port = (BITS_PER_LONG - 1) - __ilog2(bus_priv->bmp.status);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800762
763 if (port == BITS_PER_LONG)
764 break;
765
766 BUG_ON(port >= PORT_COUNT);
Geoff Levand75c86e72007-02-13 17:37:28 -0800767 BUG_ON(!bus_priv->devices[port]);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800768
Geoff Levand75c86e72007-02-13 17:37:28 -0800769 ps3_vuart_handle_port_interrupt(bus_priv->devices[port]);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800770 }
771
772 return IRQ_HANDLED;
773}
774
775static int ps3_vuart_match(struct device *_dev, struct device_driver *_drv)
776{
777 int result;
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);
780
781 result = dev->match_id == drv->match_id;
782
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"));
786
787 return result;
788}
789
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800790static int ps3_vuart_probe(struct device *_dev)
791{
792 int result;
Geoff Levand75c86e72007-02-13 17:37:28 -0800793 unsigned int port_number;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800794 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);
797
798 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
799
800 BUG_ON(!drv);
801
Geoff Levand75c86e72007-02-13 17:37:28 -0800802 down(&vuart_bus_priv.probe_mutex);
803
804 /* Setup vuart_bus_priv.devices[]. */
805
806 result = ps3_vuart_match_id_to_port(dev->match_id,
807 &port_number);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800808
809 if (result) {
810 dev_dbg(&dev->core, "%s:%d: unknown match_id (%d)\n",
811 __func__, __LINE__, dev->match_id);
812 result = -EINVAL;
813 goto fail_match;
814 }
815
Geoff Levand75c86e72007-02-13 17:37:28 -0800816 if (vuart_bus_priv.devices[port_number]) {
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800817 dev_dbg(&dev->core, "%s:%d: port busy (%d)\n", __func__,
Geoff Levand75c86e72007-02-13 17:37:28 -0800818 __LINE__, port_number);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800819 result = -EBUSY;
820 goto fail_match;
821 }
822
Geoff Levand75c86e72007-02-13 17:37:28 -0800823 vuart_bus_priv.devices[port_number] = dev;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800824
Geoff Levand75c86e72007-02-13 17:37:28 -0800825 /* Setup dev->priv. */
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800826
Geoff Levand75c86e72007-02-13 17:37:28 -0800827 dev->priv = kzalloc(sizeof(struct ps3_vuart_port_priv), GFP_KERNEL);
828
829 if (!dev->priv) {
830 result = -ENOMEM;
831 goto fail_alloc;
832 }
833
834 dev->priv->port_number = port_number;
835
836 INIT_LIST_HEAD(&dev->priv->tx_list.head);
837 spin_lock_init(&dev->priv->tx_list.lock);
838
839 INIT_LIST_HEAD(&dev->priv->rx_list.head);
840 spin_lock_init(&dev->priv->rx_list.lock);
841
842 if (++vuart_bus_priv.use_count == 1) {
843
Geoff Levand861be322007-01-26 19:08:08 -0800844 result = ps3_alloc_vuart_irq(PS3_BINDING_CPU_ANY,
Geoff Levand75c86e72007-02-13 17:37:28 -0800845 (void*)&vuart_bus_priv.bmp.status, &vuart_bus_priv.virq);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800846
847 if (result) {
848 dev_dbg(&dev->core,
849 "%s:%d: ps3_alloc_vuart_irq failed (%d)\n",
850 __func__, __LINE__, result);
851 result = -EPERM;
852 goto fail_alloc_irq;
853 }
854
Geoff Levand75c86e72007-02-13 17:37:28 -0800855 result = request_irq(vuart_bus_priv.virq, ps3_vuart_irq_handler,
856 IRQF_DISABLED, "vuart", &vuart_bus_priv);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800857
858 if (result) {
859 dev_info(&dev->core, "%s:%d: request_irq failed (%d)\n",
860 __func__, __LINE__, result);
861 goto fail_request_irq;
862 }
863 }
864
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800865 /* clear stale pending interrupts */
Geoff Levand75c86e72007-02-13 17:37:28 -0800866
867 ps3_vuart_clear_rx_bytes(dev, 0);
868
869 ps3_vuart_set_interrupt_mask(dev, INTERRUPT_MASK_RX);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800870
871 ps3_vuart_set_triggers(dev, 1, 1);
872
873 if (drv->probe)
874 result = drv->probe(dev);
875 else {
876 result = 0;
877 dev_info(&dev->core, "%s:%d: no probe method\n", __func__,
878 __LINE__);
879 }
880
881 if (result) {
882 dev_dbg(&dev->core, "%s:%d: drv->probe failed\n",
883 __func__, __LINE__);
Geoff Levand75c86e72007-02-13 17:37:28 -0800884 down(&vuart_bus_priv.probe_mutex);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800885 goto fail_probe;
886 }
887
Geoff Levand75c86e72007-02-13 17:37:28 -0800888 up(&vuart_bus_priv.probe_mutex);
889
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800890 return result;
891
892fail_probe:
Geoff Levand75c86e72007-02-13 17:37:28 -0800893 ps3_vuart_set_interrupt_mask(dev, 0);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800894fail_request_irq:
Geoff Levand75c86e72007-02-13 17:37:28 -0800895 ps3_free_vuart_irq(vuart_bus_priv.virq);
896 vuart_bus_priv.virq = NO_IRQ;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800897fail_alloc_irq:
Geoff Levand75c86e72007-02-13 17:37:28 -0800898 --vuart_bus_priv.use_count;
899 kfree(dev->priv);
900 dev->priv = NULL;
901fail_alloc:
902 vuart_bus_priv.devices[port_number] = 0;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800903fail_match:
Geoff Levand75c86e72007-02-13 17:37:28 -0800904 up(&vuart_bus_priv.probe_mutex);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800905 dev_dbg(&dev->core, "%s:%d failed\n", __func__, __LINE__);
906 return result;
907}
908
909static int ps3_vuart_remove(struct device *_dev)
910{
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);
914
Geoff Levand75c86e72007-02-13 17:37:28 -0800915 down(&vuart_bus_priv.probe_mutex);
916
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800917 dev_dbg(&dev->core, "%s:%d: %s\n", __func__, __LINE__,
918 dev->core.bus_id);
919
Geoff Levand75c86e72007-02-13 17:37:28 -0800920 BUG_ON(vuart_bus_priv.use_count < 1);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800921
922 if (drv->remove)
923 drv->remove(dev);
924 else
925 dev_dbg(&dev->core, "%s:%d: %s no remove method\n", __func__,
926 __LINE__, dev->core.bus_id);
927
Geoff Levand75c86e72007-02-13 17:37:28 -0800928 vuart_bus_priv.devices[dev->priv->port_number] = 0;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800929
Geoff Levand75c86e72007-02-13 17:37:28 -0800930 if (--vuart_bus_priv.use_count == 0) {
931 BUG();
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;
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800935 }
Geoff Levand75c86e72007-02-13 17:37:28 -0800936
937 kfree(dev->priv);
938 dev->priv = NULL;
939
940 up(&vuart_bus_priv.probe_mutex);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800941 return 0;
942}
943
Geert Uytterhoeven5b8e8ee2007-02-12 00:55:15 -0800944static void ps3_vuart_shutdown(struct device *_dev)
945{
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);
949
950 dev_dbg(&dev->core, "%s:%d: %s\n", __func__, __LINE__,
951 dev->core.bus_id);
952
953 if (drv->shutdown)
954 drv->shutdown(dev);
955 else
956 dev_dbg(&dev->core, "%s:%d: %s no shutdown method\n", __func__,
957 __LINE__, dev->core.bus_id);
958}
959
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800960/**
Geoff Levand75c86e72007-02-13 17:37:28 -0800961 * ps3_vuart_bus - The vuart bus instance.
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800962 *
963 * The vuart is managed as a bus that port devices connect to.
964 */
965
Geoff Levand75c86e72007-02-13 17:37:28 -0800966struct bus_type ps3_vuart_bus = {
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800967 .name = "ps3_vuart",
968 .match = ps3_vuart_match,
969 .probe = ps3_vuart_probe,
970 .remove = ps3_vuart_remove,
Geert Uytterhoeven5b8e8ee2007-02-12 00:55:15 -0800971 .shutdown = ps3_vuart_shutdown,
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800972};
973
Geoff Levand75c86e72007-02-13 17:37:28 -0800974int __init ps3_vuart_bus_init(void)
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800975{
976 int result;
977
978 pr_debug("%s:%d:\n", __func__, __LINE__);
Geoff Levand75c86e72007-02-13 17:37:28 -0800979
980 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
981 return 0;
982
983 init_MUTEX(&vuart_bus_priv.probe_mutex);
984 result = bus_register(&ps3_vuart_bus);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800985 BUG_ON(result);
Geoff Levand75c86e72007-02-13 17:37:28 -0800986
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800987 return result;
988}
989
Geoff Levand75c86e72007-02-13 17:37:28 -0800990void __exit ps3_vuart_bus_exit(void)
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800991{
992 pr_debug("%s:%d:\n", __func__, __LINE__);
Geoff Levand75c86e72007-02-13 17:37:28 -0800993 bus_unregister(&ps3_vuart_bus);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800994}
995
Geoff Levand75c86e72007-02-13 17:37:28 -0800996core_initcall(ps3_vuart_bus_init);
997module_exit(ps3_vuart_bus_exit);
Geoff Levand74e95d5d2006-12-08 18:27:47 -0800998
999/**
1000 * ps3_vuart_port_release_device - Remove a vuart port device.
1001 */
1002
1003static void ps3_vuart_port_release_device(struct device *_dev)
1004{
Geoff Levand74e95d5d2006-12-08 18:27:47 -08001005#if defined(DEBUG)
Geoff Levand75c86e72007-02-13 17:37:28 -08001006 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
1007
1008 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
1009
1010 BUG_ON(dev->priv && "forgot to free");
1011 memset(&dev->core, 0, sizeof(dev->core));
Geoff Levand74e95d5d2006-12-08 18:27:47 -08001012#endif
Geoff Levand74e95d5d2006-12-08 18:27:47 -08001013}
1014
1015/**
1016 * ps3_vuart_port_device_register - Add a vuart port device.
1017 */
1018
1019int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev)
1020{
Geoff Levand74e95d5d2006-12-08 18:27:47 -08001021 static unsigned int dev_count = 1;
1022
Geoff Levand75c86e72007-02-13 17:37:28 -08001023 BUG_ON(dev->priv && "forgot to free");
1024
Geoff Levand74e95d5d2006-12-08 18:27:47 -08001025 dev->core.parent = NULL;
Geoff Levand75c86e72007-02-13 17:37:28 -08001026 dev->core.bus = &ps3_vuart_bus;
Geoff Levand74e95d5d2006-12-08 18:27:47 -08001027 dev->core.release = ps3_vuart_port_release_device;
1028
1029 snprintf(dev->core.bus_id, sizeof(dev->core.bus_id), "vuart_%02x",
1030 dev_count++);
1031
1032 dev_dbg(&dev->core, "%s:%d register\n", __func__, __LINE__);
1033
Geoff Levand75c86e72007-02-13 17:37:28 -08001034 return device_register(&dev->core);
Geoff Levand74e95d5d2006-12-08 18:27:47 -08001035}
1036
1037EXPORT_SYMBOL_GPL(ps3_vuart_port_device_register);
1038
1039/**
1040 * ps3_vuart_port_driver_register - Add a vuart port device driver.
1041 */
1042
1043int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv)
1044{
1045 int result;
1046
1047 pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name);
Geoff Levand75c86e72007-02-13 17:37:28 -08001048 drv->core.bus = &ps3_vuart_bus;
Geoff Levand74e95d5d2006-12-08 18:27:47 -08001049 result = driver_register(&drv->core);
1050 return result;
1051}
1052
1053EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_register);
1054
1055/**
1056 * ps3_vuart_port_driver_unregister - Remove a vuart port device driver.
1057 */
1058
1059void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv)
1060{
Geoff Levand75c86e72007-02-13 17:37:28 -08001061 pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name);
Geoff Levand74e95d5d2006-12-08 18:27:47 -08001062 driver_unregister(&drv->core);
1063}
1064
1065EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_unregister);