All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/6] Suppor for various power sensors on GF100+
@ 2016-02-20 17:11 Karol Herbst
       [not found] ` <1455988299-2300-1-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
  0 siblings, 1 reply; 13+ messages in thread
From: Karol Herbst @ 2016-02-20 17:11 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

This is a complete rework from the first version I sent out.

Now the implementation is more centered around the power_rails we find in the
SENSE table instead of extdev centered. This makes the implementation a lot
easier and straightforward.

I've added support for the INA219, INA209 and INA3221 sensors found on multiple
Fermi and Kepler cards.

The power consumption is also exported via hwmon, so "sensors" will be able to
print it in userspace.

This work is based on Martins initial power sensor work and most of the ground
work was just copied from him.

Happy testing

changes in v3: fixes ina2x9, rebase on current master
changes in v4: some minor ina2x9 fixes and get it to work on maxwell gen2

Tested-by: Stefan Hühner <stefan@huehner.org> on gm206

Karol Herbst (4):
  iccsense: implement for ina209, ina219 and ina3221
  hwmon: add power consumption
  hwmon: don't require therm to be valid to get any data
  bios/extdev: also parse v4.1 table

Martin Peres (2):
  subdev/iccsense: add new subdev for power sensors
  nvbios/iccsense: add parsing of the SENSE table

 drm/nouveau/include/nvif/device.h               |   1 +
 drm/nouveau/include/nvkm/core/device.h          |  83 +++++-----
 drm/nouveau/include/nvkm/subdev/bios/extdev.h   |   3 +
 drm/nouveau/include/nvkm/subdev/bios/iccsense.h |  16 ++
 drm/nouveau/include/nvkm/subdev/i2c.h           |  31 ++++
 drm/nouveau/include/nvkm/subdev/iccsense.h      |  15 ++
 drm/nouveau/nouveau_hwmon.c                     |  78 +++++++---
 drm/nouveau/nvkm/core/subdev.c                  |  83 +++++-----
 drm/nouveau/nvkm/engine/device/base.c           | 144 ++++++++++--------
 drm/nouveau/nvkm/engine/device/priv.h           |   1 +
 drm/nouveau/nvkm/subdev/Kbuild                  |   1 +
 drm/nouveau/nvkm/subdev/bios/Kbuild             |   1 +
 drm/nouveau/nvkm/subdev/bios/extdev.c           |   2 +-
 drm/nouveau/nvkm/subdev/bios/iccsense.c         |  97 ++++++++++++
 drm/nouveau/nvkm/subdev/iccsense/Kbuild         |   2 +
 drm/nouveau/nvkm/subdev/iccsense/base.c         | 191 ++++++++++++++++++++++++
 drm/nouveau/nvkm/subdev/iccsense/gf100.c        |  31 ++++
 drm/nouveau/nvkm/subdev/iccsense/priv.h         |  16 ++
 18 files changed, 633 insertions(+), 163 deletions(-)
 create mode 100644 drm/nouveau/include/nvkm/subdev/bios/iccsense.h
 create mode 100644 drm/nouveau/include/nvkm/subdev/iccsense.h
 create mode 100644 drm/nouveau/nvkm/subdev/bios/iccsense.c
 create mode 100644 drm/nouveau/nvkm/subdev/iccsense/Kbuild
 create mode 100644 drm/nouveau/nvkm/subdev/iccsense/base.c
 create mode 100644 drm/nouveau/nvkm/subdev/iccsense/gf100.c
 create mode 100644 drm/nouveau/nvkm/subdev/iccsense/priv.h

-- 
2.7.1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v4 1/6] subdev/iccsense: add new subdev for power sensors
       [not found] ` <1455988299-2300-1-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
