1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Driver for FPGA Management Engine (FME)
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2017-2018 Intel Corporation, Inc.
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Authors:
8*4882a593Smuzhiyun * Kang Luwei <luwei.kang@intel.com>
9*4882a593Smuzhiyun * Xiao Guangrong <guangrong.xiao@linux.intel.com>
10*4882a593Smuzhiyun * Joseph Grecco <joe.grecco@intel.com>
11*4882a593Smuzhiyun * Enno Luebbers <enno.luebbers@intel.com>
12*4882a593Smuzhiyun * Tim Whisonant <tim.whisonant@intel.com>
13*4882a593Smuzhiyun * Ananda Ravuri <ananda.ravuri@intel.com>
14*4882a593Smuzhiyun * Henry Mitchel <henry.mitchel@intel.com>
15*4882a593Smuzhiyun */
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #include <linux/hwmon.h>
18*4882a593Smuzhiyun #include <linux/hwmon-sysfs.h>
19*4882a593Smuzhiyun #include <linux/kernel.h>
20*4882a593Smuzhiyun #include <linux/module.h>
21*4882a593Smuzhiyun #include <linux/uaccess.h>
22*4882a593Smuzhiyun #include <linux/fpga-dfl.h>
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #include "dfl.h"
25*4882a593Smuzhiyun #include "dfl-fme.h"
26*4882a593Smuzhiyun
ports_num_show(struct device * dev,struct device_attribute * attr,char * buf)27*4882a593Smuzhiyun static ssize_t ports_num_show(struct device *dev,
28*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
29*4882a593Smuzhiyun {
30*4882a593Smuzhiyun void __iomem *base;
31*4882a593Smuzhiyun u64 v;
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_HEADER);
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun v = readq(base + FME_HDR_CAP);
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "%u\n",
38*4882a593Smuzhiyun (unsigned int)FIELD_GET(FME_CAP_NUM_PORTS, v));
39*4882a593Smuzhiyun }
40*4882a593Smuzhiyun static DEVICE_ATTR_RO(ports_num);
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun /*
43*4882a593Smuzhiyun * Bitstream (static FPGA region) identifier number. It contains the
44*4882a593Smuzhiyun * detailed version and other information of this static FPGA region.
45*4882a593Smuzhiyun */
bitstream_id_show(struct device * dev,struct device_attribute * attr,char * buf)46*4882a593Smuzhiyun static ssize_t bitstream_id_show(struct device *dev,
47*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun void __iomem *base;
50*4882a593Smuzhiyun u64 v;
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_HEADER);
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun v = readq(base + FME_HDR_BITSTREAM_ID);
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "0x%llx\n", (unsigned long long)v);
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun static DEVICE_ATTR_RO(bitstream_id);
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun /*
61*4882a593Smuzhiyun * Bitstream (static FPGA region) meta data. It contains the synthesis
62*4882a593Smuzhiyun * date, seed and other information of this static FPGA region.
63*4882a593Smuzhiyun */
bitstream_metadata_show(struct device * dev,struct device_attribute * attr,char * buf)64*4882a593Smuzhiyun static ssize_t bitstream_metadata_show(struct device *dev,
65*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
66*4882a593Smuzhiyun {
67*4882a593Smuzhiyun void __iomem *base;
68*4882a593Smuzhiyun u64 v;
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_HEADER);
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun v = readq(base + FME_HDR_BITSTREAM_MD);
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun return scnprintf(buf, PAGE_SIZE, "0x%llx\n", (unsigned long long)v);
75*4882a593Smuzhiyun }
76*4882a593Smuzhiyun static DEVICE_ATTR_RO(bitstream_metadata);
77*4882a593Smuzhiyun
cache_size_show(struct device * dev,struct device_attribute * attr,char * buf)78*4882a593Smuzhiyun static ssize_t cache_size_show(struct device *dev,
79*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun void __iomem *base;
82*4882a593Smuzhiyun u64 v;
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_HEADER);
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun v = readq(base + FME_HDR_CAP);
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun return sprintf(buf, "%u\n",
89*4882a593Smuzhiyun (unsigned int)FIELD_GET(FME_CAP_CACHE_SIZE, v));
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun static DEVICE_ATTR_RO(cache_size);
92*4882a593Smuzhiyun
fabric_version_show(struct device * dev,struct device_attribute * attr,char * buf)93*4882a593Smuzhiyun static ssize_t fabric_version_show(struct device *dev,
94*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun void __iomem *base;
97*4882a593Smuzhiyun u64 v;
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_HEADER);
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun v = readq(base + FME_HDR_CAP);
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun return sprintf(buf, "%u\n",
104*4882a593Smuzhiyun (unsigned int)FIELD_GET(FME_CAP_FABRIC_VERID, v));
105*4882a593Smuzhiyun }
106*4882a593Smuzhiyun static DEVICE_ATTR_RO(fabric_version);
107*4882a593Smuzhiyun
socket_id_show(struct device * dev,struct device_attribute * attr,char * buf)108*4882a593Smuzhiyun static ssize_t socket_id_show(struct device *dev,
109*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun void __iomem *base;
112*4882a593Smuzhiyun u64 v;
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun base = dfl_get_feature_ioaddr_by_id(dev, FME_FEATURE_ID_HEADER);
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun v = readq(base + FME_HDR_CAP);
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun return sprintf(buf, "%u\n",
119*4882a593Smuzhiyun (unsigned int)FIELD_GET(FME_CAP_SOCKET_ID, v));
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun static DEVICE_ATTR_RO(socket_id);
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun static struct attribute *fme_hdr_attrs[] = {
124*4882a593Smuzhiyun &dev_attr_ports_num.attr,
125*4882a593Smuzhiyun &dev_attr_bitstream_id.attr,
126*4882a593Smuzhiyun &dev_attr_bitstream_metadata.attr,
127*4882a593Smuzhiyun &dev_attr_cache_size.attr,
128*4882a593Smuzhiyun &dev_attr_fabric_version.attr,
129*4882a593Smuzhiyun &dev_attr_socket_id.attr,
130*4882a593Smuzhiyun NULL,
131*4882a593Smuzhiyun };
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun static const struct attribute_group fme_hdr_group = {
134*4882a593Smuzhiyun .attrs = fme_hdr_attrs,
135*4882a593Smuzhiyun };
136*4882a593Smuzhiyun
fme_hdr_ioctl_release_port(struct dfl_feature_platform_data * pdata,unsigned long arg)137*4882a593Smuzhiyun static long fme_hdr_ioctl_release_port(struct dfl_feature_platform_data *pdata,
138*4882a593Smuzhiyun unsigned long arg)
139*4882a593Smuzhiyun {
140*4882a593Smuzhiyun struct dfl_fpga_cdev *cdev = pdata->dfl_cdev;
141*4882a593Smuzhiyun int port_id;
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun if (get_user(port_id, (int __user *)arg))
144*4882a593Smuzhiyun return -EFAULT;
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun return dfl_fpga_cdev_release_port(cdev, port_id);
147*4882a593Smuzhiyun }
148*4882a593Smuzhiyun
fme_hdr_ioctl_assign_port(struct dfl_feature_platform_data * pdata,unsigned long arg)149*4882a593Smuzhiyun static long fme_hdr_ioctl_assign_port(struct dfl_feature_platform_data *pdata,
150*4882a593Smuzhiyun unsigned long arg)
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun struct dfl_fpga_cdev *cdev = pdata->dfl_cdev;
153*4882a593Smuzhiyun int port_id;
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun if (get_user(port_id, (int __user *)arg))
156*4882a593Smuzhiyun return -EFAULT;
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun return dfl_fpga_cdev_assign_port(cdev, port_id);
159*4882a593Smuzhiyun }
160*4882a593Smuzhiyun
fme_hdr_ioctl(struct platform_device * pdev,struct dfl_feature * feature,unsigned int cmd,unsigned long arg)161*4882a593Smuzhiyun static long fme_hdr_ioctl(struct platform_device *pdev,
162*4882a593Smuzhiyun struct dfl_feature *feature,
163*4882a593Smuzhiyun unsigned int cmd, unsigned long arg)
164*4882a593Smuzhiyun {
165*4882a593Smuzhiyun struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun switch (cmd) {
168*4882a593Smuzhiyun case DFL_FPGA_FME_PORT_RELEASE:
169*4882a593Smuzhiyun return fme_hdr_ioctl_release_port(pdata, arg);
170*4882a593Smuzhiyun case DFL_FPGA_FME_PORT_ASSIGN:
171*4882a593Smuzhiyun return fme_hdr_ioctl_assign_port(pdata, arg);
172*4882a593Smuzhiyun }
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun return -ENODEV;
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun static const struct dfl_feature_id fme_hdr_id_table[] = {
178*4882a593Smuzhiyun {.id = FME_FEATURE_ID_HEADER,},
179*4882a593Smuzhiyun {0,}
180*4882a593Smuzhiyun };
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun static const struct dfl_feature_ops fme_hdr_ops = {
183*4882a593Smuzhiyun .ioctl = fme_hdr_ioctl,
184*4882a593Smuzhiyun };
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun #define FME_THERM_THRESHOLD 0x8
187*4882a593Smuzhiyun #define TEMP_THRESHOLD1 GENMASK_ULL(6, 0)
188*4882a593Smuzhiyun #define TEMP_THRESHOLD1_EN BIT_ULL(7)
189*4882a593Smuzhiyun #define TEMP_THRESHOLD2 GENMASK_ULL(14, 8)
190*4882a593Smuzhiyun #define TEMP_THRESHOLD2_EN BIT_ULL(15)
191*4882a593Smuzhiyun #define TRIP_THRESHOLD GENMASK_ULL(30, 24)
192*4882a593Smuzhiyun #define TEMP_THRESHOLD1_STATUS BIT_ULL(32) /* threshold1 reached */
193*4882a593Smuzhiyun #define TEMP_THRESHOLD2_STATUS BIT_ULL(33) /* threshold2 reached */
194*4882a593Smuzhiyun /* threshold1 policy: 0 - AP2 (90% throttle) / 1 - AP1 (50% throttle) */
195*4882a593Smuzhiyun #define TEMP_THRESHOLD1_POLICY BIT_ULL(44)
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun #define FME_THERM_RDSENSOR_FMT1 0x10
198*4882a593Smuzhiyun #define FPGA_TEMPERATURE GENMASK_ULL(6, 0)
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun #define FME_THERM_CAP 0x20
201*4882a593Smuzhiyun #define THERM_NO_THROTTLE BIT_ULL(0)
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun #define MD_PRE_DEG
204*4882a593Smuzhiyun
fme_thermal_throttle_support(void __iomem * base)205*4882a593Smuzhiyun static bool fme_thermal_throttle_support(void __iomem *base)
206*4882a593Smuzhiyun {
207*4882a593Smuzhiyun u64 v = readq(base + FME_THERM_CAP);
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun return FIELD_GET(THERM_NO_THROTTLE, v) ? false : true;
210*4882a593Smuzhiyun }
211*4882a593Smuzhiyun
thermal_hwmon_attrs_visible(const void * drvdata,enum hwmon_sensor_types type,u32 attr,int channel)212*4882a593Smuzhiyun static umode_t thermal_hwmon_attrs_visible(const void *drvdata,
213*4882a593Smuzhiyun enum hwmon_sensor_types type,
214*4882a593Smuzhiyun u32 attr, int channel)
215*4882a593Smuzhiyun {
216*4882a593Smuzhiyun const struct dfl_feature *feature = drvdata;
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun /* temperature is always supported, and check hardware cap for others */
219*4882a593Smuzhiyun if (attr == hwmon_temp_input)
220*4882a593Smuzhiyun return 0444;
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun return fme_thermal_throttle_support(feature->ioaddr) ? 0444 : 0;
223*4882a593Smuzhiyun }
224*4882a593Smuzhiyun
thermal_hwmon_read(struct device * dev,enum hwmon_sensor_types type,u32 attr,int channel,long * val)225*4882a593Smuzhiyun static int thermal_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
226*4882a593Smuzhiyun u32 attr, int channel, long *val)
227*4882a593Smuzhiyun {
228*4882a593Smuzhiyun struct dfl_feature *feature = dev_get_drvdata(dev);
229*4882a593Smuzhiyun u64 v;
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun switch (attr) {
232*4882a593Smuzhiyun case hwmon_temp_input:
233*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_THERM_RDSENSOR_FMT1);
234*4882a593Smuzhiyun *val = (long)(FIELD_GET(FPGA_TEMPERATURE, v) * 1000);
235*4882a593Smuzhiyun break;
236*4882a593Smuzhiyun case hwmon_temp_max:
237*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_THERM_THRESHOLD);
238*4882a593Smuzhiyun *val = (long)(FIELD_GET(TEMP_THRESHOLD1, v) * 1000);
239*4882a593Smuzhiyun break;
240*4882a593Smuzhiyun case hwmon_temp_crit:
241*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_THERM_THRESHOLD);
242*4882a593Smuzhiyun *val = (long)(FIELD_GET(TEMP_THRESHOLD2, v) * 1000);
243*4882a593Smuzhiyun break;
244*4882a593Smuzhiyun case hwmon_temp_emergency:
245*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_THERM_THRESHOLD);
246*4882a593Smuzhiyun *val = (long)(FIELD_GET(TRIP_THRESHOLD, v) * 1000);
247*4882a593Smuzhiyun break;
248*4882a593Smuzhiyun case hwmon_temp_max_alarm:
249*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_THERM_THRESHOLD);
250*4882a593Smuzhiyun *val = (long)FIELD_GET(TEMP_THRESHOLD1_STATUS, v);
251*4882a593Smuzhiyun break;
252*4882a593Smuzhiyun case hwmon_temp_crit_alarm:
253*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_THERM_THRESHOLD);
254*4882a593Smuzhiyun *val = (long)FIELD_GET(TEMP_THRESHOLD2_STATUS, v);
255*4882a593Smuzhiyun break;
256*4882a593Smuzhiyun default:
257*4882a593Smuzhiyun return -EOPNOTSUPP;
258*4882a593Smuzhiyun }
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun return 0;
261*4882a593Smuzhiyun }
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun static const struct hwmon_ops thermal_hwmon_ops = {
264*4882a593Smuzhiyun .is_visible = thermal_hwmon_attrs_visible,
265*4882a593Smuzhiyun .read = thermal_hwmon_read,
266*4882a593Smuzhiyun };
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun static const struct hwmon_channel_info *thermal_hwmon_info[] = {
269*4882a593Smuzhiyun HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_EMERGENCY |
270*4882a593Smuzhiyun HWMON_T_MAX | HWMON_T_MAX_ALARM |
271*4882a593Smuzhiyun HWMON_T_CRIT | HWMON_T_CRIT_ALARM),
272*4882a593Smuzhiyun NULL
273*4882a593Smuzhiyun };
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun static const struct hwmon_chip_info thermal_hwmon_chip_info = {
276*4882a593Smuzhiyun .ops = &thermal_hwmon_ops,
277*4882a593Smuzhiyun .info = thermal_hwmon_info,
278*4882a593Smuzhiyun };
279*4882a593Smuzhiyun
temp1_max_policy_show(struct device * dev,struct device_attribute * attr,char * buf)280*4882a593Smuzhiyun static ssize_t temp1_max_policy_show(struct device *dev,
281*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
282*4882a593Smuzhiyun {
283*4882a593Smuzhiyun struct dfl_feature *feature = dev_get_drvdata(dev);
284*4882a593Smuzhiyun u64 v;
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_THERM_THRESHOLD);
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun return sprintf(buf, "%u\n",
289*4882a593Smuzhiyun (unsigned int)FIELD_GET(TEMP_THRESHOLD1_POLICY, v));
290*4882a593Smuzhiyun }
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun static DEVICE_ATTR_RO(temp1_max_policy);
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun static struct attribute *thermal_extra_attrs[] = {
295*4882a593Smuzhiyun &dev_attr_temp1_max_policy.attr,
296*4882a593Smuzhiyun NULL,
297*4882a593Smuzhiyun };
298*4882a593Smuzhiyun
thermal_extra_attrs_visible(struct kobject * kobj,struct attribute * attr,int index)299*4882a593Smuzhiyun static umode_t thermal_extra_attrs_visible(struct kobject *kobj,
300*4882a593Smuzhiyun struct attribute *attr, int index)
301*4882a593Smuzhiyun {
302*4882a593Smuzhiyun struct device *dev = kobj_to_dev(kobj);
303*4882a593Smuzhiyun struct dfl_feature *feature = dev_get_drvdata(dev);
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun return fme_thermal_throttle_support(feature->ioaddr) ? attr->mode : 0;
306*4882a593Smuzhiyun }
307*4882a593Smuzhiyun
308*4882a593Smuzhiyun static const struct attribute_group thermal_extra_group = {
309*4882a593Smuzhiyun .attrs = thermal_extra_attrs,
310*4882a593Smuzhiyun .is_visible = thermal_extra_attrs_visible,
311*4882a593Smuzhiyun };
312*4882a593Smuzhiyun __ATTRIBUTE_GROUPS(thermal_extra);
313*4882a593Smuzhiyun
fme_thermal_mgmt_init(struct platform_device * pdev,struct dfl_feature * feature)314*4882a593Smuzhiyun static int fme_thermal_mgmt_init(struct platform_device *pdev,
315*4882a593Smuzhiyun struct dfl_feature *feature)
316*4882a593Smuzhiyun {
317*4882a593Smuzhiyun struct device *hwmon;
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun /*
320*4882a593Smuzhiyun * create hwmon to allow userspace monitoring temperature and other
321*4882a593Smuzhiyun * threshold information.
322*4882a593Smuzhiyun *
323*4882a593Smuzhiyun * temp1_input -> FPGA device temperature
324*4882a593Smuzhiyun * temp1_max -> hardware threshold 1 -> 50% or 90% throttling
325*4882a593Smuzhiyun * temp1_crit -> hardware threshold 2 -> 100% throttling
326*4882a593Smuzhiyun * temp1_emergency -> hardware trip_threshold to shutdown FPGA
327*4882a593Smuzhiyun * temp1_max_alarm -> hardware threshold 1 alarm
328*4882a593Smuzhiyun * temp1_crit_alarm -> hardware threshold 2 alarm
329*4882a593Smuzhiyun *
330*4882a593Smuzhiyun * create device specific sysfs interfaces, e.g. read temp1_max_policy
331*4882a593Smuzhiyun * to understand the actual hardware throttling action (50% vs 90%).
332*4882a593Smuzhiyun *
333*4882a593Smuzhiyun * If hardware doesn't support automatic throttling per thresholds,
334*4882a593Smuzhiyun * then all above sysfs interfaces are not visible except temp1_input
335*4882a593Smuzhiyun * for temperature.
336*4882a593Smuzhiyun */
337*4882a593Smuzhiyun hwmon = devm_hwmon_device_register_with_info(&pdev->dev,
338*4882a593Smuzhiyun "dfl_fme_thermal", feature,
339*4882a593Smuzhiyun &thermal_hwmon_chip_info,
340*4882a593Smuzhiyun thermal_extra_groups);
341*4882a593Smuzhiyun if (IS_ERR(hwmon)) {
342*4882a593Smuzhiyun dev_err(&pdev->dev, "Fail to register thermal hwmon\n");
343*4882a593Smuzhiyun return PTR_ERR(hwmon);
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun return 0;
347*4882a593Smuzhiyun }
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun static const struct dfl_feature_id fme_thermal_mgmt_id_table[] = {
350*4882a593Smuzhiyun {.id = FME_FEATURE_ID_THERMAL_MGMT,},
351*4882a593Smuzhiyun {0,}
352*4882a593Smuzhiyun };
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun static const struct dfl_feature_ops fme_thermal_mgmt_ops = {
355*4882a593Smuzhiyun .init = fme_thermal_mgmt_init,
356*4882a593Smuzhiyun };
357*4882a593Smuzhiyun
358*4882a593Smuzhiyun #define FME_PWR_STATUS 0x8
359*4882a593Smuzhiyun #define FME_LATENCY_TOLERANCE BIT_ULL(18)
360*4882a593Smuzhiyun #define PWR_CONSUMED GENMASK_ULL(17, 0)
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun #define FME_PWR_THRESHOLD 0x10
363*4882a593Smuzhiyun #define PWR_THRESHOLD1 GENMASK_ULL(6, 0) /* in Watts */
364*4882a593Smuzhiyun #define PWR_THRESHOLD2 GENMASK_ULL(14, 8) /* in Watts */
365*4882a593Smuzhiyun #define PWR_THRESHOLD_MAX 0x7f /* in Watts */
366*4882a593Smuzhiyun #define PWR_THRESHOLD1_STATUS BIT_ULL(16)
367*4882a593Smuzhiyun #define PWR_THRESHOLD2_STATUS BIT_ULL(17)
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun #define FME_PWR_XEON_LIMIT 0x18
370*4882a593Smuzhiyun #define XEON_PWR_LIMIT GENMASK_ULL(14, 0) /* in 0.1 Watts */
371*4882a593Smuzhiyun #define XEON_PWR_EN BIT_ULL(15)
372*4882a593Smuzhiyun #define FME_PWR_FPGA_LIMIT 0x20
373*4882a593Smuzhiyun #define FPGA_PWR_LIMIT GENMASK_ULL(14, 0) /* in 0.1 Watts */
374*4882a593Smuzhiyun #define FPGA_PWR_EN BIT_ULL(15)
375*4882a593Smuzhiyun
power_hwmon_read(struct device * dev,enum hwmon_sensor_types type,u32 attr,int channel,long * val)376*4882a593Smuzhiyun static int power_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
377*4882a593Smuzhiyun u32 attr, int channel, long *val)
378*4882a593Smuzhiyun {
379*4882a593Smuzhiyun struct dfl_feature *feature = dev_get_drvdata(dev);
380*4882a593Smuzhiyun u64 v;
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun switch (attr) {
383*4882a593Smuzhiyun case hwmon_power_input:
384*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_PWR_STATUS);
385*4882a593Smuzhiyun *val = (long)(FIELD_GET(PWR_CONSUMED, v) * 1000000);
386*4882a593Smuzhiyun break;
387*4882a593Smuzhiyun case hwmon_power_max:
388*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_PWR_THRESHOLD);
389*4882a593Smuzhiyun *val = (long)(FIELD_GET(PWR_THRESHOLD1, v) * 1000000);
390*4882a593Smuzhiyun break;
391*4882a593Smuzhiyun case hwmon_power_crit:
392*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_PWR_THRESHOLD);
393*4882a593Smuzhiyun *val = (long)(FIELD_GET(PWR_THRESHOLD2, v) * 1000000);
394*4882a593Smuzhiyun break;
395*4882a593Smuzhiyun case hwmon_power_max_alarm:
396*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_PWR_THRESHOLD);
397*4882a593Smuzhiyun *val = (long)FIELD_GET(PWR_THRESHOLD1_STATUS, v);
398*4882a593Smuzhiyun break;
399*4882a593Smuzhiyun case hwmon_power_crit_alarm:
400*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_PWR_THRESHOLD);
401*4882a593Smuzhiyun *val = (long)FIELD_GET(PWR_THRESHOLD2_STATUS, v);
402*4882a593Smuzhiyun break;
403*4882a593Smuzhiyun default:
404*4882a593Smuzhiyun return -EOPNOTSUPP;
405*4882a593Smuzhiyun }
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun return 0;
408*4882a593Smuzhiyun }
409*4882a593Smuzhiyun
power_hwmon_write(struct device * dev,enum hwmon_sensor_types type,u32 attr,int channel,long val)410*4882a593Smuzhiyun static int power_hwmon_write(struct device *dev, enum hwmon_sensor_types type,
411*4882a593Smuzhiyun u32 attr, int channel, long val)
412*4882a593Smuzhiyun {
413*4882a593Smuzhiyun struct dfl_feature_platform_data *pdata = dev_get_platdata(dev->parent);
414*4882a593Smuzhiyun struct dfl_feature *feature = dev_get_drvdata(dev);
415*4882a593Smuzhiyun int ret = 0;
416*4882a593Smuzhiyun u64 v;
417*4882a593Smuzhiyun
418*4882a593Smuzhiyun val = clamp_val(val / 1000000, 0, PWR_THRESHOLD_MAX);
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun mutex_lock(&pdata->lock);
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun switch (attr) {
423*4882a593Smuzhiyun case hwmon_power_max:
424*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_PWR_THRESHOLD);
425*4882a593Smuzhiyun v &= ~PWR_THRESHOLD1;
426*4882a593Smuzhiyun v |= FIELD_PREP(PWR_THRESHOLD1, val);
427*4882a593Smuzhiyun writeq(v, feature->ioaddr + FME_PWR_THRESHOLD);
428*4882a593Smuzhiyun break;
429*4882a593Smuzhiyun case hwmon_power_crit:
430*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_PWR_THRESHOLD);
431*4882a593Smuzhiyun v &= ~PWR_THRESHOLD2;
432*4882a593Smuzhiyun v |= FIELD_PREP(PWR_THRESHOLD2, val);
433*4882a593Smuzhiyun writeq(v, feature->ioaddr + FME_PWR_THRESHOLD);
434*4882a593Smuzhiyun break;
435*4882a593Smuzhiyun default:
436*4882a593Smuzhiyun ret = -EOPNOTSUPP;
437*4882a593Smuzhiyun break;
438*4882a593Smuzhiyun }
439*4882a593Smuzhiyun
440*4882a593Smuzhiyun mutex_unlock(&pdata->lock);
441*4882a593Smuzhiyun
442*4882a593Smuzhiyun return ret;
443*4882a593Smuzhiyun }
444*4882a593Smuzhiyun
power_hwmon_attrs_visible(const void * drvdata,enum hwmon_sensor_types type,u32 attr,int channel)445*4882a593Smuzhiyun static umode_t power_hwmon_attrs_visible(const void *drvdata,
446*4882a593Smuzhiyun enum hwmon_sensor_types type,
447*4882a593Smuzhiyun u32 attr, int channel)
448*4882a593Smuzhiyun {
449*4882a593Smuzhiyun switch (attr) {
450*4882a593Smuzhiyun case hwmon_power_input:
451*4882a593Smuzhiyun case hwmon_power_max_alarm:
452*4882a593Smuzhiyun case hwmon_power_crit_alarm:
453*4882a593Smuzhiyun return 0444;
454*4882a593Smuzhiyun case hwmon_power_max:
455*4882a593Smuzhiyun case hwmon_power_crit:
456*4882a593Smuzhiyun return 0644;
457*4882a593Smuzhiyun }
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun return 0;
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun static const struct hwmon_ops power_hwmon_ops = {
463*4882a593Smuzhiyun .is_visible = power_hwmon_attrs_visible,
464*4882a593Smuzhiyun .read = power_hwmon_read,
465*4882a593Smuzhiyun .write = power_hwmon_write,
466*4882a593Smuzhiyun };
467*4882a593Smuzhiyun
468*4882a593Smuzhiyun static const struct hwmon_channel_info *power_hwmon_info[] = {
469*4882a593Smuzhiyun HWMON_CHANNEL_INFO(power, HWMON_P_INPUT |
470*4882a593Smuzhiyun HWMON_P_MAX | HWMON_P_MAX_ALARM |
471*4882a593Smuzhiyun HWMON_P_CRIT | HWMON_P_CRIT_ALARM),
472*4882a593Smuzhiyun NULL
473*4882a593Smuzhiyun };
474*4882a593Smuzhiyun
475*4882a593Smuzhiyun static const struct hwmon_chip_info power_hwmon_chip_info = {
476*4882a593Smuzhiyun .ops = &power_hwmon_ops,
477*4882a593Smuzhiyun .info = power_hwmon_info,
478*4882a593Smuzhiyun };
479*4882a593Smuzhiyun
power1_xeon_limit_show(struct device * dev,struct device_attribute * attr,char * buf)480*4882a593Smuzhiyun static ssize_t power1_xeon_limit_show(struct device *dev,
481*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
482*4882a593Smuzhiyun {
483*4882a593Smuzhiyun struct dfl_feature *feature = dev_get_drvdata(dev);
484*4882a593Smuzhiyun u16 xeon_limit = 0;
485*4882a593Smuzhiyun u64 v;
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_PWR_XEON_LIMIT);
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun if (FIELD_GET(XEON_PWR_EN, v))
490*4882a593Smuzhiyun xeon_limit = FIELD_GET(XEON_PWR_LIMIT, v);
491*4882a593Smuzhiyun
492*4882a593Smuzhiyun return sprintf(buf, "%u\n", xeon_limit * 100000);
493*4882a593Smuzhiyun }
494*4882a593Smuzhiyun
power1_fpga_limit_show(struct device * dev,struct device_attribute * attr,char * buf)495*4882a593Smuzhiyun static ssize_t power1_fpga_limit_show(struct device *dev,
496*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
497*4882a593Smuzhiyun {
498*4882a593Smuzhiyun struct dfl_feature *feature = dev_get_drvdata(dev);
499*4882a593Smuzhiyun u16 fpga_limit = 0;
500*4882a593Smuzhiyun u64 v;
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_PWR_FPGA_LIMIT);
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun if (FIELD_GET(FPGA_PWR_EN, v))
505*4882a593Smuzhiyun fpga_limit = FIELD_GET(FPGA_PWR_LIMIT, v);
506*4882a593Smuzhiyun
507*4882a593Smuzhiyun return sprintf(buf, "%u\n", fpga_limit * 100000);
508*4882a593Smuzhiyun }
509*4882a593Smuzhiyun
power1_ltr_show(struct device * dev,struct device_attribute * attr,char * buf)510*4882a593Smuzhiyun static ssize_t power1_ltr_show(struct device *dev,
511*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
512*4882a593Smuzhiyun {
513*4882a593Smuzhiyun struct dfl_feature *feature = dev_get_drvdata(dev);
514*4882a593Smuzhiyun u64 v;
515*4882a593Smuzhiyun
516*4882a593Smuzhiyun v = readq(feature->ioaddr + FME_PWR_STATUS);
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun return sprintf(buf, "%u\n",
519*4882a593Smuzhiyun (unsigned int)FIELD_GET(FME_LATENCY_TOLERANCE, v));
520*4882a593Smuzhiyun }
521*4882a593Smuzhiyun
522*4882a593Smuzhiyun static DEVICE_ATTR_RO(power1_xeon_limit);
523*4882a593Smuzhiyun static DEVICE_ATTR_RO(power1_fpga_limit);
524*4882a593Smuzhiyun static DEVICE_ATTR_RO(power1_ltr);
525*4882a593Smuzhiyun
526*4882a593Smuzhiyun static struct attribute *power_extra_attrs[] = {
527*4882a593Smuzhiyun &dev_attr_power1_xeon_limit.attr,
528*4882a593Smuzhiyun &dev_attr_power1_fpga_limit.attr,
529*4882a593Smuzhiyun &dev_attr_power1_ltr.attr,
530*4882a593Smuzhiyun NULL
531*4882a593Smuzhiyun };
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun ATTRIBUTE_GROUPS(power_extra);
534*4882a593Smuzhiyun
fme_power_mgmt_init(struct platform_device * pdev,struct dfl_feature * feature)535*4882a593Smuzhiyun static int fme_power_mgmt_init(struct platform_device *pdev,
536*4882a593Smuzhiyun struct dfl_feature *feature)
537*4882a593Smuzhiyun {
538*4882a593Smuzhiyun struct device *hwmon;
539*4882a593Smuzhiyun
540*4882a593Smuzhiyun hwmon = devm_hwmon_device_register_with_info(&pdev->dev,
541*4882a593Smuzhiyun "dfl_fme_power", feature,
542*4882a593Smuzhiyun &power_hwmon_chip_info,
543*4882a593Smuzhiyun power_extra_groups);
544*4882a593Smuzhiyun if (IS_ERR(hwmon)) {
545*4882a593Smuzhiyun dev_err(&pdev->dev, "Fail to register power hwmon\n");
546*4882a593Smuzhiyun return PTR_ERR(hwmon);
547*4882a593Smuzhiyun }
548*4882a593Smuzhiyun
549*4882a593Smuzhiyun return 0;
550*4882a593Smuzhiyun }
551*4882a593Smuzhiyun
552*4882a593Smuzhiyun static const struct dfl_feature_id fme_power_mgmt_id_table[] = {
553*4882a593Smuzhiyun {.id = FME_FEATURE_ID_POWER_MGMT,},
554*4882a593Smuzhiyun {0,}
555*4882a593Smuzhiyun };
556*4882a593Smuzhiyun
557*4882a593Smuzhiyun static const struct dfl_feature_ops fme_power_mgmt_ops = {
558*4882a593Smuzhiyun .init = fme_power_mgmt_init,
559*4882a593Smuzhiyun };
560*4882a593Smuzhiyun
561*4882a593Smuzhiyun static struct dfl_feature_driver fme_feature_drvs[] = {
562*4882a593Smuzhiyun {
563*4882a593Smuzhiyun .id_table = fme_hdr_id_table,
564*4882a593Smuzhiyun .ops = &fme_hdr_ops,
565*4882a593Smuzhiyun },
566*4882a593Smuzhiyun {
567*4882a593Smuzhiyun .id_table = fme_pr_mgmt_id_table,
568*4882a593Smuzhiyun .ops = &fme_pr_mgmt_ops,
569*4882a593Smuzhiyun },
570*4882a593Smuzhiyun {
571*4882a593Smuzhiyun .id_table = fme_global_err_id_table,
572*4882a593Smuzhiyun .ops = &fme_global_err_ops,
573*4882a593Smuzhiyun },
574*4882a593Smuzhiyun {
575*4882a593Smuzhiyun .id_table = fme_thermal_mgmt_id_table,
576*4882a593Smuzhiyun .ops = &fme_thermal_mgmt_ops,
577*4882a593Smuzhiyun },
578*4882a593Smuzhiyun {
579*4882a593Smuzhiyun .id_table = fme_power_mgmt_id_table,
580*4882a593Smuzhiyun .ops = &fme_power_mgmt_ops,
581*4882a593Smuzhiyun },
582*4882a593Smuzhiyun {
583*4882a593Smuzhiyun .id_table = fme_perf_id_table,
584*4882a593Smuzhiyun .ops = &fme_perf_ops,
585*4882a593Smuzhiyun },
586*4882a593Smuzhiyun {
587*4882a593Smuzhiyun .ops = NULL,
588*4882a593Smuzhiyun },
589*4882a593Smuzhiyun };
590*4882a593Smuzhiyun
fme_ioctl_check_extension(struct dfl_feature_platform_data * pdata,unsigned long arg)591*4882a593Smuzhiyun static long fme_ioctl_check_extension(struct dfl_feature_platform_data *pdata,
592*4882a593Smuzhiyun unsigned long arg)
593*4882a593Smuzhiyun {
594*4882a593Smuzhiyun /* No extension support for now */
595*4882a593Smuzhiyun return 0;
596*4882a593Smuzhiyun }
597*4882a593Smuzhiyun
fme_open(struct inode * inode,struct file * filp)598*4882a593Smuzhiyun static int fme_open(struct inode *inode, struct file *filp)
599*4882a593Smuzhiyun {
600*4882a593Smuzhiyun struct platform_device *fdev = dfl_fpga_inode_to_feature_dev(inode);
601*4882a593Smuzhiyun struct dfl_feature_platform_data *pdata = dev_get_platdata(&fdev->dev);
602*4882a593Smuzhiyun int ret;
603*4882a593Smuzhiyun
604*4882a593Smuzhiyun if (WARN_ON(!pdata))
605*4882a593Smuzhiyun return -ENODEV;
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun mutex_lock(&pdata->lock);
608*4882a593Smuzhiyun ret = dfl_feature_dev_use_begin(pdata, filp->f_flags & O_EXCL);
609*4882a593Smuzhiyun if (!ret) {
610*4882a593Smuzhiyun dev_dbg(&fdev->dev, "Device File Opened %d Times\n",
611*4882a593Smuzhiyun dfl_feature_dev_use_count(pdata));
612*4882a593Smuzhiyun filp->private_data = pdata;
613*4882a593Smuzhiyun }
614*4882a593Smuzhiyun mutex_unlock(&pdata->lock);
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun return ret;
617*4882a593Smuzhiyun }
618*4882a593Smuzhiyun
fme_release(struct inode * inode,struct file * filp)619*4882a593Smuzhiyun static int fme_release(struct inode *inode, struct file *filp)
620*4882a593Smuzhiyun {
621*4882a593Smuzhiyun struct dfl_feature_platform_data *pdata = filp->private_data;
622*4882a593Smuzhiyun struct platform_device *pdev = pdata->dev;
623*4882a593Smuzhiyun struct dfl_feature *feature;
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun dev_dbg(&pdev->dev, "Device File Release\n");
626*4882a593Smuzhiyun
627*4882a593Smuzhiyun mutex_lock(&pdata->lock);
628*4882a593Smuzhiyun dfl_feature_dev_use_end(pdata);
629*4882a593Smuzhiyun
630*4882a593Smuzhiyun if (!dfl_feature_dev_use_count(pdata))
631*4882a593Smuzhiyun dfl_fpga_dev_for_each_feature(pdata, feature)
632*4882a593Smuzhiyun dfl_fpga_set_irq_triggers(feature, 0,
633*4882a593Smuzhiyun feature->nr_irqs, NULL);
634*4882a593Smuzhiyun mutex_unlock(&pdata->lock);
635*4882a593Smuzhiyun
636*4882a593Smuzhiyun return 0;
637*4882a593Smuzhiyun }
638*4882a593Smuzhiyun
fme_ioctl(struct file * filp,unsigned int cmd,unsigned long arg)639*4882a593Smuzhiyun static long fme_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
640*4882a593Smuzhiyun {
641*4882a593Smuzhiyun struct dfl_feature_platform_data *pdata = filp->private_data;
642*4882a593Smuzhiyun struct platform_device *pdev = pdata->dev;
643*4882a593Smuzhiyun struct dfl_feature *f;
644*4882a593Smuzhiyun long ret;
645*4882a593Smuzhiyun
646*4882a593Smuzhiyun dev_dbg(&pdev->dev, "%s cmd 0x%x\n", __func__, cmd);
647*4882a593Smuzhiyun
648*4882a593Smuzhiyun switch (cmd) {
649*4882a593Smuzhiyun case DFL_FPGA_GET_API_VERSION:
650*4882a593Smuzhiyun return DFL_FPGA_API_VERSION;
651*4882a593Smuzhiyun case DFL_FPGA_CHECK_EXTENSION:
652*4882a593Smuzhiyun return fme_ioctl_check_extension(pdata, arg);
653*4882a593Smuzhiyun default:
654*4882a593Smuzhiyun /*
655*4882a593Smuzhiyun * Let sub-feature's ioctl function to handle the cmd.
656*4882a593Smuzhiyun * Sub-feature's ioctl returns -ENODEV when cmd is not
657*4882a593Smuzhiyun * handled in this sub feature, and returns 0 or other
658*4882a593Smuzhiyun * error code if cmd is handled.
659*4882a593Smuzhiyun */
660*4882a593Smuzhiyun dfl_fpga_dev_for_each_feature(pdata, f) {
661*4882a593Smuzhiyun if (f->ops && f->ops->ioctl) {
662*4882a593Smuzhiyun ret = f->ops->ioctl(pdev, f, cmd, arg);
663*4882a593Smuzhiyun if (ret != -ENODEV)
664*4882a593Smuzhiyun return ret;
665*4882a593Smuzhiyun }
666*4882a593Smuzhiyun }
667*4882a593Smuzhiyun }
668*4882a593Smuzhiyun
669*4882a593Smuzhiyun return -EINVAL;
670*4882a593Smuzhiyun }
671*4882a593Smuzhiyun
fme_dev_init(struct platform_device * pdev)672*4882a593Smuzhiyun static int fme_dev_init(struct platform_device *pdev)
673*4882a593Smuzhiyun {
674*4882a593Smuzhiyun struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
675*4882a593Smuzhiyun struct dfl_fme *fme;
676*4882a593Smuzhiyun
677*4882a593Smuzhiyun fme = devm_kzalloc(&pdev->dev, sizeof(*fme), GFP_KERNEL);
678*4882a593Smuzhiyun if (!fme)
679*4882a593Smuzhiyun return -ENOMEM;
680*4882a593Smuzhiyun
681*4882a593Smuzhiyun fme->pdata = pdata;
682*4882a593Smuzhiyun
683*4882a593Smuzhiyun mutex_lock(&pdata->lock);
684*4882a593Smuzhiyun dfl_fpga_pdata_set_private(pdata, fme);
685*4882a593Smuzhiyun mutex_unlock(&pdata->lock);
686*4882a593Smuzhiyun
687*4882a593Smuzhiyun return 0;
688*4882a593Smuzhiyun }
689*4882a593Smuzhiyun
fme_dev_destroy(struct platform_device * pdev)690*4882a593Smuzhiyun static void fme_dev_destroy(struct platform_device *pdev)
691*4882a593Smuzhiyun {
692*4882a593Smuzhiyun struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
693*4882a593Smuzhiyun
694*4882a593Smuzhiyun mutex_lock(&pdata->lock);
695*4882a593Smuzhiyun dfl_fpga_pdata_set_private(pdata, NULL);
696*4882a593Smuzhiyun mutex_unlock(&pdata->lock);
697*4882a593Smuzhiyun }
698*4882a593Smuzhiyun
699*4882a593Smuzhiyun static const struct file_operations fme_fops = {
700*4882a593Smuzhiyun .owner = THIS_MODULE,
701*4882a593Smuzhiyun .open = fme_open,
702*4882a593Smuzhiyun .release = fme_release,
703*4882a593Smuzhiyun .unlocked_ioctl = fme_ioctl,
704*4882a593Smuzhiyun };
705*4882a593Smuzhiyun
fme_probe(struct platform_device * pdev)706*4882a593Smuzhiyun static int fme_probe(struct platform_device *pdev)
707*4882a593Smuzhiyun {
708*4882a593Smuzhiyun int ret;
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun ret = fme_dev_init(pdev);
711*4882a593Smuzhiyun if (ret)
712*4882a593Smuzhiyun goto exit;
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun ret = dfl_fpga_dev_feature_init(pdev, fme_feature_drvs);
715*4882a593Smuzhiyun if (ret)
716*4882a593Smuzhiyun goto dev_destroy;
717*4882a593Smuzhiyun
718*4882a593Smuzhiyun ret = dfl_fpga_dev_ops_register(pdev, &fme_fops, THIS_MODULE);
719*4882a593Smuzhiyun if (ret)
720*4882a593Smuzhiyun goto feature_uinit;
721*4882a593Smuzhiyun
722*4882a593Smuzhiyun return 0;
723*4882a593Smuzhiyun
724*4882a593Smuzhiyun feature_uinit:
725*4882a593Smuzhiyun dfl_fpga_dev_feature_uinit(pdev);
726*4882a593Smuzhiyun dev_destroy:
727*4882a593Smuzhiyun fme_dev_destroy(pdev);
728*4882a593Smuzhiyun exit:
729*4882a593Smuzhiyun return ret;
730*4882a593Smuzhiyun }
731*4882a593Smuzhiyun
fme_remove(struct platform_device * pdev)732*4882a593Smuzhiyun static int fme_remove(struct platform_device *pdev)
733*4882a593Smuzhiyun {
734*4882a593Smuzhiyun dfl_fpga_dev_ops_unregister(pdev);
735*4882a593Smuzhiyun dfl_fpga_dev_feature_uinit(pdev);
736*4882a593Smuzhiyun fme_dev_destroy(pdev);
737*4882a593Smuzhiyun
738*4882a593Smuzhiyun return 0;
739*4882a593Smuzhiyun }
740*4882a593Smuzhiyun
741*4882a593Smuzhiyun static const struct attribute_group *fme_dev_groups[] = {
742*4882a593Smuzhiyun &fme_hdr_group,
743*4882a593Smuzhiyun &fme_global_err_group,
744*4882a593Smuzhiyun NULL
745*4882a593Smuzhiyun };
746*4882a593Smuzhiyun
747*4882a593Smuzhiyun static struct platform_driver fme_driver = {
748*4882a593Smuzhiyun .driver = {
749*4882a593Smuzhiyun .name = DFL_FPGA_FEATURE_DEV_FME,
750*4882a593Smuzhiyun .dev_groups = fme_dev_groups,
751*4882a593Smuzhiyun },
752*4882a593Smuzhiyun .probe = fme_probe,
753*4882a593Smuzhiyun .remove = fme_remove,
754*4882a593Smuzhiyun };
755*4882a593Smuzhiyun
756*4882a593Smuzhiyun module_platform_driver(fme_driver);
757*4882a593Smuzhiyun
758*4882a593Smuzhiyun MODULE_DESCRIPTION("FPGA Management Engine driver");
759*4882a593Smuzhiyun MODULE_AUTHOR("Intel Corporation");
760*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
761*4882a593Smuzhiyun MODULE_ALIAS("platform:dfl-fme");
762