netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] eeprom_93cx6: Add write support
@ 2006-12-13 18:56 Ivo van Doorn
  2006-12-13 19:06 ` Lennart Sorensen
  0 siblings, 1 reply; 5+ messages in thread
From: Ivo van Doorn @ 2006-12-13 18:56 UTC (permalink / raw)
  To: John W. Linville; +Cc: netdev, Lennart Sorensen, Michael Wu

This patch addes support for writing to the eeprom,
this also moves some duplicate code into seperate functions.

Signed-off-by Ivo van Doorn <IvDoorn@gmail.com>

---

diff -rNU3 wireless-dev/include/linux/eeprom_93cx6.h wireless-dev-eeprom/include/linux/eeprom_93cx6.h
--- wireless-dev/include/linux/eeprom_93cx6.h	2006-12-13 19:04:44.000000000 +0100
+++ wireless-dev-eeprom/include/linux/eeprom_93cx6.h	2006-12-13 18:28:36.000000000 +0100
@@ -32,6 +32,8 @@
 #define PCI_EEPROM_WIDTH_OPCODE	3
 #define PCI_EEPROM_WRITE_OPCODE	0x05
 #define PCI_EEPROM_READ_OPCODE	0x06
+#define PCI_EEPROM_EWDS_OPCODE	0x10
+#define PCI_EEPROM_EWEN_OPCODE	0x13
 
 /**
  * struct eeprom_93cx6 - control structure for setting the commands
@@ -68,3 +70,8 @@
 	const u8 word, __le16 *data);
 extern void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom,
 	const u8 word, __le16 *data, const u16 words);
+
+extern void eeprom_93cx6_write(struct eeprom_93cx6 *eeprom,
+	const u8 word, __le16 *data);
+extern void eeprom_93cx6_multiwrite(struct eeprom_93cx6 *eeprom,
+	const u8 word, __le16 *data, const u16 words);
diff -rNU3 wireless-dev/lib/eeprom_93cx6.c wireless-dev-eeprom/lib/eeprom_93cx6.c
--- wireless-dev/lib/eeprom_93cx6.c	2006-12-13 19:04:44.000000000 +0100
+++ wireless-dev-eeprom/lib/eeprom_93cx6.c	2006-12-13 18:50:25.000000000 +0100
@@ -49,6 +49,42 @@
 	udelay(1);
 }
 
+static void eeprom_93cx6_startup(struct eeprom_93cx6 *eeprom)
+{
+	/*
+	 * Clear all flags, and enable chip select.
+	 */
+	eeprom->register_read(eeprom);
+	eeprom->reg_data_in = 0;
+	eeprom->reg_data_out = 0;
+	eeprom->reg_data_clock = 0;
+	eeprom->reg_chip_select = 1;
+	eeprom->register_write(eeprom);
+
+	/*
+	 * kick a pulse.
+	 */
+	eeprom_93cx6_pulse_high(eeprom);
+	eeprom_93cx6_pulse_low(eeprom);
+}
+
+static void eeprom_93cx6_cleanup(struct eeprom_93cx6 *eeprom)
+{
+	/*
+	 * Clear chip_select and data_in flags.
+	 */
+	eeprom->register_read(eeprom);
+	eeprom->reg_data_in = 0;
+	eeprom->reg_chip_select = 0;
+	eeprom->register_write(eeprom);
+
+	/*
+	 * kick a pulse.
+	 */
+	eeprom_93cx6_pulse_high(eeprom);
+	eeprom_93cx6_pulse_low(eeprom);
+}
+
 static void eeprom_93cx6_write_bits(struct eeprom_93cx6 *eeprom,
 	const u16 data, const u16 count)
 {
@@ -123,6 +159,44 @@
 	}
 }
 
+static void eeprom_93cx6_ewen(struct eeprom_93cx6 *eeprom)
+{
+	/*
+	 * Initialize the eeprom register
+	 */
+	eeprom_93cx6_startup(eeprom);
+
+	/*
+	 * Select the read opcode and the word to be read.
+	 */
+	eeprom_93cx6_write_bits(eeprom, PCI_EEPROM_EWEN_OPCODE, 5);
+	eeprom_93cx6_write_bits(eeprom, 0, 6);
+
+	/*
+	 * Cleanup eeprom register.
+	 */
+	eeprom_93cx6_cleanup(eeprom);
+}
+
+static void eeprom_93cx6_ewds(struct eeprom_93cx6 *eeprom)
+{
+	/*
+	 * Initialize the eeprom register
+	 */
+	eeprom_93cx6_startup(eeprom);
+
+	/*
+	 * Select the read opcode and the word to be read.
+	 */
+	eeprom_93cx6_write_bits(eeprom, PCI_EEPROM_EWDS_OPCODE, 5);
+	eeprom_93cx6_write_bits(eeprom, 0, 6);
+
+	/*
+	 * Cleanup eeprom register.
+	 */
+	eeprom_93cx6_cleanup(eeprom);
+}
+
 /**
  * eeprom_93cx6_read - Read multiple words from eeprom
  * @eeprom: Pointer to eeprom structure
@@ -139,20 +213,9 @@
 	u16 buffer = 0;
 
 	/*
-	 * Clear all flags, and enable chip select.
+	 * Initialize the eeprom register
 	 */
-	eeprom->register_read(eeprom);
-	eeprom->reg_data_in = 0;
-	eeprom->reg_data_out = 0;
-	eeprom->reg_data_clock = 0;
-	eeprom->reg_chip_select = 1;
-	eeprom->register_write(eeprom);
-
-	/*
-	 * kick a pulse.
-	 */
-	eeprom_93cx6_pulse_high(eeprom);
-	eeprom_93cx6_pulse_low(eeprom);
+	eeprom_93cx6_startup(eeprom);
 
 	/*
 	 * Select the read opcode and the word to be read.
@@ -167,18 +230,9 @@
 	eeprom_93cx6_read_bits(eeprom, &buffer, 16);
 
 	/*
-	 * Clear chip_select and data_in flags.
-	 */
-	eeprom->register_read(eeprom);
-	eeprom->reg_data_in = 0;
-	eeprom->reg_chip_select = 0;
-	eeprom->register_write(eeprom);
-
-	/*
-	 * kick a pulse.
+	 * Cleanup eeprom register.
 	 */
-	eeprom_93cx6_pulse_high(eeprom);
-	eeprom_93cx6_pulse_low(eeprom);
+	eeprom_93cx6_cleanup(eeprom);
 
 	/*
 	 * The data from the eeprom is stored as little endian,
@@ -208,3 +262,82 @@
 		eeprom_93cx6_read(eeprom, word + i, data++);
 }
 EXPORT_SYMBOL_GPL(eeprom_93cx6_multiread);
+
+/**
+ * eeprom_93cx6_write - Write multiple words to the eeprom
+ * @eeprom: Pointer to eeprom structure
+ * @word: Word index from where we should start writing
+ * @data: Pointer where the information will be read from
+ *
+ * This function will write the eeprom data as little endian word
+ * from the given data pointer.
+ */
+void eeprom_93cx6_write(struct eeprom_93cx6 *eeprom, const u8 word,
+	__le16 *data)
+{
+	u16 command;
+
+	/*
+	 * select the ewen opcode.
+	 */
+	eeprom_93cx6_ewen(eeprom);
+
+	/*
+	 * Initialize the eeprom register
+	 */
+	eeprom_93cx6_startup(eeprom);
+
+	/*
+	 * Select the write opcode and the word to be read.
+	 */
+	command = (PCI_EEPROM_WRITE_OPCODE << eeprom->width) | word;
+	eeprom_93cx6_write_bits(eeprom, command,
+		PCI_EEPROM_WIDTH_OPCODE + eeprom->width);
+
+	/*
+	 * Write the requested 16 bits.
+	 */
+	eeprom_93cx6_write_bits(eeprom, *data, 16);
+
+	/*
+	 * Cleanup eeprom register.
+	 */
+	eeprom_93cx6_cleanup(eeprom);
+
+	/*
+	 * Take a short break.
+	 */
+	msleep(10000);
+
+	/*
+	 * select the ewen opcode.
+	 */
+	eeprom_93cx6_ewds(eeprom);
+
+	/*
+	 * Cleanup eeprom register.
+	 */
+	eeprom_93cx6_cleanup(eeprom);
+}
+EXPORT_SYMBOL_GPL(eeprom_93cx6_write);
+
+
+/**
+ * eeprom_93cx6_multiwrite - Write multiple words to the eeprom
+ * @eeprom: Pointer to eeprom structure
+ * @word: Word index from where we should start writing
+ * @data: Pointer where the information will be read from
+ * @words: Number of words that should be written.
+ *
+ * This function will write all requested words to the eeprom,
+ * this is done by calling eeprom_93cx6_write() multiple times.
+ */
+void eeprom_93cx6_multiwrite(struct eeprom_93cx6 *eeprom, const u8 word,
+	__le16 *data, const u16 words)
+{
+	unsigned int i;
+
+	for (i = 0; i < words; i++)
+		eeprom_93cx6_write(eeprom, word + i, data++);
+}
+EXPORT_SYMBOL_GPL(eeprom_93cx6_multiwrite);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] eeprom_93cx6: Add write support
  2006-12-13 18:56 [PATCH] eeprom_93cx6: Add write support Ivo van Doorn
@ 2006-12-13 19:06 ` Lennart Sorensen
  2006-12-15 11:58   ` EEPROM infrastructure (was: [PATCH] eeprom_93cx6: Add write support) Ingo Oeser
  2006-12-21  7:22   ` [PATCH] eeprom_93cx6: Add write support Ivo Van Doorn
  0 siblings, 2 replies; 5+ messages in thread
