help
Help
-----=D3=CA=BC=FE=D4=AD=BC=FE-----
=B7=A2=BC=FE=C8=CB: = [email protected] [mailto:[email protected]] = =B4=FA=B1=ED
[email protected]
=B7=A2=CB=CD=CA=B1=BC=E4: 2008=C4=EA1=D4=C28=C8=D5 14:59 =CA=D5=BC=FE=C8=CB: [email protected]
=D6=F7=CC=E2: Linuxppc-dev Digest, Vol 41, Issue 56
Send Linuxppc-dev mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://ozlabs.org/mailman/listinfo/linuxppc-dev
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific than "Re: Contents of Linuxppc-dev digest..."
Today's Topics:
1. Re: [PATCH] Fix remainder calculating bug in single floating
point division (Kumar Gala)
2. Re: [PATCH] Fix carry bug in 128-bit unsigned integer adding (Kumar Gala)
3. Re: [PATCH] Hwmon for Taco (Sean MacLennan)
4. Re: [PATCH] i2c-ibm_iic driver - new patch (Stephen Rothwell)
5. Re: [PATCH] Hwmon for Taco (Grant Likely)
----------------------------------------------------------------------
Message: 1
Date: Tue, 8 Jan 2008 00:22:25 -0600
From: Kumar Gala <[email protected]>
Subject: Re: [PATCH] Fix remainder calculating bug in single floating
point division
To: Liu Yu <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=3DUS-ASCII; format=3Dflowed; = delsp=3Dyes
Quoted 10 lines · Liu Yu
This bug exists in the emulation of floating point division for =20 powerpc.
The original code cannot count the remainder correctly. I can provide a test case to trigger this bug. When use fdiv to count 1.1754941e-38f / 0.9999999f, the result is expected to be 1.175494e-38f, but we will get 1.174921e-38f in the original case.
Comments are always welcomed!
can you provide the test case that shows the error.
- k
------------------------------
Message: 2
Date: Tue, 8 Jan 2008 00:27:59 -0600
From: Kumar Gala <[email protected]>
Subject: Re: [PATCH] Fix carry bug in 128-bit unsigned integer adding
To: Liu Yu <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=3DUS-ASCII; format=3Dflowed; = delsp=3Dyes
Quoted 8 lines · Liu Yu
This bug exists in math emulation for powerpc. The macro define are mainly used by multiplication.
When adding two unsigned operands ( r =3D x + y ),
the carry bit can be counted by whether r is less than x. However, when adding three unsigned operands, this method does not =20 work.
Quoted 4 lines
The original code below uses this method to count carry,
it apparently overlook the case of three operands.
Assume all the operands is 32-bit wide,
( r =3D x + y +last_carry, x =3D 0, y =3D0xffffffff,last_carry=3D =
1),
Quoted 5 lines
then r is no less than x but it actually gets a carry.
I tried to fix this bug, but this patch seems not that pretty. Are there any better ideas?
Comments are always welcomed!
take a look at how include/math-emu/op-4.h implements __FP_FRAC_ADD_4 =20 & __FP_FRAC_SUB_4. Will that fix the bug, if so we should make the =20 code match how its done there.
- k
------------------------------
Message: 3
Date: Tue, 08 Jan 2008 01:30:00 -0500
From: Sean MacLennan <[email protected]>
Subject: Re: [PATCH] Hwmon for Taco
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=3DISO-8859-1; format=3Dflowed
Quoted 6 lines · Benjamin Herrenschmidt
That should be in the device-tree...
Cheers,
Ben.=20
Now in the device tree. The name of the file has changed.
Cheers,
Sean
drivers/hwmon/Kconfig +0 -0
@@ -57,6 +57,16 @@ config SENSORS_ABITUGURU3 This driver can also be built as a module. If so, the module will be called abituguru3.
=20
+config SENSORS_AD7414
+ tristate "Analog Devices AD7414" + depends on I2C && EXPERIMENTAL + help
+ If you say yes here you get support for the Analog Devices
+ AD7414 temperature monitoring chip.
+
+ This driver can also be built as a module. If so, the module
+ will be called ad7414.
+
config SENSORS_AD7418
tristate "Analog Devices AD7416, AD7417 and AD7418"
depends on I2C && EXPERIMENTAL@@ -763,4 +773,13 @@ config HWMON_DEBUG_CHIP
a problem with I2C support and want to see more of what is going on.
=20
+config PIKA_DTM
+ tristate "PIKA DTM (Dynamic Thermal Management)" + depends on HWMON && WARP + select SENSORS_AD7414 + default y + help
+ Say Y here if you have a PIKA Warp(tm) Appliance. This driver is
+ required for the DTM to work properly.
+
endif # HWMON
drivers/hwmon/Makefile +0 -0
@@ -15,6 +15,7 @@ obj-$(CONFIG_SENSORS_W83791D) +=3D w83791d.o
=20
obj-$(CONFIG_SENSORS_ABITUGURU) +=3D abituguru.o
obj-$(CONFIG_SENSORS_ABITUGURU3)+=3D abituguru3.o
+obj-$(CONFIG_SENSORS_AD7414) +=3D ad7414.o
obj-$(CONFIG_SENSORS_AD7418) +=3D ad7418.o
obj-$(CONFIG_SENSORS_ADM1021) +=3D adm1021.o
obj-$(CONFIG_SENSORS_ADM1025) +=3D adm1025.o
@@ -69,7 +70,8 @@ obj-$(CONFIG_SENSORS_VT8231) +=3D vt8231.o
obj-$(CONFIG_SENSORS_W83627EHF) +=3D w83627ehf.o
obj-$(CONFIG_SENSORS_W83L785TS) +=3D w83l785ts.o
=20
+obj-$(CONFIG_PIKA_DTM) +=3D pika-dtm.o
+
ifeq ($(CONFIG_HWMON_DEBUG_CHIP),y) EXTRA_CFLAGS +=3D -DDEBUG
endif
-
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +10 -0
@@ -0,0 +1,87 @@ +/* + * drivers/hwmon/pika-dtm.c + * + * Overview: On the Warp, the fpga controls the fan. This provides + * the temperature to the fpga. + * + * Copyright (c) 2008 PIKA Technologies + * Sean MacLennan <[email protected]> + * + * This program is free software; you can redistribute it and/or=20
modify it
+ * under the terms of the GNU General Public License as=20
published by the
+ * Free Software Foundation; either version 2 of the License, or=20
(at your
+ * option) any later version.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/kthread.h>
+#include <linux/io.h>
+#include <linux/of_platform.h>
+
+
+extern int ad7414_get_temp(void);
+
+static unsigned __iomem *dtm_fpga;
+static struct task_struct *dtm_thread;
+
+
+static int pika_dtm_thread(void *arg)
+{
+ while(!kthread_should_stop()) {
+ int temp =3D ad7414_get_temp();
+
+ // Write to FPGA
+ out_be32(dtm_fpga, temp);
+
+ set_current_state(TASK_INTERRUPTIBLE);
+ schedule_timeout(HZ);
+ }
+
+ return 0;
+}
+
+
+int __init pika_dtm_init(void)
+{
+ struct device_node *np;
+ struct resource res;
+
+ if((np =3D of_find_compatible_node(NULL, NULL, "pika,fpga")) =3D=3D =
NULL) {
+ printk(KERN_ERR __FILE__ ": Unable to find FPGA\n");
+ return -ENOENT;
+ }
+
+ /* We do not call of_iomap here since it would map in the entire
+ * fpga space, which is overkill for 4 bytes.
+ */
+ if(of_address_to_resource(np, 0, &res) ||
+ (dtm_fpga =3D ioremap(res.start + 0x20, 4)) =3D=3D NULL) {
+ printk(KERN_ERR __FILE__ ": Unable to map FPGA\n");
+ return -ENOENT;
+ }
+
+ dtm_thread =3D kthread_run(pika_dtm_thread, NULL, "pika-dtm");
+
+ if(IS_ERR(dtm_thread)) {
+ iounmap(dtm_fpga);
+ printk(KERN_ERR __FILE__ ": Unable to start PIKA DTM =
thread\n");
+ return PTR_ERR(dtm_thread);
+ }
+
+ return 0;
+}
+module_init(pika_dtm_init);
+
+
+void __exit pika_dtm_exit(void)
+{
+ kthread_stop(dtm_thread);
+ iounmap(dtm_fpga);
+}
+module_exit(pika_dtm_exit);
+
+
+MODULE_DESCRIPTION("PIKA DTM driver");
+MODULE_AUTHOR("Sean MacLennan");
+MODULE_LICENSE("GPL");
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +7 -0
@@ -0,0 +1,296 @@ +/* + * An hwmon driver for the Analog Devices AD7414 + * + * Copyright 2006 Stefan Roese <[email protected]>, DENX Software Engineering + * + * Based on ad7418.c + * Copyright 2006 Tower Technologies, Alessandro Zummo=20
<[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/delay.h>
+
+
+#define DRV_VERSION "0.2"
+
+/* straight from the datasheet */
+#define AD7414_TEMP_MIN (-55000)
+#define AD7414_TEMP_MAX 125000
+
+/* Addresses to scan */
+static unsigned short normal_i2c[] =3D { 0x48, 0x4a, I2C_CLIENT_END }; +
+/* Insmod parameters */
+I2C_CLIENT_INSMOD;
+
+/* AD7414 registers */
+#define AD7414_REG_TEMP 0x00
+#define AD7414_REG_CONF 0x01
+#define AD7414_REG_T_HIGH 0x02
+#define AD7414_REG_T_LOW 0x03
+
+struct ad7414_data {
+ struct i2c_client client; + struct device *dev; + struct mutex lock; + char valid; /* !=3D0 if following fields are = valid */ + unsigned long last_updated; /* In jiffies */ + u16 temp_input; /* Register values */ + u8 temp_max; + u8 temp_min; + u8 temp_alert; + u8 temp_max_flag; + u8 temp_min_flag;
+};
+
+static int ad7414_attach_adapter(struct i2c_adapter *adapter); +static int ad7414_detect(struct i2c_adapter *adapter, int address, int=20 kind);
+static int ad7414_detach_client(struct i2c_client *client);
+
+static struct i2c_driver ad7414_driver =3D {
+ .driver =3D {
+ .name =3D "ad7414",
+ }, + .attach_adapter =3D ad7414_attach_adapter, + .detach_client =3D ad7414_detach_client,
+};
+
+/*
+ * TEMP: 0.001C/bit (-55C to +125C)
+ * REG: (0.5C/bit, two's complement) << 7
+ */
+static inline int AD7414_TEMP_FROM_REG(u16 reg)
+{
+ /* use integer division instead of equivalent right shift to
+ * guarantee arithmetic shift and preserve the sign
+ */
+ return ((s16)reg / 128) * 500;
+}
+
+/* All registers are word-sized, except for the configuration = registers.
+ * AD7414 uses a high-byte first convention, which is exactly opposite = to
+ * the usual practice.
+ */
+static int ad7414_read(struct i2c_client *client, u8 reg)
+{
+ if (reg =3D=3D AD7414_REG_TEMP)
+ return swab16(i2c_smbus_read_word_data(client, reg));
+ else
+ return i2c_smbus_read_byte_data(client, reg);
+}
+
+static int ad7414_write(struct i2c_client *client, u8 reg, u16 value) +{
+ return i2c_smbus_write_byte_data(client, reg, value);
+}
+
+/* PIKA Taco - we need to access the temperature in kernel mode. As a
+ * hack we store the device here. This works because we only have one
+ * ad7414 chip.
+ */
+static struct device *ad7414_dev;
+
+static void ad7414_init_client(struct i2c_client *client)
+{
+ /* TODO: anything to do here??? */
+ ad7414_dev =3D &client->dev;
+}
+
+static struct ad7414_data *ad7414_update_device(struct device *dev) +{
+ struct i2c_client *client =3D to_i2c_client(dev);
+ struct ad7414_data *data =3D i2c_get_clientdata(client);
+
+ mutex_lock(&data->lock);
+
+ if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+ || !data->valid) {
+ dev_dbg(&client->dev, "starting ad7414 update\n");
+
+ data->temp_input =3D ad7414_read(client, AD7414_REG_TEMP); + data->temp_alert =3D (data->temp_input >> 5) & 0x01; + data->temp_max_flag =3D (data->temp_input >> 4) & 0x01; + data->temp_min_flag =3D (data->temp_input >> 3) & 0x01; + data->temp_max =3D ad7414_read(client, AD7414_REG_T_HIGH); + data->temp_min =3D ad7414_read(client, AD7414_REG_T_LOW);
+
+ data->last_updated =3D jiffies;
+ data->valid =3D 1;
+ }
+
+ mutex_unlock(&data->lock);
+
+ return data;
+}
+
+int ad7414_get_temp(void)
+{
+ if(ad7414_dev) {
+ struct ad7414_data *data =3D ad7414_update_device(ad7414_dev);
+ return data->temp_input;
+ } else
+ return 0x1f4; // +125
+}
+EXPORT_SYMBOL(ad7414_get_temp);
+
+#define show(value) \
+static ssize_t show_##value(struct device *dev, struct device_attribute =
*attr, char *buf) \
+{ \
+ struct ad7414_data *data =3D ad7414_update_device(dev); \
+ return sprintf(buf, "%d\n", AD7414_TEMP_FROM_REG(data->value)); =
\
+}
+show(temp_input);
+
+#define show_8(value) \
+static ssize_t show_##value(struct device *dev, struct device_attribute =
*attr, char *buf) \
+{ \
+ struct ad7414_data *data =3D ad7414_update_device(dev); \
+ return sprintf(buf, "%d\n", data->value); \
+}
+show_8(temp_max);
+show_8(temp_min);
+show_8(temp_alert);
+show_8(temp_max_flag);
+show_8(temp_min_flag);
+
+#define set(value, reg) \
+static ssize_t set_##value(struct device *dev, struct device_attribute=20
*attr, const char *buf, size_t count) \
+{ \
+ struct i2c_client *client =3D to_i2c_client(dev); \ + struct ad7414_data *data =3D i2c_get_clientdata(client); \ + int temp =3D simple_strtoul(buf, NULL, 10); \ + \ + mutex_lock(&data->lock); \ + data->value =3D temp; \ + ad7414_write(client, reg, data->value); \ + mutex_unlock(&data->lock); \ + return count; \
+}
+set(temp_max, AD7414_REG_T_HIGH);
+set(temp_min, AD7414_REG_T_LOW);
+
+static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,=20 set_temp_max);
+static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min,=20 set_temp_min);
+static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input, NULL); +static DEVICE_ATTR(temp1_alert, S_IRUGO, show_temp_alert, NULL); +static DEVICE_ATTR(temp1_max_flag, S_IRUGO, show_temp_max_flag, NULL); +static DEVICE_ATTR(temp1_min_flag, S_IRUGO, show_temp_min_flag, NULL); +
+static int ad7414_attach_adapter(struct i2c_adapter *adapter) +{
+ if (!(adapter->class & I2C_CLASS_HWMON))
+ return 0;
+ return i2c_probe(adapter, &addr_data, ad7414_detect);
+}
+
+static struct attribute *ad7414_attributes[] =3D {
+ &dev_attr_temp1_input.attr, + &dev_attr_temp1_max.attr, + &dev_attr_temp1_min.attr, + &dev_attr_temp1_alert.attr, + &dev_attr_temp1_max_flag.attr, + &dev_attr_temp1_min_flag.attr, + NULL
+};
+
+static const struct attribute_group ad7414_group =3D {
+ .attrs =3D ad7414_attributes,
+};
+
+static int ad7414_detect(struct i2c_adapter *adapter, int address, int=20 kind)
+{
+ struct i2c_client *client; + struct ad7414_data *data; + int err =3D 0;
+
+ if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
+ I2C_FUNC_SMBUS_WORD_DATA))
+ goto exit;
+
+ if (!(data =3D kzalloc(sizeof(struct ad7414_data), GFP_KERNEL))) {
+ err =3D -ENOMEM;
+ goto exit;
+ }
+
+ client =3D &data->client; + client->addr =3D address; + client->adapter =3D adapter; + client->driver =3D &ad7414_driver; + client->flags =3D 0;
+
+ i2c_set_clientdata(client, data);
+
+ mutex_init(&data->lock);
+
+ /* TODO: not testing for AD7414 done yet... */
+
+ strlcpy(client->name, ad7414_driver.driver.name, I2C_NAME_SIZE);
+
+ if ((err =3D i2c_attach_client(client)))
+ goto exit_free;
+
+ dev_info(&client->dev, "chip found, driver version " DRV_VERSION =
"\n");
+
+ /* Initialize the AD7414 chip */
+ ad7414_init_client(client);
+
+ /* Register sysfs hooks */
+ if ((err =3D sysfs_create_group(&client->dev.kobj, &ad7414_group)))
+ goto exit_detach;
+
+ data->dev =3D hwmon_device_register(&client->dev);
+ if (IS_ERR(data->dev)) {
+ err =3D PTR_ERR(data->dev);
+ goto exit_remove;
+ }
+
+ return 0;
+
+exit_remove:
+ sysfs_remove_group(&client->dev.kobj, &ad7414_group);
+exit_detach:
+ i2c_detach_client(client);
+exit_free:
+ kfree(data);
+exit:
+ return err;
+}
+
+static int ad7414_detach_client(struct i2c_client *client) +{
+ struct ad7414_data *data =3D i2c_get_clientdata(client); + ad7414_dev =3D NULL; + hwmon_device_unregister(data->dev); + sysfs_remove_group(&client->dev.kobj, &ad7414_group); + i2c_detach_client(client); + kfree(data); + return 0;
+}
+
+static int __init ad7414_init(void)
+{
+ return i2c_add_driver(&ad7414_driver);
+}
+
+static void __exit ad7414_exit(void)
+{
+ i2c_del_driver(&ad7414_driver);
+}
+
+MODULE_AUTHOR("Stefan Roese <[email protected]>");
+MODULE_DESCRIPTION("AD7414 driver");
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRV_VERSION);
+
+module_init(ad7414_init);
+module_exit(ad7414_exit);
------------------------------
Message: 4
Date: Tue, 8 Jan 2008 17:36:36 +1100
From: Stephen Rothwell <[email protected]>
Subject: Re: [PATCH] i2c-ibm_iic driver - new patch
To: Sean MacLennan <[email protected]>
Cc: [email protected], Stefan Roese <[email protected]>, Arnd Bergmann
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=3D"us-ascii"
Quoted 4 lines · On Tue, 08 Jan 2008 00:56:27 -0500 Sean MacLennan = <[email protected]>…
Quoted 2 lines · Stephen Rothwell
On Mon, 07 Jan 2008 21:03:12 -0500 Sean MacLennan
Quoted 4 lines · <[email protected]> wrote:
Quoted 2 lines
=20
Please don't post patches as attachments.=20
Ok.
Unfortunately, you are using thunderbird and so the patch is now = wrapped.
There is a workaround, see Documentation/email-clients.txt.
Quoted 3 lines
Quoted 2 lines
Please split the assignments from the tests. Here and elsewhere.
=20I made the changes in my code. I am trying to leave the original code =
as=20
Quoted 1 line
much as possible.
Thats all we ask.
Quoted 11 lines
Quoted 11 lines
Review
Quoted 8 lines
(quoted diff) +7
-0+ } else { + if (dev->irq !=3D NO_IRQ){ + iic_interrupt_mode(dev, 0); + free_irq(dev->irq, dev); + } + iounmap(dev->vaddr); + kfree(dev); =20Should these last two be after the below brace?
Quoted 3 lines
Quoted 1 line
=20
I'm not really qualified to answer, but I will anyway ;) I assume the=20 original author is basically saying if he cannot delete the adapter, =
it=20
Quoted 3 lines
is unsafe to free the memory since the i2c code may still use it. If I =
have read that right, then I agree.
OK, I can see that this is a "that should not happen" condition.
Review
Quoted 3 lines
(quoted diff) +3
-0+ if (iic_force_poll) + dev->irq =3D NO_IRQ; + else if ((dev->irq =3D irq_of_parse_and_map(np, 0)) =3D=3D =
NO_IRQ)
You missed this one.
Overall looks better, except all your indentation is now 4 spaces. We = use
a TAB character for each level of indentation and you should be able to set your editor to *display* the TABs as 4 places if that is what you = like.
--=20
Cheers,
Stephen Rothwell [email protected]
http://www.canb.auug.org.au/~sfr/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url :
http://ozlabs.org/pipermail/linuxppc-dev/attachments/20080108/3c5fd612/at=
tac
hment-0001.pgp=20
------------------------------
Message: 5
Date: Mon, 7 Jan 2008 23:59:09 -0700
From: "Grant Likely" <[email protected]>
Subject: Re: [PATCH] Hwmon for Taco
To: "Sean MacLennan" <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=3DISO-8859-1
Quoted 22 lines · Sean MacLennan
drivers/hwmon/Kconfig +10
-0@@ -57,6 +57,16 @@ config SENSORS_ABITUGURU3 This driver can also be built as a module. If so, the module will be called abituguru3. +config SENSORS_AD7414 + tristate "Analog Devices AD7414" + depends on I2C && EXPERIMENTAL + help + If you say yes here you get support for the Analog Devices + AD7414 temperature monitoring chip. + + This driver can also be built as a module. If so, the module + will be called ad7414. + config SENSORS_AD7418 tristate "Analog Devices AD7416, AD7417 and AD7418" depends on I2C && EXPERIMENTAL
drivers/hwmon/Kconfig config HWMON_DEBUG_CHIP · line 773
Quoted 1 line
drivers/hwmon/Kconfig +0
-0@@ -763,4 +773,13 @@ config HWMON_DEBUG_CHIP a problem with I2C support and want to see more of what is =
going
drivers/hwmon/Kconfig config HWMON_DEBUG_CHIP · line 779
Quoted 6 lines
drivers/hwmon/Kconfig +4
-0on. +config PIKA_DTM + tristate "PIKA DTM (Dynamic Thermal Management)" + depends on HWMON && WARP + select SENSORS_AD7414
select is dangerous because it bypasses dependency checking. Make it 'depends on' instead.
drivers/hwmon/Kconfig config HWMON_DEBUG_CHIP · line 782
Quoted 3 lines
drivers/hwmon/Kconfig +3
-0+ default y + help + Say Y here if you have a PIKA Warp(tm) Appliance. This driver =
is
drivers/hwmon/Kconfig config HWMON_DEBUG_CHIP · line 784
Quoted 2 lines
drivers/hwmon/Kconfig +2
-0+ required for the DTM to work properly. +
This patch should be split in 2; one for the AD7414 driver and one for the thermal management driver.
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500
Quoted 25 lines
drivers/hwmon/Kconfig +0
-0endif # HWMONdrivers/hwmon/Makefile +3
-1@@ -15,6 +15,7 @@ obj-$(CONFIG_SENSORS_W83791D) +=3D w83791d.o obj-$(CONFIG_SENSORS_ABITUGURU) +=3D abituguru.o obj-$(CONFIG_SENSORS_ABITUGURU3)+=3D abituguru3.o +obj-$(CONFIG_SENSORS_AD7414) +=3D ad7414.o obj-$(CONFIG_SENSORS_AD7418) +=3D ad7418.o obj-$(CONFIG_SENSORS_ADM1021) +=3D adm1021.o obj-$(CONFIG_SENSORS_ADM1025) +=3D adm1025.o@@ -69,7 +70,8 @@ obj-$(CONFIG_SENSORS_VT8231) +=3D vt8231.o obj-$(CONFIG_SENSORS_W83627EHF) +=3D w83627ehf.o obj-$(CONFIG_SENSORS_W83L785TS) +=3D w83l785ts.o +obj-$(CONFIG_PIKA_DTM) +=3D pika-dtm.o + ifeq ($(CONFIG_HWMON_DEBUG_CHIP),y) EXTRA_CFLAGS +=3D -DDEBUG endif -hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +0
-0
This is *very* board specific and not very complex a driver. It should probably live with the platform code somewhere in arch/powerpc/platforms. You can use the machine_device_initcall() hook to kick off the thread.
Quoted 11 lines
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +10
-0@@ -0,0 +1,87 @@ +/* + * drivers/hwmon/pika-dtm.c + * + * Overview: On the Warp, the fpga controls the fan. This provides + * the temperature to the fpga. + * + * Copyright (c) 2008 PIKA Technologies + * Sean MacLennan <[email protected]> + * + * This program is free software; you can redistribute it and/or
Quoted 6 lines
modify it
+ * under the terms of the GNU General Public License as
published by the
+ * Free Software Foundation; either version 2 of the License, or
(at your
+ * option) any later version.
Your mailer chewed up the patch here (line wrap).
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500
Quoted 10 lines
+ *
+ */hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +8
-0+ +#include <linux/module.h> +#include <linux/kthread.h> +#include <linux/io.h> +#include <linux/of_platform.h> + + +extern int ad7414_get_temp(void);
Bad! Function decls must be in common header files.
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500
Quoted 11 lines
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +11
-0+ +static unsigned __iomem *dtm_fpga; +static struct task_struct *dtm_thread; + + +static int pika_dtm_thread(void *arg) +{ + while(!kthread_should_stop()) { + int temp =3D ad7414_get_temp(); + + // Write to FPGA
Style; use /* */, not //
Quoted 6 lines
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +6
-0+ out_be32(dtm_fpga, temp); + + set_current_state(TASK_INTERRUPTIBLE); + schedule_timeout(HZ); + } +
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500
Quoted 10 lines
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +10
-0+ return 0; +} + + +int __init pika_dtm_init(void) +{ + struct device_node *np; + struct resource res; + + if((np =3D of_find_compatible_node(NULL, NULL, "pika,fpga")) =
=3D=3D NULL) {
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500
Quoted 7 lines
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +7
-0+ printk(KERN_ERR __FILE__ ": Unable to find FPGA\n"); + return -ENOENT; + } + + /* We do not call of_iomap here since it would map in the entire + * fpga space, which is overkill for 4 bytes. + */
iomapping is not expensive; just map the whole space (it's going to map a minimum 4k page anyway). The code will be easier to read if you just use of_iomap().
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500
Quoted 11 lines
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +11
-0+ if(of_address_to_resource(np, 0, &res) || + (dtm_fpga =3D ioremap(res.start + 0x20, 4)) =3D=3D NULL) { + printk(KERN_ERR __FILE__ ": Unable to map FPGA\n"); + return -ENOENT; + } + + dtm_thread =3D kthread_run(pika_dtm_thread, NULL, "pika-dtm"); + + if(IS_ERR(dtm_thread)) { + iounmap(dtm_fpga); + printk(KERN_ERR __FILE__ ": Unable to start PIKA DTM =
thread\n");
Quoted 22 lines
hwmon/pika-dtm.c 2008-01-08 01:23:32.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +19
-0+ return PTR_ERR(dtm_thread); + } + + return 0; +} +module_init(pika_dtm_init); + + +void __exit pika_dtm_exit(void) +{ + kthread_stop(dtm_thread); + iounmap(dtm_fpga); +} +module_exit(pika_dtm_exit); + + +MODULE_DESCRIPTION("PIKA DTM driver"); +MODULE_AUTHOR("Sean MacLennan"); +MODULE_LICENSE("GPL");
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 line 4
Quoted 4 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +4
-0@@ -0,0 +1,296 @@ +/* + * An hwmon driver for the Analog Devices AD7414 + * + * Copyright 2006 Stefan Roese <[email protected]>, DENX Software =
Engineering
Quoted 6 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +3
-0+ * + * Based on ad7418.c + * Copyright 2006 Tower Technologies, Alessandro Zummo<[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or =
modify
Quoted 1 line
+ * it under the terms of the GNU General Public License as published =
by
Quoted 11 lines
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +8
-0+ +#include <linux/module.h> +#include <linux/jiffies.h> +#include <linux/i2c.h> +#include <linux/hwmon.h> +#include <linux/err.h> +#include <linux/mutex.h> +#include <linux/delay.h>
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500
Quoted 10 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +10
-0+ + +#define DRV_VERSION "0.2" + +/* straight from the datasheet */ +#define AD7414_TEMP_MIN (-55000) +#define AD7414_TEMP_MAX 125000 + +/* Addresses to scan */ +static unsigned short normal_i2c[] =3D { 0x48, 0x4a, I2C_CLIENT_END =
};
Quoted 5 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +5
-0+ +/* Insmod parameters */ +I2C_CLIENT_INSMOD; + +/* AD7414 registers */
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500
Quoted 10 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +10
-0+#define AD7414_REG_TEMP 0x00 +#define AD7414_REG_CONF 0x01 +#define AD7414_REG_T_HIGH 0x02 +#define AD7414_REG_T_LOW 0x03 + +struct ad7414_data { + struct i2c_client client; + struct device *dev; + struct mutex lock; + char valid; /* !=3D0 if following fields are =
valid */
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500
Quoted 11 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +11
-0+ unsigned long last_updated; /* In jiffies */ + u16 temp_input; /* Register values */ + u8 temp_max; + u8 temp_min; + u8 temp_alert; + u8 temp_max_flag; + u8 temp_min_flag; +}; + +static int ad7414_attach_adapter(struct i2c_adapter *adapter); +static int ad7414_detect(struct i2c_adapter *adapter, int address, =
int
Quoted 14 lines
kind);
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +13
-0+static int ad7414_detach_client(struct i2c_client *client); + +static struct i2c_driver ad7414_driver =3D { + .driver =3D { + .name =3D "ad7414", + }, + .attach_adapter =3D ad7414_attach_adapter, + .detach_client =3D ad7414_detach_client, +}; + +/* + * TEMP: 0.001C/bit (-55C to +125C) + * REG: (0.5C/bit, two's complement) << 7
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500
Quoted 10 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +10
-0+ */ +static inline int AD7414_TEMP_FROM_REG(u16 reg) +{ + /* use integer division instead of equivalent right shift to + * guarantee arithmetic shift and preserve the sign + */ + return ((s16)reg / 128) * 500; +} + +/* All registers are word-sized, except for the configuration =
registers.
Quoted 1 line
+ * AD7414 uses a high-byte first convention, which is exactly =
opposite to
Quoted 10 lines
+ * the usual practice.
+ */hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +8
-0+static int ad7414_read(struct i2c_client *client, u8 reg) +{ + if (reg =3D=3D AD7414_REG_TEMP) + return swab16(i2c_smbus_read_word_data(client, reg)); + else + return i2c_smbus_read_byte_data(client, reg); +} +
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500
Quoted 10 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +10
-0+static int ad7414_write(struct i2c_client *client, u8 reg, u16 value) +{ + return i2c_smbus_write_byte_data(client, reg, value); +} + +/* PIKA Taco - we need to access the temperature in kernel mode. As a + * hack we store the device here. This works because we only have one + * ad7414 chip. + */ +static struct device *ad7414_dev;
Can you use a list_head instead? That would allow multiple instances.
This driver shouldn't contain board specific code.
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500
Quoted 5 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +5
-0+ +static void ad7414_init_client(struct i2c_client *client) +{ + /* TODO: anything to do here??? */ + ad7414_dev =3D &client->dev;
ick.
Quoted 20 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +20
-0+} + +static struct ad7414_data *ad7414_update_device(struct device *dev) +{ + struct i2c_client *client =3D to_i2c_client(dev); + struct ad7414_data *data =3D i2c_get_clientdata(client); + + mutex_lock(&data->lock); + + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) + || !data->valid) { + dev_dbg(&client->dev, "starting ad7414 update\n"); + + data->temp_input =3D ad7414_read(client, AD7414_REG_TEMP); + data->temp_alert =3D (data->temp_input >> 5) & 0x01; + data->temp_max_flag =3D (data->temp_input >> 4) & 0x01; + data->temp_min_flag =3D (data->temp_input >> 3) & 0x01; + data->temp_max =3D ad7414_read(client, AD7414_REG_T_HIGH); + data->temp_min =3D ad7414_read(client, AD7414_REG_T_LOW); +
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500
Quoted 10 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +10
-0+ data->last_updated =3D jiffies; + data->valid =3D 1; + } + + mutex_unlock(&data->lock); + + return data; +} + +int ad7414_get_temp(void)
maybe ad7414_get_temp(int index)? Would allow for multiple instances.
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500
Quoted 3 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +3
-0+{ + if(ad7414_dev) { + struct ad7414_data *data =3D =
ad7414_update_device(ad7414_dev);
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500
Quoted 3 lines
hwmon/ad7414.c 2008-01-05 20:36:06.000000000 -0500 renamed from dev/null 2005-11-20 22:22:37.000000000 -0500 +3
-0+ return data->temp_input; + } else + return 0x1f4; // +125
Style; c++ comment
Cheers,
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
------------------------------
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev
End of Linuxppc-dev Digest, Vol 41, Issue 56
********************************************