sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / media / pci / cobalt / cobalt-flash.c
blob04dcaf9198d2dc111517eac41f348ebf4b8660b5
1 /*
2 * Cobalt NOR flash functions
4 * Copyright 2012-2015 Cisco Systems, Inc. and/or its affiliates.
5 * All rights reserved.
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
21 #include <linux/mtd/mtd.h>
22 #include <linux/mtd/map.h>
23 #include <linux/mtd/cfi.h>
24 #include <linux/time.h>
26 #include "cobalt-flash.h"
28 #define ADRS(offset) (COBALT_BUS_FLASH_BASE + offset)
30 static struct map_info cobalt_flash_map = {
31 .name = "cobalt-flash",
32 .bankwidth = 2, /* 16 bits */
33 .size = 0x4000000, /* 64MB */
34 .phys = 0, /* offset */
37 static map_word flash_read16(struct map_info *map, unsigned long offset)
39 map_word r;
41 r.x[0] = cobalt_bus_read32(map->virt, ADRS(offset));
42 if (offset & 0x2)
43 r.x[0] >>= 16;
44 else
45 r.x[0] &= 0x0000ffff;
47 return r;
50 static void flash_write16(struct map_info *map, const map_word datum,
51 unsigned long offset)
53 u16 data = (u16)datum.x[0];
55 cobalt_bus_write16(map->virt, ADRS(offset), data);
58 static void flash_copy_from(struct map_info *map, void *to,
59 unsigned long from, ssize_t len)
61 u32 src = from;
62 u8 *dest = to;
63 u32 data;
65 while (len) {
66 data = cobalt_bus_read32(map->virt, ADRS(src));
67 do {
68 *dest = data >> (8 * (src & 3));
69 src++;
70 dest++;
71 len--;
72 } while (len && (src % 4));
76 static void flash_copy_to(struct map_info *map, unsigned long to,
77 const void *from, ssize_t len)
79 const u8 *src = from;
80 u32 dest = to;
82 pr_info("%s: offset 0x%x: length %zu\n", __func__, dest, len);
83 while (len) {
84 u16 data = 0xffff;
86 do {
87 data = *src << (8 * (dest & 1));
88 src++;
89 dest++;
90 len--;
91 } while (len && (dest % 2));
93 cobalt_bus_write16(map->virt, ADRS(dest - 2), data);
97 int cobalt_flash_probe(struct cobalt *cobalt)
99 struct map_info *map = &cobalt_flash_map;
100 struct mtd_info *mtd;
102 BUG_ON(!map_bankwidth_supported(map->bankwidth));
103 map->virt = cobalt->bar1;
104 map->read = flash_read16;
105 map->write = flash_write16;
106 map->copy_from = flash_copy_from;
107 map->copy_to = flash_copy_to;
109 mtd = do_map_probe("cfi_probe", map);
110 cobalt->mtd = mtd;
111 if (!mtd) {
112 cobalt_err("Probe CFI flash failed!\n");
113 return -1;
116 mtd->owner = THIS_MODULE;
117 mtd->dev.parent = &cobalt->pci_dev->dev;
118 mtd_device_register(mtd, NULL, 0);
119 return 0;
122 void cobalt_flash_remove(struct cobalt *cobalt)
124 if (cobalt->mtd) {
125 mtd_device_unregister(cobalt->mtd);
126 map_destroy(cobalt->mtd);