@ 2016-02-20 17:11   ` Karol Herbst
       [not found]     ` <1455988299-2300-2-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
  2016-02-20 17:11   ` [PATCH v4 2/6] nvbios/iccsense: add parsing of the SENSE table Karol Herbst
                     ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Karol Herbst @ 2016-02-20 17:11 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

From: Martin Peres <martin.peres@free.fr>

Signed-off-by: Karol Herbst <nouveau@karolherbst.de>
---
 drm/nouveau/include/nvkm/core/device.h     |  83 +++++++++----------
 drm/nouveau/include/nvkm/subdev/iccsense.h |  10 +++
 drm/nouveau/nvkm/core/subdev.c             |  83 +++++++++----------
 drm/nouveau/nvkm/engine/device/base.c      | 124 +++++++++++++++--------------
 drm/nouveau/nvkm/engine/device/priv.h      |   1 +
 drm/nouveau/nvkm/subdev/Kbuild             |   1 +
 drm/nouveau/nvkm/subdev/iccsense/Kbuild    |   1 +
 drm/nouveau/nvkm/subdev/iccsense/base.c    |  43 ++++++++++
 drm/nouveau/nvkm/subdev/iccsense/priv.h    |   8 ++
 9 files changed, 212 insertions(+), 142 deletions(-)
 create mode 100644 drm/nouveau/include/nvkm/subdev/iccsense.h
 create mode 100644 drm/nouveau/nvkm/subdev/iccsense/Kbuild
 create mode 100644 drm/nouveau/nvkm/subdev/iccsense/base.c
 create mode 100644 drm/nouveau/nvkm/subdev/iccsense/priv.h

diff --git a/drm/nouveau/include/nvkm/core/device.h b/drm/nouveau/include/nvkm/core/device.h
index 913192c..0940442 100644
--- a/drm/nouveau/include/nvkm/core/device.h
+++ b/drm/nouveau/include/nvkm/core/device.h
@@ -22,6 +22,7 @@ enum nvkm_devidx {
 	NVKM_SUBDEV_BAR,
 	NVKM_SUBDEV_PMU,
 	NVKM_SUBDEV_VOLT,
+	NVKM_SUBDEV_ICCSENSE,
 	NVKM_SUBDEV_THERM,
 	NVKM_SUBDEV_CLK,
 
@@ -109,6 +110,7 @@ struct nvkm_device {
 	struct nvkm_gpio *gpio;
 	struct nvkm_i2c *i2c;
 	struct nvkm_subdev *ibus;
+	struct nvkm_iccsense *iccsense;
 	struct nvkm_instmem *imem;
 	struct nvkm_ltc *ltc;
 	struct nvkm_mc *mc;
@@ -164,46 +166,47 @@ struct nvkm_device_quirk {
 struct nvkm_device_chip {
 	const char *name;
 
-	int (*bar    )(struct nvkm_device *, int idx, struct nvkm_bar **);
-	int (*bios   )(struct nvkm_device *, int idx, struct nvkm_bios **);
-	int (*bus    )(struct nvkm_device *, int idx, struct nvkm_bus **);
-	int (*clk    )(struct nvkm_device *, int idx, struct nvkm_clk **);
-	int (*devinit)(struct nvkm_device *, int idx, struct nvkm_devinit **);
-	int (*fb     )(struct nvkm_device *, int idx, struct nvkm_fb **);
-	int (*fuse   )(struct nvkm_device *, int idx, struct nvkm_fuse **);
-	int (*gpio   )(struct nvkm_device *, int idx, struct nvkm_gpio **);
-	int (*i2c    )(struct nvkm_device *, int idx, struct nvkm_i2c **);
-	int (*ibus   )(struct nvkm_device *, int idx, struct nvkm_subdev **);
-	int (*imem   )(struct nvkm_device *, int idx, struct nvkm_instmem **);
-	int (*ltc    )(struct nvkm_device *, int idx, struct nvkm_ltc **);
-	int (*mc     )(struct nvkm_device *, int idx, struct nvkm_mc **);
-	int (*mmu    )(struct nvkm_device *, int idx, struct nvkm_mmu **);
-	int (*mxm    )(struct nvkm_device *, int idx, struct nvkm_subdev **);
-	int (*pci    )(struct nvkm_device *, int idx, struct nvkm_pci **);
-	int (*pmu    )(struct nvkm_device *, int idx, struct nvkm_pmu **);
-	int (*therm  )(struct nvkm_device *, int idx, struct nvkm_therm **);
-	int (*timer  )(struct nvkm_device *, int idx, struct nvkm_timer **);
-	int (*volt   )(struct nvkm_device *, int idx, struct nvkm_volt **);
-
-	int (*bsp    )(struct nvkm_device *, int idx, struct nvkm_engine **);
-	int (*ce[3]  )(struct nvkm_device *, int idx, struct nvkm_engine **);
-	int (*cipher )(struct nvkm_device *, int idx, struct nvkm_engine **);
-	int (*disp   )(struct nvkm_device *, int idx, struct nvkm_disp **);
-	int (*dma    )(struct nvkm_device *, int idx, struct nvkm_dma **);
-	int (*fifo   )(struct nvkm_device *, int idx, struct nvkm_fifo **);
-	int (*gr     )(struct nvkm_device *, int idx, struct nvkm_gr **);
-	int (*ifb    )(struct nvkm_device *, int idx, struct nvkm_engine **);
-	int (*me     )(struct nvkm_device *, int idx, struct nvkm_engine **);
-	int (*mpeg   )(struct nvkm_device *, int idx, struct nvkm_engine **);
-	int (*msenc  )(struct nvkm_device *, int idx, struct nvkm_engine **);
-	int (*mspdec )(struct nvkm_device *, int idx, struct nvkm_engine **);
-	int (*msppp  )(struct nvkm_device *, int idx, struct nvkm_engine **);
-	int (*msvld  )(struct nvkm_device *, int idx, struct nvkm_engine **);
-	int (*pm     )(struct nvkm_device *, int idx, struct nvkm_pm **);
-	int (*sec    )(struct nvkm_device *, int idx, struct nvkm_engine **);
-	int (*sw     )(struct nvkm_device *, int idx, struct nvkm_sw **);
-	int (*vic    )(struct nvkm_device *, int idx, struct nvkm_engine **);
-	int (*vp     )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*bar     )(struct nvkm_device *, int idx, struct nvkm_bar **);
+	int (*bios    )(struct nvkm_device *, int idx, struct nvkm_bios **);
+	int (*bus     )(struct nvkm_device *, int idx, struct nvkm_bus **);
+	int (*clk     )(struct nvkm_device *, int idx, struct nvkm_clk **);
+	int (*devinit )(struct nvkm_device *, int idx, struct nvkm_devinit **);
+	int (*fb      )(struct nvkm_device *, int idx, struct nvkm_fb **);
+	int (*fuse    )(struct nvkm_device *, int idx, struct nvkm_fuse **);
+	int (*gpio    )(struct nvkm_device *, int idx, struct nvkm_gpio **);
+	int (*i2c     )(struct nvkm_device *, int idx, struct nvkm_i2c **);
+	int (*ibus    )(struct nvkm_device *, int idx, struct nvkm_subdev **);
+	int (*iccsense)(struct nvkm_device *, int idx, struct nvkm_iccsense **);
+	int (*imem    )(struct nvkm_device *, int idx, struct nvkm_instmem **);
+	int (*ltc     )(struct nvkm_device *, int idx, struct nvkm_ltc **);
+	int (*mc      )(struct nvkm_device *, int idx, struct nvkm_mc **);
+	int (*mmu     )(struct nvkm_device *, int idx, struct nvkm_mmu **);
+	int (*mxm     )(struct nvkm_device *, int idx, struct nvkm_subdev **);
+	int (*pci     )(struct nvkm_device *, int idx, struct nvkm_pci **);
+	int (*pmu     )(struct nvkm_device *, int idx, struct nvkm_pmu **);
+	int (*therm   )(struct nvkm_device *, int idx, struct nvkm_therm **);
+	int (*timer   )(struct nvkm_device *, int idx, struct nvkm_timer **);
+	int (*volt    )(struct nvkm_device *, int idx, struct nvkm_volt **);
+
+	int (*bsp     )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*ce[3]   )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*cipher  )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*disp    )(struct nvkm_device *, int idx, struct nvkm_disp **);
+	int (*dma     )(struct nvkm_device *, int idx, struct nvkm_dma **);
+	int (*fifo    )(struct nvkm_device *, int idx, struct nvkm_fifo **);
+	int (*gr      )(struct nvkm_device *, int idx, struct nvkm_gr **);
+	int (*ifb     )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*me      )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*mpeg    )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*msenc   )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*mspdec  )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*msppp   )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*msvld   )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*pm      )(struct nvkm_device *, int idx, struct nvkm_pm **);
+	int (*sec     )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*sw      )(struct nvkm_device *, int idx, struct nvkm_sw **);
+	int (*vic     )(struct nvkm_device *, int idx, struct nvkm_engine **);
+	int (*vp      )(struct nvkm_device *, int idx, struct nvkm_engine **);
 };
 
 struct nvkm_device *nvkm_device_find(u64 name);
diff --git a/drm/nouveau/include/nvkm/subdev/iccsense.h b/drm/nouveau/include/nvkm/subdev/iccsense.h
new file mode 100644
index 0000000..7fee41d
--- /dev/null
+++ b/drm/nouveau/include/nvkm/subdev/iccsense.h
@@ -0,0 +1,10 @@
+#ifndef __NVKM_ICCSENSE_H__
+#define __NVKM_ICCSENSE_H__
+
+#include <core/subdev.h>
+
+struct nvkm_iccsense {
+	struct nvkm_subdev subdev;
+};
+
+#endif
diff --git a/drm/nouveau/nvkm/core/subdev.c b/drm/nouveau/nvkm/core/subdev.c
index 7de9847..370041f 100644
--- a/drm/nouveau/nvkm/core/subdev.c
+++ b/drm/nouveau/nvkm/core/subdev.c
@@ -29,47 +29,48 @@ static struct lock_class_key nvkm_subdev_lock_class[NVKM_SUBDEV_NR];
 
 const char *
 nvkm_subdev_name[NVKM_SUBDEV_NR] = {
-	[NVKM_SUBDEV_BAR    ] = "bar",
-	[NVKM_SUBDEV_VBIOS  ] = "bios",
-	[NVKM_SUBDEV_BUS    ] = "bus",
-	[NVKM_SUBDEV_CLK    ] = "clk",
-	[NVKM_SUBDEV_DEVINIT] = "devinit",
-	[NVKM_SUBDEV_FB     ] = "fb",
-	[NVKM_SUBDEV_FUSE   ] = "fuse",
-	[NVKM_SUBDEV_GPIO   ] = "gpio",
-	[NVKM_SUBDEV_I2C    ] = "i2c",
-	[NVKM_SUBDEV_IBUS   ] = "priv",
-	[NVKM_SUBDEV_INSTMEM] = "imem",
-	[NVKM_SUBDEV_LTC    ] = "ltc",
-	[NVKM_SUBDEV_MC     ] = "mc",
-	[NVKM_SUBDEV_MMU    ] = "mmu",
-	[NVKM_SUBDEV_MXM    ] = "mxm",
-	[NVKM_SUBDEV_PCI    ] = "pci",
-	[NVKM_SUBDEV_PMU    ] = "pmu",
-	[NVKM_SUBDEV_THERM  ] = "therm",
-	[NVKM_SUBDEV_TIMER  ] = "tmr",
-	[NVKM_SUBDEV_VOLT   ] = "volt",
-	[NVKM_ENGINE_BSP    ] = "bsp",
-	[NVKM_ENGINE_CE0    ] = "ce0",
-	[NVKM_ENGINE_CE1    ] = "ce1",
-	[NVKM_ENGINE_CE2    ] = "ce2",
-	[NVKM_ENGINE_CIPHER ] = "cipher",
-	[NVKM_ENGINE_DISP   ] = "disp",
-	[NVKM_ENGINE_DMAOBJ ] = "dma",
-	[NVKM_ENGINE_FIFO   ] = "fifo",
-	[NVKM_ENGINE_GR     ] = "gr",
-	[NVKM_ENGINE_IFB    ] = "ifb",
-	[NVKM_ENGINE_ME     ] = "me",
-	[NVKM_ENGINE_MPEG   ] = "mpeg",
-	[NVKM_ENGINE_MSENC  ] = "msenc",
-	[NVKM_ENGINE_MSPDEC ] = "mspdec",
-	[NVKM_ENGINE_MSPPP  ] = "msppp",
-	[NVKM_ENGINE_MSVLD  ] = "msvld",
-	[NVKM_ENGINE_PM     ] = "pm",
-	[NVKM_ENGINE_SEC    ] = "sec",
-	[NVKM_ENGINE_SW     ] = "sw",
-	[NVKM_ENGINE_VIC    ] = "vic",
-	[NVKM_ENGINE_VP     ] = "vp",
+	[NVKM_SUBDEV_BAR     ] = "bar",
+	[NVKM_SUBDEV_VBIOS   ] = "bios",
+	[NVKM_SUBDEV_BUS     ] = "bus",
+	[NVKM_SUBDEV_CLK     ] = "clk",
+	[NVKM_SUBDEV_DEVINIT ] = "devinit",
+	[NVKM_SUBDEV_FB      ] = "fb",
+	[NVKM_SUBDEV_FUSE    ] = "fuse",
+	[NVKM_SUBDEV_GPIO    ] = "gpio",
+	[NVKM_SUBDEV_I2C     ] = "i2c",
+	[NVKM_SUBDEV_IBUS    ] = "priv",
+	[NVKM_SUBDEV_ICCSENSE] = "iccsense",
+	[NVKM_SUBDEV_INSTMEM ] = "imem",
+	[NVKM_SUBDEV_LTC     ] = "ltc",
+	[NVKM_SUBDEV_MC      ] = "mc",
+	[NVKM_SUBDEV_MMU     ] = "mmu",
+	[NVKM_SUBDEV_MXM     ] = "mxm",
+	[NVKM_SUBDEV_PCI     ] = "pci",
+	[NVKM_SUBDEV_PMU     ] = "pmu",
+	[NVKM_SUBDEV_THERM   ] = "therm",
+	[NVKM_SUBDEV_TIMER   ] = "tmr",
+	[NVKM_SUBDEV_VOLT    ] = "volt",
+	[NVKM_ENGINE_BSP     ] = "bsp",
+	[NVKM_ENGINE_CE0     ] = "ce0",
+	[NVKM_ENGINE_CE1     ] = "ce1",
+	[NVKM_ENGINE_CE2     ] = "ce2",
+	[NVKM_ENGINE_CIPHER  ] = "cipher",
+	[NVKM_ENGINE_DISP    ] = "disp",
+	[NVKM_ENGINE_DMAOBJ  ] = "dma",
+	[NVKM_ENGINE_FIFO    ] = "fifo",
+	[NVKM_ENGINE_GR      ] = "gr",
+	[NVKM_ENGINE_IFB     ] = "ifb",
+	[NVKM_ENGINE_ME      ] = "me",
+	[NVKM_ENGINE_MPEG    ] = "mpeg",
+	[NVKM_ENGINE_MSENC   ] = "msenc",
+	[NVKM_ENGINE_MSPDEC  ] = "mspdec",
+	[NVKM_ENGINE_MSPPP   ] = "msppp",
+	[NVKM_ENGINE_MSVLD   ] = "msvld",
+	[NVKM_ENGINE_PM      ] = "pm",
+	[NVKM_ENGINE_SEC     ] = "sec",
+	[NVKM_ENGINE_SW      ] = "sw",
+	[NVKM_ENGINE_VIC     ] = "vic",
+	[NVKM_ENGINE_VP      ] = "vp",
 };
 
 void
diff --git a/drm/nouveau/nvkm/engine/device/base.c b/drm/nouveau/nvkm/engine/device/base.c
index 3f4b868..a239e49 100644
--- a/drm/nouveau/nvkm/engine/device/base.c
+++ b/drm/nouveau/nvkm/engine/device/base.c
@@ -2102,26 +2102,27 @@ nvkm_device_subdev(struct nvkm_device *device, int index)
 
 	switch (index) {
 #define _(n,p,m) case NVKM_SUBDEV_##n: if (p) return (m); break
-	_(BAR    , device->bar    , &device->bar->subdev);
-	_(VBIOS  , device->bios   , &device->bios->subdev);
-	_(BUS    , device->bus    , &device->bus->subdev);
-	_(CLK    , device->clk    , &device->clk->subdev);
-	_(DEVINIT, device->devinit, &device->devinit->subdev);
-	_(FB     , device->fb     , &device->fb->subdev);
-	_(FUSE   , device->fuse   , &device->fuse->subdev);
-	_(GPIO   , device->gpio   , &device->gpio->subdev);
-	_(I2C    , device->i2c    , &device->i2c->subdev);
-	_(IBUS   , device->ibus   ,  device->ibus);
-	_(INSTMEM, device->imem   , &device->imem->subdev);
-	_(LTC    , device->ltc    , &device->ltc->subdev);
-	_(MC     , device->mc     , &device->mc->subdev);
-	_(MMU    , device->mmu    , &device->mmu->subdev);
-	_(MXM    , device->mxm    ,  device->mxm);
-	_(PCI    , device->pci    , &device->pci->subdev);
-	_(PMU    , device->pmu    , &device->pmu->subdev);
-	_(THERM  , device->therm  , &device->therm->subdev);
-	_(TIMER  , device->timer  , &device->timer->subdev);
-	_(VOLT   , device->volt   , &device->volt->subdev);
+	_(BAR     , device->bar     , &device->bar->subdev);
+	_(VBIOS   , device->bios    , &device->bios->subdev);
+	_(BUS     , device->bus     , &device->bus->subdev);
+	_(CLK     , device->clk     , &device->clk->subdev);
+	_(DEVINIT , device->devinit , &device->devinit->subdev);
+	_(FB      , device->fb      , &device->fb->subdev);
+	_(FUSE    , device->fuse    , &device->fuse->subdev);
+	_(GPIO    , device->gpio    , &device->gpio->subdev);
+	_(I2C     , device->i2c     , &device->i2c->subdev);
+	_(IBUS    , device->ibus    ,  device->ibus);
+	_(ICCSENSE, device->iccsense, &device->iccsense->subdev);
+	_(INSTMEM , device->imem    , &device->imem->subdev);
+	_(LTC     , device->ltc     , &device->ltc->subdev);
+	_(MC      , device->mc      , &device->mc->subdev);
+	_(MMU     , device->mmu     , &device->mmu->subdev);
+	_(MXM     , device->mxm     ,  device->mxm);
+	_(PCI     , device->pci     , &device->pci->subdev);
+	_(PMU     , device->pmu     , &device->pmu->subdev);
+	_(THERM   , device->therm   , &device->therm->subdev);
+	_(TIMER   , device->timer   , &device->timer->subdev);
+	_(VOLT    , device->volt    , &device->volt->subdev);
 #undef _
 	default:
 		engine = nvkm_device_engine(device, index);
@@ -2551,47 +2552,48 @@ nvkm_device_ctor(const struct nvkm_device_func *func,
 	}                                                                      \
 	break
 		switch (i) {
-		_(NVKM_SUBDEV_BAR    ,     bar);
-		_(NVKM_SUBDEV_VBIOS  ,    bios);
-		_(NVKM_SUBDEV_BUS    ,     bus);
-		_(NVKM_SUBDEV_CLK    ,     clk);
-		_(NVKM_SUBDEV_DEVINIT, devinit);
-		_(NVKM_SUBDEV_FB     ,      fb);
-		_(NVKM_SUBDEV_FUSE   ,    fuse);
-		_(NVKM_SUBDEV_GPIO   ,    gpio);
-		_(NVKM_SUBDEV_I2C    ,     i2c);
-		_(NVKM_SUBDEV_IBUS   ,    ibus);
-		_(NVKM_SUBDEV_INSTMEM,    imem);
-		_(NVKM_SUBDEV_LTC    ,     ltc);
-		_(NVKM_SUBDEV_MC     ,      mc);
-		_(NVKM_SUBDEV_MMU    ,     mmu);
-		_(NVKM_SUBDEV_MXM    ,     mxm);
-		_(NVKM_SUBDEV_PCI    ,     pci);
-		_(NVKM_SUBDEV_PMU    ,     pmu);
-		_(NVKM_SUBDEV_THERM  ,   therm);
-		_(NVKM_SUBDEV_TIMER  ,   timer);
-		_(NVKM_SUBDEV_VOLT   ,    volt);
-		_(NVKM_ENGINE_BSP    ,     bsp);
-		_(NVKM_ENGINE_CE0    ,   ce[0]);
-		_(NVKM_ENGINE_CE1    ,   ce[1]);
-		_(NVKM_ENGINE_CE2    ,   ce[2]);
-		_(NVKM_ENGINE_CIPHER ,  cipher);
-		_(NVKM_ENGINE_DISP   ,    disp);
-		_(NVKM_ENGINE_DMAOBJ ,     dma);
-		_(NVKM_ENGINE_FIFO   ,    fifo);
-		_(NVKM_ENGINE_GR     ,      gr);
-		_(NVKM_ENGINE_IFB    ,     ifb);
-		_(NVKM_ENGINE_ME     ,      me);
-		_(NVKM_ENGINE_MPEG   ,    mpeg);
-		_(NVKM_ENGINE_MSENC  ,   msenc);
-		_(NVKM_ENGINE_MSPDEC ,  mspdec);
-		_(NVKM_ENGINE_MSPPP  ,   msppp);
-		_(NVKM_ENGINE_MSVLD  ,   msvld);
-		_(NVKM_ENGINE_PM     ,      pm);
-		_(NVKM_ENGINE_SEC    ,     sec);
-		_(NVKM_ENGINE_SW     ,      sw);
-		_(NVKM_ENGINE_VIC    ,     vic);
-		_(NVKM_ENGINE_VP     ,      vp);
+		_(NVKM_SUBDEV_BAR     ,      bar);
+		_(NVKM_SUBDEV_VBIOS   ,     bios);
+		_(NVKM_SUBDEV_BUS     ,      bus);
+		_(NVKM_SUBDEV_CLK     ,      clk);
+		_(NVKM_SUBDEV_DEVINIT ,  devinit);
+		_(NVKM_SUBDEV_FB      ,       fb);
+		_(NVKM_SUBDEV_FUSE    ,     fuse);
+		_(NVKM_SUBDEV_GPIO    ,     gpio);
+		_(NVKM_SUBDEV_I2C     ,      i2c);
+		_(NVKM_SUBDEV_IBUS    ,     ibus);
+		_(NVKM_SUBDEV_ICCSENSE, iccsense);
+		_(NVKM_SUBDEV_INSTMEM ,     imem);
+		_(NVKM_SUBDEV_LTC     ,      ltc);
+		_(NVKM_SUBDEV_MC      ,       mc);
+		_(NVKM_SUBDEV_MMU     ,      mmu);
+		_(NVKM_SUBDEV_MXM     ,      mxm);
+		_(NVKM_SUBDEV_PCI     ,      pci);
+		_(NVKM_SUBDEV_PMU     ,      pmu);
+		_(NVKM_SUBDEV_THERM   ,    therm);
+		_(NVKM_SUBDEV_TIMER   ,    timer);
+		_(NVKM_SUBDEV_VOLT    ,     volt);
+		_(NVKM_ENGINE_BSP     ,      bsp);
+		_(NVKM_ENGINE_CE0     ,    ce[0]);
+		_(NVKM_ENGINE_CE1     ,    ce[1]);
+		_(NVKM_ENGINE_CE2     ,    ce[2]);
+		_(NVKM_ENGINE_CIPHER  ,   cipher);
+		_(NVKM_ENGINE_DISP    ,     disp);
+		_(NVKM_ENGINE_DMAOBJ  ,      dma);
+		_(NVKM_ENGINE_FIFO    ,     fifo);
+		_(NVKM_ENGINE_GR      ,       gr);
+		_(NVKM_ENGINE_IFB     ,      ifb);
+		_(NVKM_ENGINE_ME      ,       me);
+		_(NVKM_ENGINE_MPEG    ,     mpeg);
+		_(NVKM_ENGINE_MSENC   ,    msenc);
+		_(NVKM_ENGINE_MSPDEC  ,   mspdec);
+		_(NVKM_ENGINE_MSPPP   ,    msppp);
+		_(NVKM_ENGINE_MSVLD   ,    msvld);
+		_(NVKM_ENGINE_PM      ,       pm);
+		_(NVKM_ENGINE_SEC     ,      sec);
+		_(NVKM_ENGINE_SW      ,       sw);
+		_(NVKM_ENGINE_VIC     ,      vic);
+		_(NVKM_ENGINE_VP      ,       vp);
 		default:
 			WARN_ON(1);
 			continue;
diff --git a/drm/nouveau/nvkm/engine/device/priv.h b/drm/nouveau/nvkm/engine/device/priv.h
index ed3ad2c..49981a1 100644
--- a/drm/nouveau/nvkm/engine/device/priv.h
+++ b/drm/nouveau/nvkm/engine/device/priv.h
@@ -12,6 +12,7 @@
 #include <subdev/gpio.h>
 #include <subdev/i2c.h>
 #include <subdev/ibus.h>
+#include <subdev/iccsense.h>
 #include <subdev/instmem.h>
 #include <subdev/ltc.h>
 #include <subdev/mc.h>
diff --git a/drm/nouveau/nvkm/subdev/Kbuild b/drm/nouveau/nvkm/subdev/Kbuild
index ee2c38f..63d0587 100644
--- a/drm/nouveau/nvkm/subdev/Kbuild
+++ b/drm/nouveau/nvkm/subdev/Kbuild
@@ -8,6 +8,7 @@ include $(src)/nvkm/subdev/fuse/Kbuild
 include $(src)/nvkm/subdev/gpio/Kbuild
 include $(src)/nvkm/subdev/i2c/Kbuild
 include $(src)/nvkm/subdev/ibus/Kbuild
+include $(src)/nvkm/subdev/iccsense/Kbuild
 include $(src)/nvkm/subdev/instmem/Kbuild
 include $(src)/nvkm/subdev/ltc/Kbuild
 include $(src)/nvkm/subdev/mc/Kbuild
diff --git a/drm/nouveau/nvkm/subdev/iccsense/Kbuild b/drm/nouveau/nvkm/subdev/iccsense/Kbuild
new file mode 100644
index 0000000..b6863da
--- /dev/null
+++ b/drm/nouveau/nvkm/subdev/iccsense/Kbuild
@@ -0,0 +1 @@
+nvkm-y += nvkm/subdev/iccsense/base.o
diff --git a/drm/nouveau/nvkm/subdev/iccsense/base.c b/drm/nouveau/nvkm/subdev/iccsense/base.c
new file mode 100644
index 0000000..5dfa2fd
--- /dev/null
+++ b/drm/nouveau/nvkm/subdev/iccsense/base.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2015 Martin Peres
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Martin Peres
+ */
+#include "priv.h"
+
+struct nvkm_subdev_func iccsense_func = { 0 };
+
+int
+nvkm_iccsense_ctor(struct nvkm_device *device, int index,
+		   struct nvkm_iccsense *iccsense)
+{
+	nvkm_subdev_ctor(&iccsense_func, device, index, 0, &iccsense->subdev);
+	return 0;
+}
+
+int
+nvkm_iccsense_new_(struct nvkm_device *device, int index,
+		   struct nvkm_iccsense **iccsense)
+{
+	if (!(*iccsense = kzalloc(sizeof(**iccsense), GFP_KERNEL)))
+		return -ENOMEM;
+	return nvkm_iccsense_ctor(device, index, *iccsense);
+}
diff --git a/drm/nouveau/nvkm/subdev/iccsense/priv.h b/drm/nouveau/nvkm/subdev/iccsense/priv.h
new file mode 100644
index 0000000..f0aa17a
--- /dev/null
+++ b/drm/nouveau/nvkm/subdev/iccsense/priv.h
@@ -0,0 +1,8 @@
+#ifndef __NVKM_ICCSENSE_PRIV_H__
+#define __NVKM_ICCSENSE_PRIV_H__
+#define nvkm_iccsense(p) container_of((p), struct nvkm_iccsense, subdev)
+#include <subdev/iccsense.h>
+
+int nvkm_iccsense_ctor(struct nvkm_device *, int, struct nvkm_iccsense *);
+int nvkm_iccsense_new_(struct nvkm_device *, int, struct nvkm_iccsense **);
+#endif
-- 
2.7.1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 2/6] nvbios/iccsense: add parsing of the SENSE table
       [not found] ` <1455988299-2300-1-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
  2016-02-20 17:11   ` [PATCH v4 1/6] subdev/iccsense: add new subdev for power sensors Karol Herbst
@ 2016-02-20 17:11   ` Karol Herbst
       [not found]     ` <1455988299-2300-3-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
  2016-02-20 17:11   ` [PATCH v4 3/6] iccsense: implement for ina209, ina219 and ina3221 Karol Herbst
                     ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Karol Herbst @ 2016-02-20 17:11 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

