120-spiflash.patch 17 KB

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