Skip to contentSkip to conversation

A bit different design for it's SuperIO.

PC87366 Evgeniy Polyakov 4 participants 11 messages May 19, 2005

lore
Share & tools
lore
#0 lore raw

Although lm_sensors already has driver for it's fan, voltage and temperature sensors, it does not have driver for is's GPIO, which allows anyone to create i2c and w1 adapters over it.
Design is simple as 5 pennies:

	SuperIO main driver
		|
+----+----+-----+-----+-----+---
|    |    |     |     |     |

Logical devices space...

Where each logical device may be registered and deregistered to/from main driver. Theoretically master device may have some kind of ioctl or any other communication mechanism with userspace/kernelspace which will allow any kind of slave manipulations.

Since you have "monitoring" driver already, I've created one only for GPIO.

Since I do not know where it should live(at my private trees it lives in drivers/w1/) I post here files itself.

Anyone using GNU/Arch may access it through public mirror at:
http://tservice.net.ru/~s0mbre/2004/ branch "soekris--main--0".

Please review and comment.

Signature · 38 lines
	Evgeniy Polyakov ( s0mbre )

Crash is better than data corruption. -- Art Grabowski
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: text/x-makefile
Size: 254 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040816/9a2f13db/Makefile.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sc.c
Type: text/x-csrc
Size: 8462 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040816/9a2f13db/sc.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sc_gpio.c
Type: text/x-csrc
Size: 4357 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040816/9a2f13db/sc_gpio.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sc_gpio.h
Type: text/x-chdr
Size: 1940 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040816/9a2f13db/sc_gpio-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sc.h
Type: text/x-chdr
Size: 2538 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040816/9a2f13db/sc-0001.bin
#1 lore raw
Quoted 8 lines · Jean Delvare

I haven't read the code (yet), just a few random comments on the general design:

1* The final driver definitely should be placed in a "common" location. It isn't i2c- nor w1-specific. It would be in drivers/isa but this one doesn't seem to exist... Maybe Greg will have a suggestion when he comes back from vacations.

Quoted 5 lines

2* If such a design is in place as I port the pc87360 driver to Linux 2.6, I'll of course use it. Note that this driver supports not only the PC87366 but also the PC87360, PC87363, PC87364 and PC87365 (although these are less frequently found, it seems) so your driver would have to support them all as well.

I do not have neither spec nor hardware for any SuperIO chips other than PC87366, so I can not say if they will fill itself comfortably in the new driver, but according to your driver they almost do not have any differences.
If they are really the same, then all is ok, and I can easily extend this driver to support different ID's and even registers. But I can not test it, I have only Soekris board (PC87366 based) provided by Alexander Yurchenko ([email protected]) for a while, Thanks :)

Quoted 8 lines

3* The Super-I/O mechanics are not PC8736x-specific. It is a standard (established by Intel some years ago) used by all Super-I/O chips, including those made by National Semiconductor, ITE, Winbond, SMSC and VIA. This means that your driver should most likely be completely generic, and probably doesn't even need to know of any chip ID. It could, OTOH, export an ID test function (although I guess it wouldn't be any different from the register read function with register set to 0x20).

Probably we need to call the testers, I will extend driver to support different ID's for now, but only for PC8736*.

Will send files soon.

Thank you.

Signature · 10 lines
	Evgeniy Polyakov ( s0mbre )

Crash is better than data corruption. -- Art Grabowski
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040817/20b0b936/attachment.bin
#2 lore raw
In reply to Evgeniy Polyakov
Quoted 8 lines · Jean Delvare

I haven't read the code (yet), just a few random comments on the general design:

1* The final driver definitely should be placed in a "common" location. It isn't i2c- nor w1-specific. It would be in drivers/isa but this one doesn't seem to exist... Maybe Greg will have a suggestion when he comes back from vacations.

Quoted 5 lines

2* If such a design is in place as I port the pc87360 driver to Linux 2.6, I'll of course use it. Note that this driver supports not only the PC87366 but also the PC87360, PC87363, PC87364 and PC87365 (although these are less frequently found, it seems) so your driver would have to support them all as well.

I do not have neither spec nor hardware for any SuperIO chips other than PC87366, so I can not say if they will fill itself comfortably in the new driver, but according to your driver they almost do not have any differences.
If they are really the same, then all is ok, and I can easily extend this driver to support different ID's and even registers. But I can not test it, I have only Soekris board (PC87366 based) provided by Alexander Yurchenko ([email protected]) for a while, Thanks :)

Quoted 8 lines

3* The Super-I/O mechanics are not PC8736x-specific. It is a standard (established by Intel some years ago) used by all Super-I/O chips, including those made by National Semiconductor, ITE, Winbond, SMSC and VIA. This means that your driver should most likely be completely generic, and probably doesn't even need to know of any chip ID. It could, OTOH, export an ID test function (although I guess it wouldn't be any different from the register read function with register set to 0x20).

Probably we need to call the testers, I will extend driver to support different ID's for now, but only for PC8736*.

Will send files soon.

Thank you.

Signature · 10 lines
	Evgeniy Polyakov ( s0mbre )

Crash is better than data corruption. -- Art Grabowski
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040817/ad14f396/attachment.bin
#3 lore raw
In reply to Evgeniy Polyakov
Quoted 18 lines · Jean Delvare
Quoted 9 lines
Quoted 3 lines
Quoted 1 line

#define SIO_LDN_GPIO 0x07 /* General-Purpose I/O (GPIO) Ports */

This is PC87366-specific and doesn't belong to that driver.

