can: SJA1000: generic OF platform bus driver
Subsystems (4)
PATCH v2 1/1 can: SJA1000: generic OF platform bus driver
This patch adds a generic driver for SJA1000 chips on the OpenFirmware platform bus found on embedded PowerPC systems. You need a SJA1000 node definition in your flattened device tree source (DTS) file similar to:
can@3,100 {
compatible = "nxp,sja1000";
reg = <3 0x100 0x80>;
clock-frequency = <8000000>;
cdr-reg = <0x48>;
ocr-reg = <0x0a>;
interrupts = <2 0>;
interrupt-parent = <&mpic>;
};See also Documentation/powerpc/dts-bindings/can/sja1000.txt.
--- Documentation/powerpc/dts-bindings/can/sja1000.txt | 37 +++ drivers/net/can/Kconfig | 9 drivers/net/can/sja1000/Makefile | 1 drivers/net/can/sja1000/sja1000_of_platform.c | 215 +++++++++++++++++++++ 4 files changed, 262 insertions(+)
drivers/net/can/Kconfig +9 -0
@@ -51,6 +51,15 @@ config CAN_SJA1000_PLATFORM boards from Phytec (http://www.phytec.de) like the PCM027, PCM038. +config CAN_SJA1000_OF_PLATFORM + depends on CAN_SJA1000 && PPC_OF + tristate "Generic OF Platform Bus based SJA1000 driver" + ---help--- + This driver adds support for the SJA1000 chips connected to + the OpenFirmware "platform bus" found on embedded systems with + OpenFirmware bindings, e.g. if you have a PowerPC based system + you may want to enable this option. + config CAN_EMS_PCI tristate "EMS CPC-PCI and CPC-PCIe Card" depends on PCI && CAN_SJA1000
drivers/net/can/sja1000/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_CAN_SJA1000) += sja1000.o obj-$(CONFIG_CAN_SJA1000_PLATFORM) += sja1000_platform.o +obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o
drivers/net/can/sja1000/sja1000_of_platform.c new file +215 -0
215 lines not on this page · raw message
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +37 -0
@@ -0,0 +1,37 @@ +Memory mapped SJA1000 CAN controller from NXP (formerly Philips) + +Required properties: + +- compatible : should be "nxp,sja1000". +- reg : should specify the chip select, address offset and size used + for the chip depending on the bus it is connected to. +- interrupts: property with a value describing the interrupt source + (number and sensitivity) for that device. The encoding depends + on the type of interrupt controller used. + +Optional properties: + +- interrupt-parent : the phandle for the interrupt controller that + services interrupts for that device. +- clock-frequency : CAN system clock frequency in Hz, which is normally + half of the oscillator clock frequency. If not specified, a + default value of 8000000 (8 MHz) is used. +- cdr-reg : value of the SJA1000 clock divider register according to + the SJA1000 data sheet. If not specified, a default value of + 0x48 is used. +- ocr-reg : value of the SJA1000 output control register according to + the SJA1000 data sheet. If not specified, a default value of + 0x0a is used. + +Examples: + +can@3,100 { + compatible = "nxp,sja1000"; + reg = <3 0x100 0x80>; + clock-frequency = <8000000>; + cdr-reg = <0x48>; + ocr-reg = <0x0a>; + interrupts = <2 0>; + interrupt-parent = <&mpic>; +}; +
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Wolfgang, thanks for the quick response. Comments below...
Documentation/powerpc/dts-bindings/can/sja1000.txt line 10
Quoted 12 lines · Wolfgang Grandegger
+++
net-next-2.6/Documentation/powerpc/dts-bindings/can/sja1000.txtDocumentation/powerpc/dts-bindings/can/sja1000.txt new file +10
-0@@ -0,0 +1,37 @@ +Memory mapped SJA1000 CAN controller from NXP (formerly Philips) + +Required properties: + +- compatible : should be "nxp,sja1000". +- reg : should specify the chip select, address offset and size used + for the chip depending on the bus it is connected to. +- interrupts: property with a value describing the interrupt source + (number and sensitivity) for that device. The encoding depends + on the type of interrupt controller used.
Hmmm, "reg", "interrupts", and "interrupt-parent" are well understood properties. I don't think we need to keep boilerplate defining the meaning every time a new binding is added. (general musing; not an ack or nack of this patch)
However, what should be defined is *what* the register range is (ie. one tuple; location of device registers), and what the interrupts are (ie. single tuple for device's irq line). Granted this is a trivial case, but in the case of devices with more than one address range or irq line, the meaning of each tuple is critical information. I think it would be a good pattern to establish.
Documentation/powerpc/dts-bindings/can/sja1000.txt line 15
Quoted 4 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +4
-0+Optional properties: + +- interrupt-parent : the phandle for the interrupt controller that + services interrupts for that device.
Thinking further; I wouldn't even mention "interrupt-parent" here. Anyone working with this stuff must already understand irq routing.
Documentation/powerpc/dts-bindings/can/sja1000.txt line 18
Quoted 3 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +3
-0+- clock-frequency : CAN system clock frequency in Hz, which is normally + half of the oscillator clock frequency. If not specified, a + default value of 8000000 (8 MHz) is used.
A clock-frequency property typically refers to the bus clock frequency. Something like can-frequency would be better.
Documentation/powerpc/dts-bindings/can/sja1000.txt line 21
Quoted 3 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +3
-0+- cdr-reg : value of the SJA1000 clock divider register according to + the SJA1000 data sheet. If not specified, a default value of + 0x48 is used.
Ewh. The driver should be clueful enough to derive the clock divider value given both the bus and can frequencies. I don't like this property.
Documentation/powerpc/dts-bindings/can/sja1000.txt line 24
Quoted 3 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +3
-0+- ocr-reg : value of the SJA1000 output control register according to + the SJA1000 data sheet. If not specified, a default value of + 0x0a is used.
Ditto here; the binding should describe the usage mode; not the register settings to get the usage mode. What sort of settings will the .dts author be writing here?
Cheers,
g.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
A message that is not in the archive (sent off-list or not yet received): fa686aa40905220808kecd06cdqb570b78ca97f0ca6-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Hi Grant,
Quoted 12 lines · Grant Likely
Hi Wolfgang, thanks for the quick response. Comments below...
Quoted 9 lines · Wolfgang Grandegger
+++
net-next-2.6/Documentation/powerpc/dts-bindings/can/sja1000.txtDocumentation/powerpc/dts-bindings/can/sja1000.txt new file +7
-0@@ -0,0 +1,37 @@ +Memory mapped SJA1000 CAN controller from NXP (formerly Philips) + +Required properties: + +- compatible : should be "nxp,sja1000". +- reg : should specify the chip select, address offset and size used + for the chip depending on the bus it is connected to.
Quoted 8 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt line 10
Quoted 3 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +3
-0+- interrupts: property with a value describing the interrupt source + (number and sensitivity) for that device. The encoding depends + on the type of interrupt controller used.Hmmm, "reg", "interrupts", and "interrupt-parent" are well understood properties. I don't think we need to keep boilerplate defining the meaning every time a new binding is added. (general musing; not an ack or nack of this patch)
OK.
Quoted 6 lines
However, what should be defined is *what* the register range is (ie. one tuple; location of device registers), and what the interrupts are (ie. single tuple for device's irq line). Granted this is a trivial case, but in the case of devices with more than one address range or irq line, the meaning of each tuple is critical information. I think it would be a good pattern to establish.
Sounds reasonable.
Quoted 7 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt line 15
Quoted 4 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +4
-0+Optional properties: + +- interrupt-parent : the phandle for the interrupt controller that + services interrupts for that device.Thinking further; I wouldn't even mention "interrupt-parent" here. Anyone working with this stuff must already understand irq routing.
OK, I will remove it.
Quoted 6 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt line 18
Quoted 3 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +3
-0+- clock-frequency : CAN system clock frequency in Hz, which is normally + half of the oscillator clock frequency. If not specified, a + default value of 8000000 (8 MHz) is used.A clock-frequency property typically refers to the bus clock frequency. Something like can-frequency would be better.
Ah, right, but I'm also not happy with "can-frequency". The manual speaks about the "internal clock", which is half of the external oscillator frequency. Maybe "internal-clock-frequency" might be better.
Quoted 7 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt line 21
Quoted 3 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +3
-0+- cdr-reg : value of the SJA1000 clock divider register according to + the SJA1000 data sheet. If not specified, a default value of + 0x48 is used.Ewh. The driver should be clueful enough to derive the clock divider value given both the bus and can frequencies. I don't like this property.
The clock divider register controls the CLKOUT frequency for the microcontroller another CAN controller and allows to deactivate the CLKOUT pin. It's not used to configure the CAN bus frequency.
Quoted 8 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt line 24
Quoted 4 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +3
-0+- ocr-reg : value of the SJA1000 output control register according to + the SJA1000 data sheet. If not specified, a default value of + 0x0a is used.Ditto here; the binding should describe the usage mode; not the register settings to get the usage mode. What sort of settings will the .dts author be writing here?
Unfortunately, there are many:
clkout-frequency
bypass-comperator
tx1-output-on-rx-irq
#define OCR_MODE_BIPHASE 0x00 #define OCR_MODE_TEST 0x01 #define OCR_MODE_NORMAL 0x02 #define OCR_MODE_CLOCK 0x03
#define OCR_TX0_INVERT 0x04 #define OCR_TX0_PULLDOWN 0x08 #define OCR_TX0_PULLUP 0x10 #define OCR_TX0_PUSHPULL 0x18 #define OCR_TX1_INVERT 0x20 #define OCR_TX1_PULLDOWN 0x40 #define OCR_TX1_PULLUP 0x80 #define OCR_TX1_PUSHPULL 0xc0
I think implementing properties for each option is overkill.
Wolfgang.
Quoted 1 line
Quoted 91 lines · Wolfgang Grandegger
Hi Grant,
Quoted 19 lines · Grant Likely
Hi Wolfgang, thanks for the quick response. Comments below...
Documentation/powerpc/dts-bindings/can/sja1000.txt line 10
Quoted 12 lines · Wolfgang Grandegger
+++
net-next-2.6/Documentation/powerpc/dts-bindings/can/sja1000.txtDocumentation/powerpc/dts-bindings/can/sja1000.txt new file +10
-0@@ -0,0 +1,37 @@ +Memory mapped SJA1000 CAN controller from NXP (formerly Philips) + +Required properties: + +- compatible : should be "nxp,sja1000". +- reg : should specify the chip select, address offset and size used + for the chip depending on the bus it is connected to. +- interrupts: property with a value describing the interrupt source + (number and sensitivity) for that device. The encoding depends + on the type of interrupt controller used.Hmmm, "reg", "interrupts", and "interrupt-parent" are well understood properties. I don't think we need to keep boilerplate defining the meaning every time a new binding is added. (general musing; not an ack or nack of this patch)
OK.
Quoted 6 lines
However, what should be defined is *what* the register range is (ie. one tuple; location of device registers), and what the interrupts are (ie. single tuple for device's irq line). Granted this is a trivial case, but in the case of devices with more than one address range or irq line, the meaning of each tuple is critical information. I think it would be a good pattern to establish.
Sounds reasonable.
Quoted 6 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt line 15
Quoted 4 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +4
-0+Optional properties: + +- interrupt-parent : the phandle for the interrupt controller that + services interrupts for that device.Thinking further; I wouldn't even mention "interrupt-parent" here. Anyone working with this stuff must already understand irq routing.
OK, I will remove it.
Quoted 5 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt line 18
Quoted 3 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +3
-0+- clock-frequency : CAN system clock frequency in Hz, which is normally + half of the oscillator clock frequency. If not specified, a + default value of 8000000 (8 MHz) is used.A clock-frequency property typically refers to the bus clock frequency. Something like can-frequency would be better.
Ah, right, but I'm also not happy with "can-frequency". The manual speaks about the "internal clock", which is half of the external oscillator frequency. Maybe "internal-clock-frequency" might be better.
Quoted 6 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt line 21
Quoted 3 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +3
-0+- cdr-reg : value of the SJA1000 clock divider register according to + the SJA1000 data sheet. If not specified, a default value of + 0x48 is used.Ewh. The driver should be clueful enough to derive the clock divider value given both the bus and can frequencies. I don't like this property.
The clock divider register controls the CLKOUT frequency for the microcontroller another CAN controller and allows to deactivate the CLKOUT pin. It's not used to configure the CAN bus frequency.
Quoted 6 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt line 24
Quoted 3 lines
Documentation/powerpc/dts-bindings/can/sja1000.txt new file +3
-0+- ocr-reg : value of the SJA1000 output control register according to + the SJA1000 data sheet. If not specified, a default value of + 0x0a is used.Ditto here; the binding should describe the usage mode; not the register settings to get the usage mode. What sort of settings will the .dts author be writing here?
Unfortunately, there are many:
clkout-frequency
bypass-comperator
tx1-output-on-rx-irq#define OCR_MODE_BIPHASE 0x00 #define OCR_MODE_TEST 0x01 #define OCR_MODE_NORMAL 0x02 #define OCR_MODE_CLOCK 0x03#define OCR_TX0_INVERT 0x04 #define OCR_TX0_PULLDOWN 0x08 #define OCR_TX0_PULLUP 0x10 #define OCR_TX0_PUSHPULL 0x18 #define OCR_TX1_INVERT 0x20 #define OCR_TX1_PULLDOWN 0x40 #define OCR_TX1_PULLUP 0x80 #define OCR_TX1_PUSHPULL 0xc0
Quoted 1 line
I think implementing properties for each option is overkill.
Would the following more descriptive properties be OK?
clock-out-frequency = <0>, // CLKOUT pin clock off
= <4000000>; // frequency on CLKOUT pin
bypass-input-comparator; // allows to bypass the CAN input comparator.
tx1-output-on-rx-irq; // allows the TX1 output to be used as a
// dedicated RX interrupt output.
output-control-mode = <0x0> // bi-phase output mode
<0x1> // test output mode
<0x2> // normal output mode (default)
<0x3> // clock output mode output-pin-config = <0x01> // TX0 invert
<0x02> // TX0 pull-down
<0x04> // TX0 pull-up
<0x06> // TX0 push-pull
<0x08> // TX1 invert
<0x10> // TX1 pull-down
<0x20> // TX1 pull-up
<0x30> // TX1 push-pullWolfgang.
Quoted 11 lines · Wolfgang Grandegger
Quoted 10 lines · Wolfgang Grandegger
Quoted 5 lines · Grant Likely
Quoted 3 lines
+- clock-frequency : CAN system clock frequency in Hz, which is normally
+ half of the oscillator clock frequency. If not specified, a
+ default value of 8000000 (8 MHz) is used.A clock-frequency property typically refers to the bus clock frequency. Something like can-frequency would be better.
Ah, right, but I'm also not happy with "can-frequency". The manual speaks about the "internal clock", which is half of the external oscillator frequency. Maybe "internal-clock-frequency" might be better.
Would it be better to specify the external clock frequency, and the driver know that internal freq is half that? I ask because external clock freq is a value the HW designer actually has control over.
Quoted 38 lines
Quoted 38 lines
Quoted 6 lines
Quoted 3 lines
+- cdr-reg : value of the SJA1000 clock divider register according to
+ the SJA1000 data sheet. If not specified, a default value of
+0x48is used.Ewh. The driver should be clueful enough to derive the clock divider value given both the bus and can frequencies. I don't like this property.
The clock divider register controls the CLKOUT frequency for the microcontroller another CAN controller and allows to deactivate the CLKOUT pin. It's not used to configure the CAN bus frequency.
Quoted 6 lines
Quoted 3 lines
+- ocr-reg : value of the SJA1000 output control register according to
+ the SJA1000 data sheet. If not specified, a default value of
+0x0ais used.Ditto here; the binding should describe the usage mode; not the register settings to get the usage mode. What sort of settings will the .dts author be writing here?
Unfortunately, there are many:
clkout-frequency
bypass-comperator
tx1-output-on-rx-irq#define
OCR_MODE_BIPHASE0x00
#defineOCR_MODE_TEST0x01
#defineOCR_MODE_NORMAL0x02
#defineOCR_MODE_CLOCK0x03#define
OCR_TX0_INVERT0x04
#defineOCR_TX0_PULLDOWN0x08
#defineOCR_TX0_PULLUP0x10
#defineOCR_TX0_PUSHPULL0x18
#defineOCR_TX1_INVERT0x20
#defineOCR_TX1_PULLDOWN0x40
#defineOCR_TX1_PULLUP0x80
#defineOCR_TX1_PUSHPULL0xc0
Quoted 1 line
Quoted 1 line
I think implementing properties for each option is overkill.
Ugh, I see what you mean.
Quoted 4 lines
Would the following more descriptive properties be OK?
clock-out-frequency = <0>, // CLKOUT pin clock off = <4000000>; // frequency on CLKOUT pin
Or how about CLKOUT pin off if the property isn't present? Otherwise, this looks okay. BTW, I'd consider prefixing this with 'nxp,' or 'sja1000,' to protect the namespace. clock-out-frequency sounds like one of those names which could be commonly used in the future. I'd so the same for the other chip-specific properties too.
Segher, what's your opinion on this?
Quoted 10 lines
bypass-input-comparator; // allows to bypass the CAN input comparator.
tx1-output-on-rx-irq; // allows the TX1 output to be used as a // dedicated RX interrupt output.
output-control-mode = <
0x0> // bi-phase output mode <0x1> // test output mode <0x2> // normal output mode (default) <0x3> // clock output mode
Quoted 8 lines
output-pin-config = <
0x01> // TX0 invert
<0x02> // TX0 pull-down
<0x04> // TX0 pull-up
<0x06> // TX0 push-pull
<0x08> // TX1 invert
<0x10> // TX1 pull-down
<0x20> // TX1 pull-up
<0x30> // TX1 push-pull
hmmm; It is very chip specific and it is a lot of mucking around. If you prefix the property with the manufacturer name, then perhaps the explicit register setting is okay.
Are TX0 & TX1 protocol pins or GPIOs? If gpio, then maybe it is worth the mucking about to then use the gpios binding to specify the pin mode.
g.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
Quoted 8 lines · Grant Likely
Quoted 7 lines · Wolfgang Grandegger
Quoted 6 lines · Wolfgang Grandegger
Quoted 5 lines · Grant Likely
Review
Quoted 3 lines
+- clock-frequency : CAN system clock frequency in Hz, which is normally
(quoted diff) +2
-0+ half of the oscillator clock frequency. If not specified, a + default value of 8000000 (8 MHz) is used.A clock-frequency property typically refers to the bus clock frequency. Something like can-frequency would be better.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Ah, right, but I'm also not happy with "can-frequency". The manual speaks about the "internal clock", which is half of the external oscillator frequency. Maybe "internal-clock-frequency" might be better.
Would it be better to specify the external clock frequency, and the driver know that internal freq is half that? I ask because external clock freq is a value the HW designer actually has control over.
I'm sharing your arguments: "external-clock-frequency". There is always some confusion about external and internal clock frequency but the name should make it clear.
Quoted 38 lines
Quoted 36 lines
Quoted 36 lines
Quoted 6 lines
Review
Quoted 3 lines
+- cdr-reg : value of the SJA1000 clock divider register according to
(quoted diff) +2
-0+ the SJA1000 data sheet. If not specified, a default value of + 0x48 is used.Ewh. The driver should be clueful enough to derive the clock divider value given both the bus and can frequencies. I don't like this property.
The clock divider register controls the CLKOUT frequency for the microcontroller another CAN controller and allows to deactivate the CLKOUT pin. It's not used to configure the CAN bus frequency.
Quoted 6 lines
Review
Quoted 3 lines
+- ocr-reg : value of the SJA1000 output control register according to
(quoted diff) +2
-0+ the SJA1000 data sheet. If not specified, a default value of + 0x0a is used.Ditto here; the binding should describe the usage mode; not the register settings to get the usage mode. What sort of settings will the .dts author be writing here?
Unfortunately, there are many:
clkout-frequency
bypass-comperator
tx1-output-on-rx-irq#define OCR_MODE_BIPHASE 0x00 #define OCR_MODE_TEST 0x01 #define OCR_MODE_NORMAL 0x02 #define OCR_MODE_CLOCK 0x03#define OCR_TX0_INVERT 0x04 #define OCR_TX0_PULLDOWN 0x08 #define OCR_TX0_PULLUP 0x10 #define OCR_TX0_PUSHPULL 0x18 #define OCR_TX1_INVERT 0x20 #define OCR_TX1_PULLDOWN 0x40 #define OCR_TX1_PULLUP 0x80 #define OCR_TX1_PUSHPULL 0xc0Quoted 1 line
Quoted 1 line
I think implementing properties for each option is overkill.
Quoted 8 lines
Ugh, I see what you mean.
Quoted 4 lines
Would the following more descriptive properties be OK?
clock-out-frequency = <0>, // CLKOUT pin clock off
= <4000000>; // frequency on CLKOUT pinOr how about CLKOUT pin off if the property isn't present? Otherwise,
Yep, that will be the default anyhow.
Quoted 6 lines
this looks okay. BTW, I'd consider prefixing this with 'nxp,' or 'sja1000,' to protect the namespace. clock-out-frequency sounds like one of those names which could be commonly used in the future. I'd so the same for the other chip-specific properties too.
Segher, what's your opinion on this?
I personally don't have a real preference.
Quoted 19 lines
Quoted 10 lines
bypass-input-comparator; // allows to bypass the CAN input comparator.
tx1-output-on-rx-irq; // allows the TX1 output to be used as a
// dedicated RX interrupt output.output-control-mode = <
0x0> // bi-phase output mode<0x1> // test output mode <0x2> // normal output mode (default) <0x3> // clock output modeQuoted 8 lines
output-pin-config = <
0x01> // TX0 invert<0x02> // TX0 pull-down <0x04> // TX0 pull-up <0x06> // TX0 push-pull <0x08> // TX1 invert <0x10> // TX1 pull-down <0x20> // TX1 pull-up <0x30> // TX1 push-pull
Quoted 3 lines
hmmm; It is very chip specific and it is a lot of mucking around. If you prefix the property with the manufacturer name, then perhaps the explicit register setting is okay.
OK.
Quoted 3 lines
Are TX0 & TX1 protocol pins or GPIOs? If gpio, then maybe it is worth the mucking about to then use the gpios binding to specify the pin mode.
These are the output from the CAN output driver 0 or 1 to the physical bus line. E.g., in normal output mode the CAN bit sequence is sent via TX0 or TX1. From a non-hardware expert point of view, they must be programmed properly to get the hardware to work.
Wolfgang.
Quoted 2 lines · Wolfgang Grandegger
This patch adds a generic driver for SJA1000 chips on the OpenFirmware platform bus found on embedded PowerPC systems.
Nice driver!
drivers/net/can/sja1000/sja1000_of_platform.c line 67
Quoted 9 lines
drivers/net/can/sja1000/sja1000_of_platform.c new file +9
-0+static u8 sja1000_ofp_read_reg (const struct net_device *dev,int reg) +{ +return in_8 ((void __iomem *)(dev->base_addr + reg)); +} + +static void sja1000_ofp_write_reg (const struct net_device *dev,int reg,u8 val) +{ +out_8 ((void __iomem *)(dev->base_addr + reg), val); +}
Minor nitpicking: dev->base_addr should be defined as an __iomem pointer so you can avoid the cast here and in the ioremap/iounmap path.
Arnd <><
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 6 lines · Arnd Bergmann
Quoted 2 lines · Wolfgang Grandegger
This patch adds a generic driver for SJA1000 chips on the OpenFirmware platform bus found on embedded PowerPC systems.
Nice driver!
Quoted 12 lines
drivers/net/can/sja1000/sja1000_of_platform.c line 67
Quoted 9 lines
drivers/net/can/sja1000/sja1000_of_platform.c new file +9
-0+static u8 sja1000_ofp_read_reg (const struct net_device *dev,int reg) +{ +return in_8 ((void __iomem *)(dev->base_addr + reg)); +} + +static void sja1000_ofp_write_reg (const struct net_device *dev,int reg,u8 val) +{ +out_8 ((void __iomem *)(dev->base_addr + reg), val); +}Minor nitpicking:
dev->base_addrshould be defined as an__iomempointer so you can avoid the cast here and in the ioremap/iounmap path.
Here the member "base_addr" of "struct net_device" is used and it's not up to me to change the type.
Wolfgang.
Quoted 7 lines · Wolfgang Grandegger
Quoted 3 lines · Arnd Bergmann
Minor nitpicking:
dev->base_addrshould be defined as an__iomempointer so you can avoid the cast here and in the ioremap/iounmap path.Here the member "
base_addr" of "structnet_device" is used and it's not up to me to change the type.
Right, that makes sense. However, most drivers use the field to store the physical address, not the iomap token. Maybe there should be a new field in struct sja1000_priv for the virtual address, but that would be a change to the base driver, not just to the OF portion.
Thanks,
Arnd <><
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Wolfgang Grandegger
Quoted 2 lines · Arnd Bergmann
Minor nitpicking:
dev->base_addrshould be defined as an__iomempointer so you can avoid the cast here and in the ioremap/iounmap path.Here the member "
base_addr" of "structnet_device" is used and it's not up to me to change the type.Right, that makes sense. However, most drivers use the field to store the physical address, not the iomap token. Maybe there should be a new field in struct
sja1000_privfor the virtual address, but that would be a change to the base driver, not just to the OF portion.
Is that common practice? If yes, I will add a member to store the virtual address to struct sja1000_priv.
Wolfgang.
Quoted 7 lines · Wolfgang Grandegger
Quoted 4 lines
Right, that makes sense. However, most drivers use the field to store the physical address, not the iomap token. Maybe there should be a new field in struct
sja1000_privfor the virtual address, but that would be a change to the base driver, not just to the OF portion.Is that common practice? If yes, I will add a member to store the virtual address to struct
sja1000_priv.
I grepped through the network driver for usage of ->base_addr, and it's somewhat inconsistent. The majority of the users use it for a physical address, but there are also a few that use it for the __iomem token.
Casts between unsigned long and qualified (__iomem, __user, const, ...) pointers do not cause a warning, but can easily lead to bugs when another user casts to an unqualified pointer.
Arnd <><
A message that is not in the archive (sent off-list or not yet received): [email protected]
From: Arnd Bergmann <[email protected]>
Date: Tue, 26 May 2009 10:10:30 +0100
Quoted 9 lines · Wolfgang Grandegger
Quoted 7 lines
Quoted 4 lines
Right, that makes sense. However, most drivers use the field to store the physical address, not the iomap token. Maybe there should be a new field in struct
sja1000_privfor the virtual address, but that would be a change to the base driver, not just to the OF portion.Is that common practice? If yes, I will add a member to store the virtual address to struct
sja1000_priv.
Quoted 8 lines
I grepped through the network driver for usage of ->base_addr, and it's somewhat inconsistent. The majority of the users use it for a physical address, but there are also a few that use it for the
__iomemtoken.Casts between unsigned long and qualified (
__iomem,__user, const, ...) pointers do not cause a warning, but can easily lead to bugs when another user casts to an unqualified pointer.
It's such a baroque thing, there is no reason to set it at all if you ask me. It's only use is to allow ISA and similar primitive bus devices to have their I/O ports changed via ifconfig.
Quoted 3 lines · David Miller
It's such a baroque thing, there is no reason to set it at all if you ask me. It's only use is to allow ISA and similar primitive bus devices to have their I/O ports changed via ifconfig.
My original comment was about the fact that sja1000 was doing dev->base_addr = (unsigned long)ioremap(phys_addr, size), I didn't even think about SIOCGIFMAP and command line overrides, but that surely makes it worse and the driver should be changed to store the virtual register address in its private data structure.
drivers/net/fec.c seems to have the same problem, which manifests in a number of ugly casts and direct pointer dereferences in places where it should do writel() or out_be32().
Arnd <><
Quoted 11 lines · Arnd Bergmann
Quoted 3 lines · David Miller
It's such a baroque thing, there is no reason to set it at all if you ask me. It's only use is to allow ISA and similar primitive bus devices to have their I/O ports changed via ifconfig.
My original comment was about the fact that sja1000 was doing
dev->base_addr= (unsigned long)ioremap(phys_addr, size), I didn't even think about SIOCGIFMAP and command line overrides, but that surely makes it worse and the driver should be changed to store the virtual register address in its private data structure.
Quoted 3 lines
drivers/net/fec.cseems to have the same problem, which manifests in a number of ugly casts and direct pointer dereferences in places where it should dowritel()orout_be32().
Ack. I'll prepare a patch for fec.c. Internally the driver already uses a void __iomem * and writel/readl in -next. There is only one usage left.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 15 lines · David Miller
From: Arnd Bergmann <[email protected]>
Date: Tue, 26 May 2009 10:10:30 +0100Quoted 12 lines · Wolfgang Grandegger
Quoted 6 lines
Quoted 4 lines
Right, that makes sense. However, most drivers use the field to store the physical address, not the iomap token. Maybe there should be a new field in struct
sja1000_privfor the virtual address, but that would be a change to the base driver, not just to the OF portion.Is that common practice? If yes, I will add a member to store the virtual address to struct
sja1000_priv.I grepped through the network driver for usage of ->base_addr, and it's somewhat inconsistent. The majority of the users use it for a physical address, but there are also a few that use it for the
__iomemtoken.
Quoted 7 lines
Quoted 3 lines
Casts between unsigned long and qualified (
__iomem,__user, const, ...) pointers do not cause a warning, but can easily lead to bugs when another user casts to an unqualified pointer.It's such a baroque thing, there is no reason to set it at all if you ask me. It's only use is to allow ISA and similar primitive bus devices to have their I/O ports changed via ifconfig.
OK, I see, there are good reasons not to (mis-)use dev->base_addr. I will prepare a patch for the SJA1000 CAN drivers.
Wolfgang.
Quoted 19 lines · Wolfgang Grandegger
Quoted 18 lines · David Miller
From: Arnd Bergmann <[email protected]>
Date: Tue, 26 May 2009 10:10:30 +0100Quoted 15 lines · Wolfgang Grandegger
Quoted 6 lines
Quoted 4 lines
Right, that makes sense. However, most drivers use the field to store the physical address, not the iomap token. Maybe there should be a new field in struct
sja1000_privfor the virtual address, but that would be a change to the base driver, not just to the OF portion.Is that common practice? If yes, I will add a member to store the virtual address to struct
sja1000_priv.I grepped through the network driver for usage of ->base_addr, and it's somewhat inconsistent. The majority of the users use it for a physical address, but there are also a few that use it for the
__iomemtoken.Casts between unsigned long and qualified (
__iomem,__user, const, ...) pointers do not cause a warning, but can easily lead to bugs when another user casts to an unqualified pointer.
Quoted 6 lines
Quoted 3 lines
It's such a baroque thing, there is no reason to set it at all if you ask me. It's only use is to allow ISA and similar primitive bus devices to have their I/O ports changed via ifconfig.
OK, I see, there are good reasons not to (mis-)use
dev->base_addr. I will prepare a patch for the SJA1000 CAN drivers.
I have just sent out a patch series fixing this issue and providing a revised patch for the SJA1000 OF platform driver:
[net-next-2.6 PATCH 0/3] can: sja1000: misused netdev->base_addr and OF platform driver
Wolfgang.
Quoted 6 lines · Arnd Bergmann
Quoted 5 lines · Wolfgang Grandegger
Quoted 4 lines
Right, that makes sense. However, most drivers use the field to store the physical address, not the iomap token. Maybe there should be a new field in struct
sja1000_privfor the virtual address, but that would be a change to the base driver, not just to the OF portion.
Quoted 7 lines
Quoted 2 lines
Is that common practice? If yes, I will add a member to store the virtual address to struct
sja1000_priv.I grepped through the network driver for usage of ->base_addr, and it's somewhat inconsistent. The majority of the users use it for a physical address, but there are also a few that use it for the
__iomemtoken.
In addition, iirc, it's not big enough to hold >32 bit physical addresses on 32-bit platforms no ?
Ben.
Quoted 10 lines
Casts between unsigned long and qualified (
__iomem,__user, const, ...) pointers do not cause a warning, but can easily lead to bugs when another user casts to an unqualified pointer.Arnd <><_______________________________________________
Linuxppc-dev mailing list [email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev