Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * EEPROMs access control driver for display configuration EEPROMs
4 * on DigsyMTC board.
5 *
6 * (C) 2011 DENX Software Engineering, Anatolij Gustschin <agust@denx.de>
7 *
8 * FIXME: this driver is used on a device-tree probed platform: it
9 * should be defined as a bit-banged SPI device and probed from the device
10 * tree and not like this with static grabbing of a few numbered GPIO
11 * lines at random.
12 *
13 * Add proper SPI and EEPROM in arch/powerpc/boot/dts/digsy_mtc.dts
14 * and delete this driver.
15 */
16
17#include <linux/gpio/machine.h>
18#include <linux/init.h>
19#include <linux/platform_device.h>
20#include <linux/property.h>
21#include <linux/spi/spi.h>
22#include <linux/spi/spi_gpio.h>
23
24#define GPIO_EEPROM_CLK 216
25#define GPIO_EEPROM_CS 210
26#define GPIO_EEPROM_DI 217
27#define GPIO_EEPROM_DO 249
28#define GPIO_EEPROM_OE 255
29#define EE_SPI_BUS_NUM 1
30
31static const struct property_entry digsy_mtc_spi_properties[] = {
32 PROPERTY_ENTRY_U32("data-size", 8),
33 { }
34};
35
36static const struct software_node digsy_mtc_spi_node = {
37 .properties = digsy_mtc_spi_properties,
38};
39
40static struct spi_gpio_platform_data eeprom_spi_gpio_data = {
41 .num_chipselect = 1,
42};
43
44static struct platform_device digsy_mtc_eeprom = {
45 .name = "spi_gpio",
46 .id = EE_SPI_BUS_NUM,
47 .dev = {
48 .platform_data = &eeprom_spi_gpio_data,
49 },
50};
51
52static struct gpiod_lookup_table eeprom_spi_gpiod_table = {
53 .dev_id = "spi_gpio.1",
54 .table = {
55 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CLK,
56 "sck", GPIO_ACTIVE_HIGH),
57 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DI,
58 "mosi", GPIO_ACTIVE_HIGH),
59 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DO,
60 "miso", GPIO_ACTIVE_HIGH),
61 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CS,
62 "cs", GPIO_ACTIVE_HIGH),
63 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_OE,
64 "select", GPIO_ACTIVE_LOW),
65 { },
66 },
67};
68
69static struct spi_board_info digsy_mtc_eeprom_info[] __initdata = {
70 {
71 .modalias = "eeprom-93xx46",
72 .max_speed_hz = 1000000,
73 .bus_num = EE_SPI_BUS_NUM,
74 .chip_select = 0,
75 .mode = SPI_MODE_0,
76 },
77};
78
79static int __init digsy_mtc_eeprom_devices_init(void)
80{
81 int ret;
82
83 gpiod_add_lookup_table(&eeprom_spi_gpiod_table);
84 spi_register_board_info(digsy_mtc_eeprom_info,
85 ARRAY_SIZE(digsy_mtc_eeprom_info));
86
87 ret = device_add_software_node(&digsy_mtc_eeprom.dev, &digsy_mtc_spi_node);
88 if (ret)
89 return ret;
90
91 ret = platform_device_register(&digsy_mtc_eeprom);
92 if (ret)
93 device_remove_software_node(&digsy_mtc_eeprom.dev);
94
95 return ret;
96}
97device_initcall(digsy_mtc_eeprom_devices_init);
1/*
2 * EEPROMs access control driver for display configuration EEPROMs
3 * on DigsyMTC board.
4 *
5 * (C) 2011 DENX Software Engineering, Anatolij Gustschin <agust@denx.de>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * FIXME: this driver is used on a device-tree probed platform: it
12 * should be defined as a bit-banged SPI device and probed from the device
13 * tree and not like this with static grabbing of a few numbered GPIO
14 * lines at random.
15 *
16 * Add proper SPI and EEPROM in arch/powerpc/boot/dts/digsy_mtc.dts
17 * and delete this driver.
18 */
19
20#include <linux/gpio.h>
21#include <linux/gpio/machine.h>
22#include <linux/init.h>
23#include <linux/platform_device.h>
24#include <linux/spi/spi.h>
25#include <linux/spi/spi_gpio.h>
26#include <linux/eeprom_93xx46.h>
27
28#define GPIO_EEPROM_CLK 216
29#define GPIO_EEPROM_CS 210
30#define GPIO_EEPROM_DI 217
31#define GPIO_EEPROM_DO 249
32#define GPIO_EEPROM_OE 255
33#define EE_SPI_BUS_NUM 1
34
35static void digsy_mtc_op_prepare(void *p)
36{
37 /* enable */
38 gpio_set_value(GPIO_EEPROM_OE, 0);
39}
40
41static void digsy_mtc_op_finish(void *p)
42{
43 /* disable */
44 gpio_set_value(GPIO_EEPROM_OE, 1);
45}
46
47struct eeprom_93xx46_platform_data digsy_mtc_eeprom_data = {
48 .flags = EE_ADDR8,
49 .prepare = digsy_mtc_op_prepare,
50 .finish = digsy_mtc_op_finish,
51};
52
53static struct spi_gpio_platform_data eeprom_spi_gpio_data = {
54 .num_chipselect = 1,
55};
56
57static struct platform_device digsy_mtc_eeprom = {
58 .name = "spi_gpio",
59 .id = EE_SPI_BUS_NUM,
60 .dev = {
61 .platform_data = &eeprom_spi_gpio_data,
62 },
63};
64
65static struct gpiod_lookup_table eeprom_spi_gpiod_table = {
66 .dev_id = "spi_gpio",
67 .table = {
68 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CLK,
69 "sck", GPIO_ACTIVE_HIGH),
70 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DI,
71 "mosi", GPIO_ACTIVE_HIGH),
72 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DO,
73 "miso", GPIO_ACTIVE_HIGH),
74 GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CS,
75 "cs", GPIO_ACTIVE_HIGH),
76 { },
77 },
78};
79
80static struct spi_board_info digsy_mtc_eeprom_info[] __initdata = {
81 {
82 .modalias = "93xx46",
83 .max_speed_hz = 1000000,
84 .bus_num = EE_SPI_BUS_NUM,
85 .chip_select = 0,
86 .mode = SPI_MODE_0,
87 .platform_data = &digsy_mtc_eeprom_data,
88 },
89};
90
91static int __init digsy_mtc_eeprom_devices_init(void)
92{
93 int ret;
94
95 ret = gpio_request_one(GPIO_EEPROM_OE, GPIOF_OUT_INIT_HIGH,
96 "93xx46 EEPROMs OE");
97 if (ret) {
98 pr_err("can't request gpio %d\n", GPIO_EEPROM_OE);
99 return ret;
100 }
101 gpiod_add_lookup_table(&eeprom_spi_gpiod_table);
102 spi_register_board_info(digsy_mtc_eeprom_info,
103 ARRAY_SIZE(digsy_mtc_eeprom_info));
104 return platform_device_register(&digsy_mtc_eeprom);
105}
106device_initcall(digsy_mtc_eeprom_devices_init);