1 /* $NetBSD: nouveau_nvkm_subdev_therm_ic.c,v 1.3 2021/12/18 23:45:41 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 #include <sys/cdefs.h> 27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_therm_ic.c,v 1.3 2021/12/18 23:45:41 riastradh Exp $"); 28 29 #include "priv.h" 30 31 #include <subdev/bios/extdev.h> 32 #include <subdev/i2c.h> 33 34 static bool 35 probe_monitoring_device(struct nvkm_i2c_bus *bus, 36 struct i2c_board_info *info, void *data) 37 { 38 #ifdef __NetBSD__ 39 return false; 40 #else 41 struct nvkm_therm *therm = data; 42 struct nvbios_therm_sensor *sensor = &therm->bios_sensor; 43 struct i2c_client *client; 44 45 request_module("%s%s", I2C_MODULE_PREFIX, info->type); 46 47 client = i2c_new_device(&bus->i2c, info); 48 if (!client) 49 return false; 50 51 if (!client->dev.driver || 52 to_i2c_driver(client->dev.driver)->detect(client, info)) { 53 i2c_unregister_device(client); 54 return false; 55 } 56 57 nvkm_debug(&therm->subdev, 58 "Found an %s at address 0x%x (controlled by lm_sensors, " 59 "temp offset %+i C)\n", 60 info->type, info->addr, sensor->offset_constant); 61 therm->ic = client; 62 return true; 63 #endif 64 } 65 66 static struct nvkm_i2c_bus_probe 67 nv_board_infos[] = { 68 { { I2C_BOARD_INFO("w83l785ts", 0x2d) }, 0 }, 69 { { I2C_BOARD_INFO("w83781d", 0x2d) }, 0 }, 70 { { I2C_BOARD_INFO("adt7473", 0x2e) }, 40 }, 71 { { I2C_BOARD_INFO("adt7473", 0x2d) }, 40 }, 72 { { I2C_BOARD_INFO("adt7473", 0x2c) }, 40 }, 73 { { I2C_BOARD_INFO("f75375", 0x2e) }, 0 }, 74 { { I2C_BOARD_INFO("lm99", 0x4c) }, 0 }, 75 { { I2C_BOARD_INFO("lm90", 0x4c) }, 0 }, 76 { { I2C_BOARD_INFO("lm90", 0x4d) }, 0 }, 77 { { I2C_BOARD_INFO("adm1021", 0x18) }, 0 }, 78 { { I2C_BOARD_INFO("adm1021", 0x19) }, 0 }, 79 { { I2C_BOARD_INFO("adm1021", 0x1a) }, 0 }, 80 { { I2C_BOARD_INFO("adm1021", 0x29) }, 0 }, 81 { { I2C_BOARD_INFO("adm1021", 0x2a) }, 0 }, 82 { { I2C_BOARD_INFO("adm1021", 0x2b) }, 0 }, 83 { { I2C_BOARD_INFO("adm1021", 0x4c) }, 0 }, 84 { { I2C_BOARD_INFO("adm1021", 0x4d) }, 0 }, 85 { { I2C_BOARD_INFO("adm1021", 0x4e) }, 0 }, 86 { { I2C_BOARD_INFO("lm63", 0x18) }, 0 }, 87 { { I2C_BOARD_INFO("lm63", 0x4e) }, 0 }, 88 { } 89 }; 90 91 void 92 nvkm_therm_ic_ctor(struct nvkm_therm *therm) 93 { 94 struct nvkm_device *device = therm->subdev.device; 95 struct nvkm_bios *bios = device->bios; 96 struct nvkm_i2c *i2c = device->i2c; 97 struct nvkm_i2c_bus *bus; 98 struct nvbios_extdev_func extdev_entry; 99 100 bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_PRI); 101 if (!bus) 102 return; 103 104 if (!nvbios_extdev_find(bios, NVBIOS_EXTDEV_LM89, &extdev_entry)) { 105 struct nvkm_i2c_bus_probe board[] = { 106 { { I2C_BOARD_INFO("lm90", extdev_entry.addr >> 1) }, 0}, 107 { } 108 }; 109 110 nvkm_i2c_bus_probe(bus, "monitoring device", board, 111 probe_monitoring_device, therm); 112 if (therm->ic) 113 return; 114 } 115 116 if (!nvbios_extdev_find(bios, NVBIOS_EXTDEV_ADT7473, &extdev_entry)) { 117 struct nvkm_i2c_bus_probe board[] = { 118 { { I2C_BOARD_INFO("adt7473", extdev_entry.addr >> 1) }, 20 }, 119 { } 120 }; 121 122 nvkm_i2c_bus_probe(bus, "monitoring device", board, 123 probe_monitoring_device, therm); 124 if (therm->ic) 125 return; 126 } 127 128 if (nvbios_extdev_skip_probe(bios)) 129 return; 130 131 /* The vbios doesn't provide the address of an exisiting monitoring 132 device. Let's try our static list. 133 */ 134 nvkm_i2c_bus_probe(bus, "monitoring device", nv_board_infos, 135 probe_monitoring_device, therm); 136 } 137