2 * Copyright 2012 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
29 pwm_info(struct nouveau_therm
*therm
, int *line
, int *ctrl
, int *indx
)
46 nv_error(therm
, "unknown pwm ctrl for gpio %d\n", *line
);
54 nv50_fan_pwm_get(struct nouveau_therm
*therm
, int line
, u32
*divs
, u32
*duty
)
56 int ctrl
, id
, ret
= pwm_info(therm
, &line
, &ctrl
, &id
);
60 if (nv_rd32(therm
, ctrl
) & (1 << line
)) {
61 *divs
= nv_rd32(therm
, 0x00e114 + (id
* 8));
62 *duty
= nv_rd32(therm
, 0x00e118 + (id
* 8));
70 nv50_fan_pwm_set(struct nouveau_therm
*therm
, int line
, u32 divs
, u32 duty
)
72 int ctrl
, id
, ret
= pwm_info(therm
, &line
, &ctrl
, &id
);
76 nv_mask(therm
, ctrl
, 0x00010001 << line
, 0x00000001 << line
);
77 nv_wr32(therm
, 0x00e114 + (id
* 8), divs
);
78 nv_wr32(therm
, 0x00e118 + (id
* 8), duty
| 0x80000000);
83 nv50_temp_get(struct nouveau_therm
*therm
)
85 return nv_rd32(therm
, 0x20400);
89 nv50_therm_ctor(struct nouveau_object
*parent
,
90 struct nouveau_object
*engine
,
91 struct nouveau_oclass
*oclass
, void *data
, u32 size
,
92 struct nouveau_object
**pobject
)
94 struct nouveau_therm_priv
*priv
;
95 struct nouveau_therm
*therm
;
98 ret
= nouveau_therm_create(parent
, engine
, oclass
, &priv
);
99 *pobject
= nv_object(priv
);
100 therm
= (void *) priv
;
104 nouveau_therm_ic_ctor(therm
);
105 nouveau_therm_sensor_ctor(therm
);
106 nouveau_therm_fan_ctor(therm
);
108 priv
->fan
.pwm_get
= nv50_fan_pwm_get
;
109 priv
->fan
.pwm_set
= nv50_fan_pwm_set
;
111 therm
->temp_get
= nv50_temp_get
;
112 therm
->fan_get
= nouveau_therm_fan_get
;
113 therm
->fan_set
= nouveau_therm_fan_set
;
114 therm
->fan_sense
= nouveau_therm_fan_sense
;
115 therm
->attr_get
= nouveau_therm_attr_get
;
116 therm
->attr_set
= nouveau_therm_attr_set
;
121 struct nouveau_oclass
122 nv50_therm_oclass
= {
123 .handle
= NV_SUBDEV(THERM
, 0x50),
124 .ofuncs
= &(struct nouveau_ofuncs
) {
125 .ctor
= nv50_therm_ctor
,
126 .dtor
= _nouveau_therm_dtor
,
127 .init
= nouveau_therm_init
,
128 .fini
= nouveau_therm_fini
,