From: Martin Peres <martin.peres@free.fr>

v4: don't kmalloc(0)

Signed-off-by: Karol Herbst <nouveau@karolherbst.de>
---
 drm/nouveau/include/nvkm/subdev/bios/iccsense.h | 16 ++++
 drm/nouveau/nvkm/subdev/bios/Kbuild             |  1 +
 drm/nouveau/nvkm/subdev/bios/iccsense.c         | 97 +++++++++++++++++++++++++
 3 files changed, 114 insertions(+)
 create mode 100644 drm/nouveau/include/nvkm/subdev/bios/iccsense.h
 create mode 100644 drm/nouveau/nvkm/subdev/bios/iccsense.c

diff --git a/drm/nouveau/include/nvkm/subdev/bios/iccsense.h b/drm/nouveau/include/nvkm/subdev/bios/iccsense.h
new file mode 100644
index 0000000..9cb9747
--- /dev/null
+++ b/drm/nouveau/include/nvkm/subdev/bios/iccsense.h
@@ -0,0 +1,16 @@
+#ifndef __NVBIOS_ICCSENSE_H__
+#define __NVBIOS_ICCSENSE_H__
+struct pwr_rail_t {
+	u8 mode;
+	u8 extdev_id;
+	u8 resistor_mohm;
+	u8 rail;
+};
+
+struct nvbios_iccsense {
+	int nr_entry;
+	struct pwr_rail_t *rail;
+};
+
+int nvbios_iccsense_parse(struct nvkm_bios *, struct nvbios_iccsense *);
+#endif
diff --git a/drm/nouveau/nvkm/subdev/bios/Kbuild b/drm/nouveau/nvkm/subdev/bios/Kbuild
index 64730d5..dbcb0ef 100644
--- a/drm/nouveau/nvkm/subdev/bios/Kbuild
+++ b/drm/nouveau/nvkm/subdev/bios/Kbuild
@@ -10,6 +10,7 @@ nvkm-y += nvkm/subdev/bios/extdev.o
 nvkm-y += nvkm/subdev/bios/fan.o
 nvkm-y += nvkm/subdev/bios/gpio.o
 nvkm-y += nvkm/subdev/bios/i2c.o
