blob: 997033129d2642fc022702c316c71e4376679fb1 [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 */
Igor Grinberg11383a92011-04-26 16:25:56 +000013#define pr_fmt(fmt) "%s: " fmt, __func__
Tim Nordellcdd280b2010-09-27 16:05:49 +000014
15#include <linux/kernel.h>
16#include <linux/platform_device.h>
17#include <linux/gpio.h>
18#include <linux/delay.h>
19#include <linux/interrupt.h>
20#include <linux/io.h>
21#include <linux/smsc911x.h>
22
23#include <plat/board.h>
24#include <plat/gpmc.h>
25#include <plat/gpmc-smsc911x.h>
26
27static struct omap_smsc911x_platform_data *gpmc_cfg;
28
29static struct resource gpmc_smsc911x_resources[] = {
30 [0] = {
31 .flags = IORESOURCE_MEM,
32 },
33 [1] = {
Mike Rapoportf0949f72011-04-16 22:29:29 +000034 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
Tim Nordellcdd280b2010-09-27 16:05:49 +000035 },
36};
37
38static struct smsc911x_platform_config gpmc_smsc911x_config = {
39 .phy_interface = PHY_INTERFACE_MODE_MII,
40 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
41 .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
42 .flags = SMSC911X_USE_16BIT,
43};
44
Tim Nordellcdd280b2010-09-27 16:05:49 +000045/*
46 * Initialize smsc911x device connected to the GPMC. Note that we
47 * assume that pin multiplexing is done in the board-*.c file,
48 * or in the bootloader.
49 */
50void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *board_data)
51{
Mike Rapoport21b42732011-04-16 22:29:30 +000052 struct platform_device *pdev;
Tim Nordellcdd280b2010-09-27 16:05:49 +000053 unsigned long cs_mem_base;
54 int ret;
55
56 gpmc_cfg = board_data;
57
58 if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
Igor Grinberg11383a92011-04-26 16:25:56 +000059 pr_err("Failed to request GPMC mem region\n");
Tim Nordellcdd280b2010-09-27 16:05:49 +000060 return;
61 }
62
63 gpmc_smsc911x_resources[0].start = cs_mem_base + 0x0;
64 gpmc_smsc911x_resources[0].end = cs_mem_base + 0xff;
65
Igor Grinbergbc593f52011-05-03 18:22:09 +030066 if (gpio_request_one(gpmc_cfg->gpio_irq, GPIOF_IN, "smsc911x irq")) {
Igor Grinberg11383a92011-04-26 16:25:56 +000067 pr_err("Failed to request IRQ GPIO%d\n", gpmc_cfg->gpio_irq);
Tim Nordellcdd280b2010-09-27 16:05:49 +000068 goto free1;
69 }
70
Tim Nordellcdd280b2010-09-27 16:05:49 +000071 gpmc_smsc911x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
Tim Nordellcdd280b2010-09-27 16:05:49 +000072
73 if (gpio_is_valid(gpmc_cfg->gpio_reset)) {
Igor Grinbergbc593f52011-05-03 18:22:09 +030074 ret = gpio_request_one(gpmc_cfg->gpio_reset,
75 GPIOF_OUT_INIT_HIGH, "smsc911x reset");
Tim Nordellcdd280b2010-09-27 16:05:49 +000076 if (ret) {
Igor Grinberg11383a92011-04-26 16:25:56 +000077 pr_err("Failed to request reset GPIO%d\n",
78 gpmc_cfg->gpio_reset);
Tim Nordellcdd280b2010-09-27 16:05:49 +000079 goto free2;
80 }
81
Tim Nordellcdd280b2010-09-27 16:05:49 +000082 gpio_set_value(gpmc_cfg->gpio_reset, 0);
83 msleep(100);
84 gpio_set_value(gpmc_cfg->gpio_reset, 1);
85 }
86
Mike Rapoportf0949f72011-04-16 22:29:29 +000087 if (gpmc_cfg->flags)
88 gpmc_smsc911x_config.flags = gpmc_cfg->flags;
89
Mike Rapoport21b42732011-04-16 22:29:30 +000090 pdev = platform_device_register_resndata(NULL, "smsc911x", gpmc_cfg->id,
91 gpmc_smsc911x_resources, ARRAY_SIZE(gpmc_smsc911x_resources),
92 &gpmc_smsc911x_config, sizeof(gpmc_smsc911x_config));
93 if (!pdev) {
Igor Grinberg11383a92011-04-26 16:25:56 +000094 pr_err("Unable to register platform device\n");
Tim Nordellcdd280b2010-09-27 16:05:49 +000095 gpio_free(gpmc_cfg->gpio_reset);
96 goto free2;
97 }
98
99 return;
100
101free2:
102 gpio_free(gpmc_cfg->gpio_irq);
103free1:
104 gpmc_cs_free(gpmc_cfg->cs);
105
Igor Grinberg11383a92011-04-26 16:25:56 +0000106 pr_err("Could not initialize smsc911x device\n");
Tim Nordellcdd280b2010-09-27 16:05:49 +0000107}