Sandisk DOC H3 Linux driver
Subsystems (2)
RFC 1/1 Sandisk DOC H3 Linux driver
Hello folks,
I'm currently working on Linux port for a board with the Sandsik DOC H3 Embedded flash device installed. This is a new generation of DOC devices oriented to the open source products. The H3 is significantly different from previous DOC generations since it completely implements MTD layer (NAND driver + TrueFFS proprietary driver) inside of the chip, and provides ATA-like interface to the external CPU. While old DOC chips are true MTD devices requiring proprietary TrueFFS driver running on a host operating system.
I've surfed the net trying to find some community attempts to enable the DOC H3 in Linux kernel but didn't have a luck. So, first of all I'm wondering if somebody knows if there are community activities in this direction. I'm sending this email to the both linux-mtd and linux-ide lists because of a dual nature of the DOC H3.
I've been investigating this matter for a couple weeks and now I do see why it might be difficult to implement the DOC H3 Linux driver. Sandisk does not provide any comprehensive DOC H3 documentation freely. The one I've found myself does not have much details:
Instead of documentation, Sandisk equips its customers with GPL licensed DOC H3 SDK. It is a multi-tier complex software stack mostly intended to provide the same interface to legacy applications working on the top of the proprietary TrueFFS driver for previous DOC generations. This SDK is self-sufficient, easily portable to various platforms (Windows, VxWorks, etc.). Thus, it is absolutely impossible to integrate this SDK into Linux kernel.
After further analysis I found out that the lack of documentation is not the only problem. As mentioned above the DOC H3 provides an ATA-like interface implemented with deviation of ATA standards. From one side, It responds to standard ATA commands like ATA IDENTIFY, implements the same ATA ports to operate with device, etc. But from other side it has some specific features. Couple of them are listed below:
- The device requires low-level formatting via vendor-specific ATA commands. It may be split to several (up to 15) partitions each of them is represented as a separate "disk". So, detection, reading and writing a "disk" are to be done via vendor specific commands only.
- The DOC H3 ATA ports are 16-bit (unlike standard 8-bit ATA ones) Also, documentation above says that it is a little-endian device and recommends to
swap byte lanes to connect it to big-endian CPUs. So, ATA registers may be big endian.
I've tried to implement simple Linux driver (the patch is embedded below) to make it possible to use the DOC H3 as ATA disk (or set of disks). I decided to use an obsolete Linux ATA infrastructure (drivers/ide) instead of new libata one since the old one seems to be more flexible to accommodate the DOC H3 specific features above. I was trying to avoid hacking a generic code but had to introduce some modifications anyway.
I understand that this driver is not acceptable since I have hacked generic code like ide.c or ide-disk.c. Also I understand that DOC H3 support in the kernel might need libata-based driver. It doesn't seem straightforward to me how to make it. So, I'm looking for comments, advise and recommendations on how to re-implement the driver in a proper way.
The DOC H3 device is being seen more often in embedded systems and we would like to see it supported in mainline. Even if this current driver is completely unacceptable for upstream inclusion, I would like to use it as a starting point for discussions and would like to work with others who may already be writing a driver to reduce duplicated effort.
Thanks,
Vlad.
---
drivers/ide/Kconfig | 5 drivers/ide/Makefile | 2 drivers/ide/doch_h3/doch_h3.c | 375 ++++++++++++++++++++++++++++++++++++++++++ drivers/ide/doch_h3/doch_h3.h | 96 ++++++++++ drivers/ide/ide-disk.c | 23 ++ drivers/ide/ide-probe.c | 11 + include/linux/doch_ata.h | 84 +++++++++ include/linux/ide.h | 4 8 files changed, 600 insertions(+)
drivers/ide/Kconfig +5 -0
@@ -903,6 +903,11 @@ config BLK_DEV_MPC8xx_IDE If unsure, say N. +config BLK_DEV_DOC_H3 + bool "Sandisk DOC H3 support" + help + This option provides support for the Sandisk DiskOnChip H3 embedded flash. + choice prompt "Type of MPC8xx IDE interface" depends on BLK_DEV_MPC8xx_IDE
drivers/ide/Makefile +2 -0
@@ -42,6 +42,8 @@ ide-core-$(CONFIG_BLK_DEV_IDE_PMAC) += p # built-in only drivers from h8300/ ide-core-$(CONFIG_H8300) += h8300/ide-h8300.o +ide-core-$(CONFIG_BLK_DEV_DOC_H3) += doch_h3/doch_h3.o + obj-$(CONFIG_BLK_DEV_IDE) += ide-core.o obj-$(CONFIG_IDE_GENERIC) += ide-generic.o
drivers/ide/doch_h3/doch_h3.c +375 -0
375 lines not on this page · raw message
drivers/ide/doch_h3/doch_h3.h +96 -0
96 lines not on this page · raw message
drivers/ide/ide-disk.c +23 -0
@@ -71,6 +71,11 @@#include <asm/io.h> #include <asm/div64.h> +#ifdef CONFIG_BLK_DEV_DOC_H3 +#include <linux/doch_ata.h> +#endif + +/* * lba_capacity_is_ok() performs a sanity check on the claimed "lba_capacity" * value for this drive (from its reported identification information).
@@ -233,6 +238,11 @@ ide_startstop_t __ide_do_rw_disk (ide_dride_init_sg_cmd (drive, rq); } +#ifdef CONFIG_BLK_DEV_DOC_H3 +/* Set up partition number */ + hwif->OUTB ((drive - hwif->drives) +2 ,IDE_FEATURE_REG ); +#endif +if (rq_data_dir (rq) ==READ ) {if (drive->mult_count) {
@@ -243,6 +253,10 @@ ide_startstop_t __ide_do_rw_disk (ide_dr command = lba48 ?WIN_READ_EXT :WIN_READ ; } +#ifdef CONFIG_BLK_DEV_DOC_H3 +/*Read Partiton*/ + command =DOCH_READ_PARTITION ; +#endif ide_execute_command (drive, command, &task_in_intr,WAIT_CMD ,NULL );return ide_started; }else {
@@ -254,6 +268,10 @@ ide_startstop_t __ide_do_rw_disk (ide_dr command = lba48 ?WIN_WRITE_EXT :WIN_WRITE ; } +#ifdef CONFIG_BLK_DEV_DOC_H3 +/*Write Partiton*/ + command =DOCH_WRITE_PARTITION ; +#endif /* FIXME: ->OUTBSYNC ? */ hwif->OUTB (command,IDE_COMMAND_REG );
@@ -744,7 +762,12 @@ static ide_startstop_t idedisk_special (ide_task_t args;memset (&args,0 ,sizeof (ide_task_t)); args.tfRegister[IDE_NSECTOR_OFFSET ] = drive->mult_req; +#ifdef CONFIG_BLK_DEV_DOC_H3 + args.tfRegister[IDE_FEATURE_OFFSET ] =DOCH_SET_DATA_XFER_MODE ; + args.tfRegister[IDE_COMMAND_OFFSET ] =DOCH_EXT_DEVICE_CTRL ; +#else args.tfRegister[IDE_COMMAND_OFFSET ] =WIN_SETMULT ; +#endif args.command_type =IDE_DRIVE_TASK_NO_DATA ; args.handler = &set_multmode_intr;do_rw_taskfile (drive, &args);
drivers/ide/ide-probe.c +11 -0
@@ -56,6 +56,10 @@#include <asm/uaccess.h> #include <asm/io.h> +#ifdef CONFIG_BLKD_DEV_DOC_H3 +#include "doch_h3/doch_h3.h" +#endif +/** * generic_id - add a generic drive id * @drive: drive to make an ID block for
@@ -147,7 +151,14 @@ static inline void do_identify (ide_driv drive->id_read =1 ;local_irq_enable (); + +#ifdef CONFIG_BLK_DEV_DOC_H3 +/*TODO: Add chek if it is DOC */ +if (doch_fix_driveid (drive, id)) + goto err_misc; +#else ide_fix_driveid (id); +#endif #if defined (CONFIG_SCSI_EATA_DMA ) || defined (CONFIG_SCSI_EATA_PIO ) || defined (CONFIG_SCSI_EATA )/*
include/linux/doch_ata.h +84 -0
84 lines not on this page · raw message
include/linux/ide.h +4 -0
@@ -179,7 +179,11 @@ typedef unsigned char byte; /* used ever* Some more useful definitions */ #define PARTN_BITS 6/* number of minor dev bits for partitions */ +#ifdef CONFIG_BLK_DEV_DOC_H3 +#define MAX_DRIVES 15 +#else #define MAX_DRIVES 2/* per interface; 2 assumed by lots of code */ +#endif #define SECTOR_SIZE 512#define SECTOR_WORDS (SECTOR_SIZE / 4)/* number of 32bit words per sector */ #define IDE_LARGE_SEEK (b1,b2,t) (((b1) > (b2) + (t)) || ((b2) > (b1) + (t)))