#include <linux/list.h>
#include <linux/interrupt.h>
#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
#include <linux/device.h>
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>
/*-------------------------------------------------------------------------*/
-static inline char *dmastr(void)
+static inline const char *dmastr(void)
{
if (use_dma == 0)
return "(dma disabled)";
#define FOURBITS "%s%s%s%s"
#define EIGHTBITS FOURBITS FOURBITS
-static void
-dump_intmask(const char *label, u32 mask, char **next, unsigned *size)
+static void dump_intmask(struct seq_file *m, const char *label, u32 mask)
{
- int t;
-
/* int_status is the same format ... */
- t = scnprintf(*next, *size,
+ seq_printf(m,
"%s %05X =" FOURBITS EIGHTBITS EIGHTBITS "\n",
label, mask,
(mask & INT_PWRDETECT) ? " power" : "",
(mask & INT_ENDPOINT0) ? " ep0" : "",
(mask & INT_USBRESET) ? " reset" : "",
(mask & INT_SUSPEND) ? " suspend" : "");
- *size -= t;
- *next += t;
}
-static int
-udc_proc_read(char *buffer, char **start, off_t off, int count,
- int *eof, void *_dev)
+static int udc_proc_read(struct seq_file *m, void *v)
{
- char *buf = buffer;
- struct goku_udc *dev = _dev;
+ struct goku_udc *dev = m->private;
struct goku_udc_regs __iomem *regs = dev->regs;
- char *next = buf;
- unsigned size = count;
unsigned long flags;
- int i, t, is_usb_connected;
+ int i, is_usb_connected;
u32 tmp;
- if (off != 0)
- return 0;
-
local_irq_save(flags);
/* basic device status */
tmp = readl(®s->power_detect);
is_usb_connected = tmp & PW_DETECT;
- t = scnprintf(next, size,
+ seq_printf(m,
"%s - %s\n"
"%s version: %s %s\n"
"Gadget driver: %s\n"
is_usb_connected
? ((tmp & PW_PULLUP) ? "full speed" : "powered")
: "disconnected",
- ({char *state;
+ ({const char *state;
switch(dev->ep0state){
case EP0_DISCONNECT: state = "ep0_disconnect"; break;
case EP0_IDLE: state = "ep0_idle"; break;
default: state = "ep0_?"; break;
} state; })
);
- size -= t;
- next += t;
- dump_intmask("int_status", readl(®s->int_status), &next, &size);
- dump_intmask("int_enable", readl(®s->int_enable), &next, &size);
+ dump_intmask(m, "int_status", readl(®s->int_status));
+ dump_intmask(m, "int_enable", readl(®s->int_enable));
if (!is_usb_connected || !dev->driver || (tmp & PW_PULLUP) == 0)
goto done;
/* registers for (active) device and ep0 */
- t = scnprintf(next, size, "\nirqs %lu\ndataset %02x "
+ if (seq_printf(m, "\nirqs %lu\ndataset %02x "
"single.bcs %02x.%02x state %x addr %u\n",
dev->irqs, readl(®s->DataSet),
readl(®s->EPxSingle), readl(®s->EPxBCS),
readl(®s->UsbState),
- readl(®s->address));
- size -= t;
- next += t;
+ readl(®s->address)) < 0)
+ goto done;
tmp = readl(®s->dma_master);
- t = scnprintf(next, size,
+ if (seq_printf(m,
"dma %03X =" EIGHTBITS "%s %s\n", tmp,
(tmp & MST_EOPB_DIS) ? " eopb-" : "",
(tmp & MST_EOPB_ENA) ? " eopb+" : "",
(tmp & MST_WR_ENA) ? " OUT" : "",
(tmp & MST_CONNECTION)
? "ep1in/ep2out"
- : "ep1out/ep2in");
- size -= t;
- next += t;
+ : "ep1out/ep2in") < 0)
+ goto done;
/* dump endpoint queues */
for (i = 0; i < 4; i++) {
continue;
tmp = readl(ep->reg_status);
- t = scnprintf(next, size,
+ if (seq_printf(m,
"%s %s max %u %s, irqs %lu, "
"status %02x (%s) " FOURBITS "\n",
ep->ep.name,
(tmp & EPxSTATUS_SUSPEND) ? " suspend" : "",
(tmp & EPxSTATUS_FIFO_DISABLE) ? " disable" : "",
(tmp & EPxSTATUS_STAGE_ERROR) ? " ep0stat" : ""
- );
- if (t <= 0 || t > size)
+ ) < 0)
goto done;
- size -= t;
- next += t;
if (list_empty(&ep->queue)) {
- t = scnprintf(next, size, "\t(nothing queued)\n");
- if (t <= 0 || t > size)
+ if (seq_puts(m, "\t(nothing queued)\n") < 0)
goto done;
- size -= t;
- next += t;
continue;
}
list_for_each_entry(req, &ep->queue, queue) {
} else
tmp = req->req.actual;
- t = scnprintf(next, size,
+ if (seq_printf(m,
"\treq %p len %u/%u buf %p\n",
&req->req, tmp, req->req.length,
- req->req.buf);
- if (t <= 0 || t > size)
+ req->req.buf) < 0)
goto done;
- size -= t;
- next += t;
}
}
done:
local_irq_restore(flags);
- *eof = 1;
- return count - size;
+ return 0;
+}
+
+/*
+ * seq_file wrappers for procfile show routines.
+ */
+static int udc_proc_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, udc_proc_read, PDE_DATA(file_inode(file)));
}
+static const struct file_operations udc_proc_fops = {
+ .open = udc_proc_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = seq_release,
+};
+
#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
/*-------------------------------------------------------------------------*/
#ifdef CONFIG_USB_GADGET_DEBUG_FILES
- create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev);
+ proc_create_data(proc_node_name, 0, NULL, &udc_proc_fops, dev);
#endif
retval = device_register(&dev->gadget.dev);