+nvkm-y += nvkm/subdev/bios/iccsense.o
 nvkm-y += nvkm/subdev/bios/image.o
 nvkm-y += nvkm/subdev/bios/init.o
 nvkm-y += nvkm/subdev/bios/mxm.o
diff --git a/drm/nouveau/nvkm/subdev/bios/iccsense.c b/drm/nouveau/nvkm/subdev/bios/iccsense.c
new file mode 100644
index 0000000..0d9fc8c
--- /dev/null
+++ b/drm/nouveau/nvkm/subdev/bios/iccsense.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2015 Martin Peres
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Martin Peres
+ */
+#include <subdev/bios.h>
+#include <subdev/bios/bit.h>
+#include <subdev/bios/iccsense.h>
+
+static u16
+nvbios_iccsense_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt,
+		      u8 *len)
+{
+	struct bit_entry bit_P;
+	u16 iccsense;
+
+	if (bit_entry(bios, 'P', &bit_P) || bit_P.version != 2 ||
+	    bit_P.length < 0x2c)
+		return 0;
+
+	iccsense = nvbios_rd16(bios, bit_P.offset + 0x28);
+	if (!iccsense)
+		return 0;
+
+	*ver = nvbios_rd08(bios, iccsense + 0);
+	switch (*ver) {
+	case 0x10:
+	case 0x20:
+		*hdr = nvbios_rd08(bios, iccsense + 1);
+		*len = nvbios_rd08(bios, iccsense + 2);
+		*cnt = nvbios_rd08(bios, iccsense + 3);
+		return iccsense;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
+int
+nvbios_iccsense_parse(struct nvkm_bios *bios, struct nvbios_iccsense *iccsense)
+{
+	u8 ver, hdr, cnt, len, i;
+	u16 table, entry;
+
+	table = nvbios_iccsense_table(bios, &ver, &hdr, &cnt, &len);
+	if (!table)
+		return -EINVAL;
+
+	iccsense->nr_entry = cnt;
+	if (!cnt)
+		return 0;
+
+	iccsense->rail = kmalloc(sizeof(struct pwr_rail_t) * cnt, GFP_KERNEL);
+	if (!iccsense->rail)
+		return -ENOMEM;
+
+	for (i = 0; i < cnt; ++i) {
+		struct pwr_rail_t *rail = &iccsense->rail[i];
+		entry = table + hdr + i * len;
+
+		switch(ver) {
+		case 0x10:
+			rail->mode = nvbios_rd08(bios, entry + 0x1);
+			rail->extdev_id = nvbios_rd08(bios, entry + 0x2);
+			rail->resistor_mohm = nvbios_rd08(bios, entry + 0x3);
+			rail->rail = nvbios_rd08(bios, entry + 0x4);
+			break;
+		case 0x20:
+			rail->mode = nvbios_rd08(bios, entry);
+			rail->extdev_id = nvbios_rd08(bios, entry + 0x1);
+			rail->resistor_mohm = nvbios_rd08(bios, entry + 0x5);
+			rail->rail = nvbios_rd08(bios, entry + 0x6);
+			break;
+		};
+	}
+
+	return 0;
+}
-- 
2.7.1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 3/6] iccsense: implement for ina209, ina219 and ina3221
       [not found] ` <1455988299-2300-1-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
  2016-02-20 17:11   ` [PATCH v4 1/6] subdev/iccsense: add new subdev for power sensors Karol Herbst
  2016-02-20 17:11   ` [PATCH v4 2/6] nvbios/iccsense: add parsing of the SENSE table Karol Herbst
@ 2016-02-20 17:11   ` Karol Herbst
       [not found]     ` <1455988299-2300-4-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
  2016-02-20 17:11   ` [PATCH v4 4/6] hwmon: add power consumption Karol Herbst
                     ` (2 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Karol Herbst @ 2016-02-20 17:11 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

based on Martins initial work

v3: fix ina2x9 calculations
v4: don't kmalloc(0), fix the lsb/pga stuff

Signed-off-by: Karol Herbst <nouveau@karolherbst.de>
---
 drm/nouveau/include/nvkm/subdev/bios/extdev.h |   3 +
 drm/nouveau/include/nvkm/subdev/i2c.h         |  31 ++++++
 drm/nouveau/include/nvkm/subdev/iccsense.h    |   5 +
 drm/nouveau/nvkm/engine/device/base.c         |  20 ++++
 drm/nouveau/nvkm/subdev/iccsense/Kbuild       |   1 +
 drm/nouveau/nvkm/subdev/iccsense/base.c       | 150 +++++++++++++++++++++++++-
 drm/nouveau/nvkm/subdev/iccsense/gf100.c      |  31 ++++++
 drm/nouveau/nvkm/subdev/iccsense/priv.h       |   8 ++
 8 files changed, 248 insertions(+), 1 deletion(-)
 create mode 100644 drm/nouveau/nvkm/subdev/iccsense/gf100.c

diff --git a/drm/nouveau/include/nvkm/subdev/bios/extdev.h b/drm/nouveau/include/nvkm/subdev/bios/extdev.h
index 6d3bedc..bb49bd5 100644
--- a/drm/nouveau/include/nvkm/subdev/bios/extdev.h
+++ b/drm/nouveau/include/nvkm/subdev/bios/extdev.h
@@ -5,6 +5,9 @@ enum nvbios_extdev_type {
 	NVBIOS_EXTDEV_VT1103M		= 0x40,
 	NVBIOS_EXTDEV_PX3540		= 0x41,
 	NVBIOS_EXTDEV_VT1105M		= 0x42, /* or close enough... */
+	NVBIOS_EXTDEV_INA219		= 0x4c,
+	NVBIOS_EXTDEV_INA209		= 0x4d,
+	NVBIOS_EXTDEV_INA3221		= 0x4e,
 	NVBIOS_EXTDEV_ADT7473		= 0x70, /* can also be a LM64 */
 	NVBIOS_EXTDEV_HDCP_EEPROM	= 0x90,
 	NVBIOS_EXTDEV_NONE		= 0xff,
diff --git a/drm/nouveau/include/nvkm/subdev/i2c.h b/drm/nouveau/include/nvkm/subdev/i2c.h
index 864d1ab..a63c5ac 100644
--- a/drm/nouveau/include/nvkm/subdev/i2c.h
+++ b/drm/nouveau/include/nvkm/subdev/i2c.h
@@ -108,6 +108,22 @@ nvkm_rdi2cr(struct i2c_adapter *adap, u8 addr, u8 reg)
 }
 
 static inline int
+nv_rd16i2cr(struct i2c_adapter *adap, u8 addr, u8 reg)
+{
+	u8 val[2];
+	struct i2c_msg msgs[] = {
+		{ .addr = addr, .flags = 0, .len = 1, .buf = &reg },
+		{ .addr = addr, .flags = I2C_M_RD, .len = 2, .buf = val },
+	};
+
+	int ret = i2c_transfer(adap, msgs, ARRAY_SIZE(msgs));
+	if (ret != 2)
+		return -EIO;
+
+	return val[0] << 8 | val[1];
+}
+
+static inline int
 nvkm_wri2cr(struct i2c_adapter *adap, u8 addr, u8 reg, u8 val)
 {
 	u8 buf[2] = { reg, val };
@@ -122,6 +138,21 @@ nvkm_wri2cr(struct i2c_adapter *adap, u8 addr, u8 reg, u8 val)
 	return 0;
 }
 
+static inline int
+nv_wr16i2cr(struct i2c_adapter *adap, u8 addr, u8 reg, u16 val)
+{
+	u8 buf[3] = { reg, val >> 8, val & 0xff};
+	struct i2c_msg msgs[] = {
+		{ .addr = addr, .flags = 0, .len = 3, .buf = buf },
+	};
+
+	int ret = i2c_transfer(adap, msgs, ARRAY_SIZE(msgs));
+	if (ret != 1)
+		return -EIO;
+
+	return 0;
+}
+
 static inline bool
 nvkm_probe_i2c(struct i2c_adapter *adap, u8 addr)
 {
diff --git a/drm/nouveau/include/nvkm/subdev/iccsense.h b/drm/nouveau/include/nvkm/subdev/iccsense.h
index 7fee41d..16b77a6 100644
--- a/drm/nouveau/include/nvkm/subdev/iccsense.h
+++ b/drm/nouveau/include/nvkm/subdev/iccsense.h
@@ -3,8 +3,13 @@
 
 #include <core/subdev.h>
 
+struct nkvm_iccsense_rail;
 struct nvkm_iccsense {
 	struct nvkm_subdev subdev;
+	u8 rail_count;
+	struct nvkm_iccsense_rail *rails;
 };
 
+int gf100_iccsense_new(struct nvkm_device *, int index, struct nvkm_iccsense **);
+int nkvm_iccsense_read(struct nvkm_iccsense *iccsense, u8 idx);
 #endif
diff --git a/drm/nouveau/nvkm/engine/device/base.c b/drm/nouveau/nvkm/engine/device/base.c
index a239e49..2536890 100644
--- a/drm/nouveau/nvkm/engine/device/base.c
+++ b/drm/nouveau/nvkm/engine/device/base.c
@@ -1347,6 +1347,7 @@ nvc0_chipset = {
 	.gpio = g94_gpio_new,
 	.i2c = g94_i2c_new,
 	.ibus = gf100_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gf100_ltc_new,
 	.mc = gf100_mc_new,
@@ -1383,6 +1384,7 @@ nvc1_chipset = {
 	.gpio = g94_gpio_new,
 	.i2c = g94_i2c_new,
 	.ibus = gf100_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gf100_ltc_new,
 	.mc = gf100_mc_new,
@@ -1418,6 +1420,7 @@ nvc3_chipset = {
 	.gpio = g94_gpio_new,
 	.i2c = g94_i2c_new,
 	.ibus = gf100_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gf100_ltc_new,
 	.mc = gf100_mc_new,
@@ -1453,6 +1456,7 @@ nvc4_chipset = {
 	.gpio = g94_gpio_new,
 	.i2c = g94_i2c_new,
 	.ibus = gf100_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gf100_ltc_new,
 	.mc = gf100_mc_new,
@@ -1489,6 +1493,7 @@ nvc8_chipset = {
 	.gpio = g94_gpio_new,
 	.i2c = g94_i2c_new,
 	.ibus = gf100_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gf100_ltc_new,
 	.mc = gf100_mc_new,
@@ -1525,6 +1530,7 @@ nvce_chipset = {
 	.gpio = g94_gpio_new,
 	.i2c = g94_i2c_new,
 	.ibus = gf100_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gf100_ltc_new,
 	.mc = gf100_mc_new,
@@ -1561,6 +1567,7 @@ nvcf_chipset = {
 	.gpio = g94_gpio_new,
 	.i2c = g94_i2c_new,
 	.ibus = gf100_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gf100_ltc_new,
 	.mc = gf100_mc_new,
@@ -1596,6 +1603,7 @@ nvd7_chipset = {
 	.gpio = gf119_gpio_new,
 	.i2c = gf117_i2c_new,
 	.ibus = gf117_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gf100_ltc_new,
 	.mc = gf100_mc_new,
@@ -1629,6 +1637,7 @@ nvd9_chipset = {
 	.gpio = gf119_gpio_new,
 	.i2c = gf119_i2c_new,
 	.ibus = gf117_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gf100_ltc_new,
 	.mc = gf100_mc_new,
@@ -1664,6 +1673,7 @@ nve4_chipset = {
 	.gpio = gk104_gpio_new,
 	.i2c = gk104_i2c_new,
 	.ibus = gk104_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gk104_ltc_new,
 	.mc = gf100_mc_new,
@@ -1701,6 +1711,7 @@ nve6_chipset = {
 	.gpio = gk104_gpio_new,
 	.i2c = gk104_i2c_new,
 	.ibus = gk104_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gk104_ltc_new,
 	.mc = gf100_mc_new,
@@ -1738,6 +1749,7 @@ nve7_chipset = {
 	.gpio = gk104_gpio_new,
 	.i2c = gk104_i2c_new,
 	.ibus = gk104_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gk104_ltc_new,
 	.mc = gf100_mc_new,
@@ -1799,6 +1811,7 @@ nvf0_chipset = {
 	.gpio = gk104_gpio_new,
 	.i2c = gk104_i2c_new,
 	.ibus = gk104_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gk104_ltc_new,
 	.mc = gf100_mc_new,
@@ -1835,6 +1848,7 @@ nvf1_chipset = {
 	.gpio = gk104_gpio_new,
 	.i2c = gf119_i2c_new,
 	.ibus = gk104_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gk104_ltc_new,
 	.mc = gf100_mc_new,
@@ -1871,6 +1885,7 @@ nv106_chipset = {
 	.gpio = gk104_gpio_new,
 	.i2c = gk104_i2c_new,
 	.ibus = gk104_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gk104_ltc_new,
 	.mc = gk20a_mc_new,
@@ -1907,6 +1922,7 @@ nv108_chipset = {
 	.gpio = gk104_gpio_new,
 	.i2c = gk104_i2c_new,
 	.ibus = gk104_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gk104_ltc_new,
 	.mc = gk20a_mc_new,
@@ -1943,6 +1959,7 @@ nv117_chipset = {
 	.gpio = gk104_gpio_new,
 	.i2c = gf119_i2c_new,
 	.ibus = gk104_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gm107_ltc_new,
 	.mc = gk20a_mc_new,
@@ -1974,6 +1991,7 @@ nv120_chipset = {
 	.gpio = gk104_gpio_new,
 	.i2c = gm200_i2c_new,
 	.ibus = gm200_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gm200_ltc_new,
 	.mc = gk20a_mc_new,
@@ -2004,6 +2022,7 @@ nv124_chipset = {
 	.gpio = gk104_gpio_new,
 	.i2c = gm200_i2c_new,
 	.ibus = gm200_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gm200_ltc_new,
 	.mc = gk20a_mc_new,
@@ -2035,6 +2054,7 @@ nv126_chipset = {
 	.gpio = gk104_gpio_new,
 	.i2c = gm200_i2c_new,
 	.ibus = gm200_ibus_new,
+	.iccsense = gf100_iccsense_new,
 	.imem = nv50_instmem_new,
 	.ltc = gm200_ltc_new,
 	.mc = gk20a_mc_new,
diff --git a/drm/nouveau/nvkm/subdev/iccsense/Kbuild b/drm/nouveau/nvkm/subdev/iccsense/Kbuild
index b6863da..98a4bd3 100644
--- a/drm/nouveau/nvkm/subdev/iccsense/Kbuild
+++ b/drm/nouveau/nvkm/subdev/iccsense/Kbuild
@@ -1 +1,2 @@
 nvkm-y += nvkm/subdev/iccsense/base.o
+nvkm-y += nvkm/subdev/iccsense/gf100.o
diff --git a/drm/nouveau/nvkm/subdev/iccsense/base.c b/drm/nouveau/nvkm/subdev/iccsense/base.c
index 5dfa2fd..29c6641 100644
--- a/drm/nouveau/nvkm/subdev/iccsense/base.c
+++ b/drm/nouveau/nvkm/subdev/iccsense/base.c
@@ -23,13 +23,161 @@
  */
 #include "priv.h"
 
-struct nvkm_subdev_func iccsense_func = { 0 };
+#include <subdev/bios.h>
+#include <subdev/bios/extdev.h>
+#include <subdev/bios/iccsense.h>
+#include <subdev/i2c.h>
+
+static int
+nvkm_iccsense_poll_lane(struct i2c_adapter *i2c, u8 addr, u8 shunt_reg,
+			u8 shunt_shift, u8 bus_reg, u8 bus_shift, u8 shunt,
+			u16 lsb)
+{
+	int vbus, vshunt;
+
+	if (shunt == 0)
+		return 0;
+
+	vshunt = nv_rd16i2cr(i2c, addr, shunt_reg);
+	vbus = nv_rd16i2cr(i2c, addr, bus_reg);
+
+	if (vshunt < 0 || vbus < 0)
+		return -EINVAL;
+
+	vshunt >>= shunt_shift;
+	vbus >>= bus_shift;
+
+	return (vbus * vshunt * lsb) / shunt;
+}
+
+static int
+nvkm_iccsense_ina2x9_read(struct nvkm_iccsense *iccsense,
+                          struct nvkm_iccsense_rail *rail,
+			  u8 shunt_reg, u8 bus_reg)
+{
+	return nvkm_iccsense_poll_lane(rail->i2c, rail->addr, shunt_reg, 0,
+				       bus_reg, 3, rail->mohm, 10 * 4);
+}
+
+static int
+nvkm_iccsense_ina209_read(struct nvkm_iccsense *iccsense,
+			  struct nvkm_iccsense_rail *rail)
+{
+	return nvkm_iccsense_ina2x9_read(iccsense, rail, 3, 4);
+}
+
+static int
+nvkm_iccsense_ina219_read(struct nvkm_iccsense *iccsense,
+			  struct nvkm_iccsense_rail *rail)
+{
+	return nvkm_iccsense_ina2x9_read(iccsense, rail, 1, 2);
+}
+
+static int
+nvkm_iccsense_ina3221_read(struct nvkm_iccsense *iccsense,
+			   struct nvkm_iccsense_rail *rail)
+{
+	if (rail->rail >= 3)
+		return -EINVAL;
+
+	return nvkm_iccsense_poll_lane(rail->i2c, rail->addr,
+				       1 + (rail->rail * 2), 3,
+				       2 + (rail->rail * 2), 3, rail->mohm,
+				       40 * 8);
+}
+
+int
+nkvm_iccsense_read(struct nvkm_iccsense *iccsense, u8 idx)
+{
+	struct nvkm_iccsense_rail *rail;
+
+	if (!iccsense || idx >= iccsense->rail_count)
+		return -EINVAL;
+
+	rail = &iccsense->rails[idx];
+	if (!rail->read)
+		return -ENODEV;
+
+	return rail->read(iccsense, rail);
+}
+
+static void *
+nvkm_iccsense_dtor(struct nvkm_subdev *subdev)
+{
+	struct nvkm_iccsense *iccsense = nvkm_iccsense(subdev);
+
+	if (iccsense->rails)
+		kfree(iccsense->rails);
+
+	return iccsense;
+}
+
+struct nvkm_subdev_func iccsense_func = {
+	.dtor = nvkm_iccsense_dtor,
+};
 
 int
 nvkm_iccsense_ctor(struct nvkm_device *device, int index,
 		   struct nvkm_iccsense *iccsense)
 {
+	struct nvkm_bios *bios;
+	struct nvkm_i2c *i2c;
+	struct nvbios_iccsense stbl;
+	int i;
+
 	nvkm_subdev_ctor(&iccsense_func, device, index, 0, &iccsense->subdev);
+	bios = device->bios;
+	i2c = device->i2c;
+
+	if (!i2c || !bios || nvbios_iccsense_parse(bios, &stbl)
+	    || !stbl.nr_entry)
+		return 0;
+
+	iccsense->rails = kmalloc(sizeof(*iccsense->rails) * stbl.nr_entry,
+	                          GFP_KERNEL);
+	if (!iccsense->rails)
+		return -ENOMEM;
+
+	for (i = 0; i < stbl.nr_entry; ++i) {
+		struct pwr_rail_t *r = &stbl.rail[i];
+		struct nvbios_extdev_func extdev;
+		struct nvkm_iccsense_rail *rail;
+		struct nvkm_i2c_bus *i2c_bus;
+
+		if (!r->mode)
+			continue;
+
+		if (nvbios_extdev_parse(bios, r->extdev_id, &extdev))
+			continue;
+
+		if (extdev.bus)
+			i2c_bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_SEC);
+		else
+			i2c_bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_PRI);
+		if (!i2c_bus)
+			continue;
+
+		rail = &iccsense->rails[iccsense->rail_count];
+		switch (extdev.type) {
+		case NVBIOS_EXTDEV_INA209:
+			rail->read = nvkm_iccsense_ina209_read;
+			break;
+		case NVBIOS_EXTDEV_INA219:
+			rail->read = nvkm_iccsense_ina219_read;
+			break;
+		case NVBIOS_EXTDEV_INA3221:
+			rail->read = nvkm_iccsense_ina3221_read;
+			break;
+		default:
+			continue;
+		}
+		rail->addr = extdev.addr >> 1;
+		rail->rail = r->rail;
+		rail->mohm = r->resistor_mohm;
+		rail->i2c = &i2c_bus->i2c;
+		++iccsense->rail_count;
+	}
+
 	return 0;
 }
 
diff --git a/drm/nouveau/nvkm/subdev/iccsense/gf100.c b/drm/nouveau/nvkm/subdev/iccsense/gf100.c
new file mode 100644
index 0000000..cccff1c
--- /dev/null
+++ b/drm/nouveau/nvkm/subdev/iccsense/gf100.c
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2015 Karol Herbst
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Karol Herbst
+ */
+#include "priv.h"
+
+int
+gf100_iccsense_new(struct nvkm_device *device, int index,
+		   struct nvkm_iccsense **piccsense)
+{
+	return nvkm_iccsense_new_(device, index, piccsense);
+}
diff --git a/drm/nouveau/nvkm/subdev/iccsense/priv.h b/drm/nouveau/nvkm/subdev/iccsense/priv.h
index f0aa17a..db33d81 100644
--- a/drm/nouveau/nvkm/subdev/iccsense/priv.h
+++ b/drm/nouveau/nvkm/subdev/iccsense/priv.h
@@ -3,6 +3,14 @@
 #define nvkm_iccsense(p) container_of((p), struct nvkm_iccsense, subdev)
 #include <subdev/iccsense.h>
 
+struct nvkm_iccsense_rail {
+	int (*read)(struct nvkm_iccsense *, struct nvkm_iccsense_rail *);
+	struct i2c_adapter *i2c;
+	u16 addr;
+	u8  rail;
+	u8  mohm;
+};
+
 int nvkm_iccsense_ctor(struct nvkm_device *, int, struct nvkm_iccsense *);
 int nvkm_iccsense_new_(struct nvkm_device *, int, struct nvkm_iccsense **);
 #endif
-- 
2.7.1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 4/6] hwmon: add power consumption
       [not found] ` <1455988299-2300-1-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
                     ` (2 preceding siblings ...)
  2016-02-20 17:11   ` [PATCH v4 3/6] iccsense: implement for ina209, ina219 and ina3221 Karol Herbst
@ 2016-02-20 17:11   ` Karol Herbst
       [not found]     ` <1455988299-2300-5-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
  2016-02-20 17:11   ` [PATCH v4 5/6] hwmon: don't require therm to be valid to get any data Karol Herbst
  2016-02-20 17:11   ` [PATCH v4 6/6] bios/extdev: also parse v4.1 table Karol Herbst
  5 siblings, 1 reply; 13+ messages in thread
From: Karol Herbst @ 2016-02-20 17:11 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Signed-off-by: Karol Herbst <nouveau@karolherbst.de>
---
 drm/nouveau/include/nvif/device.h |  1 +
 drm/nouveau/nouveau_hwmon.c       | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/drm/nouveau/include/nvif/device.h b/drm/nouveau/include/nvif/device.h
index e0ed2f4..bcb9817 100644
--- a/drm/nouveau/include/nvif/device.h
+++ b/drm/nouveau/include/nvif/device.h
@@ -62,6 +62,7 @@ u64  nvif_device_time(struct nvif_device *);
 #define nvxx_gpio(a) nvxx_device(a)->gpio
 #define nvxx_clk(a) nvxx_device(a)->clk
 #define nvxx_i2c(a) nvxx_device(a)->i2c
+#define nvxx_iccsense(a) nvxx_device(a)->iccsense
 #define nvxx_therm(a) nvxx_device(a)->therm
 #define nvxx_volt(a) nvxx_device(a)->volt
 
diff --git a/drm/nouveau/nouveau_hwmon.c b/drm/nouveau/nouveau_hwmon.c
index 8e13467..c4f77f5 100644
--- a/drm/nouveau/nouveau_hwmon.c
+++ b/drm/nouveau/nouveau_hwmon.c
@@ -34,6 +34,7 @@
 #include "nouveau_drm.h"
 #include "nouveau_hwmon.h"
 
+#include <nvkm/subdev/iccsense.h>
 #include <nvkm/subdev/volt.h>
 
 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
@@ -543,6 +544,27 @@ nouveau_hwmon_get_in0_label(struct device *d,
 static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO,
 			  nouveau_hwmon_get_in0_label, NULL, 0);
 
+static ssize_t
+nouveau_hwmon_get_power1_input(struct device *d, struct device_attribute *a,
+			       char *buf)
+{
+	struct drm_device *dev = dev_get_drvdata(d);
+	struct nouveau_drm *drm = nouveau_drm(dev);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->device);
+	int result = 0, i;
+
+	for (i = 0; i < iccsense->rail_count; ++i) {
+		int res = nkvm_iccsense_read(iccsense, i);
+		if (res > 0)
+			result += res;
+	}
+
+	return sprintf(buf, "%i\n", result);
+}
+
+static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO,
+			  nouveau_hwmon_get_power1_input, NULL, 0);
+
 static struct attribute *hwmon_default_attributes[] = {
 	&sensor_dev_attr_name.dev_attr.attr,
 	&sensor_dev_attr_update_rate.dev_attr.attr,
@@ -579,6 +601,11 @@ static struct attribute *hwmon_in0_attributes[] = {
 	NULL
 };
 
+static struct attribute *hwmon_power_attributes[] = {
+	&sensor_dev_attr_power1_input.dev_attr.attr,
+	NULL
+};
+
 static const struct attribute_group hwmon_default_attrgroup = {
 	.attrs = hwmon_default_attributes,
 };
@@ -594,6 +621,9 @@ static const struct attribute_group hwmon_pwm_fan_attrgroup = {
 static const struct attribute_group hwmon_in0_attrgroup = {
 	.attrs = hwmon_in0_attributes,
 };
+static const struct attribute_group hwmon_power_attrgroup = {
+	.attrs = hwmon_power_attributes,
+};
 #endif
 
 int
@@ -603,6 +633,7 @@ nouveau_hwmon_init(struct drm_device *dev)
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nvkm_therm *therm = nvxx_therm(&drm->device);
 	struct nvkm_volt *volt = nvxx_volt(&drm->device);
+	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->device);
 	struct nouveau_hwmon *hwmon;
 	struct device *hwmon_dev;
 	int ret = 0;
@@ -662,6 +693,13 @@ nouveau_hwmon_init(struct drm_device *dev)
 			goto error;
 	}
 
