blob: d30293a36494ffa56498377d35b1aff08191f139 [file] [log] [blame]
Tim Nordellcdd280b2010-09-27 16:05:49 +00001/*
2 * linux/arch/arm/mach-omap2/gpmc-smsc911x.c
3 *
4 * Copyright (C) 2009 Li-Pro.Net
5 * Stephan Linz <linz@li-pro.net>
6 *
7 * Modified from linux/arch/arm/mach-omap2/gpmc-smc91x.c
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/kernel.h>
15#include <linux/platform_device.h>
16#include <linux/gpio.h>
17#include <linux/delay.h>
18#include <linux/interrupt.h>
19#include <linux/io.h>
20#include <linux/smsc911x.h>
21
22#include <plat/board.h>
23#include <plat/gpmc.h>
24#include <plat/gpmc-smsc911x.h>
25
26static struct omap_smsc911x_platform_data *gpmc_cfg;
27
28static struct resource gpmc_smsc911x_resources[] = {
29 [0] = {
30 .flags = IORESOURCE_MEM,
31 },
32 [1] = {
Mike Rapoportf0949f72011-04-16 22:29:29 +000033 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
Tim Nordellcdd280b2010-09-27 16:05:49 +000034 },
35};
36
37static struct smsc911x_platform_config gpmc_smsc911x_config = {
38 .phy_interface = PHY_INTERFACE_MODE_MII,
39 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
40 .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
41 .flags = SMSC911X_USE_16BIT,
42};
43
Tim Nordellcdd280b2010-09-27 16:05:49 +000044/*
45 * Initialize smsc911x device connected to the GPMC. Note that we
46 * assume that pin multiplexing is done in the board-*.c file,
47 * or in the bootloader.
48 */
49void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *board_data)
50{
Mike Rapoport21b42732011-04-16 22:29:30 +000051 struct platform_device *pdev;
Tim Nordellcdd280b2010-09-27 16:05:49 +000052 unsigned long cs_mem_base;
53 int ret;
54
55 gpmc_cfg = board_data;
56
57 if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
58 printk(KERN_ERR "Failed to request GPMC mem for smsc911x\n");
59 return;
60 }
61
62 gpmc_smsc911x_resources[0].start = cs_mem_base + 0x0;
63 gpmc_smsc911x_resources[0].end = cs_mem_base + 0xff;
64
65 if (gpio_request(gpmc_cfg->gpio_irq, "smsc911x irq") < 0) {
66 printk(KERN_ERR "Failed to request GPIO%d for smsc911x IRQ\n",
67 gpmc_cfg->gpio_irq);
68 goto free1;
69 }
70
71 gpio_direction_input(gpmc_cfg->gpio_irq);
72 gpmc_smsc911x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
Tim Nordellcdd280b2010-09-27 16:05:49 +000073
74 if (gpio_is_valid(gpmc_cfg->gpio_reset)) {
75 ret = gpio_request(gpmc_cfg->gpio_reset, "smsc911x reset");
76 if (ret) {
77 printk(KERN_ERR "Failed to request GPIO%d for smsc911x reset\n",
78 gpmc_cfg->gpio_reset);
79 goto free2;
80 }
81
82 gpio_direction_output(gpmc_cfg->gpio_reset, 1);
83 gpio_set_value(gpmc_cfg->gpio_reset, 0);
84 msleep(100);
85 gpio_set_value(gpmc_cfg->gpio_reset, 1);
86 }
87
Mike Rapoportf0949f72011-04-16 22:29:29 +000088 if (gpmc_cfg->flags)
89 gpmc_smsc911x_config.flags = gpmc_cfg->flags;
90
Mike Rapoport21b42732011-04-16 22:29:30 +000091 pdev = platform_device_register_resndata(NULL, "smsc911x", gpmc_cfg->id,
92 gpmc_smsc911x_resources, ARRAY_SIZE(gpmc_smsc911x_resources),
93 &gpmc_smsc911x_config, sizeof(gpmc_smsc911x_config));
94 if (!pdev) {
Tim Nordellcdd280b2010-09-27 16:05:49 +000095 printk(KERN_ERR "Unable to register smsc911x device\n");
96 gpio_free(gpmc_cfg->gpio_reset);
97 goto free2;
98 }
99
100 return;
101
102free2:
103 gpio_free(gpmc_cfg->gpio_irq);
104free1:
105 gpmc_cs_free(gpmc_cfg->cs);
106
107 printk(KERN_ERR "Could not initialize smsc911x\n");
108}