1/* $NetBSD: nouveau_subdev_therm_ic.c,v 1.2 2015/02/25 22:12:00 riastradh Exp $ */
2
3/*
4 * Copyright 2012 Nouveau community
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Martin Peres
25 */
26
27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_therm_ic.c,v 1.2 2015/02/25 22:12:00 riastradh Exp $");
29
30#include "priv.h"
31
32#include <subdev/i2c.h>
33#include <subdev/bios/extdev.h>
34
35static bool
36probe_monitoring_device(struct nouveau_i2c_port *i2c,
37 struct i2c_board_info *info, void *data)
38{
39#ifdef __NetBSD__
40 return false;
41#else
42 struct nouveau_therm_priv *priv = data;
43 struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
44 struct i2c_client *client;
45
46 request_module("%s%s", I2C_MODULE_PREFIX, info->type);
47
48 client = i2c_new_device(&i2c->adapter, info);
49 if (!client)
50 return false;
51
52 if (!client->dev.driver ||
53 to_i2c_driver(client->dev.driver)->detect(client, info)) {
54 i2c_unregister_device(client);
55 return false;
56 }
57
58 nv_info(priv,
59 "Found an %s at address 0x%x (controlled by lm_sensors, "
60 "temp offset %+i C)\n",
61 info->type, info->addr, sensor->offset_constant);
62 priv->ic = client;
63
64 return true;
65#endif
66}
67
68static struct nouveau_i2c_board_info
69nv_board_infos[] = {
70 { { I2C_BOARD_INFO("w83l785ts", 0x2d) }, 0 },
71 { { I2C_BOARD_INFO("w83781d", 0x2d) }, 0 },
72 { { I2C_BOARD_INFO("adt7473", 0x2e) }, 20 },
73 { { I2C_BOARD_INFO("adt7473", 0x2d) }, 20 },
74 { { I2C_BOARD_INFO("adt7473", 0x2c) }, 20 },
75 { { I2C_BOARD_INFO("f75375", 0x2e) }, 0 },
76 { { I2C_BOARD_INFO("lm99", 0x4c) }, 0 },
77 { { I2C_BOARD_INFO("lm90", 0x4c) }, 0 },
78 { { I2C_BOARD_INFO("lm90", 0x4d) }, 0 },
79 { { I2C_BOARD_INFO("adm1021", 0x18) }, 0 },
80 { { I2C_BOARD_INFO("adm1021", 0x19) }, 0 },
81 { { I2C_BOARD_INFO("adm1021", 0x1a) }, 0 },
82 { { I2C_BOARD_INFO("adm1021", 0x29) }, 0 },
83 { { I2C_BOARD_INFO("adm1021", 0x2a) }, 0 },
84 { { I2C_BOARD_INFO("adm1021", 0x2b) }, 0 },
85 { { I2C_BOARD_INFO("adm1021", 0x4c) }, 0 },
86 { { I2C_BOARD_INFO("adm1021", 0x4d) }, 0 },
87 { { I2C_BOARD_INFO("adm1021", 0x4e) }, 0 },
88 { { I2C_BOARD_INFO("lm63", 0x18) }, 0 },
89 { { I2C_BOARD_INFO("lm63", 0x4e) }, 0 },
90 { }
91};
92
93void
94nouveau_therm_ic_ctor(struct nouveau_therm *therm)
95{
96 struct nouveau_therm_priv *priv = (void *)therm;
97 struct nouveau_bios *bios = nouveau_bios(therm);
98 struct nouveau_i2c *i2c = nouveau_i2c(therm);
99 struct nvbios_extdev_func extdev_entry;
100
101 if (!nvbios_extdev_find(bios, NVBIOS_EXTDEV_LM89, &extdev_entry)) {
102 struct nouveau_i2c_board_info board[] = {
103 { { I2C_BOARD_INFO("lm90", extdev_entry.addr >> 1) }, 0},
104 { }
105 };
106
107 i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device",
108 board, probe_monitoring_device, therm);
109 if (priv->ic)
110 return;
111 }
112
113 if (!nvbios_extdev_find(bios, NVBIOS_EXTDEV_ADT7473, &extdev_entry)) {
114 struct nouveau_i2c_board_info board[] = {
115 { { I2C_BOARD_INFO("adt7473", extdev_entry.addr >> 1) }, 20 },
116 { }
117 };
118
119 i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device",
120 board, probe_monitoring_device, therm);
121 if (priv->ic)
122 return;
123 }
124
125 /* The vbios doesn't provide the address of an exisiting monitoring
126 device. Let's try our static list.
127 */
128 i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device",
129 nv_board_infos, probe_monitoring_device, therm);
130}
131