+	if (iccsense && iccsense->rail_count) {
+		ret = sysfs_create_group(&hwmon_dev->kobj,
+					 &hwmon_power_attrgroup);
+		if (ret)
+			goto error;
+	}
+
 	hwmon->hwmon = hwmon_dev;
 
 	return 0;
@@ -688,6 +726,7 @@ nouveau_hwmon_fini(struct drm_device *dev)
 		sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_pwm_fan_attrgroup);
 		sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_fan_rpm_attrgroup);
 		sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_in0_attrgroup);
+		sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_power_attrgroup);
 
 		hwmon_device_unregister(hwmon->hwmon);
 	}
-- 
2.7.1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 5/6] hwmon: don't require therm to be valid to get any data
       [not found] ` <1455988299-2300-1-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
                     ` (3 preceding siblings ...)
  2016-02-20 17:11   ` [PATCH v4 4/6] hwmon: add power consumption Karol Herbst
@ 2016-02-20 17:11   ` Karol Herbst
       [not found]     ` <1455988299-2300-6-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
  2016-02-20 17:11   ` [PATCH v4 6/6] bios/extdev: also parse v4.1 table Karol Herbst
  5 siblings, 1 reply; 13+ messages in thread
From: Karol Herbst @ 2016-02-20 17:11 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Signed-off-by: Karol Herbst <nouveau@karolherbst.de>
---
 drm/nouveau/nouveau_hwmon.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/drm/nouveau/nouveau_hwmon.c b/drm/nouveau/nouveau_hwmon.c
