^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * OPAL PNOR flash MTD abstraction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright IBM 2015
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mtd/mtd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/mtd/partitions.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/opal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * This driver creates the a Linux MTD abstraction for platform PNOR flash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * backed by OPAL calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct powernv_flash {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct mtd_info mtd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) enum flash_op {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) FLASH_OP_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) FLASH_OP_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) FLASH_OP_ERASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * Don't return -ERESTARTSYS if we can't get a token, the MTD core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * might have split up the call from userspace and called into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * driver more than once, we'll already have done some amount of work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static int powernv_flash_async_op(struct mtd_info *mtd, enum flash_op op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) loff_t offset, size_t len, size_t *retlen, u_char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct powernv_flash *info = (struct powernv_flash *)mtd->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct device *dev = &mtd->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct opal_msg msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) dev_dbg(dev, "%s(op=%d, offset=0x%llx, len=%zu)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) __func__, op, offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) token = opal_async_get_token_interruptible();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (token < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (token != -ERESTARTSYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) dev_err(dev, "Failed to get an async token\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) token = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) switch (op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) case FLASH_OP_READ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) rc = opal_flash_read(info->id, offset, __pa(buf), len, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) case FLASH_OP_WRITE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) rc = opal_flash_write(info->id, offset, __pa(buf), len, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) case FLASH_OP_ERASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) rc = opal_flash_erase(info->id, offset, len, token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) opal_async_release_token(token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (rc == OPAL_ASYNC_COMPLETION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) rc = opal_async_wait_response_interruptible(token, &msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * If we return the mtd core will free the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * buffer we've just passed to OPAL but OPAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * will continue to read or write from that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * It may be tempting to ultimately return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * if we're doing a read or a write since we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * are going to end up waiting until OPAL is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * done. However, because the MTD core sends
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * us the userspace request in chunks, we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * it to know we've been interrupted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) rc = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (opal_async_wait_response(token, &msg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) dev_err(dev, "opal_async_wait_response() failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) rc = opal_get_async_rc(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * OPAL does mutual exclusion on the flash, it will return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * OPAL_BUSY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * During firmware updates by the service processor OPAL may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * be (temporarily) prevented from accessing the flash, in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * this case OPAL will also return OPAL_BUSY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * Both cases aren't errors exactly but the flash could have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * changed, userspace should be informed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (rc != OPAL_SUCCESS && rc != OPAL_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) dev_err(dev, "opal_flash_async_op(op=%d) failed (rc %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) op, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (rc == OPAL_SUCCESS && retlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) *retlen = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) rc = opal_error_code(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) opal_async_release_token(token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * @mtd: the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * @from: the offset to read from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * @len: the number of bytes to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * @retlen: the number of bytes actually read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * @buf: the filled in buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * Returns 0 if read successful, or -ERRNO if an error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static int powernv_flash_read(struct mtd_info *mtd, loff_t from, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) size_t *retlen, u_char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return powernv_flash_async_op(mtd, FLASH_OP_READ, from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) len, retlen, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * @mtd: the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * @to: the offset to write to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * @len: the number of bytes to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * @retlen: the number of bytes actually written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * @buf: the buffer to get bytes from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * Returns 0 if write successful, -ERRNO if error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int powernv_flash_write(struct mtd_info *mtd, loff_t to, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) size_t *retlen, const u_char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return powernv_flash_async_op(mtd, FLASH_OP_WRITE, to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) len, retlen, (u_char *)buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * @mtd: the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * @erase: the erase info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * Returns 0 if erase successful or -ERRNO if an error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int powernv_flash_erase(struct mtd_info *mtd, struct erase_info *erase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) rc = powernv_flash_async_op(mtd, FLASH_OP_ERASE, erase->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) erase->len, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) erase->fail_addr = erase->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * powernv_flash_set_driver_info - Fill the mtd_info structure and docg3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * structure @pdev: The platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * @mtd: The structure to fill
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static int powernv_flash_set_driver_info(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct mtd_info *mtd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) u64 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) u32 erase_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) rc = of_property_read_u32(dev->of_node, "ibm,flash-block-size",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) &erase_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) dev_err(dev, "couldn't get resource block size information\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) rc = of_property_read_u64(dev->of_node, "reg", &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) dev_err(dev, "couldn't get resource size information\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * Going to have to check what details I need to set and how to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * get them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) mtd->type = MTD_NORFLASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) mtd->flags = MTD_WRITEABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) mtd->size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) mtd->erasesize = erase_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) mtd->writebufsize = mtd->writesize = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) mtd->owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) mtd->_erase = powernv_flash_erase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) mtd->_read = powernv_flash_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) mtd->_write = powernv_flash_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) mtd->dev.parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) mtd_set_of_node(mtd, dev->of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * powernv_flash_probe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * @pdev: platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * Returns 0 on success, -ENOMEM, -ENXIO on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int powernv_flash_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct powernv_flash *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) data->mtd.priv = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) ret = of_property_read_u32(dev->of_node, "ibm,opal-id", &(data->id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) dev_err(dev, "no device property 'ibm,opal-id'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ret = powernv_flash_set_driver_info(dev, &data->mtd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) dev_set_drvdata(dev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * The current flash that skiboot exposes is one contiguous flash chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * with an ffs partition at the start, it should prove easier for users
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * to deal with partitions or not as they see fit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return mtd_device_register(&data->mtd, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * op_release - Release the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * @pdev: the platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * Returns 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static int powernv_flash_release(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct powernv_flash *data = dev_get_drvdata(&(pdev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* All resources should be freed automatically */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return mtd_device_unregister(&(data->mtd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static const struct of_device_id powernv_flash_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) { .compatible = "ibm,opal-flash" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static struct platform_driver powernv_flash_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .name = "powernv_flash",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) .of_match_table = powernv_flash_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) .remove = powernv_flash_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) .probe = powernv_flash_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) module_platform_driver(powernv_flash_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) MODULE_DEVICE_TABLE(of, powernv_flash_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) MODULE_AUTHOR("Cyril Bur <cyril.bur@au1.ibm.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) MODULE_DESCRIPTION("MTD abstraction for OPAL flash");