[PATCH 2/5] core socket sysfs support, export card type

Dominik Brodowski linux at dominikbrodowski.de
Tue May 11 22:28:35 BST 2004


Add a first socket-related sysfs entry; and to keep things ordered, do so in
a new file drivers/pcmcia/socket_sysfs.c. To keep things easy, all files
will be present all the time, even if no card is in the socket at a specific
moment -- however, accessing the file will result in -ENODEV then, so that

# cat /sys/class/pcmcia_socket/pcmcia_socket1/card_type

will cause an error message like

"cat: card_type: No such device"

which is quite self-explanatory.


The attribute "card_type" will return either
"16-bit" or "32-bit", depending on whether the PCCard is a 16-bit PCMCIA
card or a 32-bit CardBus card. The result "invalid" should not happen, and
if it happens, something strange is going on.

 drivers/pcmcia/Makefile       |    2 -
 drivers/pcmcia/cs.c           |    2 -
 drivers/pcmcia/cs_internal.h  |    3 +
 drivers/pcmcia/socket_sysfs.c |   76 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 81 insertions(+), 2 deletions(-)

diff -ruN linux-original/drivers/pcmcia/cs.c linux/drivers/pcmcia/cs.c
--- linux-original/drivers/pcmcia/cs.c	2004-05-11 19:24:35.281484784 +0200
+++ linux/drivers/pcmcia/cs.c	2004-05-11 19:20:03.551793976 +0200
@@ -689,7 +689,7 @@
 
 	/* register with the device core */
 	ret = class_device_register(&skt->dev);
-	if (ret) {
+	if (ret || pccard_sysfs_init(skt)) {
 		printk(KERN_WARNING "PCMCIA: unable to register socket 0x%p\n",
 			skt);
 		skt->thread = NULL;
diff -ruN linux-original/drivers/pcmcia/cs_internal.h linux/drivers/pcmcia/cs_internal.h
--- linux-original/drivers/pcmcia/cs_internal.h	2004-05-11 19:12:38.859397496 +0200
+++ linux/drivers/pcmcia/cs_internal.h	2004-05-11 19:21:23.907578040 +0200
@@ -190,6 +190,9 @@
 int adjust_resource_info(client_handle_t handle, adjust_t *adj);
 void release_resource_db(void);
 
+/* In socket_sysfs.c */
+int pccard_sysfs_init(struct pcmcia_socket *s);
+
 extern struct rw_semaphore pcmcia_socket_list_rwsem;
 extern struct list_head pcmcia_socket_list;
 
diff -ruN linux-original/drivers/pcmcia/Makefile linux/drivers/pcmcia/Makefile
--- linux-original/drivers/pcmcia/Makefile	2004-05-11 19:12:38.858397648 +0200
+++ linux/drivers/pcmcia/Makefile	2004-05-11 19:23:20.482855904 +0200
@@ -16,7 +16,7 @@
 obj-$(CONFIG_PCMCIA_SA1100)			+= sa11xx_core.o sa1100_cs.o
 obj-$(CONFIG_PCMCIA_SA1111)			+= sa11xx_core.o sa1111_cs.o
 
-pcmcia_core-y					+= cistpl.o rsrc_mgr.o bulkmem.o cs.o
+pcmcia_core-y					+= cistpl.o rsrc_mgr.o bulkmem.o cs.o socket_sysfs.o
 pcmcia_core-$(CONFIG_CARDBUS)			+= cardbus.o
 
 sa1111_cs-y					+= sa1111_generic.o
diff -ruN linux-original/drivers/pcmcia/socket_sysfs.c linux/drivers/pcmcia/socket_sysfs.c
--- linux-original/drivers/pcmcia/socket_sysfs.c	1970-01-01 01:00:00.000000000 +0100
+++ linux/drivers/pcmcia/socket_sysfs.c	2004-05-11 19:25:57.413998744 +0200
@@ -0,0 +1,76 @@
+/*
+ * socket_sysfs.c -- most of socket-related sysfs output
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * (C) 2003 - 2004		Dominik Brodowski
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/config.h>
+#include <linux/string.h>
+#include <linux/major.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/mm.h>
+#include <linux/interrupt.h>
+#include <linux/timer.h>
+#include <linux/ioport.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/pci.h>
+#include <linux/device.h>
+#include <linux/suspend.h>
+#include <asm/system.h>
+#include <asm/irq.h>
+
+#define IN_CARD_SERVICES
+#include <pcmcia/version.h>
+#include <pcmcia/cs_types.h>
+#include <pcmcia/ss.h>
+#include <pcmcia/cs.h>
+#include <pcmcia/bulkmem.h>
+#include <pcmcia/cistpl.h>
+#include <pcmcia/cisreg.h>
+#include <pcmcia/ds.h>
+#include "cs_internal.h"
+
+#define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev)
+
+static ssize_t pccard_show_type(struct class_device *dev, char *buf)
+{
+	int val;
+	struct pcmcia_socket *s = to_socket(dev);
+
+        if (!(s->state & SOCKET_PRESENT))
+                return -ENODEV;
+	s->ops->get_status(s, &val);
+	if (val & SS_CARDBUS)
+		return sprintf(buf, "32-bit\n");
+	if (val & SS_DETECT)
+		return sprintf(buf, "16-bit\n");
+	return sprintf(buf, "invalid\n");
+}
+static CLASS_DEVICE_ATTR(card_type, 0400, pccard_show_type, NULL);
+
+static struct class_device_attribute *pccard_socket_attributes[] = {
+	&class_device_attr_card_type,
+	NULL,
+};
+
+int pccard_sysfs_init(struct pcmcia_socket *s)
+{
+	struct class_device_attribute *attr;
+	unsigned int i;
+	int ret = 0;
+        for (i = 0; (attr = pccard_socket_attributes[i]); i++) {
+                if ((ret = class_device_create_file(&s->dev, attr)))
+			return (ret);
+        }
+	return (ret);
+}



More information about the linux-pcmcia mailing list