index c4f77f5..a630192 100644
--- a/drm/nouveau/nouveau_hwmon.c
+++ b/drm/nouveau/nouveau_hwmon.c
@@ -643,9 +643,6 @@ nouveau_hwmon_init(struct drm_device *dev)
 		return -ENOMEM;
 	hwmon->dev = dev;
 
-	if (!therm || !therm->attr_get || !therm->attr_set)
-		return -ENODEV;
-
 	hwmon_dev = hwmon_device_register(&dev->pdev->dev);
 	if (IS_ERR(hwmon_dev)) {
 		ret = PTR_ERR(hwmon_dev);
@@ -659,26 +656,28 @@ nouveau_hwmon_init(struct drm_device *dev)
 	if (ret)
 		goto error;
 
-	/* if the card has a working thermal sensor */
-	if (nvkm_therm_temp_get(therm) >= 0) {
-		ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_temp_attrgroup);
-		if (ret)
-			goto error;
-	}
-
-	/* if the card has a pwm fan */
-	/*XXX: incorrect, need better detection for this, some boards have
-	 *     the gpio entries for pwm fan control even when there's no
-	 *     actual fan connected to it... therm table? */
-	if (therm->fan_get && therm->fan_get(therm) >= 0) {
-		ret = sysfs_create_group(&hwmon_dev->kobj,
-					 &hwmon_pwm_fan_attrgroup);
-		if (ret)
-			goto error;
+	if (therm && therm->attr_get && therm->attr_set) {
+		/* if the card has a working thermal sensor */
+		if (nvkm_therm_temp_get(therm) >= 0) {
+			ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_temp_attrgroup);
+			if (ret)
+				goto error;
+		}
+
+		/* if the card has a pwm fan */
+		/*XXX: incorrect, need better detection for this, some boards have
+		 *     the gpio entries for pwm fan control even when there's no
+		 *     actual fan connected to it... therm table? */
+		if (therm->fan_get && therm->fan_get(therm) >= 0) {
+			ret = sysfs_create_group(&hwmon_dev->kobj,
+						 &hwmon_pwm_fan_attrgroup);
+			if (ret)
+				goto error;
+		}
 	}
 
 	/* if the card can read the fan rpm */