From: Lennart Sorensen @ 2006-12-13 19:06 UTC (permalink / raw)
  To: Ivo van Doorn; +Cc: John W. Linville, netdev, Michael Wu

On Wed, Dec 13, 2006 at 07:56:50PM +0100, Ivo van Doorn wrote:
> This patch addes support for writing to the eeprom,
> this also moves some duplicate code into seperate functions.
> 
> Signed-off-by Ivo van Doorn <IvDoorn@gmail.com>

Thank you.  I will have a try with that to see if I can get that to work
with the jsm driver.  Too bad the serial drivers don't have any
geteeprom/seteeprom standard ioctl's the way ethtool does for network
devices.

--
Len Sorensen

^ permalink raw reply	[flat|nested] 5+ messages in thread

* EEPROM infrastructure (was: [PATCH] eeprom_93cx6: Add write support)
  2006-12-13 19:06 ` Lennart Sorensen
@ 2006-12-15 11:58   ` Ingo Oeser
  2006-12-21  7:22   ` [PATCH] eeprom_93cx6: Add write support Ivo Van Doorn
  1 sibling, 0 replies; 5+ messages in thread
From: Ingo Oeser @ 2006-12-15 11:58 UTC (permalink / raw)
  To: Lennart Sorensen
  Cc: Ivo van Doorn, John W. Linville, netdev, Michael Wu, linux-kernel,
	Ingo Oeser

Lennart Sorensen schrieb:
> On Wed, Dec 13, 2006 at 07:56:50PM +0100, Ivo van Doorn wrote:
> > This patch addes support for writing to the eeprom,
> > this also moves some duplicate code into seperate functions.
> > 
> > Signed-off-by Ivo van Doorn <IvDoorn@gmail.com>
> 
> Thank you.  I will have a try with that to see if I can get that to work
> with the jsm driver.  Too bad the serial drivers don't have any
> geteeprom/seteeprom standard ioctl's the way ethtool does for network
> devices.

It might be even better to have eeprom writing infrastructure.

Many device types come with eeproms today and they implement
it per driver or subsystem. On embedded platforms these EEPROMs
might even be shared among different devices.

So it might be time to generalize this like we did with LEDs.

Any comments?

Regards

Ingo Oeser

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] eeprom_93cx6: Add write support
  2006-12-13 19:06 ` Lennart Sorensen
  2006-12-15 11:58   ` EEPROM infrastructure (was: [PATCH] eeprom_93cx6: Add write support) Ingo Oeser
@ 2006-12-21  7:22   ` Ivo Van Doorn
  2006-12-21 18:54     ` Ivo van Doorn
  1 sibling, 1 reply; 5+ messages in thread
From: Ivo Van Doorn @ 2006-12-21  7:22 UTC (permalink / raw)
  To: John W. Linville; +Cc: Lennart Sorensen, netdev, Michael Wu

Hi,

> This patch addes support for writing to the eeprom,
> this also moves some duplicate code into seperate functions.

John: Do you want me to merge this path with the eeprom merge patch,
and move the patch that moves rt2x00 to use this eeprom module into a
separate patch or all these 2 patches good enough?

Ivo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] eeprom_93cx6: Add write support
  2006-12-21  7:22   ` [PATCH] eeprom_93cx6: Add write support Ivo Van Doorn
@ 2006-12-21 18:54     ` Ivo van Doorn
  0 siblings, 0 replies; 5+ messages in thread
From: Ivo van Doorn @ 2006-12-21 18:54 UTC (permalink / raw)
  To: John W. Linville; +Cc: Lennart Sorensen, netdev, Michael Wu

Hi,

> > This patch addes support for writing to the eeprom,
> > this also moves some duplicate code into seperate functions.
> 
> John: Do you want me to merge this path with the eeprom merge patch,
> and move the patch that moves rt2x00 to use this eeprom module into a
> separate patch or all these 2 patches good enough?

I shouldn't write mails while tired. Let met explain myself. ;)
eeprom_93cx6 has now 2 patches pending:
 1 - move eeprom_93cx6 out of rt2x00 and into /lib
 2 - add write support for eeprom_93cx6

Should patch 1 be split into a patch to add eeprom_93cx6
to the /lib folder and a seperate patch to remove the module
from rt2x00?

And while redoing the patch, merge patch 2 with the patch to add
eeprom_93cx6 to /lib?

Ivo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-12-21 18:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-13 18:56 [PATCH] eeprom_93cx6: Add write support Ivo van Doorn
2006-12-13 19:06 ` Lennart Sorensen
2006-12-15 11:58   ` EEPROM infrastructure (was: [PATCH] eeprom_93cx6: Add write support) Ingo Oeser
2006-12-21  7:22   ` [PATCH] eeprom_93cx6: Add write support Ivo Van Doorn
2006-12-21 18:54     ` Ivo van Doorn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).