xref: /openbmc/linux/drivers/uio/uio_dfl.c (revision c9d9d11b)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Generic DFL driver for Userspace I/O devicess
4  *
5  * Copyright (C) 2021 Intel Corporation, Inc.
6  */
7 #include <linux/dfl.h>
8 #include <linux/errno.h>
9 #include <linux/module.h>
10 #include <linux/uio_driver.h>
11 
12 #define DRIVER_NAME "uio_dfl"
13 
uio_dfl_probe(struct dfl_device * ddev)14 static int uio_dfl_probe(struct dfl_device *ddev)
15 {
16 	struct resource *r = &ddev->mmio_res;
17 	struct device *dev = &ddev->dev;
18 	struct uio_info *uioinfo;
19 	struct uio_mem *uiomem;
20 	int ret;
21 
22 	uioinfo = devm_kzalloc(dev, sizeof(struct uio_info), GFP_KERNEL);
23 	if (!uioinfo)
24 		return -ENOMEM;
25 
26 	uioinfo->name = DRIVER_NAME;
27 	uioinfo->version = "0";
28 
29 	uiomem = &uioinfo->mem[0];
30 	uiomem->memtype = UIO_MEM_PHYS;
31 	uiomem->addr = r->start & PAGE_MASK;
32 	uiomem->offs = r->start & ~PAGE_MASK;
33 	uiomem->size = (uiomem->offs + resource_size(r)
34 			+ PAGE_SIZE - 1) & PAGE_MASK;
35 	uiomem->name = r->name;
36 
37 	/* Irq is yet to be supported */
38 	uioinfo->irq = UIO_IRQ_NONE;
39 
40 	ret = devm_uio_register_device(dev, uioinfo);
41 	if (ret)
42 		dev_err(dev, "unable to register uio device\n");
43 
44 	return ret;
45 }
46 
47 #define FME_FEATURE_ID_ETH_GROUP	0x10
48 #define FME_FEATURE_ID_HSSI_SUBSYS	0x15
49 #define FME_FEATURE_ID_VENDOR_SPECIFIC	0x23
50 #define PORT_FEATURE_ID_IOPLL_USRCLK	0x14
51 
52 static const struct dfl_device_id uio_dfl_ids[] = {
53 	{ FME_ID, FME_FEATURE_ID_ETH_GROUP },
54 	{ FME_ID, FME_FEATURE_ID_HSSI_SUBSYS },
55 	{ FME_ID, FME_FEATURE_ID_VENDOR_SPECIFIC },
56 	{ PORT_ID, PORT_FEATURE_ID_IOPLL_USRCLK },
57 	{ }
58 };
59 MODULE_DEVICE_TABLE(dfl, uio_dfl_ids);
60 
61 static struct dfl_driver uio_dfl_driver = {
62 	.drv = {
63 		.name = DRIVER_NAME,
64 	},
65 	.id_table	= uio_dfl_ids,
66 	.probe		= uio_dfl_probe,
67 };
68 module_dfl_driver(uio_dfl_driver);
69 
70 MODULE_DESCRIPTION("Generic DFL driver for Userspace I/O devices");
71 MODULE_AUTHOR("Intel Corporation");
72 MODULE_LICENSE("GPL v2");
73