char interface to sdio, chdio.c
Hi Stephen.
I had some people ask me about a sdio userspace interface, and ran across the chdio.c file as found in the MSM android kernel trees:
https://android.googlesource.com/kernel/msm/+/57b74303d6f033ab04be039379f6661337fb9279
Any reason why this hasn't been submitted upstream? Or has it, and was it rejected?
Also, what userspace code uses this? Is there some android-specific code somewhere that does a weird mix of sysfs and char control of the hardware? And what type of SDIO devices are controlled with this?
thanks,
greg k-h
Quoted 4 lines · Greg KH
Hi Stephen.
I had some people ask me about a sdio userspace interface, and ran across the
chdio.cfile as found in the MSM android kernel trees:
You mean csdio.c right?
Quoted 2 lines
https://android.googlesource.com/kernel/msm/+/57b74303d6f033ab04be039379f6661337fb9279
As you can see in the commit text there, the commit I authored is actually a squash of three patches from some previous android kernel that we did (looks like it was android-msm-2.6.35) and it's been almost 4 years since those patches were written. The three original commits weren't authored by me so I really don't know the intimate details of this driver.
Quoted 3 lines
Any reason why this hasn't been submitted upstream? Or has it, and was it rejected?
I don't believe we ever submitted this upstream.
Quoted 4 lines
Also, what userspace code uses this? Is there some android-specific code somewhere that does a weird mix of sysfs and char control of the hardware? And what type of SDIO devices are controlled with this?
If I recall correctly this driver is for communicating with an external modem (in this case it was the Gobi 9k). We used the sdio interface to do some IPC stuff with the modem over sdio, mainly because back then the SoC didn't have an LTE capable modem, but the Gobi modem was LTE capable. Slap the two chips together and you have an LTE phone while you wait for us to deliver the first SoC with an integrated LTE modem (msm8960).
The userspace component is the same proprietary software that's used to make phone calls on android phones. I'd have to go dig around to find that code and confirm if it's using sysfs and char control. I'd rather not spend the time digging so let's assume it's doing that unless you have a more specific question in mind?
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 7 lines · Stephen Boyd
Quoted 4 lines · Greg KH
Hi Stephen.
I had some people ask me about a sdio userspace interface, and ran across the
chdio.cfile as found in the MSM android kernel trees:You mean
csdio.cright?
Ick, yes, sorry about that.
Quoted 9 lines
Quoted 2 lines
https://android.googlesource.com/kernel/msm/+/57b74303d6f033ab04be039379f6661337fb9279
As you can see in the commit text there, the commit I authored is actually a squash of three patches from some previous android kernel that we did (looks like it was android-msm-2.6.35) and it's been almost 4 years since those patches were written. The three original commits weren't authored by me so I really don't know the intimate details of this driver.
Yes, I know you didn't write this version, but you did the "mushing together", which was nice of you, and presumably you did it for a good reason :)
Quoted 4 lines
Quoted 2 lines
Any reason why this hasn't been submitted upstream? Or has it, and was it rejected?
I don't believe we ever submitted this upstream.
Why not?
Quoted 11 lines
Quoted 3 lines
Also, what userspace code uses this? Is there some android-specific code somewhere that does a weird mix of sysfs and char control of the hardware? And what type of SDIO devices are controlled with this?
If I recall correctly this driver is for communicating with an external modem (in this case it was the Gobi 9k). We used the sdio interface to do some IPC stuff with the modem over sdio, mainly because back then the SoC didn't have an LTE capable modem, but the Gobi modem was LTE capable. Slap the two chips together and you have an LTE phone while you wait for us to deliver the first SoC with an integrated LTE modem (msm8960).
Quoted 5 lines
The userspace component is the same proprietary software that's used to make phone calls on android phones. I'd have to go dig around to find that code and confirm if it's using sysfs and char control. I'd rather not spend the time digging so let's assume it's doing that unless you have a more specific question in mind?
My specific question is why 2 different interfaces?
Some people are looking at a way to do SDIO from userspace, if needed, and I was pointed at this driver, and wanted to figure out why it never was merged. If it's useful, and people are using it in phones today, that's a good reason to merge it in, right?
So, any objection for me taking it as-is, as long as my audit of the code passes?
thanks,
greg k-h
Quoted 7 lines · Greg KH
Quoted 5 lines · Stephen Boyd
Quoted 2 lines · Greg KH
Any reason why this hasn't been submitted upstream? Or has it, and was it rejected?
I don't believe we ever submitted this upstream.
Why not?
Sorry, I don't know. It's not upstreamed by me because there aren't any use cases on the devices I have. I only mushed the changes together because we were taking a look at the code we accumulated over the years. Soon after I did that we swept through and deleted this driver from our tree because it wasn't used by the platforms we're still supporting.
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Also, what userspace code uses this? Is there some android-specific code somewhere that does a weird mix of sysfs and char control of the hardware? And what type of SDIO devices are controlled with this?
If I recall correctly this driver is for communicating with an external modem (in this case it was the Gobi 9k). We used the sdio interface to do some IPC stuff with the modem over sdio, mainly because back then the SoC didn't have an LTE capable modem, but the Gobi modem was LTE capable. Slap the two chips together and you have an LTE phone while you wait for us to deliver the first SoC with an integrated LTE modem (msm8960).
Quoted 6 lines
Quoted 5 lines
The userspace component is the same proprietary software that's used to make phone calls on android phones. I'd have to go dig around to find that code and confirm if it's using sysfs and char control. I'd rather not spend the time digging so let's assume it's doing that unless you have a more specific question in mind?
My specific question is why 2 different interfaces?
Ok. It definitely looks odd to support set/get of the VDD with sysfs and ioctl interfaces. I'm just guessing, but I suspect it's a permissions thing given that the patch that introduces the VDD stuff also updates the permissions of the device node. Of course, the commit text only mentions an ioctl, nothing about sysfs. The only other sysfs stuff seems to be module parameters to change the vendor ids.
I'll have to go repo diving to figure out if the sysfs interface was ever used. Maybe Alex or Konstantin can respond before I have to do that.
Quoted 5 lines
Some people are looking at a way to do SDIO from userspace, if needed, and I was pointed at this driver, and wanted to figure out why it never was merged. If it's useful, and people are using it in phones today, that's a good reason to merge it in, right?
Sure I imagine some phone somewhere is using it. Unfortunately I don't have one and I don't know of anyone working on getting support for those phones in the mainline kernel.
Quoted 3 lines
So, any objection for me taking it as-is, as long as my audit of the code passes?
No objections here.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 9 lines · Stephen Boyd
Quoted 1 line · Greg KH
My specific question is why 2 different interfaces?
Ok. It definitely looks odd to support set/get of the VDD with sysfs and ioctl interfaces. I'm just guessing, but I suspect it's a permissions thing given that the patch that introduces the VDD stuff also updates the permissions of the device node. Of course, the commit text only mentions an ioctl, nothing about sysfs. The only other sysfs stuff seems to be module parameters to change the vendor ids.
Quoted 4 lines
I'll have to go repo diving to figure out if the sysfs interface was ever used. Maybe Alex or Konstantin can respond before I have to do that.
I couldn't find any usage of the sysfs interface. The only thing I see used is the host_name field when the module is inserted, if that even happens at all (I'm not sure because it's behind some ifdef that may or may not be defined). Sorry this doesn't explain why there are two different interfaces for the VDD stuff. Hopefully Alex or Konstantin can help.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 15 lines · Stephen Boyd
Quoted 9 lines · Stephen Boyd
Quoted 1 line · Greg KH
My specific question is why 2 different interfaces?
Ok. It definitely looks odd to support set/get of the VDD with sysfs and ioctl interfaces. I'm just guessing, but I suspect it's a permissions thing given that the patch that introduces the VDD stuff also updates the permissions of the device node. Of course, the commit text only mentions an ioctl, nothing about sysfs. The only other sysfs stuff seems to be module parameters to change the vendor ids.
Quoted 4 lines
I'll have to go repo diving to figure out if the sysfs interface was ever used. Maybe Alex or Konstantin can respond before I have to do that.
Quoted 6 lines
I couldn't find any usage of the sysfs interface. The only thing I see used is the
host_namefield when the module is inserted, if that even happens at all (I'm not sure because it's behind some ifdef that may or may not be defined). Sorry this doesn't explain why there are two different interfaces for the VDD stuff. Hopefully Alex or Konstantin can help.
Thanks for looking.
Alex and/or Konstantin, any objection to me removing the sysfs interface on this driver, and just using the char device ioctl hellhole^WAPI instead?
thanks,
greg k-h
Quoted 15 lines · Stephen Boyd
Quoted 9 lines · Stephen Boyd
Quoted 1 line · Greg KH
My specific question is why 2 different interfaces?
Ok. It definitely looks odd to support set/get of the VDD with sysfs and ioctl interfaces. I'm just guessing, but I suspect it's a permissions thing given that the patch that introduces the VDD stuff also updates the permissions of the device node. Of course, the commit text only mentions an ioctl, nothing about sysfs. The only other sysfs stuff seems to be module parameters to change the vendor ids.
Quoted 4 lines
I'll have to go repo diving to figure out if the sysfs interface was ever used. Maybe Alex or Konstantin can respond before I have to do that.
Quoted 6 lines
I couldn't find any usage of the sysfs interface. The only thing I see used is the
host_namefield when the module is inserted, if that even happens at all (I'm not sure because it's behind some ifdef that may or may not be defined). Sorry this doesn't explain why there are two different interfaces for the VDD stuff. Hopefully Alex or Konstantin can help.
The duplication of the vdd interface is odd, I'll just go delete it.
In looking further at the code, it only supports 1 single device, set at build time, or module load time. That's not good, or generic. Any objection to me making it so it can support any sdio device in the system, and multiple devices as well, and actually work on a 64bit kernel, with multiple cores?
Oh, and this obviously didn't run on a phone that had a kernel log enabled, as it logs every single little thing that happens to the device, just short of a raw byte stream. I'll fix that up, and I got it building on a 3.16-rc kernel. Patch that builds is below if anyone is curious.
Oh, and checkout the code that goes and modifies the permissions of the device node in /dev/ from the kernel itself. The hoops Android developers have to go through because they were not using a udev-like programs is crazy. Hopefully devtmpfs is being used these days...
thanks,
greg k-h
----------------------
mmc: Char SDIO Device Driver
Squashed commit of the following:
commit c3fb53893cbc4b5e217ef176010d1b88982a9454
Author: Alexander Kolesnikov <[email protected]> Date: Wed Sep 15 17:16:52 2010 +0200
csdio: Set/get vdd ioctl support
Implement power up/down sequence for internal UBM chip. This commit includes generic, platform independent part.
CRs-Fixed: 255849
commit e1ba27311fcf3de2a5ca9a3fc1303328720dd120
Author: Nela Gurevich <[email protected]> Date: Thu Aug 19 14:00:09 2010 +0300
csdio: Move csdio.h to kernel/include
commit 31d1b09c677c26efb71fa36ff6fe1e7f2d83abbc
Author: Alexander Kolesnikov <[email protected]> Date: Tue Aug 10 13:26:20 2010 +0300
mmc: Char SDIO Device Driver
The Char SDIO Device Driver is an interface which exposes an SDIO card/function from kernel space as a char device in user space.
--- Documentation/csdio.txt | 189 ++++++++ drivers/char/Kconfig | 23 drivers/char/Makefile | 1 drivers/char/csdio.c | 1070 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/csdio.h | 37 + include/uapi/linux/Kbuild | 1 6 files changed, 1321 insertions(+)
Documentation/csdio.txt new file +189 -0
@@ -0,0 +1,189 @@ +Introduction +============ +The Char SDIO Device Driver is an interface which exposes an SDIO +card/function from kernel space as a char device in user space. + +The driver doesn't interact with any HW directly. It relies on SDIO +card/function interface provided as a part of Linux kernel. + +Hardware description +==================== +Each SDIO device/card contains an SDIO client HW block. +The host interacts with the device by sending byte sequences called +command (CMD). Some commands can be followed by data blocks. The +device sends back a byte sequence called response (R) and a data +block if required. CMD3, CMD5 and CMD7 are used to initialize the +device. CMD52 and CMD53 are used to access the device. Command +format and properties are defined by SDIO Specification document +published by SD Association: + http://www.sdcard.org/developers/tech/sdio/. + +CMD52 and CMD53 can access up to 8 address spaces called Functions. +Function 0 contains system information predefined by SD/SDIO +standard and Functions 1-7 are defined by the SDIO device +manufacturer. + +An SDIO device/card can send an interrupt to SDIO host. This +interrupt is intercepted and handled by SDIO host. + +Software description +==================== +Linux provides a framework for handling SDIO devices. It implements +kind of plug-and-play model in which the Linux SDIO Host Driver is +responsible for initializing an SDIO device upon insertion. It also +reads device/card identification information and enumerates functions +provided by the device and then looks up in the list of +preregistered user SDIO drivers for a suitable one. + +During its lifecycle the user SDIO driver interacts with the Linux +SDIO Host Driver in order to send/receive information to/from SDIO +device/card. The user SDIO driver doesn't work with CMD52/CMD53 +directly. Instead it uses an abstraction provided by the Linux SDIO +Host Driver. + +The Linux SDIO Host Driver is also in charge of handling SDIO +interrupts. User SDIO driver can register its own callback in SDIO +Host Driver and get a notification about interrupt event. + +The Char SDIO Device Driver follows the design guidelines mentioned +above. It provides the following functionality: + + - Register itself in the user SDIO drivers list; + - Handle Probe event upon insertion of supported card/device; + - Creates and maintains a char device driver for each SDIO Function + found in the card/device; + - Translates read/write/ioctl calls to appropriate SDIO call + sequences; + +In order to handle general SDIO configuration functionality and +Function 0 the Char SDIO Device Driver provides additional +simplified char device driver. + +The Manufacturer and Device IDs of handled SDIO device should be +provided as parameters for kernel module or as configuration +parameters in case of statically linked driver. + +Design +====== +The main goal of the Char SDIO Device Driver is to expose an SDIO +card/device from kernel space to user space as a char device driver. +The driver should be generic and simple as far as possible. + +The biggest design tradeoff is maintaining a balance between the +system call overhead required to initiate an SDIO transaction from +user space and overall SDIO communication performance. But luckily, +because of nature of SDIO protocol, this overhead is negligible +comparing to time required to execute SDIO transaction itself. So, +each CMD52 (read or write) consists from single ioctl system call. +And each CMD53 invokes single ioctl system call followed by read or +write system call. + +The Char SDIO Device Driver registers its own class of the devices +called 'csdio'. This class will serve as a common roof for all SDIO +devices served by different instances of the Char SDIO Device Driver. +Additional benefit from maintaining its own class is the driver +ability to overwrite default permissions of the dev nodes created by +the driver. + +Power Management +================ +None + +SMP/multi-core +============== +The driver does not anticipate any issues related to multi-core +since it is expected to run on one core only. + +Security +======== +None + +Performance +=========== +None + +Interface +========= +The Char SDIO Device Driver has two char device interfaces: + - Control Interface; + - Function Interface. + +Char SDIO Device Driver Control Interface consists of: + - open() - device node is /dev/csdio0; + - close() + - ioctl() - the following options are available: + - CSDIO_IOC_ENABLE_HIGHSPEED_MODE; + - CSDIO_IOC_SET_DATA_TRANSFER_CLOCKS; + - CSDIO_IOC_ENABLE_ISR; + - CSDIO_IOC_DISABLE_ISR. + +Char SDIO Device Driver Function Interface consists of: + - open() - device node is /dev/csdiofX, where X is Function Id; + - close() + - read() - send CMD53 read; + - write() - send CMD53 write; + - ioctl() - the following options are available: + - CSDIO_IOC_SET_OP_CODE - 0 fixed adrress, 1 autoincrement. + - CSDIO_IOC_FUNCTION_SET_BLOCK_SIZE; + - CSDIO_IOC_SET_BLOCK_MODE - 0 byte mode, 1 block mode; + - CSDIO_IOC_CMD52 - execute CMD52, receives the + following structure as a parameter: + struct csdio_cmd52_ctrl_t { + uint32_t m_write; // 0 - read, 1 -write + uint32_t m_address; + uint32_t m_data; // data to write or read data + uint32_t m_ret; // command execution status + }__attribute__ ((packed)); + - CSDIO_IOC_CMD53 - setup CMD53 data transfer, receives the + following structure as a parameter: + struct csdio_cmd53_ctrl_t { + uint32_t m_block_mode; + uint32_t m_op_code; + uint32_t m_address; + }__attribute__ ((packed)); + - CSDIO_IOC_CONNECT_ISR; + - CSDIO_IOC_DISCONNECT_ISR; + - CSDIO_IOC_GET_VDD; + - CSDIO_IOC_SET_VDD. + +Additionally, user space application can use fcntl system call with +parameters F_SETOWN and F_SETFL in order to set an asynchronous +callback for SDIO interrupt. + +Driver parameters +================= +If the driver is compiled as a kernel module, the following +parameters can be used in order to provide Manufacturer and Device IDs +upon module download: + - csdio_vendor_id; + - csdio_device_id. +If the driver is intended to work with specific SDIO host the +host_name parameter should be added followed by the name of the MMC +host platform device. + +Config options +============== +These are the kernel configuration options: + - CONFIG_CSDIO_VENDOR_ID; + - CONFIG_CSDIO_DEVICE_ID. + +Dependencies +============ +The Char SDIO Device Driver depends on Linux SDIO Host Driver. + +User space utilities +==================== +None + +Other +===== +None + +Known issues +============ +None + +To do +===== +Provide mechanism to support a number of SDIO devices simultaneously +connected to different SDIO hosts.
drivers/char/Kconfig +23 -0
@@ -600,5 +600,28 @@ config TILE_SROM device appear much like a simple EEPROM, and knows how to partition a single ROM for multiple purposes. +config MMC_GENERIC_CSDIO + tristate "Generic sdio driver" + default n + help + SDIO function driver that extends SDIO card as character device + in user space. + +config CSDIO_VENDOR_ID + hex "Card VendorId" + depends on MMC_GENERIC_CSDIO + default "0" + help + Enter vendor id for targeted sdio device, this may be overwritten by + module parameters. + +config CSDIO_DEVICE_ID + hex "CardDeviceId" + depends on MMC_GENERIC_CSDIO + default "0" + help + Enter device id for targeted sdio device, this may be overwritten by + module parameters. +. endmenu
drivers/char/Makefile +1 -0
@@ -61,3 +61,4 @@ obj-$(CONFIG_JS_RTC) += js-rtc.o js-rtc-y = rtc.o obj-$(CONFIG_TILE_SROM) += tile-srom.o +obj-$(CONFIG_MMC_GENERIC_CSDIO) += csdio.o
drivers/char/csdio.c new file +1070 -0
1,070 lines not on this page · raw message
include/linux/csdio.h new file +37 -0
@@ -0,0 +1,37 @@ +#ifndef CSDIO_H +#define CSDIO_H + +#include <linux/ioctl.h> + +#define CSDIO_IOC_MAGIC 'm' + +#define CSDIO_IOC_ENABLE_HIGHSPEED_MODE _IO(CSDIO_IOC_MAGIC, 0) +#define CSDIO_IOC_SET_DATA_TRANSFER_CLOCKS _IO(CSDIO_IOC_MAGIC, 1) +#define CSDIO_IOC_SET_OP_CODE _IO(CSDIO_IOC_MAGIC, 2) +#define CSDIO_IOC_FUNCTION_SET_BLOCK_SIZE _IO(CSDIO_IOC_MAGIC, 3) +#define CSDIO_IOC_SET_BLOCK_MODE _IO(CSDIO_IOC_MAGIC, 4) +#define CSDIO_IOC_CONNECT_ISR _IO(CSDIO_IOC_MAGIC, 5) +#define CSDIO_IOC_DISCONNECT_ISR _IO(CSDIO_IOC_MAGIC, 6) +#define CSDIO_IOC_CMD52 _IO(CSDIO_IOC_MAGIC, 7) +#define CSDIO_IOC_CMD53 _IO(CSDIO_IOC_MAGIC, 8) +#define CSDIO_IOC_ENABLE_ISR _IO(CSDIO_IOC_MAGIC, 9) +#define CSDIO_IOC_DISABLE_ISR _IO(CSDIO_IOC_MAGIC, 10) +#define CSDIO_IOC_SET_VDD _IO(CSDIO_IOC_MAGIC, 11) +#define CSDIO_IOC_GET_VDD _IO(CSDIO_IOC_MAGIC, 12) + +#define CSDIO_IOC_MAXNR 12 + +struct csdio_cmd53_ctrl_t { +uint32_t m_block_mode;/* data tran. byte(0)/block(1) mode */ +uint32_t m_op_code;/* address auto increment flag */ +uint32_t m_address; +} __attribute__ ((packed)); + +struct csdio_cmd52_ctrl_t { +uint32_t m_write; +uint32_t m_address; +uint32_t m_data; +uint32_t m_ret; +} __attribute__ ((packed)); + +#endif
include/uapi/linux/Kbuild +1 -0
@@ -86,6 +86,7 @@ header-y += coff.h header-y += connector.h header-y += const.h header-y += cramfs_fs.h +header-y += csdio.h header-y += cuda.h header-y += cyclades.h header-y += cycx_cfm.h
Arnd Bergmann
maintainerQuoted 1 line · On Wednesday 16 July 2014 22:33:47 Greg KH wrote:
+ mmc: Char SDIO Device Driver
A few comments on the ioctl interface, since I suppose we'll have to live with that once it gets merged.
Quoted 4 lines
Documentation/csdio.txt new file +4
-0+Interface +========= +The Char SDIO Device Driver has two char device interfaces: + - Control Interface;
Documentation/csdio.txt line 118
Quoted 10 lines
Documentation/csdio.txt new file +10
-0+ - Function Interface. + +Char SDIO Device Driver Control Interface consists of: + - open() - device node is /dev/csdio0; + - close() + - ioctl() - the following options are available: + - CSDIO_IOC_ENABLE_HIGHSPEED_MODE; + - CSDIO_IOC_SET_DATA_TRANSFER_CLOCKS; + - CSDIO_IOC_ENABLE_ISR; + - CSDIO_IOC_DISABLE_ISR.
The documentation doesn't match the code.:
CSDIO_IOC_GET/SET_VDD are implemented in the control device, not the function device, and that is probably a good idea. CSDIO_IOC_ENABLE_HIGHSPEED_MODE is not implemented at all. CSDIO_IOC_ENABLE_ISR seems redundant with what the CSDIO_IOC_{DIS,}CONNECT_ISR functions do, but I could be wrong here.
The sysfs interface may actually be more appropriate than the control node, if I was to pick one of the two.
Quoted 22 lines
Documentation/csdio.txt new file +22
-0+Char SDIO Device Driver Function Interface consists of: + - open() - device node is /dev/csdiofX, where X is Function Id; + - close() + - read() - send CMD53 read; + - write() - send CMD53 write; + - ioctl() - the following options are available: + - CSDIO_IOC_SET_OP_CODE - 0 fixed adrress, 1 autoincrement. + - CSDIO_IOC_FUNCTION_SET_BLOCK_SIZE; + - CSDIO_IOC_SET_BLOCK_MODE - 0 byte mode, 1 block mode; + - CSDIO_IOC_CMD52 - execute CMD52, receives the + following structure as a parameter: + struct csdio_cmd52_ctrl_t { + uint32_t m_write; // 0 - read, 1 -write + uint32_t m_address; + uint32_t m_data; // data to write or read data + uint32_t m_ret; // command execution status + }__attribute__ ((packed)); + - CSDIO_IOC_CMD53 - setup CMD53 data transfer, receives the + following structure as a parameter: + struct csdio_cmd53_ctrl_t { + uint32_t m_block_mode; + uint32_t m_op_code;
Documentation/csdio.txt line 151
Quoted 10 lines
Documentation/csdio.txt new file +10
-0+ uint32_t m_address; + }__attribute__ ((packed)); + - CSDIO_IOC_CONNECT_ISR; + - CSDIO_IOC_DISCONNECT_ISR; + - CSDIO_IOC_GET_VDD; + - CSDIO_IOC_SET_VDD. + +Additionally, user space application can use fcntl system call with +parameters F_SETOWN and F_SETFL in order to set an asynchronous +callback for SDIO interrupt.
The read/write API seems very strange. SDIO has multiple ways of passing data between OS and device using CMD52 and CMD53, and they are all done differently here:
- A one-byte read or write uses a single CSDIO_IOC_CMD52 ioctl. This could be done using pread/pwrite with length '1' rather than an ioctl, if we want to.
- a byte-addressed multi-byte read/write needs to first 'seek' using CSDIO_IOC_CMD53 or and then transfer using read() or write().
- a block-addressed read/write is similar, but the number of bytes copied to/from user space is now multiplied with the block size (!). The block size needs to be set using both CSDIO_IOC_SET_BLOCK_MODE and CSDIO_IOC_CMD53, using the same value.
- to do a multi-byte read/write at a constant address rather than a block copy, CSDIO_IOC_CMD53 needs to set at least one bit (not necessarily the one used in the actual command) in m_op_code.
I guess all of this could be done using pread/pwrite, using the loff_t value to encode the m_address in the lower bits and the mode (single-byte, multi-byte, multi-byte auto-increment, block, block auto-increment) in some of the upper bits.
Alternatively, the read/write functions could be removed completely and everything be done in the ioctls, but in a more consistent way.
Quoted 8 lines
include/linux/csdio.h new file +8
-0+ +#define CSDIO_IOC_MAGIC 'm' + +#define CSDIO_IOC_ENABLE_HIGHSPEED_MODE _IO(CSDIO_IOC_MAGIC, 0) +#define CSDIO_IOC_SET_DATA_TRANSFER_CLOCKS _IO(CSDIO_IOC_MAGIC, 1) +#define CSDIO_IOC_SET_OP_CODE _IO(CSDIO_IOC_MAGIC, 2) +#define CSDIO_IOC_FUNCTION_SET_BLOCK_SIZE _IO(CSDIO_IOC_MAGIC, 3) +#define CSDIO_IOC_SET_BLOCK_MODE _IO(CSDIO_IOC_MAGIC, 4)
include/linux/csdio.h line 22
Quoted 10 lines
include/linux/csdio.h new file +10
-0+#define CSDIO_IOC_CONNECT_ISR _IO(CSDIO_IOC_MAGIC, 5) +#define CSDIO_IOC_DISCONNECT_ISR _IO(CSDIO_IOC_MAGIC, 6) +#define CSDIO_IOC_CMD52 _IO(CSDIO_IOC_MAGIC, 7) +#define CSDIO_IOC_CMD53 _IO(CSDIO_IOC_MAGIC, 8) +#define CSDIO_IOC_ENABLE_ISR _IO(CSDIO_IOC_MAGIC, 9) +#define CSDIO_IOC_DISABLE_ISR _IO(CSDIO_IOC_MAGIC, 10) +#define CSDIO_IOC_SET_VDD _IO(CSDIO_IOC_MAGIC, 11) +#define CSDIO_IOC_GET_VDD _IO(CSDIO_IOC_MAGIC, 12) + +#define CSDIO_IOC_MAXNR 12
The command codes above should use _IOR or _IOW where appropriate to encode the size of the transferred data.
include/linux/csdio.h line 35
Quoted 13 lines
include/linux/csdio.h new file +13
-0+ +struct csdio_cmd53_ctrl_t { +uint32_t m_block_mode;/* data tran. byte(0)/block(1) mode */ +uint32_t m_op_code;/* address auto increment flag */ +uint32_t m_address; +} __attribute__ ((packed)); + +struct csdio_cmd52_ctrl_t { +uint32_t m_write; +uint32_t m_address; +uint32_t m_data; +uint32_t m_ret; +} __attribute__ ((packed));
The packing is not necessary here, but at least all of these are compatible between 32 and 64 bit, so enabling compat mode is a one-line change and requires no conversion.
Arnd
Quoted 5 lines · Arnd Bergmann
Quoted 1 line · On Wednesday 16 July 2014 22:33:47 Greg KH wrote:
+ mmc: Char SDIO Device Driver
A few comments on the ioctl interface, since I suppose we'll have to live with that once it gets merged.
Thanks for the review comments. I'll come back to this in a week or so when I get more cycles to spend on the driver, it's _way_ down my list of priorities at the moment.
greg k-h