Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 1 | /* |
| 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 Grinberg | 11383a9 | 2011-04-26 16:25:56 +0000 | [diff] [blame] | 13 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 14 | |
| 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 Porter | e4b0b2c | 2012-02-23 09:16:04 -0500 | [diff] [blame] | 22 | #include <linux/regulator/fixed.h> |
| 23 | #include <linux/regulator/machine.h> |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 24 | |
| 25 | #include <plat/board.h> |
| 26 | #include <plat/gpmc.h> |
| 27 | #include <plat/gpmc-smsc911x.h> |
| 28 | |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 29 | static struct resource gpmc_smsc911x_resources[] = { |
| 30 | [0] = { |
| 31 | .flags = IORESOURCE_MEM, |
| 32 | }, |
| 33 | [1] = { |
Mike Rapoport | f0949f7 | 2011-04-16 22:29:29 +0000 | [diff] [blame] | 34 | .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL, |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 35 | }, |
| 36 | }; |
| 37 | |
| 38 | static 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 Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
Matt Porter | e4b0b2c | 2012-02-23 09:16:04 -0500 | [diff] [blame] | 44 | static 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 */ |
| 50 | static 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 | |
| 63 | static 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 | */ |
| 80 | static 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 Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 88 | /* |
| 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 Dill | 54da078 | 2012-03-23 02:21:33 -0700 | [diff] [blame] | 93 | void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *gpmc_cfg) |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 94 | { |
Mike Rapoport | 21b4273 | 2011-04-16 22:29:30 +0000 | [diff] [blame] | 95 | struct platform_device *pdev; |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 96 | unsigned long cs_mem_base; |
| 97 | int ret; |
| 98 | |
Kevin Hilman | bb60424 | 2012-03-01 12:30:42 -0800 | [diff] [blame] | 99 | 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 Porter | e4b0b2c | 2012-02-23 09:16:04 -0500 | [diff] [blame] | 106 | } |
| 107 | |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 108 | if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) { |
Igor Grinberg | 11383a9 | 2011-04-26 16:25:56 +0000 | [diff] [blame] | 109 | pr_err("Failed to request GPMC mem region\n"); |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 110 | 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 Grinberg | bc593f5 | 2011-05-03 18:22:09 +0300 | [diff] [blame] | 116 | if (gpio_request_one(gpmc_cfg->gpio_irq, GPIOF_IN, "smsc911x irq")) { |
Igor Grinberg | 11383a9 | 2011-04-26 16:25:56 +0000 | [diff] [blame] | 117 | pr_err("Failed to request IRQ GPIO%d\n", gpmc_cfg->gpio_irq); |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 118 | goto free1; |
| 119 | } |
| 120 | |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 121 | gpmc_smsc911x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq); |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 122 | |
| 123 | if (gpio_is_valid(gpmc_cfg->gpio_reset)) { |
Igor Grinberg | bc593f5 | 2011-05-03 18:22:09 +0300 | [diff] [blame] | 124 | ret = gpio_request_one(gpmc_cfg->gpio_reset, |
| 125 | GPIOF_OUT_INIT_HIGH, "smsc911x reset"); |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 126 | if (ret) { |
Igor Grinberg | 11383a9 | 2011-04-26 16:25:56 +0000 | [diff] [blame] | 127 | pr_err("Failed to request reset GPIO%d\n", |
| 128 | gpmc_cfg->gpio_reset); |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 129 | goto free2; |
| 130 | } |
| 131 | |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 132 | gpio_set_value(gpmc_cfg->gpio_reset, 0); |
| 133 | msleep(100); |
| 134 | gpio_set_value(gpmc_cfg->gpio_reset, 1); |
| 135 | } |
| 136 | |
Russ Dill | a0dbf2a | 2012-03-23 02:21:34 -0700 | [diff] [blame^] | 137 | gpmc_smsc911x_config.flags = gpmc_cfg->flags ? : SMSC911X_USE_16BIT; |
Mike Rapoport | f0949f7 | 2011-04-16 22:29:29 +0000 | [diff] [blame] | 138 | |
Mike Rapoport | 21b4273 | 2011-04-16 22:29:30 +0000 | [diff] [blame] | 139 | 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 Grinberg | 11383a9 | 2011-04-26 16:25:56 +0000 | [diff] [blame] | 143 | pr_err("Unable to register platform device\n"); |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 144 | gpio_free(gpmc_cfg->gpio_reset); |
| 145 | goto free2; |
| 146 | } |
| 147 | |
| 148 | return; |
| 149 | |
| 150 | free2: |
| 151 | gpio_free(gpmc_cfg->gpio_irq); |
| 152 | free1: |
| 153 | gpmc_cs_free(gpmc_cfg->cs); |
| 154 | |
Igor Grinberg | 11383a9 | 2011-04-26 16:25:56 +0000 | [diff] [blame] | 155 | pr_err("Could not initialize smsc911x device\n"); |
Tim Nordell | cdd280b | 2010-09-27 16:05:49 +0000 | [diff] [blame] | 156 | } |