blob: 2757504a13c42ae11319f9f72f4fa6ba50babd29 [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
Afzal Mohammed3ef5d002012-10-05 10:37:27 +053023#include "gpmc.h"
Tony Lindgrenac839b32012-09-20 11:41:46 -070024#include "gpmc-smsc911x.h"
Tim Nordellcdd280b2010-09-27 16:05:49 +000025
Tim Nordellcdd280b2010-09-27 16:05:49 +000026static struct resource gpmc_smsc911x_resources[] = {
27 [0] = {
28 .flags = IORESOURCE_MEM,
29 },
30 [1] = {
Mike Rapoportf0949f72011-04-16 22:29:29 +000031 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
Tim Nordellcdd280b2010-09-27 16:05:49 +000032 },
33};
34
35static struct smsc911x_platform_config gpmc_smsc911x_config = {
36 .phy_interface = PHY_INTERFACE_MODE_MII,
37 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
38 .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
Tim Nordellcdd280b2010-09-27 16:05:49 +000039};
40
Tim Nordellcdd280b2010-09-27 16:05:49 +000041/*
42 * Initialize smsc911x device connected to the GPMC. Note that we
43 * assume that pin multiplexing is done in the board-*.c file,
44 * or in the bootloader.
45 */
Russ Dill54da0782012-03-23 02:21:33 -070046void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *gpmc_cfg)
Tim Nordellcdd280b2010-09-27 16:05:49 +000047{
Mike Rapoport21b42732011-04-16 22:29:30 +000048 struct platform_device *pdev;
Tim Nordellcdd280b2010-09-27 16:05:49 +000049 unsigned long cs_mem_base;
50 int ret;
51
Tim Nordellcdd280b2010-09-27 16:05:49 +000052 if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
Igor Grinberg11383a92011-04-26 16:25:56 +000053 pr_err("Failed to request GPMC mem region\n");
Tim Nordellcdd280b2010-09-27 16:05:49 +000054 return;
55 }
56
57 gpmc_smsc911x_resources[0].start = cs_mem_base + 0x0;
58 gpmc_smsc911x_resources[0].end = cs_mem_base + 0xff;
59
Igor Grinbergbc593f52011-05-03 18:22:09 +030060 if (gpio_request_one(gpmc_cfg->gpio_irq, GPIOF_IN, "smsc911x irq")) {
Igor Grinberg11383a92011-04-26 16:25:56 +000061 pr_err("Failed to request IRQ GPIO%d\n", gpmc_cfg->gpio_irq);
Tim Nordellcdd280b2010-09-27 16:05:49 +000062 goto free1;
63 }
64
Tim Nordellcdd280b2010-09-27 16:05:49 +000065 gpmc_smsc911x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
Tim Nordellcdd280b2010-09-27 16:05:49 +000066
67 if (gpio_is_valid(gpmc_cfg->gpio_reset)) {
Igor Grinbergbc593f52011-05-03 18:22:09 +030068 ret = gpio_request_one(gpmc_cfg->gpio_reset,
69 GPIOF_OUT_INIT_HIGH, "smsc911x reset");
Tim Nordellcdd280b2010-09-27 16:05:49 +000070 if (ret) {
Igor Grinberg11383a92011-04-26 16:25:56 +000071 pr_err("Failed to request reset GPIO%d\n",
72 gpmc_cfg->gpio_reset);
Tim Nordellcdd280b2010-09-27 16:05:49 +000073 goto free2;
74 }
75
Tim Nordellcdd280b2010-09-27 16:05:49 +000076 gpio_set_value(gpmc_cfg->gpio_reset, 0);
77 msleep(100);
78 gpio_set_value(gpmc_cfg->gpio_reset, 1);
79 }
80
Russ Dilla0dbf2a2012-03-23 02:21:34 -070081 gpmc_smsc911x_config.flags = gpmc_cfg->flags ? : SMSC911X_USE_16BIT;
Mike Rapoportf0949f72011-04-16 22:29:29 +000082
Mike Rapoport21b42732011-04-16 22:29:30 +000083 pdev = platform_device_register_resndata(NULL, "smsc911x", gpmc_cfg->id,
84 gpmc_smsc911x_resources, ARRAY_SIZE(gpmc_smsc911x_resources),
85 &gpmc_smsc911x_config, sizeof(gpmc_smsc911x_config));
Wei Yongjun30e34882013-10-25 17:31:51 +080086 if (IS_ERR(pdev)) {
Igor Grinberg11383a92011-04-26 16:25:56 +000087 pr_err("Unable to register platform device\n");
Tim Nordellcdd280b2010-09-27 16:05:49 +000088 gpio_free(gpmc_cfg->gpio_reset);
89 goto free2;
90 }
91
92 return;
93
94free2:
95 gpio_free(gpmc_cfg->gpio_irq);
96free1:
97 gpmc_cs_free(gpmc_cfg->cs);
98
Igor Grinberg11383a92011-04-26 16:25:56 +000099 pr_err("Could not initialize smsc911x device\n");
Tim Nordellcdd280b2010-09-27 16:05:49 +0000100}