packages: clean up the package folder
[openwrt.git] / package / kernel / 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_old.h>
16 #include <linux/module.h>
17
18 #define DRV_NAME        "wrt55agv2-spidevs"
19 #define DRV_DESC        "SPI driver for the WRT55AG v2 board"
20 #define DRV_VERSION     "0.1.0"
21 #define PFX             DRV_NAME ": "
22
23 #define GPIO_PIN_MISO   1
24 #define GPIO_PIN_CS     2
25 #define GPIO_PIN_CLK    3
26 #define GPIO_PIN_MOSI   4
27
28 static struct platform_device *spi_gpio_dev;
29
30 static int __init boardinfo_setup(struct spi_board_info *bi,
31                 struct spi_master *master, void *data)
32 {
33
34         strlcpy(bi->modalias, "spi-ks8995", sizeof(bi->modalias));
35
36         bi->max_speed_hz = 5000000 /* Hz */;
37         bi->bus_num = master->bus_num;
38         bi->mode = SPI_MODE_0;
39
40         return 0;
41 }
42
43 static int __init wrt55agv2_spidevs_init(void)
44 {
45         struct spi_gpio_platform_data pdata;
46         int err;
47
48         spi_gpio_dev = platform_device_alloc("spi-gpio", 0);
49         if (!spi_gpio_dev) {
50                 printk(KERN_ERR PFX "no memory for spi-gpio device\n");
51                 return -ENOMEM;
52         }
53
54         memset(&pdata, 0, sizeof(pdata));
55         pdata.pin_miso = GPIO_PIN_MISO;
56         pdata.pin_cs = GPIO_PIN_CS;
57         pdata.pin_clk = GPIO_PIN_CLK;
58         pdata.pin_mosi = GPIO_PIN_MOSI;
59         pdata.cs_activelow = 1;
60         pdata.no_spi_delay = 1;
61         pdata.boardinfo_setup = boardinfo_setup;
62         pdata.boardinfo_setup_data = NULL;
63
64         err = platform_device_add_data(spi_gpio_dev, &pdata, sizeof(pdata));
65         if (err)
66                 goto err_free_dev;
67
68         err = platform_device_register(spi_gpio_dev);
69         if (err) {
70                 printk(KERN_ERR PFX "unable to register device\n");
71                 goto err_free_pdata;
72         }
73
74         return 0;
75
76 err_free_pdata:
77         kfree(spi_gpio_dev->dev.platform_data);
78         spi_gpio_dev->dev.platform_data = NULL;
79
80 err_free_dev:
81         platform_device_put(spi_gpio_dev);
82         return err;
83 }
84
85 static void __exit wrt55agv2_spidevs_cleanup(void)
86 {
87         if (!spi_gpio_dev)
88                 return;
89
90         platform_device_unregister(spi_gpio_dev);
91
92         kfree(spi_gpio_dev->dev.platform_data);
93         spi_gpio_dev->dev.platform_data = NULL;
94         platform_device_put(spi_gpio_dev);
95 }
96
97 static int __init wrt55agv2_spidevs_modinit(void)
98 {
99         printk(KERN_INFO DRV_DESC " version " DRV_VERSION "\n");
100         return wrt55agv2_spidevs_init();
101 }
102 module_init(wrt55agv2_spidevs_modinit);
103
104 static void __exit wrt55agv2_spidevs_modexit(void)
105 {
106         wrt55agv2_spidevs_cleanup();
107 }
108 module_exit(wrt55agv2_spidevs_modexit);
109
110 MODULE_DESCRIPTION(DRV_DESC);
111 MODULE_VERSION(DRV_VERSION);
112 MODULE_AUTHOR("Gabor Juhos <juhosg at openwrt.org>");
113 MODULE_LICENSE("GPL v2");
114