From nobody Wed Dec 24 10:15:08 2025 Received: from ewsoutbound.kpnmail.nl (ewsoutbound.kpnmail.nl [195.121.94.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D23FA1E51D for ; Sat, 27 Jan 2024 14:08:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.121.94.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706364487; cv=none; b=e5VpUIXsQuxv1sbLS3fb4VIzyC7pTgLeRPVB7w7n6QvtbDqh4D329WyZAPnIgD7+j6/8UrJEA4xH3PXZxVXyuLRADPYYKi4RF0zWr3O7cyO7aSUMCWEzXxtbJC/23vQW94hfXcABo8pLPGmTPnEadeEY+l7f0UydZAwbZ0/qFI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706364487; c=relaxed/simple; bh=cw1eeOM4RkSe0XSNPxAa/P/Ot8H/KXwR4u6/EczyARw=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=qR2vTND6kDbdTfq0/sF4jZ6MDW8kvvapncZ2HVS3xDhsktzq1FYYpc6VmaPIdaxyrmlEy4qTgVipgYShk4NzA0le+zSKB9n5RDYm62yE1dwAuHiLUAduFHDLTnJIT5cxa/aN/CbK8i5vCY/anlK2IccE7N58p0xqwCOSEbwUa/Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=nctdev.nl; spf=pass smtp.mailfrom=nctdev.nl; dkim=pass (1024-bit key) header.d=kpnmail.nl header.i=@kpnmail.nl header.b=YpY6eFSj; arc=none smtp.client-ip=195.121.94.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=nctdev.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nctdev.nl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=kpnmail.nl header.i=@kpnmail.nl header.b="YpY6eFSj" X-KPN-MessageId: 514459e5-bd1d-11ee-abd4-005056999439 Received: from smtp.kpnmail.nl (unknown [10.31.155.7]) by ewsoutbound.so.kpn.org (Halon) with ESMTPS id 514459e5-bd1d-11ee-abd4-005056999439; Sat, 27 Jan 2024 15:06:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kpnmail.nl; s=kpnmail01; h=content-type:subject:from:to:mime-version:date:message-id; bh=bBpLD8rwKBISkYLaBimopWAIUafM5MHOvmogIK8NVCc=; b=YpY6eFSjjmBCmJ6/oSckRvnNyNKdIZ1YUAv42Z8p/HzXPjN32oOcXclKlTxARzZOy4b8Hi5Fz4224 QgF/zcqTGFoRI7ypSGJHKVwwpXANFD/rEausj140fge7lSgo4OCa47dj1IwsiPqYGIW0bsyeKjlAu6 9RKmwdJITA7Mgubo= Received: from [192.168.2.19] (84-86-195-241.fixed.kpn.net [84.86.195.241]) by smtp.kpnmail.nl (Halon) with ESMTP id 51b0c109-bd1d-11ee-ad35-005056998788; Sat, 27 Jan 2024 15:06:51 +0100 (CET) Message-ID: <9a001fc8-d748-7d45-9a0f-6a2a5dd3438d@nctdev.nl> Date: Sat, 27 Jan 2024 15:06:51 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Content-Language: en-US To: linux-kernel@vger.kernel.org From: Nico Coesel Subject: Patch to allow hot-plugging Atmel AT24 eeproms Organization: NCT Developments Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable Hello, I'm working on an embedded project which uses SFPs (hot-pluggable=20 optical network interface modules) which have two Atmel 'AT24'=20 compatible eeproms inside. I wanted to be able to read the contents of=20 the eeproms through the nvme subsystem as a file so the higher level=20 software doesn't need to mess with I2C and all. I tried to use the at24 driver but it tests if the device is present or=20 not. Since the device may not be present, this behaviour is not suitable=20 for the project I'm working on. The patch below (against kernel version=20 5.4.142) adds a hotplug flag so the 'device present' test is skipped and=20 the device is added nevertheless. The behaviour is controlled by an=20 extra device property called 'hotplug'. diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 2cccd82..c4e9cf3 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -24,6 +24,9 @@ =C2=A0#include =C2=A0#include +//NC: Added flag to support devices not being preseny +#define AT24_FLAG_HOTPLUG=C2=A0=C2=A0=C2=A0 BIT(8) + =C2=A0/* Address pointer is 16 bit. */ =C2=A0#define AT24_FLAG_ADDR16=C2=A0=C2=A0=C2=A0 BIT(7) =C2=A0/* sysfs-entry will be read-only. */ @@ -592,6 +595,10 @@ =C2=A0=C2=A0=C2=A0=C2=A0 if (device_property_present(dev, "no-read-rollove= r")) =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 flags |=3D AT24_FLAG_NO_RDROL; +=C2=A0=C2=A0=C2=A0 //NC: Add hotplug flag. This skips device detection +=C2=A0=C2=A0=C2=A0 if (device_property_present(dev, "hotplug")) +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 flags |=3D AT24_FLAG_HOTPLUG; + =C2=A0=C2=A0=C2=A0=C2=A0 err =3D device_property_read_u32(dev, "address-wi= dth", &addrw); =C2=A0=C2=A0=C2=A0=C2=A0 if (!err) { =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 switch (addrw) { @@ -709,11 +716,14 @@ =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0* Perform a one-byte test read to verify th= at the =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0* chip is functional. =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0*/ -=C2=A0=C2=A0=C2=A0 err =3D at24_read(at24, 0, &test_byte, 1); -=C2=A0=C2=A0=C2=A0 pm_runtime_idle(dev); -=C2=A0=C2=A0=C2=A0 if (err) { -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 pm_runtime_disable(dev); -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return -ENODEV; +=C2=A0=C2=A0=C2=A0 if ((flags & AT24_FLAG_HOTPLUG) =3D=3D0) +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 { +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 err =3D at24_read(at24, 0, &test_byt= e, 1); +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 pm_runtime_idle(dev); +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (err) { +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 pm_runtime_disabl= e(dev); +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return -ENODEV; +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0 dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/wr= ite\n", I used the device tree snippet from below: =C2=A0=C2=A0=C2=A0 sfp1_info: eeprom@50 { =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 compatible =3D "atmel,24c02"; =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 reg =3D <0x50>; =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 read-only; =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 pagesize =3D <1>; =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 hotplug; =C2=A0=C2=A0 =C2=A0}; I hope this can be of use to somebody. Regards, Nico Coesel --=20 o---------------------------------------------------------------o | N C T Developments | |Innovative embedded solutions | o---------------------------------------------------------------o