Skip to contentSkip to conversation

8xx: mpc885ads pcmcia support

PATCH In review Vitaly Bordug 3 participants 4 messages May 3, 2007 – May 5, 2007

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 8xx: mpc885ads pcmcia support

Adds support for PowerQuicc on-chip PCMCIA. The driver is implemented as of_device, so only arch/powerpc stuff is capable to use it, which now implies only mpc885ads reference board.

To cope with the code that should be hooked inside driver, but is really board specific (like set_voltage), global structure mpc8xx_pcmcia_ops holds necessary function pointers that are filled in the BSP code.

---

 arch/powerpc/boot/dts/mpc885ads.dts          |   12 +
 arch/powerpc/platforms/8xx/m8xx_setup.c      |    5 
 arch/powerpc/platforms/8xx/mpc885ads.h       |    5 
 arch/powerpc/platforms/8xx/mpc885ads_setup.c |   77 ++++++
 arch/powerpc/sysdev/fsl_soc.c                |   12 +
 drivers/pcmcia/Kconfig                       |    1 
 drivers/pcmcia/m8xx_pcmcia.c                 |  352 ++++++++++++--------------
 include/linux/fsl_devices.h                  |    5 
 8 files changed, 279 insertions(+), 190 deletions(-)
arch/powerpc/boot/dts/mpc885ads.dts +12 -0
index 110bf61..56a9f6a 100644
@@ -112,6 +112,18 @@
 			compatible = "CPM";
 		};
 