No, I think it just should be extended and include any other defines(for temperature, voltage and others). Although they may live in drivers for those logical devices. Driver for PC87366 may use it... I will move it there after it will be created (actually separated to support several main SuperIO chips at once).

I'm not sure I get everything you mean here (especially the last sentence). At any rate, the logical device usage is manufacturer-dependant and, in most cases, chip dependant. And when two different chips each have a logical device for, say, temperature monitoring, the way it is organized "inside" each logical device will be different. So there's no benefit in adding labels or classes to each logical device of each chip, since we will never be able to use them.

Quoted 9 lines

I insist that the superio driver should be mostly chip-independant. The only part which will not be is the Super-I/O enter sequence. Since the PC8736x chips don't need any, you may not be familiar with it. Most Super-I/O chips need a special sequence to be written to them before they activate. Since the superio driver won't know what it is looking for before it finds it, it'll probably have to test all known keys, then the client driver will ask not only for a given chip ID but for a key + chip ID pair. This also means that you will have to store the (variable length) key in the superio structure.

I'm absolutely agree here.
I mean above that when I will split sc.c into generic part and pc8736* part I will move those definitions into the header for pc8736* driver.

Hm, if I understood you correctly you propose following design:
each superio chip has it's own driver each of which can be connected to the main superio driver, but inside it will not have different logical devices, only one monolithic module which handles all them at once.

The main idea about logical devices was that we need a simple set of cubes(logical devices) and a table(superio chip's driver) and can create any set of functionality we need.

Logical device GPIO in SC1100 is very similar with PC87366 one. I even think that _any_ GPIO logical device in any SuperIO chip works only in following way:
pin_select();
read_value();

Where pin_select() is

	write(base + index_reg, pin_select_reg_number);
	read(base + data_reg);

So if we create logical device GPIO which will get from main driver(from main SuperIO module, which in turn will get it from chip specific driver(like pc87366, sc1100)) those registers it becomes to work.

Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

struct logical_dev
{
(...)

	int			(*activate)(void *);
	u8			(*read)(void *, int);
	void			(*write)(void *, int, u8);
	void			(*control)(void *, int, u8, u8);
};
Quoted 7 lines
Quoted 3 lines

Please give the function parameters names in your prototypes. Without them, the prototype is useless to us humans (although the compiler is perfectly happy without them).

Actually I always remove names from prototypes, since I think prototypes are needed not for detailed explanation of appropriate function but only for overall design view...

Quoted 6 lines

You probably miss the target then. In the above example, I can easily imagine what the activate, read and write member functions are for (left apart the fact that I wonder what the void * is for), but I just cannot guess what the control member function is for. Anonymous parameters don't help. At any rate, other kernel headers seem to include parameters names in their functions declarations.

->control() is for control logical device - one may enable/disable logical device, turn on/off additional functionality et cetera using this function.

I'm not insist on removing parameters name, I just do not understand why they are needed there. :)

Quoted 4 lines

While we're at it, I start wondering why you need these callback functions here. Is the client not supposed to just call sc_read_reg and sc_write_reg? I see nothing logical-device-dependent here.

If we want to use read or write function outside the superio module set, than we either need to know exact name( like xyz_my_pRiVaTtte_superIo_ChIp_rEaD()) or have to use following chain:
->superio->logical_dev->read().
Or something like that...
So superio module will export common logical device structure which have pointers to it's private functions and we may just call it. Example of such behaviour is timer function(sc_timer_func()) in sc.c - it is for testing and will definitely be removed.
External driver will get pointer to the logical device using sc_{get,put}_ldev();

Quoted 25 lines
Quoted 10 lines

sc_{add,del}_logical_dev() links and unlinks logical device from the main SuperIO module. After being added any logical device becomes visible for the external world, but it should be accessed only through main module using sc_{get,put}_ldev, which also increment/decrement is's usage counter and may implement additional functionality. When logical device is registered userspace can connect to it (actually it is the next step and will be implemented after ability to handle several main SuperIO logical modules) using either ioctl or netlink but again only through main module - with such approach we can control any data/control flow only in one place and do not disperse efforts.

What's the idea behind logical device registration? I don't see how this is needed. The reason why a superio driver is needed, as I understand it, is to handle concurrent accesses to 0x2E/0x2F. This means that all we really need is:

* Super-I/O detection.
* Read and write functions (specifying a logical device and a register)
* User-space interface to read and write.

Anything above that may be discussed but isn't strictly needed. I wouldn't mind shortcut functions for retrieving the logical device I/O address or activating the logical device, but these are really only read and write functions.

Quoted 4 lines

I don't even see the need of having a structure for logical devices.

Could you please explain what benefit your approach offers? I may be missing something.

As I described above we will not have code duplication and will have ability to add/remove logical devices in run-time.

Quoted 1 line

Greg, I much would like to hear you about this.

I think we will come to logical conclusion when he will back from vocation.
Or not.

``Quod erat demonstrandum'' wise latins would often say finishing discussion with a scuffle :)

Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

static int sc_activate_one_logical(struct sc_dev *dev, struct logical_dev *ldev)(...)
static void sc_activate_logical(struct sc_dev *dev)

I doubt that the second one will ever be needed. There's no point in arbitrary activating all logical devices at once, is there? Ditto for deactivating.

Now it even is not called from any place. It was usefull when all logical devices lived with main driver in one file and we registered all at once.

Quoted 6 lines

