From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Chou Date: Fri, 6 Nov 2015 12:34:33 +0800 Subject: [U-Boot] [PATCH v4 2/3] cfi_flash: convert to driver model In-Reply-To: References: <1444289667-23775-1-git-send-email-thomas@wytron.com.tw> <1446556146-9876-1-git-send-email-thomas@wytron.com.tw> <1446556146-9876-2-git-send-email-thomas@wytron.com.tw> Message-ID: <563C2DD9.90502@wytron.com.tw> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Simon, On 2015?11?06? 11:15, Simon Glass wrote: >> +config CFI_FLASH >> + bool "Enable Driver Model for CFI Flash driver" >> + depends on MTD >> + help >> + The Common Flash Interface specification was developed by Intel, >> + AMD and other flash manufactures that provides a universal method > > flash manufacturers. It provides a universal method > OK. Thanks. >> +#ifdef CONFIG_CFI_FLASH /* for driver model */ >> +static void cfi_flash_init_dm(void) >> +{ >> + struct udevice *dev; >> + >> + cfi_flash_num_flash_banks = 0; >> + /* >> + * The uclass_first_device() will probe the first device and >> + * uclass_next_device() will probe the rest if they exist. So >> + * that cfi_flash_probe() will get called assigning the base >> + * addresses that are available. >> + */ >> + for (uclass_first_device(UCLASS_MTD, &dev); >> + dev; >> + uclass_next_device(&dev)) { >> + } > > Why do you need to probe these before they are used? Also I think you > need error checking. This is the place that the device is going to be used. In flash_init() the cfi flash is probed to find flash type and size. There may be other MTD devices, so we scan through them. If there is not cfi flash device, cfi_flash_num_flash_banks will be zero and the flash_init will return size as zero. This is not an error. >> +#ifdef CONFIG_FLASH_CFI_MTD >> + dev->uclass_priv = &cfi_mtd_info[0]; > > Could you put cfi_mtd_info in a struct and use auto-allocation to allocate it? I planned this as follow-up patches which will merge cfi-mtd.c and use mtd ops as major flash ops. Then the mtd_info will be auto-allocated. This is quite similar to Jagan's work on spi-nor. Best regards, Thomas