From c792495fa35173eb773abcf944911df3d18b372e Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Tue, 6 Jul 2004 22:45:17 +0100 Subject: [PATCH] [PCMCIA] core socket sysfs support, export card type Patch from Dominik Brodowski 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 | 7 ++++ drivers/pcmcia/cs_internal.h | 3 ++ drivers/pcmcia/socket_sysfs.c | 76 +++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 drivers/pcmcia/socket_sysfs.c diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile index caefaebfb777d..86acf410a4019 100644 --- a/drivers/pcmcia/Makefile +++ b/drivers/pcmcia/Makefile @@ -18,7 +18,7 @@ obj-$(CONFIG_PCMCIA_SA1100) += sa11xx_core.o sa1100_cs.o obj-$(CONFIG_PCMCIA_SA1111) += sa11xx_core.o sa1111_cs.o obj-$(CONFIG_PCMCIA_PXA2XX) += pxa2xx_core.o pxa2xx_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 sa11xx_core-y += soc_common.o sa11xx_base.o diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 23ab71385a8ed..ee0170e0f421c 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -695,6 +695,13 @@ static int pccardd(void *__skt) skt->thread = NULL; complete_and_exit(&skt->thread_done, 0); } + if (pccard_sysfs_init(skt)) { + printk(KERN_WARNING "PCMCIA: unable to register sysfs attributes for socket 0x%p\n", + skt); + skt->thread = NULL; + class_device_unregister(&skt->dev); + complete_and_exit(&skt->thread_done, 0); + } complete(&skt->thread_done); add_wait_queue(&skt->thread_wait, &wait); diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index 88396d87be216..8aa7ac532fb8f 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -192,6 +192,9 @@ void undo_irq(u_int Attributes, int irq); 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 --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c new file mode 100644 index 0000000000000..7550b6d981036 --- /dev/null +++ b/drivers/pcmcia/socket_sysfs.c @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define IN_CARD_SERVICES +#include +#include +#include +#include +#include +#include +#include +#include +#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); +} -- 2.53.0