Linux Audio

Check our new training course

Loading...
v5.4
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Windfarm PowerMac thermal control.
  4 *
  5 * (c) Copyright 2005 Benjamin Herrenschmidt, IBM Corp.
  6 *                    <benh@kernel.crashing.org>
 
 
  7 */
  8
  9#ifndef __WINDFARM_H__
 10#define __WINDFARM_H__
 11
 12#include <linux/kref.h>
 13#include <linux/list.h>
 14#include <linux/module.h>
 15#include <linux/notifier.h>
 16#include <linux/device.h>
 17
 18/* Display a 16.16 fixed point value */
 19#define FIX32TOPRINT(f)	(((s32)(f)) >> 16),(((((s32)(f)) & 0xffff) * 1000) >> 16)
 20
 21/*
 22 * Control objects
 23 */
 24
 25struct wf_control;
 26
 27struct wf_control_ops {
 28	int			(*set_value)(struct wf_control *ct, s32 val);
 29	int			(*get_value)(struct wf_control *ct, s32 *val);
 30	s32			(*get_min)(struct wf_control *ct);
 31	s32			(*get_max)(struct wf_control *ct);
 32	void			(*release)(struct wf_control *ct);
 33	struct module		*owner;
 34};
 35
 36struct wf_control {
 37	struct list_head		link;
 38	const struct wf_control_ops	*ops;
 39	const char			*name;
 40	int				type;
 41	struct kref			ref;
 42	struct device_attribute		attr;
 43	void				*priv;
 44};
 45
 46#define WF_CONTROL_TYPE_GENERIC		0
 47#define WF_CONTROL_RPM_FAN		1
 48#define WF_CONTROL_PWM_FAN		2
 49
 50
 51/* Note about lifetime rules: wf_register_control() will initialize
 52 * the kref and wf_unregister_control will decrement it, thus the
 53 * object creating/disposing a given control shouldn't assume it
 54 * still exists after wf_unregister_control has been called.
 
 55 */
 56extern int wf_register_control(struct wf_control *ct);
 57extern void wf_unregister_control(struct wf_control *ct);
 
 58extern int wf_get_control(struct wf_control *ct);
 59extern void wf_put_control(struct wf_control *ct);
 60
 61static inline int wf_control_set_max(struct wf_control *ct)
 62{
 63	s32 vmax = ct->ops->get_max(ct);
 64	return ct->ops->set_value(ct, vmax);
 65}
 66
 67static inline int wf_control_set_min(struct wf_control *ct)
 68{
 69	s32 vmin = ct->ops->get_min(ct);
 70	return ct->ops->set_value(ct, vmin);
 71}
 72
 73static inline int wf_control_set(struct wf_control *ct, s32 val)
 74{
 75	return ct->ops->set_value(ct, val);
 76}
 77
 78static inline int wf_control_get(struct wf_control *ct, s32 *val)
 79{
 80	return ct->ops->get_value(ct, val);
 81}
 82
 83static inline s32 wf_control_get_min(struct wf_control *ct)
 84{
 85	return ct->ops->get_min(ct);
 86}
 87
 88static inline s32 wf_control_get_max(struct wf_control *ct)
 89{
 90	return ct->ops->get_max(ct);
 91}
 92
 93/*
 94 * Sensor objects
 95 */
 96
 97struct wf_sensor;
 98
 99struct wf_sensor_ops {
100	int			(*get_value)(struct wf_sensor *sr, s32 *val);
101	void			(*release)(struct wf_sensor *sr);
102	struct module		*owner;
103};
104
105struct wf_sensor {
106	struct list_head		link;
107	const struct wf_sensor_ops	*ops;
108	const char			*name;
109	struct kref			ref;
110	struct device_attribute		attr;
111	void				*priv;
112};
113
114/* Same lifetime rules as controls */
115extern int wf_register_sensor(struct wf_sensor *sr);
116extern void wf_unregister_sensor(struct wf_sensor *sr);
 
117extern int wf_get_sensor(struct wf_sensor *sr);
118extern void wf_put_sensor(struct wf_sensor *sr);
119
120static inline int wf_sensor_get(struct wf_sensor *sr, s32 *val)
121{
122	return sr->ops->get_value(sr, val);
123}
124
125/* For use by clients. Note that we are a bit racy here since
126 * notifier_block doesn't have a module owner field. I may fix
127 * it one day ...
128 *
129 * LOCKING NOTE !
130 *
131 * All "events" except WF_EVENT_TICK are called with an internal mutex
132 * held which will deadlock if you call basically any core routine.
133 * So don't ! Just take note of the event and do your actual operations
134 * from the ticker.
135 *
136 */
137extern int wf_register_client(struct notifier_block *nb);
138extern int wf_unregister_client(struct notifier_block *nb);
139
140/* Overtemp conditions. Those are refcounted */
141extern void wf_set_overtemp(void);
142extern void wf_clear_overtemp(void);
 
