Lines Matching +full:ethernet +full:- +full:pse
1 // SPDX-License-Identifier: GPL-2.0-only
3 // Framework for Ethernet Power Sourcing Equipment
10 #include <linux/pse-pd/pse.h>
16 * struct pse_control - a PSE control
17 * @pcdev: a pointer to the PSE controller device
18 * this PSE control belongs to
19 * @list: list entry for the pcdev's PSE controller list
20 * @id: ID of the PSE line in the PSE controller device
31 * of_pse_zero_xlate - dummy function for controllers with one only control
32 * @pcdev: a pointer to the PSE controller device
33 * @pse_spec: PSE line specifier as found in the device tree
36 * :c:type:`pse_controller_dev` is not set. It is useful for all PSE
37 * controllers with #pse-cells = <0>.
46 * of_pse_simple_xlate - translate pse_spec to the PSE line number
47 * @pcdev: a pointer to the PSE controller device
48 * @pse_spec: PSE line specifier as found in the device tree
51 * :c:type:`pse_controller_dev` is not set. It is useful for all PSE
52 * controllers with 1:1 mapping, where PSE lines can be indexed by number
58 if (pse_spec->args[0] >= pcdev->nr_lines) in of_pse_simple_xlate()
59 return -EINVAL; in of_pse_simple_xlate()
61 return pse_spec->args[0]; in of_pse_simple_xlate()
65 * pse_controller_register - register a PSE controller device
66 * @pcdev: a pointer to the initialized PSE controller device
70 if (!pcdev->of_xlate) { in pse_controller_register()
71 if (pcdev->of_pse_n_cells == 0) in pse_controller_register()
72 pcdev->of_xlate = of_pse_zero_xlate; in pse_controller_register()
73 else if (pcdev->of_pse_n_cells == 1) in pse_controller_register()
74 pcdev->of_xlate = of_pse_simple_xlate; in pse_controller_register()
77 mutex_init(&pcdev->lock); in pse_controller_register()
78 INIT_LIST_HEAD(&pcdev->pse_control_head); in pse_controller_register()
81 list_add(&pcdev->list, &pse_controller_list); in pse_controller_register()
89 * pse_controller_unregister - unregister a PSE controller device
90 * @pcdev: a pointer to the PSE controller device
95 list_del(&pcdev->list); in pse_controller_unregister()
106 * devm_pse_controller_register - resource managed pse_controller_register()
107 * @dev: device that is registering this PSE controller
108 * @pcdev: a pointer to the initialized PSE controller device
110 * Managed pse_controller_register(). For PSE controllers registered by
123 return -ENOMEM; in devm_pse_controller_register()
138 /* PSE control section */
147 module_put(psec->pcdev->owner); in __pse_control_release()
149 list_del(&psec->list); in __pse_control_release()
157 kref_put(&psec->refcnt, __pse_control_release); in __pse_control_put_internal()
161 * pse_control_put - free the PSE control
162 * @psec: PSE control pointer
182 list_for_each_entry(psec, &pcdev->pse_control_head, list) { in pse_control_get_internal()
183 if (psec->id == index) { in pse_control_get_internal()
184 kref_get(&psec->refcnt); in pse_control_get_internal()
191 return ERR_PTR(-ENOMEM); in pse_control_get_internal()
193 if (!try_module_get(pcdev->owner)) { in pse_control_get_internal()
195 return ERR_PTR(-ENODEV); in pse_control_get_internal()
198 psec->pcdev = pcdev; in pse_control_get_internal()
199 list_add(&psec->list, &pcdev->pse_control_head); in pse_control_get_internal()
200 psec->id = index; in pse_control_get_internal()
201 kref_init(&psec->refcnt); in pse_control_get_internal()
216 return ERR_PTR(-EINVAL); in of_pse_control_get()
218 ret = of_parse_phandle_with_args(node, "pses", "#pse-cells", 0, &args); in of_pse_control_get()
225 if (args.np == r->dev->of_node) { in of_pse_control_get()
232 psec = ERR_PTR(-EPROBE_DEFER); in of_pse_control_get()
236 if (WARN_ON(args.args_count != pcdev->of_pse_n_cells)) { in of_pse_control_get()
237 psec = ERR_PTR(-EINVAL); in of_pse_control_get()
241 psec_id = pcdev->of_xlate(pcdev, &args); in of_pse_control_get()
259 * pse_ethtool_get_status - get status of PSE control
260 * @psec: PSE control pointer
262 * @status: struct to store PSE status
271 ops = psec->pcdev->ops; in pse_ethtool_get_status()
273 if (!ops->ethtool_get_status) { in pse_ethtool_get_status()
275 "PSE driver does not support status report"); in pse_ethtool_get_status()
276 return -EOPNOTSUPP; in pse_ethtool_get_status()
279 mutex_lock(&psec->pcdev->lock); in pse_ethtool_get_status()
280 err = ops->ethtool_get_status(psec->pcdev, psec->id, extack, status); in pse_ethtool_get_status()
281 mutex_unlock(&psec->pcdev->lock); in pse_ethtool_get_status()
288 * pse_ethtool_set_config - set PSE control configuration
289 * @psec: PSE control pointer
300 ops = psec->pcdev->ops; in pse_ethtool_set_config()
302 if (!ops->ethtool_set_config) { in pse_ethtool_set_config()
304 "PSE driver does not configuration"); in pse_ethtool_set_config()
305 return -EOPNOTSUPP; in pse_ethtool_set_config()
308 mutex_lock(&psec->pcdev->lock); in pse_ethtool_set_config()
309 err = ops->ethtool_set_config(psec->pcdev, psec->id, extack, config); in pse_ethtool_set_config()
310 mutex_unlock(&psec->pcdev->lock); in pse_ethtool_set_config()