-	if (nvkm_therm_fan_sense(therm) >= 0) {
+	if (therm && nvkm_therm_fan_sense(therm) >= 0) {
 		ret = sysfs_create_group(&hwmon_dev->kobj,
 					 &hwmon_fan_rpm_attrgroup);
 		if (ret)
-- 
2.7.1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 6/6] bios/extdev: also parse v4.1 table
       [not found] ` <1455988299-2300-1-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
                     ` (4 preceding siblings ...)
  2016-02-20 17:11   ` [PATCH v4 5/6] hwmon: don't require therm to be valid to get any data Karol Herbst
@ 2016-02-20 17:11   ` Karol Herbst
       [not found]     ` <1455988299-2300-7-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
  5 siblings, 1 reply; 13+ messages in thread
From: Karol Herbst @ 2016-02-20 17:11 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Signed-off-by: Karol Herbst <nouveau@karolherbst.de>
---
 drm/nouveau/nvkm/subdev/bios/extdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drm/nouveau/nvkm/subdev/bios/extdev.c b/drm/nouveau/nvkm/subdev/bios/extdev.c
index c9e6f6f..b857835 100644
--- a/drm/nouveau/nvkm/subdev/bios/extdev.c
+++ b/drm/nouveau/nvkm/subdev/bios/extdev.c
@@ -32,7 +32,7 @@ extdev_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *len, u8 *cnt)
 	u16 dcb, extdev = 0;
 
 	dcb = dcb_table(bios, &dcb_ver, &dcb_hdr, &dcb_cnt, &dcb_len);
-	if (!dcb || (dcb_ver != 0x30 && dcb_ver != 0x40))
+	if (!dcb || (dcb_ver != 0x30 && dcb_ver != 0x40 && dcb_ver != 0x41))
 		return 0x0000;
 
 	extdev = nvbios_rd16(bios, dcb + 18);
-- 
2.7.1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/6] subdev/iccsense: add new subdev for power sensors
       [not found]     ` <1455988299-2300-2-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
@ 2016-02-21 21:07       ` Martin Peres
  0 siblings, 0 replies; 13+ messages in thread
From: Martin Peres @ 2016-02-21 21:07 UTC (permalink / raw)
  To: Karol Herbst, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 20/02/16 19:11, Karol Herbst wrote:
> From: Martin Peres <martin.peres@free.fr>
>
> Signed-off-by: Karol Herbst <nouveau@karolherbst.de>
Reviewed-by: Martin Peres <martin.peres@free.fr>
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 2/6] nvbios/iccsense: add parsing of the SENSE table
       [not found]     ` <1455988299-2300-3-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
@ 2016-02-21 21:09       ` Martin Peres
  0 siblings, 0 replies; 13+ messages in thread
From: Martin Peres @ 2016-02-21 21:09 UTC (permalink / raw)
  To: Karol Herbst, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 20/02/16 19:11, Karol Herbst wrote:
> From: Martin Peres <martin.peres@free.fr>
>
> v4: don't kmalloc(0)
>
> Signed-off-by: Karol Herbst <nouveau@karolherbst.de>

Reviewed-by: Martin Peres <martin.peres@free.fr>
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 3/6] iccsense: implement for ina209, ina219 and ina3221
       [not found]     ` <1455988299-2300-4-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
@ 2016-02-21 21:21       ` Martin Peres
  0 siblings, 0 replies; 13+ messages in thread
From: Martin Peres @ 2016-02-21 21:21 UTC (permalink / raw)
  To: Karol Herbst, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 20/02/16 19:11, Karol Herbst wrote:
> based on Martins initial work
>
> v3: fix ina2x9 calculations
> v4: don't kmalloc(0), fix the lsb/pga stuff
>
> Signed-off-by: Karol Herbst <nouveau@karolherbst.de>
> ---
>   drm/nouveau/include/nvkm/subdev/bios/extdev.h |   3 +
>   drm/nouveau/include/nvkm/subdev/i2c.h         |  31 ++++++
>   drm/nouveau/include/nvkm/subdev/iccsense.h    |   5 +
>   drm/nouveau/nvkm/engine/device/base.c         |  20 ++++
>   drm/nouveau/nvkm/subdev/iccsense/Kbuild       |   1 +
>   drm/nouveau/nvkm/subdev/iccsense/base.c       | 150 +++++++++++++++++++++++++-
>   drm/nouveau/nvkm/subdev/iccsense/gf100.c      |  31 ++++++
>   drm/nouveau/nvkm/subdev/iccsense/priv.h       |   8 ++
>   8 files changed, 248 insertions(+), 1 deletion(-)
>   create mode 100644 drm/nouveau/nvkm/subdev/iccsense/gf100.c
>
> diff --git a/drm/nouveau/nvkm/subdev/iccsense/base.c b/drm/nouveau/nvkm/subdev/iccsense/base.c
> index 5dfa2fd..29c6641 100644
> --- a/drm/nouveau/nvkm/subdev/iccsense/base.c
> +++ b/drm/nouveau/nvkm/subdev/iccsense/base.c
> @@ -23,13 +23,161 @@
>    */
>   #include "priv.h"
>   
> -struct nvkm_subdev_func iccsense_func = { 0 };
> +#include <subdev/bios.h>
> +#include <subdev/bios/extdev.h>
> +#include <subdev/bios/iccsense.h>
> +#include <subdev/i2c.h>
> +
> +static int
> +nvkm_iccsense_poll_lane(struct i2c_adapter *i2c, u8 addr, u8 shunt_reg,
> +			u8 shunt_shift, u8 bus_reg, u8 bus_shift, u8 shunt,
> +			u16 lsb)
> +{
> +	int vbus, vshunt;
> +
> +	if (shunt == 0)
> +		return 0;
> +
> +	vshunt = nv_rd16i2cr(i2c, addr, shunt_reg);
> +	vbus = nv_rd16i2cr(i2c, addr, bus_reg);
> +
> +	if (vshunt < 0 || vbus < 0)
> +		return -EINVAL;
> +
> +	vshunt >>= shunt_shift;
> +	vbus >>= bus_shift;
> +
> +	return (vbus * vshunt * lsb) / shunt;
> +}
> +
> +static int
> +nvkm_iccsense_ina2x9_read(struct nvkm_iccsense *iccsense,
> +                          struct nvkm_iccsense_rail *rail,
> +			  u8 shunt_reg, u8 bus_reg)
> +{
> +	return nvkm_iccsense_poll_lane(rail->i2c, rail->addr, shunt_reg, 0,
> +				       bus_reg, 3, rail->mohm, 10 * 4);
> +}
> +
> +static int
> +nvkm_iccsense_ina209_read(struct nvkm_iccsense *iccsense,
> +			  struct nvkm_iccsense_rail *rail)
> +{
> +	return nvkm_iccsense_ina2x9_read(iccsense, rail, 3, 4);
> +}
> +
> +static int
> +nvkm_iccsense_ina219_read(struct nvkm_iccsense *iccsense,
> +			  struct nvkm_iccsense_rail *rail)
> +{
> +	return nvkm_iccsense_ina2x9_read(iccsense, rail, 1, 2);
> +}
> +
> +static int
> +nvkm_iccsense_ina3221_read(struct nvkm_iccsense *iccsense,
> +			   struct nvkm_iccsense_rail *rail)
> +{
> +	if (rail->rail >= 3)
> +		return -EINVAL;
> +
> +	return nvkm_iccsense_poll_lane(rail->i2c, rail->addr,
> +				       1 + (rail->rail * 2), 3,
> +				       2 + (rail->rail * 2), 3, rail->mohm,
> +				       40 * 8);
> +}
> +
> +int
> +nkvm_iccsense_read(struct nvkm_iccsense *iccsense, u8 idx)
> +{
> +	struct nvkm_iccsense_rail *rail;
> +
> +	if (!iccsense || idx >= iccsense->rail_count)
> +		return -EINVAL;
> +
> +	rail = &iccsense->rails[idx];
> +	if (!rail->read)
> +		return -ENODEV;
> +
> +	return rail->read(iccsense, rail);
> +}
> +
> +static void *
> +nvkm_iccsense_dtor(struct nvkm_subdev *subdev)
> +{
> +	struct nvkm_iccsense *iccsense = nvkm_iccsense(subdev);
> +
> +	if (iccsense->rails)
> +		kfree(iccsense->rails);
> +
> +	return iccsense;
> +}
> +
> +struct nvkm_subdev_func iccsense_func = {
> +	.dtor = nvkm_iccsense_dtor,
> +};
>   
>   int
>   nvkm_iccsense_ctor(struct nvkm_device *device, int index,
>   		   struct nvkm_iccsense *iccsense)
>   {
> +	struct nvkm_bios *bios;
> +	struct nvkm_i2c *i2c;
> +	struct nvbios_iccsense stbl;
> +	int i;
> +
>   	nvkm_subdev_ctor(&iccsense_func, device, index, 0, &iccsense->subdev);
> +	bios = device->bios;
> +	i2c = device->i2c;
> +
> +	if (!i2c || !bios || nvbios_iccsense_parse(bios, &stbl)
> +	    || !stbl.nr_entry)
I must say that this line is a bit ugly ... but meh!
> +		return 0;
> +
> +	iccsense->rails = kmalloc(sizeof(*iccsense->rails) * stbl.nr_entry,
> +	                          GFP_KERNEL);
> +	if (!iccsense->rails)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < stbl.nr_entry; ++i) {
> +		struct pwr_rail_t *r = &stbl.rail[i];
> +		struct nvbios_extdev_func extdev;
> +		struct nvkm_iccsense_rail *rail;
> +		struct nvkm_i2c_bus *i2c_bus;
> +
> +		if (!r->mode)
> +			continue;
> +
> +		if (nvbios_extdev_parse(bios, r->extdev_id, &extdev))
> +			continue;
> +
> +		if (extdev.bus)
> +			i2c_bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_SEC);
> +		else
> +			i2c_bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_PRI);
> +		if (!i2c_bus)
> +			continue;

Wow, this is great! Thanks, I always wondered how I would get the bus 
working
and it seems like you found a nice way.

> +
> +		rail = &iccsense->rails[iccsense->rail_count];
> +		switch (extdev.type) {
> +		case NVBIOS_EXTDEV_INA209:
> +			rail->read = nvkm_iccsense_ina209_read;
> +			break;
> +		case NVBIOS_EXTDEV_INA219:
> +			rail->read = nvkm_iccsense_ina219_read;
> +			break;
> +		case NVBIOS_EXTDEV_INA3221:
> +			rail->read = nvkm_iccsense_ina3221_read;
> +			break;
> +		default:

It would be nice to add a warning here that there is a new sensor type 
we do not know about yet. This is
especially since some rails may be covered by other devices which would 
be supported and an invalid power
reading would be present.

I would say that more than just displaying a warning, we should also 
change a boolean which would say how
trustful the reading is. This would be good when enabling or disabling 
the usage of boost clocks. Don't you think?

> +			continue;
> +		}
> +		rail->addr = extdev.addr >> 1;
> +		rail->rail = r->rail;
> +		rail->mohm = r->resistor_mohm;
> +		rail->i2c = &i2c_bus->i2c;
> +		++iccsense->rail_count;

There is no verification that the device is actually present. The extdev 
table is untrustful and I really wouldn't mind
more validation here :)

Other than that, nice work! I really like the design :)

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 4/6] hwmon: add power consumption
       [not found]     ` <1455988299-2300-5-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
@ 2016-02-21 21:23       ` Martin Peres
  0 siblings, 0 replies; 13+ messages in thread
From: Martin Peres @ 2016-02-21 21:23 UTC (permalink / raw)
  To: Karol Herbst, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW



On 20/02/16 19:11, Karol Herbst wrote:
> Signed-off-by: Karol Herbst <nouveau@karolherbst.de>
> ---
>   drm/nouveau/include/nvif/device.h |  1 +
>   drm/nouveau/nouveau_hwmon.c       | 39 +++++++++++++++++++++++++++++++++++++++
>   2 files changed, 40 insertions(+)
>
> diff --git a/drm/nouveau/include/nvif/device.h b/drm/nouveau/include/nvif/device.h
> index e0ed2f4..bcb9817 100644
> --- a/drm/nouveau/include/nvif/device.h
> +++ b/drm/nouveau/include/nvif/device.h
> @@ -62,6 +62,7 @@ u64  nvif_device_time(struct nvif_device *);
>   #define nvxx_gpio(a) nvxx_device(a)->gpio
>   #define nvxx_clk(a) nvxx_device(a)->clk
>   #define nvxx_i2c(a) nvxx_device(a)->i2c
> +#define nvxx_iccsense(a) nvxx_device(a)->iccsense
>   #define nvxx_therm(a) nvxx_device(a)->therm
>   #define nvxx_volt(a) nvxx_device(a)->volt
>   
> diff --git a/drm/nouveau/nouveau_hwmon.c b/drm/nouveau/nouveau_hwmon.c
> index 8e13467..c4f77f5 100644
> --- a/drm/nouveau/nouveau_hwmon.c
> +++ b/drm/nouveau/nouveau_hwmon.c
> @@ -34,6 +34,7 @@
>   #include "nouveau_drm.h"
>   #include "nouveau_hwmon.h"
>   
> +#include <nvkm/subdev/iccsense.h>
>   #include <nvkm/subdev/volt.h>
>   
>   #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
> @@ -543,6 +544,27 @@ nouveau_hwmon_get_in0_label(struct device *d,
>   static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO,
>   			  nouveau_hwmon_get_in0_label, NULL, 0);
>   
> +static ssize_t
> +nouveau_hwmon_get_power1_input(struct device *d, struct device_attribute *a,
> +			       char *buf)
> +{
> +	struct drm_device *dev = dev_get_drvdata(d);
> +	struct nouveau_drm *drm = nouveau_drm(dev);
> +	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->device);
> +	int result = 0, i;
> +
> +	for (i = 0; i < iccsense->rail_count; ++i) {
> +		int res = nkvm_iccsense_read(iccsense, i);
> +		if (res > 0)
> +			result += res;
> +	}
The code above should be moved to the icc_sense I would say, as we will 
likely need
to read the power from other places.

With such function added to the previous patch,
Reviewed-by: Martin Peres <martin.peres@free.fr>
> +
> +	return sprintf(buf, "%i\n", result);
> +}
> +
> +static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO,
> +			  nouveau_hwmon_get_power1_input, NULL, 0);
> +
>   static struct attribute *hwmon_default_attributes[] = {
>   	&sensor_dev_attr_name.dev_attr.attr,
>   	&sensor_dev_attr_update_rate.dev_attr.attr,
> @@ -579,6 +601,11 @@ static struct attribute *hwmon_in0_attributes[] = {
>   	NULL
>   };
>   
> +static struct attribute *hwmon_power_attributes[] = {
> +	&sensor_dev_attr_power1_input.dev_attr.attr,
> +	NULL
> +};
> +
>   static const struct attribute_group hwmon_default_attrgroup = {
>   	.attrs = hwmon_default_attributes,
>   };
> @@ -594,6 +621,9 @@ static const struct attribute_group hwmon_pwm_fan_attrgroup = {
>   static const struct attribute_group hwmon_in0_attrgroup = {
>   	.attrs = hwmon_in0_attributes,
>   };
> +static const struct attribute_group hwmon_power_attrgroup = {
> +	.attrs = hwmon_power_attributes,
> +};
>   #endif
>   
>   int
> @@ -603,6 +633,7 @@ nouveau_hwmon_init(struct drm_device *dev)
>   	struct nouveau_drm *drm = nouveau_drm(dev);
>   	struct nvkm_therm *therm = nvxx_therm(&drm->device);
>   	struct nvkm_volt *volt = nvxx_volt(&drm->device);
> +	struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->device);
>   	struct nouveau_hwmon *hwmon;
>   	struct device *hwmon_dev;
>   	int ret = 0;
> @@ -662,6 +693,13 @@ nouveau_hwmon_init(struct drm_device *dev)
>   			goto error;
>   	}
>   
> +	if (iccsense && iccsense->rail_count) {
> +		ret = sysfs_create_group(&hwmon_dev->kobj,
> +					 &hwmon_power_attrgroup);
> +		if (ret)
> +			goto error;
> +	}
> +
>   	hwmon->hwmon = hwmon_dev;
>   
>   	return 0;
> @@ -688,6 +726,7 @@ nouveau_hwmon_fini(struct drm_device *dev)
>   		sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_pwm_fan_attrgroup);
>   		sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_fan_rpm_attrgroup);
>   		sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_in0_attrgroup);
> +		sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_power_attrgroup);
>   
>   		hwmon_device_unregister(hwmon->hwmon);
>   	}

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 5/6] hwmon: don't require therm to be valid to get any data
       [not found]     ` <1455988299-2300-6-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
@ 2016-02-21 21:27       ` Martin Peres
  0 siblings, 0 replies; 13+ messages in thread
From: Martin Peres @ 2016-02-21 21:27 UTC (permalink / raw)
  To: Karol Herbst, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW


On 20/02/16 19:11, Karol Herbst wrote:
> Signed-off-by: Karol Herbst <nouveau@karolherbst.de>

Should never be an issue, but I get your point.

Reviewed-by: Martin Peres <martin.peres@free.fr>
> ---
>   drm/nouveau/nouveau_hwmon.c | 39 +++++++++++++++++++--------------------
>   1 file changed, 19 insertions(+), 20 deletions(-)
>
> diff --git a/drm/nouveau/nouveau_hwmon.c b/drm/nouveau/nouveau_hwmon.c
> index c4f77f5..a630192 100644
> --- a/drm/nouveau/nouveau_hwmon.c
> +++ b/drm/nouveau/nouveau_hwmon.c
> @@ -643,9 +643,6 @@ nouveau_hwmon_init(struct drm_device *dev)
>   		return -ENOMEM;
>   	hwmon->dev = dev;
>   
> -	if (!therm || !therm->attr_get || !therm->attr_set)
> -		return -ENODEV;
> -
>   	hwmon_dev = hwmon_device_register(&dev->pdev->dev);
>   	if (IS_ERR(hwmon_dev)) {
>   		ret = PTR_ERR(hwmon_dev);
> @@ -659,26 +656,28 @@ nouveau_hwmon_init(struct drm_device *dev)
>   	if (ret)
>   		goto error;
>   
> -	/* if the card has a working thermal sensor */
> -	if (nvkm_therm_temp_get(therm) >= 0) {
> -		ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_temp_attrgroup);
> -		if (ret)
> -			goto error;
> -	}
> -
> -	/* if the card has a pwm fan */
> -	/*XXX: incorrect, need better detection for this, some boards have
> -	 *     the gpio entries for pwm fan control even when there's no
> -	 *     actual fan connected to it... therm table? */
> -	if (therm->fan_get && therm->fan_get(therm) >= 0) {
> -		ret = sysfs_create_group(&hwmon_dev->kobj,
> -					 &hwmon_pwm_fan_attrgroup);
> -		if (ret)
> -			goto error;
> +	if (therm && therm->attr_get && therm->attr_set) {
> +		/* if the card has a working thermal sensor */
> +		if (nvkm_therm_temp_get(therm) >= 0) {
> +			ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_temp_attrgroup);
> +			if (ret)
> +				goto error;
> +		}
> +
> +		/* if the card has a pwm fan */
> +		/*XXX: incorrect, need better detection for this, some boards have
> +		 *     the gpio entries for pwm fan control even when there's no
> +		 *     actual fan connected to it... therm table? */
> +		if (therm->fan_get && therm->fan_get(therm) >= 0) {
> +			ret = sysfs_create_group(&hwmon_dev->kobj,
> +						 &hwmon_pwm_fan_attrgroup);
> +			if (ret)
> +				goto error;
> +		}
>   	}
>   
>   	/* if the card can read the fan rpm */
> -	if (nvkm_therm_fan_sense(therm) >= 0) {
> +	if (therm && nvkm_therm_fan_sense(therm) >= 0) {
>   		ret = sysfs_create_group(&hwmon_dev->kobj,
>   					 &hwmon_fan_rpm_attrgroup);
>   		if (ret)

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 6/6] bios/extdev: also parse v4.1 table
       [not found]     ` <1455988299-2300-7-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
@ 2016-02-21 21:28       ` Martin Peres
  0 siblings, 0 replies; 13+ messages in thread
From: Martin Peres @ 2016-02-21 21:28 UTC (permalink / raw)
  To: Karol Herbst, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 20/02/16 19:11, Karol Herbst wrote:
> Signed-off-by: Karol Herbst <nouveau@karolherbst.de>

Right, this is needed for my GM206. I have not looked into
the differences but the data made sense if parsed like v4.0.

Reviewed-by: Martin Peres <martin.peres@free.fr>
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-02-21 21:28 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-20 17:11 [PATCH v4 0/6] Suppor for various power sensors on GF100+ Karol Herbst
     [not found] ` <1455988299-2300-1-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
2016-02-20 17:11   ` [PATCH v4 1/6] subdev/iccsense: add new subdev for power sensors Karol Herbst
     [not found]     ` <1455988299-2300-2-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
2016-02-21 21:07       ` Martin Peres
2016-02-20 17:11   ` [PATCH v4 2/6] nvbios/iccsense: add parsing of the SENSE table Karol Herbst
     [not found]     ` <1455988299-2300-3-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
2016-02-21 21:09       ` Martin Peres
2016-02-20 17:11   ` [PATCH v4 3/6] iccsense: implement for ina209, ina219 and ina3221 Karol Herbst
     [not found]     ` <1455988299-2300-4-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
2016-02-21 21:21       ` Martin Peres
2016-02-20 17:11   ` [PATCH v4 4/6] hwmon: add power consumption Karol Herbst
     [not found]     ` <1455988299-2300-5-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
2016-02-21 21:23       ` Martin Peres
2016-02-20 17:11   ` [PATCH v4 5/6] hwmon: don't require therm to be valid to get any data Karol Herbst
     [not found]     ` <1455988299-2300-6-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
2016-02-21 21:27       ` Martin Peres
2016-02-20 17:11   ` [PATCH v4 6/6] bios/extdev: also parse v4.1 table Karol Herbst
     [not found]     ` <1455988299-2300-7-git-send-email-nouveau-lIBOoy2+GI7scQ4cX5LuPg@public.gmane.org>
2016-02-21 21:28       ` Martin Peres

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.