aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>2013-03-27 04:12:03 -0400
committerFelipe Balbi <balbi@ti.com>2013-04-03 07:43:35 -0400
commit0b6a1e6ff7e62a1ab5a8924bffb12c17c183308a (patch)
tree723323da9aeb3781ace1f1b8e5ce7ac87ae42079 /drivers/usb
parent9786b4561228099f579ad88912aa305812526ea1 (diff)
usb: gadget: f_serial: add configfs support
this patch implements the new configfs based interface on f_serial function driver. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/gadget/f_serial.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c
index 49c3d146f9b0..981113c9924d 100644
--- a/drivers/usb/gadget/f_serial.c
+++ b/drivers/usb/gadget/f_serial.c
@@ -258,6 +258,59 @@ fail:
258 return status; 258 return status;
259} 259}
260 260
261static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
262{
263 return container_of(to_config_group(item), struct f_serial_opts,
264 func_inst.group);
265}
266
267CONFIGFS_ATTR_STRUCT(f_serial_opts);
268static ssize_t f_serial_attr_show(struct config_item *item,
269 struct configfs_attribute *attr,
270 char *page)
271{
272 struct f_serial_opts *opts = to_f_serial_opts(item);
273 struct f_serial_opts_attribute *f_serial_opts_attr =
274 container_of(attr, struct f_serial_opts_attribute, attr);
275 ssize_t ret = 0;
276
277 if (f_serial_opts_attr->show)
278 ret = f_serial_opts_attr->show(opts, page);
279
280 return ret;
281}
282
283static void serial_attr_release(struct config_item *item)
284{
285 struct f_serial_opts *opts = to_f_serial_opts(item);
286
287 usb_put_function_instance(&opts->func_inst);
288}
289
290static struct configfs_item_operations serial_item_ops = {
291 .release = serial_attr_release,
292 .show_attribute = f_serial_attr_show,
293};
294
295static ssize_t f_serial_port_num_show(struct f_serial_opts *opts, char *page)
296{
297 return sprintf(page, "%u\n", opts->port_num);
298}
299
300static struct f_serial_opts_attribute f_serial_port_num =
301 __CONFIGFS_ATTR_RO(port_num, f_serial_port_num_show);
302
303static struct configfs_attribute *acm_attrs[] = {
304 &f_serial_port_num.attr,
305 NULL,
306};
307
308static struct config_item_type serial_func_type = {
309 .ct_item_ops = &serial_item_ops,
310 .ct_attrs = acm_attrs,
311 .ct_owner = THIS_MODULE,
312};
313
261static void gser_free_inst(struct usb_function_instance *f) 314static void gser_free_inst(struct usb_function_instance *f)
262{ 315{
263 struct f_serial_opts *opts; 316 struct f_serial_opts *opts;
@@ -282,6 +335,8 @@ static struct usb_function_instance *gser_alloc_inst(void)
282 kfree(opts); 335 kfree(opts);
283 return ERR_PTR(ret); 336 return ERR_PTR(ret);
284 } 337 }
338 config_group_init_type_name(&opts->func_inst.group, "",
339 &serial_func_type);
285 340
286 return &opts->func_inst; 341 return &opts->func_inst;
287} 342}