+               pcmcia@0080 {
+                       linux,phandle = <0080>;
+                       #interrupt-cells = <1>;
+                       #size-cells = <2>;
+                       compatible = "fsl,pq-pcmcia";
+                       device_type = "pcmcia";
+                       reg = <80 80>;
+                       clock-frequency = <2faf080>;
+                       interrupt-parent = <ff000000>;
+                       interrupts = <d 1>;
+		};
+
 		cpm@ff000000 {
 			linux,phandle = <ff000000>;
 			#address-cells = <1>;
arch/powerpc/platforms/8xx/m8xx_setup.c +5 -0
index 0901dba..f169355 100644
@@ -32,6 +32,7 @@
 #include <linux/root_dev.h>
 #include <linux/time.h>
 #include <linux/rtc.h>
+#include <linux/fsl_devices.h>
 
 #include <asm/mmu.h>
 #include <asm/reg.h>
@@ -49,6 +50,10 @@
 
 #include "sysdev/mpc8xx_pic.h"
 
+#ifdef CONFIG_PCMCIA_M8XX
+struct mpc8xx_pcmcia_ops m8xx_pcmcia_ops;
+#endif
+
 void m8xx_calibrate_decr(void);
 extern void m8xx_wdt_handler_install(bd_t *bp);
 extern int cpm_pic_init(void);
arch/powerpc/platforms/8xx/mpc885ads.h +5 -0
index 7c31aec..4439346 100644
@@ -91,5 +91,10 @@
 #define SICR_ENET_MASK	((uint)0x00ff0000)
 #define SICR_ENET_CLKRT	((uint)0x002c0000)
 
+/* Some internal interrupt registers use an 8-bit mask for the interrupt
+ * level instead of a number.
+ */
+#define mk_int_int_mask(IL) (1 << (7 - (IL/2)))
+
 #endif /* __ASM_MPC885ADS_H__ */
 #endif /* __KERNEL__ */
arch/powerpc/platforms/8xx/mpc885ads_setup.c +77 -0

101 lines not on this page · raw message

arch/powerpc/sysdev/fsl_soc.c +12 -0
index 8a123c7..01e4a40 100644
@@ -1028,6 +1028,18 @@ err:
 
 arch_initcall(fs_enet_of_init);
 
+static int __init fsl_pcmcia_of_init(void)
+{
+	struct device_node *np = NULL;
+	/*
+	 * Register all the devices which type is "pcmcia"
+	 */
+	while ((np = of_find_compatible_node(np, "pcmcia", "fsl,pq-pcmcia")) != NULL)
+		of_platform_device_create(np, "m8xx-pcmcia", NULL);
+	return 0;
+}
+
+arch_initcall(fsl_pcmcia_of_init);
 
 static const char *smc_regs = "regs";
 static const char *smc_pram = "pram";
drivers/pcmcia/Kconfig +1 -0
index 35f8864..c3fd55d 100644
@@ -183,6 +183,7 @@ config PCMCIA_M8XX
         tristate "MPC8xx PCMCIA support"
         depends on PCMCIA && PPC && 8xx 
         select PCCARD_IODYN
+	select PCCARD_NONSTATIC
         help
         Say Y here to include support for PowerPC 8xx series PCMCIA
         controller.
drivers/pcmcia/m8xx_pcmcia.c +162 -190

593 lines not on this page · raw message

include/linux/fsl_devices.h +5 -0
index 73710d6..5bd8be1 100644
@@ -120,5 +120,10 @@ struct fsl_spi_platform_data {
 	u32	sysclk;
 };
 
+struct mpc8xx_pcmcia_ops {
+        void(*hw_ctrl)(int slot, int enable);
+        int(*voltage_set)(int slot, int vcc, int vpp);
+};
+                
 #endif /* _FSL_DEVICE_H_ */
 #endif /* __KERNEL__ */
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Vitaly Bordug

Adds support for PowerQuicc on-chip PCMCIA. The driver is implemented as of_device, so only arch/powerpc stuff is capable to use it, which now implies only mpc885ads reference board.

To cope with the code that should be hooked inside driver, but is really board specific (like set_voltage), global structure mpc8xx_pcmcia_ops holds necessary function pointers that are filled in the BSP code.

#2 lore raw
In reply to Vitaly Bordug
Quoted 9 lines · On Fri, 04 May 2007 03:57:51 +0400 Vitaly Bordug <[email protected]>…

Adds support for PowerQuicc on-chip PCMCIA. The driver is implemented as of_device, so only arch/powerpc stuff is capable to use it, which now implies only mpc885ads reference board.

To cope with the code that should be hooked inside driver, but is really board specific (like set_voltage), global structure mpc8xx_pcmcia_ops holds necessary function pointers that are filled in the BSP code.

argh.

akpm:/home/akpm> grep '^.* ' x | wc -l
72

please, Linux uses hard-tabs, not spacespacespacespacespacespacespacespace everywhere.

Quoted 17 lines
arch/powerpc/boot/dts/mpc885ads.dts +1 -0
+
 		cpm@ff000000 {
 			linux,phandle = <ff000000>;
 			#address-cells = <1>;
arch/powerpc/platforms/8xx/m8xx_setup.c +1 -0
index 0901dba..f169355 100644
@@ -32,6 +32,7 @@
 #include <linux/root_dev.h>
 #include <linux/time.h>
 #include <linux/rtc.h>
+#include <linux/fsl_devices.h>
 
 #include <asm/mmu.h>
 #include <asm/reg.h>

arch/powerpc/platforms/8xx/m8xx_setup.c line 55

Quoted 6 lines
arch/powerpc/platforms/8xx/m8xx_setup.c +3 -0
@@ -49,6 +50,10 @@
 
 #include "sysdev/mpc8xx_pic.h"
 
+#ifdef CONFIG_PCMCIA_M8XX
+struct mpc8xx_pcmcia_ops m8xx_pcmcia_ops;
+#endif

Please declare this in a header file.

arch/powerpc/platforms/8xx/m8xx_setup.c line 58

Quoted 3 lines
arch/powerpc/platforms/8xx/m8xx_setup.c +3 -0
+/* Some internal interrupt registers use an 8-bit mask for the interrupt
+ * level instead of a number.
+ */

Standard Linux commenting style is:

/*
* Some internal interrupt registers use an 8-bit mask for the interrupt
* level instead of a number.
*/

arch/powerpc/platforms/8xx/m8xx_setup.c line 59

Quoted 1 line
arch/powerpc/platforms/8xx/m8xx_setup.c +1 -0
+#define mk_int_int_mask(IL) (1 << (7 - (IL/2)))

Insufficiently parenthesised?

static inline functions are preferred.

arch/powerpc/platforms/8xx/m8xx_setup.c

Quoted 2 lines
arch/powerpc/platforms/8xx/m8xx_setup.c +2 -0
+#ifdef CONFIG_PCMCIA_M8XX
+extern struct mpc8xx_pcmcia_ops m8xx_pcmcia_ops;

Please don't ever put extern declarations in C files. Declare it in a header, include that header in the C file which contains the definition as well as within all C files which use the symbol.

Quoted 24 lines
arch/powerpc/platforms/8xx/m8xx_setup.c +10 -0
+static void pcmcia_hw_setup(int slot, int enable);
+static int pcmcia_set_voltage(int slot, int vcc, int vpp);
+#endif
+
 void __init mpc885ads_board_setup(void)
 {
 	cpm8xx_t *cp;
@@ -115,6 +122,12 @@ void __init mpc885ads_board_setup(void)
 	immr_unmap(io_port);
 
 #endif
+
+#ifdef CONFIG_PCMCIA_M8XX
+	/*Set up board specific hook-ups*/
+	m8xx_pcmcia_ops.hw_ctrl = pcmcia_hw_setup;
+	m8xx_pcmcia_ops.voltage_set = pcmcia_set_voltage;
+#endif
 }
 
 
@@ -322,6 +335,70 @@ void init_smc_ioports(struct fs_uart_platform_info *data)
 	}
 }
 