Registering is one thing (even if I don't much get the interest at this point), activating is one other. Registering is a software, lernel internal action. Activating may have hardware consequences. If the functions are really about registering, they should be renamed. If they are about activating, then doing this on all logical devices at once doesn't make any sense and a function that does so shouldn't even exist.

Those function was used after all devices were logically registered and then all we "hardware" activated.
In old version they were at one place and it was more convenient to register them all at once and then to activate them all at once.

You right that it is deprecated now and not needed. I just explain why it was there.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

base+size is really base+size-1. And actually size could go away and it would be base+1. Again, it's standard. I wouldn't even print it as"0x%x/0x%x". Super-I/O have a couple addresses by nature, not an I/O range (although this translates into a 2-address range in the end).

Quoted 8 lines
Quoted 3 lines

Sure, it should be base+size-1, but if it is not PC8736* but for example SC1100 we must request more than 2 bytes at a time, because of such chips I've added size parameter.

If the SC1100 does live at different addresses and uses a different number of I/O ports, I start wondering the point in having a common driver. What are the common points between regular Super-I/O chips and the SC1100? Care to explain how the SC1100 works?

sc1100 is a system-on-chip processor which has integrated superio system.
Although AMD did not gave me spec(it's theirs fault), I have documentation.
SuperIO chip there contains serial port, IR port, RTC, system wakeup control and two AccessBUSes.
Although GPIO does not live in SuperIO module but in Core Logic module it will enter into design quite good.

Quoted 2 lines

Thanks.

Signature · 10 lines
	Evgeniy Polyakov ( s0mbre )

Crash is better than data corruption. -- Art Grabowski
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040823/c756b448/attachment.bin
#4 lore raw
In reply to Evgeniy Polyakov
Quoted 20 lines

Although lm_sensors already has driver for it's fan, voltage and temperature sensors, it does not have driver for is's GPIO, which allows anyone to create i2c and w1 adapters over it. Design is simple as 5 pennies:

	SuperIO main driver
		|
+----+----+-----+-----+-----+---
|    |    |     |     |     |

Logical devices space...

Where each logical device may be registered and deregistered to/from main driver. Theoretically master device may have some kind of ioctl or any other communication mechanism with userspace/kernelspace which will allow any kind of slave manipulations.

Since you have "monitoring" driver already, I've created one only for GPIO.

Quoted 7 lines

Since I do not know where it should live(at my private trees it lives in drivers/w1/) I post here files itself.

Anyone using GNU/Arch may access it through public mirror at:
http://tservice.net.ru/~s0mbre/2004/ branch "soekris--main--0".

Please review and comment.

I haven't read the code (yet), just a few random comments on the general design:

1* The final driver definitely should be placed in a "common" location. It isn't i2c- nor w1-specific. It would be in drivers/isa but this one doesn't seem to exist... Maybe Greg will have a suggestion when he comes back from vacations.

2* If such a design is in place as I port the pc87360 driver to Linux 2.6, I'll of course use it. Note that this driver supports not only the PC87366 but also the PC87360, PC87363, PC87364 and PC87365 (although these are less frequently found, it seems) so your driver would have to support them all as well.

3* The Super-I/O mechanics are not PC8736x-specific. It is a standard (established by Intel some years ago) used by all Super-I/O chips, including those made by National Semiconductor, ITE, Winbond, SMSC and VIA. This means that your driver should most likely be completely generic, and probably doesn't even need to know of any chip ID. It could, OTOH, export an ID test function (although I guess it wouldn't be any different from the register read function with register set to 0x20).

Signature · 2 lines
Jean "Khali" Delvare
http://khali.linux-fr.org/
#5 lore raw
In reply to Evgeniy Polyakov
Quoted 9 lines · On Tue, 17 Aug 2004 14:33:01 +0400 Evgeniy Polyakov <[email protected]> wrote:
Quoted 8 lines

3* The Super-I/O mechanics are not PC8736x-specific. It is a standard(established by Intel some years ago) used by all Super-I/O chips, including those made by National Semiconductor, ITE, Winbond, SMSC and VIA. This means that your driver should most likely be completely generic, and probably doesn't even need to know of any chip ID. It could, OTOH, export an ID test function (although I guess it wouldn't be any different from the register read function with register set to 0x20).

Quoted 4 lines

Probably we need to call the testers, I will extend driver to support different ID's for now, but only for PC8736*.

Will send files soon.

Done.
dmesg:
Soekris SuperIO driver is starting...
Found PC87366 [0xe9] at 0x002e-0x0030.
GPIO logical device driver is activating now.

                    GPIO - activated: 0x6600-0x6610, irq [type]

As before one can access GNU/Arch archive at
http://tservice.net.ru/~s0mbre/2004 branch soekris--main--0.

Please review and comment.
Thank you.

Differences from previous set include:

# do not edit -- automatically generated by arch changelog
# arch-tag:
[email protected]/soekris--main--0#
2004-08-18 17:55:04 GMT Evgeniy Polyakov <[email protected]>  patch-15

Summary:
Added run-time SuperIO chip identification.
Revision:
soekris--main--0--patch-15

Added run-time SuperIO chip identifications.
Now differend PC8736* are supported.

modified files:
sc.c sc.h

2004-08-18 17:35:57 GMT Evgeniy Polyakov <[email protected]>  patch-14

Summary:
Added sc_w1.c - w1 master over PC87366 GPIO pins.
Revision:
soekris--main--0--patch-14

Added sc_w1.c - w1 master over PC87366 GPIO pins.

new files:
.arch-ids/sc_w1.c.id sc_w1.c

modified files:
Makefile

2004-08-18 17:35:02 GMT Evgeniy Polyakov <[email protected]>  patch-13

Summary:
Experiments with GPIO pin states and masks. Added control calling
into read/write functions. Revision:
soekris--main--0--patch-13

Experiments with GPIO pin states and masks.
GPIO_PIN_OPENDRAIN | GPIO_PIN_PUSHPULL - can blink.

Added control calling into read/write functions.
Need for ability to read from line just after writing to it -
useful for i2c and w1 emulation.

modified files:
sc_gpio.c

2004-08-18 17:32:35 GMT Evgeniy Polyakov <[email protected]>  patch-12

Summary:
Removed timer insertion, do not remove logical device if refcnt !0, added sc_{get,put}_ldev, do not use port read/write operations with
delay(*_p). Revision:
soekris--main--0--patch-12

Removed timer insertion.
Do not remove logical device if refcnt != 0. Added sc_{get,put}_ldev.
Do not use port read/write operations with delay(*_p).

Added pin_num module parameter for sc.c - selects pin to work with. Removed unneded and commented debug.

modified files:
sc.c sc.h

Evgeniy Polyakov ( s0mbre )

Only failure makes us experts. -- Theo de Raadt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sc.c
Type: text/x-csrc
Size: 9056 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040818/95e65e9b/sc.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sc.h
Type: text/x-chdr
Size: 2689 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040818/95e65e9b/sc-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sc_gpio.c
Type: text/x-csrc
Size: 4574 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040818/95e65e9b/sc_gpio.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sc_gpio.h
Type: text/x-chdr
Size: 1940 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040818/95e65e9b/sc_gpio-0001.bin

#6 lore raw
In reply to Evgeniy Polyakov
Quoted 22 lines · On Wed, 18 Aug 2004 22:10:21 +0400 Evgeniy Polyakov <[email protected]> wrote:
Quoted 9 lines · On Tue, 17 Aug 2004 14:33:01 +0400 Evgeniy Polyakov <[email protected]> wrote:
Quoted 8 lines

3* The Super-I/O mechanics are not PC8736x-specific. It is a standard(established by Intel some years ago) used by all Super-I/O chips, including those made by National Semiconductor, ITE, Winbond, SMSC and VIA. This means that your driver should most likely be completely generic, and probably doesn't even need to know of any chip ID. It could, OTOH, export an ID test function (although I guess it wouldn't be any different from the register read function with register set to 0x20).

Quoted 4 lines

Probably we need to call the testers, I will extend driver to support different ID's for now, but only for PC8736*.

Will send files soon.

Done.
dmesg:
Soekris SuperIO driver is starting...
Found PC87366 [0xe9] at 0x002e-0x0030.
GPIO logical device driver is activating now.

Quoted 6 lines
                    GPIO - activated: 0x6600-0x6610, irq [type]

As before one can access GNU/Arch archive at
http://tservice.net.ru/~s0mbre/2004 branch soekris--main--0.

Please review and comment.

BTW, If someone really want to use this then it requires following patch(also attached):

s0mbre@zanzibar:~/aWork/soekris$ tla cat-log
patch-16 Revision: soekris--main--0--patch-16
Archive: [email protected]
Creator: Evgeniy Polyakov <[email protected]>
Date: Thu Aug 19 00:54:56 MSD 2004
Standard-date: 2004-08-18 20:54:56 GMT
Modified-files: sc_gpio.c
New-patches: [email protected]/soekris--main--0--patch-16
Summary: Fixed read bug - we must read from GPIO INPUT register, not
OUTPUT. Control manipulations in ->activate(). 
Keywords:

Fixed read bug - we must read from GPIO INPUT register, not OUTPUT. Control manipulations in ->activate().

sc_gpio.c +2 -3
@@ -68,13 +68,14 @@
 
 	for (i=0; i<SIO_GPIO_NPINS; ++i)
 	{
-		gpin[i].flags = GPIO_PIN_OPENDRAIN | GPIO_PIN_PUSHPULL;
-		//gpin[i].flags = GPIO_PIN_OPENDRAIN;
-		gpin[i].state = GPIO_PIN_HIGH;
+		//gpin[i].flags = GPIO_PIN_OPENDRAIN | GPIO_PIN_PUSHPULL;
+		gpin[i].flags = GPIO_PIN_TRISTATE;
 		gpin[i].mask &= ~(SIO_GPIO_CONF_OUTPUTEN |

SIO_GPIO_CONF_PUSHPULL | SIO_GPIO_CONF_PULLUP |
SIO_GPIO_CONF_DEBOUNCE);
sc_gpio_control(ldev, i, gpin[i].mask, gpin[i].flags);
+
+ gpin[i].state = GPIO_PIN_HIGH;
sc_gpio_write(ldev, i, gpin[i].state);
}

@@ -93,16 +94,16 @@
switch (port)
{
case 0:
- reg = SIO_GPDO0;
+ reg = SIO_GPDI0;
break;
case 1:
- reg = SIO_GPDO1;
+ reg = SIO_GPDI1;
break;
case 2:
- reg = SIO_GPDO2;
+ reg = SIO_GPDI2;
break;
case 3:
- reg = SIO_GPDO3;
+ reg = SIO_GPDI3;
break;
}

Evgeniy Polyakov ( s0mbre )

Only failure makes us experts. -- Theo de Raadt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sc_gpio.c.patch
Type: application/octet-stream
Size: 908 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040819/cb9bef53/sc_gpio.c.obj

#7 lore raw
In reply to Evgeniy Polyakov

Hi Evgeniy,

