Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/mtd/onenand/generic.c |
| 3 | * |
| 4 | * Copyright (c) 2005 Samsung Electronics |
| 5 | * Kyungmin Park <kyungmin.park@samsung.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * Overview: |
| 12 | * This is a device driver for the OneNAND flash for generic boards. |
| 13 | */ |
| 14 | |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 15 | #include <linux/module.h> |
Tim Schmielau | de25968 | 2006-01-08 01:02:05 -0800 | [diff] [blame] | 16 | #include <linux/slab.h> |
Kyungmin Park | 27f4e08 | 2005-12-16 11:17:29 +0900 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 18 | #include <linux/mtd/mtd.h> |
| 19 | #include <linux/mtd/onenand.h> |
| 20 | #include <linux/mtd/partitions.h> |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 21 | #include <asm/io.h> |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 22 | |
Magnus Damm | 778dbcc | 2009-09-18 12:51:44 -0700 | [diff] [blame] | 23 | /* |
| 24 | * Note: Driver name and platform data format have been updated! |
| 25 | * |
| 26 | * This version of the driver is named "onenand-flash" and takes struct |
| 27 | * onenand_platform_data as platform data. The old ARM-specific version |
| 28 | * with the name "onenand" used to take struct flash_platform_data. |
| 29 | */ |
| 30 | #define DRIVER_NAME "onenand-flash" |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 31 | |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 32 | struct onenand_info { |
| 33 | struct mtd_info mtd; |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 34 | struct onenand_chip onenand; |
| 35 | }; |
| 36 | |
Bill Pemberton | 06f2551 | 2012-11-19 13:23:07 -0500 | [diff] [blame] | 37 | static int generic_onenand_probe(struct platform_device *pdev) |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 38 | { |
| 39 | struct onenand_info *info; |
Jingoo Han | e09f7f9 | 2013-07-30 17:18:53 +0900 | [diff] [blame] | 40 | struct onenand_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 41 | struct resource *res = pdev->resource; |
Magnus Damm | 778dbcc | 2009-09-18 12:51:44 -0700 | [diff] [blame] | 42 | unsigned long size = resource_size(res); |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 43 | int err; |
| 44 | |
Burman Yan | 95b93a0 | 2006-11-15 21:10:29 +0200 | [diff] [blame] | 45 | info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL); |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 46 | if (!info) |
| 47 | return -ENOMEM; |
| 48 | |
Magnus Damm | 778dbcc | 2009-09-18 12:51:44 -0700 | [diff] [blame] | 49 | if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) { |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 50 | err = -EBUSY; |
| 51 | goto out_free_info; |
| 52 | } |
| 53 | |
| 54 | info->onenand.base = ioremap(res->start, size); |
| 55 | if (!info->onenand.base) { |
| 56 | err = -ENOMEM; |
| 57 | goto out_release_mem_region; |
| 58 | } |
| 59 | |
Brian Norris | 8b3ae73 | 2013-09-20 12:44:26 -0700 | [diff] [blame] | 60 | info->onenand.mmcontrol = pdata ? pdata->mmcontrol : NULL; |
Kyungmin Park | 2c22120 | 2006-11-16 11:23:48 +0900 | [diff] [blame] | 61 | info->onenand.irq = platform_get_irq(pdev, 0); |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 62 | |
Kay Sievers | 475b44c | 2009-01-06 10:44:38 -0800 | [diff] [blame] | 63 | info->mtd.name = dev_name(&pdev->dev); |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 64 | info->mtd.priv = &info->onenand; |
| 65 | info->mtd.owner = THIS_MODULE; |
| 66 | |
| 67 | if (onenand_scan(&info->mtd, 1)) { |
| 68 | err = -ENXIO; |
| 69 | goto out_iounmap; |
| 70 | } |
| 71 | |
Artem Bityutskiy | 42d7fbe | 2012-03-09 19:24:26 +0200 | [diff] [blame] | 72 | err = mtd_device_parse_register(&info->mtd, NULL, NULL, |
| 73 | pdata ? pdata->parts : NULL, |
| 74 | pdata ? pdata->nr_parts : 0); |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 75 | |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 76 | platform_set_drvdata(pdev, info); |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 77 | |
| 78 | return 0; |
| 79 | |
| 80 | out_iounmap: |
| 81 | iounmap(info->onenand.base); |
| 82 | out_release_mem_region: |
| 83 | release_mem_region(res->start, size); |
| 84 | out_free_info: |
| 85 | kfree(info); |
| 86 | |
| 87 | return err; |
| 88 | } |
| 89 | |
Bill Pemberton | 810b7e0 | 2012-11-19 13:26:04 -0500 | [diff] [blame] | 90 | static int generic_onenand_remove(struct platform_device *pdev) |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 91 | { |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 92 | struct onenand_info *info = platform_get_drvdata(pdev); |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 93 | struct resource *res = pdev->resource; |
Magnus Damm | 778dbcc | 2009-09-18 12:51:44 -0700 | [diff] [blame] | 94 | unsigned long size = resource_size(res); |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 95 | |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 96 | if (info) { |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 97 | onenand_release(&info->mtd); |
| 98 | release_mem_region(res->start, size); |
| 99 | iounmap(info->onenand.base); |
| 100 | kfree(info); |
| 101 | } |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 106 | static struct platform_driver generic_onenand_driver = { |
| 107 | .driver = { |
| 108 | .name = DRIVER_NAME, |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 109 | }, |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 110 | .probe = generic_onenand_probe, |
Bill Pemberton | 5153b88 | 2012-11-19 13:21:24 -0500 | [diff] [blame] | 111 | .remove = generic_onenand_remove, |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 112 | }; |
| 113 | |
Axel Lin | f99640d | 2011-11-27 20:45:03 +0800 | [diff] [blame] | 114 | module_platform_driver(generic_onenand_driver); |
Kyungmin Park | 68ee4b1 | 2005-09-09 07:39:50 +0100 | [diff] [blame] | 115 | |
| 116 | MODULE_LICENSE("GPL"); |
| 117 | MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>"); |
| 118 | MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards"); |
Axel Lin | f99640d | 2011-11-27 20:45:03 +0800 | [diff] [blame] | 119 | MODULE_ALIAS("platform:" DRIVER_NAME); |