143
144#define WF_EVENT_NEW_CONTROL	0 /* param is wf_control * */
145#define WF_EVENT_NEW_SENSOR	1 /* param is wf_sensor * */
146#define WF_EVENT_OVERTEMP	2 /* no param */
147#define WF_EVENT_NORMALTEMP	3 /* overtemp condition cleared */
148#define WF_EVENT_TICK		4 /* 1 second tick */
149
150/* Note: If that driver gets more broad use, we could replace the
151 * simplistic overtemp bits with "environmental conditions". That
152 * could then be used to also notify of things like fan failure,
153 * case open, battery conditions, ...
154 */
155
156#endif /* __WINDFARM_H__ */
v3.5.6
 
  1/*
  2 * Windfarm PowerMac thermal control.
  3 *
  4 * (c) Copyright 2005 Benjamin Herrenschmidt, IBM Corp.
  5 *                    <benh@kernel.crashing.org>
  6 *
  7 * Released under the term of the GNU GPL v2.
  8 */
  9
 10#ifndef __WINDFARM_H__
 11#define __WINDFARM_H__
 12
 13#include <linux/kref.h>
 14#include <linux/list.h>
 15#include <linux/module.h>
 16#include <linux/notifier.h>
 17#include <linux/device.h>
 18
 19/* Display a 16.16 fixed point value */
 20#define FIX32TOPRINT(f)	(((s32)(f)) >> 16),(((((s32)(f)) & 0xffff) * 1000) >> 16)
 21
 22/*
 23 * Control objects
 24 */
 25
 26struct wf_control;
 27
 28struct wf_control_ops {
 29	int			(*set_value)(struct wf_control *ct, s32 val);
 30	int			(*get_value)(struct wf_control *ct, s32 *val);
 31	s32			(*get_min)(struct wf_control *ct);
 32	s32			(*get_max)(struct wf_control *ct);
 33	void			(*release)(struct wf_control *ct);
 34	struct module		*owner;
 35};
 36
 37struct wf_control {
 38	struct list_head		link;
 39	const struct wf_control_ops	*ops;
 40	const char			*name;
 41	int				type;
 42	struct kref			ref;
 43	struct device_attribute		attr;
 44	void				*priv;
 45};
 46
 47#define WF_CONTROL_TYPE_GENERIC		0
 48#define WF_CONTROL_RPM_FAN		1
 49#define WF_CONTROL_PWM_FAN		2
 50
 51
 52/* Note about lifetime rules: wf_register_control() will initialize
 53 * the kref and wf_unregister_control will decrement it, thus the
 54 * object creating/disposing a given control shouldn't assume it
 55 * still exists after wf_unregister_control has been called.
 56 * wf_find_control will inc the refcount for you
 57 */
 58extern int wf_register_control(struct wf_control *ct);
 59extern void wf_unregister_control(struct wf_control *ct);
 60extern struct wf_control * wf_find_control(const char *name);
 61extern int wf_get_control(struct wf_control *ct);
 62extern void wf_put_control(struct wf_control *ct);
 63
 64static inline int wf_control_set_max(struct wf_control *ct)
 65{
 66	s32 vmax = ct->ops->get_max(ct);
 67	return ct->ops->set_value(ct, vmax);
 68}
 69
 70static inline int wf_control_set_min(struct wf_control *ct)
 71{
 72	s32 vmin = ct->ops->get_min(ct);
 73	return ct->ops->set_value(ct, vmin);
 74}
 75
 76static inline int wf_control_set(struct wf_control *ct, s32 val)
 77{
 78	return ct->ops->set_value(ct, val);
 79}
 80
 81static inline int wf_control_get(struct wf_control *ct, s32 *val)
 82{
 83	return ct->ops->get_value(ct, val);
 84}
 85
 86static inline s32 wf_control_get_min(struct wf_control *ct)
 87{
 88	return ct->ops->get_min(ct);
 89}
 90
 91static inline s32 wf_control_get_max(struct wf_control *ct)
 92{
 93	return ct->ops->get_max(ct);
 94}
 95
 96/*
 97 * Sensor objects
 98 */
 99
100struct wf_sensor;
101
102struct wf_sensor_ops {
103	int			(*get_value)(struct wf_sensor *sr, s32 *val);
104	void			(*release)(struct wf_sensor *sr);
105	struct module		*owner;
106};
107
108struct wf_sensor {
109	struct list_head		link;
110	const struct wf_sensor_ops	*ops;
111	const char			*name;
112	struct kref			ref;
113	struct device_attribute		attr;
114	void				*priv;
115};
116
117/* Same lifetime rules as controls */
118extern int wf_register_sensor(struct wf_sensor *sr);
119extern void wf_unregister_sensor(struct wf_sensor *sr);
120extern struct wf_sensor * wf_find_sensor(const char *name);
121extern int wf_get_sensor(struct wf_sensor *sr);
122extern void wf_put_sensor(struct wf_sensor *sr);
123
124static inline int wf_sensor_get(struct wf_sensor *sr, s32 *val)
125{
126	return sr->ops->get_value(sr, val);
127}
128
129/* For use by clients. Note that we are a bit racy here since
130 * notifier_block doesn't have a module owner field. I may fix
131 * it one day ...
132 *
133 * LOCKING NOTE !
134 *
135 * All "events" except WF_EVENT_TICK are called with an internal mutex
136 * held which will deadlock if you call basically any core routine.
137 * So don't ! Just take note of the event and do your actual operations
138 * from the ticker.
139 *
140 */
141extern int wf_register_client(struct notifier_block *nb);
142extern int wf_unregister_client(struct notifier_block *nb);
143
144/* Overtemp conditions. Those are refcounted */
145extern void wf_set_overtemp(void);
146extern void wf_clear_overtemp(void);
147extern int wf_is_overtemp(void);
148
149#define WF_EVENT_NEW_CONTROL	0 /* param is wf_control * */
150#define WF_EVENT_NEW_SENSOR	1 /* param is wf_sensor * */
151#define WF_EVENT_OVERTEMP	2 /* no param */
152#define WF_EVENT_NORMALTEMP	3 /* overtemp condition cleared */
153#define WF_EVENT_TICK		4 /* 1 second tick */
154
155/* Note: If that driver gets more broad use, we could replace the
156 * simplistic overtemp bits with "environmental conditions". That
157 * could then be used to also notify of things like fan failure,
158 * case open, battery conditions, ...
159 */
160
161#endif /* __WINDFARM_H__ */