madwifi: improve beacon miss handling to increase the reliability of STA mode links
[openwrt.git] / package / wrt55agv2-spidevs / src / wrt55agv2_spidevs.c
1 /*
2 * SPI driver for the Linksys WRT55AG v2 board.
3 *
4 * Copyright (C) 2008 Gabor Juhos <juhosg at openwrt.org>
5 *
6 * This file was based on the mmc_over_gpio driver:
7 * Copyright 2008 Michael Buesch <mb@bu3sch.de>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
12 */
13
14 #include <linux/platform_device.h>
15 #include <linux/spi/spi_gpio.h>
16
17 #define DRV_NAME "wrt55agv2-spidevs"
18 #define DRV_DESC "SPI driver for the WRT55AG v2 board"
19 #define DRV_VERSION "0.1.0"
20 #define PFX DRV_NAME ": "
21
22 #define GPIO_PIN_MISO 1
23 #define GPIO_PIN_CS 2
24 #define GPIO_PIN_CLK 3
25 #define GPIO_PIN_MOSI 4
26
27 static struct platform_device *spi_gpio_dev;
28
29 static int __init boardinfo_setup(struct spi_board_info *bi,
30 struct spi_master *master, void *data)
31 {
32
33 strlcpy(bi->modalias, "spi-ks8995", sizeof(bi->modalias));
34
35 bi->max_speed_hz = 5000000 /* Hz */;
36 bi->bus_num = master->bus_num;
37 bi->mode = SPI_MODE_0;
38
39 return 0;
40 }
41
42 static int __init wrt55agv2_spidevs_init(void)
43 {
44 struct spi_gpio_platform_data pdata;
45 int err;
46
47 spi_gpio_dev = platform_device_alloc("spi-gpio", 0);
48 if (!spi_gpio_dev) {
49 printk(KERN_ERR PFX "no memory for spi-gpio device\n");
50 return -ENOMEM;
51 }
52
53 memset(&pdata, 0, sizeof(pdata));
54 pdata.pin_miso = GPIO_PIN_MISO;
55 pdata.pin_cs = GPIO_PIN_CS;
56 pdata.pin_clk = GPIO_PIN_CLK;
57 pdata.pin_mosi = GPIO_PIN_MOSI;
58 pdata.cs_activelow = 1;
59 pdata.no_spi_delay = 1;
60 pdata.boardinfo_setup = boardinfo_setup;
61 pdata.boardinfo_setup_data = NULL;
62
63 err = platform_device_add_data(spi_gpio_dev, &pdata, sizeof(pdata));
64 if (err)
65 goto err_free_dev;
66
67 err = platform_device_register(spi_gpio_dev);
68 if (err) {
69 printk(KERN_ERR PFX "unable to register device\n");
70 goto err_free_pdata;
71 }
72
73 return 0;
74
75 err_free_pdata:
76 kfree(spi_gpio_dev->dev.platform_data);
77 spi_gpio_dev->dev.platform_data = NULL;
78
79 err_free_dev:
80 platform_device_put(spi_gpio_dev);
81 return err;
82 }
83
84 static void __exit wrt55agv2_spidevs_cleanup(void)
85 {
86 if (!spi_gpio_dev)
87 return;
88
89 platform_device_unregister(spi_gpio_dev);
90
91 kfree(spi_gpio_dev->dev.platform_data);
92 spi_gpio_dev->dev.platform_data = NULL;
93 platform_device_put(spi_gpio_dev);
94 }
95
96 static int __init wrt55agv2_spidevs_modinit(void)
97 {
98 printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
99 return wrt55agv2_spidevs_init();
100 }
101 module_init(wrt55agv2_spidevs_modinit);
102
103 static void __exit wrt55agv2_spidevs_modexit(void)
104 {
105 wrt55agv2_spidevs_cleanup();
106 }
107 module_exit(wrt55agv2_spidevs_modexit);
108
109 MODULE_DESCRIPTION(DRV_DESC);
110 MODULE_VERSION(DRV_VERSION);
111 MODULE_AUTHOR("Gabor Juhos <juhosg at openwrt.org>");
112 MODULE_LICENSE("GPL v2");
113
This page took 0.053945 seconds and 5 git commands to generate.