Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Jan 2012 22:21:20 +0000 (UTC)
From:      Justin Hibbits <jhibbits@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r230035 - head/sys/powerpc/powermac
Message-ID:  <201201122221.q0CMLKqP029035@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhibbits
Date: Thu Jan 12 22:21:20 2012
New Revision: 230035
URL: http://svn.freebsd.org/changeset/base/230035

Log:
  Add PWM monitoring sysctl to G4 MDD (Windtunnel) fan driver.  While there, clean
  up some style nits.
  
  Approved by:	nwhitehorn (mentor)
  MFC after:	3 days

Modified:
  head/sys/powerpc/powermac/windtunnel.c

Modified: head/sys/powerpc/powermac/windtunnel.c
==============================================================================
--- head/sys/powerpc/powermac/windtunnel.c	Thu Jan 12 22:12:42 2012	(r230034)
+++ head/sys/powerpc/powermac/windtunnel.c	Thu Jan 12 22:21:20 2012	(r230035)
@@ -59,8 +59,7 @@ struct adm1030_softc {
 	device_t	sc_dev;
 	struct intr_config_hook enum_hook;
 	uint32_t	sc_addr;
-	phandle_t	sc_thermostat_phandle;
-	device_t	sc_thermostat_dev;
+	int		sc_pwm;
 };
 
 /* Regular bus attachment functions */
@@ -70,7 +69,8 @@ static int	adm1030_attach(device_t);
 /* Utility functions */
 static void	adm1030_start(void *xdev);
 static int	adm1030_write_byte(device_t dev, uint32_t addr, uint8_t reg, uint8_t buf);
-static int adm1030_set(struct adm1030_softc *fan, int pwm);
+static int	adm1030_set(struct adm1030_softc *fan, int pwm);
+static int	adm1030_sysctl(SYSCTL_HANDLER_ARGS);
 
 static device_method_t adm1030_methods[] = {
 	/* Device interface */
@@ -151,6 +151,8 @@ static int
 adm1030_attach(device_t dev)
 {
 	struct adm1030_softc *sc;
+	struct sysctl_ctx_list *ctx;
+	struct sysctl_oid *tree;
 
 	sc = device_get_softc(dev);
 
@@ -158,17 +160,19 @@ adm1030_attach(device_t dev)
 	sc->enum_hook.ich_arg = dev;
 
 	/*
-	 * We have to wait until interrupts are enabled. I2C read and write
-	 * only works if the interrupts are available. The unin/i2c is
-	 * controlled by the htpic on unin. But this is not the master. The
-	 * openpic on mac-io is controlling the htpic. This one gets attached
-	 * after the mac-io probing and then the interrupts will be
-	 * available.
+	 * Wait until interrupts are available, which won't be until the openpic is
+	 * intialized.
 	 */
 
 	if (config_intrhook_establish(&sc->enum_hook) != 0)
 		return (ENOMEM);
 
+	ctx = device_get_sysctl_ctx(dev);
+	tree = device_get_sysctl_tree(dev);
+	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "pwm",
+			CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev,
+			0, adm1030_sysctl, "I", "Fan PWM Rate");
+
 	return (0);
 }
 
@@ -188,7 +192,7 @@ adm1030_start(void *xdev)
 
 	/* Use the RPM fields as PWM duty cycles. */
 	sc->fan.min_rpm = 0;
-	sc->fan.max_rpm = 15;
+	sc->fan.max_rpm = 0x0F;
 	sc->fan.default_rpm = 2;
 
 	strcpy(sc->fan.name, "MDD Case fan");
@@ -211,6 +215,26 @@ static int adm1030_set(struct adm1030_so
 	if (adm1030_write_byte(fan->sc_dev, fan->sc_addr, 0x22, pwm) < 0)
 		return (-1);
 
+	fan->sc_pwm = pwm;
 	return (0);
 }
 
+static int
+adm1030_sysctl(SYSCTL_HANDLER_ARGS)
+{
+	device_t adm1030;
+	struct adm1030_softc *sc;
+	int pwm, error;
+
+	adm1030 = arg1;
+	sc = device_get_softc(adm1030);
+
+	pwm = sc->sc_pwm;
+
+	error = sysctl_handle_int(oidp, &pwm, 0, req);
+
+	if (error || !req->newptr)
+		return (error);
+
+	return (adm1030_set(sc, pwm));
+}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201201122221.q0CMLKqP029035>