Advertisement
Guest User

nsa3x0.patch

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