arch/powerpc/platforms/8xx/m8xx_setup.c void init_smc_ioports(struct fs_uart_platform_info *data) · line 347

Quoted 10 lines
arch/powerpc/platforms/8xx/m8xx_setup.c +10 -0
+#ifdef CONFIG_PCMCIA_M8XX
+static void pcmcia_hw_setup(int slot, int enable)
+{
+	unsigned *bcsr_io;
+
+	bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
+	if (enable)
+	clrbits32(bcsr_io, BCSR1_PCCEN);
+	else
+		setbits32(bcsr_io, BCSR1_PCCEN);

Missing a tab.

Quoted 12 lines
arch/powerpc/platforms/8xx/m8xx_setup.c +12 -0
+	iounmap(bcsr_io);
+}
+
+static int pcmcia_set_voltage(int slot, int vcc, int vpp)
+{
+        u32 reg = 0;
+        unsigned *bcsr_io;
+
+        bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
+
+        switch(vcc) {
+                case 0:

arch/powerpc/platforms/8xx/m8xx_setup.c void init_smc_ioports(struct fs_uart_platform_info *data) · line 369

Quoted 10 lines
arch/powerpc/platforms/8xx/m8xx_setup.c +10 -0
+                        break;
+                case 33:
+                        reg |= BCSR1_PCCVCC0;
+                        break;
+                case 50:
+                        reg |= BCSR1_PCCVCC1;
+                        break;
+                default:
+                        return 1;
+        }

Standard Linux layout for switch statements is:

        switch(vcc) {
	case 0:
		break;
	case 33:
		reg |= BCSR1_PCCVCC0;
		break;
	case 50:
		reg |= BCSR1_PCCVCC1;
		break;
	default:
		return 1;
        }
Quoted 8 lines
arch/powerpc/platforms/8xx/m8xx_setup.c +8 -0
+        switch(vpp) {
+                case 0:
+                        break;
+                case 33:
+                case 50:
+                        if(vcc == vpp)
+                                reg |= BCSR1_PCCVPP1;
+                        else

arch/powerpc/platforms/8xx/m8xx_setup.c void init_smc_ioports(struct fs_uart_platform_info *data) · line 387

Quoted 10 lines
arch/powerpc/platforms/8xx/m8xx_setup.c +10 -0
+                                return 1;
+                        break;
+                case 120:
+                        if ((vcc == 33) || (vcc == 50))
+                                reg |= BCSR1_PCCVPP0;
+                        else
+                                return 1;
+                default:
+                        return 1;
+        }

Ditto.

Quoted 20 lines
arch/powerpc/platforms/8xx/m8xx_setup.c +11 -0
+        /* first, turn off all power */
+        clrbits32(bcsr_io, 0x00610000);
+
+        /* enable new powersettings */
+        setbits32(bcsr_io, reg);
+
+        iounmap(bcsr_io);
+        return 0;
+}
+#endif
+
 int platform_device_skip(const char *model, int id)
 {
 #ifdef CONFIG_MPC8xx_SECOND_ETH_SCC3
arch/powerpc/sysdev/fsl_soc.c +0 -0
index 8a123c7..01e4a40 100644
@@ -1028,6 +1028,18 @@ err:
 

arch/powerpc/sysdev/fsl_soc.c err: · line 1038

Quoted 10 lines
arch/powerpc/sysdev/fsl_soc.c +8 -0
 arch_initcall(fs_enet_of_init);
 
+static int __init fsl_pcmcia_of_init(void)
+{
+	struct device_node *np = NULL;
+	/*
+	 * Register all the devices which type is "pcmcia"
+	 */
+	while ((np = of_find_compatible_node(np, "pcmcia", "fsl,pq-pcmcia")) != NULL)
+		of_platform_device_create(np, "m8xx-pcmcia", NULL);

please try to fit code into 80 columns.

arch/powerpc/sysdev/fsl_soc.c err: · line 1039

Quoted 3 lines
arch/powerpc/sysdev/fsl_soc.c +1 -1
-static DEFINE_SPINLOCK(events_lock);
+static spinlock_t events_lock = SPIN_LOCK_UNLOCKED;

This is wrong. DEFINE_SPINLOCK is required for correct lockdep operation.

arch/powerpc/sysdev/fsl_soc.c err: · line 1042

Quoted 3 lines
arch/powerpc/sysdev/fsl_soc.c +3 -0
+#define hardware_enable(_slot_) m8xx_pcmcia_ops.hw_ctrl(_slot_, 1)
+#define hardware_disable(_slot_) m8xx_pcmcia_ops.hw_ctrl(_slot_, 0)
+#define voltage_set(slot, vcc, vpp) m8xx_pcmcia_ops.voltage_set(slot, vcc, vpp)

static inline functions are preferred. One reason is that people are more inclined to add comments to them than to macros.

arch/powerpc/sysdev/fsl_soc.c err: · line 1043

Quoted 2 lines
arch/powerpc/sysdev/fsl_soc.c +1 -1
-static DEFINE_SPINLOCK(pending_event_lock);
+static spinlock_t pending_event_lock = SPIN_LOCK_UNLOCKED;

again, you added a bug.

arch/powerpc/sysdev/fsl_soc.c err: · line 1044

Quoted 1 line
arch/powerpc/sysdev/fsl_soc.c +1 -0
+	for(i = 0; i < PCMCIA_SOCKETS_NO; i++){

No, we format `for' statements as:

	for (i = 0; i < PCMCIA_SOCKETS_NO; i++) {

arch/powerpc/sysdev/fsl_soc.c err:

Quoted 4 lines
arch/powerpc/sysdev/fsl_soc.c +3 -0
+		w = (void *) &pcmcia->pcmc_pbr0;
 
+		out_be32(&pcmcia->pcmc_pscr, M8XX_PCMCIA_MASK(i));
+		out_be32(&pcmcia->pcmc_per, in_be32(&pcmcia->pcmc_per) & ~M8XX_PCMCIA_MASK(i));

80-cols

arch/powerpc/sysdev/fsl_soc.c

Quoted 6 lines
arch/powerpc/sysdev/fsl_soc.c +6 -0
+
+		/* turn off interrupt and disable CxOE */
+		out_be32(M8XX_PGCRX(i), M8XX_PGCRX_CXOE);
+
+		/* turn off memory windows */
+		for(m = 0; m < PCMCIA_MEM_WIN_NO; m++) {

formatting

Quoted 23 lines
arch/powerpc/sysdev/fsl_soc.c +15 -3
+			out_be32(&w->or, 0); /* set to not valid */
+			w++;
+		}
+
+		/* turn off voltage */
+		voltage_set(i, 0, 0);
+
+		/* disable external hardware */
+		hardware_disable(i);
+	}
 	for (i = 0; i < PCMCIA_SOCKETS_NO; i++)
 		pcmcia_unregister_socket(&socket[i].socket);
 
-	m8xx_shutdown();
+	free_irq(pcmcia_schlvl, NULL);
+
+	return 0;
+}
 
 
-	platform_device_unregister(&m8xx_device);
-	driver_unregister(&m8xx_driver);
+#ifdef CONFIG_PM

arch/powerpc/sysdev/fsl_soc.c

Quoted 10 lines
arch/powerpc/sysdev/fsl_soc.c +10 -0
+static int m8xx_suspend(struct platform_device *pdev, pm_message_t state)
+{
+        return pcmcia_socket_dev_suspend(&pdev->dev, state);
+}
+
+static int m8xx_resume(struct platform_device *pdev)
+{
+        return pcmcia_socket_dev_resume(&pdev->dev);
+}
+#endif

Here, use

#else
#define m8xx_suspend NULL
#define m8xx_resume NULL
#endif

Quoted 9 lines
arch/powerpc/sysdev/fsl_soc.c +9 -0
+static struct of_device_id m8xx_pcmcia_match[] = {
+	{
+		.type = "pcmcia",
+		.compatible = "fsl,pq-pcmcia",
+	},
+	{},
+};
+
+MODULE_DEVICE_TABLE(of, m8xx_pcmcia_match);

arch/powerpc/sysdev/fsl_soc.c

Quoted 10 lines
arch/powerpc/sysdev/fsl_soc.c +10 -0
+
+static struct of_platform_driver m8xx_pcmcia_driver = {
+	.name		= (char *) driver_name,
+	.match_table	= m8xx_pcmcia_match,
+	.probe		= m8xx_probe,
+	.remove		= m8xx_remove,
+#ifdef CONFIG_PM
+	.suspend	= m8xx_suspend,
+	.resume		= m8xx_resume,
+#endif

then remove this ifdef.

#3 lore raw
Quoted 14 lines · On Fri, 4 May 2007 12:35:43 -0700 Andrew Morton wrote:
Quoted 10 lines · On Fri, 04 May 2007 03:57:51 +0400 Vitaly Bordug <[email protected]>…

Adds support for PowerQuicc on-chip PCMCIA. The driver is implemented as of_device, so only arch/powerpc stuff is capable to use it, which now implies only mpc885ads reference board.

To cope with the code that should be hooked inside driver, but is really board specific (like set_voltage), global structure mpc8xx_pcmcia_ops holds necessary function pointers that are filled in the BSP code.

Quoted 8 lines

argh.

akpm:/home/akpm> grep '^.* ' x | wc -l
72

please, Linux uses hard-tabs, not spacespacespacespacespacespacespacespace everywhere.

Whoops. That must've survived being copypasted from the original m8xx_pcmcia.c. That reminds me to do Lindent on the affected sources but that is subject for another patch. Sorry for the hassle.

Apparently all the issues were correct, and I'll follow-up with the reworked patch. Thanks for looking at it.

Signature · 1 line
Sincerely, Vitaly