Here are my comments on your code. I'll only comment on the Super-I/O part, since I don't know much (and don't really care) about the GPIO driver.

First question, why the name "sc"? We'll have to find a more suitable name for the driver. What about simply "superio"?

### sc.h

Quoted 1 line

#define SIO_LDN_GPIO 0x07 /* General-Purpose I/O (GPIO) Ports */

This is PC87366-specific and doesn't belong to that driver.

Quoted 3 lines

#define SIO_ACTIVE_EN 0x01 /* enabled */
(...)
#define LDEV_ACTIVE (1<<0)

Aren't these the same thing?

Quoted 4 lines

#define SIO_GPDO0 0x00
#define SIO_GPDI0 0x01
#define SIO_GPEVEN0 0x02
#define SIO_GPEVST0 0x03

Quoted 8 lines

#define SIO_GPDO1 0x04
#define SIO_GPDI1 0x05
#define SIO_GPEVEN1 0x06
#define SIO_GPEVST1 0x07
#define SIO_GPDO2 0x08
#define SIO_GPDI2 0x09
#define SIO_GPDO3 0x0A
#define SIO_GPDI3 0x0B

Same here, PC87366-specific (I believe) so doesn't belong to that driver.

Quoted 8 lines

struct logical_dev
{
(...)

	int			(*activate)(void *);
	u8			(*read)(void *, int);
	void			(*write)(void *, int, u8);
	void			(*control)(void *, int, u8, u8);
};

Please give the function parameters names in your prototypes. Without them, the prototype is useless to us humans (although the compiler is perfectly happy without them).

Quoted 7 lines

void sc_write_reg(struct sc_dev *, u8, u8); u8 sc_read_reg(struct sc_dev *, u8);

int sc_add_logical_dev(struct logical_dev *); void sc_del_logical_dev(struct logical_dev *); struct logical_dev *sc_get_ldev(char *); void sc_put_ldev(struct logical_dev *);

Ditto.

At this point, I'd appreciate a detailed explanation of your choices of implementation. It looks rather complex to me so the choices are not that obvious. I'd simply have provided read and write functions, keeping things really simple and low level, while it looks like you intend to implement the concept of logical device registration. Why is it needed? How is it going to work?

Please explain what the 6 functions are meant for, and how the three different structures will be used.

### sc.c

Quoted 14 lines

#include <asm/atomic.h>
#include <asm/types.h>
#include <asm/io.h>

#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/list.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/timer.h>
#include <linux/slab.h>
#include <linux/timer.h>

Quoted 6 lines

#include "../w1/w1.h"
#include "../w1/w1_int.h"
#include "../w1/w1_log.h"

#include "sc.h"
#include "sc_gpio.h"

Wow. I doubt you need all that. At any rate, you should not include any device-specific or protocol-specific header here. There's no reason you would need them. The superio driver offers an interface to the other drivers, not the other way around.

Quoted 5 lines

void sc_write_reg(struct sc_dev *, u8, u8); u8 sc_read_reg(struct sc_dev *, u8);

int sc_add_logical_dev(struct logical_dev *); void sc_del_logical_dev(struct logical_dev *);

These are already defined in the .h file.

Quoted 3 lines

static int sc_activate_one_logical(struct sc_dev *dev, struct logical_dev *ldev) (...)
static void sc_activate_logical(struct sc_dev *dev)

I doubt that the second one will ever be needed. There's no point in arbitrary activating all logical devices at once, is there? Ditto for deactivating.

Quoted 1 line

static int sc_chip_id(u8 id)

This one is supposed to convert an id into an index, isn't it? It would better be called sc_chip_index then.

Quoted 27 lines

static int sc_find_device(struct sc_dev *dev, unsigned long __base)

{
	unsigned long base;
	unsigned long size = 2;
	int i, sz;

	if (__base)
	{
		base = __base;
		sz = 1;
	}
	else
	{
		base = 0; /* Make compiler happy */
		sz = sizeof(base_addr)/sizeof(base_addr[0]);
	}
	
	for (i=0; i<sz; ++i)
	{
		u8 id;
		int chip_num;
		
		if (!__base)
			base = base_addr[i];

		dev->base_index = base;
		dev->base_data = base + 1;
Quoted 1 line

(...)

You handling of base is complex without a reason. If __base is set, do
base_addr[0] = __base and sz = 1. If it isn't, sz sizeof(base_addr)/sizeof(base_addr[0]) (unchanged). Then you don't have to care about it in the for loop:

static int sc_find_device(struct sc_dev *dev, unsigned long base)

{
	unsigned long size = 2;
	int i, sz;

	if (base)
	{
		base_addr[0] = base;
		sz = 1;
	}
	else
	{
		sz = sizeof(base_addr)/sizeof(base_addr[0]);
	}
	
	for (i=0; i<sz; ++i)
	{
		u8 id;
		int chip_num;
		
		dev->base_index = base_addr[i];
		dev->base_data = base_addr[i] + 1;

How about it?

BTW, I see no reason why you would want to force the base address. The possible addresses are standardized (0x2e/0x2f and 0x4e/0x4f), 99% of the case the super I/O is at 0x2e/0x2f. So I wouldn't even bother with that parameter.

Quoted 9 lines
		if (chip_num >= 0)
		{
			printk(KERN_INFO "Found %s [0x%x] at 0x%04lx-0x%04lx.\n", 
					sc_sio_ids[chip_num].name, sc_sio_ids[chip_num].id, 
					base, base+size);
			return i;
		}

		printk(KERN_INFO "Found nothing at 0x%04lx-0x%04lx.\n", base, base+size);

base+size is really base+size-1. And actually size could go away and it would be base+1. Again, it's standard. I wouldn't even print it as "0x%x/0x%x". Super-I/O have a couple addresses by nature, not an I/O range (although this translates into a 2-address range in the end).

I also see that your function wouldn't support a system with two similar Super-I/Os at different addresses. I admit it was never seen and will probably never be, but since you seem to be wanting to handle all cases, that's a strange choice.

As for the rest, it's way above me until you explain what it is supposed to do.

Thanks.

Signature · 2 lines
Jean "Khali" Delvare
http://khali.linux-fr.org/
#8 lore raw
In reply to Evgeniy Polyakov
Quoted 1 line · On Sat, 21 Aug 2004 09:30:57 +0200 Jean Delvare <[email protected]> wrote:

Hi Evgeniy,

Hi, Jean.

Quoted 6 lines

Here are my comments on your code. I'll only comment on the Super-I/O part, since I don't know much (and don't really care) about the GPIO driver.

First question, why the name "sc"? We'll have to find a more suitable name for the driver. What about simply "superio"?

It was derived from "Soekris" board name since it was initially wrote for those board.
It looks like it was bad crack since now I do not see letter "c" in it's name... Hmmm, maybe it was "Soekris control" or "SuperIO Control"? :)

Quoted 5 lines

### sc.h

Quoted 1 line

#define SIO_LDN_GPIO 0x07 /* General-Purpose I/O (GPIO) Ports */

This is PC87366-specific and doesn't belong to that driver.

No, I think it just should be extended and include any other defines(for temperature, voltage and others). Although they may live in drivers for those logical devices. Driver for PC87366 may use it... I will move it there after it will be created(actually separated to support several main SuperIO chips at once).

Quoted 5 lines
Quoted 3 lines

#define SIO_ACTIVE_EN 0x01 /* enabled */
(...)
#define LDEV_ACTIVE (1<<0)

Aren't these the same thing?

Actually not, the former is register value, the latter is bit in ->flags bitfield.
Although it is not very usefull to create bitfield for one bit, but it can be exteded to support states for chips that requires several steps for initialization.

Quoted 13 lines
Quoted 4 lines

#define SIO_GPDO0 0x00
#define SIO_GPDI0 0x01
#define SIO_GPEVEN0 0x02
#define SIO_GPEVST0 0x03

Quoted 8 lines

#define SIO_GPDO1 0x04
#define SIO_GPDI1 0x05
#define SIO_GPEVEN1 0x06
#define SIO_GPEVST1 0x07
#define SIO_GPDO2 0x08
#define SIO_GPDI2 0x09
#define SIO_GPDO3 0x0A
#define SIO_GPDI3 0x0B

Quoted 2 lines

Same here, PC87366-specific (I believe) so doesn't belong to that driver.

I think I should move them into GPIO driver's header or header for PC87366 SuperIO module(next step).

Quoted 9 lines
Quoted 8 lines

struct logical_dev
{
(...)

	int			(*activate)(void *);
	u8			(*read)(void *, int);
	void			(*write)(void *, int, u8);
	void			(*control)(void *, int, u8, u8);
};
Quoted 3 lines

Please give the function parameters names in your prototypes. Without them, the prototype is useless to us humans (although the compiler is perfectly happy without them).

Actually I always remove names from prototypes, since I think prototypes are needed not for detailed explanation of appropriate function but only for overall design view...

Quoted 18 lines
Quoted 8 lines

void sc_write_reg(struct sc_dev *, u8, u8); u8 sc_read_reg(struct sc_dev *, u8);

int sc_add_logical_dev(struct logical_dev *); void sc_del_logical_dev(struct logical_dev *); struct logical_dev *sc_get_ldev(char *); void sc_put_ldev(struct logical_dev *);

Ditto.

At this point, I'd appreciate a detailed explanation of your choices of implementation. It looks rather complex to me so the choices are not that obvious. I'd simply have provided read and write functions, keeping things really simple and low level, while it looks like you intend to implement the concept of logical device registration. Why is it needed? How is it going to work?

Quoted 2 lines

Please explain what the 6 functions are meant for, and how the three different structures will be used.

Sure.

sc_{add,del}_logical_dev() links and unlinks logical device from the main SuperIO module. After being added any logical device becomes visible for the external world, but it should be accessed only through main module using sc_{get,put}_ldev, which also increment/decrement is's usage counter and may implement additional functionality. When logical device is registered userspace can connect to it(actually it is the next step and will be implemented after ability to handle several main SuperIO logical modules) using either ioctl or netlink but again only through main module - with such approach we can control any data/control flow only in one place and do not disperse efforts.

Quoted 20 lines

### sc.c

Quoted 18 lines

#include <asm/atomic.h>
#include <asm/types.h>
#include <asm/io.h>

#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/list.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/timer.h>
#include <linux/slab.h>
#include <linux/timer.h>

#include "../w1/w1.h"
#include "../w1/w1_int.h"
#include "../w1/w1_log.h"

Quoted 7 lines
Quoted 2 lines

#include "sc.h"
#include "sc_gpio.h"

Wow. I doubt you need all that. At any rate, you should not include any device-specific or protocol-specific header here. There's no reason you would need them. The superio driver offers an interface to the other drivers, not the other way around.

Sure, w1 includes absolutely do not needed there.

Quoted 7 lines
Quoted 5 lines

void sc_write_reg(struct sc_dev *, u8, u8); u8 sc_read_reg(struct sc_dev *, u8);

int sc_add_logical_dev(struct logical_dev *); void sc_del_logical_dev(struct logical_dev *);

These are already defined in the .h file.

Yep, will remove.

Quoted 7 lines
Quoted 3 lines

static int sc_activate_one_logical(struct sc_dev *dev, struct logical_dev *ldev)(...)
static void sc_activate_logical(struct sc_dev *dev)

I doubt that the second one will ever be needed. There's no point in arbitrary activating all logical devices at once, is there? Ditto for deactivating.

Now it even is not called from any place. It was usefull when all logical devices lived with main driver in one file and we registered all at once.

Quoted 4 lines
Quoted 1 line

static int sc_chip_id(u8 id)

This one is supposed to convert an id into an index, isn't it? It would better be called sc_chip_index then.

No problem.

Quoted 25 lines
Quoted 25 lines

static int sc_find_device(struct sc_dev *dev, unsigned long __base)

{
	unsigned long base;
	unsigned long size = 2;
	int i, sz;

	if (__base)
	{
		base = __base;
		sz = 1;
	}
	else
	{
		base = 0; /* Make compiler happy */
		sz = sizeof(base_addr)/sizeof(base_addr[0]);
	}
	
	for (i=0; i<sz; ++i)
	{
		u8 id;
		int chip_num;
		
		if (!__base)
			base = base_addr[i];
Quoted 7 lines
Quoted 3 lines
		dev->base_index = base;
		dev->base_data = base + 1;

(...)

You handling of base is complex without a reason. If __base is set, do
base_addr[0] = __base and sz = 1. If it isn't, sz > sizeof(base_addr)/sizeof(base_addr[0]) (unchanged). Then you don't have to care about it in the for loop:

base_addr is global and may be accessed later.
And it do will be accessed when I create ability to dynamically add and remove main SuperIO "logical" modules(like with situation when we have two of them in one board).

Quoted 23 lines

static int sc_find_device(struct sc_dev *dev, unsigned long base)

{
	unsigned long size = 2;
	int i, sz;

	if (base)
	{
		base_addr[0] = base;
		sz = 1;
	}
	else
	{
		sz = sizeof(base_addr)/sizeof(base_addr[0]);
	}
	
	for (i=0; i<sz; ++i)
	{
		u8 id;
		int chip_num;
		
		dev->base_index = base_addr[i];
		dev->base_data = base_addr[i] + 1;
Quoted 6 lines

How about it?

BTW, I see no reason why you would want to force the base address. The possible addresses are standardized (0x2e/0x2f and 0x4e/0x4f), 99% of the case the super I/O is at 0x2e/0x2f. So I wouldn't even bother with that parameter.

The may live in PCI space, like SC1100 Geode processor.
It also has SuperIO, and although linux already have driver for it I will extend SuperIO main driver to support several chips at one time.

Quoted 9 lines
Quoted 9 lines
		if (chip_num >= 0)
		{
			printk(KERN_INFO "Found %s [0x%x] at
			0x%04lx-0x%04lx.\n", 
					sc_sio_ids[chip_num].name,
					sc_sio_ids[chip_num].id, base, base+size);
			return i;
		}
Quoted 7 lines
Quoted 2 lines
		printk(KERN_INFO "Found nothing at 0x%04lx-0x%04lx.\n", base,
		base+size);

base+size is really base+size-1. And actually size could go away and it would be base+1. Again, it's standard. I wouldn't even print it as "0x%x/0x%x". Super-I/O have a couple addresses by nature, not an I/O range (although this translates into a 2-address range in the end).

Sure, it should be base+size-1, but if it is not PC8736* but for example SC1100 we must request more than 2 bytes at a time, because of such chips I've added size parameter.

Quoted 4 lines

I also see that your function wouldn't support a system with two similar Super-I/Os at different addresses. I admit it was never seen and will probably never be, but since you seem to be wanting to handle all cases, that's a strange choice.

It is in my TODO list and wil be implemeted very soon after current technical problems are resolved.

Quoted 4 lines

As for the rest, it's way above me until you explain what it is supposed to do.

Thanks.

Thank you for review and comments.

Quoted 4 lines
Signature · 3 lines
-- 
Jean "Khali" Delvare
http://khali.linux-fr.org/

Evgeniy Polyakov ( s0mbre )

Only failure makes us experts. -- Theo de Raadt

#9 lore raw
In reply to Evgeniy Polyakov
Quoted 9 lines
Quoted 3 lines
Quoted 1 line

#define SIO_LDN_GPIO 0x07 /* General-Purpose I/O (GPIO) Ports */

This is PC87366-specific and doesn't belong to that driver.

No, I think it just should be extended and include any other defines(for temperature, voltage and others). Although they may live in drivers for those logical devices. Driver for PC87366 may use it... I will move it there after it will be created (actually separated to support several main SuperIO chips at once).

I'm not sure I get everything you mean here (especially the last sentence). At any rate, the logical device usage is manufacturer-dependant and, in most cases, chip dependant. And when two different chips each have a logical device for, say, temperature monitoring, the way it is organized "inside" each logical device will be different. So there's no benefit in adding labels or classes to each logical device of each chip, since we will never be able to use them.

I insist that the superio driver should be mostly chip-independant. The only part which will not be is the Super-I/O enter sequence. Since the PC8736x chips don't need any, you may not be familiar with it. Most Super-I/O chips need a special sequence to be written to them before they activate. Since the superio driver won't know what it is looking for before it finds it, it'll probably have to test all known keys, then the client driver will ask not only for a given chip ID but for a key + chip ID pair. This also means that you will have to store the (variable length) key in the superio structure.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

struct logical_dev
{
(...)

	int			(*activate)(void *);
	u8			(*read)(void *, int);
	void			(*write)(void *, int, u8);
	void			(*control)(void *, int, u8, u8);
};
Quoted 7 lines
Quoted 3 lines

Please give the function parameters names in your prototypes. Without them, the prototype is useless to us humans (although the compiler is perfectly happy without them).

Actually I always remove names from prototypes, since I think prototypes are needed not for detailed explanation of appropriate function but only for overall design view...

You probably miss the target then. In the above example, I can easily imagine what the activate, read and write member functions are for (left apart the fact that I wonder what the void * is for), but I just cannot guess what the control member function is for. Anonymous parameters don't help. At any rate, other kernel headers seem to include parameters names in their functions declarations.

While we're at it, I start wondering why you need these callback functions here. Is the client not supposed to just call sc_read_reg and sc_write_reg? I see nothing logical-device-dependent here.

Quoted 10 lines

sc_{add,del}_logical_dev() links and unlinks logical device from the main SuperIO module. After being added any logical device becomes visible for the external world, but it should be accessed only through main module using sc_{get,put}_ldev, which also increment/decrement is's usage counter and may implement additional functionality. When logical device is registered userspace can connect to it (actually it is the next step and will be implemented after ability to handle several main SuperIO logical modules) using either ioctl or netlink but again only through main module - with such approach we can control any data/control flow only in one place and do not disperse efforts.

What's the idea behind logical device registration? I don't see how this is needed. The reason why a superio driver is needed, as I understand it, is to handle concurrent accesses to 0x2E/0x2F. This means that all we really need is:

* Super-I/O detection.
* Read and write functions (specifying a logical device and a register)
* User-space interface to read and write.

Anything above that may be discussed but isn't strictly needed. I wouldn't mind shortcut functions for retrieving the logical device I/O address or activating the logical device, but these are really only read and write functions.

I don't even see the need of having a structure for logical devices.

Could you please explain what benefit your approach offers? I may be missing something.

Greg, I much would like to hear you about this.

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

static int sc_activate_one_logical(struct sc_dev *dev, struct logical_dev *ldev)(...)
static void sc_activate_logical(struct sc_dev *dev)

I doubt that the second one will ever be needed. There's no point in arbitrary activating all logical devices at once, is there? Ditto for deactivating.

Now it even is not called from any place. It was usefull when all logical devices lived with main driver in one file and we registered all at once.

Registering is one thing (even if I don't much get the interest at this point), activating is one other. Registering is a software, lernel internal action. Activating may have hardware consequences. If the functions are really about registering, they should be renamed. If they are about activating, then doing this on all logical devices at once doesn't make any sense and a function that does so shouldn't even exist.

Quoted 8 lines
Quoted 3 lines

You handling of base is complex without a reason. If __base is set,
do base_addr[0] = __base and sz = 1. If it isn't, sz > > sizeof(base_addr)/sizeof(base_addr[0]) (unchanged). Then you don't have to care about it in the for loop:

base_addr is global and may be accessed later.
And it do will be accessed when I create ability to dynamically add and remove main SuperIO "logical" modules(like with situation when we have two of them in one board).

Hm OK I see the idea now. The function may be called more than once, and my method will make the second call (possibly) fail. I admit it's no good. Forget about my proposal.

Quoted 9 lines
Quoted 5 lines

base+size is really base+size-1. And actually size could go away and it would be base+1. Again, it's standard. I wouldn't even print it as"0x%x/0x%x". Super-I/O have a couple addresses by nature, not an I/O range (although this translates into a 2-address range in the end).

Sure, it should be base+size-1, but if it is not PC8736* but for example SC1100 we must request more than 2 bytes at a time, because of such chips I've added size parameter.

If the SC1100 does live at different addresses and uses a different number of I/O ports, I start wondering the point in having a common driver. What are the common points between regular Super-I/O chips and the SC1100? Care to explain how the SC1100 works?

Thanks.

Signature · 2 lines
Jean "Khali" Delvare
http://khali.linux-fr.org/
#10 lore raw
In reply to Evgeniy Polyakov
Quoted 29 lines · Evgeniy Polyakov
Quoted 18 lines · Jean Delvare
Quoted 9 lines
Quoted 3 lines
Quoted 1 line

#define SIO_LDN_GPIO 0x07 /* General-Purpose I/O (GPIO) Ports */

This is PC87366-specific and doesn't belong to that driver.

No, I think it just should be extended and include any other defines(for temperature, voltage and others). Although they may live in drivers for those logical devices. Driver for PC87366 may use it... I will move it there after it will be created (actually separated to support several main SuperIO chips at once).

I'm not sure I get everything you mean here (especially the last sentence). At any rate, the logical device usage is manufacturer-dependant and, in most cases, chip dependant. And when two different chips each have a logical device for, say, temperature monitoring, the way it is organized "inside" each logical device will be different. So there's no benefit in adding labels or classes to each logical device of each chip, since we will never be able to use them.

Quoted 9 lines

I insist that the superio driver should be mostly chip-independant. The only part which will not be is the Super-I/O enter sequence. Since the PC8736x chips don't need any, you may not be familiar with it. Most Super-I/O chips need a special sequence to be written to them before they activate. Since the superio driver won't know what it is looking for before it finds it, it'll probably have to test all known keys, then the client driver will ask not only for a given chip ID but for a key + chip ID pair. This also means that you will have to store the (variable length) key in the superio structure.

Quoted 3 lines

I'm absolutely agree here.
I mean above that when I will split sc.c into generic part and pc8736* part I will move those definitions into the header for pc8736* driver.

That sounds fine.

Quoted 2 lines

As I described above we will not have code duplication and will have ability to add/remove logical devices in run-time.

Which is a good thing.

Quoted 5 lines
Quoted 1 line

Greg, I much would like to hear you about this.

I think we will come to logical conclusion when he will back from vocation.
Or not.

Heh, it looks good to me. Oh, and I suggest putting this in drivers/superio for a location.

thanks,

greg k-h