120-spiflash.patch 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. --- a/drivers/mtd/devices/Kconfig
  2. +++ b/drivers/mtd/devices/Kconfig
  3. @@ -120,6 +120,10 @@ config MTD_BCM47XXSFLASH
  4. registered by bcma as platform devices. This enables driver for
  5. serial flash memories (only read-only mode is implemented).
  6. +config MTD_AR2315
  7. + tristate "Atheros AR2315+ SPI Flash support"
  8. + depends on SOC_AR2315
  9. +
  10. config MTD_SLRAM
  11. tristate "Uncached system RAM"
  12. help
  13. --- a/drivers/mtd/devices/Makefile
  14. +++ b/drivers/mtd/devices/Makefile
  15. @@ -14,6 +14,7 @@ obj-$(CONFIG_MTD_DATAFLASH) += mtd_dataf
  16. obj-$(CONFIG_MTD_M25P80) += m25p80.o
  17. obj-$(CONFIG_MTD_SPEAR_SMI) += spear_smi.o
  18. obj-$(CONFIG_MTD_SST25L) += sst25l.o
  19. +obj-$(CONFIG_MTD_AR2315) += ar2315.o
  20. obj-$(CONFIG_MTD_BCM47XXSFLASH) += bcm47xxsflash.o
  21. obj-$(CONFIG_MTD_ST_SPI_FSM) += st_spi_fsm.o
  22. --- /dev/null
  23. +++ b/drivers/mtd/devices/ar2315.c
  24. @@ -0,0 +1,459 @@
  25. +
  26. +/*
  27. + * MTD driver for the SPI Flash Memory support on Atheros AR2315
  28. + *
  29. + * Copyright (c) 2005-2006 Atheros Communications Inc.
  30. + * Copyright (C) 2006-2007 FON Technology, SL.
  31. + * Copyright (C) 2006-2007 Imre Kaloz <kaloz@openwrt.org>
  32. + * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  33. + * Copyright (C) 2012 Alexandros C. Couloumbis <alex@ozo.com>
  34. + *
  35. + * This code is free software; you can redistribute it and/or modify
  36. + * it under the terms of the GNU General Public License version 2 as
  37. + * published by the Free Software Foundation.
  38. + *
  39. + */
  40. +
  41. +#include <linux/kernel.h>
  42. +#include <linux/module.h>
  43. +#include <linux/types.h>
  44. +#include <linux/errno.h>
  45. +#include <linux/slab.h>
  46. +#include <linux/mtd/mtd.h>
  47. +#include <linux/mtd/partitions.h>
  48. +#include <linux/platform_device.h>
  49. +#include <linux/sched.h>
  50. +#include <linux/delay.h>
  51. +#include <linux/io.h>
  52. +#include <linux/mutex.h>
  53. +
  54. +#include "ar2315_spiflash.h"
  55. +
  56. +#define DRIVER_NAME "ar2315-spiflash"
  57. +
  58. +#define busy_wait(_priv, _condition, _wait) do { \
  59. + while (_condition) { \
  60. + if (_wait > 1) \
  61. + msleep(_wait); \
  62. + else if ((_wait == 1) && need_resched()) \
  63. + schedule(); \
  64. + else \
  65. + udelay(1); \
  66. + } \
  67. +} while (0)
  68. +
  69. +enum {
  70. + FLASH_NONE,
  71. + FLASH_1MB,
  72. + FLASH_2MB,
  73. + FLASH_4MB,
  74. + FLASH_8MB,
  75. + FLASH_16MB,
  76. +};
  77. +
  78. +/* Flash configuration table */
  79. +struct flashconfig {
  80. + u32 byte_cnt;
  81. + u32 sector_cnt;
  82. + u32 sector_size;
  83. +};
  84. +
  85. +static const struct flashconfig flashconfig_tbl[] = {
  86. + [FLASH_NONE] = { 0, 0, 0},
  87. + [FLASH_1MB] = { STM_1MB_BYTE_COUNT, STM_1MB_SECTOR_COUNT,
  88. + STM_1MB_SECTOR_SIZE},
  89. + [FLASH_2MB] = { STM_2MB_BYTE_COUNT, STM_2MB_SECTOR_COUNT,
  90. + STM_2MB_SECTOR_SIZE},
  91. + [FLASH_4MB] = { STM_4MB_BYTE_COUNT, STM_4MB_SECTOR_COUNT,
  92. + STM_4MB_SECTOR_SIZE},
  93. + [FLASH_8MB] = { STM_8MB_BYTE_COUNT, STM_8MB_SECTOR_COUNT,
  94. + STM_8MB_SECTOR_SIZE},
  95. + [FLASH_16MB] = { STM_16MB_BYTE_COUNT, STM_16MB_SECTOR_COUNT,
  96. + STM_16MB_SECTOR_SIZE}
  97. +};
  98. +
  99. +/* Mapping of generic opcodes to STM serial flash opcodes */
  100. +enum {
  101. + SPI_WRITE_ENABLE,
  102. + SPI_WRITE_DISABLE,
  103. + SPI_RD_STATUS,
  104. + SPI_WR_STATUS,
  105. + SPI_RD_DATA,
  106. + SPI_FAST_RD_DATA,
  107. + SPI_PAGE_PROGRAM,
  108. + SPI_SECTOR_ERASE,
  109. + SPI_BULK_ERASE,
  110. + SPI_DEEP_PWRDOWN,
  111. + SPI_RD_SIG,
  112. +};
  113. +
  114. +struct opcodes {
  115. + __u16 code;
  116. + __s8 tx_cnt;
  117. + __s8 rx_cnt;
  118. +};
  119. +
  120. +static const struct opcodes stm_opcodes[] = {
  121. + [SPI_WRITE_ENABLE] = {STM_OP_WR_ENABLE, 1, 0},
  122. + [SPI_WRITE_DISABLE] = {STM_OP_WR_DISABLE, 1, 0},
  123. + [SPI_RD_STATUS] = {STM_OP_RD_STATUS, 1, 1},
  124. + [SPI_WR_STATUS] = {STM_OP_WR_STATUS, 1, 0},
  125. + [SPI_RD_DATA] = {STM_OP_RD_DATA, 4, 4},
  126. + [SPI_FAST_RD_DATA] = {STM_OP_FAST_RD_DATA, 5, 0},
  127. + [SPI_PAGE_PROGRAM] = {STM_OP_PAGE_PGRM, 8, 0},
  128. + [SPI_SECTOR_ERASE] = {STM_OP_SECTOR_ERASE, 4, 0},
  129. + [SPI_BULK_ERASE] = {STM_OP_BULK_ERASE, 1, 0},
  130. + [SPI_DEEP_PWRDOWN] = {STM_OP_DEEP_PWRDOWN, 1, 0},
  131. + [SPI_RD_SIG] = {STM_OP_RD_SIG, 4, 1},
  132. +};
  133. +
  134. +/* Driver private data structure */
  135. +struct spiflash_priv {
  136. + struct mtd_info mtd;
  137. + void __iomem *readaddr; /* memory mapped data for read */
  138. + void __iomem *mmraddr; /* memory mapped register space */
  139. + struct mutex lock; /* serialize registers access */
  140. +};
  141. +
  142. +#define to_spiflash(_mtd) container_of(_mtd, struct spiflash_priv, mtd)
  143. +
  144. +enum {
  145. + FL_READY,
  146. + FL_READING,
  147. + FL_ERASING,
  148. + FL_WRITING
  149. +};
  150. +
  151. +/*****************************************************************************/
  152. +
  153. +static u32
  154. +spiflash_read_reg(struct spiflash_priv *priv, int reg)
  155. +{
  156. + return ioread32(priv->mmraddr + reg);
  157. +}
  158. +
  159. +static void
  160. +spiflash_write_reg(struct spiflash_priv *priv, int reg, u32 data)
  161. +{
  162. + iowrite32(data, priv->mmraddr + reg);
  163. +}
  164. +
  165. +static u32
  166. +spiflash_wait_busy(struct spiflash_priv *priv)
  167. +{
  168. + u32 reg;
  169. +
  170. + busy_wait(priv, (reg = spiflash_read_reg(priv, SPI_FLASH_CTL)) &
  171. + SPI_CTL_BUSY, 0);
  172. + return reg;
  173. +}
  174. +
  175. +static u32
  176. +spiflash_sendcmd(struct spiflash_priv *priv, int opcode, u32 addr)
  177. +{
  178. + const struct opcodes *op;
  179. + u32 reg, mask;
  180. +
  181. + op = &stm_opcodes[opcode];
  182. + reg = spiflash_wait_busy(priv);
  183. + spiflash_write_reg(priv, SPI_FLASH_OPCODE,
  184. + ((u32)op->code) | (addr << 8));
  185. +
  186. + reg &= ~SPI_CTL_TX_RX_CNT_MASK;
  187. + reg |= SPI_CTL_START | op->tx_cnt | (op->rx_cnt << 4);
  188. +
  189. + spiflash_write_reg(priv, SPI_FLASH_CTL, reg);
  190. + spiflash_wait_busy(priv);
  191. +
  192. + if (!op->rx_cnt)
  193. + return 0;
  194. +
  195. + reg = spiflash_read_reg(priv, SPI_FLASH_DATA);
  196. +
  197. + switch (op->rx_cnt) {
  198. + case 1:
  199. + mask = 0x000000ff;
  200. + break;
  201. + case 2:
  202. + mask = 0x0000ffff;
  203. + break;
  204. + case 3:
  205. + mask = 0x00ffffff;
  206. + break;
  207. + default:
  208. + mask = 0xffffffff;
  209. + break;
  210. + }
  211. + reg &= mask;
  212. +
  213. + return reg;
  214. +}
  215. +
  216. +/*
  217. + * Probe SPI flash device
  218. + * Function returns 0 for failure.
  219. + * and flashconfig_tbl array index for success.
  220. + */
  221. +static int
  222. +spiflash_probe_chip(struct platform_device *pdev, struct spiflash_priv *priv)
  223. +{
  224. + u32 sig = spiflash_sendcmd(priv, SPI_RD_SIG, 0);
  225. + int flash_size;
  226. +
  227. + switch (sig) {
  228. + case STM_8MBIT_SIGNATURE:
  229. + flash_size = FLASH_1MB;
  230. + break;
  231. + case STM_16MBIT_SIGNATURE:
  232. + flash_size = FLASH_2MB;
  233. + break;
  234. + case STM_32MBIT_SIGNATURE:
  235. + flash_size = FLASH_4MB;
  236. + break;
  237. + case STM_64MBIT_SIGNATURE:
  238. + flash_size = FLASH_8MB;
  239. + break;
  240. + case STM_128MBIT_SIGNATURE:
  241. + flash_size = FLASH_16MB;
  242. + break;
  243. + default:
  244. + dev_warn(&pdev->dev, "read of flash device signature failed!\n");
  245. + return 0;
  246. + }
  247. +
  248. + return flash_size;
  249. +}
  250. +
  251. +static void
  252. +spiflash_wait_complete(struct spiflash_priv *priv, unsigned int timeout)
  253. +{
  254. + busy_wait(priv, spiflash_sendcmd(priv, SPI_RD_STATUS, 0) &
  255. + SPI_STATUS_WIP, timeout);
  256. +}
  257. +
  258. +static int
  259. +spiflash_erase(struct mtd_info *mtd, struct erase_info *instr)
  260. +{
  261. + struct spiflash_priv *priv = to_spiflash(mtd);
  262. + const struct opcodes *op;
  263. + u32 temp, reg;
  264. +
  265. + if (instr->addr + instr->len > mtd->size)
  266. + return -EINVAL;
  267. +
  268. + mutex_lock(&priv->lock);
  269. +
  270. + spiflash_sendcmd(priv, SPI_WRITE_ENABLE, 0);
  271. + reg = spiflash_wait_busy(priv);
  272. +
  273. + op = &stm_opcodes[SPI_SECTOR_ERASE];
  274. + temp = ((u32)instr->addr << 8) | (u32)(op->code);
  275. + spiflash_write_reg(priv, SPI_FLASH_OPCODE, temp);
  276. +
  277. + reg &= ~SPI_CTL_TX_RX_CNT_MASK;
  278. + reg |= op->tx_cnt | SPI_CTL_START;
  279. + spiflash_write_reg(priv, SPI_FLASH_CTL, reg);
  280. +
  281. + spiflash_wait_complete(priv, 20);
  282. +
  283. + mutex_unlock(&priv->lock);
  284. +
  285. + instr->state = MTD_ERASE_DONE;
  286. + mtd_erase_callback(instr);
  287. +
  288. + return 0;
  289. +}
  290. +
  291. +static int
  292. +spiflash_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
  293. + u_char *buf)
  294. +{
  295. + struct spiflash_priv *priv = to_spiflash(mtd);
  296. +
  297. + if (!len)
  298. + return 0;
  299. +
  300. + if (from + len > mtd->size)
  301. + return -EINVAL;
  302. +
  303. + *retlen = len;
  304. +
  305. + mutex_lock(&priv->lock);
  306. +
  307. + memcpy_fromio(buf, priv->readaddr + from, len);
  308. +
  309. + mutex_unlock(&priv->lock);
  310. +
  311. + return 0;
  312. +}
  313. +
  314. +static int
  315. +spiflash_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
  316. + const u8 *buf)
  317. +{
  318. + struct spiflash_priv *priv = to_spiflash(mtd);
  319. + u32 opcode, bytes_left;
  320. +
  321. + *retlen = 0;
  322. +
  323. + if (!len)
  324. + return 0;
  325. +
  326. + if (to + len > mtd->size)
  327. + return -EINVAL;
  328. +
  329. + bytes_left = len;
  330. +
  331. + do {
  332. + u32 read_len, reg, page_offset, spi_data = 0;
  333. +
  334. + read_len = min(bytes_left, sizeof(u32));
  335. +
  336. + /* 32-bit writes cannot span across a page boundary
  337. + * (256 bytes). This types of writes require two page
  338. + * program operations to handle it correctly. The STM part
  339. + * will write the overflow data to the beginning of the
  340. + * current page as opposed to the subsequent page.
  341. + */
  342. + page_offset = (to & (STM_PAGE_SIZE - 1)) + read_len;
  343. +
  344. + if (page_offset > STM_PAGE_SIZE)
  345. + read_len -= (page_offset - STM_PAGE_SIZE);
  346. +
  347. + mutex_lock(&priv->lock);
  348. +
  349. + spiflash_sendcmd(priv, SPI_WRITE_ENABLE, 0);
  350. + spi_data = 0;
  351. + switch (read_len) {
  352. + case 4:
  353. + spi_data |= buf[3] << 24;
  354. + /* fall through */
  355. + case 3:
  356. + spi_data |= buf[2] << 16;
  357. + /* fall through */
  358. + case 2:
  359. + spi_data |= buf[1] << 8;
  360. + /* fall through */
  361. + case 1:
  362. + spi_data |= buf[0] & 0xff;
  363. + break;
  364. + default:
  365. + break;
  366. + }
  367. +
  368. + spiflash_write_reg(priv, SPI_FLASH_DATA, spi_data);
  369. + opcode = stm_opcodes[SPI_PAGE_PROGRAM].code |
  370. + (to & 0x00ffffff) << 8;
  371. + spiflash_write_reg(priv, SPI_FLASH_OPCODE, opcode);
  372. +
  373. + reg = spiflash_read_reg(priv, SPI_FLASH_CTL);
  374. + reg &= ~SPI_CTL_TX_RX_CNT_MASK;
  375. + reg |= (read_len + 4) | SPI_CTL_START;
  376. + spiflash_write_reg(priv, SPI_FLASH_CTL, reg);
  377. +
  378. + spiflash_wait_complete(priv, 1);
  379. +
  380. + mutex_unlock(&priv->lock);
  381. +
  382. + bytes_left -= read_len;
  383. + to += read_len;
  384. + buf += read_len;
  385. +
  386. + *retlen += read_len;
  387. + } while (bytes_left != 0);
  388. +
  389. + return 0;
  390. +}
  391. +
  392. +#if defined CONFIG_MTD_REDBOOT_PARTS || CONFIG_MTD_MYLOADER_PARTS
  393. +static const char * const part_probe_types[] = {
  394. + "cmdlinepart", "RedBoot", "MyLoader", NULL
  395. +};
  396. +#endif
  397. +
  398. +static int
  399. +spiflash_probe(struct platform_device *pdev)
  400. +{
  401. + struct spiflash_priv *priv;
  402. + struct mtd_info *mtd;
  403. + struct resource *res;
  404. + int index;
  405. + int result = 0;
  406. +
  407. + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  408. + if (!priv)
  409. + return -ENOMEM;
  410. +
  411. + mutex_init(&priv->lock);
  412. + mtd = &priv->mtd;
  413. +
  414. + res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  415. + priv->mmraddr = devm_ioremap_resource(&pdev->dev, res);
  416. + if (IS_ERR(priv->mmraddr)) {
  417. + dev_warn(&pdev->dev, "failed to map flash MMR\n");
  418. + return PTR_ERR(priv->mmraddr);
  419. + }
  420. +
  421. + index = spiflash_probe_chip(pdev, priv);
  422. + if (!index) {
  423. + dev_warn(&pdev->dev, "found no flash device\n");
  424. + return -ENODEV;
  425. + }
  426. +
  427. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  428. + priv->readaddr = devm_ioremap_resource(&pdev->dev, res);
  429. + if (IS_ERR(priv->readaddr)) {
  430. + dev_warn(&pdev->dev, "failed to map flash read mem\n");
  431. + return PTR_ERR(priv->readaddr);
  432. + }
  433. +
  434. + platform_set_drvdata(pdev, priv);
  435. + mtd->name = "spiflash";
  436. + mtd->type = MTD_NORFLASH;
  437. + mtd->flags = (MTD_CAP_NORFLASH|MTD_WRITEABLE);
  438. + mtd->size = flashconfig_tbl[index].byte_cnt;
  439. + mtd->erasesize = flashconfig_tbl[index].sector_size;
  440. + mtd->writesize = 1;
  441. + mtd->numeraseregions = 0;
  442. + mtd->eraseregions = NULL;
  443. + mtd->_erase = spiflash_erase;
  444. + mtd->_read = spiflash_read;
  445. + mtd->_write = spiflash_write;
  446. + mtd->owner = THIS_MODULE;
  447. +
  448. + dev_info(&pdev->dev, "%lld Kbytes flash detected\n", mtd->size >> 10);
  449. +
  450. +#if defined CONFIG_MTD_REDBOOT_PARTS || CONFIG_MTD_MYLOADER_PARTS
  451. + /* parse redboot partitions */
  452. +
  453. + result = mtd_device_parse_register(mtd, part_probe_types,
  454. + NULL, NULL, 0);
  455. +#endif
  456. +
  457. + return result;
  458. +}
  459. +
  460. +static int
  461. +spiflash_remove(struct platform_device *pdev)
  462. +{
  463. + struct spiflash_priv *priv = platform_get_drvdata(pdev);
  464. +
  465. + mtd_device_unregister(&priv->mtd);
  466. +
  467. + return 0;
  468. +}
  469. +
  470. +static struct platform_driver spiflash_driver = {
  471. + .driver.name = DRIVER_NAME,
  472. + .probe = spiflash_probe,
  473. + .remove = spiflash_remove,
  474. +};
  475. +
  476. +module_platform_driver(spiflash_driver);
  477. +
  478. +MODULE_LICENSE("GPL");
  479. +MODULE_AUTHOR("OpenWrt.org");
  480. +MODULE_AUTHOR("Atheros Communications Inc");
  481. +MODULE_DESCRIPTION("MTD driver for SPI Flash on Atheros AR2315+ SOC");
  482. +MODULE_ALIAS("platform:" DRIVER_NAME);
  483. +
  484. --- /dev/null
  485. +++ b/drivers/mtd/devices/ar2315_spiflash.h
  486. @@ -0,0 +1,106 @@
  487. +/*
  488. + * Atheros AR2315 SPI Flash Memory support header file.
  489. + *
  490. + * Copyright (c) 2005, Atheros Communications Inc.
  491. + * Copyright (C) 2006 FON Technology, SL.
  492. + * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
  493. + * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
  494. + *
  495. + * This code is free software; you can redistribute it and/or modify
  496. + * it under the terms of the GNU General Public License version 2 as
  497. + * published by the Free Software Foundation.
  498. + *
  499. + */
  500. +#ifndef __AR2315_SPIFLASH_H
  501. +#define __AR2315_SPIFLASH_H
  502. +
  503. +#define STM_PAGE_SIZE 256
  504. +
  505. +#define SFI_WRITE_BUFFER_SIZE 4
  506. +#define SFI_FLASH_ADDR_MASK 0x00ffffff
  507. +
  508. +#define STM_8MBIT_SIGNATURE 0x13
  509. +#define STM_M25P80_BYTE_COUNT 1048576
  510. +#define STM_M25P80_SECTOR_COUNT 16
  511. +#define STM_M25P80_SECTOR_SIZE 0x10000
  512. +
  513. +#define STM_16MBIT_SIGNATURE 0x14
  514. +#define STM_M25P16_BYTE_COUNT 2097152
  515. +#define STM_M25P16_SECTOR_COUNT 32
  516. +#define STM_M25P16_SECTOR_SIZE 0x10000
  517. +
  518. +#define STM_32MBIT_SIGNATURE 0x15
  519. +#define STM_M25P32_BYTE_COUNT 4194304
  520. +#define STM_M25P32_SECTOR_COUNT 64
  521. +#define STM_M25P32_SECTOR_SIZE 0x10000
  522. +
  523. +#define STM_64MBIT_SIGNATURE 0x16
  524. +#define STM_M25P64_BYTE_COUNT 8388608
  525. +#define STM_M25P64_SECTOR_COUNT 128
  526. +#define STM_M25P64_SECTOR_SIZE 0x10000
  527. +
  528. +#define STM_128MBIT_SIGNATURE 0x17
  529. +#define STM_M25P128_BYTE_COUNT 16777216
  530. +#define STM_M25P128_SECTOR_COUNT 256
  531. +#define STM_M25P128_SECTOR_SIZE 0x10000
  532. +
  533. +#define STM_1MB_BYTE_COUNT STM_M25P80_BYTE_COUNT
  534. +#define STM_1MB_SECTOR_COUNT STM_M25P80_SECTOR_COUNT
  535. +#define STM_1MB_SECTOR_SIZE STM_M25P80_SECTOR_SIZE
  536. +#define STM_2MB_BYTE_COUNT STM_M25P16_BYTE_COUNT
  537. +#define STM_2MB_SECTOR_COUNT STM_M25P16_SECTOR_COUNT
  538. +#define STM_2MB_SECTOR_SIZE STM_M25P16_SECTOR_SIZE
  539. +#define STM_4MB_BYTE_COUNT STM_M25P32_BYTE_COUNT
  540. +#define STM_4MB_SECTOR_COUNT STM_M25P32_SECTOR_COUNT
  541. +#define STM_4MB_SECTOR_SIZE STM_M25P32_SECTOR_SIZE
  542. +#define STM_8MB_BYTE_COUNT STM_M25P64_BYTE_COUNT
  543. +#define STM_8MB_SECTOR_COUNT STM_M25P64_SECTOR_COUNT
  544. +#define STM_8MB_SECTOR_SIZE STM_M25P64_SECTOR_SIZE
  545. +#define STM_16MB_BYTE_COUNT STM_M25P128_BYTE_COUNT
  546. +#define STM_16MB_SECTOR_COUNT STM_M25P128_SECTOR_COUNT
  547. +#define STM_16MB_SECTOR_SIZE STM_M25P128_SECTOR_SIZE
  548. +
  549. +/*
  550. + * ST Microelectronics Opcodes for Serial Flash
  551. + */
  552. +
  553. +#define STM_OP_WR_ENABLE 0x06 /* Write Enable */
  554. +#define STM_OP_WR_DISABLE 0x04 /* Write Disable */
  555. +#define STM_OP_RD_STATUS 0x05 /* Read Status */
  556. +#define STM_OP_WR_STATUS 0x01 /* Write Status */
  557. +#define STM_OP_RD_DATA 0x03 /* Read Data */
  558. +#define STM_OP_FAST_RD_DATA 0x0b /* Fast Read Data */
  559. +#define STM_OP_PAGE_PGRM 0x02 /* Page Program */
  560. +#define STM_OP_SECTOR_ERASE 0xd8 /* Sector Erase */
  561. +#define STM_OP_BULK_ERASE 0xc7 /* Bulk Erase */
  562. +#define STM_OP_DEEP_PWRDOWN 0xb9 /* Deep Power-Down Mode */
  563. +#define STM_OP_RD_SIG 0xab /* Read Electronic Signature */
  564. +
  565. +#define STM_STATUS_WIP 0x01 /* Write-In-Progress */
  566. +#define STM_STATUS_WEL 0x02 /* Write Enable Latch */
  567. +#define STM_STATUS_BP0 0x04 /* Block Protect 0 */
  568. +#define STM_STATUS_BP1 0x08 /* Block Protect 1 */
  569. +#define STM_STATUS_BP2 0x10 /* Block Protect 2 */
  570. +#define STM_STATUS_SRWD 0x80 /* Status Register Write Disable */
  571. +
  572. +/*
  573. + * SPI Flash Interface Registers
  574. + */
  575. +
  576. +#define SPI_FLASH_CTL 0x00
  577. +#define SPI_FLASH_OPCODE 0x04
  578. +#define SPI_FLASH_DATA 0x08
  579. +
  580. +#define SPI_CTL_START 0x00000100
  581. +#define SPI_CTL_BUSY 0x00010000
  582. +#define SPI_CTL_TXCNT_MASK 0x0000000f
  583. +#define SPI_CTL_RXCNT_MASK 0x000000f0
  584. +#define SPI_CTL_TX_RX_CNT_MASK 0x000000ff
  585. +#define SPI_CTL_SIZE_MASK 0x00060000
  586. +
  587. +#define SPI_CTL_CLK_SEL_MASK 0x03000000
  588. +#define SPI_OPCODE_MASK 0x000000ff
  589. +
  590. +#define SPI_STATUS_WIP STM_STATUS_WIP
  591. +
  592. +#endif
  593. --- a/arch/mips/ath25/ar2315.c
  594. +++ b/arch/mips/ath25/ar2315.c
  595. @@ -220,6 +220,28 @@ static struct platform_device ar2315_gpi
  596. .num_resources = ARRAY_SIZE(ar2315_gpio_res)
  597. };
  598. +static struct resource ar2315_spiflash_res[] = {
  599. + {
  600. + .name = "spiflash_read",
  601. + .flags = IORESOURCE_MEM,
  602. + .start = AR2315_SPI_READ_BASE,
  603. + .end = AR2315_SPI_READ_BASE + AR2315_SPI_READ_SIZE - 1,
  604. + },
  605. + {
  606. + .name = "spiflash_mmr",
  607. + .flags = IORESOURCE_MEM,
  608. + .start = AR2315_SPI_MMR_BASE,
  609. + .end = AR2315_SPI_MMR_BASE + AR2315_SPI_MMR_SIZE - 1,
  610. + },
  611. +};
  612. +
  613. +static struct platform_device ar2315_spiflash = {
  614. + .id = 0,
  615. + .name = "ar2315-spiflash",
  616. + .resource = ar2315_spiflash_res,
  617. + .num_resources = ARRAY_SIZE(ar2315_spiflash_res)
  618. +};
  619. +
  620. void __init ar2315_init_devices(void)
  621. {
  622. /* Find board configuration */
  623. @@ -230,6 +252,8 @@ void __init ar2315_init_devices(void)
  624. ar2315_gpio_res[1].end = ar2315_gpio_res[1].start;
  625. platform_device_register(&ar2315_gpio);
  626. + platform_device_register(&ar2315_spiflash);
  627. +
  628. ar2315_eth_data.macaddr = ath25_board.config->enet0_mac;
  629. ath25_add_ethernet(0, AR2315_ENET0_BASE, "eth0_mii",
  630. AR2315_ENET0_MII_BASE, AR2315_IRQ_ENET0,