Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp94201yba; Mon, 1 Apr 2019 02:27:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqBjyk+f5uHCK9wOAO/fLDRl0ZIBrKir6joLZ7rVcdByUTtbIi2TJun0KewLKuDzFwyIj5 X-Received: by 2002:a63:c302:: with SMTP id c2mr32584276pgd.235.1554110854734; Mon, 01 Apr 2019 02:27:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554110854; cv=none; d=google.com; s=arc-20160816; b=uT+7FQMsqt2uym3FISLMGMyy7oamAEnch+PE/A9SQU+9pzvkTQ8PMEgSU9OFVM0HtQ g7OQfP3I4hexHTPm7HJgbzlfNE3olCpSeNgF/LAwJbqCOkYI84NffuRbZ31HuVd203pi vQvdtzhPK35Yf4jXdfFLJctxNecY8czrPFRyucxOu72E/jKeWYFZAk1ABN09UX2Uj7y6 pIe4cphCdGArGCBmGQY7nyevHu2fPlVnMFCw8+Omj9jhkpP+A3dI4n39ET53wV1kLnf6 axvHmae07mF96j9Zb5WhJ4MNbBrQSh/hBRMyANJiAy1ZmXgxM3ZTS5WES5T9867hUf0F He+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=7/zrkTRHXZhK33NRMz6bOEjVF2oOULEfSZzLKWRdAtU=; b=sdBZkliQb7Ho6i6BrkU96ROae13bPOn/rLb1mipML+A3mkbwVh4fxhrPJU0XQjOIvI l44WZmHt5f1VLRRbAjlvk0GAIG7Vy9xW+zqCpdnxQzbsG+aPqyLG64FnKkxBQMliWuKk MlBtbUsIEctj5PrP2lDFM+uMjjePrwPZAp29DoWvTPk9zaZbxQsYPdlAuxCt4JN52PKN k7Nu2D/sVztK0JC92MspL6e68ExpJdyJwJXnm/DBJmZA6mvSxr6Dv35GojSgTrkc1hlJ MD17hyg0ONzYjWHxHM58o7o4YYORRx4AtDxuBrcQVoyw2pWuh3he/9aAw8oIbv5dWxd3 UMUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w3si8230845plp.35.2019.04.01.02.27.19; Mon, 01 Apr 2019 02:27:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726421AbfDAJ0H (ORCPT + 99 others); Mon, 1 Apr 2019 05:26:07 -0400 Received: from mail-ua1-f67.google.com ([209.85.222.67]:34879 "EHLO mail-ua1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbfDAJ0G (ORCPT ); Mon, 1 Apr 2019 05:26:06 -0400 Received: by mail-ua1-f67.google.com with SMTP id f88so2818305uaf.2; Mon, 01 Apr 2019 02:26:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7/zrkTRHXZhK33NRMz6bOEjVF2oOULEfSZzLKWRdAtU=; b=fcqSzgW/N8N7RiJaGw1lkxjYv3siRBXyY9VYc7Kf/rnR8wp8v+tF0nmu9aQCoQbF3p eEZ6Umh87lqips0U2XaGQvhRIHXzYS10uBjux05mEMzZdTUQ+BrhJSRIAcOquwM1hHhl Q48vfm9y/cWiyjJ0YP6mEhZqVFi6oIeIWffHqvs+cu/GBTKFj9jcHGruuMDZuN0Uvhop PlCaF0n+YeaQWOZZcbS0Xk1Z7xOfvYeHAyl9g9eMMmO9vc8Q+eBLXyhAqW3cQga2qfDW mjN0QeV8/Yh3IIYPmVhYhx2aQVtbsnx3A6DVBSPQPG2w2BKN0zp1BnzAsToSjn01ODgQ YjTQ== X-Gm-Message-State: APjAAAVoC8RD8WnoOkTFI7vm/nCPFDkPYKjgxkbBrOOUzvbozaQwGwbh oGpWqfGFdUygzoGNTrgfgvkYLo95wp2gEfN1GiU= X-Received: by 2002:ab0:6419:: with SMTP id x25mr31251001uao.86.1554110764857; Mon, 01 Apr 2019 02:26:04 -0700 (PDT) MIME-Version: 1.0 References: <20190330141637.22632-1-boris.brezillon@collabora.com> In-Reply-To: <20190330141637.22632-1-boris.brezillon@collabora.com> From: Geert Uytterhoeven Date: Mon, 1 Apr 2019 11:25:53 +0200 Message-ID: Subject: Re: [PATCH] eeprom: at25: Convert the driver to the spi-mem interface To: Boris Brezillon Cc: Arnd Bergmann , Greg Kroah-Hartman , Linux Kernel Mailing List , Mark Brown , linux-spi , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , MTD Maling List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Boris, On Sat, Mar 30, 2019 at 3:16 PM Boris Brezillon wrote: > The AT25 protocol fits pretty well in the spi-mem model. Convert the > at25 spi driver to a spi-mem driver and use the dirmap API instead of > forging SPI messages manually. > This makes the driver compatible with spi-mem-only controllers > (controllers implementing only the spi_mem ops). Thanks for your patch! > Signed-off-by: Boris Brezillon Tested-by: Geert Uytterhoeven > --- a/drivers/misc/eeprom/at25.c > +++ b/drivers/misc/eeprom/at25.c > @@ -63,17 +68,89 @@ struct at25_data { > > #define io_limit PAGE_SIZE /* bytes */ > > +static int at25_create_dirmaps(struct at25_data *at25) > +{ > + struct spi_mem_dirmap_info info = { > + .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(AT25_READ, 1), > + SPI_MEM_OP_ADDR(at25->addrlen, 0, 1), > + SPI_MEM_OP_NO_DUMMY, > + SPI_MEM_OP_DATA_IN(0, NULL, 1)), > + .offset = 0, > + .length = at25->chip.byte_len, > + }; > + struct device *dev = &at25->spimem->spi->dev; > + > + if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR) > + info.length = 256; Note that by hardcoding 256 you do loose the ability to support chips where EE_INSTR_BIT3_IS_ADDR is set, _and_ more than one address byte is used (i.e. extra bit is A16 or A24). While the code parsing "address-width" doesn't handle that, the comment for EE_INSTR_BIT3_IS_ADDR suggests such chips do exist (I doubt it, though, but you may know better), and the flag can be enabled through the "at25,addr-mode" property, or through platform_data. > @@ -82,38 +159,14 @@ static int at25_ee_read(void *priv, unsigned int offset, > if (unlikely(!count)) > return -EINVAL; > > - cp = command; > - > - instr = AT25_READ; > - if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR) > - if (offset >= (1U << (at25->addrlen * 8))) > - instr |= AT25_INSTR_BIT3; > - *cp++ = instr; > - > - /* 8/16/24-bit address is written MSB first */ > - switch (at25->addrlen) { > - default: /* case 3 */ > - *cp++ = offset >> 16; > - /* fall through */ > - case 2: > - *cp++ = offset >> 8; > - /* fall through */ > - case 1: > - case 0: /* can't happen: for better codegen */ > - *cp++ = offset >> 0; > + if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR && offset > 255) { Loss of support for address bit A16/A24. > + desc = at25->dirmap.rdesc[1]; > + dirmap_offset = offset - 256; > + } else { > + desc = at25->dirmap.rdesc[0]; > + dirmap_offset = offset; > } > @@ -158,48 +211,37 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count) > */ > mutex_lock(&at25->lock); > do { > + struct spi_mem_dirmap_desc *desc; > unsigned long timeout, retries; > unsigned segment; > - unsigned offset = (unsigned) off; > - u8 *cp = bounce; > + unsigned int dirmap_offset; > int sr; > - u8 instr; > > - *cp = AT25_WREN; > - status = spi_write(at25->spi, cp, 1); > + status = at25_wren(at25); > if (status < 0) { > - dev_dbg(&at25->spi->dev, "WREN --> %d\n", status); > + dev_dbg(&at25->spimem->spi->dev, "WREN --> %d\n", > + status); > break; > } > > - instr = AT25_WRITE; > - if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR) > - if (offset >= (1U << (at25->addrlen * 8))) > - instr |= AT25_INSTR_BIT3; > - *cp++ = instr; > - > - /* 8/16/24-bit address is written MSB first */ > - switch (at25->addrlen) { > - default: /* case 3 */ > - *cp++ = offset >> 16; > - /* fall through */ > - case 2: > - *cp++ = offset >> 8; > - /* fall through */ > - case 1: > - case 0: /* can't happen: for better codegen */ > - *cp++ = offset >> 0; > + if (at25->chip.flags & EE_INSTR_BIT3_IS_ADDR && off > 255) { Loss of support for address bit A16/A24. > + desc = at25->dirmap.wdesc[1]; > + dirmap_offset = off - 256; Two spaces after minus sign. > + } else { > + desc = at25->dirmap.wdesc[0]; > + dirmap_offset = off; > } > @@ -211,10 +253,9 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count) > timeout = jiffies + msecs_to_jiffies(EE_TIMEOUT); > retries = 0; > do { > - > - sr = spi_w8r8(at25->spi, AT25_RDSR); > + sr = at25_rdsr(at25); > if (sr < 0 || (sr & AT25_SR_nRDY)) { > - dev_dbg(&at25->spi->dev, > + dev_dbg(&at25->spimem->spi->dev, > "rdsr --> %d (%02x)\n", sr, sr); You might want to move the debug print inside the new function at25_rdsr(), as there's another call plus debug print in at25_probe(). > @@ -328,37 +369,49 @@ static int at25_probe(struct spi_device *spi) > else if (chip.flags & EE_ADDR3) > addrlen = 3; > else { > - dev_dbg(&spi->dev, "unsupported address type\n"); > + dev_dbg(&spimem->spi->dev, "unsupported address type\n"); > return -EINVAL; > } > > - /* Ping the chip ... the status register is pretty portable, > - * unlike probing manufacturer IDs. We do expect that system > - * firmware didn't write it in the past few milliseconds! > - */ > - sr = spi_w8r8(spi, AT25_RDSR); > - if (sr < 0 || sr & AT25_SR_nRDY) { > - dev_dbg(&spi->dev, "rdsr --> %d (%02x)\n", sr, sr); > - return -ENXIO; > - } > - > - at25 = devm_kzalloc(&spi->dev, sizeof(struct at25_data), GFP_KERNEL); > + at25 = devm_kzalloc(&spimem->spi->dev, sizeof(struct at25_data), > + GFP_KERNEL); > if (!at25) > return -ENOMEM; > > mutex_init(&at25->lock); > at25->chip = chip; > - at25->spi = spi; > - spi_set_drvdata(spi, at25); > + at25->spimem = spimem; > + spi_mem_set_drvdata(spimem, at25); > at25->addrlen = addrlen; > > - at25->nvmem_config.name = dev_name(&spi->dev); > - at25->nvmem_config.dev = &spi->dev; > + /* > + * Can't be allocated with devm_kmalloc() because we need a DMA-safe > + * buffer. > + */ That is no longer true as of commit a66d972465d15b1d ("devres: Align data[] to ARCH_KMALLOC_MINALIGN") in v4.20-rc5, right? > + at25->scratchbuf = kmalloc(1, GFP_KERNEL); Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds