w83627ehf.c (fde0950903ce8cc38a91dd095280decceda2ff82) w83627ehf.c (2d8672c5a6ba0d3f1d8d3ad61ef67868941364f0)
1/*
2 w83627ehf - Driver for the hardware monitoring functionality of
3 the Winbond W83627EHF Super-I/O chip
4 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
5
6 Shamelessly ripped from the w83627hf driver
7 Copyright (C) 2003 Mark Studebaker
8

--- 27 unchanged lines hidden (view full) ---

36 fan and temperature inputs. The chip does much more than that.
37*/
38
39#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/slab.h>
42#include <linux/i2c.h>
43#include <linux/i2c-isa.h>
1/*
2 w83627ehf - Driver for the hardware monitoring functionality of
3 the Winbond W83627EHF Super-I/O chip
4 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
5
6 Shamelessly ripped from the w83627hf driver
7 Copyright (C) 2003 Mark Studebaker
8

--- 27 unchanged lines hidden (view full) ---

36 fan and temperature inputs. The chip does much more than that.
37*/
38
39#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/slab.h>
42#include <linux/i2c.h>
43#include <linux/i2c-isa.h>
44#include <linux/i2c-sensor.h>
45#include <linux/hwmon.h>
46#include <linux/err.h>
47#include <asm/io.h>
48#include "lm75.h"
49
44#include <linux/hwmon.h>
45#include <linux/err.h>
46#include <asm/io.h>
47#include "lm75.h"
48
50/* Addresses to scan
51 The actual ISA address is read from Super-I/O configuration space */
52static unsigned short normal_i2c[] = { I2C_CLIENT_END };
53static unsigned int normal_isa[] = { 0, I2C_CLIENT_ISA_END };
49/* The actual ISA address is read from Super-I/O configuration space */
50static unsigned short address;
54
51
55/* Insmod parameters */
56SENSORS_INSMOD_1(w83627ehf);
57
58/*
59 * Super-I/O constants and functions
60 */
61
62static int REG; /* The register to read/write */
63static int VAL; /* The value to read/write */
64
65#define W83627EHF_LD_HWM 0x0b

--- 602 unchanged lines hidden (view full) ---

668 W83627EHF_REG_TEMP_CONFIG[i]);
669 if (tmp & 0x01)
670 w83627ehf_write_value(client,
671 W83627EHF_REG_TEMP_CONFIG[i],
672 tmp & 0xfe);
673 }
674}
675
52/*
53 * Super-I/O constants and functions
54 */
55
56static int REG; /* The register to read/write */
57static int VAL; /* The value to read/write */
58
59#define W83627EHF_LD_HWM 0x0b

--- 602 unchanged lines hidden (view full) ---

662 W83627EHF_REG_TEMP_CONFIG[i]);
663 if (tmp & 0x01)
664 w83627ehf_write_value(client,
665 W83627EHF_REG_TEMP_CONFIG[i],
666 tmp & 0xfe);
667 }
668}
669
676static int w83627ehf_detect(struct i2c_adapter *adapter, int address, int kind)
670static int w83627ehf_detect(struct i2c_adapter *adapter)
677{
678 struct i2c_client *client;
679 struct w83627ehf_data *data;
680 int i, err = 0;
681
671{
672 struct i2c_client *client;
673 struct w83627ehf_data *data;
674 int i, err = 0;
675
682 if (!i2c_is_isa_adapter(adapter))
683 return 0;
684
685 if (!request_region(address, REGION_LENGTH, w83627ehf_driver.name)) {
686 err = -EBUSY;
687 goto exit;
688 }
689
690 if (!(data = kmalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) {
691 err = -ENOMEM;
692 goto exit_release;

--- 78 unchanged lines hidden (view full) ---

771exit_free:
772 kfree(data);
773exit_release:
774 release_region(address, REGION_LENGTH);
775exit:
776 return err;
777}
778
676 if (!request_region(address, REGION_LENGTH, w83627ehf_driver.name)) {
677 err = -EBUSY;
678 goto exit;
679 }
680
681 if (!(data = kmalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) {
682 err = -ENOMEM;
683 goto exit_release;

--- 78 unchanged lines hidden (view full) ---

762exit_free:
763 kfree(data);
764exit_release:
765 release_region(address, REGION_LENGTH);
766exit:
767 return err;
768}
769
779static int w83627ehf_attach_adapter(struct i2c_adapter *adapter)
780{
781 if (!(adapter->class & I2C_CLASS_HWMON))
782 return 0;
783 return i2c_detect(adapter, &addr_data, w83627ehf_detect);
784}
785
786static int w83627ehf_detach_client(struct i2c_client *client)
787{
788 struct w83627ehf_data *data = i2c_get_clientdata(client);
789 int err;
790
791 hwmon_device_unregister(data->class_dev);
792
793 if ((err = i2c_detach_client(client))) {

--- 5 unchanged lines hidden (view full) ---

799 kfree(data);
800
801 return 0;
802}
803
804static struct i2c_driver w83627ehf_driver = {
805 .owner = THIS_MODULE,
806 .name = "w83627ehf",
770static int w83627ehf_detach_client(struct i2c_client *client)
771{
772 struct w83627ehf_data *data = i2c_get_clientdata(client);
773 int err;
774
775 hwmon_device_unregister(data->class_dev);
776
777 if ((err = i2c_detach_client(client))) {

--- 5 unchanged lines hidden (view full) ---

783 kfree(data);
784
785 return 0;
786}
787
788static struct i2c_driver w83627ehf_driver = {
789 .owner = THIS_MODULE,
790 .name = "w83627ehf",
807 .flags = I2C_DF_NOTIFY,
808 .attach_adapter = w83627ehf_attach_adapter,
791 .attach_adapter = w83627ehf_detect,
809 .detach_client = w83627ehf_detach_client,
810};
811
792 .detach_client = w83627ehf_detach_client,
793};
794
812static int __init w83627ehf_find(int sioaddr, int *address)
795static int __init w83627ehf_find(int sioaddr, unsigned short *addr)
813{
814 u16 val;
815
816 REG = sioaddr;
817 VAL = sioaddr + 1;
818 superio_enter();
819
820 val = (superio_inb(SIO_REG_DEVID) << 8)
821 | superio_inb(SIO_REG_DEVID + 1);
822 if ((val & SIO_ID_MASK) != SIO_W83627EHF_ID) {
823 superio_exit();
824 return -ENODEV;
825 }
826
827 superio_select(W83627EHF_LD_HWM);
828 val = (superio_inb(SIO_REG_ADDR) << 8)
829 | superio_inb(SIO_REG_ADDR + 1);
796{
797 u16 val;
798
799 REG = sioaddr;
800 VAL = sioaddr + 1;
801 superio_enter();
802
803 val = (superio_inb(SIO_REG_DEVID) << 8)
804 | superio_inb(SIO_REG_DEVID + 1);
805 if ((val & SIO_ID_MASK) != SIO_W83627EHF_ID) {
806 superio_exit();
807 return -ENODEV;
808 }
809
810 superio_select(W83627EHF_LD_HWM);
811 val = (superio_inb(SIO_REG_ADDR) << 8)
812 | superio_inb(SIO_REG_ADDR + 1);
830 *address = val & ~(REGION_LENGTH - 1);
831 if (*address == 0) {
813 *addr = val & ~(REGION_LENGTH - 1);
814 if (*addr == 0) {
832 superio_exit();
833 return -ENODEV;
834 }
835
836 /* Activate logical device if needed */
837 val = superio_inb(SIO_REG_ENABLE);
838 if (!(val & 0x01))
839 superio_outb(SIO_REG_ENABLE, val | 0x01);
840
841 superio_exit();
842 return 0;
843}
844
845static int __init sensors_w83627ehf_init(void)
846{
815 superio_exit();
816 return -ENODEV;
817 }
818
819 /* Activate logical device if needed */
820 val = superio_inb(SIO_REG_ENABLE);
821 if (!(val & 0x01))
822 superio_outb(SIO_REG_ENABLE, val | 0x01);
823
824 superio_exit();
825 return 0;
826}
827
828static int __init sensors_w83627ehf_init(void)
829{
847 if (w83627ehf_find(0x2e, &normal_isa[0])
848 && w83627ehf_find(0x4e, &normal_isa[0]))
830 if (w83627ehf_find(0x2e, &address)
831 && w83627ehf_find(0x4e, &address))
849 return -ENODEV;
850
851 return i2c_isa_add_driver(&w83627ehf_driver);
852}
853
854static void __exit sensors_w83627ehf_exit(void)
855{
856 i2c_isa_del_driver(&w83627ehf_driver);
857}
858
859MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
860MODULE_DESCRIPTION("W83627EHF driver");
861MODULE_LICENSE("GPL");
862
863module_init(sensors_w83627ehf_init);
864module_exit(sensors_w83627ehf_exit);
832 return -ENODEV;
833
834 return i2c_isa_add_driver(&w83627ehf_driver);
835}
836
837static void __exit sensors_w83627ehf_exit(void)
838{
839 i2c_isa_del_driver(&w83627ehf_driver);
840}
841
842MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
843MODULE_DESCRIPTION("W83627EHF driver");
844MODULE_LICENSE("GPL");
845
846module_init(sensors_w83627ehf_init);
847module_exit(sensors_w83627ehf_exit);