Advertisement
Guest User

nsa3x0.patch

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