Advertisement
Guest User

nsa3x0.patch

a guest
Feb 8th, 2012
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.68 KB | None | 0 0
  1. diff -Nur a/arch/arm/mach-kirkwood/Kconfig b/arch/arm/mach-kirkwood/Kconfig
  2. --- a/arch/arm/mach-kirkwood/Kconfig 2012-02-06 18:47:00.000000000 +0100
  3. +++ b/arch/arm/mach-kirkwood/Kconfig 2012-02-08 22:35:35.358434319 +0100
  4. @@ -130,6 +130,18 @@
  5. Say 'Y' here if you want your kernel to support the
  6. HP t5325 Thin Client.
  7.  
  8. +config MACH_NSA310
  9. + bool "Zyxel NSA-310"
  10. + help
  11. + Say 'Y' here if you want your kernel to support the
  12. + Zyxel NSA-310 NAS.
  13. +
  14. +config MACH_NSA320
  15. + bool "Zyxel NSA-320"
  16. + help
  17. + Say 'Y' here if you want your kernel to support the
  18. + Zyxel NSA-320 NAS.
  19. +
  20. endmenu
  21.  
  22. endif
  23. diff -Nur a/arch/arm/mach-kirkwood/Makefile b/arch/arm/mach-kirkwood/Makefile
  24. --- a/arch/arm/mach-kirkwood/Makefile 2012-02-06 18:47:00.000000000 +0100
  25. +++ b/arch/arm/mach-kirkwood/Makefile 2012-02-08 22:35:35.358434319 +0100
  26. @@ -18,5 +18,7 @@
  27. obj-$(CONFIG_MACH_NET2BIG_V2) += netxbig_v2-setup.o lacie_v2-common.o
  28. obj-$(CONFIG_MACH_NET5BIG_V2) += netxbig_v2-setup.o lacie_v2-common.o
  29. obj-$(CONFIG_MACH_T5325) += t5325-setup.o
  30. +obj-$(CONFIG_MACH_NSA310) += nsa310-setup.o mcu.o
  31. +obj-$(CONFIG_MACH_NSA320) += nsa320-setup.o mcu.o
  32.  
  33. obj-$(CONFIG_CPU_IDLE) += cpuidle.o
  34. diff -Nur a/arch/arm/mach-kirkwood/mcu.c b/arch/arm/mach-kirkwood/mcu.c
  35. --- a/arch/arm/mach-kirkwood/mcu.c 1970-01-01 01:00:00.000000000 +0100
  36. +++ b/arch/arm/mach-kirkwood/mcu.c 2012-02-08 22:35:35.370434319 +0100
  37. @@ -0,0 +1,125 @@
  38. +#include <linux/module.h>
  39. +#include <linux/init.h>
  40. +#include <asm/irq.h>
  41. +#include <asm/delay.h>
  42. +#include <linux/delay.h>
  43. +#include <linux/interrupt.h>
  44. +#include <linux/workqueue.h>
  45. +#include <linux/timer.h>
  46. +#include <linux/syscalls.h>
  47. +#include <linux/kmod.h>
  48. +#include <linux/syscalls.h>
  49. +#include <linux/fs.h>
  50. +#include <asm/fcntl.h>
  51. +#include <asm/hardirq.h>
  52. +#include <linux/ioctl.h>
  53. +#include <linux/cdev.h>
  54. +#include <linux/sched.h>
  55. +#include <linux/mm.h>
  56. +#include <asm/io.h>
  57. +#include <linux/spinlock.h>
  58. +#include <mach/hardware.h>
  59. +#include <asm/uaccess.h>
  60. +#include <linux/syscalls.h>
  61. +#include <asm/atomic.h>
  62. +#include <linux/proc_fs.h>
  63. +#include <asm/uaccess.h>
  64. +#include <linux/kernel.h>
  65. +
  66. +#include <mach/kirkwood.h>
  67. +#include <plat/gpio.h>
  68. +#include <linux/gpio.h>
  69. +#include "common.h"
  70. +#include "mpp.h"
  71. +
  72. +
  73. +
  74. +#define MCU_DATA_PIN 14
  75. +#define MCU_CLK_PIN 16
  76. +#define MCU_ACT_PIN 17
  77. +
  78. +MODULE_LICENSE("GPL v2");
  79. +#define MODULE_NAME "mcu"
  80. +
  81. +unsigned long mcu_data = 0;
  82. +unsigned long mcu_counter = 0;
  83. +
  84. +static struct proc_dir_entry *mcu_proc;
  85. +
  86. +static int mcu_status_read_fn(char *buf, char **start, off_t offset,
  87. + int count, int *eof, void *data)
  88. +{
  89. + unsigned long len, i;
  90. +
  91. + mcu_data = 0;
  92. +
  93. + gpio_request(14, "MCU_DATA");
  94. + gpio_request(16, "MCU_CLK");
  95. + gpio_request(17, "MCU_ACT");
  96. +
  97. + gpio_direction_output(MCU_ACT_PIN, 0);
  98. + msleep(100);
  99. + gpio_direction_input(MCU_DATA_PIN);
  100. + gpio_direction_output(MCU_CLK_PIN, 0);
  101. + udelay(100);
  102. +
  103. + for(i = 0 ; i < 32 ; i++)
  104. + {
  105. + mcu_data <<= 1;
  106. + gpio_set_value(MCU_CLK_PIN,1);
  107. +
  108. + mcu_data |= gpio_get_value(MCU_DATA_PIN)?0x1:0;
  109. +
  110. + udelay(100);
  111. +
  112. + gpio_set_value(MCU_CLK_PIN,0);
  113. +
  114. + udelay(100);
  115. + }
  116. +
  117. +
  118. + gpio_set_value(MCU_CLK_PIN,1);
  119. + gpio_set_value(MCU_ACT_PIN,1);
  120. +
  121. +
  122. + gpio_free(14);
  123. + gpio_free(16);
  124. + gpio_free(17);
  125. +
  126. + len = sprintf(buf, "MagicNum:%u\nRpss:%u\nTemperature:%u\n",(unsigned int)((mcu_data & 0xff000000) >> 24),
  127. + (unsigned int)((mcu_data & 0xff0000) >> 16),
  128. + (unsigned int)((mcu_data & 0xffff)));
  129. + *eof = 1;
  130. +
  131. + return len;
  132. +}
  133. +
  134. +static int mcu_status_write_fn(struct file *file, const char __user *buffer,
  135. + unsigned long count, void *data)
  136. +{
  137. + return 0;
  138. +}
  139. +
  140. +
  141. +static int __init mcu_init(void)
  142. +{
  143. +
  144. + mcu_proc = create_proc_entry("mcu", 0644, NULL);
  145. + if(mcu_proc != NULL)
  146. + {
  147. + mcu_proc->read_proc = mcu_status_read_fn;
  148. + mcu_proc->write_proc = mcu_status_write_fn;
  149. + }
  150. +
  151. + return 0;
  152. +}
  153. +
  154. +static void __exit mcu_exit(void)
  155. +{
  156. + remove_proc_entry("mcu", NULL);
  157. +
  158. +}
  159. +
  160. +module_init(mcu_init);
  161. +module_exit(mcu_exit);
  162. +
  163. diff -Nur a/arch/arm/mach-kirkwood/nsa310-setup.c b/arch/arm/mach-kirkwood/nsa310-setup.c
  164. --- a/arch/arm/mach-kirkwood/nsa310-setup.c 1970-01-01 01:00:00.000000000 +0100
  165. +++ b/arch/arm/mach-kirkwood/nsa310-setup.c 2012-02-08 22:35:35.370434319 +0100
  166. @@ -0,0 +1,357 @@
  167. +/*
  168. + * arch/arm/mach-kirkwood/nsa310-setup.c
  169. + *
  170. + * Zyxel NSA-310 Setup, by AA666, Peeter123 and Piotr Gozdur
  171. + *
  172. + * This file is licensed under the terms of the GNU General Public
  173. + * License version 2. This program is licensed "as is" without any
  174. + * warranty of any kind, whether express or implied.
  175. + */
  176. +
  177. +#include <linux/kernel.h>
  178. +#include <linux/init.h>
  179. +#include <linux/input.h>
  180. +#include <linux/delay.h>
  181. +#include <linux/platform_device.h>
  182. +#include <linux/i2c.h>
  183. +#include <linux/irq.h>
  184. +#include <linux/mtd/partitions.h>
  185. +#include <mtd/mtd-abi.h>
  186. +#include <linux/ata_platform.h>
  187. +#include <linux/mv643xx_eth.h>
  188. +#include <linux/mv643xx_i2c.h>
  189. +#include <linux/ethtool.h>
  190. +#include <linux/gpio.h>
  191. +#include <linux/gpio_keys.h>
  192. +#include <linux/leds.h>
  193. +#include <asm/mach-types.h>
  194. +#include <asm/mach/arch.h>
  195. +#include <mach/kirkwood.h>
  196. +#include <plat/mvsdio.h>
  197. +#include "common.h"
  198. +#include "mpp.h"
  199. +#include <linux/timer.h>
  200. +#include <linux/jiffies.h>
  201. +
  202. +static void nsa310_timerfunc(unsigned long data);
  203. +static DEFINE_TIMER(timer, nsa310_timerfunc, 0, 0);
  204. +
  205. +static struct mtd_partition nsa310_nand_parts[] = {
  206. + {
  207. + .name = "uboot",
  208. + .offset = 0,
  209. + .size = 0x100000,
  210. + .mask_flags = MTD_WRITEABLE
  211. + }, {
  212. + .name = "uboot_env",
  213. + .offset = MTDPART_OFS_NXTBLK,
  214. + .size = 0x80000
  215. + }, {
  216. + .name = "key_store",
  217. + .offset = MTDPART_OFS_NXTBLK,
  218. + .size = 0x80000
  219. + }, {
  220. + .name = "info",
  221. + .offset = MTDPART_OFS_NXTBLK,
  222. + .size = 0x80000
  223. + }, {
  224. + .name = "etc",
  225. + .offset = MTDPART_OFS_NXTBLK,
  226. + .size = 0xA00000
  227. + }, {
  228. + .name = "kernel_1",
  229. + .offset = MTDPART_OFS_NXTBLK,
  230. + .size = 0xA00000
  231. + }, {
  232. + .name = "rootfs1",
  233. + .offset = MTDPART_OFS_NXTBLK,
  234. + .size = 0x2FC0000
  235. + }, {
  236. + .name = "kernel_2",
  237. + .offset = MTDPART_OFS_NXTBLK,
  238. + .size = 0xA00000
  239. + }, {
  240. + .name = "rootfs2",
  241. + .offset = MTDPART_OFS_NXTBLK,
  242. + .size = 0x2FC0000
  243. + },
  244. +};
  245. +
  246. +static struct i2c_board_info __initdata nsa310_i2c_rtc = {
  247. + I2C_BOARD_INFO("pcf8563", 0x51),
  248. +};
  249. +
  250. +static struct mv643xx_eth_platform_data nsa310_ge00_data = {
  251. + .phy_addr = MV643XX_ETH_PHY_ADDR(0),
  252. + .speed = SPEED_1000,
  253. + .duplex = DUPLEX_FULL,
  254. +};
  255. +
  256. +static struct mv_sata_platform_data nsa310_sata_data = {
  257. + .n_ports = 2,
  258. +};
  259. +
  260. +static unsigned int nsa310_mpp_config[] __initdata = {
  261. + MPP36_GPIO, // Reset button
  262. + MPP37_GPIO, // Copy button
  263. + MPP46_GPIO, // Power button
  264. +
  265. + MPP48_GPIO, // Power Off
  266. + MPP21_GPIO, // USB Power Off
  267. +
  268. + MPP28_GPIO, // Sys LED Green
  269. + MPP29_GPIO, // Sys LED Yellow
  270. + MPP41_GPIO, // SATA1 LED Green
  271. + MPP42_GPIO, // SATA1 LED Red
  272. + MPP12_GPO, // SATA2 LED Green
  273. + MPP13_GPIO, // SATA2 LED Red
  274. + MPP39_GPIO, // Copy LED Green
  275. + MPP40_GPIO, // Copy LED Red
  276. + MPP15_GPIO, // USB LED Green
  277. +
  278. + MPP14_GPIO, // MCU Data
  279. + MPP16_GPIO, // MCU Clk
  280. + MPP17_GPIO, // MCU Act
  281. +
  282. + MPP38_GPIO, // VID B0
  283. + MPP45_GPIO, // VID B1
  284. +
  285. + MPP44_GPIO, // Buzzer
  286. + MPP43_GPIO, // HTP
  287. +
  288. + MPP47_GPIO, // Power Resume Data
  289. + MPP49_GPIO, // Power Resume Clock
  290. +
  291. + 0
  292. +};
  293. +
  294. +static struct gpio_led nsa310_gpio_led[] = {
  295. + {
  296. + .name = "nsa310:green:System",
  297. + .default_trigger = "timer",
  298. + .gpio = 28,
  299. + .active_low = 0,
  300. +
  301. + },
  302. + {
  303. + .name = "nsa310:red:System",
  304. + .default_trigger = "none",
  305. + .gpio = 29,
  306. + .active_low = 0,
  307. + },
  308. + {
  309. + .name = "nsa310:green:SATA1",
  310. + .default_trigger = "sata1r-disk",
  311. + .gpio = 41,
  312. + .active_low = 0,
  313. + },
  314. + {
  315. + .name = "nsa310:red:SATA1",
  316. + .default_trigger = "sata1w-disk",
  317. + .gpio = 42,
  318. + .active_low = 0,
  319. + },
  320. + {
  321. + .name = "nsa310:green:SATA2",
  322. + .default_trigger = "sata2r-disk",
  323. + .gpio = 12,
  324. + .active_low = 0,
  325. + },
  326. + {
  327. + .name = "nsa310:red:SATA2",
  328. + .default_trigger = "sata2w-disk",
  329. + .gpio = 13,
  330. + .active_low = 0,
  331. + },
  332. + {
  333. + .name = "nsa310:green:USB",
  334. + .default_trigger = "none",
  335. + .gpio = 15,
  336. + .active_low = 0,
  337. + },
  338. + {
  339. + .name = "nsa310:green:Copy",
  340. + .default_trigger = "none",
  341. + .gpio = 39,
  342. + .active_low = 0,
  343. + },
  344. + {
  345. + .name = "nsa310:red:Copy",
  346. + .default_trigger = "none",
  347. + .gpio = 40,
  348. + .active_low = 0,
  349. + },
  350. +};
  351. +
  352. +
  353. +static int nsa310_gpio_blink_set(unsigned gpio, int state,
  354. + unsigned long *delay_on, unsigned long *delay_off)
  355. +{
  356. +
  357. +// Use hardware acceleration
  358. +// if (delay_on && delay_off && !*delay_on && !*delay_off)
  359. +// *delay_on = *delay_off = 100;
  360. +
  361. + switch(state) {
  362. + case GPIO_LED_NO_BLINK_LOW:
  363. + case GPIO_LED_NO_BLINK_HIGH:
  364. + orion_gpio_set_blink(gpio, 0);
  365. + gpio_set_value(gpio, state);
  366. + break;
  367. + case GPIO_LED_BLINK:
  368. + orion_gpio_set_blink(gpio, 1);
  369. + break;
  370. + }
  371. + return 0;
  372. +}
  373. +
  374. +
  375. +static struct gpio_led_platform_data nsa310_led_data = {
  376. + .leds = nsa310_gpio_led,
  377. + .num_leds = ARRAY_SIZE(nsa310_gpio_led),
  378. + .gpio_blink_set = nsa310_gpio_blink_set,
  379. +};
  380. +
  381. +static struct platform_device nsa310_leds = {
  382. + .name = "leds-gpio",
  383. + .id = -1,
  384. + .dev = { .platform_data = &nsa310_led_data, }
  385. +};
  386. +
  387. +static struct gpio_keys_button nsa310_gpio_keys_button[] = {
  388. + {
  389. + .code = KEY_POWER,
  390. + .type = EV_KEY,
  391. + .gpio = 46,
  392. + .desc = "Power Button",
  393. + .active_low = 0,
  394. + .debounce_interval = 1000,
  395. + },
  396. + {
  397. + .code = KEY_COPY,
  398. + .type = EV_KEY,
  399. + .gpio = 37,
  400. + .desc = "USB Copy",
  401. + .active_low = 1,
  402. + .debounce_interval = 1000,
  403. + },
  404. + {
  405. + .code = KEY_OPTION,
  406. + .type = EV_KEY,
  407. + .gpio = 36,
  408. + .desc = "Reset",
  409. + .active_low = 1,
  410. + .debounce_interval = 1000,
  411. + },
  412. +};
  413. +
  414. +static struct gpio_keys_platform_data nsa310_keys_data = {
  415. + .buttons = nsa310_gpio_keys_button,
  416. + .nbuttons = ARRAY_SIZE(nsa310_gpio_keys_button),
  417. +};
  418. +
  419. +
  420. +static struct platform_device nsa310_buttons = {
  421. + .name = "gpio-keys",
  422. + .id = -1,
  423. + .dev = { .platform_data = &nsa310_keys_data, }
  424. +};
  425. +
  426. +static void nsa310_power_off(void)
  427. +{
  428. +//
  429. +//don't work with sysfs
  430. + printk(KERN_INFO "Activating power off GPIO pin...\n");
  431. + gpio_set_value(48, 1);
  432. +
  433. +// If machine goes to restart, uncomment next lines for infinite loop
  434. +/* printk(KERN_INFO "System halted, please turn off power manually\n");
  435. + gpio_set_value(28, 0);
  436. + do {
  437. + mdelay(1000);
  438. + } while(1);
  439. +*/
  440. +}
  441. +
  442. +static void nsa310_timerfunc(unsigned long data)
  443. +{
  444. +// Activate USB Power
  445. + if (gpio_request(21, "USB Power") != 0 || gpio_direction_output(21, 1) != 0)
  446. + printk(KERN_ERR "failed to setup USB power GPIO\n");
  447. + else
  448. + printk(KERN_INFO "USB power enabled\n");
  449. + gpio_free(21);
  450. +}
  451. +
  452. +static void __init nsa310_init(void)
  453. +{
  454. + u32 dev, rev;
  455. +
  456. + kirkwood_init();
  457. +
  458. + kirkwood_mpp_conf(nsa310_mpp_config);
  459. + kirkwood_nand_init(ARRAY_AND_SIZE(nsa310_nand_parts), 25);
  460. + kirkwood_ge00_init(&nsa310_ge00_data);
  461. + kirkwood_pcie_id(&dev, &rev);
  462. +
  463. + kirkwood_sata_init(&nsa310_sata_data);
  464. + kirkwood_uart0_init();
  465. + kirkwood_i2c_init();
  466. + i2c_register_board_info(0, &nsa310_i2c_rtc, 1);
  467. +
  468. + platform_device_register(&nsa310_leds);
  469. + platform_device_register(&nsa310_buttons);
  470. +
  471. + kirkwood_ehci_init();
  472. +// USB Power delay for 20 sec
  473. + timer.function = nsa310_timerfunc;
  474. + timer.data = 0;
  475. + timer.expires = jiffies + msecs_to_jiffies(20000);
  476. + add_timer(&timer);
  477. +
  478. +
  479. +/* Power resume control */
  480. + gpio_request(49, "Power-clk");
  481. + gpio_direction_output(49, 1);
  482. + gpio_request(47, "Power-data");
  483. +// Clear power resume
  484. +// gpio_direction_output(47, 0);
  485. +// Set power resume
  486. + gpio_direction_output(47, 1);
  487. + udelay(1000);
  488. +// gpio_direction_output(49, 0);
  489. + gpio_set_value(49, 0);
  490. +// release GPIO?
  491. +//test
  492. + gpio_free(47);
  493. + gpio_free(49);
  494. + printk(KERN_INFO "Power resume enabled\n");
  495. +
  496. +
  497. +// Activate Power-off GPIO
  498. + if (gpio_request(48, "Power-off") == 0 && gpio_direction_output(48, 0) == 0) {
  499. +// gpio_free(48);
  500. + pm_power_off = nsa310_power_off;
  501. + printk(KERN_INFO "Power-off GPIO enabled\n");
  502. + } else
  503. + printk(KERN_ERR "failed to configure Power-off GPIO\n");
  504. +
  505. +};
  506. +
  507. +static int __init nsa310_pci_init(void)
  508. +{
  509. + if (machine_is_nsa310())
  510. + kirkwood_pcie_init(KW_PCIE0);
  511. + return 0;
  512. +}
  513. +
  514. +subsys_initcall(nsa310_pci_init);
  515. +
  516. +MACHINE_START(NSA310, "Zyxel NSA-310")
  517. + .atag_offset = 0x100,
  518. + .init_machine = nsa310_init,
  519. + .map_io = kirkwood_map_io,
  520. + .init_early = kirkwood_init_early,
  521. + .init_irq = kirkwood_init_irq,
  522. + .timer = &kirkwood_timer,
  523. +MACHINE_END
  524. diff -Nur a/arch/arm/mach-kirkwood/nsa320-setup.c b/arch/arm/mach-kirkwood/nsa320-setup.c
  525. --- a/arch/arm/mach-kirkwood/nsa320-setup.c 1970-01-01 01:00:00.000000000 +0100
  526. +++ b/arch/arm/mach-kirkwood/nsa320-setup.c 2012-02-08 22:35:35.370434319 +0100
  527. @@ -0,0 +1,356 @@
  528. +/*
  529. + * arch/arm/mach-kirkwood/nsa320-setup.c
  530. + *
  531. + * Zyxel NSA-320 Setup, by AA666 and Piotr Gozdur
  532. + *
  533. + * This file is licensed under the terms of the GNU General Public
  534. + * License version 2. This program is licensed "as is" without any
  535. + * warranty of any kind, whether express or implied.
  536. + */
  537. +
  538. +#include <linux/kernel.h>
  539. +#include <linux/init.h>
  540. +#include <linux/input.h>
  541. +#include <linux/delay.h>
  542. +#include <linux/platform_device.h>
  543. +#include <linux/i2c.h>
  544. +#include <linux/irq.h>
  545. +#include <linux/mtd/partitions.h>
  546. +#include <mtd/mtd-abi.h>
  547. +#include <linux/ata_platform.h>
  548. +#include <linux/mv643xx_eth.h>
  549. +#include <linux/mv643xx_i2c.h>
  550. +#include <linux/ethtool.h>
  551. +#include <linux/gpio.h>
  552. +#include <linux/gpio_keys.h>
  553. +#include <linux/leds.h>
  554. +#include <asm/mach-types.h>
  555. +#include <asm/mach/arch.h>
  556. +#include <mach/kirkwood.h>
  557. +#include <plat/mvsdio.h>
  558. +#include "common.h"
  559. +#include "mpp.h"
  560. +#include <linux/timer.h>
  561. +#include <linux/jiffies.h>
  562. +
  563. +static void nsa320_timerfunc(unsigned long data);
  564. +static DEFINE_TIMER(timer, nsa320_timerfunc, 0, 0);
  565. +
  566. +static struct mtd_partition nsa320_nand_parts[] = {
  567. + {
  568. + .name = "uboot",
  569. + .offset = 0,
  570. + .size = 0x100000,
  571. + .mask_flags = MTD_WRITEABLE
  572. + }, {
  573. + .name = "uboot_env",
  574. + .offset = MTDPART_OFS_NXTBLK,
  575. + .size = 0x80000
  576. + }, {
  577. + .name = "key_store",
  578. + .offset = MTDPART_OFS_NXTBLK,
  579. + .size = 0x80000
  580. + }, {
  581. + .name = "info",
  582. + .offset = MTDPART_OFS_NXTBLK,
  583. + .size = 0x80000
  584. + }, {
  585. + .name = "etc",
  586. + .offset = MTDPART_OFS_NXTBLK,
  587. + .size = 0xA00000
  588. + }, {
  589. + .name = "kernel_1",
  590. + .offset = MTDPART_OFS_NXTBLK,
  591. + .size = 0xA00000
  592. + }, {
  593. + .name = "rootfs1",
  594. + .offset = MTDPART_OFS_NXTBLK,
  595. + .size = 0x2FC0000
  596. + }, {
  597. + .name = "kernel_2",
  598. + .offset = MTDPART_OFS_NXTBLK,
  599. + .size = 0xA00000
  600. + }, {
  601. + .name = "rootfs2",
  602. + .offset = MTDPART_OFS_NXTBLK,
  603. + .size = 0x2FC0000
  604. + },
  605. +};
  606. +
  607. +static struct i2c_board_info __initdata nsa320_i2c_rtc = {
  608. + I2C_BOARD_INFO("pcf8563", 0x51),
  609. +};
  610. +
  611. +static struct mv643xx_eth_platform_data nsa320_ge00_data = {
  612. + .phy_addr = MV643XX_ETH_PHY_ADDR(0),
  613. + .speed = SPEED_1000,
  614. + .duplex = DUPLEX_FULL,
  615. +};
  616. +
  617. +static struct mv_sata_platform_data nsa320_sata_data = {
  618. + .n_ports = 2,
  619. +};
  620. +
  621. +static unsigned int nsa320_mpp_config[] __initdata = {
  622. + MPP36_GPIO, // Reset button
  623. + MPP37_GPIO, // Copy button
  624. + MPP46_GPIO, // Power button
  625. +
  626. + MPP48_GPIO, // Power Off
  627. + MPP21_GPIO, // USB Power Off
  628. +
  629. + MPP28_GPIO, // Sys LED Green
  630. + MPP29_GPIO, // Sys LED Yellow
  631. + MPP41_GPIO, // SATA1 LED Green
  632. + MPP42_GPIO, // SATA1 LED Red
  633. + MPP12_GPO, // SATA2 LED Green
  634. + MPP13_GPIO, // SATA2 LED Red
  635. + MPP39_GPIO, // Copy LED Green
  636. + MPP40_GPIO, // Copy LED Red
  637. + MPP15_GPIO, // USB LED Green
  638. +
  639. + MPP14_GPIO, // MCU Data
  640. + MPP16_GPIO, // MCU Clk
  641. + MPP17_GPIO, // MCU Act
  642. +
  643. + MPP38_GPIO, // VID B0
  644. + MPP45_GPIO, // VID B1
  645. +
  646. + MPP44_GPIO, // Buzzer
  647. + MPP43_GPIO, // HTP
  648. +
  649. + MPP47_GPIO, // Power Resume Data
  650. + MPP49_GPIO, // Power Resume Clock
  651. +
  652. + 0
  653. +};
  654. +
  655. +static struct gpio_led nsa320_gpio_led[] = {
  656. + {
  657. + .name = "nsa320:green:System",
  658. + .default_trigger = "timer",
  659. + .gpio = 28,
  660. + .active_low = 0,
  661. +
  662. + },
  663. + {
  664. + .name = "nsa320:red:System",
  665. + .default_trigger = "none",
  666. + .gpio = 29,
  667. + .active_low = 0,
  668. + },
  669. + {
  670. + .name = "nsa320:green:SATA1",
  671. + .default_trigger = "sata1r-disk",
  672. + .gpio = 41,
  673. + .active_low = 0,
  674. + },
  675. + {
  676. + .name = "nsa320:red:SATA1",
  677. + .default_trigger = "sata1w-disk",
  678. + .gpio = 42,
  679. + .active_low = 0,
  680. + },
  681. + {
  682. + .name = "nsa320:green:SATA2",
  683. + .default_trigger = "sata2r-disk",
  684. + .gpio = 12,
  685. + .active_low = 0,
  686. + },
  687. + {
  688. + .name = "nsa320:red:SATA2",
  689. + .default_trigger = "sata2w-disk",
  690. + .gpio = 13,
  691. + .active_low = 0,
  692. + },
  693. + {
  694. + .name = "nsa320:green:USB",
  695. + .default_trigger = "none",
  696. + .gpio = 15,
  697. + .active_low = 0,
  698. + },
  699. + {
  700. + .name = "nsa320:green:Copy",
  701. + .default_trigger = "none",
  702. + .gpio = 39,
  703. + .active_low = 0,
  704. + },
  705. + {
  706. + .name = "nsa320:red:Copy",
  707. + .default_trigger = "none",
  708. + .gpio = 40,
  709. + .active_low = 0,
  710. + },
  711. +};
  712. +
  713. +
  714. +static int nsa320_gpio_blink_set(unsigned gpio, int state,
  715. + unsigned long *delay_on, unsigned long *delay_off)
  716. +{
  717. +
  718. +// Use hardware acceleration
  719. +// if (delay_on && delay_off && !*delay_on && !*delay_off)
  720. +// *delay_on = *delay_off = 100;
  721. +
  722. + switch(state) {
  723. + case GPIO_LED_NO_BLINK_LOW:
  724. + case GPIO_LED_NO_BLINK_HIGH:
  725. + orion_gpio_set_blink(gpio, 0);
  726. + gpio_set_value(gpio, state);
  727. + break;
  728. + case GPIO_LED_BLINK:
  729. + orion_gpio_set_blink(gpio, 1);
  730. + break;
  731. + }
  732. + return 0;
  733. +}
  734. +
  735. +
  736. +static struct gpio_led_platform_data nsa320_led_data = {
  737. + .leds = nsa320_gpio_led,
  738. + .num_leds = ARRAY_SIZE(nsa320_gpio_led),
  739. + .gpio_blink_set = nsa320_gpio_blink_set,
  740. +};
  741. +
  742. +static struct platform_device nsa320_leds = {
  743. + .name = "leds-gpio",
  744. + .id = -1,
  745. + .dev = { .platform_data = &nsa320_led_data, }
  746. +};
  747. +
  748. +static struct gpio_keys_button nsa320_gpio_keys_button[] = {
  749. + {
  750. + .code = KEY_POWER,
  751. + .type = EV_KEY,
  752. + .gpio = 46,
  753. + .desc = "Power Button",
  754. + .active_low = 0,
  755. + .debounce_interval = 1000,
  756. + },
  757. + {
  758. + .code = KEY_COPY,
  759. + .type = EV_KEY,
  760. + .gpio = 37,
  761. + .desc = "USB Copy",
  762. + .active_low = 1,
  763. + .debounce_interval = 1000,
  764. + },
  765. + {
  766. + .code = KEY_OPTION,
  767. + .type = EV_KEY,
  768. + .gpio = 36,
  769. + .desc = "Reset",
  770. + .active_low = 1,
  771. + .debounce_interval = 1000,
  772. + },
  773. +};
  774. +
  775. +static struct gpio_keys_platform_data nsa320_keys_data = {
  776. + .buttons = nsa320_gpio_keys_button,
  777. + .nbuttons = ARRAY_SIZE(nsa320_gpio_keys_button),
  778. +};
  779. +
  780. +static struct platform_device nsa320_buttons = {
  781. + .name = "gpio-keys",
  782. + .id = -1,
  783. + .dev = { .platform_data = &nsa320_keys_data, }
  784. +};
  785. +
  786. +static void nsa320_power_off(void)
  787. +{
  788. +//
  789. +//don't work with sysfs
  790. + printk(KERN_INFO "Activating power off GPIO pin...\n");
  791. + gpio_set_value(48, 1);
  792. +
  793. +// If machine goes to restart, uncomment next lines for infinite loop
  794. +/* printk(KERN_INFO "System halted, please turn off power manually\n");
  795. + gpio_set_value(28, 0);
  796. + do {
  797. + mdelay(1000);
  798. + } while(1);
  799. +*/
  800. +}
  801. +
  802. +static void nsa320_timerfunc(unsigned long data)
  803. +{
  804. +// Activate USB Power
  805. + if (gpio_request(21, "USB Power") != 0 || gpio_direction_output(21, 1) != 0)
  806. + printk(KERN_ERR "failed to setup USB power GPIO\n");
  807. + else
  808. + printk(KERN_INFO "USB power enabled\n");
  809. + gpio_free(21);
  810. +}
  811. +
  812. +static void __init nsa320_init(void)
  813. +{
  814. + u32 dev, rev;
  815. +
  816. + kirkwood_init();
  817. +
  818. + kirkwood_mpp_conf(nsa320_mpp_config);
  819. + kirkwood_nand_init(ARRAY_AND_SIZE(nsa320_nand_parts), 25);
  820. + kirkwood_ge00_init(&nsa320_ge00_data);
  821. + kirkwood_pcie_id(&dev, &rev);
  822. +
  823. + kirkwood_sata_init(&nsa320_sata_data);
  824. + kirkwood_uart0_init();
  825. + kirkwood_i2c_init();
  826. + i2c_register_board_info(0, &nsa320_i2c_rtc, 1);
  827. +
  828. + platform_device_register(&nsa320_leds);
  829. + platform_device_register(&nsa320_buttons);
  830. +
  831. + kirkwood_ehci_init();
  832. +// USB Power delay for 20 sec
  833. + timer.function = nsa320_timerfunc;
  834. + timer.data = 0;
  835. + timer.expires = jiffies + msecs_to_jiffies(20000);
  836. + add_timer(&timer);
  837. +
  838. +
  839. +/* Power resume control */
  840. + gpio_request(49, "Power-clk");
  841. + gpio_direction_output(49, 1);
  842. + gpio_request(47, "Power-data");
  843. +// Clear power resume
  844. +// gpio_direction_output(47, 0);
  845. +// Set power resume
  846. + gpio_direction_output(47, 1);
  847. + udelay(1000);
  848. +// gpio_direction_output(49, 0);
  849. + gpio_set_value(49, 0);
  850. +// release GPIO?
  851. +//test
  852. + gpio_free(47);
  853. + gpio_free(49);
  854. + printk(KERN_INFO "Power resume enabled\n");
  855. +
  856. +
  857. +// Activate Power-off GPIO
  858. + if (gpio_request(48, "Power-off") == 0 && gpio_direction_output(48, 0) == 0) {
  859. +// gpio_free(48);
  860. + pm_power_off = nsa320_power_off;
  861. + printk(KERN_INFO "Power-off GPIO enabled\n");
  862. + } else
  863. + printk(KERN_ERR "failed to configure Power-off GPIO\n");
  864. +
  865. +};
  866. +
  867. +static int __init nsa320_pci_init(void)
  868. +{
  869. + if (machine_is_nsa320())
  870. + kirkwood_pcie_init(KW_PCIE0);
  871. + return 0;
  872. +}
  873. +
  874. +subsys_initcall(nsa320_pci_init);
  875. +
  876. +MACHINE_START(NSA320, "Zyxel NSA-320")
  877. + .atag_offset = 0x100,
  878. + .init_machine = nsa320_init,
  879. + .map_io = kirkwood_map_io,
  880. + .init_early = kirkwood_init_early,
  881. + .init_irq = kirkwood_init_irq,
  882. + .timer = &kirkwood_timer,
  883. +MACHINE_END
  884. diff -Nur a/arch/arm/tools/mach-types b/arch/arm/tools/mach-types
  885. --- a/arch/arm/tools/mach-types 2012-02-06 18:47:00.000000000 +0100
  886. +++ b/arch/arm/tools/mach-types 2012-02-08 22:35:35.374434319 +0100
  887. @@ -972,6 +972,7 @@
  888. t5388p MACH_T5388P T5388P 3336
  889. dingo MACH_DINGO DINGO 3337
  890. goflexhome MACH_GOFLEXHOME GOFLEXHOME 3338
  891. +nsa320 MACH_NSA320 NSA320 3339
  892. lanreadyfn511 MACH_LANREADYFN511 LANREADYFN511 3340
  893. omap3_baia MACH_OMAP3_BAIA OMAP3_BAIA 3341
  894. omap3smartdisplay MACH_OMAP3SMARTDISPLAY OMAP3SMARTDISPLAY 3342
  895. @@ -1021,6 +1022,7 @@
  896. bockw MACH_BOCKW BOCKW 3386
  897. eva2000 MACH_EVA2000 EVA2000 3387
  898. steelyard MACH_STEELYARD STEELYARD 3388
  899. +nsa310 MACH_NSA310 NSA310 3389
  900. sdh001 MACH_MACH_SDH001 MACH_SDH001 3390
  901. nsslsboard MACH_NSSLSBOARD NSSLSBOARD 3392
  902. geneva_b5 MACH_GENEVA_B5 GENEVA_B5 3393
  903. diff -Nur a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
  904. --- a/drivers/ata/sata_mv.c 2012-02-06 18:47:00.000000000 +0100
  905. +++ b/drivers/ata/sata_mv.c 2012-02-08 22:35:35.374434319 +0100
  906. @@ -69,6 +69,7 @@
  907. #include <scsi/scsi_cmnd.h>
  908. #include <scsi/scsi_device.h>
  909. #include <linux/libata.h>
  910. +#include <linux/leds.h>
  911.  
  912. #define DRV_NAME "sata_mv"
  913. #define DRV_VERSION "1.28"
  914. @@ -2306,6 +2307,7 @@
  915. struct mv_port_priv *pp = ap->private_data;
  916. u32 in_index;
  917. unsigned int port_irqs;
  918. + struct ata_taskfile *tf = &qc->tf;
  919.  
  920. pp->pp_flags &= ~MV_PP_FLAG_FAKE_ATA_BUSY; /* paranoia */
  921.  
  922. @@ -2318,6 +2320,8 @@
  923. }
  924. /* fall thru */
  925. case ATA_PROT_NCQ:
  926. + ledtrig_sata_activity(ap->port_no, tf->flags & ATA_TFLAG_WRITE);
  927. +
  928. mv_start_edma(ap, port_mmio, pp, qc->tf.protocol);
  929. pp->req_idx = (pp->req_idx + 1) & MV_MAX_Q_DEPTH_MASK;
  930. in_index = pp->req_idx << EDMA_REQ_Q_PTR_SHIFT;
  931. diff -Nur a/drivers/leds/Kconfig b/drivers/leds/Kconfig
  932. --- a/drivers/leds/Kconfig 2012-02-06 18:47:00.000000000 +0100
  933. +++ b/drivers/leds/Kconfig 2012-02-08 22:35:35.378434319 +0100
  934. @@ -416,6 +416,14 @@
  935. This allows LEDs to be controlled by IDE disk activity.
  936. If unsure, say Y.
  937.  
  938. +config LEDS_TRIGGER_SATA_DISK
  939. + bool "LED SATA Disk Trigger"
  940. + depends on ATA
  941. + depends on LEDS_TRIGGERS
  942. + help
  943. + This allows LEDs to be controlled by IDE disk activity.
  944. + If unsure, say Y.
  945. +
  946. config LEDS_TRIGGER_HEARTBEAT
  947. tristate "LED Heartbeat Trigger"
  948. depends on LEDS_TRIGGERS
  949. diff -Nur a/drivers/leds/ledtrig-sata-disk.c b/drivers/leds/ledtrig-sata-disk.c
  950. --- a/drivers/leds/ledtrig-sata-disk.c 1970-01-01 01:00:00.000000000 +0100
  951. +++ b/drivers/leds/ledtrig-sata-disk.c 2012-02-08 22:45:55.238439380 +0100
  952. @@ -0,0 +1,109 @@
  953. +/*
  954. + * LED SATA-Disk Activity Trigger
  955. + *
  956. + * Author: Piotr Gozdur
  957. + *
  958. + * Based on "LED IDE-Disk Activity Trigger"
  959. + * by Richard Purdie <rpurdie@openedhand.com>
  960. + *
  961. + * This program is free software; you can redistribute it and/or modify
  962. + * it under the terms of the GNU General Public License version 2 as
  963. + * published by the Free Software Foundation.
  964. + *
  965. + */
  966. +
  967. +#include <linux/module.h>
  968. +#include <linux/jiffies.h>
  969. +#include <linux/kernel.h>
  970. +#include <linux/init.h>
  971. +#include <linux/timer.h>
  972. +#include <linux/leds.h>
  973. +
  974. +DEFINE_LED_TRIGGER(ledtrig1r_sata);
  975. +DEFINE_LED_TRIGGER(ledtrig1w_sata);
  976. +DEFINE_LED_TRIGGER(ledtrig2r_sata);
  977. +DEFINE_LED_TRIGGER(ledtrig2w_sata);
  978. +
  979. +static void ledtrig_sata_timerfunc(unsigned long data);
  980. +static DEFINE_TIMER(ledtrig_sata_timer, ledtrig_sata_timerfunc, 0, 0);
  981. +
  982. +static int sata_activity=0;
  983. +static int sata_lastactivity=0;
  984. +static unsigned char sata1_rd=0, sata2_rd=0, sata1_wr=0, sata2_wr=0;
  985. +
  986. +void ledtrig_sata_activity(int port, int wr)
  987. +{
  988. + if(port == 0){
  989. + if(wr) sata1_wr = 1;
  990. + else sata1_rd = 1;
  991. + }
  992. + if(port == 1){
  993. + if(wr) sata2_wr = 1;
  994. + else sata2_rd = 1;
  995. + }
  996. +
  997. + sata_activity++;
  998. + if (!timer_pending(&ledtrig_sata_timer))
  999. + mod_timer(&ledtrig_sata_timer, jiffies + msecs_to_jiffies(10));
  1000. +}
  1001. +EXPORT_SYMBOL(ledtrig_sata_activity);
  1002. +
  1003. +static void ledtrig_sata_timerfunc(unsigned long data)
  1004. +{
  1005. + if (sata_lastactivity != sata_activity) {
  1006. + sata_lastactivity = sata_activity;
  1007. +
  1008. + if(sata1_rd){
  1009. + sata1_rd = 0;
  1010. + led_trigger_event(ledtrig1r_sata, INT_MAX);
  1011. + }
  1012. + else led_trigger_event(ledtrig1r_sata, LED_OFF);
  1013. + if(sata1_wr){
  1014. + sata1_wr = 0;
  1015. + led_trigger_event(ledtrig1w_sata, INT_MAX);
  1016. + }
  1017. + else led_trigger_event(ledtrig1w_sata, LED_OFF);
  1018. +
  1019. + if(sata2_rd){
  1020. + sata2_rd = 0;
  1021. + led_trigger_event(ledtrig2r_sata, INT_MAX);
  1022. + }
  1023. + else led_trigger_event(ledtrig2r_sata, LED_OFF);
  1024. + if(sata2_wr){
  1025. + sata2_wr = 0;
  1026. + led_trigger_event(ledtrig2w_sata, INT_MAX);
  1027. + }
  1028. + else led_trigger_event(ledtrig2w_sata, LED_OFF);
  1029. +
  1030. + mod_timer(&ledtrig_sata_timer, jiffies + msecs_to_jiffies(10));
  1031. + } else {
  1032. + led_trigger_event(ledtrig1r_sata, LED_OFF);
  1033. + led_trigger_event(ledtrig1w_sata, LED_OFF);
  1034. + led_trigger_event(ledtrig2r_sata, LED_OFF);
  1035. + led_trigger_event(ledtrig2w_sata, LED_OFF);
  1036. + }
  1037. +}
  1038. +
  1039. +static int __init ledtrig_sata_init(void)
  1040. +{
  1041. + led_trigger_register_simple("sata1r-disk", &ledtrig1r_sata);
  1042. + led_trigger_register_simple("sata1w-disk", &ledtrig1w_sata);
  1043. + led_trigger_register_simple("sata2r-disk", &ledtrig2r_sata);
  1044. + led_trigger_register_simple("sata2w-disk", &ledtrig2w_sata);
  1045. + return 0;
  1046. +}
  1047. +
  1048. +static void __exit ledtrig_sata_exit(void)
  1049. +{
  1050. + led_trigger_unregister_simple(ledtrig1r_sata);
  1051. + led_trigger_unregister_simple(ledtrig1w_sata);
  1052. + led_trigger_unregister_simple(ledtrig2r_sata);
  1053. + led_trigger_unregister_simple(ledtrig2w_sata);
  1054. +}
  1055. +
  1056. +module_init(ledtrig_sata_init);
  1057. +module_exit(ledtrig_sata_exit);
  1058. +
  1059. +MODULE_AUTHOR("Piotr Gozdur");
  1060. +MODULE_DESCRIPTION("LED SATA Disk Activity Trigger");
  1061. +MODULE_LICENSE("GPL");
  1062. diff -Nur a/drivers/leds/Makefile b/drivers/leds/Makefile
  1063. --- a/drivers/leds/Makefile 2012-02-06 18:47:00.000000000 +0100
  1064. +++ b/drivers/leds/Makefile 2012-02-08 22:35:35.378434319 +0100
  1065. @@ -54,3 +54,4 @@
  1066. obj-$(CONFIG_LEDS_TRIGGER_BACKLIGHT) += ledtrig-backlight.o
  1067. obj-$(CONFIG_LEDS_TRIGGER_GPIO) += ledtrig-gpio.o
  1068. obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
  1069. +obj-$(CONFIG_LEDS_TRIGGER_SATA_DISK) += ledtrig-sata-disk.o
  1070. diff -Nur a/include/linux/leds.h b/include/linux/leds.h
  1071. --- a/include/linux/leds.h 2012-02-06 18:47:00.000000000 +0100
  1072. +++ b/include/linux/leds.h 2012-02-08 22:35:35.378434319 +0100
  1073. @@ -167,6 +167,12 @@
  1074. #define ledtrig_ide_activity() do {} while(0)
  1075. #endif
  1076.  
  1077. +#ifdef CONFIG_LEDS_TRIGGER_SATA_DISK
  1078. +extern void ledtrig_sata_activity(int port, int wr);
  1079. +#else
  1080. +#define ledtrig_sata_activity() do {} while(0)
  1081. +#endif
  1082. +
  1083. /*
  1084. * Generic LED platform data for describing LED names and default triggers.
  1085. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement