120-spiflash.patch 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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.
  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_MCHP23K256) += mchp23k2
  16. obj-$(CONFIG_MTD_MCHP48L640) += mchp48l640.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,456 @@
  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 <[email protected]>
  33. + * Copyright (C) 2006-2009 Felix Fietkau <[email protected]>
  34. + * Copyright (C) 2012 Alexandros C. Couloumbis <[email protected]>
  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. + return 0;
  287. +}
  288. +
  289. +static int
  290. +spiflash_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
  291. + u_char *buf)
  292. +{
  293. + struct spiflash_priv *priv = to_spiflash(mtd);
  294. +
  295. + if (!len)
  296. + return 0;
  297. +
  298. + if (from + len > mtd->size)
  299. + return -EINVAL;
  300. +
  301. + *retlen = len;
  302. +
  303. + mutex_lock(&priv->lock);
  304. +
  305. + memcpy_fromio(buf, priv->readaddr + from, len);
  306. +
  307. + mutex_unlock(&priv->lock);
  308. +
  309. + return 0;
  310. +}
  311. +
  312. +static int
  313. +spiflash_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
  314. + const u8 *buf)
  315. +{
  316. + struct spiflash_priv *priv = to_spiflash(mtd);
  317. + u32 opcode, bytes_left;
  318. +
  319. + *retlen = 0;
  320. +
  321. + if (!len)
  322. + return 0;
  323. +
  324. + if (to + len > mtd->size)
  325. + return -EINVAL;
  326. +
  327. + bytes_left = len;
  328. +
  329. + do {
  330. + u32 read_len, reg, page_offset, spi_data = 0;
  331. +
  332. + read_len = min(bytes_left, sizeof(u32));
  333. +
  334. + /* 32-bit writes cannot span across a page boundary
  335. + * (256 bytes). This types of writes require two page
  336. + * program operations to handle it correctly. The STM part
  337. + * will write the overflow data to the beginning of the
  338. + * current page as opposed to the subsequent page.
  339. + */
  340. + page_offset = (to & (STM_PAGE_SIZE - 1)) + read_len;
  341. +
  342. + if (page_offset > STM_PAGE_SIZE)
  343. + read_len -= (page_offset - STM_PAGE_SIZE);
  344. +
  345. + mutex_lock(&priv->lock);
  346. +
  347. + spiflash_sendcmd(priv, SPI_WRITE_ENABLE, 0);
  348. + spi_data = 0;
  349. + switch (read_len) {
  350. + case 4:
  351. + spi_data |= buf[3] << 24;
  352. + fallthrough;
  353. + case 3:
  354. + spi_data |= buf[2] << 16;
  355. + fallthrough;
  356. + case 2:
  357. + spi_data |= buf[1] << 8;
  358. + fallthrough;
  359. + case 1:
  360. + spi_data |= buf[0] & 0xff;
  361. + break;
  362. + default:
  363. + break;
  364. + }
  365. +
  366. + spiflash_write_reg(priv, SPI_FLASH_DATA, spi_data);
  367. + opcode = stm_opcodes[SPI_PAGE_PROGRAM].code |
  368. + (to & 0x00ffffff) << 8;
  369. + spiflash_write_reg(priv, SPI_FLASH_OPCODE, opcode);
  370. +
  371. + reg = spiflash_read_reg(priv, SPI_FLASH_CTL);
  372. + reg &= ~SPI_CTL_TX_RX_CNT_MASK;
  373. + reg |= (read_len + 4) | SPI_CTL_START;
  374. + spiflash_write_reg(priv, SPI_FLASH_CTL, reg);
  375. +
  376. + spiflash_wait_complete(priv, 1);
  377. +
  378. + mutex_unlock(&priv->lock);
  379. +
  380. + bytes_left -= read_len;
  381. + to += read_len;
  382. + buf += read_len;
  383. +
  384. + *retlen += read_len;
  385. + } while (bytes_left != 0);
  386. +
  387. + return 0;
  388. +}
  389. +
  390. +#if defined CONFIG_MTD_REDBOOT_PARTS || CONFIG_MTD_MYLOADER_PARTS
  391. +static const char * const part_probe_types[] = {
  392. + "cmdlinepart", "RedBoot", "MyLoader", NULL
  393. +};
  394. +#endif
  395. +
  396. +static int
  397. +spiflash_probe(struct platform_device *pdev)
  398. +{
  399. + struct spiflash_priv *priv;
  400. + struct mtd_info *mtd;
  401. + struct resource *res;
  402. + int index;
  403. + int result = 0;
  404. +
  405. + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  406. + if (!priv)
  407. + return -ENOMEM;
  408. +
  409. + mutex_init(&priv->lock);
  410. + mtd = &priv->mtd;
  411. +
  412. + res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  413. + priv->mmraddr = devm_ioremap_resource(&pdev->dev, res);
  414. + if (IS_ERR(priv->mmraddr)) {
  415. + dev_warn(&pdev->dev, "failed to map flash MMR\n");
  416. + return PTR_ERR(priv->mmraddr);
  417. + }
  418. +
  419. + index = spiflash_probe_chip(pdev, priv);
  420. + if (!index) {
  421. + dev_warn(&pdev->dev, "found no flash device\n");
  422. + return -ENODEV;
  423. + }
  424. +
  425. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  426. + priv->readaddr = devm_ioremap_resource(&pdev->dev, res);
  427. + if (IS_ERR(priv->readaddr)) {
  428. + dev_warn(&pdev->dev, "failed to map flash read mem\n");
  429. + return PTR_ERR(priv->readaddr);
  430. + }
  431. +
  432. + platform_set_drvdata(pdev, priv);
  433. + mtd->name = "spiflash";
  434. + mtd->type = MTD_NORFLASH;
  435. + mtd->flags = (MTD_CAP_NORFLASH|MTD_WRITEABLE);
  436. + mtd->size = flashconfig_tbl[index].byte_cnt;
  437. + mtd->erasesize = flashconfig_tbl[index].sector_size;
  438. + mtd->writesize = 1;
  439. + mtd->numeraseregions = 0;
  440. + mtd->eraseregions = NULL;
  441. + mtd->_erase = spiflash_erase;
  442. + mtd->_read = spiflash_read;
  443. + mtd->_write = spiflash_write;
  444. + mtd->owner = THIS_MODULE;
  445. +
  446. + dev_info(&pdev->dev, "%lld Kbytes flash detected\n", mtd->size >> 10);
  447. +
  448. +#if defined CONFIG_MTD_REDBOOT_PARTS || CONFIG_MTD_MYLOADER_PARTS
  449. + /* parse redboot partitions */
  450. +
  451. + result = mtd_device_parse_register(mtd, part_probe_types,
  452. + NULL, NULL, 0);
  453. +#endif
  454. +
  455. + return result;
  456. +}
  457. +
  458. +static int
  459. +spiflash_remove(struct platform_device *pdev)
  460. +{
  461. + struct spiflash_priv *priv = platform_get_drvdata(pdev);
  462. +
  463. + mtd_device_unregister(&priv->mtd);
  464. +
  465. + return 0;
  466. +}
  467. +
  468. +static struct platform_driver spiflash_driver = {
  469. + .driver.name = DRIVER_NAME,
  470. + .probe = spiflash_probe,
  471. + .remove = spiflash_remove,
  472. +};
  473. +
  474. +module_platform_driver(spiflash_driver);
  475. +
  476. +MODULE_LICENSE("GPL");
  477. +MODULE_AUTHOR("OpenWrt.org");
  478. +MODULE_AUTHOR("Atheros Communications Inc");
  479. +MODULE_DESCRIPTION("MTD driver for SPI Flash on Atheros AR2315+ SOC");
  480. +MODULE_ALIAS("platform:" DRIVER_NAME);
  481. +
  482. --- /dev/null
  483. +++ b/drivers/mtd/devices/ar2315_spiflash.h
  484. @@ -0,0 +1,106 @@
  485. +/*
  486. + * Atheros AR2315 SPI Flash Memory support header file.
  487. + *
  488. + * Copyright (c) 2005, Atheros Communications Inc.
  489. + * Copyright (C) 2006 FON Technology, SL.
  490. + * Copyright (C) 2006 Imre Kaloz <[email protected]>
  491. + * Copyright (C) 2006-2009 Felix Fietkau <[email protected]>
  492. + *
  493. + * This code is free software; you can redistribute it and/or modify
  494. + * it under the terms of the GNU General Public License version 2 as
  495. + * published by the Free Software Foundation.
  496. + *
  497. + */
  498. +#ifndef __AR2315_SPIFLASH_H
  499. +#define __AR2315_SPIFLASH_H
  500. +
  501. +#define STM_PAGE_SIZE 256
  502. +
  503. +#define SFI_WRITE_BUFFER_SIZE 4
  504. +#define SFI_FLASH_ADDR_MASK 0x00ffffff
  505. +
  506. +#define STM_8MBIT_SIGNATURE 0x13
  507. +#define STM_M25P80_BYTE_COUNT 1048576
  508. +#define STM_M25P80_SECTOR_COUNT 16
  509. +#define STM_M25P80_SECTOR_SIZE 0x10000
  510. +
  511. +#define STM_16MBIT_SIGNATURE 0x14
  512. +#define STM_M25P16_BYTE_COUNT 2097152
  513. +#define STM_M25P16_SECTOR_COUNT 32
  514. +#define STM_M25P16_SECTOR_SIZE 0x10000
  515. +
  516. +#define STM_32MBIT_SIGNATURE 0x15
  517. +#define STM_M25P32_BYTE_COUNT 4194304
  518. +#define STM_M25P32_SECTOR_COUNT 64
  519. +#define STM_M25P32_SECTOR_SIZE 0x10000
  520. +
  521. +#define STM_64MBIT_SIGNATURE 0x16
  522. +#define STM_M25P64_BYTE_COUNT 8388608
  523. +#define STM_M25P64_SECTOR_COUNT 128
  524. +#define STM_M25P64_SECTOR_SIZE 0x10000
  525. +
  526. +#define STM_128MBIT_SIGNATURE 0x17
  527. +#define STM_M25P128_BYTE_COUNT 16777216
  528. +#define STM_M25P128_SECTOR_COUNT 256
  529. +#define STM_M25P128_SECTOR_SIZE 0x10000
  530. +
  531. +#define STM_1MB_BYTE_COUNT STM_M25P80_BYTE_COUNT
  532. +#define STM_1MB_SECTOR_COUNT STM_M25P80_SECTOR_COUNT
  533. +#define STM_1MB_SECTOR_SIZE STM_M25P80_SECTOR_SIZE
  534. +#define STM_2MB_BYTE_COUNT STM_M25P16_BYTE_COUNT
  535. +#define STM_2MB_SECTOR_COUNT STM_M25P16_SECTOR_COUNT
  536. +#define STM_2MB_SECTOR_SIZE STM_M25P16_SECTOR_SIZE
  537. +#define STM_4MB_BYTE_COUNT STM_M25P32_BYTE_COUNT
  538. +#define STM_4MB_SECTOR_COUNT STM_M25P32_SECTOR_COUNT
  539. +#define STM_4MB_SECTOR_SIZE STM_M25P32_SECTOR_SIZE
  540. +#define STM_8MB_BYTE_COUNT STM_M25P64_BYTE_COUNT
  541. +#define STM_8MB_SECTOR_COUNT STM_M25P64_SECTOR_COUNT
  542. +#define STM_8MB_SECTOR_SIZE STM_M25P64_SECTOR_SIZE
  543. +#define STM_16MB_BYTE_COUNT STM_M25P128_BYTE_COUNT
  544. +#define STM_16MB_SECTOR_COUNT STM_M25P128_SECTOR_COUNT
  545. +#define STM_16MB_SECTOR_SIZE STM_M25P128_SECTOR_SIZE
  546. +
  547. +/*
  548. + * ST Microelectronics Opcodes for Serial Flash
  549. + */
  550. +
  551. +#define STM_OP_WR_ENABLE 0x06 /* Write Enable */
  552. +#define STM_OP_WR_DISABLE 0x04 /* Write Disable */
  553. +#define STM_OP_RD_STATUS 0x05 /* Read Status */
  554. +#define STM_OP_WR_STATUS 0x01 /* Write Status */
  555. +#define STM_OP_RD_DATA 0x03 /* Read Data */
  556. +#define STM_OP_FAST_RD_DATA 0x0b /* Fast Read Data */
  557. +#define STM_OP_PAGE_PGRM 0x02 /* Page Program */
  558. +#define STM_OP_SECTOR_ERASE 0xd8 /* Sector Erase */
  559. +#define STM_OP_BULK_ERASE 0xc7 /* Bulk Erase */
  560. +#define STM_OP_DEEP_PWRDOWN 0xb9 /* Deep Power-Down Mode */
  561. +#define STM_OP_RD_SIG 0xab /* Read Electronic Signature */
  562. +
  563. +#define STM_STATUS_WIP 0x01 /* Write-In-Progress */
  564. +#define STM_STATUS_WEL 0x02 /* Write Enable Latch */
  565. +#define STM_STATUS_BP0 0x04 /* Block Protect 0 */
  566. +#define STM_STATUS_BP1 0x08 /* Block Protect 1 */
  567. +#define STM_STATUS_BP2 0x10 /* Block Protect 2 */
  568. +#define STM_STATUS_SRWD 0x80 /* Status Register Write Disable */
  569. +
  570. +/*
  571. + * SPI Flash Interface Registers
  572. + */
  573. +
  574. +#define SPI_FLASH_CTL 0x00
  575. +#define SPI_FLASH_OPCODE 0x04
  576. +#define SPI_FLASH_DATA 0x08
  577. +
  578. +#define SPI_CTL_START 0x00000100
  579. +#define SPI_CTL_BUSY 0x00010000
  580. +#define SPI_CTL_TXCNT_MASK 0x0000000f
  581. +#define SPI_CTL_RXCNT_MASK 0x000000f0
  582. +#define SPI_CTL_TX_RX_CNT_MASK 0x000000ff
  583. +#define SPI_CTL_SIZE_MASK 0x00060000
  584. +
  585. +#define SPI_CTL_CLK_SEL_MASK 0x03000000
  586. +#define SPI_OPCODE_MASK 0x000000ff
  587. +
  588. +#define SPI_STATUS_WIP STM_STATUS_WIP
  589. +
  590. +#endif
  591. --- a/arch/mips/ath25/ar2315.c
  592. +++ b/arch/mips/ath25/ar2315.c
  593. @@ -218,6 +218,28 @@ static struct platform_device ar2315_gpi
  594. .num_resources = ARRAY_SIZE(ar2315_gpio_res)
  595. };
  596. +static struct resource ar2315_spiflash_res[] = {
  597. + {
  598. + .name = "spiflash_read",
  599. + .flags = IORESOURCE_MEM,
  600. + .start = AR2315_SPI_READ_BASE,
  601. + .end = AR2315_SPI_READ_BASE + AR2315_SPI_READ_SIZE - 1,
  602. + },
  603. + {
  604. + .name = "spiflash_mmr",
  605. + .flags = IORESOURCE_MEM,
  606. + .start = AR2315_SPI_MMR_BASE,
  607. + .end = AR2315_SPI_MMR_BASE + AR2315_SPI_MMR_SIZE - 1,
  608. + },
  609. +};
  610. +
  611. +static struct platform_device ar2315_spiflash = {
  612. + .id = 0,
  613. + .name = "ar2315-spiflash",
  614. + .resource = ar2315_spiflash_res,
  615. + .num_resources = ARRAY_SIZE(ar2315_spiflash_res)
  616. +};
  617. +
  618. void __init ar2315_init_devices(void)
  619. {
  620. /* Find board configuration */
  621. @@ -228,6 +250,8 @@ void __init ar2315_init_devices(void)
  622. ar2315_gpio_res[1].end = ar2315_gpio_res[1].start;
  623. platform_device_register(&ar2315_gpio);
  624. + platform_device_register(&ar2315_spiflash);
  625. +
  626. ar2315_eth_data.macaddr = ath25_board.config->enet0_mac;
  627. ath25_add_ethernet(0, AR2315_ENET0_BASE, "eth0_mii",
  628. AR2315_ENET0_MII_BASE, AR2315_IRQ_ENET0,