cpm2: Reset the CPM at startup and fix the cpm_uart driver accordingly.
Subsystems (2)
PATCH v3 4/4 cpm2: Reset the CPM when early debugging is not enabled.
In reply to Laurent PinchartSimilarly to what is done for PQ1-based platforms, this patch resets the PQ2 Communication Processor Module in cpm2_reset() when early debugging is not enabled. This helps avoiding conflicts when the boot loader configured the CPM in an unexpected way.
--- arch/powerpc/sysdev/cpm2.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
arch/powerpc/sysdev/cpm2.c +6 -0
@@ -80,6 +80,12 @@ void __init cpm2_reset(void)/* Tell everyone where the comm processor resides. */ cpmp = &cpm2_immr->im_cpm; + +#ifndef CONFIG_PPC_EARLY_DEBUG_CPM +/* Reset the CPM. +*/ +cpm_command (CPM_CR_RST ,0 ); +#endif }static DEFINE_SPINLOCK (cmd_lock);
Signature · 13 lines
1.5.0 -- Laurent Pinchart CSE Semaphore Belgium Chaussée de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
PATCH v3 3/4 ep8248e: Reference SMC parameter RAM base in the device tree.
In reply to Laurent PinchartThis patch modifies the Embedded Planet EP8248E device tree to reference the SMC paramater RAM base register instead of the parameter RAM allocated by the boot loader.
The cpm_uart driver will allocate parameter RAM itself, making the serial port initialisation independent of the boot loader.
The patch adds the parameter RAM allocated by the boot loader in the CPM muram node, making it available to the kernel.
--- arch/powerpc/boot/dts/ep8248e.dts | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
arch/powerpc/boot/dts/ep8248e.dts +2 -3
@@ -121,8 +121,7 @@ data@0 { compatible = "fsl,cpm-muram-data"; - reg = <0 0x1100 0x1140 - 0xec0 0x9800 0x800>; + reg = <0 0x2000 0x9800 0x800>; }; };
@@ -138,7 +137,7 @@ device_type = "serial"; compatible = "fsl,mpc8248-smc-uart", "fsl,cpm2-smc-uart"; - reg = <0x11a80 0x20 0x1100 0x40>; + reg = <0x11a80 0x20 0x87fc 2>; interrupts = <4 8>; interrupt-parent = <&PIC>; fsl,cpm-brg = <7>;
Signature · 13 lines
1.5.0 -- Laurent Pinchart CSE Semaphore Belgium Chaussée de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
v3 cover cpm2: Reset the CPM at startup and fix the cpm_uart driver accordingly.
Hi everybody,
these 4 patches reset the CPM in cpm2_reset() and fix the cpm_uart driver to initialise SMC ports correctly without relying on any initialisation performed by the boot loader/wrapper. They update the boot wrapper code and the EP8248E device tree to match the new SMC registers description.
Signature · 9 lines
Laurent Pinchart CSE Semaphore Belgium Chaussée de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
PATCH v3 1/4 cpm_uart: Allocate DPRAM memory for SMC ports on CPM2-based platforms.
This patch allocates parameter RAM for SMC serial ports without relying on previous initialisation by a boot loader or a wrapper layer.
SMC parameter RAM on CPM2-based platforms can be allocated anywhere in the general-purpose areas of the dual-port RAM. The current code relies on the boot loader to allocate a section of general-purpose CPM RAM and gets the section address from the device tree.
This patch modifies the device tree address usage to reference the SMC parameter RAM base pointer instead of a pre-allocated RAM section and allocates memory from the CPM dual-port RAM when initialising the SMC port. CPM1-based platforms are not affected.
--- drivers/serial/cpm_uart/cpm_uart.h | 3 ++ drivers/serial/cpm_uart/cpm_uart_core.c | 19 +++++------ drivers/serial/cpm_uart/cpm_uart_cpm1.c | 12 +++++++ drivers/serial/cpm_uart/cpm_uart_cpm2.c | 52 +++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 10 deletions(-)
drivers/serial/cpm_uart/cpm_uart.h +3 -0
@@ -93,6 +93,9 @@ extern struct uart_cpm_port cpm_uart_ports[UART_NR];/* these are located in their respective files */ void cpm_line_cr_cmd (struct uart_cpm_port *port,int cmd); +void __iomem *cpm_uart_map_pram (struct uart_cpm_port *port, +struct device_node *np); +void cpm_uart_unmap_pram (struct uart_cpm_port *port,void __iomem *pram);int cpm_uart_init_portdesc (void );int cpm_uart_allocbuf (struct uart_cpm_port *pinfo,unsigned int is_con);void cpm_uart_freebuf (struct uart_cpm_port *pinfo);
drivers/serial/cpm_uart/cpm_uart_core.c +9 -10
@@ -997,24 +997,23 @@ static int cpm_uart_init_port(struct device_node *np,if (!mem)return -ENOMEM ; - pram =of_iomap (np,1 ); -if (!pram) { - ret = -ENOMEM ; - goto out_mem; - } -if (of_device_is_compatible (np,"fsl,cpm1-scc-uart" ) ||of_device_is_compatible (np,"fsl,cpm2-scc-uart" )) { pinfo->sccp = mem; - pinfo->sccup = pram; + pinfo->sccup = pram =cpm_uart_map_pram (pinfo, np); }else if (of_device_is_compatible (np,"fsl,cpm1-smc-uart" ) ||of_device_is_compatible (np,"fsl,cpm2-smc-uart" )) { pinfo->flags |=FLAG_SMC ; pinfo->smcp = mem; - pinfo->smcup = pram; + pinfo->smcup = pram =cpm_uart_map_pram (pinfo, np); }else { ret = -ENODEV ; - goto out_pram; + goto out_mem; + } + +if (!pram) { + ret = -ENOMEM ; + goto out_mem; } pinfo->tx_nrfifos =TX_NUM_FIFO ;
@@ -1038,7 +1037,7 @@ static int cpm_uart_init_port(struct device_node *np,return cpm_uart_request_port (&pinfo->port); out_pram: -iounmap (pram); +cpm_uart_unmap_pram (pinfo, pram); out_mem:iounmap (mem);return ret;
drivers/serial/cpm_uart/cpm_uart_cpm1.c +12 -0
@@ -54,6 +54,18 @@ void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd) {cpm_command (port->command, cmd); } + +void __iomem *cpm_uart_map_pram (struct uart_cpm_port *port, +struct device_node *np) +{ +return of_iomap (np,1 ); +} + +void cpm_uart_unmap_pram (struct uart_cpm_port *port,void __iomem *pram) +{ +iounmap (pram); +} +#else void cpm_line_cr_cmd (struct uart_cpm_port *port,int cmd) {
drivers/serial/cpm_uart/cpm_uart_cpm2.c +52 -0
64 lines not on this page · raw message
Signature · 13 lines
1.5.0 -- Laurent Pinchart CSE Semaphore Belgium Chaussée de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
PATCH v3 2/4 cpm-serial: Relocate CPM buffer descriptors and SMC parameter ram.
In reply to Laurent PinchartThis patch relocates the buffer descriptors and the SMC parameter RAM at the end of the first CPM muram chunk, as described in the device tree. This allows device trees to stop excluding SMC parameter ram allocated by the boot loader from the CPM muram node.
--- arch/powerpc/Kconfig.debug | 2 +- arch/powerpc/boot/cpm-serial.c | 132 ++++++++++++++++++++++++++-------------- 2 files changed, 87 insertions(+), 47 deletions(-)
arch/powerpc/Kconfig.debug +1 -1
@@ -269,7 +269,7 @@ config PPC_EARLY_DEBUG_CPM_ADDR hex "CPM UART early debug transmit descriptor address" depends on PPC_EARLY_DEBUG_CPM default "0xfa202008" if PPC_EP88XC - default "0xf0000008" if CPM2 + default "0xf0001ff8" if CPM2 default "0xff002008" if CPM1 help This specifies the address of the transmit descriptor
arch/powerpc/boot/cpm-serial.c +86 -46
203 lines not on this page · raw message
Signature · 13 lines
1.5.0 -- Laurent Pinchart CSE Semaphore Belgium Chaussée de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
Re: [PATCHv3 2/4] cpm-serial: Relocate CPM buffer descriptors and SMC parameter ram.
Quoted 4 lines · Laurent Pinchart
This patch relocates the buffer descriptors and the SMC parameter RAM at the end of the first CPM muram chunk, as described in the device tree. This allows device trees to stop excluding SMC parameter ram allocated by the boot loader from the CPM muram node.
It's usually a good idea to state that something is untested if that's the case. :-)
This patch cannot work as is.
arch/powerpc/boot/cpm-serial.c static unsigned char cpm_serial_getc(void) · line 204
Quoted 7 lines
arch/powerpc/boot/cpm-serial.c +7
-0+static int cpm_get_virtual_address (void *devp,void **addr,int ncells) +{ +unsigned long xaddr; +int n; + + n =getprop (devp,"virtual-reg" , addr, ncells *sizeof *addr); +if (n < ncells *sizeof *addr) {
You must cast the sizeof to a signed int; otherwise, a negative return from getprop will be "bigger" than the unsigned size, and you'll return garbage as the address.
arch/powerpc/boot/cpm-serial.c static unsigned char cpm_serial_getc(void) · line 209
Quoted 5 lines
arch/powerpc/boot/cpm-serial.c +5
-0+for (n =0 ; n < ncells; n++) { +if (!dt_xlate_reg (devp, n, &xaddr,NULL )) +return -1 ; + + addr[n] = (void *)xaddr;
(void *)
arch/powerpc/boot/cpm-serial.c static unsigned char cpm_serial_getc(void) · line 214
Quoted 5 lines
arch/powerpc/boot/cpm-serial.c +5
-0+ } + } + +return ncells; +}
This could be a generic bootwrapper function. It should return the number of resources (ncells is a misnomer) actually found, though, rather than failing if there are fewer than asked for. Let the caller decide if it's fatal.
arch/powerpc/boot/cpm-serial.c int cpm_console_init(void *devp, struct serial_console_data *scdp) · line 247
Quoted 8 lines
arch/powerpc/boot/cpm-serial.c +1
-2@@ -202,63 +243,62 @@ int cpm_console_init(void *devp, struct serial_console_data *scdp)else do_cmd = cpm1_cmd; - n =getprop (devp,"fsl,cpm-command" , &cpm_cmd,4 ); -if (n <4 ) +if (getprop (devp,"fsl,cpm-command" , &cpm_cmd,4 ) <sizeof cpm_cmd)return -1 ;
Standard kernel style is sizeof(foo), not sizeof foo.
Plus, if you're going to replace 4 with sizeof(cpm_cmd), do it both places. I don't really see the need, though; a cell is always 4 bytes.
arch/powerpc/boot/cpm-serial.c int cpm_console_init(void *devp, struct serial_console_data *scdp) · line 264
Quoted 11 lines
arch/powerpc/boot/cpm-serial.c +2
-9- n =getprop (parent,"virtual-reg" , reg_virt,sizeof (reg_virt)); -if (n < (int )sizeof (reg_virt)) { -if (!dt_xlate_reg (parent,0 , ®_phys,NULL )) -return -1 ; - - reg_virt[0 ] = (void *)reg_phys; - } - - cpcr = reg_virt[0 ]; +if (cpm_get_virtual_address (devp, &cpcr,1 ) <0 ) +return -1 ;
s/devp/parent/
Quoted 6 lines
arch/powerpc/boot/cpm-serial.c +0
-1muram =finddevice ("/soc/cpm/muram/data" );if (!muram)return -1 ;/* For bootwrapper-compatible device trees, we assume that the first -* entry has at least 18 bytes, and that #address-cells/#data-cells
arch/powerpc/boot/cpm-serial.c int cpm_console_init(void *devp, struct serial_console_data *scdp) · line 276
Quoted 10 lines
arch/powerpc/boot/cpm-serial.c +3
-4+* entry has at least 128 bytes, and that #address-cells/#data-cells * is one for both parent and child. */ - n =getprop (muram,"virtual-reg" , reg_virt,sizeof (reg_virt)); -if (n < (int )sizeof (reg_virt)) { -if (!dt_xlate_reg (muram,0 , ®_phys,NULL )) -return -1 ; +if (cpm_get_virtual_address (devp, &muram_addr,1 ) <0 ) +return -1 ;
s/devp/muram/
arch/powerpc/boot/cpm-serial.c int cpm_console_init(void *devp, struct serial_console_data *scdp) · line 279
Quoted 3 lines
arch/powerpc/boot/cpm-serial.c +3
-0+ +if (getprop (muram,"reg" , reg,sizeof reg) <sizeof reg) +return -1 ;
Should read into array of u32, not void *.
arch/powerpc/boot/cpm-serial.c int cpm_console_init(void *devp, struct serial_console_data *scdp) · line 292
Quoted 2 lines
arch/powerpc/boot/cpm-serial.c +2
-0+if (is_cpm2 && is_smc) { +u16 *smc_base = (u16 *)param;
(u16 *)
arch/powerpc/boot/cpm-serial.c int cpm_console_init(void *devp, struct serial_console_data *scdp) · line 297
Quoted 6 lines
arch/powerpc/boot/cpm-serial.c +4
-1+u16 pram_offset; - muram_start = reg_virt[0 ]; + pram_offset = cbd_offset -64 ; + pram_offset =_ALIGN_DOWN (pram_offset,64 ); + *smc_base = pram_offset;
Use out_be16().
The SMC should be stopped before you do this.
-Scott
Re: [PATCHv3 2/4] cpm-serial: Relocate CPM buffer descriptors and SMC parameter ram.
Quoted 8 lines · Scott Wood
Quoted 4 lines · Laurent Pinchart
This patch relocates the buffer descriptors and the SMC parameter RAM at the end of the first CPM muram chunk, as described in the device tree. This allows device trees to stop excluding SMC parameter ram allocated by the boot loader from the CPM muram node.
It's usually a good idea to state that something is untested if that's the case. :-)
Sorry. I'll state it clearly next time.
Quoted 22 lines
This patch cannot work as is.
arch/powerpc/boot/cpm-serial.c static unsigned char cpm_serial_getc(void) · line 204
Quoted 7 lines
arch/powerpc/boot/cpm-serial.c +7
-0+static int cpm_get_virtual_address (void *devp,void **addr,int ncells) +{ +unsigned long xaddr; +int n; + + n =getprop (devp,"virtual-reg" , addr, ncells *sizeof *addr); +if (n < ncells *sizeof *addr) {You must cast the sizeof to a signed int; otherwise, a negative return from getprop will be "bigger" than the unsigned size, and you'll return garbage as the address.
arch/powerpc/boot/cpm-serial.c static unsigned char cpm_serial_getc(void) · line 209
Quoted 5 lines
arch/powerpc/boot/cpm-serial.c +5
-0+for (n =0 ; n < ncells; n++) { +if (!dt_xlate_reg (devp, n, &xaddr,NULL )) +return -1 ; + + addr[n] = (void *)xaddr;(void *)
Quoted 10 lines
arch/powerpc/boot/cpm-serial.c static unsigned char cpm_serial_getc(void) · line 214
Quoted 5 lines
arch/powerpc/boot/cpm-serial.c +5
-0+ } + } + +return ncells; +}This could be a generic bootwrapper function. It should return the number of resources (ncells is a misnomer) actually found, though, rather than failing if there are fewer than asked for. Let the caller decide if it's fatal.
Ok. I'll move it to devtree.c.
Quoted 10 lines
arch/powerpc/boot/cpm-serial.c int cpm_console_init(void *devp, struct serial_console_data *scdp) · line 247
Quoted 8 lines
arch/powerpc/boot/cpm-serial.c +1
-2@@ -202,63 +243,62 @@ int cpm_console_init(void *devp, struct serial_console_data *scdp)else do_cmd = cpm1_cmd; - n =getprop (devp,"fsl,cpm-command" , &cpm_cmd,4 ); -if (n <4 ) +if (getprop (devp,"fsl,cpm-command" , &cpm_cmd,4 ) <sizeof cpm_cmd)return -1 ;Standard kernel style is sizeof(foo), not sizeof foo.
Ok.
Quoted 2 lines
Plus, if you're going to replace 4 with
sizeof(cpm_cmd), do it both places. I don't really see the need, though; a cell is always 4 bytes.
Ok, I'll keep 4.
Quoted 33 lines
arch/powerpc/boot/cpm-serial.c int cpm_console_init(void *devp, struct serial_console_data *scdp) · line 264
Quoted 11 lines
arch/powerpc/boot/cpm-serial.c +2
-9- n =getprop (parent,"virtual-reg" , reg_virt,sizeof (reg_virt)); -if (n < (int )sizeof (reg_virt)) { -if (!dt_xlate_reg (parent,0 , ®_phys,NULL )) -return -1 ; - - reg_virt[0 ] = (void *)reg_phys; - } - - cpcr = reg_virt[0 ]; +if (cpm_get_virtual_address (devp, &cpcr,1 ) <0 ) +return -1 ;s/devp/parent/
Quoted 6 lines
arch/powerpc/boot/cpm-serial.c +0
-1muram =finddevice ("/soc/cpm/muram/data" );if (!muram)return -1 ;/* For bootwrapper-compatible device trees, we assume that the first -* entry has at least 18 bytes, and that #address-cells/#data-cells arch/powerpc/boot/cpm-serial.c int cpm_console_init(void *devp, struct serial_console_data *scdp) · line 276
Quoted 10 lines
arch/powerpc/boot/cpm-serial.c +3
-4+* entry has at least 128 bytes, and that #address-cells/#data-cells * is one for both parent and child. */ - n =getprop (muram,"virtual-reg" , reg_virt,sizeof (reg_virt)); -if (n < (int )sizeof (reg_virt)) { -if (!dt_xlate_reg (muram,0 , ®_phys,NULL )) -return -1 ; +if (cpm_get_virtual_address (devp, &muram_addr,1 ) <0 ) +return -1 ;s/devp/muram/
Quoted 5 lines
arch/powerpc/boot/cpm-serial.c int cpm_console_init(void *devp, struct serial_console_data *scdp) · line 279
Quoted 3 lines
arch/powerpc/boot/cpm-serial.c +3
-0+ +if (getprop (muram,"reg" , reg,sizeof reg) <sizeof reg) +return -1 ;Should read into array of u32, not void *.
Ok.
Quoted 7 lines
arch/powerpc/boot/cpm-serial.c int cpm_console_init(void *devp, struct serial_console_data *scdp) · line 292
Quoted 2 lines
arch/powerpc/boot/cpm-serial.c +2
-0+if (is_cpm2 && is_smc) { +u16 *smc_base = (u16 *)param;(u16 *)
Quoted 2 lines
arch/powerpc/boot/cpm-serial.c +1
-0+u16 pram_offset;
Quoted 8 lines
arch/powerpc/boot/cpm-serial.c int cpm_console_init(void *devp, struct serial_console_data *scdp) · line 297
Quoted 4 lines
arch/powerpc/boot/cpm-serial.c +3
-1- muram_start = reg_virt[0 ]; + pram_offset = cbd_offset -64 ; + pram_offset =_ALIGN_DOWN (pram_offset,64 ); + *smc_base = pram_offset;Use
out_be16().The SMC should be stopped before you do this.
Right.
New patch comming.
Signature · 9 lines
Laurent Pinchart CSE Semaphore Belgium Chaussée de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75