drivers/mtd/at25.c: Added support for AT25DF081A serial flash chip
This commit is contained in:
parent
400215669a
commit
16dff59cbd
@ -58,6 +58,7 @@
|
|||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
/* Configuration ********************************************************************/
|
/* Configuration ********************************************************************/
|
||||||
|
|
||||||
#ifndef CONFIG_AT25_SPIMODE
|
#ifndef CONFIG_AT25_SPIMODE
|
||||||
@ -69,11 +70,23 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* AT25 Registers *******************************************************************/
|
/* AT25 Registers *******************************************************************/
|
||||||
/* Indentification register values */
|
|
||||||
|
|
||||||
#define AT25_MANUFACTURER 0x1F
|
/* Identification register values */
|
||||||
|
|
||||||
|
#define AT25_MANUFACTURER 0x1f
|
||||||
|
#define AT25_AT25DF081A_TYPE 0x45 /* 8 M-bit */
|
||||||
#define AT25_AT25DF321_TYPE 0x47 /* 32 M-bit */
|
#define AT25_AT25DF321_TYPE 0x47 /* 32 M-bit */
|
||||||
|
|
||||||
|
/* AT25DF081A capacity is 1,048,575 bytes:
|
||||||
|
* (16 sectors) * (65,536 bytes per sector)
|
||||||
|
* (4096 pages) * (256 bytes per page)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define AT25_AT25DF081A_SECTOR_SHIFT 12 /* Sector size 1 << 12 = 4096 */
|
||||||
|
#define AT25_AT25DF081A_NSECTORS 256
|
||||||
|
#define AT25_AT25DF081A_PAGE_SHIFT 9 /* Page size 1 << 8 = 256 */
|
||||||
|
#define AT25_AT25DF081A_NPAGES 2048
|
||||||
|
|
||||||
/* AT25DF321 capacity is 4,194,304 bytes:
|
/* AT25DF321 capacity is 4,194,304 bytes:
|
||||||
* (64 sectors) * (65,536 bytes per sector)
|
* (64 sectors) * (65,536 bytes per sector)
|
||||||
* (16384 pages) * (256 bytes per page)
|
* (16384 pages) * (256 bytes per page)
|
||||||
@ -160,10 +173,6 @@ static ssize_t at25_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
|||||||
FAR uint8_t *buffer);
|
FAR uint8_t *buffer);
|
||||||
static int at25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg);
|
static int at25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg);
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
* Private Data
|
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
@ -237,13 +246,21 @@ static inline int at25_readid(struct at25_dev_s *priv)
|
|||||||
|
|
||||||
/* Check for a valid manufacturer and memory type */
|
/* Check for a valid manufacturer and memory type */
|
||||||
|
|
||||||
if (manufacturer == AT25_MANUFACTURER && memory == AT25_AT25DF321_TYPE)
|
if (manufacturer == AT25_MANUFACTURER && memory == AT25_AT25DF081A_TYPE)
|
||||||
{
|
{
|
||||||
priv->sectorshift = AT25_AT25DF321_SECTOR_SHIFT;
|
priv->sectorshift = AT25_AT25DF081A_SECTOR_SHIFT;
|
||||||
priv->nsectors = AT25_AT25DF321_NSECTORS;
|
priv->nsectors = AT25_AT25DF081A_NSECTORS;
|
||||||
priv->pageshift = AT25_AT25DF321_PAGE_SHIFT;
|
priv->pageshift = AT25_AT25DF081A_PAGE_SHIFT;
|
||||||
priv->npages = AT25_AT25DF321_NPAGES;
|
priv->npages = AT25_AT25DF081A_NPAGES;
|
||||||
return OK;
|
return OK;
|
||||||
|
}
|
||||||
|
else if (manufacturer == AT25_MANUFACTURER && memory == AT25_AT25DF321_TYPE)
|
||||||
|
{
|
||||||
|
priv->sectorshift = AT25_AT25DF321_SECTOR_SHIFT;
|
||||||
|
priv->nsectors = AT25_AT25DF321_NSECTORS;
|
||||||
|
priv->pageshift = AT25_AT25DF321_PAGE_SHIFT;
|
||||||
|
priv->npages = AT25_AT25DF321_NPAGES;
|
||||||
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -478,7 +495,8 @@ static ssize_t at25_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nb
|
|||||||
|
|
||||||
/* On this device, we can handle the block read just like the byte-oriented read */
|
/* On this device, we can handle the block read just like the byte-oriented read */
|
||||||
|
|
||||||
nbytes = at25_read(dev, startblock << priv->pageshift, nblocks << priv->pageshift, buffer);
|
nbytes = at25_read(dev, startblock << priv->pageshift,
|
||||||
|
nblocks << priv->pageshift, buffer);
|
||||||
if (nbytes > 0)
|
if (nbytes > 0)
|
||||||
{
|
{
|
||||||
return nbytes >> priv->pageshift;
|
return nbytes >> priv->pageshift;
|
||||||
@ -491,8 +509,8 @@ static ssize_t at25_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nb
|
|||||||
* Name: at25_bwrite
|
* Name: at25_bwrite
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
static ssize_t at25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks,
|
static ssize_t at25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||||
FAR const uint8_t *buffer)
|
size_t nblocks, FAR const uint8_t *buffer)
|
||||||
{
|
{
|
||||||
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
||||||
size_t blocksleft = nblocks;
|
size_t blocksleft = nblocks;
|
||||||
@ -581,8 +599,10 @@ static int at25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
|||||||
{
|
{
|
||||||
case MTDIOC_GEOMETRY:
|
case MTDIOC_GEOMETRY:
|
||||||
{
|
{
|
||||||
FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)((uintptr_t)arg);
|
FAR struct mtd_geometry_s *geo =
|
||||||
if (geo)
|
FAR struct mtd_geometry_s *)((uintptr_t)arg);
|
||||||
|
|
||||||
|
if (geo != NULL)
|
||||||
{
|
{
|
||||||
/* Populate the geometry structure with information need to know
|
/* Populate the geometry structure with information need to know
|
||||||
* the capacity and how to access the device.
|
* the capacity and how to access the device.
|
||||||
|
Loading…
Reference in New Issue
Block a user