Skip to contentSkip to conversation

Medfield_Current_Monitoring_Driver

RFC In review Alan Cox 2 participants 2 messages Nov 29, 2010

Subsystems (3)
lore
Share & tools
lore

Alan Cox

author
#0 lore raw

RFC 1/1 Medfield_Current_Monitoring_Driver

Any views on the best way to approach this. It manages current overflow and draw - ie its not a power meter. One possibility is to put it in hwmon with some API tweaks as needed, but are there any analogous drivers or likely to be ? The other is to move it out of hwmon and into the x86 platform code and decide it's not an API/interface that can be usefully genericised.

My own preference is to make it a platform specific interface and leave it that way but I wanted to run it past the hwmon folk first.

Alan

From: Durgadoss R <[email protected]>

This is the Intel Medfield Current Monitoring Driver patch. The platform specific data required by the driver are provided by adding necessary code in arch/x86/platform/mrst/mrst.c

This driver monitors the platform current usage and handles interrupts when the configured current thresholds are crossed.
A detailed documentation for this, has been added in Documentation/hwmon/current_monitor.

---

 Documentation/hwmon/intel_over_current_detector |   86 +++
 arch/x86/platform/mrst/mrst.c                   |   39 +
 drivers/hwmon/Kconfig                           |    9 
 drivers/hwmon/Makefile                          |    1 
 drivers/hwmon/intel_mid_ocd.c                   |  647 +++++++++++++++++++++++
 5 files changed, 771 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/hwmon/intel_over_current_detector
 create mode 100644 drivers/hwmon/intel_mid_ocd.c
Documentation/hwmon/intel_over_current_detector new file +85 -0
new file mode 100644
index 0000000..d9483b0
@@ -0,0 +1,86 @@
+Kernel driver over current detection driver
+=====================+
+Supported systems:
+  * Intel Medfield Platform
+
+Author: Durgadoss R
+
+Description
+-----------
+
+This driver monitors the current drawn by the platform, and detects the
+peak current conditions. When the current drawn is more than the
+configured limit for a period of time (which is specified by a timer), an
+interrupt is generated. The current limit and the timer value can be
+configured at run time.
+
+The current thresholds aka BATTCURRENTLIMITS(BC) are of two types:
+	1.warning threshold(BC1)
+		at which the system should take actions to bring the
+		current consumption down.
+	2.shutdown threshold(BC2)
+		at which the hardware does a COLDOFF.
+
+The timer thresholds are of three types:
+	1.warning threshold(T1)
+		This corresponds to the first flag for time that the battery
+		current has been above BC1. An interrupt is generated to allow
+		software to correct the situation based on use-case.
+	2.hardware action threshold(T2)
+		This corresponds to the second flag for time that the battery
+		current has been above BC1. It signifies that the system
+		should control high current subsystems through hardware.
+		Besides a general interrupt, audio_volume_crush, vibra_disable
+		signals are sent.
+	3.shutdown threshold(T3)
+		This final flag signifies that when the system current exceeds
+		the threshold for more than T3, system should shutdown.
+
+Following table summarizes the exported sysfs files:
+
+bcu_status(RW)	     -  To enable/disable burst control unit.
+			0 - enables bcu, 1 - disables bcu.
+accumulation_time(RW)-  Time since last clearing/overflow of warning_count
+			in milli seconds. Writing 0 resets the acc_time and
+			also clears both the warning counters.
+warning_count(RO)    -  Two space seperated values that indicate the number
+			of times the current thresholds have been crossed.
+action_mask(RW)	     -  A hex value to enable/disable specific
+			actions taken when current violation happens.
+			bits [b4 b3 b2 b1 b0] control [a4 a3 a2 a1 a0] actions
+			respectively. a4 - camera output, a3 - sys burst,
+			a2 - SOC burst enable, a1 - vibra, a0 - audio output.
+			bits [b7 b6 b5] - Reserved.
+			Default value:08 (sys burst output is enabled).
+action_status(RO)    -  A hex value showing the status of actions taken
+			since the __last__ interrupt.
+			b7 - T3 violation
+			b6 - T2 violation
+			b5 - T1 violation
+			b4 - camera action taken status
+			b3 - sys burst disable action taken status
+			b2 - SOC burst disable action taken status
+			b1 - vibra disable
+			b0 - audio volume crush
+			A '1' in a bit position indicates that particular
+			action has been taken.
+current_warning(RW)  -  This gives the current(in mA) at which a warning is
+			generated. Range: 1400 to 4800. Default:3000
+current_shutdown(RW) -  This gives the current(in mA) at which system shutdown
+			is initiated. Range:1800 to 5800. Default:3800
+timer_warning(RW)    -  Time above current_warning limit at which interrupts
+			are trigerred(so that software can bring the current
+			consumption down). Values are in micro seconds.
+			Range:200 to 7700 in steps of 500
+timer_hw_action(RW)  -  Time above current_warning limit at which the system
+			is trigerred into hardware control to bring down the
+			current consumption. Values are in micro seconds.
+			Range:200 to 7700 in steps of 500
+timer_shutdown(RW)   -  Time above current_warning limit at which a hardware
+			shutdown event is trigerred. The timer values are in
+			micro seconds.
+			Range:1000 to 15000 in steps of 1000
+For all timer interfaces, tolerance shall be 5% maximum.
+All timers start running concurrently once current_warning/current_shutdown
+is crossed.
arch/x86/platform/mrst/mrst.c +28 -11
index 7ece498..6c62b6a 100644
@@ -389,6 +389,18 @@ struct devs_id {
 	void *(*get_platform_data)(void *info);
 };
 
