blob: f9446eaf9176c047c76320540632875b08b89ff5 [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>
Matt Portere4b0b2c2012-02-23 09:16:04 -050022#include <linux/regulator/fixed.h>
23#include <linux/regulator/machine.h>
Tim Nordellcdd280b2010-09-27 16:05:49 +000024
25#include <plat/board.h>
26#include <plat/gpmc.h>
27#include <plat/gpmc-smsc911x.h>
28
Tim Nordellcdd280b2010-09-27 16:05:49 +000029static 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,
Tim Nordellcdd280b2010-09-27 16:05:49 +000042};
43
Matt Portere4b0b2c2012-02-23 09:16:04 -050044static struct regulator_consumer_supply gpmc_smsc911x_supply[] = {
45 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
46 REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
47};
48
49/* Generic regulator definition to satisfy smsc911x */
50static struct regulator_init_data gpmc_smsc911x_reg_init_data = {
51 .constraints = {
52 .min_uV = 3300000,
53 .max_uV = 3300000,
54 .valid_modes_mask = REGULATOR_MODE_NORMAL
55 | REGULATOR_MODE_STANDBY,
56 .valid_ops_mask = REGULATOR_CHANGE_MODE
57 | REGULATOR_CHANGE_STATUS,
58 },
59 .num_consumer_supplies = ARRAY_SIZE(gpmc_smsc911x_supply),
60 .consumer_supplies = gpmc_smsc911x_supply,
61};
62
63static struct fixed_voltage_config gpmc_smsc911x_fixed_reg_data = {
64 .supply_name = "gpmc_smsc911x",
65 .microvolts = 3300000,
66 .gpio = -EINVAL,
67 .startup_delay = 0,
68 .enable_high = 0,
69 .enabled_at_boot = 1,
70 .init_data = &gpmc_smsc911x_reg_init_data,
71};
72
73/*
74 * Platform device id of 42 is a temporary fix to avoid conflicts
75 * with other reg-fixed-voltage devices. The real fix should
76 * involve the driver core providing a way of dynamically
77 * assigning a unique id on registration for platform devices
78 * in the same name space.
79 */
80static struct platform_device gpmc_smsc911x_regulator = {
81 .name = "reg-fixed-voltage",
82 .id = 42,
83 .dev = {
84 .platform_data = &gpmc_smsc911x_fixed_reg_data,
85 },
86};
87
Tim Nordellcdd280b2010-09-27 16:05:49 +000088/*
89 * Initialize smsc911x device connected to the GPMC. Note that we
90 * assume that pin multiplexing is done in the board-*.c file,
91 * or in the bootloader.
92 */
Russ Dill54da0782012-03-23 02:21:33 -070093void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *gpmc_cfg)
Tim Nordellcdd280b2010-09-27 16:05:49 +000094{
Mike Rapoport21b42732011-04-16 22:29:30 +000095 struct platform_device *pdev;
Tim Nordellcdd280b2010-09-27 16:05:49 +000096 unsigned long cs_mem_base;
97 int ret;
98
Kevin Hilmanbb604242012-03-01 12:30:42 -080099 if (!gpmc_cfg->id) {
100 ret = platform_device_register(&gpmc_smsc911x_regulator);
101 if (ret < 0) {
102 pr_err("Unable to register smsc911x regulators: %d\n",
103 ret);
104 return;
105 }
Matt Portere4b0b2c2012-02-23 09:16:04 -0500106 }
107
Tim Nordellcdd280b2010-09-27 16:05:49 +0000108 if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
Igor Grinberg11383a92011-04-26 16:25:56 +0000109 pr_err("Failed to request GPMC mem region\n");
Tim Nordellcdd280b2010-09-27 16:05:49 +0000110 return;
111 }
112
113 gpmc_smsc911x_resources[0].start = cs_mem_base + 0x0;
114 gpmc_smsc911x_resources[0].end = cs_mem_base + 0xff;
115
Igor Grinbergbc593f52011-05-03 18:22:09 +0300116 if (gpio_request_one(gpmc_cfg->gpio_irq, GPIOF_IN, "smsc911x irq")) {
Igor Grinberg11383a92011-04-26 16:25:56 +0000117 pr_err("Failed to request IRQ GPIO%d\n", gpmc_cfg->gpio_irq);
Tim Nordellcdd280b2010-09-27 16:05:49 +0000118 goto free1;
119 }
120
Tim Nordellcdd280b2010-09-27 16:05:49 +0000121 gpmc_smsc911x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
Tim Nordellcdd280b2010-09-27 16:05:49 +0000122
123 if (gpio_is_valid(gpmc_cfg->gpio_reset)) {
Igor Grinbergbc593f52011-05-03 18:22:09 +0300124 ret = gpio_request_one(gpmc_cfg->gpio_reset,
125 GPIOF_OUT_INIT_HIGH, "smsc911x reset");
Tim Nordellcdd280b2010-09-27 16:05:49 +0000126 if (ret) {
Igor Grinberg11383a92011-04-26 16:25:56 +0000127 pr_err("Failed to request reset GPIO%d\n",
128 gpmc_cfg->gpio_reset);
Tim Nordellcdd280b2010-09-27 16:05:49 +0000129 goto free2;
130 }
131
Tim Nordellcdd280b2010-09-27 16:05:49 +0000132 gpio_set_value(gpmc_cfg->gpio_reset, 0);
133 msleep(100);
134 gpio_set_value(gpmc_cfg->gpio_reset, 1);
135 }
136
Russ Dilla0dbf2a2012-03-23 02:21:34 -0700137 gpmc_smsc911x_config.flags = gpmc_cfg->flags ? : SMSC911X_USE_16BIT;
Mike Rapoportf0949f72011-04-16 22:29:29 +0000138
Mike Rapoport21b42732011-04-16 22:29:30 +0000139 pdev = platform_device_register_resndata(NULL, "smsc911x", gpmc_cfg->id,
140 gpmc_smsc911x_resources, ARRAY_SIZE(gpmc_smsc911x_resources),
141 &gpmc_smsc911x_config, sizeof(gpmc_smsc911x_config));
142 if (!pdev) {
Igor Grinberg11383a92011-04-26 16:25:56 +0000143 pr_err("Unable to register platform device\n");
Tim Nordellcdd280b2010-09-27 16:05:49 +0000144 gpio_free(gpmc_cfg->gpio_reset);
145 goto free2;
146 }
147
148 return;
149
150free2:
151 gpio_free(gpmc_cfg->gpio_irq);
152free1:
153 gpmc_cs_free(gpmc_cfg->cs);
154
Igor Grinberg11383a92011-04-26 16:25:56 +0000155 pr_err("Could not initialize smsc911x device\n");
Tim Nordellcdd280b2010-09-27 16:05:49 +0000156}