21 #include <linux/kernel.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
26 #include <linux/bitops.h>
114 #define dump_ports_bmp(_b) _dump_ports_bmp(_b, __func__, __LINE__)
118 pr_debug(
"%s:%d: ports_bmp: %016llxh\n", func, line, bmp->
status);
121 #define dump_port_params(_b) _dump_port_params(_b, __func__, __LINE__)
126 static const char *strings[] = {
141 result = lv1_get_virtual_uart_param(port_number, i, &value);
144 pr_debug(
"%s:%d: port_%u: %s failed: %s\n", func, line,
145 port_number, strings[i], ps3_result(result));
148 pr_debug(
"%s:%d: port_%u: %s = %lxh\n",
149 func, line, port_number, strings[i], value);
167 result = lv1_get_virtual_uart_param(dev->
port_number,
172 dev_dbg(&dev->
core,
"%s:%d: tx_trigger failed: %s\n",
173 __func__, __LINE__, ps3_result(result));
177 result = lv1_get_virtual_uart_param(dev->
port_number,
181 dev_dbg(&dev->
core,
"%s:%d: tx_buf_size failed: %s\n",
182 __func__, __LINE__, ps3_result(result));
186 result = lv1_get_virtual_uart_param(dev->
port_number,
190 dev_dbg(&dev->
core,
"%s:%d: rx_trigger failed: %s\n",
191 __func__, __LINE__, ps3_result(result));
195 trig->
rx = size -
val;
197 dev_dbg(&dev->
core,
"%s:%d: tx %lxh, rx %lxh\n", __func__, __LINE__,
209 result = lv1_set_virtual_uart_param(dev->
port_number,
213 dev_dbg(&dev->
core,
"%s:%d: tx_trigger failed: %s\n",
214 __func__, __LINE__, ps3_result(result));
218 result = lv1_get_virtual_uart_param(dev->
port_number,
222 dev_dbg(&dev->
core,
"%s:%d: tx_buf_size failed: %s\n",
223 __func__, __LINE__, ps3_result(result));
227 result = lv1_set_virtual_uart_param(dev->
port_number,
231 dev_dbg(&dev->
core,
"%s:%d: rx_trigger failed: %s\n",
232 __func__, __LINE__, ps3_result(result));
236 dev_dbg(&dev->
core,
"%s:%d: tx %xh, rx %xh\n", __func__, __LINE__,
247 result = lv1_get_virtual_uart_param(dev->
port_number,
251 dev_dbg(&dev->
core,
"%s:%d: rx_bytes failed: %s\n",
252 __func__, __LINE__, ps3_result(result));
254 dev_dbg(&dev->
core,
"%s:%d: %llxh\n", __func__, __LINE__,
271 dev_dbg(&dev->
core,
"%s:%d: %lxh\n", __func__, __LINE__, mask);
275 result = lv1_set_virtual_uart_param(dev->
port_number,
279 dev_dbg(&dev->
core,
"%s:%d: interrupt_mask failed: %s\n",
280 __func__, __LINE__, ps3_result(result));
292 result = lv1_get_virtual_uart_param(dev->
port_number,
296 dev_dbg(&dev->
core,
"%s:%d: interrupt_status failed: %s\n",
297 __func__, __LINE__, ps3_result(result));
301 dev_dbg(&dev->
core,
"%s:%d: m %llxh, s %llxh, m&s %lxh\n",
369 const void *
buf,
unsigned int bytes,
u64 *bytes_written)
378 dev_dbg(&dev->
core,
"%s:%d: lv1_write_virtual_uart failed: "
379 "%s\n", __func__, __LINE__, ps3_result(result));
383 priv->
stats.bytes_written += *bytes_written;
385 dev_dbg(&dev->
core,
"%s:%d: wrote %llxh/%xh=>%lxh\n", __func__, __LINE__,
386 *bytes_written, bytes, priv->
stats.bytes_written);
399 unsigned int bytes,
u64 *bytes_read)
404 dev_dbg(&dev->
core,
"%s:%d: %xh\n", __func__, __LINE__, bytes);
410 dev_dbg(&dev->
core,
"%s:%d: lv1_read_virtual_uart failed: %s\n",
411 __func__, __LINE__, ps3_result(result));
415 priv->
stats.bytes_read += *bytes_read;
417 dev_dbg(&dev->
core,
"%s:%d: read %llxh/%xh=>%lxh\n", __func__, __LINE__,
418 *bytes_read, bytes, priv->
stats.bytes_read);
439 result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes_waiting);
443 bytes = bytes ?
min(bytes, (
unsigned int)bytes_waiting) : bytes_waiting;
445 dev_dbg(&dev->
core,
"%s:%d: %u\n", __func__, __LINE__, bytes);
459 ps3_vuart_raw_read(dev, tmp, bytes, &bytes_waiting);
465 priv->
stats.bytes_read -= bytes_waiting;
494 static unsigned long dbg_number;
500 dev_dbg(&dev->
core,
"%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
505 if (list_empty(&priv->
tx_list.head)) {
508 result = ps3_vuart_raw_write(dev, buf, bytes, &bytes_written);
510 spin_unlock_irqrestore(&priv->
tx_list.lock, flags);
514 "%s:%d: ps3_vuart_raw_write failed\n",
519 if (bytes_written == bytes) {
521 __func__, __LINE__, bytes);
525 bytes -= bytes_written;
526 buf += bytes_written;
528 spin_unlock_irqrestore(&priv->
tx_list.lock, flags);
543 spin_unlock_irqrestore(&priv->
tx_list.lock, flags);
545 dev_dbg(&dev->
core,
"%s:%d: queued buf_%lu, %xh bytes\n",
571 result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes);
589 ps3_vuart_raw_read(dev, lb->
data, bytes, &bytes);
598 dev_dbg(&dev->
core,
"%s:%d: buf_%lu: queued %llxh bytes\n",
601 *bytes_queued =
bytes;
622 unsigned long bytes_read;
624 dev_dbg(&dev->
core,
"%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
631 while (priv->
rx_list.bytes_held < bytes) {
634 result = ps3_vuart_queue_rx_bytes(dev, &tmp);
635 if (result || !tmp) {
636 dev_dbg(&dev->
core,
"%s:%d: starved for %lxh bytes\n",
638 bytes - priv->
rx_list.bytes_held);
639 spin_unlock_irqrestore(&priv->
rx_list.lock, flags);
645 bytes_read =
min((
unsigned int)(lb->
tail - lb->
head), bytes);
650 priv->
rx_list.bytes_held -= bytes_read;
652 if (bytes_read < lb->
tail - lb->
head) {
653 lb->
head += bytes_read;
654 dev_dbg(&dev->
core,
"%s:%d: buf_%lu: dequeued %lxh "
655 "bytes\n", __func__, __LINE__, lb->
dbg_number,
657 spin_unlock_irqrestore(&priv->
rx_list.lock, flags);
661 dev_dbg(&dev->
core,
"%s:%d: buf_%lu: free, dequeued %lxh "
662 "bytes\n", __func__, __LINE__, lb->
dbg_number,
669 spin_unlock_irqrestore(&priv->
rx_list.lock, flags);
681 ps3_vuart_work_to_system_bus_dev(work);
683 ps3_system_bus_dev_to_vuart_drv(dev);
694 if (priv->
rx_list.work.trigger) {
695 dev_dbg(&dev->
core,
"%s:%d: warning, multiple calls\n",
705 if (priv->
rx_list.bytes_held >= bytes) {
706 dev_dbg(&dev->
core,
"%s:%d: schedule_work %xh bytes\n",
707 __func__, __LINE__, bytes);
709 spin_unlock_irqrestore(&priv->
rx_list.lock, flags);
714 spin_unlock_irqrestore(&priv->
rx_list.lock, flags);
716 dev_dbg(&dev->
core,
"%s:%d: waiting for %u(%xh) bytes\n", __func__,
717 __LINE__, bytes, bytes);
725 to_port_priv(dev)->rx_list.work.trigger = 0;
743 unsigned long bytes_total = 0;
745 dev_dbg(&dev->
core,
"%s:%d\n", __func__, __LINE__);
753 result = ps3_vuart_raw_write(dev, lb->
head, lb->
tail - lb->
head,
758 "%s:%d: ps3_vuart_raw_write failed\n",
763 bytes_total += bytes_written;
765 if (bytes_written < lb->
tail - lb->
head) {
766 lb->
head += bytes_written;
768 "%s:%d cleared buf_%lu, %llxh bytes\n",
774 dev_dbg(&dev->
core,
"%s:%d free buf_%lu\n", __func__, __LINE__,
783 spin_unlock_irqrestore(&priv->
tx_list.lock, flags);
784 dev_dbg(&dev->
core,
"%s:%d wrote %lxh bytes total\n",
785 __func__, __LINE__, bytes_total);
804 dev_dbg(&dev->
core,
"%s:%d\n", __func__, __LINE__);
807 result = ps3_vuart_queue_rx_bytes(dev, &bytes);
810 spin_unlock_irqrestore(&priv->
rx_list.lock, flags);
815 >= priv->
rx_list.work.trigger) {
816 dev_dbg(&dev->
core,
"%s:%d: schedule_work %lxh bytes\n",
817 __func__, __LINE__, priv->
rx_list.work.trigger);
818 priv->
rx_list.work.trigger = 0;
822 spin_unlock_irqrestore(&priv->
rx_list.lock, flags);
826 static int ps3_vuart_handle_interrupt_disconnect(
829 dev_dbg(&dev->
core,
"%s:%d\n", __func__, __LINE__);
848 result = ps3_vuart_get_interrupt_status(dev, &status);
853 dev_dbg(&dev->
core,
"%s:%d: status: %lxh\n", __func__, __LINE__,
857 priv->
stats.disconnect_interrupts++;
858 result = ps3_vuart_handle_interrupt_disconnect(dev);
864 priv->
stats.tx_interrupts++;
865 result = ps3_vuart_handle_interrupt_tx(dev);
871 priv->
stats.rx_interrupts++;
872 result = ps3_vuart_handle_interrupt_rx(dev);
896 static irqreturn_t ps3_vuart_irq_handler(
int irq,
void *_private)
915 ps3_vuart_handle_port_interrupt(bus_priv->
devices[port]);
921 static int ps3_vuart_bus_interrupt_get(
void)
925 pr_debug(
" -> %s:%d\n", __func__, __LINE__);
939 pr_debug(
"%s:%d: kzalloc failed.\n", __func__, __LINE__);
941 goto fail_bmp_malloc;
948 pr_debug(
"%s:%d: ps3_vuart_irq_setup failed (%d)\n",
949 __func__, __LINE__, result);
958 pr_debug(
"%s:%d: request_irq failed (%d)\n",
959 __func__, __LINE__, result);
960 goto fail_request_irq;
963 pr_debug(
" <- %s:%d: ok\n", __func__, __LINE__);
974 pr_debug(
" <- %s:%d: failed\n", __func__, __LINE__);
978 static int ps3_vuart_bus_interrupt_put(
void)
980 pr_debug(
" -> %s:%d\n", __func__, __LINE__);
997 pr_debug(
" <- %s:%d\n", __func__, __LINE__);
1007 dev_dbg(&dev->
core,
"%s:%d\n", __func__, __LINE__);
1009 drv = ps3_system_bus_dev_to_vuart_drv(dev);
1011 dev_dbg(&dev->
core,
"%s:%d: (%s)\n", __func__, __LINE__,
1012 drv->
core.core.name);
1023 result = ps3_vuart_bus_interrupt_get();
1026 goto fail_setup_interrupt;
1029 dev_dbg(&dev->
core,
"%s:%d: port busy (%d)\n", __func__,
1044 goto fail_dev_malloc;
1047 priv = to_port_priv(dev);
1049 INIT_LIST_HEAD(&priv->
tx_list.head);
1052 INIT_LIST_HEAD(&priv->
rx_list.head);
1056 priv->
rx_list.work.trigger = 0;
1063 ps3_vuart_set_interrupt_mask(dev, INTERRUPT_MASK_RX);
1068 result = drv->
probe(dev);
1071 dev_info(&dev->
core,
"%s:%d: no probe method\n", __func__,
1077 __func__, __LINE__);
1086 ps3_vuart_set_interrupt_mask(dev, 0);
1092 ps3_vuart_bus_interrupt_put();
1093 fail_setup_interrupt:
1095 dev_dbg(&dev->
core,
"%s:%d: failed\n", __func__, __LINE__);
1110 dev_dbg(&dev->
core,
"%s:%d\n", __func__, __LINE__);
1113 ps3_vuart_set_interrupt_mask(dev, 0);
1114 ps3_vuart_bus_interrupt_put();
1135 dev_dbg(&dev->
core,
" -> %s:%d: match_id %d\n", __func__, __LINE__,
1138 if (!dev->
core.driver) {
1139 dev_dbg(&dev->
core,
"%s:%d: no driver bound\n", __func__,
1145 drv = ps3_system_bus_dev_to_vuart_drv(dev);
1152 dev_dbg(&dev->
core,
"%s:%d: no remove method\n", __func__,
1157 ps3_vuart_cleanup(dev);
1163 dev_dbg(&dev->
core,
" <- %s:%d\n", __func__, __LINE__);
1186 dev_dbg(&dev->
core,
" -> %s:%d: match_id %d\n", __func__, __LINE__,
1189 if (!dev->
core.driver) {
1190 dev_dbg(&dev->
core,
"%s:%d: no driver bound\n", __func__,
1196 drv = ps3_system_bus_dev_to_vuart_drv(dev);
1203 dev_dbg(&dev->
core,
"%s:%d: no shutdown, calling remove\n",
1204 __func__, __LINE__);
1207 dev_dbg(&dev->
core,
"%s:%d: no shutdown method\n", __func__,
1212 ps3_vuart_cleanup(dev);
1214 dev_dbg(&dev->
core,
" <- %s:%d\n", __func__, __LINE__);
1220 static int __init ps3_vuart_bus_init(
void)
1222 pr_debug(
"%s:%d:\n", __func__, __LINE__);
1224 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
1232 static void __exit ps3_vuart_bus_exit(
void)
1234 pr_debug(
"%s:%d:\n", __func__, __LINE__);
1248 pr_debug(
"%s:%d: (%s)\n", __func__, __LINE__, drv->
core.core.name);
1253 drv->
core.probe = ps3_vuart_probe;
1254 drv->
core.remove = ps3_vuart_remove;
1255 drv->
core.shutdown = ps3_vuart_shutdown;
1268 pr_debug(
"%s:%d: (%s)\n", __func__, __LINE__, drv->
core.core.name);