+static void __init install_irq_resource(struct platform_device *pdev,
+							char *name, int irq)
+{
+	/* Single threaded */
+	static struct resource __initdata res = {
+		.flags = IORESOURCE_IRQ,
+	};
+	res.name = name;
+	res.start = irq;
+	platform_device_add_resources(pdev, &res, 1);
+}
+
 /* the offset for the mapping of global gpio pin to irq */
 #define MRST_IRQ_OFFSET 0x100
 
@@ -478,6 +490,20 @@ static void __init *emc1403_platform_data(void *info)
 	return &intr2nd_pdata;
 }
 
+static void __init *msic_ocd_platform_data(void *info)
+{
+	/* Platform Specific data for Current Monitoring Driver */
+	int gpio_base;
+	struct platform_device *pdev = (struct platform_device *)info;
+
+	gpio_base = get_gpio_by_name("msic_ocd");
+	if (gpio_base = -1)
+		return NULL;
+
+	install_irq_resource(pdev, "msic_ocd", gpio_base + MRST_IRQ_OFFSET);
+	return NULL;
+}
+
 static void __init *lis331dl_platform_data(void *info)
 {
 	static short intr2nd_pdata;
@@ -496,6 +522,7 @@ static void __init *lis331dl_platform_data(void *info)
 
 static const struct devs_id __initconst device_ids[] = {
 	{"pmic_gpio", SFI_DEV_TYPE_SPI, 1, &pmic_gpio_platform_data},
+	{"msic_ocd", SFI_DEV_TYPE_IPC, 1, &msic_ocd_platform_data},
 	{"spi_max3111", SFI_DEV_TYPE_SPI, 0, &max3111_platform_data},
 	{"i2c_max7315", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
 	{"i2c_max7315_2", SFI_DEV_TYPE_I2C, 1, &max7315_platform_data},
@@ -604,16 +631,6 @@ void intel_scu_devices_destroy(void)
 }
 EXPORT_SYMBOL_GPL(intel_scu_devices_destroy);
 
-static void __init install_irq_resource(struct platform_device *pdev, int irq)
-{
-	/* Single threaded */
-	static struct resource __initdata res = {
-		.name = "IRQ",
-		.flags = IORESOURCE_IRQ,
-	};
-	res.start = irq;
-	platform_device_add_resources(pdev, &res, 1);
-}
 
 static void __init sfi_handle_ipc_dev(struct platform_device *pdev)
 {
@@ -711,7 +728,7 @@ static int __init sfi_parse_devs(struct sfi_table_header *table)
 							pentry->name);
 				continue;
 			}
-			install_irq_resource(pdev, pentry->irq);
+			install_irq_resource(pdev, "IRQ", pentry->irq);
 			pr_debug("info[%2d]: IPC bus, name = %16.16s, "
 				"irq = 0x%2x\n", i, pentry->name, pentry->irq);
 			sfi_handle_ipc_dev(pdev);
drivers/hwmon/Kconfig +9 -0
index a56f6ad..e5bdf24 100644
@@ -1171,6 +1171,15 @@ config SENSORS_MC13783_ADC
         help
           Support for the A/D converter on MC13783 PMIC.
 
+config SENSORS_MID_CURRENT
+	tristate "Current monitoring driver for the Intel Medfield platform"
+	depends on INTEL_SCU_IPC
+	help
+	  Say Y here to enable the current monitoring driver on the Intel
+	  Medfield platform. This provides over-current and power
+	  monitoring on medfield devices. Say Y here if you have a Medfield
+	  based MID device, otherwise N.
+
 if ACPI
 
 comment "ACPI drivers"
drivers/hwmon/Makefile +1 -0
index 2479b3d..68f4c99 100644
@@ -85,6 +85,7 @@ obj-$(CONFIG_SENSORS_MAX1111)	+= max1111.o
 obj-$(CONFIG_SENSORS_MAX1619)	+= max1619.o
 obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
+obj-$(CONFIG_SENSORS_MID_CURRENT)+= intel_mid_ocd.o
 obj-$(CONFIG_SENSORS_PC87360)	+= pc87360.o
 obj-$(CONFIG_SENSORS_PC87427)	+= pc87427.o
 obj-$(CONFIG_SENSORS_PCF8591)	+= pcf8591.o
drivers/hwmon/intel_mid_ocd.c new file +643 -0

643 lines not on this page · raw message

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#1 lore raw
Quoted 11 lines · Alan Cox

Any views on the best way to approach this. It manages current overflow and draw - ie its not a power meter. One possibility is to put it in hwmon with some API tweaks as needed, but are there any analogous drivers or likely to be ? The other is to move it out of hwmon and into the x86 platform code and decide it's not an API/interface that can be usefully genericised.

My own preference is to make it a platform specific interface and leave it that way but I wanted to run it past the hwmon folk first.

Alan

Seems to be a lot of chip specific stuff. Actually, you don't define a single hwmon ABI attribute right now. So moving it to the x86 platform code might be a better option.

One possibility might be to move the driver to the x86 platform code, but add/use hwmon ABI attributes as much as possible, and register those attributes as hwmon device if CONFIG_HWMON is defined. Several other platform specific drivers already do the same.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors